diff -Nru csound-5.17.11~dfsg/BUILDING_FOR_ANDROID csound-6.02~dfsg/BUILDING_FOR_ANDROID --- csound-5.17.11~dfsg/BUILDING_FOR_ANDROID 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/BUILDING_FOR_ANDROID 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,47 @@ +BUILDING FOR ANDROID + +Csound 6 now builds and runs on Android ABI 9 or later +for the ARM-v7 architecture (hard floating point). + +The build is complex but perhaps not as complex as one might think. +Most of the code is C or C++, only some of the code is Java, so +mostly the Android Native Development Kit (NDK) must be used, as +well of course as the Android Software Development Toolkit (SDK) for Java. + +To save build time, third-party dependencies are pre-built and +installed as part of the Android toolchain. This includes for example +the fluidsynth shared library and LuaJIT. The third-party source code +must go into a directory pointed to by NDK_MODULE_PATH. NOTE: this MUST +be on the same hard disk as the Csound sources. + +Otherwise your regular Csound build environment can be used after +setting the appropriate NDK environment variables. + +Do not use the 'build.sh' helpers, use $NDK/ndk-build to build and +install the shared libraries (modules), the environment variables +will do the job of 'build.sh'. There is one exception to this... + +The following variables must be set (this is an example from my +environment): + +echo "Configure for Android/ARM, armeabi-v7a (ARMv7 VFP), Android 4.0+ (ICS)..." + +export SDK=/d/Android/adt-bundle-windows-x86-20130514/sdk +export NDK=/d/Android/android-ndk-r8e +export ANDROID_NDK_ROOT=$NDK +export NDK_MODULE_PATH=/c/ndk-modules +export PATH=${PATH}:$NDK_MODULE_PATH +export CSOUND_SRC_ROOT=/c/Users/new/csound-csound6-git +# First Android with decent audio. +export NDKABI=9 +export NDKVER=$NDK/toolchains/arm-linux-androideabi-4.7 +export NDKP=$NDKVER/prebuilt/windows/bin/arm-linux-androideabi- +export NDKF="--sysroot $NDK/platforms/android-$NDKABI/arch-arm" +export NDKARCH="-march=armv7-a -mfloat-abi=softfp -Wl,--fix-cortex-a8" + +Obviously all of these variables must be consistent for all components +of Csound for Android. + +Download xxx from SourceForge. +Unzip each archive into xxx. + diff -Nru csound-5.17.11~dfsg/CMakeLists.txt csound-6.02~dfsg/CMakeLists.txt --- csound-5.17.11~dfsg/CMakeLists.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/CMakeLists.txt 2014-01-07 16:54:20.000000000 +0000 @@ -1,856 +1,1192 @@ -cmake_minimum_required(VERSION 2.6) - -project (Csound) - -message(STATUS "${CMAKE_HOME_DIRECTORY}") - -# Project definitions -set(APIVERSION "5.2") - -# Relative install paths -set(EXECUTABLE_INSTALL_DIR "bin") -set(LIBRARY_INSTALL_DIR "lib") -if(USE_DOUBLE) - set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}") -else() - set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}") -endif() -set(PYTHON_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) -set(JAVA_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) -set(LUA_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) -set(LOCALE_INSTALL_DIR "share/locale") -set(HEADER_INSTALL_DIR "include/csound") - -include(TestBigEndian) -include(CheckFunctionExists) -include(CheckIncludeFile) -include(CheckIncludeFileCXX) -include(CheckLibraryExists) -include(CMakeParseArguments) - -# Utility function to make plugins. All plugin targets should use this as it -# sets up output directory set in top-level CmakeLists.txt -# and adds the appropriate install target -# -# libname - name of library to produce -# srcs - list of src files (must be quoted if a list) -# extralibs (OPTIONAL) - extra libraries to link the plugin to -# -function(make_plugin libname srcs) - if(APPLE) - add_library(${libname} SHARED ${srcs}) - else() - add_library(${libname} MODULE ${srcs}) - endif() - - set(i 2) - while( ${i} LESS ${ARGC} ) - if(NOT MSVC OR NOT("${ARGV${i}}" MATCHES "m")) - target_link_libraries(${libname} ${ARGV${i}}) - endif() - math(EXPR i "${i}+1") - endwhile() - - set_target_properties(${libname} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} - LIBRARY_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} - ARCHIVE_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR}) - - install(TARGETS ${libname} - LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" ) -endfunction(make_plugin) -# Utility function to make executables. All plugin targets should use this as it -# sets up output directory set in top-level CmakeLists.txt -# and adds an appropriate install target -# -# name - name of executable to produce -# srcs - list of src files -# libs - list of library files to link to -# output_name (OPTIONAL) - overide the name of the generated executable -# -function(make_executable name srcs libs) - add_executable(${name} ${srcs}) - target_link_libraries (${name} ${libs}) - set_target_properties(${name} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR}) - - if(${ARGC} EQUAL 4) - set_target_properties(${name} PROPERTIES - OUTPUT_NAME ${ARGV3}) - endif() - install(TARGETS ${name} - RUNTIME DESTINATION "${EXECUTABLE_INSTALL_DIR}" ) -endfunction(make_executable) - - -# Utility function to make a utility executable -# -# name - name of executable to produce -# srcs - list of src files - -function(make_utility name srcs) - make_executable(${name} "${srcs}" "${CSOUNDLIB}") - add_dependencies(${name} ${CSOUNDLIB}) -endfunction() - - -# Expands a list into a space-separated string (outvar element1 ....) -# Why do I have to do this? Cmake, you just lost one point -function(expand_list out) - set(i 1) - set(tmp "") - while( ${i} LESS ${ARGC} ) - set(tmp "${tmp} ${ARGV${i}}") - math(EXPR i "${i}+1") - endwhile() - set(${out} "${tmp}" PARENT_SCOPE) -endfunction(expand_list) - -# Checks if dependencies for an enabled target are fulfilled. -# If FAIL_MISSING is true and the dependencies are not fulfilled, -# it will abort the cmake run. -# If FAIL_MISSING is false, it will set the option to OFF. -# If the target is not enabled, it will do nothing. -# example: check_deps(BUILD_NEW_PARSER FLEX_EXECUTABLE BISON_EXECUTABLE) -function(check_deps option) - if(${option}) - set(i 1) - while( ${i} LESS ${ARGC} ) - set(dep ${ARGV${i}}) - if(NOT ${dep}) - if(FAIL_MISSING) - message(FATAL_ERROR - "${option} is enabled, but ${dep}=\"${${dep}}\"") - else() - message(STATUS "${dep}=\"${${dep}}\", so disabling ${option}") - set(${option} OFF PARENT_SCOPE) - # Set it in the local scope too - set(${option} OFF) - endif() - endif() - math(EXPR i "${i}+1") - endwhile() - endif() - if(${option}) - message(STATUS "${option} is enabled") - else() - message(STATUS "${option} is disabled") - endif() -endfunction(check_deps) - -# Shortcut to add compiler flags -# Mandatory arguments: the flags to add, should be passed before optional keywords, can be -# passed as lists or space-separated -# Optional keywords: -# LINKER: add to linker instead of compile flags (LDFLAGS vs CFLAGS) -# TARGETS ... -# if specified, will add the flags to a target instead -# of the global namespace -function(add_compiler_flags) - set(bool_options LINKER) - set(multi_val_args TARGETS) - cmake_parse_arguments(FLAGS "${bool_options}" "" "${multi_val_args}" ${ARGN}) - - expand_list(FLAGS ${FLAGS_UNPARSED_ARGUMENTS}) - - if(FLAGS_TARGETS) - foreach(target ${FLAGS_TARGETS}) - if(NOT FLAGS_LINKER) - set(property "COMPILE_FLAGS") - else() - set(property "LINK_FLAGS") - endif() - get_target_property(propval ${target} ${property}) - if(NOT propval) - set(propval "") - endif() - set_target_properties(${target} PROPERTIES - ${property} "${propval} ${FLAGS}") - endforeach() - else() - if(FLAGS_LINKER) - set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAGS}") - else() - add_definitions("${FLAGS}") - endif() - endif() -endfunction(add_compiler_flags) - - -# Include this after the install path definitions so we can override them here. -# Also after function definitions so we can use them there -find_file(CUSTOM_CMAKE "Custom.cmake" HINTS ${CMAKE_HOME_DIRECTORY}) -if(CUSTOM_CMAKE) - message(STATUS "Including Custom.cmake file: ${CUSTOM_CMAKE}") - include(${CUSTOM_CMAKE}) -endif() - - -if(WIN32 AND NOT MSVC) - if(EXISTS "C:/MinGW/include") - include_directories(C:/MinGW/include) - else() - MESSAGE(STATUS "MinGW include dir not found") - endif() -endif() - -if(WIN32) - set(CMAKE_SHARED_LIBRARY_PREFIX "") - set(CMAKE_SHARED_MODULE_PREFIX "") - - set(CSOUND_WINDOWS_LIBRARIES - advapi32 - comctl32 - comdlg32 - glu32 - kernel32 - msvcrt - odbc32 - odbccp32 - ole32 - oleaut32 - shell32 - user32 - uuid - winmm - winspool - ws2_32 - wsock32 - advapi32 - comctl32 - comdlg32 - glu32 - kernel32 - odbc32 - odbccp32 - ole32 - oleaut32 - shell32 - user32 - uuid - winmm - winspool - ws2_32 - wsock32 - pthread) - -endif(WIN32) - -if(CMAKE_SYSTEM_NAME MATCHES "Linux") - set(LINUX YES) -else() - set(LINUX NO) -endif() - -## USER OPTIONS ## - -option(USE_DOUBLE "Set to use double-precision floating point for audio samples." ON) -option(BUILD_UTILITIES "Build stand-alone executables for utilities that can also be used with -U" ON) - -option(BUILD_NEW_PARSER "Enable building new parser (requires Flex/Bison)" ON) -option(NEW_PARSER_DEBUG "Enable tracing of new parser" OFF) - -option(BUILD_MULTI_CORE "Enable building for multicore system (requires BUILD_NEW_PARSER)" ON) - -option(FAIL_MISSING "Fail when a required external dependency is not present (useful for packagers)" OFF) - -option(USE_GETTEXT "Use the Gettext internationalization library" ON) - -option(BUILD_STATIC_LIBRARY "Also build a static version of the csound library" OFF) - -option(USE_OPEN_MP "Use OpenMP for Parallel Performance" ON) -option(USE_LRINT "Use lrint/lrintf for converting floating point values to integers." ON) -option(BUILD_RELEASE "Build for release" ON) -# Optional targets, they should all default to ON (check_deps will disable them if not possible to build) - - -set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) - -# This needs to be here since _everybody_ needs this flag -if(USE_DOUBLE) - add_definitions("-DUSE_DOUBLE") -endif(USE_DOUBLE) -if(${CMAKE_C_COMPILER} MATCHES "gcc" AND LINUX) - add_compiler_flags("-fvisibility=hidden") - add_compiler_flags("-fvisibility=hidden" LINKER) -endif() - -if(BUILD_RELEASE) - add_definitions("-D_CSOUND_RELEASE_") - if(LINUX) - set(DEFAULT_OPCODEDIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_DIR}") - add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${DEFAULT_OPCODEDIR}\"") - endif() -else() - add_definitions("-DBETA") -endif() - -if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) - add_definitions("-Wno-format") - add_compiler_flags("-g") -endif() - -#if(USE_DOUBLE) -# set(BUILD_PLUGINS_DIR ${BUILD_DIR}/plugins64) -#else() -# set(BUILD_PLUGINS_DIR ${BUILD_DIR}/plugins) -#endif() - -set(BUILD_PLUGINS_DIR ${BUILD_DIR}) -set(BUILD_BIN_DIR ${BUILD_DIR}) -set(BUILD_LIB_DIR ${BUILD_DIR}) - -message(STATUS "BUILD_BIN_DIR set to ${BUILD_BIN_DIR}") -message(STATUS "BUILD_LIB_DIR set to ${BUILD_LIB_DIR}") -message(STATUS "BUILD_PLUGINS_DIR set to ${BUILD_PLUGINS_DIR}") - -# OS specific checks - -TEST_BIG_ENDIAN(BIG_ENDIAN) - -## CONFIGURATION ## - -SET(BUILD_SHARED_LIBS ON) - -## HEADER/LIBRARY/OTHER CHECKS ## - -find_package(OpenMP) - -# First, required stuff -find_library(LIBSNDFILE_LIBRARY sndfile) - -if(NOT LIBSNDFILE_LIBRARY AND WIN32) -find_library(LIBSNDFILE_LIBRARY sndfile-1) -endif() - -if(NOT LIBSNDFILE_LIBRARY) - message(FATAL_ERROR "Csound requires the sndfile library") -endif() - -find_path(SNDFILE_H_PATH sndfile.h) -if(SNDFILE_H_PATH) - include_directories(${SNDFILE_H_PATH}) -else() - message(FATAL_ERROR "Could not find sndfile.h") -endif() - -find_library(PTHREAD_LIBRARY pthread) - -if(NOT PTHREAD_LIBRARY AND WIN32) - find_library(PTHREAD_LIBRARY pthreadGC2) -endif() - -if(NOT PTHREAD_LIBRARY) - message(FATAL_ERROR "Csound requires the pthread library") -endif() - -set(CMAKE_REQUIRED_INCLUDES pthread.h) -set(CMAKE_REQUIRED_LIBRARIES pthread) - -# Now, non required library searches # - -find_library(VORBISFILE_LIBRARY vorbisfile) -check_include_file(libintl.h LIBINTL_HEADER) -find_library(LIBINTL_LIBRARY intl) -find_package(Gettext) -check_library_exists(m lrint "" HAVE_LRINT) - -set(HEADERS_TO_CHECK - unistd.h io.h fcntl.h stdint.h - sys/time.h sys/types.h termios.h - values.h winsock.h sys/socket.h - dirent.h) - -foreach(header ${HEADERS_TO_CHECK}) - # Convert to uppercase and replace [./] with _ - string(TOUPPER ${header} tmp) - string(REGEX REPLACE [./] "_" upper_header ${tmp}) - check_include_file(${header} HAVE_${upper_header}) -endforeach() - -check_deps(USE_LRINT HAVE_LRINT) -if(USE_LRINT) - add_definitions("-DUSE_LRINT") -endif() - -# Flex/Bison for the new parser -if(BUILD_NEW_PARSER) - find_package(FLEX) - find_package(BISON) -endif() - -## MAIN TARGETS ## - -set(libcsound_CFLAGS -D__BUILDING_LIBCSOUND) - -include_directories(./H) -include_directories(./Engine) - -#adding this for files that #include SDIF/sdif* -include_directories(./) - -#checking pthread functions -check_function_exists(pthread_spin_lock PTHREAD_SPIN_LOCK_EXISTS) -check_function_exists(pthread_barrier_init PTHREAD_BARRIER_INIT_EXISTS) - -if(PTHREAD_SPIN_LOCK_EXISTS) - list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_SPIN_LOCK) -endif() - -if(PTHREAD_BARRIER_INIT_EXISTS) - list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_BARRIER_INIT) -endif() - - -check_deps(USE_OPEN_MP OPENMP_FOUND PTHREAD_BARRIER_INIT_EXISTS) -if(USE_OPEN_MP) - list(APPEND libcsound_CFLAGS -DUSE_OPENMP) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") - - set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}") - set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}") - -endif() - - -#if(WIN32) - include_directories(${LIBSNDFILE_INCLUDE_DIRECTORY}) -#endif(WIN32) - - -# The csound library -set(libcsound_SRCS - Engine/auxfd.c - Engine/cfgvar.c - Engine/corfiles.c - Engine/entry1.c - Engine/envvar.c - Engine/express.c - Engine/extract.c - Engine/fgens.c - Engine/insert.c - Engine/linevent.c - Engine/memalloc.c - Engine/memfiles.c - Engine/musmon.c - Engine/namedins.c - Engine/otran.c - Engine/rdorch.c - Engine/rdscor.c - Engine/scsort.c - Engine/scxtract.c - Engine/sort.c - Engine/sread.c - Engine/swrite.c - Engine/swritestr.c - Engine/twarp.c - InOut/libsnd.c - InOut/libsnd_u.c - InOut/midifile.c - InOut/midirecv.c - InOut/midisend.c - InOut/winascii.c - InOut/windin.c - InOut/window.c - InOut/winEPS.c - OOps/aops.c - OOps/bus.c - OOps/cmath.c - OOps/diskin.c - OOps/diskin2.c - OOps/disprep.c - OOps/dumpf.c - OOps/fftlib.c - OOps/goto_ops.c - OOps/midiinterop.c - OOps/midiops.c - OOps/midiout.c - OOps/mxfft.c - OOps/oscils.c - OOps/pstream.c - OOps/pvfileio.c - OOps/pvsanal.c - OOps/random.c - OOps/remote.c - OOps/schedule.c - OOps/sndinfUG.c - OOps/str_ops.c - OOps/ugens1.c - OOps/ugens2.c - OOps/ugens2a.c - OOps/ugens3.c - OOps/ugens4.c - OOps/ugens5.c - OOps/ugens6.c - OOps/ugrw1.c - OOps/ugrw2.c - OOps/vdelay.c - Opcodes/babo.c - Opcodes/bilbar.c - Opcodes/compress.c - Opcodes/eqfil.c - Opcodes/Vosim.c - Opcodes/pitch.c - Opcodes/pitch0.c - Opcodes/spectra.c - Opcodes/ambicode1.c - Opcodes/sfont.c - Opcodes/grain4.c - Opcodes/hrtferX.c - Opcodes/loscilx.c - Opcodes/minmax.c - Opcodes/pan2.c - Opcodes/tabvars.c - Opcodes/phisem.c - Opcodes/hrtfopcodes.c - Opcodes/stackops.c - Opcodes/vbap.c - Opcodes/vbap_eight.c - Opcodes/vbap_four.c - Opcodes/vbap_sixteen.c - Opcodes/vbap_zak.c - Opcodes/vaops.c - Opcodes/ugakbari.c - Opcodes/harmon.c - Opcodes/pitchtrack.c - Opcodes/partikkel.c - Opcodes/shape.c - Opcodes/tabsum.c - Opcodes/crossfm.c - Opcodes/pvlock.c - Opcodes/fareyseq.c - Opcodes/modmatrix.c - Opcodes/scoreline.c - Opcodes/modal4.c - Opcodes/physutil.c - Opcodes/physmod.c - Opcodes/mandolin.c - Opcodes/singwave.c - Opcodes/fm4op.c - Opcodes/moog1.c - Opcodes/shaker.c - Opcodes/bowedbar.c - Opcodes/gab/tabmorph.c - Opcodes/gab/hvs.c - Opcodes/gab/sliderTable.c - Opcodes/gab/newgabopc.c - Opcodes/ftest.c - Opcodes/hrtfearly.c - Opcodes/hrtfreverb.c - Opcodes/cpumeter.c - Opcodes/gendy.c - Opcodes/tl/sc_noise.c - Top/argdecode.c - Top/cscore_internal.c - Top/cscorfns.c - Top/csmodule.c - Top/csound.c - Top/getstring.c - Top/main.c - Top/new_opts.c - Top/one_file.c - Top/opcode.c - Top/threads.c - Top/utility.c) - -set(stdopcod_SRCS - Opcodes/ambicode.c - Opcodes/bbcut.c - Opcodes/biquad.c - Opcodes/butter.c - Opcodes/clfilt.c - Opcodes/cross2.c - Opcodes/dam.c - Opcodes/dcblockr.c - Opcodes/filter.c - Opcodes/flanger.c - Opcodes/follow.c - Opcodes/fout.c - Opcodes/freeverb.c - Opcodes/ftconv.c - Opcodes/ftgen.c - Opcodes/gab/gab.c - Opcodes/gab/vectorial.c - Opcodes/grain.c - Opcodes/locsig.c - Opcodes/lowpassr.c - Opcodes/metro.c - Opcodes/midiops2.c - Opcodes/midiops3.c - Opcodes/newfils.c - Opcodes/nlfilt.c - Opcodes/oscbnk.c - Opcodes/pluck.c - Opcodes/repluck.c - Opcodes/reverbsc.c - Opcodes/seqtime.c - Opcodes/sndloop.c - Opcodes/sndwarp.c - Opcodes/space.c - Opcodes/spat3d.c - Opcodes/syncgrain.c - Opcodes/ugens7.c - Opcodes/ugens9.c - Opcodes/ugensa.c - Opcodes/uggab.c - Opcodes/ugmoss.c - Opcodes/ugnorman.c - Opcodes/ugsc.c - Opcodes/wave-terrain.c - Opcodes/stdopcod.c) - -set(cs_pvs_ops_SRCS - Opcodes/ifd.c - Opcodes/partials.c - Opcodes/psynth.c - Opcodes/pvsbasic.c - Opcodes/pvscent.c - Opcodes/pvsdemix.c - Opcodes/pvs_ops.c - Opcodes/pvsband.c - Opcodes/pvsbuffer.c) - -set(oldpvoc_SRCS - Opcodes/dsputil.c - Opcodes/pvadd.c - Opcodes/pvinterp.c - Opcodes/pvocext.c - Opcodes/pvread.c - Opcodes/ugens8.c - Opcodes/vpvoc.c - Opcodes/pvoc.c) - -set(mp3in_SRCS - Opcodes/mp3in.c - InOut/libmpadec/layer1.c - InOut/libmpadec/layer2.c - InOut/libmpadec/layer3.c - InOut/libmpadec/synth.c - InOut/libmpadec/tables.c - InOut/libmpadec/mpadec.c - InOut/libmpadec/mp3dec.c) - - -list(APPEND libcsound_SRCS ${stdopcod_SRCS} ${cs_pvs_ops_SRCS} ${oldpvoc_SRCS} ${mp3in_SRCS}) - -# Handling New Parser - -check_deps(BUILD_NEW_PARSER FLEX_EXECUTABLE BISON_EXECUTABLE) -if(BUILD_NEW_PARSER) - add_custom_target(NewParser echo "Creating parser.c") - - set(YACC_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_orc.y) - set(YACC_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_orcparse.c) - - set(LEX_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_orc.l) - set(LEX_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_orclex.c) - - set(PRELEX_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_pre.lex) - set(PRELEX_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_prelex.c) - - add_custom_command( - SOURCE ${LEX_SRC} - COMMAND ${FLEX_EXECUTABLE} ARGS -B -t ${LEX_SRC} > ${LEX_OUT} - TARGET NewParser - OUTPUTS ${LEX_OUT}) - - add_custom_command( - SOURCE ${PRELEX_SRC} - COMMAND ${FLEX_EXECUTABLE} ARGS -B ${PRELEX_SRC} > ${PRELEX_OUT} - TARGET NewParser - OUTPUTS ${PRELEX_OUT}) - - add_custom_command( - SOURCE ${YACC_SRC} - COMMAND ${BISON_EXECUTABLE} - ARGS -pcsound_orc -d --report=itemset -o ${YACC_OUT} ${YACC_SRC} - TARGET NewParser - DEPENDS ${LEX_OUT} - OUTPUTS ${YACC_OUT}) - - list(APPEND libcsound_SRCS - ${LEX_OUT} ${YACC_OUT} ${PRELEX_OUT} - Engine/csound_orc_semantics.c - Engine/csound_orc_expressions.c - Engine/csound_orc_optimize.c - Engine/csound_orc_compile.c - Engine/new_orc_parser.c - Engine/symbtab.c) - - set_source_files_properties(${YACC_OUT} GENERATED) - set_source_files_properties(${LEX_OUT} GENERATED) - - include_directories(${CMAKE_CURRENT_BINARY_DIR}) - - list(APPEND libcsound_CFLAGS -DENABLE_NEW_PARSER) - - if(NEW_PARSER_DEBUG) - message(STATUS "Building with new parser debugging") - list(APPEND libcsound_CFLAGS -DPARSER_DEBUG=1) - else() - message(STATUS "Not building with new parser debugging") - endif() - - if(BUILD_MULTI_CORE) - message(STATUS "Building with multicore") - - list(APPEND libcsound_SRCS - Engine/cs_par_base.c - Engine/cs_par_orc_semantic_analysis.c - Engine/cs_par_dispatch.c) - - list(APPEND libcsound_CFLAGS -DPARCS) - - else() - message(STATUS "Not building with multicore") - endif() - -endif() - - -if(USE_DOUBLE) - set(CSOUNDLIB "csound64") -else() - set(CSOUNDLIB "csound") -endif() - -set(CSOUNDLIB_STATIC "${CSOUNDLIB}-static") - - -add_library(${CSOUNDLIB} SHARED ${libcsound_SRCS}) -set_target_properties(${CSOUNDLIB} PROPERTIES - # Do not pull extra libs when linking against shared libcsound - # The shared library loader will do that for us - LINK_INTERFACE_LIBRARIES "" - SOVERSION ${APIVERSION}) - -# Add the install target -install(TARGETS ${CSOUNDLIB} - LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}" - ARCHIVE DESTINATION "${LIBRARY_INSTALL_DIR}") - -set(libcsound_LIBS - ${LIBSNDFILE_LIBRARY} - ${PTHREAD_LIBRARY}) - -if(WIN32) - list(APPEND libcsound_LIBS "${CSOUND_WINDOWS_LIBRARIES}") -endif() - -# Linux does not have a separate libintl, it is part of libc -set(LIBINTL_AVAIL (LIBINTL_LIBRARY OR LINUX)) -check_deps(USE_GETTEXT LIBINTL_HEADER LIBINTL_AVAIL GETTEXT_MSGFMT_EXECUTABLE) -if(USE_GETTEXT) - message(STATUS "Using GNU Gettext") - if(NOT LINUX) - list(APPEND libcsound_LIBS ${LIBINTL_LIBRARY}) - endif() - list(APPEND libcsound_CFLAGS -DGNU_GETTEXT) -else() - message(STATUS "Not using localization") -endif() - - -if(LINUX) - message(STATUS "Building on Linux") - add_definitions(-DLINUX) - list(APPEND libcsound_LIBS m dl) -endif() - -if(APPLE) - message(STATUS "Building on OSX") - add_definitions(-DMACOSX -DPIPES) - list(APPEND libcsound_LIBS m dl) -endif() - -if(WIN32) - add_definitions(-DWIN32) -endif() - - - -# Pass flags according to system capabilities - -if(HAVE_WINSOCK_H OR HAVE_SYS_SOCKETS_H) - list(APPEND libcsound_CFLAGS -DHAVE_SOCKETS) -endif() -if(HAVE_DIRENT_H) - list(APPEND libcsound_CFLAGS -DHAVE_DIRENT_H) -endif() -if(HAVE_FCNTL_H) - list(APPEND libcsound_CFLAGS -DHAVE_FCNTL_H) -endif() -if(HAVE_UNISTD_H) - list(APPEND libcsound_CFLAGS -DHAVE_UNISTD_H) -endif() -if(HAVE_STDINT_H) - list(APPEND libcsound_CFLAGS -DHAVE_STDINT_H) -endif() -if(HAVE_SYS_TIME_H) - list(APPEND libcsound_CFLAGS -DHAVE_SYS_TIME_H) -endif() -if(HAVE_SYS_TYPES_H) - list(APPEND libcsound_CFLAGS -DHAVE_SYS_TYPES_H) -endif() -if(HAVE_TERMIOS_H) - list(APPEND libcsound_CFLAGS -DHAVE_TERMIOS_H) -endif() -if(HAVE_VALUES_H) - list(APPEND libcsound_CFLAGS -DHAVE_VALUES_H) -endif() -#if(CMAKE_C_COMPILER MATCHES "gcc") -# list(APPEND libcsound_CFLAGS -fno-strict-aliasing) -#endif() -if(BIG_ENDIAN) - list(APPEND libcsound_CFLAGS -DWORDS_BIGENDIAN) -endif() - -add_compiler_flags(${libcsound_CFLAGS} TARGETS ${CSOUNDLIB}) - -target_link_libraries(${CSOUNDLIB} ${libcsound_LIBS}) - -set_target_properties(${CSOUNDLIB} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR} - LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} - ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR}) - -if(BUILD_STATIC_LIBRARY) - add_library(${CSOUNDLIB_STATIC} STATIC ${libcsound_SRCS}) - SET_TARGET_PROPERTIES(${CSOUNDLIB_STATIC} PROPERTIES OUTPUT_NAME ${CSOUNDLIB}) - SET_TARGET_PROPERTIES(${CSOUNDLIB_STATIC} PROPERTIES PREFIX "lib") - add_compiler_flags(${libcsound_CFLAGS} TARGETS ${CSOUNDLIB_STATIC}) - - target_link_libraries(${CSOUNDLIB_STATIC} ${libcsound_LIBS}) - - set_target_properties(${CSOUNDLIB_STATIC} PROPERTIES - RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR} - LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} - ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR}) - - # Add the install target - install(TARGETS ${CSOUNDLIB_STATIC} - LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}" - ARCHIVE DESTINATION "${LIBRARY_INSTALL_DIR}") -endif() - -option(BUILD_CATALOG "Build the opcode/library catalog" OFF) -check_deps(BUILD_CATALOG) -if(BUILD_CATALOG) - -make_executable(mkdb "mkdb" "dl") -set_target_properties(mkdb PROPERTIES LINKER_LANGUAGE C) -endif() - - -add_subdirectory(Opcodes) -add_subdirectory(InOut) -add_subdirectory(interfaces) -add_subdirectory(frontends) -add_subdirectory(util) -add_subdirectory(util1) -add_subdirectory(SDIF) -add_subdirectory(po) -add_subdirectory(H) +cmake_minimum_required(VERSION 2.8.3) + +project (Csound) + +ENABLE_TESTING() + +message(STATUS "${CMAKE_HOME_DIRECTORY}") + +set(CMAKE_CXX_FLAGS_RELEASE "-O3 ") +set(CMAKE_C_FLAGS_RELEASE "-O3 ") + +# Project definitions +set(APIVERSION "6.0") + +# Relative install paths +set(EXECUTABLE_INSTALL_DIR "bin") + +option(USE_LIB64 "Set to on to set installation directory for libraries to lib64" OFF) +if(USE_LIB64) + set(LIBRARY_INSTALL_DIR "lib64") +else() + set(LIBRARY_INSTALL_DIR "lib") +endif() +message(STATUS "LIBRARY INSTALL DIR: ${LIBRARY_INSTALL_DIR}") + +if(USE_DOUBLE) + set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins64-${APIVERSION}") +else() + set(PLUGIN_INSTALL_DIR "${LIBRARY_INSTALL_DIR}/csound/plugins-${APIVERSION}") +endif() +set(PYTHON_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) +set(JAVA_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) +set(LUA_MODULE_INSTALL_DIR ${LIBRARY_INSTALL_DIR}) +set(LOCALE_INSTALL_DIR "share/locale") +set(HEADER_INSTALL_DIR "include/csound") + +set(CS_FRAMEWORK_DEST "~/Library/Frameworks") +include(TestBigEndian) +include(CheckFunctionExists) +include(CheckIncludeFile) +include(CheckIncludeFileCXX) +include(CheckLibraryExists) +include(CMakeParseArguments) +include(CheckCCompilerFlag) +include(CheckCXXCompilerFlag) + +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/") + +# Utility function to make executables. All plugin targets should use this as it +# sets up output directory set in top-level CmakeLists.txt +# and adds an appropriate install target +# +# name - name of executable to produce +# srcs - list of src files +# libs - list of library files to link to +# output_name (OPTIONAL) - overide the name of the generated executable +# +function(make_executable name srcs libs) + add_executable(${name} ${srcs}) + target_link_libraries (${name} ${libs}) + set_target_properties(${name} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR}) + + if(${ARGC} EQUAL 4) + set_target_properties(${name} PROPERTIES + OUTPUT_NAME ${ARGV3}) + endif() + install(TARGETS ${name} + RUNTIME DESTINATION "${EXECUTABLE_INSTALL_DIR}" ) +endfunction(make_executable) + + +# Utility function to make a utility executable +# +# name - name of executable to produce +# srcs - list of src files + +function(make_utility name srcs) + make_executable(${name} "${srcs}" "${CSOUNDLIB}") + add_dependencies(${name} ${CSOUNDLIB}) +endfunction() + + +# Expands a list into a space-separated string (outvar element1 ....) +# Why do I have to do this? Cmake, you just lost one point +function(expand_list out) + set(i 1) + set(tmp "") + while( ${i} LESS ${ARGC} ) + set(tmp "${tmp} ${ARGV${i}}") + math(EXPR i "${i}+1") + endwhile() + set(${out} "${tmp}" PARENT_SCOPE) +endfunction(expand_list) + +# Checks if dependencies for an enabled target are fulfilled. +# If FAIL_MISSING is true and the dependencies are not fulfilled, +# it will abort the cmake run. +# If FAIL_MISSING is false, it will set the option to OFF. +# If the target is not enabled, it will do nothing. +# example: check_deps(BUILD_NEW_PARSER FLEX_EXECUTABLE BISON_EXECUTABLE) +function(check_deps option) + if(${option}) + set(i 1) + while( ${i} LESS ${ARGC} ) + set(dep ${ARGV${i}}) + if(NOT ${dep}) + if(FAIL_MISSING) + message(FATAL_ERROR + "${option} is enabled, but ${dep}=\"${${dep}}\"") + else() + message(STATUS "${dep}=\"${${dep}}\", so disabling ${option}") + set(${option} OFF PARENT_SCOPE) + # Set it in the local scope too + set(${option} OFF) + endif() + endif() + math(EXPR i "${i}+1") + endwhile() + endif() + if(${option}) + message(STATUS "${option} is enabled") + else() + message(STATUS "${option} is disabled") + endif() +endfunction(check_deps) + +# Shortcut to add compiler flags +# Mandatory arguments: the flags to add, should be passed before optional keywords, can be +# passed as lists or space-separated +# Optional keywords: +# LINKER: add to linker instead of compile flags (LDFLAGS vs CFLAGS) +# TARGETS ... +# if specified, will add the flags to a target instead +# of the global namespace +function(add_compiler_flags) + set(bool_options LINKER) + set(multi_val_args TARGETS) + cmake_parse_arguments(FLAGS "${bool_options}" "" "${multi_val_args}" ${ARGN}) + + expand_list(FLAGS ${FLAGS_UNPARSED_ARGUMENTS}) + + if(FLAGS_TARGETS) + foreach(target ${FLAGS_TARGETS}) + if(NOT FLAGS_LINKER) + set(property "COMPILE_FLAGS") + else() + set(property "LINK_FLAGS") + endif() + get_target_property(propval ${target} ${property}) + if(NOT propval) + set(propval "") + endif() + set_target_properties(${target} PROPERTIES + ${property} "${propval} ${FLAGS}") + endforeach() + else() + if(FLAGS_LINKER) + set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${FLAGS}") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${FLAGS}") + else() + add_definitions("${FLAGS}") + endif() + endif() +endfunction(add_compiler_flags) + +### COMPILER OPTIMIZATION FLAGS +option(USE_COMPILER_OPTIMIZATIONS "Use the default Csound compiler optimization flags" ON) +if(USE_COMPILER_OPTIMIZATIONS) +include(cmake/CompilerOptimizations.cmake) +endif() + +# Include this after the install path definitions so we can override them here. +# Also after function definitions so we can use them there +find_file(CUSTOM_CMAKE "Custom.cmake" HINTS ${CMAKE_HOME_DIRECTORY}) +if(CUSTOM_CMAKE) + message(STATUS "Including Custom.cmake file: ${CUSTOM_CMAKE}") + include(${CUSTOM_CMAKE}) +else() + message(STATUS "Not using Custom.cmake file.") +endif() + + +if(WIN32 AND NOT MSVC) + if(EXISTS "C:/MinGW/include") + include_directories(C:/MinGW/include) + else() + MESSAGE(STATUS "MinGW include dir not found") + endif() + + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -Wl,--add-stdcall-alias") +endif() + +if(WIN32) + set(CMAKE_SHARED_LIBRARY_PREFIX "") + set(CMAKE_SHARED_MODULE_PREFIX "") + + set(CSOUND_WINDOWS_LIBRARIES + advapi32 + comctl32 + comdlg32 + glu32 + kernel32 + msvcrt + odbc32 + odbccp32 + ole32 + oleaut32 + shell32 + user32 + uuid + winmm + winspool + ws2_32 + wsock32 + advapi32 + comctl32 + comdlg32 + glu32 + kernel32 + odbc32 + odbccp32 + ole32 + oleaut32 + shell32 + user32 + uuid + winmm + winspool + ws2_32 + wsock32) + +endif(WIN32) + +if(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(LINUX YES) +else() + set(LINUX NO) +endif() + +## USER OPTIONS ## + +option(USE_DOUBLE "Set to use double-precision floating point for audio samples." ON) +option(BUILD_UTILITIES "Build stand-alone executables for utilities that can also be used with -U" ON) + +option(NEW_PARSER_DEBUG "Enable tracing of new parser" OFF) + +option(SCORE_PARSER "Enable building of alternative score parser" OFF) + +option(BUILD_MULTI_CORE "Enable building for multicore system (requires BUILD_NEW_PARSER)" ON) + +option(FAIL_MISSING "Fail when a required external dependency is not present (useful for packagers)" OFF) + +option(USE_GETTEXT "Use the Gettext internationalization library" ON) + +option(BUILD_STATIC_LIBRARY "Also build a static version of the csound library" OFF) + +option(USE_OPEN_MP "Use OpenMP for Parallel Performance" ON) +option(USE_LRINT "Use lrint/lrintf for converting floating point values to integers." ON) +option(USE_CURL "Use CURL library" ON) +option(BUILD_RELEASE "Build for release" ON) +option(BUILD_INSTALLER "Build for release" OFF) +option(BUILD_TESTS "Build for release" ON) +# Optional targets, they should all default to ON (check_deps will disable them if not possible to build) + + +set(BUILD_DIR ${CMAKE_CURRENT_BINARY_DIR}) + +# This needs to be here since _everybody_ needs this flag +if(USE_DOUBLE) + add_definitions("-DUSE_DOUBLE") +endif(USE_DOUBLE) +check_c_compiler_flag(-fvisibility=hidden HAS_VISIBILITY_HIDDEN) +check_cxx_compiler_flag(-fvisibility=hidden HAS_CXX_VISIBILITY_HIDDEN) +if (HAS_VISIBILITY_HIDDEN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvisibility=hidden") +endif() +if (HAS_CXX_VISBILITY_HIDDEN) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvisibility=hidden") +endif() + +if(APPLE) + if(BUILD_INSTALLER) + set(CS_FRAMEWORK_DEST "${CMAKE_INSTALL_PREFIX}") + endif() + + set(DEFAULT_OSX_SYSROOT /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.8.sdk/) + + if(NOT CMAKE_OSX_SYSROOT AND EXISTS ${DEFAULT_OSX_SYSROOT}) + set(CMAKE_OSX_SYSROOT ${DEFAULT_OSX_SYSROOT}) + endif() + + if(EXISTS ${CMAKE_OSX_SYSROOT}) + set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6) + endif() + +endif() + +if(USE_DOUBLE) + if(APPLE) + set(CSOUNDLIB "CsoundLib64") + set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64") + else() + set(CSOUNDLIB "csound64") + endif() +else() + if(APPLE) + set(CSOUNDLIB "CsoundLib") + set(PLUGIN_INSTALL_DIR "${CS_FRAMEWORK_DEST}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes") + else() + set(CSOUNDLIB "csound") + endif() +endif() + +if(APPLE) + if(BUILD_INSTALLER) + set(CS_FRAMEWORK_FULL_PATH "/Library/Frameworks/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes64") + else() + get_filename_component(PYTHON_MODULE_INSTALL_DIR "~/Library/Python/2.7/lib/python/site-packages" ABSOLUTE) + get_filename_component(JAVA_MODULE_INSTALL_DIR "~/Library/Java/Extensions" ABSOLUTE) + get_filename_component(CS_FRAMEWORK_FULL_PATH ${PLUGIN_INSTALL_DIR} ABSOLUTE) + endif() + + add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${CS_FRAMEWORK_FULL_PATH}\"") + +endif() + +if(BUILD_RELEASE) + add_definitions("-D_CSOUND_RELEASE_") + if(LINUX) + set(DEFAULT_OPCODEDIR "${CMAKE_INSTALL_PREFIX}/${PLUGIN_INSTALL_DIR}") + add_definitions("-DCS_DEFAULT_PLUGINDIR=\"${DEFAULT_OPCODEDIR}\"") + endif() +else() + add_definitions("-DBETA") +endif() + +if(CMAKE_COMPILER_IS_GNUCC OR CMAKE_COMPILER_IS_GNUCXX) + add_definitions("-Wno-format") + # add_compiler_flags("-g") +endif() + + +#if(USE_DOUBLE) +# set(BUILD_PLUGINS_DIR ${BUILD_DIR}/plugins64) +#else() +# set(BUILD_PLUGINS_DIR ${BUILD_DIR}/plugins) +#endif() + +set(BUILD_PLUGINS_DIR ${BUILD_DIR}) +set(BUILD_BIN_DIR ${BUILD_DIR}) +set(BUILD_LIB_DIR ${BUILD_DIR}) + +#if(APPLE AND NOT ${CMAKE_GENERATOR} STREQUAL "Xcode") +# set(BUILD_PLUGINS_DIR ${BUILD_DIR}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources/Opcodes) +#endif() + +message(STATUS "BUILD_BIN_DIR set to ${BUILD_BIN_DIR}") +message(STATUS "BUILD_LIB_DIR set to ${BUILD_LIB_DIR}") +message(STATUS "BUILD_PLUGINS_DIR set to ${BUILD_PLUGINS_DIR}") + +# OS specific checks + +TEST_BIG_ENDIAN(BIG_ENDIAN) + +## CONFIGURATION ## + +SET(BUILD_SHARED_LIBS ON) + +## HEADER/LIBRARY/OTHER CHECKS ## +find_package(OpenMP) + +# First, required stuff +find_library(LIBSNDFILE_LIBRARY sndfile) + +if(NOT LIBSNDFILE_LIBRARY AND WIN32) +find_library(LIBSNDFILE_LIBRARY sndfile-1) +endif() + +if(NOT LIBSNDFILE_LIBRARY) + message(FATAL_ERROR "Csound requires the sndfile library") +endif() + +find_path(SNDFILE_H_PATH sndfile.h) +if(SNDFILE_H_PATH) + include_directories(${SNDFILE_H_PATH}) +else() + message(FATAL_ERROR "Could not find sndfile.h") +endif() + +find_library(PTHREAD_LIBRARY pthread) + +if(NOT PTHREAD_LIBRARY AND WIN32) + find_library(PTHREAD_LIBRARY pthreadGC2) +endif() + +if(NOT PTHREAD_LIBRARY) + message(FATAL_ERROR "Csound requires the pthread library") +endif() + +set(CMAKE_REQUIRED_INCLUDES pthread.h) +set(CMAKE_REQUIRED_LIBRARIES pthread) + +# Now, non required library searches # + +option(USE_ATOMIC_BUILTIN "Use Atomic Builtins if supported" ON) +if(USE_ATOMIC_BUILTIN) +include(cmake/CheckAtomic.cmake) + if(HAVE_ATOMIC_BUILTIN) + message(STATUS "Using Atomic Builtins") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_ATOMIC_BUILTIN") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_ATOMIC_BUILTIN") + else() + message(STATUS "Not using Atomic Builtins - not found") + endif() +else() + message(STATUS "Not using Atomic Builtins - user disabled") +endif() + +find_library(VORBISFILE_LIBRARY vorbisfile) +check_include_file(libintl.h LIBINTL_HEADER) +check_include_file_cxx(eigen3/Eigen/Dense EIGEN3_HEADER) +find_library(LIBINTL_LIBRARY intl) +find_package(Gettext) +check_library_exists(m lrint "" HAVE_LRINT) + +set(HEADERS_TO_CHECK + unistd.h io.h fcntl.h stdint.h + sys/time.h sys/types.h termios.h + values.h winsock.h sys/socket.h + dirent.h ) + +foreach(header ${HEADERS_TO_CHECK}) + # Convert to uppercase and replace [./] with _ + string(TOUPPER ${header} tmp) + + string(REGEX REPLACE [./] "_" upper_header ${tmp}) + check_include_file(${header} HAVE_${upper_header}) +endforeach() + +check_deps(USE_LRINT HAVE_LRINT) +if(USE_LRINT) + add_definitions("-DUSE_LRINT") +endif() + +## Check existence of CURL +if(USE_CURL) + find_package(CURL) + + if(CURL_FOUND) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DHAVE_CURL") + else() + message(STATUS "Not using CURL for urls - not found") + endif() +else() + message(STATUS "Not using CURL for urls - disabled") +endif() + +# Flex/Bison for the new parser +find_package(FLEX) +find_package(BISON) + +if(NOT FLEX_EXECUTABLE) + message(FATAL_ERROR "Csound requires the flex executable") +endif() + +if(NOT BISON_EXECUTABLE) + message(FATAL_ERROR "Csound requires the bison executable") +endif() + +find_program(FLTK_CONFIG_SCRIPT fltk-config) +if(FLTK_CONFIG_SCRIPT) + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --api-version + OUTPUT_VARIABLE FLTK_VERSION) + if(FLTK_VERSION) + string(STRIP ${FLTK_VERSION} FLTK_VERSION) + if(FLTK_VERSION GREATER 1.1) + set(HAVE_FLTK "Fltk") + set(FLTK_FOUND 1) + message("FLTK FOUND: ${FLTK_FOUND}") + message(STATUS "Using fltk-config script for FLTK " ${FLTK_VERSION}) + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --includedir + OUTPUT_VARIABLE FLTK_INCLUDE_DIR) + string(STRIP ${FLTK_INCLUDE_DIR} FLTK_INCLUDE_DIR) + execute_process(COMMAND ${FLTK_CONFIG_SCRIPT} --ldflags --use-images + OUTPUT_VARIABLE FLTK_LIBRARIES) + string(STRIP ${FLTK_LIBRARIES} FLTK_LIBRARIES) + string(REGEX MATCH "fltk[_ ]jpeg" FLTK_JPEG ${FLTK_LIBRARIES}) + string(REGEX MATCH "fltk[_ ]z" FLTK_Z ${FLTK_LIBRARIES}) + string(REGEX MATCH "fltk[_ ]png" FLTK_PNG ${FLTK_LIBRARIES}) + endif(FLTK_VERSION GREATER 1.1) + endif(FLTK_VERSION) +endif(FLTK_CONFIG_SCRIPT) +if(NOT HAVE_FLTK) + set(FLTK_SKIP_OPENGL true) + find_package(FLTK) +endif() + +## MAIN TARGETS ## + +set(libcsound_CFLAGS -D__BUILDING_LIBCSOUND) + +include_directories(./H) +include_directories(./include) +include_directories(./Engine) + +#adding this for files that #include SDIF/sdif* +include_directories(./) + +#checking pthread functions +check_function_exists(pthread_spin_lock PTHREAD_SPIN_LOCK_EXISTS) +check_function_exists(pthread_barrier_init PTHREAD_BARRIER_INIT_EXISTS) + +if(PTHREAD_SPIN_LOCK_EXISTS) + list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_SPIN_LOCK) +endif() + +if(PTHREAD_BARRIER_INIT_EXISTS) + list(APPEND libcsound_CFLAGS -DHAVE_PTHREAD_BARRIER_INIT) +endif() + + +check_deps(USE_OPEN_MP OPENMP_FOUND PTHREAD_BARRIER_INIT_EXISTS) +if(USE_OPEN_MP) + list(APPEND libcsound_CFLAGS -DUSE_OPENMP) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}") + + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}") + set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} ${OpenMP_CXX_FLAGS}") + +endif() + + +#if(WIN32) + include_directories(${LIBSNDFILE_INCLUDE_DIRECTORY}) +#endif(WIN32) + + +# The csound library +set(libcsound_SRCS + Engine/auxfd.c + Engine/cfgvar.c + Engine/corfiles.c + Engine/entry1.c + Engine/envvar.c + Engine/extract.c + Engine/fgens.c + Engine/insert.c + Engine/linevent.c + Engine/memalloc.c + Engine/memfiles.c + Engine/musmon.c + Engine/namedins.c + Engine/rdscor.c + Engine/scsort.c + Engine/scxtract.c + Engine/sort.c + Engine/sread.c + Engine/swritestr.c + Engine/twarp.c + Engine/csound_type_system.c + Engine/csound_standard_types.c + Engine/csound_data_structures.c + Engine/pools.c + InOut/libsnd.c + InOut/libsnd_u.c + InOut/midifile.c + InOut/midirecv.c + InOut/midisend.c + InOut/winascii.c + InOut/windin.c + InOut/window.c + InOut/winEPS.c + InOut/circularbuffer.c + OOps/aops.c + OOps/bus.c + OOps/cmath.c + OOps/diskin2.c + OOps/disprep.c + OOps/dumpf.c + OOps/fftlib.c + OOps/goto_ops.c + OOps/midiinterop.c + OOps/midiops.c + OOps/midiout.c + OOps/mxfft.c + OOps/oscils.c + OOps/pstream.c + OOps/pvfileio.c + OOps/pvsanal.c + OOps/random.c + OOps/remote.c + OOps/schedule.c + OOps/sndinfUG.c + OOps/str_ops.c + OOps/ugens1.c + OOps/ugens2.c + OOps/ugens2a.c + OOps/ugens3.c + OOps/ugens4.c + OOps/ugens5.c + OOps/ugens6.c + OOps/ugtabs.c + OOps/ugrw1.c + OOps/ugrw2.c + OOps/vdelay.c + OOps/compile_ops.c + Opcodes/babo.c + Opcodes/bilbar.c + Opcodes/compress.c + Opcodes/eqfil.c + Opcodes/Vosim.c + Opcodes/pitch.c + Opcodes/pitch0.c + Opcodes/spectra.c + Opcodes/ambicode1.c + Opcodes/sfont.c + Opcodes/grain4.c + Opcodes/hrtferX.c + Opcodes/loscilx.c + Opcodes/minmax.c + Opcodes/pan2.c + Opcodes/arrays.c + Opcodes/phisem.c + Opcodes/hrtfopcodes.c + Opcodes/stackops.c + Opcodes/vbap.c + Opcodes/vbap1.c + Opcodes/vbap_n.c + Opcodes/vbap_zak.c + Opcodes/vaops.c + Opcodes/ugakbari.c + Opcodes/harmon.c + Opcodes/pitchtrack.c + Opcodes/partikkel.c + Opcodes/shape.c + Opcodes/tabsum.c + Opcodes/crossfm.c + Opcodes/pvlock.c + Opcodes/fareyseq.c + Opcodes/modmatrix.c + Opcodes/scoreline.c + Opcodes/modal4.c + Opcodes/physutil.c + Opcodes/physmod.c + Opcodes/mandolin.c + Opcodes/singwave.c + Opcodes/fm4op.c + Opcodes/moog1.c + Opcodes/shaker.c + Opcodes/bowedbar.c + Opcodes/gab/tabmorph.c + Opcodes/gab/hvs.c + Opcodes/gab/sliderTable.c + Opcodes/gab/newgabopc.c + Opcodes/ftest.c + Opcodes/hrtfearly.c + Opcodes/hrtfreverb.c + Opcodes/cpumeter.c + Opcodes/gendy.c + Opcodes/tl/sc_noise.c + Opcodes/afilters.c + Top/argdecode.c + Top/cscore_internal.c + Top/cscorfns.c + Top/csmodule.c + Top/csound.c + Top/getstring.c + Top/main.c + Top/new_opts.c + Top/one_file.c + Top/opcode.c + Top/threads.c + Top/utility.c + Top/threadsafe.c + Top/server.c) + +set(stdopcod_SRCS + Opcodes/ambicode.c + Opcodes/bbcut.c + Opcodes/biquad.c + Opcodes/butter.c + Opcodes/clfilt.c + Opcodes/cross2.c + Opcodes/dam.c + Opcodes/dcblockr.c + Opcodes/filter.c + Opcodes/flanger.c + Opcodes/follow.c + Opcodes/fout.c + Opcodes/freeverb.c + Opcodes/ftconv.c + Opcodes/ftgen.c + Opcodes/gab/gab.c + Opcodes/gab/vectorial.c + Opcodes/grain.c + Opcodes/locsig.c + Opcodes/lowpassr.c + Opcodes/metro.c + Opcodes/midiops2.c + Opcodes/midiops3.c + Opcodes/newfils.c + Opcodes/nlfilt.c + Opcodes/oscbnk.c + Opcodes/pluck.c + Opcodes/repluck.c + Opcodes/reverbsc.c + Opcodes/seqtime.c + Opcodes/sndloop.c + Opcodes/sndwarp.c + Opcodes/space.c + Opcodes/spat3d.c + Opcodes/syncgrain.c + Opcodes/ugens7.c + Opcodes/ugens9.c + Opcodes/ugensa.c + Opcodes/uggab.c + Opcodes/ugmoss.c + Opcodes/ugnorman.c + Opcodes/ugsc.c + Opcodes/wave-terrain.c + Opcodes/stdopcod.c + Opcodes/socksend.c + Opcodes/sockrecv.c) + +set(cs_pvs_ops_SRCS + Opcodes/ifd.c + Opcodes/partials.c + Opcodes/psynth.c + Opcodes/pvsbasic.c + Opcodes/pvscent.c + Opcodes/pvsdemix.c + Opcodes/pvs_ops.c + Opcodes/pvsband.c + Opcodes/pvsbuffer.c + Opcodes/pvsgendy.c) + +set(oldpvoc_SRCS + Opcodes/dsputil.c + Opcodes/pvadd.c + Opcodes/pvinterp.c + Opcodes/pvocext.c + Opcodes/pvread.c + Opcodes/ugens8.c + Opcodes/vpvoc.c + Opcodes/pvoc.c) + +set(mp3in_SRCS + Opcodes/mp3in.c + InOut/libmpadec/layer1.c + InOut/libmpadec/layer2.c + InOut/libmpadec/layer3.c + InOut/libmpadec/synth.c + InOut/libmpadec/tables.c + InOut/libmpadec/mpadec.c + InOut/libmpadec/mp3dec.c) + + +list(APPEND libcsound_SRCS ${stdopcod_SRCS} ${cs_pvs_ops_SRCS} ${oldpvoc_SRCS} ${mp3in_SRCS}) + +# Handling New Parser + +add_custom_target(NewParser echo "Creating parser.c") + +set(YACC_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_orc.y) +set(YACC_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_orcparse.c) + +set(LEX_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_orc.l) +set(LEX_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_orclex.c) + +set(PRELEX_SRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_pre.lex) +set(PRELEX_OUT ${CMAKE_CURRENT_BINARY_DIR}/csound_prelex.c) + +add_custom_command( + SOURCE ${LEX_SRC} + COMMAND ${FLEX_EXECUTABLE} ARGS -B -t ${LEX_SRC} > ${LEX_OUT} + TARGET NewParser + OUTPUTS ${LEX_OUT}) + +add_custom_command( + SOURCE ${PRELEX_SRC} + COMMAND ${FLEX_EXECUTABLE} ARGS -B ${PRELEX_SRC} > ${PRELEX_OUT} + TARGET NewParser + OUTPUTS ${PRELEX_OUT}) + +add_custom_command( + SOURCE ${YACC_SRC} + COMMAND ${BISON_EXECUTABLE} + ARGS -pcsound_orc -d --report=itemset -o ${YACC_OUT} ${YACC_SRC} + TARGET NewParser + DEPENDS ${LEX_OUT} + OUTPUTS ${YACC_OUT}) + +list(APPEND libcsound_SRCS + ${LEX_OUT} ${YACC_OUT} ${PRELEX_OUT} + Engine/csound_orc_semantics.c + Engine/csound_orc_expressions.c + Engine/csound_orc_optimize.c + Engine/csound_orc_compile.c + Engine/new_orc_parser.c + Engine/symbtab.c) + +set_source_files_properties(${YACC_OUT} GENERATED) +set_source_files_properties(${LEX_OUT} GENERATED) + +# Handling New Score Parser + +if(SCORE_PARSER) + add_custom_target(NewScoParser echo "Creating sco_parser.c") + set(NewScoParser OFF) + + set(YACC_SCOSRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_sco.y) + set(YACC_SCOOUT ${CMAKE_CURRENT_BINARY_DIR}/csound_scoparse.c) + + set(LEX_SCOSRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_sco.lex) + set(LEX_SCOOUT ${CMAKE_CURRENT_BINARY_DIR}/csound_scolex.c) + + set(PRELEX_SCOSRC ${CMAKE_CURRENT_SOURCE_DIR}/Engine/csound_prs.lex) + set(PRELEX_SCOOUT ${CMAKE_CURRENT_BINARY_DIR}/csound_prslex.c) + + add_custom_command( + SOURCE ${LEX_SCOSRC} + COMMAND ${FLEX_EXECUTABLE} ARGS -B -t ${LEX_SCOSRC} > ${LEX_SCOOUT} + TARGET NewScoParser + OUTPUTS ${LEX_SCOOUT}) + + add_custom_command( + SOURCE ${PRELEX_SCOSRC} + COMMAND ${FLEX_EXECUTABLE} ARGS -B ${PRELEX_SCOSRC} > ${PRELEX_SCOOUT} + TARGET NewScoParser + OUTPUTS ${PRELEXSCO_OUT}) + + add_custom_command( + SOURCE ${YACC_SCOSRC} + COMMAND ${BISON_EXECUTABLE} + ARGS -pcsound_sco -d --report=itemset -o ${YACC_SCOOUT} ${YACC_SCOSRC} + TARGET NewScoParser + DEPENDS ${LEX_SCOOUT} + OUTPUTS ${YACC_SCOOUT}) + + list(APPEND libcsound_SRCS + ${LEX_SCOOUT} ${YACC_SCOOUT} ${PRELEXSCO_OUT}) + + set_source_files_properties(${YACC_SCOOUT} GENERATED) + set_source_files_properties(${LEX_SCOOUT} GENERATED) +else() + message(STATUS "Not building with score parser") +endif() + + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +if(NEW_PARSER_DEBUG) + message(STATUS "Building with new parser debugging") + list(APPEND libcsound_CFLAGS -DPARSER_DEBUG=1) +else() + message(STATUS "Not building with new parser debugging") +endif() + +if(BUILD_MULTI_CORE) + message(STATUS "Building with multicore") + + list(APPEND libcsound_SRCS + Engine/cs_new_dispatch.c + Engine/cs_par_base.c + Engine/cs_par_orc_semantic_analysis.c + Engine/cs_par_dispatch.c) + + list(APPEND libcsound_CFLAGS -DPARCS) + +else() + message(STATUS "Not building with multicore") +endif() + +set(CSOUNDLIB_STATIC "${CSOUNDLIB}-static") + +# ADDING HERE TO GRAB LIST OF HEADERS IN CASE OF BUILDING OSX FRAMEWORK +add_subdirectory(include) + + +if(APPLE) + string(REGEX REPLACE "([^;]+)(;|$)" "include/\\1\\2" csheaders "${csheaders}") + file(GLOB H_headers "${CMAKE_CURRENT_SOURCE_DIR}/H/*.h") + set(libcsound_SRCS "${libcsound_SRCS};${csheaders};${H_headers}") +endif() + +add_library(${CSOUNDLIB} SHARED ${libcsound_SRCS}) +set_target_properties(${CSOUNDLIB} PROPERTIES + # Do not pull extra libs when linking against shared libcsound + # The shared library loader will do that for us + LINK_INTERFACE_LIBRARIES "" + SOVERSION ${APIVERSION}) + + + +if(APPLE) + set_target_properties(${CSOUNDLIB} PROPERTIES FRAMEWORK YES) + set_target_properties(${CSOUNDLIB} PROPERTIES FRAMEWORK_VERSION "${APIVERSION}") + set_target_properties(${CSOUNDLIB} PROPERTIES PUBLIC_HEADER "${csheaders}") +endif() + +# This copies libsndfile into the framework and sets the install names +# of CsoundLib to refer to it. +#if(APPLE AND NOT ${CMAKE_GENERATOR} STREQUAL "Xcode") + +#get_filename_component(source ${LIBSNDFILE_LIBRARY} REALPATH) +#get_filename_component(depname ${source} NAME) + +#set(CSOUNDLIB_DIR ${BUILD_DIR}/${CSOUNDLIB}.framework/Versions/${APIVERSION}) + +#if(NOT EXISTS ${CSOUNDLIB_DIR}/Resources/libs/${depname}) +# add_custom_command( +# TARGET ${CSOUNDLIB} +# POST_BUILD +# COMMAND mkdir +# ARGS -p ${CSOUNDLIB_DIR}/Resources/libs +# COMMAND cp +# ARGS ${source} ${CSOUNDLIB_DIR}/Resources/libs/${depname} +# COMMAND ${CMAKE_INSTALL_NAME_TOOL} +# ARGS -id ${depname} ${CSOUNDLIB_DIR}/Resources/libs/${depname} +#) +#endif() + +#add_custom_command( +# TARGET ${CSOUNDLIB} +# POST_BUILD +# COMMAND ${CMAKE_INSTALL_NAME_TOOL} +# ARGS -change ${source} @loader_path/Resources/libs/${depname} ${CSOUNDLIB_DIR}/${CSOUNDLIB} +#) +#endif() + +# Utility function to make plugins. All plugin targets should use this as it +# sets up output directory set in top-level CmakeLists.txt +# and adds the appropriate install target +# +# libname - name of library to produce +# srcs - list of src files (must be quoted if a list) +# extralibs (OPTIONAL) - extra libraries to link the plugin to +# +# NB - this was moved here as it needs some VARS defined above +# for setting up the framework +function(make_plugin libname srcs) + if(APPLE) + add_library(${libname} SHARED ${srcs}) + else() + add_library(${libname} MODULE ${srcs}) + endif() + + set(i 2) + while( ${i} LESS ${ARGC} ) + if(NOT MSVC OR NOT("${ARGV${i}}" MATCHES "m")) + target_link_libraries(${libname} ${ARGV${i}}) + endif() + math(EXPR i "${i}+1") + endwhile() + + set_target_properties(${libname} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} + LIBRARY_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR} + ARCHIVE_OUTPUT_DIRECTORY ${BUILD_PLUGINS_DIR}) + + install(TARGETS ${libname} + LIBRARY DESTINATION "${PLUGIN_INSTALL_DIR}" ) + +endfunction(make_plugin) + +# this copies the dependencies of plugins into framework +# and fixes the lib name references +function(add_dependency_to_framework pluginlib dependency) + + + #if(APPLE AND NOT ${CMAKE_GENERATOR} STREQUAL "Xcode") + + #get_filename_component(source ${dependency} REALPATH) + #get_filename_component(depname ${source} NAME) + # + #set(RESOURCE_DIR ${BUILD_DIR}/${CSOUNDLIB}.framework/Versions/${APIVERSION}/Resources) + + #if(NOT EXISTS ${RESOURCE_DIR}/libs/${depname}) + #add_custom_command( + #TARGET ${pluginlib} + #COMMAND mkdir + #ARGS -p ${RESOURCE_DIR}/libs + #COMMAND cp + #ARGS -f ${source} ${RESOURCE_DIR}/libs/${depname} + #COMMAND ${CMAKE_INSTALL_NAME_TOOL} + #ARGS -id ${depname} ${RESOURCE_DIR}/libs/${depname} + #) + #endif() + #add_custom_command( + #TARGET ${pluginlib} + #POST_BUILD + #COMMAND ${CMAKE_INSTALL_NAME_TOOL} + #ARGS -change ${source} @loader_path/../libs/${depname} ${BUILD_PLUGINS_DIR}/lib${pluginlib}.dylib + #) + #endif() +endfunction(add_dependency_to_framework) + +# Add the install target +install(TARGETS ${CSOUNDLIB} + LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}" + ARCHIVE DESTINATION "${LIBRARY_INSTALL_DIR}" + FRAMEWORK DESTINATION "${CS_FRAMEWORK_DEST}") + +set(libcsound_LIBS + ${LIBSNDFILE_LIBRARY} + ${PTHREAD_LIBRARY}) + +if(WIN32) + list(APPEND libcsound_LIBS "${CSOUND_WINDOWS_LIBRARIES}") +endif() + +if(CURL_FOUND) + list(APPEND libcsound_LIBS ${CURL_LIBRARIES}) +endif() + +# Linux does not have a separate libintl, it is part of libc +set(LIBINTL_AVAIL (LIBINTL_LIBRARY OR LINUX)) +check_deps(USE_GETTEXT LIBINTL_HEADER LIBINTL_AVAIL GETTEXT_MSGFMT_EXECUTABLE) +if(USE_GETTEXT) + message(STATUS "Using GNU Gettext") + if(NOT LINUX) + list(APPEND libcsound_LIBS ${LIBINTL_LIBRARY}) + endif() + list(APPEND libcsound_CFLAGS -DGNU_GETTEXT) +else() + message(STATUS "Not using localization") +endif() + +if(LINUX) + message(STATUS "Building on Linux") + add_definitions(-DLINUX -DPIPES -D_GNU_SOURCE) + list(APPEND libcsound_LIBS m dl) +endif() + +if(APPLE) + message(STATUS "Building on OSX") + add_definitions(-DMACOSX -DPIPES -DNO_FLTK_THREADS -DHAVE_SOCKETS) + list(APPEND libcsound_LIBS m dl) +endif() + +if(WIN32) + add_definitions(-DWIN32) +endif() + +# Locale-aware reading and printing +check_function_exists(strtok_r HAVE_STRTOK_R) +check_function_exists(strtod_l HAVE_STRTOD_L) +check_function_exists(sprintf_l HAVE_SPRINTF_L) + +if(HAVE_STRTOK_R) + add_definitions(-DHAVE_STRTOK_R) +endif() +if(HAVE_STRTOD_L) + add_definitions(-DHAVE_STRTOD_L) +endif() +if(HAVE_SPRINTF_L) + add_definitions(-DHAVE_SPRINTF_L) +endif() + +# Same for Windows +check_function_exists(_strtok_r HAVE__STRTOK_R) +check_function_exists(_strtod_l HAVE__STRTOD_L) +check_function_exists(_sprintf_l HAVE__SPRINTF_L) + +if(HAVE__STRTOK_R) + add_definitions(-DHAVE__STRTOK_R) +endif() +if(HAVE__STRTOD_L) + add_definitions(-DHAVE__STRTOD_L) +endif() +if(HAVE__SPRINTF_L) + add_definitions(-DHAVE__SPRINTF_L) +endif() + +# Pass flags according to system capabilities + +if(HAVE_WINSOCK_H OR HAVE_SYS_SOCKETS_H) + list(APPEND libcsound_CFLAGS -DHAVE_SOCKETS) +endif() +if(HAVE_DIRENT_H) + list(APPEND libcsound_CFLAGS -DHAVE_DIRENT_H) +endif() +if(HAVE_FCNTL_H) + list(APPEND libcsound_CFLAGS -DHAVE_FCNTL_H) +endif() +if(HAVE_UNISTD_H) + list(APPEND libcsound_CFLAGS -DHAVE_UNISTD_H) +endif() +if(HAVE_STDINT_H) + list(APPEND libcsound_CFLAGS -DHAVE_STDINT_H) +endif() +if(HAVE_SYS_TIME_H) + list(APPEND libcsound_CFLAGS -DHAVE_SYS_TIME_H) +endif() +if(HAVE_SYS_TYPES_H) + list(APPEND libcsound_CFLAGS -DHAVE_SYS_TYPES_H) +endif() +if(HAVE_TERMIOS_H) + list(APPEND libcsound_CFLAGS -DHAVE_TERMIOS_H) +endif() +if(HAVE_VALUES_H) + list(APPEND libcsound_CFLAGS -DHAVE_VALUES_H) +endif() +#if(CMAKE_C_COMPILER MATCHES "gcc") +# list(APPEND libcsound_CFLAGS -fno-strict-aliasing) +#endif() + +if(BIG_ENDIAN) + list(APPEND libcsound_CFLAGS -DWORDS_BIGENDIAN) +endif() + + + + +add_compiler_flags(${libcsound_CFLAGS} TARGETS ${CSOUNDLIB}) + +target_link_libraries(${CSOUNDLIB} ${libcsound_LIBS}) + +set_target_properties(${CSOUNDLIB} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR} + LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} + ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR}) + +if(BUILD_STATIC_LIBRARY) + add_library(${CSOUNDLIB_STATIC} STATIC ${libcsound_SRCS}) + SET_TARGET_PROPERTIES(${CSOUNDLIB_STATIC} PROPERTIES OUTPUT_NAME ${CSOUNDLIB}) + SET_TARGET_PROPERTIES(${CSOUNDLIB_STATIC} PROPERTIES PREFIX "lib") + add_compiler_flags(${libcsound_CFLAGS} TARGETS ${CSOUNDLIB_STATIC}) + + target_link_libraries(${CSOUNDLIB_STATIC} ${libcsound_LIBS}) + + set_target_properties(${CSOUNDLIB_STATIC} PROPERTIES + RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR} + LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} + ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR}) + + # Add the install target + install(TARGETS ${CSOUNDLIB_STATIC} + LIBRARY DESTINATION "${LIBRARY_INSTALL_DIR}" + ARCHIVE DESTINATION "${LIBRARY_INSTALL_DIR}") +endif() + +## option(BUILD_CATALOG "Build the opcode/library catalog" OFF) +## check_deps(BUILD_CATALOG) +## if(BUILD_CATALOG) +## make_executable(mkdb "mkdb" "dl") +## set_target_properties(mkdb PROPERTIES LINKER_LANGUAGE C) +## endif() + + +add_subdirectory(Opcodes) +add_subdirectory(InOut) +add_subdirectory(interfaces) +add_subdirectory(frontends) +add_subdirectory(util) +add_subdirectory(util1) +add_subdirectory(SDIF) +add_subdirectory(po) +add_subdirectory(tests/c) +add_subdirectory(tests/commandline) +add_subdirectory(tests/regression) +add_subdirectory(tests/soak) + +# uninstall target +configure_file( + "${CMAKE_CURRENT_SOURCE_DIR}/cmake/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) + +add_custom_target(uninstall + COMMAND ${CMAKE_COMMAND} -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake) + +# target etags/tags +if(UNIX) + add_custom_target(tags COMMAND etags `find ${CMAKE_CURRENT_SOURCE_DIR} -name \\*.cc -or -name \\*.hh -or -name \\*.cpp -or -name \\*.h -or -name \\*.c | grep -v " "`) + add_custom_target(etags DEPENDS tags) +endif() + +# build a CPack driven installer package +#include (InstallRequiredSystemLibraries) + +set (CPACK_PACKAGE_NAME "csound") +set (CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") +set (CPACK_PACKAGE_VERSION "6.0.0") +set (CPACK_PACKAGE_VERSION_MAJOR "6") +set (CPACK_PACKAGE_VERSION_MINOR "0") +set (CPACK_PACKAGE_VERSION_PATCH "0") +include (CPack) + diff -Nru csound-5.17.11~dfsg/CsoundLib.framework/readme.txt csound-6.02~dfsg/CsoundLib.framework/readme.txt --- csound-5.17.11~dfsg/CsoundLib.framework/readme.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/CsoundLib.framework/readme.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,13 +0,0 @@ -This is the top-level of Csound Library Framework. The framework is -normally installed in /Library/Frameworks. In order to use -the Csound Library, the following options should be given: - -a) compiling options: - --I/Library/Frameworks/CsoundLib.Framework/Headers - -b) linker options: - --framework CsoundLib - -VL, 2005 diff -Nru csound-5.17.11~dfsg/Custom.cmake.ex csound-6.02~dfsg/Custom.cmake.ex --- csound-5.17.11~dfsg/Custom.cmake.ex 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Custom.cmake.ex 2014-01-07 16:53:47.000000000 +0000 @@ -1,20 +1,43 @@ -# CUSTOM PROPERTIES TO SET - -# GLOBAL - -set(CMAKE_BUILD_TYPE "Debug") -set(CMAKE_VERBOSE_MAKEFILE ON) - -if(WIN32) - list(APPEND CMAKE_SYSTEM_INCLUDE_PATH - "c:/work/libsndfile-1_0_17") - list(APPEND CMAKE_SYSTEM_LIBRARY_PATH - "c:/work/libsndfile-1_0_17") - - list(APPEND CMAKE_SYSTEM_LIBRARY_PATH - "c:/Python25/libs") - list(APPEND CMAKE_SYSTEM_INCLUDE_PATH - "c:/Python25/include") - -endif() - +# CUSTOM PROPERTIES TO SET + +# GLOBAL + +#set(CMAKE_BUILD_TYPE "Debug") +set(CMAKE_VERBOSE_MAKEFILE ON) +set(BUILD_STATIC_LIBRARY ON) +set(USE_OPEN_MP OFF) +set(TCL_VERSION 8.5) +set(PYTHON_INCLUDE_DIRS "/usr/include/python2.7") +##set(BUILD_CSOUND_AC OFF) +##set(BUILD_CSOUND_AC_PYTHON_INTERFACE OFF) +##set(BUILD_CSOUND_AC_LUA_INTERFACE OFF) + +#### NOTE the processor type needs setting +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -W -Wall -O3 -mtune=core2") +## also to test multicore +#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -W -Wno-missing-field-initializers -Wno-unused-parameter -O3 -mtune=core2 -DJPFF") + +include(CheckCCompilerFlag) +check_c_compiler_flag(-ftree-vectorize HAS_TREE_VECTORISE) +if (HAS_TREE_VECTORISE) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-vectorize") +endif() + +check_c_compiler_flag(-ffast-math HAS_FAST_MATH) +if (HAS_FAST_MATH) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math") +endif() + +if(WIN32) + list(APPEND CMAKE_SYSTEM_INCLUDE_PATH + "c:/work/libsndfile-1_0_17") + list(APPEND CMAKE_SYSTEM_LIBRARY_PATH + "c:/work/libsndfile-1_0_17") + + list(APPEND CMAKE_SYSTEM_LIBRARY_PATH + "c:/Python25/libs") + list(APPEND CMAKE_SYSTEM_INCLUDE_PATH + "c:/Python25/include") + +endif() + diff -Nru csound-5.17.11~dfsg/Doxyfile csound-6.02~dfsg/Doxyfile --- csound-5.17.11~dfsg/Doxyfile 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Doxyfile 2014-01-07 16:54:20.000000000 +0000 @@ -1,4 +1,4 @@ -# Doxyfile 1.5.8 +# Doxyfile 1.8.3.1 # This file describes the settings to be used by the documentation system # doxygen (www.doxygen.org) for a project @@ -22,23 +22,37 @@ DOXYFILE_ENCODING = UTF-8 -# The PROJECT_NAME tag is a single word (or a sequence of words surrounded -# by quotes) that should identify the project. +# The PROJECT_NAME tag is a single word (or sequence of words) that should +# identify the project. Note that if you do not use Doxywizard you need +# to put quotes around the project name if it contains spaces. -PROJECT_NAME = "Csound and CsoundAC API" +PROJECT_NAME = "Csound API" # The PROJECT_NUMBER tag can be used to enter a project or revision number. # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 5.17 +PROJECT_NUMBER = 6.01 + +# Using the PROJECT_BRIEF tag one can provide an optional one line description +# for a project that appears at the top of each page and should give viewer +# a quick idea about the purpose of the project. Keep the description short. + +PROJECT_BRIEF = + +# With the PROJECT_LOGO tag one can specify an logo or icon that is +# included in the documentation. The maximum height of the logo should not +# exceed 55 pixels and the maximum width should not exceed 200 pixels. +# Doxygen will copy the logo to the output directory. + +PROJECT_LOGO = # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. # If a relative path is entered, it will be relative to the location # where doxygen was started. If left blank the current directory will be used. -OUTPUT_DIRECTORY = doc +OUTPUT_DIRECTORY = doc/csound # If the CREATE_SUBDIRS tag is set to YES, then doxygen will create # 4096 sub-directories (in 2 levels) under the output directory of each output @@ -54,11 +68,11 @@ # information to generate all constant output in the proper language. # The default language is English, other supported languages are: # Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, -# Croatian, Czech, Danish, Dutch, Farsi, Finnish, French, German, Greek, -# Hungarian, Italian, Japanese, Japanese-en (Japanese with English messages), -# Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, Polish, -# Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, Slovene, -# Spanish, Swedish, and Ukrainian. +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. OUTPUT_LANGUAGE = English @@ -112,7 +126,9 @@ # only done if one of the specified strings matches the left-hand part of # the path. The tag can be used to show relative paths in the file list. # If left blank the directory from which doxygen is run is used as the -# path to strip. +# path to strip. Note that you specify absolute paths here, but also +# relative paths, which will be relative from the directory where doxygen is +# started. STRIP_FROM_PATH = @@ -126,7 +142,7 @@ STRIP_FROM_INC_PATH = # If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter -# (but less readable) file names. This can be useful is your file systems +# (but less readable) file names. This can be useful if your file system # doesn't support long names like on DOS, Mac, or CD-ROM. SHORT_NAMES = NO @@ -181,6 +197,13 @@ ALIASES = +# This tag can be used to specify a number of word-keyword mappings (TCL only). +# A mapping has the form "name=value". For example adding +# "class=itcl::class" will allow you to use the command class in the +# itcl::class meaning. + +TCL_SUBST = + # Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C # sources only. Doxygen will then generate output that is more tailored for C. # For instance, some of the names that are used will be different. The list @@ -207,22 +230,40 @@ OPTIMIZE_OUTPUT_VHDL = NO -# Doxygen selects the parser to use depending on the extension of the files it parses. -# With this tag you can assign which parser to use for a given extension. -# Doxygen has a built-in mapping, but you can override or extend it using this tag. -# The format is ext=language, where ext is a file extension, and language is one of -# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, -# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat -# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), -# use: inc=Fortran f=C +# Doxygen selects the parser to use depending on the extension of the files it +# parses. With this tag you can assign which parser to use for a given +# extension. Doxygen has a built-in mapping, but you can override or extend it +# using this tag. The format is ext=language, where ext is a file extension, +# and language is one of the parsers supported by doxygen: IDL, Java, +# Javascript, CSharp, C, C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, +# C++. For instance to make doxygen treat .inc files as Fortran files (default +# is PHP), and .f files as C (default is Fortran), use: inc=Fortran f=C. Note +# that for custom extensions you also need to set FILE_PATTERNS otherwise the +# files are not read by doxygen. EXTENSION_MAPPING = YES +# If MARKDOWN_SUPPORT is enabled (the default) then doxygen pre-processes all +# comments according to the Markdown format, which allows for more readable +# documentation. See http://daringfireball.net/projects/markdown/ for details. +# The output of markdown processing is further processed by doxygen, so you +# can mix doxygen, HTML, and XML commands with Markdown formatting. +# Disable only in case of backward compatibilities issues. + +MARKDOWN_SUPPORT = YES + +# When enabled doxygen tries to link words that correspond to documented classes, +# or namespaces to their corresponding documentation. Such a link can be +# prevented in individual cases by by putting a % sign in front of the word or +# globally by setting AUTOLINK_SUPPORT to NO. + +AUTOLINK_SUPPORT = YES + # If you use STL classes (i.e. std::string, std::vector, etc.) but do not want # to include (a tag file for) the STL sources as input, then you should # set this tag to YES in order to let doxygen match functions declarations and # definitions whose arguments contain STL classes (e.g. func(std::string); v.s. -# func(std::string) {}). This also make the inheritance and collaboration +# func(std::string) {}). This also makes the inheritance and collaboration # diagrams that involve STL classes more complete and accurate. BUILTIN_STL_SUPPORT = YES @@ -238,10 +279,10 @@ SIP_SUPPORT = NO -# For Microsoft's IDL there are propget and propput attributes to indicate getter -# and setter methods for a property. Setting this option to YES (the default) -# will make doxygen to replace the get and set methods by a property in the -# documentation. This will only work if the methods are indeed getting or +# For Microsoft's IDL there are propget and propput attributes to indicate +# getter and setter methods for a property. Setting this option to YES (the +# default) will make doxygen replace the get and set methods by a property in +# the documentation. This will only work if the methods are indeed getting or # setting a simple type. If this is not the case, or you want to show the # methods anyway, you should set this option to NO. @@ -262,6 +303,22 @@ SUBGROUPING = YES +# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and +# unions are shown inside the group in which they are included (e.g. using +# @ingroup) instead of on a separate page (for HTML and Man pages) or +# section (for LaTeX and RTF). + +INLINE_GROUPED_CLASSES = NO + +# When the INLINE_SIMPLE_STRUCTS tag is set to YES, structs, classes, and +# unions with only public data fields will be shown inline in the documentation +# of the scope in which they are defined (i.e. file, namespace, or group +# documentation), provided this scope is documented. If set to NO (the default), +# structs, classes, and unions are shown on a separate page (for HTML and Man +# pages) or section (for LaTeX and RTF). + +INLINE_SIMPLE_STRUCTS = NO + # When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum # is documented as struct, union, or enum with the name of the typedef. So # typedef struct TypeS {} TypeT, will appear in the documentation as a struct @@ -278,16 +335,27 @@ # For small to medium size projects (<1000 input files) the default value is # probably good enough. For larger projects a too small cache size can cause # doxygen to be busy swapping symbols to and from disk most of the time -# causing a significant performance penality. +# causing a significant performance penalty. # If the system has enough physical memory increasing the cache will improve the # performance by keeping more symbols in memory. Note that the value works on -# a logarithmic scale so increasing the size by one will rougly double the +# a logarithmic scale so increasing the size by one will roughly double the # memory usage. The cache size is given by this formula: # 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, -# corresponding to a cache size of 2^16 = 65536 symbols +# corresponding to a cache size of 2^16 = 65536 symbols. SYMBOL_CACHE_SIZE = 0 +# Similar to the SYMBOL_CACHE_SIZE the size of the symbol lookup cache can be +# set using LOOKUP_CACHE_SIZE. This cache is used to resolve symbols given +# their name and scope. Since this can be an expensive process and often the +# same symbol appear multiple times in the code, doxygen keeps a cache of +# pre-resolved symbols. If the cache is too small doxygen will become slower. +# If the cache is too large, memory is wasted. The cache size is given by this +# formula: 2^(16+LOOKUP_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols. + +LOOKUP_CACHE_SIZE = 0 + #--------------------------------------------------------------------------- # Build related configuration options #--------------------------------------------------------------------------- @@ -304,6 +372,11 @@ EXTRACT_PRIVATE = YES +# If the EXTRACT_PACKAGE tag is set to YES all members with package or internal +# scope will be included in the documentation. + +EXTRACT_PACKAGE = NO + # If the EXTRACT_STATIC tag is set to YES all static members of a file # will be included in the documentation. @@ -326,7 +399,7 @@ # extracted and appear in the documentation as a namespace called # 'anonymous_namespace{file}', where file will be replaced with the base # name of the file that contains the anonymous namespace. By default -# anonymous namespace are hidden. +# anonymous namespaces are hidden. EXTRACT_ANON_NSPACES = NO @@ -386,6 +459,12 @@ SHOW_INCLUDE_FILES = YES +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + # If the INLINE_INFO tag is set to YES (the default) then a tag [inline] # is inserted in the documentation for inline members. @@ -403,13 +482,23 @@ # by member name. If set to NO (the default) the members will appear in # declaration order. -SORT_BRIEF_DOCS = YES +SORT_BRIEF_DOCS = NO + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO # If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the # hierarchy of group names into alphabetical order. If set to NO (the default) # the group names will appear in their defined order. -SORT_GROUP_NAMES = YES +SORT_GROUP_NAMES = NO # If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be # sorted by fully-qualified names, including namespaces. If set to @@ -421,6 +510,15 @@ SORT_BY_SCOPE_NAME = YES +# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to +# do proper type resolution of all parameters of a function it will reject a +# match between the prototype and the implementation of a member function even +# if there is only one candidate or it is obvious which candidate to choose +# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen +# will still accept a match between prototype and implementation in such cases. + +STRICT_PROTO_MATCHING = NO + # The GENERATE_TODOLIST tag can be used to enable (YES) or # disable (NO) the todo list. This list is created by putting \todo # commands in the documentation. @@ -446,15 +544,16 @@ GENERATE_DEPRECATEDLIST= YES # The ENABLED_SECTIONS tag can be used to enable conditional -# documentation sections, marked by \if sectionname ... \endif. +# documentation sections, marked by \if section-label ... \endif +# and \cond section-label ... \endcond blocks. ENABLED_SECTIONS = # The MAX_INITIALIZER_LINES tag determines the maximum number of lines -# the initial value of a variable or define consists of for it to appear in +# the initial value of a variable or macro consists of for it to appear in # the documentation. If the initializer consists of more lines than specified # here it will be hidden. Use a value of 0 to hide initializers completely. -# The appearance of the initializer of individual variables and defines in the +# The appearance of the initializer of individual variables and macros in the # documentation can be controlled using \showinitializer or \hideinitializer # command in the documentation regardless of this setting. @@ -466,12 +565,6 @@ SHOW_USED_FILES = NO -# If the sources in your project are distributed over multiple directories -# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy -# in the documentation. The default is NO. - -SHOW_DIRECTORIES = YES - # Set the SHOW_FILES tag to NO to disable the generation of the Files page. # This will remove the Files entry from the Quick Index and from the # Folder Tree View (if specified). The default is YES. @@ -479,11 +572,10 @@ SHOW_FILES = YES # Set the SHOW_NAMESPACES tag to NO to disable the generation of the -# Namespaces page. -# This will remove the Namespaces entry from the Quick Index +# Namespaces page. This will remove the Namespaces entry from the Quick Index # and from the Folder Tree View (if specified). The default is YES. -SHOW_NAMESPACES = YES +SHOW_NAMESPACES = NO # The FILE_VERSION_FILTER tag can be used to specify a program or script that # doxygen should invoke to get the current version for each file (typically from @@ -495,15 +587,26 @@ FILE_VERSION_FILTER = -# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by -# doxygen. The layout file controls the global structure of the generated output files -# in an output format independent way. The create the layout file that represents -# doxygen's defaults, run doxygen with the -l option. You can optionally specify a -# file name after the option, if omitted DoxygenLayout.xml will be used as the name -# of the layout file. +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed +# by doxygen. The layout file controls the global structure of the generated +# output files in an output format independent way. To create the layout file +# that represents doxygen's defaults, run doxygen with the -l option. +# You can optionally specify a file name after the option, if omitted +# DoxygenLayout.xml will be used as the name of the layout file. LAYOUT_FILE = +# The CITE_BIB_FILES tag can be used to specify one or more bib files +# containing the references data. This must be a list of .bib files. The +# .bib extension is automatically appended if omitted. Using this command +# requires the bibtex tool to be installed. See also +# http://en.wikipedia.org/wiki/BibTeX for more info. For LaTeX the style +# of the bibliography can be controlled using LATEX_BIB_STYLE. To use this +# feature you need bibtex and perl available in the search path. Do not use +# file names with spaces, bibtex cannot handle them. + +CITE_BIB_FILES = + #--------------------------------------------------------------------------- # configuration options related to warning and progress messages #--------------------------------------------------------------------------- @@ -532,7 +635,7 @@ WARN_IF_DOC_ERROR = YES -# This WARN_NO_PARAMDOC option can be abled to get warnings for +# The WARN_NO_PARAMDOC option can be enabled to get warnings for # functions that are documented, but have no documentation for their parameters # or return value. If set to NO (the default) doxygen will only warn about # wrong or incomplete parameter documentation, but not about the absence of @@ -564,11 +667,7 @@ # directories like "/usr/src/myproject". Separate the files or directories # with spaces. -INPUT = H \ - interfaces \ - frontends/CsoundVST \ - frontends/CsoundAC \ - frontends/tclcsound +INPUT = include # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is @@ -582,14 +681,15 @@ # FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp # and *.h) to filter out the source-files in the directories. If left # blank the following patterns are tested: -# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx -# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 - -FILE_PATTERNS = *.h \ - *.hh \ - *.hxx \ - *.hpp \ - *.h++ +# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh +# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py +# *.f90 *.f *.for *.vhd *.vhdl + +FILE_PATTERNS = csound.h \ + csound.hpp \ + csoundCore.h \ + cscore.h \ + csdl.h # The RECURSIVE tag can be used to turn specify whether or not subdirectories # should be searched for input files as well. Possible values are YES and NO. @@ -597,14 +697,16 @@ RECURSIVE = NO -# The EXCLUDE tag can be used to specify files and/or directories that should +# The EXCLUDE tag can be used to specify files and/or directories that should be # excluded from the INPUT source files. This way you can easily exclude a -# subdirectory from a directory tree whose root is specified with the INPUT tag. +# subdirectory from a directory tree whose root is specified with the INPUT tag. +# Note that relative paths are relative to the directory from which doxygen is +# run. EXCLUDE = -# The EXCLUDE_SYMLINKS tag can be used select whether or not files or -# directories that are symbolic links (a Unix filesystem feature) are excluded +# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or +# directories that are symbolic links (a Unix file system feature) are excluded # from the input. EXCLUDE_SYMLINKS = NO @@ -660,20 +762,17 @@ # by executing (via popen()) the command , where # is the value of the INPUT_FILTER tag, and is the name of an # input file. Doxygen will then use the output that the filter program writes -# to standard output. -# If FILTER_PATTERNS is specified, this tag will be +# to standard output. If FILTER_PATTERNS is specified, this tag will be # ignored. INPUT_FILTER = # The FILTER_PATTERNS tag can be used to specify filters on a per file pattern -# basis. -# Doxygen will compare the file name with each pattern and apply the -# filter if there is a match. -# The filters are a list of the form: +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: # pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further -# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER -# is applied to all files. +# info on how filters are used. If FILTER_PATTERNS is empty or if +# non of the patterns match the file name, INPUT_FILTER is applied. FILTER_PATTERNS = @@ -683,6 +782,21 @@ FILTER_SOURCE_FILES = NO +# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file +# pattern. A pattern will override the setting for FILTER_PATTERN (if any) +# and it is also possible to disable source filtering for a specific pattern +# using *.ext= (so without naming a filter). This option only has effect when +# FILTER_SOURCE_FILES is enabled. + +FILTER_SOURCE_PATTERNS = + +# If the USE_MD_FILE_AS_MAINPAGE tag refers to the name of a markdown file that +# is part of the input, its contents will be placed on the main page (index.html). +# This can be useful if you have a project on for instance GitHub and want reuse +# the introduction page also for the doxygen output. + +USE_MDFILE_AS_MAINPAGE = + #--------------------------------------------------------------------------- # configuration options related to source browsing #--------------------------------------------------------------------------- @@ -701,7 +815,7 @@ # Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct # doxygen to hide any special comment blocks from generated source code -# fragments. Normal C and C++ comments will always remain visible. +# fragments. Normal C, C++ and Fortran comments will always remain visible. STRIP_CODE_COMMENTS = YES @@ -720,8 +834,7 @@ # If the REFERENCES_LINK_SOURCE tag is set to YES (the default) # and SOURCE_BROWSER tag is set to YES, then the hyperlinks from # functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will -# link to the source code. -# Otherwise they will link to the documentation. +# link to the source code. Otherwise they will link to the documentation. REFERENCES_LINK_SOURCE = YES @@ -785,7 +898,14 @@ # The HTML_HEADER tag can be used to specify a personal HTML header for # each generated HTML page. If it is left blank doxygen will generate a -# standard header. +# standard header. Note that when using a custom header you are responsible +# for the proper inclusion of any scripts and style sheets that doxygen +# needs, which is dependent on the configuration options used. +# It is advised to generate a default header using "doxygen -w html +# header.html footer.html stylesheet.css YourConfigFile" and then modify +# that header. Note that the header is subject to change so you typically +# have to redo this when upgrading to a newer version of doxygen or when +# changing the value of configuration settings such as GENERATE_TREEVIEW! HTML_HEADER = @@ -797,27 +917,80 @@ # The HTML_STYLESHEET tag can be used to specify a user-defined cascading # style sheet that is used by each HTML page. It can be used to -# fine-tune the look of the HTML output. If the tag is left blank doxygen -# will generate a default style sheet. Note that doxygen will try to copy -# the style sheet file to the HTML output directory, so don't put your own -# stylesheet in the HTML output directory as well, or it will be erased! +# fine-tune the look of the HTML output. If left blank doxygen will +# generate a default style sheet. Note that it is recommended to use +# HTML_EXTRA_STYLESHEET instead of this one, as it is more robust and this +# tag will in the future become obsolete. HTML_STYLESHEET = -# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, -# files or namespaces will be aligned in HTML using tables. If set to -# NO a bullet list will be used. +# The HTML_EXTRA_STYLESHEET tag can be used to specify an additional +# user-defined cascading style sheet that is included after the standard +# style sheets created by doxygen. Using this option one can overrule +# certain style aspects. This is preferred over using HTML_STYLESHEET +# since it does not replace the standard style sheet and is therefor more +# robust against future updates. Doxygen will copy the style sheet file to +# the output directory. + +HTML_EXTRA_STYLESHEET = + +# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or +# other source files which should be copied to the HTML output directory. Note +# that these files will be copied to the base HTML output directory. Use the +# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these +# files. In the HTML_STYLESHEET file, use the file name only. Also note that +# the files will be copied as-is; there are no commands or markers available. + +HTML_EXTRA_FILES = + +# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output. +# Doxygen will adjust the colors in the style sheet and background images +# according to this color. Hue is specified as an angle on a colorwheel, +# see http://en.wikipedia.org/wiki/Hue for more information. +# For instance the value 0 represents red, 60 is yellow, 120 is green, +# 180 is cyan, 240 is blue, 300 purple, and 360 is red again. +# The allowed range is 0 to 359. + +HTML_COLORSTYLE_HUE = 220 + +# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of +# the colors in the HTML output. For a value of 0 the output will use +# grayscales only. A value of 255 will produce the most vivid colors. + +HTML_COLORSTYLE_SAT = 100 + +# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to +# the luminance component of the colors in the HTML output. Values below +# 100 gradually make the output lighter, whereas values above 100 make +# the output darker. The value divided by 100 is the actual gamma applied, +# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2, +# and 100 does not change the gamma. + +HTML_COLORSTYLE_GAMMA = 80 + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. -HTML_ALIGN_MEMBERS = YES +HTML_TIMESTAMP = YES # If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML # documentation will contain sections that can be hidden and shown after the -# page has loaded. For this to work a browser that supports -# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox -# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). +# page has loaded. HTML_DYNAMIC_SECTIONS = YES +# With HTML_INDEX_NUM_ENTRIES one can control the preferred number of +# entries shown in the various tree structured indices initially; the user +# can expand and collapse entries dynamically later on. Doxygen will expand +# the tree to such a level that at most the specified number of entries are +# visible (unless a fully collapsed tree already exceeds this amount). +# So setting the number of entries 1 will produce a full collapsed tree by +# default. 0 is a special value representing an infinite number of entries +# and will result in a full expanded tree by default. + +HTML_INDEX_NUM_ENTRIES = 100 + # If the GENERATE_DOCSET tag is set to YES, additional index files # will be generated that can be used as input for Apple's Xcode 3 # integrated development environment, introduced with OSX 10.5 (Leopard). @@ -826,7 +999,8 @@ # directory and running "make install" will install the docset in # ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find # it at startup. -# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html +# for more information. GENERATE_DOCSET = NO @@ -844,6 +1018,16 @@ DOCSET_BUNDLE_ID = org.doxygen.Project +# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely +# identify the documentation publisher. This should be a reverse domain-name +# style string, e.g. com.mycompany.MyDocSet.documentation. + +DOCSET_PUBLISHER_ID = org.doxygen.Publisher + +# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher. + +DOCSET_PUBLISHER_NAME = Publisher + # If the GENERATE_HTMLHELP tag is set to YES, additional index files # will be generated that can be used as input for tools like the # Microsoft HTML help workshop to generate a compiled HTML help file (.chm) @@ -888,10 +1072,10 @@ TOC_EXPAND = NO -# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER -# are set, an additional index file will be generated that can be used as input for -# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated -# HTML documentation. +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and +# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated +# that can be used as input for Qt's qhelpgenerator to generate a +# Qt Compressed Help (.qch) of the generated HTML documentation. GENERATE_QHP = NO @@ -905,7 +1089,7 @@ # Qt Help Project output. For more information please see # http://doc.trolltech.com/qthelpproject.html#namespace -QHP_NAMESPACE = +QHP_NAMESPACE = org.doxygen.Project # The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating # Qt Help Project output. For more information please see @@ -913,20 +1097,24 @@ QHP_VIRTUAL_FOLDER = doc -# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. -# For more information please see +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to +# add. For more information please see # http://doc.trolltech.com/qthelpproject.html#custom-filters QHP_CUST_FILTER_NAME = -# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see -# Qt Help Project / Custom Filters. +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the +# custom filter to add. For more information please see +# +# Qt Help Project / Custom Filters. QHP_CUST_FILTER_ATTRS = -# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this +# project's # filter section matches. -# Qt Help Project / Filter Attributes. +# +# Qt Help Project / Filter Attributes. QHP_SECT_FILTER_ATTRS = @@ -937,40 +1125,61 @@ QHG_LOCATION = -# The DISABLE_INDEX tag can be used to turn on/off the condensed index at -# top of each HTML page. The value NO (the default) enables the index and -# the value YES disables it. +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index (tabs) +# at top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. Since the tabs have the same information as the +# navigation tree you can set this option to NO if you already set +# GENERATE_TREEVIEW to YES. DISABLE_INDEX = NO -# This tag can be used to set the number of enum values (range [1..20]) -# that doxygen will group on one line in the generated HTML documentation. - -ENUM_VALUES_PER_LINE = 4 - # The GENERATE_TREEVIEW tag is used to specify whether a tree-like index # structure should be generated to display hierarchical information. -# If the tag value is set to FRAME, a side panel will be generated +# If the tag value is set to YES, a side panel will be generated # containing a tree-like index structure (just like the one that # is generated for HTML Help). For this to work a browser that supports -# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, -# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are -# probably better off using the HTML help feature. Other possible values -# for this tag are: HIERARCHIES, which will generate the Groups, Directories, -# and Class Hierarchy pages using a tree view instead of an ordered list; -# ALL, which combines the behavior of FRAME and HIERARCHIES; and NONE, which -# disables this behavior completely. For backwards compatibility with previous -# releases of Doxygen, the values YES and NO are equivalent to FRAME and NONE -# respectively. +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. +# Since the tree basically has the same information as the tab index you +# could consider to set DISABLE_INDEX to NO when enabling this option. GENERATE_TREEVIEW = NO +# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values +# (range [0,1..20]) that doxygen will group on one line in the generated HTML +# documentation. Note that a value of 0 will completely suppress the enum +# values from appearing in the overview section. + +ENUM_VALUES_PER_LINE = 4 + # If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be # used to set the initial width (in pixels) of the frame in which the tree # is shown. TREEVIEW_WIDTH = 250 +# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open +# links to external symbols imported via tag files in a separate window. + +EXT_LINKS_IN_WINDOW = NO + # Use this tag to change the font size of Latex formulas included # as images in the HTML documentation. The default is 10. Note that # when you change the font size after a successful doxygen run you need @@ -979,6 +1188,106 @@ FORMULA_FONTSIZE = 10 +# Use the FORMULA_TRANPARENT tag to determine whether or not the images +# generated for formulas are transparent PNGs. Transparent PNGs are +# not supported properly for IE 6.0, but are supported on all modern browsers. +# Note that when changing this option you need to delete any form_*.png files +# in the HTML output before the changes have effect. + +FORMULA_TRANSPARENT = YES + +# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax +# (see http://www.mathjax.org) which uses client side Javascript for the +# rendering instead of using prerendered bitmaps. Use this if you do not +# have LaTeX installed or if you want to formulas look prettier in the HTML +# output. When enabled you may also need to install MathJax separately and +# configure the path to it using the MATHJAX_RELPATH option. + +USE_MATHJAX = NO + +# When MathJax is enabled you can set the default output format to be used for +# thA MathJax output. Supported types are HTML-CSS, NativeMML (i.e. MathML) and +# SVG. The default value is HTML-CSS, which is slower, but has the best +# compatibility. + +MATHJAX_FORMAT = HTML-CSS + +# When MathJax is enabled you need to specify the location relative to the +# HTML output directory using the MATHJAX_RELPATH option. The destination +# directory should contain the MathJax.js script. For instance, if the mathjax +# directory is located at the same level as the HTML output directory, then +# MATHJAX_RELPATH should be ../mathjax. The default value points to +# the MathJax Content Delivery Network so you can quickly see the result without +# installing MathJax. However, it is strongly recommended to install a local +# copy of MathJax from http://www.mathjax.org before deployment. + +MATHJAX_RELPATH = http://cdn.mathjax.org/mathjax/latest + +# The MATHJAX_EXTENSIONS tag can be used to specify one or MathJax extension +# names that should be enabled during MathJax rendering. + +MATHJAX_EXTENSIONS = + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = YES + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a web server instead of a web client using Javascript. +# There are two flavours of web server based search depending on the +# EXTERNAL_SEARCH setting. When disabled, doxygen will generate a PHP script for +# searching and an index file used by the script. When EXTERNAL_SEARCH is +# enabled the indexing and searching needs to be provided by external tools. +# See the manual for details. + +SERVER_BASED_SEARCH = NO + +# When EXTERNAL_SEARCH is enabled doxygen will no longer generate the PHP +# script for searching. Instead the search results are written to an XML file +# which needs to be processed by an external indexer. Doxygen will invoke an +# external search engine pointed to by the SEARCHENGINE_URL option to obtain +# the search results. Doxygen ships with an example indexer (doxyindexer) and +# search engine (doxysearch.cgi) which are based on the open source search engine +# library Xapian. See the manual for configuration details. + +EXTERNAL_SEARCH = NO + +# The SEARCHENGINE_URL should point to a search engine hosted by a web server +# which will returned the search results when EXTERNAL_SEARCH is enabled. +# Doxygen ships with an example search engine (doxysearch) which is based on +# the open source search engine library Xapian. See the manual for configuration +# details. + +SEARCHENGINE_URL = + +# When SERVER_BASED_SEARCH and EXTERNAL_SEARCH are both enabled the unindexed +# search data is written to a file for indexing by an external tool. With the +# SEARCHDATA_FILE tag the name of this file can be specified. + +SEARCHDATA_FILE = searchdata.xml + +# When SERVER_BASED_SEARCH AND EXTERNAL_SEARCH are both enabled the +# EXTERNAL_SEARCH_ID tag can be used as an identifier for the project. This is +# useful in combination with EXTRA_SEARCH_MAPPINGS to search through multiple +# projects and redirect the results back to the right project. + +EXTERNAL_SEARCH_ID = + +# The EXTRA_SEARCH_MAPPINGS tag can be used to enable searching through doxygen +# projects other than the one defined by this configuration file, but that are +# all added to the same external search index. Each project needs to have a +# unique id set via EXTERNAL_SEARCH_ID. The search mapping then maps the id +# of to a relative location where the documentation can be found. +# The format is: EXTRA_SEARCH_MAPPINGS = id1=loc1 id2=loc2 ... + +EXTRA_SEARCH_MAPPINGS = + #--------------------------------------------------------------------------- # configuration options related to the LaTeX output #--------------------------------------------------------------------------- @@ -995,7 +1304,10 @@ LATEX_OUTPUT = latex # The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be -# invoked. If left blank `latex' will be used as the default command name. +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. LATEX_CMD_NAME = pdflatex @@ -1012,7 +1324,7 @@ COMPACT_LATEX = NO # The PAPER_TYPE tag can be used to set the paper type that is used -# by the printer. Possible values are: a4, a4wide, letter, legal and +# by the printer. Possible values are: a4, letter, legal and # executive. If left blank a4wide will be used. PAPER_TYPE = letter @@ -1027,7 +1339,14 @@ # the first chapter. If it is left blank doxygen will generate a # standard header. Notice: only use this tag if you know what you are doing! -LATEX_HEADER = refman_header.tex +LATEX_HEADER = + +# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for +# the generated latex document. The footer should contain everything after +# the last chapter. If it is left blank doxygen will generate a +# standard footer. Notice: only use this tag if you know what you are doing! + +LATEX_FOOTER = # If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated # is prepared for conversion to pdf (using ps2pdf). The pdf file will @@ -1055,6 +1374,19 @@ LATEX_HIDE_INDICES = NO +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +# The LATEX_BIB_STYLE tag can be used to specify the style to use for the +# bibliography, e.g. plainnat, or ieeetr. The default style is "plain". See +# http://en.wikipedia.org/wiki/BibTeX for more info. + +LATEX_BIB_STYLE = plain + #--------------------------------------------------------------------------- # configuration options related to the RTF output #--------------------------------------------------------------------------- @@ -1086,7 +1418,7 @@ RTF_HYPERLINKS = NO -# Load stylesheet definitions from file. Syntax is similar to doxygen's +# Load style sheet definitions from file. Syntax is similar to doxygen's # config file, i.e. a series of assignments. You only have to provide # replacements, missing definitions are set to their default value. @@ -1191,10 +1523,8 @@ PERLMOD_LATEX = NO # If the PERLMOD_PRETTY tag is set to YES the Perl module output will be -# nicely formatted so it can be parsed by a human reader. -# This is useful -# if you want to understand what is going on. -# On the other hand, if this +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this # tag is set to NO the size of the Perl module output will be much smaller # and Perl will parse it just the same. @@ -1208,7 +1538,7 @@ PERLMOD_MAKEVAR_PREFIX = #--------------------------------------------------------------------------- -# Configuration options related to the preprocessor +# Configuration options related to the preprocessor #--------------------------------------------------------------------------- # If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will @@ -1231,7 +1561,7 @@ EXPAND_ONLY_PREDEF = NO # If the SEARCH_INCLUDES tag is set to YES (the default) the includes files -# in the INCLUDE_PATH (see below) will be search if a #include is found. +# pointed to by INCLUDE_PATH will be searched when a #include is found. SEARCH_INCLUDES = YES @@ -1256,43 +1586,37 @@ # undefined via #undef or recursively expanded use the := operator # instead of the = operator. -PREDEFINED = +PREDEFINED = __BUILDING_LIBCSOUND # If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then # this tag can be used to specify a list of macro names that should be expanded. # The macro definition that is found in the sources will be used. -# Use the PREDEFINED tag if you want to use a different macro definition. +# Use the PREDEFINED tag if you want to use a different macro definition that +# overrules the definition found in the source code. EXPAND_AS_DEFINED = # If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then -# doxygen's preprocessor will remove all function-like macros that are alone -# on a line, have an all uppercase name, and do not end with a semicolon. Such -# function macros are typically used for boiler-plate code, and will confuse -# the parser if not removed. +# doxygen's preprocessor will remove all references to function-like macros +# that are alone on a line, have an all uppercase name, and do not end with a +# semicolon, because these will confuse the parser if not removed. SKIP_FUNCTION_MACROS = YES #--------------------------------------------------------------------------- -# Configuration::additions related to external references +# Configuration::additions related to external references #--------------------------------------------------------------------------- -# The TAGFILES option can be used to specify one or more tagfiles. -# Optionally an initial location of the external documentation -# can be added for each tagfile. The format of a tag file without -# this location is as follows: -# -# TAGFILES = file1 file2 ... +# The TAGFILES option can be used to specify one or more tagfiles. For each +# tag file the location of the external documentation should be added. The +# format of a tag file without this location is as follows: +# TAGFILES = file1 file2 ... # Adding location for the tag files is done as follows: -# -# TAGFILES = file1=loc1 "file2 = loc2" ... -# where "loc1" and "loc2" can be relative or absolute paths or -# URLs. If a location is present for each tag, the installdox tool -# does not have to be run to correct the links. -# Note that each tag file must have a unique name -# (where the name does NOT include the path) -# If a tag file is not located in the directory in which doxygen -# is run, you must also specify the path to the tagfile here. +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths +# or URLs. Note that each tag file must have a unique name (where the name does +# NOT include the path). If a tag file is not located in the directory in which +# doxygen is run, you must also specify the path to the tagfile here. TAGFILES = @@ -1319,15 +1643,14 @@ PERL_PATH = /usr/bin/perl #--------------------------------------------------------------------------- -# Configuration options related to the dot tool +# Configuration options related to the dot tool #--------------------------------------------------------------------------- # If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will # generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base # or super classes. Setting the tag to NO turns the diagrams off. Note that -# this option is superseded by the HAVE_DOT option below. This is only a -# fallback. It is recommended to install and use dot, since it yields more -# powerful graphs. +# this option also works with HAVE_DOT disabled, but it is recommended to +# install and use dot, since it yields more powerful graphs. CLASS_DIAGRAMS = NO @@ -1353,14 +1676,20 @@ HAVE_DOT = YES -# By default doxygen will write a font called FreeSans.ttf to the output -# directory and reference it in all dot files that doxygen generates. This -# font does not include all possible unicode characters however, so when you need -# these (or just want a differently looking font) you can specify the font name -# using DOT_FONTNAME. You need need to make sure dot is able to find the font, -# which can be done by putting it in a standard location or by setting the -# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory -# containing the font. +# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is +# allowed to run in parallel. When set to 0 (the default) doxygen will +# base this on the number of processors available in the system. You can set it +# explicitly to a value larger than 0 to get control over the balance +# between CPU load and processing speed. + +DOT_NUM_THREADS = 0 + +# By default doxygen will use the Helvetica font for all dot files that +# doxygen generates. When you want a differently looking font you can specify +# the font name using DOT_FONTNAME. You need to make sure dot is able to find +# the font, which can be done by putting it in a standard location or by setting +# the DOTFONTPATH environment variable or by setting DOT_FONTPATH to the +# directory containing the font. DOT_FONTNAME = FreeSans @@ -1369,17 +1698,16 @@ DOT_FONTSIZE = 10 -# By default doxygen will tell dot to use the output directory to look for the -# FreeSans.ttf font (which doxygen will put there itself). If you specify a -# different font using DOT_FONTNAME you can set the path where dot -# can find it using this tag. +# By default doxygen will tell dot to use the Helvetica font. +# If you specify a different font using DOT_FONTNAME you can use DOT_FONTPATH to +# set the path where dot can find it. DOT_FONTPATH = # If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen # will generate a graph for each documented class showing the direct and # indirect inheritance relations. Setting this tag to YES will force the -# the CLASS_DIAGRAMS tag to NO. +# CLASS_DIAGRAMS tag to NO. CLASS_GRAPH = YES @@ -1401,6 +1729,15 @@ UML_LOOK = NO +# If the UML_LOOK tag is enabled, the fields and methods are shown inside +# the class node. If there are many fields or methods and many nodes the +# graph may become too big to be useful. The UML_LIMIT_NUM_FIELDS +# threshold limits the number of items for each type to make the size more +# managable. Set this to 0 for no limit. Note that the threshold may be +# exceeded by 50% before the limit is enforced. + +UML_LIMIT_NUM_FIELDS = 10 + # If set to YES, the inheritance and collaboration graphs will show the # relations between templates and their instances. @@ -1437,11 +1774,11 @@ CALLER_GRAPH = NO # If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen -# will graphical hierarchy of all classes instead of a textual one. +# will generate a graphical hierarchy of all classes instead of a textual one. GRAPHICAL_HIERARCHY = YES -# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# If the DIRECTORY_GRAPH and HAVE_DOT tags are set to YES # then doxygen will show the dependencies a directory has on other directories # in a graphical way. The dependency relations are determined by the #include # relations between the files in the directories. @@ -1449,11 +1786,22 @@ DIRECTORY_GRAPH = YES # The DOT_IMAGE_FORMAT tag can be used to set the image format of the images -# generated by dot. Possible values are png, jpg, or gif -# If left blank png will be used. +# generated by dot. Possible values are svg, png, jpg, or gif. +# If left blank png will be used. If you choose svg you need to set +# HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible in IE 9+ (other browsers do not have this requirement). DOT_IMAGE_FORMAT = png +# If DOT_IMAGE_FORMAT is set to svg, then this option can be set to YES to +# enable generation of interactive SVG images that allow zooming and panning. +# Note that this requires a modern browser other than Internet Explorer. +# Tested and working are Firefox, Chrome, Safari, and Opera. For IE 9+ you +# need to set HTML_FILE_EXTENSION to xhtml in order to make the SVG files +# visible. Older versions of IE do not have SVG support. + +INTERACTIVE_SVG = NO + # The tag DOT_PATH can be used to specify the path where the dot tool can be # found. If left blank, it is assumed the dot tool can be found in the path. @@ -1465,6 +1813,12 @@ DOTFILE_DIRS = +# The MSCFILE_DIRS tag can be used to specify one or more directories that +# contain msc files that are included in the documentation (see the +# \mscfile command). + +MSCFILE_DIRS = + # The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of # nodes that will be shown in the graph. If the number of nodes in a graph # becomes larger than this value, doxygen will truncate the graph, which is @@ -1511,12 +1865,3 @@ # the various graphs. DOT_CLEANUP = YES - -#--------------------------------------------------------------------------- -# Options related to the search engine -#--------------------------------------------------------------------------- - -# The SEARCHENGINE tag specifies whether or not a search engine should be -# used. If set to NO the values of all tags below this one will be ignored. - -SEARCHENGINE = NO diff -Nru csound-5.17.11~dfsg/Doxyfile-CsoundAC csound-6.02~dfsg/Doxyfile-CsoundAC --- csound-5.17.11~dfsg/Doxyfile-CsoundAC 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Doxyfile-CsoundAC 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,1572 @@ +# Doxyfile 1.6.3 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# This tag specifies the encoding used for all characters in the config file +# that follow. The default is UTF-8 which is also the encoding used for all +# text before the first occurrence of this tag. Doxygen uses libiconv (or the +# iconv built into libc) for the transcoding. See +# http://www.gnu.org/software/libiconv for the list of possible encodings. + +DOXYFILE_ENCODING = UTF-8 + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = "CsoundAC API" + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 6.00 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc/csoundac + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional, +# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German, +# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English +# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian, +# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrilic, Slovak, +# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese. + +OUTPUT_LANGUAGE = English + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = NO + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = YES + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = YES + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like regular Qt-style comments +# (thus requiring an explicit @brief command for a brief description.) + +JAVADOC_AUTOBRIEF = YES + +# If the QT_AUTOBRIEF tag is set to YES then Doxygen will +# interpret the first line (until the first dot) of a Qt-style +# comment as the brief description. If set to NO, the comments +# will behave just like regular Qt-style comments (thus requiring +# an explicit \brief command for a brief description.) + +QT_AUTOBRIEF = NO + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 4 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = YES + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for +# Java. For instance, namespaces will be presented as packages, qualified +# scopes will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran +# sources only. Doxygen will then generate output that is more tailored for +# Fortran. + +OPTIMIZE_FOR_FORTRAN = NO + +# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL +# sources. Doxygen will then generate output that is tailored for +# VHDL. + +OPTIMIZE_OUTPUT_VHDL = NO + +# Doxygen selects the parser to use depending on the extension of the files it parses. +# With this tag you can assign which parser to use for a given extension. +# Doxygen has a built-in mapping, but you can override or extend it using this tag. +# The format is ext=language, where ext is a file extension, and language is one of +# the parsers supported by doxygen: IDL, Java, Javascript, C#, C, C++, D, PHP, +# Objective-C, Python, Fortran, VHDL, C, C++. For instance to make doxygen treat +# .inc files as Fortran files (default is PHP), and .f files as C (default is Fortran), +# use: inc=Fortran f=C. Note that for custom extensions you also need to set +# FILE_PATTERNS otherwise the files are not read by doxygen. + +EXTENSION_MAPPING = YES + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want +# to include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = YES + +# If you use Microsoft's C++/CLI language, you should set this option to YES to +# enable parsing support. + +CPP_CLI_SUPPORT = NO + +# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only. +# Doxygen will parse them like normal C++ but will assume all classes use public +# instead of private inheritance when no explicit protection keyword is present. + +SIP_SUPPORT = NO + +# For Microsoft's IDL there are propget and propput attributes to indicate getter +# and setter methods for a property. Setting this option to YES (the default) +# will make doxygen to replace the get and set methods by a property in the +# documentation. This will only work if the methods are indeed getting or +# setting a simple type. If this is not the case, or you want to show the +# methods anyway, you should set this option to NO. + +IDL_PROPERTY_SUPPORT = YES + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum +# is documented as struct, union, or enum with the name of the typedef. So +# typedef struct TypeS {} TypeT, will appear in the documentation as a struct +# with name TypeT. When disabled the typedef will appear as a member of a file, +# namespace, or class. And the struct will be named TypeS. This can typically +# be useful for C code in case the coding convention dictates that all compound +# types are typedef'ed and only the typedef is referenced, never the tag name. + +TYPEDEF_HIDES_STRUCT = NO + +# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to +# determine which symbols to keep in memory and which to flush to disk. +# When the cache is full, less often used symbols will be written to disk. +# For small to medium size projects (<1000 input files) the default value is +# probably good enough. For larger projects a too small cache size can cause +# doxygen to be busy swapping symbols to and from disk most of the time +# causing a significant performance penality. +# If the system has enough physical memory increasing the cache will improve the +# performance by keeping more symbols in memory. Note that the value works on +# a logarithmic scale so increasing the size by one will rougly double the +# memory usage. The cache size is given by this formula: +# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0, +# corresponding to a cache size of 2^16 = 65536 symbols + +SYMBOL_CACHE_SIZE = 0 + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = YES + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = YES + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = YES + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If this flag is set to YES, the members of anonymous namespaces will be +# extracted and appear in the documentation as a namespace called +# 'anonymous_namespace{file}', where file will be replaced with the base +# name of the file that contains the anonymous namespace. By default +# anonymous namespace are hidden. + +EXTRACT_ANON_NSPACES = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen +# will list include files with double quotes in the documentation +# rather than with sharp brackets. + +FORCE_LOCAL_INCLUDES = NO + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = YES + +# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen +# will sort the (brief and detailed) documentation of class members so that +# constructors and destructors are listed first. If set to NO (the default) +# the constructors will appear in the respective orders defined by +# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS. +# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO +# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO. + +SORT_MEMBERS_CTORS_1ST = NO + +# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the +# hierarchy of group names into alphabetical order. If set to NO (the default) +# the group names will appear in their defined order. + +SORT_GROUP_NAMES = YES + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = YES + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = NO + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = YES + +# Set the SHOW_FILES tag to NO to disable the generation of the Files page. +# This will remove the Files entry from the Quick Index and from the +# Folder Tree View (if specified). The default is YES. + +SHOW_FILES = YES + +# Set the SHOW_NAMESPACES tag to NO to disable the generation of the +# Namespaces page. This will remove the Namespaces entry from the Quick Index +# and from the Folder Tree View (if specified). The default is YES. + +SHOW_NAMESPACES = YES + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from +# the version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed by +# doxygen. The layout file controls the global structure of the generated output files +# in an output format independent way. The create the layout file that represents +# doxygen's defaults, run doxygen with the -l option. You can optionally specify a +# file name after the option, if omitted DoxygenLayout.xml will be used as the name +# of the layout file. + +LAYOUT_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = NO + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = YES + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = H \ + interfaces \ + frontends/CsoundVST \ + frontends/CsoundAC \ + frontends/tclcsound + +# This tag can be used to specify the character encoding of the source files +# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is +# also the default input encoding. Doxygen uses libiconv (or the iconv built +# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for +# the list of possible encodings. + +INPUT_ENCODING = UTF-8 + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py *.f90 + +FILE_PATTERNS = *.h \ + *.hh \ + *.hxx \ + *.hpp \ + *.h++ + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = NO + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = AEff* \ + aeff* \ + AudioEff* \ + audioeff* \ + *wrap* + +# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names +# (namespaces, classes, functions, etc.) that should be excluded from the +# output. The symbol name can be a fully qualified name, a word, or if the +# wildcard * is used, a substring. Examples: ANamespace, AClass, +# AClass::ANamespace, ANamespace::*Test + +EXCLUDE_SYMBOLS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = NO + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = NO + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentation. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = YES + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML +# page will contain the date and time when the page was generated. Setting +# this to NO can help when comparing the output of multiple runs. + +HTML_TIMESTAMP = YES + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML +# documentation will contain sections that can be hidden and shown after the +# page has loaded. For this to work a browser that supports +# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox +# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari). + +HTML_DYNAMIC_SECTIONS = YES + +# If the GENERATE_DOCSET tag is set to YES, additional index files +# will be generated that can be used as input for Apple's Xcode 3 +# integrated development environment, introduced with OSX 10.5 (Leopard). +# To create a documentation set, doxygen will generate a Makefile in the +# HTML output directory. Running make will produce the docset in that +# directory and running "make install" will install the docset in +# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find +# it at startup. +# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html for more information. + +GENERATE_DOCSET = NO + +# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the +# feed. A documentation feed provides an umbrella under which multiple +# documentation sets from a single provider (such as a company or product suite) +# can be grouped. + +DOCSET_FEEDNAME = "Doxygen generated docs" + +# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that +# should uniquely identify the documentation set bundle. This should be a +# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen +# will append .docset to the name. + +DOCSET_BUNDLE_ID = org.doxygen.Project + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compiled HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING +# is used to encode HtmlHelp index (hhk), content (hhc) and project file +# content. + +CHM_INDEX_ENCODING = + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and QHP_VIRTUAL_FOLDER +# are set, an additional index file will be generated that can be used as input for +# Qt's qhelpgenerator to generate a Qt Compressed Help (.qch) of the generated +# HTML documentation. + +GENERATE_QHP = NO + +# If the QHG_LOCATION tag is specified, the QCH_FILE tag can +# be used to specify the file name of the resulting .qch file. +# The path specified is relative to the HTML output folder. + +QCH_FILE = + +# The QHP_NAMESPACE tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#namespace + +QHP_NAMESPACE = org.doxygen.Project + +# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating +# Qt Help Project output. For more information please see +# http://doc.trolltech.com/qthelpproject.html#virtual-folders + +QHP_VIRTUAL_FOLDER = doc + +# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to add. +# For more information please see +# http://doc.trolltech.com/qthelpproject.html#custom-filters + +QHP_CUST_FILTER_NAME = + +# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the custom filter to add.For more information please see +# Qt Help Project / Custom Filters. + +QHP_CUST_FILTER_ATTRS = + +# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this project's +# filter section matches. +# Qt Help Project / Filter Attributes. + +QHP_SECT_FILTER_ATTRS = + +# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can +# be used to specify the location of Qt's qhelpgenerator. +# If non-empty doxygen will try to run qhelpgenerator on the generated +# .qhp file. + +QHG_LOCATION = + +# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files +# will be generated, which together with the HTML files, form an Eclipse help +# plugin. To install this plugin and make it available under the help contents +# menu in Eclipse, the contents of the directory containing the HTML and XML +# files needs to be copied into the plugins directory of eclipse. The name of +# the directory within the plugins directory should be the same as +# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before +# the help appears. + +GENERATE_ECLIPSEHELP = NO + +# A unique identifier for the eclipse help plugin. When installing the plugin +# the directory name containing the HTML and XML files should also have +# this name. + +ECLIPSE_DOC_ID = org.doxygen.Project + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index +# structure should be generated to display hierarchical information. +# If the tag value is set to YES, a side panel will be generated +# containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser). +# Windows users are probably better off using the HTML help feature. + +GENERATE_TREEVIEW = NO + +# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories, +# and Class Hierarchy pages using a tree view instead of an ordered list. + +USE_INLINE_TREES = NO + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +# Use this tag to change the font size of Latex formulas included +# as images in the HTML documentation. The default is 10. Note that +# when you change the font size after a successful doxygen run you need +# to manually remove any form_*.png images from the HTML output directory +# to force them to be regenerated. + +FORMULA_FONTSIZE = 10 + +# When the SEARCHENGINE tag is enabled doxygen will generate a search box +# for the HTML output. The underlying search engine uses javascript +# and DHTML and should work on any modern browser. Note that when using +# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets +# (GENERATE_DOCSET) there is already a search function so this one should +# typically be disabled. For large projects the javascript based search engine +# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution. + +SEARCHENGINE = NO + +# When the SERVER_BASED_SEARCH tag is enabled the search engine will be +# implemented using a PHP enabled web server instead of at the web client +# using Javascript. Doxygen will generate the search PHP script and index +# file to put on the web server. The advantage of the server +# based approach is that it scales better to large projects and allows +# full text search. The disadvances is that it is more difficult to setup +# and does not have live searching capabilities. + +SERVER_BASED_SEARCH = NO + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. +# Note that when enabling USE_PDFLATEX this option is only used for +# generating bitmaps for formulas in the HTML output, but not in the +# Makefile that is written to the output directory. + +LATEX_CMD_NAME = pdflatex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = letter + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = YES + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = YES + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = YES + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +# If LATEX_SOURCE_CODE is set to YES then doxygen will include +# source code with syntax highlighting in the LaTeX output. +# Note that which sources are shown also depends on other settings +# such as SOURCE_BROWSER. + +LATEX_SOURCE_CODE = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = YES + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = NO + +# You can define message sequence charts within doxygen comments using the \msc +# command. Doxygen will then run the mscgen tool (see +# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the +# documentation. The MSCGEN_PATH tag allows you to specify the directory where +# the mscgen tool resides. If left empty the tool is assumed to be found in the +# default search path. + +MSCGEN_PATH = + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = YES + +# By default doxygen will write a font called FreeSans.ttf to the output +# directory and reference it in all dot files that doxygen generates. This +# font does not include all possible unicode characters however, so when you need +# these (or just want a differently looking font) you can specify the font name +# using DOT_FONTNAME. You need need to make sure dot is able to find the font, +# which can be done by putting it in a standard location or by setting the +# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory +# containing the font. + +DOT_FONTNAME = FreeSans + +# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs. +# The default size is 10pt. + +DOT_FONTSIZE = 10 + +# By default doxygen will tell dot to use the output directory to look for the +# FreeSans.ttf font (which doxygen will put there itself). If you specify a +# different font using DOT_FONTNAME you can set the path where dot +# can find it using this tag. + +DOT_FONTPATH = + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = NO + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = NO + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = NO + +# If the CALL_GRAPH and HAVE_DOT options are set to YES then +# doxygen will generate a call dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable call graphs +# for selected functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then +# doxygen will generate a caller dependency graph for every global function +# or class method. Note that enabling this option will significantly increase +# the time of a run. So in most cases it will be better to enable caller +# graphs for selected functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = D:\utah\opt\ATT\Graphviz\bin + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of +# nodes that will be shown in the graph. If the number of nodes in a graph +# becomes larger than this value, doxygen will truncate the graph, which is +# visualized by representing a node as a red box. Note that doxygen if the +# number of direct children of the root node in a graph is already larger than +# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note +# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH. + +DOT_GRAPH_MAX_NODES = 50 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that the size of a graph can be further restricted by +# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, because dot on Windows does not +# seem to support this out of the box. Warning: Depending on the platform used, +# enabling this option may lead to badly anti-aliased labels on the edges of +# a graph (i.e. they become hard to read). + +DOT_TRANSPARENT = YES + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = YES + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = NO + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES diff -Nru csound-5.17.11~dfsg/Engine/auxfd.c csound-6.02~dfsg/Engine/auxfd.c --- csound-5.17.11~dfsg/Engine/auxfd.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/auxfd.c 2014-01-07 16:53:47.000000000 +0000 @@ -33,7 +33,7 @@ { if (auxchp->auxp != NULL) { /* if allocd with same size, just clear to zero */ - if (nbytes == (int32)auxchp->size) { + if (nbytes == (size_t)auxchp->size) { memset(auxchp->auxp, 0, nbytes); return; } @@ -140,17 +140,17 @@ static CS_NOINLINE void auxchprint(CSOUND *csound, INSDS *ip) { AUXCH *curchp; - char *name = csound->instrtxtp[ip->insno]->insname; + char *name = csound->engineState.instrtxtp[ip->insno]->insname; if (name) - csound->Message(csound, Str("auxlist for instr %s [%d] (%p):\n"), + csoundMessage(csound, Str("auxlist for instr %s [%d] (%p):\n"), name, ip->insno, ip); else - csound->Message(csound, Str("auxlist for instr %d (%p):\n"), + csoundMessage(csound, Str("auxlist for instr %d (%p):\n"), ip->insno, ip); /* chain through auxlocs */ for (curchp = ip->auxchp; curchp != NULL; curchp = curchp->nxtchp) - csound->Message(csound, + csoundMessage(csound, Str("\tauxch at %p: size %ld, auxp %p, endp %p\n"), curchp, curchp->size, curchp->auxp, curchp->endp); } @@ -160,16 +160,16 @@ static CS_NOINLINE void fdchprint(CSOUND *csound, INSDS *ip) { FDCH *curchp; - char *name = csound->instrtxtp[ip->insno]->insname; + char *name = csound->engineState.instrtxtp[ip->insno]->insname; if (name) - csound->Message(csound, Str("fdlist for instr %s [%d] (%p):"), + csoundMessage(csound, Str("fdlist for instr %s [%d] (%p):"), name, ip->insno, ip); else - csound->Message(csound, Str("fdlist for instr %d (%p):"), ip->insno, ip); + csoundMessage(csound, Str("fdlist for instr %d (%p):"), ip->insno, ip); /* chain through fdlocs */ for (curchp = ip->fdchp; curchp != NULL; curchp = curchp->nxtchp) - csound->Message(csound, Str(" fd %p in %p"), curchp->fd, curchp); - csound->Message(csound, "\n"); + csoundMessage(csound, Str(" fd %p in %p"), curchp->fd, curchp); + csoundMessage(csound, "\n"); } diff -Nru csound-5.17.11~dfsg/Engine/cfgvar.c csound-6.02~dfsg/Engine/cfgvar.c --- csound-5.17.11~dfsg/Engine/cfgvar.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/cfgvar.c 2014-01-07 16:53:47.000000000 +0000 @@ -31,20 +31,6 @@ #include "cfgvar.h" #include "namedins.h" -/* faster version that assumes a non-empty string */ - -static inline unsigned char name_hash_(const char *s) -{ - const unsigned char *c = (const unsigned char*) &(s[0]); - unsigned int h = 0U; - do { - h = strhash_tabl_8[h ^ *c]; - } while (*(++c) != (unsigned char) '\0'); - return (unsigned char) h; -} - -#define local_cfg_db (((CSOUND*) csound)->cfgVariableDB) - /* the global database */ /* list of error messages */ @@ -137,7 +123,8 @@ * Return value is CSOUNDCFG_SUCCESS, or one of the error codes. */ -static int cfg_alloc_structure(csCfgVariable_t **ptr, +static int cfg_alloc_structure(CSOUND* csound, + csCfgVariable_t **ptr, const char *name, void *p, int type, int flags, void *min, void *max, @@ -172,7 +159,7 @@ ldBytes = (ldBytes + 15) & (~15); totBytes = structBytes + nameBytes + sdBytes + ldBytes; /* allocate memory */ - pp = (void*) malloc((size_t) totBytes); + pp = (void*) mmalloc(csound, (size_t) totBytes); if (UNLIKELY(pp == NULL)) return CSOUNDCFG_MEMORY; memset(pp, 0, (size_t) totBytes); @@ -239,84 +226,6 @@ } /** - * Create global configuration variable with the specified parameters. - * This function should be called by the host application only. - * name: name of the variable (may contain letters, digits, and _) - * p: pointer to variable - * type: type of variable, determines how 'p' is interpreted - * CSOUNDCFG_INTEGER: int* - * CSOUNDCFG_BOOLEAN: int* (value may be 0 or 1) - * CSOUNDCFG_FLOAT: float* - * CSOUNDCFG_DOUBLE: double* - * CSOUNDCFG_MYFLT: MYFLT* - * CSOUNDCFG_STRING: char* (should have enough space) - * flags: bitwise OR of flag values, currently only CSOUNDCFG_POWOFTWO - * is available, which requests CSOUNDCFG_INTEGER values to be - * power of two - * min: for CSOUNDCFG_INTEGER, CSOUNDCFG_FLOAT, CSOUNDCFG_DOUBLE, and - * CSOUNDCFG_MYFLT, a pointer to a variable of the type selected - * by 'type' that specifies the minimum allowed value. - * If 'min' is NULL, there is no minimum value. - * max: similar to 'min', except it sets the maximum allowed value. - * For CSOUNDCFG_STRING, it is a pointer to an int variable - * that defines the maximum length of the string (including the - * null character at the end) in bytes. This value is limited - * to the range 8 to 16384, and if max is NULL, it defaults to 256. - * shortDesc: a short description of the variable (may be NULL or an empty - * string if a description is not available) - * longDesc: a long description of the variable (may be NULL or an empty - * string if a description is not available) - * Return value is CSOUNDCFG_SUCCESS, or one of the following error codes: - * CSOUNDCFG_INVALID_NAME - * the specified name is invalid or is already in use - * CSOUNDCFG_MEMORY - * a memory allocation failure occured - * CSOUNDCFG_NULL_POINTER - * the 'p' pointer was NULL - * CSOUNDCFG_INVALID_TYPE - * CSOUNDCFG_INVALID_FLAG - * an invalid variable type was specified, or the flags value - * had unknown bits set - */ - -#if 0 -PUBLIC -int csoundCreateGlobalConfigurationVariable(const char *name, - void *p, int type, int flags, - void *min, void *max, - const char *shortDesc, - const char *longDesc) -{ - csCfgVariable_t *pp; - int i, retval; - unsigned char h; - - /* check if name is already in use */ - if (UNLIKELY(csoundQueryGlobalConfigurationVariable(name) != NULL)) - return CSOUNDCFG_INVALID_NAME; - /* if database is not allocated yet, create an empty one */ - if (global_cfg_db == NULL) { - global_cfg_db = (void**) malloc(sizeof(void*) * 256); - if (UNLIKELY(global_cfg_db == NULL)) - return CSOUNDCFG_MEMORY; - for (i = 0; i < 256; i++) - global_cfg_db[i] = (void*) NULL; - } - /* allocate structure */ - retval = cfg_alloc_structure(&pp, name, p, type, flags, min, max, - shortDesc, longDesc); - if (retval != CSOUNDCFG_SUCCESS) - return retval; - /* link into database */ - h = name_hash_(name); - pp->h.nxt = (csCfgVariable_t*) (global_cfg_db[(int) h]); - global_cfg_db[(int) h] = (void*) pp; - /* report success */ - return CSOUNDCFG_SUCCESS; -} -#endif - -/** * This function is similar to csoundCreateGlobalConfigurationVariable(), * except it creates a configuration variable specific to Csound instance * 'csound', and is suitable for calling from the Csound library @@ -333,280 +242,29 @@ const char *longDesc) { csCfgVariable_t *pp; - int i, retval; - unsigned char h; + int retval; /* check if name is already in use */ if (UNLIKELY(csoundQueryConfigurationVariable(csound, name) != NULL)) return CSOUNDCFG_INVALID_NAME; /* if database is not allocated yet, create an empty one */ - if (local_cfg_db == NULL) { - local_cfg_db = (void**) malloc(sizeof(void*) * 256); - if (UNLIKELY(local_cfg_db == NULL)) + if (csound->cfgVariableDB == NULL) { + csound->cfgVariableDB = cs_hash_table_create(csound); + if (UNLIKELY(csound->cfgVariableDB == NULL)) return CSOUNDCFG_MEMORY; - for (i = 0; i < 256; i++) - local_cfg_db[i] = (void*) NULL; } /* allocate structure */ - retval = cfg_alloc_structure(&pp, name, p, type, flags, min, max, + retval = cfg_alloc_structure(csound, &pp, name, p, type, flags, min, max, shortDesc, longDesc); if (UNLIKELY(retval != CSOUNDCFG_SUCCESS)) return retval; /* link into database */ - h = name_hash_(name); - pp->h.nxt = (csCfgVariable_t*) (local_cfg_db[(int) h]); - local_cfg_db[(int) h] = (void*) pp; - /* report success */ - return CSOUNDCFG_SUCCESS; -} - -/* returns non-zero if x and y are equal within maxerr error */ -#if 0 -static int compare_floats(double x, double y, double maxerr) -{ - /* trivial case */ - if (x == y) - return 1; - /* if only one of x and y is zero, then not equal */ - if (x == 0.0 || y == 0.0) { - if (x == 0.0 && y == 0.0) - return 1; - else - return 0; - } - /* different sign: not equal */ - if ((x < 0.0 && y > 0.0) || (x > 0.0 && y < 0.0)) - return 0; - /* fuzzy compare */ - if (fabs((x / y) - 1.0) < maxerr) - return 1; - return 0; -} -#endif + cs_hash_table_put(csound, csound->cfgVariableDB, (char*)name, pp); -/* Test if two existing configuration variables are compatible, that is, */ -/* they have the same type, flags, descriptions, and limit values. */ -/* Return value is non-zero if the two variables are compatible. */ - -#if 0 -static int are_cfgvars_compatible(csCfgVariable_t *p1, csCfgVariable_t *p2) -{ - if (p1->h.type != p2->h.type || p1->h.flags != p2->h.flags) - return 0; - if (p1->h.shortDesc != NULL && p2->h.shortDesc != NULL) { - if (strcmp((char*) p1->h.shortDesc, (char*) p2->h.shortDesc) != 0) - return 0; - } - else if (!(p1->h.shortDesc == NULL && p2->h.shortDesc == NULL)) - return 0; - if (p1->h.longDesc != NULL && p2->h.longDesc != NULL) { - if (strcmp((char*) p1->h.longDesc, (char*) p2->h.longDesc) != 0) - return 0; - } - else if (!(p1->h.longDesc == NULL && p2->h.longDesc == NULL)) - return 0; - switch (p1->h.type) { - case CSOUNDCFG_INTEGER: - if (p1->i.min != p2->i.min || p1->i.max != p2->i.max) - return 0; - break; - case CSOUNDCFG_BOOLEAN: - break; - case CSOUNDCFG_FLOAT: - if (!compare_floats((double) p1->f.min, (double) p2->f.min, 1.0e-6) || - !compare_floats((double) p1->f.max, (double) p2->f.max, 1.0e-6)) - return 0; - break; - case CSOUNDCFG_DOUBLE: - if (!compare_floats((double) p1->d.min, (double) p2->d.min, 1.0e-12) || - !compare_floats((double) p1->d.max, (double) p2->d.max, 1.0e-12)) - return 0; - break; - case CSOUNDCFG_MYFLT: -#ifdef USE_DOUBLE - if (!compare_floats((double) p1->m.min, (double) p2->m.min, 1.0e-12) || - !compare_floats((double) p1->m.max, (double) p2->m.max, 1.0e-12)) - return 0; -#else - if (!compare_floats((double) p1->m.min, (double) p2->m.min, 1.0e-6) || - !compare_floats((double) p1->m.max, (double) p2->m.max, 1.0e-6)) - return 0; -#endif - break; - case CSOUNDCFG_STRING: - if (p1->s.maxlen != p2->s.maxlen) - return 0; - break; - default: - return 0; - } - return 1; -} -#endif - -/** - * Copy a global configuration variable to a Csound instance. - * This function is experimental and may be subject to changes in - * future releases of the Csound library. - */ - -#if 0 -PUBLIC int csoundCopyGlobalConfigurationVariable(CSOUND *csound, - const char *name, - void *p) -{ - csCfgVariable_t *pp, *lp; - char *sdp, *ldp; - int j, type, flags; - - /* look up global configuration variable */ - pp = csoundQueryGlobalConfigurationVariable(name); - if (UNLIKELY(pp == NULL)) - return CSOUNDCFG_INVALID_NAME; - - /* check if a local configuration variable with this name already exists */ - lp = csoundQueryConfigurationVariable(csound, name); - if (lp != NULL) { - /* found one, find out if it is compatible */ - if (UNLIKELY(!are_cfgvars_compatible(lp, pp))) - return CSOUNDCFG_INVALID_NAME; /* no, report error */ - /* if a new data pointer was specified, store it */ - if (p != NULL) - lp->h.p = p; - else - p = lp->h.p; /* otherwise, get it from the existing variable */ - } - else { - /* create new local configuration variable */ - if (UNLIKELY(p == NULL)) - return CSOUNDCFG_NULL_POINTER; /* must have a valid data pointer */ - type = pp->h.type; - flags = pp->h.flags; - sdp = (char*) pp->h.shortDesc; - ldp = (char*) pp->h.longDesc; - switch (type) { - case CSOUNDCFG_INTEGER: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - (void*) &(pp->i.min), - (void*) &(pp->i.max), sdp, ldp); - break; - case CSOUNDCFG_BOOLEAN: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - NULL, NULL, sdp, ldp); - break; - case CSOUNDCFG_FLOAT: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - (void*) &(pp->f.min), - (void*) &(pp->f.max), sdp, ldp); - break; - case CSOUNDCFG_DOUBLE: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - (void*) &(pp->d.min), - (void*) &(pp->d.max), sdp, ldp); - break; - case CSOUNDCFG_MYFLT: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - (void*) &(pp->m.min), - (void*) &(pp->m.max), sdp, ldp); - break; - case CSOUNDCFG_STRING: - j = csoundCreateConfigurationVariable(csound, name, p, type, flags, - NULL, (void*) &(pp->s.maxlen), - sdp, ldp); - break; - default: - return CSOUNDCFG_INVALID_TYPE; - } - if (j != CSOUNDCFG_SUCCESS) - return j; - } - /* copy value */ - switch (pp->h.type) { - case CSOUNDCFG_INTEGER: *((int*) p) = *(pp->i.p); break; - case CSOUNDCFG_BOOLEAN: *((int*) p) = *(pp->b.p); break; - case CSOUNDCFG_FLOAT: *((float*) p) = *(pp->f.p); break; - case CSOUNDCFG_DOUBLE: *((double*) p) = *(pp->d.p); break; - case CSOUNDCFG_MYFLT: *((MYFLT*) p) = *(pp->m.p); break; - case CSOUNDCFG_STRING: strcpy((char*) p, (char*) (pp->s.p)); break; - default: return CSOUNDCFG_INVALID_TYPE; - } /* report success */ return CSOUNDCFG_SUCCESS; } -#endif - -/** - * Copy all global configuration variables to the specified Csound instance. - * This function is experimental and may be subject to changes in - * future releases of the Csound library. - */ - -#if 0 -PUBLIC int csoundCopyGlobalConfigurationVariables(CSOUND *csound) -{ - csCfgVariable_t *pp, *lp; - int i, j, k, retval; - char *s; - void *ptr = NULL; - - if (UNLIKELY(global_cfg_db == NULL)) { - /* empty database: nothing to do */ - return CSOUNDCFG_SUCCESS; - } - - retval = CSOUNDCFG_SUCCESS; - for (i = 0; i < 256; i++) { - pp = (csCfgVariable_t*) (global_cfg_db[i]); - while (pp != NULL) { - /* does a local configuration variable with this name already exist ? */ - lp = csoundQueryConfigurationVariable(csound, (char*) pp->h.name); - if (lp == NULL) { - /* no, create named global variable */ - s = (char*) malloc((size_t) strlen((char*) pp->h.name) + (size_t) 2); - if (UNLIKELY(s == NULL)) - return CSOUNDCFG_MEMORY; - strcpy(s, "."); - strcat(s, (char*) pp->h.name); - switch (pp->h.type) { - case CSOUNDCFG_INTEGER: k = (int) sizeof(int); break; - case CSOUNDCFG_BOOLEAN: k = (int) sizeof(int); break; - case CSOUNDCFG_FLOAT: k = (int) sizeof(float); break; - case CSOUNDCFG_DOUBLE: k = (int) sizeof(double); break; - case CSOUNDCFG_MYFLT: k = (int) sizeof(MYFLT); break; - case CSOUNDCFG_STRING: k = (int) (pp->s.maxlen); break; - default: k = 1; /* should not happen */ - } - j = csoundCreateGlobalVariable(csound, s, (size_t) k); - if (UNLIKELY(j != CSOUND_SUCCESS)) { - if (j == CSOUND_MEMORY) - return CSOUNDCFG_MEMORY; - else { - retval = CSOUNDCFG_INVALID_NAME; - pp = (csCfgVariable_t*) (pp->h.nxt); - continue; - } - } - /* get pointer (should not be NULL) */ - ptr = csoundQueryGlobalVariable(csound, s); - free((void*) s); - } - else - ptr = NULL; /* use pointer of existing configuration variable */ - /* copy variable */ - j = csoundCopyGlobalConfigurationVariable(csound, (char*) pp->h.name, - ptr); - if (UNLIKELY(j == CSOUNDCFG_MEMORY || j == CSOUNDCFG_NULL_POINTER)) - return j; - else if (UNLIKELY(j != CSOUNDCFG_SUCCESS)) - retval = CSOUNDCFG_INVALID_NAME; - /* continue with next link in chain */ - pp = (csCfgVariable_t*) (pp->h.nxt); - } - } - return retval; -} -#endif /* set configuration variable to value (with error checking) */ @@ -664,39 +322,6 @@ } /** - * Set the value of a global configuration variable; should be called by the - * host application only. - * 'value' is a pointer of the same type as the 'p' pointer that was passed - * to csoundCreateGlobalConfigurationVariable(), depending on the type of - * the variable (integer, float, etc.). - * Return value is CSOUNDCFG_SUCCESS in case of success, or one of the - * following error codes: - * CSOUNDCFG_INVALID_NAME - * no configuration variable was found with the specified name - * CSOUNDCFG_NULL_POINTER - * the 'value' pointer was NULL - * CSOUNDCFG_TOO_LOW - * CSOUNDCFG_TOO_HIGH - * CSOUNDCFG_NOT_POWOFTWO - * CSOUNDCFG_INVALID_BOOLEAN - * CSOUNDCFG_STRING_LENGTH - * the specified value was invalid in some way - */ - -#if 0 -PUBLIC int csoundSetGlobalConfigurationVariable(const char *name, void *value) -{ - csCfgVariable_t *pp; - - /* get pointer to variable */ - pp = csoundQueryGlobalConfigurationVariable(name); - if (UNLIKELY(pp == NULL)) - return CSOUNDCFG_INVALID_NAME; /* not found */ - return (set_cfgvariable_value(pp, value)); -} -#endif - -/** * Set the value of a configuration variable of Csound instance 'csound'. * The 'name' and 'value' parameters, and return value are the same as * in the case of csoundSetGlobalConfigurationVariable(). @@ -730,17 +355,17 @@ iVal = (int) atoi(value); return set_cfgvariable_value(pp, (void*) (&iVal)); case CSOUNDCFG_BOOLEAN: - if (strcmp(value, "0") == 0 || - strcmp(value, "no") == 0 || strcmp(value, "No") == 0 || - strcmp(value, "NO") == 0 || strcmp(value, "off") == 0 || + if (strcmp(value, "0") == 0 || + strcmp(value, "no") == 0 || strcmp(value, "No") == 0 || + strcmp(value, "NO") == 0 || strcmp(value, "off") == 0 || strcmp(value, "Off") == 0 || strcmp(value, "OFF") == 0 || strcmp(value, "false") == 0 || strcmp(value, "False") == 0 || strcmp(value, "FALSE") == 0) *(pp->b.p) = 0; - else if (strcmp(value, "1") == 0 || + else if (strcmp(value, "1") == 0 || strcmp(value, "yes") == 0 || strcmp(value, "Yes") == 0 || - strcmp(value, "YES") == 0 || strcmp(value, "on") == 0 || - strcmp(value, "On") == 0 || strcmp(value, "ON") == 0 || + strcmp(value, "YES") == 0 || strcmp(value, "on") == 0 || + strcmp(value, "On") == 0 || strcmp(value, "ON") == 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "TRUE") == 0) *(pp->b.p) = 1; @@ -763,40 +388,6 @@ } /** - * Set the value of a global configuration variable, by parsing a string; - * should be called by the host application only. - * For boolean variables, any of the strings "0", "no", "off", and "false" - * will set the value to 0, and any of "1", "yes", "on", and "true" means a - * value of 1. - * Return value is CSOUNDCFG_SUCCESS in case of success, or one of the - * following error codes: - * CSOUNDCFG_INVALID_NAME - * no configuration variable was found with the specified name - * CSOUNDCFG_NULL_POINTER - * the 'value' pointer was NULL - * CSOUNDCFG_TOO_LOW - * CSOUNDCFG_TOO_HIGH - * CSOUNDCFG_NOT_POWOFTWO - * CSOUNDCFG_INVALID_BOOLEAN - * CSOUNDCFG_STRING_LENGTH - * the specified value was invalid in some way - */ - -#if 0 -PUBLIC int - csoundParseGlobalConfigurationVariable(const char *name, const char *value) -{ - csCfgVariable_t *pp; - - /* get pointer to variable */ - pp = csoundQueryGlobalConfigurationVariable(name); - if (UNLIKELY(pp == NULL)) - return CSOUNDCFG_INVALID_NAME; /* not found */ - return (parse_cfg_variable(pp, value)); -} -#endif - -/** * Set the value of a configuration variable of Csound instance 'csound', * by parsing a string. * The 'name' and 'value' parameters, and return value are the same as @@ -816,40 +407,6 @@ return (parse_cfg_variable(pp, value)); } -static csCfgVariable_t *find_cfg_variable(void **db, const char *name) -{ - csCfgVariable_t *pp; - unsigned char h; - /* check for trivial errors */ - if (UNLIKELY(db == NULL || name == NULL)) - return (csCfgVariable_t*) NULL; - if (UNLIKELY(name[0] == '\0')) - return (csCfgVariable_t*) NULL; - /* calculate hash value */ - h = name_hash_(name); - /* find entry in database */ - pp = (csCfgVariable_t*) (db[(int) h]); - while (UNLIKELY(pp!=NULL)) { - if (sCmp((char*) pp->h.name, name) == 0) - return pp; /* found */ - pp = (csCfgVariable_t*) (pp->h.nxt); - } - return (csCfgVariable_t*) NULL; -} - -/** - * Return pointer to the global configuration variable with the specified name. - * The return value may be NULL if the variable is not found in the database. - */ - -#if 0 -PUBLIC csCfgVariable_t - *csoundQueryGlobalConfigurationVariable(const char *name) -{ - return find_cfg_variable(global_cfg_db, name); -} -#endif - /** * Return pointer to the configuration variable of Csound instace 'csound' * with the specified name. @@ -859,7 +416,11 @@ PUBLIC csCfgVariable_t *csoundQueryConfigurationVariable(CSOUND *csound, const char *name) { - return find_cfg_variable(local_cfg_db, name); + if (csound->cfgVariableDB == NULL) { + return NULL; + } + return (csCfgVariable_t*) cs_hash_table_get(csound, + csound->cfgVariableDB, (char*)name); } /* compare function for qsort() */ @@ -872,62 +433,37 @@ /* create alphabetically sorted list of all entries in 'db' */ -static csCfgVariable_t **list_db_entries(void **db) +static csCfgVariable_t **list_db_entries(CSOUND* csound, CS_HASH_TABLE *db) { - csCfgVariable_t *pp, **lst; - size_t cnt = (size_t) 0; - int i; - - /* count the number of entries */ - if (db != NULL) { - for (i = 0; i < 256; i++) { - pp = (csCfgVariable_t*) (db[i]); - while (pp != NULL) { - cnt++; - pp = (csCfgVariable_t*) (pp->h.nxt); - } - } - } + csCfgVariable_t **lst; + size_t cnt; + CONS_CELL* values; + + values = cs_hash_table_values(csound, db); + cnt = cs_cons_length(values); + + /* allocate memory for list */ - lst = (csCfgVariable_t**) malloc(sizeof(csCfgVariable_t*) + lst = (csCfgVariable_t**) mmalloc(csound, sizeof(csCfgVariable_t*) * (cnt + (size_t) 1)); if (UNLIKELY(lst == NULL)) return (csCfgVariable_t**) NULL; /* not enough memory */ /* create list */ if (cnt) { - cnt = (size_t) 0; - for (i = 0; i < 256; i++) { - pp = (csCfgVariable_t*) (db[i]); - while (pp != NULL) { - lst[cnt++] = pp; - pp = (csCfgVariable_t*) (pp->h.nxt); + cnt = 0; + while (values != NULL) { + lst[cnt++] = (csCfgVariable_t*)values->value; + values = values->next; } - } - /* sort list */ - qsort((void*) lst, cnt, sizeof(csCfgVariable_t*), compare_func); + qsort((void*) lst, cnt, sizeof(csCfgVariable_t*), compare_func); } + lst[cnt] = (csCfgVariable_t*) NULL; /* return pointer to list */ return lst; } /** - * Create an alphabetically sorted list of all global configuration variables. - * Returns a pointer to a NULL terminated array of configuration variable - * pointers, or NULL on error. - * The caller is responsible for freeing the returned list with - * csoundDeleteCfgVarList(), however, the variable pointers in the list - * should not be freed. - */ - -#if 0 -PUBLIC csCfgVariable_t **csoundListGlobalConfigurationVariables(void) -{ - return (list_db_entries(global_cfg_db)); -} -#endif - -/** * Create an alphabetically sorted list of all configuration variables * of Csound instance 'csound'. * Returns a pointer to a NULL terminated array of configuration variable @@ -939,7 +475,7 @@ PUBLIC csCfgVariable_t **csoundListConfigurationVariables(CSOUND *csound) { - return (list_db_entries(local_cfg_db)); + return (list_db_entries(csound, csound->cfgVariableDB)); } /** @@ -948,53 +484,26 @@ * csoundListConfigurationVariables(). */ -PUBLIC void csoundDeleteCfgVarList(csCfgVariable_t **lst) +PUBLIC void csoundDeleteCfgVarList(CSOUND* csound, csCfgVariable_t **lst) { if (lst != NULL) - free(lst); + mfree(csound, lst); } /* remove a configuration variable from 'db' */ -static int remove_entry_from_db(void **db, const char *name) +static int remove_entry_from_db(CSOUND* csound, CS_HASH_TABLE *db, const char *name) { - csCfgVariable_t *pp, *prvp; - unsigned char h; - /* first, check if this key actually exists */ - if (UNLIKELY(find_cfg_variable(db, name) == NULL)) - return CSOUNDCFG_INVALID_NAME; - /* calculate hash value */ - h = name_hash_(name); - /* find entry in database */ - prvp = (csCfgVariable_t*) NULL; - pp = (csCfgVariable_t*) (db[(int) h]); - while (strcmp((char*) pp->h.name, name) != 0) { - prvp = pp; - pp = (csCfgVariable_t*) (pp->h.nxt); - } - if (prvp != NULL) - prvp->h.nxt = pp->h.nxt; /* unlink */ - else - db[(int) h] = (void*) (pp->h.nxt); - /* free allocated memory */ - free ((void*) pp); - return CSOUNDCFG_SUCCESS; -} + csCfgVariable_t *pp = cs_hash_table_get(csound, db, (char*)name); -/** - * Remove the global configuration variable with the specified name - * from the database. Should be called by the host application only, - * and never by the Csound library or plugins. - * Return value is CSOUNDCFG_SUCCESS in case of success, or - * CSOUNDCFG_INVALID_NAME if the variable was not found. - */ + if (UNLIKELY(pp == NULL)) + return CSOUNDCFG_INVALID_NAME; -#if 0 -PUBLIC int csoundDeleteGlobalConfigurationVariable(const char *name) -{ - return (remove_entry_from_db(global_cfg_db, name)); + mfree(csound, pp); + cs_hash_table_remove(csound, db, (char*)name); + + return CSOUNDCFG_SUCCESS; } -#endif /** * Remove the configuration variable of Csound instance 'csound' with the @@ -1006,45 +515,29 @@ PUBLIC int csoundDeleteConfigurationVariable(CSOUND *csound, const char *name) { - return (remove_entry_from_db(local_cfg_db, name)); + return remove_entry_from_db(csound, csound->cfgVariableDB, name); } -static int destroy_entire_db(void **db) +static int destroy_entire_db(CSOUND *csound, CS_HASH_TABLE *db) { - csCfgVariable_t *pp, *prvp; - int i; - + CONS_CELL *head, *current; if (db == NULL) return CSOUNDCFG_SUCCESS; - for (i = 0; i < 256; i++) { - prvp = (csCfgVariable_t*) NULL; - pp = (csCfgVariable_t*) (db[i]); - while (pp != NULL) { - prvp = pp; - pp = (csCfgVariable_t*) (pp->h.nxt); - free((void*) prvp); - } + + head = current = cs_hash_table_values(csound, db); + + while (current != NULL) { + if (current->value != NULL) { + mfree(csound, current->value); + } + current = current->next; } - free((void*) db); - return CSOUNDCFG_SUCCESS; -} -/** - * Remove all global configuration variables and free database. - * Should be called by the host application only, and never by the - * Csound library or plugins. - * Return value is CSOUNDCFG_SUCCESS in case of success. - */ + cs_cons_free(csound, head); + cs_hash_table_free(csound, db); -#if 0 -PUBLIC int csoundDeleteAllGlobalConfigurationVariables(void) -{ - int retval; - retval = destroy_entire_db(global_cfg_db); - global_cfg_db = NULL; - return retval; + return CSOUNDCFG_SUCCESS; } -#endif /** * Remove all configuration variables of Csound instance 'csound' @@ -1055,8 +548,8 @@ int csoundDeleteAllConfigurationVariables(CSOUND *csound) { int retval; - retval = destroy_entire_db(local_cfg_db); - local_cfg_db = NULL; + retval = destroy_entire_db(csound, csound->cfgVariableDB); + csound->cfgVariableDB = NULL; return retval; } @@ -1072,4 +565,3 @@ else return errmsg_list[(-errcode)]; } - diff -Nru csound-5.17.11~dfsg/Engine/corfiles.c csound-6.02~dfsg/Engine/corfiles.c --- csound-5.17.11~dfsg/Engine/corfiles.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/corfiles.c 2014-01-07 16:54:20.000000000 +0000 @@ -25,8 +25,11 @@ #include #include #include +#include + extern int csoundFileClose(CSOUND*, void*); +CORFIL *copy_url_corefile(CSOUND *, const char *, int); CORFIL *corfile_create_w(void) { @@ -39,7 +42,7 @@ CORFIL *corfile_create_r(const char *text) { - char *strdup(const char *); + //char *strdup(const char *); CORFIL *ans = (CORFIL*)malloc(sizeof(CORFIL)); ans->body = strdup(text); ans->len = strlen(text)+1; @@ -49,30 +52,51 @@ void corfile_putc(int c, CORFIL *f) { + char *new; f->body[f->p++] = c; - if (f->p >= f->len) - f->body = (char*) realloc(f->body, f->len+=100); + if (f->p >= f->len) { + new = (char*) realloc(f->body, f->len+=100); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + f->body = new; + } f->body[f->p] = '\0'; } -void corfile_puts(char *s, CORFIL *f) +void corfile_puts(const char *s, CORFIL *f) { - char *c; + const char *c; int n; /* skip and count the NUL chars to the end */ for (n=0; f->p > 0 && f->body[f->p-1] == '\0'; n++, f->p--); /* append the string */ for (c = s; *c != '\0'; c++) { + char *new; f->body[f->p++] = *c; - if (f->p >= f->len) - f->body = (char*) realloc(f->body, f->len+=100); + if (f->p >= f->len) { + new = (char*) realloc(f->body, f->len+=100); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + f->body = new; + } } if (n > 0) { /* put the extra NUL chars to the end */ - while (--n >= 0) { + while(--n >= 0) { + char *new; f->body[f->p++] = '\0'; - if (f->p >= f->len) - f->body = (char*) realloc(f->body, f->len+=100); + if (f->p >= f->len) { + new = (char*) realloc(f->body, f->len+=100); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + f->body = new; + } } } f->body[f->p] = '\0'; @@ -80,8 +104,14 @@ void corfile_flush(CORFIL *f) { + char *new; f->len = strlen(f->body)+1; - f->body = (char*)realloc(f->body, f->len); + new = (char*)realloc(f->body, f->len); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + f->body = new; f->p = 0; } @@ -154,7 +184,7 @@ if (dir == SEEK_SET) f->p = n; else if (dir == SEEK_CUR) f->p += n; else if (dir == SEEK_END) f->p = strlen(f->body)-n; - if (f->p < 0 || f->p > strlen(f->body)) { + if (f->p > strlen(f->body)) { printf("INTERNAL ERROR: Corfile seek out of range\n"); exit(1); } @@ -174,17 +204,22 @@ } /* *** THIS NEEDS TO TAKE ACCOUNT OF SEARCH PATH *** */ -void *fopen_path(CSOUND *csound, FILE **fp, char *name, char *basename, - char *env, int fromScore); -CORFIL *copy_to_corefile(CSOUND *csound, char *fname, char *env, int fromScore) +void *fopen_path(CSOUND *csound, FILE **fp, const char *name, + const char *basename, char *env, int fromScore); +CORFIL *copy_to_corefile(CSOUND *csound, const char *fname, + const char *env, int fromScore) { CORFIL *mm; FILE *ff; void *fd; int n; char buffer[1024]; - - fd = fopen_path(csound, &ff, fname, NULL, env, fromScore); +#ifdef HAVE_CURL + if (strstr(fname,"://")) { + return copy_url_corefile(csound, fname, fromScore); + } +#endif + fd = fopen_path(csound, &ff, (char *)fname, NULL, (char *)env, fromScore); if (ff==NULL) return NULL; mm = corfile_create_w(); memset(buffer, '\0', 1024); @@ -199,3 +234,134 @@ return mm; } +void corfile_preputs(const char *s, CORFIL *f) +{ + char *body = f->body; + f->body = (char*)malloc(f->len=(strlen(body)+strlen(s)+1)); + f->p = f->len-1; + strcpy(f->body, s); strcat(f->body, body); + free(body); +} + +#ifdef HAVE_CURL + +#include + +struct MemoryStruct { + char *memory; + size_t size; +}; + + +static size_t +WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) +{ + size_t realsize = size * nmemb; + struct MemoryStruct *mem = (struct MemoryStruct *)userp; + + mem->memory = realloc(mem->memory, mem->size + realsize + 1); + if (mem->memory == NULL) { + /* out of memory! */ + printf("not enough memory (realloc returned NULL)\n"); + return 0; + } + + memcpy(&(mem->memory[mem->size]), contents, realsize); + mem->size += realsize; + mem->memory[mem->size] = 0; + + return realsize; +} + +CORFIL *copy_url_corefile(CSOUND *csound, const char *url, int fromScore) +{ + int n; + CURL *curl = curl_easy_init(); + CORFIL *mm = corfile_create_w(); + struct MemoryStruct chunk; + + chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ + chunk.size = 0; /* no data at this point */ + curl_easy_setopt(curl, CURLOPT_URL, url); + curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); + curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + n = curl_easy_perform(curl); + if (n != CURLE_OK) { + csound->Die(csound, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(n)); + } + curl_easy_cleanup(curl); + corfile_puts(chunk.memory, mm); + corfile_putc('\0', mm); /* For use in bison/flex */ + corfile_putc('\0', mm); /* For use in bison/flex */ + if (fromScore) corfile_flush(mm); + if (chunk.memory) + free (chunk.memory); + + curl_global_cleanup(); + return mm; +} + +#endif + +#if 0 +int main(void) +{ + CURL *curl_handle; + CURLcode res; + + struct MemoryStruct chunk; + + chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ + chunk.size = 0; /* no data at this point */ + + curl_global_init(CURL_GLOBAL_ALL); + + /* init the curl session */ + curl_handle = curl_easy_init(); + + /* specify URL to get */ + curl_easy_setopt(curl_handle, CURLOPT_URL, "http://www.example.com/"); + + /* send all data to this function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); + + /* we pass our 'chunk' struct to the callback function */ + curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); + + /* some servers don't like requests that are made without a user-agent + field, so we provide one */ + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); + + /* get it! */ + res = curl_easy_perform(curl_handle); + + /* check for errors */ + if(res != CURLE_OK) { + fprintf(stderr, "curl_easy_perform() failed: %s\n", + curl_easy_strerror(res)); + } + else { + /* + * Now, our chunk.memory points to a memory block that is chunk.size + * bytes big and contains the remote file. + * + * Do something nice with it! + */ + + printf("%lu bytes retrieved\n", (long)chunk.size); + } + + /* cleanup curl stuff */ + curl_easy_cleanup(curl_handle); + + if(chunk.memory) + free(chunk.memory); + + /* we're done with libcurl, so clean it up */ + curl_global_cleanup(); + + return 0; +} +#endif diff -Nru csound-5.17.11~dfsg/Engine/cs_new_dispatch.c csound-6.02~dfsg/Engine/cs_new_dispatch.c --- csound-5.17.11~dfsg/Engine/cs_new_dispatch.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/cs_new_dispatch.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,768 @@ +/* +** cs_new_dispatch.c +** +** Copyright (C) Martin Brain (mjb@cs.bath.ac.uk) 04/08/12 +** Realisation in code for Csound John ffitch Feb 2013 +** + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + + +** Fast system for managing task dependencies and dispatching to threads. +** +** Has a DAG of tasks and has to assign them to worker threads while respecting +** dependency order. +** +** OPT marks code relevant to particular optimisations (listed below the code). +** INV marks invariants +** NOTE marks notes +*/ + +#include +#include +#include +#include "csoundCore.h" +#include "cs_par_base.h" +#include "cs_par_orc_semantics.h" +#include "csGblMtx.h" + +/* Used as an error value */ +//typedef int taskID; +#define INVALID (-1) +#define WAIT (-2) + +/* Each task has a status */ +//enum state { WAITING = 3, /* Dependencies have not been finished */ +// AVAILABLE = 2, /* Dependencies met, ready to be run */ +// INPROGRESS = 1, /* Has been started */ +// DONE = 0 }; /* Has been completed */ + +/* Sets of prerequiste tasks for each task */ +//typedef struct _watchList { +// taskID id; +// struct _watchList *next; +//} watchList; + +/* Array of states of each task -- need to move to CSOUND structure */ +//static enum state *task_status = NULL; /* OPT : Structure lay out */ +//static watchList **task_watch = NULL; +//static INSDS **task_map = NULL; + +/* INV : Read by multiple threads, updated by only one */ +/* Thus use atomic read and write */ + +//static char ** task_dep; /* OPT : Structure lay out */ +//static watchList * wlmm; + +#define INIT_SIZE (100) +//static int task_max_size; + +static void dag_print_state(CSOUND *csound) +{ + int i; + watchList *w; + printf("*** %d tasks\n", csound->dag_num_active); + for (i=0; idag_num_active; i++) { + printf("%d(%d): ", i, csound->dag_task_map[i]->insno); + switch (csound->dag_task_status[i]) { + case DONE: + printf("status=DONE (watchList "); + w = csound->dag_task_watch[i]; + while (w) { printf("%d ", w->id); w=w->next; } + printf(")\n"); + break; + case INPROGRESS: + printf("status=INPROGRESS (watchList "); + w = csound->dag_task_watch[i]; + while (w) { printf("%d ", w->id); w=w->next; } + printf(")\n"); + break; + case AVAILABLE: + printf("status=AVAILABLE (watchList "); + w = csound->dag_task_watch[i]; + while (w) { printf("%d ", w->id); w=w->next; } + printf(")\n"); + break; + case WAITING: + { + char *tt = csound->dag_task_dep[i]; + int j; + printf("status=WAITING for tasks ["); + for (j=0; jdag_task_max_size; + csound->dag_task_status = mcalloc(csound, sizeof(enum state)*max); + csound->dag_task_watch = mcalloc(csound, sizeof(watchList**)*max); + csound->dag_task_map = mcalloc(csound, sizeof(INSDS*)*max); + csound->dag_task_dep = (char **)mcalloc(csound, sizeof(char*)*max); + csound->dag_wlmm = (watchList *)mcalloc(csound, sizeof(watchList)*max); +} + +void recreate_dag(CSOUND *csound) +{ + /* Allocate the main task status and watchlists */ + int max = csound->dag_task_max_size; + csound->dag_task_status = + mrealloc(csound, (enum state *)csound->dag_task_status, + sizeof(enum state)*max); + csound->dag_task_watch = + mrealloc(csound, (struct watchList *)csound->dag_task_watch, + sizeof(watchList**)*max); + csound->dag_task_map = + mrealloc(csound, (INSDS *)csound->dag_task_map, sizeof(INSDS*)*max); + csound->dag_task_dep = + (char **)mrealloc(csound, csound->dag_task_dep, sizeof(char*)*max); + csound->dag_wlmm = + (watchList *)mrealloc(csound, csound->dag_wlmm, sizeof(watchList)*max); +} + +static INSTR_SEMANTICS *dag_get_info(CSOUND* csound, int insno) +{ + INSTR_SEMANTICS *current_instr = + csp_orc_sa_instr_get_by_num(csound, insno); + if (current_instr == NULL) { + current_instr = + csp_orc_sa_instr_get_by_name(csound, + csound->engineState.instrtxtp[insno]->insname); + if (current_instr == NULL) + csound->Die(csound, + Str("Failed to find semantic information" + " for instrument '%i'"), + insno); + } + return current_instr; +} + +static int dag_intersect(CSOUND *csound, struct set_t *current, + struct set_t *later, int cnt) +{ + struct set_t *ans; + int res = 0; + struct set_element_t *ele; + csp_set_intersection(csound, current, later, &ans); + res = ans->count; + ele = ans->head; + while (ele != NULL) { + struct set_element_t *next = ele->next; + csound->Free(csound, ele); + ele = next; res++; + } + csound->Free(csound, ans); + return res; +} + +void dag_build(CSOUND *csound, INSDS *chain) +{ + INSDS *save = chain; + INSDS **task_map; + int i; + + //printf("DAG BUILD***************************************\n"); + csound->dag_num_active = 0; + while (chain != NULL) { + csound->dag_num_active++; + chain = chain->nxtact; + } + if (csound->dag_num_active>csound->dag_task_max_size) { + //printf("**************need to extend task vector\n"); + csound->dag_task_max_size = csound->dag_num_active+INIT_SIZE; + recreate_dag(csound); + } + if (csound->dag_task_status == NULL) + create_dag(csound); /* Should move elsewhere */ + else { + memset((void*)csound->dag_task_watch, '\0', + sizeof(watchList*)*csound->dag_task_max_size); + for (i=0; idag_task_max_size; i++) { + if (csound->dag_task_dep[i]) { + csound->dag_task_dep[i]= NULL; + } + csound->dag_wlmm[i].id = INVALID; + } + } + task_map = csound->dag_task_map; + for (i=0; idag_num_active; i++) { + csound->dag_task_status[i] = AVAILABLE; + csound->dag_wlmm[i].id=i; + } + csound->dag_changed = 0; + if (UNLIKELY(csound->oparms->odebug)) + printf("dag_num_active = %d\n", csound->dag_num_active); + i = 0; chain = save; + while (chain != NULL) { /* for each instance check against later */ + int j = i+1; /* count of instance */ + if (UNLIKELY(csound->oparms->odebug)) + printf("\nWho depends on %d (instr %d)?\n", i, chain->insno); + INSDS *next = chain->nxtact; + INSTR_SEMANTICS *current_instr = dag_get_info(csound, chain->insno); + //csp_set_print(csound, current_instr->read); + //csp_set_print(csound, current_instr->write); + while (next) { + INSTR_SEMANTICS *later_instr = dag_get_info(csound, next->insno); + int cnt = 0; + if (UNLIKELY(csound->oparms->odebug)) printf("%d ", j); + //csp_set_print(csound, later_instr->read); + //csp_set_print(csound, later_instr->write); + //csp_set_print(csound, later_instr->read_write); + if (dag_intersect(csound, current_instr->write, + later_instr->read, cnt++) || + dag_intersect(csound, current_instr->read_write, + later_instr->read, cnt++) || + dag_intersect(csound, current_instr->read, + later_instr->write, cnt++) || + dag_intersect(csound, current_instr->write, + later_instr->write, cnt++) || + dag_intersect(csound, current_instr->read_write, + later_instr->write, cnt++) || + dag_intersect(csound, current_instr->read, + later_instr->read_write, cnt++) || + dag_intersect(csound, current_instr->write, + later_instr->read_write, cnt++)) { + char *tt = csound->dag_task_dep[j]; + if (tt==NULL) { + /* get dep vector if missing and set watch first time */ + tt = csound->dag_task_dep[j] = + (char*)mcalloc(csound, sizeof(char)*(j+1)); + csound->dag_task_status[j] = WAITING; + csound->dag_wlmm[j].next = csound->dag_task_watch[i]; + csound->dag_wlmm[j].id = j; + csound->dag_task_watch[i] = &(csound->dag_wlmm[j]); + //printf("set watch %d to %d\n", j, i); + } + tt[i] = 1; + //printf("-yes "); + } + j++; next = next->nxtact; + } + task_map[i] = chain; + i++; chain = chain->nxtact; + } + if (UNLIKELY(csound->oparms->odebug)) dag_print_state(csound); +} + +void dag_reinit(CSOUND *csound) +{ + int i; + int max = csound->dag_task_max_size; + volatile enum state *task_status = csound->dag_task_status; + watchList * volatile *task_watch = csound->dag_task_watch; + watchList *wlmm = csound->dag_wlmm; + if (UNLIKELY(csound->oparms->odebug)) + printf("DAG REINIT************************\n"); + for (i=csound->dag_num_active; idag_num_active; i++) { + int j; + task_status[i] = AVAILABLE; + task_watch[i] = NULL; + if (csound->dag_task_dep[i]==NULL) continue; + for (j=0; jdag_task_dep[i][j]) { + task_status[i] = WAITING; + wlmm[i].id = i; + wlmm[i].next = task_watch[j]; + task_watch[j] = &wlmm[i]; + break; + } + } + //dag_print_state(csound); +} + +#define ATOMIC_READ(x) __sync_fetch_and_or(&(x), 0) +#define ATOMIC_WRITE(x,v) __sync_fetch_and_and(&(x), v) +#define ATOMIC_CAS(x,current,new) __sync_bool_compare_and_swap(x,current,new) + +taskID dag_get_task(CSOUND *csound) +{ + int i; + int morework = 0; + int active = csound->dag_num_active; + volatile enum state *task_status = csound->dag_task_status; + //printf("**GetTask from %d\n", csound->dag_num_active); + for (i=0; inext = NULL; + //printf("moveWatch\n"); + do { + //dag_print_state(csound); + local = ATOMIC_READ(*w); + if (local==&DoNotRead) { + //printf("local is DoNotRead\n"); + return 0;//was no & earlier + } + else t->next = local; + } while (!ATOMIC_CAS(w,local,t)); + //dag_print_state(csound); + //printf("moveWatch done\n"); + return 1; +} + +void dag_end_task(CSOUND *csound, taskID i) +{ + watchList *to_notify, *next; + int canQueue; + int j, k; + watchList * volatile *task_watch = csound->dag_task_watch; + ATOMIC_WRITE(csound->dag_task_status[i], DONE); /* as DONE is zero */ + { /* ATOMIC_SWAP */ + do { + to_notify = ATOMIC_READ(task_watch[i]); + } while (!ATOMIC_CAS(&task_watch[i],to_notify,&DoNotRead)); + } //to_notify = ATOMIC_SWAP(task_watch[i], &DoNotRead); + //printf("Ending task %d\n", i); + next = to_notify; + while (to_notify) { /* walk the list of watchers */ + next = to_notify->next; + j = to_notify->id; + //printf("%d notifying task %d it finished\n", i, j); + canQueue = 1; + for (k=0; kdag_task_dep[j][k]==0) continue; + //printf("investigating task %d (%d)\n", k, csound->dag_task_status[k]); + if (ATOMIC_READ(csound->dag_task_status[k]) != DONE) { + //printf("found task %d to watch %d status %d\n", + // k, j, csound->dag_task_status[k]); + if (moveWatch(csound, &task_watch[k], to_notify)) { + //printf("task %d now watches %d\n", j, k); + canQueue = 0; + break; + } + else { + /* assert csound->dag_task_status[j] == DONE and we are in race */ + //printf("Racing status %d %d %d %d\n", + // csound->dag_task_status[j], i, j, k); + } + } + //else { printf("not %d\n", k); } + } + if (canQueue) { /* could use monitor here */ + csound->dag_task_status[j] = AVAILABLE; + } + to_notify = next; + } + //dag_print_state(csound); + return; +} + + +/* INV : Acyclic */ +/* INV : Each entry is read by a single thread, + * no writes (but see OPT : Watch ordering) */ +/* Thus no protection needed */ + +/* INV : Watches for different tasks are disjoint */ +/* INV : Multiple threads can add to a watch list but only one will remove + * These are the only interactions */ +/* Thus the use of CAS / atomic operations */ + +/* Used to mark lists that should not be added to, see NOTE : Race condition */ +#if 0 +watchList nullList; +watchList *doNotAdd = &nullList; +watchList endwatch = { NULL, NULL }; + +/* Lists of tasks that depend on the given task */ +watchList ** watch; /* OPT : Structure lay out */ +watchListMemoryManagement *wlmm; /* OPT : Structure lay out */ + +/* INV : wlmm[X].s.id == X; */ /* OPT : Data structure redundancy */ +/* INV : status[X] == WAITING => wlmm[X].used */ +/* INV : wlmm[X].s is in watch[Y] => wlmm[X].used */ + + +/* Watch list helper functions */ + +void initialiseWatch (watchList **w, taskID id) { + wlmm[id].used = TRUE; + wlmm[id].s.id = id; + wlmm[id].s.tail = *w; + *w = &(wlmm[id].s); +} + +watchList * getWatches(taskID id) { + + return __sync_lock_test_and_set (&(watch[id]), doNotAdd); +} + +int moveWatch (watchList **w, watchList *t) { + watchList *local; + + t->tail = NULL; + + do { + local = atomicRead(*w); + + if (local == doNotAdd) { + return 0; + } else { + t->tail = local; + } + } while (!atomicCAS(*w,local,t)); /* OPT : Delay loop */ + + return 1; +} + +void appendToWL (taskID id, watchList *l) { + watchList *w; + + do { + w = watch[id]; + l->tail = w; + w = __sync_val_compare_and_swap(&(watch[id]),w,l); + } while (!(w == l)); + +} + +void deleteWatch (watchList *t) { + wlmm[t->id].used = FALSE; +} + + + + +typedef struct monitor { + pthread_mutex_t l = PTHREAD_MUTEX_INITIALIZER; + unsigned int threadsWaiting = 0; /* Shadows the length of + workAvailable wait queue */ + queue q; /* OPT : Dispatch order */ + pthread_cond_t workAvailable = PTHREAD_COND_INITIALIZER; + pthread_cond_t done = PTHREAD_COND_INITIALIZER; +} monitor; /* OPT : Lock-free */ + +/* INV : q.size() + dispatched <= ID */ +/* INV : foreach(id,q.contents()) { status[id] = AVAILABLE; } */ +/* INV : threadsWaiting <= THREADS */ + +monitor dispatch; + + +void addWork(monitor *dispatch, taskID id) { + pthread_mutex_lock(&dispatch->l); + + status[id] = AVAILABLE; + dispatch->q.push(id); + if (threadsWaiting >= 1) { + pthread_cond_signal(&dispatch->c); + } + + pthread_mutex_unlock(&dispatch->l); + return; +} + +taskID getWork(monitor *dispatch) { + taskID returnValue; + + pthread_mutex_lock(&dispatch->l); + + while (q.empty()) { + ++dispatch->threadsWaiting; + + if (dispatch->threadsWaiting == THREADS) { + /* Will the last person out please turn off the lights! */ + pthread_cond_signal(&dispatch->done); + } + + pthread_cond_wait(&dispatch->l,&dispatch->workAvailable); + --dispatch->threadsWaiting; + + /* NOTE : A while loop is needed as waking from this requires + * reacquiring the mutex and in the mean time someone + * might have got it first and removed the work. */ + } + + returnValue = q.pop(); + + pthread_mutex_unlock(&dispatch->l); + return returnValue; + +} + +void waitForWorkToBeCompleted (monitor *dispatch) { + /* Requires + * INV : threadsWaiting == THREADS <=> \forall id \in ID . status[id] == DONE + */ + + pthread_mutex_lock(&dispatch->l); + + if (dispatch->threadsWaiting < THREADS) { + pthread_cond_wait(&dispatch->l,&dispatch->done); + } + + /* This assertion is more difficult to prove than it might first appear */ + assert(dispatch->threadsWaiting == THREADS); + + pthread_mutex_unlock(&dispatch->l); + return; +} + + + + + + + + + + + + + + +void mainThread (State *s) { + + /* Set up the DAG */ + if (s->firstRun || s->updateNeeded) { + dep = buildDAG(s); /* OPT : Dispatch order */ + /* Other : Update anything that is indexed by task + * (i.e. all arrays given length ID) */ + } + + /* Reset the data structure */ + foreach (id in ID) { + watch[id] = NULL; + } + + /* Initialise the dispatch queue */ + foreach (id in ID) { /* OPT : Dispatch order */ + if (dep[id] == EMPTYSET) { + atomicWrite(status[id] = AVAILABLE); + addWork(*dispatch,id); + + } else { + atomicWrite(status[id] = WAITING); + initialiseWatch(&watch[choose(dep[id])], id); /* OPT : Watch ordering */ + + } + } + +/* INV : Data structure access invariants start here */ +/* INV : Status only decrease from now */ +/* INV : Watch list for id contains a subset of the things that depend on id */ +/* INV : Each id appears in at most one watch list */ +/* INV : doNotAdd only appears at the head of a watch list */ +/* INV : if (watch[id] == doNotAdd) then { status[id] == DONE; } */ + + waitForWorkToBeCompleted(*dispatch); + + return; +} + +void workerThread (State *s) { + taskID work; + watchList *tasksToNotify, next; + bool canQueue; + + do { + + task = getWork(dispatch); + + /* Do stuff */ + atomicWrite(status[work] = INPROGRESS); + doStuff(work); + atomicWrite(status[work] = DONE); /* NOTE : Race condition */ + + + tasksToNotify = getWatches(work); + + while (tasksToNotify != NULL) { + next = tasksToNotify->tail; + + canQueue = TRUE; + foreach (dep in dep[tasksToNotify->id]) { /* OPT : Watch ordering */ + if (atomicRead(status[dep]) != DONE) { + /* NOTE : Race condition */ + if (moveWatch(watch[dep],tasksToNotify)) { + canQueue = FALSE; + break; + } else { + /* Have hit the race condition, try the next option */ + assert(atomicRead(status[dep]) == DONE); + } + } + } + + if (canQueue) { /* OPT : Save one work item */ + addWork(*dispatch,tasksToNotify->id); + deleteWatch(tasksToNotify); + } + + tasksToNotify = next; + } + + } while (1); /* NOTE : some kind of control for thread exit needed */ + + return; +} + + + + +/* OPT : Structure lay out + * + * All data structures that are 1. modified by one or more thread and + * 2. accessed by multiple threads, should be aligned to cache lines and + * padded so that there is only one instance per cache line. This will reduce + * false memory contention between objects that just happen to share a cache + * line. Blocking to 64 bytes will probably be sufficient and if people really + * care about performance that much they can tune to their particular + * architecture. + */ + +/* OPT : Watch ordering + * + * Moving a watch is relatively cheap (in the uncontended case) but + * it would be best to avoid moving watches where possible. The ideal + * situation would be for every task to watch the last pre-requisite. + * There are two places in the code that affect the watch ordering; + * the initial assignment and the movement when a watch is triggered. + * Prefering WAITING tasks (in the later) and lower priority tasks + * (if combined with the dispatch order optimisation below) are probably + * good choices. One mechanism would be to reorder the set (or array) of + * dependencies to store this information. When looking for a (new) watch, + * tasks are sorted with increasing status first and then the first one picked. + * Keeping the list sorted (or at least split between WAITING and others) with + * each update should (if the dispatch order is fixed / slowly adapting) result + * in the best things to watch moving to the front and thus adaptively give + * the best possible tasks to watch. The interaction with a disaptch order + * heuristic would need to be considered. Note that only one thread will + * look at any given element of dep[] so they can be re-ordered without + * needing locking. + */ + +/* OPT : Structure lay out + * + * Some of the fields are not strictly needed and are just there to make + * the algorithm cleaner and more intelligible. The id fields of the watch + * lists are not really needed as there is one per task and their position + * within the watchListMemoryManager array allows the task to be infered. + * Likewise the used flag in the memory manager is primarily for book-keeping + * and checking / assertions and could be omitted. + */ + +/* OPT : Delay loop + * + * In theory it is probably polite to put a slowly increasing delay in + * after a failed compare and swap to reduce pressure on the memory + * subsystem in the highly contended case. As multiple threads adding + * to a task's watch list simultaneously is probably a rare event, the + * delay loop is probably unnecessary. + */ + +/* OPT : Dispatch order + * + * The order in which tasks are dispatched affects the amount of + * parallelisation possible. Picking the exact scheduling order, even + * if the duration of the tasks is known is probably NP-Hard (see + * bin-packing*) so heuristics are probably the way to go. The proporition + * of tasks which depend on a given task is probably a reasonable primary + * score, with tie-breaks going to longer tasks. This can either be + * applied to just the initial tasks (either in ordering the nodes in the DAG) + * or in the order in which they are traversed. Alternatively by + * sorting the queue / using a heap / other priority queuing structure + * it might be possible to do this dynamically. The best solution would + * probably be adaptive with a task having its priority incremented + * each time another worker thread blocks on a shortage of work, with these + * increments also propagated 'upwards' in the DAG. + * + * *. Which means that a solver could be used to give the best possible + * schedule / the maximum parallelisation. This could be useful for + * optimisation. + */ + +/* OPT : Lock-free + * + * A lock free dispatch mechanism is probably possible as threads can + * scan the status array for things listed as AVAILABLE and then atomicCAS + * to INPROGRESS to claim them. But this starts to involve busy-waits or + * direct access to futexes and is probably not worth it. + */ + +/* OPT : Save one work item + * + * Rather than adding all watching tasks who have their dependencies met to + * the dispatch queue, saving one (perhaps the best, see OPT : Dispatch order) + * means the thread does not have to wait. In the case of a purely linear DAG + * this should be roughly as fast as the single threaded version. + */ + + +/* NOTE : Race condition + * + * There is a subtle race condition: + * + * Thread 1 Thread 2 + * -------- -------- + * atomicRead(status[dep]) != DONE + * atomicWrite(status[work] = DONE); + * tasksToNotify = getWatches(work); + * moveWatch(watch[dep],tasksToNotify); + * + * The key cause is that the status and the watch list cannot be updated + * simultaneously. However as getWatches removes all watches and moves or + * removes them, it is sufficient to have a doNotAdd watchList node to detect + * this race condition and resolve it by having moveWatch() fail. + */ + +void newdag_alloc(CSOUND *csound, int numtasks) +{ + doNotAdd = &endwatch; +?? + watch = (watchList **)mcalloc(csound, sizeof(watchList *)*numtasks); + wlmm = (watchListMemoryManagement *) + mcalloc(csound, sizeof(watchListMemoryManagement)*numtasks); + +} + +#endif diff -Nru csound-5.17.11~dfsg/Engine/cs_par_base.c csound-6.02~dfsg/Engine/cs_par_base.c --- csound-5.17.11~dfsg/Engine/cs_par_base.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/cs_par_base.c 2014-01-07 16:54:20.000000000 +0000 @@ -30,7 +30,6 @@ int csp_thread_index_get(CSOUND *csound) { -#ifndef mac_classic void *threadId = csound->GetCurrentThreadID(); int index = 0; @@ -49,13 +48,12 @@ index++; current = current->next; } -#endif return -1; } /* **** An implementation of Barriers for MAC that lacks them **** */ -#ifdef __MACH__ +#if defined(__MACH__) || defined(ANDROID) || defined(NACL) /*#define BARRIER_SERIAL_THREAD (-1) typedef struct { @@ -140,14 +138,14 @@ int thread_count) { if (UNLIKELY(barrier == NULL)) - csound->Die(csound, "Invalid NULL Parameter barrier"); + csound->Die(csound, Str("Invalid NULL Parameter barrier")); if (UNLIKELY(thread_count < 1)) - csound->Die(csound, "Invalid Parameter thread_count must be > 0"); + csound->Die(csound, Str("Invalid Parameter thread_count must be > 0")); *barrier = (pthread_barrier_t *)csound->Malloc(csound, sizeof(pthread_barrier_t)); if (UNLIKELY(*barrier == NULL)) { - csound->Die(csound, "Failed to allocate barrier"); + csound->Die(csound, Str("Failed to allocate barrier")); } pthread_barrier_init(*barrier, NULL, thread_count); } @@ -155,7 +153,7 @@ void csp_barrier_dealloc(CSOUND *csound, pthread_barrier_t **barrier) { if (UNLIKELY(barrier == NULL || *barrier == NULL)) - csound->Die(csound, "Invalid NULL Parameter barrier"); + csound->Die(csound, Str("Invalid NULL Parameter barrier")); pthread_barrier_destroy(*barrier); } @@ -279,11 +277,11 @@ set_element_data_print *ele_print_func) { if (UNLIKELY(set == NULL)) - csound->Die(csound, "Invalid NULL Parameter set"); + csound->Die(csound, Str("Invalid NULL Parameter set")); *set = csound->Malloc(csound, sizeof(struct set_t)); if (UNLIKELY(*set == NULL)) { - csound->Die(csound, "Failed to allocate set"); + csound->Die(csound, Str("Failed to allocate set")); } memset(*set, 0, sizeof(struct set_t)); strncpy((*set)->hdr, SET_HDR, HDR_LEN); @@ -298,9 +296,9 @@ { struct set_element_t *ele; if (UNLIKELY(set == NULL || *set == NULL)) - csound->Die(csound, "Invalid NULL Parameter set"); + csound->Die(csound, Str("Invalid NULL Parameter set")); if (UNLIKELY(!set_is_set(csound, *set))) - csound->Die(csound, "Invalid Parameter set not a set"); + csound->Die(csound, Str("Invalid Parameter set not a set")); if ((*set)->cache != NULL) csound->Free(csound, (*set)->cache); @@ -322,11 +320,11 @@ char *data) { if (UNLIKELY(set_element == NULL || data == NULL)) - csound->Die(csound, "Invalid NULL Parameter data"); + csound->Die(csound, Str("Invalid NULL Parameter data")); *set_element = csound->Malloc(csound, sizeof(struct set_element_t)); if (UNLIKELY(*set_element == NULL)) { - csound->Die(csound, "Failed to allocate set element"); + csound->Die(csound, Str("Failed to allocate set element")); } memset(*set_element, 0, sizeof(struct set_element_t)); strncpy((*set_element)->hdr, SET_ELEMENT_HDR, HDR_LEN); @@ -339,7 +337,7 @@ struct set_element_t **set_element) { if (UNLIKELY(set_element == NULL || *set_element == NULL)) - csound->Die(csound, "Invalid NULL Parameter set_element"); + csound->Die(csound, Str("Invalid NULL Parameter set_element")); csound->Free(csound, *set_element); *set_element = NULL; @@ -390,7 +388,7 @@ void csp_set_element_string_print(CSOUND *csound, struct set_element_t *ele) { - csound->Message(csound, "%s", (char *)ele->data); + csound->Message(csound, (char *)ele->data); } void csp_set_element_ptr_print(CSOUND *csound, @@ -431,11 +429,11 @@ { #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) - csound->Die(csound, "Invalid NULL Parameter set"); + csound->Die(csound, Str("Invalid NULL Parameter set")); if (UNLIKELY(data == NULL)) - csound->Die(csound, "Invalid NULL Parameter data"); + csound->Die(csound, Str("Invalid NULL Parameter data")); if (UNLIKELY(out_set_element == NULL)) - csound->Die(csound, "Invalid NULL Parameter out_set_element"); + csound->Die(csound, Str("Invalid NULL Parameter out_set_element")); #endif { struct set_element_t *ele = set->head; @@ -546,9 +544,6 @@ csound->Message(csound, "{ "); while (ele != NULL) { set->ele_print_func(csound, ele); - - TRACE_3(" [%p]", ele); - if (ele->next != NULL) csound->Message(csound, ", "); ele = ele->next; } @@ -557,7 +552,7 @@ return CSOUND_SUCCESS; } -int inline csp_set_count(CSOUND *csound, struct set_t *set) +inline int csp_set_count(struct set_t *set) { #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) @@ -570,8 +565,7 @@ } /* 0 indexed */ -int inline csp_set_get_num(CSOUND *csound, - struct set_t *set, int num, void **data) +inline int csp_set_get_num(struct set_t *set, int num, void **data) { #ifdef SET_DEBUG if (UNLIKELY(set == NULL)) @@ -616,7 +610,7 @@ if (UNLIKELY(!set_is_set(csound, first))) csound->Die(csound, "Invalid Parameter set not a first"); if (UNLIKELY(second == NULL)) - csound->Die(csound, "Invalid NULL Parameter second"); + csound->Die(csound, "Invalid NULL Parameter second"); if (UNLIKELY(!set_is_set(csound, second))) csound->Die(csound, "Invalid Parameter set not a second"); if (UNLIKELY(result == NULL)) @@ -629,12 +623,12 @@ csp_set_alloc(csound, result, first->ele_eq_func, first->ele_print_func); - first_len = csp_set_count(csound, first); - second_len = csp_set_count(csound, second); + first_len = csp_set_count(first); + second_len = csp_set_count(second); while (ctr < first_len) { void *data = NULL; - csp_set_get_num(csound, first, ctr, &data); + csp_set_get_num(first, ctr, &data); csp_set_add(csound, *result, data); ctr++; } @@ -642,7 +636,7 @@ ctr = 0; while (ctr < second_len) { void *data = NULL; - csp_set_get_num(csound, second, ctr, &data); + csp_set_get_num(second, ctr, &data); csp_set_add(csound, *result, data); ctr++; } @@ -674,11 +668,11 @@ csp_set_alloc(csound, result, first->ele_eq_func, first->ele_print_func); - first_len = csp_set_count(csound, first); + first_len = csp_set_count(first); while (ctr < first_len) { void *data = NULL; - csp_set_get_num(csound, first, ctr, &data); + csp_set_get_num(first, ctr, &data); if (csp_set_exists(csound, second, data)) { csp_set_add(csound, *result, data); } diff -Nru csound-5.17.11~dfsg/Engine/cs_par_dispatch.c csound-6.02~dfsg/Engine/cs_par_dispatch.c --- csound-5.17.11~dfsg/Engine/cs_par_dispatch.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/cs_par_dispatch.c 2014-01-07 16:53:47.000000000 +0000 @@ -26,7 +26,6 @@ #include "csoundCore.h" #include "csound_orc.h" -#include "tok.h" #include "cs_par_base.h" #include "cs_par_orc_semantics.h" #include "cs_par_dispatch.h" @@ -38,55 +37,7 @@ * external prototypes not in headers */ extern ORCTOKEN *lookup_token(CSOUND *csound, char *); - -/*********************************************************************** - * static function prototypes - */ -static uint32_t inline hash( uint32_t a ); -static uint32_t hash_chain(INSDS *chain, uint32_t hash_size); -static uint32_t hash_string(char *str, uint32_t hash_size); - -/*********************************************************************** - * helper functions - */ - -/* Robert Jenkins' 32 bit integer hash function from - * http://www.concentric.net/~Ttwang/tech/inthash.htm - */ -static uint32_t inline hash( uint32_t a ) -{ - a = (a+0x7ed55d16) + (a<<12); - a = (a^0xc761c23c) ^ (a>>19); - a = (a+0x165667b1) + (a<<5); - a = (a+0xd3a2646c) ^ (a<<9); - a = (a+0xfd7046c5) + (a<<3); - a = (a^0xb55a4f09) ^ (a>>16); - return a; -} - -static uint32_t hash_chain(INSDS *chain, uint32_t hash_size) -{ - uint32_t val = 0; - while (chain != NULL) { - val = val ^ chain->insno; - val = hash( val ); - chain = chain->nxtact; - } - return val % hash_size; -} - -static uint32_t hash_string(char *str, uint32_t hash_size) -{ - uint32_t ctr = 0; - uint32_t val = 0; - uint32_t len = strlen(str); - while (ctr < len) { - val = val ^ str[ctr]; - val = hash( val ); - ctr++; - } - return val % hash_size; -} +extern void print_tree(CSOUND *, char *, TREE *); /*********************************************************************** * Global Var Lock Inserts @@ -106,20 +57,20 @@ //static struct global_var_lock_t **global_var_lock_cache; -void inline csp_locks_lock(CSOUND * csound, int global_index) +inline void csp_locks_lock(CSOUND * csound, int global_index) { if (UNLIKELY(global_index >= csound->global_var_lock_count)) { csound->Die(csound, Str("Poorly specified global lock index: %i [max: %i]\n"), global_index, csound->global_var_lock_count); } - TRACE_2("Locking: %i [%p %s]\n", global_index, - csound->global_var_lock_cache[global_index], - csound->global_var_lock_cache[global_index]->name); + /* TRACE_2("Locking: %i [%p %s]\n", global_index, */ + /* csound->global_var_lock_cache[global_index], */ + /* csound->global_var_lock_cache[global_index]->name); */ TAKE_LOCK(&(csound->global_var_lock_cache[global_index]->lock)); } -void inline csp_locks_unlock(CSOUND * csound, int global_index) +inline void csp_locks_unlock(CSOUND * csound, int global_index) { if (UNLIKELY(global_index >= csound->global_var_lock_count)) { csound->Die(csound, @@ -127,9 +78,9 @@ global_index, csound->global_var_lock_count); } RELS_LOCK(&(csound->global_var_lock_cache[global_index]->lock)); - TRACE_2("UnLocking: %i [%p %s]\n", - global_index, csound->global_var_lock_cache[global_index], - csound->global_var_lock_cache[global_index]->name); + /* TRACE_2("UnLocking: %i [%p %s]\n", */ + /* global_index, csound->global_var_lock_cache[global_index], */ + /* csound->global_var_lock_cache[global_index]->name); */ } static struct global_var_lock_t *global_var_lock_alloc(CSOUND *csound, @@ -185,21 +136,10 @@ } } -/* static void locks_print(CSOUND *csound) - { - csound->Message(csound, Str("Current Global Locks\n")); - struct global_var_lock_t *cg = csound->global_var_lock_root; - while (cg != NULL) { - csound->Message(csound, "[%i] %s [%p]\n", cg->index, - cg->name, cg); - cg = cg->next; - } - } */ - TREE *csp_locks_insert(CSOUND *csound, TREE *root) { csound->Message(csound, - "Inserting Parallelism Constructs into AST\n"); + Str("Inserting Parallelism Constructs into AST\n")); TREE *anchor = NULL; @@ -211,7 +151,8 @@ switch(current->type) { case INSTR_TOKEN: if (current->left->type == T_INSTLIST) { - instr = csp_orc_sa_instr_get_by_name(csound, + instr = + csp_orc_sa_instr_get_by_name(csound, current->left->left->value->lexeme); } else { @@ -221,7 +162,10 @@ if (instr->read_write->count > 0 && instr->read->count == 0 && instr->write->count == 0) { + csound->Message(csound, Str("Instr %d needs locks"), instr->insno); + //print_tree(csound, "before locks", root); current->right = csp_locks_insert(csound, current->right); + //print_tree(csound, "after locks", root); } break; @@ -232,51 +176,51 @@ case '=': /*if (current->type == '=')*/ { - struct set_t *left = NULL, *right = NULL; - left = csp_orc_sa_globals_find(csound, current->left); - right = csp_orc_sa_globals_find(csound, current->right); - + struct set_t *left = csp_orc_sa_globals_find(csound, current->left); + struct set_t *right = csp_orc_sa_globals_find(csound, current->right); struct set_t *new = NULL; csp_set_union(csound, left, right, &new); /* add locks if this is a read-write global variable * that is same global read and written in this operation */ if (left->count == 1 && right->count == 1 && new->count == 1) { char *global_var = NULL; - csp_set_get_num(csound, new, 0, (void **)&global_var); - - struct global_var_lock_t *gvar = - global_var_lock_find(csound, global_var); - - /* add_token(csound, "str", A_TYPE); */ - + struct global_var_lock_t *gvar; char buf[8]; - snprintf(buf, 8, "%i", gvar->index); + ORCTOKEN *lock_tok, *unlock_tok, *var_tok, *var0_tok;; + TREE *lock_leaf, *unlock_leaf; - ORCTOKEN *lock_tok = lookup_token(csound, "##globallock"); - ORCTOKEN *unlock_tok = lookup_token(csound, "##globalunlock"); - ORCTOKEN *var_tok = make_int(csound, buf); + csp_set_get_num(new, 0, (void **)&global_var); + gvar = global_var_lock_find(csound, global_var); + lock_tok = lookup_token(csound, "##globallock"); + unlock_tok = lookup_token(csound, "##globalunlock"); + snprintf(buf, 8, "%i", gvar->index); + var_tok = make_int(csound, buf); + var0_tok = make_int(csound, buf); - TREE *lock_leaf = make_leaf(csound, current->line, current->locn, - T_OPCODE, lock_tok); + lock_leaf = make_leaf(csound, current->line, current->locn, + T_OPCODE, lock_tok); lock_leaf->right = make_leaf(csound, current->line, current->locn, INTEGER_TOKEN, var_tok); - TREE *unlock_leaf = make_leaf(csound, current->line, current->locn, - T_OPCODE, unlock_tok); + unlock_leaf = make_leaf(csound, current->line, current->locn, + T_OPCODE, unlock_tok); unlock_leaf->right = make_leaf(csound, current->line, current->locn, - INTEGER_TOKEN, var_tok); + INTEGER_TOKEN, var0_tok); if (previous == NULL) { - TREE *old_current = lock_leaf; + //TREE *old_current = lock_leaf; lock_leaf->next = current; unlock_leaf->next = current->next; current->next = unlock_leaf; - current = old_current; + current = unlock_leaf; + //print_tree(csound, "changed to\n", lock_leaf); } else { previous->next = lock_leaf; lock_leaf->next = current; unlock_leaf->next = current->next; current->next = unlock_leaf; + current = unlock_leaf; + //print_tree(csound, "changed-1 to\n", lock_leaf); } } @@ -298,7 +242,7 @@ } csound->Message(csound, - "[End Inserting Parallelism Constructs into AST]\n"); + Str("[End Inserting Parallelism Constructs into AST]\n")); return anchor; } @@ -348,2434 +292,4 @@ return OK; } -/*********************************************************************** - * weighting - */ - -/* static struct instr_weight_info_t - *instr_weight_info_alloc(CSOUND *csound) - { - struct instr_weight_info_t *ret = - csound->Malloc(csound, sizeof(struct instr_weight_info_t)); - memset(ret, 0, sizeof(struct instr_weight_info_t)); - strncpy(ret->hdr, INSTR_WEIGHT_INFO_HDR, HDR_LEN); - - return ret; - } */ - -#define WEIGHT_UNKNOWN_NODE 1 -#define WEIGHT_S_ASSIGN_NODE 1 -#define WEIGHT_OPCODE_NODE 5 - -static void csp_weights_calculate_instr(CSOUND *csound, TREE *root, - INSTR_SEMANTICS *instr) -{ - csound->Message(csound, "Calculating Instrument weight from AST\n"); - - TREE *current = root; - INSTR_SEMANTICS *nested_instr = NULL; - - while (current != NULL) { - switch(current->type) { - case INSTR_TOKEN: - nested_instr = - csp_orc_sa_instr_get_by_name(csound, - current->left->value->lexeme); - /* if (nested_instr->weight == NULL) { - nested_instr->weight = instr_weight_info_alloc(csound); - } */ - csp_weights_calculate_instr(csound, - current->right, nested_instr); - break; - -#ifdef LOOKUP_WEIGHTS - case T_OPCODE: - case T_OPCODE0: - instr->weight += csp_opcode_weight_fetch(csound, - current->value->lexeme); - break; -#else - case T_OPCODE: - case T_OPCODE0: - instr->weight += WEIGHT_OPCODE_NODE; - break; - case '=': - instr->weight += WEIGHT_S_ASSIGN_NODE; - break; -#endif - - default: - csound->Message(csound, - "WARNING: Unexpected node type in weight " - "calculation walk %i\n", current->type); - instr->weight += WEIGHT_UNKNOWN_NODE; - break; - } - - current = current->next; - } - - csound->Message(csound, - "[End Calculating Instrument weight from AST]\n"); -} - -void csp_weights_calculate(CSOUND *csound, TREE *root) -{ - csound->Message(csound, "Calculating Instrument weights from AST\n"); - - TREE *current = root; - INSTR_SEMANTICS *instr = NULL; - - while (current != NULL) { - switch(current->type) { - case INSTR_TOKEN: - if (current->left->type == T_INSTLIST) { - TREE *p = current->left; - while (p) { - if (p->left) { - instr = csp_orc_sa_instr_get_by_name(csound, - p->left->value->lexeme); - csp_weights_calculate_instr(csound, current->right, instr); - } - else { - instr = csp_orc_sa_instr_get_by_name(csound, - p->value->lexeme); - csp_weights_calculate_instr(csound, current->right, instr); - break; - } - p = p->right; - } - } - else { - instr = csp_orc_sa_instr_get_by_name(csound, - current->left->value->lexeme); - /* if (instr->weight == NULL) { - instr->weight = instr_weight_info_alloc(csound); - } */ - csp_weights_calculate_instr(csound, current->right, instr); - } - break; - - default: - break; - } - - current = current->next; - } - - csound->Message(csound, - "[End Calculating Instrument weights from AST]\n"); -} - -static void csp_orc_sa_opcode_dump_instr(CSOUND *csound, TREE *root) -{ - TREE *current = root; - - while (current != NULL) { - switch(current->type) { - case INSTR_TOKEN: - break; - - case T_OPCODE: - case T_OPCODE0: - csound->Message(csound, "OPCODE: %s\n", current->value->lexeme); - break; - - case '=': - break; - - default: - csound->Message(csound, "WARNING: Unexpected node type in weight " - "calculation walk %i\n", current->type); - break; - } - - current = current->next; - } -} - -void csp_orc_sa_opcode_dump(CSOUND *csound, TREE *root) -{ - csound->Message(csound, "Opcode List from AST\n"); - - TREE *current = root; - - while (current != NULL) { - switch (current->type) { - case INSTR_TOKEN: - csp_orc_sa_opcode_dump_instr(csound, current->right); - break; - - default: - break; - } - - current = current->next; - } - - csound->Message(csound, "[End Opcode List from AST]\n"); -} - - -/*********************************************************************** - * weights structure - */ - -struct opcode_weight_cache_entry_t { - uint32_t hash_val; - struct opcode_weight_cache_entry_t *next; - - char *name; - double play_time; - uint32_t weight; -}; - -//#define OPCODE_WEIGHT_CACHE_SIZE 128 - -//static int opcode_weight_cache_ctr; -//static struct opcode_weight_cache_entry_t * -// opcode_weight_cache[OPCODE_WEIGHT_CACHE_SIZE]; - -//static int opcode_weight_have_cache; - -static void opcode_weight_entry_add(CSOUND *csound, - char *name, uint32_t weight); - -static int - opcode_weight_entry_alloc(CSOUND *csound, - struct opcode_weight_cache_entry_t **entry, - char *name, uint32_t weight, uint32_t hash_val) -{ -#ifdef CAUTIOUS - if (UNLIKELY(entry == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter entry")); - if (UNLIKELY(name == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter name")); -#endif - - *entry = csound->Malloc(csound, - sizeof(struct opcode_weight_cache_entry_t)); - if (UNLIKELY(*entry == NULL)) { - csound->Die(csound, - Str("Failed to allocate Opcode Weight cache entry")); - } - memset(*entry, 0, sizeof(struct opcode_weight_cache_entry_t)); - - (*entry)->hash_val = hash_val; - (*entry)->name = name; - (*entry)->weight = weight; - - return CSOUND_SUCCESS; -} - -#if 0 -static int - opcode_weight_entry_dealloc(CSOUND *csound, - struct opcode_weight_cache_entry_t **entry) -{ -#ifdef CAUTIOUS - if (UNLIKELY(entry == NULL || *entry == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter entry")); -#endif - - csound->Free(csound, *entry); - *entry = NULL; - - return CSOUND_SUCCESS; -} -#endif - -uint32_t csp_opcode_weight_fetch(CSOUND *csound, char *name) -{ -#ifdef CAUTIOUS - if (UNLIKELY(name == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter name")); -#endif - - if (csound->opcode_weight_have_cache == 0) { - return WEIGHT_OPCODE_NODE; - } - else { - uint32_t hash_val = hash_string(name, OPCODE_WEIGHT_CACHE_SIZE); - struct opcode_weight_cache_entry_t *curr = - csound->opcode_weight_cache[hash_val]; - while (curr != NULL) { - if (UNLIKELY(strcmp(curr->name, name) == 0)) { - return curr->weight; - } - curr = curr->next; - } - /* no weight for this opcode use default */ - csound->Message(csound, - "WARNING: no weight found for opcode: %s\n", name); - return WEIGHT_OPCODE_NODE; - } -} - -void csp_opcode_weight_set(CSOUND *csound, char *name, double play_time) -{ -#ifdef CAUTIOUS - if (UNLIKELY(name == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter name")); -#endif - - if (csound->opcode_weight_have_cache == 0) { - return; - } - else { - uint32_t hash_val = hash_string(name, OPCODE_WEIGHT_CACHE_SIZE); - struct opcode_weight_cache_entry_t *curr = - csound->opcode_weight_cache[hash_val]; - TRACE_0("Adding %s [%u]\n", name, hash_val); - - while (curr != NULL) { - TRACE_0("Looking at: %s\n", curr->name); - if (strcmp(curr->name, name) == 0) { - if (UNLIKELY(curr->play_time == 0)) { - curr->play_time = play_time; - } - else { - curr->play_time = 0.9 * curr->play_time + 0.1 * play_time; - } - return; - } - curr = curr->next; - } - - TRACE_0("Not Found Adding\n"); - - /* not here add it and then set the play time */ - opcode_weight_entry_add(csound, strdup(name), WEIGHT_OPCODE_NODE); - TRACE_0("Not Found Added\n"); - csp_opcode_weight_set(csound, name, play_time); - TRACE_0("Not Found Done\n"); - } -} - -static void opcode_weight_entry_add(CSOUND *csound, - char *name, uint32_t weight) -{ -#ifdef CAUTIOUS - if (UNLIKELY(name == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter name")); -#endif - - uint32_t hash_val = hash_string(name, OPCODE_WEIGHT_CACHE_SIZE); - struct opcode_weight_cache_entry_t *curr = - csound-> opcode_weight_cache[hash_val]; - int found = 0; - TRACE_0("entry_add %s [%u]\n", name, hash_val); - while (curr != NULL) { - if (strcmp(curr->name, name) == 0) { - found = 1; - break; - } - curr = curr->next; - } - if (found == 0) { - TRACE_0("Allocing %s\n", name); - opcode_weight_entry_alloc(csound, &curr, name, weight, hash_val); - csound->opcode_weight_cache_ctr++; - - curr->next = csound->opcode_weight_cache[hash_val]; - csound->opcode_weight_cache[hash_val] = curr; - } -} - -void csp_weights_dump(CSOUND *csound) -{ - if (UNLIKELY(csound->opcode_weight_have_cache == 0)) { - csound->Message(csound, - Str("No Weights to Dump (Using Defaults)\n")); - return; - } - else { - uint32_t bin_ctr = 0; - csound->Message(csound, "Weights Dump\n"); - while (bin_ctr < OPCODE_WEIGHT_CACHE_SIZE) { - struct opcode_weight_cache_entry_t *entry = - csound->opcode_weight_cache[bin_ctr]; - - while (entry != NULL) { - csound->Message(csound, "%s => %u\n", - entry->name, entry->weight); - entry = entry->next; - } - - bin_ctr++; - } - csound->Message(csound, "[Weights Dump end]\n"); - } -} - -void csp_weights_dump_file(CSOUND *csound) -{ - char *path; - FILE *f; - uint32_t bin_ctr = 0; - double min = 0, max = 0; - if (UNLIKELY(csound->opcode_weight_have_cache == 0)) { - csound->Message(csound, "No Weights to Dump to file\n"); - return; - } - - path = csound->weights; - if (path == NULL) { - return; - } - - f = fopen(path, "w+"); - if (UNLIKELY(f == NULL)) { - csound->Die(csound, - Str("Opcode Weight Spec File not found at: %s"), path); - } - - while (bin_ctr < OPCODE_WEIGHT_CACHE_SIZE) { - struct opcode_weight_cache_entry_t *entry = - csound->opcode_weight_cache[bin_ctr]; - - while (entry != NULL) { - if (min == 0) { - min = entry->play_time; - } - - if (entry->play_time != 0 && entry->play_time < min) { - min = entry->play_time; - } - else if (entry->play_time != 0 && entry->play_time > max) { - max = entry->play_time; - } - - entry = entry->next; - } - - bin_ctr++; - } - - { - double scale = 99 / (max - min); - - bin_ctr = 0; - while (bin_ctr < OPCODE_WEIGHT_CACHE_SIZE) { - struct opcode_weight_cache_entry_t *entry = - csound->opcode_weight_cache[bin_ctr]; - - while (entry != NULL) { - uint32_t weight = floor((entry->play_time - min) * scale) + 1; - fprintf(f, "%s, %u, %g\n", entry->name, weight, entry->play_time); - entry = entry->next; - } - - bin_ctr++; - } - } - fclose(f); -} - -void csp_weights_dump_normalised(CSOUND *csound) -{ - uint32_t bin_ctr = 0; - double min = 0, max = 0; - if (UNLIKELY(csound->opcode_weight_have_cache == 0)) { - csound->Message(csound, Str("No Weights to Dump (Using Defaults)\n")); - return; - } - - csound->Message(csound, Str("Weights Dump\n")); - while (bin_ctr < OPCODE_WEIGHT_CACHE_SIZE) { - struct opcode_weight_cache_entry_t *entry = - csound->opcode_weight_cache[bin_ctr]; - - while (entry != NULL) { - if (min == 0) { - min = entry->play_time; - } - - if (entry->play_time != 0 && entry->play_time < min) { - min = entry->play_time; - } - else if (entry->play_time != 0 && entry->play_time > max) { - max = entry->play_time; - } - - entry = entry->next; - } - - bin_ctr++; - } - - csound->Message(csound, "min: %g\n", min); - csound->Message(csound, "max: %g\n", max); - - { - double scale = 99 / (max - min); - - csound->Message(csound, "scale: %g\n", scale); - - bin_ctr = 0; - while (bin_ctr < OPCODE_WEIGHT_CACHE_SIZE) { - struct opcode_weight_cache_entry_t *entry = - csound->opcode_weight_cache[bin_ctr]; - - while (entry != NULL) { - uint32_t weight = floor((entry->play_time - min) * scale) + 1; - csound->Message(csound, "%s => %u, %g\n", - entry->name, weight, entry->play_time); - entry = entry->next; - } - - bin_ctr++; - } - } - if (csound->oparms->calculateWeights) { - csp_weights_dump_file(csound); - } - - csound->Message(csound, "[Weights Dump end]\n"); -} - -void csp_weights_load(CSOUND *csound) -{ - char *path = csound->weights; - FILE *f; - char buf[1024]; - char *opcode_name = NULL; - int weight = 0; - int ctr = 0; - int col = 0; - int c; - if (path == NULL) { - csound->opcode_weight_have_cache = 0; - return; - } - csound->opcode_weight_have_cache = 1; - - memset(csound->opcode_weight_cache, 0, - sizeof(struct opcode_weight_cache_entry_t *) * - OPCODE_WEIGHT_CACHE_SIZE); - - f = fopen(path, "r"); - if (UNLIKELY(f == NULL)) { - csound->Die(csound, - Str("Opcode Weight Spec File not found at: %s"), path); - } - while ((c = fgetc(f)) != EOF) { - if (col == 0 && c == ',') { - col = 1; - buf[ctr] = '\0'; - opcode_name = strdup(buf); - ctr = -1; - } - else if (col == 1 && c == '\n') { - col = 0; - buf[ctr] = '\0'; - weight = atoi(buf); - opcode_weight_entry_add(csound, opcode_name, weight); - opcode_name = NULL; weight = 0; - ctr = -1; - } - else if (col == 1 && c == ',') { - col = 2; - buf[ctr] = '\0'; - weight = atoi(buf); - ctr = -1; - } - else if (col == 2 && c == '\n') { - double play_time; - col = 0; - buf[ctr] = '\0'; - play_time = atof(buf); - opcode_weight_entry_add(csound, opcode_name, weight); - csp_opcode_weight_set(csound, opcode_name, play_time); - opcode_name = NULL; weight = 0; - ctr = -1; - } - else { - buf[ctr] = c; - } - ctr++; - - if (ctr > 1024-1) { - // do something about buffer overrun - } - } - - fclose(f); -} - - - -/*********************************************************************** - * weighting decision - */ - -/* static struct instr_weight_info_t *weight_info; */ - -struct weight_decision_info_t { - uint32_t weight_min; - uint32_t weight_max; - int roots_avail_min; - int roots_avail_max; -}; - -static struct weight_decision_info_t global_weight_info = {0, 0, 0, 0}; -/* {1125, 0, 2, 0}; */ - -void csp_orc_sa_parallel_compute_spec_read(CSOUND *csound, const char *path) -{ - FILE *f = fopen(path, "r"); - int rc = 0; - if (UNLIKELY(f == NULL)) { - csound->Die(csound, Str("Parallel Spec File not found at: %s"), path); - } - - rc = fscanf(f, "%u\n", &(global_weight_info.weight_min)); - if (UNLIKELY(rc != 0 || rc == EOF)) - csound->Die(csound, - Str("Parallel Spec File invalid format expected " - "weight_min parameter")); - rc = fscanf(f, "%u\n", &(global_weight_info.weight_max)); - if (UNLIKELY(rc != 0 || rc == EOF)) - csound->Die(csound, - Str("Parallel Spec File invalid format expected " - "weight_max parameter")); - rc = fscanf(f, "%i\n", &(global_weight_info.roots_avail_min)); - if (UNLIKELY(rc != 0 || rc == EOF)) - csound->Die(csound, Str("Parallel Spec File invalid format " - "expected roots_avail_min parameter")); - rc = fscanf(f, "%i\n", &(global_weight_info.roots_avail_max)); - if (UNLIKELY(rc != 0 || rc == EOF)) - csound->Die(csound, Str("Parallel Spec File invalid format expected" - " roots_avail_max parameter")); - - /* todo fix this */ - fclose(f); -} - -void csp_parallel_compute_spec_setup(CSOUND *csound) -{ - char *path = "Default"; - - if (csound->weight_info != NULL) { - path = csound->weight_info; - csp_orc_sa_parallel_compute_spec_read(csound, path); - } - - csound->Message(csound, "InstrWeightInfo: [%s]\n" - " weight_min: %u\n" - " weight_max: %u\n" - " roots_avail_min: %i\n" - " roots_avail_max: %i\n", - path, - global_weight_info.weight_min, - global_weight_info.weight_max, - global_weight_info.roots_avail_min, - global_weight_info.roots_avail_max); -} - -#if 0 -int inline csp_parallel_compute_should(CSOUND *csound, DAG *dag) -{ - return (dag->weight >= global_weight_info.weight_min && - dag->max_roots >= global_weight_info.roots_avail_min); - /* return (dag->ratio > 0.15 && dag->ratio < 0.85); */ - /* return (dag->weight->weight > weight_info->weight); */ - /* return 1; */ -} -#endif - -/*********************************************************************** - * dag2 data structure - */ - -/* prototypes for dag2 */ -static void dag_node_2_alloc(CSOUND *csound, DAG_NODE **dag_node, - INSTR_SEMANTICS *instr, INSDS *insds); -static void dag_node_2_alloc_list(CSOUND *csound, DAG_NODE **dag_node, - int count); -static void dag_node_2_dealloc(CSOUND *csound, DAG_NODE **dag_node); - -/* add all the instruments to a DAG found in an insds chain */ -/* static DAG *csp_dag_build_initial(CSOUND *csound, INSDS *chain); */ -/* allocate the dynamic structures which depend on the number of instruments - in the dag */ -/* static void csp_dag_build_prepare(CSOUND *csound, DAG *dag); */ -/* build the edges (fill out the table) */ -/* static void csp_dag_build_edges(CSOUND *csound, DAG *dag); */ -/* find the roots in the DAG and setup the root countdowns */ -static void csp_dag_build_roots(CSOUND *csound, DAG *dag); -/* perpare DAG after building */ -/* static void csp_dag_prepare_use_first(CSOUND *csound, DAG *dag); */ -/* perpare DAG after getting out of the cache */ -static void csp_dag_prepare_use(CSOUND *csound, DAG *dag); -/* follow insds chain in nodes to update insds pointers */ -static inline void csp_dag_prepare_use_insds(CSOUND *csound, DAG *dag, - INSDS *chain); - -#define DAG_NO_LINK 0 -#define DAG_STRONG_LINK 1 -#define DAG_WEAK_LINK 2 - -void csp_dag_alloc(CSOUND *csound, DAG **dag) -{ -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - *dag = (DAG*)csound->Malloc(csound, sizeof(DAG)); - if (UNLIKELY(*dag == NULL)) { - csound->Die(csound, Str("Failed to allocate dag")); - } - memset(*dag, 0, sizeof(DAG)); - strncpy((*dag)->hdr.hdr, DAG_2_HDR, HDR_LEN); - (*dag)->hdr.type = DAG_NODE_DAG; - INIT_LOCK((*dag)->spinlock); - INIT_LOCK((*dag)->consume_spinlock); - (*dag)->count = 0; - (*dag)->first_root_ori = -1; - /* (*dag)->weight = instr_weight_info_alloc(csound); */ - (*dag)->weight = 0; - (*dag)->max_roots = 0; -} - -void csp_dag_dealloc(CSOUND *csound, DAG **dag) -{ - int ctr = 0; -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL || *dag == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - while (ctr < (*dag)->count) { - dag_node_2_dealloc(csound, &((*dag)->all[ctr])); - (*dag)->all[ctr] = NULL; - ctr++; - } - - if ((*dag)->all != NULL) csound->Free(csound, (*dag)->all); - if ((*dag)->roots_ori != NULL) csound->Free(csound, (*dag)->roots_ori); - if ((*dag)->roots != NULL) csound->Free(csound, (*dag)->roots); - if ((*dag)->root_seen_ori!= NULL) - csound->Free(csound, (*dag)->root_seen_ori); - if ((*dag)->root_seen != NULL) csound->Free(csound, (*dag)->root_seen); - if ((*dag)->table_ori != NULL) csound->Free(csound, (*dag)->table_ori); - if ((*dag)->table != NULL) csound->Free(csound, (*dag)->table); - if ((*dag)->remaining_count_ori != NULL) - csound->Free(csound, (*dag)->remaining_count_ori); - if ((*dag)->remaining_count!= NULL) - csound->Free(csound, (*dag)->remaining_count); - - /* csound->Free(csound, (*dag)->weight); */ - - csound->Free(csound, *dag); - *dag = NULL; -} - -static void dag_node_2_alloc(CSOUND *csound, DAG_NODE **dag_node, - INSTR_SEMANTICS *instr, INSDS *insds) -{ -#ifdef CAUTIOUS - if (UNLIKELY(dag_node == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag_node")); - if (UNLIKELY(instr == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter instr")); - if (UNLIKELY(insds == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter insds")); -#endif - - *dag_node = csound->Malloc(csound, sizeof(DAG_NODE)); - if (UNLIKELY(*dag_node == NULL)) { - csound->Die(csound, Str("Failed to allocate dag_node")); - } - memset(*dag_node, 0, sizeof(DAG_NODE)); - strncpy((*dag_node)->hdr.hdr, DAG_NODE_2_HDR, HDR_LEN); - (*dag_node)->hdr.type = DAG_NODE_INDV; - (*dag_node)->instr = instr; - (*dag_node)->insds = insds; -} - -static void dag_node_2_alloc_list(CSOUND *csound, - DAG_NODE **dag_node, int count) -{ -#ifdef CAUTIOUS - if (dag_node == NULL) - csound->Die(csound, Str("Invalid NULL Parameter dag_node")); - if (count <= 0) - csound->Die(csound, - Str("Invalid Parameter count must be greater than 0")); -#endif - - *dag_node = csound->Malloc(csound, sizeof(DAG_NODE)); - if (*dag_node == NULL) { - csound->Die(csound, Str("Failed to allocate dag_node")); - } - memset(*dag_node, 0, sizeof(DAG_NODE)); - strncpy((*dag_node)->hdr.hdr, DAG_NODE_2_HDR, HDR_LEN); - (*dag_node)->hdr.type = DAG_NODE_LIST; - (*dag_node)->nodes = csound->Malloc(csound, - sizeof(DAG_NODE *) * count); - (*dag_node)->count = count; -} - -static void dag_node_2_dealloc(CSOUND *csound, DAG_NODE **dag_node) -{ -#ifdef CAUTIOUS - if (UNLIKELY(dag_node == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag_node")); - if (UNLIKELY(*dag_node == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag_node")); -#endif - - if ((*dag_node)->hdr.type == DAG_NODE_LIST) { - csound->Free(csound, (*dag_node)->nodes); - } - - csound->Free(csound, *dag_node); - *dag_node = NULL; -} - -void csp_dag_add(CSOUND *csound, DAG *dag, - INSTR_SEMANTICS *instr, INSDS *insds) -{ - DAG_NODE *dag_node = NULL; - DAG_NODE **old = dag->all; - //int ctr = 0; - dag_node_2_alloc(csound, &dag_node, instr, insds); - - TRACE_1("dag->count = %d\n", dag->count); - // dag->all = - // (DAG_NODE **)csound->Malloc(csound, - // sizeof(DAG_NODE *) * (dag->count + 1)); - /* Can not this be done with memcpy or Realloc */ - // while (ctr < dag->count) { - // dag->all[ctr] = old[ctr]; - // ctr++; - // } - // dag->all[ctr] = dag_node; - // if (old != NULL) csound->Free(csound, old); - dag->all = - (DAG_NODE **)csound->ReAlloc(csound, old, - sizeof(DAG_NODE *) * (dag->count + 1)); - dag->all[dag->count++] = dag_node; - //dag->count++; - - if (dag->count == 1) { - dag->insds_chain_start = dag->all[0]; - } - else if (dag->count > 1) { - dag->all[dag->count - 2]->insds_chain_next = dag->all[dag->count - 1]; - } -} - -inline static void csp_dag_build_prepare(CSOUND *csound, DAG *dag) -{ -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, - Str("Invalid NULL Parameter dag")); -#endif - - if (dag->roots_ori != NULL) csound->Free(csound, dag->roots_ori); - if (dag->roots != NULL) csound->Free(csound, dag->roots); - if (dag->root_seen_ori != NULL) - csound->Free(csound, dag->root_seen_ori); - if (dag->root_seen != NULL) csound->Free(csound, dag->root_seen); - if (dag->remaining_count_ori != NULL) - csound->Free(csound, dag->remaining_count_ori); - if (dag->remaining_count != NULL) - csound->Free(csound, dag->remaining_count); - if (dag->table_ori != NULL) csound->Free(csound, dag->table_ori); - if (dag->table != NULL) csound->Free(csound, dag->table); - - if (dag->count == 0) { - dag->roots_ori = NULL; - dag->roots = NULL; - dag->root_seen_ori = NULL; - dag->root_seen = NULL; - dag->remaining_count_ori = NULL; - dag->remaining_count = NULL; - dag->table_ori = NULL; - dag->table = NULL; - return; - } - - dag->roots_ori = - csound->Malloc(csound, sizeof(DAG_NODE *) * dag->count); - dag->roots = csound->Malloc(csound, sizeof(DAG_NODE *) * dag->count); - dag->root_seen_ori = csound->Malloc(csound, sizeof(uint8_t) * dag->count); - dag->root_seen = csound->Malloc(csound, sizeof(uint8_t) * dag->count); - dag->remaining_count_ori = - csound->Malloc(csound, sizeof(int) * dag->count); - dag->remaining_count = - csound->Malloc(csound, sizeof(int) * dag->count); - { - long int ss = (sizeof(uint8_t *) * dag->count) + - (sizeof(uint8_t) * dag->count * dag->count); - dag->table_ori = csound->Malloc(csound, ss); - ss = (sizeof(uint8_t *) * dag->count) + - (sizeof(uint8_t) * dag->count * dag->count); - dag->table = csound->Malloc(csound, ss); - } - /* set up pointers for 2D array */ - { - int ctr = 0; - while (ctr < dag->count) { - dag->table_ori[ctr] = ((uint8_t *)dag->table_ori) + - (sizeof(uint8_t *) * dag->count) + - (sizeof(uint8_t) * dag->count * ctr); - dag->table[ctr] = ((uint8_t *)dag->table) + - (sizeof(uint8_t *) * dag->count) + - (sizeof(uint8_t) * dag->count * ctr); - ctr++; - } - } - memset(dag->roots_ori, 0, sizeof(DAG_NODE *) * dag->count); - memset(dag->roots, 0, sizeof(DAG_NODE *) * dag->count); - memset(dag->root_seen_ori, 0, sizeof(uint8_t) * dag->count); - memset(dag->root_seen, 0, sizeof(uint8_t) * dag->count); - memset(dag->remaining_count_ori, 0, sizeof(int) * dag->count); - memset(dag->remaining_count, 0, sizeof(int) * dag->count); - memset(dag->table_ori[0], DAG_NO_LINK, - sizeof(uint8_t) * dag->count * dag->count); - memset(dag->table[0], DAG_NO_LINK, - sizeof(uint8_t) * dag->count * dag->count); -} - -inline static DAG *csp_dag_build_initial(CSOUND *csound, INSDS *chain) -{ - DAG *dag = NULL; -#ifdef CAUTIOUS - if (UNLIKELY(chain == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter chain")); -#endif - csp_dag_alloc(csound, &dag); - while (chain != NULL) { - INSTR_SEMANTICS *current_instr = - csp_orc_sa_instr_get_by_num(csound, chain->insno); - if (current_instr == NULL) { - current_instr = - csp_orc_sa_instr_get_by_name(csound, csound->instrtxtp[chain->insno]->insname); - if (current_instr == NULL) - csound->Die(csound, - Str("Failed to find semantic information" - " for instrument '%i'"), - chain->insno); - } - csp_dag_add(csound, dag, current_instr, chain); - dag->weight += current_instr->weight; - chain = chain->nxtact; - } - return dag; -} - -inline static void csp_dag_build_edges(CSOUND *csound, DAG *dag) -{ -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - int dag_root_ctr = 0; - while (dag_root_ctr < dag->count) { - int dag_curr_ctr = dag_root_ctr + 1; - while (dag_curr_ctr < dag->count) { - - /* csound->Message(csound, "=== %s <> %s ===\n", - dag->all[dag_root_ctr]->instr->name, - dag->all[dag_curr_ctr]->instr->name); */ - - int depends = DAG_NO_LINK; - struct set_t *write_intersection = NULL; - csp_set_intersection(csound, dag->all[dag_root_ctr]->instr->write, - dag->all[dag_curr_ctr]->instr->read, - &write_intersection); - if (csp_set_count(csound, write_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &write_intersection); - - /* csound->Message(csound, - "write_intersection depends: %i\n", depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->write); - csp_set_print(csound, dag->all[dag_curr_ctr]->instr->read); */ - - struct set_t *read_intersection = NULL; - csp_set_intersection(csound, dag->all[dag_root_ctr]->instr->read, - dag->all[dag_curr_ctr]->instr->write, - &read_intersection); - if (csp_set_count(csound, read_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &read_intersection); - - /* csound->Message(csound, - "read_intersection depends: %i\n", depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->read); - csp_set_print(csound, dag->all[dag_curr_ctr]->instr->write); */ - - struct set_t *double_write_intersection = NULL; - csp_set_intersection(csound, dag->all[dag_root_ctr]->instr->write, - dag->all[dag_curr_ctr]->instr->write, - &double_write_intersection); - if (csp_set_count(csound, double_write_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &double_write_intersection); - - /* csound->Message(csound, "double_write_intersection depends: %i\n", - depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->read); - csp_set_print(csound, dag->all[dag_curr_ctr]->instr->write); */ - - struct set_t *readwrite_write_intersection = NULL; - csp_set_intersection(csound, - dag->all[dag_root_ctr]->instr->read_write, - dag->all[dag_curr_ctr]->instr->write, - &readwrite_write_intersection); - if (csp_set_count(csound, readwrite_write_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &readwrite_write_intersection); - - /* csound->Message(csound, - "readwrite_write_intersection depends: %i\n", - depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->read_write); - csp_set_print(csound, dag->all[dag_curr_ctr]->instr->write); */ - - struct set_t *readwrite_read_intersection = NULL; - csp_set_intersection(csound, - dag->all[dag_root_ctr]->instr->read_write, - dag->all[dag_curr_ctr]->instr->read, - &readwrite_read_intersection); - if (csp_set_count(csound, readwrite_read_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &readwrite_read_intersection); - - /* csound->Message(csound, - "readwrite_read_intersection depends: %i\n", - depends); - csp_set_print(csound, - dag->all[dag_root_ctr]->instr->read_write); - csp_set_print(csound, dag->all[dag_curr_ctr]->instr->write); */ - - struct set_t *read_readwrite_intersection = NULL; - csp_set_intersection(csound, dag->all[dag_root_ctr]->instr->read, - dag->all[dag_curr_ctr]->instr->read_write, - &read_readwrite_intersection); - if (csp_set_count(csound, read_readwrite_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &read_readwrite_intersection); - - /* csound->Message(csound, - "read_readwrite_intersection depends: %i\n", - depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->read); - csp_set_print(csound, - dag->all[dag_curr_ctr]->instr->read_write); */ - - struct set_t *write_readwrite_intersection = NULL; - csp_set_intersection(csound, dag->all[dag_root_ctr]->instr->write, - dag->all[dag_curr_ctr]->instr->read_write, - &write_readwrite_intersection); - if (csp_set_count(csound, write_readwrite_intersection) != 0) { - depends |= DAG_STRONG_LINK; - } - csp_set_dealloc(csound, &write_readwrite_intersection); - - /* csound->Message(csound, - "write_readwrite_intersection depends: %i\n", - depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->write); - csp_set_print(csound, - dag->all[dag_curr_ctr]->instr->read_write); */ - - struct set_t *readwrite_readwrite_intersection = NULL; - csp_set_intersection(csound, - dag->all[dag_root_ctr]->instr->read_write, - dag->all[dag_curr_ctr]->instr->read_write, - &readwrite_readwrite_intersection); - if (csp_set_count(csound, - readwrite_readwrite_intersection) != 0) { - depends |= DAG_WEAK_LINK; - } - csp_set_dealloc(csound, &readwrite_readwrite_intersection); - - /* csound->Message(csound, - "readwrite_readwrite_intersection depends: %i\n", - depends); - csp_set_print(csound, dag->all[dag_root_ctr]->instr->read_write); - csp_set_print(csound, - dag->all[dag_curr_ctr]->instr->read_write); */ - - if (depends & DAG_STRONG_LINK) { - dag->table_ori[dag_root_ctr][dag_curr_ctr] = DAG_STRONG_LINK; - } - else if (depends & DAG_WEAK_LINK) { - dag->table_ori[dag_root_ctr][dag_curr_ctr] = DAG_WEAK_LINK; - } - dag_curr_ctr++; - } - dag_root_ctr++; - } -} - -static void csp_dag_build_roots(CSOUND *csound, DAG *dag) -{ - int col = 0; -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - while (col < dag->count) { - int exists_in = 0; - int row = 0; - while (row < dag->count) { - if (dag->table_ori[row][col] == DAG_STRONG_LINK) { - exists_in = 1; - dag->remaining_count_ori[col]++; - } - row++; - } - if (exists_in == 0) { - dag->roots_ori[col] = dag->all[col]; - dag->root_seen_ori[col] = 1; - if (dag->first_root_ori == -1) { - dag->first_root_ori = col; - } - } - col++; - } -} - -inline static void csp_dag_prepare_use_first(CSOUND *csound, DAG *dag) -{ - - memcpy(dag->table[0], dag->table_ori[0], - sizeof(uint8_t) * dag->count * dag->count); -} - -static void csp_dag_prepare_use(CSOUND *csound, DAG *dag) -{ - #ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - memcpy(dag->roots, dag->roots_ori, sizeof(DAG_NODE *) * dag->count); - memcpy(dag->root_seen, dag->root_seen_ori, sizeof(uint8_t) * dag->count); - memcpy(dag->remaining_count, - dag->remaining_count_ori, sizeof(int) * dag->count); - dag->remaining = dag->count; - dag->first_root = dag->first_root_ori; - dag->root_seen[dag->first_root] = 2; -} - -static inline void csp_dag_prepare_use_insds(CSOUND *csound, - DAG *dag, INSDS *chain) -{ - DAG_NODE *node; -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - TRACE_2("updating insds\n"); - node = dag->insds_chain_start; - INSDS *current_insds = chain; - while (node != NULL && current_insds != NULL) { - TRACE_2(" node: %p, insds: %p\n", node, current_insds); - node->insds = current_insds; - current_insds = current_insds->nxtact; - node = node->insds_chain_next; - } -} - -static void csp_dag_calculate_max_roots(CSOUND *csound, DAG *dag) -{ - INSTR_SEMANTICS *instr = NULL; - INSDS *insds = NULL; - DAG_NODE *node; - int update_hdl = -1; - -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - while (!csp_dag_is_finished(csound, dag)) { - int ctr = 0, roots_avail = 0; - while (ctr < dag->count) { - if (dag->roots[ctr] != NULL) { - roots_avail++; - } - ctr++; - } - if (roots_avail > dag->max_roots) { - dag->max_roots = roots_avail; - } - csp_dag_consume(csound, dag, &node, &update_hdl); - instr = node->instr; - insds = node->insds; - - if (insds != NULL) { - csp_dag_consume_update(csound, dag, update_hdl); - } - } -} - -void csp_dag_build(CSOUND *csound, DAG **dag, INSDS *chain) -{ -#ifdef CAUTIOUS - if (dag == NULL) - csound->Die(csound, Str("Invalid NULL Parameter dag")); - if (chain == NULL) - csound->Die(csound, Str("Invalid NULL Parameter chain")); -#endif - - TRACE_5("DAG BUILD\n"); - *dag = csp_dag_build_initial(csound, chain); - csp_dag_build_prepare(csound, *dag); - csp_dag_build_edges(csound, *dag); - csp_dag_build_roots(csound, *dag); - csp_dag_prepare_use_first(csound, *dag); - csp_dag_prepare_use(csound, *dag); - - csp_dag_calculate_max_roots(csound, *dag); - csp_dag_prepare_use(csound, *dag); - TRACE_5("DAG BUILT\n"); -} - -int inline csp_dag_is_finished(CSOUND *csound, DAG *dag) -{ -#ifdef CAUTIOUS - if (dag == NULL) - csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - /* TAKE_LOCK(&(dag->spinlock)); - int res = (dag->remaining <= 0); - RELS_LOCK(&(dag->spinlock)); - return res; - */ - TRACE_5("DAG is finished %d\n", dag->remaining <= 0); - return (dag->remaining <= 0); -} - -/* - * consume an instr and update the first root cache - */ -//static int waiting_for_ending=0; -void csp_dag_consume(CSOUND *csound, DAG *dag, - DAG_NODE **node, int *update_hdl) -{ - DAG_NODE *dag_node = NULL; - int ctr, first_root; - - TRACE_5("DAG consume\n"); -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter dag")); - if (UNLIKELY(node == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter node")); - if (UNLIKELY(update_hdl == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter update_hdl")); -#endif - - TRACE_2("[%i] Consuming PreLock [%i, %i] +++++\n", - csp_thread_index_get(csound), - dag->first_root, dag->consume_spinlock); - - TAKE_LOCK(&(dag->consume_spinlock)); - - TRACE_2("[%i] Consuming Have Consume_Spinlock [%i]\n", - csp_thread_index_get(csound), dag->first_root); - - if (dag->remaining <= 0) { - TRACE_5("[%i] Consuming Nothing [%i, %i]\n", - csp_thread_index_get(csound), dag->first_root, - dag->consume_spinlock); - RELS_LOCK(&(dag->consume_spinlock)); - /* RELS_LOCK(&(dag->spinlock)); */ - *node = NULL; - *update_hdl = -1; - return; - } - if (UNLIKELY(dag->first_root == -1)) { - - // csp_dag_print(csound, dag); - - /* csound->Die(csound, */ - /* Str("Expected a root to perform. Found none (%i remaining)"), */ - /* dag->remaining); */ - RELS_LOCK(&(dag->consume_spinlock)); - /* RELS_LOCK(&(dag->spinlock)); */ - *node = NULL; - *update_hdl = -1; - //{ struct timespec tt = {0, 100}; - // nanosleep(&tt, NULL); - //} - /* Really ought to wait until someone leaves comsume_dag_update */ - return; - } - - first_root = dag->first_root; - - TRACE_5("[%i] Consuming root:%i\n", - csp_thread_index_get(csound), first_root); - - dag_node = dag->roots[first_root]; - dag->roots[first_root] = NULL; - ctr = 0; - dag->remaining--; - dag->first_root = -1; - - if (dag->remaining > 0) { - while (ctr < dag->count) { - if (dag->roots[ctr] != NULL) { - dag->first_root = ctr; - if (dag->root_seen[ctr] == 1) { - dag->root_seen[ctr] = 2; - TRACE_5("[%i] Consuming Unlock [%i] -----\n", - csp_thread_index_get(csound), dag->first_root); - // RELS_LOCK(&(dag->consume_spinlock)); - } - break; - } - ctr++; - } - } - else { - // RELS_LOCK(&(dag->consume_spinlock)); - } - - RELS_LOCK(&(dag->consume_spinlock)); - - *node = dag_node; - *update_hdl = first_root; - - TRACE_5("[%i] Consuming Leave [%i]\n", - csp_thread_index_get(csound), dag->first_root); -} - -/* - * update the roots countdown and roots after consumeing a node - */ -void csp_dag_consume_update(CSOUND *csound, DAG *dag, int update_hdl) -{ - int col = 0; - TRACE_5("DAG update\n"); -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL)) - csound->Die(csound,Str( "Invalid NULL Parameter dag")); - if (UNLIKELY(update_hdl < 0 || update_hdl >= dag->count)) - csound->Die(csound, - Str("Invalid Parameter update_hdl is outside the DAG range")); -#endif - - TAKE_LOCK(&(dag->consume_spinlock)); - TRACE_2("[%i] Consuming Update [%i, %i]\n", - csp_thread_index_get(csound), dag->first_root, dag->consume_spinlock); - - while (col < dag->count) { - if (dag->table[update_hdl][col] == DAG_STRONG_LINK) { - dag->remaining_count[col]--; - TRACE_5("[%i] Consuming Remaining (%i, %i) [%i, %i]\n", - csp_thread_index_get(csound), col, dag->remaining_count[col], - dag->first_root, dag->consume_spinlock); - - if (dag->remaining_count[col] == 0) { - // TAKE_LOCK(&(dag->spinlock)); - TRACE_5("[%i] Consuming Found Root [%i]\n", - csp_thread_index_get(csound), dag->first_root); - - if (dag->root_seen[col] == 0) { - dag->root_seen[col] = 1; - dag->roots[col] = dag->all[col]; - TRACE_5("[%i] Consuming First Root Set [%i]\n", - csp_thread_index_get(csound), dag->first_root); - } - - if (dag->root_seen[col] == 1 && dag->first_root == -1) { - dag->first_root = col; - - dag->root_seen[col] = 2; - TRACE_3("[%i] Consuming Unlock [%i] -----\n", - csp_thread_index_get(csound), dag->first_root); - // RELS_LOCK(&(dag->consume_spinlock)); - } - //RELS_LOCK(&(dag->spinlock)); - } - } - col++; - } - RELS_LOCK(&(dag->consume_spinlock)); - - TRACE_2("[%i] Consuming Update Leave [%i, %i]\n", - csp_thread_index_get(csound), dag->first_root, dag->consume_spinlock); -} - -static char *csp_dag_string(CSOUND *csound, DAG *dag) -{ -#define DAG_2_BUF 8196 - char buf[DAG_2_BUF]; - char *bufp = buf; - -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); -#endif - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "Dag2:\n"); - int ctr = 0; - while (ctr < dag->count) { - if (dag->all[ctr]->hdr.type == DAG_NODE_INDV) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " %s [%p]\n", - dag->all[ctr]->instr->name, dag->all[ctr]); - } - else if (dag->all[ctr]->hdr.type == DAG_NODE_LIST) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " "); - int inner_ctr = 0; - while (inner_ctr < dag->all[ctr]->count) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "%s [%p] ", - dag->all[ctr]->nodes[inner_ctr]->instr->name, - dag->all[ctr]->nodes[inner_ctr]); - inner_ctr++; - } - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "\n"); - } - ctr++; - } - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "roots:\n"); - ctr = 0; - while (ctr < dag->count) { - if (dag->roots[ctr] != NULL) { - if (dag->all[ctr]->hdr.type == DAG_NODE_INDV) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " %s [%p]\n", - dag->roots[ctr]->instr->name, dag->roots[ctr]); - } - else if (dag->all[ctr]->hdr.type == DAG_NODE_LIST) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " "); - int inner_ctr = 0; - while (inner_ctr < dag->roots[ctr]->count) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "%s [%p] ", - dag->roots[ctr]->nodes[inner_ctr]->instr->name, - dag->roots[ctr]->nodes[inner_ctr]); - inner_ctr++; - } - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "\n"); - } - } - ctr++; - } - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "root_seen:\n "); - ctr = 0; - while (ctr < dag->count) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " %hhu ", - dag->root_seen[ctr]); - ctr++; - } - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "\n"); - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "remaining:\n"); - ctr = 0; - while (ctr < dag->count) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), " %i\n", - dag->remaining_count[ctr]); - ctr++; - } - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), - "remaining: %i\n", dag->remaining); - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), - "first_root: %i\n", dag->first_root); - - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "table:\n"); - ctr = 0; - while (ctr < dag->count) { - int inner_ctr = 0; - while (inner_ctr < dag->count) { - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "%hhi ", - dag->table[ctr][inner_ctr]); - inner_ctr++; - } - bufp = bufp + snprintf(bufp, DAG_2_BUF - (bufp - buf), "\n"); - ctr++; - } - - return strdup(buf); -} - -void csp_dag_print(CSOUND *csound, DAG *dag) -{ - char *str = csp_dag_string(csound, dag); - if (str != NULL) { - csound->Message(csound, "%s", str); - free(str); - } -#if 0 - if (dag == NULL) csound->Die(csound,Str( "Invalid NULL Parameter dag")); - - csound->Message(csound, "Dag2:\n"); - int ctr = 0; - while (ctr < dag->count) { - csound->Message(csound, " %s\n", dag->all[ctr]->instr->name); - ctr++; - } - - csound->Message(csound, "roots:\n"); - ctr = 0; - while (ctr < dag->count) { - if (dag->roots[ctr] != NULL) { - csound->Message(csound, " %s\n", dag->roots[ctr]->instr->name); - } - ctr++; - } - - csound->Message(csound, "remaining: %i\n", dag->remaining); - csound->Message(csound, "first_root: %i\n", dag->first_root); - /* csound->Message(csound, "consume_locked: %i\n", dag->consume_locked); */ - - csound->Message(csound, "table:\n"); - ctr = 0; - while (ctr < dag->count) { - int inner_ctr = 0; - while (inner_ctr < dag->count) { - csound->Message(csound, "%hhi ", dag->table[ctr][inner_ctr]); - inner_ctr++; - } - csound->Message(csound, "\n"); - ctr++; - } -#endif -} - -/********************************************************************************************** - * dag2 optimization structure - */ - -static uint64_t dag_opt_counter; - -/* attempt to optimize the dag - * this is basis of the combined design */ -void csp_dag_optimization(CSOUND *csound, DAG *dag) -{ - int starting_row = 0; - int threads = csound->oparms->numThreads; - int end_point = dag->count - threads; - int dag_table_original_size = dag->count; - -#ifdef CAUTIOUS - if (UNLIKELY(dag == NULL)) - csound->Die(csound,Str( "Invalid NULL Parameter dag")); -#endif - -#if TRACE > 1 - TRACE_0("========== Start ==========\n"); - csp_dag_print(csound, dag); -#endif - - /* loop through from start to the end of all the rows */ - while (starting_row < end_point) { - TRACE_2("Start Loop\n"); - /* DAG_NODE *readwrite_group[dag->count]; - memset(readwrite_group, 0, sizeof(DAG_NODE *) * dag->count); */ - int readwrite_group[dag->count]; - - /* try and find sqaures of target side length - * decrease target until we find one or its smaller than - * the number of threads - * - * the target square will have instruments performable at the same time - * we place the indexes of the instruments in readwrite_group */ - int found_block = 0; - int target = dag->count - starting_row; - while (target >= threads && found_block == 0) { - TRACE_2("Start Loop Target target: %i\n", target); - TRACE_2("end_point: %i\n", end_point); - TRACE_2("starting_row: %i\n", starting_row); - - int count_matching_cols = 0; - memset(readwrite_group, -1, sizeof(int) * dag->count); - - TRACE_2("readwrite_group done\n"); - - int row = starting_row, col = starting_row; - while (col < dag->count) { - row = starting_row; - while (row < dag->count && - (dag->table_ori[row][col] == DAG_WEAK_LINK || - dag->table_ori[row][col] == DAG_NO_LINK)) { - row++; - } - TRACE_2("row: %i\n", row - starting_row); - if (UNLIKELY((row - starting_row) >= target)) { - readwrite_group[count_matching_cols] = col; - count_matching_cols++; - } - col++; - } - TRACE_2("count_matching_cols: %i\n", count_matching_cols); - if (UNLIKELY(count_matching_cols >= target)) { - /* we have a target x target sized square somewhere inside */ - found_block = 1; - } - else { /* go around again looking for a smaller target */ - target--; - } - } - - TRACE_2("Found Target? %i (%i)\n", target > threads, target); - - /* we've found a target square */ - if (target > threads) { - dag_opt_counter++; - - /* replace starting_row..starting_row+target with a new row */ - int ctr = 0; - - /* copy the original dependency table */ - uint8_t table_copy[dag_table_original_size][dag_table_original_size]; - memcpy(table_copy, dag->table_ori[0], - sizeof(uint8_t) * dag_table_original_size * dag_table_original_size); - - TRACE_2("Table Copy\n"); -#if TRACE > 1 - ctr = 0; - while (ctr < dag->count) { - int col_ctr = 0; - while (col_ctr < dag->count) { - csound->Message(csound, "%i ", table_copy[ctr][col_ctr]); - col_ctr++; - } - csound->Message(csound, "\n"); - ctr++; - } -#endif - - /* stream data structure */ - int streams[threads][dag->count]; - memset(streams, -1, sizeof(int) * threads * dag->count); - int streams_ix[threads]; - memset(streams_ix, 0, sizeof(int) * threads); - int readwrite_group_copy[target]; - memcpy(readwrite_group_copy, readwrite_group, sizeof(int) * target); - - TRACE_2("Copied Everything\n"); -#if TRACE > 1 - ctr = 0; - while (ctr < target) { - csound->Message(csound, "%i: %i\n", ctr, readwrite_group_copy[ctr]); - ctr++; - } -#endif - - /* fill out the streams data structure which we use as - instructions to build the new nodes */ - ctr = 0; - while (ctr < target) { - int current_thread = 0; - while (ctr < target && current_thread < threads) { - int inner_ctr = 0, max_ix = 0; - uint32_t max_weight = 0; - while (inner_ctr < target) { - if (readwrite_group_copy[inner_ctr] >= 0 && - dag->all[readwrite_group_copy[inner_ctr]]->instr->weight - > max_weight) { - max_weight = - dag->all[readwrite_group_copy[inner_ctr]]->instr->weight; - max_ix = inner_ctr; - } - inner_ctr++; - } - streams[current_thread][streams_ix[current_thread]] = - readwrite_group_copy[max_ix]; - readwrite_group_copy[max_ix] = -1; - ctr++; - streams_ix[current_thread]++; - current_thread++; - } - } - - TRACE_2("Done Stream Instructions\n"); -#if TRACE > 1 - ctr = 0; - while (ctr < threads) { - csound->Message(csound, "Stream %i: [%i]\n ", ctr, streams_ix[ctr]); - int stream_ix = 0; - while (stream_ix < streams_ix[ctr]) { - csound->Message(csound, "%i ", streams[ctr][stream_ix]); - stream_ix++; - } - csound->Message(csound, "\n"); - ctr++; - } -#endif - - /* allocate the replacement list dag_nodes */ - ctr = 0; - DAG_NODE *new_nodes[threads]; - memset(new_nodes, 0, sizeof(DAG_NODE *) * threads); - while (ctr < threads) { - dag_node_2_alloc_list(csound, &(new_nodes[ctr]), streams_ix[ctr]); - ctr++; - } - - TRACE_2("Allocated all nodes\n"); - - /* copy nodes from dag into array inside dag_node */ - ctr = 0; - while (ctr < threads) { - int inner_ctr = 0; - while (inner_ctr < new_nodes[ctr]->count) { - new_nodes[ctr]->nodes[inner_ctr] = dag->all[streams[ctr][inner_ctr]]; - dag->all[streams[ctr][inner_ctr]] = NULL; - inner_ctr++; - } - ctr++; - } - - TRACE_2("Copied all old node references into new nodes\n"); - - int map_old_to_new_locations[dag->count]; - memset(map_old_to_new_locations, -1, sizeof(int) * dag->count); - - /* shuffle up all the nodes into the gaps left */ - ctr = 0; - int streams_remaining = 0; - while (ctr < dag->count) { - /* we only move things if necessary ie we're in a spot where a - node was removed for merging before */ - if (dag->all[ctr] == NULL) { - if (streams_remaining < threads) { /* slot new nodes in first */ - TRACE_2("Is merged node\n"); - dag->all[ctr] = new_nodes[streams_remaining]; - - int stream_ctr = 0; - while (stream_ctr < streams_ix[streams_remaining]) { - map_old_to_new_locations[streams[streams_remaining][stream_ctr]] = - ctr; - stream_ctr++; - } - - streams_remaining++; - } - else { /* slide down the rest of the nodes */ - int next = ctr + 1; - TRACE_2("No more merged nodes\n"); - while (next < dag->count && dag->all[next] == NULL) { - next++; - } - if (LIKELY(next < dag->count)) { - TRACE_2("Normal Node\n"); - dag->all[ctr] = dag->all[next]; - dag->all[next] = NULL; - - map_old_to_new_locations[next] = ctr; - } - else { - TRACE_2("Done copying normal nodes\n"); - /* we're done at this point no more nodes to copy */ - break; - } - } - } - else { - map_old_to_new_locations[ctr] = ctr; - } - ctr++; - } - - TRACE_2("Shuffled up all nodes\n"); - -#if TRACE > 1 - ctr = 0; - while (ctr < dag->count) { - csound->Message(csound, "%i -> %i\n", ctr, map_old_to_new_locations[ctr]); - ctr++; - } -#endif - - /* empty the table of dependencies */ - memset(dag->table_ori[0], 0, - sizeof(uint8_t) * dag_table_original_size * dag_table_original_size); - - /* copy across the new dependency info */ - int update_col = 0, update_row = 0; - while (update_col < dag->count) { - update_row = 0; - int working_col = map_old_to_new_locations[update_col]; - while (update_row < dag->count) { - int working_row = map_old_to_new_locations[update_row]; - - TRACE_2("(%i, %i) -> (%i, %i)\n", update_row, update_col, - working_row, working_col); - TRACE_2("%i -> %i\n", table_copy[update_row][update_col], - dag->table_ori[working_row][working_col]); - - switch (table_copy[update_row][update_col]) { - case DAG_STRONG_LINK: - dag->table_ori[working_row][working_col] = DAG_STRONG_LINK; - break; - case DAG_WEAK_LINK: - if (dag->table_ori[working_row][working_col] != DAG_STRONG_LINK) { - dag->table_ori[working_row][working_col] = DAG_WEAK_LINK; - } - break; - case DAG_NO_LINK: - if (dag->table_ori[working_row][working_col] != DAG_STRONG_LINK && - dag->table_ori[working_row][working_col] != DAG_WEAK_LINK) { - dag->table_ori[working_row][working_col] = DAG_NO_LINK; - } - break; - } - TRACE_2("-> %i\n", dag->table_ori[working_row][working_col]); - update_row++; - } - update_col++; - } - - TRACE_2("Completed dependencies merge\n"); - - /* update the dag->count */ - dag->count = dag->count - target + threads; - starting_row = starting_row + threads; - end_point = dag->count - threads; - } - else { - /* not enough parallelism after this instrument */ - starting_row++; - } - } - - /* reset ready to redo roots and similar things */ - memcpy(dag->table[0], dag->table_ori[0], - sizeof(uint8_t) * dag_table_original_size * dag_table_original_size); - memset(dag->roots_ori, 0, sizeof(DAG_NODE *) * dag_table_original_size); - dag->first_root_ori = -1; - - memset(dag->root_seen_ori, 0, sizeof(uint8_t) * dag_table_original_size); - memset(dag->root_seen, 0, sizeof(uint8_t) * dag_table_original_size); - memset(dag->remaining_count_ori, 0, sizeof(int) * dag_table_original_size); - dag->max_roots = 0; - - csp_dag_build_roots(csound, dag); - /* csp_dag_prepare_use_first(csound, dag); */ - csp_dag_prepare_use(csound, dag); - - csp_dag_calculate_max_roots(csound, dag); - csp_dag_prepare_use(csound, dag); - // csp_dag_print(csound, dag); - - -#if TRACE > 1 - TRACE_0("========== New ==========\n"); - csp_dag_print(csound, dag); -#endif -} - -/********************************************************************************************** - * dag2 cache structure - */ - -/* #ifdef LINEAR_CACHE */ - -/* struct dag_cache_entry_t { */ -/* DAG *dag; */ -/* uint32_t uses; */ -/* uint32_t age; */ -/* struct dag_cache_entry_t *next; */ -/* int16 instrs; */ -/* int16 chain[]; */ -/* }; */ - -/* static int cache_ctr; */ -/* static struct dag_cache_entry_t *cache; */ - -/* static uint32_t update_ctr; */ - -/* #define DAG_2_CACHE_SIZE 100 */ -/* #define DAG_2_DECAY_COMP 1 */ -/* #define DAG_2_MIN_USE_LIMIT 5000 */ -/* /\* aiming for 8 passes of the cache update before a new entry must exist solely on its usage *\/ */ -/* #define DAG_2_MIN_AGE_LIMIT 256 */ -/* #define DAG_2_AGE_START 131072 */ - -/* static int csp_dag_cache_entry_dealloc(CSOUND *csound, */ -/* struct dag_cache_entry_t **entry); */ -/* static int csp_dag_cache_entry_alloc(CSOUND *csound, */ -/* struct dag_cache_entry_t **entry, */ -/* INSDS *chain); */ -/* static int csp_dag_cache_compare(CSOUND *csound */ -/* , struct dag_cache_entry_t *entry, INSDS *chain); */ -/* static void csp_dag_cache_update(CSOUND *csound); */ - -/* void csp_dag_cache_print(CSOUND *csound) */ -/* { */ -/* csound->Message(csound, "Dag2 Cache Size: %i\n", cache_ctr); */ -/* uint32_t sum = 0, max = 0, min = UINT32_MAX, sum_age = 0; */ -/* struct dag_cache_entry_t *entry = cache, *prev = NULL; */ -/* while (entry != NULL) { */ -/* if (entry->uses > max) max = entry->uses; */ -/* else if (entry->uses < min) min = entry->uses; */ -/* sum = sum + entry->uses; */ -/* sum_age = sum_age + entry->age; */ -/* entry = entry->next; */ -/* } */ -/* csound->Message(csound, "Dag2 Avg Uses: %u\n", sum / cache_ctr); */ -/* csound->Message(csound, "Dag2 Min Uses: %u\n", min); */ -/* csound->Message(csound, "Dag2 Max Uses: %u\n", max); */ -/* csound->Message(csound, "Dag2 Avg Age: %u\n", sum_age / cache_ctr); */ -/* csound->Message(csound, "Dag2 Fetches: %u\n", update_ctr); */ -/* } */ - -/* static int csp_dag_cache_entry_alloc(CSOUND *csound, */ -/* struct dag_cache_entry_t **entry, INSDS *chain) */ -/* { */ -/* int ctr = 0; */ -/* INSDS *current_insds = chain; */ - -/* #ifdef CAUTIOUS */ -/* if (UNLIKELY(entry == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter entry")); */ -/* if (UNLIKELY(chain == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter chain")); */ -/* #endif */ - -/* while (current_insds != NULL) { */ -/* ctr++; */ -/* current_insds = current_insds->nxtact; */ -/* } */ - -/* *entry = csound->Malloc(csound, */ -/* sizeof(struct dag_cache_entry_t) + sizeof(int16) * ctr); */ -/* if (UNLIKELY(*entry == NULL)) { */ -/* csound->Die(csound, Str("Failed to allocate Dag2 cache")); */ -/* } */ -/* memset(*entry, 0, sizeof(struct dag_cache_entry_t) + sizeof(int16) * ctr); */ -/* (*entry)->uses = 1; */ -/* (*entry)->age = DAG_2_AGE_START; */ -/* (*entry)->instrs = ctr; */ - -/* ctr = 0; */ -/* current_insds = chain; */ -/* while (current_insds != NULL) { */ -/* (*entry)->chain[ctr] = current_insds->insno; */ -/* ctr++; */ -/* current_insds = current_insds->nxtact; */ -/* } */ - -/* DAG *dag = NULL; */ -/* csp_dag_build(csound, &dag, chain); */ -/* (*entry)->dag = dag; */ - -/* return CSOUND_SUCCESS; */ -/* } */ - -/* static int csp_dag_cache_entry_dealloc(CSOUND *csound, */ -/* struct dag_cache_entry_t **entry) */ -/* { */ -/* #ifdef CAUTIOUS */ -/* if (UNLIKELY(entry == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter entry")); */ -/* if (UNLIKELY(*entry == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter entry")); */ -/* #endif */ - -/* csp_dag_dealloc(csound, &((*entry)->dag)); */ - -/* csound->Free(csound, *entry); */ -/* *entry = NULL; */ - -/* return CSOUND_SUCCESS; */ -/* } */ - -/* static void csp_dag_cache_update(CSOUND *csound) */ -/* { */ -/* if (cache_ctr < DAG_2_CACHE_SIZE) { */ -/* return; */ -/* } */ -/* // csound->Message(csound, Str("Cache Update\n")); */ -/* struct dag_cache_entry_t *entry = cache, *prev = NULL; */ -/* while (entry != NULL) { */ -/* entry->uses = entry->uses >> DAG_2_DECAY_COMP; */ -/* entry->age = entry->age >> DAG_2_DECAY_COMP; */ -/* if (entry->uses < DAG_2_MIN_USE_LIMIT && */ -/* entry->age < DAG_2_MIN_AGE_LIMIT && */ -/* prev != NULL) { */ -/* prev->next = entry->next; */ -/* csp_dag_cache_entry_dealloc(csound, &entry); */ -/* entry = prev->next; */ -/* cache_ctr--; */ -/* } */ -/* else { */ -/* prev = entry; */ -/* entry = entry->next; */ -/* } */ -/* } */ -/* } */ - -/* static int csp_dag_cache_compare(CSOUND *csound, */ -/* struct dag_cache_entry_t *entry, INSDS *chain) */ -/* { */ -/* INSDS *current_insds = chain; */ -/* int32_t ctr = 0; */ - -/* #ifdef CAUTIOUS */ -/* if (entry == NULL) csound->Die(csound, Str("Invalid NULL Parameter entry")); */ -/* if (chain == NULL) csound->Die(csound, Str("Invalid NULL Parameter chain")); */ -/* #endif */ - -/* while (current_insds != NULL && ctr < entry->instrs) { */ -/* if (current_insds->insno != entry->chain[ctr]) { */ -/* return 0; */ -/* } */ -/* current_insds = current_insds->nxtact; */ -/* ctr++; */ -/* } */ -/* if (ctr >= entry->instrs && current_insds != NULL) { */ -/* return 0; */ -/* } */ -/* else if (ctr < entry->instrs && current_insds == NULL) { */ -/* return 0; */ -/* } */ -/* else { */ -/* return 1; */ -/* } */ -/* } */ - -/* void csp_dag_cache_fetch(CSOUND *csound, DAG **dag, INSDS *chain) */ -/* { */ -/* struct dag_cache_entry_t *curr; */ -/* #ifdef CAUTIOUS */ -/* if (UNLIKELY(dag == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter dag")); */ -/* if (UNLIKELY(chain == NULL)) */ -/* csound->Die(csound, Str("Invalid NULL Parameter chain")); */ -/* #endif */ - -/* update_ctr++; /\* What does this do? *\/ */ -/* if (update_ctr == 10000) { */ -/* csp_dag_cache_update(csound); */ -/* update_ctr = 0; */ -/* } */ - -/* curr = cache; */ -/* while (curr != NULL) { */ -/* if (UNLIKELY(csp_dag_cache_compare(csound, curr, chain))) { */ -/* TRACE_2("Cache Hit [%i]\n", cache_ctr); */ -/* *dag = curr->dag; */ - -/* curr->uses++; */ - -/* csp_dag_prepare_use_insds(csound, curr->dag, chain); */ -/* csp_dag_prepare_use(csound, curr->dag); */ -/* break; */ -/* } */ -/* curr = curr->next; */ -/* } */ -/* if (*dag == NULL) { */ -/* csp_dag_cache_entry_alloc(csound, &curr, chain); */ -/* cache_ctr++; */ -/* *dag = curr->dag; */ -/* curr->next = cache; */ -/* cache = curr; */ - -/* TRACE_2("Cache Miss [%i]\n", cache_ctr); */ -/* } */ -/* } */ - -/* #endif */ - - -#ifdef HASH_CACHE - -struct dag_cache_entry_t { - uint32_t hash_val; - struct dag_cache_entry_t *next; - DAG *dag; - uint32_t uses; - uint32_t age; - - int16 instrs; - int16 chain[]; -}; - -//#define DAG_2_CACHE_SIZE 128 -#define DAG_2_DECAY_COMP 1 -#define DAG_2_MIN_USE_LIMIT 5000 -/* aiming for 8 passes of the cache update before a new entry - must exist solely on its usage */ -#define DAG_2_MIN_AGE_LIMIT 256 -#define DAG_2_AGE_START 131072 - -static int cache_ctr; -//static struct dag_cache_entry_t *cache[DAG_2_CACHE_SIZE]; - -/* #ifdef HYBRID_HASH_CACHE */ -/* static struct dag_cache_entry_t *cache_last; */ -/* #endif */ - -static uint32_t update_ctr; - -static int csp_dag_cache_entry_alloc(CSOUND *csound, - struct dag_cache_entry_t **entry, - INSDS *chain, uint32_t hash_val); -static int csp_dag_cache_compare(CSOUND *csound, - struct dag_cache_entry_t *entry, INSDS *chain); -#if 0 -static int csp_dag_cache_entry_dealloc(CSOUND *csound, - struct dag_cache_entry_t **entry); -static void csp_dag_cache_update(CSOUND *csound); -#endif -static void csp_dag_cache_print_weights_dump(CSOUND *csound); - -void csp_dag_cache_print(CSOUND *csound) -{ - uint32_t sum = 0, max = 0, min = UINT32_MAX, sum_age = 0; - uint32_t weight_sum = 0, weight_max = 0, weight_min = UINT32_MAX; - uint32_t instr_num_sum = 0, instr_num_max = 0, instr_num_min = UINT32_MAX; - uint32_t root_avail_sum = 0, root_avail_max = 0; - uint32_t root_avail_min = UINT32_MAX; - uint32_t bin_ctr = 0, bins_empty = 0, bins_used = 0, bin_max = 0; - - csound->Message(csound, "Dag2 Cache Size: %i\n", cache_ctr); - while (bin_ctr < DAG_2_CACHE_SIZE) { - struct dag_cache_entry_t *entry = csound->cache[bin_ctr]; - - if (entry == NULL) bins_empty++; - else bins_used++; - - uint32_t entry_ctr = 0; - while (entry != NULL) { - entry_ctr++; - if (entry->uses > max) max = entry->uses; - else if (entry->uses < min) min = entry->uses; - sum = sum + entry->uses; - sum_age = sum_age + entry->age; - - weight_sum += entry->dag->weight; - if (entry->dag->weight > weight_max) weight_max = entry->dag->weight; - else if (entry->dag->weight < weight_min) weight_min = entry->dag->weight; - - instr_num_sum += entry->instrs; - if (entry->instrs > instr_num_max) instr_num_max = entry->instrs; - else if (entry->instrs < instr_num_min) instr_num_min = entry->instrs; - - root_avail_sum += entry->dag->max_roots; - if (entry->dag->max_roots > root_avail_max) - root_avail_max = entry->dag->max_roots; - else if (entry->dag->max_roots < root_avail_min) - root_avail_min = entry->dag->max_roots; - - entry = entry->next; - } - - if (entry_ctr > bin_max) bin_max = entry_ctr; - - bin_ctr++; - } - csound->Message(csound, "Dag2 Avg Uses: %u\n", sum / cache_ctr); - csound->Message(csound, "Dag2 Min Uses: %u\n", min); - csound->Message(csound, "Dag2 Max Uses: %u\n", max); - csound->Message(csound, "Dag2 Avg Age: %u\n", sum_age / cache_ctr); - csound->Message(csound, "Dag2 Fetches: %u\n", update_ctr); - - csound->Message(csound, "Dag2 Empty Bins: %u\n", bins_empty); - csound->Message(csound, "Dag2 Used Bins: %u\n", bins_used); - csound->Message(csound, "Dag2 Bins Max: %u\n", bin_max); - csound->Message(csound, "Dag2 Bins Avg: %u\n", cache_ctr / bins_used); - - csound->Message(csound, "Weights Avg: %u\n", weight_sum / cache_ctr); - csound->Message(csound, "Weights Min: %u\n", weight_min); - csound->Message(csound, "Weights Max: %u\n", weight_max); - csound->Message(csound, "Weights InstrNum Avg: %u\n", - instr_num_sum / cache_ctr); - csound->Message(csound, "Weights InstrNum Min: %u\n", instr_num_min); - csound->Message(csound, "Weights InstrNum Max: %u\n", instr_num_max); - csound->Message(csound, "Roots Available Avg: %u\n", - root_avail_sum / cache_ctr); - csound->Message(csound, "Roots Available Min: %u\n", root_avail_min); - csound->Message(csound, "Roots Available Max: %u\n", root_avail_max); - - csound->Message(csound, "Number Optimized: %llu\n", dag_opt_counter); - - - if (csound->weight_dump != NULL) { - csp_dag_cache_print_weights_dump(csound); - } -} - -static void csp_dag_cache_print_weights_dump(CSOUND *csound) -{ - char *path = csound->weight_dump; - FILE *f = fopen(path, "w+"); - uint32_t bin_ctr = 0; - -#ifdef CAUTIOUS - if (UNLIKELY(f == NULL)) { - csound->Die(csound, - Str("Parallel Dump File not found at: %s for writing"), path); - } -#endif - - while (bin_ctr < DAG_2_CACHE_SIZE) { - struct dag_cache_entry_t *entry = csound->cache[bin_ctr]; - char *dag_str; - - while (entry != NULL) { - DAG *dag = entry->dag; - int ctr = 0; - while (ctr < entry->instrs) { - fprintf(f, "%hi", entry->chain[ctr]); - if (ctr != entry->instrs - 1) { - fprintf(f, ", "); - } - ctr++; - } - fprintf(f, "\n"); - fprintf(f, "%u\n", dag->weight); - fprintf(f, "%u\n", dag->max_roots); - - dag_str = csp_dag_string(csound, dag); - if (dag_str != NULL) { - fprintf(f, "%s", dag_str); - free(dag_str); - } - fprintf(f, "\n"); - entry = entry->next; - } - - bin_ctr++; - } - - fclose(f); -} - -static int csp_dag_cache_entry_alloc(CSOUND *csound, - struct dag_cache_entry_t **entry, - INSDS *chain, uint32_t hash_val) -{ - int ctr = 0; - INSDS *current_insds = chain; - -#ifdef CAUTIOUS - if (UNLIKELY(entry == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter entry")); - if (UNLIKELY(chain == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter chain")); -#endif - - while (current_insds != NULL) { - ctr++; - current_insds = current_insds->nxtact; - } - - *entry = csound->Malloc(csound, - sizeof(struct dag_cache_entry_t) + - sizeof(int16) * ctr); - if (UNLIKELY(*entry == NULL)) { - csound->Die(csound, Str("Failed to allocate Dag2 cache entry")); - } - memset(*entry, 0, sizeof(struct dag_cache_entry_t) + sizeof(int16) * ctr); - (*entry)->uses = 1; - (*entry)->age = DAG_2_AGE_START; - (*entry)->instrs = ctr; - (*entry)->hash_val = hash_val; - - ctr = 0; - current_insds = chain; - while (current_insds != NULL) { - (*entry)->chain[ctr] = current_insds->insno; - ctr++; - current_insds = current_insds->nxtact; - } - - { - DAG *dag = NULL; - csp_dag_build(csound, &dag, chain); - (*entry)->dag = dag; - csp_dag_optimization(csound, dag); - } - return CSOUND_SUCCESS; -} - -#if 0 -static int csp_dag_cache_entry_dealloc(CSOUND *csound, - struct dag_cache_entry_t **entry) -{ -#ifdef CAUTIOUS - if (UNLIKELY(entry == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter entry")); - if (UNLIKELY(*entry == NULL)) - csound->Die(csound, Str("Invalid NULL Parameter entry")); -#endif - - csp_dag_dealloc(csound, &((*entry)->dag)); - - csound->Free(csound, *entry); - *entry = NULL; - - return CSOUND_SUCCESS; -} -#endif - -#if 0 -static void csp_dag_cache_update(CSOUND *csound) -{ - uint32_t bin_ctr = 0; - - if (cache_ctr < DAG_2_CACHE_SIZE) { - return; - } - csound->Message(csound, Str("Cache Update\n")); - - while (bin_ctr < DAG_2_CACHE_SIZE) { - struct dag_cache_entry_t *entry = csound->cache[bin_ctr], *prev = NULL; - - if (entry == NULL) { - bin_ctr++; - continue; - } - - while (entry != NULL) { - entry->uses = entry->uses >> DAG_2_DECAY_COMP; - entry->age = entry->age >> DAG_2_DECAY_COMP; - if (entry->uses < DAG_2_MIN_USE_LIMIT && - entry->age < DAG_2_MIN_AGE_LIMIT) { - if (prev == NULL) { - csound->cache[bin_ctr] = entry->next; - } - else { - prev->next = entry->next; - } - csp_dag_cache_entry_dealloc(csound, &entry); - if (prev == NULL) { - entry = csound->cache[bin_ctr]; - } - else { - entry = prev->next; - } - cache_ctr--; - } - else { - prev = entry; - entry = entry->next; - } - } - bin_ctr++; - } -} -#endif - -static int csp_dag_cache_compare(CSOUND *csound, - struct dag_cache_entry_t *entry, INSDS *chain) -{ -#ifdef CAUTIOUS - if (entry == NULL) csound->Die(csound, Str("Invalid NULL Parameter entry")); - if (chain == NULL) csound->Die(csound, Str("Invalid NULL Parameter chain")); -#endif - - INSDS *current_insds = chain; - int32_t ctr = 0; - while (current_insds != NULL && ctr < entry->instrs) { - if (current_insds->insno != entry->chain[ctr]) { - return 0; - } - current_insds = current_insds->nxtact; - ctr++; - } - if (ctr >= entry->instrs && current_insds != NULL) { - return 0; - } - else if (ctr < entry->instrs && current_insds == NULL) { - return 0; - } - else { - return 1; - } -} - -void csp_dag_cache_fetch(CSOUND *csound, DAG **dag, INSDS *chain) -{ -#ifdef CAUTIOUS - if (dag == NULL) csound->Die(csound, Str("Invalid NULL Parameter dag")); - if (chain == NULL) csound->Die(csound, Str("Invalid NULL Parameter chain")); -#endif - - update_ctr++; - // WHY does this code exist? -/* if (update_ctr == 10000) { */ -/* csound->Message(csound, "Reloading because of count\n"); */ -/* csp_dag_cache_update(csound); */ -/* update_ctr = 0; */ -/* #ifdef HYBRID_HASH_CACHE */ -/* cache_last = NULL; */ -/* #endif */ -/* } */ - -/* #ifdef HYBRID_HASH_CACHE */ -/* if (cache_last != NULL && */ -/* csp_dag_cache_compare(csound, cache_last, chain)) { */ -/* struct dag_cache_entry_t *curr = cache_last; */ -/* #if TRACE > 4 */ -/* csound->Message(csound, "Cache Hit (Last) [%i]\n", cache_ctr); */ -/* #endif */ -/* *dag = curr->dag; */ -/* TAKE_LOCK(&(curr->dag->consume_spinlock)); */ -/* curr->uses++; */ - -/* csp_dag_prepare_use_insds(csound, curr->dag, chain); */ -/* csp_dag_prepare_use(csound, curr->dag); */ -/* RELS_LOCK(&(curr->dag->consume_spinlock)); */ -/* return; */ -/* } */ -/* #endif */ - - uint32_t hash_val = hash_chain(chain, DAG_2_CACHE_SIZE); - struct dag_cache_entry_t *curr = csound->cache[hash_val]; - while (curr != NULL) { - if (csp_dag_cache_compare(csound, curr, chain)) { - TRACE_2("Cache Hit [%i]\n", cache_ctr); - - *dag = curr->dag; - - TAKE_LOCK(&(curr->dag->consume_spinlock)); - curr->uses++; - - csp_dag_prepare_use_insds(csound, curr->dag, chain); - csp_dag_prepare_use(csound, curr->dag); -/* #ifdef HYBRID_HASH_CACHE */ -/* cache_last = curr; */ -/* #endif */ - RELS_LOCK(&(curr->dag->consume_spinlock)); - break; - } - curr = curr->next; - } - if (*dag == NULL) { - TRACE_2("Cache Miss [%i]\n", cache_ctr); - csp_dag_cache_entry_alloc(csound, &curr, chain, hash_val); - cache_ctr++; - *dag = curr->dag; - - curr->next = csound->cache[hash_val]; - csound->cache[hash_val] = curr; -/* #ifdef HYBRID_HASH_CACHE */ -/* cache_last = curr; */ -/* #endif */ - } -} - -#endif - -static long x = 0; - -int waste_time(CSOUND* csound, WASTE *p) -{ - int k, n = (int)*p->icnt; - for (k=0; kweight = 1; - csp_set_alloc_string(csound, &(instr->read_write)); csp_set_alloc_string(csound, &(instr->write)); csp_set_alloc_string(csound, &(instr->read)); @@ -104,8 +102,6 @@ csound->Message(csound, " read_write: "); csp_set_print(csound, current->read_write); - csound->Message(csound, " weight: %u\n", current->weight); - current = current->next; } csound->Message(csound, "Semantic Analysis Ends\n"); @@ -121,8 +117,28 @@ } else if (UNLIKELY(write == NULL || read == NULL)) { csound->Die(csound, - "Invalid NULL parameter set to add to global read, " - "write lists\n"); + Str("Invalid NULL parameter set to add to global read, " + "write lists\n")); + } + else { + csp_orc_sa_global_write_add_list(csound, write); + csp_orc_sa_global_read_add_list(csound, read); + /* csp_set_dealloc(csound, &new); */ + } +} + +void csp_orc_sa_global_read_write_add_list1(CSOUND *csound, + struct set_t *write, + struct set_t *read) +{ + if (csound->instCurr == NULL) { + csound->DebugMsg(csound, + "Add global read, write lists without any instruments\n"); + } + else if (UNLIKELY(write == NULL || read == NULL)) { + csound->Die(csound, + Str("Invalid NULL parameter set to add to global read, " + "write lists\n")); } else { struct set_t *new = NULL; @@ -130,7 +146,8 @@ if (write->count == 1 && read->count == 1 && new->count == 1) { /* this is a read_write list thing */ struct set_t *new_read_write = NULL; - csp_set_union(csound, csound->instCurr->read_write, new, &new_read_write); + csp_set_union(csound, csound->instCurr->read_write, + new, &new_read_write); csp_set_dealloc(csound, &csound->instCurr->read_write); csound->instCurr->read_write = new_read_write; } @@ -147,11 +164,12 @@ { if (csound->instCurr == NULL) { csound->Message(csound, - "Add a global write_list without any instruments\n"); + Str("Add a global write_list without any instruments\n")); } else if (UNLIKELY(set == NULL)) { csound->Die(csound, - "Invalid NULL parameter set to add to a global write_list\n"); + Str("Invalid NULL parameter set to add to a " + "global write_list\n")); } else { struct set_t *new = NULL; @@ -167,11 +185,14 @@ void csp_orc_sa_global_read_add_list(CSOUND *csound, struct set_t *set) { if (csound->instCurr == NULL) { - csound->Message(csound, "add a global read_list without any instruments\n"); + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, + "add a global read_list without any instruments\n"); } else if (UNLIKELY(set == NULL)) { csound->Die(csound, - "Invalid NULL parameter set to add to a global read_list\n"); + Str("Invalid NULL parameter set to add to a " + "global read_list\n")); } else { struct set_t *new = NULL; @@ -192,54 +213,30 @@ struct set_t *ww = NULL; csp_set_alloc_string(csound, &ww); csp_set_alloc_string(csound, &rr); - switch (code&0xfff8) { - case ZR: - csp_set_add(csound, rr, "##zak"); - break; - case ZW: - csp_set_add(csound, ww, "##zak"); - break; - case ZB: - csp_set_add(csound, rr, "##zak"); - csp_set_add(csound, ww, "##zak"); - break; - case TR: - csp_set_add(csound, rr, "##tab"); - break; - case TW: - csp_set_add(csound, ww, "##tab"); - break; - case TB: - csp_set_add(csound, rr, "##tab"); - csp_set_add(csound, ww, "##tab"); - break; - case CR: - csp_set_add(csound, rr, "##chn"); - break; - case CW: - csp_set_add(csound, ww, "##chn"); - break; - case CB: - csp_set_add(csound, rr, "##chn"); - csp_set_add(csound, ww, "##chn"); - break; - } + if (code&ZR) csp_set_add(csound, rr, strdup("##zak")); + if (code&ZW) csp_set_add(csound, ww, strdup("##zak")); + if (code&TR) csp_set_add(csound, rr, strdup("##tab")); + if (code&TW) csp_set_add(csound, ww, strdup("##tab")); + if (code&CR) csp_set_add(csound, rr, strdup("##chn")); + if (code&CW) csp_set_add(csound, ww, strdup("##chn")); + if (code&WR) csp_set_add(csound, ww, strdup("##wri")); csp_orc_sa_global_read_write_add_list(csound, ww, rr); + if (code&_QQ) csound->Message(csound, Str("opcode deprecated")); } } void csp_orc_sa_interlocks(CSOUND *csound, ORCTOKEN *opcode) { char *name = opcode->lexeme; - int32 opnum = find_opcode(csound, name); - OENTRY *ep = csound->opcodlst + opnum; - csp_orc_sa_interlocksf(csound, ep->thread); + OENTRY *ep = find_opcode(csound, name); + csp_orc_sa_interlocksf(csound, ep->flags); } //static int inInstr = 0; void csp_orc_sa_instr_add(CSOUND *csound, char *name) { + name = strdup(name); csound->inInstr = 1; if (csound->instRoot == NULL) { csound->instRoot = instr_semantics_alloc(csound, name); @@ -267,31 +264,25 @@ { while (x) { if (x->type == INTEGER_TOKEN) { - csp_orc_sa_instr_add(csound, x->value->lexeme); + csp_orc_sa_instr_add(csound, strdup(x->value->lexeme)); return; } if (x->type == T_IDENT) { - csp_orc_sa_instr_add(csound, x->value->lexeme); + csp_orc_sa_instr_add(csound, strdup(x->value->lexeme)); return; } if (UNLIKELY(x->type != T_INSTLIST)) { csound->DebugMsg(csound,"type %d not T_INSTLIST\n", x->type); - csound->Die(csound, "Not a proper list of ints"); + csound->Die(csound, Str("Not a proper list of ints")); } - csp_orc_sa_instr_add(csound, x->left->value->lexeme); + csp_orc_sa_instr_add(csound, strdup(x->left->value->lexeme)); x = x->right; } } -void csp_orc_sa_instr_finalize(CSOUND *csound) -{ - csound->instCurr = NULL; - csound->inInstr = 0; -} - struct set_t *csp_orc_sa_globals_find(CSOUND *csound, TREE *node) { - struct set_t *left, *right; + struct set_t *left=NULL, *right; struct set_t *current_set = NULL; if (node == NULL) { @@ -307,18 +298,9 @@ csp_set_dealloc(csound, &left); csp_set_dealloc(csound, &right); - switch (node->type) { - case T_IDENT_GI: - case T_IDENT_GK: - case T_IDENT_GF: - case T_IDENT_GW: - case T_IDENT_GS: - case T_IDENT_GA: - csp_set_add(csound, current_set, node->value->lexeme); - break; - default: - /* no globals */ - break; + if ((node->type == T_IDENT || node->type == LABEL_TOKEN) && + node->value->lexeme[0] == 'g') { + csp_set_add(csound, current_set, strdup(node->value->lexeme)); } if (node->next != NULL) { @@ -356,12 +338,74 @@ } current_instr = current_instr->next; } - snprintf(buf, BUF_LENGTH, "%i", insno); - current_instr = csp_orc_sa_instr_get_by_name(csound, buf); if (current_instr != NULL) { current_instr->insno = insno; } return current_instr; } + +/* ANALYZE TREE */ + +void csp_orc_analyze_tree(CSOUND* csound, TREE* root) +{ + if (PARSER_DEBUG) csound->Message(csound, "Performing csp analysis\n"); + + TREE *current = root; + TREE *temp; + + while(current != NULL) { + switch(current->type) { + case INSTR_TOKEN: + if (PARSER_DEBUG) csound->Message(csound, "Instrument found\n"); + + temp = current->left; + + // FIXME - need to figure out why csp_orc_sa_instr_add is + // called by itself in csound_orc.y + csp_orc_sa_instr_add_tree(csound, temp); + + csp_orc_analyze_tree(csound, current->right); + + csp_orc_sa_instr_finalize(csound); + + break; + case UDO_TOKEN: + if (PARSER_DEBUG) csound->Message(csound, "UDO found\n"); + + csp_orc_analyze_tree(csound, current->right); + + break; + + case IF_TOKEN: + case UNTIL_TOKEN: + break; + case LABEL_TOKEN: + break; + default: + if (PARSER_DEBUG) + csound->Message(csound, + "Statement: %s\n", current->value->lexeme); + + if(current->left != NULL) { + csp_orc_sa_global_read_write_add_list(csound, + csp_orc_sa_globals_find(csound, current->left), + csp_orc_sa_globals_find(csound, current->right)); + + } else { + csp_orc_sa_global_read_add_list(csound, + csp_orc_sa_globals_find(csound, + current->right)); + } + + break; + } + + current = current->next; + + } + + if (PARSER_DEBUG) csound->Message(csound, "[End csp analysis]\n"); + +} diff -Nru csound-5.17.11~dfsg/Engine/csound_data_structures.c csound-6.02~dfsg/Engine/csound_data_structures.c --- csound-5.17.11~dfsg/Engine/csound_data_structures.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_data_structures.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,338 @@ +/* + csound_data_structures.c: + + Copyright (C) 2013 Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + */ +#include "csoundCore.h" +#include "csound_data_structures.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* FUNCTIONS FOR CONS_CELL */ + +PUBLIC CONS_CELL* cs_cons(CSOUND* csound, void* val, CONS_CELL* cons) { + CONS_CELL* cell = mmalloc(csound, sizeof(CONS_CELL)); + + cell->value = val; + cell->next = cons; + + return cell; +} + +PUBLIC CONS_CELL* cs_cons_append(CONS_CELL* cons1, CONS_CELL* cons2) { + if(cons1 == NULL) return cons2; + if(cons2 == NULL) return cons1; + + CONS_CELL* c = cons1; + + while (c->next != NULL) c = c->next; + + c->next = cons2; + + return cons1; +} + +PUBLIC int cs_cons_length(CONS_CELL* head) { + CONS_CELL* current = head; + int count = 0; + while (current != NULL) { + count++; + current = current->next; + } + return count; +} + +PUBLIC void cs_cons_free(CSOUND* csound, CONS_CELL* head) { + CONS_CELL *current, *next; + + if (head == NULL) return; + + current = head; + + while(current != NULL) { + next = current->next; + mfree(csound, current); + current = next; + } +} + + +PUBLIC void cs_cons_free_complete(CSOUND* csound, CONS_CELL* head) { + + CONS_CELL *current, *next; + + if (head == NULL) return; + + current = head; + + while(current != NULL) { + next = current->next; + mfree(csound, current->value); + mfree(csound, current); + current = next; + } +} + +/* FUNCTION FOR HASH SET */ + +PUBLIC CS_HASH_TABLE* cs_hash_table_create(CSOUND* csound) { + return (CS_HASH_TABLE*) mcalloc(csound, sizeof(CS_HASH_TABLE)); +} + +static unsigned int cs_name_hash(char *s) +{ + unsigned int h = 0; + while (*s != '\0') { + h = (h<<4) ^ *s++; + } + return (h%HASH_SIZE); +} + +PUBLIC void* cs_hash_table_get(CSOUND* csound, + CS_HASH_TABLE* hashTable, char* key) { + unsigned int index; + CS_HASH_TABLE_ITEM* item; + + if (key == NULL) { + return NULL; + } + + index = cs_name_hash(key); + item = hashTable->buckets[index]; + + while (item != NULL) { + if (strcmp(key, item->key) == 0) { + return item->value; + } + item = item->next; + } + + return NULL; +} + +PUBLIC char* cs_hash_table_get_key(CSOUND* csound, + CS_HASH_TABLE* hashTable, char* key) { + unsigned int index; + CS_HASH_TABLE_ITEM* item; + + if (key == NULL) { + return NULL; + } + + index = cs_name_hash(key); + item = hashTable->buckets[index]; + + while (item != NULL) { + if (strcmp(key, item->key) == 0) { + return item->key; + } + item = item->next; + } + + return NULL; +} + +char* cs_hash_table_put_no_key_copy(CSOUND* csound, + CS_HASH_TABLE* hashTable, + char* key, void* value) { + if (key == NULL) { + return NULL; + } + + unsigned int index = cs_name_hash(key); + + CS_HASH_TABLE_ITEM* item = hashTable->buckets[index]; + + if (item == NULL) { + CS_HASH_TABLE_ITEM* newItem = mmalloc(csound, sizeof(CS_HASH_TABLE_ITEM)); + newItem->key = key; + newItem->value = value; + newItem->next = NULL; + hashTable->buckets[index] = newItem; + return newItem->key; + } else { + while (item != NULL) { + if (strcmp(key, item->key) == 0) { + item->value = value; + return item->key; + } else if(item->next == NULL) { + CS_HASH_TABLE_ITEM* newItem = mmalloc(csound, + sizeof(CS_HASH_TABLE_ITEM)); + newItem->key = key; + newItem->value = value; + newItem->next = NULL; + item->next = newItem; + return newItem->key; + } + item = item->next; + } + } + return NULL; +} + +PUBLIC void cs_hash_table_put(CSOUND* csound, + CS_HASH_TABLE* hashTable, char* key, void* value) { + cs_hash_table_put_no_key_copy(csound, hashTable, + cs_strdup(csound, key), value); +} + +PUBLIC char* cs_hash_table_put_key(CSOUND* csound, + CS_HASH_TABLE* hashTable, char* key) { + return cs_hash_table_put_no_key_copy(csound, hashTable, + cs_strdup(csound, key), NULL); +} + +PUBLIC void cs_hash_table_remove(CSOUND* csound, + CS_HASH_TABLE* hashTable, char* key) { + CS_HASH_TABLE_ITEM *previous, *item; + unsigned int index; + + if (key == NULL) { + return; + } + + index = cs_name_hash(key); + + previous = NULL; + item = hashTable->buckets[index]; + + while (item != NULL) { + if (strcmp(key, item->key) == 0) { + if (previous == NULL) { + hashTable->buckets[index] = NULL; + mfree(csound, item); + return; + } else { + previous->next = item->next; + mfree(csound, item); + } + } + previous = item; + item = item->next; + } +} + +PUBLIC CONS_CELL* cs_hash_table_keys(CSOUND* csound, CS_HASH_TABLE* hashTable) { + CONS_CELL* head = NULL; + + int i = 0; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = hashTable->buckets[i]; + + while (item != NULL) { + head = cs_cons(csound, item->key, head); + item = item->next; + } + } + return head; +} + +PUBLIC CONS_CELL* cs_hash_table_values(CSOUND* csound, CS_HASH_TABLE* hashTable) { + CONS_CELL* head = NULL; + + int i = 0; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = hashTable->buckets[i]; + + while (item != NULL) { + head = cs_cons(csound, item->value, head); + item = item->next; + } + } + return head; +} + +PUBLIC void cs_hash_table_merge(CSOUND* csound, + CS_HASH_TABLE* target, CS_HASH_TABLE* source) { + // TODO - check if this is the best strategy for merging + int i = 0; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = source->buckets[i]; + + while (item != NULL) { + cs_hash_table_put_no_key_copy(csound, target, item->key, item->value); + item = item->next; + } + } + +} + +PUBLIC void cs_hash_table_free(CSOUND* csound, CS_HASH_TABLE* hashTable) { + int i; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = hashTable->buckets[i]; + + while(item != NULL) { + CS_HASH_TABLE_ITEM* next = item->next; + mfree(csound, item->key); + mfree(csound, item); + item = next; + } + } + mfree(csound, hashTable); +} + +PUBLIC void cs_hash_table_mfree_complete(CSOUND* csound, CS_HASH_TABLE* hashTable) { + + int i; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = hashTable->buckets[i]; + + while(item != NULL) { + CS_HASH_TABLE_ITEM* next = item->next; + mfree(csound, item->key); + mfree(csound, item->value); + mfree(csound, item); + item = next; + } + } + mfree(csound, hashTable); +} + +PUBLIC void cs_hash_table_free_complete(CSOUND* csound, CS_HASH_TABLE* hashTable) { + + int i; + + for (i = 0; i < HASH_SIZE; i++) { + CS_HASH_TABLE_ITEM* item = hashTable->buckets[i]; + + while(item != NULL) { + CS_HASH_TABLE_ITEM* next = item->next; + mfree(csound, item->key); + mfree(csound, item->value); + mfree(csound, item); + item = next; + } + } + mfree(csound, hashTable); +} + + + +#ifdef __cplusplus +extern "C" { +#endif diff -Nru csound-5.17.11~dfsg/Engine/csound_orc.l csound-6.02~dfsg/Engine/csound_orc.l --- csound-5.17.11~dfsg/Engine/csound_orc.l 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc.l 2014-01-07 16:53:47.000000000 +0000 @@ -31,9 +31,7 @@ #include "csoundCore.h" #define YYSTYPE TREE* #define YYLTYPE ORCTOKEN* -#include "tok.h" #define YY_DECL int yylex (YYLTYPE *lvalp, CSOUND *csound, yyscan_t yyscanner) -#include "csound_orcparse.h" #include "csound_orc.h" #include "corfile.h" YYSTYPE *yylval_param; @@ -79,7 +77,8 @@ STRCONSTe \"(\\.|[^\"])*$ LABEL ^[ \t]*[a-zA-Z0-9_][a-zA-Z0-9_]*: IDENT [a-zA-Z_][a-zA-Z0-9_]* -IDENTN [a-zA-Z0-9_]+ +IDENTB [a-zA-Z_][a-zA-Z0-9_]*\([ \t]*"\n"? +XIDENT 0|[aijkftKOVPopS\[\]]+ INTGR [0-9]+ NUMBER [0-9]+\.?[0-9]*(e[-+]?[0-9]+)?|\.[0-9]+(e[-+]?[0-9]+)?|0[xX][0-9a-fA-F]+ WHITE [ \t]+ @@ -93,53 +92,203 @@ %x line %x src %x xstr +%x udodef +%x udoarg %% "\r" { } /* EATUP THIS PART OF WINDOWS NEWLINE */ {CONT} { csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), yyscanner); - } + } "\n" { csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), yyscanner); return NEWLINE; } -"(" { return '('; } +"("{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '('; + } ")" { return ')'; } -"[" { return '['; } +"["{OPTWHITE}"\n"? { if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '['; + } "]" { return ']'; } -"+" { return '+'; } -"-" { return '-'; } -"*" { return '*'; } -"/" { return '/'; } -"%" { return '%'; } -"\^" { return '^'; } -"?" { return '?'; } +"+"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '+'; + } +"-"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '-'; + } +"*"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '*'; + } +"/"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '/'; + } +"%"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '%'; + } +"\^"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '^'; + } +"?"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '?'; + } ":" { return ':'; } -"," { return ','; } -"!" { return '!'; } -"!=" { return S_NEQ; } -"&&" { return S_AND; } -"||" { return S_OR; } -"<<" { return S_BITSHIFT_LEFT; } -">>" { return S_BITSHIFT_RIGHT; } -"<" { return S_LT; } -"<=" { return S_LE; } -"==" { return S_EQ; } -"=" { *lvalp = make_token(csound, yytext); - (*lvalp)->type = '='; - return '='; } -">" { return S_GT; } -">=" { return S_GE; } -"|" { return '|'; } -"&" { return '&'; } -"#" { return '#'; } -"¬" { return '~'; } -"~" { return '~'; } +","{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return ','; + } +"!"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '!'; } +"->" { return S_ELIPSIS; } +"!="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_NEQ; } +"&&"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_AND; } +"||"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_OR; } +"<<"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_BITSHIFT_LEFT; } +">>"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_BITSHIFT_RIGHT; } +"<"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_LT; } +"<="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_LE; } +"=="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_EQ; } +"+="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_ADDIN; } +"-="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_SUBIN; } +"*="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_MULIN; } +"/="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_DIVIN; } +"="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + *lvalp = make_token(csound, "="); + (*lvalp)->type = '='; + return '='; } +">"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_GT; } +">="{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return S_GE; } +"|"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '|'; } +"&"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '&'; } +"#"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '#'; } +"¬"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '~'; } +"~"{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return '~'; } "@@"{OPTWHITE}{INTGR} { *lvalp = do_at(csound, 1, yyg); return INTEGER_TOKEN; } "@"{OPTWHITE}{INTGR} { *lvalp = do_at(csound, 0, yyg); return INTEGER_TOKEN; } +"@i" { return T_MAPI; } +"@k" { return T_MAPK; } "if" { *lvalp = make_token(csound, yytext); (*lvalp)->type = IF_TOKEN; return IF_TOKEN; } +"if("{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + *lvalp = make_token(csound, yytext); + unput('('); + (*lvalp)->type = IF_TOKEN; + return IF_TOKEN; } "then" { *lvalp = make_token(csound, yytext); (*lvalp)->type = THEN_TOKEN; return THEN_TOKEN; } @@ -152,12 +301,23 @@ "elseif" { *lvalp = make_token(csound, yytext); (*lvalp)->type = ELSEIF_TOKEN; return ELSEIF_TOKEN; } +"elseif("{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + unput('('); + *lvalp = make_token(csound, yytext); + (*lvalp)->type = ELSEIF_TOKEN; + return ELSEIF_TOKEN; } "else" { *lvalp = make_token(csound, yytext); (*lvalp)->type = ELSE_TOKEN; return ELSE_TOKEN; } "endif" { *lvalp = make_token(csound, yytext); (*lvalp)->type = ENDIF_TOKEN; return ENDIF_TOKEN; } +"fi" { *lvalp = make_token(csound, yytext); + (*lvalp)->type = ENDIF_TOKEN; + return ENDIF_TOKEN; } "until" { *lvalp = make_token(csound, yytext); (*lvalp)->type = UNTIL_TOKEN; return UNTIL_TOKEN; } @@ -167,6 +327,9 @@ "od" { *lvalp = make_token(csound, yytext); (*lvalp)->type = OD_TOKEN; return OD_TOKEN; } +"enduntil" { *lvalp = make_token(csound, yytext); + (*lvalp)->type = OD_TOKEN; + return OD_TOKEN; } "goto" { *lvalp = make_token(csound, yytext); (*lvalp)->type = GOTO_TOKEN; @@ -200,7 +363,7 @@ "endin" { *lvalp = make_token(csound, yytext); (*lvalp)->type = ENDIN_TOKEN; return ENDIN_TOKEN; } -"opcode" { +"opcode" { BEGIN(udodef); return UDOSTART_DEFINITION; } "endop" { @@ -224,12 +387,13 @@ BEGIN(INITIAL); PARM->xstrbuff[PARM->xstrptr++] = '"'; PARM->xstrbuff[PARM->xstrptr] = '\0'; + /* printf("xstrbuff:>>%s<<\n", PARM->xstrbuff); */ *lvalp = make_string(csound, PARM->xstrbuff); free(PARM->xstrbuff); return STRING_TOKEN; } -"\n" { /* THe next two should be one case but I cannot get that to work */ +"\n" { /* The next two should be one case but I cannot get that to work */ if (PARM->xstrptr+2==PARM->xstrmax) { PARM->xstrbuff = (char *)realloc(PARM->xstrbuff, PARM->xstrmax+=80); @@ -251,6 +415,29 @@ PARM->xstrbuff[PARM->xstrptr] = '\0'; } +{WHITE} { } +{IDENT} { BEGIN(udoarg); + *lvalp = lookup_token(csound, yytext, yyscanner); + /* csound->Message(csound,"%s -> %d\n", + yytext, (*lvalp)->type); */ + return (*lvalp)->type; } +","{OPTWHITE}"\n"? { + if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return ','; + } +{XIDENT} { BEGIN(udoarg); + *lvalp = lookup_token(csound, yytext, yyscanner); + /* csound->Message(csound,"%s -> %d\n", + yytext, (*lvalp)->type); */ + return (*lvalp)->type; } +"\n" { BEGIN(INITIAL); + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + return NEWLINE; } + + {STRCONST} { *lvalp = make_string(csound, yytext); return (STRING_TOKEN); } {STRCONSTe} { *lvalp = make_string(csound, yytext); @@ -264,6 +451,12 @@ (*lvalp)->type = ZERODBFS_TOKEN; /* csound->Message(csound,"%d\n", (*lvalp)->type); */ return ZERODBFS_TOKEN; } +{IDENTB} { if (strchr(yytext, '\n')) + csound_orcset_lineno(1+csound_orcget_lineno(yyscanner), + yyscanner); + *strrchr(yytext, '(') = '\0'; + *lvalp = lookup_token(csound, yytext, yyscanner); + return (*lvalp)->type+1; } {IDENT} { *lvalp = lookup_token(csound, yytext, yyscanner); /* csound->Message(csound,"%s -> %d\n", yytext, (*lvalp)->type); */ @@ -423,52 +616,6 @@ return ans; } -#if 0 -/* Functions for working with grabbing input one line at a time */ -/* These two functions assume reading from a file */ - -int get_next_line(struct yyguts_t * yyg) -{ - char *p; - void *yyscanner = yyg; - - PARM->nBuffer = 0; - - p = fgets(yyextra->buffer, lMaxBuffer, yyin); - csound->DebugMsg(csound,"get_next_line: %s\n", yyextra->buffer); - if (UNLIKELY(p == NULL)) { - if (ferror(yyin)) - return -1; - return 1; - } - - csound_orcset_lineno(1+csound_orcget_lineno(yyg),yyg); - - PARM->lBuffer = strlen(yyextra->buffer); - - return 0; -} - -int get_next_char(char *b, int maxBuffer, struct yyguts_t* yyg) -{ - int frc; - void *yyscanner = yyg; - if (UNLIKELY( feof(yyin) )) - return 0; - csound->DebugMsg(csound,"get_next_char: %s\n", yyextra->buffer); - while ( PARM->nBuffer >= PARM->lBuffer ) { - frc = get_next_line(yyg); - if (UNLIKELY( frc != 0 )) - return 0; - } - - b[0] = yyextra->buffer[PARM->nBuffer]; - PARM->nBuffer += 1; - - return b[0]=='\0'?0:1; -} -#endif - char *csound_orcget_current_pointer(void *yyscanner) { struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; diff -Nru csound-5.17.11~dfsg/Engine/csound_orc.y csound-6.02~dfsg/Engine/csound_orc.y --- csound-5.17.11~dfsg/Engine/csound_orc.y 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc.y 2014-01-07 16:54:20.000000000 +0000 @@ -1,4 +1,4 @@ - /* +/* csound_orc.y: Copyright (C) 2006, 2007 @@ -34,8 +34,10 @@ %token S_LT %token S_LE %token S_EQ -%token S_TASSIGN -%token S_TABREF +%token S_ADDIN +%token S_SUBIN +%token S_MULIN +%token S_DIVIN %token S_GT %token S_GE %token S_BITSHIFT_LEFT @@ -45,7 +47,9 @@ %token IF_TOKEN %token T_OPCODE0 +%token T_OPCODE0B %token T_OPCODE +%token T_OPCODEB %token UDO_TOKEN %token UDOSTART_DEFINITION @@ -56,18 +60,10 @@ %token T_ERROR %token T_FUNCTION +%token T_FUNCTIONB %token INSTR_TOKEN %token ENDIN_TOKEN -%token T_STRSET -%token T_PSET -%token T_CTRLINIT -%token T_MASSIGN -%token T_TURNON -%token T_PREALLOC -%token T_ZAKINIT -%token T_FTGEN -%token T_INIT %token GOTO_TOKEN %token KGOTO_TOKEN %token IGOTO_TOKEN @@ -80,24 +76,8 @@ %token ZERODBFS_TOKEN %token STRING_TOKEN %token T_IDENT +%token T_IDENTB -%token T_IDENT_I -%token T_IDENT_GI -%token T_IDENT_K -%token T_IDENT_GK -%token T_IDENT_A -%token T_IDENT_GA -%token T_IDENT_W -%token T_IDENT_GW -%token T_IDENT_F -%token T_IDENT_GF -%token T_IDENT_S -%token T_IDENT_GS -%token T_IDENT_T -%token T_IDENT_GT -%token T_IDENT_P -%token T_IDENT_B -%token T_IDENT_b %token INTEGER_TOKEN %token NUMBER_TOKEN %token THEN_TOKEN @@ -111,6 +91,11 @@ %token OD_TOKEN %token T_INSTLIST +%token S_ELIPSIS +%token T_ARRAY +%token T_ARRAY_IDENT +%token T_MAPI +%token T_MAPK %start orcfile %left '?' @@ -148,31 +133,29 @@ #endif #include "csoundCore.h" #include +#include #include "namedins.h" #include "csound_orc.h" -#ifdef PARCS #include "cs_par_base.h" #include "cs_par_orc_semantics.h" -#endif #include "parse_param.h" - //int udoflag = -1; /* THIS NEEDS TO BE MADE NON-GLOBAL */ #define udoflag csound->parserUdoflag - //int namedInstrFlag = 0; /* THIS NEEDS TO BE MADE NON-GLOBAL */ #define namedInstrFlag csound->parserNamedInstrFlag -extern TREE* appendToTree(CSOUND * csound, TREE *first, TREE *newlast); -extern int csound_orclex(TREE**, CSOUND *, void *); -extern void print_tree(CSOUND *, char *msg, TREE *); -extern void csound_orcerror(PARSE_PARM *, void *, CSOUND *, TREE*, const char*); -extern void add_udo_definition(CSOUND*, char *, char *, char *); -extern ORCTOKEN *lookup_token(CSOUND*,char*,void*); + extern TREE* appendToTree(CSOUND * csound, TREE *first, TREE *newlast); + extern int csound_orclex(TREE**, CSOUND *, void *); + extern void print_tree(CSOUND *, char *msg, TREE *); + extern void csound_orcerror(PARSE_PARM *, void *, CSOUND *, TREE*, const char*); + extern void add_udo_definition(CSOUND*, char *, char *, char *); + extern ORCTOKEN *lookup_token(CSOUND*,char*,void*); #define LINE csound_orcget_lineno(scanner) #define LOCN csound_orcget_locn(scanner) -extern int csound_orcget_locn(void *); -extern int csound_orcget_lineno(void *); + extern int csound_orcget_locn(void *); + extern int csound_orcget_lineno(void *); + extern ORCTOKEN *make_string(CSOUND *, char *); %} %% @@ -208,9 +191,7 @@ INTEGER_TOKEN, (ORCTOKEN *)$1), $3); } | label ',' instlist { -#ifdef PARCS - csp_orc_sa_instr_add(csound, ((ORCTOKEN *)$1)->lexeme); -#endif + csp_orc_sa_instr_add(csound, strdup(((ORCTOKEN *)$1)->lexeme)); $$ = make_node(csound,LINE,LOCN, T_INSTLIST, make_leaf(csound, LINE,LOCN, T_IDENT, (ORCTOKEN *)$1), $3); } @@ -219,9 +200,7 @@ TREE *ans; ans = make_leaf(csound, LINE,LOCN, T_IDENT, (ORCTOKEN *)$2); ans->rate = (int) '+'; -#ifdef PARCS - csp_orc_sa_instr_add(csound, ((ORCTOKEN *)$2)->lexeme); -#endif + csp_orc_sa_instr_add(csound, strdup(((ORCTOKEN *)$2)->lexeme)); $$ = make_node(csound,LINE,LOCN, T_INSTLIST, ans, $4); } | '+' label { @@ -238,24 +217,18 @@ { namedInstrFlag = 1; } instlist NEWLINE { namedInstrFlag = 0; -#ifdef PARCS csp_orc_sa_instr_add_tree(csound, $3); -#endif } statementlist ENDIN_TOKEN NEWLINE { $$ = make_node(csound, LINE,LOCN, INSTR_TOKEN, $3, $6); -#ifdef PARCS csp_orc_sa_instr_finalize(csound); -#endif } | INSTR_TOKEN NEWLINE error { namedInstrFlag = 0; csound->Message(csound, Str("No number following instr\n")); -#ifdef PARCS csp_orc_sa_instr_finalize(csound); -#endif } ; @@ -321,9 +294,6 @@ TREE *ans = make_leaf(csound,LINE,LOCN, '=', (ORCTOKEN *)$2); ans->left = (TREE *)$1; ans->right = (TREE *)$3; - /* ans->value->lexeme = get_assignment_type(csound, - ans->left->value->lexeme, ans->right->value->lexeme); */ - $$ = ans; } | statement { $$ = $1; } @@ -335,68 +305,136 @@ TREE *ans = make_leaf(csound,LINE,LOCN, '=', (ORCTOKEN *)$2); ans->left = (TREE *)$1; ans->right = (TREE *)$3; - /* ans->value->lexeme = get_assignment_type(csound, - ans->left->value->lexeme, ans->right->value->lexeme); */ - $$ = ans; -#ifdef PARCS csp_orc_sa_global_read_write_add_list(csound, csp_orc_sa_globals_find(csound, ans->left), csp_orc_sa_globals_find(csound, ans->right)); -#endif } - | T_IDENT_T '=' T_IDENT_T NEWLINE - { - ORCTOKEN *op = lookup_token(csound, "#copytab", NULL); - TREE *ans = make_leaf(csound,LINE,LOCN, T_OPCODE, op); - ans->left = make_leaf(csound,LINE,LOCN, T_IDENT_T, (ORCTOKEN *)$1); - ans->right = make_leaf(csound,LINE,LOCN, T_IDENT_T, (ORCTOKEN *)$3); - $$ = ans; + | ident S_ADDIN expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', + make_token(csound, "=")); + ORCTOKEN *repeat = make_token(csound, $1->value->lexeme); + ans->left = (TREE *)$1; + ans->right = make_node(csound,LINE,LOCN, '+', + make_leaf(csound,LINE,LOCN, + $1->value->type, repeat), + (TREE *)$3); + //print_tree(csound, "+=", ans); + $$ = ans; + csp_orc_sa_global_read_write_add_list1(csound, + csp_orc_sa_globals_find(csound, ans->left), + csp_orc_sa_globals_find(csound, ans->right)); + } + | ident S_SUBIN expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', + make_token(csound, "=")); + ORCTOKEN *repeat = make_token(csound, $1->value->lexeme); + ans->left = (TREE *)$1; + ans->right = make_node(csound,LINE,LOCN, '-', + make_leaf(csound,LINE,LOCN, + $1->value->type, repeat), + (TREE *)$3); + //print_tree(csound, "-=", ans); + $$ = ans; + csp_orc_sa_global_read_write_add_list1(csound, + csp_orc_sa_globals_find(csound, ans->left), + csp_orc_sa_globals_find(csound, ans->right)); + } + | ident S_MULIN expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', + make_token(csound, "=")); + ORCTOKEN *repeat = make_token(csound, $1->value->lexeme); + ans->left = (TREE *)$1; + ans->right = make_node(csound,LINE,LOCN, '*', + make_leaf(csound,LINE,LOCN, + $1->value->type, repeat), + (TREE *)$3); + //print_tree(csound, "-=", ans); + $$ = ans; + csp_orc_sa_global_read_write_add_list(csound, + csp_orc_sa_globals_find(csound, ans->left), + csp_orc_sa_globals_find(csound, ans->right)); + } + | ident S_DIVIN expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', + make_token(csound, "=")); + ORCTOKEN *repeat = make_token(csound, $1->value->lexeme); + ans->left = (TREE *)$1; + ans->right = make_node(csound,LINE,LOCN, '/', + make_leaf(csound,LINE,LOCN, + $1->value->type, repeat), + (TREE *)$3); + //print_tree(csound, "-=", ans); + $$ = ans; + csp_orc_sa_global_read_write_add_list(csound, + csp_orc_sa_globals_find(csound, ans->left), + csp_orc_sa_globals_find(csound, ans->right)); + } + | arrayexpr '=' expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', (ORCTOKEN *)$2); + ans->left = (TREE *)$1; + ans->right = (TREE *)$3; + $$ = ans; + } - | T_IDENT_T '[' iexp ']' '=' expr NEWLINE - { - TREE *ans = make_leaf(csound,LINE,LOCN, '=', (ORCTOKEN *)$5); - ans->left = make_leaf(csound,LINE,LOCN, T_IDENT_T, (ORCTOKEN *)$1); - ans->right = appendToTree(csound, $3, $6); - /* ans->value->lexeme = get_assignment_type(csound, - ans->left->value->lexeme, ans->right->value->lexeme); */ - //print_tree(csound, "TABLE ASSIGN", ans); - $$ = ans; - /* #ifdef PARCS */ - /* csp_orc_sa_global_read_write_add_list(csound, */ - /* csp_orc_sa_globals_find(csound, ans->left) */ - /* csp_orc_sa_globals_find(csound, ans->right)); */ - /* #endif */ + | arrayident '=' expr NEWLINE + { + TREE *ans = make_leaf(csound,LINE,LOCN, '=', (ORCTOKEN *)$2); + ans->left = (TREE *)$1; + ans->right = (TREE *)$3; + $$ = ans; + } + | ans opcode exprlist NEWLINE { - $2->left = $1; $2->right = $3; - + $2->value->optype = NULL; $$ = $2; -#ifdef PARCS + csp_orc_sa_global_read_write_add_list(csound, csp_orc_sa_globals_find(csound, $2->left), csp_orc_sa_globals_find(csound, $2->right)); csp_orc_sa_interlocks(csound, $2->value); -#endif + query_deprecated_opcode(csound, $2->value); } - | opcode0 exprlist NEWLINE + + | opcode0 exprlist NEWLINE { ((TREE *)$1)->left = NULL; ((TREE *)$1)->right = (TREE *)$2; - + $1->value->optype = NULL; $$ = $1; -#ifdef PARCS csp_orc_sa_global_read_add_list(csound, csp_orc_sa_globals_find(csound, $1->right)); csp_orc_sa_interlocks(csound, $1->value); -#endif + query_deprecated_opcode(csound, $1->value); + } + | opcode0b exprlist ')' NEWLINE /* VL: added this to allow general func ops with no answers */ + { + ((TREE *)$1)->left = NULL; + ((TREE *)$1)->right = (TREE *)$2; + $1->value->optype = NULL; + $$ = $1; + + csp_orc_sa_global_read_add_list(csound, + csp_orc_sa_globals_find(csound, + $1->right)); + + csp_orc_sa_interlocks(csound, $1->value); + query_deprecated_opcode(csound, $1->value); + } | LABEL_TOKEN { + //printf("label %s\n", ((ORCTOKEN *)$1)->lexeme); $$ = make_leaf(csound,LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$1); } | goto label NEWLINE @@ -423,6 +461,8 @@ | NEWLINE { $$ = NULL; } ; ans : ident { $$ = $1; } + | arrayident { $$ = $1; } + | arrayexpr { $$ = $1; } | T_IDENT error { csound->Message(csound, "Unexpected untyped word %s when expecting a variable\n", @@ -436,6 +476,22 @@ ((ORCTOKEN*)$3)->lexeme); $$ = appendToTree(csound, $1, NULL); } + | ans ',' arrayident { $$ = appendToTree(csound, $1, $3); } + | ans ',' arrayexpr { $$ = appendToTree(csound, $1, $3); } + ; + +arrayexpr : arrayexpr '[' iexp ']' + { + appendToTree(csound, $1->right, $3); + $$ = $1; + } + | ident '[' iexp ']' + { + char* arrayName = $1->value->lexeme; + $$ = make_node(csound, LINE, LOCN, T_ARRAY, + make_leaf(csound, LINE, LOCN, T_IDENT, make_token(csound, arrayName)), $3); + + } ; ifthen : IF_TOKEN bexpr then NEWLINE statementlist ENDIF_TOKEN NEWLINE @@ -529,22 +585,7 @@ label : T_OPCODE { $$ = (TREE *)$1; } | T_OPCODE0 { $$ = (TREE *)$1; } | T_FUNCTION { $$ = (TREE *)$1; } - | T_IDENT_P { $$ = (TREE *)$1; } - | T_IDENT_I { $$ = (TREE *)$1; } - | T_IDENT_GI { $$ = (TREE *)$1; } - | T_IDENT_K { $$ = (TREE *)$1; } - | T_IDENT_GK { $$ = (TREE *)$1; } - | T_IDENT_A { $$ = (TREE *)$1; } - | T_IDENT_GA { $$ = (TREE *)$1; } - | T_IDENT_W { $$ = (TREE *)$1; } - | T_IDENT_GW { $$ = (TREE *)$1; } - | T_IDENT_F { $$ = (TREE *)$1; } - | T_IDENT_GF { $$ = (TREE *)$1; } - | T_IDENT_S { $$ = (TREE *)$1; } - | T_IDENT_GS { $$ = (TREE *)$1; } - | T_IDENT_T { $$ = (TREE *)$1; } - | T_IDENT_GT { $$ = (TREE *)$1; } - | T_IDENT { $$ = (TREE *)$1; } + | T_IDENT { $$ = (TREE *)$1; } | IF_TOKEN { $$ = (TREE *)$1; } | THEN_TOKEN { $$ = (TREE *)$1; } | ITHEN_TOKEN { $$ = (TREE *)$1; } @@ -563,6 +604,7 @@ { /* $$ = make_node(',', $1, $3); */ $$ = appendToTree(csound, $1, $3); + } | exprlist ',' label { @@ -571,15 +613,16 @@ make_leaf(csound, LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$3)); } - | exprlist ',' error - | expr { $$ = $1; } + | exprlist ',' error + | expr { $$ = $1; } | bexpr { $$ = $1; } - | T_IDENT { $$ = make_leaf(csound, LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$1); } + | T_IDENT { $$ = make_leaf(csound, LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$1); } | T_OPCODE { $$ = make_leaf(csound, LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$1); } | T_FUNCTION { $$ = make_leaf(csound, LINE,LOCN, LABEL_TOKEN, (ORCTOKEN *)$1); } | /* null */ { $$ = NULL; } ; + bexpr : '(' bexpr ')' { $$ = $2; } | expr S_LE expr { $$ = make_node(csound, LINE,LOCN, S_LE, $1, $3); } | expr S_LE error @@ -638,17 +681,12 @@ | iexp '^' error | iexp '%' iexp { $$ = make_node(csound, LINE,LOCN, '%', $1, $3); } | iexp '%' error - | ifac { $$ = $1; } + | ifac { $$ = $1; } ; ifac : ident { $$ = $1; } | constant { $$ = $1; } - | T_IDENT_T '[' iexp ']' - { - $$ = make_node(csound,LINE,LOCN, S_TABREF, - make_leaf(csound, LINE,LOCN, - T_IDENT_T, (ORCTOKEN*)$1), $3); - } + | arrayexpr { $$ = $1; } | iexp '|' iexp { $$ = make_node(csound, LINE,LOCN, '|', $1, $3); } | iexp '|' error | iexp '&' iexp { $$ = make_node(csound, LINE,LOCN, '&', $1, $3); } @@ -664,29 +702,51 @@ | '~' iexp %prec S_UMINUS { $$ = make_node(csound, LINE,LOCN, '~', NULL, $2);} | '~' error { $$ = NULL; } - | '(' expr ')' { $$ = $2; } - | '(' expr error { $$ = NULL; } + | '(' expr ')' { $$ = $2; } + | '(' expr error { $$ = NULL; } | '(' error { $$ = NULL; } - | function '(' exprlist ')' + | identb exprlist ')' { + $1->left = NULL; - $1->right = $3; - + $1->right = $2; + $1->type = T_FUNCTION; + + $$ = $1; + } + | opcode ':' identb exprlist ')' + { + $1->left = NULL; + $1->right = $4; + $1->type = T_FUNCTION; + $1->value->optype = $3->value->lexeme; + + $$ = $1; + } + | opcode ':' opcodeb exprlist ')' /* this is need because a & k are also opcodes */ + { + $1->left = NULL; + $1->right = $4; + $1->type = T_FUNCTION; + $1->value->optype = $3->value->lexeme; + $$ = $1; } - | function '(' error + | opcodeb exprlist ')' + { + $1->left = NULL; + $1->right = $2; + $1->type = T_FUNCTION; + $1->value->optype = NULL; + + $$ = $1; + //print_tree(csound, "FUNCTION CALL", $$); + } + + | identb error + | opcodeb error ; -function : T_FUNCTION { - csound->DebugMsg(csound,"FUNCTION ans=%p, token=%p %p\n", - $1, ((ORCTOKEN *)$1)->value); -#ifdef PARCS - // if ((ORCTOKEN *)$1->value != 0) - csp_orc_sa_interlocksf(csound, ((ORCTOKEN *)$1)->value); -#endif - $$ = make_leaf(csound, LINE,LOCN, T_FUNCTION, (ORCTOKEN *)$1); - } - rident : SRATE_TOKEN { $$ = make_leaf(csound, LINE,LOCN, SRATE_TOKEN, (ORCTOKEN *)$1); } | KRATE_TOKEN { $$ = make_leaf(csound, LINE,LOCN, @@ -701,25 +761,19 @@ ZERODBFS_TOKEN, (ORCTOKEN *)$1); } ; -ident : T_IDENT_I { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_I, (ORCTOKEN *)$1); } - | T_IDENT_K { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_K, (ORCTOKEN *)$1); } - | T_IDENT_F { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_F, (ORCTOKEN *)$1); } - | T_IDENT_W { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_W, (ORCTOKEN *)$1); } - | T_IDENT_S { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_S, (ORCTOKEN *)$1); } - | T_IDENT_T { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_T, (ORCTOKEN *)$1); } - | T_IDENT_A { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_A, (ORCTOKEN *)$1); } - | T_IDENT_P { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_P, (ORCTOKEN *)$1); } - | gident { $$ = $1; } - ; - -gident : T_IDENT_GI { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GI, (ORCTOKEN *)$1); } - | T_IDENT_GK { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GK, (ORCTOKEN *)$1); } - | T_IDENT_GF { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GF, (ORCTOKEN *)$1); } - | T_IDENT_GW { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GW, (ORCTOKEN *)$1); } - | T_IDENT_GS { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GS, (ORCTOKEN *)$1); } - | T_IDENT_GT { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GS, (ORCTOKEN *)$1); } - | T_IDENT_GA { $$ = make_leaf(csound, LINE,LOCN, T_IDENT_GA, (ORCTOKEN *)$1); } - ; + +arrayident: arrayident '[' ']' { + appendToTree(csound, $1->right, + make_leaf(csound, LINE, LOCN, '[', make_token(csound, "["))); + $$ = $1; + } + | ident '[' ']' { + $$ = make_leaf(csound, LINE, LOCN, T_ARRAY_IDENT, make_token(csound, $1->value->lexeme)); + $$->right = make_leaf(csound, LINE, LOCN, '[', make_token(csound, "[")); + }; + +ident : T_IDENT { $$ = make_leaf(csound, LINE,LOCN, T_IDENT, (ORCTOKEN *)$1); } +identb : T_IDENTB { $$ = make_leaf(csound, LINE,LOCN, T_IDENT, (ORCTOKEN *)$1); } constant : INTEGER_TOKEN { $$ = make_leaf(csound, LINE,LOCN, INTEGER_TOKEN, (ORCTOKEN *)$1); } @@ -743,14 +797,36 @@ opcode0 : T_OPCODE0 { - if (UNLIKELY(PARSER_DEBUG)) + if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "opcode0 $1=%p (%s)\n", $1,((ORCTOKEN *)$1)->lexeme ); $$ = make_leaf(csound,LINE,LOCN, T_OPCODE0, (ORCTOKEN *)$1); + + } ; -opcode : T_OPCODE { $$ = make_leaf(csound,LINE,LOCN, T_OPCODE, (ORCTOKEN *)$1); } +opcode0b : T_OPCODE0B + { + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "opcode0b $1=%p (%s)\n", + $1,((ORCTOKEN *)$1)->lexeme ); + $$ = make_leaf(csound,LINE,LOCN, T_OPCODE0, (ORCTOKEN *)$1); + + + } + ; + +opcode : T_OPCODE + { $$ = make_leaf(csound,LINE,LOCN, T_OPCODE, (ORCTOKEN *)$1); } + | T_FUNCTION + { $$ = make_leaf(csound,LINE,LOCN, T_OPCODE, (ORCTOKEN *)$1); } + ; + +opcodeb : T_OPCODEB + { $$ = make_leaf(csound,LINE,LOCN, T_OPCODE, (ORCTOKEN *)$1); } + | T_FUNCTIONB + { $$ = make_leaf(csound,LINE,LOCN, T_OPCODE, (ORCTOKEN *)$1); } ; %% diff -Nru csound-5.17.11~dfsg/Engine/csound_orc_compile.c csound-6.02~dfsg/Engine/csound_orc_compile.c --- csound-5.17.11~dfsg/Engine/csound_orc_compile.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc_compile.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,29 +1,30 @@ - /* - csound_orc_compile.c: - (Based on otran.c) - - Copyright (C) 1991, 1997, 2003, 2006 - Barry Vercoe, John ffitch, Istvan Varga, Steven Yi - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA +/* + csound_orc_compile.c: + (Based on otran.c) + + Copyright (C) 1991, 1997, 2003, 2006, 2012 + Barry Vercoe, John ffitch, Steven Yi, Victor Lazzarini + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ #include "csoundCore.h" +#include "parse_param.h" #include "csound_orc.h" #include #include @@ -32,63 +33,28 @@ #include "oload.h" #include "insert.h" #include "pstream.h" -#include "namedins.h" #include "typetabl.h" +#include "csound_standard_types.h" +#include "csound_orc_semantics.h" -typedef struct NAME_ { - char *namep; struct NAME_ *nxt; - int type, count; -} NAME; - -typedef struct { - NAME *gblNames[256], *lclNames[256]; /* for 8 bit hash */ - ARGLST *nullist; - ARGOFFS *nulloffs; - int lclkcnt, lclwcnt, lclfixed; - int lclpcnt, lclscnt, lclacnt, lclnxtpcnt; - int lclnxtkcnt, lclnxtwcnt, lclnxtacnt, lclnxtscnt; - int gblnxtkcnt, gblnxtpcnt, gblnxtacnt, gblnxtscnt; - int gblfixed, gblkcount, gblacount, gblscount; - int *nxtargoffp, *argofflim, lclpmax; - char **strpool; - int32 poolcount, strpool_cnt, argoffsize; - int nconsts; - int *constTbl; - int32 *typemask_tabl; - int32 *typemask_tabl_in, *typemask_tabl_out; - int lgprevdef; - char *filedir[101]; -} OTRAN_GLOBALS; - -static int gexist(CSOUND *, char *), gbloffndx(CSOUND *, char *); -static int lcloffndx(CSOUND *, char *); -static int constndx(CSOUND *, const char *); -static int strconstndx(CSOUND *, const char *); -static void insprep(CSOUND *, INSTRTXT *); -static void lgbuild(CSOUND *, char *, int inarg); -static void gblnamset(CSOUND *, char *); -static int plgndx(CSOUND *, char *); -static NAME *lclnamset(CSOUND *, char *); -/* int lgexist(CSOUND *, const char *);*/ -static void delete_global_namepool(CSOUND *); -static void delete_local_namepool(CSOUND *); -static int pnum(char *s) ; -static int lgexist2(CSOUND *csound, const char *s); - +static const char* INSTR_NAME_FIRST = "::^inm_first^::"; +static ARG* createArg(CSOUND *csound, INSTRTXT* ip, + char *s, ENGINE_STATE *engineState); +static void insprep(CSOUND *, INSTRTXT *, ENGINE_STATE *engineState); +static void lgbuild(CSOUND *, INSTRTXT *, char *, + int inarg, ENGINE_STATE *engineState); +int pnum(char *s) ; +static void unquote_string(char *, const char *); extern void print_tree(CSOUND *, char *, TREE *); +void close_instrument(CSOUND *csound, ENGINE_STATE *engineState, INSTRTXT * ip); +char argtyp2(char *s); +void debugPrintCsound(CSOUND* csound); + +void named_instr_assign_numbers(CSOUND *csound, ENGINE_STATE *engineState); +int named_instr_alloc(CSOUND *csound, char *s, INSTRTXT *ip, int32 insno, + ENGINE_STATE *engineState); +int check_instr_name(char *s); -void close_instrument(CSOUND *csound, INSTRTXT * ip); - -char argtyp2(CSOUND *csound, char *s); - -#define txtcpy(a,b) memcpy(a,b,sizeof(TEXT)); -#define ST(x) (((OTRAN_GLOBALS*) ((CSOUND*) csound)->otranGlobals)->x) - -#define KTYPE 1 -#define WTYPE 2 -#define ATYPE 3 -#define PTYPE 4 -#define STYPE 5 /* NOTE: these assume that sizeof(MYFLT) is either 4 or 8 */ #define Wfloats (((int) sizeof(SPECDAT) + 7) / (int) sizeof(MYFLT)) #define Pfloats (((int) sizeof(PVSDAT) + 7) / (int) sizeof(MYFLT)) @@ -101,79 +67,84 @@ #else #define FLOAT_COMPARE(x,y) (fabs((double) (x) / (double) (y) - 1.0) > 5.0e-7) #endif +/* ------------------------------------------------------------------------ */ -#define lblclear(x) -#if 0 -/** This function body copied from rdorch.c, not currently used */ -static void lblclear(CSOUND *csound) -{ - /* ST(lblcnt) = 0; */ +char* strsav_string(CSOUND* csound, ENGINE_STATE* engineState, char* key) { + char* retVal = cs_hash_table_get_key(csound, + csound->engineState.stringPool, key); + + if (retVal == NULL) { + retVal = cs_hash_table_put_key(csound, engineState->stringPool, key); + } + return retVal; } -#endif -static void intyperr(CSOUND *csound, int n, char *s, char *opname, - char tfound, char expect, int line) -{ - char t[10]; - switch (tfound) { - case 'w': - case 'f': - case 'a': - case 'k': - case 'i': - case 'P': - case 't': - case 'p': t[0] = tfound; - t[1] = '\0'; - break; - case 'r': - case 'c': strcpy(t,"const"); - break; - case 'S': strcpy(t,"string"); - break; - case 'b': - case 'B': strcpy(t,"boolean"); - break; - case '?': strcpy(t,"?"); - break; - } - synterr(csound, Str("input arg %d '%s' of type %s not allowed when " - "expecting %c (for opcode %s), line %d\n"), - n+1, s, t, expect, opname, line); -} - -#if 0 -static void lblrequest(CSOUND *csound, char *s) -{ - /* for (req=0; req= ST(lblmax)) { */ - /* LBLREQ *tmp; */ - /* ST(lblmax) += LBLMAX; */ - /* tmp = mrealloc(csound, ST(lblreq), ST(lblmax) * sizeof(LBLREQ)); */ - /* ST(lblreq) = tmp; */ - /* } */ - /* ST(lblreq)[req].reqline = ST(curline); */ - /* ST(lblreq)[req].label =s; */ +int pnum(char *s) /* check a char string for pnum format */ + /* and return the pnum ( >= 0 ) */ +{ /* else return -1 */ + int n; + + if (*s == 'p' || *s == 'P') + if (sscanf(++s, "%d", &n)) + return(n); + return(-1); } -#endif -static inline void resetouts(CSOUND *csound) +static int argCount(ARG* arg) { - csound->acount = csound->kcount = csound->icount = - csound->Bcount = csound->bcount = 0; + int retVal = -1; + if (arg != NULL) { + retVal = 0; + while (arg != NULL) { + arg = arg->next; + retVal++; + } + } + return retVal; } -/* Unused */ -#if 0 -TEXT *create_text(CSOUND *csound) +/* get size of string in MYFLT units */ +static inline int strlen_to_samples(const char *s) { - TEXT *tp = (TEXT *)mcalloc(csound, (int32)sizeof(TEXT)); - return tp; + int n = (int) strlen(s); + n = (n + (int) sizeof(MYFLT)) / (int) sizeof(MYFLT); + return n; +} + +/* convert string constant */ +static void unquote_string(char *dst, const char *src) +{ + int i, j, n = (int) strlen(src) - 1; + for (i = 1, j = 0; i < n; i++) { + if (src[i] != '\\') + dst[j++] = src[i]; + else { + switch (src[++i]) { + case 'a': dst[j++] = '\a'; break; + case 'b': dst[j++] = '\b'; break; + case 'f': dst[j++] = '\f'; break; + case 'n': dst[j++] = '\n'; break; + case 'r': dst[j++] = '\r'; break; + case 't': dst[j++] = '\t'; break; + case 'v': dst[j++] = '\v'; break; + case '"': dst[j++] = '"'; break; + case '\\': dst[j++] = '\\'; break; + default: + if (src[i] >= '0' && src[i] <= '7') { + int k = 0, l = (int) src[i] - '0'; + while (++k < 3 && src[i + 1] >= '0' && src[i + 1] <= '7') + l = (l << 3) | ((int) src[++i] - '0'); + dst[j++] = (char) l; + } + else { + dst[j++] = '\\'; i--; + } + } + } + } + dst[j] = '\0'; } -#endif int tree_arg_list_count(TREE * root) { @@ -208,223 +179,187 @@ last_optxt(op1)->nxtop = op2; } +/** Counts number of args in argString, taking into account array identifiers */ +int argsRequired(char* argString) +{ + int retVal = 0; + char* t = argString; -/** - * Current not used; intended to do the job of counting lcl counts - * but is flawed as it does not take into account counting variables - * only once if used multiple times; to be removed or reused in context - * of redoing namset functions (if even desirable) - */ + if (t != NULL) { + while (*t != '\0') { + retVal++; + t++; + while (*t == '[') { + t++; + if (*t != ']') { + // ERROR HERE, unmatched array identifier, perhaps should report... + return -1; + } + t++; + } + } + } + return retVal; +} -/* -void update_lclcount(CSOUND *csound, INSTRTXT *ip, TREE *argslist) +/** Splits args in argString into char**, taking into account array identifiers */ +char** splitArgs(CSOUND* csound, char* argString) { - TREE * current = argslist; + int argCount = argsRequired(argString); + char** args = mmalloc(csound, sizeof(char**) * (argCount + 1)); + char* t = argString; + int i = 0; - while (current != NULL) { - switch(current->type) { - case T_IDENT_S: - ip->lclscnt++; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "S COUNT INCREASED: %d\n", ip->lclscnt); - break; - case T_IDENT_W: - ip->lclwcnt++; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "W COUNT INCREASED: %d\n", ip->lclwcnt); - break; - case T_IDENT_A: - ip->lclacnt++; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "A COUNT INCREASED: %d\n", ip->lclacnt); - break; - case T_IDENT_K: - case T_IDENT_F: - case T_IDENT_I: - case NUMBER_TOKEN: - case INTEGER_TOKEN: - default: - ip->lclkcnt++; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "K COUNT INCREASED: %d\n", ip->lclkcnt); + if (t != NULL) { + while (*t != '\0' ) { + char* part; + int dimensions = 0; + + if (*(t + 1) == '[') { + char* start = t; + int len = 1; + int j; + t++; + + while (*t == '[') { + t++; + len++; + + if (*t != ']') { + // ERROR HERE, unmatched array identifier, perhaps should report... + return NULL; + } + + t++; + len++; + dimensions++; + } + part = mmalloc(csound, sizeof(char) * (dimensions + 3)); + part[dimensions + 2] = '\0'; + part[dimensions + 1] = ']'; + part[dimensions] = *start; + for (j = 0; j < dimensions; j++) { + part[j] = '['; + } + + } else { + part = mmalloc(csound, sizeof(char) * 2); + part[0] = *t; + part[1] = '\0'; + t++; + } + args[i] = part; + i++; } - current = current->next; } + + args[argCount] = NULL; + + return args; } -*/ -void set_xincod(CSOUND *csound, TEXT *tp, OENTRY *ep, int line) +void set_xincod(CSOUND *csound, TEXT *tp, OENTRY *ep) { int n = tp->inlist->count; char *s; - char *types = ep->intypes; - int nreqd = strlen(types); + int nreqd = argsRequired(ep->intypes); + char **types = splitArgs(csound, ep->intypes); + //int lgprevdef = 0; char tfound = '\0', treqd; - if (n > nreqd) { /* IV - Oct 24 2002: end of new code */ - if ((treqd = types[nreqd-1]) == 'n') { /* indef args: */ + if (n > nreqd) { + if ((treqd = *types[nreqd-1]) == 'n') { /* indef args: */ int incnt = -1; /* Should count args */ if (!(incnt & 01)) /* require odd */ synterr(csound, Str("missing or extra arg")); } /* IV - Sep 1 2002: added 'M' */ else if (treqd != 'm' && treqd != 'z' && treqd != 'y' && - treqd != 'Z' && treqd != 'M' && treqd != 'N') /* else any no */ + treqd != 'Z' && treqd != 'M' && treqd != 'N' && + treqd != '*' && treqd != 'I') /* else any no */ synterr(csound, Str("too many input args\n")); } while (n--) { /* inargs: */ - int32 tfound_m, treqd_m = 0L; s = tp->inlist->arg[n]; if (n >= nreqd) { /* det type required */ - csound->DebugMsg(csound, "%s(%d): type required: %c\n", - __FILE__, __LINE__, types[nreqd-1]); - switch (types[nreqd-1]) { + switch (*types[nreqd-1]) { case 'M': case 'N': case 'Z': case 'y': - case 'z': treqd = types[nreqd-1]; break; + case 'I': + case 'z': treqd = *types[nreqd-1]; break; default: treqd = 'i'; /* (indef in-type) */ } } - else treqd = types[n]; /* or given) */ - csound->DebugMsg(csound, "%s(%d): treqd: %c\n", __FILE__, __LINE__, treqd); + else treqd = *types[n]; /* or given) */ if (treqd == 'l') { /* if arg takes lbl */ csound->DebugMsg(csound, "treqd = l"); // lblrequest(csound, s); /* req a search */ continue; /* chk it later */ } - tfound = argtyp2(csound, s); /* else get arg type */ - /* IV - Oct 31 2002 */ - tfound_m = ST(typemask_tabl)[(unsigned char) tfound]; - csound->DebugMsg(csound, "%s(%d): treqd: %c, tfound %c\n", - __FILE__, __LINE__,treqd, tfound); - csound->DebugMsg(csound, "treqd %c, tfound_m %d ST(lgprevdef) %d\n", - treqd, tfound_m, ST(lgprevdef)); - if (!(tfound_m & (ARGTYP_c|ARGTYP_p)) && !ST(lgprevdef) && *s != '"') { - synterr(csound, - Str("input arg '%s' used before defined (in opcode %s)," - " line %d\n"), - s, ep->opname, line); - } + tfound = argtyp2(s); /* else get arg type */ if (tfound == 'a' && n < 31) /* JMC added for FOG */ /* 4 for FOF, 8 for FOG; expanded to 15 */ tp->xincod |= (1 << n); if (tfound == 'S' && n < 31) tp->xincod_str |= (1 << n); - /* IV - Oct 31 2002: simplified code */ - if (!(tfound_m & ST(typemask_tabl_in)[(unsigned char) treqd])) { - /* check for exceptional types */ - switch (treqd) { - case 'Z': /* indef kakaka ... */ - if (!(tfound_m & (n & 1 ? ARGTYP_a : ARGTYP_ipcrk))) - intyperr(csound, n, s, ep->opname, tfound, treqd, line); - break; - case 'x': - treqd_m = ARGTYP_ipcr; /* also allows i-rate */ - case 's': /* a- or k-rate */ - treqd_m |= ARGTYP_a | ARGTYP_k; - if (tfound_m & treqd_m) { - if (tfound == 'a' && tp->outlist->count != 0) { - long outyp_m = /* ??? */ - ST(typemask_tabl)[(unsigned char) argtyp2(csound, - tp->outlist->arg[0])]; - if (outyp_m & (ARGTYP_a | ARGTYP_w)) break; - } - else - break; - } - default: - intyperr(csound, n, s, ep->opname, tfound, treqd, line); - break; - } - } } - csound->DebugMsg(csound, "xincod = %d", tp->xincod); + mfree(csound, types); } -void set_xoutcod(CSOUND *csound, TEXT *tp, OENTRY *ep, int line) + +void set_xoutcod(CSOUND *csound, TEXT *tp, OENTRY *ep) { int n = tp->outlist->count; char *s; - char *types = ep->outypes; - int nreqd = -1; - char tfound = '\0', treqd; - - if (nreqd < 0) /* for other opcodes */ - nreqd = strlen(types = ep->outypes); -/* if ((n != nreqd) && */ /* IV - Oct 24 2002: end of new code */ -/* !(n > 0 && n < nreqd && - (types[n] == (char) 'm' || types[n] == (char) 'z' || - types[n] == (char) 'X' || types[n] == (char) 'N' || - types[n] == (char) 'F' || types[n] == (char) 'I'))) { - synterr(csound, Str("illegal no of output args")); - if (n > nreqd) - n = nreqd; - }*/ - + char **types = splitArgs(csound, ep->outypes); + char tfound = '\0'; while (n--) { /* outargs: */ - long tfound_m; /* IV - Oct 31 2002 */ s = tp->outlist->arg[n]; - treqd = types[n]; - tfound = argtyp2(csound, s); /* found */ - /* IV - Oct 31 2002 */ - tfound_m = ST(typemask_tabl)[(unsigned char) tfound]; - /* IV - Sep 1 2002: xoutcod is the same as xincod for input */ + tfound = argtyp2(s); /* found */ if (tfound == 'a' && n < 31) tp->xoutcod |= (1 << n); if (tfound == 'S' && n < 31) tp->xoutcod_str |= (1 << n); - csound->DebugMsg(csound, "treqd %c, tfound %c", treqd, tfound); - /* if (tfound_m & ARGTYP_w) */ - /* if (ST(lgprevdef)) { */ - /* synterr(csound, Str("output name previously used, " */ - /* "type '%c' must be uniquely defined, line %d"), */ - /* tfound, line); */ - /* } */ - /* IV - Oct 31 2002: simplified code */ - if (!(tfound_m & ST(typemask_tabl_out)[(unsigned char) treqd])) { - synterr(csound, Str("output arg '%s' illegal type (for opcode %s)," - " line %d\n"), - s, ep->opname, line); - } } + mfree(csound, types); } + +OENTRY* find_opcode(CSOUND*, char*); /** - * Create an Opcode (OPTXT) from the AST node given. Called from - * create_instrument. + * Create an Opcode (OPTXT) from the AST node given for a given engineState */ -OPTXT *create_opcode(CSOUND *csound, TREE *root, INSTRTXT *ip) +OPTXT *create_opcode(CSOUND *csound, TREE *root, INSTRTXT *ip, + ENGINE_STATE *engineState) { TEXT *tp; TREE *inargs, *outargs; OPTXT *optxt, *retOptxt = NULL; char *arg; - int opnum; - int n, nreqd;; - - /* printf("%d(%d): tree=%p\n", __FILE__, __LINE__, root); */ - /* print_tree(csound, "create_opcode", root); */ + int n;// nreqd; optxt = (OPTXT *) mcalloc(csound, (int32)sizeof(OPTXT)); tp = &(optxt->t); + OENTRY* labelOpcode; switch(root->type) { case LABEL_TOKEN: + labelOpcode = find_opcode(csound, "$label"); /* TODO - Need to verify here or elsewhere that this label is not already defined */ - tp->opnum = LABEL; - tp->opcod = strsav_string(csound, root->value->lexeme); + tp->oentry = labelOpcode; + tp->opcod = strsav_string(csound, engineState, root->value->lexeme); tp->outlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); tp->outlist->count = 0; tp->inlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); tp->inlist->count = 0; - ip->mdepends |= csound->opcodlst[LABEL].thread; - ip->opdstot += csound->opcodlst[LABEL].dsblksiz; + ip->mdepends |= labelOpcode->flags; + ip->opdstot += labelOpcode->dsblksiz; break; case GOTO_TOKEN: @@ -438,34 +373,22 @@ "create_opcode: Found node for opcode %s\n", root->value->lexeme); - nreqd = tree_arg_list_count(root->left); /* outcount */ + // FIXME THIS RESULT IS NOT USED -- VL I don't think it's needed + //nreqd = tree_arg_list_count(root->left); /* outcount */ /* replace opcode if needed */ - if (!strcmp(root->value->lexeme, "xin") && - nreqd > OPCODENUMOUTS_LOW) { - if (nreqd > OPCODENUMOUTS_HIGH) - opnum = find_opcode(csound, ".xin256"); - else - opnum = find_opcode(csound, ".xin64"); - } - else { - opnum = find_opcode(csound, root->value->lexeme); - } /* INITIAL SETUP */ - tp->opnum = opnum; - tp->opcod = strsav_string(csound, csound->opcodlst[opnum].opname); - ip->mdepends |= csound->opcodlst[opnum].thread; - ip->opdstot += csound->opcodlst[opnum].dsblksiz; + tp->oentry = (OENTRY*)root->markup; + tp->opcod = strsav_string(csound, engineState, tp->oentry->opname); + ip->mdepends |= tp->oentry->flags; + ip->opdstot += tp->oentry->dsblksiz; + /* BUILD ARG LISTS */ { int incount = tree_arg_list_count(root->right); int outcount = tree_arg_list_count(root->left); int argcount = 0; - - // csound->Message(csound, "Tree: In Count: %d\n", incount); - // csound->Message(csound, "Tree: Out Count: %d\n", outcount); - size_t m = sizeof(ARGLST) + (incount - 1) * sizeof(char*); tp->inlist = (ARGLST*) mrealloc(csound, tp->inlist, m); tp->inlist->count = incount; @@ -477,12 +400,8 @@ for (inargs = root->right; inargs != NULL; inargs = inargs->next) { /* INARGS */ - - // csound->Message(csound, "IN ARG TYPE: %d\n", inargs->type); - arg = inargs->value->lexeme; - - tp->inlist->arg[argcount++] = strsav_string(csound, arg); + tp->inlist->arg[argcount++] = strsav_string(csound, engineState, arg); if ((n = pnum(arg)) >= 0) { if (n > ip->pmax) ip->pmax = n; @@ -490,31 +409,21 @@ /* VL 14/12/11 : calling lgbuild here seems to be problematic for undef arg checks */ else { - lgbuild(csound, arg, 1); + lgbuild(csound, ip, arg, 1, engineState); } - - } - - /* update_lclcount(csound, ip, root->right); */ - } - /* update_lclcount(csound, ip, root->left); */ - - /* VERIFY ARG LISTS MATCH OPCODE EXPECTED TYPES */ - { - OENTRY *ep = csound->opcodlst + tp->opnum; - int argcount = 0; - // csound->Message(csound, "Opcode InTypes: %s\n", ep->intypes); - // csound->Message(csound, "Opcode OutTypes: %s\n", ep->outypes); + OENTRY *ep = tp->oentry; + int argcount = 0; for (outargs = root->left; outargs != NULL; outargs = outargs->next) { arg = outargs->value->lexeme; - tp->outlist->arg[argcount++] = strsav_string(csound, arg); + tp->outlist->arg[argcount++] = strsav_string(csound, engineState, arg); } - set_xincod(csound, tp, ep, root->line); + set_xincod(csound, tp, ep); + /* OUTARGS */ for (outargs = root->left; outargs != NULL; outargs = outargs->next) { @@ -524,21 +433,16 @@ if (n > ip->pmax) ip->pmax = n; } else { - if (arg[0] == 'w' && - lgexist2(csound, arg) != 0) { - synterr(csound, Str("output name previously used, " - "type 'w' must be uniquely defined, line %d"), - root->line); - } - lgbuild(csound, arg, 0); + csound->DebugMsg(csound, "Arg: %s\n", arg); + lgbuild(csound, ip, arg, 0, engineState); } } - set_xoutcod(csound, tp, ep, root->line); + set_xoutcod(csound, tp, ep); if (root->right != NULL) { if (ep->intypes[0] != 'l') { /* intype defined by 1st inarg */ - tp->intype = argtyp2(csound, tp->inlist->arg[0]); + tp->intype = argtyp2( tp->inlist->arg[0]); } else { tp->intype = 'l'; /* (unless label) */ @@ -546,15 +450,11 @@ } if (root->left != NULL) { /* pftype defined by outarg */ - tp->pftype = argtyp2(csound, root->left->value->lexeme); + tp->pftype = argtyp2( root->left->value->lexeme); } else { /* else by 1st inarg */ tp->pftype = tp->intype; } - -// csound->Message(csound, -// Str("create_opcode[%s]: opnum for opcode: %d\n"), -// root->value->lexeme, opnum); } break; default: @@ -574,112 +474,306 @@ return retOptxt; } +/** + * Add a global variable and allocate memory + * Globals, unlike locals, keep their memory space + * in separate blocks, pointed by var->memBlock + */ +void addGlobalVariable(CSOUND *csound, + ENGINE_STATE *engineState, + CS_TYPE* type, + char *name, + void *typeArg) +{ + CS_VARIABLE *var = csoundCreateVariable(csound, csound->typePool, + type, name, typeArg); + csoundAddVariable(engineState->varPool, var); + var->memBlock = (void *) mmalloc(csound, var->memBlockSize); + if (var->initializeVariableMemory != NULL) { + var->initializeVariableMemory(var, var->memBlock); + } +} /** + * NB - instr0 to be created only once, in the first compilation + * and stored in csound->instr0 * Create an Instrument (INSTRTXT) from the AST node given for use as * Instrument0. Called from csound_orc_compile. */ -INSTRTXT *create_instrument0(CSOUND *csound, TREE *root) +INSTRTXT *create_instrument0(CSOUND *csound, TREE *root, + ENGINE_STATE *engineState, + CS_VAR_POOL* varPool) { INSTRTXT *ip; OPTXT *op; - TREE *current; + MYFLT sr= FL(-1.0), kr= FL(-1.0), ksmps= FL(-1.0), + nchnls= DFLT_NCHNLS, inchnls = FL(0.0), _0dbfs= FL(-1.0); + CS_TYPE* rType = (CS_TYPE*)&CS_VAR_TYPE_R; + + addGlobalVariable(csound, engineState, rType, "sr", NULL); + addGlobalVariable(csound, engineState, rType, "kr", NULL); + addGlobalVariable(csound, engineState, rType, "ksmps", NULL); + addGlobalVariable(csound, engineState, rType, "nchnls", NULL); + addGlobalVariable(csound, engineState, rType, "nchnls_i", NULL); + addGlobalVariable(csound, engineState, rType, "0dbfs", NULL); + addGlobalVariable(csound, engineState, rType, "$sr", NULL); + addGlobalVariable(csound, engineState, rType, "$kr", NULL); + addGlobalVariable(csound, engineState, rType, "$ksmps", NULL); + + myflt_pool_find_or_add(csound, engineState->constantsPool, 0); ip = (INSTRTXT *) mcalloc(csound, sizeof(INSTRTXT)); + ip->varPool = varPool; op = (OPTXT *)ip; current = root; /* initialize */ - ip->lclkcnt = 0; - ip->lclwcnt = 0; - ip->lclacnt = 0; - ip->lclpcnt = 0; - ip->lclscnt = 0; - - delete_local_namepool(csound); - ST(lclnxtkcnt) = 0; /* for rebuilding */ - ST(lclnxtwcnt) = ST(lclnxtacnt) = 0; - ST(lclnxtpcnt) = ST(lclnxtscnt) = 0; ip->mdepends = 0; ip->opdstot = 0; + ip->pmax = 3L; /* start chain */ - ip->t.opnum = INSTR; - ip->t.opcod = strsav_string(csound, "instr"); /* to hold global assigns */ - - /* The following differs from otran and needs review. otran keeps a - * nulllist to point to for empty lists, while this is creating a new list - * regardless - */ + ip->t.oentry = find_opcode(csound, "instr"); + /* to hold global assigns */ + ip->t.opcod = strsav_string(csound, engineState, "instr"); + + /* The following differs from otran and needs review. otran keeps a + * nulllist to point to for empty lists, while this is creating a new list + * regardless + */ ip->t.outlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); ip->t.outlist->count = 0; ip->t.inlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); ip->t.inlist->count = 1; - ip->t.inlist->arg[0] = strsav_string(csound, "0"); + ip->t.inlist->arg[0] = strsav_string(csound, engineState, "0"); while (current != NULL) { - + unsigned int uval; if (current->type != INSTR_TOKEN && current->type != UDO_TOKEN) { - + OENTRY* oentry = (OENTRY*)current->markup; if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "In INSTR 0: %s\n", current->value->lexeme); if (current->type == '=' - && strcmp(current->value->lexeme, "=.r") == 0) { - - MYFLT val = csound->pool[constndx(csound, - current->right->value->lexeme)]; + && strcmp(oentry->opname, "=.r") == 0) { - - /* if (current->right->type == INTEGER_TOKEN) { - val = FL(current->right->value->value); - } else { - val = FL(current->right->value->fvalue); - }*/ + //FIXME - perhaps should add check as it was in + //constndx? Not sure if necessary due to assumption + //that tree will be verified + MYFLT val = (MYFLT) cs_strtod(current->right->value->lexeme, + NULL); + // systems constants get set here and are not + // compiled into i-time code + myflt_pool_find_or_add(csound, csound->engineState.constantsPool, val); /* modify otran defaults*/ + /* removed assignments to csound->tran_* */ if (current->left->type == SRATE_TOKEN) { - csound->tran_sr = val; + sr = val; } else if (current->left->type == KRATE_TOKEN) { - csound->tran_kr = val; + kr = val; } else if (current->left->type == KSMPS_TOKEN) { - csound->tran_ksmps = val; + uval = (val<=0 ? 1u : (unsigned int)val); + ksmps = uval; } else if (current->left->type == NCHNLS_TOKEN) { - csound->tran_nchnls = current->right->value->value; + uval = (val<=0 ? 1u : (unsigned int)val); + nchnls = uval; } else if (current->left->type == NCHNLSI_TOKEN) { - csound->tran_nchnlsi = current->right->value->value; - /* csound->Message(csound, "SETTING NCHNLS: %d\n", - csound->tran_nchnls); */ + uval = (val<=0 ? 1u : (unsigned int)val); + inchnls = uval; } else if (current->left->type == ZERODBFS_TOKEN) { - csound->tran_0dbfs = val; - /* csound->Message(csound, "SETTING 0DBFS: %f\n", - csound->tran_0dbfs); */ + _0dbfs = val; } } + else{ + op->nxtop = create_opcode(csound, current, ip, engineState); + op = last_optxt(op); + } - op->nxtop = create_opcode(csound, current, ip); + } + current = current->next; + } - op = last_optxt(op); + /* Deal with defaults and consistency */ + if (ksmps == FL(-1.0)) { + if (sr == FL(-1.0)) sr = DFLT_SR; + if (kr == FL(-1.0)) kr = DFLT_KR; + ksmps = (MYFLT) ((int) (sr/kr + FL(0.5))); + } + else if (kr == FL(-1.0)) { + if (sr == FL(-1.0)) sr = DFLT_SR; + kr = sr/ksmps; + } + else if (sr == FL(-1.0)) { + sr = kr*ksmps; + } + /* That deals with missing values, however we do need ksmps to be integer */ + { + CSOUND *p = (CSOUND*) csound; + char err_msg[128]; + CS_SPRINTF(err_msg, "sr = %.7g, kr = %.7g, ksmps = %.7g\nerror:", + sr, kr, ksmps); + if (UNLIKELY(sr <= FL(0.0))) + synterr(p, Str("%s invalid sample rate"), err_msg); + if (UNLIKELY(kr <= FL(0.0))) + synterr(p, Str("%s invalid control rate"), err_msg); + else if (UNLIKELY(ksmps < FL(0.75) || + FLOAT_COMPARE(ksmps, + MYFLT2LRND(ksmps)))) + synterr(p, Str("%s invalid ksmps value"), err_msg); + else if (UNLIKELY(FLOAT_COMPARE(sr,(double)kr *ksmps))) + synterr(p, Str("%s inconsistent sr, kr, ksmps"), err_msg); + else if (ksmps > sr) + synterr(p, Str("%s inconsistent sr, kr, ksmps \n"), err_msg); + } + + csound->ksmps = ksmps; + + csound->nchnls = nchnls; + if (inchnls==0) csound->inchnls = nchnls; + else csound->inchnls = inchnls; + csound->esr = sr; + csound->ekr = kr; + if (_0dbfs < 0) csound->e0dbfs = DFLT_DBFS; + else csound->e0dbfs = _0dbfs; + + OPARMS *O = csound->oparms; + if (UNLIKELY(csound->e0dbfs <= FL(0.0))){ + csound->Warning(csound, + Str("bad value for 0dbfs: must be positive. " + "Setting default value.")); + csound->e0dbfs = DFLT_DBFS; + } + + if (O->nchnls_override > 0) + csound->nchnls = csound->inchnls = O->nchnls_override; + if (O->nchnls_i_override > 0) csound->inchnls = O->nchnls_i_override; + if (O->e0dbfs_override > 0) csound->e0dbfs = O->e0dbfs_override; + + if (UNLIKELY(O->odebug)) + csound->Message(csound, "esr = %7.1f, ekr = %7.1f, ksmps = %d, nchnls = %d " + "0dbfs = %.1f\n", + csound->esr, csound->ekr, csound->ksmps, + csound->nchnls, csound->e0dbfs); + + if (O->sr_override) { /* if command-line overrides, apply now */ + MYFLT ensmps; + csound->esr = (MYFLT) O->sr_override; + csound->ekr = (MYFLT) O->kr_override; + csound->ksmps = (int) ((ensmps = ((MYFLT) O->sr_override + / (MYFLT) O->kr_override)) + FL(0.5)); + csound->Message(csound, Str("sample rate overrides: " + "esr = %7.4f, ekr = %7.4f, ksmps = %d\n"), + csound->esr, csound->ekr, csound->ksmps); + /* chk consistency one more time */ + { + char s[256]; + CS_SPRINTF(s, Str("sr = %.7g, kr = %.7g, ksmps = %.7g\nerror:"), + csound->esr, csound->ekr, ensmps); + if (UNLIKELY(csound->ksmps < 1 || FLOAT_COMPARE(ensmps, csound->ksmps))) + csoundDie(csound, Str("%s invalid ksmps value"), s); + if (UNLIKELY(csound->esr <= FL(0.0))) + csoundDie(csound, Str("%s invalid sample rate"), s); + if (UNLIKELY(csound->ekr <= FL(0.0))) + csoundDie(csound, Str("%s invalid control rate"), s); + if (UNLIKELY(FLOAT_COMPARE(csound->esr, (double) csound->ekr * ensmps))) + csoundDie(csound, Str("%s inconsistent sr, kr, ksmps"), s); + } + } + + csound->tpidsr = TWOPI_F / csound->esr; /* now set internal */ + csound->mtpdsr = -(csound->tpidsr); /* consts */ + csound->pidsr = PI_F / csound->esr; + csound->mpidsr = -(csound->pidsr); + csound->onedksmps = FL(1.0) / (MYFLT) csound->ksmps; + csound->sicvt = FMAXLEN / csound->esr; + csound->kicvt = FMAXLEN / csound->ekr; + csound->onedsr = FL(1.0) / csound->esr; + csound->onedkr = FL(1.0) / csound->ekr; + csound->global_kcounter = csound->kcounter; + + if (csound->ksmps != DFLT_KSMPS) { + reallocateVarPoolMemory(csound, engineState->varPool); + } + close_instrument(csound, engineState, ip); + + return ip; +} + +/** +This global instrument replaces instr 0 in +subsequent compilations. It does not allow the +setting of system parameters such as ksmps etc, +but it allows i-time code to be compiled and run. +**/ +INSTRTXT *create_global_instrument(CSOUND *csound, TREE *root, + ENGINE_STATE *engineState, + CS_VAR_POOL* varPool) +{ + INSTRTXT *ip; + OPTXT *op; + TREE *current; + + myflt_pool_find_or_add(csound, engineState->constantsPool, 0); + + ip = (INSTRTXT *) mcalloc(csound, sizeof(INSTRTXT)); + ip->varPool = varPool; + op = (OPTXT *)ip; + + current = root; + + /* initialize */ + ip->mdepends = 0; + ip->opdstot = 0; + ip->pmax = 3L; + + /* start chain */ + ip->t.oentry = find_opcode(csound, "instr"); + /* to hold global assigns */ + ip->t.opcod = strsav_string(csound, engineState, "instr"); + + /* The following differs from otran and needs review. otran keeps a + * nulllist to point to for empty lists, while this is creating a new list + * regardless + */ + ip->t.outlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); + ip->t.outlist->count = 0; + ip->t.inlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); + ip->t.inlist->count = 1; + ip->t.inlist->arg[0] = strsav_string(csound, engineState, "0"); + + while (current != NULL) { + if (current->type != INSTR_TOKEN && current->type != UDO_TOKEN) { + OENTRY* oentry = (OENTRY*)current->markup; + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "In INSTR GLOBAL: %s\n", current->value->lexeme); + if (current->type == '=' + && strcmp(oentry->opname, "=.r") == 0) + csound->Warning(csound, "system constants can only be set once\n"); + else { + op->nxtop = create_opcode(csound, current, ip, engineState); + op = last_optxt(op); } - current = current->next; + } + current = current->next; } - close_instrument(csound, ip); + close_instrument(csound, engineState, ip); return ip; } @@ -689,48 +783,47 @@ * Create an Instrument (INSTRTXT) from the AST node given. Called from * csound_orc_compile. */ -INSTRTXT *create_instrument(CSOUND *csound, TREE *root) +INSTRTXT *create_instrument(CSOUND *csound, TREE *root, + ENGINE_STATE *engineState) { INSTRTXT *ip; OPTXT *op; char *c; - TREE *statements, *current; ip = (INSTRTXT *) mcalloc(csound, sizeof(INSTRTXT)); + ip->varPool = (CS_VAR_POOL*)root->markup; op = (OPTXT *)ip; statements = root->right; - - ip->lclkcnt = 0; - ip->lclwcnt = 0; - ip->lclacnt = 0; - ip->lclpcnt = 0; - ip->lclscnt = 0; - - delete_local_namepool(csound); - ST(lclnxtkcnt) = 0; /* for rebuilding */ - ST(lclnxtwcnt) = ST(lclnxtacnt) = 0; - ST(lclnxtpcnt) = ST(lclnxtscnt) = 0; - - ip->mdepends = 0; ip->opdstot = 0; ip->pmax = 3L; /* Initialize */ - ip->t.opnum = INSTR; - ip->t.opcod = strsav_string(csound, "instr"); /* to hold global assigns */ - - /* The following differs from otran and needs review. otran keeps a - * nulllist to point to for empty lists, while this is creating a new list - * regardless - */ + ip->t.oentry = find_opcode(csound, "instr"); + /* to hold global assigns */ + ip->t.opcod = strsav_string(csound, engineState, "instr"); + + /* The following differs from otran and needs review. otran keeps a + * nulllist to point to for empty lists, while this is creating a new list + * regardless + */ ip->t.outlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); ip->t.outlist->count = 0; ip->t.inlist = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); ip->t.inlist->count = 1; + /* create local ksmps variable */ + CS_TYPE* rType = (CS_TYPE*)&CS_VAR_TYPE_R; + CS_VARIABLE *var = csoundCreateVariable(csound, csound->typePool, + rType, "ksmps", NULL); + csoundAddVariable(ip->varPool, var); + /* same for kr */ + var = csoundCreateVariable(csound, csound->typePool, + rType, "kr", NULL); + csoundAddVariable(ip->varPool, var); + /* Maybe should do this assignment at end when instr is setup? * Note: look into how "instr 4,5,6,8" is handled, i.e. if copies * are made or if they are all set to point to the same INSTRTXT @@ -742,13 +835,14 @@ int32 instrNum = (int32)root->left->value->value; /* Not used! */ c = csound->Malloc(csound, 10); /* arbritrarily chosen number of digits */ - sprintf(c, "%ld", instrNum); + sprintf(c, "%ld", (long)instrNum); if (PARSER_DEBUG) - csound->Message(csound, - Str("create_instrument: instr num %ld\n"), instrNum); + csound->Message(csound, + Str("create_instrument: instr num %ld\n"), instrNum); + + ip->t.inlist->arg[0] = strsav_string(csound, engineState, c); - ip->t.inlist->arg[0] = strsav_string(csound, c); csound->Free(csound, c); } else if (root->left->type == T_IDENT && @@ -758,49 +852,36 @@ c = root->left->value->lexeme; if (PARSER_DEBUG) - csound->Message(csound, Str("create_instrument: instr name %s\n"), c); + csound->Message(csound, "create_instrument: instr name %s\n", c); if (UNLIKELY(root->left->rate == (int) '+')) { insno_priority--; } - /* IV - Oct 31 2002: some error checking */ - if (UNLIKELY(!check_instr_name(c))) { - synterr(csound, Str("invalid name for instrument")); - } - /* IV - Oct 31 2002: store the name */ - if (UNLIKELY(!named_instr_alloc(csound, c, ip, insno_priority))) { - synterr(csound, Str("instr %s redefined"), c); - } - ip->insname = c; /* IV - Nov 10 2002: also in INSTRTXT */ + ip->insname = csound->Malloc(csound, strlen(c) + 1); + strcpy(ip->insname, c); } - - current = statements; - while (current != NULL) { - OPTXT * optxt = create_opcode(csound, current, ip); - - op->nxtop = optxt; - op = last_optxt(op); - - current = current->next; + OPTXT * optxt = create_opcode(csound, current, ip, engineState); + op->nxtop = optxt; + op = last_optxt(op); + current = current->next; } - - close_instrument(csound, ip); - + close_instrument(csound, engineState, ip); return ip; } -void close_instrument(CSOUND *csound, INSTRTXT * ip) +void close_instrument(CSOUND *csound, ENGINE_STATE* engineState, INSTRTXT * ip) { OPTXT * bp, *current; int n; bp = (OPTXT *) mcalloc(csound, (int32)sizeof(OPTXT)); - bp->t.opnum = ENDIN; /* send an endin to */ - bp->t.opcod = strsav_string(csound, "endin"); /* term instr 0 blk */ + bp->t.oentry = find_opcode(csound, "endin"); /* send an endin to */ + bp->t.opcod = + strsav_string(csound, engineState, "endin"); /* term instr 0 blk */ bp->t.outlist = bp->t.inlist = NULL; bp->nxtop = NULL; /* terminate the optxt chain */ @@ -808,279 +889,645 @@ current = (OPTXT *)ip; while (current->nxtop != NULL) { - current = current->nxtop; + current = current->nxtop; } current->nxtop = bp; - - - ip->lclkcnt = ST(lclnxtkcnt); - /* align to 8 bytes for "spectral" types */ - if ((int) sizeof(MYFLT) < 8 && - (ST(lclnxtwcnt) + ST(lclnxtpcnt)) > 0) - ip->lclkcnt = (ip->lclkcnt + 1) & (~1); - ip->lclwcnt = ST(lclnxtwcnt); - ip->lclacnt = ST(lclnxtacnt); - ip->lclpcnt = ST(lclnxtpcnt); - ip->lclscnt = ST(lclnxtscnt); - ip->lclfixed = ST(lclnxtkcnt) + ST(lclnxtwcnt) * Wfloats - + ST(lclnxtpcnt) * Pfloats; - - /* align to 8 bytes for "spectral" types */ -/* if ((int) sizeof(MYFLT) < 8 && (ip->lclwcnt + ip->lclpcnt) > 0) { - ip->lclkcnt = (ip->lclkcnt + 1) & (~1); - } - - ip->lclfixed = ip->lclkcnt + - ip->lclwcnt * Wfloats * ip->lclpcnt * Pfloats;*/ - - ip->mdepends = ip->mdepends >> 4; - ip->pextrab = ((n = ip->pmax - 3L) > 0 ? (int) n * sizeof(MYFLT) : 0); ip->pextrab = ((int) ip->pextrab + 7) & (~7); - ip->muted = 1; - /*ip->pmax = (int)pmax; - ip->pextrab = ((n = pmax-3L) > 0 ? (int) n * sizeof(MYFLT) : 0); - ip->pextrab = ((int) ip->pextrab + 7) & (~7); - ip->mdepends = threads >> 4; - ip->lclkcnt = ST(lclnxtkcnt); */ - /* align to 8 bytes for "spectral" types */ - - /*if ((int) sizeof(MYFLT) < 8 && - (ST(lclnxtwcnt) + ST(lclnxtpcnt)) > 0) - ip->lclkcnt = (ip->lclkcnt + 1) & (~1); - ip->lclwcnt = ST(lclnxtwcnt); - ip->lclacnt = ST(lclnxtacnt); - ip->lclpcnt = ST(lclnxtpcnt); - ip->lclscnt = ST(lclnxtscnt); - ip->lclfixed = ST(lclnxtkcnt) + ST(lclnxtwcnt) * Wfloats - + ST(lclnxtpcnt) * Pfloats;*/ - /*ip->opdstot = opdstot;*/ /* store total opds reqd */ - /*ip->muted = 1;*/ /* Allow to play */ - } - +void deleteVarPoolMemory(void* csound, CS_VAR_POOL* pool); /** - * Append an instrument to the end of Csound's linked list of instruments + This function deletes an inactive instrument which has been replaced */ -void append_instrument(CSOUND * csound, INSTRTXT * instrtxt) +void free_instrtxt(CSOUND *csound, INSTRTXT *instrtxt) { - INSTRTXT *current = &(csound->instxtanchor); - while (current->nxtinstxt != NULL) { - current = current->nxtinstxt; - } - - current->nxtinstxt = instrtxt; + INSTRTXT *ip = instrtxt; + INSDS *active = ip->instance; + while (active != NULL) { /* remove instance memory */ + INSDS *nxt = active->nxtinstance; + if (active->fdchp != NULL) + fdchclose(csound, active); + if (active->auxchp != NULL) + auxchfree(csound, active); + mfree(csound, active); + active = nxt; + } + OPTXT *t = ip->nxtop; + while (t) { + OPTXT *s = t->nxtop; + mfree(csound, t); + t = s; + } + // myflt_pool_free(csound, ip->varPool); + /* VL: 19-12-13 + an instrument varpool memory is allocated in the instrument block + so deallocating the pool is not really right */ + // deleteVarPoolMemory(csound, ip->varPool); + //mfree(csound, ip->varPool); /* need to delete the varPool memory */ + mfree(csound, ip); + if (csound->oparms->odebug) + csound->Message(csound, Str("-- deleted instr from deadpool \n")); } -static int pnum(char *s) /* check a char string for pnum format */ - /* and return the pnum ( >= 0 ) */ -{ /* else return -1 */ - int n; - if (*s == 'p' || *s == 'P') - if (sscanf(++s, "%d", &n)) - return(n); - return(-1); -} -/** Insert INSTRTXT into Csound's list of INSTRTXT's, checking to see if number - * is greater than number of pointers currently allocated and if so expand - * pool of instruments +/** + * This function has two purposes: + * 1) check deadpool for active instances, and + * if none is active, send it to be deleted + * 2) add a dead instr to deadpool (because it still has active instances) */ -void insert_instrtxt(CSOUND *csound, INSTRTXT *instrtxt, int32 instrNum) { +void add_to_deadpool(CSOUND *csound, INSTRTXT *instrtxt) +{ + /* check current items in deadpool to see if they need deleting */ int i; - - if (UNLIKELY(instrNum > csound->maxinsno)) { - int old_maxinsno = csound->maxinsno; - - /* expand */ - while (instrNum > csound->maxinsno) { - csound->maxinsno += MAXINSNO; + for(i=0; i < csound->dead_instr_no; i++){ + if (csound->dead_instr_pool[i] != NULL) { + INSDS *active = csound->dead_instr_pool[i]->instance; + while (active != NULL) { + if (active->actflg) { + // add_to_deadpool(csound,csound->dead_instr_pool[i]); + break; + } + active = active->nxtinstance; } - - csound->instrtxtp = (INSTRTXT**)mrealloc(csound, - csound->instrtxtp, (1 + csound->maxinsno) * sizeof(INSTRTXT*)); - - /* Array expected to be nulled so.... */ - for (i = old_maxinsno + 1; i <= csound->maxinsno; i++) { - csound->instrtxtp[i] = NULL; + /* no active instances */ + if (active == NULL) { + if (csound->oparms->odebug) + csound->Message(csound, Str(" -- free instr def %p \n"), + csound->dead_instr_pool[i]); + free_instrtxt(csound, csound->dead_instr_pool[i]); + csound->dead_instr_pool[i] = NULL; } + } } - - if (UNLIKELY(csound->instrtxtp[instrNum] != NULL)) { - synterr(csound, Str("instr %ld redefined"), instrNum); - /* err++; continue; */ - } - - csound->instrtxtp[instrNum] = instrtxt; + /* add latest instr to deadpool */ + /* check for free slots */ + for (i=0; i < csound->dead_instr_no; i++) { + if (csound->dead_instr_pool[i] == NULL) { + csound->dead_instr_pool[i] = instrtxt; + if (csound->oparms->odebug) + csound->Message(csound, Str(" -- added to deadpool slot %d \n"), + i); + return; + } + } + /* no free slots, expand pool */ + csound->dead_instr_pool = (INSTRTXT**) + mrealloc(csound, csound->dead_instr_pool, + ++csound->dead_instr_no * sizeof(INSTRTXT*)); + csound->dead_instr_pool[csound->dead_instr_no-1] = instrtxt; + if (csound->oparms->odebug) + csound->Message(csound, Str(" -- added to deadpool slot %d \n"), + csound->dead_instr_no-1); } -OPCODINFO *find_opcode_info(CSOUND *csound, char *opname) +/** + allocate entry for named instrument ip with name s + instrument number is set to insno + If named instr exists, it is replaced. +*/ +int named_instr_alloc(CSOUND *csound, char *s, INSTRTXT *ip, + int32 insno, ENGINE_STATE *engineState) { - OPCODINFO *opinfo = csound->opcodeInfo; - if (UNLIKELY(opinfo == NULL)) { + INSTRNAME *inm, *inm2, *inm_head; + + if (UNLIKELY(!engineState->instrumentNames)) + engineState->instrumentNames = cs_hash_table_create(csound); + + /* now check if instrument is already defined */ + inm = cs_hash_table_get(csound, engineState->instrumentNames, s); + if (inm != NULL) { + int i; + inm->ip->isNew = 1; + /* redefinition does not raise an error now, just a warning */ + if (csound->oparms->odebug) + csound->Warning(csound, + Str("instr %ld redefined, replacing previous definition"), + inm->instno); + /* here we should move the old instrument definition into a deadpool + which will be checked for active instances and freed when there are no + further ones + */ + for (i=0; i < engineState->maxinsno; i++) { + /* check for duplicate numbers and do nothing */ + if (i != inm->instno && + engineState->instrtxtp[i] == engineState->instrtxtp[inm->instno]) + goto cont; + } + INSDS *active = engineState->instrtxtp[inm->instno]->instance; + while (active != NULL) { + if (active->actflg) { + add_to_deadpool(csound, engineState->instrtxtp[inm->instno]); + break; + } + active = active->nxtinstance; + } + /* no active instances */ + if (active == NULL) { + if (csound->oparms->odebug) + csound->Message(csound, "no active instances \n"); + free_instrtxt(csound, engineState->instrtxtp[inm->instno]); + engineState->instrtxtp[inm->instno] = NULL; + } + inm->ip->instance = inm->ip->act_instance = inm->ip->lst_instance = NULL; + } + cont: + + /* allocate entry, */ + inm = (INSTRNAME*) mcalloc(csound, sizeof(INSTRNAME)); + inm2 = (INSTRNAME*) mcalloc(csound, sizeof(INSTRNAME)); + /* and store parameters */ + inm->name = strdup(s); inm->ip = ip; + inm2->instno = insno; + inm2->name = (char*) inm; /* hack */ + /* link into chain */ + cs_hash_table_put(csound, engineState->instrumentNames, s, inm); + + inm_head = cs_hash_table_get(csound, engineState->instrumentNames, + (char*)INSTR_NAME_FIRST); + /* temporary chain for use by named_instr_assign_numbers() */ + if (inm_head == NULL) { + cs_hash_table_put(csound, engineState->instrumentNames, + (char*)INSTR_NAME_FIRST, inm2); + } else { + while(inm_head->next != NULL) { + inm_head = inm_head->next; + } + inm_head->next = inm2; + } + + if (UNLIKELY(csound->oparms->odebug) && engineState == &csound->engineState) + csound->Message(csound, + "named instr name = \"%s\", txtp = %p,\n", + s, (void*) ip); + return 1; +} + +/** + assign instrument numbers to all named instruments +*/ +void named_instr_assign_numbers(CSOUND *csound, ENGINE_STATE *engineState) +{ + INSTRNAME *inm, *inm2, *inm_first; + int num = 0, insno_priority = 0; + + if (!engineState->instrumentNames) return; /* no named instruments */ + inm_first = cs_hash_table_get(csound, engineState->instrumentNames, + (char*)INSTR_NAME_FIRST); + + while (--insno_priority > -3) { + if (insno_priority == -2) { + num = engineState->maxinsno; /* find last used instr number */ + while (!engineState->instrtxtp[num] && --num); + } + for (inm = inm_first; inm; inm = inm->next) { + if ((int) inm->instno != insno_priority) continue; + /* the following is based on code by Matt J. Ingalls */ + /* find an unused number and use it */ + while (++num <= engineState->maxinsno && engineState->instrtxtp[num]); + /* we may need to expand the instrument array */ + if (num > engineState->maxinsno) { + int m = engineState->maxinsno; + engineState->maxinsno += MAXINSNO; /* Expand */ + engineState->instrtxtp = (INSTRTXT**) + mrealloc(csound, engineState->instrtxtp, + (1 + engineState->maxinsno) * sizeof(INSTRTXT*)); + /* Array expected to be nulled so.... */ + while (++m <= engineState->maxinsno) engineState->instrtxtp[m] = NULL; + } + /* hack: "name" actually points to the corresponding INSTRNAME */ + inm2 = (INSTRNAME*) (inm->name); /* entry in the table */ + inm2->instno = (int32) num; + engineState->instrtxtp[num] = inm2->ip; + if (csound->oparms->msglevel && engineState == &csound->engineState) + csound->Message(csound, Str("instr %s uses instrument number %d\n"), + inm2->name, num); + } + } + /* clear temporary chains */ + inm = inm_first; + while (inm) { + INSTRNAME *nxtinm = inm->next; + mfree(csound, inm); + inm = nxtinm; + } + cs_hash_table_remove(csound, engineState->instrumentNames, + (char*)INSTR_NAME_FIRST); +} + +/** + Insert INSTRTXT into an engineState list of INSTRTXT's, + checking to see if number is greater than number of pointers currently + allocated and if so expand pool of instruments +*/ +void insert_instrtxt(CSOUND *csound, INSTRTXT *instrtxt, + int32 instrNum, ENGINE_STATE *engineState) +{ + int i; + + if (UNLIKELY(instrNum >= engineState->maxinsno)) { + int old_maxinsno = engineState->maxinsno; + + /* expand */ + while (instrNum >= engineState->maxinsno) { + engineState->maxinsno += MAXINSNO; + } + + engineState->instrtxtp = + (INSTRTXT**)mrealloc(csound, + engineState->instrtxtp, + (1 + engineState->maxinsno) * sizeof(INSTRTXT*)); + + /* Array expected to be nulled so.... */ + for (i = old_maxinsno + 1; i <= engineState->maxinsno; i++) { + engineState->instrtxtp[i] = NULL; + } + } + + if (UNLIKELY(engineState->instrtxtp[instrNum] != NULL)) { + instrtxt->isNew = 1; + /* redefinition does not raise an error now, just a warning */ + if (instrNum && csound->oparms->odebug) + csound->Warning(csound, + Str("instr %ld redefined, replacing previous definition"), + instrNum); + /* here we should move the old instrument definition into a deadpool + which will be checked for active instances and freed when there are no + further ones + */ + for (i=0; i < engineState->maxinsno; i++) { + /* check for duplicate numbers and do nothing */ + if (i != instrNum && + engineState->instrtxtp[i] == engineState->instrtxtp[instrNum]) + goto end; + } + INSDS *active = engineState->instrtxtp[instrNum]->instance; + while (active != NULL && instrNum != 0) { + if (active->actflg) { + add_to_deadpool(csound, engineState->instrtxtp[instrNum]); + break; + } + active = active->nxtinstance; + } + /* no active instances */ + if (active == NULL || instrNum == 0) { + + if (csound->oparms->odebug) + csound->Message(csound, + Str("no active instances of instr %d \n"), instrNum); + free_instrtxt(csound, engineState->instrtxtp[instrNum]); + } + /* err++; continue; */ + } + end: + + instrtxt->instance = instrtxt->act_instance = instrtxt->lst_instance = NULL; + engineState->instrtxtp[instrNum] = instrtxt; + +} + +void insert_opcodes(CSOUND *csound, OPCODINFO *opcodeInfo, + ENGINE_STATE *engineState) +{ + if (opcodeInfo) { + int num = engineState->maxinsno; /* store after any other instruments */ + OPCODINFO *inm = opcodeInfo; + while (inm) { + /* we may need to expand the instrument array */ + if (UNLIKELY(++num > engineState->maxopcno)) { + int i; + i = (engineState->maxopcno > 0 ? + engineState->maxopcno : engineState->maxinsno); + engineState->maxopcno = i + MAXINSNO; + engineState->instrtxtp = (INSTRTXT**) + mrealloc(csound, engineState->instrtxtp, (1 + engineState->maxopcno) + * sizeof(INSTRTXT*)); + /* Array expected to be nulled so.... */ + while (++i <= engineState->maxopcno) engineState->instrtxtp[i] = NULL; + } + inm->instno = num; + //csound->Message(csound, Str("UDO INSTR NUM: %d\n"), num); + engineState->instrtxtp[num] = inm->ip; + inm = inm->prv; + } + } +} + + +OPCODINFO *find_opcode_info(CSOUND *csound, char *opname, + char* outargs, char* inargs) +{ + OPCODINFO *opinfo = csound->opcodeInfo; + if (UNLIKELY(opinfo == NULL)) { csound->Message(csound, Str("!!! csound->opcodeInfo is NULL !!!\n")); - return NULL; + return NULL; } while (opinfo != NULL) { - csound->Message(csound, "%s : %s\n", opinfo->name, opname); - if (UNLIKELY(strcmp(opinfo->name, opname) == 0)) { - return opinfo; - } - opinfo = opinfo->prv; /* Move on: JPff suggestion */ + if (UNLIKELY(strcmp(opinfo->name, opname) == 0 && + strcmp(opinfo->intypes, inargs) == 0 && + strcmp(opinfo->outtypes, outargs) == 0)) { + return opinfo; + } + opinfo = opinfo->prv; /* Move on: JPff suggestion */ } return NULL; } /** - * Compile the given TREE node into structs for Csound to use - */ -void csound_orc_compile(CSOUND *csound, TREE *root) + Merge a new engineState into csound->engineState + 1) Add to stringPool, constantsPool and varPool (globals) + 2) Add to opinfo and UDOs + 3) Call insert_instrtxt() on csound->engineState for each new instrument + 4) Call insprep() and recalculateVarPoolMemory() for each new instrument + 5) patch up nxtinstxt order +*/ +int engineState_merge(CSOUND *csound, ENGINE_STATE *engineState) { -// csound->Message(csound, "Begin Compiling AST (Currently Implementing)\n"); + int i, end = engineState->maxinsno; + ENGINE_STATE *current_state = &csound->engineState; + INSTRTXT *current; + int count; + + cs_hash_table_merge(csound, + current_state->stringPool, engineState->stringPool); + + for (count = 0; count < engineState->constantsPool->count; count++) { + if (csound->oparms->odebug) + csound->Message(csound, Str(" merging constants %d) %f\n"), + count, engineState->constantsPool->values[count]); + myflt_pool_find_or_add(csound, current_state->constantsPool, + engineState->constantsPool->values[count]); + } + CS_VARIABLE* gVar = engineState->varPool->head; + while (gVar != NULL) { + CS_VARIABLE* var; + if (csound->oparms->odebug) + csound->Message(csound, Str(" merging %d) %s:%s\n"), count, + gVar->varName, gVar->varType->varTypeName); + var = csoundFindVariableWithName(current_state->varPool, gVar->varName); + if (var == NULL) { + ARRAY_VAR_INIT varInit; + varInit.dimensions = gVar->dimensions; + varInit.type = gVar->varType; + var = csoundCreateVariable(csound, csound->typePool, + gVar->varType, gVar->varName, &varInit); + csoundAddVariable(current_state->varPool, var); + /* memory has already been allocated, so we just point to it */ + /* when disposing of the engineState global vars, we do not + delete the memBlock */ + var->memBlock = gVar->memBlock; + } + gVar = gVar->next; + } + + /* merge opcodinfo */ + insert_opcodes(csound, csound->opcodeInfo, current_state); + insert_instrtxt(csound,engineState->instrtxtp[0],0,current_state); + for (i=1; i < end; i++){ + current = engineState->instrtxtp[i]; + if (current != NULL){ + if (current->insname == NULL) { + if (csound->oparms->odebug) + csound->Message(csound, Str("merging instr %d \n"), i); + /* a first attempt at this merge is to make it use + insert_instrtxt again */ + /* insert instrument in current engine */ + insert_instrtxt(csound,current,i,current_state); + } + else { + if (csound->oparms->odebug) + csound->Message(csound, Str("merging instr %s \n"), current->insname); + /* allocate a named_instr string in the current engine */ + named_instr_alloc(csound,current->insname,current,-1L,current_state); + } + } + } + /* merges all named instruments */ + named_instr_assign_numbers(csound,current_state); + /* this needs to be called in a separate loop + in case of multiple instr numbers, so insprep() is called only once */ + current = (&(engineState->instxtanchor));//->nxtinstxt; + while ((current = current->nxtinstxt) != NULL) { + if (csound->oparms->odebug) + csound->Message(csound, "insprep %p \n", current); + insprep(csound, current, current_state);/* run insprep() to connect ARGS */ + recalculateVarPoolMemory(csound, + current->varPool); /* recalculate var pool */ + } + /* now we need to patch up instr order */ + end = current_state->maxinsno; + end = end < current_state->maxopcno ? current_state->maxopcno : end; + for (i=0; i < end; i++) { + int j; + current = current_state->instrtxtp[i]; + if (current != NULL) { + if(csound->oparms->odebug) + csound->Message(csound, "instr %d \n", i, current); + current->nxtinstxt = NULL; + j = i; + while (++j < end-1) { + if (current_state->instrtxtp[j] != NULL) { + current->nxtinstxt = current_state->instrtxtp[j]; + break; + } + } + } + } + (&(current_state->instxtanchor))->nxtinstxt = csound->instr0; + return 0; +} - OPARMS *O = csound->oparms; +int engineState_free(CSOUND *csound, ENGINE_STATE *engineState) +{ + /* FIXME: we need functions to deallocate stringPool, constantPool */ + mfree(csound, engineState->instrumentNames); + myflt_pool_free(csound, engineState->constantsPool); + /* purposely using mfree and not cs_hash_table_free as keys will have + been merged into csound->engineState */ + mfree(csound, engineState->stringPool); + mfree(csound, engineState->varPool); + mfree(csound, engineState); + return 0; +} + +/** + * Compile the given TREE node into structs + + In the the first compilation run, it: + 1) Uses the empty csound->engineState + 2) Creates instrument 0 + 3) Creates other instruments and UDOs + 4) Runs insprep() and recalculateVarpool() for each instrument + + In any subsequent compilation run, it: + 1) Creates a new engineState + 2) instrument 0 is treated as a global i-time instrument, header constants + are ignored. + 3) Creates other instruments + 4) Calls engineState_merge() and engineState_free() + + VL 20-12-12 + + * ASSUMES: TREE has been validated prior to compilation + * + * + */ +PUBLIC int csoundCompileTree(CSOUND *csound, TREE *root) +{ INSTRTXT *instrtxt = NULL; INSTRTXT *ip = NULL; - INSTRTXT *prvinstxt = &(csound->instxtanchor); + INSTRTXT *prvinstxt; OPTXT *bp; char *opname; - int32 count, sumcount, instxtcount, optxtcount; TREE * current = root; - INSTRTXT * instr0; - - strsav_create(csound); - - if (UNLIKELY(csound->otranGlobals == NULL)) { - csound->otranGlobals = csound->Calloc(csound, sizeof(OTRAN_GLOBALS)); + ENGINE_STATE *engineState; + CS_VARIABLE* var; + TYPE_TABLE* typeTable = (TYPE_TABLE*)current->markup; + + current = current->next; + if (csound->instr0 == NULL) { + engineState = &csound->engineState; + engineState->varPool = typeTable->globalPool; + + csound->instr0 = create_instrument0(csound, current, engineState, + typeTable->instr0LocalPool); + cs_hash_table_put_key(csound, engineState->stringPool, "\"\""); + prvinstxt = &(engineState->instxtanchor); + engineState->instrtxtp = + (INSTRTXT **) mcalloc(csound, (1 + engineState->maxinsno) + * sizeof(INSTRTXT*)); + prvinstxt = prvinstxt->nxtinstxt = csound->instr0; + insert_instrtxt(csound, csound->instr0, 0, engineState); + } + else { + engineState = (ENGINE_STATE *) mcalloc(csound, sizeof(ENGINE_STATE)); + engineState->stringPool = cs_hash_table_create(csound); + engineState->constantsPool = myflt_pool_create(csound); + engineState->varPool = typeTable->globalPool; + prvinstxt = &(engineState->instxtanchor); + engineState->instrtxtp = + (INSTRTXT **) mcalloc(csound, (1 + engineState->maxinsno) * + sizeof(INSTRTXT*)); + /* VL: allowing global code to be evaluated in + subsequent compilations */ + csound->instr0 = create_global_instrument(csound, current, engineState, + typeTable->instr0LocalPool); + insert_instrtxt(csound, csound->instr0, 0, engineState); + prvinstxt = prvinstxt->nxtinstxt = csound->instr0; + //engineState->maxinsno = 1; + } + + var = typeTable->globalPool->head; + while(var != NULL) { + var->memBlock = (void *) mcalloc(csound, var->memBlockSize); + if (var->initializeVariableMemory != NULL) { + var->initializeVariableMemory(var, (MYFLT *)(var->memBlock)); + } else memset(var->memBlock , 0, var->memBlockSize); + var = var->next; } - csound->instrtxtp = (INSTRTXT **) mcalloc(csound, (1 + csound->maxinsno) - * sizeof(INSTRTXT*)); - // csound->opcodeInfo = NULL; /* IV - Oct 20 2002 */ - - strconstndx(csound, "\"\""); - - gblnamset(csound, "sr"); /* enter global reserved words */ - gblnamset(csound, "kr"); - gblnamset(csound, "ksmps"); - gblnamset(csound, "nchnls"); - gblnamset(csound, "nchnls_i"); - gblnamset(csound, "0dbfs"); /* no commandline override for that! */ - gblnamset(csound, "$sr"); /* incl command-line overrides */ - gblnamset(csound, "$kr"); - gblnamset(csound, "$ksmps"); - - csound->pool = (MYFLT*) mmalloc(csound, NCONSTS * sizeof(MYFLT)); - ST(poolcount) = 0; - ST(nconsts) = NCONSTS; - ST(constTbl) = (int*) mcalloc(csound, (256 + NCONSTS) * sizeof(int)); - constndx(csound, "0"); - - if (!ST(typemask_tabl)) { - const int32 *ptr = typetabl1; - ST(typemask_tabl) = (int32*) mcalloc(csound, sizeof(int32) * 256); - ST(typemask_tabl_in) = (int32*) mcalloc(csound, sizeof(int32) * 256); - ST(typemask_tabl_out) = (int32*) mcalloc(csound, sizeof(int32) * 256); - while (*ptr) { /* basic types (both for input */ - int32 pos = *ptr++; /* and output) */ - ST(typemask_tabl)[pos] = ST(typemask_tabl_in)[pos] = - ST(typemask_tabl_out)[pos] = *ptr++; - } - ptr = typetabl2; - while (*ptr) { /* input types */ - int32 pos = *ptr++; - ST(typemask_tabl_in)[pos] = *ptr++; - } - ptr = typetabl3; - while (*ptr) { /* output types */ - int32 pos = *ptr++; - ST(typemask_tabl_out)[pos] = *ptr++; - } - } - instr0 = create_instrument0(csound, root); - prvinstxt = prvinstxt->nxtinstxt = instr0; - insert_instrtxt(csound, instr0, 0); while (current != NULL) { switch (current->type) { - case T_INIT: case '=': /* csound->Message(csound, "Assignment found\n"); */ break; case INSTR_TOKEN: - /* csound->Message(csound, "Instrument found\n"); */ - - resetouts(csound); /* reset #out counts */ - lblclear(csound); /* restart labelist */ - - instrtxt = create_instrument(csound, current); + //print_tree(csound, "Instrument found\n", current); + instrtxt = create_instrument(csound, current,engineState); prvinstxt = prvinstxt->nxtinstxt = instrtxt; /* Handle Inserting into CSOUND here by checking ids (name or * numbered) and using new insert_instrtxt? */ - //printf("Starting to install instruments\n"); /* Temporarily using the following code */ - if (current->left->type == INTEGER_TOKEN) { /* numbered instrument */ + if (current->left->type == INTEGER_TOKEN) { /* numbered instrument, eg.: + instr 1 + */ int32 instrNum = (int32)current->left->value->value; + insert_instrtxt(csound, instrtxt, instrNum, engineState); - insert_instrtxt(csound, instrtxt, instrNum); + } + else if (current->left->type == T_IDENT){ /* named instrument, eg.: + instr Hello + */ + int32 insno_priority = -1L; + char *c; + c = current->left->value->lexeme; + + if (UNLIKELY(current->left->rate == (int) '+')) { + insno_priority--; + } + if (UNLIKELY(!check_instr_name(c))) { + synterr(csound, Str("invalid name for instrument")); + } + named_instr_alloc(csound,c,instrtxt, insno_priority, + engineState); + instrtxt->insname = csound->Malloc(csound, strlen(c) + 1); + strcpy(instrtxt->insname, c); } else if (current->left->type == T_INSTLIST) { + /* list of instr names, eg: + instr Hello, 1, 2 + */ TREE *p = current->left; - //printf("instlist case:\n"); /* This code is suspect */ while (p) { if (PARSER_DEBUG) print_tree(csound, "Top of loop\n", p); if (p->left) { - //print_tree(csound, "Left\n", p->left); + if (p->left->type == INTEGER_TOKEN) { - insert_instrtxt(csound, instrtxt, p->left->value->value); + insert_instrtxt(csound, instrtxt, p->left->value->value, + engineState); } else if (p->left->type == T_IDENT) { int32 insno_priority = -1L; char *c; c = p->left->value->lexeme; - if (UNLIKELY(p->left->rate == (int) '+')) { insno_priority--; } if (UNLIKELY(!check_instr_name(c))) { synterr(csound, Str("invalid name for instrument")); } - if (UNLIKELY(!named_instr_alloc(csound, c, instrtxt, insno_priority))) { + if (UNLIKELY(!named_instr_alloc(csound, c, + instrtxt, insno_priority, + engineState))) { synterr(csound, Str("instr %s redefined"), c); } - instrtxt->insname = c; + instrtxt->insname = csound->Malloc(csound, strlen(c) + 1); + strcpy(instrtxt->insname, c); } } else { if (p->type == INTEGER_TOKEN) { - insert_instrtxt(csound, instrtxt, p->value->value); + insert_instrtxt(csound, instrtxt, p->value->value, engineState); } else if (p->type == T_IDENT) { int32 insno_priority = -1L; char *c; c = p->value->lexeme; - if (UNLIKELY(p->rate == (int) '+')) { insno_priority--; } if (UNLIKELY(!check_instr_name(c))) { synterr(csound, Str("invalid name for instrument")); } - if (UNLIKELY(!named_instr_alloc(csound, c, instrtxt, insno_priority))) { + if (UNLIKELY(!named_instr_alloc(csound, c, + instrtxt, insno_priority, + engineState))) { synterr(csound, Str("instr %s redefined"), c); } - instrtxt->insname = c; + instrtxt->insname = csound->Malloc(csound, strlen(c) + 1); + strcpy(instrtxt->insname, c); } break; } @@ -1090,30 +1537,21 @@ break; case UDO_TOKEN: /* csound->Message(csound, "UDO found\n"); */ - - resetouts(csound); /* reset #out counts */ - lblclear(csound); /* restart labelist */ - - instrtxt = create_instrument(csound, current); - + instrtxt = create_instrument(csound, current, engineState); prvinstxt = prvinstxt->nxtinstxt = instrtxt; - opname = current->left->value->lexeme; - - /* csound->Message(csound, */ - /* "Searching for OPCODINFO for opname: %s\n", opname); */ - - OPCODINFO *opinfo = find_opcode_info(csound, opname); + OPCODINFO *opinfo = find_opcode_info(csound, opname, + current->left->left->value->lexeme, + current->left->right->value->lexeme); if (UNLIKELY(opinfo == NULL)) { csound->Message(csound, - "ERROR: Could not find OPCODINFO for opname: %s\n", + Str("ERROR: Could not find OPCODINFO for opname: %s\n"), opname); } else { opinfo->ip = instrtxt; - instrtxt->insname = (char*)mmalloc(csound, 1+strlen(opname)); - strcpy(instrtxt->insname, opname); + instrtxt->insname = cs_strdup(csound, opname); instrtxt->opcode_info = opinfo; } @@ -1124,337 +1562,300 @@ break; case T_OPCODE: case T_OPCODE0: + case LABEL: break; + default: csound->Message(csound, Str("Unknown TREE node of type %d found in root.\n"), current->type); if (PARSER_DEBUG) print_tree(csound, NULL, current); } - current = current->next; + } + if (UNLIKELY(csound->synterrcnt)) { + print_opcodedir_warning(csound); + csound->Warning(csound, Str("%d syntax errors in orchestra. " + "compilation invalid\n"), + csound->synterrcnt); + return CSOUND_ERROR; } - /* Begin code from otran */ /* now add the instruments with names, assigning them fake instr numbers */ - named_instr_assign_numbers(csound); /* IV - Oct 31 2002 */ - if (csound->opcodeInfo) { - int num = csound->maxinsno; /* store after any other instruments */ - OPCODINFO *inm = csound->opcodeInfo; - /* IV - Oct 31 2002: now add user defined opcodes */ - while (inm) { - /* we may need to expand the instrument array */ - if (UNLIKELY(++num > csound->maxopcno)) { - int i; - i = (csound->maxopcno > 0 ? csound->maxopcno : csound->maxinsno); - csound->maxopcno = i + MAXINSNO; - csound->instrtxtp = (INSTRTXT**) - mrealloc(csound, csound->instrtxtp, (1 + csound->maxopcno) - * sizeof(INSTRTXT*)); - /* Array expected to be nulled so.... */ - while (++i <= csound->maxopcno) csound->instrtxtp[i] = NULL; - } - inm->instno = num; + named_instr_assign_numbers(csound,engineState); - /* csound->Message(csound, "UDO INSTR NUM: %d\n", num); */ + /* lock to ensure thread-safety */ + csoundLockMutex(csound->API_lock); + if (csound->init_pass_threadlock) csoundLockMutex(csound->init_pass_threadlock); + if (engineState != &csound->engineState) { + OPDS *ids = csound->ids; + /* any compilation other than the first one */ + /* merge ENGINE_STATE */ + engineState_merge(csound, engineState); + /* delete ENGINE_STATE */ + engineState_free(csound, engineState); + /* run global i-time code */ + init0(csound); + csound->ids = ids; - csound->instrtxtp[num] = inm->ip; - inm = inm->prv; - } - } - /* Deal with defaults and consistency */ - if (csound->tran_ksmps == FL(-1.0)) { - if (csound->tran_sr == FL(-1.0)) csound->tran_sr = DFLT_SR; - if (csound->tran_kr == FL(-1.0)) csound->tran_kr = DFLT_KR; - csound->tran_ksmps = (MYFLT) ((int) (csound->tran_sr / csound->tran_kr - + FL(0.5))); - } - else if (csound->tran_kr == FL(-1.0)) { - if (csound->tran_sr == FL(-1.0)) csound->tran_sr = DFLT_SR; - csound->tran_kr = csound->tran_sr / csound->tran_ksmps; } - else if (csound->tran_sr == FL(-1.0)) { - csound->tran_sr = csound->tran_kr * csound->tran_ksmps; - } - /* That deals with missing values, however we do need ksmps to be integer */ - { - char err_msg[128]; - sprintf(err_msg, "sr = %.7g, kr = %.7g, ksmps = %.7g\nerror:", - csound->tran_sr, csound->tran_kr, csound->tran_ksmps); - if (UNLIKELY(csound->tran_sr <= FL(0.0))) - synterr(csound, Str("%s invalid sample rate"), err_msg); - if (UNLIKELY(csound->tran_kr <= FL(0.0))) - synterr(csound, Str("%s invalid control rate"), err_msg); - else if (UNLIKELY(csound->tran_ksmps < FL(0.75) || - FLOAT_COMPARE(csound->tran_ksmps, - MYFLT2LRND(csound->tran_ksmps)))) - synterr(csound, Str("%s invalid ksmps value"), err_msg); - else if (UNLIKELY(FLOAT_COMPARE(csound->tran_sr, - (double) csound->tran_kr * csound->tran_ksmps))) - synterr(csound, Str("%s inconsistent sr, kr, ksmps"), err_msg); - } - - ip = csound->instxtanchor.nxtinstxt; - bp = (OPTXT *) ip; - while (bp != (OPTXT *) NULL && (bp = bp->nxtop) != NULL) { - /* chk instr 0 for illegal perfs */ - int thread, opnum = bp->t.opnum; - if (opnum == ENDIN) break; - if (opnum == LABEL) continue; - if (PARSER_DEBUG) - csound->DebugMsg(csound, "Instr 0 check on opcode=%s\n", bp->t.opcod); - if (UNLIKELY((thread = csound->opcodlst[opnum].thread) & 06 || - (!thread && bp->t.pftype != 'b'))) { - csound->DebugMsg(csound, "***opcode=%s thread=%d pftype=%c\n", - bp->t.opcod, thread, bp->t.pftype); - synterr(csound, Str("perf-pass statements illegal in header blk\n")); + else { + /* first compilation */ + insert_opcodes(csound, csound->opcodeInfo, engineState); + ip = engineState->instxtanchor.nxtinstxt; + bp = (OPTXT *) ip; + while (bp != (OPTXT *) NULL && (bp = bp->nxtop) != NULL) { + /* chk instr 0 for illegal perfs */ + int thread; + OENTRY* oentry = bp->t.oentry; + if (strcmp(oentry->opname, "endin") == 0) break; + if (strcmp(oentry->opname, "$label") == 0) continue; + if (PARSER_DEBUG) + csound->DebugMsg(csound, "Instr 0 check on opcode=%s\n", bp->t.opcod); + if (UNLIKELY((thread = oentry->thread) & 06 || + (!thread && bp->t.pftype != 'b'))) { + csound->DebugMsg(csound, "***opcode=%s thread=%d pftype=%c\n", + bp->t.opcod, thread, bp->t.pftype); + synterr(csound, Str("perf-pass statements illegal in header blk\n")); + } } + + ip = &(engineState->instxtanchor); + while ((ip = ip->nxtinstxt) != NULL) { /* add all other entries */ + insprep(csound, ip, engineState); /* as combined offsets */ + recalculateVarPoolMemory(csound, ip->varPool); + } + + CS_VARIABLE *var; + var = csoundFindVariableWithName(engineState->varPool, "sr"); + *((MYFLT *)(var->memBlock)) = csound->esr; + var = csoundFindVariableWithName(engineState->varPool, "kr"); + *((MYFLT *)(var->memBlock)) = csound->ekr; + var = csoundFindVariableWithName(engineState->varPool, "ksmps"); + *((MYFLT *)(var->memBlock)) = csound->ksmps; + var = csoundFindVariableWithName(engineState->varPool, "nchnls"); + *((MYFLT *)(var->memBlock)) = csound->nchnls; + if (csound->inchnls<0) csound->inchnls = csound->nchnls; + var = csoundFindVariableWithName(engineState->varPool, "nchnls_i"); + *((MYFLT *)(var->memBlock)) = csound->inchnls; + var = csoundFindVariableWithName(engineState->varPool, "0dbfs"); + *((MYFLT *)(var->memBlock)) = csound->e0dbfs; + + } - if (UNLIKELY(csound->synterrcnt)) { - print_opcodedir_warning(csound); - csound->Die(csound, Str("%d syntax errors in orchestra. " - "compilation invalid\n"), csound->synterrcnt); - } - if (UNLIKELY(O->odebug)) { - int32 n; - MYFLT *p; - csound->Message(csound, "poolcount = %ld, strpool_cnt = %ld\n", - ST(poolcount), ST(strpool_cnt)); - csound->Message(csound, "pool:"); - for (n = ST(poolcount), p = csound->pool; n--; p++) - csound->Message(csound, "\t%g", *p); - csound->Message(csound, "\n"); - csound->Message(csound, "strpool:"); - for (n = 0L; n < ST(strpool_cnt); n++) - csound->Message(csound, "\t%s", ST(strpool)[n]); - csound->Message(csound, "\n"); - } - ST(gblfixed) = ST(gblnxtkcnt) + ST(gblnxtpcnt) * (int) Pfloats; - ST(gblkcount) = ST(gblnxtkcnt); - /* align to 8 bytes for "spectral" types */ - if ((int) sizeof(MYFLT) < 8 && ST(gblnxtpcnt)) - ST(gblkcount) = (ST(gblkcount) + 1) & (~1); - ST(gblacount) = ST(gblnxtacnt); - ST(gblscount) = ST(gblnxtscnt); - - ip = &(csound->instxtanchor); - for (sumcount = 0; (ip = ip->nxtinstxt) != NULL; ) {/* for each instxt */ - OPTXT *optxt = (OPTXT *) ip; - int optxtcount = 0; - while ((optxt = optxt->nxtop) != NULL) { /* for each op in instr */ - TEXT *ttp = &optxt->t; - optxtcount += 1; - if (ttp->opnum == ENDIN /* (until ENDIN) */ - || ttp->opnum == ENDOP) break; /* (IV - Oct 26 2002: or ENDOP) */ - if ((count = ttp->inlist->count)!=0) - sumcount += count +1; /* count the non-nullist */ - if ((count = ttp->outlist->count)!=0) /* slots in all arglists */ - sumcount += (count + 1); - } - ip->optxtcount = optxtcount; /* optxts in this instxt */ - } - ST(argoffsize) = (sumcount + 1) * sizeof(int); /* alloc all plus 1 null */ - /* as argoff ints */ - csound->argoffspace = (int*) mmalloc(csound, ST(argoffsize)); - ST(nxtargoffp) = csound->argoffspace; - ST(nulloffs) = (ARGOFFS *) csound->argoffspace; /* setup the null argoff */ - *ST(nxtargoffp)++ = 0; - ST(argofflim) = ST(nxtargoffp) + sumcount; - ip = &(csound->instxtanchor); - while ((ip = ip->nxtinstxt) != NULL) /* add all other entries */ - insprep(csound, ip); /* as combined offsets */ - if (UNLIKELY(O->odebug)) { - int *p = csound->argoffspace; - csound->Message(csound, "argoff array:\n"); - do { - csound->Message(csound, "\t%d", *p++); - } while (p < ST(argofflim)); - csound->Message(csound, "\n"); - } - if (UNLIKELY(ST(nxtargoffp) != ST(argofflim))) - csoundDie(csound, Str("inconsistent argoff sumcount")); - - ip = &(csound->instxtanchor); /* set the OPARMS values */ - instxtcount = optxtcount = 0; - while ((ip = ip->nxtinstxt) != NULL) { - instxtcount += 1; - optxtcount += ip->optxtcount; - } - csound->instxtcount = instxtcount; - csound->optxtsize = instxtcount * sizeof(INSTRTXT) - + optxtcount * sizeof(OPTXT); - csound->poolcount = ST(poolcount); - csound->gblfixed = ST(gblnxtkcnt) + ST(gblnxtpcnt) * (int) Pfloats; - csound->gblacount = ST(gblnxtacnt); - csound->gblscount = ST(gblnxtscnt); - /* clean up */ - delete_local_namepool(csound); - delete_global_namepool(csound); - mfree(csound, ST(constTbl)); - ST(constTbl) = NULL; - /* End code from otran */ - /* csound->Message(csound, "End Compiling AST\n"); */ + if (csound->init_pass_threadlock) + csoundUnlockMutex(csound->init_pass_threadlock); + /* notify API lock */ + csoundUnlockMutex(csound->API_lock); + + return CSOUND_SUCCESS; +} + +/** + Parse and compile an orchestra given on an string, + evaluating any global space code (i-time only). + On SUCCESS it returns a value passed to the + 'return' opcode in global space +*/ +PUBLIC MYFLT csoundEvalCode(CSOUND *csound, const char *str) +{ + if (str && csoundCompileOrc(csound,str) == CSOUND_SUCCESS) + return csound->instr0->instance[0].retval; +#ifdef NAN + else return NAN; +#else + else return 0; +#endif +} + +/** + Parse and compile an orchestra given on an string (OPTIONAL) + if str is NULL the string is taken from the internal corfile + containing the initial orchestra file passed to Csound. + Also evaluates any global space code. +*/ +PUBLIC int csoundCompileOrc(CSOUND *csound, const char *str) +{ + int retVal; + TREE *root = csoundParseOrc(csound, str); + if (LIKELY(root != NULL)) { + retVal = csoundCompileTree(csound, root); + } + else + return CSOUND_ERROR; + csoundDeleteTree(csound, root); + + if (UNLIKELY(csound->oparms->odebug)) + debugPrintCsound(csound); + return retVal; } /* prep an instr template for efficient allocs */ /* repl arg refs by offset ndx to lcl/gbl space */ -static void insprep(CSOUND *csound, INSTRTXT *tp) +static void insprep(CSOUND *csound, INSTRTXT *tp, ENGINE_STATE *engineState) { OPARMS *O = csound->oparms; OPTXT *optxt; OENTRY *ep; - int n, opnum, inreqd; char **argp; - char **labels, **lblsp; - LBLARG *larg, *largp; + + int n, inreqd; + char** argStringParts; ARGLST *outlist, *inlist; - ARGOFFS *outoffs, *inoffs; - int indx, *ndxp; - labels = (char **)mmalloc(csound, (csound->nlabels) * sizeof(char *)); - lblsp = labels; - larg = (LBLARG *)mmalloc(csound, (csound->ngotos) * sizeof(LBLARG)); - largp = larg; - ST(lclkcnt) = tp->lclkcnt; - ST(lclwcnt) = tp->lclwcnt; - ST(lclfixed) = tp->lclfixed; - ST(lclpcnt) = tp->lclpcnt; - ST(lclscnt) = tp->lclscnt; - ST(lclacnt) = tp->lclacnt; - delete_local_namepool(csound); /* clear lcl namlist */ - ST(lclnxtkcnt) = 0; /* for rebuilding */ - ST(lclnxtwcnt) = ST(lclnxtacnt) = 0; - ST(lclnxtpcnt) = ST(lclnxtscnt) = 0; - ST(lclpmax) = tp->pmax; /* set pmax for plgndx */ - ndxp = ST(nxtargoffp); + OENTRY* pset = find_opcode(csound, "pset"); + optxt = (OPTXT *)tp; while ((optxt = optxt->nxtop) != NULL) { /* for each op in instr */ TEXT *ttp = &optxt->t; - if ((opnum = ttp->opnum) == ENDIN /* (until ENDIN) */ - || opnum == ENDOP) /* (IV - Oct 31 2002: or ENDOP) */ - break; - if (opnum == LABEL) { - if (lblsp - labels >= csound->nlabels) { - int oldn = lblsp - labels; - csound->nlabels += NLABELS; - if (lblsp - labels >= csound->nlabels) - csound->nlabels = lblsp - labels + 2; - if (csound->oparms->msglevel) - csound->Message(csound, - Str("LABELS list is full...extending to %d\n"), - csound->nlabels); - labels = - (char**)mrealloc(csound, labels, csound->nlabels*sizeof(char*)); - lblsp = &labels[oldn]; - } - *lblsp++ = ttp->opcod; + ep = ttp->oentry; + + if (strcmp(ep->opname, "endin") == 0 /* (until ENDIN) */ + || strcmp(ep->opname, "endop") == 0) break; + if (strcmp(ep->opname, "$label") == 0) { continue; } - ep = &(csound->opcodlst[opnum]); - if (O->odebug) csound->Message(csound, "%s argndxs:", ep->opname); - if ((outlist = ttp->outlist) == ST(nullist) || !outlist->count) - ttp->outoffs = ST(nulloffs); + + if (O->odebug) + csound->Message(csound, "%s args:", ep->opname); + if ((outlist = ttp->outlist) == NULL || !outlist->count) + ttp->outArgs = NULL; else { - ttp->outoffs = outoffs = (ARGOFFS *) ndxp; - outoffs->count = n = outlist->count; + n = outlist->count; argp = outlist->arg; /* get outarg indices */ - ndxp = outoffs->indx; while (n--) { - *ndxp++ = indx = plgndx(csound, *argp++); - if (O->odebug) csound->Message(csound, "\t%d", indx); + ARG* arg = createArg(csound, tp, *argp++, engineState); + if (ttp->outArgs == NULL) { + ttp->outArgs = arg; + } else { + ARG* current = ttp->outArgs; + while (current->next != NULL) { + current = current->next; + } + current->next = arg; + arg->next = NULL; + } } + ttp->outArgCount = argCount(ttp->outArgs); } - if ((inlist = ttp->inlist) == ST(nullist) || !inlist->count) - ttp->inoffs = ST(nulloffs); + if ((inlist = ttp->inlist) == NULL || !inlist->count) + ttp->inArgs = NULL; else { - ttp->inoffs = inoffs = (ARGOFFS *) ndxp; - inoffs->count = inlist->count; - inreqd = strlen(ep->intypes); + inreqd = argsRequired(ep->intypes); + argStringParts = splitArgs(csound, ep->intypes); argp = inlist->arg; /* get inarg indices */ - ndxp = inoffs->indx; - for (n=0; n < inlist->count; n++, argp++, ndxp++) { - if (n < inreqd && ep->intypes[n] == 'l') { - if (largp - larg >= csound->ngotos) { - int oldn = csound->ngotos; - csound->ngotos += NGOTOS; - if (csound->oparms->msglevel) - csound->Message(csound, - Str("GOTOS list is full..extending to %d\n"), - csound->ngotos); - if (largp - larg >= csound->ngotos) - csound->ngotos = largp - larg + 1; - larg = (LBLARG *) - mrealloc(csound, larg, csound->ngotos * sizeof(LBLARG)); - largp = &larg[oldn]; - } + for (n=0; n < inlist->count; n++, argp++) { + ARG* arg = NULL; + if (n < inreqd && *argStringParts[n] == 'l') { + arg = csound->Calloc(csound, sizeof(ARG)); + arg->type = ARG_LABEL; + arg->argPtr = mmalloc(csound, strlen(*argp) + 1); + strcpy(arg->argPtr, *argp); if (UNLIKELY(O->odebug)) - csound->Message(csound, "\t***lbl"); /* if arg is label, */ - largp->lbltxt = *argp; - largp->ndxp = ndxp; /* defer till later */ - largp++; - } - else { + csound->Message(csound, "\t%s:", *argp); /* if arg is label, */ + } else { char *s = *argp; - indx = plgndx(csound, s); - if (UNLIKELY(O->odebug)) csound->Message(csound, "\t%d", indx); - *ndxp = indx; + arg = createArg(csound, tp, s, engineState); + } + + if (ttp->inArgs == NULL) { + ttp->inArgs = arg; + } else { + ARG* current = ttp->inArgs; + while(current->next != NULL) { + current = current->next; + } + current->next = arg; + arg->next = NULL; } } - } - if (UNLIKELY(O->odebug)) csound->Message(csound, "\n"); - } - nxt: - while (--largp >= larg) { /* resolve the lbl refs */ - char *s = largp->lbltxt; - char **lp; - for (lp = labels; lp < lblsp; lp++) - if (strcmp(s, *lp) == 0) { - *largp->ndxp = lp - labels + LABELOFS; - goto nxt; + + ttp->inArgCount = argCount(ttp->inArgs); + + if (ttp->oentry == pset) { + MYFLT* fp1; + int n; + ARG* inArgs = ttp->inArgs; + //CS_VARIABLE* var; + + if (tp->insname) + csound->Message(csound, "PSET: isname=\"%s\", pmax=%d\n", + tp->insname, tp->pmax); + else + csound->Message(csound, "PSET: isno=??, pmax=%d\n", tp->pmax); + if ((n = ttp->inArgCount) != tp->pmax) { + //csound->Warning(csound, Str("i%d pset args != pmax"), (int) insno); + csound->Warning(csound, Str("i[fixme] pset args != pmax")); + if (n < tp->pmax) n = tp->pmax; /* cf pset, pmax */ + } + tp->psetdata = (MYFLT*) mcalloc(csound, n * sizeof(MYFLT)); + + for (n = 0, fp1 = tp->psetdata; + n < (int)ttp->inArgCount; + n++, inArgs = inArgs->next) { + switch (inArgs->type) { + case ARG_CONSTANT: + + *fp1++ = engineState->constantsPool->values[inArgs->index]; + break; + +// case ARG_LOCAL: +// *fp1++ = 44.0; +// break; +// +// case ARG_GLOBAL: +// var = (CS_VARIABLE*)inArgs->argPtr; +// *fp1++ = *((MYFLT*)var->memBlock); +// break; + + /* FIXME - to note, because this is done during + compile time, pset does not work with local and + global variables as they have not been initialized + yet. Csound5 also did not work with local/global + variables. In the future, use the test in + tests/commandline/contrib/test_pset.csd for testing. + */ + default: + *fp1++ = 0.0; + break; + } + + // csound->Message(csound, "..%f..", *(fp1-1)); + } + + csound->Message(csound, "\n"); } - csoundDie(csound, Str("target label '%s' not found"), s); - } - ST(nxtargoffp) = ndxp; - mfree(csound, labels); - mfree(csound, larg); -} -/* returns non-zero if 's' is defined in the global or local pool of names */ + mfree(csound, argStringParts); + } -static int lgexist2(CSOUND *csound, const char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = NULL; - for (p = ST(gblNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) - return 1; - for (p = ST(lclNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - return (p == NULL ? 0 : 1); + if (O->odebug) + csound->Message(csound, "\n"); + } } /* build pool of floating const values */ /* build lcl/gbl list of ds names, offsets */ /* (no need to save the returned values) */ -static void lgbuild(CSOUND *csound, char *s, int inarg) +static void lgbuild(CSOUND *csound, INSTRTXT* ip, char *s, + int inarg, ENGINE_STATE *engineState) { char c; + char* temp; c = *s; /* must trap 0dbfs as name starts with a digit! */ if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || - (c == '0' && strcmp(s, "0dbfs") != 0)) - constndx(csound, s); - else if (c == '"') - strconstndx(csound, s); - else if (!(lgexist2(csound, s)) && !inarg) { - if (c == 'g' || (c == '#' && s[1] == 'g')) - gblnamset(csound, s); - else - lclnamset(csound, s); + (c == '0' && strcmp(s, "0dbfs") != 0)) { + myflt_pool_find_or_addc(csound, engineState->constantsPool, s); + } else if (c == '"') { + temp = mcalloc(csound, strlen(s) + 1); + unquote_string(temp, s); + cs_hash_table_put_key(csound, engineState->stringPool, temp); } } @@ -1462,369 +1863,78 @@ /* argument const/gbl indexes are positiv+1, */ /* pnum/lcl negativ-1 called only after */ /* poolcount & lclpmax are finalised */ -static int plgndx(CSOUND *csound, char *s) +static ARG* createArg(CSOUND *csound, INSTRTXT* ip, + char *s, ENGINE_STATE *engineState) { char c; - int n, indx; + char* temp; + int n; c = *s; - /* must trap 0dbfs as name starts with a digit! */ - if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || - (c == '0' && strcmp(s, "0dbfs") != 0)) - indx = constndx(csound, s) + 1; - else if (c == '"') - indx = strconstndx(csound, s) + STR_OFS + 1; - else if ((n = pnum(s)) >= 0) - indx = -n; - else if (c == 'g' || (c == '#' && *(s+1) == 'g') || gexist(csound, s)) - indx = (int) (ST(poolcount) + 1 + gbloffndx(csound, s)); - else - indx = -(ST(lclpmax) + 1 + lcloffndx(csound, s)); -/* csound->Message(csound, " [%s -> %d (%x)]\n", s, indx, indx); */ - return(indx); -} - -/* get storage ndx of string const value */ -/* builds value pool on 1st occurrence */ -static int strconstndx(CSOUND *csound, const char *s) -{ - int i, cnt; - - /* check syntax */ - cnt = (int) strlen(s); - if (UNLIKELY(cnt < 2 || *s != '"' || s[cnt - 1] != '"')) { - synterr(csound, Str("string syntax '%s'"), s); - return 0; - } - /* check if a copy of the string is already stored */ - for (i = 0; i < ST(strpool_cnt); i++) { - if (strcmp(s, ST(strpool)[i]) == 0) - return i; - } - /* not found, store new string */ - cnt = ST(strpool_cnt)++; - if (!(cnt & 0x7F)) { - /* extend list */ - if (!cnt) ST(strpool) = csound->Malloc(csound, 0x80 * sizeof(MYFLT*)); - else ST(strpool) = csound->ReAlloc(csound, ST(strpool), - (cnt + 0x80) * sizeof(MYFLT*)); - } - ST(strpool)[cnt] = (char*) csound->Malloc(csound, strlen(s) + 1); - strcpy(ST(strpool)[cnt], s); - /* and return index */ - return cnt; -} - -static inline unsigned int MYFLT_hash(const MYFLT *x) -{ - const unsigned char *c = (const unsigned char*) x; - size_t i; - unsigned int h = 0U; + ARG* arg = csound->Calloc(csound, sizeof(ARG)); - for (i = (size_t) 0; i < sizeof(MYFLT); i++) - h = (unsigned int) strhash_tabl_8[(unsigned int) c[i] ^ h]; + if (UNLIKELY(csound->oparms->odebug)) + csound->Message(csound, "\t%s", s); /* if arg is label, */ - return h; -} - -/* get storage ndx of float const value */ -/* builds value pool on 1st occurrence */ -/* final poolcount used in plgndx above */ -/* pool may be moved w. ndx still valid */ - -static int constndx(CSOUND *csound, const char *s) -{ - MYFLT newval; - int h, n, prv; - - { - volatile MYFLT tmpVal; /* make sure it really gets rounded to MYFLT */ - char *tmp = (char*) s; - tmpVal = (MYFLT) strtod(s, &tmp); - newval = tmpVal; - if (UNLIKELY(tmp == s || *tmp != (char) 0)) { - synterr(csound, Str("numeric syntax '%s'"), s); - return 0; - } - } - /* calculate hash value (0 to 255) */ - h = (int) MYFLT_hash(&newval); - n = ST(constTbl)[h]; /* now search constpool */ - prv = 0; - while (n) { - if (csound->pool[n - 256] == newval) { /* if val is there */ - if (prv) { - /* move to the beginning of the chain, so that */ - /* frequently searched values are found faster */ - ST(constTbl)[prv] = ST(constTbl)[n]; - ST(constTbl)[n] = ST(constTbl)[h]; - ST(constTbl)[h] = n; - } - return (n - 256); /* return w. index */ - } - prv = n; - n = ST(constTbl)[prv]; - } - n = ST(poolcount)++; - if (n >= ST(nconsts)) { - ST(nconsts) = ((ST(nconsts) + (ST(nconsts) >> 3)) | (NCONSTS - 1)) + 1; - if (UNLIKELY(csound->oparms->msglevel)) - csound->Message(csound, Str("extending Floating pool to %d\n"), - ST(nconsts)); - csound->pool = (MYFLT*) mrealloc(csound, csound->pool, ST(nconsts) - * sizeof(MYFLT)); - ST(constTbl) = (int*) mrealloc(csound, ST(constTbl), (256 + ST(nconsts)) - * sizeof(int)); - } - csound->pool[n] = newval; /* else enter newval */ - ST(constTbl)[n + 256] = ST(constTbl)[h]; /* link into chain */ - ST(constTbl)[h] = n + 256; - - return n; /* and return new ndx */ -} - -/* tests whether variable name exists */ -/* in gbl namelist */ - -static int gexist(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p; - - for (p = ST(gblNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - return (p == NULL ? 0 : 1); -} - - -/* builds namelist & type counts for gbl names */ - -static void gblnamset(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(gblNames)[h]; - /* search gbl namelist: */ - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) /* if name is there */ - return; /* return */ - p = (NAME*) malloc(sizeof(NAME)); - if (UNLIKELY(p == NULL)) - csound->Die(csound, Str("gblnamset(): memory allocation failure")); - p->namep = s; /* else record newname */ - p->nxt = ST(gblNames)[h]; - ST(gblNames)[h] = p; - if (*s == '#') s++; - if (*s == 'g') s++; - switch ((int) *s) { /* and its type-count */ - case 'a': p->type = ATYPE; p->count = ST(gblnxtacnt)++; break; - case 'S': p->type = STYPE; p->count = ST(gblnxtscnt)++; break; - case 'f': p->type = PTYPE; p->count = ST(gblnxtpcnt)++; break; - default: p->type = KTYPE; p->count = ST(gblnxtkcnt)++; - } -} - -/* builds namelist & type counts for lcl names */ -/* called by otran for each instr for lcl cnts */ -/* lists then redone by insprep via lcloffndx */ - -static NAME *lclnamset(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(lclNames)[h]; - /* search lcl namelist: */ - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) /* if name is there */ - return p; /* return ptr */ - p = (NAME*) malloc(sizeof(NAME)); - if (UNLIKELY(p == NULL)) - csound->Die(csound, Str("lclnamset(): memory allocation failure")); - p->namep = s; /* else record newname */ - p->nxt = ST(lclNames)[h]; - ST(lclNames)[h] = p; - if (*s == '#') s++; - switch (*s) { /* and its type-count */ - case 'w': p->type = WTYPE; p->count = ST(lclnxtwcnt)++; break; - case 'a': p->type = ATYPE; p->count = ST(lclnxtacnt)++; break; - case 'f': p->type = PTYPE; p->count = ST(lclnxtpcnt)++; break; - case 't': p->type = PTYPE; p->count = ST(lclnxtpcnt)++; break; - case 'S': p->type = STYPE; p->count = ST(lclnxtscnt)++; break; - default: p->type = KTYPE; p->count = ST(lclnxtkcnt)++; break; - } - return p; -} - -/* get named offset index into gbl dspace */ -/* called only after otran and gblfixed valid */ - -static int gbloffndx(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(gblNames)[h]; - - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (UNLIKELY(p == NULL)) - csoundDie(csound, Str("unexpected global name")); - switch (p->type) { - case ATYPE: return (ST(gblfixed) + p->count); - case STYPE: return (ST(gblfixed) + ST(gblacount) + p->count); - case PTYPE: return (ST(gblkcount) + p->count * (int) Pfloats); - } - return p->count; -} - -/* get named offset index into instr lcl dspace */ -/* called by insprep aftr lclcnts, lclfixed valid */ - -static int lcloffndx(CSOUND *csound, char *s) -{ - NAME *np = lclnamset(csound, s); /* rebuild the table */ - - switch (np->type) { /* use cnts to calc ndx */ - case KTYPE: return np->count; - case WTYPE: return (ST(lclkcnt) + np->count * Wfloats); - case ATYPE: return (ST(lclfixed) + np->count); - case PTYPE: return (ST(lclkcnt) + ST(lclwcnt) * Wfloats - + np->count * (int) Pfloats); - case STYPE: return (ST(lclfixed) + ST(lclacnt) + np->count); - default: csoundDie(csound, Str("unknown nametype")); - } - return 0; -} - -static void delete_global_namepool(CSOUND *csound) -{ - int i; + /* must trap 0dbfs as name starts with a digit! */ + if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || + (c == '0' && strcmp(s, "0dbfs") != 0)) { + arg->type = ARG_CONSTANT; - if (csound->otranGlobals == NULL) - return; - for (i = 0; i < 256; i++) { - while (ST(gblNames)[i] != NULL) { - NAME *nxt = ST(gblNames)[i]->nxt; - free(ST(gblNames)[i]); - ST(gblNames)[i] = nxt; - } + arg->index = myflt_pool_find_or_addc(csound, engineState->constantsPool, s); + } else if (c == '"') { + STRINGDAT *str = mcalloc(csound, sizeof(STRINGDAT)); + arg->type = ARG_STRING; + temp = mcalloc(csound, strlen(s) + 1); + unquote_string(temp, s); + str->data = cs_hash_table_get_key(csound, + csound->engineState.stringPool, temp); + str->size = strlen(temp) + 1; + arg->argPtr = str; + if (str->data == NULL) { + str->data = cs_hash_table_put_key(csound, engineState->stringPool, temp); + } + } else if ((n = pnum(s)) >= 0) { + arg->type = ARG_PFIELD; + arg->index = n; } -} - -static void delete_local_namepool(CSOUND *csound) -{ - int i; + /* trap local ksmps and kr */ + else + if ((strcmp(s, "ksmps") == 0 && csoundFindVariableWithName(ip->varPool, s)) + || (strcmp(s, "kr") == 0 && csoundFindVariableWithName(ip->varPool, s))) { + arg->type = ARG_LOCAL; + arg->argPtr = csoundFindVariableWithName(ip->varPool, s); + CS_VARIABLE *var = (CS_VARIABLE *)arg->argPtr; + } + else if (c == 'g' || (c == '#' && *(s+1) == 'g') || + csoundFindVariableWithName(csound->engineState.varPool, s) != NULL) { + // FIXME - figure out why string pool searched with gexist + //|| string_pool_indexof(csound->engineState.stringPool, s) > 0) { + arg->type = ARG_GLOBAL; + arg->argPtr = csoundFindVariableWithName(engineState->varPool, s); - if (csound->otranGlobals == NULL) - return; - for (i = 0; i < 256; i++) { - while (ST(lclNames)[i] != NULL) { - NAME *nxt = ST(lclNames)[i]->nxt; - free(ST(lclNames)[i]); - ST(lclNames)[i] = nxt; - } } -} - - /* ------------------------------------------------------------------------ */ -#if 0 - -/* get size of string in MYFLT units */ - -static int strlen_to_samples(const char *s) -{ - int n = (int) strlen(s); - n = (n + (int) sizeof(MYFLT)) / (int) sizeof(MYFLT); - return n; -} - -/* convert string constant */ - -static void unquote_string(char *dst, const char *src) -{ - int i, j, n = (int) strlen(src) - 1; - for (i = 1, j = 0; i < n; i++) { - if (src[i] != '\\') - dst[j++] = src[i]; - else { - switch (src[++i]) { - case 'a': dst[j++] = '\a'; break; - case 'b': dst[j++] = '\b'; break; - case 'f': dst[j++] = '\f'; break; - case 'n': dst[j++] = '\n'; break; - case 'r': dst[j++] = '\r'; break; - case 't': dst[j++] = '\t'; break; - case 'v': dst[j++] = '\v'; break; - case '"': dst[j++] = '"'; break; - case '\\': dst[j++] = '\\'; break; - default: - if (src[i] >= '0' && src[i] <= '7') { - int k = 0, l = (int) src[i] - '0'; - while (++k < 3 && src[i + 1] >= '0' && src[i + 1] <= '7') - l = (l << 3) | ((int) src[++i] - '0'); - dst[j++] = (char) l; - } - else { - dst[j++] = '\\'; i--; - } - } + else { + arg->type = ARG_LOCAL; + arg->argPtr = csoundFindVariableWithName(ip->varPool, s); + if (arg->argPtr == NULL) { + csound->Message(csound, Str("Missing local arg: %s\n"), s); } } - dst[j] = '\0'; -} - -static int create_strconst_ndx_list(CSOUND *csound, int **lst, int offs) -{ - int *ndx_lst; - char **strpool; - int strpool_cnt, ndx, i; - - strpool_cnt = ST(strpool_cnt); - strpool = ST(strpool); - /* strpool_cnt always >= 1 because of empty string at index 0 */ - ndx_lst = (int*) csound->Malloc(csound, strpool_cnt * sizeof(int)); - for (i = 0, ndx = offs; i < strpool_cnt; i++) { - ndx_lst[i] = ndx; - ndx += strlen_to_samples(strpool[i]); - } - *lst = ndx_lst; - /* return with total size in MYFLT units */ - return (ndx - offs); -} - -static void convert_strconst_pool(CSOUND *csound, MYFLT *dst) -{ - char **strpool, *s; - int strpool_cnt, ndx, i; - - strpool_cnt = ST(strpool_cnt); - strpool = ST(strpool); - if (strpool == NULL) - return; - for (ndx = i = 0; i < strpool_cnt; i++) { - s = (char*) ((MYFLT*) dst + (int) ndx); - unquote_string(s, strpool[i]); - ndx += strlen_to_samples(strpool[i]); - } - /* original pool is no longer needed */ - ST(strpool) = NULL; - ST(strpool_cnt) = 0; - for (i = 0; i < strpool_cnt; i++) - csound->Free(csound, strpool[i]); - csound->Free(csound, strpool); + /* csound->Message(csound, " [%s -> %d (%x)]\n", s, indx, indx); */ + return arg; } -#endif -char argtyp2(CSOUND *csound, char *s) +char argtyp2(char *s) { /* find arg type: d, w, a, k, i, c, p, r, S, B, b, t */ char c = *s; /* also set lgprevdef if !c && !p && !S */ - /* VL: added this to make sure the object exists before we try to read - from it */ - if (UNLIKELY(csound->otranGlobals == NULL)) { - csound->otranGlobals = csound->Calloc(csound, sizeof(OTRAN_GLOBALS)); - } - /* csound->Message(csound, "\nArgtyp2: received %s\n", s); */ - - /*trap this before parsing for a number! */ + /* trap this before parsing for a number! */ /* two situations: defined at header level: 0dbfs = 1.0 * and returned as a value: idb = 0dbfs */ + if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || (c == '0' && strcmp(s, "0dbfs") != 0)) return('c'); /* const */ @@ -1832,7 +1942,6 @@ return('p'); /* pnum */ if (c == '"') return('S'); /* quoted String */ - ST(lgprevdef) = lgexist2(csound, s); /* (lgprev) */ if (strcmp(s,"sr") == 0 || strcmp(s,"kr") == 0 || strcmp(s,"0dbfs") == 0 || strcmp(s,"nchnls_i") == 0 || strcmp(s,"ksmps") == 0 || strcmp(s,"nchnls") == 0) @@ -1843,16 +1952,24 @@ c = *(++s); if (c == 'g') c = *(++s); + if (c == '[') { + while(c == '[') { + c = *(++s); + } + } + if (c == 't') { /* Support legacy t-vars by mapping to k subtypes */ + return 'k'; + } if (strchr("akiBbfSt", c) != NULL) return(c); else return('?'); } /* For diagnostics map file name or macro name to an index */ -int file_to_int(CSOUND *csound, const char *name) +uint8_t file_to_int(CSOUND *csound, const char *name) { - extern char *strdup(const char *); - int n = 0; + //extern char *strdup(const char *); + uint8_t n = 0; char **filedir = csound->filedir; while (filedir[n] && n<63) { /* Do we have it already? */ if (strcmp(filedir[n], name)==0) return n; /* yes */ @@ -1861,7 +1978,6 @@ // Not there so add // ensure long enough? if (n==63) { - //csound->Die(csound, "Too many file/macros\n"); filedir[n] = strdup("**unknown**"); } else { @@ -1870,3 +1986,70 @@ } return n; } + +void debugPrintCsound(CSOUND* csound) +{ + INSTRTXT *current; + CONS_CELL* val = cs_hash_table_keys(csound, csound->engineState.stringPool); + int count = 0; + csound->Message(csound, "Compile State:\n"); + csound->Message(csound, "String Pool:\n"); + + while(val != NULL) { + csound->Message(csound, " %d) %s\n", count++, val->value); + val = val->next; + } + csound->Message(csound, "Constants Pool:\n"); + count = 0; + for(count = 0; count < csound->engineState.constantsPool->count; count++) { + csound->Message(csound, " %d) %f\n", + count, csound->engineState.constantsPool->values[count]); + } + + csound->Message(csound, "Global Variables:\n"); + CS_VARIABLE* gVar = csound->engineState.varPool->head; + count = 0; + while(gVar != NULL) { + csound->Message(csound, " %d) %s:%s\n", count++, + gVar->varName, gVar->varType->varTypeName); + gVar = gVar->next; + } + + /* bad practice to declare variables in middle of block */ + current = &(csound->engineState.instxtanchor); + current = current->nxtinstxt; + count = 0; + while (current != NULL) { + csound->Message(csound, "Instrument %d %p %p\n", + count, current, current->nxtinstxt); + csound->Message(csound, "Variables\n"); + + if (current->varPool != NULL) { + CS_VARIABLE* var = current->varPool->head; + int index = 0; + while (var != NULL) { + if (var->varType == &CS_VAR_TYPE_ARRAY) { + csound->Message(csound, " %d) %s:[%s]\n", index++, + var->varName, var->subType->varTypeName); + } else { + csound->Message(csound, " %d) %s:%s\n", index++, + var->varName, var->varType->varTypeName); + } + + var = var->next; + } + } + count++; + current = current->nxtinstxt; + } +} + + +#include "interlocks.h" +void query_deprecated_opcode(CSOUND *csound, ORCTOKEN *o) +{ + char *name = o->lexeme; + OENTRY *ep = find_opcode(csound, name); + if (ep->flags&_QQ) + csound->Warning(csound, Str("Opcode \"%s\" is deprecated\n"), name); +} diff -Nru csound-5.17.11~dfsg/Engine/csound_orc_expressions.c csound-6.02~dfsg/Engine/csound_orc_expressions.c --- csound-5.17.11~dfsg/Engine/csound_orc_expressions.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc_expressions.c 2014-01-07 16:53:47.000000000 +0000 @@ -24,31 +24,72 @@ #include "csoundCore.h" #include "csound_orc.h" +#include "csound_orc_expressions.h" +#include "csound_type_system.h" +#include "csound_orc_semantics.h" -extern char argtyp2(CSOUND *, char *); +extern char argtyp2(char *); extern void print_tree(CSOUND *, char *, TREE *); -extern void handle_polymorphic_opcode(CSOUND*, TREE *); extern void handle_optional_args(CSOUND *, TREE *); extern ORCTOKEN *make_token(CSOUND *, char *); extern ORCTOKEN *make_label(CSOUND *, char *); -extern int find_opcode(CSOUND *csound, char *opname); +extern OENTRIES* find_opcode2(CSOUND *, char*); +extern char* resolve_opcode_get_outarg(CSOUND* , OENTRIES* , char*); +extern TREE* appendToTree(CSOUND * csound, TREE *first, TREE *newlast); +extern char* get_arg_string_from_tree(CSOUND* csound, TREE* tree, + TYPE_TABLE* typeTable); +extern void add_arg(CSOUND* csound, char* varName, TYPE_TABLE* typeTable); +extern void add_array_arg(CSOUND* csound, char* varName, int dimensions, + TYPE_TABLE* typeTable); + +extern char* get_array_sub_type(CSOUND* csound, char*); + +extern char* convert_external_to_internal(CSOUND* csound, char* arg); + + +TREE* create_boolean_expression(CSOUND*, TREE*, int, int, TYPE_TABLE*); +TREE * create_expression(CSOUND *, TREE *, int, int, TYPE_TABLE*); +char *check_annotated_type(CSOUND* csound, OENTRIES* entries, + char* outArgTypes); -TREE* create_boolean_expression(CSOUND*, TREE*, int, int); -TREE * create_expression(CSOUND *, TREE *, int, int); static int genlabs = 300; -char *create_out_arg(CSOUND *csound, char outype) +TREE* tree_tail(TREE* node) { + TREE* t = node; + if (t == NULL) { + return NULL; + } + while(t->next != NULL) { + t = t->next; + } + return t; +} + +char *create_out_arg(CSOUND *csound, char* outype, TYPE_TABLE* typeTable) { char* s = (char *)csound->Malloc(csound, 16); - switch(outype) { + + switch(*outype) { case 'a': sprintf(s, "#a%d", csound->acount++); break; case 'K': case 'k': sprintf(s, "#k%d", csound->kcount++); break; case 'B': sprintf(s, "#B%d", csound->Bcount++); break; case 'b': sprintf(s, "#b%d", csound->bcount++); break; + case 'f': sprintf(s, "#f%d", csound->tcount++); break; + case 't': sprintf(s, "#k%d", csound->tcount++); break; + case 'S': sprintf(s, "#S%d", csound->tcount++); break; + case '[': sprintf(s, "#%c%d[]", outype[1], csound->tcount++); + break; // piggyback on tcount default: sprintf(s, "#i%d", csound->icount++); break; } + + if (*outype == '[') { + add_array_arg(csound, s, 1, typeTable); + } else { + add_arg(csound, s, typeTable); + } + return s; } @@ -56,33 +97,21 @@ * Handles expression opcode type, appending to passed in opname * returns outarg type */ -char *set_expression_type(CSOUND *csound, char * op, char arg1, char arg2) + +//FIXME - need to remove using this function, should not be necessary with +// using new type system code +char *set_expression_type(CSOUND *csound, char * op, char arg1, char arg2, + TYPE_TABLE* typeTable) { - char outype, *s; + char *outype, *s; + OENTRIES* oentries; - if (arg1 == 'a') { - if (arg2 == 'a') { - strncat(op,".aa",80); - } - else { - strncat(op,".ak",80); - } - outype = 'a'; - } - else if (arg2 == 'a') { - strncat(op,".ka",80); - outype = 'a'; - } - else if (arg1 == 'k' || arg2 == 'k') { - strncat(op,".kk",80); - outype = 'k'; - } - else { - strncat(op,".ii",80); - outype = 'i'; - } + oentries = find_opcode2(csound, op); + char args[3] = { arg1, arg2, '\0' }; - s = create_out_arg(csound, outype); + outype = resolve_opcode_get_outarg(csound, oentries, args); + + s = create_out_arg(csound, outype, typeTable); if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "SET_EXPRESSION_TYPE: %s : %s\n", op, s); @@ -98,25 +127,6 @@ return s; } -int get_expression_ans_type(CSOUND * csound, char * ans) -{ - char * t = ans; - t++; - - switch(*t) { - case 'a': - return T_IDENT_A; - case 'k': - return T_IDENT_K; - case 'B': - return T_IDENT_B; - case 'b': - return T_IDENT_b; - default: - return T_IDENT_I; - } -} - TREE *create_empty_token(CSOUND *csound) { TREE *ans; @@ -131,6 +141,8 @@ ans->next = NULL; ans->len = 0; ans->rate = -1; + ans->line = 0; + ans->locn = 0; ans->value = NULL; return ans; } @@ -168,7 +180,7 @@ { TREE *ans = create_empty_token(csound); - ans->type = get_expression_ans_type(csound, var); + ans->type = T_IDENT; ans->value = make_token(csound, var); ans->value->type = ans->type; @@ -179,32 +191,32 @@ TREE * create_goto_token(CSOUND *csound, char * booleanVar, TREE * gotoNode, int type) { -/* TREE *ans = create_empty_token(csound); */ - char* op = (char *)csound->Malloc(csound, 7); /* Unchecked */ + /* TREE *ans = create_empty_token(csound); */ + char* op = (char *)csound->Malloc(csound, 8); /* Unchecked */ TREE *opTree, *bVar; switch(gotoNode->type) { case KGOTO_TOKEN: - sprintf(op, "ckgoto"); + strncpy(op, "ckgoto", 8); break; case IGOTO_TOKEN: - sprintf(op, "cigoto"); + strncpy(op, "cigoto", 8); break; case ITHEN_TOKEN: - sprintf(op, "cngoto"); + strncpy(op, "cingoto", 8); break; case THEN_TOKEN: case KTHEN_TOKEN: - sprintf(op, "cngoto"); + strncpy(op, "cngoto", 8); break; default: - if (type) sprintf(op, "ckgoto"); - else sprintf(op, "cggoto"); + if (type) strncpy(op, "ckgoto", 8); + else strncpy(op, "cggoto", 8); } opTree = create_opcode_token(csound, op); bVar = create_empty_token(csound); - bVar->type = (type ? T_IDENT_B : T_IDENT_b); + bVar->type = T_IDENT; //(type ? T_IDENT_B : T_IDENT_b); bVar->value = make_token(csound, booleanVar); bVar->value->type = bVar->type; @@ -222,7 +234,7 @@ char* op = (char *)csound->Calloc(csound, 6); TREE * opTree; char *gt[3] = {"kgoto", "igoto", "goto"}; - sprintf(op, gt[type]); /* kgoto, igoto, goto ?? */ + strncpy(op, gt[type],6); /* kgoto, igoto, goto ?? */ opTree = create_opcode_token(csound, op); opTree->left = NULL; opTree->right = label; @@ -231,7 +243,7 @@ } /* Returns true if passed in TREE node is a numerical expression */ -static int is_expression_node(TREE *node) +int is_expression_node(TREE *node) { if (node == NULL) { return 0; @@ -253,14 +265,14 @@ case '#': case '~': case '?': - case S_TABREF: + case T_ARRAY: return 1; } - return 0; + return 0; } /* Returns if passed in TREE node is a boolean expression */ -static int is_boolean_expression_node(TREE *node) +int is_boolean_expression_node(TREE *node) { if (node == NULL) { return 0; @@ -280,22 +292,27 @@ return 0; } -static TREE *create_cond_expression(CSOUND *csound, TREE *root, int line, int locn) +static TREE *create_cond_expression(CSOUND *csound, + TREE *root, int line, int locn, + TYPE_TABLE* typeTable) { - char *op = (char*)mmalloc(csound, 4), arg1, arg2, ans, *outarg = NULL; - char outype; - TREE *anchor = create_boolean_expression(csound, root->left, line, locn); + char *arg1, *arg2, *ans, *outarg = NULL; + char* outype; + TREE *anchor = create_boolean_expression(csound, root->left, line, locn, + typeTable); TREE *last; TREE * opTree; TREE *b; TREE *c = root->right->left, *d = root->right->right; last = anchor; + char condInTypes[64]; + while (last->next != NULL) { last = last->next; } b= create_ans_token(csound, last->left->value->lexeme); if (is_expression_node(c)) { - last->next = create_expression(csound, c, line, locn); + last->next = create_expression(csound, c, line, locn, typeTable); /* TODO - Free memory of old left node freetree */ last = last->next; @@ -305,7 +322,7 @@ c = create_ans_token(csound, last->left->value->lexeme); } if (is_expression_node(d)) { - last->next = create_expression(csound, d, line, locn); + last->next = create_expression(csound, d, line, locn, typeTable); /* TODO - Free memory of old left node freetree */ last = last->next; @@ -315,24 +332,17 @@ d = create_ans_token(csound, last->left->value->lexeme); } - arg1 = argtyp2(csound, c->value->lexeme); - arg2 = argtyp2(csound, d->value->lexeme); - ans = argtyp2(csound, b->value->lexeme); - if (arg1 == 'a' || arg2 == 'a') { - strcpy(op,":a"); - outype = 'a'; - } - else if (arg1 == 'k' || arg2 == 'k' || ans == 'B') { - strcpy(op,":k"); - outype = 'k'; - } - else { - strcpy(op,":i"); - outype = 'i'; - } + arg1 = get_arg_type2(csound, c, typeTable); + arg2 = get_arg_type2(csound, d, typeTable); + ans = get_arg_type2(csound, b, typeTable); - outarg = create_out_arg(csound, outype); - opTree = create_opcode_token(csound, op); + sprintf(condInTypes, "%s%s%s", ans, arg1, arg2); + + OENTRIES* entries = find_opcode2(csound, ":cond"); + outype = resolve_opcode_get_outarg(csound, entries, condInTypes); + + outarg = create_out_arg(csound, outype, typeTable); + opTree = create_opcode_token(csound, cs_strdup(csound, ":cond")); opTree->left = create_ans_token(csound, outarg); opTree->right = b; opTree->right->next = c; @@ -343,170 +353,250 @@ // print_tree(csound, "Answer:\n", anchor); return anchor; } + +char* create_out_arg_for_expression(CSOUND* csound, char* op, TREE* left, + TREE* right, TYPE_TABLE* typeTable) { + char* outType; + + OENTRIES* opentries = find_opcode2(csound, op); + + char* leftArgType = get_arg_string_from_tree(csound, left, typeTable); + char* rightArgType = get_arg_string_from_tree(csound, right, typeTable); + char* argString = mcalloc(csound, 80); + + strncpy(argString, leftArgType, 80); + strncat(argString, rightArgType, 80 - strlen(leftArgType)); + outType = resolve_opcode_get_outarg(csound, opentries, argString); + if(outType == NULL) return NULL; + + outType = convert_external_to_internal(csound, outType); + + return create_out_arg(csound, outType, typeTable); +} + /** * Create a chain of Opcode (OPTXT) text from the AST node given. Called from * create_opcode when an expression node has been found as an argument */ -TREE * create_expression(CSOUND *csound, TREE *root, int line, int locn) +TREE * create_expression(CSOUND *csound, TREE *root, int line, int locn, + TYPE_TABLE* typeTable) { - char *op, arg1, arg2, c, *outarg = NULL; + char *op, *outarg = NULL; TREE *anchor = NULL, *last; - TREE * opTree; - int opnum; + TREE * opTree, *current, *newArgList; + OENTRIES* opentries; /* HANDLE SUB EXPRESSIONS */ - if (root->type=='?') return create_cond_expression(csound, root, line, locn); + if (root->type=='?') return create_cond_expression(csound, root, line, + locn, typeTable); - if (is_expression_node(root->left)) { - anchor = create_expression(csound, root->left, line, locn); - - /* TODO - Free memory of old left node - freetree */ - last = anchor; - while (last->next != NULL) { - last = last->next; + current = root->left; + newArgList = NULL; + while(current != NULL) { + if (is_expression_node(current)) { + TREE* newArg; + + anchor = appendToTree(csound, anchor, + create_expression(csound, current, line, locn, + typeTable)); + last = tree_tail(anchor); + newArg = create_ans_token(csound, last->left->value->lexeme); + newArgList = appendToTree(csound, newArgList, newArg); + current = current->next; + } else { + TREE* temp; + newArgList = appendToTree(csound, newArgList, current); + temp = current->next; + current->next = NULL; + current = temp; } - root->left = create_ans_token(csound, last->left->value->lexeme); - } - if (is_expression_node(root->right)) { - TREE * newRight = create_expression(csound, root->right, line, locn); - if (anchor == NULL) { - anchor = newRight; + } + root->left = newArgList; + + current = root->right; + newArgList = NULL; + while(current != NULL) { + if (is_expression_node(current)) { + TREE* newArg; + + anchor = appendToTree(csound, anchor, + create_expression(csound, current, line, + locn, typeTable)); + last = tree_tail(anchor); + + newArg = create_ans_token(csound, last->left->value->lexeme); + newArgList = appendToTree(csound, newArgList, newArg); + current = current->next; } else { - last = anchor; - while (last->next != NULL) { - last = last->next; - } - last->next = newRight; + TREE* temp; + newArgList = appendToTree(csound, newArgList, current); + temp = current->next; + current->next = NULL; + current = temp; } - last = newRight; - - while (last->next != NULL) { - last = last->next; - } - /* TODO - Free memory of old right node - freetree */ - root->right = create_ans_token(csound, last->left->value->lexeme); - } - arg1 = '\0'; - if (root->left != NULL) { - arg1 = argtyp2(csound, root->left->value->lexeme); } - arg2 = argtyp2(csound, root->right->value->lexeme); + root->right = newArgList; op = mcalloc(csound, 80); - switch(root->type) { + switch(root->type) { case '+': - strncpy(op, "add", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##add", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '-': - strncpy(op, "sub", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##sub", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '*': - strncpy(op, "mul", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##mul", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '%': - strncpy(op, "mod", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##mod", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '/': - strncpy(op, "div", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##div", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '^': - { int outype = 'i'; - strncpy(op, "pow.", 80); - if (arg1 == 'a' || arg2 == 'a') { - strncat(op, "a", 80); - outype = (arg1 == 'a' ? arg1 : arg2); + strncpy(op, "pow", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); + break; + case T_FUNCTION: + { + char* outtype; + op = cs_strdup(csound, root->value->lexeme); + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Found OP: %s\n", op); + + opentries = find_opcode2(csound, root->value->lexeme); + if (opentries->count == 0) { + csound->Warning(csound, + Str("error: function %s not found, " + "line %d \n"), + root->value->lexeme, line); + outtype = "i"; } - else if (arg1 == 'k' || arg2 == 'k') { - strncat(op, "k", 80); - outype = (arg1 == 'k' ? arg1 : arg2); + else { + char* inArgTypes = + get_arg_string_from_tree(csound, root->right, typeTable); + if (root->value->optype != NULL) + outtype = + check_annotated_type(csound, opentries, root->value->optype); + /* if there are type annotations */ + else outtype = + resolve_opcode_get_outarg(csound, opentries, inArgTypes); } - else - strncat(op, "i", 80); - outarg = create_out_arg(csound, outype); - } - break; - case S_TABREF: - strncpy(op, "##tabref", 80); - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found TABREF: %s\n", op); - outarg = create_out_arg(csound, 'k'); - break; - case T_FUNCTION: /* assumes on single arg input */ - c = arg2; - if (c == 'p' || c == 'c') c = 'i'; - sprintf(op, "%s.%c", root->value->lexeme, c); - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found OP: %s\n", op); - /* VL: some non-existing functions were appearing here - looking for opcodes that did not exist */ - if ((opnum = find_opcode(csound, op))==0) { - /* This is a little like overkill */ - strncpy(op, "##error", 80); - opnum = find_opcode(csound, op); - csound->Warning(csound, - Str("error: function %s with arg type %c not found, " - "line %d \n"), - root->value->lexeme, c, line); + if (outtype == NULL) { + csound->Warning(csound, + Str("error: opcode %s with output type %s not found, " + "line %d"), + root->value->lexeme, root->value->optype, line); + outtype = "i"; + } + outarg = create_out_arg(csound, outtype, typeTable); + } - c = csound->opcodlst[opnum].outypes[0]; - outarg = create_out_arg(csound, c); break; case S_UMINUS: if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "HANDLING UNARY MINUS!"); root->left = create_minus_token(csound); - arg1 = 'i'; - strncpy(op, "mul", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + // arg1 = 'i'; + strncpy(op, "##mul", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); + break; case '|': - strncpy(op, "or", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##or", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '&': - strncpy(op, "and", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##and", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case S_BITSHIFT_RIGHT: - strncpy(op, "shr", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##shr", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case S_BITSHIFT_LEFT: - strncpy(op, "shl", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##shl", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '#': - strncpy(op, "xor", 80); - outarg = set_expression_type(csound, op, arg1, arg2); + strncpy(op, "##xor", 80); + outarg = create_out_arg_for_expression(csound, op, root->left, + root->right, typeTable); break; case '~': - { int outype = 'i'; - strncpy(op, "not.", 80); - if (arg2 == 'a') { - strncat(op, "a", 80); - outype = 'a'; - } - else if (arg2 == 'k') { - strncat(op, "k", 80); - outype = 'k'; - } - else - strncat(op, "i", 80); - outarg = create_out_arg(csound, outype); + { + strncpy(op, "##not", 80); + + opentries = find_opcode2(csound, op); + + char* rightArgType = get_arg_string_from_tree(csound, root->right, + typeTable); + char* outype = resolve_opcode_get_outarg(csound, opentries, + rightArgType); + outarg = create_out_arg(csound, outype, typeTable); + } break; + case T_ARRAY: + strncpy(op, "##array_get", 80); + + char* leftArgType = + get_arg_string_from_tree(csound, root->left, typeTable); + + //FIXME: this is sort of hackish as it's checking and arg + // string; should use a function to get the CS_TYPE of the var + // instead + if (strlen(leftArgType) > 1 && leftArgType[1] == '[') { + outarg = create_out_arg(csound, + get_array_sub_type(csound, + root->left->value->lexeme), + typeTable); + } else { + + opentries = find_opcode2(csound, op); + + char* rightArgType = get_arg_string_from_tree(csound, root->right, + typeTable); + + char* argString = strcat(leftArgType, rightArgType); + + char* outype = resolve_opcode_get_outarg(csound, opentries, + argString); + + // free(argString); + + if (outype == NULL) { + return NULL; + } + outarg = create_out_arg(csound, outype, typeTable); + + } + + break; + } opTree = create_opcode_token(csound, op); + if(root->value) opTree->value->optype = root->value->optype; if (root->left != NULL) { opTree->right = root->left; opTree->right->next = root->right; @@ -520,8 +610,7 @@ opTree->left = create_ans_token(csound, outarg); opTree->line = line; opTree->locn = locn; - } - + } if (anchor == NULL) { anchor = opTree; } @@ -540,17 +629,18 @@ * Create a chain of Opcode (OPTXT) text from the AST node given. Called from * create_opcode when an expression node has been found as an argument */ -TREE * create_boolean_expression(CSOUND *csound, TREE *root, int line, int locn) +TREE * create_boolean_expression(CSOUND *csound, TREE *root, int line, int locn, + TYPE_TABLE* typeTable) { char *op, *outarg; TREE *anchor = NULL, *last; TREE * opTree; - /* if (UNLIKELY(PARSER_DEBUG)) */ - csound->Message(csound, "Creating boolean expression\n"); + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Creating boolean expression\n"); /* HANDLE SUB EXPRESSIONS */ if (is_boolean_expression_node(root->left)) { - anchor = create_boolean_expression(csound, root->left, line, locn); + anchor = create_boolean_expression(csound, root->left, line, locn, typeTable); last = anchor; while (last->next != NULL) { last = last->next; @@ -559,7 +649,7 @@ freetree */ root->left = create_ans_token(csound, last->left->value->lexeme); } else if (is_expression_node(root->left)) { - anchor = create_expression(csound, root->left, line, locn); + anchor = create_expression(csound, root->left, line, locn, typeTable); /* TODO - Free memory of old left node freetree */ @@ -572,7 +662,9 @@ if (is_boolean_expression_node(root->right)) { - TREE * newRight = create_boolean_expression(csound, root->right, line, locn); + TREE * newRight = create_boolean_expression(csound, + root->right, line, locn, + typeTable); if (anchor == NULL) { anchor = newRight; } @@ -593,7 +685,8 @@ root->right = create_ans_token(csound, last->left->value->lexeme); } else if (is_expression_node(root->right)) { - TREE * newRight = create_expression(csound, root->right, line, locn); + TREE * newRight = create_expression(csound, root->right, line, + locn, typeTable); if (anchor == NULL) { anchor = newRight; } @@ -647,16 +740,17 @@ if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "Operator Found: %s (%c %c)\n", op, - argtyp2(csound, root->left->value->lexeme), - argtyp2(csound, root->right->value->lexeme)); + argtyp2( root->left->value->lexeme), + argtyp2( root->right->value->lexeme)); outarg = get_boolean_arg( csound, - argtyp2(csound, root->left->value->lexeme) =='k' || - argtyp2(csound, root->right->value->lexeme)=='k' || - argtyp2(csound, root->left->value->lexeme) =='B' || - argtyp2(csound, root->right->value->lexeme)=='B'); + argtyp2( root->left->value->lexeme) =='k' || + argtyp2( root->right->value->lexeme)=='k' || + argtyp2( root->left->value->lexeme) =='B' || + argtyp2( root->right->value->lexeme)=='B'); + add_arg(csound, outarg, typeTable); opTree = create_opcode_token(csound, op); opTree->right = root->left; opTree->right->next = root->right; @@ -681,7 +775,7 @@ char *label = (char *)csound->Calloc(csound, 20); ORCTOKEN *token; - sprintf(label, "__synthetic_%ld", count); + sprintf(label, "__synthetic_%ld", (long)count); if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "Creating Synthetic T_IDENT: %s\n", label); token = make_token(csound, label); @@ -693,479 +787,502 @@ { char *label = (char *)csound->Calloc(csound, 20); - sprintf(label, "__synthetic_%ld:", count); + sprintf(label, "__synthetic_%ld:", (long)count); if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "Creating Synthetic label: %s\n", label); return make_leaf(csound, -1, 0, LABEL_TOKEN, make_label(csound, label)); } -/* Expands expression nodes into opcode calls - * - * - * for if-goto, expands to: - * 1. Expression nodes - all of the expressions that lead to the boolean var - * 2. goto node - a conditional goto to evals the boolean var and goes to a - * label - * - * for if-then-elseif-else, expands to: - * 1. for each conditional, converts to a set of: - * -expression nodes - * -conditional not-goto that goes to block end label if condition does - * not pass (negative version of conditional is used to conditional skip - * contents of block) - * -statements (body of within conditional block) - * -goto complete block end (this signifies that at the end of these - * statements, skip all other elseif or else branches and go to very end) - * -block end label - * 2. for else statements found, do no conditional and just link in statements - * - * */ - -TREE *csound_orc_expand_expressions(CSOUND * csound, TREE *root) -{ - // int32 labelCounter = 300L; +/* returns the head of a list of TREE* nodes, expanding all RHS + expressions into statements prior to the original statement line, + and LHS expressions (array sets) after the original statement + line */ +TREE* expand_statement(CSOUND* csound, TREE* current, TYPE_TABLE* typeTable) { + /* This is WRONG in optional argsq */ + TREE* anchor = NULL; + TREE* originalNext = current->next; - TREE *anchor = NULL; - TREE * expressionNodes = NULL; + TREE* previousArg = NULL; + TREE* currentArg = current->right; - TREE *current = root; - TREE *previous = NULL; + current->next = NULL; if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "[Begin Expanding Expressions in AST]\n"); - - while (current != NULL) { - switch(current->type) { - case INSTR_TOKEN: - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Instrument found\n"); - current->right = csound_orc_expand_expressions(csound, current->right); - //print_tree(csound, "AFTER", current); - break; - case UDO_TOKEN: - if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "UDO found\n"); - current->right = csound_orc_expand_expressions(csound, current->right); - break; - case IF_TOKEN: - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found IF statement\n"); - { - TREE * left = current->left; - TREE * right = current->right; - TREE* last; - TREE * gotoToken; - - if (right->type == IGOTO_TOKEN || - right->type == KGOTO_TOKEN || - right->type == GOTO_TOKEN) { + csound->Message(csound, "Found Statement.\n"); + while (currentArg != NULL) { + TREE* last; + TREE *nextArg; + TREE *newArgTree; + TREE *expressionNodes; + int is_bool = 0; + if (is_expression_node(currentArg) || + (is_bool = is_boolean_expression_node(currentArg))) { + char * newArg; if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found if-goto\n"); - expressionNodes = - create_boolean_expression(csound, left, right->line, right->locn); - /* Set as anchor if necessary */ - if (anchor == NULL) { - anchor = expressionNodes; - } - /* reconnect into chain */ - last = expressionNodes; - while (last->next != NULL) { - last = last->next; + csound->Message(csound, "Found Expression.\n"); + if (is_bool == 0) { + expressionNodes = + create_expression(csound, currentArg, + currentArg->line, currentArg->locn, typeTable); } - if (previous != NULL) { - previous->next = expressionNodes; + else { + expressionNodes = + create_boolean_expression(csound, currentArg, + currentArg->line, currentArg->locn, + typeTable); } - gotoToken = create_goto_token(csound, - last->left->value->lexeme, - right, - last->left->type == 'k' || - right->type =='k'); - last->next = gotoToken; - gotoToken->next = current->next; - current = gotoToken; - previous = last; - } - else if (right->type == THEN_TOKEN || - right->type == ITHEN_TOKEN || - right->type == KTHEN_TOKEN) { - int endLabelCounter = -1; - TREE *tempLeft; - TREE *tempRight; - TREE *ifBlockStart = NULL; - TREE *ifBlockCurrent = current; - TREE *ifBlockLast = NULL; + /* Set as anchor if necessary */ + + anchor = appendToTree(csound, anchor, expressionNodes); + + /* reconnect into chain */ + last = tree_tail(expressionNodes); + + newArg = last->left->value->lexeme; if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found if-then\n"); - if (right->next != NULL) { - endLabelCounter = genlabs++; - } + csound->Message(csound, "New Arg: %s\n", newArg); - while (ifBlockCurrent != NULL) { - tempLeft = ifBlockCurrent->left; - tempRight = ifBlockCurrent->right; - if (ifBlockCurrent->type == ELSE_TOKEN) { - // print_tree(csound, "ELSE case\n", ifBlockCurrent); - ifBlockLast->next = - csound_orc_expand_expressions(csound, tempRight); - while (ifBlockLast->next != NULL) { - ifBlockLast = ifBlockLast->next; - } - // print_tree(csound, "ELSE transformed\n", ifBlockCurrent); - break; - } - else if (ifBlockCurrent->type == ELSEIF_TOKEN) { /* JPff code */ - // print_tree(csound, "ELSEIF case\n", ifBlockCurrent); - ifBlockCurrent->type = IF_TOKEN; - ifBlockCurrent = make_node(csound, ifBlockCurrent->line, - ifBlockCurrent->locn, ELSE_TOKEN, - NULL, ifBlockCurrent); - //tempLeft = NULL; - /* ifBlockLast->next = */ - /* csound_orc_expand_expressions(csound, ifBlockCurrent); */ - /* while (ifBlockLast->next != NULL) { */ - /* ifBlockLast = ifBlockLast->next; */ - /* } */ - // print_tree(csound, "ELSEIF transformed\n", ifBlockCurrent); - //break; - } - - expressionNodes = - create_boolean_expression(csound, tempLeft, - tempLeft->line, tempLeft->locn); - /* Set as anchor if necessary */ - if (ifBlockStart == NULL) { - ifBlockStart = expressionNodes; - } - /* reconnect into chain */ - { - TREE* last = expressionNodes; - TREE *statements, *label, *labelEnd, *gotoToken; - int gotoType; - - while (last->next != NULL) { - last = last->next; - } - if (ifBlockLast != NULL) { - ifBlockLast->next = expressionNodes; - } - - statements = tempRight->right; - label = create_synthetic_ident(csound, genlabs); - labelEnd = create_synthetic_label(csound, genlabs++); - tempRight->right = label; -// printf("goto types %c %c %c %c %d\n", -// expressionNodes->left->type, tempRight->type, -// argtyp2(csound, last->left->value->lexeme), -// argtyp2(csound, tempRight->value->lexeme), -// (argtyp2(csound, last->left->value->lexeme) == 'k') || -// (argtyp2(csound, tempRight->value->lexeme) == 'k')); -// print_tree(csound, "expression nodes", expressionNodes); - gotoType = (argtyp2(csound, last->left->value->lexeme) == 'B') || - (argtyp2(csound, tempRight->value->lexeme) == 'k'); - gotoToken = - create_goto_token(csound, - last->left->value->lexeme, - tempRight, - gotoType); - /* relinking */ - last->next = gotoToken; - gotoToken->next = statements; - /* VL: added as means of dealing with empty conditionals, - may need revision */ - if(statements == NULL) - csound->Die(csound, - Str("error: non-existent statement in " - "conditional, line %d \n"), - last->right->line); - while (statements->next != NULL) { - statements = statements->next; - } - if (endLabelCounter > 0) { - TREE *endLabel = create_synthetic_ident(csound, - endLabelCounter); - int type = (gotoType == 1) ? 0 : 2; - /* csound->DebugMsg(csound, "%s(%d): type = %d %d\n", */ - /* __FILE__, __LINE__, type, gotoType); */ - TREE *gotoEndLabelToken = - create_simple_goto_token(csound, endLabel, type); - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Creating simple goto token\n"); - - statements->next = gotoEndLabelToken; - gotoEndLabelToken->next = labelEnd; - } - else { - statements->next = labelEnd; - } - - ifBlockLast = labelEnd; - ifBlockCurrent = tempRight->next; - } - } + /* handle arg replacement of currentArg here */ + nextArg = currentArg->next; + newArgTree = create_ans_token(csound, newArg); - if (endLabelCounter > 0) { - TREE *endLabel = create_synthetic_label(csound, - endLabelCounter); - endLabel->next = ifBlockLast->next; - ifBlockLast->next = endLabel; - ifBlockLast = endLabel; + if (previousArg == NULL) { + current->right = newArgTree; } - ifBlockLast->next = current->next; - - /* Connect in all of the TREE nodes that were flattened from - * the if-else-else block - */ - /* Set as anchor if necessary */ - if (anchor == NULL) { - anchor = ifBlockStart; + else { + previousArg->next = newArgTree; } - /* reconnect into chain */ - if (previous != NULL) { - previous->next = ifBlockStart; - } - current = ifBlockStart; + newArgTree->next = nextArg; + currentArg = newArgTree; + /* TODO - Delete the expression nodes here */ + } + + previousArg = currentArg; + currentArg = currentArg->next; + } + + anchor = appendToTree(csound, anchor, current); + + + // handle LHS expressions (i.e. array-set's) + previousArg = NULL; + currentArg = current->left; + + while (currentArg != NULL) { + TREE* temp; + + if (currentArg->type == T_ARRAY) { + char *outType; + char* leftArgType = + get_arg_string_from_tree(csound, currentArg->left, typeTable); + + //FIXME: this is sort of hackish as it's checking and arg + // string; should use a function to get the CS_TYPE of the + // var instead + if (strlen(leftArgType) > 1 && leftArgType[1] == '[') { + outType = get_array_sub_type(csound, + currentArg->left->value->lexeme); } else { - csound->Message(csound, - "ERROR: Neither if-goto or if-then found on line %d!!!", - right->line); + // FIXME - this is hardcoded to "k" for now. The problem + // here is that this body of code is essentially looking + // for what type to use for the synthesized in-type. I + // think the solution is to use the types from the opcode + // that this LHS array_set is being used with, but this is + // not implemented. + +// OENTRIES* opentries = find_opcode2(csound, "##array_set"); +// +// char* rightArgType = get_arg_string_from_tree(csound, +// currentArg->right, +// typeTable); +// +// char* argString = strcat(leftArgType, rightArgType); +// argString = strcat(argString, "k"); +// FIXME - this is hardcoding a k input for what would be the in arg type +// +// outType = resolve_opcode_get_outarg(csound, opentries, +// argString); + + outType = "k"; + // free(argString); + +// if (outType == NULL) { +// return NULL; +// } + } + + temp = create_ans_token(csound, + create_out_arg(csound, outType, typeTable)); + + if (previousArg == NULL) { + current->left = temp; } - break; - case UNTIL_TOKEN: - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found UNTIL statement\n"); + else { + previousArg->next = temp; + } + temp->next = currentArg->next; + + TREE* arraySet = create_opcode_token(csound, "##array_set"); + arraySet->right = currentArg->left; + arraySet->right->next = + make_leaf(csound, temp->line, temp->locn, + T_IDENT, make_token(csound, + temp->value->lexeme)); + arraySet->right->next->next = + currentArg->right; // TODO - check if this handles expressions + + anchor = appendToTree(csound, anchor, arraySet); + + currentArg = temp; + + } + previousArg = currentArg; + currentArg = currentArg->next; + } + + handle_optional_args(csound, current); + + appendToTree(csound, anchor, originalNext); + + return anchor; +} + +/* Flattens one level of if-blocks, sub-if-blocks should get flattened + when the expander goes through statements */ +TREE* expand_if_statement(CSOUND* csound, + TREE* current, TYPE_TABLE* typeTable) { + + TREE* anchor = NULL; + TREE* expressionNodes = NULL; + + TREE* left = current->left; + TREE* right = current->right; + TREE* last; + TREE* gotoToken; + + if (right->type == IGOTO_TOKEN || + right->type == KGOTO_TOKEN || + right->type == GOTO_TOKEN) { + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Found if-goto\n"); + expressionNodes = + create_boolean_expression(csound, left, right->line, + right->locn, typeTable); + + + anchor = appendToTree(csound, anchor, expressionNodes); + + /* reconnect into chain */ + last = tree_tail(expressionNodes); + + gotoToken = create_goto_token(csound, + last->left->value->lexeme, + right, + last->left->type == 'k' || + right->type =='k'); + last->next = gotoToken; + gotoToken->next = current->next; + } + else if (right->type == THEN_TOKEN || + right->type == ITHEN_TOKEN || + right->type == KTHEN_TOKEN) { + int endLabelCounter = -1; + TREE *tempLeft; + TREE *tempRight; + TREE* last; + + TREE *ifBlockCurrent = current; + + if (UNLIKELY(PARSER_DEBUG)) + csound->Message(csound, "Found if-then\n"); + if (right->next != NULL) { + endLabelCounter = genlabs++; + } + + while (ifBlockCurrent != NULL) { + tempLeft = ifBlockCurrent->left; + tempRight = ifBlockCurrent->right; + + if (ifBlockCurrent->type == ELSE_TOKEN) { + appendToTree(csound, anchor, tempRight); + break; + } + + expressionNodes = + create_boolean_expression(csound, tempLeft, + tempLeft->line, tempLeft->locn, + typeTable); + + anchor = appendToTree(csound, anchor, expressionNodes); + + last = tree_tail(expressionNodes); + + /* reconnect into chain */ { - //TREE * left = current->left; - //TREE * right = current->right; - //TREE* last; - TREE * gotoToken; - - int32 topLabelCounter = genlabs++; - int32 endLabelCounter = genlabs++; - TREE *tempLeft = current->left; - TREE *tempRight = current->right; - //TREE *ifBlockStart = current; - TREE *ifBlockCurrent = current; - TREE *ifBlockLast = current; - //TREE *next = current->next; - TREE *statements, *labelEnd; - int type; - /* *** Stage 1: Create a top label (overwriting *** */ - { /* Change UNTIL to label and add IF */ - TREE* t=create_synthetic_label(csound, topLabelCounter); - current->type = t->type; current->left = current->right = NULL; - current->value = t->value; - ifBlockCurrent = t; - ifBlockCurrent->left = tempLeft; - ifBlockCurrent->right = tempRight; - ifBlockCurrent->next = current->next; - ifBlockCurrent->type = IF_TOKEN; - current->next = t; - } - /* *** Stage 2: Boolean expression *** */ - /* Deal with the boolean expression to variable */ - tempRight = ifBlockCurrent->right; - expressionNodes = - ifBlockLast->next = create_boolean_expression(csound, - ifBlockCurrent->left, - ifBlockCurrent->line, - ifBlockCurrent->locn); - while (ifBlockLast->next != NULL) { - ifBlockLast = ifBlockLast->next; - } - /* *** Stage 3: Create the goto *** */ - statements = tempRight; /* the body of the loop */ - labelEnd = create_synthetic_label(csound, endLabelCounter); + TREE *statements, *label, *labelEnd, *gotoToken; + int gotoType; + + statements = tempRight->right; + label = create_synthetic_ident(csound, genlabs); + labelEnd = create_synthetic_label(csound, genlabs++); + tempRight->right = label; + + typeTable->labelList = + cs_cons(csound, + cs_strdup(csound, + labelEnd->value->lexeme), + typeTable->labelList); + + gotoType = // checking for #B... var name + (last->left->value->lexeme[1] == 'B'); gotoToken = create_goto_token(csound, - ifBlockLast->left->value->lexeme, - labelEnd, - type = - ((argtyp2(csound, - ifBlockLast->left->value->lexeme)=='B') - || - (argtyp2(csound, - tempRight->value->lexeme) == 'k'))); - /* relinking */ - /* tempRight = ifBlockLast->next; */ - ifBlockLast->next = gotoToken; - /* ifBlockLast->next->next = tempRight; */ - gotoToken->right->next = labelEnd; + last->left->value->lexeme, + tempRight, + gotoType); gotoToken->next = statements; - labelEnd = create_synthetic_label(csound, endLabelCounter); - while (statements->next != NULL) { /* To end of body */ - statements = statements->next; - } - { - TREE *topLabel = create_synthetic_ident(csound, - topLabelCounter); - TREE *gotoTopLabelToken = - create_simple_goto_token(csound, topLabel, (type==1 ? 0 : 1)); + anchor = appendToTree(csound, anchor, gotoToken); + + /* relinking */ + last = tree_tail(last); + + if (endLabelCounter > 0) { + TREE *endLabel = create_synthetic_ident(csound, + endLabelCounter); + int type = (gotoType == 1) ? 0 : 2; + /* csound->DebugMsg(csound, "%s(%d): type = %d %d\n", */ + /* __FILE__, __LINE__, type, gotoType); */ + TREE *gotoEndLabelToken = + create_simple_goto_token(csound, endLabel, type); if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "Creating simple goto token\n"); - statements->next = gotoTopLabelToken; - gotoTopLabelToken->next = labelEnd; + + appendToTree(csound, last, gotoEndLabelToken); + + gotoEndLabelToken->next = labelEnd; } - labelEnd->next = ifBlockCurrent->next; - ifBlockLast = labelEnd; - ifBlockCurrent = tempRight->next; - } - break; - case LABEL_TOKEN: - break; - case '=': - { - TREE* currentArg = current->right; - TREE* currentAns = current->left; - //csound->Message(csound, "Assignment Statement.\n"); - if (currentArg->left || currentArg->right) { - int anstype, argtype; - //csound->Message(csound, "expansion case\n"); - anstype = argtyp2(csound, current->left->value->lexeme); - //print_tree(csound, "Assignment\n", current); - expressionNodes = - create_expression(csound, currentArg, - currentArg->line, currentArg->locn); - //print_tree(csound, "expressionNodes\n", currentArg); - currentArg = expressionNodes; - while (currentArg->next) currentArg = currentArg->next; - //print_tree(csound, "currentArg\n", currentArg); - argtype = argtyp2(csound, currentArg->left->value->lexeme); - //printf("anstype = %c argtype = %c\n", anstype, argtype); - if (anstype=='a' && argtype!='a') { - //upsample - //goto maincase; /* Wastes time and space */ - TREE* opTree = create_opcode_token(csound, "upsamp"); - opTree->right = make_leaf(csound, current->line, current->locn, - T_IDENT_K, currentArg->left->value); - opTree->left = current->left; - opTree->line = current->line; - opTree->locn = current->locn; - opTree->next = current->next; - //print_tree(csound, "opTree\n", opTree); - currentArg->next = opTree; - //print_tree(csound, "currentArg\n", currentArg); - //print_tree(csound, "making expression", opTree); - - /* current->right = currentArg->left; /\* Should this copy? *\/ */ - /* current->next = NULL; */ - /* currentArg->next = current; */ - //print_tree(csound, "becomes\n", expressionNodes); - memmove(current, expressionNodes, sizeof(TREE)); - //print_tree(csound, "current\n", current); - break; - } - else if (anstype=='k' && argtype=='i') { - TREE* opTree = create_opcode_token(csound, "=.k"); - opTree->right = make_leaf(csound, current->line, current->locn, - T_IDENT_K, currentArg->left->value); - opTree->left = current->left; - opTree->line = current->line; - opTree->locn = current->locn; - opTree->next = current->next; - currentArg->next = opTree; - memmove(current, expressionNodes, sizeof(TREE)); - //print_tree(csound, "current\n", current); - break; - } - else { - mfree(csound, currentArg->left); - currentArg->left = currentAns; - currentArg->next = current->next; - //print_tree(csound, "becomes\n", expressionNodes); - memmove(current, expressionNodes, sizeof(TREE)); - } - break; + else { + appendToTree(csound, last, labelEnd); } + + ifBlockCurrent = tempRight->next; } - default: - //maincase: - { /* This is WRONG in optional argsq */ - TREE* previousArg = NULL; - TREE* currentArg = current->right; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found Statement.\n"); - while (currentArg != NULL) { - TREE* last; - TREE *nextArg; - TREE *newArgTree; - int is_bool = 0; - if (is_expression_node(currentArg) || - (is_bool = is_boolean_expression_node(currentArg))) { - char * newArg; - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "Found Expression.\n"); - if (is_bool == 0) { - expressionNodes = - create_expression(csound, currentArg, - currentArg->line, currentArg->locn); - } - else { - expressionNodes = - create_boolean_expression(csound, currentArg, - currentArg->line, currentArg->locn); - } - - /* Set as anchor if necessary */ - if (anchor == NULL) { - anchor = expressionNodes; - } - - /* reconnect into chain */ - last = expressionNodes; - while (last->next != NULL) { - last = last->next; - } - last->next = current; - if (previous == NULL) { - previous = last; - } - else { - previous->next = expressionNodes; - previous = last; - } + } - newArg = last->left->value->lexeme; + if (endLabelCounter > 0) { + TREE *endLabel = create_synthetic_label(csound, + endLabelCounter); + anchor = appendToTree(csound, anchor, endLabel); + + typeTable->labelList = cs_cons(csound, + cs_strdup(csound, + endLabel->value->lexeme), + typeTable->labelList); + } - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "New Arg: %s\n", newArg); + anchor = appendToTree(csound, anchor, current->next); - /* handle arg replacement of currentArg here */ - nextArg = currentArg->next; - newArgTree = create_ans_token(csound, newArg); + } + else { + csound->Message(csound, + "ERROR: Neither if-goto or if-then found on line %d!!!", + right->line); + } - if (previousArg == NULL) { - current->right = newArgTree; - } - else { - previousArg->next = newArgTree; - } + return anchor; +} - newArgTree->next = nextArg; - currentArg = newArgTree; - /* TODO - Delete the expression nodes here */ - } +/* 1. create top label to loop back to + 2. do boolean expression + 3. do goto token that checks boolean and goes to end label + 4. insert statements + 5. add goto token that goes to top label + 6. end label */ +TREE* expand_until_statement(CSOUND* csound, TREE* current, TYPE_TABLE* typeTable) +{ + TREE* anchor = NULL; + TREE* expressionNodes = NULL; - previousArg = currentArg; - currentArg = currentArg->next; - } - handle_polymorphic_opcode(csound, current); - handle_optional_args(csound, current); - } + TREE* gotoToken; + + int32 topLabelCounter = genlabs++; + int32 endLabelCounter = genlabs++; + TREE* tempRight = current->right; + TREE* last = NULL; + TREE* labelEnd; + int gotoType; + + anchor = create_synthetic_label(csound, topLabelCounter); + typeTable->labelList = cs_cons(csound, + cs_strdup(csound, anchor->value->lexeme), + typeTable->labelList); + + expressionNodes = create_boolean_expression(csound, + current->left, + current->line, + current->locn, + typeTable); + anchor = appendToTree(csound, anchor, expressionNodes); + last = tree_tail(anchor); + + labelEnd = create_synthetic_label(csound, endLabelCounter); + typeTable->labelList = cs_cons(csound, + cs_strdup(csound, labelEnd->value->lexeme), + typeTable->labelList); + + gotoType = + last->left->value->lexeme[1] == 'B'; // checking for #B... var name + + gotoToken = + create_goto_token(csound, + last->left->value->lexeme, + labelEnd, + gotoType); + gotoToken->next = tempRight; + gotoToken->right->next = labelEnd; + + last = appendToTree(csound, last, gotoToken); + last = tree_tail(last); + + + labelEnd = create_synthetic_label(csound, endLabelCounter); + TREE *topLabel = create_synthetic_ident(csound, + topLabelCounter); + TREE *gotoTopLabelToken = create_simple_goto_token(csound, + topLabel, + (gotoType==1 ? 0 : 1)); + + appendToTree(csound, last, gotoTopLabelToken); + gotoTopLabelToken->next = labelEnd; + + + labelEnd->next = current->next; + + return anchor; +} + +int is_statement_expansion_required(TREE* root) { + TREE* current = root->right; + while (current != NULL) { + if (is_boolean_expression_node(current) || is_expression_node(current)) { + return 1; } + current = current->next; + } - if (anchor == NULL) { - anchor = current; + current = root->left; + while (current != NULL) { + if (current->type == T_ARRAY) { + return 1; } - previous = current; current = current->next; } + return 0; +} - if (UNLIKELY(PARSER_DEBUG)) - csound->Message(csound, "[End Expanding Expressions in AST]\n"); +/* Expands expression nodes into opcode calls + * + * + * for if-goto, expands to: + * 1. Expression nodes - all of the expressions that lead to the boolean var + * 2. goto node - a conditional goto to evals the boolean var and goes to a + * label + * + * for if-then-elseif-else, expands to: + * 1. for each conditional, converts to a set of: + * -expression nodes + * -conditional not-goto that goes to block end label if condition does + * not pass (negative version of conditional is used to conditional skip + * contents of block) + * -statements (body of within conditional block) + * -goto complete block end (this signifies that at the end of these + * statements, skip all other elseif or else branches and go to very end) + * -block end label + * 2. for else statements found, do no conditional and just link in statements + * + * */ - return anchor; -} +//TREE *csound_orc_expand_expressions(CSOUND * csound, TREE *root) +//{ +// // int32 labelCounter = 300L; +// +// TREE *anchor = NULL; +// TREE * expressionNodes = NULL; +// +// TREE *current = root; +// TREE *previous = NULL; +// +// if (UNLIKELY(PARSER_DEBUG)) +// csound->Message(csound, "[Begin Expanding Expressions in AST]\n"); +// +// while (current != NULL) { +// switch(current->type) { +// case INSTR_TOKEN: +// if (UNLIKELY(PARSER_DEBUG)) +// csound->Message(csound, "Instrument found\n"); +// current->right = csound_orc_expand_expressions(csound, current->right); +// //print_tree(csound, "AFTER", current); +// break; +// +// case UDO_TOKEN: +// if (UNLIKELY(PARSER_DEBUG)) csound->Message(csound, "UDO found\n"); +// current->right = csound_orc_expand_expressions(csound, current->right); +// break; +// +// case IF_TOKEN: +// if (UNLIKELY(PARSER_DEBUG)) +// csound->Message(csound, "Found IF statement\n"); +// +// current = expand_if_statement(csound, current); +// +// if (previous != NULL) { +// previous->next = current; +// } +// +// continue; +// case UNTIL_TOKEN: +// if (UNLIKELY(PARSER_DEBUG)) +// csound->Message(csound, "Found UNTIL statement\n"); +// +// current = expand_until_statement(csound, current); +// +// if (previous != NULL) { +// previous->next = current; +// } +// +// continue; +// +// case LABEL_TOKEN: +// break; +// +// default: +// //maincase: +// if (is_statement_expansion_required(current)) { +// current = expand_statement(csound, current); +// +// if (previous != NULL) { +// previous->next = current; +// } +// continue; +// } else { +// handle_optional_args(csound, current); +// } +// } +// +// if (anchor == NULL) { +// anchor = current; +// } +// previous = current; +// current = current->next; +// } +// +// if (UNLIKELY(PARSER_DEBUG)) +// csound->Message(csound, "[End Expanding Expressions in AST]\n"); +// +// return anchor; +//} diff -Nru csound-5.17.11~dfsg/Engine/csound_orc_optimize.c csound-6.02~dfsg/Engine/csound_orc_optimize.c --- csound-5.17.11~dfsg/Engine/csound_orc_optimize.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc_optimize.c 2014-01-07 16:53:47.000000000 +0000 @@ -25,63 +25,208 @@ #include "csoundCore.h" #include "csound_orc.h" -/* Optimizes tree (expressions, etc.) */ -TREE* csound_orc_optimize(CSOUND * csound, TREE *root) +static TREE * create_fun_token(CSOUND *csound, TREE *right, char *fname) { - if (PARSER_DEBUG) csound->Message(csound, "Optimizing AST\n"); - - TREE *anchor = NULL; - - TREE *current = root; - TREE *previous = NULL; - - while(current != NULL) { - switch(current->type) { - case INSTR_TOKEN: - if (PARSER_DEBUG) csound->Message(csound, "Instrument found\n"); - current->right = csound_orc_optimize(csound, current->right); - - break; - case UDO_TOKEN: - if (PARSER_DEBUG) csound->Message(csound, "UDO found\n"); - - break; - - case IF_TOKEN: - - break; - - default: - - if (current->right != NULL) { - if (PARSER_DEBUG) csound->Message(csound, "Found Statement.\n"); - - if (current->type == '=' && previous != NULL) { - /* '=' should be guaranteed to have left and right - * arg by the time it gets here */ - if (previous->left != NULL && previous->left->value != NULL) { - if (strcmp(previous->left->value->lexeme, - current->right->value->lexeme) == 0) { + TREE *ans; + ans = (TREE*)mmalloc(csound, sizeof(TREE)); + if (UNLIKELY(ans == NULL)) exit(1); + ans->type = T_FUNCTION; + ans->value = make_token(csound, fname); + ans->value->type = T_FUNCTION; + ans->left = NULL; + ans->right = right; + ans->next = NULL; + ans->len = 0; + ans->rate = -1; + return ans; +} - } +static TREE * optimize_ifun(CSOUND *csound, TREE *root) +{ + /* print_tree(csound, "optimize_ifun: before", root); */ + switch(root->right->type) { + case INTEGER_TOKEN: + case NUMBER_TOKEN: /* i(num) -> num */ + // FIXME - reinstate optimization after implementing get_type(varname) + // case T_IDENT_I: /* i(ivar) -> ivar */ + // case T_IDENT_GI: /* i(givar) -> givar */ + // case T_IDENT_P: /* i(pN) -> pN */ + root = root->right; + break; + // case T_IDENT_K: /* i(kvar) -> i(kvar) */ + // case T_IDENT_GK: /* i(gkvar) -> i(gkvar) */ + // break; + case T_FUNCTION: /* i(fn(x)) -> fn(i(x)) */ + { + TREE *funTree = root->right; + funTree->right = create_fun_token(csound, funTree->right, "i"); + root = funTree; + } + break; + default: /* i(A op B) -> i(A) op i(B) */ + if(root->right->left != NULL) + root->right->left = create_fun_token(csound, + root->right->left, "i"); + if(root->right->right != NULL) + root->right->right = create_fun_token(csound, + root->right->right, "i"); + root->right->next = root->next; + root = root->right; + break; + } + /* print_tree(csound, "optimize_ifun: after", root); */ + return root; +} +/** Verifies and optimise; constant fold and opcodes and args are correct*/ +static TREE * verify_tree1(CSOUND *csound, TREE *root) +{ + TREE *ans, *last; + double lval, rval; + //csound->Message(csound, "Verifying AST (NEED TO IMPLEMENT)\n"); + //print_tree(csound, "Verify", root); + if (root->right && root->right->type != T_INSTLIST) { + if (root->type == T_OPCODE || root->type == T_OPCODE0) { + last = root->right; + while (last->next) { + /* we optimize the i() functions in the opcode */ + if (last->next->type == T_FUNCTION && + (strcmp(last->next->value->lexeme, "i") == 0)) { + TREE *temp = optimize_ifun(csound, last->next); + temp->next = last->next->next; + last->next = temp; + } + last = last->next; + } + } + if (root->right->type == T_FUNCTION && + (strcmp(root->right->value->lexeme, "i") == 0)) { /* i() function */ + root->right = optimize_ifun(csound, root->right); + } + last = root->right; + while (last->next) { + last->next = verify_tree1(csound, last->next); + last = last->next; + } + root->right = verify_tree1(csound, root->right); + if (root->left) { + if (root->left->type == T_FUNCTION && + (strcmp(root->left->value->lexeme, "i") == 0)) { /* i() function */ + root->left = optimize_ifun(csound, root->left); + } + root->left= verify_tree1(csound, root->left); + if ((root->left->type == INTEGER_TOKEN || + root->left->type == NUMBER_TOKEN) && + (root->right->type == INTEGER_TOKEN || + root->right->type == NUMBER_TOKEN)) { + //print_tree(csound, "numerical case\n", root); + lval = (root->left->type == INTEGER_TOKEN ? + (double)root->left->value->value : + root->left->value->fvalue); + rval = (root->right->type == INTEGER_TOKEN ? + (double)root->right->value->value : + root->right->value->fvalue); + ans = root->left; + /* **** Something wrong here -- + subtraction confuses memory **** */ + switch (root->type) { + case '+': + ans->type = ans->value->type = NUMBER_TOKEN; + ans->value->fvalue = lval+rval; + ans->value->lexeme = + (char*)mrealloc(csound, ans->value->lexeme, 24); + CS_SPRINTF(ans->value->lexeme, "%f", ans->value->fvalue); + ans->next = root->next; + //Memory leak!! + //mfree(csound, root); mfree(csound root->right); + return ans; + case '-': + ans->type = ans->value->type = NUMBER_TOKEN; + ans->value->fvalue = lval-rval; + ans->value->lexeme = + (char*)mrealloc(csound, ans->value->lexeme, 24); + CS_SPRINTF(ans->value->lexeme, "%f", ans->value->fvalue); + ans->next = root->next; + //Memory leak!! + //mfree(csound, root); mfree(csound, root->right); + return ans; + case '*': + ans->type = ans->value->type = NUMBER_TOKEN; + ans->value->fvalue = lval*rval; + ans->value->lexeme = + (char*)mrealloc(csound, ans->value->lexeme, 24); + CS_SPRINTF(ans->value->lexeme, "%f", ans->value->fvalue); + ans->next = root->next; + //Memory leak!! + //mfree(csound, root); mfree(csound, root->right); + return ans; + case '/': + ans->type = ans->value->type = NUMBER_TOKEN; + ans->value->fvalue = lval/rval; + ans->value->lexeme = + (char*)mrealloc(csound, ans->value->lexeme, 24); + CS_SPRINTF(ans->value->lexeme, "%f", ans->value->fvalue); + ans->next = root->next; + //Memory leak!! + //mfree(csound, root); mfree(csound, root->right); + return ans; + /* case S_NEQ: */ + /* break; */ + /* case S_AND: */ + /* break; */ + /* case S_OR: */ + /* break; */ + /* case S_LT: */ + /* break; */ + /* case S_LE: */ + /* break; */ + /* case S_EQ: */ + /* break; */ + /* case S_GT: */ + /* break; */ + /* case S_GE: */ + /* break; */ + default: break; + } + } + } + else if (root->right->type == INTEGER_TOKEN || + root->right->type == NUMBER_TOKEN) { + switch (root->type) { + case S_UMINUS: + /*print_tree(csound, "root", root);*/ + ans = root->right; + ans->value->fvalue = + -(ans->type==INTEGER_TOKEN ? (double)ans->value->value + : ans->value->fvalue); + ans->value->lexeme = + (char*)mrealloc(csound, ans->value->lexeme, 24); + CS_SPRINTF(ans->value->lexeme, "%f", ans->value->fvalue); + ans->type = ans->value->type = NUMBER_TOKEN; + //print_tree(csound, "ans", ans); + ans->next = root->next; + return ans; + default: + break; } - - } } - } - - if (anchor == NULL) { - anchor = current; - } - - previous = current; - current = current->next; - } + return root; +} - if (PARSER_DEBUG) csound->Message(csound, "[End Optimizing AST]\n"); - - return anchor; - +/* Optimizes tree (expressions, etc.) */ +TREE * csound_orc_optimize(CSOUND *csound, TREE *root) +{ + TREE *original=root, *last = NULL; + while (root) { + TREE *xx = verify_tree1(csound, root); + if (xx != root) { + xx->next = root->next; + if (last) last->next = xx; + else original = xx; + } + last = root; + root = root->next; + } + return original; } diff -Nru csound-5.17.11~dfsg/Engine/csound_orc_semantics.c csound-6.02~dfsg/Engine/csound_orc_semantics.c --- csound-5.17.11~dfsg/Engine/csound_orc_semantics.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_orc_semantics.c 2014-01-07 16:53:47.000000000 +0000 @@ -24,219 +24,1566 @@ #include #include +//#include #include "csoundCore.h" #include "csound_orc.h" #include "namedins.h" #include "parse_param.h" +#include "csound_type_system.h" +#include "csound_standard_types.h" +#include "csound_orc_expressions.h" +#include "csound_orc_semantics.h" char *csound_orcget_text ( void *scanner ); +int is_label(char* ident, CONS_CELL* labelList); -extern char argtyp2(CSOUND*, char*); +extern char argtyp2(char*); extern int tree_arg_list_count(TREE *); void print_tree(CSOUND *, char *, TREE *); -/* TREE* force_rate(TREE* a, char t) */ -/* { /\* Ensure a is of type t *\/ */ -/* return a; */ -/* } */ -static TREE * create_fun_token(CSOUND *csound, TREE *right, char *fname) +/* from csound_orc_compile.c */ +extern int argsRequired(char* arrayName); +extern char** splitArgs(CSOUND* csound, char* argString); +extern int pnum(char*); + +OENTRIES* find_opcode2(CSOUND*, char*); +char* resolve_opcode_get_outarg(CSOUND* csound, + OENTRIES* entries, char* inArgTypes); +int check_out_args(CSOUND* csound, char* outArgsFound, char* opOutArgs); +char* get_arg_string_from_tree(CSOUND* csound, TREE* tree, + TYPE_TABLE* typeTable); +char* convert_internal_to_external(CSOUND* csound, char* arg); +char* convert_external_to_internal(CSOUND* csound, char* arg); + + +char* cs_strdup(CSOUND* csound, char* str) { + size_t len; + char* retVal; + + if (str == NULL) return NULL; + + len = strlen(str); + retVal = mmalloc(csound, (len + 1) * sizeof(char)); + + if(len > 0) memcpy(retVal, str, len * sizeof(char));//why not strcpy? + retVal[len] = '\0'; + + return retVal; +} + +char* cs_strndup(CSOUND* csound, char* str, size_t size) { + size_t len; + char* retVal; + + if (str == NULL || size == 0) return NULL; + len = strlen(str); + + if (size > len) { // catches if str is empty string + return cs_strdup(csound, str); + } + + retVal = mmalloc(csound, (size + 1) * sizeof(char)); + memcpy(retVal, str, size * sizeof(char)); + retVal[size] = '\0'; + + return retVal; +} + +char* get_expression_opcode_type(CSOUND* csound, TREE* tree) { + switch(tree->type) { + case '+': + return "##add"; + case '-': + return "##sub"; + case '*': + return "##mul"; + case '%': + return "##mod"; + case '/': + return "##div"; + case '^': + return "pow"; + case S_UMINUS: + return "##mul"; + case '|': + return "##or"; + case '&': + return "##and"; + case S_BITSHIFT_RIGHT: + return "##shr"; + case S_BITSHIFT_LEFT: + return "##shl"; + case '#': + return "##xor"; + case '~': + return "##not"; + case T_ARRAY: + return "##array_get"; + } + csound->Warning(csound, Str("Unknown function type found: %d [%c]\n"), + tree->type, tree->type); + return NULL; +} + +char* get_boolean_expression_opcode_type(CSOUND* csound, TREE* tree) { + switch(tree->type) { + case S_EQ: + return "=="; + case S_NEQ: + return "!="; + case S_GE: + return ">="; + case S_LE: + return "<="; + case S_GT: + return ">"; + case S_LT: + return "<"; + case S_AND: + return "&&"; + case S_OR: + return "||"; + } + csound->Warning(csound, + Str("Unknown boolean expression type found: %d\n"), + tree->type); + return NULL; +} + +//FIXME - current just returns subtype but assumes single char type name, +// should check for long type names, as well as check dimensions and remove one +char* get_array_sub_type(CSOUND* csound, char* arrayName) { + char temp[2]; + char *t = arrayName; + + if (*t == '#') t++; + if (*t == 'g') t++; + + if (*t == 't') { /* Support legacy t-vars by mapping to k subtypes */ + return cs_strdup(csound, "k"); + } + + while (*t == '[') { + t++; + } + temp[0] = *t; + temp[1] = 0; + return cs_strdup(csound, temp); +} + +char* create_array_arg_type(CSOUND* csound, CS_VARIABLE* arrayVar) { + + int i, len = arrayVar->dimensions + 3; + char* retVal = mmalloc(csound, len); + retVal[len - 1] = '\0'; + retVal[len - 2] = ']'; + retVal[len - 3] = *arrayVar->subType->varTypeName; + for (i = len - 4; i >= 0; i--) { + retVal[i] = '['; + } + return retVal; +} + +/* this checks if the annotated type exists */ +char *check_annotated_type(CSOUND* csound, OENTRIES* entries, + char* outArgTypes) { + int i; + for (i = 0; i < entries->count; i++) { + OENTRY* temp = entries->entries[i]; + if (check_out_args(csound, outArgTypes, temp->outypes)) + return outArgTypes; + } + return NULL; +} + + +/* This function gets arg type with checking type table */ +char* get_arg_type2(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable) { - TREE *ans; - ans = (TREE*)mmalloc(csound, sizeof(TREE)); - if (UNLIKELY(ans == NULL)) exit(1); - ans->type = T_FUNCTION; - ans->value = make_token(csound, fname); - ans->value->type = T_FUNCTION; - ans->left = NULL; - ans->right = right; - ans->next = NULL; - ans->len = 0; - ans->rate = -1; - return ans; + char* s; + char* t; + //CS_TYPE* type; + CS_VAR_POOL* pool; + CS_VARIABLE* var; + + if (is_expression_node(tree)) { + TREE* nodeToCheck = tree; + + if (tree->type == T_ARRAY) { + char* leftArgType = get_arg_type2(csound, tree->left, typeTable); + + //FIXME - should use CS_TYPE and not interrogate string + if (leftArgType[0] == '[') { + return get_array_sub_type(csound, tree->left->value->lexeme); + } + else { + char* rightArgType = get_arg_string_from_tree(csound, tree->right, + typeTable); + char* argString = strcat(leftArgType, rightArgType); + + char* outype = resolve_opcode_get_outarg(csound, + find_opcode2(csound, + "##array_get"), + argString); + + if (UNLIKELY(outype == NULL)) { + synterr(csound, + Str("unable to find array operator for " + "types %s line %d\n"), + argString, tree->line); + return NULL; + } + + return cs_strdup(csound, outype); + } + } + + if (tree->type == '?') { + char* arg1, *arg2, *ans, *out; + char condInTypes[64]; + + ans = get_arg_type2(csound, tree->left, typeTable); + if (UNLIKELY(ans == NULL || (*ans != 'b' && *ans != 'B'))) { + synterr(csound, + Str("non-boolean expression found for ternary operator," + " line %d\n"), tree->line); + return NULL; + } + arg1 = get_arg_type2(csound, tree->right->left, typeTable); + arg2 = get_arg_type2(csound, tree->right->right, typeTable); + + sprintf(condInTypes, "%s%s%s", ans, arg1, arg2); + + out = resolve_opcode_get_outarg(csound, + find_opcode2(csound, ":cond"), + condInTypes); + + if (UNLIKELY(out == NULL)) { + synterr(csound, + Str("unable to find ternary operator for " + "types '%s ? %s : %s' line %d\n"), + ans, arg1, arg2, tree->line); + return NULL; + } + + return cs_strdup(csound, out); + + } + + if (tree->type == T_FUNCTION) { + char* argTypeRight = get_arg_string_from_tree(csound, + tree->right, typeTable); + char* opname = tree->value->lexeme; + OENTRIES* entries = find_opcode2(csound, opname); + char * out; + + if(tree->value->optype != NULL) /* if there is type annotation */ + out = check_annotated_type(csound, entries, tree->value->optype); + else out = resolve_opcode_get_outarg(csound, entries, argTypeRight); + + + if (UNLIKELY(out == 0)) { + synterr(csound, Str("error: opcode '%s' for expression with arg " + "types %s not found, line %d \n"), + opname, argTypeRight, tree->line); + return NULL; + } + + return cs_strdup(csound, out); + + } + + char* argTypeRight = get_arg_type2(csound, + nodeToCheck->right, typeTable); + + if(nodeToCheck->left != NULL) { + char* argTypeLeft = get_arg_type2(csound, nodeToCheck->left, typeTable); + + char* opname = get_expression_opcode_type(csound, nodeToCheck); + int len1, len2; + char* inArgTypes; + char* out; + + if (UNLIKELY(argTypeLeft == NULL || argTypeRight == NULL)) { + synterr(csound, + Str("Unable to verify arg types for expression '%s'\n"), + opname); + return NULL; + } + + OENTRIES* entries = find_opcode2(csound, opname); + + + argTypeLeft = convert_internal_to_external(csound, argTypeLeft); + argTypeRight = convert_internal_to_external(csound, argTypeRight); + + len1 = strlen(argTypeLeft); + len2 = strlen(argTypeRight); + inArgTypes = malloc(len1 + len2 + 1); + + strncpy(inArgTypes, argTypeLeft, len1); + strncpy(inArgTypes + len1, argTypeRight, len2); + + inArgTypes[len1 + len2] = '\0'; + + out = resolve_opcode_get_outarg(csound, entries, inArgTypes); + + if (UNLIKELY(out == NULL)) { + synterr(csound, Str("error: opcode '%s' for expression with arg " + "types %s not found, line %d \n"), + opname, inArgTypes, tree->line); + return NULL; + } + + return cs_strdup(csound, out); + + } else { + return argTypeRight; + } + + } + + if (is_boolean_expression_node(tree)) { + char* argTypeLeft = get_arg_type2(csound, tree->left, typeTable); + char* argTypeRight = get_arg_type2(csound, tree->right, typeTable); + + char* opname = get_boolean_expression_opcode_type(csound, tree); + int len1, len2; + char* inArgTypes; + char* out; + OENTRIES* entries; + + if (UNLIKELY(argTypeLeft == NULL || argTypeRight == NULL)) { + synterr(csound, + Str("Unable to verify arg types for boolean expression '%s'\n"), + opname); + return NULL; + } + + entries = find_opcode2(csound, opname); + + len1 = strlen(argTypeLeft); + len2 = strlen(argTypeRight); + inArgTypes = malloc(len1 + len2 + 1); + + strncpy(inArgTypes, argTypeLeft, len1); + strncpy(inArgTypes + len1, argTypeRight, len2); + + inArgTypes[len1 + len2] = '\0'; + + out = resolve_opcode_get_outarg(csound, entries, inArgTypes); + + if (UNLIKELY(out == NULL)) { + synterr(csound, Str("error: boolean expression '%s' with arg " + "types %s not found, line %d \n"), + opname, inArgTypes, tree->line); + return NULL; + } + + return cs_strdup(csound, out); + + } + + switch(tree->type) { + case NUMBER_TOKEN: + case INTEGER_TOKEN: + return cs_strdup(csound, "c"); /* const */ + case STRING_TOKEN: + return cs_strdup(csound, "S"); /* quoted String */ + case SRATE_TOKEN: + case KRATE_TOKEN: + case KSMPS_TOKEN: + case ZERODBFS_TOKEN: + case NCHNLS_TOKEN: + case NCHNLSI_TOKEN: + return cs_strdup(csound, "r"); /* rsvd */ + case LABEL_TOKEN: + //FIXME: Need to review why label token is used so much in parser, + //for now treat as T_IDENT + case T_ARRAY_IDENT: + case T_IDENT: + s = tree->value->lexeme; + + if (is_label(s, typeTable->labelList)) { + return cs_strdup(csound, "l"); + } + + if (*s == 't') { /* Support legacy t-vars by mapping to k-array */ + return cs_strdup(csound, "[k]"); + } + + if ((*s >= '1' && *s <= '9') || *s == '.' || *s == '-' || *s == '+' || + (*s == '0' && strcmp(s, "0dbfs") != 0)) + return cs_strdup(csound, "c"); /* const */ + if (*s == '"') + return cs_strdup(csound, "S"); + + if (pnum(s) >= 0) + return cs_strdup(csound, "p"); /* pnum */ + + if (*s == '#') + s++; + + pool = (*s == 'g') ? + typeTable->globalPool : typeTable->localPool; + var = csoundFindVariableWithName(pool, tree->value->lexeme); + /* VL: 13-06-13 + if it is not found, we still check the global (merged) pool */ + if(var == NULL && *s == 'g') + var = csoundFindVariableWithName(csound->engineState.varPool, + tree->value->lexeme); + + if (UNLIKELY(var == NULL)) { + synterr(csound, Str("Variable '%s' used before defined\n"), + tree->value->lexeme); + return NULL; + } + + if (var->varType == &CS_VAR_TYPE_ARRAY) { + return create_array_arg_type(csound, var); + } else { + return cs_strdup(csound, var->varType->varTypeName); + } + + + case T_ARRAY: + + s = tree->value->lexeme; + + if (*s == '#') s++; + if (*s == 'g') s++; + + if (*s == 't') { /* Support legacy t-vars by mapping to k-array */ + return cs_strdup(csound, "[k]"); + } + + t = s; + + int len = 1; + while (*t == '[') { + t++; + len++; + } + + char* retVal = mmalloc(csound, (len + 2) * sizeof(char)); + memcpy(retVal, s, len); + retVal[len] = ']'; + retVal[len + 1] = '\0'; + + return retVal; + + default: + csoundWarning(csound, Str("Unknown arg type: %d\n"), tree->type); + print_tree(csound, "Arg Tree\n", tree); + return NULL; + } +} + + + +char* get_opcode_short_name(CSOUND* csound, char* opname) { + + char* dot = strchr(opname, '.'); + if(dot != NULL) { + int opLen = dot - opname; + return cs_strndup(csound, opname, opLen); + } + return opname; +} + +/* find opcode with the specified name in opcode list */ +/* returns index to opcodlst[], or zero if the opcode cannot be found */ + +OENTRY* find_opcode(CSOUND *csound, char *opname) +{ + char *shortName; + CONS_CELL* head; + OENTRY* retVal; + + if (opname[0] == (char) 0 || + (opname[0] >= (char) '0' && opname[0] <= (char) '9')) + return 0; + + shortName = get_opcode_short_name(csound, opname); + + head = cs_hash_table_get(csound, csound->opcodes, shortName); + + retVal = (head != NULL) ? head->value : NULL; + if (shortName != opname) mfree(csound, shortName); + + return retVal; +} + + +/* Finds OENTRIES that match the given opcode name. May return multiple + * OENTRY*'s for each entry in a polyMorphic opcode. + */ +OENTRIES* find_opcode2(CSOUND* csound, char* opname) { + + int i = 0; + char *shortName; + CONS_CELL *head; + OENTRIES* retVal; + + if (UNLIKELY(opname == NULL)) { + return NULL; + } + + retVal = mcalloc(csound, sizeof(OENTRIES)); + + shortName = get_opcode_short_name(csound, opname); + + head = cs_hash_table_get(csound, csound->opcodes, shortName); + + retVal->count = cs_cons_length(head); + while (head != NULL) { + retVal->entries[i++] = head->value; + head = head->next; + } + + if (shortName != opname) { + mfree(csound, shortName); + } + + return retVal; + +} + +inline static int is_in_optional_arg(char arg) { + return (strchr("opqvjhOJVP?", arg) != NULL); +} + +inline static int is_in_var_arg(char arg) { + return (strchr("mMNnyzZ*", arg) != NULL); +} + +int check_array_arg(char* found, char* required) { + char* f = found; + char* r = required; + + while(*r == '[') r++; + + if (*r == '.' || *r == '?' || *r == '*') { + return 1; + } + + while(*f == '[') f++; + + return (*f == *r); +} + +int check_in_arg(char* found, char* required) { + char* t; + int i; + if (UNLIKELY(found == NULL || required == NULL)) { + return 0; + } + + if (strcmp(found, required) == 0) { + return 1; + } + + if (*required == '.' || *required == '?' || *required == '*') { + return 1; + } + + if (*found == '[' || *required == '[') { + if (*found != *required) { + return 0; + } + return check_array_arg(found, required); + } + + t = (char*)POLY_IN_TYPES[0]; + + for (i = 0; t != NULL; i += 2) { + if (strcmp(required, t) == 0) { + return (strchr(POLY_IN_TYPES[i + 1], *found) != NULL); + } + t = (char*)POLY_IN_TYPES[i + 2]; + } + + if (is_in_optional_arg(*required)) { + t = (char*)OPTIONAL_IN_TYPES[0]; + for (i = 0; t != NULL; i += 2) { + if (strcmp(required, t) == 0) { + return (strchr(OPTIONAL_IN_TYPES[i + 1], *found) != NULL); + } + t = (char*)OPTIONAL_IN_TYPES[i + 2]; + } + } + + if (!is_in_var_arg(*required)) { + return 0; + } + + t = (char*)VAR_ARG_IN_TYPES[0]; + for (i = 0; t != NULL; i += 2) { + if (strcmp(required, t) == 0) { + return (strchr(VAR_ARG_IN_TYPES[i + 1], *found) != NULL); + } + t = (char*)VAR_ARG_IN_TYPES[i + 2]; + } + return 0; +} + +int check_in_args(CSOUND* csound, char* inArgsFound, char* opInArgs) { + if((inArgsFound == NULL || strlen(inArgsFound) == 0) && + (opInArgs == NULL || strlen(opInArgs) == 0)) { + return 1; + } + + if (UNLIKELY(opInArgs == NULL)) { + return 0; + } + + { + int argsFoundCount = argsRequired(inArgsFound); + int argsRequiredCount = argsRequired(opInArgs); + char** argsRequired = splitArgs(csound, opInArgs); + char** argsFound; + int i; + int argTypeIndex = 0; + char* varArg = NULL; + int returnVal = 1; + + if ((argsFoundCount > argsRequiredCount) && + !(is_in_var_arg(*argsRequired[argsRequiredCount - 1]))) { + mfree(csound, argsRequired); + return 0; + } + + argsFound = splitArgs(csound, inArgsFound); + + if (argsFoundCount == 0) { + if (is_in_var_arg(*argsRequired[0])) { + varArg = argsRequired[0]; + } + } else { + for (i = 0; i < argsFoundCount; i++) { + char* argFound = argsFound[i]; + + if (varArg != NULL) { + if (!check_in_arg(argFound, varArg)) { + returnVal = 0; + break; + } + } else { + char* argRequired = argsRequired[argTypeIndex++]; + if (!check_in_arg(argFound, argRequired)) { + returnVal = 0; + break; + } + if (is_in_var_arg(*argRequired)) { + varArg = argRequired; + } + } + } + } + + if (returnVal && varArg == NULL) { + while (argTypeIndex < argsRequiredCount) { + char c = *argsRequired[argTypeIndex++]; + + if (!is_in_optional_arg(c) && !is_in_var_arg(c)) { + returnVal = 0; + break; + } + } + + } + + mfree(csound, argsFound); + mfree(csound, argsRequired); + + return returnVal; + } +} + +inline static int is_out_var_arg(char arg) { + return (strchr("mzIXNF*", arg) != NULL); +} + +int check_out_arg(char* found, char* required) { + char* t; + int i; + + if (UNLIKELY(found == NULL || required == NULL)) { + return 0; + } + + // constants not allowed in out args + if (strcmp(found, "c") == 0) { + return 0; + } + + if (*required == '.' || *required == '?' || *required == '*') { + return 1; + } + + if (*found == '[' || *required == '[') { + if(*found != *required) { + return 0; + } + return check_array_arg(found, required); + } + + if(strcmp(found, required) == 0) { + return 1; + } + + t = (char*)POLY_OUT_TYPES[0]; + for(i = 0; t != NULL; i += 2) { + if(strcmp(required, t) == 0) { + return (strchr(POLY_OUT_TYPES[i + 1], *found) != NULL); + } + t = (char*)POLY_OUT_TYPES[i + 2]; + } + + if (!is_out_var_arg(*required)) { + return 0; + } + + t = (char*)VAR_ARG_OUT_TYPES[0]; + for(i = 0; t != NULL; i += 2) { + if(strcmp(required, t) == 0) { + return (strchr(VAR_ARG_OUT_TYPES[i + 1], *found) != NULL); + } + t = (char*)VAR_ARG_OUT_TYPES[i + 2]; + } + return 0; +} + +int check_out_args(CSOUND* csound, char* outArgsFound, char* opOutArgs) +{ + + if((outArgsFound == NULL || strlen(outArgsFound) == 0) && + (opOutArgs == NULL || strlen(opOutArgs) == 0)) { + return 1; + } + + { + int argsFoundCount = argsRequired(outArgsFound); + int argsRequiredCount = argsRequired(opOutArgs); + char** argsRequired = splitArgs(csound, opOutArgs); + char** argsFound; + int i; + int argTypeIndex = 0; + char* varArg = NULL; + int returnVal = 1; + + if ((argsFoundCount > argsRequiredCount) && + !(is_out_var_arg(*argsRequired[argsRequiredCount - 1]))) { + mfree(csound, argsRequired); + return 0; + } + + argsFound = splitArgs(csound, outArgsFound); + + for (i = 0; i < argsFoundCount; i++) { + char* argFound = argsFound[i]; + + if (varArg != NULL) { + if (!check_out_arg(argFound, varArg)) { + returnVal = 0; + break; + } + } else { + char* argRequired = argsRequired[argTypeIndex++]; + if (!check_out_arg(argFound, argRequired)) { + returnVal = 0; + break; + } + if (is_out_var_arg(*argRequired)) { + varArg = argRequired; + } + } + } + + if (returnVal && varArg == NULL) { + + if (argTypeIndex < argsRequiredCount) { + char* argRequired = argsRequired[argTypeIndex]; + returnVal = is_out_var_arg(*argRequired); + } else { + returnVal = 1; + } + } + + mfree(csound, argsFound); + mfree(csound, argsRequired); + + return returnVal; + } +} + + +/* Given an OENTRIES list, resolve to a single OENTRY* based on the + * found in- and out- argtypes. Returns NULL if opcode could not be + * resolved. If more than one entry matches, mechanism assumes there + * are multiple opcode entries with same types and last one should + * override previous definitions. + */ +OENTRY* resolve_opcode(CSOUND* csound, OENTRIES* entries, + char* outArgTypes, char* inArgTypes) { + +// OENTRY* retVal = NULL; + int i; + + + for (i = 0; i < entries->count; i++) { + OENTRY* temp = entries->entries[i]; +// if (temp->intypes == NULL && temp->outypes == NULL) { +// if (outArgTypes == NULL && inArgTypes == NULL) { +// +// } +// continue; +// } + if(check_in_args(csound, inArgTypes, temp->intypes) && + check_out_args(csound, outArgTypes, temp->outypes)) { +// if (retVal != NULL) { +// return NULL; +// } +// retVal = temp; + return temp; + } + } + return NULL; +// return retVal; +} + +/* used when creating T_FUNCTION's */ +char* resolve_opcode_get_outarg(CSOUND* csound, OENTRIES* entries, + char* inArgTypes) { + int i; + + for (i = 0; i < entries->count; i++) { + OENTRY* temp = entries->entries[i]; + if (temp->intypes == NULL && temp->outypes == NULL) { + continue; + } + if(check_in_args(csound, inArgTypes, temp->intypes)) { + // FIXME this is only returning the first match, we need to check + // if there are multiple matches and if so, return NULL to signify + // ambiguity + return temp->outypes; + } + + } + return NULL; +} + +//PUBLIC int resolve_opcode_num(CSOUND* csound, OENTRIES* entries, +// char* outArgTypes, char* inArgTypes) { +// +// int i; +//// int retVal = -1; +// +// for (i = 0; i < entries->count; i++) { +// OENTRY* temp = entries->entries[i]; +// if (temp->intypes == NULL && temp->outypes == NULL) { +// continue; +// } +// if(check_in_args(csound, inArgTypes, temp->intypes) && +// check_out_args(csound, outArgTypes, temp->outypes)) { +//// if (retVal >= 0) { +//// return 0; +//// } +//// retVal = entries->opnum[i]; +// return entries->opnum[i]; +// } +// +// } +// +//// return (retVal < 0) ? 0 : retVal; +// return 0; +//} + + +/* Converts internal array specifier from [[a] to a[][]. + Used by get_arg_string_from_tree to create an arg string that is + compatible with the ones found in OENTRY's. splitArgs converts back + to internal representation. */ +char* convert_internal_to_external(CSOUND* csound, char* arg) { + int i, dimensions; + char* retVal; + + if (arg == NULL || *arg != '[') { + return arg; + } + + dimensions = 0; + while (*arg == '[') { + arg++; + dimensions++; + } + + retVal = mmalloc(csound, sizeof(char) * ((dimensions * 2) + 2)); + retVal[0] = *arg; + for (i = 0; i < dimensions * 2; i += 2) { + retVal[i + 1] = '['; + retVal[i + 2] = ']'; + } + retVal[dimensions * 2 + 1] = '\0'; + //mfree(csound, arg); + return retVal; +} + +/* ASSUMES VALID ARRAY SPECIFIER! */ +char* convert_external_to_internal(CSOUND* csound, char* arg) { + int i, dimensions; + char* retVal; + + if (arg == NULL || *(arg + 1) != '[') { + return arg; + } + + dimensions = (strlen(arg) - 1) / 2; + + retVal = mmalloc(csound, sizeof(char) * (dimensions + 3)); + retVal[dimensions + 2] = '\0'; + retVal[dimensions + 1] = ']'; + retVal[dimensions] = *arg; + + for (i = 0; i < dimensions; i++) { + retVal[i] = '['; + } + //mfree(csound, arg); + return retVal; } -static TREE * optimize_ifun(CSOUND *csound, TREE *root) -{ - /* print_tree(csound, "optimize_ifun: before", root); */ - switch(root->right->type) { - case INTEGER_TOKEN: - case NUMBER_TOKEN: /* i(num) -> num */ - case T_IDENT_I: /* i(ivar) -> ivar */ - case T_IDENT_GI: /* i(givar) -> givar */ - case T_IDENT_P: /* i(pN) -> pN */ - root = root->right; - break; - case T_IDENT_K: /* i(kvar) -> i(kvar) */ - case T_IDENT_GK: /* i(gkvar) -> i(gkvar) */ - break; - case T_FUNCTION: /* i(fn(x)) -> fn(i(x)) */ - { - TREE *funTree = root->right; - funTree->right = create_fun_token(csound, funTree->right, "i"); - root = funTree; - } - break; - default: /* i(A op B) -> i(A) op i(B) */ - if(root->right->left != NULL) - root->right->left = create_fun_token(csound, root->right->left, "i"); - if(root->right->right != NULL) - root->right->right = create_fun_token(csound, root->right->right, "i"); - root->right->next = root->next; - root = root->right; - break; - } - /* print_tree(csound, "optimize_ifun: after", root); */ - return root; -} - -/** Verifies and optimise; constant fold and opcodes and args are correct*/ -static TREE * verify_tree1(CSOUND *csound, TREE *root) -{ - TREE *ans, *last; - double lval, rval; - //csound->Message(csound, "Verifying AST (NEED TO IMPLEMENT)\n"); - //print_tree(csound, "Verify", root); - if (root->right && root->right->type != T_INSTLIST) { - if (root->type == T_OPCODE || root->type == T_OPCODE0) { - last = root->right; - while (last->next) { - /* we optimize the i() functions in the opcode */ - if (last->next->type == T_FUNCTION && - (strcmp(last->next->value->lexeme, "i") == 0)) { - TREE *temp = optimize_ifun(csound, last->next); - temp->next = last->next->next; - last->next = temp; - } - last = last->next; - } - } - if (root->right->type == T_FUNCTION && - (strcmp(root->right->value->lexeme, "i") == 0)) { /* i() function */ - root->right = optimize_ifun(csound, root->right); - } - last = root->right; - while (last->next) { - last->next = verify_tree1(csound, last->next); - last = last->next; - } - root->right = verify_tree1(csound, root->right); - if (root->left) { - if (root->left->type == T_FUNCTION && - (strcmp(root->left->value->lexeme, "i") == 0)) { /* i() function */ - root->left = optimize_ifun(csound, root->left); - } - root->left= verify_tree1(csound, root->left); - if ((root->left->type == INTEGER_TOKEN || - root->left->type == NUMBER_TOKEN) && - (root->right->type == INTEGER_TOKEN || - root->right->type == NUMBER_TOKEN)) { - //print_tree(csound, "numerical case\n", root); - lval = (root->left->type == INTEGER_TOKEN ? - (double)root->left->value->value :root->left->value->fvalue); - rval = (root->right->type == INTEGER_TOKEN ? - (double)root->right->value->value :root->right->value->fvalue); - ans = root->left; - /* **** Something wrong here -- subtraction confuses memory **** */ - switch (root->type) { - case '+': - ans->type = ans->value->type = NUMBER_TOKEN; - ans->value->fvalue = lval+rval; - ans->value->lexeme = - (char*)mrealloc(csound, ans->value->lexeme, 24); - sprintf(ans->value->lexeme, "%f", ans->value->fvalue); - ans->next = root->next; - //Memory leak!! - //mfree(csound, root); mfree(csound root->right); - return ans; - case '-': - ans->type = ans->value->type = NUMBER_TOKEN; - ans->value->fvalue = lval-rval; - ans->value->lexeme = - (char*)mrealloc(csound, ans->value->lexeme, 24); - sprintf(ans->value->lexeme, "%f", ans->value->fvalue); - ans->next = root->next; - //Memory leak!! - //mfree(csound, root); mfree(csound, root->right); - return ans; - case '*': - ans->type = ans->value->type = NUMBER_TOKEN; - ans->value->fvalue = lval*rval; - ans->value->lexeme = - (char*)mrealloc(csound, ans->value->lexeme, 24); - sprintf(ans->value->lexeme, "%f", ans->value->fvalue); - ans->next = root->next; - //Memory leak!! - //mfree(csound, root); mfree(csound, root->right); - return ans; - case '/': - ans->type = ans->value->type = NUMBER_TOKEN; - ans->value->fvalue = lval/rval; - ans->value->lexeme = - (char*)mrealloc(csound, ans->value->lexeme, 24); - sprintf(ans->value->lexeme, "%f", ans->value->fvalue); - ans->next = root->next; - //Memory leak!! - //mfree(csound, root); mfree(csound, root->right); - return ans; - /* case S_NEQ: */ - /* break; */ - /* case S_AND: */ - /* break; */ - /* case S_OR: */ - /* break; */ - /* case S_LT: */ - /* break; */ - /* case S_LE: */ - /* break; */ - /* case S_EQ: */ - /* break; */ - /* case S_GT: */ - /* break; */ - /* case S_GE: */ - /* break; */ - default: break; - } - } - } - else if (root->right->type == INTEGER_TOKEN || - root->right->type == NUMBER_TOKEN) { - switch (root->type) { - case S_UMINUS: - /*print_tree(csound, "root", root);*/ - ans = root->right; - ans->value->fvalue = -(ans->type==INTEGER_TOKEN ? ans->value->value - : ans->value->fvalue); - ans->value->lexeme = - (char*)mrealloc(csound, ans->value->lexeme, 24); - sprintf(ans->value->lexeme, "%f", ans->value->fvalue); - ans->type = ans->value->type = NUMBER_TOKEN; - //print_tree(csound, "ans", ans); - ans->next = root->next; - return ans; + +char* get_arg_string_from_tree(CSOUND* csound, TREE* tree, + TYPE_TABLE* typeTable) { + + int len = tree_arg_list_count(tree); + int i; + + if (len == 0) { + return NULL; + } + + char** argTypes = mmalloc(csound, len * sizeof(char*)); + char* argString = NULL; + TREE* current = tree; + int index = 0; + int argsLen = 0; + + while (current != NULL) { + char* argType = get_arg_type2(csound, current, typeTable); + + //FIXME - fix if argType is NULL and remove the below hack + if(argType == NULL) { + argsLen += 1; + argTypes[index++] = "@"; + } else { + argType = convert_internal_to_external(csound, argType); + argsLen += strlen(argType); + argTypes[index++] = argType; + } + + + current = current->next; + } + + argString = mmalloc(csound, (argsLen + 1) * sizeof(char)); + char* temp = argString; + + for (i = 0; i < len; i++) { + int size = strlen(argTypes[i]); + memcpy(temp, argTypes[i], size); + temp += size; + } + + argString[argsLen] = '\0'; + + return argString; + +} + + + +OENTRY* find_opcode_new(CSOUND* csound, char* opname, + char* outArgsFound, char* inArgsFound) { + +// csound->Message(csound, "Searching for opcode: %s | %s | %s\n", +// outArgsFound, opname, inArgsFound); + + OENTRIES* opcodes = find_opcode2(csound, opname); + + if (opcodes->count == 0) { + return NULL; + } + OENTRY* retVal = resolve_opcode(csound, opcodes, outArgsFound, inArgsFound); + + mfree(csound, opcodes); + + return retVal; +} + +//FIXME - this needs to be updated to take into account array names +// that could clash with non-array names, i.e. kVar and kVar[] +int check_args_exist(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable) { + CS_VARIABLE *var = 0; + TREE* current; + char* argType; + char* varName; + CS_VAR_POOL* pool; + + if (tree == NULL) { + return 1; + } + + current = tree; + + while (current != NULL) { + + if (is_expression_node(tree) || is_boolean_expression_node(tree)) { + if (!(check_args_exist(csound, tree->left, typeTable) && + check_args_exist(csound, tree->right, typeTable))) { + return 0; + } + } else { + switch (current->type) { + case LABEL_TOKEN: + case T_IDENT: + varName = current->value->lexeme; + + if (is_label(varName, typeTable->labelList)) { + break; + } + + argType = get_arg_type2(csound, current, typeTable); + if(argType==NULL) { + synterr(csound, + Str("Variable type for %s could not be determined.\n"), varName); + return 0; + } + + //FIXME - this feels like a hack + if (*argType == 'c' || *argType == 'r' || *argType == 'p') { + break; + } + + pool = (*varName == 'g') ? + typeTable->globalPool : typeTable->localPool; + var = csoundFindVariableWithName(pool, varName); + if (UNLIKELY(var == NULL)) { + /* VL: 13-06-13 + if it is not found, we still check the global (merged) pool */ + if (*varName == 'g') + var = csoundFindVariableWithName(csound->engineState.varPool, + varName); + if(var == NULL) { + synterr(csound, + Str("Variable '%s' used before defined\n"), varName); + return 0; + } + } + break; + case T_ARRAY: + varName = current->left->value->lexeme; + + pool = (*varName == 'g') ? + typeTable->globalPool : typeTable->localPool; + + if (UNLIKELY(csoundFindVariableWithName(pool, varName) == NULL)) { + CS_VARIABLE *var = 0; + /* VL: 13-06-13 + if it is not found, we still check the global (merged) pool */ + if (var == NULL && *varName == 'g') + var = csoundFindVariableWithName(csound->engineState.varPool, + varName); + if (var == NULL) { + synterr(csound, + Str("Variable '%s' used before defined\n"), varName); + return 0; + } + } + break; default: + //synterr(csound, "Unknown arg type: %s\n", current->value->lexeme); + //printf("\t->FOUND OTHER: %s %d\n", current->value->lexeme, + // current->type); + break; + } + + } + + current = current->next; + } + + return 1; +} + +void add_arg(CSOUND* csound, char* varName, TYPE_TABLE* typeTable) { + + CS_TYPE* type; + CS_VARIABLE* var; + char *t; + CS_VAR_POOL* pool; + char argLetter[2]; + ARRAY_VAR_INIT varInit; + void* typeArg = NULL; + + t = varName; + if (*t == '#') t++; + pool = (*t == 'g') ? typeTable->globalPool : typeTable->localPool; + + var = csoundFindVariableWithName(pool, varName); + if (var == NULL) { + t = varName; + argLetter[1] = 0; + + if (*t == '#') t++; + if (*t == 'g') t++; + + if (*t == '[' || *t == 't') { /* Support legacy t-vars */ + int dimensions = 1; + CS_TYPE* varType; + char* b = t + 1; + + while(*b == '[') { + b++; + dimensions++; + } + argLetter[0] = (*b == 't') ? 'k' : *b; /* Support legacy t-vars */ + + varType = csoundGetTypeWithVarTypeName(csound->typePool, argLetter); + + varInit.dimensions = dimensions; + varInit.type = varType; + typeArg = &varInit; + } + + argLetter[0] = (*t == 't') ? '[' : *t; /* Support legacy t-vars */ + + type = csoundGetTypeForVarName(csound->typePool, argLetter); + + var = csoundCreateVariable(csound, csound->typePool, + type, varName, typeArg); + csoundAddVariable(pool, var); + } else { + //TODO - implement reference count increment + } + +} + +void add_array_arg(CSOUND* csound, char* varName, int dimensions, + TYPE_TABLE* typeTable) { + + CS_VARIABLE* var; + char *t; + CS_VAR_POOL* pool; + char argLetter[2]; + ARRAY_VAR_INIT varInit; + void* typeArg = NULL; + + pool = (*varName == 'g') ? typeTable->globalPool : typeTable->localPool; + + var = csoundFindVariableWithName(pool, varName); + if (var == NULL) { + CS_TYPE* varType; + + t = varName; + argLetter[1] = 0; + + if (*t == '#') t++; + if (*t == 'g') t++; + + argLetter[0] = (*t == 't') ? 'k' : *t; /* Support legacy t-vars */ + + varType = csoundGetTypeWithVarTypeName(csound->typePool, argLetter); + + varInit.dimensions = dimensions; + varInit.type = varType; + typeArg = &varInit; + + var = csoundCreateVariable(csound, csound->typePool, + (CS_TYPE*) &CS_VAR_TYPE_ARRAY, + varName, typeArg); + csoundAddVariable(pool, var); + } else { + //TODO - implement reference count increment + } +} + +/* return 1 on succcess, 0 on failure */ +int add_args(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable) +{ + TREE* current; + char* varName; + + if (tree == NULL) { + return 1; + } + + current = tree; + + while (current != NULL) { + + switch (current->type) { + case T_ARRAY_IDENT: + varName = current->value->lexeme; + add_array_arg(csound, varName, + tree_arg_list_count(current->right), typeTable); + + break; + + case LABEL_TOKEN: + case T_IDENT: + varName = current->value->lexeme; + + if (*varName == 't') { /* Support legacy t-vars */ + add_array_arg(csound, varName, 1, typeTable); + } else { + add_arg(csound, varName, typeTable); + } + + break; + + case T_ARRAY: + varName = current->left->value->lexeme; + // FIXME - this needs to work for array and a-names + add_arg(csound, varName, typeTable); + break; + + default: + //synterr(csound, "Unknown arg type: %s\n", current->value->lexeme); + //printf("\t->FOUND OTHER: %s %d\n", + // current->value->lexeme, current->type); + break; + } + + current = current->next; + } + + return 1; +} + + +/* + * Verifies: + * -number of args correct + * -types of arg correct + * -expressions are valid and types correct + */ +int verify_opcode(CSOUND* csound, TREE* root, TYPE_TABLE* typeTable) { + + TREE* left = root->left; + TREE* right = root->right; + char* leftArgString; + char* rightArgString; + char* opcodeName; + + if(root->value == NULL) return 0; + + if (!check_args_exist(csound, root->right, typeTable)) { + return 0; + } + + add_args(csound, root->left, typeTable); + + opcodeName = root->value->lexeme; + leftArgString = get_arg_string_from_tree(csound, left, typeTable); + rightArgString = get_arg_string_from_tree(csound, right, typeTable); + + if (!strcmp(opcodeName, "xin")) { + int nreqd = tree_arg_list_count(root->right); + + if (nreqd > OPCODENUMOUTS_LOW) { + opcodeName = (nreqd > OPCODENUMOUTS_HIGH) ? "##xin256" : "##xin64"; + } + } + + OENTRIES* entries = find_opcode2(csound, opcodeName); + if (UNLIKELY(entries == NULL || entries->count == 0)) { + synterr(csound, Str("Unable to find opcode with name: %s\n"), + root->value->lexeme); + return 0; + } + + OENTRY* oentry; + if(root->value->optype == NULL) + oentry = resolve_opcode(csound, entries, + leftArgString, rightArgString); + /* if there is type annotation, try to resolve it */ + else oentry = resolve_opcode(csound, entries, + root->value->optype, rightArgString); + + + if (UNLIKELY(oentry == NULL)) { + synterr(csound, Str("Unable to find opcode entry for \'%s\' " + "with matching argument types:\n"), + opcodeName); + csoundMessage(csound, Str("Found: %s %s %s\n"), + leftArgString, root->value->lexeme, rightArgString); + csoundMessage(csound, Str("Line: %d Loc: %d\n"), + root->line, root->locn); + return 0; + } else { + root->markup = oentry; + } + + return 1; +} + +/* Walks tree and finds all label: definitions */ +CONS_CELL* get_label_list(CSOUND* csound, TREE* root) { + CONS_CELL* head = NULL, *ret = NULL; + TREE* current = root; + char* labelText; + + while (current != NULL) { + switch(current->type) { + case LABEL_TOKEN: + labelText = current->value->lexeme; + head = cs_cons(csound, cs_strdup(csound, labelText), head); + break; + + case IF_TOKEN: + case ELSEIF_TOKEN: + if (current->right->type == THEN_TOKEN || + current->right->type == KTHEN_TOKEN || + current->right->type == ITHEN_TOKEN) { + + ret = get_label_list(csound, current->right->right); + head = cs_cons_append(head, ret); + ret = get_label_list(csound, current->right->next); + head = cs_cons_append(head, ret); + } + break; + + case ELSE_TOKEN: + case UNTIL_TOKEN: + ret = get_label_list(csound, current->right); + head = cs_cons_append(head, ret); + break; + + default: + break; + } + + current = current->next; + } + + return head; +} + +int is_label(char* ident, CONS_CELL* labelList) { + CONS_CELL* current; + + if (labelList == NULL) return 0; + + current = labelList; + + while (current != NULL) { + if (strcmp((char*)current->value, ident) == 0) { + return 1; + } + current = current->next; + } + return 0; +} + +int verify_if_statement(CSOUND* csound, TREE* root, TYPE_TABLE* typeTable) { + + char* outArg; + + TREE* right = root->right; + + if (right->type == IGOTO_TOKEN || + right->type == KGOTO_TOKEN || + right->type == GOTO_TOKEN) { + + if (!check_args_exist(csound, root->left, typeTable)) { + return 0; + } + + outArg = get_arg_type2(csound, root->left, typeTable); + + return (outArg != NULL && (*outArg == 'b' || *outArg == 'B')); + + } + else if (right->type == THEN_TOKEN || + right->type == ITHEN_TOKEN || + right->type == KTHEN_TOKEN) { + + //TREE *tempLeft; + //TREE *tempRight; + TREE* current = root; + + while(current != NULL) { + //tempLeft = current->left; + //tempRight = current->right; + + if (current->type == ELSE_TOKEN) { break; } + + if (!check_args_exist(csound, current->left, typeTable)) { + return 0; + } + + outArg = get_arg_type2(csound, current->left, typeTable); + + if (outArg == NULL || (*outArg != 'b' && *outArg != 'B')) { + return 0; + } + + current = (current->right == NULL) ? NULL : current->right->next; } + + } + + return 1; + +} + +int verify_until_statement(CSOUND* csound, TREE* root, TYPE_TABLE* typeTable) { + char* outArg; + + if (!check_args_exist(csound, root->left, typeTable)) { + return 0; + }; + + outArg = get_arg_type2(csound, root->left, typeTable); + + + if (UNLIKELY(outArg == NULL || (*outArg != 'b' && *outArg != 'B'))) { + synterr(csound, + Str("expression for until statement not a boolean " + "expression, line %d\n"), + root->line); + return 0; } - return root; + return 1; } -TREE * verify_tree(CSOUND *csound, TREE *root) +TREE* verify_tree(CSOUND * csound, TREE *root, TYPE_TABLE* typeTable) { - TREE *original=root, *last = NULL; - while (root) { - TREE *xx = verify_tree1(csound, root); - if (xx != root) { - xx->next = root->next; - if (last) last->next = xx; - else original = xx; + TREE *anchor = NULL; + TREE *current = root; + TREE *previous = NULL; + TREE* newRight; + + CONS_CELL* parentLabelList = typeTable->labelList; + typeTable->labelList = get_label_list(csound, root); + + if (PARSER_DEBUG) csound->Message(csound, "Verifying AST\n"); + + while (current != NULL) { + switch(current->type) { + case INSTR_TOKEN: + if (PARSER_DEBUG) csound->Message(csound, "Instrument found\n"); + typeTable->localPool = mcalloc(csound, sizeof(CS_VAR_POOL)); + current->markup = typeTable->localPool; + + if (current->right) { + + newRight = verify_tree(csound, current->right, typeTable); + + if (newRight == NULL) { + cs_cons_free(csound, typeTable->labelList); + typeTable->labelList = parentLabelList; + return NULL; + } + + current->right = newRight; + newRight = NULL; + } + + typeTable->localPool = typeTable->instr0LocalPool; + + break; + case UDO_TOKEN: + if (PARSER_DEBUG) csound->Message(csound, "UDO found\n"); + + typeTable->localPool = mcalloc(csound, sizeof(CS_VAR_POOL)); + current->markup = typeTable->localPool; + + if (current->right != NULL) { + + newRight = verify_tree(csound, current->right, typeTable); + + if (newRight == NULL) { + cs_cons_free(csound, typeTable->labelList); + typeTable->labelList = parentLabelList; + return NULL; + } + + current->right = newRight; + newRight = NULL; + } + + typeTable->localPool = typeTable->instr0LocalPool; + + break; + + case IF_TOKEN: + if (!verify_if_statement(csound, current, typeTable)) { + return 0; + } + + current = expand_if_statement(csound, current, typeTable); + + if (previous != NULL) { + previous->next = current; + } + + continue; + + case UNTIL_TOKEN: + if (!verify_until_statement(csound, current, typeTable)) { + return 0; + } + + current = expand_until_statement(csound, current, typeTable); + + if (previous != NULL) { + previous->next = current; + } + + continue; + + case LABEL_TOKEN: + break; + + default: + if(!verify_opcode(csound, current, typeTable)) { + return 0; + } + + if (is_statement_expansion_required(current)) { + current = expand_statement(csound, current, typeTable); + + if (previous != NULL) { + previous->next = current; + } + continue; + } else { + handle_optional_args(csound, current); + } + } + + if (anchor == NULL) { + anchor = current; } - last = root; - root = root->next; + + previous = current; + current = current->next; + } - return original; + + if (PARSER_DEBUG) csound->Message(csound, "[End Verifying AST]\n"); + + cs_cons_free(csound, typeTable->labelList); + typeTable->labelList = parentLabelList; + + return anchor; } + /* BISON PARSER FUNCTION */ int csound_orcwrap() { @@ -246,6 +1593,8 @@ return (1); } +/* UTILITY FUNCTIONS */ + extern int csound_orcget_lineno(void*); extern char *csound_orcget_current_pointer(void *); /* BISON PARSER FUNCTION */ @@ -274,7 +1623,7 @@ while ((ch=*--p) != '\n' && ch != '\0'); do { ch = *++p; - if(ch == '\n') break; + if (ch == '\n') break; csound->Message(csound, "%c", ch); } while (ch != '\n' && ch != '\0'); csound->Message(csound, " <<<\n"); @@ -286,14 +1635,15 @@ * down the linked list to append at end; checks for NULL's and returns * appropriate nodes */ -TREE* appendToTree(CSOUND * csound, TREE *first, TREE *newlast) { +TREE* appendToTree(CSOUND * csound, TREE *first, TREE *newlast) +{ TREE *current; if (first == NULL) { - return newlast; + return newlast; } if (newlast == NULL) { - return first; + return first; } /* HACK - Checks to see if first node is uninitialized (sort of) @@ -303,13 +1653,13 @@ * value higher than all the type numbers that were being printed out */ if (first->type > 400 || first-> type < 0) { - return newlast; + return newlast; } current = first; while (current->next != NULL) { - current = current->next; + current = current->next; } current->next = newlast; @@ -331,12 +1681,13 @@ ans->type = type; ans->left = left; ans->right = right; + ans->value = NULL; /* New code -- JPff */ ans->next = NULL; ans->len = 2; ans->rate = -1; ans->line = line; ans->locn = locn; - csound->DebugMsg(csound, "%s(%d) line = %d\n", __FILE__, __LINE__, line); + //csound->DebugMsg(csound, "%s(%d) line = %d\n", __FILE__, __LINE__, line); return ans; } @@ -361,34 +1712,37 @@ return ans; } -/** Utility function to create assignment statements - * Replaces = with correct version for args - */ -char* get_assignment_type(CSOUND *csound, char * ans, TREE* arg1) { - char c = argtyp2(csound, ans); - char* str = (char*)mcalloc(csound, 65); - - switch (c) { - case 'S': - strcpy(str, "strcpy"); - break; - case 'a': - c = argtyp2(csound, arg1->value->lexeme); - strcpy(str, (c == 'a' ? "=.a" : "upsamp")); - /* strcpy(str, "=.a"); */ - break; - case 'p': - c = 'i'; /* purposefully fall through */ - default: - sprintf(str, "=.%c", c); +static void delete_tree(CSOUND *csound, TREE *l) +{ + while (1) { + TREE *old = l; + if (UNLIKELY(l==NULL)) { + return; + } + if (l->value) { + if (l->value->lexeme) { + //printf("Free %p (%s)\n", l->value->lexeme, l->value->lexeme); + mfree(csound, l->value->lexeme); + //l->value->lexeme = NULL; + } + //printf("Free val %p\n", l->value); + mfree(csound, l->value); + //l->value = NULL; + } + delete_tree(csound, l->left); + //l->left = NULL; + delete_tree(csound, l->right); + //l->right = NULL; + l = l->next; + //printf("Free %p\n", old); + mfree(csound, old); } - - if (PARSER_DEBUG) - csound->Message(csound, "Found Assignment type: %s\n", str); - - return str; } +PUBLIC void csoundDeleteTree(CSOUND *csound, TREE *tree) +{ + delete_tree(csound, tree); +} /* DEBUGGING FUNCTIONS */ @@ -433,10 +1787,6 @@ csound->Message(csound,"S_LE:(%d:%d)\n", l->line, l->locn); break; case S_EQ: csound->Message(csound,"S_EQ:(%d:%d)\n", l->line, l->locn); break; - case S_TASSIGN: - csound->Message(csound,"S_TASSIGN:(%d:%d)\n", l->line, l->locn); break; - case S_TABREF: - csound->Message(csound,"S_TABREF:(%d:%d)\n", l->line, l->locn); break; case S_GT: csound->Message(csound,"S_GT:(%d:%d)\n", l->line, l->locn); break; case S_GE: @@ -446,21 +1796,21 @@ case IF_TOKEN: csound->Message(csound,"IF_TOKEN:(%d:%d)\n", l->line, l->locn); break; case THEN_TOKEN: - csound->Message(csound,"THEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"THEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; case ITHEN_TOKEN: - csound->Message(csound,"ITHEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"ITHEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; case KTHEN_TOKEN: - csound->Message(csound,"KTHEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"KTHEN_TOKEN:(%d:%d)\n", l->line, l->locn); break; case ELSEIF_TOKEN: - csound->Message(csound,"ELSEIF_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"ELSEIF_TOKEN:(%d:%d)\n", l->line, l->locn); break; case ELSE_TOKEN: - csound->Message(csound,"ELSE_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"ELSE_TOKEN:(%d:%d)\n", l->line, l->locn); break; case UNTIL_TOKEN: - csound->Message(csound,"UNTIL_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"UNTIL_TOKEN:(%d:%d)\n", l->line, l->locn); break; case DO_TOKEN: - csound->Message(csound,"DO_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"DO_TOKEN:(%d:%d)\n", l->line, l->locn); break; case OD_TOKEN: - csound->Message(csound,"OD_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"OD_TOKEN:(%d:%d)\n", l->line, l->locn); break; case GOTO_TOKEN: csound->Message(csound,"GOTO_TOKEN:(%d:%d)\n", l->line, l->locn); break; case IGOTO_TOKEN: @@ -472,53 +1822,21 @@ case KRATE_TOKEN: csound->Message(csound,"KRATE_TOKEN:(%d:%d)\n", l->line, l->locn); break; case ZERODBFS_TOKEN: - csound->Message(csound,"ZERODFFS_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"ZERODFFS_TOKEN:(%d:%d)\n", + l->line, l->locn); break; case KSMPS_TOKEN: csound->Message(csound,"KSMPS_TOKEN:(%d:%d)\n", l->line, l->locn); break; case NCHNLS_TOKEN: csound->Message(csound,"NCHNLS_TOKEN:(%d:%d)\n", l->line, l->locn); break; case NCHNLSI_TOKEN: - csound->Message(csound,"NCHNLSI_TOKEN:(%d:%d)\n", l->line, l->locn); break; + csound->Message(csound,"NCHNLSI_TOKEN:(%d:%d)\n", + l->line, l->locn); break; case INSTR_TOKEN: csound->Message(csound,"INSTR_TOKEN:(%d:%d)\n", l->line, l->locn); break; case STRING_TOKEN: csound->Message(csound,"STRING_TOKEN: %s\n", l->value->lexeme); break; case T_IDENT: csound->Message(csound,"T_IDENT: %s\n", l->value->lexeme); break; - case T_IDENT_I: - csound->Message(csound,"IDENT_I: %s\n", l->value->lexeme); break; - case T_IDENT_GI: - csound->Message(csound,"IDENT_GI: %s\n", l->value->lexeme); break; - case T_IDENT_K: - csound->Message(csound,"IDENT_K: %s\n", l->value->lexeme); break; - case T_IDENT_GK: - csound->Message(csound,"IDENT_GK: %s\n", l->value->lexeme); break; - case T_IDENT_A: - csound->Message(csound,"IDENT_A: %s\n", l->value->lexeme); break; - case T_IDENT_GA: - csound->Message(csound,"IDENT_GA: %s\n", l->value->lexeme); break; - case T_IDENT_S: - csound->Message(csound,"IDENT_S: %s\n", l->value->lexeme); break; - case T_IDENT_GS: - csound->Message(csound,"IDENT_GS: %s\n", l->value->lexeme); break; - case T_IDENT_T: - csound->Message(csound,"IDENT_T: %s\n", l->value->lexeme); break; - case T_IDENT_GT: - csound->Message(csound,"IDENT_GT: %s\n", l->value->lexeme); break; - case T_IDENT_W: - csound->Message(csound,"IDENT_W: %s\n", l->value->lexeme); break; - case T_IDENT_GW: - csound->Message(csound,"IDENT_GW: %s\n", l->value->lexeme); break; - case T_IDENT_F: - csound->Message(csound,"IDENT_F: %s\n", l->value->lexeme); break; - case T_IDENT_GF: - csound->Message(csound,"IDENT_GF: %s\n", l->value->lexeme); break; - case T_IDENT_P: - csound->Message(csound,"IDENT_P: %s\n", l->value->lexeme); break; - case T_IDENT_B: - csound->Message(csound,"IDENT_B: %s\n", l->value->lexeme); break; - case T_IDENT_b: - csound->Message(csound,"IDENT_b: %s\n", l->value->lexeme); break; case INTEGER_TOKEN: csound->Message(csound,"INTEGER_TOKEN: %d\n", l->value->value); break; case NUMBER_TOKEN: @@ -545,7 +1863,7 @@ print_tree_i(csound, l->right,n+1); if (l->next != NULL) { - print_tree_i(csound, l->next, n); + print_tree_i(csound, l->next, n); } } @@ -596,10 +1914,12 @@ csound->Message(csound,"name=\"S_LE\""); break; case S_EQ: csound->Message(csound,"name=\"S_EQ\""); break; - case S_TASSIGN: - csound->Message(csound,"name=\"S_TASSIGN\""); break; - case S_TABREF: - csound->Message(csound,"name=\"S_TABREF\""); break; +// case S_TASSIGN: +// csound->Message(csound,"name=\"S_TASSIGN\""); break; +// case S_TABRANGE: +// csound->Message(csound,"name=\"S_TABRANGE\""); break; +// case S_TABREF: +// csound->Message(csound,"name=\"S_TABREF\""); break; case S_GT: csound->Message(csound,"name=\"S_GT\""); break; case S_GE: @@ -614,21 +1934,21 @@ case IF_TOKEN: csound->Message(csound,"name=\"IF_TOKEN\""); break; case THEN_TOKEN: - csound->Message(csound,"name=\"THEN_TOKEN\""); break; + csound->Message(csound,"name=\"THEN_TOKEN\""); break; case ITHEN_TOKEN: - csound->Message(csound,"name=\"ITHEN_TOKEN\""); break; + csound->Message(csound,"name=\"ITHEN_TOKEN\""); break; case KTHEN_TOKEN: - csound->Message(csound,"name=\"KTHEN_TOKEN\""); break; + csound->Message(csound,"name=\"KTHEN_TOKEN\""); break; case ELSEIF_TOKEN: - csound->Message(csound,"name=\"ELSEIF_TOKEN\""); break; + csound->Message(csound,"name=\"ELSEIF_TOKEN\""); break; case ELSE_TOKEN: - csound->Message(csound,"name=\"ELSE_TOKEN\""); break; + csound->Message(csound,"name=\"ELSE_TOKEN\""); break; case UNTIL_TOKEN: - csound->Message(csound,"name=\"UNTIL_TOKEN\""); break; + csound->Message(csound,"name=\"UNTIL_TOKEN\""); break; case DO_TOKEN: - csound->Message(csound,"name=\"DO_TOKEN\""); break; + csound->Message(csound,"name=\"DO_TOKEN\""); break; case OD_TOKEN: - csound->Message(csound,"name=\"OD_TOKEN\""); break; + csound->Message(csound,"name=\"OD_TOKEN\""); break; case GOTO_TOKEN: csound->Message(csound,"name=\"GOTO_TOKEN\""); break; case IGOTO_TOKEN: @@ -655,63 +1975,20 @@ case T_IDENT: csound->Message(csound,"name=\"T_IDENT\" varname=\"%s\"", l->value->lexeme); break; - case T_IDENT_I: - csound->Message(csound,"name=\"IDENT_I\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GI: - csound->Message(csound,"name=\"IDENT_GI\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_K: - csound->Message(csound,"name=\"IDENT_K\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GK: - csound->Message(csound,"name=\"IDENT_GK\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_A: - csound->Message(csound,"name=\"IDENT_A\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GA: - csound->Message(csound,"name=\"IDENT_GA\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_S: - csound->Message(csound,"name=\"IDENT_S\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GS: - csound->Message(csound,"name=\"IDENT_GS\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_T: - csound->Message(csound,"name=\"IDENT_T\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GT: - csound->Message(csound,"name=\"IDENT_GT\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_W: - csound->Message(csound,"name=\"IDENT_W\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GW: - csound->Message(csound,"name=\"IDENT_GW\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_F: - csound->Message(csound,"name=\"IDENT_F\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_GF: - csound->Message(csound,"name=\"IDENT_GF\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_P: - csound->Message(csound,"name=\"IDENT_P\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_B: - csound->Message(csound,"name=\"IDENT_B\" varname=\"%s\"", - l->value->lexeme); break; - case T_IDENT_b: - csound->Message(csound,"name=\"IDENT_b\" varname=\"%s\"", + + case T_ARRAY: + csound->Message(csound,"name=\"T_ARRAY\""); break; + + case T_ARRAY_IDENT: + csound->Message(csound,"name=\"T_ARRAY_IDENT\" varname=\"%s\"", l->value->lexeme); break; + case INTEGER_TOKEN: csound->Message(csound,"name=\"INTEGER_TOKEN\" value=\"%d\"", l->value->value); break; case NUMBER_TOKEN: - csound->Message(csound,"name=\"NUMBER_TOKEN\" value=\"%f\" type=%d", - l->value->fvalue, l->value->type); break; + csound->Message(csound,"name=\"NUMBER_TOKEN\" value=\"%f\"", + l->value->fvalue); break; case S_ANDTHEN: csound->Message(csound,"name=\"S_ANDTHEN\""); break; case S_APPLY: @@ -726,22 +2003,40 @@ csound->Message(csound,"name=\"T_FUNCTION\" fname=\"%s\"", l->value->lexeme); break; case S_UMINUS: - csound->Message(csound,"name=\"S_UMINUS\""); break; + csound->Message(csound,"name=\"S_UMINUS\""); break; case T_INSTLIST: - csound->Message(csound,"name=\"T_INSTLIST\""); break; + csound->Message(csound,"name=\"T_INSTLIST\""); break; case UDO_TOKEN: - csound->Message(csound,"name=\"UDO_TOKEN\""); break; + csound->Message(csound,"name=\"UDO_TOKEN\""); break; case UDO_ANS_TOKEN: - csound->Message(csound,"name=\"UDO_ANS_TOKEN\" signature=\"%s\"", - l->value->lexeme); break; + csound->Message(csound,"name=\"UDO_ANS_TOKEN\" signature=\"%s\"", + l->value->lexeme); break; case UDO_ARGS_TOKEN: - csound->Message(csound,"name=\"UDO_ARGS_TOKEN\" signature=\"%s\"", - l->value->lexeme); break; + csound->Message(csound,"name=\"UDO_ARGS_TOKEN\" signature=\"%s\"", + l->value->lexeme); break; + case S_ELIPSIS: + csound->Message(csound,"name=\"S_ELIPSIS\""); break; +// case T_MAPI: +// csound->Message(csound,"name=\"T_MAPI\""); break; +// case T_MAPK: +// csound->Message(csound,"name=\"T_MAPK\""); break; +// case T_TADD: +// csound->Message(csound,"name=\"T_TADD\""); break; +// case T_SUB: +// csound->Message(csound,"name=\"T_SUB\""); break; +// case S_TUMINUS: +// csound->Message(csound,"name=\"S_TUMINUS\""); break; +// case T_TMUL: +// csound->Message(csound,"name=\"T_TMUL\""); break; +// case T_TDIV: +// csound->Message(csound,"name=\"T_TDIV\""); break; +// case T_TREM: +// csound->Message(csound,"name=\"T_TREM\""); break; default: csound->Message(csound,"name=\"unknown\"(%d)", l->type); } - csound->Message(csound, " (%d:%d)>\n", l->line, l->locn); + csound->Message(csound, " loc=\"%d:%d\">\n", l->line, l->locn); print_tree_xml(csound, l->left,n+1, TREE_LEFT); print_tree_xml(csound, l->right,n+1, TREE_RIGHT); @@ -759,86 +2054,98 @@ void print_tree(CSOUND * csound, char* msg, TREE *l) { - /*if (PARSER_DEBUG)*/ { - if (msg) - csound->Message(csound, msg); - else - csound->Message(csound, "Printing Tree\n"); - csound->Message(csound, "\n"); - print_tree_xml(csound, l, 0, TREE_NONE); - csound->Message(csound, "\n"); - } + if (msg) + csound->Message(csound, msg); + else + csound->Message(csound, "Printing Tree\n"); + csound->Message(csound, "\n"); + print_tree_xml(csound, l, 0, TREE_NONE); + csound->Message(csound, "\n"); } void handle_optional_args(CSOUND *csound, TREE *l) { if (l == NULL || l->type == LABEL_TOKEN) return; + { - int opnum = find_opcode(csound, l->value->lexeme); - OENTRY *ep = csound->opcodlst + opnum; - int nreqd = 0; - int incnt = tree_arg_list_count(l->right); - TREE * temp; - - if (ep->intypes != NULL) { - nreqd = strlen(ep->intypes); - } - - if (PARSER_DEBUG) { - csound->Message(csound, "Handling Optional Args for opcode %s, %d, %d", - ep->opname, incnt, nreqd); - // csound->Message(csound, "ep->intypes = >%s<\n", ep->intypes); - } - if (incnt < nreqd) { /* or set defaults: */ - do { - switch (ep->intypes[incnt]) { - case 'O': /* Will this work? Doubtful code.... */ - case 'o': - temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, make_int(csound, "0")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; - case 'P': - case 'p': - temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, make_int(csound, "1")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; - case 'q': - temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, make_int(csound, "10")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; + OENTRY *ep = (OENTRY*)l->markup; + int nreqd = 0; + int incnt = tree_arg_list_count(l->right); + TREE * temp; + char** inArgParts = NULL; + + if (UNLIKELY(ep==NULL)) { /* **** FIXME **** */ + printf("THIS SHOULD NOT HAPPEN -- ep NULL %s(%d)\n", + __FILE__, __LINE__); + } + if (ep->intypes != NULL) { + nreqd = argsRequired(ep->intypes); + inArgParts = splitArgs(csound, ep->intypes); + } - case 'V': - case 'v': - temp = make_leaf(csound, l->line, l->locn, NUMBER_TOKEN, make_num(csound, ".5")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; - case 'h': - temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, make_int(csound, "127")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; - case 'J': - case 'j': - temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, make_int(csound, "-1")); - if (l->right==NULL) l->right = temp; - else appendToTree(csound, l->right, temp); - break; - case 'M': - case 'N': - case 'm': - nreqd--; - break; - default: - synterr(csound, - Str("insufficient required arguments for opcode %s on line %d\n"), - ep->opname, l->line, l->locn); - } - incnt++; - } while (incnt < nreqd); + if (PARSER_DEBUG) { + csound->Message(csound, "Handling Optional Args for opcode %s, %d, %d", + ep->opname, incnt, nreqd); + csound->Message(csound, "ep->intypes = >%s<\n", ep->intypes); + } + if (incnt < nreqd) { /* or set defaults: */ + do { + switch (*inArgParts[incnt]) { + case 'O': /* Will this work? Doubtful code.... */ + case 'o': + temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, + make_int(csound, "0")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + case 'P': + case 'p': + temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, + make_int(csound, "1")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + case 'q': + temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, + make_int(csound, "10")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + + case 'V': + case 'v': + temp = make_leaf(csound, l->line, l->locn, NUMBER_TOKEN, + make_num(csound, ".5")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + case 'h': + temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, + make_int(csound, "127")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + case 'J': + case 'j': + temp = make_leaf(csound, l->line, l->locn, INTEGER_TOKEN, + make_int(csound, "-1")); + if (l->right==NULL) l->right = temp; + else appendToTree(csound, l->right, temp); + break; + case 'M': + case 'N': + case 'm': + nreqd--; + break; + default: + synterr(csound, + Str("insufficient required arguments for opcode %s" + " on line %d:%d\n"), + ep->opname, l->line, l->locn); + } + incnt++; + } while (incnt < nreqd); + } } } @@ -847,131 +2154,5 @@ return 'i'; } - return argtyp2(csound, tree->value->lexeme); -} - -void handle_polymorphic_opcode(CSOUND* csound, TREE * tree) { - if (tree->type == '=') { - /* BUG: tree->right->value may be NULL */ - /* if (tree->right->value) */ - tree->value->lexeme = - get_assignment_type(csound, - tree->left->value->lexeme, - tree->right/*->value->lexeme*/); - return; - } - else if (tree->type==0) { - csound->Message(csound, "Null type in tree -- aborting\n"); - exit(2); - } - else { - int opnum = find_opcode(csound, tree->value->lexeme); - OENTRY *ep = csound->opcodlst + opnum; - -/* int incnt = tree_arg_list_count(tree->right); */ - - char * str = (char *)mcalloc(csound, strlen(ep->opname) + 4); - char c, d; - - if (ep->dsblksiz >= 0xfffb) { - - switch (ep->dsblksiz) { - - case 0xffff: - /* use outype to modify some opcodes flagged as translating */ - if (PARSER_DEBUG) - csound->Message(csound, "[%s]\n", tree->left->value->lexeme); - - c = tree_argtyp(csound, tree->left); - if (c == 'p') c = 'i'; - if (c == '?') c = 'a'; /* tmp */ - sprintf(str, "%s.%c", ep->opname, c); - - if (PARSER_DEBUG) csound->Message(csound, "New Value: %s\n", str); - - /*if (find_opcode(csound, str) == 0) {*/ - /* synterr(csound, Str("failed to find %s, output arg '%s' illegal type"), - str, ST(group)[ST(nxtest)]);*/ /* report syntax error */ - /*ST(nxtest) = 100; */ /* step way over this line */ - /*goto tstnxt;*/ /* & go to next */ - /*break;*/ - /*}*/ - tree->value->lexeme = (char *)mrealloc(csound, tree->value->lexeme, - strlen(str) + 1); - strcpy(tree->value->lexeme, str); - csound->DebugMsg(csound, Str("modified opcod: %s"), str); - break; - case 0xfffe: /* Two tags for OSCIL's */ - if (PARSER_DEBUG) - csound->Message(csound, "POLYMORPHIC 0xfffe\n"); - c = tree_argtyp(csound, tree->right); - if (c != 'a') c = 'k'; - if ((d = tree_argtyp(csound, tree->right->next)) != 'a') d = 'k'; - sprintf(str, "%s.%c%c", ep->opname, c, d); - if (PARSER_DEBUG) csound->Message(csound, "New Value: %s\n", str); - tree->value->lexeme = (char *)mrealloc(csound, tree->value->lexeme, - strlen(str) + 1); - strcpy(tree->value->lexeme, str); - break; - case 0xfffd: /* For peak, etc. */ - c = tree_argtyp(csound, tree->right); - if (PARSER_DEBUG) - csound->Message(csound, "POLYMORPHIC 0xfffd\n"); - if (c != 'a') c = 'k'; - sprintf(str, "%s.%c", ep->opname, c); - if (PARSER_DEBUG) csound->Message(csound, "New Value: %s\n", str); - tree->value->lexeme = (char *)mrealloc(csound, tree->value->lexeme, - strlen(str) + 1); - strcpy(tree->value->lexeme, str); - break; - case 0xfffc: /* For divz types */ - if (PARSER_DEBUG) - csound->Message(csound, "POLYMORPHIC 0xfffc\n"); - c = tree_argtyp(csound, tree->right); - d = tree_argtyp(csound, tree->right->next); - if ((c=='i' || c=='c') && (d=='i' || d=='c')) - c = 'i', d = 'i'; - else { - if (c != 'a') c = 'k'; - if (d != 'a') d = 'k'; - } - sprintf(str, "%s.%c%c", ep->opname, c, d); - if (PARSER_DEBUG) csound->Message(csound, "New Value: %s\n", str); - tree->value->lexeme = (char *)mrealloc(csound, tree->value->lexeme, - strlen(str) + 1); - strcpy(tree->value->lexeme, str); - break; - case 0xfffb: /* determine opcode by type of first input arg */ - if (PARSER_DEBUG) - csound->Message(csound, "POLYMORPHIC 0xfffb\n"); - c = tree_argtyp(csound, tree->right); - /* allows a, k, and i types (e.g. Inc, Dec), but not constants */ - if (c=='p') c = 'i'; - /*if (ST(typemask_tabl)[(unsigned char) c] & (ARGTYP_i | ARGTYP_p)) - c = 'i'; - sprintf(str, "%s.%c", ST(linopcod), c);*/ - sprintf(str, "%s.%c", ep->opname, c); - if (PARSER_DEBUG) csound->Message(csound, "New Value: %s\n", str); - tree->value->lexeme = (char *)mrealloc(csound, tree->value->lexeme, - strlen(str) + 1); - strcpy(tree->value->lexeme, str); - break; - default: - csound->Message(csound, "Impossible case\n"); - break; - } - - /*if (!(isopcod(csound, str))) {*/ - /* if opcode is not found: report syntax error */ - /*synterr(csound, Str("failed to find %s, input arg illegal type"), str);*/ - /*ST(nxtest) = 100;*/ /* step way over this line */ - /*goto tstnxt;*/ /* & go to next */ - /*} - ST(linopnum) = ST(opnum); - ST(linopcod) = ST(opcod); - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod));*/ - } - - /* free(str); */ - } + return argtyp2( tree->value->lexeme); } diff -Nru csound-5.17.11~dfsg/Engine/csound_pre.lex csound-6.02~dfsg/Engine/csound_pre.lex --- csound-5.17.11~dfsg/Engine/csound_pre.lex 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_pre.lex 2014-01-07 16:54:20.000000000 +0000 @@ -39,7 +39,8 @@ void do_umacro(CSOUND *, char *, yyscan_t); void do_ifdef(CSOUND *, char *, yyscan_t); void do_ifdef_skip_code(CSOUND *, yyscan_t); -// static void print_csound_predata(CSOUND *,char *,yyscan_t); +void do_function(char *, CORFIL*); + // static void print_csound_predata(CSOUND *,char *,yyscan_t); void csound_pre_line(CORFIL*, yyscan_t); #include "parse_param.h" @@ -77,14 +78,87 @@ ELSE #else[ \t]*(;.*)?$ END #end(if)?[ \t]*(;.*)?(\n|\r\n?) CONT \\[ \t]*(;.*)?(\n|\r\n?) +RESET "###\n" -%x incl +INT "int"[ \t]*\( +FRAC "frac"[ \t]*\( +ROUND "round"[ \t]*\( +FLOOR "floor"[ \t]*\( +CEIL "ceil"[ \t]*\( +RND "rnd"[ \t]*\( +BIRND "birnd"[ \t]*\( +ABS "abs"[ \t]*\( +EXP "exp"[ \t]*\( +LOG "log"[ \t]*\( +SQRT "sqrt"[ \t]*\( +SIN "sin"[ \t]*\( +COS "cos"[ \t]*\( +TAN "tan"[ \t]*\( +SININV "sininv"[ \t]*\( +COSINV "cosinv"[ \t]*\( +TANINV "taninv"[ \t]*\( +LOG10 "log10"[ \t]*\( +LOG2 "log2"[ \t]*\( +SINH "sinh"[ \t]*\( +COSH "cosh"[ \t]*\( +TANH "tanh"[ \t]*\( +AMPDB "ampdb"[ \t]*\( +AMPDBFS "ampdbfs"[ \t]*\( +DBAMP "dbamp"[ \t]*\( +DBFSAMP "dbfsamp"[ \t]*\( +FTCPS "ftcps"[ \t]*\( +FTLEN "ftlen"[ \t]*\( +FTSR "ftsr"[ \t]*\( +FTLPTIM "ftlptim"[ \t]*\( +FTCHNLS "ftchnls"[ \t]*\( +I "i"[ \t]*\( +K "k"[ \t]*\( +CPSOCT "cpsoct"[ \t]*\( +OCTPCH "octpch"[ \t]*\( +CPSPCH "cpspch"[ \t]*\( +PCHOCT "pchoct"[ \t]*\( +OCTCPS "octcps"[ \t]*\( +NSAMP "nsamp"[ \t]*\( +POWOFTWO "powoftwo"[ \t]*\( +LOGBTWO "logbtwo"[ \t]*\( +A "a"[ \t]*\( +TB0 "tb0"[ \t]*\( +TB1 "tb1"[ \t]*\( +TB2 "tb2"[ \t]*\( +TB3 "tb3"[ \t]*\( +TB4 "tb4"[ \t]*\( +TB5 "tb5"[ \t]*\( +TB6 "tb6"[ \t]*\( +TB7 "tb7"[ \t]*\( +TB8 "tb8"[ \t]*\( +TB9 "tb9"[ \t]*\( +TB10 "tb10"[ \t]*\( +TB11 "tb11"[ \t]*\( +TB12 "tb12"[ \t]*\( +TB13 "tb13"[ \t]*\( +TB14 "tb14"[ \t]*\( +TB15 "tb15"[ \t]*\( +URD "urd"[ \t]*\( +NOT "not"[ \t]*\( +CENT "cent"[ \t]*\( +OCTAVE "octave"[ \t]*\( +SEMITONE "semitone"[ \t]*\( +CPSMIDIN "cpsmidinn"[ \t]*\( +OCTMIDIN "octmidinn"[ \t]*\( +PCHMIDIN "pchmidinn"[ \t]*\( +DB "db"[ \t]*\( +P "p"[ \t]*\( +QINF "qinf"[ \t]*\( +QNAN "qnan"[ \t]*\( + +%X incl %x macro %x umacro %x ifdef %% +{RESET} { csound_preset_lineno(csound->orcLineOffset, yyscanner); } {CONT} { csound_preset_lineno(1+csound_preget_lineno(yyscanner), yyscanner); } @@ -143,7 +217,7 @@ } {MACRONAME} { MACRO *mm, *mfound=NULL; - int i, len, mlen; + unsigned int i, len, mlen; //print_csound_predata(csound, "Macro call", yyscanner); len = strlen(yytext)-1; mlen = 0; @@ -372,7 +446,8 @@ if (UNLIKELY(PARM->depth > 1024)) csound->Die(csound, Str("unexpected EOF")); PARM->llocn = PARM->locn; PARM->locn = make_location(PARM); - csound->DebugMsg(csound,"%s(%d): loc=%d; lastloc=%d\n", __FILE__, __LINE__, + csound->DebugMsg(csound,"%s(%d): loc=%d; lastloc=%d\n", + __FILE__, __LINE__, PARM->llocn, PARM->locn); if ( !YY_CURRENT_BUFFER ) yyterminate(); /* csound->DebugMsg(csound,"End of input; popping to %p\n", */ @@ -381,7 +456,8 @@ n = PARM->alt_stack[--PARM->macro_stack_ptr].n; csound_preset_lineno(PARM->alt_stack[PARM->macro_stack_ptr].line, yyscanner); - csound->DebugMsg(csound,"%s(%d): line now %d at %d\n", __FILE__, __LINE__, + csound->DebugMsg(csound,"%s(%d): line now %d at %d\n", + __FILE__, __LINE__, csound_preget_lineno(yyscanner), PARM->macro_stack_ptr); /* csound->DebugMsg(csound,"n=%d\n", n); */ if (n!=0) { @@ -502,6 +578,77 @@ corfile_puts(yytext, csound->expanded_orc); } } +{INT} { do_function(yytext,csound->expanded_orc); } +{FRAC} { do_function(yytext,csound->expanded_orc); } +{ROUND} { do_function(yytext,csound->expanded_orc); } +{FLOOR} { do_function(yytext,csound->expanded_orc); } +{CEIL} { do_function(yytext,csound->expanded_orc); } +{RND} { do_function(yytext,csound->expanded_orc); } +{BIRND} { do_function(yytext,csound->expanded_orc); } +{ABS} { do_function(yytext,csound->expanded_orc); } +{EXP} { do_function(yytext,csound->expanded_orc); } +{LOG} { do_function(yytext,csound->expanded_orc); } +{SQRT} { do_function(yytext,csound->expanded_orc); } +{SIN} { do_function(yytext,csound->expanded_orc); } +{COS} { do_function(yytext,csound->expanded_orc); } +{TAN} { do_function(yytext,csound->expanded_orc); } +{SININV} { do_function(yytext,csound->expanded_orc); } +{COSINV} { do_function(yytext,csound->expanded_orc); } +{TANINV} { do_function(yytext,csound->expanded_orc); } +{LOG10} { do_function(yytext,csound->expanded_orc); } +{LOG2} { do_function(yytext,csound->expanded_orc); } +{SINH} { do_function(yytext,csound->expanded_orc); } +{COSH} { do_function(yytext,csound->expanded_orc); } +{TANH} { do_function(yytext,csound->expanded_orc); } +{AMPDB} { do_function(yytext,csound->expanded_orc); } +{AMPDBFS} { do_function(yytext,csound->expanded_orc); } +{DBAMP} { do_function(yytext,csound->expanded_orc); } +{DBFSAMP} { do_function(yytext,csound->expanded_orc); } +{FTCPS} { do_function(yytext,csound->expanded_orc); } +{FTLEN} { do_function(yytext,csound->expanded_orc); } +{FTSR} { do_function(yytext,csound->expanded_orc); } +{FTLPTIM} { do_function(yytext,csound->expanded_orc); } +{FTCHNLS} { do_function(yytext,csound->expanded_orc); } +{I} { do_function(yytext,csound->expanded_orc); } +{K} { do_function(yytext,csound->expanded_orc); } +{CPSOCT} { do_function(yytext,csound->expanded_orc); } +{OCTPCH} { do_function(yytext,csound->expanded_orc); } +{CPSPCH} { do_function(yytext,csound->expanded_orc); } +{PCHOCT} { do_function(yytext,csound->expanded_orc); } +{OCTCPS} { do_function(yytext,csound->expanded_orc); } +{NSAMP} { do_function(yytext,csound->expanded_orc); } +{POWOFTWO} { do_function(yytext,csound->expanded_orc); } +{LOGBTWO} { do_function(yytext,csound->expanded_orc); } +{A} { do_function(yytext,csound->expanded_orc); } +{TB0} { do_function(yytext,csound->expanded_orc); } +{TB1} { do_function(yytext,csound->expanded_orc); } +{TB2} { do_function(yytext,csound->expanded_orc); } +{TB3} { do_function(yytext,csound->expanded_orc); } +{TB4} { do_function(yytext,csound->expanded_orc); } +{TB5} { do_function(yytext,csound->expanded_orc); } +{TB6} { do_function(yytext,csound->expanded_orc); } +{TB7} { do_function(yytext,csound->expanded_orc); } +{TB8} { do_function(yytext,csound->expanded_orc); } +{TB9} { do_function(yytext,csound->expanded_orc); } +{TB10} { do_function(yytext,csound->expanded_orc); } +{TB11} { do_function(yytext,csound->expanded_orc); } +{TB12} { do_function(yytext,csound->expanded_orc); } +{TB13} { do_function(yytext,csound->expanded_orc); } +{TB14} { do_function(yytext,csound->expanded_orc); } +{TB15} { do_function(yytext,csound->expanded_orc); } +{URD} { do_function(yytext,csound->expanded_orc); } +{NOT} { do_function(yytext,csound->expanded_orc); } +{CENT} { do_function(yytext,csound->expanded_orc); } +{OCTAVE} { do_function(yytext,csound->expanded_orc); } +{SEMITONE} { do_function(yytext,csound->expanded_orc); } +{CPSMIDIN} { do_function(yytext,csound->expanded_orc); } +{OCTMIDIN} { do_function(yytext,csound->expanded_orc); } +{PCHMIDIN} { do_function(yytext,csound->expanded_orc); } +{DB} { do_function(yytext,csound->expanded_orc); } +{P} { do_function(yytext,csound->expanded_orc); } +{QINF} { do_function(yytext,csound->expanded_orc); } +{QNAN} { do_function(yytext,csound->expanded_orc); } + . { corfile_putc(yytext[0], csound->expanded_orc); } %% @@ -920,42 +1067,16 @@ PARM->line = n; } -#ifdef MAIN_NEEDED -int main(void) +void do_function(char *text, CORFIL *cf) { - PRE_PARM qq; - int len=100, p=0, n; - char buff[1024]; - FILE *fd = fopen("III", "r"); - - inp = (char*)calloc(100,1); - memset(buff, '\0', 1024); - while ((n = fread(buff, 1, 1023, fd))) { - while (p+n+1>=len) - inp = (char*) realloc(inp, len+=100); - strcat(inp, buff); - p += n; - memset(buff, '\0', 1024); - } - if (n+8>= len) inp = (char*) realloc(inp, len = n+9); - strcat(inp, "\n#exit\0\0"); - rewind(fd); - - memset(&qq, '\0', sizeof(PRE_PARM)); - csound_prelex_init(&qq.yyscanner); - csound_preset_extra(&qq, qq.yyscanner); - //csound_preset_debug(1, &qq.yyscanner); - //csound_prepush_buffer_state(NULL, &qq.yyscanner); - //csound_pre_scan_string(inp, qq.yyscanner); - //csound_preset_in(NULL, qq.yyscanner); - qq.line = 1; - csound_prelex(NULL, qq.yyscanner); - //csound->DebugMsg(csound,corfile_body(expanded_pre)); - //csound_prelex_destroy(&qq.yyscanner); - return 0; + char *p = text; + while (*p != '\0') { + if (!isspace(*p)) corfile_putc(*p, cf); + p++; + } + return; } -#endif - + #if 0 static void print_csound_predata(CSOUND *csound, char *mesg, void *yyscanner) { diff -Nru csound-5.17.11~dfsg/Engine/csound_prs.lex csound-6.02~dfsg/Engine/csound_prs.lex --- csound-5.17.11~dfsg/Engine/csound_prs.lex 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_prs.lex 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,883 @@ +_comment(yyscan_t); +static void do_include(CSOUND *, int, yyscan_t); +static void do_macro_arg(CSOUND *, char *, yyscan_t); +static void do_macro(CSOUND *, char *, yyscan_t); +static void do_umacro(CSOUND *, char *, yyscan_t); +static void do_ifdef(CSOUND *, char *, yyscan_t); +static void do_ifdef_skip_code(CSOUND *, yyscan_t); +// static void print_csound_prsdata(CSOUND *,char *,yyscan_t); +static void csound_prs_line(CORFIL*, yyscan_t); + +#define YY_EXTRA_TYPE PRS_PARM * +#define PARM yyget_extra(yyscanner) + +#define YY_USER_INIT {csound_prs_scan_string(csound->scorestr->body, yyscanner); \ + csound_prsset_lineno(csound->orcLineOffset, yyscanner); yyg->yy_flex_debug_r=1;} +%} +%option reentrant +%option noyywrap +%option prefix="csound_prs" +%option outfile="Engine/csound_prslex.c" +%option stdout + +WHITE ^[ \t]* +NEWLINE (\n|\r\n?) +STSTR \" +ESCAPE \\. +XSTR \{\{([^}]|\}[^}])*\}\} +IDENT [a-zA-Z_][a-zA-Z0-9_]* +IDENTN [a-zA-Z0-9_]+ +MACRONAME "$"[a-zA-Z0-9_]+ +MACRONAMED "$"[a-zA-Z0-9_]+\. +MACRONAMEA "$"[a-zA-Z0-9_]+\( +MACRONAMEDA "$"[a-zA-Z0-9_]+\.\( +MACRO [a-zA-Z0-9_]+\( + +STCOM \/\* +INCLUDE "#include" +DEFINE #[ \t]*define +UNDEF "#undef" +IFDEF #ifn?def +ELSE #else[ \t]*(;.*)?$ +END #end(if)?[ \t]*(;.*)?(\n|\r\n?) +CONT \\[ \t]*(;.*)?(\n|\r\n?) + +%x incl +%x macro +%x umacro +%x ifdef + +%% + +{CONT} { csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + } +{NEWLINE} { csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + } +"//" { + if (PARM->isString != 1) { + comment(yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + } + else { + corfile_puts(yytext, csound->expanded_sco); + } + } +";" { + if (PARM->isString != 1) { + comment(yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + } + else { + corfile_puts(yytext, csound->expanded_sco); + } + //corfile_putline(csound_prsget_lineno(yyscanner), csound->expanded_sco); + } +{STCOM} { + if (PARM->isString != 1) + do_comment(yyscanner); + else + corfile_puts(yytext, csound->expanded_sco); + } +{ESCAPE} { corfile_puts(yytext, csound->expanded_sco); } +{STSTR} { + corfile_putc('"', csound->expanded_sco); + PARM->isString = !PARM->isString; + } +{XSTR} { + char c, *str = yytext; + if (PARM->isString == 1) + yyless(2); + while ((c = *str++) != '\0') { + switch(c) { + case '\r': if (*str == '\n') continue; + case '\n': + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + break; + default: break; + } + } + corfile_puts(yytext, csound->expanded_sco); + } +{MACRONAME} { + MACRO *mm, *mfound=NULL; + int i, len, mlen; + //print_csound_prsdata(csound, "Macro call", yyscanner); + len = strlen(yytext)-1; + mlen = 0; + for (i=len; i>0; i--) { /* Find the definition */ + mm = PARM->macros; + while (mm != NULL) { + if (!(strncmp(yytext+1, mm->name, i))) { + mfound = mm; + mlen = i; + if (strlen(mm->name) == mlen) + goto cont; + } + mm = mm->next; + } + } + cont: + mm = mfound; + if (UNLIKELY(mm == NULL)) { + csound->Message(csound,Str("Undefined macro: '%s'"), yytext); + csound->LongJmp(csound, 1); + } + if (mlenDebugMsg(csound, "found macro %s\nstack ptr = %d\n", */ + /* yytext+1, PARM->macro_stack_ptr); */ + /* print_csound_prsdata(csound, "macro found", yyscanner); */ + /* ??fiddle with buffers I guess */ + if (UNLIKELY(PARM->macro_stack_ptr >= MAX_INCLUDE_DEPTH )) { + csound->Die(csound, Str("Includes nested too deeply")); + } + PARM->alt_stack[PARM->macro_stack_ptr].n = 0; + PARM->alt_stack[PARM->macro_stack_ptr].line = + csound_prsget_lineno(yyscanner); + PARM->alt_stack[PARM->macro_stack_ptr++].s = NULL; + /* csound->DebugMsg(csound,"Push %p macro stack; new body #%s#\n", */ + /* PARM->macros, mm->body); */ + /* csound->DebugMsg(csound,"Push buffer %p -> ", YY_CURRENT_BUFFER); */ + yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + csound_prsset_lineno(1, yyscanner); + PARM->lstack[++PARM->depth] = + (strchr(mm->body,'\n') ?file_to_int(csound, yytext) : 63); + yy_scan_string(mm->body, yyscanner); + csound->DebugMsg(csound,"%p\n", YY_CURRENT_BUFFER); + } +{MACRONAMED} { + MACRO *mm = PARM->macros; + yytext[yyleng-1] = '\0'; + while (mm != NULL) { /* Find the definition */ + if (!(strcmp(yytext+1, mm->name))) + break; + mm = mm->next; + } + if (UNLIKELY(mm == NULL)) { + csound->Message(csound,Str("Undefined macro: '%s'"), yytext); + csound->LongJmp(csound, 1); + } + /* Need to read from macro definition */ + /* ??fiddle with buffers I guess */ + if (UNLIKELY(PARM->macro_stack_ptr >= MAX_INCLUDE_DEPTH )) { + csound->Message(csound, Str("Includes nested too deeply\n")); + exit(1); + } + PARM->alt_stack[PARM->macro_stack_ptr].n = 0; + PARM->alt_stack[PARM->macro_stack_ptr].line = + csound_prsget_lineno(yyscanner); + PARM->alt_stack[PARM->macro_stack_ptr++].s = NULL; + yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + csound_prsset_lineno(1, yyscanner); + PARM->lstack[++PARM->depth] = + (strchr(mm->body,'\n') ?file_to_int(csound, yytext) : 63); + yy_scan_string(mm->body, yyscanner); + csound->DebugMsg(csound,"%p\n", YY_CURRENT_BUFFER); + } +{MACRONAMEA} { + MACRO *mm = PARM->macros; + char *mname; + int c, i, j; + /* csound->DebugMsg(csound,"Macro with arguments call %s\n", yytext); */ + yytext[yyleng-1] = '\0'; + while (mm != NULL) { /* Find the definition */ + csound->DebugMsg(csound,"Check %s against %s\n", yytext+1, mm->name); + if (!(strcmp(yytext+1, mm->name))) + break; + mm = mm->next; + } + if (UNLIKELY(mm == NULL)) { + csound->Message(csound,Str("Undefined macro: '%s'"), yytext); + csound->LongJmp(csound, 1); + } + mname = yytext; + /* Need to read from macro definition */ + csound->DebugMsg(csound,"Looking for %d args\n", mm->acnt); + for (j = 0; j < mm->acnt; j++) { + char term = (j == mm->acnt - 1 ? ')' : '\''); + /* Compatability */ + char trm1 = (j == mm->acnt - 1 ? ')' : '#'); + MACRO *nn = (MACRO*) mmalloc(csound, sizeof(MACRO)); + int size = 100; + nn->name = mmalloc(csound, strlen(mm->arg[j]) + 1); + csound->DebugMsg(csound,"Arg %d: %s\n", j+1, mm->arg[j]); + strcpy(nn->name, mm->arg[j]); + csound->Message(csound, "defining argument %s ", + nn->name); + i = 0; + nn->body = (char*) mmalloc(csound, 100); + while ((c = input(yyscanner))!= term && c!=trm1) { + if (UNLIKELY(i > 98)) { + csound->Die(csound, + Str("Missing argument terminator\n%.98s"), + nn->body); + } + nn->body[i++] = c; + if (UNLIKELY(i >= size)) + nn->body = mrealloc(csound, nn->body, size += 100); + } + nn->body[i] = '\0'; + csound->Message(csound, "as...#%s#\n", nn->body); + nn->acnt = 0; /* No arguments for arguments */ + nn->next = PARM->macros; + PARM->macros = nn; + } + /* csound->DebugMsg(csound,"New body: ...#%s#\n", mm->body); */ + if (UNLIKELY(PARM->macro_stack_ptr >= MAX_INCLUDE_DEPTH )) { + csound->Message(csound, + Str("macro_stack_ptr beyond end: %d \n"), + PARM->macro_stack_ptr); + exit(1); + } + PARM->alt_stack[PARM->macro_stack_ptr].n = PARM->macros->acnt; + PARM->alt_stack[PARM->macro_stack_ptr++].s = PARM->macros; + PARM->alt_stack[PARM->macro_stack_ptr].n = 0; + PARM->alt_stack[PARM->macro_stack_ptr].line = + csound_prsget_lineno(yyscanner); + PARM->alt_stack[PARM->macro_stack_ptr].s = NULL; + csound->DebugMsg(csound,"Push %p macro stack\n",PARM->macros); + yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + csound_prsset_lineno(1, yyscanner); + PARM->lstack[++PARM->depth] = + (strchr(mm->body,'\n') ?file_to_int(csound, mname) : 63); + yy_scan_string(mm->body, yyscanner); + } +{MACRONAMEDA} { + MACRO *mm = PARM->macros; + char *mname; + int c, i, j; + /* csound->DebugMsg(csound,"Macro with arguments call %s\n", yytext); */ + yytext[yyleng-2] = '\0'; + while (mm != NULL) { /* Find the definition */ + csound->DebugMsg(csound,"Check %s against %s\n", yytext+1, mm->name); + if (!(strcmp(yytext+1, mm->name))) + break; + mm = mm->next; + } + if (UNLIKELY(mm == NULL)) { + csound->Message(csound,Str("Undefined macro: '%s'"), yytext); + csound->LongJmp(csound, 1); + } + mname = yytext; + /* Need to read from macro definition */ + csound->DebugMsg(csound,"Looking for %d args\n", mm->acnt); + for (j = 0; j < mm->acnt; j++) { + char term = (j == mm->acnt - 1 ? ')' : '\''); + /* Compatability */ + char trm1 = (j == mm->acnt - 1 ? ')' : '#'); + MACRO *nn = (MACRO*) mmalloc(csound, sizeof(MACRO)); + int size = 100; + nn->name = mmalloc(csound, strlen(mm->arg[j]) + 1); + csound->DebugMsg(csound,"Arg %d: %s\n", j+1, mm->arg[j]); + strcpy(nn->name, mm->arg[j]); + csound->Message(csound, "defining argument %s ", + nn->name); + i = 0; + nn->body = (char*) mmalloc(csound, 100); + while ((c = input(yyscanner))!= term && c!=trm1) { + if (UNLIKELY(i > 98)) { + csound->Die(csound, + Str("Missing argument terminator\n%.98s"), + nn->body); + } + nn->body[i++] = c; + if (UNLIKELY(i >= size)) + nn->body = mrealloc(csound, nn->body, size += 100); + } + nn->body[i] = '\0'; + csound->Message(csound, "as...#%s#\n", nn->body); + nn->acnt = 0; /* No arguments for arguments */ + nn->next = PARM->macros; + PARM->macros = nn; + } + csound->DebugMsg(csound,"New body: ...#%s#\n", mm->body); + PARM->alt_stack[PARM->macro_stack_ptr].n = PARM->macros->acnt; + PARM->alt_stack[PARM->macro_stack_ptr++].s = PARM->macros; + PARM->alt_stack[PARM->macro_stack_ptr].n = 0; + PARM->alt_stack[PARM->macro_stack_ptr].line = + csound_prsget_lineno(yyscanner); + PARM->alt_stack[PARM->macro_stack_ptr].s = NULL; + yypush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + if (PARM->depth++>1024) { + csound->Die(csound, Str("Includes nested too deeply")); + } + csound_prsset_lineno(1, yyscanner); + PARM->lstack[PARM->depth] = + (strchr(mm->body,'\n') ?file_to_int(csound, mname) : 63); + yy_scan_string(mm->body, yyscanner); + } +{INCLUDE} { + if (PARM->isString != 1) + BEGIN(incl); + else + corfile_puts(yytext, csound->expanded_sco); + } +[ \t]* /* eat the whitespace */ +. { /* got the include file name */ + do_include(csound, yytext[0], yyscanner); + BEGIN(INITIAL); + } +#exit { corfile_putc('\0', csound->expanded_sco); + corfile_putc('\0', csound->expanded_sco); + return 0;} +<> { + MACRO *x, *y=NULL; + int n; + csound->DebugMsg(csound,"*********Leaving buffer %p\n", YY_CURRENT_BUFFER); + yypop_buffer_state(yyscanner); + PARM->depth--; + if (UNLIKELY(PARM->depth > 1024)) + csound->Die(csound, Str("unexpected EOF")); + PARM->llocn = PARM->locn; PARM->locn = make_location(PARM); + csound->DebugMsg(csound,"%s(%d): loc=%d; lastloc=%d\n", __FILE__, __LINE__, + PARM->llocn, PARM->locn); + if ( !YY_CURRENT_BUFFER ) yyterminate(); + /* csound->DebugMsg(csound,"End of input; popping to %p\n", */ + /* YY_CURRENT_BUFFER); */ + csound_prs_line(csound->expanded_sco, yyscanner); + n = PARM->alt_stack[--PARM->macro_stack_ptr].n; + csound_prsset_lineno(PARM->alt_stack[PARM->macro_stack_ptr].line, + yyscanner); + csound->DebugMsg(csound,"%s(%d): line now %d at %d\n", __FILE__, __LINE__, + csound_prsget_lineno(yyscanner), PARM->macro_stack_ptr); + /* csound->DebugMsg(csound,"n=%d\n", n); */ + if (n!=0) { + /* We need to delete n macros starting with y */ + y = PARM->alt_stack[PARM->macro_stack_ptr].s; + x = PARM->macros; + if (x==y) { + while (n>0) { + mfree(csound, y->name); x=y->next; + mfree(csound, y); y=x; n--; + } + PARM->macros = x; + } + else { + MACRO *nxt = y->next; + while (x->next != y) x = x->next; + while (n>0) { + nxt = y->next; + mfree(csound, y->name); mfree(csound, y); y=nxt; n--; + } + x->next = nxt; + } + y->next = x; + } + /* csound->DebugMsg(csound,"End of input segment: macro pop %p -> %p\n", */ + /* y, PARM->macros); */ + csound_prs_line(csound->scorestr, yyscanner); + } +{DEFINE} { + if (PARM->isString != 1) + BEGIN(macro); + else + corfile_puts(yytext, csound->expanded_sco); + } +[ \t]* /* eat the whitespace */ +{MACRO} { + yytext[yyleng-1] = '\0'; + /* csound->DebugMsg(csound,"Define macro with args %s\n", yytext); */ + /* print_csound_prsdata(csound, "Before do_macro_arg", yyscanner); */ + do_macro_arg(csound, yytext, yyscanner); + //print_csound_prsdata(csound,"After do_macro_arg", yyscanner); + BEGIN(INITIAL); + } +{IDENTN} { + /* csound->DebugMsg(csound,"Define macro %s\n", yytext); */ + /* print_csound_prsdata(csound,"Before do_macro", yyscanner); */ + do_macro(csound, yytext, yyscanner); + //print_csound_prsdata(csound,"After do_macro", yyscanner); + BEGIN(INITIAL); + } +{UNDEF} { + if (PARM->isString != 1) + BEGIN(umacro); + else + corfile_puts(yytext, csound->expanded_sco); + } +[ \t]* /* eat the whitespace */ +{IDENT} { + /* csound->DebugMsg(csound,"Undefine macro %s\n", yytext); */ + do_umacro(csound, yytext, yyscanner); + BEGIN(INITIAL); + } + +{IFDEF} { + if (PARM->isString != 1) { + PARM->isIfndef = (yytext[3] == 'n'); /* #ifdef or #ifndef */ + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + BEGIN(ifdef); + } + else { + corfile_puts(yytext, csound->expanded_sco); + } + } +[ \t]* /* eat the whitespace */ +{IDENT} { + do_ifdef(csound, yytext, yyscanner); + BEGIN(INITIAL); + } +{ELSE} { + if (PARM->isString != 1) { + if (PARM->ifdefStack == NULL) { + csound->Message(csound, Str("#else without #if\n")); + csound->LongJmp(csound, 1); + } + else if (PARM->ifdefStack->isElse) { + csound->Message(csound, Str("#else after #else\n")); + csound->LongJmp(csound, 1); + } + PARM->ifdefStack->isElse = 1; + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + do_ifdef_skip_code(csound, yyscanner); + } + else { + corfile_puts(yytext, csound->expanded_sco); + } + } +{END} { + if (PARM->isString != 1) { + IFDEFSTACK *pp = PARM->ifdefStack; + if (UNLIKELY(pp == NULL)) { + csound->Message(csound, Str("Unmatched #end\n")); + csound->LongJmp(csound, 1); + } + PARM->ifdefStack = pp->prv; + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + mfree(csound, pp); + } + else { + corfile_puts(yytext, csound->expanded_sco); + } + } +. { corfile_putc(yytext[0], csound->expanded_sco); } + +%% +void comment(yyscan_t yyscanner) /* Skip until nextline */ +{ + char c; + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + while ((c = input(yyscanner)) != '\n' && c != '\r') { /* skip */ + if (c == EOF) { + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + return; + } + } + if (c == '\r' && (c = input(yyscanner)) != '\n') { + if (c != EOF) + unput(c); + else + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); +} + +void do_comment(yyscan_t yyscanner) /* Skip until * and / chars */ +{ + char c; + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + for (;;) { + c = input(yyscanner); + if (UNLIKELY(c == '\r')) { /* skip */ + if ((c = input(yyscanner)) != '\n') + unput(c); + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + } + else if (UNLIKELY(c=='\n')) { /* skip */ + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + } + if (c == EOF) { + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + return; + } + if (c != '*') continue; + while ((c=input(yyscanner))=='*'); + if (c=='/') return; + if (UNLIKELY(c == '\r')) { + if ((c = input(yyscanner)) != '\n') + unput(c); + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + } + else if (UNLIKELY(c=='\n')) { + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + } + if (c == EOF) { + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + return; + } + } +} + +void do_include(CSOUND *csound, int term, yyscan_t yyscanner) +{ + char buffer[100]; + int p=0; + int c; + CORFIL *cf; + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + while ((c=input(yyscanner))!=term) { + buffer[p] = c; + p++; + } + buffer[p] = '\0'; + while ((c=input(yyscanner))!='\n'); + if (PARM->depth++>=1024) { + csound->Die(csound, Str("Includes nested too deeply")); + } + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), yyscanner); + csound->DebugMsg(csound,"line %d at end of #include line\n", csound_prsget_lineno(yyscanner)); + { + uint8_t n = file_to_int(csound, buffer); + char bb[16]; + PARM->lstack[PARM->depth] = n; + sprintf(bb, "#source %d\n", PARM->locn = make_location(PARM)); + PARM->llocn = PARM->locn; + corfile_puts(bb, csound->expanded_sco); + } + if (strstr(buffer, "://")) return cf = copyurl_corefile(csound, buffer, 1); + else cf = copy_to_corefile(csound, buffer, "INCDIR", 1); + if (cf == NULL) + csound->Die(csound, + Str("Cannot open #include'd file %s\n"), buffer); + csound->DebugMsg(csound,"%s(%d): stacking line %d at %d\n", __FILE__, __LINE__, + csound_prsget_lineno(yyscanner),PARM->macro_stack_ptr); + PARM->alt_stack[PARM->macro_stack_ptr].n = 0; + PARM->alt_stack[PARM->macro_stack_ptr].line = csound_prsget_lineno(yyscanner); + PARM->alt_stack[PARM->macro_stack_ptr++].s = NULL; + csound_prspush_buffer_state(YY_CURRENT_BUFFER, yyscanner); + csound_prs_scan_string(cf->body, yyscanner); + corfile_rm(&cf); + csound->DebugMsg(csound,"Set line number to 1\n"); + csound_prsset_lineno(1, yyscanner); +} + +static inline int isNameChar(int c, int pos) +{ + c = (int) ((unsigned char) c); + return (isalpha(c) || (pos && (c == '_' || isdigit(c)))); +} + +void do_macro_arg(CSOUND *csound, char *name0, yyscan_t yyscanner) +{ + MACRO *mm = (MACRO*) mmalloc(csound, sizeof(MACRO)); + int arg = 0, i, c; + int size = 100; + int mlen = 40; + char *mname = malloc(mlen); + mm->margs = MARGS; /* Initial size */ + mm->name = (char*)mmalloc(csound, strlen(name0) + 1); + strcpy(mm->name, name0); + do { + while (isspace((c = input(yyscanner)))); + i = 0; + + while (isNameChar(c, i)) { + mname[i++] = c; + if (UNLIKELY(i==mlen)) + mname = (char *)realloc(mname, mlen+=40); + c = input(yyscanner); + } + mname[i] = '\0'; + mm->arg[arg] = mmalloc(csound, i + 1); + strcpy(mm->arg[arg++], mname); + if (UNLIKELY(arg >= mm->margs)) { + mm = (MACRO*) mrealloc(csound, mm, sizeof(MACRO) + + mm->margs * sizeof(char*)); + mm->margs += MARGS; + } + while (isspace(c)) + c = input(yyscanner); + } while (c == '\'' || c == '#'); + if (UNLIKELY(c != ')')) { + csound->Message(csound, Str("macro error\n")); + } + free(mname); + while (c!='#') c = input(yyscanner); + mm->acnt = arg; + i = 0; + mm->body = (char*) mmalloc(csound, 100); + while ((c = input(yyscanner)) != '#') { + if (UNLIKELY(c == EOF)) + csound->Die(csound, Str("define macro with args: unexpected EOF")); + mm->body[i++] = c; + if (UNLIKELY(i >= size)) + mm->body = mrealloc(csound, mm->body, size += 100); + if (c == '\\') { /* allow escaped # */ + mm->body[i++] = c = input(yyscanner); + if (UNLIKELY(i >= size)) + mm->body = mrealloc(csound, mm->body, size += 100); + } + if (UNLIKELY(c == '\n')) { + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + } + } + mm->body[i] = '\0'; + mm->next = PARM->macros; + PARM->macros = mm; +} + +void do_macro(CSOUND *csound, char *name0, yyscan_t yyscanner) +{ + MACRO *mm = (MACRO*) mmalloc(csound, sizeof(MACRO)); + int i, c; + int size = 100; + mm->margs = MARGS; /* Initial size */ + /* csound->DebugMsg(csound,"Macro definition for %s\n", name0); */ + mm->name = (char*)mmalloc(csound, strlen(name0) + 1); + strcpy(mm->name, name0); + mm->acnt = 0; + i = 0; + while ((c = input(yyscanner)) != '#'); + mm->body = (char*) mmalloc(csound, 100); + while ((c = input(yyscanner)) != '#') { + if (UNLIKELY(c == EOF)) + csound->Die(csound, Str("define macro: unexpected EOF")); + mm->body[i++] = c; + if (UNLIKELY(i >= size)) + mm->body = mrealloc(csound, mm->body, size += 100); + if (c == '\\') { /* allow escaped # */ + mm->body[i++] = c = input(yyscanner); + if (UNLIKELY(i >= size)) + mm->body = mrealloc(csound, mm->body, size += 100); + } + if (UNLIKELY(c == '\n')) { + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + } + } + mm->body[i] = '\0'; + /* csound->DebugMsg(csound,"Body #%s#\n", mm->body); */ + mm->next = PARM->macros; + PARM->macros = mm; +} + +void do_umacro(CSOUND *csound, char *name0, yyscan_t yyscanner) +{ + int i,c; + if (UNLIKELY(csound->oparms->msglevel)) + csound->Message(csound,Str("macro %s undefined\n"), name0); + /* csound->DebugMsg(csound, "macro %s undefined\n", name0); */ + if (strcmp(name0, PARM->macros->name)==0) { + MACRO *mm=PARM->macros->next; + mfree(csound, PARM->macros->name); mfree(csound, PARM->macros->body); + for (i=0; imacros->acnt; i++) + mfree(csound, PARM->macros->arg[i]); + mfree(csound, PARM->macros); PARM->macros = mm; + } + else { + MACRO *mm = PARM->macros; + MACRO *nn = mm->next; + while (strcmp(name0, nn->name) != 0) { + mm = nn; nn = nn->next; + if (UNLIKELY(nn == NULL)) { + csound->Message(csound, Str("Undefining undefined macro")); + csound->LongJmp(csound, 1); + } + } + mfree(csound, nn->name); mfree(csound, nn->body); + for (i=0; iacnt; i++) + mfree(csound, nn->arg[i]); + mm->next = nn->next; mfree(csound, nn); + } + while ((c=input(yyscanner)) != '\n' && c != EOF); /* ignore rest of line */ + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner),yyscanner); +} + +void do_ifdef(CSOUND *csound, char *name0, yyscan_t yyscanner) +{ + int c; + MACRO *mm; + IFDEFSTACK *pp; + pp = (IFDEFSTACK*) mcalloc(csound, sizeof(IFDEFSTACK)); + pp->prv = PARM->ifdefStack; + pp->isDef = PARM->isIfndef; + for (mm = PARM->macros; mm != NULL; mm = mm->next) { + if (strcmp(name0, mm->name) == 0) { + pp->isDef ^= (unsigned char) 1; + break; + } + } + PARM->ifdefStack = pp; + pp->isSkip = pp->isDef ^ (unsigned char) 1; + if (pp->isSkip) + do_ifdef_skip_code(csound, yyscanner); + else + while ((c = input(yyscanner)) != '\n' && c != EOF); +} + +void do_ifdef_skip_code(CSOUND *csound, yyscan_t yyscanner) +{ + int i, c, nested_ifdef = 0; + char *buf; + IFDEFSTACK *pp; + buf = (char*)malloc(8*sizeof(char)); + pp = PARM->ifdefStack; + c = input(yyscanner); + for (;;) { + while (c!='\n') { + if (UNLIKELY(c == EOF)) { + csound->Message(csound, Str("Unmatched #if%sdef\n"), + PARM->isIfndef ? "n" : ""); + csound->LongJmp(csound, 1); + } + c = input(yyscanner); + } + csound_prsset_lineno(1+csound_prsget_lineno(yyscanner), + yyscanner); + corfile_putc('\n', csound->expanded_sco); + csound_prs_line(csound->expanded_sco, yyscanner); + while (isblank(c = input(yyscanner))); /* eat the whitespace */ + if (c == '#') { + for (i=0; islower(c = input(yyscanner)) && i < 7; i++) + buf[i] = c; + buf[i] = '\0'; + if (strcmp("end", buf) == 0 || strcmp("endif", buf) == 0) { + if (nested_ifdef-- == 0) { + PARM->ifdefStack = pp->prv; + mfree(csound, pp); + break; + } + } + else if (strcmp("ifdef", buf) == 0 || strcmp("ifndef", buf) == 0) { + nested_ifdef++; + } + else if (strcmp("else", buf) == 0 && nested_ifdef == 0) { + if (pp->isElse) { + csound->Message(csound, Str("#else after #else\n")); + csound->LongJmp(csound, 1); + } + pp->isElse = 1; + break; + } + } + } + free(buf); + while (c != '\n' && c != EOF) c = input(yyscanner); +} + +void cs_init_smacros(CSOUND *csound, PRS_PARM *qq, NAMES *nn) +{ + while (nn) { + char *s = nn->mac; + char *p = strchr(s, '='); + char *mname; + MACRO *mm; + + if (p == NULL) + p = s + strlen(s); + if (csound->oparms->msglevel & 7) + csound->Message(csound, Str("Macro definition for %*s\n"), p - s, s); + s = strchr(s, ':') + 1; /* skip arg bit */ + if (UNLIKELY(s == NULL || s >= p)) { + csound->Die(csound, Str("Invalid macro name for --smacro")); + } + mname = (char*) mmalloc(csound, (p - s) + 1); + strncpy(mname, s, p - s); + mname[p - s] = '\0'; + /* check if macro is already defined */ + for (mm = qq->macros; mm != NULL; mm = mm->next) { + if (strcmp(mm->name, mname) == 0) + break; + } + if (mm == NULL) { + mm = (MACRO*) mcalloc(csound, sizeof(MACRO)); + mm->name = mname; + mm->next = qq->macros; + qq->macros = mm; + } + else + mfree(csound, mname); + mm->margs = MARGS; /* Initial size */ + mm->acnt = 0; + if (*p != '\0') + p++; + mm->body = (char*) mmalloc(csound, strlen(p) + 1); + strcpy(mm->body, p); + nn = nn->next; + } +} + +void csound_prs_line(CORFIL* cf, void *yyscanner) +{ + int n = csound_prsget_lineno(yyscanner); + /* This assumes that the initial line was not written with this system */ + if (cf->body[cf->p-1]=='\n') { + int locn = PARM->locn; + int llocn = PARM->llocn; + if (locn != llocn) { + char bb[80]; + sprintf(bb, "#source %d\n", locn); + corfile_puts(bb, cf); + } + PARM->llocn = locn; + if (n!=PARM->line+1) { + char bb[80]; + sprintf(bb, "#line %d\n", n); + corfile_puts(bb, cf); + } + } + PARM->line = n; +} + +#ifdef MAIN_NEEDED +int main(void) +{ + PRS_PARM qq; + int len=100, p=0, n; + char buff[1024]; + /* FILE *fd = fopen("III", "r"); */ + + /* inp = (char*)calloc(100,1); */ + /* memset(buff, '\0', 1024); */ + /* while ((n = fread(buff, 1, 1023, fd))) { */ + /* while (p+n+1>=len) */ + /* inp = (char*) realloc(inp, len+=100); */ + /* strcat(inp, buff); */ + /* p += n; */ + /* memset(buff, '\0', 1024); */ + /* } */ + /* if (n+8>= len) inp = (char*) realloc(inp, len = n+9); */ + /* strcat(inp, "\n#exit\0\0"); */ + /* rewind(fd); */ + + memset(&qq, '\0', sizeof(PRS_PARM)); + csound_prslex_init(&qq.yyscanner); + csound_prsset_extra(&qq, qq.yyscanner); + //csound_prsset_debug(1, &qq.yyscanner); + //csound_prspush_buffer_state(NULL, &qq.yyscanner); + //csound_prs_scan_string(inp, qq.yyscanner); + //csound_prsset_in(NULL, qq.yyscanner); + qq.line = 1; + csound_prslex(NULL, qq.yyscanner); + //csound->DebugMsg(csound,corfile_body(expanded_prs)); + //csound_prslex_destroy(&qq.yyscanner); + return 0; +} +#endif + + + + diff -Nru csound-5.17.11~dfsg/Engine/csound_sco.lex csound-6.02~dfsg/Engine/csound_sco.lex --- csound-5.17.11~dfsg/Engine/csound_sco.lex 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_sco.lex 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,212 @@ +%{ + + /* + csound_sco.lex: + + Copyright (C) 2013 March + John ffitch + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include +#include +#include +#include +#include "csoundCore.h" +#include "score_param.h" +#include "csound_scoparse.h" + +#define YYSTYPE MYFLT +#define YYLTYPE SCOTOKEN +#define YY_DECL int yylex (YYLTYPE *lvalp, CSOUND *csound, yyscan_t yyscanner) +#include "corfile.h" +YYLTYPE *yylval_param; +YYLTYPE *yylloc_param; +static SCOTOKEN *make_string(CSOUND *, char *); +static SCOTOKEN *make_int(CSOUND *, int); +static SCOTOKEN *make_num(CSOUND *, double); +extern void *fopen_path(CSOUND *, FILE **, char *, char *, char *, int); + +#define YY_EXTRA_TYPE SCORE_PARM * +#define PARM yyget_extra(yyscanner) + +#define YY_USER_INIT + +struct yyguts_t; +static SCOTOKEN *do_at(CSOUND *, int, struct yyguts_t*); +%} +%option reentrant +%option bison-bridge +%option bison-locations +%option prefix="csound_sco" +%option outfile="Engine/csound_scolex.c" +%option stdout + +STRCONST \"(\\.|[^\"])*\" +STRCONSTe \"(\\.|[^\"])*$ +INTGR [0-9]+ +NUMBER [0-9]+\.?[0-9]*(e[-+]?[0-9]+)?|\.[0-9]+(e[-+]?[0-9]+)?|0[xX][0-9a-fA-F]+ +WHITE [ \t]+ +OPTWHITE [ \t]* +CONT \\[ \t]*(;.*)?\n +LINE ^[ \t]*"#line" +FILE ^[ \t]*"#source" +FNAME [a-zA-Z0-9/:.+-_]+ +NPX "np^"${INTGR} +PPX "pp^"${INTGR} + +%x line +%x src +%x xstr + +%% +"\r" { } /* EATUP THIS PART OF WINDOWS NEWLINE */ + +{CONT} { csound_scoset_lineno(1+csound_scoget_lineno(yyscanner), + yyscanner); + } +"\n" { csound_scoset_lineno(1+csound_scoget_lineno(yyscanner), + yyscanner); + return '\n'; } +"a" { return yytext[0];} +"b" { return yytext[0];} +"e" { return yytext[0];} +"f" { return yytext[0];} +"i" { return yytext[0];} +"m" { return yytext[0];} +"n" { return yytext[0];} +"q" { return yytext[0];} +"r" { return yytext[0];} +"s" { return yytext[0];} +"t" { return yytext[0];} +"v" { return yytext[0];} +"x" { return yytext[0];} +"(" { return '('; } +")" { return ')'; } +"[" { return '['; } +"]" { return ']'; } +"{" { return '}'; } +"}" { return '}'; } +"+" { return '+'; } +"-" { return '-'; } +"*" { return '*'; } +"/" { return '/'; } +"%" { return '%'; } +"\^" { return '^'; } +"!" { return '!'; } +">" { return '>'; } +"<" { return '<'; } +"|" { return '|'; } +"&" { return '&'; } +"#" { return '#'; } +"~" { return '~'; } +"." { return '.'; } +"@@"{OPTWHITE}{INTGR} { lvalp = do_at(csound, 1, yyg); + return INTEGER_TOKEN; } +"@"{OPTWHITE}{INTGR} { lvalp = do_at(csound, 0, yyg); + return INTEGER_TOKEN; } + +{STRCONST} { lvalp = make_string(csound, yytext); + return (STRING_TOKEN); } + +{STRCONSTe} { lvalp = make_string(csound, yytext); + csound->Message(csound, + Str("unterminated string found on line %d >>%s<<\n"), + csound_scoget_lineno(yyscanner), + yytext); + return (STRING_TOKEN); } + +{INTGR} { + lvalp = make_int(csound, atoi(yytext)); return (INTEGER_TOKEN); + } +{NUMBER} { lvalp = make_num(csound, atof(yytext)); return (NUMBER_TOKEN); } + +{WHITE} { } + +{LINE} { BEGIN(line); } + +[ \t]* /* eat the whitespace */ +{INTGR} { csound_scoset_lineno(atoi(yytext), yyscanner); } +"\n" {BEGIN(INITIAL);} + +{FILE} { BEGIN(src); } + +[ \t]* /* eat the whitespace */ +{FNAME} { PARM->locn = atoi(yytext); } +"\n" { BEGIN(INITIAL); } + + +<> { + yyterminate(); + } + +. { fprintf(stderr, "unknown character %c(%.2x)\n", + yytext[0], yytext[0]); + } + +%% + +static SCOTOKEN *make_string(CSOUND *csound, char *s) +{ + SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN)); + ans->type = STRING_TOKEN; + ans->strbuff = strdup(s); + return ans; +} + +static SCOTOKEN *make_int(CSOUND *csound, int i) +{ + SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN)); + ans->type = INTEGER_TOKEN; + ans->ival = i; + return ans; +} + +static SCOTOKEN *make_num(CSOUND *csound, double f) +{ + SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN)); + ans->type = NUMBER_TOKEN; + ans->fval = (MYFLT)f; + return ans; +} + +static SCOTOKEN *do_at(CSOUND *csound, int k, struct yyguts_t *yyg) +{ + SCOTOKEN *ans = (SCOTOKEN*)mcalloc(csound, sizeof(SCOTOKEN)); + int n, i = 1; + char *s = yytext; + while (*s=='@') s++; + n = atoi(s); + while (i<=n-k && i< 0x4000000) i <<= 1; + ans->type = INTEGER_TOKEN; + ans->ival = i; + return ans; +} + +char *csound_scoget_current_pointer(void *yyscanner) +{ + struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + return yyg->yy_c_buf_p; +} + +int csound_scoget_locn(void *yyscanner) +{ +// struct yyguts_t *yyg = (struct yyguts_t*)yyscanner; + return PARM->locn; +} diff -Nru csound-5.17.11~dfsg/Engine/csound_sco.y csound-6.02~dfsg/Engine/csound_sco.y --- csound-5.17.11~dfsg/Engine/csound_sco.y 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_sco.y 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,239 @@ +/* + csound_sco.y: + + Copyright (C) 2013 + John ffitch + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ +%pure_parser +%parse-param {SCORE_PARM *parm} +%parse-param {void *scanner} +%lex-param { CSOUND * csound } +%lex-param {yyscan_t *scanner} + +%token NEWLINE + +%token T_ERROR + +%token STRING_TOKEN +%token INTEGER_TOKEN +%token NUMBER_TOKEN + +%start scolines +%left S_AND S_OR +%left '|' +%left '&' +%left S_LT S_GT S_LEQ S_GEQ S_EQ S_NEQ +%left S_BITSHIFT_LEFT S_BITSHIFT_RIGHT +%left '+' '-' +%left '*' '/' '%' +%left '^' +%left '#' +%right '~' +%right S_UNOT +%right S_UMINUS +%token T_HIGHEST +%pure_parser +%error-verbose + //%parse-param { CSOUND * csound } + +/* NOTE: Perhaps should use %union feature of bison */ + +%{ +#ifndef NULL +#define NULL 0L +#endif +#include "csoundCore.h" +#include +#include +#include +#include +#include "score_param.h" +extern void csound_scoerror(SCORE_PARM *, void *, const char*); + //extern int csound_scolex(TREE**, CSOUND *, void *); +#define LINE csound_scoget_lineno() +#define LOCN csound_scoget_locn() +extern int csound_orcget_locn(void *); +extern int csound_orcget_lineno(void *); +#define csound 0 +%} +%token NP +%token PP +%% + +scoline : statement + { + + } + | '{' scolines '}' + { + } + ; + +scolines : scoline scolines + { + + } + | { } + ; + +statement : op arglist NEWLINE + { + printf("op=%c\n"); + } + ; + +op : 'i' { $$ = $1; } + | 'f' { $$ = $1; } + | 'a' { $$ = $1; } + | 'e' { $$ = $1; } + | 's' { $$ = $1; } + | 't' { $$ = $1; } + ; + +arglist : arg arglist {} + | { parm->arglist = NULL; } + ; + +arg : NUMBER_TOKEN { $$ = parm->fval;} + | INTEGER_TOKEN { $$ = (MYFLT)parm->ival;} + | STRING_TOKEN {} + | '[' exp ']' { $$ = $2; } + | NP + | PP + +exp : exp '+' exp { $$ = $1 + $3; } + | exp '+' error + | exp '-' exp { $$ = $1 - $3; } + | exp '-' error + | '-' exp %prec S_UMINUS { $$ = - $2; } + | '-' error { } + | '+' exp %prec S_UMINUS { $$ = $2; } + | '+' error { } +| term { $$ = $1; } + ; + +term : exp '*' exp { $$ = $1 * $3; } + | exp '*' error + | exp '/' exp { $$ = $1 / $3; } + | exp '/' error + | exp '^' exp { $$ = pow($1, $3); } + | exp '^' error + | exp '%' exp { $$ = $1 % $3; } + | exp '%' error + | fac { $$ = $1; } + ; + +fac : constant { $$ = $1; } + | exp '|' exp { $$ = (int)$1 | (int)$3; } + | exp '|' error + | exp '&' exp { $$ = (int)$1 & (int)$3; } + | exp '&' error + | exp '#' exp { $$ = (int)$1 ^ (int)$3; } + | exp '#' error + | exp S_BITSHIFT_LEFT exp + { $$ = (int)$1 << (int)$3; } + | exp S_BITSHIFT_LEFT error + | exp S_BITSHIFT_RIGHT exp + { $$ = (int)$1 >> (int)$3; } + | exp S_BITSHIFT_RIGHT error + | '~' exp %prec S_UMINUS + { $$ = ~(int)$2; } + | '~' error { $$ = 0; } + | '(' exp ')' { $$ = $2; } + | '(' exp error { $$ = 0; } + | '(' error { $$ = 0; } + ; + +constant : NUMBER_TOKEN { $$ = parm->fval; } + | INTEGER_TOKEN { $$ = (MYFLT)parm->ival; } + ; + +%% + +#ifdef SOME_FINE_DAY +void +yyerror(char *s, ...) +{ + va_list ap; + va_start(ap, s); + + if(yylloc.first_line) + fprintf(stderr, "%d.%d-%d.%d: error: ", + yylloc.first_line, yylloc.first_column, + yylloc.last_line, yylloc.last_column); + vfprintf(stderr, s, ap); + fprintf(stderr, "\n"); + +} + +void +lyyerror(YYLTYPE t, char *s, ...) +{ + va_list ap; + va_start(ap, s); + + if(t.first_line) + fprintf(stderr, "%d.%d-%d.%d: error: ", t.first_line, t.first_column, + t.last_line, t.last_column); + vfprintf(stderr, s, ap); + fprintf(stderr, "\n"); +} + +#endif + +void +csound_scoerror(SCORE_PARM *parm, void *yyg, const char* s) +{ + fprintf(stderr, s); +} + +int csound_scowrap() +{ +#ifdef DEBUG + printf("\n === END OF INPUT ===\n"); +#endif + return (1); +} + +#if 0 +int yylex(void) +{ + int c; + while ((c=getchar())==' '); + if (isdigit(c)) { + int n = c-'0'; + while (isdigit(c=getchar())) { + n = 10*n+c-'0'; + } + ungetc(c, stdin); + return NUMBER_TOKEN; + } + return c=='\n' ? NEWLINE : c; +} + +extern int csound_scodebug; +int main(void) +{ + csound_scodebug = 1; + yyparse(); + return 0; +} + +#endif diff -Nru csound-5.17.11~dfsg/Engine/csound_standard_types.c csound-6.02~dfsg/Engine/csound_standard_types.c --- csound-5.17.11~dfsg/Engine/csound_standard_types.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_standard_types.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,246 @@ +/* + csound_standard_types.c: + + Copyright (C) 2012,2013 Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + */ + +#include "csoundCore.h" +#include "csound_standard_types.h" +#include "pstream.h" +#include + +//#define Wfloats (((int) sizeof(SPECDAT) + 7) / (int) sizeof(MYFLT)) +//#define Pfloats (((int) sizeof(PVSDAT) + 7) / (int) sizeof(MYFLT)) + +void updateAsigMemBlock(void* csound, CS_VARIABLE* var) { + CSOUND* cs = (CSOUND*)csound; + int ksmps = cs->ksmps; + var->memBlockSize = ksmps * sizeof (MYFLT); +} + +void varInitMemory(CS_VARIABLE* var, MYFLT* memblock) { + memset(memblock, 0, var->memBlockSize); +} + + +CS_VARIABLE* createAsig(void* cs, void* p) { + int ksmps; + CSOUND* csound = (CSOUND*)cs; + IGN(p); + + //FIXME - this needs to take into account local ksmps, once + //context work is complete +// if(instr != NULL) { +// OPDS* p = (OPDS*)instr; +// ksmps = CS_KSMPS; +// } else { + ksmps = csound->ksmps; +// } + + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + var->memBlockSize = ksmps * sizeof (MYFLT); + var->updateMemBlockSize = &updateAsigMemBlock; + var->initializeVariableMemory = &varInitMemory; + return var; +} + +CS_VARIABLE* createMyflt(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + IGN(p); + var->memBlockSize = sizeof (MYFLT); + var->initializeVariableMemory = &varInitMemory; + return var; +} + +CS_VARIABLE* createBool(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + IGN(p); + var->memBlockSize = sizeof (MYFLT); + var->initializeVariableMemory = &varInitMemory; + return var; +} + +CS_VARIABLE* createWsig(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + IGN(p); + var->memBlockSize = sizeof(SPECDAT); + var->initializeVariableMemory = &varInitMemory; + return var; +} + +CS_VARIABLE* createFsig(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + IGN(p); + var->memBlockSize = sizeof(PVSDAT); + var->initializeVariableMemory = &varInitMemory; + return var; +} + +void arrayInitMemory(CS_VARIABLE* var, MYFLT* memblock) { + ARRAYDAT* dat = (ARRAYDAT*)memblock; + dat->arrayType = var->subType; +} + +CS_VARIABLE* createString(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + IGN(p); + var->memBlockSize = sizeof(STRINGDAT); + return var; +} + +CS_VARIABLE* createArray(void* csound, void* p) { + CSOUND* cs = (CSOUND*)csound; + ARRAY_VAR_INIT* state = (ARRAY_VAR_INIT*)p; + + + CS_VARIABLE* var = mcalloc(cs, sizeof (CS_VARIABLE)); + var->memBlockSize = sizeof(ARRAYDAT); + var->initializeVariableMemory = &arrayInitMemory; + + if(state) { // NB: this function is being called with p=NULL + CS_TYPE* type = state->type; + var->subType = type; + var->dimensions = state->dimensions; + } + return var; +} + + +//#define ARGTYP_S 0x00000040L /* string constant or variable */ +//#define ARGTYP_l 0x00000800L /* label */ + +const CS_TYPE CS_VAR_TYPE_A = { + "a", "audio rate vector", CS_ARG_TYPE_BOTH, createAsig, NULL +}; + +const CS_TYPE CS_VAR_TYPE_K = { + "k", "control rate var", CS_ARG_TYPE_BOTH, createMyflt, NULL +}; + +const CS_TYPE CS_VAR_TYPE_I = { + "i", "init time var", CS_ARG_TYPE_BOTH, createMyflt, NULL +}; + +const CS_TYPE CS_VAR_TYPE_S = { + "S", "String var", CS_ARG_TYPE_BOTH, createString, NULL +}; + +const CS_TYPE CS_VAR_TYPE_P = { + "p", "p-field", CS_ARG_TYPE_BOTH, createMyflt, NULL +}; + +const CS_TYPE CS_VAR_TYPE_R = { + "r", "reserved symbol", CS_ARG_TYPE_BOTH, createMyflt, NULL +}; + +const CS_TYPE CS_VAR_TYPE_C = { + "c", "constant", CS_ARG_TYPE_IN, createMyflt, NULL +}; + +const CS_TYPE CS_VAR_TYPE_W = { + "w", "spectral", CS_ARG_TYPE_BOTH, createWsig, NULL +}; + +const CS_TYPE CS_VAR_TYPE_F = { + "f", "f-sig", CS_ARG_TYPE_BOTH, createFsig, NULL +}; + +const CS_TYPE CS_VAR_TYPE_B = { + "B", "boolean", CS_ARG_TYPE_BOTH, createBool, NULL +}; + +const CS_TYPE CS_VAR_TYPE_b = { + "b", "boolean", CS_ARG_TYPE_BOTH, createBool, NULL +}; + +const CS_TYPE CS_VAR_TYPE_ARRAY = { + "[", "array", CS_ARG_TYPE_BOTH, createArray, NULL +}; + + + +void csoundAddStandardTypes(CSOUND* csound, TYPE_POOL* pool) { + + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_A); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_K); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_I); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_S); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_P); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_R); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_C); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_W); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_F); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_B); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_b); + csoundAddVariableType(csound, pool, (CS_TYPE*)&CS_VAR_TYPE_ARRAY); + +} + + +/* Type maps for poly, optional, and var arg types + * format is in pairs of specified type and types it can resolve into, + * termintated by a NULL */ +const char* POLY_IN_TYPES[] = { + "x", "kacpri", + "T", "Sicpr", + "U", "Sikcpr", + "i", "cpri", + "k", "cprki", + "B", "Bb", NULL}; +const char* OPTIONAL_IN_TYPES[] = { + "o", "icpr", + "p", "icpr", + "q", "icpr", + "v", "icpr", + "j", "icpr", + "h", "icpr", + "O", "kicpr", + "J", "kicpr", + "V", "kicpr", + "P", "kicpr", NULL +}; +const char* VAR_ARG_IN_TYPES[] = { + "m", "icrp", + "M", "icrpka", + "N", "icrpkaS", + "n", "icrp", /* this one requires odd number of args... */ + "y", "a", + "z", "kicrp", + "Z", "kaicrp", NULL /* this one needs to be ka alternatating... */ +}; + +const char* POLY_OUT_TYPES[] = { + "s", "ka", + "i", "pi", NULL +}; + +const char* VAR_ARG_OUT_TYPES[] = { + "m", "a", + "z", "k", + "I", "Sip", /* had comment of (not implemented yet) in entry1.c */ + "X", "akip", + "N", "akipS", + "F", "f", NULL +}; diff -Nru csound-5.17.11~dfsg/Engine/csound_type_system.c csound-6.02~dfsg/Engine/csound_type_system.c --- csound-5.17.11~dfsg/Engine/csound_type_system.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/csound_type_system.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,297 @@ +/* + csound_type_system.c: + + Copyright (C) 2012,2013 Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + */ + +#include "csound_type_system.h" +#include +#include +#include "csoundCore.h" + +int csTypeExistsWithSameName(TYPE_POOL* pool, CS_TYPE* typeInstance) { + CS_TYPE_ITEM* current = pool->head; + while (current != NULL) { + + /* printf("Search if type [%s] == [%s]", + current->varTypeName, typeInstance->varTypeName); */ + + if (strcmp(current->cstype->varTypeName, + typeInstance->varTypeName) == 0) { + return 1; + } + current = current->next; + } + + return 0; +} + +CS_TYPE* csoundGetTypeWithVarTypeName(TYPE_POOL* pool, char* typeName) { + CS_TYPE_ITEM* current = pool->head; + while (current != NULL) { + if (strcmp(typeName, current->cstype->varTypeName) == 0) { + return current->cstype; + } + current = current->next; + } + return NULL; +} + +CS_TYPE* csoundGetTypeForVarName(TYPE_POOL* pool, char* varName) { + CS_TYPE_ITEM* current = pool->head; + char temp[2]; + temp[0] = varName[0]; + temp[1] = 0; + while (current != NULL) { + if (strcmp(temp, current->cstype->varTypeName) == 0) { + return current->cstype; + } + current = current->next; + } + return NULL; +} + +int csoundAddVariableType(CSOUND* csound, TYPE_POOL* pool, CS_TYPE* typeInstance) +{ + CS_TYPE_ITEM* item; + if (csTypeExistsWithSameName(pool, typeInstance)) { + return 0; + } + + item = (CS_TYPE_ITEM*)mcalloc(csound, sizeof(CS_TYPE_ITEM)); + item->cstype = typeInstance; + + if (pool->head == NULL) { + pool->head = item; + } else { + CS_TYPE_ITEM* current = pool->head; + while (current->next) { + current = current->next; + } + current->next = item; + item->next = NULL; + } + + /* printf("Adding type with type name: %s\n", typeInstance->varTypeName); */ + + return 1; +} + +/* VAR POOL FUNCTIONS */ + +char* getVarSimpleName(CSOUND* csound, const char* varName) { + char* retVal; + + if (varName[0] != '[') { + retVal = (char*)mcalloc(csound, sizeof(char) * (strlen(varName) + 1)); + strcpy(retVal, varName); + } else { + int start = 0; + int typeEnd = 0; + int len = strlen(varName); + int newFirstLen, newSecondLen, newTotalLen; + char* t = (char*) varName; + char* t2; + + while(*t == '[') { + t++; + start++; + } + typeEnd = start; + t2 = t; + while(*t2 != ']' && *t2 != (char)0) { + t2++; + typeEnd++; + } + t2++; + typeEnd++; + + newFirstLen = (typeEnd - start - 1); + newSecondLen = (len - typeEnd); + newTotalLen = newFirstLen + newSecondLen; + + retVal = (char*)mcalloc(csound, sizeof(char) * (newTotalLen + 1)); + strncpy(retVal, t, newFirstLen); + strncpy(retVal + newFirstLen, t2, newSecondLen); + } + + return retVal; +} + +CS_VARIABLE* csoundCreateVariable(void* csound, TYPE_POOL* pool, + CS_TYPE* type, char* name, void* typeArg) +{ + CS_TYPE_ITEM* current = pool->head; + while (current != NULL) { + if (strcmp(type->varTypeName, current->cstype->varTypeName) == 0) { + CS_VARIABLE* var = current->cstype->createVariable(csound, typeArg); + var->varType = type; + var->varName = cs_strdup(csound, name); + return var; + } + current = current->next; + } + return NULL; +} + +//CS_VARIABLE* csoundFindVariableWithName(CSOUND* csound, CS_VAR_POOL* pool, +// const char* name) { +CS_VARIABLE* csoundFindVariableWithName(CS_VAR_POOL* pool, const char* name) +{ + CS_VARIABLE* current = pool->head; + CS_VARIABLE* returnValue = NULL; + + if(current != NULL && name != NULL) { + while(current != NULL) { + if (strcmp(current->varName, name) == 0) { + returnValue = current; + break; + } + current = current->next; + } + } + + if (returnValue == NULL && pool->parent != NULL) { + returnValue = csoundFindVariableWithName(pool->parent, name); + } + + return returnValue; +} + +CS_VARIABLE* csoundGetVariable(CS_VAR_POOL* pool, int index) { + + CS_VARIABLE* current = pool->head; + int i; + + for(i = 0; i < index || current != NULL; i++) { + /* THIS WAS WRONG!! && or || meant foR , ?? */ + current = current->next; + } + + return current; +} + +int csoundFindVariable(CS_VAR_POOL* pool, const char* name) { + CS_VARIABLE* current = pool->head; + int returnValue = -1; + int counter = 0; + + if(current != NULL && name != NULL) { + while(current != NULL) { + if (strcmp(current->varName, name) == 0) { + returnValue = counter; + break; + } + current = current->next; + counter++; + } + } + + return returnValue; +} + + +int csoundAddVariable(CS_VAR_POOL* pool, CS_VARIABLE* var) { + if(pool->head == NULL) { + pool->head = var; + } else { + CS_VARIABLE* varCurrent = pool->head; + while(varCurrent->next != NULL) { + varCurrent = varCurrent->next; + } + varCurrent->next = var; + } + // may need to revise this; var pools are accessed as MYFLT*, + // so need to ensure all memory is aligned to sizeof(MYFLT) + // boundaries maybe should align block size here to +7 before dividing? + var->memBlockIndex = pool->poolSize / sizeof(MYFLT); + pool->poolSize += var->memBlockSize; + + return 0; +} + +void recalculateVarPoolMemory(void* csound, CS_VAR_POOL* pool) +{ + CS_VARIABLE* current = pool->head; + pool->poolSize = 0; + + while (current != NULL) { + /* VL 26-12-12: had to revert these lines to avoid memory crashes + with higher ksmps */ + if(current->updateMemBlockSize != NULL) { + current->updateMemBlockSize(csound, current); + } + + current->memBlockIndex = pool->poolSize / sizeof(MYFLT); + pool->poolSize += current->memBlockSize; + + current = current->next; + } +} + +void reallocateVarPoolMemory(void* csound, CS_VAR_POOL* pool) { + CS_VARIABLE* current = pool->head; + pool->poolSize = 0; + + while (current != NULL) { + if(current->updateMemBlockSize != NULL) { + current->updateMemBlockSize(csound, current); + } + current->memBlock = + (MYFLT *)((CSOUND *)csound)->ReAlloc(csound,current->memBlock, + current->memBlockSize); + pool->poolSize += current->memBlockSize; + current = current->next; + } +} + +void deleteVarPoolMemory(void* csound, CS_VAR_POOL* pool) { + CS_VARIABLE* current = pool->head, *tmp; + while (current != NULL) { + tmp = current; + mfree((CSOUND *)csound, current->memBlock); + current = current->next; + mfree((CSOUND *)csound, tmp); + } +} + + + +void initializeVarPool(MYFLT* memBlock, CS_VAR_POOL* pool) { + CS_VARIABLE* current = pool->head; + + while (current != NULL) { + if (current->initializeVariableMemory != NULL) { + current->initializeVariableMemory(current, + memBlock + current->memBlockIndex); + } + current = current->next; + } +} + +void debug_print_varpool(CSOUND* csound, CS_VAR_POOL* pool) { + CS_VARIABLE* gVar = pool->head; + int count = 0; + while(gVar != NULL) { + csound->Message(csound, " %d) %s:%s\n", count++, + gVar->varName, gVar->varType->varTypeName); + gVar = gVar->next; + } +} diff -Nru csound-5.17.11~dfsg/Engine/entry1.c csound-6.02~dfsg/Engine/entry1.c --- csound-5.17.11~dfsg/Engine/entry1.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/entry1.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,957 +1,1161 @@ /* - entry1.c: + entry1.c: - Copyright (C) 1991 Barry Vercoe, John ffitch + Copyright (C) 1991 Barry Vercoe, John ffitch - This file is part of Csound. + This file is part of Csound. - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ #include "entry1.h" /* ENTRY1.C */ #include "interlocks.h" /* thread vals, where isub=1, ksub=2, asub=4: - 0 = 1 OR 2 (B out only) - 1 = 1 - 2 = 2 - 3 = 1 AND 2 - 4 = 4 - 5 = 1 AND 4 - 7 = 1 AND (2 OR 4) */ + 0 = 1 OR 2 (B out only) + 1 = 1 + 2 = 2 + 3 = 1 AND 2 + 4 = 4 + 5 = 1 AND 4 + 7 = 1 AND (2 OR 4) */ /* inarg types include the following: - i irate scalar - k krate scalar - a arate vector - f frequency variable - w spectral variable - x krate scalar or arate vector - S String - T String or i-rate - U String or i/k-rate - B Boolean - l Label - and codes - m begins an indef list of iargs (any count) - M begins an indef list of args (any count/rate i,k,a) - N begins an indef list of args (any count/rate i,k,a,S) - n begins an indef list of iargs (nargs odd) - o optional i-rate, defaulting to 0 - p " " 1 - q " " 10 - v " " .5 - j " " -1 - h " " 127 - O optional k-rate, defaulting to 0 - J " " -1 - V " " .5 - P " " 1 - y begins indef list of aargs (any count) - z begins indef list of kargs (any count) - Z begins alternating kakaka...list (any count) */ + i irate scalar + k krate scalar + a arate vector + f frequency variable + w spectral variable + x krate scalar or arate vector + S String + T String or i-rate + U String or i/k-rate + B Boolean + l Label + . required arg of any-type + and codes + ? optional arg of any-type + m begins an indef list of iargs (any count) + M begins an indef list of args (any count/rate i,k,a) + N begins an indef list of args (any count/rate i,k,a,S) + n begins an indef list of iargs (nargs odd) + o optional i-rate, defaulting to 0 + p " " 1 + q " " 10 + v " " .5 + j " " -1 + h " " 127 + O optional k-rate, defaulting to 0 + J " " -1 + V " " .5 + P " " 1 + y begins indef list of aargs (any count) + z begins indef list of kargs (any count) + Z begins alternating kakaka...list (any count) */ /* outarg types include: - m multiple out aargs - z multiple out kargs - I multiple out irate (not implemented yet) - s arate or krate scalar - X multiple args (a, k, or i-rate) IV - Sep 1 2002 - N multiple args (a, k, i, or S-rate) - F multiple args (f-rate) - (these types must agree with rdorch.c) */ - -/* If dsblksize is 0xffff then translate on output arg - 0xfffe then translate two (oscil) - 0xfffd then translate on first input arg (peak) - 0xfffc then translate two (divz) - 0xfffb then translate on first input arg (loop_l) */ + * multiple out args of any-type + m multiple out aargs + z multiple out kargs + I multiple out irate (not implemented yet) + s deprecated (use a or k as required) + X multiple args (a, k, or i-rate) IV - Sep 1 2002 + N multiple args (a, k, i, or S-rate) + F multiple args (f-rate) + */ + OENTRY opcodlst_1[] = { -/* opcode dspace thread outarg inargs isub ksub asub */ -{ "" }, -{ "instr", 0, 0, "", "" }, -{ "endin", 0, 0, "", "" }, -/* IV - Sep 8 2002 */ -{ "opcode", 0, 0, "", "", NULL, NULL, NULL }, -{ "endop", 0, 0, "", "", NULL, NULL, NULL }, -{ "$label", S(LBLBLK), 0, "", "" }, -{ "pset", S(PVSET), 0, "", "m" }, -{ "ctrlinit",S(CTLINIT),1, "", "im", ctrlinit }, -{ "massign",S(MASSIGN), 1, "", "iTp", massign }, -{ "turnon", S(TURNON), 1, "", "To", turnon }, -{ "remoteport", S(REMOTEPORT), 1, "", "i", remoteport }, -{ "insremot",S(INSREMOT),1, "", "SSm", insremot }, -{ "midremot",S(MIDREMOT),1, "", "SSm", midremot }, -{ "insglobal",S(INSGLOBAL),1, "", "Sm", insglobal }, -{ "midglobal",S(MIDGLOBAL),1, "", "Sm", midglobal }, -{ "=", 0, 0, "", "" }, -{ "init", 0xffff /* base names for later prefixes,suffixes */ }, -{ "betarand",0xffff }, -{ "bexprnd", 0xffff }, -{ "cauchy", 0xffff }, -{ "cauchyi", 0xffff }, -{ "chanctrl",0xffff }, -{ "cpsmidib",0xffff }, -{ "exprand", 0xffff }, -{ "exprandi",0xffff }, -{ "gauss" , 0xffff }, -{ "gaussi" , 0xffff }, -{ "limit", 0xffff, }, -{ "linrand", 0xffff }, -{ "midictrl",0xffff }, -{ "polyaft", 0xffff }, -{ "ntrpol", 0xffff }, -{ "octmidib",0xffff }, -{ "pcauchy", 0xffff }, -{ "pchbend", 0xffff }, -{ "pchmidib",0xffff }, -{ "poisson", 0xffff }, -{ "pow", 0xffff, }, -{ "tableng", 0xffff, TR }, -{ "taninv2", 0xffff }, -{ "timek", 0xffff, }, -{ "times", 0xffff, }, -{ "trirand", 0xffff }, -{ "unirand", 0xffff, }, -{ "weibull", 0xffff }, -{ "oscil", 0xfffe, TR }, -{ "oscil3", 0xfffe, TR }, -{ "oscili", 0xfffe, TR }, -{ "peak", 0xfffd }, -{ "rtclock", 0xffff }, -{ "ptablew", 0xfffe, TW }, -{ "tablew", 0xfffe, TW }, -{ "tablewkt",0xfffe, TW }, -{ "ihold", S(LINK), 1, "", "", ihold }, -{ "turnoff",S(LINK), 2, "", "", NULL, turnoff }, -{ "=.r", S(ASSIGN), 1, "r", "i", rassign }, -{ "=.i", S(ASSIGNM), 1, "IIIIIIIIIIIIIIIIIIIIIIII", "m", minit }, -{ "=.k", S(ASSIGNM), 2, "zzzzzzzzzzzzzzzzzzzzzzzz", "z", NULL, minit }, -{ "=.a", S(ASSIGN), 4, "a", "x", NULL, NULL, aassign }, -{ "=.t", S(ASSIGNT), 2, "t", "kk", NULL, tassign, NULL }, -{ "init.i", S(ASSIGNM), 1, "IIIIIIIIIIIIIIIIIIIIIIII", "m", minit }, -{ "init.k", S(ASSIGNM), 1, "zzzzzzzzzzzzzzzzzzzzzzzz", "m", minit }, -{ "init.a", S(ASSIGNM), 1, "mmmmmmmmmmmmmmmmmmmmmmmm", "m", mainit }, -{ "init.t", S(ASSIGNM), 1, "t", "io", tinit }, -{ "##tabref", S(TABREF),3, "k", "tk", tabref_check, tabref, NULL }, -{ ">", S(RELAT), 0, "B", "kk", gt, gt }, -{ ">=", S(RELAT), 0, "B", "kk", ge, ge }, -{ "<", S(RELAT), 0, "B", "kk", lt, lt }, -{ "<=", S(RELAT), 0, "B", "kk", le, le }, -{ "==", S(RELAT), 0, "B", "kk", eq, eq }, -{ "!=", S(RELAT), 0, "B", "kk", ne, ne }, -{ "&&", S(LOGCL), 0, "B", "BB", and, and }, -{ "||", S(LOGCL), 0, "B", "BB", or, or }, -{ ":i", S(CONVAL), 1, "i", "bii", conval }, -{ ":k", S(CONVAL), 2, "k", "Bkk", NULL, conval }, -{ ":a", S(CONVAL), 4, "a", "Bxx", NULL, NULL, aconval }, -{ "add.ii", S(AOP), 1, "i", "ii", addkk }, -{ "sub.ii", S(AOP), 1, "i", "ii", subkk }, -{ "mul.ii", S(AOP), 1, "i", "ii", mulkk }, -{ "div.ii", S(AOP), 1, "i", "ii", divkk }, -{ "mod.ii", S(AOP), 1, "i", "ii", modkk }, -{ "add.kk", S(AOP), 2, "k", "kk", NULL, addkk }, -{ "sub.kk", S(AOP), 2, "k", "kk", NULL, subkk }, -{ "mul.kk", S(AOP), 2, "k", "kk", NULL, mulkk }, -{ "div.kk", S(AOP), 2, "k", "kk", NULL, divkk }, -{ "mod.kk", S(AOP), 2, "k", "kk", NULL, modkk }, -{ "add.ka", S(AOP), 4, "a", "ka", NULL, NULL, addka }, -{ "sub.ka", S(AOP), 4, "a", "ka", NULL, NULL, subka }, -{ "mul.ka", S(AOP), 4, "a", "ka", NULL, NULL, mulka }, -{ "div.ka", S(AOP), 4, "a", "ka", NULL, NULL, divka }, -{ "mod.ka", S(AOP), 4, "a", "ka", NULL, NULL, modka }, -{ "add.ak", S(AOP), 4, "a", "ak", NULL, NULL, addak }, -{ "sub.ak", S(AOP), 4, "a", "ak", NULL, NULL, subak }, -{ "mul.ak", S(AOP), 4, "a", "ak", NULL, NULL, mulak }, -{ "div.ak", S(AOP), 4, "a", "ak", NULL, NULL, divak }, -{ "mod.ak", S(AOP), 4, "a", "ak", NULL, NULL, modak }, -{ "add.aa", S(AOP), 4, "a", "aa", NULL, NULL, addaa }, -{ "sub.aa", S(AOP), 4, "a", "aa", NULL, NULL, subaa }, -{ "mul.aa", S(AOP), 4, "a", "aa", NULL, NULL, mulaa }, -{ "div.aa", S(AOP), 4, "a", "aa", NULL, NULL, divaa }, -{ "mod.aa", S(AOP), 4, "a", "aa", NULL, NULL, modaa }, -{ "divz", 0xfffc }, -{ "divz.ii", S(DIVZ), 1, "i", "iii", divzkk, NULL, NULL }, -{ "divz.kk", S(DIVZ), 2, "k", "kkk", NULL, divzkk, NULL }, -{ "divz.ak", S(DIVZ), 4, "a", "akk", NULL, NULL, divzak }, -{ "divz.ka", S(DIVZ), 4, "a", "kak", NULL, NULL, divzka }, -{ "divz.aa", S(DIVZ), 4, "a", "aak", NULL, NULL, divzaa }, -{ "int.i", S(EVAL), 1, "i", "i", int1 }, -{ "frac.i", S(EVAL), 1, "i", "i", frac1 }, -{ "round.i",S(EVAL), 1, "i", "i", int1_round }, -{ "floor.i",S(EVAL), 1, "i", "i", int1_floor }, -{ "ceil.i", S(EVAL), 1, "i", "i", int1_ceil }, -{ "rnd.i", S(EVAL), 1, "i", "i", rnd1 }, -{ "birnd.i",S(EVAL), 1, "i", "i", birnd1 }, -{ "abs.i", S(EVAL), 1, "i", "i", abs1 }, -{ "exp.i", S(EVAL), 1, "i", "i", exp01 }, -{ "log.i", S(EVAL), 1, "i", "i", log01 }, -{ "sqrt.i", S(EVAL), 1, "i", "i", sqrt1 }, -{ "sin.i", S(EVAL), 1, "i", "i", sin1 }, -{ "cos.i", S(EVAL), 1, "i", "i", cos1 }, -{ "tan.i", S(EVAL), 1, "i", "i", tan1 }, -{ "qinf.i", S(EVAL), 1, "i", "i", is_inf }, -{ "qnan.i", S(EVAL), 1, "i", "i", is_NaN }, -{ "sininv.i", S(EVAL), 1, "i", "i", asin1 }, -{ "cosinv.i", S(EVAL), 1, "i", "i", acos1 }, -{ "taninv.i", S(EVAL), 1, "i", "i", atan1 }, -{ "taninv2.i",S(AOP), 1, "i", "ii", atan21 }, -{ "log10.i",S(EVAL), 1, "i", "i", log101 }, -{ "sinh.i", S(EVAL), 1, "i", "i", sinh1 }, -{ "cosh.i", S(EVAL), 1, "i", "i", cosh1 }, -{ "tanh.i", S(EVAL), 1, "i", "i", tanh1 }, -{ "int.k", S(EVAL), 2, "k", "k", NULL, int1 }, -{ "frac.k", S(EVAL), 2, "k", "k", NULL, frac1 }, -{ "round.k",S(EVAL), 2, "k", "k", NULL, int1_round }, -{ "floor.k",S(EVAL), 2, "k", "k", NULL, int1_floor }, -{ "ceil.k", S(EVAL), 2, "k", "k", NULL, int1_ceil }, -{ "rnd.k", S(EVAL), 2, "k", "k", NULL, rnd1 }, -{ "birnd.k",S(EVAL), 2, "k", "k", NULL, birnd1 }, -{ "abs.k", S(EVAL), 2, "k", "k", NULL, abs1 }, -{ "exp.k", S(EVAL), 2, "k", "k", NULL, exp01 }, -{ "log.k", S(EVAL), 2, "k", "k", NULL, log01 }, -{ "sqrt.k", S(EVAL), 2, "k", "k", NULL, sqrt1 }, -{ "sin.k", S(EVAL), 2, "k", "k", NULL, sin1 }, -{ "cos.k", S(EVAL), 2, "k", "k", NULL, cos1 }, -{ "tan.k", S(EVAL), 2, "k", "k", NULL, tan1 }, -{ "qinf.k", S(EVAL), 2, "k", "k", NULL, is_inf }, -{ "qnan.k", S(EVAL), 2, "k", "k", NULL, is_NaN }, -{ "sininv.k", S(EVAL), 2, "k", "k", NULL, asin1 }, -{ "cosinv.k", S(EVAL), 2, "k", "k", NULL, acos1 }, -{ "taninv.k", S(EVAL), 2, "k", "k", NULL, atan1 }, -{ "taninv2.k",S(AOP), 2, "k", "kk", NULL, atan21 }, -{ "sinh.k", S(EVAL), 2, "k", "k", NULL, sinh1 }, -{ "cosh.k", S(EVAL), 2, "k", "k", NULL, cosh1 }, -{ "tanh.k", S(EVAL), 2, "k", "k", NULL, tanh1 }, -{ "log10.k",S(EVAL), 2, "k", "k", NULL, log101 }, -{ "int.a", S(EVAL), 4, "a", "a", NULL, NULL, int1a }, -{ "frac.a", S(EVAL), 4, "a", "a", NULL, NULL, frac1a }, -{ "round.a",S(EVAL), 4, "a", "a", NULL, NULL, int1a_round }, -{ "floor.a",S(EVAL), 4, "a", "a", NULL, NULL, int1a_floor }, -{ "ceil.a", S(EVAL), 4, "a", "a", NULL, NULL, int1a_ceil }, -{ "abs.a", S(EVAL), 4, "a", "a", NULL, NULL, absa }, -{ "exp.a", S(EVAL), 4, "a", "a", NULL, NULL, expa }, -{ "log.a", S(EVAL), 4, "a", "a", NULL, NULL, loga }, -{ "sqrt.a", S(EVAL), 4, "a", "a", NULL, NULL, sqrta }, -{ "sin.a", S(EVAL), 4, "a", "a", NULL, NULL, sina }, -{ "cos.a", S(EVAL), 4, "a", "a", NULL, NULL, cosa }, -{ "tan.a", S(EVAL), 4, "a", "a", NULL, NULL, tana }, -{ "qinf.a", S(EVAL), 4, "a", "a", NULL, NULL, is_infa }, -{ "qnan.a", S(EVAL), 4, "a", "a", NULL, NULL, is_NaNa }, -{ "sininv.a", S(EVAL), 4, "a", "a", NULL, NULL, asina }, -{ "cosinv.a", S(EVAL), 4, "a", "a", NULL, NULL, acosa }, -{ "taninv.a", S(EVAL), 4, "a", "a", NULL, NULL, atana }, -{ "taninv2.a",S(AOP), 4, "a", "aa", NULL, NULL, atan2aa }, -{ "sinh.a", S(EVAL), 4, "a", "a", NULL, NULL, sinha }, -{ "cosh.a", S(EVAL), 4, "a", "a", NULL, NULL, cosha }, -{ "tanh.a", S(EVAL), 4, "a", "a", NULL, NULL, tanha }, -{ "log10.a",S(EVAL), 4, "a", "a", NULL, NULL, log10a }, -{ "ampdb.a",S(EVAL), 4, "a", "a", NULL, NULL, aampdb }, -{ "ampdb.i",S(EVAL), 1, "i", "i", ampdb }, -{ "ampdb.k",S(EVAL), 2, "k", "k", NULL, ampdb }, -{ "ampdbfs.a",S(EVAL), 4, "a", "a", NULL, NULL, aampdbfs }, -{ "ampdbfs.i",S(EVAL), 1, "i", "i", ampdbfs }, -{ "ampdbfs.k",S(EVAL), 2, "k", "k", NULL, ampdbfs }, -{ "dbamp.i",S(EVAL), 1, "i", "i", dbamp }, -{ "dbamp.k",S(EVAL), 2, "k", "k", NULL, dbamp }, -{ "dbfsamp.i",S(EVAL), 1, "i", "i", dbfsamp }, -{ "dbfsamp.k",S(EVAL), 2, "k", "k", NULL, dbfsamp }, -{ "rtclock.i",S(EVAL), 1, "i", "", rtclock }, -{ "rtclock.k",S(EVAL), 2, "k", "", NULL, rtclock }, -{ "ftlen.i",S(EVAL), 1, "i", "i", ftlen }, -{ "ftsr.i",S(EVAL), 1, "i", "i", ftsr }, -{ "ftlptim.i",S(EVAL), 1, "i", "i", ftlptim }, -{ "ftchnls.i",S(EVAL), 1, "i", "i", ftchnls }, -{ "ftcps.i",S(EVAL), 1, "i", "i", ftcps }, -{ "i.i", S(ASSIGN), 1, "i", "i", assign }, -{ "i.k", S(ASSIGN), 1, "i", "k", assign }, -{ "k.i", S(ASSIGN), 1, "k", "i", assign }, -{ "cpsoct.i",S(EVAL), 1, "i", "i", cpsoct }, -{ "octpch.i",S(EVAL), 1, "i", "i", octpch }, -{ "cpspch.i",S(EVAL), 1, "i", "i", cpspch }, -{ "pchoct.i",S(EVAL), 1, "i", "i", pchoct }, -{ "octcps.i",S(EVAL), 1, "i", "i", octcps }, -{ "cpsoct.k",S(EVAL), 2, "k", "k", NULL, cpsoct }, -{ "octpch.k",S(EVAL), 2, "k", "k", NULL, octpch }, -{ "cpspch.k",S(EVAL), 2, "k", "k", NULL, cpspch }, -{ "pchoct.k",S(EVAL), 2, "k", "k", NULL, pchoct }, -{ "octcps.k",S(EVAL), 2, "k", "k", NULL, octcps }, -{ "cpsoct.a",S(EVAL), 4, "a", "a", NULL, NULL, acpsoct }, -{ "cpsmidinn.i",S(EVAL),1, "i", "i", cpsmidinn }, -{ "octmidinn.i",S(EVAL),1, "i", "i", octmidinn }, -{ "pchmidinn.i",S(EVAL),1, "i", "i", pchmidinn }, -{ "cpsmidinn.k",S(EVAL),2, "k", "k", NULL, cpsmidinn }, -{ "octmidinn.k",S(EVAL),2, "k", "k", NULL, octmidinn }, -{ "pchmidinn.k",S(EVAL),2, "k", "k", NULL, pchmidinn }, -{ "notnum", S(MIDIKMB), 1, "i", "", notnum }, -{ "veloc", S(MIDIMAP), 1, "i", "oh", veloc }, -{ "pchmidi",S(MIDIKMB), 1, "i", "", pchmidi }, -{ "octmidi",S(MIDIKMB), 1, "i", "", octmidi }, -{ "cpsmidi",S(MIDIKMB), 1, "i", "", cpsmidi }, -{ "pchmidib.i",S(MIDIKMB),1, "i", "o", pchmidib_i }, -{ "octmidib.i",S(MIDIKMB),1, "i", "o", octmidib_i }, -{ "cpsmidib.i",S(MIDIKMB),1, "i", "o", icpsmidib_i }, -{ "pchmidib.k",S(MIDIKMB),3, "k", "o", midibset, pchmidib }, -{ "octmidib.k",S(MIDIKMB),3, "k", "o", midibset, octmidib }, -{ "cpsmidib.k",S(MIDIKMB),3, "k", "o", midibset, icpsmidib }, -{ "ampmidi",S(MIDIAMP), 1, "i", "io", ampmidi }, -{ "aftouch",S(MIDIKMAP), 3, "k", "oh", aftset, aftouch }, -{ "pchbend.i",S(MIDIMAP),0x21, "i", "jp", ipchbend }, -{ "pchbend.k",S(MIDIKMAP),0x23, "k", "jp", kbndset,kpchbend }, -{ "midictrl.i",S(MIDICTL),1, "i", "ioh", imidictl }, -{ "midictrl.k",S(MIDICTL),3, "k", "ioh", mctlset, midictl }, -{ "polyaft.i",S(MIDICTL),1, "i", "ioh", imidiaft }, -{ "polyaft.k",S(MIDICTL),3, "k", "ioh", maftset, midiaft }, -{ "chanctrl.i",S(CHANCTL),1, "i", "iioh", ichanctl }, -{ "chanctrl.k",S(CHANCTL),3, "k", "iioh", chctlset,chanctl }, -{ "line", S(LINE), 7, "s", "iii", linset, kline, aline }, -{ "expon", S(EXPON), 7, "s", "iii", expset, kexpon, expon }, -{ "linseg", S(LINSEG), 7, "s", "iin", lsgset, klnseg, linseg }, -{ "linsegb", S(LINSEG), 7, "s", "iin", lsgset_bkpt, klnseg, linseg }, -{ "linsegr",S(LINSEG), 7, "s", "iin", lsgrset,klnsegr,linsegr }, -{ "expseg", S(EXXPSEG), 7, "s", "iin", xsgset, kxpseg, expseg }, -{ "expsegb", S(EXXPSEG), 7, "s", "iin", xsgset_bkpt, kxpseg, expseg }, -{ "expsega",S(EXPSEG2), 7, "a", "iin", xsgset2, NULL, expseg2 }, -{ "expsegba",S(EXPSEG2), 7, "a", "iin", xsgset2b, NULL, expseg2 }, -{ "expsegr",S(EXPSEG), 7, "s", "iin", xsgrset,kxpsegr,expsegr }, -{ "linen", S(LINEN), 7, "s", "xiii", lnnset, klinen, linen }, -{ "linenr", S(LINENR), 7, "s", "xiii", lnrset, klinenr,linenr }, -{ "envlpx", S(ENVLPX), TR|7, "s","xiiiiiio", evxset, knvlpx, envlpx }, -{ "envlpxr", S(ENVLPR), TR|7, "s","xiiiiioo", evrset, knvlpxr,envlpxr }, -{ "phasor", S(PHSOR), 7, "s", "xo", phsset, kphsor, phsor }, -{ "ephasor", S(EPHSOR), 5, "ss", "xko", ephsset, NULL, ephsor }, -{ "table", 0xffff, TR }, -{ "tablei", 0xffff, TR }, -{ "table3", 0xffff, TR }, -{ "table.i", S(TABLE), 1, "i", "iiooo",itable }, -{ "table.k", S(TABLE), 3, "k", "xiooo",tblset, ktable }, -{ "table.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, tablefn }, -{ "tablei.i", S(TABLE), 1, "i", "iiooo",itabli }, -{ "tablei.k", S(TABLE), 3, "k", "xiooo",tblset, ktabli }, -{ "tablei.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, tabli }, -{ "table3.i", S(TABLE), 1, "i", "iiooo",itabl3 }, -{ "table3.k", S(TABLE), 3, "k", "xiooo",tblset, ktabl3 }, -{ "table3.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, tabl3 }, -{ "ptable", 0xffff, TR }, -{ "ptablei", 0xffff, TR }, -{ "ptable3", 0xffff, TR }, -{ "ptable.i", S(TABLE), 1, "i", "iiooo",pitable }, -{ "ptable.k", S(TABLE), 3, "k", "xiooo",tblset, pktable }, -{ "ptable.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, ptablefn }, -{ "ptablei.i", S(TABLE), 1, "i", "iiooo",pitabli }, -{ "ptablei.k", S(TABLE), 3, "k", "xiooo",tblset, pktabli }, -{ "ptablei.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, ptabli }, -{ "ptable3.i", S(TABLE), 1, "i", "iiooo",pitabl3 }, -{ "ptable3.k", S(TABLE), 3, "k", "xiooo",tblset, pktabl3 }, -{ "ptable3.a", S(TABLE), 5, "a", "xiooo",tblset, NULL, ptabl3 }, -{ "oscil1", S(OSCIL1), TR|3, "k", "ikii", ko1set, kosc1 }, -{ "oscil1i",S(OSCIL1), TR|3, "k", "ikii", ko1set, kosc1i }, -{ "osciln", S(OSCILN), TR|5, "a", "kiii", oscnset,NULL, osciln }, -{ "oscil.kk",S(OSC), 7, "s", "kkio", oscset, koscil, osckk }, -{ "oscil.ka",S(OSC), 5, "a", "kaio", oscset, NULL, oscka }, -{ "oscil.ak",S(OSC), 5, "a", "akio", oscset, NULL, oscak }, -{ "oscil.aa",S(OSC), 5, "a", "aaio", oscset, NULL, oscaa }, -/* CHangerthese to -{ "oscil.kk", S(POSC), 7, "s", "kkio", posc_set, kposc, posckk }, -{ "oscil.ka", S(POSC), 5, "a", "kaio", posc_set, NULL, poscka }, -{ "oscil.ak", S(POSC), 5, "a", "akio", posc_set, NULL, poscak }, -{ "oscil.aa", S(POSC), 5, "a", "aaio", posc_set, NULL, poscaa }, -{ "oscil3.kk", S(POSC), 7, "s", "kkio", posc_set, kposc3, posc3 }, -*/ -{ "oscili.kk",S(OSC), 7, "s", "kkio", oscset, koscli, osckki }, -{ "oscili.ka",S(OSC), 5, "a", "kaio", oscset, NULL, osckai }, -{ "oscili.ak",S(OSC), 5, "a", "akio", oscset, NULL, oscaki }, -{ "oscili.aa",S(OSC), 5, "a", "aaio", oscset, NULL, oscaai }, -{ "oscil3.kk",S(OSC), 7, "s", "kkio", oscset, koscl3, osckk3 }, -{ "oscil3.ka",S(OSC), 5, "a", "kaio", oscset, NULL, oscka3 }, -{ "oscil3.ak",S(OSC), 5, "a", "akio", oscset, NULL, oscak3 }, -{ "oscil3.aa",S(OSC), 5, "a", "aaio", oscset, NULL, oscaa3 }, -/* end change */ -{ "foscil", S(FOSC), TR|5, "a", "xkxxkio",foscset,NULL, foscil }, -{ "foscili",S(FOSC), TR|5, "a", "xkxxkio",foscset,NULL, foscili }, -{ "loscil", S(LOSC), TR|5, "mm","xkiojoojoo",losset,NULL, loscil }, -{ "loscil3", S(LOSC), TR|5, "mm","xkiojoojoo",losset,NULL, loscil3 }, -{ "adsyn", S(ADSYN), 5, "a", "kkkTo", adset, NULL, adsyn }, -{ "buzz", S(BUZZ), TR|5, "a", "xxkio", bzzset, NULL, buzz }, -{ "gbuzz", S(GBUZZ), TR|5, "a", "xxkkkio",gbzset, NULL, gbuzz }, -{ "pluck", S(PLUCK), TR|5, "a", "kkiiioo",plukset,NULL, pluck }, -{ "rand", S(RAND), 7, "s", "xvoo", rndset, krand, arand }, -{ "randh", S(RANDH), 7, "s", "xxvoo", rhset, krandh, randh }, -{ "randi", S(RANDI), 7, "s", "xxvoo", riset, krandi, randi }, -{ "port", S(PORT), 3, "k", "kio", porset, port }, -{ "tone", S(TONE), 5, "a", "ako", tonset, NULL, tone }, -{ "tonex", S(TONEX), 5, "a", "akoo", tonsetx, NULL, tonex }, -{ "atone", S(TONE), 5, "a", "ako", tonset, NULL, atone }, -{ "atonex", S(TONEX), 5, "a", "akoo", tonsetx, NULL, atonex }, -{ "reson", S(RESON), 5, "a", "akkoo",rsnset, NULL, reson }, -{ "resonx", S(RESONX), 5, "a", "akkooo", rsnsetx, NULL, resonx }, -{ "areson", S(RESON), 5, "a", "akkoo",rsnset, NULL, areson }, -{ "lpread", S(LPREAD), 3, "kkkk", "kToo", lprdset,lpread }, -{ "lpform", S(LPFORM), 3, "kk", "k", lpformantset,lpformant }, -{ "lpreson",S(LPRESON), 5, "a", "a", lprsnset,NULL, lpreson }, -{ "lpfreson",S(LPFRESON),5, "a", "ak", lpfrsnset,NULL, lpfreson}, -{ "lpslot" , S(LPSLOT), 1, "", "i", lpslotset, NULL, NULL }, -{ "lpinterp", S(LPINTERPOL), 3, "", "iik", lpitpset, lpinterpol, NULL}, -{ "rms", S(RMS), 3, "k", "aqo", rmsset, rms }, -{ "gain", S(GAIN), 5, "a", "akqo", gainset,NULL, gain }, -{ "balance",S(BALANCE), 5, "a", "aaqo", balnset,NULL, balance }, -{ "pan", S(PAN), 5, "aaaa", "akkioo",(SUBR)panset,NULL, (SUBR)pan }, -{ "soundin",S(SOUNDIN_),5,"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm","Toooo", - sndinset, NULL, soundin }, -{ "soundout",S(SNDOUT), _QQ|5, "", "aTo", sndo1set, NULL, soundout }, -{ "soundouts",S(SNDOUTS),_QQ|5, "", "aaTo", sndo1set, NULL, soundouts }, -{ "in", S(INM), 4, "a", "", NULL, NULL, in }, -{ "ins", S(INS), 4, "aa", "", NULL, NULL, ins }, -{ "inq", S(INQ), 4, "aaaa", "", NULL, NULL, inq }, - /* Note that there is code in rdorch.c that assumes that opcodes starting - with the charcters out followed by a s, q, h, o or x are in this group - ***BEWARE*** - CODE REMOVED 2011-Dec-14 - */ -{ "out", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "outs", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "outq", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "outh", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "outo", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "outx", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "out32", S(OUTX), 4, "", "y", NULL, NULL, outall }, -/* { "out", S(OUTM), 4, "", "a", NULL, NULL, out }, */ -/* { "outs", S(OUTS), 4, "", "aa", NULL, NULL, outs }, */ -{ "outs1", S(OUTM), 4, "", "a", NULL, NULL, outs1 }, -{ "outs2", S(OUTM), 4, "", "a", NULL, NULL, outs2 }, -/* { "outq", S(OUTQ), 4, "", "aaaa", NULL, NULL, outq }, */ -{ "outq1", S(OUTM), 4, "", "a", NULL, NULL, outq1 }, -{ "outq2", S(OUTM), 4, "", "a", NULL, NULL, outq2 }, -{ "outq3", S(OUTM), 4, "", "a", NULL, NULL, outq3 }, -{ "outq4", S(OUTM), 4, "", "a", NULL, NULL, outq4 }, -{ "igoto", S(GOTO), 1, "", "l", igoto }, -{ "kgoto", S(GOTO), 2, "", "l", NULL, kgoto }, -{ "goto", S(GOTO), 3, "", "l", igoto, kgoto }, -{ "cigoto", S(CGOTO), 1, "", "Bl", icgoto }, -{ "ckgoto", S(CGOTO), 2, "", "Bl", NULL, kcgoto }, -{ "cggoto", S(CGOTO), 3, "", "Bl", icgoto, kcgoto }, -{ "timout", S(TIMOUT), 3, "", "iil", timset, timout }, -{ "reinit", S(GOTO), 2, "", "l", NULL, reinit }, -{ "rigoto", S(GOTO), 1, "", "l", rigoto }, -{ "rireturn",S(LINK), 1, "", "", rireturn }, -{ "tigoto", S(GOTO), 1, "", "l", tigoto }, -{ "tival", S(EVAL), 1, "i", "", tival }, -{ "print", S(PRINTV), 1, "", "m", printv }, -{ "display",S(DSPLAY), 7, "", "sioo", dspset, kdsplay,dsplay }, -{ "pvsdisp",S(FSIGDISP), 3, "", "foo", fdspset, fdsplay,NULL }, -{ "dispfft",S(DSPFFT), 7, "", "siiooo",fftset,kdspfft,dspfft }, -{ "dumpk", S(KDUMP), 3, "", "kTii", kdmpset,kdump }, -{ "dumpk2", S(KDUMP2), 3, "", "kkTii",kdmp2set,kdump2 }, -{ "dumpk3", S(KDUMP3), 3, "", "kkkTii",kdmp3set,kdump3 }, -{ "dumpk4", S(KDUMP4), 3, "", "kkkkTii",kdmp4set,kdump4 }, -{ "readk", S(KREAD), 3, "k", "Tii", krdset, kread }, -{ "readk2", S(KREAD2), 3, "kk", "Tii", krd2set, kread2 }, -{ "readk3", S(KREAD3), 3, "kkk", "Tii", krd3set, kread3 }, -{ "readk4", S(KREAD4), 3, "kkkk", "Tii", krd4set, kread4 }, -{ "readks", S(KREADS), 3, "S", "Ti", krdsset, kreads }, -{ "xyin", S(XYIN), 3, "kk", "iiiiioo",xyinset,xyin }, -{ "tempest", S(TEMPEST), 5, "k","kiiiiiiiiiop",tempeset,NULL,tempest}, -{ "tempo", S(TEMPO), 3, "", "ki", tempset,tempo }, -{ "pow.i", S(POW), 1, "i", "iip", ipow, NULL, NULL }, -{ "pow.k", S(POW), 2, "k", "kkp", NULL, ipow, NULL }, -{ "pow.a", S(POW), 4, "a", "akp", NULL, NULL, apow }, -{ "oscilx", S(OSCILN),TR|5, "a", "kiii", oscnset,NULL, osciln }, -{ "linrand.i",S(PRAND), 1, "i", "k", iklinear, NULL, NULL }, -{ "linrand.k",S(PRAND), 2, "k", "k", NULL, iklinear, NULL }, -{ "linrand.a",S(PRAND), 4, "a", "k", NULL, NULL, alinear }, -{ "trirand.i",S(PRAND), 1, "i", "k", iktrian, NULL, NULL }, -{ "trirand.k",S(PRAND), 2, "k", "k", NULL, iktrian, NULL }, -{ "trirand.a",S(PRAND), 4, "a", "k", NULL, NULL, atrian }, -{ "exprand.i",S(PRAND), 1, "i", "k", ikexp, NULL, NULL }, -{ "exprand.k",S(PRAND), 2, "k", "k", NULL, ikexp, NULL }, -{ "exprand.a",S(PRAND), 4, "a", "k", NULL, NULL, aexp }, -{ "bexprnd.i",S(PRAND), 1, "i", "k", ikbiexp, NULL, NULL }, -{ "bexprnd.k",S(PRAND), 2, "k", "k", NULL, ikbiexp, NULL }, -{ "bexprnd.a",S(PRAND), 4, "a", "k", NULL, NULL, abiexp }, -{ "cauchy.i", S(PRAND), 1, "i", "k", ikcauchy, NULL, NULL }, -{ "cauchy.k", S(PRAND), 2, "k", "k", NULL, ikcauchy, NULL }, -{ "cauchy.a", S(PRAND), 4, "a", "k", NULL, NULL, acauchy }, -{ "pcauchy.i",S(PRAND), 1, "i", "k", ikpcauchy, NULL,NULL }, -{ "pcauchy.k",S(PRAND), 2, "k", "k", NULL, ikpcauchy,NULL }, -{ "pcauchy.a",S(PRAND), 4, "a", "k", NULL, NULL, apcauchy}, -{ "poisson.i",S(PRAND), 1, "i", "k", ikpoiss, NULL, NULL }, -{ "poisson.k",S(PRAND), 2, "k", "k", NULL, ikpoiss, NULL }, -{ "poisson.a",S(PRAND), 4, "a", "k", NULL, NULL, apoiss }, -{ "gauss.i" , S(PRAND), 1, "i", "k", ikgaus, NULL, NULL }, -{ "gauss.k" , S(PRAND), 2, "k", "k", NULL, ikgaus, NULL }, -{ "gauss.a" , S(PRAND), 4, "a", "k", NULL, NULL, agaus }, -{ "weibull.i",S(PRAND), 1, "i", "kk", ikweib, NULL, NULL }, -{ "weibull.k",S(PRAND), 2, "k", "kk", NULL, ikweib, NULL }, -{ "weibull.a",S(PRAND), 4, "a", "kk", NULL, NULL, aweib }, -{ "betarand.i",S(PRAND),1, "i", "kkk", ikbeta, NULL, NULL }, -{ "betarand.k",S(PRAND),2, "k", "kkk", NULL, ikbeta,NULL }, -{ "betarand.a",S(PRAND),4, "a", "kkk", NULL, NULL, abeta }, -{ "seed", S(PRAND), 1, "", "i", seedrand, NULL, NULL }, -{ "unirand.i",S(PRAND), 1, "i", "k", ikuniform, NULL, NULL }, -{ "unirand.k",S(PRAND), 2, "k", "k", NULL, ikuniform, NULL}, -{ "unirand.a",S(PRAND), 4, "a", "k", NULL, NULL, auniform }, - -{ "diskin",S(SOUNDINEW),_QQ|5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", - "Tkooooo", - (SUBR) newsndinset, NULL, (SUBR) soundinew }, -{ "diskin2",S(DISKIN2), 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", - "Tkoooooo", - (SUBR) diskin2_init, (SUBR) NULL, - (SUBR) diskin2_perf }, -{ "noteon", S(OUT_ON), 1, "", "iii", iout_on, NULL, NULL }, -{ "noteoff", S(OUT_ON), 1, "", "iii", iout_off, NULL, NULL }, -{ "noteondur",S(OUT_ON_DUR),3, "", "iiii", iout_on_dur_set,iout_on_dur,NULL}, -{ "noteondur2",S(OUT_ON_DUR),3, "", "iiii", iout_on_dur_set,iout_on_dur2,NULL}, -{ "moscil",S(MOSCIL), 3, "", "kkkkk",moscil_set, moscil, NULL}, -{ "midion",S(KOUT_ON), 3, "", "kkk", kvar_out_on_set,kvar_out_on,NULL}, -{ "outic",S(OUT_CONTR), 1, "", "iiiii", out_controller, NULL, NULL}, -{ "outkc",S(OUT_CONTR), 2, "", "kkkkk", NULL, out_controller, NULL}, -{ "outic14",S(OUT_CONTR14),1, "", "iiiiii",out_controller14, NULL,NULL}, -{ "outkc14",S(OUT_CONTR14),2, "", "kkkkkk",NULL, out_controller14, NULL}, -{ "outipb",S(OUT_PB), 1, "", "iiii", out_pitch_bend, NULL , NULL}, -{ "outkpb",S(OUT_PB), 2, "", "kkkk", NULL, out_pitch_bend, NULL}, -{ "outiat",S(OUT_ATOUCH),1, "", "iiii", out_aftertouch, NULL , NULL}, -{ "outkat",S(OUT_ATOUCH),2, "", "kkkk", NULL, out_aftertouch, NULL}, -{ "outipc",S(OUT_PCHG), 1, "", "iiii", out_progchange, NULL , NULL}, -{ "outkpc",S(OUT_PCHG), 2, "", "kkkk", NULL, out_progchange, NULL}, -{ "outipat",S(OUT_POLYATOUCH),1,"", "iiiii", out_poly_aftertouch, NULL,NULL}, -{ "outkpat",S(OUT_POLYATOUCH),2,"", "kkkkk", NULL, out_poly_aftertouch,NULL}, -{ "release",S(REL), 3, "k", "", release_set, release , NULL }, -{ "xtratim",S(XTRADUR), 1, "", "i", xtratim, NULL, NULL }, -{ "mclock", S(MCLOCK), 3, "", "i", mclock_set, mclock, NULL }, -{ "mrtmsg", S(XTRADUR), 1, "", "i", mrtmsg, NULL, NULL }, -{ "midiout",S(MIDIOUT), 2, "", "kkkk", NULL, midiout, NULL }, -{ "midion2", S(KON2), 3, "", "kkkk", kon2_set, kon2, NULL }, -{ "nrpn", S(NRPN), 2, "", "kkk", NULL, nrpn ,NULL }, -{ "mdelay", S(MDELAY), 3, "", "kkkkk",mdelay_set, mdelay, NULL }, -{ "nsamp.i", S(EVAL), 1, "i", "i", numsamp }, -{ "powoftwo.i",S(EVAL), 1, "i", "i", powoftwo }, -{ "powoftwo.k",S(EVAL), 2, "k", "k", NULL, powoftwo }, -{ "powoftwo.a",S(EVAL), 4, "a", "a", NULL, NULL, powoftwoa }, -{ "logbtwo.i",S(EVAL), 1, "i", "i", ilogbasetwo }, -{ "logbtwo.k",S(EVAL), 3, "k", "k", logbasetwo_set, logbasetwo }, -{ "logbtwo.a",S(EVAL), 5, "a", "a", logbasetwo_set, NULL, logbasetwoa }, -{ "filelen", S(SNDINFO), 1, "i", "Tp", filelen, NULL, NULL }, -{ "filenchnls", S(SNDINFO), 1, "i", "Tp", filenchnls, NULL, NULL }, -{ "filesr", S(SNDINFO), 1, "i", "Tp", filesr, NULL, NULL }, -{ "filebit", S(SNDINFO), 1, "i", "Tp", filebit, NULL, NULL }, -{ "filepeak", S(SNDINFOPEAK), 1, "i", "To", filepeak, NULL, NULL }, -{ "filevalid", S(FILEVALID), 1, "i", "T", filevalid, NULL, NULL }, -/* { "nlalp", S(NLALP), 5, "a", "akkoo", nlalp_set, NULL, nlalp }, */ -{ "ptableiw", S(TABLEW),TW|1, "", "iiiooo", (SUBR)pitablew, NULL, NULL}, -{ "ptablew.kk", S(TABLEW), 3, "", "kkiooo",(SUBR)itblchkw,(SUBR)pktablew, NULL}, -{ "ptablew.aa", S(TABLEW), 5, "", "aaiooo",(SUBR)itblchkw, NULL, (SUBR)ptablew}, -/* Robin Whittle */ -{ "tableiw", S(TABLEW),TW|1, "", "iiiooo", (SUBR)itablew, NULL, NULL}, -{ "tablew.kk", S(TABLEW), 3, "", "kkiooo",(SUBR)itblchkw,(SUBR)ktablew, NULL}, -{ "tablew.aa", S(TABLEW), 5, "", "aaiooo",(SUBR)itblchkw, NULL, (SUBR)tablew}, -{ "tablewkt.kk", S(TABLEW),3, "", "kkkooo", - (SUBR)tblsetwkt,(SUBR)ktablewkt,NULL}, -{ "tablewkt.aa", S(TABLEW),5, "", "aakooo", - (SUBR)tblsetwkt,NULL,(SUBR)tablewkt}, -{ "tableng.i", S(TABLENG),1, "i", "i", (SUBR)itableng, NULL, NULL}, -{ "tableng.k", S(TABLENG),2, "k", "k", NULL, (SUBR)tableng, NULL}, -{ "tableigpw",S(TABLENG),TB|1, "", "i", (SUBR)itablegpw, NULL, NULL}, -{ "tablegpw", S(TABLENG),2, "", "k", NULL, (SUBR)tablegpw, NULL}, -{ "tableimix",S(TABLEMIX),TB|1, "", "iiiiiiiii", (SUBR)itablemix, NULL, NULL}, -{ "tablemix", S(TABLEMIX),TB|2, "", "kkkkkkkkk", - (SUBR)tablemixset, (SUBR)tablemix, NULL}, -{ "tableicopy",S(TABLECOPY),TB|1, "", "ii", (SUBR)itablecopy, NULL, NULL}, -{ "tablecopy", S(TABLECOPY),TB|2, "", "kk", - (SUBR)tablecopyset, (SUBR)tablecopy, NULL}, -{ "tablera", S(TABLERA),TR|5, "a", "kkk", - (SUBR)tableraset, NULL, (SUBR)tablera}, -{ "tablewa", S(TABLEWA),TW|5, "k", "kak", - (SUBR)tablewaset, NULL, (SUBR)tablewa}, -{ "tablekt", S(TABLE), TR|7, "s", "xkooo",tblsetkt, ktablekt, tablekt }, -{ "tableikt", S(TABLE), TR|7, "s", "xkooo",tblsetkt, ktablikt, tablikt }, -{ "zakinit", S(ZAKINIT), ZB|1, "", "ii", (SUBR)zakinit, NULL, NULL}, -{ "zir", S(ZKR), ZR|1, "i", "i", (SUBR)zir, NULL, NULL}, -{ "zkr", S(ZKR), ZR|3, "k", "k", (SUBR)zkset, (SUBR)zkr, NULL}, -{ "ziw", S(ZKW), ZW|1, "", "ii", (SUBR)ziw, NULL, NULL}, -{ "zkw", S(ZKW), ZW|3, "", "kk", (SUBR)zkset, (SUBR)zkw, NULL}, -{ "ziwm", S(ZKWM), ZB|1, "", "iip", (SUBR)ziwm, NULL, NULL}, -{ "zkwm", S(ZKWM), ZB|3, "", "kkp", (SUBR)zkset, (SUBR)zkwm, NULL}, -{ "zkmod", S(ZKMOD), ZB|2, "k", "kk", NULL, (SUBR)zkmod, NULL}, -{ "zkcl", S(ZKCL), ZW|3, "", "kk", (SUBR)zkset, (SUBR)zkcl, NULL}, -{ "zar", S(ZAR), ZR|5, "a", "k", (SUBR)zaset, NULL, (SUBR)zar}, -{ "zarg", S(ZARG), ZB|5, "a", "kk", (SUBR)zaset, NULL, (SUBR)zarg}, -{ "zaw", S(ZAW), ZW|5, "", "ak", (SUBR)zaset, NULL, (SUBR)zaw}, -{ "zawm", S(ZAWM), ZB|5, "", "akp", (SUBR)zaset, NULL, (SUBR)zawm}, -{ "zamod", S(ZAMOD), ZB|4, "a", "ak", NULL, NULL, (SUBR)zamod}, -{ "zacl", S(ZACL), ZW|5, "", "kk", (SUBR)zaset, NULL, (SUBR)zacl}, -{ "inz", S(IOZ), ZW|4, "", "k", (SUBR)zaset, NULL, (SUBR)inz }, -{ "outz", S(IOZ), ZR|4, "", "k", (SUBR)zaset, NULL, (SUBR)outz }, -{ "timek.i", S(RDTIME), 1, "i", "", (SUBR)timek, NULL, NULL }, -{ "times.i", S(RDTIME), 1, "i", "", (SUBR)timesr, NULL, NULL }, -{ "timek.k", S(RDTIME), 2, "k", "", NULL, (SUBR)timek, NULL }, -{ "times.k", S(RDTIME), 2, "k", "", NULL, (SUBR)timesr,NULL }, -{ "timeinstk", S(RDTIME), 3, "k", "", (SUBR)instimset, (SUBR)instimek, NULL }, -{ "timeinsts", S(RDTIME), 3, "k", "", (SUBR)instimset, (SUBR)instimes, NULL }, -{ "peak.k", S(PEAK), 2, "k", "k", NULL, (SUBR)peakk, NULL }, -{ "peak.a", S(PEAK), 4, "k", "a", NULL, NULL, (SUBR)peaka }, -{ "printk", S(PRINTK), 3, "", "iko", (SUBR)printkset, (SUBR)printk, NULL }, -{ "printks",S(PRINTKS), 3, "", "TiM", (SUBR)printksset,(SUBR)printks, NULL }, -{ "prints",S(PRINTS), 1, "", "TM", (SUBR)printsset, NULL, NULL }, -{ "printk2", S(PRINTK2),3, "", "ko", (SUBR)printk2set, (SUBR)printk2, NULL }, -{ "portk", S(KPORT), 3, "k", "kko", (SUBR)kporset, (SUBR)kport, NULL }, -{ "tonek", S(KTONE), 3, "k", "kko", (SUBR)ktonset, (SUBR)ktone, NULL }, -{ "atonek", S(KTONE), 3, "k", "kko", (SUBR)ktonset, (SUBR)katone, NULL }, -{ "resonk", S(KRESON), 3, "k", "kkkpo",(SUBR)krsnset, (SUBR)kreson, NULL }, -{ "aresonk",S(KRESON), 3, "k", "kkkpo",(SUBR)krsnset, (SUBR)kareson, NULL }, -{ "limit.i", S(LIMIT), 1, "i", "iii", (SUBR)klimit, NULL, NULL }, -{ "limit.k", S(LIMIT), 2, "k", "xkk", NULL, (SUBR)klimit, NULL }, -{ "limit.a", S(LIMIT), 4, "a", "xkk", NULL, NULL, (SUBR)limit }, -{ "prealloc", S(AOP), 1, "", "Tio", (SUBR)prealloc, NULL, NULL }, -/* opcode dspace thread outarg inargs isub ksub asub */ -{ "inh", S(INH), 4, "aaaaaa","", NULL, NULL, inh }, -{ "ino", S(INO), 4, "aaaaaaaa","", NULL, NULL, ino }, -{ "inx", S(INALL), 4, "aaaaaaaaaaaaaaaa","", NULL, NULL, in16 }, -{ "in32", S(INALL), 4, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", - "", NULL, NULL, in32 }, -//{ "inch", S(INCH), 4, "a", "k", NULL, NULL, inch_opcode }, -{ "inch", S(INCH), 4, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", - "z", NULL, NULL, inch_opcode }, -{ "_in", S(INALL), 4, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", - "", NULL, NULL, inall_opcode }, + /* opcode dspace flags thread outarg inargs isub ksub asub */ + { "", 0, 0, 0, "", "", NULL, NULL, NULL, NULL }, + { "instr", 0, 0, 0, "", "", NULL, NULL, NULL, NULL }, + { "endin", 0, 0, 0, "", "", NULL, NULL, NULL, NULL }, + /* IV - Sep 8 2002 */ + { "opcode", 0, 0, 0, "", "", NULL, NULL, NULL, NULL }, + { "endop", 0, 0, 0, "", "", NULL, NULL, NULL, NULL }, + { "$label", S(LBLBLK), 0,0, "", "", NULL, NULL, NULL, NULL }, + { "pset", S(PVSET), 0,0, "", "m", NULL, NULL, NULL, NULL }, + + /* IV - Sep 8 2002 - added entries for user defined opcodes, xin, xout */ + /* and setksmps */ + { "##userOpcode", S(UOPCODE),0, 7, "", "", useropcdset, useropcd, useropcd }, + /* IV - Sep 10 2002: removed perf time routines of xin and xout */ + { "xin", S(XIN_MAX),0, 1, "****************", "", xinset, NULL, NULL }, + /* { "xin.64", S(XIN_HIGH),0, 1, + "****************************************************************", "", + xinset, NULL, NULL }, + { "##xin256", S(XIN_MAX),0, 1, + "****************************************************************" + "****************************************************************" + "****************************************************************" + "****************************************************************", "", + xinset, NULL, NULL },*/ + { "xout", S(XOUT_MAX),0, 1, "", "*", xoutset, NULL, NULL }, + /* { "##xout64", S(XOUT_HIGH),0, 1, "", "*", xoutset, NULL }, + { "##xout256", S(XOUT_MAX),0, 1, "", "*", xoutset, NULL },*/ + { "setksmps", S(SETKSMPS),0, 1, "", "i", setksmpsset, NULL, NULL }, + { "ctrlinit",S(CTLINIT),0,1, "", "im", ctrlinit, NULL, NULL, NULL}, + { "massign",S(MASSIGN), 0,1, "", "iip",massign_p, NULL, NULL, NULL}, + { "massign.iS",S(MASSIGNS), 0,1, "", "iSp",massign_S, NULL, NULL, NULL}, + { "turnon", S(TURNON), 0,1, "", "io", turnon, NULL, NULL, NULL }, + { "turnon.S", S(TURNON), 0,1, "", "So", turnon_S, NULL, NULL, NULL}, + { "remoteport", S(REMOTEPORT), 0,1, "", "i", remoteport, NULL, NULL, NULL}, + { "insremot",S(INSREMOT),0,1, "", "SSm",insremot, NULL, NULL, NULL}, + { "midremot",S(MIDREMOT),0,1, "", "SSm",midremot, NULL, NULL, NULL}, + { "insglobal",S(INSGLOBAL),0,1, "", "Sm", insglobal, NULL, NULL, NULL}, + { "midglobal",S(MIDGLOBAL),0,1, "", "Sm", midglobal, NULL, NULL, NULL}, + /* //{ "=", 0,0, 0, "", "", NULL, NULL, NULL, NULL}, */ + /* { "init", 0xffff /\* base names for later prefixes,suffixes *\/ }, */ + /* { "betarand",0xffff, 0,0, "", "", NULL, NULL, NULL, NULL }, */ + /* { "bexprnd", 0xffff }, */ + /* { "cauchy", 0xffff }, */ + /* { "cauchyi", 0xffff }, */ + /* { "chanctrl",0xffff }, */ + /* { "cpsmidib",0xffff }, */ + /* { "exprand", 0xffff }, */ + /* { "exprandi",0xffff }, */ + /* { "gauss" , 0xffff }, */ + /* { "gaussi" , 0xffff }, */ + /* { "limit", 0xffff }, */ + /* { "linrand", 0xffff }, */ + /* { "midictrl",0xffff }, */ + /* { "polyaft", 0xffff }, */ + /* { "ntrpol", 0xffff }, */ + /* { "octmidib",0xffff }, */ + /* { "pcauchy", 0xffff }, */ + /* { "pchbend", 0xffff }, */ + /* { "pchmidib",0xffff }, */ + /* { "poisson", 0xffff }, */ + /* { "pow", 0xffff, }, */ + /* { "tableng", 0xffff, TR }, */ + /* { "taninv2", 0xffff }, */ + /* { "timek", 0xffff, }, */ + /* { "times", 0xffff, }, */ + /* { "trirand", 0xffff }, */ + /* { "unirand", 0xffff, }, */ + /* { "weibull", 0xffff }, */ + /* { "oscil", 0xfffe, TR }, */ + /* { "oscil3", 0xfffe, TR }, */ + /* { "oscili", 0xfffe, TR }, */ + /* { "peak", 0xfffd }, */ + /* { "rtclock", 0xffff }, */ + /* { "ptablew", 0xfffe, TW }, */ + /* { "tablew", 0xfffe, TW }, */ + /* { "tablewkt",0xfffe, TW }, */ + { "ihold", S(LINK),0, 1, "", "", ihold }, + { "turnoff",S(LINK),0, 2, "", "", NULL, turnoff }, + { "=.S", S(STRCPY_OP),0, 1, "S", "S", + (SUBR) strcpy_opcode_S, NULL, (SUBR) NULL }, + { "=.T", S(STRGET_OP),0, 1, "S", "i", + (SUBR) strcpy_opcode_p, (SUBR) NULL, (SUBR) NULL }, + { "=.r", S(ASSIGN),0, 1, "r", "i", rassign }, + { "=.i", S(ASSIGNM),0, 1, "IIIIIIIIIIIIIIIIIIIIIIII", "m", minit }, + { "=.k", S(ASSIGNM),0, 2, "zzzzzzzzzzzzzzzzzzzzzzzz", "z", NULL, minit }, + { "=.a", S(ASSIGN),0, 4, "a", "a", NULL, NULL, aassign }, + { "=.up", S(UPSAMP),0, 4, "a", "k", NULL, NULL, (SUBR)upsamp }, + { "=.down", S(DOWNSAMP),0, 3, "k", "ao", (SUBR)downset,(SUBR)downsamp }, + // { "=.t", S(ASSIGNT),0, 2, "t", "kk", NULL, tassign, NULL }, + { "init.S", S(STRCPY_OP),0, 1, "S", "S", (SUBR) strcpy_opcode_S }, + { "init.Si", S(STRCPY_OP),0, 1, "S", "i", (SUBR) strcpy_opcode_p }, + { "init.i", S(ASSIGNM),0, 1, "IIIIIIIIIIIIIIIIIIIIIIII", "m", minit }, + { "init.k", S(ASSIGNM),0, 1, "zzzzzzzzzzzzzzzzzzzzzzzz", "m", minit }, + { "init.a", S(ASSIGNM),0, 1, "mmmmmmmmmmmmmmmmmmmmmmmm", "m", mainit }, + { ">", S(RELAT),0, 0, "b", "ii", gt, gt }, + { ">.0", S(RELAT),0, 0, "B", "kk", gt, gt }, + { ">=", S(RELAT),0, 0, "b", "ii", ge, ge }, + { ">=.0", S(RELAT),0, 0, "B", "kk", ge, ge }, + { "<", S(RELAT),0, 0, "b", "ii", lt, lt }, + { "<.0", S(RELAT),0, 0, "B", "kk", lt, lt }, + { "<=", S(RELAT),0, 0, "b", "ii", le, le }, + { "<=.0", S(RELAT),0, 0, "B", "kk", le, le }, + { "==", S(RELAT),0, 0, "b", "ii", eq, eq }, + { "==.0", S(RELAT),0, 0, "B", "kk", eq, eq }, + { "!=", S(RELAT),0, 0, "b", "ii", ne, ne }, + { "!=.0", S(RELAT),0, 0, "B", "kk", ne, ne }, + { "&&", S(LOGCL),0, 0, "b", "bb", and, and }, + { "&&.0", S(LOGCL),0, 0, "B", "BB", and, and }, + { "||", S(LOGCL),0, 0, "b", "bb", or, or }, + { "||.0", S(LOGCL),0, 0, "B", "BB", or, or }, + { ":cond.i", S(CONVAL),0, 1, "i", "bii", conval }, + { ":cond.k", S(CONVAL),0, 2, "k", "Bkk", NULL, conval }, + { ":cond.a", S(CONVAL),0, 4, "a", "Bxx", NULL, NULL, aconval }, + { "##add.ii", S(AOP),0, 1, "i", "ii", addkk }, + { "##sub.ii", S(AOP),0, 1, "i", "ii", subkk }, + { "##mul.ii", S(AOP),0, 1, "i", "ii", mulkk }, + { "##div.ii", S(AOP),0, 1, "i", "ii", divkk }, + { "##mod.ii", S(AOP),0, 1, "i", "ii", modkk }, + { "##add.kk", S(AOP),0, 2, "k", "kk", NULL, addkk }, + { "##sub.kk", S(AOP),0, 2, "k", "kk", NULL, subkk }, + { "##mul.kk", S(AOP),0, 2, "k", "kk", NULL, mulkk }, + { "##div.kk", S(AOP),0, 2, "k", "kk", NULL, divkk }, + { "##mod.kk", S(AOP),0, 2, "k", "kk", NULL, modkk }, + { "##add.ka", S(AOP),0, 4, "a", "ka", NULL, NULL, addka }, + { "##sub.ka", S(AOP),0, 4, "a", "ka", NULL, NULL, subka }, + { "##mul.ka", S(AOP),0, 4, "a", "ka", NULL, NULL, mulka }, + { "##div.ka", S(AOP),0, 4, "a", "ka", NULL, NULL, divka }, + { "##mod.ka", S(AOP),0, 4, "a", "ka", NULL, NULL, modka }, + { "##add.ak", S(AOP),0, 4, "a", "ak", NULL, NULL, addak }, + { "##sub.ak", S(AOP),0, 4, "a", "ak", NULL, NULL, subak }, + { "##mul.ak", S(AOP),0, 4, "a", "ak", NULL, NULL, mulak }, + { "##div.ak", S(AOP),0, 4, "a", "ak", NULL, NULL, divak }, + { "##mod.ak", S(AOP),0, 4, "a", "ak", NULL, NULL, modak }, + { "##add.aa", S(AOP),0, 4, "a", "aa", NULL, NULL, addaa }, + { "##sub.aa", S(AOP),0, 4, "a", "aa", NULL, NULL, subaa }, + { "##mul.aa", S(AOP),0, 4, "a", "aa", NULL, NULL, mulaa }, + { "##div.aa", S(AOP),0, 4, "a", "aa", NULL, NULL, divaa }, + { "##mod.aa", S(AOP),0, 4, "a", "aa", NULL, NULL, modaa }, + { "divz", 0xfffc }, + { "divz.ii", S(DIVZ),0, 1, "i", "iii", divzkk, NULL, NULL }, + { "divz.kk", S(DIVZ),0, 2, "k", "kkk", NULL, divzkk, NULL }, + { "divz.ak", S(DIVZ),0, 4, "a", "akk", NULL, NULL, divzak }, + { "divz.ka", S(DIVZ),0, 4, "a", "kak", NULL, NULL, divzka }, + { "divz.aa", S(DIVZ),0, 4, "a", "aak", NULL, NULL, divzaa }, + { "int.i", S(EVAL),0, 1, "i", "i", int1 }, + { "frac.i", S(EVAL),0, 1, "i", "i", frac1 }, + { "round.i",S(EVAL),0, 1, "i", "i", int1_round }, + { "floor.i",S(EVAL),0, 1, "i", "i", int1_floor }, + { "ceil.i", S(EVAL),0, 1, "i", "i", int1_ceil }, + { "rnd.i", S(EVAL),0, 1, "i", "i", rnd1 }, + { "birnd.i",S(EVAL),0, 1, "i", "i", birnd1 }, + { "abs.i", S(EVAL),0, 1, "i", "i", abs1 }, + { "exp.i", S(EVAL),0, 1, "i", "i", exp01 }, + { "log.i", S(EVAL),0, 1, "i", "i", log01 }, + { "sqrt.i", S(EVAL),0, 1, "i", "i", sqrt1 }, + { "sin.i", S(EVAL),0, 1, "i", "i", sin1 }, + { "cos.i", S(EVAL),0, 1, "i", "i", cos1 }, + { "tan.i", S(EVAL),0, 1, "i", "i", tan1 }, + { "qinf.i", S(EVAL),0, 1, "i", "i", is_inf }, + { "qnan.i", S(EVAL),0, 1, "i", "i", is_NaN }, + { "sininv.i", S(EVAL),0, 1, "i", "i", asin1 }, + { "cosinv.i", S(EVAL),0, 1, "i", "i", acos1 }, + { "taninv.i", S(EVAL),0, 1, "i", "i", atan1 }, + { "taninv2.i",S(AOP),0, 1, "i", "ii", atan21 }, + { "log10.i",S(EVAL),0, 1, "i", "i", log101 }, + { "log2.i", S(EVAL),0, 1, "i", "i", log21 }, + { "sinh.i", S(EVAL),0, 1, "i", "i", sinh1 }, + { "cosh.i", S(EVAL),0, 1, "i", "i", cosh1 }, + { "tanh.i", S(EVAL),0, 1, "i", "i", tanh1 }, + { "int.k", S(EVAL),0, 2, "k", "k", NULL, int1 }, + { "frac.k", S(EVAL),0, 2, "k", "k", NULL, frac1 }, + { "round.k",S(EVAL),0, 2, "k", "k", NULL, int1_round }, + { "floor.k",S(EVAL),0, 2, "k", "k", NULL, int1_floor }, + { "ceil.k", S(EVAL),0, 2, "k", "k", NULL, int1_ceil }, + { "rnd.k", S(EVAL),0, 2, "k", "k", NULL, rnd1 }, + { "birnd.k",S(EVAL),0, 2, "k", "k", NULL, birnd1 }, + { "abs.k", S(EVAL),0, 2, "k", "k", NULL, abs1 }, + { "exp.k", S(EVAL),0, 2, "k", "k", NULL, exp01 }, + { "log.k", S(EVAL),0, 2, "k", "k", NULL, log01 }, + { "sqrt.k", S(EVAL),0, 2, "k", "k", NULL, sqrt1 }, + { "sin.k", S(EVAL),0, 2, "k", "k", NULL, sin1 }, + { "cos.k", S(EVAL),0, 2, "k", "k", NULL, cos1 }, + { "tan.k", S(EVAL),0, 2, "k", "k", NULL, tan1 }, + { "qinf.k", S(EVAL),0, 2, "k", "k", NULL, is_inf }, + { "qnan.k", S(EVAL),0, 2, "k", "k", NULL, is_NaN }, + { "sininv.k", S(EVAL),0, 2, "k", "k", NULL, asin1 }, + { "cosinv.k", S(EVAL),0, 2, "k", "k", NULL, acos1 }, + { "taninv.k", S(EVAL),0, 2, "k", "k", NULL, atan1 }, + { "taninv2.k",S(AOP),0, 2, "k", "kk", NULL, atan21 }, + { "sinh.k", S(EVAL),0, 2, "k", "k", NULL, sinh1 }, + { "cosh.k", S(EVAL),0, 2, "k", "k", NULL, cosh1 }, + { "tanh.k", S(EVAL),0, 2, "k", "k", NULL, tanh1 }, + { "log10.k",S(EVAL),0, 2, "k", "k", NULL, log101 }, + { "log2.k", S(EVAL),0, 2, "k", "k", NULL, log21 }, + { "int.a", S(EVAL),0, 4, "a", "a", NULL, NULL, int1a }, + { "frac.a", S(EVAL),0, 4, "a", "a", NULL, NULL, frac1a }, + { "round.a",S(EVAL),0, 4, "a", "a", NULL, NULL, int1a_round }, + { "floor.a",S(EVAL),0, 4, "a", "a", NULL, NULL, int1a_floor }, + { "ceil.a", S(EVAL),0, 4, "a", "a", NULL, NULL, int1a_ceil }, + { "abs.a", S(EVAL),0, 4, "a", "a", NULL, NULL, absa }, + { "exp.a", S(EVAL),0, 4, "a", "a", NULL, NULL, expa }, + { "log.a", S(EVAL),0, 4, "a", "a", NULL, NULL, loga }, + { "sqrt.a", S(EVAL),0, 4, "a", "a", NULL, NULL, sqrta }, + { "sin.a", S(EVAL),0, 4, "a", "a", NULL, NULL, sina }, + { "cos.a", S(EVAL),0, 4, "a", "a", NULL, NULL, cosa }, + { "tan.a", S(EVAL),0, 4, "a", "a", NULL, NULL, tana }, + { "qinf.a", S(EVAL),0, 4, "a", "a", NULL, NULL, is_infa }, + { "qnan.a", S(EVAL),0, 4, "a", "a", NULL, NULL, is_NaNa }, + { "sininv.a", S(EVAL),0, 4, "a", "a", NULL, NULL, asina }, + { "cosinv.a", S(EVAL),0, 4, "a", "a", NULL, NULL, acosa }, + { "taninv.a", S(EVAL),0, 4, "a", "a", NULL, NULL, atana }, + { "taninv2.a",S(AOP),0, 4, "a", "aa", NULL, NULL, atan2aa }, + { "sinh.a", S(EVAL),0, 4, "a", "a", NULL, NULL, sinha }, + { "cosh.a", S(EVAL),0, 4, "a", "a", NULL, NULL, cosha }, + { "tanh.a", S(EVAL),0, 4, "a", "a", NULL, NULL, tanha }, + { "log10.a",S(EVAL),0, 4, "a", "a", NULL, NULL, log10a }, + { "log2.a", S(EVAL),0, 4, "a", "a", NULL, NULL, log2a }, + { "ampdb.a",S(EVAL),0, 4, "a", "a", NULL, NULL, aampdb }, + { "ampdb.i",S(EVAL),0, 1, "i", "i", ampdb }, + { "ampdb.k",S(EVAL),0, 2, "k", "k", NULL, ampdb }, + { "ampdbfs.a",S(EVAL),0, 4, "a", "a", NULL, NULL, aampdbfs }, + { "ampdbfs.i",S(EVAL),0, 1, "i", "i", ampdbfs }, + { "ampdbfs.k",S(EVAL),0, 2, "k", "k", NULL, ampdbfs }, + { "dbamp.i",S(EVAL),0, 1, "i", "i", dbamp }, + { "dbamp.k",S(EVAL),0, 2, "k", "k", NULL, dbamp }, + { "dbfsamp.i",S(EVAL),0, 1, "i", "i", dbfsamp }, + { "dbfsamp.k",S(EVAL),0, 2, "k", "k", NULL, dbfsamp }, + { "rtclock.i",S(EVAL),0, 1, "i", "", rtclock }, + { "rtclock.k",S(EVAL),0, 2, "k", "", NULL, rtclock }, + { "ftlen.i",S(EVAL),0, 1, "i", "i", ftlen }, + { "ftsr.i",S(EVAL),0, 1, "i", "i", ftsr }, + { "ftlptim.i",S(EVAL),0, 1, "i", "i", ftlptim }, + { "ftchnls.i",S(EVAL),0, 1, "i", "i", ftchnls }, + { "ftcps.i",S(EVAL),0, 1, "i", "i", ftcps }, + { "i.i", S(ASSIGN),0, 1, "i", "i", assign }, + { "i.k", S(ASSIGN),0, 1, "i", "k", assign }, + { "k.i", S(ASSIGN),0, 1, "k", "i", assign }, + { "k.a", S(DOWNSAMP),0, 3, "k", "ao", (SUBR)downset,(SUBR)downsamp }, + { "cpsoct.i",S(EVAL),0, 1, "i", "i", cpsoct }, + { "octpch.i",S(EVAL),0, 1, "i", "i", octpch }, + { "cpspch.i",S(EVAL),0, 1, "i", "i", cpspch }, + { "pchoct.i",S(EVAL),0, 1, "i", "i", pchoct }, + { "octcps.i",S(EVAL),0, 1, "i", "i", octcps }, + { "cpsoct.k",S(EVAL),0, 2, "k", "k", NULL, cpsoct }, + { "octpch.k",S(EVAL),0, 2, "k", "k", NULL, octpch }, + { "cpspch.k",S(EVAL),0, 2, "k", "k", NULL, cpspch }, + { "pchoct.k",S(EVAL),0, 2, "k", "k", NULL, pchoct }, + { "octcps.k",S(EVAL),0, 2, "k", "k", NULL, octcps }, + { "cpsoct.a",S(EVAL),0, 4, "a", "a", NULL, NULL, acpsoct }, + { "cpsmidinn.i",S(EVAL),0,1, "i", "i", cpsmidinn }, + { "octmidinn.i",S(EVAL),0,1, "i", "i", octmidinn }, + { "pchmidinn.i",S(EVAL),0,1, "i", "i", pchmidinn }, + { "cpsmidinn.k",S(EVAL),0,2, "k", "k", NULL, cpsmidinn }, + { "octmidinn.k",S(EVAL),0,2, "k", "k", NULL, octmidinn }, + { "pchmidinn.k",S(EVAL),0,2, "k", "k", NULL, pchmidinn }, + { "notnum", S(MIDIKMB),0, 1, "i", "", notnum }, + { "veloc", S(MIDIMAP),0, 1, "i", "oh", veloc }, + { "pchmidi",S(MIDIKMB),0, 1, "i", "", pchmidi }, + { "octmidi",S(MIDIKMB),0, 1, "i", "", octmidi }, + { "cpsmidi",S(MIDIKMB),0, 1, "i", "", cpsmidi }, + { "pchmidib.i",S(MIDIKMB),0,1, "i", "o", pchmidib_i }, + { "octmidib.i",S(MIDIKMB),0,1, "i", "o", octmidib_i }, + { "cpsmidib.i",S(MIDIKMB),0,1, "i", "o", icpsmidib_i }, + { "pchmidib.k",S(MIDIKMB),0,3, "k", "o", midibset, pchmidib }, + { "octmidib.k",S(MIDIKMB),0,3, "k", "o", midibset, octmidib }, + { "cpsmidib.k",S(MIDIKMB),0,3, "k", "o", midibset, icpsmidib }, + { "ampmidi",S(MIDIAMP),0, 1, "i", "io", ampmidi }, + { "aftouch",S(MIDIKMAP),0, 3, "k", "oh", aftset, aftouch }, + { "pchbend.i",S(MIDIMAP),0,0x21, "i", "jp", ipchbend }, + { "pchbend.k",S(MIDIKMAP),0,0x23, "k", "jp", kbndset,kpchbend }, + { "midictrl.i",S(MIDICTL),0,1, "i", "ioh", imidictl }, + { "midictrl.k",S(MIDICTL),0,3, "k", "ioh", mctlset, midictl }, + { "polyaft.i",S(MIDICTL),0,1, "i", "ioh", imidiaft }, + { "polyaft.k",S(MIDICTL),0,3, "k", "ioh", maftset, midiaft }, + { "chanctrl.i",S(CHANCTL),0,1, "i", "iioh", ichanctl }, + { "chanctrl.k",S(CHANCTL),0,3, "k", "iioh", chctlset,chanctl }, + { "line", S(LINE),0, 3, "k", "iii", linset, kline, NULL }, + { "line.a", S(LINE),0, 5, "a", "iii", linset, NULL, aline }, + { "expon", S(EXPON),0, 3, "k", "iii", expset, kexpon, NULL }, + { "expon.a", S(EXPON),0, 5, "a", "iii", expset, NULL, expon }, + { "cosseg", S(COSSEG),0, 3, "k", "iin", csgset, kosseg, NULL }, + { "cosseg.a", S(COSSEG),0, 5, "a", "iin", csgset, NULL, cosseg }, + { "cossegb", S(COSSEG),0, 3, "k", "iin", csgset_bkpt, kosseg, NULL }, + { "cossegb.a", S(COSSEG),0, 5, "a", "iin", csgset_bkpt, NULL, cosseg }, + { "cossegr", S(COSSEG),0, 3, "k", "iin", csgrset, kcssegr, NULL }, + { "cossegr.a", S(COSSEG),0, 5, "a", "iin", csgrset, NULL, cossegr }, + { "linseg", S(LINSEG),0, 3, "k", "iin", lsgset, klnseg, NULL }, + { "linseg.a", S(LINSEG),0, 5, "a", "iin", lsgset, NULL, linseg }, + { "linsegb", S(LINSEG),0, 3, "k", "iin", lsgset_bkpt, klnseg, NULL }, + { "linsegb.a", S(LINSEG),0, 5, "a", "iin", lsgset_bkpt, NULL, linseg }, + { "linsegr",S(LINSEG),0, 3, "k", "iin", lsgrset,klnsegr,NULL }, + { "linsegr.a",S(LINSEG),0, 5, "a", "iin", lsgrset,NULL,linsegr }, + { "expseg", S(EXXPSEG),0, 3, "k", "iin", xsgset, kxpseg, NULL }, + { "expseg.a", S(EXXPSEG),0, 5, "a", "iin", xsgset, NULL, expseg }, + { "expsegb", S(EXXPSEG),0, 3, "k", "iin", xsgset_bkpt, kxpseg, NULL }, + { "expsegb.a", S(EXXPSEG),0, 5, "a", "iin", xsgset_bkpt, NULL, expseg }, + { "expsega",S(EXPSEG2),0, 5, "a", "iin", xsgset2, NULL, expseg2 }, + { "expsegba",S(EXPSEG2),0, 5, "a", "iin", xsgset2b, NULL, expseg2 }, + { "expsegr",S(EXPSEG),0, 3, "k", "iin", xsgrset,kxpsegr,NULL }, + { "expsegr.a",S(EXPSEG),0, 5, "a", "iin", xsgrset,NULL,expsegr }, + { "linen", S(LINEN),0, 3, "k", "kiii", lnnset, klinen, NULL }, + { "linen.a", S(LINEN),0, 5, "a", "aiii", lnnset, NULL, linen }, + { "linen.x", S(LINEN),0, 5, "a", "kiii", lnnset, NULL, linen }, + { "linenr", S(LINENR),0, 3, "k", "kiii", lnrset, klinenr,NULL }, + { "linenr.a", S(LINENR),0, 5, "a", "aiii", lnrset, NULL,linenr }, + { "linenr.x", S(LINENR),0, 5, "a", "kiii", lnrset, NULL,linenr }, + { "envlpx", S(ENVLPX), TR, 3, "k","kiiiiiio", evxset, knvlpx, NULL }, + { "envlpxr", S(ENVLPR),TR, 3, "k","aiiiiioo", evrset, knvlpxr, NULL }, + { "envlpx.a", S(ENVLPX), TR, 5, "a","kiiiiiio", evxset, NULL,envlpx }, + { "envlpxr.a", S(ENVLPR),TR, 5, "a","aiiiiioo", evrset, NULL,envlpxr }, + { "envlpx.x", S(ENVLPX), TR, 5, "a","kiiiiiio", evxset, NULL,envlpx }, + { "envlpxr.x", S(ENVLPR),TR, 5, "a","kiiiiioo", evrset, NULL,envlpxr }, + { "phasor", S(PHSOR),0, 5, "a", "xo", phsset, NULL, phsor }, + { "phasor.k", S(PHSOR),0, 3, "k", "ko", phsset, kphsor, NULL }, + { "ephasor", S(EPHSOR), 0, 5, "aa", "xko", ephsset, NULL, ephsor }, + { "signum.i", S(ASSIGN), 0, 1, "i", "i", signum, NULL, NULL }, + { "signum.k", S(ASSIGN), 0, 3, "k", "k", signum, signum, NULL }, + { "signum.a", S(ASSIGN), 0, 4, "a", "a", NULL, NULL, asignum }, + /* { "table", 0xffff, TR }, */ + /* { "tablei", 0xffff, TR }, */ + /* { "table3", 0xffff, TR }, */ + { "table.i", S(TABL),0, 1, "i", "iiooo",(SUBR)tabler_init }, + { "table.k", S(TABL),0, 3, "k", "xiooo",(SUBR)tabl_setup, + (SUBR)tabler_kontrol }, + { "table.a", S(TABL),0, 5, "a", "xiooo",(SUBR)tabl_setup, NULL, + (SUBR)tabler_audio }, + { "tablei.i", S(TABL),0, 1, "i", "iiooo",(SUBR)tableir_init }, + { "tablei.k", S(TABL),0, 3, "k", "xiooo",(SUBR)tabl_setup, + (SUBR)tableir_kontrol }, + { "tablei.a", S(TABL),0, 5, "a", "xiooo",(SUBR)tabl_setup, NULL, + (SUBR)tableir_audio }, + { "table3.i", S(TABL),0, 1, "i", "iiooo",(SUBR)table3r_init }, + { "table3.k", S(TABL),0, 3, "k", "xiooo",(SUBR)tabl_setup, + (SUBR)table3r_kontrol }, + { "table3.a", S(TABL),0, 5, "a", "xiooo",(SUBR)tabl_setup, NULL, + (SUBR)table3r_audio }, + { "ptable", 0xffff, TR }, + { "ptablei", 0xffff, TR }, + { "ptable3", 0xffff, TR }, + { "ptable.i", S(TABLE),0, 1, "i", "iiooo",pitable }, + { "ptable.k", S(TABLE),0, 3, "k", "xiooo",tblset, pktable }, + { "ptable.a", S(TABLE),0, 5, "a", "xiooo",tblset, NULL, ptablefn }, + { "ptablei.i", S(TABLE),0, 1, "i", "iiooo",pitabli }, + { "ptablei.k", S(TABLE),0, 3, "k", "xiooo",tblset, pktabli }, + { "ptablei.a", S(TABLE),0, 5, "a", "xiooo",tblset, NULL, ptabli }, + { "ptable3.i", S(TABLE),0, 1, "i", "iiooo",pitabl3 }, + { "ptable3.k", S(TABLE),0, 3, "k", "xiooo",tblset, pktabl3 }, + { "ptable3.a", S(TABLE),0, 5, "a", "xiooo",tblset, NULL, ptabl3 }, + { "oscil1", S(OSCIL1), TR, 3, "k", "ikij", ko1set, kosc1 }, + { "oscil1i",S(OSCIL1), TR, 3, "k", "ikij", ko1set, kosc1i }, + { "osciln", S(OSCILN), TR, 5, "a", "kiii", oscnset,NULL, osciln }, + { "oscil.a",S(OSC),0, 5, "a", "kkjo", oscset, NULL, osckk }, + { "oscil.kk",S(OSC),0, 7, "s", "kkjo", oscset, koscil, osckk }, + { "oscil.ka",S(OSC),0, 5, "a", "kajo", oscset, NULL, oscka }, + { "oscil.ak",S(OSC),0, 5, "a", "akjo", oscset, NULL, oscak }, + { "oscil.aa",S(OSC),0, 5, "a", "aajo", oscset, NULL, oscaa }, + { "oscil.kkA",S(OSC),0, 7, "a", "kki[]o", oscsetA, koscil, osckk }, + { "oscil.kaA",S(OSC),0, 5, "a", "kai[]o", oscsetA, NULL, oscka }, + { "oscil.akA",S(OSC),0, 5, "a", "aki[]o", oscsetA, NULL, oscak }, + { "oscil.aaA",S(OSC),0, 5, "a", "aai[]o", oscsetA, NULL,oscaa }, + /* Change these to + { "oscil.kk", S(POSC),0, 7, "s", "kkjo", posc_set, kposc, posckk }, + { "oscil.ka", S(POSC),0, 5, "a", "kajo", posc_set, NULL, poscka }, + { "oscil.ak", S(POSC),0, 5, "a", "akjo", posc_set, NULL, poscak }, + { "oscil.aa", S(POSC),0, 5, "a", "aajo", posc_set, NULL, poscaa }, + { "oscil3.kk", S(POSC),0, 7, "s", "kkjo", posc_set, kposc3, posc3 }, + */ + { "oscili.a",S(OSC),0, 5, "a", "kkjo", oscset, NULL, osckki }, + { "oscili.kk",S(OSC),0, 3, "k", "kkjo", oscset, koscli, NULL }, + { "oscili.ka",S(OSC),0, 5, "a", "kajo", oscset, NULL, osckai }, + { "oscili.ak",S(OSC),0, 5, "a", "akjo", oscset, NULL, oscaki }, + { "oscili.aa",S(OSC),0, 5, "a", "aajo", oscset, NULL, oscaai }, + { "oscili.aA",S(OSC),0, 5, "a", "kki[]o", oscsetA, NULL, osckki }, + { "oscili.kkA",S(OSC),0, 3, "k", "kki[]o", oscsetA, koscli, NULL }, + { "oscili.kaA",S(OSC),0, 5, "a", "kai[]o", oscsetA, NULL, osckai }, + { "oscili.akA",S(OSC),0, 5, "a", "aki[]o", oscsetA, NULL, oscaki }, + { "oscili.aaA",S(OSC),0, 5, "a", "aai[]o", oscsetA, NULL, oscaai }, + { "oscil3.a",S(OSC),0, 5, "a", "kkjo", oscset, NULL, osckk3 }, + { "oscil3.kk",S(OSC),0, 3, "k", "kkjo", oscset, koscl3, NULL }, + { "oscil3.ka",S(OSC),0, 5, "a", "kajo", oscset, NULL, oscka3 }, + { "oscil3.ak",S(OSC),0, 5, "a", "akjo", oscset, NULL, oscak3 }, + { "oscil3.aa",S(OSC),0, 5, "a", "aajo", oscset, NULL, oscaa3 }, + { "oscil3.aA",S(OSC),0, 5, "a", "kki[]o", oscsetA, NULL, osckk3 }, + { "oscil3.kkA",S(OSC),0, 3, "k", "kki[]o", oscsetA, koscl3, NULL }, + { "oscil3.kaA",S(OSC),0, 5, "a", "kai[]o", oscsetA, NULL, oscka3 }, + { "oscil3.akA",S(OSC),0, 5, "a", "aki[]o", oscsetA, NULL, oscak3 }, + { "oscil3.aaA",S(OSC),0, 5, "a", "aai[]o", oscsetA, NULL, oscaa3 }, + /* end change */ + { "foscil", S(FOSC),TR, 5, "a", "xkxxkjo",foscset,NULL, foscil }, + { "foscili",S(FOSC),TR, 5, "a", "xkxxkjo",foscset,NULL, foscili }, + { "loscil", S(LOSC),TR, 5, "mm","xkjojoojoo",losset,NULL, loscil }, + { "loscil3", S(LOSC),TR, 5, "mm","xkjojoojoo",losset,NULL, loscil3 }, + { "adsyn", S(ADSYN),0, 5, "a", "kkkSo", adset_S, NULL, adsyn }, + { "adsyn.i", S(ADSYN),0, 5, "a", "kkkio", adset, NULL, adsyn }, + { "buzz", S(BUZZ),TR, 5, "a", "xxkio", bzzset, NULL, buzz }, + { "gbuzz", S(GBUZZ),TR, 5, "a", "xxkkkio",gbzset, NULL, gbuzz }, + { "pluck", S(PLUCK), TR, 5, "a", "kkiiioo",plukset,NULL, pluck }, + { "rand", S(RAND),0, 5, "a", "xvoo", rndset, NULL, arand }, + { "rand.k", S(RAND),0, 3, "k", "xvoo", rndset, krand, NULL }, + { "randh", S(RANDH),0, 5, "a", "xxvoo", rhset, NULL, randh }, + { "randh.k", S(RANDH),0, 3, "k", "xxvoo", rhset, krandh, NULL }, + { "randi", S(RANDI),0, 5, "a", "xxvoo", riset, NULL, randi }, + { "randi.k", S(RANDI),0, 3, "k", "xxvoo", riset, krandi, NULL }, + { "port", S(PORT),0, 3, "k", "kio", porset, port }, + { "tone.k", S(TONE),0, 5, "a", "ako", tonset, NULL, tone }, + { "tonex.k",S(TONEX),0, 5, "a", "akoo", tonsetx, NULL, tonex }, + { "atone.k", S(TONE),0, 5, "a", "ako", tonset, NULL, atone }, + { "atonex.k", S(TONEX),0, 5, "a", "akoo", tonsetx, NULL, atonex }, + { "reson", S(RESON), 0, 5, "a", "axxoo", rsnset, NULL, reson }, + { "resonx", S(RESONX),0, 5, "a", "axxooo", rsnsetx, NULL, resonx }, + { "areson.kk", S(RESON),0,5, "a", "akkoo",rsnset, NULL, areson }, + { "lpread", S(LPREAD),0, 3, "kkkk", "kSoo", lprdset_S,lpread }, + { "lpread.i", S(LPREAD),0, 3, "kkkk", "kioo", lprdset,lpread }, + { "lpform", S(LPFORM),0, 3, "kk", "k", lpformantset,lpformant }, + { "lpreson",S(LPRESON),0, 5, "a", "a", lprsnset,NULL, lpreson }, + { "lpfreson",S(LPFRESON),0,5, "a", "ak", lpfrsnset,NULL, lpfreson}, + { "lpslot" , S(LPSLOT),0, 1, "", "i", lpslotset, NULL, NULL }, + { "lpinterp", S(LPINTERPOL),0, 3, "", "iik", lpitpset, lpinterpol, NULL}, + { "rms", S(RMS),0, 3, "k", "aqo", rmsset, rms }, + { "gain", S(GAIN),0, 5, "a", "akqo", gainset,NULL, gain }, + { "balance",S(BALANCE),0, 5, "a", "aaqo", balnset,NULL, balance }, + { "pan", S(PAN),0, 5, "aaaa", "akkioo",(SUBR)panset,NULL, (SUBR)pan }, + { "soundin",S(SOUNDIN_),0,5,"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm","Soooo", + sndinset_S, NULL, soundin }, + { "soundin.i",S(SOUNDIN_),0,5,"mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm","ioooo", + sndinset, NULL, soundin }, + { "soundout",S(SNDOUT), _QQ, 5, "", "aSo", sndoutset_S, NULL, soundout }, + { "soundout.i",S(SNDOUT), _QQ, 5, "", "aio", sndoutset, NULL, soundout }, + { "soundouts",S(SNDOUTS),_QQ, 5, "", "aaSo", sndoutset_S, NULL, soundouts }, + { "soundouts.i",S(SNDOUTS),_QQ, 5, "", "aaio", sndoutset, NULL, soundouts }, + { "in.a", S(INM),0, 4, "a", "", NULL, NULL, in }, + { "in.A", S(INM),0, 4, "a[]", "", NULL, NULL, inarray }, + { "ins", S(INS),0, 4, "aa", "", NULL, NULL, ins }, + { "inq", S(INQ),0, 4, "aaaa", "", NULL, NULL, inq }, + { "out.a", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "out.A", S(OUTARRAY),0, 4, "", "a[]", NULL, NULL, outarr }, + { "outs", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "outq", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "outh", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "outo", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "outx", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "out32", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "outs1", S(OUTM),0, 4, "", "a", NULL, NULL, outs1 }, + { "outs2", S(OUTM),0, 4, "", "a", NULL, NULL, outs2 }, + { "outq1", S(OUTM),0, 4, "", "a", NULL, NULL, outq1 }, + { "outq2", S(OUTM),0, 4, "", "a", NULL, NULL, outq2 }, + { "outq3", S(OUTM),0, 4, "", "a", NULL, NULL, outq3 }, + { "outq4", S(OUTM),0, 4, "", "a", NULL, NULL, outq4 }, + { "igoto", S(GOTO),0, 1, "", "l", igoto }, + { "kgoto", S(GOTO),0, 2, "", "l", NULL, kgoto }, + { "goto", S(GOTO),0, 3, "", "l", igoto, kgoto }, + { "cigoto", S(CGOTO),0, 1, "", "Bl", icgoto }, + { "ckgoto", S(CGOTO),0, 2, "", "Bl", NULL, kcgoto }, + { "cggoto.0", S(CGOTO),0, 3, "", "Bl", icgoto, kcgoto }, + { "timout", S(TIMOUT),0, 3, "", "iil", timset, timout }, + { "reinit", S(GOTO),0, 2, "", "l", NULL, reinit }, + { "rigoto", S(GOTO),0, 1, "", "l", rigoto }, + { "rireturn",S(LINK),0, 1, "", "", rireturn }, + { "tigoto", S(GOTO),0, 1, "", "l", tigoto }, + { "tival", S(EVAL),0, 1, "i", "", tival }, + { "print", S(PRINTV),WR, 1, "", "m", printv }, + { "display",S(DSPLAY),0, 7, "", "xioo", dspset, kdsplay,dsplay }, + { "pvsdisp",S(FSIGDISP),0, 3, "", "foo", fdspset, fdsplay,NULL }, + { "dispfft",S(DSPFFT),0, 7, "", "xiiooo",fftset,kdspfft,dspfft }, + { "dumpk", S(KDUMP),0, 3, "", "kSii", kdmpset_S,kdump }, + { "dumpk2", S(KDUMP2),0, 3, "", "kkSii",kdmp2set_S,kdump2 }, + { "dumpk3", S(KDUMP3),0, 3, "", "kkkSii",kdmp3set_S,kdump3 }, + { "dumpk4", S(KDUMP4),0, 3, "", "kkkkSii",kdmp4set_S,kdump4 }, + { "dumpk.i", S(KDUMP),0, 3, "", "kiii", kdmpset_p,kdump }, + { "dumpk2.i", S(KDUMP2),0, 3, "", "kkiii",kdmp2set_p,kdump2 }, + { "dumpk3.i", S(KDUMP3),0, 3, "", "kkkiii",kdmp3set_p,kdump3 }, + { "dumpk4.i", S(KDUMP4),0, 3, "", "kkkkiii",kdmp4set_p,kdump4 }, + { "readk", S(KREAD),0, 3, "k", "Sii", krdset_S, kread }, + { "readk2", S(KREAD2),0, 3, "kk", "Sii", krd2set_S, kread2 }, + { "readk3", S(KREAD3),0, 3, "kkk", "Sii", krd3set_S, kread3 }, + { "readk4", S(KREAD4),0, 3, "kkkk", "Sii", krd4set_S, kread4 }, + { "readk.i", S(KREAD),0, 3, "k", "iii", krdset_p, kread }, + { "readk2.i", S(KREAD2),0, 3, "kk", "iii", krd2set_p, kread2 }, + { "readk3.i", S(KREAD3),0, 3, "kkk", "iii", krd3set_p, kread3 }, + { "readk4.i", S(KREAD4),0, 3, "kkkk", "iii", krd4set_p, kread4 }, + { "readks", S(KREADS),0, 3, "S", "Si", krdsset_S, kreads }, + { "readks.i", S(KREADS),0, 3, "S", "ii", krdsset_p, kreads }, + { "xyin", S(XYIN), _QQ, 1, "kk", "iiiiioo",xyinset,NULL }, + { "tempest", S(TEMPEST),0, 5, "k","kiiiiiiiiiop",tempeset,NULL,tempest}, + { "tempo", S(TEMPO),0, 3, "", "ki", tempset,tempo }, + { "pow.i", S(POW),0, 1, "i", "iip", ipow, NULL, NULL }, + { "pow.k", S(POW),0, 2, "k", "kkp", NULL, ipow, NULL }, + { "pow.a", S(POW),0, 4, "a", "akp", NULL, NULL, apow }, + { "oscilx", S(OSCILN), TR, 5, "a", "kiii", oscnset,NULL, osciln }, + { "linrand.i",S(PRAND),0, 1, "i", "k", iklinear, NULL, NULL }, + { "linrand.k",S(PRAND),0, 2, "k", "k", NULL, iklinear, NULL }, + { "linrand.a",S(PRAND),0, 4, "a", "k", NULL, NULL, alinear }, + { "trirand.i",S(PRAND),0, 1, "i", "k", iktrian, NULL, NULL }, + { "trirand.k",S(PRAND),0, 2, "k", "k", NULL, iktrian, NULL }, + { "trirand.a",S(PRAND),0, 4, "a", "k", NULL, NULL, atrian }, + { "exprand.i",S(PRAND),0, 1, "i", "k", ikexp, NULL, NULL }, + { "exprand.k",S(PRAND),0, 2, "k", "k", NULL, ikexp, NULL }, + { "exprand.a",S(PRAND),0, 4, "a", "k", NULL, NULL, aexp }, + { "bexprnd.i",S(PRAND),0, 1, "i", "k", ikbiexp, NULL, NULL }, + { "bexprnd.k",S(PRAND),0, 2, "k", "k", NULL, ikbiexp, NULL }, + { "bexprnd.a",S(PRAND),0, 4, "a", "k", NULL, NULL, abiexp }, + { "cauchy.i", S(PRAND),0, 1, "i", "k", ikcauchy, NULL, NULL }, + { "cauchy.k", S(PRAND),0, 2, "k", "k", NULL, ikcauchy, NULL }, + { "cauchy.a", S(PRAND),0, 4, "a", "k", NULL, NULL, acauchy }, + { "pcauchy.i",S(PRAND),0, 1, "i", "k", ikpcauchy, NULL,NULL }, + { "pcauchy.k",S(PRAND),0, 2, "k", "k", NULL, ikpcauchy,NULL }, + { "pcauchy.a",S(PRAND),0, 4, "a", "k", NULL, NULL, apcauchy}, + { "poisson.i",S(PRAND),0, 1, "i", "k", ikpoiss, NULL, NULL }, + { "poisson.k",S(PRAND),0, 2, "k", "k", NULL, ikpoiss, NULL }, + { "poisson.a",S(PRAND),0, 4, "a", "k", NULL, NULL, apoiss }, + { "gauss.i" , S(PRAND),0, 1, "i", "k", ikgaus, NULL, NULL }, + { "gauss.k" , S(PRAND),0, 2, "k", "k", NULL, ikgaus, NULL }, + { "gauss.a" , S(PRAND),0, 4, "a", "k", NULL, NULL, agaus }, + { "weibull.i",S(PRAND),0, 1, "i", "kk", ikweib, NULL, NULL }, + { "weibull.k",S(PRAND),0, 2, "k", "kk", NULL, ikweib, NULL }, + { "weibull.a",S(PRAND),0, 4, "a", "kk", NULL, NULL, aweib }, + { "betarand.i",S(PRAND),0,1, "i", "kkk", ikbeta, NULL, NULL }, + { "betarand.k",S(PRAND),0,2, "k", "kkk", NULL, ikbeta,NULL }, + { "betarand.a",S(PRAND),0,4, "a", "kkk", NULL, NULL, abeta }, + { "seed", S(PRAND),0, 1, "", "i", seedrand, NULL, NULL }, + { "unirand.i",S(PRAND),0, 1, "i", "k", ikuniform, NULL, NULL }, + { "unirand.k",S(PRAND),0, 2, "k", "k", NULL, ikuniform, NULL}, + { "unirand.a",S(PRAND),0, 4, "a", "k", NULL, NULL, auniform }, + { "diskin",S(DISKIN2_ARRAY),0, 5, "a[]", + "Skooooooo", + (SUBR) diskin_init_array_S, (SUBR) NULL, + (SUBR) diskin2_perf_array }, + { "diskin2",S(DISKIN2_ARRAY),0, 5, "a[]", + "Skooooooo", + (SUBR) diskin2_init_array_S, (SUBR) NULL, + (SUBR) diskin2_perf_array }, + { "diskin.i",S(DISKIN2_ARRAY),0, 5, "a[]", + "ikooooooo", + (SUBR) diskin_init_array_I, (SUBR) NULL, + (SUBR) diskin2_perf_array }, + { "diskin2.i",S(DISKIN2_ARRAY),0, 5, "a[]", + "ikooooooo", + (SUBR) diskin2_init_array_I, (SUBR) NULL, + (SUBR) diskin2_perf_array }, + { "diskin",S(DISKIN2),0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "Skooooooo", + (SUBR) diskin_init_S, (SUBR) NULL, + (SUBR) diskin2_perf }, + { "diskin2",S(DISKIN2),0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "Skooooooo", + (SUBR) diskin2_init_S, (SUBR) NULL, + (SUBR) diskin2_perf }, + { "diskin.i",S(DISKIN2),0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "ikooooooo", + (SUBR) diskin_init, (SUBR) NULL, + (SUBR) diskin2_perf }, + { "diskin2.i",S(DISKIN2),0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "ikooooooo", + (SUBR) diskin2_init, (SUBR) NULL, + (SUBR) diskin2_perf }, + { "noteon", S(OUT_ON),0, 1, "", "iii", iout_on, NULL, NULL }, + { "noteoff", S(OUT_ON),0, 1, "", "iii", iout_off, NULL, NULL }, + { "noteondur",S(OUT_ON_DUR),0,3, "", "iiii", iout_on_dur_set,iout_on_dur,NULL}, + { "noteondur2",S(OUT_ON_DUR),0,3, "", "iiii", iout_on_dur_set,iout_on_dur2,NULL}, + { "moscil",S(MOSCIL),0, 3, "", "kkkkk",moscil_set, moscil, NULL}, + { "midion",S(KOUT_ON),0, 3, "", "kkk", kvar_out_on_set,kvar_out_on,NULL}, + { "outic",S(OUT_CONTR),0, 1, "", "iiiii", out_controller, NULL, NULL}, + { "outkc",S(OUT_CONTR),0, 2, "", "kkkkk", NULL, out_controller, NULL}, + { "outic14",S(OUT_CONTR14),0,1, "", "iiiiii",out_controller14, NULL,NULL}, + { "outkc14",S(OUT_CONTR14),0,2, "", "kkkkkk",NULL, out_controller14, NULL}, + { "outipb",S(OUT_PB),0, 1, "", "iiii", out_pitch_bend, NULL , NULL}, + { "outkpb",S(OUT_PB),0, 2, "", "kkkk", NULL, out_pitch_bend, NULL}, + { "outiat",S(OUT_ATOUCH),0,1, "", "iiii", out_aftertouch, NULL , NULL}, + { "outkat",S(OUT_ATOUCH),0,2, "", "kkkk", NULL, out_aftertouch, NULL}, + { "outipc",S(OUT_PCHG),0, 1, "", "iiii", out_progchange, NULL , NULL}, + { "outkpc",S(OUT_PCHG),0, 2, "", "kkkk", NULL, out_progchange, NULL}, + { "outipat",S(OUT_POLYATOUCH),0,1,"", "iiiii", out_poly_aftertouch, NULL,NULL}, + { "outkpat",S(OUT_POLYATOUCH),0,2,"", "kkkkk", NULL, out_poly_aftertouch,NULL}, + { "release",S(REL),0, 3, "k", "", release_set, release, NULL }, + { "xtratim",S(XTRADUR),0, 1, "", "i", xtratim, NULL, NULL }, + { "mclock", S(MCLOCK),0, 3, "", "i", mclock_set, mclock, NULL }, + { "mrtmsg", S(XTRADUR),0, 1, "", "i", mrtmsg, NULL, NULL }, + { "midiout",S(MIDIOUT),0, 2, "", "kkkk", NULL, midiout, NULL }, + { "midion2", S(KON2),0, 3, "", "kkkk", kon2_set, kon2, NULL }, + { "nrpn", S(NRPN),0, 2, "", "kkk", NULL, nrpn ,NULL }, + { "mdelay", S(MDELAY),0, 3, "", "kkkkk",mdelay_set, mdelay, NULL }, + { "nsamp.i", S(EVAL),0, 1, "i", "i", numsamp }, + { "powoftwo.i",S(EVAL),0, 1, "i", "i", powoftwo }, + { "powoftwo.k",S(EVAL),0, 2, "k", "k", NULL, powoftwo }, + { "powoftwo.a",S(EVAL),0, 4, "a", "a", NULL, NULL, powoftwoa }, + { "logbtwo.i",S(EVAL),0, 1, "i", "i", ilogbasetwo }, + { "logbtwo.k",S(EVAL),0, 3, "k", "k", logbasetwo_set, logbasetwo }, + { "logbtwo.a",S(EVAL),0, 5, "a", "a", + logbasetwo_set, NULL, logbasetwoa }, + { "filelen", S(SNDINFO),0, 1, "i", "Sp", filelen_S, NULL, NULL }, + { "filenchnls", S(SNDINFO),0, 1, "i", "Sp", filenchnls_S, NULL, NULL }, + { "filesr", S(SNDINFO),0, 1, "i", "Sp", filesr_S, NULL, NULL }, + { "filebit", S(SNDINFO),0, 1, "i", "Sp", filebit_S, NULL, NULL }, + { "filepeak", S(SNDINFOPEAK),0, 1, "i", "So", filepeak_S, NULL, NULL }, + { "filevalid", S(FILEVALID),0, 1, "i", "S", filevalid_S, NULL, NULL }, + { "filelen.i", S(SNDINFO),0, 1, "i", "ip", filelen, NULL, NULL }, + { "filenchnls.i", S(SNDINFO),0, 1, "i", "ip", filenchnls, NULL, NULL }, + { "filesr.i", S(SNDINFO),0, 1, "i", "ip", filesr, NULL, NULL }, + { "filebit.i", S(SNDINFO),0, 1, "i", "ip", filebit, NULL, NULL }, + { "filepeak.i", S(SNDINFOPEAK),0, 1, "i", "io", filepeak, NULL, NULL }, + { "filevalid.i", S(FILEVALID),0, 1, "i", "i", filevalid, NULL, NULL }, + /* { "nlalp", S(NLALP),0, 5, "a", "akkoo", nlalp_set, NULL, nlalp }, */ + { "ptableiw", S(TABLEW),TW, 1, "", "iiiooo", (SUBR)pitablew, NULL, NULL}, + { "ptablew.kk", S(TABLEW),0, 3, "", "kkiooo", + (SUBR)itblchkw,(SUBR)pktablew, NULL}, + { "ptablew.aa", S(TABLEW),0, 5, "", "aaiooo", + (SUBR)itblchkw, NULL, (SUBR)ptablew}, + { "tableiw", S(TABL),TW, 1, "", "iiiooo", (SUBR)tablew_init, NULL, NULL}, + { "tablew.kk", S(TABL),TW, 3, "", "kkiooo",(SUBR)tabl_setup, + (SUBR)tablew_kontrol, NULL }, + { "tablew.aa", S(TABL),TW, 5, "", "aaiooo",(SUBR)tabl_setup, NULL, + (SUBR)tablew_audio }, + { "tablewkt.kk", S(TABL),TW,3, "", "kkkooo", + (SUBR)tablkt_setup,(SUBR)tablewkt_kontrol,NULL}, + { "tablewkt.aa", S(TABL),TW,5, "", "aakooo", + (SUBR)tablkt_setup,NULL,(SUBR)tablewkt_audio}, + { "tableng.i", S(TLEN),TR,1, "i", "i", (SUBR)table_length, NULL, NULL}, + { "tableng.k", S(TLEN),TR,2, "k", "k", NULL, (SUBR)table_length, NULL}, + { "tableigpw",S(TGP), TB, 1, "", "i", (SUBR)table_gpw, NULL, NULL}, + { "tablegpw", S(TGP), TB,2, "", "k", NULL, (SUBR)table_gpw, NULL}, + { "tableimix",S(TABLMIX),TB, 1, "", "iiiiiiiii", (SUBR)table_mix, NULL, NULL}, + { "tablemix", S(TABLMIX),TB, 2, "", "kkkkkkkkk", NULL, (SUBR)table_mix, NULL}, + { "tableicopy",S(TGP),TB, 1, "", "ii", (SUBR)table_copy, NULL, NULL}, + { "tablecopy", S(TGP),TB, 2, "", "kk", NULL, (SUBR)table_copy, NULL}, + { "tablera", S(TABLRA),TR, 5, "a", "kkk", + (SUBR)table_ra_set, NULL, (SUBR)table_ra}, + { "tablewa", S(TABLWA),TW, 5, "k", "kak", + (SUBR)table_wa_set, NULL, (SUBR)table_wa}, + { "tablekt", S(TABL),TR, 3, "k", "xkooo", (SUBR)tablkt_setup, + (SUBR)tablerkt_kontrol, + NULL }, + { "tablekt.a", S(TABL),TR, 5, "a", "xkooo", (SUBR)tablkt_setup, + NULL, + (SUBR)tablerkt_audio }, + { "tableikt", S(TABL),TR, 3, "k", "xkooo", (SUBR)tablkt_setup, + (SUBR)tableirkt_kontrol, + NULL }, + { "tableikt.a", S(TABL),TR, 5, "a", "xkooo", (SUBR)tablkt_setup, + NULL, + (SUBR)tableirkt_audio }, + { "table3kt", S(TABL),TR, 3, "k", "xkooo", (SUBR)tablkt_setup, + (SUBR)table3rkt_kontrol, + NULL }, + { "table3kt.a", S(TABL),TR, 5, "a", "xkooo", (SUBR)tablkt_setup, + NULL, + (SUBR)table3rkt_audio }, + { "zakinit", S(ZAKINIT), ZB, 1, "", "ii", (SUBR)zakinit, NULL, NULL }, + { "zir", S(ZKR),ZR, 1, "i", "i", (SUBR)zir, NULL, NULL }, + { "zkr", S(ZKR),ZR, 3, "k", "k", (SUBR)zkset, (SUBR)zkr, NULL}, + { "ziw", S(ZKW),ZW, 1, "", "ii", (SUBR)ziw, NULL, NULL }, + { "zkw", S(ZKW), ZW, 3, "", "kk", (SUBR)zkset, (SUBR)zkw, NULL}, + { "ziwm", S(ZKWM), ZB, 1, "", "iip", (SUBR)ziwm, NULL, NULL }, + { "zkwm", S(ZKWM), ZB, 3, "", "kkp", (SUBR)zkset, (SUBR)zkwm, NULL}, + { "zkmod", S(ZKMOD), ZB, 2, "k", "kk", NULL, (SUBR)zkmod, NULL }, + { "zkcl", S(ZKCL), ZW, 3, "", "kk", (SUBR)zkset, (SUBR)zkcl, NULL }, + { "zar", S(ZAR),ZR, 5, "a", "k", (SUBR)zaset, NULL, (SUBR)zar }, + { "zarg", S(ZARG), ZB, 5, "a", "kk", (SUBR)zaset, NULL, (SUBR)zarg }, + { "zaw", S(ZAW), ZW, 5, "", "ak", (SUBR)zaset, NULL, (SUBR)zaw }, + { "zawm", S(ZAWM), ZB, 5, "", "akp", (SUBR)zaset, NULL, (SUBR)zawm }, + { "zamod", S(ZAMOD), ZB, 4, "a", "ak", NULL, NULL, (SUBR)zamod}, + { "zacl", S(ZACL), ZW, 5, "", "kk", (SUBR)zaset, NULL, (SUBR)zacl}, + { "inz", S(IOZ), ZW, 4, "", "k", (SUBR)zaset, NULL, (SUBR)inz }, + { "outz", S(IOZ),ZR, 4, "", "k", (SUBR)zaset, NULL, (SUBR)outz }, + { "timek.i", S(RDTIME),0, 1, "i", "", (SUBR)timek, NULL, NULL }, + { "times.i", S(RDTIME),0, 1, "i", "", (SUBR)timesr, NULL, NULL }, + { "timek.k", S(RDTIME),0, 2, "k", "", NULL, (SUBR)timek, NULL }, + { "times.k", S(RDTIME),0, 2, "k", "", NULL, (SUBR)timesr,NULL }, + { "timeinstk", S(RDTIME),0, 3, "k", "", + (SUBR)instimset, (SUBR)instimek, NULL }, + { "timeinsts", S(RDTIME),0, 3, "k", "", + (SUBR)instimset, (SUBR)instimes, NULL }, + { "peak.k", S(PEAK),0, 2, "k", "k", NULL, (SUBR)peakk, NULL }, + { "peak.a", S(PEAK),0, 4, "k", "a", NULL, NULL, (SUBR)peaka }, + { "printk", S(PRINTK),WR, 3,"", "iko", + (SUBR)printkset, (SUBR)printk, NULL }, + { "printks",S(PRINTKS),WR, 3, "", "SiM", + (SUBR)printksset_S,(SUBR)printks, NULL }, + { "printks.i",S(PRINTKS),WR, 3, "", "iiM", + (SUBR)printksset,(SUBR)printks, NULL }, + { "prints",S(PRINTS),0, 1, "", "SM", (SUBR)printsset_S, NULL, NULL }, + { "prints.i",S(PRINTS),0, 1, "", "iM", (SUBR)printsset, NULL, NULL }, + { "printk2", S(PRINTK2), WR, 3, "", "ko", + (SUBR)printk2set, (SUBR)printk2, NULL }, + { "portk", S(KPORT),0, 3, "k", "kko", (SUBR)kporset, (SUBR)kport, NULL }, + { "tonek", S(KTONE),0, 3, "k", "kko", (SUBR)ktonset, (SUBR)ktone, NULL }, + { "atonek", S(KTONE),0, 3, "k", "kko", (SUBR)ktonset, (SUBR)katone, NULL}, + { "resonk", S(KRESON),0, 3, "k", "kkkpo",(SUBR)krsnset, (SUBR)kreson, NULL}, + { "aresonk",S(KRESON),0, 3, "k", "kkkpo",(SUBR)krsnset, (SUBR)kareson, NULL}, + { "limit.i", S(LIMIT),0, 1, "i", "iii", (SUBR)klimit, NULL, NULL }, + { "limit.k", S(LIMIT),0, 2, "k", "xkk", NULL, (SUBR)klimit, NULL }, + { "limit.a", S(LIMIT),0, 4, "a", "xkk", NULL, NULL, (SUBR)limit }, + { "prealloc", S(AOP),0, 1, "", "iio", (SUBR)prealloc, NULL, NULL }, + { "prealloc", S(AOP),0, 1, "", "Sio", (SUBR)prealloc_S, NULL, NULL }, + /* opcode dspace thread outarg inargs isub ksub asub */ + { "inh", S(INH),0, 4, "aaaaaa","", NULL, NULL, inh }, + { "ino", S(INO),0, 4, "aaaaaaaa","", NULL, NULL, ino }, + { "inx", S(INALL),0, 4, "aaaaaaaaaaaaaaaa","", NULL, NULL, in16 }, + { "in32", S(INALL),0, 4, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", + "", NULL, NULL, in32 }, + { "inch", S(INCH1),0, 4, "a", + "k", NULL, NULL, (SUBR) inch_opcode1 }, + { "inch.m", S(INCH),0, 4, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "z", NULL, NULL, inch_opcode }, + { "_in", S(INALL),0, 4, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "", NULL, NULL, inall_opcode }, /* Note that there is code in rdorch.c that assumes that opcodes starting - with the charcters out followed by a s, q, h, o or x are in this group + with the characters out followed by a s, q, h, o or x are in this group ***BEWARE*** CODE REMOVED 2011-Dec-14 - */ -/* { "outh", S(OUTH), 4, "", "aaaaaa",NULL, NULL, outh }, */ -/* { "outo", S(OUTO), 4, "", "aaaaaaaa",NULL,NULL, outo }, */ -/* { "outx", S(OUTX), 4, "", "aaaaaaaaaaaaaaaa",NULL,NULL, outx }, */ -/* { "out32", S(OUTX), 4, "", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", */ - /* NULL, NULL, outX }, */ -{ "outch", S(OUTCH), 4, "", "Z", NULL, NULL, outch }, -{ "outc", S(OUTX), 4, "", "y", NULL, NULL, outall }, -{ "cpsxpch", S(XENH),TR|1, "i", "iiii", cpsxpch, NULL, NULL }, -{ "cps2pch", S(XENH),TR|1, "i", "ii", cps2pch, NULL, NULL }, -{ "cpstun", S(CPSTUN), TR|2, "k", "kkk", NULL, cpstun }, -{ "cpstuni",S(CPSTUNI), TR|1, "i", "ii", cpstun_i, }, -{ "cpstmid", S(CPSTABLE), 1, "i", "i", (SUBR)cpstmid }, -{ "adsr", S(LINSEG), 7, "s", "iiiio",adsrset,klnseg, linseg }, -{ "madsr", S(LINSEG), 7, "s", "iiiioj", madsrset,klnsegr, linsegr }, -{ "xadsr", S(EXXPSEG), 7, "s", "iiiio", xdsrset, kxpseg, expseg }, -{ "mxadsr", S(EXPSEG), 7, "s", "iiiioj", mxdsrset, kxpsegr, expsegr }, -{ "schedule", S(SCHED), 1, "", "Tiim", schedule, schedwatch, NULL }, -{ "schedwhen", S(WSCHED),3, "", "kkkkm",ifschedule, kschedule, NULL }, -{ "schedkwhen", S(TRIGINSTR), 3,"", "kkkUkz",triginset, ktriginstr, NULL }, -{ "schedkwhennamed", S(TRIGINSTR), 3,"", "kkkUkz",triginset, ktriginstr, NULL }, -{ "trigseq", S(TRIGSEQ), 3, "", "kkkkkz", trigseq_set, trigseq, NULL }, -{ "event", S(LINEVENT), 2, "", "SUz", NULL, eventOpcode, NULL }, -{ "event_i", S(LINEVENT),1, "", "STm", eventOpcodeI, NULL, NULL }, -{ "lfo", S(LFO), 7, "s", "kko", lfoset, lfok, lfoa }, -{ "oscils", S(OSCILS), 5, "a", "iiio", - (SUBR)oscils_set, NULL, (SUBR)oscils }, -{ "lphasor", S(LPHASOR),5, "a", "xooooooo" , - (SUBR)lphasor_set, NULL, (SUBR)lphasor }, -{ "tablexkt", S(TABLEXKT),TR|5, "a", "xkkiooo", - (SUBR)tablexkt_set, NULL, (SUBR)tablexkt }, -{ "reverb2", S(NREV2), 5, "a", "akkoojoj", - (SUBR)reverbx_set,NULL,(SUBR)reverbx }, -{ "nreverb", S(NREV2), 5, "a", "akkoojoj", - (SUBR)reverbx_set,NULL,(SUBR) reverbx }, -{ "=.f", S(FASSIGN), 2, "f", "f", NULL, fassign, NULL }, -{ "init.f", S(FASSIGN), 2, "f", "f", fassign, NULL, NULL }, -{ "pvsanal", S(PVSANAL), 5, "f", "aiiiioo", pvsanalset, NULL, pvsanal }, -{ "pvsynth", S(PVSYNTH), 5, "a", "fo", pvsynthset, NULL, pvsynth }, -{ "pvsadsyn", S(PVADS), 7, "a", "fikopo", pvadsynset, pvadsyn, pvadsyn }, -{ "pvscross", S(PVSCROSS),3, "f", "ffkk", pvscrosset, pvscross, NULL }, -{ "pvsfread", S(PVSFREAD),3, "f", "kTo", pvsfreadset, pvsfread, NULL }, -{ "pvsmaska", S(PVSMASKA),3, "f", "fik", pvsmaskaset, pvsmaska, NULL }, -{ "pvsftw", S(PVSFTW), TW|3, "k", "fio", pvsftwset, pvsftw, NULL }, -{ "pvsftr", S(PVSFTR), TR|3, "", "fio", pvsftrset, pvsftr, NULL }, -{ "pvsinfo", S(PVSINFO), 1, "iiii","f", pvsinfo, NULL, NULL }, -{ "octave", 0xffff }, -{ "semitone", 0xffff }, -{ "cent", 0xffff }, -{ "octave.i", S(EVAL), 1, "i", "i", powoftwo }, -{ "octave.k", S(EVAL), 2, "k", "k", NULL, powoftwo }, -{ "octave.a", S(EVAL), 4, "a", "a", NULL, NULL, powoftwoa }, -{ "semitone.i",S(EVAL), 1, "i", "i", semitone }, -{ "semitone.k",S(EVAL), 2, "k", "k", NULL, semitone }, -{ "semitone.a",S(EVAL), 4, "a", "a", NULL, NULL, asemitone }, -{ "cent.i", S(EVAL), 1, "i", "i", cent }, -{ "cent.k", S(EVAL), 2, "k", "k", NULL, cent }, -{ "cent.a", S(EVAL), 4, "a", "a", NULL, NULL, acent }, -{ "db", 0xffff }, -{ "db.i", S(EVAL), 1, "i", "i", db }, -{ "db.k", S(EVAL), 2, "k", "k", NULL, db }, -{ "db.a", S(EVAL), 4, "a", "a", NULL, NULL, dba }, -{ "midichn", S(MIDICHN), 1, "i", "", midichn, NULL, NULL }, -{ "pgmassign",S(PGMASSIGN), 1, "", "iTo", pgmassign, NULL, NULL }, -{ "midiin", S(MIDIIN), 3, "kkkk", "", midiin_set, midiin, NULL }, -{ "pgmchn", S(PGMIN), 3, "kk", "o", pgmin_set, pgmin, NULL }, -{ "ctlchn", S(CTLIN), 3, "kkk", "oo", ctlin_set, ctlin, NULL }, -{ "miditempo", S(MIDITEMPO), 3, "k", "", - (SUBR) midiTempoOpcode, (SUBR) midiTempoOpcode, NULL }, -{ "midinoteoff", S(MIDINOTEON),3,"", "xx", midinoteoff, midinoteoff, }, -{ "midinoteonkey", S(MIDINOTEON),3, "", "xx", midinoteonkey, midinoteonkey }, -{ "midinoteoncps", S(MIDINOTEON), 3, "", "xx", midinoteoncps,midinoteoncps }, -{ "midinoteonoct", S(MIDINOTEON), 3, "", "xx", midinoteonoct,midinoteonoct }, -{ "midinoteonpch", S(MIDINOTEON), 3, "", "xx", midinoteonpch, midinoteonpch }, -{ "midipolyaftertouch", S(MIDIPOLYAFTERTOUCH), - 3, "", "xxoh", midipolyaftertouch, midipolyaftertouch}, -{ "midicontrolchange", S(MIDICONTROLCHANGE), - 3, "", "xxoh",midicontrolchange, midicontrolchange }, -{ "midiprogramchange", S(MIDIPROGRAMCHANGE), - 3, "", "x", midiprogramchange, midiprogramchange }, -{ "midichannelaftertouch", S(MIDICHANNELAFTERTOUCH), - 3, "", "xoh",midichannelaftertouch, midichannelaftertouch }, -{ "midipitchbend", S(MIDIPITCHBEND),3, "", "xoh", midipitchbend, midipitchbend }, -{ "mididefault", S(MIDIDEFAULT), 3, "", "xx", mididefault, mididefault }, -{ "invalue", 0xFFFF, CR, NULL, NULL, NULL, NULL, NULL }, -{ "invalue.k", S(INVAL), 3, "k", "T", invalset, kinval, NULL }, -{ "invalue.S", S(INVAL), 3, "S", "T", invalset_S, kinval_S, NULL }, -{ "outvalue", S(OUTVAL), CW|3, "", "TU", outvalset, koutval, NULL }, -/* IV - Oct 20 2002 */ -{ "subinstr", S(SUBINST), 5, "mmmmmmmm", "Tm", subinstrset, NULL, subinstr }, -{ "subinstrinit", S(SUBINST), 1, "", "Tm", subinstrset, NULL, NULL }, -{ "nstrnum", S(NSTRNUM), 1, "i", "T", nstrnumset, NULL, NULL }, -{ "turnoff2", 0xFFFB, CW, NULL, NULL, NULL, NULL, NULL }, -{ "turnoff2.S",S(TURNOFF2),2, "", "Skk", NULL, turnoff2S, NULL }, -{ "turnoff2.c",S(TURNOFF2),2, "", "ikk", NULL, turnoff2k, NULL }, -{ "turnoff2.k",S(TURNOFF2),2, "", "kkk", NULL, turnoff2k, NULL }, -{ "turnoff2.i",S(TURNOFF2),2, "", "ikk", NULL, turnoff2k, NULL }, -{ "turnoff2.r",S(TURNOFF2),2, "", "ikk", NULL, turnoff2k, NULL }, -{ "cngoto", S(CGOTO), 3, "", "Bl", ingoto, kngoto, NULL }, -#ifdef VARGA -{ "cogoto", S(CGOTO), 3, "", "bl", iingoto, kingoto, NULL }, -#endif -/* IV - Sep 8 2002 - added entries for user defined opcodes, xin, xout */ -/* and setksmps */ -{ ".userOpcode", S(UOPCODE), 7, "", "", useropcdset, useropcd, useropcd }, -/* IV - Sep 10 2002: removed perf time routines of xin and xout */ -{ "xin", S(XIN_LOW), 1, "NNNNNNNNNNNNNNNN", "", xinset, NULL, NULL }, -{ ".xin64", S(XIN_HIGH), 1, - "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "", - xinset, NULL, NULL }, -{ ".xin256", S(XIN_MAX), 1, - "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" - "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" - "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" - "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "", - xinset, NULL, NULL }, -{ "xout", S(XOUT_LOW), 1, "", "N", xoutset, NULL, NULL }, -{ ".xout64", S(XOUT_HIGH), 1, "", "N", xoutset, NULL, NULL }, -{ ".xout256", S(XOUT_MAX), 1, "", "N", xoutset, NULL, NULL }, -{ "setksmps", S(SETKSMPS), 1, "", "i", setksmpsset, NULL, NULL }, -{ "tempoval", S(GTEMPO), 2, "k", "", NULL, (SUBR)gettempo, NULL }, -{ "downsamp",S(DOWNSAMP),3, "k", "ao", (SUBR)downset,(SUBR)downsamp }, -{ "upsamp", S(UPSAMP), 4, "a", "k", NULL, NULL, (SUBR)upsamp }, -/* IV - Sep 5 2002 */ -{ "interp", S(INTERP), 5, "a", "koo", (SUBR)interpset,NULL, (SUBR)interp }, -{ "a.k", S(INTERP), 5, "a", "k", (SUBR)a_k_set,NULL, (SUBR)interp }, -{ "integ", S(INDIFF), 7, "s", "xo", (SUBR)indfset,(SUBR)kntegrate,(SUBR)integrate}, -{ "diff", S(INDIFF), 7, "s", "xo", (SUBR)indfset,(SUBR)kdiff, (SUBR)diff }, -{ "samphold",S(SAMPHOLD),7, "s", "xxoo", - (SUBR)samphset,(SUBR)ksmphold,(SUBR)samphold}, -{ "delay", S(DELAY), 5, "a", "aio", (SUBR)delset, NULL, (SUBR)delay }, -{ "delayr", S(DELAYR), 5, "aX","io", (SUBR)delrset,NULL, (SUBR)delayr }, -{ "delayw", S(DELAYW), 5, "", "a", (SUBR)delwset,NULL, (SUBR)delayw }, -{ "delay1", S(DELAY1), 5, "a", "ao", (SUBR)del1set,NULL, (SUBR)delay1 }, -{ "deltap", S(DELTAP), 5, "a", "ko", (SUBR)tapset, NULL, (SUBR)deltap }, -{ "deltapi",S(DELTAP), 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltapi }, -{ "deltapn",S(DELTAP), 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltapn }, -{ "deltap3",S(DELTAP), 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltap3 }, -{ "reverb", S(REVERB), 5, "a", "ako", (SUBR)rvbset, NULL, (SUBR)reverb }, -{ "vdelay", S(VDEL), 5, "a", "axio", (SUBR)vdelset, NULL, (SUBR)vdelay }, -{ "vdelay3", S(VDEL), 5, "a", "axio", (SUBR)vdelset, NULL, (SUBR)vdelay3 }, -{ "vdelayxwq",S(VDELXQ),5, "aaaa", "aaaaaiio", - (SUBR)vdelxqset, NULL, (SUBR)vdelayxwq}, -{ "vdelayxws",S(VDELXS),5, "aa", "aaaiio", (SUBR)vdelxsset, NULL, (SUBR)vdelayxws}, -{ "vdelayxw", S(VDELX), 5, "a", "aaiio", (SUBR)vdelxset, NULL, (SUBR)vdelayxw}, -{ "vdelayxq", S(VDELXQ),5, "aaaa", "aaaaaiio", - (SUBR)vdelxqset, NULL, (SUBR)vdelayxq}, -{ "vdelayxs", S(VDELXS),5, "aa", "aaaiio", (SUBR)vdelxsset, NULL, (SUBR)vdelayxs}, -{ "vdelayx", S(VDELX), 5, "a", "aaiio", (SUBR)vdelxset, NULL, (SUBR)vdelayx}, -{ "deltapx", S(DELTAPX),5, "a", "aio", (SUBR)tapxset, NULL, (SUBR)deltapx }, -{ "deltapxw", S(DELTAPX),5, "", "aaio", (SUBR)tapxset, NULL, (SUBR)deltapxw }, -{ "multitap", S(MDEL), 5, "a", "am", - (SUBR)multitap_set,NULL,(SUBR)multitap_play}, -{ "comb", S(COMB), 5, "a", "akioo", (SUBR)cmbset,NULL, (SUBR)comb }, -{ "alpass", S(COMB), 5, "a", "akioo", (SUBR)cmbset,NULL, (SUBR)alpass }, -{ "strset", S(STRSET_OP), 1, "", "iS", - (SUBR) strset_init, (SUBR) NULL, (SUBR) NULL }, -{ "strget", S(STRGET_OP), 1, "S", "i", - (SUBR) strget_init, (SUBR) NULL, (SUBR) NULL }, -{ "strcpy", S(STRCPY_OP), 1, "S", "T", - (SUBR) strcpy_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strcpyk", S(STRCPY_OP), 3, "S", "T", - (SUBR) strcpy_opcode, (SUBR) strcpy_opcode, (SUBR) NULL }, -{ "strcat", S(STRCAT_OP), 1, "S", "SS", - (SUBR) strcat_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strcatk", S(STRCAT_OP), 3, "S", "SS", - (SUBR) strcat_opcode, (SUBR) strcat_opcode, (SUBR) NULL }, -{ "strcmp", S(STRCAT_OP), 1, "i", "SS", - (SUBR) strcmp_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strcmpk", S(STRCAT_OP), 3, "k", "SS", - (SUBR) strcmp_opcode, (SUBR) strcmp_opcode, (SUBR) NULL }, -{ "sprintf", S(SPRINTF_OP), 1, "S", "STN", - (SUBR) sprintf_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "sprintfk", S(SPRINTF_OP), 3, "S", "SUN", - (SUBR) sprintf_opcode, (SUBR) sprintf_opcode, (SUBR) NULL }, -{ "printf_i", S(PRINTF_OP), 1, "", "SiTN", - (SUBR) printf_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "printf", S(PRINTF_OP), 3, "", "SkUN", - (SUBR) printf_opcode_set, (SUBR) printf_opcode_perf, (SUBR) NULL }, -{ "puts", S(PUTS_OP), 3, "", "Sko", - (SUBR) puts_opcode_init, (SUBR) puts_opcode_perf, (SUBR) NULL }, -{ "strtod", S(STRSET_OP), 1, "i", "T", - (SUBR) strtod_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strtodk", S(STRSET_OP), 3, "k", "U", - (SUBR) strtod_opcode, (SUBR) strtod_opcode, (SUBR) NULL }, -{ "strtol", S(STRSET_OP), 1, "i", "T", - (SUBR) strtol_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strtolk", S(STRSET_OP), 3, "k", "U", - (SUBR) strtol_opcode, (SUBR) strtol_opcode, (SUBR) NULL }, -{ "strsub", S(STRSUB_OP), 1, "S", "Soj", - (SUBR) strsub_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strsubk", S(STRSUB_OP), 3, "S", "Skk", - (SUBR) strsub_opcode, (SUBR) strsub_opcode, (SUBR) NULL }, -{ "strchar", S(STRCHAR_OP), 1, "i", "So", - (SUBR) strchar_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strchark", S(STRCHAR_OP), 3, "k", "SO", - (SUBR) strchar_opcode, (SUBR) strchar_opcode, (SUBR) NULL }, -{ "strlen", S(STRLEN_OP), 1, "i", "S", - (SUBR) strlen_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strlenk", S(STRLEN_OP), 3, "k", "S", - (SUBR) strlen_opcode, (SUBR) strlen_opcode, (SUBR) NULL }, -{ "strupper", S(STRUPPER_OP), 1, "S", "S", - (SUBR) strupper_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strupperk", S(STRUPPER_OP), 3, "S", "S", - (SUBR) strupper_opcode, (SUBR) strupper_opcode, (SUBR) NULL }, -{ "strlower", S(STRUPPER_OP), 1, "S", "S", - (SUBR) strlower_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strlowerk", S(STRUPPER_OP), 3, "S", "S", - (SUBR) strlower_opcode, (SUBR) strlower_opcode, (SUBR) NULL }, -{ "getcfg", S(GETCFG_OP), 1, "S", "i", - (SUBR) getcfg_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strindex", S(STRINDEX_OP), 1, "i", "SS", - (SUBR) strindex_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strindexk", S(STRINDEX_OP), 3, "k", "SS", - (SUBR) strindex_opcode, (SUBR) strindex_opcode, (SUBR) NULL }, -{ "strrindex", S(STRINDEX_OP), 1, "i", "SS", - (SUBR) strrindex_opcode, (SUBR) NULL, (SUBR) NULL }, -{ "strrindexk", S(STRINDEX_OP), 3, "k", "SS", - (SUBR) strrindex_opcode, (SUBR) strrindex_opcode, (SUBR) NULL }, -{ "loop_lt", 0xfffb }, -{ "loop_le", 0xfffb }, -{ "loop_gt", 0xfffb }, -{ "loop_ge", 0xfffb }, -{ "loop_lt.i", S(LOOP_OPS), 1, "", "iiil", (SUBR) loop_l_i, NULL, NULL }, -{ "loop_le.i", S(LOOP_OPS), 1, "", "iiil", (SUBR) loop_le_i, NULL, NULL }, -{ "loop_gt.i", S(LOOP_OPS), 1, "", "iiil", (SUBR) loop_g_i, NULL, NULL }, -{ "loop_ge.i", S(LOOP_OPS), 1, "", "iiil", (SUBR) loop_ge_i, NULL, NULL }, -{ "loop_lt.k", S(LOOP_OPS), 2, "", "kkkl", NULL, (SUBR) loop_l_p, NULL }, -{ "loop_le.k", S(LOOP_OPS), 2, "", "kkkl", NULL, (SUBR) loop_le_p, NULL }, -{ "loop_gt.k", S(LOOP_OPS), 2, "", "kkkl", NULL, (SUBR) loop_g_p, NULL }, -{ "loop_ge.k", S(LOOP_OPS), 2, "", "kkkl", NULL, (SUBR) loop_ge_p, NULL }, -{ "chnget", 0xFFFF, CR }, -{ "chnget.i", S(CHNGET), 1, "i", "S", - (SUBR) chnget_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, -{ "chnget.k", S(CHNGET), 3, "k", "S", - (SUBR) chnget_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, -{ "chnget.a", S(CHNGET), 5, "a", "S", - (SUBR) chnget_opcode_init_a, (SUBR) NULL, (SUBR) notinit_opcode_stub }, -{ "chnget.S", S(CHNGET), 1, "S", "S", - (SUBR) chnget_opcode_init_S, (SUBR) NULL, (SUBR) NULL }, -{ "chnset", 0xFFFB, CW }, -{ "chnset.i", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, -{ "chnset.r", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, -{ "chnset.c", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, -{ "chnset.k", S(CHNGET), 3, "", "kS", - (SUBR) chnset_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, -{ "chnset.a", S(CHNGET), 5, "", "aS", - (SUBR) chnset_opcode_init_a, (SUBR) NULL, (SUBR) notinit_opcode_stub }, -{ "chnset.S", S(CHNGET), 1, "", "SS", - (SUBR) chnset_opcode_init_S, (SUBR) NULL, (SUBR) NULL }, -{ "chnmix", S(CHNGET), CB|5, "", "aS", - (SUBR) chnmix_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, -{ "chnclear", S(CHNCLEAR), CW|5, "", "S", - (SUBR) chnclear_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, -{ "chn_k", S(CHN_OPCODE_K), CW|1, "", "Sioooo", - (SUBR) chn_k_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chn_a", S(CHN_OPCODE), CW|1, "", "Si", - (SUBR) chn_a_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chn_S", S(CHN_OPCODE), CW|1, "", "Si", - (SUBR) chn_S_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnexport", 0xFFFF, 0, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, -{ "chnexport.i", S(CHNEXPORT_OPCODE), 1, "i", "Sioooo", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnexport.k", S(CHNEXPORT_OPCODE), 1, "k", "Sioooo", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnexport.a", S(CHNEXPORT_OPCODE), 1, "a", "Si", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnexport.S", S(CHNEXPORT_OPCODE), 1, "S", "Si", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnparams", S(CHNPARAMS_OPCODE), CR|1, "iiiiii", "S", - (SUBR) chnparams_opcode_init, (SUBR) NULL, (SUBR) NULL }, -{ "chnrecv", S(CHNSEND), CR|3, "", "So", - (SUBR) chnrecv_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, -{ "chnsend", S(CHNSEND), 3, "", "So", - (SUBR) chnsend_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, -{ "chano", 0xFFFD, CW, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, -{ "chano.k", S(ASSIGN), 2, "", "kk", - (SUBR) NULL, (SUBR) chano_opcode_perf_k, (SUBR) NULL }, -{ "chano.a", S(ASSIGN), 4, "", "ak", - (SUBR) NULL, (SUBR) NULL, (SUBR) chano_opcode_perf_a }, -{ "pvsout", S(FCHAN), 2, "", "fk", - (SUBR) NULL, (SUBR) pvsout_perf, (SUBR) NULL }, -{ "chani", 0xFFFF, CR, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, -{ "chani.k", S(ASSIGN), 2, "k", "k", - (SUBR) NULL, (SUBR) chani_opcode_perf_k, (SUBR) NULL }, -{ "chani.a", S(ASSIGN), 4, "a", "k", - (SUBR) NULL, (SUBR) NULL, (SUBR) chani_opcode_perf_a }, -{ "pvsin", S(FCHAN), 3, "f", "kooopo", - (SUBR) pvsin_init, (SUBR) pvsin_perf, (SUBR) NULL }, -{ "sense", S(KSENSE), 2, "kz", "", - (SUBR) NULL, (SUBR) sensekey_perf, (SUBR) NULL }, -{ "sensekey", S(KSENSE), 2, "kz", "", - (SUBR) NULL, (SUBR) sensekey_perf, (SUBR) NULL }, -{ "remove", S(DELETEIN), 1, "", "T", - (SUBR) delete_instr, (SUBR) NULL, (SUBR) NULL }, -#ifdef PARCS -{ "##globallock", S(GLOBAL_LOCK_UNLOCK), 3, "", "k", - globallock, globallock, NULL}, -{ "##globalunlock", S(GLOBAL_LOCK_UNLOCK), 3, "", "k", - globalunlock, globalunlock, NULL}, + */ + { "outch", S(OUTCH),0, 4, "", "Z", NULL, NULL, outch }, + { "outc", S(OUTX),0, 4, "", "y", NULL, NULL, outall }, + { "cpsxpch", S(XENH),TR, 1, "i", "iiii", cpsxpch, NULL, NULL }, + { "cps2pch", S(XENH),TR, 1, "i", "ii", cps2pch, NULL, NULL }, + { "cpstun", S(CPSTUN), TR, 2, "k", "kkk", NULL, cpstun }, + { "cpstuni",S(CPSTUNI), TR, 1, "i", "ii", cpstun_i, }, + { "cpstmid", S(CPSTABLE),0, 1, "i", "i", (SUBR)cpstmid }, + { "adsr", S(LINSEG),0, 3, "k", "iiiio",adsrset,klnseg, NULL }, + { "adsr.a", S(LINSEG),0, 5, "a", "iiiio",adsrset,NULL, linseg }, + { "madsr", S(LINSEG),0, 3, "k", "iiiioj", madsrset,klnsegr,NULL }, + { "madsr.a", S(LINSEG),0, 5, "s", "iiiioj", madsrset,NULL, linsegr }, + { "xadsr", S(EXXPSEG),0, 3, "k", "iiiio", xdsrset, kxpseg, NULL }, + { "xadsr.a", S(EXXPSEG),0, 5, "a", "iiiio", xdsrset, NULL, expseg }, + { "mxadsr", S(EXPSEG),0, 3, "k", "iiiioj", mxdsrset, kxpsegr, NULL}, + { "mxadsr.a", S(EXPSEG),0, 5, "a", "iiiioj", mxdsrset, NULL, expsegr}, + { "schedule", S(SCHED),0, 1, "", "iiim", + schedule, NULL, NULL }, + { "schedule.S", S(SCHED),0, 1, "", "Siim", + schedule_S, NULL, NULL }, + { "schedwhen", S(WSCHED),0,3, "", "kkkkm",ifschedule, kschedule, NULL }, + { "schedwhen", S(WSCHED),0,3, "", "kSkkm",ifschedule, kschedule, NULL }, + { "schedkwhen", S(TRIGINSTR),0, 3,"", "kkkkkz",triginset, ktriginstr, NULL }, + { "schedkwhen.S", S(TRIGINSTR),0, 3,"", "kkkSkz", + triginset_S, ktriginstr_S, NULL }, + { "schedkwhennamed", S(TRIGINSTR),0, 3,"", "kkkkkz",triginset, ktriginstr, NULL }, + { "schedkwhennamed.S", S(TRIGINSTR),0, 3,"", + "kkkSkz",triginset_S, ktriginstr_S, NULL }, + { "trigseq", S(TRIGSEQ),0, 3, "", "kkkkkz", trigseq_set, trigseq, NULL }, + { "event", S(LINEVENT),0, 2, "", "Skz", NULL, eventOpcode, NULL }, + { "event_i", S(LINEVENT),0,1, "", "Sim", eventOpcodeI, NULL, NULL }, + { "event.S", S(LINEVENT),0, 2, "", "SSz", NULL, eventOpcode_S, NULL }, + { "event_i.S", S(LINEVENT),0,1, "", "SSm", eventOpcodeI_S, NULL, NULL }, + { "instance", S(LINEVENT2),0,2, "k", "kkz", NULL, instanceOpcode, NULL }, + { "instance.i", S(LINEVENT2),0,1, "i", "iiim", instanceOpcode, NULL, NULL }, + { "instance.kS", S(LINEVENT2),0, 2, "k", "SSz", NULL, instanceOpcode_S, NULL }, + { "instance.S", S(LINEVENT2),0, 1, "i", "Siim", instanceOpcode_S, NULL, NULL}, + { "kill", S(KILLOP),0,1, "", "i", kill_instance, NULL, NULL }, + { "kill.k", S(KILLOP),0,2, "", "k", NULL, kill_instance, NULL}, + { "lfo", S(LFO),0, 3, "k", "kko", lfoset, lfok, NULL }, + { "lfo.a", S(LFO),0, 5, "a", "kko", lfoset, NULL, lfoa }, + { "oscils", S(OSCILS),0, 5, "a", "iiio", + (SUBR)oscils_set, NULL, (SUBR)oscils }, + { "lphasor", S(LPHASOR),0,5, "a", "xooooooo" , + (SUBR)lphasor_set, NULL, (SUBR)lphasor }, + { "tablexkt", S(TABLEXKT),TR, 5, "a", "xkkiooo", (SUBR)tablexkt_set, NULL, + (SUBR)tablexkt }, + { "reverb2", S(NREV2),0, 5, "a", "akkoojoj", + (SUBR)reverbx_set,NULL,(SUBR)reverbx }, + { "nreverb", S(NREV2),0, 5, "a", "akkoojoj", + (SUBR)reverbx_set,NULL,(SUBR) reverbx }, + { "=.f", S(FASSIGN),0, 3, "f", "f", + (SUBR)fassign_set, (SUBR)fassign }, + { "init.f", S(FASSIGN),0, 1, "f", "f", + (SUBR)fassign_set, NULL, NULL }, + { "pvsanal", S(PVSANAL), 0, 5, "f", "aiiiioo", + pvsanalset, NULL, pvsanal }, + { "pvsynth", S(PVSYNTH),0, 5, "a", "fo", pvsynthset, NULL, pvsynth }, + { "pvsadsyn", S(PVADS),0, 7, "a", "fikopo", pvadsynset, pvadsyn, pvadsyn}, + { "pvscross", S(PVSCROSS),0,3, "f", "ffkk", pvscrosset, pvscross, NULL }, + { "pvsfread", S(PVSFREAD),0,3, "f", "kSo", pvsfreadset_S, pvsfread, NULL}, + { "pvsfread.i", S(PVSFREAD),0,3, "f", "kio", pvsfreadset, pvsfread, NULL}, + { "pvsmaska", S(PVSMASKA),0,3, "f", "fik", pvsmaskaset, pvsmaska, NULL }, + { "pvsftw", S(PVSFTW), TW, 3, "k", "fio", pvsftwset, pvsftw, NULL }, + { "pvsftr", S(PVSFTR),TR, 3, "", "fio", pvsftrset, pvsftr, NULL }, + { "pvsinfo", S(PVSINFO),0, 1, "iiii","f", pvsinfo, NULL, NULL }, + { "octave", 0xffff }, + { "semitone", 0xffff }, + { "cent", 0xffff }, + { "octave.i", S(EVAL),0, 1, "i", "i", powoftwo }, + { "octave.k", S(EVAL),0, 2, "k", "k", NULL, powoftwo }, + { "octave.a", S(EVAL),0, 4, "a", "a", NULL, NULL, powoftwoa }, + { "semitone.i",S(EVAL),0, 1, "i", "i", semitone }, + { "semitone.k",S(EVAL),0, 2, "k", "k", NULL, semitone }, + { "semitone.a",S(EVAL),0, 4, "a", "a", NULL, NULL, asemitone }, + { "cent.i", S(EVAL),0, 1, "i", "i", cent }, + { "cent.k", S(EVAL),0, 2, "k", "k", NULL, cent }, + { "cent.a", S(EVAL),0, 4, "a", "a", NULL, NULL, acent }, + { "db", 0xffff }, + { "db.i", S(EVAL),0, 1, "i", "i", db }, + { "db.k", S(EVAL),0, 2, "k", "k", NULL, db }, + { "db.a", S(EVAL),0, 4, "a", "a", NULL, NULL, dba }, + { "midichn", S(MIDICHN),0, 1, "i", "", midichn, NULL, NULL }, + { "pgmassign",S(PGMASSIGN),0, 1, "", "iio", pgmassign, NULL, NULL }, + { "pgmassign.S",S(PGMASSIGN),0, 1, "", "iSo", pgmassign_S, NULL, NULL }, + { "midiin", S(MIDIIN),0, 3, "kkkk", "", midiin_set, midiin, NULL }, + { "pgmchn", S(PGMIN),0, 3, "kk", "o", pgmin_set, pgmin, NULL }, + { "ctlchn", S(CTLIN),0, 3, "kkk", "oo", ctlin_set, ctlin, NULL }, + { "miditempo", S(MIDITEMPO),0, 3, "k", "", + (SUBR) midiTempoOpcode, (SUBR) midiTempoOpcode, NULL }, + { "midifilestatus", S(MIDITEMPO),0, 2, "k", "", + NULL, (SUBR) midiFileStatus, NULL }, + { "midinoteoff", S(MIDINOTEON),0,3,"", "xx", midinoteoff, midinoteoff, }, + { "midinoteonkey", S(MIDINOTEON),0,3, "", "xx", midinoteonkey, midinoteonkey }, + { "midinoteoncps", S(MIDINOTEON),0, 3, "", "xx", midinoteoncps,midinoteoncps }, + { "midinoteonoct", S(MIDINOTEON),0, 3, "", "xx", midinoteonoct,midinoteonoct }, + { "midinoteonpch", S(MIDINOTEON),0, 3, "", "xx", midinoteonpch, midinoteonpch }, + { "midipolyaftertouch", S(MIDIPOLYAFTERTOUCH),0, + 3, "", "xxoh", midipolyaftertouch, midipolyaftertouch}, + { "midicontrolchange", S(MIDICONTROLCHANGE),0, + 3, "", "xxoh",midicontrolchange, midicontrolchange }, + { "midiprogramchange", S(MIDIPROGRAMCHANGE),0, + 3, "", "x", midiprogramchange, midiprogramchange }, + { "midichannelaftertouch", S(MIDICHANNELAFTERTOUCH),0, + 3, "", "xoh",midichannelaftertouch, midichannelaftertouch }, + { "midipitchbend", S(MIDIPITCHBEND),0,3, "", "xoh", + midipitchbend, midipitchbend }, + { "mididefault", S(MIDIDEFAULT),0, 3, "", "xx", mididefault, mididefault }, + { "invalue", 0xFFFF, CR, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL }, + { "invalue.k", S(INVAL),0, 3, "k", "i", (SUBR) invalset,(SUBR) kinval, NULL }, + { "invalue.kS", S(INVAL),0, 3, "k", "S", (SUBR) invalset_S,(SUBR) kinval, NULL }, + { "invalue.S", S(INVAL),0, 3, "S", "i", + (SUBR) invalset_string, (SUBR) kinvalS, NULL }, + { "invalue.SS", S(INVAL),0, 3, "S", "S", + (SUBR) invalset_string_S, (SUBR) kinvalS, NULL }, + { "outvalue", S(OUTVAL), CW, 3, "", "ik", (SUBR) outvalset, (SUBR) koutval, NULL}, + { "outvalue.k", S(OUTVAL), CW, 3, "", "Sk", + (SUBR) outvalset_S, (SUBR) koutval, NULL}, + { "outvalue.S", S(OUTVAL), CW, 3, "", "iS", + (SUBR) outvalset_string, (SUBR) koutvalS, NULL}, + { "outvalue.SS", S(OUTVAL), CW, 3, "", "SS", + (SUBR) outvalset_string_S, (SUBR) koutvalS, NULL}, + /* IV - Oct 20 2002 */ + { "subinstr", S(SUBINST),0, 5, "mmmmmmmm", "Sm", subinstrset_S, NULL, subinstr }, + { "subinstrinit", S(SUBINST),0, 1, "", "Sm", subinstrset_S, NULL, NULL }, + { "subinstr.i", S(SUBINST),0, 5, "mmmmmmmm", "im", subinstrset, NULL, subinstr }, + { "subinstrinit.i", S(SUBINST),0, 1, "", "im", subinstrset, NULL, NULL }, + { "nstrnum", S(NSTRNUM),0, 1, "i", "S", nstrnumset_S, NULL, NULL }, + { "nstrnum.i", S(NSTRNUM),0, 1, "i", "i", nstrnumset, NULL, NULL }, + { "turnoff2", 0xFFFB, CW, 0, NULL, NULL, NULL, NULL, NULL }, + { "turnoff2.S",S(TURNOFF2),0,2, "", "Skk", NULL, turnoff2S, NULL }, + { "turnoff2.c",S(TURNOFF2),0,2, "", "ikk", NULL, turnoff2k, NULL }, + { "turnoff2.k",S(TURNOFF2),0,2, "", "kkk", NULL, turnoff2k, NULL }, + { "turnoff2.i",S(TURNOFF2),0,2, "", "ikk", NULL, turnoff2k, NULL }, + { "turnoff2.r",S(TURNOFF2),0,2, "", "ikk", NULL, turnoff2k, NULL }, + { "cngoto", S(CGOTO),0, 3, "", "Bl", ingoto, kngoto, NULL }, + { "cingoto", S(CGOTO),0, 1, "", "Bl", ingoto, NULL, NULL }, + { "tempoval", S(GTEMPO),0, 2, "k", "", NULL, (SUBR)gettempo, NULL }, + { "downsamp",S(DOWNSAMP),0,3, "k", "ao", (SUBR)downset,(SUBR)downsamp }, + { "upsamp", S(UPSAMP),0, 4, "a", "k", NULL, NULL, (SUBR)upsamp }, + /* IV - Sep 5 2002 */ + { "interp", S(INTERP),0, 5, "a", "koo", (SUBR)interpset,NULL, (SUBR)interp }, + { "a.k", S(INTERP),0, 5, "a", "k", (SUBR)a_k_set,NULL, (SUBR)interp }, + { "integ", S(INDIFF), 0, 5, "a", "xo", + (SUBR)indfset,NULL,(SUBR)integrate}, + { "integ.k", S(INDIFF), 0, 3, "k", "xo", + (SUBR)indfset,(SUBR)kntegrate, NULL}, + { "diff", S(INDIFF),0, 5, "a", "xo", (SUBR)indfset,NULL, (SUBR)diff }, + { "diff.k", S(INDIFF),0, 3, "k", "xo", (SUBR)indfset,(SUBR)kdiff, NULL }, + { "samphold",S(SAMPHOLD),0,5, "a", "xxoo", + (SUBR)samphset,NULL,(SUBR)samphold }, + { "samphold.k",S(SAMPHOLD),0,3, "k", "xxoo", + (SUBR)samphset,(SUBR)ksmphold,NULL }, + { "delay", S(DELAY),0, 5, "a", "aio", (SUBR)delset, NULL, (SUBR)delay }, + { "delayr", S(DELAYR),0, 5, "aX","io", (SUBR)delrset,NULL, (SUBR)delayr }, + { "delayw", S(DELAYW),0, 5, "", "a", (SUBR)delwset,NULL, (SUBR)delayw }, + { "delay1", S(DELAY1),0, 5, "a", "ao", (SUBR)del1set,NULL, (SUBR)delay1 }, + { "deltap", S(DELTAP),0, 5, "a", "ko", (SUBR)tapset, NULL, (SUBR)deltap }, + { "deltapi",S(DELTAP),0, 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltapi }, + { "deltapn",S(DELTAP),0, 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltapn }, + { "deltap3",S(DELTAP),0, 5, "a", "xo", (SUBR)tapset, NULL, (SUBR)deltap3 }, + { "reverb", S(REVERB),0, 5, "a", "ako", (SUBR)rvbset, NULL, (SUBR)reverb }, + { "vdelay", S(VDEL),0, 5, "a", "axio", (SUBR)vdelset, NULL, (SUBR)vdelay }, + { "vdelay3", S(VDEL),0, 5, "a", "axio", (SUBR)vdelset, NULL, (SUBR)vdelay3 }, + { "vdelayxwq",S(VDELXQ),0,5, "aaaa", "aaaaaiio", + (SUBR)vdelxqset, NULL, (SUBR)vdelayxwq}, + { "vdelayxws",S(VDELXS),0,5, "aa", "aaaiio", (SUBR)vdelxsset, NULL, + (SUBR)vdelayxws }, + { "vdelayxw", S(VDELX),0, 5, "a", "aaiio", + (SUBR)vdelxset, NULL, (SUBR)vdelayxw}, + { "vdelayxq", S(VDELXQ),0,5, "aaaa", "aaaaaiio", + (SUBR)vdelxqset, NULL, (SUBR)vdelayxq}, + { "vdelayxs", S(VDELXS),0,5, "aa", "aaaiio", + (SUBR)vdelxsset, NULL, (SUBR)vdelayxs}, + { "vdelayx", S(VDELX),0, 5, "a", "aaiio", (SUBR)vdelxset, NULL, (SUBR)vdelayx}, + { "deltapx", S(DELTAPX),0,5, "a", "aio", (SUBR)tapxset, NULL, (SUBR)deltapx }, + { "deltapxw", S(DELTAPX),0,5, "", "aaio", (SUBR)tapxset, NULL, (SUBR)deltapxw }, + { "multitap", S(MDEL),0, 5, "a", "am", + (SUBR)multitap_set,NULL,(SUBR)multitap_play}, + { "comb", S(COMB),0, 5, "a", "akioo", (SUBR)cmbset,NULL, (SUBR)comb }, + { "combinv",S(COMB),0, 5, "a", "akioo", (SUBR)cmbset,NULL, (SUBR)invcomb }, + { "alpass", S(COMB),0, 5, "a", "axioo", (SUBR)cmbset,NULL, (SUBR)alpass }, + { "strset", S(STRSET_OP),0, 1, "", "iS", + (SUBR) strset_init, (SUBR) NULL, (SUBR) NULL }, + { "strget", S(STRGET_OP),0, 1, "S", "i", + (SUBR) strget_init, (SUBR) NULL, (SUBR) NULL }, + { "strcpy", S(STRCPY_OP),0, 1, "S", "S", + (SUBR) strcpy_opcode_S, (SUBR) NULL, (SUBR) NULL }, + { "strcpy", S(STRGET_OP),0, 1, "S", "i", + (SUBR) strcpy_opcode_p, (SUBR) NULL, (SUBR) NULL }, + { "strcpyk", S(STRCPY_OP),0, 3, "S", "S", + (SUBR) strcpy_opcode_S, (SUBR) strcpy_opcode_S, (SUBR) NULL }, + { "strcpyk.k", S(STRGET_OP),0, 3, "S", "k", + (SUBR) strcpy_opcode_p, (SUBR) strcpy_opcode_p, (SUBR) NULL }, + { "strcat", S(STRCAT_OP),0, 1, "S", "SS", + (SUBR) strcat_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strcatk", S(STRCAT_OP),0, 3, "S", "SS", + (SUBR) strcat_opcode, (SUBR) strcat_opcode, (SUBR) NULL }, + { "strcmp", S(STRCMP_OP),0, 1, "i", "SS", + (SUBR) strcmp_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strcmpk", S(STRCAT_OP),0, 3, "k", "SS", + (SUBR) strcmp_opcode, (SUBR) strcmp_opcode, (SUBR) NULL }, + { "sprintf", S(SPRINTF_OP),0, 1, "S", "STN", + (SUBR) sprintf_opcode, (SUBR) NULL, (SUBR) NULL }, + { "sprintfk", S(SPRINTF_OP),WR, 3, "S", "SUN", + (SUBR) sprintf_opcode, (SUBR) sprintf_opcode, (SUBR) NULL }, + { "printf_i", S(PRINTF_OP),0, 1, "", "SiTN", + (SUBR) printf_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "printf", S(PRINTF_OP),WR, 3, "", "SkUN", + (SUBR) printf_opcode_set, (SUBR) printf_opcode_perf, (SUBR) NULL }, + { "puts", S(PUTS_OP),WR, 3, "", "Sko", + (SUBR) puts_opcode_init, (SUBR) puts_opcode_perf, (SUBR) NULL }, + { "strtod", S(STRSET_OP),0, 1, "i", "S", + (SUBR) strtod_opcode_S, (SUBR) NULL, (SUBR) NULL }, + { "strtod", S(STRTOD_OP),0, 1, "i", "i", + (SUBR) strtod_opcode_p, (SUBR) NULL, (SUBR) NULL }, + { "strtodk", S(STRSET_OP),0, 3, "k", "S", + (SUBR) strtod_opcode_S, (SUBR) strtod_opcode_S, (SUBR) NULL }, + { "strtol", S(STRSET_OP),0, 1, "i", "S", + (SUBR) strtol_opcode_S, (SUBR) NULL, (SUBR) NULL }, + { "strtol", S(STRTOD_OP),0, 1, "i", "i", + (SUBR) strtol_opcode_p, (SUBR) NULL, (SUBR) NULL }, + { "strtolk", S(STRSET_OP),0, 3, "k", "S", + (SUBR) strtol_opcode_S, (SUBR) strtol_opcode_S, (SUBR) NULL }, + { "strsub", S(STRSUB_OP),0, 1, "S", "Soj", + (SUBR) strsub_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strsubk", S(STRSUB_OP),0, 3, "S", "Skk", + (SUBR) strsub_opcode, (SUBR) strsub_opcode, (SUBR) NULL }, + { "strchar", S(STRCHAR_OP),0, 1, "i", "So", + (SUBR) strchar_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strchark", S(STRCHAR_OP),0, 3, "k", "SO", + (SUBR) strchar_opcode, (SUBR) strchar_opcode, (SUBR) NULL }, + { "strlen", S(STRLEN_OP),0, 1, "i", "S", + (SUBR) strlen_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strlenk", S(STRLEN_OP),0, 3, "k", "S", + (SUBR) strlen_opcode, (SUBR) strlen_opcode, (SUBR) NULL }, + { "strupper", S(STRUPPER_OP),0, 1, "S", "S", + (SUBR) strupper_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strupperk", S(STRUPPER_OP),0, 3, "S", "S", + (SUBR) strupper_opcode, (SUBR) strupper_opcode, (SUBR) NULL }, + { "strlower", S(STRUPPER_OP),0, 1, "S", "S", + (SUBR) strlower_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strlowerk", S(STRUPPER_OP),0, 3, "S", "S", + (SUBR) strlower_opcode, (SUBR) strlower_opcode, (SUBR) NULL }, + { "getcfg", S(GETCFG_OP),0, 1, "S", "i", + (SUBR) getcfg_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strindex", S(STRINDEX_OP),0, 1, "i", "SS", + (SUBR) strindex_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strindexk", S(STRINDEX_OP),0, 3, "k", "SS", + (SUBR) strindex_opcode, (SUBR) strindex_opcode, (SUBR) NULL }, + { "strrindex", S(STRINDEX_OP),0, 1, "i", "SS", + (SUBR) strrindex_opcode, (SUBR) NULL, (SUBR) NULL }, + { "strrindexk", S(STRINDEX_OP),0, 3, "k", "SS", + (SUBR) strrindex_opcode, (SUBR) strrindex_opcode, (SUBR) NULL }, +#ifdef HAVE_CURL + { "strfromurl", S(STRCPY_OP), 0, 1, "S", "S", (SUBR) str_from_url }, #endif -{ "##error",S(ERRFN), 1, "i", "i", error_fn, NULL, NULL }, -{ "exprandi.i",S(PRANDI), 1, "i", "kxx", iexprndi, NULL, NULL }, -{ "exprandi.k",S(PRANDI), 3, "k", "kxx", exprndiset, kexprndi, NULL }, -{ "exprandi.a",S(PRANDI), 4, "a", "kxx", exprndiset, NULL, aexprndi }, -{ "cauchyi.i", S(PRANDI), 1, "i", "kxx", icauchyi, NULL, NULL }, -{ "cauchyi.k", S(PRANDI), 3, "k", "kxx", cauchyiset, kcauchyi, NULL }, -{ "cauchyi.a", S(PRANDI), 4, "a", "kxx", cauchyiset, NULL, acauchyi }, -{ "gaussi.i", S(PRANDI), 1, "i", "kxx", igaussi, NULL, NULL }, -{ "gaussi.k", S(PRANDI), 3, "k", "kxx", gaussiset, kgaussi, NULL }, -{ "gaussi.a", S(PRANDI), 4, "a", "kxx", gaussiset, NULL, agaussi }, -{ "ftresizei", S(RESIZE), TB|1, "i", "ii", (SUBR) resize_table, NULL, NULL }, -{ "ftresize", S(RESIZE), TB|2, "k", "kk", NULL, (SUBR) resize_table, NULL }, -/* terminate list */ -{ NULL, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } + { "changed.S", S(STRINDEX_OP),0, 3, "k", "S", + (SUBR) str_changed, (SUBR) str_changed_k, (SUBR) NULL }, + { "loop_lt", 0xfffb }, + { "loop_le", 0xfffb }, + { "loop_gt", 0xfffb }, + { "loop_ge", 0xfffb }, + { "loop_lt.i", S(LOOP_OPS),0, 1, "", "iiil", (SUBR) loop_l_i, NULL, NULL }, + { "loop_le.i", S(LOOP_OPS),0, 1, "", "iiil", (SUBR) loop_le_i, NULL, NULL }, + { "loop_gt.i", S(LOOP_OPS),0, 1, "", "iiil", (SUBR) loop_g_i, NULL, NULL }, + { "loop_ge.i", S(LOOP_OPS),0, 1, "", "iiil", (SUBR) loop_ge_i, NULL, NULL }, + { "loop_lt.k", S(LOOP_OPS),0, 2, "", "kkkl", NULL, (SUBR) loop_l_p, NULL }, + { "loop_le.k", S(LOOP_OPS),0, 2, "", "kkkl", NULL, (SUBR) loop_le_p, NULL }, + { "loop_gt.k", S(LOOP_OPS),0, 2, "", "kkkl", NULL, (SUBR) loop_g_p, NULL }, + { "loop_ge.k", S(LOOP_OPS),0, 2, "", "kkkl", NULL, (SUBR) loop_ge_p, NULL }, + { "chnget", 0xFFFF, CR }, + { "chnget.i", S(CHNGET),0, 1, "i", "S", + (SUBR) chnget_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, + { "chnget.k", S(CHNGET),0, 3, "k", "S", + (SUBR) chnget_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, + { "chnget.a", S(CHNGET),0, 5, "a", "S", + (SUBR) chnget_opcode_init_a, (SUBR) NULL, (SUBR) notinit_opcode_stub }, + { "chnget.S", S(CHNGET),0, 3, "S", "S", + (SUBR) chnget_opcode_init_S, (SUBR) chnget_opcode_perf_S, (SUBR) NULL}, + { "chnset", 0xFFFB, CW }, + { "chnset.i", S(CHNGET),0, 1, "", "iS", + (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, + { "chnset.r", S(CHNGET),0, 1, "", "iS", + (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, + { "chnset.c", S(CHNGET),0, 1, "", "iS", + (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, + { "chnset.k", S(CHNGET),0, 3, "", "kS", + (SUBR) chnset_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, + { "chnset.a", S(CHNGET),0, 5, "", "aS", + (SUBR) chnset_opcode_init_a, (SUBR) NULL, (SUBR) notinit_opcode_stub }, + { "chnset.S", S(CHNGET),0, 3, "", "SS", + (SUBR) chnset_opcode_init_S, (SUBR) chnset_opcode_perf_S, (SUBR) NULL }, + { "chnmix", S(CHNGET), CB, 5, "", "aS", + (SUBR) chnmix_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, + { "chnclear", S(CHNCLEAR), CW, 5, "", "S", + (SUBR) chnclear_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, + { "chn_k", S(CHN_OPCODE_K), CW, 1, "", "SiooooooooN", + (SUBR) chn_k_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chn_a", S(CHN_OPCODE), CW, 1, "", "Si", + (SUBR) chn_a_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chn_S", S(CHN_OPCODE), CW, 1, "", "Si", + (SUBR) chn_S_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chnexport", 0xFFFF, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL }, + { "chnexport.i", S(CHNEXPORT_OPCODE),0, 1, "i", "Sioooo", + (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chnexport.k", S(CHNEXPORT_OPCODE),0, 1, "k", "Sioooo", + (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chnexport.a", S(CHNEXPORT_OPCODE),0, 1, "a", "Si", + (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chnexport.S", S(CHNEXPORT_OPCODE),0, 1, "S", "Si", + (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, + { "chnparams", S(CHNPARAMS_OPCODE),CR, 1, "iiiiii", "S", + (SUBR) chnparams_opcode_init, (SUBR) NULL, (SUBR) NULL }, + /* these opcodes have never been fully implemented + { "chnrecv", S(CHNSEND), CR, 3, "", "So", + (SUBR) chnrecv_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, + { "chnsend", S(CHNSEND),0, 3, "", "So", + (SUBR) chnsend_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, + */ + { "chano", 0xFFFD, CW, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL }, + { "chano.k", S(ASSIGN),0, 2, "", "kk", + (SUBR) NULL, (SUBR) chano_opcode_perf_k, (SUBR) NULL }, + { "chano.a", S(ASSIGN),0, 4, "", "ak", + (SUBR) NULL, (SUBR) NULL, (SUBR) chano_opcode_perf_a }, + { "pvsout", S(FCHAN),0, 3, "", "fk", + (SUBR) pvsout_init, (SUBR) pvsout_perf, (SUBR) NULL }, + { "chani", 0xFFFF, CR, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL }, + { "chani.k", S(ASSIGN),0, 2, "k", "k", + (SUBR) NULL, (SUBR) chani_opcode_perf_k, (SUBR) NULL }, + { "chani.a", S(ASSIGN),0, 4, "a", "k", + (SUBR) NULL, (SUBR) NULL, (SUBR) chani_opcode_perf_a }, + { "pvsin", S(FCHAN),0, 3, "f", "kooopo", + (SUBR) pvsin_init, (SUBR) pvsin_perf, (SUBR) NULL }, + { "sense", S(KSENSE),0, 2, "kz", "", + (SUBR) NULL, (SUBR) sensekey_perf, (SUBR) NULL }, + { "sensekey", S(KSENSE),0, 2, "kz", "", + (SUBR) NULL, (SUBR) sensekey_perf, (SUBR) NULL }, + { "remove", S(DELETEIN),0, 1, "", "T", + (SUBR) delete_instr, (SUBR) NULL, (SUBR) NULL }, + { "##globallock", S(GLOBAL_LOCK_UNLOCK),0, 3, "", "i", + globallock, globallock, NULL}, + { "##globalunlock", S(GLOBAL_LOCK_UNLOCK),0, 3, "", "i", + globalunlock, globalunlock, NULL}, + { "##error",S(ERRFN),0, 1, "i", "i", error_fn, NULL, NULL }, + { "exprandi.i",S(PRANDI),0, 1, "i", "kxx", iexprndi, NULL, NULL }, + { "exprandi.k",S(PRANDI),0, 3, "k", "kxx", exprndiset, kexprndi, NULL }, + { "exprandi.a",S(PRANDI),0, 4, "a", "kxx", exprndiset, NULL, aexprndi }, + { "cauchyi.i", S(PRANDI),0, 1, "i", "kxx", icauchyi, NULL, NULL }, + { "cauchyi.k", S(PRANDI),0, 3, "k", "kxx", cauchyiset, kcauchyi, NULL }, + { "cauchyi.a", S(PRANDI),0, 4, "a", "kxx", cauchyiset, NULL, acauchyi }, + { "gaussi.i", S(PRANDI),0, 1, "i", "kxx", igaussi, NULL, NULL }, + { "gaussi.k", S(PRANDI),0, 3, "k", "kxx", gaussiset, kgaussi, NULL }, + { "gaussi.a", S(PRANDI),0, 4, "a", "kxx", gaussiset, NULL, agaussi }, + { "ftresizei", S(RESIZE), TB, 1, "i", "ii", (SUBR) resize_table, NULL, NULL }, + { "ftresize", S(RESIZE), TB, 2, "k", "kk", NULL, (SUBR) resize_table, NULL }, + { "compileorc", S(COMPILE), 0, 1, "i", "S", (SUBR) compile_orc_i, NULL, NULL }, + { "compilestr", S(COMPILE), 0, 1, "i", "S", (SUBR) compile_str_i, NULL, NULL }, + { "evalstr", S(COMPILE), 0, 1, "i", "S", (SUBR) eval_str_i, NULL, NULL }, + { "evalstr", S(COMPILE), 0, 2, "k", "Sk", NULL, (SUBR) eval_str_k, NULL }, + { "readscore", S(COMPILE), 0, 1, "i", "S", (SUBR) read_score_i, NULL, NULL }, + { "return", S(RETVAL), 0, 1, "", "i", (SUBR) retval_i, NULL, NULL }, + /* ----------------------------------------------------------------------- */ + { "monitor", sizeof(MONITOR_OPCODE), 0, 3, "mmmmmmmmmmmmmmmmmmmmmmmm", "", + (SUBR) monitor_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, + { "outrg", S(OUTRANGE), 0,5, "", "ky", + (SUBR)outRange_i, (SUBR)NULL, (SUBR)outRange}, + /* terminate list */ + { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } }; diff -Nru csound-5.17.11~dfsg/Engine/envvar.c csound-6.02~dfsg/Engine/envvar.c --- csound-5.17.11~dfsg/Engine/envvar.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/envvar.c 2014-01-07 16:54:20.000000000 +0000 @@ -22,7 +22,7 @@ */ #include "csoundCore.h" -#include +#include "soundio.h" #include "envvar.h" #include #include @@ -31,13 +31,6 @@ #include #endif -#if defined(mac_classic) && defined(__MWERKS__) -#include -#endif -#if defined(SYMANTEC) -extern off_t lseek(int, off_t, int); -#endif - #include "namedins.h" /* list of environment variables used by Csound */ @@ -49,8 +42,8 @@ "CS_LANG", "HOME", "INCDIR", - "OPCODEDIR", - "OPCODEDIR64", + "OPCODE6DIR", + "OPCODE6DIR64", "RAWWAVE_PATH", "SADIR", "SFDIR", @@ -61,12 +54,26 @@ NULL }; -#define ENV_DB (((CSOUND*) csound)->envVarDB) +typedef struct CSFILE_ { + struct CSFILE_ *nxt; + struct CSFILE_ *prv; + int type; + int fd; + FILE *f; + SNDFILE *sf; + void *cb; + int async_flag; + int items; + int pos; + MYFLT *buf; + int bufsize; + char fullName[1]; +} CSFILE; #if defined(MSVC) #define RD_OPTS _O_RDONLY | _O_BINARY #define WR_OPTS _O_TRUNC | _O_CREAT | _O_WRONLY | _O_BINARY,_S_IWRITE -#elif defined(mac_classic) || defined(SYMANTEC) || defined(WIN32) +#elif defined(WIN32) #define RD_OPTS O_RDONLY | O_BINARY #define WR_OPTS O_TRUNC | O_CREAT | O_WRONLY | O_BINARY, 0644 #elif defined DOSGCC @@ -80,12 +87,6 @@ #define WR_OPTS O_TRUNC | O_CREAT | O_WRONLY | O_BINARY, 0644 #endif -typedef struct envVarEntry_s { - struct envVarEntry_s *nxt; /* pointer to next link in chain */ - char *name; /* name of environment variable */ - char *value; /* value of environment variable */ -} envVarEntry_t; - typedef struct searchPathCacheEntry_s { char *name; struct searchPathCacheEntry_s *nxt; @@ -97,16 +98,6 @@ char s[1]; } nameChain_t; -typedef struct CSFILE_ { - struct CSFILE_ *nxt; - struct CSFILE_ *prv; - int type; - int fd; - FILE *f; - SNDFILE *sf; - char fullName[1]; -} CSFILE; - /* Space for 16 global environment variables, */ /* 32 bytes for name and 480 bytes for value. */ /* Only written by csoundSetGlobalEnv(). */ @@ -116,18 +107,6 @@ #define globalEnvVarName(x) ((char*) &(globalEnvVars[(int) (x) << 9])) #define globalEnvVarValue(x) ((char*) &(globalEnvVars[((int) (x) << 9) + 32])) -static inline envVarEntry_t **getEnvVarChain(CSOUND *csound, const char *name) -{ - unsigned char h; - /* check for trivial cases */ - if (UNLIKELY(ENV_DB == NULL || name == NULL || name[0] == '\0')) - return NULL; - /* calculate hash value */ - h = name_hash_2(csound, name); - /* return with pointer from table */ - return &(((envVarEntry_t**) ENV_DB)[(int) h]); -} - static int is_valid_envvar_name(const char *name) { char *s; @@ -151,8 +130,6 @@ PUBLIC const char *csoundGetEnv(CSOUND *csound, const char *name) { - envVarEntry_t **pp, *p; - if (csound == NULL) { int i; if (name == NULL || name[0] == '\0') @@ -163,15 +140,10 @@ } return (const char*) getenv(name); } - pp = getEnvVarChain(csound, name); - if (pp == NULL) - return (const char*) NULL; - p = *pp; - while (p != NULL && sCmp(p->name, name) != 0) - p = p->nxt; - if (p == NULL) - return (const char*) NULL; - return (const char*) p->value; + + if (csound->envVarDB == NULL) return NULL; + + return (const char*) cs_hash_table_get(csound, csound->envVarDB, (char*)name); } /** @@ -215,15 +187,12 @@ int csoundSetEnv(CSOUND *csound, const char *name, const char *value) { searchPathCacheEntry_t *ep, *nxt; - envVarEntry_t **pp, *p; - char *s1, *s2; + char *oldValue; /* check for valid parameters */ if (UNLIKELY(csound == NULL || !is_valid_envvar_name(name))) return CSOUND_ERROR; - pp = getEnvVarChain(csound, name); - if (UNLIKELY(pp == NULL)) - return CSOUND_ERROR; + /* invalidate search path cache */ ep = (searchPathCacheEntry_t*) csound->searchPathCache; while (ep != NULL) { @@ -232,49 +201,31 @@ ep = nxt; } csound->searchPathCache = NULL; - p = *pp; - s1 = (char*) name; - s2 = NULL; - /* copy value */ - if (value != NULL) { - s2 = (char*) mmalloc(csound, strlen(value) + 1); - strcpy(s2, value); - } - /* is this variable already defined ? */ - while (p != NULL && sCmp(p->name, name) != 0) - p = p->nxt; - if (p != NULL) { - /* yes, only need to replace value */ - if (p->value != NULL) - mfree(csound, p->value); - p->value = s2; - } - else { - /* no, need to allocate new entry, and copy name too */ - p = (envVarEntry_t*) mmalloc(csound, sizeof(envVarEntry_t)); - s1 = (char*) mmalloc(csound, (size_t) strlen(name) + (size_t) 1); - strcpy(s1, name); - /* store pointers to name and value, and link into chain */ - p->nxt = *pp; - p->name = s1; - p->value = s2; - *pp = p; + + + oldValue = cs_hash_table_get(csound, csound->envVarDB, (char*)name); + if (oldValue != NULL) { + mfree(csound, oldValue); } + + cs_hash_table_put(csound, csound->envVarDB, + (char*)name, cs_strdup(csound, (char*)value)); + /* print debugging info if requested */ if (csound->oparms->odebug) { - csound->Message(csound, Str("Environment variable '%s' has been set to "), + csoundMessage(csound, Str("Environment variable '%s' has been set to "), name); if (value == NULL) - csound->Message(csound, "NULL\n"); + csoundMessage(csound, "NULL\n"); else - csound->Message(csound, "'%s'\n", s2); + csoundMessage(csound, "'%s'\n", value); } /* report success */ return CSOUND_SUCCESS; } /** - * Append 'value' to environment variable 'name', using ';' as + * Append 'value' to environment variable 'name', using ENVSEP as * separator character. * Returns CSOUND_SUCCESS on success, and CSOUND_ERROR or CSOUND_MEMORY * if the environment variable could not be set for some reason. @@ -295,13 +246,18 @@ return csoundSetEnv(csound, name, value); if (value == NULL || value[0] == '\0') return CSOUND_SUCCESS; - /* allocate new value (+ 2 bytes for ';' and null character) */ + /* allocate new value (+ 2 bytes for ENVSEP and null character) */ newval = (char*) mmalloc(csound, (size_t) strlen(oldval) + (size_t) strlen(value) + (size_t) 2); /* append to old value */ strcpy(newval, oldval); /* These are safe as space calculated above */ - strcat(newval, ";"); + // printf("%d: newval = %s\n", __LINE__, newval); + // should be a better way + newval[strlen(oldval)]= ENVSEP; + newval[strlen(oldval)+1]= '\0'; + // printf("%d: newval = %s\n", __LINE__, newval); strcat(newval, value); + // printf("%d: newval = %s\n", __LINE__, newval); /* set variable */ retval = csoundSetEnv(csound, name, newval); mfree(csound, newval); @@ -310,7 +266,7 @@ } /** - * Prepend 'value' to environment variable 'name', using ';' as + * Prepend 'value' to environment variable 'name', using ENVSEP as * separator character. * Returns CSOUND_SUCCESS on success, and CSOUND_ERROR or CSOUND_MEMORY * if the environment variable could not be set for some reason. @@ -336,8 +292,12 @@ + (size_t) strlen(value) + (size_t) 2); /* prepend to old value */ strcpy(newval, value); - strcat(newval, ";"); + // printf("%d: newval = %s\n", __LINE__, newval); + newval[strlen(value)]= ENVSEP; + newval[strlen(value)+1]= '\0'; + // printf("%d: newval = %s\n", __LINE__, newval); strcat(newval, oldval); + // printf("%d: newval = %s\n", __LINE__, newval); /* set variable */ retval = csoundSetEnv(csound, name, newval); mfree(csound, newval); @@ -356,12 +316,10 @@ { int i, retval; /* check if already initialised */ - if (ENV_DB != NULL) + if (csound->envVarDB != NULL) return CSOUND_SUCCESS; /* allocate table */ - ENV_DB = (void*) mmalloc(csound, sizeof(envVarEntry_t*) * (size_t) 256); - for (i = 0; i < 256; i++) - ((envVarEntry_t**) ENV_DB)[i] = (envVarEntry_t*) NULL; + csound->envVarDB = cs_hash_table_create(csound); /* copy standard Csound environment variables */ for (i = 0; envVar_list[i] != NULL; i++) { const char *name = envVar_list[i]; @@ -405,7 +363,7 @@ value = strchr(name, '='); append_mode = 0; if (UNLIKELY(value == NULL || value == name)) { - sprintf(msg, " *** invalid format for --env\n"); + strcpy(msg, " *** invalid format for --env\n"); retval = CSOUND_ERROR; goto err_return; } @@ -415,7 +373,7 @@ *(value - 2) = '\0'; } if (UNLIKELY(!is_valid_envvar_name(name))) { - sprintf(msg, " *** invalid environment variable name\n"); + strcpy(msg, " *** invalid environment variable name\n"); retval = CSOUND_ERROR; goto err_return; } @@ -425,13 +383,13 @@ else retval = csoundAppendEnv(csound, name, value); if (UNLIKELY(retval == CSOUND_MEMORY)) - sprintf(msg, " *** memory allocation failure\n"); + strcpy(msg, " *** memory allocation failure\n"); else - sprintf(msg, " *** error setting environment variable\n"); + strcpy(msg, " *** error setting environment variable\n"); err_return: if (UNLIKELY(retval != CSOUND_SUCCESS)) - csound->Message(csound, Str(msg)); + csoundMessage(csound, Str(msg)); if (name != NULL) mfree(csound, name); return retval; @@ -455,7 +413,7 @@ len = (int) strlen(envList); /* split environment variable list to tokens */ for (i = j = 0; i <= len; i++) { - if (envList[i] == ';' || envList[i] == '\0') { + if (envList[i] == ';' || envList[i] == ':' || envList[i] == '\0') { if (i > j) { tmp = (nameChain_t*) mmalloc(csound, sizeof(nameChain_t) + (i - j)); for (k = 0; j < i; j++, k++) @@ -492,7 +450,7 @@ else len = -1; for (i = j = 0; i <= len; i++) { - if (s[i] == ';' || s[i] == '\0') { + if (s[i] == ';' || s[i] == ':' || s[i] == '\0') { if (i > j) { tmp = (nameChain_t*) mmalloc(csound, sizeof(nameChain_t) + (i - j) + 1); @@ -589,18 +547,11 @@ #ifdef WIN32 if (isalpha(name[0]) && name[1] == ':') return 1; #endif -#ifndef mac_classic if (name[0] == DIRSEP) /* || (name[0] == '.' && (name[1] == DIRSEP || (name[1] == '.' && name[2] == DIRSEP)))) */ return 1; return 0; -#else - /* MacOS full paths contain DIRSEP but do not start with it */ - if (name[0] == DIRSEP || strchr(name, DIRSEP) == NULL) - return 0; - return 1; -#endif } /** Check if name is a relative pathname for this platform. Bare @@ -608,16 +559,9 @@ */ int csoundIsNameRelativePath(const char *name) { -#ifndef mac_classic if (name[0] != DIRSEP && strchr(name, DIRSEP) != NULL) return 1; return 0; -#else - /* MacOS relative paths begin with DIRSEP */ - if (name[0] == DIRSEP) - return 1; - return 0; -#endif } /** Check if name is a "leaf" (bare) filename for this platform. */ @@ -654,13 +598,8 @@ } start2 = path2; -#ifndef mac_classic /* ignore "./" at the beginning */ if (path2[0] == '.' && path2[1] == DIRSEP) start2 = path2 + 2; -#else - /* ignore the first ':' of path2 if any are present */ - if (path2[0] == ':') start2 = path2 + 1; -#endif result = (char*) mmalloc(csound, (size_t)len1+(size_t)len2+2); strcpy(result, path1); @@ -742,13 +681,14 @@ char *cwd; int len; + if(path == NULL) return NULL; + char *tempPath = csoundConvertPathname(csound, path); char *lastIndex = strrchr(tempPath, DIRSEP); if (csoundIsNameFullpath(tempPath)) { -#ifndef mac_classic /* check if root directory */ if (lastIndex == tempPath) { partialPath = (char *)mmalloc(csound, 2); @@ -774,8 +714,6 @@ return partialPath; } # endif -#endif /* no special case needed on OS 9 for root directory */ - /* not the root directory or we are on OS 9 */ len = (lastIndex - tempPath); partialPath = (char *)mcalloc(csound, len + 1); @@ -790,7 +728,7 @@ /* we have a relative path or just a filename */ cwd = mmalloc(csound, 512); if (UNLIKELY(getcwd(cwd, 512)==NULL)) { - csoundDie(csound, "Current directory path name too long\n"); + csoundDie(csound, Str("Current directory path name too long\n")); } if (lastIndex == NULL) { @@ -948,9 +886,9 @@ * and if it is still not found, a pathname list that is created the * following way is searched: * 1. if envList is NULL or empty, no directories are searched - * 2. envList is parsed as a ';' separated list of environment variable - * names, and all environment variables are expanded and expected to - * contain a ';' separated list of directory names + * 2. envList is parsed as a ';' or ':' separated list of environment + * variable names, and all environment variables are expanded and + * expected to contain a ';' or ':' separated list of directory names * 2. all directories in the resulting pathname list are searched, starting * from the last and towards the first one, and the directory where the * file is found first will be used @@ -1013,9 +951,6 @@ /** * Open a file and return handle. * - * This function has been replaced by csoundFileOpenWithType(). - * Please do not use it in new code. - * * CSOUND *csound: * Csound instance pointer * void *fd: @@ -1043,33 +978,17 @@ * list of environment variables for search path (see csoundFindInputFile() * for details); if NULL, the specified name is used as it is, without any * conversion or search. - * return value: - * opaque handle to the opened file, for use with csoundGetFileName() or - * csoundFileClose(), or storing in FDCH.fd. - * On failure, NULL is returned. - */ - -void *csoundFileOpen(CSOUND *csound, void *fd, int type, - const char *name, void *param, const char *env) -{ - return csoundFileOpenWithType(csound, fd, type, name, param, env, - CSFTYPE_UNKNOWN, 0); -} - -/** - * Open a file and return handle. - * - * Same as csoundFileOpen() with two additional parameters describing the - * type of file being opened and whether it is a temporary file. This - * function replaces csoundFileOpen(). This additional information is - * used as metadata to be passed to the host application's FileOpenCallback. - * * int csFileType: * A value from the enumeration CSOUND_FILETYPES (see soundCore.h) * int isTemporary: * 1 if this file will be deleted when Csound is finished. * Otherwise, 0. + * return value: + * opaque handle to the opened file, for use with csoundGetFileName() or + * csoundFileClose(), or storing in FDCH.fd. + * On failure, NULL is returned. */ + void *csoundFileOpenWithType(CSOUND *csound, void *fd, int type, const char *name, void *param, const char *env, int csFileType, int isTemporary) @@ -1080,6 +999,7 @@ SF_INFO sfinfo; int tmp_fd = -1, nbytes = (int) sizeof(CSFILE); + /* check file type */ if (UNLIKELY((unsigned int) (type - 1) >= (unsigned int) CSFILE_SND_W)) { csoundErrorMsg(csound, Str("internal error: csoundFileOpen(): " @@ -1134,6 +1054,7 @@ mfree(csound, fullName); env = NULL; } + /* if sound file, re-open file descriptor with libsndfile */ switch (type) { case CSFILE_STD: /* stdio */ @@ -1198,6 +1119,10 @@ writing, isTemporary); } /* return with opaque file handle */ + p->cb = NULL; + p->async_flag = 0; + p->buf = NULL; + p->bufsize = 0; return (void*) p; err_return: @@ -1219,6 +1144,7 @@ return NULL; } + /** * Allocate a file handle for an existing file already opened with open(), * fopen(), or sf_open(), for later use with csoundFileClose() or @@ -1250,6 +1176,7 @@ p->fd = -1; p->f = (FILE*) NULL; p->sf = (SNDFILE*) NULL; + p->cb = NULL; strcpy(&(p->fullName[0]), fullName); /* open file */ switch (type) { @@ -1275,6 +1202,7 @@ ((CSFILE*) csound->open_files)->prv = p; csound->open_files = (void*) p; /* return with opaque file handle */ + p->cb = NULL; return (void*) p; } @@ -1295,8 +1223,9 @@ { CSFILE *p = (CSFILE*) fd; int retval = -1; - - /* close file */ + if(p->async_flag == ASYNC_GLOBAL) { + csound->WaitThreadLockNoTimeout(csound->file_io_threadlock); + /* close file */ switch (p->type) { case CSFILE_FD_R: case CSFILE_FD_W: @@ -1307,7 +1236,9 @@ break; case CSFILE_SND_R: case CSFILE_SND_W: + if(p->sf) retval = sf_close(p->sf); + p->sf = NULL; if (p->fd >= 0) retval |= close(p->fd); break; @@ -1319,8 +1250,38 @@ p->prv->nxt = p->nxt; if (p->nxt != NULL) p->nxt->prv = p->prv; + if(p->buf != NULL) mfree(csound, p->buf); + p->bufsize = 0; + csound->DestroyCircularBuffer(csound, p->cb); + csound->NotifyThreadLock(csound->file_io_threadlock); + } else { + /* close file */ + switch (p->type) { + case CSFILE_FD_R: + case CSFILE_FD_W: + retval = close(p->fd); + break; + case CSFILE_STD: + retval = fclose(p->f); + break; + case CSFILE_SND_R: + case CSFILE_SND_W: + retval = sf_close(p->sf); + if (p->fd >= 0) + retval |= close(p->fd); + break; + } + /* unlink from chain of open files */ + if (p->prv == NULL) + csound->open_files = (void*) p->nxt; + else + p->prv->nxt = p->nxt; + if (p->nxt != NULL) + p->nxt->prv = p->prv; + } /* free allocated memory */ mfree(csound, fd); + /* return with error value */ return retval; } @@ -1331,5 +1292,174 @@ { while (csound->open_files != NULL) csoundFileClose(csound, csound->open_files); + if (csound->file_io_start) { + pthread_join(csound->file_io_thread, NULL); + if (csound->file_io_threadlock != NULL) + csound->DestroyThreadLock(csound->file_io_threadlock); + } } +/* The fromScore parameter should be 1 if opening a score include file, + 0 if opening an orchestra include file */ +void *fopen_path(CSOUND *csound, FILE **fp, char *name, char *basename, + char *env, int fromScore) +{ + void *fd; + int csftype = (fromScore ? CSFTYPE_SCO_INCLUDE : CSFTYPE_ORC_INCLUDE); + + /* First try to open name given */ + fd = csound->FileOpen2(csound, fp, CSFILE_STD, name, "rb", NULL, + csftype, 0); + if (fd != NULL) + return fd; + /* if that fails try in base directory */ + if (basename != NULL) { + char *dir, *name_full; + if ((dir = csoundSplitDirectoryFromPath(csound, basename)) != NULL) { + name_full = csoundConcatenatePaths(csound, dir, name); + fd = csound->FileOpen2(csound, fp, CSFILE_STD, name_full, "rb", NULL, + csftype, 0); + mfree(csound, dir); + mfree(csound, name_full); + if (fd != NULL) + return fd; + } + } + /* or use env argument */ + fd = csound->FileOpen2(csound, fp, CSFILE_STD, name, "rb", env, + csftype, 0); + return fd; +} + +void *file_iothread(void *p); + +void *csoundFileOpenWithType_Async(CSOUND *csound, void *fd, int type, + const char *name, void *param, const char *env, + int csFileType, int buffsize, int isTemporary) +{ + CSFILE *p; + if ((p = (CSFILE *) csoundFileOpenWithType(csound,fd,type,name,param,env, + csFileType,isTemporary)) == NULL) + return NULL; + + if (csound->file_io_start == 0) { + csound->file_io_start = 1; + csound->file_io_threadlock = csound->CreateThreadLock(); + csound->NotifyThreadLock(csound->file_io_threadlock); + pthread_create(&csound->file_io_thread,NULL, file_iothread, (void *) csound); + } + csound->WaitThreadLockNoTimeout(csound->file_io_threadlock); + p->async_flag = ASYNC_GLOBAL; + + p->cb = csound->CreateCircularBuffer(csound, buffsize*4, sizeof(MYFLT)); + p->items = 0; + p->pos = 0; + p->bufsize = buffsize; + p->buf = (MYFLT *) mcalloc(csound, sizeof(MYFLT)*buffsize); + csound->NotifyThreadLock(csound->file_io_threadlock); + + if (p->cb == NULL || p->buf == NULL) { + /* close file immediately */ + csoundFileClose(csound, (void *) p); + return NULL; + } + return (void *) p; +} + +unsigned int csoundReadAsync(CSOUND *csound, void *handle, + MYFLT *buf, int items) +{ + CSFILE *p = handle; + if(p != NULL && p->cb != NULL) + return csound->ReadCircularBuffer(csound, p->cb, buf, items); + else return 0; +} + +unsigned int csoundWriteAsync(CSOUND *csound, void *handle, + MYFLT *buf, int items) +{ + CSFILE *p = handle; + if(p != NULL && p->cb != NULL) + return csound->WriteCircularBuffer(csound, p->cb, buf, items); + else return 0; +} + +int csoundFSeekAsync(CSOUND *csound, void *handle, int pos, int whence){ + CSFILE *p = handle; + int ret = 0; + csound->WaitThreadLockNoTimeout(csound->file_io_threadlock); + switch (p->type) { + case CSFILE_FD_R: + break; + case CSFILE_FD_W: + break; + case CSFILE_STD: + break; + case CSFILE_SND_R: + case CSFILE_SND_W: + ret = sf_seek(p->sf,pos,whence); + //csoundMessage(csound, "seek set %d \n", pos); + csound->FlushCircularBuffer(csound, p->cb); + p->items = 0; + break; + } + csound->NotifyThreadLock(csound->file_io_threadlock); + return ret; +} + + +static int read_files(CSOUND *csound){ + CSFILE *current = (CSFILE *) csound->open_files; + if (current == NULL) return 0; + while (current) { + if(current->async_flag == ASYNC_GLOBAL) { + int m = current->pos, l, n = current->items; + int items = current->bufsize; + MYFLT *buf = current->buf; + switch (current->type) { + case CSFILE_FD_R: + break; + case CSFILE_FD_W: + break; + case CSFILE_STD: + break; + case CSFILE_SND_R: + if(n == 0) { + n = sf_read_MYFLT(current->sf, buf, items); + m = 0; + } + l = csound->WriteCircularBuffer(csound,current->cb,&buf[m],n); + m += l; + n -= l; + current->items = n; + current->pos = m; + break; + case CSFILE_SND_W: + items = csound->ReadCircularBuffer(csound, current->cb, buf, items); + if(items == 0) { csoundSleep(10); break;} + sf_write_MYFLT(current->sf, buf, items); + break; + } + } + current = current->nxt; + } + return 1; +} + + + + +void *file_iothread(void *p){ + int res = 1; + CSOUND *csound = p; + int wakeup = (int) (1000*csound->ksmps/csound->esr); + if(wakeup == 0) wakeup = 1; + while(res){ + csoundSleep(wakeup); + csound->WaitThreadLockNoTimeout(csound->file_io_threadlock); + res = read_files(csound); + csound->NotifyThreadLock(csound->file_io_threadlock); + } + csound->file_io_start = 0; + return NULL; +} diff -Nru csound-5.17.11~dfsg/Engine/express.c csound-6.02~dfsg/Engine/express.c --- csound-5.17.11~dfsg/Engine/express.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/express.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,601 +0,0 @@ -/* - express.c: - - Copyright (C) 1991 Barry Vercoe, John ffitch, Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#include "csoundCore.h" /* EXPRESS.C */ -#include "namedins.h" - -#define BITSHL 0x19 -#define BITSHR 0x18 -#define BITSET 0x17 -#define BITCLR 0x16 -#define BITFLP 0x15 - -#define POLMAX 30L /* This one is OK */ -#define XERROR(CAUSE) { strncpy(xprmsg,CAUSE,128); goto error; } - -static const char strminus1[] = "-1"; -static const char strmult[] = "*"; - -static void putokens(CSOUND*), putoklist(CSOUND*); -static int nontermin(int); - -#define copystring(s) strsav_string(csound, s) - -static CS_NOINLINE char *extend_tokenstring(CSOUND *csound, size_t len) -{ - size_t newLen; - char *tt; - TOKEN *ttt; - - newLen = (size_t) csound->toklen; - do { - newLen = ((newLen + (newLen >> 2)) | (size_t) 127) + (size_t) 1; - } while (newLen <= len); - tt = (char*) mrealloc(csound, csound->tokenstring, newLen + (size_t) 128); - /* Adjust all previous tokens */ - if (LIKELY(csound->token)) { - for (ttt = csound->tokens; ttt <= csound->token; ttt++) - ttt->str += (tt - csound->tokenstring); - } - csound->tokenstring = tt; /* Reset string and length */ - csound->toklen = (int32) newLen; - csound->stringend = csound->tokenstring + csound->toklen; - /* if (UNLIKELY(newLen != (size_t) 128)) */ - /* csound->Message(csound, Str("Token length extended to %ld\n"), */ - /* csound->toklen); */ - return &(csound->tokenstring[len]); -} - -int express(CSOUND *csound, char *s) -{ - POLISH *pp; - char xprmsg[128]; - char b, c, d, e, nextc, *t, *op, outype = '\0', *sorig; - int open, prec, polcnt, argcnt; - int argcnt_max = 0; - - if (*s == '"') /* if quoted string, not an exprssion */ - return (0); - if (UNLIKELY(csound->tokens == NULL)) { - csound->tokens = (TOKEN*) mmalloc(csound, TOKMAX * sizeof(TOKEN)); - csound->tokend = csound->tokens + TOKMAX; - csound->tokenlist = (TOKEN**) mmalloc(csound, TOKMAX * sizeof(TOKEN*)); - csound->polish = (POLISH*) mmalloc(csound, POLMAX * sizeof(POLISH)); - csound->polmax = POLMAX; - csound->tokenstring = NULL; - csound->stringend = NULL; - csound->toklen = 0L; - } - sorig = s; - if (UNLIKELY(strlen(s) >= (size_t) csound->toklen)) - extend_tokenstring(csound, strlen(s)); - - csound->token = csound->tokens; - csound->token->str = t = csound->tokenstring; - open = 1; - while ((c = *s++)) { - if (open) { /* if unary possible here, */ - if (c == '+') /* look for signs: */ - continue; - if (c == '-') { /* neg const: get past sign */ - /* the check for 'd' is for correctly parsing "-0dbfs" */ - if (*s == '.' || (*s >= '0' && *s <= '9' && s[1] != 'd')) - *t++ = c; - else { /* neg symbol: prv / illegal */ - if (UNLIKELY(csound->token > csound->tokens && - *(csound->token-1)->str == '/')) - XERROR(Str("divide by unary minus")) - csound->token->str = (char*) strminus1; csound->token++; - csound->token->str = (char*) strmult; csound->token++; - csound->token->str = t; /* else -1 * symbol */ - } - c = *s++; /* beg rem of token */ - } - else if (UNLIKELY(c == '*' || c == '/' || c == '%')) /* unary mlt, div */ - XERROR(Str("unary mult or divide")) /* illegal */ - open = 0; - } - *t++ = c; /* copy this character or */ - if (((nextc = *s) == c && (c == '&' || c == '|')) || /* double op */ - (nextc == '=' && (c=='<' || c=='>' || c=='=' || c=='!'))) { - *t++ = c = *s++; - open = 1; - } - else if (nextc == c && (c == '<' || c == '>')) { - *(t - 1) = (char) (c == '<' ? BITSHL : BITSHR); - s++; open = 1; - } - /* Would it be better to use strchr("(+-*%/><=&|?:#~\254",c)!=NULL ? */ - else if (c == '(' || c == '+' || c == '-' || c == '*' || c == '/' || - c == '%' || c == '>' || c == '<' || c == '=' || c == '&' || - c == '|' || c == '?' || c == ':' || c == '#' || c == '\254' || - c == '~') { - if (c == '&') *(t-1) = BITCLR; - else if (c == '|') *(t-1) = BITSET; - else if (c == '#') *(t-1) = BITFLP; - open = 1; /* decl if unary can follow */ - } - else if (nontermin(c)) { /* if not just a termin char */ - if (c == '.' || (c >= '0' && c <= '9')) { - char *tmp = --s; - double tt = strtod(s, &tmp); /* copy constant */ - while (++s < tmp) - *t++ = *s; - /* also copy any trailing characters after a constant, */ - /* which will be a syntax error later (in constndx()) */ - /* for anything other than "0dbfs" */ - } - while (nontermin(*s)) - *t++ = *s++; /* copy entire token */ - } - *t++ = '\0'; /* terminate this token */ - if (t >= csound->stringend) { /* Extend token length as required */ - t = extend_tokenstring(csound, (size_t) (t - csound->tokenstring)); - } - if ((csound->tokend - csound->token) <= 4) { - /* Extend token array and friends */ - int n = csound->token - csound->tokens; - csound->tokens = (TOKEN*) mrealloc(csound, csound->tokens, - (csound->toklength + TOKMAX) - * sizeof(TOKEN)); - csound->tokenlist = (TOKEN**) mrealloc(csound, csound->tokenlist, - (csound->toklength + TOKMAX) - * sizeof(TOKEN*)); - csound->toklength += TOKMAX; - csound->token = csound->tokens + n; - csound->tokend = csound->tokens + csound->toklength; - } - /* IV - Jan 08 2003: check if the output arg of an '=' opcode is */ - /* used in the expression (only if optimisation is enabled) */ - if (csound->opcode_is_assign == 1) - if (!strcmp(csound->token->str, - csound->assign_outarg)) /* if yes, mark as */ - csound->opcode_is_assign = 2; /* dangerous case */ - (++csound->token)->str = t; /* & record begin of nxt one */ - } - csound->token->str = NULL; /* expr end: terminate tokens array */ - if (csound->token - csound->tokens <= 1) /* & return if no expr */ - return(0); - - csound->token = csound->tokens; - while ((s = csound->token->str) != NULL) { /* now for all tokens found, */ - c = *s; - switch ((int) c) { /* IV - Jan 15 2003 */ - /* assign precedence values */ - case ')': prec = 0; break; - case ',': prec = 1; break; - case '?': - case ':': prec = 2; break; - case '|': prec = 3; break; - case '&': prec = 4; break; - case '<': - case '=': - case '>': - case '!': prec = 5; break; - case BITSET: prec = 6; break; - case BITFLP: prec = 7; break; - case BITCLR: prec = 8; break; - case BITSHL: - case BITSHR: prec = 9; break; - case '+': - case '-': prec = (s[1] == '\0' ? 10 : 18); break; - case '*': - case '/': - case '%': prec = 11; break; - case '^': prec = 12; break; - case '~': - case '\254': prec = 13; break; - case '(': prec = 15; break; - default: - if (((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) && - (t = (csound->token + 1)->str) != NULL && *t == '(') { - prec = 14; /* function call */ - } - else { - c = argtyp(csound, s); - /* terms: precedence depends on type (a < k < i) */ - if (c == 'a') prec = 16; - else if (c == 'k') prec = 17; - else prec = 18; - } - break; - } - (csound->token++)->prec = prec; - } - if (csound->oparms->odebug) putokens(csound); - -#define CONDVAL 2 -#define LOGOPS 3 -#define RELOPS 5 -#define BITOPS 6 -#define AOPS 10 -#define BITNOT 13 -#define FCALL 14 -#define TERMS 16 - - csound->token = csound->tokens; - csound->revp = csound->tokenlist; - csound->pushp = csound->endlist = csound->tokenlist + csound->toklength; - /* using precedence vals, */ - while (csound->token->str != NULL) { /* put tokens rev pol order */ - if (*csound->token->str == '(') { - csound->token->prec = -1; - *--csound->pushp = csound->token++; - } - else if (csound->pushp < csound->endlist && - (*csound->pushp)->prec >= csound->token->prec) { - if (*csound->token->str == ':' && *(*csound->pushp)->str == '?') - *csound->pushp = csound->token++; /* replace ? with : */ - else *csound->revp++ = *csound->pushp++; - } - else if (*csound->token->str == ')') { - if (csound->token++ && *(*csound->pushp++)->str != '(') - XERROR(Str("within parens")) - } - else if ((csound->token + 1)->str != NULL && - csound->token->prec < (csound->token + 1)->prec) - *--csound->pushp = csound->token++; - else *csound->revp++ = csound->token++; - } - while (csound->pushp < csound->endlist) - *csound->revp++ = *csound->pushp++; - - csound->endlist = csound->revp; /* count of pol operators */ - if (csound->oparms->odebug) putoklist(csound); - for (csound->revp = csound->tokenlist, polcnt = 0; - csound->revp < csound->endlist; ) - if ((*csound->revp++)->prec < TERMS) /* is no w. prec < TERMS */ - polcnt++; - if (!polcnt) { /* if no real operators, */ - strcpy(csound->tokenstring, - csound->tokenlist[0]->str); /* cpy arg to beg str */ - return(-1); /* and return this info */ - } - if (polcnt >= csound->polmax) { - csound->polmax = polcnt + POLMAX; - csound->polish = (POLISH*) mrealloc(csound, csound->polish, - csound->polmax * sizeof(POLISH)); - } - pp = &(csound->polish[polcnt - 1]); - op = pp->opcod; - for (csound->revp = csound->argp = csound->tokenlist; - csound->revp < csound->endlist; ) { /* for all tokens: */ - char buffer[1024]; - if ((prec = (*csound->revp)->prec) >= TERMS) { - *csound->argp++ = *csound->revp++; /* arg: push back */ - continue; /* till later */ - } - argcnt = csound->argp - csound->tokenlist; - if (prec == FCALL && argcnt >= 1) { /* function call: */ - pp->incount = 1; /* takes one arg */ - pp->arg[1] = copystring((*--csound->argp)->str); - c = argtyp(csound, pp->arg[1]); /* whose aki type */ - if (c == 'B' || c == 'b') - XERROR(Str("misplaced relational op")) - if (c != 'a' && c != 'k') - c = 'i'; /* (simplified) */ - sprintf(op, "%s.%c", (*csound->revp)->str, c); /* Type at end now */ - if (strcmp(op,"i.k") == 0) { - outype = 'i'; /* i(karg) is irreg. */ - if (UNLIKELY(pp->arg[1][0] == '#' && pp->arg[1][1] == 'k')) { - /* IV - Jan 15 2003: input arg should not be a k-rate expression */ - if (csound->oparms->expr_opt) { - XERROR(Str("i() with expression argument not " - "allowed with --expression-opt")); - } - else { - csound->Message(csound, - Str("WARNING: i() should not be used with " - "expression argument\n")); - } - } - } - else if (strcmp(op,"a.k") == 0) /* a(karg) is irreg. */ - outype = 'a'; - else if (strcmp(op,"k.i") == 0) /* k(iarg) is irreg. */ - outype = 'K'; /* K-type is k-rate assigned at i-time only */ - else outype = c; /* else outype=intype */ - } - else if (prec >= BITOPS && prec < AOPS && argcnt >= 2) { /* bit op: */ - c = *(*csound->revp)->str; - switch (c) { - case BITSHL: strcpy(op, "shl"); break; - case BITSHR: strcpy(op, "shr"); break; - case BITSET: strcpy(op, "or"); break; - case BITFLP: strcpy(op, "xor"); break; - case BITCLR: strcpy(op, "and"); break; - default: csound->Message(csound, Str("Expression got lost\n")); - } - goto common_ops; - } - else if (prec == BITNOT && argcnt == 1) { /* bit op: */ - c = *(*csound->revp)->str; - pp->incount = 1; /* copy 1 arg txts */ - pp->arg[1] = copystring((*--csound->argp)->str); - e = argtyp(csound, pp->arg[1]); - if (UNLIKELY(e == 'B' || e == 'b')) - XERROR(Str("misplaced relational op")); - if (LIKELY(c == '\254' || c == '~')) { - strcpy(op, "not"); /* to complete optxt */ - switch (e) { - case 'a': strncat(op, ".a", 12); outype = 'a'; break; - case 'k': strncat(op, ".k", 12); outype = 'k'; break; - default: strncat(op, ".i", 12); outype = 'i'; break; - } - } - else - csound->Message(csound, Str("Expression got lost\n")); - } - else if (prec >= AOPS && prec < BITNOT && argcnt >= 2) { /* arith op: */ - c = *(*csound->revp)->str; - switch (c) { /* create op text */ - case '+': strncpy(op, "add", 12); break; - case '-': strncpy(op, "sub", 12); break; - case '*': strncpy(op, "mul", 12); break; - case '/': strncpy(op, "div", 12); break; - case '%': strncpy(op, "mod", 12); break; - case '^': strncpy(op, "pow", 12); break; - default: csound->Message(csound, Str("Expression got lost\n")); - } - common_ops: - pp->incount = 2; /* copy 2 arg txts */ - pp->arg[2] = copystring((*--csound->argp)->str); - pp->arg[1] = copystring((*--csound->argp)->str); - e = argtyp(csound, pp->arg[1]); - d = argtyp(csound, pp->arg[2]); /* now use argtyps */ - if (UNLIKELY(e == 'B' || e == 'b' || d == 'B' || d == 'b' )) - XERROR(Str("misplaced relational op")) -/* csound->Message(csound, "op=%s e=%c c=%c d=%c\n", op, e, c, d); */ - if (e == 'a') { /* to complet optxt*/ - if (c=='^' && (d == 'c' || d == 'k'|| d == 'i' || d == 'p')) - strncat(op,".a",12); - else if (d == 'a') strncat(op,".aa",12); - else strncat(op,".ak",12); - outype = 'a'; - } - else if (d == 'a') { - strncat(op,".ka",12); - outype = 'a'; - } - else if (e == 'k' || d == 'k') { - if (c == '^') strncat(op,".k",12); - else strncat(op,".kk",12); - outype = 'k'; - } - else { - if (c == '^') strncat(op,".i",12); - else strncat(op,".ii",12); - outype = 'i'; - } - } - else if (prec == RELOPS && argcnt >= 2) { /* relationals: */ - strncpy(op, (*csound->revp)->str, 12); /* copy rel op */ - if (strcmp(op, "=") == 0) - strncpy(op, "==", 12); - pp->incount = 2; /* & 2 arg txts */ - pp->arg[2] = copystring((*--csound->argp)->str); - pp->arg[1] = copystring((*--csound->argp)->str); - c = argtyp(csound, pp->arg[1]); - d = argtyp(csound, pp->arg[2]); /* now use argtyps */ - if (UNLIKELY(c == 'a' || d == 'a')) /* to determ outs */ - XERROR(Str("audio relational")) - if (UNLIKELY(c == 'B' || c == 'b' || d == 'B' || d == 'b' )) - XERROR(Str("misplaced relational op")) - if (c == 'k' || d == 'k') - outype = 'B'; - else outype = 'b'; - } - else if (prec >= LOGOPS && prec < RELOPS && argcnt >= 2) { /* logicals: */ - strncpy(op, (*csound->revp)->str, 12); /* copy rel op */ - pp->incount = 2; /* & 2 arg txts */ - pp->arg[2] = copystring((*--csound->argp)->str); - pp->arg[1] = copystring((*--csound->argp)->str); - c = argtyp(csound, pp->arg[1]); - d = argtyp(csound, pp->arg[2]); /* now use argtyps */ - if (c == 'b' && d == 'b') /* to determ outs */ - outype = 'b'; - else if ((c == 'B' || c == 'b') && - (d == 'B' || d == 'b')) - outype = 'B'; - else XERROR(Str("incorrect logical arguments")) - } - else if (prec == CONDVAL && argcnt >= 3) { /* cond vals: */ - strncpy(op, ": ", 12); /* init op as ': ' */ - pp->incount = 3; /* & cpy 3 argtxts */ - pp->arg[3] = copystring((*--csound->argp)->str); - pp->arg[2] = copystring((*--csound->argp)->str); - pp->arg[1] = copystring((*--csound->argp)->str); - b = argtyp(csound, pp->arg[1]); - c = argtyp(csound, pp->arg[2]); - d = argtyp(csound, pp->arg[3]); - if (UNLIKELY((b != 'B' && b != 'b') || /* chk argtypes, */ - c == 'B' || c == 'b' || d == 'B' || d == 'b' || - (c == 'a' && d != 'a') || (d == 'a' && c != 'a'))) - XERROR(Str("incorrect cond value format")) - outype = 'i'; /* determine outyp */ - if (b == 'B' || c == 'k' || d == 'k') - outype = 'k'; - if (c == 'a' || d == 'a') - outype = 'a'; - *(op+1) = outype; /* & complet opcod */ - } - else XERROR(Str("insufficient terms")) - s = &buffer[0] /* pp->arg[0] */; /* now create outarg acc. to type */ - if (!csound->oparms->expr_opt) { - /* IV - Jan 08 2003: old code: should work ... */ - /* Should use snprintf for safety */ - switch (outype) { - case 'a': sprintf(s, "#a%d", csound->acount++); break; - case 'K': - case 'k': sprintf(s, "#k%d", csound->kcount++); break; - case 'B': sprintf(s, "#B%d", csound->Bcount++); break; - case 'b': sprintf(s, "#b%d", csound->bcount++); break; - default: sprintf(s, "#i%d", csound->icount++); break; - } - } - else { - int ndx = (int) (csound->argp - csound->tokenlist); /* argstack index */ - if (csound->opcode_is_assign == 1 && - (int) ndx == 0 && - (int) outype == csound->assign_type && - strchr("aki", csound->assign_type) != NULL) { - /* IV - Jan 08 2003: if the expression is an input arg to the '=' */ - /* opcode, the output type is appropriate, and the argument stack */ - /* is empty, there is no need for a temporary variable, */ - /* instead just use the opcode outarg */ - strncpy(s, csound->assign_outarg, 1024); - /* note: this is not safe if the expression contains the output */ - /* variable; if that is the case, opcode_is_assign is set to 2 */ - } - else { - int cnt = ndx; - /* IV - Jan 08 2003: make optimal use of temporary variables by */ - /* using the argstack pointer as index. This is not reliable with */ - /* i-rate variables, so we limit the optimisation to a- and k-rate */ - /* operations only. */ - /* If there are multiple expressions on the same line, use */ - /* different indexes for the tmp variables of each expression. */ -/* if (!cnt) */ - cnt += csound->argcnt_offs; /* IV - Jan 15 2003 */ - switch (outype) { - case 'a': sprintf(s, "#a%d", cnt); break; - case 'K': sprintf(s, "#k_%d", csound->kcount++); break; - case 'k': sprintf(s, "#k%d", cnt); break; - case 'B': sprintf(s, "#B%d", csound->Bcount++); break; - case 'b': sprintf(s, "#b%d", csound->bcount++); break; - default: sprintf(s, "#i%d", csound->icount++); break; - } - /* IV - Jan 08 2003: count max. stack depth in order to allow */ - /* generating different indexes for temporary variables of */ - /* separate expressions on the same line (see also below). */ - /* N.B. argcnt_offs is reset in rdorch.c when a new line is read. */ - if (ndx > argcnt_max) argcnt_max = ndx; - } - } - /* & point argstack there */ - (*csound->argp++)->str = pp->arg[0] = copystring(s); - csound->revp++; - pp--; op = pp->opcod; /* prep for nxt pol */ - } - if (csound->argp - csound->tokenlist == 1) { - /* IV - Jan 08 2003: do not re-use temporary variables between */ - /* expressions of the same line */ - csound->argcnt_offs += (argcnt_max + 1); - /* if wrote to output arg of '=' last time, '=' can be omitted */ - if (csound->opcode_is_assign != 0 && /* only if optimising */ - (int) outype == csound->assign_type && - strchr("aki", csound->assign_type) != NULL) { - /* replace outarg if necessary */ - if (strcmp(csound->tokenlist[0]->str, csound->assign_outarg)) { - /* now the last op will use the output of '=' directly */ - /* the pp + 1 is because of the last pp-- */ - csound->tokenlist[0]->str = - (pp + 1)->arg[0] = copystring(csound->assign_outarg); - } - /* mark as optimised away */ - csound->opcode_is_assign = -1; - } - return(polcnt); /* finally, return w. polcnt */ - } - XERROR(Str("term count")) - - error: - synterr(csound, Str("expression syntax")); /* or gracefully report error*/ - csound->Message(csound, " %s: %s\n", xprmsg, sorig); - strcpy(csound->tokenstring, "1"); - return -1; -} - -static int nontermin(int c) -{ - switch (c) { - case '(': - case ')': - case '\0': - case '^': - case '+': - case '-': - case '*': - case '/': - case '%': - case '>': - case '<': - case '=': - case '!': - case '&': - case '|': - case '#': - case '\254': - case '~': - case '?': - case ':': - return 0; - default: - return 1; - } -} - -static void putokens(CSOUND *csound) /* for debugging check only */ -{ - TOKEN *tp = csound->tokens; - - while (tp->str != NULL) { - if (tp->str[0] != '\0' && tp->str[1] == '\0') { - switch (tp->str[0]) { - case BITSHL: csound->Message(csound, "<<\t"); break; - case BITSHR: csound->Message(csound, ">>\t"); break; - case BITCLR: csound->Message(csound, "&\t"); break; - case BITFLP: csound->Message(csound, "#\t"); break; - case BITSET: csound->Message(csound, "|\t"); break; - default: csound->Message(csound, "%s\t", tp->str); - } - } - else - csound->Message(csound, "%s\t", tp->str); - tp++; - } - csound->Message(csound, "\n"); -} - -static void putoklist(CSOUND *csound) /* ditto */ -{ - TOKEN **tpp = csound->tokenlist; - - while (tpp < csound->endlist) { - if ((*tpp)->str[0] != '\0' && (*tpp)->str[1] == '\0') { - switch ((*tpp)->str[0]) { - case BITSHL: csound->Message(csound, "<<\t"); break; - case BITSHR: csound->Message(csound, ">>\t"); break; - case BITCLR: csound->Message(csound, "&\t"); break; - case BITFLP: csound->Message(csound, "#\t"); break; - case BITSET: csound->Message(csound, "|\t"); break; - default: csound->Message(csound, "%s\t", (*tpp)->str); - } - } - else - csound->Message(csound, "%s\t", (*tpp)->str); - tpp++; - } - csound->Message(csound, "\n"); -} - diff -Nru csound-5.17.11~dfsg/Engine/extract.c csound-6.02~dfsg/Engine/extract.c --- csound-5.17.11~dfsg/Engine/extract.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/extract.c 2014-01-07 16:54:20.000000000 +0000 @@ -23,27 +23,14 @@ #include "csoundCore.h" #include "sysdep.h" /* EXTRACT.C */ - -#define INSMAX 4096 +#include "extract.h" extern int realtset(CSOUND *, SRTBLK *); extern MYFLT realt(CSOUND *, MYFLT); -static void include(CSOUND *, SRTBLK *); - -typedef struct { - char inslst[INSMAX]; /* values set by readxfil */ - int sectno, a0done; - int onsect, offsect; /* " " " */ - MYFLT onbeat, offbeat; /* " " " */ - MYFLT ontime, offtime; /* set by readxfil, mod by w-stmnt */ - SRTBLK *frstout, *prvout; /* links for building new outlist */ - SRTBLK a0; - SRTBLK f0; - SRTBLK e; -} EXTRACT_GLOBALS; +static void include(CSOUND *, EXTRACT_STATICS*, SRTBLK *); -#define ST(x) (((EXTRACT_GLOBALS*) ((CSOUND*) csound)->extractGlobals)->x) +#define STA(x) (extractStatics->x) static const SRTBLK a0 = { NULL, NULL, 0, 3, FL(0.0), FL(0.0), FL(0.0), FL(0.0), FL(0.0), @@ -60,29 +47,31 @@ 0, SP, "e\n" }; -static void alloc_globals(CSOUND *csound) +static void alloc_globals(CSOUND *csound, EXTRACT_STATICS* extractStatics) { - if (csound->extractGlobals == NULL) { - csound->extractGlobals = csound->Calloc(csound, sizeof(EXTRACT_GLOBALS)); - ST(onbeat) = ST(offbeat) = FL(0.0); - ST(ontime) = ST(offtime) = FL(0.0); - memcpy(&ST(a0), &a0, sizeof(SRTBLK)); - memcpy(&ST(f0), &f0, sizeof(SRTBLK)); - memcpy(&ST(e), &e, sizeof(SRTBLK)); - } +/* if (csound->extractGlobals == NULL) { */ +/* csound->extractGlobals = csound->Calloc(csound, sizeof(EXTRACT_GLOBALS)); */ + /* STA(onbeat) = STA(offbeat) = FL(0.0); */ + /* STA(ontime) = STA(offtime) = FL(0.0); */ + memcpy(&STA(a0), &a0, sizeof(SRTBLK)); + memcpy(&STA(f0), &f0, sizeof(SRTBLK)); + memcpy(&STA(e), &e, sizeof(SRTBLK)); + /* } */ } -void readxfil(CSOUND *csound, FILE *xfp) /* read the extract control file */ +void readxfil(CSOUND *csound, EXTRACT_STATICS* extractStatics, + FILE *xfp) /* read the extract control file */ { int flag, all; char s[82]; - alloc_globals(csound); + alloc_globals(csound, extractStatics); all = 1; flag = 'i'; /* default -i flag supplied */ - ST(onsect) = 1; ST(onbeat) = FL(0.0); /* other default vals */ - ST(offsect) = 999; ST(offbeat) = FL(0.0); - while (fscanf(xfp, "%s", s) != EOF) { + STA(onsect) = 1; STA(onbeat) = FL(0.0); /* other default vals */ + STA(offsect) = 999; STA(offbeat) = FL(0.0); + // while (fscanf(xfp, s) != EOF) { + while (fgets(s, 82, xfp) != NULL) { char *c = s; int i; switch (*c) { @@ -96,61 +85,62 @@ switch (flag) { case 'i': sscanf(s, "%d", &i); - ST(inslst)[i] = 1; + STA(inslst)[i] = 1; all = 0; break; case 'f': #if defined(USE_DOUBLE) - sscanf(s, "%d:%lf", &ST(onsect), &ST(onbeat)); + CS_SSCANF(s, "%d:%lf", &STA(onsect), &STA(onbeat)); #else - sscanf(s, "%d:%f", &ST(onsect), &ST(onbeat)); + CS_SSCANF(s, "%d:%f", &STA(onsect), &STA(onbeat)); #endif break; case 't': - ST(offsect) = ST(onsect); /* default offsect */ + STA(offsect) = STA(onsect); /* default offsect */ #if defined(USE_DOUBLE) - sscanf(s, "%d:%lf", &ST(offsect), &ST(offbeat)); + CS_SSCANF(s, "%d:%lf", &STA(offsect), &STA(offbeat)); #else - sscanf(s, "%d:%f", &ST(offsect), &ST(offbeat)); + CS_SSCANF(s, "%d:%f", &STA(offsect), &STA(offbeat)); #endif } } } if (all) { char *ip; - for (ip = &ST(inslst)[0]; ip < &ST(inslst)[INSMAX]; *ip++ = 1); + for (ip = &STA(inslst)[0]; ip < &STA(inslst)[INSMAX]; *ip++ = 1); } - ST(ontime) = ST(a0).newp3 = ST(a0).p3val = ST(onbeat); - ST(offtime) = ST(f0).newp2 = ST(f0).p2val = ST(offbeat); + STA(ontime) = STA(a0).newp3 = STA(a0).p3val = STA(onbeat); + STA(offtime) = STA(f0).newp2 = STA(f0).p2val = STA(offbeat); } -void extract(CSOUND *csound) /* extract instr events within the time period */ +void extract(CSOUND *csound, EXTRACT_STATICS* extractStatics) + /* extract instr events within the time period */ { SRTBLK *bp; MYFLT turnoff, anticip; int warped; - alloc_globals(csound); + alloc_globals(csound, extractStatics); if ((bp = csound->frstbp) == NULL) /* if null file */ return; - if (++ST(sectno) > ST(offsect)) { /* or later section, */ + if (++STA(sectno) > STA(offsect)) { /* or later section, */ csound->frstbp = NULL; return; /* return */ } - ST(frstout) = ST(prvout) = NULL; - if (ST(sectno) < ST(onsect)) { /* for sects preceding, */ + STA(frstout) = STA(prvout) = NULL; + if (STA(sectno) < STA(onsect)) { /* for sects preceding, */ do { switch (bp->text[0]) { case 'f': /* include f's at time 0 */ bp->p2val = bp->newp2 = FL(1.0); /* time 1 for now!! */ - include(csound, bp); + include(csound, extractStatics, bp); break; case 'w': case 's': case 'e': - include(csound, bp); /* incl w,s,e verbatim */ + include(csound, extractStatics, bp); /* incl w,s,e verbatim */ break; case 't': case 'i': @@ -164,83 +154,83 @@ switch(bp->text[0]) { case 'w': warped = realtset(csound, bp); - if (ST(sectno) == ST(onsect) && warped) - ST(ontime) = ST(a0).newp3 = realt(csound, ST(onbeat)); - if (ST(sectno) == ST(offsect) && warped) - ST(offtime) = ST(f0).newp2 = realt(csound, ST(offbeat)); - include(csound, bp); + if (STA(sectno) == STA(onsect) && warped) + STA(ontime) = STA(a0).newp3 = realt(csound, STA(onbeat)); + if (STA(sectno) == STA(offsect) && warped) + STA(offtime) = STA(f0).newp2 = realt(csound, STA(offbeat)); + include(csound, extractStatics, bp); break; case 't': - include(csound, bp); + include(csound, extractStatics, bp); break; case 'f': - casef: if (ST(sectno) == ST(onsect) && bp->newp2 < ST(ontime)) - bp->newp2 = ST(ontime); - else if (ST(sectno) == ST(offsect) && bp->newp2 > ST(offtime)) - break; - if (ST(sectno) == ST(onsect) && !ST(a0done)) { - if (ST(onbeat) > 0) - include(csound, &ST(a0)); - ST(a0done)++; + casef: if (STA(sectno) == STA(onsect) && bp->newp2 < STA(ontime)) + bp->newp2 = STA(ontime); + else if (STA(sectno) == STA(offsect) && bp->newp2 > STA(offtime)) + break; + if (STA(sectno) == STA(onsect) && !STA(a0done)) { + if (STA(onbeat) > 0) + include(csound, extractStatics, &STA(a0)); + STA(a0done)++; } - include(csound, bp); + include(csound, extractStatics, bp); break; case 'i': - if (!ST(inslst)[bp->insno]) /* skip insnos not required */ + if (!STA(inslst)[bp->insno]) /* skip insnos not required */ break; if (bp->newp3 < 0) /* treat indef dur like f */ goto casef; case 'a':turnoff = bp->newp2 + bp->newp3; /* i and a: */ - if (ST(sectno) == ST(onsect)) { - if (turnoff < ST(ontime)) + if (STA(sectno) == STA(onsect)) { + if (turnoff < STA(ontime)) break; - if ((anticip = ST(ontime) - bp->newp2) > 0) { + if ((anticip = STA(ontime) - bp->newp2) > 0) { if ((bp->newp3 -= anticip) < FL(0.001)) break; - bp->p3val -= ST(onbeat) - bp->p2val; - bp->newp2 = ST(ontime); - bp->p2val = ST(onbeat); + bp->p3val -= STA(onbeat) - bp->p2val; + bp->newp2 = STA(ontime); + bp->p2val = STA(onbeat); } } - if (ST(sectno) == ST(offsect)) { - if (bp->newp2 >= ST(offtime)) + if (STA(sectno) == STA(offsect)) { + if (bp->newp2 >= STA(offtime)) break; - if (turnoff > ST(offtime)) { - bp->newp3 = ST(offtime) - bp->newp2; - bp->p3val = ST(offbeat) - bp->p2val; + if (turnoff > STA(offtime)) { + bp->newp3 = STA(offtime) - bp->newp2; + bp->p3val = STA(offbeat) - bp->p2val; } } - if (ST(sectno) == ST(onsect) && !ST(a0done)) { - if (ST(onbeat) > 0) - include(csound, &ST(a0)); - ST(a0done)++; + if (STA(sectno) == STA(onsect) && !STA(a0done)) { + if (STA(onbeat) > 0) + include(csound, extractStatics, &STA(a0)); + STA(a0done)++; } - include(csound, bp); + include(csound, extractStatics, bp); break; case 's': case 'e': - if (ST(sectno) == ST(offsect)) { - include(csound, &ST(f0)); - include(csound, &ST(e)); + if (STA(sectno) == STA(offsect)) { + include(csound, extractStatics, &STA(f0)); + include(csound, extractStatics, &STA(e)); } - else include(csound, bp); + else include(csound, extractStatics, bp); break; } } while ((bp = bp->nxtblk) != NULL); } - csound->frstbp = ST(frstout); - if (ST(prvout) != NULL) - ST(prvout)->nxtblk = NULL; + csound->frstbp = STA(frstout); + if (STA(prvout) != NULL) + STA(prvout)->nxtblk = NULL; } /* wire a srtblk into the outlist */ -static void include(CSOUND *csound, SRTBLK *bp) +static void include(CSOUND *csound, EXTRACT_STATICS* extractStatics, SRTBLK *bp) { - if (ST(frstout) == NULL) /* first one is special */ - ST(frstout) = bp; - else ST(prvout)->nxtblk = bp; /* others just add onto list */ - bp->prvblk = ST(prvout); /* maintain the backptr */ - ST(prvout) = bp; /* and get ready for next */ + if (STA(frstout) == NULL) /* first one is special */ + STA(frstout) = bp; + else STA(prvout)->nxtblk = bp; /* others just add onto list */ + bp->prvblk = STA(prvout); /* maintain the backptr */ + STA(prvout) = bp; /* and get ready for next */ } diff -Nru csound-5.17.11~dfsg/Engine/fgens.c csound-6.02~dfsg/Engine/fgens.c --- csound-5.17.11~dfsg/Engine/fgens.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/fgens.c 2014-01-07 16:54:20.000000000 +0000 @@ -36,8 +36,6 @@ extern double besseli(double); -/* Start of moving static data into a single structure */ - static int gen01raw(FGDATA *, FUNC *); static int gen01(FGDATA *, FUNC *), gen02(FGDATA *, FUNC *); static int gen03(FGDATA *, FUNC *), gen04(FGDATA *, FUNC *); @@ -61,7 +59,9 @@ static int gen51(FGDATA *, FUNC *), gen52(FGDATA *, FUNC *); static int gen53(FGDATA *, FUNC *); static int GENUL(FGDATA *, FUNC *); +#ifndef NACL static int gen49(FGDATA *, FUNC *); +#endif static const GEN or_sub[GENMAX + 1] = { GENUL, @@ -69,7 +69,13 @@ gen11, gen12, gen13, gen14, gen15, gen16, gen17, gen18, gen19, gen20, gen21, GENUL, gen23, gen24, gen25, GENUL, gen27, gen28, GENUL, gen30, gen31, gen32, gen33, gen34, GENUL, GENUL, GENUL, GENUL, GENUL, gen40, - gen41, gen42, gen43, GENUL, GENUL, GENUL, GENUL, GENUL, gen49, GENUL, + gen41, gen42, gen43, GENUL, GENUL, GENUL, GENUL, GENUL, +#ifndef NACL + gen49, +#else + GENUL, +#endif + GENUL, gen51, gen52, gen53, GENUL, GENUL, GENUL, GENUL, GENUL, GENUL, GENUL }; @@ -81,6 +87,8 @@ #define tpd360 (FL(0.0174532925199433)) +#define FTAB_SEARCH_BASE (100) + static CS_NOINLINE int fterror(const FGDATA *, const char *, ...); static CS_NOINLINE void ftresdisp(const FGDATA *, FUNC *); static CS_NOINLINE FUNC *ftalloc(const FGDATA *); @@ -120,7 +128,7 @@ if (!ff.fno) { if (!mode) return 0; /* fno = 0: return, */ - ff.fno = csound->ftldno; + ff.fno = FTAB_SEARCH_BASE; do { /* or automatic number */ ++ff.fno; } while (ff.fno <= csound->maxfnum && csound->flist[ff.fno] != NULL); @@ -135,7 +143,7 @@ csound->flist[ff.fno] = NULL; mfree(csound, (void*) ftp); if (UNLIKELY(msg_enabled)) - csound->Message(csound, Str("ftable %d now deleted\n"), ff.fno); + csoundMessage(csound, Str("ftable %d now deleted\n"), ff.fno); return 0; } if (UNLIKELY(ff.fno > csound->maxfnum)) { /* extend list if necessary */ @@ -165,7 +173,7 @@ else memcpy(&(ff.e.p[2]), &(evtblkp->p[2]), sizeof(MYFLT) * ((int) ff.e.pcnt - 1)); - if ((genum = (int32) MYFLT2LRND(ff.e.p[4])) == SSTRCOD) { + if (ISSTRCOD(ff.e.p[4])) { /* A named gen given so search the list of extra gens */ NAMEDGEN *n = (NAMEDGEN*) csound->namedgen; while (n) { @@ -180,6 +188,7 @@ } } else { + genum = (int32) MYFLT2LRND(ff.e.p[4]); if (genum < 0) genum = -genum; if (UNLIKELY(!genum || genum > csound->genmax)) { /* & legal gen number x*/ @@ -194,7 +203,7 @@ return fterror(&ff, Str("deferred size for GENs 1, 23, 28 or 49 only")); } if (msg_enabled) - csound->Message(csound, Str("ftable %d:\n"), ff.fno); + csoundMessage(csound, Str("ftable %d:\n"), ff.fno); i = (*csound->gensub[genum])(&ff, NULL); ftp = csound->flist[ff.fno]; if (i != 0) { @@ -225,8 +234,12 @@ (ltest & MAXLEN) == 0L; lobits++, ltest <<= 1) ; - if (UNLIKELY(ltest != MAXLEN)) { /* flen must be power-of-2 */ - return fterror(&ff, Str("illegal table length")); + if (UNLIKELY(ltest != MAXLEN)) { /* flen is not power-of-2 */ + // return fterror(&ff, Str("illegal table length")); + //csound->Warning(csound, Str("table %d size not power of two"), ff.fno); + lobits = 0; + nonpowof2_flag = 1; + ff.guardreq = 1; } } ftp = ftalloc(&ff); /* alloc ftable space now */ @@ -242,7 +255,7 @@ ftp->lenmask = 0xFFFFFFFF; /* gab: fixed for non-powoftwo function tables */ if (msg_enabled) - csound->Message(csound, Str("ftable %d:\n"), ff.fno); + csoundMessage(csound, Str("ftable %d:\n"), ff.fno); if ((*csound->gensub[genum])(&ff, ftp) != 0) { csound->flist[ff.fno] = NULL; mfree(csound, ftp); @@ -278,10 +291,13 @@ csound->maxfnum = size; } /* allocate space for table */ - size = (int) sizeof(FUNC) + (len * (int) sizeof(MYFLT)); + size = (int) (len * (int) sizeof(MYFLT)); ftp = csound->flist[tableNum]; - if (ftp == NULL) - csound->flist[tableNum] = (FUNC*) csound->Malloc(csound, (size_t) size); + if (ftp == NULL) { + csound->flist[tableNum] = (FUNC*) csound->Malloc(csound, sizeof(FUNC)); + csound->flist[tableNum]->ftable = + (MYFLT*)csound->Malloc(csound, sizeof(MYFLT)*(len+1)); + } else if (len != (int) ftp->flen) { if (csound->actanchor.nxtact != NULL) { /* & chk for danger */ /* return */ /* VL: changed this into a Warning */ @@ -295,7 +311,7 @@ } /* initialise table header */ ftp = csound->flist[tableNum]; - memset((void*) ftp, 0, (size_t) ((char*) &(ftp->ftable[0]) - (char*) ftp)); + //memset((void*) ftp, 0, (size_t) ((char*) &(ftp->ftable) - (char*) ftp)); ftp->flen = (int32) len; if (!(len & (len - 1))) { /* for power of two length: */ @@ -322,10 +338,10 @@ { FUNC *ftp; - if ((unsigned int) (tableNum - 1) >= (unsigned int) csound->maxfnum) + if (UNLIKELY((unsigned int) (tableNum - 1) >= (unsigned int) csound->maxfnum)) return -1; ftp = csound->flist[tableNum]; - if (ftp == NULL) + if (UNLIKELY(ftp == NULL)) return -1; csound->flist[tableNum] = NULL; csound->Free(csound, ftp); @@ -409,7 +425,7 @@ } if (!ff->e.p[6]) { srcpts = srcftp->flen; - valp = &srcftp->ftable[0]; + valp = srcftp->ftable; rvalp = NULL; } else { @@ -818,7 +834,7 @@ rtnp1 = rtn * r; if ((absr = FABS(r)) > FL(0.999) && absr < FL(1.001)) scale = FL(1.0) / n; - else scale = (FL(1.0) - absr) / (FL(1.0) - (MYFLT) fabs(rtn)); + else scale = (FL(1.0) - absr) / (FL(1.0) - FABS(rtn)); for (phs = 0; fp <= finp; phs++) { x = (double) phs * tpdlen; numer = (MYFLT)cos(x*k) - r * (MYFLT)cos(x*km1) - rtn*(MYFLT)cos(x*kpn) @@ -873,7 +889,7 @@ MYFLT xamp, xintvl, scalfac, sum, prvm; int nsw = 1; - if (ff->e.pcnt>=PMAX) + if (UNLIKELY(ff->e.pcnt>=PMAX)) csound->Warning(csound, Str("using extended arguments\n")); if (UNLIKELY((nh = ff->e.pcnt - 6) <= 0)) { return fterror(ff, Str("insufficient arguments")); @@ -981,7 +997,7 @@ lp13 = (void*) ftp; ff->fno++; /* alloc eq. space for fno+1 */ ftp = ftalloc(ff); /* & copy header */ - memcpy((void*) ftp, lp13, (size_t) ((char*) ftp->ftable - (char*) ftp)); + memcpy((void*) ftp, lp13, (size_t) sizeof(FUNC)-sizeof(MYFLT*)); ftp->fno = (int32) ff->fno; fp = &ff->e.p[5]; nsw = 1; @@ -998,12 +1014,12 @@ } } nargs--; - ff->e.pcnt = (int16)(nargs + 4); /* added by F. Pinot 16-01-2012 */ + ff->e.pcnt = (int16)(nargs + 4); /* added by F. Pinot 16-01-2012 */ free(hsin); - n = gen14(ff, ftp); /* now draw ftable */ - ftresdisp(ff, ftp); /* added by F. Pinot 16-01-2012 */ - ff->fno--; /* F. Pinot, the first function table */ - /* is scaled and displayed by hfgens */ + n = gen14(ff, ftp); /* now draw ftable */ + ftresdisp(ff, ftp); /* added by F. Pinot 16-01-2012 */ + ff->fno--; /* F. Pinot, the first function table */ + /* is scaled and displayed by hfgens */ return n; } @@ -1123,11 +1139,14 @@ } range = (MYFLT) (finish - start), j = start; - while (j++ <= finish) { /* write the table */ - f = (MYFLT)modf((fnlen*(j-start)/range), &i); - *(fp18 + j) += amp * ((f * (*(fp + (int)(i+1)) - - *(fp + (int)i))) + - *(fp + (int)i)); + while (j <= finish) { /* write the table */ + f = (MYFLT)modf((fnlen*(j++ - start)/range), &i); + if (i==fnp->flen) + fp18[j] += amp * fp[(int)i]; + else + fp18[j] += amp * ((f * (*(fp + (int)(i+1)) - + *(fp + (int)i))) + + *(fp + (int)i)); } } return OK; @@ -1325,8 +1344,12 @@ if (ftp == NULL) { /* Start counting elements */ ff->flen = 0; - while (!feof(infile)) nextval(infile), ff->flen++; - csound->Message(csound, Str("%ld elements in %s\n"), + nextval(infile); + do { + ff->flen++; + nextval(infile); + } while (!feof(infile)); + csoundMessage(csound, Str("%ld elements in %s\n"), ff->flen, ff->e.strarg); rewind(infile); /* Allocate memory and read them in now */ @@ -1529,18 +1552,25 @@ y = (MYFLT*)malloc(arraysize*sizeof(MYFLT)); z = (MYFLT*)malloc(arraysize*sizeof(MYFLT)); #if defined(USE_DOUBLE) - while (fscanf( filp, "%lf%lf%lf", &z[i], &x[i], &y[i])!= EOF) { + while (fscanf( filp, "%lf%lf%lf", &z[i], &x[i], &y[i])!= EOF) #else - while (fscanf( filp, "%f%f%f", &z[i], &x[i], &y[i])!= EOF) { + while (fscanf( filp, "%f%f%f", &z[i], &x[i], &y[i])!= EOF) #endif - i++; - if (i>=arraysize) { - arraysize += 1000; - x = (MYFLT*)realloc(x, arraysize*sizeof(MYFLT)); - y = (MYFLT*)realloc(y, arraysize*sizeof(MYFLT)); - z = (MYFLT*)realloc(z, arraysize*sizeof(MYFLT)); + { + i++; + if (i>=arraysize) { + MYFLT* newx, *newy, *newz; + arraysize += 1000; + newx = (MYFLT*)realloc(x, arraysize*sizeof(MYFLT)); + newy = (MYFLT*)realloc(y, arraysize*sizeof(MYFLT)); + newz = (MYFLT*)realloc(z, arraysize*sizeof(MYFLT)); + if (!newx || !newy || !newz) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + x = newx; y = newy; z = newz; + } } - } --i; ff->flen = (int32) (z[i] * resolution * 2); @@ -1602,11 +1632,11 @@ xsr = FL(1.0); if ((nargs > 3) && (ff->e.p[8] > FL(0.0))) xsr = csound->esr / ff->e.p[8]; - l2 = csound->GetTable(csound, &f2, (int) ff->e.p[5]); + l2 = csoundGetTable(csound, &f2, (int) ff->e.p[5]); if (UNLIKELY(l2 < 0)) { return fterror(ff, Str("GEN30: source ftable not found")); } - f1 = &(ftp->ftable[0]); + f1 = ftp->ftable; l1 = (int) ftp->flen; minfrac = ff->e.p[6]; /* lowest harmonic partial number */ maxfrac = ff->e.p[7] * xsr; /* highest harmonic partial number */ @@ -1685,11 +1715,11 @@ if (UNLIKELY(nargs < 4)) { return fterror(ff, Str("insufficient gen arguments")); } - l2 = csound->GetTable(csound, &f2, (int) ff->e.p[5]); + l2 = csoundGetTable(csound, &f2, (int) ff->e.p[5]); if (UNLIKELY(l2 < 0)) { return fterror(ff, Str("GEN31: source ftable not found")); } - f1 = &(ftp->ftable[0]); + f1 = ftp->ftable; l1 = (int) ftp->flen; x = (MYFLT*) calloc(l2 + 2, sizeof(MYFLT)); @@ -1780,7 +1810,7 @@ } } while (k); - f1 = &(ftp->ftable[0]); + f1 = ftp->ftable; l1 = (int) ftp->flen; memset(f1, 0, l1*sizeof(MYFLT)); /* for (i = 0; i <= l1; i++) */ @@ -1793,7 +1823,7 @@ while (++j < ntabl) { p = paccess(ff,pnum[j]); /* table number */ i = (int) MYFLT2LRND(p); - l2 = csound->GetTable(csound, &f2, abs(i)); + l2 = csoundGetTable(csound, &f2, abs(i)); if (UNLIKELY(l2 < 0)) { fterror(ff, Str("GEN32: source ftable %d not found"), abs(i)); if (x != NULL) free(x); @@ -1887,7 +1917,7 @@ /* table length and data */ ft = ftp->ftable; flen = (int) ftp->flen; /* source table */ - srclen = csound->GetTable(csound, &srcft, (int) ff->e.p[5]); + srclen = csoundGetTable(csound, &srcft, (int) ff->e.p[5]); if (UNLIKELY(srclen < 0)) { return fterror(ff, Str("GEN33: source ftable not found")); } @@ -2159,16 +2189,16 @@ va_start(args, s); csound->ErrMsgV(csound, buf, s, args); va_end(args); - csound->Message(csound, "f%3.0f %8.2f %8.2f ", + csoundMessage(csound, "f%3.0f %8.2f %8.2f ", ff->e.p[1], ff->e.p2orig, ff->e.p3orig); - if (ff->e.p[4] == SSTRCOD) - csound->Message(csound, "%s", ff->e.strarg); + if (ISSTRCOD(ff->e.p[4])) + csoundMessage(csound, ff->e.strarg); else - csound->Message(csound, "%8.2f", ff->e.p[4]); - if (ff->e.p[5] == SSTRCOD) - csound->Message(csound, " \"%s\" ...\n", ff->e.strarg); + csoundMessage(csound, "%8.2f", ff->e.p[4]); + if (ISSTRCOD(ff->e.p[5])) + csoundMessage(csound, " \"%s\" ...\n", ff->e.strarg); else - csound->Message(csound, "%8.2f ...\n", ff->e.p[5]); + csoundMessage(csound, "%8.2f ...\n", ff->e.p[5]); return -1; } @@ -2200,11 +2230,39 @@ return; memset(&dwindow, 0, sizeof(WINDAT)); sprintf(strmsg, Str("ftable %d:"), (int) ff->fno); - dispset(csound, &dwindow, ftp->ftable, (int32) (ff->flen + ff->guardreq), + dispset(csound, &dwindow, ftp->ftable, (int32) (ff->flen), strmsg, 0, "ftable"); display(csound, &dwindow); } +static void generate_sine_tab(CSOUND *csound) +{ /* Assume power of 2 length */ + int flen = csound->sinelength; + FUNC *ftp = (FUNC*) mcalloc(csound, sizeof(FUNC)); + ftp->ftable = (MYFLT*) mcalloc(csound, sizeof(MYFLT)*(flen+1)); + double tpdlen = TWOPI / (double) flen; + MYFLT *ftable = ftp->ftable; + unsigned int i; + int ltest, lobits; + for (ltest = flen, lobits = 0; + (ltest & MAXLEN) == 0L; + lobits++, ltest <<= 1) + ; + ftp->lobits = lobits; + i = (1 << lobits); + ftp->lomask = (int32) (i - 1); + ftp->lodiv = FL(1.0) / (MYFLT) i; /* & other useful vals */ + ftp->flen = ftp->flenfrms = flen; + ftp->fno = -1; + ftp->lenmask = flen - 1; + ftp->nchanls = 1; + for (i = 1; iflen; i++) + ftable[i] = (MYFLT) sin(i*tpdlen); + ftable[0] = ftable[ftp->flen] = FL(0.0); + csound->sinetable = ftp; + return; +} + /* alloc ftable space for fno (or replace one) */ /* set ftp to point to that structure */ @@ -2213,10 +2271,11 @@ CSOUND *csound = ff->csound; FUNC *ftp = csound->flist[ff->fno]; - if (ftp != NULL) { + if (UNLIKELY(ftp != NULL)) { csound->Warning(csound, Str("replacing previous ftable %d"), ff->fno); - if (ff->flen != ftp->flen) { /* if redraw & diff len, */ - mfree(csound, (void*) ftp); /* release old space */ + if (ff->flen != (int32)ftp->flen) { /* if redraw & diff len, */ + mfree(csound, ftp->ftable); + mfree(csound, (void*) ftp); /* release old space */ csound->flist[ff->fno] = ftp = NULL; if (csound->actanchor.nxtact != NULL) { /* & chk for danger */ csound->Warning(csound, Str("ftable %d relocating due to size change" @@ -2225,17 +2284,16 @@ } } else { /* else clear it to zero */ - size_t nBytes = sizeof(FUNC) + (size_t) ff->flen * sizeof(MYFLT); - memset((void*) ftp, 0, nBytes); + memset((void*) ftp->ftable, 0, ff->flen+1); + memset((void*) ftp, 0, sizeof(FUNC)-sizeof(MYFLT*)); /* leaving table! */ } } if (ftp == NULL) { /* alloc space as reqd */ - size_t nBytes = sizeof(FUNC) + (size_t) ff->flen * sizeof(MYFLT); - csound->flist[ff->fno] = ftp = (FUNC*) mcalloc(csound, nBytes); + csound->flist[ff->fno] = ftp = (FUNC*) mcalloc(csound, sizeof(FUNC)); + ftp->ftable = (MYFLT*) mcalloc(csound, (1+ff->flen) * sizeof(MYFLT)); } ftp->fno = (int32) ff->fno; ftp->flen = ff->flen; - return ftp; } @@ -2247,12 +2305,21 @@ FUNC *ftp; int fno; - if (UNLIKELY((fno = (int) *argp) <= 0 || + fno = (int) *argp; + if (UNLIKELY(fno == -1)) { + if (UNLIKELY(csound->sinetable==NULL)) generate_sine_tab(csound); + return csound->sinetable; + } + if (UNLIKELY(fno <= 0 || fno > csound->maxfnum || (ftp = csound->flist[fno]) == NULL)) { csoundInitError(csound, Str("Invalid ftable no. %f"), *argp); return NULL; } + else if (UNLIKELY(ftp->lenmask == -1)) { + csoundInitError(csound, Str("illegal table length")); + return NULL; + } else if (UNLIKELY(!ftp->lenmask)) { csoundInitError(csound, Str("deferred-size ftable %f illegal here"), *argp); @@ -2261,6 +2328,34 @@ return ftp; } +/* find the ptr to an existing ftable structure */ +/* called by oscils, etc at init time */ +/* does not throw an error when a non-pow of two size table is found */ + +FUNC *csoundFTFind2(CSOUND *csound, MYFLT *argp) +{ + FUNC *ftp; + int fno; + + fno = (int) *argp; + if (UNLIKELY(fno == -1)) { + if (UNLIKELY(csound->sinetable==NULL)) generate_sine_tab(csound); + return csound->sinetable; + } + if (UNLIKELY(fno <= 0 || + fno > csound->maxfnum || + (ftp = csound->flist[fno]) == NULL)) { + return NULL; + } + else if (UNLIKELY(ftp->lenmask == -1)) { + return NULL; + } + else if (UNLIKELY(!ftp->lenmask)) { + return NULL; + } + return ftp; +} + /* **** SOMETHING WRONG HERE __ NOT CALLED **** */ static CS_NOINLINE FUNC *gen01_defer_load(CSOUND *csound, int fno) { @@ -2271,6 +2366,7 @@ /* The soundfile hasn't been loaded yet, so call GEN01 */ strcpy(strarg, ftp->gen01args.strarg); memset(&ff, 0, sizeof(FGDATA)); + ff.csound = csound; ff.fno = fno; ff.e.strarg = strarg; ff.e.opcod = 'f'; @@ -2302,7 +2398,7 @@ if (UNLIKELY(ftp == NULL)) goto err_return; } - *tablePtr = &(ftp->ftable[0]); + *tablePtr = ftp->ftable; return (int) ftp->flen; err_return: @@ -2335,16 +2431,21 @@ /* Check limits, and then index directly into the flist[] which * contains pointers to FUNC data structures for each table. */ - if (UNLIKELY((fno = (int) *argp) <= 0 || - fno > csound->maxfnum || + fno = (int) *argp; + if (UNLIKELY(fno == -1)) { + if (UNLIKELY(csound->sinetable==NULL)) generate_sine_tab(csound); + return csound->sinetable; + } + if (UNLIKELY(fno <= 0 || + fno > csound->maxfnum || (ftp = csound->flist[fno]) == NULL)) { - csoundPerfError(csound, Str("Invalid ftable no. %f"), *argp); + csound->ErrorMsg(csound, Str("Invalid ftable no. %f"), *argp); return NULL; } else if (UNLIKELY(!ftp->lenmask)) { /* Now check that the table has a length > 0. This should only * occur for tables which have not been loaded yet. */ - csoundPerfError(csound, Str("Deferred-size ftable %f load " + csound->ErrorMsg(csound, Str("Deferred-size ftable %f load " "not available at perf time."), *argp); return NULL; } @@ -2357,16 +2458,25 @@ FUNC *csoundFTnp2Find(CSOUND *csound, MYFLT *argp) { FUNC *ftp; - int fno; + int fno = (int) *argp; - if (UNLIKELY((fno = (int) *argp) <= 0 || - fno > csound->maxfnum || + if (UNLIKELY(fno == -1)) { + if (UNLIKELY(csound->sinetable==NULL)) generate_sine_tab(csound); + return csound->sinetable; + } + if (UNLIKELY(fno <= 0 || + fno > csound->maxfnum || (ftp = csound->flist[fno]) == NULL)) { csoundInitError(csound, Str("Invalid ftable no. %f"), *argp); return NULL; } if (ftp->flen == 0) { - ftp = gen01_defer_load(csound, fno); + if (LIKELY(csound->oparms->gen01defer)) + ftp = gen01_defer_load(csound, fno); + else { + csoundInitError(csound, Str("Invalid ftable no. %f"), *argp); + return NULL; + } if (UNLIKELY(ftp == NULL)) csound->inerrcnt++; } @@ -2403,7 +2513,7 @@ maxend -= 1; nxtpow = 2; while (maxend >>= 1) nxtpow <<= 1; - csound->Message(csound, Str("non-deferred ftable %d needs size %d\n"), + csoundMessage(csound, Str("non-deferred ftable %d needs size %d\n"), (int) ff->fno, nxtpow); } @@ -2431,7 +2541,7 @@ { int32 filno = (int32) MYFLT2LRND(ff->e.p[5]); int fmt = (int) MYFLT2LRND(ff->e.p[7]); - if (filno == (int32) SSTRCOD) { + if (ISSTRCOD(ff->e.p[5])) { if (ff->e.strarg[0] == '"') { int len = (int) strlen(ff->e.strarg) - 2; strcpy(p->sfname, ff->e.strarg + 1); @@ -2464,7 +2574,7 @@ p->channel = ALLCHNLS; p->analonly = 0; if (UNLIKELY(ff->flen == 0 && (csound->oparms->msglevel & 7))) - csound->Message(csound, Str("deferred alloc\n")); + csoundMessage(csound, Str("deferred alloc\n")); if (UNLIKELY((fd = sndgetset(csound, p))==NULL)) { /* sndinset to open the file */ return fterror(ff, "Failed to open file"); @@ -2475,7 +2585,7 @@ return fterror(ff, Str("deferred size, but filesize unknown")); } if (csound->oparms->msglevel & 7) - csound->Message(csound, Str(" defer length %d\n"), ff->flen - 1); + csoundMessage(csound, Str(" defer length %d\n"), ff->flen - 1); if (p->channel == ALLCHNLS) ff->flen *= p->nchanls; ff->guardreq = 1; /* presum this includes guard */ @@ -2497,7 +2607,6 @@ ftp->flenfrms = ff->flen / p->nchanls; /* ?????????? */ ftp->gen01args.sample_rate = (MYFLT) p->sr; ftp->cvtbas = LOFACT * p->sr * csound->onedsr; -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1013 { SF_INSTRUMENT lpd; int ans = sf_command(fd, SFC_GET_INSTRUMENT, &lpd, sizeof(SF_INSTRUMENT)); @@ -2505,7 +2614,7 @@ double natcps; #ifdef BETA if ((csound->oparms_.msglevel & 7) == 7) { - csound->Message(csound, + csoundMessage(csound, "Base Note : %u\tDetune : %u\n" "Low Note : %u\tHigh Note : %u\n" "Low Vel. : %u\tHigh Vel. : %u\n" @@ -2547,7 +2656,7 @@ Str("GEN1: input file truncated by ftable size")); if ((maxend = ftp->end1) < ftp->end2) maxend = ftp->end2; - csound->Message(csound, + csoundMessage(csound, Str("\tlooping endpoint %d exceeds ftsize %d\n"), maxend, ff->flen); needsiz(csound, ff, maxend); @@ -2561,12 +2670,6 @@ ftp->end1 = ftp->flenfrms; /* Greg Sullivan */ } } -#else - ftp->cpscvt = FL(0.0); - ftp->loopmode1 = 0; - ftp->loopmode2 = 0; - ftp->end1 = ftp->flenfrms; /* Greg Sullivan */ -#endif /* HAVE_LIBSNDFILE >= 1013 */ /* read sound with opt gain */ if (UNLIKELY((inlocs=getsndin(csound, fd, ftp->ftable, table_length, p)) < 0)) { @@ -2583,7 +2686,7 @@ ftp->soundend = inlocs / ftp->nchanls; /* record end of sound samps */ csound->FileClose(csound, p->fd); if (def) { - MYFLT *tab = (MYFLT *) ftp->ftable; + MYFLT *tab = ftp->ftable; ftresdisp(ff, ftp); /* VL: 11.01.05 for deferred alloc tables */ tab[ff->flen] = tab[0]; /* guard point */ ftp->flen -= 1; /* exclude guard point */ @@ -2624,7 +2727,7 @@ } filno = &ff->e.p[5]; - if (*filno == SSTRCOD) + if (ISSTRCOD(ff->e.p[5])) strcpy(filename, (char *)(&ff->e.strarg[0])); else csound->strarg2name(csound, filename, filno, "pvoc.", 0); @@ -2672,7 +2775,7 @@ } return OK; } - +#ifndef NACL #include "mp3dec.h" static int gen49raw(FGDATA *ff, FUNC *ftp) @@ -2699,7 +2802,7 @@ /* memset(&mpainfo, 0, sizeof(mpadec_info_t)); */ /* Is this necessary? */ { int32 filno = (int32) MYFLT2LRND(ff->e.p[5]); - if (filno == (int32) SSTRCOD) { + if (ISSTRCOD(ff->e.p[5])) { if (ff->e.strarg[0] == '"') { int len = (int) strlen(ff->e.strarg) - 2; strncpy(sfname, ff->e.strarg + 1, 1023); @@ -2709,7 +2812,8 @@ else strncpy(sfname, ff->e.strarg, 1023); } - else if (filno >= 0 && filno <= csound->strsmax && + else if ((filno= (int32) MYFLT2LRND(ff->e.p[5])) >= 0 && + filno <= csound->strsmax && csound->strsets && csound->strsets[filno]) strncpy(sfname, csound->strsets[filno], 1023); else @@ -2794,7 +2898,7 @@ if (UNLIKELY(ff->flen > MAXLEN)) return fterror(ff, Str("illegal table length")); if (csound->oparms->msglevel & 7) - csound->Message(csound, Str(" defer length %d\n"), ff->flen); + csoundMessage(csound, Str(" defer length %d\n"), ff->flen); ftp = ftalloc(ff); ftp->lenmask = 0L; ftp->flenfrms = frames; @@ -2807,7 +2911,7 @@ flen = ftp->flen; //printf("gen49: flen=%d size=%d bufsize=%d\n", flen, size, bufsize); while ((r == MP3DEC_RETCODE_OK) && bufused) { - int i; + unsigned int i; short *bb = (short*)buffer; //printf("gen49: p=%d bufused=%d\n", p, bufused); for (i=0; iflen / nchn) * nchn; - dst = &(ftp->ftable[0]); + dst = ftp->ftable; memset(dst, 0, ftp->flen*sizeof(MYFLT)); /* for (i = len; i <= (int) ftp->flen; i++) */ /* dst[i] = FL(0.0); */ @@ -2955,7 +3060,7 @@ if (UNLIKELY(f == NULL)) return NOTOK; len2 = (int) f->flen; - src = &(f->ftable[0]); + src = f->ftable; i = n; if (LIKELY((n * 3) + 7e.p[(n * 3) + 7]); else j = MYFLT2LRND(ff->e.c.extra[(n * 3) + 7-PMAX]); @@ -3110,7 +3215,7 @@ if (UNLIKELY(dstflen < 8 || (dstflen & (dstflen - 1)))) { return fterror(ff, Str("GEN53: invalid table length")); } - srcflen = csound->GetTable(csound, &srcftp, srcftno); + srcflen = csoundGetTable(csound, &srcftp, srcftno); if (UNLIKELY(srcflen < 0)) { return fterror(ff, Str("GEN53: invalid source table number")); } @@ -3122,7 +3227,7 @@ return fterror(ff, Str("GEN53: invalid source table length")); } if (winftno) { - winflen = csound->GetTable(csound, &winftp, winftno); + winflen = csoundGetTable(csound, &winftp, winftno); if (UNLIKELY(winflen <= 0 || (winflen & (winflen - 1)))) { return fterror(ff, Str("GEN53: invalid window table")); } @@ -3181,7 +3286,7 @@ static int warned = 0; int resize_table(CSOUND *csound, RESIZE *p) { - int fsize = (int) MYFLT2LRND(*p->nsize); + unsigned int fsize = (unsigned int) MYFLT2LRND(*p->nsize); int fno = (int) MYFLT2LRND(*p->fn); FUNC *ftp; diff -Nru csound-5.17.11~dfsg/Engine/insert.c csound-6.02~dfsg/Engine/insert.c --- csound-5.17.11~dfsg/Engine/insert.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/insert.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,26 +1,26 @@ /* - insert.c: + insert.c: - Copyright (C) 1991, 1997, 1999, 2002, 2005 - Barry Vercoe, Istvan Varga, John ffitch, - Gabriel Maldonado, matt ingalls - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + Copyright (C) 1991, 1997, 1999, 2002, 2005 + Barry Vercoe, Istvan Varga, John ffitch, + Gabriel Maldonado, matt ingalls + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ #include "csoundCore.h" /* INSERT.C */ @@ -30,18 +30,19 @@ #include "midiops.h" #include "namedins.h" /* IV - Oct 31 2002 */ #include "pstream.h" -/*extern MYFLT cpsocfrc[]; */ /* Needed by CPSOCTL */ +#include "interlocks.h" static void showallocs(CSOUND *); static void deact(CSOUND *, INSDS *); static void schedofftim(CSOUND *, INSDS *); - void beatexpire(CSOUND *, double); - void timexpire(CSOUND *, double); +void beatexpire(CSOUND *, double); +void timexpire(CSOUND *, double); static void instance(CSOUND *, int); +extern int argsRequired(char* argString); int init0(CSOUND *csound) { - INSTRTXT *tp = csound->instrtxtp[0]; + INSTRTXT *tp = csound->engineState.instrtxtp[0]; INSDS *ip; instance(csound, 0); /* allocate instr 0 */ @@ -50,6 +51,12 @@ csound->ids = (OPDS*) ip; tp->active++; ip->actflg++; + ip->ksmps = csound->ksmps; + ip->ekr = csound->ekr; + ip->kcounter = csound->kcounter; + ip->onedksmps = csound->onedksmps; + ip->onedkr = csound->onedkr; + ip->kicvt = csound->kicvt; csound->inerrcnt = 0; while ((csound->ids = csound->ids->nxti) != NULL) { (*csound->ids->iopadr)(csound, csound->ids); /* run all i-code */ @@ -57,14 +64,35 @@ return csound->inerrcnt; /* return errcnt */ } +static void putop(CSOUND *csound, TEXT *tp) +{ + int n, nn; + + if ((n = tp->outlist->count) != 0) { + nn = 0; + while (n--) + csound->Message(csound, "%s\t", tp->outlist->arg[nn++]); + } + else + csound->Message(csound, "\t"); + csound->Message(csound, "%s\t", tp->opcod); + if ((n = tp->inlist->count) != 0) { + nn = 0; + while (n--) + csound->Message(csound, "%s\t", tp->inlist->arg[nn++]); + } + csound->Message(csound, "\n"); +} + static void set_xtratim(CSOUND *csound, INSDS *ip) { if (ip->relesing) return; ip->offtim = (csound->icurTime + - csound->ksmps * (double) ip->xtratim)/csound->esr; + ip->ksmps * (double) ip->xtratim)/csound->esr; ip->offbet = csound->curBeat + (csound->curBeat_inc * (double) ip->xtratim); ip->relesing = 1; + csound->engineState.instrtxtp[ip->insno]->pending_release++; } /* insert an instr copy into active list */ @@ -75,11 +103,12 @@ INSTRTXT *tp; INSDS *ip, *prvp, *nxtp; OPARMS *O = csound->oparms; + int tie=0; if (csound->advanceCnt) return 0; if (UNLIKELY(O->odebug)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csound->Message(csound, Str("activating instr %s at %d\n"), name, csound->icurTime); @@ -88,25 +117,25 @@ insno, csound->icurTime); } csound->inerrcnt = 0; - tp = csound->instrtxtp[insno]; + tp = csound->engineState.instrtxtp[insno]; if (UNLIKELY(tp->muted == 0)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csound->Warning(csound, Str("Instrument %s muted\n"), name); else csound->Warning(csound, Str("Instrument %d muted\n"), insno); return 0; } - if (UNLIKELY(tp->mdepends & 04)) { - char *name = csound->instrtxtp[insno]->insname; - if (UNLIKELY(name)) - csound->Message(csound, Str("instr %s expects midi event data, " - "cannot run from score\n"), name); - else - csound->Message(csound, Str("instr %d expects midi event data, " - "cannot run from score\n"), insno); - return(1); - } + /* if (UNLIKELY(tp->mdepends & MO)) { */ + /* char *name = csound->engineState.instrtxtp[insno]->insname; */ + /* if (UNLIKELY(name)) */ + /* csound->Message(csound, Str("instr %s expects midi event data, " */ + /* "cannot run from score\n"), name); */ + /* else */ + /* csound->Message(csound, Str("instr %d expects midi event data, " */ + /* "cannot run from score\n"), insno); */ + /* return(1); */ + /* } */ if (tp->cpuload > FL(0.0)) { csound->cpu_power_busy += tp->cpuload; /* if there is no more cpu processing time*/ @@ -126,28 +155,39 @@ for (ip = tp->instance; ip != NULL; ip = ip->nxtinstance) { if (ip->actflg && ip->offtim < 0.0 && ip->p1 == newevtp->p[1]) { csound->tieflag++; + ip->tieflag = 1; + tie = 1; goto init; /* continue that event */ } } /* alloc new dspace if needed */ - if (tp->act_instance == NULL) { - if (O->msglevel & RNGEMSG) { - char *name = csound->instrtxtp[insno]->insname; + if (tp->act_instance == NULL || tp->isNew) { + if (UNLIKELY(O->msglevel & RNGEMSG)) { + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csound->Message(csound, Str("new alloc for instr %s:\n"), name); else csound->Message(csound, Str("new alloc for instr %d:\n"), insno); } instance(csound, insno); + tp->isNew=0; } /* pop from free instance chain */ ip = tp->act_instance; tp->act_instance = ip->nxtact; ip->insno = (int16) insno; - + ip->ksmps = csound->ksmps; + ip->ekr = csound->ekr; + ip->kcounter = csound->kcounter; + ip->onedksmps = csound->onedksmps; + ip->onedkr = csound->onedkr; + ip->kicvt = csound->kicvt; + ip->pds = NULL; /* Add an active instrument */ tp->active++; tp->instcnt++; + csound->dag_changed++; /* Need to remake DAG */ + //printf("**** dag changed by insert\n"); nxtp = &(csound->actanchor); /* now splice into activ lst */ while ((prvp = nxtp) && (nxtp = prvp->nxtact) != NULL) { if (nxtp->insno > insno || @@ -171,7 +211,7 @@ memcpy(&ip->p3, pdat, sizeof(MYFLT)*nn); } if (UNLIKELY((n = tp->pmax) != newevtp->pcnt && !tp->psetdata)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csoundWarning(csound, Str("instr %s uses %d p-fields but is given %d"), name, n, newevtp->pcnt); @@ -181,7 +221,7 @@ } if (newevtp->p3orig >= FL(0.0)) ip->offbet = csound->beatOffs - + (double) newevtp->p2orig + (double) newevtp->p3orig; + + (double) newevtp->p2orig + (double) newevtp->p3orig; else ip->offbet = -1.0; flp = &ip->p1; @@ -195,6 +235,12 @@ if (UNLIKELY(O->odebug)) csound->Message(csound, " ending at %p\n", (void*) flp); } + +#ifdef HAVE_ATOMIC_BUILTIN + __sync_lock_test_and_set((int*)&ip->init_done,1); +#else + ip->init_done = 1; +#endif if (O->Beatmode) ip->p2 = (MYFLT) (csound->icurTime/csound->esr - csound->timeOffs); ip->offtim = (double) ip->p3; /* & duplicate p3 for now */ @@ -204,20 +250,63 @@ ip->m_sust = 0; ip->nxtolap = NULL; ip->opcod_iobufs = NULL; - csound->curip = ip; - csound->ids = (OPDS *)ip; - /* do init pass for this instr */ - while ((csound->ids = csound->ids->nxti) != NULL) { - if (UNLIKELY(O->odebug)) - csound->Message(csound, "init %s:\n", - csound->opcodlst[csound->ids->optext->t.opnum].opname); - (*csound->ids->iopadr)(csound, csound->ids); + ip->strarg = newevtp->strarg; /* copy strarg so it does not get lost */ +#ifdef HAVE_ATOMIC_BUILTIN + __sync_lock_test_and_set((int*)&ip->init_done,0); +#else + ip->init_done = 0; +#endif + + + if (csound->realtime_audio_flag == 0) { + csound->curip = ip; + csound->ids = (OPDS *)ip; + /* do init pass for this instr */ + while ((csound->ids = csound->ids->nxti) != NULL) { + if (O->odebug) + csound->Message(csound, "init %s:\n", + csound->ids->optext->t.oentry->opname); + (*csound->ids->iopadr)(csound, csound->ids); + } + ip->init_done = 1; + ip->tieflag = 0; + ip->reinitflag = 0; + csound->tieflag = csound->reinitflag = 0; } - csound->tieflag = csound->reinitflag = 0; + if (UNLIKELY(csound->inerrcnt || ip->p3 == FL(0.0))) { xturnoff_now(csound, ip); return csound->inerrcnt; } + + /* new code for sample-accurate timing, not for tied notes */ + if (O->sampleAccurate & !tie) { + int64_t start_time_samps, start_time_kcycles; + double duration_samps; + start_time_samps = (int64_t) (ip->p2 * csound->esr); + duration_samps = ip->p3 * csound->esr; + start_time_kcycles = start_time_samps/csound->ksmps; + ip->ksmps_offset = start_time_samps - start_time_kcycles*csound->ksmps; + ip->no_end = csound->ksmps - + ((int)duration_samps+ip->ksmps_offset)%csound->ksmps; + /* the ksmps_no_end field is initially 0, set to no_end in the last + perf cycle */ + ip->ksmps_no_end = 0; + /* if (ip->no_end) { */ + /* // printf(">>>> %d\n",((int)duration_samps+ip->ksmps_offset)); */ + /* printf(">>>> no_end=%d (%ld,%d,%f,%d)\n", */ + /* ip->no_end, (long)duration_kcycles, csound->ksmps, */ + /* duration_samps, ip->ksmps_offset); */ + /* //printf(" > p2=%f p3=%f\n", ip->p2, ip->p3); */ + /* } */ + } + else { + /* ksmps_offset = */ + ip->ksmps_offset = 0; + ip->ksmps_no_end = 0; + ip->no_end = 0; + } + #ifdef BETA if (UNLIKELY(O->odebug)) csound->Message(csound, "In insert: %d %lf %lf\n", @@ -226,9 +315,13 @@ if (ip->p3 > FL(0.0) && ip->offtim > 0.0) { /* if still finite time, */ double p2 = (double) ip->p2 + csound->timeOffs; ip->offtim = p2 + (double) ip->p3; + //csound->Message(csound, "%lf\n", ip->offtim); /* csound->Message(csound, "ip->offtim = %lf -> ", ip->offtim); */ - ip->offtim = FLOOR(ip->offtim * csound->ekr +0.5)/csound->ekr; - /* csound->Message(csound, "%lf\n", ip->offtim); */ + if(O->sampleAccurate && !tie) /* ceil for sample-accurate ending */ + ip->offtim = CEIL(ip->offtim*csound->ekr) / csound->ekr; + else /* normal : round */ + ip->offtim = FLOOR(ip->offtim * csound->ekr +0.5)/csound->ekr; + // csound->Message(csound, "%lf\n", ip->offtim); if (O->Beatmode) { p2 = ((p2*csound->esr - csound->icurTime) / csound->ibeatTime) + csound->curBeat; @@ -236,7 +329,8 @@ } #ifdef BETA if (UNLIKELY(O->odebug)) - csound->Message(csound, "Calling schedofftim line %d; offtime= %lf (%lf)\n", + csound->Message(csound, + "Calling schedofftim line %d; offtime= %lf (%lf)\n", __LINE__, ip->offtim, ip->offtim*csound->ekr); #endif schedofftim(csound, ip); /* put in turnoff list */ @@ -246,13 +340,16 @@ ip->offtim = -1.0; /* else mark indef */ } if (UNLIKELY(O->odebug)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csound->Message(csound, Str("instr %s now active:\n"), name); else csound->Message(csound, Str("instr %d now active:\n"), insno); showallocs(csound); } + if(newevtp->pinstance != NULL) { + newevtp->pinstance = ip; + } return 0; } @@ -267,10 +364,10 @@ if (csound->advanceCnt) return 0; - if (insno <= 0 || csound->instrtxtp[insno]->muted == 0) + if (insno <= 0 || csound->engineState.instrtxtp[insno]->muted == 0) return 0; /* muted */ - tp = csound->instrtxtp[insno]; + tp = csound->engineState.instrtxtp[insno]; if (tp->cpuload > FL(0.0)) { csound->cpu_power_busy += tp->cpuload; if (UNLIKELY(csound->cpu_power_busy > FL(100.0))) { @@ -289,24 +386,25 @@ tp->active++; tp->instcnt++; if (UNLIKELY(O->odebug)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) - csound->Message(csound, Str("activating instr %s\n"), name); + csound->Message(csound, Str("MIDI activating instr %s\n"), name); else - csound->Message(csound, Str("activating instr %d\n"), insno); + csound->Message(csound, Str("MIDI activating instr %d\n"), insno); } csound->inerrcnt = 0; ipp = &chn->kinsptr[mep->dat1]; /* key insptr ptr */ /* alloc new dspace if needed */ - if (tp->act_instance == NULL) { - if (O->msglevel & RNGEMSG) { - char *name = csound->instrtxtp[insno]->insname; + if (tp->act_instance == NULL || tp->isNew) { + if (UNLIKELY(O->msglevel & RNGEMSG)) { + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) - csound->Message(csound, Str("new alloc for instr %s:\n"), name); + csound->Message(csound, Str("new MIDI alloc for instr %s:\n"), name); else - csound->Message(csound, Str("new alloc for instr %d:\n"), insno); + csound->Message(csound, Str("new MIDI alloc for instr %d:\n"), insno); } instance(csound, insno); + tp->isNew = 0; } /* pop from free instance chain */ ip = tp->act_instance; @@ -336,30 +434,35 @@ break; } } - ip->nxtact = nxtp; - ip->prvact = prvp; - prvp->nxtact = ip; + ip->nxtact = nxtp; + ip->prvact = prvp; + prvp->nxtact = ip; ip->actflg++; /* and mark the instr active */ - ip->m_chnbp = chn; /* rec address of chnl ctrl blk */ - ip->m_pitch = (unsigned char) mep->dat1; /* rec MIDI data */ - ip->m_veloc = (unsigned char) mep->dat2; - ip->xtratim = 0; - ip->m_sust = 0; - ip->relesing = 0; - ip->offbet = -1.0; - ip->offtim = -1.0; /* set indef duration */ - ip->opcod_iobufs = NULL; /* IV - Sep 8 2002: */ - ip->p1 = (MYFLT) insno; /* set these required p-fields */ - ip->p2 = (MYFLT) (csound->icurTime/csound->esr - csound->timeOffs); - ip->p3 = FL(-1.0); + ip->m_chnbp = chn; /* rec address of chnl ctrl blk */ + ip->m_pitch = (unsigned char) mep->dat1; /* rec MIDI data */ + ip->m_veloc = (unsigned char) mep->dat2; + ip->xtratim = 0; + ip->m_sust = 0; + ip->relesing = 0; + ip->offbet = -1.0; + ip->offtim = -1.0; /* set indef duration */ + ip->opcod_iobufs = NULL; /* IV - Sep 8 2002: */ + ip->p1 = (MYFLT) insno; /* set these required p-fields */ + ip->p2 = (MYFLT) (csound->icurTime/csound->esr - csound->timeOffs); + ip->p3 = FL(-1.0); + ip->ksmps = csound->ksmps; + ip->ekr = csound->ekr; + ip->kcounter = csound->kcounter; + ip->onedksmps = csound->onedksmps; + ip->onedkr = csound->onedkr; + ip->kicvt = csound->kicvt; + //#endif + ip->pds = NULL; if (tp->psetdata != NULL) { MYFLT *pfld = &ip->p3; /* if pset data present */ MYFLT *pdat = tp->psetdata + 2; int32 nn = tp->pmax - 2; /* put cur vals in pflds */ memcpy(pfld, pdat, nn*sizeof(MYFLT)); -/* do { */ -/* *pfld++ = *pdat++; */ -/* } while (--nn); */ } /* MIDI channel message note on routing overrides pset: */ @@ -442,42 +545,32 @@ pfield, pfields[index]); } } - /* - the code above assumes &p1 is a pointer to an array of N pfields, but - this is wrong. It overwrites memory and uses it for passing p-field - values. When the overwritten memory is taken to be a pointer in the - loop below, the loop does not stop at the end of the opcode list - and causes iopadr to be garbage, leading to a segfault. - This happens where there is exactly one opcode in an instrument. - It is a nasty bug that needs to be fixed. - - A possible solution is to allocate always a minimum of 5 p-fields (see line - approx 1809 below). The extra p-fields appear to be hanging at the end of - an INSDS structure, and &p1 appears to be a legal array start address. - This allows p4 and p5 to be mapped, but no further p-fields (possibly). - - This fix is a bit of hack IMHO. But I have implemented it here, as it - seemingly prevents the crashes. - - (JPff) a safer fix to readthe extra arg numbers - */ - - csound->curip = ip; - csound->ids = (OPDS *)ip; - /* do init pass for this instr */ - while ((csound->ids = csound->ids->nxti) != NULL) { - if (O->odebug) - csound->Message(csound, "init %s:\n", - csound->opcodlst[csound->ids->optext->t.opnum].opname); - (*csound->ids->iopadr)(csound, csound->ids); +#ifdef HAVE_ATOMIC_BUILTIN + __sync_lock_test_and_set((int*)&ip->init_done,0); +#else + ip->init_done = 0; +#endif + csound->curip = ip; + if(csound->realtime_audio_flag == 0) { + csound->ids = (OPDS *)ip; + /* do init pass for this instr */ + while ((csound->ids = csound->ids->nxti) != NULL) { + if (O->odebug) + csound->Message(csound, "init %s:\n", + csound->ids->optext->t.oentry->opname); + (*csound->ids->iopadr)(csound, csound->ids); + } + ip->init_done = 1; + ip->tieflag = ip->reinitflag = 0; + csound->tieflag = csound->reinitflag = 0; } - csound->tieflag = csound->reinitflag = 0; + if (csound->inerrcnt) { xturnoff_now(csound, ip); return csound->inerrcnt; } if (UNLIKELY(O->odebug)) { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (UNLIKELY(name)) csound->Message(csound, Str("instr %s now active:\n"), name); else @@ -493,8 +586,11 @@ INSDS *p; csound->Message(csound, "insno\tinstanc\tnxtinst\tprvinst\tnxtact\t" - "prvact\tnxtoff\tactflg\tofftim\n"); - for (txtp = &(csound->instxtanchor); txtp != NULL; txtp = txtp->nxtinstxt) + "prvact\tnxtoff\tactflg\tofftim\n"); + for (txtp = &(csound->engineState.instxtanchor); + txtp != NULL; + txtp = txtp->nxtinstxt) + if ((p = txtp->instance) != NULL) { /* * On Alpha, we print pointers as pointers. heh 981101 @@ -525,6 +621,7 @@ csound->Message(csound,"schedofftim: %lf %lf %f\n", ip->offtim, csound->icurTime/csound->esr, csound->curTime_inc); + #endif if (csound->oparms_.Beatmode) { double tval = csound->curBeat + (0.505 * csound->curBeat_inc); @@ -553,17 +650,20 @@ /* csound.c */ extern int csoundDeinitialiseOpcodes(CSOUND *csound, INSDS *ip); - int useropcd(CSOUND *, UOPCODE*); +int useropcd(CSOUND *, UOPCODE*); static void deact(CSOUND *csound, INSDS *ip) { /* unlink single instr from activ chain */ INSDS *nxtp; /* and mark it inactive */ - /* close any files in fd chain */ + /* close any files in fd chain */ if (ip->nxtd != NULL) csoundDeinitialiseOpcodes(csound, ip); - csound->instrtxtp[ip->insno]->active--; /* remove an active instrument */ - csound->cpu_power_busy -= csound->instrtxtp[ip->insno]->cpuload; + /* remove an active instrument */ + csound->engineState.instrtxtp[ip->insno]->active--; + if (ip->xtratim > 0) + csound->engineState.instrtxtp[ip->insno]->pending_release--; + csound->cpu_power_busy -= csound->engineState.instrtxtp[ip->insno]->cpuload; /* IV - Sep 8 2002: free subinstr instances */ /* that would otherwise result in a memory leak */ if (ip->opcod_deact) { @@ -580,7 +680,7 @@ ip->subins_deact = NULL; } if (UNLIKELY(csound->oparms->odebug)) { - char *name = csound->instrtxtp[ip->insno]->insname; + char *name = csound->engineState.instrtxtp[ip->insno]->insname; if (UNLIKELY(name)) csound->Message(csound, Str("removed instance of instr %s\n"), name); else @@ -592,10 +692,20 @@ ip->actflg = 0; /* link into free instance chain */ /* This also destroys ip->nxtact causing loops */ - ip->nxtact = csound->instrtxtp[ip->insno]->act_instance; - csound->instrtxtp[ip->insno]->act_instance = ip; + if(csound->engineState.instrtxtp[ip->insno] == ip->instr){ + ip->nxtact = csound->engineState.instrtxtp[ip->insno]->act_instance; + csound->engineState.instrtxtp[ip->insno]->act_instance = ip; + } if (ip->fdchp != NULL) fdchclose(csound, ip); + csound->dag_changed++; + //printf("**** dag changed by deact\n"); +} + +int kill_instance(CSOUND *csound, KILLOP *p) { + if(*p->inst) xturnoff(csound, (INSDS *) ((long)*p->inst)); + else csound->Warning(csound, "instance not valid \n"); + return OK; } /* Turn off a particular insalloc, also remove from list of active */ @@ -651,6 +761,8 @@ else { /* no extra time needed: deactivate immediately */ deact(csound, ip); + csound->dag_changed++; /* Need to remake DAG */ + //printf("**** dag changed by xturnoff\n"); } } @@ -664,21 +776,25 @@ xturnoff(csound, ip); } +extern void free_instrtxt(CSOUND *csound, INSTRTXT *instrtxt); + void orcompact(CSOUND *csound) /* free all inactive instr spaces */ { INSTRTXT *txtp; INSDS *ip, *nxtip, *prvip, **prvnxtloc; int cnt = 0; - - for (txtp = &(csound->instxtanchor); + for (txtp = &(csound->engineState.instxtanchor); txtp != NULL; txtp = txtp->nxtinstxt) { + // csound->Message(csound, "txp=%p \n", txtp); if ((ip = txtp->instance) != NULL) { /* if instance exists */ + prvip = NULL; prvnxtloc = &txtp->instance; do { if (!ip->actflg) { + // csound->Message(csound, "ip=%p \n", ip); cnt++; - if (ip->opcod_iobufs && ip->insno > csound->maxinsno) + if (ip->opcod_iobufs && ip->insno > csound->engineState.maxinsno) mfree(csound, ip->opcod_iobufs); /* IV - Nov 10 2002 */ if (ip->fdchp != NULL) fdchclose(csound, ip); @@ -687,7 +803,9 @@ if ((nxtip = ip->nxtinstance) != NULL) nxtip->prvinstance = prvip; *prvnxtloc = nxtip; + mfree(csound, (char *)ip); + } else { prvip = ip; @@ -696,6 +814,7 @@ } while ((ip = *prvnxtloc) != NULL); } + /* IV - Oct 31 2002 */ if (!txtp->instance) txtp->lst_instance = NULL; /* find last alloc */ @@ -704,8 +823,30 @@ while (ip->nxtinstance) ip = ip->nxtinstance; txtp->lst_instance = ip; } + txtp->act_instance = NULL; /* no free instances */ } + /* check current items in deadpool to see if they need deleting */ + { + int i; + for(i=0; i < csound->dead_instr_no; i++){ + if(csound->dead_instr_pool[i] != NULL) { + INSDS *active = csound->dead_instr_pool[i]->instance; + while (active != NULL) { + if(active->actflg) { + // add_to_deadpool(csound,csound->dead_instr_pool[i]); + break; + } + active = active->nxtinstance; + } + /* no active instances */ + if (active == NULL) { + free_instrtxt(csound, csound->dead_instr_pool[i]); + csound->dead_instr_pool[i] = NULL; + } + } + } + } if (UNLIKELY(cnt)) csound->Message(csound, Str("inactive allocs returned to freespace\n")); } @@ -716,16 +857,17 @@ int insno; insno = (int) p1; - if (LIKELY((ip = (csound->instrtxtp[insno])->instance) != NULL)) { + if (LIKELY((ip = (csound->engineState.instrtxtp[insno])->instance) != NULL)) { do { if (ip->insno == insno /* if find the insno */ && ip->actflg /* active */ - && ip->offtim < 0.0 /* but indef, VL: currently this condition - cannot be removed, as it breaks turning off extratime instances */ + && ip->offtim < 0.0 /* but indef, VL: currently this condition + cannot be removed, as it breaks turning + off extratime instances */ && ip->p1 == p1) { if (UNLIKELY(csound->oparms->odebug)) csound->Message(csound, "turning off inf copy of instr %d\n", - insno); + insno); xturnoff(csound, ip); return; /* turn it off */ } @@ -774,21 +916,11 @@ return ++(csound->inerrcnt); } -int csoundPerfError(CSOUND *csound, const char *s, ...) +int csoundPerfError(CSOUND *csound, INSDS *ip, const char *s, ...) { va_list args; - INSDS *ip; char buf[512]; - /* RWD and probably this too... */ - if (UNLIKELY(csound->pds == NULL)) { - va_start(args, s); - csoundErrMsgV(csound, Str("\nPERF ERROR: "), s, args); - va_end(args); - csound->LongJmp(csound, 1); - } - /* IV - Oct 16 2002: check for subinstr and user opcode */ - ip = csound->pds->insdshead; if (ip->opcod_iobufs) { OPCODINFO *op = ((OPCOD_IOBUFS*) ip->opcod_iobufs)->opcode_info; /* find top level instrument instance */ @@ -797,59 +929,50 @@ } while (ip->opcod_iobufs); if (op) sprintf(buf, Str("PERF ERROR in instr %d (opcode %s): "), - ip->insno, op->name); + ip->insno, op->name); else sprintf(buf, Str("PERF ERROR in instr %d (subinstr %d): "), - ip->insno, csound->pds->insdshead->insno); + ip->insno, ip->insno); } else sprintf(buf, Str("PERF ERROR in instr %d: "), ip->insno); va_start(args, s); csoundErrMsgV(csound, buf, s, args); va_end(args); - putop(csound, &(csound->pds->optext->t)); + putop(csound, &(ip->pds->optext->t)); csoundMessage(csound, Str(" note aborted\n")); csound->perferrcnt++; xturnoff_now((CSOUND*) csound, ip); /* rm ins fr actlist */ - while (csound->pds->nxtp != NULL) - csound->pds = csound->pds->nxtp; /* loop to last opds */ - return csound->perferrcnt; /* contin from there */ } -/* IV - Oct 12 2002: new simplified subinstr functions */ - -int subinstrset(CSOUND *csound, SUBINST *p) +int subinstrset_(CSOUND *csound, SUBINST *p, int instno) { OPDS *saved_ids = csound->ids; INSDS *saved_curip = csound->curip; MYFLT *flp; - int instno, n, init_op, inarg_ofs; + int n, init_op, inarg_ofs; + INSDS *pip = p->h.insdshead; - /* check if we are using subinstrinit or subinstr */ init_op = (p->h.opadr == NULL ? 1 : 0); inarg_ofs = (init_op ? 0 : SUBINSTNUMOUTS); - /* IV - Oct 31 2002 */ - if (UNLIKELY((instno = strarg2insno(csound, p->ar[inarg_ofs], - (p->XSTRCODE & 1))) - < 0)) - return NOTOK; + if (UNLIKELY(instno < 0)) return NOTOK; /* IV - Oct 9 2002: need this check */ if (UNLIKELY(!init_op && p->OUTOCOUNT > csound->nchnls)) { return csoundInitError(csound, Str("subinstr: number of output " "args greater than nchnls")); } /* IV - Oct 9 2002: copied this code from useropcdset() to fix some bugs */ - if (!(csound->reinitflag | csound->tieflag)) { + if (!(pip->reinitflag | pip->tieflag)) { /* get instance */ - if (csound->instrtxtp[instno]->act_instance == NULL) + if (csound->engineState.instrtxtp[instno]->act_instance == NULL) instance(csound, instno); - p->ip = csound->instrtxtp[instno]->act_instance; - csound->instrtxtp[instno]->act_instance = p->ip->nxtact; + p->ip = csound->engineState.instrtxtp[instno]->act_instance; + csound->engineState.instrtxtp[instno]->act_instance = p->ip->nxtact; p->ip->insno = (int16) instno; p->ip->actflg++; /* and mark the instr active */ - csound->instrtxtp[instno]->active++; - csound->instrtxtp[instno]->instcnt++; + csound->engineState.instrtxtp[instno]->active++; + csound->engineState.instrtxtp[instno]->instcnt++; p->ip->p1 = (MYFLT) instno; p->ip->opcod_iobufs = (void*) &p->buf; /* link into deact chain */ @@ -858,6 +981,26 @@ saved_curip->subins_deact = (void*) p; p->parent_ip = p->buf.parent_ip = saved_curip; } + + /* set the local ksmps values */ +// if (local_ksmps != CS_KSMPS) { +// /* this is the case when p->ip->ksmps != p->h.insdshead->ksmps */ +// p->ip->ksmps = local_ksmps; +// ksmps_scale = CS_KSMPS / local_ksmps; +// lcurip->onedksmps = FL(1.0) / (MYFLT) local_ksmps; +// lcurip->ekr = csound->esr / (MYFLT) local_ksmps; +// lcurip->onedkr = FL(1.0) / lcurip->ekr; +// lcurip->kicvt = (MYFLT) FMAXLEN /lcurip->ekr; +// lcurip->kcounter *= ksmps_scale; +// } else { + p->ip->ksmps = CS_KSMPS; + p->ip->kcounter = CS_KCNT; + p->ip->ekr = CS_EKR; + p->ip->onedkr = CS_ONEDKR; + p->ip->onedksmps = CS_ONEDKSMPS; + p->ip->kicvt = CS_KICVT; +// } + /* copy parameters from this instrument into our subinstrument */ p->ip->xtratim = saved_curip->xtratim; p->ip->m_sust = 0; @@ -867,33 +1010,41 @@ p->ip->nxtolap = NULL; p->ip->p2 = saved_curip->p2; p->ip->p3 = saved_curip->p3; + p->ip->ksmps = CS_KSMPS; /* IV - Oct 31 2002 */ p->ip->m_chnbp = saved_curip->m_chnbp; p->ip->m_pitch = saved_curip->m_pitch; p->ip->m_veloc = saved_curip->m_veloc; + p->ip->ksmps_offset = saved_curip->ksmps_offset; + p->ip->ksmps_no_end = saved_curip->ksmps_no_end; + p->ip->tieflag = saved_curip->tieflag; + p->ip->reinitflag = saved_curip->reinitflag; + /* copy remainder of pfields */ flp = &p->ip->p3 + 1; /* by default all inputs are i-rate mapped to p-fields */ - if (UNLIKELY(p->INOCOUNT > (csound->instrtxtp[instno]->pmax + 1))) { + if (UNLIKELY(p->INOCOUNT > + (unsigned int)(csound->engineState.instrtxtp[instno]->pmax + 1))) return csoundInitError(csound, Str("subinstr: too many p-fields")); - } - for (n = 1; n < p->INOCOUNT; n++) + for (n = 1; (unsigned int) n < p->INOCOUNT; n++) *flp++ = *p->ar[inarg_ofs + n]; /* allocate memory for a temporary store of spout buffers */ - if (!init_op && !(csound->reinitflag | csound->tieflag)) + if (!init_op && !(pip->reinitflag | pip->tieflag)) csoundAuxAlloc(csound, (int32) csound->nspout * sizeof(MYFLT), &p->saved_spout); /* do init pass for this instr */ csound->curip = p->ip; csound->ids = (OPDS *)p->ip; - + p->ip->init_done = 0; while ((csound->ids = csound->ids->nxti) != NULL) { (*csound->ids->iopadr)(csound, csound->ids); } + p->ip->init_done = 1; + /* copy length related parameters back to caller instr */ saved_curip->xtratim = csound->curip->xtratim; saved_curip->relesing = csound->curip->relesing; @@ -907,62 +1058,89 @@ return OK; } +int subinstrset_S(CSOUND *csound, SUBINST *p){ + int instno, init_op, inarg_ofs; + /* check if we are using subinstrinit or subinstr */ + init_op = (p->h.opadr == NULL ? 1 : 0); + inarg_ofs = (init_op ? 0 : SUBINSTNUMOUTS); + instno = strarg2insno(csound, ((STRINGDAT *)p->ar[inarg_ofs])->data, 1); + return subinstrset_(csound,p,instno); +} + + +int subinstrset(CSOUND *csound, SUBINST *p){ + int instno, init_op, inarg_ofs; + /* check if we are using subinstrinit or subinstr */ + init_op = (p->h.opadr == NULL ? 1 : 0); + inarg_ofs = (init_op ? 0 : SUBINSTNUMOUTS); + instno = (int) *(p->ar[inarg_ofs]); + return subinstrset_(csound,p,instno); +} + /* IV - Sep 8 2002: new functions for user defined opcodes (based */ /* on Matt J. Ingalls' subinstruments, but mostly rewritten) */ +/* + UDOs now use the local ksmps stored in lcurip->ksmps + all the other dependent parameters are calculated in relation to + this. + + lcurip->ksmps is set to the caller ksmps (CS_KSMPS), unless a new + local ksmps is used, in which case it is set to that value. + If local ksmps differs from CS_KSMPS, we set useropcd1() to + deal with the perf-time code. Otherwise useropcd2() is used. + + For recursive calls when the local ksmps is set to differ from + the calling instrument ksmps, the top-level call + will use useropcd1(), whereas all the other recursive calls + will use useropdc2(), since their local ksmps will be the same + as the caller. + + Also in case of a local ksmps that differs from the caller, + the local kcounter value, obtained from the caller is + scaled to denote the correct kcount in terms of local + kcycles. + +*/ int useropcd1(CSOUND *, UOPCODE*), useropcd2(CSOUND *, UOPCODE*); int useropcdset(CSOUND *csound, UOPCODE *p) { - OPDS *saved_ids = csound->ids; - INSDS *saved_curip = csound->curip, *parent_ip = csound->curip, *lcurip; - INSTRTXT *tp; - int instno, i, n, pcnt; - OPCODINFO *inm; - OPCOD_IOBUFS *buf; - int g_ksmps; - int32 g_kcounter; - MYFLT g_ekr, g_onedkr, g_onedksmps, g_kicvt; - - g_ksmps = p->l_ksmps = csound->ksmps; /* default ksmps */ - p->ksmps_scale = 1; + OPDS *saved_ids = csound->ids; + INSDS *parent_ip = csound->curip, *lcurip; + INSTRTXT *tp; + unsigned int instno; + unsigned int pcnt; + unsigned int i, n; + OPCODINFO *inm; + OPCOD_IOBUFS *buf; + MYFLT ksmps_scale; + unsigned int local_ksmps; + + /* default ksmps */ + local_ksmps = CS_KSMPS; + ksmps_scale = 1; /* look up the 'fake' instr number, and opcode name */ - inm = (OPCODINFO*) csound->opcodlst[p->h.optext->t.opnum].useropinfo; + inm = (OPCODINFO*) p->h.optext->t.oentry->useropinfo; instno = inm->instno; - tp = csound->instrtxtp[instno]; + tp = csound->engineState.instrtxtp[instno]; /* set local ksmps if defined by user */ n = p->OUTOCOUNT + p->INOCOUNT - 1; + if (*(p->ar[n]) != FL(0.0)) { - i = (int) *(p->ar[n]); + i = (unsigned int) *(p->ar[n]); if (UNLIKELY(i < 1 || i > csound->ksmps || - ((csound->ksmps / i) * i) != csound->ksmps)) { + ((CS_KSMPS / i) * i) != CS_KSMPS)) { return csoundInitError(csound, Str("%s: invalid local ksmps value: %d"), - inm->name, i); + inm->name, i); } - p->l_ksmps = i; - } - /* save old globals */ - g_kcounter = csound->kcounter; - g_ekr = csound->ekr; - g_onedkr = csound->onedkr; - g_onedksmps = csound->onedksmps; - g_kicvt = csound->kicvt; - /* set up local variables depending on ksmps, also change globals */ - if (p->l_ksmps != g_ksmps) { - csound->ksmps = p->l_ksmps; /* Oh dear! breaks many assumptions -- JPff */ - p->ksmps_scale = g_ksmps / (int) csound->ksmps; - csound->pool[csound->poolcount + 2] = (MYFLT) p->l_ksmps; - p->l_onedksmps = csound->onedksmps = FL(1.0) / (MYFLT) p->l_ksmps; - p->l_ekr = csound->ekr = csound->pool[csound->poolcount + 1] = - csound->esr / (MYFLT) p->l_ksmps; - p->l_onedkr = csound->onedkr = FL(1.0) / p->l_ekr; - p->l_kicvt = csound->kicvt = (MYFLT) FMAXLEN / p->l_ekr; - csound->kcounter *= p->ksmps_scale; + local_ksmps = i; } if (!p->ip) { /* search for already allocated, but not active instance */ /* if none was found, allocate a new instance */ + if (!tp->act_instance) instance(csound, instno); lcurip = tp->act_instance; /* use free intance, and */ @@ -983,28 +1161,66 @@ buf->iobufp_ptrs[2] = buf->iobufp_ptrs[3] = NULL; buf->iobufp_ptrs[4] = buf->iobufp_ptrs[5] = NULL; buf->iobufp_ptrs[6] = buf->iobufp_ptrs[7] = NULL; + buf->iobufp_ptrs[8] = buf->iobufp_ptrs[9] = NULL; + buf->iobufp_ptrs[10] = buf->iobufp_ptrs[11] = NULL; /* store parameters of input and output channels, and parent ip */ buf->uopcode_struct = (void*) p; buf->parent_ip = p->parent_ip = parent_ip; + } - /* copy parameters from the caller instrument into our subinstrument */ + /* copy parameters from the caller instrument into our subinstrument */ lcurip = p->ip; + + /* set the local ksmps values */ + if (local_ksmps != CS_KSMPS) { + /* this is the case when p->ip->ksmps != p->h.insdshead->ksmps */ + lcurip->ksmps = local_ksmps; + ksmps_scale = CS_KSMPS / local_ksmps; + lcurip->onedksmps = FL(1.0) / (MYFLT) local_ksmps; + lcurip->ekr = csound->esr / (MYFLT) local_ksmps; + lcurip->onedkr = FL(1.0) / lcurip->ekr; + lcurip->kicvt = (MYFLT) FMAXLEN /lcurip->ekr; + lcurip->kcounter *= ksmps_scale; + } else { + lcurip->ksmps = CS_KSMPS; + lcurip->kcounter = CS_KCNT; + lcurip->ekr = CS_EKR; + lcurip->onedkr = CS_ONEDKR; + lcurip->onedksmps = CS_ONEDKSMPS; + lcurip->kicvt = CS_KICVT; + } + + /* VL 13-12-13 */ + /* this sets ksmps and kr local variables */ + /* create local ksmps variable and init with ksmps */ + CS_VARIABLE *var = + csoundFindVariableWithName(lcurip->instr->varPool, "ksmps"); + *((MYFLT *)(var->memBlockIndex + lcurip->lclbas)) = lcurip->ksmps; + /* same for kr */ + var = + csoundFindVariableWithName(lcurip->instr->varPool, "kr"); + *((MYFLT *)(var->memBlockIndex + lcurip->lclbas)) = lcurip->ekr; + lcurip->m_chnbp = parent_ip->m_chnbp; /* MIDI parameters */ lcurip->m_pitch = parent_ip->m_pitch; lcurip->m_veloc = parent_ip->m_veloc; - lcurip->xtratim = parent_ip->xtratim * p->ksmps_scale; + lcurip->xtratim = parent_ip->xtratim * ksmps_scale; lcurip->m_sust = 0; lcurip->relesing = parent_ip->relesing; lcurip->offbet = parent_ip->offbet; lcurip->offtim = parent_ip->offtim; lcurip->nxtolap = NULL; + lcurip->ksmps_offset = parent_ip->ksmps_offset; + lcurip->ksmps_no_end = parent_ip->ksmps_no_end; + lcurip->tieflag = parent_ip->tieflag; + lcurip->reinitflag = parent_ip->reinitflag; /* copy all p-fields, including p1 (will this work ?) */ if (tp->pmax > 3) { /* requested number of p-fields */ n = tp->pmax; pcnt = 0; while (pcnt < n) { - if ((i = csound->instrtxtp[parent_ip->insno]->pmax) > pcnt) { + if ((i = csound->engineState.instrtxtp[parent_ip->insno]->pmax) > pcnt) { if (i > n) i = n; /* copy next block of p-fields */ memcpy(&(lcurip->p1) + pcnt, &(parent_ip->p1) + pcnt, @@ -1019,39 +1235,41 @@ else memcpy(&(lcurip->p1), &(parent_ip->p1), 3 * sizeof(MYFLT)); + /* do init pass for this instr */ + p->ip->init_done = 0; csound->curip = lcurip; csound->ids = (OPDS *) (lcurip->nxti); while (csound->ids != NULL) { (*csound->ids->iopadr)(csound, csound->ids); csound->ids = csound->ids->nxti; - } + } + p->ip->init_done = 1; + /* copy length related parameters back to caller instr */ - saved_curip->relesing = lcurip->relesing; - saved_curip->offbet = lcurip->offbet; - saved_curip->offtim = lcurip->offtim; - saved_curip->p3 = lcurip->p3; + parent_ip->relesing = lcurip->relesing; + parent_ip->offbet = lcurip->offbet; + parent_ip->offtim = lcurip->offtim; + parent_ip->p3 = parent_ip->p3; + local_ksmps = lcurip->ksmps; /* restore globals */ csound->ids = saved_ids; - csound->curip = saved_curip; - if (csound->ksmps != g_ksmps) { - csound->ksmps = g_ksmps; - saved_curip->xtratim = lcurip->xtratim / p->ksmps_scale; - csound->pool[csound->poolcount + 2] = (MYFLT) g_ksmps; - csound->kcounter = g_kcounter; - csound->ekr = csound->pool[csound->poolcount + 1] = g_ekr; - csound->onedkr = g_onedkr; - csound->onedksmps = g_onedksmps; - csound->kicvt = g_kicvt; - /* IV - Sep 17 2002: also select perf routine */ + csound->curip = parent_ip; + + /* select perf routine and scale xtratim accordingly */ + if (local_ksmps != CS_KSMPS) { + ksmps_scale = CS_KSMPS / local_ksmps; + parent_ip->xtratim = lcurip->xtratim / ksmps_scale; p->h.opadr = (SUBR) useropcd1; } else { - saved_curip->xtratim = lcurip->xtratim; + parent_ip->xtratim = lcurip->xtratim; p->h.opadr = (SUBR) useropcd2; } - + if(csound->oparms->odebug) + csound->Message(csound, "EXTRATIM=> cur(%p): %d, parent(%p): %d\n", + lcurip, lcurip->xtratim, parent_ip, parent_ip->xtratim); return OK; } @@ -1059,8 +1277,12 @@ int useropcd(CSOUND *csound, UOPCODE *p) { - return csoundPerfError(csound, Str("%s: not initialised"), - p->h.optext->t.opcod); + + if(p->h.nxtp) + return csoundPerfError(csound, p->h.insdshead, Str("%s: not initialised"), + p->h.optext->t.opcod); + else + return OK; } /* IV - Sep 1 2002: new opcodes: xin, xout */ @@ -1078,17 +1300,24 @@ bufs = ((UOPCODE*) buf->uopcode_struct)->ar + inm->outchns; /* copy i-time variables */ ndx_list = inm->in_ndx_list - 1; - while (*++ndx_list >= 0) - *(*(p->args + *ndx_list)) = *(*(bufs + *ndx_list)); + + while (*++ndx_list >= 0) { + *(*(p->args + *ndx_list)) = *(*(bufs + *ndx_list)); + } + /* IV - Jul 29 2006: and string variables */ while (*++ndx_list >= 0) { - const char *src = (char *)bufs[*ndx_list]; - char *dst = (char *)(p->args[*ndx_list]); - int n; - /* FIXME: should throw error instead of truncating string ? */ - for (n = csound->strVarMaxLen - 1; *src != '\0' && n != 0; n--) - *(dst++) = *(src++); - *dst = '\0'; + void *in, *out; + in = (void *)*(bufs + *ndx_list); + out = (void *) *(p->args + *ndx_list); + memcpy(out, in, sizeof(STRINGDAT)); + } + /* and i-time arrays */ + while (*++ndx_list >= 0) { + void *in, *out; + in = (void *)*(bufs + *ndx_list); + out = (void *) *(p->args + *ndx_list); + memcpy(out, in, sizeof(ARRAYDAT)); } /* find a-rate variables and add to list of perf-time buf ptrs ... */ @@ -1097,6 +1326,7 @@ return OK; while (*++ndx_list >= 0) { + *(tmp++) = *(bufs + *ndx_list); /* "from" address */ *(tmp++) = *(p->args + *ndx_list);/* "to" address */ } @@ -1108,25 +1338,25 @@ } *(tmp++) = NULL; /* put delimiter */ /* fsigs: we'll need to do extra work */ - while (*++ndx_list >= 0) { - void *in, *out; - in = (void *)*(bufs + *ndx_list); - *(tmp++) = (MYFLT *) in; - out = (void *) *(p->args + *ndx_list); - *(tmp++) = (MYFLT *) out; - memcpy(out, in, sizeof(PVSDAT)); - } - *(tmp++) = NULL; - /* tsigs: similar to avove */ - while (*++ndx_list >= 0) { - void *in, *out; - in = (void *)*(bufs + *ndx_list); - *(tmp++) = (MYFLT *) in; - out = (void *) *(p->args + *ndx_list); - *(tmp++) = (MYFLT *) out; - memcpy(out, in, sizeof(TABDAT)); + while (*++ndx_list >= 0) { + void *in, *out; + in = (void *)*(bufs + *ndx_list); + *(tmp++) = (MYFLT *) in; + out = (void *) *(p->args + *ndx_list); + *(tmp++) = (MYFLT *) out; + memcpy(out, in, sizeof(PVSDAT)); } - *(tmp++) = NULL; + *(tmp++) = NULL; + /* arrays: similar to avove */ + while (*++ndx_list >= 0) { + void *in, *out; + in = (void *)*(bufs + *ndx_list); + *(tmp++) = (MYFLT *) in; + out = (void *) *(p->args + *ndx_list); + *(tmp++) = (MYFLT *) out; + memcpy(out, in, sizeof(ARRAYDAT)); + } + *(tmp++) = NULL; /* fix for case when xout is omitted */ *(tmp++) = NULL; *(tmp++) = NULL; *(tmp++) = NULL; *tmp = NULL; @@ -1151,22 +1381,27 @@ } /* IV - Jul 29 2006: and string variables */ while (*++ndx_list >= 0) { - const char *src = (char *)(p->args[*ndx_list]); - char *dst = (char *)(bufs[*ndx_list]); - int n; - /* FIXME: should throw error instead of truncating string ? */ - for (n = csound->strVarMaxLen - 1; *src != '\0' && n != 0; n--) - *(dst++) = *(src++); - *dst = '\0'; + void *in, *out; + in = (void *) *(p->args + *ndx_list); + out = (void *) *(bufs + *ndx_list); + memcpy(out, in, sizeof(STRINGDAT)); } + /* i-time arrays */ + while (*++ndx_list >= 0) { + void *in, *out; + in = (void *) *(p->args + *ndx_list); + out = (void *) *(bufs + *ndx_list); + memcpy(out, in, sizeof(ARRAYDAT)); + } + + /* skip input pointers, including the three delimiter NULLs */ tmp = buf->iobufp_ptrs; - /* VL: needs to check if there are not 4 nulls in a sequence, which - would indicate no a, k, f or t sigs */ - if (*tmp || *(tmp + 1) || *(tmp + 2) || *(tmp + 3)) tmp += (inm->perf_incnt << 1); - tmp += 4; /* VL: this was 2, now 4 with fsigs and tsigs added */ + if (*tmp || *(tmp + 1) || *(tmp + 2) || *(tmp + 3)) + tmp += (inm->perf_incnt << 1); + tmp += 4; if (*tmp || *(tmp + 1)) - return OK; + return OK; /* find a-rate variables and add to list of perf-time buf ptrs ... */ while (*++ndx_list >= 0) { @@ -1191,14 +1426,14 @@ memcpy(out, in, sizeof(PVSDAT)); } *(tmp++) = NULL; - /* tsigs: as above */ + /* arrays: as above */ while (*++ndx_list >= 0) { void *in, *out; in = (void *) *(p->args + *ndx_list); *(tmp++) = (MYFLT *) in; out = (void *) *(bufs + *ndx_list); *(tmp++) = (MYFLT *) out; - memcpy(out, in, sizeof(TABDAT)); + memcpy(out, in, sizeof(ARRAYDAT)); } *tmp = NULL; @@ -1207,33 +1442,51 @@ /* IV - Sep 8 2002: new opcode: setksmps */ +/* + This opcode sets the local ksmps for an instrument + it can be used on any instrument with the implementation + of a mechanism to perform at local ksmps (in kperf etc) +*/ +#include "typetabl.h" +#include "csound_standard_types.h" int setksmpsset(CSOUND *csound, SETKSMPS *p) { - OPCOD_IOBUFS *buf; - UOPCODE *pp; - int l_ksmps, n; - buf = (OPCOD_IOBUFS*) p->h.insdshead->opcod_iobufs; - l_ksmps = (int) *(p->i_ksmps); + unsigned int l_ksmps, n; + + l_ksmps = (unsigned int) *(p->i_ksmps); if (!l_ksmps) return OK; /* zero: do not change */ - if (UNLIKELY(l_ksmps < 1 || l_ksmps > csound->ksmps - || ((csound->ksmps / l_ksmps) * l_ksmps != csound->ksmps))) { - return csoundInitError(csound, Str("setksmps: invalid ksmps value: %d"), - l_ksmps); - } - /* set up global variables according to the new ksmps value */ - pp = (UOPCODE*) buf->uopcode_struct; - n = csound->ksmps / l_ksmps; - pp->ksmps_scale *= n; + if (UNLIKELY(l_ksmps < 1 || l_ksmps > CS_KSMPS + || ((CS_KSMPS / l_ksmps) * l_ksmps != CS_KSMPS))) { + return csoundInitError(csound, + Str("setksmps: invalid ksmps value: %d, original: %d"), + l_ksmps, CS_KSMPS); + } + + n = CS_KSMPS / l_ksmps; p->h.insdshead->xtratim *= n; - pp->l_ksmps = csound->ksmps = l_ksmps; - csound->pool[csound->poolcount + 2] = (MYFLT) csound->ksmps; - pp->l_onedksmps = csound->onedksmps = FL(1.0) / (MYFLT) csound->ksmps; - pp->l_ekr = csound->ekr = csound->pool[csound->poolcount + 1] = - csound->esr / (MYFLT) csound->ksmps; - pp->l_onedkr = csound->onedkr = FL(1.0) / csound->ekr; - pp->l_kicvt = csound->kicvt = (MYFLT) FMAXLEN / csound->ekr; - csound->kcounter *= pp->ksmps_scale; + CS_KSMPS = l_ksmps; + CS_ONEDKSMPS = FL(1.0) / (MYFLT) CS_KSMPS; + CS_EKR = csound->esr / (MYFLT) CS_KSMPS; + CS_ONEDKR = FL(1.0) / CS_EKR; + CS_KICVT = (MYFLT) FMAXLEN / CS_EKR; + CS_KCNT *= n; + + /* VL 13-12-13 */ + /* this sets ksmps and kr local variables */ + /* lookup local ksmps variable and init with ksmps */ + INSTRTXT *ip = p->h.insdshead->instr; + CS_VARIABLE *var = + csoundFindVariableWithName(ip->varPool, "ksmps"); + MYFLT *varmem = p->h.insdshead->lclbas + var->memBlockIndex; + *varmem = CS_KSMPS; + + /* same for kr */ + var = + csoundFindVariableWithName(ip->varPool, "kr"); + varmem = p->h.insdshead->lclbas + var->memBlockIndex; + *varmem = CS_EKR; + return OK; } @@ -1243,197 +1496,18 @@ int nstrnumset(CSOUND *csound, NSTRNUM *p) { /* IV - Oct 31 2002 */ - *(p->i_insno) = (MYFLT) strarg2insno(csound, p->iname, (p->XSTRCODE & 1)); + *(p->i_insno) = (MYFLT) strarg2insno(csound, p->iname, 0); return (*(p->i_insno) > FL(0.0) ? OK : NOTOK); } -/* IV - Nov 16 2002: moved insert_event() here to have access to some static */ -/* functions defined in this file */ - -INSDS *insert_event(CSOUND *csound, - MYFLT instr, - MYFLT when, - MYFLT dur, - int narg, - MYFLT **args, - int midi) -{ - int pcnt = narg + 3; - int insno = (int) instr, saved_inerrcnt = csound->inerrcnt; - int saved_reinitflag = csound->reinitflag, saved_tieflag = csound->tieflag; - INSDS *saved_curip = csound->curip, *ip = NULL; - INSDS *prvp, *nxtp; /* IV - Nov 16 2002 */ - OPDS *saved_ids = csound->ids; - OPARMS *O = csound->oparms; - INSTRTXT *tp; - - if (csound->advanceCnt) - return NULL; - - csound->inerrcnt = csound->tieflag = csound->reinitflag = 0; - tp = csound->instrtxtp[insno]; - if (UNLIKELY(tp == NULL)) { - csound->Message(csound, - Str("schedule event ignored. instr %d undefined\n"), - insno); - csound->perferrcnt++; - goto endsched; /* IV - Nov 16 2002 */ - } - csound->cpu_power_busy += tp->cpuload; - /* if there is no more cpu processing time: */ - if (UNLIKELY(csound->cpu_power_busy > 100.0)) { - csound->cpu_power_busy -= tp->cpuload; - csoundWarning(csound, Str("cannot allocate last note because it exceeds " - "100%% of cpu time")); - goto endsched; - } - if (UNLIKELY(tp->maxalloc > 0 && tp->active >= tp->maxalloc)) { - csoundWarning(csound, Str("cannot allocate last note because it exceeds " - "instr maxalloc")); - goto endsched; - } - /* Insert this event into event queue */ - if (UNLIKELY(O->odebug)) - csound->Message(csound, "activating instr %d\n", insno); - if (UNLIKELY((tp->mdepends & 4) && !midi)) { - char *name = csound->instrtxtp[ip->insno]->insname; - if (name) - csound->Message(csound, Str("instr %s expects midi event data, " - "cannot run from score\n"), name); - else - csound->Message(csound, Str("instr %d expects midi event data, " - "cannot run from score\n"), insno); - csound->perferrcnt++; - goto endsched; - } - /* if find this insno, active, with indef (tie) & matching p1 */ - for (ip = tp->instance; ip != NULL; ip = ip->nxtinstance) { - /* if find this insno, active, with indef (tie) & matching p1 */ - if (ip->actflg && ip->offtim < 0.0 && ip->p1 == instr) { - csound->tieflag++; - goto init; /* continue that event */ - } - } - /* alloc new dspace if needed */ - if (tp->act_instance == NULL) { - if (O->msglevel & RNGEMSG) { - char *name = csound->instrtxtp[insno]->insname; - if (name) - csound->Message(csound, Str("new alloc for instr %s:\n"), name); - else - csound->Message(csound, Str("new alloc for instr %d:\n"), insno); - } - instance(csound, insno); - } - /* pop from free instance chain */ - ip = tp->act_instance; - tp->act_instance = ip->nxtact; - ip->insno = (int16) insno; - - /* Add an active instrument */ - tp->active++; - tp->instcnt++; - nxtp = &(csound->actanchor); /* now splice into active list */ - while ((prvp = nxtp) && (nxtp = prvp->nxtact) != NULL) - if (nxtp->insno > insno || - (nxtp->insno == insno && nxtp->p1 > instr)) { - nxtp->prvact = ip; - break; - } - ip->nxtact = nxtp; - ip->prvact = prvp; - prvp->nxtact = ip; - ip->actflg++; /* and mark the instr active */ - init: - { - int i; - int imax = tp->pmax - 3; - MYFLT *flp; - if (UNLIKELY((int) tp->pmax != pcnt)) { - char *name = csound->instrtxtp[insno]->insname; - if (name) - csoundWarning(csound, Str("instr %s pmax = %d, note pcnt = %d"), - name, (int) tp->pmax, pcnt); - else - csoundWarning(csound, Str("instr %d pmax = %d, note pcnt = %d"), - insno, (int) tp->pmax, pcnt); - } - ip->p1 = instr; - ip->p2 = when; - ip->p3 = dur; - flp = &(ip->p1) + 3; - if (UNLIKELY(O->odebug)) - csound->Message(csound, Str("psave beg at %p\n"), flp); - for (i = 0; i < imax; i++) { - if (i < narg) - *flp++ = *(args[i]); - else - *flp++ = FL(0.0); - } - if (UNLIKELY(O->odebug)) - csound->Message(csound, Str(" ending at %p\n"), flp); - } - if (O->Beatmode) - ip->p2 = (MYFLT) (csound->icurTime/csound->esr - csound->timeOffs); - ip->offbet = (double) ip->p3; - ip->offtim = (double) ip->p3; /* & duplicate p3 for now */ - ip->xtratim = 0; - ip->relesing = 0; - ip->m_sust = 0; - ip->nxtolap = NULL; - /* IV - Nov 16 2002 */ - ip->opcod_iobufs = NULL; - if (midi) { - /* should we copy MIDI parameters from the note from which the */ - /* event was scheduled ? */ - ip->m_chnbp = saved_curip->m_chnbp; - ip->m_pitch = saved_curip->m_pitch; - ip->m_veloc = saved_curip->m_veloc; - } - else - ip->m_chnbp = NULL; /* score event */ - csound->curip = ip; - csound->ids = (OPDS *)ip; - /* do init pass for this instr */ - while ((csound->ids = csound->ids->nxti) != NULL) { - /* if (O->odebug) csound->Message(csound, "init %s:\n", - csound->opcodlst[csound->ids->optext->t.opnum].opname); */ - (*csound->ids->iopadr)(csound, csound->ids); - } - if (csound->inerrcnt || ip->p3 == FL(0.0)) { - xturnoff_now(csound, ip); - ip = NULL; goto endsched; - } - if (!midi && /* if not MIDI activated, */ - ip->p3 > FL(0.0) && ip->offtim > 0.0) { /* and still finite time, */ - double p2; - p2 = (double) ip->p2 + csound->timeOffs; - ip->offtim = p2 + (double) ip->p3; - p2 = ((p2 - csound->icurTime) / csound->ibeatTime) + csound->curBeat; - ip->offbet = p2 + ((double) ip->p3*csound->esr / csound->ibeatTime); - schedofftim(csound, ip); /* put in turnoff list */ - if (!ip->actflg) { - ip = NULL; goto endsched; - } - } - else { - ip->offbet = -1.0; - ip->offtim = -1.0; /* else mark indef */ - } - if (UNLIKELY(O->odebug)) { - csound->Message(csound, "instr %d now active:\n", insno); - showallocs(csound); - } - endsched: - /* IV - Nov 16 2002: restore globals */ - csound->inerrcnt = saved_inerrcnt; - csound->reinitflag = saved_reinitflag; - csound->tieflag = saved_tieflag; - csound->curip = saved_curip; - csound->ids = saved_ids; - return ip; +int nstrnumset_S(CSOUND *csound, NSTRNUM *p) +{ + /* IV - Oct 31 2002 */ + *(p->i_insno) = (MYFLT) strarg2insno(csound, ((STRINGDAT *)p->iname)->data, 1); + return (*(p->i_insno) > FL(0.0) ? OK : NOTOK); } + /* unlink expired notes from activ chain */ /* and mark them inactive */ /* close any files in each fdchain */ @@ -1507,51 +1581,96 @@ } } +/** + this was rewritten for Csound 6 to allow + PARCS and local ksmps instruments +*/ + int subinstr(CSOUND *csound, SUBINST *p) { - OPDS *saved_pds = csound->pds; - int saved_sa = csound->spoutactive; - MYFLT *pbuf, *saved_spout = csound->spout; - int32 frame, chan; + OPDS *saved_pds = CS_PDS; + MYFLT *pbuf; + uint32_t frame, chan; + unsigned int nsmps = CS_KSMPS; + INSDS *ip = p->ip; if (UNLIKELY(p->ip == NULL)) { /* IV - Oct 26 2002 */ - return csoundPerfError(csound, Str("subinstr: not initialised")); + return csoundPerfError(csound, p->h.insdshead, + Str("subinstr: not initialised")); } /* copy current spout buffer and clear it */ - csound->spout = (MYFLT*) p->saved_spout.auxp; + ip->spout = (MYFLT*) p->saved_spout.auxp; + memset(ip->spout, 0, csound->nspout*sizeof(MYFLT)); csound->spoutactive = 0; + /* update release flag */ - p->ip->relesing = p->parent_ip->relesing; /* IV - Nov 16 2002 */ + ip->relesing = p->parent_ip->relesing; /* IV - Nov 16 2002 */ /* run each opcode */ - csound->pds = (OPDS *)p->ip; - while ((csound->pds = csound->pds->nxtp) != NULL) { - (*csound->pds->opadr)(csound, csound->pds); + if(csound->ksmps == ip->ksmps) { + if((CS_PDS = (OPDS *) (ip->nxtp)) != NULL) { + CS_PDS->insdshead->pds = NULL; + do { + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + }while ((CS_PDS = CS_PDS->nxtp)); + } + ip->kcounter++; } - - /* copy outputs */ - if (csound->spoutactive) { - for (chan = 0; chan < p->OUTOCOUNT; chan++) { - for (pbuf = csound->spout + chan, frame = 0; - frame < csound->ksmps; frame++) { - p->ar[chan][frame] = *pbuf; - pbuf += csound->nchnls; + else { + int i, n = csound->nspout, start = 0; + int lksmps = ip->ksmps; + int incr = csound->nchnls*lksmps; + int offset = ip->ksmps_offset; + int early = ip->ksmps_no_end; + ip->spin = csound->spin; + ip->kcounter = csound->kcounter*csound->ksmps/lksmps; + + /* we have to deal with sample-accurate code + whole CS_KSMPS blocks are offset here, the + remainder is left to each opcode to deal with. + */ + while(offset >= lksmps) { + offset -= lksmps; + start += csound->nchnls; + } + ip->ksmps_offset = offset; + if(early){ + n -= (early*csound->nchnls); + ip->ksmps_no_end = early % lksmps; + } + + for (i=start; i < n; i+=incr, ip->spin+=incr, ip->spout+=incr) { + if((CS_PDS = (OPDS *) (ip->nxtp)) != NULL) { + CS_PDS->insdshead->pds = NULL; + do { + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + }while ((CS_PDS = CS_PDS->nxtp)); } + ip->kcounter++; } + ip->spout = (MYFLT*) p->saved_spout.auxp; } - else { - for (chan = 0; chan < p->OUTOCOUNT; chan++) - for (frame = 0; frame < csound->ksmps; frame++) - p->ar[chan][frame] = FL(0.0); + /* copy outputs */ + for (chan = 0; chan < p->OUTOCOUNT; chan++) { + for (pbuf = ip->spout + chan, frame = 0; + frame < nsmps; frame++) { + p->ar[chan][frame] = *pbuf; + pbuf += csound->nchnls; + } } - /* restore spouts */ - csound->spout = saved_spout; - csound->spoutactive = saved_sa; - csound->pds = saved_pds; + CS_PDS = saved_pds; /* check if instrument was deactivated (e.g. by perferror) */ if (!p->ip) /* loop to last opds */ - while (csound->pds->nxtp) csound->pds = csound->pds->nxtp; + while (CS_PDS->nxtp)CS_PDS = CS_PDS->nxtp; return OK; } @@ -1559,30 +1678,30 @@ int useropcd1(CSOUND *csound, UOPCODE *p) { - OPDS *saved_pds = csound->pds; - int g_ksmps, ofs = 0, n; - MYFLT g_ekr, g_onedkr, g_onedksmps, g_kicvt, **tmp, *ptr1, *ptr2; - int32 g_kcounter; - - /* update release flag */ + OPDS *saved_pds = CS_PDS; + int g_ksmps, ofs, n, early, offset; + MYFLT **tmp, *ptr1, *ptr2, *out; + INSDS *this_instr = p->ip; p->ip->relesing = p->parent_ip->relesing; /* IV - Nov 16 2002 */ - /* save old globals */ - g_ksmps = csound->ksmps; - g_ekr = csound->ekr; - g_onedkr = csound->onedkr; - g_onedksmps = csound->onedksmps; - g_kicvt = csound->kicvt; - g_kcounter = csound->kcounter; - /* set local ksmps and related values */ - csound->ksmps = p->l_ksmps; - csound->pool[csound->poolcount + 2] = (MYFLT) p->l_ksmps; - csound->ekr = csound->pool[csound->poolcount + 1] = p->l_ekr; - csound->onedkr = p->l_onedkr; - csound->onedksmps = p->l_onedksmps; - csound->kicvt = p->l_kicvt; - csound->kcounter = csound->kcounter * p->ksmps_scale; + early = p->h.insdshead->ksmps_no_end; + offset = p->h.insdshead->ksmps_offset; + this_instr->spin = csound->spin; + this_instr->spout = csound->spout; + + /* global ksmps is the caller instr ksmps minus sample-accurate end */ + g_ksmps = CS_KSMPS - early; + + /* sample-accurate offset */ + ofs = offset; + + /* clear offsets, since with CS_KSMPS=1 + they don't apply to opcodes, but to the + calling code (ie. this code) + */ + this_instr->ksmps_offset = 0; + this_instr->ksmps_no_end = 0; - if (csound->ksmps == 1) { /* special case for local kr == sr */ + if (this_instr->ksmps == 1) { /* special case for local kr == sr */ do { /* copy inputs */ tmp = p->buf->iobufp_ptrs; @@ -1594,31 +1713,55 @@ } /* VL: fsigs in need to be dealt with here */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); - } - /* and tsigs */ + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); + } + /* and arrayss */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(TABDAT)); - } - - /* run each opcode */ - csound->pds = (OPDS *) (p->ip); - while ((csound->pds = csound->pds->nxtp)) { - (*csound->pds->opadr)(csound, csound->pds); + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(ARRAYDAT)); + } + if((CS_PDS = (OPDS *) (this_instr->nxtp)) != NULL) { + CS_PDS->insdshead->pds = NULL; + do { + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL + && CS_PDS->insdshead->pds->insdshead) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + }while ((CS_PDS = CS_PDS->nxtp)); } /* copy outputs */ + out = *tmp; while (*(++tmp)) { /* a-rate */ ptr1 = *tmp; (*(++tmp))[ofs] = *ptr1; } - ++(csound->kcounter); + this_instr->kcounter++; + this_instr->spout += csound->nchnls; + this_instr->spin += csound->nchnls; } while (++ofs < g_ksmps); } - else { /* generic case for local kr != sr */ + else { + /* generic case for local kr != sr */ + /* we have to deal with sample-accurate code + whole CS_KSMPS blocks are offset here, the + remainder is left to each opcode to deal with. + */ + int start = 0; + int lksmps = this_instr->ksmps; + while(ofs >= lksmps) { + ofs -= lksmps; + start++; + } + this_instr->ksmps_offset = ofs; + ofs = start; + if(early) this_instr->ksmps_no_end = early % lksmps; + do { /* copy inputs */ tmp = p->buf->iobufp_ptrs; + while (*tmp) { /* a-rate */ ptr1 = *(tmp++) + ofs; ptr2 = *(tmp++); n = csound->ksmps; @@ -1631,29 +1774,39 @@ } /* VL: fsigs in need to be dealt with here */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); - } - /* and tsigs */ + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); + } + /* and arrays */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(TABDAT)); - } + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(ARRAYDAT)); + } /* run each opcode */ - csound->pds = (OPDS *) (p->ip); - while ((csound->pds = csound->pds->nxtp)) { - (*csound->pds->opadr)(csound, csound->pds); + if((CS_PDS = (OPDS *) (this_instr->nxtp)) != NULL) { + CS_PDS->insdshead->pds = NULL; + do { + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL + && CS_PDS->insdshead->pds->insdshead) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + }while ((CS_PDS = CS_PDS->nxtp)); } /* copy outputs */ + out = *tmp; while (*(++tmp)) { /* a-rate */ ptr1 = *tmp; ptr2 = *(++tmp) + ofs; - n = csound->ksmps; + n = lksmps; do { *(ptr2++) = *(ptr1++); } while (--n); } - ++(csound->kcounter); - } while ((ofs += csound->ksmps) < g_ksmps); + this_instr->spout += csound->nchnls*lksmps; + this_instr->spin += csound->nchnls*lksmps; + this_instr->kcounter++; + } while ((ofs += this_instr->ksmps) < g_ksmps); } /* k-rate outputs are copied only in the last sub-kperiod, */ /* so we do it now */ @@ -1662,28 +1815,35 @@ *(*(++tmp)) = *ptr1; } /* VL: fsigs out need to be dealt with here */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(PVSDAT)); + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(PVSDAT)); } - /* tsigs */ + /* arrayss */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(TABDAT)); + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(ARRAYDAT)); } - /* restore globals */ - csound->ksmps = g_ksmps; - csound->pool[csound->poolcount + 2] = (MYFLT) g_ksmps; - csound->ekr = csound->pool[csound->poolcount + 1] = g_ekr; - csound->onedkr = g_onedkr; - csound->onedksmps = g_onedksmps; - csound->kicvt = g_kicvt; - csound->kcounter = g_kcounter; - csound->pds = saved_pds; + /* clear the beginning portion of outputs for sample accurate end */ + if(offset){ + *tmp = out; + while (*(++tmp)) + memset(*(++tmp), '\0', sizeof(MYFLT)*offset); + } + + /* clear the end portion of outputs for sample accurate end */ + if(early){ + *tmp = out; + while (*(++tmp)) + memset(&((*(++tmp))[g_ksmps]), '\0', sizeof(MYFLT)*early); + } + + + CS_PDS = saved_pds; /* check if instrument was deactivated (e.g. by perferror) */ if (!p->ip) /* loop to last opds */ - while (csound->pds->nxtp) csound->pds = csound->pds->nxtp; + while (CS_PDS->nxtp) CS_PDS = CS_PDS->nxtp; return OK; } @@ -1691,19 +1851,19 @@ int useropcd2(CSOUND *csound, UOPCODE *p) { - OPDS *saved_pds = csound->pds; int n; + OPDS *saved_pds = CS_PDS; MYFLT **tmp, *ptr1, *ptr2; + INSDS *this_instr = p->ip; + p->ip->spin = csound->spin; + p->ip->spout = csound->spout; - if (!(csound->pds = (OPDS*) (p->ip->nxtp))) goto endop; /* no perf code */ + if (!(CS_PDS = (OPDS*) (p->ip->nxtp))) goto endop; /* no perf code */ - //csound->Message(csound, "end input\n"); /* FOR SOME REASON the opcode has no perf code */ /* IV - Nov 16 2002: update release flag */ p->ip->relesing = p->parent_ip->relesing; - tmp = p->buf->iobufp_ptrs; - if (csound->ksmps != 1) { /* generic case for kr != sr */ - + if (CS_KSMPS != 1) { /* generic case for kr != sr */ /* copy inputs */ while (*tmp) { /* a-rate */ ptr1 = *(tmp++); ptr2 = *(tmp++); @@ -1718,21 +1878,26 @@ } /* VL: fsigs in need to be dealt with here */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); - } - /* VL: tsigs */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(TABDAT)); - } - - - /* run each opcode */ + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); + } + /* VL: arrays */ + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(ARRAYDAT)); + } + CS_PDS->insdshead->pds = NULL; do { - (*csound->pds->opadr)(csound, csound->pds); - } while ((csound->pds = csound->pds->nxtp)); + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL + && CS_PDS->insdshead->pds->insdshead) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + } while ((CS_PDS = CS_PDS->nxtp)); + + this_instr->kcounter++; /* copy outputs */ while (*(++tmp)) { /* a-rate */ ptr1 = *tmp; ptr2 = *(++tmp); @@ -1752,19 +1917,27 @@ ptr1 = *tmp; *(*(++tmp)) = *ptr1; } /* VL: fsigs in need to be dealt with here */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); - } - /* VL: tsigs */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(TABDAT)); - } + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(PVSDAT)); + } + /* VL: arrays */ + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *) ptr1, sizeof(ARRAYDAT)); + } /* run each opcode */ + CS_PDS->insdshead->pds = NULL; do { - (*csound->pds->opadr)(csound, csound->pds); - } while ((csound->pds = csound->pds->nxtp)); + (*CS_PDS->opadr)(csound, CS_PDS); + if (CS_PDS->insdshead->pds != NULL + && CS_PDS->insdshead->pds->insdshead) { + CS_PDS = CS_PDS->insdshead->pds; + CS_PDS->insdshead->pds = NULL; + } + } while ((CS_PDS = CS_PDS->nxtp)); + + this_instr->kcounter++; /* copy outputs */ while (*(++tmp)) { /* a-rate */ ptr1 = *tmp; *(*(++tmp)) = *ptr1; @@ -1774,24 +1947,42 @@ ptr1 = *tmp; *(*(++tmp)) = *ptr1; } /* VL: fsigs out need to be dealt with here */ - while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(PVSDAT)); - } - /* tsigs */ while (*(++tmp)) { - ptr1 = *tmp; - memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(TABDAT)); - } + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(PVSDAT)); + } + /* arrays */ + while (*(++tmp)) { + ptr1 = *tmp; + memcpy((void *)(*(++tmp)), (void *)ptr1, sizeof(ARRAYDAT)); + } endop: /* restore globals */ - csound->pds = saved_pds; + CS_PDS = saved_pds; /* check if instrument was deactivated (e.g. by perferror) */ if (!p->ip) /* loop to last opds */ - while (csound->pds->nxtp) csound->pds = csound->pds->nxtp; + while (CS_PDS->nxtp) CS_PDS = CS_PDS->nxtp; return OK; } +/* UTILITY FUNCTIONS FOR LABELS */ + +int findLabelMemOffset(CSOUND* csound, INSTRTXT* ip, char* labelName) { + OPTXT* optxt = (OPTXT*) ip; + int offset = 0; + + while ((optxt = optxt->nxtop) != NULL) { + TEXT* t = &optxt->t; + if (strcmp(t->oentry->opname, "$label") == 0 && + strcmp(t->opcod, labelName) == 0) { + break; + } + offset += t->oentry->dsblksiz; + } + + return offset; +} + /* create instance of an instr template */ /* allocates and sets up all pntrs */ @@ -1802,20 +1993,17 @@ OPTXT *optxt; OPDS *opds, *prvids, *prvpds; const OENTRY *ep; - LBLBLK **lopdsp; - LARGNO *largp; - int n, cnt, pextent, opnum, pextra; + int n, /*cnt, */pextent, pextra; char *nxtopds, *opdslim; - MYFLT **argpp, *lclbas, *gbloffbas, *lcloffbas; - int *ndxp; + MYFLT **argpp, *lclbas, /* *gbloffbas,*/ *lcloffbas; + char* opMemStart; + OPARMS *O = csound->oparms; int odebug = O->odebug; + ARG* arg; + int argStringCount; - lopdsp = csound->lopds; - largp = (LARGNO*) csound->larg; - tp = csound->instrtxtp[insno]; - /* VL: added 2 extra MYFLT pointers to the memory to account for possible - use by midi mapping flags */ + tp = csound->engineState.instrtxtp[insno]; n = 3; if (O->midiKey>n) n = O->midiKey; if (O->midiKeyCps>n) n = O->midiKeyCps; @@ -1824,10 +2012,13 @@ if (O->midiVelocity>n) n = O->midiVelocity; if (O->midiVelocityAmp>n) n = O->midiVelocityAmp; pextra = n-3; - pextent = sizeof(INSDS) + tp->pextrab + pextra*sizeof(MYFLT *); /* alloc new space, */ - ip = (INSDS*) mcalloc(csound, (size_t) pextent + tp->localen + tp->opdstot); + /* alloc new space, */ + pextent = sizeof(INSDS) + tp->pextrab + pextra*sizeof(MYFLT *); + ip = (INSDS*) mcalloc(csound, + (size_t) pextent + tp->varPool->poolSize + tp->opdstot); ip->csound = csound; ip->m_chnbp = (MCHNBLK*) NULL; + ip->instr = tp; /* IV - Oct 26 2002: replaced with faster version (no search) */ ip->prvinstance = tp->lst_instance; if (tp->lst_instance) @@ -1839,17 +2030,20 @@ ip->nxtact = tp->act_instance; tp->act_instance = ip; ip->insno = insno; - /* IV - Nov 10 2002 */ - if (insno > csound->maxinsno) { + + if (insno > csound->engineState.maxinsno) { size_t pcnt = (size_t) tp->opcode_info->perf_incnt; pcnt += (size_t) tp->opcode_info->perf_outcnt; pcnt = sizeof(OPCOD_IOBUFS) + sizeof(MYFLT*) * (pcnt << 1); ip->opcod_iobufs = (void*) mmalloc(csound, pcnt); } - gbloffbas = csound->gbloffbas; + + /* gbloffbas = csound->globalVarPool; */ lcloffbas = &ip->p0; lclbas = (MYFLT*) ((char*) ip + pextent); /* split local space */ - nxtopds = (char*) lclbas + tp->localen; + initializeVarPool(lclbas, tp->varPool); + + opMemStart = nxtopds = (char*) lclbas + tp->varPool->poolSize; opdslim = nxtopds + tp->opdstot; if (UNLIKELY(odebug)) csound->Message(csound, @@ -1859,26 +2053,26 @@ prvids = prvpds = (OPDS*) ip; while ((optxt = optxt->nxtop) != NULL) { /* for each op in instr */ TEXT *ttp = &optxt->t; - if ((opnum = ttp->opnum) == ENDIN /* (until ENDIN) */ - || opnum == ENDOP) /* (or ENDOP) */ + ep = ttp->oentry; + opds = (OPDS*) nxtopds; /* take reqd opds */ + nxtopds += ep->dsblksiz; + if (strcmp(ep->opname, "endin") == 0 /* (until ENDIN) */ + || strcmp(ep->opname, "endop") == 0) /* (or ENDOP) */ break; - if (opnum == PSET) { + + if (strcmp(ep->opname, "pset") == 0) { ip->p1 = (MYFLT) insno; continue; } - ep = &(csound->opcodlst[opnum]); /* for all ops: */ - opds = (OPDS*) nxtopds; /* take reqd opds */ - nxtopds += ep->dsblksiz; if (UNLIKELY(odebug)) - csound->Message(csound, Str("op %d (%s) allocated at %p\n"), - opnum, ep->opname, opds); + csound->Message(csound, Str("op (%s) allocated at %p\n"), + ep->opname, opds); opds->optext = optxt; /* set common headata */ opds->insdshead = ip; - if (opnum == LABEL) { /* LABEL: */ + if (strcmp(ep->opname, "$label") == 0) { /* LABEL: */ LBLBLK *lblbp = (LBLBLK *) opds; lblbp->prvi = prvids; /* save i/p links */ lblbp->prvp = prvpds; - *lopdsp++ = lblbp; /* log the lbl bp */ continue; /* for later refs */ } if ((ep->thread & 07) == 0) { /* thread 1 OR 2: */ @@ -1901,8 +2095,7 @@ if ((n = ep->thread & 06) != 0) { /* thread 2 OR 4: */ prvpds = prvpds->nxtp = opds; /* link into pchain */ if (!(n & 04) || - ((ttp->pftype == 'k' || ttp->pftype == 'c') && - ep->kopadr != NULL)) + ((ttp->pftype == 'k' || ttp->pftype == 'c') && ep->kopadr != NULL)) opds->opadr = ep->kopadr; /* krate or */ else opds->opadr = ep->aopadr; /* arate */ if (UNLIKELY(odebug)) @@ -1915,78 +2108,117 @@ argpp = (MYFLT **) ((char *) opds + sizeof(OPDS)); else /* user defined opcodes are a special case */ argpp = &(((UOPCODE *) ((char *) opds))->ar[0]); - ndxp = ttp->outoffs->indx; /* for outarg codes: */ - cnt = ttp->outoffs->count; - for (n = 0; n < cnt; n++) { + + arg = ttp->outArgs; + for (n = 0; arg != NULL; n++) { MYFLT *fltp; - int indx = ndxp[n]; - if (indx > 0) /* cvt index to lcl/gbl adr */ - fltp = gbloffbas + indx; - else - fltp = lcloffbas + (-indx); + CS_VARIABLE* var = (CS_VARIABLE*)arg->argPtr; + if (arg->type == ARG_GLOBAL) { + fltp = (MYFLT *) var->memBlock; /* gbloffbas + var->memBlockIndex; */ + } + else if(arg->type == ARG_LOCAL) { + fltp = lclbas + var->memBlockIndex; + } + else if (arg->type == ARG_PFIELD) { + /* VL 1.1.13 - changed lclbas to + lcloffbas so p-fields can be assigned to */ + fltp = lcloffbas + arg->index; + } + else { + csound->Message(csound, "FIXME: Unhandled out-arg type: %d\n", + arg->type); + fltp = NULL; + } argpp[n] = fltp; + arg = arg->next; } - for ( ; ep->outypes[n] != (char) 0; n++) /* if more outypes, pad */ + + for (argStringCount = argsRequired(ep->outypes); + n < argStringCount; + n++) /* if more outypes, pad */ argpp[n] = NULL; - ndxp = ttp->inoffs->indx; /* for inarg codes: */ - cnt = n + ttp->inoffs->count; - for ( ; n < cnt; n++) { - int indx = *(ndxp++); - if (indx > 0) /* cvt ndx to lcl/gbl */ - argpp[n] = gbloffbas + indx; - else if (indx >= LABELIM) - argpp[n] = lcloffbas + (-indx); - else { /* if label ref, defer */ - largp->lblno = indx - LABELOFS; - largp->argpp = &(argpp[n]); - largp++; - } - } - if (UNLIKELY(odebug)) { - csound->Message(csound, "argptrs:"); - cnt = ttp->outoffs->count; - for (n = 0; n < cnt; n++) - csound->Message(csound, "\t%p", (void*) argpp[n]); - for ( ; ep->outypes[n] != (char) 0; n++) - csound->Message(csound, "\tPADOUT"); - ndxp = ttp->inoffs->indx; - cnt = n + ttp->inoffs->count; - for ( ; n < cnt; n++) { - int indx = *(ndxp++); - if (indx >= LABELIM) - csound->Message(csound, "\t%p", (void*) argpp[n]); - else - csound->Message(csound, "\t***lbl"); - } - csound->Message(csound, "\n"); - } - } - /* if (nxtopds != opdslim) { */ - /* csound->Message(csound, Str("nxtopds = %p opdslim = %p\n"), - nxtopds, opdslim); */ + + arg = ttp->inArgs; + ip->lclbas = lclbas; + for (; arg != NULL; n++, arg = arg->next) { + CS_VARIABLE* var = (CS_VARIABLE*)(arg->argPtr); + if(arg->type == ARG_CONSTANT) { + argpp[n] = csound->engineState.constantsPool->values + arg->index; + } + else if(arg->type == ARG_STRING) { + argpp[n] = (MYFLT*)(arg->argPtr); + } + else if(arg->type == ARG_PFIELD) { + argpp[n] = lcloffbas + arg->index; + } + else if(arg->type == ARG_GLOBAL) { + argpp[n] = (MYFLT *) var->memBlock; /*gbloffbas + var->memBlockIndex; */ + } + else if(arg->type == ARG_LOCAL){ + argpp[n] = lclbas + var->memBlockIndex; + } + else if(arg->type == ARG_LABEL) { + argpp[n] = (MYFLT*)(opMemStart + + findLabelMemOffset(csound, tp, (char*)arg->argPtr)); + } + else { + csound->Message(csound, "FIXME: instance unexpected arg: %d\n", + arg->type); + } + } + + } + + /* VL 13-12-13: point the memory to the local ksmps & kr variables, + and initialise them */ + CS_VARIABLE* var = csoundFindVariableWithName(ip->instr->varPool, "ksmps"); + if(var) { + var->memBlock = lclbas + var->memBlockIndex; + *((MYFLT *)(var->memBlock)) = csound->ksmps; + } + var = csoundFindVariableWithName(ip->instr->varPool, "kr"); + if(var) { + var->memBlock = lclbas + var->memBlockIndex; + *((MYFLT *)(var->memBlock)) = csound->ekr; + } + if (UNLIKELY(nxtopds > opdslim)) csoundDie(csound, Str("inconsistent opds total")); - /* } */ - while (largp > (LARGNO*) csound->larg) { /* now label refs */ - largp--; - *largp->argpp = (MYFLT*) csound->lopds[largp->lblno]; - } + } -int prealloc(CSOUND *csound, AOP *p) + + +int prealloc_(CSOUND *csound, AOP *p, int instname) { int n, a; - n = (int) strarg2opcno(csound, p->r, (p->XSTRCODE & 1), - (*p->b == FL(0.0) ? 0 : 1)); + if(instname) + n = (int) strarg2opcno(csound, ((STRINGDAT*)p->r)->data, 1, + (*p->b == FL(0.0) ? 0 : 1)); + else { + if(ISSTRCOD(*p->r)) + n = (int) strarg2opcno(csound, get_arg_string(csound,*p->r), 1, + (*p->b == FL(0.0) ? 0 : 1)); + else n = *p->r; + } + if (UNLIKELY(n < 1)) return NOTOK; - a = (int) *p->a - csound->instrtxtp[n]->active; + a = (int) *p->a - csound->engineState.instrtxtp[n]->active; for ( ; a > 0; a--) instance(csound, n); return OK; } +int prealloc(CSOUND *csound, AOP *p){ + return prealloc_(csound,p,0); +} + +int prealloc_S(CSOUND *csound, AOP *p){ + return prealloc_(csound,p,1); +} + int delete_instr(CSOUND *csound, DELETEIN *p) { int n; @@ -1996,18 +2228,20 @@ int isNamedInstr = (int) csound->GetInputArgSMask(p); if (isNamedInstr) - n = csound->strarg2insno(csound, p->insno, isNamedInstr); + n = csound->strarg2insno(csound, ((STRINGDAT *)p->insno)->data, isNamedInstr); else n = (int) (*p->insno + FL(0.5)); - if (n < 1 || n > csound->maxinsno || csound->instrtxtp[n] == NULL) + if (n < 1 || + n > csound->engineState.maxinsno || + csound->engineState.instrtxtp[n] == NULL) return OK; /* Instrument does not exist so noop */ - ip = csound->instrtxtp[n]; + ip = csound->engineState.instrtxtp[n]; active = ip->instance; while (active != NULL) { /* Check there are no active instances */ INSDS *nxt = active->nxtinstance; if (UNLIKELY(active->actflg)) { /* Can only remove non-active instruments */ - char *name = csound->instrtxtp[n]->insname; + char *name = csound->engineState.instrtxtp[n]->insname; if (name) return csound->InitError(csound, Str("Instrument %s is still active"), name); @@ -2016,7 +2250,7 @@ Str("Instrument %d is still active"), n); } #if 0 - if (active->opcod_iobufs && active->insno > csound->maxinsno) + if (active->opcod_iobufs && active->insno > csound->engineState.maxinsno) mfree(csound, active->opcod_iobufs); /* IV - Nov 10 2002 */ #endif if (active->fdchp != NULL) @@ -2026,9 +2260,11 @@ mfree(csound, active); active = nxt; } - csound->instrtxtp[n] = NULL; + csound->engineState.instrtxtp[n] = NULL; /* Now patch it out */ - for (txtp = &(csound->instxtanchor); txtp != NULL; txtp = txtp->nxtinstxt) + for (txtp = &(csound->engineState.instxtanchor); + txtp != NULL; + txtp = txtp->nxtinstxt) if (txtp->nxtinstxt == ip) { OPTXT *t = ip->nxtop; txtp->nxtinstxt = ip->nxtinstxt; @@ -2042,3 +2278,124 @@ } return NOTOK; } + +PUBLIC int csoundKillInstance(CSOUND *csound, MYFLT instr, char *instrName, + int mode, int allow_release) +{ + INSDS *ip, *ip2, *nip; + int insno; + + csoundLockMutex(csound->API_lock); + if(instrName){ + insno = named_instr_find(csound, instrName); + instr = (MYFLT) insno; + } else insno = instr; + + if (UNLIKELY(insno < 1 || insno > (int) csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL)) { + return CSOUND_ERROR; + } + + if (UNLIKELY(mode < 0 || mode > 15 || (mode & 3) == 3)) { + return CSOUND_ERROR; + } + ip = &(csound->actanchor); + ip2 = NULL; + + while ((ip = ip->nxtact) != NULL && (int) ip->insno != insno); + if (ip == NULL) + return CSOUND_ERROR; + do { /* This loop does not terminate in mode=0 */ + nip = ip->nxtact; + if (((mode & 8) && ip->offtim >= 0.0) || + ((mode & 4) && ip->p1 != instr) || + (allow_release && ip->relesing)) { + ip = nip; + continue; + } + if (!(mode & 3)) { + if (allow_release) { + xturnoff(csound, ip); + } + else { + nip = ip->nxtact; + xturnoff_now(csound, ip); + } + } + else { + ip2 = ip; + if ((mode & 3) == 1) + break; + } + ip = nip; + } while (ip != NULL && (int) ip->insno == insno); + if (ip2 != NULL) { + if (allow_release) { + xturnoff(csound, ip2); + } + else { + xturnoff_now(csound, ip2); + } + } + csoundUnlockMutex(csound->API_lock); + return CSOUND_SUCCESS; +} + + + +/** + In realtime mode, this function takes care of the init pass in a + separate thread. + Any new instances will have their init-pass code executed here. + This thread is started by musmon() and killed by csoundCleanup() +*/ +void *init_pass_thread(void *p){ + CSOUND *csound = (CSOUND *) p; + INSDS *ip; + int done; + float wakeup = (1000*csound->ksmps/csound->esr); + while(csound->init_pass_loop) { + +#if defined(MACOSX) || defined(LINUX) || defined(HAIKU) + usleep(1000*wakeup); +#else + csoundSleep(((int)wakeup > 0) ? wakeup : 1); +#endif + ip = csound->actanchor.nxtact; + /* do init pass for this instr */ + while(ip != NULL){ + INSDS *nxt = ip->nxtact; +#ifdef HAVE_ATOMIC_BUILTIN + done = __sync_fetch_and_add((int *) &ip->init_done, 0); +#else + done = ip->init_done; +#endif + if (done == 0) { + csoundLockMutex(csound->init_pass_threadlock); + csound->ids = (OPDS *) (ip->nxti); + csound->curip = ip; + while (csound->ids != NULL) { + if (csound->oparms->odebug) + csound->Message(csound, "init %s:\n", + csound->ids->optext->t.oentry->opname); + (*csound->ids->iopadr)(csound, csound->ids); + csound->ids = csound->ids->nxti; + } + ip->tieflag = 0; +#ifdef HAVE_ATOMIC_BUILTIN + __sync_lock_test_and_set((int*)&ip->init_done,1); +#else + ip->init_done = 1; +#endif + if (ip->reinitflag==1) { + ip->reinitflag = 0; + } + csoundUnlockMutex(csound->init_pass_threadlock); + } + ip = nxt; + + } + + } + return NULL; +} diff -Nru csound-5.17.11~dfsg/Engine/linevent.c csound-6.02~dfsg/Engine/linevent.c --- csound-5.17.11~dfsg/Engine/linevent.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/linevent.c 2014-01-07 16:54:20.000000000 +0000 @@ -22,11 +22,7 @@ */ #include "csoundCore.h" /* LINEVENT.C */ -#include "text.h" #include -#if (defined(mac_classic) && defined(__MWERKS__)) || defined(SYMANTEC) -#include -#endif #include "linevent.h" @@ -43,51 +39,40 @@ # endif #endif -#define LBUFSIZ 32768 +//#define LBUFSIZ 32768 #define LF '\n' -typedef struct { - char *Linep, *Linebufend; - FILE *Linecons; - int stdmode; - EVTBLK prve; - char Linebuf[LBUFSIZ]; -} LINEVENT_GLOBALS; +/* typedef struct { */ +/* char *Linep, *Linebufend; */ +/* FILE *Linecons; */ +/* int stdmode; */ +/* EVTBLK prve; */ +/* char Linebuf[LBUFSIZ]; */ +/* } LINEVENT_GLOBALS; */ static void sensLine(CSOUND *csound, void *userData); -#define ST(x) (((LINEVENT_GLOBALS*) ((CSOUND*) csound)->lineventGlobals)->x) +#define STA(x) (csound->lineventStatics.x) void RTLineset(CSOUND *csound) /* set up Linebuf & ready the input files */ { /* callable once from musmon.c */ OPARMS *O = csound->oparms; - csound->lineventGlobals = (LINEVENT_GLOBALS*) - csound->Calloc(csound, sizeof(LINEVENT_GLOBALS)); - ST(prve).opcod = ' '; - ST(Linebufend) = ST(Linebuf) + LBUFSIZ; - ST(Linep) = ST(Linebuf); + /* csound->lineventGlobals = (LINEVENT_GLOBALS*) */ + /* csound->Calloc(csound, */ + /* sizeof(LINEVENT_GLOBALS)); */ + STA(linebufsiz) = LBUFSIZ; + STA(Linebuf) = (char *) csound->Calloc(csound, STA(linebufsiz)); + STA(prve).opcod = ' '; + STA(Linebufend) = STA(Linebuf) + STA(linebufsiz); + STA(Linep) = STA(Linebuf); if (strcmp(O->Linename, "stdin") == 0) { -#ifdef SYMANTEC - console_options.top += 10; - console_options.left += 10; - console_options.title = "\pRT Line_events"; - console_options.nrows = 10; - console_options.ncols = 50; - ST(Linecons) = fopenc(); - cshow(ST(Linecons)); -#elif defined(mills_macintosh) - ST(Linecons) = stdin; +#if defined(DOSGCC) || defined(WIN32) setvbuf(stdin, NULL, _IONBF, 0); + /* WARNING("-L stdin: system has no fcntl function to get stdin"); */ #else - #if defined(DOSGCC) || defined(__WATCOMC__) || defined(WIN32) || \ - defined(mills_macintosh) - setvbuf(stdin, NULL, _IONBF, 0); - /* WARNING("-L stdin: system has no fcntl function to get stdin"); */ - #else - ST(stdmode) = fcntl(csound->Linefd, F_GETFL, 0); - if (UNLIKELY(fcntl(csound->Linefd, F_SETFL, ST(stdmode) | O_NDELAY) < 0)) + STA(stdmode) = fcntl(csound->Linefd, F_GETFL, 0); + if (UNLIKELY(fcntl(csound->Linefd, F_SETFL, STA(stdmode) | O_NDELAY) < 0)) csoundDie(csound, Str("-L stdin fcntl failed")); - #endif #endif } #ifdef PIPES @@ -99,11 +84,7 @@ else csoundDie(csound, Str("Cannot open %s"), O->Linename); } #endif -#if defined(mills_macintosh) || defined(SYMANTEC) -#define MODE -#else #define MODE ,0 -#endif #if defined(MSVC) #define O_RDONLY _O_RDONLY #endif @@ -111,7 +92,7 @@ if (UNLIKELY((csound->Linefd=open(O->Linename, O_RDONLY|O_NDELAY MODE)) < 0)) csoundDie(csound, Str("Cannot open %s"), O->Linename); csound->Message(csound, Str("stdmode = %.8x Linefd = %d\n"), - ST(stdmode), csound->Linefd); + STA(stdmode), csound->Linefd); csound->RegisterSenseEventCallback(csound, sensLine, NULL); } @@ -121,32 +102,26 @@ void RTclose(CSOUND *csound) { - if (csound->oparms->Linein == 0 || csound->lineventGlobals == NULL) + if (csound->oparms->Linein == 0) return; csound->oparms->Linein = 0; csound->Message(csound, Str("stdmode = %.8x Linefd = %d\n"), - ST(stdmode), csound->Linefd); -#if defined(mills_macintosh) || defined(SYMANTEC) - if (ST(Linecons) != NULL) - fclose(ST(Linecons)); -#else - #ifdef PIPES + STA(stdmode), csound->Linefd); +#ifdef PIPES if (csound->oparms->Linename[0] == '|') _pclose(csound->Linepipe); else - #endif - { - if (strcmp(csound->oparms->Linename, "stdin") != 0) - close(csound->Linefd); - #if !defined(DOSGCC) && !defined(__WATCOMC__) && !defined(WIN32) && \ - !defined(mills_macintosh) - else - fcntl(csound->Linefd, F_SETFL, ST(stdmode)); - #endif - } -#endif /* !(mills_macintosh || SYMANTEC) */ - csound->Free(csound, csound->lineventGlobals); - csound->lineventGlobals = NULL; +#endif + { + if (strcmp(csound->oparms->Linename, "stdin") != 0) + close(csound->Linefd); +#if !defined(DOSGCC) && !defined(WIN32) + else + fcntl(csound->Linefd, F_SETFL, STA(stdmode)); +#endif + } +//csound->Free(csound, csound->lineventGlobals); +//csound->lineventGlobals = NULL; } /* does string segment contain LF? */ @@ -160,24 +135,34 @@ return 0; } -static CS_NOINLINE int linevent_alloc(CSOUND *csound) +static CS_NOINLINE int linevent_alloc(CSOUND *csound, int reallocsize) { volatile jmp_buf tmpExitJmp; int err; + if (reallocsize > 0) { + STA(Linebuf) = (char *) csound->ReAlloc(csound, + (void *) STA(Linebuf), reallocsize); + STA(linebufsiz) = reallocsize; + STA(Linebufend) = STA(Linebuf) + STA(linebufsiz); + } else if (STA(Linebuf)==NULL) { + STA(linebufsiz) = LBUFSIZ; + STA(Linebuf) = (char *) csound->Calloc(csound, STA(linebufsiz)); + } + if(STA(Linebuf) == NULL) return 1; + + if (STA(Linep)) return 0; csound->Linefd = -1; memcpy((void*) &tmpExitJmp, (void*) &csound->exitjmp, sizeof(jmp_buf)); if ((err = setjmp(csound->exitjmp)) != 0) { memcpy((void*) &csound->exitjmp, (void*) &tmpExitJmp, sizeof(jmp_buf)); - csound->lineventGlobals = NULL; + //csound->lineventGlobals = NULL; return -1; } - csound->lineventGlobals = - (LINEVENT_GLOBALS*) mcalloc(csound, sizeof(LINEVENT_GLOBALS)); memcpy((void*) &csound->exitjmp, (void*) &tmpExitJmp, sizeof(jmp_buf)); - ST(prve).opcod = ' '; - ST(Linebufend) = ST(Linebuf) + LBUFSIZ; - ST(Linep) = ST(Linebuf); + STA(prve).opcod = ' '; + STA(Linebufend) = STA(Linebuf) + STA(linebufsiz); + STA(Linep) = STA(Linebuf); csound->RegisterSenseEventCallback(csound, sensLine, NULL); return 0; @@ -186,25 +171,25 @@ /* insert text from an external source, to be interpreted as if coming in from stdin/Linefd for -L */ -PUBLIC void csoundInputMessage(CSOUND *csound, const char *message) +void csoundInputMessageInternal(CSOUND *csound, const char *message) { int32 size = (int32) strlen(message); + int n; - if (!csound->lineventGlobals) { - if (linevent_alloc(csound) != 0) + if ((n=linevent_alloc(csound, 0)) != 0) return; + if (!size) return; + if (UNLIKELY((STA(Linep) + size) >= STA(Linebufend))) { + int extralloc = STA(Linep) + size - STA(Linebufend); + if ((n=linevent_alloc(csound, STA(linebufsiz) + extralloc ), 0) != 0) { + csoundErrorMsg(csound, Str("LineBuffer Overflow - " + "Input Data has been Lost")); return; + } } - if (!size) - return; - if (UNLIKELY((ST(Linep) + size) >= ST(Linebufend))) { - csoundErrorMsg(csound, Str("LineBuffer Overflow - " - "Input Data has been Lost")); - return; - } - memcpy(ST(Linep), message, size); - if (ST(Linep)[size - 1] != (char) '\n') - ST(Linep)[size++] = (char) '\n'; - ST(Linep) += size; + memcpy(STA(Linep), message, size); + if (STA(Linep)[size - 1] != (char) '\n') + STA(Linep)[size++] = (char) '\n'; + STA(Linep) += size; } /* accumlate RT Linein buffer, & place completed events in EVTBLK */ @@ -214,26 +199,26 @@ { char *cp, *Linestart, *Linend; int c, n, pcnt; + IGN(userData); while (1) { - Linend = ST(Linep); + Linend = STA(Linep); if (csound->Linefd >= 0) { -#if defined(mills_macintosh) || defined(SYMANTEC) - n = fread((void *) Linend, (size_t) 1, - (size_t) (ST(Linebufend) - Linend), ST(Linecons)); -#else - n = read(csound->Linefd, Linend, ST(Linebufend) - Linend); -#endif + n = read(csound->Linefd, Linend, STA(Linebufend) - Linend); Linend += (n > 0 ? n : 0); } - if (Linend <= ST(Linebuf)) + if (Linend <= STA(Linebuf)) break; - Linestart = ST(Linebuf); + Linestart = STA(Linebuf); cp = Linestart; + while (containsLF(Linestart, Linend)) { EVTBLK e; - char sstrp[SSTRSIZ]; - e.strarg = NULL; + char *sstrp = NULL; + int scnt = 0; + int strsiz = 0; + memset(&e, 0, sizeof(EVTBLK)); + e.strarg = NULL; e.scnt = 0; c = *cp; while (c == ' ' || c == '\t') /* skip initial white space */ c = *(++cp); @@ -263,10 +248,10 @@ break; pcnt++; if (c == '"') { /* if find character string */ - if (UNLIKELY(e.strarg != NULL)) { - csound->ErrorMsg(csound, Str("multiple string p-fields")); - goto Lerr; - } + if (e.strarg == NULL) + e.strarg = sstrp = mmalloc(csound, strsiz=SSTRSIZ); + n = scnt; + while (n-->0) sstrp += strlen(sstrp)+1; n = 0; while ((c = *(++cp)) != '"') { if (UNLIKELY(c == LF)) { @@ -274,14 +259,21 @@ goto Lerr; } sstrp[n++] = c; /* save in private strbuf */ - if (UNLIKELY(n >= SSTRSIZ)) { - csound->ErrorMsg(csound, Str("string p-field is too long")); - goto Lerr; + if (UNLIKELY((sstrp-e.strarg)+n >= strsiz-10)) { + e.strarg = mrealloc(csound, e.strarg, strsiz+=SSTRSIZ); + sstrp = e.strarg+n; } } sstrp[n] = '\0'; - e.strarg = &(sstrp[0]); - e.p[pcnt] = SSTRCOD; /* & store coded float */ + { + union { + MYFLT d; + int32 i; + } ch; + ch.d = SSTRCOD; ch.i += scnt++; + e.p[pcnt] = ch.d; /* set as string with count */ + } + e.scnt = scnt; continue; } if (UNLIKELY(!(isdigit(c) || c == '+' || c == '-' || c == '.'))) @@ -289,18 +281,18 @@ if (c == '.' && /* if lone dot, */ ((n = cp[1]) == ' ' || n == '\t' || n == LF)) { if (UNLIKELY(e.opcod != 'i' || - ST(prve).opcod != 'i' || pcnt > ST(prve).pcnt)) { + STA(prve).opcod != 'i' || pcnt > STA(prve).pcnt)) { csound->ErrorMsg(csound, Str("dot carry has no reference")); goto Lerr; } /* pfld carry */ - e.p[pcnt] = ST(prve).p[pcnt]; - if (UNLIKELY(e.p[pcnt] == SSTRCOD)) { + e.p[pcnt] = STA(prve).p[pcnt]; + if (UNLIKELY(ISSTRCOD(e.p[pcnt]))) { csound->ErrorMsg(csound, Str("cannot carry string p-field")); goto Lerr; } continue; } - e.p[pcnt] = (MYFLT) strtod(cp, &newcp); + e.p[pcnt] = (MYFLT) cs_strtod(cp, &newcp); cp = newcp - 1; } while (pcnt < PMAX); if (e.opcod =='f' && e.p[1]= PMAX && c != LF)) { csound->ErrorMsg(csound, Str("too many pfields")); @@ -328,7 +320,7 @@ Linestart = (++cp); insert_score_event_at_sample(csound, &e, csound->icurTime); continue; - Lerr: + Lerr: n = cp - Linestart; /* error position */ while (*cp != LF) cp++; /* go on to LF */ @@ -337,18 +329,18 @@ Linestart, n + 1, "^"); /* mark the error */ Linestart = (++cp); } - if (Linestart != &(ST(Linebuf)[0])) { + if (Linestart != &(STA(Linebuf)[0])) { int len = (int) (Linend - Linestart); /* move any remaining characters to the beginning of the buffer */ for (n = 0; n < len; n++) - ST(Linebuf)[n] = Linestart[n]; - n = (int) (Linestart - &(ST(Linebuf)[0])); - ST(Linep) -= n; + STA(Linebuf)[n] = Linestart[n]; + n = (int) (Linestart - &(STA(Linebuf)[0])); + STA(Linep) -= n; Linend -= n; } - if (Linend == ST(Linep)) /* return if no more data is available */ + if (Linend == STA(Linep)) /* return if no more data is available */ break; - ST(Linep) = Linend; /* accum the chars */ + STA(Linep) = Linend; /* accum the chars */ } } @@ -359,69 +351,103 @@ static const char *errmsg_2 = Str_noop("event: string name is allowed only for \"i\" and \"q\" events"); -int eventOpcode(CSOUND *csound, LINEVENT *p) +int eventOpcode_(CSOUND *csound, LINEVENT *p, int insname, char p1) { EVTBLK evt; int i; char opcod; + memset(&evt, 0, sizeof(EVTBLK)); - opcod = ((char*) p->args[0])[0]; - if ((opcod != 'a' && opcod != 'i' && opcod != 'q' && opcod != 'f' && - opcod != 'e') || ((char*) p->args[0])[1] != '\0') - return csound->PerfError(csound, Str(errmsg_1)); - evt.strarg = NULL; + if (p1==0) + opcod = *((STRINGDAT*) p->args[0])->data; + else opcod = p1; + + if (UNLIKELY((opcod != 'a' && opcod != 'i' && opcod != 'q' && opcod != 'f' && + opcod != 'e') /*|| ((STRINGDAT*) p->args[0])->data[1] != '\0'*/)) + return csound->PerfError(csound, p->h.insdshead,Str(errmsg_1)); + evt.strarg = NULL; evt.scnt = 0; evt.opcod = opcod; - evt.pcnt = p->INOCOUNT - 1; + if (p->flag==1) evt.pcnt = p->argno-2; + else + evt.pcnt = p->INOCOUNT - 1; + /* IV - Oct 31 2002: allow string argument */ if (evt.pcnt > 0) { - if (p->XSTRCODE & 2) { + if (insname) { if (UNLIKELY(evt.opcod != 'i' && evt.opcod != 'q')) - return csound->PerfError(csound, Str(errmsg_2)); - evt.p[1] = SSTRCOD; - evt.strarg = (char*) p->args[1]; + return csound->PerfError(csound, p->h.insdshead,Str(errmsg_2)); + evt.p[1] = csound->strarg2insno(csound, + ((STRINGDAT*) p->args[1])->data, 1); + evt.strarg = NULL; evt.scnt = 0; } else { - evt.p[1] = *p->args[1]; - evt.strarg = NULL; + if (ISSTRCOD(*p->args[1])) { + evt.p[1] = csound->strarg2insno(csound, + get_arg_string(csound, *p->args[1]), 1); + } else evt.p[1] = *p->args[1]; + evt.strarg = NULL; evt.scnt = 0; } for (i = 2; i <= evt.pcnt; i++) evt.p[i] = *p->args[i]; } if (insert_score_event_at_sample(csound, &evt, csound->icurTime) != 0) - return csound->PerfError(csound, Str("event: error creating '%c' event"), - opcod); + return csound->PerfError(csound, p->h.insdshead, + Str("event: error creating '%c' event"), + opcod); return OK; } +int eventOpcode(CSOUND *csound, LINEVENT *p) +{ + return eventOpcode_(csound, p, 0, 0); +} + +int eventOpcode_S(CSOUND *csound, LINEVENT *p) +{ + return eventOpcode_(csound, p, 1, 0); +} + + + /* i-time version of event opcode */ -int eventOpcodeI(CSOUND *csound, LINEVENT *p) +int eventOpcodeI_(CSOUND *csound, LINEVENT *p, int insname, char p1) { EVTBLK evt; int i, err = 0; char opcod; + memset(&evt, 0, sizeof(EVTBLK)); - opcod = ((char*) p->args[0])[0]; + if(p1==0) + opcod = *((STRINGDAT*) p->args[0])->data; + else opcod = p1; if (UNLIKELY((opcod != 'a' && opcod != 'i' && opcod != 'q' && opcod != 'f' && - opcod != 'e') || ((char*) p->args[0])[1] != '\0')) + opcod != 'e') /*|| ((STRINGDAT*) p->args[0])->data[1] != '\0'*/)) return csound->InitError(csound, Str(errmsg_1)); - evt.strarg = NULL; + evt.strarg = NULL; evt.scnt = 0; evt.opcod = opcod; - evt.pcnt = p->INOCOUNT - 1; + if(p->flag==1) evt.pcnt = p->argno-1; + else + evt.pcnt = p->INOCOUNT - 1; /* IV - Oct 31 2002: allow string argument */ if (evt.pcnt > 0) { - if (p->XSTRCODE & 2) { + if (insname) { if (UNLIKELY(evt.opcod != 'i' && evt.opcod != 'q')) return csound->InitError(csound, Str(errmsg_2)); - evt.p[1] = SSTRCOD; - evt.strarg = (char*) p->args[1]; + evt.p[1] = csound->strarg2insno(csound,((STRINGDAT *)p->args[1])->data, 1); + evt.strarg = NULL; evt.scnt = 0; + for (i = 2; i <= evt.pcnt; i++) + evt.p[i] = *p->args[i]; } else { - evt.p[1] = *p->args[1]; - evt.strarg = NULL; + evt.strarg = NULL; evt.scnt = 0; + if (ISSTRCOD(*p->args[1])) { + evt.p[1] = csound->strarg2insno(csound, + get_arg_string(csound, *p->args[1]), 1); + } else evt.p[1] = *p->args[1]; + for (i = 2; i <= evt.pcnt; i++) + evt.p[i] = *p->args[i]; } - for (i = 2; i <= evt.pcnt; i++) - evt.p[i] = *p->args[i]; } if (opcod == 'f' && (int) evt.pcnt >= 2 && evt.p[2] <= FL(0.0)) { FUNC *dummyftp; @@ -435,3 +461,58 @@ return (err == 0 ? OK : NOTOK); } +int eventOpcodeI(CSOUND *csound, LINEVENT *p) +{ + return eventOpcodeI_(csound, p, 0, 0); +} + +int eventOpcodeI_S(CSOUND *csound, LINEVENT *p) +{ + return eventOpcodeI_(csound, p, 1, 0); +} + +int instanceOpcode_(CSOUND *csound, LINEVENT2 *p, int insname) +{ + EVTBLK evt; + int i; + + evt.strarg = NULL; evt.scnt = 0; + evt.opcod = 'i'; + evt.pcnt = p->INOCOUNT; + + /* pass in the memory to hold the instance after insertion */ + evt.pinstance = (void *) p->inst; + + /* IV - Oct 31 2002: allow string argument */ + if (evt.pcnt > 0) { + if (insname) { + evt.p[1] = csound->strarg2insno(csound, + ((STRINGDAT*) p->args[0])->data, 1); + evt.strarg = NULL; evt.scnt = 0; + } + else { + if (ISSTRCOD(*p->args[0])) { + evt.p[1] = csound->strarg2insno(csound, + get_arg_string(csound, *p->args[0]), 1); + } else evt.p[1] = *p->args[0]; + evt.strarg = NULL; evt.scnt = 0; + } + for (i = 2; i <= evt.pcnt; i++) + evt.p[i] = *p->args[i-1]; + } + if (insert_score_event_at_sample(csound, &evt, csound->icurTime) != 0) + return csound->PerfError(csound, p->h.insdshead, + Str("instance: error creating event")); + + return OK; +} + +int instanceOpcode(CSOUND *csound, LINEVENT2 *p) +{ + return instanceOpcode_(csound, p, 0); +} + +int instanceOpcode_S(CSOUND *csound, LINEVENT2 *p) +{ + return instanceOpcode_(csound, p, 1); +} diff -Nru csound-5.17.11~dfsg/Engine/memalloc.c csound-6.02~dfsg/Engine/memalloc.c --- csound-5.17.11~dfsg/Engine/memalloc.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/memalloc.c 2014-01-07 16:53:47.000000000 +0000 @@ -129,16 +129,18 @@ if (UNLIKELY(p == NULL)) return; pp = HDR_PTR(p); -#ifdef MEMDEBUG + #ifdef MEMDEBUG if (UNLIKELY(pp->magic != MEMALLOC_MAGIC || pp->ptr != p)) { - csound->DebugMsg(csound, " *** internal error: mfree() called with invalid " - "pointer (%p)\n", p); + csound->Warning(csound, "mfree() called with invalid " + "pointer (%p)", p); /* exit() is ugly, but this is a fatal error that can only occur */ /* as a result of a bug */ - exit(-1); + /* exit(-1); */ + /*VL 28-12-12 - returning from here instead of exit() */ + return; } pp->magic = 0; -#endif + #endif CSOUND_MEM_SPINLOCK /* unlink from chain */ { @@ -150,6 +152,7 @@ else MEMALLOC_DB = (void*)nxt; } + //csound->Message(csound, "free\n"); /* free memory */ free((void*) pp); CSOUND_MEM_SPINUNLOCK @@ -228,4 +231,3 @@ pp = nxtp; } } - diff -Nru csound-5.17.11~dfsg/Engine/memfiles.c csound-6.02~dfsg/Engine/memfiles.c --- csound-5.17.11~dfsg/Engine/memfiles.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/memfiles.c 2014-01-07 16:53:47.000000000 +0000 @@ -25,11 +25,205 @@ #include "csoundCore.h" /* MEMFILES.C */ #include "soundio.h" #include "pvfileio.h" +#include "convolve.h" +#include "lpc.h" #include "pstream.h" #include "namedins.h" #include #include +static int Load_Het_File_(CSOUND *csound, const char *filnam, + char **allocp, int32 *len) +{ + FILE *f; + int length = 1024; + int i = 0; + int cc; + int16 x; + char *all; + char buffer[10]; + f = fopen(filnam, "r"); + csoundNotifyFileOpened(csound, filnam, CSFTYPE_HETRO, 0, 0); + all = (char *)mmalloc(csound, (size_t) length); + for (i=0; i<6; i++) fgetc(f); /* Skip HETRO */ + fgets(buffer, 10, f); /* number of partials */ + x = atoi(buffer); + memcpy(&all[0], &x, sizeof(int16)); + /* Read data until end, pack as int16 */ + for (i=sizeof(int16);;i+=sizeof(int16)) { + int p = 0; + while ((cc=getc(f))!=',' && cc!='\n' && p<15) { + if (cc == EOF) { + goto out; + } + buffer[p++] = cc; + } + buffer[p]='\0'; + /* Expand as necessary */ + if (i>=length-4) all = mrealloc(csound, all, length+=1024); + x = atoi(buffer); + memcpy(&all[i], &x, sizeof(int16)); + } + out: + fclose(f); /* and close it */ + *len = i; + all = mrealloc(csound, all, i); + *allocp = all; + return 0; /* return 0 for OK */ +} + +static MYFLT read_ieee(FILE* f, int *end) +{ + char buff[120]; + double x; + char *p = fgets(buff, 120, f); + + if (p==NULL || feof(f)) { + *end = 1; + return FL(0.0); + } + x = cs_strtod(buff, NULL); + return (MYFLT)x; + /* union { */ + /* double d; */ + /* struct {int j,k;} n; */ + /* int64_t i; */ + /* } x; */ + /* int sign=1, ex; */ + /* int64_t man; */ + /* int64_t bit = 1; */ + /* char buff[32]; */ + /* char *p; */ + /* bit <<= 62; */ + /* p = fgets(buff, 32, f); */ + /* printf("... %s", buff); */ + /* if (p==NULL || feof(f)) { */ + /* printf("ending\n"); */ + /* *end = 1; */ + /* return FL(0.0); */ + /* } */ + /* if (strstr(p, "0x0p+0")) { */ + /* return FL(0.0); */ + /* } */ + /* if (buff[0]=='-') sign=-1; */ + /* p = strchr(buff, '.')+1; */ + /* sscanf(p, "%lxp%d", &man, &ex); */ + /* x.i = man; */ + /* if (man!=(int64_t)0) x.i |= bit; */ + /* x.d = ldexp(x.d, ex-1); */ + /* if (sign<0) x.d =-x.d; */ + /* return (MYFLT)x.d; */ +} + +static int Load_CV_File_(CSOUND *csound, const char *filnam, + char **allocp, int32 *len) +{ + FILE *f; + int length = 4096; + unsigned int i = 0; + int j = 0; + MYFLT x; + char *all; + CVSTRUCT cvh = {0,0,0,0,0.0,0,0,0,0,{0}}; + char buff[120]; + char *p; + + f = fopen(filnam, "r"); + csoundNotifyFileOpened(csound, filnam, CSFTYPE_CVANAL, 0, 0); + all = (char *)mmalloc(csound, (size_t) length); + p = fgets(buff, 120, f); /* Skip CVANAL */ + cvh.magic = CVMAGIC; + p = fgets(buff, 120, f); + cvh.headBsize = strtol(p, &p, 10); + cvh.dataBsize = strtol(p, &p, 10); + cvh.dataFormat = strtol(p, &p, 10); + cvh.samplingRate = (MYFLT)cs_strtod(p, &p); + cvh.src_chnls = strtol(p, &p, 10); + cvh.channel = strtol(p, &p, 10); + cvh.Hlen = strtol(p, &p, 10); + cvh.Format = strtol(p, &p, 10); + /* fscanf(f, "%d %d %d %g %d %d %d %d\n", */ + /* &cvh.headBsize, &cvh.dataBsize, &cvh.dataFormat, */ + /* &cvh.samplingRate, &cvh.src_chnls, &cvh.channel, */ + /* &cvh.Hlen, &cvh.Format); */ + cvh.headBsize = sizeof(int32)*8 + sizeof(MYFLT); + memcpy(&all[0], &cvh, sizeof(CVSTRUCT)); + + /* Read data until end, pack as MYFLTs */ + for (i=sizeof(CVSTRUCT);;i+=sizeof(MYFLT)) { + /* Expand as necessary */ + if (i>=length-sizeof(MYFLT)-4) { + //printf("expanding from %p[%d] to\n", all, length); + all = mrealloc(csound, all, length+=4096); + //printf("i=%d %p[%d]\n", i, all, length); + } x = read_ieee(f, &j); + if (j) break; + memcpy(&all[i], &x, sizeof(MYFLT)); + } + fclose(f); /* and close it */ + //printf("length=%d i=%d\n", length, i); + *len = i; + all = mrealloc(csound, all, i); + *allocp = all; + return 0; /* return 0 for OK */ +} + +static int Load_LP_File_(CSOUND *csound, const char *filnam, + char **allocp, int32 *len) +{ + FILE *f; + int length = 4096; + unsigned int i = 0; + int j = 0; + MYFLT x; + char *all, *p; + LPHEADER lph = {0,0,0,0,0.0,0.0,0.0,{0}}; + char buff[120]; + + f = fopen(filnam, "r"); + csoundNotifyFileOpened(csound, filnam, CSFTYPE_LPC, 0, 0); + all = (char *)mmalloc(csound, (size_t) length); + for (i=0; i<6; i++) fgetc(f); /* Skip LPANAL */ + fscanf(f, "%d %d %d %d\n", + &lph.headersize, &lph.lpmagic, &lph.npoles, &lph.nvals); + fgets(buff, 120, f); + lph.framrate = (MYFLT)cs_strtod(buff, &p); + lph.srate = (MYFLT)cs_strtod(p, &p); + lph.duration = (MYFLT)cs_strtod(p, &p); + /* lph.text[0] = (char)strtol(p, &p, 0); */ + /* lph.text[1] = (char)strtol(p, &p, 0); */ + /* lph.text[2] = (char)strtol(p, &p, 0); */ + /* lph.text[3] = (char)strtol(p, &p, 0); */ + /* printf("LPHeader %d %d %d %d\n%f %f %f\n", */ + /* lph.headersize, lph.lpmagic, lph.npoles, lph.nvals, */ + /* lph.framrate, lph.srate, lph.duration); */ + /* fscanf(f, "%f %f %f %.2x %.2x %.2x %.2x\n", */ + /* &lph.framrate, &lph.srate, &lph.duration, */ + /* &lph.text[0], &lph.text[1], &lph.text[2], &lph.text[3]); */ + // This needs surgery if in/out different MYFLT sizes *** FIX ME *** + lph.headersize = sizeof(int32)*4+sizeof(MYFLT)*3; + memcpy(&all[0], &lph, lph.headersize); + + /* Read data until end, pack as MYFLTs */ + for (i=lph.headersize;;i+=sizeof(MYFLT)) { + /* Expand as necessary */ + if (i>=length-sizeof(MYFLT)-8) { + //printf("expanding from %p[%d] to\n", all, length); + all = mrealloc(csound, all, length+=4096); + //printf("i=%d %p[%d]\n", i, all, length); + } + x = read_ieee(f, &j); + if (j) break; + memcpy(&all[i], &x, sizeof(MYFLT)); + } + fclose(f); /* and close it */ + printf("length=%d i=%u\n", length, i); + *len = i; + all = mrealloc(csound, all, i); + *allocp = all; + return 0; /* return 0 for OK */ +} + static int Load_File_(CSOUND *csound, const char *filnam, char **allocp, int32 *len, int csFileType) { @@ -38,6 +232,30 @@ f = fopen(filnam, "rb"); if (UNLIKELY(f == NULL)) /* if cannot open the file */ return 1; /* return 1 */ + if (csFileType==CSFTYPE_HETRO) { + char buff[8]; + fgets(buff, 6, f); + if (strcmp(buff, "HETRO")==0) { + fclose(f); + return Load_Het_File_(csound, filnam, allocp, len); + } + } + else if (csFileType==CSFTYPE_CVANAL) { + char buff[8]; + fgets(buff, 7, f); + if (strcmp(buff, "CVANAL")==0) { + fclose(f); + return Load_CV_File_(csound, filnam, allocp, len); + } + } + else if (csFileType==CSFTYPE_LPC) { + char buff[8]; + fgets(buff, 7, f); + if (strcmp(buff, "LPANAL")==0) { + fclose(f); + return Load_LP_File_(csound, filnam, allocp, len); + } + } /* notify the host if it asked */ csoundNotifyFileOpened(csound, filnam, csFileType, 0, 0); fseek(f, 0L, SEEK_END); /* then get its length */ @@ -62,19 +280,20 @@ } /* Backwards-compatible wrapper for ldmemfile2(). - Please use ldmemfile2() or ldmemfile2withCB() in all new code instead. */ + Please use ldmemfile2() or ldmemfile2withCB() in all new code instead. MEMFIL *ldmemfile(CSOUND *csound, const char *filnam) { return ldmemfile2withCB(csound, filnam, CSFTYPE_UNKNOWN, NULL); } - +*/ /* Takes an additional parameter specifying the type of the file being opened. The type constants are defined in the enumeration CSOUND_FILETYPES. - Use ldmemfile2() to load file without additional processing. */ + Use ldmemfile2() to load file without additional processing. MEMFIL *ldmemfile2(CSOUND *csound, const char *filnam, int csFileType) { return ldmemfile2withCB(csound, filnam, csFileType, NULL); } +*/ /* This version of ldmemfile2 allows you to specify a callback procedure to process the file's data after it is loaded. This method ensures that @@ -348,33 +567,27 @@ void *fd; SNDMEMFILE *p = NULL; SF_INFO tmp; - unsigned char h; if (UNLIKELY(fileName == NULL || fileName[0] == '\0')) return NULL; + /* check if file is already loaded */ - h = name_hash_2(csound, fileName); if (csound->sndmemfiles != NULL) { - p = ((SNDMEMFILE**) csound->sndmemfiles)[(int) h]; - while (p != NULL && sCmp(p->name, fileName) != 0) - p = p->nxt; + p = cs_hash_table_get(csound, csound->sndmemfiles, (char*)fileName); } else { - int i; - /* if no files loaded yet, allocate table */ - csound->sndmemfiles = csound->Malloc(csound, sizeof(SNDMEMFILE*) * 256); - for (i = 0; i < 256; i++) - ((SNDMEMFILE**) csound->sndmemfiles)[i] = NULL; + csound->sndmemfiles = cs_hash_table_create(csound); } + if (p != NULL) { /* if file was loaded earlier: */ if (sfinfo != NULL) { memset(sfinfo, 0, sizeof(SF_INFO)); sfinfo->frames = (sf_count_t) p->nFrames; - sfinfo->samplerate = ((int) p->sampleRate + 0.5); - sfinfo->channels = p->nChannels; - sfinfo->format = FORMAT2SF(p->sampleFormat) | TYPE2SF(p->fileType); + sfinfo->samplerate = ((int) p->sampleRate + 0.5); + sfinfo->channels = p->nChannels; + sfinfo->format = FORMAT2SF(p->sampleFormat) | TYPE2SF(p->fileType); } return p; } @@ -412,8 +625,6 @@ p->loopEnd = 0.0; p->baseFreq = 1.0; p->scaleFac = 1.0; -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1013 - /* sampler information requires libsndfile version 1.0.13 or later */ { SF_INSTRUMENT lpd; if (sf_command(sf, SFC_GET_INSTRUMENT, &lpd, sizeof(SF_INSTRUMENT)) @@ -434,8 +645,6 @@ p->scaleFac = pow(10.0, (double) lpd.gain * 0.05); } } -#endif /* HAVE_LIBSNDFILE >= 1013 */ - p->nxt = ((SNDMEMFILE**) csound->sndmemfiles)[(int) h]; if ((size_t) sf_readf_float(sf, &(p->data[0]), (sf_count_t) p->nFrames) != p->nFrames) { csound->FileClose(csound, fd); @@ -453,8 +662,10 @@ p->fullName, (int) sfinfo->samplerate, (int) sfinfo->channels, (uint32) sfinfo->frames); + /* link into database */ - ((SNDMEMFILE**) csound->sndmemfiles)[(int) h] = p; + cs_hash_table_put(csound, csound->sndmemfiles, (char*)fileName, p); + /* return with pointer to file structure */ return p; } diff -Nru csound-5.17.11~dfsg/Engine/musmon.c csound-6.02~dfsg/Engine/musmon.c --- csound-5.17.11~dfsg/Engine/musmon.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/musmon.c 2014-01-07 16:54:20.000000000 +0000 @@ -29,7 +29,6 @@ #include "oload.h" #include "remote.h" #include -# include "cscore.h" #include "corfile.h" #define SEGAMPS AMPLMSG @@ -39,7 +38,7 @@ extern int insert(CSOUND *, int, EVTBLK*); extern void MidiOpen(CSOUND *); extern void m_chn_init_all(CSOUND *); -extern void scsortstr(CSOUND *, CORFIL *); +//extern char * scsortstr(CSOUND *, CORFIL *); extern void infoff(CSOUND*, MYFLT), orcompact(CSOUND*); extern void beatexpire(CSOUND *, double), timexpire(CSOUND *, double); extern void sfopenin(CSOUND *), sfopenout(CSOUND*), sfnopenout(CSOUND*); @@ -48,6 +47,7 @@ extern void RTclose(CSOUND *); extern void remote_Cleanup(CSOUND *); extern char **csoundGetSearchPathFromEnv(CSOUND *, const char *); +/* extern void initialize_instrument0(CSOUND *); */ typedef struct evt_cb_func { void (*func)(CSOUND *, void *); @@ -55,17 +55,7 @@ struct evt_cb_func *nxt; } EVT_CB_FUNC; -typedef struct { - int32 srngcnt[MAXCHNLS], orngcnt[MAXCHNLS]; - int16 srngflg; - int16 sectno; - int lplayed; - int segamps, sormsg; - EVENT **ep, **epend; /* pointers for stepping through lplay list */ - EVENT *lsect; -} MUSMON_GLOBALS; - -#define ST(x) (((MUSMON_GLOBALS*) csound->musmonGlobals)->x) +#define STA(x) (csound->musmonStatics.x) /* IV - Jan 28 2005 */ void print_benchmark_info(CSOUND *csound, const char *s) @@ -86,7 +76,7 @@ if (tempo <= FL(0.0)) return; if (csound->oparms->Beatmode==1) csound->ibeatTime = (int64_t)(csound->esr*60.0 / (double) tempo); - csound->curBeat_inc = (double) tempo / (60.0 * (double) csound->global_ekr); + csound->curBeat_inc = (double) tempo / (60.0 * (double) csound->ekr); } int gettempo(CSOUND *csound, GTEMPO *p) @@ -195,8 +185,6 @@ CS_PACKAGE_VERSION, __DATE__); #endif #endif - if (LIKELY(csound->musmonGlobals == NULL)) - csound->musmonGlobals = csound->Calloc(csound, sizeof(MUSMON_GLOBALS)); /* initialise search path cache */ csoundGetSearchPathFromEnv(csound, "SNAPDIR"); csoundGetSearchPathFromEnv(csound, "SFDIR;SSDIR;INCDIR"); @@ -206,11 +194,42 @@ m_chn_init_all(csound); /* allocate MIDI channels */ dispinit(csound); /* initialise graphics or character display */ - oload(csound); /* set globals and run inits */ + + reverbinit(csound); + dbfs_init(csound, csound->e0dbfs); + csound->nspout = csound->ksmps * csound->nchnls; /* alloc spin & spout */ + csound->nspin = csound->ksmps * csound->inchnls; /* JPff: in preparation */ + csound->spin = (MYFLT *) mcalloc(csound, csound->nspin * sizeof(MYFLT)); + csound->spout = (MYFLT *) mcalloc(csound, csound->nspout * sizeof(MYFLT)); + csound->auxspin = (MYFLT *) mcalloc(csound, csound->nspin * sizeof(MYFLT)); + /* memset(csound->maxamp, '\0', sizeof(MYFLT)*MAXCHNLS); */ + /* memset(csound->smaxamp, '\0', sizeof(MYFLT)*MAXCHNLS); */ + /* memset(csound->omaxamp, '\0', sizeof(MYFLT)*MAXCHNLS); */ + + /* initialise sensevents state */ + csound->prvbt = csound->curbt = csound->nxtbt = 0.0; + csound->curp2 = csound->nxtim = csound->timeOffs = csound->beatOffs = 0.0; + csound->icurTime = 0L; + if (O->Beatmode && O->cmdTempo > 0) { + /* if performing from beats, set the initial tempo */ + csound->curBeat_inc = (double) O->cmdTempo / (60.0 * (double) csound->ekr); + csound->ibeatTime = (int64_t)(csound->esr*60.0 / (double) O->cmdTempo); + } + else { + csound->curBeat_inc = 1.0 / (double) csound->ekr; + csound->ibeatTime = 1; + } + csound->cyclesRemaining = 0; + memset(&(csound->evt), 0, sizeof(EVTBLK)); + + /* run instr 0 inits */ + if (UNLIKELY(init0(csound) != 0)) + csoundDie(csound, Str("header init errors")); /* kperf() will not call csoundYield() more than 250 times per second */ - csound->evt_poll_cnt = 0; - csound->evt_poll_maxcnt = (int) ((double) csound->ekr / 250.0); + csound->evt_poll_cnt = 0; + csound->evt_poll_maxcnt = + (int)(250.0 /(double) csound->ekr); /* VL this was wrong: kr/250 originally */ /* Enable musmon to handle external MIDI input, if it has been enabled. */ if (O->Midiin || O->FMidiin || O->RMidiin) { O->RTevents = 1; @@ -219,18 +238,18 @@ csound->Message(csound, Str("orch now loaded\n")); csound->multichan = (csound->nchnls > 1 ? 1 : 0); - ST(segamps) = O->msglevel & SEGAMPS; - ST(sormsg) = O->msglevel & SORMSG; + STA(segamps) = O->msglevel & SEGAMPS; + STA(sormsg) = O->msglevel & SORMSG; if (O->Linein) RTLineset(csound); /* if realtime input expected */ if (csound->enableHostImplementedAudioIO && csound->hostRequestedBufferSize) { - int bufsize = (int) csound->hostRequestedBufferSize; - int ksmps = (int) csound->ksmps; - bufsize = (bufsize + (ksmps >> 1)) / ksmps; - bufsize = (bufsize ? bufsize * ksmps : ksmps); + int bufsize = (int) csound->hostRequestedBufferSize; + int ksmps = (int) csound->ksmps; + bufsize = (bufsize + (ksmps >> 1)) / ksmps; + bufsize = (bufsize ? bufsize * ksmps : ksmps); O->outbufsamps = O->inbufsamps = bufsize; } else { @@ -259,7 +278,7 @@ } csound->Message(csound, Str("audio buffered in %d sample-frame blocks\n"), (int) O->outbufsamps); - O->inbufsamps *= csound->inchnls; /* now adjusted for n channels */ + O->inbufsamps *= csound->inchnls; /* now adjusted for n channels */ O->outbufsamps *= csound->nchnls; iotranset(csound); /* point recv & tran to audio formatter */ /* open audio file or device for input first, and then for output */ @@ -271,13 +290,12 @@ else sfnopenout(csound); } - - corfile_flush(O->playscore); + if(O->playscore!=NULL) corfile_flush(O->playscore); //csound->scfp if (UNLIKELY(O->usingcscore)) { - if (ST(lsect) == NULL) { - ST(lsect) = (EVENT*) mmalloc(csound, sizeof(EVENT)); - ST(lsect)->op = 'l'; + if (STA(lsect) == NULL) { + STA(lsect) = (EVENT*) mmalloc(csound, sizeof(EVENT)); + STA(lsect)->op = 'l'; } csound->Message(csound, Str("using Cscore processing\n")); /* override stdout in */ @@ -293,7 +311,7 @@ fclose(csound->scfp); csound->scfp = NULL; } - if (ST(lplayed)) + if (STA(lplayed)) return 0; /* read from cscore.out */ @@ -324,10 +342,22 @@ O->usingcscore = 0; } - csound->Message(csound, Str("SECTION %d:\n"), ++ST(sectno)); + csound->Message(csound, Str("SECTION %d:\n"), ++STA(sectno)); /* apply score offset if non-zero */ if (csound->csoundScoreOffsetSeconds_ > FL(0.0)) - csound->SetScoreOffsetSeconds(csound, csound->csoundScoreOffsetSeconds_); + csoundSetScoreOffsetSeconds(csound, csound->csoundScoreOffsetSeconds_); + + + if(csound->realtime_audio_flag && csound->init_pass_loop == 0){ + extern void *init_pass_thread(void *); + pthread_attr_t attr; + csound->init_pass_loop = 1; + csound->init_pass_threadlock = csoundCreateMutex(0); + pthread_attr_init(&attr); + //pthread_attr_setstacksize(&attr, 1048576); + pthread_create(&csound->init_pass_thread,&attr,init_pass_thread, csound); + } + /* since we are running in components, we exit here to playevents later */ return 0; @@ -362,12 +392,21 @@ csound->OrcTrigEvts = NULL; } +static void cs_beep(CSOUND *csound) +{ + csound->Message(csound, Str("%c\tbeep!\n"), '\a'); +} + +extern int UDPServerClose(CSOUND *csound); PUBLIC int csoundCleanup(CSOUND *csound) { void *p; MYFLT *maxp; int32 *rngp; - int n; + uint32_t n; + + if(csound->QueryGlobalVariable(csound,"::UDPCOM") + != NULL) UDPServerClose(csound); while (csound->evtFuncChain != NULL) { p = (void*) csound->evtFuncChain; @@ -376,49 +415,62 @@ } /* check if we have already cleaned up */ - if (!(csound->engineState & CS_STATE_CLN)) + if (!(csound->engineStatus & CS_STATE_CLN)) return 0; /* will not clean up more than once */ - csound->engineState &= ~(CS_STATE_CLN); + csound->engineStatus &= ~(CS_STATE_CLN); deactivate_all_notes(csound); - if (csound->instrtxtp && - csound->instrtxtp[0] && - csound->instrtxtp[0]->instance && - csound->instrtxtp[0]->instance->actflg) - xturnoff_now(csound, csound->instrtxtp[0]->instance); - delete_pending_rt_events(csound); + + if (csound->engineState.instrtxtp && + csound->engineState.instrtxtp[0] && + csound->engineState.instrtxtp[0]->instance && + csound->engineState.instrtxtp[0]->instance->actflg) + xturnoff_now(csound, csound->engineState.instrtxtp[0]->instance); + delete_pending_rt_events(csound); + + if(csound->init_pass_loop == 1) { + csoundLockMutex(csound->init_pass_threadlock); + csound->init_pass_loop = 0; + csoundUnlockMutex(csound->init_pass_threadlock); + pthread_join(csound->init_pass_thread, NULL); + csoundDestroyMutex(csound->init_pass_threadlock); + csound->init_pass_threadlock = 0; + } + while (csound->freeEvtNodes != NULL) { p = (void*) csound->freeEvtNodes; csound->freeEvtNodes = ((EVTNODE*) p)->nxt; free(p); } + orcompact(csound); + corfile_rm(&csound->scstr); /* print stats only if musmon was actually run */ - if (UNLIKELY(csound->musmonGlobals != NULL)) { + /* NOT SURE HOW ************************** */ + { csound->Message(csound, Str("end of score.\t\t overall amps:")); for (n = 0; n < csound->nchnls; n++) { if (csound->smaxamp[n] > csound->omaxamp[n]) csound->omaxamp[n] = csound->smaxamp[n]; if (csound->maxamp[n] > csound->omaxamp[n]) csound->omaxamp[n] = csound->maxamp[n]; - ST(orngcnt)[n] += (ST(srngcnt)[n] + csound->rngcnt[n]); + STA(orngcnt)[n] += (STA(srngcnt)[n] + csound->rngcnt[n]); } for (maxp = csound->omaxamp, n = csound->nchnls; n--; ) print_maxamp(csound, *maxp++); if (csound->oparms->outformat != AE_FLOAT) { csound->Message(csound, Str("\n\t overall samples out of range:")); - for (rngp = ST(orngcnt), n = csound->nchnls; n--; ) + for (rngp = STA(orngcnt), n = csound->nchnls; n--; ) csound->Message(csound, "%9d", *rngp++); } csound->Message(csound, Str("\n%d errors in performance\n"), - csound->perferrcnt); + csound->perferrcnt); print_benchmark_info(csound, Str("end of performance")); } - - /* close line input (-L) */ +/* close line input (-L) */ RTclose(csound); /* close MIDI input */ MidiClose(csound); @@ -436,29 +488,21 @@ if (csound->oparms->ringbell) cs_beep(csound); - return dispexit(csound); /* hold or terminate the display output */ -} -void cs_beep(CSOUND *csound) -{ -#ifdef mac_classic - SysBeep(30L); -#else - csound->Message(csound, Str("%c\tbeep!\n"), '\007'); -#endif + return dispexit(csound); /* hold or terminate the display output */ } int lplay(CSOUND *csound, EVLIST *a) /* cscore re-entry into musmon */ { - if (csound->musmonGlobals == NULL) - csound->musmonGlobals = csound->Calloc(csound, sizeof(MUSMON_GLOBALS)); - ST(lplayed) = 1; - if (!ST(sectno)) - csound->Message(csound, Str("SECTION %d:\n"), ++ST(sectno)); - ST(ep) = &a->e[1]; /* from 1st evlist member */ - ST(epend) = ST(ep) + a->nevents; /* to last */ + /* if (csound->musmonGlobals == NULL) */ + /* csound->musmonGlobals = csound->Calloc(csound, sizeof(MUSMON_GLOBALS)); */ + STA(lplayed) = 1; + if (!STA(sectno)) + csound->Message(csound, Str("SECTION %d:\n"), ++STA(sectno)); + STA(ep) = &a->e[1]; /* from 1st evlist member */ + STA(epend) = STA(ep) + a->nevents; /* to last */ while (csoundPerform(csound) == 0) /* play list members */ - ; + ; /* NB: empoty loop */ return OK; } @@ -468,20 +512,40 @@ int turnon(CSOUND *csound, TURNON *p) { EVTBLK evt; - int isNamedInstr; + int insno; + memset(&evt, 0, sizeof(EVTBLK)); + evt.strarg = NULL; evt.scnt = 0; + evt.opcod = 'i'; + evt.pcnt = 3; - evt.strarg = NULL; + if(ISSTRCOD(*p->insno)) { + char *ss = get_arg_string(csound,*p->insno); + insno = csound->strarg2insno(csound,ss,1); + if (insno <= 0L) + return NOTOK; + } else insno = *p->insno; + evt.p[1] = (MYFLT) insno; + evt.p[2] = *p->itime; + evt.p[3] = FL(-1.0); + evt.c.extra = NULL; + return insert_score_event_at_sample(csound, &evt, csound->icurTime); +} + +/* make list to turn on instrs for indef */ +/* perf called from i0 for execution in playevents */ + +int turnon_S(CSOUND *csound, TURNON *p) +{ + EVTBLK evt; + int insno; + memset(&evt, 0, sizeof(EVTBLK)); + evt.strarg = NULL; evt.scnt = 0; evt.opcod = 'i'; evt.pcnt = 3; - isNamedInstr = (int) csound->GetInputArgSMask(p); - if (isNamedInstr) { - int32 insno = csound->strarg2insno(csound, p->insno, isNamedInstr); - if (insno <= 0L) + insno = csound->strarg2insno(csound, ((STRINGDAT *)p->insno)->data, 1); + if (insno <= 0L) return NOTOK; - evt.p[1] = (MYFLT) insno; - } - else - evt.p[1] = *p->insno; + evt.p[1] = (MYFLT) insno; evt.p[2] = *p->itime; evt.p[3] = FL(-1.0); evt.c.extra = NULL; @@ -498,7 +562,7 @@ int32 *rngp, *srngp; int n; - if (ST(segamps) || (p->rngflg && ST(sormsg))) { + if (STA(segamps) || (p->rngflg && STA(sormsg))) { if (score_evt) p->Message(p, "B%7.3f ..%7.3f T%7.3f TT%7.3f M:", p->prvbt - p->beatOffs, p->curbt - p->beatOffs, @@ -518,12 +582,12 @@ } if (p->rngflg) { p->rngflg = 0; - ST(srngflg)++; + STA(srngflg)++; } for (n = p->nchnls, maxp = p->maxamp - 1, smaxp = p->smaxamp - 1, maxps = p->maxpos - 1, smaxps = p->smaxpos - 1, - rngp = p->rngcnt, srngp = ST(srngcnt); n--; ) { + rngp = p->rngcnt, srngp = STA(srngcnt); n--; ) { ++maxps; ++smaxps; if (*++maxp > *++smaxp) { *smaxp = *maxp; @@ -549,24 +613,24 @@ if (enable_msgs) { if (enable_msgs == 1) - p->Message(p, Str("end of section %d\t sect peak amps:"), ST(sectno)); + p->Message(p, Str("end of section %d\t sect peak amps:"), STA(sectno)); else if (enable_msgs == 2) p->Message(p, Str("end of lplay event list\t peak amps:")); for (n = p->nchnls, maxp = p->smaxamp; n--; ) print_maxamp(p, *maxp++); /* IV - Jul 9 2002 */ p->Message(p, "\n"); - if (UNLIKELY(ST(srngflg))) { + if (UNLIKELY(STA(srngflg))) { p->Message(p, Str("\t number of samples out of range:")); - for (n = p->nchnls, srngp = ST(srngcnt); n--; ) + for (n = p->nchnls, srngp = STA(srngcnt); n--; ) p->Message(p, "%9d", *srngp++); p->Message(p, "\n"); } } - ST(srngflg) = 0; + STA(srngflg) = 0; for (n = p->nchnls, smaxp = p->smaxamp - 1, maxp = p->omaxamp - 1, smaxps = p->smaxpos - 1, maxps = p->omaxpos - 1, - srngp = ST(srngcnt), rngp = ST(orngcnt); n--; ) { + srngp = STA(srngcnt), rngp = STA(orngcnt); n--; ) { ++maxps; ++smaxps; if (UNLIKELY(*++smaxp > *++maxp)) { *maxp = *smaxp; /* keep ovrl maxamps */ @@ -613,50 +677,54 @@ csound->currevent = saved_currevent; return (evt->opcod == 'l' ? 3 : (evt->opcod == 's' ? 1 : 2)); case 'q': - if (evt->p[1] == SSTRCOD && evt->strarg) { /* IV - Oct 31 2002 */ + if (ISSTRCOD(evt->p[1]) && evt->strarg) { /* IV - Oct 31 2002 */ if (UNLIKELY((insno = (int) named_instr_find(csound, evt->strarg)) < 1)) { - printScoreError(csound, rtEvt, Str(" - note deleted. instr %s undefined"), - evt->strarg); + printScoreError(csound, rtEvt, + Str(" - note deleted. instr %s undefined"), + evt->strarg); break; } csound->Message(csound, Str("Setting instrument %s %s\n"), evt->strarg, (evt->p[3] == 0 ? Str("off") : Str("on"))); - csound->instrtxtp[insno]->muted = (int16) evt->p[3]; + csound->engineState.instrtxtp[insno]->muted = (int16) evt->p[3]; } else { /* IV - Oct 31 2002 */ insno = abs((int) evt->p[1]); - if (UNLIKELY((unsigned int)(insno-1) >= (unsigned int) csound->maxinsno || - csound->instrtxtp[insno] == NULL)) { + if (UNLIKELY((unsigned int)(insno-1) >= + (unsigned int) csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL)) { printScoreError(csound, rtEvt, Str(" - note deleted. instr %d(%d) undefined"), - insno, csound->maxinsno); + insno, csound->engineState.maxinsno); break; } csound->Message(csound, Str("Setting instrument %d %s\n"), insno, (evt->p[3] == 0 ? Str("off") : (Str("on")))); - csound->instrtxtp[insno]->muted = (int16) evt->p[3]; + csound->engineState.instrtxtp[insno]->muted = (int16) evt->p[3]; } break; case 'i': - if (evt->p[1] == SSTRCOD && evt->strarg) { /* IV - Oct 31 2002 */ + if (ISSTRCOD(evt->p[1]) && evt->strarg) { /* IV - Oct 31 2002 */ if (UNLIKELY((insno = (int) named_instr_find(csound, evt->strarg)) < 1)) { - printScoreError(csound, rtEvt, Str(" - note deleted. instr %s undefined"), - evt->strarg); + printScoreError(csound, rtEvt, + Str(" - note deleted. instr %s undefined"), + evt->strarg); break; } if ((rfd = getRemoteInsRfd(csound, insno))) { /* RM: if this note labeled as remote */ if (rfd == GLOBAL_REMOT) - insGlobevt(csound, evt); /* RM: do a global send and allow local */ + insGlobevt(csound, evt); /* RM: do a global send and allow local */ else { - insSendevt(csound, evt, rfd);/* RM: or send to single remote Csound */ + insSendevt(csound, evt, rfd);/* RM: or send to single remote Csound */ break; /* RM: and quit */ } } evt->p[1] = (MYFLT) insno; if (csound->oparms->Beatmode && !rtEvt && evt->p3orig > FL(0.0)) evt->p[3] = evt->p3orig * (MYFLT) csound->ibeatTime/csound->esr; - if (UNLIKELY((n = insert(csound, insno, evt)))) { /* else alloc, init, activate */ + /* else alloc, init, activate */ + if (UNLIKELY((n = insert(csound, insno, evt)))) { printScoreError(csound, rtEvt, Str(" - note deleted. i%d (%s) had %d init errors"), insno, evt->strarg, n); @@ -664,11 +732,12 @@ } else { /* IV - Oct 31 2002 */ insno = abs((int) evt->p[1]); - if (UNLIKELY((unsigned int)(insno-1) >= (unsigned int)csound->maxinsno || - csound->instrtxtp[insno] == NULL)) { + if (UNLIKELY((unsigned int)(insno-1) >= + (unsigned int)csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL)) { printScoreError(csound, rtEvt, Str(" - note deleted. instr %d(%d) undefined"), - insno, csound->maxinsno); + insno, csound->engineState.maxinsno); break; } if ((rfd = getRemoteInsRfd(csound, insno))) { @@ -705,7 +774,7 @@ case 'a': { int64_t kCnt; - kCnt = (int64_t) ((double) csound->global_ekr * (double) evt->p[3] + 0.5); + kCnt = (int64_t) ((double) csound->ekr * (double) evt->p[3] + 0.5); if (kCnt > csound->advanceCnt) { csound->advanceCnt = kCnt; csound->Message(csound, @@ -729,11 +798,13 @@ csound->Message(csound, Str("\t\t T%7.3f - note deleted. "), csound->curp2); { - char *name = csound->instrtxtp[insno]->insname; + char *name = csound->engineState.instrtxtp[insno]->insname; if (name) - csound->Message(csound, Str("instr %s had %d init errors\n"), name, n); + csound->Message(csound, Str("instr %s had %d init errors\n"), + name, n); else - csound->Message(csound, Str("instr %d had %d init errors\n"), insno, n); + csound->Message(csound, Str("instr %d had %d init errors\n"), + insno, n); } csound->perferrcnt++; } @@ -869,6 +940,7 @@ } /* end of: 1: section, 2: score, 3: lplay list */ retval = (e->opcod == 'l' ? 3 : (e->opcod == 's' ? 1 : 2)); + goto scode; default: /* q, i, f, a: */ process_score_event(csound, e, 0);/* handle event now */ @@ -878,12 +950,12 @@ } else { /* else read next score event */ - if (UNLIKELY(O->usingcscore)) { /* get next lplay event */ + if (UNLIKELY(O->usingcscore)) { /* get next lplay event */ /* FIXME: this may be non-portable */ - if (ST(ep) < ST(epend)) /* nxt event */ - memcpy((void*) e, (void*) &((*ST(ep)++)->strarg), sizeof(EVTBLK)); - else /* else lcode */ - memcpy((void*) e, (void*) &(ST(lsect)->strarg), sizeof(EVTBLK)); + if (STA(ep) < STA(epend)) /* nxt event */ + memcpy((void*) e, (void*) &((*STA(ep)++)->strarg), sizeof(EVTBLK)); + else /* else lcode */ + memcpy((void*) e, (void*) &(STA(lsect)->strarg), sizeof(EVTBLK)); } else if (!(rdscor(csound, e))) /* or rd nxt evt from scstr */ e->opcod = 'e'; @@ -916,17 +988,40 @@ continue; } } + + /* calculate the number of k-periods remaining until next event */ - if (O->Beatmode) - csound->cyclesRemaining = - RNDINT64((csound->nxtbt - csound->curBeat) / csound->curBeat_inc); + if (!O->sampleAccurate) { + if (O->Beatmode) + csound->cyclesRemaining = + RNDINT64((csound->nxtbt - csound->curBeat) / csound->curBeat_inc); + else { + csound->cyclesRemaining = + RNDINT64((csound->nxtim*csound->esr - csound->icurTime)/csound->ksmps); + csound->nxtim = + (csound->cyclesRemaining*csound->ksmps+csound->icurTime)/csound->esr; + } + } else { - csound->cyclesRemaining = - RNDINT64((csound->nxtim*csound->esr - csound->icurTime) / csound->ksmps); - csound->nxtim = (csound->cyclesRemaining*csound->ksmps+csound->icurTime)/csound->esr; + /* VL 30-11-2012 + new code for sample-accurate timing needs to truncate cyclesRemaining + */ + if (O->Beatmode) + csound->cyclesRemaining = (int64_t) + ((csound->nxtbt - csound->curBeat) / csound->curBeat_inc); + else { + csound->cyclesRemaining = (int64_t) + FLOOR((csound->nxtim*csound->esr - + csound->icurTime+csound->onedsr*0.5) / csound->ksmps); + csound->nxtim = + (csound->cyclesRemaining*csound->ksmps+csound->icurTime)/csound->esr; + } } } + + + /* handle any real time events now: */ /* FIXME: the initialisation pass of real time */ /* events is not sorted by instrument number */ @@ -1009,30 +1104,34 @@ return 1; } /* for s, or e after s */ - if (retval == 1 || (retval == 2 && ST(sectno) > 1)) { + if (retval == 1 || (retval == 2 && STA(sectno) > 1)) { delete_pending_rt_events(csound); if (O->Beatmode) csound->curbt = csound->curBeat; - csound->curp2 = csound->nxtim = csound->timeOffs = csound->icurTime/csound->esr; + csound->curp2 = csound->nxtim = + csound->timeOffs = csound->icurTime/csound->esr; csound->prvbt = csound->nxtbt = csound->beatOffs = csound->curbt; section_amps(csound, 1); } - else + else{ section_amps(csound, 0); + + } if (retval == 1) { /* if s code, */ orcompact(csound); /* rtn inactiv spc */ if (csound->actanchor.nxtact == NULL) /* if no indef ins */ rlsmemfiles(csound); /* purge memfiles */ - csound->Message(csound, Str("SECTION %d:\n"), ++ST(sectno)); + csound->Message(csound, Str("SECTION %d:\n"), ++STA(sectno)); goto retest; /* & back for more */ } + return 2; /* done with entire score */ } static inline uint64_t time2kcnt(CSOUND *csound, double tval) { if (tval > 0.0) { - tval *= (double) csound->global_ekr; + tval *= (double) csound->ekr; #ifdef HAVE_C99 return (uint64_t) llrint(tval); #else @@ -1078,13 +1177,19 @@ return CSOUND_MEMORY; } if (evt->strarg != NULL) { /* copy string argument if present */ - e->evt.strarg = (char*) malloc((size_t) strlen(evt->strarg) + (size_t) 1); + /* NEED TO COPY WHOLE STRING STRUCTURE */ + int n = evt->scnt; + char *p = evt->strarg; + while (n--) { p += strlen(p)+1; }; + e->evt.strarg = (char*) malloc((size_t) (p-evt->strarg)+1); if (UNLIKELY(e->evt.strarg == NULL)) { free(e); return CSOUND_MEMORY; } - strcpy(e->evt.strarg, evt->strarg); + memcpy(e->evt.strarg, evt->strarg, p-evt->strarg+1 ); + e->evt.scnt = evt->scnt; } + e->evt.pinstance = evt->pinstance; e->evt.opcod = evt->opcod; e->evt.pcnt = evt->pcnt; p = &(e->evt.p[0]); @@ -1114,7 +1219,8 @@ if (p[2] < FL(0.0)) p[2] = FL(0.0); /* start beat: this is possibly wrong */ - evt->p2orig = (MYFLT) (((start_time - st->icurTime/st->esr) / st->ibeatTime) + evt->p2orig = (MYFLT) (((start_time - st->icurTime/st->esr) / + st->ibeatTime) + (st->curBeat - st->beatOffs)); if (evt->p2orig < FL(0.0)) evt->p2orig = FL(0.0); @@ -1131,14 +1237,15 @@ evt->p3orig = (MYFLT) ((double) evt->p3orig / st->ibeatTime); case 'q': /* mute instrument */ /* check for a valid instrument number or name */ - if (evt->strarg != NULL && p[1] == SSTRCOD) + if (evt->strarg != NULL && ISSTRCOD(p[1])) i = (int) named_instr_find(csound, evt->strarg); else i = (int) fabs((double) p[1]); - if (UNLIKELY((unsigned int) (i - 1) >= (unsigned int) csound->maxinsno || - csound->instrtxtp[i] == NULL)) { + if (UNLIKELY((unsigned int) (i - 1) >= + (unsigned int) csound->engineState.maxinsno || + csound->engineState.instrtxtp[i] == NULL)) { csoundMessage(csound, Str("insert_score_event(): invalid instrument " - "number or name\n")); + "number or name\n" )); goto err_return; } break; @@ -1211,11 +1318,12 @@ csound->nxtbt = csound->curbt = csound->prvbt = 0.0; csound->nxtim = csound->curp2 = 0.0; csound->beatOffs = csound->timeOffs = 0.0; - csound->curBeat = 0.0; + csound->curBeat = 0.0; csound->icurTime = 0L; csound->cyclesRemaining = 0; csound->evt.strarg = NULL; - csound->evt.opcod = '\0'; + csound->evt.scnt = 0; + csound->evt.opcod = '\0'; /* reset tempo */ if (csound->oparms->Beatmode) settempo(csound, (MYFLT) csound->oparms->cmdTempo); @@ -1223,16 +1331,17 @@ settempo(csound, FL(60.0)); /* update section/overall amplitudes, reset to section 1 */ section_amps(csound, 1); - ST(sectno) = 1; - csound->Message(csound, Str("SECTION %d:\n"), ST(sectno)); + STA(sectno) = 1; + csound->Message(csound, Str("SECTION %d:\n"), STA(sectno)); } /* apply score offset if non-zero */ csound->advanceCnt = 0; if (csound->csoundScoreOffsetSeconds_ > FL(0.0)) - csound->SetScoreOffsetSeconds(csound, csound->csoundScoreOffsetSeconds_); - - corfile_rewind(csound->scstr); + csoundSetScoreOffsetSeconds(csound, csound->csoundScoreOffsetSeconds_); + if(csound->scstr) + corfile_rewind(csound->scstr); + else csound->Warning(csound, Str("cannot rewind score: no score in memory \n")); } /** diff -Nru csound-5.17.11~dfsg/Engine/namedins.c csound-6.02~dfsg/Engine/namedins.c --- csound-5.17.11~dfsg/Engine/namedins.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/namedins.c 2014-01-07 16:53:47.000000000 +0000 @@ -23,110 +23,9 @@ #include "csoundCore.h" #include "namedins.h" +#include "csound_orc_semantics.h" #include -typedef struct namedInstr { - int32 instno; - char *name; - INSTRTXT *ip; - struct namedInstr *prv; -} INSTRNAME; - -typedef struct CsoundOpcodePluginFile_s { - /* file name (base name only) */ - char *fname; - /* pointer to next link in chain */ - struct CsoundOpcodePluginFile_s *nxt; - /* file name (full path) */ - char *fullName; - /* is this file already loaded ? (0: no, 1: yes, -1: does not exist) */ - int isLoaded; -} CsoundOpcodePluginFile_t; - -typedef struct CsoundPluginOpcode_s { - /* opcode name */ - char *opname; - /* pointer to next link in chain */ - struct CsoundPluginOpcode_s *nxt; - /* associated plugin library */ - CsoundOpcodePluginFile_t *fp; -} CsoundPluginOpcode_t; - -/* do not touch this ! */ - -const unsigned char strhash_tabl_8[256] = { - 230, 69, 87, 14, 21, 133, 233, 229, 54, 111, 196, 53, 128, 23, - 66, 225, 67, 79, 173, 110, 116, 56, 48, 129, 89, 188, 29, 251, - 186, 159, 102, 162, 227, 57, 220, 244, 165, 243, 215, 216, 214, 33, - 172, 254, 247, 241, 121, 197, 83, 22, 142, 61, 199, 50, 140, 192, - 6, 237, 183, 46, 206, 81, 18, 105, 147, 253, 15, 97, 179, 163, - 108, 123, 59, 198, 19, 141, 9, 95, 25, 219, 222, 1, 5, 52, - 90, 138, 11, 234, 55, 60, 209, 39, 80, 203, 120, 4, 64, 146, - 153, 157, 194, 134, 174, 100, 107, 125, 236, 160, 150, 41, 12, 223, - 135, 189, 122, 171, 10, 221, 71, 68, 106, 73, 218, 115, 2, 152, - 132, 190, 185, 113, 139, 104, 151, 154, 248, 117, 193, 118, 136, 204, - 17, 239, 158, 77, 103, 182, 250, 191, 170, 13, 75, 85, 62, 0, - 164, 8, 178, 93, 47, 42, 177, 3, 212, 255, 35, 137, 31, 224, - 242, 88, 161, 145, 49, 119, 143, 245, 201, 38, 211, 96, 169, 98, - 78, 195, 58, 109, 40, 238, 114, 20, 99, 24, 175, 200, 148, 112, - 45, 7, 28, 168, 27, 249, 94, 205, 156, 44, 37, 82, 217, 36, - 30, 16, 101, 72, 43, 149, 144, 187, 65, 131, 184, 166, 51, 32, - 226, 202, 231, 213, 126, 210, 235, 74, 208, 252, 181, 155, 246, 92, - 63, 228, 180, 176, 76, 167, 232, 91, 130, 84, 124, 86, 34, 26, - 207, 240, 127, 70 -}; - -unsigned int csound_str_hash_32(const char *s) -{ - uint64_t tmp; - unsigned int h = 0U; - - while (1) { - unsigned int c; - c = (unsigned int) s[0] & 0xFFU; - if (!c) - return h; - h ^= c; - c = (unsigned int) s[1] & 0xFFU; - if (!c) - break; - h ^= (c << 8); - c = (unsigned int) s[2] & 0xFFU; - if (!c) - break; - h ^= (c << 16); - c = (unsigned int) s[3] & 0xFFU; - if (!c) - break; - h ^= (c << 24); - tmp = (uint32_t) h * (uint64_t) 0xC2B0C3CCU; - h = ((unsigned int) tmp ^ (unsigned int) (tmp >> 32)) & 0xFFFFFFFFU; - c = (unsigned int) s[4] & 0xFFU; - if (!c) - return h; - h ^= c; - c = (unsigned int) s[5] & 0xFFU; - if (!c) - break; - h ^= (c << 8); - c = (unsigned int) s[6] & 0xFFU; - if (!c) - break; - h ^= (c << 16); - c = (unsigned int) s[7] & 0xFFU; - if (!c) - break; - h ^= (c << 24); - s += 8; - tmp = (uint32_t) h * (uint64_t) 0xC2B0C3CCU; - h = ((unsigned int) tmp ^ (unsigned int) (tmp >> 32)) & 0xFFFFFFFFU; - } - tmp = (uint32_t) h * (uint64_t) 0xC2B0C3CCU; - h = ((unsigned int) tmp ^ (unsigned int) (tmp >> 32)) & 0xFFFFFFFFU; - - return h; -} - /* check if the string s is a valid instrument or opcode name */ /* return value is zero if the string is not a valid name */ @@ -147,116 +46,18 @@ int32 named_instr_find(CSOUND *csound, char *s) { INSTRNAME *inm; - unsigned char h = name_hash(csound, s); /* calculate hash value */ - if (!csound->instrumentNames) return 0L; /* no named instruments defined */ + if (!csound->engineState.instrumentNames) + return 0L; /* no named instruments defined */ /* now find instrument */ - inm = ((INSTRNAME**) csound->instrumentNames)[h]; - while (inm) { - if (!sCmp(inm->name, s)) - return (int32) inm->instno; - inm = inm->prv; - } - return 0L; /* not found */ -} - -/* allocate entry for named instrument ip with name s (s must not be freed */ -/* after the call, because only the pointer is stored); instrument number */ -/* is set to insno */ -/* returns zero if the named instr entry could not be allocated */ -/* (e.g. because it already exists) */ - -int named_instr_alloc(CSOUND *csound, char *s, INSTRTXT *ip, int32 insno) -{ - INSTRNAME **inm_base = (INSTRNAME**) csound->instrumentNames, *inm, *inm2; - unsigned char h = name_hash(csound, s); /* calculate hash value */ + inm = cs_hash_table_get(csound, csound->engineState.instrumentNames, s); - if (UNLIKELY(!inm_base)) - /* no named instruments defined yet */ - inm_base = csound->instrumentNames = - (void*) mcalloc(csound, sizeof(INSTRNAME*) * 258); - /* now check if instrument is already defined */ - if ((inm = inm_base[h])) { - while (inm && sCmp(inm->name, s)) inm = inm->prv; - if (UNLIKELY(inm!=NULL)) return 0; /* error: instr exists */ - } - /* allocate entry, */ - inm = (INSTRNAME*) mcalloc(csound, sizeof(INSTRNAME)); - inm2 = (INSTRNAME*) mcalloc(csound, sizeof(INSTRNAME)); - /* and store parameters */ - inm->name = s; inm->ip = ip; - inm2->instno = insno; - inm2->name = (char*) inm; /* hack */ - /* link into chain */ - inm->prv = inm_base[h]; - inm_base[h] = inm; - /* temporary chain for use by named_instr_assign_numbers() */ - if (!inm_base[256]) - inm_base[256] = inm2; - else - inm_base[257]->prv = inm2; - inm_base[257] = inm2; - if (UNLIKELY(csound->oparms->odebug)) - csound->Message(csound, - "named instr name = \"%s\", hash = %d, txtp = %p\n", - s, (int) h, (void*) ip); - return 1; -} - -/* assign instrument numbers to all named instruments */ -/* called by otran */ - -void named_instr_assign_numbers(CSOUND *csound) -{ - INSTRNAME *inm, *inm2, **inm_first, **inm_last; - int num = 0, insno_priority = 0; - - if (!csound->instrumentNames) return; /* no named instruments */ - inm_first = (INSTRNAME**) csound->instrumentNames + 256; - inm_last = inm_first + 1; - while (--insno_priority > -3) { - if (insno_priority == -2) { - num = csound->maxinsno; /* find last used instr number */ - while (!csound->instrtxtp[num] && --num); - } - for (inm = *inm_first; inm; inm = inm->prv) { - if ((int) inm->instno != insno_priority) continue; - /* the following is based on code by Matt J. Ingalls */ - /* find an unused number and use it */ - while (++num <= csound->maxinsno && csound->instrtxtp[num]); - /* we may need to expand the instrument array */ - if (num > csound->maxinsno) { - int m = csound->maxinsno; - csound->maxinsno += MAXINSNO; /* Expand */ - csound->instrtxtp = (INSTRTXT**) - mrealloc(csound, csound->instrtxtp, - (1 + csound->maxinsno) * sizeof(INSTRTXT*)); - /* Array expected to be nulled so.... */ - while (++m <= csound->maxinsno) csound->instrtxtp[m] = NULL; - } - /* hack: "name" actually points to the corresponding INSTRNAME */ - inm2 = (INSTRNAME*) (inm->name); /* entry in the table */ - inm2->instno = (int32) num; - csound->instrtxtp[num] = inm2->ip; - if (csound->oparms->msglevel) - csound->Message(csound, Str("instr %s uses instrument number %d\n"), - inm2->name, num); - } - } - /* clear temporary chains */ - inm = *inm_first; - while (inm) { - INSTRNAME *nxtinm = inm->prv; - mfree(csound, inm); - inm = nxtinm; - } - *inm_first = *inm_last = NULL; + return (inm == NULL) ? 0L : inm->instno; } /* convert opcode string argument to instrument number */ /* return value is -1 if the instrument cannot be found */ /* (in such cases, csoundInitError() is also called) */ - int32 strarg2insno(CSOUND *csound, void *p, int is_string) { int32 insno; @@ -269,8 +70,8 @@ } else { /* numbered instrument */ insno = (int32) *((MYFLT*) p); - if (UNLIKELY(insno < 1 || insno > csound->maxinsno || - !csound->instrtxtp[insno])) { + if (UNLIKELY(insno < 1 || insno > csound->engineState.maxinsno || + !csound->engineState.instrtxtp[insno])) { csound->InitError(csound, Str("Cannot Find Instrument %d"), (int) insno); return -1; } @@ -281,13 +82,12 @@ /* same as strarg2insno, but runs at perf time, */ /* and does not support numbered instruments */ /* (used by opcodes like event or schedkwhen) */ - int32 strarg2insno_p(CSOUND *csound, char *s) { int32 insno; if (UNLIKELY(!(insno = named_instr_find(csound, s)))) { - csound->PerfError(csound, Str("instr %s not found"), s); + csound->ErrorMsg(csound, Str("instr %s not found"), s); return -1; } return insno; @@ -298,7 +98,6 @@ /* argument is non-zero, only opcode names are searched */ /* return value is -1 if the instrument cannot be found */ /* (in such cases, csoundInitError() is also called) */ - int32 strarg2opcno(CSOUND *csound, void *p, int is_string, int force_opcode) { int32 insno = 0; @@ -309,8 +108,8 @@ } else { /* numbered instrument */ insno = (int32) *((MYFLT*) p); - if (UNLIKELY(insno < 1 || insno > csound->maxinsno || - !csound->instrtxtp[insno])) { + if (UNLIKELY(insno < 1 || insno > csound->engineState.maxinsno || + !csound->engineState.instrtxtp[insno])) { csound->InitError(csound, Str("Cannot Find Instrument %d"), (int) insno); return -1; } @@ -357,9 +156,6 @@ /* 3. the file name is generated using baseName and the */ /* value rounded to the nearest integer, as described */ /* above */ -/* 'is_string' is usually p->XSTRCODE for an opcode with */ -/* only one string argument, otherwise it is */ -/* p->XSTRCODE & (1 << (argno - 1)) */ /* return value: */ /* pointer to the output string; if 's' is not NULL, it is */ /* always the same as 's', otherwise it is allocated with */ @@ -375,12 +171,13 @@ s = mmalloc(csound, strlen((char*) p) + 1); strcpy(s, (char*) p); } - else if (*((MYFLT*) p) == SSTRCOD) { + else if (ISSTRCOD(*((MYFLT*) p))) { /* p-field string, unquote and copy */ - char *s2 = csound->currevent->strarg; + char *s2 = get_arg_string(csound, *((MYFLT*)p)); int i = 0; + //printf("strarg2name: %g %s\n", *((MYFLT*)p), s2); if (s == NULL) - s = mmalloc(csound, strlen(csound->currevent->strarg) + 1); + s = mmalloc(csound, strlen(s2) + 1); if (*s2 == '"') s2++; while (*s2 != '"' && *s2 != '\0') @@ -409,447 +206,12 @@ /* ----------------------------------------------------------------------- */ /* the following functions are for efficient management of the opcode list */ -static CS_NOINLINE int loadPluginOpcode(CSOUND *csound, - CsoundOpcodePluginFile_t *fp, - const char *opname, int h) -{ - int n; - - if (fp->isLoaded != 0) - return 0; - n = csoundLoadAndInitModule(csound, fp->fullName); - if (UNLIKELY(n != 0)) { - fp->isLoaded = -1; - if (n != CSOUND_ERROR) - csound->LongJmp(csound, (n == CSOUND_MEMORY ? n : CSOUND_ERROR)); - return 0; - } - fp->isLoaded = 1; - n = ((int*) csound->opcode_list)[h]; - while (n && sCmp(csound->opcodlst[n].opname, opname)) - n = csound->opcodlst[n].prvnum; - - return n; -} - -/* find opcode with the specified name in opcode list */ -/* returns index to opcodlst[], or zero if the opcode cannot be found */ - -int find_opcode(CSOUND *csound, char *opname) -{ - int h, n; - - if (opname[0] == (char) 0 || - (opname[0] >= (char) '0' && opname[0] <= (char) '9')) - return 0; - - /* calculate hash value */ - h = (int) name_hash_2(csound, opname); - /* now find entry in opcode chain */ - n = ((int*) csound->opcode_list)[h]; - while (n) { - if (!sCmp(opname, csound->opcodlst[n].opname)) - return n; - n = csound->opcodlst[n].prvnum; - } - if (csound->pluginOpcodeDB != NULL) { - CsoundPluginOpcode_t *p; - /* not found, check for deferred plugin loading */ - p = ((CsoundPluginOpcode_t**) csound->pluginOpcodeDB)[h]; - while (p) { - if (!sCmp(opname, p->opname)) - return loadPluginOpcode(csound, p->fp, opname, h); - p = p->nxt; - } - } - - return 0; -} - -/* -------------------------------------------------------------------- */ -/* These functions replace the functionality of strsav() in rdorch.c. */ - -#define STRSPACE (2000) /* number of bytes in a buffer */ -typedef struct strsav_t { - struct strsav_t *nxt; /* pointer to next structure */ - char s[1]; /* the string stored */ -} STRSAV; - -typedef struct strsav_space_t { - char *sp; /* string space */ - int size; /* Size of buffer */ - int splim; /* number of bytes allocated */ - struct strsav_space_t *prv; /* ptr to previous buffer */ -} STRSAV_SPACE; - -#define STRSAV_STR_ ((STRSAV**) (csound->strsav_str)) -#define STRSAV_SPACE_ ((STRSAV_SPACE*) (csound->strsav_space)) - -/* allocate space for strsav (called once from rdorchfile()) */ - -void strsav_create(CSOUND *csound) -{ - if (csound->strsav_space != NULL) return; /* already allocated */ - csound->strsav_str = mcalloc(csound, sizeof(STRSAV*) * 256); - csound->strsav_space = mcalloc(csound, sizeof(STRSAV_SPACE)); - STRSAV_SPACE_->sp = (char*)mcalloc(csound, STRSPACE); - STRSAV_SPACE_->size = STRSPACE; -} -/* Locate string s in database, and return address of stored string (not */ -/* necessarily the same as s). If the string is not defined yet, it is */ -/* copied to the database (in such cases, it is allowed to free s after */ -/* the call). */ -char *strsav_string(CSOUND *csound, char *s) -{ - STRSAV *ssp, *prv; - int n; - unsigned char h = name_hash(csound, s); /* calculate hash value */ - - /* now find entry in database */ - ssp = STRSAV_STR_[h]; - prv = NULL; - while (ssp) { - if (!sCmp(ssp->s, s)) { - if (prv != NULL) { - /* move to the beginning of the chain, so that */ - /* frequently searched strings are found faster */ - prv->nxt = ssp->nxt; - ssp->nxt = STRSAV_STR_[h]; - STRSAV_STR_[h] = ssp; - } - return (ssp->s); /* already defined */ - } - prv = ssp; - ssp = prv->nxt; - } - /* not found, so need to allocate a new entry */ - n = (int) sizeof(struct strsav_t *) + (int) strlen(s) + 1; /* n bytes */ - n = ((n + (int) sizeof(struct strsav_t *) - 1) /* round up for alignment */ - / (int) sizeof(struct strsav_t *)) * (int) sizeof(struct strsav_t *); - if ((STRSAV_SPACE_->splim + n) > STRSAV_SPACE_->size) { - STRSAV_SPACE *sp; - /* not enough space, allocate new buffer */ - if (UNLIKELY(n > STRSAV_SPACE_->size)) { - /* this should not happen */ - sp = (STRSAV_SPACE*)mcalloc(csound, sizeof(STRSAV_SPACE)); - sp->sp = - (char*)mcalloc(csound, sp->size = n+STRSPACE); - csound->DebugMsg(csound, - "internal message: strsav: buffer length now %d\n", - sp->size); - - } - else { - sp = (STRSAV_SPACE*) mcalloc(csound, sizeof(STRSAV_SPACE)); - sp->sp = - (char*)mcalloc(csound, STRSAV_SPACE_->size = STRSPACE); - } - sp->prv = STRSAV_SPACE_; - csound->strsav_space = sp; - } - /* use space from buffer */ - // ssp = (STRSAV*) ((char*) STRSAV_SPACE_->sp + STRSAV_SPACE_->splim); - ssp = (STRSAV*)(&(STRSAV_SPACE_->sp)[STRSAV_SPACE_->splim]); - STRSAV_SPACE_->splim += n; - strcpy(ssp->s, s); /* save string */ - /* link into chain */ - ssp->nxt = STRSAV_STR_[h]; - STRSAV_STR_[h] = ssp; - return (ssp->s); -} /* -------- IV - Jan 29 2005 -------- */ -/* #define CSGLOBALS_USE_TREE 1 */ - -#ifdef CSGLOBALS_USE_TREE - -static void fix_pointers_in_db(void **p, - unsigned char *oldp, unsigned char *newp) -{ - void **pp; - int i, j; - /* hack to fix pointers in globals database after realloc() */ - for (i = 0; i < 16; i++) { - if (p[i] == (void*) NULL) - continue; /* nothing here */ - pp = (void**) ((unsigned char*) (p[i]) + (newp - oldp)); - p[i] = (void*) pp; - for (j = 0; j < 16; j += 2) { - if (pp[j] != (void*) NULL) { - /* recursively search entire database */ - pp[j] = (void*) ((unsigned char*) (pp[j]) + (newp - oldp)); - fix_pointers_in_db((void**) pp[j], oldp, newp); - } - } - } -} - -static void **extendNamedGlobals(CSOUND *p, int n, int storeIndex) -{ - void **ptr = NULL; - int i, oldlimit; - - oldlimit = p->namedGlobalsCurrLimit; - p->namedGlobalsCurrLimit += n; - if (UNLIKELY(p->namedGlobalsCurrLimit > p->namedGlobalsMaxLimit)) { - p->namedGlobalsMaxLimit = p->namedGlobalsCurrLimit; - p->namedGlobalsMaxLimit += (p->namedGlobalsMaxLimit >> 3); - p->namedGlobalsMaxLimit = (p->namedGlobalsMaxLimit + 15) & (~15); - ptr = p->namedGlobals; - p->namedGlobals = (void**) realloc((void*) p->namedGlobals, - sizeof(void*) - * (size_t) p->namedGlobalsMaxLimit); - if (UNLIKELY(p->namedGlobals == NULL)) { - p->namedGlobalsCurrLimit = p->namedGlobalsMaxLimit = 0; - return NULL; - } - if (p->namedGlobals != ptr && ptr != NULL) { - /* realloc() moved the data, need to fix pointers */ - fix_pointers_in_db(p->namedGlobals, (unsigned char*) ptr, - (unsigned char*) p->namedGlobals); - } - /* clear new allocated space to zero */ - for (i = oldlimit; i < p->namedGlobalsMaxLimit; i++) - p->namedGlobals[i] = (void*) NULL; - } - ptr = (void**) p->namedGlobals + (int) oldlimit; - if (storeIndex >= 0) { - /* if requested, store pointer to new area at specified array index */ - p->namedGlobals[storeIndex] = (void*) ptr; - } - return ptr; -} - -/** - * Allocate nbytes bytes of memory that can be accessed later by calling - * csoundQueryGlobalVariable() with the specified name; the space is - * cleared to zero. - * Returns CSOUND_SUCCESS on success, CSOUND_ERROR in case of invalid - * parameters (zero nbytes, invalid or already used name), or - * CSOUND_MEMORY if there is not enough memory. - */ -PUBLIC int csoundCreateGlobalVariable(CSOUND *csnd, - const char *name, size_t nbytes) -{ - void **p = NULL; - int i, j, k, len; - /* create new empty database if it does not exist yet */ - if (UNLIKELY(csnd->namedGlobals == NULL)) { - if (UNLIKELY(extendNamedGlobals(csnd, 16, -1) == (void**) NULL)) - return CSOUND_MEMORY; - } - /* check for a valid name */ - if (UNLIKELY(name == NULL)) - return CSOUND_ERROR; - if (UNLIKELY(name[0] == '\0')) - return CSOUND_ERROR; - len = (int) strlen(name); - for (i = 0; i < len; i++) - if (UNLIKELY((unsigned char) name[i] >= (unsigned char) 0x80)) - return CSOUND_ERROR; - /* cannot allocate zero bytes */ - if (UNLIKELY((int) nbytes < 1)) - return CSOUND_ERROR; - /* store in tree */ - i = -1; - p = csnd->namedGlobals; - while (++i < (len - 1)) { - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - if (UNLIKELY(p[j] == (void*) NULL)) { - p = extendNamedGlobals(csnd, 16, (int) ((void**) &(p[j]) - - csnd->namedGlobals)); - if (UNLIKELY(p == NULL)) - return CSOUND_MEMORY; - } - else - p = (void**) (p[j]); - if (UNLIKELY(p[k] == (void*) NULL)) { - p = extendNamedGlobals(csnd, 16, (int) ((void**) &(p[k]) - - csnd->namedGlobals)); - if (UNLIKELY(p == NULL)) - return CSOUND_MEMORY; - } - else - p = (void**) (p[k]); - } - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - if (UNLIKELY(p[j] == (void*) NULL)) { - p = extendNamedGlobals(csnd, 16, (int) ((void**) &(p[j]) - - csnd->namedGlobals)); - if (UNLIKELY(p == NULL)) - return CSOUND_MEMORY; - } - else - p = (void**) (p[j]); - if (UNLIKELY(p[k + 1] != (void*) NULL)) - return CSOUND_ERROR; /* name is already defined */ - /* allocate memory and store pointer */ - p[k + 1] = (void*) malloc(nbytes); - if (UNLIKELY(p[k + 1] == (void*) NULL)) - return CSOUND_MEMORY; - memset(p[k + 1], 0, nbytes); /* clear space to zero */ - /* successfully finished */ - return CSOUND_SUCCESS; -} - -/** - * Get pointer to space allocated with the name "name". - * Returns NULL if the specified name is not defined. - */ -PUBLIC void *csoundQueryGlobalVariable(CSOUND *csnd, const char *name) -{ - void **p = NULL; - int i, j, k, len; - /* check if there is an actual database to search */ - if (csnd->namedGlobals == NULL) - return NULL; - /* check for a valid name */ - if (name == NULL) - return NULL; - if (name[0] == '\0') - return NULL; - len = (int) strlen(name); - /* search tree */ - i = -1; - p = csnd->namedGlobals; - while (++i < (len - 1)) { - if (UNLIKELY((unsigned char) name[i] >= (unsigned char) 0x80)) - return NULL; /* invalid name: must be 7-bit ASCII */ - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - if (p[j] == (void*) NULL) - return NULL; /* not found */ - else - p = (void**) (p[j]); - if (p[k] == (void*) NULL) - return NULL; /* not found */ - else - p = (void**) (p[k]); - } - if (UNLIKELY((unsigned char) name[i] >= (unsigned char) 0x80)) - return NULL; /* invalid name: must be 7-bit ASCII */ - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - if (p[j] == (void*) NULL) - return NULL; /* not found */ - else - p = (void**) (p[j]); - /* return with pointer (will be NULL for undefined name) */ - return ((void*) p[k + 1]); -} - -/** - * This function is the same as csoundQueryGlobalVariable(), except the - * variable is assumed to exist and no error checking is done. - * Faster, but may crash or return an invalid pointer if 'name' is - * not defined. - */ -PUBLIC void *csoundQueryGlobalVariableNoCheck(CSOUND *csnd, const char *name) -{ - void **p = NULL; - int i, j, k, len; - - len = (int) strlen(name); - /* search tree */ - i = -1; - p = csnd->namedGlobals; - while (++i < (len - 1)) { - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - p = (void**) (p[j]); - p = (void**) (p[k]); - } - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - p = (void**) (p[j]); - /* return with pointer */ - return ((void*) p[k + 1]); -} - -/** - * Free memory allocated for "name" and remove "name" from the database. - * Return value is CSOUND_SUCCESS on success, or CSOUND_ERROR if the name is - * not defined. - */ -PUBLIC int csoundDestroyGlobalVariable(CSOUND *csnd, const char *name) -{ - void **p = NULL; - int i, j, k, len; - /* check for a valid name */ - if (UNLIKELY(csoundQueryGlobalVariable(csnd, name) == (void*) NULL)) - return CSOUND_ERROR; - len = (int) strlen(name); - /* search tree (simple version, as the name will surely be found) */ - i = -1; - p = csnd->namedGlobals; - while (++i < (len - 1)) { - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - p = (void**) (p[j]); - p = (void**) (p[k]); - } - j = ((int) name[i] & 0x78) >> 3; /* bits 3-6 */ - k = ((int) name[i] & 0x07) << 1; /* bits 0-2 */ - p = (void**) (p[j]); - /* free memory and clear pointer */ - free((void*) p[k + 1]); - p[k + 1] = (void*) NULL; - /* done */ - return CSOUND_SUCCESS; -} - -/* recursively free all allocated globals */ - -static void free_global_variable(void **p) -{ - void **pp; - int i, j; - for (i = 0; i < 16; i++) { - if (p[i] == (void*) NULL) - continue; /* nothing here */ - pp = (void**) p[i]; - for (j = 0; j < 16; j += 2) { - if (pp[j + 1] != (void*) NULL) { - /* found allocated memory, free it now */ - free((void*) pp[j + 1]); - pp[j + 1] = NULL; - } - /* recursively search entire database */ - if (pp[j] != (void*) NULL) - free_global_variable((void**) pp[j]); - } - } -} - -/** - * Free entire global variable database. This function is for internal use - * only (e.g. by RESET routines). - */ -void csoundDeleteAllGlobalVariables(CSOUND *csound) -{ - csound->namedGlobalsCurrLimit = 0; - csound->namedGlobalsMaxLimit = 0; - if (csound->namedGlobals == NULL) - return; - free_global_variable(csound->namedGlobals); - free(csound->namedGlobals); - csound->namedGlobals = (void**) NULL; -} - -#else /* CSGLOBALS_USE_TREE */ - -typedef struct GlobalVariableEntry_s { - struct GlobalVariableEntry_s *nxt; - unsigned char *name; - void *p; - void *dummy; -} GlobalVariableEntry_t; /** * Allocate nbytes bytes of memory that can be accessed later by calling @@ -862,16 +224,12 @@ PUBLIC int csoundCreateGlobalVariable(CSOUND *csnd, const char *name, size_t nbytes) { - GlobalVariableEntry_t *p, **pp; - int i, structBytes, nameBytes, allocBytes; - unsigned char h; + void* p; /* create new empty database if it does not exist yet */ if (csnd->namedGlobals == NULL) { - csnd->namedGlobals = (void**) malloc(sizeof(void*) * 256); + csnd->namedGlobals = cs_hash_table_create(csnd); if (UNLIKELY(csnd->namedGlobals == NULL)) return CSOUND_MEMORY; - for (i = 0; i < 256; i++) - csnd->namedGlobals[i] = (void*) NULL; } /* check for valid parameters */ if (UNLIKELY(name == NULL)) @@ -880,43 +238,15 @@ return CSOUND_ERROR; if (UNLIKELY(nbytes < (size_t) 1 || nbytes >= (size_t) 0x7F000000L)) return CSOUND_ERROR; - /* calculate hash value */ - h = name_hash_2(csnd, name); - /* number of bytes to allocate */ - structBytes = ((int) sizeof(GlobalVariableEntry_t) + 15) & (~15); - nameBytes = (((int) strlen(name) + 1) + 15) & (~15); - allocBytes = ((int) nbytes + 15) & (~15); - /* allocate memory */ - i = structBytes + nameBytes + allocBytes; - p = (GlobalVariableEntry_t*) malloc((size_t) i); + + if (cs_hash_table_get(csnd, csnd->namedGlobals, (char*)name) != NULL) + return CSOUND_ERROR; + + p = mcalloc(csnd, nbytes); if (UNLIKELY(p == NULL)) return CSOUND_MEMORY; - /* initialise structure */ - memset((void*) p, 0, (size_t) i); - p->nxt = (GlobalVariableEntry_t*) NULL; - p->name = (unsigned char*) p + (int) structBytes; - p->p = (void*) ((unsigned char*) p + (int) (structBytes + nameBytes)); - strcpy((char*) (p->name), name); - /* link into database */ - if (csnd->namedGlobals[(int) h] == (void*) NULL) { - /* hash value is not used yet */ - csnd->namedGlobals[(int) h] = (void*) p; - return CSOUND_SUCCESS; - } - /* need to search */ - pp = (GlobalVariableEntry_t**) &(csnd->namedGlobals[(int) h]); - while (1) { - /* check for a conflicting name */ - if (UNLIKELY(sCmp(name, (char*) ((*pp)->name)) == 0)) { - free((void*) p); - return CSOUND_ERROR; - } - if ((*pp)->nxt == NULL) - break; - pp = &((*pp)->nxt); - } - (*pp)->nxt = (GlobalVariableEntry_t*) p; - /* successfully finished */ + + cs_hash_table_put(csnd, csnd->namedGlobals, (char*)name, p); return CSOUND_SUCCESS; } @@ -926,28 +256,14 @@ */ PUBLIC void *csoundQueryGlobalVariable(CSOUND *csnd, const char *name) { - GlobalVariableEntry_t *p; - unsigned char h; /* check if there is an actual database to search */ - if (csnd->namedGlobals == NULL) - return NULL; + if (csnd->namedGlobals == NULL) return NULL; + /* check for a valid name */ - if (name == NULL) - return NULL; - if (name[0] == '\0') - return NULL; - /* calculate hash value */ - h = name_hash_2(csnd, name); - /* search tree */ - p = (GlobalVariableEntry_t*) (csnd->namedGlobals[(int) h]); - if (p == NULL) - return NULL; - while (sCmp(name, (char*) (p->name)) != 0) { - p = (GlobalVariableEntry_t*) p->nxt; - if (p == NULL) - return NULL; - } - return (void*) (p->p); + if (name == NULL) return NULL; + if (name[0] == '\0') return NULL; + + return cs_hash_table_get(csnd, csnd->namedGlobals, (char*) name); } /** @@ -958,19 +274,7 @@ */ PUBLIC void *csoundQueryGlobalVariableNoCheck(CSOUND *csnd, const char *name) { - GlobalVariableEntry_t *p; - unsigned char h; - - /* calculate hash value */ - h = name_hash_2(csnd, name); - /* search tree */ - p = (GlobalVariableEntry_t*) (csnd->namedGlobals[(int) h]); - if (!p) { - return 0; - } - while (p->nxt != NULL && sCmp(name, (char*) (p->name)) != 0) - p = (GlobalVariableEntry_t*) p->nxt; - return (void*) (p->p); + return cs_hash_table_get(csnd, csnd->namedGlobals, (char*) name); } /** @@ -980,27 +284,13 @@ */ PUBLIC int csoundDestroyGlobalVariable(CSOUND *csnd, const char *name) { - GlobalVariableEntry_t *p, *prvp; - unsigned char h; - - /* check for a valid name */ - if (UNLIKELY(csoundQueryGlobalVariable(csnd, name) == (void*) NULL)) + void *p = cs_hash_table_get(csnd, csnd->namedGlobals, (char*)name); + if (UNLIKELY(p == NULL)) return CSOUND_ERROR; - /* calculate hash value */ - h = name_hash_2(csnd, name); - /* search database (simple version, as the name will surely be found) */ - prvp = NULL; - p = (GlobalVariableEntry_t*) (csnd->namedGlobals[(int) h]); - while (sCmp(name, (char*) (p->name)) != 0) { - prvp = p; - p = (GlobalVariableEntry_t*) p->nxt; - } - if (prvp != NULL) - prvp->nxt = (struct GlobalVariableEntry_s *) (p->nxt); - else - csnd->namedGlobals[(int) h] = (void*) (p->nxt); - free((void*) p); - /* done */ + + mfree(csnd, p); + cs_hash_table_remove(csnd, csnd->namedGlobals, (char*) name); + return CSOUND_SUCCESS; } @@ -1010,112 +300,8 @@ */ void csoundDeleteAllGlobalVariables(CSOUND *csound) { - GlobalVariableEntry_t *p, *prvp; - int i; - - if (csound->namedGlobals == NULL) - return; - for (i = 0; i < 256; i++) { - prvp = (GlobalVariableEntry_t*) NULL; - p = (GlobalVariableEntry_t*) csound->namedGlobals[i]; - while (p != NULL) { - prvp = p; - p = (GlobalVariableEntry_t*) (p->nxt); - if (prvp != NULL) - free((void*) prvp); - } - } - free((void*) csound->namedGlobals); - csound->namedGlobals = (void**) NULL; -} - -#endif /* CSGLOBALS_USE_TREE */ - - /* ------------------------------------------------------------------------ */ - -/** - * The following functions implement deferred loading of opcode plugins. - */ - -/* returns non-zero if 'fname' (not full path) */ -/* is marked for deferred loading */ - -int csoundCheckOpcodePluginFile(CSOUND *csound, const char *fname) -{ -#if !(defined(LINUX) || defined(__unix__) || defined(__MACH__)) - char buf[512]; - size_t i; -#endif - CsoundOpcodePluginFile_t **pp, *p; - const char *s; - unsigned char h; - - if (fname == NULL || fname[0] == (char) 0) - return 0; -#if !(defined(LINUX) || defined(__unix__) || defined(__MACH__)) - /* on some platforms, file names are case insensitive */ - i = (size_t) 0; - do { - if (isupper(fname[i])) - buf[i] = (char) tolower(fname[i]); - else - buf[i] = fname[i]; - if (++i >= (size_t) 512) - return 0; - } while (fname[i] != (char) 0); - buf[i] = (char) 0; - s = &(buf[0]); -#else - s = fname; -#endif - pp = (CsoundOpcodePluginFile_t**) csound->pluginOpcodeFiles; - h = name_hash_2(csound, s); - p = (CsoundOpcodePluginFile_t*) NULL; - if (pp) { - p = pp[h]; - while (p) { - if (!sCmp(p->fname, s)) - break; - p = p->nxt; - } - } - if (!p) - return 0; - /* file exists, but is not loaded yet */ - p->isLoaded = 0; - return 1; -} - -int csoundLoadAllPluginOpcodes(CSOUND *csound) -{ - CsoundOpcodePluginFile_t *p; - int i, err; - - if (csound->pluginOpcodeFiles == NULL) - return CSOUND_SUCCESS; - - err = CSOUND_SUCCESS; - for (i = 0; i < 256; i++) { - p = ((CsoundOpcodePluginFile_t**) csound->pluginOpcodeFiles)[i]; - while (p) { - if (!p->isLoaded) { - int retval; - retval = csoundLoadAndInitModule(csound, p->fullName); - p->isLoaded = (retval == 0 ? 1 : -1); - if (retval != 0 && retval != CSOUND_ERROR) { - /* record serious errors */ - if (retval < err) - err = retval; - } - } - p = p->nxt; - } - } -/* csoundDestroyOpcodeDB(csound); */ - /* report any errors */ - return (err == 0 || err == CSOUND_MEMORY ? err : CSOUND_ERROR); -} + if (csound == NULL || csound->namedGlobals == NULL) return; -#ifdef __cplusplus + cs_hash_table_mfree_complete(csound, csound->namedGlobals); + csound->namedGlobals = NULL; } -#endif diff -Nru csound-5.17.11~dfsg/Engine/new_orc_parser.c csound-6.02~dfsg/Engine/new_orc_parser.c --- csound-5.17.11~dfsg/Engine/new_orc_parser.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/new_orc_parser.c 2014-01-07 16:54:20.000000000 +0000 @@ -24,11 +24,24 @@ */ #include "csoundCore.h" -#include "csound_orcparse.h" #include "csound_orc.h" -#include "parse_param.h" #include "corfile.h" +#if defined(HAVE_DIRENT_H) +# include +# if 0 && defined(__MACH__) +typedef void* DIR; +DIR opendir(const char *); +struct dirent *readdir(DIR*); +int closedir(DIR*); +# endif +#endif + +#if defined(WIN32) +# include +# include +#endif + extern void csound_orcrestart(FILE*, void *); extern int csound_orcdebug; @@ -44,20 +57,14 @@ extern int csound_orcparse(PARSE_PARM *, void *, CSOUND*, TREE*); extern void csound_orclex_init(void *); extern void csound_orcset_extra(void *, void *); -//extern void csound_orc_scan_string(char *, void *); extern void csound_orcset_lineno(int, void*); extern void csound_orclex_destroy(void *); extern void init_symbtab(CSOUND*); extern void print_tree(CSOUND *, char *, TREE *); -extern TREE* verify_tree(CSOUND *, TREE *); +extern TREE* verify_tree(CSOUND *, TREE *, TYPE_TABLE*); extern TREE *csound_orc_expand_expressions(CSOUND *, TREE *); extern TREE* csound_orc_optimize(CSOUND *, TREE *); -extern void csound_orc_compile(CSOUND *, TREE *); -#ifdef PARCS -extern TREE *csp_locks_insert(CSOUND *csound, TREE *root); -void csp_locks_cache_build(CSOUND *); -void csp_weights_calculate(CSOUND *, TREE *); -#endif +extern void csp_orc_analyze_tree(CSOUND* csound, TREE* root); void csound_print_preextra(CSOUND *csound, PRE_PARM *x) @@ -80,9 +87,45 @@ return loc; } -int new_orc_parser(CSOUND *csound) +// Code to add #includes of UDOs +void add_include_udo_dir(CORFIL *xx) +{ + char *dir = getenv("CS_UDO_DIR"); + char buff[1024]; + if (dir) { + DIR *udo = opendir(dir); + printf("** found CS_UDO_DIR=%s\n", dir); + if (udo) { + struct dirent *f; + //printf("**and it opens\n"); + strcpy(buff, "#line 0\n"); + while ((f = readdir(udo)) != NULL) { + char *fname = &(f->d_name[0]); + int n = (int)strlen(fname); + printf("** name=%s n=%d\n", fname, n); + if (n>4 && (strcmp(&fname[n-4], ".udo")==0)) { + strcpy(buff, "#include \""); + strncat(buff, dir, 1024); + strncat(buff, "/", 1024); + strncat(buff, fname, 1024); + strncat(buff, "\"\n", 1024); + if (strlen(buff)>768) { + corfile_preputs(buff, xx); + buff[0] ='\0'; + } + } + } + closedir(udo); + strncat(buff, "###\n", 1024); + corfile_preputs(buff, xx); + } + } + //printf("Giving\n%s", corfile_body(xx)); +} + +TREE *csoundParseOrc(CSOUND *csound, const char *str) { - int retVal; + int err; OPARMS *O = csound->oparms; { PRE_PARM qq; @@ -92,9 +135,16 @@ csound_preset_extra(&qq, qq.yyscanner); qq.line = csound->orcLineOffset; csound->expanded_orc = corfile_create_w(); - { + file_to_int(csound, "**unknown**"); + if (str == NULL) { char bb[80]; - file_to_int(csound, "**unknown**"); + + if (csound->orchstr==NULL && !csound->oparms->daemon) + csound->Die(csound, + Str("Failed to open input file %s\n"), csound->orchname); + else if(csound->orchstr==NULL && csound->oparms->daemon) return NULL; + + add_include_udo_dir(csound->orchstr); if (csound->orchname==NULL || csound->orchname[0]=='\0') csound->orchname = csound->csdname; /* We know this is the start so stack is empty so far */ @@ -104,6 +154,17 @@ sprintf(bb, "#line %d\n", csound->orcLineOffset); corfile_puts(bb, csound->expanded_orc); } + else { + if (csound->orchstr == NULL || + corfile_body(csound->orchstr) == NULL) + csound->orchstr = corfile_create_w(); + else + corfile_reset(csound->orchstr); + corfile_puts(str, csound->orchstr); + corfile_puts("\n#exit\n", csound->orchstr); + corfile_putc('\0', csound->orchstr); + corfile_putc('\0', csound->orchstr); + } csound->DebugMsg(csound, "Calling preprocess on >>%s<<\n", corfile_body(csound->orchstr)); //csound->DebugMsg(csound,"FILE: %s \n", csound->orchstr->body); @@ -117,14 +178,19 @@ csound->LongJmp(csound, 1); } csound_prelex_destroy(qq.yyscanner); - csound->DebugMsg(csound, "yielding >>%s<<\n", corfile_body(csound->expanded_orc)); + csound->DebugMsg(csound, "yielding >>%s<<\n", + corfile_body(csound->expanded_orc)); corfile_rm(&csound->orchstr); } { TREE* astTree = (TREE *)mcalloc(csound, sizeof(TREE)); + TREE* newRoot; PARSE_PARM pp; + TYPE_TABLE* typeTable = NULL; + /* Parse */ memset(&pp, '\0', sizeof(PARSE_PARM)); + init_symbtab(csound); csound_orcdebug = O->odebug; @@ -133,22 +199,24 @@ csound_orcset_extra(&pp, pp.yyscanner); csound_orc_scan_buffer(corfile_body(csound->expanded_orc), corfile_tell(csound->expanded_orc), pp.yyscanner); + //csound_orcset_lineno(csound->orcLineOffset, pp.yyscanner); - retVal = csound_orcparse(&pp, pp.yyscanner, csound, astTree); + err = csound_orcparse(&pp, pp.yyscanner, csound, astTree); corfile_rm(&csound->expanded_orc); - if (csound->synterrcnt) retVal = 3; - if (LIKELY(retVal == 0)) { - csound->Message(csound, "Parsing successful!\n"); + if (csound->synterrcnt) err = 3; + if (LIKELY(err == 0)) { + if(csound->oparms->odebug) csound->Message(csound, "Parsing successful!\n"); } else { - if (retVal == 1){ - csound->Message(csound, "Parsing failed due to invalid input!\n"); + if (err == 1){ + csound->Message(csound, Str("Parsing failed due to invalid input!\n")); } - else if (retVal == 2){ - csound->Message(csound, "Parsing failed due to memory exhaustion!\n"); + else if (err == 2){ + csound->Message(csound, + Str("Parsing failed due to memory exhaustion!\n")); } - else if (retVal == 3){ - csound->Message(csound, "Parsing failed due to %d syntax error%s!\n", + else if (err == 3){ + csound->Message(csound, Str("Parsing failed due to %d syntax error%s!\n"), csound->synterrcnt, csound->synterrcnt==1?"":"s"); } goto ending; @@ -157,33 +225,59 @@ print_tree(csound, "AST - INITIAL\n", astTree); } //print_tree(csound, "AST - INITIAL\n", astTree); - astTree = verify_tree(csound, astTree); + typeTable = mmalloc(csound, sizeof(TYPE_TABLE)); + typeTable->udos = NULL; + + typeTable->globalPool = mcalloc(csound, sizeof(CS_VAR_POOL)); + typeTable->instr0LocalPool = mcalloc(csound, sizeof(CS_VAR_POOL)); + + typeTable->localPool = typeTable->instr0LocalPool; + typeTable->labelList = NULL; + + /**** THIS NEXT LINE IS WRONG AS err IS int WHILE FN RETURNS TREE* ****/ + astTree = verify_tree(csound, astTree, typeTable); +// mfree(csound, typeTable->instr0LocalPool); +// mfree(csound, typeTable->globalPool); +// mfree(csound, typeTable); //print_tree(csound, "AST - FOLDED\n", astTree); -#ifdef PARCS - if (LIKELY(O->numThreads > 1)) { - /* insert the locks around global variables before expr expansion */ - astTree = csp_locks_insert(csound, astTree); - csp_locks_cache_build(csound); + + //FIXME - synterrcnt should not be global + if (astTree == NULL || csound->synterrcnt){ + err = 3; + csound->Message(csound, "Parsing failed due to %d semantic error%s!\n", + csound->synterrcnt, csound->synterrcnt==1?"":"s"); + goto ending; } -#endif /* PARCS */ + err = 0; - astTree = csound_orc_expand_expressions(csound, astTree); + //csp_orc_analyze_tree(csound, astTree); +// astTree = csound_orc_expand_expressions(csound, astTree); +// if (UNLIKELY(PARSER_DEBUG)) { - print_tree(csound, "AST - AFTER EXPANSION\n", astTree); + print_tree(csound, "AST - AFTER VERIFICATION/EXPANSION\n", astTree); } -#ifdef PARCS - if (LIKELY(O->numThreads > 1)) { - /* calculate the weights for the instruments */ - csp_weights_calculate(csound, astTree); + + ending: + csound_orclex_destroy(pp.yyscanner); + if(err) { + csound->Warning(csound, Str("Stopping on parser failure\n")); + csoundDeleteTree(csound, astTree); + if (typeTable != NULL) { + mfree(csound, typeTable); + } + return NULL; } -#endif /* PARCS */ astTree = csound_orc_optimize(csound, astTree); - csound_orc_compile(csound, astTree); - ending: - csound_orclex_destroy(pp.yyscanner); + // small hack: use an extra node as head of tree list to hold the + // typeTable, to be used during compilation + newRoot = make_leaf(csound, 0, 0, 0, NULL); + newRoot->markup = typeTable; + newRoot->next = astTree; + + + return newRoot; } - return retVal; } diff -Nru csound-5.17.11~dfsg/Engine/otran.c csound-6.02~dfsg/Engine/otran.c --- csound-5.17.11~dfsg/Engine/otran.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/otran.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,1467 +0,0 @@ -/* - otran.c: - - Copyright (C) 1991, 1997, 2003 Barry Vercoe, John ffitch, Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#include "csoundCore.h" /* OTRAN.C */ -#include -#include -#include - -#include "oload.h" -#include "insert.h" -#include "pstream.h" -#include "namedins.h" /* IV - Oct 31 2002 */ -#include "corfile.h" - -typedef struct NAME_ { - char *namep; - struct NAME_ *nxt; - int type, count; -} NAME; - -typedef struct { - NAME *gblNames[256], *lclNames[256]; /* for 8 bit hash */ - ARGLST *nullist; - ARGOFFS *nulloffs; - int lclkcnt, lclwcnt, lclfixed; - int lclpcnt, lclscnt, lclacnt, lclnxtpcnt; - int lclnxtkcnt, lclnxtwcnt, lclnxtacnt, lclnxtscnt; - int gblnxtkcnt, gblnxtpcnt, gblnxtacnt, gblnxtscnt; - int gblfixed, gblkcount, gblacount, gblscount; - int *nxtargoffp, *argofflim, lclpmax; - char **strpool; - int32 poolcount, strpool_cnt, argoffsize; - int nconsts; - int *constTbl; -} OTRAN_GLOBALS; - -static int gexist(CSOUND *, char *), gbloffndx(CSOUND *, char *); -static int lcloffndx(CSOUND *, char *); -static int constndx(CSOUND *, const char *); -static int strconstndx(CSOUND *, const char *); -static void insprep(CSOUND *, INSTRTXT *); -static void lgbuild(CSOUND *, char *); -static void gblnamset(CSOUND *, char *); -static int plgndx(CSOUND *, char *); -static NAME *lclnamset(CSOUND *, char *); - int lgexist(CSOUND *, const char *); -static void delete_global_namepool(CSOUND *); -static void delete_local_namepool(CSOUND *); - -#define txtcpy(a,b) memcpy(a,b,sizeof(TEXT)); -#define ST(x) (((OTRAN_GLOBALS*) ((CSOUND*) csound)->otranGlobals)->x) - -#define KTYPE 1 -#define WTYPE 2 -#define ATYPE 3 -#define PTYPE 4 -#define STYPE 5 -/* NOTE: these assume that sizeof(MYFLT) is either 4 or 8 */ -#define Wfloats (((int) sizeof(SPECDAT) + 7) / (int) sizeof(MYFLT)) -#define Pfloats (((int) sizeof(PVSDAT) + 7) / (int) sizeof(MYFLT)) - -#ifdef FLOAT_COMPARE -#undef FLOAT_COMPARE -#endif -#ifdef USE_DOUBLE -#define FLOAT_COMPARE(x,y) (fabs((double) (x) / (double) (y) - 1.0) > 1.0e-12) -#else -#define FLOAT_COMPARE(x,y) (fabs((double) (x) / (double) (y) - 1.0) > 5.0e-7) -#endif - -void tranRESET(CSOUND *csound) -{ - void *p; - - delete_local_namepool(csound); - delete_global_namepool(csound); - p = (void*) csound->opcodlst; - csound->opcodlst = NULL; - csound->oplstend = NULL; - if (p != NULL) - free(p); - csound->otranGlobals = NULL; -} - -/* IV - Oct 12 2002: new function to parse arguments of opcode definitions */ - -static int parse_opcode_args(CSOUND *csound, OENTRY *opc) -{ - OPCODINFO *inm = (OPCODINFO*) opc->useropinfo; - char *types, *otypes; - int i, i_incnt, a_incnt, k_incnt, i_outcnt, a_outcnt, k_outcnt, err; - int S_incnt, S_outcnt, f_outcnt, f_incnt, t_incnt, t_outcnt; - int16 *a_inlist, *k_inlist, *i_inlist, *a_outlist, *k_outlist, *i_outlist; - int16 *S_inlist, *S_outlist, *f_inlist, *f_outlist, *t_inlist, *t_outlist; - - /* count the number of arguments, and check types */ - i = i_incnt = S_incnt = a_incnt = k_incnt = f_incnt = f_outcnt = - i_outcnt = S_outcnt = a_outcnt = k_outcnt = t_incnt = t_outcnt = err = 0; - types = inm->intypes; otypes = opc->intypes; - opc->dsblksiz = (uint16) sizeof(UOPCODE); - if (!strcmp(types, "0")) - types++; /* no input args */ - while (*types) { - switch (*types) { - case 'a': - a_incnt++; *otypes++ = *types; - break; - case 'K': - i_incnt++; /* also updated at i-time */ - case 'k': - k_incnt++; *otypes++ = 'k'; - break; - case 'f': - f_incnt++; *otypes++ = *types; - break; - case 't': - t_incnt++; *otypes++ = *types; - break; - case 'i': - case 'o': - case 'p': - case 'j': - i_incnt++; *otypes++ = *types; - break; - case 'S': - S_incnt++; *otypes++ = *types; - break; - default: - synterr(csound, Str("invalid input type for opcode %s"), inm->name); - err++; i--; - } - i++; types++; - if (UNLIKELY(i > OPCODENUMOUTS_MAX)) { - synterr(csound, Str("too many input args for opcode %s"), inm->name); - csound->LongJmp(csound, 1); - } - } - *otypes++ = 'o'; *otypes = '\0'; /* optional arg for local ksmps */ - inm->inchns = i; /* total number of input chnls */ - inm->perf_incnt = a_incnt + k_incnt + f_incnt + t_incnt; - opc->dsblksiz += (uint16) (sizeof(MYFLT*) * i); - /* same for outputs */ - i = 0; - types = inm->outtypes; otypes = opc->outypes; - if (!strcmp(types, "0")) - types++; /* no output args */ - while (*types) { - if (UNLIKELY(i >= OPCODENUMOUTS_MAX)) { - synterr(csound, Str("too many output args for opcode %s"), inm->name); - csound->LongJmp(csound, 1); - } - switch (*types) { - case 'a': - a_outcnt++; *otypes++ = *types; - break; - case 'K': - i_outcnt++; /* also updated at i-time */ - case 'k': - k_outcnt++; *otypes++ = 'k'; - break; - case 'f': - f_outcnt++; *otypes++ = *types; - break; - case 't': - t_outcnt++; *otypes++ = *types; - break; - case 'i': - i_outcnt++; *otypes++ = *types; - break; - case 'S': - S_outcnt++; *otypes++ = *types; - break; - default: - synterr(csound, Str("invalid output type for opcode %s"), inm->name); - err++; i--; - } - i++; types++; - } - *otypes = '\0'; - inm->outchns = i; /* total number of output chnls */ - inm->perf_outcnt = a_outcnt + k_outcnt + f_outcnt + t_outcnt; - opc->dsblksiz += (uint16) (sizeof(MYFLT*) * i); - opc->dsblksiz = ((opc->dsblksiz + (uint16) 15) - & (~((uint16) 15))); /* align (needed ?) */ - /* now build index lists for the various types of arguments */ - i = i_incnt + S_incnt + inm->perf_incnt + - i_outcnt + S_outcnt + inm->perf_outcnt; - i_inlist = inm->in_ndx_list = (int16*) mmalloc(csound, - sizeof(int16) * (i + 14)); - S_inlist = i_inlist + i_incnt + 1; - a_inlist = S_inlist + S_incnt + 1; - k_inlist = a_inlist + a_incnt + 1; - f_inlist = k_inlist + k_incnt + 1; - t_inlist = f_inlist + f_incnt + 1; - i = 0; types = inm->intypes; - while (*types) { - switch (*types++) { - case 'a': *a_inlist++ = i; break; - case 'k': *k_inlist++ = i; break; - case 'f': *f_inlist++ = i; break; - case 't': *t_inlist++ = i; break; - case 'K': *k_inlist++ = i; /* also updated at i-time */ - case 'i': - case 'o': - case 'p': - case 'j': *i_inlist++ = i; break; - case 'S': *S_inlist++ = i; break; - } - i++; - } - *i_inlist = *S_inlist = *a_inlist = *k_inlist = *f_inlist = *t_inlist = -1; /* put delimiters */ - i_outlist = inm->out_ndx_list = t_inlist + 1; - S_outlist = i_outlist + i_outcnt + 1; - a_outlist = S_outlist + S_outcnt + 1; - k_outlist = a_outlist + a_outcnt + 1; - f_outlist = k_outlist + k_outcnt + 1; - t_outlist = f_outlist + f_outcnt + 1; - i = 0; types = inm->outtypes; - while (*types) { - switch (*types++) { - case 'a': *a_outlist++ = i; break; - case 'k': *k_outlist++ = i; break; - case 'f': *f_outlist++ = i; break; - case 't': *t_outlist++ = i; break; - case 'K': *k_outlist++ = i; /* also updated at i-time */ - case 'i': *i_outlist++ = i; break; - case 'S': *S_outlist++ = i; break; - } - i++; - } - *i_outlist = *S_outlist = *a_outlist = *k_outlist = - *f_outlist = *t_outlist = -1; /* put delimiters */ - return err; -} - -static int pnum(char *s) /* check a char string for pnum format */ - /* and return the pnum ( >= 0 ) */ -{ /* else return -1 */ - int n; - - if (*s == 'p' || *s == 'P') - if (sscanf(++s, "%d", &n)) - return(n); - return(-1); -} - -void otran(CSOUND *csound) -{ - OPARMS *O = csound->oparms; - TEXT *tp; - int init = 1; - INSTRTXT *ip = NULL; - INSTRTXT *prvinstxt = &(csound->instxtanchor); - OPTXT *bp, *prvbp = NULL; - ARGLST *alp; - char *s; - int32 pmax = -1, nn; - int32 n = 0, opdstot = 0, count, sumcount, instxtcount, optxtcount; - - if (csound->otranGlobals == NULL) { - csound->otranGlobals = csound->Calloc(csound, sizeof(OTRAN_GLOBALS)); - } - csound->instrtxtp = (INSTRTXT **) mcalloc(csound, (1 + csound->maxinsno) - * sizeof(INSTRTXT*)); - csound->opcodeInfo = NULL; /* IV - Oct 20 2002 */ - - strconstndx(csound, "\"\""); - - gblnamset(csound, "sr"); /* enter global reserved words */ - gblnamset(csound, "kr"); - gblnamset(csound, "ksmps"); - gblnamset(csound, "nchnls"); - gblnamset(csound, "nchnls_i"); - gblnamset(csound, "0dbfs"); /* no commandline override for that! */ - gblnamset(csound, "$sr"); /* incl command-line overrides */ - gblnamset(csound, "$kr"); - gblnamset(csound, "$ksmps"); - - rdorchfile(csound); /* go read orch file */ - corfile_rm(&(csound->orchstr)); - - csound->pool = (MYFLT*) mmalloc(csound, NCONSTS * sizeof(MYFLT)); - ST(poolcount) = 0; - ST(nconsts) = NCONSTS; - ST(constTbl) = (int*) mcalloc(csound, (256 + NCONSTS) * sizeof(int)); - constndx(csound, "0"); - - while ((tp = getoptxt(csound, &init)) != NULL) { - /* then for each opcode: */ - unsigned int threads = 0; - int opnum = tp->opnum; - switch (opnum) { - case INSTR: - case OPCODE: /* IV - Sep 8 2002 */ - ip = (INSTRTXT *) mcalloc(csound, sizeof(INSTRTXT)); - prvinstxt = prvinstxt->nxtinstxt = ip; - txtcpy((char*) &ip->t, (char*) tp); - prvbp = (OPTXT *) ip; /* begin an optxt chain */ - alp = ip->t.inlist; -/* <---- IV - Oct 16 2002: rewritten this code ---- */ - if (opnum == INSTR) { - int err = 0, cnt, i; - if (!alp->count) { /* IV - Sep 8 2002: check for missing name */ - synterr(csound, Str("missing instrument number or name")); - continue; - } - /* IV - Oct 16 2002: allow both numbers and names for instr */ - for (cnt = 0; cnt < alp->count; cnt++) { - char *c = alp->arg[cnt]; - if (UNLIKELY(strlen(c) <= 0)) { - synterr(csound, Str("missing instrument number or name")); - err++; continue; - } - if (isdigit(*c)) { /* numbered instrument */ - if (UNLIKELY(!sscanf(c, "%d", &n) || n < 0)) { - synterr(csound, Str("illegal instr number")); - err++; continue; - } - if (n > csound->maxinsno) { - int old_maxinsno = csound->maxinsno; - /* expand */ - while (n>csound->maxinsno) csound->maxinsno += MAXINSNO; - csound->instrtxtp = (INSTRTXT**) - mrealloc(csound, csound->instrtxtp, (1 + csound->maxinsno) - * sizeof(INSTRTXT*)); - /* Array expected to be nulled so.... */ - for (i = old_maxinsno + 1; i <= csound->maxinsno; i++) - csound->instrtxtp[i] = NULL; - } - if (UNLIKELY(csound->instrtxtp[n] != NULL)) { - synterr(csound, Str("instr %ld redefined"), (int32) n); - err++; continue; - } - csound->instrtxtp[n] = ip; - } - else { /* named instrument */ - int32 insno_priority = -1L; - if (*c == '+') { - insno_priority--; c++; - } - /* IV - Oct 31 2002: some error checking */ - if (UNLIKELY(!check_instr_name(c))) { - synterr(csound, Str("invalid name for instrument")); - err++; continue; - } - /* IV - Oct 31 2002: store the name */ - if (UNLIKELY(!named_instr_alloc(csound, c, ip, - insno_priority))) { - synterr(csound, Str("instr %s redefined"), c); - err++; continue; - } - ip->insname = c; /* IV - Nov 10 2002: also in INSTRTXT */ - n = -2; - } - } - if (UNLIKELY(err)) continue; - if (n) putop(csound, &ip->t); /* print, except i0 */ - } - else { /* opcode definition with string name */ - OENTRY tmpEntry, *opc, *newopc; - int32 newopnum; - OPCODINFO *inm; - char *name = alp->arg[0]; - - /* some error checking */ - if (UNLIKELY(!alp->count || (strlen(name) <= 0))) { - synterr(csound, Str("No opcode name")); - continue; - } - /* IV - Oct 31 2002 */ - if (UNLIKELY(!check_instr_name(name))) { - synterr(csound, Str("invalid name for opcode")); - continue; - } - if (UNLIKELY(ip->t.inlist->count != 3)) { - synterr(csound, Str("opcode declaration error " - "(usage: opcode name, outtypes, intypes) " - "-- opcode %s"), name); - continue; - } - - /* IV - Oct 31 2002: check if opcode is already defined */ - newopnum = find_opcode(csound, name); - if (newopnum) { - /* IV - Oct 31 2002: redefine old opcode if possible */ - if (UNLIKELY(newopnum < SETEND || !strcmp(name, "subinstr"))) { - synterr(csound, Str("cannot redefine %s"), name); - continue; - } - csound->Message(csound, - Str("WARNING: redefined opcode: %s\n"), name); - } - /* IV - Oct 31 2002 */ - /* store the name in a linked list (note: must use mcalloc) */ - inm = (OPCODINFO *) mcalloc(csound, sizeof(OPCODINFO)); - inm->name = name; - inm->intypes = alp->arg[2]; - inm->outtypes = alp->arg[1]; - inm->ip = ip; - inm->prv = csound->opcodeInfo; - csound->opcodeInfo = inm; - /* IV - Oct 31 2002: */ - /* create a fake opcode so we can call it as such */ - opc = csound->opcodlst + find_opcode(csound, ".userOpcode"); - memcpy(&tmpEntry, opc, sizeof(OENTRY)); - tmpEntry.opname = name; - csound->AppendOpcodes(csound, &tmpEntry, 1); - if (!newopnum) - newopnum = (int32) ((OENTRY*) csound->oplstend - - (OENTRY*) csound->opcodlst) - 1L; - newopc = &(csound->opcodlst[newopnum]); - newopc->useropinfo = (void*) inm; /* ptr to opcode parameters */ - ip->insname = name; ip->opcode_info = inm; /* IV - Nov 10 2002 */ - /* check in/out types and copy to the opcode's */ - /* IV - Sep 8 2002: opcodes have an optional arg for ksmps */ - newopc->outypes = mmalloc(csound, strlen(alp->arg[1]) + 1 - + strlen(alp->arg[2]) + 2); - newopc->intypes = &(newopc->outypes[strlen(alp->arg[1]) + 1]); - if (parse_opcode_args(csound, newopc) != 0) - continue; - n = -2; -/* ---- IV - Oct 16 2002: end of new code ----> */ - putop(csound, &ip->t); - } - delete_local_namepool(csound); /* clear lcl namlist */ - ST(lclnxtkcnt) = 0; /* for rebuilding */ - ST(lclnxtwcnt) = ST(lclnxtacnt) = 0; - ST(lclnxtpcnt) = ST(lclnxtscnt) = 0; - opdstot = 0; - threads = 0; - pmax = 3L; /* set minimum pflds */ - break; - case ENDIN: - case ENDOP: /* IV - Sep 8 2002 */ - bp = (OPTXT *) mcalloc(csound, (int32)sizeof(OPTXT)); - txtcpy((char *)&bp->t, (char *)tp); - prvbp->nxtop = bp; - bp->nxtop = NULL; /* terminate the optxt chain */ - if (UNLIKELY(O->odebug)) { - putop(csound, &bp->t); - csound->Message(csound, "pmax %d, kcnt %d, " - "wcnt %d, acnt %d, pcnt %d, scnt %d\n", - pmax, ST(lclnxtkcnt), - ST(lclnxtwcnt), ST(lclnxtacnt), - ST(lclnxtpcnt), ST(lclnxtscnt)); - } - ip->pmax = (int)pmax; - ip->pextrab = ((n = pmax-3L) > 0 ? (int) n * sizeof(MYFLT) : 0); - ip->pextrab = ((int) ip->pextrab + 7) & (~7); - ip->mdepends = threads >> 4; - ip->lclkcnt = ST(lclnxtkcnt); - /* align to 8 bytes for "spectral" types */ - if ((int) sizeof(MYFLT) < 8 && - (ST(lclnxtwcnt) + ST(lclnxtpcnt)) > 0) - ip->lclkcnt = (ip->lclkcnt + 1) & (~1); - ip->lclwcnt = ST(lclnxtwcnt); - ip->lclacnt = ST(lclnxtacnt); - ip->lclpcnt = ST(lclnxtpcnt); - ip->lclscnt = ST(lclnxtscnt); - ip->lclfixed = ST(lclnxtkcnt) + ST(lclnxtwcnt) * Wfloats - + ST(lclnxtpcnt) * Pfloats; - ip->opdstot = opdstot; /* store total opds reqd */ - ip->muted = 1; /* Allow to play */ - n = -1; /* No longer in an instrument */ - break; - default: - bp = (OPTXT *) mcalloc(csound, (int32)sizeof(OPTXT)); - txtcpy((char *)&bp->t, (char *)tp); - prvbp = prvbp->nxtop = bp; /* link into optxt chain */ - threads |= csound->opcodlst[opnum].thread; - opdstot += csound->opcodlst[opnum].dsblksiz; /* sum opds's */ - if (UNLIKELY(O->odebug)) putop(csound, &bp->t); - for (alp=bp->t.inlist, nn=alp->count; nn>0; ) { - s = alp->arg[--nn]; - if ((n = pnum(s)) >= 0) - { if (n > pmax) pmax = n; } - else lgbuild(csound, s); - } - for (alp=bp->t.outlist, nn=alp->count; nn>0; ) { - s = alp->arg[--nn]; - if (UNLIKELY(*s == '"')) { - synterr(csound, Str("string constant used as output")); - continue; - } - if ((n = pnum(s)) >= 0) { - if (n > pmax) pmax = n; - } - else lgbuild(csound, s); - if (!nn && bp->t.opcod[1] == '.' /* rsvd glbal = n ? */ - && strcmp(bp->t.opcod,"=.r")==0) { /* (assume const) */ - MYFLT constval = csound->pool[constndx(csound, - bp->t.inlist->arg[0])]; - if (strcmp(s, "sr") == 0) - csound->tran_sr = constval; /* modify otran defaults*/ - else if (strcmp(s, "kr") == 0) - csound->tran_kr = constval; - else if (strcmp(s, "ksmps") == 0) - csound->tran_ksmps = constval; - else if (strcmp(s, "nchnls") == 0) - csound->tran_nchnlsi = csound->tran_nchnls = (int) constval; - else if (strcmp(s, "nchnls_i") == 0) - csound->tran_nchnlsi = (int) constval; - /* we have set this as reserved in rdorch.c */ - else if (strcmp(s, "0dbfs") == 0) - csound->tran_0dbfs = constval; - } - } - n = 0; /* Mark as unfinished */ - break; - } - } - if (UNLIKELY(n != -1)) - synterr(csound, Str("Missing endin")); - /* now add the instruments with names, assigning them fake instr numbers */ - named_instr_assign_numbers(csound); /* IV - Oct 31 2002 */ - if (csound->opcodeInfo) { - int num = csound->maxinsno; /* store after any other instruments */ - OPCODINFO *inm = csound->opcodeInfo; - /* IV - Oct 31 2002: now add user defined opcodes */ - while (inm) { - /* we may need to expand the instrument array */ - if (++num > csound->maxopcno) { - int i; - i = (csound->maxopcno > 0 ? csound->maxopcno : csound->maxinsno); - csound->maxopcno = i + MAXINSNO; - csound->instrtxtp = (INSTRTXT**) - mrealloc(csound, csound->instrtxtp, (1 + csound->maxopcno) - * sizeof(INSTRTXT*)); - /* Array expected to be nulled so.... */ - while (++i <= csound->maxopcno) csound->instrtxtp[i] = NULL; - } - inm->instno = num; - csound->instrtxtp[num] = inm->ip; - inm = inm->prv; - } - } - /* Deal with defaults and consistency */ - if (csound->tran_ksmps == FL(-1.0)) { - if (csound->tran_sr == FL(-1.0)) csound->tran_sr = DFLT_SR; - if (csound->tran_kr == FL(-1.0)) csound->tran_kr = DFLT_KR; - csound->tran_ksmps = (MYFLT) ((int) (csound->tran_sr / csound->tran_kr - + FL(0.5))); - } - else if (csound->tran_kr == FL(-1.0)) { - if (csound->tran_sr == FL(-1.0)) csound->tran_sr = DFLT_SR; - csound->tran_kr = csound->tran_sr / csound->tran_ksmps; - } - else if (csound->tran_sr == FL(-1.0)) { - csound->tran_sr = csound->tran_kr * csound->tran_ksmps; - } - /* That deals with missing values, however we do need ksmps to be integer */ - { - CSOUND *p = (CSOUND*) csound; - char err_msg[128]; - sprintf(err_msg, "sr = %.7g, kr = %.7g, ksmps = %.7g\nerror:", - p->tran_sr, p->tran_kr, p->tran_ksmps); - if (UNLIKELY(p->tran_sr <= FL(0.0))) - synterr(p, Str("%s invalid sample rate"), err_msg); - if (UNLIKELY(p->tran_kr <= FL(0.0))) - synterr(p, Str("%s invalid control rate"), err_msg); - else if (UNLIKELY(p->tran_ksmps < FL(0.75) || - FLOAT_COMPARE(p->tran_ksmps, MYFLT2LRND(p->tran_ksmps)))) - synterr(p, Str("%s invalid ksmps value"), err_msg); - else if (UNLIKELY(FLOAT_COMPARE(p->tran_sr, - (double) p->tran_kr * p->tran_ksmps))) - synterr(p, Str("%s inconsistent sr, kr, ksmps"), err_msg); - } - - ip = csound->instxtanchor.nxtinstxt; - bp = (OPTXT *) ip; - while (bp != (OPTXT *) NULL && (bp = bp->nxtop) != NULL) { - /* chk instr 0 for illegal perfs */ - int thread, opnum = bp->t.opnum; - if (opnum == ENDIN) break; - if (opnum == LABEL) continue; - if (UNLIKELY((thread = csound->opcodlst[opnum].thread) & 06 || - (!thread && bp->t.pftype != 'b'))) - synterr(csound, Str("perf-pass statements illegal in header blk")); - } - if (UNLIKELY(csound->synterrcnt)) { - print_opcodedir_warning(csound); - csound->Die(csound, Str("%d syntax errors in orchestra. " - "compilation invalid"), csound->synterrcnt); - } - if (UNLIKELY(O->syntaxCheckOnly)) { - /* no need to go any further, so cleanup */ - delete_local_namepool(csound); - delete_global_namepool(csound); - mfree(csound, ST(constTbl)); - ST(constTbl) = NULL; - return; - } - if (UNLIKELY(O->odebug)) { - int32 n; - MYFLT *p; - csound->Message(csound, "poolcount = %d, strpool_cnt = %d\n", - ST(poolcount), ST(strpool_cnt)); - csound->Message(csound, "pool:"); - for (n = ST(poolcount), p = csound->pool; n--; p++) - csound->Message(csound, "\t%g", *p); - csound->Message(csound, "\n"); - csound->Message(csound, "strpool:"); - for (n = 0L; n < ST(strpool_cnt); n++) - csound->Message(csound, "\t%s", ST(strpool)[n]); - csound->Message(csound, "\n"); - } - ST(gblfixed) = ST(gblnxtkcnt) + ST(gblnxtpcnt) * (int) Pfloats; - ST(gblkcount) = ST(gblnxtkcnt); - /* align to 8 bytes for "spectral" types */ - if ((int) sizeof(MYFLT) < 8 && ST(gblnxtpcnt)) - ST(gblkcount) = (ST(gblkcount) + 1) & (~1); - ST(gblacount) = ST(gblnxtacnt); - ST(gblscount) = ST(gblnxtscnt); - - ip = &(csound->instxtanchor); - for (sumcount = 0; (ip = ip->nxtinstxt) != NULL; ) {/* for each instxt */ - OPTXT *optxt = (OPTXT *) ip; - int optxtcount = 0; - while ((optxt = optxt->nxtop) != NULL) { /* for each op in instr */ - TEXT *ttp = &optxt->t; - optxtcount += 1; - if (ttp->opnum == ENDIN /* (until ENDIN) */ - || ttp->opnum == ENDOP) break; /* (IV - Oct 26 2002: or ENDOP) */ - if ((count = ttp->inlist->count)!=0) - sumcount += count +1; /* count the non-nullist */ - if ((count = ttp->outlist->count)!=0) /* slots in all arglists */ - sumcount += (count + 1); - } - ip->optxtcount = optxtcount; /* optxts in this instxt */ - } - ST(argoffsize) = (sumcount + 1) * sizeof(int); /* alloc all plus 1 null */ - /* as argoff ints */ - csound->argoffspace = (int*) mmalloc(csound, ST(argoffsize)); - ST(nxtargoffp) = csound->argoffspace; - ST(nulloffs) = (ARGOFFS *) csound->argoffspace; /* setup the null argoff */ - *ST(nxtargoffp)++ = 0; - ST(argofflim) = ST(nxtargoffp) + sumcount; - ip = &(csound->instxtanchor); - while ((ip = ip->nxtinstxt) != NULL) /* add all other entries */ - insprep(csound, ip); /* as combined offsets */ - if (UNLIKELY(O->odebug)) { - int *p = csound->argoffspace; - csound->Message(csound, "argoff array:\n"); - do { - csound->Message(csound, "\t%d", *p++); - } while (p < ST(argofflim)); - csound->Message(csound, "\n"); - } - if (UNLIKELY(ST(nxtargoffp) != ST(argofflim))) - csoundDie(csound, Str("inconsistent argoff sumcount")); - - ip = &(csound->instxtanchor); /* set the OPARMS values */ - instxtcount = optxtcount = 0; - while ((ip = ip->nxtinstxt) != NULL) { - instxtcount += 1; - optxtcount += ip->optxtcount; - } - csound->instxtcount = instxtcount; - csound->optxtsize = instxtcount * sizeof(INSTRTXT) - + optxtcount * sizeof(OPTXT); - csound->poolcount = ST(poolcount); - csound->gblfixed = ST(gblnxtkcnt) + ST(gblnxtpcnt) * (int) Pfloats; - csound->gblacount = ST(gblnxtacnt); - csound->gblscount = ST(gblnxtscnt); - /* clean up */ - delete_local_namepool(csound); - delete_global_namepool(csound); - mfree(csound, ST(constTbl)); - ST(constTbl) = NULL; - return; -} - -/* prep an instr template for efficient allocs */ -/* repl arg refs by offset ndx to lcl/gbl space */ - -static void insprep(CSOUND *csound, INSTRTXT *tp) -{ - OPARMS *O = csound->oparms; - OPTXT *optxt; - OENTRY *ep; - int n, opnum, inreqd; - char **argp; - char **labels, **lblsp; - LBLARG *larg, *largp; - ARGLST *outlist, *inlist; - ARGOFFS *outoffs, *inoffs; - int indx, *ndxp; - - labels = (char **)mmalloc(csound, (csound->nlabels) * sizeof(char *)); - lblsp = labels; - larg = (LBLARG *)mmalloc(csound, (csound->ngotos) * sizeof(LBLARG)); - largp = larg; - ST(lclkcnt) = tp->lclkcnt; - ST(lclwcnt) = tp->lclwcnt; - ST(lclfixed) = tp->lclfixed; - ST(lclpcnt) = tp->lclpcnt; - ST(lclscnt) = tp->lclscnt; - ST(lclacnt) = tp->lclacnt; - delete_local_namepool(csound); /* clear lcl namlist */ - ST(lclnxtkcnt) = 0; /* for rebuilding */ - ST(lclnxtwcnt) = ST(lclnxtacnt) = 0; - ST(lclnxtpcnt) = ST(lclnxtscnt) = 0; - ST(lclpmax) = tp->pmax; /* set pmax for plgndx */ - ndxp = ST(nxtargoffp); - optxt = (OPTXT *)tp; - while ((optxt = optxt->nxtop) != NULL) { /* for each op in instr */ - TEXT *ttp = &optxt->t; - if ((opnum = ttp->opnum) == ENDIN /* (until ENDIN) */ - || opnum == ENDOP) /* (IV - Oct 31 2002: or ENDOP) */ - break; - if (opnum == LABEL) { - if (lblsp - labels >= csound->nlabels) { - int oldn = lblsp - labels; - csound->nlabels += NLABELS; - if (lblsp - labels >= csound->nlabels) - csound->nlabels = lblsp - labels + 2; - if (csound->oparms->msglevel) - csound->Message(csound, - Str("LABELS list is full...extending to %d\n"), - csound->nlabels); - labels = - (char**)mrealloc(csound, labels, csound->nlabels*sizeof(char*)); - lblsp = &labels[oldn]; - } - *lblsp++ = ttp->opcod; - continue; - } - ep = &(csound->opcodlst[opnum]); - if (UNLIKELY(O->odebug)) csound->Message(csound, "%s argndxs:", ep->opname); - if ((outlist = ttp->outlist) == ST(nullist) || !outlist->count) - ttp->outoffs = ST(nulloffs); - else { - ttp->outoffs = outoffs = (ARGOFFS *) ndxp; - outoffs->count = n = outlist->count; - argp = outlist->arg; /* get outarg indices */ - ndxp = outoffs->indx; - while (n--) { - *ndxp++ = indx = plgndx(csound, *argp++); - if (UNLIKELY(O->odebug)) csound->Message(csound, "\t%d", indx); - } - } - if ((inlist = ttp->inlist) == ST(nullist) || !inlist->count) - ttp->inoffs = ST(nulloffs); - else { - ttp->inoffs = inoffs = (ARGOFFS *) ndxp; - inoffs->count = inlist->count; - inreqd = strlen(ep->intypes); - argp = inlist->arg; /* get inarg indices */ - ndxp = inoffs->indx; - for (n=0; n < inlist->count; n++, argp++, ndxp++) { - if (n < inreqd && ep->intypes[n] == 'l') { - if (UNLIKELY(largp - larg >= csound->ngotos)) { - int oldn = csound->ngotos; - csound->ngotos += NGOTOS; - if (csound->oparms->msglevel) - csound->Message(csound, - Str("GOTOS list is full..extending to %d\n"), - csound->ngotos); - if (largp - larg >= csound->ngotos) - csound->ngotos = largp - larg + 1; - larg = (LBLARG *) - mrealloc(csound, larg, csound->ngotos * sizeof(LBLARG)); - largp = &larg[oldn]; - } - if (UNLIKELY(O->odebug)) - csound->Message(csound, "\t***lbl"); /* if arg is label, */ - largp->lbltxt = *argp; - largp->ndxp = ndxp; /* defer till later */ - largp++; - } - else { - char *s = *argp; - indx = plgndx(csound, s); - if (UNLIKELY(O->odebug)) csound->Message(csound, "\t%d", indx); - *ndxp = indx; - } - } - } - if (UNLIKELY(O->odebug)) csound->Message(csound, "\n"); - } - nxt: - while (--largp >= larg) { /* resolve the lbl refs */ - char *s = largp->lbltxt; - char **lp; - for (lp = labels; lp < lblsp; lp++) - if (strcmp(s, *lp) == 0) { - *largp->ndxp = lp - labels + LABELOFS; - goto nxt; - } - csoundDie(csound, Str("target label '%s' not found"), s); - } - ST(nxtargoffp) = ndxp; - mfree(csound, labels); - mfree(csound, larg); -} - -static void lgbuild(CSOUND *csound, char *s) -{ /* build pool of floating const values */ - char c; /* build lcl/gbl list of ds names, offsets */ - /* (no need to save the returned values) */ - c = *s; - /* must trap 0dbfs as name starts with a digit! */ - if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || - (c == '0' && strcmp(s, "0dbfs") != 0)) - constndx(csound, s); - else if (c == '"') - strconstndx(csound, s); - else if (!(lgexist(csound, s))) { - if (c == 'g' || (c == '#' && s[1] == 'g')) - gblnamset(csound, s); - else - lclnamset(csound, s); - } -} - -static int plgndx(CSOUND *csound, char *s) -{ /* get storage ndx of const, pnum, lcl or gbl */ - char c; /* argument const/gbl indexes are positiv+1, */ - int n, indx; /* pnum/lcl negativ-1 called only after */ - /* poolcount & lclpmax are finalised */ - c = *s; - /* must trap 0dbfs as name starts with a digit! */ - if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || - (c == '0' && strcmp(s, "0dbfs") != 0)) - indx = constndx(csound, s) + 1; - else if (c == '"') - indx = strconstndx(csound, s) + STR_OFS + 1; - else if ((n = pnum(s)) >= 0) - indx = -n; - else if (c == 'g' || (c == '#' && *(s+1) == 'g') || gexist(csound, s)) - indx = (int) (ST(poolcount) + 1 + gbloffndx(csound, s)); - else - indx = -(ST(lclpmax) + 1 + lcloffndx(csound, s)); -/* csound->Message(csound, " [%s -> %d (%x)]\n", s, indx, indx); */ - return(indx); -} - -static int strconstndx(CSOUND *csound, const char *s) -{ /* get storage ndx of string const value */ - int i, cnt; /* builds value pool on 1st occurrence */ - - /* check syntax */ - cnt = (int) strlen(s); - if (UNLIKELY(cnt < 2 || *s != '"' || s[cnt - 1] != '"')) { - synterr(csound, Str("string syntax '%s'"), s); - return 0; - } - /* check if a copy of the string is already stored */ - for (i = 0; i < ST(strpool_cnt); i++) { - if (strcmp(s, ST(strpool)[i]) == 0) - return i; - } - /* not found, store new string */ - cnt = ST(strpool_cnt)++; - if (!(cnt & 0x7F)) { - /* extend list */ - if (!cnt) ST(strpool) = csound->Malloc(csound, 0x80 * sizeof(MYFLT*)); - else ST(strpool) = csound->ReAlloc(csound, ST(strpool), - (cnt + 0x80) * sizeof(MYFLT*)); - } - ST(strpool)[cnt] = (char*) csound->Malloc(csound, strlen(s) + 1); - strcpy(ST(strpool)[cnt], s); - /* and return index */ - return cnt; -} - -static inline unsigned int MYFLT_hash(const MYFLT *x) -{ - const unsigned char *c = (const unsigned char*) x; - size_t i; - unsigned int h = 0U; - - for (i = (size_t) 0; i < sizeof(MYFLT); i++) - h = (unsigned int) strhash_tabl_8[(unsigned int) c[i] ^ h]; - - return h; -} - -/* get storage ndx of float const value */ -/* builds value pool on 1st occurrence */ -/* final poolcount used in plgndx above */ -/* pool may be moved w. ndx still valid */ - -static int constndx(CSOUND *csound, const char *s) -{ - MYFLT newval; - int h, n, prv; - - { - volatile MYFLT tmpVal; /* make sure it really gets rounded to MYFLT */ - char *tmp = (char*) s; - tmpVal = (MYFLT) strtod(s, &tmp); - newval = tmpVal; - if (UNLIKELY(tmp == s || *tmp != '\0')) { - synterr(csound, Str("numeric syntax '%s'"), s); - return 0; - } - } - /* calculate hash value (0 to 255) */ - h = (int) MYFLT_hash(&newval); - n = ST(constTbl)[h]; /* now search constpool */ - prv = 0; - while (n) { - if (csound->pool[n - 256] == newval) { /* if val is there */ - if (prv) { - /* move to the beginning of the chain, so that */ - /* frequently searched values are found faster */ - ST(constTbl)[prv] = ST(constTbl)[n]; - ST(constTbl)[n] = ST(constTbl)[h]; - ST(constTbl)[h] = n; - } - return (n - 256); /* return w. index */ - } - prv = n; - n = ST(constTbl)[prv]; - } - n = ST(poolcount)++; - if (UNLIKELY(n >= ST(nconsts))) { - ST(nconsts) = ((ST(nconsts) + (ST(nconsts) >> 3)) | (NCONSTS - 1)) + 1; - if (csound->oparms->msglevel) - csound->Message(csound, Str("extending Floating pool to %d\n"), - ST(nconsts)); - csound->pool = (MYFLT*) mrealloc(csound, csound->pool, ST(nconsts) - * sizeof(MYFLT)); - ST(constTbl) = (int*) mrealloc(csound, ST(constTbl), (256 + ST(nconsts)) - * sizeof(int)); - } - csound->pool[n] = newval; /* else enter newval */ - ST(constTbl)[n + 256] = ST(constTbl)[h]; /* link into chain */ - ST(constTbl)[h] = n + 256; - - return n; /* and return new ndx */ -} - -void putop(CSOUND *csound, TEXT *tp) -{ - int n, nn; - - if ((n = tp->outlist->count) != 0) { - nn = 0; - while (n--) - csound->Message(csound, "%s\t", tp->outlist->arg[nn++]); - } - else - csound->Message(csound, "\t"); - csound->Message(csound, "%s\t", tp->opcod); - if ((n = tp->inlist->count) != 0) { - nn = 0; - while (n--) - csound->Message(csound, "%s\t", tp->inlist->arg[nn++]); - } - csound->Message(csound, "\n"); -} - -/* tests whether variable name exists */ -/* in gbl namelist */ - -static int gexist(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p; - - for (p = ST(gblNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - return (p == NULL ? 0 : 1); -} - -/* returns non-zero if 's' is defined in the global or local pool of names */ - -int lgexist(CSOUND *csound, const char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p; - - - - for (p = ST(gblNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) - return 1; - for (p = ST(lclNames)[h]; p != NULL && sCmp(p->namep, s); p = p->nxt); - - return (p == NULL ? 0 : 1); - -} - -/* builds namelist & type counts for gbl names */ - -static void gblnamset(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(gblNames)[h]; - /* search gbl namelist: */ - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) /* if name is there */ - return; /* return */ - p = (NAME*) malloc(sizeof(NAME)); - if (UNLIKELY(p == NULL)) - csound->Die(csound, Str("gblnamset(): memory allocation failure")); - p->namep = s; /* else record newname */ - p->nxt = ST(gblNames)[h]; - ST(gblNames)[h] = p; - if (*s == '#') s++; - if (*s == 'g') s++; - switch ((int) *s) { /* and its type-count */ - case 'a': p->type = ATYPE; p->count = ST(gblnxtacnt)++; break; - case 'S': p->type = STYPE; p->count = ST(gblnxtscnt)++; break; - case 'f': p->type = PTYPE; p->count = ST(gblnxtpcnt)++; break; - default: p->type = KTYPE; p->count = ST(gblnxtkcnt)++; - } -} - -/* builds namelist & type counts for lcl names */ -/* called by otran for each instr for lcl cnts */ -/* lists then redone by insprep via lcloffndx */ - -static NAME *lclnamset(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(lclNames)[h]; - /* search lcl namelist: */ - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (p != NULL) /* if name is there */ - return p; /* return ptr */ - p = (NAME*) malloc(sizeof(NAME)); - if (UNLIKELY(p == NULL)) - csound->Die(csound, Str("lclnamset(): memory allocation failure")); - p->namep = s; /* else record newname */ - p->nxt = ST(lclNames)[h]; - ST(lclNames)[h] = p; - if (*s == '#') s++; - switch (*s) { /* and its type-count */ - case 'w': p->type = WTYPE; p->count = ST(lclnxtwcnt)++; break; - case 'a': p->type = ATYPE; p->count = ST(lclnxtacnt)++; break; - case 'f': p->type = PTYPE; p->count = ST(lclnxtpcnt)++; break; - case 'S': p->type = STYPE; p->count = ST(lclnxtscnt)++; break; - default: p->type = KTYPE; p->count = ST(lclnxtkcnt)++; break; - } - return p; -} - -/* get named offset index into gbl dspace */ -/* called only after otran and gblfixed valid */ - -static int gbloffndx(CSOUND *csound, char *s) -{ - unsigned char h = name_hash(csound, s); - NAME *p = ST(gblNames)[h]; - - for ( ; p != NULL && sCmp(p->namep, s); p = p->nxt); - if (UNLIKELY(p == NULL)) - csoundDie(csound, Str("unexpected global name")); - switch (p->type) { - case ATYPE: return (ST(gblfixed) + p->count); - case STYPE: return (ST(gblfixed) + ST(gblacount) + p->count); - case PTYPE: return (ST(gblkcount) + p->count * (int) Pfloats); - } - return p->count; -} - -/* get named offset index into instr lcl dspace */ -/* called by insprep aftr lclcnts, lclfixed valid */ - -static int lcloffndx(CSOUND *csound, char *s) -{ - NAME *np = lclnamset(csound, s); /* rebuild the table */ - switch (np->type) { /* use cnts to calc ndx */ - case KTYPE: return np->count; - case WTYPE: return (ST(lclkcnt) + np->count * Wfloats); - case ATYPE: return (ST(lclfixed) + np->count); - case PTYPE: return (ST(lclkcnt) + ST(lclwcnt) * Wfloats - + np->count * (int) Pfloats); - case STYPE: return (ST(lclfixed) + ST(lclacnt) + np->count); - default: csoundDie(csound, Str("unknown nametype")); - } - return 0; -} - -static void delete_global_namepool(CSOUND *csound) -{ - int i; - - if (csound->otranGlobals == NULL) - return; - for (i = 0; i < 256; i++) { - while (ST(gblNames)[i] != NULL) { - NAME *nxt = ST(gblNames)[i]->nxt; - free(ST(gblNames)[i]); - ST(gblNames)[i] = nxt; - } - } -} - -static void delete_local_namepool(CSOUND *csound) -{ - int i; - - if (csound->otranGlobals == NULL) - return; - for (i = 0; i < 256; i++) { - while (ST(lclNames)[i] != NULL) { - NAME *nxt = ST(lclNames)[i]->nxt; - free(ST(lclNames)[i]); - ST(lclNames)[i] = nxt; - } - } -} - - /* ------------------------------------------------------------------------ */ - -/* get size of string in MYFLT units */ - -static int strlen_to_samples(const char *s) -{ - int n = (int) strlen(s); - n = (n + (int) sizeof(MYFLT)) / (int) sizeof(MYFLT); - return n; -} - -/* convert string constant */ - -static void unquote_string(char *dst, const char *src) -{ - int i, j, n = (int) strlen(src) - 1; - for (i = 1, j = 0; i < n; i++) { - if (src[i] != '\\') - dst[j++] = src[i]; - else { - switch (src[++i]) { - case 'a': dst[j++] = '\a'; break; - case 'b': dst[j++] = '\b'; break; - case 'f': dst[j++] = '\f'; break; - case 'n': dst[j++] = '\n'; break; - case 'r': dst[j++] = '\r'; break; - case 't': dst[j++] = '\t'; break; - case 'v': dst[j++] = '\v'; break; - case '"': dst[j++] = '"'; break; - case '\\': dst[j++] = '\\'; break; - default: - if (src[i] >= '0' && src[i] <= '7') { - int k = 0, l = (int) src[i] - '0'; - while (++k < 3 && src[i + 1] >= '0' && src[i + 1] <= '7') - l = (l << 3) | ((int) src[++i] - '0'); - dst[j++] = (char) l; - } - else { - dst[j++] = '\\'; i--; - } - } - } - } - dst[j] = '\0'; -} - -static int create_strconst_ndx_list(CSOUND *csound, int **lst, int offs) -{ - int *ndx_lst; - char **strpool; - int strpool_cnt, ndx, i; - - strpool_cnt = ST(strpool_cnt); - strpool = ST(strpool); - /* strpool_cnt always >= 1 because of empty string at index 0 */ - ndx_lst = (int*) csound->Malloc(csound, strpool_cnt * sizeof(int)); - for (i = 0, ndx = offs; i < strpool_cnt; i++) { - ndx_lst[i] = ndx; - ndx += strlen_to_samples(strpool[i]); - } - *lst = ndx_lst; - /* return with total size in MYFLT units */ - return (ndx - offs); -} - -static void convert_strconst_pool(CSOUND *csound, MYFLT *dst) -{ - char **strpool, *s; - int strpool_cnt, ndx, i; - - strpool_cnt = ST(strpool_cnt); - strpool = ST(strpool); - if (strpool == NULL) - return; - for (ndx = i = 0; i < strpool_cnt; i++) { - s = (char*) ((MYFLT*) dst + (int) ndx); - unquote_string(s, strpool[i]); - ndx += strlen_to_samples(strpool[i]); - } - /* original pool is no longer needed */ - ST(strpool) = NULL; - ST(strpool_cnt) = 0; - for (i = 0; i < strpool_cnt; i++) - csound->Free(csound, strpool[i]); - csound->Free(csound, strpool); -} - -void oload(CSOUND *p) -{ - int32 n, combinedsize, insno, *lp; - int32 gblabeg, gblsbeg, gblsbas, gblscbeg, lclabeg, lclsbeg, lclsbas; - MYFLT *combinedspc, *gblspace, *fp1; - INSTRTXT *ip; - OPTXT *optxt; - OPARMS *O = p->oparms; - int *strConstIndexList; - MYFLT ensmps; - - if (O->newParser) { - p->esr = p->tran_sr; p->ekr = p->tran_kr; p->ksmps = ensmps = p->tran_ksmps; - p->nchnls = p->tran_nchnls; - p->e0dbfs = p->tran_0dbfs; - } - else { - p->esr = p->tran_sr; p->ekr = p->tran_kr; p->ksmps = ensmps = p->tran_ksmps; - p->e0dbfs = p->tran_0dbfs; - ip = p->instxtanchor.nxtinstxt; /* for instr 0 optxts: */ - optxt = (OPTXT *) ip; - while ((optxt = optxt->nxtop) != NULL) { - TEXT *ttp = &optxt->t; - ARGOFFS *inoffp, *outoffp; - int opnum = ttp->opnum; - if (opnum == ENDIN) break; - if (opnum == LABEL) continue; - outoffp = ttp->outoffs; /* use unexpanded ndxes */ - inoffp = ttp->inoffs; /* to find sr.. assigns */ - if (outoffp->count == 1 && inoffp->count == 1) { - int rindex = (int) outoffp->indx[0] - (int) p->poolcount; - if (rindex > 0 && rindex <= 6) { - MYFLT conval = p->pool[inoffp->indx[0] - 1]; - switch (rindex) { - case 1: p->esr = conval; break; /* & use those values */ - case 2: p->ekr = conval; break; /* to set params now */ - case 3: p->ksmps = (int) ((ensmps = conval) + FL(0.5)); break; - case 4: p->nchnls = (int) (conval + FL(0.5)); break; - case 5: p->inchnls = (int) (conval + FL(0.5)); break; - case 6: - default: p->e0dbfs = conval; break; - } - } - } - } - /* why I want oload() to return an error value.... */ - if (UNLIKELY(p->e0dbfs <= FL(0.0))) - p->Die(p, Str("bad value for 0dbfs: must be positive.")); - if (UNLIKELY(O->odebug)) - p->Message(p, "esr = %7.1f, ekr = %7.1f, ksmps = %d, nchnls = %d " - "0dbfs = %.1f\n", - p->esr, p->ekr, p->ksmps, p->nchnls, p->e0dbfs); - } - if (O->sr_override) { /* if command-line overrides, apply now */ - p->esr = (MYFLT) O->sr_override; - p->ekr = (MYFLT) O->kr_override; - p->ksmps = (int) ((ensmps = ((MYFLT) O->sr_override - / (MYFLT) O->kr_override)) + FL(0.5)); - p->Message(p, Str("sample rate overrides: " - "esr = %7.4f, ekr = %7.4f, ksmps = %d\n"), - p->esr, p->ekr, p->ksmps); - } - /* number of MYFLT locations to allocate for a string variable */ - p->strVarSamples = (p->strVarMaxLen + (int) sizeof(MYFLT) - 1) - / (int) sizeof(MYFLT); - p->strVarMaxLen = p->strVarSamples * (int) sizeof(MYFLT); - /* calculate total size of global pool */ - combinedsize = p->poolcount /* floating point constants */ - + p->gblfixed /* k-rate / spectral */ - + p->gblacount * p->ksmps /* a-rate variables */ - + p->gblscount * p->strVarSamples; /* string variables */ - gblscbeg = combinedsize + 1; /* string constants */ - combinedsize += create_strconst_ndx_list(p, &strConstIndexList, gblscbeg); - - combinedspc = (MYFLT*) mcalloc(p, combinedsize * sizeof(MYFLT)); - /* copy pool into combined space */ - memcpy(combinedspc, p->pool, p->poolcount * sizeof(MYFLT)); - mfree(p, (void*) p->pool); - p->pool = combinedspc; - gblspace = p->pool + p->poolcount; - gblspace[0] = p->esr; /* & enter */ - gblspace[1] = p->ekr; /* rsvd word */ - gblspace[2] = (MYFLT) p->ksmps; /* curr vals */ - gblspace[3] = (MYFLT) p->nchnls; - if (p->inchnls<0) p->inchnls = p->nchnls; - gblspace[4] = (MYFLT) p->inchnls; - gblspace[5] = p->e0dbfs; - p->gbloffbas = p->pool - 1; - /* string constants: unquote, convert escape sequences, and copy to pool */ - convert_strconst_pool(p, (MYFLT*) p->gbloffbas + (int32) gblscbeg); - - gblabeg = p->poolcount + p->gblfixed + 1; - gblsbeg = gblabeg + p->gblacount; - gblsbas = gblabeg + (p->gblacount * p->ksmps); - ip = &(p->instxtanchor); - while ((ip = ip->nxtinstxt) != NULL) { /* EXPAND NDX for A & S Cells */ - optxt = (OPTXT *) ip; /* (and set localen) */ - lclabeg = (int32) (ip->pmax + ip->lclfixed + 1); - lclsbeg = (int32) (lclabeg + ip->lclacnt); - lclsbas = (int32) (lclabeg + (ip->lclacnt * (int32) p->ksmps)); - if (UNLIKELY(O->odebug)) p->Message(p, "lclabeg %d, lclsbeg %d\n", - lclabeg, lclsbeg); - ip->localen = ((int32) ip->lclfixed - + (int32) ip->lclacnt * (int32) p->ksmps - + (int32) ip->lclscnt * (int32) p->strVarSamples) - * (int32) sizeof(MYFLT); - /* align to 64 bits */ - ip->localen = (ip->localen + 7L) & (~7L); - for (insno = 0, n = 0; insno <= p->maxinsno; insno++) - if (p->instrtxtp[insno] == ip) n++; /* count insnos */ - lp = ip->inslist = (int32 *) mmalloc(p, (int32)(n+1) * sizeof(int32)); - for (insno=0; insno <= p->maxinsno; insno++) - if (p->instrtxtp[insno] == ip) *lp++ = insno; /* creat inslist */ - *lp = -1; /* & terminate */ - insno = *ip->inslist; /* get the first */ - while ((optxt = optxt->nxtop) != NULL) { - TEXT *ttp = &optxt->t; - ARGOFFS *aoffp; - int32 indx; - int32 posndx; - int *ndxp; - int opnum = ttp->opnum; - if (opnum == ENDIN || opnum == ENDOP) break; /* IV - Sep 8 2002 */ - if (opnum == LABEL) continue; - aoffp = ttp->outoffs; /* ------- OUTARGS -------- */ - n = aoffp->count; - for (ndxp = aoffp->indx; n--; ndxp++) { - indx = *ndxp; - if (indx > 0) { /* positive index: global */ - if (UNLIKELY(indx >= STR_OFS)) /* string constant */ - p->Die(p, Str("internal error: string constant outarg")); - if (indx > gblsbeg) /* global string variable */ - indx = gblsbas + (indx - gblsbeg) * p->strVarSamples; - else if (indx > gblabeg) /* global a-rate variable */ - indx = gblabeg + (indx - gblabeg) * p->ksmps; - else if (indx <= 3 && O->sr_override && - ip == p->instxtanchor.nxtinstxt) /* for instr 0 */ - indx += 3; /* deflect any old sr,kr,ksmps targets */ - } - else { /* negative index: local */ - posndx = -indx; - if (indx < LABELIM) /* label */ - continue; - if (posndx > lclsbeg) /* local string variable */ - indx = -(lclsbas + (posndx - lclsbeg) * p->strVarSamples); - else if (posndx > lclabeg) /* local a-rate variable */ - indx = -(lclabeg + (posndx - lclabeg) * p->ksmps); - } - *ndxp = (int) indx; - } - aoffp = ttp->inoffs; /* inargs: */ - if (opnum >= SETEND) goto realops; - switch (opnum) { /* do oload SETs NOW */ - case PSET: - p->Message(p, "PSET: isno=%d, pmax=%d\n", insno, ip->pmax); - if ((n = aoffp->count) != ip->pmax) { - p->Warning(p, Str("i%d pset args != pmax"), (int) insno); - if (n < ip->pmax) n = ip->pmax; /* cf pset, pmax */ - } /* alloc the larger */ - ip->psetdata = (MYFLT *) mcalloc(p, n * sizeof(MYFLT)); - for (n = aoffp->count, fp1 = ip->psetdata, ndxp = aoffp->indx; - n--; ) { - *fp1++ = p->gbloffbas[*ndxp++]; - p->Message(p, "..%f..", *(fp1-1)); - } - p->Message(p, "\n"); - break; - } - continue; /* no runtime role for the above SET types */ - - realops: - n = aoffp->count; /* -------- INARGS -------- */ - for (ndxp = aoffp->indx; n--; ndxp++) { - indx = *ndxp; - if (indx > 0) { /* positive index: global */ - if (indx >= STR_OFS) /* string constant */ - indx = (int32) strConstIndexList[indx - (int32) (STR_OFS + 1)]; - else if (indx > gblsbeg) /* global string variable */ - indx = gblsbas + (indx - gblsbeg) * p->strVarSamples; - else if (indx > gblabeg) /* global a-rate variable */ - indx = gblabeg + (indx - gblabeg) * p->ksmps; - } - else { /* negative index: local */ - posndx = -indx; - if (indx < LABELIM) /* label */ - continue; - if (posndx > lclsbeg) /* local string variable */ - indx = -(lclsbas + (posndx - lclsbeg) * p->strVarSamples); - else if (posndx > lclabeg) /* local a-rate variable */ - indx = -(lclabeg + (posndx - lclabeg) * p->ksmps); - } - *ndxp = (int) indx; - } - } - } - p->Free(p, strConstIndexList); - - p->tpidsr = TWOPI_F / p->esr; /* now set internal */ - p->mtpdsr = -(p->tpidsr); /* consts */ - p->pidsr = PI_F / p->esr; - p->mpidsr = -(p->pidsr); - p->onedksmps = FL(1.0) / (MYFLT) p->ksmps; - p->sicvt = FMAXLEN / p->esr; - p->kicvt = FMAXLEN / p->ekr; - p->onedsr = FL(1.0) / p->esr; - p->onedkr = FL(1.0) / p->ekr; - /* IV - Sep 8 2002: save global variables that depend on ksmps */ - p->global_ksmps = p->ksmps; - p->global_ekr = p->ekr; - p->global_kcounter = p->kcounter; - reverbinit(p); - dbfs_init(p, p->e0dbfs); - p->nspout = p->ksmps * p->nchnls; /* alloc spin & spout */ - p->nspin = p->ksmps * p->inchnls; /* JPff: in preparation */ - p->spin = (MYFLT *) mcalloc(p, p->nspin * sizeof(MYFLT)); - p->spout = (MYFLT *) mcalloc(p, p->nspout * sizeof(MYFLT)); - /* chk consistency one more time (FIXME: needed ?) */ - { - char s[256]; - sprintf(s, Str("sr = %.7g, kr = %.7g, ksmps = %.7g\nerror:"), - p->esr, p->ekr, ensmps); - if (UNLIKELY(p->ksmps < 1 || FLOAT_COMPARE(ensmps, p->ksmps))) - csoundDie(p, Str("%s invalid ksmps value"), s); - if (UNLIKELY(p->esr <= FL(0.0))) - csoundDie(p, Str("%s invalid sample rate"), s); - if (UNLIKELY(p->ekr <= FL(0.0))) - csoundDie(p, Str("%s invalid control rate"), s); - if (UNLIKELY(FLOAT_COMPARE(p->esr, (double) p->ekr * ensmps))) - csoundDie(p, Str("%s inconsistent sr, kr, ksmps"), s); - } - /* initialise sensevents state */ - p->prvbt = p->curbt = p->nxtbt = 0.0; - p->curp2 = p->nxtim = p->timeOffs = p->beatOffs = 0.0; - p->icurTime = 0L; - if (O->Beatmode && O->cmdTempo > 0) { - /* if performing from beats, set the initial tempo */ - p->curBeat_inc = (double) O->cmdTempo / (60.0 * (double) p->ekr); - p->ibeatTime = (int64_t)(p->esr*60.0 / (double) O->cmdTempo); - } - else { - p->curBeat_inc = 1.0 / (double) p->ekr; - p->ibeatTime = 1; - } - p->cyclesRemaining = 0; - memset(&(p->evt), 0, sizeof(EVTBLK)); - - /* pre-allocate temporary label space for instance() */ - p->lopds = (LBLBLK**) mmalloc(p, sizeof(LBLBLK*) * p->nlabels); - p->larg = (LARGNO*) mmalloc(p, sizeof(LARGNO) * p->ngotos); - - /* run instr 0 inits */ - if (UNLIKELY(init0(p) != 0)) - csoundDie(p, Str("header init errors")); -} diff -Nru csound-5.17.11~dfsg/Engine/parse_param.h csound-6.02~dfsg/Engine/parse_param.h --- csound-5.17.11~dfsg/Engine/parse_param.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/parse_param.h 2014-01-07 16:53:47.000000000 +0000 @@ -1,3 +1,6 @@ +#ifndef __PARSE_PARAM_H +#define __PARSE_PARAM_H + #define MARGS (3) #define MAX_INCLUDE_DEPTH 100 struct MACRO; @@ -54,4 +57,6 @@ void cs_init_omacros(CSOUND*, PRE_PARM*, NAMES*); uint32_t make_location(PRE_PARM *); -extern uint8_t file_to_int(CSOUND*, char*); +extern uint8_t file_to_int(CSOUND*, const char*); + +#endif diff -Nru csound-5.17.11~dfsg/Engine/pools.c csound-6.02~dfsg/Engine/pools.c --- csound-5.17.11~dfsg/Engine/pools.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/pools.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,60 @@ + +#include "csoundCore.h" +#include "pools.h" + +/* MYFLT POOL */ + +MYFLT_POOL* myflt_pool_create(CSOUND* csound) { + MYFLT_POOL* pool = csound->Malloc(csound, sizeof(MYFLT_POOL)); + pool->count = 0; + pool->max = POOL_SIZE; + pool->values = csound->Calloc(csound, sizeof(MYFLT) * POOL_SIZE); + + return pool; +} + +void myflt_pool_free(CSOUND *csound, MYFLT_POOL *pool){ + if(pool != NULL) { + csound->Free(csound, pool->values); + csound->Free(csound, pool); + } +} + +int myflt_pool_indexof(MYFLT_POOL* pool, MYFLT value) { + int retVal = -1; + int i; + + for (i = 0; i < pool->count; i++) { + if(pool->values[i] == value) { + retVal = i; + break; + } + } + + return retVal; +} + +int myflt_pool_find_or_add(CSOUND* csound, MYFLT_POOL* pool, MYFLT value) { + int index = myflt_pool_indexof(pool, value); + + if(index == -1) { + if (pool->count > 0 && pool->count % POOL_SIZE == 0) { + pool->max += POOL_SIZE; + pool->values = csound->ReAlloc(csound, pool->values, + pool->max * sizeof + (MYFLT)); + } + index = pool->count; + pool->values[index] = value; + + pool->count++; + } + + return index; +} + +int myflt_pool_find_or_addc(CSOUND* csound, MYFLT_POOL* pool, char* s) { + + MYFLT val = (MYFLT) cs_strtod(s, NULL); + return myflt_pool_find_or_add(csound, pool, val); +} diff -Nru csound-5.17.11~dfsg/Engine/rdorch.c csound-6.02~dfsg/Engine/rdorch.c --- csound-5.17.11~dfsg/Engine/rdorch.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/rdorch.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,2300 +0,0 @@ -/* - rdorch.c: - - Copyright (C) 1991-2002 Barry Vercoe, John ffitch, Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#include "csoundCore.h" /* RDORCH.C */ -#include -#include "namedins.h" /* IV - Oct 31 2002 */ -#include "typetabl.h" /* IV - Oct 31 2002 */ -#include "envvar.h" -#include -#include "corfile.h" - -#ifdef sun -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#endif - -#define LINMAX 1000 -#define LENMAX 4096L -#define GRPMAX VARGMAX -#define LBLMAX 100 - -//#define MACDEBUG (1) - -typedef struct { - int reqline; - char *label; -} LBLREQ; - -#define MARGS (3) - -typedef struct MACRO { /* To store active macros */ - char *name; /* Use is by name */ - int acnt; /* Count of arguments */ - char *body; /* The text of the macro */ - struct MACRO *next; /* Chain of active macros */ - int margs; /* amount of space for args */ - char *arg[MARGS]; /* With these arguments */ -} MACRO; - -typedef struct in_stack { - int16 string; - int16 args; - char *body; - FILE *file; - void *fd; - MACRO *mac; - int line; - int unget_cnt; - char unget_buf[128]; -} IN_STACK; - -typedef struct iflabel { /* for if/else/endif */ - char els[256]; - char end[256]; - /* is the conditional valid at i-time ? 0: no, 1: yes, -1: unknown */ - int ithen; - struct iflabel *prv; -} IFLABEL; - -typedef struct IFDEFSTACK_ { - struct IFDEFSTACK_ *prv; - unsigned char isDef; /* non-zero if #ifdef is true, or #ifndef */ - /* is false */ - unsigned char isElse; /* non-zero between #else and #endif */ - unsigned char isSkip; /* sum of: 1: skipping code due to this */ - /* #ifdef, 2: skipping due to parent */ -} IFDEFSTACK; - -typedef struct { - MACRO *macros; - int32 lenmax /* = LENMAX */; /* Length of input line buffer */ - char *ortext; - char **linadr; /* adr of each line in text */ - int curline; /* current line being examined */ - char *collectbuf; /* splitline collect buffer */ - char **group; /* splitline local storage */ - char **grpsav; /* copy of above */ - int32 grpmax /* = GRPMAX */; /* Size of group structure */ - int opgrpno; /* grpno identified as opcode */ - int linopnum; /* data for opcode in this line */ - char *linopcod; - int linlabels; /* count of labels this line */ - LBLREQ *lblreq; - int lblmax; - int lblcnt; - int lgprevdef; - int opnum; /* opcod data carriers */ - char *opcod; /* (line or subline) */ - ARGLST *nxtarglist, *nullist; - IN_STACK *inputs, *str; - FILE *fp; - void *fd; - int input_size, input_cnt; - int pop; /* Number of macros to pop */ - int ingappop /* = 1 */; - int linepos /* = -1 */; - int32 *typemask_tabl; - int32 *typemask_tabl_in, *typemask_tabl_out; - int32 orchsiz; - IFLABEL *iflabels; - int repeatingElseifLine; - int32 tempNum /* = 300L */; - int repeatingElseLine; - int16 grpcnt, nxtest /* = 1 */; - int16 xprtstno, polcnt; - int16 instrblk, instrcnt; - int16 opcodblk; /* IV - Sep 8 2002 */ - int16 opcodflg; /* 1: xin, 2: xout, 4: setksmps */ - IFDEFSTACK *ifdefStack; - TEXT optext; /* struct to be passed back to caller */ -} RDORCH_GLOBALS; - -#define ST(x) (((RDORCH_GLOBALS*) csound->rdorchGlobals)->x) -#define CURLINE (csound->oparms->useCsdLineCounts ? \ - csound->orcLineOffset + ST(curline) : ST(curline)) - -static void intyperr(CSOUND *, int, char, char); -static void printgroups(CSOUND *, int); -static int isopcod(CSOUND *, char *); -static void lblrequest(CSOUND *, char *), lblfound(CSOUND *, char *); -static void lblclear(CSOUND *), lblchk(CSOUND *); -static void lexerr(CSOUND *, const char *, ...); -static void synterrp(CSOUND *, const char *, char *); - -static ARGLST *copy_arglist(CSOUND *csound, ARGLST *old) -{ - size_t n = sizeof(ARGLST) + old->count * sizeof(char*) - sizeof(char*); - ARGLST *nn = (ARGLST*) mmalloc(csound, n); - memcpy(nn, old, n); - memset(old, 0, n); - return nn; -} - -static inline int isNameChar(int c, int pos) -{ - c = (int) ((unsigned char) c); - return (isalpha(c) || (pos && (c == '_' || isdigit(c)))); -} - -/* Functions to read/unread chracters from - * a stack of file and macro inputs */ - -static inline void ungetorchar(CSOUND *csound, int c) -{ - if (LIKELY(ST(str)->unget_cnt < 128)) - ST(str)->unget_buf[ST(str)->unget_cnt++] = (char) c; - else - csoundDie(csound, Str("ungetorchar(): buffer overflow")); -} - -static int skiporccomment(CSOUND *csound) -{ - int c; - int mode = 0; /* Mode = 1 after / character */ - int srccnt = 0; - top: - if (ST(str)->unget_cnt) { - c = (int) ((unsigned char) ST(str)->unget_buf[--ST(str)->unget_cnt]); - } - else if (ST(str)->string) { - c = *ST(str)->body++; - if (c == '\0') { - ST(pop) += ST(str)->args; - ST(str)--; ST(input_cnt)--; - ST(linepos) = -1; - return srccnt; - } - } - else { - c = getc(ST(str)->file); - if (c == EOF) { - if (ST(str) == &ST(inputs)[0]) { - ST(linepos) = -1; - return srccnt; - } - if (ST(str)->fd != NULL) { - csound->FileClose(csound, ST(str)->fd); ST(str)->fd = NULL; - } - ST(str)--; ST(input_cnt)--; - ST(str)->line++; ST(linepos) = -1; - return srccnt; - } - } - if (c == '*') mode = 1; /* look for end of comment */ - else if (c == '/' && mode == 1) { - return srccnt; - } - else mode = 0; - if (c == '\n') { - ST(str)->line++; ST(linepos) = -1; - srccnt++; - } - goto top; -} - -static void skiporchar(CSOUND *csound) -{ - int c; - top: - if (UNLIKELY(ST(str)->unget_cnt)) { - c = (int) ((unsigned char) ST(str)->unget_buf[--ST(str)->unget_cnt]); - if (c == '\n') { - ST(linepos) = -1; - return; - } - goto top; - } - else if (ST(str)->string) { - c = *ST(str)->body++; - if (c == '\n') { - ST(str)->line++; ST(linepos) = -1; - return; - } - if (c == '\0') { - ST(pop) += ST(str)->args; - ST(str)--; ST(input_cnt)--; - ST(linepos) = -1; - return; - } - } - else { - c = getc(ST(str)->file); - if (c == '\n' || c == '\r' || c == 26) { /* MS-DOS spare ^Z */ - ST(str)->line++; ST(linepos) = -1; - if (c == '\r') { - if (ST(str)->string) { - if ((c = *ST(str)->body++) != '\n') - ST(str)->body--; - } - else if ((c = getc(ST(str)->file)) != '\n') - ungetc(c, ST(str)->file); - } - return; - } - if (UNLIKELY(c == EOF)) { - if (ST(str) == &ST(inputs)[0]) { - ST(linepos) = -1; - return; - } - if (ST(str)->fd != NULL) { - csound->FileClose(csound, ST(str)->fd); ST(str)->fd = NULL; - } - ST(str)--; ST(input_cnt)--; - ST(str)->line++; ST(linepos) = -1; - return; - } - } - ST(linepos)++; - goto top; -} - -static int getorchar(CSOUND *csound) -{ - int c; - top: - if (UNLIKELY(ST(str)->unget_cnt)) { - c = (int) ((unsigned char) ST(str)->unget_buf[--ST(str)->unget_cnt]); - if (c == '\n') - ST(linepos) = -1; - // printf("%s(%d): %c(%.2x)\n", __FILE__, __LINE__, c,c); - return c; - } - else if (ST(str)->string) { - c = *ST(str)->body++; - if (UNLIKELY(c == '\0')) { - if (ST(str) == &ST(inputs)[0]) { - //corfile_rm(&(csound->orchstr)); - // printf("%s(%d): EOF\n", __FILE__, __LINE__); - return EOF; - } - ST(pop) += ST(str)->args; - ST(str)--; ST(input_cnt)--; - goto top; - } - } - else { - c = getc(ST(str)->file); - if (UNLIKELY(c == 26)) goto top; /* MS-DOS spare ^Z */ - if (UNLIKELY(c == EOF)) { - if (ST(str) == &ST(inputs)[0]) return EOF; - if (ST(str)->fd != NULL) { - csound->FileClose(csound, ST(str)->fd); ST(str)->fd = NULL; - } - ST(str)--; ST(input_cnt)--; goto top; - } - } - if (c == '\r') { - int d; - if (ST(str)->string) { - if ((d = *ST(str)->body++) != '\n') - ST(str)->body--; - } - else if ((d = getc(ST(str)->file)) != '\n') { - ungetc(d, ST(str)->file); - } - c = '\n'; - } - if (c == '\n') { - ST(str)->line++; ST(linepos) = -1; - } - else ST(linepos)++; - if (ST(ingappop) && ST(pop)) { - do { - MACRO *nn = ST(macros)->next; - int i; -#ifdef MACDEBUG - csound->Message(csound, "popping %s\n", ST(macros)->name); -#endif - mfree(csound, ST(macros)->name); mfree(csound, ST(macros)->body); - for (i=0; iacnt; i++) - mfree(csound, ST(macros)->arg[i]); - mfree(csound, ST(macros)); - ST(macros) = nn; - ST(pop)--; - } while (ST(pop)); - } - // printf("%s(%d): %c(%.2x)\n", __FILE__, __LINE__, c,c); - return c; -} - -static int getorchar_noeof(CSOUND *csound) -{ - int c; - - c = getorchar(csound); - if (UNLIKELY(c == EOF)) - lexerr(csound, Str("Unexpected end of orchestra file")); - return c; -} - -/* The fromScore parameter should be 1 if opening a score include file, - 0 if opening an orchestra include file */ -void *fopen_path(CSOUND *csound, FILE **fp, char *name, char *basename, - char *env, int fromScore) -{ - void *fd; - int csftype = (fromScore ? CSFTYPE_SCO_INCLUDE : CSFTYPE_ORC_INCLUDE); - - /* First try to open name given */ - fd = csound->FileOpen2(csound, fp, CSFILE_STD, name, "rb", NULL, - csftype, 0); - if (fd != NULL) - return fd; - /* if that fails try in base directory */ - if (basename != NULL) { - char *dir, *name_full; - if ((dir = csoundSplitDirectoryFromPath(csound, basename)) != NULL) { - name_full = csoundConcatenatePaths(csound, dir, name); - fd = csound->FileOpen2(csound, fp, CSFILE_STD, name_full, "rb", NULL, - csftype, 0); - mfree(csound, dir); - mfree(csound, name_full); - if (fd != NULL) - return fd; - } - } - /* or use env argument */ - fd = csound->FileOpen2(csound, fp, CSFILE_STD, name, "rb", env, - csftype, 0); - return fd; -} - -static void add_math_const_macro(CSOUND *csound, char * name, char *body) -{ - MACRO *mm; - - mm = (MACRO*) mcalloc(csound, sizeof(MACRO)); - mm->name = (char*) mcalloc(csound, strlen(name) + 3); - sprintf(mm->name, "M_%s", name); - mm->next = ST(macros); - ST(macros) = mm; - mm->margs = MARGS; /* Initial size */ - mm->acnt = 0; - mm->body = (char*) mcalloc(csound, strlen(body) + 1); - mm->body = strcpy(mm->body, body); -} - -/** - * Add math constants from math.h as orc macros - */ -static void init_math_constants_macros(CSOUND *csound) -{ - add_math_const_macro(csound, "E", "2.7182818284590452354"); - add_math_const_macro(csound, "LOG2E", "1.4426950408889634074"); - add_math_const_macro(csound, "LOG10E", "0.43429448190325182765"); - add_math_const_macro(csound, "LN2", "0.69314718055994530942"); - add_math_const_macro(csound, "LN10", "2.30258509299404568402"); - add_math_const_macro(csound, "PI", "3.14159265358979323846"); - add_math_const_macro(csound, "PI_2", "1.57079632679489661923"); - add_math_const_macro(csound, "PI_4", "0.78539816339744830962"); - add_math_const_macro(csound, "1_PI", "0.31830988618379067154"); - add_math_const_macro(csound, "2_PI", "0.63661977236758134308"); - add_math_const_macro(csound, "2_SQRTPI", "1.12837916709551257390"); - add_math_const_macro(csound, "SQRT2", "1.41421356237309504880"); - add_math_const_macro(csound, "SQRT1_2", "0.70710678118654752440"); - add_math_const_macro(csound, "INF", "800000000000.0"); /* ~25367 years */ -} - -static void init_omacros(CSOUND *csound, NAMES *nn) -{ - while (nn) { - char *s = nn->mac; - char *p = strchr(s, '='); - char *mname; - MACRO *mm; - - if (p == NULL) - p = s + strlen(s); - if (csound->oparms->msglevel & 7) - csound->Message(csound, Str("Macro definition for %*s\n"), p - s, s); - s = strchr(s, ':') + 1; /* skip arg bit */ - if (UNLIKELY(s == NULL || s >= p)) - csound->Die(csound, Str("Invalid macro name for --omacro")); - mname = (char*) mmalloc(csound, (p - s) + 1); - strncpy(mname, s, p - s); - mname[p - s] = '\0'; - /* check if macro is already defined */ - for (mm = ST(macros); mm != NULL; mm = mm->next) { - if (strcmp(mm->name, mname) == 0) - break; - } - if (mm == NULL) { - mm = (MACRO*) mcalloc(csound, sizeof(MACRO)); - mm->name = mname; - mm->next = ST(macros); - ST(macros) = mm; - } - else - mfree(csound, mname); - mm->margs = MARGS; /* Initial size */ - mm->acnt = 0; - if (*p != '\0') - p++; - mm->body = (char*) mmalloc(csound, strlen(p) + 1); - strcpy(mm->body, p); - nn = nn->next; - } -} - -void rdorchfile(CSOUND *csound) /* read entire orch file into txt space */ -{ - int c, lincnt; - int srccnt; - char *cp, *endspace, *ortext; - int linmax = LINMAX; /* Maximum number of lines */ - int heredoc = 0, openquote = 0; - - if (csound->rdorchGlobals == NULL) { - csound->rdorchGlobals = csound->Calloc(csound, sizeof(RDORCH_GLOBALS)); - ST(lenmax) = LENMAX; - ST(grpmax) = GRPMAX; - ST(ingappop) = 1; - ST(linepos) = -1; - ST(tempNum) = 300L; - ST(nxtest) = 1; - } - init_math_constants_macros(csound); - init_omacros(csound, csound->omacros); - /* IV - Oct 31 2002: create tables for easier checking for common types */ - if (!ST(typemask_tabl)) { - const int32 *ptr = typetabl1; - ST(typemask_tabl) = (int32*) mcalloc(csound, sizeof(int32) * 256); - ST(typemask_tabl_in) = (int32*) mcalloc(csound, sizeof(int32) * 256); - ST(typemask_tabl_out) = (int32*) mcalloc(csound, sizeof(int32) * 256); - while (*ptr) { /* basic types (both for input */ - int32 pos = *ptr++; /* and output) */ - ST(typemask_tabl)[pos] = ST(typemask_tabl_in)[pos] = - ST(typemask_tabl_out)[pos] = *ptr++; - } - ptr = typetabl2; - while (*ptr) { /* input types */ - int32 pos = *ptr++; - ST(typemask_tabl_in)[pos] = *ptr++; - } - ptr = typetabl3; - while (*ptr) { /* output types */ - int32 pos = *ptr++; - ST(typemask_tabl_out)[pos] = *ptr++; - } - } - csound->Message(csound, Str("orch compiler:\n")); - ST(inputs) = (IN_STACK*) mmalloc(csound, 20 * sizeof(IN_STACK)); - ST(input_size) = 20; - ST(input_cnt) = 0; - ST(str) = ST(inputs); - ST(str)->line = 1; - ST(str)->unget_cnt = 0; - if (csound->orchstr) { - ST(orchsiz) = corfile_length(csound->orchstr); - ST(str)->string = 1; - ST(str)->body = corfile_body(csound->orchstr); - ST(str)->file = NULL; - ST(str)->fd = NULL; - } - else { - /* if (UNLIKELY((ST(fd) = csound->FileOpen2(csound, &ST(fp), CSFILE_STD, */ - /* csound->orchname, "rb", NULL, CSFTYPE_ORCHESTRA, */ - /* (csound->tempStatus & csOrcMask)!=0)) == NULL)) */ - csoundDie(csound, Str("cannot open orch file %s"), csound->orchname); - /* if (UNLIKELY(fseek(ST(fp), 0L, SEEK_END) != 0)) */ - /* csoundDie(csound, Str("cannot find end of file %s"), csound->orchname); */ - /* if (UNLIKELY((ST(orchsiz) = ftell(ST(fp))) <= 0)) */ - /* csoundDie(csound, Str("ftell error on %s"), csound->orchname); */ - /* rewind(ST(fp)); */ - /* ST(str)->string = 0; */ - /* ST(str)->file = ST(fp); */ - /* ST(str)->fd = ST(fd); */ - /* ST(str)->body = csound->orchname; */ - } - ortext = mmalloc(csound, ST(orchsiz) + 1); /* alloc mem spaces */ - ST(linadr) = (char **) mmalloc(csound, (LINMAX + 1) * sizeof(char *)); - strsav_create(csound); - lincnt = srccnt = 1; - cp = ST(linadr)[1] = ortext; - endspace = ortext + ST(orchsiz) + 1; - strsav_string(csound, "sr"); - ST(group) = (char **)mcalloc(csound, (GRPMAX+1)*sizeof(char*)); - ST(grpsav)= (char **)mcalloc(csound, (GRPMAX+1)*sizeof(char*)); - ST(lblreq) = (LBLREQ*)mcalloc(csound, LBLMAX*sizeof(LBLREQ)); - ST(lblmax) = LBLMAX; - - top: - while ((c = getorchar(csound)) != EOF) { /* read entire orch file */ - if (cp == endspace-5) { /* Must extend */ - char *orold = ortext; - int i; - /* printf("Expand orch: %p (%d) %p -> ", ortext, ST(orchsiz), endspace); */ - ST(orchsiz) = ST(orchsiz) + (ST(orchsiz) >> 4) + 1L; - ST(orchsiz) = (ST(orchsiz) + 511L) & (~511L); - ortext = mrealloc(csound, ortext, ST(orchsiz)); - endspace = ortext + ST(orchsiz) + 1; - /* printf("%p (%d) %p\n", ortext, ST(orchsiz), endspace); */ - if (ortext != orold) { - ptrdiff_t adj = ortext - orold; - for (i=1; i<=lincnt; i++) - ST(linadr)[i] += adj; /* Relocate */ - cp += adj; - } - } - *cp++ = c; - if (c == '{' && !openquote) { - char c2 = getorchar(csound); - if (c2 == '{') { - heredoc = 1; - *cp++ = c; - } - else - ungetorchar(csound, c2); - } - else if (c == '}' && heredoc) { - char c2 = getorchar(csound); - if (c2 == '}') { - heredoc = 0; - *cp++ = c; - } - else - ungetorchar(csound, c2); - } - if (c == ';' && !heredoc) { - skiporchar(csound); - *(cp - 1) = (char) (c = '\n'); - } - if (c == '"' && !heredoc) { - openquote = !openquote; - } - if (c == '\\' && !heredoc & !openquote) { /* Continuation ? */ - while ((c = getorchar(csound)) == ' ' || c == '\t') - ; /* Ignore spaces */ - if (c == ';') { /* Comments get skipped */ - skiporchar(csound); - c = '\n'; - } - if (c == '\n') { - cp--; /* Ignore newline */ - srccnt++; /* record a fakeline */ - /* lincnt++; Thsi is wrong */ - } - else { - *cp++ = c; - } - } - else if (c == '/') { - c = getorchar(csound); - if (c=='*') { - srccnt += skiporccomment(csound); - cp--; /* ?? ?? ?? */ - goto top; - } - else { - ungetorchar(csound, c); - c = '/'; - } - } - else if (c == '\n') { /* at each new line */ - char *lp = ST(linadr)[lincnt]; - /* printf("lincnt=%d; lp=%p, ST(linadr)=%p\n", lincnt, lp, ST(linadr)); */ - while ((c = *lp) == ' ' || c == '\t') - lp++; - if (*lp != '\n' && *lp != ';') { - ST(curline) = lincnt - 1; - } - srccnt++; - if (++lincnt >= linmax) { - linmax += 100; - ST(linadr) = (char**) mrealloc(csound, ST(linadr), (linmax + 1) - * sizeof(char*)); - } - /* ST(srclin)[lincnt] = srccnt; unused */ - ST(linadr)[lincnt] = cp; /* record the adrs */ - } - else if (c == '#' && ST(linepos) == 0 && !heredoc) { - /* Start Macro definition */ - /* also deal with #include here */ - char *mname, *preprocName; - int mlen = 40; - int i, cnt; - mname = (char *)malloc(mlen); - cp--; - parsePreproc: - preprocName = NULL; - i = 0; - cnt = 0; - mname[cnt++] = '#'; - if (cnt==mlen) - mname = (char *)realloc(mname, mlen+=40); - do { - c = getorchar(csound); - if (UNLIKELY(c == EOF)) - break; - mname[cnt++] = c; - if (cnt==mlen) - mname = (char *)realloc(mname, mlen+=40); - } while ((c == ' ' || c == '\t')); - mname[cnt] = '\0'; - if (c == EOF || c == '\n') - goto unknownPreproc; - preprocName = &(mname[cnt - 1]); - while (1) { - c = getorchar(csound); - if (c == EOF || !(isalnum(c) || c == '_')) - break; - mname[cnt++] = c; - if (cnt==mlen) - mname = (char *)realloc(mname, mlen+=40); - } - mname[cnt] = '\0'; - if (strcmp(preprocName, "define") == 0 && - !(ST(ifdefStack) != NULL && ST(ifdefStack)->isSkip)) { - MACRO *mm = (MACRO*) mmalloc(csound, sizeof(MACRO)); - int arg = 0; - int size = 40; - mm->margs = MARGS; /* Initial size */ - while (isspace((c = getorchar(csound)))) - ; - while (isNameChar(c, i)) { - mname[i++] = c; - if (i==mlen) - mname = (char *)realloc(mname, mlen+=40); - c = getorchar(csound); - } - mname[i] = '\0'; - if (csound->oparms->msglevel & 7) - csound->Message(csound, Str("Macro definition for %s\n"), mname); - mm->name = mmalloc(csound, i + 1); - strcpy(mm->name, mname); - if (c == '(') { /* arguments */ -#ifdef MACDEBUG - csound->Message(csound, "M-arguments: "); -#endif - do { - while (isspace((c = getorchar_noeof(csound)))) - ; - i = 0; - while (isNameChar(c, i)) { - mname[i++] = c; - if (i==mlen) - mname = (char *)realloc(mname, mlen+=40); - c = getorchar(csound); - } - mname[i] = '\0'; -#ifdef MACDEBUG - csound->Message(csound, "%s\t", mname); -#endif - mm->arg[arg] = mmalloc(csound, i + 1); - strcpy(mm->arg[arg++], mname); - if (arg >= mm->margs) { - mm = (MACRO*) mrealloc(csound, mm, sizeof(MACRO) - + mm->margs * sizeof(char*)); - mm->margs += MARGS; - } - while (isspace(c)) - c = getorchar_noeof(csound); - } while (c == '\'' || c == '#'); - if (UNLIKELY(c != ')')) - csound->Message(csound, Str("macro error\n")); - } - mm->acnt = arg; - i = 0; - while (c != '#') - c = getorchar_noeof(csound); /* Skip to next # */ - mm->body = (char*) mmalloc(csound, 100); - while ((c = getorchar_noeof(csound)) != '#') { - mm->body[i++] = c; - if (UNLIKELY(i >= size)) - mm->body = mrealloc(csound, mm->body, size += 100); - if (c == '\\') { /* allow escaped # */ - mm->body[i++] = c = getorchar_noeof(csound); - if (UNLIKELY(i >= size)) - mm->body = mrealloc(csound, mm->body, size += 100); - } - if (c == '\n') - srccnt++; - } - mm->body[i] = '\0'; - mm->next = ST(macros); - ST(macros) = mm; -#ifdef MACDEBUG - csound->Message(csound, "Macro %s with %d arguments defined\n", - mm->name, mm->acnt); -#endif - c = ' '; - } - else if (strcmp(preprocName, "include") == 0 && - !(ST(ifdefStack) != NULL && ST(ifdefStack)->isSkip)) { - int delim; - while (isspace(c)) - c = getorchar(csound); - delim = c; - i = 0; - while ((c = getorchar_noeof(csound)) != delim) { - mname[i++] = c; - if (i==mlen) - mname = (char *)realloc(mname, mlen+=40); - } - mname[i] = '\0'; - do { - c = getorchar(csound); - } while (c != EOF && c != '\n'); -#ifdef MACDEBUG - csound->Message(csound, "#include \"%s\"\n", mname); -#endif - ST(input_cnt)++; - if (ST(input_cnt) >= ST(input_size)) { - ST(input_size) += 20; - ST(inputs) = mrealloc(csound, ST(inputs), ST(input_size) - * sizeof(IN_STACK)); - } - ST(str) = (IN_STACK*) ST(inputs) + (int) ST(input_cnt); - ST(str)->string = 0; - ST(str)->fd = fopen_path(csound, &(ST(str)->file), - mname, csound->orchname, "INCDIR", 0); - if (UNLIKELY(ST(str)->fd == NULL)) { - csound->Message(csound, - Str("Cannot open #include'd file %s\n"), mname); - /* Should this stop things?? */ - ST(str)--; ST(input_cnt)--; - } - else { - ST(str)->body = csound->GetFileName(ST(str)->fd); - ST(str)->line = 1; - ST(str)->unget_cnt = 0; - ST(linepos) = -1; - } - } - else if (strcmp(preprocName, "ifdef") == 0 || - strcmp(preprocName, "ifndef") == 0) { - MACRO *mm; /* #ifdef or #ifndef */ - IFDEFSTACK *pp; - pp = (IFDEFSTACK*) mcalloc(csound, sizeof(IFDEFSTACK)); - pp->prv = ST(ifdefStack); - if (strcmp(preprocName, "ifndef") == 0) - pp->isDef = 1; - while (isspace(c = getorchar(csound))) - ; - while (isNameChar(c, i)) { - mname[i++] = c; - if (i==mlen) - mname = (char *)realloc(mname, mlen+=40); - c = getorchar(csound); - } - mname[i] = '\0'; - for (mm = ST(macros); mm != NULL; mm = mm->next) { - if (strcmp(mname, mm->name) == 0) { - pp->isDef ^= (unsigned char) 1; - break; - } - } - ST(ifdefStack) = pp; - pp->isSkip = pp->isDef ^ (unsigned char) 1; - if (pp->prv != NULL && pp->prv->isSkip) - pp->isSkip |= (unsigned char) 2; - if (!pp->isSkip) { - while (c != '\n' && c != EOF) { /* Skip to end of line */ - c = getorchar(csound); - } - srccnt++; goto top; - } - else { /* Skip a section of code */ - ifdefSkipCode: - do { - while (c != '\n') { - if (UNLIKELY(c == EOF)) - lexerr(csound, Str("unmatched #ifdef")); - c = getorchar(csound); - } - srccnt++; - c = getorchar(csound); - } while (c != '#'); - goto parsePreproc; - } - } - else if (strcmp(preprocName, "else") == 0) { - if (ST(ifdefStack) == NULL || ST(ifdefStack)->isElse) - lexerr(csound, Str("Unmatched #else")); - while (c != '\n' && c != EOF) - c = getorchar(csound); - srccnt++; - ST(ifdefStack)->isElse = 1; - ST(ifdefStack)->isSkip ^= (unsigned char) 1; - if (ST(ifdefStack)->isSkip) - goto ifdefSkipCode; - goto top; - } - else if (strcmp(preprocName, "end") == 0 || - strcmp(preprocName, "endif") == 0) { - IFDEFSTACK *pp = ST(ifdefStack); - if (UNLIKELY(pp == NULL)) - lexerr(csound, Str("Unmatched #endif")); - while (c != '\n' && c != EOF) { - c = getorchar(csound); - } - srccnt++; - ST(ifdefStack) = pp->prv; - mfree(csound, pp); - if (ST(ifdefStack) != NULL && ST(ifdefStack)->isSkip) - goto ifdefSkipCode; - goto top; - } - else if (strcmp(preprocName, "undef") == 0 && - !(ST(ifdefStack) != NULL && ST(ifdefStack)->isSkip)) { - while (isspace(c = getorchar(csound))) - ; - while (isNameChar(c, i)) { - mname[i++] = c; - if (i==mlen) - mname = (char *)realloc(mname, mlen+=40); - c = getorchar(csound); - } - mname[i] = '\0'; - if (csound->oparms->msglevel) - csound->Message(csound,Str("macro %s undefined\n"), mname); - if (strcmp(mname, ST(macros)->name)==0) { - MACRO *mm=ST(macros)->next; - mfree(csound, ST(macros)->name); mfree(csound, ST(macros)->body); - for (i=0; iacnt; i++) - mfree(csound, ST(macros)->arg[i]); - mfree(csound, ST(macros)); ST(macros) = mm; - } - else { - MACRO *mm = ST(macros); - MACRO *nn = mm->next; - while (strcmp(mname, nn->name) != 0) { - mm = nn; nn = nn->next; - if (nn == NULL) - lexerr(csound, Str("Undefining undefined macro")); - } - mfree(csound, nn->name); mfree(csound, nn->body); - for (i=0; iacnt; i++) - mfree(csound, nn->arg[i]); - mm->next = nn->next; mfree(csound, nn); - } - while (c != '\n' && c != EOF) - c = getorchar(csound); /* ignore rest of line */ - srccnt++; - } - else { - unknownPreproc: - if (ST(ifdefStack) != NULL && ST(ifdefStack)->isSkip) - goto ifdefSkipCode; - if (preprocName == NULL) - lexerr(csound, Str("Unexpected # character")); - else if (strcmp("exit", preprocName)) /* VL: ignore #exit */ - lexerr(csound, Str("Unknown # option: '%s'"), preprocName); - } - free(mname); - } - else if (c == '$' && !heredoc) { - char name[100]; - int i = 0; - int j; - MACRO *mm, *mm_save = NULL; - ST(ingappop) = 0; - while (isNameChar((c = getorchar(csound)), i)) { - name[i++] = c; name[i] = '\0'; - mm = ST(macros); - while (mm != NULL) { /* Find the definition */ - if (!(strcmp(name, mm->name))) { - mm_save = mm; /* found a match, save it */ - break; - } - mm = mm->next; - } - } - mm = mm_save; - if (UNLIKELY(mm == NULL)) { - if (i) - lexerr(csound,Str("Undefined macro: '%s'"), name); - else - lexerr(csound,Str("Macro expansion symbol ($) without macro name")); - continue; - } - if ((int) strlen(mm->name) != i) { - int cnt = i - (int) strlen(mm->name); - csound->Warning(csound, Str("$%s matches macro name $%s"), - name, mm->name); - do { - ungetorchar(csound, c); - c = name[--i]; - } while (cnt--); - } - else if (c != '.') - ungetorchar(csound, c); -#ifdef MACDEBUG - csound->Message(csound, "Found macro %s required %d arguments\n", - mm->name, mm->acnt); -#endif - /* Should bind arguments here */ - /* How do I recognise entities?? */ - if (mm->acnt) { - if (UNLIKELY((c = getorchar(csound)) != '(')) - lexerr(csound, Str("Syntax error in macro call")); - for (j = 0; j < mm->acnt; j++) { - char term = (j == mm->acnt - 1 ? ')' : '\''); - char trm1 = (j == mm->acnt - 1 ? ')' : '#'); /* Compatability */ - MACRO *nn = (MACRO*) mmalloc(csound, sizeof(MACRO)); - int size = 100; - nn->name = mmalloc(csound, strlen(mm->arg[j]) + 1); - strcpy(nn->name, mm->arg[j]); -#ifdef MACDEBUG - csound->Message(csound, "defining argument %s ", nn->name); -#endif - i = 0; - nn->body = (char*) mmalloc(csound, 100); - while ((c = getorchar(csound))!= term && c!=trm1) { - if (UNLIKELY(i > 98)) { - csound->Die(csound, Str("Missing argument terminator\n%.98s"), - nn->body); - } - nn->body[i++] = c; - if (UNLIKELY(i >= size)) - nn->body = mrealloc(csound, nn->body, size += 100); - if (c == '\n') { - srccnt++; - } - } - nn->body[i] = '\0'; -#ifdef MACDEBUG - csound->Message(csound, "as...#%s#\n", nn->body); -#endif - nn->acnt = 0; /* No arguments for arguments */ - nn->next = ST(macros); - ST(macros) = nn; - } - } - cp--; /* Ignore $ sign */ - ST(input_cnt)++; - if (ST(input_cnt) >= ST(input_size)) { - ST(input_size) += 20; - ST(inputs) = (IN_STACK*) mrealloc(csound, ST(inputs), - ST(input_size) * sizeof(IN_STACK)); - } - ST(str) = (IN_STACK*) ST(inputs) + (int) ST(input_cnt); - ST(str)->string = 1; ST(str)->body = mm->body; ST(str)->args = mm->acnt; - ST(str)->mac = mm; - ST(str)->line = 1; - ST(str)->unget_cnt = 0; - ST(ingappop) = 1; - } - } - if (UNLIKELY(ST(ifdefStack) != NULL)) - lexerr(csound, Str("Unmatched #ifdef")); - if (UNLIKELY(cp >= endspace)) { /* Ought to extend */ - csoundDie(csound, Str("file too large for ortext space")); - } - if (*(cp-1) != '\n') /* if no final NL, */ - *cp++ = '\n'; /* add one */ - else --lincnt; - ST(linadr)[lincnt+1] = NULL; /* terminate the adrs list */ -#ifdef BETA - csound->Message(csound,Str("%d (%d) lines read\n"),lincnt, srccnt); -#endif - if (ST(fd) != NULL) { - csound->FileClose(csound, ST(fd)); /* close the file */ - ST(fd) = NULL; - } - ST(curline) = 0; /* & reset to line 1 */ - ST(ortext) = ortext; - while (ST(macros)) { /* Clear all macros */ - int i; - mfree(csound, ST(macros)->body); - mfree(csound, ST(macros)->name); - for (i = 0; i < ST(macros)->acnt; i++) - mfree(csound, ST(macros)->arg[i]); - ST(macros) = ST(macros)->next; - } /* nullist is a count only */ - ST(nullist) = (ARGLST *) mmalloc(csound, sizeof(ARGLST)); - ST(nullist)->count = 0; - ST(nxtarglist) = (ARGLST*) mmalloc(csound, sizeof(ARGLST) - + 200 * sizeof(char*)); -} - -static void extend_collectbuf(CSOUND *csound, char **cp, int grpcnt) -{ - char *nn; - int i; - - i = (int) ST(lenmax); - ST(lenmax) <<= 1; - nn = mrealloc(csound, ST(collectbuf), ST(lenmax) + 16); - (*cp) += (nn - ST(collectbuf)); /* Adjust pointer */ - for ( ; i < (int) ST(lenmax); i++) - nn[i] = (char) 0; - /* Need to correct grp vector */ - for (i = 0; i < grpcnt; i++) - ST(group)[i] += (nn - ST(collectbuf)); - ST(collectbuf) = nn; -} - -static void extend_group(CSOUND *csound) -{ - int32 i, j; - - i = ST(grpmax); - j = i + (int32) GRPMAX; - ST(grpmax) = (j++); - ST(group) = (char **) mrealloc(csound, ST(group), j * sizeof(char *)); - ST(grpsav) = (char **) mrealloc(csound, ST(grpsav), j * sizeof(char *)); - while (++i < j) { - ST(group)[i] = (char *) NULL; - ST(grpsav)[i] = (char *) NULL; - } -} - -/* split next orch line into atomic groups, count */ -/* labels this line, and set opgrpno where found */ - -static int splitline(CSOUND *csound) -{ - int grpcnt, prvif, prvelsif, logical, condassgn, parens; - int c, collecting; - char *cp, *lp, *grpp = NULL; - - if (ST(collectbuf) == NULL) - ST(collectbuf) = mcalloc(csound, ST(lenmax) + 16); - nxtlin: - if ((lp = ST(linadr)[++ST(curline)]) == NULL) /* point at next line */ - return 0; - csound->DebugMsg(csound, Str("LINE %d:"), CURLINE); - ST(linlabels) = ST(opgrpno) = 0; - grpcnt = prvif = prvelsif = logical = condassgn = parens = collecting = 0; - cp = ST(collectbuf); - while ((c = *lp++) != '\n') { /* for all chars this line: */ - if (cp - ST(collectbuf) >= ST(lenmax)) - extend_collectbuf(csound, &cp, grpcnt); - if (c == ' ' || c == '\t' || c == '(') { /* spaces, tabs, (: */ - if (!ST(opgrpno) && collecting) { /* those before args */ - *cp++ = '\0'; /* can be delimiters */ - collecting = 0; - if (strcmp(grpp, "if") == 0) { /* of if opcod, */ - strcpy(grpp, "cggoto"); /* (replace) */ - cp = grpp + 7; - prvif++; - } - else if (strcmp(grpp, "elseif") == 0) { /* of elseif opcod, ... */ - /* check to see we had an 'if' before */ - if (!ST(iflabels)) { - synterr(csound, Str("invalid 'elseif' statement. " - "must have a corresponding 'if'")); - goto nxtlin; - } - /* check to see we did not have an 'else' before */ - if (UNLIKELY(!ST(iflabels)->els[0])) { - synterr(csound, - Str("'elseif' statement cannot occur after an 'else'")); - goto nxtlin; - } - /* 'elseif' requires 2 additional lines */ - if (ST(repeatingElseifLine)) { - /* add the 'elselabel' */ - ST(linlabels)++; - strcpy(grpp, ST(iflabels)->els); - cp = grpp + strlen(ST(iflabels)->els) + 1; - /* finally replace the 'elseif' with a 'goto' */ - grpp = ST(group)[grpcnt++] = cp; - strcpy(grpp, "cggoto"); - cp = grpp + 7; - prvif++; - prvelsif++; - ST(repeatingElseifLine) = 0; - } - else { - /* first add a 'goto endif' for the previous if */ - if (ST(iflabels)->ithen > 0) - strcpy(grpp, "goto"); - else - strcpy(grpp, "kgoto"); - if (isopcod(csound, grpp)) - ST(opgrpno) = grpcnt; - ST(group)[grpcnt] = strchr(grpp, '\0') + 1; - grpp = ST(group)[grpcnt++]; - strcpy(grpp, ST(iflabels)->end); - ST(curline)--; /* roll back one and parse this line again */ - ST(repeatingElseifLine)++; - ST(linopnum) = ST(opnum); /* else save full line ops */ - ST(linopcod) = ST(opcod); - return grpcnt; - } - } - if (isopcod(csound, grpp)) /* ... or maybe others */ - ST(opgrpno) = grpcnt; - } - if (c == ' ' || c == '\t') - continue; /* now discard blanks */ - } - else if (c == ';') { - while ((c = *lp++) != '\n'); /* comments: gobble */ - break; /* & exit linloop */ - } - else if (c == '/' && *lp == '*') { /* C Style comments */ - char *ll, *eol; - ll = strstr(lp++, "*/"); - nxtl: - eol = strchr(lp, '\n'); - if (eol != NULL && eol < ll) { - lp = ST(linadr)[++ST(curline)]; - ll = strstr(lp, "*/"); - goto nxtl; - } - if (UNLIKELY(ll == NULL)) { - synterrp(csound, lp - 2, Str("Unmatched comment")); - lp = eol + 1; break; - } - lp = ll + 2; - continue; - } - else if (c == '"') { /* quoted string: */ - if (grpcnt >= ST(grpmax)) - extend_group(csound); - grpp = ST(group)[grpcnt++] = cp; - *cp++ = c; /* cpy to nxt quote */ - do { - loop: - c = *lp++; - if (c=='\\' && *lp=='"') { /* Deal with \" case */ - *cp++ = '\\'; - *cp++ = '"'; - lp++; - goto loop; - } - *cp++ = c; - } while (c != '"' && c != '\n'); - if (c == '\n') - synterrp(csound, lp - 1, Str("unmatched quotes")); - collecting = 1; /* & resume chking */ - continue; - } - else if (c == '{' && *lp == '{') { /* multiline quoted string: */ - if (grpcnt >= ST(grpmax)) - extend_group(csound); - grpp = ST(group)[grpcnt++] = cp; - c = '"'; /* cpy to nxt quote */ - do { - *cp++ = c; - if (cp - ST(collectbuf) >= ST(lenmax)) - extend_collectbuf(csound, &cp, grpcnt); - c = *(++lp); - if (c == '\n') - ++ST(curline); - } while (!(c == '}' && lp[1] == '}')); - lp += 2; - *cp++ = '"'; - collecting = 1; /* & resume chking */ - continue; - } - else if (c == ':' && collecting && grpcnt == ST(linlabels)+1) { - ST(linlabels)++; /* colon in 1st grps */ - *cp++ = '\0'; /* is also delimitr */ - collecting = 0; /* (do not copy it) */ - continue; - } - else if (c == '=' && !ST(opgrpno)) { /* assign befor args */ - if (collecting) /* can be a delimitr */ - *cp++ = '\0'; - grpp = ST(group)[grpcnt++] = cp; /* is itslf an opcod */ - *cp++ = c; - *cp++ = '\0'; - isopcod(csound, grpp); - ST(opgrpno) = grpcnt; - collecting = 0; /* & self-delimiting */ - continue; - } - else if (c == ',') { /* comma: */ - if (UNLIKELY(!collecting)) - synterrp(csound, lp - 1, Str("misplaced comma")); - if (UNLIKELY(parens)) { - synterrp(csound, lp - 2, Str("unbalanced parens")); - parens = 0; - } - *cp++ = '\0'; /* terminate string */ - collecting = logical = condassgn = 0; - continue; - } - if (prvif && collecting && !parens) { /* for prev "if": */ - if (strncmp(lp-1,"goto",4) == 0) { /* if found "goto" */ - *cp++ = '\0'; /* delimit cond */ - lp += 3; /* & step over */ - prvif = collecting = 0; - continue; - } - else if ((c == 'i' || c == 'k') && /* if preced i or k */ - strncmp(lp, "goto", 4) == 0) { /* before "goto" */ - *(ST(group)[ST(opgrpno) - 1] + 1) = c; /* modify cggoto */ - isopcod(csound, ST(group)[ST(opgrpno) - 1]); - *cp++ = '\0'; /* then delimit */ - lp += 4; /* etc */ - prvif = collecting = 0; - continue; - } - else if (strncmp(lp - 1, "then", 4) == 0) { - struct iflabel *prv = ST(iflabels); - /* modify cggoto */ - *(ST(group)[ST(opgrpno) - 1] + 1) = 'n'; - isopcod(csound, ST(group)[ST(opgrpno) - 1]); - *cp++ = '\0'; - lp += 3; - prvif = collecting = 0; - grpp = ST(group)[grpcnt++] = cp; - /* synthesize labels to represent an else and endif */ - if (prvelsif) { /* elseif, so we just need a new elselabel */ - sprintf(ST(iflabels)->els, "__else_%d", ST(tempNum)++); - prvelsif = 0; - } - else { - /* this is a new if, so put a whole new label struct on the stack */ - ST(iflabels) = (struct iflabel *) mmalloc(csound, - sizeof(struct iflabel)); - ST(iflabels)->prv = prv; - sprintf(ST(iflabels)->end, "__endif_%d",ST(tempNum)++); - sprintf(ST(iflabels)->els, "__else_%d", ST(tempNum)++); - } - /* we set the 'goto' label to the 'else' label */ - strcpy(grpp, ST(iflabels)->els); - cp = strchr(grpp, '\0'); - /* set ithen flag to unknown (getoptxt() will update it later) */ - ST(iflabels)->ithen = -1; - continue; - } - else if (strncmp(lp - 1, "ithen", 5) == 0) { - struct iflabel *prv = ST(iflabels); - /* modify cggoto */ - *(ST(group)[ST(opgrpno) - 1] + 1) = 'o'; - isopcod(csound, ST(group)[ST(opgrpno) - 1]); - *cp++ = '\0'; - lp += 4; - prvif = collecting = 0; - grpp = ST(group)[grpcnt++] = cp; - /* synthesize labels to represent an else and endif */ - if (prvelsif) { /* elseif, so we just need a new elselabel */ - sprintf(ST(iflabels)->els, "__else_%d",ST(tempNum)++); - prvelsif = 0; - } - else { - /* this is a new if, so put a whole new label struct on the stack */ - ST(iflabels) = (struct iflabel *)mmalloc(csound, - sizeof(struct iflabel)); - ST(iflabels)->prv = prv; - sprintf(ST(iflabels)->end, "__endif_%d",ST(tempNum)++); - sprintf(ST(iflabels)->els, "__else_%d", ST(tempNum)++); - } - /* we set the 'goto' label to the 'else' label */ - strcpy(grpp, ST(iflabels)->els); - cp = strchr(grpp, '\0'); - /* set ithen flag */ - ST(iflabels)->ithen = 1; - continue; - } - } - if (!collecting++) { /* remainder are */ - if (grpcnt >= ST(grpmax)) /* collectable chars */ - extend_group(csound); - grpp = ST(group)[grpcnt++] = cp; - } - *cp++ = c; /* collect the char */ - /* establish validity: allow letters, digits, and underscore */ - /* in label, variable, and opcode names */ - if (isalnum(c) || c == '_') - continue; - /* other characters are valid only after an opcode */ - if (UNLIKELY(!ST(opgrpno))) - goto char_err; - switch (c) { - case '<': - case '>': - if (*lp == c) { - lp++; *cp++ = c; /* <<, >> */ - } - else if (prvif || parens) /* <, <=, >=, > */ - logical++; - else - goto char_err; - break; - case '&': - case '|': - if (*lp == c) { /* &&, ||, &, | */ - if (UNLIKELY(!prvif && !parens)) - goto char_err; - logical++; lp++; *cp++ = c; - } - break; - case '!': - case '=': - if (UNLIKELY(!prvif && !parens)) /* ==, !=, <=, >= */ - goto char_err; - logical++; - break; - case '+': /* arithmetic and bitwise ops */ - case '-': - case '*': - case '/': - case '%': - case '^': - case '#': /* XOR */ - case '\254': /* NOT (same as ~) */ - case '~': - case '.': - break; - case '\302': - if (*lp == '\254') /* NOT operator in UTF-8 format */ - *(cp - 1) = *lp++; - else - goto char_err; - break; - case '(': - parens++; /* and monitor function */ - break; - case ')': - if (UNLIKELY(!parens)) { - synterrp(csound, lp - 1, Str("unbalanced parens")); - cp--; - } - else - --parens; - break; - case '?': - if (UNLIKELY(!logical)) - goto char_err; - condassgn++; - break; - case ':': - if (UNLIKELY(!condassgn)) - goto char_err; - break; - default: - goto char_err; - } - continue; /* loop back for next character */ - char_err: - { - char err_msg[64]; - sprintf(err_msg, Str("illegal character %c"), c); - synterrp(csound, lp - 1, err_msg); - cp--; - } - } - *cp = '\0'; /* terminate last group */ - if (grpp && grpcnt == (ST(linlabels) + 1)) { - /* convert an 'else' statement into 2 lines - goto - - to do this, we parse the current twice */ - if (strcmp(grpp, "else") == 0) { - if (UNLIKELY(!ST(iflabels))) { /* 'else': check to see we had an 'if' before */ - synterr(csound, Str("invalid 'else' statement. " - "must have a corresponding 'if'")); - goto nxtlin; - } - if (ST(repeatingElseLine)) { /* add the elselabel */ - if (UNLIKELY(!ST(iflabels)->els[0])) { - /* check to see we had not another 'else' */ - synterr(csound, Str("duplicate 'else' statement")); - goto nxtlin; - } - ST(linlabels)++; - strcpy(grpp, ST(iflabels)->els); - ST(iflabels)->els[0] = '\0'; - ST(repeatingElseLine) = 0; - } - else { /* add the goto statement */ - if (ST(iflabels)->ithen > 0) - strcpy(grpp, "goto"); - else - strcpy(grpp, "kgoto"); - ST(linlabels) = 0; /* ignore any labels this time */ - ST(group)[0] = grpp; - grpcnt = 1; - if (isopcod(csound, grpp)) - ST(opgrpno) = grpcnt; - ST(group)[grpcnt] = strchr(grpp, '\0') + 1; - grpp = ST(group)[grpcnt++]; - strcpy(grpp, ST(iflabels)->end); - ST(curline)--; /* roll back one and parse this line again */ - ST(repeatingElseLine) = 1; - } - } - else if (strcmp(grpp, "endif") == 0) { - /* replace 'endif' with the synthesized label */ - struct iflabel *prv; - if (UNLIKELY(!ST(iflabels))) { /* check to see we had an 'if' before */ - synterr(csound, Str("invalid 'endif' statement. " - "must have a corresponding 'if'")); - goto nxtlin; - } - if (ST(iflabels)->els[0]) { - /* we had no 'else' statement, so we need to insert the elselabel */ - ST(linlabels)++; - strcpy(grpp, ST(iflabels)->els); - ST(iflabels)->els[0] = '\0'; - ST(curline)--; /* roll back one and parse this line again */ - } - else { - prv = ST(iflabels)->prv; - ST(linlabels)++; - strcpy(grpp, ST(iflabels)->end); - mfree(csound, ST(iflabels)); - ST(iflabels) = prv; - } - } - } - if (!grpcnt) /* if line was trivial, */ - goto nxtlin; /* try another */ - if (collecting && !ST(opgrpno)) { /* if still collecting, */ - if (isopcod(csound, grpp)) /* chk for opcod */ - ST(opgrpno) = grpcnt; - } - if (UNLIKELY(parens)) /* check balanced parens */ - synterrp(csound, lp - 1, Str("unbalanced parens")); - if (UNLIKELY(grpcnt > ST(linlabels) && !ST(opgrpno))) { /* if no full line opcod, */ - synterr(csound, Str("no legal opcode")); /* complain & */ - goto nxtlin; /* try another */ - } - ST(linopnum) = ST(opnum); /* else save full line ops */ - ST(linopcod) = ST(opcod); - if (UNLIKELY(csound->oparms->odebug)) - printgroups(csound, grpcnt); - return grpcnt; -} - -static void resetouts(CSOUND *csound) -{ - csound->acount = csound->kcount = csound->icount = 0; - csound->Bcount = csound->bcount = 0; -} - -TEXT *getoptxt(CSOUND *csound, int *init) -{ /* get opcod and args from current line */ - /* returns pntr to a TEXT struct */ - TEXT *tp; - char c, d, str[64], *s; - int nn, incnt, outcnt; - - if (*init) { - ST(grpcnt) = 0; - ST(nxtest) = 1; - ST(xprtstno) = 0; - ST(polcnt) = 0; - ST(instrblk) = 0; - ST(opcodblk) = 0; /* IV - Sep 8 2002 */ - ST(instrcnt) = 0; - *init = 0; - memset(&ST(optext), 0, sizeof(TEXT)); - } - - tstnxt: - tp = &ST(optext); - if (ST(nxtest) >= ST(grpcnt)) { /* if done with prevline, */ - csound->argcnt_offs = 0; /* reset temporary variable index */ - if (!(ST(grpcnt) = splitline(csound))) { /* attack next line */ - /* end of orchestra, clean up */ - mfree(csound, ST(linadr)); ST(linadr) = NULL; - mfree(csound, ST(ortext)); ST(ortext) = NULL; - mfree(csound, ST(collectbuf)); ST(collectbuf) = NULL; - mfree(csound, ST(group)); ST(group) = NULL; - mfree(csound, ST(grpsav)); ST(grpsav) = NULL; - mfree(csound, csound->tokens); csound->tokens = NULL; - mfree(csound, csound->tokenlist); csound->tokenlist = NULL; - mfree(csound, csound->tokenstring); csound->tokenstring = NULL; - mfree(csound, csound->polish); csound->polish = NULL; - csound->token = NULL; - return (TEXT*) NULL; /* (else we're done) */ - } - for (nn=0; nnlinenum = ST(curline); - /* IV - Jan 27 2005 */ - if (csound->oparms->expr_opt) { - int i = (int) ST(linlabels) + 1; - if (((int) ST(grpcnt) - i) > 0 && ST(group)[i][0] == '=' && - ST(group)[i][1] == '\0') { - /* if opcode is '=', save outarg and type for expression optimiser */ - csound->opcode_is_assign = 1; - csound->assign_type = (int) argtyp(csound, ST(group)[ST(linlabels)]); - csound->assign_outarg = strsav_string(csound, - ST(group)[ST(linlabels)]); - } - else { - csound->opcode_is_assign = csound->assign_type = 0; - csound->assign_outarg = NULL; - } - } - } - if (ST(linlabels)) { - s = strsav_string(csound, ST(group)[ST(nxtest)]); - lblfound(csound, s); - tp->opnum = LABEL; - tp->opcod = s; - tp->inlist = tp->outlist = ST(nullist); - ST(linlabels)--; - ST(nxtest)++; - return(tp); - } - if (!ST(instrcnt)) { /* send initial "instr 0" */ - tp->opnum = INSTR; - tp->opcod = strsav_string(csound, "instr"); /* to hold global assigns */ - tp->outlist = ST(nullist); - ST(nxtarglist)->count = 1; - ST(nxtarglist)->arg[0] = strsav_string(csound, "0"); - tp->inlist = copy_arglist(csound, ST(nxtarglist)); - ST(instrcnt) = ST(instrblk) = 1; - return(tp); - } /* then at 1st real INSTR, */ - /* or OPCODE, */ - if (ST(instrcnt) == 1 && ST(instrblk) && - (ST(opnum) == INSTR || ST(opnum) == OPCODE)) { - tp->opnum = ENDIN; /* send an endin to */ - tp->opcod = strsav_string(csound, "endin"); /* term instr 0 blk */ - tp->outlist = tp->inlist = ST(nullist); - ST(instrblk) = 0; - ST(instrcnt) = 2; - return(tp); - } - while (ST(xprtstno) >= 0) { /* for each arg (last 1st): */ - if (!ST(polcnt)) { - /* if not midst of expressn: tst nxtarg */ - ST(polcnt) = express(csound, ST(group)[ST(xprtstno)--]); - /* IV - Feb 06 2006: if there is an if/then with an unknown rate: */ - if (ST(polcnt) > 0 && ST(iflabels) != NULL && ST(iflabels)->ithen < 0) { - char tmp; - /* check the output type of the expression (FIXME: is this safe ?) */ - /* if it is an i-rate conditional, set ithen flag for else/elseif */ - tmp = argtyp(csound, csound->tokenlist[0]->str); - if (tmp == (char) 'b') - ST(iflabels)->ithen = 1; - else - ST(iflabels)->ithen = 0; - } - } - if (ST(polcnt) < 0) { - /* polish but arg only: redo ptr & contin */ - ST(group)[ST(xprtstno)+1] = strsav_string(csound, csound->tokenstring); - ST(polcnt) = 0; - } - else if (ST(polcnt)) { - POLISH *pol; /* for real polish ops, */ - int n; - pol = &(csound->polish[--ST(polcnt)]); /* grab top one */ - if (UNLIKELY(isopcod(csound, pol->opcod) == 0)) { /* and check it out */ - synterr(csound, Str("illegal opcod from expr anal")); - goto tstnxt; - } - tp->opnum = ST(opnum); /* ok to send subop */ - tp->opcod = strsav_string(csound, ST(opcod)); - ST(nxtarglist)->count = outcnt = 1; - ST(nxtarglist)->arg[0] = strsav_string(csound, pol->arg[0]); - tp->outlist = copy_arglist(csound, ST(nxtarglist)); - n = ST(nxtarglist)->count = incnt = pol->incount; - do ST(nxtarglist)->arg[n-1] = strsav_string(csound, pol->arg[n]); - while (--n); - tp->inlist = copy_arglist(csound, ST(nxtarglist)); - if (!ST(polcnt)) /* last op? hit the grp ptr */ - ST(group)[ST(xprtstno)+1] = tp->outlist->arg[0]; - goto spctst; - } - } - if (!strcmp(ST(linopcod), "=")) { /* IV - Jan 08 2003: '=' opcode */ - if (csound->oparms->expr_opt && csound->opcode_is_assign < 0) { - /* if optimised away, skip line */ - ST(nxtest) = ST(grpcnt); goto tstnxt; - } - if (ST(nxtest) < ST(opgrpno)) { - c = argtyp(csound, ST(group)[ST(nxtest)]); - switch (c) { - case 'S': strcpy(str, "strcpy"); break; - case 'a': c = argtyp(csound, ST(group)[ST(opgrpno)]); - strcpy(str, (c == 'a' ? "=.a" : "upsamp")); break; - case 'p': c = 'i'; - default: sprintf(str, "=.%c", c); - } - if (UNLIKELY(!(isopcod(csound, str)))) { - synterr(csound, - Str("failed to find %s, output arg '%s' illegal type"), - str, ST(group)[ST(nxtest)]); /* report syntax error */ - ST(nxtest) = 100; /* step way over this line */ - goto tstnxt; /* & go to next */ - } - if (strcmp(ST(group)[ST(nxtest)], ST(group)[ST(opgrpno)]) == 0) { - /* outarg same as inarg, skip line */ - ST(nxtest) = ST(grpcnt); goto tstnxt; - } - ST(linopnum) = ST(opnum); - ST(linopcod) = ST(opcod); - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod)); - } - } - else if (ST(nxtest) < ST(opgrpno) && /* Some aopcodes do not have ans! */ - csound->opcodlst[ST(linopnum)].dsblksiz == 0xffff) { - /* use outype to modify some opcodes flagged as translating */ - c = argtyp(csound, ST(group)[ST(nxtest)]); - if (c == 'p') c = 'i'; - if (c == '?') c = 'a'; /* tmp */ - sprintf(str, "%s.%c", ST(linopcod), c); - if (UNLIKELY(!(isopcod(csound, str)))) { - synterr(csound, Str("failed to find %s, output arg '%s' illegal type"), - str, ST(group)[ST(nxtest)]); /* report syntax error */ - ST(nxtest) = 100; /* step way over this line */ - goto tstnxt; /* & go to next */ - } - ST(linopnum) = ST(opnum); - ST(linopcod) = ST(opcod); - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod)); - } - else if ((int) csound->opcodlst[ST(linopnum)].dsblksiz >= 0xfffb) { - c = argtyp(csound, ST(group)[ST(opgrpno)]); /* type of first input arg */ - switch ((int) csound->opcodlst[ST(linopnum)].dsblksiz) { - case 0xfffe: /* Two tags for OSCIL's */ - if (c != 'a') c = 'k'; - if ((d = argtyp(csound, ST(group)[ST(opgrpno)+1])) != 'a') d = 'k'; - sprintf(str, "%s.%c%c", ST(linopcod), c, d); - break; - case 0xfffd: /* For peak, etc. */ - if (c != 'a') c = 'k'; - sprintf(str, "%s.%c", ST(linopcod), c); - break; - case 0xfffc: /* For divz types */ - d = argtyp(csound, ST(group)[ST(opgrpno)+1]); - if ((c=='i' || c=='c') && (d=='i' || d=='c')) - c = 'i', d = 'i'; - else { - if (c != 'a') c = 'k'; - if (d != 'a') d = 'k'; - } - sprintf(str, "%s.%c%c", ST(linopcod), c, d); - break; - case 0xfffb: /* determine opcode by type of first input arg */ - /* allows a, k, and i types (e.g. Inc, Dec), but not constants */ - if (ST(typemask_tabl)[(unsigned char) c] & (ARGTYP_i | ARGTYP_p)) - c = 'i'; - sprintf(str, "%s.%c", ST(linopcod), c); - break; - default: - strcpy(str, ST(linopcod)); /* unknown code: use original opcode */ - } - if (UNLIKELY(!(isopcod(csound, str)))) { - /* if opcode is not found: report syntax error */ - synterr(csound, Str("failed to find %s, input arg illegal type"), str); - ST(nxtest) = 100; /* step way over this line */ - goto tstnxt; /* & go to next */ - } - ST(linopnum) = ST(opnum); - ST(linopcod) = ST(opcod); - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod)); - } - tp->opnum = ST(linopnum); /* now use identified */ - tp->opcod = strsav_string(csound, ST(linopcod)); /* full line opcode */ - /* IV - Oct 24 2002: check for invalid use of setksmps */ - if (strcmp(ST(linopcod), "setksmps") == 0) { - if (UNLIKELY(!ST(opcodblk))) - synterr(csound, - Str("setksmps is allowed only in user defined opcodes")); - else if (UNLIKELY((int) ST(opcodflg) & 4)) - synterr(csound, - Str("multiple uses of setksmps in the same opcode definition")); - else - ST(opcodflg) |= (int16) 4; - } -#if 0 - /* NO LONGER USED */ - if (strncmp(ST(linopcod),"out",3) == 0 && /* but take case of MIDI ops */ - (ST(linopcod)[3] == '\0' || ST(linopcod)[3] == 's' || - ST(linopcod)[3] == 'q' || ST(linopcod)[3] == 'h' || - ST(linopcod)[3] == 'o' || ST(linopcod)[3] == 'x' || - ST(linopcod)[3] == '3' )) - if ((csound->tran_nchnls == 1 && strcmp(ST(linopcod),"out" ) != 0) || - (csound->tran_nchnls == 2 && strncmp(ST(linopcod),"outs",4) != 0) || - (csound->tran_nchnls == 4 && strncmp(ST(linopcod),"outq",4) != 0) || - (csound->tran_nchnls == 6 && strncmp(ST(linopcod),"outh",4) != 0) || - (csound->tran_nchnls == 8 && strncmp(ST(linopcod),"outo",4) != 0) || - (csound->tran_nchnls == 16 && strncmp(ST(linopcod),"outx",4) != 0) || - (csound->tran_nchnls == 32 && strncmp(ST(linopcod),"out32",5) != 0)) { - if (csound->tran_nchnls == 1) isopcod(csound, "out"); - else if (csound->tran_nchnls == 2) isopcod(csound, "outs"); - else if (csound->tran_nchnls == 4) isopcod(csound, "outq"); - else if (csound->tran_nchnls == 6) isopcod(csound, "outh"); - else if (csound->tran_nchnls == 8) isopcod(csound, "outo"); - else if (csound->tran_nchnls == 16) isopcod(csound, "outx"); - else if (csound->tran_nchnls == 32) isopcod(csound, "out32"); - csound->Message(csound, Str("%s inconsistent with global nchnls (%d); " - "replaced with %s\n"), - ST(linopcod), csound->tran_nchnls, ST(opcod)); - tp->opnum = ST(linopnum) = ST(opnum); - tp->opcod = strsav_string(csound, ST(linopcod) = ST(opcod)); - } -#endif - incnt = outcnt = 0; - while (ST(nxtest) < ST(opgrpno)-1) /* create the out arglist */ - ST(nxtarglist)->arg[outcnt++] = - strsav_string(csound, ST(group)[ST(nxtest)++]); - ST(nxtarglist)->count = outcnt; - if (outcnt == 0) - tp->outlist = ST(nullist); - else { - tp->outlist = copy_arglist(csound, ST(nxtarglist)); /* & prep ins */ - } - ST(nxtest)++; - while (ST(nxtest) < ST(grpcnt)) /* & ensuing inargs */ - ST(nxtarglist)->arg[incnt++] = - strsav_string(csound, ST(group)[ST(nxtest)++]); - ST(nxtarglist)->count = incnt; - if (incnt==0) - tp->inlist = ST(nullist); - else tp->inlist = copy_arglist(csound, ST(nxtarglist)); - ST(grpcnt) = 0; /* all done w. these groups */ - - spctst: - tp->xincod_str = tp->xincod = 0; - if (tp->opnum == OPCODE) { /* IV - Sep 8 2002: added OPCODE and ENDOP */ - if (UNLIKELY(ST(opcodblk))) - synterr(csound, Str("opcode blks cannot be nested (missing 'endop'?)")); - else if (UNLIKELY(ST(instrblk))) - synterr(csound, Str("opcode not allowed in instr block")); - else ST(instrblk) = ST(opcodblk) = 1; - ST(opcodflg) = 0; - resetouts(csound); /* reset #out counts */ - lblclear(csound); /* restart labelist */ - } - else if (tp->opnum == ENDOP) { /* IV - Sep 8 2002: ENDOP: */ - lblchk(csound); /* chk missed labels */ - if (UNLIKELY(!ST(instrblk))) - synterr(csound, Str("unmatched endop")); - else if (UNLIKELY(!ST(opcodblk))) - synterr(csound, Str("endop not allowed in instr block")); - else ST(instrblk) = ST(opcodblk) = 0; - } - else if (tp->opnum == INSTR) { /* IV - Sep 8 2002: for opcod INSTR */ - if (UNLIKELY(ST(opcodblk))) /* IV - Sep 8 2002 */ - synterr(csound, Str("instr not allowed in opcode block")); - else if (UNLIKELY(ST(instrblk))) - synterr(csound, - Str("instr blocks cannot be nested (missing 'endin'?)")); - else ST(instrblk) = 1; - resetouts(csound); /* reset #out counts */ - lblclear(csound); /* restart labelist */ - } - else if (tp->opnum == ENDIN) { /* ENDIN: */ - lblchk(csound); /* chk missed labels */ - if (UNLIKELY(ST(opcodblk))) - synterr(csound, Str("endin not allowed in opcode blk")); - else if (UNLIKELY(!ST(instrblk))) - synterr(csound, Str("unmatched endin")); - else ST(instrblk) = 0; - } - else { /* for all other opcodes: */ - OENTRY *ep = csound->opcodlst + tp->opnum; - int n, nreqd; - char tfound = '\0', treqd, *types = NULL; - char xtypes[OPCODENUMOUTS_MAX + 1]; /* IV - Oct 24 2002 */ - - if (UNLIKELY(!ST(instrblk))) - synterr(csound, Str("misplaced opcode")); - /* IV - Oct 24 2002: moved argument parsing for xout here */ - n = incnt; - nreqd = -1; - if (!strcmp(ep->opname, "xout")) { - if (UNLIKELY(!ST(opcodblk))) - synterr(csound, Str("xout is allowed only in user defined opcodes")); - else if (UNLIKELY((int) ST(opcodflg) & 2)) - synterr(csound, - Str("multiple uses of xout in the same opcode definition")); - else { - /* IV - Oct 24 2002: opcodeInfo always points to the most recently */ - /* defined user opcode (or named instrument) structure; in this */ - /* case, it is the current opcode definition (not very elegant, */ - /* but works) */ - char *c = csound->opcodeInfo->outtypes; - int i = 0; - ST(opcodflg) |= (int16) 2; - nreqd = csound->opcodeInfo->outchns; - /* replace opcode if needed */ - if (nreqd > OPCODENUMOUTS_LOW) { - if (nreqd > OPCODENUMOUTS_HIGH) - isopcod(csound, ".xout256"); - else - isopcod(csound, ".xout64"); - ST(linopcod) = ST(opcod); - ST(linopnum) = ST(opnum); - tp->opcod = strsav_string(csound, ST(linopcod)); - tp->opnum = ST(linopnum); - ep = csound->opcodlst + tp->opnum; - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod)); - } - while (c[i]) { - switch (c[i]) { - case 'a': - case 'k': - case 'f': - case 'i': xtypes[i] = c[i]; break; - case 'K': xtypes[i] = 'k'; - } - i++; - } - xtypes[i] = '\0'; - types = &xtypes[0]; - } - } - if (nreqd < 0) /* for other opcodes */ - nreqd = strlen(types = ep->intypes); - if (n > nreqd) { /* IV - Oct 24 2002: end of new code */ - if ((treqd = types[nreqd-1]) == 'n') { /* indef args: */ - if (UNLIKELY(!(incnt & 01))) /* require odd */ - synterr(csound, Str("missing or extra arg")); - } /* IV - Sep 1 2002: added 'M' */ - else if (UNLIKELY(treqd != 'm' && treqd != 'z' && treqd != 'y' && - treqd != 'Z' && treqd != 'M' && - treqd != 'N')) /* else any no */ - synterr(csound, Str("too many input args")); - } - else if (incnt < nreqd) { /* or set defaults: */ - do { - switch (types[incnt]) { - case 'O': /* Will this work? Doubtful code.... */ - case 'o': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, "0"); - break; - case 'P': - case 'p': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, "1"); - break; - case 'q': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, "10"); - break; - case 'V': - case 'v': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, ".5"); - break; - case 'h': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, "127"); - break; - case 'J': - case 'j': ST(nxtarglist)->arg[incnt++] = strsav_string(csound, "-1"); - break; - case 'F': - case 'M': - case 'N': - case 'm': nreqd--; - break; - default: synterr(csound, Str("insufficient required arguments")); - goto chkin; - } - } while (incnt < nreqd); - ST(nxtarglist)->count = n = incnt; /* in extra space */ - if (tp->inlist == ST(nullist) && incnt > 0) { - /*MWB 2/11/97 fixed bug that prevented an - opcode with only optional arguments from - properly loading defaults */ - tp->inlist = copy_arglist(csound, ST(nxtarglist)); - } - } - chkin: - if (n>tp->inlist->count) { - int i; - size_t m = sizeof(ARGLST) + (n - 1) * sizeof(char*); - tp->inlist = (ARGLST*) mrealloc(csound, tp->inlist, m); - for (i=tp->inlist->count; iinlist->arg[i] = ST(nxtarglist)->arg[i]; - } - tp->inlist->count = n; - } - while (n--) { /* inargs: */ - int32 tfound_m, treqd_m = 0L; - s = tp->inlist->arg[n]; - if (n >= nreqd) { /* det type required */ - switch (types[nreqd-1]) { - case 'M': - case 'N': - case 'Z': - case 'y': - case 'z': treqd = types[nreqd-1]; break; - default: treqd = 'i'; /* (indef in-type) */ - } - } - else treqd = types[n]; /* or given) */ - if (treqd == 'l') { /* if arg takes lbl */ - csound->DebugMsg(csound, "treqd = l"); - lblrequest(csound, s); /* req a search */ - continue; /* chk it later */ - } - tfound = argtyp(csound, s); /* else get arg type */ - /* IV - Oct 31 2002 */ - - tfound_m = ST(typemask_tabl)[(unsigned char) tfound]; - if (UNLIKELY(!(tfound_m & (ARGTYP_c|ARGTYP_p)) && - !ST(lgprevdef) && *s != '"')) { - synterr(csound, Str("input arg '%s' used before defined \n"), s); - } - csound->DebugMsg(csound, "treqd %c, tfound %c", treqd, tfound); - if (tfound == 'a' && n < 31) /* JMC added for FOG */ - /* 4 for FOF, 8 for FOG; expanded to 15 */ - tp->xincod |= (1 << n); - if (tfound == 'S' && n < 31) - tp->xincod_str |= (1 << n); - /* IV - Oct 31 2002: simplified code */ - if (!(tfound_m & ST(typemask_tabl_in)[(unsigned char) treqd])) { - /* check for exceptional types */ - switch (treqd) { - case 'I': - treqd_m = ARGTYP_i; - break; - case 'Z': /* indef kakaka ... */ - if (UNLIKELY(!(tfound_m & (n & 1 ? ARGTYP_a : ARGTYP_ipcrk)))) - intyperr(csound, n, tfound, treqd); - break; - case 'x': - treqd_m = ARGTYP_ipcr; /* also allows i-rate */ - case 's': /* a- or k-rate */ - treqd_m |= ARGTYP_a | ARGTYP_k; - if (tfound_m & treqd_m) { - if (tfound == 'a' && tp->outlist != ST(nullist)) { - int32 outyp_m = /* ??? */ - ST(typemask_tabl)[(unsigned char) argtyp(csound, - tp->outlist->arg[0])]; - if (outyp_m & (ARGTYP_a | ARGTYP_w | ARGTYP_f)) break; - } - else - break; - } - default: - intyperr(csound, n, tfound, treqd); - break; - } - } - } - csound->DebugMsg(csound, "xincod = %d", tp->xincod); - /* IV - Sep 1 2002: added 'X' type, and xoutcod */ - tp->xoutcod_str = tp->xoutcod = 0; - /* IV - Oct 24 2002: moved argument parsing for xin here */ - n = outcnt; - nreqd = -1; - if (!strcmp(ep->opname, "xin")) { - if (UNLIKELY(!ST(opcodblk))) - synterr(csound, Str("xin is allowed only in user defined opcodes")); - else if (UNLIKELY((int) ST(opcodflg) & 1)) - synterr(csound, - Str("multiple uses of xin in the same opcode definition")); - else { - /* IV - Oct 24 2002: opcodeInfo always points to the most recently */ - /* defined user opcode (or named instrument) structure; in this */ - /* case, it is the current opcode definition (not very elegant, */ - /* but works) */ - char *c = csound->opcodeInfo->intypes; - int i = 0; - ST(opcodflg) |= (int16) 1; - nreqd = csound->opcodeInfo->inchns; - /* replace opcode if needed */ - if (nreqd > OPCODENUMOUTS_LOW) { - if (nreqd > OPCODENUMOUTS_HIGH) - isopcod(csound, ".xin256"); - else - isopcod(csound, ".xin64"); - ST(linopcod) = ST(opcod); - ST(linopnum) = ST(opnum); - tp->opcod = strsav_string(csound, ST(linopcod)); - tp->opnum = ST(linopnum); - ep = csound->opcodlst + tp->opnum; - csound->DebugMsg(csound, Str("modified opcod: %s"), ST(opcod)); - } - while (c[i]) { - switch (c[i]) { - case 'a': xtypes[i] = c[i]; break; - case 'f': xtypes[i] = c[i]; break; - case 'k': - case 'P': - case 'K': xtypes[i] = 'k'; break; - case 'S': xtypes[i] = 'S'; break; - default: xtypes[i] = 'i'; - } - i++; - } - xtypes[i] = '\0'; - types = &xtypes[0]; - } - } - if (nreqd < 0) /* for other opcodes */ - nreqd = strlen(types = ep->outypes); - if (UNLIKELY((n != nreqd) && /* IV - Oct 24 2002: end of new code */ - !(n > 0 && n < nreqd && - (types[n] == 'm' || types[n] == 'z' || types[n] == 'I' || - types[n] == 'X' || types[n] == 'N' || types[n] == 'F')))) { - synterr(csound, Str("illegal no of output args")); - if (n > nreqd) - n = nreqd; - } - while (n--) { /* outargs: */ - int32 tfound_m; /* IV - Oct 31 2002 */ - s = tp->outlist->arg[n]; - treqd = types[n]; - tfound = argtyp(csound, s); /* found */ - /* IV - Oct 31 2002 */ - tfound_m = ST(typemask_tabl)[(unsigned char) tfound]; - /* IV - Sep 1 2002: xoutcod is the same as xincod for input */ - if (tfound == 'a' && n < 31) - tp->xoutcod |= (1 << n); - if (tfound == 'S' && n < 31) - tp->xoutcod_str |= (1 << n); - csound->DebugMsg(csound, "treqd %c, tfound %c", treqd, tfound); - if (tfound_m & ARGTYP_w) - if (UNLIKELY(ST(lgprevdef))) { - synterr(csound, Str("output name previously used, " - "type '%c' must be uniquely defined"), tfound); - } - /* IV - Oct 31 2002: simplified code */ - if (UNLIKELY(!(tfound_m & ST(typemask_tabl_out)[(unsigned char) treqd]))) { - synterr(csound, Str("output arg '%s' illegal type"), s); - } - } - if (incnt) { - if (ep->intypes[0] != 'l') /* intype defined by 1st inarg */ - tp->intype = argtyp(csound, tp->inlist->arg[0]); - else tp->intype = 'l'; /* (unless label) */ - } - if (outcnt) /* pftype defined by outarg */ - tp->pftype = tfound; - else tp->pftype = tp->intype; /* else by 1st inarg */ - } - return(tp); /* return the text blk */ -} - -static void intyperr(CSOUND *csound, int n, char tfound, char expect) -{ - char *s = ST(grpsav)[ST(opgrpno) + n]; - char t[10]; - - switch (tfound) { - case 'w': - case 'f': - case 'a': - case 'k': - case 'i': - case 'P': - case 'p': t[0] = tfound; - t[1] = '\0'; - break; - case 'r': - case 'c': strcpy(t,"const"); - break; - case 'S': strcpy(t,"string"); - break; - case 'b': - case 'B': strcpy(t,"boolean"); - break; - case '?': strcpy(t,"?"); - break; - } - synterr(csound, Str("input arg '%s' of type %s " - "not allowed when expecting %c"), s, t, expect); -} - -static int isopcod(CSOUND *csound, char *s) -{ /* tst a string against opcodlst */ - int n; /* & set op carriers if matched */ - - if (!(n = find_opcode(csound, s))) return (0); /* IV - Oct 31 2002 */ - ST(opnum) = n; /* on corr match, */ - ST(opcod) = csound->opcodlst[n].opname; /* set op carriers */ - - return(1); /* & report success */ -} - -static int pnum(char *s) /* check a char string for pnum format */ -/* and return the pnum ( >= 0 ) */ -{ /* else return -1 */ - int n; - - if (*s == 'p' || *s == 'P') - if (sscanf(++s, "%d", &n)) - return(n); - return(-1); -} - -char argtyp(CSOUND *csound, char *s) -{ /* find arg type: d, w, a, k, i, c, p, r, S, B, b */ - char c = *s; /* also set lgprevdef if !c && !p && !S */ - - - /*trap this before parsing for a number! */ - /* two situations: defined at header level: 0dbfs = 1.0 - * and returned as a value: idb = 0dbfs - */ - if ((c >= '1' && c <= '9') || c == '.' || c == '-' || c == '+' || - (c == '0' && strcmp(s, "0dbfs") != 0)) - return('c'); /* const */ - if (pnum(s) >= 0) - return('p'); /* pnum */ - if (c == '"') - return('S'); /* quoted String */ - ST(lgprevdef) = lgexist(csound, s); /* (lgprev) */ - if (strcmp(s,"sr") == 0 || strcmp(s,"kr") == 0 || - strcmp(s,"0dbfs") == 0 || strcmp(s,"nchnls_i") == 0 || - strcmp(s,"ksmps") == 0 || strcmp(s,"nchnls") == 0) - return('r'); /* rsvd */ - if (c == 'w') /* N.B. w NOT YET #TYPE OR GLOBAL */ - return(c); - if (c == '#') - c = *(++s); - if (c == 'g') - c = *(++s); - if (strchr("akiBbfS", c) != NULL) - return(c); - else return('?'); -} - -static void lblclear(CSOUND *csound) -{ - ST(lblcnt) = 0; -} - -static void lblrequest(CSOUND *csound, char *s) -{ - int req; - - for (req=0; req= ST(lblmax)) { - LBLREQ *tmp; - ST(lblmax) += LBLMAX; - tmp = mrealloc(csound, ST(lblreq), ST(lblmax) * sizeof(LBLREQ)); - ST(lblreq) = tmp; - } - ST(lblreq)[req].reqline = ST(curline); - ST(lblreq)[req].label =s; -} - -static void lblfound(CSOUND *csound, char *s) -{ - int req; - - for (req=0; req= ST(lblmax)) { - LBLREQ *tmp; - ST(lblmax) += LBLMAX; - tmp = mrealloc(csound, ST(lblreq), ST(lblmax) * sizeof(LBLREQ)); - ST(lblreq) = tmp; - } - ST(lblreq)[req].label = s; - noprob: - ST(lblreq)[req].reqline = 0; -} - -static void lblchk(CSOUND *csound) -{ - int req; - int n; - - for (req=0; reqMessage(csound, Str("error line %d. unknown label:\n"), n); - s = ST(linadr)[n]; - do { - csound->Message(csound, "%c", *s); - } while (*s++ != '\n'); - csound->synterrcnt++; - } -} - -void synterr(CSOUND *csound, const char *s, ...) -{ - va_list args; - - csound->MessageS(csound, CSOUNDMSG_ERROR, Str("error: ")); - va_start(args, s); - csound->MessageV(csound, CSOUNDMSG_ERROR, s, args); - va_end(args); - - - /* FIXME - Removed temporarily for debugging - * This function may not be necessary at all in the end if some of this is - * done in the parser - */ -#ifdef never - if (ST(linadr) != NULL && (cp = ST(linadr)[ST(curline)]) != NULL -#if defined(ENABLE_NEW_PARSER) - && !csound->oparms->newParser -#endif - ) { - csound->MessageS(csound, CSOUNDMSG_ERROR, - Str(", line %d:\n"), CURLINE); - do { - csound->MessageS(csound, CSOUNDMSG_ERROR, "%c", (c = *cp++)); - } while (c != '\n'); - } - else { - csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); - } -#endif - csound->synterrcnt++; -} - -static void synterrp(CSOUND *csound, const char *errp, char *s) -{ - char *cp; - - synterr(csound, s); - cp = ST(linadr)[ST(curline)]; - while (cp < errp) { - int ch = *cp++; - if (ch != '\t') ch = ' '; - csound->MessageS(csound, CSOUNDMSG_ERROR, "%c", ch); - } - csound->ErrorMsg(csound, "^"); -} - -static void lexerr(CSOUND *csound, const char *s, ...) -{ - IN_STACK *curr = ST(str); - va_list args; - - va_start(args, s); - csound->ErrMsgV(csound, Str("error: "), s, args); - va_end(args); - - while (curr != ST(inputs)) { - if (curr->string) { - MACRO *mm = ST(macros); - while (mm != curr->mac) mm = mm->next; - csound->ErrorMsg(csound, Str("called from line %d of macro %s"), - curr->line, mm->name); - } - else { - csound->ErrorMsg(csound, Str("in line %d of file input %s"), - curr->line, curr->body); - } - curr--; - } - csound->LongJmp(csound, 1); -} - -static void printgroups(CSOUND *csound, int grpcnt) -{ /* debugging aid (onto stdout) */ - char c, *cp = ST(group)[0]; - - csound->Message(csound, "groups:\t"); - while (grpcnt--) { - csound->Message(csound, "%s ", cp); - while ((c = *cp++)); - } - csound->Message(csound, "\n"); -} diff -Nru csound-5.17.11~dfsg/Engine/rdscor.c csound-6.02~dfsg/Engine/rdscor.c --- csound-5.17.11~dfsg/Engine/rdscor.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/rdscor.c 2014-01-07 16:54:20.000000000 +0000 @@ -24,6 +24,19 @@ #include "csoundCore.h" /* RDSCORSTR.C */ #include "corfile.h" +char* get_arg_string(CSOUND *csound, MYFLT p) +{ + int32 n; + char *ss = csound->ids->insdshead->strarg; /* look at this instr's strarg */ + union { + MYFLT d; + int32 i; + } ch; + ch.d = p; n = ch.i&0xffff; + while (n-- > 0) ss += strlen(ss)+1; + return ss; +} + static void dumpline(CSOUND *); static void flushline(CSOUND *csound) /* flush scorefile to next newline */ @@ -46,32 +59,32 @@ } if (c == '"') { /* if find a quoted string */ char *sstrp; - if (csound->scnt0==0) { - if ((sstrp = csound->sstrbuf) == NULL) - sstrp = csound->sstrbuf = mmalloc(csound, SSTRSIZ); - while ((c = corfile_getc(csound->scstr)) != '"') { - if (c=='\\') c = corfile_getc(csound->scstr); - *sstrp++ = c; + int n = csound->scnt; + if ((sstrp = csound->sstrbuf) == NULL) + sstrp = csound->sstrbuf = mmalloc(csound, csound->strsiz=SSTRSIZ); + while (n--!=0) sstrp += strlen(sstrp)+1; + n = sstrp-csound->sstrbuf; + while ((c = corfile_getc(csound->scstr)) != '"') { + //if (c=='\\') c = corfile_getc(csound->scstr); + *sstrp++ = c; + n++; + if (n > csound->strsiz-10) { + csound->sstrbuf = mrealloc(csound, csound->sstrbuf, + csound->strsiz+=SSTRSIZ); + sstrp = csound->sstrbuf+n; } - *sstrp++ = '\0'; - *pfld = SSTRCOD; /* flag with hifloat */ - csound->sstrlen = sstrp - csound->sstrbuf; /* & overall length */ } - else { - int n = csound->scnt0; - printf("***Entering dubious code; n=%d\n", n); - if ((sstrp = csound->sstrbuf0[n]) == NULL) - sstrp = csound->sstrbuf0[n] = mmalloc(csound, SSTRSIZ); - while ((c = corfile_getc(csound->scstr)) != '"') { - if (c=='\\') c = corfile_getc(csound->scstr); - *sstrp++ = c; - } - *sstrp++ = '\0'; - *pfld = ((int[4]){SSTRCOD,SSTRCOD1,SSTRCOD2,SSTRCOD3})[n]; /* flag with hifloat */ - /* Net line is wrong*/ - csound->sstrlen0[n] = sstrp - csound->sstrbuf0[n]; /* & overall length */ + *sstrp++ = '\0'; + { + union { + MYFLT d; + int32 i; + } ch; + ch.d = SSTRCOD; ch.i += csound->scnt++; + *pfld = ch.d; /* set as string with count */ } - csound->scnt0++; + csound->sstrlen = sstrp - csound->sstrbuf; /* & overall length */ + //printf("csound->sstrlen = %d\n", csound->sstrlen); return(1); } if (UNLIKELY(!((c>='0' && c<='9') || c=='+' || c=='-' || c=='.'))) { @@ -105,12 +118,10 @@ { /* presumes good format if warped */ MYFLT *pp, *plim; int c; + e->pinstance = NULL; if (csound->scstr == NULL || csound->scstr->body[0] == '\0') { /* if no concurrent scorefile */ -#ifdef BETA - csound->Message(csound, "THIS SHOULD NOT HAPPEN -- CONTACT jpff"); -#endif e->opcod = 'f'; /* return an 'f 0 3600' */ e->p[1] = FL(0.0); e->p[2] = FL(INF); @@ -118,8 +129,9 @@ e->pcnt = 2; return(1); } - while ((c = corfile_getc(csound->scstr)) != '\0') { /* else read the real score */ - csound->scnt0 = 0; + /* else read the real score */ + while ((c = corfile_getc(csound->scstr)) != '\0') { + csound->scnt = 0; switch (c) { case ' ': case '\t': @@ -134,7 +146,7 @@ goto unwarped; case 'w': csound->warped = 1; /* w statement is itself unwarped */ - unwarped: e->opcod = c; /* UNWARPED scorefile: */ + unwarped: e->opcod = c; /* UNWARPED scorefile: */ pp = &e->p[0]; plim = &e->p[PMAX]; /* caution, irregular format */ while (1) { @@ -142,7 +154,7 @@ c=='\t'); /* eat whitespace */ if (c == ';') { flushline(csound); break; } /* comments? skip */ if (c == '\n' || c == '\0') break; /* newline? done */ - corfile_ungetc(csound->scstr); /* pfld: back up */ + corfile_ungetc(csound->scstr); /* pfld: back up */ if (!scanflt(csound, ++pp)) break; /* & read value */ if (UNLIKELY(pp >= plim)) { csound->Message(csound, Str("ERROR: too many pfields: ")); @@ -157,6 +169,7 @@ case 'e': e->opcod = c; e->pcnt = 0; + return(1); case EOF: /* necessary for cscoreGetEvent */ return(0); @@ -181,49 +194,62 @@ scanflt(csound, ++pp)) /* p4.... */ if (pp >= plim) { + MYFLT *new; MYFLT *q; int c=1; csound->DebugMsg(csound, "Extra p-fields (%d %d %d %d)\n", - (int)e->p[1],(int)e->p[2], - (int)e->p[3],(int)e->p[4]); - e->c.extra = (MYFLT*)realloc(e->c.extra,sizeof(MYFLT)*PMAX); + (int)e->p[1],(int)e->p[2], + (int)e->p[3],(int)e->p[4]); + new = (MYFLT*)realloc(e->c.extra,sizeof(MYFLT)*PMAX); + if (new==NULL) { + fprintf(stderr, "Out of Mdemory\n"); + exit(7); + } + e->c.extra = new; e->c.extra[0] = PMAX-2; q = e->c.extra; while ((corfile_getc(csound->scstr) != '\n') && (scanflt(csound, &q[c++]))) { if (c > (int) e->c.extra[0]) { - csound->DebugMsg(csound, "and more extra p-fields [%d](%d)%d\n", - c, (int) e->c.extra[0], - sizeof(MYFLT)*((int)e->c.extra[0]+PMAX) ); - q = e->c.extra = + csound->DebugMsg(csound, + "and more extra p-fields [%d](%d)%d\n", + c, (int) e->c.extra[0], + sizeof(MYFLT)*((int)e->c.extra[0]+PMAX)); + new = (MYFLT *)realloc(e->c.extra, - sizeof(MYFLT)*((int) e->c.extra[0]+PMAX)); + sizeof(MYFLT)*((int) e->c.extra[0]+ + PMAX)); + if (new==NULL) { + fprintf(stderr, "Out of Mdemory\n"); + exit(7); + } + q = e->c.extra = new; e->c.extra[0] = e->c.extra[0]+PMAX-1; } } e->c.extra[0] = c; /* flushline(csound); */ - goto setp; + goto setp; } setp: if (!csound->csoundIsScorePending_ && e->opcod == 'i') { /* FIXME: should pause and not mute */ csound->sstrlen = 0; - e->opcod = 'f'; e->p[1] = FL(0.0); e->pcnt = 2; + e->opcod = 'f'; e->p[1] = FL(0.0); e->pcnt = 2; e->scnt = 0; return 1; } e->pcnt = pp - &e->p[0]; /* count the pfields */ if (e->pcnt>=PMAX) e->pcnt += e->c.extra[0]; /* and overflow fields */ if (csound->sstrlen) { /* if string arg present, save it */ e->strarg = mmalloc(csound, csound->sstrlen); /* FIXME: */ - strcpy(e->strarg, csound->sstrbuf); /* leaks memory */ + memcpy(e->strarg, csound->sstrbuf, csound->sstrlen); /* leaks memory */ + e->scnt = csound->scnt; csound->sstrlen = 0; } + else { e->strarg = NULL; e->scnt = 0; } /* is this necessary?? */ return 1; } } corfile_rm(&(csound->scstr)); return 0; } - - diff -Nru csound-5.17.11~dfsg/Engine/score_param.h csound-6.02~dfsg/Engine/score_param.h --- csound-5.17.11~dfsg/Engine/score_param.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Engine/score_param.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,69 @@ +#ifndef __SCORE_PARAM_H +#define __SCORE_PARAM_H + +#define MARGS (3) +#define MAX_INCLUDE_DEPTH 100 +struct MACRO; + +typedef struct MACRON { + int n; + unsigned int line; + struct MACRO *s; +} MACRON; + +typedef struct MACRO { /* To store active macros */ + char *name; /* Use is by name */ + int acnt; /* Count of arguments */ + char *body; /* The text of the macro */ + struct MACRO *next; /* Chain of active macros */ + int margs; /* amount of space for args */ + char *arg[MARGS]; /* With these arguments */ +} MACRO; + +typedef struct IFDEFSTACK_ { + struct IFDEFSTACK_ *prv; + unsigned char isDef; /* non-zero if #ifdef is true, or #ifndef */ + /* is false */ + unsigned char isElse; /* non-zero between #else and #endif */ + unsigned char isSkip; /* sum of: 1: skipping code due to this */ + /* #ifdef, 2: skipping due to parent */ +} IFDEFSTACK; + + +typedef struct prs_parm_s { + void *yyscanner; + MACRO *macros; + MACRON alt_stack[MAX_INCLUDE_DEPTH]; + unsigned int macro_stack_ptr; + IFDEFSTACK *ifdefStack; + unsigned char isIfndef; + unsigned char isString; + uint16_t line; + uint32_t locn; + uint32_t llocn; + uint16_t depth; + uint8_t lstack[1024]; +} PRS_PARM; + +typedef struct scotoken_s { + int type; + int ival; + MYFLT fval; + char *strbuff; +} SCOTOKEN; + +typedef struct score_parm_s { + void *yyscanner; + int locn; + MACRO *macros; + char *xstrbuff; + int xstrptr,xstrmax; + int ival; + MYFLT fval; + SCOTOKEN *arglist; +} SCORE_PARM; + +uint32_t make_location(PRS_PARM *); +extern uint8_t file_to_int(CSOUND*, const char*); + +#endif diff -Nru csound-5.17.11~dfsg/Engine/scsort.c csound-6.02~dfsg/Engine/scsort.c --- csound-5.17.11~dfsg/Engine/scsort.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/scsort.c 2014-01-07 16:53:47.000000000 +0000 @@ -24,53 +24,50 @@ #include "csoundCore.h" /* SCSORT.C */ #include "corfile.h" -extern void sort(CSOUND*), twarp(CSOUND*), swrite(CSOUND*), swritestr(CSOUND*); +extern void sort(CSOUND*); +extern void twarp(CSOUND*); +extern void swritestr(CSOUND*, CORFIL *sco, int first); extern void sfree(CSOUND *csound); -extern void sread_init(CSOUND *csound); +//extern void sread_init(CSOUND *csound); extern int sread(CSOUND *csound); /* called from smain.c or some other main */ /* reads,sorts,timewarps each score sect in turn */ -#ifdef OLD_CODE -void scsort(CSOUND *csound, FILE *scin, FILE *scout) +extern void sread_initstr(CSOUND *, CORFIL *sco); +char *scsortstr(CSOUND *csound, CORFIL *scin) { int n; - - csound->scorein = scin; - csound->scoreout = scout; - - csound->sectcnt = 0; - sread_init(csound); - while ((n = sread(csound)) > 0) { - sort(csound); - twarp(csound); - swrite(csound); - } - sfree(csound); /* return all memory used */ -} -#endif - -extern void sread_initstr(CSOUND *); -void scsortstr(CSOUND *csound, CORFIL *scin) -{ - int n; - int m = 0; + int m = 0, first = 0; + CORFIL *sco; csound->scoreout = NULL; - csound->scstr = corfile_create_w(); + if(csound->scstr == NULL && (csound->engineStatus & CS_STATE_COMP) == 0) { + first = 1; + sco = csound->scstr = corfile_create_w(); + } + else sco = corfile_create_w(); csound->sectcnt = 0; - sread_initstr(csound); + sread_initstr(csound, scin); while ((n = sread(csound)) > 0) { sort(csound); twarp(csound); - swritestr(csound); + swritestr(csound, sco, first); m++; } - if (m==0) corfile_puts("f0 800000000000.0\ne\n", csound->scstr); /* ~25367 years */ - else corfile_puts("e\n", csound->scstr); - corfile_flush(csound->scstr); - sfree(csound); /* return all memory used */ + if(first){ + if (m==0) + corfile_puts("f0 800000000000.0\ne\n", sco); /* ~25367 years */ + else corfile_puts("e\n", sco); + } + corfile_flush(sco); + sfree(csound); + if(first) return sco->body; + else { + char *str = strdup(sco->body); + corfile_rm(&(sco)); + return str; + } } diff -Nru csound-5.17.11~dfsg/Engine/scxtract.c csound-6.02~dfsg/Engine/scxtract.c --- csound-5.17.11~dfsg/Engine/scxtract.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/scxtract.c 2014-01-07 16:53:47.000000000 +0000 @@ -1,7 +1,7 @@ /* scxtract.c: - Copyright (C) 1991 Barry Vercoe + Copyright (C) 1991 Barry Vercoe; 2012 John ffitch This file is part of Csound. @@ -23,59 +23,40 @@ #include "csoundCore.h" /* SCXTRACT.C */ #include "corfile.h" +#include "extract.h" -extern void readxfil(CSOUND *, FILE *), extract(CSOUND *), swrite(CSOUND *); extern void sfree(CSOUND *csound); extern int sread(CSOUND *csound); -extern void sread_init(CSOUND *csound); -extern void swritestr(CSOUND *csound); +//extern void sread_init(CSOUND *csound); +extern void swritestr(CSOUND *csound, CORFIL *sco, int first); /* called from xmain.c or some other main */ /* extracts events from each score sect */ /* according to the controlling xfile */ -#ifdef OLD_CODE -int scxtract(CSOUND *csound, FILE *scin, FILE * scout, FILE *xfile) -{ - int n; - - readxfil(csound, xfile); - csound->scorein = scin; - csound->scoreout = scout; - csound->sectcnt = 0; - sread_init(csound); - - while ((n = sread(csound)) > 0) { - /* allout(); */ - /* textout(); */ - extract(csound); - swrite(csound); - } +extern void sread_initstr(CSOUND *, CORFIL *sco); - sfree(csound); /* return all memory used */ - return 0; -} -#endif - -extern void sread_initstr(CSOUND *); int scxtract(CSOUND *csound, CORFIL *scin, FILE *xfile) { int n; + EXTRACT_STATICS* extractStatics = calloc(1, sizeof(EXTRACT_STATICS)); + csound->scoreout = NULL; csound->scorestr = scin; csound->scstr = corfile_create_w(); csound->sectcnt = 0; - readxfil(csound, xfile); - sread_initstr(csound); + readxfil(csound, extractStatics, xfile); + sread_initstr(csound, scin); while ((n = sread(csound)) > 0) { /* allout(); */ /* textout(); */ - extract(csound); - swritestr(csound); + extract(csound, extractStatics); + swritestr(csound, csound->scstr, 1); } corfile_flush(csound->scstr); sfree(csound); /* return all memory used */ + free(extractStatics); return 0; } diff -Nru csound-5.17.11~dfsg/Engine/sort.c csound-6.02~dfsg/Engine/sort.c --- csound-5.17.11~dfsg/Engine/sort.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/sort.c 2014-01-07 16:53:47.000000000 +0000 @@ -101,7 +101,7 @@ #define b1 (data[6]) #define c1 (data[7]) -static void inline sift(SRTBLK *A[], int data[]) +inline static void sift(SRTBLK *A[], int data[]) { int r0, r2, temp; SRTBLK * T; @@ -123,9 +123,9 @@ if (UNLIKELY(r1 != r0)) A[r1] = T; } -static void inline trinkle(SRTBLK *A[], int data[]) +inline static void trinkle(SRTBLK *A[], int data[]) { - int p1, r2, r3, r0, temp; + int p1,r2,r3, r0, temp; SRTBLK * T; p1 = p; b1 = b; c1 = c; r0 = r1; T = A[r0]; @@ -140,13 +140,13 @@ p1--; if (b1==1) { A[r1] = A[r3]; - r1 = r3; + r1 = r3; } else if (b1 >= 3) { r2 = r1-b1+c1; if (! ordering(A[r1-1],A[r2])) { - r2 = r1-1; + r2 = r1-1; DOWN(b1,c1) p1 <<= 1; } @@ -166,7 +166,7 @@ sift(A, data); } -static void inline semitrinkle(SRTBLK *A[], int data[]) +inline static void semitrinkle(SRTBLK *A[], int data[]) { SRTBLK * T; r1 = r-c; @@ -179,8 +179,7 @@ static void smoothsort(SRTBLK *A[], const int N) { int temp; - int data[] = {/*q*/ 1, /*r*/ 0, /*p*/ 1, /*b*/ 1, - /*c*/ 1, /*r1*/ 0, /*b1*/ 0, /*c1*/ 0}; + int data[] = {/*q*/ 1, /*r*/ 0, /*p*/ 1, /*b*/ 1, /*c*/ 1, 0,0,0}; /* building tree */ while (q < N) { @@ -199,7 +198,7 @@ p <<= 1; while (b > 1) { DOWN(b,c) - p <<= 1; + p <<= 1; } p++; } @@ -261,27 +260,33 @@ case 's': bp->preced = 'a'; break; + case -1: + break; default: csound->Message(csound, Str("sort: illegal opcode %c(%.2x)\n"), bp->text[0], bp->text[0]); break; } } while ((bp = bp->nxtblk) != NULL); - /* Get a temporary array and populate it */ - A = (SRTBLK**) malloc(n*sizeof(SRTBLK*)); - bp = csound->frstbp; - for (i=0; inxtblk) - A[i] = bp; - if (LIKELY(A[n-1]->text[0]=='e' || A[n-1]->text[0]=='s')) - smoothsort(A, n-1); - else - smoothsort(A, n); - /* Relink list in order; first and last different */ - csound->frstbp = bp = A[0]; bp->prvblk = NULL; bp->nxtblk = A[1]; - for (i=1; iprvblk = A[i-1]; bp->nxtblk = A[i+1]; - } - if (n>1) bp = A[n-1]; bp->nxtblk = NULL; bp->prvblk = A[n-2]; - /* and return temporary space */ - free(A); + + if (n>1) { + /* Get a temporary array and populate it */ + A = ((SRTBLK**) malloc(n*sizeof(SRTBLK*))); + bp = csound->frstbp; + for (i=0; inxtblk) + A[i] = bp; + if (LIKELY(A[n-1]->text[0]=='e' || A[n-1]->text[0]=='s')) + smoothsort(A, n-1); + else + smoothsort(A, n); + /* Relink list in order; first and last different */ + csound->frstbp = bp = A[0]; bp->prvblk = NULL; bp->nxtblk = A[1]; + for (i=1; iprvblk = A[i-1]; bp->nxtblk = A[i+1]; + } + if (n>1) bp = A[n-1]; bp->nxtblk = NULL; bp->prvblk = A[n-2]; + /* and return temporary space */ + free(A); + + } } diff -Nru csound-5.17.11~dfsg/Engine/sread.c csound-6.02~dfsg/Engine/sread.c --- csound-5.17.11~dfsg/Engine/sread.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/sread.c 2014-01-07 16:54:20.000000000 +0000 @@ -32,69 +32,34 @@ #define NAMELEN 40 /* array size of repeat macro names */ #define RPTDEPTH 40 /* size of repeat_n arrays (39 loop levels) */ -#define MARGS (3) +//#define MARGS (3) //#define MACDEBUG (1) -typedef struct MACRO { /* To store active macros */ - char *name; /* Use is by name */ - int acnt; /* Count of arguments */ - CORFIL *body; /* The text of the macro */ - struct MACRO *next; /* Chain of active macros */ - int margs; /* ammount of space for args */ - char *arg[MARGS]; /* With these arguments */ -} MACRO; - -typedef struct in_stack_s { /* Stack of active inputs */ - // int16 string; /* Flag to say if string or file */ - int16 is_marked_repeat; /* 1 if this input created by 'n' stmnt */ - int16 args; /* Argument count for macro */ - CORFIL *cf; /* In core file */ - // FILE *file; /* File case only */ - void *fd; /* for closing stream */ - MACRO *mac; - int line; -} IN_STACK; - -typedef struct marked_sections { - char *name; - int32 posit; - int line; - char *file; -} MARKED_SECTIONS; - -typedef struct { - SRTBLK *bp, *prvibp; /* current srtblk, prev w/same int(p1) */ - char *sp, *nxp; /* string pntrs into srtblk text */ - int op; /* opcode of current event */ - int warpin; /* input format sensor */ - int linpos; /* line position sensor */ - int lincnt; /* count of lines/section in scorefile */ - MYFLT prvp2 /* = -FL(1.0) */; /* Last event time */ - MYFLT clock_base /* = FL(0.0) */; - MYFLT warp_factor /* = FL(1.0) */; - char *curmem; - char *memend; /* end of cur memblk */ - MACRO *macros; - int next_name /* = -1 */; - IN_STACK *inputs, *str; - int input_size, input_cnt; - int pop; /* Number of macros to pop */ - int ingappop /* = 1 */; /* Are we in a popable gap? */ - int linepos /* = -1 */; - MARKED_SECTIONS names[30], *current_name; - char repeat_name_n[RPTDEPTH][NAMELEN]; - int repeat_cnt_n[RPTDEPTH]; - int32 repeat_point_n[RPTDEPTH]; - int repeat_inc_n /* = 1 */; - MACRO *repeat_mm_n[RPTDEPTH]; - int repeat_index; - /* Variable for repeat sections */ - char repeat_name[NAMELEN]; - int repeat_cnt; - int32 repeat_point; - int repeat_inc /* = 1 */; - MACRO *repeat_mm; -} SREAD_GLOBALS; +/* typedef struct S_MACRO { /\* To store active macros *\/ */ +/* char *name; /\* Use is by name *\/ */ +/* int acnt; /\* Count of arguments *\/ */ +/* CORFIL *body; /\* The text of the macro *\/ */ +/* struct S_MACRO *next; /\* Chain of active macros *\/ */ +/* int margs; /\* ammount of space for args *\/ */ +/* char *arg[MARGS]; /\* With these arguments *\/ */ +/* } S_MACRO; */ + +/* typedef struct in_stack_s { /\* Stack of active inputs *\/ */ +/* int16 is_marked_repeat;/\* 1 if this input created by 'n' stmnt *\/ */ +/* int16 args; /\* Argument count for macro *\/ */ +/* CORFIL *cf; /\* In core file *\/ */ +/* void *fd; /\* for closing stream *\/ */ +/* S_MACRO *mac; */ +/* int line; */ +/* } IN_STACK; */ + +/* typedef struct marked_sections { */ +/* char *name; */ +/* int32 posit; */ +/* int line; */ +/* char *file; */ +/* } MARKED_SECTIONS; */ + static void print_input_backtrace(CSOUND *csound, int needLFs, void (*msgfunc)(CSOUND*, const char*, ...)); @@ -107,23 +72,8 @@ MYFLT stof(CSOUND *, char *); extern void *fopen_path(CSOUND *, FILE **, char *, char *, char *, int); -#define ST(x) (((SREAD_GLOBALS*) csound->sreadGlobals)->x) - -static void sread_alloc_globals(CSOUND *csound) -{ - if (LIKELY(csound->sreadGlobals != NULL)) - return; - csound->sreadGlobals = (SREAD_GLOBALS*) - csound->Calloc(csound, sizeof(SREAD_GLOBALS)); - ST(prvp2) = -FL(1.0); - ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(next_name) = -1; - ST(ingappop) = 1; - ST(linepos) = -1; - ST(repeat_inc_n) = 1; - ST(repeat_inc) = 1; -} +//#define ST(x) (((SREAD_GLOBALS*) csound->sreadGlobals)->x) +#define STA(x) (csound->sreadStatics.x) static intptr_t expand_nxp(CSOUND *csound) { @@ -132,32 +82,32 @@ intptr_t offs; size_t nbytes; - if (UNLIKELY(ST(nxp) >= (ST(memend) + MARGIN))) { + if (UNLIKELY(STA(nxp) >= (STA(memend) + MARGIN))) { csound->Die(csound, Str("sread: text space overrun, increase MARGIN")); return 0; /* not reached */ } /* calculate the number of bytes to allocate */ - nbytes = (size_t) (ST(memend) - ST(curmem)); + nbytes = (size_t) (STA(memend) - STA(curmem)); nbytes = nbytes + (nbytes >> 3) + (size_t) (MEMSIZ - 1); nbytes &= ~((size_t) (MEMSIZ - 1)); /* extend allocated memory */ - oldp = ST(curmem); - ST(curmem) = (char*) csound->ReAlloc(csound, ST(curmem), + oldp = STA(curmem); + STA(curmem) = (char*) csound->ReAlloc(csound, STA(curmem), nbytes + (size_t) MARGIN); - ST(memend) = (char*) ST(curmem) + (int32) nbytes; + STA(memend) = (char*) STA(curmem) + (int32) nbytes; /* did the pointer change ? */ - if (ST(curmem) == oldp) + if (STA(curmem) == oldp) return (intptr_t) 0; /* no, nothing to do */ /* correct all pointers for the change */ - offs = (intptr_t) ((uintptr_t) ST(curmem) - (uintptr_t) oldp); - if (ST(bp) != NULL) - ST(bp) = (SRTBLK*) ((uintptr_t) ST(bp) + (intptr_t) offs); - if (ST(prvibp) != NULL) - ST(prvibp) = (SRTBLK*) ((uintptr_t) ST(prvibp) + (intptr_t) offs); - if (ST(sp) != NULL) - ST(sp) = (char*) ((uintptr_t) ST(sp) + (intptr_t) offs); - if (ST(nxp) != NULL) - ST(nxp) = (char*) ((uintptr_t) ST(nxp) + (intptr_t) offs); + offs = (intptr_t) ((uintptr_t) STA(curmem) - (uintptr_t) oldp); + if (STA(bp) != NULL) + STA(bp) = (SRTBLK*) ((uintptr_t) STA(bp) + (intptr_t) offs); + if (STA(prvibp) != NULL) + STA(prvibp) = (SRTBLK*) ((uintptr_t) STA(prvibp) + (intptr_t) offs); + if (STA(sp) != NULL) + STA(sp) = (char*) ((uintptr_t) STA(sp) + (intptr_t) offs); + if (STA(nxp) != NULL) + STA(nxp) = (char*) ((uintptr_t) STA(nxp) + (intptr_t) offs); if (csound->frstbp == NULL) return offs; p = csound->frstbp; @@ -202,18 +152,20 @@ static void print_input_backtrace(CSOUND *csound, int needLFs, void (*msgfunc)(CSOUND*, const char*, ...)) { - IN_STACK *curr = ST(str); + IN_STACK *curr = STA(str); char *m, *lf = (needLFs ? "\n" : ""); int lastinput = 0; int lastsource = 2; /* 2=current file, 1=macro, 0=#include */ msgfunc(csound, Str(" section %d: at position %d%s"), csound->sectcnt, - ST(linepos), lf); + STA(linepos), lf); do { - if (curr == ST(inputs)) lastinput = 1; - if (UNLIKELY(!curr->mac || !curr->mac->name)) - csoundDie(csound, Str("Internal error in print_input_backtrace()")); + if (curr == STA(inputs)) lastinput = 1; + if (UNLIKELY(!curr->mac || !curr->mac->name)){ + csound->Warning(csound, Str("Internal error in print_input_backtrace()")); + return; + } switch(lastsource) { case 0: m = Str(" included from line %d of macro %s%s"); break; case 1: m = Str(" called from line %d of macro %s%s"); break; @@ -230,7 +182,7 @@ } /* else { */ /* msgfunc(csound, m, (lastsource == 0 ? curr->line - 1 : curr->line), */ - /* corfile_tell(curr->cf), lf); /\* #include is one line before *\/ */ + /* corfile_tell(curr->cf), lf); /\* #include is one line before *\/ */ /* } */ } while (!lastsource); curr--; @@ -261,24 +213,25 @@ static int undefine_score_macro(CSOUND *csound, const char *name) { - MACRO *mm, *nn; + S_MACRO *mm, *nn; int i; - if (strcmp(name, ST(macros)->name) == 0) { - mm = ST(macros)->next; - if (strcmp(ST(macros)->name, "[") != 0) - corfile_rm(&(ST(macros)->body)); - mfree(csound, ST(macros)->name); + if (strcmp(name, STA(macros)->name) == 0) { + mm = STA(macros)->next; + if (strcmp(STA(macros)->name, "[") != 0) + corfile_rm(&(STA(macros)->body)); + mfree(csound, STA(macros)->name); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): corfile is %p\n", __FILE__, __LINE__, ST(macros)->body); + csound->DebugMsg(csound,"%s(%d): corfile is %p\n", + __FILE__, __LINE__, STA(macros)->body); #endif - for (i = 0; i < ST(macros)->acnt; i++) - mfree(csound, ST(macros)->arg[i]); - mfree(csound, ST(macros)); - ST(macros) = mm; + for (i = 0; i < STA(macros)->acnt; i++) + mfree(csound, STA(macros)->arg[i]); + mfree(csound, STA(macros)); + STA(macros) = mm; } else { - mm = ST(macros); + mm = STA(macros); nn = mm->next; while (strcmp(name, nn->name) != 0) { mm = nn; nn = nn->next; @@ -308,65 +261,66 @@ static inline void ungetscochar(CSOUND *csound, int c) { - corfile_ungetc(ST(str)->cf); - ST(str)->cf->body[(ST(str)->cf)->p] = (char)c; + corfile_ungetc(STA(str)->cf); + STA(str)->cf->body[(STA(str)->cf)->p] = (char)c; } static int getscochar(CSOUND *csound, int expand) { /* Read a score character, expanding macros if flag set */ int c; top: - c = corfile_getc(ST(str)->cf); + c = corfile_getc(STA(str)->cf); if (c == EOF) { - if (ST(str) == &ST(inputs)[0]) { - corfile_putc('\n', ST(str)->cf); /* to ensure repeated EOF */ + if (STA(str) == &STA(inputs)[0]) { + corfile_putc('\n', STA(str)->cf); /* to ensure repeated EOF */ return EOF; } - if (ST(str)->mac == 0) { - corfile_rm(&(ST(str)->cf)); /* No longer needed */ + if (STA(str)->mac == 0) { + corfile_rm(&(STA(str)->cf)); /* No longer needed */ } else { - corfile_rewind(ST(str)->cf); + corfile_rewind(STA(str)->cf); } - ST(pop) += ST(str)->args; - ST(str)--; ST(input_cnt)--; + STA(pop) += STA(str)->args; + STA(str)--; STA(input_cnt)--; goto top; } #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): character = %c(%.2d)\n", __FILE__, __LINE__, c, c); + csound->DebugMsg(csound,"%s(%d): character = %c(%.2d)\n", + __FILE__, __LINE__, c, c); #endif if (c == '\r') { /* can only occur in files, and not in macros */ - if ((c = corfile_getc(ST(str)->cf)) != '\n') { + if ((c = corfile_getc(STA(str)->cf)) != '\n') { if (c == EOF) goto top; - corfile_ungetc(ST(str)->cf); + corfile_ungetc(STA(str)->cf); } c = '\n'; } if (c == '\n') { - ST(str)->line++; ST(linepos) = -1; + STA(str)->line++; STA(linepos) = -1; } - else ST(linepos)++; - if (ST(ingappop) && ST(pop)) { + else STA(linepos)++; + if (STA(ingappop) && STA(pop)) { do { - if (ST(macros) != NULL) { + if (STA(macros) != NULL) { #ifdef MACDEBUG - csound->Message(csound,"popping %s\n", ST(macros)->name); + csound->Message(csound,"popping %s\n", STA(macros)->name); #endif - undefine_score_macro(csound, ST(macros)->name); + undefine_score_macro(csound, STA(macros)->name); } - ST(pop)--; - } while (ST(pop)); + STA(pop)--; + } while (STA(pop)); } if (c == '$' && expand) { char name[100]; unsigned int i = 0; int j; - MACRO *mm, *mm_save = NULL; - ST(ingappop) = 0; + S_MACRO *mm, *mm_save = NULL; + STA(ingappop) = 0; while (isNameChar((c = getscochar(csound, 1)), (int) i)) { name[i++] = c; name[i] = '\0'; - mm = ST(macros); + mm = STA(macros); while (mm != NULL) { /* Find the definition */ if (!(strcmp(name, mm->name))) { mm_save = mm; /* found a match, save it */ @@ -405,7 +359,7 @@ for (j = 0; j < mm->acnt; j++) { char term = (j == mm->acnt - 1 ? ')' : '\''); char trm1 = (j == mm->acnt - 1 ? ')' : '#'); - MACRO* nn = (MACRO*) mmalloc(csound, sizeof(MACRO)); + S_MACRO* nn = (S_MACRO*) mmalloc(csound, sizeof(S_MACRO)); nn->name = mmalloc(csound, strlen(mm->arg[j])+1); strcpy(nn->name, mm->arg[j]); #ifdef MACDEBUG @@ -413,7 +367,8 @@ #endif nn->body = corfile_create_w(); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): creating\n", __FILE__, __LINE__, nn->body); + csound->DebugMsg(csound,"%s(%d): creating\n", + __FILE__, __LINE__, nn->body); #endif while ((c = getscochar(csound, 1))!= term && c != trm1) { if (UNLIKELY(c==EOF)) @@ -425,28 +380,28 @@ csound->Message(csound,"as...#%s#\n", corfile_body(nn->body)); #endif nn->acnt = 0; /* No arguments for arguments */ - nn->next = ST(macros); - ST(macros) = nn; + nn->next = STA(macros); + STA(macros) = nn; } } - ST(input_cnt)++; - if (UNLIKELY(ST(input_cnt)>=ST(input_size))) { - int old = ST(str)-ST(inputs); - ST(input_size) += 20; - ST(inputs) = mrealloc(csound, ST(inputs), ST(input_size) + STA(input_cnt)++; + if (UNLIKELY(STA(input_cnt)>=STA(input_size))) { + int old = STA(str)-STA(inputs); + STA(input_size) += 20; + STA(inputs) = mrealloc(csound, STA(inputs), STA(input_size) * sizeof(IN_STACK)); - ST(str) = &ST(inputs)[old]; /* In case it moves */ + STA(str) = &STA(inputs)[old]; /* In case it moves */ } - ST(str)++; - ST(str)->fd = ST(str)->cf = mm->body; ST(str)->args = mm->acnt; - ST(str)->is_marked_repeat = 0; - ST(str)->mac = mm; ST(str)->line = 1; + STA(str)++; + STA(str)->fd = STA(str)->cf = mm->body; STA(str)->args = mm->acnt; + STA(str)->is_marked_repeat = 0; + STA(str)->mac = mm; STA(str)->line = 1; #ifdef MACDEBUG csound->Message(csound, "Macro %s definded as >>%s<<\n", mm->name, corfile_body(mm->body)); #endif - ST(ingappop) = 1; + STA(ingappop) = 1; goto top; } /* End of macro expander */ @@ -601,35 +556,36 @@ } } while (c != '$'); /* Make string macro or value */ - sprintf(buffer, "%g", *pv); + CS_SPRINTF(buffer, "%f", *pv); { - MACRO *nn = (MACRO*) mmalloc(csound, sizeof(MACRO)); + S_MACRO *nn = (S_MACRO*) mmalloc(csound, sizeof(S_MACRO)); nn->name = mmalloc(csound, 2); strcpy(nn->name, "["); nn->body = corfile_create_r(buffer); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): creating arg %p\n", __FILE__, __LINE__, nn->body); + csound->DebugMsg(csound,"%s(%d): creating arg %p\n", + __FILE__, __LINE__, nn->body); #endif nn->acnt = 0; /* No arguments for arguments */ - nn->next = ST(macros); - ST(macros) = nn; - ST(input_cnt)++; - if (UNLIKELY(ST(input_cnt)>=ST(input_size))) { - int old = ST(str)-ST(inputs); - ST(input_size) += 20; - ST(inputs) = mrealloc(csound, ST(inputs), ST(input_size) + nn->next = STA(macros); + STA(macros) = nn; + STA(input_cnt)++; + if (UNLIKELY(STA(input_cnt)>=STA(input_size))) { + int old = STA(str)-STA(inputs); + STA(input_size) += 20; + STA(inputs) = mrealloc(csound, STA(inputs), STA(input_size) * sizeof(IN_STACK)); - ST(str) = &ST(inputs)[old]; /* In case it moves */ + STA(str) = &STA(inputs)[old]; /* In case it moves */ } - ST(str)++; - ST(str)->cf = nn->body; ST(str)->args = 0; - ST(str)->fd = NULL; - ST(str)->is_marked_repeat = 0; - ST(str)->mac = NULL; ST(str)->line = 1; + STA(str)++; + STA(str)->cf = nn->body; STA(str)->args = 0; + STA(str)->fd = NULL; + STA(str)->is_marked_repeat = 0; + STA(str)->mac = NULL; STA(str)->line = 1; #ifdef MACDEBUG csound->Message(csound,"[] defined as >>%s<<\n", corfile_body(nn->body)); #endif - ST(ingappop) = 1; + STA(ingappop) = 1; goto top; } } @@ -638,73 +594,77 @@ static int nested_repeat(CSOUND *csound) /* gab A9*/ { - ST(repeat_cnt_n)[ST(repeat_index)]--; - if (ST(repeat_cnt_n)[ST(repeat_index)] == 0) { /* Expired */ - if (ST(repeat_index) > 1) { + STA(repeat_cnt_n)[STA(repeat_index)]--; + if (STA(repeat_cnt_n)[STA(repeat_index)] == 0) { /* Expired */ + if (STA(repeat_index) > 1) { char c[41]; int j; - for (j = 0; joparms->msglevel & TIMEMSG) csound->Message(csound,Str("%s Nested LOOP terminated, level:%d\n"), - c,ST(repeat_index)); + c,STA(repeat_index)); } else { if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound,Str("External LOOP terminated, level:%d\n"), - ST(repeat_index)); + STA(repeat_index)); } - undefine_score_macro(csound, ST(repeat_name_n)[ST(repeat_index)]); - ST(repeat_index)--; + undefine_score_macro(csound, STA(repeat_name_n)[STA(repeat_index)]); + STA(repeat_index)--; } else { int i; - corfile_set(ST(str)->cf,ST(repeat_point_n)[ST(repeat_index)]); - sscanf(corfile_current(ST(repeat_mm_n)[ST(repeat_index)]->body), + corfile_set(STA(str)->cf,STA(repeat_point_n)[STA(repeat_index)]); + sscanf(corfile_current(STA(repeat_mm_n)[STA(repeat_index)]->body), "%d", &i); #ifdef MACDEBUG csound->DebugMsg(csound,"%s(%d) reset point to %d\n", __FILE__, __LINE__, - ST(repeat_point_n)[ST(repeat_index)], i); + STA(repeat_point_n)[STA(repeat_index)], i); csound->DebugMsg(csound,"%s(%d) corefile: %s %d %d\n", __FILE__, __LINE__, - ST(repeat_mm_n)[ST(repeat_index)]->body->body, - ST(repeat_mm_n)[ST(repeat_index)]->body->p, - ST(repeat_mm_n)[ST(repeat_index)]->body->len); + STA(repeat_mm_n)[STA(repeat_index)]->body->body, + STA(repeat_mm_n)[STA(repeat_index)]->body->p, + STA(repeat_mm_n)[STA(repeat_index)]->body->len); #endif - i = i + ST(repeat_inc_n); + i = i + STA(repeat_inc_n); { char buffer[128]; + memset(buffer, '\0', 128); sprintf(buffer, "%d", i); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d) new i = %s\n", __FILE__, __LINE__, buffer); + csound->DebugMsg(csound,"%s(%d) new i = %s\n", + __FILE__, __LINE__, buffer); #endif - corfile_reset(ST(repeat_mm_n)[ST(repeat_index)]->body); - corfile_puts(buffer, ST(repeat_mm_n)[ST(repeat_index)]->body); - corfile_rewind(ST(repeat_mm_n)[ST(repeat_index)]->body); + corfile_reset(STA(repeat_mm_n)[STA(repeat_index)]->body); + corfile_puts(buffer, STA(repeat_mm_n)[STA(repeat_index)]->body); + corfile_rewind(STA(repeat_mm_n)[STA(repeat_index)]->body); #ifdef MACDEBUG csound->DebugMsg(csound,"%s(%d) corefile: %s %d %d\n", __FILE__, __LINE__, - ST(repeat_mm_n)[ST(repeat_index)]->body->body, - ST(repeat_mm_n)[ST(repeat_index)]->body->p, - ST(repeat_mm_n)[ST(repeat_index)]->body->len); + STA(repeat_mm_n)[STA(repeat_index)]->body->body, + STA(repeat_mm_n)[STA(repeat_index)]->body->p, + STA(repeat_mm_n)[STA(repeat_index)]->body->len); #endif } - if (ST(repeat_index) > 1) { + if (STA(repeat_index) > 1) { char c[41]; int j; - for (j = 0; joparms->msglevel & TIMEMSG) csound->Message(csound,Str("%s Nested LOOP section (%d) Level:%d\n"), - c, i, ST(repeat_index)); + c, i, STA(repeat_index)); } else { if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound,Str(" External LOOP section (%d) Level:%d\n"), - i, ST(repeat_index)); + i, STA(repeat_index)); } return 1; } @@ -713,28 +673,28 @@ static int do_repeat(CSOUND *csound) { /* At end of section repeat if necessary */ - ST(repeat_cnt)--; - if (ST(repeat_cnt) == 0) { /* Expired */ + STA(repeat_cnt)--; + if (STA(repeat_cnt) == 0) { /* Expired */ /* Delete macro (assuming there is any) */ if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound, Str("Loop terminated\n")); - if (ST(repeat_name)[0] != '\0') - undefine_score_macro(csound, ST(repeat_name)); - ST(repeat_name)[0] = '\0'; + if (STA(repeat_name)[0] != '\0') + undefine_score_macro(csound, STA(repeat_name)); + STA(repeat_name)[0] = '\0'; } else { int i, n; - corfile_set(ST(str)->cf, ST(repeat_point)); - if (ST(repeat_name)[0] != '\0') { - sscanf(corfile_current(ST(repeat_mm)->body), "%d%n", &i, &n); - i = i + ST(repeat_inc); - corfile_seek(ST(repeat_mm)->body, n, SEEK_CUR); + corfile_set(STA(str)->cf, STA(repeat_point)); + if (STA(repeat_name)[0] != '\0') { + sscanf(corfile_current(STA(repeat_mm)->body), "%d%n", &i, &n); + i = i + STA(repeat_inc); + corfile_seek(STA(repeat_mm)->body, n, SEEK_CUR); { char buffer[128]; sprintf(buffer, "%d", i); - corfile_reset(ST(repeat_mm)->body); - corfile_puts(buffer, ST(repeat_mm)->body); - corfile_rewind(ST(repeat_mm)->body); + corfile_reset(STA(repeat_mm)->body); + corfile_puts(buffer, STA(repeat_mm)->body); + corfile_rewind(STA(repeat_mm)->body); } if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound, Str("Repeat section (%d)\n"), i); @@ -742,10 +702,10 @@ else csound->Message(csound, Str("Repeat section\n")); /* replace 'e' or 'r' with 's' and end section */ - ST(bp)->text[0] = 's'; - ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(prvp2) = -FL(1.0); + STA(bp)->text[0] = 's'; + STA(clock_base) = FL(0.0); + STA(warp_factor) = FL(1.0); + STA(prvp2) = -FL(1.0); return 1; } return 0; @@ -753,7 +713,7 @@ static void init_smacros(CSOUND *csound, NAMES *nn) { - MACRO *mm; + S_MACRO *mm; while (nn) { char *s = nn->mac; char *p = strchr(s, '='); @@ -770,15 +730,15 @@ strncpy(mname, s, p - s); mname[p - s] = '\0'; /* check if macro is already defined */ - for (mm = ST(macros); mm != NULL; mm = mm->next) { + for (mm = STA(macros); mm != NULL; mm = mm->next) { if (strcmp(mm->name, mname) == 0) break; } if (mm == NULL) { - mm = (MACRO*) mcalloc(csound, sizeof(MACRO)); + mm = (S_MACRO*) mcalloc(csound, sizeof(S_MACRO)); mm->name = mname; - mm->next = ST(macros); - ST(macros) = mm; + mm->next = STA(macros); + STA(macros) = mm; } else mfree(csound, mname); @@ -788,46 +748,49 @@ p++; mm->body = corfile_create_r(p); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): init %s %p\n", __FILE__, __LINE__, mm->name, mm->body); + csound->DebugMsg(csound,"%s(%d): init %s %p\n", + __FILE__, __LINE__, mm->name, mm->body); #endif nn = nn->next; } - mm = (MACRO*) mcalloc(csound, sizeof(MACRO)); + mm = (S_MACRO*) mcalloc(csound, sizeof(S_MACRO)); mm->name = (char*)mmalloc(csound,4); strcpy(mm->name, "INF"); mm->body = corfile_create_r("800000000000.0"); #ifdef MACDEBUG csound->DebugMsg(csound,"%s(%d): INF %p\n", __FILE__, __LINE__, mm->body); #endif - mm->next = ST(macros); - ST(macros) = mm; + mm->next = STA(macros); + STA(macros) = mm; } +#if never void sread_init(CSOUND *csound) { - sread_alloc_globals(csound); - ST(inputs) = (IN_STACK*) mmalloc(csound, 20 * sizeof(IN_STACK)); - ST(input_size) = 20; - ST(input_cnt) = 0; - ST(str) = ST(inputs); - ST(str)->fd = NULL; - ST(str)->cf = csound->scstr; - ST(str)->is_marked_repeat = 0; - ST(str)->line = 1; ST(str)->mac = NULL; + /* sread_alloc_globals(csound); */ + STA(inputs) = (IN_STACK*) mmalloc(csound, 20 * sizeof(IN_STACK)); + STA(input_size) = 20; + STA(input_cnt) = 0; + STA(str) = STA(inputs); + STA(str)->fd = NULL; + STA(str)->cf = csound->scstr; + STA(str)->is_marked_repeat = 0; + STA(str)->line = 1; STA(str)->mac = NULL; init_smacros(csound, csound->smacros); } +#endif -void sread_initstr(CSOUND *csound) +void sread_initstr(CSOUND *csound, CORFIL *sco) { - sread_alloc_globals(csound); - ST(inputs) = (IN_STACK*) mmalloc(csound, 20 * sizeof(IN_STACK)); - ST(input_size) = 20; - ST(input_cnt) = 0; - ST(str) = ST(inputs); - ST(str)->fd = NULL; - ST(str)->fd = ST(str)->cf = csound->scorestr; - ST(str)->is_marked_repeat = 0; - ST(str)->line = 1; ST(str)->mac = NULL; + /* sread_alloc_globals(csound); */ + STA(inputs) = (IN_STACK*) mmalloc(csound, 20 * sizeof(IN_STACK)); + STA(input_size) = 20; + STA(input_cnt) = 0; + STA(str) = STA(inputs); + STA(str)->fd = NULL; + STA(str)->fd = STA(str)->cf = sco; + STA(str)->is_marked_repeat = 0; + STA(str)->line = 1; STA(str)->mac = NULL; init_smacros(csound, csound->smacros); } @@ -836,20 +799,20 @@ int rtncod; /* return code to calling program: */ /* 1 = section read */ /* 0 = end of file */ - sread_alloc_globals(csound); - ST(bp) = ST(prvibp) = csound->frstbp = NULL; - ST(nxp) = NULL; - ST(warpin) = 0; - ST(lincnt) = 1; + /* sread_alloc_globals(csound); */ + STA(bp) = STA(prvibp) = csound->frstbp = NULL; + STA(nxp) = NULL; + STA(warpin) = 0; + STA(lincnt) = 1; csound->sectcnt++; rtncod = 0; salcinit(csound); /* init the mem space for this section */ - while ((ST(op) = getop(csound)) != EOF) { /* read next op from scorefile */ + while ((STA(op) = getop(csound)) != EOF) { /* read next op from scorefile */ rtncod = 1; salcblk(csound); /* build a line structure; init bp,nxp */ again: - switch (ST(op)) { /* and dispatch on opcodes */ + switch (STA(op)) { /* and dispatch on opcodes */ case 'i': case 'f': case 'a': @@ -857,7 +820,7 @@ ifa(csound); break; case 'w': - ST(warpin)++; + STA(warpin)++; copypflds(csound); break; case 't': @@ -865,16 +828,16 @@ break; case 'b': /* Set a clock base */ { - char *old_nxp = ST(nxp)-2; + char *old_nxp = STA(nxp)-2; getpfld(csound); - ST(clock_base) = stof(csound, ST(sp)); + STA(clock_base) = stof(csound, STA(sp)); if (csound->oparms->msglevel & TIMEMSG) - csound->Message(csound,Str("Clockbase = %f\n"), ST(clock_base)); + csound->Message(csound,Str("Clockbase = %f\n"), STA(clock_base)); flushlin(csound); - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); /* Undo this line */ - ST(nxp)++; + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); /* Undo this line */ + STA(nxp)++; goto again; } case 's': @@ -882,7 +845,7 @@ /* check for optional p1 before doing repeats */ copylin(csound); { - char *p = &(ST(bp)->text[1]); + char *p = &(STA(bp)->text[1]); char q; while (*p == ' ' || *p == '\t') p++; @@ -893,201 +856,203 @@ if (isdigit(q) || q=='+' || q=='-' || q=='.') { double tt; char *tmp = p; - tt = strtod(p, &tmp); + tt = cs_strtod(p, &tmp); if (tmp != p && (*tmp == '\0' || isspace(*tmp))) { - ST(bp)->pcnt = 1; - ST(bp)->p1val = ST(bp)->p2val = ST(bp)->newp2 = (MYFLT) tt; + STA(bp)->pcnt = 1; + STA(bp)->p1val = STA(bp)->p2val = STA(bp)->newp2 = (MYFLT) tt; } } - else ST(bp)->p1val = ST(bp)->p2val = ST(bp)->newp2 = FL(0.0); + else STA(bp)->p1val = STA(bp)->p2val = STA(bp)->newp2 = FL(0.0); } /* If we are in a repeat of a marked section ('n' statement), we must pop those inputs before doing an 'r' repeat. */ - while (ST(str)->is_marked_repeat && ST(input_cnt) > 0) { + while (STA(str)->is_marked_repeat && STA(input_cnt) > 0) { /* close all marked repeat inputs */ - /* if (ST(str)->fd != NULL) { */ - /* csound->FileClose(csound, ST(str)->fd); ST(str)->fd = NULL; */ + /* if (STA(str)->fd != NULL) { */ + /* csound->FileClose(csound, STA(str)->fd); STA(str)->fd = NULL; */ /* } */ - corfile_rm(&(ST(str)->cf)); - ST(str)--; ST(input_cnt)--; + corfile_rm(&(STA(str)->cf)); + STA(str)--; STA(input_cnt)--; } - if (ST(repeat_cnt) != 0) { + if (STA(repeat_cnt) != 0) { if (do_repeat(csound)) return rtncod; } - if (ST(op) != 'e') { - ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(prvp2) = -FL(1.0); + if (STA(op) != 'e') { + STA(clock_base) = FL(0.0); + STA(warp_factor) = FL(1.0); + STA(prvp2) = -FL(1.0); } return rtncod; case '}': { int temp; - char *old_nxp = ST(nxp)-2; - if ((temp=ST(repeat_cnt_n)[ST(repeat_index)])!=0) + char *old_nxp = STA(nxp)-2; + if ((temp=STA(repeat_cnt_n)[STA(repeat_index)])!=0) nested_repeat(csound); - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); - ST(nxp)++; + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); + STA(nxp)++; goto again; } case '{': { - char *old_nxp = ST(nxp)-2; + char *old_nxp = STA(nxp)-2; int c, i; - ST(repeat_index)++; - if (UNLIKELY(ST(repeat_index) >= RPTDEPTH)) + STA(repeat_index)++; + if (UNLIKELY(STA(repeat_index) >= RPTDEPTH)) scorerr(csound, Str("Loops are nested too deeply")); - ST(repeat_mm_n)[ST(repeat_index)] = - (MACRO*)mmalloc(csound, sizeof(MACRO)); - ST(repeat_cnt_n)[ST(repeat_index)] = 0; + STA(repeat_mm_n)[STA(repeat_index)] = + (S_MACRO*)mmalloc(csound, sizeof(S_MACRO)); + STA(repeat_cnt_n)[STA(repeat_index)] = 0; do { c = getscochar(csound, 1); } while (c==' '||c=='\t'); while (isdigit(c)) { - ST(repeat_cnt_n)[ST(repeat_index)] = - 10 * ST(repeat_cnt_n)[ST(repeat_index)] + c - '0'; + STA(repeat_cnt_n)[STA(repeat_index)] = + 10 * STA(repeat_cnt_n)[STA(repeat_index)] + c - '0'; c = getscochar(csound, 1); } - if (UNLIKELY(ST(repeat_cnt_n)[ST(repeat_index)] <= 0 + if (UNLIKELY(STA(repeat_cnt_n)[STA(repeat_index)] <= 0 || (c != ' ' && c != '\t' && c != '\n'))) scorerr(csound, Str("{: invalid repeat count")); - if (ST(repeat_index) > 1) { + if (STA(repeat_index) > 1) { char st[41]; int j; - for (j = 0; j < ST(repeat_index); j++) { + for (j = 0; j < STA(repeat_index); j++) { st[j] = ' '; st[j+1] = '\0'; } if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound, Str("%s Nested LOOP=%d Level:%d\n"), - st, ST(repeat_cnt_n)[ST(repeat_index)], - ST(repeat_index)); + st, STA(repeat_cnt_n)[STA(repeat_index)], + STA(repeat_index)); } else { if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound, Str("External LOOP=%d Level:%d\n"), - ST(repeat_cnt_n)[ST(repeat_index)], - ST(repeat_index)); + STA(repeat_cnt_n)[STA(repeat_index)], + STA(repeat_index)); } while (c == ' ' || c == '\t') { c = getscochar(csound, 1); } for (i = 0; isNameChar(c, i) && i < (NAMELEN-1); i++) { - ST(repeat_name_n)[ST(repeat_index)][i] = c; + STA(repeat_name_n)[STA(repeat_index)][i] = c; c = getscochar(csound, 1); } - ST(repeat_name_n)[ST(repeat_index)][i] = '\0'; + STA(repeat_name_n)[STA(repeat_index)][i] = '\0'; ungetscochar(csound, c); /* Define macro for counter */ - ST(repeat_mm_n)[ST(repeat_index)]->name = - mmalloc(csound, strlen(ST(repeat_name_n)[ST(repeat_index)])+1); - strcpy(ST(repeat_mm_n)[ST(repeat_index)]->name, - ST(repeat_name_n)[ST(repeat_index)]); - ST(repeat_mm_n)[ST(repeat_index)]->acnt = 0; - ST(repeat_mm_n)[ST(repeat_index)]->body = corfile_create_r("0"); + STA(repeat_mm_n)[STA(repeat_index)]->name = + mmalloc(csound, strlen(STA(repeat_name_n)[STA(repeat_index)])+1); + strcpy(STA(repeat_mm_n)[STA(repeat_index)]->name, + STA(repeat_name_n)[STA(repeat_index)]); + STA(repeat_mm_n)[STA(repeat_index)]->acnt = 0; + STA(repeat_mm_n)[STA(repeat_index)]->body = corfile_create_r("0"); #ifdef MACDEBUG csound->DebugMsg(csound,"%s(%d): repeat %s zero %p\n", __FILE__, __LINE__, - ST(repeat_name_n)[ST(repeat_index)], - ST(repeat_mm_n)[ST(repeat_index)]->body); + STA(repeat_name_n)[STA(repeat_index)], + STA(repeat_mm_n)[STA(repeat_index)]->body); #endif - ST(repeat_mm_n)[ST(repeat_index)]->next = ST(macros); - ST(macros) = ST(repeat_mm_n)[ST(repeat_index)]; + STA(repeat_mm_n)[STA(repeat_index)]->next = STA(macros); + STA(macros) = STA(repeat_mm_n)[STA(repeat_index)]; flushlin(csound); /* Ignore rest of line */ - ST(repeat_point_n)[ST(repeat_index)] = - corfile_tell(ST(str)->cf); + STA(repeat_point_n)[STA(repeat_index)] = + corfile_tell(STA(str)->cf); /* { does not start a new section - akozar */ - /* ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(prvp2) = -FL(1.0); */ - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); - ST(nxp)++; + /* STA(clock_base) = FL(0.0); + STA(warp_factor) = FL(1.0); + STA(prvp2) = -FL(1.0); */ + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); + STA(nxp)++; goto again; } case 'r': /* For now treat as s */ /* First deal with previous section */ /* If we are in a repeat of a marked section ('n' statement), we must pop those inputs before doing an 'r' repeat. */ - if (ST(str)->is_marked_repeat) { - while (ST(str)->is_marked_repeat && ST(input_cnt) > 0) { + if (STA(str)->is_marked_repeat) { + while (STA(str)->is_marked_repeat && STA(input_cnt) > 0) { /* close all marked repeat inputs */ - /* if (ST(str)->fd != NULL) { */ - /* csound->FileClose(csound, ST(str)->fd); ST(str)->fd = NULL; */ + /* if (STA(str)->fd != NULL) { */ + /* csound->FileClose(csound, STA(str)->fd); STA(str)->fd = NULL; */ /* } */ - corfile_rm(&(ST(str)->cf)); - ST(str)--; ST(input_cnt)--; + corfile_rm(&(STA(str)->cf)); + STA(str)--; STA(input_cnt)--; } /* last time thru an 'r', cleanup up 'r' before finishing 'n' */ - if (ST(repeat_cnt) == 1) do_repeat(csound); - if (ST(repeat_cnt) == 0) { + if (STA(repeat_cnt) == 1) do_repeat(csound); + if (STA(repeat_cnt) == 0) { /* replace with 's' and end section if no previous 'r' or just finished an 'r' loop */ - ST(bp)->text[0] = 's'; - ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(prvp2) = -FL(1.0); + STA(bp)->text[0] = 's'; + STA(clock_base) = FL(0.0); + STA(warp_factor) = FL(1.0); + STA(prvp2) = -FL(1.0); return rtncod; } } - if (ST(repeat_cnt) != 0) { + if (STA(repeat_cnt) != 0) { if (do_repeat(csound)) return rtncod; } /* Then remember this state */ - *(ST(nxp)-2) = 's'; *ST(nxp)++ = LF; - if (ST(nxp) >= ST(memend)) /* if this memblk exhausted */ + *(STA(nxp)-2) = 's'; *STA(nxp)++ = LF; + if (STA(nxp) >= STA(memend)) /* if this memblk exhausted */ expand_nxp(csound); { int c, i; - ST(repeat_cnt) = 0; + STA(repeat_cnt) = 0; do { c = getscochar(csound, 1); } while (c == ' ' || c == '\t'); while (isdigit(c)) { - ST(repeat_cnt) = 10 * ST(repeat_cnt) + c - '0'; + STA(repeat_cnt) = 10 * STA(repeat_cnt) + c - '0'; c = getscochar(csound, 1); } - if (UNLIKELY(ST(repeat_cnt) <= 0 || (c != ' ' && c != '\t' && c != '\n'))) + if (UNLIKELY(STA(repeat_cnt) <= 0 || + (c != ' ' && c != '\t' && c != '\n'))) scorerr(csound, Str("r: invalid repeat count")); if (csound->oparms->msglevel & TIMEMSG) - csound->Message(csound, Str("Repeats=%d\n"), ST(repeat_cnt)); + csound->Message(csound, Str("Repeats=%d\n"), STA(repeat_cnt)); while (c == ' ' || c == '\t') { c = getscochar(csound, 1); } for (i = 0; isNameChar(c, i) && i < (NAMELEN-1); i++) { - ST(repeat_name)[i] = c; + STA(repeat_name)[i] = c; c = getscochar(csound, 1); } - ST(repeat_name)[i] = '\0'; + STA(repeat_name)[i] = '\0'; ungetscochar(csound, c); flushlin(csound); /* Ignore rest of line */ if (i) { /* Only if there is a name: define macro for counter */ - ST(repeat_mm) = (MACRO*) mmalloc(csound, sizeof(MACRO)); - ST(repeat_mm)->name = mmalloc(csound, strlen(ST(repeat_name)) + 1); - strcpy(ST(repeat_mm)->name, ST(repeat_name)); - ST(repeat_mm)->acnt = 0; - ST(repeat_mm)->body = corfile_create_r("1"); + STA(repeat_mm) = (S_MACRO*) mmalloc(csound, sizeof(S_MACRO)); + STA(repeat_mm)->name = mmalloc(csound, strlen(STA(repeat_name)) + 1); + strcpy(STA(repeat_mm)->name, STA(repeat_name)); + STA(repeat_mm)->acnt = 0; + STA(repeat_mm)->body = corfile_create_r("1"); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): 1 %p\n", __FILE__, __LINE__,ST(repeat_mm)->body); + csound->DebugMsg(csound,"%s(%d): 1 %p\n", + __FILE__, __LINE__,STA(repeat_mm)->body); #endif - ST(repeat_mm)->next = ST(macros); - ST(macros) = ST(repeat_mm); + STA(repeat_mm)->next = STA(macros); + STA(macros) = STA(repeat_mm); } - ST(repeat_point) = corfile_tell(ST(str)->cf); + STA(repeat_point) = corfile_tell(STA(str)->cf); } - ST(clock_base) = FL(0.0); - ST(warp_factor) = FL(1.0); - ST(prvp2) = -FL(1.0); + STA(clock_base) = FL(0.0); + STA(warp_factor) = FL(1.0); + STA(prvp2) = -FL(1.0); return rtncod; case 'm': /* Remember this place */ { - char *old_nxp = ST(nxp)-2; + char *old_nxp = STA(nxp)-2; char buff[200]; int c; int i = 0, j; @@ -1100,32 +1065,32 @@ if (c != '\n' && c != EOF) flushlin(csound); if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound,Str("Named section >>>%s<<<\n"), buff); - for (j=0; j<=ST(next_name); j++) - if (strcmp(buff, ST(names)[j].name)==0) break; - if (j>ST(next_name)) { - j = ++ST(next_name); - ST(names)[j].name = (char*)mmalloc(csound, i+1); - strcpy(ST(names)[j].name, buff); - } - else mfree(csound, ST(names)[j].file); - ST(names)[ST(next_name)].posit = corfile_tell(ST(str)->cf); - ST(names)[ST(next_name)].line = ST(str)->line; - ST(names)[ST(next_name)].file = - mmalloc(csound, strlen(corfile_body(ST(str)->cf)) + 1); - strcpy(ST(names)[ST(next_name)].file, corfile_body(ST(str)->cf)); + for (j=0; j<=STA(next_name); j++) + if (strcmp(buff, STA(names)[j].name)==0) break; + if (j>STA(next_name)) { + j = ++STA(next_name); + STA(names)[j].name = (char*)mmalloc(csound, i+1); + strcpy(STA(names)[j].name, buff); + } + else mfree(csound, STA(names)[j].file); + STA(names)[STA(next_name)].posit = corfile_tell(STA(str)->cf); + STA(names)[STA(next_name)].line = STA(str)->line; + STA(names)[STA(next_name)].file = + mmalloc(csound, strlen(corfile_body(STA(str)->cf)) + 1); + strcpy(STA(names)[STA(next_name)].file, corfile_body(STA(str)->cf)); if (csound->oparms->msglevel & TIMEMSG) csound->Message(csound,Str("%d: File %s position %ld\n"), - ST(next_name), ST(names)[ST(next_name)].file, - ST(names)[ST(next_name)].posit); - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); /* Undo this line */ - ST(nxp)++; + STA(next_name), STA(names)[STA(next_name)].file, + STA(names)[STA(next_name)].posit); + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); /* Undo this line */ + STA(nxp)++; goto again; /* suggested this loses a line?? */ } case 'n': { - char *old_nxp = ST(nxp)-2; + char *old_nxp = STA(nxp)-2; char buff[200]; int c; int i = 0; @@ -1136,52 +1101,51 @@ } buff[i] = '\0'; if (c != '\n' && c != EOF) flushlin(csound); - for (i = 0; i<=ST(next_name); i++) - if (strcmp(buff, ST(names)[i].name)==0) break; - if (UNLIKELY(i > ST(next_name))) + for (i = 0; i<=STA(next_name); i++) + if (strcmp(buff, STA(names)[i].name)==0) break; + if (UNLIKELY(i > STA(next_name))) sreaderr(csound, Str("Name %s not found"), buff); else { csound->Message(csound, Str("Duplicate %d: %s (%s,%ld)\n"), - i, buff, ST(names)[i].file, ST(names)[i].posit); - ST(input_cnt)++; - if (ST(input_cnt)>=ST(input_size)) { - int old = ST(str)-ST(inputs); - ST(input_size) += 20; - ST(inputs) = mrealloc(csound, ST(inputs), - ST(input_size) * sizeof(IN_STACK)); - ST(str) = &ST(inputs)[old]; /* In case it moves */ + i, buff, STA(names)[i].file, STA(names)[i].posit); + STA(input_cnt)++; + if (STA(input_cnt)>=STA(input_size)) { + int old = STA(str)-STA(inputs); + STA(input_size) += 20; + STA(inputs) = mrealloc(csound, STA(inputs), + STA(input_size) * sizeof(IN_STACK)); + STA(str) = &STA(inputs)[old]; /* In case it moves */ } - ST(str)++; - ST(str)->is_marked_repeat = 1; - /* ST(str)->cf = copy_to_corefile(csound, ST(names)[i].file, NULL, 1); */ - ST(str)->cf = corfile_create_r(ST(names)[i].file); -// ST(str)->cf = corfile_create_r(csound->GetFileName(ST(str)->fd)); - ST(str)->line = ST(names)[i].line; - corfile_set(ST(str)->cf, ST(names)[i].posit); - } - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); /* Undo this line */ - ST(nxp)++; + STA(str)++; + STA(str)->is_marked_repeat = 1; + STA(str)->cf = corfile_create_r(STA(names)[i].file); +// STA(str)->cf = corfile_create_r(csound->GetFileName(STA(str)->fd)); + STA(str)->line = STA(names)[i].line; + corfile_set(STA(str)->cf, STA(names)[i].posit); + } + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); /* Undo this line */ + STA(nxp)++; goto again; } case 'v': /* Suggestion of Bryan Bales */ { /* Set local variability of time */ - char *old_nxp = ST(nxp)-2; + char *old_nxp = STA(nxp)-2; getpfld(csound); - ST(warp_factor) = stof(csound, ST(sp)); + STA(warp_factor) = stof(csound, STA(sp)); if (csound->oparms->msglevel & TIMEMSG) - csound->Message(csound, Str("Warp_factor = %f\n"), ST(warp_factor)); + csound->Message(csound, Str("Warp_factor = %f\n"), STA(warp_factor)); flushlin(csound); - ST(op) = getop(csound); - ST(nxp) = old_nxp; - *ST(nxp)++ = ST(op); /* Undo this line */ - ST(nxp)++; + STA(op) = getop(csound); + STA(nxp) = old_nxp; + *STA(nxp)++ = STA(op); /* Undo this line */ + STA(nxp)++; goto again; } case 'x': /* Skip section */ while (1) { - switch (ST(op) = getop(csound)) { + switch (STA(op) = getop(csound)) { case 's': case 'r': case 'm': @@ -1195,22 +1159,24 @@ } } break; + case -1: + break; default: csound->Message(csound,Str("sread is confused on legal opcodes\n")); break; } } ending: - if (ST(repeat_cnt) > 0) { - ST(op) = 'e'; + if (STA(repeat_cnt) > 0) { + STA(op) = 'e'; salcblk(csound); if (do_repeat(csound)) return rtncod; - *ST(nxp)++ = LF; + *STA(nxp)++ = LF; } if (!rtncod) { /* Ending so clear macros */ - while (ST(macros) != NULL) { - undefine_score_macro(csound, ST(macros)->name); + while (STA(macros) != NULL) { + undefine_score_macro(csound, STA(macros)->name); } } return rtncod; @@ -1219,24 +1185,24 @@ static void copylin(CSOUND *csound) /* copy source line to srtblk */ { int c; - ST(nxp)--; - if (ST(nxp) >= ST(memend)) /* if this memblk exhausted */ + STA(nxp)--; + if (STA(nxp) >= STA(memend)) /* if this memblk exhausted */ expand_nxp(csound); do { c = getscochar(csound, 1); - *ST(nxp)++ = c; + *STA(nxp)++ = c; } while (c != LF && c != EOF); - if (c == EOF) *(ST(nxp)-1) = '\n'; /* Avoid EOF characters */ - ST(lincnt)++; - ST(linpos) = 0; + if (c == EOF) *(STA(nxp)-1) = '\n'; /* Avoid EOF characters */ + STA(lincnt)++; + STA(linpos) = 0; } static void copypflds(CSOUND *csound) { - ST(bp)->pcnt = 0; + STA(bp)->pcnt = 0; while (getpfld(csound)) /* copy each pfield, */ - ST(bp)->pcnt++; /* count them, */ - *(ST(nxp)-1) = LF; /* terminate with newline */ + STA(bp)->pcnt++; /* count them, */ + *(STA(nxp)-1) = LF; /* terminate with newline */ } static void ifa(CSOUND *csound) @@ -1244,64 +1210,64 @@ SRTBLK *prvbp; int n, nocarry = 0; - ST(bp)->pcnt = 0; + STA(bp)->pcnt = 0; while (getpfld(csound)) { /* while there's another pfield, */ nocarry = 0; - ++ST(bp)->pcnt; - /* if (UNLIKELY(++ST(bp)->pcnt == PMAX)) { */ + ++STA(bp)->pcnt; + /* if (UNLIKELY(++STA(bp)->pcnt == PMAX)) { */ /* sreaderr(csound, Str("instr pcount exceeds PMAX")); */ /* csound->Message(csound, Str(" remainder of line flushed\n")); */ /* flushlin(csound); */ /* continue; */ /* } */ - if (*ST(sp) == '^' && ST(op) == 'i' && ST(bp)->pcnt == 2) { + if (*STA(sp) == '^' && STA(op) == 'i' && STA(bp)->pcnt == 2) { int foundplus = 0; - if (*(ST(sp)+1)=='+') { ST(sp)++; foundplus = 1; } - if (UNLIKELY(ST(prvp2)<0)) { + if (*(STA(sp)+1)=='+') { STA(sp)++; foundplus = 1; } + if (UNLIKELY(STA(prvp2)<0)) { sreaderr(csound,Str("No previous event for ^")); - ST(prvp2) = ST(bp)->p2val = ST(warp_factor) * stof(csound, ST(sp)+1); + STA(prvp2) = STA(bp)->p2val = STA(warp_factor) * stof(csound, STA(sp)+1); } - else if (UNLIKELY(isspace(*(ST(sp)+1)))) { + else if (UNLIKELY(isspace(*(STA(sp)+1)))) { /* stof() assumes no leading whitespace -- 070204, akozar */ sreaderr(csound, Str("illegal space following %s, zero substituted"), (foundplus ? "^+" : "^")); - ST(prvp2) = ST(bp)->p2val = ST(prvp2); + STA(prvp2) = STA(bp)->p2val = STA(prvp2); } - else ST(prvp2) = ST(bp)->p2val = - ST(prvp2) + ST(warp_factor) * stof(csound, ST(sp) + 1); + else STA(prvp2) = STA(bp)->p2val = + STA(prvp2) + STA(warp_factor) * stof(csound, STA(sp) + 1); } - else if (ST(nxp)-ST(sp) == 2 && (*ST(sp) == '.' || *ST(sp) == '+')) { - if (ST(op) == 'i' - && (*ST(sp) == '.' || ST(bp)->pcnt == 2) - && ((ST(bp)->pcnt >= 2 && (prvbp = ST(prvibp)) != NULL - && ST(bp)->pcnt <= prvbp->pcnt) - || (ST(bp)->pcnt == 1 && (prvbp = ST(bp)->prvblk) != NULL + else if (STA(nxp)-STA(sp) == 2 && (*STA(sp) == '.' || *STA(sp) == '+')) { + if (STA(op) == 'i' + && (*STA(sp) == '.' || STA(bp)->pcnt == 2) + && ((STA(bp)->pcnt >= 2 && (prvbp = STA(prvibp)) != NULL + && STA(bp)->pcnt <= prvbp->pcnt) + || (STA(bp)->pcnt == 1 && (prvbp = STA(bp)->prvblk) != NULL && prvbp->text[0] == 'i'))) { - if (*ST(sp) == '.') { - ST(nxp) = ST(sp); - pcopy(csound, (int) ST(bp)->pcnt, 1, prvbp); - if (ST(bp)->pcnt >= 2) ST(prvp2) = ST(bp)->p2val; + if (*STA(sp) == '.') { + STA(nxp) = STA(sp); + pcopy(csound, (int) STA(bp)->pcnt, 1, prvbp); + if (STA(bp)->pcnt >= 2) STA(prvp2) = STA(bp)->p2val; } else /* need the fabs() in case of neg p3 */ - ST(prvp2) = ST(bp)->p2val = + STA(prvp2) = STA(bp)->p2val = prvbp->p2val + FABS(prvbp->p3val); } else carryerror(csound); } - else if (*ST(sp) == '!') { + else if (*STA(sp) == '!') { int getmore = 0; - if (UNLIKELY(ST(op) != 'i')) { - *(ST(nxp)-1) = '\0'; + if (UNLIKELY(STA(op) != 'i')) { + *(STA(nxp)-1) = '\0'; getmore = 1; - sreaderr(csound, Str("ignoring '%s' in '%c' event"), ST(sp), ST(op)); + sreaderr(csound, Str("ignoring '%s' in '%c' event"), STA(sp), STA(op)); } - else if (UNLIKELY(ST(bp)->pcnt < 4)) { + else if (UNLIKELY(STA(bp)->pcnt < 4)) { sreaderr(csound, Str("! invalid in p1, p2, or p3")); csound->Message(csound, Str(" remainder of line flushed\n")); flushlin(csound); } - else if (UNLIKELY(ST(nxp)-ST(sp) != 2)) { - sreaderr(csound, Str("illegal character after !: '%c'"), *(ST(sp)+1)); + else if (UNLIKELY(STA(nxp)-STA(sp) != 2)) { + sreaderr(csound, Str("illegal character after !: '%c'"), *(STA(sp)+1)); csound->Message(csound, Str(" remainder of line flushed\n")); flushlin(csound); } @@ -1310,73 +1276,69 @@ flushlin(csound); } /* but always delete the pfield beginning with '!' */ - ST(nxp) = ST(sp); - ST(bp)->pcnt--; + STA(nxp) = STA(sp); + STA(bp)->pcnt--; if (getmore) continue; /* not the best, but not easy to delete event */ /* since ifa() doesn't return anything */ else break; } - else switch (ST(bp)->pcnt) { /* watch for p1,p2,p3, */ + else switch (STA(bp)->pcnt) { /* watch for p1,p2,p3, */ case 1: /* & MYFLT, setinsno..*/ - if ((ST(op) == 'i' || ST(op) == 'q') && *ST(sp) == '"') { - /* csound->DebugMsg(csound,"***Entering second dubious code scnt=%d\n", csound->scnt0); */ - /* ST(bp)->p1val = ((int[4]){SSTRCOD,SSTRCOD1, - SSTRCOD2,SSTRCOD3})[csound->scnt0++]; */ - /* if (csound->scnt0>3) { */ - /* csound->scnt0 = 3; */ - /* } */ - ST(bp)->p1val = SSTRCOD; /* allow string name */ + if ((STA(op) == 'i' || STA(op) == 'q') && *STA(sp) == '"') { + /* csound->DebugMsg(csound,"***Entering second dubious code scnt=%d\n", + csound->scnt0); */ + STA(bp)->p1val = SSTRCOD; /* allow string name */ } else - ST(bp)->p1val = stof(csound, ST(sp)); - if (ST(op) == 'i') + STA(bp)->p1val = stof(csound, STA(sp)); + if (STA(op) == 'i') setprv(csound); - else ST(prvibp) = NULL; + else STA(prvibp) = NULL; break; - case 2: ST(prvp2) = ST(bp)->p2val = - ST(warp_factor)*stof(csound, ST(sp)) + ST(clock_base); + case 2: STA(prvp2) = STA(bp)->p2val = + STA(warp_factor)*stof(csound, STA(sp)) + STA(clock_base); break; - case 3: if (ST(op) == 'i') - ST(bp)->p3val = ST(warp_factor) * stof(csound, ST(sp)); - else ST(bp)->p3val = stof(csound, ST(sp)); + case 3: if (STA(op) == 'i') + STA(bp)->p3val = STA(warp_factor) * stof(csound, STA(sp)); + else STA(bp)->p3val = stof(csound, STA(sp)); break; default:break; } - switch (ST(bp)->pcnt) { /* newp2, newp3: */ - case 2: if (ST(warpin)) { /* for warpin, */ + switch (STA(bp)->pcnt) { /* newp2, newp3: */ + case 2: if (STA(warpin)) { /* for warpin, */ getpfld(csound); /* newp2 follows */ - ST(bp)->newp2 = ST(warp_factor) * stof(csound, ST(sp)) + ST(clock_base); - ST(nxp) = ST(sp); /* (skip text) */ + STA(bp)->newp2 = STA(warp_factor) * stof(csound, STA(sp)) + STA(clock_base); + STA(nxp) = STA(sp); /* (skip text) */ } - else ST(bp)->newp2 = ST(bp)->p2val; /* else use p2val */ + else STA(bp)->newp2 = STA(bp)->p2val; /* else use p2val */ break; - case 3: if (ST(warpin) && (ST(op) == 'i' || ST(op) == 'f')) { + case 3: if (STA(warpin) && (STA(op) == 'i' || STA(op) == 'f')) { getpfld(csound); /* same for newp3 */ - ST(bp)->newp3 = ST(warp_factor) * stof(csound, ST(sp)); - ST(nxp) = ST(sp); + STA(bp)->newp3 = STA(warp_factor) * stof(csound, STA(sp)); + STA(nxp) = STA(sp); } - else ST(bp)->newp3 = ST(bp)->p3val; + else STA(bp)->newp3 = STA(bp)->p3val; break; } } - if (ST(op) == 'i' && !nocarry && /* then carry any rem pflds */ - ((prvbp = ST(prvibp)) != NULL || - (!ST(bp)->pcnt && (prvbp = ST(bp)->prvblk) != NULL && + if (STA(op) == 'i' && !nocarry && /* then carry any rem pflds */ + ((prvbp = STA(prvibp)) != NULL || + (!STA(bp)->pcnt && (prvbp = STA(bp)->prvblk) != NULL && prvbp->text[0] == 'i')) && - (n = prvbp->pcnt - ST(bp)->pcnt) > 0) { - pcopy(csound, (int) ST(bp)->pcnt + 1, n, prvbp); - ST(bp)->pcnt += n; + (n = prvbp->pcnt - STA(bp)->pcnt) > 0) { + pcopy(csound, (int) STA(bp)->pcnt + 1, n, prvbp); + STA(bp)->pcnt += n; } - *(ST(nxp)-1) = LF; /* terminate this stmnt with newline */ + *(STA(nxp)-1) = LF; /* terminate this stmnt with newline */ } static void setprv(CSOUND *csound) /* set insno = (int) p1val */ { /* prvibp = prv note, same insno */ - SRTBLK *p = ST(bp); + SRTBLK *p = STA(bp); int16 n; - if (ST(bp)->p1val == SSTRCOD && *ST(sp) == '"') { /* IV - Oct 31 2002 */ - char name[MAXNAME], *c, *s = ST(sp); + if (ISSTRCOD(STA(bp)->p1val) && *STA(sp) == '"') { /* IV - Oct 31 2002 */ + char name[MAXNAME], *c, *s = STA(sp); /* unquote instrument name */ c = name; while (*++s != '"') *c++ = *s; *c = '\0'; /* find corresponding insno */ @@ -1386,15 +1348,15 @@ n = -1; } } - else n = (int16) ST(bp)->p1val; /* set current insno */ - ST(bp)->insno = n; + else n = (int16) STA(bp)->p1val; /* set current insno */ + STA(bp)->insno = n; while ((p = p->prvblk) != NULL) if (p->insno == n) { - ST(prvibp) = p; /* find prev same */ + STA(prvibp) = p; /* find prev same */ return; } - ST(prvibp) = NULL; /* if there is one */ + STA(prvibp) = NULL; /* if there is one */ } static void carryerror(CSOUND *csound) /* print offending text line */ @@ -1403,13 +1365,13 @@ csound->Message(csound, Str("sread: illegal use of carry, " " 0 substituted\n")); - *(ST(nxp) - 3) = SP; - p = ST(bp)->text; - while (p <= ST(nxp) - 2) + *(STA(nxp) - 3) = SP; + p = STA(bp)->text; + while (p <= STA(nxp) - 2) csound->Message(csound, "%c", *p++); csound->Message(csound, "<=\n"); print_input_backtrace(csound, 1, csoundMessage); - *(ST(nxp) - 2) = '0'; + *(STA(nxp) - 2) = '0'; } static void pcopy(CSOUND *csound, int pfno, int ncopy, SRTBLK *prvbp) @@ -1426,7 +1388,7 @@ while (*pp++ != SP) /* locate starting pfld */ ; n = ncopy; - p = ST(nxp); + p = STA(nxp); while (n--) { /* and copy n pflds */ if (*pp != '"') while ((*p++ = c = *pp++) != SP && c != LF) @@ -1438,67 +1400,67 @@ *p++ = *pp++; } switch (pfno) { - case 1: ST(bp)->p1val = prvbp->p1val; /* with p1-p3 vals */ + case 1: STA(bp)->p1val = prvbp->p1val; /* with p1-p3 vals */ setprv(csound); break; case 2: if (*(p-2) == '+') /* (interpr . of +) */ - ST(prvp2) = ST(bp)->p2val = prvbp->p2val + FABS(prvbp->p3val); - else ST(prvp2) = ST(bp)->p2val = prvbp->p2val; - ST(bp)->newp2 = ST(bp)->p2val; + STA(prvp2) = STA(bp)->p2val = prvbp->p2val + FABS(prvbp->p3val); + else STA(prvp2) = STA(bp)->p2val = prvbp->p2val; + STA(bp)->newp2 = STA(bp)->p2val; break; - case 3: ST(bp)->newp3 = ST(bp)->p3val = prvbp->p3val; + case 3: STA(bp)->newp3 = STA(bp)->p3val = prvbp->p3val; break; default:break; } - ST(bp)->lineno = prvbp->lineno; + STA(bp)->lineno = prvbp->lineno; pfno++; } - ST(nxp) = p; /* adjust globl nxp pntr */ + STA(nxp) = p; /* adjust globl nxp pntr */ } static void salcinit(CSOUND *csound) { /* init the sorter mem space for a new section */ - if (ST(curmem) == NULL) { /* alloc 1st memblk if nec; init *nxp to this */ - ST(curmem) = (char*) mmalloc(csound, (size_t) (MEMSIZ + MARGIN)); - ST(memend) = (char*) ST(curmem) + MEMSIZ; + if (STA(curmem) == NULL) { /* alloc 1st memblk if nec; init *nxp to this */ + STA(curmem) = (char*) mmalloc(csound, (size_t) (MEMSIZ + MARGIN)); + STA(memend) = (char*) STA(curmem) + MEMSIZ; } - ST(nxp) = (char*) ST(curmem); + STA(nxp) = (char*) STA(curmem); } static void salcblk(CSOUND *csound) { /* alloc a srtblk from current mem space: */ SRTBLK *prvbp; /* align following *nxp, set new bp, nxp */ /* set srtblk lnks, put op+blank in text */ - if (ST(nxp) >= ST(memend)) /* if this memblk exhausted */ + if (STA(nxp) >= STA(memend)) /* if this memblk exhausted */ expand_nxp(csound); /* now allocate a srtblk from this space: */ - prvbp = ST(bp); - ST(bp) = (SRTBLK*) (((uintptr_t) ST(nxp) + (uintptr_t)7) & ~((uintptr_t)7)); + prvbp = STA(bp); + STA(bp) = (SRTBLK*) (((uintptr_t) STA(nxp) + (uintptr_t)7) & ~((uintptr_t)7)); if (csound->frstbp == NULL) - csound->frstbp = ST(bp); + csound->frstbp = STA(bp); if (prvbp != NULL) - prvbp->nxtblk = ST(bp); /* link with prev srtblk */ - ST(bp)->nxtblk = NULL; - ST(bp)->prvblk = prvbp; - ST(bp)->insno = 0; - ST(bp)->pcnt = 0; - ST(bp)->lineno = ST(lincnt); - ST(nxp) = &(ST(bp)->text[0]); - *ST(nxp)++ = ST(op); /* place op, blank into text */ - *ST(nxp)++ = SP; - *ST(nxp) = '\0'; + prvbp->nxtblk = STA(bp); /* link with prev srtblk */ + STA(bp)->nxtblk = NULL; + STA(bp)->prvblk = prvbp; + STA(bp)->insno = 0; + STA(bp)->pcnt = 0; + STA(bp)->lineno = STA(lincnt); + STA(nxp) = &(STA(bp)->text[0]); + *STA(nxp)++ = STA(op); /* place op, blank into text */ + *STA(nxp)++ = SP; + *STA(nxp) = '\0'; } void sfree(CSOUND *csound) /* free all sorter allocated space */ { /* called at completion of sort */ - sread_alloc_globals(csound); - if (ST(curmem) != NULL) { - mfree(csound, ST(curmem)); - ST(curmem) = NULL; - } - while (ST(str) != &ST(inputs)[0]) { - corfile_rm(&(ST(str)->cf)); - ST(str)--; + /* sread_alloc_globals(csound); */ + if (STA(curmem) != NULL) { + mfree(csound, STA(curmem)); + STA(curmem) = NULL; + } + while (STA(str) != &STA(inputs)[0]) { + corfile_rm(&(STA(str)->cf)); + STA(str)--; } corfile_rm(&(csound->scorestr)); } @@ -1508,8 +1470,8 @@ int c; while ((c = getscochar(csound, 0)) != LF && c != EOF) ; - ST(linpos) = 0; - ST(lincnt)++; + STA(linpos) = 0; + STA(lincnt)++; } static inline int check_preproc_name(CSOUND *csound, const char *name) @@ -1531,8 +1493,8 @@ srch: while ((c = getscochar(csound, 1)) == SP || c == '\t' || c == LF) if (c == LF) { - ST(lincnt)++; - ST(linpos) = 0; + STA(lincnt)++; + STA(linpos) = 0; } if (c == ';' || c == 'c') { flushlin(csound); @@ -1575,7 +1537,7 @@ while (isspace((c = getscochar(csound, 1)))); if (c == 'd') { int arg = 0; - MACRO *mm = (MACRO*) mmalloc(csound, sizeof(MACRO)); + S_MACRO *mm = (S_MACRO*) mmalloc(csound, sizeof(S_MACRO)); mm->margs = MARGS; if (UNLIKELY(!check_preproc_name(csound, "define"))) { csound->Message(csound, Str("Not #define")); @@ -1586,8 +1548,16 @@ } while (isspace((c = getscochar(csound, 1)))); while (isNameChar(c, i)) { + char *new; mname[i++] = c; - if (i==mlen) mname = (char *)realloc(mname, mlen+=40); + if (i==mlen) { + new = (char *)realloc(mname, mlen+=40); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + mname = new; + } c = getscochar(csound, 1); } mname[i] = '\0'; @@ -1600,16 +1570,24 @@ while (isspace((c = getscochar(csound, 1)))); i = 0; while (isNameChar(c, i)) { + char *new; mname[i++] = c; - if (i==mlen) mname = (char *)realloc(mname, mlen+=40); + if (i==mlen) { + new = (char *)realloc(mname, mlen+=40); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + mname = new; + } c = getscochar(csound, 1); } mname[i] = '\0'; mm->arg[arg] = mmalloc(csound, i+1); strcpy(mm->arg[arg++], mname); if (arg>=mm->margs) { - mm = (MACRO*)mrealloc(csound, mm, - sizeof(MACRO)+mm->margs*sizeof(char*)); + mm = (S_MACRO*)mrealloc(csound, mm, + sizeof(S_MACRO)+mm->margs*sizeof(char*)); mm->margs += MARGS; } while (isspace(c)) c = getscochar(csound, 1); @@ -1628,7 +1606,8 @@ } mm->body = corfile_create_w(); #ifdef MACDEBUG - csound->DebugMsg(csound,"%s(%d): macro %s %p\n", __FILE__, __LINE__, mname, mm->body); + csound->DebugMsg(csound,"%s(%d): macro %s %p\n", + __FILE__, __LINE__, mname, mm->body); #endif while ((c = getscochar(csound, 0)) != '#') { /* Do not expand here!! */ if (UNLIKELY(c==EOF)) @@ -1637,11 +1616,11 @@ if (c=='\\') { corfile_putc(getscochar(csound, 0), mm->body); /* Allow escaped # */ } - if (c=='\n') ST(lincnt)++; + if (c=='\n') STA(lincnt)++; } corfile_rewind(mm->body); - mm->next = ST(macros); - ST(macros) = mm; + mm->next = STA(macros); + STA(macros) = mm; #ifdef MACDEBUG csound->Message(csound, Str("Macro %s with %d arguments defined\n"), mm->name, mm->acnt); @@ -1664,30 +1643,43 @@ delim = c; i = 0; while ((c=getscochar(csound, 1))!=delim) { + char *new; mname[i++] = c; - if (i==mlen) mname = (char *)realloc(mname, mlen+=40); + if (i==mlen) { + new = (char *)realloc(mname, mlen+=40); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + mname = new; + } } mname[i]='\0'; while ((c=getscochar(csound, 1))!='\n'); - ST(input_cnt)++; - if (ST(input_cnt)>=ST(input_size)) { - int old = ST(str)-ST(inputs); - ST(input_size) += 20; - ST(inputs) = mrealloc(csound, ST(inputs), ST(input_size) + STA(input_cnt)++; + if (STA(input_cnt)>=STA(input_size)) { + int old = STA(str)-STA(inputs); + STA(input_size) += 20; + STA(inputs) = mrealloc(csound, STA(inputs), STA(input_size) * sizeof(IN_STACK)); - ST(str) = &ST(inputs)[old]; /* In case it moves */ + STA(str) = &STA(inputs)[old]; /* In case it moves */ } - ST(str)++; - ST(str)->is_marked_repeat = 0; - ST(str)->cf = copy_to_corefile(csound, mname, "INCDIR", 1); - if (ST(str)->cf == NULL) { - ST(str)--; - ST(str)->line--; /* include was one line earlier */ - ST(linepos) = 0; + STA(str)++; + STA(str)->is_marked_repeat = 0; +#ifdef HAVE_CURL + if (strstr(mname, "://")) + STA(str)->cf = copy_url_corefile(csound, mname, 1); + else +#endif + STA(str)->cf = copy_to_corefile(csound, mname, "INCDIR", 1); + if (STA(str)->cf == NULL) { + STA(str)--; + STA(str)->line--; /* include was one line earlier */ + STA(linepos) = 0; scorerr(csound, Str("Cannot open #include'd file %s"), mname); } else { - ST(str)->line = 1; + STA(str)->line = 1; free(mname); goto srch; } @@ -1701,8 +1693,16 @@ } while (isspace((c = getscochar(csound, 1)))); while (isNameChar(c, i)) { + char *new; mname[i++] = c; - if (i==mlen) mname = (char *)realloc(mname, mlen+=40); + if (i==mlen) { + new = (char *)realloc(mname, mlen+=40); + if (new==NULL) { + fprintf(stderr, "Out of Memory\n"); + exit(7); + } + mname = new; + } c = getscochar(csound, 1); } mname[i] = '\0'; @@ -1755,7 +1755,7 @@ flushlin(csound); goto nextc; } - ST(linpos)++; + STA(linpos)++; return(c); } @@ -1772,21 +1772,21 @@ && c!='p' && c!='<' && c!='>' && c!='(' && c!=')' && c!='"' && c!='~' && c!='!' && c!='z') { ungetscochar(csound, c); /* then no more pfields */ - if (UNLIKELY(ST(linpos))) { + if (UNLIKELY(STA(linpos))) { sreaderr(csound, Str("unexpected char %c"), c); csound->Message(csound, Str(" remainder of line flushed\n")); flushlin(csound); } return(0); /* so return */ } - p = ST(sp) = ST(nxp); /* else start copying to text */ + p = STA(sp) = STA(nxp); /* else start copying to text */ *p++ = c; - ST(linpos)++; + STA(linpos)++; if (c == '"') { /* if have quoted string, */ /* IV - Oct 31 2002: allow string instr name for i and q events */ - if (UNLIKELY(ST(bp)->pcnt < 3 && - !((ST(op) == 'i' || ST(op) == 'q') && - !ST(bp)->pcnt))) { + if (UNLIKELY(STA(bp)->pcnt < 3 && + !((STA(op) == 'i' || STA(op) == 'q') && + !STA(bp)->pcnt))) { sreaderr(csound, Str("illegally placed string")); csound->Message(csound, Str(" remainder of line flushed\n")); flushlin(csound); @@ -1799,7 +1799,7 @@ } *p++ = c; /* copy to matched quote */ /* **** CHECK **** */ - if (p >= ST(memend)) + if (p >= STA(memend)) p = (char*) ((uintptr_t) p + expand_nxp(csound)); /* **** END CHECK **** */ } @@ -1815,7 +1815,7 @@ c==')' || c=='~' || c=='z') { *p++ = c; /* **** CHECK **** */ - if (p >= ST(memend)) + if (p >= STA(memend)) p = (char*) ((uintptr_t) p + expand_nxp(csound)); /* **** END CHECK **** */ } @@ -1826,7 +1826,7 @@ } blank: *p++ = SP; - ST(nxp) = p; /* add blank */ + STA(nxp) = p; /* add blank */ return(1); /* and report ok */ } @@ -1834,7 +1834,7 @@ /* (assumes no white space at beginning */ { /* but a blank or nl at end) */ char *p; - MYFLT x = (MYFLT) strtod(s, &p); + MYFLT x = (MYFLT) cs_strtod(s, &p); if (*p=='z') return FL(800000000000.0); /* 25367 years */ if (UNLIKELY(s == p || !(*p == '\0' || isspace(*p)))) { diff -Nru csound-5.17.11~dfsg/Engine/swrite.c csound-6.02~dfsg/Engine/swrite.c --- csound-5.17.11~dfsg/Engine/swrite.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/swrite.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,527 +0,0 @@ -/* - swrite.c: - - Copyright (C) 1991 Barry Vercoe, John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#include "csoundCore.h" /* SWRITE.C */ -#include -#include -#include - -static SRTBLK *nxtins(SRTBLK *), *prvins(SRTBLK *); -static char *pfout(CSOUND *,SRTBLK *, char *, int, int); -static char *nextp(CSOUND *,SRTBLK *, char *, int, int); -static char *prevp(CSOUND *,SRTBLK *, char *, int, int); -static char *ramp(CSOUND *,SRTBLK *, char *, int, int); -static char *expramp(CSOUND *,SRTBLK *, char *, int, int); -static char *randramp(CSOUND *,SRTBLK *, char *, int, int); -static char *pfStr(CSOUND *,char *, int, int); -static char *fpnum(CSOUND *,char *, int, int); - -#define fltout(n) fprintf(csound->scoreout, "%.6f", n) - -void swrite(CSOUND *csound) -{ - SRTBLK *bp; - char *p, c, isntAfunc; - int lincnt, pcnt=0; - - if (UNLIKELY((bp = csound->frstbp) == NULL)) - return; - lincnt = 0; - if ((c = bp->text[0]) != 'w' - && c != 's' && c != 'e') { /* if no warp stmnt but real data, */ - fprintf(csound->scoreout, "w 0 60\n"); /* create warp-format indicator */ - lincnt++; - } - nxtlin: - lincnt++; /* now for each line: */ - p = bp->text; - c = *p++; - isntAfunc = 1; - switch (c) { - case 'f': - isntAfunc = 0; - case 'q': - case 'i': - case 'a': - putc(c, csound->scoreout); - putc(*p++, csound->scoreout); - while ((c = *p++) != SP && c != LF) - putc(c, csound->scoreout); /* put p1 */ - putc(c, csound->scoreout); - if (c == LF) - break; - fltout(bp->p2val); /* put p2val, */ - putc(SP, csound->scoreout); - fltout(bp->newp2); /* newp2, */ - while ((c = *p++) != SP && c != LF) - ; - putc(c, csound->scoreout); /* and delim */ - if (c == LF) - break; - if (isntAfunc) { - fltout(bp->p3val); /* put p3val, */ - putc(SP, csound->scoreout); - fltout(bp->newp3); /* newp3, */ - while ((c = *p++) != SP && c != LF) - ; - } - else { /*make sure p3s (table length) are ints */ - char temp[256]; - sprintf(temp,"%d ",(int32)bp->p3val); /* put p3val */ - fpnum(csound,temp, lincnt, pcnt); - putc(SP, csound->scoreout); - sprintf(temp,"%d ",(int32)bp->newp3); /* put newp3 */ - fpnum(csound,temp, lincnt, pcnt); - while ((c = *p++) != SP && c != LF) - ; - } - pcnt = 3; - while (c != LF) { - pcnt++; - putc(SP, csound->scoreout); - p = pfout(csound,bp,p,lincnt,pcnt); /* now put each pfield */ - c = *p++; - } - putc('\n', csound->scoreout); - break; - case 's': - case 'e': - if (bp->pcnt > 0) - fprintf(csound->scoreout, "f 0 %f %f\n", bp->p2val, bp->newp2); - putc(c, csound->scoreout); - putc(LF, csound->scoreout); - break; - case 'w': - case 't': - putc(c, csound->scoreout); - while ((c = *p++) != LF) /* put entire line */ - putc(c, csound->scoreout); - putc(LF, csound->scoreout); - break; - default: - csound->Message(csound, - Str("swrite: unexpected opcode, section %d line %d\n"), - csound->sectcnt, lincnt); - break; - } - if ((bp = bp->nxtblk) != NULL) - goto nxtlin; -} - -static char *pfout(CSOUND *csound, SRTBLK *bp, char *p,int lincnt, int pcnt) -{ - switch (*p) { - case 'n': - p = nextp(csound, bp,p, lincnt, pcnt); - break; - case 'p': - p = prevp(csound, bp,p, lincnt, pcnt); - break; - case '<': - case '>': - p = ramp(csound, bp,p, lincnt, pcnt); - break; - case '(': - case ')': - p = expramp(csound, bp, p, lincnt, pcnt); - break; - case '~': - p = randramp(csound, bp, p, lincnt, pcnt); - break; - case '"': - p = pfStr(csound, p, lincnt, pcnt); - break; - default: - p = fpnum(csound, p, lincnt, pcnt); - break; - } - return(p); -} - -static SRTBLK *nxtins(SRTBLK *bp) /* find nxt note with same p1 */ -{ - MYFLT p1; - - p1 = bp->p1val; - while ((bp = bp->nxtblk) != NULL - && (bp->p1val != p1 || bp->text[0] != 'i')) - ; - return(bp); -} - -static SRTBLK *prvins(SRTBLK *bp) /* find prv note with same p1 */ -{ - MYFLT p1; - - p1 = bp->p1val; - while ((bp = bp->prvblk) != NULL - && (bp->p1val != p1 || bp->text[0] != 'i')) - ; - return(bp); -} - -static char *nextp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) -{ - char *q; - int n; - - q = p; - p++; /* 1st char */ - if (UNLIKELY(*p++ != 'p')) /* 2nd char */ - goto error; - n = 999; - if (isdigit(*p)) - n = *p++ - '0'; - if (isdigit(*p)) /* n is np subscript no */ - n = 10*n + (*p++ - '0'); - if (UNLIKELY(*p != SP && *p != LF)) - goto error; - if (LIKELY((bp = nxtins(bp)) != NULL /* for nxtins, same p1 */ - && n <= bp->pcnt)) { - q = bp->text; - while (n--) - while (*q++ != SP) /* go find the pfield */ - ; - pfout(csound,bp,q,lincnt,pcnt); /* and put it out */ - } - else { - error: - csound->Message(csound,Str("swrite: output, sect%d line%d p%d makes" - " illegal reference to "), - csound->sectcnt,lincnt,pcnt); - while (q < p) - csound->Message(csound,"%c", *q++); - while (*p != SP && *p != LF) - csound->Message(csound,"%c", *p++); - csound->Message(csound,Str(" Zero substituted\n")); - putc('0', csound->scoreout); - } - return(p); -} - -static char *prevp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) -{ - char *q; - int n; - - q = p; - p++; /* 1st char */ - if (UNLIKELY(*p++ != 'p')) /* 2nd char */ - goto error; - n = 999; - if (isdigit(*p)) - n = *p++ - '0'; - if (isdigit(*p)) /* n is np subscript no */ - n = 10*n + (*p++ - '0'); - if (UNLIKELY(*p != SP && *p != LF)) - goto error; - if (LIKELY((bp = prvins(bp)) != NULL /* for prvins, same p1, */ - && n <= bp->pcnt)) { - q = bp->text; - while (n--) - while (*q++ != SP) /* go find the pfield */ - ; - pfout(csound,bp,q,lincnt,pcnt); /* and put it out */ - } - else { - error: - csound->Message(csound, - Str("swrite: output, sect%d line%d p%d makes illegal reference to "), - csound->sectcnt,lincnt,pcnt); - while (q < p) - csound->Message(csound,"%c", *q++); - while (*p != SP && *p != LF) - csound->Message(csound,"%c", *p++); - csound->Message(csound,Str(" Zero substituted\n")); - putc('0', csound->scoreout); - } - return(p); -} - -static char *ramp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) - /* NB np's may reference a ramp but ramps must terminate in valid nums */ -{ - char *q; - char *psav; - SRTBLK *prvbp, *nxtbp; - MYFLT pval, qval, rval, p2span; - extern MYFLT stof(CSOUND *, char *); - int pnum, n; - - psav = ++p; - if (UNLIKELY(*psav != SP && *psav != LF)) - goto error1; - pnum = 0; - q = bp->text; - while (q < p) - if (*q++ == SP) - pnum++; - prvbp = bp; - backup: - if (LIKELY((prvbp = prvins(prvbp)) != NULL)) { - p = prvbp->text; - n = pnum; - while (n--) - while (*p++ != SP) - ; - if (*p == '>' || *p == '<') - goto backup; - } - else goto error2; - nxtbp = bp; - forwrd: - if (LIKELY((nxtbp = nxtins(nxtbp)) != NULL)) { - q = nxtbp->text; - n = pnum; - while (n--) - while (*q++ != SP) - ; - if (*q == '>' || *q == '<') - goto forwrd; - } - else goto error2; - pval = stof(csound, p); /* the error msgs generated by stof */ - qval = stof(csound, q); /* are misleading */ - if (UNLIKELY((p2span = nxtbp->newp2 - prvbp->newp2) <= 0)) - goto error2; - rval = (qval - pval) * (bp->newp2 - prvbp->newp2) / p2span + pval; - fltout(rval); - return(psav); - - error1: - csound->Message(csound, - Str("swrite: output, sect%d line%d p%d has illegal ramp symbol\n"), - csound->sectcnt,lincnt,pcnt); - goto put0; - error2: - csound->Message(csound, Str("swrite: output, sect%d line%d p%d ramp " - "has illegal forward or backward ref\n"), - csound->sectcnt, lincnt, pcnt); - put0: - putc('0', csound->scoreout); - return(psav); -} - -static char *expramp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) - /* NB np's may reference a ramp but ramps must terminate in valid nums */ -{ - char *q; - char *psav; - SRTBLK *prvbp, *nxtbp; - MYFLT pval, qval, rval; - double p2span; - extern MYFLT stof(CSOUND *, char *); - int pnum, n; - - psav = ++p; - if (UNLIKELY(*psav != SP && *psav != LF)) - goto error1; - pnum = 0; - q = bp->text; - while (q < p) - if (*q++ == SP) - pnum++; - prvbp = bp; - backup: - if (LIKELY((prvbp = prvins(prvbp)) != NULL)) { - p = prvbp->text; - n = pnum; - while (n--) - while (*p++ != SP) - ; - if (*p == '}' || *p == '{' || *p == '(' || *p == ')') - goto backup; - } - else goto error2; - nxtbp = bp; - forwrd: - if (LIKELY((nxtbp = nxtins(nxtbp)) != NULL)) { - q = nxtbp->text; - n = pnum; - while (n--) - while (*q++ != SP) - ; - if (*q == '}' || *q == '{' || *q == '(' || *q == ')') - goto forwrd; - } - else goto error2; - pval = stof(csound, p); /* the error msgs generated by stof */ - qval = stof(csound, q); /* are misleading */ - p2span = (double)(nxtbp->newp2 - prvbp->newp2); -/* printf("pval=%f qval=%f span = %f\n", pval, qval, p2span); */ - rval = pval * (MYFLT)pow((double)(qval/pval), - (double)(bp->newp2 - prvbp->newp2) / p2span); -/* printf("rval=%f bp->newp2=%f prvbp->newp2-%f\n", - rval, bp->newp2, prvbp->newp2); */ - fltout(rval); - return(psav); - - error1: - csound->Message(csound,Str("swrite: output, sect%d line%d p%d has illegal" - " expramp symbol\n"), - csound->sectcnt,lincnt,pcnt); - goto put0; - error2: - csound->Message(csound, Str("swrite: output, sect%d line%d p%d expramp " - "has illegal forward or backward ref\n"), - csound->sectcnt, lincnt, pcnt); - put0: - putc('0', csound->scoreout); - return(psav); -} - -static char *randramp(CSOUND *csound, - SRTBLK *bp, char *p, int lincnt, int pcnt) - /* NB np's may reference a ramp but ramps must terminate in valid nums */ -{ - char *q; - char *psav; - SRTBLK *prvbp, *nxtbp; - MYFLT pval, qval, rval; - extern MYFLT stof(CSOUND *, char *); - int pnum, n; - - psav = ++p; - if (UNLIKELY(*psav != SP && *psav != LF)) - goto error1; - pnum = 0; - q = bp->text; - while (q < p) - if (*q++ == SP) - pnum++; - prvbp = bp; - backup: - if (LIKELY((prvbp = prvins(prvbp)) != NULL)) { - p = prvbp->text; - n = pnum; - while (n--) - while (*p++ != SP) - ; - if (UNLIKELY(*p == '~')) - goto backup; - } - else goto error2; - nxtbp = bp; - forwrd: - if (LIKELY((nxtbp = nxtins(nxtbp)) != NULL)) { - q = nxtbp->text; - n = pnum; - while (n--) - while (*q++ != SP) - ; - if (*q == '~') - goto forwrd; - } - else goto error2; - pval = stof(csound, p); /* the error msgs generated by stof */ - qval = stof(csound, q); /* are misleading */ - rval = (MYFLT) (((double) (csound->Rand31(&(csound->randSeed1)) - 1) - / 2147483645.0) * ((double) qval - (double) pval) - + (double) pval); - fltout(rval); - return(psav); - - error1: - csound->Message(csound,Str("swrite: output, sect%d line%d p%d has illegal" - " expramp symbol\n"), - csound->sectcnt,lincnt,pcnt); - goto put0; - error2: - csound->Message(csound,Str("swrite: output, sect%d line%d p%d expramp has" - " illegal forward or backward ref\n"), - csound->sectcnt,lincnt,pcnt); - put0: - putc('0', csound->scoreout); - return(psav); -} - -static char *pfStr(CSOUND *csound, char *p, int lincnt, int pcnt) -{ /* moves quoted ascii string to SCOREOUT file */ - char *q = p; /* with no internal format chk */ - putc(*p++, csound->scoreout); - while (*p != '"') - putc(*p++, csound->scoreout); - putc(*p++, csound->scoreout); - if (UNLIKELY(*p != SP && *p != LF)) { - csound->Message(csound, Str("swrite: output, sect%d line%d p%d " - "has illegally terminated string "), - csound->sectcnt, lincnt, pcnt); - while (q < p) - csound->Message(csound,"%c", *q++); - while (*p != SP && *p != LF) - csound->Message(csound,"%c", *p++); - csound->Message(csound,"\n"); - } - return(p); -} - -static char *fpnum(CSOUND *csound, - char *p, int lincnt, int pcnt) /* moves ascii string */ - /* to SCOREOUT file with fpnum format chk */ -{ - char *q; - int dcnt; - - q = p; - if (*p == '+') - p++; - if (*p == '-') - putc(*p++, csound->scoreout); - dcnt = 0; - while (isdigit(*p)) { - putc(*p++, csound->scoreout); - dcnt++; - } - if (*p == '.') - putc(*p++, csound->scoreout); - while (isdigit(*p)) { - putc(*p++, csound->scoreout); - dcnt++; - } - if (*p == 'E' || *p == 'e') { /* Allow exponential notation */ - putc(*p++, csound->scoreout); - dcnt++; - if (*p == '+' || *p == '-') { - putc(*p++, csound->scoreout); - dcnt++; - } - while (isdigit(*p)) { - putc(*p++, csound->scoreout); - dcnt++; - } - } - if (UNLIKELY((*p != SP && *p != LF) || !dcnt)) { - csound->Message(csound,Str("swrite: output, sect%d line%d p%d has " - "illegal number "), - csound->sectcnt,lincnt,pcnt); - while (q < p) - csound->Message(csound,"%c", *q++); - while (*p != SP && *p != LF) - csound->Message(csound,"%c", *p++); - csound->Message(csound,Str(" String truncated\n")); - if (!dcnt) - putc('0', csound->scoreout); - } - return(p); -} - diff -Nru csound-5.17.11~dfsg/Engine/swritestr.c csound-6.02~dfsg/Engine/swritestr.c --- csound-5.17.11~dfsg/Engine/swritestr.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/swritestr.c 2014-01-07 16:53:47.000000000 +0000 @@ -28,25 +28,40 @@ #include "corfile.h" static SRTBLK *nxtins(SRTBLK *), *prvins(SRTBLK *); -static char *pfout(CSOUND *,SRTBLK *, char *, int, int); -static char *nextp(CSOUND *,SRTBLK *, char *, int, int); -static char *prevp(CSOUND *,SRTBLK *, char *, int, int); -static char *ramp(CSOUND *,SRTBLK *, char *, int, int); -static char *expramp(CSOUND *,SRTBLK *, char *, int, int); -static char *randramp(CSOUND *,SRTBLK *, char *, int, int); -static char *pfStr(CSOUND *,char *, int, int); -static char *fpnum(CSOUND *,char *, int, int); +static char *pfout(CSOUND *,SRTBLK *, char *, int, int, CORFIL *sco); +static char *nextp(CSOUND *,SRTBLK *, char *, int, int, CORFIL *sco); +static char *prevp(CSOUND *,SRTBLK *, char *, int, int, CORFIL *sco); +static char *ramp(CSOUND *,SRTBLK *, char *, int, int, CORFIL *sco); +static char *expramp(CSOUND *,SRTBLK *, char *, int, int,CORFIL *sco); +static char *randramp(CSOUND *,SRTBLK *, char *, int, int, CORFIL *sco); +static char *pfStr(CSOUND *,char *, int, int, CORFIL *sco); +static char *fpnum(CSOUND *,char *, int, int, CORFIL *sco); -static void fltout(CSOUND *csound, MYFLT n) +static void fltout(CSOUND *csound, MYFLT n, CORFIL *sco) { char *c, buffer[1024]; - sprintf(buffer, "%.6f", n); - /* corfile_puts(buffer, csound->scstr); */ + CS_SPRINTF(buffer, "%.6f", n); + /* corfile_puts(buffer, sco); */ for (c = buffer; *c != '\0'; c++) - corfile_putc(*c, csound->scstr); + corfile_putc(*c, sco); } -void swritestr(CSOUND *csound) +/* + The 'first' parameter was added so that the + copies of p2 and p3 are made only in scores + loaded before the first compilation before + performance starts; in this case swritestr() + is called with first = 0; + In the case of scores passed in after Csound + is running, events are scheduled as RT events + through the linevent mechanism (linevent.c) + and in that scenario, cannot contain duplicate + p2 and p3 values. In this case, swritestr() is + called with first = 1; + VL - new in Csound 6. +*/ + +void swritestr(CSOUND *csound, CORFIL *sco, int first) { SRTBLK *bp; char *p, c, isntAfunc; @@ -59,7 +74,7 @@ if ((c = bp->text[0]) != 'w' && c != 's' && c != 'e') { /* if no warp stmnt but real data, */ /* create warp-format indicator */ - corfile_puts("w 0 60\n", csound->scstr); + if(first) corfile_puts("w 0 60\n", sco); lincnt++; } nxtlin: @@ -73,63 +88,67 @@ case 'q': case 'i': case 'a': - corfile_putc(c, csound->scstr); - corfile_putc(*p++, csound->scstr); + corfile_putc(c, sco); + corfile_putc(*p++, sco); while ((c = *p++) != SP && c != LF) - corfile_putc(c, csound->scstr); /* put p1 */ - corfile_putc(c, csound->scstr); + corfile_putc(c, sco); /* put p1 */ + corfile_putc(c, sco); if (c == LF) break; - fltout(csound, bp->p2val); /* put p2val, */ - corfile_putc(SP, csound->scstr); - fltout(csound, bp->newp2); /* newp2, */ + fltout(csound, bp->p2val, sco); /* put p2val, */ + corfile_putc(SP, sco); + if (first) fltout(csound, bp->newp2, sco); /* newp2, */ while ((c = *p++) != SP && c != LF) ; - corfile_putc(c, csound->scstr); /* and delim */ + corfile_putc(c, sco); /* and delim */ if (c == LF) break; if (isntAfunc) { - fltout(csound, bp->p3val); /* put p3val, */ - corfile_putc(SP, csound->scstr); - fltout(csound, bp->newp3); /* newp3, */ + fltout(csound, bp->p3val, sco); /* put p3val, */ + corfile_putc(SP, sco); + if (first) fltout(csound, bp->newp3, sco); /* newp3, */ while ((c = *p++) != SP && c != LF) ; } else { /*make sure p3s (table length) are ints */ char temp[256]; sprintf(temp,"%d ",(int32)bp->p3val); /* put p3val */ - fpnum(csound,temp, lincnt, pcnt); - corfile_putc(SP, csound->scstr); - sprintf(temp,"%d ",(int32)bp->newp3); /* put newp3 */ - fpnum(csound,temp, lincnt, pcnt); + fpnum(csound,temp, lincnt, pcnt, sco); + corfile_putc(SP, sco); + if (first) { + sprintf(temp,"%d ",(int32)bp->newp3); /* put newp3 */ + fpnum(csound,temp, lincnt, pcnt, sco); + } while ((c = *p++) != SP && c != LF) ; } pcnt = 3; while (c != LF) { pcnt++; - corfile_putc(SP, csound->scstr); - p = pfout(csound,bp,p,lincnt,pcnt); /* now put each pfield */ + corfile_putc(SP, sco); + p = pfout(csound,bp,p,lincnt,pcnt, sco); /* now put each pfield */ c = *p++; } - corfile_putc('\n', csound->scstr); + corfile_putc('\n', sco); break; case 's': case 'e': if (bp->pcnt > 0) { char buffer[80]; - sprintf(buffer, "f 0 %f %f\n", bp->p2val, bp->newp2); - corfile_puts(buffer, csound->scstr); + CS_SPRINTF(buffer, "f 0 %f %f\n", bp->p2val, bp->newp2); + corfile_puts(buffer, sco); } - corfile_putc(c, csound->scstr); - corfile_putc(LF, csound->scstr); + corfile_putc(c, sco); + corfile_putc(LF, sco); break; case 'w': case 't': - corfile_putc(c, csound->scstr); + corfile_putc(c, sco); while ((c = *p++) != LF) /* put entire line */ - corfile_putc(c, csound->scstr); - corfile_putc(LF, csound->scstr); + corfile_putc(c, sco); + corfile_putc(LF, sco); + break; + case -1: break; default: csound->Message(csound, @@ -141,31 +160,32 @@ goto nxtlin; } -static char *pfout(CSOUND *csound, SRTBLK *bp, char *p,int lincnt, int pcnt) +static char *pfout(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) { switch (*p) { case 'n': - p = nextp(csound, bp,p, lincnt, pcnt); + p = nextp(csound, bp,p, lincnt, pcnt, sco); break; case 'p': - p = prevp(csound, bp,p, lincnt, pcnt); + p = prevp(csound, bp,p, lincnt, pcnt, sco); break; case '<': case '>': - p = ramp(csound, bp,p, lincnt, pcnt); + p = ramp(csound, bp,p, lincnt, pcnt, sco); break; case '(': case ')': - p = expramp(csound, bp, p, lincnt, pcnt); + p = expramp(csound, bp, p, lincnt, pcnt, sco); break; case '~': - p = randramp(csound, bp, p, lincnt, pcnt); + p = randramp(csound, bp, p, lincnt, pcnt, sco); break; case '"': - p = pfStr(csound, p, lincnt, pcnt); + p = pfStr(csound, p, lincnt, pcnt, sco); break; default: - p = fpnum(csound, p, lincnt, pcnt); + p = fpnum(csound, p, lincnt, pcnt, sco); break; } return(p); @@ -193,7 +213,8 @@ return(bp); } -static char *nextp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) +static char *nextp(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) { char *q; int n; @@ -205,7 +226,7 @@ n = 999; if (isdigit(*p)) n = *p++ - '0'; - if (isdigit(*p)) /* n is np subscript no */ + if (isdigit(*p)) /* n is np subscript no */ n = 10*n + (*p++ - '0'); if (UNLIKELY(*p != SP && *p != LF)) goto error; @@ -213,9 +234,9 @@ && n <= bp->pcnt)) { q = bp->text; while (n--) - while (*q++ != SP) /* go find the pfield */ + while (*q++ != SP) /* go find the pfield */ ; - pfout(csound,bp,q,lincnt,pcnt); /* and put it out */ + pfout(csound,bp,q,lincnt,pcnt,sco); /* and put it out */ } else { error: @@ -227,12 +248,13 @@ while (*p != SP && *p != LF) csound->Message(csound,"%c", *p++); csound->Message(csound,Str(" Zero substituted\n")); - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); } return(p); } -static char *prevp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) +static char *prevp(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) { char *q; int n; @@ -254,7 +276,7 @@ while (n--) while (*q++ != SP) /* go find the pfield */ ; - pfout(csound,bp,q,lincnt,pcnt); /* and put it out */ + pfout(csound,bp,q,lincnt,pcnt, sco); /* and put it out */ } else { error: @@ -266,12 +288,13 @@ while (*p != SP && *p != LF) csound->Message(csound,"%c", *p++); csound->Message(csound,Str(" Zero substituted\n")); - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); } return(p); } -static char *ramp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) +static char *ramp(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) /* NB np's may reference a ramp but ramps must terminate in valid nums */ { char *q; @@ -318,7 +341,7 @@ if (UNLIKELY((p2span = nxtbp->newp2 - prvbp->newp2) <= 0)) goto error2; rval = (qval - pval) * (bp->newp2 - prvbp->newp2) / p2span + pval; - fltout(csound, rval); + fltout(csound, rval, sco); return(psav); error1: @@ -331,11 +354,12 @@ "has illegal forward or backward ref\n"), csound->sectcnt, lincnt, pcnt); put0: - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); return(psav); } -static char *expramp(CSOUND *csound, SRTBLK *bp, char *p, int lincnt, int pcnt) +static char *expramp(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) /* NB np's may reference a ramp but ramps must terminate in valid nums */ { char *q; @@ -386,7 +410,7 @@ (double)(bp->newp2 - prvbp->newp2) / p2span); /* printf("rval=%f bp->newp2=%f prvbp->newp2-%f\n", rval, bp->newp2, prvbp->newp2); */ - fltout(csound, rval); + fltout(csound, rval, sco); return(psav); error1: @@ -399,12 +423,12 @@ "has illegal forward or backward ref\n"), csound->sectcnt, lincnt, pcnt); put0: - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); return(psav); } -static char *randramp(CSOUND *csound, - SRTBLK *bp, char *p, int lincnt, int pcnt) +static char *randramp(CSOUND *csound, SRTBLK *bp, char *p, + int lincnt, int pcnt, CORFIL *sco) /* NB np's may reference a ramp but ramps must terminate in valid nums */ { char *q; @@ -451,7 +475,7 @@ rval = (MYFLT) (((double) (csound->Rand31(&(csound->randSeed1)) - 1) / 2147483645.0) * ((double) qval - (double) pval) + (double) pval); - fltout(csound, rval); + fltout(csound, rval, sco); return(psav); error1: @@ -464,17 +488,17 @@ " illegal forward or backward ref\n"), csound->sectcnt,lincnt,pcnt); put0: - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); return(psav); } -static char *pfStr(CSOUND *csound, char *p, int lincnt, int pcnt) +static char *pfStr(CSOUND *csound, char *p, int lincnt, int pcnt, CORFIL *sco) { /* moves quoted ascii string to SCOREOUT file */ char *q = p; /* with no internal format chk */ - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); while (*p != '"') - corfile_putc(*p++, csound->scstr); - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); + corfile_putc(*p++, sco); if (UNLIKELY(*p != SP && *p != LF)) { csound->Message(csound, Str("swrite: output, sect%d line%d p%d " "has illegally terminated string "), @@ -488,8 +512,8 @@ return(p); } -static char *fpnum(CSOUND *csound, - char *p, int lincnt, int pcnt) /* moves ascii string */ +static char *fpnum(CSOUND *csound, char *p, + int lincnt, int pcnt, CORFIL *sco) /* moves ascii string */ /* to SCOREOUT file with fpnum format chk */ { char *q; @@ -499,34 +523,34 @@ if (*p == '+') p++; if (*p == '-') - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt = 0; while (isdigit(*p)) { // printf("*p=%c\n", *p); - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt++; } - // printf("%d:output: %s<<\n", __LINE__, csound->scstr); + // printf("%d:output: %s<<\n", __LINE__, sco); if (*p == '.') - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); while (isdigit(*p)) { - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt++; } - // printf("%d:output: %s<<\n", __LINE__, csound->scstr); + // printf("%d:output: %s<<\n", __LINE__, sco); if (*p == 'E' || *p == 'e') { /* Allow exponential notation */ - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt++; if (*p == '+' || *p == '-') { - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt++; } while (isdigit(*p)) { - corfile_putc(*p++, csound->scstr); + corfile_putc(*p++, sco); dcnt++; } } - // printf("%d:output: %s<<\n", __LINE__, csound->scstr); + // printf("%d:output: %s<<\n", __LINE__, sco); if (UNLIKELY((*p != SP && *p != LF) || !dcnt)) { csound->Message(csound,Str("swrite: output, sect%d line%d p%d has " "illegal number "), @@ -537,7 +561,7 @@ csound->Message(csound,"%c", *p++); csound->Message(csound,Str(" String truncated\n")); if (!dcnt) - corfile_putc('0', csound->scstr); + corfile_putc('0', sco); } return(p); } diff -Nru csound-5.17.11~dfsg/Engine/symbtab.c csound-6.02~dfsg/Engine/symbtab.c --- csound-5.17.11~dfsg/Engine/symbtab.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/symbtab.c 2014-01-07 16:53:47.000000000 +0000 @@ -1,4 +1,4 @@ - /* +/* symbtab.c: Copyright (C) 2006 @@ -27,33 +27,31 @@ #include #include "csoundCore.h" #include "tok.h" -#include "csound_orcparse.h" +#include "csound_orc.h" #include "insert.h" #include "namedins.h" #include "interlocks.h" +#include "csound_orc_semantics.h" #ifndef PARSER_DEBUG #define PARSER_DEBUG (0) #endif -ORCTOKEN** symbtab; +// FIXME - this is global... +CS_HASH_TABLE* symbtab; #define udoflag csound->parserUdoflag #define namedInstrFlag csound->parserNamedInstrFlag ORCTOKEN *add_token(CSOUND *csound, char *s, int type); -static ORCTOKEN *add_token_p(CSOUND *csound, char *s, int type, int val); +//static ORCTOKEN *add_token_p(CSOUND *csound, char *s, int type, int val); extern int csound_orcget_lineno(void*); + int get_opcode_type(OENTRY *ep) { int retVal = 0; -// if ((ep->outypes == NULL || strlen(ep->outypes) == 0) && -// (ep->intypes == NULL || strlen(ep->intypes) == 0)) { -// retVal = T_OPCODE00; -// } else - if (ep->outypes == NULL || strlen(ep->outypes) == 0) { retVal = T_OPCODE0; } @@ -66,10 +64,12 @@ void init_symbtab(CSOUND *csound) { OENTRY *ep; - OENTRY *temp; - int len = 0; + CONS_CELL *top, *head, *items; + + char *shortName; - symbtab = (ORCTOKEN**)mcalloc(csound, HASH_SIZE * sizeof(ORCTOKEN*)); + + symbtab = cs_hash_table_create(csound); /* Now we need to populate with basic words */ /* Add token types for opcodes to symbtab. If a polymorphic opcode * definition is found (dsblksiz >= 0xfffb), look for implementations @@ -77,167 +77,70 @@ * T_OPCODE0, or T_OPCODE00) */ - for (ep = (OENTRY*) csound->opcodlst; ep < (OENTRY*) csound->oplstend; ep++) { - if (ep->dsblksiz >= 0xfffb) { - char * polyName; - len = strlen(ep->opname) + 1; - polyName = mcalloc(csound, len + 1); - sprintf(polyName, "%s.", ep->opname); - - for (temp = (OENTRY*) csound->opcodlst; - temp < (OENTRY*) csound->oplstend; temp++) { - if (ep != temp && strncmp(polyName, temp->opname, len) == 0) { - add_token(csound, ep->opname, get_opcode_type(temp)); - } - } - - mfree(csound, polyName); + top = head = cs_hash_table_values(csound, csound->opcodes); -// if (strchr(ep->opname, '.') != NULL) { -// csound->Message(csound, -// "Found PolyMorphic Opcode Definition %s\n",ep->opname); -// } + while (head != NULL) { + items = head->value; + while (items != NULL) { + ep = items->value; - } - else { -// csound->Message(csound, "Found Regular Opcode %s\n",ep->opname); - add_token(csound, ep->opname,get_opcode_type(ep)); - } + if (ep->dsblksiz < 0xfffb) { + shortName = get_opcode_short_name(csound, ep->opname); + add_token(csound, shortName, get_opcode_type(ep)); + if (shortName != ep->opname) { + mfree(csound, shortName); + } + } + items = items->next; + } + head = head->next; } - /* This adds all the T_FUNCTION tokens. These should only be - * looked up in context when parsing a expression list (not yet done) - * and perhaps a more intelligent way needs to be done eventually to - * look up opcodes which can serve as functions, as well as for allowing - * multiple arguments to functions - */ - add_token(csound, "int", T_FUNCTION); - add_token(csound, "frac", T_FUNCTION); - add_token(csound, "round", T_FUNCTION); - add_token(csound, "floor", T_FUNCTION); - add_token(csound, "ceil", T_FUNCTION); - add_token(csound, "rnd", T_FUNCTION); - add_token(csound, "birnd", T_FUNCTION); - add_token(csound, "abs", T_FUNCTION); - add_token(csound, "exp", T_FUNCTION); - add_token(csound, "log", T_FUNCTION); - add_token(csound, "sqrt", T_FUNCTION); - add_token(csound, "sin", T_FUNCTION); - add_token(csound, "cos", T_FUNCTION); - add_token(csound, "tan", T_FUNCTION); - add_token(csound, "sininv", T_FUNCTION); - add_token(csound, "cosinv", T_FUNCTION); - add_token(csound, "taninv", T_FUNCTION); - add_token(csound, "log10", T_FUNCTION); - add_token(csound, "sinh", T_FUNCTION); - add_token(csound, "cosh", T_FUNCTION); - add_token(csound, "tanh", T_FUNCTION); - add_token(csound, "ampdb", T_FUNCTION); - add_token(csound, "ampdbfs", T_FUNCTION); - add_token(csound, "dbamp", T_FUNCTION); - add_token(csound, "dbfsamp", T_FUNCTION); - add_token_p(csound, "ftcps", T_FUNCTION, TR); - add_token_p(csound, "ftlen", T_FUNCTION, TR); - add_token_p(csound, "ftsr", T_FUNCTION, TR); - add_token_p(csound, "ftlptim", T_FUNCTION, TR); - add_token_p(csound, "ftchnls", T_FUNCTION, TR); - add_token(csound, "i", T_FUNCTION); - add_token(csound, "k", T_FUNCTION); - add_token(csound, "cpsoct", T_FUNCTION); - add_token(csound, "octpch", T_FUNCTION); - add_token(csound, "cpspch", T_FUNCTION); - add_token(csound, "pchoct", T_FUNCTION); - add_token(csound, "octcps", T_FUNCTION); - add_token_p(csound, "nsamp", T_FUNCTION, TR); - add_token(csound, "powoftwo", T_FUNCTION); - add_token(csound, "logbtwo", T_FUNCTION); - add_token(csound, "a", T_FUNCTION); - add_token_p(csound, "tb0", T_FUNCTION, TR); - add_token_p(csound, "tb1", T_FUNCTION, TR); - add_token_p(csound, "tb2", T_FUNCTION, TR); - add_token_p(csound, "tb3", T_FUNCTION, TR); - add_token_p(csound, "tb4", T_FUNCTION, TR); - add_token_p(csound, "tb5", T_FUNCTION, TR); - add_token_p(csound, "tb6", T_FUNCTION, TR); - add_token_p(csound, "tb7", T_FUNCTION, TR); - add_token_p(csound, "tb8", T_FUNCTION, TR); - add_token_p(csound, "tb9", T_FUNCTION, TR); - add_token_p(csound, "tb10", T_FUNCTION, TR); - add_token_p(csound, "tb11", T_FUNCTION, TR); - add_token_p(csound, "tb12", T_FUNCTION, TR); - add_token_p(csound, "tb13", T_FUNCTION, TR); - add_token_p(csound, "tb14", T_FUNCTION, TR); - add_token_p(csound, "tb15", T_FUNCTION, TR); - add_token_p(csound, "urd", T_FUNCTION, TR); - add_token(csound, "not", T_FUNCTION); - add_token(csound, "cent", T_FUNCTION); - add_token(csound, "octave", T_FUNCTION); - add_token(csound, "semitone", T_FUNCTION); - add_token(csound, "cpsmidinn", T_FUNCTION); - add_token(csound, "octmidinn", T_FUNCTION); - add_token(csound, "pchmidinn", T_FUNCTION); - add_token(csound, "db", T_FUNCTION); - add_token(csound, "p", T_FUNCTION); - add_token(csound, "qinf", T_FUNCTION); - add_token(csound, "qnan", T_FUNCTION); - add_token(csound, "##error", T_FUNCTION); -} - -static unsigned int hash(char *s) -{ - unsigned int h = 0; - while (*s != '\0') { - h = (h<<4) ^ *s++; - } - return (h%HASH_SIZE); + mfree(csound, top); } ORCTOKEN *add_token(CSOUND *csound, char *s, int type) { - unsigned int h = hash(s); - //printf("Hash value for %s: %i\n", s, h); - ORCTOKEN *a = symbtab[h]; + ORCTOKEN *a = cs_hash_table_get(csound, symbtab, s); + ORCTOKEN *ans; - while (a!=NULL) { - if (strcmp(a->lexeme, s)==0) { - if (type == a->type) return a; - if (type!= T_FUNCTION || a->type!=T_OPCODE) - csound->Warning(csound, - Str("Type confusion for %s (%d,%d), replacing\n"), - s, type, a->type); - a->type = type; - return a; - } - a = a->next; + if (a!=NULL) { + if (type == a->type) return a; + if ((type!=T_FUNCTION || a->type!=T_OPCODE)) + csound->Warning(csound, + Str("Type confusion for %s (%d,%d), replacing\n"), + s, type, a->type); + a->type = type; + return a; } ans = new_token(csound, T_IDENT); ans->lexeme = (char*)mmalloc(csound, 1+strlen(s)); strcpy(ans->lexeme, s); - ans->next = symbtab[h]; ans->type = type; - symbtab[h] = ans; - return ans; -} + cs_hash_table_put(csound, symbtab, s, ans); -static ORCTOKEN *add_token_p(CSOUND *csound, char *s, int type, int val) -{ - ORCTOKEN *ans = add_token(csound, s, type); - ans->value = val; return ans; } +/* static ORCTOKEN *add_token_p(CSOUND *csound, char *s, int type, int val) */ +/* { */ +/* ORCTOKEN *ans = add_token(csound, s, type); */ +/* ans->value = val; */ +/* return ans; */ +/* } */ + int isUDOArgList(char *s) { int len = strlen(s) - 1; while (len >= 0) { - if (UNLIKELY(strchr("aijkftKopS0", s[len]) == NULL)) { + if (UNLIKELY(strchr("aijkftKOVPopS[]0", s[len]) == NULL)) { /* printf("Invalid char '%c' in '%s'", *p, s); */ return 0; } @@ -251,7 +154,7 @@ int len = strlen(s) - 1; while (len >= 0) { - if (UNLIKELY(strchr("aikftSK0", s[len]) == NULL)) { + if (UNLIKELY(strchr("aikftSK[]0", s[len]) == NULL)) { return 0; } len--; @@ -261,128 +164,98 @@ ORCTOKEN *lookup_token(CSOUND *csound, char *s, void *yyscanner) { - unsigned int h = hash(s); int type = T_IDENT; - ORCTOKEN *a = symbtab[h]; + ORCTOKEN *a; ORCTOKEN *ans; if (PARSER_DEBUG) - csound->Message(csound, "Looking up token for: %d : %s\n", h, s); + csound->Message(csound, "Looking up token for: %s\n", s); if (udoflag == 0) { if (isUDOAnsList(s)) { ans = new_token(csound, UDO_ANS_TOKEN); ans->lexeme = (char*)mmalloc(csound, 1+strlen(s)); strcpy(ans->lexeme, s); -// ans->next = symbtab[h]; -// symbtab[h] = ans; - //printf("Found UDO Answer List\n"); return ans; } } if (udoflag == 1) { + if (csound->oparms->odebug) printf("Found UDO Arg List\n"); if (isUDOArgList(s)) { ans = new_token(csound, UDO_ARGS_TOKEN); ans->lexeme = (char*)mmalloc(csound, 1+strlen(s)); strcpy(ans->lexeme, s); -// ans->next = symbtab[h]; -// symbtab[h] = ans; - //printf("Found UDO Arg List\n"); return ans; } } - while (a!=NULL) { - if (strcmp(s, "reverb") == 0) { - if (PARSER_DEBUG) - csound->Message(csound, "Looking up token for: %d: %d: %s : %s\n", - hash("reverb"), hash("a4"), s, a->lexeme); - } - if (strcmp(a->lexeme, s)==0) { - ans = (ORCTOKEN*)mmalloc(csound, sizeof(ORCTOKEN)); - memcpy(ans, a, sizeof(ORCTOKEN)); - ans->next = NULL; - ans->lexeme = (char *)mmalloc(csound, strlen(a->lexeme) + 1); - strcpy(ans->lexeme, a->lexeme); - return ans; - } - a = a->next; - } + a = cs_hash_table_get(csound, symbtab, s); + if (a != NULL) { + ans = (ORCTOKEN*)mmalloc(csound, sizeof(ORCTOKEN)); + memcpy(ans, a, sizeof(ORCTOKEN)); + ans->next = NULL; + ans->lexeme = (char *)mmalloc(csound, strlen(a->lexeme) + 1); + strcpy(ans->lexeme, a->lexeme); + return ans; + } ans = new_token(csound, T_IDENT); ans->lexeme = (char*)mmalloc(csound, 1+strlen(s)); strcpy(ans->lexeme, s); - //ans->next = symbtab[h]; - - /* if (PARSER_DEBUG) */ - /* csound->Message(csound, "NamedInstrFlag: %d\n", namedInstrFlag); */ if (udoflag == -2 || namedInstrFlag == 1) { return ans; } - // NEED TO FIX: In case of looking for label for kgoto or other opcodes, need - // to return T_IDENT instead of any sub-type - // Currently fixed by definition of label non-terminal - switch (s[0]) { - case 'S': type = T_IDENT_S; break; - case 'a': type = T_IDENT_A; break; - case 'f': type = T_IDENT_F; break; - case 'i': type = T_IDENT_I; break; - case 'k': type = T_IDENT_K; break; - case 'p': type = T_IDENT_P; break; - case 't': type = T_IDENT_T; break; - case 'w': type = T_IDENT_W; break; - case'g': - switch (s[1]) { - case 'i': type = T_IDENT_GI; break; - case 'k': type = T_IDENT_GK; break; - case 'a': type = T_IDENT_GA; break; - case 'f': type = T_IDENT_GF; break; - case 'w': type = T_IDENT_GW; break; - case 't': type = T_IDENT_GT; break; - case 'S': type = T_IDENT_GS; break; - /* default: */ - /* csound->Message(csound, Str("Unknown word type for %s on line %d\n"), */ - /* s, csound_orcget_lineno(yyscanner)); */ - /* exit(1); */ - } - default: /* - csound->DebugMsg(csound,"IDENT Token: %i : %i", ans->type, T_IDENT); - csound->DebugMsg(csound,"Unknown word type for %s on line %d\n", s, yyline); - exit(1); - */ - break; - } ans->type = type; - //symbtab[h] = ans; return ans; } +/** + * + This function takes in the arguments from useropinfo in OENTRY and parses + them, filling the OENTRY input and output types and creating + the argument lists for xinset/xouset in insert.c + argument pointerlists, stored in useropinfo->in_ndx_list and + useropinfo->out_ndx_list. + + The argument lists are terminated by a -1 and are set in the + following order: + i-var args (i-time vars) + S-var args (strings) + i-arrays + a-vars + k-vars + f-sigs + arrays (a,k,f) + This order is fixed and followed up in xinset/xoutset and + useropcd1, useropcd2. -/* UDO code below was from otran, broken out and modified for new parser by - * SYY - */ -/* VL -- I have made the modifications below to allow for f-sigs & t-sigs and on line 224 and 238*/ + Original code - IV Oct 12 2002 + modified by VL for Csound 6 + +*/ -/* IV - Oct 12 2002: new function to parse arguments of opcode definitions */ static int parse_opcode_args(CSOUND *csound, OENTRY *opc) { OPCODINFO *inm = (OPCODINFO*) opc->useropinfo; char *types, *otypes; - int i, i_incnt, a_incnt, k_incnt, i_outcnt, a_outcnt, k_outcnt, err; - int S_incnt, S_outcnt, f_outcnt, f_incnt, t_incnt, t_outcnt; + int i, i_incnt, iv_incnt, iv_outcnt, a_incnt, k_incnt, + i_outcnt, a_outcnt, k_outcnt, err; + int S_incnt, S_outcnt, f_outcnt, f_incnt, kv_incnt, kv_outcnt; int16 *a_inlist, *k_inlist, *i_inlist, *a_outlist, *k_outlist, *i_outlist; - int16 *S_inlist, *S_outlist, *f_inlist, *f_outlist, *t_inlist, *t_outlist; + int16 *S_inlist, *S_outlist, *f_inlist, *f_outlist, *kv_inlist, + *kv_outlist, *iv_inlist, *iv_outlist; /* count the number of arguments, and check types */ i = i_incnt = S_incnt = a_incnt = k_incnt = f_incnt = f_outcnt = - i_outcnt = S_outcnt = a_outcnt = k_outcnt = t_incnt = t_outcnt = err = 0; + i_outcnt = S_outcnt = a_outcnt = k_outcnt = kv_incnt = + kv_outcnt = iv_outcnt = iv_incnt = err = 0; types = inm->intypes; otypes = opc->intypes; opc->dsblksiz = (uint16) sizeof(UOPCODE); if (!strcmp(types, "0")) @@ -392,23 +265,42 @@ case 'a': a_incnt++; *otypes++ = *types; break; + case 'O': + k_incnt++; *otypes++ = 'O'; break; + case 'P': + k_incnt++;*otypes++ = 'P'; break; + case 'V': + k_incnt++;*otypes++ = 'V'; break; case 'K': i_incnt++; /* also updated at i-time */ case 'k': + if(*(types+1) == '[') { + kv_incnt++; + *otypes++ = *types; + *otypes++ = *(types+1); + *otypes++ = *(types+2); + types+=2; + break; + } k_incnt++; *otypes++ = 'k'; break; case 'f': f_incnt++; *otypes++ = *types; break; - case 't': - t_incnt++; *otypes++ = *types; - break; case 'i': + if(*(types+1) == '[') { + iv_incnt++; + *otypes++ = *types; + *otypes++ = *(types+1); + *otypes++ = *(types+2); + types+=2; + break; + } case 'o': case 'p': case 'j': i_incnt++; *otypes++ = *types; - break; + break; case 'S': S_incnt++; *otypes++ = *types; break; @@ -424,7 +316,7 @@ } *otypes++ = 'o'; *otypes = '\0'; /* optional arg for local ksmps */ inm->inchns = i; /* total number of input chnls */ - inm->perf_incnt = a_incnt + k_incnt + f_incnt + t_incnt; + inm->perf_incnt = a_incnt + k_incnt + f_incnt + kv_incnt; opc->dsblksiz += (uint16) (sizeof(MYFLT*) * i); /* same for outputs */ i = 0; @@ -443,15 +335,28 @@ case 'K': i_outcnt++; /* also updated at i-time */ case 'k': + if(*(types+1) == '[') { + kv_outcnt++; + *otypes++ = *types; + *otypes++ = *(types+1); + *otypes++ = *(types+2); + types+=2; + break; + } k_outcnt++; *otypes++ = 'k'; break; case 'f': f_outcnt++; *otypes++ = *types; break; - case 't': - t_outcnt++; *otypes++ = *types; - break; case 'i': + if(*(types+1) == '[') { + iv_outcnt++; + *otypes++ = *types; + *otypes++ = *(types+1); + *otypes++ = *(types+2); + types+=2; + break; + } i_outcnt++; *otypes++ = *types; break; case 'S': @@ -465,29 +370,52 @@ } *otypes = '\0'; inm->outchns = i; /* total number of output chnls */ - inm->perf_outcnt = a_outcnt + k_outcnt + f_outcnt + t_outcnt; + inm->perf_outcnt = a_outcnt + k_outcnt + f_outcnt + kv_outcnt; + opc->dsblksiz += (uint16) (sizeof(MYFLT*) * i); opc->dsblksiz = ((opc->dsblksiz + (uint16) 15) & (~((uint16) 15))); /* align (needed ?) */ /* now build index lists for the various types of arguments */ - i = i_incnt + S_incnt + inm->perf_incnt + - i_outcnt + S_outcnt + inm->perf_outcnt; + i = i_incnt + S_incnt + inm->perf_incnt + iv_incnt + + i_outcnt + S_outcnt + inm->perf_outcnt + iv_outcnt; i_inlist = inm->in_ndx_list = (int16*) mmalloc(csound, - sizeof(int16) * (i + 14)); + sizeof(int16) * (i + 16)); S_inlist = i_inlist + i_incnt + 1; - a_inlist = S_inlist + S_incnt + 1; + iv_inlist = S_inlist + S_incnt + 1; + a_inlist = iv_inlist + iv_incnt + 1; k_inlist = a_inlist + a_incnt + 1; f_inlist = k_inlist + k_incnt + 1; - t_inlist = f_inlist + f_incnt + 1; + kv_inlist = f_inlist + f_incnt + 1; i = 0; types = inm->intypes; while (*types) { + switch (*types++) { + case 'a': *a_inlist++ = i; break; - case 'k': *k_inlist++ = i; break; + case 'O': + case 'P': + case 'V': + case 'k': + if(*(types) == '[') { + *kv_inlist++ = i; + types+=2; + break; + } + *k_inlist++ = i; + break; case 'f': *f_inlist++ = i; break; - case 't': *t_inlist++ = i; break; + /* case '[': */ + /* if(*types=='i') *iv_inlist++ = i; */ + /* else *kv_inlist++ = i; */ + /* types+=2; */ + /* break; */ case 'K': *k_inlist++ = i; /* also updated at i-time */ case 'i': + if(*(types) == '[') { + *iv_inlist++ = i; + types+=2; + break; + } case 'o': case 'p': case 'j': *i_inlist++ = i; break; @@ -497,33 +425,81 @@ } /* put delimiters */ - *i_inlist = *S_inlist = *a_inlist = *k_inlist = *f_inlist = *t_inlist = -1; - i_outlist = inm->out_ndx_list = t_inlist + 1; + *i_inlist = *S_inlist = *iv_inlist = *a_inlist = *k_inlist = + *f_inlist = *kv_inlist = -1; + + i_outlist = inm->out_ndx_list = kv_inlist + 1; S_outlist = i_outlist + i_outcnt + 1; - a_outlist = S_outlist + S_outcnt + 1; + iv_outlist = S_outlist + S_outcnt + 1; + a_outlist = iv_outlist + iv_outcnt + 1; k_outlist = a_outlist + a_outcnt + 1; f_outlist = k_outlist + k_outcnt + 1; - t_outlist = f_outlist + f_outcnt + 1; + kv_outlist = f_outlist + f_outcnt + 1; i = 0; types = inm->outtypes; while (*types) { switch (*types++) { case 'a': *a_outlist++ = i; break; - case 'k': *k_outlist++ = i; break; + case 'k': + if(*(types) == '[') { + *kv_outlist++ = i; + types+=2; + break; + } + *k_outlist++ = i; break; case 'f': *f_outlist++ = i; break; - case 't': *t_outlist++ = i; break; case 'K': *k_outlist++ = i; /* also updated at i-time */ - case 'i': *i_outlist++ = i; break; + case 'i': + if(*(types) == '[') { + *iv_inlist++ = i; + types+=2; + break; + } + *i_outlist++ = i; break; case 'S': *S_outlist++ = i; break; } i++; } - *i_outlist = *S_outlist = *a_outlist = *k_outlist = - *f_outlist = *t_outlist = -1; /* put delimiters */ + *i_outlist = *S_outlist = *iv_outlist = *a_outlist = *k_outlist = + *f_outlist = *kv_outlist = -1; /* put delimiters */ return err; } +OENTRY* csound_find_internal_oentry(CSOUND* csound, OENTRY* oentry) { + CONS_CELL *items; + char *shortName; + OENTRY *ep, *retVal = NULL; + + if(oentry == NULL) { + return NULL; + } + shortName = get_opcode_short_name(csound, oentry->opname); + + items = cs_hash_table_get(csound, csound->opcodes, shortName); + + while (items != NULL) { + ep = items->value; + if (oentry->iopadr == ep->iopadr && + oentry->kopadr == ep->kopadr && + oentry->aopadr == ep->aopadr && + strcmp(oentry->opname, ep->opname) == 0 && + strcmp(oentry->outypes, ep->outypes) == 0 && + strcmp(oentry->intypes, ep->intypes) == 0) { + retVal = ep; + break; + } + items = items->next; + } + + if (shortName != oentry->opname) { + mfree(csound, shortName); + } + + return retVal; +} + + /** Adds a UDO definition as an T_OPCODE or T_OPCODE0 type to the symbol table * used at parse time. An OENTRY is also added at this time so that at * verification time the opcode can be looked up to get its signature. @@ -532,22 +508,29 @@ char *outtypes, char *intypes) { OENTRY tmpEntry, *opc, *newopc; - int32 newopnum; OPCODINFO *inm; - - /* IV - Oct 31 2002 */ if (UNLIKELY(!check_instr_name(opname))) { synterr(csound, Str("invalid name for opcode")); return -1; } - /* IV - Oct 31 2002: check if opcode is already defined */ - newopnum = find_opcode(csound, opname); + /* check if opcode is already defined */ + + opc = find_opcode_new(csound, opname, outtypes, intypes); - if (newopnum) { + if (opc != NULL) { /* IV - Oct 31 2002: redefine old opcode if possible */ - if (UNLIKELY(newopnum < SETEND || !strcmp(opname, "subinstr"))) { + if (UNLIKELY( + !strcmp(opname, "instr") || + !strcmp(opname, "endin") || + !strcmp(opname, "opcode") || + !strcmp(opname, "endop") || + !strcmp(opname, "$label") || + !strcmp(opname, "pset") || + !strcmp(opname, "xin") || + !strcmp(opname, "xout") || + !strcmp(opname, "subinstr"))) { synterr(csound, Str("cannot redefine %s"), opname); return -2; } @@ -559,8 +542,7 @@ /* IV - Oct 31 2002 */ /* store the name in a linked list (note: must use mcalloc) */ inm = (OPCODINFO *) mcalloc(csound, sizeof(OPCODINFO)); - inm->name = (char*)mmalloc(csound, 1+strlen(opname)); - strcpy(inm->name, opname); + inm->name = cs_strdup(csound, opname); inm->intypes = intypes; inm->outtypes = outtypes; @@ -569,18 +551,12 @@ /* IV - Oct 31 2002: */ /* create a fake opcode so we can call it as such */ - opc = csound->opcodlst + find_opcode(csound, ".userOpcode"); + opc = find_opcode(csound, "##userOpcode"); memcpy(&tmpEntry, opc, sizeof(OENTRY)); - tmpEntry.opname = (char*)mmalloc(csound, 1+strlen(opname)); - strcpy(tmpEntry.opname, opname); + tmpEntry.opname = cs_strdup(csound, opname); csound->AppendOpcodes(csound, &tmpEntry, 1); - if (!newopnum) { - newopnum = (int32) ((OENTRY*) csound->oplstend - - (OENTRY*) csound->opcodlst) - 1L; - } - - newopc = &(csound->opcodlst[newopnum]); + newopc = csound_find_internal_oentry(csound, &tmpEntry); newopc->useropinfo = (void*) inm; /* ptr to opcode parameters */ /* check in/out types and copy to the opcode's */ @@ -590,7 +566,7 @@ newopc->intypes = &(newopc->outypes[strlen(outtypes) + 1]); if (UNLIKELY(parse_opcode_args(csound, newopc) != 0)) - return -3; + return -3; if (strcmp(outtypes, "0")==0) { add_token(csound, opname, T_OPCODE0); @@ -600,3 +576,19 @@ return 0; } + +void synterr(CSOUND *csound, const char *s, ...) +{ + va_list args; + + csound->MessageS(csound, CSOUNDMSG_ERROR, Str("error: ")); + va_start(args, s); + csound->MessageV(csound, CSOUNDMSG_ERROR, s, args); + va_end(args); + + /* FIXME - Removed temporarily for debugging + * This function may not be necessary at all in the end if some of this is + * done in the parser + */ + csound->synterrcnt++; +} diff -Nru csound-5.17.11~dfsg/Engine/twarp.c csound-6.02~dfsg/Engine/twarp.c --- csound-5.17.11~dfsg/Engine/twarp.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Engine/twarp.c 2014-01-07 16:53:47.000000000 +0000 @@ -39,7 +39,8 @@ void twarp(CSOUND *csound) /* time-warp a score section acc to T-statement */ { SRTBLK *bp; - MYFLT absp3, endtime; + MYFLT absp3; + MYFLT endtime; int negp3; if (UNLIKELY((bp = csound->frstbp) == NULL)) /* if null file, */ @@ -55,7 +56,8 @@ do { switch (bp->text[0]) { /* else warp all timvals */ case 'i': - if (UNLIKELY((absp3 = bp->newp3) < 0)) { + absp3 = bp->newp3; + if (UNLIKELY(absp3 < 0)) { absp3 = -absp3; negp3++; } diff -Nru csound-5.17.11~dfsg/H/CMakeLists.txt csound-6.02~dfsg/H/CMakeLists.txt --- csound-5.17.11~dfsg/H/CMakeLists.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/CMakeLists.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,79 +0,0 @@ - -set(csheaders - cfgvar.h - cscore.h - csdl.h - csound.h - csound.hpp - csoundCore.h - cwindow.h - msg_attr.h - OpcodeBase.hpp - pstream.h - pvfileio.h - soundio.h - sysdep.h - text.h - version.h - float-version.h) - -# These don't live here... but we list them here to have all headers -# in one place -list(APPEND csheaders - ../interfaces/CsoundFile.hpp - ../interfaces/CppSound.hpp - ../interfaces/filebuilding.h - ../interfaces/csPerfThread.hpp) - -set(csacheaders - ../frontends/CsoundAC/Cell.hpp - ../frontends/CsoundAC/ChordLindenmayer.hpp - ../frontends/CsoundAC/Composition.hpp - ../frontends/CsoundAC/Conversions.hpp - ../frontends/CsoundAC/Counterpoint.hpp - ../frontends/CsoundAC/CounterpointNode.hpp - ../frontends/CsoundAC/Event.hpp - ../frontends/CsoundAC/Exception.hpp - ../frontends/CsoundAC/Hocket.hpp - ../frontends/CsoundAC/ImageToScore.hpp - ../frontends/CsoundAC/Lindenmayer.hpp - ../frontends/CsoundAC/MCRM.hpp - ../frontends/CsoundAC/Midifile.hpp - ../frontends/CsoundAC/MusicModel.hpp - ../frontends/CsoundAC/Node.hpp - ../frontends/CsoundAC/OrchestraNode.hpp - ../frontends/CsoundAC/Platform.hpp - ../frontends/CsoundAC/Random.hpp - ../frontends/CsoundAC/Rescale.hpp - ../frontends/CsoundAC/Score.hpp - ../frontends/CsoundAC/ScoreModel.hpp - ../frontends/CsoundAC/ScoreNode.hpp - ../frontends/CsoundAC/Sequence.hpp - ../frontends/CsoundAC/Shell.hpp - ../frontends/CsoundAC/Silence.hpp - ../frontends/CsoundAC/Soundfile.hpp - ../frontends/CsoundAC/StrangeAttractor.hpp - ../frontends/CsoundAC/System.hpp - ../frontends/CsoundAC/Voicelead.hpp - ../frontends/CsoundAC/VoiceleadingNode.hpp - ) - -set(csvstheaders - frontends/CsoundVST/CsoundVstFltk.hpp - frontends/CsoundVST/CsoundVST.hpp - frontends/CsoundVST/CsoundVstUi.h - frontends/CsoundVST/Platform.hpp - frontends/CsoundVST/ScoreGenerator.hpp - frontends/CsoundVST/ScoreGeneratorVstFltk.hpp - frontends/CsoundVST/ScoreGeneratorVst.hpp - frontends/CsoundVST/ScoreGeneratorVstUi.h - ) - -INSTALL(FILES ${csheaders} DESTINATION ${HEADER_INSTALL_DIR}) - -IF( BUILD_CSOUND_AC ) - INSTALL(FILES ${csacheaders} DESTINATION ${HEADER_INSTALL_DIR}) -endif() - -# Enable this when we build CsoundVST -#INSTALL(FILES ${csvstheaders} DESTINATION ${HEADER_INSTALL_DIR}) diff -Nru csound-5.17.11~dfsg/H/OpcodeBase.hpp csound-6.02~dfsg/H/OpcodeBase.hpp --- csound-5.17.11~dfsg/H/OpcodeBase.hpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/OpcodeBase.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,171 +0,0 @@ -#ifndef OPCODE_BASE_H -#define OPCODE_BASE_H -#ifndef MSVC -#include "csdl.h" -#include -#else -#include -#include "csdl.h" -#endif - -/** - * Template base class, or pseudo-virtual base class, - * for writing Csound opcodes in C++. - * Derive opcode implementation classes like this: - * - * DerivedClass : public OpcodeBase - * { - * public: - * // All output fields must be declared first as MYFLT *: - * MYFLT *aret1; - * // All input fields must be declared next as MYFLT *: - * MYFLT *iarg1; - * MYFLT *karg2; - * MYFLT *aarg3; - * // All internal state variables must be declared after that: - * size_t state1; - * double state2; - * MYFLT state3; - * // Declare and implement only whichever of these are required: - * int init(); - * int kontrol(); - * int audio; - * int noteoff(); - * void deinit(); - * }; - */ -template -class OpcodeBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } - else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & WARNMSG || - csound->GetDebug(csound)) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } - else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - OPDS h; -}; - -template -class OpcodeNoteoffBase -{ -public: - int init(CSOUND *csound) - { - return NOTOK; - } - static int init_(CSOUND *csound, void *opcode) - { - if (!csound->reinitflag && !csound->tieflag) { - csound->RegisterDeinitCallback(csound, opcode, &OpcodeNoteoffBase::noteoff_); - } - return reinterpret_cast(opcode)->init(csound); - } - int kontrol(CSOUND *csound) - { - return NOTOK; - } - static int kontrol_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->kontrol(csound); - } - int audio(CSOUND *csound) - { - return NOTOK; - } - static int audio_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->audio(csound); - } - void log(CSOUND *csound, const char *format,...) - { - va_list args; - va_start(args, format); - if(csound) { - csound->MessageV(csound, 0, format, args); - } - else { - vfprintf(stdout, format, args); - } - va_end(args); - } - void warn(CSOUND *csound, const char *format,...) - { - if(csound) { - if(csound->GetMessageLevel(csound) & WARNMSG || - csound->GetDebug(csound)) { - va_list args; - va_start(args, format); - csound->MessageV(csound, CSOUNDMSG_WARNING, format, args); - va_end(args); - } - } - else { - va_list args; - va_start(args, format); - vfprintf(stdout, format, args); - va_end(args); - } - } - int noteoff(CSOUND *csound) - { - return OK; - } - static int noteoff_(CSOUND *csound, void *opcode) - { - return reinterpret_cast(opcode)->noteoff(csound); - } - OPDS h; -}; - -#endif - diff -Nru csound-5.17.11~dfsg/H/aops.h csound-6.02~dfsg/H/aops.h --- csound-5.17.11~dfsg/H/aops.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/aops.h 2014-01-07 16:53:47.000000000 +0000 @@ -100,6 +100,11 @@ typedef struct { OPDS h; + ARRAYDAT *tabout; +} INA; + +typedef struct { + OPDS h; MYFLT *ar1, *ar2; } INS; @@ -131,39 +136,25 @@ typedef struct { OPDS h; + MYFLT *ar; + MYFLT *ch; +} INCH1; + +typedef struct { + OPDS h; MYFLT *asig[VARGMAX]; } OUTX; typedef struct { OPDS h; + ARRAYDAT *tabin; +} OUTARRAY; + +typedef struct { + OPDS h; MYFLT *asig; } OUTM; -/* typedef struct { */ -/* OPDS h; */ -/* MYFLT *asig1, *asig2; */ -/* } OUTS; */ - -/* typedef struct { */ -/* OPDS h; */ -/* MYFLT *asig1, *asig2, *asig3, *asig4; */ -/* } OUTQ; */ - -/* typedef struct { */ -/* OPDS h; */ -/* MYFLT *asig1, *asig2, *asig3, *asig4, *asig5, *asig6; */ -/* } OUTH; */ - -/* typedef struct { */ -/* OPDS h; */ -/* MYFLT *asig1, *asig2, *asig3, *asig4, *asig5, *asig6, *asig7, *asig8; */ -/* } OUTO; */ - -/* typedef struct { */ -/* OPDS h; */ -/* MYFLT *asig[VARGMAX]; */ -/* } OUTX; */ - typedef struct { OPDS h; MYFLT *args[VARGMAX]; @@ -187,18 +178,21 @@ typedef struct { OPDS h; - MYFLT *value, *valID; - AUXCH channelName; -} INVAL; + MYFLT *res, *arg; +} ERRFN; -typedef struct { +typedef struct MONITOR_OPCODE_ { OPDS h; - MYFLT *valID, *value; - AUXCH channelName; -} OUTVAL; + MYFLT *ar[24]; +} MONITOR_OPCODE; typedef struct { - OPDS h; - MYFLT *res, *arg; -} ERRFN; + OPDS h; + MYFLT *kstartChan, *argums[VARGMAX]; + int narg; +} OUTRANGE; +int monitor_opcode_perf(CSOUND *csound, MONITOR_OPCODE *p); +int monitor_opcode_init(CSOUND *csound, MONITOR_OPCODE *p); +int outRange_i(CSOUND *csound, OUTRANGE *p); +int outRange(CSOUND *csound, OUTRANGE *p); diff -Nru csound-5.17.11~dfsg/H/bus.h csound-6.02~dfsg/H/bus.h --- csound-5.17.11~dfsg/H/bus.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/bus.h 2014-01-07 16:53:47.000000000 +0000 @@ -29,6 +29,7 @@ #define CSOUND_BUS_H #include "pstream.h" +#include "csound_standard_types.h" #ifdef __cplusplus extern "C" { @@ -36,6 +37,11 @@ typedef struct { OPDS h; + MYFLT *r, *a; +} CHNVAL; + +typedef struct { + OPDS h; PVSDAT *r; MYFLT *a,*N, *overlap, *winsize, *wintype, *format; PVSDAT init; @@ -48,45 +54,60 @@ int evtbuf; } KSENSE; +typedef struct channelEntry_s { + struct channelEntry_s *nxt; + controlChannelHints_t hints; + MYFLT *data; +#ifndef MACOSX +#if defined(HAVE_PTHREAD_SPIN_LOCK) + pthread_spinlock_t *lock; + pthread_spinlock_t theLock; +#else + int lock; +#endif +#else + int lock; /* Multi-thread protection */ +#endif + int type; + int datasize; /* size of allocated chn data */ + char name[1]; +} CHNENTRY; + typedef struct { OPDS h; MYFLT *arg; - MYFLT *iname; + STRINGDAT *iname; MYFLT *fp; int *lock; + int pos; } CHNGET; typedef struct { OPDS h; - MYFLT *iname; + STRINGDAT *iname; MYFLT *fp; int *lock; } CHNCLEAR; typedef struct { OPDS h; - MYFLT *iname; - MYFLT *imode; - const char *name; - MYFLT *fp; - int *lock; - int type; -} CHNSEND; - -typedef struct { - OPDS h; - MYFLT *iname; + STRINGDAT *iname; MYFLT *imode; MYFLT *itype; MYFLT *idflt; MYFLT *imin; MYFLT *imax; + MYFLT *ix; + MYFLT *iy; + MYFLT *iwidth; + MYFLT *iheight; + STRINGDAT *Sattributes; int *lock; } CHN_OPCODE_K; typedef struct { OPDS h; - MYFLT *iname; + STRINGDAT *iname; MYFLT *imode; int *lock; } CHN_OPCODE; @@ -94,7 +115,7 @@ typedef struct { OPDS h; MYFLT *arg; - MYFLT *iname; + STRINGDAT *iname; MYFLT *imode; MYFLT *itype; MYFLT *idflt; @@ -110,98 +131,67 @@ MYFLT *idflt; MYFLT *imin; MYFLT *imax; - MYFLT *iname; + STRINGDAT *iname; } CHNPARAMS_OPCODE; -/* - { "chnget", 0xFFFF, 0, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, - { "chnget.i", S(CHNGET), 1, "i", "S", - (SUBR) chnget_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, - { "chnget.k", S(CHNGET), 3, "k", "S", - (SUBR) chnget_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, - { "chnget.a", S(CHNGET), 5, "a", "S", - (SUBR) chnget_opcode_init_a, (SUBR) notinit_opcode_stub, (SUBR) NULL }, - { "chnget.S", S(CHNGET), 1, "S", "S", - (SUBR) chnget_opcode_init_S, (SUBR) NULL, (SUBR) NULL }, - { "chnset", 0xFFFB, 0, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, - { "chnset.i", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, - { "chnset.r", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, - { "chnset.c", S(CHNGET), 1, "", "iS", - (SUBR) chnset_opcode_init_i, (SUBR) NULL, (SUBR) NULL }, - { "chnset.k", S(CHNGET), 3, "", "kS", - (SUBR) chnset_opcode_init_k, (SUBR) notinit_opcode_stub, (SUBR) NULL }, - { "chnset.a", S(CHNGET), 5, "", "aS", - (SUBR) chnset_opcode_init_a, (SUBR) notinit_opcode_stub, (SUBR) NULL }, - { "chnset.S", S(CHNGET), 1, "", "SS", - (SUBR) chnset_opcode_init_S, (SUBR) NULL, (SUBR) NULL }, - { "chnmix", S(CHNGET), 5, "", "aS", - (SUBR) chnmix_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, - { "chnclear", S(CHNCLEAR), 5, "", "S", - (SUBR) chnclear_opcode_init, (SUBR) NULL, (SUBR) notinit_opcode_stub }, - { "chn_k", S(CHN_OPCODE_K), 1, "", "Sioooo", - (SUBR) chn_k_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chn_a", S(CHN_OPCODE), 1, "", "Si", - (SUBR) chn_a_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chn_S", S(CHN_OPCODE), 1, "", "Si", - (SUBR) chn_S_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnexport", 0xFFFF, 0, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, - { "chnexport.i", S(CHNEXPORT_OPCODE), 1, "i", "Sioooo", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnexport.k", S(CHNEXPORT_OPCODE), 1, "k", "Sioooo", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnexport.a", S(CHNEXPORT_OPCODE), 1, "a", "Si", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnexport.S", S(CHNEXPORT_OPCODE), 1, "S", "Si", - (SUBR) chnexport_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnparams", S(CHNPARAMS_OPCODE), 1, "iiiiii", "S", - (SUBR) chnparams_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "chnrecv", S(CHNSEND), 3, "", "So", - (SUBR) chnrecv_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, - { "chnsend", S(CHNSEND), 3, "", "So", - (SUBR) chnsend_opcode_init, (SUBR) notinit_opcode_stub, (SUBR) NULL }, -*/ - -#ifndef CSOUND_BUS_C - -int chano_opcode_perf_k(CSOUND *, void *); -int chano_opcode_perf_a(CSOUND *, void *); -int chani_opcode_perf_k(CSOUND *, void *); -int chani_opcode_perf_a(CSOUND *, void *); -int pvsin_init(CSOUND *, void *); -int pvsin_perf(CSOUND *, void *); -int pvsout_perf(CSOUND *, void *); - -int sensekey_perf(CSOUND *, void *); +typedef struct { + OPDS h; + MYFLT *value, *valID; + AUXCH channelName; + const CS_TYPE *channelType; +} INVAL; -int notinit_opcode_stub(CSOUND *, void *); -int chnget_opcode_init_i(CSOUND *, void *); -int chnget_opcode_init_k(CSOUND *, void *); -int chnget_opcode_init_a(CSOUND *, void *); -int chnget_opcode_init_S(CSOUND *, void *); -int chnset_opcode_init_i(CSOUND *, void *); -int chnset_opcode_init_k(CSOUND *, void *); -int chnset_opcode_init_a(CSOUND *, void *); -int chnset_opcode_init_S(CSOUND *, void *); -int chnmix_opcode_init(CSOUND *, void *); -int chnclear_opcode_init(CSOUND *, void *); -int chn_k_opcode_init(CSOUND *, void *); -int chn_a_opcode_init(CSOUND *, void *); -int chn_S_opcode_init(CSOUND *, void *); -int chnexport_opcode_init(CSOUND *, void *); -int chnparams_opcode_init(CSOUND *, void *); -int chnrecv_opcode_init(CSOUND *, void *); -int chnsend_opcode_init(CSOUND *, void *); +typedef struct { + OPDS h; + MYFLT *valID, *value; + AUXCH channelName; + const CS_TYPE *channelType; +} OUTVAL; + +int chano_opcode_perf_k(CSOUND *, CHNVAL *); +int chano_opcode_perf_a(CSOUND *, CHNVAL *); +int chani_opcode_perf_k(CSOUND *, CHNVAL *); +int chani_opcode_perf_a(CSOUND *, CHNVAL *); +int pvsin_init(CSOUND *, FCHAN *); +int pvsin_perf(CSOUND *, FCHAN *); +int pvsout_init(CSOUND *, FCHAN *); +int pvsout_perf(CSOUND *, FCHAN *); -#endif /* CSOUND_BUS_C */ +int sensekey_perf(CSOUND *, KSENSE *); +int notinit_opcode_stub(CSOUND *, void *); +int chnget_opcode_init_i(CSOUND *, CHNGET *); +int chnget_opcode_init_k(CSOUND *, CHNGET *); +int chnget_opcode_init_a(CSOUND *, CHNGET *); +int chnget_opcode_init_S(CSOUND *, CHNGET *); +int chnget_opcode_perf_S(CSOUND *, CHNGET *); +int chnset_opcode_init_i(CSOUND *, CHNGET *); +int chnset_opcode_init_k(CSOUND *, CHNGET *); +int chnset_opcode_init_a(CSOUND *, CHNGET *); +int chnset_opcode_init_S(CSOUND *, CHNGET *); +int chnset_opcode_perf_S(CSOUND *, CHNGET *); +int chnmix_opcode_init(CSOUND *, CHNGET *); +int chnclear_opcode_init(CSOUND *, CHNCLEAR *); +int chn_k_opcode_init(CSOUND *, CHN_OPCODE_K *); +int chn_a_opcode_init(CSOUND *, CHN_OPCODE *); +int chn_S_opcode_init(CSOUND *, CHN_OPCODE *); +int chnexport_opcode_init(CSOUND *, CHNEXPORT_OPCODE *); +int chnparams_opcode_init(CSOUND *, CHNPARAMS_OPCODE *); + +int kinval(CSOUND *csound, INVAL *p); +int kinvalS(CSOUND *csound, INVAL *p); +int invalset(CSOUND *csound, INVAL *p); +int invalset_string(CSOUND *csound, INVAL *p); +int invalset_string_S(CSOUND *csound, INVAL *p); +int invalset_S(CSOUND *csound, INVAL *p); +int koutval(CSOUND *csound, OUTVAL *p); +int koutvalS(CSOUND *csound, OUTVAL *p); +int outvalset(CSOUND *csound, OUTVAL *p); +int outvalset_string(CSOUND *csound, OUTVAL *p); +int outvalset_string_S(CSOUND *csound, OUTVAL *p); +int outvalset_S(CSOUND *csound, OUTVAL *p); #ifdef __cplusplus } #endif #endif /* CSOUND_BUS_H */ - diff -Nru csound-5.17.11~dfsg/H/cfgvar.h csound-6.02~dfsg/H/cfgvar.h --- csound-5.17.11~dfsg/H/cfgvar.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cfgvar.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,415 +0,0 @@ -/* - cfgvar.h: - - Copyright (C) 2005 Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_CFGVAR_H -#define CSOUND_CFGVAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* generic header structure */ - -typedef struct csCfgVariableHead_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - void *p; /* pointer to value */ - int type; /* type (e.g. CSOUNDCFG_INTEGER) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ -} csCfgVariableHead_t; - -/* int type */ - -typedef struct csCfgVariableInt_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - int *p; /* pointer to value */ - int type; /* type (CSOUNDCFG_INTEGER) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ - int min; /* minimum allowed value */ - int max; /* maximum allowed value */ -} csCfgVariableInt_t; - -/* boolean type (int with a value of 0 or 1) */ - -typedef struct csCfgVariableBoolean_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - int *p; /* pointer to value */ - int type; /* type (CSOUNDCFG_BOOLEAN) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ -} csCfgVariableBoolean_t; - -/* float type */ - -typedef struct csCfgVariableFloat_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - float *p; /* pointer to value */ - int type; /* type (CSOUNDCFG_FLOAT) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ - float min; /* minimum allowed value */ - float max; /* maximum allowed value */ -} csCfgVariableFloat_t; - -/* double type */ - -typedef struct csCfgVariableDouble_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - double *p; /* pointer to value */ - int type; /* type (CSOUNDCFG_DOUBLE) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ - double min; /* minimum allowed value */ - double max; /* maximum allowed value */ -} csCfgVariableDouble_t; - -/* MYFLT (float or double) type */ - -typedef struct csCfgVariableMYFLT_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - MYFLT *p; /* pointer to value */ - int type; /* type (CSOUNDCFG_MYFLT) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ - MYFLT min; /* minimum allowed value */ - MYFLT max; /* maximum allowed value */ -} csCfgVariableMYFLT_t; - -/* string type */ - -typedef struct csCfgVariableString_s { - union csCfgVariable_u *nxt; /* pointer to next structure in chain */ - unsigned char *name; /* name of the variable */ - char *p; /* value: array of 'maxlen' chars */ - int type; /* type (CSOUNDCFG_STRING) */ - int flags; /* bitwise OR of flags */ - unsigned char *shortDesc; /* short description (NULL if none) */ - unsigned char *longDesc; /* long description (NULL if none) */ - int maxlen; /* maximum length + 1 */ -} csCfgVariableString_t; - -/* union of all variable types */ - -typedef union csCfgVariable_u { - csCfgVariableHead_t h; - csCfgVariableInt_t i; - csCfgVariableBoolean_t b; - csCfgVariableFloat_t f; - csCfgVariableDouble_t d; - csCfgVariableMYFLT_t m; - csCfgVariableString_t s; -} csCfgVariable_t; - -/* types */ - -#define CSOUNDCFG_INTEGER 1 -#define CSOUNDCFG_BOOLEAN 2 -#define CSOUNDCFG_FLOAT 3 -#define CSOUNDCFG_DOUBLE 4 -#define CSOUNDCFG_MYFLT 5 -#define CSOUNDCFG_STRING 6 - -/* flags */ - -#define CSOUNDCFG_POWOFTWO 0x00000001 - -/* error codes */ - -#define CSOUNDCFG_SUCCESS 0 -#define CSOUNDCFG_INVALID_NAME -1 -#define CSOUNDCFG_INVALID_TYPE -2 -#define CSOUNDCFG_INVALID_FLAG -3 -#define CSOUNDCFG_NULL_POINTER -4 -#define CSOUNDCFG_TOO_HIGH -5 -#define CSOUNDCFG_TOO_LOW -6 -#define CSOUNDCFG_NOT_POWOFTWO -7 -#define CSOUNDCFG_INVALID_BOOLEAN -8 -#define CSOUNDCFG_MEMORY -9 -#define CSOUNDCFG_STRING_LENGTH -10 - -#define CSOUNDCFG_LASTERROR -10 - -/* -------- interface functions -------- */ - -/* This pragma must come before all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export on -#endif - - /** - * Create global configuration variable with the specified parameters. - * This function should be called by the host application only. - * name: name of the variable (may contain letters, digits, and _) - * p: pointer to variable - * type: type of variable, determines how 'p' is interpreted - * CSOUNDCFG_INTEGER: int* - * CSOUNDCFG_BOOLEAN: int* (value may be 0 or 1) - * CSOUNDCFG_FLOAT: float* - * CSOUNDCFG_DOUBLE: double* - * CSOUNDCFG_MYFLT: MYFLT* - * CSOUNDCFG_STRING: char* (should have enough space) - * flags: bitwise OR of flag values, currently only CSOUNDCFG_POWOFTWO - * is available, which requests CSOUNDCFG_INTEGER values to be - * power of two - * min: for CSOUNDCFG_INTEGER, CSOUNDCFG_FLOAT, CSOUNDCFG_DOUBLE, and - * CSOUNDCFG_MYFLT, a pointer to a variable of the type selected - * by 'type' that specifies the minimum allowed value. - * If 'min' is NULL, there is no minimum value. - * max: similar to 'min', except it sets the maximum allowed value. - * For CSOUNDCFG_STRING, it is a pointer to an int variable - * that defines the maximum length of the string (including the - * null character at the end) in bytes. This value is limited - * to the range 8 to 16384, and if max is NULL, it defaults to 256. - * shortDesc: a short description of the variable (may be NULL or an empty - * string if a description is not available) - * longDesc: a long description of the variable (may be NULL or an empty - * string if a description is not available) - * Return value is CSOUNDCFG_SUCCESS, or one of the following error codes: - * CSOUNDCFG_INVALID_NAME - * the specified name is invalid or is already in use - * CSOUNDCFG_MEMORY - * a memory allocation failure occured - * CSOUNDCFG_NULL_POINTER - * the 'p' pointer was NULL - * CSOUNDCFG_INVALID_TYPE - * CSOUNDCFG_INVALID_FLAG - * an invalid variable type was specified, or the flags value - * had unknown bits set - */ -#if 0 - PUBLIC int - csoundCreateGlobalConfigurationVariable(const char *name, - void *p, int type, int flags, - void *min, void *max, - const char *shortDesc, - const char *longDesc); -#endif - - /** - * This function is similar to csoundCreateGlobalConfigurationVariable(), - * except it creates a configuration variable specific to Csound instance - * 'csound', and is suitable for calling from the Csound library - * (in csoundPreCompile()) or plugins (in csoundModuleCreate()). - * The other parameters and return value are the same as in the case of - * csoundCreateGlobalConfigurationVariable(). - */ - PUBLIC int - csoundCreateConfigurationVariable(CSOUND *csound, const char *name, - void *p, int type, int flags, - void *min, void *max, - const char *shortDesc, - const char *longDesc); - - /** - * Copy a global configuration variable to a Csound instance. - * This function is experimental and may be subject to changes in - * future releases of the Csound library. - */ -#if 0 - PUBLIC int csoundCopyGlobalConfigurationVariable(CSOUND *csound, - const char *name, void *p); -#endif - - /** - * Copy all global configuration variables to the specified Csound instance. - * This function is experimental and may be subject to changes in - * future releases of the Csound library. - */ -#if 0 - PUBLIC int csoundCopyGlobalConfigurationVariables(CSOUND *csound); -#endif - - /** - * Set the value of a global configuration variable; should be called by the - * host application only. - * 'value' is a pointer of the same type as the 'p' pointer that was passed - * to csoundCreateGlobalConfigurationVariable(), depending on the type of - * the variable (integer, float, etc.). - * Return value is CSOUNDCFG_SUCCESS in case of success, or one of the - * following error codes: - * CSOUNDCFG_INVALID_NAME - * no configuration variable was found with the specified name - * CSOUNDCFG_NULL_POINTER - * the 'value' pointer was NULL - * CSOUNDCFG_TOO_LOW - * CSOUNDCFG_TOO_HIGH - * CSOUNDCFG_NOT_POWOFTWO - * CSOUNDCFG_INVALID_BOOLEAN - * CSOUNDCFG_STRING_LENGTH - * the specified value was invalid in some way - */ -#if 0 - PUBLIC int csoundSetGlobalConfigurationVariable(const char *name, - void *value); -#endif - - /** - * Set the value of a configuration variable of Csound instance 'csound'. - * The 'name' and 'value' parameters, and return value are the same as - * in the case of csoundSetGlobalConfigurationVariable(). - */ - PUBLIC int csoundSetConfigurationVariable(CSOUND *csound, const char *name, - void *value); - - /** - * Set the value of a global configuration variable, by parsing a string; - * should be called by the host application only. - * For boolean variables, any of the strings "0", "no", "off", and "false" - * will set the value to 0, and any of "1", "yes", "on", and "true" means a - * value of 1. - * Return value is CSOUNDCFG_SUCCESS in case of success, or one of the - * following error codes: - * CSOUNDCFG_INVALID_NAME - * no configuration variable was found with the specified name - * CSOUNDCFG_NULL_POINTER - * the 'value' pointer was NULL - * CSOUNDCFG_TOO_LOW - * CSOUNDCFG_TOO_HIGH - * CSOUNDCFG_NOT_POWOFTWO - * CSOUNDCFG_INVALID_BOOLEAN - * CSOUNDCFG_STRING_LENGTH - * the specified value was invalid in some way - */ -#if 0 - PUBLIC int csoundParseGlobalConfigurationVariable(const char *name, - const char *value); -#endif - - /** - * Set the value of a configuration variable of Csound instance 'csound', - * by parsing a string. - * The 'name' and 'value' parameters, and return value are the same as - * in the case of csoundParseGlobalConfigurationVariable(). - */ - PUBLIC int csoundParseConfigurationVariable(CSOUND *csound, const char *name, - const char *value); - - /** - * Return pointer to the global configuration variable with the specified - * name. - * The return value may be NULL if the variable is not found in the database. - */ -#if 0 - PUBLIC csCfgVariable_t - *csoundQueryGlobalConfigurationVariable(const char *name); -#endif - - /** - * Return pointer to the configuration variable of Csound instace 'csound' - * with the specified name. - * The return value may be NULL if the variable is not found in the database. - */ - PUBLIC csCfgVariable_t - *csoundQueryConfigurationVariable(CSOUND *csound, const char *name); - - /** - * Create an alphabetically sorted list of all global configuration variables. - * Returns a pointer to a NULL terminated array of configuration variable - * pointers, or NULL on error. - * The caller is responsible for freeing the returned list with - * csoundDeleteCfgVarList(), however, the variable pointers in the list - * should not be freed. - */ -#if 0 - PUBLIC csCfgVariable_t **csoundListGlobalConfigurationVariables(void); -#endif - - /** - * Create an alphabetically sorted list of all configuration variables - * of Csound instance 'csound'. - * Returns a pointer to a NULL terminated array of configuration variable - * pointers, or NULL on error. - * The caller is responsible for freeing the returned list with - * csoundDeleteCfgVarList(), however, the variable pointers in the list - * should not be freed. - */ - PUBLIC csCfgVariable_t **csoundListConfigurationVariables(CSOUND *csound); - - /** - * Release a configuration variable list previously returned - * by csoundListGlobalConfigurationVariables() or - * csoundListConfigurationVariables(). - */ - PUBLIC void csoundDeleteCfgVarList(csCfgVariable_t **lst); - - /** - * Remove the global configuration variable with the specified name - * from the database. Should be called by the host application only, - * and never by the Csound library or plugins. - * Return value is CSOUNDCFG_SUCCESS in case of success, or - * CSOUNDCFG_INVALID_NAME if the variable was not found. - */ -#if 0 - PUBLIC int csoundDeleteGlobalConfigurationVariable(const char *name); -#endif - - /** - * Remove the configuration variable of Csound instance 'csound' with the - * specified name from the database. Plugins need not call this, as all - * configuration variables are automatically deleted by csoundReset(). - * Return value is CSOUNDCFG_SUCCESS in case of success, or - * CSOUNDCFG_INVALID_NAME if the variable was not found. - */ - PUBLIC int csoundDeleteConfigurationVariable(CSOUND *csound, - const char *name); - - /** - * Remove all global configuration variables and free database. - * Should be called by the host application only, and never by the - * Csound library or plugins. - * Return value is CSOUNDCFG_SUCCESS in case of success. - */ -#if 0 - PUBLIC int csoundDeleteAllGlobalConfigurationVariables(void); -#endif - - /** - * Returns pointer to an error string constant for the specified - * CSOUNDCFG error code. The string is not translated. - */ - PUBLIC const char *csoundCfgErrorCodeToString(int errcode); - -/* This pragma must come after all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export off -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* CSOUND_CFGVAR_H */ - diff -Nru csound-5.17.11~dfsg/H/compile_ops.h csound-6.02~dfsg/H/compile_ops.h --- csound-5.17.11~dfsg/H/compile_ops.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/H/compile_ops.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,21 @@ +#include + +typedef struct _compile { + OPDS h; + MYFLT *res; + MYFLT *str; + MYFLT *ktrig; +}COMPILE; + +typedef struct _retval { + OPDS h; + MYFLT *ret; +} RETVAL; + +int compile_orc_i(CSOUND *csound, COMPILE *c); +int compile_str_i(CSOUND *csound, COMPILE *c); +int read_score_i(CSOUND *csound, COMPILE *c); +int eval_str_i(CSOUND *csound, COMPILE *p); +int eval_str_k(CSOUND *csound, COMPILE *p); +int retval_i(CSOUND *csound, RETVAL *p); +int eval_str_k(CSOUND *csound, COMPILE *p); diff -Nru csound-5.17.11~dfsg/H/convolve.h csound-6.02~dfsg/H/convolve.h --- csound-5.17.11~dfsg/H/convolve.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/convolve.h 2014-01-07 16:53:47.000000000 +0000 @@ -40,12 +40,12 @@ int32 headBsize; /* byte offset from start to data */ int32 dataBsize; /* total number of bytes of data */ int32 dataFormat; /* (int) format specifier */ - MYFLT samplingRate; /* of original sample */ + MYFLT samplingRate; /* of original sample */ int32 src_chnls; /* no. of channels in source */ int32 channel; /* requested channel(s) */ int32 Hlen; /* length of impulse reponse */ int32 Format; /* (int) how words are org'd in frm */ - char info[CVDFLTBYTS]; /* extendable byte area */ + char info[CVDFLTBYTS]; /* extendable byte area */ } CVSTRUCT; /* Error codes returned by CONVOLVE file functions */ diff -Nru csound-5.17.11~dfsg/H/corfile.h csound-6.02~dfsg/H/corfile.h --- csound-5.17.11~dfsg/H/corfile.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/corfile.h 2014-01-07 16:54:20.000000000 +0000 @@ -26,9 +26,9 @@ #define __corfil CORFIL *corfile_create_w(void); -CORFIL *corfile_create_r(char *text); +CORFIL *corfile_create_r(const char *text); void corfile_putc(int c, CORFIL *f); -void corfile_puts(char *s, CORFIL *f); +void corfile_puts(const char *s, CORFIL *f); void corfile_flush(CORFIL *f); void corfile_rm(CORFIL **ff); int corfile_getc(CORFIL *f); @@ -45,11 +45,13 @@ #define corfile_body(f) (f->body) char *corfile_current(CORFIL *f); #define corfile_current(f) (f->body+f->p) -CORFIL *copy_to_corefile(CSOUND *, char *, char *, int); +CORFIL *copy_to_corefile(CSOUND *, const char *, const char *, int); +CORFIL *copy_url_corefile(CSOUND *, const char *, int); int corfile_length(CORFIL *f); #define corfile_length(f) (strlen(f->body)) void corfile_set(CORFIL *f, int n); #define corfile_set(f,n) (f->p = n) void corfile_seek(CORFIL *f, int n, int dir); +void corfile_preputs(const char *s, CORFIL *f); #endif diff -Nru csound-5.17.11~dfsg/H/cs_jack.h csound-6.02~dfsg/H/cs_jack.h --- csound-5.17.11~dfsg/H/cs_jack.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_jack.h 2014-01-07 16:53:47.000000000 +0000 @@ -38,4 +38,5 @@ jack_default_audio_sample_t **outPortBufs; RtJackBuffer **bufs; /* 'nBuffers' I/O buffers */ int xrunFlag; /* non-zero if an xrun has occured */ + jack_client_t *listclient; } RtJackGlobals; diff -Nru csound-5.17.11~dfsg/H/cs_par_base.h csound-6.02~dfsg/H/cs_par_base.h --- csound-5.17.11~dfsg/H/cs_par_base.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_par_base.h 2014-01-07 16:53:47.000000000 +0000 @@ -13,22 +13,22 @@ /* #define LOCK_TYPE pthread_mutex_t */ /* #define INIT_LOCK(x) pthread_mutex_init(&(x), NULL) */ -#if !defined(HAVE_PTHREAD_SPIN_LOCK) /* VL: 18.05.2011 enabled this to allow OSX build */ - # define TAKE_LOCK(x) pthread_mutex_lock(x) - # define RELS_LOCK(x) pthread_mutex_unlock(x) - # define LOCK_TYPE pthread_mutex_t - # define INIT_LOCK(x) pthread_mutex_init(&(x), NULL) - - #else - # define TAKE_LOCK(x) pthread_spin_lock(x) - # define RELS_LOCK(x) pthread_spin_unlock(x) - # define LOCK_TYPE pthread_spinlock_t - # define INIT_LOCK(x) pthread_spin_init(&(x), PTHREAD_PROCESS_PRIVATE) -#endif +#if !defined(HAVE_PTHREAD_SPIN_LOCK) + /* VL: 18.05.2011 enabled this to allow OSX build */ + # define TAKE_LOCK(x) pthread_mutex_lock(x) + # define RELS_LOCK(x) pthread_mutex_unlock(x) + # define LOCK_TYPE pthread_mutex_t + # define INIT_LOCK(x) pthread_mutex_init(&(x), NULL) + + #else + # define TAKE_LOCK(x) pthread_spin_lock(x) + # define RELS_LOCK(x) pthread_spin_unlock(x) + # define LOCK_TYPE pthread_spinlock_t + # define INIT_LOCK(x) pthread_spin_init(&(x), PTHREAD_PROCESS_PRIVATE) +#endif #define DYNAMIC_2_SERIALIZE_PAR -#define TRACE 0 /* #define TIMING */ /* #define SPINLOCK_BARRIER */ @@ -41,85 +41,28 @@ /* #define CACLULATE_WEIGHTS_BUILD */ #define LOOKUP_WEIGHTS -#ifdef TIMING - #define TIMER_INIT(val, name) RTCLOCK val ## _timer; - #define TIMER_START(val, name) \ - csound->InitTimerStruct(& val ## _timer); \ - csound->Message(csound, name "Start: %f\n", \ - csound->GetRealTime(& val ## _timer)) - #define TIMER_END(val, name) \ - csound->Message(csound, name "End: %f\n", \ - csound->GetRealTime(& val ## _timer)) - - #define TIMER_T_START(val, index, name) \ - csound->InitTimerStruct(& val ## _timer); \ - csound->Message(csound, "[%i] " name "Start: %f\n", \ - index, csound->GetRealTime(& val ## _timer)) - #define TIMER_T_END(val, index, name) \ - csound->Message(csound, "[%i] " name "End: %f\n", \ - index, csound->GetRealTime(& val ## _timer)) -#else - #define TIMER_INIT(val, name) - #define TIMER_START(val, name) - #define TIMER_END(val, name) - #define TIMER_T_START(val, index, name) - #define TIMER_T_END(val, index, name) -#endif - -#if (TRACE&1) == 1 -#define TRACE_0(...) { csound->Message(csound,"0:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_0(...) -#endif -#if (TRACE&2) == 2 -#define TRACE_1(...) { csound->Message(csound,"1:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_1(...) -#endif -#if (TRACE&4) == 4 - #define TRACE_2(...) { csound->Message(csound,"2:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_2(...) -#endif -#if (TRACE&8) == 8 - #define TRACE_3(...) { csound->Message(csound,"3:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_3(...) -#endif -#if (TRACE&16) == 16 - #define TRACE_4(...) { csound->Message(csound,"4:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_4(...) -#endif -#if (TRACE&32) == 32 - #define TRACE_5(...) { csound->Message(csound,"5:"); csound->Message(csound, __VA_ARGS__);} -#else - #define TRACE_5(...) -#endif - #define KPERF_SYM 0x31 #define BARRIER_1_WAIT_SYM 0x32 #define BARRIER_2_WAIT_SYM 0x33 -#define SHARK_SIGNPOST(sym) /* return thread index of caller */ int csp_thread_index_get(CSOUND *csound); /* structure headers */ #define HDR_LEN 4 -#define INSTR_WEIGHT_INFO_HDR "IWI" +//#define INSTR_WEIGHT_INFO_HDR "IWI" #define INSTR_SEMANTICS_HDR "SEM" #define SET_ELEMENT_HDR "STE" #define SET_HDR "SET" -#define DAG_2_HDR "DG2" -#define DAG_NODE_2_HDR "DN2" -#define SEMAPHORE_HDR "SPS" +//#define DAG_2_HDR "DG2" +//#define DAG_NODE_2_HDR "DN2" +//#define SEMAPHORE_HDR "SPS" #define GLOBAL_VAR_LOCK_HDR "GVL" -#define SERIALIZED_DAG_HDR "SDG" +//#define SERIALIZED_DAG_HDR "SDG" /* * set structures - * + * * set maintains insertion order of elements * implemented as a singly linked list */ @@ -168,10 +111,10 @@ int csp_set_print(CSOUND *csound, struct set_t *set); /* get a count and access members */ -extern int inline csp_set_count(CSOUND *csound, struct set_t *set); -extern int inline csp_set_get_num(CSOUND *csound, struct set_t *set, int num, void **data); +int csp_set_count(struct set_t *set); +int csp_set_get_num(struct set_t *set, int num, void **data); -/* +/* * set union and intersection * allocates a new set in result * union/intersect first and second putting into result @@ -203,7 +146,7 @@ void csp_semaphore_alloc(CSOUND *csound, sem_t **sem, int max_threads); void csp_semaphore_dealloc(CSOUND *csound, sem_t **sem); -/* wait at the semaphore. if the number allowed in is greater than the +/* wait at the semaphore. if the number allowed in is greater than the * number arrived calling thread continues * otherwise thread blocks until semaphore is grown */ diff -Nru csound-5.17.11~dfsg/H/cs_par_dispatch.h csound-6.02~dfsg/H/cs_par_dispatch.h --- csound-5.17.11~dfsg/H/cs_par_dispatch.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_par_dispatch.h 2014-01-07 16:53:47.000000000 +0000 @@ -11,115 +11,8 @@ /* build the cache of global locks */ void csp_locks_cache_build(CSOUND *csound); /* lock global with index */ -extern void inline csp_locks_lock(CSOUND * csound, int global_index); +void csp_locks_lock(CSOUND * csound, int global_index); /* unlock global with index */ -extern void inline csp_locks_unlock(CSOUND * csound, int global_index); - -/* fetch a weight for opcode name */ -uint32_t csp_opcode_weight_fetch(CSOUND *csound, char *name); -/* set the time for opcode name */ -void csp_opcode_weight_set(CSOUND *csound, char *name, double play_time); -/* print opcode weights */ -void csp_weights_dump(CSOUND *csound); -/* print opcode weights normalised to 1-100 (inclusive) scale */ -void csp_weights_dump_normalised(CSOUND *csound); -/* dump opcode weights normalised to a file with 1-100 (inclusive) scale - * also write out the times associated with the weights */ -void csp_weights_dump_file(CSOUND *csound); -/* load opcode weights from a file */ -void csp_weights_load(CSOUND *csound); -/* calculate the weight for each instrument in the AST - * put the weight in the instr_semantics_t structure stored in - * cs_par_orc_semantic_analysis */ -void csp_weights_calculate(CSOUND *csound, TREE *root); - -/* dag2 prototypes */ -enum dag_node_type_t { - DAG_NODE_INDV, - DAG_NODE_LIST, - DAG_NODE_DAG -}; - -struct dag_base_t { - char hdr[HDR_LEN]; - enum dag_node_type_t type; -}; - -typedef struct dag_t { - struct dag_base_t hdr; - - int count; - LOCK_TYPE spinlock; - LOCK_TYPE table_spinlock; - LOCK_TYPE consume_spinlock; - struct dag_node_t **all; - struct dag_node_t *insds_chain_start; - struct dag_node_t **roots_ori; - struct dag_node_t **roots; - uint8_t *root_seen_ori; - uint8_t *root_seen; - int *remaining_count_ori; - int *remaining_count; - int remaining; - int first_root_ori; - int first_root; - uint8_t **table_ori; - uint8_t **table; - - /* used for deciding whether to run this dag in parallel */ - int max_roots; - uint32_t weight; -} DAG; - -/* load the parallel decision infomation from specified file */ -void csp_parallel_compute_spec_setup(CSOUND *csound); -/* decide based in parallel decision info whether to do this dag in parallel */ -#if 0 -int inline csp_parallel_compute_should(CSOUND *csound, DAG *dag); -#endif - -typedef struct dag_node_t { - struct dag_base_t hdr; - - union { - struct { - struct instr_semantics_t *instr; - INSDS *insds; - struct dag_node_t *insds_chain_next; - }; - struct { - int count; - struct dag_node_t **nodes; - }; - }; -} DAG_NODE; - -void csp_dag_alloc(CSOUND *csound, DAG **dag); -void csp_dag_dealloc(CSOUND *csound, DAG **dag); -/* add a node to the dag with instrument info */ -void csp_dag_add(CSOUND *csound, DAG *dag, - struct instr_semantics_t *instr, INSDS *insds); - -/* once a DAG has been created and had all its instruments added call this - * prepares a DAG for use - * builds edges, roots, root countdowns, finds weight, etc */ -void csp_dag_build(CSOUND *csound, DAG **dag, INSDS *chain); -void csp_dag_print(CSOUND *csound, DAG *dag); - -/* return 1 if the DAG is completely consume */ -extern int inline csp_dag_is_finished(CSOUND *csound, DAG *dag); -/* get a node from the dag - * update_hdl should be passed into consume_update when the node has - * been performed */ -void csp_dag_consume(CSOUND *csound, DAG *dag, - struct dag_node_t **node, int *update_hdl); -/* update the dag having consumed a node previously */ -void csp_dag_consume_update(CSOUND *csound, DAG *dag, int update_hdl); - -/* get a dag from the cache - * if it exists it is retuned - * if not builds a new one and stores in the cache, then returns */ -void csp_dag_cache_fetch(CSOUND *csound, DAG **dag, INSDS *chain); -void csp_dag_cache_print(CSOUND *csound); +void csp_locks_unlock(CSOUND * csound, int global_index); #endif /* end of include guard: __CS_PAR_DISPATCH_H__ */ diff -Nru csound-5.17.11~dfsg/H/cs_par_ops.h csound-6.02~dfsg/H/cs_par_ops.h --- csound-5.17.11~dfsg/H/cs_par_ops.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_par_ops.h 2014-01-07 16:53:47.000000000 +0000 @@ -1,7 +1,7 @@ /* cs_par_ops.h: - Copyright (C) 2010 Chriss Wilson and John ffitch + Copyright (C) 2010 Chris Wilson and John ffitch This file is part of Csound. @@ -28,9 +28,3 @@ OPDS h; MYFLT *gvar_ix; } GLOBAL_LOCK_UNLOCK; - - -typedef struct { - OPDS h; - MYFLT *icnt; -} WASTE; diff -Nru csound-5.17.11~dfsg/H/cs_par_orc_semantics.h csound-6.02~dfsg/H/cs_par_orc_semantics.h --- csound-5.17.11~dfsg/H/cs_par_orc_semantics.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_par_orc_semantics.h 2014-01-07 16:53:47.000000000 +0000 @@ -1,17 +1,17 @@ #ifndef __CSOUND_ORC_SEMANTIC_ANALYSIS_H__ #define __CSOUND_ORC_SEMANTIC_ANALYSIS_H__ -/* +/* * This module maintains a list of instruments that have been parsed * When parsing an instrument: - * csp_orc_sa_instr_add + * csp_orc_sa_instr_add * called first to setup instrument (when parsed the instrument name/number) - * csp_orc_sa_global_read_write_add_list + * csp_orc_sa_global_read_write_add_list * called to add globals to that instruments dependency lists * csp_orc_sa_instr_finalize * called when finished parsing that instrument - * + * * csp_orc_sa_instr_get_by_name or by_num * called to fetch an instrument later */ @@ -36,13 +36,16 @@ void csp_orc_sa_instr_add(CSOUND *csound, char *name); void csp_orc_sa_instr_add_tree(CSOUND *csound, TREE *x); /* finish the current instrument */ -void csp_orc_sa_instr_finalize(CSOUND *csound); +#define csp_orc_sa_instr_finalize(csound) \ + { csound->instCurr = NULL; csound->inInstr = 0; } -/* add the globals read and written to the current instrument +/* add the globals read and written to the current instrument; second case * if write and read contain the same global and size of both is 1 then * that global is added to the read-write list of the current instrument */ void csp_orc_sa_global_read_write_add_list(CSOUND *csound, struct set_t *write, struct set_t *read); +void csp_orc_sa_global_read_write_add_list1(CSOUND *csound, + struct set_t *write, struct set_t *read); /* add to the read and write lists of the current instrument */ void csp_orc_sa_global_write_add_list(CSOUND *csound, struct set_t *list); @@ -52,14 +55,15 @@ struct set_t *csp_orc_sa_globals_find(CSOUND *csound, TREE *node); /* find an instrument from the instruments parsed */ -struct instr_semantics_t +struct instr_semantics_t *csp_orc_sa_instr_get_by_name(CSOUND *csound, char *instr_name); -struct instr_semantics_t +struct instr_semantics_t *csp_orc_sa_instr_get_by_num(CSOUND *csound, int16 insno); /* interlocks */ void csp_orc_sa_interlocks(CSOUND *, ORCTOKEN *); void csp_orc_sa_interlocksf(CSOUND *, int); +void csp_orc_analyze_tree(CSOUND *, TREE*); #endif /* end of include guard: __CSOUND_ORC_SEMANTIC_ANALYSIS_H__ */ diff -Nru csound-5.17.11~dfsg/H/cs_par_structs.h csound-6.02~dfsg/H/cs_par_structs.h --- csound-5.17.11~dfsg/H/cs_par_structs.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cs_par_structs.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,37 +0,0 @@ -/* - csoundCore.h: - - Copyright (C) 2011 John ffitch and Chris Wilson - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - - -/* global variables lock support */ -struct global_var_lock_t; - -struct opcode_weight_cache_entry_t; - -struct dag_node_t; - -struct dag_cache_entry_t; -#define DAG_2_CACHE_SIZE (128) -#define OPCODE_WEIGHT_CACHE_SIZE (128) - -struct instr_semantics_t; - diff -Nru csound-5.17.11~dfsg/H/cscore.h csound-6.02~dfsg/H/cscore.h --- csound-5.17.11~dfsg/H/cscore.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cscore.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,109 +0,0 @@ -/* - cscore.h: - - Copyright (C) 1991 Barry Vercoe, John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSCORE_H -#define CSCORE_H - -#include - -#ifndef MYFLT -#include "sysdep.h" -#endif -#include "csound.h" - -typedef struct cshdr { - struct cshdr *prvblk; - struct cshdr *nxtblk; - int16 type; - int16 size; -} CSHDR; - -/* Single score event structure */ -typedef struct { - CSHDR h; - char *strarg; - char op; - int16 pcnt; - MYFLT p2orig; - MYFLT p3orig; - MYFLT p[1]; -} EVENT; - -/* Event list structure */ -typedef struct { - CSHDR h; - int nslots; - int nevents; - EVENT *e[1]; -} EVLIST; - -/* This pragma must come before all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export on -#endif - -/* Functions for working with single events */ -PUBLIC EVENT *cscoreCreateEvent(CSOUND*, int); -PUBLIC EVENT *cscoreDefineEvent(CSOUND*, char*); -PUBLIC EVENT *cscoreCopyEvent(CSOUND*, EVENT*); -PUBLIC EVENT *cscoreGetEvent(CSOUND*); -PUBLIC void cscorePutEvent(CSOUND*, EVENT*); -PUBLIC void cscorePutString(CSOUND*, char*); - -/* Functions for working with event lists */ -PUBLIC EVLIST *cscoreListCreate(CSOUND*, int); -PUBLIC EVLIST *cscoreListAppendEvent(CSOUND*, EVLIST*, EVENT*); -PUBLIC EVLIST *cscoreListAppendStringEvent(CSOUND*, EVLIST*, char*); -PUBLIC EVLIST *cscoreListGetSection(CSOUND*); -PUBLIC EVLIST *cscoreListGetNext(CSOUND *, MYFLT); -PUBLIC EVLIST *cscoreListGetUntil(CSOUND*, MYFLT); -PUBLIC EVLIST *cscoreListCopy(CSOUND*, EVLIST*); -PUBLIC EVLIST *cscoreListCopyEvents(CSOUND*, EVLIST*); -PUBLIC EVLIST *cscoreListExtractInstruments(CSOUND*, EVLIST*, char*); -PUBLIC EVLIST *cscoreListExtractTime(CSOUND*, EVLIST*, MYFLT, MYFLT); -PUBLIC EVLIST *cscoreListSeparateF(CSOUND*, EVLIST*); -PUBLIC EVLIST *cscoreListSeparateTWF(CSOUND*, EVLIST*); -PUBLIC EVLIST *cscoreListAppendList(CSOUND*, EVLIST*, EVLIST*); -PUBLIC EVLIST *cscoreListConcatenate(CSOUND*, EVLIST*, EVLIST*); -PUBLIC void cscoreListPut(CSOUND*, EVLIST*); -PUBLIC int cscoreListPlay(CSOUND*, EVLIST*); -PUBLIC void cscoreListSort(CSOUND*, EVLIST*); -PUBLIC int cscoreListCount(CSOUND*, EVLIST *); - -/* Functions for reclaiming memory */ -PUBLIC void cscoreFreeEvent(CSOUND*, EVENT*); -PUBLIC void cscoreListFree(CSOUND*, EVLIST*); -PUBLIC void cscoreListFreeEvents(CSOUND*, EVLIST*); - -/* Functions for working with multiple input score files */ -PUBLIC FILE *cscoreFileOpen(CSOUND*, char*); -PUBLIC void cscoreFileClose(CSOUND*, FILE*); -PUBLIC FILE *cscoreFileGetCurrent(CSOUND*); -PUBLIC void cscoreFileSetCurrent(CSOUND*, FILE*); - -/* This pragma must come after all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export off -#endif - -#endif diff -Nru csound-5.17.11~dfsg/H/csdl.h csound-6.02~dfsg/H/csdl.h --- csound-5.17.11~dfsg/H/csdl.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csdl.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,89 +0,0 @@ -/* - csdl.h: - - Copyright (C) 2002 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_CSDL_H -#define CSOUND_CSDL_H - -#ifdef __BUILDING_LIBCSOUND -#undef __BUILDING_LIBCSOUND -#endif - -#include "csoundCore.h" -#include "interlocks.h" - -#ifdef __cplusplus -extern "C" { -#endif - - - - -#undef Str -#ifndef GNU_GETTEXT -#define Str(x) (x) -#else -#define Str(x) (csound->LocalizeString(x)) -#endif - -PUBLIC long csound_opcode_init(CSOUND *, OENTRY **); -PUBLIC NGFENS *csound_fgen_init(CSOUND *); - -PUBLIC int csoundModuleCreate(CSOUND *); -PUBLIC int csoundModuleInit(CSOUND *); -PUBLIC int csoundModuleDestroy(CSOUND *); -PUBLIC const char *csoundModuleErrorCodeToString(int); - -PUBLIC int csoundModuleInfo(void); - -#define LINKAGE \ -PUBLIC long csound_opcode_init(CSOUND *csound, OENTRY **ep) \ -{ (void) csound; *ep = localops; return (long) sizeof(localops); } \ -PUBLIC int csoundModuleInfo(void) \ -{ return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - -#undef LINKAGE1 -#define LINKAGE1(name) \ -PUBLIC long csound_opcode_init(CSOUND *csound, OENTRY **ep) \ -{ (void) csound; *ep = name; return (long) (sizeof(name)); } \ -PUBLIC int csoundModuleInfo(void) \ -{ return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - -#define FLINKAGE \ -PUBLIC NGFENS *csound_fgen_init(CSOUND *csound) \ -{ (void) csound; return localfgens; } \ -PUBLIC int csoundModuleInfo(void) \ -{ return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - -#undef FLINKAGE1 -#define FLINKAGE1(name) \ -PUBLIC NGFENS *csound_fgen_init(CSOUND *csound) \ -{ (void) csound; return name; } \ -PUBLIC int csoundModuleInfo(void) \ -{ return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - -#ifdef __cplusplus -} -#endif - -#endif /* CSOUND_CSDL_H */ - diff -Nru csound-5.17.11~dfsg/H/csmodule.h csound-6.02~dfsg/H/csmodule.h --- csound-5.17.11~dfsg/H/csmodule.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csmodule.h 2014-01-07 16:53:47.000000000 +0000 @@ -30,7 +30,7 @@ * ==================== * * * * Plugin libraries are loaded from the directory defined by the environment * - * variable OPCODEDIR (or the current directory if OPCODEDIR is unset) by * + * variable OPCODE6DIR (or the current directory if OPCODE6DIR is unset) by * * csoundPreCompile() while initialising a Csound instance, and are unloaded * * at the end of performance by csoundReset(). * * A library may export any of the following five interface functions, * diff -Nru csound-5.17.11~dfsg/H/csound.h csound-6.02~dfsg/H/csound.h --- csound-5.17.11~dfsg/H/csound.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csound.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,1973 +0,0 @@ -#ifndef CSOUND_H -#define CSOUND_H -/*! \mainpage - * - * Csound is a unit generator-based, user-programmable, user-extensible computer music system. - * It was originally written by Barry Vercoe at the Massachusetts Institute of Technology in 1984 - * as the first C language version of this type of software. Since then Csound has received - * numerous contributions from researchers, programmers, and musicians from around the world. - * - * CsoundAC is a Python extension module for doing algorithmic composition, in one which one - * writes music by programming in Python. Musical events are points in music space with - * dimensions {time, duration, event type, instrument, pitch as MIDI key, loudness as MIDI - * velocity, phase, pan, depth, height, pitch-class set, 1}, and pieces are composed by - * assembling a hierarchical tree of nodes in music space. Each node has its own local - * transformation of coordinates in music space. Nodes can be empty, contain scores or - * fragments of scores, generate scores, or transform scores. CsoundAC also contains a Python - * interface to the Csound API, making it easy to render CsoundAC compositions using Csound. - * - * \section section_licenses Licenses - * - * \subsection section_csound_license Csound, CsoundAC, and CsoundVST - * - * Copyright (C) 2001-2005 Michael Gogins, Matt Ingalls, John D. Ramsdell, - * John P. ffitch, Istvan Varga, Victor Lazzarini - * - * This software is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This software is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this software; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * \subsection section_manual_license Manual - * - * Permission is granted to copy, distribute and/or modify this document - * under the terms of the GNU Free Documentation License, Version 1.2 or - * any later version published by the Free Software Foundation; with no - * Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. - * - * \section section_api_outline Outline of the API - * - * \subsection section_api_apilist The Csound Application Programming Interfaces - * - * The Csound Application Programming Interface (API) reference is contained herein. - * The Csound API actually consists of several APIs: - * - * - The basic Csound C API. Include csound.h and link with libcsound.a. - * This also includes the Cscore API (see below). - * - The basic Csound C++ API. Include csound.hpp and link with libcsound.a. - * - The extended Csound C++ API. Include CppSound.hpp and link with - * libcsound.a and libcsnd.a, - * which adds to the Csound C++ API a CsoundFile class for loading, saving, - * and editing Csound orchestra and score files. - * - The CsoundAC C++ API. Include CsoundAC.hpp and link with libcsound.a, - * libcsnd.a, and libCsoundAC.a. - * The CsoundAC class contains an instance of the CppSound class, - * and provides a class hierarchy for doing algorithmic composition using - * Michael Gogins' concept of music graphs (previously known as Silence). - * - The Csound Python API. Import the csnd Python extension module. - * This provides a complete Python wrapper for csound.hpp, CppSound, - * and CsoundFile. The Python API provides a complete Python wrapper - * for the entire Csound C++ API, - * and the Csound C++ API reference also serves as a reference to the Python API. - * - The CsoundAC Python API. Import the CsoundAC Python extension module. - * The Python API provides a complete Python wrapper - * for the entire CsoundAC C++ API, including Silence, and the CsoundAC - * C++ API reference also serves as a reference to the Python API. - * - An experimental LISP API. - * - * \section section_api_c_example An Example Using the Csound API - * - * The Csound command--line program is itself built using the Csound API. - * Its code reads as follows: - * - * \code - * #include "csound.h" - * - * int main(int argc, char **argv) - * { - * // Create Csound. - * void *csound = csoundCreate(0); - * // One complete compile/perform cycle. - * int result = csoundCompile(csound, argc, argv); - * if(!result) { - * while(csoundPerformKsmps(csound) == 0){} - * csoundCleanup(csound); - * } - * // Destroy Csound. - * csoundDestroy(csound); - * return result; - * } - * \endcode - * - * \section section_api_example_cpp The CsoundAC C++ API - * - * CsoundAC extends the Csound API with C++. There is a C++ class for the Csound API proper (CppSound), - * another C++ class (CsoundFile) for manipulating Csound files in code, and additional classes for - * algorithmic composition based on music space. All these C++ classes also have a - * Python interface in the CsoundAC Python extension module. - * - * You can build CsoundAC into your own software using the CsoundAC shared library and - * CsoundAC.hpp header file. - * - * \section section_api_cscore Cscore - * - * Beginning with Csound 5, all of the Cscore functions described in the - * manual are now part of the Csound API, and they can be called from a program - * that calls the Csound library. - * - * All of the CScore functions are renamed in the Csound API. For example, createv() is now - * cscoreCreateEvent(), and lcopy() is now cscoreListCopy(). In addition, each - * function takes an additional first parameter that is a pointer to a CSOUND - * instance. You can find the details in the header file, cscore.h, which may - * be included with your Csound distribution, or if not, can be found in Csound CVS - *`on SourceForge. - * - * Before you can use any of the Cscore API functions, you must create a CSOUND - * instance and initialize Cscore by calling csoundInitializeCscore() -- see - * csound.h for an explanation. An example main program that does all of this - * Top/cscormai.c. You should add a function called cscore() with your own - * score-processing code. An example that does nothing except write the score - * back out unchanged can be found in the file Top/cscore_internal.c. - * - * To create your own standalone Cscore program, you must compile cscormai.c - * (or your own main program) and the file containing your - * cscore() function, and link them with the Csound API library. - * - * Everything that can be done using C as in the above examples can also be done - * in a similar manner in Python or any of the other Csound API languages. - * - * \file - * - * \brief Declares the public Csound application programming interface (API). - * \author John P. ffitch, Michael Gogins, Matt Ingalls, John D. Ramsdell, - * Istvan Varga and Victor Lazzarini - * - * \b Purposes - * - * The purposes of the Csound API are as follows: - * - * \li Declare a stable public application programming interface (API) - * for Csound in csound.h. This is the only header file that needs - * to be \#included by users of the Csound API. - * - * \li Hide the internal implementation details of Csound from users of - * the API, so that development of Csound can proceed without affecting - * code that uses the API. - * - * \b Users - * - * Users of the Csound API fall into two main categories: hosts, and plugins. - * - * \li Hosts are applications that use Csound as a software synthesis engine. - * Hosts can link with the Csound API either statically or dynamically. - * - * \li Plugins are shared libraries loaded by Csound at run time to implement - * external opcodes and/or drivers for audio or MIDI input and output. - * - * Hosts using the Csound API must \#include , and link with the - * Csound API library. Plugin libraries should \#include to get - * access to the API function pointers in the CSOUND structure, and do not - * need to link with the Csound API library. - * Only one of csound.h and csdl.h may be included by a compilation unit. - * - * Hosts must first create an instance of Csound using the \c csoundCreate - * API function. When hosts are finished using Csound, they must destroy the - * instance of csound using the \c csoundDestroy API function. - * Most of the other Csound API functions take the Csound instance as their - * first argument. - * Hosts can only call the standalone API functions declared in csound.h. - * - * Here is the complete code for the simplest possible Csound API host, - * a command-line Csound application: - * - * \code - * - * #include - * - * int main(int argc, char **argv) - * { - * CSOUND *csound = csoundCreate(NULL); - * int result = csoundCompile(csound, argc, argv); - * if (!result) - * result = csoundPerform(csound); - * csoundDestroy(csound); - * return (result >= 0 ? 0 : result); - * } - * - * \endcode - * - * All opcodes, including plugins, receive a pointer to their host - * instance of Csound as the first argument. Therefore, plugins MUST NOT - * compile, perform, or destroy the host instance of Csound, and MUST call - * the Csound API function pointers off the Csound instance pointer. - * - * \code - * MYFLT sr = csound->GetSr(csound); - * \endcode - * - * In general, plugins should ONLY access Csound functionality through the - * API function pointers and public members of the CSOUND structure. - */ - -/* - * Platform-dependent definitions and declarations. - */ - -#if (defined(WIN32) || defined(_WIN32)) && !defined(SWIG) -# define PUBLIC __declspec(dllexport) -#elif defined(__GNUC__) && !defined(__MACH__) -# define PUBLIC __attribute__ ( (visibility("default")) ) -#else -# define PUBLIC -#endif - -#if defined(MSVC) -# include /* for _InterlockedExchange */ -#endif - -/** - * Enables Python interface. - */ - -#ifdef SWIG -#define CS_PRINTF2 -#define CS_PRINTF3 -#ifndef __MYFLT_DEF -#define __MYFLT_DEF -#ifndef USE_DOUBLE -#define MYFLT float -#else -#define MYFLT double -#endif -#endif -%module csnd -%{ -# include "sysdep.h" -# include "text.h" -# include -%} -#else -# include "sysdep.h" -# include "text.h" -# include -#endif - -#ifdef __cplusplus -extern "C" { -#endif - - /** - * ERROR DEFINITIONS - */ - - typedef enum - { - /* Completed successfully. */ - CSOUND_SUCCESS = 0, - /* Unspecified failure. */ - CSOUND_ERROR = -1, - /* Failed during initialization. */ - CSOUND_INITIALIZATION = -2, - /* Failed during performance. */ - CSOUND_PERFORMANCE = -3, - /* Failed to allocate requested memory. */ - CSOUND_MEMORY = -4, - /* Termination requested by SIGINT or SIGTERM. */ - CSOUND_SIGNAL = -5 - } - CSOUND_STATUS; - - /* Compilation or performance aborted, but not as a result of an error - (e.g. --help, or running an utility with -U). */ -#define CSOUND_EXITJMP_SUCCESS (256) - - /** - * Flags for csoundInitialize(). - */ -#define CSOUNDINIT_NO_SIGNAL_HANDLER 1 -#define CSOUNDINIT_NO_ATEXIT 2 - - /** - * Constants used by the bus interface (csoundGetChannelPtr() etc.). - */ -#define CSOUND_CONTROL_CHANNEL 1 -#define CSOUND_AUDIO_CHANNEL 2 -#define CSOUND_STRING_CHANNEL 3 - -#define CSOUND_CHANNEL_TYPE_MASK 15 - -#define CSOUND_INPUT_CHANNEL 16 -#define CSOUND_OUTPUT_CHANNEL 32 - -#define CSOUND_CONTROL_CHANNEL_INT 1 -#define CSOUND_CONTROL_CHANNEL_LIN 2 -#define CSOUND_CONTROL_CHANNEL_EXP 3 - -#define CSOUND_CALLBACK_KBD_EVENT (0x00000001U) -#define CSOUND_CALLBACK_KBD_TEXT (0x00000002U) - - /** - * The following constants are used with csound->FileOpen2() and - * csound->ldmemfile2() to specify the format of a file that is being - * opened. This information is passed by Csound to a host's FileOpen - * callback and does not influence the opening operation in any other - * way. Conversion from Csound's TYP_XXX macros for audio formats to - * CSOUND_FILETYPES values can be done with csound->type2csfiletype(). - */ - typedef enum { - CSFTYPE_UNIFIED_CSD = 1, /* Unified Csound document */ - CSFTYPE_ORCHESTRA = 2, /* the primary orc file (may be temporary) */ - CSFTYPE_SCORE = 3, /* the primary sco file (may be temporary) - or any additional score opened by Cscore */ - CSFTYPE_ORC_INCLUDE = 4, /* a file #included by the orchestra */ - CSFTYPE_SCO_INCLUDE = 5, /* a file #included by the score */ - CSFTYPE_SCORE_OUT = 6, /* used for score.srt, score.xtr, cscore.out */ - CSFTYPE_SCOT = 7, /* Scot score input format */ - CSFTYPE_OPTIONS = 8, /* for .csoundrc and -@ flag */ - CSFTYPE_EXTRACT_PARMS = 9, /* extraction file specified by -x */ - - /* audio file types that Csound can write (10-19) or read */ - CSFTYPE_RAW_AUDIO = 10, - CSFTYPE_IRCAM = 11, - CSFTYPE_AIFF = 12, - CSFTYPE_AIFC = 13, - CSFTYPE_WAVE = 14, - CSFTYPE_AU = 15, - CSFTYPE_SD2 = 16, - CSFTYPE_W64 = 17, - CSFTYPE_WAVEX = 18, - CSFTYPE_FLAC = 19, - CSFTYPE_CAF = 20, - CSFTYPE_AVR = 21, - CSFTYPE_HTK = 22, - CSFTYPE_MAT4 = 23, - CSFTYPE_MAT5 = 24, - CSFTYPE_NIST = 25, - CSFTYPE_PAF = 26, - CSFTYPE_PVF = 27, - CSFTYPE_SDS = 28, - CSFTYPE_SVX = 29, - CSFTYPE_VOC = 30, - CSFTYPE_XI = 31, - CSFTYPE_UNKNOWN_AUDIO = 32, /* used when opening audio file for reading - or temp file written with */ - - /* miscellaneous music formats */ - CSFTYPE_SOUNDFONT = 33, - CSFTYPE_STD_MIDI = 34, /* Standard MIDI file */ - CSFTYPE_MIDI_SYSEX = 35, /* Raw MIDI codes, eg. SysEx dump */ - - /* analysis formats */ - CSFTYPE_HETRO = 36, - CSFTYPE_PVC = 37, /* original PVOC format */ - CSFTYPE_PVCEX = 38, /* PVOC-EX format */ - CSFTYPE_CVANAL = 39, - CSFTYPE_LPC = 40, - CSFTYPE_ATS = 41, - CSFTYPE_LORIS = 42, - CSFTYPE_SDIF = 43, - CSFTYPE_HRTF = 44, - - /* Types for plugins and the files they read/write */ - CSFTYPE_VST_PLUGIN = 45, - CSFTYPE_LADSPA_PLUGIN = 46, - CSFTYPE_SNAPSHOT = 47, - - /* Special formats for Csound ftables or scanned synthesis - matrices with header info */ - CSFTYPE_FTABLES_TEXT = 48, /* for ftsave and ftload */ - CSFTYPE_FTABLES_BINARY = 49, /* for ftsave and ftload */ - CSFTYPE_XSCANU_MATRIX = 50, /* for xscanu opcode */ - - /* These are for raw lists of numbers without header info */ - CSFTYPE_FLOATS_TEXT = 51, /* used by GEN23, GEN28, dumpk, readk */ - CSFTYPE_FLOATS_BINARY = 52, /* used by dumpk, readk, etc. */ - CSFTYPE_INTEGER_TEXT = 53, /* used by dumpk, readk, etc. */ - CSFTYPE_INTEGER_BINARY = 54, /* used by dumpk, readk, etc. */ - - /* image file formats */ - CSFTYPE_IMAGE_PNG = 59, - - /* For files that don't match any of the above */ - CSFTYPE_POSTSCRIPT = 55, /* EPS format used by graphs */ - CSFTYPE_SCRIPT_TEXT = 56, /* executable script files (eg. Python) */ - CSFTYPE_OTHER_TEXT = 57, - CSFTYPE_OTHER_BINARY = 58, - - /* This should only be used internally by the original FileOpen() - API call or for temp files written with */ - CSFTYPE_UNKNOWN = 0 - } - CSOUND_FILETYPES; - - /* - * TYPE DEFINITIONS - */ - - /* - * Forward declarations. - */ - - typedef struct CSOUND_ CSOUND; - - typedef struct windat_ WINDAT; - typedef struct xyindat_ XYINDAT; - - /** - * Real-time audio parameters structure - */ - typedef struct { - /** device name (NULL/empty: default) */ - char *devName; - /** device number (0-1023), 1024: default */ - int devNum; - /** buffer fragment size (-b) in sample frames */ - int bufSamp_SW; - /** total buffer size (-B) in sample frames */ - int bufSamp_HW; - /** number of channels */ - int nChannels; - /** sample format (AE_SHORT etc.) */ - int sampleFormat; - /** sample rate in Hz */ - float sampleRate; - } csRtAudioParams; - - typedef struct RTCLOCK_S { - int_least64_t starttime_real; - int_least64_t starttime_CPU; - } RTCLOCK; - - typedef struct { - char *opname; - char *outypes; - char *intypes; - } opcodeListEntry; - - typedef struct CsoundRandMTState_ { - int mti; - uint32_t mt[624]; - } CsoundRandMTState; - - typedef struct CsoundChannelListEntry_ { - const char *name; - int type; - } CsoundChannelListEntry; - - /* PVSDATEXT is a variation on PVSDAT used in - the pvs bus interface */ - typedef struct pvsdat_ext { - int32 N; - int sliding; /* Flag to indicate sliding case */ - int32 NB; - int32 overlap; - int32 winsize; - int wintype; - int32 format; - uint32 framecount; - float* frame; - } PVSDATEXT; - - typedef struct { - int size; - MYFLT *data; - } TABDAT; - - typedef void (*CsoundChannelIOCallback_t)(CSOUND *csound, - const char *channelName, - MYFLT *channelValuePtr, - int channelType); -#ifndef CSOUND_CSDL_H - - /* This pragma must come before all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export on -#endif - - /* - * INSTANTIATION - */ - - /** - * Initialise Csound library; should be called once before creating - * any Csound instances. - * Return value is zero on success, positive if initialisation was - * done already, and negative on error. - */ - PUBLIC int csoundInitialize(int *argc, char ***argv, int flags); - - /** - * Creates an instance of Csound. - * Returns an opaque pointer that must be passed to most Csound API functions. - * The hostData parameter can be NULL, or it can be a pointer to any sort of - * data; this pointer can be accessed from the Csound instance that is passed - * to callback routines. - */ - PUBLIC CSOUND *csoundCreate(void *hostData); - - /** - * Reset and prepare an instance of Csound for compilation. - * Returns CSOUND_SUCCESS on success, and CSOUND_ERROR or - * CSOUND_MEMORY if an error occured. - */ - PUBLIC int csoundPreCompile(CSOUND *); - - /** - * csoundInitializeCscore() prepares an instance of Csound for Cscore - * processing outside of running an orchestra (i.e. "standalone Cscore"). - * It is an alternative to csoundPreCompile(), csoundCompile(), and - * csoundPerform*() and should not be used with these functions. - * You must call this function before using the interface in "cscore.h" - * when you do not wish to compile an orchestra. - * Pass it the already open FILE* pointers to the input and - * output score files. - * It returns CSOUND_SUCCESS on success and CSOUND_INITIALIZATION or other - * error code if it fails. - */ - PUBLIC int csoundInitializeCscore(CSOUND *, FILE *insco, FILE *outsco); - - /** - * Returns a pointer to the requested interface, if available, in the - * interface argument, and its version number, in the version argument. - * Returns 0 for success. - */ - PUBLIC int csoundQueryInterface(const char *name, void **iface, int *version); - - /** - * Destroys an instance of Csound. - */ - PUBLIC void csoundDestroy(CSOUND *); - - /** - * Returns the version number times 1000 (5.00.0 = 5000). - */ - PUBLIC int csoundGetVersion(void); - - /** - * Returns the API version number times 100 (1.00 = 100). - */ - PUBLIC int csoundGetAPIVersion(void); - - /** - * Returns host data. - */ - PUBLIC void *csoundGetHostData(CSOUND *); - - /** - * Sets host data. - */ - PUBLIC void csoundSetHostData(CSOUND *, void *hostData); - - /** - * Get pointer to the value of environment variable 'name', searching - * in this order: local environment of 'csound' (if not NULL), variables - * set with csoundSetGlobalEnv(), and system environment variables. - * If 'csound' is not NULL, should be called after csoundPreCompile() - * or csoundCompile(). - * Return value is NULL if the variable is not set. - */ - PUBLIC const char *csoundGetEnv(CSOUND *csound, const char *name); - - /** - * Set the global value of environment variable 'name' to 'value', - * or delete variable if 'value' is NULL. - * It is not safe to call this function while any Csound instances - * are active. - * Returns zero on success. - */ - PUBLIC int csoundSetGlobalEnv(const char *name, const char *value); - - /* - * PERFORMANCE - */ - - /** - * Compiles Csound input files (such as an orchestra and score) - * as directed by the supplied command-line arguments, - * but does not perform them. Returns a non-zero error code on failure. - * In this (host-driven) mode, the sequence of calls should be as follows: - * /code - * csoundCompile(csound, argc, argv); - * while (!csoundPerformBuffer(csound)); - * csoundCleanup(csound); - * csoundReset(csound); - * /endcode - */ - PUBLIC int csoundCompile(CSOUND *, int argc, char **argv); - - /** - * Senses input events and performs audio output until the end of score - * is reached (positive return value), an error occurs (negative return - * value), or performance is stopped by calling csoundStop() from another - * thread (zero return value). - * Note that csoundCompile must be called first. - * In the case of zero return value, csoundPerform() can be called again - * to continue the stopped performance. Otherwise, csoundReset() should be - * called to clean up after the finished or failed performance. - */ - PUBLIC int csoundPerform(CSOUND *); - - /** - * Senses input events, and performs one control sample worth (ksmps) of - * audio output. - * Note that csoundCompile must be called first. - * Returns false during performance, and true when performance is finished. - * If called until it returns true, will perform an entire score. - * Enables external software to control the execution of Csound, - * and to synchronize performance with audio input and output. - */ - PUBLIC int csoundPerformKsmps(CSOUND *); - - /** - * Senses input events, and performs one control sample worth (ksmps) of - * audio output. - * Note that csoundCompile must be called first. - * Performs audio whether or not the Csound score has finished. - * Enables external software to control the execution of Csound, - * and to synchronize performance with audio input and output. - */ - PUBLIC int csoundPerformKsmpsAbsolute(CSOUND *); - - /** - * Performs Csound, sensing real-time and score events - * and processing one buffer's worth (-b frames) of interleaved audio. - * Returns a pointer to the new output audio in 'outputAudio' - * Note that csoundCompile must be called first, then call - * csoundGetOutputBuffer() and csoundGetInputBuffer() to get the pointer - * to csound's I/O buffers. - * Returns false during performance, and true when performance is finished. - */ - PUBLIC int csoundPerformBuffer(CSOUND *); - - /** - * Stops a csoundPerform() running in another thread. Note that it is - * not guaranteed that csoundPerform() has already stopped when this - * function returns. - */ - PUBLIC void csoundStop(CSOUND *); - - /** - * Finds th elist of named gens - */ - PUBLIC void *csoundGetNamedGens(CSOUND *); - - /** - * Prints information about the end of a performance, and closes audio - * and MIDI devices. - * Note: after calling csoundCleanup(), the operation of the perform - * functions is undefined. - */ - PUBLIC int csoundCleanup(CSOUND *); - - /** - * Resets all internal memory and state in preparation for a new performance. - * Enables external software to run successive Csound performances - * without reloading Csound. Implies csoundCleanup(), unless already called. - */ - PUBLIC void csoundReset(CSOUND *); - - /* - * ATTRIBUTES - */ - - /** - * Returns the number of audio sample frames per second. - */ - PUBLIC MYFLT csoundGetSr(CSOUND *); - - /** - * Returns the number of control samples per second. - */ - PUBLIC MYFLT csoundGetKr(CSOUND *); - - /** - * Returns the number of audio sample frames per control sample. - */ - PUBLIC int csoundGetKsmps(CSOUND *); - - /** - * Returns the number of audio output channels. - */ - PUBLIC int csoundGetNchnls(CSOUND *); - - /** - * Returns the 0dBFS level of the spin/spout buffers. - */ - PUBLIC MYFLT csoundGet0dBFS(CSOUND *); - - /** - * Returns the number of bytes allocated for a string variable - * (the actual length is one less because of the null character - * at the end of the string). Should be called after csoundCompile(). - */ - PUBLIC int csoundGetStrVarMaxLen(CSOUND *); - - /** - * Returns the sample format. - */ - PUBLIC int csoundGetSampleFormat(CSOUND *); - - /** - * Returns the size in bytes of a single sample. - */ - PUBLIC int csoundGetSampleSize(CSOUND *); - - /** - * Returns the number of samples in Csound's input buffer. - */ - PUBLIC long csoundGetInputBufferSize(CSOUND *); - - /** - * Returns the number of samples in Csound's output buffer. - */ - PUBLIC long csoundGetOutputBufferSize(CSOUND *); - - /** - * Returns the address of the Csound audio input buffer. - * Enables external software to write audio into Csound before calling - * csoundPerformBuffer. - */ - PUBLIC MYFLT *csoundGetInputBuffer(CSOUND *); - - /** - * Returns the address of the Csound audio output buffer. - * Enables external software to read audio from Csound after calling - * csoundPerformBuffer. - */ - PUBLIC MYFLT *csoundGetOutputBuffer(CSOUND *); - - /** - * Returns the address of the Csound audio input working buffer (spin). - * Enables external software to write audio into Csound before calling - * csoundPerformKsmps. - */ - PUBLIC MYFLT *csoundGetSpin(CSOUND *); - - /** - * Adds the indicated sample into the audio input woriing buffer (spin); - * this only ever makes sense before calling csoundPerformKsmps(). - * The frame and channel must be in bounds relative to ksmps and nchnls. - */ - PUBLIC void csoundAddSpinSample(CSOUND *csound, int frame, int channel, MYFLT sample); - - /** - * Returns the address of the Csound audio output working buffer (spout). - * Enables external software to read audio from Csound after calling - * csoundPerformKsmps. - */ - PUBLIC MYFLT *csoundGetSpout(CSOUND *csound); - - /** - * Returns the indicated sample from the Csound audio output working buffer (spout); - * only ever makes sense after calling csoundPerformKsmps(). - * The frame and channel must be in bounds relative to ksmps and nchnls. - */ - PUBLIC MYFLT csoundGetSpoutSample(CSOUND *csound, int frame, int channel); - - /** - * Returns the output sound file name (-o). - */ - PUBLIC const char *csoundGetOutputFileName(CSOUND *); - - /** - * Calling this function with a non-zero 'state' value between - * csoundPreCompile() and csoundCompile() will disable all default - * handling of sound I/O by the Csound library, allowing the host - * application to use the spin/spout/input/output buffers directly. - * If 'bufSize' is greater than zero, the buffer size (-b) will be - * set to the integer multiple of ksmps that is nearest to the value - * specified. - */ - PUBLIC void csoundSetHostImplementedAudioIO(CSOUND *, int state, int bufSize); - - /** - * Returns the current score time in seconds - * since the beginning of performance. - */ - PUBLIC double csoundGetScoreTime(CSOUND *); - - /* - * SCORE HANDLING - */ - - /** - * Sets whether Csound score events are performed or not, independently - * of real-time MIDI events (see csoundSetScorePending()). - */ - PUBLIC int csoundIsScorePending(CSOUND *); - - /** - * Sets whether Csound score events are performed or not (real-time - * events will continue to be performed). Can be used by external software, - * such as a VST host, to turn off performance of score events (while - * continuing to perform real-time events), for example to - * mute a Csound score while working on other tracks of a piece, or - * to play the Csound instruments live. - */ - PUBLIC void csoundSetScorePending(CSOUND *, int pending); - - /** - * Returns the score time beginning at which score events will - * actually immediately be performed (see csoundSetScoreOffsetSeconds()). - */ - PUBLIC MYFLT csoundGetScoreOffsetSeconds(CSOUND *); - - /** - * Csound score events prior to the specified time are not performed, and - * performance begins immediately at the specified time (real-time events - * will continue to be performed as they are received). - * Can be used by external software, such as a VST host, - * to begin score performance midway through a Csound score, - * for example to repeat a loop in a sequencer, or to synchronize - * other events with the Csound score. - */ - PUBLIC void csoundSetScoreOffsetSeconds(CSOUND *, MYFLT time); - - /** - * Rewinds a compiled Csound score to the time specified with - * csoundSetScoreOffsetSeconds(). - */ - PUBLIC void csoundRewindScore(CSOUND *); - - /** - * Sets an external callback for Cscore processing. - * Pass NULL to reset to the internal cscore() function (which does nothing). - * This callback is retained after a csoundReset() call. - */ - PUBLIC void csoundSetCscoreCallback(CSOUND *, - void (*cscoreCallback_)(CSOUND *)); - - /** - * Sorts score file 'inFile' and writes the result to 'outFile'. - * The Csound instance should be initialised with csoundPreCompile() - * before calling this function, and csoundReset() should be called - * after sorting the score to clean up. On success, zero is returned. - */ - PUBLIC int csoundScoreSort(CSOUND *, FILE *inFile, FILE *outFile); - - /** - * Extracts from 'inFile', controlled by 'extractFile', and writes - * the result to 'outFile'. The Csound instance should be initialised - * with csoundPreCompile() before calling this function, and csoundReset() - * should be called after score extraction to clean up. - * The return value is zero on success. - */ - PUBLIC int csoundScoreExtract(CSOUND *, - FILE *inFile, FILE *outFile, FILE *extractFile); - - /* - * MESSAGES & TEXT - */ - - /** - * Displays an informational message. - */ - PUBLIC CS_PRINTF2 void csoundMessage(CSOUND *, const char *format, ...); - - /** - * Print message with special attributes (see msg_attr.h for the list of - * available attributes). With attr=0, csoundMessageS() is identical to - * csoundMessage(). - */ - PUBLIC CS_PRINTF3 void csoundMessageS(CSOUND *, - int attr, const char *format, ...); - - PUBLIC void csoundMessageV(CSOUND *, - int attr, const char *format, va_list args); - - /** - * Sets a function to be called by Csound to print an informational message. - */ - PUBLIC void csoundSetMessageCallback(CSOUND *, - void (*csoundMessageCallback_)(CSOUND *, - int attr, - const char *format, - va_list valist)); - - /** - * Returns the Csound message level (from 0 to 231). - */ - PUBLIC int csoundGetMessageLevel(CSOUND *); - - /** - * Sets the Csound message level (from 0 to 231). - */ - PUBLIC void csoundSetMessageLevel(CSOUND *, int messageLevel); - - /** - * Input a NULL-terminated string (as if from a console), - * used for line events. - */ - PUBLIC void csoundInputMessage(CSOUND *, const char *message); - - /** - * Set the ASCII code of the most recent key pressed. - * This value is used by the 'sensekey' opcode if a callback - * for returning keyboard events is not set (see csoundSetCallback()). - */ - PUBLIC void csoundKeyPress(CSOUND *, char c); - - /* - * CONTROL AND EVENTS - */ - - /** - * Control values are specified by a 'channelName' string. - * Note that the 'invalue' & 'outvalue' channels can be specified by - * either a string or a number. If a number is specified, it will be - * converted to a string before making the callbacks to the external - * software. - */ - - /** - * Called by external software to set a function for Csound to - * fetch input control values. The 'invalue' opcodes will - * directly call this function. If 'channelName' starts with a - * '$', then 'invalue' opcode is expecting a C string, to be copied - * to 'value', with maximum size csoundGetStrVarMaxLen(). - */ - PUBLIC void csoundSetInputValueCallback(CSOUND *, - void (*inputValueCalback_)(CSOUND *, - const char *channelName, - MYFLT *value)); - - /** - * Called by external software to set a function for Csound to - * send output control values. The 'outvalue' opcodes will - * directly call this function. If 'channelName' starts with a - * '$', then the 'outvalue' opcode is sending a string appended - * to channelName in the format: "$channelName$stringOutput". - * and 'value' will be the index number into 'channelName' where - * the stringOutput begins. - */ - PUBLIC void csoundSetOutputValueCallback(CSOUND *, - void (*outputValueCalback_)(CSOUND *, - const char *channelName, - MYFLT value)); - - /** - * Send a new score event. 'type' is the score event type ('a', 'i', 'q', - * 'f', or 'e'). - * 'numFields' is the size of the pFields array. 'pFields' is an array of - * floats with all the pfields for this event, starting with the p1 value - * specified in pFields[0]. - */ - PUBLIC int csoundScoreEvent(CSOUND *, - char type, const MYFLT *pFields, long numFields); - - PUBLIC int csoundScoreEventAbsolute(CSOUND *, - char type, const MYFLT *pfields, long numFields, double time_ofs); - - /* - * MIDI - */ - - /** - * Sets callback for opening real time MIDI input. - */ - PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *, - int (*func)(CSOUND *, void **userData, const char *devName)); - - /** - * Sets callback for reading from real time MIDI input. - */ - PUBLIC void csoundSetExternalMidiReadCallback(CSOUND *, - int (*func)(CSOUND *, void *userData, - unsigned char *buf, int nBytes)); - - /** - * Sets callback for closing real time MIDI input. - */ - PUBLIC void csoundSetExternalMidiInCloseCallback(CSOUND *, - int (*func)(CSOUND *, void *userData)); - - /** - * Sets callback for opening real time MIDI output. - */ - PUBLIC void csoundSetExternalMidiOutOpenCallback(CSOUND *, - int (*func)(CSOUND *, void **userData, const char *devName)); - - /** - * Sets callback for writing to real time MIDI output. - */ - PUBLIC void csoundSetExternalMidiWriteCallback(CSOUND *, - int (*func)(CSOUND *, void *userData, - const unsigned char *buf, int nBytes)); - - /** - * Sets callback for closing real time MIDI output. - */ - PUBLIC void csoundSetExternalMidiOutCloseCallback(CSOUND *, - int (*func)(CSOUND *, void *userData)); - - /** - * Sets callback for converting MIDI error codes to strings. - */ - PUBLIC void csoundSetExternalMidiErrorStringCallback(CSOUND *, - const char *(*func)(int)); - - /* - * FUNCTION TABLE DISPLAY - */ - - /** - * Tells Csound whether external graphic table display is supported. - * Returns the previously set value (initially zero). - */ - PUBLIC int csoundSetIsGraphable(CSOUND *, int isGraphable); - - /** - * Called by external software to set Csound's MakeGraph function. - */ - PUBLIC void csoundSetMakeGraphCallback(CSOUND *, - void (*makeGraphCallback_)(CSOUND *, - WINDAT *windat, - const char *name)); - - /** - * Called by external software to set Csound's DrawGraph function. - */ - PUBLIC void csoundSetDrawGraphCallback(CSOUND *, - void (*drawGraphCallback_)(CSOUND *, - WINDAT *windat)); - - /** - * Called by external software to set Csound's KillGraph function. - */ - PUBLIC void csoundSetKillGraphCallback(CSOUND *, - void (*killGraphCallback_)(CSOUND *, - WINDAT *windat)); - - /** - * Called by external software to set Csound's MakeXYin function. - */ - PUBLIC void csoundSetMakeXYinCallback(CSOUND *, - void (*makeXYinCallback_)(CSOUND *, XYINDAT *, - MYFLT x, MYFLT y)); - - /** - * Called by external software to set Csound's ReadXYin function. - */ - PUBLIC void csoundSetReadXYinCallback(CSOUND *, - void (*readXYinCallback_)(CSOUND *, XYINDAT *)); - - /** - * Called by external software to set Csound's KillXYin function. - */ - PUBLIC void csoundSetKillXYinCallback(CSOUND *, - void (*killXYinCallback_)(CSOUND *, XYINDAT *)); - - /** - * Called by external software to set Csound's ExitGraph function. - */ - PUBLIC void csoundSetExitGraphCallback(CSOUND *, - int (*exitGraphCallback_)(CSOUND *)); - - /* - * OPCODES - */ - - /** - * Gets an alphabetically sorted list of all opcodes. - * Should be called after externals are loaded by csoundCompile(). - * Returns the number of opcodes, or a negative error code on failure. - * Make sure to call csoundDisposeOpcodeList() when done with the list. - */ - PUBLIC int csoundNewOpcodeList(CSOUND *, opcodeListEntry **opcodelist); - - /** - * Releases an opcode list. - */ - PUBLIC void csoundDisposeOpcodeList(CSOUND *, opcodeListEntry *opcodelist); - - /** - * Appends an opcode implemented by external software - * to Csound's internal opcode list. - * The opcode list is extended by one slot, - * and the parameters are copied into the new slot. - * Returns zero on success. - */ - PUBLIC int csoundAppendOpcode(CSOUND *, const char *opname, - int dsblksiz, int thread, - const char *outypes, const char *intypes, - int (*iopadr)(CSOUND *, void *), - int (*kopadr)(CSOUND *, void *), - int (*aopadr)(CSOUND *, void *)); - - /* - * MISCELLANEOUS FUNCTIONS - */ - - /** - * Platform-independent function to load a shared library. - */ - PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath); - - /** - * Platform-independent function to unload a shared library. - */ - PUBLIC int csoundCloseLibrary(void *library); - - /** - * Platform-independent function to get a symbol address in a shared library. - */ - PUBLIC void *csoundGetLibrarySymbol(void *library, const char *symbolName); - - /** - * Called by external software to set a function for checking system - * events, yielding cpu time for coopertative multitasking, etc. - * This function is optional. It is often used as a way to 'turn off' - * Csound, allowing it to exit gracefully. In addition, some operations - * like utility analysis routines are not reentrant and you should use - * this function to do any kind of updating during the operation. - * Returns an 'OK to continue' boolean. - */ - PUBLIC void csoundSetYieldCallback(CSOUND *, int (*yieldCallback_)(CSOUND *)); - - /* - * REAL-TIME AUDIO PLAY AND RECORD - */ - - /** - * Sets a function to be called by Csound for opening real-time - * audio playback. - */ - PUBLIC void csoundSetPlayopenCallback(CSOUND *, - int (*playopen__)(CSOUND *, - const csRtAudioParams *parm)); - - /** - * Sets a function to be called by Csound for performing real-time - * audio playback. - */ - PUBLIC void csoundSetRtplayCallback(CSOUND *, - void (*rtplay__)(CSOUND *, - const MYFLT *outBuf, int nbytes)); - - /** - * Sets a function to be called by Csound for opening real-time - * audio recording. - */ - PUBLIC void csoundSetRecopenCallback(CSOUND *, - int (*recopen_)(CSOUND *, - const csRtAudioParams *parm)); - - /** - * Sets a function to be called by Csound for performing real-time - * audio recording. - */ - PUBLIC void csoundSetRtrecordCallback(CSOUND *, - int (*rtrecord__)(CSOUND *, - MYFLT *inBuf, int nbytes)); - - /** - * Sets a function to be called by Csound for closing real-time - * audio playback and recording. - */ - PUBLIC void csoundSetRtcloseCallback(CSOUND *, void (*rtclose__)(CSOUND *)); - - /** - * Returns whether Csound is in debug mode. - */ - PUBLIC int csoundGetDebug(CSOUND *); - - /** - * Sets whether Csound is in debug mode. - */ - PUBLIC void csoundSetDebug(CSOUND *, int debug); - - /** - * Returns the length of a function table (not including the guard point), - * or -1 if the table does not exist. - */ - PUBLIC int csoundTableLength(CSOUND *, int table); - - /** - * Returns the value of a slot in a function table. - * The table number and index are assumed to be valid. - */ - PUBLIC MYFLT csoundTableGet(CSOUND *, int table, int index); - - /** - * Sets the value of a slot in a function table. - * The table number and index are assumed to be valid. - */ - PUBLIC void csoundTableSet(CSOUND *, int table, int index, MYFLT value); - - /** - * Stores pointer to function table 'tableNum' in *tablePtr, - * and returns the table length (not including the guard point). - * If the table does not exist, *tablePtr is set to NULL and - * -1 is returned. - */ - PUBLIC int csoundGetTable(CSOUND *, MYFLT **tablePtr, int tableNum); - - /** - * Creates and starts a new thread of execution. - * Returns an opaque pointer that represents the thread on success, - * or NULL for failure. - * The userdata pointer is passed to the thread routine. - */ - PUBLIC void *csoundCreateThread(uintptr_t (*threadRoutine)(void *), - void *userdata); - - /** - * Returns the ID of the currently executing thread, - * or NULL for failure. - * - * NOTE: The return value can be used as a pointer - * to a thread object, but it should not be compared - * as a pointer. The pointed to values should be compared, - * and the user must free the pointer after use. - */ - PUBLIC void *csoundGetCurrentThreadId(void); - - /** - * Waits until the indicated thread's routine has finished. - * Returns the value returned by the thread routine. - */ - PUBLIC uintptr_t csoundJoinThread(void *thread); - - /** - * Runs an external command with the arguments specified in 'argv'. - * argv[0] is the name of the program to execute (if not a full path - * file name, it is searched in the directories defined by the PATH - * environment variable). The list of arguments should be terminated - * by a NULL pointer. - * If 'noWait' is zero, the function waits until the external program - * finishes, otherwise it returns immediately. In the first case, a - * non-negative return value is the exit status of the command (0 to - * 255), otherwise it is the PID of the newly created process. - * On error, a negative value is returned. - */ - PUBLIC long csoundRunCommand(const char * const *argv, int noWait); - - /** - * Creates and returns a monitor object, or NULL if not successful. - * The object is initially in signaled (notified) state. - */ - PUBLIC void *csoundCreateThreadLock(void); - - /** - * Waits on the indicated monitor object for the indicated period. - * The function returns either when the monitor object is notified, - * or when the period has elapsed, whichever is sooner; in the first case, - * zero is returned. - * If 'milliseconds' is zero and the object is not notified, the function - * will return immediately with a non-zero status. - */ - PUBLIC int csoundWaitThreadLock(void *lock, size_t milliseconds); - - /** - * Waits on the indicated monitor object until it is notified. - * This function is similar to csoundWaitThreadLock() with an infinite - * wait time, but may be more efficient. - */ - PUBLIC void csoundWaitThreadLockNoTimeout(void *lock); - - /** - * Notifies the indicated monitor object. - */ - PUBLIC void csoundNotifyThreadLock(void *lock); - - /** - * Destroys the indicated monitor object. - */ - PUBLIC void csoundDestroyThreadLock(void *lock); - - /** - * Creates and returns a mutex object, or NULL if not successful. - * Mutexes can be faster than the more general purpose monitor objects - * returned by csoundCreateThreadLock() on some platforms, and can also - * be recursive, but the result of unlocking a mutex that is owned by - * another thread or is not locked is undefined. - * If 'isRecursive' is non-zero, the mutex can be re-locked multiple - * times by the same thread, requiring an equal number of unlock calls; - * otherwise, attempting to re-lock the mutex results in undefined - * behavior. - * Note: the handles returned by csoundCreateThreadLock() and - * csoundCreateMutex() are not compatible. - */ - PUBLIC void *csoundCreateMutex(int isRecursive); - - /** - * Acquires the indicated mutex object; if it is already in use by - * another thread, the function waits until the mutex is released by - * the other thread. - */ - PUBLIC void csoundLockMutex(void *mutex_); - - /** - * Acquires the indicated mutex object and returns zero, unless it is - * already in use by another thread, in which case a non-zero value is - * returned immediately, rather than waiting until the mutex becomes - * available. - * Note: this function may be unimplemented on Windows. - */ - PUBLIC int csoundLockMutexNoWait(void *mutex_); - - /** - * Releases the indicated mutex object, which should be owned by - * the current thread, otherwise the operation of this function is - * undefined. A recursive mutex needs to be unlocked as many times - * as it was locked previously. - */ - PUBLIC void csoundUnlockMutex(void *mutex_); - - /** - * Destroys the indicated mutex object. Destroying a mutex that - * is currently owned by a thread results in undefined behavior. - */ - PUBLIC void csoundDestroyMutex(void *mutex_); - - - /** - * Create a Thread Barrier. Max value parameter should be equal to - * number of child threads using the barrier plus one for the - * master thread */ - - PUBLIC void *csoundCreateBarrier(unsigned int max); - - /** - * Destroy a Thread Barrier. - */ - PUBLIC int csoundDestroyBarrier(void *barrier); - - /** - * Wait on the thread barrier. - */ - PUBLIC int csoundWaitBarrier(void *barrier); - - /** - * Waits for at least the specified number of milliseconds, - * yielding the CPU to other threads. - */ - PUBLIC void csoundSleep(size_t milliseconds); - - /** - * If the spinlock is not locked, lock it and return; - * if is is locked, wait until it is unlocked, then lock it and return. - * Uses atomic compare and swap operations that are safe across processors - * and safe for out of order operations, - * and which are more efficient than operating system locks. - * Use spinlocks to protect access to shared data, especially in functions - * that do little more than read or write such data, for example: - * - * void write(size_t frames, int* signal) - * { - * static int lock = 0; - * csoundSpinLock(&lock); - * for (size_t frame = 0; i < frames; frame++) { - * global_buffer[frame] += signal[frame]; - * } - * csoundSpinUnlock(&lock); - * } - */ - - /* PUBLIC void csoundSpinLock(int32_t *spinlock) */ - /* PUBLIC void csoundSpinUnlock(int32_t *spinlock) */ - - /* PUBLIC void csoundSpinLock(int32_t *spinlock) */ - /* PUBLIC void csoundSpinUnlock(int32_t *spinlock) */ - -#if defined(MSVC) - -# pragma intrinsic(_InterlockedExchange) -# define csoundSpinLock(spinlock) \ - { \ - while (_InterlockedExchange(spinlock, 1) == 1) { \ - } \ - } -# define csoundSpinUnLock(spinlock) \ - { \ - _InterlockedExchange(spinlock, 0); \ - } -# define CSOUND_SPIN_LOCK static int32_t spinlock = 0; csoundSpinLock(&spinlock); -# define CSOUND_SPIN_UNLOCK csoundSpinUnLock(&spinlock); - -#elif defined(__GNUC__) && defined(HAVE_PTHREAD_SPIN_LOCK) -# if defined(SWIG) -# define csoundSpinLock(spinlock) \ - { \ - pthread_spin_lock((pthread_spinlock_t *)spinlock); \ - } -# define csoundSpinUnLock(spinlock) \ - { \ - pthread_spin_unlock((pthread_spinlock_t *)spinlock); \ - } -# define CSOUND_SPIN_LOCK static int32_t spinlock = 0; csoundSpinLock(&spinlock); -# define CSOUND_SPIN_UNLOCK csoundSpinUnLock(&spinlock); -# else -# define csoundSpinLock(spinlock) -# define csoundSpinUnLock(spinlock) -# define CSOUND_SPIN_LOCK -# define CSOUND_SPIN_UNLOCK -#endif - -#elif defined(__GNUC__) && defined(HAVE_SYNC_LOCK_TEST_AND_SET) - -# define csoundSpinLock(spinlock) \ - { \ - while (__sync_lock_test_and_set(spinlock, 1) == 1) { \ - } \ - } -# define csoundSpinUnLock(spinlock) \ - { \ - __sync_lock_release(spinlock); \ - } -# define CSOUND_SPIN_LOCK static int32_t spinlock = 0; csoundSpinLock(&spinlock); -# define CSOUND_SPIN_UNLOCK csoundSpinUnLock(&spinlock); - -#elif defined(MACOSX) - -#ifndef SWIG - -#include -#define csoundSpinLock(spinlock) \ - { \ - OSSpinLockLock(spinlock); \ - } -#define csoundSpinUnLock(spinlock) \ - { \ - OSSpinLockUnlock(spinlock); \ - } -#define CSOUND_SPIN_LOCK static int32_t spinlock = 0; csoundSpinLock(&spinlock); - -#define CSOUND_SPIN_UNLOCK csoundSpinUnLock(&spinlock); -#endif -#else - - /* We don't know the configuration, */ - /* so we define these symbols as nothing. */ -# define csoundSpinLock(spinlock) -# define csoundSpinUnLock(spinlock) -# define CSOUND_SPIN_LOCK -# define CSOUND_SPIN_UNLOCK - -#endif - - /** - * Initialise a timer structure. - */ - PUBLIC void csoundInitTimerStruct(RTCLOCK *); - - /** - * Return the elapsed real time (in seconds) since the specified timer - * structure was initialised. - */ - PUBLIC double csoundGetRealTime(RTCLOCK *); - - /** - * Return the elapsed CPU time (in seconds) since the specified timer - * structure was initialised. - */ - PUBLIC double csoundGetCPUTime(RTCLOCK *); - - /** - * Return a 32-bit unsigned integer to be used as seed from current time. - */ - PUBLIC uint32_t csoundGetRandomSeedFromTime(void); - - /** - * Set language to 'lang_code' (lang_code can be for example - * CSLANGUAGE_ENGLISH_UK or CSLANGUAGE_FRENCH or many others, - * see n_getstr.h for the list of languages). This affects all - * Csound instances running in the address space of the current - * process. The special language code CSLANGUAGE_DEFAULT can be - * used to disable translation of messages and free all memory - * allocated by a previous call to csoundSetLanguage(). - * csoundSetLanguage() loads all files for the selected language - * from the directory specified by the CSSTRNGS environment - * variable. - */ - PUBLIC void csoundSetLanguage(cslanguage_t lang_code); - - /** - * Translate string 's' to the current language, and return - * pointer to the translated message. This may be the same as - * 's' if language was set to CSLANGUAGE_DEFAULT. - */ - PUBLIC char *csoundLocalizeString(const char *s); - - /** - * Allocate nbytes bytes of memory that can be accessed later by calling - * csoundQueryGlobalVariable() with the specified name; the space is - * cleared to zero. - * Returns CSOUND_SUCCESS on success, CSOUND_ERROR in case of invalid - * parameters (zero nbytes, invalid or already used name), or - * CSOUND_MEMORY if there is not enough memory. - */ - PUBLIC int csoundCreateGlobalVariable(CSOUND *, - const char *name, size_t nbytes); - - /** - * Get pointer to space allocated with the name "name". - * Returns NULL if the specified name is not defined. - */ - PUBLIC void *csoundQueryGlobalVariable(CSOUND *, const char *name); - - /** - * This function is the same as csoundQueryGlobalVariable(), except the - * variable is assumed to exist and no error checking is done. - * Faster, but may crash or return an invalid pointer if 'name' is - * not defined. - */ - PUBLIC void *csoundQueryGlobalVariableNoCheck(CSOUND *, const char *name); - - /** - * Free memory allocated for "name" and remove "name" from the database. - * Return value is CSOUND_SUCCESS on success, or CSOUND_ERROR if the name is - * not defined. - */ - PUBLIC int csoundDestroyGlobalVariable(CSOUND *, const char *name); - - /** - * Return the size of MYFLT in bytes. - */ - PUBLIC int csoundGetSizeOfMYFLT(void); - - /** - * Return pointer to user data pointer for real time audio input. - */ - PUBLIC void **csoundGetRtRecordUserData(CSOUND *); - - /** - * Return pointer to user data pointer for real time audio output. - */ - PUBLIC void **csoundGetRtPlayUserData(CSOUND *); - - /** - * Register a function to be called once in every control period - * by sensevents(). Any number of functions may be registered, - * and will be called in the order of registration. - * The callback function takes two arguments: the Csound instance - * pointer, and the userData pointer as passed to this function. - * Returns zero on success. - */ - PUBLIC int csoundRegisterSenseEventCallback(CSOUND *, - void (*func)(CSOUND *, void *), - void *userData); - - /** - * Run utility with the specified name and command line arguments. - * Should be called after loading utility plugins with csoundPreCompile(); - * use csoundReset() to clean up after calling this function. - * Returns zero if the utility was run successfully. - */ - PUBLIC int csoundRunUtility(CSOUND *, const char *name, - int argc, char **argv); - - /** - * Returns a NULL terminated list of registered utility names. - * The caller is responsible for freeing the returned array with - * csoundDeleteUtilityList(), however, the names should not be - * changed or freed. - * The return value may be NULL in case of an error. - */ - PUBLIC char **csoundListUtilities(CSOUND *); - - /** - * Releases an utility list previously returned by csoundListUtilities(). - */ - PUBLIC void csoundDeleteUtilityList(CSOUND *, char **lst); - - /** - * Get utility description. - * Returns NULL if the utility was not found, or it has no description, - * or an error occured. - */ - PUBLIC const char *csoundGetUtilityDescription(CSOUND *, - const char *utilName); - - /** - * Stores a pointer to the specified channel of the bus in *p, - * creating the channel first if it does not exist yet. - * 'type' must be the bitwise OR of exactly one of the following values, - * CSOUND_CONTROL_CHANNEL - * control data (one MYFLT value) - * CSOUND_AUDIO_CHANNEL - * audio data (csoundGetKsmps(csound) MYFLT values) - * CSOUND_STRING_CHANNEL - * string data (MYFLT values with enough space to store - * csoundGetStrVarMaxLen(csound) characters, including the - * NULL character at the end of the string) - * and at least one of these: - * CSOUND_INPUT_CHANNEL - * CSOUND_OUTPUT_CHANNEL - * If the channel already exists, it must match the data type (control, - * audio, or string), however, the input/output bits are OR'd with the - * new value. Note that audio and string channels can only be created - * after calling csoundCompile(), because the storage size is not known - * until then. - * Return value is zero on success, or a negative error code, - * CSOUND_MEMORY there is not enough memory for allocating the channel - * CSOUND_ERROR the specified name or type is invalid - * or, if a channel with the same name but incompatible type already exists, - * the type of the existing channel. In the case of any non-zero return - * value, *p is set to NULL. - * Note: to find out the type of a channel without actually creating or - * changing it, set 'type' to zero, so that the return value will be either - * the type of the channel, or CSOUND_ERROR if it does not exist. - */ - PUBLIC int csoundGetChannelPtr(CSOUND *, - MYFLT **p, const char *name, int type); - - /** - * Returns a list of allocated channels in *lst. A CsoundChannelListEntry - * structure contains the name and type of a channel, with the type having - * the same format as in the case of csoundGetChannelPtr(). - * The return value is the number of channels, which may be zero if there - * are none, or CSOUND_MEMORY if there is not enough memory for allocating - * the list. In the case of no channels or an error, *lst is set to NULL. - * Notes: the caller is responsible for freeing the list returned in *lst - * with csoundDeleteChannelList(). The name pointers may become invalid - * after calling csoundReset(). - */ - PUBLIC int csoundListChannels(CSOUND *, CsoundChannelListEntry **lst); - - /** - * Releases a channel list previously returned by csoundListChannels(). - */ - PUBLIC void csoundDeleteChannelList(CSOUND *, CsoundChannelListEntry *lst); - - /** - * Sets special parameters for a control channel. The parameters are: - * type: must be one of CSOUND_CONTROL_CHANNEL_INT, - * CSOUND_CONTROL_CHANNEL_LIN, or CSOUND_CONTROL_CHANNEL_EXP for - * integer, linear, or exponential channel data, respectively, - * or zero to delete any previously assigned parameter information - * dflt: the control value that is assumed to be the default, should be - * greater than or equal to 'min', and less than or equal to 'max' - * min: the minimum value expected; if the control type is exponential, - * it must be non-zero - * max: the maximum value expected, should be greater than 'min'; - * if the control type is exponential, it must be non-zero and - * match the sign of 'min' - * Returns zero on success, or a non-zero error code on failure: - * CSOUND_ERROR: the channel does not exist, is not a control channel, - * or the specified parameters are invalid - * CSOUND_MEMORY: could not allocate memory - */ - PUBLIC int csoundSetControlChannelParams(CSOUND *, const char *name, - int type, MYFLT dflt, - MYFLT min, MYFLT max); - - /** - * Returns special parameters (assuming there are any) of a control channel, - * previously set with csoundSetControlChannelParams(). - * If the channel exists, is a control channel, and has the special parameters - * assigned, then the default, minimum, and maximum value is stored in *dflt, - * *min, and *max, respectively, and a positive value that is one of - * CSOUND_CONTROL_CHANNEL_INT, CSOUND_CONTROL_CHANNEL_LIN, and - * CSOUND_CONTROL_CHANNEL_EXP is returned. - * In any other case, *dflt, *min, and *max are not changed, and the return - * value is zero if the channel exists, is a control channel, but has no - * special parameters set; otherwise, a negative error code is returned. - */ - PUBLIC int csoundGetControlChannelParams(CSOUND *, const char *name, - MYFLT *dflt, MYFLT *min, MYFLT *max); - - /** - * Sets callback function to be called by the opcodes 'chnsend' and - * 'chnrecv'. Should be called between csoundPreCompile() and - * csoundCompile(). - * The callback function takes the following arguments: - * CSOUND *csound - * Csound instance pointer - * const char *channelName - * the channel name - * MYFLT *channelValuePtr - * pointer to the channel value. Control channels are a single MYFLT - * value, while audio channels are an array of csoundGetKsmps(csound) - * MYFLT values. In the case of string channels, the pointer should be - * cast to char *, and points to a buffer of - * csoundGetStrVarMaxLen(csound) bytes - * int channelType - * bitwise OR of the channel type (CSOUND_CONTROL_CHANNEL, - * CSOUND_AUDIO_CHANNEL, or CSOUND_STRING_CHANNEL; use - * channelType & CSOUND_CHANNEL_TYPE_MASK to extract the channel - * type), and either CSOUND_INPUT_CHANNEL or CSOUND_OUTPUT_CHANNEL - * to indicate the direction of the data transfer - * The callback is not preserved on csoundReset(). - */ - PUBLIC void csoundSetChannelIOCallback(CSOUND *, - CsoundChannelIOCallback_t func); - - /** - * Recovers a pointer to a lock for the specified channel of the bus in *p - * which must exist. - * 'type' must be the bitwise OR of exactly one of the following values, - * CSOUND_CONTROL_CHANNEL - * control data (one MYFLT value) - * CSOUND_AUDIO_CHANNEL - * audio data (csoundGetKsmps(csound) MYFLT values) - * CSOUND_STRING_CHANNEL - * string data (MYFLT values with enough space to store - * csoundGetStrVarMaxLen(csound) characters, including the - * NULL character at the end of the string) - * and at least one of these: - * CSOUND_INPUT_CHANNEL - * CSOUND_OUTPUT_CHANNEL - * Return value is the address of the lock - */ - PUBLIC int *csoundGetChannelLock(CSOUND *, - const char *name, int type); - - /** - * Simple linear congruential random number generator: - * (*seedVal) = (*seedVal) * 742938285 % 2147483647 - * the initial value of *seedVal must be in the range 1 to 2147483646. - * Returns the next number from the pseudo-random sequence, - * in the range 1 to 2147483646. - */ - PUBLIC int csoundRand31(int *seedVal); - - /** - * Initialise Mersenne Twister (MT19937) random number generator, - * using 'keyLength' unsigned 32 bit values from 'initKey' as seed. - * If the array is NULL, the length parameter is used for seeding. - */ - PUBLIC void csoundSeedRandMT(CsoundRandMTState *p, - const uint32_t *initKey, uint32_t keyLength); - - /** - * Returns next random number from MT19937 generator. - * The PRNG must be initialised first by calling csoundSeedRandMT(). - */ - PUBLIC uint32_t csoundRandMT(CsoundRandMTState *p); - - /** - * Sends a MYFLT value to the chani opcode (k-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, and - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundChanIKSet(CSOUND *, MYFLT value, int n); - - /** - * Receives a MYFLT value from the chano opcode (k-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, and - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundChanOKGet(CSOUND *, MYFLT *value, int n); - - /** - * Sends ksmps MYFLT values to the chani opcode (a-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, and - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundChanIASet(CSOUND *, const MYFLT *value, int n); - - /** - * Receives ksmps MYFLT values from the chano opcode (a-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, and - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundChanOAGet(CSOUND *, MYFLT *value, int n); - - /** - * Sets the chani opcode MYFLT k-rate value for the indicated channel. - * The bus is automatically extended if the channel is greater than - * previously used, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, - * and CSOUND_MEMORY if there is not enough memory to estend the bus. - */ - PUBLIC int csoundChanIKSetValue(CSOUND *, int channel, MYFLT value); - - /** - * Returns the chani opcode MYFLT k-rate value for the indicated channel. - * The bus is automatically extended if the channel is greater than - * previously used, clearing new locations to zero. - * Returns the sample value on success, CSOUND_ERROR if the index is invalid, - * and CSOUND_MEMORY if there is not enough memory to estend the bus - */ - PUBLIC MYFLT csoundChanOKGetValue(CSOUND *, int channel); - - /** - * Sets the chani opcode MYFLT a-rate value for the indicated frame - * of the indicated channel. - * The bus is automatically extended if the channel is greater than - * previously used, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid, - * and CSOUND_MEMORY if there is not enough memory to estend the bus. - */ - PUBLIC int csoundChanIASetSample(CSOUND *, int channel, int frame, MYFLT sample); - - /** - * Sets the chani opcode MYFLT a-rate value for the indicated frame - * for the indicated channel. - * The bus is automatically extended if the channel is greater than - * previously used, clearing new locations to zero. - * Returns the sample value on success, CSOUND_ERROR if the index is invalid, - * and CSOUND_MEMORY if there is not enough memory to estend the bus. - */ - PUBLIC MYFLT csoundChanOAGetSample(CSOUND *, int channel, int frame); - - /** - * Sends a PVSDATEX fin to the pvsin opcode (f-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid or - * fsig framesizes are incompatible - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundChanIASetSample(CSOUND *, int channel, int frame, MYFLT sample); - - /** - * Sets the chani opcode MYFLT a-rate value for the indicated frame - * for the indicated channel. - * The bus is automatically extended if the channel is greater than - * previously used, clearing new locations to zero. - * Returns the sample value on success, CSOUND_ERROR if the index is invalid, - * and CSOUND_MEMORY if there is not enough memory to estend the bus. - */ - PUBLIC MYFLT csoundChanOAGetSample(CSOUND *, int channel, int frame); - - /** - * Sends a PVSDATEX fin to the pvsin opcode (f-rate) at index 'n'. - * The bus is automatically extended if 'n' exceeds any previously used - * index value, clearing new locations to zero. - * Returns zero on success, CSOUND_ERROR if the index is invalid or - * fsig framesizes are incompatible - * CSOUND_MEMORY if there is not enough memory to extend the bus. - */ - PUBLIC int csoundPvsinSet(CSOUND *, const PVSDATEXT *fin, int n); - - /** - * Receives a PVSDAT fout from the pvsout opcode (f-rate) at index 'n'. - * The bus is extended if 'n' exceeds any previous value. - * Returns zero on success, CSOUND_ERROR if the index is invalid or - * if fsig framesizes are incompatible - * CSOUND_MEMORY if there is not enough memory to extend the bus - */ - PUBLIC int csoundPvsoutGet(CSOUND *csound, PVSDATEXT *fout, int n); - - /** - * Sets general purpose callback function that will be called on various - * events. The callback is preserved on csoundReset(), and multiple - * callbacks may be set and will be called in reverse order of - * registration. If the same function is set again, it is only moved - * in the list of callbacks so that it will be called first, and the - * user data and type mask parameters are updated. 'typeMask' can be the - * bitwise OR of callback types for which the function should be called, - * or zero for all types. - * Returns zero on success, CSOUND_ERROR if the specified function - * pointer or type mask is invalid, and CSOUND_MEMORY if there is not - * enough memory. - * - * The callback function takes the following arguments: - * void *userData - * the "user data" pointer, as specified when setting the callback - * void *p - * data pointer, depending on the callback type - * unsigned int type - * callback type, can be one of the following (more may be added in - * future versions of Csound): - * CSOUND_CALLBACK_KBD_EVENT - * CSOUND_CALLBACK_KBD_TEXT - * called by the sensekey opcode to fetch key codes. The data - * pointer is a pointer to a single value of type 'int', for - * returning the key code, which can be in the range 1 to 65535, - * or 0 if there is no keyboard event. - * For CSOUND_CALLBACK_KBD_EVENT, both key press and release - * events should be returned (with 65536 (0x10000) added to the - * key code in the latter case) as unshifted ASCII codes. - * CSOUND_CALLBACK_KBD_TEXT expects key press events only as the - * actual text that is typed. - * The return value should be zero on success, negative on error, and - * positive if the callback was ignored (for example because the type is - * not known). - */ - PUBLIC int csoundSetCallback(CSOUND *, int (*func)(void *userData, void *p, - unsigned int type), - void *userData, unsigned int typeMask); - - /** - * Removes a callback previously set with csoundSetCallback(). - */ - PUBLIC void csoundRemoveCallback(CSOUND *, - int (*func)(void *, void *, unsigned int)); - - - - /** - * Creates a buffer for storing messages printed by Csound. - * Should be called after creating a Csound instance; note that - * the message buffer uses the host data pointer, and the buffer - * should be freed by calling csoundDestroyMessageBuffer() before - * deleting the Csound instance. - * If 'toStdOut' is non-zero, the messages are also printed to - * stdout and stderr (depending on the type of the message), - * in addition to being stored in the buffer. - */ - void PUBLIC csoundEnableMessageBuffer(CSOUND *csound, int toStdOut); - - /** - * Returns the first message from the buffer. - */ - PUBLIC const char* csoundGetFirstMessage(CSOUND *csound); - - /** - * Returns the attribute parameter (see msg_attr.h) of the first message - * in the buffer. - */ - int PUBLIC csoundGetFirstMessageAttr(CSOUND *csound); - - /** - * Removes the first message from the buffer. - */ - void PUBLIC csoundPopFirstMessage(CSOUND *csound); - - /** - * Returns the number of pending messages in the buffer. - */ - int PUBLIC csoundGetMessageCnt(CSOUND *csound); - - /** - * Releases all memory used by the message buffer. - */ - void PUBLIC csoundDestroyMessageBuffer(CSOUND *csound); - - void PUBLIC sigcpy(MYFLT *dest, MYFLT *src, int size); -#if !defined(SWIG) - /** - * Sets an external callback for receiving notices whenever Csound opens - * a file. The callback is made after the file is successfully opened. - * The following information is passed to the callback: - * char* pathname of the file; either full or relative to current dir - * int a file type code from the enumeration CSOUND_FILETYPES - * int 1 if Csound is writing the file, 0 if reading - * int 1 if a temporary file that Csound will delete; 0 if not - * - * Pass NULL to disable the callback. - * This callback is retained after a csoundReset() call. - */ - PUBLIC void csoundSetFileOpenCallback(CSOUND *p, - void (*func)(CSOUND*, const char*, int, int, int)); -#endif - - /* This pragma must come after all public function declarations */ -#if (defined(macintosh) && defined(__MWERKS__)) -# pragma export off -#endif - -#endif /* !CSOUND_CSDL_H */ - - /* typedefs, macros, and interface functions for configuration variables */ -#include "cfgvar.h" - /* message attribute definitions for csoundMessageS() and csoundMessageV() */ -#include "msg_attr.h" - /* macro definitions for Csound release, and API version */ -#include "version.h" - -#ifdef __cplusplus -} -#endif - -#endif /* CSOUND_H */ diff -Nru csound-5.17.11~dfsg/H/csound.hpp csound-6.02~dfsg/H/csound.hpp --- csound-5.17.11~dfsg/H/csound.hpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csound.hpp 1970-01-01 00:00:00.000000000 +0000 @@ -1,1034 +0,0 @@ -/* - csound.hpp: - - Copyright (C) 2005 Istvan Varga, Michael Gogins - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA - - As a special exception, if other files instantiate templates or - use macros or inline functions from this file, this file does not - by itself cause the resulting executable or library to be covered - by the GNU Lesser General Public License. This exception does not - however invalidate any other reasons why the library or executable - file might be covered by the GNU Lesser General Public License. -*/ - -#ifndef __CSOUND_HPP__ -#define __CSOUND_HPP__ - -#ifdef SWIG -%module csnd -%{ -#include "csound.h" - //#include "cs_glue.h" -%} -#else -#include "csound.h" -#if defined(HAVE_PTHREAD_SPIN_LOCK) && !defined(SWIG) -#include -#endif -#ifdef __BUILDING_CSOUND_INTERFACES -//#include "cs_glue.h" -#endif -#endif - -#ifdef SWIGPYTHON -#define MESSAGE_BUFFER_LENGTH 8192 -struct PUBLIC pycbdata { - PyObject *mfunc,*invalfunc,*outvalfunc; - PyObject *midiinopenfunc, *midireadfunc, *midiinclosefunc; - PyObject *hostdata; - char messageBuffer[MESSAGE_BUFFER_LENGTH]; - int messageBufferIndex; -}; -#endif - -#if defined(__cplusplus) - -#if defined(HAVE_PTHREAD_SPIN_LOCK) && !defined(SWIG) -struct Spinlock -{ - pthread_spinlock_t lock_; - Spinlock() - { - pthread_spin_init(&lock_, PTHREAD_PROCESS_PRIVATE); - } - ~Spinlock() - { - pthread_spin_destroy(&lock_); - } - void lock() - { - pthread_spin_lock(&lock_); - } - void unlock() - { - pthread_spin_unlock(&lock_); - } -}; - -struct Spinlocker -{ - Spinlock &spinlock; - Spinlocker(Spinlock &spinlock_) : spinlock(spinlock_) - { - spinlock.lock(); - } - ~Spinlocker() - { - spinlock.unlock(); - } -}; -#endif - - -/** - * C++ interface to the "C" Csound API. - */ -class PUBLIC Csound -{ -protected: - CSOUND *csound; -public: - void *pydata; - -public: - virtual CSOUND *GetCsound() - { - return csound; - } - // csound.h interface - virtual int PreCompile() - { - return csoundPreCompile(csound); - } - virtual int InitializeCscore(FILE *insco, FILE *outsco) - { - return csoundInitializeCscore(csound, insco, outsco); - } - virtual void *GetHostData() - { - return csoundGetHostData(csound); - } - virtual void SetHostData(void *hostData) - { - csoundSetHostData(csound, hostData); - } - virtual const char *GetEnv(const char *name) - { - return csoundGetEnv(csound, name); - } - // performance - virtual int Compile(int argc, char **argv) - { - return csoundCompile(csound, argc, argv); - } - virtual int Compile(char *csdName) - { - char *argv[3]; - argv[0] = (char*)"csound"; - argv[1] = csdName; - argv[2] = (char*) 0; - return csoundCompile(csound, 2, &(argv[0])); - } - virtual int Compile(char *orcName, char *scoName) - { - char *argv[4]; - argv[0] = (char*)"csound"; - argv[1] = orcName; - argv[2] = scoName; - argv[3] = (char*) 0; - return csoundCompile(csound, 3, &(argv[0])); - } - virtual int Compile(char *arg1, char *arg2, char *arg3) - { - char *argv[5]; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = (char*) 0; - return csoundCompile(csound, 4, &(argv[0])); - } - virtual int Compile(char *arg1, char *arg2, char *arg3, char *arg4) - { - char *argv[6]; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = arg4; - argv[5] = (char*) 0; - return csoundCompile(csound, 5, &(argv[0])); - } - virtual int Compile(char *arg1, char *arg2, char *arg3, - char *arg4, char *arg5) - { - char *argv[7]; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = arg4; - argv[5] = arg5; - argv[6] = (char*) 0; - return csoundCompile(csound, 6, &(argv[0])); - } - virtual int Perform() - { - return csoundPerform(csound); - } - virtual int Perform(int argc, char **argv) - { - int retval = csoundCompile(csound, argc, argv); - if (!retval) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int Perform(char *csdName) - { - char *argv[3]; - int retval; - argv[0] = (char*)"csound"; - argv[1] = csdName; - argv[2] = (char*) 0; - if (!(retval = csoundCompile(csound, 2, &(argv[0])))) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int Perform(char *orcName, char *scoName) - { - char *argv[4]; - int retval; - argv[0] = (char*)"csound"; - argv[1] = orcName; - argv[2] = scoName; - argv[3] = (char*) 0; - if (!(retval = csoundCompile(csound, 3, &(argv[0])))) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int Perform(char *arg1, char *arg2, char *arg3) - { - char *argv[5]; - int retval; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = (char*) 0; - if (!(retval = csoundCompile(csound, 4, &(argv[0])))) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int Perform(char *arg1, char *arg2, char *arg3, char *arg4) - { - char *argv[6]; - int retval; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = arg4; - argv[5] = (char*) 0; - if (!(retval = csoundCompile(csound, 5, &(argv[0])))) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int Perform(char *arg1, char *arg2, char *arg3, - char *arg4, char *arg5) - { - char *argv[7]; - int retval; - argv[0] = (char*)"csound"; - argv[1] = arg1; - argv[2] = arg2; - argv[3] = arg3; - argv[4] = arg4; - argv[5] = arg5; - argv[6] = (char*) 0; - if (!(retval = csoundCompile(csound, 6, &(argv[0])))) - retval = csoundPerform(csound); - csoundCleanup(csound); - return (retval >= 0 ? 0 : retval); - } - virtual int PerformKsmps() - { - return csoundPerformKsmps(csound); - } - virtual int PerformKsmpsAbsolute() - { - return csoundPerformKsmpsAbsolute(csound); - } - virtual int PerformBuffer() - { - return csoundPerformBuffer(csound); - } - virtual void Stop() - { - csoundStop(csound); - } - virtual int Cleanup() - { - return csoundCleanup(csound); - } - virtual void Reset() - { - csoundReset(csound); - } - // attributes - virtual MYFLT GetSr() - { - return csoundGetSr(csound); - } - virtual MYFLT GetKr() - { - return csoundGetKr(csound); - } - virtual int GetKsmps() - { - return csoundGetKsmps(csound); - } - virtual int GetNchnls() - { - return csoundGetNchnls(csound); - } - virtual MYFLT Get0dBFS() - { - return csoundGet0dBFS(csound); - } - virtual int GetStrVarMaxLen() - { - return csoundGetStrVarMaxLen(csound); - } - virtual int GetSampleFormat() - { - return csoundGetSampleFormat(csound); - } - virtual int GetSampleSize() - { - return csoundGetSampleSize(csound); - } - virtual long GetInputBufferSize() - { - return csoundGetInputBufferSize(csound); - } - virtual long GetOutputBufferSize() - { - return csoundGetOutputBufferSize(csound); - } - virtual MYFLT *GetInputBuffer() - { - return csoundGetInputBuffer(csound); - } - virtual MYFLT *GetOutputBuffer() - { - return csoundGetOutputBuffer(csound); - } - virtual MYFLT *GetSpin() - { - return csoundGetSpin(csound); - } - virtual MYFLT *GetSpout() - { - return csoundGetSpout(csound); - } - virtual const char *GetOutputFileName() - { - return csoundGetOutputFileName(csound); - } - virtual void SetHostImplementedAudioIO(int state, int bufSize) - { - csoundSetHostImplementedAudioIO(csound, state, bufSize); - } - virtual double GetScoreTime() - { - return csoundGetScoreTime(csound); - } - // score handling - virtual int IsScorePending() - { - return csoundIsScorePending(csound); - } - virtual void SetScorePending(int pending) - { - csoundSetScorePending(csound, pending); - } - virtual MYFLT GetScoreOffsetSeconds() - { - return csoundGetScoreOffsetSeconds(csound); - } - virtual void SetScoreOffsetSeconds(double time) - { - csoundSetScoreOffsetSeconds(csound, (MYFLT) time); - } - virtual void RewindScore() - { - csoundRewindScore(csound); - } - virtual void SetCscoreCallback(void (*cscoreCallback_)(CSOUND *)) - { - csoundSetCscoreCallback(csound, cscoreCallback_); - } - virtual int ScoreSort(FILE *inFile, FILE *outFile) - { - return csoundScoreSort(csound, inFile, outFile); - } - virtual int ScoreExtract(FILE *inFile, FILE *outFile, FILE *extractFile) - { - return csoundScoreExtract(csound, inFile, outFile, extractFile); - } - // messages & text - virtual void Message(const char *format, ...) - { - va_list args; - va_start(args, format); - csoundMessageV(csound, 0, format, args); - va_end(args); - } - virtual void MessageS(int attr, const char *format, ...) - { - va_list args; - va_start(args, format); - csoundMessageV(csound, attr, format, args); - va_end(args); - } - virtual void MessageV(int attr, const char *format, va_list args) - { - csoundMessageV(csound, attr, format, args); - } - virtual void SetMessageCallback( - void (*csoundMessageCallback_)(CSOUND *, int attr, - const char *format, va_list valist)) - { - csoundSetMessageCallback(csound, csoundMessageCallback_); - } - virtual int GetMessageLevel() - { - return csoundGetMessageLevel(csound); - } - virtual void SetMessageLevel(int messageLevel) - { - csoundSetMessageLevel(csound, messageLevel); - } - virtual void InputMessage(const char *message) - { - csoundInputMessage(csound, message); - } - virtual void KeyPressed(char c) - { - csoundKeyPress(csound, c); - } - // control and events - virtual void SetInputValueCallback( - void (*inputValueCallback_)(CSOUND *, const char *, MYFLT *)) - { - csoundSetInputValueCallback(csound, inputValueCallback_); - } - virtual void SetOutputValueCallback( - void (*outputValueCallback_)(CSOUND *, const char *, MYFLT)) - { - csoundSetOutputValueCallback(csound, outputValueCallback_); - } - virtual int ScoreEvent(char type, const MYFLT *pFields, long numFields) - { - return csoundScoreEvent(csound, type, pFields, numFields); - } - virtual int ScoreEventAbsolute(char type, const MYFLT *pFields, - long numFields, double time_ofs) - { - return csoundScoreEventAbsolute(csound, type, pFields, numFields, time_ofs); - } - // MIDI - virtual void SetExternalMidiInOpenCallback( - int (*func)(CSOUND *, void **, const char *)) - { - csoundSetExternalMidiInOpenCallback(csound, func); - } - virtual void SetExternalMidiReadCallback( - int (*func)(CSOUND *, void *, unsigned char *, int)) - { - csoundSetExternalMidiReadCallback(csound, func); - } - virtual void SetExternalMidiInCloseCallback( - int (*func)(CSOUND *, void *)) - { - csoundSetExternalMidiInCloseCallback(csound, func); - } - virtual void SetExternalMidiOutOpenCallback( - int (*func)(CSOUND *, void **, const char *)) - { - csoundSetExternalMidiOutOpenCallback(csound, func); - } - virtual void SetExternalMidiWriteCallback( - int (*func)(CSOUND *, void *, const unsigned char *, int)) - { - csoundSetExternalMidiWriteCallback(csound, func); - } - virtual void SetExternalMidiOutCloseCallback( - int (*func)(CSOUND *, void *)) - { - csoundSetExternalMidiOutCloseCallback(csound, func); - } - virtual void SetExternalMidiErrorStringCallback( - const char *(*func)(int)) - { - csoundSetExternalMidiErrorStringCallback(csound, func); - } - // function table display - virtual int SetIsGraphable(int isGraphable) - { - return csoundSetIsGraphable(csound, isGraphable); - } - virtual void SetMakeGraphCallback( - void (*makeGraphCallback_)(CSOUND *, WINDAT *windat, const char *name)) - { - csoundSetMakeGraphCallback(csound, makeGraphCallback_); - } - virtual void SetDrawGraphCallback( - void (*drawGraphCallback_)(CSOUND *, WINDAT *windat)) - { - csoundSetDrawGraphCallback(csound, drawGraphCallback_); - } - virtual void SetKillGraphCallback( - void (*killGraphCallback_)(CSOUND *, WINDAT *windat)) - { - csoundSetKillGraphCallback(csound, killGraphCallback_); - } - virtual void SetMakeXYinCallback( - void (*makeXYinCallback_)(CSOUND *, XYINDAT *, MYFLT x, MYFLT y)) - { - csoundSetMakeXYinCallback(csound, makeXYinCallback_); - } - virtual void SetReadXYinCallback( - void (*readXYinCallback_)(CSOUND *, XYINDAT *)) - { - csoundSetReadXYinCallback(csound, readXYinCallback_); - } - virtual void SetKillXYinCallback( - void (*killXYinCallback_)(CSOUND *, XYINDAT *)) - { - csoundSetKillXYinCallback(csound, killXYinCallback_); - } - virtual void SetExitGraphCallback( - int (*exitGraphCallback_)(CSOUND *)) - { - csoundSetExitGraphCallback(csound, exitGraphCallback_); - } - // opcodes - virtual int NewOpcodeList(opcodeListEntry* &opcodelist) - { - opcodeListEntry *tmp = (opcodeListEntry*) 0; - int retval; - retval = csoundNewOpcodeList(csound, &tmp); - opcodelist = tmp; - return retval; - } - virtual void DisposeOpcodeList(opcodeListEntry *opcodelist) - { - csoundDisposeOpcodeList(csound, opcodelist); - } - virtual int AppendOpcode(const char *opname, int dsblksiz, int thread, - const char *outypes, const char *intypes, - int (*iopadr)(CSOUND *, void *), - int (*kopadr)(CSOUND *, void *), - int (*aopadr)(CSOUND *, void *)) - { - return csoundAppendOpcode(csound, opname, dsblksiz, thread, - outypes, intypes, iopadr, kopadr, aopadr); - } - // miscellaneous functions - virtual void SetYieldCallback(int (*yieldCallback_)(CSOUND *)) - { - csoundSetYieldCallback(csound, yieldCallback_); - } - // real-time audio play and record - virtual void SetPlayopenCallback( - int (*playopen__)(CSOUND *, const csRtAudioParams *parm)) - { - csoundSetPlayopenCallback(csound, playopen__); - } - virtual void SetRtplayCallback( - void (*rtplay__)(CSOUND *, const MYFLT *outBuf, int nbytes)) - { - csoundSetRtplayCallback(csound, rtplay__); - } - virtual void SetRecopenCallback( - int (*recopen_)(CSOUND *, const csRtAudioParams *parm)) - { - csoundSetRecopenCallback(csound, recopen_); - } - virtual void SetRtrecordCallback( - int (*rtrecord__)(CSOUND *, MYFLT *inBuf, int nbytes)) - { - csoundSetRtrecordCallback(csound, rtrecord__); - } - virtual void SetRtcloseCallback( - void (*rtclose__)(CSOUND *)) - { - csoundSetRtcloseCallback(csound, rtclose__); - } - // -------- - virtual int GetDebug() - { - return csoundGetDebug(csound); - } - virtual void SetDebug(int debug) - { - csoundSetDebug(csound, debug); - } - virtual int TableLength(int table) - { - return csoundTableLength(csound, table); - } - virtual MYFLT TableGet(int table, int index) - { - return csoundTableGet(csound, table, index); - } - virtual void TableSet(int table, int index, double value) - { - csoundTableSet(csound, table, index, (MYFLT) value); - } - virtual int GetTable(MYFLT* &tablePtr, int tableNum) - { - MYFLT *ftable; - int tmp; - tmp = csoundGetTable(csound, &ftable, tableNum); - tablePtr = ftable; - return tmp; - } - virtual int CreateGlobalVariable(const char *name, size_t nbytes) - { - return csoundCreateGlobalVariable(csound, name, nbytes); - } - virtual void *QueryGlobalVariable(const char *name) - { - return csoundQueryGlobalVariable(csound, name); - } - virtual void *QueryGlobalVariableNoCheck(const char *name) - { - return csoundQueryGlobalVariableNoCheck(csound, name); - } - virtual int DestroyGlobalVariable(const char *name) - { - return csoundDestroyGlobalVariable(csound, name); - } - virtual void **GetRtRecordUserData() - { - return csoundGetRtRecordUserData(csound); - } - virtual void **GetRtPlayUserData() - { - return csoundGetRtPlayUserData(csound); - } - virtual int RegisterSenseEventCallback(void (*func)(CSOUND *, void *), - void *userData) - { - return csoundRegisterSenseEventCallback(csound, func, userData); - } - virtual int RunUtility(const char *name, int argc, char **argv) - { - return csoundRunUtility(csound, name, argc, argv); - } - virtual char **ListUtilities() - { - return csoundListUtilities(csound); - } - virtual void DeleteUtilityList(char **lst) - { - csoundDeleteUtilityList(csound, lst); - } - virtual const char *GetUtilityDescription(const char *utilName) - { - return csoundGetUtilityDescription(csound, utilName); - } - virtual int GetChannelPtr(MYFLT* &p, const char *name, int type) - { - MYFLT *tmp; - int retval; - retval = csoundGetChannelPtr(csound, &tmp, name, type); - p = tmp; - return retval; - } - virtual int ListChannels(CsoundChannelListEntry* &lst) - { - CsoundChannelListEntry *tmp; - int retval; - retval = csoundListChannels(csound, &tmp); - lst = tmp; - return retval; - } - virtual void DeleteChannelList(CsoundChannelListEntry *lst) - { - csoundDeleteChannelList(csound, lst); - } - virtual int SetControlChannelParams(const char *name, int type, - double dflt, double min, double max) - { - return csoundSetControlChannelParams(csound, name, type, (MYFLT) dflt, - (MYFLT) min, (MYFLT) max); - } - virtual int GetControlChannelParams(const char *name, - MYFLT &dflt, MYFLT &min, MYFLT &max) - { - MYFLT tmp1 = (MYFLT) 0, tmp2 = (MYFLT) 0, tmp3 = (MYFLT) 0; - int retval; - retval = csoundGetControlChannelParams(csound, name, &tmp1, &tmp2, &tmp3); - dflt = tmp1; - min = tmp2; - max = tmp3; - return retval; - } - virtual void SetChannel(const char *name, double value) - { - MYFLT *p; - if (!(csoundGetChannelPtr(csound, &p, name, - CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL))) - *p = (MYFLT) value; - } - virtual void SetChannel(const char *name, const char *value) - { - MYFLT *p; - if (!(csoundGetChannelPtr(csound, &p, name, - CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL))) { - size_t maxLen = (size_t) (csoundGetStrVarMaxLen(csound) - 1); - size_t i = (size_t) 0; - while (value[i]) { - ((char*) p)[i] = value[i]; - if (++i >= maxLen) - break; - } - ((char*) p)[i] = '\0'; - } - } - virtual MYFLT GetChannel(const char *name) - { - MYFLT *p; - if (!(csoundGetChannelPtr(csound, &p, name, - CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL))) - return (*p); - return (MYFLT) 0; - } - virtual int ChanIKSet(double value, int n) - { - return csoundChanIKSet(csound, (MYFLT) value, n); - } - virtual int ChanOKGet(MYFLT &value, int n) - { - MYFLT tmp = (MYFLT) 0; - int retval; - retval = csoundChanOKGet(csound, &tmp, n); - value = tmp; - return retval; - } - virtual int ChanIASet(const MYFLT *value, int n) - { - return csoundChanIASet(csound, value, n); - } - virtual int ChanOAGet(MYFLT *value, int n) - { - return csoundChanOAGet(csound, value, n); - } - - - virtual int PvsinSet(const PVSDATEXT* value, int n) - { - return csoundPvsinSet(csound, value, n); - } - - virtual int PvsoutGet(PVSDATEXT* value, int n) - { - return csoundPvsoutGet(csound, value, n); - } - - // cfgvar.h interface - virtual int CreateConfigurationVariable(const char *name, void *p, - int type, int flags, - void *min, void *max, - const char *shortDesc, - const char *longDesc) - { - return csoundCreateConfigurationVariable(csound, name, p, type, flags, - min, max, shortDesc, longDesc); - } -#if 0 - virtual int CopyGlobalConfigurationVariable(const char *name, void *p) - { - return csoundCopyGlobalConfigurationVariable(csound, name, p); - } - virtual int CopyGlobalConfigurationVariables() - { - return csoundCopyGlobalConfigurationVariables(csound); - } -#endif - virtual int SetConfigurationVariable(const char *name, void *value) - { - return csoundSetConfigurationVariable(csound, name, value); - } - virtual int ParseConfigurationVariable(const char *name, const char *value) - { - return csoundParseConfigurationVariable(csound, name, value); - } - virtual csCfgVariable_t *QueryConfigurationVariable(const char *name) - { - return csoundQueryConfigurationVariable(csound, name); - } - virtual csCfgVariable_t **ListConfigurationVariables() - { - return csoundListConfigurationVariables(csound); - } - virtual int DeleteConfigurationVariable(const char *name) - { - return csoundDeleteConfigurationVariable(csound, name); - } - virtual void SetChannelIOCallback(CsoundChannelIOCallback_t func) - { - csoundSetChannelIOCallback(csound, func); - } - // constructors - // FIXME: should throw exception on failure ? - Csound() - { - csound = csoundCreate((CSOUND*) 0); - #ifdef SWIGPYTHON - pydata =(pycbdata *) new pycbdata; - memset(pydata, sizeof(pydata), 0); - ((pycbdata *)pydata)->mfunc = NULL; - ((pycbdata *)pydata)->messageBufferIndex = 0; - csoundSetHostData(csound, this); - #endif - } - Csound(void *hostData) - { - csound = csoundCreate(hostData); - #ifdef SWIGPYTHON - pydata =(pycbdata *) new pycbdata; - ((pycbdata *)pydata)->mfunc = NULL; - ((pycbdata *)pydata)->messageBufferIndex = 0; - csoundSetHostData(csound, this); - #endif - } - // destructor - virtual ~Csound() - { - csoundDestroy(csound); - #ifdef SWIGPYTHON - ((pycbdata *)pydata)->mfunc = NULL; - delete (pycbdata *)pydata; - #endif - - } - // Functions for embedding. - virtual void EnableMessageBuffer(int toStdOut) - { - csoundEnableMessageBuffer(csound, toStdOut); - } - virtual const char *GetFirstMessage() - { - return csoundGetFirstMessage(csound); - } - virtual int GetFirstMessageAttr() - { - return csoundGetFirstMessageAttr(csound); - } - virtual void PopFirstMessage() - { - csoundPopFirstMessage(csound); - } - virtual int GetMessageCnt() - { - return csoundGetMessageCnt(csound); - } - virtual void DestroyMessageBuffer() - { - csoundDestroyMessageBuffer(csound); - } - virtual void AddSpinSample(int frame, int channel, MYFLT sample) - { - csoundAddSpinSample(csound, frame, channel, sample); - } - virtual MYFLT GetSpoutSample(int frame, int channel) const - { - return csoundGetSpoutSample(csound, frame, channel); - } - virtual int ChanIKSetValue(int channel, MYFLT value) - { - return csoundChanIKSetValue(csound, channel, value); - } - virtual MYFLT ChanOKGetValue(int channel) - { - return csoundChanOKGetValue(csound, channel); - } - virtual int ChanIASetSample(int channel, int frame, MYFLT sample) - { - return csoundChanIASetSample(csound, channel, frame, sample); - } - virtual MYFLT ChanOAGetSample(int channel, int frame) - { - return csoundChanOAGetSample(csound, channel, frame); - } -}; - -// thread locks - -class CsoundThreadLock { -protected: - void *threadLock; -public: - int Lock(size_t milliseconds) - { - return csoundWaitThreadLock(threadLock, milliseconds); - } - void Lock() - { - csoundWaitThreadLockNoTimeout(threadLock); - } - int TryLock() - { - return csoundWaitThreadLock(threadLock, (size_t) 0); - } - void Unlock() - { - csoundNotifyThreadLock(threadLock); - } - // constructors - // FIXME: should throw exception on failure ? - CsoundThreadLock() - { - threadLock = csoundCreateThreadLock(); - } - CsoundThreadLock(int locked) - { - threadLock = csoundCreateThreadLock(); - if (locked) - csoundWaitThreadLock(threadLock, (size_t) 0); - } - // destructor - ~CsoundThreadLock() - { - csoundDestroyThreadLock(threadLock); - } -}; - -class CsoundMutex { -protected: - void *mutex_; -public: - void Lock() - { - csoundLockMutex(mutex_); - } - // FIXME: this may be unimplemented on Windows - int TryLock() - { - return csoundLockMutexNoWait(mutex_); - } - void Unlock() - { - csoundUnlockMutex(mutex_); - } - // constructors - // FIXME: should throw exception on failure ? - CsoundMutex() - { - mutex_ = csoundCreateMutex(1); - } - CsoundMutex(int isRecursive) - { - mutex_ = csoundCreateMutex(isRecursive); - } - // destructor - ~CsoundMutex() - { - csoundDestroyMutex(mutex_); - } -}; - -// Mersenne Twister (MT19937) pseudo-random number generator - -class CsoundRandMT { -protected: - CsoundRandMTState mt; -public: - uint32_t Random() - { - return csoundRandMT(&mt); - } - void Seed(uint32_t seedVal) - { - csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal); - } - void Seed(const uint32_t *initKey, int keyLength) - { - csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength); - } - // constructors - CsoundRandMT() - { - csoundSeedRandMT(&mt, (uint32_t*) 0, csoundGetRandomSeedFromTime()); - } - CsoundRandMT(uint32_t seedVal) - { - csoundSeedRandMT(&mt, (uint32_t*) 0, seedVal); - } - CsoundRandMT(const uint32_t *initKey, int keyLength) - { - csoundSeedRandMT(&mt, initKey, (uint32_t) keyLength); - } - ~CsoundRandMT() - { - } -}; - -// timer (csoundInitialize() should be called before using this) - -class CsoundTimer { -protected: - RTCLOCK rt; -public: - double GetRealTime() - { - return csoundGetRealTime(&rt); - } - double GetCPUTime() - { - return csoundGetCPUTime(&rt); - } - void Reset() - { - csoundInitTimerStruct(&rt); - } - // constructor - CsoundTimer() - { - csoundInitTimerStruct(&rt); - } - ~CsoundTimer() - { - } -}; - -#endif // __cplusplus - -#endif // __CSOUND_HPP__ - diff -Nru csound-5.17.11~dfsg/H/csoundCore.h csound-6.02~dfsg/H/csoundCore.h --- csound-5.17.11~dfsg/H/csoundCore.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csoundCore.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,1396 +0,0 @@ -/* - csoundCore.h: - - Copyright (C) 1991-2006 Barry Vercoe, John ffitch, Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#if !defined(__BUILDING_LIBCSOUND) && !defined(CSOUND_CSDL_H) -# error "Csound plugins and host applications should not include csoundCore.h" -#endif - -#ifndef CSOUNDCORE_H -#define CSOUNDCORE_H - -#include "sysdep.h" -#ifdef PARCS -#include -#include "cs_par_structs.h" -#endif /* PARCS */ -#include -#include - -/* -#include -JPff: But this gives warnings in many files as rewriteheader expects -to have an argument of SNDFILE*. Might be able to fix with a void* -VL: moved to allow opcodes to be built without libsndfile headers -The libsndfile header is now place only where it is used: -Engine/envvar.c -Engine/memfiles.c -Engine/libsnd_u.c -OOps/sndinfUG.c -Opcodes/fout.c -util/atsa.c -Opcodes/stdopcode.h -H/diskin2.h -H/soundio.h -util/pvanal.c -util/sndinfo.c -util/xtrct.c -*/ - -#include "csound.h" - - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#ifdef __MACH__ -#define BARRIER_SERIAL_THREAD (-1) -typedef struct { - pthread_mutex_t mut; - pthread_cond_t cond; - unsigned int count, max, iteration; -} barrier_t; - -#ifndef PTHREAD_BARRIER_SERIAL_THREAD -#define pthread_barrier_t barrier_t -#endif /* PTHREAD_BARRIER_SERIAL_THREAd */ -#endif /* __MACH__ */ - - -#define OK (0) -#define NOTOK (-1) - -#define CSFILE_FD_R 1 -#define CSFILE_FD_W 2 -#define CSFILE_STD 3 -#define CSFILE_SND_R 4 -#define CSFILE_SND_W 5 - -#define MAXINSNO (200) -#define PMAX (1998) -#define VARGMAX (1999) - -#define ORTXT h.optext->t -#define INCOUNT ORTXT.inlist->count -#define OUTCOUNT ORTXT.outlist->count /* Not used */ -#define INOCOUNT ORTXT.inoffs->count -#define OUTOCOUNT ORTXT.outoffs->count -#define XINCODE ORTXT.xincod -# define XINARG1 (p->XINCODE & 1) -# define XINARG2 (p->XINCODE & 2) -# define XINARG3 (p->XINCODE & 4) -# define XINARG4 (p->XINCODE & 8) -# define XINARG5 (p->XINCODE &16) -#define XOUTCODE ORTXT.xoutcod -#define XSTRCODE ORTXT.xincod_str -#define XOUTSTRCODE ORTXT.xoutcod_str - -#define CURTIME (((double)csound->icurTime)/((double)csound->esr)) -#define CURTIME_inc (((double)csound->ksmps)/((double)csound->esr)) - -#define MAXLEN 0x1000000L -#define FMAXLEN ((MYFLT)(MAXLEN)) -#define PHMASK 0x0FFFFFFL -#define PFRAC(x) ((MYFLT)((x) & ftp->lomask) * ftp->lodiv) -#define MAXPOS 0x7FFFFFFFL - -#define BYTREVS(n) ((n>>8 & 0xFF) | (n<<8 & 0xFF00)) -#define BYTREVL(n) ((n>>24 & 0xFF) | (n>>8 & 0xFF00L) | \ - (n<<8 & 0xFF0000L) | (n<<24 & 0xFF000000L)) - -#define OCTRES 8192 -#define CPSOCTL(n) ((MYFLT)(1 << ((int)(n) >> 13)) * csound->cpsocfrc[(int)(n) & 8191]) - -#define LOBITS 10 -#define LOFACT 1024 - /* LOSCAL is 1/LOFACT as MYFLT */ -#define LOSCAL FL(0.0009765625) - -#define LOMASK 1023 - -#define SSTRCOD 3945467 -#define SSTRCOD1 3945466 -#define SSTRCOD2 3945465 -#define SSTRCOD3 3945464 -#define SSTRSIZ 200 -#define ALLCHNLS 0x7fff -#define DFLT_SR FL(44100.0) -#define DFLT_KR FL(4410.0) -#define DFLT_KSMPS 10 -#define DFLT_NCHNLS 1 -#define MAXCHNLS 256 - -#define MAXNAME (256) - -#define DFLT_DBFS (FL(32768.0)) - -#define MAXOCTS 8 -#define MAXCHAN 16 /* 16 MIDI channels; only one port for now */ - -#define ONEPT 1.02197486 /* A440 tuning factor */ -#define LOG10D20 0.11512925 /* for db to ampfac */ -#define DV32768 FL(0.000030517578125) - -#ifndef PI -#define PI (3.141592653589793238462643383279502884197) -#endif /* pi */ -#define TWOPI (6.283185307179586476925286766559005768394) -#define PI_F ((MYFLT) PI) -#define TWOPI_F ((MYFLT) TWOPI) -#define INF (2147483647.0) - -#define AMPLMSG 01 -#define RNGEMSG 02 -#define WARNMSG 04 -#define RAWMSG 0x40 -#define TIMEMSG 0x80 -#define IGN(X) (void) X -/* VL: this is a silly redefinition that can only - cause confusion -#define printf use_csoundMessage_instead_of_printf -*/ - typedef struct CORFIL { - char *body; - int len; - int p; - } CORFIL; - - typedef struct { - int odebug; - int sfread, sfwrite, sfheader, filetyp; - int inbufsamps, outbufsamps; - int informat, outformat; - int sfsampsize; - int displays, graphsoff, postscript, msglevel; - int Beatmode, cmdTempo, oMaxLag; - int usingcscore, Linein; - int RTevents, Midiin, FMidiin, RMidiin; - int ringbell, termifend; - int rewrt_hdr, heartbeat, gen01defer; - int expr_opt; /* IV - Jan 27 2005: for --expression-opt */ - float sr_override, kr_override; - char *infilename, *outfilename; - CORFIL *playscore; - char *Linename, *Midiname, *FMidiname; - char *Midioutname; /* jjk 09252000 - MIDI output device, -Q option */ - char *FMidioutname; - int midiKey, midiKeyCps, midiKeyOct, midiKeyPch; - int midiVelocity, midiVelocityAmp; - int noDefaultPaths; /* syy - Oct 25, 2006: for disabling relative paths - from files */ - int numThreads; - int syntaxCheckOnly; - int useCsdLineCounts; -#ifdef ENABLE_NEW_PARSER - int newParser; /* SYY - July 30, 2006: for --new-parser */ - int calculateWeights; -#endif /* ENABLE_NEW_PARSE */ - } OPARMS; - - typedef struct arglst { - int count; - char *arg[1]; - } ARGLST; - - typedef struct argoffs { - int count; - int indx[1]; - } ARGOFFS; - - /** - * Storage for parsed orchestra code, for each opcode in an INSTRTXT. - */ - typedef struct text { - int linenum; /* Line num in orch file (currently buggy!) */ - int opnum; /* Opcode index in opcodlst[] */ - char *opcod; /* Pointer to opcode name in global pool */ - ARGLST *inlist; /* Input args (pointer to item in name list) */ - ARGLST *outlist; - ARGOFFS *inoffs; /* Input args (index into list of values) */ - ARGOFFS *outoffs; - int xincod; /* Rate switch for multi-rate opcode functions */ - int xoutcod; /* output rate switch (IV - Sep 1 2002) */ - int xincod_str; /* Type switch for string arguments */ - int xoutcod_str; - char intype; /* Type of first input argument (g,k,a,w etc) */ - char pftype; /* Type of output argument (k,a etc) */ - } TEXT; - - /** - * This struct is filled out by otran() at orch parse time. - * It is used as a template for instrument events. - */ - typedef struct instr { - struct op * nxtop; /* Linked list of instr opcodes */ - TEXT t; /* Text of instrument (same in nxtop) */ - int pmax, vmax, pextrab; /* Arg count, size of data for all - opcodes in instr */ - int mdepends; /* Opcode type (i/k/a) */ - int lclkcnt, dummy01; /* Storage reqs for this instr */ - int lclwcnt, lclacnt; - int lclpcnt, lclscnt; - int lclfixed, optxtcount; - int16 muted; - int32 localen; - int32 opdstot; /* Total size of opds structs in instr */ - int32 *inslist; /* Only used in parsing (?) */ - MYFLT *psetdata; /* Used for pset opcode */ - struct insds * instance; /* Chain of allocated instances of - this instrument */ - struct insds * lst_instance; /* last allocated instance */ - struct insds * act_instance; /* Chain of free (inactive) instances */ - /* (pointer to next one is INSDS.nxtact) */ - struct instr * nxtinstxt; /* Next instrument in orch (num order) */ - int active; /* To count activations for control */ - int maxalloc; - MYFLT cpuload; /* % load this instrumemnt makes */ - struct opcodinfo *opcode_info; /* IV - Nov 10 2002 */ - char *insname; /* instrument name */ - int instcnt; /* Count number of instances ever */ - } INSTRTXT; - - /** - * A chain of TEXT structs. Note that this is identical with the first two - * members of struct INSTRTEXT, and is so typecast at various points in code. - */ - typedef struct op { - struct op *nxtop; - TEXT t; - } OPTXT; - - typedef struct fdch { - struct fdch *nxtchp; - /** handle returned by csound->FileOpen() */ - void *fd; - } FDCH; - - typedef struct auxch { - struct auxch *nxtchp; - size_t size; - void *auxp, *endp; - } AUXCH; - - typedef struct monblk { - int16 pch; - struct monblk *prv; - } MONPCH; - - typedef struct { - int notnum[4]; - } DPEXCL; - - typedef struct { - DPEXCL dpexcl[8]; - /** for keys 25-99 */ - int exclset[75]; - } DPARM; - - typedef struct dklst { - struct dklst *nxtlst; - int32 pgmno; - /** cnt + keynos */ - MYFLT keylst[1]; - } DKLST; - - typedef struct mchnblk { - /** most recently received program change */ - int16 pgmno; - /** instrument number assigned to this channel */ - int16 insno; - int16 RegParNo; - int16 mono; - MONPCH *monobas; - MONPCH *monocur; - /** list of active notes (NULL: not active) */ - struct insds *kinsptr[128]; - /** polyphonic pressure indexed by note number */ - MYFLT polyaft[128]; - /** ... with GS vib_rate, stored in c128-c135 */ - MYFLT ctl_val[136]; - /** program change to instr number (<=0: ignore) */ - int16 pgm2ins[128]; - /** channel pressure (0-127) */ - MYFLT aftouch; - /** pitch bend (-1 to 1) */ - MYFLT pchbend; - /** pitch bend sensitivity in semitones */ - MYFLT pbensens; - /** number of held (sustaining) notes */ - int16 ksuscnt; - /** current state of sustain pedal (0: off) */ - int16 sustaining; - int dpmsb; - int dplsb; - int datenabl; - /** chain of dpgm keylists */ - DKLST *klists; - /** drumset params */ - DPARM *dparms; - } MCHNBLK; - - /** - * This struct holds the info for a concrete instrument event - * instance in performance. - */ - typedef struct insds { - /* Chain of init-time opcodes */ - struct opds * nxti; - /* Chain of performance-time opcodes */ - struct opds * nxtp; - /* Next allocated instance */ - struct insds * nxtinstance; - /* Previous allocated instance */ - struct insds * prvinstance; - /* Next in list of active instruments */ - struct insds * nxtact; - /* Previous in list of active instruments */ - struct insds * prvact; - /* Next instrument to terminate */ - struct insds * nxtoff; - /* Chain of files used by opcodes in this instr */ - FDCH *fdchp; - /* Extra memory used by opcodes in this instr */ - AUXCH *auxchp; - /* Extra release time requested with xtratim opcode */ - int xtratim; - /* MIDI note info block if event started from MIDI */ - MCHNBLK *m_chnbp; - /* ptr to next overlapping MIDI voice */ - struct insds * nxtolap; - /* Instrument number */ - int16 insno; - /* non-zero for sustaining MIDI note */ - int16 m_sust; - /* MIDI pitch, for simple access */ - unsigned char m_pitch; - /* ...ditto velocity */ - unsigned char m_veloc; - /* Flag to indicate we are releasing, test with release opcode */ - char relesing; - /* Set if instr instance is active (perfing) */ - char actflg; - /* Time to turn off event, in score beats */ - double offbet; - /* Time to turn off event, in seconds (negative on indef/tie) */ - double offtim; - /* Python namespace for just this instance. */ - void *pylocal; - /* pointer to Csound engine and API for externals */ - CSOUND *csound; - /* user defined opcode I/O buffers */ - void *opcod_iobufs; - void *opcod_deact, *subins_deact; - /* opcodes to be run at note deactivation */ - void *nxtd; - /* Copy of required p-field values for quick access */ - MYFLT p0; - MYFLT p1; - MYFLT p2; - MYFLT p3; - } INSDS; - - typedef int (*SUBR)(CSOUND *, void *); - - /** - * This struct holds the info for one opcode in a concrete - * instrument instance in performance. - */ - typedef struct opds { - /** Next opcode in init-time chain */ - struct opds * nxti; - /** Next opcode in perf-time chain */ - struct opds * nxtp; - /** Initialization (i-time) function pointer */ - SUBR iopadr; - /** Perf-time (k- or a-rate) function pointer */ - SUBR opadr; - /** Orch file template part for this opcode */ - OPTXT *optext; - /** Owner instrument instance data structure */ - INSDS *insdshead; - } OPDS; - - typedef struct oentry { - char *opname; - uint16 dsblksiz; - uint16 thread; - char *outypes; - char *intypes; - int (*iopadr)(CSOUND *, void *p); - int (*kopadr)(CSOUND *, void *p); - int (*aopadr)(CSOUND *, void *p); - void *useropinfo; /* user opcode parameters */ - int prvnum; /* IV - Oct 31 2002 */ - } OENTRY; - - typedef struct lblblk { - OPDS h; - OPDS *prvi; - OPDS *prvp; - } LBLBLK; - - typedef struct { - MYFLT *begp, *curp, *endp, feedback[6]; - int32 scount; - } OCTDAT; - - typedef struct { - int32 npts, nocts, nsamps; - MYFLT lofrq, hifrq, looct, srate; - OCTDAT octdata[MAXOCTS]; - AUXCH auxch; - } DOWNDAT; - - typedef struct { - int32 ktimstamp, ktimprd; - int32 npts, nfreqs, dbout; - DOWNDAT *downsrcp; - AUXCH auxch; - } SPECDAT; - - /** - * This struct holds the data for one score event. - */ - typedef struct event { - /** String argument (NULL if none) */ - char *strarg; - /** Event type */ - char opcod; - /** Number of p-fields */ - int16 pcnt; - /** Event start time */ - MYFLT p2orig; - /** Length */ - MYFLT p3orig; - /** All p-fields for this event (SSTRCOD: string argument) */ - MYFLT p[PMAX + 1]; - union { /* To ensure size is same as earlier */ - MYFLT *extra; - MYFLT p[2]; - } c; - char estrarg[3]; /* Extra strings */ - } EVTBLK; - - typedef struct { - MYFLT gen01; - MYFLT ifilno; - MYFLT iskptim; - MYFLT iformat; - MYFLT channel; - MYFLT sample_rate; - char strarg[SSTRSIZ]; - } GEN01ARGS; - - typedef struct { - /** table length, not including the guard point */ - int32 flen; - /** length mask ( = flen - 1) for power of two table size, 0 otherwise */ - int32 lenmask; - /** log2(MAXLEN / flen) for power of two table size, 0 otherwise */ - int32 lobits; - /** 2^lobits - 1 */ - int32 lomask; - /** 1 / 2^lobits */ - MYFLT lodiv; - /** LOFACT * (table_sr / orch_sr), cpscvt = cvtbas / base_freq */ - MYFLT cvtbas, cpscvt; - /** sustain loop mode (0: none, 1: forward, 2: forward and backward) */ - int16 loopmode1; - /** release loop mode (0: none, 1: forward, 2: forward and backward) */ - int16 loopmode2; - /** sustain loop start and end in sample frames */ - int32 begin1, end1; - /** release loop start and end in sample frames */ - int32 begin2, end2; - /** sound file length in sample frames (flenfrms = soundend - 1) */ - int32 soundend, flenfrms; - /** number of channels */ - int32 nchanls; - /** table number */ - int32 fno; - /** GEN01 parameters */ - GEN01ARGS gen01args; - /** table data (flen + 1 MYFLT values) */ - MYFLT ftable[1]; - } FUNC; - - typedef struct { - CSOUND *csound; - int32 flen; - int fno, guardreq; - EVTBLK e; - } FGDATA; - - typedef struct { - char *name; - int (*fn)(FGDATA *, FUNC *); - } NGFENS; - - typedef int (*GEN)(FGDATA *, FUNC *); - - typedef struct MEMFIL { - char filename[256]; /* Made larger RWD */ - char *beginp; - char *endp; - int32 length; - struct MEMFIL *next; - } MEMFIL; - - typedef struct { - int16 type; - int16 chan; - int16 dat1; - int16 dat2; - } MEVENT; - - typedef struct SNDMEMFILE_ { - /** file ID (short name) */ - char *name; - struct SNDMEMFILE_ *nxt; - /** full path filename */ - char *fullName; - /** file length in sample frames */ - size_t nFrames; - /** sample rate in Hz */ - double sampleRate; - /** number of channels */ - int nChannels; - /** AE_SHORT, AE_FLOAT, etc. */ - int sampleFormat; - /** TYP_WAV, TYP_AIFF, etc. */ - int fileType; - /** - * loop mode: - * 0: no loop information - * 1: off - * 2: forward - * 3: backward - * 4: bidirectional - */ - int loopMode; - /** playback start offset frames */ - double startOffs; - /** loop start (sample frames) */ - double loopStart; - /** loop end (sample frames) */ - double loopEnd; - /** base frequency (in Hz) */ - double baseFreq; - /** amplitude scale factor */ - double scaleFac; - /** interleaved sample data */ - float data[1]; - } SNDMEMFILE; - - typedef struct pvx_memfile_ { - char *filename; - struct pvx_memfile_ *nxt; - float *data; - uint32 nframes; - int format; - int fftsize; - int overlap; - int winsize; - int wintype; - int chans; - MYFLT srate; - } PVOCEX_MEMFILE; - -#ifdef __BUILDING_LIBCSOUND - -#define INSTR 1 -#define ENDIN 2 -#define OPCODE 3 -#define ENDOP 4 -#define LABEL 5 -#define SETBEG 6 -#define PSET 6 -#define SETEND 7 - -#define TOKMAX 50L /* Should be 50 but bust */ - -/* max number of input/output args for user defined opcodes */ -#define OPCODENUMOUTS_LOW 16 -#define OPCODENUMOUTS_HIGH 64 -#define OPCODENUMOUTS_MAX 256 - -#define MBUFSIZ (4096) -#define MIDIINBUFMAX (1024) -#define MIDIINBUFMSK (MIDIINBUFMAX-1) - - typedef union { - uint32 dwData; - unsigned char bData[4]; - } MIDIMESSAGE; - - /* MIDI globals */ - - typedef struct midiglobals { - MEVENT *Midevtblk; - int sexp; - int MIDIoutDONE; - int MIDIINbufIndex; - MIDIMESSAGE MIDIINbuffer2[MIDIINBUFMAX]; - int (*MidiInOpenCallback)(CSOUND *, void **, const char *); - int (*MidiReadCallback)(CSOUND *, void *, unsigned char *, int); - int (*MidiInCloseCallback)(CSOUND *, void *); - int (*MidiOutOpenCallback)(CSOUND *, void **, const char *); - int (*MidiWriteCallback)(CSOUND *, void *, const unsigned char *, int); - int (*MidiOutCloseCallback)(CSOUND *, void *); - const char *(*MidiErrorStringCallback)(int); - void *midiInUserData; - void *midiOutUserData; - void *midiFileData; - void *midiOutFileData; - int rawControllerMode; - char muteTrackList[256]; - unsigned char mbuf[MBUFSIZ]; - unsigned char *bufp, *endatp; - int16 datreq, datcnt; - } MGLOBAL; - - typedef struct eventnode { - struct eventnode *nxt; - uint32 start_kcnt; - EVTBLK evt; - } EVTNODE; - - typedef struct { - OPDS h; - MYFLT *ktempo, *istartempo; - MYFLT prvtempo; - } TEMPO; - - typedef struct opcodinfo { - int32 instno; - char *name, *intypes, *outtypes; - int16 inchns, outchns, perf_incnt, perf_outcnt; - int16 *in_ndx_list, *out_ndx_list; - INSTRTXT *ip; - struct opcodinfo *prv; - } OPCODINFO; - - typedef struct polish { - char opcod[12]; - int incount; - char *arg[4]; /* Was [4][12] */ - } POLISH; - - typedef struct token { - char *str; - int16 prec; - } TOKEN; - - typedef struct names { - char *mac; - struct names *next; - } NAMES; - - typedef struct threadInfo { - struct threadInfo *next; - void * threadId; - } THREADINFO; - -#include "sort.h" -#include "text.h" -#include "prototyp.h" -#include "cwindow.h" -#include "envvar.h" -#include "remote.h" - -#define CS_STATE_PRE (1) -#define CS_STATE_COMP (2) -#define CS_STATE_UTIL (4) -#define CS_STATE_CLN (8) -#define CS_STATE_JMP (16) - -/* These are used to set/clear bits in csound->tempStatus. - If the bit is set, it indicates that the given file is - a temporary. */ - extern const uint32_t csOrcMask; - extern const uint32_t csScoInMask; - extern const uint32_t csScoSortMask; - extern const uint32_t csMidiScoMask; - extern const uint32_t csPlayScoMask; - -#endif /* __BUILDING_LIBCSOUND */ - /** - * Contains all function pointers, data, and data pointers required - * to run one instance of Csound. - */ - - - struct CSOUND_ { - /* Csound API function pointers (320 total) */ - int (*GetVersion)(void); - int (*GetAPIVersion)(void); - void *(*GetHostData)(CSOUND *); - void (*SetHostData)(CSOUND *, void *hostData); - CSOUND *(*Create)(void *hostData); - int (*Compile)(CSOUND *, int argc, char **argv); - int (*Perform)(CSOUND *); - int (*PerformKsmps)(CSOUND *); - int (*PerformBuffer)(CSOUND *); - int (*Cleanup)(CSOUND *); - void (*Reset)(CSOUND *); - void (*Destroy)(CSOUND *); - MYFLT (*GetSr)(CSOUND *); - MYFLT (*GetKr)(CSOUND *); - int (*GetKsmps)(CSOUND *); - int (*GetNchnls)(CSOUND *); - int (*GetSampleFormat)(CSOUND *); - int (*GetSampleSize)(CSOUND *); - long (*GetInputBufferSize)(CSOUND *); - long (*GetOutputBufferSize)(CSOUND *); - MYFLT *(*GetInputBuffer)(CSOUND *); - MYFLT *(*GetOutputBuffer)(CSOUND *); - MYFLT *(*GetSpin)(CSOUND *); - MYFLT *(*GetSpout)(CSOUND *); - double (*GetScoreTime)(CSOUND *); - void (*SetMakeXYinCallback)(CSOUND *, - void (*)(CSOUND *, XYINDAT *, MYFLT, MYFLT)); - void (*SetReadXYinCallback)(CSOUND *, void (*)(CSOUND *, XYINDAT *)); - void (*SetKillXYinCallback)(CSOUND *, void (*)(CSOUND *, XYINDAT *)); - int (*IsScorePending)(CSOUND *); - void (*SetScorePending)(CSOUND *, int pending); - MYFLT (*GetScoreOffsetSeconds)(CSOUND *); - void (*SetScoreOffsetSeconds)(CSOUND *, MYFLT offset); - void (*RewindScore)(CSOUND *); - CS_PRINTF2 void (*Message)(CSOUND *, const char *fmt, ...); - CS_PRINTF3 void (*MessageS)(CSOUND *, int attr, const char *fmt, ...); - void (*MessageV)(CSOUND *, int attr, const char *format, va_list args); - void (*DeleteUtilityList)(CSOUND *, char **lst); - void (*DeleteChannelList)(CSOUND *, CsoundChannelListEntry *lst); - void (*SetMessageCallback)(CSOUND *, - void (*csoundMessageCallback)(CSOUND *, - int attr, const char *format, - va_list valist)); - void (*DeleteCfgVarList)(csCfgVariable_t **lst); - int (*GetMessageLevel)(CSOUND *); - void (*SetMessageLevel)(CSOUND *, int messageLevel); - void (*InputMessage)(CSOUND *, const char *message__); - void (*KeyPressed)(CSOUND *, char c__); - void (*SetInputValueCallback)(CSOUND *, - void (*inputValueCalback)(CSOUND *, const char *channelName, - MYFLT *value)); - void (*SetOutputValueCallback)(CSOUND *, - void (*outputValueCalback)(CSOUND *, const char *channelName, - MYFLT value)); - int (*ScoreEvent)(CSOUND *, - char type, const MYFLT *pFields, long numFields); - int (*ScoreEventAbsolute)(CSOUND *, - char type, const MYFLT *pFields, long numFields, double time_ofs); - void (*SetExternalMidiInOpenCallback)(CSOUND *, - int (*func)(CSOUND *, void **, const char *)); - void (*SetExternalMidiReadCallback)(CSOUND *, - int (*func)(CSOUND *, void *, unsigned char *, int)); - void (*SetExternalMidiInCloseCallback)(CSOUND *, - int (*func)(CSOUND *, void *)); - void (*SetExternalMidiOutOpenCallback)(CSOUND *, - int (*func)(CSOUND *, void **, const char *)); - void (*SetExternalMidiWriteCallback)(CSOUND *, - int (*func)(CSOUND *, void *, const unsigned char *, int)); - void (*SetExternalMidiOutCloseCallback)(CSOUND *, - int (*func)(CSOUND *, void *)); - void (*SetExternalMidiErrorStringCallback)(CSOUND *, - const char *(*func)(int)); - int (*SetIsGraphable)(CSOUND *, int isGraphable); - void (*SetMakeGraphCallback)(CSOUND *, - void (*makeGraphCallback)(CSOUND *, WINDAT *p, - const char *name)); - void (*SetDrawGraphCallback)(CSOUND *, - void (*drawGraphCallback)(CSOUND *, WINDAT *p)); - void (*SetKillGraphCallback)(CSOUND *, - void (*killGraphCallback)(CSOUND *, WINDAT *p)); - void (*SetExitGraphCallback)(CSOUND *, int (*exitGraphCallback)(CSOUND *)); - int (*NewOpcodeList)(CSOUND *, opcodeListEntry **); - void (*DisposeOpcodeList)(CSOUND *, opcodeListEntry *); - int (*AppendOpcode)(CSOUND *, const char *opname, int dsblksiz, - int thread, const char *outypes, const char *intypes, - int (*iopadr)(CSOUND *, void *), - int (*kopadr)(CSOUND *, void *), - int (*aopadr)(CSOUND *, void *)); - int (*AppendOpcodes)(CSOUND *, const OENTRY *opcodeList, int n); - int (*OpenLibrary)(void **library, const char *libraryPath); - int (*CloseLibrary)(void *library); - void *(*GetLibrarySymbol)(void *library, const char *procedureName); - int (*CheckEvents)(CSOUND *); - void (*SetYieldCallback)(CSOUND *, int (*yieldCallback)(CSOUND *)); - const char *(*GetEnv)(CSOUND *, const char *name); - char *(*FindInputFile)(CSOUND *, const char *filename, const char *envList); - char *(*FindOutputFile)(CSOUND *, - const char *filename, const char *envList); - void (*SetPlayopenCallback)(CSOUND *, - int (*playopen__)(CSOUND *, const csRtAudioParams *parm)); - void (*SetRtplayCallback)(CSOUND *, - void (*rtplay__)(CSOUND *, const MYFLT *outBuf, int nbytes)); - void (*SetRecopenCallback)(CSOUND *, - int (*recopen__)(CSOUND *, const csRtAudioParams *parm)); - void (*SetRtrecordCallback)(CSOUND *, - int (*rtrecord__)(CSOUND *, MYFLT *inBuf, int nbytes)); - void (*SetRtcloseCallback)(CSOUND *, void (*rtclose__)(CSOUND *)); - void (*AuxAlloc)(CSOUND *, size_t nbytes, AUXCH *auxchp); - void *(*Malloc)(CSOUND *, size_t nbytes); - void *(*Calloc)(CSOUND *, size_t nbytes); - void *(*ReAlloc)(CSOUND *, void *oldp, size_t nbytes); - void (*Free)(CSOUND *, void *ptr); - /* Internal functions that are needed */ - void (*dispset)(CSOUND *, WINDAT *, MYFLT *, int32, char *, int, char *); - void (*display)(CSOUND *, WINDAT *); - int (*dispexit)(CSOUND *); - MYFLT (*intpow)(MYFLT, int32); - MEMFIL *(*ldmemfile)(CSOUND *, const char *); /* use ldmemfile2 instead */ - int32 (*strarg2insno)(CSOUND *, void *p, int is_string); - char *(*strarg2name)(CSOUND *, char *, void *, const char *, int); - int (*hfgens)(CSOUND *, FUNC **, const EVTBLK *, int); - int (*insert_score_event)(CSOUND *, EVTBLK *, double); - int (*FTAlloc)(CSOUND *, int tableNum, int len); - int (*FTDelete)(CSOUND *, int tableNum); - FUNC *(*FTFind)(CSOUND *, MYFLT *argp); - FUNC *(*FTFindP)(CSOUND *, MYFLT *argp); - FUNC *(*FTnp2Find)(CSOUND *, MYFLT *argp); - int (*GetTable)(CSOUND *, MYFLT **tablePtr, int tableNum); - SNDMEMFILE *(*LoadSoundFile)(CSOUND *, const char *, void *); - char *(*getstrformat)(int format); - int (*sfsampsize)(int format); - char *(*type2string)(int type); - void *(*SAsndgetset)(CSOUND *, - char *, void *, MYFLT *, MYFLT *, MYFLT *, int); - void *(*sndgetset)(CSOUND *, void *); - int (*getsndin)(CSOUND *, void *, MYFLT *, int, void *); - void (*rewriteheader)(void *ofd); - int (*Rand31)(int *seedVal); - void (*FDRecord)(CSOUND *, FDCH *fdchp); - void (*FDClose)(CSOUND *, FDCH *fdchp); - void (*SetDebug)(CSOUND *, int d); - int (*GetDebug)(CSOUND *); - int (*TableLength)(CSOUND *, int table); - MYFLT (*TableGet)(CSOUND *, int table, int index); - void (*TableSet)(CSOUND *, int table, int index, MYFLT value); - void *(*CreateThread)(uintptr_t (*threadRoutine)(void *), void *userdata); - uintptr_t (*JoinThread)(void *thread); - void *(*CreateThreadLock)(void); - void (*DestroyThreadLock)(void *lock); - int (*WaitThreadLock)(void *lock, size_t milliseconds); - void (*NotifyThreadLock)(void *lock); - void (*WaitThreadLockNoTimeout)(void *lock); - void (*Sleep)(size_t milliseconds); - void (*InitTimerStruct)(RTCLOCK *); - double (*GetRealTime)(RTCLOCK *); - double (*GetCPUTime)(RTCLOCK *); - uint32_t (*GetRandomSeedFromTime)(void); - void (*SeedRandMT)(CsoundRandMTState *p, - const uint32_t *initKey, uint32_t keyLength); - uint32_t (*RandMT)(CsoundRandMTState *p); - int (*PerformKsmpsAbsolute)(CSOUND *); - char *(*LocalizeString)(const char *); - int (*CreateGlobalVariable)(CSOUND *, const char *name, size_t nbytes); - void *(*QueryGlobalVariable)(CSOUND *, const char *name); - void *(*QueryGlobalVariableNoCheck)(CSOUND *, const char *name); - int (*DestroyGlobalVariable)(CSOUND *, const char *name); - int (*CreateConfigurationVariable)(CSOUND *, const char *name, - void *p, int type, int flags, - void *min, void *max, - const char *shortDesc, - const char *longDesc); - int (*SetConfigurationVariable)(CSOUND *, const char *name, void *value); - int (*ParseConfigurationVariable)(CSOUND *, - const char *name, const char *value); - csCfgVariable_t *(*QueryConfigurationVariable)(CSOUND *, const char *name); - csCfgVariable_t **(*ListConfigurationVariables)(CSOUND *); - int (*DeleteConfigurationVariable)(CSOUND *, const char *name); - const char *(*CfgErrorCodeToString)(int errcode); - int (*GetSizeOfMYFLT)(void); - void **(*GetRtRecordUserData)(CSOUND *); - void **(*GetRtPlayUserData)(CSOUND *); - MYFLT (*GetInverseComplexFFTScale)(CSOUND *, int FFTsize); - MYFLT (*GetInverseRealFFTScale)(CSOUND *, int FFTsize); - void (*ComplexFFT)(CSOUND *, MYFLT *buf, int FFTsize); - void (*InverseComplexFFT)(CSOUND *, MYFLT *buf, int FFTsize); - void (*RealFFT)(CSOUND *, MYFLT *buf, int FFTsize); - void (*InverseRealFFT)(CSOUND *, MYFLT *buf, int FFTsize); - void (*RealFFTMult)(CSOUND *, MYFLT *outbuf, MYFLT *buf1, MYFLT *buf2, - int FFTsize, MYFLT scaleFac); - void (*RealFFTnp2)(CSOUND *, MYFLT *buf, int FFTsize); - void (*InverseRealFFTnp2)(CSOUND *, MYFLT *buf, int FFTsize); - int (*AddUtility)(CSOUND *, const char *name, - int (*UtilFunc)(CSOUND *, int, char **)); - int (*RunUtility)(CSOUND *, const char *name, int argc, char **argv); - char **(*ListUtilities)(CSOUND *); - int (*SetUtilityDescription)(CSOUND *, const char *utilName, - const char *utilDesc); - const char *(*GetUtilityDescription)(CSOUND *, const char *utilName); - int (*RegisterSenseEventCallback)(CSOUND *, void (*func)(CSOUND *, void *), - void *userData); - int (*RegisterDeinitCallback)(CSOUND *, void *p, - int (*func)(CSOUND *, void *)); - int (*RegisterResetCallback)(CSOUND *, void *userData, - int (*func)(CSOUND *, void *)); - void *(*CreateFileHandle)(CSOUND *, void *, int, const char *); - /* Do not use FileOpen in new code; it has been replaced by FileOpen2 */ - void *(*FileOpen)(CSOUND *, - void *, int, const char *, void *, const char *); - char *(*GetFileName)(void *); - int (*FileClose)(CSOUND *, void *); - /* PVOC-EX system */ - int (*PVOC_CreateFile)(CSOUND *, const char *, - uint32, uint32, uint32, - uint32, int32, int, int, - float, float *, uint32); - int (*PVOC_OpenFile)(CSOUND *, const char *, void *, void *); - int (*PVOC_CloseFile)(CSOUND *, int); - int (*PVOC_PutFrames)(CSOUND *, int, const float *, int32); - int (*PVOC_GetFrames)(CSOUND *, int, float *, uint32); - int (*PVOC_FrameCount)(CSOUND *, int); - int (*PVOC_fseek)(CSOUND *, int, int); - const char *(*PVOC_ErrorString)(CSOUND *); - int (*PVOCEX_LoadFile)(CSOUND *, const char *, PVOCEX_MEMFILE *); - char *(*GetOpcodeName)(void *p); - int (*GetInputArgCnt)(void *p); - unsigned long (*GetInputArgAMask)(void *p); - unsigned long (*GetInputArgSMask)(void *p); - char *(*GetInputArgName)(void *p, int n); - int (*GetOutputArgCnt)(void *p); - unsigned long (*GetOutputArgAMask)(void *p); - unsigned long (*GetOutputArgSMask)(void *p); - char *(*GetOutputArgName)(void *p, int n); - int (*SetReleaseLength)(void *p, int n); - MYFLT (*SetReleaseLengthSeconds)(void *p, MYFLT n); - int (*GetMidiChannelNumber)(void *p); - MCHNBLK *(*GetMidiChannel)(void *p); - int (*GetMidiNoteNumber)(void *p); - int (*GetMidiVelocity)(void *p); - int (*GetReleaseFlag)(void *p); - double (*GetOffTime)(void *p); - MYFLT *(*GetPFields)(void *p); - int (*GetInstrumentNumber)(void *p); - CS_NORETURN CS_PRINTF2 void (*Die)(CSOUND *, const char *msg, ...); - CS_PRINTF2 int (*InitError)(CSOUND *, const char *msg, ...); - CS_PRINTF2 int (*PerfError)(CSOUND *, const char *msg, ...); - CS_PRINTF2 void (*Warning)(CSOUND *, const char *msg, ...); - CS_PRINTF2 void (*DebugMsg)(CSOUND *, const char *msg, ...); - CS_NORETURN void (*LongJmp)(CSOUND *, int); - CS_PRINTF2 void (*ErrorMsg)(CSOUND *, const char *fmt, ...); - void (*ErrMsgV)(CSOUND *, const char *hdr, const char *fmt, va_list); - int (*GetChannelPtr)(CSOUND *, MYFLT **p, const char *name, int type); - int (*ListChannels)(CSOUND *, CsoundChannelListEntry **lst); - int (*SetControlChannelParams)(CSOUND *, const char *name, - int type, MYFLT dflt, MYFLT min, MYFLT max); - int (*GetControlChannelParams)(CSOUND *, const char *name, - MYFLT *dflt, MYFLT *min, MYFLT *max); - int (*ChanIKSet)(CSOUND *, MYFLT value, int n); - int (*ChanOKGet)(CSOUND *, MYFLT *value, int n); - int (*ChanIASet)(CSOUND *, const MYFLT *value, int n); - int (*ChanOAGet)(CSOUND *, MYFLT *value, int n); - void (*dispinit)(CSOUND *); - void *(*Create_Mutex)(int isRecursive); - int (*LockMutexNoWait)(void *mutex_); - void (*LockMutex)(void *mutex_); - void (*UnlockMutex)(void *mutex_); - void (*DestroyMutex)(void *mutex_); - long (*RunCommand)(const char * const *argv, int noWait); - void *(*GetCurrentThreadID)(void); - void (*SetChannelIOCallback)(CSOUND *, CsoundChannelIOCallback_t func); - int (*Set_Callback)(CSOUND *, int (*func)(void *, void *, unsigned int), - void *userData, unsigned int typeMask); - void (*Remove_Callback)(CSOUND *, - int (*func)(void *, void *, unsigned int)); - int (*PvsinSet)(CSOUND *, const PVSDATEXT *value, int n); - int (*PvsoutGet)(CSOUND *, PVSDATEXT *value, int n); - void (*SetInternalYieldCallback)(CSOUND *, - int (*yieldCallback)(CSOUND *)); - void *(*CreateBarrier)(unsigned int max); - int (*DestroyBarrier)(void *); - int (*WaitBarrier)(void *); - void *(*FileOpen2)(CSOUND *, void *, int, const char *, void *, - const char *, int, int); - int (*type2csfiletype)(int type, int encoding); - MEMFIL *(*ldmemfile2)(CSOUND *, const char *, int); - void (*NotifyFileOpened)(CSOUND*, const char*, int, int, int); - int (*sftype2csfiletype)(int type); - int (*insert_score_event_at_sample)(CSOUND *, EVTBLK *, long); - int *(*GetChannelLock)(CSOUND *, const char *name, int type); - MEMFIL *(*ldmemfile2withCB)(CSOUND *, const char *, int, - int (*callback)(CSOUND *, MEMFIL *)); - void (*AddSpinSample)(CSOUND *, int, int, MYFLT); - MYFLT (*GetSpoutSample)(CSOUND *, int, int); - int (*ChanIKSetValue)(CSOUND *, int channel, MYFLT value); - MYFLT (*ChanOKGetValue)(CSOUND *, int channel); - int (*ChanIASetSample)(CSOUND *, int channel, int frame, MYFLT sample); - MYFLT (*ChanOAGetSample)(CSOUND *, int channel, int frame); - void (*Stop)(CSOUND *); - void *(*GetNamedGens)(CSOUND *); - /* SUBR dummyfn_1; */ - MYFLT (*Pow2)(CSOUND *, MYFLT a); - SUBR dummyfn_2[75]; - int dither_output; - void *flgraphGlobals; - char *delayederrormessages; - void *printerrormessagesflag; - /* ----------------------- public data fields ----------------------- */ - /** used by init and perf loops */ - OPDS *ids, *pds; - int ksmps, global_ksmps, nchnls, spoutactive; - long kcounter, global_kcounter; - int reinitflag; - int tieflag; - MYFLT esr, onedsr, sicvt; - MYFLT tpidsr, pidsr, mpidsr, mtpdsr; - MYFLT onedksmps; - MYFLT ekr, global_ekr; - MYFLT onedkr; - MYFLT kicvt; - MYFLT e0dbfs, dbfs_to_float; - /** start time of current section */ - double timeOffs, beatOffs; - /** current time in seconds, inc. per kprd */ - int64_t icurTime; /* Current time in samples */ - double curTime_inc; - /** current time in beats, inc per kprd */ - double curBeat, curBeat_inc; - /** beat time = 60 / tempo */ - int64_t ibeatTime; /* Beat time in samples */ -#if defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS) - pthread_spinlock_t spoutlock, spinlock; -#else - int spoutlock, spinlock; -#endif /* defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS) */ - /* Widgets */ - void *widgetGlobals; - /** reserved for std opcode library */ - void *stdOp_Env; - MYFLT *zkstart; - MYFLT *zastart; - long zklast; - long zalast; - MYFLT *spin; - MYFLT *spout; - int nspin; - int nspout; - OPARMS *oparms; - EVTBLK *currevent; - INSDS *curip; - void *hostdata; - void *rtRecord_userdata; - void *rtPlay_userdata; - char *orchname, *scorename; - CORFIL *orchstr, *scorestr; - int holdrand; - /** max. length of string variables + 1 */ - int strVarMaxLen; - int maxinsno; - int strsmax; - char **strsets; - INSTRTXT **instrtxtp; - /** reserve space for up to 4 MIDI devices */ - MCHNBLK *m_chnbp[64]; - RTCLOCK *csRtClock; - CsoundRandMTState *csRandState; - int randSeed1; - int randSeed2; -#if defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS) - pthread_spinlock_t memlock; -#else - int memlock; -#endif /* defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS */ - int floatsize; - int inchnls; /* Not fully used yet -- JPff */ - int dummyint[7]; - long dummyint32[10]; - /* ------- private data (not to be used by hosts or externals) ------- */ -#ifdef __BUILDING_LIBCSOUND - /* callback function pointers */ - SUBR first_callback_; - void (*InputValueCallback_)(CSOUND *, - const char *channelName, MYFLT *value); - void (*OutputValueCallback_)(CSOUND *, - const char *channelName, MYFLT value); - void (*csoundMessageCallback_)(CSOUND *, int attr, - const char *format, va_list args); - int (*csoundConfigureCallback_)(CSOUND *); - void (*csoundMakeGraphCallback_)(CSOUND *, WINDAT *windat, - const char *name); - void (*csoundDrawGraphCallback_)(CSOUND *, WINDAT *windat); - void (*csoundKillGraphCallback_)(CSOUND *, WINDAT *windat); - int (*csoundExitGraphCallback_)(CSOUND *); - int (*csoundYieldCallback_)(CSOUND *); - void (*csoundMakeXYinCallback_)(CSOUND *, XYINDAT *, MYFLT, MYFLT); - void (*csoundReadXYinCallback_)(CSOUND *, XYINDAT *); - void (*csoundKillXYinCallback_)(CSOUND *, XYINDAT *); - void (*cscoreCallback_)(CSOUND *); - void (*FileOpenCallback_)(CSOUND*, const char*, int, int, int); - SUBR last_callback_; - /* these are not saved on RESET */ - int (*playopen_callback)(CSOUND *, const csRtAudioParams *parm); - void (*rtplay_callback)(CSOUND *, const MYFLT *outBuf, int nbytes); - int (*recopen_callback)(CSOUND *, const csRtAudioParams *parm); - int (*rtrecord_callback)(CSOUND *, MYFLT *inBuf, int nbytes); - void (*rtclose_callback)(CSOUND *); - /* end of callbacks */ - int nchanik, nchania, nchanok, nchanoa; - MYFLT *chanik, *chania, *chanok, *chanoa; - MYFLT cpu_power_busy; - char *xfilename; - /* oload.h */ - int16 nlabels; - int16 ngotos; - int peakchunks; - int keep_tmp; - OENTRY *opcodlst; - int *opcode_list; - OENTRY *oplstend; - int maxopcno; - int32 nrecs; - FILE* Linepipe; - int Linefd; - void *csoundCallbacks_; - FILE* scfp; - CORFIL *scstr; - FILE* oscfp; - MYFLT maxamp[MAXCHNLS]; - MYFLT smaxamp[MAXCHNLS]; - MYFLT omaxamp[MAXCHNLS]; - uint32 maxpos[MAXCHNLS], smaxpos[MAXCHNLS], omaxpos[MAXCHNLS]; - FILE* scorein; - FILE* scoreout; - MYFLT *pool; - int *argoffspace; - INSDS *frstoff; - jmp_buf exitjmp; - SRTBLK *frstbp; - int sectcnt; - int inerrcnt, synterrcnt, perferrcnt; - INSTRTXT instxtanchor; - INSDS actanchor; - int32 rngcnt[MAXCHNLS]; - int16 rngflg, multichan; - void *evtFuncChain; - EVTNODE *OrcTrigEvts; /* List of events to be started */ - EVTNODE *freeEvtNodes; - int csoundIsScorePending_; - int64_t advanceCnt; - int initonly; - int evt_poll_cnt; - int evt_poll_maxcnt; - int Mforcdecs, Mxtroffs, MTrkend; - MYFLT tran_sr, tran_kr, tran_ksmps; - MYFLT tran_0dbfs; - int tran_nchnls; - OPCODINFO *opcodeInfo; - void *instrumentNames; - void *strsav_str; - void *strsav_space; - FUNC** flist; - int maxfnum; - GEN *gensub; - int genmax; - int ftldno; - void **namedGlobals; - int namedGlobalsCurrLimit; - int namedGlobalsMaxLimit; - void **cfgVariableDB; - double prvbt, curbt, nxtbt; - double curp2, nxtim; - int64_t cyclesRemaining; - EVTBLK evt; - void *memalloc_db; - MGLOBAL *midiGlobals; - void *envVarDB; - MEMFIL *memfiles; - PVOCEX_MEMFILE *pvx_memfiles; - int FFT_max_size; - void *FFT_table_1; - void *FFT_table_2; - /* statics from twarp.c should be TSEG* */ - void *tseg, *tpsave, *tplim; - /* Statics from express.c */ - int32 polmax; - int32 toklen; - char *tokenstring; - POLISH *polish; - TOKEN *token; - TOKEN *tokend; - TOKEN *tokens; - TOKEN **tokenlist; - int toklength; - int acount, kcount, icount, Bcount, bcount; - char *stringend; - TOKEN **revp, **pushp, **argp, **endlist; - char *assign_outarg; - int argcnt_offs, opcode_is_assign, assign_type; - int strVarSamples; /* number of MYFLT locations for string */ - MYFLT *gbloffbas; /* was static in oload.c */ - void *otranGlobals; - void *rdorchGlobals; - void *sreadGlobals; - void *extractGlobals; - void *oneFileGlobals; - void *lineventGlobals; - void *musmonGlobals; - void *libsndGlobals; - void (*spinrecv)(CSOUND *); - void (*spoutran)(CSOUND *); - int (*audrecv)(CSOUND *, MYFLT *, int); - void (*audtran)(CSOUND *, const MYFLT *, int); - int warped; /* rdscor.c */ - int sstrlen; - char *sstrbuf; - int enableMsgAttr; /* csound.c */ - int sampsNeeded; - MYFLT csoundScoreOffsetSeconds_; - int inChar_; - int isGraphable_; - int delayr_stack_depth; /* ugens6.c */ - void *first_delayr; - void *last_delayr; - int32 revlpsiz[6]; - int32 revlpsum; - double rndfrac; /* aops.c */ - MYFLT *logbase2; - NAMES *omacros, *smacros; - void *namedgen; /* fgens.c */ - void *open_files; /* fileopen.c */ - void *searchPathCache; - void *sndmemfiles; - void *reset_list; - void *pvFileTable; /* pvfileio.c */ - int pvNumFiles; - int pvErrorCode; - /* database for deferred loading of opcode plugin libraries */ - void *pluginOpcodeFiles, *pluginOpcodeDB; - int enableHostImplementedAudioIO; - int hostRequestedBufferSize; - /* engineState is sum of: - * 1 (CS_STATE_PRE): csoundPreCompile was called - * 2 (CS_STATE_COMP): csoundCompile was called - * 4 (CS_STATE_UTIL): csoundRunUtility was called - * 8 (CS_STATE_CLN): csoundCleanup needs to be called - * 16 (CS_STATE_JMP): csoundLongJmp was called - */ - int engineState; - int stdin_assign_flg; - int stdout_assign_flg; - int orcname_mode; /* 0: normal, 1: ignore, 2: fail */ - void *csmodule_db; - char *dl_opcodes_oplibs; - char *SF_csd_licence; - char *SF_id_title; - char *SF_id_copyright; - char *SF_id_software; - char *SF_id_artist; - char *SF_id_comment; - char *SF_id_date; - void *utility_db; - int16 *isintab; /* ugens3.c */ - void *lprdaddr; /* ugens5.c */ - int currentLPCSlot; - int max_lpc_slot; - void *chn_db; - int opcodedirWasOK; - int disable_csd_options; - CsoundRandMTState randState_; - int performState; - int ugens4_rand_16; - int ugens4_rand_15; - void *schedule_kicked; - LBLBLK **lopds; - void *larg; /* this is actually LARGNO* */ - MYFLT *disprep_fftcoefs; - void *winEPS_globals; - OPARMS oparms_; - int32 instxtcount, optxtsize; - int32 poolcount, gblfixed, gblacount, gblscount; - CsoundChannelIOCallback_t channelIOCallback_; - int (*doCsoundCallback)(CSOUND *, void *, unsigned int); - const unsigned char *strhash_tabl_8; - unsigned int (*strHash32)(const char *s); - REMOT_BUF SVrecvbuf; /* RM: rt_evt input Communications buffer */ - void *remoteGlobals; - /* VL: pvs bus */ - int nchanif, nchanof; - char *chanif, *chanof; - /* VL: internal yield callback */ - int (*csoundInternalYieldCallback_)(CSOUND *); - void *multiThreadedBarrier1; - void *multiThreadedBarrier2; - int multiThreadedComplete; - THREADINFO *multiThreadedThreadInfo; - INSDS *multiThreadedStart; - INSDS *multiThreadedEnd; -#ifdef PARCS - char *weight_info; - char *weight_dump; - char *weights; - struct dag_t *multiThreadedDag; - pthread_barrier_t *barrier1; - pthread_barrier_t *barrier2; - /* Statics from cs_par_dispatch; */ - struct global_var_lock_t *global_var_lock_root; - struct global_var_lock_t **global_var_lock_cache; - int global_var_lock_count; - int opcode_weight_cache_ctr; - struct opcode_weight_cache_entry_t - *opcode_weight_cache[OPCODE_WEIGHT_CACHE_SIZE]; - int opcode_weight_have_cache; - struct dag_cache_entry_t *cache[DAG_2_CACHE_SIZE]; - /* statics from cs_par_orc_semantic_analysis */ - struct instr_semantics_t *instCurr; - struct instr_semantics_t *instRoot; - int inInstr; -#endif - uint32_t tempStatus; /* keeps track of which files are temps */ - int orcLineOffset; /* 1 less than 1st orch line in the CSD */ - int scoLineOffset; /* 1 less than 1st score line in the CSD */ - char* csdname; /* original CSD name; do not free() */ - int parserUdoflag; - int parserNamedInstrFlag; - int tran_nchnlsi; - int scnt0; /* Count of extra strings */ - char *sstrbuf0[3]; /* For extra strings in scores */ - int sstrlen0[3]; /* lengths for extra strings */ - int genlabs; /* Count for generated labels */ - MYFLT *powerof2; /* pow2 table */ - MYFLT *cpsocfrc; /* cps conv table */ - CORFIL* expanded_orc; /* output of preprocessor */ - char *filedir[64]; /* for location directory */ -#endif /* __BUILDING_LIBCSOUND */ - }; - -/* - * Move the C++ guards to enclose the entire file, - * in order to enable C++ to #include this file. - */ - -#define LINKAGE1(name) \ -long name##_init(CSOUND *csound, OENTRY **ep) \ -{ (void) csound; *ep = name; return (long) (sizeof(name)); } - -#define FLINKAGE1(name) \ -NGFENS* name##_init(CSOUND *csound) \ -{ (void) csound; return name; } - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* CSOUNDCORE_H */ diff -Nru csound-5.17.11~dfsg/H/csound_orc.h csound-6.02~dfsg/H/csound_orc.h --- csound-5.17.11~dfsg/H/csound_orc.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/csound_orc.h 2014-01-07 16:53:47.000000000 +0000 @@ -1,18 +1,11 @@ #ifndef __CSOUND_ORC_H #define __CSOUND_ORC_H + +#define YYDEBUG 1 + +#include "parse_param.h" #include "tok.h" -typedef struct TREE { - int type; - ORCTOKEN *value; - int rate; - int len; - int line; - int locn; - struct TREE *left; - struct TREE *right; - struct TREE *next; -} TREE; #include "csound_orcparse.h" #include "csoundCore.h" @@ -21,7 +14,15 @@ S_APPLY, }; -#define YYDEBUG 1 +typedef struct type_table { + OENTRY* udos; + CS_VAR_POOL* globalPool; + CS_VAR_POOL* instr0LocalPool; + CS_VAR_POOL* localPool; + CONS_CELL* labelList; +} TYPE_TABLE; + + #ifndef PARSER_DEBUG #define PARSER_DEBUG (0) #endif @@ -40,4 +41,6 @@ /*void start_instr(int);*/ /* extern double sr, kr; extern int ksmps, nchnls; */ + +void query_deprecated_opcode(CSOUND *, ORCTOKEN *); #endif diff -Nru csound-5.17.11~dfsg/H/csound_orc_expressions.h csound-6.02~dfsg/H/csound_orc_expressions.h --- csound-5.17.11~dfsg/H/csound_orc_expressions.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/H/csound_orc_expressions.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,43 @@ +/* + csound_orc_expressions.h: + + Copyright (C) 2013 + Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + */ + +#ifndef CSOUND_ORC_EXPRESSION_H +#define CSOUND_ORC_EXPRESSION_H 1 + +#include "csound_orc.h" + +CONS_CELL* cs_cons(CSOUND* csound, void* val, CONS_CELL* cons); +CONS_CELL* cs_cons_append(CONS_CELL* cons1, CONS_CELL* cons2); + +int is_expression_node(TREE *node); +int is_boolean_expression_node(TREE *node); +int is_statement_expansion_required(TREE* root); + +void handle_optional_args(CSOUND *csound, TREE *l); + +TREE* expand_if_statement(CSOUND* csound, TREE* current, TYPE_TABLE* typeTable); +TREE* expand_until_statement(CSOUND* csound, TREE* current, TYPE_TABLE* typeTable); +TREE* expand_statement(CSOUND* csound, TREE* current, TYPE_TABLE* typeTable); + +#endif \ No newline at end of file diff -Nru csound-5.17.11~dfsg/H/csound_orc_semantics.h csound-6.02~dfsg/H/csound_orc_semantics.h --- csound-5.17.11~dfsg/H/csound_orc_semantics.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/H/csound_orc_semantics.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,23 @@ +#ifndef CSOUND_ORC_SEMANTICS_H +#define CSOUND_ORC_SEMANTICS_H + +#include "csoundCore.h" +#include "csound_orc.h" + +/** Gets short version of opcode name, trimming off anything after '.'. + If opname has no '.' in name, simply returns the opname pointer. + If the name is truncated, caller is responsible for calling mfree + on returned value. Caller should compare the returned value with the + passed in opname to see if it is different and thus requires mfree'ing. */ +char* get_opcode_short_name(CSOUND* csound, char* opname); + +PUBLIC OENTRY* find_opcode_new(CSOUND* csound, char* opname, + char* outArgsFound, char* inArgsFound); + +/* find OENTRY with the specified name in opcode list */ + +OENTRY* find_opcode(CSOUND *, char *); +char* get_arg_type2(CSOUND* csound, TREE* tree, TYPE_TABLE* typeTable); + +#endif + diff -Nru csound-5.17.11~dfsg/H/cwindow.h csound-6.02~dfsg/H/cwindow.h --- csound-5.17.11~dfsg/H/cwindow.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/cwindow.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,92 +0,0 @@ -/* - cwindow.h: - - Copyright (C) 1990 Dan Ellis - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CWINDOW_H -#define CWINDOW_H - -/*******************************************************\ -* cwindow.h * -* portable window graphs stolen from Csound * -* necessary header declarations * -* 08nov90 dpwe * -\*******************************************************/ - -#include "csound.h" - -#define CAPSIZE 60 - -struct windat_ { - uintptr_t windid; /* set by MakeGraph() */ - MYFLT *fdata; /* data passed to DrawGraph */ - int32 npts; /* size of above array */ - char caption[CAPSIZE]; /* caption string for graph */ - int16 waitflg; /* set =1 to wait for ms after Draw */ - int16 polarity; /* controls positioning of X axis */ - MYFLT max, min; /* workspace .. extrema this frame */ - MYFLT absmax; /* workspace .. largest of above */ - MYFLT oabsmax; /* Y axis scaling factor */ - int danflag; /* set to 1 for extra Yaxis mid span */ -}; - -enum { /* symbols for WINDAT.polarity field */ - NOPOL, - NEGPOL, - POSPOL, - BIPOL -}; - -struct xyindat_ { /* for 'joystick' input window */ - uintptr_t windid; /* xwindow handle */ - int m_x,m_y; /* current crosshair pixel adr */ - MYFLT x,y; /* current proportions of fsd */ - int down; -}; - - /* ------------------------------------------------------------------------ */ - -#ifdef __BUILDING_LIBCSOUND - -void dispset(CSOUND *, WINDAT *, MYFLT *, int32, char *, int, char *); -int dispexit(CSOUND *); -void display(CSOUND *, WINDAT*); -#if 0 -/* create window for a graph */ -void MakeGraph(CSOUND *, WINDAT *, const char *); -/* create a mouse input window; init scale */ -void MakeXYin(CSOUND *, XYINDAT *, MYFLT, MYFLT); -/* update graph in existing window */ -void DrawGraph(CSOUND *, WINDAT *); -/* fetch latest value from mouse input window */ -void ReadXYin(CSOUND *, XYINDAT *); -/* remove a graph window */ -void KillGraph(CSOUND *, WINDAT *); -/* remove a mouse input window */ -void KillXYin(CSOUND *, XYINDAT *); -/* print click-Exit message in most recently active window */ -int ExitGraph(CSOUND *); -#endif - -#endif /* __BUILDING_LIBCSOUND */ - -#endif /* CWINDOW_H */ - diff -Nru csound-5.17.11~dfsg/H/diskin.h csound-6.02~dfsg/H/diskin.h --- csound-5.17.11~dfsg/H/diskin.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/diskin.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,79 +0,0 @@ -/* - diskin.h: - - Copyright (C) 1998, 2001 matt ingalls, Richard Dobson, John ffitch - (C) 2005 Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_DISKIN_H -#define CSOUND_DISKIN_H - -#include "diskin2.h" - -typedef struct { - OPDS h; - MYFLT *aOut[DISKIN2_MAXCHN]; - MYFLT *iFileCode; - MYFLT *kTranspose; - MYFLT *iSkipTime; - MYFLT *iWrapMode; - MYFLT *iSampleFormat; - MYFLT *iSkipInit; - MYFLT *ibufsize; - /* ------------------------------------- */ - int initDone; - int nChannels; - int bufSize; /* in sample frames, power of two */ - int wrapMode; - int32 fileLength; /* in sample frames */ - int32 bufStartPos; - int64_t pos_frac; /* type should be defined in sysdep.h */ - int64_t pos_frac_inc; - SNDFILE *sf; - MYFLT prv_kTranspose; - MYFLT scaleFac; - float *buf; /* variable */ - AUXCH auxch; - FDCH fdch; -} SOUNDINEW; - -#define SNDOUTSMPS (1024) - -typedef struct { - SNDFILE *sf; - void *fd; - MYFLT *outbufp, *bufend; - MYFLT outbuf[SNDOUTSMPS]; -} SNDCOM; - -typedef struct { - OPDS h; - MYFLT *asig, *ifilcod, *iformat; - SNDCOM c; -} SNDOUT; - -typedef struct { - OPDS h; - MYFLT *asig1, *asig2, *ifilcod, *iformat; - SNDCOM c; -} SNDOUTS; - -#endif /* CSOUND_DISKIN_H */ - diff -Nru csound-5.17.11~dfsg/H/diskin2.h csound-6.02~dfsg/H/diskin2.h --- csound-5.17.11~dfsg/H/diskin2.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/diskin2.h 2014-01-07 16:54:20.000000000 +0000 @@ -42,7 +42,13 @@ MYFLT *iWinSize; MYFLT *iBufSize; MYFLT *iSkipInit; + MYFLT *forceSync; /* ------------------------------------- */ + MYFLT WinSize; + MYFLT BufSize; + MYFLT SkipInit; + MYFLT fforceSync; + int initDone; int nChannels; int bufSize; /* in sample frames, power of two */ @@ -61,10 +67,63 @@ SNDFILE *sf; FDCH fdch; AUXCH auxData; /* for dynamically allocated buffers */ + AUXCH auxData2; + MYFLT *aOut_buf; + MYFLT aOut_bufsize; + void *cb; + int async; } DISKIN2; +typedef struct { + OPDS h; + ARRAYDAT *aOut; + MYFLT *iFileCode; + MYFLT *kTranspose; + MYFLT *iSkipTime; + MYFLT *iWrapMode; + MYFLT *iSampleFormat; + MYFLT *iWinSize; + MYFLT *iBufSize; + MYFLT *iSkipInit; + MYFLT *forceSync; + /* ------------------------------------- */ + MYFLT WinSize; + MYFLT BufSize; + MYFLT SkipInit; + MYFLT fforceSync; + int initDone; + int nChannels; + int bufSize; /* in sample frames, power of two */ + int wrapMode; + int32 fileLength; /* in sample frames */ + int32 bufStartPos; + int64_t pos_frac; /* type should be defined in sysdep.h */ + int64_t pos_frac_inc; + int32 prvBufStartPos; + int32 winSize; + MYFLT *buf; + MYFLT *prvBuf; + MYFLT prv_kTranspose; + MYFLT winFact; + double warpScale; + SNDFILE *sf; + FDCH fdch; + AUXCH auxData; /* for dynamically allocated buffers */ + AUXCH auxData2; + MYFLT *aOut_buf; + MYFLT aOut_bufsize; + void *cb; + int async; +} DISKIN2_ARRAY; + int diskin2_init(CSOUND *csound, DISKIN2 *p); +int diskin2_init_S(CSOUND *csound, DISKIN2 *p); int diskin2_perf(CSOUND *csound, DISKIN2 *p); +int diskin2_init_array_I(CSOUND *csound, DISKIN2_ARRAY *p); +int diskin2_init_array_S(CSOUND *csound, DISKIN2_ARRAY *p); +int diskin_init_array_I(CSOUND *csound, DISKIN2_ARRAY *p); +int diskin_init_array_S(CSOUND *csound, DISKIN2_ARRAY *p); +int diskin2_perf_array(CSOUND *csound, DISKIN2_ARRAY *p); typedef struct { OPDS h; @@ -82,5 +141,25 @@ AUXCH auxData; /* for dynamically allocated buffers */ } SOUNDIN_; -#endif /* CSOUND_DISKIN2_H */ +#define SNDOUTSMPS (1024) + +typedef struct { + SNDFILE *sf; + void *fd; + MYFLT *outbufp, *bufend; + MYFLT outbuf[SNDOUTSMPS]; +} SNDCOM; + +typedef struct { + OPDS h; + MYFLT *asig, *ifilcod, *iformat; + SNDCOM c; +} SNDOUT; +typedef struct { + OPDS h; + MYFLT *asig1, *asig2, *ifilcod, *iformat; + SNDCOM c; +} SNDOUTS; + +#endif /* CSOUND_DISKIN2_H */ diff -Nru csound-5.17.11~dfsg/H/dumpf.h csound-6.02~dfsg/H/dumpf.h --- csound-5.17.11~dfsg/H/dumpf.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/dumpf.h 2014-01-07 16:53:47.000000000 +0000 @@ -104,7 +104,8 @@ typedef struct { OPDS h; - MYFLT *str, *ifilcod, *iprd; + STRINGDAT *str; + MYFLT *ifilcod, *iprd; int32 countdown, timcount; char *lasts; FILE *f; diff -Nru csound-5.17.11~dfsg/H/entry1.h csound-6.02~dfsg/H/entry1.h --- csound-5.17.11~dfsg/H/entry1.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/entry1.h 2014-01-07 16:54:20.000000000 +0000 @@ -1,5 +1,5 @@ /* - entry1.h: + entry1.h: Copyright (C) 1991 Barry Vercoe, John ffitch @@ -37,7 +37,6 @@ #include "soundio.h" #include "dumpf.h" #include "cmath.h" -#include "diskin.h" #include "diskin2.h" #include "oload.h" #include "midiout.h" @@ -56,9 +55,9 @@ #include "pstream.h" #include "remote.h" #include "resize.h" -#ifdef PARCS #include "cs_par_ops.h" -#endif +#include "ugtabs.h" +#include "compile_ops.h" #define S(x) sizeof(x) @@ -67,8 +66,8 @@ int aassign(CSOUND *, void *); int init(CSOUND *, void *), ainit(CSOUND *, void *); int minit(CSOUND *, void *), mainit(CSOUND *, void *); -int tinit(CSOUND *, void *), tassign(CSOUND *, void *); -int tabref_check(CSOUND *, void *), tabref(CSOUND *, void *); +/* int tinit(CSOUND *, void *), tassign(CSOUND *, void *); */ +/* int tabref_check(CSOUND *, void *), tabref(CSOUND *, void *); */ int gt(CSOUND *, void *), ge(CSOUND *, void *); int lt(CSOUND *, void *), le(CSOUND *, void *); int eq(CSOUND *, void *), ne(CSOUND *, void *); @@ -102,7 +101,7 @@ int tan1(CSOUND *, void *), asin1(CSOUND *, void *); int acos1(CSOUND *, void *), atan1(CSOUND *, void *); int sinh1(CSOUND *, void *), cosh1(CSOUND *, void *); -int tanh1(CSOUND *, void *), log101(CSOUND *, void *); +int tanh1(CSOUND *, void *), log101(CSOUND *, void *), log21(CSOUND *, void *); int atan21(CSOUND *, void *), atan2aa(CSOUND *, void *); int absa(CSOUND *, void *), expa(CSOUND *, void *); int loga(CSOUND *, void *), sqrta(CSOUND *, void *); @@ -110,18 +109,20 @@ int tana(CSOUND *, void *), asina(CSOUND *, void *); int acosa(CSOUND *, void *), atana(CSOUND *, void *); int sinha(CSOUND *, void *), cosha(CSOUND *, void *); -int tanha(CSOUND *, void *), log10a(CSOUND *, void *); +int tanha(CSOUND *, void *), log10a(CSOUND *, void *), log2a(CSOUND *, void *); int dbamp(CSOUND *, void *), ampdb(CSOUND *, void *); int aampdb(CSOUND *, void *), dbfsamp(CSOUND *, void *); int ampdbfs(CSOUND *, void *), aampdbfs(CSOUND *, void *); int ftlen(CSOUND *, void *), ftlptim(CSOUND *, void *); -int ftchnls(CSOUND *, void *), ftcps(CSOUND *, void *), rtclock(CSOUND *, void *); +int ftchnls(CSOUND *, void *), ftcps(CSOUND *, void *); +int signum(CSOUND *, void *), asignum(CSOUND *, void *); +int rtclock(CSOUND *, void *); int cpsoct(CSOUND *, void *), octpch(CSOUND *, void *); int cpspch(CSOUND *, void *), pchoct(CSOUND *, void *); int octcps(CSOUND *, void *), acpsoct(CSOUND *, void *); int cpsmidinn(CSOUND *, void *), octmidinn(CSOUND *, void *); -int pchmidinn(CSOUND *, void *); -int massign(CSOUND *, void *), ctrlinit(CSOUND *, void *); +int pchmidinn(CSOUND *, void *);int massign_S(CSOUND *, void *); +int massign_p(CSOUND *, void *), ctrlinit(CSOUND *, void *); int notnum(CSOUND *, void *), veloc(CSOUND *, void *); int pchmidi(CSOUND *, void *), pchmidib(CSOUND *, void *); int octmidi(CSOUND *, void *), octmidib(CSOUND *, void *); @@ -139,6 +140,7 @@ int midictl(CSOUND *, void *), imidiaft(CSOUND *, void *); int maftset(CSOUND *, void *), midiaft(CSOUND *, void *); int midiout(CSOUND *, void *), turnon(CSOUND *, void *); +int turnon_S(CSOUND *, void *); int kmapset(CSOUND *, void *), polyaft(CSOUND *, void *); int ichanctl(CSOUND *, void *), chctlset(CSOUND *, void *); int chanctl(CSOUND *, void *), linset(CSOUND *, void *); @@ -146,6 +148,10 @@ int expset(CSOUND *, void *), kexpon(CSOUND *, void *); int expon(CSOUND *, void *), lsgset(CSOUND *, void *); int klnseg(CSOUND *, void *), linseg(CSOUND *, void *); +int csgset(CSOUND *, void *), kosseg(CSOUND *, void *); +int csgset_bkpt(CSOUND *, void *), cosseg(CSOUND *, void *); +int csgrset(CSOUND *, void *); +int kcssegr(CSOUND *, void *), cossegr(CSOUND *, void *); int madsrset(CSOUND *, void *), adsrset(CSOUND *, void *); int xdsrset(CSOUND *, void *), mxdsrset(CSOUND *, void *); int expseg2(CSOUND *, void *), xsgset(CSOUND *, void *); @@ -182,6 +188,7 @@ int kosc1(CSOUND *, void *), kosc1i(CSOUND *, void *); int oscnset(CSOUND *, void *), osciln(CSOUND *, void *); int oscset(CSOUND *, void *), koscil(CSOUND *, void *); +int oscsetA(CSOUND *, void *); int osckk(CSOUND *, void *), oscka(CSOUND *, void *); int oscak(CSOUND *, void *), oscaa(CSOUND *, void *); int koscli(CSOUND *, void *), osckki(CSOUND *, void *); @@ -220,13 +227,15 @@ int lpinterpol(CSOUND *, void *); int rmsset(CSOUND *, void *), rms(CSOUND *, void *); int gainset(CSOUND *, void *), gain(CSOUND *, void *); -int sndinset(CSOUND *, void *), soundin(CSOUND *, void *); -int sndo1set(CSOUND *, void *), soundout(CSOUND *, void *); -int soundouts(CSOUND *, void *); +int sndinset(CSOUND *, void *), sndinset_S(CSOUND *, void *), + soundin(CSOUND *, void *); +int sndoutset(CSOUND *, void *), sndoutset_S(CSOUND *, void *), + soundout(CSOUND *, void *); +int soundouts(CSOUND *, void *), inarray(CSOUND *, void *); int in(CSOUND *, void *), ins(CSOUND *, void *); int inq(CSOUND *, void *), inh(CSOUND *, void *); int ino(CSOUND *, void *), in16(CSOUND *, void *); -int in32(CSOUND *, void *); +int in32(CSOUND *, void *), outarr(CSOUND *, void *); int inch_opcode(CSOUND *, void *), inall_opcode(CSOUND *, void *); int outmultiple(CSOUND *, void *); /* int out(CSOUND *, void *), outs(CSOUND *, void *); */ @@ -247,20 +256,25 @@ int fdspset(CSOUND *, void *), fdsplay(CSOUND *, void *); int dsplay(CSOUND *, void *), fftset(CSOUND *, void *); int kdspfft(CSOUND *, void *), dspfft(CSOUND *, void *); -int xyinset(CSOUND *, void *), xyin(CSOUND *, void *); +int xyinset(CSOUND *, void *); int tempeset(CSOUND *, void *), tempest(CSOUND *, void *); int tempset(CSOUND *, void *), tempo(CSOUND *, void *); int old_kdmpset(CSOUND *, void *), old_kdmp2set(CSOUND *, void *); int old_kdmp3set(CSOUND *, void *), old_kdmp4set(CSOUND *, void *); -int kdmpset(CSOUND *, void *), kdmp2set(CSOUND *, void *); -int kdmp3set(CSOUND *, void *), kdmp4set(CSOUND *, void *); +int kdmpset_p(CSOUND *, void *), kdmp2set_p(CSOUND *, void *); +int kdmp3set_p(CSOUND *, void *), kdmp4set_p(CSOUND *, void *); +int kdmpset_S(CSOUND *, void *), kdmp2set_S(CSOUND *, void *); +int kdmp3set_S(CSOUND *, void *), kdmp4set_S(CSOUND *, void *); int kdump(CSOUND *, void *), kdump2(CSOUND *, void *); int kdump3(CSOUND *, void *), kdump4(CSOUND *, void *); -int krdset(CSOUND *, void *), krd2set(CSOUND *, void *); -int krd3set(CSOUND *, void *), krd4set(CSOUND *, void *); +int krdset_S(CSOUND *, void *), krd2set_S(CSOUND *, void *); +int krd3set_S(CSOUND *, void *), krd4set_S(CSOUND *, void *); +int krdset_p(CSOUND *, void *), krd2set_p(CSOUND *, void *); +int krd3set_p(CSOUND *, void *), krd4set_p(CSOUND *, void *); int kread(CSOUND *, void *), kread2(CSOUND *, void *); int kread3(CSOUND *, void *), kread4(CSOUND *, void *); -int krdsset(CSOUND *, void *), kreads(CSOUND *, void *); +int krdsset_S(CSOUND *, void *),krdsset_p(CSOUND *, void *), + kreads(CSOUND *, void *); int ipow(CSOUND *, void *), apow(CSOUND *, void *); int alinear(CSOUND *, void *), iklinear(CSOUND *, void *); int atrian(CSOUND *, void *), iktrian(CSOUND *, void *); @@ -309,6 +323,9 @@ int filelen(CSOUND *, void *), filenchnls(CSOUND *, void *); int filesr(CSOUND *, void *), filepeak(CSOUND *, void *); int filevalid(CSOUND *, void *); +int filelen_S(CSOUND *, void *), filenchnls_S(CSOUND *, void *); +int filesr_S(CSOUND *, void *), filepeak_S(CSOUND *, void *); +int filevalid_S(CSOUND *, void *); int ilogbasetwo(CSOUND *, void *), logbasetwo_set(CSOUND *, void *); int powoftwo(CSOUND *, void *), powoftwoa(CSOUND *, void *); int logbasetwo(CSOUND *, void *), logbasetwoa(CSOUND *, void *); @@ -316,7 +333,8 @@ int phaser2set(CSOUND *, void *), phaser2(CSOUND *, void *); int phaser1set(CSOUND *, void *), phaser1(CSOUND *, void *); int balnset(CSOUND *, void *), balance(CSOUND *, void *); -int prealloc(CSOUND *, void *), active_alloc(CSOUND*, void*); +int prealloc(CSOUND *, void *); +int prealloc_S(CSOUND *, void *), active_alloc(CSOUND*, void*); int cpsxpch(CSOUND *, void *), cps2pch(CSOUND *, void *); int cpstmid(CSOUND *, void *); int cpstun(CSOUND *, void *), cpstun_i(CSOUND *, void *); @@ -326,11 +344,15 @@ int fluteset(CSOUND *, void *), flute(CSOUND *, void *); int bowedset(CSOUND *, void *), bowed(CSOUND *, void *); int brassset(CSOUND *, void *), brass(CSOUND *, void *); -int schedule(CSOUND *, void *), schedwatch(CSOUND *, void *); +int schedule(CSOUND *, void *), schedule_S(CSOUND *, void *); int ifschedule(CSOUND *, void *), kschedule(CSOUND *, void *); int triginset(CSOUND *, void *), ktriginstr(CSOUND *, void *); +int triginset_S(CSOUND *, void *), ktriginstr_S(CSOUND *, void *); int trigseq_set(CSOUND *, void *), trigseq(CSOUND *, void *); int eventOpcode(CSOUND *, void *), eventOpcodeI(CSOUND *, void *); +int eventOpcode_S(CSOUND *, void *), eventOpcodeI_S(CSOUND *, void *); +int instanceOpcode(CSOUND *, void *), instanceOpcode_S(CSOUND *, void *); +int kill_instance(CSOUND *csound, void *p); int lfoset(CSOUND *, void *); int lfok(CSOUND *, void *), lfoa(CSOUND *, void *); int mute_inst(CSOUND *, void *); @@ -359,7 +381,8 @@ int db(CSOUND *, void *), dba(CSOUND *, void *); int semitone(CSOUND *, void *), asemitone(CSOUND *, void *); int cent(CSOUND *, void *), acent(CSOUND *, void *); -int midichn(CSOUND *, void *), pgmassign(CSOUND *, void *); +int midichn(CSOUND *, void *), pgmassign(CSOUND *, void *), + pgmassign_S(CSOUND *, void *); int midiin_set(CSOUND *, void *), midiin(CSOUND *, void *); int pgmin_set(CSOUND *, void *), pgmin(CSOUND *, void *); int ctlin_set(CSOUND *, void *), ctlin(CSOUND *, void *); @@ -371,16 +394,16 @@ int midichannelaftertouch(CSOUND *, void *); int midipitchbend(CSOUND *, void *); int mididefault(CSOUND *, void *); -int invalset(CSOUND *, void *), kinval(CSOUND *, void *); -int invalset_S(CSOUND *, void *), kinval_S(CSOUND *, void *); -int outvalset(CSOUND *, void *), koutval(CSOUND *, void *); +int subinstrset_S(CSOUND *, void *); int subinstrset(CSOUND *, void *), subinstr(CSOUND *, void *); int useropcdset(CSOUND *, void *), useropcd(CSOUND *, void *); int setksmpsset(CSOUND *, void *); int xinset(CSOUND *, void *), xoutset(CSOUND *, void *); int ingoto(CSOUND *, void *), kngoto(CSOUND *, void *); int iingoto(CSOUND *, void *), kingoto(CSOUND *, void *); -int nstrnumset(CSOUND *, void *), turnoff2k(CSOUND *, void *), turnoff2S(CSOUND *, void *) ; +int nstrnumset(CSOUND *, void *), turnoff2k(CSOUND *, void *); +int nstrnumset_S(CSOUND *, void *); +int turnoff2S(CSOUND *, void *) ; int loop_l_i(CSOUND *, void *), loop_le_i(CSOUND *, void *); int loop_g_i(CSOUND *, void *), loop_ge_i(CSOUND *, void *); int loop_l_p(CSOUND *, void *), loop_le_p(CSOUND *, void *); @@ -391,7 +414,7 @@ int remoteport(CSOUND *, void *); int globallock(CSOUND *, void *); int globalunlock(CSOUND *, void *); -int filebit(CSOUND *, void *); +int filebit(CSOUND *, void *); int filebit_S(CSOUND *, void *); int iexprndi(CSOUND *, void *), exprndiset(CSOUND *, void *); int kexprndi(CSOUND *, void *), aexprndi(CSOUND *, void *); int icauchyi(CSOUND *, void *), cauchyiset(CSOUND *, void *); @@ -403,3 +426,41 @@ int xsgset_bkpt(CSOUND *csound, void *p), xsgset2b(CSOUND *, void *); int resize_table(CSOUND *csound, void *p); int error_fn(CSOUND *csound, void *p); +int fassign_set(CSOUND *csound, FASSIGN *p); +int tabler_init(CSOUND *csound, TABL *p); +int tabl_setup(CSOUND *csound, TABL *p); +int tabler_kontrol(CSOUND *csound, TABL *p); +int tabler_audio(CSOUND *csound, TABL *p); +int tableir_init(CSOUND *csound, TABL *p); +int tableir_audio(CSOUND *csound, TABL *p); +int tableir_kontrol(CSOUND *csound, TABL *p); +int tableir_audio(CSOUND *csound, TABL *p); +int table3r_init(CSOUND *csound, TABL *p); +int table3r_kontrol(CSOUND *csound, TABL *p); +int table3r_audio(CSOUND *csound, TABL *p); +int tablerkt_kontrol(CSOUND *csound, TABL *p); +int tablerkt_audio(CSOUND *csound, TABL *p); +int tableirkt_kontrol(CSOUND *csound, TABL *p); + int tableirkt_audio(CSOUND *csound, TABL *p); +int table3rkt_kontrol(CSOUND *csound, TABL *p); +int table3rkt_audio(CSOUND *csound, TABL *p); +int tablew_init(CSOUND *csound, TABL *p); +int tablew_kontrol(CSOUND *csound, TABL *p); +int tablew_audio(CSOUND *csound, TABL *p); +int tablewkt_kontrol(CSOUND *csound, TABL *p); +int tablewkt_audio(CSOUND *csound, TABL *p); +int table_length(CSOUND *csound, TLEN *p); +int table_gpw(CSOUND *csound, TGP *p); +int table_copy(CSOUND *csound, TGP *p); +int table_mix(CSOUND *csound, TABLMIX *p); +int table_ra_set(CSOUND *csound, TABLRA *p); +int table_ra(CSOUND *csound, TABLRA *p); +int table_wa_set(CSOUND *csound, TABLWA *p); +int table_wa(CSOUND *csound, TABLWA *p); +int tablkt_setup(CSOUND *csound, TABL *p); +int diskin_init(CSOUND *csound, DISKIN2 *p); +int diskin_init_S(CSOUND *csound, DISKIN2 *p); +int inch_opcode1(CSOUND *csound, INCH1 *p); +int adset_S(CSOUND *csound, void *p); +int lprdset_S(CSOUND *csound, void *p); +int pvsfreadset_S(CSOUND *csound, void *p); diff -Nru csound-5.17.11~dfsg/H/envvar.h csound-6.02~dfsg/H/envvar.h --- csound-5.17.11~dfsg/H/envvar.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/envvar.h 2014-01-07 16:53:47.000000000 +0000 @@ -157,9 +157,6 @@ /** * Open a file and return handle. * - * This function has been replaced by csoundFileOpenWithType(). - * Please do not use it in new code. - * * CSOUND *csound: * Csound instance pointer * void *fd: @@ -187,27 +184,15 @@ * list of environment variables for search path (see csoundFindInputFile() * for details); if NULL, the specified name is used as it is, without any * conversion or search. - * return value: - * opaque handle to the opened file, for use with csoundGetFileName() or - * csoundFileClose(), or storing in FDCH.fd. - * On failure, NULL is returned. - */ - void *csoundFileOpen(CSOUND *csound, void *fd, int type, - const char *name, void *param, const char *env); - - /** - * Open a file and return handle. - * - * Same as csoundFileOpen() with two additional parameters describing the - * type of file being opened and whether it is a temporary file. This - * function replaces csoundFileOpen(). This additional information is - * used as metadata to be passed to the host application's FileOpenCallback. - * * int csFileType: * A value from the enumeration CSOUND_FILETYPES (see CsoundCore.h) * int isTemporary: * 1 if this file will be deleted when Csound is finished. * Otherwise, 0. + * return value: + * opaque handle to the opened file, for use with csoundGetFileName() or + * csoundFileClose(), or storing in FDCH.fd. + * On failure, NULL is returned. */ void *csoundFileOpenWithType(CSOUND *csound, void *fd, int type, const char *name, void *param, const char *env, @@ -217,9 +202,9 @@ * Allocate a file handle for an existing file already opened with open(), * fopen(), or sf_open(), for later use with csoundFileClose() or * csoundGetFileName(), or storing in an FDCH structure. - * Files registered this way (or opened with csoundFileOpen()) are also + * Files registered this way are also * automatically closed by csoundReset(). - * Parameters and return value are similar to csoundFileOpen(), except + * Parameters and return value are similar to csoundFileOpenithType(), except * fullName is the name that will be returned by a later call to * csoundGetFileName(). */ @@ -242,9 +227,23 @@ char *csoundGetDirectoryForPath(CSOUND* csound, const char * path); + void *csoundFileOpenWithType_Async(CSOUND *csound, void *fd, int type, + const char *name, void *param, + const char *env, + int csFileType, int buffsize, + int isTemporary); + + unsigned int csoundReadAsync(CSOUND *csound, void *handle, + MYFLT *buf, int items); + + unsigned int csoundWriteAsync(CSOUND *csound, void *handle, + MYFLT *buf, int items); + + int csoundFSeekAsync(CSOUND *csound, void *handle, int pos, int whence); + + #ifdef __cplusplus } #endif #endif /* CSOUND_ENVVAR_H */ - diff -Nru csound-5.17.11~dfsg/H/extract.h csound-6.02~dfsg/H/extract.h --- csound-5.17.11~dfsg/H/extract.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/H/extract.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,48 @@ +/* + extract.h: + + Copyright (C) 2013 Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + */ + +#ifndef EXTRACT_H +#define EXTRACT_H + +#define INSMAX 4096 + +typedef struct extractStatics__ { + char inslst[INSMAX]; /* values set by readxfil */ + int sectno, a0done; + int onsect, offsect; /* " " " */ + MYFLT onbeat, offbeat; /* " " " */ + MYFLT ontime, offtime; /* set by readxfil, mod by w-stmnt */ + SRTBLK *frstout, *prvout; /* links for building new outlist */ + SRTBLK a0; + SRTBLK f0; + SRTBLK e; +} EXTRACT_STATICS; + +/* read the extract control file */ +void readxfil(CSOUND *csound, EXTRACT_STATICS* extractStatics, FILE *xfp); + +/* extract instr events within the time period */ +void extract(CSOUND *csound, EXTRACT_STATICS* extractStatics); + + +#endif \ No newline at end of file diff -Nru csound-5.17.11~dfsg/H/float-version-double.h csound-6.02~dfsg/H/float-version-double.h --- csound-5.17.11~dfsg/H/float-version-double.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/float-version-double.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,31 +0,0 @@ -/* - float-version.h: - - Copyright (C) 1991-2010 Victor Lazzarini - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* this file can be copied as float-version.h in installers for double precision - currently implemented only for OSX -*/ - -#ifndef USE_DOUBLE -#define USE_DOUBLE -#endif - diff -Nru csound-5.17.11~dfsg/H/float-version.h csound-6.02~dfsg/H/float-version.h --- csound-5.17.11~dfsg/H/float-version.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/float-version.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,30 +0,0 @@ -/* - float-version.h: - - Copyright (C) 1991-2010 Victor Lazzarini - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* uncomment the line below for double-precision installed headers */ - -/* -#ifndef USE_DOUBLE -#define USE_DOUBLE -#endif -*/ diff -Nru csound-5.17.11~dfsg/H/insert.h csound-6.02~dfsg/H/insert.h --- csound-5.17.11~dfsg/H/insert.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/insert.h 2014-01-07 16:54:20.000000000 +0000 @@ -49,6 +49,11 @@ OPDS h; } LINK; +typedef struct { + OPDS h; + MYFLT *inst; +} KILLOP; + /* the number of optional outputs defined in entry.c */ #define SUBINSTNUMOUTS 8 @@ -56,7 +61,7 @@ OPCODINFO *opcode_info; void *uopcode_struct; INSDS *parent_ip; - MYFLT *iobufp_ptrs[12]; /* expandable IV - Oct 26 2002 */ /* was 8 */ + MYFLT *iobufp_ptrs[12]; /* expandable IV - Oct 26 2002 */ /* was 8 */ } OPCOD_IOBUFS; typedef struct { /* IV - Oct 16 2002 */ @@ -68,14 +73,16 @@ } SUBINST; typedef struct { /* IV - Sep 8 2002: new structure: UOPCODE */ - OPDS h; - INSDS *ip, *parent_ip; + OPDS h; + INSDS *ip, *parent_ip; OPCOD_IOBUFS *buf; - int l_ksmps, ksmps_scale; - MYFLT l_ekr, l_onedkr, l_onedksmps, l_kicvt; + /*unsigned int l_ksmps; + int ksmps_scale; + MYFLT l_ekr, l_onedkr, l_onedksmps, l_kicvt; + int mode;*/ /* special case: the argument list is stored at the end of the */ /* opcode data structure */ - MYFLT *ar[1]; + MYFLT *ar[1]; } UOPCODE; /* IV - Sep 8 2002: added opcodes: xin, xout, and setksmps */ diff -Nru csound-5.17.11~dfsg/H/interlocks.h csound-6.02~dfsg/H/interlocks.h --- csound-5.17.11~dfsg/H/interlocks.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/interlocks.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -/* - interlocks.h: - - Copyright (C) 2011 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#define ZR (0x0100) -#define ZW (0x0200) -#define ZB (0x0300) - -#define TR (0x0400) -#define TW (0x0800) -#define TB (0x0c00) - -#define CR (0x1000) -#define CW (0x2000) -#define CB (0x3000) - -#define SB (0x4000) -#define _QQ (0x8000) - - diff -Nru csound-5.17.11~dfsg/H/linevent.h csound-6.02~dfsg/H/linevent.h --- csound-5.17.11~dfsg/H/linevent.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/linevent.h 2014-01-07 16:54:20.000000000 +0000 @@ -31,7 +31,16 @@ typedef struct { OPDS h; MYFLT *args[VARGMAX]; + int argno; + int flag; } LINEVENT; -#endif /* CSOUND_LINEVENT_H */ +typedef struct { + OPDS h; + MYFLT *inst; + MYFLT *args[VARGMAX]; + int argno; +} LINEVENT2; + +#endif /* CSOUND_LINEVENT_H */ diff -Nru csound-5.17.11~dfsg/H/lpc.h csound-6.02~dfsg/H/lpc.h --- csound-5.17.11~dfsg/H/lpc.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/lpc.h 2014-01-07 16:54:20.000000000 +0000 @@ -26,12 +26,12 @@ #define LP_MAGIC 999 #define LP_MAGIC2 2399 /* pole file type */ #define LPBUFSIZ 4096 /* in lpanal */ -#define MAXWINDIN 1000 /* for 10ms hops at 50 KC */ -#define MAXPOLES 1000 +#define MAXWINDIN 5000 /* for 10ms hops at 50 KC */ +#define MAXPOLES 5000 #define NDATA 4 /* number of data values stored with frame */ typedef struct { - int32 headersize, lpmagic, npoles, nvals; + uint32_t headersize, lpmagic, npoles, nvals; MYFLT framrate, srate, duration; char text[4]; } LPHEADER; diff -Nru csound-5.17.11~dfsg/H/midifile.h csound-6.02~dfsg/H/midifile.h --- csound-5.17.11~dfsg/H/midifile.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/midifile.h 2014-01-07 16:53:47.000000000 +0000 @@ -50,6 +50,7 @@ /* miditempo opcode: returns the current tempo of MIDI file */ extern int midiTempoOpcode(CSOUND *csound, MIDITEMPO *p); +extern int midiFileStatus(CSOUND *csound, MIDITEMPO *p); #ifdef __cplusplus } diff -Nru csound-5.17.11~dfsg/H/midiops.h csound-6.02~dfsg/H/midiops.h --- csound-5.17.11~dfsg/H/midiops.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/midiops.h 2014-01-07 16:53:47.000000000 +0000 @@ -51,9 +51,20 @@ #define TVA_DEC 134 #define TVA_RLS 135 + + +typedef struct { + OPDS h; + MYFLT *chnl; + STRINGDAT *insno; + MYFLT *iresetctls; +} MASSIGNS; + typedef struct { OPDS h; - MYFLT *chnl, *insno, *iresetctls; + MYFLT *chnl; + MYFLT *insno; + MYFLT *iresetctls; } MASSIGN; typedef struct { @@ -149,4 +160,3 @@ } CTLIN; #endif - diff -Nru csound-5.17.11~dfsg/H/mpadec.h csound-6.02~dfsg/H/mpadec.h --- csound-5.17.11~dfsg/H/mpadec.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/mpadec.h 2014-01-07 16:53:47.000000000 +0000 @@ -118,7 +118,9 @@ int mpadec_reset(mpadec_t mpadec); int mpadec_configure(mpadec_t mpadec, mpadec_config_t *cfg); int mpadec_get_info(mpadec_t mpadec, void *info, int info_type); -int mpadec_decode(mpadec_t mpadec, uint8_t *srcbuf, uint32_t srcsize, uint8_t *dstbuf, uint32_t dstsize, uint32_t *srcused, uint32_t *dstused); +int mpadec_decode(mpadec_t mpadec, uint8_t *srcbuf, uint32_t srcsize, + uint8_t *dstbuf, uint32_t dstsize, uint32_t *srcused, + uint32_t *dstused); char *mpadec_error(int code); mpadec2_t mpadec2_init(void); @@ -126,7 +128,8 @@ int mpadec2_reset(mpadec2_t mpadec); int mpadec2_configure(mpadec2_t mpadec, mpadec_config_t *cfg); int mpadec2_get_info(mpadec2_t mpadec, void *info, int info_type); -int mpadec2_decode(mpadec2_t mpadec, uint8_t *srcbuf, uint32_t srcsize, uint8_t *dstbuf, uint32_t dstsize, uint32_t *dstused); +int mpadec2_decode(mpadec2_t mpadec, uint8_t *srcbuf, uint32_t srcsize, + uint8_t *dstbuf, uint32_t dstsize, uint32_t *dstused); #define mpadec2_error(x) mpadec_error(x) #ifdef __cplusplus @@ -134,4 +137,3 @@ #endif #endif - diff -Nru csound-5.17.11~dfsg/H/msg_attr.h csound-6.02~dfsg/H/msg_attr.h --- csound-5.17.11~dfsg/H/msg_attr.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/msg_attr.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,71 +0,0 @@ -/* - msg_attr.h: - - Copyright (C) 2005 Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_MSG_ATTR_H -#define CSOUND_MSG_ATTR_H - -/* message types (only one can be specified) */ - -/* standard message */ -#define CSOUNDMSG_DEFAULT (0x0000) -/* error message (initerror, perferror, etc.) */ -#define CSOUNDMSG_ERROR (0x1000) -/* orchestra opcodes (e.g. printks) */ -#define CSOUNDMSG_ORCH (0x2000) -/* for progress display and heartbeat characters */ -#define CSOUNDMSG_REALTIME (0x3000) -/* warning messages */ -#define CSOUNDMSG_WARNING (0x4000) - -/* format attributes (colors etc.), use the bitwise OR of any of these: */ - -#define CSOUNDMSG_FG_BLACK (0x0100) -#define CSOUNDMSG_FG_RED (0x0101) -#define CSOUNDMSG_FG_GREEN (0x0102) -#define CSOUNDMSG_FG_YELLOW (0x0103) -#define CSOUNDMSG_FG_BLUE (0x0104) -#define CSOUNDMSG_FG_MAGENTA (0x0105) -#define CSOUNDMSG_FG_CYAN (0x0106) -#define CSOUNDMSG_FG_WHITE (0x0107) - -#define CSOUNDMSG_FG_BOLD (0x0008) -#define CSOUNDMSG_FG_UNDERLINE (0x0080) - -#define CSOUNDMSG_BG_BLACK (0x0200) -#define CSOUNDMSG_BG_RED (0x0210) -#define CSOUNDMSG_BG_GREEN (0x0220) -#define CSOUNDMSG_BG_ORANGE (0x0230) -#define CSOUNDMSG_BG_BLUE (0x0240) -#define CSOUNDMSG_BG_MAGENTA (0x0250) -#define CSOUNDMSG_BG_CYAN (0x0260) -#define CSOUNDMSG_BG_GREY (0x0270) - - /* ------------------------------------------------------------------------ */ - -#define CSOUNDMSG_TYPE_MASK (0x7000) -#define CSOUNDMSG_FG_COLOR_MASK (0x0107) -#define CSOUNDMSG_FG_ATTR_MASK (0x0088) -#define CSOUNDMSG_BG_COLOR_MASK (0x0270) - -#endif /* CSOUND_MSG_ATTR_H */ - diff -Nru csound-5.17.11~dfsg/H/namedins.h csound-6.02~dfsg/H/namedins.h --- csound-5.17.11~dfsg/H/namedins.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/namedins.h 2014-01-07 16:53:47.000000000 +0000 @@ -42,19 +42,6 @@ int32 named_instr_find(CSOUND *, char *); -/* allocate entry for named instrument ip with name s (s must not be freed */ -/* after the call, because only the pointer is stored); instrument number */ -/* is set to insno */ -/* returns zero if the named instr entry could not be allocated */ -/* (e.g. because it already exists) */ - -int named_instr_alloc(CSOUND *, char *, INSTRTXT *, int32); - -/* assign instrument numbers to all named instruments */ -/* called by otran */ - -void named_instr_assign_numbers(CSOUND *); - /* convert opcode string argument to instrument number */ /* return value is -1 if the instrument cannot be found */ /* (in such cases, csoundInitError() is also called) */ @@ -103,9 +90,6 @@ /* 3. the file name is generated using baseName and the */ /* value rounded to the nearest integer, as described */ /* above */ -/* 'is_string' is usually p->XSTRCODE for an opcode with */ -/* only one string argument, otherwise it is */ -/* p->XSTRCODE & (1 << (argno - 1)) */ /* return value: */ /* pointer to the output string; if 's' is not NULL, it is */ /* always the same as 's', otherwise it is allocated with */ @@ -115,65 +99,6 @@ char *strarg2name(CSOUND *, char *, void *, const char *, int); /* ----------------------------------------------------------------------- */ -/* the following functions are for efficient management of the opcode list */ - -/* find opcode with the specified name in opcode list */ -/* returns index to opcodlst[], or zero if the opcode cannot be found */ - -int find_opcode(CSOUND *, char *); - -/* ----------------------------------------------------------------------- */ -/* These functions replace the functionality of strsav() in rdorch.c. */ - -/* Allocate space for strsav (called once from rdorchfile()). */ - -void strsav_create(CSOUND *); - -/* Locate string s in database, and return address of stored string (not */ -/* necessarily the same as s). If the string is not defined yet, it is */ -/* copied to the database (in such cases, it is allowed to free s after */ -/* the call). */ - -char *strsav_string(CSOUND *, char *); - -/* ----------------------------------------------------------------------- */ - -extern const unsigned char strhash_tabl_8[256]; -extern unsigned int csound_str_hash_32(const char *s); - -static inline unsigned char name_hash(CSOUND *csound, const char *s) -{ - const unsigned char *c = (const unsigned char*) &(s[0]); - unsigned int h = 0U; -#ifdef LINUX - for ( ; *c != (unsigned char) 0; c++) - h = csound->strhash_tabl_8[h ^ *c]; -#else - (void) csound; - for ( ; *c != (unsigned char) 0; c++) - h = strhash_tabl_8[h ^ *c]; -#endif - return (unsigned char) h; -} - -/* faster version that assumes a non-empty string */ - -static inline unsigned char name_hash_2(CSOUND *csound, const char *s) -{ - const unsigned char *c = (const unsigned char*) &(s[0]); - unsigned int h = 0U; -#ifdef LINUX - do { - h = csound->strhash_tabl_8[h ^ *c]; - } while (*(++c) != (unsigned char) 0); -#else - (void) csound; - do { - h = strhash_tabl_8[h ^ *c]; - } while (*(++c) != (unsigned char) 0); -#endif - return (unsigned char) h; -} static inline int sCmp(const char *x, const char *y) { diff -Nru csound-5.17.11~dfsg/H/oload.h csound-6.02~dfsg/H/oload.h --- csound-5.17.11~dfsg/H/oload.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/oload.h 2014-01-07 16:53:47.000000000 +0000 @@ -25,8 +25,8 @@ #define CSOUND_OLOAD_H #define NCONSTS 256 /* gbl */ /* OLOAD.H */ -#define NLABELS 5 /* lcl */ -#define NGOTOS 40 +//#define NLABELS 5 /* lcl */ +//#define NGOTOS 40 #define LABELOFS (-0x40000000) #define LABELIM (-0x38000000) diff -Nru csound-5.17.11~dfsg/H/prototyp.h csound-6.02~dfsg/H/prototyp.h --- csound-5.17.11~dfsg/H/prototyp.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/prototyp.h 2014-01-07 16:54:20.000000000 +0000 @@ -34,30 +34,26 @@ void *mcalloc(CSOUND *, size_t); void *mrealloc(CSOUND *, void *, size_t); void mfree(CSOUND *, void *); +char *cs_strdup(CSOUND*, char*); +char *cs_strndup(CSOUND*, char*, size_t); void csoundAuxAlloc(CSOUND *, size_t, AUXCH *), auxchfree(CSOUND *, INSDS *); void fdrecord(CSOUND *, FDCH *), fdclose(CSOUND *, FDCH *); void fdchclose(CSOUND *, INSDS *); CS_PRINTF2 void synterr(CSOUND *, const char *, ...); CS_NORETURN CS_PRINTF2 void csoundDie(CSOUND *, const char *, ...); CS_PRINTF2 int csoundInitError(CSOUND *, const char *, ...); -CS_PRINTF2 int csoundPerfError(CSOUND *, const char *, ...); +CS_PRINTF3 int csoundPerfError(CSOUND *, INSDS *ip, const char *, ...); CS_PRINTF2 void csoundWarning(CSOUND *, const char *, ...); CS_PRINTF2 void csoundDebugMsg(CSOUND *, const char *, ...); CS_PRINTF2 void csoundErrorMsg(CSOUND *, const char *, ...); void csoundErrMsgV(CSOUND *, const char *, const char *, va_list); CS_NORETURN void csoundLongJmp(CSOUND *, int retval); -void putop(CSOUND *, TEXT *); -void rdorchfile(CSOUND *), otran(CSOUND *); -char argtyp(CSOUND *, char *); TEXT *getoptxt(CSOUND *, int *); -int express(CSOUND *, char *); -int lgexist(CSOUND *, const char *); -void oload(CSOUND *); void reverbinit(CSOUND *); void dispinit(CSOUND *); int init0(CSOUND *); void scsort(CSOUND *, FILE *, FILE *); -void scsortstr(CSOUND *, CORFIL *); +char *scsortstr(CSOUND *, CORFIL *); int scxtract(CSOUND *, CORFIL *, FILE *); int rdscor(CSOUND *, EVTBLK *); int musmon(CSOUND *); @@ -65,7 +61,6 @@ FUNC *csoundFTFind(CSOUND *, MYFLT *); FUNC *csoundFTFindP(CSOUND *, MYFLT *); FUNC *csoundFTnp2Find(CSOUND *, MYFLT *); -void cs_beep(CSOUND *); MYFLT intpow(MYFLT, int32); void list_opcodes(CSOUND *, int); char *getstrformat(int format); @@ -81,13 +76,13 @@ void xturnoff(CSOUND *, INSDS *); void xturnoff_now(CSOUND *, INSDS *); int insert_score_event(CSOUND *, EVTBLK *, double); -MEMFIL *ldmemfile(CSOUND *, const char *); -MEMFIL *ldmemfile2(CSOUND *, const char *, int); + //MEMFIL *ldmemfile(CSOUND *, const char *); + //MEMFIL *ldmemfile2(CSOUND *, const char *, int); MEMFIL *ldmemfile2withCB(CSOUND *csound, const char *filnam, int csFileType, int (*callback)(CSOUND*, MEMFIL*)); void rlsmemfiles(CSOUND *); int delete_memfile(CSOUND *, const char *); -char *csoundTmpFileName(CSOUND *, char *, const char *); +char *csoundTmpFileName(CSOUND *, const char *); void *SAsndgetset(CSOUND *, char *, void *, MYFLT *, MYFLT *, MYFLT *, int); int getsndin(CSOUND *, void *, MYFLT *, int, void *); void *sndgetset(CSOUND *, void *); @@ -100,11 +95,13 @@ int csoundLoadOpcodeDB(CSOUND *, const char *); void csoundDestroyOpcodeDB(CSOUND *); int csoundCheckOpcodePluginFile(CSOUND *, const char *); -int csoundLoadAllPluginOpcodes(CSOUND *); + //int csoundLoadAllPluginOpcodes(CSOUND *); int csoundLoadAndInitModule(CSOUND *, const char *); void csoundNotifyFileOpened(CSOUND *, const char *, int, int, int); int insert_score_event_at_sample(CSOUND *, EVTBLK *, int64_t); +char *get_arg_string(CSOUND *, MYFLT); + /** * Register a function to be called at note deactivation. * Should be called from the initialisation routine of an opcode. diff -Nru csound-5.17.11~dfsg/H/pstream.h csound-6.02~dfsg/H/pstream.h --- csound-5.17.11~dfsg/H/pstream.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/pstream.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,291 +0,0 @@ -/* - pstream.h: - - Copyright (C) 2001 Richard Dobson - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef __PSTREAM_H_INCLUDED -#define __PSTREAM_H_INCLUDED - -/* pstream.h. Implementation of PVOCEX streaming opcodes. - (c) Richard Dobson August 2001 - NB pvoc routines based on CARL distribution (Mark Dolson). - This file is licensed according to the terms of the GNU LGPL. - */ - -/* opcodes: PROVISIONAL DEFINITIONS - - fsig pvsanal ain,ifftsize,ioverlap,iwinsize,iwintype[,iformat,iinit] - - iwintype: 0 = HAMMING, 1 = VonHann, 2 = Kaiser(?) - iformat: only PVS_AMP_FREQ (0) supported at present - (TODO: add f-table support for custom window) - ( But: really need a param to associate with the window too, - or just use a standard default value...) - - fsig pvsfread ktimpt,ifn[,ichan] - - asig pvsynth fsig[,iinit] - - asig pvsadsyn fsig,inoscs,kfmod[,ibin,ibinoffset,iinit] - - ibin: starting bin (defualt 0) - ibinoffset: distance between successive bins (default 1) - kfmod: multiplier; 1 = no change, 2 = up one octave. - - fsig pvscross fsrc,fdest,kamp1,kamp2 - - fsig pvsmaska fsrc,ifn,kdepth - - ioverlap,inumbins,iwinsize,iformat pvsinfo fsig - - ( will need sndinfo supporting pvocex files anyway, - to know numchans, wintype, etc.) - - fdest = fsrc - - ( woo-hoo! operator overloading in Csound!) - ( NB an init statement for fsigs is not supported. One day....) - - kflag pvsftw fsig,ifna [,ifnf] - pvsftr fsig,ifna [,ifnf] - - ( this modifies an ~existing~ signal, does not create a new one, - hence no output) - - Re iinit: not implemented yet: and I still need to establish - if it's possible... - */ - -/* description of an fsig analysis frame*/ -enum PVS_WINTYPE { - PVS_WIN_HAMMING = 0, - PVS_WIN_HANN, - PVS_WIN_KAISER, - PVS_WIN_CUSTOM, - PVS_WIN_BLACKMAN, - PVS_WIN_BLACKMAN_EXACT, - PVS_WIN_NUTTALLC3, - PVS_WIN_BHARRIS_3, - PVS_WIN_BHARRIS_MIN, - PVS_WIN_RECT -}; - - -enum PVS_ANALFORMAT { - PVS_AMP_FREQ = 0, - PVS_AMP_PHASE, - PVS_COMPLEX, - PVS_TRACKS /* added VL, 24.06.2005 */ -}; - -typedef struct { - MYFLT re; - MYFLT im; -} CMPLX; - -typedef struct pvsdat { - int32 N; - int sliding; /* Flag to indicate sliding case */ - int32 NB; - int32 overlap; - int32 winsize; - int wintype; - int32 format; /* fixed for now to AMP:FREQ */ - uint32 framecount; - AUXCH frame; /* RWD MUST always be 32bit floats */ - /* But not in sliding case when MYFLT */ -} PVSDAT; - -/* may be no point supporting Kaiser in an opcode unless we can support - the param too but we can have kaiser in a PVOCEX file. */ - -typedef struct { - OPDS h; - PVSDAT *fsig; /* output signal is an analysis frame */ - MYFLT *ain; /* input sig is audio */ - MYFLT *fftsize; /* params */ - MYFLT *overlap; - MYFLT *winsize; - MYFLT *wintype; - MYFLT *format; /* always PVS_AMP_FREQ at present */ - MYFLT *init; /* not yet implemented */ - /* internal */ - int32 buflen; - float fund,arate; - float RoverTwoPi,TwoPioverR,Fexact; - MYFLT *nextIn; - int32 nI,Ii,IOi; /* need all these ?; double as N and NB */ - int32 inptr; - - AUXCH input; - AUXCH overlapbuf; - AUXCH analbuf; - AUXCH analwinbuf; /* prewin in SDFT case */ - AUXCH oldInPhase; - AUXCH trig; - double *cosine, *sine; -} PVSANAL; - -typedef struct { - OPDS h; - MYFLT *aout; /* audio output signal */ - PVSDAT *fsig; /* input signal is an analysis frame */ - MYFLT *init; /* not yet implemented */ - /* internal */ - /* check these against fsig vals */ - int32 overlap,winsize,fftsize,wintype,format; - /* can we allow variant window tpes? */ - int32 buflen; - MYFLT fund,arate; - MYFLT RoverTwoPi,TwoPioverR,Fexact; - MYFLT *nextOut; - int32 nO,Ii,IOi; /* need all these ?*/ - int32 outptr; - int32 bin_index; /* for phase normalization across frames */ - /* renderer gets all format info from fsig */ - - AUXCH output; - AUXCH overlapbuf; - AUXCH synbuf; - AUXCH analwinbuf; /* may get away with a local alloc and free */ - AUXCH synwinbuf; - AUXCH oldOutPhase; - -} PVSYNTH; - -/* for pvadsyn */ - -typedef struct { - OPDS h; - MYFLT *aout; - PVSDAT *fsig; - MYFLT *n_oscs; - MYFLT *kfmod; - MYFLT *ibin; /* default 0 */ - MYFLT *ibinoffset; /* default 1 */ - MYFLT *init; /* not yet implemented */ - /* internal */ - int32 outptr; - uint32 lastframe; - /* check these against fsig vals */ - int32 overlap,winsize,fftsize,wintype,format,noscs; - int32 maxosc; - float one_over_overlap,pi_over_sr, one_over_sr; - float fmod; - AUXCH a; - AUXCH x; - AUXCH y; - AUXCH amps; - AUXCH lastamps; - AUXCH freqs; - AUXCH outbuf; -} PVADS; - -/* for pvscross */ -typedef struct { - OPDS h; - PVSDAT *fout; - PVSDAT *fsrc; - PVSDAT *fdest; - MYFLT *kamp1; - MYFLT *kamp2; - /* internal */ - int32 overlap,winsize,fftsize,wintype,format; - uint32 lastframe; -} PVSCROSS; - -/* for pvsmaska */ -typedef struct { - OPDS h; - PVSDAT *fout; - PVSDAT *fsrc; - MYFLT *ifn; - MYFLT *kdepth; - /* internal*/ - int32 overlap,winsize,fftsize,wintype,format; - uint32 lastframe; - int nwarned,pwarned; /* range errors for kdepth */ - FUNC *maskfunc; -} PVSMASKA; - -/* for pvsftw, pvsftr */ - -typedef struct { - OPDS h; - MYFLT *kflag; - PVSDAT *fsrc; - MYFLT *ifna; /* amp, required */ - MYFLT *ifnf; /* freq: optional*/ - /* internal */ - int32 overlap,winsize,fftsize,wintype,format; - uint32 lastframe; - FUNC *outfna, *outfnf; -} PVSFTW; - -typedef struct { - OPDS h; - /* no output var*/ - PVSDAT *fdest; - MYFLT *ifna; /* amp, may be 0 */ - MYFLT *ifnf; /* freq: optional*/ - /* internal */ - int32 overlap,winsize,fftsize,wintype,format; - uint32 lastframe; - FUNC *infna, *infnf; - MYFLT *ftablea,*ftablef; -} PVSFTR; - -/* for pvsfread */ -/* wsig pvsread ktimpt,ifilcod */ -typedef struct { - OPDS h; - PVSDAT *fout; - MYFLT *kpos; - MYFLT *ifilno; - MYFLT *ichan; - /* internal */ - int ptr; - int32 overlap,winsize,fftsize,wintype,format; - uint32 chans, nframes,lastframe,chanoffset,blockalign; - MYFLT arate; - float *membase; /* RWD MUST be 32bit: reads file */ -} PVSFREAD; - -/* for pvsinfo */ - -typedef struct { - OPDS h; - MYFLT *ioverlap; - MYFLT *inumbins; - MYFLT *iwinsize; - MYFLT *iformat; - /* internal*/ - PVSDAT *fsrc; -} PVSINFO; - -typedef struct { - OPDS h; - PVSDAT *fout; - PVSDAT *fsrc; -} FASSIGN; - -#endif - diff -Nru csound-5.17.11~dfsg/H/pvfileio.h csound-6.02~dfsg/H/pvfileio.h --- csound-5.17.11~dfsg/H/pvfileio.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/pvfileio.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,167 +0,0 @@ -/* - pvfileio.h: - - Copyright (C) 2000 Richard Dobson - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* pvfileio.h: header file for PVOC_EX file format */ -/* Initial Version 0.1 RWD 25:5:2000 all rights reserved: work in progress! */ - -#ifndef __PVFILEIO_H_INCLUDED -#define __PVFILEIO_H_INCLUDED - -#include "sysdep.h" - -#if defined(WIN32) || defined(_WIN32) || defined(_MSC_VER) - -#include - -#else - -typedef struct -{ - uint32_t Data1; - uint16_t Data2; - uint16_t Data3; - unsigned char Data4[8]; -} GUID; - -typedef struct /* waveformatex */ { - uint16_t wFormatTag; - uint16_t nChannels; - uint32_t nSamplesPerSec; - uint32_t nAvgBytesPerSec; - uint16_t nBlockAlign; - uint16_t wBitsPerSample; - uint16_t cbSize; -} WAVEFORMATEX; - -#endif - -/* NB no support provided for double format (yet) */ - -typedef enum pvoc_wordformat { - PVOC_IEEE_FLOAT, - PVOC_IEEE_DOUBLE -} pvoc_wordformat; - -/* include PVOC_COMPLEX for some parity with SDIF */ - -typedef enum pvoc_frametype { - PVOC_AMP_FREQ = 0, - PVOC_AMP_PHASE, - PVOC_COMPLEX -} pvoc_frametype; - -/* a minimal list */ - -typedef enum pvoc_windowtype { - PVOC_DEFAULT = 0, - PVOC_HAMMING, - PVOC_HANN, - PVOC_KAISER, - PVOC_RECT, - PVOC_CUSTOM -} pv_wtype; - -/* Renderer information: source is presumed to be of this type */ - -typedef enum pvoc_sampletype { - STYPE_16, - STYPE_24, - STYPE_32, - STYPE_IEEE_FLOAT -} pv_stype; - -typedef struct pvoc_data { /* 32 bytes */ - uint16_t wWordFormat; /* pvoc_wordformat */ - uint16_t wAnalFormat; /* pvoc_frametype */ - uint16_t wSourceFormat; /* WAVE_FORMAT_PCM or WAVE_FORMAT_IEEE_FLOAT */ - uint16_t wWindowType; /* pvoc_windowtype */ - uint32_t nAnalysisBins; /* implicit FFT size = (nAnalysisBins-1) * 2 */ - uint32_t dwWinlen; /* analysis winlen, in samples */ - /* NB may be != FFT size */ - uint32_t dwOverlap; /* samples */ - uint32_t dwFrameAlign; /* usually nAnalysisBins * 2 * sizeof(float) */ - float fAnalysisRate; - float fWindowParam; /* default 0.0f unless needed */ -} PVOCDATA; - -typedef struct { - WAVEFORMATEX Format; /* 18 bytes: info for renderer */ - /* as well as for pvoc */ - union { /* 2 bytes */ - uint16_t wValidBitsPerSample; /* as per standard WAVE_EX: */ - /* applies to renderer */ - uint16_t wSamplesPerBlock; - uint16_t wReserved; - } Samples; - uint32_t dwChannelMask; /* 4 bytes: can be used as in */ - /* standrad WAVE_EX */ - GUID SubFormat; /* 16 bytes */ -} WAVEFORMATEXTENSIBLE, *PWAVEFORMATEXTENSIBLE; - -typedef struct { - WAVEFORMATEXTENSIBLE wxFormat; /* 40 bytes */ - uint32_t dwVersion; /* 4 bytes */ - uint32_t dwDataSize; /* 4 bytes: sizeof PVOCDATA data block */ - PVOCDATA data; /* 32 bytes */ -} WAVEFORMATPVOCEX; /* total 80 bytes */ - -/* at least VC++ will give 84 for sizeof(WAVEFORMATPVOCEX), */ -/* so we need our own version */ -#define SIZEOF_FMTPVOCEX (80) -/* for the same reason: */ -#define SIZEOF_WFMTEX (18) -#define PVX_VERSION (1) - -/******* the all-important PVOC GUID - - {8312B9C2-2E6E-11d4-A824-DE5B96C3AB21} - -**************/ - -#ifndef CSOUND_CSDL_H - -extern const GUID KSDATAFORMAT_SUBTYPE_PVOC; - -/* pvoc file handling functions */ - -const char *pvoc_errorstr(CSOUND *); -int init_pvsys(CSOUND *); -int pvoc_createfile(CSOUND *, const char *, - uint32, uint32, uint32, - uint32, int32, int, int, - float, float *, uint32); -int pvoc_openfile(CSOUND *, - const char *filename, PVOCDATA *data, WAVEFORMATEX *fmt); -int pvoc_closefile(CSOUND *, int); -int pvoc_putframes(CSOUND *, - int ofd, const float *frame, int32 numframes); -int pvoc_getframes(CSOUND *, - int ifd, float *frames, uint32 nframes); -int pvoc_framecount(CSOUND *, int ifd); -int pvoc_fseek(CSOUND *, int ifd, int offset); -int pvsys_release(CSOUND *); - -#endif /* CSOUND_CSDL_H */ - -#endif /* __PVFILEIO_H_INCLUDED */ - diff -Nru csound-5.17.11~dfsg/H/remote.h csound-6.02~dfsg/H/remote.h --- csound-5.17.11~dfsg/H/remote.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/remote.h 2014-01-07 16:53:47.000000000 +0000 @@ -26,7 +26,7 @@ #ifdef HAVE_SOCKETS #ifdef WIN32 -#include +#include #else #include #include @@ -96,22 +96,26 @@ typedef struct { /* structs for INSTR 0 opcodes */ OPDS h; - MYFLT *str1, *str2, *insno[64]; + STRINGDAT *str1, *str2; + MYFLT *insno[64]; } INSREMOT; typedef struct { /* structs for INSTR 0 opcodes */ OPDS h; - MYFLT *str1, *insno[64]; + STRINGDAT *str1; + MYFLT *insno[64]; } INSGLOBAL; typedef struct { OPDS h; - MYFLT *str1, *str2, *chnum[16]; + STRINGDAT *str1, *str2; + MYFLT *chnum[16]; } MIDREMOT; typedef struct { /* structs for INSTR 0 opcodes */ OPDS h; - MYFLT *str1, *chnum[16]; + STRINGDAT *str1; + MYFLT *chnum[16]; } MIDGLOBAL; int CLsend(CSOUND *csound, int conn, void *data, int length); diff -Nru csound-5.17.11~dfsg/H/resource.h csound-6.02~dfsg/H/resource.h --- csound-5.17.11~dfsg/H/resource.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/resource.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,39 +0,0 @@ -/* - resource.h: - - Copyright (C) 1995 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by winsound.rc -// - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 101 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1000 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff -Nru csound-5.17.11~dfsg/H/soundio.h csound-6.02~dfsg/H/soundio.h --- csound-5.17.11~dfsg/H/soundio.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/soundio.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,154 +0,0 @@ -/* - soundio.h: - - Copyright (C) 1991, 2000 Barry Vercoe, Richard Dobson - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - /* SOUNDIO.H */ -#ifndef CSOUND_SOUNDIO_H -#define CSOUND_SOUNDIO_H - -#include - -#ifdef WIN32 -#define IOBUFSAMPS 4096 /* default sampframes in audio iobuf, -b settable */ -#define IODACSAMPS 16384 /* default samps in hardware buffer, -B settable */ -#elif defined(NeXT) || defined(__MACH__) -#define IOBUFSAMPS 1024 /* default sampframes in audio iobuf, -b settable */ -#define IODACSAMPS 4096 /* default samps in hardware buffer, -B settable */ -#elif defined(ANDROID) -#define IOBUFSAMPS 2048 /* default sampframes in audio iobuf, -b settable */ -#define IODACSAMPS 4096 /* default samps in hardware buffer, -B settable */ -#else -#define IOBUFSAMPS 256 /* default sampframes in audio iobuf, -b settable */ -#define IODACSAMPS 1024 /* default samps in hardware buffer, -B settable */ -#endif - -#define SNDINBUFSIZ 4096 /* soundin bufsize; must be > sizeof(SFHEADER), */ - /* but small is kind to net rexec */ - -/* standard audio encoding types */ - -#define AE_CHAR SF_FORMAT_PCM_S8 -#define AE_SHORT SF_FORMAT_PCM_16 -#define AE_24INT SF_FORMAT_PCM_24 -#define AE_LONG SF_FORMAT_PCM_32 -#define AE_UNCH SF_FORMAT_PCM_U8 -#define AE_FLOAT SF_FORMAT_FLOAT -#define AE_DOUBLE SF_FORMAT_DOUBLE -#define AE_ULAW SF_FORMAT_ULAW -#define AE_ALAW SF_FORMAT_ALAW -#define AE_IMA_ADPCM SF_FORMAT_IMA_ADPCM -#define AE_MS_ADPCM SF_FORMAT_MS_ADPCM -#define AE_GSM610 SF_FORMAT_GSM610 -#define AE_VOX SF_FORMAT_VOX_ADPCM -#define AE_G721_32 SF_FORMAT_G721_32 -#define AE_G723_24 SF_FORMAT_G723_24 -#define AE_G723_40 SF_FORMAT_G723_40 -#define AE_DWVW_12 SF_FORMAT_DWVW_12 -#define AE_DWVW_16 SF_FORMAT_DWVW_16 -#define AE_DWVW_24 SF_FORMAT_DWVW_24 -#define AE_DWVW_N SF_FORMAT_DWVW_N -#define AE_DPCM_8 SF_FORMAT_DPCM_8 -#define AE_DPCM_16 SF_FORMAT_DPCM_16 - -#define AE_LAST SF_FORMAT_DPCM_16 /* current last audio encoding value */ - -/* file types */ - -#define TYP_WAV (SF_FORMAT_WAV >> 16) -#define TYP_AIFF (SF_FORMAT_AIFF >> 16) -#define TYP_AU (SF_FORMAT_AU >> 16) -#define TYP_RAW (SF_FORMAT_RAW >> 16) -#define TYP_PAF (SF_FORMAT_PAF >> 16) -#define TYP_SVX (SF_FORMAT_SVX >> 16) -#define TYP_NIST (SF_FORMAT_NIST >> 16) -#define TYP_VOC (SF_FORMAT_VOC >> 16) -#define TYP_IRCAM (SF_FORMAT_IRCAM >> 16) -#define TYP_W64 (SF_FORMAT_W64 >> 16) -#define TYP_MAT4 (SF_FORMAT_MAT4 >> 16) -#define TYP_MAT5 (SF_FORMAT_MAT5 >> 16) -#define TYP_PVF (SF_FORMAT_PVF >> 16) -#define TYP_XI (SF_FORMAT_XI >> 16) -#define TYP_HTK (SF_FORMAT_HTK >> 16) -#define TYP_SDS (SF_FORMAT_SDS >> 16) -#define TYP_AVR (SF_FORMAT_AVR >> 16) -#define TYP_WAVEX (SF_FORMAT_WAVEX >> 16) -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1011 -# define TYP_SD2 (SF_FORMAT_SD2 >> 16) -# if HAVE_LIBSNDFILE >= 1013 -# define TYP_FLAC (SF_FORMAT_FLAC >> 16) -# define TYP_CAF (SF_FORMAT_CAF >> 16) -# endif -# if HAVE_LIBSNDFILE >= 1018 -# define TYP_WVE (SF_FORMAT_WVE >> 16) -# define TYP_OGG (SF_FORMAT_OFF >> 16) -# endif -# if HAVE_LIBSNDFILE >= 1019 -# define TYP_MPC2K (SF_FORMAT_MPC2K >> 16) -# define TYP_RF64 (SF_FORMAT_RF64 >> 16) -# endif -#endif - -#define FORMAT2SF(x) ((int) (x)) -#define SF2FORMAT(x) ((int) (x) & 0xFFFF) -#define TYPE2SF(x) ((int) (x) << 16) -#define SF2TYPE(x) ((int) (x& SF_FORMAT_TYPEMASK) >> 16) - -#ifdef USE_DOUBLE -#define sf_write_MYFLT sf_write_double -#define sf_read_MYFLT sf_read_double -#else -#define sf_write_MYFLT sf_write_float -#define sf_read_MYFLT sf_read_float -#endif - -#ifdef __cplusplus -extern "C" { -#endif - -/* generic sound input structure */ - -typedef struct { - SNDFILE *sinfd; /* sound file handle */ - MYFLT *inbufp, *bufend; /* current buffer position, end of buf */ - void *fd; /* handle returned by csoundFileOpen() */ - int bufsmps; /* number of mono samples in buffer */ - int format; /* sample format (AE_SHORT, etc.) */ - int channel; /* requested channel (ALLCHNLS: all) */ - int nchanls; /* number of channels in file */ - int sampframsiz; /* sample frame size in bytes */ - int filetyp; /* file format (TYP_WAV, etc.) */ - int analonly; /* non-zero for analysis utilities */ - int endfile; /* end of file reached ? non-zero: yes */ - int sr; /* sample rate in Hz */ - int do_floatscaling; /* scale floats by fscalefac ? 0: no */ - int64_t audrem, framesrem, getframes; /* samples, frames, frames */ - MYFLT fscalefac; - MYFLT skiptime; - char sfname[512]; - MYFLT inbuf[SNDINBUFSIZ]; -} SOUNDIN; - -#ifdef __cplusplus -} -#endif - -#endif /* CSOUND_SOUNDIO_H */ - diff -Nru csound-5.17.11~dfsg/H/str_ops.h csound-6.02~dfsg/H/str_ops.h --- csound-5.17.11~dfsg/H/str_ops.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/str_ops.h 2014-01-07 16:54:20.000000000 +0000 @@ -32,38 +32,58 @@ typedef struct { OPDS h; MYFLT *indx; - MYFLT *str; + STRINGDAT *str; } STRSET_OP; typedef struct { OPDS h; MYFLT *r; + STRINGDAT *str; + char *mem; +} STRCHGD; + +typedef struct { + OPDS h; + MYFLT *indx; + MYFLT *str; +} STRTOD_OP; + +typedef struct { + OPDS h; + STRINGDAT *r; MYFLT *indx; } STRGET_OP; typedef struct { OPDS h; - MYFLT *r; - MYFLT *str; + STRINGDAT *r; + STRINGDAT *str; } STRCPY_OP; typedef struct { OPDS h; - MYFLT *r; - MYFLT *str1; - MYFLT *str2; + STRINGDAT *r; + STRINGDAT *str1; + STRINGDAT *str2; } STRCAT_OP; typedef struct { OPDS h; MYFLT *r; - MYFLT *sfmt; + STRINGDAT *str1; + STRINGDAT *str2; +} STRCMP_OP; + +typedef struct { + OPDS h; + STRINGDAT *r; + STRINGDAT *sfmt; MYFLT *args[64]; } SPRINTF_OP; typedef struct { OPDS h; - MYFLT *sfmt; + STRINGDAT *sfmt; MYFLT *ktrig; MYFLT *args[64]; MYFLT prv_ktrig; @@ -71,7 +91,7 @@ typedef struct { OPDS h; - MYFLT *str; + STRINGDAT *str; MYFLT *ktrig; MYFLT *no_newline; MYFLT prv_ktrig; @@ -80,8 +100,8 @@ typedef struct { OPDS h; - MYFLT *Sdst; - MYFLT *Ssrc; + STRINGDAT *Sdst; + STRINGDAT *Ssrc; MYFLT *istart; MYFLT *iend; } STRSUB_OP; @@ -89,33 +109,33 @@ typedef struct { OPDS h; MYFLT *ichr; - MYFLT *Ssrc; + STRINGDAT *Ssrc; MYFLT *ipos; } STRCHAR_OP; typedef struct { OPDS h; MYFLT *ilen; - MYFLT *Ssrc; + STRINGDAT *Ssrc; } STRLEN_OP; typedef struct { OPDS h; - MYFLT *Sdst; - MYFLT *Ssrc; + STRINGDAT *Sdst; + STRINGDAT *Ssrc; } STRUPPER_OP; typedef struct { OPDS h; - MYFLT *Sdst; + STRINGDAT *Sdst; MYFLT *iopt; } GETCFG_OP; typedef struct { OPDS h; MYFLT *ipos; - MYFLT *Ssrc1; - MYFLT *Ssrc2; + STRINGDAT *Ssrc1; + STRINGDAT *Ssrc2; } STRINDEX_OP; /* @@ -189,7 +209,10 @@ int strset_init(CSOUND *, void *); int strget_init(CSOUND *, void *); -int strcpy_opcode(CSOUND *, void *); +int strcpy_opcode_p(CSOUND *, void *); +int strcpy_opcode_S(CSOUND *, void *); +int strassign_opcode_S(CSOUND *, void *); +int strassign_opcode_Sk(CSOUND *, void *); int strcat_opcode(CSOUND *, void *); int strcmp_opcode(CSOUND *, void *); int sprintf_opcode(CSOUND *, void *); @@ -198,8 +221,10 @@ int printf_opcode_perf(CSOUND *, void *); int puts_opcode_init(CSOUND *, void *); int puts_opcode_perf(CSOUND *, void *); -int strtod_opcode(CSOUND *, void *); -int strtol_opcode(CSOUND *, void *); +int strtod_opcode_p(CSOUND *, void *); +int strtod_opcode_S(CSOUND *, void *); +int strtol_opcode_p(CSOUND *, void *); +int strtol_opcode_S(CSOUND *, void *); int strsub_opcode(CSOUND *, void *); int strchar_opcode(CSOUND *, void *); int strlen_opcode(CSOUND *, void *); @@ -208,6 +233,9 @@ int getcfg_opcode(CSOUND *, void *); int strindex_opcode(CSOUND *, void *); int strrindex_opcode(CSOUND *, void *); + int str_changed(CSOUND *csound, STRCHGD *p); + int str_changed_k(CSOUND *csound, STRCHGD *p); + int str_from_url(CSOUND *csound, STRCPY_OP *p); #endif /* CSOUND_STR_OPS_C */ diff -Nru csound-5.17.11~dfsg/H/sysdep.h csound-6.02~dfsg/H/sysdep.h --- csound-5.17.11~dfsg/H/sysdep.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/sysdep.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,405 +0,0 @@ -/* - sysdep.h: - - Copyright (C) 1991 Barry Vercoe, John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_SYSDEP_H -#define CSOUND_SYSDEP_H - - - - -/* check for the presence of a modern compiler (for use of certain features) */ - -#ifdef HAVE_GCC3 -# undef HAVE_GCC3 -#endif -#ifdef HAVE_C99 -# undef HAVE_C99 -#endif -#if (defined(__GNUC__) && (__GNUC__ >= 3)) -# define HAVE_C99 1 -# if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H) -# ifndef _ISOC99_SOURCE -# define _ISOC99_SOURCE 1 -# endif -# ifndef _ISOC9X_SOURCE -# define _ISOC9X_SOURCE 1 -# endif -# endif -# if !(defined(__MACH__) && (__GNUC__ == 3) && (__GNUC_MINOR__ < 2)) -# define HAVE_GCC3 1 -# endif -#elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) -# define HAVE_C99 1 -#endif - -#ifdef MSVC -typedef __int32 int32; -typedef __int16 int16; -typedef unsigned __int32 uint32; -typedef unsigned __int16 uint16; -#else -#include -typedef int_least32_t int32; -typedef int_least16_t int16; -typedef uint_least32_t uint32; -typedef uint_least16_t uint16; -#endif - -#if defined(HAVE_PTHREAD_SPIN_LOCK) -#include -#endif - -#if defined(HAVE_PTHREAD_SPIN_LOCK) -#include -#endif - -#ifdef __MACH__ -#include -#endif - -#include "float-version.h" - -#ifdef USE_DOUBLE - #define ACOS acos - #define ASIN asin - #define ATAN atan - #define ATAN2 atan2 - #define COS cos - #define SIN sin - #define TAN tan - #define COSH cosh - #define SINH sinh - #define TANH tanh - #define ACOSH acosh - #define ASINH asinh - #define ATANH atanh - #define EXP exp - #define LOG log - #define LOG10 log10 - #define LOG2 log2 - #define POWER pow - #define SQRT sqrt - #define HYPOT hypot - #define FABS fabs - #define FLOOR floor - #define CEIL ceil - #define FMOD fmod - #define MODF modf -#else - #define ACOS acosf - #define ASIN asinf - #define ATAN atanf - #define ATAN2 atan2f - #define COS cosf - #define SIN sinf - #define TAN tanf - #define COSH coshf - #define SINH sinhf - #define TANH tanhf - #define ACOSH acoshf - #define ASINH asinhf - #define ATANH atanhf - #define EXP expf - #define LOG logf - #define LOG10 log10f - #define LOG2 log2f - #define POWER powf - #define SQRT sqrtf - #define HYPOT hypotf - #define FABS fabsf - #define FLOOR floorf - #define CEIL ceilf - #define FMOD fmodf - #define MODF modff -#endif - -#include -#include -#include -#include -#if defined(HAVE_FCNTL_H) || defined(__unix) || defined(__unix__) -#include -#endif -#if defined(HAVE_UNISTD_H) || defined(__unix) || defined(__unix__) -#include -#endif - -/* Experiment with doubles or floats */ - -#ifndef __MYFLT_DEF -# define __MYFLT_DEF -# ifndef USE_DOUBLE -# define MYFLT float -# else -# define MYFLT double -# endif -#endif - -#if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H) - -#define FL(x) ((MYFLT) (x)) - -/* find out operating system if not specified on the command line */ - -#if defined(_WIN32) || defined(__WIN32__) -# ifndef WIN32 -# define WIN32 1 -# endif -#elif (defined(linux) || defined(__linux)) && !defined(LINUX) -# define LINUX 1 -#endif - -#if defined(WIN32) && defined(_MSC_VER) && !defined(__GNUC__) -# ifndef MSVC -# define MSVC 1 -# endif -#elif defined(MSVC) -# undef MSVC -#endif - -/* inline keyword: always available in C++, C99, and GCC 3.x and above */ -/* add any other compiler that supports 'inline' */ - -#if !(defined(__cplusplus) || defined(inline)) -# if defined(HAVE_C99) || defined(HAVE_GCC3) -# if defined(__GNUC__) && defined(__STRICT_ANSI__) -# define inline __inline__ -# endif -# elif defined(MSVC) -# define inline __inline -# elif defined(__MWERKS__) -# define inline inline -# else -# define inline -# endif -#endif - -#if defined(macintosh) -# define mac_classic /* All Mac Compiles Before OSX, including Carbon */ - /* define mills_macintosh in your prefix file - to compile the Mills "Perf" version */ -# ifndef USE_GUSI2 -# include -# endif -# define O_NDELAY (0) -# define DIRSEP ':' -#elif defined(SYMANTEC) -# include /* for open() etc protos on mac */ -# define DIRSEP ':' -#else -# define DIRSEP '/' -# ifdef LATTICE -# ifdef HAVE_SYS_TYPES_H -# include -# endif -# else -# ifdef __WATCOMC__ -# if !defined(O_NDELAY) -# define O_NDELAY (0) -# endif -# include -# else -# ifdef WIN32 -# undef DIRSEP -# define DIRSEP '\\' -# if !defined(O_NDELAY) -# define O_NDELAY (0) -# endif -# include -# else -# ifdef DOSGCC -# if !defined(O_NDELAY) -# define O_NDELAY (0) -# endif -# endif -# ifdef HAVE_SYS_TYPES_H -# include -# endif -# endif -/* RWD for WIN32 on VC++ */ -# ifndef MSVC -# include -# endif -# endif -# endif -# include -#endif - -#endif /* __BUILDING_LIBCSOUND || CSOUND_CSDL_H */ - -/* standard integer types */ - -#if defined(USE_GUSI2) -/* When compiling with GUSI on MacOS 9 (for Python), */ -/* all of the other integer types are already defined */ -typedef int64_t int_least64_t; -typedef uint64_t uint_least64_t; -#elif defined(HAVE_STDINT_H) || defined(HAVE_C99) -# include -#else -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned int uint32_t; -# if defined(__GNUC__) || !defined(WIN32) -typedef long long int64_t; -typedef unsigned long long uint64_t; -typedef long long int_least64_t; -typedef unsigned long long uint_least64_t; -# else -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; -typedef __int64 int_least64_t; -typedef unsigned __int64 uint_least64_t; -# endif -#if !defined(MSVC) -typedef long intptr_t; -typedef unsigned long uintptr_t; -#endif -#endif /* !(USE_GUSI2 || HAVE_STDINT_H || HAVE_C99) */ - -/* function attributes */ - -#if defined(HAVE_GCC3) && !defined(SWIG) -/* deprecated function, variable, or type that is to be removed eventually */ -# define CS_DEPRECATED __attribute__ ((__deprecated__)) -/* a function that should not be inlined */ -# define CS_NOINLINE __attribute__ ((__noinline__)) -/* a function that never returns (e.g. csoundDie()) */ -# define CS_NORETURN __attribute__ ((__noreturn__)) -/* printf-style function with first argument as format string */ -# define CS_PRINTF1 __attribute__ ((__format__ (__printf__, 1, 2))) -/* printf-style function with second argument as format string */ -# define CS_PRINTF2 __attribute__ ((__format__ (__printf__, 2, 3))) -/* printf-style function with third argument as format string */ -# define CS_PRINTF3 __attribute__ ((__format__ (__printf__, 3, 4))) -/* a function with no side effects or dependencies on volatile data */ -# define CS_PURE __attribute__ ((__pure__)) -# define LIKELY(x) __builtin_expect(!!(x),1) -# define UNLIKELY(x) __builtin_expect(!!(x),0) -#else -# define CS_DEPRECATED -# define CS_NOINLINE -# define CS_NORETURN -# define CS_PRINTF1 -# define CS_PRINTF2 -# define CS_PRINTF3 -# define CS_PURE -# define LIKELY(x) x -# define UNLIKELY(x) x -#endif - -#if defined(__BUILDING_LIBCSOUND) || defined(CSOUND_CSDL_H) - -/* macros for converting floats to integers */ -/* MYFLT2LONG: converts with unspecified rounding */ -/* MYFLT2LRND: rounds to nearest integer */ - -#ifdef USE_LRINT -# ifndef USE_DOUBLE -# define MYFLT2LONG(x) ((int32) lrintf((float) (x))) -# define MYFLT2LRND(x) ((int32) lrintf((float) (x))) -# else -# define MYFLT2LONG(x) ((int32) lrint((double) (x))) -# define MYFLT2LRND(x) ((int32) lrint((double) (x))) -# endif -#elif defined(MSVC) -# ifndef USE_DOUBLE -static inline int32 MYFLT2LRND(float fval) -{ - int result; - _asm { - fld fval - fistp result - mov eax, result - } - return result; -} -# else -static inline int32 MYFLT2LRND(double fval) -{ - int result; - _asm { - fld fval - fistp result - mov eax, result - } - return result; -} -# endif -# define MYFLT2LONG(x) MYFLT2LRND(x) -#else -# ifndef USE_DOUBLE -# define MYFLT2LONG(x) ((int32) (x)) -# if defined(HAVE_GCC3) && defined(__i386__) && !defined(__ICC) -# define MYFLT2LRND(x) ((int32) lrintf((float) (x))) -# else -static inline int32 MYFLT2LRND(float fval) -{ - return ((int32) (fval + (fval < 0.0f ? -0.5f : 0.5f))); -} -# endif -# else -# define MYFLT2LONG(x) ((int32) (x)) -# if defined(HAVE_GCC3) && defined(__i386__) && !defined(__ICC) -# define MYFLT2LRND(x) ((int32) lrint((double) (x))) -# else -static inline int32 MYFLT2LRND(double fval) -{ - return ((int32) (fval + (fval < 0.0 ? -0.5 : 0.5))); -} -# endif -# endif -#endif - -/* inline functions and macros for clamping denormals to zero */ - -#if defined(__i386__) || defined(MSVC) -static inline float csoundUndenormalizeFloat(float x) -{ - volatile float tmp = 1.0e-30f; - return ((x + 1.0e-30f) - tmp); -} - -static inline double csoundUndenormalizeDouble(double x) -{ - volatile double tmp = 1.0e-200; - return ((x + 1.0e-200) - tmp); -} -#else -# define csoundUndenormalizeFloat(x) x -# define csoundUndenormalizeDouble(x) x -#endif - -#ifndef USE_DOUBLE -# define csoundUndenormalizeMYFLT csoundUndenormalizeFloat -#else -# define csoundUndenormalizeMYFLT csoundUndenormalizeDouble -#endif - -#endif /* __BUILDING_LIBCSOUND || CSOUND_CSDL_H */ - -#endif /* CSOUND_SYSDEP_H */ - diff -Nru csound-5.17.11~dfsg/H/text.h csound-6.02~dfsg/H/text.h --- csound-5.17.11~dfsg/H/text.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/text.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,158 +0,0 @@ -#/* - text.h: - - Copyright (C) 1999 John ffitch - Jan 27 2005: Replaced with new implementation by Istvan Varga - Dec 25 2007: Added gettext support by John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_TEXT_H -#define CSOUND_TEXT_H - -/* list of languages */ - - typedef enum { - CSLANGUAGE_DEFAULT = 0, - CSLANGUAGE_AFRIKAANS, - CSLANGUAGE_ALBANIAN, - CSLANGUAGE_ARABIC, - CSLANGUAGE_ARMENIAN, - CSLANGUAGE_ASSAMESE, - CSLANGUAGE_AZERI, - CSLANGUAGE_BASQUE, - CSLANGUAGE_BELARUSIAN, - CSLANGUAGE_BENGALI, - CSLANGUAGE_BULGARIAN, - CSLANGUAGE_CATALAN, - CSLANGUAGE_CHINESE, - CSLANGUAGE_CROATIAN, - CSLANGUAGE_CZECH, - CSLANGUAGE_DANISH, - CSLANGUAGE_DUTCH, - CSLANGUAGE_ENGLISH_UK, - CSLANGUAGE_ENGLISH_US, - CSLANGUAGE_ESTONIAN, - CSLANGUAGE_FAEROESE, - CSLANGUAGE_FARSI, - CSLANGUAGE_FINNISH, - CSLANGUAGE_FRENCH, - CSLANGUAGE_GEORGIAN, - CSLANGUAGE_GERMAN, - CSLANGUAGE_GREEK, - CSLANGUAGE_GUJARATI, - CSLANGUAGE_HEBREW, - CSLANGUAGE_HINDI, - CSLANGUAGE_HUNGARIAN, - CSLANGUAGE_ICELANDIC, - CSLANGUAGE_INDONESIAN, - CSLANGUAGE_ITALIAN, - CSLANGUAGE_JAPANESE, - CSLANGUAGE_KANNADA, - CSLANGUAGE_KASHMIRI, - CSLANGUAGE_KAZAK, - CSLANGUAGE_KONKANI, - CSLANGUAGE_KOREAN, - CSLANGUAGE_LATVIAN, - CSLANGUAGE_LITHUANIAN, - CSLANGUAGE_MACEDONIAN, - CSLANGUAGE_MALAY, - CSLANGUAGE_MALAYALAM, - CSLANGUAGE_MANIPURI, - CSLANGUAGE_MARATHI, - CSLANGUAGE_NEPALI, - CSLANGUAGE_NORWEGIAN, - CSLANGUAGE_ORIYA, - CSLANGUAGE_POLISH, - CSLANGUAGE_PORTUGUESE, - CSLANGUAGE_PUNJABI, - CSLANGUAGE_ROMANIAN, - CSLANGUAGE_RUSSIAN, - CSLANGUAGE_SANSKRIT, - CSLANGUAGE_SERBIAN, - CSLANGUAGE_SINDHI, - CSLANGUAGE_SLOVAK, - CSLANGUAGE_SLOVENIAN, - CSLANGUAGE_SPANISH, - CSLANGUAGE_SWAHILI, - CSLANGUAGE_SWEDISH, - CSLANGUAGE_TAMIL, - CSLANGUAGE_TATAR, - CSLANGUAGE_TELUGU, - CSLANGUAGE_THAI, - CSLANGUAGE_TURKISH, - CSLANGUAGE_UKRAINIAN, - CSLANGUAGE_URDU, - CSLANGUAGE_UZBEK, - CSLANGUAGE_VIETNAMESE, - CSLANGUAGE_COLUMBIAN -} cslanguage_t; - -#ifdef GNU_GETTEXT -#ifdef __cplusplus -extern "C" { -#endif -#include - /* This could be gettext but this indirection helps debugging */ -#define Str(x) csoundLocalizeString(x) -void init_getstring(void); -#ifdef __cplusplus -} -#endif - -#else -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __BUILDING_LIBCSOUND - -/* Deal with localisation of mesages */ - -#define Str(x) (x) - -/* NOTE: function prototypes are in csound.h */ - -/* - * Set language to 'lang_code' (lang_code can be for example - * CSLANGUAGE_ENGLISH_UK or CSLANGUAGE_FRENCH or many others, - * see n_getstr.h for the list of languages). This affects all - * Csound instances running in the address space of the current - * process. The special language code CSLANGUAGE_DEFAULT can be - * used to disable translation of messages and free all memory - * allocated by a previous call to csoundSetLanguage(). - * csoundSetLanguage() loads all files for the selected language - * from the directory specified by the CSSTRNGS environment - * variable. - */ - -void init_getstring(void); - -#endif /* __BUILDING_LIBCSOUND */ - -#ifdef __cplusplus -} -#endif -void init_getstring(void); - -#endif -#define Str_noop(x) x - -#endif /* CSOUND_TEXT_H */ - diff -Nru csound-5.17.11~dfsg/H/tok.h csound-6.02~dfsg/H/tok.h --- csound-5.17.11~dfsg/H/tok.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/tok.h 2014-01-07 16:53:47.000000000 +0000 @@ -6,19 +6,6 @@ /* typedef int (*SUBR)(void *, void *); */ -typedef struct ORCTOKEN { - int type; - char *lexeme; - int value; - double fvalue; -/* char *ins,*outs; - int size;*/ - /* SUBR init,perform,denit; */ - struct ORCTOKEN *next; -} ORCTOKEN; - extern ORCTOKEN *new_token(CSOUND *, int); -#define HASH_SIZE (4099) - #endif diff -Nru csound-5.17.11~dfsg/H/ugens1.h csound-6.02~dfsg/H/ugens1.h --- csound-5.17.11~dfsg/H/ugens1.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens1.h 2014-01-07 16:53:47.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -/* UGENS1.H */ +/* UGENS1.H */ typedef struct { OPDS h; @@ -60,6 +60,17 @@ OPDS h; MYFLT *rslt, *argums[VARGMAX]; SEG *cursegp; + int32 nsegs; + int32 segsrem, curcnt; + double y1, y2, x, inc; + AUXCH auxch; + int32 xtra; +} COSSEG; + +typedef struct { + OPDS h; + MYFLT *rslt, *argums[VARGMAX]; + SEG *cursegp; int32 segsrem, curcnt; double curval, curmlt, curamlt; int32 nsegs; diff -Nru csound-5.17.11~dfsg/H/ugens2.h csound-6.02~dfsg/H/ugens2.h --- csound-5.17.11~dfsg/H/ugens2.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens2.h 2014-01-07 16:54:20.000000000 +0000 @@ -69,4 +69,5 @@ MYFLT *sr, *xamp, *xcps, *ifn, *iphs; int32 lphs; FUNC *ftp; + FUNC FF; } OSC; diff -Nru csound-5.17.11~dfsg/H/ugens3.h csound-6.02~dfsg/H/ugens3.h --- csound-5.17.11~dfsg/H/ugens3.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens3.h 2014-01-07 16:53:47.000000000 +0000 @@ -33,7 +33,8 @@ typedef struct { OPDS h; - MYFLT *ar1,*ar2,*xamp,*kcps,*ifn,*ibas,*imod1,*ibeg1,*iend1,*imod2,*ibeg2,*iend2; + MYFLT *ar1,*ar2,*xamp,*kcps,*ifn,*ibas,*imod1,*ibeg1,*iend1, + *imod2,*ibeg2,*iend2; MYFLT cpscvt; int32 lphs; int16 mod1, mod2; diff -Nru csound-5.17.11~dfsg/H/ugens4.h csound-6.02~dfsg/H/ugens4.h --- csound-5.17.11~dfsg/H/ugens4.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens4.h 2014-01-07 16:54:20.000000000 +0000 @@ -65,7 +65,7 @@ MYFLT *ar, *xamp, *xcps, *iseed, *sel, *base; int16 ampcod, cpscod, new; int rand; - int32 phs; + long phs; MYFLT num1; } RANDH; @@ -74,6 +74,6 @@ MYFLT *ar, *xamp, *xcps, *iseed, *sel, *base; int16 ampcod, cpscod, new; int rand; - int32 phs; + long phs; MYFLT num1, num2, dfdmax; } RANDI; diff -Nru csound-5.17.11~dfsg/H/ugens5.h csound-6.02~dfsg/H/ugens5.h --- csound-5.17.11~dfsg/H/ugens5.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens5.h 2014-01-07 16:53:47.000000000 +0000 @@ -21,12 +21,13 @@ 02111-1307 USA */ -#include "lpc.h" /* UGENS5.H */ +#include "lpc.h" /* UGENS5.H */ typedef struct { OPDS h; MYFLT *kr, *ksig, *ihtim, *isig; double c1, c2, yt1; + MYFLT ihtim_old; } PORT; typedef struct { @@ -60,7 +61,7 @@ typedef struct { OPDS h; - MYFLT *krmr, *krmo, *kerr, *kcps, *ktimpt, *ifilno, *inpoles, *ifrmrate; + MYFLT *krmr, *krmo, *kerr, *kcps, *ktimpt, *ifilcod, *inpoles, *ifrmrate; int32 headlen, npoles, nvals, lastfram16, lastmsg; MYFLT kcoefs[MAXPOLES*2], framrat16; int storePoles ; @@ -122,3 +123,25 @@ MYFLT kcoefs[MAXPOLES*2], framrat16; int storePoles ; } LPINTERPOL ; + +typedef struct { + OPDS h; + MYFLT *ans, *sig, *min, *max; +} LIMIT; + +typedef PORT KPORT; +typedef TONE KTONE; +typedef RESON KRESON; + +int kporset(CSOUND*,PORT *p); +int kport(CSOUND*,PORT *p); +int ktonset(CSOUND*,TONE *p); +int ktone(CSOUND*,TONE *p); +int katone(CSOUND*,TONE *p); +int krsnset(CSOUND*,RESON *p); +int kreson(CSOUND*,RESON *p); +int kareson(CSOUND*,RESON *p); +int limitset(CSOUND*,LIMIT *p); +int klimit(CSOUND*,LIMIT *p); +int limit(CSOUND*,LIMIT *p); + diff -Nru csound-5.17.11~dfsg/H/ugens6.h csound-6.02~dfsg/H/ugens6.h --- csound-5.17.11~dfsg/H/ugens6.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugens6.h 2014-01-07 16:53:47.000000000 +0000 @@ -27,7 +27,7 @@ typedef struct { OPDS h; MYFLT *kr, *asig, *ilen; - int len; + unsigned int len; } DOWNSAMP; typedef struct { @@ -67,7 +67,7 @@ OPDS h; MYFLT *ar, *indx, *idlt, *istor; MYFLT *curp; - int32 npts; + uint32_t npts; AUXCH auxch; struct DELAYR *next_delayr; /* fifo for delayr pointers by Jens Groh */ } DELAYR; @@ -155,6 +155,7 @@ int delay1(CSOUND *, DELAY1 *p); int cmbset(CSOUND *, COMB *p); int comb(CSOUND *, COMB *p); +int invcomb(CSOUND *, COMB *p); int alpass(CSOUND *, COMB *p); void reverbinit(CSOUND *); int rvbset(CSOUND *, REVERB *p); diff -Nru csound-5.17.11~dfsg/H/ugrw1.h csound-6.02~dfsg/H/ugrw1.h --- csound-5.17.11~dfsg/H/ugrw1.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugrw1.h 2014-01-07 16:53:47.000000000 +0000 @@ -241,7 +241,8 @@ typedef struct { OPDS h; MYFLT *sig; - MYFLT *ndx, *mix; /* Locations to read; 0 for write directly, or addd in */ + MYFLT *ndx, *mix; /* Locations to read; + 0 for write directly, or addd in */ } ZAWM; /* ZAWOD data structure for zamod(). */ @@ -292,6 +293,7 @@ int32 cysofar; /* Number of print cycles so far from 0 */ int initialised; char txtstring[8192]; /* Place to store the string printed */ + char* old; } PRINTKS; /* an i-rate-only prints */ @@ -327,13 +329,13 @@ int instimes(CSOUND*,RDTIME *p); int instimset(CSOUND*,RDTIME *p); int inz(CSOUND*,IOZ *p); -int itablecopy(CSOUND*,TABLECOPY *p); -int itablegpw(CSOUND*,TABLEGPW *p); -int itablemix(CSOUND*,TABLEMIX *p); -int itableng(CSOUND*,TABLENG *p); -int itablew(CSOUND*,TABLEW *p); -int ktablew(CSOUND*,TABLEW *p); -int ktablewkt(CSOUND*,TABLEW *p); +//int itablecopy(CSOUND*,TABLECOPY *p); +//int itablegpw(CSOUND*,TABLEGPW *p); +//int itablemix(CSOUND*,TABLEMIX *p); +//int itableng(CSOUND*,TABLENG *p); +//int itablew(CSOUND*,TABLEW *p); +//int ktablew(CSOUND*,TABLEW *p); +//int ktablewkt(CSOUND*,TABLEW *p); int outz(CSOUND*,IOZ *p); int peaka(CSOUND*,PEAK *p); int peakk(CSOUND*,PEAK *p); @@ -343,21 +345,23 @@ int printks(CSOUND*,PRINTKS *p); int printkset(CSOUND*,PRINTK *p); int printksset(CSOUND*,PRINTKS *p); +int printksset_S(CSOUND*,PRINTKS *p); int printsset(CSOUND*,PRINTS *p); -int tablecopy(CSOUND*,TABLECOPY *p); -int tablecopyset(CSOUND*,TABLECOPY *p); -int tablegpw(CSOUND*,TABLEGPW *p); -int tablemix(CSOUND*,TABLEMIX *p); -int tablemixset(CSOUND*,TABLEMIX *p); -int tableng(CSOUND*,TABLENG *p); -int tablera(CSOUND*,TABLERA *p); -int tableraset(CSOUND*,TABLERA *p); -int tablew(CSOUND*,TABLEW *p); -int tablewa(CSOUND*,TABLEWA *p); -int tablewaset(CSOUND*,TABLEWA *p); -int tablewkt(CSOUND*,TABLEW *p); -int tblsetw(CSOUND*,TABLEW *p); -int tblsetwkt(CSOUND*,TABLEW *p); +int printsset_S(CSOUND*,PRINTS *p); +//int tablecopy(CSOUND*,TABLECOPY *p); +//int tablecopyset(CSOUND*,TABLECOPY *p); +//int tablegpw(CSOUND*,TABLEGPW *p); +//int tablemix(CSOUND*,TABLEMIX *p); +//int tablemixset(CSOUND*,TABLEMIX *p); +//int tableng(CSOUND*,TABLENG *p); +//int tablera(CSOUND*,TABLERA *p); +//int tableraset(CSOUND*,TABLERA *p); +//int tablew(CSOUND*,TABLEW *p); +//int tablewa(CSOUND*,TABLEWA *p); +//int tablewaset(CSOUND*,TABLEWA *p); +//int tablewkt(CSOUND*,TABLEW *p); +//int tblsetw(CSOUND*,TABLEW *p); +//int tblsetwkt(CSOUND*,TABLEW *p); int timek(CSOUND*,RDTIME *p); int timesr(CSOUND*,RDTIME *p); int zacl(CSOUND*,ZACL *p); diff -Nru csound-5.17.11~dfsg/H/ugrw2.h csound-6.02~dfsg/H/ugrw2.h --- csound-5.17.11~dfsg/H/ugrw2.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/ugrw2.h 2014-01-07 16:53:47.000000000 +0000 @@ -45,7 +45,7 @@ * * Header file containing data structures for UGRW2.C. */ - +#ifdef SOME_FINE_DAY #include "csoundCore.h" /* KPORT data structure. @@ -149,3 +149,4 @@ int klimit(CSOUND*,LIMIT *p); int limit(CSOUND*,LIMIT *p); +#endif /* SOME_FINE_DAY */ diff -Nru csound-5.17.11~dfsg/H/ugtabs.h csound-6.02~dfsg/H/ugtabs.h --- csound-5.17.11~dfsg/H/ugtabs.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/H/ugtabs.h 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,60 @@ +/* + ugtabs.h: new implementation of table readers and writers + + Copyright (C) 2013 V Lazzarini + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + + +typedef struct _tabl { + OPDS h; + MYFLT *sig; + MYFLT *ndx, *ftable, *mode, *offset, *wrap; + MYFLT mul; + int32 np2; + int32 len; + FUNC *ftp; + int iwrap; +} TABL; + +typedef struct _tlen { + OPDS h; + MYFLT *ans, *ftable; +} TLEN; + +typedef struct _tgp { + OPDS h; + MYFLT *ftable, *ftsrc; +} TGP; + +typedef struct _tablmix { + OPDS h; + MYFLT *tab, *off, *len, *tab1, *off1, *g1, *tab2, *off2, *g2; +} TABLMIX; + +typedef struct _tablra { + OPDS h; + MYFLT *sig,*ftable,*strt,*off; +} TABLRA; + +typedef struct _tablwa { + OPDS h; + MYFLT *strt,*ftable,*sig,*off; + MYFLT pos; +} TABLWA; diff -Nru csound-5.17.11~dfsg/H/version.h csound-6.02~dfsg/H/version.h --- csound-5.17.11~dfsg/H/version.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/H/version.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,61 +0,0 @@ -/* - version.h: - - Copyright (C) 1995 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#ifndef CSOUND_VERSION_H -#define CSOUND_VERSION_H - -#define VERSION "5.17" - -/* Define to the full name of this package. */ -#ifndef PARCS -#define CS_PACKAGE_NAME "Csound" -#else /* PARCS */ -#define CS_PACKAGE_NAME "ParCsound" -#endif /* PARCS */ - -/* Define to the full name and version of this package. */ -#ifndef PARCS -#define CS_PACKAGE_STRING "Csound " VERSION -#else /* PARCS */ -#define CS_PACKAGE_STRING "ParCsound " VERSION -#endif /* PARCS */ - -/* Define to the one symbol short name of this package. */ -#define CS_PACKAGE_TARNAME "csound" - -/* Define to the version of this package. */ -#define CS_PACKAGE_VERSION VERSION -#define CS_VERSION (5) -#define CS_SUBVER (17) -#define CS_PATCHLEVEL (11) - -#define CS_APIVERSION 2 /* should be increased anytime a new version - contains changes that an older host will - not be able to handle -- most likely this - will be a change to an API function or - the CSOUND struct */ -#define CS_APISUBVER 6 /* for minor changes that will still allow - compatiblity with older hosts */ - -#endif /* CSOUND_VERSION_H */ - Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/How_to_Build_Csound_on_Windows.doc and /tmp/soxM_lCYvY/csound-6.02~dfsg/How_to_Build_Csound_on_Windows.doc differ diff -Nru csound-5.17.11~dfsg/INSTALL csound-6.02~dfsg/INSTALL --- csound-5.17.11~dfsg/INSTALL 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/INSTALL 1970-01-01 00:00:00.000000000 +0000 @@ -1,15 +0,0 @@ -INSTALLING CSOUND 5 - -To install prebuilt binaries for Linux on Intel, Windows, and OS X, -obtain the appropriate archive or installer -from the Files page at http://sourceforge.net/projects/csound. - -To build from sources in the csound5 module in Csound CVS -at SourceForge, follow the instructions in -The Canonical Csound Reference Manual. -It is available online at http://csounds.com/manual, -in the Windows installer Csound5.02.1-win32-d.exe from SourceForge, -or by building from sources in the manual module in Csound CVS. -The installation instructions are available online at -http://csounds.com/manual/html/BuildingCsound.html - diff -Nru csound-5.17.11~dfsg/INSTALLING csound-6.02~dfsg/INSTALLING --- csound-5.17.11~dfsg/INSTALLING 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/INSTALLING 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,18 @@ +INSTALLING CSOUND 6 + +To install prebuilt binaries for Linux on Intel, Windows, and OS X, +obtain the appropriate archive or installer +from the Files page at http://sourceforge.net/projects/csound. + +To build from sources in the csound6 module in Csound GIT +at SourceForge, follow the instructions in +The Canonical Csound Reference Manual. +It is available online at http://csounds.com/manual, +in the Windows installer from SourceForge, +or by building from sources in the manual module in Csound GIT. +The installation instructions are available online at +http://csounds.com/manual/html/BuildingCsound.html + +NOTE: For Windows, follow the instructions in +"How_to_Build_Csound_on_Windows.doc" in Csound 6 GIT. + diff -Nru csound-5.17.11~dfsg/InOut/CMakeLists.txt csound-6.02~dfsg/InOut/CMakeLists.txt --- csound-5.17.11~dfsg/InOut/CMakeLists.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/CMakeLists.txt 2014-01-07 16:54:20.000000000 +0000 @@ -6,6 +6,7 @@ option(USE_PULSEAUDIO "Build the PulseAudio I/O module" ON) option(USE_PORTAUDIO "Build the PortAudio I/O module" ON) option(USE_PORTMIDI "Build the PortMIDI I/O module" ON) +option(USE_IPMIDI "Build the IPMIDI I/O module" ON) option(USE_JACK "Build the jack I/O module and opcodes" ON) option(USE_ALSA "Build the ALSA I/O module" ON) # option(USE_COREAUDIO "Build the CoreAudio I/O module" ON) @@ -14,6 +15,9 @@ option(USE_FLTK "Use FLTK for graphs and widget opcodes" ON) option(BUILD_VIRTUAL_KEYBOARD "Build Virtual MIDI keyboard" ON) + +set(CMAKE_REQUIRED_INCLUDES /usr/local/include) + # FIND LIBRARIES AND HEADERS if(USE_ALSA) @@ -21,13 +25,18 @@ check_include_file(alsa/asoundlib.h ALSA_HEADER) endif() if(USE_PORTAUDIO) + find_path(PORTAUDIO_INCLUDE_PATH portaudio.h) find_library(PORTAUDIO_LIBRARY portaudio) - check_include_file(portaudio.h PORTAUDIO_HEADER) endif() if(USE_PORTMIDI) + find_path(PORTMIDI_INCLUDE_PATH portmidi.h) find_library(PORTMIDI_LIBRARY portmidi) - find_library(PORTTIME_LIBRARY porttime) - check_include_file(portmidi.h PORTMIDI_HEADER) +# include_directories(${PORTMIDI_INCLUDE_PATH}) +# include_directories(${PORTTIME_INCLUDE_PATH}) + if(WIN32) + else() + find_library(PORTTIME_LIBRARY porttime) + endif() endif() if(USE_JACK) find_library(JACK_LIBRARY jack) @@ -55,9 +64,6 @@ find_path(COREAUDIO_INCLUDE_PATH CoreAudio.h) find_library(COREAUDIO_LIBRARY CoreAudio) endif() -if(USE_FLTK OR BUILD_VIRTUAL_KEYBOARD) - find_package(FLTK) -endif() # BUILD TARGETS @@ -83,8 +89,8 @@ endif() check_deps(USE_ALSA ALSA_HEADER ALSA_LIBRARY PTHREAD_LIBRARY) -if(USE_ALSA) - set(rtalsa_LIBS +if(USE_ALSA) + set(rtalsa_LIBS ${ALSA_LIBRARY} ${PTHREAD_LIBRARY} m) make_plugin(rtalsa rtalsa.c ${rtalsa_LIBS}) endif() @@ -102,37 +108,57 @@ make_plugin(rtpulse rtpulse.c ${PULSEAUDIO_LIBRARY} ${PULSESIMPLE_LIBRARY}) endif() -check_deps(USE_PORTAUDIO PORTAUDIO_HEADER PORTAUDIO_LIBRARY) +check_deps(USE_PORTAUDIO PORTAUDIO_INCLUDE_PATH PORTAUDIO_LIBRARY) if(USE_PORTAUDIO) set(rtpa_LIBS ${PORTAUDIO_LIBRARY}) - + include_directories(${PORTAUDIO_INCLUDE_PATH}) + if(WIN32) list(APPEND rtpa_LIBS winmm dsound ${CSOUND_WINDOWS_LIBRARIES}) endif() make_plugin(rtpa rtpa.c ${rtpa_LIBS}) + add_dependency_to_framework(portaudio ${PORTAUDIO_LIBRARY}) +endif() + +if(APPLE) + check_deps(USE_PORTMIDI PORTMIDI_INCLUDE_PATH PORTMIDI_LIBRARY) +elseif(WIN32) + check_deps(USE_PORTMIDI PORTMIDI_INCLUDE_PATH PORTTIME_INCLUDE_PATH PORTMIDI_LIBRARY) +else() + check_deps(USE_PORTMIDI PORTMIDI_INCLUDE_PATH PORTMIDI_LIBRARY PORTTIME_LIBRARY) endif() -check_deps(USE_PORTMIDI PORTMIDI_HEADER PORTMIDI_LIBRARY) if(USE_PORTMIDI) set(pmidi_LIBS ${PORTMIDI_LIBRARY}) - if(NOT APPLE) + include_directories(${PORTMIDI_INCLUDE_PATH}) + if(LINUX) list(APPEND pmidi_LIBS ${PORTTIME_LIBRARY}) endif() if(WIN32) + include_directories(${PORTTIME_INCLUDE_PATH}) list(APPEND pmidi_LIBS ${CSOUND_WINDOWS_LIBRARIES}) endif() if(LINUX AND ALSA_LIBRARY) list(APPEND pmidi_LIBS ${ALSA_LIBRARY}) endif() make_plugin(pmidi pmidi.c "${pmidi_LIBS}") + add_dependency_to_framework(pmidi ${PORTMIDI_LIBRARY}) +endif() + +#check_deps(USE_IPMIDI PORTMIDI_HEADER PORTMIDI_LIBRARY) +if(USE_IPMIDI) + if(WIN32) + set(ipmidi_LIBS ws2_32) + endif() + make_plugin(ipmidi ipmidi.c "${ipmidi_LIBS}") endif() check_deps(USE_JACK JACK_HEADER JACK_LIBRARY) if(USE_JACK) set(rtjack_LIBS "") if(LINUX) - list(APPEND rtjack_LIBS + list(APPEND rtjack_LIBS ${JACK_LIBRARY} ${PTHREAD_LIBRARY}) elseif(WIN32) list(APPEND rtjack_LIBS @@ -148,6 +174,9 @@ if(USE_FLTK) set(widgets_SRCS FL_graph.cpp winFLTK.c widgets.cpp) make_plugin(widgets "${widgets_SRCS}" "${FLTK_LIBRARIES}") + #add_dependency_to_framework(widgets ${FLTK_BASE_LIBRARY}) + #add_dependency_to_framework(widgets ${FLTK_FORMS_LIBRARY}) + #add_dependency_to_framework(widgets ${FLTK_IMAGES_LIBRARY}) endif() check_deps(BUILD_VIRTUAL_KEYBOARD FLTK_FOUND) @@ -162,6 +191,9 @@ virtual_keyboard/SliderBank.cpp virtual_keyboard/SliderData.cpp) make_plugin(virtual "${virtual_SRCS}" "${FLTK_LIBRARIES}") + #add_dependency_to_framework(virtual ${FLTK_BASE_LIBRARY}) + #add_dependency_to_framework(virtual ${FLTK_FORMS_LIBRARY}) + #add_dependency_to_framework(virtual ${FLTK_IMAGES_LIBRARY}) include_directories(".") include_directories(${FLTK_INCLUDE_DIR}) endif() diff -Nru csound-5.17.11~dfsg/InOut/FL_graph.cpp csound-6.02~dfsg/InOut/FL_graph.cpp --- csound-5.17.11~dfsg/InOut/FL_graph.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/FL_graph.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -70,7 +70,7 @@ Fl_Window *form; } FLGRAPH_GLOBALS; -#define ST(x) (((FLGRAPH_GLOBALS*) csound->flgraphGlobals)->x) +#define ST(x) ((flgraphGlobals)->x) /*void printouts(CSOUND *csound){ csound->Message(csound, "menu object: %p\n", ST(menu)); @@ -83,9 +83,17 @@ void flgraph_init(CSOUND *csound) { - if (csound->flgraphGlobals==NULL) { - csound->flgraphGlobals = - (FLGRAPH_GLOBALS*) csound->Malloc(csound,sizeof(FLGRAPH_GLOBALS)); + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); + if (flgraphGlobals==NULL) { + csound->CreateGlobalVariable(csound, "FLGRAPH_GLOBALS", + sizeof(FLGRAPH_GLOBALS)); + flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); + //csound->flgraphGlobals = + //(FLGRAPH_GLOBALS*) csound->Malloc(csound,sizeof(FLGRAPH_GLOBALS)); } ST(form) = (Fl_Window *) 0; ST(choice) = (Fl_Choice *) 0; @@ -105,6 +113,9 @@ void graph_box::draw() { + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); Fl_Window::draw(); fl_color(0, 0, 0); fl_line_style(FL_SOLID); @@ -199,6 +210,9 @@ void add_graph(CSOUND *csound, WINDAT *wdptr) { + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); WINDAT *n = (WINDAT*) malloc(sizeof(WINDAT)); int m; WINDAT *old; @@ -250,12 +264,18 @@ void do_redraw(Fl_Widget *, void *cs) { CSOUND *csound = (CSOUND*)cs; + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); ST(graph)->curr = ST(choice)->value(); ST(graph)->redraw(); } void makeWindow(CSOUND *csound, char *name) { + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); if (ST(form)) return; @@ -292,7 +312,9 @@ uintptr_t MakeWindow_FLTK(CSOUND *csound, char *name) { - + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); if (ST(form) == NULL) { makeWindow(csound, name); ST(form)->show(); @@ -301,8 +323,8 @@ return (uintptr_t) ST(form); } - int CsoundYield_FLTK(CSOUND *csound) - { + int CsoundYield_FLTK(CSOUND *csound){ + #ifndef NO_FLTK_THREADS /* nothing to do, unless no widget thread is running */ @@ -315,6 +337,9 @@ void kill_graph(CSOUND *csound, uintptr_t m) { + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); for (int i = 0; i < NUMOFWINDOWS; i++) { WINDAT *n = (WINDAT*) ST(menu)[i].user_data_; if (n != NULL && ((uintptr_t) n == m ||n->windid == m)) { @@ -330,6 +355,9 @@ int ExitGraph_FLTK(CSOUND *csound) { + FLGRAPH_GLOBALS *flgraphGlobals = + (FLGRAPH_GLOBALS *) csound->QueryGlobalVariable(csound, + "FLGRAPH_GLOBALS"); if (ST(form) && ST(graph_created) == 1) { if (ST(form)->shown() && !(getFLTKFlags(csound) & 256)) { diff -Nru csound-5.17.11~dfsg/InOut/circularbuffer.c csound-6.02~dfsg/InOut/circularbuffer.c --- csound-5.17.11~dfsg/InOut/circularbuffer.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/InOut/circularbuffer.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,153 @@ +/* + circularbuffer.c: + + Copyright (C) 2012 Victor Lazzarini + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include + +typedef struct _circular_buffer { + char *buffer; + int wp; + int rp; + int numelem; + int elemsize; /* in number of bytes */ +} circular_buffer; + +void *csoundCreateCircularBuffer(CSOUND *csound, int numelem, int elemsize){ + circular_buffer *p; + if ((p = (circular_buffer *) + csound->Malloc(csound, sizeof(circular_buffer))) == NULL) { + return NULL; + } + p->numelem = numelem; + p->wp = p->rp = 0; + p->elemsize = elemsize; + + if ((p->buffer = (char *) csound->Malloc(csound, numelem*elemsize)) == NULL) { + return NULL; + } + memset(p->buffer, 0, numelem*elemsize); + return (void *)p; +} + +static int checkspace(circular_buffer *p, int writeCheck){ + int wp = p->wp, rp = p->rp, numelem = p->numelem; + if(writeCheck){ + if (wp > rp) return rp - wp + numelem - 1; + else if (wp < rp) return rp - wp - 1; + else return numelem - 1; + } + else { + if (wp > rp) return wp - rp; + else if (wp < rp) return wp - rp + numelem; + else return 0; + } +} + +int csoundReadCircularBuffer(CSOUND *csound, void *p, void *out, int items){ + int remaining; + int itemsread, numelem = ((circular_buffer *)p)->numelem; + int elemsize = ((circular_buffer *)p)->elemsize; + int i=0, rp = ((circular_buffer *)p)->rp; + char *buffer = ((circular_buffer *)p)->buffer; + IGN(csound); + if(p == NULL) return 0; + if ((remaining = checkspace(p, 0)) == 0) { + return 0; + } + itemsread = items > remaining ? remaining : items; + for(i=0; i < itemsread; i++){ + memcpy((char *) out + (i * elemsize), &(buffer[elemsize * rp++]), elemsize); + if (rp == numelem) { + rp = 0; + } + } + ((circular_buffer *)p)->rp = rp; + return itemsread; +} + +int csoundPeekCircularBuffer(CSOUND *csound, void *p, void *out, int items) +{ + int remaining; + int itemsread, numelem = ((circular_buffer *)p)->numelem; + int elemsize = ((circular_buffer *)p)->elemsize; + int i=0, rp = ((circular_buffer *)p)->rp; + char *buffer = ((circular_buffer *)p)->buffer; + IGN(csound); + if(p == NULL) return 0; + if ((remaining = checkspace(p, 0)) == 0) { + return 0; + } + itemsread = items > remaining ? remaining : items; + for(i=0; i < itemsread; i++){ + memcpy((char *) out + (i * elemsize), &(buffer[elemsize * rp++]), elemsize); + if (rp == numelem) { + rp = 0; + } + } + return itemsread; +} + +void csoundFlushCircularBuffer(CSOUND *csound, void *p){ + int remaining; + int itemsread, numelem = ((circular_buffer *)p)->numelem; + int i=0, rp = ((circular_buffer *)p)->rp; + //MYFLT *buffer = ((circular_buffer *)p)->buffer; + IGN(csound); + if(p == NULL) return; + if ((remaining = checkspace(p, 0)) == 0) { + return; + } + itemsread = numelem > remaining ? remaining: numelem; + for(i=0; i < itemsread; i++){ + rp++; + if(rp == numelem) rp = 0; + } + ((circular_buffer *)p)->rp = rp; +} + + +int csoundWriteCircularBuffer(CSOUND *csound, void *p, const void *in, int items){ + int remaining; + int itemswrite, numelem = ((circular_buffer *)p)->numelem; + int elemsize = ((circular_buffer *)p)->elemsize; + int i=0, wp = ((circular_buffer *)p)->wp; + char *buffer = ((circular_buffer *)p)->buffer; + IGN(csound); + if(p == NULL) return 0; + if ((remaining = checkspace(p, 1)) == 0) { + return 0; + } + itemswrite = items > remaining ? remaining : items; + for(i=0; i < itemswrite; i++){ + memcpy(&(buffer[elemsize * wp++]), + ((char *) in) + (i * elemsize), elemsize); + if(wp == numelem) wp = 0; + } + ((circular_buffer *)p)->wp = wp; + return itemswrite; +} + +void csoundDestroyCircularBuffer(CSOUND *csound, void *p){ + if(p == NULL) return; + csound->Free(csound, ((circular_buffer *)p)->buffer); + csound->Free(csound, p); +} diff -Nru csound-5.17.11~dfsg/InOut/cmidi.c csound-6.02~dfsg/InOut/cmidi.c --- csound-5.17.11~dfsg/InOut/cmidi.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/cmidi.c 2014-01-07 16:53:47.000000000 +0000 @@ -30,9 +30,6 @@ #include "csdl.h" /* CMIDI.C */ #include "csGblMtx.h" #include "midiops.h" -#include "oload.h" - - /* MIDI message queue size */ @@ -76,6 +73,31 @@ } +static int listDevices(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput){ + int k, endpoints; + MIDIEndpointRef endpoint; + CFStringRef name = NULL; + CFStringEncoding defaultEncoding = CFStringGetSystemEncoding(); + char tmp[64]; + char *drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); + if(isOutput) return 0; + endpoints = MIDIGetNumberOfSources(); + if(list == NULL) return endpoints; + for(k=0; k < endpoints; k++) { + endpoint = MIDIGetSource(k); + MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &name); + strncpy(list[k].device_name, CFStringGetCStringPtr(name, defaultEncoding), 63); + sprintf(tmp, "%d", k); + strncpy(list[k].device_id, tmp, 63); + list[k].isOutput = isOutput; + strcpy(list[k].interface_name, ""); + strncpy(list[k].midi_module, drv, 63); + } + if(name) CFRelease(name); + return endpoints; +} + + /* csound MIDI input open callback, sets the device for input */ static int MidiInDeviceOpen(CSOUND *csound, void **userData, const char *dev) { @@ -92,7 +114,6 @@ refcon->mdata = mdata; refcon->p = 0; refcon->q = 0; - /* MIDI client */ cname = CFStringCreateWithCString(NULL, "my client", defaultEncoding); ret = MIDIClientCreate(cname, NULL, NULL, &mclient); @@ -103,15 +124,15 @@ if(!ret){ /* sources, we connect to all available input sources */ endpoints = MIDIGetNumberOfSources(); - csound->Message(csound, "%d MIDI sources in system \n", endpoints); + csound->Message(csound, Str("%d MIDI sources in system \n"), endpoints); if(!strcmp(dev,"all")) { - csound->Message(csound, "receiving from all sources \n"); + csound->Message(csound, Str("receiving from all sources \n")); for(k=0; k < endpoints; k++){ endpoint = MIDIGetSource(k); long srcRefCon = (long) endpoint; MIDIPortConnectSource(mport, endpoint, (void *) srcRefCon); MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &name); - csound->Message(csound, "connecting midi device %d: %s \n", k, + csound->Message(csound, Str("connecting midi device %d: %s \n"), k, CFStringGetCStringPtr(name, defaultEncoding)); } } @@ -122,13 +143,13 @@ long srcRefCon = (long) endpoint; MIDIPortConnectSource(mport, endpoint, (void *) srcRefCon); MIDIObjectGetStringProperty(endpoint, kMIDIPropertyName, &name); - csound->Message(csound, "connecting midi device %d: %s \n", k, + csound->Message(csound, Str("connecting midi device %d: %s \n"), k, CFStringGetCStringPtr(name, defaultEncoding)); } else csound->Message(csound, - "MIDI device number %d is out-of-range, " - "not connected \n", k); + Str("MIDI device number %d is out-of-range, " + "not connected \n"), k); } } @@ -145,7 +166,7 @@ static int MidiOutDeviceOpen(CSOUND *csound, void **userData, const char *dev) { /*stub for the moment */ - csound->Message(csound, "output not implemented yet in CoreMIDI \n"); + csound->Message(csound, Str("output not implemented yet in CoreMIDI \n")); return 0; } @@ -207,9 +228,11 @@ static int MidiInDeviceClose(CSOUND *csound, void *userData) { cdata * data = (cdata *)userData; - MIDIClientDispose(data->mclient); - free(data->mdata); - free(data); + if(data != NULL) { + MIDIClientDispose(data->mclient); + free(data->mdata); + free(data); + } return 0; } @@ -217,6 +240,11 @@ const unsigned char *mbuf, int nbytes) { /* stub at the moment */ + /* + + + + */ return nbytes; } @@ -233,14 +261,14 @@ PUBLIC int csoundModuleCreate(CSOUND *csound) { /* nothing to do, report success */ - csound->Message(csound, Str("CoreMIDI real time MIDI plugin for Csound\n")); + //csound->Message(csound, Str("CoreMIDI real time MIDI plugin for Csound\n")); return 0; } PUBLIC int csoundModuleInit(CSOUND *csound) { char *drv; - + csound->module_list_add(csound, "coremidi", "midi"); drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); if (drv == NULL) return 0; @@ -254,6 +282,7 @@ csound->SetExternalMidiOutOpenCallback(csound, MidiOutDeviceOpen); csound->SetExternalMidiWriteCallback(csound, MidiDataWrite); csound->SetExternalMidiOutCloseCallback(csound, MidiOutDeviceClose); + csound->SetMIDIDeviceListCallback(csound,listDevices); return 0; } diff -Nru csound-5.17.11~dfsg/InOut/ipmidi.c csound-6.02~dfsg/InOut/ipmidi.c --- csound-5.17.11~dfsg/InOut/ipmidi.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/InOut/ipmidi.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,188 @@ +/* + ipmidi.c: + + Copyright (C) 2012 Henri Manson + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +/* Realtime MIDI using ipmidi library */ + +#include +#ifdef WIN32 +#include +#include +#else +#include +#include +#include +#include +#endif +#include + +#include "csdl.h" /* IPMIDI.C */ +#include "csGblMtx.h" +#include "midiops.h" +#include "oload.h" + +static int OpenMidiInDevice_(CSOUND *csound, void **userData, const char *dev) +{ + static int sock; + int status; + struct sockaddr_in saddr; + struct ip_mreq mreq; + +#ifdef WIN32 + WSADATA wsaData; + if (WSAStartup (MAKEWORD(2, 2), &wsaData) != 0) { + fprintf(stderr, Str("WSAStartup failed!\n")); + return -1; + } +#endif + printf("OpenMidiInDevice_: %s\n", dev); + // set content of struct saddr and imreq to zero + memset(&saddr, 0, sizeof(struct sockaddr_in)); + + // open a UDP socket + sock = socket(PF_INET, SOCK_DGRAM, 0); + if ( sock < 0 ) { + perror(Str("Error creating socket")); + return -1; + } + + saddr.sin_family = AF_INET; + saddr.sin_addr.s_addr = htonl(INADDR_ANY); + saddr.sin_port = htons(21928); + + status = bind(sock, (struct sockaddr *) &saddr, sizeof(struct sockaddr_in)); + if ( status < 0 ) { +#ifdef WIN32 + char *buff = strerror(errno); + printf("WSAGetLastError() = %d\n", WSAGetLastError()); +#else + char buff[128]; + strerror_r(errno, buff, 128); +#endif + + csound->ErrorMsg(csound, Str("Error binding socket to interface: %s"), + buff); + //perror("Error binding socket to interface"); + return -1; + } + + mreq.imr_multiaddr.s_addr = inet_addr("225.0.0.37"); + mreq.imr_interface.s_addr = htonl(INADDR_ANY); + status = setsockopt(sock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); + + if ( status < 0 ) { +#ifdef WIN32 + char *buff = strerror(errno); + csound->ErrorMsg(csound, "WSAGetLastError() = %d\n", WSAGetLastError()); + return -1; +#else + char buff[128]; + strerror_r(errno, buff, 128); + + csound->ErrorMsg(csound, Str("Error adding membership to interface: %s"), + buff); + return NOTOK; + //perror("Error binding socket to interface"); +#endif + } + + *userData = (void*) &sock; + /* report success */ + return 0; +} + +static int ReadMidiData_(CSOUND *csound, void *userData, + unsigned char *mbuf, int nbytes) +{ + int n; + int sock = *((int *) userData); + fd_set rset; + struct timeval timeout; + int rc; + + n = 0; + FD_ZERO(&rset); + FD_SET(sock, &rset); + timeout.tv_sec = 0; + timeout.tv_usec = 0; + + rc = select(sock + 1, &rset, NULL, NULL, &timeout); + if (rc > 0) { +#ifdef WIN32 + n = recv(sock, mbuf, nbytes, 0); +#else + n = read(sock, mbuf, nbytes); +#endif + printf("ReadMidiData__ n = %d\n", n); + } + + /* return the number of bytes read */ + return n; +} + +static int CloseMidiInDevice_(CSOUND *csound, void *userData) +{ + int sock = *((int *) userData); + //printf("CloseMidiInDevice_\n"); + close(sock); +#ifdef WIN32 + WSACleanup(); +#endif + return 0; +} + +/* module interface functions */ + +PUBLIC int csoundModuleCreate(CSOUND *csound) +{ + OPARMS oparms; + csound->GetOParms(csound, &oparms); + /* nothing to do, report success */ + if (oparms.msglevel & 0x400) + csound->Message(csound, Str("ipMIDI real time MIDI plugin for Csound\n")); + return 0; +} + +PUBLIC int csoundModuleInit(CSOUND *csound) +{ + char *drv; + OPARMS oparms; + csound->GetOParms(csound, &oparms); + + drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); + if (drv == NULL) + return 0; + if (strcmp(drv, "ipmidi") != 0) + return 0; + if (oparms.msglevel & 0x400) + csound->Message(csound, Str("ipmidi: ipMIDI module enabled\n")); + csound->SetExternalMidiInOpenCallback(csound, OpenMidiInDevice_); + csound->SetExternalMidiReadCallback(csound, ReadMidiData_); + csound->SetExternalMidiInCloseCallback(csound, CloseMidiInDevice_); + return 0; +} + +PUBLIC int csoundModuleInfo(void) +{ + /* does not depend on MYFLT type */ + return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8)); +} diff -Nru csound-5.17.11~dfsg/InOut/libmpadec/mp3dec.c csound-6.02~dfsg/InOut/libmpadec/mp3dec.c --- csound-5.17.11~dfsg/InOut/libmpadec/mp3dec.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/libmpadec/mp3dec.c 2014-01-07 16:53:47.000000000 +0000 @@ -42,7 +42,8 @@ int mp3dec_init_file(mp3dec_t mp3dec, int fd, int64_t length, int nogap) { register struct mp3dec_t *mp3 = (struct mp3dec_t *)mp3dec; - int64_t tmp; int r; + int64_t tmp; + int r; if (!mp3 || (mp3->size != sizeof(struct mp3dec_t)) || !mp3->mpadec) return MP3DEC_RETCODE_INVALID_HANDLE; @@ -89,7 +90,8 @@ mp3->stream_position = mp3->in_buffer_used; } else { int32_t n = sizeof(mp3->in_buffer); - if (mp3->stream_size && (n > mp3->stream_size)) n = (int32_t)mp3->stream_size; + if (mp3->stream_size && (n > mp3->stream_size)) + n = (int32_t)mp3->stream_size; n = read(fd, mp3->in_buffer, n); if (n < 0) n = 0; mp3->stream_position = mp3->in_buffer_used = n; diff -Nru csound-5.17.11~dfsg/InOut/libmpadec/synth.c csound-6.02~dfsg/InOut/libmpadec/synth.c --- csound-5.17.11~dfsg/InOut/libmpadec/synth.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/libmpadec/synth.c 2014-01-07 16:53:47.000000000 +0000 @@ -49,7 +49,7 @@ MYFLT tmp1[32], tmp2[32]; { - register MYFLT *in = samples; + MYFLT *in = samples; tmp1[0] = in[0] + in[31]; tmp1[1] = in[1] + in[30]; @@ -272,7 +272,7 @@ tmp1[29] += tmp1[31]; } { - register MYFLT tmp, *out0 = outptr0, *out1 = outptr1; + MYFLT tmp, *out0 = outptr0, *out1 = outptr1; out0[16*16] = tmp1[0]; out0[12*16] = tmp1[4]; @@ -321,7 +321,7 @@ static void synth_full(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer) { - register struct mpadec_t *mpa = (struct mpadec_t *)mpadec; + struct mpadec_t *mpa = (struct mpadec_t *)mpadec; unsigned bo; MYFLT *b0, (*buf)[0x110]; @@ -341,12 +341,12 @@ dct64(buf[0] + mpa->synth_bufoffs, buf[1] + (mpa->synth_bufoffs + 1), bandptr); } { - register int i; - register MYFLT *out = buffer; - register MYFLT *win = mpa->tables.decwin + (16 - bo); + int i; + MYFLT *out = buffer; + MYFLT *win = mpa->tables.decwin + (16 - bo); for (i = 16; i; i--, win += 32, b0 += 16) { - register MYFLT sum = win[0]*b0[0]; + MYFLT sum = win[0]*b0[0]; sum -= win[1]*b0[1]; sum += win[2]*b0[2]; sum -= win[3]*b0[3]; @@ -365,7 +365,7 @@ *out++ = sum; } { - register MYFLT sum = win[0]*b0[0]; + MYFLT sum = win[0]*b0[0]; sum += win[2]*b0[2]; sum += win[4]*b0[4]; sum += win[6]*b0[6]; @@ -379,7 +379,7 @@ win += (bo << 1); for (i = 15; i; i--, win -= 32, b0 -= 16) { - register MYFLT sum = -win[-1]*b0[0]; + MYFLT sum = -win[-1]*b0[0]; sum -= win[-2]*b0[1]; sum -= win[-3]*b0[2]; sum -= win[-4]*b0[3]; @@ -402,7 +402,7 @@ static void synth_half(mpadec_t mpadec, MYFLT *bandptr, int channel, MYFLT *buffer) { - register struct mpadec_t *mpa = (struct mpadec_t *)mpadec; + struct mpadec_t *mpa = (struct mpadec_t *)mpadec; unsigned bo; MYFLT *b0, (*buf)[0x110]; @@ -423,12 +423,12 @@ buf[1] + (mpa->synth_bufoffs + 1), bandptr); } { - register int i; - register MYFLT *out = buffer; - register MYFLT *win = mpa->tables.decwin + (16 - bo); + int i; + MYFLT *out = buffer; + MYFLT *win = mpa->tables.decwin + (16 - bo); for (i = 8; i; i--, win += 64, b0 += 32) { - register MYFLT sum = win[0]*b0[0]; + MYFLT sum = win[0]*b0[0]; sum -= win[1]*b0[1]; sum += win[2]*b0[2]; sum -= win[3]*b0[3]; @@ -447,7 +447,7 @@ *out++ = sum; } { - register MYFLT sum = win[0]*b0[0]; + MYFLT sum = win[0]*b0[0]; sum += win[2]*b0[2]; sum += win[4]*b0[4]; sum += win[6]*b0[6]; @@ -461,7 +461,7 @@ win += (bo << 1); for (i = 7; i; i--, win -= 64, b0 -= 32) { - register MYFLT sum = -win[-1]*b0[0]; + MYFLT sum = -win[-1]*b0[0]; sum -= win[-2]*b0[1]; sum -= win[-3]*b0[2]; sum -= win[-4]*b0[3]; @@ -489,13 +489,13 @@ static void synth_full16lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = (uint8_t)tmp; ((int8_t *)out)[1] = (int8_t)(tmp >> 8); @@ -507,13 +507,13 @@ static void synth_full16lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = ((uint8_t *)out)[2] = (uint8_t)tmp; ((int8_t *)out)[1] = ((int8_t *)out)[3] = (int8_t)(tmp >> 8); @@ -523,14 +523,14 @@ static void synth_full16lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = (uint8_t)tmp; ((int8_t *)out)[1] = (int8_t)(tmp >> 8); @@ -542,13 +542,13 @@ static void synth_full16bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = (uint8_t)tmp; @@ -561,13 +561,13 @@ static void synth_full16bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = ((uint8_t *)out)[3] = (uint8_t)tmp; ((int8_t *)out)[0] = ((int8_t *)out)[2] = (int8_t)(tmp >> 8); @@ -577,14 +577,14 @@ static void synth_full16bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = (uint8_t)tmp; ((int8_t *)out)[0] = (int8_t)(tmp >> 8); @@ -596,13 +596,13 @@ static void synth_full24lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 3) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -616,13 +616,13 @@ static void synth_full24lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -634,14 +634,14 @@ static void synth_full24lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out += 3; for (i = 0; i < SBLIMIT; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -655,13 +655,13 @@ static void synth_full24bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 3) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = (uint8_t)tmp; @@ -675,13 +675,13 @@ static void synth_full24bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = ((uint8_t *)out)[5] = (uint8_t)tmp; @@ -693,14 +693,14 @@ static void synth_full24bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out += 3; for (i = 0; i < SBLIMIT; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = (uint8_t)tmp; @@ -714,13 +714,13 @@ static void synth_full32lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -735,13 +735,13 @@ static void synth_full32lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp; @@ -754,14 +754,14 @@ static void synth_full32lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -776,13 +776,13 @@ static void synth_full32bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -797,13 +797,13 @@ static void synth_full32bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp; @@ -816,14 +816,14 @@ static void synth_full32bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -838,18 +838,21 @@ static void synth_full32flmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = (uint8_t)tmp; - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24); } } @@ -858,37 +861,43 @@ static void synth_full32flms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp; - ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp.i >> 24); } } static void synth_full32flss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = (uint8_t)tmp; - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24); } } @@ -897,18 +906,21 @@ static void synth_full32fbmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out++) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = (uint8_t)tmp; - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24); } } @@ -917,37 +929,43 @@ static void synth_full32fbms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp; - ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp.i >> 24); } } static void synth_full32fbss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT]; synth_full(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = (uint8_t)tmp; - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24); } } @@ -958,13 +976,13 @@ static void synth_half16lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = (uint8_t)tmp; ((int8_t *)out)[1] = (int8_t)(tmp >> 8); @@ -976,13 +994,13 @@ static void synth_half16lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = ((uint8_t *)out)[2] = (uint8_t)tmp; ((int8_t *)out)[1] = ((int8_t *)out)[3] = (int8_t)(tmp >> 8); @@ -992,14 +1010,14 @@ static void synth_half16lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[0] = (uint8_t)tmp; ((int8_t *)out)[1] = (int8_t)(tmp >> 8); @@ -1011,13 +1029,13 @@ static void synth_half16bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = (uint8_t)tmp; ((int8_t *)out)[0] = (int8_t)(tmp >> 8); @@ -1029,13 +1047,13 @@ static void synth_half16bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = ((uint8_t *)out)[3] = (uint8_t)tmp; ((int8_t *)out)[0] = ((int8_t *)out)[2] = (int8_t)(tmp >> 8); @@ -1045,14 +1063,14 @@ static void synth_half16bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int16_t *out = (int16_t *)buffer; + int i; + int16_t *out = (int16_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 32767) tmp = 32767; else if (tmp < -32768) tmp = -32768; ((uint8_t *)out)[1] = (uint8_t)tmp; ((int8_t *)out)[0] = (int8_t)(tmp >> 8); @@ -1064,13 +1082,13 @@ static void synth_half24lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 3) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -1084,13 +1102,13 @@ static void synth_half24lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -1102,14 +1120,14 @@ static void synth_half24lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out += 3; for (i = 0; i < SBLIMIT/2; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -1123,13 +1141,13 @@ static void synth_half24bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 3) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = (uint8_t)tmp; @@ -1143,13 +1161,13 @@ static void synth_half24bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = ((uint8_t *)out)[5] = (uint8_t)tmp; @@ -1161,14 +1179,14 @@ static void synth_half24bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register uint8_t *out = (uint8_t *)buffer; + int i; + uint8_t *out = (uint8_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out += 3; for (i = 0; i < SBLIMIT/2; i++, out += 6) { - register int32_t tmp = LROUND(buf[i]); + int32_t tmp = LROUND(buf[i]); if (tmp > 0x7FFFFF) tmp = 0x7FFFFF; else if (tmp < -0x800000) tmp = -0x800000; ((uint8_t *)out)[2] = (uint8_t)tmp; @@ -1182,13 +1200,13 @@ static void synth_half32lmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -1203,13 +1221,13 @@ static void synth_half32lms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp; @@ -1222,14 +1240,14 @@ static void synth_half32lss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[0] = (uint8_t)tmp; @@ -1244,13 +1262,13 @@ static void synth_half32bmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -1265,13 +1283,13 @@ static void synth_half32bms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp; @@ -1284,14 +1302,14 @@ static void synth_half32bss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register int32_t *out = (int32_t *)buffer; + int i; + int32_t *out = (int32_t *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - register int64_t tmp = LLROUND(buf[i]); + int64_t tmp = LLROUND(buf[i]); if (tmp > 0x7FFFFFFF) tmp = 0x7FFFFFFF; else if (tmp < (-0x7FFFFFFF - 1)) tmp = (-0x7FFFFFFF - 1); ((uint8_t *)out)[3] = (uint8_t)tmp; @@ -1306,18 +1324,21 @@ static void synth_half32flmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = (uint8_t)tmp; - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24); } } @@ -1326,37 +1347,43 @@ static void synth_half32flms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp; - ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = ((uint8_t *)out)[4] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = ((int8_t *)out)[7] = (int8_t)(tmp.i >> 24); } } static void synth_half32flss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[0] = (uint8_t)tmp; - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[3] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[0] = (uint8_t)tmp.i; + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[3] = (int8_t)(tmp.i >> 24); } } @@ -1365,18 +1392,21 @@ static void synth_half32fbmm(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out++) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = (uint8_t)tmp; - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24); } } @@ -1385,37 +1415,43 @@ static void synth_half32fbms(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); for (i = 0; i < SBLIMIT/2; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp; - ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp >> 24); + union tmp__ { + int32_t i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = ((uint8_t *)out)[7] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = ((uint8_t *)out)[6] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = ((uint8_t *)out)[5] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = ((int8_t *)out)[4] = (int8_t)(tmp.i >> 24); } } static void synth_half32fbss(mpadec_t mpadec, MYFLT *bandptr, int channel, uint8_t *buffer) { - register int i; - register float *out = (float *)buffer; + int i; + float *out = (float *)buffer; MYFLT buf[SBLIMIT/2]; synth_half(mpadec, bandptr, channel, buf); if (channel) out++; for (i = 0; i < SBLIMIT/2; i++, out += 2) { - int32_t tmp; - *((float *)(&tmp)) = (float)buf[i]; - ((uint8_t *)out)[3] = (uint8_t)tmp; - ((uint8_t *)out)[2] = (uint8_t)(tmp >> 8); - ((uint8_t *)out)[1] = (uint8_t)(tmp >> 16); - ((int8_t *)out)[0] = (int8_t)(tmp >> 24); + union tmp__ { + int32 i; + float f; + } tmp; + tmp.f = (float)buf[i]; + ((uint8_t *)out)[3] = (uint8_t)tmp.i; + ((uint8_t *)out)[2] = (uint8_t)(tmp.i >> 8); + ((uint8_t *)out)[1] = (uint8_t)(tmp.i >> 16); + ((int8_t *)out)[0] = (int8_t)(tmp.i >> 24); } } diff -Nru csound-5.17.11~dfsg/InOut/libsnd.c csound-6.02~dfsg/InOut/libsnd.c --- csound-5.17.11~dfsg/InOut/libsnd.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/libsnd.c 2014-01-07 16:53:47.000000000 +0000 @@ -28,27 +28,6 @@ # include #endif -typedef struct { - SNDFILE *outfile; - SNDFILE *infile; - char *sfoutname; /* soundout filename */ - MYFLT *inbuf; - MYFLT *outbuf; /* contin sndio buffers */ - MYFLT *outbufp; /* MYFLT pntr */ - uint32 inbufrem; - uint32 outbufrem; /* in monosamps */ - /* (see openin, iotranset) */ - unsigned int inbufsiz, outbufsiz; /* alloc in sfopenin/out */ - int isfopen; /* (real set in sfopenin) */ - int osfopen; /* (real set in sfopenout) */ - int pipdevin, pipdevout; /* 0: file, 1: pipe, 2: rtaudio */ - uint32 nframes /* = 1UL */; - FILE *pin, *pout; -#ifndef SOME_FILE_DAY - int dither; -#endif -} LIBSND_GLOBALS; - #ifdef PIPES # if defined(SGI) || defined(LINUX) || defined(__BEOS__) || defined(NeXT) || \ defined(__MACH__) @@ -62,14 +41,11 @@ static void sndwrterr(CSOUND *, int, int); static void sndfilein_noscale(CSOUND *csound); -#define ST(x) (((LIBSND_GLOBALS*) csound->libsndGlobals)->x) +#define STA(x) (csound->libsndStatics.x) -static void alloc_globals(CSOUND *csound) +static inline void alloc_globals(CSOUND *csound) { - if (csound->libsndGlobals == NULL) { - csound->libsndGlobals = csound->Calloc(csound, sizeof(LIBSND_GLOBALS)); - ST(nframes) = (uint32)1; - } + csound->libsndStatics.nframes = (uint32)1; } /* The interface requires 2 functions: @@ -83,23 +59,27 @@ static void spoutsf(CSOUND *csound) { - int n, chn = 0, spoutrem = csound->nspout; + uint32_t chn = 0; + int n; + int spoutrem = csound->nspout; MYFLT *sp = csound->spout; - MYFLT absamp; - uint32 nframes = ST(nframes); - + MYFLT absamp = FL(0.0); + uint32 nframes = csound->libsndStatics.nframes; nchk: /* if nspout remaining > buf rem, prepare to send in parts */ - if ((n = spoutrem) > (int) ST(outbufrem)) - n = (int)ST(outbufrem); + if ((n = spoutrem) > (int) csound->libsndStatics.outbufrem) { + n = (int) csound->libsndStatics.outbufrem; + } spoutrem -= n; - ST(outbufrem) -= n; + csound->libsndStatics.outbufrem -= n; do { absamp = *sp++; - if (ST(osfopen)) - *ST(outbufp)++ = absamp * csound->dbfs_to_float; - if (absamp < FL(0.0)) + if (csound->libsndStatics.osfopen) { + *csound->libsndStatics.outbufp++ = (absamp * csound->dbfs_to_float); + } + if (absamp < FL(0.0)) { absamp = -absamp; + } if (absamp > csound->maxamp[chn]) { /* maxamp this seg */ csound->maxamp[chn] = absamp; csound->maxpos[chn] = nframes; @@ -109,44 +89,49 @@ csound->rngflg = 1; } if (csound->multichan) { - if (++chn >= csound->nchnls) - chn = 0, nframes++; - } - else + if (++chn >= csound->nchnls) { + chn = 0; + nframes++; + } + } else { nframes++; + } } while (--n); - - if (!ST(outbufrem)) { - if (ST(osfopen)) { + if (!csound->libsndStatics.outbufrem) { + if (csound->libsndStatics.osfopen) { csound->nrecs++; - csound->audtran(csound, ST(outbuf), ST(outbufsiz)); /* Flush buffer */ - ST(outbufp) = (MYFLT*) ST(outbuf); + csound->audtran(csound, csound->libsndStatics.outbuf, + csound->libsndStatics.outbufsiz); /* Flush buffer */ + csound->libsndStatics.outbufp = (MYFLT*) csound->libsndStatics.outbuf; + } + csound->libsndStatics.outbufrem = csound->oparms_.outbufsamps; + if (spoutrem) { + goto nchk; } - ST(outbufrem) = csound->oparms_.outbufsamps; - if (spoutrem) goto nchk; } - ST(nframes) = nframes; + csound->libsndStatics.nframes = nframes; } /* special version of spoutsf for "raw" floating point files */ static void spoutsf_noscale(CSOUND *csound) { - int n, chn = 0, spoutrem = csound->nspout; - MYFLT *sp = csound->spout; - MYFLT absamp; - uint32 nframes = ST(nframes); + uint32_t chn = 0; + int n, spoutrem = csound->nspout; + MYFLT *sp = csound->spout; + MYFLT absamp = FL(0.0); + uint32 nframes = csound->libsndStatics.nframes; nchk: /* if nspout remaining > buf rem, prepare to send in parts */ - if ((n = spoutrem) > (int) ST(outbufrem)) - n = (int)ST(outbufrem); + if ((n = spoutrem) > (int) csound->libsndStatics.outbufrem) + n = (int)csound->libsndStatics.outbufrem; spoutrem -= n; - ST(outbufrem) -= n; + csound->libsndStatics.outbufrem -= n; do { absamp = *sp++; - if (ST(osfopen)) - *ST(outbufp)++ = absamp; + if (csound->libsndStatics.osfopen) + *csound->libsndStatics.outbufp++ = absamp; if (absamp < FL(0.0)) absamp = -absamp; if (absamp > csound->maxamp[chn]) { /* maxamp this seg */ @@ -157,16 +142,17 @@ chn = 0, nframes++; } while (--n); - if (!ST(outbufrem)) { - if (ST(osfopen)) { + if (!csound->libsndStatics.outbufrem) { + if (csound->libsndStatics.osfopen) { csound->nrecs++; - csound->audtran(csound, ST(outbuf), ST(outbufsiz)); /* Flush buffer */ - ST(outbufp) = (MYFLT*) ST(outbuf); + csound->audtran(csound, csound->libsndStatics.outbuf, + csound->libsndStatics.outbufsiz); /* Flush buffer */ + csound->libsndStatics.outbufp = (MYFLT*) csound->libsndStatics.outbuf; } - ST(outbufrem) = csound->oparms_.outbufsamps; + csound->libsndStatics.outbufrem = csound->oparms_.outbufsamps; if (spoutrem) goto nchk; } - ST(nframes) = nframes; + csound->libsndStatics.nframes = nframes; } /* diskfile write option for audtran's */ @@ -177,14 +163,14 @@ OPARMS *O = csound->oparms; int n; - if (UNLIKELY(ST(outfile) == NULL)) + if (UNLIKELY(STA(outfile) == NULL)) return; - n = (int) sf_write_MYFLT(ST(outfile), (MYFLT*) outbuf, + n = (int) sf_write_MYFLT(STA(outfile), (MYFLT*) outbuf, nbytes / sizeof(MYFLT)) * (int) sizeof(MYFLT); if (UNLIKELY(n < nbytes)) sndwrterr(csound, n, nbytes); if (UNLIKELY(O->rewrt_hdr)) - rewriteheader((void *)ST(outfile)); + rewriteheader((void *)STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, @@ -196,12 +182,12 @@ case 3: { char s[512]; - sprintf(s, "%ld(%.3f)%n", (long) csound->nrecs, + CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; - csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); + csound->MessageS(csound, CSOUNDMSG_REALTIME, s); } } break; @@ -218,25 +204,25 @@ int m = nbytes / sizeof(MYFLT); MYFLT *buf = (MYFLT*) outbuf; - if (UNLIKELY(ST(outfile) == NULL)) + if (UNLIKELY(STA(outfile) == NULL)) return; for (n=0; n>1; /* triangular distribution */ result = (MYFLT) (rnd - 0x8000) / ((MYFLT) 0x10000); result /= ((MYFLT) 0x7fff); buf[n] += result; } - n = (int) sf_write_MYFLT(ST(outfile), (MYFLT*) outbuf, + n = (int) sf_write_MYFLT(STA(outfile), (MYFLT*) outbuf, nbytes / sizeof(MYFLT)) * (int) sizeof(MYFLT); if (UNLIKELY(n < nbytes)) sndwrterr(csound, n, nbytes); if (UNLIKELY(O->rewrt_hdr)) - rewriteheader(ST(outfile)); + rewriteheader(STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, @@ -248,12 +234,12 @@ case 3: { char s[512]; - sprintf(s, "%ld(%.3f)%n", (long) csound->nrecs, + CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; - csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); + csound->MessageS(csound, CSOUNDMSG_REALTIME, s); } } break; @@ -270,25 +256,25 @@ int m = nbytes / sizeof(MYFLT); MYFLT *buf = (MYFLT*) outbuf; - if (UNLIKELY(ST(outfile) == NULL)) + if (UNLIKELY(STA(outfile) == NULL)) return; for (n=0; n>1; /* triangular distribution */ result = (MYFLT) (rnd - 0x8000) / ((MYFLT) 0x10000); result /= ((MYFLT) 0x7f); buf[n] += result; } - n = (int) sf_write_MYFLT(ST(outfile), (MYFLT*) outbuf, + n = (int) sf_write_MYFLT(STA(outfile), (MYFLT*) outbuf, nbytes / sizeof(MYFLT)) * (int) sizeof(MYFLT); if (UNLIKELY(n < nbytes)) sndwrterr(csound, n, nbytes); if (UNLIKELY(O->rewrt_hdr)) - rewriteheader(ST(outfile)); + rewriteheader(STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, @@ -300,12 +286,12 @@ case 3: { char s[512]; - sprintf(s, "%ld(%.3f)%n", (long) csound->nrecs, + CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; - csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); + csound->MessageS(csound, CSOUNDMSG_REALTIME, s); } } break; @@ -322,23 +308,23 @@ int m = nbytes / sizeof(MYFLT); MYFLT *buf = (MYFLT*) outbuf; - if (UNLIKELY(ST(outfile) == NULL)) + if (UNLIKELY(STA(outfile) == NULL)) return; for (n=0; nrewrt_hdr)) - rewriteheader(ST(outfile)); + rewriteheader(STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, @@ -350,12 +336,12 @@ case 3: { char s[512]; - sprintf(s, "%ld(%.3f)%n", (long) csound->nrecs, + CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; - csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); + csound->MessageS(csound, CSOUNDMSG_REALTIME, s); } } break; @@ -372,23 +358,23 @@ int m = nbytes / sizeof(MYFLT); MYFLT *buf = (MYFLT*) outbuf; - if (UNLIKELY(ST(outfile) == NULL)) + if (UNLIKELY(STA(outfile) == NULL)) return; for (n=0; nrewrt_hdr)) - rewriteheader(ST(outfile)); + rewriteheader(STA(outfile)); switch (O->heartbeat) { case 1: csound->MessageS(csound, CSOUNDMSG_REALTIME, @@ -400,12 +386,12 @@ case 3: { char s[512]; - sprintf(s, "%ld(%.3f)%n", (long) csound->nrecs, + CS_SPRINTF(s, "%ld(%.3f)%n", (long) csound->nrecs, csound->icurTime/csound->esr, &n); if (n > 0) { memset(&(s[n]), '\b', n); s[n + n] = '\0'; - csound->MessageS(csound, CSOUNDMSG_REALTIME, "%s", s); + csound->MessageS(csound, CSOUNDMSG_REALTIME, s); } } break; @@ -421,12 +407,10 @@ (void) csound; n = inbufsize / (int) sizeof(MYFLT); - i = (int) sf_read_MYFLT(ST(infile), inbuf, n); + i = (int) sf_read_MYFLT(STA(infile), inbuf, n); if (UNLIKELY(i < 0)) return inbufsize; memset(&inbuf[i], 0, (n-i)*sizeof(MYFLT)); - /* while (i < n) */ - /* inbuf[i++] = FL(0.0); */ return inbufsize; } @@ -434,6 +418,7 @@ /* Returns the device number (defaults to 1024) if it is, and -1 otherwise. */ /* If a device name is specified, and 'devName' is not NULL, a pointer to it */ /* is stored in *devName. */ +/* Called from musmon, str_ops and here */ int check_rtaudio_name(char *fName, char **devName, int isOutput) { @@ -454,8 +439,9 @@ if (*s == (char) '\0') return 1024; if (*s == (char) ':') { - if (devName != NULL) - *devName = &(s[1]); + if (devName != NULL) { + *devName = &(s[1]); + } return 1024; } else { @@ -480,19 +466,19 @@ int isfd = 0; /* stdin */ alloc_globals(csound); - ST(inbufrem) = (uint32) 0; /* start with empty buffer */ + STA(inbufrem) = (uint32) 0; /* start with empty buffer */ sfname = O->infilename; if (UNLIKELY(sfname == NULL || sfname[0] == '\0')) csound->Die(csound, Str("error: no input file name")); if (strcmp(sfname, "stdin") == 0) { - ST(pipdevin) = 1; + STA(pipdevin) = 1; } #ifdef PIPES else if (sfname[0] == '|') { - ST(pin) = _popen(sfname + 1, "r"); - isfd = fileno(ST(pin)); - ST(pipdevin) = 1; + STA(pin) = _popen(sfname + 1, "r"); + isfd = fileno(STA(pin)); + STA(pipdevin) = 1; } #endif else { @@ -501,45 +487,49 @@ parm.devNum = check_rtaudio_name(sfname, &(parm.devName), 0); if (parm.devNum >= 0) { /* set device parameters */ - parm.bufSamp_SW = (int) O->inbufsamps / (int) csound->inchnls; - parm.bufSamp_HW = O->oMaxLag; - parm.nChannels = csound->nchnls; + parm.bufSamp_SW = + (unsigned int) O->inbufsamps / (unsigned int) csound->inchnls; + parm.bufSamp_HW = O->oMaxLag; + parm.nChannels = csound->nchnls; parm.sampleFormat = O->informat; - parm.sampleRate = (float) csound->esr; + parm.sampleRate = (float) csound->esr; /* open devaudio for input */ if (UNLIKELY(csound->recopen_callback(csound, &parm) != 0)) csoundDie(csound, Str("Failed to initialise real time audio input")); /* & redirect audio gets */ csound->audrecv = csound->rtrecord_callback; - ST(pipdevin) = 2; /* no backward seeks ! */ + STA(pipdevin) = 2; /* no backward seeks ! */ goto inset; /* no header processing */ } } /* open file */ memset(&sfinfo, 0, sizeof(SF_INFO)); - if (ST(pipdevin)) { - ST(infile) = sf_open_fd(isfd, SFM_READ, &sfinfo, 0); - if (UNLIKELY(ST(infile) == NULL)) { + if (STA(pipdevin)) { + STA(infile) = sf_open_fd(isfd, SFM_READ, &sfinfo, 0); + if (UNLIKELY(STA(infile) == NULL)) { /* open failed: possibly raw file, but cannot seek back to try again */ - csoundDie(csound, Str("isfinit: cannot open %s"), sfname); + const char *sfError = sf_strerror(NULL); + csoundDie(csound, Str("isfinit: cannot open %s -- %s"), sfname, sfError); } } else { fullName = csoundFindInputFile(csound, sfname, "SFDIR;SSDIR"); if (UNLIKELY(fullName == NULL)) /* if not found */ csoundDie(csound, Str("isfinit: cannot open %s"), sfname); - ST(infile) = sf_open(fullName, SFM_READ, &sfinfo); - if (ST(infile) == NULL) { + STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); + if (STA(infile) == NULL) { /* open failed: maybe raw file ? */ memset(&sfinfo, 0, sizeof(SF_INFO)); sfinfo.samplerate = (int) (csound->esr + FL(0.5)); sfinfo.channels = csound->nchnls; /* FIXME: assumes input sample format is same as output */ sfinfo.format = TYPE2SF(TYP_RAW) | FORMAT2SF(O->outformat); - ST(infile) = sf_open(fullName, SFM_READ, &sfinfo); /* try again */ + STA(infile) = sf_open(fullName, SFM_READ, &sfinfo); /* try again */ + } + if (UNLIKELY(STA(infile) == NULL)) { + const char *sfError = sf_strerror(NULL); + csoundDie(csound, Str("isfinit: cannot open %s -- %s"), fullName, sfError); } - if (UNLIKELY(ST(infile) == NULL)) - csoundDie(csound, Str("isfinit: cannot open %s"), fullName); /* only notify the host if we opened a real file, not stdin or a pipe */ csoundNotifyFileOpened(csound, fullName, sftype2csfiletype(sfinfo.format), 0, 0); @@ -567,19 +557,19 @@ inset: /* calc inbufsize reqd */ - ST(inbufsiz) = (unsigned) (O->inbufsamps * sizeof(MYFLT)); - ST(inbuf) = (MYFLT*) mcalloc(csound, ST(inbufsiz)); /* alloc inbuf space */ - if (ST(pipdevout) == 2) + STA(inbufsiz) = (unsigned) (O->inbufsamps * sizeof(MYFLT)); + STA(inbuf) = (MYFLT*) mcalloc(csound, STA(inbufsiz)); /* alloc inbuf space */ + if (STA(pipdevout) == 2) csound->Message(csound, Str("reading %d sample blks of %d-bit floats from %s \n"), O->inbufsamps * O->sfsampsize, sizeof(MYFLT)*8, sfname); else { - csound->Message(csound, - Str("reading %d-byte blks of %s from %s (%s)\n"), - O->inbufsamps * (int) sfsampsize(FORMAT2SF(O->informat)), - getstrformat(O->informat), sfname, type2string(fileType)); + csound->Message(csound, + Str("reading %d-byte blks of %s from %s (%s)\n"), + O->inbufsamps * (int) sfsampsize(FORMAT2SF(O->informat)), + getstrformat(O->informat), sfname, type2string(fileType)); } - ST(isfopen) = 1; + STA(isfopen) = 1; } void sfopenout(CSOUND *csound) /* init for sound out */ @@ -591,29 +581,98 @@ alloc_globals(csound); if (O->outfilename == NULL) { - if (O->filetyp == TYP_WAV) + switch (O->filetyp) { + case TYP_WAV: + case TYP_W64: + case TYP_WAVEX: O->outfilename = "test.wav"; - else if (O->filetyp == TYP_AIFF) + break; + case TYP_AIFF: O->outfilename = "test.aif"; - else if (O->filetyp == TYP_AU) + break; + case TYP_AU: O->outfilename = "test.au"; - else + break; + /* case TYP_PAF: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_SVX: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_NIST: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_VOC: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_IRCAM: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_MAT4: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_MAT5: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_PVF: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_XI: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_HTK: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_SDS: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_AVR: */ + /* O->outfilename = ""; */ + case TYP_SD2: + O->outfilename = "test.sd2"; + break; + case TYP_FLAC: + O->outfilename = "test.flac"; + break; + case TYP_CAF: + O->outfilename = "test.caf"; + break; + case TYP_OGG: + O->outfilename = "test.ogg"; + break; + /* case TYP_MPC2K: */ + /* O->outfilename = ""; */ + /* break; */ + /* case TYP_RF64: */ + /* O->outfilename = ""; */ + /* break; */ + default: O->outfilename = "test"; + break; + } } - ST(sfoutname) = fName = O->outfilename; + STA(sfoutname) = fName = O->outfilename; if (strcmp(fName, "stdout") == 0) { - ST(pipdevout) = 1; + STA(pipdevout) = 1; } #ifdef PIPES else if (fName[0] == '|') { - ST(pout) = _popen(fName+1, "w"); - osfd = fileno(ST(pout)); - ST(pipdevout) = 1; + STA(pout) = _popen(fName+1, "w"); + osfd = fileno(STA(pout)); + STA(pipdevout) = 1; if (O->filetyp == TYP_AIFF || O->filetyp == TYP_WAV) { - csound->Message(csound, Str("Output file type changed to IRCAM " - "for use in pipe\n")); - O->filetyp = TYP_IRCAM; + char fmt_name[6]; + if (O->sfsampsize == 8) { + strcpy(fmt_name, "AU"); + O->filetyp = TYP_AU; + } + else { + strcpy(fmt_name, "IRCAM"); + O->filetyp = TYP_IRCAM; + } + csound->Message(csound, Str("Output file type changed to %s " + "for use in pipe\n"), fmt_name); } } #endif @@ -623,24 +682,27 @@ parm.devNum = check_rtaudio_name(fName, &(parm.devName), 1); if (parm.devNum >= 0) { /* set device parameters */ - parm.bufSamp_SW = (int) O->outbufsamps / (int) csound->nchnls; - parm.bufSamp_HW = O->oMaxLag; - parm.nChannels = csound->nchnls; + parm.bufSamp_SW = (unsigned int) O->outbufsamps / csound->nchnls; + parm.bufSamp_HW = O->oMaxLag; + parm.nChannels = csound->nchnls; parm.sampleFormat = O->outformat; - parm.sampleRate = (float) csound->esr; - csound->spoutran = spoutsf; + parm.sampleRate = (float) csound->esr; + csound->spoutran = spoutsf; /* open devaudio for output */ if (csound->playopen_callback(csound, &parm) != 0) csoundDie(csound, Str("Failed to initialise real time audio output")); /* & redirect audio puts */ csound->audtran = csound->rtplay_callback; - ST(outbufrem) = parm.bufSamp_SW * parm.nChannels; - ST(pipdevout) = 2; /* no backward seeks ! */ - goto outset; /* no header needed */ + STA(outbufrem) = parm.bufSamp_SW * parm.nChannels; + STA(pipdevout) = 2; /* no backward seeks ! */ + if(O->realtime == 1) /* set realtime priority mode */ + csound->realtime_audio_flag = 1; + goto outset; /* no header needed */ } else if (strcmp(fName, "null") == 0) { - ST(outfile) = NULL; - if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT) { + STA(outfile) = NULL; + if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && + csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) if (csound->dither_output==1) csound->audtran = writesf_dither_16; @@ -661,21 +723,47 @@ } /* set format parameters */ memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.frames = -1; + sfinfo.frames = -1; sfinfo.samplerate = (int) (csound->esr + FL(0.5)); - sfinfo.channels = csound->nchnls; - sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); + sfinfo.channels = csound->nchnls; + sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); /* open file */ - if (ST(pipdevout)) { - ST(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); + if (STA(pipdevout)) { + STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); +#ifdef PIPES + if (STA(outfile) == NULL) { + char fmt_name[6]; + if (O->sfsampsize == 8) { + if (O->filetyp == TYP_AU) + csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, + sf_strerror(NULL)); + strcpy(fmt_name, "AU"); + O->filetyp = TYP_AU; + } + else { + if (O->filetyp == TYP_IRCAM) + csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, + sf_strerror(NULL)); + strcpy(fmt_name, "IRCAM"); + O->filetyp = TYP_IRCAM; + } + csound->Message(csound, Str("Output file type changed to %s " + "for use in pipe\n"), fmt_name); + sfinfo.format = TYPE2SF(O->filetyp) | FORMAT2SF(O->outformat); + STA(outfile) = sf_open_fd(osfd, SFM_WRITE, &sfinfo, 0); + } +#endif + if (UNLIKELY(STA(outfile) == NULL)) + csoundDie(csound, Str("sfinit: cannot open fd %d\n%s"), osfd, + sf_strerror(NULL)); } else { fullName = csoundFindOutputFile(csound, fName, "SFDIR"); if (UNLIKELY(fullName == NULL)) csoundDie(csound, Str("sfinit: cannot open %s"), fName); - ST(sfoutname) = fullName; - ST(outfile) = sf_open(fullName, SFM_WRITE, &sfinfo); - if (UNLIKELY(ST(outfile) == NULL)) + STA(sfoutname) = fullName; + STA(outfile) = sf_open(fullName, SFM_WRITE, &sfinfo); + if (UNLIKELY(STA(outfile) == NULL)) csoundDie(csound, Str("sfinit: cannot open %s"), fullName); /* only notify the host if we opened a real file, not stdout or a pipe */ csoundNotifyFileOpened(csound, fullName, @@ -683,17 +771,17 @@ } /* IV - Feb 22 2005: clip integer formats */ if (O->outformat != AE_FLOAT && O->outformat != AE_DOUBLE) - sf_command(ST(outfile), SFC_SET_CLIPPING, NULL, SF_TRUE); - sf_command(ST(outfile), SFC_SET_ADD_PEAK_CHUNK, + sf_command(STA(outfile), SFC_SET_CLIPPING, NULL, SF_TRUE); + sf_command(STA(outfile), SFC_SET_ADD_PEAK_CHUNK, NULL, (csound->peakchunks ? SF_TRUE : SF_FALSE)); #ifdef SOME_FINE_DAY if (csound->dither_output) { /* This may not be written yet!! */ SF_DITHER_INFO ditherInfo; memset(&ditherInfo, 0, sizeof(SF_DITHER_INFO)); - ditherInfo.type = SFD_TRIANGULAR_PDF | SFD_DEFAULT_LEVEL; + ditherInfo.type = SFD_TRIANGULAR_PDF | SFD_DEFAULT_LEVEL; ditherInfo.level = 1.0; - ditherInfo.name = (char*) NULL; - sf_command(ST(outfile), SFC_SET_DITHER_ON_WRITE, + ditherInfo.name = (char*) NULL; + sf_command(STA(outfile), SFC_SET_DITHER_ON_WRITE, &ditherInfo, sizeof(SF_DITHER_INFO)); } #endif @@ -703,7 +791,8 @@ csound->spoutran = spoutsf; /* accumulate output */ else csound->spoutran = spoutsf_noscale; - if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT) { + if (csound->dither_output && csound->oparms->outformat!=AE_FLOAT && + csound->oparms->outformat!=AE_DOUBLE) { if (csound->oparms->outformat==AE_SHORT) csound->audtran = writesf_dither_16; else if (csound->oparms->outformat==AE_CHAR) @@ -715,66 +804,66 @@ csound->audtran = writesf; /* Write any tags. */ if ((s = csound->SF_id_title) != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_TITLE, s); + sf_set_string(STA(outfile), SF_STR_TITLE, s); if ((s = csound->SF_csd_licence) == NULL || *s == '\0') s = csound->SF_id_copyright; if (s != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_COPYRIGHT, s); + sf_set_string(STA(outfile), SF_STR_COPYRIGHT, s); if ((s = csound->SF_id_software) != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_SOFTWARE, s); + sf_set_string(STA(outfile), SF_STR_SOFTWARE, s); if ((s = csound->SF_id_artist) != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_ARTIST, s); + sf_set_string(STA(outfile), SF_STR_ARTIST, s); if ((s = csound->SF_id_comment) != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_COMMENT, s); + sf_set_string(STA(outfile), SF_STR_COMMENT, s); if ((s = csound->SF_id_date) != NULL && *s != '\0') - sf_set_string(ST(outfile), SF_STR_DATE, s); + sf_set_string(STA(outfile), SF_STR_DATE, s); /* file is now open */ - ST(osfopen) = 1; + STA(osfopen) = 1; outset: O->sfsampsize = (int) sfsampsize(FORMAT2SF(O->outformat)); /* calc outbuf size & alloc bufspace */ - ST(outbufsiz) = O->outbufsamps * sizeof(MYFLT); - ST(outbufp) = ST(outbuf) = mmalloc(csound, ST(outbufsiz)); - if (ST(pipdevout) == 2) + STA(outbufsiz) = O->outbufsamps * sizeof(MYFLT); + STA(outbufp) = STA(outbuf) = mmalloc(csound, STA(outbufsiz)); + if (STA(pipdevout) == 2) csound->Message(csound, Str("writing %d sample blks of %d-bit floats to %s \n"), - O->outbufsamps, sizeof(MYFLT)*8, ST(sfoutname)); + O->outbufsamps, sizeof(MYFLT)*8, STA(sfoutname)); else { csound->Message(csound, Str("writing %d-byte blks of %s to %s"), O->outbufsamps * O->sfsampsize, - getstrformat(O->outformat), ST(sfoutname)); + getstrformat(O->outformat), STA(sfoutname)); if (O->sfheader == 0) csound->Message(csound, Str(" (raw)\n")); else csound->Message(csound, " (%s)\n", type2string(O->filetyp)); } - ST(osfopen) = 1; - ST(outbufrem) = O->outbufsamps; + STA(osfopen) = 1; + STA(outbufrem) = O->outbufsamps; } void sfclosein(CSOUND *csound) { alloc_globals(csound); - if (!ST(isfopen)) + if (!STA(isfopen)) return; - if (ST(pipdevin) == 2 && (!ST(osfopen) || ST(pipdevout) != 2)) { + if (STA(pipdevin) == 2 && (!STA(osfopen) || STA(pipdevout) != 2)) { /* close only if not open for output too */ csound->rtclose_callback(csound); } - else if (ST(pipdevin) != 2) { - if (ST(infile) != NULL) - sf_close(ST(infile)); + else if (STA(pipdevin) != 2) { + if (STA(infile) != NULL) + sf_close(STA(infile)); #ifdef PIPES - if (ST(pin) != NULL) { - _pclose(ST(pin)); - ST(pin) = NULL; + if (STA(pin) != NULL) { + _pclose(STA(pin)); + STA(pin) = NULL; } #endif - ST(infile) = NULL; + STA(infile) = NULL; } - ST(isfopen) = 0; + STA(isfopen) = 0; } void sfcloseout(CSOUND *csound) @@ -783,49 +872,49 @@ int nb; alloc_globals(csound); - if (!ST(osfopen)) + if (!STA(osfopen)) return; - if ((nb = (O->outbufsamps - ST(outbufrem)) * sizeof(MYFLT)) > 0) { + if ((nb = (O->outbufsamps - STA(outbufrem)) * sizeof(MYFLT)) > 0) { /* flush outbuffer */ csound->nrecs++; - csound->audtran(csound, ST(outbuf), nb); + csound->audtran(csound, STA(outbuf), nb); } - if (ST(pipdevout) == 2 && (!ST(isfopen) || ST(pipdevin) != 2)) { + if (STA(pipdevout) == 2 && (!STA(isfopen) || STA(pipdevin) != 2)) { /* close only if not open for input too */ csound->rtclose_callback(csound); } - if (ST(pipdevout) == 2) + if (STA(pipdevout) == 2) goto report; - if (ST(outfile) != NULL) { - if (!ST(pipdevout)) - sf_command(ST(outfile), SFC_UPDATE_HEADER_NOW, NULL, 0); - sf_close(ST(outfile)); - ST(outfile) = NULL; + if (STA(outfile) != NULL) { + if (!STA(pipdevout) && O->outformat != AE_VORBIS) + sf_command(STA(outfile), SFC_UPDATE_HEADER_NOW, NULL, 0); + sf_close(STA(outfile)); + STA(outfile) = NULL; } #ifdef PIPES - if (ST(pout) != NULL) { - _pclose(ST(pout)); - ST(pout) = NULL; + if (STA(pout) != NULL) { + _pclose(STA(pout)); + STA(pout) = NULL; } #endif report: - if (ST(pipdevout) == 2) { + if (STA(pipdevout) == 2) { csound->Message(csound, Str("%ld %d sample blks of %d-bit floats written to %s\n"), csound->nrecs, O->outbufsamps, - sizeof(MYFLT)*8, ST(sfoutname)); + sizeof(MYFLT)*8, STA(sfoutname)); } else { csound->Message(csound, Str("%ld %d sample blks of %s written to %s"), O->outbufsamps, O->outbufsamps * O->sfsampsize, - getstrformat(O->outformat), ST(sfoutname)); + getstrformat(O->outformat), STA(sfoutname)); if (O->sfheader == 0) csound->Message(csound, Str(" (raw)\n")); else csound->Message(csound, " (%s)\n", type2string(O->filetyp)); } - ST(osfopen) = 0; + STA(osfopen) = 0; } /* report soundfile write(osfd) error */ @@ -838,7 +927,7 @@ nret, nput); csound->ErrorMsg(csound, Str("(disk may be full...\n closing the file ...)")); - ST(outbufrem) = csound->oparms->outbufsamps; /* consider buf is flushed */ + STA(outbufrem) = csound->oparms->outbufsamps; /* consider buf is flushed */ sfcloseout(csound); /* & try to close the file */ csound->Die(csound, Str("\t... closed\n")); } @@ -848,7 +937,7 @@ alloc_globals(csound); csound->Message(csound, Str("not writing to sound disk\n")); /* init counter, though not writing */ - ST(outbufrem) = csound->oparms->outbufsamps; + STA(outbufrem) = csound->oparms->outbufsamps; } static inline void sndfilein_(CSOUND *csound, MYFLT scaleFac) @@ -857,19 +946,19 @@ int i, n, nsmps, bufpos; nsmps = csound->nspin; - bufpos = (int) O->inbufsamps - (int) ST(inbufrem); + bufpos = (int) O->inbufsamps - (int) STA(inbufrem); for (i = 0; iinbufsamps - (int) ST(inbufrem)) * (int) sizeof(MYFLT); - n = csound->audrecv(csound, ST(inbuf) + (int) ST(inbufrem), n); - ST(inbufrem) += (unsigned int) (n / (int) sizeof(MYFLT)); - } while ((int) ST(inbufrem) < (int) O->inbufsamps); + n = ((int) O->inbufsamps - (int) STA(inbufrem)) * (int) sizeof(MYFLT); + n = csound->audrecv(csound, STA(inbuf) + (int) STA(inbufrem), n); + STA(inbufrem) += (unsigned int) (n / (int) sizeof(MYFLT)); + } while ((int) STA(inbufrem) < (int) O->inbufsamps); bufpos = 0; } - csound->spin[i] = ST(inbuf)[bufpos++] * scaleFac; - ST(inbufrem)--; + csound->spin[i] = STA(inbuf)[bufpos++] * scaleFac; + STA(inbufrem)--; } } @@ -908,37 +997,33 @@ if (!csound->enableHostImplementedAudioIO) return; alloc_globals(csound); - O = csound->oparms; + O = csound->oparms; csound->audrecv = audrecv_dummy; csound->audtran = audtran_dummy; - ST(inbufrem) = (unsigned int) O->inbufsamps; - ST(outbufrem) = (unsigned int) O->outbufsamps; + STA(inbufrem) = (unsigned int) O->inbufsamps; + STA(outbufrem) = (unsigned int) O->outbufsamps; if (!csound->hostRequestedBufferSize) { - O->sfread = 0; - O->sfwrite = 0; - ST(osfopen) = 0; + O->sfread = 0; + O->sfwrite = 0; + STA(osfopen) = 0; return; } - ST(inbufsiz) = (unsigned int) (O->inbufsamps * (int) sizeof(MYFLT)); - ST(inbuf) = (MYFLT*) mcalloc(csound, ST(inbufsiz)); - ST(outbufsiz) = (unsigned int) (O->outbufsamps * (int) sizeof(MYFLT)); - ST(outbuf) = (MYFLT*) mcalloc(csound, ST(outbufsiz)); - ST(outbufp) = ST(outbuf); - O->sfread = 1; - O->sfwrite = 1; - ST(osfopen) = 1; + STA(inbufsiz) = (unsigned int) (O->inbufsamps * (int) sizeof(MYFLT)); + STA(inbuf) = (MYFLT*) mcalloc(csound, STA(inbufsiz)); + STA(outbufsiz) = (unsigned int) (O->outbufsamps * (int) sizeof(MYFLT)); + STA(outbuf) = (MYFLT*) mcalloc(csound, STA(outbufsiz)); + STA(outbufp) = STA(outbuf); + O->sfread = 1; + O->sfwrite = 1; + STA(osfopen) = 1; } PUBLIC MYFLT *csoundGetInputBuffer(CSOUND *csound) { - if (csound->libsndGlobals == NULL) - return NULL; - return ST(inbuf); + return STA(inbuf); } PUBLIC MYFLT *csoundGetOutputBuffer(CSOUND *csound) { - if (csound->libsndGlobals == NULL) - return NULL; - return ST(outbuf); + return STA(outbuf); } diff -Nru csound-5.17.11~dfsg/InOut/libsnd_u.c csound-6.02~dfsg/InOut/libsnd_u.c --- csound-5.17.11~dfsg/InOut/libsnd_u.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/libsnd_u.c 2014-01-07 16:53:47.000000000 +0000 @@ -334,24 +334,14 @@ case TYP_PVF: return "PVF"; case TYP_XI: return "XI"; case TYP_HTK: return "HTK"; -#ifdef SF_FORMAT_SDS case TYP_SDS: return "SDS"; -#endif -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1011 case TYP_SD2: return "SD2"; -# if HAVE_LIBSNDFILE >= 1013 case TYP_FLAC: return "FLAC"; case TYP_CAF: return "CAF"; -# endif -# if HAVE_LIBSNDFILE >= 1018 case TYP_WVE: return "WVE"; case TYP_OGG: return "OGG"; -# endif -# if HAVE_LIBSNDFILE >= 1019 - case TYP_MPC2K: return "MPC"; - case TYP_RF64: return "W64"; -# endif -#endif + case TYP_MPC2K: return "MPC2K"; + case TYP_RF64: return "RF64"; default: return Str("unknown"); } } @@ -378,7 +368,9 @@ case AE_SHORT: return Str("shorts"); case AE_LONG: return Str("longs"); case AE_FLOAT: return Str("floats"); + case AE_DOUBLE: return Str("double floats"); case AE_24INT: return Str("24bit ints"); /* RWD 5:2001 */ + case AE_VORBIS: return Str("vorbis encoding"); } return Str("unknown"); } @@ -413,24 +405,14 @@ case TYP_SVX: return CSFTYPE_SVX; case TYP_VOC: return CSFTYPE_VOC; case TYP_XI: return CSFTYPE_XI; -#ifdef SF_FORMAT_SDS case TYP_SDS: return CSFTYPE_SDS; -#endif -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1011 case TYP_SD2: return CSFTYPE_SD2; -# if HAVE_LIBSNDFILE >= 1013 case TYP_FLAC: return CSFTYPE_FLAC; case TYP_CAF: return CSFTYPE_CAF; -# endif -# if HAVE_LIBSNDFILE >= 1018 case TYP_WVE: return CSFTYPE_WVE; case TYP_OGG: return CSFTYPE_OGG; -# endif -# if HAVE_LIBSNDFILE >= 1019 - case TYP_MPC2K: return "CSFTYPE_MPC"; - case TYP_RF64: return "CSFTYPE_W64"; -# endif -#endif + case TYP_MPC2K: return CSFTYPE_MPC2K; + case TYP_RF64: return CSFTYPE_RF64; default: return CSFTYPE_UNKNOWN_AUDIO; } } diff -Nru csound-5.17.11~dfsg/InOut/midifile.c csound-6.02~dfsg/InOut/midifile.c --- csound-5.17.11~dfsg/InOut/midifile.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/midifile.c 2014-01-07 16:53:47.000000000 +0000 @@ -652,7 +652,7 @@ MF(timeCode) *= (double) (timeCode & 0xFF); } /* initialise structure data */ - MF(totalKcnt) = 0UL; + MF(totalKcnt) = csound->global_kcounter; MF(nEvents) = 0; MF(maxEvents) = 0; MF(nTempo) = 0; MF(maxTempo) = 0; MF(eventList) = (midiEvent_t*) NULL; @@ -777,6 +777,7 @@ void midifile_rewind_score(CSOUND *csound) { int i; + OPARMS *O = csound->oparms; if (MIDIFILE != NULL) { /* reset event index and tempo */ @@ -787,7 +788,13 @@ /* reset controllers on all channels */ for (i = 0; i < MAXCHAN; i++) midi_ctl_reset(csound, (int16) i); + } else if (O->FMidiname != NULL) { + csound->MTrkend = 0; + if (csoundMIDIFileOpen(csound, O->FMidiname) != 0) + csound->Die(csound, Str("Failed to load MIDI file.")); + O->FMidiin = 1; } + else csound->Warning(csound, Str("Cannot rewind MIDI score\n")); } /* ------------------------------------------------------------------------ */ @@ -803,3 +810,7 @@ return OK; } +int midiFileStatus(CSOUND *csound, MIDITEMPO *p){ + *p->kResult = csound->oparms->FMidiin; + return OK; +} diff -Nru csound-5.17.11~dfsg/InOut/midirecv.c csound-6.02~dfsg/InOut/midirecv.c --- csound-5.17.11~dfsg/InOut/midirecv.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/midirecv.c 2014-01-07 16:54:20.000000000 +0000 @@ -102,7 +102,6 @@ #include "csoundCore.h" #include "midiops.h" -#include "oload.h" #include "midifile.h" #define MGLOB(x) (csound->midiGlobals->x) @@ -218,8 +217,9 @@ if (chn->insno <= 0) /* ignore if channel is muted */ break; n = (int16) chn->pgm2ins[mep->dat1]; /* program change -> INSTR */ - if (n > 0 && n <= csound->maxinsno && /* if corresp instr exists */ - csound->instrtxtp[n] != NULL) { /* assign as insno */ + if (n > 0 && + n <= csound->engineState.maxinsno && /* if corresp instr exists */ + csound->engineState.instrtxtp[n] != NULL) { /* assign as insno */ chn->insno = n; /* else ignore prog. change */ csound->Message(csound, Str("midi channel %d now using instr %d\n"), mep->chan + 1, chn->insno); @@ -373,9 +373,10 @@ int16 chan; defaultinsno = 0; - while (++defaultinsno <= (int) csound->maxinsno && - csound->instrtxtp[defaultinsno] == NULL); - if (defaultinsno > (int) csound->maxinsno) + while (csound->engineState.instrtxtp && + ++defaultinsno <= (int) csound->engineState.maxinsno && + csound->engineState.instrtxtp[defaultinsno] == NULL); + if (defaultinsno > (int) csound->engineState.maxinsno) defaultinsno = 0; /* no instruments */ for (chan = (int16) 0; chan < (int16) 16; chan++) { /* alloc a midi control blk for midi channel */ @@ -383,7 +384,9 @@ csound->m_chnbp[chan] = chn = (MCHNBLK*) mcalloc(csound, sizeof(MCHNBLK)); n = (int) chan + 1; /* if corresponding instrument exists, assign as insno, */ - if (n <= (int) csound->maxinsno && csound->instrtxtp[n] != NULL) + if (csound->engineState.instrtxtp && + n <= (int) csound->engineState.maxinsno && + csound->engineState.instrtxtp[n] != NULL) chn->insno = (int16) n; else if (defaultinsno > 0) chn->insno = (int16) defaultinsno; @@ -420,7 +423,8 @@ csound->Message(csound, Str("MIDI channel %d muted\n"), chan + 1); } else { - if (insno > csound->maxinsno || csound->instrtxtp[insno] == NULL) { + if (insno > csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL) { csound->Message(csound, Str("Insno = %d\n"), insno); return csound->InitError(csound, Str("unknown instr")); } @@ -615,4 +619,3 @@ p->midiOutFileData = NULL; } } - diff -Nru csound-5.17.11~dfsg/InOut/midisend.c csound-6.02~dfsg/InOut/midisend.c --- csound-5.17.11~dfsg/InOut/midisend.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/midisend.c 2014-01-07 16:53:47.000000000 +0000 @@ -44,7 +44,8 @@ 0x00, 0x00, 0x00, 0x06, /* header length */ 0x00, 0x00, /* file type */ 0x00, 0x01, /* number of tracks */ - 0x19, 0x78, /* tick time (1/25 sec / 120), VL this was 0xE7, which was wrong, changed to 0x19 0x78*/ + 0x19, 0x78, /* tick time (1/25 sec / 120), */ + /*VL this was 0xE7, which was wrong, changed to 0x19 0x78 */ 0x4D, 0x54, 0x72, 0x6B, /* "MTrk" */ 0x00, 0x00, 0x00, 0x00, /* track length (updated later) */ /* -------------------------------------------------------- */ @@ -65,9 +66,15 @@ if (nbytes < 2) return; s = csound->icurTime/csound->esr; - if (csound->ids == NULL && csound->pds != NULL) + /* this check (for perf time run?) used the global pds, which has now + been removed. My impression is that it is sufficient to check + for csound->ids, but this might need attention if MIDI file output + has problems + */ + if (csound->ids == NULL) s -= csound->ksmps/csound->esr; - s *= 13040.; /* VL NOV 11: this was 3000.0, which was wrong; 13040.0 was arrived at by experimentation */ + s *= 13040.; /* VL NOV 11: this was 3000.0, which was wrong; + 13040.0 was arrived at by experimentation */ #ifdef HAVE_C99 t = (unsigned int) lrint(s); #else @@ -193,7 +200,7 @@ /* write header */ if (UNLIKELY(fwrite(&(midiOutFile_header[0]), (size_t)1, (size_t)22, fp->f) != 22)) { - csound->Die(csound, "SHort write in MIDI\n"); + csound->Die(csound, Str("Short write in MIDI\n")); } } @@ -214,4 +221,3 @@ csound->FileClose(csound, p->fd); csound->Free(csound, p); } - diff -Nru csound-5.17.11~dfsg/InOut/pmidi.c csound-6.02~dfsg/InOut/pmidi.c --- csound-5.17.11~dfsg/InOut/pmidi.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/pmidi.c 2014-01-07 16:53:47.000000000 +0000 @@ -28,7 +28,6 @@ #include "csdl.h" /* PMIDI.C */ #include "csGblMtx.h" #include "midiops.h" -#include "oload.h" #include #include @@ -123,29 +122,6 @@ return NULL; return ((PmDeviceInfo*)Pm_GetDeviceInfo((PmDeviceID) i)); } - -static void portMidi_listDevices(CSOUND *csound, int output) -{ - int i, cnt; - PmDeviceInfo *info; - - cnt = portMidi_getDeviceCount(output); - if (UNLIKELY(cnt < 1)) - return; - if (output) - csound->Message(csound, Str("The available MIDI out devices are:\n")); - else - csound->Message(csound, Str("The available MIDI in devices are:\n")); - for (i = 0; i < cnt; i++) { - info = portMidi_getDeviceInfo(i, output); - if (info->interf != NULL) - csound->Message(csound, " %3d: %s (%s)\n", i, info->name, info->interf); - else - csound->Message(csound, " %3d: %s\n", i, info->name); - - } -} - /* reference count for PortMidi initialisation */ static unsigned long portmidi_init_cnt = 0UL; @@ -184,9 +160,48 @@ csound->ErrorMsg(csound, Str(errMsg)); return -1; } + csound_global_mutex_unlock(); return csound->RegisterResetCallback(csound, NULL, stop_portmidi); } +static int listDevices(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput){ + int i, cnt; + PmDeviceInfo *info; + char tmp[64]; + char *drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); + + if (UNLIKELY(start_portmidi(csound) != 0)) + return 0; + + cnt = portMidi_getDeviceCount(isOutput); + if(list == NULL) return cnt; + for (i = 0; i < cnt; i++) { + info = portMidi_getDeviceInfo(i, isOutput); + strncpy(list[i].device_name, info->name, 63); + sprintf(tmp, "%d", i); + strncpy(list[i].device_id, tmp, 63); + list[i].isOutput = isOutput; + if (info->interf != NULL) + strncpy(list[i].interface_name, info->interf, 63); + else strcpy(list[i].interface_name, ""); + strncpy(list[i].midi_module, drv, 63); + } + return cnt; +} + +static void portMidi_listDevices(CSOUND *csound, int output) +{ + int i,n = listDevices(csound, NULL, output); + CS_MIDIDEVICE *devs = + (CS_MIDIDEVICE *) csound->Malloc(csound, n*sizeof(CS_MIDIDEVICE)); + listDevices(csound, devs, output); + for(i=0; i < n; i++) + csound->Message(csound, "%s: %s (%s)\n", + devs[i].device_id, devs[i].device_name, devs[i].midi_module); + csound->Free(csound, devs); +} + + static int OpenMidiInDevice_(CSOUND *csound, void **userData, const char *dev) { int cntdev, devnum, opendevs, i; @@ -321,6 +336,7 @@ } *userData = (void*) midistream; /* report success */ + return 0; } @@ -400,6 +416,9 @@ return 0; n = 0; do { + int time = csound->GetCurrentTimeSamples(csound)/csound->GetSr(csound); + //printf("jitter: %d \n", + // Pt_Time(NULL) - (int)(1000*time/csound->GetSr(csound))); st = (int)*(mbuf++); if (UNLIKELY(st < 0x80)) { portMidiErrMsg(csound, Str("invalid MIDI out data")); @@ -425,8 +444,9 @@ mev.message |= (PmMessage) Pm_Message(0, 0, (int)*(mbuf++)); if (UNLIKELY(Pm_Write(midistream, &mev, 1L) != pmNoError)) portMidiErrMsg(csound, Str("MIDI out: error writing message")); - else + else { n += (datbyts[(st - 0x80) >> 4] + 1); + } } while (nbytes > 0); /* return the number of bytes written */ return n; @@ -467,14 +487,14 @@ PUBLIC int csoundModuleCreate(CSOUND *csound) { /* nothing to do, report success */ - csound->Message(csound, Str("PortMIDI real time MIDI plugin for Csound\n")); + // csound->Message(csound, Str("PortMIDI real time MIDI plugin for Csound\n")); return 0; } PUBLIC int csoundModuleInit(CSOUND *csound) { char *drv; - + csound->module_list_add(csound, "portmidi", "midi"); drv = (char*) (csound->QueryGlobalVariable(csound, "_RTMIDI")); if (drv == NULL) return 0; @@ -488,6 +508,13 @@ csound->SetExternalMidiOutOpenCallback(csound, OpenMidiOutDevice_); csound->SetExternalMidiWriteCallback(csound, WriteMidiData_); csound->SetExternalMidiOutCloseCallback(csound, CloseMidiOutDevice_); + csound->SetMIDIDeviceListCallback(csound,listDevices); + + return 0; +} + +PUBLIC int csoundModuleDestroy(CSOUND *csound) { + return 0; } diff -Nru csound-5.17.11~dfsg/InOut/rtalsa.c csound-6.02~dfsg/InOut/rtalsa.c --- csound-5.17.11~dfsg/InOut/rtalsa.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtalsa.c 2014-01-07 16:53:47.000000000 +0000 @@ -3,6 +3,7 @@ Copyright (C) 2005 Istvan Varga (C) 2009 Andrés Cabrera, Clemens Ladisch + (C) 2012 Tito Latini This file is part of Csound. @@ -49,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -65,7 +67,7 @@ char *device; /* device name */ int format; /* sample format */ int sampleSize; /* MYFLT sample frame size in bytes */ - int srate; /* sample rate in Hz */ + uint32_t srate; /* sample rate in Hz */ int nchns; /* number of channels */ int buffer_smps; /* buffer length in samples */ int period_smps; /* period time in samples */ @@ -97,12 +99,18 @@ unsigned char prvStatus, dat1, dat2; } midiDevFile; +typedef struct alsaseqMidi_ { + snd_seq_t *seq; + snd_midi_event_t *mev; + snd_seq_event_t sev; + snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; +} alsaseqMidi; + static const unsigned char dataBytes[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 2, 1, 1, 2, 0 }; - - int set_scheduler_priority(CSOUND *csound, int priority) { struct sched_param p; @@ -110,27 +118,31 @@ memset(&p, 0, sizeof(struct sched_param)); if (priority < -20 || priority > sched_get_priority_max(SCHED_RR)) { csound->Message(csound, - Str("--scheduler: invalid priority value; the allowed range is:")); + Str("--scheduler: invalid priority value; " + "the allowed range is:")); csound->Message(csound,Str(" -20 to -1: set nice level")); - csound->Message(csound,Str(" 0: normal scheduling, but lock memory")); - csound->Message(csound,Str(" 1 to %d: SCHED_RR with the specified priority " - "(DANGEROUS)"), sched_get_priority_max(SCHED_RR)); - return -1; - } + csound->Message(csound,Str(" 0: normal scheduling, " + "but lock memory")); + csound->Message(csound,Str(" 1 to %d: SCHED_RR with the specified " + "priority (DANGEROUS)"), + sched_get_priority_max(SCHED_RR)); + return -1; + } /* set scheduling policy and priority */ if (priority > 0) { p.sched_priority = priority; if (sched_setscheduler(0, SCHED_RR, &p) != 0) { - csound->Message(csound,"csound: cannot set scheduling policy to SCHED_RR"); + csound->Message(csound, + Str("csound: cannot set scheduling policy to SCHED_RR")); } else csound->Message(csound, - "csound: setting scheduling policy to SCHED_RR\n"); + Str("csound: setting scheduling policy to SCHED_RR\n")); } else { /* nice requested */ if (setpriority(PRIO_PROCESS, 0, priority) != 0) { csound->Message(csound,"csound: cannot set nice level to %d", - priority); + priority); } } return 0; @@ -234,15 +246,17 @@ static void short_to_MYFLT(int nSmps, int16_t *inBuf, MYFLT *outBuf) { int n; + MYFLT adjust = FL(1.0) / (MYFLT) 0x8000; for (n=0; nbuf = NULL; snd_pcm_hw_params_alloca(&hw_params); @@ -327,26 +342,26 @@ devName = dev->device; err = snd_pcm_open(&(dev->handle), devName, (play ? SND_PCM_STREAM_PLAYBACK - : SND_PCM_STREAM_CAPTURE), 0); + : SND_PCM_STREAM_CAPTURE), 0); if (err < 0) { if (play) p->ErrorMsg(p, Str(" *** Cannot open device '%s' for audio output: %s"), - devName, snd_strerror(err)); + devName, snd_strerror(err)); else p->ErrorMsg(p, Str(" *** Cannot open device '%s' for audio input: %s"), - devName, snd_strerror(err)); + devName, snd_strerror(err)); return -1; } /* allocate hardware and software parameters */ if (snd_pcm_hw_params_any(dev->handle, hw_params) < 0) { - sprintf(msg, "No real-time audio configurations found"); + strncpy(msg, Str("No real-time audio configurations found"), MSGLEN); goto err_return_msg; } /* now set the various hardware parameters: */ /* access method, */ if (snd_pcm_hw_params_set_access(dev->handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED) < 0) { - sprintf(msg, "Error setting access type for soundcard"); + strncpy(msg, Str("Error setting access type for soundcard"), MSGLEN); goto err_return_msg; } /* sample format, */ @@ -354,23 +369,24 @@ dev->sampleSize = (int) sizeof(MYFLT) * dev->nchns; { void (*fp)(void) = NULL; - alsaFmt = set_format(&fp, dev->format, play, csound->dither_output); + alsaFmt = set_format(&fp, dev->format, play, csound->GetDitherMode(csound)); if (play) dev->playconv = (void (*)(int, MYFLT*, void*, int*)) fp; else dev->rec_conv = (void (*)(int, void*, MYFLT*)) fp; } if (alsaFmt == SND_PCM_FORMAT_UNKNOWN) { - sprintf(msg, "Unknown sample format.\n *** Only 16-bit and 32-bit " - "integers, and 32-bit floats are supported."); + strncpy(msg, Str("Unknown sample format.\n *** Only 16-bit and 32-bit " + "integers, and 32-bit floats are supported."), MSGLEN); goto err_return_msg; } if (snd_pcm_hw_params_set_format(dev->handle, hw_params, alsaFmt) < 0) { - sprintf(msg, "Unable to set requested sample format on soundcard"); + strncpy(msg, + Str("Unable to set requested sample format on soundcard"),MSGLEN); goto err_return_msg; } /* number of channels, */ if (snd_pcm_hw_params_set_channels(dev->handle, hw_params, (unsigned int) dev->nchns) < 0) { - sprintf(msg, "Unable to set number of channels on soundcard"); + strncpy(msg, Str("Unable to set number of channels on soundcard"), MSGLEN); goto err_return_msg; } /* sample rate, (patched for sound cards that object to fixed rate) */ @@ -378,7 +394,7 @@ unsigned int target = dev->srate; if (snd_pcm_hw_params_set_rate_near(dev->handle, hw_params, (unsigned int *) &dev->srate, 0) < 0) { - sprintf(msg, "Unable to set sample rate on soundcard"); + strncpy(msg, Str("Unable to set sample rate on soundcard"), MSGLEN); goto err_return_msg; } if (dev->srate!=target) @@ -425,14 +441,16 @@ } /* set up device according to the above parameters */ if (snd_pcm_hw_params(dev->handle, hw_params) < 0) { - sprintf(msg, "Error setting hardware parameters for real-time audio"); + strncpy(msg, + Str("Error setting hardware parameters for real-time audio"), + MSGLEN); goto err_return_msg; } /* print settings */ if (p->GetMessageLevel(p) != 0) p->Message(p, Str("ALSA %s: total buffer size: %d, period size: %d\n"), - (play ? "output" : "input"), - dev->buffer_smps, dev->period_smps); + (play ? "output" : "input"), + dev->buffer_smps, dev->period_smps); /* now set software parameters */ n = (play ? dev->buffer_smps : 1); if (snd_pcm_sw_params_current(dev->handle, sw_params) < 0 @@ -442,14 +460,15 @@ dev->period_smps) < 0 /* || snd_pcm_sw_params_set_xfer_align(dev->handle, sw_params, 1) < 0 */ || snd_pcm_sw_params(dev->handle, sw_params) < 0) { - sprintf(msg, "Error setting software parameters for real-time audio"); + strncpy(msg, + Str("Error setting software parameters for real-time audio"),MSGLEN); goto err_return_msg; } /* allocate memory for sample conversion buffer */ n = (dev->format == AE_SHORT ? 2 : 4) * dev->nchns * alloc_smps; dev->buf = (void*) malloc((size_t) n); if (dev->buf == NULL) { - sprintf(msg, "Memory allocation failure"); + strncpy(msg, Str("Memory allocation failure"),MSGLEN); goto err_return_msg; } memset(dev->buf, 0, (size_t) n); @@ -457,7 +476,7 @@ return 0; err_return_msg: - p->MessageS(p, CSOUNDMSG_ERROR, " *** %s\n", Str(msg)); + p->MessageS(p, CSOUNDMSG_ERROR, " *** %s\n", msg); snd_pcm_close(dev->handle); return -1; } @@ -466,7 +485,7 @@ { FILE * f = fopen("/proc/asound/pcm", "r"); /*file presents this format: - 02-00: Analog PCM : Mona : playback 6 : capture 4*/ + 02-00: Analog PCM : Mona : playback 6 : capture 4*/ char *line, *line_; line = (char *) calloc (128, sizeof(char)); line_ = (char *) calloc (128, sizeof(char)); @@ -474,35 +493,81 @@ char num_[] = " "; char *temp; if (f) { + char *th; while (fgets(line, 128, f)) { /* Read one line*/ strcpy(line_, line); - temp = strtok (line, "-"); + temp = strtok_r (line, "-", &th); strncpy (card_, temp, 2); - temp = strtok (NULL, ":"); + temp = strtok_r (NULL, ":", &th); strncpy (num_, temp, 2); int card = atoi (card_); int num = atoi (num_); temp = strchr (line_, ':'); if (temp) temp = temp + 2; - /* name contains spaces at the beginning and the end. - And line return at the end*/ + /* name contains spaces at the beginning and the end. + And line return at the end*/ csound->Message(csound, " \"hw:%i,%i\" - %s",card, num, temp ); } } + fclose(f); free(line); free(line_); +} + +int listDevices(CSOUND *csound, CS_AUDIODEVICE *list, int isOutput){ + + FILE * f = fopen("/proc/asound/pcm", "r"); + /*file presents this format: + 02-00: Analog PCM : Mona : playback 6 : capture 4*/ + char *line, *line_; + line = (char *) calloc (128, sizeof(char)); + line_ = (char *) calloc (128, sizeof(char)); + char card_[] = " "; + char num_[] = " "; + char *temp; + char tmp[64]; + int n =0; + if (f) { + char *th; + while (fgets(line, 128, f)) { /* Read one line*/ + strcpy(line_, line); + temp = strtok_r (line, "-", &th); + strncpy (card_, temp, 2); + temp = strtok_r (NULL, ":", &th); + strncpy (num_, temp, 2); + int card = atoi (card_); + int num = atoi (num_); + temp = strchr (line_, ':'); + if (temp) + temp = temp + 2; + if (list != NULL) { + /* for some reason, there appears to be a memory + problem if we try to copy more than 10 chars, + even though list[n].device_name is 64 chars long */ + strncpy(list[n].device_name, temp, 10); + list[n].device_name[10] = '\0'; + sprintf(tmp, "%shw:%i,%i", isOutput ? "dac:" : "adc:", card, num); + strncpy(list[n].device_id, tmp, 16); + list[n].max_nchnls = -1; + list[n].isOutput = isOutput; + } + n++; + } + } fclose(f); + free(line); + free(line_); + return n; } static int open_device(CSOUND *csound, const csRtAudioParams *parm, int play) -{ - DEVPARAMS *dev; +{ DEVPARAMS *dev; void **userDataPtr; int retval; - userDataPtr = (play ? (void**) &(csound->rtPlay_userdata) - : (void**) &(csound->rtRecord_userdata)); + userDataPtr = (play ? (void**) csound->GetRtPlayUserData(csound) + : (void**) csound->GetRtRecordUserData(csound)); /* check if the device is already opened */ if (*userDataPtr != NULL) return 0; @@ -516,7 +581,7 @@ dev = (DEVPARAMS*) malloc(sizeof(DEVPARAMS)); if (dev == NULL) { csound->ErrorMsg(csound, Str(" *** ALSA: %s: memory allocation failure"), - (play ? "playopen" : "recopen")); + (play ? "playopen" : "recopen")); return -1; } *userDataPtr = (void*) dev; @@ -563,17 +628,16 @@ #undef warning #endif #define warning(x) { \ - if (csound->GetMessageLevel(csound) & 4) \ - csound->Warning(csound, Str(x)); \ -} + if (csound->GetMessageLevel(csound) & 4) \ + csound->Warning(csound, Str(x)); \ + } static int rtrecord_(CSOUND *csound, MYFLT *inbuf, int nbytes) { DEVPARAMS *dev; int n, m, err; - - dev = (DEVPARAMS*) csound->rtRecord_userdata; + dev = (DEVPARAMS*) *(csound->GetRtRecordUserData(csound)); if (dev->handle == NULL) { /* no device, return zero samples */ memset(inbuf, 0, (size_t) nbytes); @@ -619,7 +683,7 @@ DEVPARAMS *dev; int n, err; - dev = (DEVPARAMS*) csound->rtPlay_userdata; + dev = (DEVPARAMS*) *(csound->GetRtPlayUserData(csound)); if (dev->handle == NULL) return; /* calculate the number of samples to play */ @@ -786,7 +850,7 @@ unsigned char c; if (!dev) { /* No devices */ - /* fprintf(stderr, "No devices!"); */ + /* fprintf(stderr, "No devices!"); */ return 0; } /* (void) csound; */ @@ -881,7 +945,7 @@ { (void) csound; snd_rawmidi_write((snd_rawmidi_t*) userData, buf, (size_t) nbytes); - /* snd_rawmidi_drain((snd_rawmidi_t*) userData); */ + /* snd_rawmidi_drain((snd_rawmidi_t*) userData); */ return nbytes; } @@ -1060,7 +1124,7 @@ return -1; } csound->Message(csound, Str("Opened MIDI output device file '%s'\n"), - devName); + devName); } (*userData) = (void*) ((uintptr_t) fd); @@ -1090,15 +1154,366 @@ return retval; } +/* ALSA MIDI Sequencer added by Tito Latini (2012) */ +#define ALSASEQ_SYSEX_BUFFER_SIZE (1024) +static int alsaseq_get_client_id(CSOUND *csound, alsaseqMidi *amidi, + unsigned int capability, const char *name) +{ + snd_seq_client_info_t *client_info = amidi->cinfo; + snd_seq_port_info_t *port_info = amidi->pinfo; + + snd_seq_client_info_set_client(client_info, -1); + while (snd_seq_query_next_client(amidi->seq, client_info) >= 0) { + int client_id; + if ((client_id = snd_seq_client_info_get_client(client_info)) < 0) + break; + snd_seq_port_info_set_client(port_info, client_id); + snd_seq_port_info_set_port(port_info, -1); + if (snd_seq_query_next_port(amidi->seq, port_info) < 0) + break; + if (snd_seq_port_info_get_capability(port_info) & capability) { + char *client_name; + client_name = (char*) snd_seq_client_info_get_name(client_info); + if (strcmp(name, client_name) == 0) + return client_id; + } + } + return -1; +} + +/* + * my_strchr is a destructive version of strchr that removes the + * escape characters '\' from the string s. If escape_all is zero, + * '\' is removed only when it is the escape char for c. + */ +static char *my_strchr(const char *s, int c, int escape_all) +{ + int refill, success = 0, escape = 0, changed = 0; + char *old = (char*)s; + + for (refill = 1; *s != '\0'; s++) { + if (*s == c) { + if (escape) { + escape = 0; + refill = 1; + } + else { + success = 1; + break; + } + } + else if (*s == '\\' || *s == 0x18) { + /* + * CAN char used to mark the escape character during the parsing + * of CsOptions. It is useful only in parse_option_as_cfgvar. + */ + escape ^= 1; + if (escape_all || *(s+1) == c) { + refill = !escape; + changed = 1; + } + } + else if (escape) { + escape = 0; + refill = 1; + } + if (refill) { + /* ETX char used to mark the limits of a string */ + if (*s != 3 && *s != '\n') + *old++ = (*s == 0x18 ? '\\' : *s); + else + changed = 1; + } + } + if (changed) + *old = '\0'; + return (success ? (char*)s : NULL); +} + +/* Searching for port number after ':' at the end of the string */ +static int get_port_from_string(CSOUND *csound, char *str) +{ + int port = 0; + char *end, *tmp, *c = str; + + while (1) { + c = my_strchr(c, ':', 1); + if (c == NULL) + break; + tmp = c+1; + port = strtol(tmp, &end, 10); + if (*end == '\0') { + *c = '\0'; + break; + } + else { /* Not found, continue the search */ + port = 0; + c = tmp; + } + } + return port; +} + +static int alsaseq_connect(CSOUND *csound, alsaseqMidi *amidi, + unsigned int capability, const char *addr_str) +{ + snd_seq_addr_t addr; + char *s, *client_spec, direction_str[5]; + int (*amidi_connect)(snd_seq_t*, int, int, int); + + if (capability == SND_SEQ_PORT_CAP_READ) { + strcpy(direction_str, "from"); + amidi_connect = snd_seq_connect_from; + } + else { + strcpy(direction_str, "to"); + amidi_connect = snd_seq_connect_to; + } + snd_seq_client_info_alloca(&amidi->cinfo); + snd_seq_port_info_alloca(&amidi->pinfo); + client_spec = s = (char*) addr_str; + while (s != NULL) { + int err; + if ((s = my_strchr(client_spec, ',', 0)) != NULL) + *s = '\0'; + if (*client_spec <= '9' && *client_spec >= '0') { /* client_id[:port] */ + err = snd_seq_parse_address(amidi->seq, &addr, client_spec); + if (err >= 0) { + err = amidi_connect(amidi->seq, 0, addr.client, addr.port); + if (err < 0) { + csound->ErrorMsg(csound, Str("ALSASEQ: connection failed %s %s (%s)"), + direction_str, client_spec, snd_strerror(err)); + } + else { + csound->Message(csound, Str("ALSASEQ: connected %s %d:%d\n"), + direction_str, addr.client, addr.port); + } + } + } + else { /* client_name[:port] */ + int client, port; + port = get_port_from_string(csound, client_spec); + client = alsaseq_get_client_id(csound, amidi, capability, client_spec); + if (client >= 0) { + err = amidi_connect(amidi->seq, 0, client, port); + if (err < 0) { + csound->ErrorMsg(csound, + Str("ALSASEQ: connection failed %s %s, port %d (%s)"), + direction_str, client_spec, port, snd_strerror(err)); + } + else { + csound->Message(csound, Str("ALSASEQ: connected %s %d:%d\n"), + direction_str, client, port); + } + } + else { + csound->ErrorMsg(csound, + Str("ALSASEQ: connection failed %s %s, port %d (%s)"), + direction_str, client_spec, port, snd_strerror(client)); + } + } + if (s != NULL) + client_spec = s+1; + } + return OK; +} + +static int alsaseq_in_open(CSOUND *csound, void **userData, const char *devName) +{ + int err, client_id, port_id; + alsaseqMidi *amidi; + csCfgVariable_t *cfg; + char *client_name; + + *userData = NULL; + amidi = (alsaseqMidi*) malloc(sizeof(alsaseqMidi)); + if (UNLIKELY(amidi == NULL)) { + csound->ErrorMsg(csound, Str("ALSASEQ input: memory allocation failure")); + return -1; + } + memset(amidi, 0, sizeof(alsaseqMidi)); + err = snd_seq_open(&(amidi->seq), "default", + SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: error opening sequencer (%s)"), + snd_strerror(err)); + free(amidi); + return -1; + } + csound->Message(csound, Str("ALSASEQ: opened MIDI input sequencer\n")); + cfg = csound->QueryConfigurationVariable(csound, "alsaseq_client"); + client_name = cfg->s.p; + err = snd_seq_set_client_name(amidi->seq, client_name); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot set client name '%s' (%s)"), + client_name, snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + err = snd_seq_create_simple_port(amidi->seq, client_name, + SND_SEQ_PORT_CAP_WRITE | + SND_SEQ_PORT_CAP_SUBS_WRITE, + SND_SEQ_PORT_TYPE_MIDI_GENERIC | + SND_SEQ_PORT_TYPE_APPLICATION); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot create input port (%s)"), + snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + client_id = snd_seq_client_id(amidi->seq); + port_id = err; + csound->Message(csound, Str("ALSASEQ: created input port '%s' %d:%d\n"), + client_name, client_id, port_id); + err = snd_midi_event_new(ALSASEQ_SYSEX_BUFFER_SIZE, &amidi->mev); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot create midi event (%s)"), + snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + snd_midi_event_init(amidi->mev); + alsaseq_connect(csound, amidi, SND_SEQ_PORT_CAP_READ, devName); + *userData = (void*) amidi; + return OK; +} + +static int alsaseq_in_read(CSOUND *csound, + void *userData, unsigned char *buf, int nbytes) +{ + int err; + alsaseqMidi *amidi = (alsaseqMidi*) userData; + snd_seq_event_t *ev; + IGN(csound); + + err = snd_seq_event_input(amidi->seq, &ev); + if (err <= 0) + return 0; + else + err = snd_midi_event_decode(amidi->mev, buf, nbytes, ev); + return err; +} + +static int alsaseq_in_close(CSOUND *csound, void *userData) +{ + alsaseqMidi *amidi = (alsaseqMidi*) userData; + IGN(csound); + + if (amidi != NULL) { + snd_midi_event_free(amidi->mev); + snd_seq_close(amidi->seq); + free(amidi); + } + return OK; +} + +static int alsaseq_out_open(CSOUND *csound, void **userData, const char *devName) +{ + int err, client_id, port_id; + alsaseqMidi *amidi; + csCfgVariable_t *cfg; + char *client_name; + + *userData = NULL; + amidi = (alsaseqMidi*) malloc(sizeof(alsaseqMidi)); + if (UNLIKELY(amidi == NULL)) { + csound->ErrorMsg(csound, Str("ALSASEQ output: memory allocation failure")); + return -1; + } + memset(amidi, 0, sizeof(alsaseqMidi)); + err = snd_seq_open(&(amidi->seq), "default", + SND_SEQ_OPEN_DUPLEX, SND_SEQ_NONBLOCK); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: error opening sequencer (%s)"), + snd_strerror(err)); + free(amidi); + return -1; + } + csound->Message(csound, Str("ALSASEQ: opened MIDI output sequencer\n")); + cfg = csound->QueryConfigurationVariable(csound, "alsaseq_client"); + client_name = cfg->s.p; + err = snd_seq_set_client_name(amidi->seq, client_name); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot set client name '%s' (%s)"), + client_name, snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + err = snd_seq_create_simple_port(amidi->seq, client_name, + SND_SEQ_PORT_CAP_READ | + SND_SEQ_PORT_CAP_SUBS_READ, + SND_SEQ_PORT_TYPE_MIDI_GENERIC | + SND_SEQ_PORT_TYPE_APPLICATION); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot create output port (%s)"), + snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + client_id = snd_seq_client_id(amidi->seq); + port_id = err; + csound->Message(csound, Str("ALSASEQ: created output port '%s' %d:%d\n"), + client_name, client_id, port_id); + err = snd_midi_event_new(ALSASEQ_SYSEX_BUFFER_SIZE, &amidi->mev); + if (UNLIKELY(err < 0)) { + csound->ErrorMsg(csound, Str("ALSASEQ: cannot create midi event (%s)"), + snd_strerror(err)); + snd_seq_close(amidi->seq); + free(amidi); + return -1; + } + snd_midi_event_init(amidi->mev); + snd_seq_ev_clear(&amidi->sev); + snd_seq_ev_set_source(&amidi->sev, port_id); + snd_seq_ev_set_subs(&amidi->sev); + snd_seq_ev_set_direct(&amidi->sev); + alsaseq_connect(csound, amidi, SND_SEQ_PORT_CAP_WRITE, devName); + *userData = (void*) amidi; + return OK; +} + +static int alsaseq_out_write(CSOUND *csound, + void *userData, const unsigned char *buf, int nbytes) +{ + alsaseqMidi *amidi = (alsaseqMidi*) userData; + IGN(csound); + + if (nbytes == 0) + return 0; + snd_midi_event_reset_encode(amidi->mev); + nbytes = snd_midi_event_encode(amidi->mev, buf, nbytes, &amidi->sev); + snd_seq_event_output(amidi->seq, &amidi->sev); + snd_seq_drain_output(amidi->seq); + return nbytes; +} + +static int alsaseq_out_close(CSOUND *csound, void *userData) +{ + alsaseqMidi *amidi = (alsaseqMidi*) userData; + IGN(csound); + + if (amidi != NULL) { + snd_seq_drain_output(amidi->seq); + snd_midi_event_free(amidi->mev); + snd_seq_close(amidi->seq); + free(amidi); + } + return OK; +} /* module interface functions */ PUBLIC int csoundModuleCreate(CSOUND *csound) { - - int minsched, maxsched, *priority; + int minsched, maxsched, *priority, maxlen; + char *alsaseq_client; csound->CreateGlobalVariable(csound, "::priority", sizeof(int)); priority = (int *) (csound->QueryGlobalVariable(csound, "::priority")); if (priority == NULL) @@ -1109,31 +1524,269 @@ CSOUNDCFG_INTEGER, 0, &minsched, &maxsched, Str("RT scheduler priority, alsa module"), NULL); - + maxlen = 64; + alsaseq_client = (char*) calloc(maxlen, sizeof(char)); + strcpy(alsaseq_client, "Csound"); + csound->CreateConfigurationVariable(csound, "alsaseq_client", + (void*) alsaseq_client, CSOUNDCFG_STRING, + 0, NULL, &maxlen, + Str("ALSASEQ client name (default: Csound)"), + NULL); /* nothing to do, report success */ - if (csound->oparms->msglevel & 0x400) - csound->Message(csound, Str("ALSA real-time audio and MIDI module " - "for Csound by Istvan Varga\n")); - + { + OPARMS oparms; + csound->GetOParms(csound, &oparms); + if (oparms.msglevel & 0x400) + csound->Message(csound, Str("ALSA real-time audio and MIDI module " + "for Csound by Istvan Varga\n")); + } return 0; } +int listRawMidi(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput) { + int count = 0; + int card, err; + + card = -1; + if ((err = snd_card_next(&card)) < 0) { + csound->ErrorMsg(csound, + Str("cannot determine card number: %s"), snd_strerror(err)); + return 0; + } + if (card < 0) { + csound->ErrorMsg(csound,Str("no sound card found")); + return 0; + } + do { + snd_ctl_t *ctl; + char name[32]; + int device; + int err; + + sprintf(name, "hw:%d", card); + if ((err = snd_ctl_open(&ctl, name, 0)) < 0) { + csound->ErrorMsg(csound, Str("cannot open control for card %d: %s"), + card, snd_strerror(err)); + return 0; + } + device = -1; + for (;;) { + if ((err = snd_ctl_rawmidi_next_device(ctl, &device)) < 0) { + csound->ErrorMsg(csound, Str("cannot determine device number: %s"), + snd_strerror(err)); + break; + } + if (device < 0) + break; + snd_rawmidi_info_t *info; + const char *name; + const char *sub_name; + int subs, subs_in, subs_out; + int sub; + int err; + + snd_rawmidi_info_alloca(&info); + snd_rawmidi_info_set_device(info, device); + + snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_INPUT); + err = snd_ctl_rawmidi_info(ctl, info); + if (err >= 0) + subs_in = snd_rawmidi_info_get_subdevices_count(info); + else + subs_in = 0; + + snd_rawmidi_info_set_stream(info, SND_RAWMIDI_STREAM_OUTPUT); + err = snd_ctl_rawmidi_info(ctl, info); + if (err >= 0) + subs_out = snd_rawmidi_info_get_subdevices_count(info); + else + subs_out = 0; + + subs = subs_in > subs_out ? subs_in : subs_out; + if (!subs) + return 0; + + for (sub = 0; sub < subs; ++sub) { + snd_rawmidi_info_set_stream(info, sub < subs_in ? + SND_RAWMIDI_STREAM_INPUT : + SND_RAWMIDI_STREAM_OUTPUT); + snd_rawmidi_info_set_subdevice(info, sub); + err = snd_ctl_rawmidi_info(ctl, info); + if (err < 0) { + csound->Warning(csound, + Str("cannot get rawmidi information %d:%d:%d: %s\n"), + card, device, sub, snd_strerror(err)); + return 0; + } + name = snd_rawmidi_info_get_name(info); + sub_name = snd_rawmidi_info_get_subdevice_name(info); + if (sub == 0 && sub_name[0] == '\0') { + if (sub < subs_in && !isOutput) { + if (list) { + char devid[32]; + strncpy(list[count].device_name, name, 31); + sprintf(devid, "hw:%d,%d", card, device); + strncpy(list[count].device_id, devid, 63); + strncpy(list[count].interface_name, devid, 31); + strncpy(list[count].midi_module, "alsaraw", 8); + list[count].isOutput = isOutput; + } + count++; + } + if (sub < subs_out && isOutput) { + if (list) { + char devid[64]; + strncpy(list[count].device_name, name, 63); + sprintf(devid, "hw:%d,%d", card, device); + strncpy(list[count].device_id, devid, 63); + strncpy(list[count].interface_name, devid, 31); + strncpy(list[count].midi_module, "alsaraw", 8); + list[count].isOutput = isOutput; + } + count++; + } + break; + } else { + if (sub < subs_in && !isOutput) { + if (list) { + char devid[64]; + strncpy(list[count].device_name, sub_name, 63); + sprintf(devid, "hw:%d,%d,%d", card, device,sub); + strncpy(list[count].device_id, devid, 63); + strncpy(list[count].midi_module, "alsaraw", 8); + list[count].isOutput = isOutput; + } + count++; + } + if (sub < subs_out && isOutput) { + if (list) { + char devid[64]; + strncpy(list[count].device_name, sub_name, 63); + sprintf(devid, "hw:%d,%d,%d", card, device,sub); + strncpy(list[count].device_id, devid, 63); + strncpy(list[count].midi_module, "alsaraw", 8); + list[count].isOutput = isOutput; + } + count++; + } + } + } + + } + snd_ctl_close(ctl); + if ((err = snd_card_next(&card)) < 0) { + csound->Warning(csound, + Str("cannot determine card number: %s"), snd_strerror(err)); + break; + } + } while (card >= 0); + return count; +} + + +#define LIST_INPUT 1 +#define LIST_OUTPUT 2 + +#define perm_ok(pinfo,bits) \ + ((snd_seq_port_info_get_capability(pinfo) & (bits)) == (bits)) + +static int check_permission(snd_seq_port_info_t *pinfo, int perm) +{ + if (perm) { + if (perm & LIST_INPUT) { + if (perm_ok(pinfo, SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ)) + goto __ok; + } + if (perm & LIST_OUTPUT) { + if (perm_ok(pinfo, SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE)) + goto __ok; + } + return 0; + } + __ok: + if (snd_seq_port_info_get_capability(pinfo) & SND_SEQ_PORT_CAP_NO_EXPORT) + return 0; + return 1; +} + +int listAlsaSeq(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput) { + snd_seq_client_info_t *cinfo; + snd_seq_port_info_t *pinfo; + int numdevs = 0, count = 0; + snd_seq_t *seq; + + IGN(csound); + + if (snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { + fprintf(stderr, "can't open sequencer\n"); + return 1; + } + + snd_seq_client_info_alloca(&cinfo); + snd_seq_port_info_alloca(&pinfo); + snd_seq_client_info_set_client(cinfo, -1); + while (snd_seq_query_next_client(seq, cinfo) >= 0) { + /* reset query info */ + snd_seq_port_info_set_client(pinfo, snd_seq_client_info_get_client(cinfo)); + snd_seq_port_info_set_port(pinfo, -1); + count = 0; + while (snd_seq_query_next_port(seq, pinfo) >= 0) { + if (check_permission(pinfo, isOutput? LIST_OUTPUT : LIST_INPUT)) { + if (list) { + strncpy(list[numdevs].midi_module, "alsaseq", 15); + strncpy(list[numdevs].device_name, + snd_seq_port_info_get_name(pinfo), 63); + strncpy(list[numdevs].interface_name, + snd_seq_client_info_get_name(cinfo), 63); + sprintf(list[numdevs].device_id, "hw:%d,%d", + snd_seq_client_info_get_client(cinfo), + snd_seq_port_info_get_port(pinfo)); + } + numdevs++; + count++; + } + } + } + return numdevs; +} + +static int listDevicesM(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput){ + int count = 0; + char *s; + s = (char*) csound->QueryGlobalVariable(csound, "_RTMIDI"); + if (strncmp(s, "alsaraw", 8) == 0) { /* ALSA Raw MIDI */ + count = listRawMidi(csound, list, isOutput); + } else if (strncmp(s, "alsaseq", 8) == 0) {/* ALSA Sequencer */ + count = listAlsaSeq(csound, list, isOutput); + } else if (strncmp(s, "devfile", 8) == 0) { + + } else { + csound->ErrorMsg(csound, Str("rtalsa: Wrong callback.")); + } + return count; +} PUBLIC int csoundModuleInit(CSOUND *csound) { char *s; int i; char buf[9]; + OPARMS oparms; + csound->GetOParms(csound, &oparms); + + csound->module_list_add(csound, "alsa", "audio"); + csound->module_list_add(csound, "alsaraw", "midi"); + csound->module_list_add(csound, "alsaseq", "midi"); + csound->module_list_add(csound, "devfile", "midi"); csCfgVariable_t *cfg; int priority; - cfg = csound->QueryConfigurationVariable(csound, "rtscheduler"); - priority = *(cfg->i.p); - - if (priority != 0) set_scheduler_priority(csound, priority); - - csound->DeleteConfigurationVariable(csound, "rtscheduler"); - csound->DestroyGlobalVariable(csound, "::priority"); + if ((cfg=csound->QueryConfigurationVariable(csound, "rtscheduler")) != NULL) { + priority = *(cfg->i.p); + if (priority != 0) set_scheduler_priority(csound, priority); + csound->DeleteConfigurationVariable(csound, "rtscheduler"); + csound->DestroyGlobalVariable(csound, "::priority"); + } s = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO"); i = 0; @@ -1149,6 +1802,8 @@ csound->SetRtplayCallback(csound, rtplay_); csound->SetRtrecordCallback(csound, rtrecord_); csound->SetRtcloseCallback(csound, rtclose_); + csound->SetAudioDeviceListCallback(csound, listDevices); + } s = (char*) csound->QueryGlobalVariable(csound, "_RTMIDI"); i = 0; @@ -1157,14 +1812,27 @@ buf[i++] = *(s++) | (char) 0x20; } buf[i] = (char) 0; - if (strcmp(&(buf[0]), "alsa") == 0) { - csound->Message(csound, Str("rtmidi: ALSA module enabled\n")); + if (strcmp(&(buf[0]), "alsaraw") == 0 || strcmp(&(buf[0]), "alsa") == 0) { + csound->Message(csound, Str("rtmidi: ALSA Raw MIDI module enabled\n")); csound->SetExternalMidiInOpenCallback(csound, midi_in_open); csound->SetExternalMidiReadCallback(csound, midi_in_read); csound->SetExternalMidiInCloseCallback(csound, midi_in_close); csound->SetExternalMidiOutOpenCallback(csound, midi_out_open); csound->SetExternalMidiWriteCallback(csound, midi_out_write); csound->SetExternalMidiOutCloseCallback(csound, midi_out_close); + csound->SetMIDIDeviceListCallback(csound,listDevicesM); + + } + else if (strcmp(&(buf[0]), "alsaseq") == 0) { + if (oparms.msglevel & 0x400) + csound->Message(csound, Str("rtmidi: ALSASEQ module enabled\n")); + csound->SetExternalMidiInOpenCallback(csound, alsaseq_in_open); + csound->SetExternalMidiReadCallback(csound, alsaseq_in_read); + csound->SetExternalMidiInCloseCallback(csound, alsaseq_in_close); + csound->SetExternalMidiOutOpenCallback(csound, alsaseq_out_open); + csound->SetExternalMidiWriteCallback(csound, alsaseq_out_write); + csound->SetExternalMidiOutCloseCallback(csound, alsaseq_out_close); + csound->SetMIDIDeviceListCallback(csound,listDevicesM); } else if (strcmp(&(buf[0]), "devfile") == 0) { csound->Message(csound, Str("rtmidi: devfile module enabled\n")); @@ -1174,13 +1842,23 @@ csound->SetExternalMidiOutOpenCallback(csound, midi_out_open_file); csound->SetExternalMidiWriteCallback(csound, midi_out_write_file); csound->SetExternalMidiOutCloseCallback(csound, midi_out_close_file); + csound->SetMIDIDeviceListCallback(csound,listDevicesM); } return 0; } +PUBLIC int csoundModuleDestroy(CSOUND *csound) +{ + csCfgVariable_t *cfg; + + cfg = csound->QueryConfigurationVariable(csound, "alsaseq_client"); + if (cfg != NULL && cfg->s.p != NULL) + free(cfg->s.p); + return OK; +} + PUBLIC int csoundModuleInfo(void) { return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - diff -Nru csound-5.17.11~dfsg/InOut/rtauhal.c csound-6.02~dfsg/InOut/rtauhal.c --- csound-5.17.11~dfsg/InOut/rtauhal.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtauhal.c 2014-01-07 16:54:20.000000000 +0000 @@ -41,6 +41,15 @@ #endif +typedef struct { + char name[128]; + int outchannels; + int inchannels; + int indevnum; + int outdevnum; +} Device_Info; + + typedef struct csdata_ { AudioDeviceID dev; AudioStreamBasicDescription format; @@ -50,10 +59,6 @@ int currentOutputIndex; MYFLT *inputBuffer; MYFLT *outputBuffer; - void *auLock_in; /* thread lock for au callback */ - void *clientLock_in; /* thread lock for rtrecord */ - void *auLock_out; /* thread lock for au callback */ - void *clientLock_out; /* thread lock for rtplay */ csRtAudioParams *inParm; csRtAudioParams *outParm; int onchnls, inchnls; @@ -62,12 +67,16 @@ CSOUND *csound; AudioBufferList *inputdata; int disp; - int isInputRunning; - int isOutputRunning; AudioDeviceID defdevin; AudioDeviceID defdevout; + int devnos; + int devin; + int devout; + void *incb; + void *outcb; } csdata; + OSStatus Csound_Input(void *inRefCon, AudioUnitRenderActionFlags *ioActionFlags, const AudioTimeStamp *inTimeStamp, @@ -86,11 +95,13 @@ csdata *cdata, int isInput) { UInt32 psize, devnum, devnos; - AudioDeviceID *sysdevs; AudioDeviceID dev; + AudioDeviceID *sysdevs; AudioStreamBasicDescription format; int i; + Device_Info *devinfo; UInt32 bufframes, nchnls; + int devouts = 0, devins = 0; double srate; UInt32 enableIO, maxFPS; AudioComponent HALOutput; @@ -106,9 +117,11 @@ CFStringRef devName; CFStringEncoding defaultEncoding = CFStringGetSystemEncoding(); + + prop.mSelector = (isInput ? kAudioHardwarePropertyDefaultInputDevice : - kAudioHardwarePropertyDefaultOutputDevice ); + kAudioHardwarePropertyDefaultOutputDevice); psize = sizeof(AudioDeviceID); AudioObjectGetPropertyData(kAudioObjectSystemObject, @@ -118,52 +131,143 @@ else cdata->defdevout = dev; prop.mSelector = kAudioHardwarePropertyDevices; - AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, - &prop, 0, NULL, &psize); + &prop, 0, NULL, &psize); devnos = psize / sizeof(AudioDeviceID); sysdevs = (AudioDeviceID *) malloc(psize); - + devinfo = (Device_Info *) malloc(devnos*sizeof(Device_Info)); AudioObjectGetPropertyData(kAudioObjectSystemObject, &prop, 0, NULL, &psize, sysdevs); - if(cdata->disp){ + + cdata->devnos = devnos; + for (i = 0; (unsigned int) i < devnos; i++) { + AudioBufferList *b; + int devchannels, k, n; + int numlists; + psize = sizeof(CFStringRef); + prop.mScope = kAudioObjectPropertyScopeGlobal; + prop.mSelector = kAudioObjectPropertyName; + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, &devName); + strcpy(devinfo[i].name, CFStringGetCStringPtr(devName, defaultEncoding)); + CFRelease(devName); + + devchannels = 0; + prop.mScope = kAudioDevicePropertyScopeInput; + prop.mSelector = kAudioDevicePropertyStreamConfiguration; + AudioObjectGetPropertyDataSize(sysdevs[i], + &prop, 0, NULL, &psize); + b = (AudioBufferList *) malloc(psize); + numlists = psize / sizeof(AudioBufferList); + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, b); + for(n=0; n < numlists; n++){ + for(k=0; (unsigned int) k < b[n].mNumberBuffers; k++) + devchannels += b[n].mBuffers[k].mNumberChannels; + } + devinfo[i].inchannels = devchannels; + if(devchannels) { + devins++; + devinfo[i].indevnum = devins; + } else devinfo[i].indevnum = -1; + free(b); + + devchannels = 0; + prop.mScope = kAudioDevicePropertyScopeOutput; + AudioObjectGetPropertyDataSize(sysdevs[i], + &prop, 0, NULL, &psize); + b = (AudioBufferList *) malloc(psize); + numlists = psize /sizeof(AudioBufferList); + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, b); + for(n=0; n < numlists; n++){ + for(k=0; (unsigned int) k < b[n].mNumberBuffers; k++) + devchannels += b[n].mBuffers[k].mNumberChannels; + } + devinfo[i].outchannels = devchannels; + if(devchannels) { + devouts++; + devinfo[i].outdevnum = devouts; + } else devinfo[i].outdevnum = -1; + free(b); + } + + + if(cdata->disp) csound->Message(csound, - "==========================================================\n" - "AuHAL Module: found %d device(s):\n", (int) devnos); - for (i = 0; i < devnos; i++) { - psize = sizeof(CFStringRef); - prop.mSelector = kAudioObjectPropertyName; - AudioObjectGetPropertyData(sysdevs[i], - &prop, 0, NULL, &psize, &devName); - csound->Message(csound, "=> AuHAL device %d: %s \n", i, - CFStringGetCStringPtr(devName, defaultEncoding)); - CFRelease(devName); + "==========================================================\n"); + if (isInput) + csound->Message(csound, + Str("AuHAL Module: found %d input device(s):\n"), devins); + else csound->Message(csound, + Str("AuHAL Module: found %d output device(s):\n"), + devouts); + + for (i = 0; (unsigned int) i < devnos; i++) { + if (isInput) { + if(devinfo[i].inchannels) { + csound->Message(csound, Str("%d: %s (%d channels) \n"), + devinfo[i].indevnum, devinfo[i].name, + devinfo[i].inchannels); + } + } + else { + if(devinfo[i].outchannels) + csound->Message(csound, Str("%d: %s (%d channels) \n"), + devinfo[i].outdevnum, devinfo[i].name, + devinfo[i].outchannels); } - cdata->disp = 0; } - if (parm->devName != NULL) { - devnum = atoi(parm->devName); - if (devnum >= 0 && devnum < devnos) - dev = sysdevs[devnum]; - prop.mSelector = (isInput ? - kAudioHardwarePropertyDefaultInputDevice : - kAudioHardwarePropertyDefaultOutputDevice ); - AudioObjectSetPropertyData(kAudioObjectSystemObject, &prop, - 0, NULL, sizeof(AudioDeviceID), &dev); - free(sysdevs); + if (parm->devName != NULL) devnum = atoi(parm->devName); + else devnum = parm->devNum; + + if (devnum > 0 && devnum < 1024) { + int CoreAudioDev = -1; + prop.mSelector = kAudioHardwarePropertyDevices; + if (isInput) { + for(i=0; (unsigned int) i < devnos; i++) { + if((unsigned int) devinfo[i].indevnum == devnum) CoreAudioDev = i; + } + if(CoreAudioDev >= 0) { + prop.mSelector = kAudioHardwarePropertyDefaultInputDevice; + dev = sysdevs[CoreAudioDev]; + AudioObjectSetPropertyData(kAudioObjectSystemObject, &prop, + 0, NULL, sizeof(AudioDeviceID), &dev); + } + else csound->Warning(csound, Str("requested device %d out of range"), + devnum); + } + else { + prop.mSelector = kAudioHardwarePropertyDefaultOutputDevice; + for(i=0;(unsigned int) i < devnos; i++) { + if((unsigned int) devinfo[i].outdevnum == devnum) CoreAudioDev = i; + } + if(CoreAudioDev >= 0) { + dev = sysdevs[CoreAudioDev]; + AudioObjectSetPropertyData(kAudioObjectSystemObject, &prop, + 0, NULL, sizeof(AudioDeviceID), &dev); + } + else csound->Warning(csound, Str("requested device %d out of range"), + devnum, devinfo[CoreAudioDev].name); + } } + + + free(sysdevs); + free(devinfo); + psize = sizeof(CFStringRef); prop.mSelector = kAudioObjectPropertyName; AudioObjectGetPropertyData(dev, &prop, 0, NULL, &psize, &devName); if(isInput) csound->Message(csound, Str("selected input device: %s \n"), - CFStringGetCStringPtr(devName, defaultEncoding)); + CFStringGetCStringPtr(devName, defaultEncoding)); else csound->Message(csound, Str("selected output device: %s \n"), - CFStringGetCStringPtr(devName, defaultEncoding)); + CFStringGetCStringPtr(devName, defaultEncoding)); CFRelease(devName); @@ -186,12 +290,13 @@ double sr; AudioObjectGetPropertyData(dev, &prop, 0, NULL, &psize, &sr); if(sr != srate) { - csound->Die(csound, - "could not set SR, tried %.1f, got %.1f \n", srate, sr); + csound->Warning(csound, + Str("Attempted to set device SR, tried %.1f, got %.1f \n"), + srate, sr); } HALOutput = AudioComponentFindNext(NULL, &cd); - if(isInput){ + if (isInput) { AudioComponentInstanceNew(HALOutput, &(cdata->inunit)); enableIO = 1; AudioUnitSetProperty(cdata->inunit, kAudioOutputUnitProperty_EnableIO, @@ -204,12 +309,13 @@ AudioUnitSetProperty(cdata->inunit,kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, isInput, &dev, psize); aunit = &(cdata->inunit); - } else { + } + else { AudioComponentInstanceNew(HALOutput, &(cdata->outunit)); psize = sizeof(AudioDeviceID); /* for output, select device BEFORE enabling IO */ AudioUnitSetProperty(cdata->outunit, kAudioOutputUnitProperty_CurrentDevice, - kAudioUnitScope_Global, isInput, &dev, psize); + kAudioUnitScope_Global, isInput, &dev, psize); enableIO = 1; AudioUnitSetProperty(cdata->outunit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Output, 0, &enableIO, sizeof(enableIO)); @@ -260,9 +366,10 @@ AudioOutputUnitStart(*aunit); csound->Message(csound, - "AuHAL module: output device open with %d buffer frames\n" - "======================================================\n", - bufframes); + Str("***** AuHAL module: output device open with %d " + "buffer frames\n"), + bufframes); + cdata->disp = 0; } else { AURenderCallbackStruct input; @@ -286,70 +393,186 @@ AudioUnitInitialize(*aunit); AudioOutputUnitStart(*aunit); csound->Message(csound, - "AuHAL module: input device open with %d buffer frames\n" - "==============================================\n", - bufframes); - + "***** AuHAL module: input device open with %d buffer frames\n", + bufframes); } + if(!cdata->disp) + csound->Message(csound, + "==========================================================\n"); + cdata->disp = 0; return 0; } +int listDevices(CSOUND *csound, CS_AUDIODEVICE *list, int isOutput){ + UInt32 psize, devnos; + AudioDeviceID *sysdevs; + Device_Info *devinfo; + int i; + int devouts = 0, devins = 0; + + AudioObjectPropertyAddress prop = { + kAudioObjectPropertyName, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + CFStringRef devName; + CFStringEncoding defaultEncoding = CFStringGetSystemEncoding(); + prop.mSelector = kAudioHardwarePropertyDevices; + AudioObjectGetPropertyDataSize(kAudioObjectSystemObject, + &prop, 0, NULL, &psize); + devnos = psize / sizeof(AudioDeviceID); + sysdevs = (AudioDeviceID *) malloc(psize); + devinfo = (Device_Info *) malloc(devnos*sizeof*devinfo); + AudioObjectGetPropertyData(kAudioObjectSystemObject, + &prop, 0, NULL, &psize, sysdevs); + + for (i = 0; (unsigned int) i < devnos; i++) { + AudioBufferList *b; + int devchannels, k, n; + int numlists; + psize = sizeof(CFStringRef); + prop.mScope = kAudioObjectPropertyScopeGlobal; + prop.mSelector = kAudioObjectPropertyName; + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, &devName); + strcpy(devinfo[i].name, CFStringGetCStringPtr(devName, defaultEncoding)); + CFRelease(devName); + + devchannels = 0; + prop.mScope = kAudioDevicePropertyScopeInput; + prop.mSelector = kAudioDevicePropertyStreamConfiguration; + AudioObjectGetPropertyDataSize(sysdevs[i], + &prop, 0, NULL, &psize); + b = (AudioBufferList *) malloc(psize); + numlists = psize / sizeof(AudioBufferList); + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, b); + for(n=0; n < numlists; n++){ + for(k=0; (unsigned int) k < b[n].mNumberBuffers; k++) + devchannels += b[n].mBuffers[k].mNumberChannels; + } + devinfo[i].inchannels = devchannels; + if(devchannels) { + devins++; + devinfo[i].indevnum = devins; + } else devinfo[i].indevnum = -1; + free(b); + + devchannels = 0; + prop.mScope = kAudioDevicePropertyScopeOutput; + AudioObjectGetPropertyDataSize(sysdevs[i], + &prop, 0, NULL, &psize); + b = (AudioBufferList *) malloc(psize); + numlists = psize /sizeof(AudioBufferList); + AudioObjectGetPropertyData(sysdevs[i], + &prop, 0, NULL, &psize, b); + for(n=0; n < numlists; n++){ + for(k=0; (unsigned int) k < b[n].mNumberBuffers; k++) + devchannels += b[n].mBuffers[k].mNumberChannels; + } + devinfo[i].outchannels = devchannels; + if(devchannels) { + devouts++; + devinfo[i].outdevnum = devouts; + } else devinfo[i].outdevnum = -1; + free(b); + } + if(list==NULL){ + return (isOutput ? devouts : devins); + } else { + + char tmp[64], *s; + int n=0, i; + + if ((s = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO")) == NULL) + return 0; + + if(!isOutput){ + for(i=0; (unsigned int) i < devnos; i++) { + if(devinfo[i].inchannels) { + strncpy(list[n].device_name, devinfo[i].name, 63); + sprintf(tmp, "dac%d", devinfo[i].indevnum); + strncpy(list[n].device_id, tmp, 63); + strncpy(list[n].rt_module, s, 63); + list[n].max_nchnls = devinfo[i].inchannels; + list[n].isOutput = 0; + n++; + } + } + return n; + } else { + for(i=0;(unsigned int) i < devnos; i++){ + if(devinfo[i].outchannels) { + strncpy(list[n].device_name, devinfo[i].name, 63); + sprintf(tmp, "adc%d", devinfo[i].outdevnum); + strncpy(list[n].device_id, tmp, 63); + strncpy(list[n].rt_module, s, 63); + list[n].max_nchnls = devinfo[i].outchannels; + list[n].isOutput = 1; + n++; + } + } + return n; + } + } +} + /* open for audio input */ static int recopen_(CSOUND *csound, const csRtAudioParams * parm) { csdata *cdata; - - if (csound->rtRecord_userdata != NULL) + void **recordata = csound->GetRtRecordUserData(csound); + if (*(csound->GetRtRecordUserData(csound)) != NULL) return 0; /* allocate structure */ - if(csound->rtPlay_userdata != NULL) - cdata = (csdata *) csound->rtPlay_userdata; + if(*(csound->GetRtPlayUserData(csound) )!= NULL) + cdata = (csdata *) *(csound->GetRtPlayUserData(csound)); else { - cdata = (csdata *) calloc(1, sizeof(csdata)); + cdata = (csdata *) calloc(1, sizeof(csdata)); cdata->disp = 1; } cdata->inunit = NULL; - cdata->auLock_in = csound->CreateThreadLock(); - cdata->clientLock_in = csound->CreateThreadLock(); - csound->WaitThreadLock(cdata->auLock_in, (size_t) 500); - csound->WaitThreadLock(cdata->clientLock_in, (size_t) 500); - csound->rtRecord_userdata = (void *) cdata; + *recordata = (void *) cdata; cdata->inParm = (csRtAudioParams *) parm; cdata->csound = cdata->csound; cdata->inputBuffer = (MYFLT *) calloc (csound->GetInputBufferSize(csound), sizeof(MYFLT)); - cdata->isInputRunning = 1; - return AuHAL_open(csound, parm, cdata, 1); + cdata->incb = + csound->CreateCircularBuffer(csound, + parm->bufSamp_HW*parm->nChannels, sizeof(MYFLT)); + int ret = AuHAL_open(csound, parm, cdata, 1); + return ret; } /* open for audio output */ static int playopen_(CSOUND *csound, const csRtAudioParams * parm) { csdata *cdata; - if(csound->rtRecord_userdata != NULL) - cdata = (csdata *) csound->rtRecord_userdata; + void **playdata = csound->GetRtPlayUserData(csound); + + if(*(csound->GetRtRecordUserData(csound)) != NULL) + cdata = (csdata *) *(csound->GetRtRecordUserData(csound)); else { cdata = (csdata *) calloc(1, sizeof(csdata)); cdata->disp = 1; } cdata->outunit = NULL; - cdata->auLock_out = csound->CreateThreadLock(); - cdata->clientLock_out = csound->CreateThreadLock(); - csound->WaitThreadLock(cdata->auLock_out, (size_t) 500); - csound->WaitThreadLock(cdata->clientLock_out, (size_t) 500); - - csound->rtPlay_userdata = (void *) cdata; + *playdata = (void *) cdata; cdata->outParm = (csRtAudioParams *) parm; cdata->csound = csound; cdata->outputBuffer = (MYFLT *) calloc (csound->GetOutputBufferSize(csound), sizeof(MYFLT)); - cdata->isOutputRunning = 1; - return AuHAL_open(csound, parm, cdata, 0); + memset(cdata->outputBuffer, 0, + csound->GetOutputBufferSize(csound)*sizeof(MYFLT)); + cdata->outcb = + csound->CreateCircularBuffer(csound, + parm->bufSamp_HW*parm->nChannels, sizeof(MYFLT)); + return AuHAL_open(csound, parm,cdata,0); } OSStatus Csound_Input(void *inRefCon, @@ -365,28 +588,36 @@ MYFLT *inputBuffer = cdata->inputBuffer; int j,k; AudioUnitSampleType *buffer; - if(!cdata->isInputRunning) return 0; - csound->WaitThreadLock(cdata->auLock_in,10); + int n = inNumberFrames*inchnls; + int l; + IGN(ioData); + AudioUnitRender(cdata->inunit, ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, cdata->inputdata); for (k = 0; k < inchnls; k++){ buffer = (AudioUnitSampleType *) cdata->inputdata->mBuffers[k].mData; - for(j=0; j < inNumberFrames; j++){ + for(j=0; (unsigned int) j < inNumberFrames; j++){ inputBuffer[j*inchnls+k] = buffer[j]; } } - csound->NotifyThreadLock(cdata->clientLock_in); - + l = csound->WriteCircularBuffer(csound, cdata->incb,inputBuffer,n); return 0; } +#define MICROS 1000000 static int rtrecord_(CSOUND *csound, MYFLT *inbuff_, int nbytes) { csdata *cdata; + int n = nbytes/sizeof(MYFLT); + int m = 0, l, w = n; + MYFLT sr = csound->GetSr(csound); cdata = (csdata *) *(csound->GetRtRecordUserData(csound)); - csound->WaitThreadLock(cdata->clientLock_in, (size_t) 500); - memcpy(inbuff_,cdata->inputBuffer,nbytes); - csound->NotifyThreadLock(cdata->auLock_in); + do{ + l = csound->ReadCircularBuffer(csound,cdata->incb,&inbuff_[m],n); + m += l; + n -= l; + if(n) usleep(MICROS*w/sr); + } while(n); return nbytes; } @@ -397,36 +628,40 @@ UInt32 inNumberFrames, AudioBufferList *ioData) { - csdata *cdata = (csdata *) inRefCon; CSOUND *csound = cdata->csound; - int onchnls = cdata->onchnls;; + int onchnls = cdata->onchnls; MYFLT *outputBuffer = cdata->outputBuffer; int j,k; AudioUnitSampleType *buffer; + int n = inNumberFrames*onchnls; + IGN(ioActionFlags); + IGN(inTimeStamp); + IGN(inBusNumber); - if(!cdata->isOutputRunning) return 0; - csound->WaitThreadLock(cdata->auLock_out, 10); + n = csound->ReadCircularBuffer(csound,cdata->outcb,outputBuffer,n); for (k = 0; k < onchnls; k++) { buffer = (AudioUnitSampleType *) ioData->mBuffers[k].mData; - for(j=0; j < inNumberFrames; j++){ + for(j=0; (unsigned int) j < inNumberFrames; j++){ buffer[j] = (AudioUnitSampleType) outputBuffer[j*onchnls+k] ; } } - csound->NotifyThreadLock(cdata->clientLock_out); - return 0; } static void rtplay_(CSOUND *csound, const MYFLT *outbuff_, int nbytes) { - csdata *cdata; + int n = nbytes/sizeof(MYFLT); + int m = 0, l, w = n; + MYFLT sr = csound->GetSr(csound); cdata = (csdata *) *(csound->GetRtPlayUserData(csound)); - csound->WaitThreadLock(cdata->clientLock_out, (size_t) 500); - memcpy(cdata->outputBuffer,outbuff_,nbytes); - csound->NotifyThreadLock(cdata->auLock_out); - + do { + l = csound->WriteCircularBuffer(csound, cdata->outcb,&outbuff_[m],n); + m += l; + n -= l; + if(n) usleep(MICROS*w/sr); + } while(n); } /* close the I/O device entirely */ @@ -448,38 +683,12 @@ AudioUnitUninitialize(cdata->inunit); AudioComponentInstanceDispose(cdata->inunit); } - cdata->isInputRunning = 0; if(cdata->outunit != NULL){ AudioOutputUnitStop(cdata->outunit); AudioUnitUninitialize(cdata->outunit); AudioComponentInstanceDispose(cdata->outunit); } - cdata->isOutputRunning = 0; - - if (cdata->clientLock_in != NULL) { - csound->NotifyThreadLock(cdata->clientLock_in); - csound->DestroyThreadLock(cdata->clientLock_in); - cdata->clientLock_in = NULL; - } - if (cdata->auLock_in != NULL) { - csound->NotifyThreadLock(cdata->auLock_in); - csound->DestroyThreadLock(cdata->auLock_in); - cdata->auLock_in = NULL; - } - - if (cdata->clientLock_out != NULL) { - csound->NotifyThreadLock(cdata->clientLock_out); - csound->DestroyThreadLock(cdata->clientLock_out); - cdata->clientLock_in = NULL; - } - - if (cdata->auLock_out != NULL) { - csound->NotifyThreadLock(cdata->auLock_out); - csound->DestroyThreadLock(cdata->auLock_out); - cdata->auLock_out = NULL; - } - if (cdata->outputBuffer != NULL) { free(cdata->outputBuffer); @@ -489,8 +698,9 @@ free(cdata->inputBuffer); cdata->inputBuffer = NULL; } - csound->rtRecord_userdata = NULL; - csound->rtPlay_userdata = NULL; + + *(csound->GetRtRecordUserData(csound)) = NULL; + *(csound->GetRtPlayUserData(csound)) = NULL; if(cdata->inputdata) { int i; @@ -500,34 +710,36 @@ } if(cdata->defdevin) { - AudioObjectPropertyAddress prop = { - kAudioHardwarePropertyDefaultInputDevice, - kAudioObjectPropertyScopeGlobal, - kAudioObjectPropertyElementMaster - }; - UInt32 psize = sizeof(AudioDeviceID); - AudioObjectSetPropertyData(kAudioObjectSystemObject, - &prop, 0, NULL, psize, &cdata->defdevin); + AudioObjectPropertyAddress prop = { + kAudioHardwarePropertyDefaultInputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + UInt32 psize = sizeof(AudioDeviceID); + AudioObjectSetPropertyData(kAudioObjectSystemObject, + &prop, 0, NULL, psize, &cdata->defdevin); } if(cdata->defdevout) { - AudioObjectPropertyAddress prop = { - kAudioHardwarePropertyDefaultOutputDevice, - kAudioObjectPropertyScopeGlobal, - kAudioObjectPropertyElementMaster - }; - UInt32 psize = sizeof(AudioDeviceID); - AudioObjectSetPropertyData(kAudioObjectSystemObject, - &prop, 0, NULL, psize, &cdata->defdevout); - } + AudioObjectPropertyAddress prop = { + kAudioHardwarePropertyDefaultOutputDevice, + kAudioObjectPropertyScopeGlobal, + kAudioObjectPropertyElementMaster + }; + UInt32 psize = sizeof(AudioDeviceID); + AudioObjectSetPropertyData(kAudioObjectSystemObject, + &prop, 0, NULL, psize, &cdata->defdevout); + } + csound->DestroyCircularBuffer(csound, cdata->incb); + csound->DestroyCircularBuffer(csound, cdata->outcb); free(cdata); csound->Message(csound, Str("AuHAL module: device closed\n")); - } } int csoundModuleInit(CSOUND *csound) { char *drv; + csound->module_list_add(csound, "auhal", "audio"); drv = (char *) csound->QueryGlobalVariable(csound, "_RTAUDIO"); if (drv == NULL) return 0; @@ -536,18 +748,19 @@ strcmp(drv, "coreaudio") == 0 || strcmp(drv, "CoreAudio") == 0 || strcmp(drv, "COREAUDIO") == 0)) return 0; - if (csound->oparms->msglevel & 0x400) - csound->Message(csound, Str("rtaudio: coreaaudio-AuHAL module enabled\n")); + //if (csound->oparms->msglevel & 0x400) + csound->Message(csound, Str("rtaudio: coreaaudio-AuHAL module enabled\n")); csound->SetPlayopenCallback(csound, playopen_); csound->SetRecopenCallback(csound, recopen_); csound->SetRtplayCallback(csound, rtplay_); csound->SetRtrecordCallback(csound, rtrecord_); csound->SetRtcloseCallback(csound, rtclose_); + csound->SetAudioDeviceListCallback(csound, listDevices); return 0; } int csoundModuleCreate(CSOUND *csound) { - CSOUND *p = csound; + IGN(csound); return 0; } diff -Nru csound-5.17.11~dfsg/InOut/rtcoreaudio.c csound-6.02~dfsg/InOut/rtcoreaudio.c --- csound-5.17.11~dfsg/InOut/rtcoreaudio.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtcoreaudio.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,576 +0,0 @@ -/* - rtcoreaudio.c: - - Copyright (C) 2005 Victor Lazzarini - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* this code is deprecated, has been substituted by the rtauhal.c module */ - - -#include -#include -#include -#include "csdl.h" -#include "soundio.h" - - -typedef struct devparams_ { - AudioDeviceID dev; - float **inbuffs; - float **outbuffs; - AudioStreamBasicDescription format; - unsigned int bufframes; - unsigned int buffnos; - unsigned int outcurbuff; - unsigned int incurbuff; - unsigned int iocurbuff; - unsigned int outcount; - unsigned int incount; - int *inused; - int *outused; - float srate; - int nchns; - int isNInterleaved; -#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5) - AudioDeviceIOProcID procID; -#else - int procID; -#endif -} DEVPARAMS; - -/* module interface functions */ - -int csoundModuleCreate(CSOUND *csound) -{ - int min, max, *def; - CSOUND *p = csound; - - min = 2; - max = 32; - - p->CreateGlobalVariable(csound, "::cabuffnos", sizeof(int)); - def = (int *) (p->QueryGlobalVariable(csound, "::cabuffnos")); - if (def == NULL) - p->Message(csound, Str("warning... could not create global var\n")); - else - *def = 4; - p->CreateConfigurationVariable(csound, "buffnos", def, - CSOUNDCFG_INTEGER, 0, &min, &max, - "coreaudio IO buffer numbers", NULL); - - p->CreateGlobalVariable(csound, "::cainterleaved", sizeof(int)); - def = (int *) (p->QueryGlobalVariable(csound, "::cainterleaved")); - if (def == NULL) - p->Message(csound, Str("warning... could not create global var\n")); - else - *def = 0; - p->CreateConfigurationVariable(csound, "noninterleaved", def, - CSOUNDCFG_BOOLEAN, 0, NULL, NULL, - "deprecated, noninterleaved audio is automatically detected", - NULL); - - if (csound->oparms->msglevel & 0x400) - p->Message(csound, Str("CoreAudio real-time audio module for Csound\n" - "by Victor Lazzarini\n")); - return 0; -} - -static int playopen_(CSOUND *, const csRtAudioParams *); -static int recopen_(CSOUND *, const csRtAudioParams *); -static void rtplay_(CSOUND *, const MYFLT *, int); -static int rtrecord_(CSOUND *, MYFLT *, int); -static void rtclose_(CSOUND *); - -int csoundModuleInit(CSOUND *csound) -{ - char *drv; - - drv = (char *) csound->QueryGlobalVariable(csound, "_RTAUDIO"); - if (drv == NULL) - return 0; - if (!(strcmp(drv, "coreaudio") == 0 || strcmp(drv, "CoreAudio") == 0 || - strcmp(drv, "COREAUDIO") == 0)) - return 0; - if (csound->oparms->msglevel & 0x400) - csound->Message(csound, Str("rtaudio: CoreAudio module enabled\n")); - csound->SetPlayopenCallback(csound, playopen_); - csound->SetRecopenCallback(csound, recopen_); - csound->SetRtplayCallback(csound, rtplay_); - csound->SetRtrecordCallback(csound, rtrecord_); - csound->SetRtcloseCallback(csound, rtclose_); - return 0; -} - -OSStatus -ADIOProc(const AudioBufferList * input, - AudioBufferList * output, DEVPARAMS * cdata) -{ - int i, j, cnt; - int chans = cdata->nchns; - int cachans = output->mBuffers[0].mNumberChannels; - int inchans = input->mBuffers[0].mNumberChannels; - int items; - int buff = cdata->iocurbuff; - float *outp, *inp; - float *ibufp = cdata->inbuffs[buff]; - float *obufp = cdata->outbuffs[buff]; - - if (input->mNumberBuffers > 1) cdata->isNInterleaved = 1; - - if (cdata->isNInterleaved) { - - int nibuffs = input->mNumberBuffers, buffs; - int nobuffs = output->mNumberBuffers; - - items = cdata->bufframes * chans; - buffs = nibuffs > nobuffs ? nibuffs : nobuffs; - output->mNumberBuffers = buffs; - chans = chans > buffs ? buffs : chans; - for (j = 0; j < chans; j++) { - outp = (float *) output[0].mBuffers[j].mData; - inp = (float *) input[0].mBuffers[j].mData; - - for (i = j, cnt = 0; i < items; i += chans, cnt++) { - outp[cnt] = obufp[i]; - obufp[i] = 0.0f; - ibufp[i] = inp[cnt]; - } - output->mBuffers[j].mDataByteSize = input[0].mBuffers[j].mDataByteSize; - output->mBuffers[j].mNumberChannels = 1; - } - } - else { - items = cdata->bufframes * cachans; - output->mNumberBuffers = 1; - output->mBuffers[0].mDataByteSize = items * sizeof(float); - output->mBuffers[0].mNumberChannels = cachans; - outp = (float *) output->mBuffers[0].mData; - inp = (float *) input->mBuffers[0].mData; - for (i = 0, cnt = 0; i < items; i += cachans) { - for (j = 0; j < cachans; j++) - if (j < chans) { - outp[i + j] = obufp[cnt]; - obufp[cnt] = 0.0f; - if (inp != NULL && j < inchans) - ibufp[cnt] = inp[i + j]; - cnt++; - } - else - outp[i + j] = 0.0f; - } - } - cdata->outused[buff] = cdata->inused[buff] = 1; - buff++; - buff %= cdata->buffnos; - cdata->iocurbuff = buff; - - return 0; -} - -OSStatus Csound_IOProcEntry(AudioDeviceID indev, - const AudioTimeStamp * inN, - const AudioBufferList * input, - const AudioTimeStamp * inT, - AudioBufferList * output, - const AudioTimeStamp * inOT, void *cdata) -{ - return ADIOProc(input, output, (DEVPARAMS *) cdata); -} - -int coreaudio_open(CSOUND *csound, const csRtAudioParams * parm, - DEVPARAMS * dev, int isInput) -{ - - CSOUND *p; - UInt32 psize, devnum, devnos; - double sr; - AudioDeviceID *sysdevs; - AudioStreamBasicDescription format; - int i, bfns, *vpt; - char *name; - UInt32 obufframes, ibufframes, buffbytes; - - memset(dev, 0, sizeof(DEVPARAMS)); - p = (CSOUND *) csound; - /* set up parameters */ - vpt = (int *) (p->QueryGlobalVariable(csound, "::cabuffnos")); - if (vpt != NULL) - bfns = *vpt; - else - bfns = 4; - - p->DeleteConfigurationVariable(csound, "buffnos"); - p->DestroyGlobalVariable(csound, "::cabuffnos"); - - vpt = (int *) (p->QueryGlobalVariable(csound, "::cainterleaved")); - - /* - if (vpt != NULL) - dev->isNInterleaved = *vpt; - else - dev->isNInterleaved = 0; - */ - - p->DeleteConfigurationVariable(csound, "interleaved"); - p->DestroyGlobalVariable(csound, "::cainterleaved"); - - psize = sizeof(AudioDeviceID); - AudioHardwareGetProperty(kAudioHardwarePropertyDefaultOutputDevice, - &psize, &dev->dev); - - AudioHardwareGetPropertyInfo(kAudioHardwarePropertyDevices, &psize, NULL); - devnos = psize / sizeof(AudioDeviceID); - sysdevs = (AudioDeviceID *) malloc(psize); - AudioHardwareGetProperty(kAudioHardwarePropertyDevices, &psize, sysdevs); - if (csound->oparms->msglevel & 0x400) { - p->Message(csound, - "==========================================================\n" - "CoreAudio Module: found %d device(s):\n", (int) devnos); - - for (i = 0; (unsigned int) i < devnos; i++) { - - AudioDeviceGetPropertyInfo(sysdevs[i], 1, false, - kAudioDevicePropertyDeviceName, &psize, NULL); - name = (char *) malloc(psize); - AudioDeviceGetProperty(sysdevs[i], 1, false, - kAudioDevicePropertyDeviceName, &psize, name); - p->Message(csound, "=> CoreAudio device %d: %s \n", i, name); - free(name); - } - if (parm->devName != NULL) { - devnum = atoi(parm->devName); - if (devnum >= 0 && devnum < devnos) - dev->dev = sysdevs[devnum]; - p->Message(csound, Str("selected device: %u \n"), (unsigned int) devnum); - free(sysdevs); - } - - AudioDeviceGetPropertyInfo(dev->dev, 1, false, - kAudioDevicePropertyDeviceName, &psize, NULL); - name = (char *) malloc(psize); - AudioDeviceGetProperty(dev->dev, 1, false, kAudioDevicePropertyDeviceName, - &psize, name); - p->Message(csound, Str("CoreAudio module: opening %s \n"), name); - free(name); - } - dev->srate = (float) (parm->sampleRate); - dev->nchns = parm->nChannels; - dev->bufframes = parm->bufSamp_HW; - dev->buffnos = bfns; - - psize = 4; - /* set the buffer size - output */ - AudioDeviceSetProperty(dev->dev, NULL, 0, false, - kAudioDevicePropertyBufferFrameSize, - psize, &dev->bufframes); - /* input */ - AudioDeviceSetProperty(dev->dev, NULL, 0, true, - kAudioDevicePropertyBufferFrameSize, - psize, &dev->bufframes); - - /* check that it matches the expected size */ - AudioDeviceGetProperty(dev->dev, 0, true, - kAudioDevicePropertyBufferFrameSize, - &psize, &ibufframes); - - AudioDeviceGetProperty(dev->dev, 0, false, - kAudioDevicePropertyBufferFrameSize, - &psize, &obufframes); - - if (ibufframes != dev->bufframes) { - if (ibufframes == obufframes) - dev->bufframes = obufframes; - else { - free(dev); - csound->rtRecord_userdata = NULL; - p->Message(csound, Str(" *** CoreAudio: open: could not set buffer size\n")); - return -1; - } - } - psize = sizeof(double); - sr = dev->srate; - AudioDeviceSetProperty(dev->dev, NULL, 0, true, - kAudioDevicePropertyNominalSampleRate, psize, &sr); - AudioDeviceSetProperty(dev->dev, NULL, 0, false, - kAudioDevicePropertyNominalSampleRate, psize, &sr); - - psize = sizeof(AudioStreamBasicDescription); - AudioDeviceGetProperty(dev->dev, 0, false, - kAudioDevicePropertyStreamFormat, &psize, &format); - - dev->isNInterleaved = 0; - - dev->format.mSampleRate = dev->srate; - dev->format.mFormatID = kAudioFormatLinearPCM; - dev->format.mFormatFlags = kAudioFormatFlagIsFloat | format.mFormatFlags; - dev->format.mBytesPerPacket = sizeof(float) * dev->nchns; - dev->format.mFramesPerPacket = 1; - dev->format.mBytesPerFrame = format.mBytesPerPacket; - dev->format.mChannelsPerFrame = dev->nchns; - dev->format.mBitsPerChannel = sizeof(float); - - psize = sizeof(AudioStreamBasicDescription); - - AudioDeviceSetProperty(dev->dev, NULL, 0, true, - kAudioDevicePropertyStreamFormat, - psize, &dev->format); - AudioDeviceSetProperty(dev->dev, NULL, 0, false, - kAudioDevicePropertyStreamFormat, - psize, &dev->format); - AudioDeviceGetProperty(dev->dev, 0, false, - kAudioDevicePropertyStreamFormat, &psize, &format); - - if (format.mChannelsPerFrame != (unsigned int) dev->nchns && - !dev->isNInterleaved) { - dev->format.mChannelsPerFrame = format.mChannelsPerFrame; - } - - if (format.mSampleRate != dev->srate) { - csound->rtRecord_userdata = NULL; - p->Message(csound, - Str(" *** CoreAudio: open: could not set device parameter sr: %d \n"), - (int) dev->srate); - p->Message(csound, Str(" *** CoreAudio: current device sampling rate is:%d \n" - " try setting the above value in your csound orchestra \n"), - (int) format.mSampleRate); - free(dev); - return -1; - } - else{ - - p->Message(csound, - Str("CoreAudio module: sr set to %d with %d audio channels \n"), - (int) dev->srate, (int) dev->nchns); - } - - dev->outbuffs = (float **) malloc(sizeof(float *) * dev->buffnos); - dev->inbuffs = (float **) malloc(sizeof(float *) * dev->buffnos); - dev->inused = (int *) malloc(sizeof(int) * dev->buffnos); - dev->outused = (int *) malloc(sizeof(int) * dev->buffnos); - - buffbytes = dev->bufframes * dev->nchns * sizeof(float); - - for (i = 0; (unsigned int) i < dev->buffnos; i++) { - - if ((dev->inbuffs[i] = (float *) malloc(buffbytes)) == NULL) { - free(dev->outbuffs); - free(dev->inbuffs); - free(dev->inused); - free(dev->outused); - free(dev); - csound->rtRecord_userdata = NULL; - p->Message(csound, - Str(" *** CoreAudio: open: memory allocation failure\n")); - return -1; - } - memset(dev->inbuffs[i], 0, buffbytes); - - if ((dev->outbuffs[i] = (float *) malloc(buffbytes)) == NULL) { - free(dev->outbuffs); - free(dev->inbuffs); - free(dev->inused); - free(dev->outused); - free(dev); - csound->rtRecord_userdata = NULL; - p->Message(csound, - Str(" *** CoreAudio: open: memory allocation failure\n")); - return -1; - } - memset(dev->outbuffs[i], 0, buffbytes); - dev->inused[i] = dev->outused[i] = 1; - } - - dev->incurbuff = dev->outcurbuff = dev->iocurbuff = 0; - dev->incount = dev->outcount = 0; - dev->procID = 0; - - // - -#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5) - AudioDeviceCreateIOProcID(dev->dev,Csound_IOProcEntry,dev,&dev->procID); -#else - AudioDeviceAddIOProc(dev->dev, Csound_IOProcEntry, dev); -#endif - AudioDeviceStart(dev->dev,Csound_IOProcEntry); - - - if (isInput) - csound->rtPlay_userdata = (void *) dev; - else - csound->rtRecord_userdata = (void *) dev; - - p->Message(csound, - Str("CoreAudio module: device open with %d buffers of %d frames\n" - "==========================================================\n"), - dev->buffnos, dev->bufframes); - return 0; -} - -/* open for audio input */ -static int recopen_(CSOUND *csound, const csRtAudioParams * parm) -{ - CSOUND *p; - DEVPARAMS *dev; - - p = (CSOUND *) csound; - if (csound->rtRecord_userdata != NULL) - return 0; - /* allocate structure */ - dev = (DEVPARAMS *) malloc(sizeof(DEVPARAMS)); - if (dev == NULL) { - p->Message(csound, Str(" *** CoreAudio: open: memory allocation failure\n")); - return -1; - } - csound->rtRecord_userdata = (void *) dev; - - return coreaudio_open(csound, parm, dev, 1); -} - -/* open for audio output */ -static int playopen_(CSOUND *csound, const csRtAudioParams * parm) -{ - CSOUND *p; - DEVPARAMS *dev; - - p = (CSOUND *) csound; - if (csound->rtPlay_userdata != NULL) - return 0; - /* allocate structure */ - dev = (DEVPARAMS *) malloc(sizeof(DEVPARAMS)); - if (dev == NULL) { - p->Message(csound, Str(" *** CoreAudio: open: memory allocation failure\n")); - return -1; - } - csound->rtPlay_userdata = (void *) dev; - - return coreaudio_open(csound, parm, dev, 0); -} - -static int rtrecord_(CSOUND *csound, MYFLT *inbuf_, int bytes_) -{ - DEVPARAMS *dev; - CSOUND *p; - int n, i, chans, cur, icount, buffitems, buffnos, *inused, usecs; - float **ibuffs; - - /* MYFLT norm; */ - p = (CSOUND *) csound; - dev = (DEVPARAMS *) (csound->rtRecord_userdata); - usecs = (int) (1000 * dev->bufframes / p->esr); - n = bytes_ / sizeof(MYFLT); - chans = dev->nchns; - ibuffs = dev->inbuffs; - cur = dev->incurbuff; - inused = dev->inused; - icount = dev->incount; - buffnos = dev->buffnos; - buffitems = dev->bufframes * chans; - /* norm = p->e0dbfs; */ - - for (i = 0; i < n; i++) { - ((MYFLT *) inbuf_)[i] = ibuffs[cur][icount]; - icount++; - if (icount == buffitems) { - inused[cur] = 0; - cur++; - cur %= buffnos; - icount = 0; - while (!inused[cur]) - usleep(usecs); - } - } /* for */ - dev->incount = icount; - dev->incurbuff = cur; - - return bytes_; - -} - -/* put samples to DAC */ - -static void rtplay_(CSOUND *csound, const MYFLT *outbuf_, int bytes_) -{ - DEVPARAMS *dev; - CSOUND *p; - int n, i, chans, cur, ocount, buffitems, buffnos, *outused, usecs; - float **obuffs; - - /* MYFLT norm; */ - p = (CSOUND *) csound; - dev = (DEVPARAMS *) (csound->rtRecord_userdata); - - n = bytes_ / sizeof(MYFLT); - usecs = (int) (1000 * dev->bufframes / p->esr); - chans = dev->nchns; - obuffs = dev->outbuffs; - cur = dev->outcurbuff; - outused = dev->outused; - ocount = dev->outcount; - buffnos = dev->buffnos; - buffitems = dev->bufframes * chans; - /* norm = p->e0dbfs; */ - - for (i = 0; i < n; i++) { - obuffs[cur][ocount] = (float) outbuf_[i]; - ocount++; - if (ocount == buffitems) { - outused[cur] = 0; - cur++; - cur %= buffnos; - ocount = 0; - while (!outused[cur]) - usleep(usecs); - } - } - - dev->outcurbuff = cur; - dev->outcount = ocount; -} - -/* close the I/O device entirely */ -/* called only when both complete */ - -static void rtclose_(CSOUND *csound) -{ - DEVPARAMS *dev; - CSOUND *p; - - p = (CSOUND *) csound; - dev = (DEVPARAMS *) (csound->rtRecord_userdata); - if (dev != NULL) { - p->Message(csound, Str("coreaudio module: closing device...\n")); - sleep(1); - AudioDeviceStop(dev->dev,Csound_IOProcEntry ); -#if defined(MAC_OS_X_VERSION_10_5) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_5) - AudioDeviceDestroyIOProcID(dev->dev, dev->procID); -#else - AudioDeviceRemoveIOProc(dev->dev, Csound_IOProcEntry); -#endif - csound->rtRecord_userdata = NULL; - free(dev->outbuffs); - free(dev->inbuffs); - free(dev->inused); - free(dev->outused); - free(dev); - p->Message(csound, Str("coreaudio module: device closed\n")); - } -} - diff -Nru csound-5.17.11~dfsg/InOut/rtjack.c csound-6.02~dfsg/InOut/rtjack.c --- csound-5.17.11~dfsg/InOut/rtjack.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtjack.c 2014-01-07 16:53:47.000000000 +0000 @@ -1,24 +1,24 @@ /* - rtjack.c: + rtjack.c: - Copyright (C) 2005, 2006 Istvan Varga + Copyright (C) 2005, 2006 Istvan Varga - This file is part of Csound. + This file is part of Csound. - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ #include @@ -210,7 +210,7 @@ int i, nChn, maxChn, len, nPorts, retval = -1; portFlags = (isOutput ? (unsigned long) JackPortIsInput - : (unsigned long) JackPortIsOutput); + : (unsigned long) JackPortIsOutput); len = jack_port_name_size(); prvPortName = (char*) malloc((size_t) len); if (UNLIKELY(prvPortName == (char*) NULL)) @@ -226,7 +226,7 @@ goto err_return; retval = 0; csound->Message(csound, Str("The available JACK %s devices are:\n"), - (isOutput ? Str("output") : Str("input"))); + (isOutput ? Str("output") : Str("input"))); /* count the number of ports, and sort port names in alphabetical order */ for (nPorts = 0; portNames[nPorts] != NULL; nPorts++) ; @@ -265,7 +265,7 @@ maxChn = chn_; } continue; - nextPortName: + nextPortName: if (nChn == maxChn) rtJack_PrintPortName(csound, prvPortName, nChn); prvPortName[0] = (char) 0; @@ -392,7 +392,7 @@ } } } - +static int listDevices(CSOUND *csound, CS_AUDIODEVICE *list, int isOutput); /* connect to JACK server, set up ports and ring buffers, */ /* activate client, and connect ports if requested */ @@ -415,7 +415,7 @@ if (UNLIKELY(p->sampleRate != (int) jack_get_sample_rate(p->client))) { sprintf(&(buf[0]), Str("sample rate %d does not match " "JACK sample rate %d"), - p->sampleRate, (int) jack_get_sample_rate(p->client)); + p->sampleRate, (int) jack_get_sample_rate(p->client)); rtJack_Error(p->csound, -1, &(buf[0])); } if (UNLIKELY(p->bufSize < 8 || p->bufSize > 32768)) @@ -460,21 +460,25 @@ p->outPortBufs[0] = (jack_default_audio_sample_t*) NULL; /* register callback functions */ - if (UNLIKELY(jack_set_sample_rate_callback(p->client, sampleRateCallback, (void*) p) + if (UNLIKELY(jack_set_sample_rate_callback(p->client, + sampleRateCallback, (void*) p) != 0)) rtJack_Error(csound, -1, Str("error setting sample rate callback")); - if (UNLIKELY(jack_set_buffer_size_callback(p->client, bufferSizeCallback, (void*) p) + if (UNLIKELY(jack_set_buffer_size_callback(p->client, + bufferSizeCallback, (void*) p) != 0)) rtJack_Error(csound, -1, Str("error setting buffer size callback")); #ifdef LINUX - if (UNLIKELY(jack_set_freewheel_callback(p->client, freeWheelCallback, (void*) p) + if (UNLIKELY(jack_set_freewheel_callback(p->client, + freeWheelCallback, (void*) p) != 0)) rtJack_Error(csound, -1, Str("error setting freewheel callback")); #endif if (UNLIKELY(jack_set_xrun_callback(p->client, xrunCallback, (void*) p) != 0)) rtJack_Error(csound, -1, Str("error setting xrun callback")); jack_on_shutdown(p->client, shutDownCallback, (void*) p); - if (UNLIKELY(jack_set_process_callback(p->client, processCallback, (void*) p) != 0)) + if (UNLIKELY(jack_set_process_callback(p->client, + processCallback, (void*) p) != 0)) rtJack_Error(csound, -1, Str("error setting process callback")); /* activate client */ @@ -482,31 +486,65 @@ rtJack_Error(csound, -1, Str("error activating JACK client")); /* connect ports if requested */ - if (p->inputEnabled && p->inDevName != NULL) { - char *sp = strchr(p->inDevName, '\0'); - for (i = 0; i < p->nChannels; i++) { - sprintf(sp, "%d", i + 1); - if (UNLIKELY(jack_connect(p->client, p->inDevName, - jack_port_name(p->inPorts[i])) != 0)) { - rtJack_ListPorts(csound, p->client, &(p->clientName[0]), 0); - rtJack_Error(csound, -1, Str("error connecting input ports")); + if (p->inputEnabled) { + char dev[128], *dev_final, *sp; + { + int i,n = listDevices(csound,NULL,0); + CS_AUDIODEVICE *devs = (CS_AUDIODEVICE *) + malloc(n*sizeof(CS_AUDIODEVICE)); + listDevices(csound,devs,0); + for(i=0; i < n; i++) + csound->Message(csound, " %d: %s (%s)\n", + i, devs[i].device_id, devs[i].device_name); + strncpy(dev, devs[0].device_name, 128); + free(devs); + } + if(p->inDevName != NULL) + strncpy(dev, p->inDevName, 128); + if (dev) { + dev_final = dev; + sp = strchr(dev_final, '\0'); + if(!isalpha(dev_final[0])) dev_final++; + + for (i = 0; i < p->nChannels; i++) { + sprintf(sp, "%d", i + 1); + if (UNLIKELY(jack_connect(p->client, dev_final, + jack_port_name(p->inPorts[i])) != 0)) { + rtJack_Error(csound, -1, Str("error connecting input ports")); + } } + *sp = (char) 0; } - *sp = (char) 0; + } - if (p->outputEnabled && p->outDevName != NULL) { - char *sp = strchr(p->outDevName, '\0'); - for (i = 0; i < p->nChannels; i++) { - sprintf(sp, "%d", i + 1); - if (jack_connect(p->client, jack_port_name(p->outPorts[i]), - p->outDevName) != 0) { - rtJack_ListPorts(csound, p->client, &(p->clientName[0]), 1); - rtJack_Error(csound, -1, Str("error connecting output ports")); + if (p->outputEnabled) { + char dev[128], *dev_final, *sp; + { + int i,n = listDevices(csound,NULL,1); + CS_AUDIODEVICE *devs = (CS_AUDIODEVICE *) + malloc(n*sizeof(CS_AUDIODEVICE)); + listDevices(csound,devs,1); + for(i=0; i < n; i++) + csound->Message(csound, " %d: %s (%s)\n", + i, devs[i].device_id, devs[i].device_name); + strncpy(dev, devs[0].device_name, 128); + free(devs); + } + if(p->outDevName != NULL) strncpy(dev, p->outDevName, 128); + if (dev) { + dev_final = dev; + sp = strchr(dev_final, '\0'); + if(!isalpha(dev_final[0])) dev_final++; + for (i = 0; i < p->nChannels; i++) { + sprintf(sp, "%d", i + 1); + if (jack_connect(p->client, jack_port_name(p->outPorts[i]), + dev_final) != 0) { + rtJack_Error(csound, -1, Str("error connecting output ports")); + } } + *sp = (char) 0; } - *sp = (char) 0; } - /* stream is now active */ p->jackState = 0; } @@ -547,19 +585,21 @@ nBytes = strlen(parm->devName) + 4; if (UNLIKELY(nBytes > (size_t) jack_port_name_size())) rtJack_Error(csound, -1, Str("device name is too long")); - s = (char*) malloc(nBytes); + s = (char*) malloc(nBytes+1); if (UNLIKELY(s == NULL)) rtJack_Error(csound, CSOUND_MEMORY, Str("memory allocation failure")); strcpy(s, parm->devName); + *devName = s; } if (isOutput && p->inputEnabled) { /* full duplex audio I/O: check consistency of parameters */ - if (UNLIKELY(p->nChannels != parm->nChannels || p->bufSize != parm->bufSamp_SW)) + if (UNLIKELY(p->nChannels != parm->nChannels || + (unsigned int)p->bufSize != parm->bufSamp_SW)) rtJack_Error(csound, -1, Str("input and output parameters are not consistent")); - if (UNLIKELY(((parm->bufSamp_SW / csound->ksmps) * csound->ksmps) - != parm->bufSamp_SW)) + if (UNLIKELY((unsigned int)((parm->bufSamp_SW / csound->GetKsmps(csound)) * + csound->GetKsmps(csound)) != parm->bufSamp_SW)) rtJack_Error(csound, -1, Str("period size (-b) must be an integer multiple of ksmps")); } @@ -580,20 +620,22 @@ p = (RtJackGlobals*) csound->QueryGlobalVariable(csound, "_rtjackGlobals"); if (p == NULL) return -1; - csound->rtRecord_userdata = (void*) p; + *(csound->GetRtRecordUserData(csound)) = (void*) p; rtJack_CopyDevParams(p, &(p->inDevName), parm, 0); p->inputEnabled = 1; /* allocate pointers to input ports */ p->inPorts = (jack_port_t**) - calloc((size_t) p->nChannels, sizeof(jack_port_t*)); + calloc((size_t) p->nChannels, sizeof(jack_port_t*)); if (UNLIKELY(p->inPorts == NULL)) rtJack_Error(p->csound, CSOUND_MEMORY, Str("memory allocation failure")); /* allocate pointers to input port buffers */ p->inPortBufs = (jack_default_audio_sample_t**) - calloc((size_t) p->nChannels, sizeof(jack_default_audio_sample_t*)); + calloc((size_t) p->nChannels, sizeof(jack_default_audio_sample_t*)); if (UNLIKELY(p->inPortBufs == NULL)) rtJack_Error(p->csound, CSOUND_MEMORY, Str("memory allocation failure")); + + return 0; } @@ -606,17 +648,18 @@ p = (RtJackGlobals*) csound->QueryGlobalVariable(csound, "_rtjackGlobals"); if (p == NULL) return -1; - csound->rtPlay_userdata = (void*) p; + *(csound->GetRtPlayUserData(csound)) = (void*) p; rtJack_CopyDevParams(p, &(p->outDevName), parm, 1); + p->outputEnabled = 1; /* allocate pointers to output ports */ p->outPorts = (jack_port_t**) - calloc((size_t) p->nChannels, sizeof(jack_port_t*)); + calloc((size_t) p->nChannels, sizeof(jack_port_t*)); if (UNLIKELY(p->outPorts == NULL)) rtJack_Error(p->csound, CSOUND_MEMORY, Str("memory allocation failure")); /* allocate pointers to output port buffers */ p->outPortBufs = (jack_default_audio_sample_t**) - calloc((size_t) p->nChannels, sizeof(jack_default_audio_sample_t*)); + calloc((size_t) p->nChannels, sizeof(jack_default_audio_sample_t*)); if (UNLIKELY(p->outPortBufs == NULL)) rtJack_Error(p->csound, CSOUND_MEMORY, Str("memory allocation failure")); /* activate client to start playback */ @@ -638,12 +681,12 @@ if (p->inputEnabled) { for (i = 0; i < p->nChannels; i++) p->inPortBufs[i] = (jack_default_audio_sample_t*) - jack_port_get_buffer(p->inPorts[i], nframes); + jack_port_get_buffer(p->inPorts[i], nframes); } if (p->outputEnabled && p->outPortBufs[0] == NULL) { for (i = 0; i < p->nChannels; i++) p->outPortBufs[i] = (jack_default_audio_sample_t*) - jack_port_get_buffer(p->outPorts[i], nframes); + jack_port_get_buffer(p->outPorts[i], nframes); } i = 0; do { @@ -724,7 +767,7 @@ RtJackGlobals *p; int i, j, k, nframes, bufpos, bufcnt; - p = (RtJackGlobals*) csound->rtPlay_userdata; + p = (RtJackGlobals*) *(csound->GetRtPlayUserData(csound)); if (p->jackState != 0) { if (p->jackState < 0) openJackStreams(p); /* open audio input */ @@ -760,7 +803,9 @@ } if (p->xrunFlag) { p->xrunFlag = 0; - if (csound->oparms->msglevel & 4) + OPARMS oparms; + csound->GetOParms(csound, &oparms); + if (oparms.msglevel & 4) csound->Warning(csound, Str("rtjack: xrun in real time audio")); } @@ -774,7 +819,7 @@ RtJackGlobals *p; int i, j, k, nframes; - p = (RtJackGlobals*) csound->rtPlay_userdata; + p = (RtJackGlobals*) *(csound->GetRtPlayUserData(csound)); if (p == NULL) return; if (p->jackState != 0) { @@ -794,7 +839,7 @@ /* copy audio data */ for (k = 0; k < p->nChannels; k++) p->bufs[p->csndBufCnt]->outBufs[k][i] = - (jack_default_audio_sample_t) outbuf_[j++]; + (jack_default_audio_sample_t) outbuf_[j++]; if (++(p->csndBufPos) >= p->bufSize) { p->csndBufPos = 0; /* notify JACK callback that this buffer is now filled */ @@ -843,20 +888,20 @@ pp = (RtJackGlobals*) csound->QueryGlobalVariable(csound, "_rtjackGlobals"); if (pp == NULL) return; - csound->rtRecord_userdata = NULL; - csound->rtPlay_userdata = NULL; + *(csound->GetRtPlayUserData(csound)) = NULL; + *(csound->GetRtRecordUserData(csound)) = NULL; memcpy(&p, pp, sizeof(RtJackGlobals)); /* free globals */ csound->DestroyGlobalVariable(csound, "_rtjackGlobals"); if (p.client != (jack_client_t*) NULL) { /* deactivate client */ - if (p.jackState != 2) { - if (p.jackState == 0) - csound->Sleep((size_t) - ((int) ((double) (p.bufSize * p.nBuffers) - * 1000.0 / (double) p.sampleRate + 0.999))); - jack_deactivate(p.client); - } + //if (p.jackState != 2) { + //if (p.jackState == 0) + // csound->Sleep((size_t) + // ((int) ((double) (p.bufSize * p.nBuffers) + // * 1000.0 / (double) p.sampleRate + 0.999))); + jack_deactivate(p.client); + //} csound->Sleep((size_t) 50); /* unregister and free all ports */ if (p.inPorts != NULL) { @@ -872,8 +917,9 @@ } } /* close connection */ - if (p.jackState != 2) + if (p.jackState != 2) { jack_client_close(p.client); + } } /* free copy of input and output device name */ if (p.inDevName != NULL) @@ -903,15 +949,70 @@ csound->LongJmp(csound, errCode); } +int listDevices(CSOUND *csound, CS_AUDIODEVICE *list, int isOutput){ + + char **portNames = (char**) NULL, port[64]; + unsigned long portFlags; + int i, n, cnt=0; + jack_client_t *jackClient; + RtJackGlobals* p = + (RtJackGlobals*) csound->QueryGlobalVariableNoCheck(csound, + "_rtjackGlobals"); + + if(p->listclient == NULL) + p->listclient = jack_client_open("list", JackNoStartServer, NULL); + + jackClient = p->listclient; + + if(jackClient == NULL) return 0; + portFlags = (isOutput ? (unsigned long) JackPortIsInput + : (unsigned long) JackPortIsOutput); + + portNames = (char**) jack_get_ports(jackClient, + (char*) NULL, + JACK_DEFAULT_AUDIO_TYPE, + portFlags); + if(portNames == NULL) { + jack_client_close(jackClient); + p->listclient = NULL; + return 0; + } + + memset(port, '\0', 64); + for(i=0; portNames[i] != NULL; i++) { + n = (int) strlen(portNames[i]); + do { + n--; + } while (n > 0 && isdigit(portNames[i][n])); + n++; + if(strncmp(portNames[i], port, n)==0) continue; + strncpy(port, portNames[i], n); + port[n] = '\0'; + if (list != NULL) { + strncpy(list[cnt].device_name, port, 63); + snprintf(list[cnt].device_id, 63, "%s%s", + isOutput ? "dac:" : "adc:",port); + list[cnt].max_nchnls = -1; + list[cnt].isOutput = isOutput; + } + cnt++; + } + jack_client_close(jackClient); + p->listclient = NULL; + return cnt; +} + /* module interface functions */ PUBLIC int csoundModuleCreate(CSOUND *csound) { RtJackGlobals *p; int i, j; + OPARMS oparms; + csound->GetOParms(csound, &oparms); /* allocate and initialise globals */ - if (csound->oparms->msglevel & 0x400) + if (oparms.msglevel & 0x400) csound->Message(csound, Str("JACK real-time audio module for Csound " "by Istvan Varga\n")); if (csound->CreateGlobalVariable(csound, "_rtjackGlobals", @@ -923,7 +1024,7 @@ "_rtjackGlobals"); p->csound = csound; p->jackState = -1; - strcpy(&(p->clientName[0]), "csound5"); + strcpy(&(p->clientName[0]), "csound6"); strcpy(&(p->inputPortName[0]), "input"); strcpy(&(p->outputPortName[0]), "output"); p->sleepTime = 1000; /* this is not actually used */ @@ -940,40 +1041,61 @@ i = jack_client_name_size(); if (i > (MAX_NAME_LEN + 1)) i = (MAX_NAME_LEN + 1); - csound->CreateConfigurationVariable( - csound, "jack_client", (void*) &(p->clientName[0]), - CSOUNDCFG_STRING, 0, NULL, &i, - "JACK client name (default: csound5)", NULL); + csound->CreateConfigurationVariable(csound, "jack_client", + (void*) &(p->clientName[0]), + CSOUNDCFG_STRING, 0, NULL, &i, + Str("JACK client name (default: csound6)"), + NULL); /* input port name */ i = jack_port_name_size() - 3; if (i > (MAX_NAME_LEN + 1)) i = (MAX_NAME_LEN + 1); - csound->CreateConfigurationVariable( - csound, "jack_inportname", (void*) &(p->inputPortName[0]), - CSOUNDCFG_STRING, 0, NULL, &i, - "JACK input port name prefix (default: input)", NULL); + csound->CreateConfigurationVariable(csound, "jack_inportname", + (void*) &(p->inputPortName[0]), + CSOUNDCFG_STRING, 0, NULL, &i, + Str("JACK input port name prefix " + "(default: input)"), NULL); /* output port name */ i = jack_port_name_size() - 3; if (i > (MAX_NAME_LEN + 1)) i = (MAX_NAME_LEN + 1); - csound->CreateConfigurationVariable( - csound, "jack_outportname", (void*) &(p->outputPortName[0]), - CSOUNDCFG_STRING, 0, NULL, &i, - "JACK output port name prefix (default: output)", NULL); - /* sleep time */ + csound->CreateConfigurationVariable(csound, "jack_outportname", + (void*) &(p->outputPortName[0]), + CSOUNDCFG_STRING, 0, NULL, &i, + Str("JACK output port name prefix" + " (default: output)"), NULL); + /* sleep time */ i = 250; j = 25000; /* min/max value */ - csound->CreateConfigurationVariable( - csound, "jack_sleep_time", (void*) &(p->sleepTime), - CSOUNDCFG_INTEGER, 0, &i, &j, - "Deprecated", NULL); + csound->CreateConfigurationVariable(csound, "jack_sleep_time", + (void*) &(p->sleepTime), + CSOUNDCFG_INTEGER, 0, &i, &j, + Str("Deprecated"), NULL); /* done */ + p->listclient = NULL; + return 0; } + + +PUBLIC int csoundModuleDestroy(CSOUND *csound) +{ + RtJackGlobals* p = + (RtJackGlobals*) csound->QueryGlobalVariableNoCheck(csound, + "_rtjackGlobals"); + if(p && p->listclient) { + jack_client_close(p->listclient); + p->listclient = NULL; + } + return OK; +} + + + PUBLIC int csoundModuleInit(CSOUND *csound) { char *drv; - + csound->module_list_add(csound,"jack", "audio"); drv = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO"); if (drv == NULL) return 0; @@ -981,13 +1103,15 @@ strcmp(drv, "JACK") == 0)) return 0; csound->Message(csound, Str("rtaudio: JACK module enabled\n")); - /* register Csound interface functions */ - csound->SetPlayopenCallback(csound, playopen_); - csound->SetRecopenCallback(csound, recopen_); - csound->SetRtplayCallback(csound, rtplay_); - csound->SetRtrecordCallback(csound, rtrecord_); - csound->SetRtcloseCallback(csound, rtclose_); - + { + /* register Csound interface functions */ + csound->SetPlayopenCallback(csound, playopen_); + csound->SetRecopenCallback(csound, recopen_); + csound->SetRtplayCallback(csound, rtplay_); + csound->SetRtrecordCallback(csound, rtrecord_); + csound->SetRtcloseCallback(csound, rtclose_); + csound->SetAudioDeviceListCallback(csound, listDevices); + } return 0; } @@ -995,4 +1119,3 @@ { return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - diff -Nru csound-5.17.11~dfsg/InOut/rtpa.c csound-6.02~dfsg/InOut/rtpa.c --- csound-5.17.11~dfsg/InOut/rtpa.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtpa.c 2014-01-07 16:53:47.000000000 +0000 @@ -100,40 +100,66 @@ } /* list available input or output devices; returns the number of devices */ - -static int listPortAudioDevices_blocking(CSOUND *csound, - int print_list, int play) -{ - PaDeviceInfo *dev_info; +int listDevices(CSOUND *csound, CS_AUDIODEVICE *list, int isOutput){ + PaDeviceInfo *dev_info; int i, j, ndev; + char tmp[256], *s; + + if (initPortAudio(csound) != 0) + return 0; + + if ((s = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO")) == NULL) + return 0; ndev = (int) Pa_GetDeviceCount(); for (i = j = 0; i < ndev; i++) { dev_info = (PaDeviceInfo*) Pa_GetDeviceInfo((PaDeviceIndex) i); - if ((play && dev_info->maxOutputChannels > 0) || - (!play && dev_info->maxInputChannels > 0)) + if ((isOutput && dev_info->maxOutputChannels > 0) || + (!isOutput && dev_info->maxInputChannels > 0)) j++; } - if (!j) { - pa_PrintErrMsg(csound, Str("No %s devices are available\n"), - (play ? Str("output") : Str("input"))); - return 0; - } - if (!print_list) - return j; - csound->Message(csound, Str("PortAudio: available %s devices:\n"), - (play ? Str("output") : Str("input"))); + if (!j) return 0; + if(list!=NULL) { for (i = j = 0; i < ndev; i++) { dev_info = (PaDeviceInfo*) Pa_GetDeviceInfo((PaDeviceIndex) i); - if ((play && dev_info->maxOutputChannels > 0) || - (!play && dev_info->maxInputChannels > 0)) { - csound->Message(csound, " %3d: %s\n", j, dev_info->name); + if ((isOutput && dev_info->maxOutputChannels > 0) || + (!isOutput && dev_info->maxInputChannels > 0)) { + strncpy(list[j].device_name, dev_info->name, 63); + if (isOutput) { + sprintf(tmp, "dac%d", j); + } else { + sprintf(tmp, "adc%d", j); + } + strncpy(list[j].device_id, tmp, 63); + strncpy(list[j].rt_module, s, 63); + list[j].max_nchnls = + isOutput ? dev_info->maxOutputChannels : dev_info->maxInputChannels; + list[j].isOutput = isOutput; j++; } } + } return j; } + +static int listPortAudioDevices_blocking(CSOUND *csound, + int print_list, int play) +{ + int i,n = listDevices(csound, NULL, play); + CS_AUDIODEVICE *devs = + (CS_AUDIODEVICE *) csound->Malloc(csound, n*sizeof(CS_AUDIODEVICE)); + listDevices(csound, devs, play); + for(i=0; i < n; i++) + csound->Message(csound, " %3d: %s (%s)\n", + i, devs[i].device_id, devs[i].device_name); + csound->Free(csound, devs); + return n; +} + + + + /* select PortAudio device; returns the actual device number */ static int selectPortAudioDevice(CSOUND *csound, int devNum, int play) @@ -193,7 +219,6 @@ if (dev < 0) return -1; sp->device = (PaDeviceIndex) dev; - if(!is_playback && (csound->nchnls != csound->inchnls)) parm->nChannels = csound->inchnls; sp->channelCount = (parm->nChannels < 2 ? 2 : parm->nChannels); sp->sampleFormat = (PaSampleFormat) paFloat32; sp->suggestedLatency = (PaTime) ((double) parm->bufSamp_HW @@ -219,7 +244,7 @@ "_rtpaGlobals"); if (pabs == NULL) return -1; - if (initPortAudio(csound) != 0) + if (initPortAudio(csound) != 0) goto err_return; if ((int) Pa_GetDeviceCount() <= 0) { @@ -262,8 +287,8 @@ pa_PrintErrMsg(csound, Str("Inconsistent full-duplex sample rates")); goto err_return; } - if (((pabs->inParm.bufSamp_SW / csound->ksmps) * csound->ksmps) - != pabs->inParm.bufSamp_SW) + if (UNLIKELY(((pabs->inParm.bufSamp_SW / csound->GetKsmps(csound)) * + csound->GetKsmps(csound)) != pabs->inParm.bufSamp_SW)) csound->MessageS(csound, CSOUNDMSG_WARNING, Str("WARNING: buffer size should be an integer " @@ -306,7 +331,7 @@ (unsigned long) (pabs->mode & 2 ? pabs->outParm.bufSamp_SW : pabs->inParm.bufSamp_SW), - (csound->dither_output ? + (csound->GetDitherMode(csound) ? (PaStreamFlags) paNoFlag : (PaStreamFlags) paDitherOff), paBlockingReadWriteStreamCallback, (void*) pabs); @@ -535,6 +560,8 @@ PA_BLOCKING_STREAM *pabs; pabs = (PA_BLOCKING_STREAM*) csound->QueryGlobalVariable(csound, "_rtpaGlobals"); + + csound->Message(csound, Str("closing device\n")); if (pabs == NULL) return; @@ -542,20 +569,20 @@ if (pabs->paStream != NULL) { PaStream *stream = pabs->paStream; - int i; - pabs->paStream = NULL; - for (i = 0; i < 4; i++) { + unsigned int i; + + for (i = 0; i < 4u; i++) { #if NO_FULLDUPLEX_PA_LOCK if (!pabs->noPaLock) #endif csound->NotifyThreadLock(pabs->paLock); csound->NotifyThreadLock(pabs->clientLock); -// Pa_Sleep(80); + //Pa_Sleep(80); } Pa_StopStream(stream); Pa_CloseStream(stream); -// Pa_Sleep(80); + //Pa_Sleep(80); } if (pabs->clientLock != NULL) { @@ -577,7 +604,7 @@ free(pabs->inputBuffer); pabs->inputBuffer = NULL; } - + pabs->paStream = NULL; *(csound->GetRtRecordUserData(csound)) = NULL; *(csound->GetRtPlayUserData(csound)) = NULL; csound->DestroyGlobalVariable(csound, "_rtpaGlobals"); @@ -628,7 +655,7 @@ err = (int) Pa_OpenStream(&(dev->handle), NULL, &streamParams, (double) parm->sampleRate, (unsigned long) parm->bufSamp_SW, - (csound->dither_output? + (csound->GetDitherMode(csound) ? paNoFlag:paDitherOff), NULL, NULL); } @@ -747,7 +774,7 @@ static void rtclose_blocking(CSOUND *csound) { DEVPARAMS *dev; - + csound->Message(csound, Str("closing device\n")); dev = (DEVPARAMS*) (*(csound->GetRtRecordUserData(csound))); if (dev != NULL) { *(csound->GetRtRecordUserData(csound)) = NULL; @@ -777,8 +804,8 @@ PUBLIC int csoundModuleCreate(CSOUND *csound) { /* nothing to do, report success */ - csound->Message(csound, - Str("PortAudio real-time audio module for Csound\n")); + //csound->Message(csound, + // Str("PortAudio real-time audio module for Csound\n")); return 0; } @@ -786,7 +813,8 @@ { char *s, drv[12]; int i; - + csound->module_list_add(csound, "pa_bl", "audio"); + csound->module_list_add(csound, "pa_cb", "audio"); if ((s = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO")) == NULL) return 0; for (i = 0; s[i] != '\0' && i < 11; i++) @@ -795,7 +823,7 @@ if (!(strcmp(drv, "PORTAUDIO") == 0 || strcmp(drv, "PA") == 0 || strcmp(drv, "PA_BL") == 0 || strcmp(drv, "PA_CB") == 0)) return 0; - csound->Message(csound, Str("rtaudio: PortAudio module enabled ... ")); + csound->Message(csound, Str("rtaudio: PortAudio module enabled ... \n")); /* set function pointers */ #ifdef LINUX if (strcmp(drv, "PA_CB") != 0) @@ -809,6 +837,7 @@ csound->SetRtplayCallback(csound, rtplay_blocking); csound->SetRtrecordCallback(csound, rtrecord_blocking); csound->SetRtcloseCallback(csound, rtclose_blocking); + csound->SetAudioDeviceListCallback(csound, listDevices); } else { csound->Message(csound, Str("using callback interface\n")); @@ -817,7 +846,10 @@ csound->SetRtplayCallback(csound, rtplay_); csound->SetRtrecordCallback(csound, rtrecord_); csound->SetRtcloseCallback(csound, rtclose_); + csound->SetAudioDeviceListCallback(csound, listDevices); } + + csound->module_list_add(csound, s, "audio"); return 0; } diff -Nru csound-5.17.11~dfsg/InOut/rtpulse.c csound-6.02~dfsg/InOut/rtpulse.c --- csound-5.17.11~dfsg/InOut/rtpulse.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtpulse.c 2014-01-07 16:53:47.000000000 +0000 @@ -42,8 +42,10 @@ { pulse_globals *p; int siz = 64; + OPARMS oparms; + csound->GetOParms(csound, &oparms); - if (csound->oparms->msglevel & 0x400) + if (oparms.msglevel & 0x400) csound->Message(csound, Str("PulseAudio client RT IO module for Csound" "by Victor Lazzarini\n")); @@ -96,8 +98,8 @@ int pulserror; pulse = (pulse_params *) malloc(sizeof(pulse_params)); - pulse->buf = (float *) malloc(sizeof(float)* parm->bufSamp_HW); - csound->rtPlay_userdata = (void *) pulse; + pulse->buf = (float *) malloc(sizeof(float)* parm->bufSamp_SW); + *(csound->GetRtPlayUserData(csound)) = (void *) pulse; pulse->spec.rate = csound->GetSr(csound); pulse->spec.channels = csound->GetNchnls(csound); pulse->spec.format = PA_SAMPLE_FLOAT32; @@ -149,8 +151,8 @@ int i, bufsiz, pulserror; float *buf; - pulse_params *pulse = (pulse_params*) csound->rtPlay_userdata; - MYFLT norm = csound->e0dbfs; + pulse_params *pulse = (pulse_params*) *(csound->GetRtPlayUserData(csound)); + //MYFLT norm = csound->e0dbfs; bufsiz = nbytes/sizeof(MYFLT); buf = pulse->buf; for (i=0;irtPlay_userdata; + pulse_params *pulse = (pulse_params*) *(csound->GetRtPlayUserData(csound)); if (pulse != NULL){ pa_simple_drain(pulse->ps, &error); @@ -173,7 +175,7 @@ free(pulse->buf); } - pulse = (pulse_params*) csound->rtRecord_userdata; + pulse = (pulse_params*) *(csound->GetRtRecordUserData(csound)) ; if (pulse != NULL){ pa_simple_free(pulse->ps); @@ -191,8 +193,8 @@ int pulserror; pulse = (pulse_params *) malloc(sizeof(pulse_params)); - pulse->buf = (float *) malloc(sizeof(float)* parm->bufSamp_HW); - csound->rtRecord_userdata = (void *) pulse; + pulse->buf = (float *) malloc(sizeof(float)* parm->bufSamp_SW); + *(csound->GetRtRecordUserData(csound)) = (void *) pulse; pulse->spec.rate = csound->GetSr(csound); pulse->spec.channels = csound->GetNchnls(csound); pulse->spec.format = PA_SAMPLE_FLOAT32; @@ -240,8 +242,8 @@ { int i, bufsiz,pulserror; float *buf; - pulse_params *pulse = (pulse_params*) csound->rtRecord_userdata; - MYFLT norm = csound->e0dbfs; + pulse_params *pulse = (pulse_params*) *(csound->GetRtRecordUserData(csound)) ; + //MYFLT norm = csound->e0dbfs; bufsiz = nbytes/sizeof(MYFLT); buf = pulse->buf; @@ -262,7 +264,7 @@ char *s; int i; char buf[9]; - + csound->module_list_add(csound, "pulse", "audio"); s = (char*) csound->QueryGlobalVariable(csound, "_RTAUDIO"); i = 0; if (s != NULL) { diff -Nru csound-5.17.11~dfsg/InOut/rtwinmm.c csound-6.02~dfsg/InOut/rtwinmm.c --- csound-5.17.11~dfsg/InOut/rtwinmm.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/rtwinmm.c 2014-01-07 16:53:47.000000000 +0000 @@ -192,7 +192,8 @@ } } -static void MYFLT_to_short_no_dither(int nSmps, MYFLT *inBuf, int16_t *outBuf, int *seed) +static void MYFLT_to_short_no_dither(int nSmps, MYFLT *inBuf, + int16_t *outBuf, int *seed) { MYFLT tmp_f; int tmp_i; @@ -318,7 +319,7 @@ 0 : (parm->sampleFormat == AE_LONG ? 1 : 2)); if (is_playback) { p->outDev = dev; - csound->rtPlay_userdata = (void*) dev; + *(csound->GetRtPlayUserData(csound)) = (void*) dev; dev->enable_buf_timer = p->enable_buf_timer; if (UNLIKELY(waveOutOpen((LPHWAVEOUT) &(dev->outDev), (unsigned int) devNum, (LPWAVEFORMATEX) &wfx, 0, 0, @@ -328,10 +329,10 @@ } switch (conv_idx) { case 0: - if (csound->dither_output==1) + if (csound->GetDitherMode(csound)==1) dev->playconv = (void (*)(int, MYFLT*, void*, int*)) MYFLT_to_short; - else if (csound->dither_output==2) + else if (csound->GetDitherMode(csound)==2) dev->playconv = (void (*)(int, MYFLT*, void*, int*)) MYFLT_to_short_u; else @@ -346,7 +347,7 @@ } else { p->inDev = dev; - csound->rtRecord_userdata = (void*) dev; + *(csound->GetRtRecordUserData(csound)) = (void*) dev; /* disable playback timer in full-duplex mode */ dev->enable_buf_timer = p->enable_buf_timer = 0; if (UNLIKELY(waveInOpen((LPHWAVEIN) &(dev->inDev), (unsigned int) devNum, @@ -394,7 +395,7 @@ static int rtrecord_(CSOUND *csound, MYFLT *inBuf, int nbytes) { - rtWinMMDevice *dev = (rtWinMMDevice*) csound->rtRecord_userdata; + rtWinMMDevice *dev = (rtWinMMDevice*) *(csound->GetRtRecordUserData(csound)) ; WAVEHDR *buf = &(dev->buffers[dev->cur_buf]); volatile DWORD *dwFlags = &(buf->dwFlags); @@ -423,7 +424,7 @@ static void rtplay_(CSOUND *csound, const MYFLT *outBuf, int nbytes) { - rtWinMMDevice *dev = (rtWinMMDevice*) csound->rtPlay_userdata; + rtWinMMDevice *dev = (rtWinMMDevice*) *(csound->GetRtPlayUserData(csound)); WAVEHDR *buf = &(dev->buffers[dev->cur_buf]); volatile DWORD *dwFlags = &(buf->dwFlags); LARGE_INTEGER pp; @@ -466,8 +467,8 @@ rtWinMMDevice *inDev, *outDev; int i; - csound->rtPlay_userdata = NULL; - csound->rtRecord_userdata = NULL; + *(csound->GetRtPlayUserData(csound)) = NULL; + *(csound->GetRtRecordUserData(csound)) = NULL; pp = (rtWinMMGlobals*) csound->QueryGlobalVariable(csound, "_rtwinmm_globals"); if (pp == NULL) @@ -720,8 +721,10 @@ PUBLIC int csoundModuleCreate(CSOUND *csound) { rtWinMMGlobals *pp; + OPARMS oparms; + csound->GetOParms(csound, &oparms); - if (UNLIKELY(csound->oparms->msglevel & 0x400)) + if (UNLIKELY(oparms.msglevel & 0x400)) csound->Message(csound, Str("Windows MME real time audio and MIDI module " "for Csound by Istvan Varga\n")); @@ -767,7 +770,7 @@ csound->SetRtcloseCallback(csound, rtclose_); } if (check_name((char*) csound->QueryGlobalVariable(csound, "_RTMIDI"))) { - csound->Message(csound, "rtmidi: WinMM module enabled\n"); + csound->Message(csound, Str("rtmidi: WinMM module enabled\n")); csound->SetExternalMidiInOpenCallback(csound, midi_in_open); csound->SetExternalMidiReadCallback(csound, midi_in_read); csound->SetExternalMidiInCloseCallback(csound, midi_in_close); @@ -782,4 +785,3 @@ { return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/Bank.cpp csound-6.02~dfsg/InOut/virtual_keyboard/Bank.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/Bank.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/Bank.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -169,7 +169,7 @@ (char *)"Gunshot" }; -Bank::Bank(CSOUND *csound, char* bankName) { +Bank::Bank(CSOUND *csound, char* bankName) : bankNum(0) { this->name = bankName; currentProgram = 0; diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboard.cpp csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboard.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboard.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboard.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -27,7 +27,8 @@ #include #include "FLTKKeyboard.hpp" -FLTKKeyboard::FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, int X, int Y, int W, int H, const char *L) +FLTKKeyboard::FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, + int X, int Y, int W, int H, const char *L) : Fl_Widget(X, Y, W, H, L) { this->csound = csound; @@ -531,11 +532,14 @@ runningX += whiteKeyWidth; } else { if(keyStates[i] == 1) { - fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, blackKeyWidth, blackKeyHeight, FL_BLUE); + fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, + blackKeyWidth, blackKeyHeight, FL_BLUE); } else { - fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, blackKeyWidth, blackKeyHeight, FL_BLACK); + fl_draw_box(box(), (int)(runningX - blackKeyOffset), yval, + blackKeyWidth, blackKeyHeight, FL_BLACK); } - fl_rect((int)(runningX - blackKeyOffset), yval, blackKeyWidth, blackKeyHeight, FL_BLACK); + fl_rect((int)(runningX - blackKeyOffset), yval, + blackKeyWidth, blackKeyHeight, FL_BLACK); } } } diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboard.hpp csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboard.hpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboard.hpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboard.hpp 2014-01-07 16:53:47.000000000 +0000 @@ -31,7 +31,8 @@ class FLTKKeyboard : public Fl_Widget { public: - FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, int X, int Y, int W, int H, const char *L); + FLTKKeyboard(CSOUND *csound, SliderBank *sliderBank, + int X, int Y, int W, int H, const char *L); ~FLTKKeyboard(); int handle(int event); void draw(); diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboardWidget.cpp csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboardWidget.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboardWidget.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboardWidget.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -150,7 +150,8 @@ this->allNotesOffButton = new Fl_Button(baseX, row2, w, 20, "All Notes Off"); this->allNotesOffButton->callback((Fl_Callback*) allNotesOff, this); - this->keyboard = new FLTKKeyboard(csound, NULL, baseX, row3, w, h - 40, "Keyboard"); + this->keyboard = new FLTKKeyboard(csound, NULL, baseX, row3, w, h - 40, + "Keyboard"); this->end(); diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboardWindow.cpp csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboardWindow.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/FLTKKeyboardWindow.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/FLTKKeyboardWindow.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -139,7 +139,8 @@ this->allNotesOffButton = new Fl_Button(0, row3, W, 20, "All Notes Off"); this->allNotesOffButton->callback((Fl_Callback*) allNotesOff, this); - this->keyboard = new FLTKKeyboard(csound, this->sliderBank, 0, row4, W, 80, "Keyboard"); + this->keyboard = new FLTKKeyboard(csound, this->sliderBank, 0, row4, W, 80, + "Keyboard"); this->end(); diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/KeyboardMapping.cpp csound-6.02~dfsg/InOut/virtual_keyboard/KeyboardMapping.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/KeyboardMapping.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/KeyboardMapping.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -23,6 +23,7 @@ #include "KeyboardMapping.hpp" #include +#include #define LINELENGTH (300) @@ -89,84 +90,84 @@ } void KeyboardMapping::initializeMap(CSOUND * csound, FILE *file) { - char buff[LINELENGTH]; - char *p; + char buff[LINELENGTH]; + char *p; - /* 0 = general search - * 1 = bank found but error in bank def, ignore all until next bank - */ - int state = 0; - - Bank *bank = NULL; - - while (my_fgets(buff, LINELENGTH, file)!=NULL) { - p = buff; - while (*p == ' ' || *p == '\t') p++; - - if(*p == '#') { // line comment - continue; - } if(*p == '[') { - p++; - - // cleanup current bank - if(bank != NULL) { - if(bank->programs.size() == 0) { - bank->initializeGM(); - } - } - - char *q = strstr(p, "="); - char *z = strstr(p, "]"); - - if(q == NULL || z == NULL) { - state = 1; - continue; - } - - *q = '\0'; - *z = '\0'; - - int bankNum = atoi(p) - 1; - - char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); - memcpy(name, q + 1, strlen(q + 1) + 1); - - if(bankNum >= 0 && bankNum < 16384) { - bank = new Bank(csound, name); - bank->bankNum = bankNum; - banks.push_back(bank); - - //bank->initializeGM(); - state = 0; - } else { - state = 1; - } - - } else { - if(state == 1 || bank == NULL) { - continue; - } - - char *q = strstr(p, "="); - - if(q == NULL) { - continue; - } - - *q = '\0'; - - int programNum = atoi(p) - 1; - - char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); - memcpy(name, q + 1, strlen(q + 1) + 1); - - if(programNum >= 0 && programNum < 128) { - Program program(programNum, name); - bank->programs.push_back(program); - } - } + /* 0 = general search + * 1 = bank found but error in bank def, ignore all until next bank + */ + int state = 0; + + Bank *bank = NULL; + + while (my_fgets(buff, LINELENGTH, file)!=NULL) { + p = buff; + while (*p == ' ' || *p == '\t') p++; + + if(*p == '#') { // line comment + continue; + } if(*p == '[') { + p++; + + // cleanup current bank + if(bank != NULL) { + if(bank->programs.size() == 0) { + bank->initializeGM(); + } } + char *q = strstr(p, "="); + char *z = strstr(p, "]"); + + if(q == NULL || z == NULL) { + state = 1; + continue; + } + + *q = '\0'; + *z = '\0'; + + int bankNum = atoi(p) - 1; + + char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); + memcpy(name, q + 1, strlen(q + 1) + 1); + + if(bankNum >= 0 && bankNum < 16384) { + bank = new Bank(csound, name); + bank->bankNum = bankNum; + banks.push_back(bank); + + //bank->initializeGM(); + state = 0; + } else { + state = 1; + } + + } else { + if(state == 1 || bank == NULL) { + continue; + } + + char *q = strstr(p, "="); + + if(q == NULL) { + continue; + } + + *q = '\0'; + + int programNum = atoi(p) - 1; + + char *name = (char *)csound->Calloc(csound, strlen(q +1) + 1); + memcpy(name, q + 1, strlen(q + 1) + 1); + + if(programNum >= 0 && programNum < 128) { + Program program(programNum, name); + bank->programs.push_back(program); + } + } + } + } void KeyboardMapping::initializeDefaults(CSOUND *csound) { diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/KeyboardMapping.hpp csound-6.02~dfsg/InOut/virtual_keyboard/KeyboardMapping.hpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/KeyboardMapping.hpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/KeyboardMapping.hpp 2014-01-07 16:53:47.000000000 +0000 @@ -27,6 +27,7 @@ #include "csdl.h" #include "Bank.hpp" #include +#include #include using namespace std; diff -Nru csound-5.17.11~dfsg/InOut/virtual_keyboard/virtual_keyboard.cpp csound-6.02~dfsg/InOut/virtual_keyboard/virtual_keyboard.cpp --- csound-5.17.11~dfsg/InOut/virtual_keyboard/virtual_keyboard.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/virtual_keyboard/virtual_keyboard.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -24,7 +24,6 @@ #include "csdl.h" #include "csGblMtx.h" #include "midiops.h" -#include "oload.h" #include "winFLTK.h" #include "FLTKKeyboardWindow.hpp" #include "FLTKKeyboardWidget.hpp" @@ -63,7 +62,8 @@ typedef struct { OPDS h; - MYFLT *mapFileName, *iwidth, *iheight, *ix, *iy; + STRINGDAT *mapFileName; + MYFLT *iwidth, *iheight, *ix, *iy; } FLVKEYBD; @@ -394,7 +394,7 @@ char *mapFileName = new char[MAXNAME]; - csound->strarg2name(csound, mapFileName, p->mapFileName, "", p->XSTRCODE); + strncpy(mapFileName, p->mapFileName->data, MAXNAME-1); FLTKKeyboardWidget *widget = createWidget(csound, mapFileName, (int)*p->iwidth, (int)*p->iheight, (int)*p->ix, (int)*p->iy); @@ -407,9 +407,9 @@ #define S(x) sizeof(x) const OENTRY widgetOpcodes_[] = { - { (char*)"FLvkeybd", S(FLVKEYBD), 1, (char*)"", (char*)"Tiiii", + { (char*)"FLvkeybd", S(FLVKEYBD), 0, 1, (char*)"", (char*)"Siiii", (SUBR) fl_vkeybd, (SUBR) NULL, (SUBR) NULL }, - { NULL, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL,(SUBR) NULL } + { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL,(SUBR) NULL } }; @@ -437,8 +437,8 @@ for ( ; ep->opname != NULL; ep++) { if (csound->AppendOpcode(csound, ep->opname, - (int)ep->dsblksiz, (int)ep->thread, - ep->outypes, ep->intypes, + (int)ep->dsblksiz, (int)ep->flags, + (int)ep->thread, ep->outypes, ep->intypes, ep->iopadr, ep->kopadr, ep->aopadr) != 0) { csound->ErrorMsg(csound, Str("Error registering opcode '%s'"), ep->opname); diff -Nru csound-5.17.11~dfsg/InOut/widgets.cpp csound-6.02~dfsg/InOut/widgets.cpp --- csound-5.17.11~dfsg/InOut/widgets.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/widgets.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -24,9 +24,47 @@ #if defined(WIN32) #include #endif +#include #include "widglobals.h" #include +#if !defined(cs_strtok_r) +static char* cs_strtok_r(char* str, char* delim, char** nextp) { +#ifdef HAVE_STRTOK_R + return strtok_r(str, delim, nextp); +#else + /* + * public domain strtok_r() by Charlie Gordon + * + * from comp.lang.c 9/14/2007 + * + * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684 + * + * (Declaration that it's public domain): + * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c + */ + char *ret; + if (str == NULL) + { + str = *nextp; + } + str += strspn(str, delim); + if (*str == '\0') + { + return NULL; + } + ret = str; + str += strcspn(str, delim); + if (*str) + { + *str++ = '\0'; + } + *nextp = str; + return ret; +#endif +} + +#endif Fl_Font FONT_TABLE[] = { FL_HELVETICA, FL_HELVETICA, FL_HELVETICA_BOLD, FL_HELVETICA_ITALIC, @@ -57,8 +95,15 @@ void widget_init(CSOUND *csound) { - if (csound->widgetGlobals == NULL) { - csound->widgetGlobals = new WIDGET_GLOBALS; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *) csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + if (widgetGlobals == NULL) { + csound->CreateGlobalVariable(csound, "WIDGET_GLOBALS", + sizeof(WIDGET_GLOBALS)); + widgetGlobals = + (WIDGET_GLOBALS *) csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + + //csound->widgetGlobals = new WIDGET_GLOBALS; //csound->Calloc(csound, sizeof(WIDGET_GLOBALS)); // ST(indrag) = 0; // ST(sldrag) = 0; @@ -92,10 +137,10 @@ int widget_reset(CSOUND *csound, void *pp) { IGN(pp); - if (csound->widgetGlobals != NULL) { - //csound->Free(csound, csound->widgetGlobals); - delete (WIDGET_GLOBALS*)csound->widgetGlobals; - csound->widgetGlobals = NULL; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + if (widgetGlobals != NULL) { + csound->DestroyGlobalVariable(csound, "WIDGET_GLOBALS"); } graphs_reset(csound); return OK; @@ -114,7 +159,7 @@ p->eventQueue = ep->nxt; csound->UnlockMutex(p->mutex_); csound->insert_score_event_at_sample(csound, &(ep->evt), - csound->icurTime); + csound->GetCurrentTimeSamples(csound)); free(ep); csound->LockMutex(p->mutex_); } @@ -125,7 +170,8 @@ EVTBLK e; memset(&e, 0, sizeof(EVTBLK)); e.opcod = 'e'; - csound->insert_score_event_at_sample(csound, &e, csound->icurTime); + csound->insert_score_event_at_sample(csound, &e, + csound->GetCurrentTimeSamples(csound)); } } } // extern "C" @@ -158,16 +204,16 @@ /* Create the new event */ evt = (rtEvt_t*) malloc(sizeof(rtEvt_t)); evt->nxt = NULL; - evt->evt.strarg = NULL; + evt->evt.strarg = NULL; evt->evt.scnt = 0; evt->evt.opcod = (char) *args[0]; if (evt->evt.opcod == '\0') evt->evt.opcod = 'i'; evt->evt.pcnt = numargs - 1; - evt->evt.p[1] = evt->evt.p[2] = evt->evt.p[3] = FL(0.0); + evt->evt.p[1] = evt->evt.p[2] = evt->evt.p[3] = MYFLT(0.0); for (i = 1; i < numargs; i++) evt->evt.p[i] = *args[i]; - if (evt->evt.p[2] < FL(0.0)) - evt->evt.p[2] = FL(0.0); + if (evt->evt.p[2] < MYFLT(0.0)) + evt->evt.p[2] = MYFLT(0.0); /* queue event for insertion by main Csound thread */ csound->LockMutex(p->mutex_); if (p->eventQueue == NULL) @@ -187,17 +233,18 @@ int i; /* Create the new event */ - e.strarg = NULL; + e.strarg = NULL; e.scnt = 0; e.opcod = (char) *args[0]; if (e.opcod == '\0') e.opcod = 'i'; e.pcnt = numargs - 1; - e.p[1] = e.p[2] = e.p[3] = FL(0.0); + e.p[1] = e.p[2] = e.p[3] = MYFLT(0.0); for (i = 1; i < numargs; i++) e.p[i] = *args[i]; - if (e.p[2] < FL(0.0)) - e.p[2] = FL(0.0); - csound->insert_score_event_at_sample(csound, &e, csound->icurTime); + if (e.p[2] < MYFLT(0.0)) + e.p[2] = MYFLT(0.0); + csound->insert_score_event_at_sample(csound, &e, + csound->GetCurrentTimeSamples(csound)); } } } @@ -470,6 +517,8 @@ int sxx = x(), syy = y(), sww = w(), shh = h(); Fl_Boxtype box1 = (Fl_Boxtype)(box()); int border_size=Fl::box_dx(box()); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (damage()&~FL_DAMAGE_CHILD) clear_damage(FL_DAMAGE_ALL); @@ -540,6 +589,8 @@ int mx = Fl::event_x(); int my = Fl::event_y(); int sxx = x(), syy = y(), sww = w(), shh = h(); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); switch (event) { case FL_PUSH: @@ -613,7 +664,10 @@ Fl_Spin::Fl_Spin(CSOUND *cs, int x, int y, int w, int h, const char* l) : Fl_Valuator(x,y,w,h,l) { + csound = cs; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); soft_ = 0; align(FL_ALIGN_LEFT); ix=x; @@ -632,10 +686,11 @@ Fl_Value_Input_Spin& t = *(Fl_Value_Input_Spin*)v; CSOUND *csound = t.csound; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); double nv; if (t.step()>=1.0) nv = strtol(t.input.value(), 0, 0); - else nv = strtod(t.input.value(), 0); + else nv = csound->strtod((char*)t.input.value(), 0); ST(hack_o_rama1) = 1; t.handle_push(); t.handle_drag(nv); @@ -649,6 +704,8 @@ sxx += sww - buttonssize(); sww = buttonssize(); Fl_Boxtype box1 = (Fl_Boxtype)(box()&-2); int border_size=Fl::box_dx(box()); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (damage()&~FL_DAMAGE_CHILD) input.clear_damage(FL_DAMAGE_ALL); input.box(box()); @@ -705,6 +762,8 @@ void Fl_Value_Input_Spin::value_damage(void) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (ST(hack_o_rama1)) return; char buf[128]; format(buf); @@ -743,6 +802,8 @@ int my = Fl::event_y(); int sxx = x(), syy = y(), sww = w(), shh = h(); sxx += sww - buttonssize(); sww = buttonssize(); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (!ST(indrag) && ( !ST(sldrag) || !((mx>=sxx && mx<=(sxx+sww)) && (my>=syy && my<=(syy+shh)))) ) { @@ -843,6 +904,8 @@ : Fl_Valuator(x,y,w,h,l), input(x, y, w, h, 0) { csound = cs; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); soft_ = 0; // if (input.parent()) // defeat automatic-add // ((Fl_Group*)input.parent())->remove(input); @@ -870,10 +933,11 @@ void Fl_Value_Slider_Input::input_cb(Fl_Widget*, void* v) { Fl_Value_Slider_Input& t = *(Fl_Value_Slider_Input*)v; CSOUND *csound = t.csound; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); double nv; if (t.step()>=1.0) nv = strtol(t.input.value(), 0, 0); - else nv = strtod(t.input.value(), 0); + else nv = csound->strtod((char*)t.input.value(), 0); ST(hack_o_rama2) = 1; t.handle_push(); t.handle_drag(nv); @@ -890,7 +954,7 @@ int border_size=Fl::box_dx(box()); if (horizontal()) { - //bww = textboxsize(); + //bww = textboxsize(); sxx += textboxsize(); sww -= textboxsize(); input.resize(X,Y,W-sww,shh); } @@ -929,6 +993,8 @@ void Fl_Value_Slider_Input::value_damage() { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (ST(hack_o_rama2)) return; char buf[128]; format(buf); @@ -942,6 +1008,8 @@ int my = Fl::event_y(); int sxx = x(), syy = y(), sww = w(), shh = h(); int border_size=Fl::box_dx(box()); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (horizontal()) { sxx += textboxsize(); sww -= textboxsize(); } @@ -1079,15 +1147,14 @@ opcode_name = fld->opcode_name = ((OPDS *) (v.opcode))->optext->t.opcod; if (UNLIKELY(opcode_name.c_str() == NULL)) { - csound->InitError(csound, "%s", - Str("Invalid snapshot. Perhaps you modified " - "orchestra widget code after you saved " - "the snapshot bank.")); + csound->InitError(csound, Str("Invalid snapshot. Perhaps you modified " + "orchestra widget code after you saved " + "the snapshot bank.")); goto err; } else if (opcode_name == "FLslider") { FLSLIDER *p = (FLSLIDER *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; fld->exp = (int) *p->iexp; min = fld->min = *p->imin; max = fld->max = *p->imax; switch (fld->exp) { @@ -1109,7 +1176,7 @@ } else if (opcode_name == "FLslidBnk" || opcode_name == "FLvslidBnk") { FLSLIDERBANK *p = (FLSLIDERBANK *) (v.opcode); - fld->widg_name = GetString(csound, p->names, p->XSTRCODE); + fld->widg_name = ((STRINGDAT *)p->names)->data; int numsliders = (int) *p->inumsliders; fld->sldbnk = p->slider_data; // fld->sldbnkValues = new MYFLT[numsliders]; @@ -1139,7 +1206,7 @@ } else if (opcode_name == "FLslidBnk2" || opcode_name == "FLvslidBnk2") { FLSLIDERBANK2 *p = (FLSLIDERBANK2 *) (v.opcode); - fld->widg_name = GetString(csound, p->names, p->XSTRCODE); + fld->widg_name = ((STRINGDAT *)p->names)->data; int numsliders = (int) *p->inumsliders; fld->sldbnk = p->slider_data; // EXCEPTIONAL CASE! fld->exp contains the number of sliders @@ -1167,7 +1234,7 @@ } else if (opcode_name == "FLknob") { FLKNOB *p = (FLKNOB *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; fld->exp = (int) *p->iexp; min = fld->min = *p->imin; max = fld->max = *p->imax; switch (fld->exp) { @@ -1189,7 +1256,7 @@ } else if (opcode_name == "FLroller") { FLROLLER *p = (FLROLLER *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; fld->exp = (int) *p->iexp; min = fld->min = *p->imin; max = fld->max = *p->imax; switch (fld->exp) { @@ -1211,7 +1278,7 @@ } else if (opcode_name == "FLtext") { FLTEXT *p = (FLTEXT *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; val = *p->kout; min = fld->min = *p->imin; max = fld->max = *p->imax; if (min < max) { if (val < min) val=min; @@ -1226,7 +1293,7 @@ } else if (opcode_name == "FLjoy") { FLJOYSTICK *p = (FLJOYSTICK *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; fld->exp = (int) *p->iexpx; min = fld->min = *p->iminx; max = fld->max = *p->imaxx; switch (fld->exp) { @@ -1267,7 +1334,7 @@ } else if (opcode_name == "FLbutton") { FLBUTTON *p = (FLBUTTON *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; fld->value = *p->kout; fld->min = 0; fld->max = 1; fld->exp = LIN_; } @@ -1280,7 +1347,7 @@ } else if (opcode_name == "FLcount") { FLCOUNTER *p = (FLCOUNTER *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; val = *p->kout; min = *p->imin; max =*p->imax; if (min != max) { if (val < min) val=min; @@ -1291,11 +1358,11 @@ } else if (opcode_name == "FLvalue") { FLVALUE *p = (FLVALUE *) (v.opcode); - fld->widg_name = GetString(csound, p->name, p->XSTRCODE); + fld->widg_name = p->name->data; } else if (opcode_name == "FLbox") { FL_BOX *p = (FL_BOX *) (v.opcode); - fld->widg_name = GetString(csound, p->itext, p->XSTRCODE); + fld->widg_name = p->itext->data; } } err: @@ -1306,7 +1373,7 @@ { if (is_empty == 1) { /* FIXME: should have CSOUND* pointer here */ - /* return csound->InitError(csound, "empty snapshot"); */ + /* return csound->InitError(csound, Str("empty snapshot")); */ return -1; } FLlock(); //<================= @@ -1382,7 +1449,7 @@ if(fld->value >= *p->ioff - 0.0001 && fld->value <= *p->ioff + 0.0001) // to avoid eventual math rounding ((Fl_Button*) o)->value(0); - else + else if (fld->value >= *p->ion - 0.0001 && fld->value <= *p->ion + 0.0001) // to avoid eventual math rounding ((Fl_Button*) o)->value(1); @@ -1503,12 +1570,15 @@ static int set_snap(CSOUND *csound, FLSETSNAP *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); SNAPSHOT snap(ST(AddrSetValue), (int) *p->group ); int numfields = snap.fields.size(); int index = (int) *p->index; int group = (int) *p->group; SNAPVEC snapvec_init; SNAPSHOT snap_init; + snap_init.fields.resize(1,VALUATOR_FIELD()); snapvec_init.resize(1,snap_init); if (group+1 > (int) ST(snapshots).size()) @@ -1517,19 +1587,19 @@ *p->inum_val = numfields; // number of snapshots if (*p->ifn >= 1) { // if the table number is valid FUNC *ftp; // store the snapshot into the table - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { MYFLT *table = ftp->ftable; for (int j = 0; j < numfields; j++) { table[index*numfields+j] = snap.fields[j].value; } } - else return csound->InitError(csound, "%s", - Str("FLsetsnap: invalid table")); + else return csound->InitError(csound, + Str("FLsetsnap: invalid table")); } else { // else store it into snapshot bank if ((int) ST(snapshots)[group].size() < index+1) ST(snapshots)[group].resize(index+1); - csound->Message(csound, "setsnap saving\n"); + csound->Message(csound, Str("setsnap saving\n")); ST(snapshots)[group][index]=snap; *p->inum_snap = ST(snapshots)[group].size(); } @@ -1542,6 +1612,8 @@ int group = (int) *p->group; SNAPVEC snapvec_init; SNAPSHOT snap_init; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); snap_init.fields.resize(1,VALUATOR_FIELD()); snapvec_init.resize(1,snap_init); if (group+1 > (int) ST(snapshots).size()) @@ -1563,7 +1635,7 @@ string filename; #ifdef WIN32 int id = MessageBox(NULL, Str("Saving could overwrite the old file.\n" - "Are you sure to save ?"), "Warning", + "Are you sure to save ?"), Str("Warning"), MB_SYSTEMMODAL | MB_ICONWARNING | MB_OKCANCEL); if (id != IDOK) return OK; @@ -1582,10 +1654,10 @@ return OK; } #endif - csound->strarg2name(csound, s, p->filename, "snap.", p->XSTRCODE); + csound->strarg2name(csound, s, p->filename->data, "snap.", 1); s2 = csound->FindOutputFile(csound, s, "SNAPDIR"); if (UNLIKELY(s2 == NULL)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsavesnap: cannot open file")); strcpy(s, s2); csound->Free(csound, s2); @@ -1593,6 +1665,8 @@ fstream file(filename.c_str(), ios::out); int group = (int) *p->group; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); for (int j =0; j < (int) ST(snapshots)[group].size(); j++) { file << "----------- "<< j << " -----------\n"; int siz = ST(snapshots)[group][j].fields.size(); @@ -1635,11 +1709,12 @@ { char s[MAXNAME], *s2; string filename; - - csound->strarg2name(csound, s, p->filename, "snap.", p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + csound->strarg2name(csound, s, p->filename->data, "snap.", 1); s2 = csound->FindInputFile(csound, s, "SNAPDIR"); if (UNLIKELY(s2 == NULL)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLloadsnap: cannot open file")); strcpy(s, s2); csound->Free(csound, s2); @@ -1685,7 +1760,6 @@ if (UNLIKELY(!(opc_orig == opc))) { //return csound->InitError(csound, csound->Message(csound, - "%s", Str("unmatched widget, probably due to a " "modified orchestra. Modifying an " "orchestra makes it incompatible with " @@ -1754,6 +1828,8 @@ static char *GetString(CSOUND *csound, MYFLT *pname, int is_string) { char *Name = new char[MAXNAME]; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(allocatedStrings).push_back(Name); return csound->strarg2name(csound, Name, pname, "", is_string); } @@ -1761,6 +1837,7 @@ class CsoundFLTKKeyboardBuffer { private: CSOUND *csound; + WIDGET_GLOBALS *widgetGlobals; void *mutex_; char kbdTextBuf[64]; int kbdEvtBuf[64]; @@ -1783,6 +1860,8 @@ CsoundFLTKKeyboardBuffer(CSOUND *csound) { this->csound = csound; + widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); mutex_ = csound->Create_Mutex(0); kbdTextBufRPos = 0; kbdTextBufWPos = 0; @@ -1854,14 +1933,17 @@ class CsoundFLWindow : public Fl_Double_Window { public: CSOUND *csound_; //gab + WIDGET_GLOBALS *widgetGlobals; CsoundFLTKKeyboardBuffer fltkKeyboardBuffer; CsoundFLWindow(CSOUND *csound, int w, int h, const char *title = 0) : Fl_Double_Window(w, h, title), csound_(csound), fltkKeyboardBuffer(csound)//gab { - csound->Set_Callback(csound, fltkKeyboardCallback, (void*) this, - CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); + widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + csound->Set_KeyCallback(csound, fltkKeyboardCallback, (void*) this, + CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); } CsoundFLWindow(CSOUND *csound, int x, int y, int w, int h, const char *title = 0) @@ -1869,13 +1951,15 @@ csound_(csound), fltkKeyboardBuffer(csound)//gab { - csound->Set_Callback(csound, fltkKeyboardCallback, (void*) this, - CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); + widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + csound->Set_KeyCallback(csound, fltkKeyboardCallback, (void*) this, + CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT); } virtual ~CsoundFLWindow() { CSOUND *csound = fltkKeyboardBuffer.GetCsound(); - csound->Remove_Callback(csound, fltkKeyboardCallback); + csound->Remove_KeyCallback(csound, fltkKeyboardCallback); } virtual int handle(int evt) { @@ -1922,6 +2006,8 @@ PUBLIC int csoundModuleDestroy(CSOUND *csound) { int j; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); #ifndef NO_FLTK_THREADS int *fltkflags = getFLTKFlagsPtr(csound); if (fltkflags) { @@ -1957,7 +2043,7 @@ } } #endif // NO_FLTK_THREADS - if(csound->widgetGlobals != NULL) { + if(widgetGlobals != NULL) { for (j = ST(allocatedStrings).size() - 1; j >= 0; j--) { delete[] ST(allocatedStrings)[j]; ST(allocatedStrings).pop_back(); @@ -1998,8 +2084,9 @@ ST(FL_ix) = 10; ST(FL_iy) = 10; - delete (WIDGET_GLOBALS*)csound->widgetGlobals; - csound->widgetGlobals = NULL; + //delete (WIDGET_GLOBALS*)csound->widgetGlobals; + csound->DestroyGlobalVariable(csound, "WIDGET_GLOBALS"); + //csound->widgetGlobals = NULL; } return 0; } @@ -2016,7 +2103,8 @@ volatile widgetsGlobals_t *p; CSOUND *csound = (CSOUND*) userdata; int j; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); p = (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, "_widgets_globals"); #ifdef LINUX @@ -2058,7 +2146,7 @@ if (!(p->fltkFlags & 8)) Fl::unlock(); } while (j && !p->end_of_perf); - csound->Message(csound, "%s", Str("end of widget thread\n")); + csound->Message(csound, Str("end of widget thread\n")); // IV - Jun 07 2005: exit if all windows are closed p->exit_now = -1; return (uintptr_t) 0; @@ -2075,7 +2163,8 @@ int FL_run(CSOUND *csound, FLRUN *p) { int *fltkFlags; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); fltkFlags = getFLTKFlagsPtr(csound); (*fltkFlags) |= 32; #ifndef NO_FLTK_THREADS @@ -2084,10 +2173,10 @@ if (UNLIKELY(csound->QueryGlobalVariable(csound, "_widgets_globals") != NULL)) - return csound->InitError(csound, "%s", Str("FLrun was already called")); + return csound->InitError(csound, Str("FLrun was already called")); if (UNLIKELY(csound->CreateGlobalVariable(csound, "_widgets_globals", sizeof(widgetsGlobals_t)) != 0)) - csound->Die(csound, "%s", Str("FL_run: memory allocation failure")); + csound->Die(csound, Str("FL_run: memory allocation failure")); pp = (widgetsGlobals_t*) csound->QueryGlobalVariable(csound, "_widgets_globals"); pp->fltkFlags = *fltkFlags; @@ -2122,6 +2211,8 @@ int fl_update(CSOUND *csound, FLRUN *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_lock(csound); for (int j=0; j< (int) ST(AddrSetValue).size()-1; j++) { ADDR_SET_VALUE v = ST(AddrSetValue)[j]; @@ -2137,6 +2228,8 @@ static inline void displ(MYFLT val, MYFLT index, CSOUND *csound) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (index >= 0) { // display current value of valuator char valString[MAXNAME]; sprintf(valString, "%.5g", val); @@ -2170,17 +2263,17 @@ pid_t pId = vfork(); if (pId == 0) { - + char *th; char *v[40]; int i = 0; strcpy(command, p->commandString); - char *tok = strtok(command, " "); + char *tok = csound->strtok_r(command,(char *) " ", &th); if(tok != NULL) { v[i++] = tok; - while((tok = strtok(NULL, " ")) != NULL) { + while((tok = csound->strtok_r(NULL,(char *) " ", &th)) != NULL) { v[i++] = tok; } v[i] = NULL; @@ -2189,22 +2282,23 @@ _exit(0); } else if (UNLIKELY(pId < 0)) { - p->csound->Message(p->csound, "%s", + p->csound->Message(p->csound, Str("Error: Unable to fork process\n")); } csound->Free(csound, command); #elif defined(WIN32) { + char *th; char *v[40]; int i = 0; strcpy(command, p->commandString); - char *tok = strtok(command, " "); + char *tok = cs_strtok_r(command, " ", &th); if(tok != NULL) { v[i++] = tok; - while((tok = strtok(NULL, " ")) != NULL) { + while((tok = cs_strtok_r(NULL, " ", &th)) != NULL) { v[i++] = tok; } v[i] = NULL; @@ -2448,12 +2542,15 @@ static int rand_31_i(CSOUND *csound, int maxVal) { - double x = (double) (csound->Rand31(&(csound->randSeed2)) - 1); + int seed = csound->GetRandSeed(csound,2); + double x = (double) (csound->Rand31(&seed) - 1); return (int) (x * (double) (maxVal + 1) / 2147483646.0); } static void widget_attributes(CSOUND *csound, Fl_Widget *o) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (ST(FLtext_size) == -2 ) { ST(FLtext_size) = -1; ST(FLtext_color)= -1; @@ -2555,7 +2652,9 @@ static int StartPanel(CSOUND *csound, FLPANEL *p) { char *panelName; - panelName = GetString(csound, p->name, p->XSTRCODE); + panelName = p->name->data; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); *(getFLTKFlagsPtr(csound)) |= 32; int x = (int) *p->ix, y = (int) *p->iy; @@ -2580,7 +2679,7 @@ // } Fl_Window *o; - if (*(p->ikbdsense) == FL(0.0)) { + if (*(p->ikbdsense) == MYFLT(0.0)) { if (x < 0) o = new Fl_Window(width, height, panelName); else @@ -2607,14 +2706,16 @@ static int EndPanel(CSOUND *csound, FLPANELEND *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(stack_count)--; ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLpanel"))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLpanel_end: invalid stack pointer: " "verify its placement")); if (UNLIKELY(adrstk.count != ST(stack_count))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLpanel_end: invalid stack count: " "verify FLpanel/FLpanel_end count and" " placement")); @@ -2626,6 +2727,8 @@ //----------- static int StartScroll(CSOUND *csound, FLSCROLL *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_Scroll *o = new Fl_Scroll ((int) *p->ix, (int) *p->iy, (int) *p->iwidth, (int) *p->iheight); ADDR_STACK adrstk(&p->h,o,ST(stack_count)); @@ -2636,15 +2739,17 @@ static int EndScroll(CSOUND *csound, FLSCROLLEND *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(stack_count)--; ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLscroll"))) return - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLscroll_end: invalid stack pointer: " "verify its placement")); if (UNLIKELY(adrstk.count != ST(stack_count))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLscroll_end: invalid stack count: " "verify FLscroll/FLscroll_end count " "and placement")); @@ -2657,6 +2762,8 @@ //----------- static int StartTabs(CSOUND *csound, FLTABS *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_Tabs *o = new Fl_Tabs ((int) *p->ix, (int) *p->iy, (int) *p->iwidth, (int) *p->iheight); widget_attributes(csound, o); @@ -2669,18 +2776,20 @@ static int EndTabs(CSOUND *csound, FLTABSEND *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(stack_count)--; ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLtabs"))) return - csound->InitError(csound, "%s", - Str("FLscroll_end: invalid stack pointer: " - "verify its placement")); + csound->InitError(csound, + Str("FLscroll_end: invalid stack pointer: " + "verify its placement")); if (UNLIKELY(adrstk.count != ST(stack_count))) - return csound->InitError(csound, "%s", - Str("FLtabs_end: invalid stack count: " - "verify FLtabs/FLtabs_end count and " - "placement")); + return csound->InitError(csound, + Str("FLtabs_end: invalid stack count: " + "verify FLtabs/FLtabs_end count and " + "placement")); ((Fl_Scroll*) adrstk.WidgAddress)->end(); ST(AddrStack).pop_back(); @@ -2690,7 +2799,9 @@ //----------- static int StartGroup(CSOUND *csound, FLGROUP *p) { - char *Name = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *Name = p->name->data; Fl_Group *o = new Fl_Group ((int) *p->ix, (int) *p->iy, (int) *p->iwidth, (int) *p->iheight,Name); widget_attributes(csound, o); @@ -2719,14 +2830,16 @@ static int EndGroup(CSOUND *csound, FLGROUPEND *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(stack_count)--; ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLgroup"))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLgroup_end: invalid stack pointer: " "verify its placement")); if (UNLIKELY(adrstk.count != ST(stack_count))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLgroup_end: invalid stack count: " "verify FLgroup/FLgroup_end count and" " placement")); @@ -2740,6 +2853,8 @@ static int StartPack(CSOUND *csound, FLPACK *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_Pack *o = new Fl_Pack ((int) *p->ix, (int) *p->iy, (int) *p->iwidth, (int) *p->iheight); Fl_Boxtype borderType = FL_FLAT_BOX; @@ -2759,14 +2874,16 @@ static int EndPack(CSOUND *csound, FLSCROLLEND *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(stack_count)--; ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLpack"))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLpack_end: invalid stack pointer: " "verify its placement")); if (UNLIKELY(adrstk.count != ST(stack_count))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLpack_end: invalid stack count: " "verify FLpack/FLpack_end count and " "placement")); @@ -2780,6 +2897,8 @@ static int fl_widget_color(CSOUND *csound, FLWIDGCOL *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (*p->red1 < 0) { // reset colors to default ST(FLcolor) = (int) *p->red1; //when called without arguments ST(FLcolor2) =(int) *p->red1; @@ -2797,6 +2916,8 @@ static int fl_widget_color2(CSOUND *csound, FLWIDGCOL2 *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (*p->red < 0) { // reset colors to default ST(FLcolor2) =(int) *p->red; } @@ -2810,6 +2931,8 @@ static int fl_widget_label(CSOUND *csound, FLWIDGLABEL *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (*p->size <= 0) { // reset settings to default ST(FLtext_size) = 0; //when called without arguments ST(FLtext_font) = -1; @@ -2848,8 +2971,8 @@ return 4; if (strcmp(opname, "FLbox") != 0) return 0; - csound->Warning(csound, "System error: value() method called from " - "non-valuator object"); + csound->Warning(csound, Str("System error: value() method called from " + "non-valuator object")); return -1; } @@ -2914,13 +3037,15 @@ static int fl_setWidgetValuei(CSOUND *csound, FL_SET_WIDGET_VALUE_I *p) { - MYFLT log_base = FL(1.0); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + MYFLT log_base = MYFLT(1.0); ADDR_SET_VALUE &v = ST(AddrSetValue)[(int) *p->ihandle]; int widgetType; widgetType = fl_getWidgetTypeFromOpcodeName(csound, v.opcode); if (UNLIKELY(widgetType == 4)) { - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLvalue cannot be set by FLsetVal.\n")); return NOTOK; } @@ -2951,14 +3076,15 @@ static int fl_setWidgetValue_set(CSOUND *csound, FL_SET_WIDGET_VALUE *p) { p->handle = (int) *(p->ihandle); - - MYFLT log_base = FL(1.0); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + MYFLT log_base = MYFLT(1.0); ADDR_SET_VALUE &v = ST(AddrSetValue)[p->handle]; int widgetType; widgetType = fl_getWidgetTypeFromOpcodeName(csound, v.opcode); if (UNLIKELY(widgetType == 4)) { - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLvalue cannot be set by FLsetVal\n")); return NOTOK; } @@ -2970,7 +3096,7 @@ break; case EXP_: // exponential #if defined(sun) - log_base = (MYFLT) log(::pow(v.max / (double)v.min, + log_base = (MYFLT) log(::pow(v.max / (double)v.min, 1.0 / (v.max - v.min))); #else log_base = (MYFLT) log(::pow(v.max / v.min, 1.0 / (v.max - v.min))); @@ -2990,7 +3116,9 @@ static int fl_setWidgetValue(CSOUND *csound, FL_SET_WIDGET_VALUE *p) { - if (*p->ktrig != FL(0.0)) + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + if (*p->ktrig != MYFLT(0.0)) fl_setWidgetValue_(csound, ST(AddrSetValue)[p->handle], p->widgetType, *(p->kvalue), p->log_base); return OK; @@ -3001,6 +3129,8 @@ static int fl_setColor1(CSOUND *csound, FL_SET_COLOR *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; int color = fl_rgb_color((int) *p->red, @@ -3012,6 +3142,8 @@ static int fl_setColor2(CSOUND *csound, FL_SET_COLOR *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; int color = fl_rgb_color((int) *p->red, (int) *p->green, (int) *p->blue); @@ -3021,6 +3153,8 @@ static int fl_setTextColor(CSOUND *csound, FL_SET_COLOR *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; int color = fl_rgb_color((int) *p->red, (int) *p->green, (int) *p->blue); @@ -3030,6 +3164,8 @@ static int fl_setTextSize(CSOUND *csound, FL_SET_TEXTSIZE *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; o->labelsize((uchar) *p->ivalue); @@ -3038,6 +3174,8 @@ static int fl_setFont(CSOUND *csound, FL_SET_FONT *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; Fl_Font font; @@ -3069,6 +3207,8 @@ static int fl_setTextType(CSOUND *csound, FL_SET_FONT *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; Fl_Labeltype type; @@ -3093,7 +3233,7 @@ static int fl_box_(CSOUND *csound, FL_BOX *p) { - char *text = GetString(csound, p->itext, p->XSTRCODE); + char *text = p->itext->data; Fl_Box *o = new Fl_Box((int)*p->ix, (int)*p->iy, (int)*p->iwidth, (int)*p->iheight, text); widget_attributes(csound, o); @@ -3150,6 +3290,8 @@ o->labelfont(font); o->labelsize((unsigned char)*p->isize); o->align(FL_ALIGN_WRAP); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(AddrSetValue).push_back(ADDR_SET_VALUE(0, 0, 0, (void *)o, (void *)p, ST(currentSnapGroup))); *p->ihandle = ST(AddrSetValue).size()-1; @@ -3158,7 +3300,9 @@ static int fl_setText(CSOUND *csound, FL_SET_TEXT *p) { - char *text = GetString(csound, p->itext, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *text = p->itext->data; ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; o->label(text); @@ -3167,6 +3311,8 @@ static int fl_setSize(CSOUND *csound, FL_SET_SIZE *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; o->size((short) *p->iwidth, (short) *p->iheight); @@ -3175,6 +3321,8 @@ static int fl_setPosition(CSOUND *csound, FL_SET_POSITION *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; o->position((short) *p->ix, (short) *p->iy); @@ -3183,6 +3331,8 @@ static int fl_hide(CSOUND *csound, FL_WIDHIDE *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_lock(csound); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; @@ -3193,6 +3343,8 @@ static int fl_show(CSOUND *csound, FL_WIDSHOW *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_lock(csound); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; @@ -3203,6 +3355,8 @@ static int fl_setBox(CSOUND *csound, FL_SETBOX *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; Fl_Boxtype type; @@ -3237,6 +3391,8 @@ static int fl_align(CSOUND *csound, FL_TALIGN *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; Fl_Widget *o = (Fl_Widget *) v.WidgAddress; Fl_Align type; @@ -3264,7 +3420,9 @@ static int fl_value(CSOUND *csound, FLVALUE *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *controlName = p->name->data; int ix, iy, iwidth, iheight; if (*p->ix<0) ix = ST(FL_ix); else ST(FL_ix) = ix = (int) *p->ix; if (*p->iy<0) iy = ST(FL_iy); else ST(FL_iy) = iy = (int) *p->iy; @@ -3292,7 +3450,9 @@ static int fl_slider(CSOUND *csound, FLSLIDER *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *controlName = p->name->data; int ix,iy,iwidth, iheight,itype, iexp; bool plastic = false; @@ -3325,7 +3485,7 @@ itype = itype - 20; } if (UNLIKELY(itype > 10 && iexp == EXP_)) { - csound->Warning(csound, "%s", + csound->Warning(csound, Str("FLslider exponential, using non-labeled slider")); itype -= 10; } @@ -3333,7 +3493,7 @@ Fl_Slider *o; if (itype <= 10) o = new Fl_Slider(ix, iy, iwidth, iheight, controlName); else { - o = new Fl_Value_Slider_Input(csound, ix, iy, + o = new Fl_Value_Slider_Input(csound, ix, iy, iwidth, iheight, controlName); itype -=10; //o->labelsize(20); @@ -3348,7 +3508,7 @@ case 4: o->type(FL_VERT_SLIDER); break; case 5: o->type(FL_HOR_NICE_SLIDER); o->box(FL_FLAT_BOX); break; case 6: o->type(FL_VERT_NICE_SLIDER); o->box(FL_FLAT_BOX); break; - default: return csound->InitError(csound, "%s", + default: return csound->InitError(csound, Str("FLslider: invalid slider type")); } if (plastic) o->box(FL_PLASTIC_DOWN_BOX); @@ -3361,7 +3521,7 @@ break; case EXP_ : //exponential if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslider: zero is illegal " "in exponential operations")); range = max - min; @@ -3377,7 +3537,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->table = ftp->ftable; p->tablen = ftp->flen; } @@ -3396,15 +3556,17 @@ return OK; } - static int fl_slider_bank(CSOUND *csound, FLSLIDERBANK *p) + static int fl_slider_bank_(CSOUND *csound, FLSLIDERBANK *p, int istring) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); char s[MAXNAME]; bool plastic = false; - if (p->XSTRCODE) - strcpy(s, (char*) p->names); - else if ((long) *p->names <= csound->strsmax && - csound->strsets != NULL && csound->strsets[(long) *p->names]) { - strcpy(s, csound->strsets[(long) *p->names]); + if (istring) + strcpy(s, ((STRINGDAT*) p->names)->data); + else if ((long) *p->names <= csound->GetStrsmax(csound) && + csound->GetStrsets(csound,(long) *p->names)) { + strcpy(s, csound->GetStrsets(csound,(long) *p->names)); } string tempname(s); stringstream sbuf; @@ -3418,33 +3580,35 @@ FUNC *ftp; MYFLT *minmaxtable = NULL, *typetable = NULL, *outable, *exptable = NULL; + MYFLT *zkstart; + int zklast = csound->GetZakBounds(csound, &zkstart); if (*p->ioutable < 1) { - if (LIKELY(csound->zkstart != NULL && - csound->zklast > (long)(*p->inumsliders+*p->ioutablestart_ndx))) - outable = csound->zkstart + (long) *p->ioutablestart_ndx; + if (LIKELY(zkstart != NULL && + zklast > (long)(*p->inumsliders+*p->ioutablestart_ndx))) + outable = zkstart + (long) *p->ioutablestart_ndx; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("invalid ZAK space allocation")); } } else { - if (LIKELY((ftp = csound->FTFind(csound, p->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL)) outable = ftp->ftable + (long) *p->ioutablestart_ndx; else return NOTOK; } if ((int) *p->iminmaxtable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->iminmaxtable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iminmaxtable)) != NULL)) minmaxtable = ftp->ftable; else return NOTOK; } if ((int) *p->iexptable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->iexptable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iexptable)) != NULL)) exptable = ftp->ftable; else return NOTOK; } if ((int) *p->itypetable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->itypetable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->itypetable)) != NULL)) typetable = ftp->ftable; else return NOTOK; } @@ -3505,8 +3669,8 @@ max = minmaxtable[j*2+1]; } else { - min = FL(0.0); - max = FL(1.0); + min = MYFLT(0.0); + max = MYFLT(1.0); } int iexp; @@ -3538,7 +3702,7 @@ case EXP_ : //exponential if (UNLIKELY(min == 0 || max == 0)) return - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLslidBnk: zero is illegal " "in exponential operations")); range = max - min; @@ -3565,7 +3729,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) p->slider_data[j].table = ftp->ftable; else return NOTOK; p->slider_data[j].tablen = ftp->flen; @@ -3598,9 +3762,19 @@ return OK; } + static int fl_slider_bank(CSOUND *csound, FLSLIDERBANK *p){ + return fl_slider_bank_(csound,p,0); + } + + static int fl_slider_bank_S(CSOUND *csound, FLSLIDERBANK *p){ + return fl_slider_bank_(csound,p,1); + } + static int fl_joystick(CSOUND *csound, FLJOYSTICK *p) { - char *Name = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *Name = p->name->data; int ix,iy,iwidth, iheight, iexpx, iexpy; if (*p->ix < 0) ix = 10; // omitted options: set default @@ -3636,7 +3810,7 @@ o->xbounds(*p->iminx,*p->imaxx); break; case EXP_: //exponential { if (UNLIKELY(*p->iminx == 0 || *p->imaxx == 0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLjoy X axe: zero is illegal " "in exponential operations")); MYFLT range = *p->imaxx - *p->iminx; @@ -3651,7 +3825,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexpx); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->tablex = ftp->ftable; p->tablenx = ftp->flen; } @@ -3670,7 +3844,7 @@ o->ybounds(*p->imaxy,*p->iminy); break; case EXP_ : //exponential { if (UNLIKELY(*p->iminy == 0 || *p->imaxy == 0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLjoy X axe: zero is illegal " "in exponential operations")); MYFLT range = *p->imaxy - *p->iminy; @@ -3685,7 +3859,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexpy); - if (LIKELY((ftp = csound->FTFind(csound, &fnum)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, &fnum)) != NULL)) { p->tabley = ftp->ftable; p->tableny = ftp->flen; } @@ -3719,7 +3893,9 @@ static int fl_knob(CSOUND *csound, FLKNOB *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *controlName = p->name->data; int ix, iy, iwidth, itype, iexp; if (*p->iy < 0) iy = ST(FL_iy); @@ -3745,8 +3921,8 @@ case 1: o = new Fl_Knob(csound, ix, iy, iwidth, iwidth, controlName); o->box(FL_NO_BOX); - if (*p->icursorsize > FL(0.5)) - ((Fl_Knob*) o)->cursor((int) (*p->icursorsize + FL(0.5))); + if (*p->icursorsize > MYFLT(0.5)) + ((Fl_Knob*) o)->cursor((int) (*p->icursorsize + MYFLT(0.5))); break; case 2: o = new Fl_Dial(ix, iy, iwidth, iwidth, controlName); @@ -3765,7 +3941,7 @@ o->box(_FL_OSHADOW_BOX); break; default: - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLknob: invalid knob type")); } widget_attributes(csound, o); @@ -3781,7 +3957,7 @@ { MYFLT min = p->min = *p->imin, max = *p->imax; if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLknob: zero is illegal " "in exponential operations")); MYFLT range = max - min; @@ -3798,7 +3974,7 @@ FUNC *ftp; p->min = *p->imin; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->table = ftp->ftable; p->tablen = ftp->flen; } @@ -3818,7 +3994,9 @@ static int fl_text(CSOUND *csound, FLTEXT *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *controlName = p->name->data; int ix,iy,iwidth,iheight,itype; MYFLT istep; @@ -3832,7 +4010,7 @@ else ST(FLcontrol_iheight) = iheight = (int) *p->iheight; if (*p->itype < 1) itype = 1; else itype = (int) *p->itype; - if (*p->istep < 0) istep = FL(.1); + if (*p->istep < 0) istep = MYFLT(.1); else istep = *p->istep; Fl_Valuator* o; @@ -3874,7 +4052,9 @@ static int fl_button(CSOUND *csound, FLBUTTON *p) { - char *Name = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *Name = p->name->data; int type = (int) *p->itype; bool plastic = false; if (type > 19) { @@ -3882,7 +4062,7 @@ plastic = true; } if (UNLIKELY(type > 9)) { // ignored when getting ST(snapshots) - csound->Warning(csound, + csound->Warning(csound, Str("FLbutton \"%s\" ignoring snapshot capture retrieve"), Name); type = type - 10; @@ -3924,7 +4104,7 @@ } break; default: - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLbutton: invalid button type")); } Fl_Button *o = w; @@ -3943,7 +4123,9 @@ static int fl_close_button(CSOUND *csound, FLCLOSEBUTTON *p) { - char *Name = GetString(csound, p->name, p->XSTRCODE); + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + char *Name = p->name->data; Fl_Button *w; @@ -3957,7 +4139,7 @@ ADDR_STACK adrstk = ST(AddrStack).back(); if (UNLIKELY(strcmp( adrstk.h->optext->t.opcod, "FLpanel"))) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLcloseButton: invalid stack" " pointer: verify its placement")); @@ -3972,15 +4154,17 @@ static int fl_exec_button(CSOUND *csound, FLEXECBUTTON *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); p->csound = csound; Fl_Button *w; - p->commandString = GetString(csound, p->command, p->XSTRCODE); + p->commandString = p->command->data; csound->Message(csound, Str("Command Found: %s\n"), p->commandString); w = new Fl_Button((int)*p->ix, (int)*p->iy, - (int)*p->iwidth, (int)*p->iheight, "About"); + (int)*p->iwidth, (int)*p->iheight, Str("About")); Fl_Button *o = w; @@ -3998,6 +4182,8 @@ static int fl_button_bank(CSOUND *csound, FLBUTTONBANK *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); char *Name = (char*)"/0"; int type = (int) *p->itype; bool plastic = false; @@ -4049,7 +4235,7 @@ w->down_box(FL_PLASTIC_DOWN_BOX); } break; - default: return csound->InitError(csound, "%s", + default: return csound->InitError(csound, Str("FLbuttonBank: " "invalid button type")); } @@ -4070,17 +4256,18 @@ ST(AddrSetValue).push_back(ADDR_SET_VALUE(0, 0, 0, (void *) o, (void *) p, ST(currentSnapGroup))); - *p->kout = FL(0.0); + *p->kout = MYFLT(0.0); *p->ihandle = ST(AddrSetValue).size()-1; return OK; } static int fl_counter(CSOUND *csound, FLCOUNTER *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + char *controlName = p->name->data; // int ix,iy,iwidth,iheight,itype; // MYFLT istep1, istep2; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); Fl_Counter* o = new Fl_Counter((int)*p->ix, (int)*p->iy, (int)*p->iwidth, (int)*p->iheight, controlName); @@ -4114,9 +4301,11 @@ static int fl_roller(CSOUND *csound, FLROLLER *p) { - char *controlName = GetString(csound, p->name, p->XSTRCODE); + char *controlName = p->name->data; int ix,iy,iwidth, iheight,itype, iexp ; double istep; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (*p->iy < 0) { iy = ST(FL_iy); ST(FL_iy) += ST(FLroller_iheight) + 15; @@ -4155,7 +4344,7 @@ o->type(FL_VERTICAL); break; default: - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLroller: invalid roller type")); } widget_attributes(csound, o); @@ -4169,7 +4358,7 @@ { MYFLT min = p->min, max = *p->imax; if (UNLIKELY(min == 0 || max == 0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslider: zero is illegal " "in exponential operations")); MYFLT range = max - min; @@ -4186,7 +4375,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->table = ftp->ftable; p->tablen = ftp->flen; } @@ -4207,11 +4396,13 @@ static int FLprintkset(CSOUND *csound, FLPRINTK *p) { - if (*p->ptime < FL(1.0) / csound->global_ekr) - p->ctime = FL(1.0) / csound->global_ekr; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + if (*p->ptime < MYFLT(1.0) / CS_EKR) + p->ctime = MYFLT(1.0) / CS_EKR; else p->ctime = *p->ptime; - p->initime = (MYFLT) csound->kcounter * csound->onedkr; + p->initime = (MYFLT) csound->GetKcounter(csound) * (1.0/CS_EKR); p->cysofar = -1; return OK; } @@ -4220,8 +4411,11 @@ { MYFLT timel; long cycles; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - timel = ((MYFLT) csound->kcounter * csound->onedkr) - p->initime; + timel = ((MYFLT) csound->GetKcounter(csound) * + (1.0/CS_EKR)) - p->initime; cycles = (long)(timel / p->ctime); if (p->cysofar < cycles) { p->cysofar = cycles; @@ -4235,13 +4429,15 @@ static int FLprintk2set(CSOUND *csound, FLPRINTK2 *p) // IV - Aug 27 2002 { - p->oldvalue = FL(-1.12123e35); // hack to force printing first value + p->oldvalue = MYFLT(-1.12123e35); // hack to force printing first value return OK; } static int FLprintk2(CSOUND *csound, FLPRINTK2 *p) { MYFLT value = *p->val; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (p->oldvalue != value) { char valString[MAXNAME]; sprintf(valString,"%.5g", *p->val); @@ -4256,6 +4452,8 @@ void skin(CSOUND* csound, Fl_Widget *o, int imgNum, bool isTiled) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); #ifdef CS_IMAGE extern void* get_image(CSOUND* csound, int imgNum); ImageSTRUCT *bmp = (ImageSTRUCT*) get_image(csound, imgNum); @@ -4351,8 +4549,10 @@ static int fl_hvsbox(CSOUND *csound,FL_HVSBOX *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (UNLIKELY(*p->numlinesX < 2 || *p->numlinesY < 2)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLhvsBox: a square area must be" " delimited by 2 lines at least")); @@ -4372,6 +4572,8 @@ static int fl_setHvsValue_set(CSOUND *csound,FL_SET_HVS_VALUE *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ADDR_SET_VALUE v = ST(AddrSetValue)[(int) *p->ihandle]; p->WidgAddress = v.WidgAddress; p->opcode = v.opcode; @@ -4398,14 +4600,14 @@ if (*p->ifn > 0) { // mapping values p->flag = 1; - if (LIKELY((ftp = csound->FTFind(csound,p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifn)) != NULL)) p->table = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLkeyIn: invalid table number")); } if (UNLIKELY(ftp->flen < 512)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLkeyIn: table too short!")); } } @@ -4415,6 +4617,8 @@ static int fl_keyin(CSOUND *csound,FLKEYIN *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if (ST(last_KEY)) { int key; @@ -4438,6 +4642,8 @@ static int fl_setSnapGroup(CSOUND *csound, FLSETSNAPGROUP *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); ST(currentSnapGroup) = (int) *p->group; return OK; } @@ -4474,15 +4680,17 @@ } - static int fl_vertical_slider_bank(CSOUND *csound, FLSLIDERBANK *p) + static int fl_vertical_slider_bank_(CSOUND *csound, FLSLIDERBANK *p, int istring) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); char s[MAXNAME]; bool plastic = false; - if (p->XSTRCODE) - strcpy(s, (char*) p->names); - else if ((long) *p->names <= csound->strsmax && - csound->strsets != NULL && csound->strsets[(long) *p->names]) { - strcpy(s, csound->strsets[(long) *p->names]); + if (istring) + strcpy(s, ((STRINGDAT *)p->names)->data); + else if ((long) *p->names <= csound->GetStrsmax(csound) && + csound->GetStrsets(csound,(long) *p->names)) { + strcpy(s, csound->GetStrsets(csound,(long) *p->names)); } string tempname(s); stringstream sbuf; @@ -4495,33 +4703,35 @@ FUNC *ftp; MYFLT *minmaxtable = NULL, *typetable = NULL, *outable, *exptable = NULL; + MYFLT *zkstart; + int zklast = csound->GetZakBounds(csound, &zkstart); if (*p->ioutable < 1) { - if (LIKELY(csound->zkstart != NULL && - csound->zklast>(long)(*p->inumsliders+*p->ioutablestart_ndx))) - outable = csound->zkstart + (long) *p->ioutablestart_ndx; + if (LIKELY(zkstart != NULL && + zklast > (long)(*p->inumsliders+*p->ioutablestart_ndx))) + outable = zkstart + (long) *p->ioutablestart_ndx; else { - return csound->InitError(csound, "%s", - Str("invalid ZAK space allocation")); + return csound->InitError(csound, + Str("invalid ZAK space allocation")); } } else { - if (LIKELY((ftp = csound->FTFind(csound, p->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL)) outable = ftp->ftable + (long) *p->ioutablestart_ndx; else return NOTOK; } if ((int) *p->iminmaxtable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->iminmaxtable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iminmaxtable)) != NULL)) minmaxtable = ftp->ftable; else return NOTOK; } if ((int) *p->iexptable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->iexptable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iexptable)) != NULL)) exptable = ftp->ftable; else return NOTOK; } if ((int) *p->itypetable > 0) { - if (LIKELY((ftp = csound->FTFind(csound, p->itypetable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->itypetable)) != NULL)) typetable = ftp->ftable; else return NOTOK; } @@ -4591,8 +4801,8 @@ max = minmaxtable[j*2+1]; } else { - min = FL(0.0); - max = FL(1.0); + min = MYFLT(0.0); + max = MYFLT(1.0); } int iexp; @@ -4624,7 +4834,7 @@ case EXP_ : //exponential if (UNLIKELY(min == 0 || max == 0)) return - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLvslidBnk: zero is illegal " "in exponential operations")); range = max - min; @@ -4651,7 +4861,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if (LIKELY((ftp = csound->FTFind(csound, &fnum)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, &fnum)) != NULL)) p->slider_data[j].table = ftp->ftable; else return NOTOK; p->slider_data[j].tablen = ftp->flen; @@ -4685,16 +4895,26 @@ return OK; } + static int fl_vertical_slider_bank(CSOUND *csound, FLSLIDERBANK *p){ + return fl_vertical_slider_bank_(csound,p,0); + } - static int fl_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p) + static int fl_vertical_slider_bank_S(CSOUND *csound, FLSLIDERBANK *p){ + return fl_vertical_slider_bank_(csound,p,1); + } + + + static int fl_slider_bank2_(CSOUND *csound, FLSLIDERBANK2 *p, int istring) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); char s[MAXNAME]; bool plastic = false; - if (p->XSTRCODE) - strcpy(s, (char*) p->names); - else if ((long) *p->names <= csound->strsmax && - csound->strsets != NULL && csound->strsets[(long) *p->names]) { - strcpy(s, csound->strsets[(long) *p->names]); + if (istring) + strcpy(s, ((STRINGDAT*) p->names)->data); + else if ((long) *p->names <= csound->GetStrsmax(csound) && + csound->GetStrsets(csound,(long) *p->names)) { + strcpy(s, csound->GetStrsets(csound,(long) *p->names)); } string tempname(s); stringstream sbuf; @@ -4708,22 +4928,24 @@ FUNC *ftp; MYFLT *configtable, *outable; + MYFLT *zkstart; + int zklast = csound->GetZakBounds(csound, &zkstart); if (*p->ioutable < 1) { - if (LIKELY(csound->zkstart != NULL && - csound->zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) - outable = csound->zkstart + (long) *p->ioutablestart_ndx; + if (LIKELY(zkstart != NULL && + zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) + outable = zkstart + (long) *p->ioutablestart_ndx; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("invalid ZAK space allocation")); } } else { - if ((ftp = csound->FTFind(csound, p->ioutable)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL) outable = ftp->ftable + (long) *p->ioutablestart_ndx; else return NOTOK; } - if((ftp = csound->FTFind(csound, p->iconfigtable)) != NULL) + if((ftp = csound->FTnp2Find(csound, p->iconfigtable)) != NULL) configtable = ftp->ftable; else return NOTOK; @@ -4751,7 +4973,7 @@ slider_type = slider_type - 20; } if (UNLIKELY(slider_type > 10 && iexp == EXP_)) { - csound->Warning(csound, "%s", + csound->Warning(csound, Str("FLslider exponential, using non-labeled slider")); slider_type -= 10; } @@ -4802,7 +5024,7 @@ case EXP_ : //exponential if (UNLIKELY(min == 0 || max == 0)) return - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLsliderBank: zero is illegal " "in exponential operations")); range = max - min; @@ -4829,7 +5051,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) p->slider_data[j].table = ftp->ftable; else return NOTOK; p->slider_data[j].tablen = ftp->flen; @@ -4864,16 +5086,25 @@ return OK; } + static int fl_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p){ + return fl_slider_bank2_(csound, p,0); + } + + static int fl_slider_bank2_S(CSOUND *csound, FLSLIDERBANK2 *p){ + return fl_slider_bank2_(csound, p,1); + } - static int fl_vertical_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p) + static int fl_vertical_slider_bank2_(CSOUND *csound, FLSLIDERBANK2 *p, int istring) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); char s[MAXNAME]; bool plastic = false; - if (p->XSTRCODE) - strcpy(s, (char*) p->names); - else if ((long) *p->names <= csound->strsmax && - csound->strsets != NULL && csound->strsets[(long) *p->names]) { - strcpy(s, csound->strsets[(long) *p->names]); + if (istring) + strcpy(s, ((STRINGDAT*) p->names)->data); + else if ((long) *p->names <= csound->GetStrsmax(csound) && + csound->GetStrsets(csound,(long) *p->names)) { + strcpy(s, csound->GetStrsets(csound,(long) *p->names)); } string tempname(s); stringstream sbuf; @@ -4887,22 +5118,24 @@ FUNC *ftp; MYFLT *configtable, *outable; + MYFLT *zkstart; + int zklast = csound->GetZakBounds(csound, &zkstart); if (*p->ioutable < 1) { - if (LIKELY(csound->zkstart != NULL && - csound->zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) - outable = csound->zkstart + (long) *p->ioutablestart_ndx; + if (LIKELY(zkstart != NULL && + zklast>(long)(*p->inumsliders + *p->ioutablestart_ndx))) + outable = zkstart + (long) *p->ioutablestart_ndx; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("invalid ZAK space allocation")); } } else { - if ((ftp = csound->FTFind(csound, p->ioutable)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->ioutable)) != NULL) outable = ftp->ftable + (long) *p->ioutablestart_ndx; else return NOTOK; } - if((ftp = csound->FTFind(csound, p->iconfigtable)) != NULL) + if((ftp = csound->FTnp2Find(csound, p->iconfigtable)) != NULL) configtable = ftp->ftable; else return NOTOK; @@ -4931,7 +5164,7 @@ slider_type -= 20; } if (UNLIKELY(slider_type > 10 && iexp == EXP_)) { - csound->Warning(csound, "%s", + csound->Warning(csound, Str("FLslidBnk2: FLslider exponential, " "using non-labeled slider")); slider_type -= 10; @@ -4982,7 +5215,7 @@ case EXP_ : //exponential if (UNLIKELY(min == 0 || max == 0)) return - csound->InitError(csound, "%s", + csound->InitError(csound, Str("FLsliderBank: zero is illegal " "in exponential operations")); range = max - min; @@ -5009,7 +5242,7 @@ { FUNC *ftp; MYFLT fnum = abs(iexp); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) p->slider_data[j].table = ftp->ftable; else return NOTOK; p->slider_data[j].tablen = ftp->flen; @@ -5045,9 +5278,21 @@ return OK; } + static int fl_vertical_slider_bank2(CSOUND *csound, FLSLIDERBANK2 *p){ + return fl_vertical_slider_bank2_(csound,p,0); + } + + static int fl_vertical_slider_bank2_S(CSOUND *csound, FLSLIDERBANK2 *p){ + return fl_vertical_slider_bank2_(csound,p,1); + } + + + static int fl_slider_bank_getHandle(CSOUND *csound, FLSLDBNK_GETHANDLE *p) //valid only if called immediately after FLslidBnk { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); *p->ihandle = ST(last_sldbnk); return OK; } @@ -5059,29 +5304,31 @@ int numslid = (int)*p->numSlid; int startInd = (int)*p->startInd; int startSlid = (int)*p->startSlid; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) table = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSet: invalid table number")); } // *startInd, *startSlid, *numSlid if (UNLIKELY( ftp->flen < startInd + numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSet: table too short!")); } FLSLIDERBANK *q = (FLSLIDERBANK *)ST(AddrSetValue)[ (int) *p->ihandle].opcode; - if (LIKELY((ftp = csound->FTFind(csound, q->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, q->ioutable)) != NULL)) outable = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSet: invalid outable number")); } if (numslid == 0) numslid = (int)(q->elements - *p->startSlid); if (UNLIKELY( q->elements > startSlid + numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSet: too many sliders to reset!")); } for (int j = startSlid, k = startInd; j< numslid + startSlid; j++, k++) { @@ -5105,7 +5352,7 @@ } break; default: - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSet: " "function mapping not available")); } @@ -5125,31 +5372,33 @@ int numslid = (int)*p->numSlid; int startInd = (int)*p->startInd; int startSlid = (int)*p->startSlid; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) table = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSet: invalid table number")); } // *startInd, *startSlid, *numSlid if (UNLIKELY( ftp->flen < startInd + numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSet: table too short!")); } FLSLIDERBANK2 *q = (FLSLIDERBANK2 *)ST(AddrSetValue)[ (int) *p->ihandle].opcode; - if (LIKELY((ftp = csound->FTFind(csound, q->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, q->ioutable)) != NULL)) outable = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSet: invalid outable number")); } if (numslid == 0) numslid = (int)(q->elements - *p->startSlid); if (UNLIKELY( q->elements > startSlid + numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSet: too many sliders to reset!")); } @@ -5177,7 +5426,7 @@ { // val = table[k]; if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, "%s", + csound->PerfError(csound, p->h.insdshead, Str("FLslidBnk2Setk: value out of range: " "function mapping requires a 0 to 1 " "range for input")); @@ -5203,30 +5452,32 @@ p->numslid = (int)*p->numSlid; p->startind = (int)*p->startInd; p->startslid = (int)*p->startSlid; + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->table = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSetk: invalid table number")); } // *startInd, *startSlid, *numSlid if (UNLIKELY( ftp->flen < p->startind + p->numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk: table too short!")); } p->q = (FLSLIDERBANK2 *) ST(AddrSetValue)[ (int) *p->ihandle].opcode; - if (LIKELY((ftp = csound->FTFind(csound, p->q->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->q->ioutable)) != NULL)) p->outable = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLsldBnkSetk: invalid outable number")); } if (p->numslid == 0) p->numslid = p->q->elements - p->startslid; if (UNLIKELY( p->q->elements < p->startslid + p->numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk: too many sliders to reset!")); } return OK; @@ -5236,6 +5487,8 @@ static int fl_slider_bank2_setVal_k(CSOUND *csound, FLSLDBNK2_SETK *p) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); if(*p->kflag) { FLSLIDERBANK2 *q = p->q; MYFLT *table=p->table; @@ -5265,7 +5518,7 @@ { val = table[k]; if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, "%s", + csound->PerfError(csound, p->h.insdshead, Str("FLslidBnk2Setk: value out of range:" " function mapping requires a 0 to 1" " range for input")); @@ -5287,34 +5540,35 @@ static int fl_slider_bank_setVal_k_set(CSOUND *csound, FLSLDBNK_SETK *p) { FUNC* ftp; - + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *)csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); p->numslid = (int)*p->numSlid; p->startind = (int)*p->startInd; p->startslid = (int)*p->startSlid; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->table = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk: invalid table number")); } // *startInd, *startSlid, *numSlid if (UNLIKELY( ftp->flen < p->startind + p->numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk: table too short!")); } p->q = (FLSLIDERBANK *) ST(AddrSetValue)[ (int) *p->ihandle].opcode; - if (LIKELY((ftp = csound->FTFind(csound, p->q->ioutable)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->q->ioutable)) != NULL)) p->outable = ftp->ftable; else { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk: invalid outable number")); } if (p->numslid == 0) p->numslid = p->q->elements - p->startslid; if (UNLIKELY( p->q->elements < p->startslid + p->numslid)) { - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLslidBnkSetk:" " too many sliders to reset!")); } @@ -5325,7 +5579,9 @@ static int fl_slider_bank_setVal_k(CSOUND *csound, FLSLDBNK_SETK *p) { - if(*p->kflag) { + WIDGET_GLOBALS *widgetGlobals = + (WIDGET_GLOBALS *) csound->QueryGlobalVariable(csound, "WIDGET_GLOBALS"); + if (*p->kflag) { FLSLIDERBANK *q = p->q; MYFLT *table=p->table; for (int j = p->startslid, k = p->startind; @@ -5354,7 +5610,7 @@ { val = table[k]; if (UNLIKELY(val < 0 || val > 1)) { // input range must be 0 to 1 - csound->PerfError(csound, "%s", + csound->PerfError(csound, p->h.insdshead, Str("FLslidBnk2Setk: value out of range: " "function mapping requires a 0 to 1 range " "for input")); @@ -5375,6 +5631,7 @@ static int FLxyin_set(CSOUND *csound, FLXYIN *p) { + *p->koutx = *p->ioutx; //initial values *p->kouty = *p->iouty; p->rangex = *p->ioutx_max - *p->ioutx_min; @@ -5387,7 +5644,6 @@ p->expx = EXP_; if (UNLIKELY(*p->ioutx_min == 0 || *p->ioutx_max==0)) return csound->InitError(csound, - "%s", Str("FLxyin: none of X limits can be zero in" " exponential mode!")); p->basex = pow((double) (*p->ioutx_max / *p->ioutx_min), @@ -5399,7 +5655,7 @@ { FUNC *ftp; MYFLT fnum = abs(p->expx); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->tablex = ftp->ftable; p->tablenx = ftp->flen; } @@ -5414,7 +5670,7 @@ case -1: // EXP p->expy = EXP_; if (UNLIKELY(*p->iouty_min == 0 || *p->iouty_max==0)) - return csound->InitError(csound, "%s", + return csound->InitError(csound, Str("FLxyin: none of Y limits can " "be zero in exponential mode!")); p->basey = pow((double) (*p->iouty_max / *p->iouty_min), @@ -5425,7 +5681,7 @@ { FUNC *ftp; MYFLT fnum = abs(p->expy); - if ((ftp = csound->FTFind(csound, &fnum)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, &fnum)) != NULL) { p->tabley = ftp->ftable; p->tableny = ftp->flen; } @@ -5578,7 +5834,7 @@ // int nchnls = csound->nchnls; // int n = (csound->oparms->sfread) ? nchnls * 2 : nchnls; // MYFLT temp[MAXCHNLS]; - // int smps = csound->ksmps; + // int smps = csound->GetKsmps(csound); // MYFLT max[MAXCHNLS]; // MYFLT *spo = csound->spout; // MYFLT *spi = csound->spin; @@ -5640,149 +5896,157 @@ #define S(x) sizeof(x) const OENTRY widgetOpcodes_[] = { - { (char*)"FLslider", S(FLSLIDER), 1, (char*)"ki", (char*)"Tiijjjjjjj", + { (char*)"FLslider", S(FLSLIDER), 0, 1, (char*)"ki", (char*)"Siijjjjjjj", (SUBR) fl_slider, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk", S(FLSLIDERBANK), 1, (char*)"", (char*)"Tiooooooooo", + { (char*)"FLslidBnk", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"Siooooooooo", + (SUBR) fl_slider_bank_S, (SUBR) NULL, (SUBR) NULL }, + { (char*)"FLslidBnk.i", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"iiooooooooo", (SUBR) fl_slider_bank, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLknob", S(FLKNOB), 1, (char*)"ki", (char*)"Tiijjjjjjo", + { (char*)"FLknob", S(FLKNOB), 0, 1, (char*)"ki", (char*)"Siijjjjjjo", (SUBR) fl_knob, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLroller", S(FLROLLER), 1, (char*)"ki", (char*)"Tiijjjjjjjj", + { (char*)"FLroller", S(FLROLLER), 0, 1, (char*)"ki", (char*)"Siijjjjjjjj", (SUBR) fl_roller, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtext", S(FLTEXT), 1, (char*)"ki", (char*)"Tiijjjjjj", + { (char*)"FLtext", S(FLTEXT), 0, 1, (char*)"ki", (char*)"Siijjjjjj", (SUBR) fl_text, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLjoy", S(FLJOYSTICK), 1, (char*)"kkii", (char*)"Tiiiijjjjjjjj", + { (char*)"FLjoy", S(FLJOYSTICK), 0, 1, (char*)"kkii", (char*)"Siiiijjjjjjjj", (SUBR) fl_joystick, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcount", S(FLCOUNTER), 1, (char*)"ki", (char*)"Tiiiiiiiiiz", + { (char*)"FLcount", S(FLCOUNTER), 0, 1, (char*)"ki", (char*)"Siiiiiiiiiz", (SUBR) fl_counter, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbutton", S(FLBUTTON), 1, (char*)"ki", (char*)"Tiiiiiiiz", + { (char*)"FLbutton", S(FLBUTTON), 0, 1, (char*)"ki", (char*)"Siiiiiiiz", (SUBR) fl_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbutBank", S(FLBUTTONBANK), 1, (char*)"ki", (char*)"iiiiiiiz", + { (char*)"FLbutBank", S(FLBUTTONBANK), 0, 1, (char*)"ki", (char*)"iiiiiiiz", (SUBR) fl_button_bank, (SUBR) NULL, (SUBR) NULL }, - // { (char*)"FLkeyb", S(FLKEYB), 1, (char*)"k", (char*)"z", + // { (char*)"FLkeyb", S(FLKEYB), 0, 1, (char*)"k", (char*)"z", // (SUBR) FLkeyb, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcolor", S(FLWIDGCOL), 1, (char*)"", (char*)"jjjjjj", + { (char*)"FLcolor", S(FLWIDGCOL), 0, 1, (char*)"", (char*)"jjjjjj", (SUBR) fl_widget_color, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLcolor2", S(FLWIDGCOL2), 1, (char*)"", (char*)"jjj", + { (char*)"FLcolor2", S(FLWIDGCOL2), 0, 1, (char*)"", (char*)"jjj", (SUBR) fl_widget_color2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLlabel", S(FLWIDGLABEL), 1, (char*)"", (char*)"ojojjj", + { (char*)"FLlabel", S(FLWIDGLABEL), 0, 1, (char*)"", (char*)"ojojjj", (SUBR) fl_widget_label, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVal_i", S(FL_SET_WIDGET_VALUE_I), 1, (char*)"", (char*)"ii", + { (char*)"FLsetVal_i", S(FL_SET_WIDGET_VALUE_I), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setWidgetValuei, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVali", S(FL_SET_WIDGET_VALUE_I), 1, (char*)"", (char*)"ii", + { (char*)"FLsetVali", S(FL_SET_WIDGET_VALUE_I), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setWidgetValuei, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetVal", S(FL_SET_WIDGET_VALUE), 3, (char*)"", (char*)"kki", + { (char*)"FLsetVal", S(FL_SET_WIDGET_VALUE),0, 3, (char*)"", (char*)"kki", (SUBR) fl_setWidgetValue_set, (SUBR) fl_setWidgetValue, (SUBR) NULL }, - { (char*)"FLsetColor", S(FL_SET_COLOR), 1, (char*)"", (char*)"iiii", + { (char*)"FLsetColor", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", (SUBR) fl_setColor1, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetColor2", S(FL_SET_COLOR), 1, (char*)"", (char*)"iiii", + { (char*)"FLsetColor2", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", (SUBR) fl_setColor2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextSize", S(FL_SET_TEXTSIZE), 1, (char*)"", (char*)"ii", + { (char*)"FLsetTextSize", S(FL_SET_TEXTSIZE), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setTextSize, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextColor", S(FL_SET_COLOR), 1, (char*)"", (char*)"iiii", + { (char*)"FLsetTextColor", S(FL_SET_COLOR), 0, 1, (char*)"", (char*)"iiii", (SUBR) fl_setTextColor, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetFont", S(FL_SET_FONT), 1, (char*)"", (char*)"ii", + { (char*)"FLsetFont", S(FL_SET_FONT), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setFont, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetTextType", S(FL_SET_FONT), 1, (char*)"", (char*)"ii", + { (char*)"FLsetTextType", S(FL_SET_FONT), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setTextType, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetText", S(FL_SET_TEXT), 1, (char*)"", (char*)"Ti", + { (char*)"FLsetText", S(FL_SET_TEXT), 0, 1, (char*)"", (char*)"Ti", (SUBR) fl_setText, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetSize", S(FL_SET_SIZE), 1, (char*)"", (char*)"iii", + { (char*)"FLsetSize", S(FL_SET_SIZE), 0, 1, (char*)"", (char*)"iii", (SUBR) fl_setSize, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetPosition", S(FL_SET_POSITION), 1, (char*)"", (char*)"iii", + { (char*)"FLsetPosition", S(FL_SET_POSITION), 0, 1, (char*)"", (char*)"iii", (SUBR) fl_setPosition, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLhide", S(FL_WIDHIDE), 1, (char*)"", (char*)"i", + { (char*)"FLhide", S(FL_WIDHIDE), 0, 1, (char*)"", (char*)"i", (SUBR) fl_hide, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLshow", S(FL_WIDSHOW), 1, (char*)"", (char*)"i", + { (char*)"FLshow", S(FL_WIDSHOW), 0, 1, (char*)"", (char*)"i", (SUBR) fl_show, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetBox", S(FL_SETBOX), 1, (char*)"", (char*)"ii", + { (char*)"FLsetBox", S(FL_SETBOX), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_setBox, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetAlign", S(FL_TALIGN), 1, (char*)"", (char*)"ii", + { (char*)"FLsetAlign", S(FL_TALIGN), 0, 1, (char*)"", (char*)"ii", (SUBR) fl_align, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLbox", S(FL_BOX), 1, (char*)"i", (char*)"Tiiiiiii", + { (char*)"FLbox", S(FL_BOX), 0, 1, (char*)"i", (char*)"Siiiiiii", (SUBR) fl_box_, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvalue", S(FLVALUE), 1, (char*)"i", (char*)"Tjjjj", + { (char*)"FLvalue", S(FLVALUE), 0, 1, (char*)"i", (char*)"Sjjjj", (SUBR) fl_value, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanel", S(FLPANEL), 1, (char*)"", (char*)"Tjjjoooo", + { (char*)"FLpanel", S(FLPANEL), 0, 1, (char*)"", (char*)"Sjjjoooo", (SUBR) StartPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanelEnd", S(FLPANELEND), 1, (char*)"", (char*)"", + { (char*)"FLpanelEnd", S(FLPANELEND), 0, 1, (char*)"", (char*)"", (SUBR) EndPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpanel_end", S(FLPANELEND), 1, (char*)"", (char*)"", + { (char*)"FLpanel_end", S(FLPANELEND), 0, 1, (char*)"", (char*)"", (SUBR) EndPanel, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscroll", S(FLSCROLL), 1, (char*)"", (char*)"iiii", + { (char*)"FLscroll", S(FLSCROLL), 0, 1, (char*)"", (char*)"iiii", (SUBR) StartScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscrollEnd", S(FLSCROLLEND), 1, (char*)"", (char*)"", + { (char*)"FLscrollEnd", S(FLSCROLLEND), 0, 1, (char*)"", (char*)"", (SUBR) EndScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLscroll_end",S(FLSCROLLEND), 1, (char*)"", (char*)"", + { (char*)"FLscroll_end",S(FLSCROLLEND), 0, 1, (char*)"", (char*)"", (SUBR) EndScroll, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpack", S(FLPACK), 1, (char*)"", (char*)"iiiiooo", + { (char*)"FLpack", S(FLPACK), 0, 1, (char*)"", (char*)"iiiiooo", (SUBR) StartPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpackEnd", S(FLPACKEND), 1, (char*)"", (char*)"", + { (char*)"FLpackEnd", S(FLPACKEND), 0, 1, (char*)"", (char*)"", (SUBR) EndPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLpack_end", S(FLPACKEND), 1, (char*)"", (char*)"", + { (char*)"FLpack_end", S(FLPACKEND), 0, 1, (char*)"", (char*)"", (SUBR) EndPack, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabs", S(FLTABS), 1, (char*)"", (char*)"iiii", + { (char*)"FLtabs", S(FLTABS), 0, 1, (char*)"", (char*)"iiii", (SUBR) StartTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabsEnd", S(FLTABSEND), 1, (char*)"", (char*)"", + { (char*)"FLtabsEnd", S(FLTABSEND), 0, 1, (char*)"", (char*)"", (SUBR) EndTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLtabs_end", S(FLTABSEND), 1, (char*)"", (char*)"", + { (char*)"FLtabs_end", S(FLTABSEND), 0, 1, (char*)"", (char*)"", (SUBR) EndTabs, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroup", S(FLGROUP), 1, (char*)"", (char*)"Tiiiij", + { (char*)"FLgroup", S(FLGROUP), 0, 1, (char*)"", (char*)"Siiiij", (SUBR) StartGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroupEnd", S(FLGROUPEND), 1, (char*)"", (char*)"", + { (char*)"FLgroupEnd", S(FLGROUPEND), 0, 1, (char*)"", (char*)"", (SUBR) EndGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgroup_end", S(FLGROUPEND), 1, (char*)"", (char*)"", + { (char*)"FLgroup_end", S(FLGROUPEND), 0, 1, (char*)"", (char*)"", (SUBR) EndGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetsnap", S(FLSETSNAP), 1, (char*)"ii", (char*)"ioo", + { (char*)"FLsetsnap", S(FLSETSNAP), 0, 1, (char*)"ii", (char*)"ioo", (SUBR) set_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsetSnapGroup", S(FLSETSNAPGROUP), 1, (char*)"", (char*)"i", + { (char*)"FLsetSnapGroup", S(FLSETSNAPGROUP), 0, 1, (char*)"", (char*)"i", (SUBR)fl_setSnapGroup, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLgetsnap", S(FLGETSNAP), 1, (char*)"i", (char*)"io", + { (char*)"FLgetsnap", S(FLGETSNAP), 0, 1, (char*)"i", (char*)"io", (SUBR) get_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLsavesnap", S(FLSAVESNAPS), 1, (char*)"", (char*)"To", + { (char*)"FLsavesnap", S(FLSAVESNAPS), 0, 1, (char*)"", (char*)"So", (SUBR) save_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLloadsnap", S(FLLOADSNAPS), 1, (char*)"", (char*)"To", + { (char*)"FLloadsnap", S(FLLOADSNAPS), 0, 1, (char*)"", (char*)"So", (SUBR) load_snap, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLrun", S(FLRUN), 1, (char*)"", (char*)"", + { (char*)"FLrun", S(FLRUN), 0, 1, (char*)"", (char*)"", (SUBR) FL_run, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLupdate", S(FLRUN), 1, (char*)"", (char*)"", + { (char*)"FLupdate", S(FLRUN), 0, 1, (char*)"", (char*)"", (SUBR) fl_update, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLprintk", S(FLPRINTK), 3, (char*)"", (char*)"iki", + { (char*)"FLprintk", S(FLPRINTK), 0, 3, (char*)"", (char*)"iki", (SUBR) FLprintkset, (SUBR) FLprintk, (SUBR) NULL }, - { (char*)"FLprintk2", S(FLPRINTK2), 3, (char*)"", (char*)"ki", + { (char*)"FLprintk2", S(FLPRINTK2), 0, 3, (char*)"", (char*)"ki", (SUBR) FLprintk2set, (SUBR) FLprintk2, (SUBR) NULL }, - { (char*)"FLcloseButton", S(FLCLOSEBUTTON), 1, (char*)"i", (char*)"Tiiii", + { (char*)"FLcloseButton", S(FLCLOSEBUTTON), 0, 1, (char*)"i", (char*)"Siiii", (SUBR) fl_close_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLexecButton", S(FLEXECBUTTON), 1, (char*)"i", (char*)"Tiiii", + { (char*)"FLexecButton", S(FLEXECBUTTON), 0, 1, (char*)"i", (char*)"Siiii", (SUBR) fl_exec_button, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLkeyIn", S(FLKEYIN), 3, (char*)"k", (char*)"o", + { (char*)"FLkeyIn", S(FLKEYIN), 0, 3, (char*)"k", (char*)"o", (SUBR)fl_keyin_set, (SUBR)fl_keyin, (SUBR) NULL }, - { (char*)"FLxyin", S(FLXYIN), 3, (char*)"kkk",(char*)"iiiiiiiioooo", + { (char*)"FLxyin", S(FLXYIN), 0, 3, (char*)"kkk",(char*)"iiiiiiiioooo", (SUBR)FLxyin_set, (SUBR)FLxyin, (SUBR) NULL }, - { (char*)"FLmouse", S(FLMOUSE), 3, (char*)"kkkkk",(char*)"o", + { (char*)"FLmouse", S(FLMOUSE), 0, 3, (char*)"kkkkk",(char*)"o", (SUBR)fl_mouse_set, (SUBR)fl_mouse, (SUBR) NULL }, - { (char*)"FLvslidBnk", S(FLSLIDERBANK), 1, (char*)"", (char*)"Siooooooooo", + { (char*)"FLvslidBnk", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"Siooooooooo", + (SUBR)fl_vertical_slider_bank_S, (SUBR) NULL, (SUBR) NULL }, + { (char*)"FLvslidBnk.i", S(FLSLIDERBANK), 0, 1, (char*)"", (char*)"iiooooooooo", (SUBR)fl_vertical_slider_bank, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk2", S(FLSLIDERBANK2),1, (char*)"", (char*)"Siiiooooo", + { (char*)"FLslidBnk2", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"Siiiooooo", + (SUBR)fl_slider_bank2_S , (SUBR) NULL, (SUBR) NULL }, + { (char*)"FLslidBnk2.i", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"Iiiiooooo", (SUBR)fl_slider_bank2 , (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLvslidBnk2", S(FLSLIDERBANK2),1, (char*)"", (char*)"Siiiooooo", + { (char*)"FLvslidBnk2", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"Siiiooooo", + (SUBR)fl_vertical_slider_bank2_S, (SUBR) NULL, (SUBR) NULL }, + { (char*)"FLvslidBnk2.i", S(FLSLIDERBANK2),0, 1, (char*)"", (char*)"iiiiooooo", (SUBR)fl_vertical_slider_bank2, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkGetHandle",S(FLSLDBNK_GETHANDLE),1, (char*)"i", (char*)"", + { (char*)"FLslidBnkGetHandle",S(FLSLDBNK_GETHANDLE),0, 1, (char*)"i", (char*)"", (SUBR)fl_slider_bank_getHandle, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkSet",S(FLSLDBNK_SET), 1, (char*)"", (char*)"iiooo", + { (char*)"FLslidBnkSet",S(FLSLDBNK_SET), 0, 1, (char*)"", (char*)"iiooo", (SUBR)fl_slider_bank_setVal, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnkSetk", S(FLSLDBNK2_SETK), 3, (char*)"", (char*)"kiiooo", + { (char*)"FLslidBnkSetk", S(FLSLDBNK2_SETK), 0, 3, (char*)"", (char*)"kiiooo", (SUBR)fl_slider_bank_setVal_k_set,(SUBR)fl_slider_bank_setVal_k,(SUBR) NULL }, - { (char*)"FLslidBnk2Set", S(FLSLDBNK_SET), 1, (char*)"", (char*)"iiooo", + { (char*)"FLslidBnk2Set", S(FLSLDBNK_SET), 0, 1, (char*)"", (char*)"iiooo", (SUBR)fl_slider_bank2_setVal, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLslidBnk2Setk", S(FLSLDBNK2_SETK), 3, (char*)"", (char*)"kiiooo", + { (char*)"FLslidBnk2Setk", S(FLSLDBNK2_SETK), 0, 3, (char*)"", (char*)"kiiooo", (SUBR)fl_slider_bank2_setVal_k_set, (SUBR)fl_slider_bank2_setVal_k, (SUBR) NULL }, - { (char*)"FLhvsBox", S(FL_HVSBOX), 1, (char*)"i", (char*)"iiiiiio", + { (char*)"FLhvsBox", S(FL_HVSBOX), 0, 1, (char*)"i", (char*)"iiiiiio", (SUBR)fl_hvsbox, (SUBR) NULL, (SUBR) NULL }, - { (char*)"FLhvsBoxSetValue",S(FL_SET_HVS_VALUE), 3, (char*)"", (char*)"kki", + { (char*)"FLhvsBoxSetValue",S(FL_SET_HVS_VALUE), 0, 3, (char*)"", (char*)"kki", (SUBR)fl_setHvsValue_set, (SUBR)fl_setHvsValue, (SUBR) NULL }, - // { (char*)"FLmeter", S(FLTKMETER), 1, (char*)"", (char*)"", + // { (char*)"FLmeter", S(FLTKMETER), 0, 1, (char*)"", (char*)"", // (SUBR)VuMeter_set, (SUBR) NULL, (SUBR) NULL }, - { NULL, 0, 0, NULL, NULL, + { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } }; diff -Nru csound-5.17.11~dfsg/InOut/widgets.h csound-6.02~dfsg/InOut/widgets.h --- csound-5.17.11~dfsg/InOut/widgets.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/widgets.h 2014-01-07 16:53:47.000000000 +0000 @@ -30,7 +30,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *imin, *imax, *iexp; + MYFLT *kout, *ihandle; + STRINGDAT *name; + MYFLT *imin, *imax, *iexp; MYFLT *itype, *idisp, *iwidth, *iheight, *ix, *iy; MYFLT min, base, *table; long tablen; @@ -50,7 +52,8 @@ typedef struct { OPDS h; - MYFLT *names, *inumsliders, *ioutable, *iwidth, *iheight; + MYFLT *names; + MYFLT *inumsliders, *ioutable, *iwidth, *iheight; MYFLT *ix, *iy, *itypetable, *iexptable, *ioutablestart_ndx; MYFLT *iminmaxtable; SLDBK_ELEMENT slider_data[MAXSLIDERBANK]; @@ -59,7 +62,8 @@ typedef struct { OPDS h; - MYFLT *names, *inumsliders, *ioutable, *iconfigtable, *iwidth, + MYFLT *names; + MYFLT *inumsliders, *ioutable, *iconfigtable, *iwidth, *iheight, *ix, *iy, *ioutablestart_ndx; SLDBK_ELEMENT slider_data[MAXSLIDERBANK]; long elements; @@ -78,7 +82,8 @@ typedef struct { OPDS h; MYFLT *koutx, *kouty, *ihandle1, *ihandle2; - MYFLT *name, *iminx, *imaxx, *iminy, *imaxy; + STRINGDAT *name; + MYFLT *iminx, *imaxx, *iminy, *imaxy; MYFLT *iexpx, *iexpy, *idispx, *idispy, *iwidth, *iheight, *ix, *iy; MYFLT basex, basey, *tablex, *tabley; long tablenx, tableny; @@ -86,7 +91,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *imin, *imax, *istep, *iexp; + MYFLT *kout, *ihandle; + STRINGDAT *name; +MYFLT *imin, *imax, *istep, *iexp; MYFLT *itype, *idisp, *iwidth, *iheight, *ix, *iy; MYFLT min, base, *table; long tablen; @@ -94,7 +101,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *imin, *imax, *iexp, *itype; + MYFLT *kout, *ihandle; + STRINGDAT *name; +MYFLT *imin, *imax, *iexp, *itype; MYFLT *idisp, *iwidth, *ix, *iy, *icursorsize; MYFLT min, base, *table; long tablen; @@ -102,7 +111,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *imin, *imax, *istep, *itype; + MYFLT *kout, *ihandle; + STRINGDAT *name; +MYFLT *imin, *imax, *istep, *itype; MYFLT *iwidth, *iheight, *ix, *iy; } FLTEXT; @@ -155,7 +166,8 @@ typedef struct { OPDS h; - MYFLT *itext, *ihandle; + STRINGDAT *itext; + MYFLT *ihandle; } FL_SET_TEXT; typedef struct { @@ -190,7 +202,9 @@ typedef struct { OPDS h; - MYFLT *ihandle, *itext, *itype, *ifont, *isize; + MYFLT *ihandle; + STRINGDAT *itext; + MYFLT *itype, *ifont, *isize; MYFLT *iwidth, *iheight, *ix, *iy; } FL_BOX; @@ -198,7 +212,9 @@ typedef struct { OPDS h; - MYFLT *ihandle, *name, *iwidth, *iheight, *ix, *iy; + MYFLT *ihandle; + STRINGDAT *name; + MYFLT *iwidth, *iheight, *ix, *iy; } FLVALUE; typedef struct { @@ -207,7 +223,8 @@ typedef struct { OPDS h; - MYFLT *name, *iwidth, *iheight, *ix, *iy, *border, *ikbdsense, *iclose; + STRINGDAT *name; + MYFLT *iwidth, *iheight, *ix, *iy, *border, *ikbdsense, *iclose; } FLPANEL; typedef struct { @@ -222,12 +239,14 @@ typedef struct { OPDS h; - MYFLT *filename, *group; + STRINGDAT *filename; + MYFLT *group; } FLSAVESNAPS; typedef struct { OPDS h; - MYFLT *filename, *group; + STRINGDAT *filename; + MYFLT *group; } FLLOADSNAPS; typedef struct { @@ -254,7 +273,8 @@ typedef struct { OPDS h; - MYFLT *name, *iwidth, *iheight, *ix, *iy, *border; + STRINGDAT *name; + MYFLT *iwidth, *iheight, *ix, *iy, *border; } FLGROUP; typedef struct { @@ -272,7 +292,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *ion, *ioff, *itype; + MYFLT *kout, *ihandle; + STRINGDAT *name; + MYFLT *ion, *ioff, *itype; MYFLT *iwidth, *iheight, *ix, *iy, *args[PMAX]; } FLBUTTON; @@ -284,7 +306,9 @@ typedef struct { OPDS h; - MYFLT *kout, *ihandle, *name, *imin, *imax, *istep1, *istep2, *itype; + MYFLT *kout, *ihandle; + STRINGDAT *name; +MYFLT *imin, *imax, *istep1, *istep2, *itype; MYFLT *iwidth, *iheight, *ix, *iy, *args[PMAX]; } FLCOUNTER; @@ -304,13 +328,15 @@ typedef struct { OPDS h; - MYFLT *ihandle, *name; + MYFLT *ihandle; + STRINGDAT *name; MYFLT *iwidth, *iheight, *ix, *iy; } FLCLOSEBUTTON; typedef struct { OPDS h; - MYFLT *ihandle, *command; + MYFLT *ihandle; + STRINGDAT *command; MYFLT *iwidth, *iheight, *ix, *iy; char *commandString; CSOUND *csound; @@ -611,4 +637,3 @@ #endif /* CSOUND_WIDGETS_CPP */ #endif /* CSOUND_WIDGETS_H */ - diff -Nru csound-5.17.11~dfsg/InOut/widglobals.h csound-6.02~dfsg/InOut/widglobals.h --- csound-5.17.11~dfsg/InOut/widglobals.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/widglobals.h 2014-01-07 16:54:20.000000000 +0000 @@ -237,10 +237,6 @@ //GAB (MAKING snapshots_iterator GLOBAL IS A TEMPORARY UGLY HACK) vector::iterator snapshots_iterator; FLTKMETER *p_vumeter; -#ifdef CS_VSTHOST - vector VSTplugEditors; //GAB for the vst plugin custom editors - vector vstPlugins; //GAB to remove globals in VST plugins -#endif #ifdef CS_IMAGE vector Bm_image; // map of pointers to CAnyBmp objects @@ -250,4 +246,4 @@ } WIDGET_GLOBALS; } -#define ST(x) (((WIDGET_GLOBALS*) csound->widgetGlobals)->x) +#define ST(x) ((widgetGlobals)->x) diff -Nru csound-5.17.11~dfsg/InOut/winEPS.c csound-6.02~dfsg/InOut/winEPS.c --- csound-5.17.11~dfsg/InOut/winEPS.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/winEPS.c 2014-01-07 16:53:47.000000000 +0000 @@ -9,7 +9,6 @@ and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. - Csound is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -99,13 +98,17 @@ char pathnam[1024]; char *t; time_t lt; + OPARMS oparms; + csound->GetOParms(csound, &oparms); + IGN(wdptr); + IGN(name); if (csound->winEPS_globals != NULL) return; csound->winEPS_globals = csound->Calloc(csound, sizeof(winEPS_globals_t)); pp = (winEPS_globals_t *) csound->winEPS_globals; - filenam = csound->oparms->outfilename; + filenam = oparms.outfilename; if (filenam == NULL) filenam = "test"; /* O.outfilename not set yet */ @@ -224,8 +227,8 @@ * Write characters */ - sprintf(cmin, "%g", *min); - sprintf(cmax, "%g", *max); + CS_SPRINTF(cmin, "%g", *min); + CS_SPRINTF(cmax, "%g", *max); } static void PS_drawAxes(winEPS_globals_t *pp, @@ -360,7 +363,7 @@ //xmin = FL(0.0); /* xmax = FL(1.0) * wdptr->npts; */ sprintf(cxmin, "%d", 0); - sprintf(cxmax, "%ld", wdptr->npts); + sprintf(cxmax, "%ld", (long)wdptr->npts); ymin = wdptr->min; ymax = wdptr->max; diff -Nru csound-5.17.11~dfsg/InOut/winFLTK.c csound-6.02~dfsg/InOut/winFLTK.c --- csound-5.17.11~dfsg/InOut/winFLTK.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/winFLTK.c 2014-01-07 16:53:47.000000000 +0000 @@ -69,6 +69,8 @@ int initFlags = 0; int *fltkFlags; int enableDisplays = 0; + OPARMS oparms; + csound->GetOParms(csound, &oparms); if (csound->QueryGlobalVariable(csound, "FLTK_Flags") == (void*) 0) { @@ -80,7 +82,7 @@ } fltkFlags = getFLTKFlagsPtr(csound); if (((*fltkFlags) & 2) == 0 && - !(csound->oparms->graphsoff || csound->oparms->postscript)) { + !(oparms.graphsoff || oparms.postscript)) { #ifdef LINUX Display *dpy = XOpenDisplay(NULL); if (dpy != NULL) { @@ -97,9 +99,6 @@ csound->SetDrawGraphCallback(csound, DrawGraph_FLTK); csound->SetKillGraphCallback(csound, KillGraph_FLTK); csound->SetExitGraphCallback(csound, ExitGraph_FLTK); - csound->SetMakeXYinCallback(csound, MakeXYin_FLTK); - csound->SetReadXYinCallback(csound, ReadXYin_FLTK); - csound->SetKillXYinCallback(csound, KillXYin_FLTK); /* seemed to crash, but not anymore... */ csound->RegisterResetCallback(csound, NULL, widget_reset); csound->Message(csound, "graph init \n"); @@ -118,7 +117,7 @@ if (!((*fltkFlags) & 129)) for ( ; ep->opname != NULL; ep++) { if (csound->AppendOpcode(csound, ep->opname, - (int)ep->dsblksiz, (int)ep->thread, + (int)ep->dsblksiz, (int)ep->flags, (int)ep->thread, ep->outypes, ep->intypes, ep->iopadr, ep->kopadr, ep->aopadr) != 0) { csound->ErrorMsg(csound, Str("Error registering opcode '%s'"), @@ -129,7 +128,8 @@ else if (!((*fltkFlags) & 128)) { for ( ; ep->opname != NULL; ep++) { if (csound->AppendOpcode( - csound, ep->opname, (int)ep->dsblksiz, (int)ep->thread, + csound, ep->opname, (int)ep->dsblksiz, + (int)ep->flags,(int)ep->thread, ep->outypes, ep->intypes, (((int)ep->thread & 1) ? dummyWidgetOpcode : (SUBR) 0), (((int)ep->thread & 2) ? dummyWidgetOpcode : (SUBR) 0), diff -Nru csound-5.17.11~dfsg/InOut/winascii.c csound-6.02~dfsg/InOut/winascii.c --- csound-5.17.11~dfsg/InOut/winascii.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/winascii.c 2014-01-07 16:53:47.000000000 +0000 @@ -31,11 +31,14 @@ void MakeAscii(CSOUND *csound, WINDAT *wdptr, const char *n) { + IGN(n); + IGN(csound); wdptr->windid = ~((uintptr_t) 0); /* just so it's not null */ } void KillAscii(CSOUND *csound, WINDAT *wdptr) { + IGN(csound); wdptr->windid = 0; /* just to make out that it's dead */ } diff -Nru csound-5.17.11~dfsg/InOut/windin.c csound-6.02~dfsg/InOut/windin.c --- csound-5.17.11~dfsg/InOut/windin.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/windin.c 2014-01-07 16:54:20.000000000 +0000 @@ -26,64 +26,71 @@ #include "windin.h" /* real-time input control units */ /* 26aug90 dpwe */ -static int deinit_func(CSOUND *csound, void *p) -{ - csound->csoundKillXYinCallback_(csound, &(((XYIN*) p)->w)); - return OK; -} - int xyinset(CSOUND *csound, XYIN *p) { - MYFLT x, y; - MYFLT iymax = *p->iymax; - MYFLT iymin = *p->iymin; - MYFLT ixmax = *p->ixmax; - MYFLT ixmin = *p->ixmin; - MYFLT iyinit = *p->iyinit; - MYFLT ixinit = *p->ixinit; - - if (UNLIKELY((p->timcount = (int) (csound->ekr * *p->iprd + FL(0.5))) <= 0)) { - return csound->InitError(csound, Str("illegal iprd")); - } - if (UNLIKELY(iymin > iymax)) { /* swap if wrong order */ - y = iymin; iymin = iymax; iymax = y; - } - if (UNLIKELY(iyinit < iymin)) - iyinit = iymin; - else if (UNLIKELY(iyinit > iymax)) - iyinit = iymax; - *(p->kyrslt) = iyinit; - y = (*p->iymax != *p->iymin ? (*p->iymax - iyinit) / (*p->iymax - *p->iymin) - : FL(0.5)); - p->w.y = y; - - if (UNLIKELY(ixmin > ixmax)) { /* swap if wrong order */ - x = ixmin; ixmin = ixmax; ixmax = x; - } - if (UNLIKELY(ixinit < ixmin)) - ixinit = ixmin; - else if (UNLIKELY(ixinit > ixmax)) - ixinit = ixmax; - *(p->kxrslt) = ixinit; - x = (*p->ixmax != *p->ixmin ? (ixinit - *p->ixmin) / (*p->ixmax - *p->ixmin) - : FL(0.5)); - p->w.x = x; - - csound->csoundMakeXYinCallback_(csound, &p->w, x, y); - csound->RegisterDeinitCallback(csound, (void*) p, deinit_func); - - p->countdown = 1; /* init counter to run xyin on first call */ - return OK; + // This is not the way to do it; set _QQ in interlocks + return csound->InitError(csound, + Str("xyin opcode has been deprecated in Csound6.")); } -int xyin(CSOUND *csound, XYIN *p) -{ - if (UNLIKELY(!(--p->countdown))) { /* at each countdown */ - p->countdown = p->timcount; /* reset counter & */ - csound->csoundReadXYinCallback_(csound, &p->w); /* read cursor postn */ - *(p->kxrslt) = *p->ixmin + p->w.x * (*p->ixmax - *p->ixmin); - *(p->kyrslt) = *p->iymin + (FL(1.0) - p->w.y) * (*p->iymax - *p->iymin); - } - return OK; -} +/* static int deinit_func(CSOUND *csound, void *p) */ +/* { */ +/* csound->csoundKillXYinCallback_(csound, &(((XYIN*) p)->w)); */ +/* return OK; */ +/* } */ + +/* int xyinset(CSOUND *csound, XYIN *p) */ +/* { */ +/* MYFLT x, y; */ +/* MYFLT iymax = *p->iymax; */ +/* MYFLT iymin = *p->iymin; */ +/* MYFLT ixmax = *p->ixmax; */ +/* MYFLT ixmin = *p->ixmin; */ +/* MYFLT iyinit = *p->iyinit; */ +/* MYFLT ixinit = *p->ixinit; */ + +/* if (UNLIKELY((p->timcount = (int)(CS_EKR * *p->iprd + FL(0.5)))<=0)) { */ +/* return csound->InitError(csound, Str("illegal iprd")); */ +/* } */ +/* if (UNLIKELY(iymin > iymax)) { /\* swap if wrong order *\/ */ +/* y = iymin; iymin = iymax; iymax = y; */ +/* } */ +/* if (UNLIKELY(iyinit < iymin)) */ +/* iyinit = iymin; */ +/* else if (UNLIKELY(iyinit > iymax)) */ +/* iyinit = iymax; */ +/* *(p->kyrslt) = iyinit; */ +/* y = (*p->iymax != *p->iymin ? (*p->iymax-iyinit)/ (*p->iymax - *p->iymin) */ +/* : FL(0.5)); */ +/* p->w.y = y; */ + +/* if (UNLIKELY(ixmin > ixmax)) { /\* swap if wrong order *\/ */ +/* x = ixmin; ixmin = ixmax; ixmax = x; */ +/* } */ +/* if (UNLIKELY(ixinit < ixmin)) */ +/* ixinit = ixmin; */ +/* else if (UNLIKELY(ixinit > ixmax)) */ +/* ixinit = ixmax; */ +/* *(p->kxrslt) = ixinit; */ +/* x = (*p->ixmax != *p->ixmin ? (ixinit-*p->ixmin) / (*p->ixmax - *p->ixmin) */ +/* : FL(0.5)); */ +/* p->w.x = x; */ + +/* csound->csoundMakeXYinCallback_(csound, &p->w, x, y); */ +/* csound->RegisterDeinitCallback(csound, (void*) p, deinit_func); */ + +/* p->countdown = 1; /\* init counter to run xyin on first call *\/ */ +/* return OK; */ +/* } */ + +/* int xyin(CSOUND *csound, XYIN *p) */ +/* { */ +/* if (UNLIKELY(!(--p->countdown))) { /\* at each countdown *\/ */ +/* p->countdown = p->timcount; /\* reset counter & *\/ */ +/* csound->csoundReadXYinCallback_(csound, &p->w); \* read cursor postn */ +/* *(p->kxrslt) = *p->ixmin + p->w.x * (*p->ixmax - *p->ixmin); */ +/* *(p->kyrslt) = *p->iymin + (FL(1.0) - p->w.y) * (*p->iymax - *p->iymin); */ +/* } */ +/* return OK; */ +/* } */ diff -Nru csound-5.17.11~dfsg/InOut/window.c csound-6.02~dfsg/InOut/window.c --- csound-5.17.11~dfsg/InOut/window.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/InOut/window.c 2014-01-07 16:53:47.000000000 +0000 @@ -24,7 +24,9 @@ #include "csoundCore.h" /* WINDOW.C */ #include "cwindow.h" /* graph window mgr */ #include "winEPS.h" /* PostSCript routines */ -#include "namedins.h" /* dpwe 16may90 */ + /* dpwe 16may90 */ + +extern OENTRY* find_opcode_new(CSOUND*, char*, char*, char*); extern void MakeAscii(CSOUND *, WINDAT *, const char *); extern void DrawAscii(CSOUND *, WINDAT *); @@ -55,38 +57,22 @@ /* initial proportions */ -static void MkXYDummy(CSOUND *csound, XYINDAT *wdptr, MYFLT x, MYFLT y) -{ - IGN(csound); - wdptr->windid = 0; /* xwin = MakeWindow(1); */ - wdptr->down = 0; /* by def released after Make */ - - wdptr->m_x = 0; - wdptr->m_y = 0; - wdptr->x = x; - wdptr->y = y; -} - -static void RdXYDummy(CSOUND *csound, XYINDAT *wdptr) -{ - IGN(csound); - IGN(wdptr); -} /* called once on initialisation of program to */ /* choose between teletype or bitmap graphics */ void dispinit(CSOUND *csound) { - OPARMS *O = csound->oparms; + OPARMS O; + csound->GetOParms(csound, &O); - if (O->displays && !(O->graphsoff || O->postscript)) { + if (O.displays && !(O.graphsoff || O.postscript)) { if (!csound->isGraphable_) - find_opcode(csound, "FLrun"); /* load FLTK for displays */ + find_opcode_new(csound, "FLrun", NULL, NULL); /* load FLTK for displays */ if (csound->isGraphable_) return; /* provided by window driver: is this session able? */ } - if (!O->displays) { + if (!O.displays) { csound->Message(csound, Str("displays suppressed\n")); csound->csoundMakeGraphCallback_ = DummyFn1; csound->csoundDrawGraphCallback_ = DummyFn2; @@ -94,16 +80,13 @@ } else { csound->Message(csound, Str("graphics %s, ascii substituted\n"), - ((O->graphsoff || O->postscript) ? + ((O.graphsoff || O.postscript) ? Str("suppressed") : Str("not supported on this terminal"))); csound->csoundMakeGraphCallback_ = MakeAscii; csound->csoundDrawGraphCallback_ = DrawAscii; csound->csoundKillGraphCallback_ = KillAscii; } - csound->csoundMakeXYinCallback_ = MkXYDummy; - csound->csoundReadXYinCallback_ = RdXYDummy; - csound->csoundKillXYinCallback_ = RdXYDummy; csound->csoundExitGraphCallback_ = DummyFn3; } @@ -115,10 +98,12 @@ int waitflg, char *label) { + OPARMS O; + csound->GetOParms(csound, &O); char *s = caption; char *t = wdptr->caption; char *tlim = t + CAPSIZE - 1; - if (!csound->oparms->displays) return; /* return if displays disabled */ + if (!O.displays) return; /* return if displays disabled */ wdptr->fdata = fdata; /* init remainder of data structure */ wdptr->npts = npts; while (*s != '\0' && t < tlim) @@ -126,7 +111,7 @@ *t = '\0'; if (!wdptr->windid) { /* if no window defined for this str, create one */ csound->csoundMakeGraphCallback_(csound, wdptr, label); - if (csound->oparms->postscript) + if (O.postscript) PS_MakeGraph(csound, wdptr, label); /* open PS file + write header */ } @@ -141,10 +126,16 @@ int dispexit(CSOUND *csound) { - if (csound->oparms->postscript) + OPARMS O; + csound->GetOParms(csound, &O); + if (O.postscript) PS_ExitGraph(csound); /* Write trailer to PostScript file */ /* prompt for exit from last active window */ - return csound->csoundExitGraphCallback_(csound); + int ret = -1; + if (csound->csoundExitGraphCallback_) { + ret = csound->csoundExitGraphCallback_(csound); + } + return ret; } void display(CSOUND *csound, WINDAT *wdptr) /* prepare a MYFLT array, then */ @@ -153,8 +144,10 @@ MYFLT *fp, *fplim; MYFLT max, min, absmax, fval; int pol; + OPARMS O; + csound->GetOParms(csound, &O); - if (!csound->oparms->displays) return; /* displays disabled? return */ + if (!O.displays) return; /* displays disabled? return */ fp = wdptr->fdata; fplim = fp + wdptr->npts; for (max = *fp++, min = max; fp < fplim; ) { /* find max & min values */ @@ -183,6 +176,6 @@ /* Write postscript code */ - if (csound->oparms->postscript) + if (O.postscript) PS_DrawGraph(csound, wdptr); } diff -Nru csound-5.17.11~dfsg/Known_Problems csound-6.02~dfsg/Known_Problems --- csound-5.17.11~dfsg/Known_Problems 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Known_Problems 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,58 @@ +Problems of which we are aware +============================== + +code like + outs (kadsr)*a1,a1 +fails as the parser tries to make outs a function. + Fixed in git 2013 Jun 28 1200 UT + + +Use of multiple strings in scoreline fails + Fixed in git 2013 Jun 28 1640 UT + + +If a CsOptions section is in a .csd file the line count does not take +account of the section. + Believed fixed in git 2013 Jun 28 1210 UT + + +Long stnding bug wherebye sdif2ad rashed on wring input + Fixed in git 2013 Jun 28 1525 UT + + + +Problems Fixed since rc1 +======================== + +Named instruments do not work unless in a list + ie instr foo fails but "instr foo, 1" works + -- fixed in git sources 2013 Apr 10 08:30 UT +chnset locks were NULL + -- fixed in git sources 2013 Apr 12 06:30 UT +wrong goto token synthesized for if-then + -- fixed in git sources Apr 13 23:07:03 2013 +0100 +if-then in UDO would not properly set label jumps when called + in recursive UDO's, also cause of issue with recursive + UDO's recursing one extra time + -- fixed in git sources Sun Apr 14 14:41:30 2013 +0100 +kr,ksmps vars not set in local-ksmps UDOs + -- fixed in git sources Sun Apr 14 18:50 UT +wrong perf function selected in recursive UDOs with local ksmps + -- fixed in git sources Sun Apr 14 19:52 UT +T opcode arg type did not match against reserved var types (r-) + -- fixed in git source Wed Apr 17 11:47 2013 +0100 +local ksmps UDO breaking multicore performance assumptions + -- fixed by setting local ksmps for opcodes instead of the global ksmps, completed Wed Apr 17 12:49:05 2013 +0100 +semantic phase: label list creation did not correctly walk TREE* + to find all labels: + -- fixed in git sources Apr 18 15:31 2013 +0100 +if-then blocks were not being expanded correctly, with bug + presenting consistently in case of nested if-then's + -- fixed in git sources Apr 19 17:44 2013 +0100 +subinstr broken in multicore + -- fixed in git +csoundPerfError broken as it uses csound-pds + -- fixed to take in an instance argument Thu May 2 00:56:17 2013 +0100 +global variable initialization not done + -- fixed in git sources Fri May 3 20:55:55 2013 +0100 + diff -Nru csound-5.17.11~dfsg/Loadable_Opcodes.txt csound-6.02~dfsg/Loadable_Opcodes.txt --- csound-5.17.11~dfsg/Loadable_Opcodes.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Loadable_Opcodes.txt 1970-01-01 00:00:00.000000000 +0000 @@ -1,2235 +0,0 @@ -Library names are of the form libXXX.so, XXX.dll or libXXX.dylib -depending on platform. - -*** means in manual - -OPCODE -> LIBRARY - -"active" :pitch: *** -"adsynt" :pitch: *** -"and" :stdopcod: n.a. (&) -"ATSaddnz" :stdopcod: (note 1) -"ATSadd" :stdopcod: (note 1) -"ATSbufread" :stdopcod: (note 1) -"ATScross" :stdopcod: (note 1) -"ATSinfo" :stdopcod: (note 1) -"ATSinterpread" :stdopcod: (note 1) -"ATSpartialtap" :stdopcod: (note 1) -"ATSreadnz" :stdopcod: (note 1) -"ATSread" :stdopcod: (note 1) -"ATSsinnoi" :stdopcod: (note 1) -"babo" :babo: *** -"bamboo" :phisem: *** -"barmodel" :barmodel: *** -"bbcutm" :stdopcod: *** -"bbcuts" :stdopcod: *** -"bformdec" :stdopcod: *** -"bformenc" :stdopcod: *** -"binit" :stdopcod: *** -"biquada" :stdopcod: *** -"biquad" :stdopcod: *** -"bqrez" :stdopcod: *** -"butbp" :stdopcod: *** -"butbr" :stdopcod: *** -"buthp" :stdopcod: *** -"butlp" :stdopcod: *** -"butterbp" :stdopcod: *** -"butterbr" :stdopcod: *** -"butterhp" :stdopcod: *** -"butterlp" :stdopcod: *** -"button" :control: *** -"cabasa" :phisem: *** -"checkbox" :control: *** -"clear" :stdopcod: *** -"clfilt" :stdopcod: *** -"clip" :pitch: *** -"clockoff" :pitch: *** -"clockon" :pitch: *** -"control" :control: *** -"cpuprc" :pitch: *** -"cross2" :stdopcod: *** -"crunch" :phisem: *** -"ctrl14" :stdopcod: *** -"ctrl21" :stdopcod: *** -"ctrl7" :stdopcod: *** -"cuserrnd" :stdopcod: *** -"dam" :stdopcod: *** -"dcblock" :stdopcod: *** -"dconv" :stdopcod: *** -"distort1" :stdopcod: *** -"dripwater" :phisem: *** -"dssiaudio" :dssi4cs: *** -"dssictls" :dssi4cs: *** -"dssievent" :dssi4cs: (unimplemented) -"dssilist" :dssi4cs: *** -"dssinote" :dssi4cs: (unimplemented) -"dssisynth" :dssi4cs: (unimplemented) -"duserrnd" :stdopcod: *** -"exitnow" :stdopcod: *** -"filter2" :stdopcod: *** -"fini" :stdopcod: *** -"fink" :stdopcod: *** -"fin" :stdopcod: *** -"fiopen" :stdopcod: *** -"flanger" :stdopcod: *** -"flashtxt" :control: *** -"fluidAllOut" :fluidOpcodes: *** -"fluidCCi" :fluidOpcodes: *** -"fluidCCk" :fluidOpcodes: *** -"fluidControl" :fluidOpcodes: *** -"fluidEngine" :fluidOpcodes: *** -"fluidLoad" :fluidOpcodes: *** -"fluidNote" :fluidOpcodes: *** -"fluidOut" :fluidOpcodes: *** -"fluidProgramSelect" :fluidOpcodes: *** -"fmb3" :physmod: *** -"fmbell" :physmod: *** -"fmmetal" :physmod: *** -"fmpercfl" :physmod: *** -"fmrhode" :physmod: *** -"fmvoice" :physmod: *** -"fmwurlie" :physmod: *** -"fof2" :stdopcod: *** -"fof" :stdopcod: *** -"fog" :stdopcod: *** -"fold" :stdopcod: *** -"follow2" :stdopcod: *** -"follow" :stdopcod: *** -"foutir" :stdopcod: *** -"fouti" :stdopcod: *** -"foutk" :stdopcod: *** -"fout" :stdopcod: *** -"fprintks" :stdopcod: *** -"fprints" :stdopcod: *** -"ftfree" :stdopcod: *** -"ftgen" :stdopcod: *** -"ftgentmp" :stdopcod: *** -"ftloadk" :stdopcod: *** -"ftload" :stdopcod: *** -"ftmorf" :stdopcod: *** -"ftsavek" :stdopcod: *** -"ftsave" :stdopcod: *** -"gogobel" :modal4: *** -"grain" :stdopcod: *** -"granule" :grain4: *** -"guiro" :phisem: *** -"harmon" :stdopcod: *** -"hilbert" :stdopcod: *** -"hrtfer" :hrtferX: *** -"hsboscil" :pitch: *** -"initc14" :stdopcod: *** -"initc21" :stdopcod: *** -"initc7" :stdopcod: *** -"jitter2" :stdopcod: *** -"jitter" :stdopcod: *** -"jspline" :stdopcod: *** -"lineto" :stdopcod: *** -"locsend" :stdopcod: *** -"locsig" :stdopcod: *** -"loopsegp" :stdopcod: *** -"loopseg" :stdopcod: *** -"lorenz" :stdopcod: *** -"lorismorph" :loris: *** -"lorisplay" :loris: *** -"lorisread" :loris: *** -"lowpass2" :stdopcod: *** -"lowres" :stdopcod: *** -"lowresx" :stdopcod: *** -"lpf18" :pitch: *** -"lposcil3" :stdopcod: *** -"lposcil" :stdopcod: *** -"lpsholdp" :stdopcod: *** -"lpshold" :stdopcod: *** -"maca" :pitch: *** -"mac" :pitch: *** -"mandol" :physmod: *** -"marimba" :modal4: *** -"maxabsaccum" :minmax: *** -"maxabs" :minmax: *** -"maxaccum" :minmax: *** -"maxalloc" :pitch: *** -"max" :minmax: *** -"metro" :stdopcod: *** -"midic14" :stdopcod: *** -"midic21" :stdopcod: *** -"midic7" :stdopcod: *** -"minabsaccum" :minmax: *** -"minabs" :minmax: *** -"minaccum" :minmax: *** -"min" :minmax: *** -"mirror" :stdopcod: *** -"moog" :physmod: *** -"moogvcf" :stdopcod: *** -"mpulse" :pitch: *** -"mute" :pitch: *** -"nestedap" :stdopcod: *** -"nlfilt" :stdopcod: *** -"noise" :pitch: *** -"not" :stdopcod: n.a. (~) -"ntrpol" :stdopcod: *** -"or" :stdopcod: n.a. (|) -"oscilv" :pitch: (beta only) -"OSCinit" :osc: *** -"OSClisten" :osc: *** -"OSCrecv" :osc: *** -"OSCsend" :osc: *** -"pareq" :stdopcod: *** -"partials" :stdopcod: *** -"phaser1" :stdopcod: *** -"phaser2" :stdopcod: *** -"phasorbnk" :pitch: *** -"pinkish" :pitch: *** -"pitchamdf" :pitch: *** -"pitch" :pitch: *** -"planet" :stdopcod: *** -"poscil3" :stdopcod: *** -"poscil" :stdopcod: *** -"p" :pitch: *** -"product" :stdopcod: *** -"pvsblur" :stdopcod: *** -"pvscale" :stdopcod: *** -"pvscent" :stdopcod: *** -"pvsdemix" :stdopcod: *** -"pvsfilter" :stdopcod: *** -"pvshift" :stdopcod: *** -"pvsifd" :stdopcod: *** -"pvsinit" :stdopcod: *** -"pvsmix" :stdopcod: *** -"pvstencil" :stdopcod: *** -"pyassigni" :py: *** -"pyassign" :py: *** -"pyassignt" :py: *** -"pycall1i" :py: *** -"pycall1" :py: *** -"pycall1t" :py: *** -"pycall2i" :py: *** -"pycall2" :py: *** -"pycall2t" :py: *** -"pycall3i" :py: *** -"pycall3" :py: *** -"pycall3t" :py: *** -"pycall4i" :py: *** -"pycall4" :py: *** -"pycall4t" :py: *** -"pycall5i" :py: *** -"pycall5" :py: *** -"pycall5t" :py: *** -"pycall6i" :py: *** -"pycall6" :py: *** -"pycall6t" :py: *** -"pycall7i" :py: *** -"pycall7" :py: *** -"pycall7t" :py: *** -"pycall8i" :py: *** -"pycall8" :py: *** -"pycall8t" :py: *** -"pycalli" :py: *** -"pycallni" :py: *** -"pycalln" :py: *** -"pycallnt" :py: *** -"pycallt" :py: *** -"pyevali" :py: *** -"pyeval" :py: *** -"pyevalt" :py: *** -"pyexeci" :py: *** -"pyexec" :py: *** -"pyexect" :py: *** -"pyinit" :py: *** -"pylassigni" :py: *** -"pylassign" :py: *** -"pylassignt" :py: *** -"pylcall1i" :py: *** -"pylcall1" :py: *** -"pylcall1t" :py: *** -"pylcall2i" :py: *** -"pylcall2" :py: *** -"pylcall2t" :py: *** -"pylcall3i" :py: *** -"pylcall3" :py: *** -"pylcall3t" :py: *** -"pylcall4i" :py: *** -"pylcall4" :py: *** -"pylcall4t" :py: *** -"pylcall5i" :py: *** -"pylcall5" :py: *** -"pylcall5t" :py: *** -"pylcall6i" :py: *** -"pylcall6" :py: *** -"pylcall6t" :py: *** -"pylcall7i" :py: *** -"pylcall7" :py: *** -"pylcall7t" :py: *** -"pylcall8i" :py: *** -"pylcall8" :py: *** -"pylcall8t" :py: *** -"pylcalli" :py: *** -"pylcallni" :py: *** -"pylcalln" :py: *** -"pylcallnt" :py: *** -"pylcall" :py: *** -"pylcallt" :py: *** -"pylevali" :py: *** -"pyleval" :py: *** -"pylevalt" :py: *** -"pylexeci" :py: *** -"pylexec" :py: *** -"pylexect" :py: *** -"pylruni" :py: *** -"pylrun" :py: *** -"pylrunt" :py: *** -"pyruni" :py: *** -"pyrun" :py: *** -"pyrunt" :py: *** -"randomh" :stdopcod: *** -"randomi" :stdopcod: *** -"random" :stdopcod: *** -"readclock" :pitch: *** -"repluck" :stdopcod: *** -"resonr" :stdopcod: *** -"resony" :stdopcod: *** -"resonz" :stdopcod: *** -"resyn" :stdopcod: *** -"rezzy" :stdopcod: *** -"rspline" :stdopcod: *** -"s16b14" :stdopcod: *** -"s32b14" :stdopcod: *** -"sandpaper" :phisem: *** -"scanhammer" :stdopcod: *** -"scans" :scansyn: *** -"scantable" :stdopcod: *** -"scanu" :scansyn: *** -"sekere" :phisem: *** -"sensekey" :pitch: *** -"sense" :pitch: *** -"seqtime2" :stdopcod: *** -"seqtime" :stdopcod: *** -"setctrl" :control: *** -"sfilist" :sfont: *** -"sfinstr3m" :sfont: *** -"sfinstr3" :sfont: *** -"sfinstrm" :sfont: *** -"sfinstr" :sfont: *** -"sfload" :sfont: *** -"sfpassign" :sfont: *** -"sfplay3m" :sfont: *** -"sfplay3" :sfont: *** -"sfplaym" :sfont: *** -"sfplay" :sfont: *** -"sfplist" :sfont: *** -"sfpreset" :sfont: *** -"shaker" :physmod: *** -"shl" :stdopcod: n.a. (<<) -"sinsyn" :stdopcod: *** -"sleighbells" :phisem: *** -"slider16f" :stdopcod: *** -"slider16" :stdopcod: *** -"slider32f" :stdopcod: *** -"slider32" :stdopcod: *** -"slider64f" :stdopcod: *** -"slider64" :stdopcod: *** -"slider8f" :stdopcod: *** -"slider8" :stdopcod: *** -"sndwarp" :stdopcod: *** -"sndwarpst" :stdopcod: *** -"space" :stdopcod: *** -"spat3di" :stdopcod: *** -"spat3d" :stdopcod: *** -"spat3dt" :stdopcod: *** -"spdist" :stdopcod: *** -"specaddm" :pitch: *** -"specdiff" :pitch: *** -"specdisp" :pitch: *** -"specfilt" :pitch: *** -"spechist" :pitch: *** -"specptrk" :pitch: *** -"specscal" :pitch: *** -"specsum" :pitch: *** -"spectrum" :pitch: *** -"splitrig" :stdopcod: *** -"spsend" :stdopcod: *** -"stix" :phisem: *** -"STKBandedWG" :stk: (note 2) -"STKBeeThree" :stk: (note 2) -"STKBlowBotl" :stk: (note 2) -"STKBlowHole" :stk: (note 2) -"STKBowed" :stk: (note 2) -"STKBrass" :stk: (note 2) -"STKClarinet" :stk: (note 2) -"STKDrummer" :stk: (note 2) -"STKFlute" :stk: (note 2) -"STKFMVoices" :stk: (note 2) -"STKHevyMetl" :stk: (note 2) -"STKMandolin" :stk: (note 2) -"STKModalBar" :stk: (note 2) -"STKMoog" :stk: (note 2) -"STKPercFlut" :stk: (note 2) -"STKPlucked" :stk: (note 2) -"STKResonate" :stk: (note 2) -"STKRhodey" :stk: (note 2) -"STKSaxofony" :stk: (note 2) -"STKShakers" :stk: (note 2) -"STKSimple" :stk: (note 2) -"STKSitar" :stk: (note 2) -"STKStifKarp" :stk: (note 2) -"STKTubeBell" :stk: (note 2) -"STKVoicForm" :stk: (note 2) -"STKWhistle" :stk: (note 2) -"STKWurley" :stk: (note 2) -"streson" :stdopcod: *** -"sum" :stdopcod: *** -"svfilter" :stdopcod: *** -"tab_i" :stdopcod: *** -"tabw_i" :stdopcod: *** -"tambourine" :phisem: *** -"tb0_init" :stdopcod: *** -"tb0" :stdopcod: *** -"tb10_init" :stdopcod: *** -"tb10" :stdopcod: *** -"tb11_init" :stdopcod: *** -"tb11" :stdopcod: *** -"tb12_init" :stdopcod: *** -"tb12" :stdopcod: *** -"tb13_init" :stdopcod: *** -"tb13" :stdopcod: *** -"tb14_init" :stdopcod: *** -"tb14" :stdopcod: *** -"tb15_init" :stdopcod: *** -"tb15" :stdopcod: *** -"tb1_init" :stdopcod: *** -"tb1" :stdopcod: *** -"tb2_init" :stdopcod: *** -"tb2" :stdopcod: *** -"tb3_init" :stdopcod: *** -"tb3" :stdopcod: *** -"tb4_init" :stdopcod: *** -"tb4" :stdopcod: *** -"tb5_init" :stdopcod: *** -"tb5" :stdopcod: *** -"tb6_init" :stdopcod: *** -"tb6" :stdopcod: *** -"tb7_init" :stdopcod: *** -"tb7" :stdopcod: *** -"tb8_init" :stdopcod: *** -"tb8" :stdopcod: *** -"tb9_init" :stdopcod: *** -"tb9" :stdopcod: *** -"tbvcf" :stdopcod: *** -"timedseq" :stdopcod: *** -"tlineto" :stdopcod: *** -"tradsyn" :stdopcod: *** -"transeg" :pitch: *** -"trcross" :stdopcod: *** -"trfilter" :stdopcod: *** -"trhighest" :stdopcod: *** -"trigger" :stdopcod: *** -"trlowest" :stdopcod: *** -"trmix" :stdopcod: *** -"trscale" :stdopcod: *** -"trshift" :stdopcod: *** -"trsplit" :stdopcod: *** -"urd" :stdopcod: *** -"vadd" :stdopcod: *** -"vaddv" :stdopcod: *** -"valpass" :stdopcod: *** -"vbap16move" :vbap: *** -"vbap16" :vbap: *** -"vbap4move" :vbap: *** -"vbap4" :vbap: *** -"vbap8move" :vbap: *** -"vbap8" :vbap: *** -"vbaplsinit" :vbap: *** -"vbapzmove" :vbap: *** -"vbapz" :vbap: *** -"vcella" :stdopcod: *** -"vcomb" :stdopcod: *** -"vcopy_i" :stdopcod: *** -"vcopy" :stdopcod: *** -"vco" :stdopcod: *** -"vdelayk" :stdopcod: *** -"vdivv" :stdopcod: *** -"vecdelay" :stdopcod: *** -"vexpseg" :stdopcod: *** -"vexp" :stdopcod: *** -"vexpv" :stdopcod: *** -"vibes" :modal4: *** -"vibrato" :stdopcod: *** -"vibr" :stdopcod: *** -"vincr" :stdopcod: *** -"vlimit" :stdopcod: *** -"vlinseg" :stdopcod: *** -"vlowres" :stdopcod: *** -"vmap" :stdopcod: *** -"vmirror" :stdopcod: *** -"vmult" :stdopcod: *** -"vmultv" :stdopcod: *** -"voice" :physmod: *** -"vport" :stdopcod: *** -"vpow" :stdopcod: *** -"vpowv" :stdopcod: *** -"vrandh" :stdopcod: *** -"vrandi" :stdopcod: *** -"vsubv" :stdopcod: *** -"vtaba" :stdopcod: *** -"vtabi" :stdopcod: *** -"vtabk" :stdopcod: *** -"vtablea" :stdopcod: *** -"vtablei" :stdopcod: *** -"vtablek" :stdopcod: *** -"vtablewa" :stdopcod: *** -"vtablewi" :stdopcod: *** -"vtablewk" :stdopcod: *** -"vtabwa" :stdopcod: *** -"vtabwi" :stdopcod: *** -"vtabwk" :stdopcod: *** -"vwrap" :stdopcod: *** -"waveset" :pitch: *** -"wgbowedbar" :physmod: *** -"wgbow" :physmod: *** -"wgbrass" :physmod: *** -"wgclar" :physmod: *** -"wgflute" :physmod: *** -"wgpluck2" :stdopcod: *** -"wgpluck" :stdopcod: *** -"wguide1" :stdopcod: *** -"wguide2" :stdopcod: *** -"wrap" :stdopcod: *** -"wterrain" :stdopcod: *** -"xor" :stdopcod: n.a. (#) -"xscanmap" :scansyn: *** -"xscansmap" :scansyn: *** -"xscans" :scansyn: *** -"xscanu" :scansyn: *** -"zfilter2" :stdopcod: *** - -note 1: http://sourceforge.net/projects/atsa/ -note 2: http://ccrma.stanford.edu/software/stk/ - ------------------------------------------------------------------------- -LIBRARY -> OPCODE - -babo: "babo" -barmodel: "barmodel" -control: "button" -control: "checkbox" -control: "control" -control: "flashtxt" -control: "setctrl" -dssi4cs: "dssiaudio" -dssi4cs: "dssictls" -dssi4cs: "dssievent" -dssi4cs: "dssiinit" -dssi4cs: "dssilist" -dssi4cs: "dssinote" -dssi4cs: "dssisynth" -fluidOpcodes: "fluidAllOut" -fluidOpcodes: "fluidCCi" -fluidOpcodes: "fluidCCk" -fluidOpcodes: "fluidControl" -fluidOpcodes: "fluidEngine" -fluidOpcodes: "fluidLoad" -fluidOpcodes: "fluidNote" -fluidOpcodes: "fluidOut" -fluidOpcodes: "fluidProgramSelect" -grain4: "granule" -hrtferX: "hrtfer" -loris: "lorismorph" -loris: "lorisplay" -loris: "lorisread" -minmax: "max" -minmax: "maxabs" -minmax: "maxabsaccum" -minmax: "maxaccum" -minmax: "min" -minmax: "minabs" -minmax: "minabsaccum" -minmax: "minaccum" -modal4: "gogobel" -modal4: "marimba" -modal4: "vibes" -osc: "OSCinit" -osc: "OSClisten" -osc: "OSCrecv" -osc: "OSCsend" -phisem: "bamboo" -phisem: "cabasa" -phisem: "crunch" -phisem: "dripwater" -phisem: "guiro" -phisem: "sandpaper" -phisem: "sekere" -phisem: "sleighbells" -phisem: "stix" -phisem: "tambourine" -physmod: "fmb3" -physmod: "fmbell" -physmod: "fmmetal" -physmod: "fmpercfl" -physmod: "fmrhode" -physmod: "fmvoice" -physmod: "fmwurlie" -physmod: "mandol" -physmod: "moog" -physmod: "shaker" -physmod: "voice" -physmod: "wgbow" -physmod: "wgbowedbar" -physmod: "wgbrass" -physmod: "wgclar" -physmod: "wgflute" -pitch: "active" -pitch: "adsynt" -pitch: "clip" -pitch: "clockoff" -pitch: "clockon" -pitch: "cpuprc" -pitch: "hsboscil" -pitch: "lpf18" -pitch: "mac" -pitch: "maca" -pitch: "maxalloc" -pitch: "mpulse" -pitch: "mute" -pitch: "noise" -pitch: "oscilv" -pitch: "p" -pitch: "phasorbnk" -pitch: "pinkish" -pitch: "pitch" -pitch: "pitchamdf" -pitch: "readclock" -pitch: "sense" -pitch: "sensekey" -pitch: "specaddm" -pitch: "specdiff" -pitch: "specdisp" -pitch: "specfilt" -pitch: "spechist" -pitch: "specptrk" -pitch: "specscal" -pitch: "specsum" -pitch: "spectrum" -pitch: "transeg" -pitch: "waveset" -py: "pyassign" -py: "pyassigni" -py: "pyassignt" -py: "pycall" -py: "pycall1" -py: "pycall1i" -py: "pycall1t" -py: "pycall2" -py: "pycall2i" -py: "pycall2t" -py: "pycall3" -py: "pycall3i" -py: "pycall3t" -py: "pycall4" -py: "pycall4i" -py: "pycall4t" -py: "pycall5" -py: "pycall5i" -py: "pycall5t" -py: "pycall6" -py: "pycall6i" -py: "pycall6t" -py: "pycall7" -py: "pycall7i" -py: "pycall7t" -py: "pycall8" -py: "pycall8i" -py: "pycall8t" -py: "pycalli" -py: "pycalln" -py: "pycallni" -py: "pycallnt" -py: "pycallt" -py: "pyeval" -py: "pyevali" -py: "pyevalt" -py: "pyexec" -py: "pyexeci" -py: "pyexect" -py: "pyinit" -py: "pylassign" -py: "pylassigni" -py: "pylassignt" -py: "pylcall" -py: "pylcall1" -py: "pylcall1i" -py: "pylcall1t" -py: "pylcall2" -py: "pylcall2i" -py: "pylcall2t" -py: "pylcall3" -py: "pylcall3i" -py: "pylcall3t" -py: "pylcall4" -py: "pylcall4i" -py: "pylcall4t" -py: "pylcall5" -py: "pylcall5i" -py: "pylcall5t" -py: "pylcall6" -py: "pylcall6i" -py: "pylcall6t" -py: "pylcall7" -py: "pylcall7i" -py: "pylcall7t" -py: "pylcall8" -py: "pylcall8i" -py: "pylcall8t" -py: "pylcalli" -py: "pylcalln" -py: "pylcallni" -py: "pylcallnt" -py: "pylcallt" -py: "pyleval" -py: "pylevali" -py: "pylevalt" -py: "pylexec" -py: "pylexeci" -py: "pylexect" -py: "pylrun" -py: "pylruni" -py: "pylrunt" -py: "pyrun" -py: "pyruni" -py: "pyrunt" -scansyn: "scans" -scansyn: "scanu" -scansyn: "xscanmap" -scansyn: "xscans" -scansyn: "xscansmap" -scansyn: "xscanu" -sfont: "sfilist" -sfont: "sfinstr" -sfont: "sfinstr3" -sfont: "sfinstr3m" -sfont: "sfinstr3m" -sfont: "sfinstrm" -sfont: "sfload" -sfont: "sfpassign" -sfont: "sfplay" -sfont: "sfplay3" -sfont: "sfplay3m" -sfont: "sfplaym" -sfont: "sfplist" -sfont: "sfpreset" -stdopcod: "and" -stdopcod: "ATSadd" -stdopcod: "ATSaddnz" -stdopcod: "ATSbufread" -stdopcod: "ATScross" -stdopcod: "ATSinfo" -stdopcod: "ATSinterpread" -stdopcod: "ATSpartialtap" -stdopcod: "ATSread" -stdopcod: "ATSreadnz" -stdopcod: "ATSsinnoi" -stdopcod: "bbcutm" -stdopcod: "bbcuts" -stdopcod: "bformdec" -stdopcod: "bformenc" -stdopcod: "binit" -stdopcod: "biquad" -stdopcod: "biquada" -stdopcod: "bqrez" -stdopcod: "butbp" -stdopcod: "butbr" -stdopcod: "buthp" -stdopcod: "butlp" -stdopcod: "butterbp" -stdopcod: "butterbr" -stdopcod: "butterhp" -stdopcod: "butterlp" -stdopcod: "clear" -stdopcod: "clfilt" -stdopcod: "cross2" -stdopcod: "ctrl14" -stdopcod: "ctrl21" -stdopcod: "ctrl7" -stdopcod: "cuserrnd" -stdopcod: "dam" -stdopcod: "dcblock" -stdopcod: "dconv" -stdopcod: "distort1" -stdopcod: "duserrnd" -stdopcod: "exitnow" -stdopcod: "filter2" -stdopcod: "fin" -stdopcod: "fini" -stdopcod: "fink" -stdopcod: "fiopen" -stdopcod: "flanger" -stdopcod: "fof" -stdopcod: "fof2" -stdopcod: "fog" -stdopcod: "fold" -stdopcod: "follow" -stdopcod: "follow2" -stdopcod: "fout" -stdopcod: "fouti" -stdopcod: "foutir" -stdopcod: "foutk" -stdopcod: "fprintks" -stdopcod: "fprints" -stdopcod: "ftfree" -stdopcod: "ftgen" -stdopcod: "ftgentmp" -stdopcod: "ftload" -stdopcod: "ftloadk" -stdopcod: "ftmorf" -stdopcod: "ftsave" -stdopcod: "ftsavek" -stdopcod: "grain" -stdopcod: "harmon" -stdopcod: "hilbert" -stdopcod: "initc14" -stdopcod: "initc21" -stdopcod: "initc7" -stdopcod: "jitter" -stdopcod: "jitter2" -stdopcod: "jspline" -stdopcod: "lineto" -stdopcod: "locsend" -stdopcod: "locsig" -stdopcod: "loopseg" -stdopcod: "loopsegp" -stdopcod: "lorenz" -stdopcod: "lowpass2" -stdopcod: "lowres" -stdopcod: "lowresx" -stdopcod: "lposcil" -stdopcod: "lposcil3" -stdopcod: "lpshold" -stdopcod: "lpsholdp" -stdopcod: "metro" -stdopcod: "midic14" -stdopcod: "midic21" -stdopcod: "midic7" -stdopcod: "mirror" -stdopcod: "moogvcf" -stdopcod: "nestedap" -stdopcod: "nlfilt" -stdopcod: "not" -stdopcod: "ntrpol" -stdopcod: "or" -stdopcod: "pareq" -stdopcod: "partials" -stdopcod: "phaser1" -stdopcod: "phaser2" -stdopcod: "planet" -stdopcod: "poscil" -stdopcod: "poscil3" -stdopcod: "product" -stdopcod: "pvsblur" -stdopcod: "pvscale" -stdopcod: "pvscent" -stdopcod: "pvsdemix" -stdopcod: "pvsfilter" -stdopcod: "pvshift" -stdopcod: "pvsifd" -stdopcod: "pvsinit" -stdopcod: "pvsmix" -stdopcod: "pvstencil" -stdopcod: "random" -stdopcod: "randomh" -stdopcod: "randomi" -stdopcod: "repluck" -stdopcod: "resonr" -stdopcod: "resony" -stdopcod: "resonz" -stdopcod: "resyn" -stdopcod: "rezzy" -stdopcod: "rspline" -stdopcod: "s16b14" -stdopcod: "s32b14" -stdopcod: "scanhammer" -stdopcod: "scantable" -stdopcod: "seqtime" -stdopcod: "seqtime2" -stdopcod: "shl" -stdopcod: "sinsyn" -stdopcod: "slider16" -stdopcod: "slider16f" -stdopcod: "slider32" -stdopcod: "slider32f" -stdopcod: "slider64" -stdopcod: "slider64f" -stdopcod: "slider8" -stdopcod: "slider8f" -stdopcod: "sndwarp" -stdopcod: "sndwarpst" -stdopcod: "space" -stdopcod: "spat3d" -stdopcod: "spat3di" -stdopcod: "spat3dt" -stdopcod: "spdist" -stdopcod: "splitrig" -stdopcod: "spsend" -stdopcod: "streson" -stdopcod: "sum" -stdopcod: "svfilter" -stdopcod: "tab_i" -stdopcod: "tabw_i" -stdopcod: "tb0" -stdopcod: "tb0_init" -stdopcod: "tb1" -stdopcod: "tb10" -stdopcod: "tb10_init" -stdopcod: "tb11" -stdopcod: "tb11_init" -stdopcod: "tb12" -stdopcod: "tb12_init" -stdopcod: "tb13" -stdopcod: "tb13_init" -stdopcod: "tb14" -stdopcod: "tb14_init" -stdopcod: "tb15" -stdopcod: "tb15_init" -stdopcod: "tb1_init" -stdopcod: "tb2" -stdopcod: "tb2_init" -stdopcod: "tb3" -stdopcod: "tb3_init" -stdopcod: "tb4" -stdopcod: "tb4_init" -stdopcod: "tb5" -stdopcod: "tb5_init" -stdopcod: "tb6" -stdopcod: "tb6_init" -stdopcod: "tb7" -stdopcod: "tb7_init" -stdopcod: "tb8" -stdopcod: "tb8_init" -stdopcod: "tb9" -stdopcod: "tb9_init" -stdopcod: "tbvcf" -stdopcod: "timedseq" -stdopcod: "tlineto" -stdopcod: "tradsyn" -stdopcod: "trcross" -stdopcod: "trfilter" -stdopcod: "trhighest" -stdopcod: "trigger" -stdopcod: "trlowest" -stdopcod: "trmix" -stdopcod: "trscale" -stdopcod: "trshift" -stdopcod: "trsplit" -stdopcod: "urd" -stdopcod: "vadd" -stdopcod: "vaddv" -stdopcod: "valpass" -stdopcod: "vcella" -stdopcod: "vco" -stdopcod: "vcomb" -stdopcod: "vcopy" -stdopcod: "vcopy_i" -stdopcod: "vdelayk" -stdopcod: "vdivv" -stdopcod: "vecdelay" -stdopcod: "vexp" -stdopcod: "vexpseg" -stdopcod: "vexpv" -stdopcod: "vibr" -stdopcod: "vibrato" -stdopcod: "vincr" -stdopcod: "vlimit" -stdopcod: "vlinseg" -stdopcod: "vlowres" -stdopcod: "vmap" -stdopcod: "vmirror" -stdopcod: "vmult" -stdopcod: "vmultv" -stdopcod: "vport" -stdopcod: "vpow" -stdopcod: "vpowv" -stdopcod: "vrandh" -stdopcod: "vrandi" -stdopcod: "vsubv" -stdopcod: "vtaba" -stdopcod: "vtabi" -stdopcod: "vtabk" -stdopcod: "vtablea" -stdopcod: "vtablei" -stdopcod: "vtablek" -stdopcod: "vtablewa" -stdopcod: "vtablewi" -stdopcod: "vtablewk" -stdopcod: "vtabwa" -stdopcod: "vtabwi" -stdopcod: "vtabwk" -stdopcod: "vwrap" -stdopcod: "wgpluck" -stdopcod: "wgpluck2" -stdopcod: "wguide1" -stdopcod: "wguide2" -stdopcod: "wrap" -stdopcod: "wterrain" -stdopcod: "xor" -stdopcod: "zfilter2" -stk: "STKBandedWG" -stk: "STKBeeThree" -stk: "STKBlowBotl" -stk: "STKBlowHole" -stk: "STKBowed" -stk: "STKBrass" -stk: "STKClarinet" -stk: "STKDrummer" -stk: "STKFlute" -stk: "STKFMVoices" -stk: "STKHevyMetl" -stk: "STKMandolin" -stk: "STKModalBar" -stk: "STKMoog" -stk: "STKPercFlut" -stk: "STKPlucked" -stk: "STKResonate" -stk: "STKRhodey" -stk: "STKSaxofony" -stk: "STKShakers" -stk: "STKSimple" -stk: "STKSitar" -stk: "STKStifKarp" -stk: "STKTubeBell" -stk: "STKVoicForm" -stk: "STKWhistle" -stk: "STKWurley" -vbap: "vbap16" -vbap: "vbap16move" -vbap: "vbap4" -vbap: "vbap4move" -vbap: "vbap8" -vbap: "vbap8move" -vbap: "vbaplsinit" -vbap: "vbapz" -vbap: "vbapzmove" - -*end* - -======================================================================== -Opcodes in base system ----------------------- - -a *** -abs *** -add n.a. (+) -adsr *** -adsyn *** -aftouch *** -alpass *** -ampdb *** -ampdbfs *** -ampmidi *** -areson *** -aresonk *** -atone *** -atonek *** -atonex *** -balance *** -betarand *** -bexprnd *** -birnd *** -buzz *** -cauchy *** -ceil *** -cent *** -cggoto *** -chanctrl *** -chani *** -chano *** -chn_a *** -chnclear *** -chnexport *** -chnget *** -chn_k *** -chnmix *** -chnparams *** -chn_S *** -chnset *** -cigoto *** -ckgoto *** -cngoto *** -cogoto n.a. (ithen?) -comb *** -cos *** -cosh *** -cosinv *** -cps2pch *** -cpsmidi *** -cpsmidib *** -cpsoct *** -cpspch *** -cpstmid *** -cpstun *** -cpstuni *** -cpsxpch *** -ctrlinit *** -db *** -dbamp *** -dbfsamp *** -delay *** -delay1 *** -delayr *** -delayw *** -deltap *** -deltap3 *** -deltapi *** -deltapn *** -deltapx *** -deltapxw *** -diff *** -diskin *** -diskin2 *** -dispfft *** -display *** -div n.a. (/) -divz *** -downsamp *** -dumpk *** -dumpk2 *** -dumpk3 *** -dumpk4 *** -endin *** -endop *** -envlpx *** -envlpxr *** -event *** -event_i *** -exp *** -expon *** -exprand *** -expseg *** -expsega *** -expsegr *** -filelen *** -filenchnls *** -filepeak *** -filesr *** -floor *** -foscil *** -foscili *** -frac *** -ftchnls *** -ftlen *** -ftlptim *** -ftsr *** -gain *** -gauss *** -gbuzz *** -goto *** -i *** -igoto *** -ihold *** -_in -in *** -in32 *** -inch *** -inh *** -init *** -ino *** -inq *** -ins *** -instr *** -int *** -integ *** -interp *** -invalue *** -inx *** -inz *** -k *** -kgoto *** -ktableseg *** -lfo *** -limit *** -line *** -linen *** -linenr *** -linrand *** -linseg *** -linsegr *** -log *** -log10 *** -logbtwo *** -loop_ge *** -loop_gt *** -loop_le *** -loop_lt *** -loscil *** -loscil3 *** -lpfreson *** -lphasor *** -lpinterp *** -lpread *** -lpreson *** -lpslot *** -madsr *** -massign *** -mclock *** -mdelay *** -midichannelaftertouch *** -midichn *** -midicontrolchange *** -midictrl *** -mididefault *** -midiin *** -midinoteoff *** -midinoteoncps *** -midinoteonkey *** -midinoteonoct *** -midinoteonpch *** -midion *** -midion2 *** -midiout *** -midipitchbend *** -midipolyaftertouch *** -midiprogramchange *** -miditempo *** -mod n.a. (%) -moscil *** -mrtmsg *** -multitap *** -mxadsr *** -noteoff *** -noteon *** -noteondur *** -noteondur2 *** -notnum *** -nreverb *** -nrpn *** -nsamp *** -nstrnum *** -ntrpol *** -octave *** -octcps *** -octmidi *** -octmidib *** -octpch *** -opcode *** -oscil *** -oscil1 *** -oscil1i *** -oscil3 *** -oscili *** -osciln *** -oscils *** -oscilx *** -out *** -out32 *** -outc *** -outch *** -outh *** -outiat *** -outic *** -outic14 *** -outipat *** -outipb *** -outipc *** -outkat *** -outkc *** -outkc14 *** -outkpat *** -outkpb *** -outkpc *** -outo *** -outq *** -outq1 *** -outq2 *** -outq3 *** -outq4 *** -outs *** -outs1 *** -outs2 *** -outvalue *** -outx *** -outz *** -pan *** -pcauchy *** -pchbend *** -pchmidi *** -pchmidib *** -pchoct *** -peak *** -pgmassign *** -phasor *** -pluck *** -poisson *** -polyaft *** -port *** -portk *** -pow *** -powoftwo *** -prealloc *** -print *** -printf *** -printf_i *** -printk *** -printk2 *** -printks *** -prints *** -pset *** -puts *** -pvadd *** -pvbufread *** -pvcross *** -pvinterp *** -pvoc *** -pvread *** -pvsadsyn *** -pvsanal *** -pvscross *** -pvsfread *** -pvsftr *** -pvsftw *** -pvsinfo *** -pvsmaska *** -pvsynth *** -rand *** -randh *** -randi *** -readk *** -readk2 *** -readk3 *** -readk4 *** -reinit *** -release *** -reson *** -resonk *** -resonx *** -reverb *** -reverb2 *** -rigoto *** -rireturn *** -rms *** -rnd *** -round *** -rtclock *** -samphold *** -schedkwhen *** -schedkwhennamed *** -schedule *** -schedwhen *** -seed *** -semitone *** -setksmps *** -sin *** -sinh *** -sininv *** -soundin *** -soundout *** -soundouts *** -sprintf *** -sprintfk *** -sqrt *** -strcat *** -strcatk *** -strcmp *** -strcmpk *** -strcpy *** -strcpyk *** -strget *** -strset *** -strtod *** -strtodk *** -strtol *** -strtolk *** -sub n.a. (-) -subinstr *** -subinstrinit *** -table *** -table3 *** -tablecopy *** -tablegpw *** -tablei *** -tableicopy *** -tableigpw *** -tableikt *** -tableimix *** -tableiw *** -tablekt *** -tablemix *** -tableng *** -tablera *** -tableseg *** -tablew *** -tablewa *** -tablewkt *** -tablexkt *** -tablexseg *** -tan *** -tanh *** -taninv *** -taninv2 *** -tempest *** -tempo *** -tempoval *** -tigoto *** -timeinstk *** -timeinsts *** -timek *** -times *** -timout *** -tival *** -tone *** -tonek *** -tonex *** -trigseq *** -trirand *** -turnoff *** -turnoff2 *** -turnon *** -unirand *** -upsamp *** -vdelayx *** -vdelayxq *** -vdelayxs *** -vdelayxw *** -vdelayxwq *** -vdelayxws *** -veloc *** -vpvoc *** -weibull *** -xadsr *** -xin *** -xout *** -xtratim *** -xyin *** -zacl *** -zakinit *** -zamod *** -zar *** -zarg *** -zaw *** -zawm *** -zir *** -ziw *** -ziwm *** -zkcl *** -zkmod *** -zkr *** -zkw *** -zkwm *** - -======================================================================== -Documemtation exists for - -adsynt2 -changed -chnparams -chnset -clock -convle -convolve -delayk -denorm -dssiactivate -dssiinit -FLbox -FLbutBank -FLbutton -FLcolor -FLcolor2 -FLcount -FLgetsnap -FLgroup -FLgroupEnd -FLgroupEnd -FLhide -FLjoy -FLkeyb -FLknob -FLlabel -FLloadsnap -flooper -FLpack -FLpackEnd -FLpackEnd -FLpanel -FLpanel_end -FLpanelEnd -FLprintk -FLprintk2 -FLroller -FLrun -FLsavesnap -FLscroll -FLscroll_end -FLscrollEnd -FLsetAlign -FLsetBox -FLsetColor -FLsetColor2 -FLsetFont -FLsetPosition -FLsetSize -FLsetsnap -FLsetText -FLsetTextColor -FLsetTextSize -FLsetTextType -FLsetVal -FLsetVal_i -FLshow -FLslidBnk -FLslider -FLtabs -FLtabs_end -FLtabsEnd -FLtext -FLupdate -FLvalue -fofilter -freeverb -ftconv -grain2 -grain3 -ictrl14 -ictrl21 -ictrl7 -imidic14 -imidic21 -imidic7 -ink -instimek -instimes -ioff -ion -iondur -iondur2 -ioutat -ioutc -ioutc14 -ioutpat -ioutpb -ioutpc -is16b14 -is32b14 -islider16 -islider32 -islider64 -islider8 -itablecopy -itablegpw -itablemix -itablew -k -kon -koutat -koutc -koutc14 -koutpat -koutpb -koutpc -loop -mandel -max_k -MixerClear -MixerGetLevel -MixerReceive -MixerSend -MixerSetLevel -moscil -nchnls -oscbnk -oscilikt -osciliktp -oscilikts -outk -pconvolve -peakk -pluck -puts -pvsarp -pvsvoc -pycall Opcodes -pyeval Opcodes -pyexec Opcodes -pyinit Opcodes -pyrun Opcodes -random -randomh -randomi -rbjeq -resonxk -reverbsc -rnd31 -sndloop -sr -statevar -strtodk -strtolk -syncgrain -tabrec -tb -vco2 -vco2ft -vco2ift -vco2init -vdelay3 -vstaudio, vstaudiog -vstbankload -vstedit -vstinfo -vstinit -vstmidiout -vstnote -vstparamset, vstparamget -vstprogset - -======================================================================== -Module ./libeqfil.so - eqfil -Module ./libgabnew.so - hvs1 - hvs2 - hvs3 - vphaseseg - vtable1k - trandom - lposcila - lposcilsa - lposcilsa2 - slider8table - slider16table - slider32table - slider64table - slider8tablef - slider16tablef - slider32tablef - slider64tablef - sliderKawai - ctrl7.a - tabmorph - tabmorphi - tabmorpha - tabmorphak -Module ./libampmidid.so - kampmidid - iampmidid -Module ./libgrain4.so - granule -Module ./libbarmodel.so - barmodel - prepiano -Module ./libcompress.so - compress - distort -Module ./libcs_date.so - date - dates -Module ./libcs_pan2.so - pan2 -Module ./libcs_pvs_ops.so - pvsifd - partials - tradsyn - sinsyn - resyn - trscale - trshift - trsplit - trmix - trlowest - trhighest - trfilter - trcross - binit - pvsfwrite - pvsfilter - pvscale - pvshift - pvsmix - pvsfilter - pvsblur - pvstencil - pvsinit - pvsbin - pvsfreeze - pvsmooth - pvsosc - pvsdiskin - pvscent - pvspitch - pvsdemix - pvsbandp - pvsbandr -Module ./libharmon.so - harmon2 - harmon3 - harmon4 -Module ./libhrtfnew.so - hrtfmove - hrtfstat - hrtfmove2 -Module ./libimage.so - imageload - imagecreate - imagesize - imagegetpixel - imagesetpixel - imagesave - imagefree -Module ./libloscilx.so - sndload - loscilx -Module ./libminmax.so - maxaccum - minaccum - maxabsaccum - minabsaccum - max - min - maxabs - minabs - max.a - min.a - maxabs.a - minabs.a - max.k - min.k - maxabs.k - minabs.k -Module ./libmixer.so - MixerSetLevel - MixerGetLevel - MixerSend - MixerReceive - MixerClear -Module ./libmodal4.so - marimba - vibes - gogobel -Module ./libmutexops.so - mutex_lock - mutex_unlock - mutex_locki - mutex_unlocki -Module ./libogg.so - oggread -Module ./libosc.so - OSCsend - OSCrecv - OSCinit - OSClisten -Module ./libpartikkel.so - partikkel - partikkelsync -Module ./libphisem.so - cabasa - crunch - sekere - sandpaper - stix - guiro - tambourine - bamboo - dripwater - sleighbells -Module ./libphysmod.so - wgclar - wgflute - wgbow - wgbrass - mandol - voice - fmbell - fmrhode - fmwurlie - fmmetal - fmb3 - fmvoice - fmpercfl - moog - shaker - wgbowedbar -Module ./libpitch.so - spectrum - specaddm - specdiff - specscal - spechist - specfilt - specptrk - specsum - specdisp - pitch - maca - mac - clockon - clockoff - readclock - pitchamdf - hsboscil - phasorbnk - adsynt - mpulse - lpf18 - waveset - pinkish - noise - transeg - clip - cpuprc - maxalloc - active - active.i - active.k - p.i - p.k - mute - oscilv - oscilv.kk - oscilv.ka - oscilv.ak - oscilv.aa -Module ./libptrack.so - ptrack -Module ./libpvoc.so - pvoc - tableseg - ktableseg - tablexseg - vpvoc - pvread - pvcross - pvbufread - pvinterp - pvadd -Module ./libpvsbuffer.so - pvsbuffer - pvsbufread -Module ./libscansyn.so - scanu - scans - xscanu - xscans - xscanmap - xscansmap -Module ./libscoreline.so - scoreline_i - scoreline -Module ./libsfont.so - sfload - sfpreset - sfplay - sfplaym - sfplist - sfilist - sfpassign - sfinstrm - sfinstr - sfplay3 - sfplay3m - sfinstr3 - sfinstr3m - sflooper -Module ./libshape.so - powershape - polynomial - chebyshevpoly - pdclip - pdhalf - pdhalfy - syncphasor -Module ./libstackops.so - stack - push - pop - push_f - pop_f - monitor -Module ./libstdopcod.so - bbcutm - bbcuts - biquad - biquada - moogvcf - moogvcf2 - rezzy - bqrez - distort1 - vco - tbvcf - planet - pareq - nestedap - lorenz - mode - butterhp - butterlp - butterbp - butterbr - buthp - butlp - butbp - butbr - clfilt - cross2 - dam - dcblock - filter2 - filter2.a - filter2.k - zfilter2 - flanger - wguide1 - wguide2 - follow - follow2 - fprints - fprintks - vincr - clear - fout - foutk - fouti - foutir - fiopen - ficlose - fin - fink - fini - freeverb - ftconv - ftgen - ftgentmp - ftfree - ftsave - ftload - ftsavek - ftloadk - resonxk - tab_i - tab - tabw_i - tabw - tb0_init - tb1_init - tb2_init - tb3_init - tb4_init - tb5_init - tb6_init - tb7_init - tb8_init - tb9_init - tb10_init - tb11_init - tb12_init - tb13_init - tb14_init - tb15_init - tb0.k - tb1.k - tb2.k - tb3.k - tb4.k - tb5.k - tb6.k - tb7.k - tb8.k - tb9.k - tb10.k - tb11.k - tb12.k - tb13.k - tb14.k - tb15.k - tb0.i - tb1.i - tb2.i - tb3.i - tb4.i - tb5.i - tb6.i - tb7.i - tb8.i - tb9.i - tb10.i - tb11.i - tb12.i - tb13.i - tb14.i - tb15.i - nlalp - adsynt2 - exitnow - tabrec - tabplay - changed - max_k - maxk - mandel - vtablei - vtablek - vtablea - vtablewi - vtablewk - vtablewa - vtabi - vtabk - vtaba - vtabwi - vtabwk - vtabwa - vadd - vadd_i - vmult - vmult_i - vpow - vpow_i - vexp - vexp_i - vaddv - vaddv_i - vsubv - vsubv_i - vmultv - vmultv_i - vdivv - vdivv_i - vpowv - vpowv_i - vexpv - vexpv_i - vcopy - vcopy_i - vmap - vlimit - vwrap - vmirror - vlinseg - vexpseg - vrandh - vrandi - vport - vecdelay - vdelayk - vcella - grain - locsig - locsend - lowres - lowresx - vlowres - metro - splitrig - timedseq - ctrl14 - ctrl21 - ctrl7 - midic14 - midic21 - midic7 - midic7.i - midic7.k - midic14.i - midic14.k - midic21.i - midic21.k - ctrl7.i - ctrl7.k - ctrl14.i - ctrl14.k - ctrl21.i - ctrl21.k - initc7 - initc14 - initc21 - midipgm - s16b14 - s32b14 - slider16 - slider32 - slider64 - slider8 - slider8.k - slider8f - slider8.i - slider16.k - slider16f - slider16.i - slider32.k - slider32f - slider32.i - slider64.k - slider64f - slider64.i - s16b14.k - s32b14.k - s16b14.i - s32b14.i - moogladder - statevar - fofilter - pcount - pindex - nlfilt - oscbnk - grain2 - grain3 - rnd31 - rnd31.i - rnd31.k - rnd31.a - oscilikt - oscilikt.kk - oscilikt.ka - oscilikt.ak - oscilikt.aa - osciliktp - oscilikts - vco2init - vco2ift - vco2ft - vco2 - denorm - delayk - vdel_k - rbjeq - wgpluck - repluck - wgpluck2 - streson - reverbsc - seqtime - seqtime2 - sndloop - flooper - pvsarp - pvsvoc - flooper2 - flooper3 - pvsmorph - sndwarp - sndwarpst - space - spsend - spdist - syncgrain - syncloop - diskgrain - fof - fof2 - harmon - convolve - convle - pconvolve - fog - wrap - wrap.i - wrap.k - wrap.a - mirror - mirror.i - mirror.k - mirror.a - ntrpol.i - ntrpol.k - ntrpol.a - fold - lineto - tlineto - vibrato - vibr - jitter2 - jitter - jspline - loopseg - lpshold - loopsegp - lpsholdp - cuserrnd - duserrnd - random - cuserrnd.i - cuserrnd.k - cuserrnd.a - random.i - random.k - random.a - rspline - randomi - randomh - urd.i - urd.k - urd.a - duserrnd.i - duserrnd.k - duserrnd.a - poscil - poscil.kk - poscil.ka - poscil.ak - poscil.aa - lposcil - poscil3 - lposcil3 - trigger - sum - product - resony - dconv - vcomb - valpass - ftmorf - and.ii - and.kk - and.ka - and.ak - and.aa - or.ii - or.kk - or.ka - or.ak - or.aa - xor.ii - xor.kk - xor.ka - xor.ak - xor.aa - not.i - not.k - not.a - shl.ii - shl.kk - shl.ka - shl.ak - shl.aa - shr.ii - shr.kk - shr.ka - shr.ak - shr.aa - svfilter - hilbert - resonr - resonz - lowpass2 - phaser2 - phaser1 - wterrain - scantable - scanhammer -Module ./libsystem_call.so - system - system_i -Module ./libudprecv.so - sockrecv - sockrecvs - strecv -Module ./libudpsend.so - socksend - socksends - stsend -Module ./libugakbari.so - scale - expcurve - logcurve - gainslider -Module ./libvaops.so - vaget - vaset -Module ./liboggplay.so - oggplay diff -Nru csound-5.17.11~dfsg/Makefile-win32 csound-6.02~dfsg/Makefile-win32 --- csound-5.17.11~dfsg/Makefile-win32 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Makefile-win32 2014-01-07 16:53:47.000000000 +0000 @@ -22,7 +22,7 @@ endif CFLAGS += -I. -IH -DWIN32 -DPIPES -DHAVE_STDINT_H -DHAVE_DIRENT_H CFLAGS += -DHAVE_UNISTD_H -DHAVE_FCNTL_H -DHAVE_SYS_TIME_H -DHAVE_SYS_TYPES_H -CFLAGS += -DHAVE_LIBSNDFILE=1016 -DPIC +CFLAGS += -DPIC LDFLAGS = -L. LIBS = D:/MinGW/bin/libsndfile-1.dll -lgdi32 -luser32 -lkernel32 -lm PYINCDIR = D:/MinGW/Python/include @@ -256,42 +256,6 @@ interfaces/Soundfile.oo interfaces/java_interface_wrap.oo $(CXX) -O2 -shared -o $@ $^ $(LDFLAGS) -Wl,--add-stdcall-alias -Wl,--output-def,_jcsound.def $(CSLIB_LNK) -lstdc++ $(LIBS) -$(CSOUND5GUI): frontends/fltk_gui/ConfigFile.oo \ - frontends/fltk_gui/CsoundAboutWindow_FLTK.oo \ - frontends/fltk_gui/CsoundCopyrightInfo.oo \ - frontends/fltk_gui/CsoundGlobalSettings.oo \ - frontends/fltk_gui/CsoundGlobalSettingsPanel_FLTK.oo \ - frontends/fltk_gui/CsoundGUIConsole.oo \ - frontends/fltk_gui/CsoundGUIConsole_FLTK.oo \ - frontends/fltk_gui/CsoundGUIMain.oo \ - frontends/fltk_gui/CsoundGUIMain_FLTK.oo \ - frontends/fltk_gui/CsoundPerformance.oo \ - frontends/fltk_gui/CsoundPerformanceSettings.oo \ - frontends/fltk_gui/CsoundPerformanceSettingsPanel_FLTK.oo \ - frontends/fltk_gui/CsoundUtilitiesWindow_FLTK.oo \ - frontends/fltk_gui/CsoundUtility.oo \ - frontends/fltk_gui/main.oo \ - interfaces/csPerfThread.oo - $(CXX) -O2 -o $@ $^ $(LDFLAGS) $(FLTK_LIBS) $(CSLIB_LNK) $(LIBS) - -frontends/fltk_gui/%_FLTK.cpp: frontends/fltk_gui/%_FLTK.fl - fluid -c -o $@ -h frontends/fltk_gui/$*_FLTK.hpp $< - -frontends/fltk_gui/CsoundPerformance.oo: \ - frontends/fltk_gui/CsoundPerformance.cpp - $(CXX) $(CFLAGS) -Iinterfaces -c $< -o $@ - -frontends/fltk_gui/CsoundPython.oo: frontends/fltk_gui/CsoundPython.cpp - $(CXX) $(CFLAGS) -Iinterfaces -c $< -o $@ - -frontends/fltk_gui/ConfigFile.cpp: \ - frontends/fltk_gui/CsoundAboutWindow_FLTK.cpp \ - frontends/fltk_gui/CsoundGlobalSettingsPanel_FLTK.cpp \ - frontends/fltk_gui/CsoundGUIConsole_FLTK.cpp \ - frontends/fltk_gui/CsoundGUIMain_FLTK.cpp \ - frontends/fltk_gui/CsoundPerformanceSettingsPanel_FLTK.cpp \ - frontends/fltk_gui/CsoundUtilitiesWindow_FLTK.cpp - clean: -rm `find . -type f \( -name "*.o" -o -name "*.oo" \) -print` -rm `find . -type f \( -name "*.a" -o -name "*.dll" \) -print` @@ -302,6 +266,5 @@ -rm interfaces/python_interface_wrap.h -rm interfaces/java_interface_wrap.cc -rm interfaces/java_interface_wrap.h - -rm frontends/fltk_gui/*_FLTK.cpp frontends/fltk_gui/*_FLTK.hpp -rm frontends/winsound/winsound.cxx frontends/winsound/winsound.h diff -Nru csound-5.17.11~dfsg/OOps/aops.c csound-6.02~dfsg/OOps/aops.c --- csound-5.17.11~dfsg/OOps/aops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/aops.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,5 +1,4 @@ -/* - aops.c: +/* aops.c: Copyright (C) 1991 Barry Vercoe, John ffitch, Gabriel Maldonado @@ -22,13 +21,16 @@ */ #include "csoundCore.h" /* AOPS.C */ -#include "csound.h" #include "aops.h" #include #include #define POW2TABSIZI 4096 -#define POW2MAX 24.0 +#if ULONG_MAX == 18446744073709551615UL +# define POW2MAX (24.0) +#else +# define POW2MAX (15.0) +#endif #define EIPT3 (25.0/3.0) #define LOGTWO (0.69314718055994530942) #define STEPS (32768) @@ -48,29 +50,36 @@ for (i = 0; i < OCTRES; i++) cpsocfrc[i] = POWER(FL(2.0), (MYFLT)i / OCTRES) * ONEPT; for (i = 0; i < POW2TABSIZI; i++) - powerof2[i] = POWER(FL(2.0), (MYFLT)i * (MYFLT)(1.0/POW2TABSIZI) - FL(POW2MAX)); + powerof2[i] = POWER(FL(2.0), + (MYFLT)i * (MYFLT)(1.0/POW2TABSIZI) - FL(POW2MAX)); }*/ /* initialise the tables, called by csoundPreCompile() */ void csound_aops_init_tables(CSOUND *csound) { int i; - if(csound->cpsocfrc==NULL)csound->cpsocfrc = (MYFLT *) csound->Malloc(csound, sizeof(MYFLT)*OCTRES); - if(csound->powerof2==NULL) csound->powerof2 = (MYFLT *) csound->Malloc(csound, sizeof(MYFLT)*POW2TABSIZI); + if (csound->cpsocfrc==NULL) + csound->cpsocfrc = (MYFLT *) csound->Malloc(csound, sizeof(MYFLT)*OCTRES); + if (csound->powerof2==NULL) + csound->powerof2 = (MYFLT *) csound->Malloc(csound, + sizeof(MYFLT)*POW2TABSIZI); for (i = 0; i < OCTRES; i++) csound->cpsocfrc[i] = POWER(FL(2.0), (MYFLT)i / OCTRES) * ONEPT; - for (i = 0; i < POW2TABSIZI; i++) - csound->powerof2[i] = POWER(FL(2.0), (MYFLT)i * (MYFLT)(1.0/POW2TABSIZI) - FL(POW2MAX)); + for (i = 0; i < POW2TABSIZI; i++) { + csound->powerof2[i] = + POWER(FL(2.0), (MYFLT)i * (MYFLT)(1.0/POW2TABSIZI) - FL(POW2MAX)); + } } -MYFLT csoundPow2(CSOUND *csound, MYFLT a){ - - if(a > POW2MAX) a = POW2MAX; - else if(a < -POW2MAX) a = -POW2MAX; - int n = (int)MYFLT2LRND(a * FL(POW2TABSIZI)) + POW2MAX*POW2TABSIZI; /* 4096 * 15 */ +MYFLT csoundPow2(CSOUND *csound, MYFLT a) +{ + int n; + if (a > POW2MAX) a = POW2MAX; + else if (a < -POW2MAX) a = -POW2MAX; + /* 4096 * 15 */ + n = (int)MYFLT2LRND(a * FL(POW2TABSIZI)) + POW2MAX*POW2TABSIZI; return ((MYFLT) (1UL << (n >> 12)) * csound->powerof2[n & (POW2TABSIZI-1)]); - } @@ -83,37 +92,59 @@ int rassign(CSOUND *csound, ASSIGN *p) { /* already assigned by otran */ + IGN(csound); + IGN(p); return OK; } int assign(CSOUND *csound, ASSIGN *p) { + IGN(csound); *p->r = *p->a; return OK; } int aassign(CSOUND *csound, ASSIGN *p) { - /* the orchestra parser converts '=' to 'upsamp' if input arg is k-rate, */ - /* and skips the opcode if outarg == inarg */ - memcpy(p->r, p->a, csound->ksmps * sizeof(MYFLT)); + uint32_t nsmps = CS_KSMPS; + if (LIKELY(nsmps!=1)) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + /* the orchestra parser converts '=' to 'upsamp' if input arg is k-rate, */ + /* and skips the opcode if outarg == inarg */ + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&p->r[offset], &p->a[offset], (nsmps-offset) * sizeof(MYFLT)); + } + else + *p->r =*p->a; return OK; } int ainit(CSOUND *csound, ASSIGN *p) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; MYFLT aa = *p->a; - int n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) + int n, nsmps = CS_KSMPS; + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) p->r[n] = aa; return OK; } int minit(CSOUND *csound, ASSIGNM *p) { - int nargs = p->INCOUNT; - int i; + unsigned int nargs = p->INCOUNT; + unsigned int i; MYFLT *tmp; if (UNLIKELY(nargs > p->OUTOCOUNT)) return csound->InitError(csound, @@ -136,9 +167,12 @@ int mainit(CSOUND *csound, ASSIGNM *p) { - int nargs = p->INCOUNT; - int i, n, nsmps = csound->ksmps; + unsigned int nargs = p->INCOUNT; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + unsigned int i, n, nsmps = CS_KSMPS; MYFLT aa = FL(0.0); + early = nsmps - early; /* Bit at end to ignore */ if (UNLIKELY(nargs > p->OUTOCOUNT)) return csound->InitError(csound, Str("Cannot be more In arguments than Out in " @@ -147,84 +181,46 @@ aa = *p->a[i]; MYFLT *r =p->r[i]; for (n = 0; n < nsmps; n++) - r[n] = aa; + r[n] = (n < offset || n > early ? FL(0.0) : aa); } for (; iOUTOCOUNT; i++) { MYFLT *r =p->r[i]; + memset(r, '\0', nsmps*sizeof(MYFLT)); for (n = 0; n < nsmps; n++) - r[n] = aa; + r[n] = (n < offset || n > early ? FL(0.0) : aa); } return OK; } -typedef struct { - OPDS h; - TABDAT *tab; -} TABDEL; -static int tabdel(CSOUND *csound, void *p) +int signum(CSOUND *csound, ASSIGN *p) { - TABDAT *t = ((TABDEL*)p)->tab; - mfree(csound, t->data); - mfree(csound, p); + MYFLT a = *p->a; + int ans = (a==FL(0.0) ? 0 : ar = (MYFLT) ans; return OK; } -int tinit(CSOUND *csound, INITT *p) +/* ********COULD BE IMPROVED******** */ +int asignum(CSOUND *csound, ASSIGN *p) { - int size = MYFLT2LRND(*p->size); - MYFLT val = *p->value; - TABDAT *t = p->a; - int i; - - t->size = size; - mfree(csound, t->data); - t->data = mmalloc(csound, sizeof(MYFLT)*(size+1)); - for (i=0; i<=size; i++) t->data[i] = val; - { // Need to recover space eventually - TABDEL *op = (TABDEL*) mmalloc(csound, sizeof(TABDEL)); - op->h.insdshead = ((OPDS*) p)->insdshead; - op->tab = t; - csound->RegisterDeinitCallback(csound, op, tabdel); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + unsigned int i, nsmps = CS_KSMPS; + MYFLT *a = p->a; + memset(p->r, '\0', nsmps*sizeof(MYFLT)); + early = nsmps-early; + for (i=offset; ir[i] = (MYFLT) ans; } return OK; } -int tassign(CSOUND *csound, ASSIGNT *p) -{ - TABDAT *t = p->tab; - int ind = MYFLT2LRND(*p->ind); - if (ind<0 || ind>t->size) - return csound->PerfError(csound, - Str("Index %d out of range [0,%d] in t[]\n"), - ind, t->size); - t->data[ind] = *p->val; - return OK; -} - -int tabref_check(CSOUND *csound, TABREF *p) -{ - if (UNLIKELY(p->tab->data==NULL)) - return csound->InitError(csound, Str("Vector not initialised\n")); - return OK; -} - -int tabref(CSOUND *csound, TABREF *p) -{ - int ind = MYFLT2LRND(*p->ind); - TABDAT *t = p->tab; - if (ind<0 || ind>t->size) - return csound->PerfError(csound, - Str("Index %d out of range [0,%d] in t[]\n"), - ind, t->size); - *p->ans = t->data[ind]; - return OK; -} - #define RELATN(OPNAME,OP) \ int OPNAME(CSOUND *csound, RELAT *p) \ - { *p->rbool = (*p->a OP *p->b) ? 1 : 0; return OK; } + { IGN(csound); *p->rbool = (*p->a OP *p->b) ? 1 : 0; return OK; } RELATN(gt,>) RELATN(ge,>=) @@ -235,13 +231,14 @@ #define LOGCLX(OPNAME,OP) \ int OPNAME(CSOUND *csound, LOGCL *p) \ - { *p->rbool = (*p->ibool OP *p->jbool) ? 1 : 0; return OK; } + { IGN(csound);*p->rbool = (*p->ibool OP *p->jbool) ? 1 : 0; return OK; } LOGCLX(and,&&) LOGCLX(or,||) -#define KK(OPNAME,OP) \ - int OPNAME(CSOUND *csound, AOP *p) { *p->r = *p->a OP *p->b; return OK; } +#define KK(OPNAME,OP) \ + int OPNAME(CSOUND *csound, AOP *p) \ + { IGN(csound); *p->r = *p->a OP *p->b; return OK; } KK(addkk,+) KK(subkk,-) @@ -262,21 +259,34 @@ int modkk(CSOUND *csound, AOP *p) { + IGN(csound); *p->r = MOD(*p->a, *p->b); return OK; } #define KA(OPNAME,OP) \ int OPNAME(CSOUND *csound, AOP *p) { \ - int n; \ - MYFLT *r, a, *b; \ - int nsmps = csound->ksmps; \ - r = p->r; \ - a = *p->a; \ - b = p->b; \ - for (n=0; nh.insdshead->ksmps_offset; \ + uint32_t early = p->h.insdshead->ksmps_no_end; \ + r = p->r; \ + a = *p->a; \ + b = p->b; \ + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); \ + if (UNLIKELY(early)) { \ + nsmps -= early; \ + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); \ + } \ + for (n=offset; nr = *p->a OP *p->b; \ + return OK; \ + } \ } KA(addka,+) @@ -284,63 +294,102 @@ KA(mulka,*) KA(divka,/) +/* ********COULD BE IMPROVED******** */ int modka(CSOUND *csound, AOP *p) { - int n; MYFLT *r, a, *b; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; r = p->r; a = *p->a; b = p->b; - for (n=0; nksmps; \ - r = p->r; \ - a = p->a; \ - b = *p->b; \ - for (n=0; nh.insdshead->ksmps_offset; \ + uint32_t early = p->h.insdshead->ksmps_no_end; \ + r = p->r; \ + a = p->a; \ + b = *p->b; \ + if (UNLIKELY(offset)) \ + memset(r, '\0', offset*sizeof(MYFLT)); \ + if (UNLIKELY(early)) { \ + nsmps -= early; \ + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); \ + } \ + for (n=offset; nr[0] = p->a[0] OP *p->b; \ + return OK; \ + } \ +} AK(addak,+) AK(subak,-) AK(mulak,*) AK(divak,/) +/* ********COULD BE IMPROVED******** */ int modak(CSOUND *csound, AOP *p) { - int n; MYFLT *r, *a, b; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; r = p->r; a = p->a; b = *p->b; - for (n=0; nksmps; \ + MYFLT *r, *a, *b; \ + uint32_t n, nsmps = CS_KSMPS; \ + if (LIKELY(nsmps!=1)) { \ + uint32_t offset = p->h.insdshead->ksmps_offset; \ + uint32_t early = p->h.insdshead->ksmps_no_end; \ r = p->r; \ a = p->a; \ b = p->b; \ - for (n=0; nr = *p->a OP *p->b; \ + return OK; \ + } \ } AA(addaa,+) @@ -348,77 +397,110 @@ AA(mulaa,*) AA(divaa,/) +/* ********COULD BE IMPROVED******** */ int modaa(CSOUND *csound, AOP *p) { - int n; MYFLT *r, *a, *b; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; r = p->r; a = p->a; b = p->b; - for (n=0; nr = (*p->b != FL(0.0) ? *p->a / *p->b : *p->def); return OK; } +/* ********COULD BE IMPROVED******** */ int divzka(CSOUND *csound, DIVZ *p) { - int n; - MYFLT *r, a, *b, def; - int nsmps = csound->ksmps; + uint32_t n; + MYFLT *r, a, *b, def; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; r = p->r; a = *p->a; b = p->b; def = *p->def; - for (n=0; nksmps; + uint32_t n; + MYFLT *r, *a, b, def; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; r = p->r; a = p->a; b = *p->b; def = *p->def; + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } if (UNLIKELY(b==FL(0.0))) { - for (n=0; nksmps; + uint32_t n; + MYFLT *r, *a, *b, def; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; r = p->r; a = p->a; b = p->b; def = *p->def; - for (n=0; ncond) *p->r = *p->a; else @@ -426,33 +508,50 @@ return OK; } +/* ********COULD BE IMPROVED******** */ int aconval(CSOUND *csound, CONVAL *p) { + uint32_t offset = p->h.insdshead->ksmps_offset*sizeof(MYFLT); + uint32_t early = p->h.insdshead->ksmps_no_end*sizeof(MYFLT); MYFLT *r, *s; r = p->r; if (*p->cond) s = p->a; else s = p->b; - if (r!=s) memcpy(r, s, csound->ksmps*sizeof(MYFLT)); + if (r!=s) { + memset(r, '\0', offset); + memcpy(&r[offset], &s[offset], CS_KSMPS*sizeof(MYFLT)-offset-early); + memset(&r[offset-early], '\0', early); + } return OK; } int int1(CSOUND *csound, EVAL *p) /* returns signed whole no. */ { MYFLT intpart; + IGN(csound); MODF(*p->a, &intpart); *p->r = intpart; return OK; } +/* ********COULD BE IMPROVED******** */ int int1a(CSOUND *csound, EVAL *p) /* returns signed whole no. */ { - MYFLT intpart; - int n; - for (n = 0; n < csound->ksmps; n++) { - MODF(p->a[n], &intpart); - p->r[n] = intpart; + MYFLT intpart, *a=p->a, *r=p->r; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { + MODF(a[n], &intpart); + r[n] = intpart; } return OK; } @@ -460,18 +559,28 @@ int frac1(CSOUND *csound, EVAL *p) /* returns positive frac part */ { MYFLT intpart, fracpart; + IGN(csound); fracpart = MODF(*p->a, &intpart); *p->r = fracpart; return OK; } +/* ********COULD BE IMPROVED******** */ int frac1a(CSOUND *csound, EVAL *p) /* returns positive frac part */ { - MYFLT intpart, fracpart; - int n; - for (n = 0; n < csound->ksmps; n++) { - fracpart = MODF(p->a[n], &intpart); - p->r[n] = fracpart; + MYFLT intpart, fracpart, *r = p->r, *a = p->a; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { + fracpart = MODF(a[n], &intpart); + r[n] = fracpart; } return OK; } @@ -488,43 +597,76 @@ int int1_round(CSOUND *csound, EVAL *p) /* round to nearest integer */ { + IGN(csound); *p->r = (MYFLT) MYFLT2LRND(*p->a); return OK; } +/* ********COULD BE IMPROVED******** */ int int1a_round(CSOUND *csound, EVAL *p) /* round to nearest integer */ { - int n, nsmps = csound->ksmps; - for (n = 0; n < nsmps; n++) - p->r[n] = (MYFLT)MYFLT2LRND(p->a[n]); - return OK; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + MYFLT *r=p->r, *a=p->a; + + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) + r[n] = (MYFLT)MYFLT2LRND(a[n]); + return OK; } int int1_floor(CSOUND *csound, EVAL *p) /* round down */ { + IGN(csound); *p->r = (MYFLT)(MYFLOOR(*p->a)); return OK; } +/* ********COULD BE IMPROVED******** */ int int1a_floor(CSOUND *csound, EVAL *p) /* round down */ { - int n, nsmps = csound->ksmps; - for (n = 0; n < nsmps; n++) - p->r[n] = (MYFLT)(MYFLOOR(p->a[n])); + MYFLT *a=p->a, *r=p->r; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) + r[n] = (MYFLT)(MYFLOOR(a[n])); return OK; } int int1_ceil(CSOUND *csound, EVAL *p) /* round up */ { + IGN(csound); *p->r = (MYFLT)(MYCEIL(*p->a)); return OK; } +/* ********COULD BE IMPROVED******** */ int int1a_ceil(CSOUND *csound, EVAL *p) /* round up */ { - int n, nsmps = csound->ksmps; - for (n = 0; n < nsmps; n++) - p->r[n] = (MYFLT)(MYCEIL(p->a[n])); + MYFLT *a=p->a, *r=p->r; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) + r[n] = (MYFLT)(MYCEIL(a[n])); return OK; } @@ -547,7 +689,7 @@ } #define LIB1(OPNAME,LIBNAME) int OPNAME(CSOUND *csound, EVAL *p) \ - { *p->r = LIBNAME(*p->a); return OK; } + { IGN(csound); *p->r = LIBNAME(*p->a); return OK; } LIB1(abs1,FABS) LIB1(exp01,EXP) LIB1(log01,LOG) @@ -562,20 +704,29 @@ LIB1(cosh1,COSH) LIB1(tanh1,TANH) LIB1(log101,LOG10) +LIB1(log21,LOG2) int atan21(CSOUND *csound, AOP *p) { + IGN(csound); *p->r = ATAN2(*p->a, *p->b); return OK; } +/* ********COULD BE IMPROVED******** */ #define LIBA(OPNAME,LIBNAME) int OPNAME(CSOUND *csound, EVAL *p) { \ - int n; \ + uint32_t offset = p->h.insdshead->ksmps_offset; \ + uint32_t early = p->h.insdshead->ksmps_no_end; \ + uint32_t n, nsmps =CS_KSMPS; \ MYFLT *r, *a; \ - int nsmps = csound->ksmps; \ r = p->r; \ a = p->a; \ - for (n=0;nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; r = p->r; a = p->a; b = p->b; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) r[n] = ATAN2(a[n], b[n]); return OK; } int dbamp(CSOUND *csound, EVAL *p) { + IGN(csound); *p->r = LOG(FABS(*p->a)) / LOG10D20; return OK; } int ampdb(CSOUND *csound, EVAL *p) { + IGN(csound); *p->r = EXP(*p->a * LOG10D20); return OK; } int aampdb(CSOUND *csound, EVAL *p) { - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; MYFLT *r = p->r, *a = p->a; - int nsmps = csound->ksmps; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) r[n] = EXP(a[n] * LOG10D20); return OK; } @@ -643,15 +810,22 @@ return OK; } +/* ********COULD BE IMPROVED******** */ int aampdbfs(CSOUND *csound, EVAL *p) { - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; MYFLT *r, *a; - int nsmps = csound->ksmps; r = p->r; a = p->a; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) r[n] = csound->e0dbfs * EXP(a[n] * LOG10D20); return OK; } @@ -750,6 +924,7 @@ int octpch(CSOUND *csound, EVAL *p) { + IGN(csound); double fract, oct; fract = modf((double)*p->a, &oct); fract *= EIPT3; @@ -759,6 +934,7 @@ int pchoct(CSOUND *csound, EVAL *p) { + IGN(csound); double fract, oct; fract = modf((double)*p->a, &oct); fract *= 0.12; @@ -768,6 +944,7 @@ int cpsoct(CSOUND *csound, EVAL *p) { + IGN(csound); int loct = (int)(*p->a * OCTRES); *p->r = (MYFLT)CPSOCTL(loct); return OK; @@ -777,11 +954,18 @@ { MYFLT *r, *a; int loct; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; a = p->a; r = p->r; - for (n=0; nr = (LOG(*p->a /(MYFLT)ONEPT) / (MYFLT)LOGTWO); return OK; } @@ -798,7 +983,7 @@ { double fract, oct; int loct; - + IGN(csound); fract = modf((double)*p->a, &oct); fract *= EIPT3; loct = (int)((oct + fract) * OCTRES); @@ -808,16 +993,14 @@ int cpsmidinn(CSOUND *csound, EVAL *p) { - /* Convert Midi Note number to 8ve.decimal format */ - MYFLT oct = (*p->a / FL(12.0)) + FL(MIDINOTE0); - /* Lookup in cpsoct table */ - int32 loct = (int32)(oct * OCTRES); - *p->r = (MYFLT)CPSOCTL(loct); + IGN(csound); + *p->r = pow(FL(2.0), (*p->a - FL(69.0)) / FL(12.0)) * FL(440.0); return OK; } int octmidinn(CSOUND *csound, EVAL *p) { + IGN(csound); /* Convert Midi Note number to 8ve.decimal format */ *p->r = (*p->a / FL(12.0)) + FL(MIDINOTE0); return OK; @@ -825,6 +1008,7 @@ int pchmidinn(CSOUND *csound, EVAL *p) { + IGN(csound); double fract, oct, octdec; /* Convert Midi Note number to 8ve.decimal format */ octdec = ((double)*p->a / 12.0) + MIDINOTE0; @@ -850,7 +1034,7 @@ FUNC* ftp = csound->FTnp2Find(csound, &t); int32 len; if (UNLIKELY(ftp == NULL)) - return csound->PerfError(csound, Str("No tuning table %d"), + return csound->PerfError(csound, p->h.insdshead,Str("No tuning table %d"), -((int)*p->et)); len = ftp->flen; while (fract>len) { @@ -878,7 +1062,7 @@ FUNC* ftp = csound->FTnp2Find(csound, &t); int32 len; if (UNLIKELY(ftp == NULL)) - return csound->PerfError(csound, Str("No tuning table %d"), + return csound->PerfError(csound, p->h.insdshead,Str("No tuning table %d"), -((int)*p->et)); len = ftp->flen; while (fract>len) { @@ -923,7 +1107,7 @@ *p->r = func[grade] * factor * basefreq; return OK; err1: - return csound->PerfError(csound, Str("cpstun: invalid table")); + return csound->PerfError(csound, p->h.insdshead,Str("cpstun: invalid table")); } int cpstun(CSOUND *csound, CPSTUN *p) @@ -961,11 +1145,12 @@ else *p->r = p->old_r; return OK; err1: - return csound->PerfError(csound, Str("cpstun: invalid table")); + return csound->PerfError(csound, p->h.insdshead,Str("cpstun: invalid table")); } int logbasetwo_set(CSOUND *csound, EVAL *p) { + IGN(p); if (UNLIKELY(csound->logbase2 == NULL)) { double x = (1.0 / INTERVAL); int i; @@ -985,11 +1170,20 @@ return OK; } +/* ********COULD BE IMPROVED******** */ int powoftwoa(CSOUND *csound, EVAL *p) { /* by G.Maldonado, liberalised by JPff */ - int n, nsmps = csound->ksmps; - for (n = 0; n < nsmps; n++) - p->r[n] = csound->Pow2(csound,p->a[n]); + MYFLT *a=p->a, *r=p->r; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) + r[n] = csound->Pow2(csound,a[n]); return OK; } @@ -1006,11 +1200,17 @@ int asemitone(CSOUND *csound, EVAL *p) /* JPff */ { MYFLT *r, *a; - int n; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; a = p->a; r = p->r; - for (n=0; nPow2(csound,aa); } @@ -1024,14 +1224,21 @@ return OK; } +/* ********COULD BE IMPROVED******** */ int acent(CSOUND *csound, EVAL *p) /* JPff */ { MYFLT *r, *a; - int n; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; a = p->a; r = p->r; - for (n=0; nPow2(csound,aa); } @@ -1046,14 +1253,21 @@ return OK; } +/* ********COULD BE IMPROVED******** */ int dba(CSOUND *csound, EVAL *p) /* JPff */ { MYFLT *r, *a; - int n; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; a = p->a; r = p->r; - for (n=0; nPow2(csound,aa*LOG2_10D20); } @@ -1074,11 +1288,17 @@ int logbasetwoa(CSOUND *csound, EVAL *p) { /* by G.Maldonado liberalised by JPff */ MYFLT *r, *a; - int n; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS; a = p->a; r = p->r; - for (n=0; nh.insdshead->ksmps_offset*sizeof(MYFLT); + uint32_t early = p->h.insdshead->ksmps_no_end; + CSOUND_SPIN_SPINLOCK - memcpy(p->ar, csound->spin, csound->ksmps * sizeof(MYFLT)); + if (UNLIKELY(offset)) memset(p->ar, '\0', offset); + memcpy(&p->ar[offset], CS_SPIN, (CS_KSMPS-early) * sizeof(MYFLT)-offset); + if (UNLIKELY(early)) + memset(&p->ar[CS_KSMPS-early], '\0', early * sizeof(MYFLT)); + CSOUND_SPIN_SPINUNLOCK + return OK; +} + +int inarray(CSOUND *csound, INA *p) +{ + MYFLT *data = p->tabout->data; + uint32_t n = p->tabout->sizes[0]; + uint32_t offset = p->h.insdshead->ksmps_offset*sizeof(MYFLT); + uint32_t early = p->h.insdshead->ksmps_no_end; + MYFLT *sp = CS_SPIN; + uint32_t m, nsmps =CS_KSMPS, i; + uint32_t ksmps = nsmps; + + if ((int)n>csound->inchnls) n = csound->inchnls; + CSOUND_SPIN_SPINLOCK + if (UNLIKELY(offset)) for (i = 0; i < n; i++) + memset(&data[i*ksmps], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i = 0; i < n; i++) + memset(&data[nsmps+i*ksmps], '\0', early*sizeof(MYFLT)); + } + for (m = offset; m < nsmps; m++) { + for (i = 0; i < n; i++) + data[m+i*ksmps] = *sp++; + } CSOUND_SPIN_SPINUNLOCK return OK; } @@ -1106,13 +1359,23 @@ int ins(CSOUND *csound, INS *p) { MYFLT *sp, *ar1, *ar2; - int n, k; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS, k; CSOUND_SPIN_SPINLOCK - sp = csound->spin; + sp = CS_SPIN; ar1 = p->ar1; ar2 = p->ar2; - for (n=0, k=0; nar1[nsmps],'\0', early * sizeof(MYFLT)); + memset(&p->ar2[nsmps], '\0', early * sizeof(MYFLT)); + } + for (n=offset, k=0; nspin, *ar1 = p->ar1, *ar2 = p->ar2, + MYFLT *sp = CS_SPIN, *ar1 = p->ar1, *ar2 = p->ar2, *ar3 = p->ar3, *ar4 = p->ar4; - int n, k; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS, k; CSOUND_SPIN_SPINLOCK - for (n=0, k=0; nspin, *ar1 = p->ar1, *ar2 = p->ar2, *ar3 = p->ar3, + MYFLT *sp = CS_SPIN, *ar1 = p->ar1, *ar2 = p->ar2, *ar3 = p->ar3, *ar4 = p->ar4, *ar5 = p->ar5, *ar6 = p->ar6; - int n, k; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS, k; CSOUND_SPIN_SPINLOCK - for (n=0, k=0; nspin, *ar1 = p->ar1, *ar2 = p->ar2, *ar3 = p->ar3, + MYFLT *sp = CS_SPIN, *ar1 = p->ar1, *ar2 = p->ar2, *ar3 = p->ar3, *ar4 = p->ar4, *ar5 = p->ar5, *ar6 = p->ar6, *ar7 = p->ar7, *ar8 = p->ar8; - int n, k; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps =CS_KSMPS, k; CSOUND_SPIN_SPINLOCK - for (n=0, k=0; nspin, **ara = p->ar; - int m; - int i; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPIN, **ara = p->ar; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t m, nsmps =CS_KSMPS, i; + CSOUND_SPIN_SPINLOCK - for (m = 0; m < nsmps; m++) { + if (UNLIKELY(offset)) for (i = 0; i < n; i++) + memset(ara[i], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i = 0; i < n; i++) + memset(ara[i], '\0', early*sizeof(MYFLT)); + } + for (m = offset; m < nsmps; m++) { for (i = 0; i < n; i++) *ara[i] = *sp++; } @@ -1195,34 +1520,72 @@ int in16(CSOUND *csound, INALL *p) { - return inn(csound, p, 16); + return inn(csound, p, 16u); } int in32(CSOUND *csound, INALL *p) { - return inn(csound, p, 32); + return inn(csound, p, 32u); +} + +int inch_opcode1(CSOUND *csound, INCH1 *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS, ch; + MYFLT *sp, *ain; + + ch = ((int)*p->ch + FL(0.5)); + if (UNLIKELY(ch > (uint32_t)csound->inchnls)) { + csound->Message(csound, Str("Input channel %d too large; ignored"), ch); + memset(p->ar, 0, sizeof(MYFLT)*nsmps); + // return OK; + } + else { + sp = CS_SPIN + (ch - 1); + ain = p->ar; + if (UNLIKELY(offset)) memset(ain, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ain[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { + ain[n] = *sp; + sp += csound->inchnls; + } + } + + return OK; } + int inch_opcode(CSOUND *csound, INCH *p) { /* Rewritten to allow multiple args upto 40 */ - int nc, nChannels = p->INCOUNT; - int ch, n, nsmps = csound->ksmps; + uint32_t nc, nChannels = p->INCOUNT; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS, ch; MYFLT *sp, *ain; if (UNLIKELY(nChannels != p->OUTOCOUNT)) return - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str("Input and output argument count differs in inch")); for (nc=0; ncch[nc] + FL(0.5)); - if (UNLIKELY(ch > csound->inchnls)) { + if (UNLIKELY(ch > (uint32_t)csound->inchnls)) { csound->Message(csound, Str("Input channel %d too large; ignored"), ch); memset(p->ar[nc], 0, sizeof(MYFLT)*nsmps); // return OK; } else { - sp = csound->spin + (ch - 1); + sp = CS_SPIN + (ch - 1); ain = p->ar[nc]; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(ain, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ain[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { ain[n] = *sp; sp += csound->inchnls; } @@ -1231,137 +1594,51 @@ return OK; } -/* int inch_opcode(CSOUND *csound, INCH *p) */ -/* { */ -/* int ch = (int)(*p->ch + FL(0.5)); */ -/* int n; */ -/* int nsmps = csound->ksmps; */ -/* MYFLT *sp = csound->spin + (ch - 1); */ -/* MYFLT *ain = p->ar; */ -/* if (UNLIKELY(ch > csound->inchnls)) { */ -/* return NOTOK; */ -/* } */ -/* /\* Are APINLOCKS really necessary for reading?? *\/ */ -/* CSOUND_SPIN_SPINLOCK */ -/* for (n = 0; n < nsmps; n++) { */ -/* ain[n] = *sp; */ -/* sp += csound->inchnls; */ -/* } */ -/* CSOUND_SPIN_SPINUNLOCK */ -/* return OK; */ -/* } */ int inall_opcode(CSOUND *csound, INALL *p) { - int n = (int)p->OUTOCOUNT; - int m; - int i, j = 0, k = 0, nsmps = csound->ksmps; - MYFLT *spin = csound->spin; + uint32_t n = (int)p->OUTOCOUNT, m; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t i,j = 0, k = 0, nsmps = CS_KSMPS; + uint32_t early = nsmps - p->h.insdshead->ksmps_no_end; + MYFLT *spin = CS_SPIN; CSOUND_SPIN_SPINLOCK - m = (n < csound->inchnls ? n : csound->inchnls); - for (j=0; jar[i][j] = spin[k + i]; - } - for ( ; i < n; i++) - p->ar[i][j] = FL(0.0); - k += csound->inchnls; - } - CSOUND_SPIN_SPINUNLOCK - return OK; -} - -#if 0 -int out(CSOUND *csound, OUTM *p) -{ - int n; - int nsmps = csound->ksmps; - MYFLT *smp = p->asig; - CSOUND_SPOUT_SPINLOCK - if (!csound->spoutactive) { - memcpy(csound->spout, smp, nsmps * sizeof(MYFLT)); - csound->spoutactive = 1; - } - else { - for (n=0; nspout[n] += smp[n]; - } - CSOUND_SPOUT_SPINUNLOCK - return OK; -} - -int outs(CSOUND *csound, OUTS *p) -{ - MYFLT *sp= csound->spout, *ap1 = p->asig1, *ap2= p->asig2; - int nsmps = csound->ksmps; - CSOUND_SPOUT_SPINLOCK - if (!csound->spoutactive) { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=0; nspoutactive = 1; - } - else { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=0; nspout, *ap1= p->asig1, *ap2= p->asig2, - *ap3= p->asig3, *ap4= p->asig4; - int nsmps = csound->ksmps; - CSOUND_SPOUT_SPINLOCK - sp = csound->spout; - if (!csound->spoutactive) { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=0; ninchnls ? n : (uint32_t)csound->inchnls); + for (j=0; jearly) { + for (i=0 ; i < n; i++) + p->ar[i][j] = FL(0.0); } - csound->spoutactive = 1; - } - else { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=0; nar[i][j] = spin[k + i]; + } + for ( ; i < n; i++) + p->ar[i][j] = FL(0.0); + k += csound->inchnls; } - } - CSOUND_SPOUT_SPINUNLOCK + CSOUND_SPIN_SPINUNLOCK return OK; } -#endif int outs1(CSOUND *csound, OUTM *p) { - MYFLT *sp= csound->spout, *ap1= p->asig; - int nsmps = csound->ksmps; + MYFLT *sp= CS_SPOUT, *ap1= p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; /* Amazingly this compiles better!!! */ for (n=0, m=0; nearly) ? FL(0.0) : ap1[n]; sp[m++] = FL(0.0); } csound->spoutactive = 1; } else { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=0; n=offset) sp[m] += ap1[n]; } } CSOUND_SPOUT_SPINUNLOCK @@ -1370,21 +1647,22 @@ int outs2(CSOUND *csound, OUTM *p) { - MYFLT *sp = csound->spout, *ap2 = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap2 = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; /* Amazingly this compiles better!!! */ for (n=0, m=0; nearly) ? FL(0.0) : ap2[n]; } csound->spoutactive = 1; } else { - int n, m; /* Amazingly this compiles better!!! */ - for (n=0, m=1; n=offset) sp[m] += ap2[n]; } } CSOUND_SPOUT_SPINUNLOCK @@ -1393,22 +1671,25 @@ int outs12(CSOUND *csound, OUTM *p) { - MYFLT *sp = csound->spout, *ap = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; for (n=0, m=0; nearly) ? FL(0.0) : ap[n]; } csound->spoutactive = 1; } else { - int n, m; - for (n=0, m=0; nspout, *ap1 = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap1 = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; for (n=0, m=0; nearly) ? FL(0.0) : ap1[n]; sp[m+1] = FL(0.0); sp[m+2] = FL(0.0); sp[m+3] = FL(0.0); @@ -1431,9 +1713,8 @@ csound->spoutactive = 1; } else { - int n, m; - for (n=0, m=0; n=offset) sp[m] += ap1[n]; } } CSOUND_SPOUT_SPINUNLOCK @@ -1442,23 +1723,23 @@ int outq2(CSOUND *csound, OUTM *p) { - MYFLT *sp = csound->spout, *ap2 = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap2 = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; for (n=0, m=0; nearly) ? FL(0.0) : ap2[n]; sp[m+2] = FL(0.0); sp[m+3] = FL(0.0); } csound->spoutactive = 1; } else { - int n, m; - for (n=0, m=1; n=offset) sp[m] += ap2[n]; } } CSOUND_SPOUT_SPINUNLOCK @@ -1467,23 +1748,23 @@ int outq3(CSOUND *csound, OUTM *p) { - MYFLT *sp = csound->spout, *ap3 = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap3 = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; for (n=0, m=0; nearly) ? FL(0.0) : ap3[n]; sp[m+3] = FL(0.0); } csound->spoutactive = 1; } else { - int n, m; - for (n=0, m=2; n=offset) sp[m] += ap3[n]; } } CSOUND_SPOUT_SPINUNLOCK @@ -1492,177 +1773,184 @@ int outq4(CSOUND *csound, OUTM *p) { - MYFLT *sp = csound->spout, *ap4 = p->asig; - int nsmps = csound->ksmps; + MYFLT *sp = CS_SPOUT, *ap4 = p->asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps =CS_KSMPS, n, m; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; CSOUND_SPOUT_SPINLOCK if (!csound->spoutactive) { - int n, m; for (n=0, m=0; nearly) ? FL(0.0) : ap4[n]; } csound->spoutactive = 1; } else { - int n, m; - for (n=0, m=3; n=offset) sp[m] += ap4[n]; } } CSOUND_SPOUT_SPINUNLOCK return OK; } -#if 0 -int outh(CSOUND *csound, OUTH *p) +inline static int outn(CSOUND *csound, uint32_t n, OUTX *p) { - MYFLT *sp = csound->spout, *ap1 = p->asig1, *ap2 = p->asig2, *ap3 = p->asig3, - *ap4 = p->asig4, *ap5 = p->asig5, *ap6 = p->asig6; - int nsmps = csound->ksmps; - CSOUND_SPOUT_SPINLOCK - if (!csound->spoutactive) { - int n, m; - for (n=0, m=0; noparms->sampleAccurate) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + + CSOUND_SPOUT_SPINLOCK + if (!csound->spoutactive) { + for (j=0; jearly) ? FL(0.0) : p->asig[i][j]; + } + for ( ; i < csound->nchnls; i++) { + CS_SPOUT[k + i] = FL(0.0); + } + k += csound->nchnls; + } + csound->spoutactive = 1; } - csound->spoutactive = 1; + else { + for (j=offset; jasig[i][j]; + } + k += csound->nchnls; + } + } + CSOUND_SPOUT_SPINUNLOCK } else { - int n, m; - for (n=0, m=0; nspoutactive) { + for (j=0; jasig[i][j]; + } + for ( ; i < csound->nchnls; i++) { + CS_SPOUT[k + i] = FL(0.0); + } + k += csound->nchnls; + } + csound->spoutactive = 1; + } + else { + for (j=0; jasig[i][j]; + } + k += csound->nchnls; + } } + CSOUND_SPOUT_SPINUNLOCK } - CSOUND_SPOUT_SPINUNLOCK return OK; } -int outo(CSOUND *csound, OUTO *p) +int outall(CSOUND *csound, OUTX *p) /* Output a list of channels */ { - MYFLT *sp = csound->spout, *ap1 = p->asig1, *ap2 = p->asig2, *ap3 = p->asig3, - *ap4 = p->asig4, *ap5 = p->asig5, *ap6 = p->asig6, - *ap7 = p->asig7, *ap8 = p->asig8; - int nsmps = csound->ksmps; - CSOUND_SPOUT_SPINLOCK - if (!csound->spoutactive) { - int n, m; - for (n=0, m=0; nspoutactive = 1; - } - else { - int n, m; - for (n=0, m=0; nINOCOUNT; + + return outn(csound, (nch <= csound->nchnls ? nch : csound->nchnls), p); } -#endif -static int outn(CSOUND *csound, int n, OUTX *p) +int outarr(CSOUND *csound, OUTARRAY *p) { - int i, j = 0, k = 0; - int nsmps = csound->ksmps; - CSOUND_SPOUT_SPINLOCK - if (!csound->spoutactive) { - for (j=0; jspout[k + i] = p->asig[i][j]; + uint32_t nsmps =CS_KSMPS, i, j, k=0; + uint32_t ksmps = nsmps; + uint32_t n = p->tabin->sizes[0]; + MYFLT *data = p->tabin->data; + if (csound->oparms->sampleAccurate) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + + CSOUND_SPOUT_SPINLOCK + if (!csound->spoutactive) { + for (j=0; jearly) ? FL(0.0) : data[j+i*ksmps]; + } + for ( ; i < csound->nchnls; i++) { + CS_SPOUT[k + i] = FL(0.0); + } + k += csound->nchnls; } - for ( ; i < csound->nchnls; i++) { - csound->spout[k + i] = FL(0.0); + csound->spoutactive = 1; + } + else { + for (j=offset; jnchnls; } - k += csound->nchnls; } - csound->spoutactive = 1; + CSOUND_SPOUT_SPINUNLOCK } else { - for (j=0; jspout[k + i] += p->asig[i][j]; + CSOUND_SPOUT_SPINLOCK + + if (!csound->spoutactive) { + for (j=0; jnchnls; i++) { + CS_SPOUT[k + i] = FL(0.0); + } + k += csound->nchnls; + } + csound->spoutactive = 1; + } + else { + for (j=0; jnchnls; } - k += csound->nchnls; } + CSOUND_SPOUT_SPINUNLOCK } - CSOUND_SPOUT_SPINUNLOCK return OK; } -#if 0 -int outx(CSOUND *csound, OUTX *p) -{ - return outn(csound, 16, p); -} - -int outX(CSOUND *csound, OUTX *p) -{ - return outn(csound, 32, p); -} -#endif - -int outall(CSOUND *csound, OUTX *p) /* Output a list of channels */ -{ - int nch = (int)p->INOCOUNT; - return outn(csound, (nch <= csound->nchnls ? nch : csound->nchnls), p); -} - int outch(CSOUND *csound, OUTCH *p) { - int ch; - int i, j; + uint32_t ch; MYFLT *sp, *apn; - int n, nsmps = csound->ksmps; - int count = (int)p->INOCOUNT; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t nsmps = CS_KSMPS, i, j, n; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + uint32_t count = p->INOCOUNT; MYFLT **args = p->args; - int nchnls = csound->nchnls; + uint32_t nchnls = csound->nchnls; CSOUND_SPOUT_SPINLOCK for (j = 0; j < count; j += 2) { ch = (int)(*args[j] + FL(0.5)); apn = args[j + 1]; if (ch > nchnls) continue; if (!csound->spoutactive) { - sp = csound->spout; + sp = CS_SPOUT; for (n=0; n=offset && nspoutactive = 1; } else { - sp = csound->spout + (ch - 1); - for (n=0; n=offset)*/ *sp += apn[n]; sp += nchnls; } } @@ -1671,166 +1959,146 @@ return OK; } -/* k-rate and string i/o opcodes */ -/* invalue and outvalue are used with the csoundAPI */ -/* ma++ ingalls matt@sonomatics.com */ - -int kinval(CSOUND *csound, INVAL *p) -{ - if (csound->InputValueCallback_) - csound->InputValueCallback_(csound, - (char*) p->channelName.auxp, p->value); - else - *(p->value) = FL(0.0); - +int is_NaN(CSOUND *csound, ASSIGN *p) +{ + IGN(csound); + *p->r = isnan(*p->a); return OK; } -int invalset(CSOUND *csound, INVAL *p) +/* ********COULD BE IMPROVED******** */ +int is_NaNa(CSOUND *csound, ASSIGN *p) { - if (p->XSTRCODE) { - const char *s = (char*) p->valID; - - /* check for starting with a $, which will confuse hosts - -- pretty unlikely given that the parser thinks - "$string" is a macro -- but just in case: */ - if (UNLIKELY(*s == '$')) - return csound->InitError(csound, Str("k-rate invalue ChannelName " - "cannot start with $")); - /* allocate the space used to pass a string during the k-pass */ - csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); - sprintf((char*) p->channelName.auxp, "%s", s); - } - else { - /* convert numerical channel to string name */ - csound->AuxAlloc(csound, 64, &p->channelName); - sprintf((char*) p->channelName.auxp, "%d", (int)MYFLT2LRND(*p->valID)); - } - - /* grab input now for use during i-pass */ - kinval(csound, p); - + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t k, nsmps = CS_KSMPS; + uint32_t early = nsmps - p->h.insdshead->ksmps_no_end; + MYFLT *a = p->a; + *p->r = FL(0.0); + for (k=offset; kr += isnan(a[k]); return OK; } -int kinval_S(CSOUND *csound, INVAL *p) +int is_inf(CSOUND *csound, ASSIGN *p) { - ((char*) p->value)[0] = (char) 0; - /* make sure the output is null-terminated with old hosts that */ - /* are not aware of string channels */ - ((char*) p->value)[sizeof(MYFLT)] = (char) 0; - - if (csound->InputValueCallback_) - csound->InputValueCallback_(csound, - (char*) p->channelName.auxp, p->value); - + IGN(csound); + *p->r = isinf(*p->a); return OK; } -int invalset_S(CSOUND *csound, INVAL *p) +/* ********COULD BE IMPROVED******** */ +int is_infa(CSOUND *csound, ASSIGN *p) { - if (p->XSTRCODE) { - const char *s = (char*) p->valID; - csound->AuxAlloc(csound, strlen(s) + 2, &p->channelName); - sprintf((char*) p->channelName.auxp, "$%s", s); - } - else { - csound->AuxAlloc(csound, 64, &p->channelName); - sprintf(p->channelName.auxp, "$%d", (int)MYFLT2LRND(*p->valID)); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t k, nsmps = CS_KSMPS; + uint32_t early = nsmps-p->h.insdshead->ksmps_no_end; + MYFLT *a = p->a; + MYFLT ans = FL(0.0); + int sign = 1; + for (k=offset; kr = ans*sign; return OK; } -int koutval(CSOUND *csound, OUTVAL *p) +int error_fn(CSOUND *csound, ERRFN *p) { - char *chan = (char*)p->channelName.auxp; - - if (csound->OutputValueCallback_) { - if (p->XSTRCODE & 2) { - /* a hack to support strings */ - int32 len = strlen(chan); - strcat(chan, (char*)p->value); - csound->OutputValueCallback_(csound, chan, (MYFLT)len); - chan[len] = '\0'; /* clear for next time */ - } - else - csound->OutputValueCallback_(csound, chan, *(p->value)); - } - - return OK; + IGN(p); + return csound->InitError(csound, Str("Unknown function called")); } -int outvalset(CSOUND *csound, OUTVAL *p) + /* ------------------------------------------------------------------------ */ + +int monitor_opcode_perf(CSOUND *csound, MONITOR_OPCODE *p) { - if (p->XSTRCODE & 1) { - const char *s = (char*) p->valID; - if (p->XSTRCODE & 2) { - /* allocate the space used to pass a string during the k-pass */ - /* FIXME: string constants may use more space than strVarMaxLen */ - csound->AuxAlloc(csound, strlen(s) + csound->strVarMaxLen + 2, - &p->channelName); - sprintf((char*) p->channelName.auxp, "$%s$", s); - } - else { - csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); - strcpy((char*) p->channelName.auxp, s); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, j, nsmps = CS_KSMPS; + + if (csound->spoutactive) { + int k = 0; + for (i = 0; iGetNchnls(csound); j++) { + if (insmps-early) + p->ar[j][i] = FL(0.0); + else + p->ar[j][i] = CS_SPOUT[k]; + k++; + } } } else { - /* convert numerical channel to string name */ - csound->AuxAlloc(csound, 64, &p->channelName); - sprintf((char*)p->channelName.auxp, (p->XSTRCODE & 2 ? "$%d" : "%d"), - (int)MYFLT2LRND(*p->valID)); + for (j = 0; jGetNchnls(csound); j++) { + for (i = 0; iar[j][i] = FL(0.0); + } + } } - - /* send output now for use during i-pass */ - koutval(csound, p); - return OK; } -int is_NaN(CSOUND *csound, ASSIGN *p) +int monitor_opcode_init(CSOUND *csound, MONITOR_OPCODE *p) { - *p->r = isnan(*p->a); + if (UNLIKELY(csound->GetOutputArgCnt(p) != (int)csound->GetNchnls(csound))) + return csound->InitError(csound, Str("number of arguments != nchnls")); + p->h.opadr = (SUBR) monitor_opcode_perf; return OK; } -int is_NaNa(CSOUND *csound, ASSIGN *p) -{ - int k, nsmps = csound->ksmps; - MYFLT *a = p->a; - *p->r = FL(0.0); - for (k=0; kr += isnan(a[k]); - return OK; -} +/* -------------------------------------------------------------------- */ -int is_inf(CSOUND *csound, ASSIGN *p) +int outRange_i(CSOUND *csound, OUTRANGE *p) { - *p->r = isinf(*p->a); + IGN(csound); + p->narg = p->INOCOUNT-1; + return OK; } -int is_infa(CSOUND *csound, ASSIGN *p) +int outRange(CSOUND *csound, OUTRANGE *p) { - int k, nsmps = csound->ksmps; - MYFLT *a = p->a; - MYFLT ans = FL(0.0); - int sign = 1; - for (k=0; kh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nchnls = csound->GetNchnls(csound); + MYFLT *ara[VARGMAX]; + int startChan = (int) *p->kstartChan -1; + MYFLT *sp = CS_SPOUT + startChan; + int narg = p->narg; + + + if (startChan < 0) + return csound->PerfError(csound, p->h.insdshead, + Str("outrg: channel number cannot be < 1 " + "(1 is the first channel)")); + + for (j = 0; j < narg; j++) + ara[j] = p->argums[j]; + + if (!csound->spoutactive) { + memset(CS_SPOUT, 0, nsmps * nchnls * sizeof(MYFLT)); + for (n=offset; nspoutactive = 1; + } + else { + for (n=offset; nr = ans*sign; return OK; } - -int error_fn(CSOUND *csound, ERRFN *p) -{ - return csound->InitError(csound, Str("Unknown functuon called")); -} +/* -------------------------------------------------------------------- */ diff -Nru csound-5.17.11~dfsg/OOps/bus.c csound-6.02~dfsg/OOps/bus.c --- csound-5.17.11~dfsg/OOps/bus.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/bus.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,5 +1,4 @@ -/* -bus.c: +/* bus.c: Copyright (C) 2004 John ffitch (C) 2005, 2006 Istvan Varga @@ -22,275 +21,35 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ + /* BUS.C */ #include "csoundCore.h" #include #include +#include +#include +#ifdef NACL +#include +#endif -#define CSOUND_BUS_C 1 - -#include "aops.h" #include "bus.h" #include "namedins.h" -static CS_NOINLINE int chan_realloc(CSOUND *csound, - MYFLT **p, int *oldSize, int newSize) -{ - volatile jmp_buf saved_exitjmp; - MYFLT *newp; - int i; - - memcpy((void*) &saved_exitjmp, (void*)&csound->exitjmp, sizeof(jmp_buf)); - if (setjmp(csound->exitjmp) != 0) { - memcpy((void*)&csound->exitjmp, (void*)&saved_exitjmp, sizeof(jmp_buf)); - return CSOUND_MEMORY; - } - newp = (MYFLT*)mrealloc(csound, (void*)(*p), sizeof(MYFLT) * newSize); - memcpy((void*)&csound->exitjmp, (void*)&saved_exitjmp, sizeof(jmp_buf)); - i = (*oldSize); - memset(&newp[i], '\0', (&newp[newSize-1]-&newp[i])); - /* do { */ - /* newp[i] = FL(0.0); */ - /* } while (++i < newSize); */ - (*p) = newp; - (*oldSize) = newSize; - return CSOUND_SUCCESS; -} - -static CS_NOINLINE int chan_realloc_f(CSOUND *csound, - void **p, int *oldSize, - int newSize, void *init) -{ - volatile jmp_buf saved_exitjmp; - PVSDATEXT *newp, *pp; - int chans = newSize - *oldSize, i; - PVSDAT *fin = (PVSDAT *)init; - - memcpy((void*) &saved_exitjmp, (void*)&csound->exitjmp, sizeof(jmp_buf)); - if (setjmp(csound->exitjmp) != 0) { - memcpy((void*)&csound->exitjmp, (void*)&saved_exitjmp, sizeof(jmp_buf)); - return CSOUND_MEMORY; - } - newp = (PVSDATEXT *)mrealloc(csound, *p, sizeof(PVSDATEXT) * newSize); - for (i=*oldSize; i < chans; i++) { - pp = &newp[i]; - pp->frame = (float *)mmalloc(csound, (fin->N+2)*sizeof(float)); - pp->N = fin->N; - pp->overlap = fin->overlap; - pp->winsize = fin->winsize; - pp->wintype = fin->wintype; - pp->format = fin->format; - pp->framecount = fin->framecount; - } - memcpy((void*)&csound->exitjmp, (void*)&saved_exitjmp, sizeof(jmp_buf)); - (*p) = newp; - (*oldSize) = newSize; - - return CSOUND_SUCCESS; -} - -/** -* Sends a MYFLT value to the chani opcode (k-rate) at index 'n'. -* The bus is automatically extended if 'n' exceeds any previously used -* index value, clearing new locations to zero. -* Returns zero on success, CSOUND_ERROR if the index is invalid, and -* CSOUND_MEMORY if there is not enough memory to extend the bus. -*/ -PUBLIC int csoundChanIKSet(CSOUND *csound, MYFLT value, int n) -{ - if (n < 0) - return CSOUND_ERROR; - if ((unsigned int)n >= (unsigned int)csound->nchanik) { - int err = chan_realloc(csound, - &(csound->chanik), &(csound->nchanik), n + 1); - if (UNLIKELY(err)) - return err; - } - csound->chanik[n] = value; - return CSOUND_SUCCESS; -} - -/** -* Receives a MYFLT value from the chano opcode (k-rate) at index 'n'. -* The bus is automatically extended if 'n' exceeds any previously used -* index value, clearing new locations to zero. -* Returns zero on success, CSOUND_ERROR if the index is invalid, and -* CSOUND_MEMORY if there is not enough memory to extend the bus. -*/ -PUBLIC int csoundChanOKGet(CSOUND *csound, MYFLT *value, int n) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - if ((unsigned int)n >= (unsigned int)csound->nchanok) { - int err = chan_realloc(csound, - &(csound->chanok), &(csound->nchanok), n + 1); - if (UNLIKELY(err)) - return err; - } - (*value) = csound->chanok[n]; - return CSOUND_SUCCESS; -} - -/** -* Sends ksmps MYFLT values to the chani opcode (a-rate) at index 'n'. -* The bus is automatically extended if 'n' exceeds any previously used -* index value, clearing new locations to zero. -* Returns zero on success, CSOUND_ERROR if the index is invalid, and -* CSOUND_MEMORY if there is not enough memory to extend the bus. -*/ -PUBLIC int csoundChanIASet(CSOUND *csound, const MYFLT *value, int n) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - n *= csound->ksmps; - if ((unsigned int)n >= (unsigned int)csound->nchania) { - int err = chan_realloc(csound, &(csound->chania), - &(csound->nchania), n + csound->ksmps); - if (UNLIKELY(err)) - return err; - } - memcpy(&(csound->chania[n]), value, sizeof(MYFLT) * csound->ksmps); - return CSOUND_SUCCESS; -} - -/** -* Receives ksmps MYFLT values from the chano opcode (a-rate) at index 'n'. -* The bus is automatically extended if 'n' exceeds any previously used -* index value, clearing new locations to zero. -* Returns zero on success, CSOUND_ERROR if the index is invalid, and -* CSOUND_MEMORY if there is not enough memory to extend the bus. -*/ -PUBLIC int csoundChanOAGet(CSOUND *csound, MYFLT *value, int n) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - n *= csound->ksmps; - if ((unsigned int)n >= (unsigned int)csound->nchanoa) { - int err = chan_realloc(csound, &(csound->chanoa), - &(csound->nchanoa), n + csound->ksmps); - if (UNLIKELY(err)) - return err; - } - memcpy(value, &(csound->chanoa[n]), sizeof(MYFLT) * csound->ksmps); - return CSOUND_SUCCESS; -} - -PUBLIC int csoundChanIKSetValue(CSOUND *csound, int n, MYFLT value) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - if ((unsigned int)n >= (unsigned int)csound->nchanik) { - int err = chan_realloc(csound, - &(csound->chanik), &(csound->nchanik), n + 1); - if (UNLIKELY(err)) - return err; - } - csound->chanik[n] = value; - return CSOUND_SUCCESS; -} - -PUBLIC MYFLT csoundChanOKGetValue(CSOUND *csound, int n) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - if ((unsigned int)n >= (unsigned int)csound->nchanok) { - int err = chan_realloc(csound, - &(csound->chanok), &(csound->nchanok), n + 1); - if (UNLIKELY(err)) - return err; - } - return csound->chanok[n]; -} - -PUBLIC int csoundChanIASetSample(CSOUND *csound, int n, int i, MYFLT sample) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - n *= csound->ksmps; - if ((unsigned int)n >= (unsigned int)csound->nchanoa) { - int err = chan_realloc(csound, &(csound->chanoa), - &(csound->nchanoa), n + csound->ksmps); - if (UNLIKELY(err)) - return err; - } - csound->chanoa[n + i] = sample; - return CSOUND_SUCCESS; -} - - -PUBLIC MYFLT csoundChanOAGetSample(CSOUND *csound, int n, int i) -{ - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - n *= csound->ksmps; - if ((unsigned int)n >= (unsigned int)csound->nchanoa) { - int err = chan_realloc(csound, &(csound->chanoa), - &(csound->nchanoa), n + csound->ksmps); - if (UNLIKELY(err)) - return err; - } - return csound->chanoa[n + i]; -} - - -/** -* Sends a PVSDATEX fin to the pvsin opcode (f-rate) at index 'n'. -* The bus is automatically extended if 'n' exceeds any previously used -* index value, clearing new locations to zero. -* Returns zero on success, CSOUND_ERROR if the index is invalid or -* fsig framesizes are incompatible, and -* CSOUND_MEMORY if there is not enough memory to extend the bus. -*/ -PUBLIC int csoundPvsinSet(CSOUND *csound, const PVSDATEXT *fin, int n) -{ - PVSDATEXT *fout = (PVSDATEXT *)csound->chanif; - int size; - if (UNLIKELY(n < 0)) - return CSOUND_ERROR; - if ((unsigned int)n >= (unsigned int)csound->nchanif) { - int err = chan_realloc_f(csound, (void *)&(csound->chanif), - &(csound->nchanif), n + 1, - (void *)fin); - if (UNLIKELY(err)) - return err; - fout = (PVSDATEXT *)csound->chanif; - memcpy(fout[n].frame, fin->frame, sizeof(float)*(fin->N+2)); - return CSOUND_SUCCESS; - } - size = fout[n].N < fin->N ? fout[n].N : fin->N; - memcpy(&fout[n], fin, sizeof(PVSDATEXT)-sizeof(float *)); - if (LIKELY(size > 0)) - memcpy(fout[n].frame, fin->frame, sizeof(float)*(size+2)); - return CSOUND_SUCCESS; -} +/* For sensing opcodes */ +#if defined(__unix) || defined(__unix__) || defined(__MACH__) +# ifdef HAVE_SYS_TIME_H +# include +# endif +# ifdef HAVE_SYS_TYPES_H +# include +# endif +# ifdef HAVE_TERMIOS_H +# include +# endif +#elif defined(WIN32) +# include +#endif -/** -* Receives a PVSDATEX fout from the chano opcode (f-rate) at index 'n'. -* The bus is extended if n exceeds existing spaces, initialising -* it using the PVSDATEX fout struct parameters. -* Returns zero on success, CSOUND_ERROR if the index is invalid or -* if fsigs framesizes are incompatible -*/ -PUBLIC int csoundPvsoutGet(CSOUND *csound, PVSDATEXT *fout, int n) -{ - PVSDATEXT *fin = (PVSDATEXT *)csound->chanof; - int size; - if (UNLIKELY(n < 0)) return CSOUND_ERROR; - if (((unsigned int)n >= (unsigned int)csound->nchanof)) { - int err = chan_realloc_f(csound, (void *)&(csound->chanof), - &(csound->nchanof), n + 1, (void *)fout); - if (UNLIKELY(err)) - return err; - fin = (PVSDATEXT *)csound->chanof; - memset(fin[n].frame, 0, sizeof(float)*(fin[n].N+2)); - return CSOUND_SUCCESS; - } - size = fout->N < fin[n].N ? fout->N : fin[n].N; - memcpy(fout, &fin[n], sizeof(PVSDATEXT)-sizeof(float *)); - if (LIKELY(size > 0)) - memcpy(fout->frame, fin[n].frame, sizeof(float)*(size+2)); - return CSOUND_SUCCESS; -} /* ------------------------------------------------------------------------ */ @@ -305,257 +64,346 @@ # endif #endif -int chani_opcode_perf_k(CSOUND *csound, ASSIGN *p) +#ifdef USE_DOUBLE +# define MYFLT_INT_TYPE int64_t +#else +# define MYFLT_INT_TYPE int32_t +#endif + + + +int chani_opcode_perf_k(CSOUND *csound, CHNVAL *p) { int n = (int)MYFLT2LRND(*(p->a)); + char chan_name[16]; + int err; + MYFLT *val; if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("chani: invalid index")); - if ((unsigned int)n >= (unsigned int)csound->nchanik) { - if (UNLIKELY(chan_realloc(csound, &(csound->chanik), - &(csound->nchanik), n + 1) != 0)) - return csound->PerfError(csound, - Str("chani: memory allocation failure")); - } - *(p->r) = csound->chanik[n]; + return csound->PerfError(csound, p->h.insdshead,Str("chani: invalid index")); + + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &val, chan_name, + CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL); + + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("chani error %d:" + "channel not found or not right type"), err); + *(p->r) = *val; return OK; } -int chano_opcode_perf_k(CSOUND *csound, ASSIGN *p) +int chano_opcode_perf_k(CSOUND *csound, CHNVAL *p) { int n = (int)MYFLT2LRND(*(p->a)); + char chan_name[16]; + int err; + MYFLT *val; if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("chano: invalid index")); - if ((unsigned int)n >= (unsigned int)csound->nchanok) { - if (UNLIKELY(chan_realloc(csound, &(csound->chanok), - &(csound->nchanok), n + 1) != 0)) - return csound->PerfError(csound, - Str("chano: memory allocation failure")); - } - csound->chanok[n] = *(p->r); + return csound->PerfError(csound,p->h.insdshead,Str("chani: invalid index")); + + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &val, chan_name, + CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL); + + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("chano error %d:" + "channel not found or not right type"), err); + *val = *(p->r); return OK; } -int chani_opcode_perf_a(CSOUND *csound, ASSIGN *p) +int chani_opcode_perf_a(CSOUND *csound, CHNVAL *p) { - int n = (int)MYFLT2LRND(*(p->a)) * csound->global_ksmps; + int n = (int)MYFLT2LRND(*(p->a)); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + char chan_name[16]; + int err; + MYFLT *val; if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("chani: invalid index")); - if ((unsigned int)n >= (unsigned int)csound->nchania) { - if (UNLIKELY(chan_realloc(csound, &(csound->chania), - &(csound->nchania), n + csound->global_ksmps) != 0)) - return csound->PerfError(csound, - Str("chani: memory allocation failure")); - } - memcpy(p->r, &(csound->chania[n]), sizeof(MYFLT) * csound->ksmps); + return csound->PerfError(csound, p->h.insdshead,Str("chani: invalid index")); + + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &val, chan_name, + CSOUND_AUDIO_CHANNEL | CSOUND_INPUT_CHANNEL); + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("chani error %d:" + "channel not found or not right type"), err); + if (UNLIKELY(offset)) memset(p->r, '\0', offset * sizeof(MYFLT)); + memcpy(&p->r[offset], &val[offset], + sizeof(MYFLT) * (CS_KSMPS-offset-early)); + if (UNLIKELY(early)) + memset(&p->r[CS_KSMPS-early], '\0', early * sizeof(MYFLT)); return OK; } -int chano_opcode_perf_a(CSOUND *csound, ASSIGN *p) +int chano_opcode_perf_a(CSOUND *csound, CHNVAL *p) { - int n = (int)MYFLT2LRND(*(p->a)) * csound->global_ksmps; + int n = (int)MYFLT2LRND(*(p->a)); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + char chan_name[16]; + int err; + MYFLT *val; if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("chano: invalid index")); - if ((unsigned int)n >= (unsigned int)csound->nchanoa) { - if (UNLIKELY(chan_realloc(csound, &(csound->chanoa), - &(csound->nchanoa), n + csound->global_ksmps) != 0)) - return csound->PerfError(csound, - Str("chano: memory allocation failure")); - } - memcpy(&(csound->chanoa[n]), p->r, sizeof(MYFLT) * csound->ksmps); + return csound->PerfError(csound, p->h.insdshead,Str("chani: invalid index")); + + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &val, chan_name, + CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("chano error %d:" + "channel not found or not right type"), err); + + if (UNLIKELY(offset)) memset(&val, '\0', offset * sizeof(MYFLT)); + memcpy(&val[offset], &p->r[offset], + sizeof(MYFLT) * (CS_KSMPS-offset-early)); + + if (UNLIKELY(early)) + memset(&val[CS_KSMPS-early], '\0', early * sizeof(MYFLT)); return OK; } int pvsin_init(CSOUND *csound, FCHAN *p) { int N; - N = p->init.N = (int32)(*p->N ? *p->N : 1024); - p->init.overlap = (int32) (*p->overlap ? *p->overlap : p->init.N/4); - p->init.winsize = (int32) (*p->winsize ? *p->winsize : p->init.N); + MYFLT *pp; + PVSDATEXT *f; + int n = (int)MYFLT2LRND(*(p->a)); + char name[16]; + sprintf(name, "%i", n); + if (csoundGetChannelPtr(csound, &pp, name, + CSOUND_PVS_CHANNEL | CSOUND_INPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = + csoundGetChannelLock(csound, name); + f = (PVSDATEXT *) pp; + csoundSpinLock(lock); + memcpy(&(p->init), f, sizeof(PVSDAT)-sizeof(AUXCH)); + csoundSpinUnLock(lock); + } + + N = p->init.N = (int32)(*p->N ? *p->N : p->init.N); + p->init.overlap = (int32) (*p->overlap ? *p->overlap : p->init.overlap); + p->init.winsize = (int32) (*p->winsize ? *p->winsize : p->init.winsize); p->init.wintype = (int32)(*p->wintype); p->init.format = (int32)(*p->format); p->init.framecount = 0; memcpy(p->r, &p->init, sizeof(PVSDAT)-sizeof(AUXCH)); if (p->r->frame.auxp == NULL || - p->r->frame.size < sizeof(float) * (N + 2)) + p->r->frame.size < sizeof(float) * (N + 2)) csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->r->frame); return OK; } int pvsin_perf(CSOUND *csound, FCHAN *p) { - PVSDATEXT *fin = (PVSDATEXT *)csound->chanif; PVSDAT *fout = p->r; - int n = (int)MYFLT2LRND(*(p->a)), size; + int n = (int)MYFLT2LRND(*(p->a)); + char chan_name[16]; + int err, size, *lock; + PVSDATEXT *fin; + MYFLT *pp; + if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("pvsin: invalid index")); - if (((unsigned int)n >= (unsigned int)csound->nchanif)){ - int err = chan_realloc_f(csound, (void *)&(csound->chanif), - &(csound->nchanif), n + 1, - (void *) &(p->init)); - if (UNLIKELY(err)) { - return csound->PerfError(csound, Str("pvsin: memory allocation failure")); - } - else { - fin = (PVSDATEXT *)csound->chanif; - memset(fin[n].frame, 0, sizeof(float)*(fin[n].N+2)); - } + return csound->PerfError(csound, p->h.insdshead,Str("pvsin: invalid index")); + + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &pp, chan_name, + CSOUND_PVS_CHANNEL | CSOUND_INPUT_CHANNEL); + fin = (PVSDATEXT *) pp; + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("pvsin error %d:" + "channel not found or not right type"), err); + + size = fin->N < fout->N ? fin->N : fout->N; + lock = csoundGetChannelLock(csound, chan_name); + csoundSpinLock(lock); + memcpy(fout, fin, sizeof(PVSDAT)-sizeof(AUXCH)); + //printf("fout=%p fout->frame.auxp=%p fin=%p fin->frame=%p\n", + // fout, fout->frame.auxp, fin, fin->frame); + if(fin->frame != NULL) + memcpy(fout->frame.auxp, fin->frame, sizeof(float)*(size+2)); + else memset(fout->frame.auxp, 0, sizeof(float)*(size+2)); + csoundSpinUnLock(lock); + return OK; +} + +int pvsout_init(CSOUND *csound, FCHAN *p) +{ + PVSDAT *fin = p->r; + MYFLT *pp; + PVSDATEXT *f; + int n = (int)MYFLT2LRND(*(p->a)); + char name[16]; + + sprintf(name, "%i", n); + if (csoundGetChannelPtr(csound, &pp, name, + CSOUND_PVS_CHANNEL | CSOUND_OUTPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = + csoundGetChannelLock(csound, name); + f = (PVSDATEXT *) pp; + csoundSpinLock(lock); + if(f->frame == NULL) { + f->frame = mcalloc(csound, sizeof(float)*(fin->N+2)); + } else if(f->N < fin->N) { + f->frame = mrealloc(csound, f->frame, sizeof(float)*(fin->N+2)); + } + memcpy(f, fin, sizeof(PVSDAT)-sizeof(AUXCH)); + csoundSpinUnLock(lock); } - size = fin[n].N < fout->N ? fin[n].N : fout->N; - memcpy(fout, &fin[n], sizeof(PVSDAT)-sizeof(AUXCH)); - memcpy(fout->frame.auxp, fin[n].frame, sizeof(float)*(size+2)); return OK; } + int pvsout_perf(CSOUND *csound, FCHAN *p) { - int n = (int)MYFLT2LRND(*(p->a)), size; - PVSDATEXT *fout = (PVSDATEXT *)csound->chanof; + PVSDAT *fin = p->r; + int n = (int)MYFLT2LRND(*(p->a)); + char chan_name[16]; + int err, size, *lock; + PVSDATEXT *fout; + MYFLT *pp; + if (UNLIKELY(n < 0)) - return csound->PerfError(csound,Str("pvsout: invalid index")); + return csound->PerfError(csound, p->h.insdshead,Str("pvsout: invalid index")); - if ((unsigned int)n >= (unsigned int)csound->nchanof) { - if (UNLIKELY(chan_realloc_f(csound, (void *)&(csound->chanof), - &(csound->nchanof), n + 1, - (void *) fin) != 0)) - return csound->PerfError(csound, - Str("pvsout: memory allocation failure")); - else fout = (PVSDATEXT *)csound->chanof; - } - size = fout[n].N < fin->N ? fout[n].N : fin->N; - memcpy(&fout[n], fin, sizeof(PVSDAT)-sizeof(AUXCH)); - memcpy(fout[n].frame, fin->frame.auxp, sizeof(float)*(size+2)); + sprintf(chan_name, "%i", n); + err = csoundGetChannelPtr(csound, &pp, chan_name, + CSOUND_PVS_CHANNEL | CSOUND_OUTPUT_CHANNEL); + fout = (PVSDATEXT *) pp; + if (UNLIKELY(err)) + return csound->PerfError(csound, p->h.insdshead, + Str("pvsout error %d:" + "channel not found or not right type"), err); + + lock = csoundGetChannelLock(csound, chan_name); + csoundSpinLock(lock); + size = fin->N < fout->N ? fin->N : fout->N; + memcpy(fout, fin, sizeof(PVSDAT)-sizeof(AUXCH)); + if(fout->frame != NULL) + memcpy(fout->frame, fin->frame.auxp, sizeof(float)*(size+2)); + csoundSpinUnLock(lock); return OK; } /* ======================================================================== */ /* "chn" opcodes and bus interface by Istvan Varga */ -typedef struct controlChannelInfo_s { - int type; - MYFLT dflt; - MYFLT min; - MYFLT max; -} controlChannelInfo_t; - -typedef struct channelEntry_s { - struct channelEntry_s *nxt; - controlChannelInfo_t *info; - MYFLT *data; - int lock; /* Multi-thread protection */ - int type; - char name[1]; -} channelEntry_t; - static int delete_channel_db(CSOUND *csound, void *p) { - channelEntry_t **db, *pp; - int i; + CONS_CELL *head, *values; - (void) p; - db = (channelEntry_t**) csound->chn_db; - if (db == NULL) { + if (csound->chn_db == NULL) { return 0; } - for (i = 0; i < 256; i++) { - while (db[i] != NULL) { - pp = db[i]; - db[i] = pp->nxt; - if (pp->info != NULL) - free((void*) pp->info); - free((void*) pp); + + head = values = cs_hash_table_values(csound, csound->chn_db); + + if (head != NULL) { + while(values != NULL) { + CHNENTRY* entry = values->value; + + if ((entry->type & CSOUND_CHANNEL_TYPE_MASK) != CSOUND_CONTROL_CHANNEL) { + csound->Free(csound, entry->hints.attributes); + } + csound->Free(csound, entry->data); + entry->datasize = 0; + values = values->next; } + cs_cons_free(csound, head); } + + cs_hash_table_free_complete(csound, csound->chn_db); csound->chn_db = NULL; - free((void*) db); return 0; } -static inline channelEntry_t *find_channel(CSOUND *csound, const char *name) +static inline CHNENTRY *find_channel(CSOUND *csound, const char *name) { if (csound->chn_db != NULL && name[0]) { - channelEntry_t *pp; - pp = ((channelEntry_t**) csound->chn_db)[name_hash_2(csound, name)]; - for ( ; pp != NULL; pp = pp->nxt) { - const char *p1 = &(name[0]); - const char *p2 = &(pp->name[0]); - while (1) { - if (*p1 != *p2) - break; - if (*p1 == '\0') - return pp; - p1++, p2++; - } - } + return (CHNENTRY*) cs_hash_table_get(csound, csound->chn_db, (char*) name); } return NULL; } -static CS_NOINLINE channelEntry_t *alloc_channel(CSOUND *csound, MYFLT **p, - const char *name, int type) +void set_channel_data_ptr(CSOUND *csound, const char *name, void *ptr, int newSize) +{ + find_channel(csound, name)->data = (MYFLT *) ptr; + find_channel(csound, name)->datasize = newSize; +} + +#define INIT_STRING_CHANNEL_DATASIZE 256 + +static CS_NOINLINE CHNENTRY *alloc_channel(CSOUND *csound, MYFLT **p, + const char *name, int type) { - channelEntry_t dummy; - void *pp; - int nbytes, nameOffs, dataOffs; - - (void) dummy; - nameOffs = (int)((char*) &(dummy.name[0]) - (char*) &dummy); - dataOffs = nameOffs + ((int)strlen(name) + 1); - dataOffs += ((int)sizeof(MYFLT) - 1); - dataOffs = (dataOffs / (int)sizeof(MYFLT)) * (int)sizeof(MYFLT); - nbytes = dataOffs; - if (*p == NULL) { - switch (type & CSOUND_CHANNEL_TYPE_MASK) { + CHNENTRY *pp; + int dsize = 0; + switch (type & CSOUND_CHANNEL_TYPE_MASK) { case CSOUND_CONTROL_CHANNEL: - nbytes += (int)sizeof(MYFLT); + dsize = (int)sizeof(MYFLT); break; case CSOUND_AUDIO_CHANNEL: - nbytes += ((int)sizeof(MYFLT) * csound->global_ksmps); + dsize = ((int)sizeof(MYFLT) * csound->ksmps); break; case CSOUND_STRING_CHANNEL: - nbytes += ((int)sizeof(MYFLT) * csound->strVarSamples); + dsize = ((int)sizeof(STRINGDAT)); + break; + case CSOUND_PVS_CHANNEL: + dsize = ((int)sizeof(PVSDATEXT)); break; } - } - pp = (void*) malloc((size_t) nbytes); - if (pp == NULL) - return (channelEntry_t*) NULL; - memset(pp, 0, (size_t) nbytes); - if (*p == NULL) - *p = (MYFLT*) ((char*) pp + (int)dataOffs); - return (channelEntry_t*) pp; + pp = (CHNENTRY *) mcalloc(csound, (size_t) sizeof(CHNENTRY) + strlen(name) + 1); + if (pp == NULL) return (CHNENTRY*) NULL; + pp->data = (MYFLT *) mcalloc(csound, dsize); + +#ifndef MACOSX +#if defined(HAVE_PTHREAD_SPIN_LOCK) + pthread_spin_init(&(pp->theLock), PTHREAD_PROCESS_PRIVATE); + pp->lock = &(pp->theLock); +#endif +#endif + *p = (MYFLT*) pp->data; + pp->datasize = dsize; + + return (CHNENTRY*) pp; } static CS_NOINLINE int create_new_channel(CSOUND *csound, MYFLT **p, const char *name, int type) { - channelEntry_t *pp; - const char *s; - unsigned char h; + CHNENTRY *pp; + // const char *s; /* check for valid parameters and calculate hash value */ - if (UNLIKELY((type & (~51)) || !(type & 3) || !(type & 48))) - return CSOUND_ERROR; - s = name; - if (UNLIKELY(!isalpha((unsigned char) *s))) - return CSOUND_ERROR; - h = (unsigned char) 0; - do { - h = strhash_tabl_8[(unsigned char) *(s++) ^ h]; - } while (isalnum((unsigned char) *s) || - *s == (char) '_' || *s == (char) '-' || *s == (char) '.'); - if (*s != (char) 0) + if (UNLIKELY(!(type & 48))) return CSOUND_ERROR; + // s = name; + +// while (isalnum((unsigned char) *s) || +// *s == (char) '_' || *s == (char) '-' || *s == (char) '.') s++; +// if (*s != (char) 0) +// return CSOUND_ERROR; /* create new empty database on first call */ if (csound->chn_db == NULL) { + csound->chn_db = cs_hash_table_create(csound); if (UNLIKELY(csound->RegisterResetCallback(csound, NULL, delete_channel_db) != 0)) - return CSOUND_MEMORY; - csound->chn_db = (void*) calloc((size_t) 256, sizeof(channelEntry_t*)); + return CSOUND_MEMORY; if (UNLIKELY(csound->chn_db == NULL)) return CSOUND_MEMORY; } @@ -563,51 +411,21 @@ pp = alloc_channel(csound, p, name, type); if (UNLIKELY(pp == NULL)) return CSOUND_MEMORY; - pp->nxt = ((channelEntry_t**) csound->chn_db)[h]; - pp->info = NULL; + pp->hints.behav = 0; pp->data = (*p); pp->type = type; strcpy(&(pp->name[0]), name); - ((channelEntry_t**) csound->chn_db)[h] = pp; + + cs_hash_table_put(csound, csound->chn_db, (char*)name, pp); return CSOUND_SUCCESS; } -/** -* Stores a pointer to the specified channel of the bus in *p, -* creating the channel first if it does not exist yet. -* 'type' must be the bitwise OR of exactly one of the following values, -* CSOUND_CONTROL_CHANNEL -* control data (one MYFLT value) -* CSOUND_AUDIO_CHANNEL -* audio data (csoundGetKsmps(csound) MYFLT values) -* CSOUND_STRING_CHANNEL -* string data (MYFLT values with enough space to store -* csoundGetStrVarMaxLen(csound) characters, including the -* NULL character at the end of the string) -* and at least one of these: -* CSOUND_INPUT_CHANNEL -* CSOUND_OUTPUT_CHANNEL -* If the channel already exists, it must match the data type (control, -* audio, or string), however, the input/output bits are OR'd with the -* new value. Note that audio and string channels can only be created -* after calling csoundCompile(), because the storage size is not known -* until then. -* Return value is zero on success, or a negative error code, -* CSOUND_MEMORY there is not enough memory for allocating the channel -* CSOUND_ERROR the specified name or type is invalid -* or, if a channel with the same name but incompatible type already exists, -* the type of the existing channel. In the case of any non-zero return -* value, *p is set to NULL. -* Note: to find out the type of a channel without actually creating or -* changing it, set 'type' to zero, so that the return value will be either -* the type of the channel, or CSOUND_ERROR if it does not exist. -*/ PUBLIC int csoundGetChannelPtr(CSOUND *csound, MYFLT **p, const char *name, int type) { - channelEntry_t *pp; + CHNENTRY *pp; *p = (MYFLT*) NULL; if (UNLIKELY(name == NULL)) @@ -623,104 +441,98 @@ return create_new_channel(csound, p, name, type); } +PUBLIC int csoundGetChannelDatasize(CSOUND *csound, const char *name){ + + CHNENTRY *pp; + pp = find_channel(csound, name); + if (pp == NULL) return 0; + else { + /* the reason for this is that if chnexport is + used with strings, the datasize might become + invalid */ + if (pp->type == CSOUND_STRING_CHANNEL) + return strlen((char *) pp->data) + 1; + return pp->datasize; + } +} + + PUBLIC int *csoundGetChannelLock(CSOUND *csound, - const char *name, int type) + const char *name) { - channelEntry_t *pp; + CHNENTRY *pp; if (UNLIKELY(name == NULL)) return NULL; pp = find_channel(csound, name); - return &pp->lock; + if (pp) { +#ifndef MACOSX +#if defined(HAVE_PTHREAD_SPIN_LOCK) + return (int*)pp->lock; +#else + return &(pp->lock); +#endif +#else + return &(pp->lock); +#endif + } + else return NULL; } static int cmp_func(const void *p1, const void *p2) { - return strcmp(((CsoundChannelListEntry*) p1)->name, - ((CsoundChannelListEntry*) p2)->name); + return strcmp(((controlChannelInfo_t*) p1)->name, + ((controlChannelInfo_t*) p2)->name); } -/** -* Returns a list of allocated channels in *lst. A CsoundChannelListEntry -* structure contains the name and type of a channel, with the type having -* the same format as in the case of csoundGetChannelPtr(). -* The return value is the number of channels, which may be zero if there -* are none, or CSOUND_MEMORY if there is not enough memory for allocating -* the list. In the case of no channels or an error, *lst is set to NULL. -* Notes: the caller is responsible for freeing the list returned in *lst -* with csoundDeleteChannelList(). The name pointers may become invalid -* after calling csoundReset(). -*/ - -PUBLIC int csoundListChannels(CSOUND *csound, CsoundChannelListEntry **lst) +PUBLIC int csoundListChannels(CSOUND *csound, controlChannelInfo_t **lst) { - channelEntry_t *pp; - size_t i, n; + CHNENTRY *pp; + size_t n; + CONS_CELL* channels; - *lst = (CsoundChannelListEntry*) NULL; + *lst = (controlChannelInfo_t*) NULL; if (csound->chn_db == NULL) return 0; - /* count the number of channels */ - for (n = (size_t) 0, i = (size_t) 0; i < (size_t) 256; i++) { - for (pp = ((channelEntry_t**) csound->chn_db)[i]; - pp != NULL; - pp = pp->nxt, n++) - ; - } + + channels = cs_hash_table_values(csound, csound->chn_db); + n = cs_cons_length(channels); + if (!n) return 0; + /* create list, initially in unsorted order */ - *lst = (CsoundChannelListEntry*) malloc(n * sizeof(CsoundChannelListEntry)); + // TODO - should this be malloc or mmalloc? + *lst = (controlChannelInfo_t*) malloc(n * sizeof(controlChannelInfo_t)); if (UNLIKELY(*lst == NULL)) return CSOUND_MEMORY; - for (n = (size_t) 0, i = (size_t) 0; i < (size_t) 256; i++) { - for (pp = ((channelEntry_t**) csound->chn_db)[i]; - pp != NULL; - pp = pp->nxt, n++) { - (*lst)[n].name = pp->name; - (*lst)[n].type = pp->type; - } + + n = 0; + while (channels != NULL) { + pp = channels->value; + (*lst)[n].name = pp->name; + (*lst)[n].type = pp->type; + (*lst)[n].hints = pp->hints; + channels = channels->next; + n++; } + /* sort list */ - qsort((void*) (*lst), n, sizeof(CsoundChannelListEntry), cmp_func); + qsort((void*) (*lst), n, sizeof(controlChannelInfo_t), cmp_func); /* return the number of channels */ return (int)n; } -/** -* Releases a channel list previously returned by csoundListChannels(). -*/ - -PUBLIC void csoundDeleteChannelList(CSOUND *csound, CsoundChannelListEntry *lst) +PUBLIC void csoundDeleteChannelList(CSOUND *csound, controlChannelInfo_t *lst) { (void) csound; if (lst != NULL) free(lst); } -/** -* Sets special parameters for a control channel. The parameters are: -* type: must be one of CSOUND_CONTROL_CHANNEL_INT, -* CSOUND_CONTROL_CHANNEL_LIN, or CSOUND_CONTROL_CHANNEL_EXP for -* integer, linear, or exponential channel data, respectively, -* or zero to delete any previously assigned parameter information -* dflt: the control value that is assumed to be the default, should be -* greater than or equal to 'min', and less than or equal to 'max' -* min: the minimum value expected; if the control type is exponential, -* it must be non-zero -* max: the maximum value expected, should be greater than 'min'; -* if the control type is exponential, it must be non-zero and -* match the sign of 'min' -* Returns zero on success, or a non-zero error code on failure: -* CSOUND_ERROR: the channel does not exist, is not a control channel, -* or the specified parameters are invalid -* CSOUND_MEMORY: could not allocate memory -*/ - -PUBLIC int csoundSetControlChannelParams(CSOUND *csound, const char *name, - int type, MYFLT dflt, - MYFLT min, MYFLT max) +PUBLIC int csoundSetControlChannelHints(CSOUND *csound, const char *name, + controlChannelHints_t hints) { - channelEntry_t *pp; + CHNENTRY *pp; if (UNLIKELY(name == NULL)) return CSOUND_ERROR; @@ -729,43 +541,35 @@ return CSOUND_ERROR; if (UNLIKELY((pp->type & CSOUND_CHANNEL_TYPE_MASK) != CSOUND_CONTROL_CHANNEL)) return CSOUND_ERROR; - if (!type) { - if (pp->info != NULL) { - free((void*) pp->info); - pp->info = NULL; - } - return CSOUND_SUCCESS; - } - switch (type) { - case CSOUND_CONTROL_CHANNEL_INT: - dflt = (MYFLT) ((int32) MYFLT2LRND(dflt)); - min = (MYFLT) ((int32) MYFLT2LRND(min)); - max = (MYFLT) ((int32) MYFLT2LRND(max)); - break; - case CSOUND_CONTROL_CHANNEL_LIN: - case CSOUND_CONTROL_CHANNEL_EXP: - break; - default: + if (hints.behav == CSOUND_CONTROL_CHANNEL_NO_HINTS) { + pp->hints.behav = CSOUND_CONTROL_CHANNEL_NO_HINTS; + return 0; + } + if (hints.behav == CSOUND_CONTROL_CHANNEL_INT) { + hints.dflt = (MYFLT) ((int32) MYFLT2LRND(hints.dflt)); + hints.min = (MYFLT) ((int32) MYFLT2LRND(hints.min)); + hints.max = (MYFLT) ((int32) MYFLT2LRND(hints.max)); + } + if (UNLIKELY(hints.min > hints.max || hints.dflt < hints.min || + hints.dflt > hints.max || + (hints.behav == CSOUND_CONTROL_CHANNEL_EXP && + ((hints.min * hints.max) <= FL(0.0))))) { return CSOUND_ERROR; } - if (UNLIKELY(min >= max || dflt < min || dflt > max || - (type == CSOUND_CONTROL_CHANNEL_EXP && ((min * max) <= FL(0.0))))) - return CSOUND_ERROR; - if (pp->info == NULL) { - pp->info = (controlChannelInfo_t*) malloc(sizeof(controlChannelInfo_t)); - if (UNLIKELY(pp->info == NULL)) - return CSOUND_MEMORY; + + pp->hints = hints; + if (hints.attributes) { + pp->hints.attributes + = (char *) csound->Malloc(csound, + (strlen(hints.attributes) + 1)* sizeof(char)); + strcpy(pp->hints.attributes, hints.attributes); } - pp->info->type = type; - pp->info->dflt = dflt; - pp->info->min = min; - pp->info->max = max; return CSOUND_SUCCESS; } /** * Returns special parameters (assuming there are any) of a control channel, -* previously set with csoundSetControlChannelParams(). +* previously set with csoundSetControlChannelHints(). * If the channel exists, is a control channel, and has the special parameters * assigned, then the default, minimum, and maximum value is stored in *dflt, * *min, and *max, respectively, and a positive value that is one of @@ -776,10 +580,10 @@ * special parameters set; otherwise, a negative error code is returned. */ -PUBLIC int csoundGetControlChannelParams(CSOUND *csound, const char *name, - MYFLT *dflt, MYFLT *min, MYFLT *max) +PUBLIC int csoundGetControlChannelHints(CSOUND *csound, const char *name, + controlChannelHints_t *hints) { - channelEntry_t *pp; + CHNENTRY *pp; if (UNLIKELY(name == NULL)) return CSOUND_ERROR; @@ -788,42 +592,16 @@ return CSOUND_ERROR; if ((pp->type & CSOUND_CHANNEL_TYPE_MASK) != CSOUND_CONTROL_CHANNEL) return CSOUND_ERROR; - if (pp->info == NULL) - return 0; - (*dflt) = pp->info->dflt; - (*min) = pp->info->min; - (*max) = pp->info->max; - return pp->info->type; -} - -/** -* Sets callback function to be called by the opcodes 'chnsend' and -* 'chnrecv'. Should be called between csoundPreCompile() and -* csoundCompile(). -* The callback function takes the following arguments: -* CSOUND *csound -* Csound instance pointer -* const char *channelName -* the channel name -* MYFLT *channelValuePtr -* pointer to the channel value. Control channels are a single MYFLT -* value, while audio channels are an array of csoundGetKsmps(csound) -* MYFLT values. In the case of string channels, the pointer should be -* cast to char *, and points to a buffer of -* csoundGetStrVarMaxLen(csound) bytes -* int channelType -* bitwise OR of the channel type (CSOUND_CONTROL_CHANNEL, -* CSOUND_AUDIO_CHANNEL, or CSOUND_STRING_CHANNEL; use -* channelType & CSOUND_CHANNEL_TYPE_MASK to extract the channel -* type), and either CSOUND_INPUT_CHANNEL or CSOUND_OUTPUT_CHANNEL -* to indicate the direction of the data transfer -* The callback is not preserved on csoundReset(). -*/ - -PUBLIC void csoundSetChannelIOCallback(CSOUND *csound, - CsoundChannelIOCallback_t func) -{ - csound->channelIOCallback_ = func; + if (pp->hints.behav == 0) + return CSOUND_ERROR; + *hints = pp->hints; + if (pp->hints.attributes) { + hints->attributes + = (char *) csound->Malloc(csound, + strlen(pp->hints.attributes) + 1); + strcpy(hints->attributes, pp->hints.attributes); + } + return 0; } /* ------------------------------------------------------------------------ */ @@ -832,8 +610,9 @@ int notinit_opcode_stub(CSOUND *csound, void *p) { - return csound->PerfError(csound, Str("%s: not initialised"), - csound->GetOpcodeName(p)); + return csound->PerfError(csound, ((CHNGET *)p)->h.insdshead, + Str("%s: not initialised"), + csound->GetOpcodeName(p)); } /* print error message on failed channel query */ @@ -855,10 +634,18 @@ } /* receive control value from bus at performance time */ - static int chnget_opcode_perf_k(CSOUND *csound, CHNGET *p) { +#ifdef HAVE_ATOMIC_BUILTIN + volatile union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.i = __sync_fetch_and_add((MYFLT_INT_TYPE *) p->fp, 0); + *(p->arg) = x.d; +#else *(p->arg) = *(p->fp); +#endif return OK; } @@ -866,7 +653,28 @@ static int chnget_opcode_perf_a(CSOUND *csound, CHNGET *p) { - memcpy(p->arg, p->fp, sizeof(MYFLT)*csound->ksmps); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + if(CS_KSMPS == (unsigned int) csound->ksmps) { + csoundSpinLock(p->lock); + if (UNLIKELY(offset)) memset(p->arg, '\0', offset); + memcpy(&p->arg[offset], p->fp, sizeof(MYFLT)*(CS_KSMPS-offset-early)); + if (UNLIKELY(early)) + memset(&p->arg[CS_KSMPS-early], '\0', sizeof(MYFLT)*early); + csoundSpinUnLock(p->lock); + } else { + csoundSpinLock(p->lock); + if (UNLIKELY(offset)) memset(p->arg, '\0', offset); + memcpy(&p->arg[offset], &(p->fp[offset+p->pos]), + sizeof(MYFLT)*(CS_KSMPS-offset-early)); + if (UNLIKELY(early)) + memset(&p->arg[CS_KSMPS-early], '\0', sizeof(MYFLT)*early); + p->pos+=CS_KSMPS; + p->pos %= (csound->ksmps-offset); + csoundSpinUnLock(p->lock); + } + return OK; } @@ -876,12 +684,22 @@ { int err; - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), p->iname->data, CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL); if (UNLIKELY(err)) return print_chn_err(p, err); +#ifdef HAVE_ATOMIC_BUILTIN + { + union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.i = __sync_fetch_and_add((MYFLT_INT_TYPE *) p->fp, 0); + *(p->arg) = x.d; + } +#else *(p->arg) = *(p->fp); - +#endif return OK; } @@ -891,8 +709,9 @@ { int err; - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); if (LIKELY(!err)) { p->h.opadr = (SUBR) chnget_opcode_perf_k; return OK; @@ -905,9 +724,11 @@ int chnget_opcode_init_a(CSOUND *csound, CHNGET *p) { int err; - - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + p->pos = 0; + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_AUDIO_CHANNEL | CSOUND_INPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); + if (LIKELY(!err)) { p->h.opadr = (SUBR) chnget_opcode_perf_a; return OK; @@ -920,21 +741,67 @@ int chnget_opcode_init_S(CSOUND *csound, CHNGET *p) { int err; + char *s = ((STRINGDAT *) p->arg)->data; + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, + CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); + + if (UNLIKELY(err)) + return print_chn_err(p, err); + csoundSpinLock(p->lock); + if(s != NULL) { + memset(s, '\0', strlen(s)); + mfree(csound, s); + } + s = cs_strdup(csound,(char*) p->fp); + ((STRINGDAT *) p->arg)->data = s; + ((STRINGDAT *) p->arg)->size = strlen(s) + 1; + csoundSpinUnLock(p->lock); + return OK; +} - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, +int chnget_opcode_perf_S(CSOUND *csound, CHNGET *p) +{ + int err; + char *s = ((STRINGDAT *) p->arg)->data; + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); + if (UNLIKELY(err)) return print_chn_err(p, err); - strcpy((char*) p->arg, (char*) p->fp); + if(strcmp(s, (char *) p->fp) == 0) return OK; + + csoundSpinLock(p->lock); + if(((STRINGDAT *) p->arg)->size <= (int) strlen((char *) p->fp)) { + s = cs_strdup(csound,(char*) p->fp); + ((STRINGDAT *) p->arg)->data = s; + ((STRINGDAT *) p->arg)->size = strlen(s) + 1; + } + else strcpy (((STRINGDAT *) p->arg)->data, (char*) p->fp); + + csoundSpinUnLock(p->lock); return OK; } + /* send control value to bus at performance time */ static int chnset_opcode_perf_k(CSOUND *csound, CHNGET *p) { +#ifdef HAVE_ATOMIC_BUILTIN + union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.d = *(p->arg); + __sync_lock_test_and_set((MYFLT_INT_TYPE *)(p->fp),x.i); +#else + csoundSpinLock(p->lock); *(p->fp) = *(p->arg); + csoundSpinUnLock(p->lock); +#endif return OK; } @@ -942,10 +809,29 @@ static int chnset_opcode_perf_a(CSOUND *csound, CHNGET *p) { - /* Need lock for the channel */ - csoundSpinLock(p->lock); - memcpy(p->fp, p->arg, sizeof(MYFLT)*csound->ksmps); - csoundSpinUnLock(p->lock); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if(CS_KSMPS == (unsigned int) csound->ksmps){ + /* Need lock for the channel */ + csoundSpinLock(p->lock); + if (UNLIKELY(offset)) memset(p->fp, '\0', sizeof(MYFLT)*offset); + memcpy(&p->fp[offset], &p->arg[offset], + sizeof(MYFLT)*(CS_KSMPS-offset-early)); + if (UNLIKELY(early)) + memset(&p->fp[early], '\0', sizeof(MYFLT)*(CS_KSMPS-early)); + csoundSpinUnLock(p->lock); + } else { + /* Need lock for the channel */ + csoundSpinLock(p->lock); + if (UNLIKELY(offset)) memset(p->fp, '\0', sizeof(MYFLT)*offset); + memcpy(&p->fp[offset+p->pos], &p->arg[offset], + sizeof(MYFLT)*(CS_KSMPS-offset-early)); + if (UNLIKELY(early)) + memset(&p->fp[early], '\0', sizeof(MYFLT)*(CS_KSMPS-early)); + p->pos += CS_KSMPS; + p->pos %= (csound->ksmps-offset); + csoundSpinUnLock(p->lock); + } return OK; } @@ -953,12 +839,15 @@ static int chnmix_opcode_perf(CSOUND *csound, CHNGET *p) { - int i = 0; - int n = csound->ksmps; - /* Need lock for the channel */ + uint32_t n = 0; + uint32_t nsmps = CS_KSMPS; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if (UNLIKELY(early)) nsmps -= early; + /* Need lock for the channel */ csoundSpinLock(p->lock); - for (i=0; ifp[i] += p->arg[i]; + for (n=offset; nfp[n] += p->arg[n]; } csoundSpinUnLock(p->lock); return OK; @@ -970,7 +859,7 @@ { /* Need lock for the channel */ csoundSpinLock(p->lock); - memset(p->fp, 0, csound->ksmps*sizeof(MYFLT)); + memset(p->fp, 0, CS_KSMPS*sizeof(MYFLT)); /* Should this leave start? */ csoundSpinUnLock(p->lock); return OK; } @@ -980,18 +869,30 @@ int chnset_opcode_init_i(CSOUND *csound, CHNGET *p) { int err; - int *lock; /* Need lock for the channel */ - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL); if (UNLIKELY(err)) return print_chn_err(p, err); - p->lock = lock = csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL); - csoundSpinLock(lock); - *(p->fp) = *(p->arg); - csoundSpinUnLock(lock); + +#ifdef HAVE_ATOMIC_BUILTIN + union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.d = *(p->arg); + __sync_lock_test_and_set((MYFLT_INT_TYPE *)(p->fp),x.i); +#else + { + int *lock; /* Need lock for the channel */ + p->lock = lock = + csoundGetChannelLock(csound, (char*) p->iname->data); + csoundSpinLock(lock); + *(p->fp) = *(p->arg); + csoundSpinUnLock(lock); + } +#endif return OK; } @@ -1001,11 +902,10 @@ { int err; - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL); if (LIKELY(!err)) { - p->lock = csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); p->h.opadr = (SUBR) chnset_opcode_perf_k; return OK; } @@ -1017,12 +917,11 @@ int chnset_opcode_init_a(CSOUND *csound, CHNGET *p) { int err; - - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + p->pos = 0; + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); if (!err) { - p->lock = csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); p->h.opadr = (SUBR) chnset_opcode_perf_a; return OK; } @@ -1035,11 +934,10 @@ { int err; - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); if (LIKELY(!err)) { - p->lock = csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); p->h.opadr = (SUBR) chnmix_opcode_perf; return OK; } @@ -1053,11 +951,10 @@ int err; /* NOTE: p->imode is a pointer to the channel data here */ - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); if (LIKELY(!err)) { - p->lock = csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); p->h.opadr = (SUBR) chnclear_opcode_perf; return OK; } @@ -1068,32 +965,64 @@ int chnset_opcode_init_S(CSOUND *csound, CHNGET *p) { - int err; + int err, size; int *lock; - err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname, + char *s = ((STRINGDAT *) p->arg)->data; + + err = csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL); + size = csoundGetChannelDatasize(csound, p->iname->data); if (UNLIKELY(err)) return print_chn_err(p, err); - if (UNLIKELY((int)strlen((char*) p->arg) >= csound->strVarMaxLen)) { - /* can only happen with constants */ - return csound->InitError(csound, Str("string is too long")); - } p->lock = lock = - csoundGetChannelLock(csound, (char*) p->iname, - CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL); + csoundGetChannelLock(csound, (char*) p->iname->data); csoundSpinLock(lock); - strcpy((char*) p->fp, (char*) p->arg); + if (s && strlen(s) >= (unsigned int) size) { + if(p->fp != NULL) mfree(csound, p->fp); + p->fp = (MYFLT *)cs_strdup(csound, s); + set_channel_data_ptr(csound, p->iname->data,p->fp, strlen(s)+1); + } + else strcpy((char*) p->fp, s); csoundSpinUnLock(lock); return OK; } +int chnset_opcode_perf_S(CSOUND *csound, CHNGET *p) +{ + int err, size; + int *lock; + char *s = ((STRINGDAT *) p->arg)->data; + + if ((err=csoundGetChannelPtr(csound, &(p->fp), (char*) p->iname->data, + CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL))) + return err; + size = csoundGetChannelDatasize(csound, p->iname->data); + + if(strcmp(s, (char *) p->fp) == 0) return OK; + + p->lock = lock = + csoundGetChannelLock(csound, (char*) p->iname->data); + csoundSpinLock(lock); + if (s && strlen(s) >= (unsigned int) size) { + if(p->fp != NULL) mfree(csound, p->fp); + p->fp = (MYFLT *)cs_strdup(csound, s); + set_channel_data_ptr(csound, p->iname->data,p->fp, strlen(s)+1); + } + else strcpy((char*) p->fp, s); + csoundSpinUnLock(lock); + //printf("%s \n", (char *)p->fp); + return OK; +} + /* declare control channel, optionally with special parameters */ int chn_k_opcode_init(CSOUND *csound, CHN_OPCODE_K *p) { MYFLT *dummy; int type, mode, err; + controlChannelHints_t hints; + hints.attributes = NULL; mode = (int)MYFLT2LRND(*(p->imode)); if (UNLIKELY(mode < 1 || mode > 3)) @@ -1103,14 +1032,33 @@ type |= CSOUND_INPUT_CHANNEL; if (mode & 2) type |= CSOUND_OUTPUT_CHANNEL; - err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname, type); + + err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname->data, type); if (err) return print_chn_err(p, err); - type = (int)MYFLT2LRND(*(p->itype)); - err = csoundSetControlChannelParams(csound, (char*) p->iname, type, - *(p->idflt), *(p->imin), *(p->imax)); + hints.behav = CSOUND_CONTROL_CHANNEL_NO_HINTS; + if ((int)MYFLT2LRND(*(p->itype)) == 1) + hints.behav = CSOUND_CONTROL_CHANNEL_INT; + else if ((int)MYFLT2LRND(*(p->itype)) == 2) + hints.behav |= CSOUND_CONTROL_CHANNEL_LIN; + else if ((int)MYFLT2LRND(*(p->itype)) == 3) + hints.behav |= CSOUND_CONTROL_CHANNEL_EXP; + if ((int)MYFLT2LRND(*(p->itype)) != 0) { + hints.attributes = 0; + if (p->INOCOUNT > 10) { + hints.attributes = p->Sattributes->data; + } + hints.dflt = *(p->idflt); + hints.min = *(p->imin); + hints.max = *(p->imax); + hints.x = *(p->ix); + hints.y = *(p->iy); + hints.width = *(p->iwidth); + hints.height = *(p->iheight); + } + err = csoundSetControlChannelHints(csound, (char*) p->iname->data, hints); if (LIKELY(!err)) { - p->lock = csoundGetChannelLock(csound, (char*) p->iname, type); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); return OK; } if (err == CSOUND_MEMORY) @@ -1133,7 +1081,7 @@ type |= CSOUND_INPUT_CHANNEL; if (mode & 2) type |= CSOUND_OUTPUT_CHANNEL; - err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname, type); + err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname->data, type); if (UNLIKELY(err)) return print_chn_err(p, err); return OK; @@ -1154,10 +1102,10 @@ type |= CSOUND_INPUT_CHANNEL; if (mode & 2) type |= CSOUND_OUTPUT_CHANNEL; - err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname, type); + err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname->data, type); if (UNLIKELY(err)) return print_chn_err(p, err); - p->lock = csoundGetChannelLock(csound, (char*) p->iname, type); + p->lock = csoundGetChannelLock(csound, (char*) p->iname->data); return OK; } @@ -1168,6 +1116,8 @@ MYFLT *dummy; const char *argName; int type = CSOUND_CONTROL_CHANNEL, mode, err; + controlChannelHints_t hints; + CHNENTRY *chn; /* must have an output argument of type 'gi', 'gk', 'ga', or 'gS' */ if (UNLIKELY(csound->GetOutputArgCnt(p) != 1)) @@ -1199,24 +1149,37 @@ if (mode & 2) type |= CSOUND_OUTPUT_CHANNEL; /* check if the channel already exists (it should not) */ - err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname, 0); + err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname->data, 0); if (UNLIKELY(err >= 0)) return csound->InitError(csound, Str("channel already exists")); /* now create new channel, using output variable for data storage */ dummy = p->arg; /* THIS NEEDS A LOCK BUT DOES NOT EXIST YET */ - /* lock = csoundGetChannelLock(csound, (char*) p->iname, 0); */ + /* lock = csoundGetChannelLock(csound, (char*) p->iname->data); */ /* csoundSpinLock(lock); */ - err = create_new_channel(csound, &dummy, (char*) p->iname, type); + err = create_new_channel(csound, &dummy, (char*) p->iname->data, type); + /* csoundSpinLock(lock); */ if (err) return print_chn_err(p, err); + + /* Now we need to find the channel entry */ + chn = find_channel(csound, (char*) p->iname->data); + /* free the allocated memory (we will not use it) */ + mfree(csound, chn->data); + /* point to the arg var */ + chn->data = p->arg; + /* if control channel, set additional parameters */ if ((type & CSOUND_CHANNEL_TYPE_MASK) != CSOUND_CONTROL_CHANNEL) return OK; type = (int)MYFLT2LRND(*(p->itype)); - err = csoundSetControlChannelParams(csound, (char*) p->iname, type, - *(p->idflt), *(p->imin), *(p->imax)); + hints.behav = CSOUND_CONTROL_CHANNEL_LIN; + hints.dflt = *(p->idflt); + hints.min = *(p->imin); + hints.max = *(p->imax); + hints.attributes = NULL; + err = csoundSetControlChannelHints(csound, (char*) p->iname->data, hints); if (LIKELY(!err)) return OK; if (err == CSOUND_MEMORY) @@ -1241,7 +1204,7 @@ *(p->idflt) = FL(0.0); *(p->imin) = FL(0.0); *(p->imax) = FL(0.0); - err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname, 0); + err = csoundGetChannelPtr(csound, &dummy, (char*) p->iname->data, 0); /* ...if channel does not exist */ if (err <= 0) return OK; @@ -1251,105 +1214,22 @@ *(p->imode) = (MYFLT) ((err & 48) >> 4); /* check for control channel parameters */ if ((err & 15) == CSOUND_CONTROL_CHANNEL) { - err = csoundGetControlChannelParams(csound, (char*) p->iname, - p->idflt, p->imin, p->imax); - if (UNLIKELY(err > 0)) - *(p->ictltype) = (MYFLT) err; + controlChannelHints_t hints; + err = csoundGetControlChannelHints(csound, (char*) p->iname->data, &hints); + if (UNLIKELY(err > 0)) + *(p->ictltype) = (MYFLT) err; + *(p->ictltype) = hints.behav; + *(p->idflt) = hints.dflt; + *(p->imin) = hints.min; + *(p->imax) = hints.max; } return OK; } -static int dummy_opcode_stub(CSOUND *csound, void *p) -{ - (void) csound; - (void) p; - return OK; -} - -static int chn_send_recv_opcodes_perf(CSOUND *csound, CHNSEND *p) -{ - csound->channelIOCallback_(csound, p->name, p->fp, p->type); - return OK; -} - -static CS_NOINLINE int chn_send_recv_opcodes_init_(CSOUND *csound, - CHNSEND *p, int ioType) -{ - channelEntry_t *pp; - int chnType, mode = 0; - - pp = find_channel(csound, (char*) p->iname); - if (UNLIKELY(pp == (channelEntry_t*) NULL)) { - p->h.opadr = (SUBR) notinit_opcode_stub; - return csound->InitError(csound, Str("channel '%s' does not exist"), - (char*) p->iname); - } - if (UNLIKELY(!(pp->type & ioType))) { - p->h.opadr = (SUBR) notinit_opcode_stub; - return csound->InitError(csound, Str("channel '%s' is not an %s channel"), - Str(ioType == CSOUND_INPUT_CHANNEL ? - "input" : "output")); - } - p->name = &(pp->name[0]); - p->fp = pp->data; - chnType = pp->type & CSOUND_CHANNEL_TYPE_MASK; - p->type = chnType | ioType; - if (chnType != CSOUND_AUDIO_CHANNEL) { - if (*(p->imode) < FL(0.5)) - mode = (chnType == CSOUND_STRING_CHANNEL ? 1 : 3); - else { - mode = (int)(*(p->imode) + FL(0.5)); - if (UNLIKELY(mode > 3)) { - p->h.opadr = (SUBR) notinit_opcode_stub; - return csound->InitError(csound, Str("invalid mode parameter: %d"), - mode); - } - } - } - else - mode = 2; - if (csound->channelIOCallback_ != (CsoundChannelIOCallback_t) NULL) { - if (mode & 2) - p->h.opadr = (SUBR) chn_send_recv_opcodes_perf; - else - p->h.opadr = (SUBR) dummy_opcode_stub; - if (mode & 1) - csound->channelIOCallback_(csound, p->name, p->fp, p->type); - } - else - p->h.opadr = (SUBR) dummy_opcode_stub; - - return OK; -} - -int chnrecv_opcode_init(CSOUND *csound, CHNSEND *p) -{ - return chn_send_recv_opcodes_init_(csound, p, CSOUND_INPUT_CHANNEL); -} - -int chnsend_opcode_init(CSOUND *csound, CHNSEND *p) -{ - return chn_send_recv_opcodes_init_(csound, p, CSOUND_OUTPUT_CHANNEL); -} - /* ********************************************************************** */ /* *************** SENSING ********************************************** */ /* ********************************************************************** */ -#if defined(__unix) || defined(__unix__) || defined(__MACH__) -# ifdef HAVE_SYS_TIME_H -# include -# endif -# ifdef HAVE_SYS_TYPES_H -# include -# endif -# ifdef HAVE_TERMIOS_H -# include -# endif -#elif defined(WIN32) -# include -#endif - int sensekey_perf(CSOUND *csound, KSENSE *p) { int keyCode = 0; @@ -1390,8 +1270,11 @@ if (retval) { char ch = '\0'; - if (UNLIKELY(read(0, &ch, 1)!=1)) - csound->Die(csound, "read failure in sensekey\n"); + if (UNLIKELY(read(0, &ch, 1)!=1)) { + csound->PerfError(csound, p->h.insdshead, + Str("read failure in sensekey\n")); + return NOTOK; + } keyCode = (int)((unsigned char) ch); /* FD_ISSET(0, &rfds) will be true. */ } @@ -1432,3 +1315,282 @@ return OK; } + +/* k-rate and string i/o opcodes */ +/* invalue and outvalue are used with the csoundAPI */ +/* ma++ ingalls matt@sonomatics.com */ + +int kinval(CSOUND *csound, INVAL *p) +{ + if (csound->InputChannelCallback_) + csound->InputChannelCallback_(csound, + (char*) p->channelName.auxp, + p->value, p->channelType); + else + *(p->value) = FL(0.0); + + return OK; +} + +int kinvalS(CSOUND *csound, INVAL *p) +{ + if (csound->InputChannelCallback_) + csound->InputChannelCallback_(csound, + (char*) p->channelName.auxp, + (MYFLT *) ((STRINGDAT *)p->value)->data, + p->channelType); + else memset(((STRINGDAT *)p->value)->data, '\0', ((STRINGDAT *)p->value)->size); + + return OK; +} + + +int invalset_string_S(CSOUND *csound, INVAL *p) +{ + MYFLT *dummy; + int err; + int type; + + const char *s = ((STRINGDAT *)p->valID)->data; + csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); + strcpy((char*) p->channelName.auxp, s); + + p->channelType = &CS_VAR_TYPE_S; + type = CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + if(((STRINGDAT *)p->value)->data == NULL) { + ((STRINGDAT *)p->value)->data = + (char *) mcalloc(csound, INIT_STRING_CHANNEL_DATASIZE); + ((STRINGDAT *)p->value)->size = INIT_STRING_CHANNEL_DATASIZE; + } + /* grab input now for use during i-pass */ + kinvalS(csound, p); + if (!csound->InputChannelCallback_) { + csound->Warning(csound,Str("InputChannelCallback not set.")); + } + return OK; +} + +int invalset_S(CSOUND *csound, INVAL *p) +{ + MYFLT *dummy; + int err; + int type; + + const char *s = ((STRINGDAT *)p->valID)->data; + csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); + strcpy((char*) p->channelName.auxp, s); + + p->channelType = &CS_VAR_TYPE_K; + type = CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* grab input now for use during i-pass */ + kinval(csound, p); + if (!csound->InputChannelCallback_) { + csound->Warning(csound,Str("InputChannelCallback not set.")); + } + return OK; +} + +int invalset_string(CSOUND *csound, INVAL *p) +{ + MYFLT *dummy; + int err; + int type; + + /* convert numerical channel to string name */ + csound->AuxAlloc(csound, 64, &p->channelName); + sprintf((char*) p->channelName.auxp, "%d", (int)MYFLT2LRND(*p->valID)); + + p->channelType = &CS_VAR_TYPE_S; + type = CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + if(((STRINGDAT *)p->value)->data == NULL) { + ((STRINGDAT *)p->value)->data = + (char *) mcalloc(csound, INIT_STRING_CHANNEL_DATASIZE); + ((STRINGDAT *)p->value)->size = INIT_STRING_CHANNEL_DATASIZE; + } + + /* grab input now for use during i-pass */ + kinvalS(csound, p); + if (!csound->InputChannelCallback_) { + csound->Warning(csound,Str("InputChannelCallback not set.")); + } + return OK; +} + + +int invalset(CSOUND *csound, INVAL *p) +{ + MYFLT *dummy; + int err; + int type; + + /* convert numerical channel to string name */ + csound->AuxAlloc(csound, 64, &p->channelName); + sprintf((char*) p->channelName.auxp, "%d", (int)MYFLT2LRND(*p->valID)); + + p->channelType = &CS_VAR_TYPE_K; + type = CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* grab input now for use during i-pass */ + kinval(csound, p); + if (!csound->InputChannelCallback_) { + csound->Warning(csound,Str("InputChannelCallback not set.")); + } + return OK; +} + + + +int koutvalS(CSOUND *csound, OUTVAL *p) +{ + char *chan = (char*)p->channelName.auxp; + + if (csound->OutputChannelCallback_) { + csound->OutputChannelCallback_(csound, chan, + (MYFLT *) ((STRINGDAT *)p->value)->data, + p->channelType); + } + + return OK; +} + +int koutval(CSOUND *csound, OUTVAL *p) +{ + char *chan = (char*)p->channelName.auxp; + + if (csound->OutputChannelCallback_) { + csound->OutputChannelCallback_(csound, chan, p->value, p->channelType); + } + + return OK; +} + +int outvalset_string_S(CSOUND *csound, OUTVAL *p) +{ + MYFLT *dummy; + int type, err; + const char *s = ((STRINGDAT *)p->valID)->data; + csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); + strcpy((char*) p->channelName.auxp, s); + + + p->channelType = &CS_VAR_TYPE_S; + type = CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* send output now for use during i-pass */ + koutvalS(csound, p); + if (!csound->OutputChannelCallback_) { + csound->Warning(csound,Str("OutputChannelCallback not set.")); + } + + return OK; +} + + + +int outvalset_S(CSOUND *csound, OUTVAL *p) +{ + MYFLT *dummy; + int type, err; + const char *s = ((STRINGDAT *)p->valID)->data; + csound->AuxAlloc(csound, strlen(s) + 1, &p->channelName); + strcpy((char*) p->channelName.auxp, s); + + p->channelType = &CS_VAR_TYPE_K; + type = CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* send output now for use during i-pass */ + koutval(csound, p); + if (!csound->OutputChannelCallback_) { + csound->Warning(csound,Str("OutputChannelCallback not set.")); + } + + return OK; +} + + +int outvalset_string(CSOUND *csound, OUTVAL *p) +{ + MYFLT *dummy; + int type, err; + + /* convert numerical channel to string name */ + csound->AuxAlloc(csound, 64, &p->channelName); + sprintf((char*)p->channelName.auxp, "%d", + (int)MYFLT2LRND(*p->valID)); + + p->channelType = &CS_VAR_TYPE_S; + type = CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* send output now for use during i-pass */ + koutvalS(csound, p); + if (!csound->OutputChannelCallback_) { + csound->Warning(csound,Str("OutputChannelCallback not set.")); + } + + return OK; +} + +int outvalset(CSOUND *csound, OUTVAL *p) +{ + MYFLT *dummy; + int type, err; + + /* convert numerical channel to string name */ + csound->AuxAlloc(csound, 64, &p->channelName); + sprintf((char*)p->channelName.auxp, "%d", + (int)MYFLT2LRND(*p->valID)); + + p->channelType = &CS_VAR_TYPE_K; + type = CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL; + + err = csoundGetChannelPtr(csound, &(dummy), (char*) p->channelName.auxp, + type); + if (UNLIKELY(err)) + return print_chn_err(p, err); + + /* send output now for use during i-pass */ + koutval(csound, p); + if (!csound->OutputChannelCallback_) { + csound->Warning(csound,Str("OutputChannelCallback not set.")); + } + + return OK; +} diff -Nru csound-5.17.11~dfsg/OOps/cmath.c csound-6.02~dfsg/OOps/cmath.c --- csound-5.17.11~dfsg/OOps/cmath.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/cmath.c 2014-01-07 16:53:47.000000000 +0000 @@ -33,7 +33,7 @@ MYFLT in = *p->in; MYFLT powerOf = *p->powerOf; if (UNLIKELY(in == FL(0.0) && powerOf == FL(0.0))) - return csound->PerfError(csound, Str("NaN in pow\n")); + return csound->PerfError(csound, p->h.insdshead, Str("NaN in pow\n")); else if (p->norm!=NULL && *p->norm != FL(0.0)) *p->sr = POWER(in, powerOf) / *p->norm; else @@ -43,24 +43,31 @@ int apow(CSOUND *csound, POW *p) /* Power routine for a-rate */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *in = p->in, *out = p->sr; MYFLT powerOf = *p->powerOf; MYFLT norm = (p->norm!=NULL ? *p->norm : FL(1.0)); if (norm==FL(0.0)) norm = FL(1.0); + memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (UNLIKELY(powerOf == FL(0.0))) { MYFLT yy = FL(1.0) / norm; - for (n = 0; n < nsmps; n++) { + for (n = offset; n < nsmps; n++) { MYFLT xx = in[n]; if (UNLIKELY(xx == FL(0.0))) { - return csound->PerfError(csound, Str("NaN in pow\n")); + return csound->PerfError(csound, p->h.insdshead,Str("NaN in pow\n")); } else out[n] = yy; } } else { - for (n = 0; n < nsmps; n++) + for (n = offset; n < nsmps; n++) out[n] = POWER(in[n], powerOf) / norm; } return OK; @@ -267,10 +274,17 @@ int auniform(CSOUND *csound, PRAND *p) /* Uniform distribution */ { MYFLT *out = p->out; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double scale = (double)*p->arg1 * (1.0 / 4294967295.03125); - for (n=0; nrandState_)) * scale); } return OK; @@ -284,13 +298,21 @@ int alinear(CSOUND *csound, PRAND *p) /* Linear random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = linrand(csound, arg1); return OK; + } int iklinear(CSOUND *csound, PRAND *p) @@ -301,11 +323,18 @@ int atrian(CSOUND *csound, PRAND *p) /* Triangle random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = trirand(csound, arg1); return OK; } @@ -331,7 +360,7 @@ { /* rslt = (num1 + diff*phs) * amp */ /* IV - Jul 11 2002 */ *p->ar = (p->num1 + (MYFLT)p->phs * p->dfdmax) * *p->xamp; - p->phs += (int32)(*p->xcps * csound->kicvt); /* phs += inc */ + p->phs += (int32)(*p->xcps * CS_KICVT); /* phs += inc */ if (UNLIKELY(p->phs >= MAXLEN)) { /* when phs overflows, */ p->phs &= PHMASK; /* mod the phs */ p->num1 = p->num2; /* & new num vals */ @@ -350,21 +379,29 @@ int aexprndi(CSOUND *csound, PRANDI *p) { int32 phs = p->phs, inc; - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *ampp, *cpsp; cpsp = p->xcps; ampp = p->xamp; ar = p->ar; - inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0;nsicvt); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset;nnum1 + (MYFLT)phs * p->dfdmax) * *ampp; if (p->ampcod) - ampp++; + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[n]; + else + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[0]; phs += inc; /* phs += inc */ if (p->cpscod) - inc = (int32)(*cpsp++ * csound->sicvt); /* (nxt inc) */ + inc = (int32)(cpsp[n] * csound->sicvt); /* (nxt inc) */ if (UNLIKELY(phs >= MAXLEN)) { /* when phs o'flows */ phs &= PHMASK; p->num1 = p->num2; @@ -378,11 +415,18 @@ int aexp(CSOUND *csound, PRAND *p) /* Exponential random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = exprand(csound, arg1); return OK; } @@ -395,11 +439,18 @@ int abiexp(CSOUND *csound, PRAND *p) /* Bilateral exponential rand */ { /* functions */ - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = biexprand(csound, arg1); return OK; } @@ -412,11 +463,18 @@ int agaus(CSOUND *csound, PRAND *p) /* Gaussian random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = gaussrand(csound, arg1); return OK; } @@ -429,11 +487,18 @@ int acauchy(CSOUND *csound, PRAND *p) /* Cauchy random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = cauchrand(csound, arg1); return OK; } @@ -453,7 +518,7 @@ { /* rslt = (num1 + diff*phs) * amp */ /* IV - Jul 11 2002 */ *p->ar = (p->num1 + (MYFLT)p->phs * p->dfdmax) * *p->xamp; - p->phs += (int32)(*p->xcps * csound->kicvt); /* phs += inc */ + p->phs += (int32)(*p->xcps * CS_KICVT); /* phs += inc */ if (UNLIKELY(p->phs >= MAXLEN)) { /* when phs overflows, */ p->phs &= PHMASK; /* mod the phs */ p->num1 = p->num2; /* & new num vals */ @@ -472,21 +537,29 @@ int agaussi(CSOUND *csound, PRANDI *p) { int32 phs = p->phs, inc; - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *ampp, *cpsp; cpsp = p->xcps; ampp = p->xamp; ar = p->ar; - inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0;nsicvt); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset;nnum1 + (MYFLT)phs * p->dfdmax) * *ampp; if (p->ampcod) - ampp++; - phs += inc; /* phs += inc */ + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[n]; + else + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[0]; + phs += inc; /* phs += inc */ if (p->cpscod) - inc = (int32)(*cpsp++ * csound->sicvt); /* (nxt inc) */ + inc = (int32)(cpsp[n] * csound->sicvt); /* (nxt inc) */ if (UNLIKELY(phs >= MAXLEN)) { /* when phs o'flows */ phs &= PHMASK; p->num1 = p->num2; @@ -506,11 +579,18 @@ int apcauchy(CSOUND *csound, PRAND *p) /* +ve Cauchy random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = pcauchrand(csound, arg1); return OK; } @@ -536,7 +616,7 @@ { /* rslt = (num1 + diff*phs) * amp */ /* IV - Jul 11 2002 */ *p->ar = (p->num1 + (MYFLT)p->phs * p->dfdmax) * *p->xamp; - p->phs += (int32)(*p->xcps * csound->kicvt); /* phs += inc */ + p->phs += (int32)(*p->xcps * CS_KICVT); /* phs += inc */ if (UNLIKELY(p->phs >= MAXLEN)) { /* when phs overflows, */ p->phs &= PHMASK; /* mod the phs */ p->num1 = p->num2; /* & new num vals */ @@ -555,21 +635,29 @@ int acauchyi(CSOUND *csound, PRANDI *p) { int32 phs = p->phs, inc; - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *ampp, *cpsp; cpsp = p->xcps; ampp = p->xamp; ar = p->ar; - inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0;nsicvt); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset;nnum1 + (MYFLT)phs * p->dfdmax) * *ampp; if (p->ampcod) - ampp++; + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[n]; + else + ar[n] = (p->num1 + (MYFLT)phs * p->dfdmax) * ampp[0]; phs += inc; /* phs += inc */ if (p->cpscod) - inc = (int32)(*cpsp++ * csound->sicvt); /* (nxt inc) */ + inc = (int32)(cpsp[n] * csound->sicvt); /* (nxt inc) */ if (UNLIKELY(phs >= MAXLEN)) { /* when phs o'flows */ phs &= PHMASK; p->num1 = p->num2; @@ -583,12 +671,19 @@ int abeta(CSOUND *csound, PRAND *p) /* Beta random functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; MYFLT arg2 = *p->arg2; MYFLT arg3 = *p->arg3; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } for (n = 0; n < nsmps; n++) out[n] = betarand(csound, arg1, arg2, arg3); return OK; @@ -602,12 +697,19 @@ int aweib(CSOUND *csound, PRAND *p) /* Weibull randon functions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; MYFLT arg2 = *p->arg2; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = weibrand(csound, arg1, arg2); return OK; } @@ -620,11 +722,18 @@ int apoiss(CSOUND *csound, PRAND *p) /* Poisson random funcions */ { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; MYFLT arg1 = *p->arg1; - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) out[n] = poissrand(csound, arg1); return OK; } diff -Nru csound-5.17.11~dfsg/OOps/compile_ops.c csound-6.02~dfsg/OOps/compile_ops.c --- csound-5.17.11~dfsg/OOps/compile_ops.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/OOps/compile_ops.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,87 @@ +/* compile_ops.c: + + Copyright (c) 2013 Victor Lazzarini + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include "compile_ops.h" +#include + +int compile_orc_i(CSOUND *csound, COMPILE *p){ + FILE *fp; + int size=0; + char *orc, c, *name; + + + name = ((STRINGDAT *)p->str)->data; + fp = fopen(name, "rb"); + + if(fp == NULL) { + csound->Warning(csound, Str("compileorc: could not open %s\n"), name); + *p->res = FL(CSOUND_ERROR); + return NOTOK; + } + + while(!feof(fp)) + size += fread(&c,1,1,fp); + + if(size==0) { + fclose(fp); + *p->res = FL(CSOUND_ERROR); + csound->InitError(csound, Str("compileorc: could not read %s\n"), name); + return NOTOK; + } + + orc = (char *) mcalloc(csound, size+1); + fseek(fp, 0, SEEK_SET); + fread(orc,1,size,fp); + *p->res = FL(csoundCompileOrc(csound, orc)); + fclose(fp); + mfree(csound,orc); + return OK; +} + +int compile_str_i(CSOUND *csound, COMPILE *p){ + *p->res = FL(csoundCompileOrc(csound, ((STRINGDAT *)p->str)->data)); + return OK; +} + +int read_score_i(CSOUND *csound, COMPILE *p){ + *p->res = FL(csoundReadScore(csound, ((STRINGDAT *)p->str)->data)); + return OK; +} + +int eval_str_i(CSOUND *csound, COMPILE *p){ + *p->res = csoundEvalCode(csound, ((STRINGDAT *)p->str)->data); + return OK; +} + +int eval_str_k(CSOUND *csound, COMPILE *p){ + if(*p->ktrig) + *p->res = csoundEvalCode(csound, ((STRINGDAT *)p->str)->data); + return OK; +} + + +int retval_i(CSOUND *csound, RETVAL *p){ + INSDS *ip = p->h.insdshead; + ip->retval = *p->ret; + return OK; +} + diff -Nru csound-5.17.11~dfsg/OOps/diskin.c csound-6.02~dfsg/OOps/diskin.c --- csound-5.17.11~dfsg/OOps/diskin.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/diskin.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,466 +0,0 @@ -/* - diskin.c: - - Copyright (C) 1998, 2001 matt ingalls, Richard Dobson, John ffitch - (C) 2005 Istvan Varga - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* ugen developed by matt ingalls, ... */ -/* replaced with new implementation based on */ -/* diskin2 by Istvan Varga */ -/* */ -/* diskin - a new soundin that shifts pitch */ -/* based on the old soundin code */ -/* Adjusted to include sndfile library */ - -#include "csoundCore.h" -#include "soundio.h" -#include "diskin.h" -#include - -static CS_NOINLINE void diskin_read_buffer(SOUNDINEW *p, int bufReadPos) -{ - int32 nsmps, bufsmps; - int i; - - /* calculate new buffer frame start position */ - p->bufStartPos = p->bufStartPos + (int32) bufReadPos; - p->bufStartPos &= (~((int32) (p->bufSize - 1))); - bufsmps = (int32) ((p->bufSize + 1) * p->nChannels); - i = 0; - if (p->bufStartPos >= 0L) { - /* number of sample frames to read */ - nsmps = p->fileLength - p->bufStartPos; - if (nsmps > 0) { /* if there is anything to read: */ - nsmps *= (int32) p->nChannels; - if (nsmps > bufsmps) - nsmps = bufsmps; - sf_seek(p->sf, (sf_count_t) p->bufStartPos, SEEK_SET); - i = (int) sf_read_float(p->sf, &(p->buf[0]), (sf_count_t) nsmps); - if (UNLIKELY(i < 0)) /* error ? */ - i = 0; /* clear entire buffer to zero */ - } - } - /* fill rest of buffer with zero samples */ - memset(p->buf+i, 0, sizeof(float)*(bufsmps-i)); - /* while (i < bufsmps) */ - /* p->buf[i++] = 0.0f; */ -} - -/* Mix one sample frame from input file at location 'pos' to outputs */ -/* of opcode 'p', at sample index 'n' (0 <= n < ksmps), with amplitude */ -/* scale 'scl'. */ - -static inline void diskin_get_sample(SOUNDINEW *p, int32 fPos, int n, MYFLT scl) -{ - int bufPos, i; - - if (p->wrapMode) { - if (UNLIKELY(fPos >= p->fileLength)) - fPos -= p->fileLength; - else if (UNLIKELY(fPos < 0L)) - fPos += p->fileLength; - } - bufPos = (int) (fPos - p->bufStartPos); - if (UNLIKELY(bufPos < 0 || bufPos > p->bufSize)) { - /* not in current buffer frame, need to read file */ - diskin_read_buffer(p, bufPos); - /* recalculate buffer position */ - bufPos = (int) (fPos - p->bufStartPos); - } - /* copy all channels from buffer */ - if (p->nChannels == 1) { - p->aOut[0][n] += scl * (MYFLT) p->buf[bufPos]; - } - else if (p->nChannels == 2) { - bufPos += bufPos; - p->aOut[0][n] += scl * (MYFLT) p->buf[bufPos]; - p->aOut[1][n] += scl * (MYFLT) p->buf[bufPos + 1]; - } - else { - bufPos *= p->nChannels; - i = 0; - /* p->aOut[i++][n] += scl * (MYFLT) p->buf[bufPos++]; */ - /* p->aOut[i++][n] += scl * (MYFLT) p->buf[bufPos++]; */ - do { - p->aOut[i++][n] += scl * (MYFLT) p->buf[bufPos++]; - } while (i < p->nChannels); - } -} - -/* calculate buffer size in sample frames */ - -static int diskin_calc_buffer_size(SOUNDINEW *p, int n_monoSamps) -{ - int i, nFrames; - - /* default to 4096 mono samples if zero or negative */ - if (n_monoSamps <= 0) - n_monoSamps = 4096; - /* convert mono samples -> sample frames */ - i = n_monoSamps / p->nChannels; - /* buffer size must be an integer power of two, so round up */ - nFrames = 1; - while (nFrames < i) - nFrames <<= 1; - /* limit to sane range */ - if (nFrames < 128) - nFrames = 128; - else if (nFrames > 1048576) - nFrames = 1048576; - - return nFrames; -} - -static const int diskin_format_table[11] = { - 0, - 0, - SF_FORMAT_RAW | SF_FORMAT_PCM_S8, - SF_FORMAT_RAW | SF_FORMAT_ALAW, - SF_FORMAT_RAW | SF_FORMAT_ULAW, - SF_FORMAT_RAW | SF_FORMAT_PCM_16, - SF_FORMAT_RAW | SF_FORMAT_PCM_32, - SF_FORMAT_RAW | SF_FORMAT_FLOAT, - SF_FORMAT_RAW | SF_FORMAT_PCM_U8, - SF_FORMAT_RAW | SF_FORMAT_PCM_24, - SF_FORMAT_RAW | SF_FORMAT_DOUBLE -}; - -/* init routine for diskin */ - -int newsndinset(CSOUND *csound, SOUNDINEW *p) -{ - double pos; - char name[1024]; - void *fd; - SF_INFO sfinfo; - int n, bsize = (int) *p->ibufsize; - - /* check number of channels */ - p->nChannels = (int) (p->OUTOCOUNT); - if (UNLIKELY(p->nChannels < 1 || p->nChannels > DISKIN2_MAXCHN)) { - return csound->InitError(csound, Str("diskin: invalid number of channels")); - } - /* if already open, close old file first */ - if (p->fdch.fd != NULL) { - /* skip initialisation if requested */ - if (*(p->iSkipInit) != FL(0.0)) - return OK; - fdclose(csound, &(p->fdch)); - } - /* set default format parameters */ - memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.samplerate = (int) (csound->esr + FL(0.5)); - sfinfo.channels = p->nChannels; - /* check for user specified sample format */ - n = (int) (*(p->iSampleFormat) + FL(2.5)) - 1; - if (n == 1) { - sfinfo.format = SF_FORMAT_RAW - | (int) FORMAT2SF(csound->oparms_.outformat); - } - else { - if (UNLIKELY(n < 0 || n > 10)) - return csound->InitError(csound, Str("diskin: unknown sample format")); - sfinfo.format = diskin_format_table[n]; - } - /* open file */ - /* FIXME: name can overflow with very long string */ - csound->strarg2name(csound, name, p->iFileCode, "soundin.", p->XSTRCODE); - fd = csound->FileOpen2(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, - "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); - if (UNLIKELY(fd == NULL)) { - return - csound->InitError(csound, Str("diskin: %s: failed to open file"), name); - } - /* record file handle so that it will be closed at note-off */ - memset(&(p->fdch), 0, sizeof(FDCH)); - p->fdch.fd = fd; - fdrecord(csound, &(p->fdch)); - /* print file information */ - csound->Warning(csound, Str("diskin: opened '%s':\n" - " %d Hz, %d channel(s), " - "%ld sample frames\n"), - csound->GetFileName(fd), - (int) sfinfo.samplerate, (int) sfinfo.channels, - (int32) sfinfo.frames); - /* check number of channels in file (must equal the number of outargs) */ - if (UNLIKELY(sfinfo.channels != p->nChannels && - (csound->oparms_.msglevel & WARNMSG) != 0)) { - return csound->InitError(csound, - Str("diskin: number of output args " - "inconsistent with number of file channels")); - } - /* skip initialisation if requested */ - if (p->initDone && *(p->iSkipInit) != FL(0.0)) - return OK; - /* set file parameters from header info */ - p->fileLength = (int32) sfinfo.frames; - if ((int) (csound->esr + FL(0.5)) != sfinfo.samplerate) { - csound->Warning(csound, Str("diskin: warning: file sample rate (%d) " - "!= orchestra sr (%d)\n"), - sfinfo.samplerate, (int) (csound->esr + FL(0.5))); - } - /* apply dBFS scale unless reading "raw" float file */ - if ((SF2FORMAT(sfinfo.format) == AE_FLOAT || - SF2FORMAT(sfinfo.format) == AE_DOUBLE) && - !(SF2TYPE(sfinfo.format) == TYP_WAV || - SF2TYPE(sfinfo.format) == TYP_AIFF || - SF2TYPE(sfinfo.format) == TYP_W64)) - p->scaleFac = FL(1.0); - else - p->scaleFac = csound->e0dbfs; - /* wrap mode */ - p->wrapMode = (*(p->iWrapMode) == FL(0.0) ? 0 : 1); - if (p->fileLength < 1L) - p->wrapMode = 0; - /* initialise read position */ - pos = (double)*(p->iSkipTime) * (double)sfinfo.samplerate; - if (UNLIKELY(pos > (double)p->fileLength)) { - csound->Warning(csound, Str("skip time larger than audio data, " - "substituting zero.")); - pos = 0.0; - } - else if (UNLIKELY(pos < 0.0)) { - csound->Warning(csound, Str("negative skip time, substituting zero.")); - pos = 0.0; - } - pos = (pos + 0.5) * (double)POS_FRAC_SCALE; - p->pos_frac = (int64_t)pos & (~((int64_t)POS_FRAC_MASK)); - p->pos_frac_inc = (int64_t)0; - p->prv_kTranspose = FL(0.0); - /* initialise buffer */ - p->bufSize = diskin_calc_buffer_size(p, (bsize ? bsize : 4096)); - csound->Warning(csound, Str("bufsize %d\n"), p->bufSize); - p->bufStartPos = -((int32)(p->bufSize << 1)); - - if (p->auxch.auxp == NULL || - p->auxch.size < 2*p->bufSize*sizeof(MYFLT)*p->nChannels) - csound->AuxAlloc(csound,2*sizeof(MYFLT)*p->bufSize*p->nChannels, &p->auxch); - p->buf = (float *) p->auxch.auxp; - - /* done initialisation */ - p->initDone = -1; - - return OK; -} - -static inline void diskin_file_pos_inc(SOUNDINEW *p, int32 *ndx) -{ - p->pos_frac += p->pos_frac_inc; - *ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); - if (p->wrapMode) { - if (*ndx >= p->fileLength) { - *ndx -= p->fileLength; - p->pos_frac -= ((int64_t) p->fileLength << POS_FRAC_SHIFT); - } - else if (*ndx < 0L) { - *ndx += p->fileLength; - p->pos_frac += ((int64_t) p->fileLength << POS_FRAC_SHIFT); - } - } -} - -/* a-rate routine for soundinew */ - -int soundinew(CSOUND *csound, SOUNDINEW *p) -{ - MYFLT a0, a1; - int32 ndx; - int nn, chn; - - if (p->initDone <= 0) { - if (UNLIKELY(!p->initDone)) - return csound->PerfError(csound, Str("diskin: not initialised")); - p->initDone = 1; - /* if no skip time, and playing backwards: start from end of file */ - if (p->pos_frac <= (int64_t)0 && *(p->kTranspose) < FL(0.0)) { - p->pos_frac = (int64_t)(((double)p->fileLength + 0.5) - * (double)POS_FRAC_SCALE); - p->pos_frac = p->pos_frac & (~((int64_t)POS_FRAC_MASK)); - } - } - if (*(p->kTranspose) != p->prv_kTranspose) { - double f; - p->prv_kTranspose = *(p->kTranspose); - f = (double)p->prv_kTranspose * (double)POS_FRAC_SCALE; -#ifdef HAVE_C99 - p->pos_frac_inc = (int64_t) llrint(f); -#else - p->pos_frac_inc = (int64_t) (f + (f < 0.0 ? -0.5 : 0.5)); -#endif - } - /* clear outputs to zero first */ - for (chn = 0; chn < p->nChannels; chn++) - for (nn = 0; nn < csound->ksmps; nn++) - p->aOut[chn][nn] = FL(0.0); - /* file read position */ - ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); - /* ---- linear interpolation ---- */ - for (nn = 0; nn < csound->ksmps; nn++) { - a1 = (MYFLT) ((int) (p->pos_frac & (int64_t) POS_FRAC_MASK)) - * (FL(1.0) / (MYFLT) POS_FRAC_SCALE) * p->scaleFac; - a0 = p->scaleFac - a1; - diskin_get_sample(p, ndx, nn, a0); - ndx++; - diskin_get_sample(p, ndx, nn, a1); - /* update file position */ - diskin_file_pos_inc(p, &ndx); - } - - return OK; -} - -static int soundout_deinit(CSOUND *csound, void *pp) -{ - char *opname = csound->GetOpcodeName(pp); - SNDCOM *p; - - if (strcmp(opname, "soundouts") == 0) - p = &(((SNDOUTS*) pp)->c); - else - p = &(((SNDOUT*) pp)->c); - - if (p->fd != NULL) { - /* flush buffer */ - MYFLT *p0 = (MYFLT*) &(p->outbuf[0]); - MYFLT *p1 = (MYFLT*) p->outbufp; - if (p1 > p0) { - sf_write_MYFLT(p->sf, p0, (sf_count_t) ((MYFLT*) p1 - (MYFLT*) p0)); - p->outbufp = (MYFLT*) &(p->outbuf[0]); - } - /* close file */ - csound->FileClose(csound, p->fd); - p->sf = (SNDFILE*) NULL; - p->fd = NULL; - } - - return OK; -} - -/* RWD:DBFS: NB: thse funcs all supposed to write to a 'raw' file, so - what will people want for 0dbfs handling? really need to update - opcode with more options. */ - -/* init routine for instr soundout */ - -int sndo1set(CSOUND *csound, void *pp) -{ - char *sfname, *opname, sndoutname[256]; - SNDCOM *p; - MYFLT *ifilcod, *iformat; - int filetyp = TYP_RAW, format = csound->oparms_.outformat, nchns = 1; - SF_INFO sfinfo; - - opname = csound->GetOpcodeName(pp); - csound->Warning(csound, Str("%s is deprecated; use fout instead\n"), - opname); - if (strcmp(opname, "soundouts") == 0) { - p = &(((SNDOUTS*) pp)->c); - ifilcod = ((SNDOUTS*) pp)->ifilcod; - iformat = ((SNDOUTS*) pp)->iformat; - nchns++; - } - else { - p = &(((SNDOUT*) pp)->c); - ifilcod = ((SNDOUT*) pp)->ifilcod; - iformat = ((SNDOUT*) pp)->iformat; - } - - if (p->fd != NULL) /* if file already open, */ - return OK; /* return now */ - - csound->RegisterDeinitCallback(csound, pp, soundout_deinit); - - csound->strarg2name(csound, sndoutname, ifilcod, "soundout.", - ((OPDS*) pp)->optext->t.xincod_str); - sfname = sndoutname; - memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.frames = -1; - sfinfo.samplerate = (int) (csound->esr + FL(0.5)); - sfinfo.channels = nchns; - switch ((int) (*iformat + FL(0.5))) { - case 1: format = AE_CHAR; break; - case 4: format = AE_SHORT; break; - case 5: format = AE_LONG; break; - case 6: format = AE_FLOAT; - case 0: break; - default: - return csound->InitError(csound, Str("%s: invalid sample format: %d"), - opname, (int) (*iformat + FL(0.5))); - } - sfinfo.format = TYPE2SF(filetyp) | FORMAT2SF(format); - p->fd = csound->FileOpen2(csound, &(p->sf), CSFILE_SND_W, sfname, &sfinfo, - "SFDIR", type2csfiletype(filetyp, format), 0); - if (p->fd == NULL) { - return csound->InitError(csound, Str("%s cannot open %s"), opname, sfname); - } - sfname = csound->GetFileName(p->fd); - if (format != AE_FLOAT) - sf_command(p->sf, SFC_SET_CLIPPING, NULL, SF_TRUE); - else - sf_command(p->sf, SFC_SET_CLIPPING, NULL, SF_FALSE); -#ifdef USE_DOUBLE - sf_command(p->sf, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE); -#else - sf_command(p->sf, SFC_SET_NORM_FLOAT, NULL, SF_FALSE); -#endif - csound->Warning(csound, Str("%s: opening RAW outfile %s\n"), - opname, sfname); - p->outbufp = p->outbuf; /* fix - isro 20-11-96 */ - p->bufend = p->outbuf + SNDOUTSMPS; /* fix - isro 20-11-96 */ - - return OK; -} - -int soundout(CSOUND *csound, SNDOUT *p) -{ - int nn, nsamps = csound->ksmps; - - if (UNLIKELY(p->c.sf == NULL)) - return csound->PerfError(csound, Str("soundout: not initialised")); - for (nn = 0; nn < nsamps; nn++) { - if (UNLIKELY(p->c.outbufp >= p->c.bufend)) { - sf_write_MYFLT(p->c.sf, p->c.outbuf, p->c.bufend - p->c.outbuf); - p->c.outbufp = p->c.outbuf; - } - *(p->c.outbufp++) = p->asig[nn]; - } - - return OK; -} - -int soundouts(CSOUND *csound, SNDOUTS *p) -{ - int nn, nsamps = csound->ksmps; - - if (UNLIKELY(p->c.sf == NULL)) - return csound->PerfError(csound, Str("soundouts: not initialised")); - for (nn = 0; nn < nsamps; nn++) { - if (UNLIKELY(p->c.outbufp >= p->c.bufend)) { - sf_write_MYFLT(p->c.sf, p->c.outbuf, p->c.bufend - p->c.outbuf); - p->c.outbufp = p->c.outbuf; - } - *(p->c.outbufp++) = p->asig1[nn]; - *(p->c.outbufp++) = p->asig2[nn]; - } - - return OK; -} - diff -Nru csound-5.17.11~dfsg/OOps/diskin2.c csound-6.02~dfsg/OOps/diskin2.c --- csound-5.17.11~dfsg/OOps/diskin2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/diskin2.c 2014-01-07 16:54:20.000000000 +0000 @@ -26,12 +26,20 @@ #include "diskin2.h" #include -static CS_NOINLINE void diskin2_read_buffer(DISKIN2 *p, int bufReadPos) +typedef struct DISKIN_INST_ { + CSOUND *csound; + DISKIN2 *diskin; + struct DISKIN_INST_ *nxt; +} DISKIN_INST; + + +static CS_NOINLINE void diskin2_read_buffer(CSOUND *csound, + DISKIN2 *p, int bufReadPos) { MYFLT *tmp; int32 nsmps; int i; - + IGN(csound); /* swap buffer pointers */ tmp = p->buf; p->buf = p->prvBuf; @@ -58,9 +66,9 @@ if (nsmps > 0L) { /* if there is anything to read: */ if (nsmps > (int32) p->bufSize) nsmps = (int32) p->bufSize; + nsmps *= (int32) p->nChannels; sf_seek(p->sf, (sf_count_t) p->bufStartPos, SEEK_SET); /* convert sample count to mono samples and read file */ - nsmps *= (int32) p->nChannels; i = (int)sf_read_MYFLT(p->sf, p->buf, (sf_count_t) nsmps); if (UNLIKELY(i < 0)) /* error ? */ i = 0; /* clear entire buffer to zero */ @@ -76,31 +84,37 @@ /* of opcode 'p', at sample index 'n' (0 <= n < ksmps), with amplitude */ /* scale 'scl'. */ -static inline void diskin2_get_sample(DISKIN2 *p, int32 fPos, int n, MYFLT scl) +static inline void diskin2_get_sample(CSOUND *csound, + DISKIN2 *p, int32 fPos, int n, MYFLT scl) { int bufPos, i; if (p->wrapMode) { - if (UNLIKELY(fPos >= p->fileLength)) + if (UNLIKELY(fPos >= p->fileLength)){ fPos -= p->fileLength; - else if (UNLIKELY(fPos < 0L)) + } + else if (UNLIKELY(fPos < 0L)){ fPos += p->fileLength; + } } bufPos = (int)(fPos - p->bufStartPos); if (UNLIKELY((unsigned int) bufPos >= (unsigned int) p->bufSize)) { /* not in current buffer frame, need to read file */ - diskin2_read_buffer(p, bufPos); + diskin2_read_buffer(csound, p, bufPos); /* recalculate buffer position */ bufPos = (int)(fPos - p->bufStartPos); } + + if(p->aOut_buf == NULL){ + MYFLT **aOut = p->aOut; /* copy all channels from buffer */ if (p->nChannels == 1) { - p->aOut[0][n] += scl * p->buf[bufPos]; + aOut[0][n] += scl * p->buf[bufPos]; } else if (p->nChannels == 2) { bufPos += bufPos; - p->aOut[0][n] += scl * p->buf[bufPos]; - p->aOut[1][n] += scl * p->buf[bufPos + 1]; + aOut[0][n] += scl * p->buf[bufPos]; + aOut[1][n] += scl * p->buf[bufPos + 1]; } else { bufPos *= p->nChannels; @@ -108,9 +122,30 @@ /* p->aOut[i++][n] += scl * p->buf[bufPos++]; */ /* p->aOut[i++][n] += scl * p->buf[bufPos++]; */ do { - p->aOut[i++][n] += scl * p->buf[bufPos++]; + aOut[i++][n] += scl * p->buf[bufPos++]; } while (i < p->nChannels); } + } else{ + MYFLT *aOut = p->aOut_buf; + int chans = p->nChannels; + /* copy all channels from buffer */ + if (chans == 1) { + aOut[n] += scl * p->buf[bufPos]; + } + else if (chans == 2) { + bufPos += bufPos; + aOut[n*2] += scl * p->buf[bufPos]; + aOut[n*2+1] += scl * p->buf[bufPos+1]; + } + else { + bufPos *= chans;//p->nChannels; + i = 0; + do { + aOut[n*chans+i] += scl * p->buf[bufPos++]; + } while (++i < chans); + } + + } } /* ------------- set up fast sine generator ------------- */ @@ -185,7 +220,45 @@ SF_FORMAT_RAW | SF_FORMAT_DOUBLE }; -int diskin2_init(CSOUND *csound, DISKIN2 *p) +static int diskin2_init_(CSOUND *csound, DISKIN2 *p, int stringname); + +int diskin2_init(CSOUND *csound, DISKIN2 *p) { + p->SkipInit = *p->iSkipInit; + p->WinSize = *p->iWinSize; + p->BufSize = *p->iBufSize; + p->fforceSync = *p->forceSync; + return diskin2_init_(csound,p,0); +} + +int diskin2_init_S(CSOUND *csound, DISKIN2 *p) { + p->SkipInit = *p->iSkipInit; + p->WinSize = *p->iWinSize; + p->BufSize = *p->iBufSize; + p->fforceSync = *p->forceSync; + return diskin2_init_(csound,p,1); +} + +/* VL 11-01-13 diskin_init - calls diskin2_init */ + +int diskin_init(CSOUND *csound, DISKIN2 *p){ + p->SkipInit = *p->iWinSize; + p->WinSize = 2; + p->BufSize = 0; + p->fforceSync = 0; + return diskin2_init_(csound,p,0); +} + +int diskin_init_S(CSOUND *csound, DISKIN2 *p){ + p->SkipInit = *p->iWinSize; + p->WinSize = 2; + p->BufSize = 0; + p->fforceSync = 0; + return diskin2_init_(csound,p,1); +} + +int diskin2_async_deinit(CSOUND *csound, void *p); + +static int diskin2_init_(CSOUND *csound, DISKIN2 *p, int stringname) { double pos; char name[1024]; @@ -196,7 +269,8 @@ /* check number of channels */ p->nChannels = (int)(p->OUTOCOUNT); if (UNLIKELY(p->nChannels < 1 || p->nChannels > DISKIN2_MAXCHN)) { - return csound->InitError(csound, Str("diskin2: invalid number of channels")); + return csound->InitError(csound, + Str("diskin2: invalid number of channels")); } /* if already open, close old file first */ if (p->fdch.fd != NULL) { @@ -216,7 +290,13 @@ sfinfo.format = diskin2_format_table[n]; /* open file */ /* FIXME: name can overflow with very long string */ - csound->strarg2name(csound, name, p->iFileCode, "soundin.", p->XSTRCODE); + if(stringname==0){ + if(ISSTRCOD(*p->iFileCode)) + strncpy(name,get_arg_string(csound, *p->iFileCode), 1023); + else csound->strarg2name(csound, name, p->iFileCode, "soundin.",0); + } + else strncpy(name, ((STRINGDAT *)p->iFileCode)->data, 1023); + fd = csound->FileOpen2(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); if (UNLIKELY(fd == NULL)) { @@ -227,15 +307,7 @@ memset(&(p->fdch), 0, sizeof(FDCH)); p->fdch.fd = fd; fdrecord(csound, &(p->fdch)); - /* print file information */ - if (UNLIKELY((csound->oparms_.msglevel & 7) == 7)) { - csound->Message(csound, Str("diskin2: opened '%s':\n" - " %d Hz, %d channel(s), " - "%ld sample frames\n"), - csound->GetFileName(fd), - (int)sfinfo.samplerate, (int)sfinfo.channels, - (int32) sfinfo.frames); - } + /* check number of channels in file (must equal the number of outargs) */ if (UNLIKELY(sfinfo.channels != p->nChannels)) { return csound->InitError(csound, @@ -245,10 +317,12 @@ /* skip initialisation if requested */ if (p->initDone && *(p->iSkipInit) != FL(0.0)) return OK; + + /* interpolation window size: valid settings are 1 (no interpolation), */ /* 2 (linear interpolation), 4 (cubic interpolation), and integer */ /* multiples of 4 in the range 8 to 1024 (sinc interpolation) */ - p->winSize = (int)(*(p->iWinSize) + FL(0.5)); + p->winSize = (int)((p->WinSize) + FL(0.5)); if (p->winSize < 1) p->winSize = 4; /* use cubic interpolation by default */ else if (p->winSize > 2) { @@ -290,7 +364,7 @@ p->pos_frac_inc = (int64_t)0; p->prv_kTranspose = FL(0.0); /* allocate and initialise buffers */ - p->bufSize = diskin2_calc_buffer_size(p, (int)(*(p->iBufSize) + FL(0.5))); + p->bufSize = diskin2_calc_buffer_size(p, (int)((p->BufSize) + FL(0.5))); n = 2 * p->bufSize * p->nChannels * (int)sizeof(MYFLT); if (n != (int)p->auxData.size) csound->AuxAlloc(csound, (int32) n, &(p->auxData)); @@ -298,14 +372,119 @@ n = p->bufSize * p->nChannels; p->buf = (MYFLT*) (p->auxData.auxp); p->prvBuf = (MYFLT*) p->buf + (int)n; -/* for (i = 0; i < n; i++) */ -/* p->buf[i] = FL(0.0); */ + memset(p->buf, 0, n*sizeof(MYFLT)); + + // create circular buffer, on fail set mode to synchronous + if(csound->realtime_audio_flag==1 && p->fforceSync==0 && + (p->cb = csound->CreateCircularBuffer(csound, + p->bufSize*p->nChannels*2, + sizeof(MYFLT))) != NULL){ + DISKIN_INST **top, *current; + int *start; + // allocate buffer + n = CS_KSMPS*sizeof(MYFLT)*p->nChannels; + if (n != (int)p->auxData2.size) + csound->AuxAlloc(csound, (int32) n, &(p->auxData2)); + p->aOut_buf = (MYFLT *) (p->auxData2.auxp); + memset(p->aOut_buf, 0, n); + p->aOut_bufsize = CS_KSMPS; + + if ((top=(DISKIN_INST **)csound->QueryGlobalVariable(csound, + "DISKIN_INST")) == NULL){ + csound->CreateGlobalVariable(csound, "DISKIN_INST", sizeof(DISKIN_INST *)); + top = (DISKIN_INST **) csound->QueryGlobalVariable(csound, "DISKIN_INST"); + *top = (DISKIN_INST *) mcalloc(csound, sizeof(DISKIN_INST)); + csound->CreateGlobalVariable(csound, "DISKIN_PTHREAD", sizeof(pthread_t)); + csound->CreateGlobalVariable(csound, "DISKIN_THREAD_START", sizeof(int)); + current = *top; + } + else { + current = *top; + while(current->nxt != NULL) { /* find next empty slot in chain */ + current = current->nxt; + } + current->nxt = (DISKIN_INST *) mcalloc(csound, sizeof(DISKIN_INST)); + current = current->nxt; + } + current->csound = csound; + current->diskin = p; + current->nxt = NULL; + + if( *(start = csound->QueryGlobalVariable(csound, + "DISKIN_THREAD_START")) == 0) { + void *diskin_io_thread(void *p); + *start = 1; + pthread_create((pthread_t *)csound->QueryGlobalVariable(csound, + "DISKIN_PTHREAD"), + NULL, diskin_io_thread, *top); + } + csound->RegisterDeinitCallback(csound, p, diskin2_async_deinit); + p->async = 1; + + /* print file information */ + if (UNLIKELY((csound->oparms_.msglevel & 7) == 7)) { + csound->Message(csound, Str("diskin2: opened (asynchronously) '%s':\n" + " %d Hz, %d channel(s), " + "%ld sample frames\n"), + csound->GetFileName(fd), + (int)sfinfo.samplerate, (int)sfinfo.channels, + (int32) sfinfo.frames); + } + } + else { + p->aOut_buf = NULL; + p->aOut_bufsize = 0; + p->async = 0; + /* print file information */ + if (UNLIKELY((csound->oparms_.msglevel & 7) == 7)) { + csound->Message(csound, Str("diskin2: opened '%s':\n" + " %d Hz, %d channel(s), " + "%ld sample frames\n"), + csound->GetFileName(fd), + (int)sfinfo.samplerate, (int)sfinfo.channels, + (int32) sfinfo.frames); + } + } + /* done initialisation */ p->initDone = 1; return OK; } +int diskin2_async_deinit(CSOUND *csound, void *p){ + + DISKIN_INST **top, *current, *prv; + + if ((top = (DISKIN_INST **) + csound->QueryGlobalVariable(csound, "DISKIN_INST")) == NULL) return NOTOK; + current = *top; + prv = NULL; + while(current->diskin != (DISKIN2 *)p) { + prv = current; + current = current->nxt; + } + if(prv == NULL) *top = current->nxt; + else prv->nxt = current->nxt; + + if(*top == NULL) { + int *start; pthread_t *pt; + + start = (int *) csound->QueryGlobalVariable(csound,"DISKIN_THREAD_START"); + *start = 0; + pt = (pthread_t *) csound->QueryGlobalVariable(csound,"DISKIN_PTHREAD"); + //csound->Message(csound, "dealloc %p %d\n", start, *start); + pthread_join(*pt, NULL); + csound->DestroyGlobalVariable(csound, "DISKIN_PTHREAD"); + csound->DestroyGlobalVariable(csound, "DISKIN_THREAD_START"); + csound->DestroyGlobalVariable(csound, "DISKIN_INST"); + } + mfree(csound, current); + csound->DestroyCircularBuffer(csound, ((DISKIN2 *)p)->cb); + + return OK; +} + static inline void diskin2_file_pos_inc(DISKIN2 *p, int32 *ndx) { p->pos_frac += p->pos_frac_inc; @@ -322,16 +501,23 @@ } } -int diskin2_perf(CSOUND *csound, DISKIN2 *p) + +int diskin2_perf_synchronous(CSOUND *csound, DISKIN2 *p) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + int nsmps = CS_KSMPS; + int chn, i, nn; double d, frac_d, x, c, v, pidwarp_d; MYFLT frac, a0, a1, a2, a3, onedwarp, winFact; int32 ndx; - int i, nn, chn, wsized2, warp; + int wsized2, warp; + if (UNLIKELY(p->fdch.fd == NULL) ) goto file_error; - if(!p->initDone && !p->iSkipInit){ - return csound->PerfError(csound, Str("diskin2: not initialised")); + if (!p->initDone && !p->iSkipInit){ + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); } if (*(p->kTranspose) != p->prv_kTranspose) { double f; @@ -345,34 +531,35 @@ } /* clear outputs to zero first */ for (chn = 0; chn < p->nChannels; chn++) - for (nn = 0; nn < csound->ksmps; nn++) + for (nn = 0; nn < nsmps; nn++) p->aOut[chn][nn] = FL(0.0); /* file read position */ + if (UNLIKELY(early)) nsmps -= early; ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); switch (p->winSize) { case 1: /* ---- no interpolation ---- */ - for (nn = 0; nn < csound->ksmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { if (p->pos_frac & ((int64_t)POS_FRAC_SCALE >> 1)) ndx++; /* round to nearest sample */ - diskin2_get_sample(p, ndx, nn, FL(1.0)); + diskin2_get_sample(csound, p, ndx, nn, FL(1.0)); /* update file position */ diskin2_file_pos_inc(p, &ndx); } break; case 2: /* ---- linear interpolation ---- */ - for (nn = 0; nn < csound->ksmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { a1 = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); a0 = FL(1.0) - a1; - diskin2_get_sample(p, ndx, nn, a0); + diskin2_get_sample(csound, p, ndx, nn, a0); ndx++; - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); /* update file position */ diskin2_file_pos_inc(p, &ndx); } break; case 4: /* ---- cubic interpolation ---- */ - for (nn = 0; nn < csound->ksmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { frac = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); a3 = frac * frac; a3 -= FL(1.0); a3 *= (FL(1.0) / FL(6.0)); @@ -380,13 +567,13 @@ a1 = FL(3.0) * a3; a2 -= a1; a0 -= a3; a1 -= frac; a0 *= frac; a1 *= frac; a2 *= frac; a3 *= frac; a1 += FL(1.0); ndx--; /* sample -1 */ - diskin2_get_sample(p, ndx, nn, a0); + diskin2_get_sample(csound, p, ndx, nn, a0); ndx++; /* sample 0 */ - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); ndx++; /* sample +1 */ - diskin2_get_sample(p, ndx, nn, a2); + diskin2_get_sample(csound, p, ndx, nn, a2); ndx++; /* sample +2 */ - diskin2_get_sample(p, ndx, nn, a3); + diskin2_get_sample(csound, p, ndx, nn, a3); /* update file position */ diskin2_file_pos_inc(p, &ndx); } @@ -413,7 +600,7 @@ pidwarp_d = c = 0.0; winFact = p->winFact; } - for (nn = 0; nn < csound->ksmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { frac_d = (double)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) * (1.0 / (double)POS_FRAC_SCALE); ndx += (int32)(1 - wsized2); @@ -425,7 +612,7 @@ do { a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); ndx++; d += 1.0; v += c * x; x += v; } while (--i); @@ -438,7 +625,7 @@ a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; } - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); ndx++; d += 1.0; v += c * x; x += v; /* sample 1 */ @@ -450,7 +637,7 @@ a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; } - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); ndx++; d += 1.0; v += c * x; x += v; /* samples 2 to (window size / 2) */ @@ -458,7 +645,7 @@ do { a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); ndx++; d += 1.0; v += c * x; x += v; } while (--i); @@ -467,7 +654,7 @@ /* avoid division by zero */ if (frac_d < 0.00001 || frac_d > 0.99999) { ndx += (int32) (wsized2 - (frac_d < 0.5 ? 1 : 0)); - diskin2_get_sample(p, ndx, nn, FL(1.0)); + diskin2_get_sample(csound, p, ndx, nn, FL(1.0)); } else { a0 = (MYFLT)(sin(PI * frac_d) / PI); @@ -475,12 +662,12 @@ do { a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = a0 * a1 * a1 / (MYFLT)d; - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); d += 1.0; ndx++; a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; a1 = -(a0 * a1 * a1 / (MYFLT)d); - diskin2_get_sample(p, ndx, nn, a1); + diskin2_get_sample(csound, p, ndx, nn, a1); d += 1.0; ndx++; } while (--i); @@ -492,17 +679,268 @@ } /* apply 0dBFS scale */ for (chn = 0; chn < p->nChannels; chn++) - for (nn = 0; nn < csound->ksmps; nn++) + for (nn = offset; nn < nsmps; nn++) p->aOut[chn][nn] *= csound->e0dbfs; return OK; file_error: - csound->ErrorMsg(csound, "diskin2: file descriptor closed or invalid\n"); + csound->ErrorMsg(csound, Str("diskin2: file descriptor closed or invalid\n")); + return NOTOK; +} + + +int diskin_file_read(CSOUND *csound, DISKIN2 *p) +{ + /* nsmps is bufsize in frames */ + int nsmps = p->aOut_bufsize - p->h.insdshead->ksmps_offset; + int i, nn; + int chn, chans = p->nChannels; + double d, frac_d, x, c, v, pidwarp_d; + MYFLT frac, a0, a1, a2, a3, onedwarp, winFact; + int32 ndx; + int wsized2, warp; + MYFLT *aOut = (MYFLT *)p->aOut_buf; /* needs to be allocated */ + + if (UNLIKELY(p->fdch.fd == NULL) ) goto file_error; + if (!p->initDone && !p->iSkipInit) { + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); + } + if (*(p->kTranspose) != p->prv_kTranspose) { + double f; + p->prv_kTranspose = *(p->kTranspose); + f = (double)p->prv_kTranspose * p->warpScale * (double)POS_FRAC_SCALE; +#ifdef HAVE_C99 + p->pos_frac_inc = (int64_t)llrint(f); +#else + p->pos_frac_inc = (int64_t)(f + (f < 0.0 ? -0.5 : 0.5)); +#endif + } + /* clear outputs to zero first */ + for (chn = 0; chn < chans; chn++) + for (nn = 0; nn < nsmps; nn++) + aOut[chn + nn*chans] = FL(0.0); + /* file read position */ + ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); + switch (p->winSize) { + case 1: /* ---- no interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + if (p->pos_frac & ((int64_t)POS_FRAC_SCALE >> 1)) + ndx++; /* round to nearest sample */ + diskin2_get_sample(csound, p, ndx, nn, FL(1.0)); + /* update file position */ + diskin2_file_pos_inc(p, &ndx); + } + break; + case 2: /* ---- linear interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + a1 = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a0 = FL(1.0) - a1; + diskin2_get_sample(csound, p, ndx, nn, a0); + ndx++; + diskin2_get_sample(csound, p, ndx, nn, a1); + /* update file position */ + diskin2_file_pos_inc(p, &ndx); + } + break; + case 4: /* ---- cubic interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + frac = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a3 = frac * frac; a3 -= FL(1.0); a3 *= (FL(1.0) / FL(6.0)); + a2 = frac; a2 += FL(1.0); a0 = (a2 *= FL(0.5)); a0 -= FL(1.0); + a1 = FL(3.0) * a3; a2 -= a1; a0 -= a3; a1 -= frac; + a0 *= frac; a1 *= frac; a2 *= frac; a3 *= frac; a1 += FL(1.0); + ndx--; /* sample -1 */ + diskin2_get_sample(csound, p, ndx, nn, a0); + ndx++; /* sample 0 */ + diskin2_get_sample(csound, p, ndx, nn, a1); + ndx++; /* sample +1 */ + diskin2_get_sample(csound, p, ndx, nn, a2); + ndx++; /* sample +2 */ + diskin2_get_sample(csound, p, ndx, nn, a3); + /* update file position */ + diskin2_file_pos_inc(p, &ndx); + } + break; + default: /* ---- sinc interpolation ---- */ + wsized2 = p->winSize >> 1; + nn = POS_FRAC_SCALE + (POS_FRAC_SCALE >> 12); + if (p->pos_frac_inc > (int64_t) nn || + p->pos_frac_inc < (int64_t) (-nn)) { + warp = 1; /* enable warp */ + onedwarp = (p->pos_frac_inc >= (int64_t) 0 ? + ((MYFLT)nn / (MYFLT)p->pos_frac_inc) + : ((MYFLT)(-nn) / (MYFLT)p->pos_frac_inc)); + pidwarp_d = PI * (double)onedwarp; + c = 2.0 * cos(pidwarp_d) - 2.0; + /* correct window for kwarp */ + x = v = (double)wsized2; x *= x; x = 1.0 / x; + v *= (double)onedwarp; v -= (double)((int)v) + 0.5; v *= 4.0 * v; + winFact = (MYFLT)(((double)p->winFact - x) * v + x); + } + else { + warp = 0; + onedwarp = FL(0.0); + pidwarp_d = c = 0.0; + winFact = p->winFact; + } + for (nn = 0; nn < nsmps; nn++) { + frac_d = (double)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (1.0 / (double)POS_FRAC_SCALE); + ndx += (int32)(1 - wsized2); + d = (double)(1 - wsized2) - frac_d; + if (warp) { /* ---- warp enabled ---- */ + init_sine_gen((1.0 / PI), pidwarp_d, (pidwarp_d * d), c, &x, &v); + /* samples -(window size / 2 - 1) to -1 */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + /* sample 0 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d < 0.00003)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* sample 1 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d > 0.99997)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* samples 2 to (window size / 2) */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + } + else { /* ---- warp disabled ---- */ + /* avoid division by zero */ + if (frac_d < 0.00001 || frac_d > 0.99999) { + ndx += (int32) (wsized2 - (frac_d < 0.5 ? 1 : 0)); + diskin2_get_sample(csound, p, ndx, nn, FL(1.0)); + } + else { + a0 = (MYFLT)(sin(PI * frac_d) / PI); + i = wsized2; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = a0 * a1 * a1 / (MYFLT)d; + diskin2_get_sample(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = -(a0 * a1 * a1 / (MYFLT)d); + diskin2_get_sample(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + } while (--i); + } + } + /* update file position */ + diskin2_file_pos_inc(p, &ndx); + } + } + { + /* write to circular buffer */ + int lc, mc=0, nc=nsmps*p->nChannels; + int *start = csound->QueryGlobalVariable(csound,"DISKIN_THREAD_START"); + do{ + lc = csound->WriteCircularBuffer(csound, p->cb, &aOut[mc], nc); + nc -= lc; + mc += lc; + } while(nc && *start); + } + return OK; + file_error: + csound->ErrorMsg(csound, Str("diskin2: file descriptor closed or invalid\n")); return NOTOK; } + +int diskin2_perf_asynchronous(CSOUND *csound, DISKIN2 *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + MYFLT samp; + int chn; + void *cb = p->cb; + int chans = p->nChannels; + + if(offset || early) { + for (chn = 0; chn < chans; chn++) + for (nn = 0; nn < nsmps; nn++) + p->aOut[chn][nn] = FL(0.0); + if (UNLIKELY(early)) nsmps -= early; + } + + if (UNLIKELY(p->fdch.fd == NULL)) return NOTOK; + if(!p->initDone && !p->iSkipInit){ + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); + } + for (nn = offset; nn < nsmps; nn++){ + + for (chn = 0; chn < chans; chn++) { + //int i =0; + //do { + // i = + csound->ReadCircularBuffer(csound, cb, &samp, 1); + //} while(i==0); + p->aOut[chn][nn] = csound->e0dbfs*samp; + } + } + return OK; +} + + +void *diskin_io_thread(void *p){ + DISKIN_INST *current = (DISKIN_INST *) p; + int wakeup = 1000*current->csound->ksmps/current->csound->esr; + int *start = + current->csound->QueryGlobalVariable(current->csound,"DISKIN_THREAD_START"); + while(*start){ + current = (DISKIN_INST *) p; + csoundSleep(wakeup > 0 ? wakeup : 1); + while(current != NULL){ + diskin_file_read(current->csound, current->diskin); + current = current->nxt; + } + } + return NULL; +} + + +int diskin2_perf(CSOUND *csound, DISKIN2 *p) { + if(!p->async) return diskin2_perf_synchronous(csound, p); + else return diskin2_perf_asynchronous(csound, p); +} + /* -------- soundin opcode: simplified version of diskin2 -------- */ -static void soundin_read_buffer(SOUNDIN_ *p, int bufReadPos) +static void soundin_read_buffer(CSOUND *csound, SOUNDIN_ *p, int bufReadPos) { int i = 0; @@ -516,10 +954,15 @@ lsmps = p->fileLength - p->bufStartPos; if (lsmps > (int_least64_t) 0) { /* if there is anything to read: */ nsmps = (lsmps < (int_least64_t) p->bufSize ? (int) lsmps : p->bufSize); - sf_seek(p->sf, (sf_count_t) p->bufStartPos, SEEK_SET); /* convert sample count to mono samples and read file */ nsmps *= (int) p->nChannels; - i = (int) sf_read_MYFLT(p->sf, p->buf, (sf_count_t) nsmps); + if(csound->realtime_audio_flag==0){ + sf_seek(p->sf, (sf_count_t) p->bufStartPos, SEEK_SET); + i = (int) sf_read_MYFLT(p->sf, p->buf, (sf_count_t) nsmps); + } + else + i = (int) csound->ReadAsync(csound, p->fdch.fd, p->buf, + (sf_count_t) nsmps); if (UNLIKELY(i < 0)) /* error ? */ i = 0; /* clear entire buffer to zero */ } @@ -552,7 +995,7 @@ return nFrames; } -int sndinset(CSOUND *csound, SOUNDIN_ *p) +static int sndinset_(CSOUND *csound, SOUNDIN_ *p, int stringname) { double pos; char name[1024]; @@ -563,8 +1006,10 @@ /* check number of channels */ p->nChannels = (int) (p->OUTOCOUNT); if (UNLIKELY(p->nChannels < 1 || p->nChannels > DISKIN2_MAXCHN)) { - return csound->InitError(csound, Str("soundin: invalid number of channels")); + return csound->InitError(csound, + Str("soundin: invalid number of channels")); } + p->bufSize = soundin_calc_buffer_size(p, (int) (*(p->iBufSize) + FL(0.5))); /* if already open, close old file first */ if (p->fdch.fd != NULL) { /* skip initialisation if requested */ @@ -589,9 +1034,20 @@ } /* open file */ /* FIXME: name can overflow with very long string */ - csound->strarg2name(csound, name, p->iFileCode, "soundin.", p->XSTRCODE); + if(stringname==0){ + if(ISSTRCOD(*p->iFileCode)) + strncpy(name,get_arg_string(csound, *p->iFileCode), 1023); + else csound->strarg2name(csound, name, p->iFileCode, "soundin.",0); + } + else strncpy(name, ((STRINGDAT *)p->iFileCode)->data, 1023); + + if(csound->realtime_audio_flag==0) fd = csound->FileOpen2(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, - "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + else + fd = csound->FileOpenAsync(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, + p->bufSize*p->nChannels, 0); if (UNLIKELY(fd == NULL)) { return csound->InitError(csound, Str("soundin: %s: failed to open file"), name); @@ -635,7 +1091,6 @@ pos = (double)*(p->iSkipTime) * (double)sfinfo.samplerate; p->read_pos = (int_least64_t)(pos + (pos >= 0.0 ? 0.5 : -0.5)); /* allocate and initialise buffer */ - p->bufSize = soundin_calc_buffer_size(p, (int) (*(p->iBufSize) + FL(0.5))); n = p->bufSize * p->nChannels; if (n != (int) p->auxData.size) csound->AuxAlloc(csound, (int32) (n * (int) sizeof(MYFLT)), &(p->auxData)); @@ -646,45 +1101,1097 @@ else p->bufStartPos = -((int_least64_t) p->bufSize); /* done initialisation */ + if(csound->realtime_audio_flag) { + csound->FSeekAsync(csound,p->fdch.fd, p->read_pos, SEEK_SET); + // csound->Message(csound, "using async code \n"); + } return OK; } +int sndinset(CSOUND *csound, SOUNDIN_ *p){ + return sndinset_(csound,p,0); +} + +int sndinset_S(CSOUND *csound, SOUNDIN_ *p){ + return sndinset_(csound,p,1); +} + + int soundin(CSOUND *csound, SOUNDIN_ *p) { - int nn, nsmps=csound->ksmps, bufPos, i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps=CS_KSMPS, bufPos; + int i; if (UNLIKELY(p->fdch.fd == NULL)) { - return csound->PerfError(csound, Str("soundin: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("soundin: not initialised")); } - for (nn = 0; nn < nsmps; nn++) { + if (UNLIKELY(offset)) for (i=0; inChannels; i++) + memset(p->aOut[i], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i=0; inChannels; i++) + memset(&(p->aOut[i][nsmps]), '\0', early*sizeof(MYFLT)); + } + for (nn = offset; nn < nsmps; nn++) { bufPos = (int) (p->read_pos - p->bufStartPos); if ((unsigned int) bufPos >= (unsigned int) p->bufSize) { /* not in current buffer frame, need to read file */ - soundin_read_buffer(p, bufPos); + soundin_read_buffer(csound, p, bufPos); /* recalculate buffer position */ - bufPos = (int) (p->read_pos - p->bufStartPos); + bufPos = (int) (p->read_pos - p->bufStartPos); } /* copy all channels from buffer */ if (p->nChannels == 1) { - p->aOut[0][nn] = p->scaleFac * p->buf[bufPos]; - } - else if (p->nChannels == 2) { - bufPos += bufPos; - p->aOut[0][nn] = p->scaleFac * p->buf[bufPos]; - p->aOut[1][nn] = p->scaleFac * p->buf[bufPos + 1]; - } - else { - bufPos *= p->nChannels; - i = 0; + p->aOut[0][nn] = p->scaleFac * (MYFLT) p->buf[bufPos]; + } + else if (p->nChannels == 2) { + bufPos += bufPos; + p->aOut[0][nn] = p->scaleFac * p->buf[bufPos]; + p->aOut[1][nn] = p->scaleFac * p->buf[bufPos + 1]; + } + else { + bufPos *= p->nChannels; + i = 0; /* p->aOut[i++][nn] = p->scaleFac * p->buf[bufPos++]; */ /* p->aOut[i++][nn] = p->scaleFac * p->buf[bufPos++]; */ - do { - p->aOut[i++][nn] = p->scaleFac * p->buf[bufPos++]; - } while (i < p->nChannels); - } - p->read_pos++; + do { + p->aOut[i++][nn] = p->scaleFac * p->buf[bufPos++]; + } while (i < p->nChannels); + } + p->read_pos++; } - return OK; } +static int soundout_deinit(CSOUND *csound, void *pp) +{ + char *opname = csound->GetOpcodeName(pp); + SNDCOM *q; + + if (strcmp(opname, "soundouts") == 0) + q = &(((SNDOUTS*) pp)->c); + else + q = &(((SNDOUT*) pp)->c); + + if (q->fd != NULL) { + /* flush buffer */ + MYFLT *p0 = (MYFLT*) &(q->outbuf[0]); + MYFLT *p1 = (MYFLT*) q->outbufp; + if (p1 > p0) { + sf_write_MYFLT(q->sf, p0, (sf_count_t) ((MYFLT*) p1 - (MYFLT*) p0)); + q->outbufp = (MYFLT*) &(q->outbuf[0]); + } + /* close file */ + csound->FileClose(csound, q->fd); + q->sf = (SNDFILE*) NULL; + q->fd = NULL; + } + + return OK; +} + +/* RWD:DBFS: NB: thse funcs all supposed to write to a 'raw' file, so + what will people want for 0dbfs handling? really need to update + opcode with more options. */ + +/* init routine for instr soundout */ + +static int sndo1set_(CSOUND *csound, void *pp, int stringname) +{ + char *sfname, *opname, name[1024]; + SNDCOM *q; + MYFLT *ifilcod, *iformat; + int filetyp = TYP_RAW, format = csound->oparms_.outformat, nchns = 1; + SF_INFO sfinfo; + //SNDOUTS *p = (SNDOUTS*) pp; + + opname = csound->GetOpcodeName(pp); + csound->Warning(csound, Str("%s is deprecated; use fout instead\n"), + opname); + if (strcmp(opname, "soundouts") == 0 || strcmp(opname, "soundouts.i") == 0) { + q = &(((SNDOUTS*) pp)->c); + ifilcod = ((SNDOUTS*) pp)->ifilcod; + iformat = ((SNDOUTS*) pp)->iformat; + nchns++; + } + else { + q = &(((SNDOUT*) pp)->c); + ifilcod = ((SNDOUT*) pp)->ifilcod; + iformat = ((SNDOUT*) pp)->iformat; + } + + if (q->fd != NULL) /* if file already open, */ + return OK; /* return now */ + + csound->RegisterDeinitCallback(csound, pp, soundout_deinit); + + if(stringname==0){ + if(ISSTRCOD(*ifilcod)) strncpy(name,get_arg_string(csound, *ifilcod), 1023); + else csound->strarg2name(csound, name, ifilcod, "soundout.",0); + } + else strncpy(name, ((STRINGDAT *)ifilcod)->data, 1023); + + sfname = name; + memset(&sfinfo, 0, sizeof(SF_INFO)); + sfinfo.frames = -1; + sfinfo.samplerate = (int) (csound->esr + FL(0.5)); + sfinfo.channels = nchns; + switch ((int) (*iformat + FL(0.5))) { + case 1: format = AE_CHAR; break; + case 4: format = AE_SHORT; break; + case 5: format = AE_LONG; break; + case 6: format = AE_FLOAT; + case 0: break; + default: + return csound->InitError(csound, Str("%s: invalid sample format: %d"), + opname, (int) (*iformat + FL(0.5))); + } + sfinfo.format = TYPE2SF(filetyp) | FORMAT2SF(format); + if (q->fd == NULL) { + return csound->InitError(csound, Str("%s cannot open %s"), opname, sfname); + } + sfname = csound->GetFileName(q->fd); + if (format != AE_FLOAT) + sf_command(q->sf, SFC_SET_CLIPPING, NULL, SF_TRUE); + else + sf_command(q->sf, SFC_SET_CLIPPING, NULL, SF_FALSE); +#ifdef USE_DOUBLE + sf_command(q->sf, SFC_SET_NORM_DOUBLE, NULL, SF_FALSE); +#else + sf_command(q->sf, SFC_SET_NORM_FLOAT, NULL, SF_FALSE); +#endif + csound->Warning(csound, Str("%s: opening RAW outfile %s\n"), + opname, sfname); + q->outbufp = q->outbuf; /* fix - isro 20-11-96 */ + q->bufend = q->outbuf + SNDOUTSMPS; /* fix - isro 20-11-96 */ + + return OK; +} + +int sndoutset(CSOUND *csound, SNDOUT *p){ + return sndo1set_(csound,p,0); +} + +int sndoutset_S(CSOUND *csound, SNDOUT *p){ + return sndo1set_(csound,p,1); +} + + +int soundout(CSOUND *csound, SNDOUT *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + + if (UNLIKELY(p->c.sf == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("soundout: not initialised")); + if (UNLIKELY(early)) nsmps -= early; + for (nn = offset; nn < nsmps; nn++) { + if (UNLIKELY(p->c.outbufp >= p->c.bufend)) { + + sf_write_MYFLT(p->c.sf, p->c.outbuf, p->c.bufend - p->c.outbuf); + p->c.outbufp = p->c.outbuf; + } + *(p->c.outbufp++) = p->asig[nn]; + } + + return OK; +} + +int soundouts(CSOUND *csound, SNDOUTS *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + + if (UNLIKELY(p->c.sf == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("soundouts: not initialised")); + if (UNLIKELY(early)) nsmps -= early; + for (nn = offset; nn < nsmps; nn++) { + if (UNLIKELY(p->c.outbufp >= p->c.bufend)) { + sf_write_MYFLT(p->c.sf, p->c.outbuf, p->c.bufend - p->c.outbuf); + p->c.outbufp = p->c.outbuf; + } + *(p->c.outbufp++) = p->asig1[nn]; + *(p->c.outbufp++) = p->asig2[nn]; + } + + return OK; +} + +static CS_NOINLINE void diskin2_read_buffer_array(CSOUND *csound, + DISKIN2_ARRAY *p, int bufReadPos) +{ + MYFLT *tmp; + int32 nsmps; + int i; + IGN(csound); + /* swap buffer pointers */ + tmp = p->buf; + p->buf = p->prvBuf; + p->prvBuf = tmp; + /* check if requested data can be found in previously used buffer */ + i = (int)((int32) bufReadPos + (p->bufStartPos - p->prvBufStartPos)); + if ((unsigned int) i < (unsigned int) p->bufSize) { + int32 tmp2; + /* yes, only need to swap buffers and return */ + tmp2 = p->bufStartPos; + p->bufStartPos = p->prvBufStartPos; + p->prvBufStartPos = tmp2; + return; + } + /* save buffer position */ + p->prvBufStartPos = p->bufStartPos; + /* calculate new buffer frame start position */ + p->bufStartPos = p->bufStartPos + (int32) bufReadPos; + p->bufStartPos &= (~((int32) (p->bufSize - 1))); + i = 0; + if (p->bufStartPos >= 0L) { + /* number of sample frames to read */ + nsmps = p->fileLength - p->bufStartPos; + if (nsmps > 0L) { /* if there is anything to read: */ + if (nsmps > (int32) p->bufSize) + nsmps = (int32) p->bufSize; + nsmps *= (int32) p->nChannels; + sf_seek(p->sf, (sf_count_t) p->bufStartPos, SEEK_SET); + /* convert sample count to mono samples and read file */ + i = (int)sf_read_MYFLT(p->sf, p->buf, (sf_count_t) nsmps); + if (UNLIKELY(i < 0)) /* error ? */ + i = 0; /* clear entire buffer to zero */ + } + } + /* fill rest of buffer with zero samples */ + memset(&p->buf[i], 0, sizeof(MYFLT)*(p->bufSize * p->nChannels-i)); + /* while (i < (p->bufSize * p->nChannels)) */ + /* p->buf[i++] = FL(0.0); */ +} + + +static int diskin2_calc_buffer_size_array(DISKIN2_ARRAY *p, int n_monoSamps) +{ + int i, nFrames; + + /* default to 4096 mono samples if zero or negative */ + if (n_monoSamps <= 0) + n_monoSamps = 4096; + /* convert mono samples -> sample frames */ + i = n_monoSamps / p->nChannels; + /* limit to sane range */ + if (i < p->winSize) + i = p->winSize; + else if (i > 1048576) + i = 1048576; + /* buffer size must be an integer power of two, so round up */ + nFrames = 64; /* will be at least 128 sample frames */ + do { + nFrames <<= 1; + } while (nFrames < i); + + return nFrames; +} + +static inline void diskin2_file_pos_inc_array(DISKIN2_ARRAY *p, int32 *ndx) +{ + p->pos_frac += p->pos_frac_inc; + *ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); + if (p->wrapMode) { + if (*ndx >= p->fileLength) { + *ndx -= p->fileLength; + p->pos_frac -= ((int64_t)p->fileLength << POS_FRAC_SHIFT); + } + else if (*ndx < 0L) { + *ndx += p->fileLength; + p->pos_frac += ((int64_t)p->fileLength << POS_FRAC_SHIFT); + } + } +} + +static inline void diskin2_get_sample_array(CSOUND *csound, + DISKIN2_ARRAY *p, int32 fPos, + int n, MYFLT scl) +{ + int bufPos, i; + int ksmps = CS_KSMPS; + MYFLT *aOut = (MYFLT *) p->aOut->data; + + if (p->wrapMode) { + if (UNLIKELY(fPos >= p->fileLength)){ + fPos -= p->fileLength; + } + else if (UNLIKELY(fPos < 0L)){ + fPos += p->fileLength; + } + } + bufPos = (int)(fPos - p->bufStartPos); + if (UNLIKELY((unsigned int) bufPos >= (unsigned int) p->bufSize)) { + /* not in current buffer frame, need to read file */ + diskin2_read_buffer_array(csound, p, bufPos); + /* recalculate buffer position */ + bufPos = (int)(fPos - p->bufStartPos); + } + + /* copy all channels from buffer */ + if(p->aOut_buf == NULL){ + if (p->nChannels == 1) { + aOut[n] += scl * p->buf[bufPos]; + } + else if (p->nChannels == 2) { + bufPos += bufPos; + aOut[n] += scl * p->buf[bufPos]; + aOut[n+ksmps] += scl * p->buf[bufPos + 1]; + } + else { + bufPos *= p->nChannels; + i = 0; + do { + aOut[i*ksmps+n] += scl * p->buf[bufPos++]; + } while (++i < p->nChannels); + } + } else{ + MYFLT *aOut = p->aOut_buf; + int chans = p->nChannels; + /* copy all channels from buffer */ + if (chans == 1) { + aOut[n] += scl * p->buf[bufPos]; + } + else if (chans == 2) { + bufPos += bufPos; + aOut[n*2] += scl * p->buf[bufPos]; + aOut[n*2+1] += scl * p->buf[bufPos+1]; + } + else { + bufPos *= chans;//p->nChannels; + i = 0; + do { + aOut[n*chans+i] += scl * p->buf[bufPos++]; + } while (++i < chans); + } + + } +} + +int diskin2_async_deinit_array(CSOUND *csound, void *p){ + + DISKIN_INST **top, *current, *prv; + + if ((top = (DISKIN_INST **) + csound->QueryGlobalVariable(csound, "DISKIN_INST_ARRAY")) == NULL) + return NOTOK; + current = *top; + prv = NULL; + while(current->diskin != (DISKIN2 *)p) { + prv = current; + current = current->nxt; + } + if(prv == NULL) *top = current->nxt; + else prv->nxt = current->nxt; + + if(*top == NULL) { + int *start; pthread_t *pt; + + start = (int *) csound->QueryGlobalVariable(csound, + "DISKIN_THREAD_START_ARRAY"); + *start = 0; + pt = (pthread_t *) csound->QueryGlobalVariable(csound,"DISKIN_PTHREAD_ARRAY"); + //csound->Message(csound, "dealloc %p %d\n", start, *start); + pthread_join(*pt, NULL); + csound->DestroyGlobalVariable(csound, "DISKIN_PTHREAD_ARRAY"); + csound->DestroyGlobalVariable(csound, "DISKIN_THREAD_START_ARRAY"); + csound->DestroyGlobalVariable(csound, "DISKIN_INST_ARRAY"); + } + mfree(csound, current); + csound->DestroyCircularBuffer(csound, ((DISKIN2_ARRAY *)p)->cb); + + return OK; +} + + +int diskin_file_read_array(CSOUND *csound, DISKIN2_ARRAY *p) +{ + /* nsmps is bufsize in frames */ + int nsmps = p->aOut_bufsize - p->h.insdshead->ksmps_offset; + int i, nn; + int chn, chans = p->nChannels; + double d, frac_d, x, c, v, pidwarp_d; + MYFLT frac, a0, a1, a2, a3, onedwarp, winFact; + int32 ndx; + int wsized2, warp; + MYFLT *aOut = (MYFLT *)p->aOut_buf; /* needs to be allocated */ + + if (UNLIKELY(p->fdch.fd == NULL) ) goto file_error; + if (!p->initDone && !p->iSkipInit) { + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); + } + if (*(p->kTranspose) != p->prv_kTranspose) { + double f; + p->prv_kTranspose = *(p->kTranspose); + f = (double)p->prv_kTranspose * p->warpScale * (double)POS_FRAC_SCALE; +#ifdef HAVE_C99 + p->pos_frac_inc = (int64_t)llrint(f); +#else + p->pos_frac_inc = (int64_t)(f + (f < 0.0 ? -0.5 : 0.5)); +#endif + } + /* clear outputs to zero first */ + for (chn = 0; chn < chans; chn++) + for (nn = 0; nn < nsmps; nn++) + aOut[chn + nn*chans] = FL(0.0); + /* file read position */ + ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); + switch (p->winSize) { + case 1: /* ---- no interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + if (p->pos_frac & ((int64_t)POS_FRAC_SCALE >> 1)) + ndx++; /* round to nearest sample */ + diskin2_get_sample_array(csound, p, ndx, nn, FL(1.0)); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + case 2: /* ---- linear interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + a1 = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a0 = FL(1.0) - a1; + diskin2_get_sample_array(csound, p, ndx, nn, a0); + ndx++; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + case 4: /* ---- cubic interpolation ---- */ + for (nn = 0; nn < nsmps; nn++) { + frac = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a3 = frac * frac; a3 -= FL(1.0); a3 *= (FL(1.0) / FL(6.0)); + a2 = frac; a2 += FL(1.0); a0 = (a2 *= FL(0.5)); a0 -= FL(1.0); + a1 = FL(3.0) * a3; a2 -= a1; a0 -= a3; a1 -= frac; + a0 *= frac; a1 *= frac; a2 *= frac; a3 *= frac; a1 += FL(1.0); + ndx--; /* sample -1 */ + diskin2_get_sample_array(csound, p, ndx, nn, a0); + ndx++; /* sample 0 */ + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; /* sample +1 */ + diskin2_get_sample_array(csound, p, ndx, nn, a2); + ndx++; /* sample +2 */ + diskin2_get_sample_array(csound, p, ndx, nn, a3); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + default: /* ---- sinc interpolation ---- */ + wsized2 = p->winSize >> 1; + nn = POS_FRAC_SCALE + (POS_FRAC_SCALE >> 12); + if (p->pos_frac_inc > (int64_t) nn || + p->pos_frac_inc < (int64_t) (-nn)) { + warp = 1; /* enable warp */ + onedwarp = (p->pos_frac_inc >= (int64_t) 0 ? + ((MYFLT)nn / (MYFLT)p->pos_frac_inc) + : ((MYFLT)(-nn) / (MYFLT)p->pos_frac_inc)); + pidwarp_d = PI * (double)onedwarp; + c = 2.0 * cos(pidwarp_d) - 2.0; + /* correct window for kwarp */ + x = v = (double)wsized2; x *= x; x = 1.0 / x; + v *= (double)onedwarp; v -= (double)((int)v) + 0.5; v *= 4.0 * v; + winFact = (MYFLT)(((double)p->winFact - x) * v + x); + } + else { + warp = 0; + onedwarp = FL(0.0); + pidwarp_d = c = 0.0; + winFact = p->winFact; + } + for (nn = 0; nn < nsmps; nn++) { + frac_d = (double)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (1.0 / (double)POS_FRAC_SCALE); + ndx += (int32)(1 - wsized2); + d = (double)(1 - wsized2) - frac_d; + if (warp) { /* ---- warp enabled ---- */ + init_sine_gen((1.0 / PI), pidwarp_d, (pidwarp_d * d), c, &x, &v); + /* samples -(window size / 2 - 1) to -1 */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + /* sample 0 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d < 0.00003)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* sample 1 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d > 0.99997)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* samples 2 to (window size / 2) */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + } + else { /* ---- warp disabled ---- */ + /* avoid division by zero */ + if (frac_d < 0.00001 || frac_d > 0.99999) { + ndx += (int32) (wsized2 - (frac_d < 0.5 ? 1 : 0)); + diskin2_get_sample_array(csound, p, ndx, nn, FL(1.0)); + } + else { + a0 = (MYFLT)(sin(PI * frac_d) / PI); + i = wsized2; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = a0 * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = -(a0 * a1 * a1 / (MYFLT)d); + diskin2_get_sample_array(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + } while (--i); + } + } + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + } + { + /* write to circular buffer */ + int lc, mc=0, nc=nsmps*p->nChannels; + int *start = csound->QueryGlobalVariable(csound,"DISKIN_THREAD_START"); + do{ + lc = csound->WriteCircularBuffer(csound, p->cb, &aOut[mc], nc); + nc -= lc; + mc += lc; + } while(nc && *start); + } + return OK; + file_error: + csound->ErrorMsg(csound, Str("diskin2: file descriptor closed or invalid\n")); + return NOTOK; +} + +void *diskin_io_thread_array(void *p){ + DISKIN_INST *current = (DISKIN_INST *) p; + int wakeup = 1000*current->csound->ksmps/current->csound->esr; + int *start = + current->csound->QueryGlobalVariable(current->csound, + "DISKIN_THREAD_START_ARRAY"); + while(*start){ + current = (DISKIN_INST *) p; + csoundSleep(wakeup > 0 ? wakeup : 1); + while(current != NULL){ + diskin_file_read_array(current->csound, (DISKIN2_ARRAY *)current->diskin); + current = current->nxt; + } + } + return NULL; +} + + +static int diskin2_init_array(CSOUND *csound, DISKIN2_ARRAY *p, int stringname) +{ + double pos; + char name[1024]; + void *fd; + SF_INFO sfinfo; + int n; + ARRAYDAT *t = p->aOut; + + /* if already open, close old file first */ + if (p->fdch.fd != NULL) { + /* skip initialisation if requested */ + if (*(p->iSkipInit) != FL(0.0)) + return OK; + fdclose(csound, &(p->fdch)); + } + /* set default format parameters */ + memset(&sfinfo, 0, sizeof(SF_INFO)); + sfinfo.samplerate = (int)(csound->esr + FL(0.5)); + sfinfo.channels = p->nChannels; + /* check for user specified sample format */ + n = (int)(*(p->iSampleFormat) + FL(2.5)) - 1; + if (UNLIKELY(n < 0 || n > 10)) + return csound->InitError(csound, Str("diskin2: unknown sample format")); + sfinfo.format = diskin2_format_table[n]; + /* open file */ + /* FIXME: name can overflow with very long string */ + if(stringname==0){ + if(ISSTRCOD(*p->iFileCode)) + strncpy(name,get_arg_string(csound, *p->iFileCode), 1023); + else csound->strarg2name(csound, name, p->iFileCode, "soundin.",0); + } + else strncpy(name, ((STRINGDAT *)p->iFileCode)->data, 1023); + + fd = csound->FileOpen2(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + if (UNLIKELY(fd == NULL)) { + return csound->InitError(csound, + Str("diskin2: %s: failed to open file"), name); + } + /* record file handle so that it will be closed at note-off */ + memset(&(p->fdch), 0, sizeof(FDCH)); + p->fdch.fd = fd; + fdrecord(csound, &(p->fdch)); + + /* get number of channels in file */ + p->nChannels = sfinfo.channels; + + if (UNLIKELY(t->data == NULL)) { + /* create array */ + CS_VARIABLE* var; + int memSize; + t->dimensions = 1; + t->sizes = mcalloc(csound, sizeof(int)); + t->sizes[0] = p->nChannels; + var = t->arrayType->createVariable(csound, NULL); + t->arrayMemberSize = var->memBlockSize; + memSize = var->memBlockSize*(t->sizes[0]); + t->data = mcalloc(csound, memSize); + + } else{ + /* check dim 1 to see if it matches channels*/ + if(t->sizes[0] < p->nChannels) + return csound->InitError(csound, + Str("diskin2: output array too small")); + } + + /* skip initialisation if requested */ + if (p->initDone && *(p->iSkipInit) != FL(0.0)) + return OK; + + /* interpolation window size: valid settings are 1 (no interpolation), */ + /* 2 (linear interpolation), 4 (cubic interpolation), and integer */ + /* multiples of 4 in the range 8 to 1024 (sinc interpolation) */ + p->winSize = (int)((p->WinSize) + FL(0.5)); + if (p->winSize < 1) + p->winSize = 4; /* use cubic interpolation by default */ + else if (p->winSize > 2) { + /* cubic/sinc: round to nearest integer multiple of 4 */ + p->winSize = (p->winSize + 2) & (~3L); + if ((uint32) p->winSize > 1024UL) + p->winSize = 1024; + /* constant for window calculation */ + p->winFact = (FL(1.0) - POWER(p->winSize * FL(0.85172), -FL(0.89624))) + / ((MYFLT)((p->winSize * p->winSize) >> 2)); + } + /* set file parameters from header info */ + p->fileLength = (int32) sfinfo.frames; + p->warpScale = 1.0; + if ((int)(csound->esr + FL(0.5)) != sfinfo.samplerate) { + if (LIKELY(p->winSize != 1)) { + /* will automatically convert sample rate if interpolation is enabled */ + p->warpScale = (double)sfinfo.samplerate / (double)csound->esr; + } + else { + csound->Warning(csound, Str("diskin2: warning: file sample rate (%d) " + "!= orchestra sr (%d)\n"), + sfinfo.samplerate, (int)(csound->esr + FL(0.5))); + } + } + /* wrap mode */ + p->wrapMode = (*(p->iWrapMode) == FL(0.0) ? 0 : 1); + if (UNLIKELY(p->fileLength < 1L)) + p->wrapMode = 0; + /* initialise read position */ + pos = (double)*(p->iSkipTime) * (double)csound->esr * p->warpScale; + pos *= (double)POS_FRAC_SCALE; + p->pos_frac = (int64_t)(pos >= 0.0 ? (pos + 0.5) : (pos - 0.5)); + if (p->wrapMode) { + p->pos_frac %= ((int64_t)p->fileLength << POS_FRAC_SHIFT); + if (UNLIKELY(p->pos_frac < (int64_t)0)) + p->pos_frac += ((int64_t)p->fileLength << POS_FRAC_SHIFT); + } + p->pos_frac_inc = (int64_t)0; + p->prv_kTranspose = FL(0.0); + /* allocate and initialise buffers */ + p->bufSize = diskin2_calc_buffer_size_array(p, (int)((p->BufSize) + FL(0.5))); + n = 2 * p->bufSize * p->nChannels * (int)sizeof(MYFLT); + if (n != (int)p->auxData.size) + csound->AuxAlloc(csound, (int32) n, &(p->auxData)); + p->bufStartPos = p->prvBufStartPos = -((int32)p->bufSize); + n = p->bufSize * p->nChannels; + p->buf = (MYFLT*) (p->auxData.auxp); + p->prvBuf = (MYFLT*) p->buf + (int)n; + + memset(p->buf, 0, n*sizeof(MYFLT)); + + // create circular buffer, on fail set mode to synchronous + if(csound->realtime_audio_flag==1 && p->fforceSync==0 && + (p->cb = csound->CreateCircularBuffer(csound, + p->bufSize*p->nChannels*2, + sizeof(MYFLT))) != NULL){ + DISKIN_INST **top, *current; + int *start; + // allocate buffer + n = CS_KSMPS*sizeof(MYFLT)*p->nChannels; + if (n != (int)p->auxData2.size) + csound->AuxAlloc(csound, (int32) n, &(p->auxData2)); + p->aOut_buf = (MYFLT *) (p->auxData2.auxp); + memset(p->aOut_buf, 0, n); + p->aOut_bufsize = CS_KSMPS; + + if ((top=(DISKIN_INST **) + csound->QueryGlobalVariable(csound, + "DISKIN_INST_ARRAY")) == NULL){ + csound->CreateGlobalVariable(csound, + "DISKIN_INST_ARRAY", sizeof(DISKIN_INST *)); + top = (DISKIN_INST **) csound->QueryGlobalVariable(csound, + "DISKIN_INST_ARRAY"); + *top = (DISKIN_INST *) mcalloc(csound, sizeof(DISKIN_INST)); + csound->CreateGlobalVariable(csound, + "DISKIN_PTHREAD_ARRAY", sizeof(pthread_t)); + csound->CreateGlobalVariable(csound, + "DISKIN_THREAD_START_ARRAY", sizeof(int)); + current = *top; + } + else { + current = *top; + while(current->nxt != NULL) { /* find next empty slot in chain */ + current = current->nxt; + } + current->nxt = (DISKIN_INST *) mcalloc(csound, sizeof(DISKIN_INST)); + current = current->nxt; + } + current->csound = csound; + current->diskin = (DISKIN2 *) p; + current->nxt = NULL; + + if (*(start = + csound->QueryGlobalVariable(csound, + "DISKIN_THREAD_START_ARRAY")) == 0) { + void *diskin_io_thread(void *p); + *start = 1; + pthread_create((pthread_t *)csound->QueryGlobalVariable(csound, + "DISKIN_PTHREAD_ARRAY"), + NULL, diskin_io_thread_array, *top); + } + csound->RegisterDeinitCallback(csound, (DISKIN2 *) p, + diskin2_async_deinit_array); + p->async = 1; + + /* print file information */ + if (UNLIKELY((csound->oparms_.msglevel & 7) == 7)) { + csound->Message(csound, Str("diskin2: opened (asynchronously) '%s':\n" + " %d Hz, %d channel(s), " + "%ld sample frames\n"), + csound->GetFileName(fd), + (int)sfinfo.samplerate, (int)sfinfo.channels, + (int32) sfinfo.frames); + } + } + else { + p->aOut_buf = NULL; + p->aOut_bufsize = 0; + p->async = 0; + /* print file information */ + if (UNLIKELY((csound->oparms_.msglevel & 7) == 7)) { + csound->Message(csound, Str("diskin2: opened '%s':\n" + " %d Hz, %d channel(s), " + "%ld sample frames\n"), + csound->GetFileName(fd), + (int)sfinfo.samplerate, (int)sfinfo.channels, + (int32) sfinfo.frames); + } + } + + /* done initialisation */ + p->initDone = 1; + return OK; +} + + + +int diskin2_perf_synchronous_array(CSOUND *csound, DISKIN2_ARRAY *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + int nsmps = CS_KSMPS, ksmps = CS_KSMPS; + int chn, i, nn; + double d, frac_d, x, c, v, pidwarp_d; + MYFLT frac, a0, a1, a2, a3, onedwarp, winFact; + int32 ndx; + int wsized2, warp; + MYFLT *aOut = (MYFLT *) p->aOut->data; + + + if (UNLIKELY(p->fdch.fd == NULL) ) goto file_error; + if (!p->initDone && !p->iSkipInit){ + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); + } + if (*(p->kTranspose) != p->prv_kTranspose) { + double f; + p->prv_kTranspose = *(p->kTranspose); + f = (double)p->prv_kTranspose * p->warpScale * (double)POS_FRAC_SCALE; +#ifdef HAVE_C99 + p->pos_frac_inc = (int64_t)llrint(f); +#else + p->pos_frac_inc = (int64_t)(f + (f < 0.0 ? -0.5 : 0.5)); +#endif + } + /* clear outputs to zero first */ + for (chn = 0; chn < p->nChannels; chn++) + for (nn = 0; nn < nsmps; nn++) + aOut[chn*ksmps+nn] = FL(0.0); + /* file read position */ + if (UNLIKELY(early)) nsmps -= early; + ndx = (int32) (p->pos_frac >> POS_FRAC_SHIFT); + switch (p->winSize) { + case 1: /* ---- no interpolation ---- */ + for (nn = offset; nn < nsmps; nn++) { + if (p->pos_frac & ((int64_t)POS_FRAC_SCALE >> 1)) + ndx++; /* round to nearest sample */ + diskin2_get_sample_array(csound, p, ndx, nn, FL(1.0)); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + case 2: /* ---- linear interpolation ---- */ + for (nn = offset; nn < nsmps; nn++) { + a1 = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a0 = FL(1.0) - a1; + diskin2_get_sample_array(csound, p, ndx, nn, a0); + ndx++; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + case 4: /* ---- cubic interpolation ---- */ + for (nn = offset; nn < nsmps; nn++) { + frac = (MYFLT)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (FL(1.0) / (MYFLT)POS_FRAC_SCALE); + a3 = frac * frac; a3 -= FL(1.0); a3 *= (FL(1.0) / FL(6.0)); + a2 = frac; a2 += FL(1.0); a0 = (a2 *= FL(0.5)); a0 -= FL(1.0); + a1 = FL(3.0) * a3; a2 -= a1; a0 -= a3; a1 -= frac; + a0 *= frac; a1 *= frac; a2 *= frac; a3 *= frac; a1 += FL(1.0); + ndx--; /* sample -1 */ + diskin2_get_sample_array(csound, p, ndx, nn, a0); + ndx++; /* sample 0 */ + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; /* sample +1 */ + diskin2_get_sample_array(csound, p, ndx, nn, a2); + ndx++; /* sample +2 */ + diskin2_get_sample_array(csound, p, ndx, nn, a3); + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + break; + default: /* ---- sinc interpolation ---- */ + wsized2 = p->winSize >> 1; + nn = POS_FRAC_SCALE + (POS_FRAC_SCALE >> 12); + if (p->pos_frac_inc > (int64_t) nn || + p->pos_frac_inc < (int64_t) (-nn)) { + warp = 1; /* enable warp */ + onedwarp = (p->pos_frac_inc >= (int64_t) 0 ? + ((MYFLT)nn / (MYFLT)p->pos_frac_inc) + : ((MYFLT)(-nn) / (MYFLT)p->pos_frac_inc)); + pidwarp_d = PI * (double)onedwarp; + c = 2.0 * cos(pidwarp_d) - 2.0; + /* correct window for kwarp */ + x = v = (double)wsized2; x *= x; x = 1.0 / x; + v *= (double)onedwarp; v -= (double)((int)v) + 0.5; v *= 4.0 * v; + winFact = (MYFLT)(((double)p->winFact - x) * v + x); + } + else { + warp = 0; + onedwarp = FL(0.0); + pidwarp_d = c = 0.0; + winFact = p->winFact; + } + for (nn = offset; nn < nsmps; nn++) { + frac_d = (double)((int)(p->pos_frac & (int64_t)POS_FRAC_MASK)) + * (1.0 / (double)POS_FRAC_SCALE); + ndx += (int32)(1 - wsized2); + d = (double)(1 - wsized2) - frac_d; + if (warp) { /* ---- warp enabled ---- */ + init_sine_gen((1.0 / PI), pidwarp_d, (pidwarp_d * d), c, &x, &v); + /* samples -(window size / 2 - 1) to -1 */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + /* sample 0 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d < 0.00003)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* sample 1 */ + /* avoid division by zero */ + if (UNLIKELY(frac_d > 0.99997)) { + a1 = onedwarp; + } + else { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + } + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + /* samples 2 to (window size / 2) */ + i = wsized2 - 1; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = (MYFLT)x * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + ndx++; + d += 1.0; v += c * x; x += v; + } while (--i); + } + else { /* ---- warp disabled ---- */ + /* avoid division by zero */ + if (frac_d < 0.00001 || frac_d > 0.99999) { + ndx += (int32) (wsized2 - (frac_d < 0.5 ? 1 : 0)); + diskin2_get_sample_array(csound, p, ndx, nn, FL(1.0)); + } + else { + a0 = (MYFLT)(sin(PI * frac_d) / PI); + i = wsized2; + do { + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = a0 * a1 * a1 / (MYFLT)d; + diskin2_get_sample_array(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + a1 = (MYFLT)d; a1 = FL(1.0) - a1 * a1 * winFact; + a1 = -(a0 * a1 * a1 / (MYFLT)d); + diskin2_get_sample_array(csound, p, ndx, nn, a1); + d += 1.0; + ndx++; + } while (--i); + } + } + /* update file position */ + diskin2_file_pos_inc_array(p, &ndx); + } + } + /* apply 0dBFS scale */ + for (chn = 0; chn < p->nChannels; chn++) + for (nn = offset; nn < nsmps; nn++) + aOut[chn*ksmps+nn] *= csound->e0dbfs; + return OK; + file_error: + csound->ErrorMsg(csound, Str("diskin2: file descriptor closed or invalid\n")); + return NOTOK; +} + + + +int diskin2_perf_asynchronous_array(CSOUND *csound, DISKIN2_ARRAY *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS, ksmps = CS_KSMPS; + MYFLT samp; + int chn; + void *cb = p->cb; + int chans = p->nChannels; + MYFLT *aOut = (MYFLT *) p->aOut->data; + + if(offset || early) { + for (chn = 0; chn < chans; chn++) + for (nn = 0; nn < nsmps; nn++) + aOut[chn*ksmps+nn] = FL(0.0); + if (UNLIKELY(early)) nsmps -= early; + } + + if (UNLIKELY(p->fdch.fd == NULL)) return NOTOK; + if(!p->initDone && !p->iSkipInit){ + return csound->PerfError(csound, p->h.insdshead, + Str("diskin2: not initialised")); + } + for (nn = offset; nn < nsmps; nn++){ + + for (chn = 0; chn < chans; chn++) { + //int i =0; + //do { + // i = + csound->ReadCircularBuffer(csound, cb, &samp, 1); + //} while(i==0); + aOut[chn*ksmps+nn] = csound->e0dbfs*samp; + } + } + return OK; +} + +int diskin2_init_array_I(CSOUND *csound, DISKIN2_ARRAY *p) { + p->SkipInit = *p->iSkipInit; + p->WinSize = *p->iWinSize; + p->BufSize = *p->iBufSize; + p->fforceSync = *p->forceSync; + return diskin2_init_array(csound,p,0); +} + +int diskin2_init_array_S(CSOUND *csound, DISKIN2_ARRAY *p) { + p->SkipInit = *p->iSkipInit; + p->WinSize = *p->iWinSize; + p->BufSize = *p->iBufSize; + p->fforceSync = *p->forceSync; + return diskin2_init_array(csound,p,1); +} + +/* diskin_init_array - calls diskin2_init_array */ + +int diskin_init_array_I(CSOUND *csound, DISKIN2_ARRAY *p){ + p->SkipInit = *p->iWinSize; + p->WinSize = 2; + p->BufSize = 0; + p->fforceSync = 0; + return diskin2_init_array(csound,p,0); +} + +int diskin_init_array_S(CSOUND *csound, DISKIN2_ARRAY *p){ + p->SkipInit = *p->iWinSize; + p->WinSize = 2; + p->BufSize = 0; + p->fforceSync = 0; + return diskin2_init_array(csound,p,1); +} + +int diskin2_perf_array(CSOUND *csound, DISKIN2_ARRAY *p) { + if(!p->async) return diskin2_perf_synchronous_array(csound, p); + else return diskin2_perf_asynchronous_array(csound, p); +} diff -Nru csound-5.17.11~dfsg/OOps/disprep.c csound-6.02~dfsg/OOps/disprep.c --- csound-5.17.11~dfsg/OOps/disprep.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/disprep.c 2014-01-07 16:54:20.000000000 +0000 @@ -30,9 +30,6 @@ #ifdef MSVC /* Thanks to Richard Dobson */ # define hypot _hypot #endif -#if defined(__WATCOMC__) || defined(__ncc) -extern double hypot(double, double); -#endif int printv(CSOUND *csound, PRINTV *p) { @@ -57,7 +54,7 @@ p->size = *p->points; } if ((p->fdata.auxp == NULL) || - (p->fdata.size < (int) (p->size*sizeof(MYFLT)))) { + (p->fdata.size < (unsigned int) (p->size*sizeof(MYFLT)))) { csound->AuxAlloc(csound, p->size*sizeof(MYFLT), &p->fdata); } sprintf(strmsg, Str("instr %d, pvs-signal %s:"), @@ -90,7 +87,7 @@ char strmsg[256]; if (p->h.optext->t.intype == 'k') - npts = (int32)(*p->iprd * csound->ekr); + npts = (int32)(*p->iprd * CS_EKR); else npts = (int32)(*p->iprd * csound->esr); if (UNLIKELY(npts <= 0)) { return csound->InitError(csound, Str("illegal iprd in display")); @@ -153,16 +150,20 @@ p->nxtp = fp; return OK; err1: - return csound->PerfError(csound, Str("display: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("display: not initialised")); } int dsplay(CSOUND *csound, DSPLAY *p) { MYFLT *fp = p->nxtp, *sp = p->signal, *endp = p->endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + nsmps -= early; if (!p->nprds) { - for (n=0; n= endp) { fp = p->begp; @@ -172,7 +173,7 @@ } else { MYFLT *fp2 = fp + p->bufpts; - for (n=0; npntcnt)) { @@ -246,7 +247,7 @@ return csound->InitError(csound, Str("window size must be power of two")); } if (p->h.optext->t.intype == 'k') - step_size = (int32)(*p->iprd * csound->ekr); + step_size = (int32)(*p->iprd * CS_EKR); else step_size = (int32)(*p->iprd * csound->esr); if (UNLIKELY(step_size <= 0)) { return csound->InitError(csound, Str("illegal iprd in ffy display")); @@ -377,16 +378,20 @@ p->bufp = bufp; return OK; err1: - return csound->PerfError(csound, Str("dispfft: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("dispfft: not initialised")); } int dspfft(CSOUND *csound, DSPFFT *p) { MYFLT *sigp = p->signal, *bufp = p->bufp, *endp = p->endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; - for (n=0; nsampbuf) { /* skip any spare samples */ bufp++; sigp++; } @@ -417,7 +422,8 @@ p->bufp = bufp; return OK; err1: - return csound->PerfError(csound, Str("dispfft: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("dispfft: not initialised")); } #define NTERMS 4 @@ -431,9 +437,9 @@ MYFLT b, iperiod = *p->iprd; char strmsg[256]; - if (UNLIKELY((p->timcount = (int)(csound->ekr * iperiod)) <= 0)) + if (UNLIKELY((p->timcount = (int)(CS_EKR * iperiod)) <= 0)) return csound->InitError(csound, Str("illegal iperiod")); - if (UNLIKELY((p->dtimcnt = (int)(csound->ekr * *p->idisprd)) < 0)) + if (UNLIKELY((p->dtimcnt = (int)(CS_EKR * *p->idisprd)) < 0)) return csound->InitError(csound, Str("illegal idisprd")); if (UNLIKELY((p->tweek = *p->itweek) <= 0)) return csound->InitError(csound, Str("illegal itweek")); @@ -518,11 +524,11 @@ } } /* calc input lo-pass filter coefs */ - b = FL(2.0) - COS((*p->ihp * 6.28318 * csound->onedkr)); + b = FL(2.0) - COS((*p->ihp * 6.28318 * CS_ONEDKR)); p->coef1 = b - SQRT(b * b - FL(1.0)); p->coef0 = FL(1.0) - p->coef1; p->yt1 = FL(0.0); - p->fwdcoef = POWER(FL(0.5), p->timcount*csound->onedkr/(*p->ihtim)); + p->fwdcoef = POWER(FL(0.5), p->timcount*CS_ONEDKR/(*p->ihtim)); p->fwdmask = FL(0.0); #ifdef DEBUG csound->Message(csound, @@ -531,7 +537,7 @@ #endif p->thresh = *p->ithresh; /* record incoming loudness threshold */ p->xfdbak = *p->ixfdbak; /* & expectation feedback fraction */ - p->tempscal = FL(60.0) * csound->ekr / p->timcount; + p->tempscal = FL(60.0) * CS_EKR / p->timcount; p->avglam = p->tempscal / *p->istartempo; /* init the tempo factors */ p->tempo = FL(0.0); p->hcur = p->hbeg; /* init the circular ptrs */ @@ -557,9 +563,9 @@ p->yt1 = p->coef0 * *p->kin + p->coef1 * p->yt1; /* get lo-pass of kinput */ if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ - if (!(--p->countdown)) { /* then on countdown: */ + if (!(--p->countdown)) { /* then on countdown: */ MYFLT *memp; - MYFLT kin, expect, *xcur = p->xcur; /* xcur from prv pass */ + MYFLT kin, expect, *xcur = p->xcur; /* xcur from prv pass */ MYFLT lamtot = FL(0.0), weightot = FL(0.0); p->countdown = p->timcount; /* reset the countdown */ @@ -697,6 +703,7 @@ *p->kout = p->tempo; /* put current tempo */ return OK; err1: - return csound->PerfError(csound, Str("tempest: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tempest: not initialised")); } diff -Nru csound-5.17.11~dfsg/OOps/dumpf.c csound-6.02~dfsg/OOps/dumpf.c --- csound-5.17.11~dfsg/OOps/dumpf.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/dumpf.c 2014-01-07 16:54:20.000000000 +0000 @@ -37,7 +37,86 @@ CSFTYPE_FLOATS_TEXT, }; -int kdmpset(CSOUND *csound, KDUMP *p) +int kdmpset_S(CSOUND *csound, KDUMP *p) { + /* open in curdir or pathname */ + char soundoname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + strncpy(soundoname, ((STRINGDAT *)p->ifilcod)->data, 1023); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, + "wb", "", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundoname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = p->timcount; + return OK; + +} + + +int kdmpset_p(CSOUND *csound, KDUMP *p) +{ + /* open in curdir or pathname */ + char soundoname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundoname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", 0); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, + "wb", "", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundoname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = p->timcount; + return OK; +} + +int kdmp2set_S(CSOUND *csound, KDUMP2 *p) +{ + /* open in curdir or pathname */ + char soundoname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + strncpy(soundoname, ((STRINGDAT *)p->ifilcod)->data, 1023); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, + "wb", "", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundoname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = p->timcount; + return OK; +} + + +int kdmp2set_p(CSOUND *csound, KDUMP2 *p) { /* open in curdir or pathname */ char soundoname[1024]; @@ -48,7 +127,9 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", p->XSTRCODE); + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundoname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, @@ -56,13 +137,14 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundoname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = p->timcount; return OK; } -int kdmp2set(CSOUND *csound, KDUMP2 *p) + +int kdmp3set_S(CSOUND *csound, KDUMP3 *p) { /* open in curdir or pathname */ char soundoname[1024]; @@ -73,7 +155,7 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", p->XSTRCODE); + strncpy(soundoname, ((STRINGDAT *)p->ifilcod)->data, 1023); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, @@ -81,13 +163,15 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundoname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = p->timcount; return OK; } -int kdmp3set(CSOUND *csound, KDUMP3 *p) + + +int kdmp3set_p(CSOUND *csound, KDUMP3 *p) { /* open in curdir or pathname */ char soundoname[1024]; @@ -98,7 +182,9 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", p->XSTRCODE); + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundoname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, @@ -106,13 +192,38 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundoname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = p->timcount; + return OK; +} + +int kdmp4set_S(CSOUND *csound, KDUMP4 *p) +{ + /* open in curdir or pathname */ + char soundoname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + strncpy(soundoname, ((STRINGDAT *)p->ifilcod)->data, 1023); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, + "wb", "", dumpf_format_table[p->format], 0); + if (p->fdch.fd == NULL) + return csound->InitError(csound, Str("Cannot open %s"), soundoname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = p->timcount; return OK; } -int kdmp4set(CSOUND *csound, KDUMP4 *p) +int kdmp4set_p(CSOUND *csound, KDUMP4 *p) { /* open in curdir or pathname */ char soundoname[1024]; @@ -123,7 +234,9 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", p->XSTRCODE); + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundoname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundoname, p->ifilcod, "dumpk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundoname, @@ -131,13 +244,14 @@ if (p->fdch.fd == NULL) return csound->InitError(csound, Str("Cannot open %s"), soundoname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = p->timcount; return OK; } -static void nkdump(CSOUND *csound, MYFLT *kp, FILE *ofd, int format, int nk) +static void nkdump(CSOUND *csound, MYFLT *kp, FILE *ofd, int format, + int nk, void *p) { char buf1[256], outbuf[256]; int len = 0; @@ -183,17 +297,20 @@ break; case 8: *outbuf = '\0'; while (--nk) { - sprintf(buf1, "%6.4f\t", *kp++); + CS_SPRINTF(buf1, "%6.4f\t", *kp++); strncat(outbuf, buf1, 256); } - sprintf(buf1, "%6.4f\n", *kp); + CS_SPRINTF(buf1, "%6.4f\n", *kp); strncat(outbuf, buf1, 256); len = strlen(outbuf); break; - default: csound->Die(csound, Str("unknown kdump format")); + default: + csound->PerfError(csound,((KDUMP *)p)->h.insdshead, + Str("unknown kdump format")); } if (UNLIKELY(fwrite(outbuf, len, 1, ofd)!=1)) { /* now write the buffer */ - csound->PerfError(csound, Str("write failure in dumpk")); + csound->PerfError(csound, ((KDUMP *)p)->h.insdshead, + Str("write failure in dumpk")); } } @@ -204,7 +321,7 @@ if (--p->countdown <= 0) { p->countdown = p->timcount; kval[0] = *p->ksig; - nkdump(csound, kval, p->f, p->format, 1); + nkdump(csound, kval, p->f, p->format, 1, p); } return OK; } @@ -217,7 +334,7 @@ p->countdown = p->timcount; kval[0] = *p->ksig1; kval[1] = *p->ksig2; - nkdump(csound, kval, p->f, p->format, 2); + nkdump(csound, kval, p->f, p->format, 2, p); } return OK; } @@ -231,7 +348,7 @@ kval[0] = *p->ksig1; kval[1] = *p->ksig2; kval[2] = *p->ksig3; - nkdump(csound, kval, p->f, p->format, 3); + nkdump(csound, kval, p->f, p->format, 3, p); } return OK; } @@ -246,7 +363,7 @@ kval[1] = *p->ksig2; kval[2] = *p->ksig3; kval[3] = *p->ksig4; - nkdump(csound, kval, p->f, p->format, 4); + nkdump(csound, kval, p->f, p->format, 4, p); } return OK; } @@ -255,7 +372,7 @@ /* ******** READK and friends; new code 1999 Feb 14 by JPff ******** */ /* ******************************************************************** */ -int krdset(CSOUND *csound, KREAD *p) +int krdset_p(CSOUND *csound, KREAD *p) { /* open in curdir or pathname */ char soundiname[1024]; @@ -266,8 +383,9 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundiname, - p->ifilcod, "readk.", p->XSTRCODE); + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", @@ -275,14 +393,14 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); return OK; } -int krd2set(CSOUND *csound, KREAD2 *p) +int krdset_S(CSOUND *csound, KREAD *p) { /* open in curdir or pathname */ char soundiname[1024]; @@ -293,8 +411,7 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundiname, p->ifilcod, - "readk.", p->XSTRCODE); + strncpy(soundiname, ((STRINGDAT *)p->ifilcod)->data, 1023); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", @@ -302,14 +419,14 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); return OK; } -int krd3set(CSOUND *csound, KREAD3 *p) +int krd2set_S(CSOUND *csound, KREAD2 *p) { /* open in curdir or pathname */ char soundiname[1024]; @@ -320,8 +437,7 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundiname, p->ifilcod, - "readk.", p->XSTRCODE); + strncpy(soundiname, ((STRINGDAT *)p->ifilcod)->data, 1023); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", @@ -329,14 +445,14 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); return OK; } -int krd4set(CSOUND *csound, KREAD4 *p) +int krd2set_p(CSOUND *csound, KREAD2 *p) { /* open in curdir or pathname */ char soundiname[1024]; @@ -347,8 +463,9 @@ return csound->InitError(csound, Str("alaw and ulaw not implemented here")); } - csound->strarg2name(csound, soundiname, p->ifilcod, - "readk.", p->XSTRCODE); + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", @@ -356,13 +473,122 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); return OK; } +int krd3set_S(CSOUND *csound, KREAD3 *p) +{ + /* open in curdir or pathname */ + char soundiname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + strncpy(soundiname, ((STRINGDAT *)p->ifilcod)->data, 1023); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", + "SFDIR;SSDIR", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundiname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = 0; + p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); + return OK; +} + +int krd3set_p(CSOUND *csound, KREAD3 *p) +{ + /* open in curdir or pathname */ + char soundiname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", + "SFDIR;SSDIR", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundiname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = 0; + p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); + return OK; +} + +int krd4set_S(CSOUND *csound, KREAD4 *p) +{ + /* open in curdir or pathname */ + char soundiname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + strncpy(soundiname, ((STRINGDAT *)p->ifilcod)->data, 1023); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", + "SFDIR;SSDIR", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundiname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = 0; + p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); + return OK; +} + +int krd4set_p(CSOUND *csound, KREAD4 *p) +{ + /* open in curdir or pathname */ + char soundiname[1024]; + if (UNLIKELY((p->format = (int)*p->iformat) < 1 || p->format > 8)) { + return csound->InitError(csound, Str("unknown format request")); + } + if (UNLIKELY(p->format == 2 || p->format == 3)) { + return csound->InitError(csound, + Str("alaw and ulaw not implemented here")); + } + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", + "SFDIR;SSDIR", dumpf_format_table[p->format], 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundiname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = 0; + p->k[0] = p->k[1] = p->k[2] = p->k[3] = FL(0.0); + return OK; +} + + static void nkread(CSOUND *csound, MYFLT *kp, FILE *ifd, int format, int nk) { int len; @@ -414,9 +640,9 @@ fseek(ifd, -1L, SEEK_CUR); *bp = '\0'; #ifndef USE_DOUBLE - sscanf(inbuf,"%f", kp); + CS_SSCANF(inbuf,"%f", kp); #else - sscanf(inbuf,"%lf", kp); + CS_SSCANF(inbuf,"%lf", kp); #endif kp++; } @@ -433,14 +659,14 @@ fseek(ifd, -1L, SEEK_CUR); *bp = '\0'; #ifndef USE_DOUBLE - sscanf(inbuf,"%f", kp); + CS_SSCANF(inbuf,"%f", kp); #else - sscanf(inbuf,"%lf", kp); + CS_SSCANF(inbuf,"%lf", kp); #endif kp++; } break; - default: csound->Die(csound, Str("unknown kdump format")); + default: csound->Warning(csound,Str("unknown kdump format")); } } @@ -514,12 +740,13 @@ return OK; } -int krdsset(CSOUND *csound, KREADS *p) +#define INITSIZE 1024 + +int krdsset_S(CSOUND *csound, KREADS *p) { /* open in curdir or pathname */ char soundiname[1024]; - csound->strarg2name(csound, soundiname, - p->ifilcod, "readk.", p->XSTRCODE); + strncpy(soundiname, ((STRINGDAT *)p->ifilcod)->data, 1023); if (p->fdch.fd != NULL) fdclose(csound, &(p->fdch)); p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", @@ -527,22 +754,54 @@ if (UNLIKELY(p->fdch.fd == NULL)) return csound->InitError(csound, Str("Cannot open %s"), soundiname); fdrecord(csound, &p->fdch); - if ((p->timcount = (int32)(*p->iprd * csound->ekr)) <= 0) + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) p->timcount = 1; p->countdown = 0; - p->lasts = (char*)csound->Malloc(csound, 1+csound->strVarMaxLen); + p->lasts = (char*)csound->Calloc(csound, INITSIZE); p->lasts[0] = '\0'; + if(p->str->data == NULL) { + p->str->data = mcalloc(csound, INITSIZE); + p->str->size = INITSIZE; + } return OK; } + +int krdsset_p(CSOUND *csound, KREADS *p) +{ + /* open in curdir or pathname */ + char soundiname[1024]; + if(ISSTRCOD(*p->ifilcod)) + strncpy(soundiname, get_arg_string(csound, *p->ifilcod), 1023); + else csound->strarg2name(csound, soundiname, p->ifilcod, "readk.", 0); + if (p->fdch.fd != NULL) + fdclose(csound, &(p->fdch)); + p->fdch.fd = csound->FileOpen2(csound, &(p->f), CSFILE_STD, soundiname, "rb", + "SFDIR;SSDIR", 0, 0); + if (UNLIKELY(p->fdch.fd == NULL)) + return csound->InitError(csound, Str("Cannot open %s"), soundiname); + fdrecord(csound, &p->fdch); + if ((p->timcount = (int32)(*p->iprd * CS_EKR)) <= 0) + p->timcount = 1; + p->countdown = 0; + p->lasts = (char*)csound->Malloc(csound, INITSIZE); + p->lasts[0] = '\0'; + if(p->str->data == NULL) { + p->str->data = mcalloc(csound, INITSIZE); + p->str->size = INITSIZE; + } + return OK; +} + + int kreads(CSOUND *csound, KREADS *p) { if (--p->countdown <= 0) { p->countdown = p->timcount; - if (UNLIKELY(fgets(p->lasts, csound->strVarMaxLen, p->f)==NULL)) { - csound->PerfError(csound, "Read failure in readks"); + if (UNLIKELY(fgets(p->lasts, INITSIZE-1, p->f)==NULL)) { + csound->PerfError(csound, p->h.insdshead, Str("Read failure in readks")); } } - strncpy((char*) p->str, p->lasts, csound->strVarMaxLen); + strncpy((char*) p->str->data, p->lasts, INITSIZE); return OK; } diff -Nru csound-5.17.11~dfsg/OOps/fftlib.c csound-6.02~dfsg/OOps/fftlib.c --- csound-5.17.11~dfsg/OOps/fftlib.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/fftlib.c 2014-01-07 16:53:47.000000000 +0000 @@ -32,11 +32,6 @@ #include "csound.h" #include "fftlib.h" -#define MYRECIPLN2 1.442695040888963407359924681001892137426 /* 1.0/log(2) */ - -/* some useful conversions between a number and its power of 2 */ - -/* #define LOG2(a) (MYRECIPLN2*log(a)) /* floating point logarithm base 2 */ #define POW2(m) ((uint32) 1 << (m)) /* integer power of 2 for m<32 */ /* fft's with M bigger than this bust primary cache */ @@ -3192,7 +3187,7 @@ case 0x08000000: return 27; case 0x10000000: return 28; } - csoundDie(csound, Str(" *** fftlib.c: internal error: " + csound->Warning(csound, Str(" *** fftlib.c: internal error: " "invalid FFT size: %d"), N); return 0; } @@ -3213,6 +3208,8 @@ MYFLT csoundGetInverseComplexFFTScale(CSOUND *csound, int FFTsize) { + IGN(FFTsize); + IGN(csound); return FL(1.0); } @@ -3223,6 +3220,8 @@ MYFLT csoundGetInverseRealFFTScale(CSOUND *csound, int FFTsize) { + IGN(FFTsize); + IGN(csound); return FL(1.0); } @@ -3317,6 +3316,7 @@ { MYFLT re, im; int i; + IGN(csound); if (scaleFac != FL(1.0)) { outbuf[0] = buf1[0] * buf2[0] * scaleFac; diff -Nru csound-5.17.11~dfsg/OOps/goto_ops.c csound-6.02~dfsg/OOps/goto_ops.c --- csound-5.17.11~dfsg/OOps/goto_ops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/goto_ops.c 2014-01-07 16:54:20.000000000 +0000 @@ -24,7 +24,6 @@ */ #include "csoundCore.h" /* GOTO_OPS.C */ -#include "oload.h" #include "insert.h" /* for goto's */ #include "aops.h" /* for cond's */ extern int32 strarg2insno(CSOUND *, void *p, int is_string); @@ -37,7 +36,8 @@ int kgoto(CSOUND *csound, GOTO *p) { - csound->pds = p->lblblk->prvp; + IGN(csound); + CS_PDS = p->lblblk->prvp; return OK; } @@ -50,8 +50,10 @@ int kcgoto(CSOUND *csound, CGOTO *p) { + IGN(csound); if (*p->cond) - csound->pds = p->lblblk->prvp; + CS_PDS = p->lblblk->prvp; + return OK; } @@ -66,8 +68,9 @@ int kngoto(CSOUND *csound, CGOTO *p) { + IGN(csound); if (!*p->cond) - csound->pds = p->lblblk->prvp; + CS_PDS = p->lblblk->prvp; return OK; } @@ -83,25 +86,27 @@ int kingoto(CSOUND *csound, CGOTO *p) { - csound->pds = p->lblblk->prvp; + IGN(csound); + CS_PDS = p->lblblk->prvp; return OK; } #endif int timset(CSOUND *csound, TIMOUT *p) { - if (UNLIKELY((p->cnt1 = (int32)(*p->idel * csound->ekr + FL(0.5))) < 0L || - (p->cnt2 = (int32)(*p->idur * csound->ekr + FL(0.5))) < 0L)) + if (UNLIKELY((p->cnt1 = (int32)(*p->idel * CS_EKR + FL(0.5))) < 0L || + (p->cnt2 = (int32)(*p->idur * CS_EKR + FL(0.5))) < 0L)) return csoundInitError(csound, Str("negative time period")); return OK; } int timout(CSOUND *csound, TIMOUT *p) { + IGN(csound); if (p->cnt1) /* once delay has expired, */ p->cnt1--; else if (--p->cnt2 >= 0L) /* br during idur countdown */ - csound->pds = p->lblblk->prvp; + CS_PDS = p->lblblk->prvp; return OK; } @@ -114,40 +119,46 @@ int reinit(CSOUND *csound, GOTO *p) { - csound->reinitflag = 1; + csound->reinitflag = p->h.insdshead->reinitflag = 1; csound->curip = p->h.insdshead; csound->ids = p->lblblk->prvi; /* now, despite ANSI C warning: */ + if(csound->realtime_audio_flag == 0) { while ((csound->ids = csound->ids->nxti) != NULL && csound->ids->iopadr != (SUBR) rireturn) (*csound->ids->iopadr)(csound, csound->ids); - csound->reinitflag = 0; + csound->reinitflag = p->h.insdshead->reinitflag = 0; + } else { + csound->curip->init_done = 0; + } return OK; } int rigoto(CSOUND *csound, GOTO *p) { - if (csound->reinitflag) + if (p->h.insdshead->reinitflag) csound->ids = p->lblblk->prvi; return OK; } int tigoto(CSOUND *csound, GOTO *p) /* I-time only, NOP at reinit */ { - if (csound->tieflag && !csound->reinitflag) + if (p->h.insdshead->tieflag && !p->h.insdshead->reinitflag) csound->ids = p->lblblk->prvi; return OK; } int tival(CSOUND *csound, EVAL *p) /* I-time only, NOP at reinit */ { - if (!csound->reinitflag) - *p->r = (csound->tieflag ? FL(1.0) : FL(0.0)); + if (!p->h.insdshead->reinitflag) + *p->r = p->h.insdshead->tieflag; + /* *p->r = (csound->tieflag ? FL(1.0) : FL(0.0)); */ return OK; } int ihold(CSOUND *csound, LINK *p) /* make this note indefinit duration */ { /* called by ihold statmnt at Itime */ - if (!csound->reinitflag) { /* no-op at reinit */ + IGN(csound); + if (!p->h.insdshead->reinitflag) { /* no-op at reinit */ csound->curip->offbet = -1.0; csound->curip->offtim = -1.0; } @@ -156,15 +167,16 @@ int turnoff(CSOUND *csound, LINK *p) /* terminate the current instrument */ { /* called by turnoff statmt at Ptime */ - INSDS *lcurip = csound->pds->insdshead; + IGN(csound); + INSDS *lcurip = CS_PDS->insdshead; /* IV - Oct 16 2002: check for subinstr and user opcode */ /* find top level instrument instance */ while (lcurip->opcod_iobufs) lcurip = ((OPCOD_IOBUFS*) lcurip->opcod_iobufs)->parent_ip; xturnoff(csound, lcurip); if (lcurip->xtratim <= 0) - while (csound->pds->nxtp != NULL) - csound->pds = csound->pds->nxtp; /* loop to last opds */ + while (CS_PDS->nxtp != NULL) + CS_PDS = CS_PDS->nxtp; /* loop to last opds */ return OK; } @@ -176,26 +188,33 @@ int mode, insno, allow_release; if(isStringArg){ - p1 = (MYFLT) strarg2insno(csound, p->kInsNo, (p->XSTRCODE & 1)); - } else p1 = *(p->kInsNo); + p1 = (MYFLT) strarg2insno(csound, ((STRINGDAT *)p->kInsNo)->data, 1); + } + else if(ISSTRCOD(*p->kInsNo)) { + p1 = (MYFLT) strarg2insno(csound, get_arg_string(csound, *p->kInsNo), 1); + } + else p1 = *(p->kInsNo); if (p1 <= FL(0.0)) return OK; /* not triggered */ insno = (int) p1; - if (UNLIKELY(insno < 1 || insno > (int) csound->maxinsno || - csound->instrtxtp[insno] == NULL)) { - return csoundPerfError(csound, Str("turnoff2: invalid instrument number")); + if (UNLIKELY(insno < 1 || insno > (int) csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL)) { + return csoundPerfError(csound, p->h.insdshead, + Str("turnoff2: invalid instrument number")); } mode = (int) (*(p->kFlags) + FL(0.5)); allow_release = (*(p->kRelease) == FL(0.0) ? 0 : 1); if (UNLIKELY(mode < 0 || mode > 15 || (mode & 3) == 3)) { - return csoundPerfError(csound, Str("turnoff2: invalid mode parameter")); + return csoundPerfError(csound, p->h.insdshead, + Str("turnoff2: invalid mode parameter")); } ip = &(csound->actanchor); ip2 = NULL; /* if ((mode & 4) && !ip->p1){ */ -/* return csoundPerfError(csound, Str("turnoff2: invalid instrument number")); */ +/* return csoundPerfError(csound, p->h.insdshead, */ +/* Str("turnoff2: invalid instrument number")); */ /* } */ while ((ip = ip->nxtact) != NULL && (int) ip->insno != insno); if (ip == NULL) @@ -233,8 +252,8 @@ } } if (!p->h.insdshead->actflg) { /* if current note was deactivated: */ - while (csound->pds->nxtp != NULL) - csound->pds = csound->pds->nxtp; /* loop to last opds */ + while (CS_PDS->nxtp != NULL) + CS_PDS = CS_PDS->nxtp; /* loop to last opds */ } return OK; } @@ -286,35 +305,39 @@ int loop_l_p(CSOUND *csound, LOOP_OPS *p) { /* if ((kndxvar += kincr) < klimit) kgoto l */ + IGN(csound); *(p->ndxvar) += *(p->incr); if (*(p->ndxvar) < *(p->limit)) - csound->pds = p->l->prvp; + CS_PDS = p->l->prvp; return OK; } int loop_le_p(CSOUND *csound, LOOP_OPS *p) { /* if ((kndxvar += kincr) <= klimit) kgoto l */ + IGN(csound); *(p->ndxvar) += *(p->incr); if (*(p->ndxvar) <= *(p->limit)) - csound->pds = p->l->prvp; + CS_PDS = p->l->prvp; return OK; } int loop_g_p(CSOUND *csound, LOOP_OPS *p) { /* if ((kndxvar -= kdecr) > klimit) kgoto l */ + IGN(csound); *(p->ndxvar) -= *(p->incr); if (*(p->ndxvar) > *(p->limit)) - csound->pds = p->l->prvp; + CS_PDS = p->l->prvp; return OK; } int loop_ge_p(CSOUND *csound, LOOP_OPS *p) { /* if ((kndxvar -= kdecr) >= klimit) kgoto l */ + IGN(csound); *(p->ndxvar) -= *(p->incr); if (*(p->ndxvar) >= *(p->limit)) - csound->pds = p->l->prvp; + CS_PDS = p->l->prvp; return OK; } diff -Nru csound-5.17.11~dfsg/OOps/midiinterop.c csound-6.02~dfsg/OOps/midiinterop.c --- csound-5.17.11~dfsg/OOps/midiinterop.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/midiinterop.c 2014-01-07 16:53:47.000000000 +0000 @@ -32,6 +32,7 @@ int midinoteoff(CSOUND *csound, MIDINOTEON *p) { + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -42,6 +43,7 @@ int midinoteonkey(CSOUND *csound, MIDINOTEON *p) { + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -67,6 +69,7 @@ int midinoteonoct(CSOUND *csound, MIDINOTEON *p) { MYFLT octave; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -82,6 +85,7 @@ double octave; double integer; double fraction; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -97,6 +101,7 @@ int midipolyaftertouch(CSOUND *csound, MIDIPOLYAFTERTOUCH *p) { MYFLT scale; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -109,6 +114,7 @@ int midicontrolchange(CSOUND *csound, MIDICONTROLCHANGE *p) { MYFLT scale; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -120,6 +126,7 @@ int midiprogramchange(CSOUND *csound, MIDIPROGRAMCHANGE *p) { + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -130,6 +137,7 @@ int midichannelaftertouch(CSOUND *csound, MIDICHANNELAFTERTOUCH *p) { MYFLT scale; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -141,6 +149,7 @@ int midipitchbend(CSOUND *csound, MIDIPITCHBEND *p) { MYFLT scale; + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } @@ -151,6 +160,7 @@ int mididefault(CSOUND *csound, MIDIDEFAULT *p) { + IGN(csound); if (!p->h.insdshead->m_chnbp) { return OK; } diff -Nru csound-5.17.11~dfsg/OOps/midiops.c csound-6.02~dfsg/OOps/midiops.c --- csound-5.17.11~dfsg/OOps/midiops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/midiops.c 2014-01-07 16:53:47.000000000 +0000 @@ -53,17 +53,34 @@ /* IV - Oct 31 2002: modified to allow named instruments */ -int massign(CSOUND *csound, MASSIGN *p) +int massign_p(CSOUND *csound, MASSIGN *p) +{ + int chnl = (int)(*p->chnl + FL(0.5)); + int resetCtls; + int retval = OK; + + resetCtls = (*p->iresetctls == FL(0.0) ? 0 : 1); + if (--chnl >= 0) + retval = m_chinsno(csound, chnl, (int) *p->insno, resetCtls); + else { + for (chnl = 0; chnl < 16; chnl++) { + if (m_chinsno(csound, chnl, (int) *p->insno, resetCtls) != OK) + retval = NOTOK; + } + } + return retval; +} + +int massign_S(CSOUND *csound, MASSIGNS *p) { int chnl = (int)(*p->chnl + FL(0.5)); int32 instno = 0L; int resetCtls; int retval = OK; - if (p->XSTRCODE || *(p->insno) >= FL(0.5)) { - if (UNLIKELY((instno = strarg2insno(csound, p->insno, p->XSTRCODE)) <= 0L)) + if (UNLIKELY((instno = strarg2insno(csound, p->insno->data, 1)) <= 0L)) return NOTOK; - } + resetCtls = (*p->iresetctls == FL(0.0) ? 0 : 1); if (--chnl >= 0) retval = m_chinsno(csound, chnl, (int) instno, resetCtls); @@ -76,6 +93,7 @@ return retval; } + int ctrlinit(CSOUND *csound, CTLINIT *p) { int16 chnl = (int16)(*p->chnl - FL(0.5)); @@ -116,7 +134,7 @@ int basekeymidi; MYFLT basefreq, factor, interval; - if (UNLIKELY((ftp = csound->FTFind(csound, p->tablenum)) == NULL)) { + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->tablenum)) == NULL)) { return csound->InitError(csound, Str("cpstabm: invalid modulator table")); } func = ftp->ftable; @@ -148,6 +166,7 @@ int pchmidi(CSOUND *csound, MIDIKMB *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; double fract, oct, ioct; oct = lcurip->m_pitch / 12.0 + 3.0; @@ -179,6 +198,7 @@ int octmidi(CSOUND *csound, MIDIKMB *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = lcurip->m_pitch / FL(12.0) + FL(3.0); return OK; @@ -186,6 +206,7 @@ int octmidib(CSOUND *csound, MIDIKMB *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = (lcurip->m_pitch + (pitchbend_value(lcurip->m_chnbp) * p->scale)) / FL(12.0) + FL(3.0); @@ -254,7 +275,7 @@ amp = csound->curip->m_veloc / FL(128.0); /* amp = normalised veloc */ if ((fno = (int32)*p->ifn) > 0) { /* if valid ftable, */ - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; /* use amp as index */ amp = *(ftp->ftable + (int32)(amp * ftp->flen)); } @@ -267,7 +288,7 @@ int midibset(CSOUND *csound, MIDIKMB *p) { MCHNBLK *chn; - + IGN(csound); chn = p->h.insdshead->m_chnbp; if (*p->iscal > FL(0.0)) p->scale = *p->iscal; @@ -285,6 +306,7 @@ int aftset(CSOUND *csound, MIDIKMAP *p) { + IGN(csound); p->lo = *p->ilo; p->scale = (*p->ihi - p->lo) * dv127; return OK; @@ -292,6 +314,7 @@ int aftouch(CSOUND *csound, MIDIKMAP *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = p->lo + MIDI_VALUE(lcurip->m_chnbp, aftouch) * p->scale; return OK; @@ -322,6 +345,7 @@ int midictl(CSOUND *csound, MIDICTL *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = MIDI_VALUE(lcurip->m_chnbp, ctl_val[p->ctlno]) * p->scale + p->lo; return OK; @@ -352,6 +376,7 @@ int midiaft(CSOUND *csound, MIDICTL *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = MIDI_VALUE(lcurip->m_chnbp, polyaft[p->ctlno]) * p->scale + p->lo; return OK; @@ -368,7 +393,7 @@ /* pgmassign - assign MIDI program to instrument */ -int pgmassign(CSOUND *csound, PGMASSIGN *p) +int pgmassign_(CSOUND *csound, PGMASSIGN *p, int instname) { int pgm, ins, chn; @@ -376,7 +401,7 @@ if (UNLIKELY(chn < 0 || chn > 16)) return csound->InitError(csound, Str("illegal channel number")); /* IV - Oct 31 2002: allow named instruments */ - if (p->XSTRCODE || *p->inst == SSTRCOD) { + if (instname || ISSTRCOD(*p->inst)) { MYFLT buf[128]; csound->strarg2name(csound, (char*) buf, p->inst, "", 1); ins = (int)strarg2insno(csound, buf, 1); @@ -412,6 +437,14 @@ return OK; } +int pgmassign_S(CSOUND *csound, PGMASSIGN *p){ + return pgmassign_(csound,p,1); +} + +int pgmassign(CSOUND *csound, PGMASSIGN *p){ + return pgmassign_(csound,p,0); +} + int ichanctl(CSOUND *csound, CHANCTL *p) { int32 ctlno, chan = (int32)(*p->ichano - FL(1.0)); @@ -450,6 +483,7 @@ int ipchbend(CSOUND *csound, MIDIMAP *p) { + IGN(csound); *p->r = *p->ilo + (*p->ihi - *p->ilo) * pitchbend_value(p->h.insdshead->m_chnbp); return OK; @@ -457,6 +491,7 @@ int kbndset(CSOUND *csound, MIDIKMAP *p) { + IGN(csound); p->lo = *p->ilo; p->scale = *p->ihi - *p->ilo; return OK; @@ -464,6 +499,7 @@ int kpchbend(CSOUND *csound, MIDIKMAP *p) { + IGN(csound); INSDS *lcurip = p->h.insdshead; *p->r = p->lo + pitchbend_value(lcurip->m_chnbp) * p->scale; return OK; diff -Nru csound-5.17.11~dfsg/OOps/midiout.c csound-6.02~dfsg/OOps/midiout.c --- csound-5.17.11~dfsg/OOps/midiout.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/midiout.c 2014-01-07 16:54:20.000000000 +0000 @@ -49,6 +49,7 @@ int release_set(CSOUND *csound, REL *p) { + IGN(csound); if (p->h.insdshead->xtratim < EXTRA_TIME) /* if not initialised by another opcode */ p->h.insdshead->xtratim = EXTRA_TIME; @@ -57,6 +58,7 @@ int release(CSOUND *csound, REL *p) { + IGN(csound); if (p->h.insdshead->relesing) *p->r = FL(1.0); /* TRUE */ else @@ -67,7 +69,7 @@ int xtratim(CSOUND *csound, XTRADUR *p) { int *xtra = &(p->h.insdshead->xtratim); - int tim = (int)(*p->extradur * csound->ekr); + int tim = (int)(*p->extradur * p->h.insdshead->ekr); if (*xtra < tim) /* gab-a5 revised */ *xtra = tim; return OK; @@ -75,7 +77,7 @@ int mclock_set(CSOUND *csound, MCLOCK *p) { - p->period= csound->ekr / *p->freq; + p->period= CS_EKR / *p->freq; p->clock_tics = p->period; p->beginning_flag = TRUE; return OK; @@ -88,7 +90,7 @@ p->beginning_flag=FALSE; return OK; } - else if ((MYFLT) csound->kcounter > p->clock_tics) { + else if ((MYFLT) CS_KCNT > p->clock_tics) { send_midi_message(csound, 0xF8, 0, 0); /* clock message */ p->clock_tics += p->period; } @@ -143,7 +145,7 @@ p->vel = (temp = abs((int)*p->ivel)) < 128 ? temp : 127; note_on(csound, p->chn,p->num, p->vel); - p->istart_time = (MYFLT)csound->kcounter * csound->onedkr; + p->istart_time = (MYFLT)CS_KCNT * CS_ONEDKR; p->fl_expired = FALSE; p->fl_extra_dur = FALSE; return OK; @@ -152,7 +154,7 @@ int iout_on_dur(CSOUND *csound, OUT_ON_DUR *p) { if (!(p->fl_expired)) { - MYFLT actual_dur = (MYFLT) csound->kcounter * csound->onedkr + MYFLT actual_dur = (MYFLT) CS_KCNT * CS_ONEDKR - p->istart_time; MYFLT dur = *p->idur; if (dur < actual_dur) { @@ -170,7 +172,7 @@ int iout_on_dur2(CSOUND *csound, OUT_ON_DUR *p) { if (!(p->fl_expired)) { - MYFLT actual_dur = (MYFLT)csound->kcounter * csound->onedkr + MYFLT actual_dur = (MYFLT)CS_KCNT * CS_ONEDKR - p->istart_time; MYFLT dur = *p->idur; if (dur < actual_dur) { @@ -198,7 +200,7 @@ if (p->h.insdshead->xtratim < EXTRA_TIME) /* if not initialised by another opcode */ p->h.insdshead->xtratim = EXTRA_TIME; - p->istart_time = (MYFLT)csound->kcounter * csound->onedkr; + p->istart_time = (MYFLT)CS_KCNT * CS_ONEDKR; p->fl_first_note = TRUE; p->fl_note_expired = TRUE; p->fl_end_note = FALSE; @@ -217,7 +219,7 @@ p->fl_end_note = TRUE; note_off(csound, p->last_chn, p->last_num, p->last_vel); } - else if (p->last_dur < (MYFLT)csound->kcounter * csound->onedkr + else if (p->last_dur < (MYFLT)CS_KCNT * CS_ONEDKR - p->istart_time) { p->fl_note_expired = TRUE; note_off(csound, p->last_chn, p->last_num, p->last_vel); @@ -226,13 +228,13 @@ else { if (!p->fl_end_note && p->last_pause + p->last_dur < - (MYFLT)csound->kcounter * csound->onedkr - p->istart_time + (MYFLT)CS_KCNT * CS_ONEDKR - p->istart_time && !(p->h.insdshead->relesing)) { MYFLT ftemp; p->istart_time = p->istart_time + p->last_pause + p->last_dur; p->last_dur = /* dur must be at least 1/kr */ - (ftemp = *p->kdur) > 0 ? ftemp : csound->onedkr; - p->last_pause = (ftemp = *p->kpause) > 0 ? ftemp : csound->onedkr; + (ftemp = *p->kdur) > 0 ? ftemp : CS_ONEDKR; + p->last_pause = (ftemp = *p->kpause) > 0 ? ftemp : CS_ONEDKR; first_note: { int temp; @@ -250,6 +252,7 @@ int kvar_out_on_set(CSOUND *csound, KOUT_ON *p) { + IGN(csound); if (p->h.insdshead->xtratim < EXTRA_TIME) /* if not initialised by another opcode */ p->h.insdshead->xtratim = EXTRA_TIME; @@ -308,7 +311,9 @@ value = (int)((*p->value - min) * FL(127.0) / (*p->max - min)); value = (value < 128) ? value : 127; value = (value > -1) ? value : 0; - if (value != p->last_value || *p->chn != p->lastchn || *p->num != p->lastctrl) { + if (value != p->last_value || + *p->chn != p->lastchn || + *p->num != p->lastctrl) { /* csound->Message(csound, "out contr value: %d\n", value); */ control_change(csound, (int)*p->chn-1,(int)*p->num ,value); p->last_value = value; @@ -344,7 +349,9 @@ value = (int)((*p->value - min) * FL(127.0) / (*p->max - min)); value = value < 128 ? value : 127; value = value > -1 ? value : 0; - if (value != p->last_value || *p->chn != p->lastchn || *p->num != p->lastctrl) { + if (value != p->last_value || + *p->chn != p->lastchn || + *p->num != p->lastctrl) { poly_after_touch(csound, (int)*p->chn-1, (int)*p->num, value); p->last_value = value; p->lastchn = *p->chn; @@ -383,7 +390,9 @@ value = (value < 16384) ? value : 16383; value = (value > -1) ? value : 0; - if (value != p->last_value || *p->chn != p->lastchn || *p->msb_num != p->lastctrl) { + if (value != p->last_value || + *p->chn != p->lastchn || + *p->msb_num != p->lastctrl) { unsigned int msb = value >> 7; unsigned int lsb = value & 0x7F; csound->Warning(csound, Str("out contr14 msb:%x lsb:%x\n"), msb, lsb); @@ -423,6 +432,7 @@ int kon2_set(CSOUND *csound, KON2 *p) { + IGN(csound); /* if not initialised by another opcode */ if (p->h.insdshead->xtratim < EXTRA_TIME) p->h.insdshead->xtratim = EXTRA_TIME; @@ -519,6 +529,7 @@ int mdelay_set(CSOUND *csound, MDELAY *p) { + IGN(csound); p->read_index = 0; p->write_index = 0; memset(p->status, 0, DELTAB_LENGTH); @@ -529,7 +540,7 @@ { int read_index = p->read_index % DELTAB_LENGTH; int write_index = p->write_index % DELTAB_LENGTH; - MYFLT present_time = csound->kcounter * csound->onedkr; + MYFLT present_time = CS_KCNT * CS_ONEDKR; if (((int)*p->in_status == 0x90 || (int)*p->in_status == 0x80)) { p->status[write_index] = (int)*p->in_status; diff -Nru csound-5.17.11~dfsg/OOps/mxfft.c csound-6.02~dfsg/OOps/mxfft.c --- csound-5.17.11~dfsg/OOps/mxfft.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/mxfft.c 2014-01-07 16:53:47.000000000 +0000 @@ -168,8 +168,9 @@ if (m <= kt+1) maxp = m + kt + 1; if (UNLIKELY(m+kt > 15)) { - csound->Die(csound, Str("\nerror - fft parameter n has " + csound->Warning(csound, Str("\nerror - fft parameter n has " "more than 15 factors : %d"), n); + return; } if (kt!=0) { j = kt; @@ -932,8 +933,10 @@ buf[FFTsize] = buf[1]; } else { - if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))) - csoundDie(csound, Str("csoundRealFFTnp2(): invalid FFT size")); + if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))) { + csound->Warning(csound, Str("csoundRealFFTnp2(): invalid FFT size")); + return; + } buf[FFTsize] = buf[FFTsize + 1] = FL(0.0); fft_(csound, buf, &(buf[1]), 1, (FFTsize >> 1), 1, -2); reals_(csound, buf, &(buf[1]), (FFTsize >> 1), -2); @@ -953,11 +956,30 @@ */ void csoundInverseRealFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize) { - if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))) - csoundDie(csound, Str("csoundInverseRealFFTnp2(): invalid FFT size")); + if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))){ + csound->Warning(csound, Str("csoundInverseRealFFTnp2(): invalid FFT size")); + return; + } buf[1] = buf[FFTsize + 1] = FL(0.0); reals_(csound, buf, &(buf[1]), (FFTsize >> 1), 2); fft_(csound, buf, &(buf[1]), 1, (FFTsize >> 1), 1, 2); buf[FFTsize] = buf[FFTsize + 1] = FL(0.0); } +void csoundInverseComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize) +{ + if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))){ + csound->Warning(csound, Str("csoundInverseRealFFTnp2(): invalid FFT size")); + return; + } + fft_(csound, buf, buf, 1, FFTsize, 1, 2); +} + +void csoundComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize) +{ + if (UNLIKELY(FFTsize < 2 || (FFTsize & 1))) { + csound->Warning(csound, Str("csoundRealFFTnp2(): invalid FFT size")); + return; + } + fft_(csound, buf, buf, 1, FFTsize, 1, -2); +} diff -Nru csound-5.17.11~dfsg/OOps/oscils.c csound-6.02~dfsg/OOps/oscils.c --- csound-5.17.11~dfsg/OOps/oscils.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/oscils.c 2014-01-07 16:53:47.000000000 +0000 @@ -69,7 +69,7 @@ int iflg; iflg = (int) (*(p->iflg) + FL(0.5)) & 0x07; /* check flags */ - if (iflg & 1) return OK; /* skip init, nothing to do */ + if (UNLIKELY(iflg & 1)) return OK; /* skip init, nothing to do */ p->use_double = (iflg & 2 ? 1 : 0); /* use doubles internally */ init_sine_gen((double)*(p->iamp), (double)(*(p->icps) * csound->tpidsr), (double)(*(p->iphs) * TWOPI_F), @@ -86,16 +86,23 @@ int oscils(CSOUND *csound, OSCILS *p) { - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, x, c, v; double xd, cd, vd; /* copy object data to local variables */ ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->use_double) { /* use doubles */ xd = p->xd; cd = p->cd; vd = p->vd; - for (n=0; nx; c = p->c; v = p->v; - for (n=0; nistor) != FL(0.0)) return OK; /* nothing to do */ + IGN(csound); + if (UNLIKELY(*(p->istor) != FL(0.0))) return OK; /* nothing to do */ p->phs = (double)*(p->istrt); /* start phase */ p->lps = (double)*(p->ilps); /* loop start */ p->lpe = (double)*(p->ilpe); /* loop end */ - p->loop_mode = (int) (*(p->imode) + FL(0.5)) & 0x03; /* loop mode */ - if (p->lpe <= p->lps) p->loop_mode = 0; /* disable loop */ - p->dir = 1; /* direction */ + p->loop_mode = (int) (*(p->imode) + FL(0.5)) & 0x03; /* loop mode */ + if (p->lpe <= p->lps) p->loop_mode = 0; /* disable loop */ + p->dir = 1; /* direction */ return OK; } @@ -133,7 +141,10 @@ int lphasor(CSOUND *csound, LPHASOR *p) { - int n, nsmps=csound->ksmps, loop_mode, dir; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int loop_mode, dir; MYFLT *ar, *xtrns; double trns, phs, lps, lpe, lpt; @@ -144,8 +155,13 @@ loop_mode = p->loop_mode; trns = (double)*xtrns; - for (n=0; ndir ? trns : -trns); if (loop_mode) { @@ -175,8 +191,9 @@ int tablexkt_set(CSOUND *csound, TABLEXKT *p) { + IGN(csound); p->wsize = (int)(*(p->iwsize) + 0.5); /* window size */ - if (p->wsize < 3) { + if (UNLIKELY(p->wsize < 3)) { p->wsize = 2; } else { @@ -199,7 +216,10 @@ int tablexkt(CSOUND *csound, TABLEXKT *p) { - int i, n, nsmps=csound->ksmps, wsize, wsized2, wrap_ndx, warp; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int i, wsize, wsized2, wrap_ndx, warp; double ndx, d, x, c, v, flen_d, onedpi_d, pidwarp_d; int32 ndx_i, flen; MYFLT *ar, *xndx, ndx_f, a0, a1, a2, a3, v0, v1, v2, v3, *ftable; @@ -209,7 +229,8 @@ /* window size */ wsize = p->wsize; if (UNLIKELY((wsize < 2) || (wsize > 1024))) { - return csound->PerfError(csound, Str("tablexkt: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tablexkt: not initialised")); } wsized2 = wsize >> 1; @@ -224,7 +245,7 @@ ar = p->ar; xndx = p->xndx; wrap_ndx = p->wrap_ndx; - if ((wsize > 4) && (*(p->kwarp) > FL(1.001))) { + if ((wsize > 4) && UNLIKELY((*(p->kwarp) > FL(1.001)))) { warp = 1; /* enable warp */ onedwarp = FL(1.0) / *(p->kwarp); pidwarp_d = PI / (double)*(p->kwarp); @@ -239,7 +260,12 @@ } onedpi_d = 1.0 / PI; - for (n=0; n= flen) { + else if (UNLIKELY(ndx_i >= flen)) { ndx_i = flen; ndx_f = FL(0.0); } } @@ -383,4 +409,3 @@ } return OK; } - diff -Nru csound-5.17.11~dfsg/OOps/pstream.c csound-6.02~dfsg/OOps/pstream.c --- csound-5.17.11~dfsg/OOps/pstream.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/pstream.c 2014-01-07 16:53:47.000000000 +0000 @@ -29,7 +29,6 @@ #include "csoundCore.h" #include "pstream.h" #include "pvfileio.h" -#include "oload.h" #ifdef _DEBUG #include @@ -52,12 +51,38 @@ /* Pandora's box opcode, but we can make it at least plausible, by forbidding copy to different format. */ +int fassign_set(CSOUND *csound, FASSIGN *p) +{ + int32 N = p->fsrc->N; + + p->fout->N = N; + p->fout->overlap = p->fsrc->overlap; + p->fout->winsize = p->fsrc->winsize; + p->fout->wintype =p->fsrc->wintype; + p->fout->format = p->fout->format; + p->fout->sliding = p->fsrc->sliding; + /* sliding needs to be checked */ + if (p->fsrc->sliding) { + p->fout->NB = p->fsrc->NB; + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + &p->fout->frame); + return OK; + } + csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); + p->fout->framecount = 1; + //csound->Message(csound, Str("fsig = : init\n")); + return OK; +} + + int fassign(CSOUND *csound, FASSIGN *p) { int32 framesize; float *fout,*fsrc; - if (UNLIKELY(!fsigs_equal(p->fout,p->fsrc))) - csound->Die(csound, Str("fsig = : formats are different.\n")); + + // if (UNLIKELY(!fsigs_equal(p->fout,p->fsrc))) + //return csound->PerfError(csound,p->h.insdshead, + // Str("fsig = : formats are different.\n")); if (p->fsrc->sliding) { memcpy(p->fout->frame.auxp, p->fsrc->frame.auxp, sizeof(MYFLT)*(p->fsrc->N+2)*csound->ksmps); @@ -67,8 +92,12 @@ fsrc = (float *) p->fsrc->frame.auxp; framesize = p->fsrc->N + 2; - if (p->fout->framecount == p->fsrc->framecount) /* avoid duplicate copying*/ - memcpy(fout, fsrc, framesize*sizeof(float)); + + if (p->fout->framecount == p->fsrc->framecount) {/* avoid duplicate copying*/ + memcpy(fout, fsrc, framesize*sizeof(float)); + p->fout->framecount++; + } + return OK; } @@ -79,27 +108,29 @@ /* get params from input fsig */ /* we trust they are legit! */ int i; - int32 N = p->fsig->N; + PVSDAT *fs = p->fsig; + int32 N = fs->N; int32 noscs,n_oscs; int32 startbin,binoffset; MYFLT *p_x; - if (UNLIKELY(p->fsig->sliding)) - csound->InitError(csound, Str("Sliding version not yet available")); - p->overlap = p->fsig->overlap; + if (UNLIKELY(fs->sliding)) + return csound->InitError(csound, Str("Sliding version not yet available")); + p->overlap = fs->overlap; /* a moot question, whether window params are relevant for adsyn?*/ /* but for now, we validate all params in fsig */ - p->winsize = p->fsig->winsize; - p->wintype = p->fsig->wintype; + p->winsize = fs->winsize; + p->wintype = fs->wintype; p->fftsize = N; noscs = N/2 + 1; /* max possible */ n_oscs = (int32) *p->n_oscs; /* user param*/ if (UNLIKELY(n_oscs <=0)) - csound->Die(csound, Str("pvadsyn: bad value for inoscs\n")); + csound->InitError(csound, Str("pvadsyn: bad value for inoscs\n")); /* remove this when I know how to do it... */ - if (UNLIKELY(p->fsig->format != PVS_AMP_FREQ)) - csound->Die(csound, Str("pvadsyn: format must be amp-freq (0).\n")); - p->format = p->fsig->format; + if (UNLIKELY(fs->format != PVS_AMP_FREQ)) + return csound->InitError(csound, + Str("pvadsyn: format must be amp-freq (0).\n")); + p->format = fs->format; /* interesting question: could noscs be krate variable? * answer: yes, but adds complexity to oscbank, as have to set/reset each osc when started and stopped */ @@ -108,13 +139,15 @@ startbin = (int32) *p->ibin; /* default 0 */ binoffset = (int32) *p->ibinoffset; /* default 1 */ if (UNLIKELY(startbin < 0 || startbin > noscs)) - csound->Die(csound, Str("pvsadsyn: ibin parameter out of range.\n")); + return csound->InitError(csound, + Str("pvsadsyn: ibin parameter out of range.\n")); if (UNLIKELY(startbin + n_oscs > noscs)) - csound->Die(csound, Str("pvsadsyn: ibin + inoscs too large.\n")); + return csound->InitError(csound, + Str("pvsadsyn: ibin + inoscs too large.\n")); /* calc final max bin target */ p->maxosc = startbin + (n_oscs * binoffset); if (UNLIKELY(p->maxosc > noscs)) - csound->Die(csound, Str("pvsadsyn: " + return csound->InitError(csound, Str("pvsadsyn: " "ibin + (inoscs * ibinoffset) too large.")); p->outptr = 0; @@ -170,8 +203,8 @@ amps = (MYFLT *) p->amps.auxp; freqs = (MYFLT *) p->freqs.auxp; lastamps = (MYFLT *) p->lastamps.auxp; - startbin = (int32) *p->ibin; - binoffset = (int32) *p->ibinoffset; + startbin = (int32) *p->ibin; + binoffset = (int32) *p->ibinoffset; lastbin = p->maxosc; /*update amps, freqs*/ @@ -217,14 +250,22 @@ int pvadsyn(CSOUND *csound, PVADS *p) { - int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; MYFLT *aout = p->aout; if (UNLIKELY(p->outbuf.auxp==NULL)) { - csound->Die(csound, Str("pvsynth: Not initialised.\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsynth: Not initialised.\n")); } - for (i=0;i < csound->ksmps;i++) + if (UNLIKELY(offset)) memset(aout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&aout[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset;i < nsmps;i++) aout[i] = adsyn_tick(csound, p); return OK; } @@ -233,34 +274,36 @@ int pvscrosset(CSOUND *csound, PVSCROSS *p) { - int32 N = p->fsrc->N; + PVSDAT *fsrc = p->fsrc; + PVSDAT *fout = p->fout; + int32 N = fsrc->N; /* source fsig */ - p->overlap = p->fsrc->overlap; - p->winsize = p->fsrc->winsize; - p->wintype = p->fsrc->wintype; + p->overlap = fsrc->overlap; + p->winsize = fsrc->winsize; + p->wintype = fsrc->wintype; p->fftsize = N; - p->format = p->fsrc->format; + p->format = fsrc->format; /* make sure fdest is same format */ - if (UNLIKELY(!fsigs_equal(p->fsrc,p->fdest))) - csound->Die(csound, Str("pvscross: source and dest signals " + if (UNLIKELY(!fsigs_equal(fsrc,p->fdest))) + return csound->InitError(csound, Str("pvscross: source and dest signals " "must have same format\n")); - p->fout->N = N; - p->fout->overlap = p->overlap; - p->fout->winsize = p->winsize; - p->fout->wintype = p->wintype; - p->fout->format = p->format; - p->fout->format = p->fsrc->sliding; - if (p->fsrc->sliding) { - p->fout->NB = p->fsrc->NB; - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, - &p->fout->frame); + fout->N = N; + fout->overlap = p->overlap; + fout->winsize = p->winsize; + fout->wintype = p->wintype; + fout->format = p->format; + // fout->format = p->fsrc->sliding; + if (fsrc->sliding) { + fout->NB = fsrc->NB; + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, + &fout->frame); return OK; } /* setup output signal */ /* RWD MUST be 32bit */ - csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); - p->fout->framecount = 1; + csound->AuxAlloc(csound, (N + 2) * sizeof(float), &fout->frame); + fout->framecount = 1; p->lastframe = 0; return OK; } @@ -275,18 +318,24 @@ float *fout = (float *) p->fout->frame.auxp; if (UNLIKELY(fout==NULL)) - csound->Die(csound, Str("pvscross: not initialised\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvscross: not initialised\n")); /* make sure sigs have same format as output */ if (UNLIKELY(!fsigs_equal(p->fout,p->fsrc))) - csound->Die(csound, Str("pvscross: mismatch in fsrc format\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvscross: mismatch in fsrc format\n")); if (UNLIKELY(!fsigs_equal(p->fout,p->fdest))) - csound->Die(csound, Str("pvscross: mismatch in fdest format\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvscross: mismatch in fdest format\n")); if (p->fsrc->sliding) { CMPLX *fout, *fsrc, *fdest; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fsrc->NB; - for (n=0; nfsrc->frame.auxp +n*NB; /* RWD all must be 32bit */ fdest = (CMPLX *) p->fdest->frame.auxp +n*NB; fout = (CMPLX *) p->fout->frame.auxp +n*NB; @@ -315,13 +364,17 @@ /******** PVSFREAD ************/ -int pvsfreadset(CSOUND *csound, PVSFREAD *p) +static int pvsfreadset_(CSOUND *csound, PVSFREAD *p, int stringname) { PVOCEX_MEMFILE pp; uint32 N; char pvfilnam[MAXNAME]; - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if(stringname) strncpy(pvfilnam, ((STRINGDAT*)p->ifilno)->data, MAXNAME-1); + else if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam, get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", 0); + if (UNLIKELY(PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) { return csound->InitError(csound, Str("Failed to load PVOC-EX file")); } @@ -336,23 +389,24 @@ p->arate = csound->esr / (MYFLT) pp.overlap; p->membase = (float*) pp.data; - if (UNLIKELY(p->overlap < csound->ksmps || p->overlap < 10)) + if (UNLIKELY(p->overlap < (int)CS_KSMPS || p->overlap < 10)) csound->InitError(csound, Str("Sliding version not yet available")); if (UNLIKELY(p->nframes <= 0)) - csound->Die(csound, Str("pvsfread: file is empty!\n")); + return csound->InitError(csound, Str("pvsfread: file is empty!\n")); /* special case if only one frame - it is an impulse response */ if (UNLIKELY(p->nframes == 1)) - csound->Die(csound, Str("pvsfread: file has only one frame " + return csound->InitError(csound, Str("pvsfread: file has only one frame " "(= impulse response).\n")); - if (UNLIKELY(p->overlap < csound->ksmps)) - csound->Die(csound, Str("pvsfread: analysis frame overlap " + if (UNLIKELY(p->overlap < (int)CS_KSMPS)) + return csound->InitError(csound, Str("pvsfread: analysis frame overlap " "must be >= ksmps\n")); p->blockalign = (p->fftsize+2) * p->chans; if (UNLIKELY((*p->ichan) >= p->chans)) - csound->Die(csound, Str("pvsfread: ichan value exceeds " + return csound->InitError(csound, Str("pvsfread: ichan value exceeds " "file channel count.\n")); if (UNLIKELY((int32) (*p->ichan) < 0)) - csound->Die(csound, Str("pvsfread: ichan cannot be negative.\n")); + return csound->InitError(csound, + Str("pvsfread: ichan cannot be negative.\n")); N = p->fftsize; /* setup output signal */ @@ -375,18 +429,29 @@ return OK; } + +int pvsfreadset(CSOUND *csound, PVSFREAD *p){ + return pvsfreadset_(csound,p, 0); + } + +int pvsfreadset_S(CSOUND *csound, PVSFREAD *p){ + return pvsfreadset_(csound,p, 1); + } + + int pvsfread(CSOUND *csound, PVSFREAD *p) { int i,j; MYFLT pos = *p->kpos; MYFLT framepos,frac; - int32 frame1pos,frame2pos,framesize,n_mcframes; + int32 frame1pos,/*frame2pos,*/framesize,n_mcframes; float *pmem,*pframe1,*pframe2; /* RWD all MUST be 32bit */ float *fout = (float *) p->fout->frame.auxp; if (UNLIKELY(fout==NULL)) - csound->Die(csound, Str("pvsfread: not initialised.\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsfread: not initialised.\n")); pmem = (float *) p->membase; framesize = p->fftsize+2; @@ -409,7 +474,7 @@ /* gotta interpolate */ /* any optimizations possible here ? Avoid v samll frac values ? higher-order interp ? */ - frame2pos = frame1pos+p->chans; + //frame2pos = frame1pos+p->chans; frac = framepos - (MYFLT) frame1pos; pframe1 = pmem + (frame1pos * p->blockalign) + p->chanoffset; pframe2 = pframe1 + p->blockalign; @@ -426,7 +491,7 @@ p->fout->framecount++; p->lastframe = p->fout->framecount; } - p->ptr += csound->ksmps; + p->ptr += CS_KSMPS; return OK; } @@ -434,10 +499,10 @@ /************* PVSMASKA ****************/ int pvsmaskaset(CSOUND *csound, PVSMASKA *p) { - int i; + unsigned int i; MYFLT *ftable; - int32 N = p->fsrc->N; - int32 nbins = N/2 + 1; + uint32_t N = p->fsrc->N; + uint32_t nbins = N/2 + 1; /* source fsig */ p->overlap = p->fsrc->overlap; p->winsize = p->fsrc->winsize; @@ -445,7 +510,7 @@ p->format = p->fsrc->format; p->fftsize = N; if (UNLIKELY(!(p->format==PVS_AMP_FREQ) || (p->format==PVS_AMP_PHASE))) - csound->Die(csound, Str("pvsmaska: " + return csound->InitError(csound, Str("pvsmaska: " "signal format must be amp-phase or amp-freq.")); /* setup output signal */ p->fout->N = N; @@ -455,7 +520,7 @@ p->fout->format = p->format; p->fout->sliding = p->fsrc->sliding; if (p->fsrc->sliding) { - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); p->fout->NB = p->fsrc->NB; } @@ -466,13 +531,13 @@ p->fout->framecount = 1; p->lastframe = 0; } - p->maskfunc = csound->FTFind(csound, p->ifn); + p->maskfunc = csound->FTnp2Find(csound, p->ifn); if (UNLIKELY(p->maskfunc==NULL)) return NOTOK; /* require at least size of nbins */ if (UNLIKELY(p->maskfunc->flen + 1 < nbins)) - csound->Die(csound, Str("pvsmaska: ftable too small.\n")); + return csound->InitError(csound, Str("pvsmaska: ftable too small.\n")); /* clip any negative values in table */ ftable = p->maskfunc->ftable; @@ -486,18 +551,19 @@ int pvsmaska(CSOUND *csound, PVSMASKA *p) { int i; - int32 flen, nbins; + int32 /*flen, */nbins; MYFLT *ftable; float *fout,*fsrc; /* RWD MUST be 32bit */ float margin, depth = (float)*p->kdepth; - flen = p->maskfunc->flen + 1; + //flen = p->maskfunc->flen + 1; ftable = p->maskfunc->ftable; fout = (float *) p->fout->frame.auxp; /* RWD both MUST be 32bit */ fsrc = (float *) p->fsrc->frame.auxp; if (UNLIKELY(fout==NULL)) - csound->Die(csound, Str("pvsmaska: not initialised\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsmaska: not initialised\n")); if (depth < FL(0.0)) { /* need the warning: but krate linseg can give below-zeroes incorrectly */ @@ -526,9 +592,12 @@ if (p->fsrc->sliding) { int NB = p->fsrc->NB; CMPLX *fout, *fsrc; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = FL(1.0); - for (n=0; nfout->frame.auxp +n*NB; fsrc = (CMPLX *) p->fsrc->frame.auxp +n*NB; for (i=0; ilastframe = 0; if (UNLIKELY(!(p->format==PVS_AMP_FREQ) || (p->format==PVS_AMP_PHASE))) - csound->Die(csound, Str("pvsftw: signal format must be " + return csound->InitError(csound, Str("pvsftw: signal format must be " "amp-phase or amp-freq.\n")); if (UNLIKELY(*p->ifna < 1.0f)) - csound->Die(csound, Str("pvsftw: bad value for ifna.\n")); + return csound->InitError(csound, Str("pvsftw: bad value for ifna.\n")); if (UNLIKELY(*p->ifnf < 0.0f)) /* 0 = notused */ - csound->Die(csound, Str("pvsftw: bad value for ifnf.\n")); - p->outfna = csound->FTFind(csound, p->ifna); + return csound->InitError(csound, Str("pvsftw: bad value for ifnf.\n")); + p->outfna = csound->FTnp2Find(csound, p->ifna); if (UNLIKELY(p->outfna==NULL)) return NOTOK; if (UNLIKELY(p->fsrc->sliding)) @@ -593,7 +662,7 @@ flena = p->outfna->flen + 1; if (UNLIKELY(flena < nbins)) - csound->Die(csound, Str("pvsftw: amps ftable too small.\n")); + return csound->InitError(csound, Str("pvsftw: amps ftable too small.\n")); /* init tables */ ftablea = p->outfna->ftable; @@ -602,14 +671,15 @@ /* freq table? */ if ((int32) *p->ifnf >= 1) { - p->outfnf = csound->FTFind(csound, p->ifnf); + p->outfnf = csound->FTnp2Find(csound, p->ifnf); if (UNLIKELY(p->outfnf==NULL)) return NOTOK; ftablef = p->outfnf->ftable; if (ftablef) { flenf = p->outfnf->flen+1; if (UNLIKELY(flenf < nbins)) - csound->Die(csound, Str("pvsftw: freqs ftable too small.\n")); + return csound->InitError(csound, + Str("pvsftw: freqs ftable too small.\n")); for (i=0;i < nbins;i++) ftablef[i] = fsrc[(i*2) + 1]; } @@ -629,13 +699,16 @@ fsrc = (float *) p->fsrc->frame.auxp; if (UNLIKELY(fsrc==NULL)) - csound->Die(csound, Str("pvsftw: not initialised\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsftw: not initialised\n")); if (UNLIKELY(ftablea==NULL)) - csound->Die(csound, Str("pvsftw: no amps ftable!\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsftw: no amps ftable!\n")); if (p->outfnf) { ftablef = p->outfnf->ftable; if (UNLIKELY(ftablef==NULL)) - csound->Die(csound, Str("pvsftw: no freqs ftable!\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsftw: no freqs ftable!\n")); } nbins = p->fftsize/2 + 1; @@ -677,27 +750,27 @@ nbins = p->fftsize/2 + 1; if (UNLIKELY(!(p->format==PVS_AMP_FREQ) || (p->format==PVS_AMP_PHASE))) - csound->Die(csound, Str("pvsftr: signal format must be " + return csound->InitError(csound, Str("pvsftr: signal format must be " "amp-phase or amp-freq.\n")); /* ifn = 0 = notused */ if (UNLIKELY(*p->ifna < FL(0.0))) - csound->Die(csound, Str("pvsftr: bad value for ifna.\n")); + return csound->InitError(csound, Str("pvsftr: bad value for ifna.\n")); if (UNLIKELY(*p->ifnf < FL(0.0))) - csound->Die(csound, Str("pvsftr: bad value for ifnf.\n")); + return csound->InitError(csound, Str("pvsftr: bad value for ifnf.\n")); /* if ifna=0; no amps to read; one assumes the user ias changing freqs only, otherwise, there is no change! */ if ((int32) *p->ifna != 0) { - p->infna = csound->FTFind(csound, p->ifna); + p->infna = csound->FTnp2Find(csound, p->ifna); if (UNLIKELY(p->infna==NULL)) return NOTOK; p->ftablea = p->infna->ftable; flena = p->infna->flen + 1; if (UNLIKELY(flena < nbins)) - csound->Die(csound, Str("pvsftr: amps ftable too small.\n")); + return csound->InitError(csound, Str("pvsftr: amps ftable too small.\n")); } - if (UNLIKELY(p->overlap < csound->ksmps || p->overlap < 10)) + if (UNLIKELY(p->overlap < (int)CS_KSMPS || p->overlap < 10)) csound->InitError(csound, Str("Sliding version not yet available")); fdest = (float *) p->fdest->frame.auxp; /* RWD MUST be 32bit */ @@ -708,13 +781,13 @@ /* freq table? */ if ((int32) *p->ifnf >= 1) { - p->infnf = csound->FTFind(csound, p->ifnf); + p->infnf = csound->FTnp2Find(csound, p->ifnf); if (UNLIKELY(p->infnf==NULL)) return NOTOK; p->ftablef = p->infnf->ftable; flenf = p->infnf->flen+1; if (UNLIKELY(flenf < nbins)) - csound->Die(csound, Str("pvsftr: freqs ftable too small.\n")); + return csound->InitError(csound, Str("pvsftr: freqs ftable too small.\n")); for (i=0;i < nbins;i++) fdest[(i*2) + 1] = (float) p->ftablef[i]; @@ -731,7 +804,8 @@ fdest = (float *) p->fdest->frame.auxp; if (UNLIKELY(fdest==NULL)) - csound->Die(csound, Str("pvsftr: not initialised\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsftr: not initialised\n")); nbins = p->fftsize/2 + 1; /* only write when a new frame is ready */ @@ -763,4 +837,3 @@ *p->iformat = (MYFLT) p->fsrc->format; return OK; } - diff -Nru csound-5.17.11~dfsg/OOps/pvfileio.c csound-6.02~dfsg/OOps/pvfileio.c --- csound-5.17.11~dfsg/OOps/pvfileio.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/pvfileio.c 2014-01-07 16:53:47.000000000 +0000 @@ -422,7 +422,7 @@ csound->pvErrorCode = -3; return -1; } - if (UNLIKELY(format < PVOC_AMP_FREQ || format > PVOC_COMPLEX)) { + if (UNLIKELY(/*format < PVOC_AMP_FREQ ||*/ format > PVOC_COMPLEX)) { csound->pvErrorCode = -4; return -1; } @@ -509,12 +509,14 @@ } int pvoc_openfile(CSOUND *csound, - const char *filename, PVOCDATA *data, WAVEFORMATEX *fmt) + const char *filename, void *data_, void *fmt_) { WAVEFORMATPVOCEX wfpx; char *pname; PVOCFILE *p = NULL; int fd; + PVOCDATA *data = (PVOCDATA *) data_; + WAVEFORMATEX *fmt = (WAVEFORMATEX *) fmt_; csound->pvErrorCode = -1; if (UNLIKELY(data == NULL || fmt == NULL)) { @@ -683,7 +685,8 @@ return -1; } p->customWindow = mmalloc(csound, p->pvdata.dwWinlen * sizeof(float)); - if (UNLIKELY(pvoc_readWindow(p, p->customWindow, p->pvdata.dwWinlen) != 0)) { + if (UNLIKELY(pvoc_readWindow(p, + p->customWindow, p->pvdata.dwWinlen) != 0)) { csound->pvErrorCode = -24; return -1; } @@ -819,7 +822,8 @@ csound->pvErrorCode = -38; return 0; } - if (UNLIKELY(fseek(p->fp, (int32) (p->datachunkoffset - sizeof(uint32_t)), SEEK_SET) + if (UNLIKELY(fseek(p->fp, + (int32) (p->datachunkoffset - sizeof(uint32_t)), SEEK_SET) != 0)) { csound->pvErrorCode = -33; return 0; @@ -1015,4 +1019,3 @@ } return p->nFrames; } - diff -Nru csound-5.17.11~dfsg/OOps/pvsanal.c csound-6.02~dfsg/OOps/pvsanal.c --- csound-5.17.11~dfsg/OOps/pvsanal.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/pvsanal.c 2014-01-07 16:53:47.000000000 +0000 @@ -29,7 +29,6 @@ #include #include "csoundCore.h" #include "pstream.h" -#include "oload.h" double besseli(double x); static void hamming(MYFLT *win, int winLen, int even); @@ -74,7 +73,7 @@ return csound->InitError(csound, Str("invalid window type")); } /* use table created with GEN20 */ - flen = csound->GetTable(csound, &ftable, -(type)); + flen = csoundGetTable(csound, &ftable, -(type)); if (UNLIKELY(flen < 0)) return csound->InitError(csound, Str("ftable for window not found")); inc = (double)flen / (double)(winLen & (~1)); @@ -110,9 +109,9 @@ /* Need space for NB complex numbers for each of ksmps */ if (p->fsig->frame.auxp==NULL || - csound->ksmps*(N+2)*sizeof(MYFLT) > (unsigned int)p->fsig->frame.size) - csound->AuxAlloc(csound, csound->ksmps*(N+2)*sizeof(MYFLT),&p->fsig->frame); - else memset(p->fsig->frame.auxp, 0, csound->ksmps*(N+2)*sizeof(MYFLT)); + CS_KSMPS*(N+2)*sizeof(MYFLT) > (unsigned int)p->fsig->frame.size) + csound->AuxAlloc(csound, CS_KSMPS*(N+2)*sizeof(MYFLT),&p->fsig->frame); + else memset(p->fsig->frame.auxp, 0, CS_KSMPS*(N+2)*sizeof(MYFLT)); /* Space for remembering samples */ if (p->input.auxp==NULL || N*sizeof(MYFLT) > (unsigned int)p->input.size) @@ -164,28 +163,34 @@ MYFLT *analwinhalf,*analwinbase; MYFLT sum; int32 halfwinsize,buflen; - int i,nBins,Mf,Lf; + int i,nBins,Mf/*,Lf*/; /* opcode params */ - int32 N =(int32) *(p->fftsize); - int32 overlap = (int32) *(p->overlap); - int32 M = (int32) *(p->winsize); + uint32_t N =(int32) *(p->fftsize); + uint32_t overlap = (uint32_t) *(p->overlap); + uint32_t M = (uint32_t) *(p->winsize); int wintype = (int) *p->wintype; /* deal with iinit and iformat later on! */ - if (overlapksmps || overlap<=10) /* 10 is a guess.... */ + if (overlapDie(csound, Str("pvsanal: fftsize of 32 is too small!\n")); + return csound->InitError(csound, + Str("pvsanal: fftsize of 32 is too small!\n")); /* check N for powof2? CARL fft routines and FFTW are not limited to that */ N = N + N%2; /* Make N even */ - if (UNLIKELY(M < N)) - csound->Die(csound, Str("pvsanal: window size too small for fftsize\n")); + if (UNLIKELY(M < N)) { + csound->Warning(csound, + Str("pvsanal: window size too small for fftsize")); + M = N; + } if (UNLIKELY(overlap > N / 2)) - csound->Die(csound, Str("pvsanal: overlap too big for fft size\n")); -#ifdef OPLC - if (UNLIKELY(overlap < csound->ksmps)) - csound->Die(csound, Str("pvsanal: overlap must be >= ksmps\n")); + return csound->InitError(csound, + Str("pvsanal: overlap too big for fft size\n")); +#ifdef OLPC + if (UNLIKELY(overlap < CS_KSMPS)) + return csound->InitError(csound, + Str("pvsanal: overlap must be >= ksmps\n")); #endif halfwinsize = M/2; buflen = M*4; @@ -196,7 +201,7 @@ /* we can exclude/simplify all sorts of stuff in CARL * as we will never do time-scaling with this opcode */ - Lf = Mf = 1 - M%2; + /*Lf =*/ Mf = 1 - M%2; csound->AuxAlloc(csound, overlap * sizeof(MYFLT), &p->overlapbuf); csound->AuxAlloc(csound, (N+2) * sizeof(MYFLT), &p->analbuf); @@ -363,7 +368,9 @@ } #endif /*if (format==PVS_AMP_FREQ) {*/ - for (i=ii=0/*,i0=anal,i1=anal+1,oi=oldInPhase*/; i <= N2; i++,ii+=2/*i0+=2,i1+=2, oi++*/) { + for (i=ii=0 /*,i0=anal,i1=anal+1,oi=oldInPhase*/; + i <= N2; + i++,ii+=2 /*i0+=2,i1+=2, oi++*/) { real = anal[ii] /* *i0 */; imag = anal[ii+1] /* *i1 */; /**i0*/ anal[ii] = HYPOT(real, imag); @@ -422,6 +429,7 @@ p->inptr = 0; } + //printf("inptr = %d fsig->overlap=%d\n", p->inptr, p->fsig->overlap); inbuf[p->inptr++] = samp; } @@ -442,21 +450,25 @@ int pvssanal(CSOUND *csound, PVSANAL *p) { MYFLT *ain; - int NB = p->Ii, i, loc; + int NB = p->Ii, loc; int N = p->fsig->N; MYFLT *data = (MYFLT*)(p->input.auxp); CMPLX *fw = (CMPLX*)(p->analwinbuf.auxp); double *c = p->cosine; double *s = p->sine; double *h = (double*)p->oldInPhase.auxp; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int wintype = p->fsig->wintype; if (UNLIKELY(data==NULL)) { - csound->Die(csound, Str("pvsanal: Not Initialised.\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsanal: Not Initialised.\n")); } ain = p->ain; /* The input samples */ loc = p->inptr; /* Circular buffer */ - for (i=0; i < nsmps; i++) { + nsmps -= early; + for (i=offset; i < nsmps; i++) { MYFLT re, im, dx; CMPLX* ff; int j; @@ -479,7 +491,7 @@ /* Rectang :Fw_t = F_t */ /* Hamming :Fw_t = 0.54F_t - 0.23[ F_{t-1}+F_{t+1}] */ /* Hamming :Fw_t = 0.5 F_t - 0.25[ F_{t-1}+F_{t+1}] */ - /* Blackman:Fw_t = 0.42F_t - 0.25[ F_{t-1}+F_{t+1}] + 0.04[F_{t-2}+F_{t+2}] */ + /* Blackman:Fw_t = 0.42F_t - 0.25[ F_{t-1}+F_{t+1}]+0.04[F_{t-2}+F_{t+2}] */ /* Blackman_exact:Fw_t = 0.42659071367153912296F_t - 0.24828030954428202923 [F_{t-1}+F_{t+1}] + 0.038424333619948409286 [F_{t-2}+F_{t+2}] */ @@ -656,19 +668,23 @@ int pvsanal(CSOUND *csound, PVSANAL *p) { MYFLT *ain; - int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; ain = p->ain; if (UNLIKELY(p->input.auxp==NULL)) { - csound->Die(csound, Str("pvsanal: Not Initialised.\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsanal: Not Initialised.\n")); } { int overlap = (int)*p->overlap; - if (overlapksmps || overlap<10) /* 10 is a guess.... */ + if (overlap<(int)nsmps || overlap<10) /* 10 is a guess.... */ return pvssanal(csound, p); } - for (i=0; i < csound->ksmps; i++) + nsmps -= early; + for (i=offset; i < nsmps; i++) anal_tick(csound,p,ain[i]); return OK; } @@ -831,7 +847,7 @@ { int i,j,k,ii,NO,NO2; float *anal; /* RWD MUST be 32bit */ - MYFLT *syn,*bsyn,*output; + MYFLT *syn, *output; MYFLT *oldOutPhase = (MYFLT *) (p->oldOutPhase.auxp); int32 N = p->fsig->N; MYFLT *obufptr,*outbuf,*synWindow; @@ -851,7 +867,6 @@ outbuf = (MYFLT *) (p->overlapbuf.auxp); synWindow = (MYFLT *) (p->synwinbuf.auxp) + synWinLen; - bsyn = syn+1; /* reconversion: The magnitude and angle-difference-per-second in syn (assuming an intermediate sampling rate of rOut) are converted to real and imaginary values and are returned in syn. @@ -885,7 +900,7 @@ /* this is spread across several frame cycles, as the problem does not develop for a while */ - angledif = p->TwoPioverR * ( /* *i1 */ syn[ii+1] - ((MYFLT) i * p->Fexact)); + angledif = p->TwoPioverR * ( /* *i1 */ syn[ii+1] - ((MYFLT)i * p->Fexact)); the_phase = /* *(oldOutPhase + i) */ oldOutPhase[i] + angledif; if (i== p->bin_index) the_phase = (MYFLT) fmod(the_phase,TWOPI); @@ -915,6 +930,7 @@ out (to standard output). The subroutines reals and fft together perform an efficient inverse FFT. */ if (!(NO & (NO - 1))) { + /*printf("N %d %d \n", NO, NO & (NO-1));*/ syn[1] = syn[NO]; csound->InverseRealFFT(csound, syn, NO); syn[NO] = syn[NO + 1] = FL(0.0); @@ -983,7 +999,7 @@ int pvssynth(CSOUND *csound, PVSYNTH *p) { int i, k; - int ksmps = csound->ksmps; + int ksmps = CS_KSMPS; int N = p->fsig->N; int NB = p->fsig->NB; MYFLT *aout = p->aout; @@ -1020,14 +1036,22 @@ int pvsynth(CSOUND *csound, PVSYNTH *p) { - int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; MYFLT *aout = p->aout; if (UNLIKELY(p->output.auxp==NULL)) { - csound->Die(csound, Str("pvsynth: Not Initialised.\n")); + return csound->PerfError(csound,p->h.insdshead, + Str("pvsynth: Not Initialised.\n")); } if (p->fsig->sliding) return pvssynth(csound, p); - for (i=0;i < csound->ksmps;i++) + if (UNLIKELY(offset)) memset(aout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&aout[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset; i -#ifdef LINUX -#include -#include -#include -#include -extern int inet_aton (const char *, struct in_addr *); -#endif -#include -#endif + #ifndef WIN32 + #include + #ifdef LINUX + #include + #endif + #ifdef __HAIKU__ + #include + #endif + #include + #include + #include + extern int inet_aton (const char *, struct in_addr *); + #include + #endif /* not WIN32 */ #endif /* HAVE_SOCKETS */ #define MAXREMOTES 10 @@ -49,44 +55,79 @@ csound->remoteGlobals = NULL; } -#ifdef HAVE_SOCKETS - - /* get the IPaddress of this machine */ -static int getIpAddress(char *ipaddr, char *ifname) +#if defined(HAVE_SOCKETS) +#ifndef WIN32 +#include +#endif +#if 0 +static int foo(char *ipaddr) { - int ret = 1; -#ifdef WIN32 /* VL 12/10/06: something needs to go here */ /* gethostbyname is the real answer; code below is unsafe */ char hostname[1024]; struct hostent *he; struct sockaddr_in sin; gethostname(hostname, sizeof(hostname)); + printf("hostname=%s\n", hostname); he = gethostbyname(hostname); memset(&sin, 0, sizeof (struct sockaddr_in)); memmove(&sin.sin_addr, he->h_addr_list[0], he->h_length); strcpy(ipaddr, inet_ntoa (sin.sin_addr)); - ret = 0; + printf("IP: %s\n", ipaddr); + return 0; +} +#endif + /* get the IPaddress of this machine */ +static int getIpAddress(char *ipaddr) +{ +#ifdef WIN32 + /* VL 12/10/06: something needs to go here */ + /* gethostbyname is the real answer; code below is unsafe */ + char hostname[1024]; + struct hostent *he; + struct sockaddr_in sin; + if (gethostname(hostname, sizeof(hostname))<0) return 1; + if ((he = gethostbyname(hostname))==NULL) return 1; + + memset(&sin, 0, sizeof (struct sockaddr_in)); + memmove(&sin.sin_addr, he->h_addr_list[0], he->h_length); + strcpy(ipaddr, inet_ntoa (sin.sin_addr)); + return 0; #else + int ret = 1; struct ifreq ifr; int fd; fd = socket(AF_INET,SOCK_DGRAM, 0); if (fd >= 0) { - strcpy(ifr.ifr_name, ifname); - +#ifdef MACOSX + strcpy(ifr.ifr_name, "en0"); +#else + strcpy(ifr.ifr_name, "eth0"); +#endif if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { char *local; local = inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr); strcpy(ipaddr, local); + printf("IP for remote: %s\n", ipaddr); ret = 0; } + else { + strcpy(ifr.ifr_name, "wlan0"); + if (ioctl(fd, SIOCGIFADDR, &ifr) == 0) { + char *local; + local = inet_ntoa(((struct sockaddr_in *)(&ifr.ifr_addr))->sin_addr); + strcpy(ipaddr, local); + printf("IP for remote: %s\n", ipaddr); + ret = 0; + } + } } close(fd); -#endif return ret; +#endif } char remoteID(CSOUND *csound) @@ -160,7 +201,7 @@ /* get IP adrs of this machine */ /* FIXME: don't hardcode eth0 */ - if (UNLIKELY(getIpAddress(ST(ipadrs), "eth0") < 0)) { + if (UNLIKELY(getIpAddress(ST(ipadrs)) != 0)) { csound->Message(csound, Str("unable to get local ip address.")); goto error; } @@ -236,7 +277,8 @@ ST(to_addr).sin_port = htons((int) ST(remote_port)); /* port we will listen on, network byte order */ for (i=0; i<10; i++){ - if (UNLIKELY(connect(rfd, (struct sockaddr *) &ST(to_addr), sizeof(ST(to_addr))) < 0)) + if (UNLIKELY(connect(rfd, (struct sockaddr *) &ST(to_addr), + sizeof(ST(to_addr))) < 0)) csound->Message(csound, Str("---> Could not connect \n")); else goto conok; } @@ -258,13 +300,14 @@ { int nbytes; if (UNLIKELY((nbytes = write(conn, data, length)) <= 0)) { - return csound->PerfError(csound, Str("write to socket failed")); + csound->ErrorMsg(csound, Str("write to socket failed")); + return NOTOK; } /* csound->Message(csound, "nbytes sent: %d \n", nbytes); */ return OK; } -static int SVopen(CSOUND *csound, char *ipadrs_local) +static int SVopen(CSOUND *csound) /* Server -- open to receive */ { int conn, socklisten,opt; @@ -303,8 +346,8 @@ inet_aton((const char *)ipadrs, &(ST(local_addr).sin_addr)); #endif /* ST(local_addr).sin_port = htons((int)REMOT_PORT); */ - ST(local_addr).sin_port = htons((int) ST(remote_port)); /* port we will listen - on, netwrk byt order */ + ST(local_addr).sin_port = + htons((int) ST(remote_port)); /* port we will listen on, netwrk byt order */ /* associate the socket with the address and port */ if (UNLIKELY(bind (socklisten, (struct sockaddr *) &ST(local_addr), @@ -334,6 +377,7 @@ int SVrecv(CSOUND *csound, int conn, void *data, int length) { struct sockaddr from; + IGN(csound); #ifdef WIN32 /* VL, 12/10/06: I'm guessing here. If someone knows better, fix it */ #define MSG_DONTWAIT 0 int clilen = sizeof(from); @@ -382,10 +426,12 @@ } /* csound->Message(csound, Str("*** str1: %s own:%s\n"), */ /* (char *)p->str1 , ST(ipadrs)); */ - if (strcmp(ST(ipadrs), (char *)p->str1) == 0) { /* if client is this adrs */ + if (strcmp(ST(ipadrs), (char *)p->str1->data) == 0) { + /* if client is this adrs */ MYFLT **argp = p->insno; int rfd = 0; - if ((rfd = CLopen(csound, (char *)p->str2)) <= 0) /* open port to remote */ + if ((rfd = CLopen(csound, (char *)p->str2->data)) <= 0) + /* open port to remote */ return NOTOK; for (nargs -= 2; nargs--; ) { int16 insno = (int16)**argp++; /* & for each insno */ @@ -399,10 +445,12 @@ } ST(insrfd_list)[ST(insrfd_count)++] = rfd; /* and make a list */ } - else if (!strcmp(ST(ipadrs),(char *)p->str2)) { /* if server is this adrs*/ + else if (!strcmp(ST(ipadrs),(char *)p->str2->data)) { + /* if server is this adrs*/ /* csound->Message(csound, Str("*** str2: %s own:%s\n"), */ /* (char *)p->str2 , ST(ipadrs)); */ - if (UNLIKELY(SVopen(csound, (char *)p->str2) == NOTOK)){ /* open port to listen */ + /* open port to listen */ + if (UNLIKELY(SVopen(csound) == NOTOK)){ return csound->InitError(csound, Str("Failed to open port to listen")); } } @@ -424,8 +472,9 @@ return csound->InitError(csound, Str("missing instr nos")); } csound->Message(csound, Str("*** str1: %s own:%s\n"), - (char *)p->str1 , ST(ipadrs)); - if (strcmp(ST(ipadrs), (char *)p->str1) == 0) { /* if client is this adrs */ + (char *)p->str1->data , ST(ipadrs)); + if (strcmp(ST(ipadrs), (char *)p->str1->data) == 0) { + /* if client is this adrs */ MYFLT **argp = p->insno; for (nargs -= 1; nargs--; ) { int16 insno = (int16)**argp++; /* for each insno */ @@ -455,14 +504,16 @@ if (UNLIKELY(nargs < 3)) { return csound->InitError(csound, Str("missing channel nos")); } - if (strcmp(ST(ipadrs), (char *)p->str1) == 0) { /* if client is this adrs */ + if (strcmp(ST(ipadrs), (char *)p->str1->data) == 0) { + /* if client is this adrs */ MYFLT **argp = p->chnum; int rfd; - if (UNLIKELY((rfd = CLopen(csound, (char *)p->str2)) <= 0)) /* open port to remot */ + /* open port to remote */ + if (UNLIKELY((rfd = CLopen(csound, (char *)p->str2->data)) <= 0)) return NOTOK; for (nargs -= 2; nargs--; ) { int16 chnum = (int16)**argp++; /* & for each channel */ - if (UNLIKELY(chnum <= 0 || chnum > 16)) { /* THESE ARE MIDCHANS+1 */ + if (UNLIKELY(chnum <= 0 || chnum > 16)) { /* THESE ARE MIDCHANS+1 */ return csound->InitError(csound, Str("illegal channel no")); } if (UNLIKELY(ST(chnrfd)[chnum])) { @@ -472,8 +523,10 @@ } ST(chnrfd_list)[ST(chnrfd_count)++] = rfd; /* and make a list */ } - else if (!strcmp(ST(ipadrs), (char *)p->str2)) { /* if server is this adrs */ - if (UNLIKELY(SVopen(csound, (char *)p->str2) == NOTOK)){ /* open port to listen */ + else if (!strcmp(ST(ipadrs), (char *)p->str2->data)) { + /* if server is this adrs */ + /* open port to listen */ + if (UNLIKELY(SVopen(csound) == NOTOK)){ return csound->InitError(csound, Str("Failed to open port to listen")); } csound->oparms->RMidiin = 1; /* & enable rtevents in */ @@ -497,7 +550,8 @@ } /* csound->Message(csound, Str("*** str1: %s own:%s\n"), */ /* (char *)p->str1 , ST(ipadrs)); */ - if (strcmp(ST(ipadrs), (char *)p->str1) == 0) { /* if client is this adrs */ + if (strcmp(ST(ipadrs), (char *)p->str1->data) == 0) { + /* if client is this adrs */ MYFLT **argp = p->chnum; for (nargs -= 1; nargs--; ) { int16 chnum = (int16)**argp++; /* for each channel */ @@ -521,7 +575,9 @@ EVTBLK *cpp = (EVTBLK *)bp->data; /* align an EVTBLK struct */ int nn; MYFLT *f, *g; + cpp->pinstance = NULL; cpp->strarg = NULL; /* copy the initial header */ + cpp->scnt = 0; cpp->opcod = evt->opcod; cpp->pcnt = evt->pcnt; f = &evt->p2orig; @@ -531,7 +587,8 @@ bp->type = SCOR_EVT; /* insert type and len */ bp->len = (char *)g - (char *)bp; if (UNLIKELY(CLsend(csound, rfd, (void *)bp, (int)bp->len) < 0)) { - return csound->PerfError(csound, Str("CLsend failed")); + csound->ErrorMsg(csound, Str("CLsend failed")); + return NOTOK; } else return OK; } @@ -555,7 +612,8 @@ bp->len = sizeof(int) * 2 + sizeof(MEVENT); if (UNLIKELY(CLsend(csound, rfd, (void *)bp, (size_t)bp->len) < 0)) { - return csound->PerfError(csound, Str("CLsend failed")); + csound->ErrorMsg(csound, Str("CLsend failed")); + return NOTOK; } else return OK; } @@ -579,7 +637,8 @@ bp->len = sizeof(int) * 2 + sizeof(MEVENT); if (UNLIKELY(CLsend(csound, rfd, (void *)bp, (size_t)bp->len) < 0)) { - return csound->PerfError(csound, Str("CLsend failed")); + csound->ErrorMsg(csound, Str("CLsend failed")); + return NOTOK; } else return OK; } diff -Nru csound-5.17.11~dfsg/OOps/schedule.c csound-6.02~dfsg/OOps/schedule.c --- csound-5.17.11~dfsg/OOps/schedule.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/schedule.c 2014-01-07 16:54:20.000000000 +0000 @@ -26,216 +26,83 @@ #include "schedule.h" #include #include "namedins.h" +#include "linevent.h" -extern INSDS *insert_event(CSOUND*, MYFLT, MYFLT, MYFLT, int, MYFLT **, int); -typedef struct rsched { - void *parent; - INSDS *kicked; - struct rsched *next; -} RSCHED; +int eventOpcodeI_(CSOUND *csound, LINEVENT *p, int s, char p1); +int eventOpcode_(CSOUND *csound, LINEVENT *p, int s, char p1); -/******************************************************************************/ -/* triginstr - Ignite instrument events at k-rate from orchestra. */ -/* August 1999 by rasmus ekman. */ -/******************************************************************************/ - -static void unquote(char *dst, char *src, int maxsize) -{ - if (src[0] == '"') { - int len = (int) strlen(src) - 2; - strncpy(dst, src + 1, maxsize-1); - if (len >= 0 && dst[len] == '"') - dst[len] = '\0'; - } - else - strncpy(dst, src, maxsize); -} - -static void queue_event(CSOUND *csound, - MYFLT instr, double when, MYFLT dur, - int narg, MYFLT **args) -{ - EVTBLK evt; - int i; - - evt.strarg = NULL; - evt.opcod = 'i'; - evt.pcnt = narg + 3; - evt.p[1] = instr; - evt.p[2] = FL(0.0); - evt.p[3] = dur; - for (i = 0; i < narg; i++) - evt.p[i + 4] = *(args[i]); - insert_score_event(csound, &evt, when); -} - -/* ********** Need to add turnoff stuff *************** */ int schedule(CSOUND *csound, SCHED *p) { - RSCHED *rr = (RSCHED*) csound->schedule_kicked; - RSCHED *ss = NULL; - int which; - /* First ensure any stragglers die really in case of reinit */ - while (rr!=NULL) { - if (rr->parent==p) { - xturnoff(csound, rr->kicked); - { - RSCHED *tt = rr->next; - free(rr); - rr = tt; - if (ss == NULL) - csound->schedule_kicked = (void*) rr; - } - } - else { - ss = rr; rr = rr->next; - } + LINEVENT pp; + int i; + pp.h = p->h; + char c[2] = "i"; + pp.args[0] = (MYFLT *) c; + pp.args[1] = p->which; + pp.args[2] = p->when; + pp.args[3] = p->dur; + pp.argno = p->INOCOUNT+1; + for (i=4; i < pp.argno ; i++) { + pp.args[i] = p->argums[i-4]; + } + pp.flag = 1; + return eventOpcodeI_(csound, &pp, 0, 'i'); +} + +int schedule_S(CSOUND *csound, SCHED *p) +{ + LINEVENT pp; + int i; + pp.h = p->h; + char c[2] = "i"; + pp.args[0] = (MYFLT *) c; + pp.args[1] = p->which; + pp.args[2] = p->when; + pp.args[3] = p->dur; + pp.argno = p->INOCOUNT+1; + for (i=4; i < pp.argno ; i++) { + pp.args[i] = p->argums[i-4]; } - if (p->XSTRCODE) - which = (int) named_instr_find(csound, (char*) p->which); - else if (*p->which == SSTRCOD) - which = (int) named_instr_find(csound, csound->currevent->strarg); - else - which = (int) (FL(0.5) + *p->which); - if (UNLIKELY(which < 1 || which > csound->maxinsno || - csound->instrtxtp[which] == NULL)) { - return csound->InitError(csound, Str("Instrument not defined")); - } - { - RSCHED *rr; - /* if duration is zero assume MIDI schedule */ - MYFLT dur = *p->dur; -/* csound->Message(csound,"SCH: when = %f dur = %f\n", *p->when, dur); */ - p->midi = (dur <= FL(0.0)); - if (UNLIKELY(p->midi)) { - csound->Warning(csound,Str("schedule in MIDI mode is not " - "implemented correctly, do not use it\n")); - /* set 1 k-cycle of extratime in order to allow mtrnoff to - recognize whether the note is turned off */ - if (UNLIKELY(p->h.insdshead->xtratim < 1)) - p->h.insdshead->xtratim = 1; - } - if (*p->when <= FL(0.0)) { - p->kicked = insert_event(csound, (MYFLT) which, - (MYFLT) (csound->icurTime/csound->esr - - csound->timeOffs), - dur, p->INOCOUNT - 3, p->argums, p->midi); - if (UNLIKELY(p->midi)) { - rr = (RSCHED*) malloc(sizeof(RSCHED)); - rr->parent = p; rr->kicked = p->kicked; - rr->next = (RSCHED*) csound->schedule_kicked; - csound->schedule_kicked = (void*) rr; - } - } - else - queue_event(csound, (MYFLT) which, - (double)*p->when + csound->icurTime/csound->esr, - dur, p->INOCOUNT - 3, p->argums); - } - return OK; + pp.flag = 1; + return eventOpcodeI_(csound, &pp, 1, 'i'); } -int schedwatch(CSOUND *csound, SCHED *p) -{ /* If MIDI case watch for release */ - if (p->midi && p->h.insdshead->relesing) { - p->midi = 0; - if (p->kicked==NULL) return OK; - xturnoff(csound, p->kicked); - { - RSCHED *rr = (RSCHED*) csound->schedule_kicked; - RSCHED *ss = NULL; - while (rr!=NULL) { - if (rr->parent==p) { - RSCHED *tt = rr->next; - free(rr); - rr = tt; - if (ss == NULL) - csound->schedule_kicked = (void*) rr; - } - else { - ss = rr; rr = rr->next; - } - } - } - p->kicked = NULL; - } - return OK; -} + int ifschedule(CSOUND *csound, WSCHED *p) { /* All we need to do is ensure the trigger is set */ + IGN(csound); p->todo = 1; - p->abs_when = p->h.insdshead->p2; - p->midi = 0; return OK; } int kschedule(CSOUND *csound, WSCHED *p) { - if (p->todo && *p->trigger != FL(0.0)) { /* If not done and trigger */ - double starttime; - RSCHED *rr; - MYFLT dur = *p->dur; - int which; - if (p->XSTRCODE) - which = (int) named_instr_find(csound, (char*) p->which); - else if (*p->which == SSTRCOD) - which = (int) named_instr_find(csound, csound->currevent->strarg); - else - which = (int) (FL(0.5) + *p->which); - if (UNLIKELY(which < 1 || which > csound->maxinsno || - csound->instrtxtp[which] == NULL)) { - return csound->PerfError(csound, Str("Instrument not defined")); - } - p->midi = (dur <= FL(0.0)); - if (UNLIKELY(p->midi)) - csound->Warning(csound, - Str("schedule in MIDI mode is not " - "implemented correctly, do not use it\n")); - p->todo = 0; - /* Insert event */ - starttime = (double)p->abs_when + (double)*(p->when) + csound->timeOffs; - if (starttime*csound->esr <= csound->icurTime) { - p->kicked = insert_event(csound, (MYFLT) which, - (MYFLT) (csound->icurTime/csound->esr - - csound->timeOffs), - dur, p->INOCOUNT - 4, p->argums, p->midi); - if (p->midi) { - rr = (RSCHED*) malloc(sizeof(RSCHED)); - rr->parent = p; rr->kicked = p->kicked; - rr->next = (RSCHED*) csound->schedule_kicked; - csound->schedule_kicked = (void*) rr; - } - } - else - queue_event(csound, (MYFLT) which, - starttime, dur, p->INOCOUNT - 4, p->argums); - } - else if (p->midi && p->h.insdshead->relesing) { - /* If MIDI case watch for release */ - p->midi = 0; - if (p->kicked==NULL) return OK; - xturnoff(csound, p->kicked); - { - RSCHED *rr = (RSCHED*) csound->schedule_kicked; - RSCHED *ss = NULL; - while (rr!=NULL) { - if (rr->parent==p) { - RSCHED *tt = rr->next; - free(rr); - rr = tt; - if (ss == NULL) - csound->schedule_kicked = (void*) rr; - } - else { - ss = rr; rr = rr->next; - } - } - } - p->kicked = NULL; + if (p->todo && *p->trigger != FL(0.0)) { + LINEVENT pp; + int i; + pp.h = p->h; + char c[2] = "i"; + pp.args[0] = (MYFLT *) c; + pp.args[1] = p->which; + pp.args[2] = p->when; + pp.args[3] = p->dur; + pp.argno = p->INOCOUNT+1; + for(i=4; i < pp.argno ; i++) { + pp.args[i] = p->argums[i-4]; + } + p->todo =0; + pp.flag = 1; + if(csoundGetInputArgSMask(p) & 2){ + return eventOpcode_(csound, &pp, 1, 'i'); + } + else { + pp.flag = 0; + return eventOpcode_(csound, &pp, 0, 'i'); + } } - return OK; + else return OK; } /* tables are 4096 entries always */ @@ -281,8 +148,9 @@ phs = p->phs; switch (p->lasttype) { default: - return csound->PerfError(csound, Str("LFO: unknown oscilator type %d"), - p->lasttype); + return csound->PerfError(csound, p->h.insdshead, + Str("LFO: unknown oscilator type %d"), + p->lasttype); case 0: iphs = phs >> 12; fract = (MYFLT)(phs & 0xfff)/FL(4096.0); @@ -314,7 +182,7 @@ res = FL(1.0) - (MYFLT)phs/(MYFLT)MAXPHASE; break; } - phs += (int32)(*p->xcps * MAXPHASE * csound->onedkr); + phs += (int32)(*p->xcps * MAXPHASE * CS_ONEDKR); phs &= MAXMASK; p->phs = phs; *p->res = *p->kamp * res; @@ -323,7 +191,9 @@ int lfoa(CSOUND *csound, LFO *p) { - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 phs; MYFLT fract; MYFLT res; @@ -334,11 +204,17 @@ inc = (int32)((*p->xcps * (MYFLT)MAXPHASE) * csound->onedsr); amp = *p->kamp; ar = p->res; - for (n=0; nksmps; n++) { + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nlasttype) { default: - return csound->PerfError(csound, Str("LFO: unknown oscilator type %d"), - p->lasttype); + return csound->PerfError(csound, p->h.insdshead, + Str("LFO: unknown oscilator type %d"), + p->lasttype); case 0: iphs = phs >> 12; fract = (MYFLT)(phs & 0xfff)/FL(4096.0); @@ -384,7 +260,24 @@ /* Changes made also to Cs.h, Musmon.c and Insert.c; look for "(re Aug 1999)" */ /******************************************************************************/ -int ktriginstr(CSOUND *csound, TRIGINSTR *p); +/******************************************************************************/ +/* triginstr - Ignite instrument events at k-rate from orchestra. */ +/* August 1999 by rasmus ekman. */ +/******************************************************************************/ + +static void unquote(char *dst, char *src, int maxsize) +{ + if (src[0] == '"') { + int len = (int) strlen(src) - 2; + strncpy(dst, src + 1, maxsize-1); + if (len >= 0 && dst[len] == '"') + dst[len] = '\0'; + } + else + strncpy(dst, src, maxsize); +} + +static int ktriginstr_(CSOUND *csound, TRIGINSTR *p, int stringname); int triginset(CSOUND *csound, TRIGINSTR *p) { @@ -399,31 +292,57 @@ if (csound->global_kcounter == 0 && *p->trigger != FL(0.0) /*&& *p->args[1] <= FL(0.0)*/) { p->kadjust = 0; /* No kcounter offset at this time */ - ktriginstr(csound, p); + ktriginstr_(csound, p, 0); } p->kadjust = -1; /* Set kcounter offset for perf-time */ /* Catch p3==0 (i-time only) event triggerings. */ if (csound->global_kcounter > 0 && *p->trigger != FL(0.0) && p->h.insdshead->p3 == 0) - ktriginstr(csound, p); + ktriginstr_(csound, p,0); return OK; } -static int get_absinsno(CSOUND *csound, TRIGINSTR *p) +int triginset_S(CSOUND *csound, TRIGINSTR *p) +{ + p->prvmintim = *p->mintime; + p->timrem = 0; + /* An instrument is initialised before kcounter is incremented for + this k-cycle, and begins playing after kcounter++. + Therefore, if we should start something at the very first k-cycle of + performance, we must thus do it now, lest it be one k-cycle late. + But in ktriginstr() we'll need to use kcounter-1 to set the start time + of new events. So add a separate variable for the kcounter offset (-1) */ + if (csound->global_kcounter == 0 && + *p->trigger != FL(0.0) /*&& *p->args[1] <= FL(0.0)*/) { + p->kadjust = 0; /* No kcounter offset at this time */ + ktriginstr_(csound, p, 1); + } + p->kadjust = -1; /* Set kcounter offset for perf-time */ + /* Catch p3==0 (i-time only) event triggerings. */ + if (csound->global_kcounter > 0 && + *p->trigger != FL(0.0) && p->h.insdshead->p3 == 0) + ktriginstr_(csound, p, 1); + return OK; +} + + +static int get_absinsno(CSOUND *csound, TRIGINSTR *p, int stringname) { int insno; /* Get absolute instr num */ /* IV - Oct 31 2002: allow string argument for named instruments */ - if (p->XSTRCODE) - insno = (int)strarg2insno_p(csound, (char*)p->args[0]); - else if (*p->args[0] == SSTRCOD) - insno = (int)strarg2insno_p(csound, csound->currevent->strarg); + if (stringname) + insno = (int)strarg2insno_p(csound, ((STRINGDAT*)p->args[0])->data); + else if (ISSTRCOD(*p->args[0])) { + char *ss = get_arg_string(csound, *p->args[0]); + insno = (int)strarg2insno_p(csound, ss); + } else insno = (int)FABS(*p->args[0]); /* Check that instrument is defined */ - if (UNLIKELY(insno < 1 || insno > csound->maxinsno || - csound->instrtxtp[insno] == NULL)) { + if (UNLIKELY(insno < 1 || insno > csound->engineState.maxinsno || + csound->engineState.instrtxtp[insno] == NULL)) { csound->Warning(csound, Str("schedkwhen ignored. " "Instrument %d undefined\n"), insno); csound->perferrcnt++; @@ -432,12 +351,13 @@ return insno; } -int ktriginstr(CSOUND *csound, TRIGINSTR *p) +static int ktriginstr_(CSOUND *csound, TRIGINSTR *p, int stringname) { /* k-rate event generator */ long starttime; int i, argnum; EVTBLK evt; char name[512]; + memset(&evt, 0, sizeof(EVTBLK)); if (p->timrem > 0) p->timrem--; @@ -446,7 +366,7 @@ /* Check if mintime has changed */ if (p->prvmintim != *p->mintime) { - int32 timrem = (int32) (*p->mintime * csound->global_ekr + FL(0.5)); + int32 timrem = (int32) (*p->mintime * CS_EKR + FL(0.5)); if (timrem > 0) { /* Adjust countdown for new mintime */ p->timrem += timrem - p->prvktim; @@ -457,7 +377,7 @@ p->prvmintim = *p->mintime; } - if (*p->args[0] >= FL(0.0) || *p->args[0] == SSTRCOD) { + if (*p->args[0] >= FL(0.0) || ISSTRCOD(*p->args[0])) { /* Check for rate limit on event generation */ if (*p->mintime > FL(0.0) && p->timrem > 0) return OK; @@ -466,7 +386,7 @@ INSDS *ip; int absinsno, numinst = 0; /* Count active instr instances */ - absinsno = get_absinsno(csound, p); + absinsno = get_absinsno(csound, p, stringname); if (UNLIKELY(absinsno < 1)) return NOTOK; ip = &(csound->actanchor); @@ -478,23 +398,28 @@ } /* Create the new event */ - if (p->XSTRCODE) { - evt.strarg = (char*) p->args[0]; - evt.p[1] = SSTRCOD; - } - else if (*p->args[0] == SSTRCOD) { - unquote(name, csound->currevent->strarg, 512); - evt.strarg = name; - evt.p[1] = SSTRCOD; + if (stringname) { + evt.p[1] = csound->strarg2insno(csound,((STRINGDAT *)p->args[0])->data, 1); + evt.strarg = NULL; evt.scnt = 0; + /*evt.strarg = ((STRINGDAT*)p->args[0])->data; + evt.p[1] = SSTRCOD;*/ + } + else if (ISSTRCOD(*p->args[0])) { + unquote(name, get_arg_string(csound, *p->args[0]), 512); + evt.p[1] = csound->strarg2insno(csound,name, 1); + evt.strarg = NULL; + /* evt.strarg = name; */ + evt.scnt = 0; + /* evt.p[1] = SSTRCOD; */ } else { - evt.strarg = NULL; + evt.strarg = NULL; evt.scnt = 0; evt.p[1] = *p->args[0]; } evt.opcod = 'i'; evt.pcnt = argnum = p->INOCOUNT - 3; /* Add current time (see note about kadjust in triginset() above) */ - starttime = csound->ksmps*(csound->global_kcounter + p->kadjust); + starttime = CS_KSMPS*(csound->global_kcounter + p->kadjust); /* Copy all arguments to the new event */ for (i = 1; i < argnum; i++) evt.p[i + 1] = *p->args[i]; @@ -506,19 +431,27 @@ } /* Reset min pause counter */ if (*p->mintime > FL(0.0)) - p->timrem = (int32) (*p->mintime * csound->global_ekr + FL(0.5)); + p->timrem = (int32) (*p->mintime * CS_EKR + FL(0.5)); else p->timrem = 0; return (insert_score_event_at_sample(csound, &evt, starttime) == 0 ? OK : NOTOK); } +int ktriginstr_S(CSOUND *csound, TRIGINSTR *p){ + return ktriginstr_(csound,p,1); +} + +int ktriginstr(CSOUND *csound, TRIGINSTR *p){ + return ktriginstr_(csound,p,0); +} + /* Maldonado triggering of events */ int trigseq_set(CSOUND *csound, TRIGSEQ *p) /* by G.Maldonado */ { FUNC *ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->kfn)) == NULL)) { + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->kfn)) == NULL)) { return csound->InitError(csound, Str("trigseq: incorrect table number")); } p->done = 0; @@ -541,7 +474,7 @@ if (p->pfn != (int32)*p->kfn) { FUNC *ftp; if (UNLIKELY((ftp = csound->FTFindP(csound, p->kfn)) == NULL)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("trigseq: incorrect table number")); } p->pfn = (int32)*p->kfn; @@ -577,4 +510,3 @@ } return OK; } - diff -Nru csound-5.17.11~dfsg/OOps/sndinfUG.c csound-6.02~dfsg/OOps/sndinfUG.c --- csound-5.17.11~dfsg/OOps/sndinfUG.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/sndinfUG.c 2014-01-07 16:53:47.000000000 +0000 @@ -30,25 +30,32 @@ #include "soundio.h" #include "sndinfUG.h" -#include "oload.h" /* for strset */ #include "pvfileio.h" #include "convolve.h" -static int getsndinfo(CSOUND *csound, SNDINFO *p, SF_INFO *hdr) +static int getsndinfo(CSOUND *csound, SNDINFO *p, SF_INFO *hdr, int strin) { - char *sfname, *s, soundiname[512]; + char *sfname, *s, soundiname[1024]; SNDFILE *sf; SF_INFO sfinfo; int csFileType; memset(hdr, 0, sizeof(SF_INFO)); /* leap thru std hoops to get the name */ - csound->strarg2name(csound, soundiname, p->ifilno, "soundin.", - p->XSTRCODE); + if(strin) + strncpy(soundiname, ((STRINGDAT*)p->ifilno)->data, 1023); + else if (ISSTRCOD(*p->ifilno)){ + strncpy(soundiname, get_arg_string(csound, *p->ifilno), 1023); + } + else csound->strarg2name(csound, soundiname, p->ifilno, "soundin.",0); + + sfname = soundiname; if (strcmp(sfname, "-i") == 0) { /* get info on the -i */ - if (UNLIKELY(!csound->oparms->infilename)) /* commandline inputfile */ - csound->Die(csound, Str("no infile specified in the commandline")); + if (UNLIKELY(!csound->oparms->infilename)) { /* commandline inputfile */ + csound->InitError(csound, Str("no infile specified in the commandline")); + return NOTOK; + } sfname = csound->oparms->infilename; } s = csoundFindInputFile(csound, sfname, "SFDIR;SSDIR"); @@ -56,7 +63,8 @@ s = csoundFindInputFile(csound, sfname, "SADIR"); if (UNLIKELY(s == NULL)) { /* RWD 5:2001 better to exit in this situation ! */ - csound->Die(csound, Str("diskinfo cannot open %s"), sfname); + csound->InitError(csound, Str("diskinfo cannot open %s"), sfname); + return NOTOK; } } sfname = s; /* & record fullpath filnam */ @@ -120,7 +128,8 @@ } } if (UNLIKELY(sf == NULL && csFileType == CSFTYPE_UNKNOWN)) { - csound->Die(csound, Str("diskinfo cannot open %s"), sfname); + csound->InitError(csound, Str("diskinfo cannot open %s"), sfname); + return NOTOK; } if (sf != NULL) { csFileType = sftype2csfiletype(sfinfo.format); @@ -139,7 +148,7 @@ { SF_INFO hdr; - if (getsndinfo(csound, p, &hdr)) + if (getsndinfo(csound, p, &hdr, 0)) *(p->r1) = (MYFLT)((int32)hdr.frames) / (MYFLT)hdr.samplerate; else *(p->r1) = FL(0.0); @@ -147,11 +156,63 @@ return OK; } +int filelen_S(CSOUND *csound, SNDINFO *p) +{ + SF_INFO hdr; + + if (getsndinfo(csound, p, &hdr, 1)) + *(p->r1) = (MYFLT)((int32)hdr.frames) / (MYFLT)hdr.samplerate; + else + *(p->r1) = FL(0.0); + + return OK; +} + +int filenchnls_S(CSOUND *csound, SNDINFO *p) +{ + SF_INFO hdr; + + getsndinfo(csound, p, &hdr, 1); + *(p->r1) = (MYFLT)hdr.channels; + + return OK; +} + +int filesr_S(CSOUND *csound, SNDINFO *p) +{ + SF_INFO hdr; + + getsndinfo(csound, p, &hdr, 1); + *(p->r1) = (MYFLT)hdr.samplerate; + + return OK; +} + +int filebit_S(CSOUND *csound, SNDINFO *p) +{ + SF_INFO hdr; + int bits, format; + + getsndinfo(csound, p, &hdr, 1); + format = hdr.format & SF_FORMAT_SUBMASK; + if (format < 5) + bits = format*8 ; + else if (format == 5) bits = 8; + else if (format == 6) bits = -1; + else if (format == 7) bits = -2; + else bits = -format; /* non-PCM data */ + + *(p->r1) = (MYFLT) bits; + + return OK; +} + + int filenchnls(CSOUND *csound, SNDINFO *p) { SF_INFO hdr; - getsndinfo(csound, p, &hdr); + getsndinfo(csound, p, &hdr, 0); *(p->r1) = (MYFLT)hdr.channels; return OK; @@ -161,7 +222,7 @@ { SF_INFO hdr; - getsndinfo(csound, p, &hdr); + getsndinfo(csound, p, &hdr, 0); *(p->r1) = (MYFLT)hdr.samplerate; return OK; @@ -172,7 +233,7 @@ SF_INFO hdr; int bits, format; - getsndinfo(csound, p, &hdr); + getsndinfo(csound, p, &hdr, 0); format = hdr.format & SF_FORMAT_SUBMASK; if (format < 5) bits = format*8 ; @@ -190,23 +251,23 @@ /* RWD 8:2001: now supports all relevant files, */ /* and scans overall peak properly */ -int filepeak(CSOUND *csound, SNDINFOPEAK *p) + + +int filepeak_(CSOUND *csound, SNDINFOPEAK *p, char *soundiname) { int channel = (int)(*p->channel + FL(0.5)); - char *sfname, soundiname[512]; + char *sfname; void *fd; SNDFILE *sf; double peakVal = -1.0; int fmt, typ; SF_INFO sfinfo; - csound->strarg2name(csound, soundiname, p->ifilno, - "soundin.", p->XSTRCODE); sfname = soundiname; if (strcmp(sfname, "-i") == 0) { /* get info on the -i */ sfname = csound->oparms->infilename; /* commandline inputfile */ if (UNLIKELY(sfname == NULL)) - csound->Die(csound, + return csound->InitError(csound, Str("no infile specified in the commandline")); } memset(&sfinfo, 0, sizeof(SF_INFO)); /* open with full dir paths */ @@ -214,44 +275,36 @@ "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); if (UNLIKELY(fd == NULL)) { /* RWD 5:2001 better to exit in this situation ! */ - csound->Die(csound, Str("diskinfo cannot open %s"), sfname); + return csound->InitError(csound, Str("diskinfo cannot open %s"), sfname); } if (channel <= 0) { -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1016 if (sf_command(sf, SFC_GET_SIGNAL_MAX, &peakVal, sizeof(double)) == SF_FALSE) { csound->Warning(csound, Str("%s: no PEAK chunk was found, scanning " "file for maximum amplitude"), sfname); -#endif if (sf_command(sf, SFC_CALC_NORM_SIGNAL_MAX, &peakVal, sizeof(double)) != 0) peakVal = -1.0; -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1016 } -#endif } else { double *peaks; size_t nBytes; if (UNLIKELY(channel > sfinfo.channels)) - csound->Die(csound, Str("Input channel for peak exceeds number " + return csound->InitError(csound, Str("Input channel for peak exceeds number " "of channels in file")); nBytes = sizeof(double)* sfinfo.channels; peaks = (double*)csound->Malloc(csound, nBytes); -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1016 if (sf_command(sf, SFC_GET_MAX_ALL_CHANNELS, peaks, nBytes) == SF_FALSE) { csound->Warning(csound, Str("%s: no PEAK chunk was found, scanning " "file for maximum amplitude"), sfname); -#endif if (sf_command(sf, SFC_CALC_NORM_MAX_ALL_CHANNELS, peaks, nBytes) == 0) peakVal = peaks[channel - 1]; -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1016 } -#endif csound->Free(csound, peaks); } if (UNLIKELY(peakVal < 0.0)) - csound->Die(csound, Str("filepeak: error getting peak value")); + return csound->InitError(csound, Str("filepeak: error getting peak value")); /* scale output consistently with soundin opcode (see diskin2.c) */ fmt = sfinfo.format & SF_FORMAT_SUBMASK; typ = sfinfo.format & SF_FORMAT_TYPEMASK; @@ -265,13 +318,54 @@ return OK; } + +int filepeak(CSOUND *csound, SNDINFOPEAK *p){ + + char soundiname[1024]; + if (ISSTRCOD(*p->ifilno)){ + strncpy(soundiname, get_arg_string(csound, *p->ifilno), 1023); + } + else csound->strarg2name(csound, soundiname, p->ifilno, + "soundin.", 0); + + return filepeak_(csound, p, soundiname); +} + +int filepeak_S(CSOUND *csound, SNDINFOPEAK *p){ + + char soundiname[1024]; + strncpy(soundiname, ((STRINGDAT*)p->ifilno)->data, 1023); + + return filepeak_(csound, p, soundiname); +} + /* From matt ingalls */ int filevalid(CSOUND *csound, FILEVALID *p) { - char soundiname[512]; /* There is no check on this length */ + char soundiname[1024]; /* There is no check on this length */ + *p->r1 = 0; + if (ISSTRCOD(*p->ifilno)){ + strncpy(soundiname, get_arg_string(csound, *p->ifilno), 1023); + } + else csound->strarg2name(csound, soundiname, p->ifilno, + "soundin.", 0); + + if (UNLIKELY(strcmp(soundiname, "-i") == 0)) { /* get info on the -i */ + if (csound->oparms->infilename) /* commandline inputfile */ + *p->r1 = 1; + return OK; + } + if (LIKELY(csound->FindInputFile(csound, soundiname, "SFDIR;SSDIR"))) + *p->r1 = 1; + return OK; +} + + +int filevalid_S(CSOUND *csound, FILEVALID *p) +{ + char soundiname[1024]; /* There is no check on this length */ *p->r1 = 0; - csound->strarg2name(csound, soundiname, p->ifilno, "soundin.", - p->XSTRCODE); + strncpy(soundiname, ((STRINGDAT*)p->ifilno)->data, 1023); if (UNLIKELY(strcmp(soundiname, "-i") == 0)) { /* get info on the -i */ if (csound->oparms->infilename) /* commandline inputfile */ *p->r1 = 1; diff -Nru csound-5.17.11~dfsg/OOps/str_ops.c csound-6.02~dfsg/OOps/str_ops.c --- csound-5.17.11~dfsg/OOps/str_ops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/str_ops.c 2014-01-07 16:54:20.000000000 +0000 @@ -3,6 +3,7 @@ Copyright (C) 2005, 2006 Istvan Varga (C) 2005 Matt J. Ingalls, John ffitch + (C) 2013 V Lazzarini (new string code) This file is part of Csound. @@ -26,6 +27,10 @@ #define CSOUND_STR_OPS_C 1 #include "str_ops.h" #include +#ifdef HAVE_CURL +#include +#include "corfile.h" +#endif #define STRSMAX 8 @@ -55,8 +60,10 @@ csound->strsets[i] = NULL; csound->strsmax = newmax; } - if (UNLIKELY(ndx < 0)) /* -ve index */ - csound->Die(csound, Str("illegal strset index")); + if (UNLIKELY(ndx < 0)) { /* -ve index */ + csound->InitError(csound, Str("illegal strset index")); + return; + } if (csound->strsets[ndx] != NULL) { if (strcmp(s, csound->strsets[ndx]) == 0) @@ -76,7 +83,7 @@ int strset_init(CSOUND *csound, STRSET_OP *p) { - str_set(csound, (int) MYFLT2LRND(*p->indx), (char*) p->str); + str_set(csound, (int) MYFLT2LRND(*p->indx), p->str->data); return OK; } @@ -86,36 +93,50 @@ { int indx = 0; - if (UNLIKELY(!isdigit(*s))) - csound->Die(csound, Str("--strset: invalid format")); + if (UNLIKELY(!isdigit(*s))) { + csound->Warning(csound, Str("--strset: invalid format")); + return; + } do { indx = (indx * 10) + (int) (*s++ - '0'); } while (isdigit(*s)); - if (UNLIKELY(*s++ != '=')) - csound->Die(csound, Str("--strset: invalid format")); + if (UNLIKELY(*s++ != '=')){ + csound->Warning(csound, Str("--strset: invalid format")); + return; + } str_set(csound, indx, s); } int strget_init(CSOUND *csound, STRGET_OP *p) { int indx; - - ((char*) p->r)[0] = '\0'; - if (*(p->indx) == SSTRCOD) { - if (csound->currevent->strarg == NULL) + if (ISSTRCOD(*(p->indx))) { + char *ss = csound->currevent->strarg; + if (ss == NULL) return OK; - if ((int) strlen(csound->currevent->strarg) >= csound->strVarMaxLen) - return csound->InitError(csound, Str("strget: buffer overflow")); - strcpy((char*) p->r, csound->currevent->strarg); + ss = get_arg_string(csound, *p->indx); + if(p->r->data == NULL) { + p->r->data = cs_strdup(csound, ss); + p->r->size = strlen(ss)+1; + } + else if ((int) strlen(ss) >= p->r->size) { + mfree(csound, p->r->data); + p->r->data = cs_strdup(csound, ss); + p->r->size = strlen(ss) + 1; + } + else strcpy(p->r->data, ss); return OK; } indx = (int)((double)*(p->indx) + (*(p->indx) >= FL(0.0) ? 0.5 : -0.5)); if (indx < 0 || indx > (int) csound->strsmax || csound->strsets == NULL || csound->strsets[indx] == NULL) return OK; - if (UNLIKELY((int) strlen(csound->strsets[indx]) >= csound->strVarMaxLen)) - return csound->InitError(csound, Str("strget: buffer overflow")); - strcpy((char*) p->r, csound->strsets[indx]); + if (UNLIKELY((int) strlen(csound->strsets[indx]) >= p->r->size)){ + int size = strlen(csound->strsets[indx]); + p->r->data = mrealloc(csound, p->r->data, size + 1); + p->r->size = size + 1; + } + strcpy((char*) p->r->data, csound->strsets[indx]); return OK; } @@ -126,68 +147,128 @@ if (UNLIKELY(csound->ids != NULL && csound->ids->insdshead == csound->curip)) return csound->InitError(csound, "%s: %s", opname, Str(msg)); - else if (UNLIKELY(csound->pds != NULL)) - return csound->PerfError(csound, "%s: %s", opname, Str(msg)); + else if (UNLIKELY(((OPDS*) p)->insdshead->pds != NULL)) + return csound->PerfError(csound, ((OPDS*)p)->insdshead, + "%s: %s", opname, Str(msg)); else - csound->Die(csound, "%s: %s", opname, Str(msg)); + csound->Warning(csound, "%s: %s", opname, Str(msg)); return NOTOK; } +/* strcpy */ +int strcpy_opcode_S(CSOUND *csound, STRCPY_OP *p) +{ + char *newVal = p->str->data; + if(p->r->data == NULL) { + p->r->data = cs_strdup(csound, newVal); + p->r->size = strlen(p->str->data) + 1; + return OK; + } + if (p->r->data == p->str->data) + return OK; + if (UNLIKELY((int) strlen(newVal) >= p->r->size)){ + mfree(csound, p->r->data); + p->r->data = cs_strdup(csound, newVal); + p->r->size = strlen(newVal) + 1; + + } + else strcpy((char*) p->r->data, newVal); + + return OK; +} -static CS_NOINLINE CS_NORETURN void StrOp_FatalError(void *p, const char *msg) +int strassign_opcode_S(CSOUND *csound, STRCPY_OP *p) { - CSOUND *csound = ((OPDS*) p)->insdshead->csound; - const char *opname = csound->GetOpcodeName(p); + p->r->data = p->str->data; + p->r->size = p->str->size; + return OK; +} +int strassign_opcode_Sk(CSOUND *csound, STRCPY_OP *p) +{ + if(strcmp(p->r->data, p->str->data)!=0){ + p->r->data = p->str->data; + p->r->size = p->str->size; + } + //csound->Message(csound, p->r->data); + return OK; +} - csound->Die(csound, "%s: %s", opname, Str(msg)); +int str_changed(CSOUND *csound, STRCHGD *p){ + if(p->mem == NULL) { + mfree(csound, p->mem); + p->mem = cs_strdup(csound, p->str->data); + } + *p->r = 0; + return OK; } -/* strcpy */ +int str_changed_k(CSOUND *csound, STRCHGD *p){ -int strcpy_opcode(CSOUND *csound, STRCPY_OP *p) + if(strcmp(p->str->data, p->mem)!=0 || p->mem == NULL) { + mfree(csound, p->mem); + p->mem = cs_strdup(csound, p->str->data); + *p->r = 1; + } + else *p->r = 0; + return OK; +} +extern char* get_strarg(CSOUND *csound, MYFLT p, char *strarg); +int strcpy_opcode_p(CSOUND *csound, STRGET_OP *p) { - char *newVal = (char*) p->str; - if (p->r == p->str) - return OK; - if (*p->str == SSTRCOD){ - csound->strarg2name(csound, (char *)p->r, p->str, "soundin.", p->XSTRCODE); - return OK; - } - if (UNLIKELY((int) strlen(newVal) >= csound->strVarMaxLen)) - return StrOp_ErrMsg(p, "buffer overflow"); - strcpy((char*) p->r, newVal); + if (ISSTRCOD(*p->indx)) { + char *ss; + //printf("here\n "); + ss = get_arg_string(csound, *p->indx); + //csound->Message(csound, "%s \n", ss); + if(p->r->data == NULL) { + p->r->data = cs_strdup(csound, ss); + p->r->size = strlen(ss)+1; + } + else if ((int) strlen(ss) >= p->r->size) { + mfree(csound, p->r->data); + p->r->data = cs_strdup(csound, ss); + p->r->size = strlen(ss) + 1; + } + else strcpy(p->r->data,ss); + + } + else{ + p->r->data = csound->strarg2name(csound, NULL, p->indx, "soundin.", 0); + } return OK; } -/* strcat */ +/* strcat */ int strcat_opcode(CSOUND *csound, STRCAT_OP *p) { - char *newVal1 = (char*) p->str1; - char *newVal2 = (char*) p->str2; +; + int size; - if (UNLIKELY((int) (strlen(newVal1) + strlen(newVal2)) >= csound->strVarMaxLen)) - return StrOp_ErrMsg(p, "buffer overflow"); - if (p->r != p->str2) { - if (p->r != p->str1) - strcpy((char*) p->r, newVal1); - strcat((char*) p->r, newVal2); - return OK; + size = strlen(p->str1->data) + + strlen(p->str2->data); + + if(p->r->data == NULL) { + p->r->data = mcalloc(csound, size+1); + p->r->size = size+1; } - if (newVal1[0] == '\0') - return OK; - memmove(newVal2 + strlen(newVal1), newVal2, strlen(newVal2) + 1); - if (p->r != p->str1) - memcpy(newVal2, newVal1, strlen(newVal1)); + else if(UNLIKELY((int) size >= p->r->size)) { + p->r->data = mrealloc(csound, p->r->data, size + 1); + p->r->size = size + 1; + } + + if(p->r->data != p->str1->data) + strncpy((char*) p->r->data, p->str1->data, p->r->size); + strcat((char*) p->r->data, p->str2->data); return OK; } /* strcmp */ -int strcmp_opcode(CSOUND *csound, STRCAT_OP *p) +int strcmp_opcode(CSOUND *csound, STRCMP_OP *p) { int i; @@ -195,7 +276,7 @@ *(p->r) = FL(0.0); if (p->str1 == p->str2) return OK; - i = strcmp((char*) p->str1, (char*) p->str2); + i = strcmp((char*) p->str1->data, (char*) p->str2->data); if (i < 0) *(p->r) = FL(-1.0); else if (i > 0) @@ -207,29 +288,36 @@ /* perform a sprintf-style format -- based on code by Matt J. Ingalls */ static CS_NOINLINE int - sprintf_opcode_(void *p, /* opcode data structure pointer */ - char *dst, /* pointer to space for output string */ +sprintf_opcode_(CSOUND *csound, + void *p, /* opcode data structure pointer */ + STRINGDAT *str, /* pointer to space for output string */ const char *fmt, /* format string */ MYFLT **kvals, /* array of argument pointers */ int numVals, /* number of arguments */ - int strCode, /* bit mask for string arguments */ - int maxLen) /* available space in output buffer */ + int strCode) /* bit mask for string arguments */ { int len = 0; - char strseg[2048], *outstring = dst; + char *strseg, *outstring = str->data; MYFLT *parm = NULL; int i = 0, j = 0, n; const char *segwaiting = NULL; - int maxChars; + int maxChars, siz = strlen(fmt) + numVals*7 + 1; if (UNLIKELY((int) ((OPDS*) p)->optext->t.xincod != 0)) return StrOp_ErrMsg(p, "a-rate argument not allowed"); - if (UNLIKELY((int) ((OPDS*) p)->optext->t.inoffs->count > 31)) - StrOp_FatalError(p, "too many arguments"); + if (UNLIKELY((int) ((OPDS*) p)->optext->t.inArgCount > 31)){ + StrOp_ErrMsg(p, "too many arguments"); + return NOTOK; + } + + + strseg = malloc(siz); while (1) { - if (UNLIKELY(i >= 2047)) { - return StrOp_ErrMsg(p, "format string too long"); + if (UNLIKELY(i >= siz)) { + // return StrOp_ErrMsg(p, "format string too long"); + siz *= 2; + strseg = realloc(strseg, siz); } if (*fmt != '%' && *fmt != '\0') { strseg[i++] = *fmt++; @@ -244,16 +332,16 @@ } /* if already a segment waiting, then lets print it */ if (segwaiting != NULL) { - maxChars = maxLen - len; + maxChars = str->size - len; strseg[i] = '\0'; if (UNLIKELY(numVals <= 0)) { return StrOp_ErrMsg(p, "insufficient arguments for format"); } numVals--; - if (UNLIKELY((*segwaiting == 's' && !(strCode & 1)) || - (*segwaiting != 's' && (strCode & 1)))) { - return StrOp_ErrMsg(p, "argument type inconsistent with format"); - } + /* if (UNLIKELY((*segwaiting == 's' && !(strCode & 1)) || */ + /* (*segwaiting != 's' && (strCode & 1)))) { */ + /* return StrOp_ErrMsg(p, "argument type inconsistent with format"); */ + /* } */ strCode >>= 1; parm = kvals[j++]; switch (*segwaiting) { @@ -265,6 +353,15 @@ case 'u': case 'c': #ifdef HAVE_SNPRINTF + if ((int)strlen(strseg) + 24 > (int)maxChars) { + int offs = outstring - str->data; + str->data = mrealloc(csound, str->data, + str->size + 13); + str->size += 24; + maxChars += 24; + outstring = str->data + offs; + //printf("maxchars = %d %s\n", maxChars, strseg); + } n = snprintf(outstring, maxChars, strseg, (int) MYFLT2LRND(*parm)); #else n = sprintf(outstring, strseg, (int) MYFLT2LRND(*parm)); @@ -277,33 +374,46 @@ case 'g': case 'G': #ifdef HAVE_SNPRINTF + if(strlen(strseg) + 24 > (unsigned)maxChars) { + int offs = outstring - str->data; + str->data = mrealloc(csound, str->data, + str->size + 13); + str->size += 24; + maxChars += 24; + outstring = str->data + offs; + //printf("maxchars = %d %s\n", maxChars, strseg); + } n = snprintf(outstring, maxChars, strseg, (double)*parm); #else n = sprintf(outstring, strseg, (double)*parm); #endif break; case 's': - if ((char*)parm == dst) { + if (((STRINGDAT*)parm)->data == str->data) { return StrOp_ErrMsg(p, "output argument may not be " "the same as any of the input args"); } -#ifdef HAVE_SNPRINTF - n = snprintf(outstring, maxChars, strseg, (char*) parm); -#else - n = sprintf(outstring, strseg, (char*)parm); -#endif + if(((STRINGDAT*)parm)->size >= maxChars) { + int offs = outstring - str->data; + str->data = mrealloc(csound, str->data, + str->size + ((STRINGDAT*)parm)->size); + str->size += ((STRINGDAT*)parm)->size; + maxChars += ((STRINGDAT*)parm)->size; + outstring = str->data + offs; + } + n = sprintf(outstring, strseg, ((STRINGDAT*)parm)->data); break; default: return StrOp_ErrMsg(p, "invalid format string"); } - if (UNLIKELY(n < 0 || n >= maxChars)) { -#ifdef HAVE_SNPRINTF + if (n < 0 || n >= maxChars) { /* safely detected excess string length */ - return StrOp_ErrMsg(p, "buffer overflow"); -#else - /* wrote past end of buffer - hope that did not already crash ! */ - StrOp_FatalError(p, "buffer overflow"); -#endif + int offs = outstring - str->data; + str->data = mrealloc(csound, str->data, maxChars*2); + outstring = str->data + offs; + str->size = maxChars*2; + maxChars += str->size; + } outstring += n; len += n; @@ -321,15 +431,21 @@ if (UNLIKELY(numVals > 0)) { return StrOp_ErrMsg(p, "too many arguments for format"); } - return 0; + free(strseg); + return OK; } int sprintf_opcode(CSOUND *csound, SPRINTF_OP *p) { - if (UNLIKELY(sprintf_opcode_(p, (char*) p->r, (char*) p->sfmt, &(p->args[0]), - (int) p->INOCOUNT - 1, ((int) p->XSTRCODE >> 1), - csound->strVarMaxLen) != 0)) { - ((char*) p->r)[0] = '\0'; + if(p->r->data == NULL) { + int size = p->sfmt->size+ 10*((int) p->INOCOUNT); + p->r->data = mcalloc(csound, size); + p->r->size = size; + } + if (UNLIKELY(sprintf_opcode_(csound, p, p->r, + (char*) p->sfmt->data, &(p->args[0]), + (int) p->INOCOUNT - 1,0) == NOTOK)) { + ((char*) p->r->data)[0] = '\0'; return NOTOK; } return OK; @@ -337,13 +453,16 @@ static CS_NOINLINE int printf_opcode_(CSOUND *csound, PRINTF_OP *p) { - char buf[3072]; + STRINGDAT buf; int err; - err = sprintf_opcode_(p, buf, (char*) p->sfmt, &(p->args[0]), - (int) p->INOCOUNT - 2, ((int) p->XSTRCODE >> 2), - 3072); + buf.size = 3072; + buf.data = mcalloc(csound, buf.size); + + err = sprintf_opcode_(csound, p, &buf, (char*) p->sfmt->data, &(p->args[0]), + (int) p->INOCOUNT - 2,0); if (LIKELY(err == OK)) - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", buf); + csound->MessageS(csound, CSOUNDMSG_ORCH, buf.data); + mfree(csound, buf.data); return err; } @@ -377,9 +496,9 @@ p->noNewLine = (*p->no_newline == FL(0.0) ? 0 : 1); if (*p->ktrig > FL(0.0)) { if (!p->noNewLine) - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s\n", (char*) p->str); + csound->MessageS(csound, CSOUNDMSG_ORCH, "%s\n", (char*) p->str->data); else - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", (char*) p->str); + csound->MessageS(csound, CSOUNDMSG_ORCH, (char*) p->str->data); } p->prv_ktrig = *p->ktrig; @@ -391,36 +510,48 @@ if (*p->ktrig != p->prv_ktrig && *p->ktrig > FL(0.0)) { p->prv_ktrig = *p->ktrig; if (!p->noNewLine) - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s\n", (char*) p->str); + csound->MessageS(csound, CSOUNDMSG_ORCH, "%s\n", (char*) p->str->data); else - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", (char*) p->str); + csound->MessageS(csound, CSOUNDMSG_ORCH, (char*) p->str->data); } return OK; } -int strtod_opcode(CSOUND *csound, STRSET_OP *p) +int strtod_opcode_p(CSOUND *csound, STRTOD_OP *p) { char *s = NULL, *tmp; double x; - if (p->XSTRCODE) - s = (char*) p->str; - else { - if (*p->str == SSTRCOD) - s = csound->currevent->strarg; + if (ISSTRCOD(*p->str)) + s = get_arg_string(csound, *p->str); else { int ndx = (int) MYFLT2LRND(*p->str); if (ndx >= 0 && ndx <= (int) csound->strsmax && csound->strsets != NULL) s = csound->strsets[ndx]; } - if (UNLIKELY(s == NULL)) + if (UNLIKELY(s == NULL)) return StrOp_ErrMsg(p, "empty string"); - } while (*s == ' ' || *s == '\t') s++; if (UNLIKELY(*s == '\0')) return StrOp_ErrMsg(p, "empty string"); - x = strtod(s, &tmp); + x = cs_strtod(s, &tmp); + if (UNLIKELY(*tmp != '\0')) + return StrOp_ErrMsg(p, "invalid format"); + *p->indx = (MYFLT) x; + + return OK; +} + +int strtod_opcode_S(CSOUND *csound, STRSET_OP *p) +{ + char *s = NULL, *tmp; + double x; + s = (char*) p->str->data; + while (*s == ' ' || *s == '\t') s++; + if (UNLIKELY(*s == '\0')) + return StrOp_ErrMsg(p, "empty string"); + x = cs_strtod(s, &tmp); if (UNLIKELY(*tmp != '\0')) return StrOp_ErrMsg(p, "invalid format"); *p->indx = (MYFLT) x; @@ -428,17 +559,66 @@ return OK; } -int strtol_opcode(CSOUND *csound, STRSET_OP *p) +int strtol_opcode_S(CSOUND *csound, STRSET_OP *p) { char *s = NULL; int sgn = 0, radix = 10; int32 x = 0L; - if (p->XSTRCODE) - s = (char*) p->str; - else { - if (*p->str == SSTRCOD) - s = csound->currevent->strarg; + s = (char*) p->str->data; + while (*s == ' ' || *s == '\t') s++; + if (UNLIKELY(*s == '\0')) + return StrOp_ErrMsg(p, "empty string"); + if (*s == '+') s++; + else if (*s == '-') sgn++, s++; + if (*s == '0') { + if (s[1] == 'x' || s[1] == 'X') + radix = 16, s += 2; + else if (s[1] != '\0') + radix = 8, s++; + else { + *p->indx = FL(0.0); + return OK; + } + } + if (UNLIKELY(*s == '\0')) + return StrOp_ErrMsg(p, "invalid format"); + switch (radix) { + case 8: + while (*s >= '0' && *s <= '7') x = (x * 8L) + (int32) (*s++ - '0'); + break; + case 10: + while (*s >= '0' && *s <= '9') x = (x * 10L) + (int32) (*s++ - '0'); + break; + default: + while (1) { + if (*s >= '0' && *s <= '9') + x = (x * 16L) + (int32) (*s++ - '0'); + else if (*s >= 'A' && *s <= 'F') + x = (x * 16L) + (int32) (*s++ - 'A') + 10L; + else if (*s >= 'a' && *s <= 'f') + x = (x * 16L) + (int32) (*s++ - 'a') + 10L; + else + break; + } + } + if (UNLIKELY(*s != '\0')) + return StrOp_ErrMsg(p, "invalid format"); + if (sgn) x = -x; + *p->indx = (MYFLT) x; + + return OK; +} + + +int strtol_opcode_p(CSOUND *csound, STRTOD_OP *p) +{ + char *s = NULL; + int sgn = 0, radix = 10; + int32 x = 0L; + + if (ISSTRCOD(*p->str)) + s = get_arg_string(csound, *p->str); else { int ndx = (int) MYFLT2LRND(*p->str); if (ndx >= 0 && ndx <= (int) csound->strsmax && csound->strsets != NULL) @@ -446,7 +626,7 @@ } if (UNLIKELY(s == NULL)) return StrOp_ErrMsg(p, "empty string"); - } + while (*s == ' ' || *s == '\t') s++; if (UNLIKELY(*s == '\0')) return StrOp_ErrMsg(p, "empty string"); @@ -507,8 +687,15 @@ char *dst; int i, len, strt, end, rev = 0; - src = (char*) p->Ssrc; - dst = (char*) p->Sdst; + if(p->Ssrc->data == NULL) return NOTOK; + if(p->Sdst->data == NULL) { + int size = p->Ssrc->size; + p->Sdst->data = mcalloc(csound, size); + p->Sdst->size = size; + } + + src = (char*) p->Ssrc->data; + dst = (char*) p->Sdst->data; len = (int) strlen(src); #if defined(MSVC) || (defined(__GNUC__) && defined(__i386__)) strt = (int) MYFLT2LRND(*(p->istart)); @@ -533,14 +720,16 @@ end = tmp; rev = 1; } + src += strt; len = end - strt; - if (UNLIKELY(len >= csound->strVarMaxLen)) { - ((char*) p->Sdst)[0] = '\0'; - return StrOp_ErrMsg(p, "buffer overflow"); + if (UNLIKELY(len >= p->Sdst->size)) { + p->Sdst->data = mrealloc(csound, p->Sdst->data, len+1); + p->Sdst->size = len+1; + dst = (char*) p->Sdst->data; } i = 0; - if (!rev || p->Sdst == p->Ssrc) { + if (!rev || p->Sdst->data == p->Ssrc->data) { /* copying in forward direction is safe */ /* even if Ssrc and Sdst are the same */ do { @@ -582,7 +771,7 @@ int strchar_opcode(CSOUND *csound, STRCHAR_OP *p) { - int len = (int) strlen((char*) p->Ssrc); + int len = (int) strlen((char*) p->Ssrc->data); #if defined(MSVC) || (defined(__GNUC__) && defined(__i386__)) int pos = (int) MYFLT2LRND(*(p->ipos)); #else @@ -593,7 +782,7 @@ if (pos < 0 || pos >= len) *(p->ichr) = FL(0.0); else - *(p->ichr) = (MYFLT) ((int) ((unsigned char) ((char*) p->Ssrc)[pos])); + *(p->ichr) = (MYFLT) ((int) ((unsigned char) ((char*) p->Ssrc->data)[pos])); return OK; } @@ -608,7 +797,9 @@ int strlen_opcode(CSOUND *csound, STRLEN_OP *p) { (void) csound; - *(p->ilen) = (MYFLT) ((int) strlen((char*) p->Ssrc)); + if(p->Ssrc->size) + *(p->ilen) = (MYFLT) strlen(p->Ssrc->data); + else *(p->ilen) = FL(0.0); return OK; } @@ -626,10 +817,16 @@ const char *src; char *dst; int i; + if(p->Ssrc->data == NULL) return NOTOK; + if(p->Sdst->data == NULL) { + int size = p->Ssrc->size; + p->Sdst->data = mcalloc(csound, size); + p->Sdst->size = size; + } (void) csound; - src = (char*) p->Ssrc; - dst = (char*) p->Sdst; + src = (char*) p->Ssrc->data; + dst = (char*) p->Sdst->data; for (i = 0; src[i] != '\0'; i++) { unsigned char tmp; tmp = (unsigned char) src[i]; @@ -644,10 +841,16 @@ const char *src; char *dst; int i; + if(p->Ssrc->data == NULL) return NOTOK; + if(p->Sdst->data == NULL) { + int size = p->Ssrc->size; + p->Sdst->data = mcalloc(csound, size); + p->Sdst->size = size; + } (void) csound; - src = (char*) p->Ssrc; - dst = (char*) p->Sdst; + src = (char*) p->Ssrc->data; + dst = (char*) p->Sdst->data; for (i = 0; src[i] != '\0'; i++) { unsigned char tmp; tmp = (unsigned char) src[i]; @@ -674,12 +877,13 @@ #endif char buf[32]; - ((char*) p->Sdst)[0] = '\0'; + + ((char*) p->Sdst->data)[0] = '\0'; buf[0] = '\0'; s = &(buf[0]); switch (opt) { - case 1: /* maximum length of string variables */ - sprintf(&(buf[0]), "%d", (int) csound->strVarMaxLen - 1); + case 1: /* maximum length of variable */ + sprintf(&(buf[0]), "%d", (int) p->Sdst->size - 1); break; case 2: /* input sound file name */ s = (csound->oparms->sfread && !csound->initonly ? @@ -709,15 +913,12 @@ s = "Win32"; #elif defined(MACOSX) s = "MacOSX"; -#elif defined(mac_classic) - s = "MacOS"; #else s = "unknown"; #endif break; case 7: /* is the channel I/O callback set ? (0: no, 1: yes) */ - buf[0] = (csound->channelIOCallback_ - == (CsoundChannelIOCallback_t) NULL ? '0' : '1'); + buf[0] = 0; buf[1] = '\0'; break; default: @@ -725,9 +926,17 @@ *(p->iopt)); } if (s != NULL) { - if (UNLIKELY((int) strlen(s) >= csound->strVarMaxLen)) - return csound->InitError(csound, Str("getcfg: buffer overflow")); - strcpy((char*) p->Sdst, s); + + if(p->Sdst->data == NULL) { + int size = strlen(s) + 1; + p->Sdst->data = mcalloc(csound, size); + p->Sdst->size = size; + } + else if (UNLIKELY((int) strlen(s) >= p->Sdst->size)) { + p->Sdst->data = mrealloc(csound, p->Sdst->data, strlen(s) + 1); + p->Sdst->size = strlen(s) + 1; + } + strcpy((char*) p->Sdst->data, s); } return OK; @@ -743,8 +952,8 @@ int strindex_opcode(CSOUND *csound, STRINDEX_OP *p) { - const char *s1 = (char*) p->Ssrc1; - const char *s2 = (char*) p->Ssrc2; + const char *s1 = (char*) p->Ssrc1->data; + const char *s2 = (char*) p->Ssrc2->data; int i, j; (void) csound; @@ -775,8 +984,8 @@ int strrindex_opcode(CSOUND *csound, STRINDEX_OP *p) { - const char *s1 = (char*) p->Ssrc1; - const char *s2 = (char*) p->Ssrc2; + const char *s1 = (char*) p->Ssrc1->data; + const char *s2 = (char*) p->Ssrc2->data; int i, j, k; (void) csound; @@ -799,3 +1008,28 @@ return OK; } +#ifdef HAVE_CURL +int str_from_url(CSOUND *csound, STRCPY_OP *p) +{ + char *newVal = p->str->data; + if (strstr(newVal, ":/")==NULL) return strcpy_opcode_S(csound, p); + { + CORFIL *mm = copy_url_corefile(csound, newVal,0); + int len = corfile_length(mm); + if (p->r->data == NULL) { + p->r->data = cs_strdup(csound, corfile_body(mm)); + p->r->size = len + 1; + goto cleanup; + } + if (UNLIKELY(len >= p->r->size)) { + mfree(csound, p->r->data); + p->r->data = cs_strdup(csound, corfile_body(mm)); + p->r->size = len + 1; + } + else strcpy((char*) p->r->data, corfile_body(mm)); + cleanup: + corfile_rm(&mm); + return OK; + } +} +#endif diff -Nru csound-5.17.11~dfsg/OOps/ugens1.c csound-6.02~dfsg/OOps/ugens1.c --- csound-5.17.11~dfsg/OOps/ugens1.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens1.c 2014-01-07 16:53:47.000000000 +0000 @@ -1,4 +1,4 @@ -/* +/*% ugens1.c: Copyright (C) 1991 Barry Vercoe, John ffitch @@ -32,7 +32,7 @@ double dur; if ((dur = *p->idur) > FL(0.0)) { - p->incr = (*p->ib - *p->ia) / dur * csound->onedkr; + p->incr = (*p->ib - *p->ia) / dur * CS_ONEDKR; p->val = *p->ia; } return OK; @@ -47,15 +47,24 @@ int aline(CSOUND *csound, LINE *p) { - double val, inc; MYFLT *ar; - int n, nsmps=csound->ksmps; - + double val, inc; + MYFLT *ar; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + ar = p->xr; val = p->val; inc = p->incr; - p->val += inc; /* nxtval = val + inc */ - inc *= csound->onedksmps; - ar = p->xr; - for (n=0; nval += inc;/* nxtval = val + inc */ + inc /= (nsmps - offset); + for (n=offset; nidur) > FL(0.0) )) { a = *p->ia; b = *p->ib; if (LIKELY((a * b) > FL(0.0))) { - p->mlt = POWER(b/a, csound->onedkr/dur); + p->mlt = POWER(b/a, CS_ONEDKR/dur); p->val = a; } else if (a == FL(0.0)) @@ -91,16 +100,24 @@ int expon(CSOUND *csound, EXPON *p) { - double val, mlt, inc, nxtval; MYFLT *ar; - int n, nsmps=csound->ksmps; + double val, mlt, inc, nxtval; + MYFLT *ar; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; val = p->val; mlt = p->mlt; nxtval = val * mlt; - inc = nxtval - val; - inc *= csound->onedksmps; /* increment per sample */ ar = p->xr; - for (n=0; nINOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (SEG *) p->auxch.auxp) == NULL || nsegs*sizeof(SEG) < (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(SEG), &p->auxch); @@ -133,7 +150,7 @@ do { /* init each seg .. */ double dur = (double)**argp++; segp->nxtpt = (double)**argp++; - if (UNLIKELY((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) < 0)) + if (UNLIKELY((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) < 0)) segp->cnt = 0; segp++; } while (--nsegs); @@ -154,9 +171,6 @@ do { if (UNLIKELY(cnt > segp->cnt)) return csound->InitError(csound, Str("Breakpoint %d not valid"), bkpt); -#ifdef BETA - csound->Message(csound, " %d: %d, %d \n", bkpt, cnt, segp->cnt); -#endif segp->cnt -= cnt; cnt += segp->cnt; segp++; @@ -201,11 +215,18 @@ int linseg(CSOUND *csound, LINSEG *p) { double val, ainc; MYFLT *rs = p->rslt; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ val = p->curval; /* sav the cur value */ + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } if (LIKELY(p->segsrem)) { /* if no more segs putk */ if (--p->curcnt <= 0) { /* if done cur segment */ SEG *segp = p->cursegp; @@ -220,25 +241,26 @@ goto chk1; } /* poslen = new slope */ p->curinc = (segp->nxtpt - val) / segp->cnt; - p->curainc = p->curinc * csound->onedksmps; + p->curainc = p->curinc * CS_ONEDKSMPS; } p->curval = val + p->curinc; /* advance the cur val */ if (UNLIKELY((ainc = p->curainc) == FL(0.0))) goto putk; - for (n=0; nPerfError(csound, Str("linseg: not initialised (arate)\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("linseg: not initialised (arate)\n")); } /* **** ADSR is just a construction and use of linseg */ @@ -277,7 +299,7 @@ if (UNLIKELY(dur > len)) dur = len; len -= dur; segp->nxtpt = FL(0.0); - if ((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) == 0) + if ((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) == 0) segp->cnt = 0; segp++; /* Attack */ @@ -285,7 +307,7 @@ if (dur > len) dur = len; len -= dur; segp->nxtpt = FL(1.0); - if (UNLIKELY((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) == 0)) + if (UNLIKELY((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) == 0)) segp->cnt = 0; segp++; /* Decay */ @@ -293,7 +315,7 @@ if (dur > len) dur = len; len -= dur; segp->nxtpt = *argp[2]; - if (UNLIKELY((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) == 0)) + if (UNLIKELY((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) == 0)) segp->cnt = 0; segp++; /* Sustain */ @@ -301,16 +323,18 @@ dur = len; /* dur = csound->curip->p3 - *argp[4] - *argp[0] - *argp[1] - *argp[3]; */ segp->nxtpt = *argp[2]; - if (UNLIKELY((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) == 0)) + if (UNLIKELY((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) == 0)) segp->cnt = 0; segp++; /* Release */ segp->nxtpt = FL(0.0); - if (UNLIKELY((segp->cnt = (int32)(release * csound->ekr + FL(0.5))) == 0)) + if (UNLIKELY((segp->cnt = (int32)(release * CS_EKR + FL(0.5))) == 0)) segp->cnt = 0; if (midip) { relestim = (p->cursegp + p->segsrem - 1)->cnt; - p->xtra = relestim;/* VL 4-1-2011 was (int32)(*argp[5] * csound->ekr + FL(0.5)); this seems to fix it */ + p->xtra = relestim; + /* VL 4-1-2011 was (int32)(*argp[5] * CS_EKR + FL(0.5)); + this seems to fix it */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = (int)relestim; } @@ -382,8 +406,15 @@ int linsegr(CSOUND *csound, LINSEG *p) { MYFLT val, ainc, *rs = p->rslt; - int n, nsmps=csound->ksmps; - + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } val = p->curval; /* sav the cur value */ if (LIKELY(p->segsrem)) { /* if no more segs putk */ SEG *segp; @@ -406,19 +437,19 @@ goto chk2; } /* else get new slope */ p->curinc = (segp->nxtpt - val) / segp->cnt; - p->curainc = p->curinc * csound->onedksmps; + p->curainc = p->curinc * CS_ONEDKSMPS; } p->curval = val + p->curinc; /* advance the cur val */ if ((ainc = p->curainc) == FL(0.0)) goto putk; - for (n=0; nINOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (XSEG *) p->auxch.auxp) == NULL || nsegs*sizeof(XSEG) < (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(XSEG), &p->auxch); @@ -450,7 +482,7 @@ nxtval = **argp++; if (UNLIKELY(val * nxtval <= FL(0.0))) goto experr; - d = dur * csound->ekr; + d = dur * CS_EKR; segp->val = val; segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d)); segp->cnt = (int32) (d + FL(0.5)); @@ -474,7 +506,8 @@ MYFLT d, **argp, val, dur, dursum = FL(0.0), bkpt, nxtval; int n=0; - nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (XSEG *) p->auxch.auxp) == NULL || nsegs*sizeof(XSEG) < (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(XSEG), &p->auxch); @@ -499,7 +532,7 @@ nxtval = **argp++; if (UNLIKELY(val * nxtval <= FL(0.0))) goto experr; - d = dur * csound->ekr; + d = dur * CS_EKR; segp->val = val; segp->mlt = (MYFLT) pow((double)(nxtval / val), (1.0/(double)d)); segp->cnt = (int32) (d + FL(0.5)); @@ -524,7 +557,8 @@ MYFLT d, **argp, val, dur, dursum = FL(0.0), bkpt, nxtval; int n; - nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (XSEG*) p->auxch.auxp) == NULL || (unsigned int)nsegs*sizeof(XSEG) > (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(XSEG), &p->auxch); @@ -575,7 +609,8 @@ MYFLT d, **argp, val, dur, nxtval; int n; - nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (XSEG*) p->auxch.auxp) == NULL || (unsigned int)nsegs*sizeof(XSEG) > (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(XSEG), &p->auxch); @@ -619,12 +654,19 @@ int expseg2(CSOUND *csound, EXPSEG2 *p) /* gab-A1 (G.Maldonado) */ { XSEG *segp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT val, *rs; segp = p->cursegp; val = segp->val; rs = p->rslt; - for (n=0; ncnt < 0) { p->cursegp = ++segp; val = segp->val; @@ -671,19 +713,19 @@ sus = len; segp[0].val = FL(0.001); /* Like zero start, but exponential */ segp[0].mlt = FL(1.0); - segp[0].cnt = (int32) (delay*csound->ekr + FL(0.5)); - dur = attack*csound->ekr; + segp[0].cnt = (int32) (delay*CS_EKR + FL(0.5)); + dur = attack*CS_EKR; segp[1].val = FL(0.001); segp[1].mlt = POWER(FL(1000.0), FL(1.0)/dur); segp[1].cnt = (int32) (dur + FL(0.5)); - dur = decay*csound->ekr; + dur = decay*CS_EKR; segp[2].val = FL(1.0); segp[2].mlt = POWER(*argp[2], FL(1.0)/dur); segp[2].cnt = (int32) (dur + FL(0.5)); segp[3].val = *argp[2]; segp[3].mlt = FL(1.0); - segp[3].cnt = (int32) (sus*csound->ekr + FL(0.5)); - dur = release*csound->ekr; + segp[3].cnt = (int32) (sus*CS_EKR + FL(0.5)); + dur = release*CS_EKR; segp[4].val = *argp[2]; segp[4].mlt = POWER(FL(0.001)/(*argp[2]), FL(1.0)/dur); segp[4].cnt = MAXPOS; /*(int32) (dur + FL(0.5)); */ @@ -704,33 +746,41 @@ segp->val *= segp->mlt; return OK; err1: - return csound->PerfError(csound, Str("expseg (krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("expseg (krate): not initialised")); } int expseg(CSOUND *csound, EXXPSEG *p) { XSEG *segp; - int n, nsmps=csound->ksmps; - MYFLT li, val, *rs; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT li, val, *rs = p->rslt; MYFLT nxtval; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } segp = p->cursegp; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ while (--segp->cnt < 0) p->cursegp = ++segp; val = segp->val; nxtval = val * segp->mlt; - li = (nxtval - val) * csound->onedksmps; - rs = p->rslt; - for (n=0; nval = nxtval; return OK; err1: - return csound->PerfError(csound, Str("expseg (arate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("expseg (arate): not initialised")); } int xsgrset(CSOUND *csound, EXPSEG *p) @@ -741,7 +791,8 @@ MYFLT **argp, prvpt; p->xtra = -1; - nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; /* count segs & alloc if nec */ + /* count segs & alloc if nec */ + nsegs = (p->INOCOUNT - (!(p->INOCOUNT & 1))) >> 1; if ((segp = (SEG *) p->auxch.auxp) == NULL || (unsigned int)nsegs*sizeof(SEG) > (unsigned int)p->auxch.size) { csound->AuxAlloc(csound, (int32)nsegs*sizeof(SEG), &p->auxch); @@ -757,7 +808,7 @@ do { /* init & chk each real seg .. */ MYFLT dur = **argp++; segp->nxtpt = **argp++; - if ((segp->cnt = (int32)(dur * csound->ekr + FL(0.5))) <= 0) + if ((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) <= 0) segp->cnt = 0; else if (segp->nxtpt * prvpt <= FL(0.0)) goto experr; @@ -803,15 +854,15 @@ delay += FL(0.001); attack -= FL(0.001); segp[0].nxtpt = FL(0.001); - segp[0].cnt = (int32) (delay*csound->ekr + FL(0.5)); + segp[0].cnt = (int32) (delay*CS_EKR + FL(0.5)); segp[1].nxtpt = FL(1.0); - segp[1].cnt = (int32) (attack*csound->ekr + FL(0.5)); + segp[1].cnt = (int32) (attack*CS_EKR + FL(0.5)); segp[2].nxtpt = *argp[2]; - segp[2].cnt = (int32) (decay*csound->ekr + FL(0.5)); + segp[2].cnt = (int32) (decay*CS_EKR + FL(0.5)); segp[3].nxtpt = FL(0.001); - segp[3].cnt = (int32) (rel*csound->ekr + FL(0.5)); + segp[3].cnt = (int32) (rel*CS_EKR + FL(0.5)); relestim = (int)(p->cursegp + p->segsrem - 1)->cnt; - p->xtra = (int32)(*argp[5] * csound->ekr + FL(0.5)); /* Release time?? */ + p->xtra = (int32)(*argp[5] * CS_EKR + FL(0.5)); /* Release time?? */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; return OK; @@ -854,8 +905,15 @@ int expsegr(CSOUND *csound, EXPSEG *p) { MYFLT val, amlt, *rs = p->rslt; - int n, nsmps=csound->ksmps; - + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } val = p->curval; /* sav the cur value */ if (p->segsrem) { /* if no more segs putk */ SEG *segp; @@ -884,20 +942,20 @@ } else { p->curmlt = POWER((segp->nxtpt/val), FL(1.0)/segp->cnt); - p->curamlt = POWER(p->curmlt, csound->onedksmps); + p->curamlt = POWER(p->curmlt, FL(1.0)/(MYFLT)(nsmps-offset)); } } p->curval = val * p->curmlt; /* advance the cur val */ if ((amlt = p->curamlt) == FL(1.0)) goto putk; - for (n=0; nidur) > FL(0.0)) { - p->cnt1 = (int32)(*p->iris * csound->ekr + FL(0.5)); + p->cnt1 = (int32)(*p->iris * CS_EKR + FL(0.5)); if (p->cnt1 > (int32)0) { p->inc1 = FL(1.0) / (MYFLT) p->cnt1; p->val = FL(0.0); } else p->inc1 = p->val = FL(1.0); - a = dur * csound->ekr + FL(0.5); - b = *p->idec * csound->ekr + FL(0.5); + a = dur * CS_EKR + FL(0.5); + b = *p->idec * CS_EKR + FL(0.5); if ((int32) b > 0) { p->cnt2 = (int32) (a - b); p->inc2 = FL(1.0) / b; @@ -950,7 +1008,9 @@ int linen(CSOUND *csound, LINEN *p) { - int flag=0, n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag=0, n, nsmps = CS_KSMPS; MYFLT *rs,*sg,li,val,nxtval=FL(1.0); val = p->val; @@ -969,17 +1029,22 @@ } else p->cnt2--; p->val = nxtval; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } if (flag) { - li = (nxtval - val) * csound->onedksmps; + li = (nxtval - val) / (nsmps-offset); if (p->XINCODE) { - for (n=0; nXINCODE) { /* for (n=0; ncnt1 = (int32)(*p->iris * csound->ekr + FL(0.5)); + p->cnt1 = (int32)(*p->iris * CS_EKR + FL(0.5)); if (p->cnt1 > 0L) { p->inc1 = FL(1.0) / (MYFLT)p->cnt1; p->val = FL(0.0); } else p->inc1 = p->val = FL(1.0); if (*p->idec > FL(0.0)) { - int relestim = (int)(*p->idec * csound->ekr + FL(0.5)); + int relestim = (int)(*p->idec * CS_EKR + FL(0.5)); if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; if (UNLIKELY(*p->iatdec <= FL(0.0))) { return csound->InitError(csound, Str("non-positive iatdec")); } - else p->mlt2 = POWER(*p->iatdec, csound->onedkr / *p->idec); + else p->mlt2 = POWER(*p->iatdec, CS_ONEDKR / *p->idec); } else p->mlt2 = FL(1.0); p->lin1 = FL(0.0); @@ -1040,12 +1105,19 @@ int linenr(CSOUND *csound, LINENR *p) { - int flag=0, n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag=0, n, nsmps = CS_KSMPS; MYFLT *rs,*sg,li,val,nxtval=FL(1.0); val = p->val; rs = p->rslt; sg = p->sig; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->cnt1 > 0L) { flag = 1; p->lin1 += p->inc1; @@ -1059,16 +1131,16 @@ } p->val = nxtval; if (flag) { - li = (nxtval - val) * csound->onedksmps; + li = (nxtval - val) / (nsmps-offset); if (p->XINCODE) { - for (n=0; nXINCODE) { - memcpy(rs, sg, nsmps*sizeof(MYFLT)); + memcpy(&rs[offset], &sg[offset], (nsmps-offset)*sizeof(MYFLT)); /* for (n=0; nirise) > FL(0.0)) { p->phs = 0; - p->ki = (int32) (csound->kicvt / irise); + p->ki = (int32) (CS_KICVT / irise); p->val = *ftp->ftable; } else { @@ -1134,14 +1206,14 @@ if (UNLIKELY(!(*(ftp->ftable + ftp->flen)))) { return csound->InitError(csound, Str("rise func ends with zero")); } - cnt1 = (int32) ((idur - irise - *p->idec) * csound->ekr + FL(0.5)); + cnt1 = (int32) ((idur - irise - *p->idec) * CS_EKR + FL(0.5)); if (cnt1 < 0L) { cnt1 = 0; - nk = csound->ekr; + nk = CS_EKR; } else { if (*p->iatss < FL(0.0) || cnt1 <= 4L) - nk = csound->ekr; + nk = CS_EKR; else nk = (MYFLT) cnt1; } p->mlt1 = POWER(iatss, (FL(1.0)/nk)); @@ -1149,7 +1221,7 @@ if (UNLIKELY(*p->iatdec <= FL(0.0))) { return csound->InitError(csound, Str("non-positive iatdec")); } - p->mlt2 = POWER(*p->iatdec, (csound->onedkr / *p->idec)); + p->mlt2 = POWER(*p->iatdec, (CS_ONEDKR / *p->idec)); } p->cnt1 = cnt1; p->asym = asym; @@ -1175,7 +1247,7 @@ if (phs >= MAXLEN) { /* check that 2**N+1th pnt is good */ p->val = *(ftp->ftable + ftp->flen ); if (UNLIKELY(!p->val)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("envlpx rise func ends with zero")); } p->val -= p->asym; @@ -1197,19 +1269,27 @@ *p->rslt = *p->xamp * fact; return OK; err1: - return csound->PerfError(csound, Str("envlpx(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("envlpx(krate): not initialised")); } int envlpx(CSOUND *csound, ENVLPX *p) { FUNC *ftp; int32 phs; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *xamp, *rslt, val, nxtval, li, v1, fract, *ftab; xamp = p->xamp; rslt = p->rslt; val = p->val; + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } if ((phs = p->phs) >= 0L) { ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; /* RWD fix */ @@ -1236,25 +1316,26 @@ else nxtval *= p->mlt2; } p->val = nxtval; - li = (nxtval - val) * csound->onedksmps; /* linear interpolation factor */ + li = (nxtval - val) / (nsmps-offset); /* linear interpolation factor */ if (p->XINCODE) { /* for audio rate amplitude: */ - for (n=0; nPerfError(csound, Str("envlpx(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("envlpx(krate): not initialised")); err2: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("envlpx rise func ends with zero")); } @@ -1290,7 +1371,7 @@ else asym = FL(0.0); if ((irise = *p->irise) > FL(0.0)) { p->phs = 0; - p->ki = (int32) (csound->kicvt / irise); + p->ki = (int32) (CS_KICVT / irise); p->val = *ftp->ftable; } else { @@ -1301,9 +1382,9 @@ if (UNLIKELY(!(*(ftp->ftable + ftp->flen)))) { return csound->InitError(csound, Str("rise func ends with zero")); } - p->mlt1 = POWER(iatss, csound->onedkr); + p->mlt1 = POWER(iatss, CS_ONEDKR); if (*p->idec > FL(0.0)) { - int32 rlscnt = (int32)(*p->idec * csound->ekr + FL(0.5)); + int32 rlscnt = (int32)(*p->idec * CS_EKR + FL(0.5)); if ((p->rindep = (int32)*p->irind)) p->rlscnt = rlscnt; else if (rlscnt > p->h.insdshead->xtratim) @@ -1360,12 +1441,19 @@ int envlpxr(CSOUND *csound, ENVLPR *p) { - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 rlscnt; MYFLT *xamp, *rslt, val, nxtval, li; xamp = p->xamp; rslt = p->rslt; + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } val = p->val; if (!p->rlsing) { /* if not in reles seg */ if (p->h.insdshead->relesing) { @@ -1404,19 +1492,317 @@ } } else p->val = nxtval = val * p->mlt2; /* else do seg 3 decay */ - li = (nxtval - val) * csound->onedksmps; /* all segs use interp */ + li = (nxtval - val) / (nsmps-offset); /* all segs use interp */ if (p->XINCODE) { - for (n=0; nINOCOUNT - (!(p->INOCOUNT & 1))) >> 1; + //printf("nsegs = %d\n", nsegs); + if ((segp = (SEG *) p->auxch.auxp) == NULL || + nsegs*sizeof(SEG) < (unsigned int)p->auxch.size) { + csound->AuxAlloc(csound, (int32)nsegs*sizeof(SEG), &p->auxch); + p->cursegp = 1+(segp = (SEG *) p->auxch.auxp); + segp[nsegs-1].cnt = MAXPOS; /* set endcount for safety */ + } + sp = segp; + argp = p->argums; + y1 = val = (double)**argp++; + if (UNLIKELY(**argp <= FL(0.0))) return OK; /* if idur1 <= 0, skip init */ + p->curcnt = 0; + p->cursegp = segp+1; /* else setup first seg */ + p->segsrem = nsegs; + //printf("current seg = %p segp = %p\n", p->cursegp, segp); + do { /* init each seg .. */ + double dur = (double)**argp++; + segp->nxtpt = (double)**argp++; + if (UNLIKELY((segp->cnt = (int32)(dur * CS_EKR + FL(0.5))) < 0)) + segp->cnt = 0; + //printf("%d(%p): cnt=%d nxtpt=%f\n", + // p->segsrem-nsegs, segp, segp->cnt, segp->nxtpt); + segp++; + } while (--nsegs); + p->y1 = y1; + p->y2 = y2 = sp->nxtpt; + p->x = 0.0; + p->inc = (y2!=y1 ? 1.0/(sp->cnt) : 0.0); + p->curcnt = sp->cnt; +//printf("incx, y1,y2 = %g, %f, %f\n", p->inc, p->y1, p->y2); + return OK; +} + +int csgset_bkpt(CSOUND *csound, COSSEG *p) +{ + int32 cnt, bkpt = 0; + int nsegs; + int n; + SEG *segp; + n = csgset(csound, p); + if (UNLIKELY(n!=0)) return n; + cnt = p->curcnt; + nsegs = p->segsrem-1; + segp = p->cursegp; + do { + //csound->Message(csound, "%d/ %d: %d, %d ", nsegs, bkpt, cnt, segp->cnt); + if (UNLIKELY(cnt > segp->cnt)) + return csound->InitError(csound, Str("Breakpoint %d not valid"), bkpt); + segp->cnt -= cnt; + cnt += segp->cnt; + //csound->Message(csound, "-> %d, %d %f\n", cnt, segp->cnt, segp->nxtpt); + segp++; + bkpt++; + } while (--nsegs); + return OK; +} + +int csgrset(CSOUND *csound, COSSEG *p) +{ + int32 relestim; + csgset(csound,p); + relestim = (p->cursegp + p->segsrem-2)->cnt; + p->xtra = relestim; + if (relestim > p->h.insdshead->xtratim) + p->h.insdshead->xtratim = (int)relestim; + return OK; +} + +int kosseg(CSOUND *csound, COSSEG *p) +{ + double val1 = p->y1, val2 = p->y2, x = p->x; + double inc = p->inc; + + if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ + + if (LIKELY(p->segsrem)) { /* if no more segs putk */ + if (--p->curcnt <= 0) { /* if done cur segment */ + SEG *segp = p->cursegp; + chk1: + p->y1 = val1 = val2; + if (UNLIKELY(!--p->segsrem)) { /* if none left */ + p->y2 = val2 = segp->nxtpt; + goto putk; /* put endval */ + } + //printf("new seg: %d %f\n", segp->cnt, segp->nxtpt); + val2 = p->y2 = segp->nxtpt; /* Base of next segment */ + inc = p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + x = 0.0; + p->cursegp = segp+1; /* else find the next */ + if (UNLIKELY(!(p->curcnt = segp->cnt))) { + val2 = p->y2 = segp->nxtpt; /* nonlen = discontin */ + inc = p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + goto chk1; + } /* poslen = new slope */ + } + { + double mu2 = (1.0-cos(x*PI))*0.5; + *p->rslt = (MYFLT)(val1*(1.0-mu2)+val2*mu2); + x += inc; + } + } + else { + putk: + *p->rslt = (MYFLT)val1; + } + p->x = x; + return OK; + err1: + return csound->InitError(csound, Str("cosseg not initialised (krate)\n")); +} + +int cosseg(CSOUND *csound, COSSEG *p) +{ + double val1 = p->y1, val2 = p->y2, x = p->x; + MYFLT *rs = p->rslt; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + double inc = p->inc/(nsmps-offset); + + if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; + + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } + if (LIKELY(p->segsrem)) { /* if no more segs putk */ + if (--p->curcnt <= 0) { /* if done cur segment */ + SEG *segp = p->cursegp; + chk1: + p->y1 = val1 = val2; + if (UNLIKELY(!--p->segsrem)) { /* if none left */ + p->y2 = val2 = segp->nxtpt; + goto putk; /* put endval */ + } + //printf("new seg: %d %f\n", segp->cnt, segp->nxtpt); + val2 = p->y2 = segp->nxtpt; /* Base of next segment */ + p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + inc /= nsmps; + x = 0.0; + p->cursegp = segp+1; /* else find the next */ + if (UNLIKELY(!(p->curcnt = segp->cnt))) { + val2 = p->y2 = segp->nxtpt; /* nonlen = discontin */ + p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + inc /= nsmps; + //printf("zero length: incx, y1,y2 = %f, %f, %f\n", inc, val1, val2); + goto chk1; + } /* poslen = new slope */ + //printf("New segment incx, y1,y2 = %g, %f, %f\n", inc, val1, val2); + } + for (n=offset; n1 || x<0) printf("x=%f out of range\n", x); + } + } + else { + putk: + //printf("ending at %f\n", val1); + for (n=offset; nx = x; + return OK; + err1: + return csound->PerfError(csound, p->h.insdshead, + Str("cosseg: not initialised (arate)\n")); +} + +int cossegr(CSOUND *csound, COSSEG *p) +{ + double val1 = p->y1, val2 = p->y2, x = p->x; + MYFLT *rs = p->rslt; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; + double inc = p->inc/(nsmps-offset); + + memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; + + if (LIKELY(p->segsrem)) { /* if no more segs putk */ + SEG *segp = p->cursegp; + if (p->h.insdshead->relesing && p->segsrem > 1) { + while (p->segsrem > 1) { /* release flag new: */ + segp = ++p->cursegp; /* go to last segment */ + p->segsrem--; + } /* get univ relestim */ + segp->cnt = p->xtra >=0 ? p->xtra : p->h.insdshead->xtratim; + goto newi; /* and set new curinc */ + } + if (--p->curcnt <= 0) { /* if done cur segment */ + chk1: + p->y1 = val1 = val2; + if (UNLIKELY(!--p->segsrem)) { /* if none left */ + p->y2 = val2 = segp->nxtpt; + goto putk; /* put endval */ + } + newi: + //printf("new seg: %d %f\n", segp->cnt, segp->nxtpt); + val2 = p->y2 = segp->nxtpt; /* Base of next segment */ + p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + inc /= nsmps; + x = 0.0; + p->cursegp = segp+1; /* else find the next */ + if (UNLIKELY(!(p->curcnt = segp->cnt))) { + val2 = p->y2 = segp->nxtpt; /* nonlen = discontin */ + p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + inc /= nsmps; + //printf("zero length: incx, y1,y2 = %f, %f, %f\n", inc, val1, val2); + goto chk1; + } /* poslen = new slope */ + //printf("New segment incx, y1,y2 = %g, %f, %f\n", inc, val1, val2); + } + for (n=offset; n1 || x<0) printf("x=%f out of range\n", x); + } + } + else { + putk: + //printf("ending at %f\n", val1); + for (n=offset; nx = x; + return OK; + err1: + return csound->PerfError(csound, p->h.insdshead, + Str("cossegr: not initialised (arate)\n")); +} + + +int kcssegr(CSOUND *csound, COSSEG *p) +{ + double val1 = p->y1, val2 = p->y2, x = p->x; + double inc = p->inc; + + if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ + + if (LIKELY(p->segsrem)) { /* if no more segs putk */ + SEG *segp = p->cursegp; + if (p->h.insdshead->relesing && p->segsrem > 1) { + while (p->segsrem > 1) { /* reles flag new: */ + segp = ++p->cursegp; /* go to last segment */ + p->segsrem--; + } /* get univ relestim */ + segp->cnt = p->xtra>= 0 ? p->xtra : p->h.insdshead->xtratim; + goto newi; /* and set new curinc */ + } + if (--p->curcnt <= 0) { /* if done cur segment */ + chk1: + p->y1 = val1 = val2; + if (UNLIKELY(!--p->segsrem)) { /* if none left */ + p->y2 = val2 = segp->nxtpt; + goto putk; /* put endval */ + } + newi: + val2 = p->y2 = segp->nxtpt; /* Base of next segment */ + inc = p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + x = 0.0; + p->cursegp = segp+1; /* else find the next */ + if (UNLIKELY(!(p->curcnt = segp->cnt))) { + val2 = p->y2 = segp->nxtpt; /* nonlen = discontin */ + inc = p->inc = (segp->cnt ? 1.0/(segp->cnt) : 0.0); + goto chk1; + } /* poslen = new slope */ + } + { + double mu2 = (1.0-cos(x*PI))*0.5; + *p->rslt = (MYFLT)(val1*(1.0-mu2)+val2*mu2); + x += inc; + } + } + else { + putk: + *p->rslt = (MYFLT)val1; + } + p->x = x; + return OK; + err1: + return csound->InitError(csound, Str("cosseg not initialised (krate)\n")); +} diff -Nru csound-5.17.11~dfsg/OOps/ugens2.c csound-6.02~dfsg/OOps/ugens2.c --- csound-5.17.11~dfsg/OOps/ugens2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens2.c 2014-01-07 16:54:20.000000000 +0000 @@ -69,17 +69,24 @@ int ephsor(CSOUND *csound, EPHSOR *p) { double phase; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rs, *aphs, onedsr = csound->onedsr; - double b = p->b; + double b = p->b; double incr, R = *p->kR; rs = p->sr; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } aphs = p->aphs; phase = p->curphs; if (p->XINCODE) { MYFLT *cps = p->xcps; - for (n=0; nxcps * onedsr); - for (n=0; nsr = (MYFLT)(phs = p->curphs); - if (UNLIKELY((phs += (double)*p->xcps * csound->onedkr) >= 1.0)) + if (UNLIKELY((phs += (double)*p->xcps * CS_ONEDKR) >= 1.0)) phs -= 1.0; else if (UNLIKELY(phs < 0.0)) phs += 1.0; @@ -132,15 +139,22 @@ int phsor(CSOUND *csound, PHSOR *p) { double phase; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rs, onedsr = csound->onedsr; double incr; rs = p->sr; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } phase = p->curphs; if (p->XINCODE) { MYFLT *cps = p->xcps; - for (n=0; nxcps * onedsr); - for (n=0; n= 1.0)){ @@ -168,6 +182,7 @@ return OK; } +#ifdef SOME_FINE_DAY /*****************************************************************************/ /*****************************************************************************/ @@ -194,7 +209,7 @@ static int itblchk(CSOUND *csound, TABLE *p) { - if (UNLIKELY((p->ftp = csound->FTFind(csound, p->xfn)) == NULL)) + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->xfn)) == NULL)) return NOTOK; /* Although TABLE has an integer variable for the table number @@ -271,7 +286,7 @@ if (UNLIKELY(p->XINCODE != p->XOUTCODE)) { const char *opname = csound->GetOpcodeName(p); const char *msg = Str("%s: table index type inconsistent with output"); - if (UNLIKELY(csound->ksmps == 1)) + if (UNLIKELY(CS_KSMPS == 1)) csound->Warning(csound, msg, opname); else { return csound->InitError(csound, msg, opname); @@ -288,7 +303,7 @@ if (UNLIKELY(p->XINCODE != p->XOUTCODE)) { const char *opname = csound->GetOpcodeName(p); const char *msg = Str("%s: table index type inconsistent with output"); - if (UNLIKELY(csound->ksmps == 1)) + if (UNLIKELY(CS_KSMPS == 1)) csound->Warning(csound, msg, opname); else { return csound->InitError(csound, msg, opname); @@ -365,7 +380,7 @@ * with interpolation. * * This is typically used for k rate reading - where they are called - * as a result of being listed in a line in opcodlst. They are also + * as a result of being listed in a line in engineState.opcodlst. They are also * called by two functions which after they have coped with any change * in the k rate function table number. * @@ -380,7 +395,7 @@ * * These do the reading at a rate with an a rate index. * - * They are called directly via their entries in opcodlst, and also by + * They are called directly via their entries in engineState.opcodlst, and also by * two functions which call them after they have coped with any change * in the k rate function table number. * @@ -459,7 +474,8 @@ *p->rslt = *(ftp->ftable + indx); return OK; err1: - return csound->PerfError(csound, Str("table(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("table(krate): not initialised")); } /* tablefn() */ @@ -473,20 +489,27 @@ FUNC *ftp; MYFLT *rslt, *pxndx, *tab; int32 indx, mask, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT ndx, xbmul, offset; int wrap = p->wrap; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; /* RWD fix */ rslt = p->rslt; + if (UNLIKELY(koffset)) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; offset = p->offset; mask = ftp->lenmask; tab = ftp->ftable; - for (n=0; nPerfError(csound, Str("table: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("table: not initialised")); } /* ktabli() */ @@ -603,7 +627,8 @@ *p->rslt = v1 + (v2 - v1) * fract; return OK; err1: - return csound->PerfError(csound, Str("tablei(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tablei(krate): not initialised")); } @@ -694,7 +719,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("table3(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("table3(krate): not initialised")); } /* tabli() */ @@ -706,13 +732,20 @@ { FUNC *ftp; int32 indx, mask, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rslt, *pxndx, *tab; - MYFLT fract, v1, v2, ndx, xbmul, offset; + MYFLT fract, v1, v2, ndx, xbmul, offset; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; rslt = p->rslt; + if (UNLIKELY(koffset)) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; @@ -721,7 +754,7 @@ tab = ftp->ftable; /* As for ktabli() code to handle non wrap mode, and wrap mode. */ if (!p->wrap) { - for (n=0; nPerfError(csound, Str("tablei: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tablei: not initialised")); } int tabl3(CSOUND *csound, TABLE *p) /* Like tabli but cubic interpolation */ { FUNC *ftp; int32 indx, mask, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rslt, *pxndx, *tab; - MYFLT fract, v1, v2, ndx, xbmul, offset; - int wrap = p->wrap; + MYFLT fract, v1, v2, ndx, xbmul, offset; + int wrap = p->wrap; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; rslt = p->rslt; + if (UNLIKELY(koffset)) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; offset = p->offset; mask = ftp->lenmask; tab = ftp->ftable; - for (n=0; nPerfError(csound, Str("table3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("table3: not initialised")); } /*************************************/ @@ -909,15 +951,17 @@ } return OK; err1: - return csound->PerfError(csound, Str("k rate function table no. %f < 1"), + return csound->PerfError(csound, p->h.insdshead, + Str("k rate function table no. %f < 1"), *p->xfn); err2: - return csound->PerfError(csound, Str("Offset %f < 0 or > tablelength"), + return csound->PerfError(csound, p->h.insdshead, + Str("Offset %f < 0 or > tablelength"), p->offset); } /* Now for the four functions, which are called as a result of being - * listed in opcodlst in entry.c */ + * listed in engineState.opcodlst in entry.c */ int ktablekt(CSOUND *csound, TABLE *p) { @@ -954,6 +998,7 @@ if (LIKELY(ftkrchk(csound,p)==OK)) return tabl3(csound,p); return NOTOK; } +#endif /* SOME_FINE_DAY */ int ko1set(CSOUND *csound, OSCIL1 *p) { @@ -966,8 +1011,8 @@ } p->ftp = ftp; p->phs = 0; - p->dcnt = (int32)(*p->idel * csound->ekr); - p->kinc = (int32) (csound->kicvt / *p->idur); + p->dcnt = (int32)(*p->idel * CS_EKR); + p->kinc = (int32) (CS_KICVT / *p->idur); if (p->kinc==0) p->kinc = 1; return OK; } @@ -994,7 +1039,8 @@ p->dcnt = dcnt; return OK; err1: - return csound->PerfError(csound, Str("oscil1(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil1(krate): not initialised")); } int kosc1i(CSOUND *csound, OSCIL1 *p) @@ -1025,14 +1071,15 @@ } return OK; err1: - return csound->PerfError(csound, Str("oscil1i(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil1i(krate): not initialised")); } int oscnset(CSOUND *csound, OSCILN *p) { FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { p->ftp = ftp; p->inc = ftp->flen * *p->ifrq * csound->onedsr; p->index = FL(0.0); @@ -1046,16 +1093,23 @@ int osciln(CSOUND *csound, OSCILN *p) { MYFLT *rs = p->rslt; - int32 n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->ftp==NULL)) goto err1; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->ntimes) { MYFLT *ftbl = p->ftp->ftable; MYFLT amp = *p->kamp; MYFLT ndx = p->index; MYFLT inc = p->inc; MYFLT maxndx = p->maxndx; - for (n=0; n maxndx)) { if (--p->ntimes) @@ -1078,7 +1132,50 @@ } return OK; err1: - return csound->PerfError(csound, Str("osciln: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("osciln: not initialised")); +} + +static int fill_func_from_array(ARRAYDAT *a, FUNC *f) +{ + int lobits, ltest, flen, i; + int nonpowof2_flag = 0; + + flen = f->flen = a->sizes[0]; + flen &= -2L; + for (ltest = flen, lobits = 0; + (ltest & MAXLEN) == 0L; + lobits++, ltest <<= 1) + ; + if (UNLIKELY(ltest != MAXLEN)) { + lobits = 0; + nonpowof2_flag = 1; + } + f->ftable = a->data; + f->lenmask = ((flen & (flen - 1L)) ? + 0L : (flen - 1L)); /* init hdr w powof2 data */ + f->lobits = lobits; + i = (1 << lobits); + f->lomask = (int32) (i - 1); + f->lodiv = FL(1.0) / (MYFLT) i; /* & other useful vals */ + f->nchanls = 1; /* presume mono for now */ + f->flenfrms = flen; + if (nonpowof2_flag) + f->lenmask = 0xFFFFFFFF; + return OK; +} + +int oscsetA(CSOUND *csound, OSC *p) +{ + FUNC *ftp = &p->FF; + int res; + + if (*p->iphs >= 0) + p->lphs = ((int32)(*p->iphs * FMAXLEN)) & PHMASK; + //check p->ifn is a valid array with power-of-two length + p->ftp = ftp; + res = fill_func_from_array((ARRAYDAT*)p->ifn, ftp); + return OK; } int oscset(CSOUND *csound, OSC *p) @@ -1102,14 +1199,15 @@ ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; phs = p->lphs; - inc = (int32) (*p->xcps * csound->kicvt); + inc = (int32) (*p->xcps * CS_KICVT); *p->sr = ftp->ftable[phs >> ftp->lobits] * *p->xamp; phs += inc; phs &= PHMASK; p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil(krate): not initialised")); } int osckk(CSOUND *csound, OSC *p) @@ -1117,7 +1215,9 @@ FUNC *ftp; MYFLT amp, *ar, *ftbl; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; @@ -1127,7 +1227,12 @@ lobits = ftp->lobits; amp = *p->xamp; ar = p->sr; - for (n=0;n> lobits] * amp; /* phs += inc; */ /* phs &= PHMASK; */ @@ -1136,7 +1241,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil: not initialised")); } int oscka(CSOUND *csound, OSC *p) @@ -1144,7 +1250,9 @@ FUNC *ftp; MYFLT *ar, amp, *cpsp, *ftbl; int32 phs, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; ftp = p->ftp; @@ -1155,7 +1263,12 @@ cpsp = p->xcps; phs = p->lphs; ar = p->sr; - for (n=0;n> lobits] * amp; phs += inc; @@ -1164,7 +1277,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil: not initialised")); } int oscak(CSOUND *csound, OSC *p) @@ -1172,7 +1286,9 @@ FUNC *ftp; MYFLT *ar, *ampp, *ftbl; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; @@ -1182,14 +1298,20 @@ inc = MYFLT2LONG(*p->xcps * csound->sicvt); ampp = p->xamp; ar = p->sr; - for (n=0;n> lobits] * ampp[n]; phs = (phs+inc) & PHMASK; } p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil: not initialised")); } int oscaa(CSOUND *csound, OSC *p) @@ -1197,7 +1319,9 @@ FUNC *ftp; MYFLT *ar, *ampp, *cpsp, *ftbl; int32 phs, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; ftp = p->ftp; @@ -1208,7 +1332,12 @@ ampp = p->xamp; cpsp = p->xcps; ar = p->sr; - for (n=0;n> lobits] * ampp[n]; phs = (phs+inc) & PHMASK; @@ -1216,7 +1345,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil: not initialised")); } int koscli(CSOUND *csound, OSC *p) @@ -1232,13 +1362,14 @@ ftab = ftp->ftable + (phs >> ftp->lobits); v1 = ftab[0]; *p->sr = (v1 + (ftab[1] - v1) * fract) * *p->xamp; - inc = (int32)(*p->xcps * csound->kicvt); + inc = (int32)(*p->xcps * CS_KICVT); phs += inc; phs &= PHMASK; p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscili(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscili(krate): not initialised")); } int osckki(CSOUND *csound, OSC *p) @@ -1246,7 +1377,9 @@ FUNC *ftp; MYFLT fract, v1, amp, *ar, *ft, *ftab; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY((ftp = p->ftp)==NULL)) goto err1; lobits = ftp->lobits; @@ -1254,8 +1387,13 @@ inc = MYFLT2LONG(*p->xcps * csound->sicvt); amp = *p->xamp; ar = p->sr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } ft = ftp->ftable; - for (n=0; n> lobits); v1 = ftab[0]; @@ -1265,7 +1403,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscili: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscili: not initialised")); } int osckai(CSOUND *csound, OSC *p) @@ -1273,7 +1412,9 @@ FUNC *ftp; MYFLT *ar, amp, *cpsp, fract, v1, *ftab, *ft; int32 phs, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; ftp = p->ftp; @@ -1283,8 +1424,13 @@ cpsp = p->xcps; phs = p->lphs; ar = p->sr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } ft = ftp->ftable; - for (n=0;nlphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscili: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscili: not initialised")); } int oscaki(CSOUND *csound, OSC *p) { FUNC *ftp; - MYFLT v1, fract, *ar, *ampp, *ftab, *ft; + MYFLT v1, fract, *ar, *ampp, *ftab, *ft; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; @@ -1314,8 +1463,13 @@ inc = MYFLT2LONG(*p->xcps * csound->sicvt); ampp = p->xamp; ar = p->sr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } ft = ftp->ftable; - for (n=0;n> lobits); v1 = ftab[0]; @@ -1325,7 +1479,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscili: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscili: not initialised")); } int oscaai(CSOUND *csound, OSC *p) @@ -1333,7 +1488,9 @@ FUNC *ftp; MYFLT v1, fract, *ar, *ampp, *cpsp, *ftab, *ft; int32 phs, lobits; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; ftp = p->ftp; @@ -1344,7 +1501,12 @@ ampp = p->xamp; cpsp = p->xcps; ar = p->sr; - for (n=0;nlphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscili: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscili: not initialised")); } int koscl3(CSOUND *csound, OSC *p) @@ -1364,7 +1527,7 @@ FUNC *ftp; int32 phs, inc; MYFLT *ftab, fract; - int x0; + int32 x0; MYFLT y0, y1, ym1, y2, amp = *p->xamp; phs = p->lphs; @@ -1380,7 +1543,7 @@ else ym1 = ftab[x0++]; y0 = ftab[x0++]; y1 = ftab[x0++]; - if (UNLIKELY(x0>ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; + if (UNLIKELY(x0>(int32)ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; { MYFLT frsq = fract*fract; MYFLT frcu = frsq*ym1; @@ -1390,13 +1553,14 @@ frsq*fract*(t1/FL(6.0) - FL(0.5)*y1) + frsq*(FL(0.5)* y1 - y0)); } - inc = (int32)(*p->xcps * csound->kicvt); + inc = (int32)(*p->xcps * CS_KICVT); phs += inc; phs &= PHMASK; p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil3(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil3(krate): not initialised")); } int osckk3(CSOUND *csound, OSC *p) @@ -1404,8 +1568,10 @@ FUNC *ftp; MYFLT fract, amp, *ar, *ftab; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; - int x0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 x0; MYFLT y0, y1, ym1, y2; ftp = p->ftp; @@ -1416,7 +1582,12 @@ inc = MYFLT2LONG(*p->xcps * csound->sicvt); amp = *p->xamp; ar = p->sr; - for (n=0;n> lobits); x0--; @@ -1426,7 +1597,7 @@ else ym1 = ftab[x0++]; y0 = ftab[x0++]; y1 = ftab[x0++]; - if (UNLIKELY(x0>ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; + if (UNLIKELY(x0>(int32)ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; /* printf("fract = %f; y = %f, %f, %f, %f\n", fract,ym1,y0,y1,y2); */ { MYFLT frsq = fract*fract; @@ -1447,7 +1618,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil3: not initialised")); } int oscka3(CSOUND *csound, OSC *p) @@ -1455,8 +1627,10 @@ FUNC *ftp; MYFLT *ar, amp, *cpsp, fract, *ftab; int32 phs, lobits; - int n, nsmps=csound->ksmps; - int x0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 x0; MYFLT y0, y1, ym1, y2; MYFLT sicvt = csound->sicvt; @@ -1468,7 +1642,12 @@ cpsp = p->xcps; phs = p->lphs; ar = p->sr; - for (n=0;nftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; + if (UNLIKELY(x0>(int32)ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; { MYFLT frsq = fract*fract; MYFLT frcu = frsq*ym1; @@ -1495,7 +1674,8 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil3: not initialised")); } int oscak3(CSOUND *csound, OSC *p) @@ -1503,8 +1683,10 @@ FUNC *ftp; MYFLT fract, *ar, *ampp, *ftab; int32 phs, inc, lobits; - int n, nsmps=csound->ksmps; - int x0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 x0; MYFLT y0, y1, ym1, y2; ftp = p->ftp; @@ -1515,7 +1697,12 @@ inc = MYFLT2LONG(*p->xcps * csound->sicvt); ampp = p->xamp; ar = p->sr; - for (n=0;n> lobits); x0--; @@ -1525,7 +1712,7 @@ else ym1 = ftab[x0++]; y0 = ftab[x0++]; y1 = ftab[x0++]; - if (UNLIKELY(x0>ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; + if (UNLIKELY(x0>(int32)ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; { MYFLT frsq = fract*fract; MYFLT frcu = frsq*ym1; @@ -1540,18 +1727,21 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil3: not initialised")); } int oscaa3(CSOUND *csound, OSC *p) { FUNC *ftp; - MYFLT fract, *ar, *ampp, *cpsp, *ftab; - int32 phs, lobits; - int n, nsmps=csound->ksmps; - int x0; - MYFLT y0, y1, ym1, y2; - MYFLT sicvt = csound->sicvt; + MYFLT fract, *ar, *ampp, *cpsp, *ftab; + int32 phs, lobits; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 x0; + MYFLT y0, y1, ym1, y2; + MYFLT sicvt = csound->sicvt; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; @@ -1561,7 +1751,12 @@ ampp = p->xamp; cpsp = p->xcps; ar = p->sr; - for (n=0;n> lobits); @@ -1572,7 +1767,7 @@ else ym1 = ftab[x0++]; y0 = ftab[x0++]; y1 = ftab[x0++]; - if (UNLIKELY(x0>ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; + if (UNLIKELY(x0>(int32)ftp->flen)) y2 = ftab[1]; else y2 = ftab[x0]; { MYFLT frsq = fract*fract; MYFLT frcu = frsq*ym1; @@ -1587,5 +1782,6 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("oscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscil3: not initialised")); } diff -Nru csound-5.17.11~dfsg/OOps/ugens2a.c csound-6.02~dfsg/OOps/ugens2a.c --- csound-5.17.11~dfsg/OOps/ugens2a.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens2a.c 2014-01-07 16:53:47.000000000 +0000 @@ -37,7 +37,7 @@ static int itblchk(CSOUND *csound, TABLE *p) { - if (UNLIKELY((p->ftp = csound->FTFind(csound, p->xfn)) == NULL)) + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->xfn)) == NULL)) return csound->InitError(csound, Str("table does not exist")); /* Although TABLE has an integer variable for the table number @@ -70,6 +70,22 @@ return OK; } +int tblset(CSOUND *csound, TABLE *p) +{ + if (UNLIKELY(p->XINCODE != p->XOUTCODE)) { + const char *opname = csound->GetOpcodeName(p); + const char *msg = Str("%s: table index type inconsistent with output"); + if (UNLIKELY(CS_KSMPS == 1)) + csound->Warning(csound, msg, opname); + else { + return csound->InitError(csound, msg, opname); + } + } + p->h.iopadr = (SUBR) itblchk; + return itblchk(csound, p); +} + + int pktable(CSOUND *,TABLE*); int pktabli(CSOUND *,TABLE*); int pktabl3(CSOUND *,TABLE*); @@ -165,7 +181,8 @@ *p->rslt = *(ftp->ftable + indx); return OK; err1: - return csound->PerfError(csound, Str("ptable(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ptable(krate): not initialised")); } /* ptablefn() */ @@ -175,20 +192,27 @@ FUNC *ftp; MYFLT *rslt, *pxndx, *tab; int32 indx, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT ndx, xbmul, offset; int wrap = p->wrap; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; /* RWD fix */ rslt = p->rslt; + if (koffset) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; offset = p->offset; //mask = ftp->lenmask; tab = ftp->ftable; - for (n=0; nPerfError(csound, Str("table: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("table: not initialised")); } /* pktabli() */ @@ -262,7 +287,8 @@ *p->rslt = v1 + (v2 - v1) * fract; return OK; err1: - return csound->PerfError(csound, Str("ptablei(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ptablei(krate): not initialised")); } @@ -321,20 +347,28 @@ } return OK; err1: - return csound->PerfError(csound, Str("ptable3(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ptable3(krate): not initialised")); } int ptabli(CSOUND *csound, TABLE *p) { FUNC *ftp; int32 indx, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rslt, *pxndx, *tab; MYFLT fract, v1, v2, ndx, xbmul, offset; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; rslt = p->rslt; + if (koffset) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; @@ -343,7 +377,7 @@ tab = ftp->ftable; /* As for ktabli() code to handle non wrap mode, and wrap mode. */ if (!p->wrap) { - for (n=0; nPerfError(csound, Str("ptablei: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ptablei: not initialised")); } int ptabl3(CSOUND *csound, TABLE *p) /* Like ptabli but cubic interpolation */ { FUNC *ftp; int32 indx, length; - int n, nsmps=csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rslt, *pxndx, *tab; MYFLT fract, v1, v2, ndx, xbmul, offset; int wrap = p->wrap; @@ -410,12 +447,17 @@ ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; rslt = p->rslt; + if (koffset) memset(rslt, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } length = ftp->flen; pxndx = p->xndx; xbmul = (MYFLT)p->xbmul; offset = p->offset; tab = ftp->ftable; - for (n=0; nPerfError(csound, Str("ptable3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ptable3: not initialised")); } -extern int itblchkw(CSOUND *, TABLEW*); +int itblchkw(CSOUND *csound, TABLEW *p) +{ + /* Get pointer to the function table data structure of the table + * number specified in xfn. Return 0 if it cannot be found. + * + * csoundFTFind() generates an error message if the table cannot be + * found. This works OK at init time. It also deactivates the + * instrument. + * + * It also checks for numbers < 0, and table 0 is never valid, so we + * do not need to check here for the table number being < 1. */ + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->xfn)) == NULL)) + return NOTOK; + /* Although TABLEW has an integer variable for the table number + * (p->pfn) we do not need to * write it. We know that the * k + * and a rate functions * which will follow will not * be + * expecting a changed * table number. + * + * p->pfn exists only for checking * table number changes for + * functions * which are expecting a k rate * table number. */ + + /* Set denormalisation factor to 1 or table length, depending on + * the state of ixmode. 1L means a 32 bit 1. */ + /* JPff.............................^...not so; could be any length */ + if (*p->ixmode) + p->xbmul = p->ftp->flen; + else p->xbmul = 1L; + /* Multiply the ixoff value by the xbmul denormalisation + * factor and then check it is between 0 and the table length. */ + if (UNLIKELY((p->offset = p->xbmul * *p->ixoff) < FL(0.0) + || p->offset > p->ftp->flen)) { + return csound->InitError(csound, + Str("Table write offset %f < 0 or > tablelength"), + p->offset); + } + p->iwgm = (int)*p->iwgmode; + return OK; +} + + int pktablew(CSOUND *, TABLEW*); int pitablew(CSOUND *csound, TABLEW *p) { @@ -560,7 +643,9 @@ int32 indx; /* Used to read table. */ int32 length; /* Length of table */ int liwgm; /* Local copy of iwgm for speed */ - int n, nsmps = csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT ndx, xbmul, offset; /*-----------------------------------*/ /* Assume that TABLEW has been set up correctly. */ @@ -574,7 +659,8 @@ xbmul = (MYFLT)p->xbmul; offset = p->offset; /* Main loop - for the number of a samples in a k cycle. */ - for (n=0; n -#include "oload.h" int foscset(CSOUND *csound, FOSC *p) { @@ -48,7 +47,9 @@ MYFLT *ar, *ampp, *modp, cps, amp; MYFLT xcar, xmod, *carp, car, fmod, cfreq, mod, ndx, *ftab; int32 mphs, cphs, minc, cinc, lobits; - int n, nn=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; ar = p->rslt; @@ -65,9 +66,14 @@ amp = *ampp; xcar = *carp; xmod = *modp; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->XINCODE) { - for (n=0;nampcod) amp = ampp[n]; if (p->carcod) xcar = carp[n]; if (p->modcod) xmod = modp[n]; @@ -92,7 +98,7 @@ mod = cps * *modp; ndx = *p->kndx * mod; minc = (int32)(mod * sicvt); - for (n=0;n>lobits)) * ndx; mphs += minc; @@ -108,7 +114,8 @@ return OK; err1: - return csound->PerfError(csound, Str("foscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("foscil: not initialised")); } int foscili(CSOUND *csound, FOSC *p) @@ -117,7 +124,9 @@ MYFLT *ar, *ampp, amp, cps, fract, v1, car, fmod, cfreq, mod; MYFLT *carp, *modp, xcar, xmod, ndx, *ftab; int32 mphs, cphs, minc, cinc, lobits; - int n, nn=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT sicvt = csound->sicvt; MYFLT *ft; @@ -135,8 +144,13 @@ amp = *ampp; xcar = *carp; xmod = *modp; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->XINCODE) { - for (n=0;nampcod) amp = ampp[n]; if (p->carcod) xcar = carp[n]; if (p->modcod) xmod = modp[n]; @@ -166,7 +180,7 @@ mod = cps * *modp; ndx = *p->kndx * mod; minc = (int32)(mod * sicvt); - for (n=0;n>lobits); @@ -188,7 +202,8 @@ return OK; err1: - return csound->PerfError(csound, Str("foscili: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("foscili: not initialised")); } @@ -219,10 +234,10 @@ p->end1 = (int32) (*p->iend1 * (MYFLT) (LOFACT)); if (!p->beg1 && !p->end1) { /* default to looping the whole sample */ - p->end1 = (p->mod1 ? maxphs : ((int32) ftp->flenfrms << LOBITS)); + p->end1 = (p->mod1 ? (int32)maxphs : ((int32) ftp->flenfrms << LOBITS)); } else if (UNLIKELY(p->beg1 < 0 || - p->end1 > maxphs || + p->end1 > (int32)maxphs || p->beg1 >= p->end1)) { csound->Message(csound, "beg: %d, end = %d, maxphs = %d\n", p->beg1, p->end1, maxphs); @@ -238,19 +253,20 @@ p->beg2 = (int32) (*p->ibeg2 * (MYFLT) (LOFACT)); p->end2 = (int32) (*p->iend2 * (MYFLT) (LOFACT)); if (UNLIKELY(p->mod2 < 0 || p->mod2 > 3 || - p->beg2 < 0 || p->end2 > maxphs || p->beg2 >= p->end2)) { + p->beg2 < 0 || p->end2 > (int32)maxphs || + p->beg2 >= p->end2)) { goto lerr3; } } p->beg1 = (p->beg1 >= 0L ? p->beg1 : 0L); - p->end1 = (p->end1 < maxphs ? p->end1 : maxphs); + p->end1 = (p->end1 < (int32)maxphs ? p->end1 : (int32)maxphs); if (UNLIKELY(p->beg1 >= p->end1)) { p->mod1 = 0; p->beg1 = 0L; p->end1 = maxphs; } p->beg2 = (p->beg2 >= 0L ? p->beg2 : 0L); - p->end2 = (p->end2 < maxphs ? p->end2 : maxphs); + p->end2 = (p->end2 < (int32)maxphs ? p->end2 : (int32)maxphs); if (UNLIKELY(p->beg2 >= p->end2)) { p->mod2 = 0; p->beg2 = 0L; @@ -361,18 +377,24 @@ *arR = tmpR; } +/* *********************** needs total rewrite **************** */ int loscil(CSOUND *csound, LOSC *p) { FUNC *ftp; MYFLT *ar1, *ar2, *ftbl, *xamp; int32 phs, inc, beg, end; - int nsmps = csound->ksmps, aamp; + uint32_t n = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + int aamp; + MYFLT xx; ftp = p->ftp; ftbl = ftp->ftable; if ((inc = (int32)(*p->kcps * p->cpscvt)) < 0) inc = -inc; xamp = p->xamp; + xx = *xamp; aamp = (p->XINCODE) ? 1 : 0; if (p->seg1) { /* if still segment 1 */ beg = p->beg1; @@ -386,8 +408,15 @@ } phs = p->lphs; ar1 = p->ar1; + if (UNLIKELY(n)) memset(ar1, '\0', n*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar1[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->stereo) { ar2 = p->ar2; + if (UNLIKELY(n)) memset(ar2, '\0', n*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&ar2[nsmps], '\0', early*sizeof(MYFLT)); goto phsck2; } phschk: @@ -395,53 +424,53 @@ goto put0; switch (p->curmod) { case 0: - do { /* NO LOOPING */ - loscil_linear_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if ((phs += inc) >= end) goto nxtseg; - } while (--nsmps); + } break; case 1: - do { /* NORMAL LOOPING */ - loscil_linear_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg; phs -= end - beg; } - } while (--nsmps); + } break; case 2: case2: - do { /* BIDIR FORW, EVEN */ - loscil_linear_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if ((phs += inc) >= end) { if (!(p->looping)) goto nxtseg; phs -= (phs - end) * 2; p->curmod = 3; - if (--nsmps) goto case3; + if (++nflen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs -= inc) < beg)) { phs += (beg - phs) * 2; p->curmod = 2; - if (--nsmps) goto case2; + if (++nseg1 = 0; if ((p->curmod = p->mod2) != 0) p->looping = 1; - if (--nsmps) { + if (++n>nsmps) { beg = p->beg2; end = p->end2; p->lphs = phs; @@ -457,7 +486,7 @@ } break; } - if (UNLIKELY(--nsmps)) goto phsout; + if (LIKELY(++nlphs = phs; @@ -466,10 +495,7 @@ phsout: p->lphs = phs; put0: - memset(ar1, 0, sizeof(MYFLT)*nsmps); - /* do { */ - /* *ar1++ = FL(0.0); */ - /* } while (--nsmps); */ + memset(&ar1[n], '\0', sizeof(MYFLT)*(nsmps-n)); return OK; phsck2: @@ -477,57 +503,57 @@ goto put0s; /* for STEREO: */ switch (p->curmod) { case 0: - do { /* NO LOOPING */ - loscil_linear_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) goto nxtseg2; - } while (--nsmps); + } break; case 1: - do { /* NORMAL LOOPING */ - loscil_linear_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg2; phs -= end - beg; } - } while (--nsmps); + } break; case 2: case2s: - do { /* BIDIR FORW, EVEN */ - loscil_linear_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg2; phs -= (phs - end) * 2; p->curmod = 3; - if (--nsmps) goto case3s; + if (++nflen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs -= inc) < beg)) { phs += (beg - phs) * 2; p->curmod = 2; - if (--nsmps) goto case2s; + if (++nseg1 = 0; if ((p->curmod = p->mod2) != 0) p->looping = 1; - if (--nsmps) { + if (++nbeg2; end = p->end2; p->lphs = phs; @@ -543,7 +569,7 @@ } break; } - if (UNLIKELY(--nsmps)) goto phsout2; + if (LIKELY(++nlphs = phs; @@ -552,8 +578,8 @@ phsout2: p->lphs = phs; put0s: - memset(ar1, 0, sizeof(MYFLT)*nsmps); - memset(ar2, 0, sizeof(MYFLT)*nsmps); + memset(&ar1[n], '\0', sizeof(MYFLT)*(nsmps-n)); + memset(&ar2[n], '\0', sizeof(MYFLT)*(nsmps-n)); /* do { */ /* *ar1++ = FL(0.0); */ /* *ar2++ = FL(0.0); */ @@ -567,13 +593,18 @@ FUNC *ftp; MYFLT *ar1, *ar2, *ftbl, *xamp; int32 phs, inc, beg, end; - int nsmps = csound->ksmps, aamp; + uint32_t n = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + int aamp; + MYFLT xx; ftp = p->ftp; ftbl = ftp->ftable; if ((inc = (int32)(*p->kcps * p->cpscvt)) < 0) inc = -inc; xamp = p->xamp; + xx = *xamp; aamp = (p->XINCODE) ? 1 : 0; if (p->seg1) { /* if still segment 1 */ beg = p->beg1; @@ -587,8 +618,15 @@ } phs = p->lphs; ar1 = p->ar1; + if (UNLIKELY(n)) memset(ar1, '\0', n*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar1[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->stereo) { ar2 = p->ar2; + if (UNLIKELY(n)) memset(ar1, '\0', n*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&ar2[nsmps], '\0', early*sizeof(MYFLT)); goto phsck2; } phschk: @@ -596,53 +634,53 @@ goto put0; switch (p->curmod) { case 0: - do { /* NO LOOPING */ - loscil_cubic_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs += inc) >= end)) goto nxtseg; - } while (--nsmps); + } break; case 1: - do { /* NORMAL LOOPING */ - loscil_cubic_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg; phs -= end - beg; } - } while (--nsmps); + } break; case 2: case2: - do { /* BIDIR FORW, EVEN */ - loscil_cubic_interp_mono(ar1, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg; phs -= (phs - end) * 2; p->curmod = 3; - if (--nsmps) goto case3; + if (++nflen); - *ar1++ *= *xamp; - if (aamp) xamp++; + for (; nflen);; + if (aamp) xx = xamp[n]; + ar1[n] *= xx; if (UNLIKELY((phs -= inc) < beg)) { phs += (beg - phs) * 2; p->curmod = 2; - if (--nsmps) goto case2; + if (++nlphs = phs; @@ -667,7 +705,7 @@ phsout: p->lphs = phs; put0: - memset(ar1, 0, sizeof(MYFLT)*nsmps); + memset(&ar1[n], 0, sizeof(MYFLT)*(nsmps-n)); /* do { */ /* *ar1++ = FL(0.0); */ /* } while (--nsmps); */ @@ -678,57 +716,57 @@ goto put0s; /* for STEREO: */ switch (p->curmod) { case 0: - do { /* NO LOOPING */ - loscil_cubic_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) goto nxtseg2; - } while (--nsmps); + } break; case 1: - do { /* NORMAL LOOPING */ - loscil_cubic_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg2; phs -= end - beg; } - } while (--nsmps); + } break; case 2: case2s: - do { /* BIDIR FORW, EVEN */ - loscil_cubic_interp_stereo(ar1, ar2, ftbl, phs, ftp->flen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs += inc) >= end)) { if (!(p->looping)) goto nxtseg2; phs -= (phs - end) * 2; p->curmod = 3; - if (--nsmps) goto case3s; + if (++nflen); - *ar1++ *= *xamp; - *ar2++ *= *xamp; - if (aamp) xamp++; + for (; nflen); + if (aamp) xx = xamp[n]; + ar1[n] *= xx; + ar2[n] *= xx; if (UNLIKELY((phs -= inc) < beg)) { phs += (beg - phs) * 2; p->curmod = 2; - if (--nsmps) goto case2s; + if (++nseg1 = 0; if ((p->curmod = p->mod2) != 0) p->looping = 1; - if (--nsmps) { + if (++nbeg2; end = p->end2; p->lphs = phs; @@ -744,7 +782,7 @@ } break; } - if (UNLIKELY(--nsmps)) goto phsout2; + if (LIKELY(++nlphs = phs; @@ -753,8 +791,8 @@ phsout2: p->lphs = phs; put0s: - memset(ar1, 0, sizeof(MYFLT)*nsmps); - memset(ar2, 0, sizeof(MYFLT)*nsmps); + memset(&ar1[n], '\0', sizeof(MYFLT)*(nsmps-n)); + memset(&ar2[n], '\0', sizeof(MYFLT)*(nsmps-n)); /* do { */ /* *ar1++ = FL(0.0); */ /* *ar2++ = FL(0.0); */ @@ -766,7 +804,7 @@ #define ISINSIZ 32768L #define ADMASK 32767L -int adset(CSOUND *csound, ADSYN *p) +static int adset_(CSOUND *csound, ADSYN *p, int stringname) { int32 n; char filnam[MAXNAME]; @@ -781,10 +819,16 @@ for (n = 0; n < ISINSIZ; n++) *ip++ = (int16) (sin(TWOPI * n / ISINSIZ) * 32767.0); } - csound->strarg2name(csound, filnam, p->ifilcod, "adsyn.", p->XSTRCODE); + if(stringname) strncpy(filnam, ((STRINGDAT*)p->ifilcod)->data, MAXNAME-1); + else if (ISSTRCOD(*p->ifilcod)) + strncpy(filnam, get_arg_string(csound, *p->ifilcod), MAXNAME-1); + else csound->strarg2name(csound, filnam, p->ifilcod, "adsyn.", 0); + + if ((mfp = p->mfp) == NULL || strcmp(mfp->filename,filnam) != 0) { /* readfile if reqd */ - if (UNLIKELY((mfp = ldmemfile2(csound, filnam, CSFTYPE_HETRO)) == NULL)) { + if (UNLIKELY((mfp = ldmemfile2withCB(csound, filnam, + CSFTYPE_HETRO, NULL)) == NULL)) { csound->InitError(csound, Str("ADSYN cannot load %s"), filnam); return NOTOK; } @@ -794,7 +838,7 @@ adp = (int16 *) mfp->beginp; /* align on file data */ endata = (int16 *) mfp->endp; size = 1+(*adp == -1 ? MAXPTLS : *adp++); /* Old no header -> MAXPIL */ - if (p->aux.auxp==NULL || p->aux.size < (int32)sizeof(PTLPTR)*size) + if (p->aux.auxp==NULL || p->aux.size < (uint32_t)sizeof(PTLPTR)*size) csound->AuxAlloc(csound, sizeof(PTLPTR)*size, &p->aux); ptlap = ptlfp = (PTLPTR*)p->aux.auxp; /* find base ptl blk */ @@ -834,6 +878,14 @@ return csound->InitError(csound, Str("partial count exceeds MAXPTLS")); } +int adset(CSOUND *csound, ADSYN *p){ + return adset_(csound,p,0); +} + +int adset_S(CSOUND *csound, ADSYN *p){ + return adset_(csound,p,1); +} + #define ADSYN_MAXLONG FL(2147483647.0) int adsyn(CSOUND *csound, ADSYN *p) @@ -842,21 +894,24 @@ DUPLE *ap, *fp; int16 curtim, diff, ktogo; int32 phs, sinc, amp; - int n, nsmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar = p->rslt; MYFLT ampscale, frqscale; int32 timkincr, nxtim; if (UNLIKELY(csound->isintab == NULL)) { /* RWD fix */ - return csound->PerfError(csound, Str("adsyn: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("adsyn: not initialised")); } /* IV - Jul 11 2002 */ ampscale = *p->kamod * csound->e0dbfs; /* since 15-bit sine table */ frqscale = *p->kfmod * ISINSIZ * csound->onedsr; /* 1024 * msecs of analysis */ - timkincr = (int32)(*p->ksmod*FL(1024000.0)*csound->onedkr); - nsmps = csound->ksmps; memset(p->rslt,0,sizeof(MYFLT)*nsmps); + if (UNLIKELY(early)) nsmps -= early; + timkincr = (int32)(*p->ksmod*FL(1024000.0)*CS_ONEDKR); curtim = (int16)(p->mksecs >> 10); /* cvt mksecs to msecs */ curp = (PTLPTR*)p->aux.auxp; /* now for each partial: */ while ((prvp = curp) && (curp = curp->nxtp) != NULL ) { @@ -869,8 +924,8 @@ if ((amp = curp->amp)) { /* for non-zero amp */ sinc = (int32)(curp->frq * frqscale); phs = curp->phs; - nsmps = csound->ksmps; /* addin a sinusoid */ - for (n=0; nisintab[phs]*(MYFLT)amp)/ADSYN_MAXLONG; phs += sinc; phs &= ADMASK; @@ -898,4 +953,3 @@ p->mksecs += timkincr; /* advance the time */ return OK; } - diff -Nru csound-5.17.11~dfsg/OOps/ugens4.c csound-6.02~dfsg/OOps/ugens4.c --- csound-5.17.11~dfsg/OOps/ugens4.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens4.c 2014-01-07 16:54:20.000000000 +0000 @@ -47,9 +47,12 @@ { FUNC *ftp; MYFLT *ar, *ampp, *cpsp, *ftbl; - int32 phs, inc, lobits, dwnphs, tnp1, lenmask, nn; + int32 phs, inc, lobits, dwnphs, tnp1, lenmask; MYFLT sicvt2, over2n, scal, num, denom; - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 nn; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; /* RWD fix */ @@ -59,18 +62,27 @@ lenmask = ftp->lenmask; ampp = p->xamp; cpsp = p->xcps; - if ((n = (int)*p->knh) < 0) n = -n; - if (UNLIKELY(n == 0)) { /* fix n = knh */ - n = 1; + if ((nn = (int)*p->knh) < 0) nn = -nn; + if (UNLIKELY(nn == 0)) { /* fix nn = knh */ + nn = 1; } - tnp1 = (n<<1) + 1; /* calc 2n + 1 */ - over2n = FL(0.5) / (MYFLT)n; + tnp1 = (nn<<1) + 1; /* calc 2n + 1 */ + over2n = FL(0.5) / (MYFLT)nn; scal = *ampp * over2n; inc = (int32)(*cpsp * sicvt2); ar = p->ar; phs = p->lphs; - nn = csound->ksmps; - for (n=0; nampcod) + scal = ampp[n] * over2n; + if (p->cpscod) + inc = (int32)(cpsp[n] * sicvt2); dwnphs = phs >> lobits; denom = ftbl[dwnphs]; if (denom > FL(0.0002) || denom < -FL(0.0002)) { @@ -80,15 +92,11 @@ else ar[n] = *ampp; phs += inc; phs &= PHMASK; - if (p->ampcod) - scal = *++ampp * over2n; - if (p->cpscod) - inc = (int32)(*++cpsp * sicvt2); } p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("buzz: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("buzz: not initialised")); } int gbzset(CSOUND *csound, GBUZZ *p) @@ -134,10 +142,12 @@ { FUNC *ftp; MYFLT *ar, *ampp, *cpsp, *ftbl; - int32 phs, inc, lobits, lenmask, k, km1, kpn, kpnm1, nn; - int32 n; + int32 phs, inc, lobits, lenmask, k, km1, kpn, kpnm1; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT r, absr, num, denom, scal, last = p->last; - int32 lphs = p->lphs; + int32 nn, lphs = p->lphs; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) goto err1; @@ -147,29 +157,37 @@ ampp = p->xamp; cpsp = p->xcps; k = (int32)*p->kk; /* fix k and n */ - if ((n = (int32)*p->kn)<0) n = -n; - if (UNLIKELY(n == 0)) { /* n must be > 0 */ - n = 1; + if ((nn = (int32)*p->kn)<0) nn = -nn; + if (UNLIKELY(nn == 0)) { /* n must be > 0 */ + nn = 1; } km1 = k - 1; - kpn = k + n; + kpn = k + nn; kpnm1 = kpn - 1; - if ((r = *p->kr) != p->prvr || n != p->prvn) { + if ((r = *p->kr) != p->prvr || nn != p->prvn) { p->twor = r + r; p->rsqp1 = r * r + FL(1.0); - p->rtn = intpow1(r, n); + p->rtn = intpow1(r, nn); p->rtnp1 = p->rtn * r; if ((absr = FABS(r)) > FL(0.999) && absr < FL(1.001)) - p->rsumr = FL(1.0) / n; + p->rsumr = FL(1.0) / nn; else p->rsumr = (FL(1.0) - absr) / (FL(1.0) - FABS(p->rtn)); p->prvr = r; - p->prvn = (int16)n; + p->prvn = (int16)nn; } scal = *ampp * p->rsumr; inc = (int32)(*cpsp * csound->sicvt); ar = p->ar; - nn = csound->ksmps; - for (n=0; nampcod) + scal = p->rsumr * ampp[n]; + if (p->cpscod) + inc = (int32)(cpsp[n] * csound->sicvt); phs = lphs >>lobits; denom = p->rsqp1 - p->twor * ftbl[phs]; num = ftbl[phs * k & lenmask] @@ -180,21 +198,17 @@ ar[n] = last = num / denom * scal; } else if (last<0) - ar[n] = last = - *ampp; + ar[n] = last = - (p->ampcod ? ampp[n] : *ampp); else - ar[n] = last = *ampp; - if (p->ampcod) - scal = p->rsumr * *(++ampp); + ar[n] = last = (p->ampcod ? ampp[n] : *ampp); lphs += inc; lphs &= PHMASK; - if (p->cpscod) - inc = (int32)(*(++cpsp) * csound->sicvt); } p->last = last; p->lphs = lphs; return OK; err1: - return csound->PerfError(csound, Str("gbuzz: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("gbuzz: not initialised")); } #define PLUKMIN 64 @@ -225,7 +239,7 @@ if (*p->ifn == 0.0) for (n=npts; n--; ) /* f0: fill w. rands */ *ap++ = (MYFLT) rand16(csound) * DV32768; - else if ((ftp = csound->FTFind(csound, p->ifn)) != NULL) { + else if ((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL) { fp = ftp->ftable; /* else from ftable */ phs = FL(0.0); phsinc = (MYFLT)(ftp->flen/npts); @@ -286,7 +300,9 @@ { MYFLT *ar, *fp; int32 phs256, phsinc, ltwopi, offset; - int n, nsmps = csound->ksmps; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT frac, diff; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD FIX */ @@ -294,8 +310,13 @@ phsinc = (int32)(*p->kcps * p->sicps); phs256 = p->phs256; ltwopi = p->npts << 8; - if (phsinc > ltwopi) goto err2; - for (n=0; n ltwopi)) goto err2; + if (UNLIKELY(koffset)) memset(ar, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=koffset; n> 8; fp = (MYFLT *)p->auxch.auxp + offset; /* lookup position */ diff = fp[1] - fp[0]; @@ -370,9 +391,9 @@ p->phs256 = phs256; return OK; err1: - return csound->PerfError(csound, Str("pluck: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("pluck: not initialised")); err2: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("pluck: kcps more than sample rate")); } @@ -417,7 +438,7 @@ */ #define BIPOLAR 0x7FFFFFFF /* Constant to make bipolar */ -#define RIA 16807 /* multiplier */ +#define RIA (16807) /* multiplier */ #define RIM 0x7FFFFFFFL /* 2**31 - 1 */ #define dv2_31 (FL(4.656612873077392578125e-10)) @@ -492,16 +513,24 @@ int arand(CSOUND *csound, RAND *p) { MYFLT *ar; - int16 rndmul = RNDMUL, n, nn = csound->ksmps; + int16 rndmul = RNDMUL; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT ampscl; MYFLT base = *p->base; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (!p->new) { int16 rand = p->rand; if (!(p->ampcod)) { ampscl = *p->xamp * DV32768; /* IV - Jul 11 2002 */ - for (n=0;nxamp; - for (n=0;nrand; if (!(p->ampcod)) { ampscl = *p->xamp * dv2_31; - for (n=0;nxamp; - for (n=0;nar = *p->base + p->num1 * *p->xamp; /* rslt = num * amp */ - p->phs += (int32)(*p->xcps * csound->kicvt); /* phs += inc */ + p->phs += (long)(*p->xcps * CS_KICVT); /* phs += inc */ + if (p->phs >= MAXLEN) { /* when phs overflows, */ p->phs &= PHMASK; /* mod the phs */ if (!p->new) { @@ -602,23 +632,30 @@ int randh(CSOUND *csound, RANDH *p) { - int32 phs = p->phs, inc; - int n, nn = csound->ksmps; + long phs = p->phs, inc; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *ampp, *cpsp; MYFLT base = *p->base; cpsp = p->xcps; ampp = p->xamp; ar = p->ar; - inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0;nsicvt); + for (n=offset;nnum1 * *ampp; /* rslt = num * amp */ if (p->ampcod) ampp++; phs += inc; /* phs += inc */ if (p->cpscod) - inc = (int32)(*cpsp++ * csound->sicvt); + inc = (long)(*cpsp++ * csound->sicvt); if (phs >= MAXLEN) { /* when phs o'flows, */ phs &= PHMASK; if (!p->new) { @@ -697,7 +734,7 @@ { /* rslt = (num1 + diff*phs) * amp */ /* IV - Jul 11 2002 */ *p->ar = *p->base + (p->num1 + (MYFLT)p->phs * p->dfdmax) * *p->xamp; - p->phs += (int32)(*p->xcps * csound->kicvt); /* phs += inc */ + p->phs += (long)(*p->xcps * CS_KICVT); /* phs += inc */ if (p->phs >= MAXLEN) { /* when phs overflows, */ p->phs &= PHMASK; /* mod the phs */ if (!p->new) { @@ -721,23 +758,30 @@ int randi(CSOUND *csound, RANDI *p) { - int32 phs = p->phs, inc; - int n, nn = csound->ksmps; + long phs = p->phs, inc; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *ampp, *cpsp; MYFLT base = *p->base; cpsp = p->xcps; ampp = p->xamp; ar = p->ar; - inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0;nsicvt); + for (n=offset;nnum1 + (MYFLT)phs * p->dfdmax) * *ampp; if (p->ampcod) ampp++; phs += inc; /* phs += inc */ if (p->cpscod) - inc = (int32)(*cpsp++ * csound->sicvt); /* (nxt inc) */ + inc = (long)(*cpsp++ * csound->sicvt); /* (nxt inc) */ if (phs >= MAXLEN) { /* when phs o'flows, */ phs &= PHMASK; if (!p->new) { @@ -760,4 +804,3 @@ p->phs = phs; return OK; } - diff -Nru csound-5.17.11~dfsg/OOps/ugens5.c csound-6.02~dfsg/OOps/ugens5.c --- csound-5.17.11~dfsg/OOps/ugens5.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens5.c 2014-01-07 16:54:20.000000000 +0000 @@ -24,7 +24,6 @@ #include "csoundCore.h" /* UGENS5.C */ #include "ugens5.h" #include -#include "oload.h" /* * LPC storage slots @@ -32,14 +31,17 @@ #define MAX_LPC_SLOT 20 + int porset(CSOUND *csound, PORT *p) { - p->c2 = pow(0.5, (double)csound->onedkr / *p->ihtim); + p->c2 = pow(0.5, (double)CS_ONEDKR / *p->ihtim); p->c1 = 1.0 - p->c2; if (LIKELY(*p->isig >= FL(0.0))) p->yt1 = (double)(*p->isig); + p->ihtim_old = *p->ihtim; return OK; } +int kporset(CSOUND *csound, PORT *p) { return porset(csound, p); } int port(CSOUND *csound, PORT *p) { @@ -48,6 +50,18 @@ return OK; } +int kport(CSOUND *csound, KPORT *p) +{ + if(p->ihtim_old != *p->ihtim) { + p->c2 = pow(0.5, (double)CS_ONEDKR / *p->ihtim); + p->c1 = 1.0 - p->c2; + p->ihtim_old = *p->ihtim; + } + p->yt1 = p->c1 * (double)*p->ksig + p->c2 * p->yt1; + *p->kr = (MYFLT)p->yt1; + return OK; +} + int tonset(CSOUND *csound, TONE *p) { double b; @@ -61,10 +75,43 @@ return OK; } +int ktonset(CSOUND *csound, TONE *p) { + double b; + p->prvhp = (double)*p->khp; + b = 2.0 - cos((double)(p->prvhp * CS_ONEDKR *TWOPI)); + p->c2 = b - sqrt(b * b - 1.0); + p->c1 = 1.0 - p->c2; + + if (LIKELY(!(*p->istor))) + p->yt1 = 0.0; + return OK; + + } + +int ktone(CSOUND *csound, TONE *p) +{ + double c1 = p->c1, c2 = p->c2; + double yt1 = p->yt1; + + if (*p->khp != (MYFLT)p->prvhp) { + double b; + p->prvhp = (double)*p->khp; + b = 2.0 - cos((double)(p->prvhp * CS_ONEDKR *TWOPI)); + p->c2 = c2 = b - sqrt(b * b - 1.0); + p->c1 = c1 = 1.0 - c2; + } + yt1 = c1 * (double)(*p->asig) + c2 * yt1; + *p->ar = (MYFLT)yt1; + p->yt1 = yt1; + return OK; +} + int tone(CSOUND *csound, TONE *p) { MYFLT *ar, *asig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double c1 = p->c1, c2 = p->c2; double yt1 = p->yt1; @@ -77,7 +124,12 @@ } ar = p->ar; asig = p->asig; - for (n=0; nloop = (int) (*p->ord + FL(0.5))) < 1)) p->loop = 4; if (!*p->istor && (p->aux.auxp == NULL || - (int)(p->loop*sizeof(double)) > p->aux.size)) - csound->AuxAlloc(csound, (int32)(p->loop*sizeof(double)), &p->aux); + (unsigned int)(p->loop*sizeof(double)) > p->aux.size)) + csound->AuxAlloc(csound, (int32)(p->loop*sizeof(double)), &p->aux); p->yt1 = (double*)p->aux.auxp; if (LIKELY(!(*p->istor))) { - memset(p->yt1, 0, p->loop*sizeof(double)); /* Punning zero and 0.0 */ + memset(p->yt1, 0, p->loop*sizeof(double)); /* Punning zero and 0.0 */ } return OK; } int tonex(CSOUND *csound, TONEX *p) /* From Gabriel Maldonado, modified */ { - int j; - int nsmps; - MYFLT *asig, *ar; - double c1, c2, *yt1; + MYFLT *ar = p->ar; + double c2 = p->c2, *yt1 = p->yt1,c1 = p->c1; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j, lp = p->loop; + if (*p->khp != p->prvhp) { double b; p->prvhp = (double)*p->khp; @@ -118,30 +173,52 @@ p->c2 = b - sqrt(b * b - 1.0); p->c1 = 1.0 - p->c2; } - c1 = p->c1; - c2 = p->c2; - yt1= p->yt1; - nsmps = csound->ksmps; - ar = p->ar; - memmove(ar,p->asig,sizeof(MYFLT)*nsmps); - for (j=0; j< p->loop; j++) { - int n; + memmove(ar,p->asig,sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (j=0; j< lp; j++) { + /* Should *yt1 be reset to something?? */ for (n=0; nar; - yt1++; } return OK; } +int katone(CSOUND *csound, TONE *p) +{ + double sig, x; + double c2 = p->c2, yt1 = p->yt1; + + if (*p->khp != p->prvhp) { + double b; + p->prvhp = *p->khp; + b = 2.0 - cos((double)(*p->khp * CS_ONEDKR *TWOPI)); + p->c2 = c2 = b - sqrt(b * b - 1.0); +/* p->c1 = c1 = 1.0 - c2; */ + } + sig = *p->asig; + x = yt1 = c2 * (yt1 + sig); + *p->ar = (MYFLT)x; + yt1 -= sig; /* yt1 contains yt1-xt1 */ + + p->yt1 = yt1; + return OK; +} + + int atone(CSOUND *csound, TONE *p) { MYFLT *ar, *asig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double c2 = p->c2, yt1 = p->yt1; if (*p->khp != p->prvhp) { @@ -152,8 +229,13 @@ /* p->c1 = c1 = 1.0 - c2; */ } ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->asig; - for (n=0; nar; double c2 = p->c2, *yt1 = p->yt1; - int n, nsmps=csound->ksmps, j; - int lp = p->loop; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j, lp = p->loop; if (*p->khp != p->prvhp) { double b; @@ -179,8 +263,13 @@ } memmove(ar,p->asig,sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } for (j=1; jksmps; - MYFLT *ar, *asig; + uint32_t flag = 0; double c3p1, c3t4, omc3, c2sqr; - double yt1, yt2, c1 = p->c1, c2 = p->c2, c3 = p->c3; + double yt0, yt1, yt2, c1 = p->c1, c2 = p->c2, c3 = p->c3; + IGN(csound); if (*p->kcf != (MYFLT)p->prvcf) { p->prvcf = (double)*p->kcf; - p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + p->cosf = cos(p->prvcf * (double)(CS_ONEDKR *TWOPI)); flag = 1; /* Mark as changed */ } if (*p->kbw != (MYFLT)p->prvbw) { p->prvbw = (double)*p->kbw; - c3 = p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + c3 = p->c3 = exp(p->prvbw * (double)(-CS_ONEDKR *TWOPI)); flag = 1; /* Mark as changed */ } if (flag) { @@ -233,11 +324,60 @@ c1 = p->c1 = sqrt((c3p1*c3p1-c2sqr) * omc3/c3p1); else c1 = p->c1 = 1.0; } + + yt1 = p->yt1; yt2 = p->yt2; + yt0 = c1 * ((double)*p->asig) + c2 * yt1 - c3 * yt2; + *p->ar = (MYFLT)yt0; + p->yt1 = yt0; p->yt2 = yt1; /* Write back for next cycle */ + return OK; +} + + +int reson(CSOUND *csound, RESON *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag = 0, n, nsmps = CS_KSMPS; + MYFLT *ar, *asig; + double c3p1, c3t4, omc3, c2sqr; + double yt1, yt2, c1 = p->c1, c2 = p->c2, c3 = p->c3; + asig = p->asig; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } yt1 = p->yt1; yt2 = p->yt2; - for (n=0; nkcf[n] : *p->kcf; + MYFLT bw = XINARG3 ? p->kbw[n] : *p->kbw; + if (cf != (MYFLT)p->prvcf) { + p->prvcf = (double)cf; + p->cosf = cos(cf * (double)(csound->tpidsr)); + flag = 1; /* Mark as changed */ + } + if (bw != (MYFLT)p->prvbw) { + p->prvbw = (double)bw; + c3 = p->c3 = exp(bw * (double)(csound->mtpdsr)); + flag = 1; /* Mark as changed */ + } + if (flag) { + c3p1 = c3 + 1.0; + c3t4 = c3 * 4.0; + omc3 = 1.0 - c3; + c2 = p->c2 = c3t4 * p->cosf / c3p1; /* -B, so + below */ + c2sqr = c2 * c2; + if (p->scale == 1) + c1 = p->c1 = omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) + c1 = p->c1 = sqrt((c3p1*c3p1-c2sqr) * omc3/c3p1); + else c1 = p->c1 = 1.0; + flag = 0; + } + yt0 = c1 * ((double)asig[n]) + c2 * yt1 - c3 * yt2; ar[n] = (MYFLT)yt0; yt2 = yt1; yt1 = yt0; @@ -253,7 +393,7 @@ if ((p->loop = (int) (*p->ord + FL(0.5))) < 1) p->loop = 4; /* default value */ if (!*p->istor && (p->aux.auxp == NULL || - (int)(p->loop*2*sizeof(double)) > p->aux.size)) + (unsigned int)(p->loop*2*sizeof(double)) > p->aux.size)) csound->AuxAlloc(csound, (int32)(p->loop*2*sizeof(double)), &p->aux); p->yt1 = (double*)p->aux.auxp; p->yt2 = (double*)p->aux.auxp + p->loop; if (UNLIKELY(scale && scale != 1 && scale != 2)) { @@ -271,60 +411,122 @@ int resonx(CSOUND *csound, RESONX *p) /* Gabriel Maldonado, modified */ { - int flag = 0, nsmps = csound->ksmps, j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag = 0, n, nsmps = CS_KSMPS; + int j; MYFLT *ar; double c3p1, c3t4, omc3, c2sqr; double *yt1, *yt2, c1,c2,c3; + ar = p->ar; + c1 = p->c1; + c2 = p->c2; + c3 = p->c3; + yt1 = p->yt1; + yt2 = p->yt2; + ar = p->ar; + memmove(ar,p->asig,sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (j=0; j< p->loop; j++) { + for (n=offset; nkcf[n] : *p->kcf; + MYFLT bw = XINARG3 ? p->kbw[n] : *p->kbw; + if (cf != (MYFLT)p->prvcf) { + p->prvcf = (double)cf; + p->cosf = cos(cf * (double)(csound->tpidsr)); + flag = 1; + } + if (bw != (MYFLT)p->prvbw) { + p->prvbw = (double)bw; + c3 = exp(bw * (double)(csound->mtpdsr)); + flag = 1; + } + if (flag) { + c3p1 = c3 + 1.0; + c3t4 = c3 * 4.0; + omc3 = 1.0 - c3; + c2 = c3t4 * p->cosf / c3p1; /* -B, so + below */ + c2sqr = c2 * c2; + if (p->scale == 1) + c1 = omc3 * sqrt(1.0 - (c2sqr / c3t4)); + else if (p->scale == 2) + c1 = sqrt((c3p1*c3p1-c2sqr) * omc3/c3p1); + else c1 = 1.0; + flag =0; + } + x = c1 * ((double)ar[n]) + c2 * yt1[j] - c3 * yt2[j]; + yt2[j] = yt1[j]; + ar[n] = (MYFLT)x; + yt1[j] = x; + } + } + p->c1 = c1; p->c2 = c2; p->c3 = c3; + return OK; +} + +int kareson(CSOUND *csound, RESON *p) +{ + uint32_t flag = 0; + double c3p1, c3t4, omc3, c2sqr; //, D = 2.0; /* 1/RMS = root2 (rand) */ + /* or 1/.5 (sine) */ + double yt1, yt2, c1, c2, c3; + IGN(csound); + if (*p->kcf != (MYFLT)p->prvcf) { p->prvcf = (double)*p->kcf; - p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + p->cosf = cos(p->prvcf * (double)(CS_ONEDKR *TWOPI)); flag = 1; } if (*p->kbw != (MYFLT)p->prvbw) { p->prvbw = (double)*p->kbw; - p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + p->c3 = exp(p->prvbw * (double)(-CS_ONEDKR *TWOPI)); flag = 1; } if (flag) { c3p1 = p->c3 + 1.0; c3t4 = p->c3 * 4.0; omc3 = 1.0 - p->c3; - p->c2 = c3t4 * p->cosf / c3p1; /* -B, so + below */ + p->c2 = c3t4 * p->cosf / c3p1; c2sqr = p->c2 * p->c2; - if (p->scale == 1) - p->c1 = omc3 * sqrt(1.0 - (c2sqr / c3t4)); - else if (p->scale == 2) - p->c1 = sqrt((c3p1*c3p1-c2sqr) * omc3/c3p1); - else p->c1 = 1.0; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ } - ar = p->ar; - c1 = p->c1; - c2 = p->c2; - c3 = p->c3; - yt1 = p->yt1; - yt2 = p->yt2; - ar = p->ar; - memmove(ar,p->asig,sizeof(MYFLT)*nsmps); - for (j=0; j< p->loop; j++) { - int n; - for (n=0; nc1; c2 = p->c2; c3 = p->c3; yt1 = p->yt1; yt2 = p->yt2; + if (p->scale == 1 || p->scale == 0) { + double sig = (double) *p->asig; + double ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - sig; /* yt1 contains yt1-xt1 */ + *p->ar = (MYFLT)ans; } + else if (p->scale == 2) { + double sig = (double) *p->asig; + double ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - 2.0 * sig; /* yt1 contains yt1-D*xt1 */ + *p->ar = (MYFLT)ans; + } + p->yt1 = yt1; p->yt2 = yt2; return OK; } int areson(CSOUND *csound, RESON *p) { - int flag = 0, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag = 0, n, nsmps = CS_KSMPS; MYFLT *ar, *asig; - double c3p1, c3t4, omc3, c2sqr, D = 2.0; /* 1/RMS = root2 (rand) */ + double c3p1, c3t4, omc3, c2sqr;//, D = 2.0; /* 1/RMS = root2 (rand) */ /* or 1/.5 (sine) */ double yt1, yt2, c1, c2, c3; @@ -347,15 +549,19 @@ if (p->scale == 1) /* i.e. 1 - A(reson) */ p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); else if (p->scale == 2) /* i.e. D - A(reson) */ - p->c1 = D - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); else p->c1 = 0.0; /* cannot tell */ } asig = p->asig; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } c1 = p->c1; c2 = p->c2; c3 = p->c3; yt1 = p->yt1; yt2 = p->yt2; if (p->scale == 1 || p->scale == 0) { - int n; - for (n=0; nscale == 2) { - int n; - for (n=0; nlprdaddr)[csound->currentLPCSlot] = p; /* Build file name */ - csound->strarg2name(csound, lpfilname, p->ifilno, "lp.", p->XSTRCODE); + if (stringname) strncpy(lpfilname, ((STRINGDAT*)p->ifilcod)->data, MAXNAME-1); + else if (ISSTRCOD(*p->ifilcod)) + strncpy(lpfilname, get_arg_string(csound, *p->ifilcod), MAXNAME-1); + else csound->strarg2name(csound, lpfilname, p->ifilcod, "lp.", 0); /* Do not reload existing file ? */ if (UNLIKELY((mfp = p->mfp) != NULL && strcmp(mfp->filename, lpfilname) == 0)) goto lpend; /* rtn if file prv known */ /* Load analysis in memory file */ /* else read file */ - if (UNLIKELY((mfp = ldmemfile2(csound, lpfilname, CSFTYPE_LPC)) == NULL)) { + if (UNLIKELY((mfp = ldmemfile2withCB(csound, lpfilname, CSFTYPE_LPC, NULL)) + == NULL)) { return csound->InitError(csound, Str("LPREAD cannot load %s"), lpfilname); } /* Store memory file location in opcode */ @@ -470,9 +679,18 @@ return OK; } +int lprdset(CSOUND *csound, LPREAD *p){ + return lprdset_(csound, p, 0); +} + +int lprdset_S(CSOUND *csound, LPREAD *p){ + return lprdset_(csound, p, 1); +} + + #ifdef TRACE_POLES static void - DumpPolesF(int poleCount, MYFLT *part1, MYFLT *part2, int isMagn, char *where) + DumpPolesF(int poleCount, MYFLT *part1, MYFLT *part2, int isMagn, char *where) { int i; @@ -537,7 +755,7 @@ int i; if (UNLIKELY(poleCount%2!=0)) { -/* printf (Str("Cannot handle uneven pole count yet \n")); */ + printf (Str("Cannot handle uneven pole count yet \n")); return (0); } @@ -649,12 +867,14 @@ MYFLT interMagn[MAXPOLES], interPhas[MAXPOLES]; if (UNLIKELY(p->mfp==NULL)) { - return csound->PerfError(csound, Str("lpread: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("lpread: not initialised")); } /* Locate frame position range */ if (UNLIKELY((framphase = (int32)(*p->ktimpt*p->framrat16)) < 0)) { /* for kfram reqd*/ - return csound->PerfError(csound, Str("lpread timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, + Str("lpread timpnt < 0")); } if (framphase > p->lastfram16) { /* not past last one */ framphase = p->lastfram16; @@ -690,7 +910,8 @@ DoPoleInterpolation(p->npoles,poleMagn1,polePhas1,poleMagn2, polePhas2,fract,interMagn,interPhas); if (UNLIKELY(!status)) { - return csound->PerfError(csound, Str("Interpolation failed")); + return csound->PerfError(csound, p->h.insdshead, + Str("Interpolation failed")); } for (i=0; inpoles; i++) { *cp++ = interMagn[i]; @@ -747,8 +968,9 @@ } } else { - csound->PerfError(csound, Str("this opcode only works with LPC " - "pole analysis type (-a)\n")); + csound->PerfError(csound, p->h.insdshead, + Str("this opcode only works with LPC " + "pole analysis type (-a)\n")); return NOTOK; } @@ -756,7 +978,7 @@ if (bws[j] > sr/2 || isnan(bws[j])) bws[j] = sr/2; if (bws[j] < 1.0) bws[j] = 1.0; if (cfs[j] > sr/2 || isnan(cfs[j])) cfs[j] = sr/2; - if (cfs[j] < 0) cfs[j] = -cfs[j]; + cfs[j] = FABS(cfs[j]); *p->kcf = cfs[j]; *p->kbw = bws[j]; @@ -793,12 +1015,14 @@ int lpreson(CSOUND *csound, LPRESON *p) { LPREAD *q = p->lpread; - int nn, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *coefp, *pastp, *jp, *jp2, *rslt = p->ar, *asig = p->asig; MYFLT x; double poleReal[MAXPOLES], poleImag[MAXPOLES]; double polyReal[MAXPOLES+1], polyImag[MAXPOLES+1]; - int i; + int i, nn; double pm,pp; jp = p->circjp; @@ -828,14 +1052,19 @@ } } + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } /* For each sample */ - do { + for (n=offset; nMessage(csound, "Asig=%f\n", *asig); #endif - x = *asig++; + x = asig[n]; coefp = q->kcoefs; /* using lpread interp coefs */ pastp = jp; nn = q->npoles; @@ -851,14 +1080,14 @@ /* Store result signal in circular and output buffers */ *jp++ = *jp2++ = x; - *rslt++ = x; + rslt[n] = x; /* Check if end of buffer reached */ if (jp2 >= p->jp2lim) { jp2 = jp; jp = p->circbuf; } - } while (--nsmps); + } p->circjp = jp; return OK; } @@ -892,13 +1121,16 @@ int lpfreson(CSOUND *csound, LPFRESON *p) { LPREAD *q = p->lpread; - int nn, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, n, nsmps = CS_KSMPS; MYFLT *coefp, *pastp, *pastp1, *rslt = p->ar, *asig = p->asig; MYFLT x, temp1, temp2, ampscale, cq; if (*p->kfrqratio != p->prvratio) { /* for new freqratio */ if (*p->kfrqratio <= FL(0.0)) { - return csound->PerfError(csound, Str("illegal frqratio, %5.2f"), + return csound->PerfError(csound, p->h.insdshead, + Str("illegal frqratio, %5.2f"), *p->kfrqratio); } /* calculate d */ p->d = (*p->kfrqratio - FL(1.0)) / (*p->kfrqratio + FL(1.0)); @@ -920,7 +1152,12 @@ ampscale = FL(1.0); } x = p->prvout; - do { + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nnpoles - 1; pastp = pastp1 = p->past + nn; temp1 = *pastp; @@ -932,14 +1169,15 @@ pastp--; pastp1--; temp1 = temp2; } while (--nn); - x = *asig++; + x = asig[n]; pastp = p->past; coefp = q->kcoefs; nn = q->npoles; - do x += *coefp++ * *pastp++; - while (--nn); - *rslt++ = x * ampscale; - } while (--nsmps); + do { + x += *coefp++ * *pastp++; + } while (--nn); + rslt[n] = x * ampscale; + } p->prvout = x; return OK; } @@ -982,14 +1220,17 @@ int rms(CSOUND *csound, RMS *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *asig; double q; double c1 = p->c1, c2 = p->c2; q = p->prvq; asig = p->asig; - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *asig; double q, a, m, diff, inc; double c1 = p->c1, c2 = p->c2; - int n; q = p->prvq; asig = p->asig; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(early)) nsmps -= early; + for (n = offset; n < nsmps-early; n++) { double as = (double)asig[n]; q = c1 * as * as + c2 * q; } @@ -1018,17 +1261,22 @@ else a = *p->krms; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if ((diff = a - p->prva) != 0.0) { m = p->prva; - inc = diff * (double)csound->onedksmps; - for (n = 0; n < nsmps; n++) { + inc = diff / (double)(nsmps-offset); + for (n = offset; n < nsmps; n++) { ar[n] = asig[n] * m; m += inc; } p->prva = a; } else { - for (n = 0; n < nsmps; n++) { + for (n = offset; n < nsmps; n++) { ar[n] = asig[n] * a; } } @@ -1037,7 +1285,9 @@ int balance(CSOUND *csound, BALANCE *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *asig, *csig; double q, r, a, m, diff, inc; double c1 = p->c1, c2 = p->c2; @@ -1046,7 +1296,13 @@ r = p->prvr; asig = p->asig; csig = p->csig; - for (n = 0; n < nsmps; n++) { + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { double as = (double)asig[n]; double cs = (double)csig[n]; q = c1 * as * as + c2 * q; @@ -1058,18 +1314,17 @@ a = sqrt(r/q); else a = sqrt(r); - ar = p->ar; if ((diff = a - p->prva) != 0.0) { m = p->prva; - inc = diff * (double)csound->onedksmps; - for (n = 0; n < nsmps; n++) { + inc = diff / (double)(nsmps-offset); + for (n = offset; n < nsmps; n++) { ar[n] = asig[n] * m; m += inc; } p->prva = a; } else { - for (n = 0; n < nsmps; n++) { + for (n = offset; n < nsmps; n++) { ar[n] = asig[n] * a; } } @@ -1142,7 +1397,8 @@ /* RWD: guessing this... */ if (UNLIKELY(p->lp1==NULL || p->lp2==NULL)) { - return csound->PerfError(csound, Str("lpinterpol: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("lpinterpol: not initialised")); } cp1 = p->lp1->kcoefs; cp2 = p->lp2->kcoefs; @@ -1157,7 +1413,8 @@ status = DoPoleInterpolation(p->npoles,poleMagn1,polePhas1,poleMagn2, polePhas2,*p->kmix,interMagn,interPhas); if (UNLIKELY(!status)) { - return csound->PerfError(csound, Str("Interpolation failed")); + return csound->PerfError(csound, p->h.insdshead, + Str("Interpolation failed")); } cp = p->kcoefs; /* This is where the coefs get stored */ @@ -1168,3 +1425,59 @@ return OK; } + +int klimit(CSOUND *csound, LIMIT *p) +{ + MYFLT sig=*p->sig, min=*p->min, max=*p->max; + if (LIKELY((sig <= max) && (sig >= min))) { + *p->ans = sig; + } + else { + if ( min >= max) { + *p->ans = FL(0.5) * (min + max); + } + else { + if (sig > max) + *p->ans = max; + else + *p->ans = min; + } + } + return OK; +} + +int limit(CSOUND *csound, LIMIT *p) +{ + MYFLT *ans, *asig; + MYFLT min=*p->min, max=*p->max, aver; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + ans = p->ans; + asig = p->sig; + + if (UNLIKELY(offset)) memset(ans, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ans[nsmps], '\0', early*sizeof(MYFLT)); + } + if (min >= max) { + aver = (min + max) * FL(0.5); + for (n=offset; n= min)) { + ans[n] = asig[n]; + } + else { + if (asig[n] > max) + ans[n] = max; + else + ans[n] = min; + } + } + return OK; +} diff -Nru csound-5.17.11~dfsg/OOps/ugens6.c csound-6.02~dfsg/OOps/ugens6.c --- csound-5.17.11~dfsg/OOps/ugens6.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugens6.c 2014-01-07 16:54:20.000000000 +0000 @@ -30,7 +30,7 @@ int downset(CSOUND *csound, DOWNSAMP *p) { - if (UNLIKELY((p->len = (int)*p->ilen) > csound->ksmps)) + if (UNLIKELY((p->len = (unsigned int)*p->ilen) > CS_KSMPS)) return csound->InitError(csound, "ilen > ksmps"); return OK; } @@ -38,15 +38,18 @@ int downsamp(CSOUND *csound, DOWNSAMP *p) { MYFLT *asig, sum; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; int len, n; if (p->len <= 1) - *p->kr = *p->asig; + *p->kr = p->asig[offset]; else { asig = p->asig; sum = FL(0.0); len = p->len; - for (n=0; n(int)(CS_KSMPS-early)) len = early; + for (n=offset; nkr = sum / p->len; @@ -58,9 +61,16 @@ { MYFLT kval = *p->ksig; MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) ar[n] = kval; return OK; } @@ -84,16 +94,23 @@ int interp(CSOUND *csound, INTERP *p) { MYFLT *ar, val, incr; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ar = p->rslt; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->init_k) { p->init_k = 0; p->prev = *p->xsig; } val = p->prev; - incr = (*p->xsig - val) * csound->onedksmps; - for (n=0; nxsig - val) / (nsmps-offset); + for (n=offset; nprev = val; @@ -116,12 +133,19 @@ int integrate(CSOUND *csound, INDIFF *p) { MYFLT *rslt, *asig, sum; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; rslt = p->rslt; + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->xsig; sum = p->prev; - for (n=0; nprev = sum; @@ -140,12 +164,19 @@ int diff(CSOUND *csound, INDIFF *p) { MYFLT *ar, *asig, prev, tmp; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ar = p->rslt; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->xsig; prev = p->prev; - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; ar = p->xr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->xsig; state = p->state; if (p->audiogate) { agate = p->xgate; - for (n=0; n FL(0.0)) state = asig[n]; ar[n] = state; @@ -188,12 +226,12 @@ } else { if (*p->xgate > FL(0.0)) { - for (n=0; nXOUTCODE != 1)) @@ -252,7 +290,7 @@ if (UNLIKELY(*p->istor != FL(0.0) && p->auxch.auxp != NULL)) return OK; /* ksmps is min dely */ - if (UNLIKELY((npts=(int32)(FL(0.5) + *p->idlt*csound->esr)) < csound->ksmps)) { + if (UNLIKELY((npts=(uint32_t)(FL(0.5) + *p->idlt*csound->esr)) < CS_KSMPS)) { return csound->InitError(csound, Str("illegal delay time")); } if ((auxp = (MYFLT*)p->auxch.auxp) == NULL || /* new space if reqd */ @@ -322,15 +360,25 @@ int delay(CSOUND *csound, DELAY *p) { MYFLT *ar, *asig, *curp, *endp; - int n, nsmps = csound->ksmps; - + uint32_t offset = 0; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ ar = p->ar; + if (csound->oparms->sampleAccurate) { + uint32_t early = p->h.insdshead->ksmps_no_end; + offset = p->h.insdshead->ksmps_offset; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + } asig = p->asig; curp = p->curp; endp = (MYFLT *) p->auxch.endp; - for (n=0; nPerfError(csound, Str("delay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("delay: not initialised")); } int delayr(CSOUND *csound, DELAYR *p) { MYFLT *ar, *curp, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } curp = p->curp; endp = (MYFLT *) p->auxch.endp; - for (n=0; n= endp)) curp = (MYFLT *) p->auxch.auxp; } return OK; err1: - return csound->PerfError(csound, Str("delayr: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("delayr: not initialised")); } int delayw(CSOUND *csound, DELAYW *p) { DELAYR *q = p->delayr; MYFLT *asig, *curp, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(q->auxch.auxp==NULL)) goto err1; /* RWD fix */ asig = p->asig; curp = q->curp; endp = (MYFLT *) q->auxch.endp; - for (n=0; n= endp)) curp = (MYFLT *) q->auxch.auxp; @@ -381,50 +441,67 @@ q->curp = curp; /* now sav new curp */ return OK; err1: - return csound->PerfError(csound, Str("delayw: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("delayw: not initialised")); } int deltap(CSOUND *csound, DELTAP *p) { DELAYR *q = p->delayr; MYFLT *ar, *tap, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(q->auxch.auxp==NULL)) goto err1; /* RWD fix */ ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } tap = q->curp - (int32) (FL(0.5) + *p->xdlt * csound->esr); while (tap < (MYFLT *) q->auxch.auxp) tap += q->npts; endp = (MYFLT *) q->auxch.endp; - for (n=0; n= endp)) tap -= q->npts; ar[n] = *tap++; } return OK; err1: - return csound->PerfError(csound, Str("deltap: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltap: not initialised")); } int deltapi(CSOUND *csound, DELTAP *p) { DELAYR *q = p->delayr; MYFLT *ar, *tap, *prv, *begp, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 idelsmps; MYFLT delsmps, delfrac; if (UNLIKELY(q->auxch.auxp==NULL)) goto err1; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } begp = (MYFLT *) q->auxch.auxp; endp = (MYFLT *) q->auxch.endp; if (!p->XINCODE) { + if(*p->xdlt == INFINITY) goto err2; delsmps = *p->xdlt * csound->esr; idelsmps = (int32)delsmps; delfrac = delsmps - idelsmps; tap = q->curp - idelsmps; while (tap < begp) tap += q->npts; - for (n=0; n= endp)) tap -= q->npts; if (UNLIKELY((prv = tap - 1) < begp)) @@ -435,7 +512,8 @@ } else { MYFLT *timp = p->xdlt, *curq = q->curp; - for (n=0; nesr; idelsmps = (int32)delsmps; delfrac = delsmps - idelsmps; @@ -450,7 +528,11 @@ } return OK; err1: - return csound->PerfError(csound, Str("deltapi: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltapi: not initialised")); + err2: + return csound->PerfError(csound, p->h.insdshead, + Str("deltapi: INF delaytime")); } /* ***** From Hans Mikelson ************* */ @@ -459,12 +541,19 @@ { DELAYR *q = p->delayr; MYFLT *ar, *tap, *begp, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 idelsmps; MYFLT delsmps; if (UNLIKELY(q->auxch.auxp==NULL)) goto err1; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } begp = (MYFLT *) q->auxch.auxp; endp = (MYFLT *) q->auxch.endp; if (!p->XINCODE) { @@ -472,7 +561,7 @@ idelsmps = (int32)delsmps; tap = q->curp - idelsmps; while (tap < begp) tap += q->npts; - for (n=0; n= endp )) tap -= q->npts; if (UNLIKELY(tap < begp)) @@ -483,7 +572,7 @@ } else { MYFLT *timp = p->xdlt, *curq = q->curp; - for (n=0; nPerfError(csound, Str("deltapn: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltapn: not initialised")); } /* **** JPff **** */ @@ -503,21 +593,29 @@ { DELAYR *q = p->delayr; MYFLT *ar, *tap, *prv, *begp, *endp; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 idelsmps; MYFLT delsmps, delfrac; if (UNLIKELY(q->auxch.auxp==NULL)) goto err1; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } begp = (MYFLT *) q->auxch.auxp; endp = (MYFLT *) q->auxch.endp; if (!p->XINCODE) { + if(*p->xdlt == INFINITY) goto err2; delsmps = *p->xdlt * csound->esr; idelsmps = (int32)delsmps; delfrac = delsmps - idelsmps; tap = q->curp - idelsmps; while (tap < begp) tap += q->npts; - for (n=0; n= endp)) tap -= q->npts; @@ -544,8 +642,9 @@ } else { MYFLT *timp = p->xdlt, *curq = q->curp; - for (n=0; nesr; idelsmps = (int32)delsmps; delfrac = delsmps - idelsmps; @@ -571,7 +670,12 @@ } return OK; err1: - return csound->PerfError(csound, Str("deltap3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltap3: not initialised")); + err2: + return csound->PerfError(csound, p->h.insdshead, + Str("deltapi: INF delaytime")); + } @@ -596,11 +700,18 @@ { DELAYR *q = p->delayr; MYFLT *out1, *del, *buf1, *bufp, *bufend; - int nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 indx, maxd, xpos; if (UNLIKELY(q->auxch.auxp == NULL)) goto err1; /* RWD fix */ out1 = p->ar; del = p->adlt; + if (UNLIKELY(offset)) memset(out1, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + } buf1 = (MYFLT *) q->auxch.auxp; indx = (int32) (q->curp - buf1); maxd = q->npts; bufend = buf1 + maxd; @@ -611,7 +722,7 @@ i2 = (p->wsize >> 1); /* wsize = 4: d2x = 1 - 1/3, wsize = 64: d2x = 1 - 1/36 */ d2x = p->d2x; - do { + for (n=offset; n= bufend)) bufp = buf1; n1 -= w * w * (double)*bufp / d; d++; } while (--i); - *out1 = (MYFLT)(n1 * sin(PI * x1) / PI); + out1[n] = (MYFLT)(n1 * sin(PI * x1) / PI); } else { /* integer sample */ xpos = (int32) ((double)xpos + x1 + 0.5); /* position */ if (xpos >= maxd) xpos -= maxd; - *out1 = buf1[xpos]; + out1[n] = buf1[xpos]; } - out1++; indx++; - } while (--nn); + indx++; + } } else { /* window size = 4, cubic interpolation */ double x, am1, a0, a1, a2; - do { + for (n=offset; nesr; while (am1 < 0.0) am1 += (double)maxd; xpos = (int32) am1; am1 -= (double)xpos; @@ -665,23 +776,27 @@ x += a1 * (double)*bufp; if (UNLIKELY(++bufp >= bufend)) bufp = buf1; x += a2 * (double)*bufp; - indx++; *out1++ = (MYFLT)x; - } while (--nn); + indx++; out1[n] = (MYFLT)x; + } } return OK; err1: - return csound->PerfError(csound, Str("deltap: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltap: not initialised")); } int deltapxw(CSOUND *csound, DELTAPX *p) /* deltapxw opcode */ { DELAYR *q = p->delayr; MYFLT *in1, *del, *buf1, *bufp, *bufend; - int nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 indx, maxd, xpos; if (UNLIKELY(q->auxch.auxp == NULL)) goto err1; /* RWD fix */ in1 = p->ar; del = p->adlt; + if (UNLIKELY(early)) nsmps -= early; buf1 = (MYFLT *) q->auxch.auxp; indx = (int32) (q->curp - buf1); maxd = q->npts; bufend = buf1 + maxd; @@ -692,7 +807,7 @@ i2 = (p->wsize >> 1); /* wsize = 4: d2x = 1 - 1/3, wsize = 64: d2x = 1 - 1/36 */ d2x = p->d2x; - do { + for (n=offset; n= maxd)) xpos -= maxd; - buf1[xpos] += *in1; + buf1[xpos] += in1[n]; } - in1++; indx++; - } while (--nn); + indx++; + } } else { /* window size = 4, cubic interpolation */ double x, am1, a0, a1, a2; - do { + for (n=offset; nesr; while (am1 < 0.0) am1 += (double)maxd; xpos = (int32) am1; am1 -= (double)xpos; @@ -738,7 +853,7 @@ am1 = 0.5 * (a0 - am1) - a2; /* sample -1 */ a0 = 3.0 * a2 - a0; a0++; /* sample 0 */ - x = (double)*(in1++); + x = (double)in1[n]; bufp = (xpos ? (buf1 + (xpos - 1L)) : (bufend - 1)); while (bufp >= bufend) bufp -= maxd; *bufp += (MYFLT)(am1 * x); if (UNLIKELY(++bufp >= bufend)) bufp = buf1; @@ -747,11 +862,12 @@ *bufp += (MYFLT)(a2 * x); indx++; - } while (--nn); + } } return OK; err1: - return csound->PerfError(csound, Str("deltap: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("deltap: not initialised")); } int del1set(CSOUND *csound, DELAY1 *p) @@ -764,13 +880,20 @@ int delay1(CSOUND *csound, DELAY1 *p) { MYFLT *ar, *asig; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; ar = p->ar; /* asig = p->asig - 1; */ asig = p->asig; - ar[0] = p->sav1; - memmove(&ar[1], asig, sizeof(MYFLT)*(nsmps-1)); + ar[offset] = p->sav1; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + memmove(&ar[offset+1], &asig[offset], sizeof(MYFLT)*(nsmps-1-offset)); p->sav1 = asig[nsmps-1]; return OK; } @@ -788,7 +911,7 @@ return csound->InitError(csound, Str("illegal loop time")); } nbytes = lpsiz * sizeof(MYFLT); - if (p->auxch.auxp == NULL || nbytes != p->auxch.size) { + if (p->auxch.auxp == NULL || (uint32_t)nbytes != p->auxch.size) { csound->AuxAlloc(csound, (int32)nbytes, &p->auxch); p->pntr = (MYFLT *) p->auxch.auxp; p->prvt = FL(0.0); @@ -806,7 +929,9 @@ int comb(CSOUND *csound, COMB *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *asig, *xp, *endp; MYFLT coef = p->coef; @@ -828,10 +953,14 @@ xp = p->pntr; endp = (MYFLT *) p->auxch.endp; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->asig; - MYFLT out; - for (n=0; npntr = xp; return OK; err1: - return csound->PerfError(csound, Str("comb: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("comb: not initialised")); } -int alpass(CSOUND *csound, COMB *p) +int invcomb(CSOUND *csound, COMB *p) { int n, nsmps = csound->ksmps; MYFLT *ar, *asig, *xp, *endp; + MYFLT coef = p->coef; + + if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ + if (p->prvt != *p->krvt) { + p->prvt = *p->krvt; + /* + * The argument to exp() in the following is sometimes a small + * enough negative number to result in a denormal (or worse) + * on Alpha. So if the result would be less than 1.0e-16, we + * just say it is zero and do not call exp(). heh 981101 + */ + double exp_arg = (double)(log001 * *p->ilpt / p->prvt); + if (UNLIKELY(exp_arg < -36.8413615)) /* ln(1.0e-16) */ + coef = p->coef = FL(0.0); + else + coef = p->coef = (MYFLT)exp(exp_arg); + } + xp = p->pntr; + endp = (MYFLT *) p->auxch.endp; + ar = p->ar; + asig = p->asig; + MYFLT out; + for (n=0; n= endp)) + xp = (MYFLT *) p->auxch.auxp; + } + p->pntr = xp; + return OK; + err1: + return csound->PerfError(csound, p->h.insdshead, + Str("combinv: not initialised")); +} + +int alpass(CSOUND *csound, COMB *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *ar, *asig, *xp, *endp; MYFLT y, z; MYFLT coef = p->coef; @@ -859,8 +1030,13 @@ xp = p->pntr; endp = (MYFLT *) p->auxch.endp; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->asig; - for (n=0; npntr = xp; return OK; err1: - return csound->PerfError(csound, Str("alpass: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("alpass: not initialised")); } static const MYFLT revlptimes[6] = {FL(0.0297), FL(0.0371), FL(0.0411), @@ -903,7 +1080,7 @@ p->adr5 = p->p5 = p->adr4 + *sizp++; p->adr6 = p->p6 = p->adr5 + *sizp++; if (UNLIKELY(p->adr6 + *sizp != (MYFLT *) p->auxch.endp)) { - csound->Die(csound, Str("revlpsiz inconsistent\n")); + csound->InitError(csound, Str("revlpsiz inconsistent\n")); } p->prvt = FL(0.0); } @@ -924,7 +1101,9 @@ { MYFLT *asig, *p1, *p2, *p3, *p4, *p5, *p6, *ar, *endp; MYFLT c1,c2,c3,c4,c5,c6; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ if (p->prvt != *p->krvt) { @@ -955,8 +1134,13 @@ endp = (MYFLT *) p->auxch.endp; ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } asig = p->asig; - for (n=0; np6 = p6; return OK; err1: - return csound->PerfError(csound, Str("reverb: not intialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("reverb: not intialised")); } int panset(CSOUND *csound, PAN *p) { FUNC *ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; p->ftp = ftp; p->xmul = (*p->imode == FL(0.0) ? FL(1.0) : (MYFLT)ftp->flen); @@ -1006,7 +1191,9 @@ { MYFLT flend2, xndx_f, yndx_f, xt, yt, ch1, ch2, ch3, ch4; int32 xndx, yndx, flen; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; FUNC *ftp; ftp = p->ftp; @@ -1033,7 +1220,21 @@ ch2 = ftp->ftable[xndx] * ftp->ftable[yndx]; ch3 = ftp->ftable[flen - xndx] * ftp->ftable[flen - yndx]; ch4 = ftp->ftable[xndx] * ftp->ftable[flen - yndx]; - for (n=0; nr1, '\0', offset*sizeof(MYFLT)); + memset(p->r2, '\0', offset*sizeof(MYFLT)); + memset(p->r3, '\0', offset*sizeof(MYFLT)); + memset(p->r4, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->r2[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->r3[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->r4[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nasig[n]; p->r1[n] = sig * ch1; p->r2[n] = sig * ch2; @@ -1043,6 +1244,7 @@ return OK; err1: - return csound->PerfError(csound, Str("pan: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pan: not initialised")); } diff -Nru csound-5.17.11~dfsg/OOps/ugrw1.c csound-6.02~dfsg/OOps/ugrw1.c --- csound-5.17.11~dfsg/OOps/ugrw1.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugrw1.c 2014-01-07 16:53:47.000000000 +0000 @@ -49,2069 +49,6 @@ #include #include -/* Macro form of Istvan's speedup ; constant should be 3fefffffffffffff */ -/* #define MYFLOOR(x) - (x >= FL(0.0) ? (long)x : (long)((double)x - 0.999999999999999)) */ -/* 1.0-1e-8 is safe for a maximum table length of 16777216 */ -/* 1.0-1e-15 could incorrectly round down large negative integers, */ -/* because doubles do not have sufficient resolution for numbers like */ -/* -1000.999999999999999 (MYFLOOR(-1000) might possibly be -1001 which is wrong)*/ -/* it should be noted, though, that the above incorrect result would not be */ -/* a problem in the case of interpolating table opcodes, as the fractional */ -/* part would then be exactly 1.0, still giving a correct output value */ -#define MYFLOOR(x) (x >= FL(0.0) ? (int32)x : (int32)((double)x - 0.99999999)) - -/* Do List: - * - * Clean up code in zak - use arrays rather than messy pointer stuff. - * Clean up doco file. - * Add maxampr to ugrw1.doc - */ - -/* 27 August 1996: - * - * Offset bug in ftkrchkw() fixed, as per my 3 Feb bug report. - * - * 1 February 1996: - * Offset bugs fixed in init time table write - same as in table read. - * See itblchkw() - * - * New ugen 7 January 1996 - peak. - * - * Unit generators by Robin Whittle 8 September 1995 - * UGRW1.H contains data structures. - * - * See UGRW1.DOC for more details on using these ugens. Essential - * functional documentation for them is included here to ensure it - * is never separated from the code. - * - * Changes required to other files: - *--------------------------------- - * - * 2 - A new fgens.c is needed to provide csoundFTFindP() - finding tables at - * performance time. - * - * 3 - prototype.h has a new entry for csoundFTFindP() - see start of fgens.c. - * - * Table write ugens - *------------------ - * - * These table write ugens are adapted from similar code in my modified, - * "bug free" version of the table read code in UGENS2.H & .C. - * - * Ugens: Subroutines: Data structure: - * - * tablew tblsetw() TABLEW - * ktablew() " - * tablew() " - * - * itablew itablew() " - * - * tablewkt tblsetwkt() TABLEW - * ktablewkt() " - * tablewkt() " - *-- - * - * These find out the length of a table, and write the guard point - * of a table. - * - * Ugens: Subroutines: Data structure: - * - * tableng tableng() TABLENG - * itableng itableng() - * - * tablegpw tablegpw() TABLEGPW - * itablegpw itablegpw() - * - * Two ugens to manipulate the entire contents, or part of the contents - * of a table in a single k cycle. - * - * Ugens: Subroutines: Data structure: - * - * tablemix tablemix() TABLEMIX - * itablemix itablemix() - * - * tablecopy tablecopy() TABLECOPY - * itablecopy itablecopy() - * - * Two ugens which enable a rate reading and writing to sequential - * locations in tables. Useful of a rate manipulation of table contents - * and conversely for writing a rate data into a table, where k rate - * code can manipulate it before it is written back to an a rate variable. - * - * Ugens: Subroutines: Data structure: - * - * tablera tableraset() TABLERA - * tablera() - * - * tablewa tablewaset() TABLEWA - * tablewa() - * - *------ - * - * The following ugens are fudges - it would be better to have arrays - - * like ablah[kx][ky]. - * - * Arrays should be local and global, multidimensional, a, k and i rate. - * - * I will use these to get things done until arrays are implemented in - * the core of the language. - * - * The zak system uses one area of memory as a global i or k rate - * patching area, and another for audio rate patching. - * - * Ugens: Subroutines: Data structure: - * - * zakinit zakinit() ZAKINIT - * - * zir zkset() - - * zkr zir() ZKR - * zkr() ZKR - * ziw ziw() ZKW - * zkw zkw() ZKW - * ziwm ziwm() ZKWM - * zkwm zkwm() ZKWM - * zkmod zkmod() ZKMOD - * zkcl zkcl() ZKCL - * - * zar zaset() - - * zaw zar() ZAR - * zaw() ZAW - * zarg zarg() ZARG - * - * zawm zawm() ZAWM - * zamod zamod() ZAMOD - * zacl zacl() ZACL - * - *--- - * Four ugens for reading the abosolute time since the start of the - * performance, and two for reading the time since the instrument was - * initialised: - * - * Ugens: Subroutines: Data structure: - * - * timek timek() RDTIME - * itimek itimek() " - * - * times timesr() " - * itimes itimes() " - * - * instimek instimset() " - * instimes instimek() " - * instimes() " - *--- - * Two ugens for printing a k rate variable during k rate processing. - * - * Ugens: Subroutines: Data structure: - * - * printk printk() PRINTK - * printks printks() PRINTKS - * - */ - -/***************************************************************************** - * - * Table write syntax - *------------------- - * - * Use itablew when all inputs are init time variables or constants - * and you only want to run it at the initialisation of the instrument. - * - * tablew is for writing at k or at a rates, with the table number being - * specified at init time. - * - * tablewkt is the same, but uses a k rate variable for selecting the table - * number. The valid combinations of variable types are shown by the first - * letter of the variable names: - * -*** itablew isig, indx, ifn [,ixmode] [,ixoff] [,iwgmode] - * -*** tablew ksig, kndx, ifn [,ixmode] [,ixoff] [,iwgmode] -*** tablew asig, andx, ifn [,ixmode] [,ixoff] [,iwgmode] - * -*** tablewkt ksig, kndx, kfn [,ixmode] [,ixoff] [,iwgmode] -*** tablewkt asig, andx, kfn [,ixmode] [,ixoff] [,iwgmode] - * - * isig, ksig, The value to be written into the table. - * asig - * - * indx, kndx, Index into table, either a positive number range - * andx matching the table length (ixmode = 0) or a 0 to 1 - * range (ixmode != 0) - * - * ifn, kfn Table number. Must be >= 1. Floats are rounded down to - * an integer. If a table number does not point to a - * valid table, or the table has not yet been loaded - * (gen01) then an error will result and the instrument - * will be de-activated. - * - * ixmode Default 0 ==0 xndx and ixoff ranges match the length - * of the table. - * - * !=0 xndx and ixoff have a 0 to 1 range. - * - * - * ixoff Default 0 ==0 Total index is controlled directly by - * xndx. ie. the indexing starts from the - * start of the table. - * - * !=0 Start indexing from somewhere else in - * the table. Value must be positive and - * less than the table length (ixmode = 0) - * or less than 1 (ixmode !=0 - * - * iwgmode Default 0 ==0 Limit mode } See full explanation in - * ==1 Wrap mode } ugrw1.doc - * ==2 Guardpoint mode } - */ - -/* Known bugs in table write: - * - * Watch out for giving a number (like "5" or p6) instead of a a rate - * variable to the index of table write ugens operating at a rate. - * The ugen gets a pointer to the number, but it is expecting a pointer - * to an a rate variable - which is an array of numbers. - * Upsamp the number (or k rate variable) to an a rate variable first. - * - * This pitfall could be fixed with a revamp of how Csound processes the - * orchestra, or by making different named ugens for different types of - * variables. - */ - -/***************************************************************************** - * - * Other table manipulation ugens - * ------------------------------ - * -*** ir itableng ifn -*** kr tableng kfn - * - * ifn i rate number of function table - * kfn k rate number of function table - * - * These return the length of the specified table. This will be a power - * of two number in most circumstances - it will not show whether - * a table has a guardpoint or not - it seems this information is not - * available in the table's data structure. If table is not found, then - * 0 will be returned. - * - * Likely to be useful for setting up code for table manipulation - * operations, such as tablemix and tablecopy. - * - * -*** itablegpw ifn -*** tablegpw kfn - * - * For writing the table's guard point, with the value which is in - * location 0. Does nothing if table does not exist. - * - * Likely to be useful after manipulating a table with tablemix or - * tablecopy. - * - *------ - * -*** tablemix kdft, kdoff, klen, ks1ft, ks1off, ks1g, ks2ft, ks2off, ks2g -*** itablemix idft, idoff, ilen, is1ft, is1off, is1g, is2ft, is2off, is2g - * - * This ugen mixes from two tables, with separate gains into the - * destination table. Writing is done for klen locations, usually - * stepping forward through the table - if klen was positive. - * If it is negative, then the writing and reading order is backwards - - * towards lower indexes in the tables. This bidirectional option makes - * it easy to shift the contents of a table by reading from it and - * writing back to it. - * - * If klen is 0, no writing occurs. Note that the internal integer value - * of klen is derived from the ANSI C floor() function - which returns - * the next most negative integer. Hence a fractional negative klen - * value of -2.3 would create an internal length of 3, and cause - * the copying to start from the offset locations and proceed for - * two locations to the left. - * - * The total index for table reading and writing is calculated from the - * starting offset for each table, plus the index value, which starts - * at 0 and then increments (or decrements) by 1 as mixing proceeds. - * - * These total indexes can potentially be very large, since there is no - * restriction on the offset or the klen. However each total index for - * each table is ANDed with a length mask (such as 0000 0111 for a table - * of length 8) to form a final index which is actually used for - * reading or writing. So no reading or writing can occur outside - * the tables. - * - * This is the same as "wrap" mode in table read and write. This process - * does not read or write the guardpoint. - * - * If a table has been rewritten with one of these, then if it has a - * guardpoint which is supposed to contain the same value as the - * location 0, then call tablegpw afterwards. - * - * The indexes and offsets are all in table steps - they are not - * normalised to 0 - 1. So for a table of length 256, klen would be - * set to 256 if all the table was to be read or written. - * - * The tables do not need to be the same length - wrapping occurs - * individually for each table. - * - * kdft Destination function table. - * - * kdoff Offset to start writing from. Can be negative. - * - * klen Number of write operations to perform. Negative means - * work backwards. - * - * ks1ft ks2ft Source function tables. These can be the same as the - * destination table, if care is exercised about direction - * of copying data. - * - * ks1off ks2off Offsets to start reading from in source tables. - * - * ks1g ks2g Gains to apply when reading from the source tables. The - * results are added and the sum is written to the destination - * table. - * - *--- - * -*** tablecopy kdft, ksft -*** itablecopy idft, isft - * - * Simple, fast table copy ugens. Takes the table length from the - * destination table, and reads from the start of the source table. - * For speed reasons, does not check the source length - just copies - * regardless - in "wrap" mode. This may read through the source - * table several times. A source table with length 1 will cause - * all values in the destination table to be written to its value. - * - * Table copy cannot read or write the guardpoint. To read it - * use table read, with ndx = the table length. Likewise use - * table write to write it. - * - * To write the guardpoint to the value in location 0, use tablegpw. - * - * This is primarily to change function tables quickly in a real-time - * situation. - * - * kdft Number of destination function table. - * - * ksft Number of source function table. - * - *----- - * -*** ar tablera kfn, kstart, koff - * -*** kstart tablewa kfn, asig, koff - * - * ar a rate distination for reading ksmps values from a table. - * - * kfn i oro k rate number of the table to read or write. - * - * kstart Where in table to read or write. - * - * asig a rate signal to read from when writing to the table. - * - * koff k rate offset into table. Range unlimited - see explanation - * at end of this section. - * - * In one application, these are intended to be used in pairs, or with - * several tablera ugens before a tablewa - all sharing the same kstart - * variable. - * - * These read from and write to sequential locations in a table at audio - * rates, with ksmps floats being written and read each cycle. - * - * tablera starts reading from location kstart. - * tablewa starts writing to location kstart, and then writes to kstart - * with the number of the location one more than the one it last wrote. - * (Note that for tablewa, kstart is both an input and output variable.) - * If the writing index reaches the end of the table, then the no further - * writing occurs and zero is written to kstart. - * - * For instance, if the table's length was 16 (locations 0 to 15), and - * ksmps was 5. Then the following steps would occur with repetitive - * runs of the tablewa ugen, assuming that kstart started at 0. - * - * Run no. Initial Final locations written - * kstart kstart - * - * 1 0 5 0 1 2 3 4 - * - * 2 5 10 5 6 7 8 9 - * - * 3 10 15 10 11 12 13 14 - * - * 4 15 0 15 - * - * This is to facilitate processing table data using standard a rate - * orchestra code between the tablera and tablewa ugens: - * - * ;----------------------------- - * ; - * kstart = 0 ; - * ; Read 5 values from table into an a rate - * ; variable. - * - * lab1: atemp tablera ktabsource, kstart, 0 - * - * ; Process the values using a rate code. - * atemp = log(atemp) ; - * ; Write it back to the table - * - * kstart tablewa ktabdest, atemp, 0 - * - * ; Loop until all table locations have been - * ; processed. - * if ktemp > 0 goto lab1 ; - * ; - * ;----------------------------- - * - * This example shows a processing loop, which runs every k cycle, - * reading each location in the table ktabsource, and writing the log - * of those values into the same locations of table ktabdest. - * - * This enables whole tables, parts of tables (with offsets and different - * control loops) and data from several tables at once to be manipulated - * with a rate code and written back to another (or the same) table. - * This is a bit of a fudge, but it is faster than doing it with - * k rate table read and write code. - * - * Another application is: - * - * ;----------------------------- - * - * kzero = 0 ; - * kloop = 0 ; - * ; - * kzero tablewa 23, asignal, 0 ; ksmps a rate samples written into - * ; locations 0 to (ksmps -1) of table 23. - * ; - * lab1: ktemp table kloop, 23 ; Start a loop which runs ksmps times, - * ; in which each cycle processes one of - * [ Some code to manipulate ] ; table 23's values with k rate orchestra - * [ the value of ktemp. ] ; code. - * ; - * ; - * tablew ktemp, kloop, 23 ; Write the processed value to the table. - * ; - * kloop = kloop + 1 ; Increment the kloop, which is both the - * ; pointer into the table and the loop - * if kloop < ksmps goto lab1 ; counter. Keep looping until all values - * ; in the table have been processed. - * ; - * asignal tablera 23, 0, 0 ; Copy the table contents back to an a rate - * ; variable. - * ;----------------------------- - * - * - * koff This is an offset which is added to the sum of kstart and the internal - * index variable which steps through the table. The result is then - * ANDed with the lengthmask (000 0111 for a table of length 8 - or - * 9 with guardpoint) and that final index is used to read or write to - * the table. koff can be any value. It is converted into a long using - * the ANSI floor() function so that -4.3 becomes -5. This is what we - * would want when using wide rangeing offsets. - * - * Ideally this would be an optional variable, defaulting to 0, however - * with the existing Csount orchestra read code, such default parameters - * must be init time only. We want k rate here, so we cannot have a - * default. - * - * Notes on tablera and tablewa - *----------------------------- - * - * These are a fudge, but they allows all Csounds k rate operators to be - * used (with caution) on a rate variables - something that would only - * be possible otherwise by ksmps = 1, downsamp and upsamp. - * - * Several cautions: - * - * 1 - The k rate code in the processing loop is really running at a rate, - * so time dependant functions like port would not work normally. - * - * 2 - This system will produce undesirable results unless the ksmps fits - * within the table length. For instance a table of length 16 will - * accomodate 1 to 16 samples, so this example will work with - * ksmps = 1 to 16. - * - * Both these ugens generate an error and deactivate the instrument if - * a table with length < ksmps is selected. Likewise an error occurs - * if kstart is below 0 or greater than the highest entry in the table - - * if kstart >= table length. - * - * 3 - kstart is intended to contain integer values between 0 and (table - * length - 1). Fractional values above this should not affect operation - * but do not achieve anything useful. - * - * 4 - These ugens do not do interpolation and the kstart and koff parameters - * always have a range of 0 to (table length - 1) - not 0 to 1 as is - * available in other table read/write ugens. koff can be outside this - * range but it is wrapped around by the final AND operation. - * - * 5 - These ugnes are permanently in wrap mode. When koff is 0, no wrapping - * needs to occur, since the kstart++ index will always be within the - * table's normal range. koff != 0 can lead to wrapping. - * - * 6 - The offset does not affect the number of read/write cycles performed, - * or the value written to kstart by tablewa. - * - * 7 - These ugens cannot read or write the guardpoint. Use tablegpw to - * write the guardpoint after manipulations have been done with tablewa. - * - *------ - * - */ - -/***************************************************************************** - * - * The "zak" system - * ---------------- - * - * The zak system uses one area of memory as a global i or k rate - * patching area, and another for audio rate patching. These are - * establised by a ugen which must be called once only. - * -*** zakinit isizea, isizek - * - * isizek is the number of locations we want to reserve for floats - * in the zk space. These can be written and read at i and k rates. - * - * isizea is the number of audio rate "locations" for a rate patching. - * Each "location" is actually an array which is ksmps long. - * - * eg. zakinit 100 30 reserves memory for locations 0 to 100 of zk space - * and for locations 0 to 30 of a rate za space. With ksmps = 8, this - * would take 101 floats for zk and 248 floats for za space. - * - * At least one location is always allocated for both zk and za spaces. - * - * These patching locations can be referred to by number with the - * following ugens. - * - * There are two short, simple, fast opcodes which read a location in - * zk space, at either i time or at the k rate. - * -*** ir zir indx -*** kr zkr kndx - * - * Likewise, two write to a location in zk space at i time or at the k - * rate. - * -*** ziw isig, indx -*** zkw ksig, kndx - * - * These are fast and always check that the index is within the - * range of zk space. If it is out of range, an error is reported - * and 0 is returned, or no writing takes place. - * -*** ziwm isig, indx [,imix] -*** zkwm ksig, kndx [,imix] - * - * Like ziw and zkw above, except that they can mix - add the sig - * to the current value of the variable. If no imix is specified, - * they mix, but if imix is used, then 0 will cause writing (like - * ziw and zkw) any other value will cause direct mixing. - * -*** kr zkmod ksig, kzkmod - * - * zkmod is a unit generator intended to facilitate the modulation - * of one signal by another, where the modulating signal comes from - * a zk variable. Either additive or mulitiplicative modulation is - * provided. - * - * ksig is the input signal, to be modulated and sent to the output - * of the zkmod unit generator. - * - * kzkmod controls which zk variable is used for modulation. A positive - * value means additive modulation, a negative value means multiplicative - * modulation. A value of 0 means no change to ksig - it is transferred - * directly to the output. - * - * For instance kzkmod = 23 will read from zk variable 23, and add the - * value it finds there to ksig. If kzkmod = -402, then ksig is - * multiplied by the value read from zk location 402. - * - * kskmod can be an init time constant, or a k rate value. - * - * -*** zkcl kfirst, klast - * - * This will clear to zero one or more variables in the zk space. - * Useful for those variables which are accumulators for mixing - * things during the processing for each cycle, but which must be - * cleared to zero before the next set of calculations. - * - *------ - * - * For a rate reading and writing, in the za space, we use similar - * opcodes: - * -*** ar zar kndx - * - * kndx points to which za variable to read. This reads the number kndx - * array of floats which are the ksmps number of audio rate floats to be - * processed in a k cycle. - * -*** ar zarg kndx, kgain - * - * Similar to zar, but multiplies the a rate signal by a k rate value - * kgain. - * -*** zaw asig, kndx - * - * Writes into the array specified by kndx. - * -*** zawm asig, kndx [,imix] - * - * Like zaw above, except that it can mix - add the asig to the current - * value of the destination za variable. If no imix is specified, - * it mixes, but if imix is used, then 0 will cause a simple write (like - * zaw) and any other value will cause mixing. - * -*** ar zamod asig, kzamod - * - * Modulation of one audio rate signal by a second one - which comes from - * a za variable. The location of the modulating variable is controlled - * by the k rate variable kzamod. This is the audio rate version of - * zkmod described above. - * -*** zacl kfirst, klast - * - * This will clear to zero one or more variables in the za space. - * Useful for those variables which are accumulators for mixing - * things during the processing for each cycle, but which must be - * cleared to zero before the next set of calculations. - * - *------ - * - * What types of input variables are used? - * - * Runs at time - * ir zir indx i - * kr zkr kndx k - * - * ziw isig, indx i - * zkw ksig, kndx k - * - * ziwm isig, indx, imix i - * zkwm ksig, kndx, kmix k - * - * zkcl kfirst, klast k - * - * ar zar kndx k but does arrays - * ar zarg kndx, kgain k but does arrays - * - * zaw asig, kndx k but does arrays - * - * zawm asig, kndx, kmix k but does arrays - * - * zacl kfirst, klast k but does arrays - * - * - * isig } - * indx } Known at init time - * imix } - * - * ksig } - * kndx } - * kmix } k rate variables - * kfirst } - * klast } - * kgain } - * - * asig } a rate variable - an array of floats. - * - */ - -/************************************************************************** - * - * Simple time reading ugens - *-------------------------- - * -*** kr timek -*** kr timesr - * - * timek returns a float containing an integer - the number of k cycles - * since the start of the performance of the orchestra. - * - * timesr returns a float with the number of seconds. - * - * They both expect a k rate variable as their output. There are no - * input parameters. - * -*** ir itimek -*** ir itimes - * - * itemek and itimes are similar ugens which only operate during the - * initialisation of an instance of the instrument. - * -*** kr instimek -*** kr instimes - * - * These are similar to timek and timesr, except they return the - * time since the start of this instance of the instrument. - * - */ - -/************************************************************************** - * - * Two ugens for printing at k rate - *--------------------------------- - * - * printk prints one k rate value on every k cycle, every second or at - * intervals specified. First the instrument number is printed, then - * the absolute time in seconds, then a specified number of spaces, then - * the value. The variable number of spaces enables different values to - * be spaced out across the screen - so they are easier to view. - * This is for debugging orchestra code. - * -*** printk itime, kval [, ispace] - * - * itime How much time in seconds is to elapse between printings. - * - * kval The number to be printed. - * - * ispace How many spaces to insert before it is printed. (Max 120.) - * Default = 0. - * - * The first print is on the first k cycle of the instance of the - * instrument. - * - *------ - * - * printks prints numbers and text, with up to four printable numbers - * - which can be i or k rate values. - * -*** printks "txtstring", itime, kval1, kval2, kval3, kval4 - * - * txtstring Text to be printed first - can be up to 130 characters at - * least. _Must_ be in double quotes. - * - * The string is printed as is, but standard printf %f etc. - * codes are interpreted to print the four parameters. - * - * However the \n style of character codes are not interpreted - * by printf. (They are converted by the C compiler in - * string literals found in the C program.) This ugen therefore - * provides certain specific codes which are expanded: - * - * \n or \N Newline - * \t or \T Tab - * - * ^ Escape character - * ^^ ^ - * - * ~ Escape and '[' These are the leadin codes for - * MSDOS ANSI.SYS screen control characters. - * ~~ ~ - * - * An init error is generated if the first parameter is not - * a string of length > 0 enclosed in double quotes. - * - * A special mode of operation allows this ugen to convert - * the first input parameter into a 0 to 255 character, and - * to use it as the first character to be printed. This enables - * a Csound program to send arbitrary characters to the console - - * albeit with a little awkwardness. printf() does not have a - * format specifier to read a float and turn it into a byte - * for direct output. We could add extra code to do this if - * we really wanted to put arbitrary characters out with ease. - * - * To acheive this, make the first character of the string a - * # and then, if desired continue with normal text and format - * specifiers. Three more format specifers may be used - they - * access kval2, kval3 and kval4. - * - * itime How much time in seconds is to elapse between printings. - * - * kvalx The k rate values to be printed. Use 0 for those which are not - * used. - * - * - */ - -/************************************************************************** - * - * Two ugens for tracking peak signal levels - *------------------------------------------ - * - * peakk takes k rate inputs and peak takes a rate inputs. - * - * They maintain the output k rate variable as the peak absolute - * level so far received. - * -*** kpeakout peakk ksigin -*** kpeakout peaka asigin - * - * - * kpeakout Output equal to the highest absolute value received - * so far. - * This is effectively an input to the ugen as well, since it - * reads kpeakout in order to decide whether to write - * something higher into it. - * - * ksigin k rate input signal. - * asigin a rate input signal. - * - */ - -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ -/*---------------------------------------------------------------------------*/ - -static int ftkrchkw(CSOUND *, TABLEW *p); - int itblchkw(CSOUND *, TABLEW *p); -static int tblchkw(CSOUND *, TABLEW *p); - -/* Table write code - * - * The way that the k rate table numbers are handled by different - * ugens and functions is analogous to the approach used in the new - * ugens2.c. */ - -/* itblchkw() - * - * Internal function itblchkw(). Called at init time by tblsetw() to - * initialise some of the variables in TABLEW - which is pointed to by - * p. - * - * Also called by itablew(). - * - * A similar function tblchkw() does the same job at performance time - * - k processing cycles. - * - * Both these functions are virtually identical to those itblchk() and - * ptblchk() in ugens2.c. The differences are: - * - * 1 - They use TABLEW instead of TABLE. - * 2 - There is no iwrap parameter. - * 3 - There is an igwmode parameter. -*/ - -int itblchkw(CSOUND *csound, TABLEW *p) -{ - /* Get pointer to the function table data structure of the table - * number specified in xfn. Return 0 if it cannot be found. - * - * csoundFTFind() generates an error message if the table cannot be - * found. This works OK at init time. It also deactivates the - * instrument. - * - * It also checks for numbers < 0, and table 0 is never valid, so we - * do not need to check here for the table number being < 1. */ - - if (UNLIKELY((p->ftp = csound->FTFind(csound, p->xfn)) == NULL)) - return NOTOK; - /* Although TABLEW has an integer variable for the table number - * (p->pfn) we do not need to * write it. We know that the * k - * and a rate functions * which will follow will not * be - * expecting a changed * table number. - * - * p->pfn exists only for checking * table number changes for - * functions * which are expecting a k rate * table number. */ - - /* Set denormalisation factor to 1 or table length, depending on - * the state of ixmode. 1L means a 32 bit 1. */ - /* JPff.............................^...not so; could be any length */ - if (*p->ixmode) - p->xbmul = p->ftp->flen; - else p->xbmul = 1L; - /* Multiply the ixoff value by the xbmul denormalisation - * factor and then check it is between 0 and the table length. */ - if (UNLIKELY((p->offset = p->xbmul * *p->ixoff) < FL(0.0) - || p->offset > p->ftp->flen)) { - return csound->InitError(csound, - Str("Table write offset %f < 0 or > tablelength"), - p->offset); - } - p->iwgm = (int)*p->iwgmode; - return OK; -} - -/*************************************/ - -/* tblchkw() - * - * This is called at init time by tblsetwkt() to set up the TABLEW - * data structure for subsequent k and a rate operations which are - * expecting the table number to change at k rate. - * - * tblsetwkt() does very little - just setting up the iwgm variable in - * TABLE. All the other variables depend on the table number. This is - * not available at init time, so the following two functions must - * look for the changed table number and set up the variables - * accordingly - generating error messages in a way which works at - * performance time. - * - * k rate a rate - * - * ktablewkt tablewkt - * - */ -static int tblchkw(CSOUND *csound, TABLEW *p) -{ - /* TABLEW has an integer variable for the previous table number - * (p->pfn). - * - * Now (at init time) we do not know the function table number which - * will be provided at perf time, so set p->pfn to 0, so that the k or - * a rate code will recognise that the first table number is different - * from the "previous" one. - */ - p->pfn = 0; /* the only other thing to do is write the iwgmode - value into the immediate copy of it in TABLEW. */ - p->iwgm = (int)*p->iwgmode; - return OK; -} - -/*---------------------------------------------------------------------------*/ - -/* tblsetwkt() - * - * This is called at init time to set up TABLEW for the a and k rate - * table read functions which are expecting the table number to be a k - * rate variable. - * - * Call the tblchkw() function to do the work. */ -int tblsetwkt(CSOUND *csound, TABLEW *p) -{ - return tblchkw(csound, p); -} - -/* itablew() - * - * Used to write to a table only at init time. It is called (via the - * opcodlst in entry.c) for the itablew opcode. - * - * It sets up some variables in the TABLEW data structure for this - * instance and calls ktablew() once to write to the table. */ -int itablew(CSOUND *csound, TABLEW *p) -{ - if (LIKELY(itblchkw(csound, p) == OK)) - return ktablew(csound, p); - return NOTOK; -} - -/*---------------------------------------------------------------------------*/ - -/* ktablew is called with p pointing to the TABLEW data structure - - * which contains the input arguments. */ - -int ktablew(CSOUND *csound, TABLEW *p) -{ -/* Pointer to data structure for accessing the table we will be - * writing to. - */ - FUNC *ftp; - /* 32 bit integers for pointing into table and for the table - * length - which is always a power of 2. The table must - * actually be one more longer than this if it has a guard - * point. */ - int32 indx, length; - MYFLT ndx; /* for calculating index of read. */ - MYFLT *ptab; /* Where we will write */ - - /*-----------------------------------*/ - /* Assume that TABLEW has been set up correctly. */ - - ftp = p->ftp; - ndx = *p->xndx; - length = ftp->flen; - /* Multiply ndx by denormalisation factor. and add in the - * offset - already denormalised - by tblchkw(). - * xbmul = 1 or table length depending on state of ixmode. */ - - ndx = (ndx * p->xbmul) + p->offset; - - /* ndx now includes the offset and is ready to address the table. - * However we have three modes to consider: - * igwm = 0 Limit mode. - * 1 Wrap mode. - * 2 Guardpoint mode. - */ - if (p->iwgm == 0) { - /* Limit mode - when igmode = 0. - * - * Limit the final index to 0 and the last location in the table. - */ - indx = (int32) MYFLOOR(ndx); /* Limit to (table length - 1) */ - if (UNLIKELY(indx > length - 1)) - indx = length - 1; /* Limit the high values. */ - else if (UNLIKELY(indx < 0L)) indx = 0L; /* limit negative values to zero. */ - } - /* Wrap and guard point mode. - * In guard point mode only, add 0.5 to the index. */ - else { - if (p->iwgm == 2) ndx += FL(0.5); - indx = (int32) MYFLOOR(ndx); - - /* Both wrap and guard point mode. - * The following code uses an AND with an integer like 0000 0111 to wrap - * the current index within the range of the table. */ - indx &= ftp->lenmask; - } - /* Calculate the address of where we - * want to write to, from indx and the - * starting address of the table. - */ - ptab = ftp->ftable + indx; - *ptab = *p->xsig; /* Write the input value to the table. */ - /* If this is guard point mode and we - * have just written to location 0, - * then also write to the guard point. - */ - if ((p->iwgm == 2) && indx == 0) { /* Fix -- JPff 2000/1/5 */ - ptab += ftp->flen; - *ptab = *p->xsig; - } - return OK; -} - -/*---------------------------------------------------------------------------*/ - -/* tablew() is similar to ktablew() above, except that it processes - * two arrays of input values and indexes. These arrays are ksmps long. */ -int tablew(CSOUND *csound, TABLEW *p) -{ - FUNC *ftp; /* Pointer to function table data structure. */ - MYFLT *psig; /* Array of input values to be written to table. */ - MYFLT *pxndx; /* Array of input index values */ - MYFLT *ptab; /* Pointer to start of table we will write. */ - MYFLT *pwrite;/* Pointer to location in table where we will write */ - int32 indx; /* Used to read table. */ - int32 mask; /* ANDed with indx to make it wrap within table.*/ - int32 length; /* Length of table - always a power of two, - * even if the table has a guard point. */ - /* For instance length = 8, mask = 0000 0111, normal locations in table - * are 0 to 7. Location 8 is the guard point. table() does not read - * the guard point - tabli() does.*/ - int liwgm; /* Local copy of iwgm for speed */ - int n, nsmps = csound->ksmps; - MYFLT ndx, xbmul, offset; - /*-----------------------------------*/ - /* Assume that TABLEW has been set up correctly. */ - - ftp = p->ftp; - psig = p->xsig; - pxndx = p->xndx; - ptab = ftp->ftable; - mask = ftp->lenmask; - length = ftp->flen; - liwgm = p->iwgm; - xbmul = (MYFLT)p->xbmul; - offset = p->offset; - /* Main loop - for the number of a samples in a k cycle. */ - for (n=0; n length - 1)) indx = length - 1; - else if (UNLIKELY(indx < 0L)) indx = 0L; - } - else { - if (liwgm == 2) ndx += FL(0.5); - indx = (int32) MYFLOOR(ndx); - /* Both wrap and guard point mode. - * - * AND with an integer like 0000 0111 to wrap the index within the - * range of the table. */ - indx &= mask; - } - pwrite = ptab + indx; - *pwrite = psig[n]; - /* If this is guard point mode and we - * have just written to location 0, - * then also write to the guard point. - */ - if ((liwgm == 2) && indx == 0) { /* Fix -- JPff 2000/1/5 */ - /* Note that since pwrite is a pointer - * to a float, adding length to it - * adds (4 * length) to its value since - * the length of a float is 4 bytes. - */ - pwrite += length; - /* Decrement psig to make it point - * to the same input value. - * Write to guard point. - */ - *pwrite = psig[n]; - } - } - return OK; -} - -/*************************************/ - -/* ktablewkt() and tablewkt() - * - * These call ktablew() and tablew() above - after they have set up - * TABLEW after the k rate table number changes. - * - * Prior to these running, we can assume that tblsetwkt() has been run - * at init time. - * - * tblsetwkt() does very little - just setting up the iwgmode variable - * in TABLEW. All the other variables depend on the table number. This - * is not available at init time, so the following two functions must - * look for the changed table number and set up the variables - * accordingly - generating error messages in a way which works at - * performance time. - * - * k rate a rate - * - * ktablewkt tablewkt - * - * Since these perform identical operations, apart from the function - * they call, create a common function to do this work: - * - * ftkrchkw() */ - -static int ftkrchkw(CSOUND *csound, TABLEW *p) -{ -/* Check the table number is >= 1. Print error and deactivate if it - * is. Return 0 to tell calling function not to proceed with a or k - * rate operations. - * - * This was not necessary in the versions of ktablew() and tablew() - * because csoundFTFind() would catch a table number < 1. - * - * However, in this case, we only call csoundFTFindP() if the table number - * changes from p->pfn, so we want to generate an error message if the - * ugen is ever called with a table number of 0. While we are about - * it, catch negative values too. */ - if (UNLIKELY(*p->xfn < 1)) goto err1; - /* Check to see if table number has changed from previous value. - * - * On the first run through, the previous value will be 0. */ - - if (p->pfn != (int32)*p->xfn) { - /* If it is different, check to see if the table exists. If it - * doesn't, an error message should be produced by csoundFTFindP() - * which should also deactivate the instrument. Return 0 to - * tell calling function not to proceed with a or k rate - * operations. - */ - - if (UNLIKELY((p->ftp = csound->FTFindP(csound, p->xfn)) == NULL)) { - return NOTOK; - } - - /* p->ftp now points to the FUNC data structure of the newly - * selected table. - * - * Now we set up some variables in TABLEW ready for the k or a - * rate functions which follow. */ - - /* Write the integer version of the table number into pfn so we - * can later decide whether subsequent calls to the k and a rate - * functions occur with a table number value which points to a - * different table. - * - * p->pfn is an integer. */ - p->pfn = (int32)*p->xfn; - - /* Set denormalisation factor to 1 or table length, depending on - * the state of ixmode. 1L means a 32 bit 1. */ - if (*p->ixmode) p->xbmul = p->ftp->flen; - else p->xbmul = 1L; - - /* Multiply the ixoff value by the xbmul denormalisation factor - * and then check it is between 0 and the table length. */ - - if (UNLIKELY((p->offset = p->xbmul * *p->ixoff) < FL(0.0) || - p->offset > p->ftp->flen)) goto err2; - } - /* If all is well, return 1 to tell calling function to proceed - * with a or k rate operations. */ - return OK; - err1: - return csound->PerfError(csound, Str("Table write k rate " - "function table no. %f < 1"), - *p->xfn); - err2: - return csound->PerfError(csound, - Str("Table write offset %f < 0 or > tablelength"), - p->offset); -} - -/* Now for the two functions, which are called as a result of being - * listed in opcodlst in entry.c */ - -int ktablewkt(CSOUND *csound, TABLEW *p) -{ - if (LIKELY(ftkrchkw(csound, p) == OK)) - return ktablew(csound, p); - return NOTOK; -} - -int tablewkt(CSOUND *csound, TABLEW *p) -{ - if (LIKELY(ftkrchkw(csound, p) == OK)) - return tablew(csound, p); - return NOTOK; -} - -/*****************************************************************************/ - -/* Reading the table length */ - -/* tableng() - * - * At k rate - performance time. See similar function to do it at - * init time - itableng(). - * - * The means of finding the table, and of reporting an error differ - * between these i time and perf time. */ -int tableng(CSOUND *csound, TABLENG *p) -{ - MYFLT *dummy; - int flen; - /* Check to see we can find the table and find its location in - * memory. Returns -1 if not found. Report and error, which - * will cause this instrument to be de-activated. */ - - flen = csound->GetTable(csound, &dummy, (int)*(p->xfn)); - if (UNLIKELY(flen < 0)) { - *p->kout = FL(0.0); - return csound->PerfError(csound, Str("Table %f not found"), *(p->xfn)); - } - /* Return length as a float if we do find the table. */ - *p->kout = (MYFLT) flen; - return OK; -} -/*-----------------------------------*/ - -/* itableng() - * - * At init time. - */ -int itableng(CSOUND *csound, TABLENG *p) -{ - MYFLT *dummy; - int flen; - /* Check to see we can find the table and find its location in - * memory. Returns -1 if not found. Report and error, which - * will cause this instrument initialisation to fail. */ - - flen = csound->GetTable(csound, &dummy, (int)*(p->xfn)); - if (UNLIKELY(flen < 0)) { - *p->kout = FL(0.0); - return csound->InitError(csound, Str("Table %f not found"), *(p->xfn)); - } - /* Return length as a float if we do find the table. */ - *p->kout = (MYFLT) flen; - return OK; -} - -/*---------------------------------------------------------------------------*/ - -/* Writing the guardpoint */ - -/* tablegpw() - * - * At k rate - performance time. See similar function to do it at - * init time - itablegpw(). - * - * The means of finding the table, and of reporting an error differ - * between these i time and perf time. - * - * Read the value in location 0 and write it to the guard point. */ -int tablegpw(CSOUND *csound, TABLEGPW *p) -{ - /* Local variables - * - * Pointer to data structure for - * accessing table. - */ - FUNC *ftp; - - MYFLT *ptab; /* Pointer to start of table. */ - - MYFLT val0; /* Value read from location 0 in table. */ - - int32 length; /* temporary storage for length - - * in floats, not in bytes. - */ - - /* Check to see we can find the table - * and find its location in memory. - */ - - if (UNLIKELY((ftp = csound->FTFindP(csound, p->xfn)) == NULL)) { - return NOTOK; - } - /* Find length of table. - */ - else { - length = (int32) ftp->flen; - ptab = ftp->ftable; - /* Now write from location 0 to - * the guard point which is at - * location length. - */ - val0 = *ptab; - ptab = ptab + length; - *ptab = val0; - } - return OK; -} -/*-----------------------------------*/ - - /* itablegpw() - * - * At init time. - */ -int itablegpw(CSOUND *csound, TABLEGPW *p) -{ - /* Local variables - * - * Pointer to data structure for - * accessing table. - */ - FUNC *ftp; /* Pointer to start of table. */ - MYFLT *ptab; /* Value read from location 0 in table. */ - MYFLT val0; /* Temp. storage for length in floats, not in bytes.*/ - int32 length; - - /* Check to see we can find the table and find its location in memory. */ - if (UNLIKELY((ftp = csound->FTFind(csound, p->xfn)) == NULL)) { - return csound->InitError(csound, Str("Table %f not found"), *(p->xfn)); - } - /* Find length of table. */ - else { - length = (int32) ftp->flen; - ptab = ftp->ftable; - /* Now write from location 0 to - * the guard point which is at - * location length. - */ - val0 = *ptab; - ptab = ptab + length; - *ptab = val0; - } - return OK; -} - -/*---------------------------------------------------------------------------*/ - - /* tablemix functions */ - -/* tablemixset() - * - * Called at i time prior to the k rate function tablemix(). */ - -int tablemixset(CSOUND *csound, TABLEMIX *p) -{ - /* There may be no input values now - they are typically k rate and so - * are not present at i time. - * - * Set to zero the three variables with which we check to see if - * the k rate table numbers have changed. These are in the TABLEMIX - * structure which is specific to this instance of the ugen. However - * its values have not been initialised, so they could be anything. */ - p->pdft = 0; - p->ps1ft = 0; - p->ps2ft = 0; - return OK; -} - -/* tablemix() - * - * k rate version - see itablemix() for the init time version. - * - * These are similar but require two different approaches to - * finding tables and reporting errors. - * - * This adventurous ugen uses nine parameters which are all assumed - * to be k rate variables - which could change at any time. - * - * Six of these will used directly. - * - * However, three of them will be checked to see if they have changed - * from last time - the three variables which point to the - * destination and source tables. - * - * If they change, then the new values will be used to search for a new - * table. Otherwise, existing pointers will be used to access the data - * structures for the tables. - * - * Both the i and k rate operations have a lot in common, so use a - * common function domix(). - * - * Declare it here. - */ -static void domix(CSOUND *csound, TABLEMIX *p); - -int tablemix(CSOUND *csound, TABLEMIX *p) -{ - /* Check the state of the three table number variables. - * - * Error message if any are < 1 and no further action. - * We cannot leave it for csoundFTFindP() to find 0 values, since it is only - * called if the input value is different from the "previous" value - * which is initially 0. - */ - if (UNLIKELY((*p->dft < 1) || (*p->s1ft < 1) || (*p->s2ft < 1))) { - return csound->PerfError(csound, Str("Table no. < 1 " - "dft=%.2f s1ft=%.2f s2ft=%.2f\n"), - *p->dft, *p->s1ft, *p->s2ft); - } - /* Check each table number in turn. */ - - /* Destination */ - if (p->pdft != (int)*p->dft) { - /* Get pointer to the function table data structure. - * - * csoundFTFindP() for perf time. - * csoundFTFind() for init time. - */ - - if (UNLIKELY((p->funcd = csound->FTFindP(csound, p->dft)) == NULL)) { - return csound->PerfError(csound, - Str("Destination dft table %.2f not found."), - *p->dft); - } - /* Table number is valid. - * - * Save the integer version of the table number for future reference.*/ - p->pdft = (int)*p->dft; - } - - /* Source 1 */ - if (p->ps1ft != (int)*p->s1ft) { - if (UNLIKELY((p->funcs1 = csound->FTFindP(csound, p->s1ft)) == NULL)) { - return csound->PerfError(csound, - Str("Source 1 s1ft table %.2f not found."), - *p->s1ft); - } - p->ps1ft = (int)*p->s1ft; - } - - /* Source 2 */ - if (p->ps2ft != (int)*p->s2ft) { - if (UNLIKELY((p->funcs2 = csound->FTFindP(csound, p->s2ft)) == NULL)) { - return csound->PerfError(csound, - Str("Source 2 s2ft table %.2f not found."), - *p->s2ft); - } - p->ps2ft = (int)*p->s2ft; - } - /* OK all tables present and the funcx pointers are pointing to - * their data structures. - * - * The other parameters do not need checking - and the remaining - * proceedures are common to the init time version, so call a - * function to do the rest. */ - domix(csound, p); - return OK; -} - -/*-----------------------------------*/ - -/* itablemix() - * - * identical to above, but we know it runs at init time, so we do not - * check for changes, we look for the table with csoundFTFind() instead of - * csoundFTFindP() and we use csoundInitError() instead of csoundPerfError(). - */ -int itablemix(CSOUND *csound, TABLEMIX *p) -{ - /* Check the state of the three table number variables. - * - * Error message if any are < 1 and no further action. - * - * Technically we do not need to check for values of 0 or negative - * since they will all be fed to csoundFTFind(). - * Do so anyway to be consistent with tablemix(). - * - * This runs only once, so speed is not an issue. */ - if (UNLIKELY((*p->dft < 1) || (*p->s1ft < 1) || (*p->s2ft < 1))) { - return csound->InitError(csound, Str("Table number < 1 " - "dft=%.2f s1ft=%.2f s2ft=%.2f"), - *p->dft, *p->s1ft, *p->s2ft); - } - /* Check each table number in turn. */ - - /* Destination */ - - /* Get pointer to the function table data structure. - * - * csoundFTFind() for init time. - */ - - if (UNLIKELY((p->funcd = csound->FTFind(csound, p->dft)) == NULL)) { - return csound->InitError(csound, - Str("Destination dft table %.2f not found."), - *p->dft); - } - /* Table number is valid. - * - * Save the integer version of the table number for future reference. */ - p->pdft = (int)*p->dft; - - /* Source 1 */ - if (UNLIKELY((p->funcs1 = csound->FTFind(csound, p->s1ft)) == NULL)) { - return csound->InitError(csound, - Str("Source 1 s1ft table %.2f not found."), - *p->s1ft); - } - p->ps1ft = (int)*p->s1ft; - - /* Source 2 */ - if (UNLIKELY((p->funcs2 = csound->FTFind(csound, p->s2ft)) == NULL)) { - return csound->InitError(csound, - Str("Source 2 s2ft table %.2f not found."), - *p->s2ft); - } - p->ps2ft = (int)*p->s2ft; - domix(csound, p); - return OK; -} - -/*-----------------------------------*/ - -/* domix() - * - * This is the business end of tablemix and itablemix. - * - * We could be called at either init or perf time. So we do not - * make any error messages here. - * - * The three tables have been found and are known to be of greater - * than zero length - csoundFTFind() and csoundFTFindP() check this. - * - * We will use the remaining input parameters no matter what their - * values are. - * - * Length is converted from a float to a long, with floor() - * so that -0.3 converts to -1. - * - * The resulting integer could be negative - this tells us to - * work backwards. - * - * The offsets could be anything whatsoever - these will be added - * to index to produce integers which are rounded by the lenmask - * of each table. So we don't mind if the offsets are all over the place. - * - * Likewise the gain parameters for source tables 1 and 2, except - * that if the gain of source 2 is 0, then we do not bother reading - * it. This is to save time when all that the user wants is a copy. - */ -static void domix(CSOUND *csound, TABLEMIX *p) -{ - MYFLT gains1, gains2; /* Gains for source tables 1 and 2. */ - int32 length; /* from len input parameter */ - int32 loopcount; - - int32 offd, offs1, offs2; /* Offsets for the three tables. */ - - /* Index to be added to offsets as we step through the tables. - * If length was positive, this will increase by one each cycle. - * If length was negative, it will step backards from 0. - */ - int32 indx = 0; - MYFLT *based, *bases1, *bases2; /* Base addresses of the three tables. */ - int32 maskd, masks1, masks2; - MYFLT *pdest, *ps1, *ps2; - - gains1 = *p->s1g; - gains2 = *p->s2g; - - /* Get the length and generate the loop count. - * Return with no action if it is 0. */ - - if (UNLIKELY((length = (int32)MYFLOOR(*p->len)) == 0L)) return; - - if (UNLIKELY(length < 0L)) loopcount = 0L - length; - else loopcount = length; - - /* Get the offsets for the three tables; Use floor to reduce negative floats - * to the next most negative integer. This ensures that a sweeping - * offset will wrap correctly into the table's address space. */ - - offd = (int32)MYFLOOR(*p->doff); - offs1 = (int32)MYFLOOR(*p->s1off); - offs2 = (int32)MYFLOOR(*p->s2off); - - /* Now get the base addresses and length masks of the three tables. */ - based = p->funcd->ftable; - maskd = p->funcd->lenmask; - - bases1 = p->funcs1->ftable; - masks1 = p->funcs1->lenmask; - - bases2 = p->funcs2->ftable; - masks2 = p->funcs2->lenmask; - - /* Decide which of four loops to do based on: - * Forwards or backwards? Source 2 gain is zero or not? */ - if (length > 0) { - if (gains2 != 0) { /* Forwards, full mix. */ - do { - /* Create pointers by adding index to offset, ANDing - * with mask, and adding to base address. - * - * Mask, offset and index are all in units of 1 - not - * the units of 4 bytes (typically) needed to step - * through memory to find floats. - * - * So we make base a pointer to a float and the - * compiler is smart enough to know that when we add - * an integer to a float pointer, we want that - * pointers address to change by sizeof(float) * the - * value of the integer. */ - - pdest = based + (maskd & (offd + indx)); - ps1 = bases1 + (masks1 & (offs1 + indx)); - ps2 = bases2 + (masks2 & (offs2 + indx)); - - /* Mix from source1 and source 2. */ - *pdest = (*ps1 * gains1) + (*ps2 * gains2); - indx++; - } while (--loopcount); - } - else { - /* Forwards, only read source 1 */ - do { - pdest = based + (maskd & (offd + indx)); - ps1 = bases1 + (masks1 & (offs1 + indx)); - /* Write fomr source1 to destination. */ - *pdest = (*ps1 * gains1); - indx++; - } while (--loopcount); - } - } - else { /* Negative length, so do things backwards. */ - if (gains2 != 0) { /* Backwards, full mix. */ - do { - pdest = based + (maskd & (offd + indx)); - ps1 = bases1 + (masks1 & (offs1 + indx)); - ps2 = bases2 + (masks2 & (offs2 + indx)); - /* Mix from source1 and source 2. */ - *pdest = (*ps1 * gains1) + (*ps2 * gains2); - indx--; - } while (--loopcount); - } - else { /* Backwards, only read source 1 */ - do { - pdest = based + (maskd & (offd + indx)); - ps1 = bases1 + (masks1 & (offs1 + indx)); - /* Write from source1 to destination. */ - *pdest = (*ps1 * gains1); - indx--; - } while (--loopcount); - } - } - return; -} - -/*---------------------------------------------------------------------------*/ - -/* tablecopy functions - */ - -/* tablecopyset() - * - * Called at i time prior to the k rate function tablemix(). - * Similar function to tablemixset(). - */ - -int tablecopyset(CSOUND *csound, TABLECOPY *p) -{ - p->pdft = 0; - p->psft = 0; - return OK; -} - -/*-----------------------------------*/ -/* tablecopy() - * - * k rate version - see itablecopy() for the init time version. - * - * These two functions, and the docopy() function they share are - * simpler, faster, cut-down versions of their equivalent in the - * tablemix section above. Read the comments there for a full - * explanation. - */ -static int docopy(CSOUND *csound, TABLECOPY *p); - -int tablecopy(CSOUND *csound, TABLECOPY *p) -{ - /* Check the state of the two table number variables. - * Error message if any are < 1 and no further action. */ - if (UNLIKELY((*p->dft < 1) || (*p->sft < 1))) { - return csound->PerfError(csound, - Str("Table no. < 1 dft=%.2f sft=%.2f"), - *p->dft, *p->sft); - } - /* Check each table number in turn. */ - - /* Destination */ - if (p->pdft != (int)*p->dft) { - /* Get pointer to the function table data structure. - * csoundFTFindP() for perf time. csoundFTFind() for init time. - */ - if (UNLIKELY((p->funcd = csound->FTFindP(csound, p->dft)) == NULL)) { - return csound->PerfError(csound, - Str("Destination dft table %.2f not found."), - *p->dft); - } - /* Table number is valid. - * Save the integer version of the table number for future reference.*/ - p->pdft = (int)*p->dft; - } - /* Source */ - if (p->psft != (int)*p->sft) { - if (UNLIKELY((p->funcs = csound->FTFindP(csound, p->sft)) == NULL)) { - return csound->PerfError(csound, - Str("Source sft table %.2f not found."), - *p->sft); - } - p->psft = (int)*p->sft; - } - /* OK both tables present and the funcx pointers are pointing to - * their data structures. */ - docopy(csound, p); - return OK; -} - -/*-----------------------------------*/ - -int itablecopy(CSOUND *csound, TABLECOPY *p) -{ - /* Check the state of the two table number variables. - * Error message if any are < 1 and no further action. */ - if (UNLIKELY((*p->dft < 1) || (*p->sft < 1))) { - return csound->InitError(csound, - Str("Table no. < 1 dft=%.2f sft=%.2f"), - *p->dft, *p->sft); - } - /* Check each table number in turn. */ - - /* Destination */ - if (p->pdft != (int)*p->dft) { - /* Get pointer to the function table data structure. - * csoundFTFindP() for perf time. csoundFTFind() for init time. */ - if (UNLIKELY((p->funcd = csound->FTFind(csound, p->dft)) == NULL)) { - return csound->InitError(csound, - Str("Destination dft table %.2f not found."), - *p->dft); - } - /* Table number is valid. - * Save the integer version of the table number for future reference. */ - p->pdft = (int)*p->dft; - } - /* Source */ - if (p->psft != (int)*p->sft) { - if (UNLIKELY((p->funcs = csound->FTFind(csound, p->sft)) == NULL)) { - return csound->InitError(csound, - Str("Source sft table %.2f not found."), - *p->sft); - } - p->psft = (int)*p->sft; - } - /* OK both tables present and the funcx pointers are pointing to - * their data structures. */ - docopy(csound, p); - return OK; -} - -/*-----------------------------------*/ - -/* docopy() - * - * This is the business end oF tablecopy and itablecopy. - * - * See domix for full explanation. make any error messages here. - */ -static int docopy(CSOUND *csound, TABLECOPY *p) -{ - int32 loopcount; /* Loop counter. Set by the length of the dest table.*/ - int32 indx = 0; /* Index to be added to offsets */ - MYFLT *based, *bases; /* Base addresses of the two tables.*/ - int32 masks; /* Binary masks for the source table */ - MYFLT *pdest, *ps; - - loopcount = p->funcd->flen; - - /* Now get the base addresses and length masks of the tables. */ - based = p->funcd->ftable; - bases = p->funcs->ftable; - masks = p->funcs->lenmask; - - do { - /* Create source pointers by ANDing index with mask, and adding to base - * address. This causes source addresses to wrap around if the - * destination table is longer. - * Destination address is simply the index plus the base address since - * we know we will be writing within the table. */ - - pdest = based + indx; - ps = bases + (masks & indx); - *pdest = *ps; - indx++; - } while (--loopcount); - return OK; -} - -/*---------------------------------------------------------------------------*/ - - /* tablera functions */ - -/* tableraset() - * - * Called at i time prior to the k rate function tablemix(). - * Similar function to tablemixset(). Set the "previous table number" - * to 0, so that at the first k cycle, a positive table number - * will be recognised as a new value. - */ -int tableraset(CSOUND *csound, TABLERA *p) -{ - p->pfn = 0; - return OK; -} - -/*-----------------------------------*/ - -/* tablera() - * - * Read ksmps values from a table, starting at location kstart. - * Has an offset and wrap-around index calculation. - * - * Write them to an a rate destination. - * - * Table number is k rate, so check for it changing and for it being 0. - */ -int tablera(CSOUND *csound, TABLERA *p) -{ - MYFLT *writeloc, *readloc; - int32 kstart; - /* Local variable to hold integer version of offset, and the length - * mask for ANDing the total index - wrapping it into the table length. */ - int32 kioff, mask; - int loopcount; - - /* Check the state of the table number variable. - * Error message if it is < 1 and no further action. */ - if (UNLIKELY(*p->kfn < 1)) { - return csound->PerfError(csound, Str("Table kfn=%.2f < 1"), *p->kfn); - } - - if (p->pfn != (int)*p->kfn) { /* Check if the table number has changed. */ - /* Get pointer to the function table data structure. - * csoundFTFindP() for perf time. */ - - if (UNLIKELY((p->ftp = csound->FTFindP(csound, p->kfn)) == NULL)) { - return csound->PerfError(csound, Str("kfn table %.2f not found"), - *p->kfn); - } - /* Table number is valid. - * Save the integer version of the table number for future reference. */ - p->pfn = (int)*p->kfn; - - /* Check that the table length is equal to or greater than ksmps. - * Create error message if this is not so. We must ensure that - * the ksmps number of reads can fit within the length of the table. */ - - if (UNLIKELY(p->ftp->flen < csound->ksmps)) { - return csound->PerfError(csound, Str("Table kfn=%.2f length %ld " - "shorter than ksmps %d"), - *p->kfn, p->ftp->flen, csound->ksmps); - } - } - /* Check that kstart is within the range of the table. */ - - if (UNLIKELY(((kstart = (int32)*p->kstart) < 0L) || - (kstart >= p->ftp->flen))) { - return csound->PerfError(csound, Str("kstart %.2f is outside " - "table %.2f range 0 to %ld"), - *p->kstart, *p->kfn, p->ftp->flen - 1); - } - /* Set up the offset integer rounding float input argument to the next - * more negative integer. Also read the mask from the FUNC data structure. - */ - kioff = (int32)MYFLOOR(*p->koff); - mask = p->ftp->lenmask; - - /* We are almost ready to go, but first check to see whether - * ksmps loops from the starting point of kstart, will take us - * beyond the length of the table. - * - * Therefore calculate the number of loop cycles to perform. - * Eg. if kstart = 14, ksmps = 8 and table length = 16, then we only - * want to read 2 locations. - * - * koff is not considered here. It changes the read location - wrapped - * around the length of the table. It does not change the number of - * cycles of read/write. - */ - - if (UNLIKELY((loopcount = p->ftp->flen - kstart) > csound->ksmps)) { - /* If we are not going to exceed the length of the table, - * then loopcount = ksmps. */ - loopcount = csound->ksmps; - } - /* Otherwise it is the number of locations between kstart and - * the end of the table - as calculated above. */ - - /* Main loop: - * - * Write sequentially into the a rate variable. - * - * Read from masked totalindex in the table, where the total index - * is (kstart++ + kioff). */ - - /* Initialise write location to start of a rate destination array. */ - writeloc = p->adest; - /* Transfer the data, whilst updating pointers and masking to get - * final read address. */ - do { - readloc = p->ftp->ftable + ((kstart++ + kioff) & mask); - *writeloc++ = *readloc; - } while (--loopcount); - return OK; -} - -/*---------------------------------------------------------------------------*/ - -/* tablewa functions - */ - -/* tablewaset() - * - * Called at i time prior to the k rate function tablemix(). - * Same function to tablerset(). - */ -int tablewaset(CSOUND *csound, TABLEWA *p) -{ - p->pfn = 0; - return OK; -} - -/*-----------------------------------*/ - -/* tablewa() - * - * Read ksmps values from an a rate variable and write them into a - * table, starting at location kstart. - * - * Similar to tablera() above, except that writing is from a rate to table - * and we rewrite kstart. - */ - -int tablewa(CSOUND *csound, TABLEWA *p) -{ - MYFLT *writeloc, *readloc; - int32 kstart; - int32 kioff; /* integer version of offset */ - int32 mask; /* length mask for ANDing the total index */ - int32 loopcount; - - /* From here the main loop, (except where noted "!!") this code is - * the same as tablera above. It is not in a common subroutine - * for speed reasons and because there are several local variables for - * tablewa() that need to be written. */ - - /* Check the state of the table number variable. - * Error message if it is < 1 and no further action. */ - if (UNLIKELY(*p->kfn < 1)) { - return csound->PerfError(csound, Str("Table kfn=%.2f < 1"), *p->kfn); - } - - if (p->pfn != (int)*p->kfn) { /* Check if the table number has changed. */ - /* Get pointer to the function table data structure. - * csoundFTFindP() for perf time. */ - - if (UNLIKELY((p->ftp = csound->FTFindP(csound, p->kfn)) == NULL)) { - return csound->PerfError(csound, Str("kfn table %.2f not found"), - *p->kfn); - } - /* Table number is valid. - * Save the integer version of the table number for future reference. - */ - p->pfn = (int)*p->kfn; - - /* Check that the table length is equal to or greater than ksmps. - * Create error message if this is not so. We must ensure that - * the ksmps number of reads can fit within the length of the table. */ - - if (UNLIKELY(p->ftp->flen < csound->ksmps)) { - return csound->PerfError(csound, Str("Table kfn=%.2f length %ld " - "shorter than ksmps %d"), - *p->kfn, p->ftp->flen, csound->ksmps); - } - } - - /* Check that kstart is within the range of the table. */ - if (UNLIKELY(((kstart = (int32)*p->kstart) < 0L) || - (kstart >= p->ftp->flen))) { - return csound->PerfError(csound, Str("kstart %.2f is outside " - "table %.2f range 0 to %ld"), - *p->kstart, *p->kfn, p->ftp->flen - 1); - } - /* Set up the offset integer rounding float input argument to the next - * more negative integer. Also read the mask from the FUNC data structure. - */ - kioff = (int32)MYFLOOR(*p->koff); - mask = p->ftp->lenmask; - /* !! end of code identical to tablera. */ - - /* We are almost ready to go, but first check to see whether - * ksmps loops from the starting point of kstart, will take us - * beyond the length of the table. - * - * Therefore calculate the number of loop cycles to perform. - * Eg. if kstart = 14, ksmps = 8 and table length = 16, then we only - * want to read 2 locations. - * - * koff is not considered here. It changes the read location - wrapped - * around the length of the table. It does not change the number of - * cycles of read/write. - */ - - if (UNLIKELY((p->ftp->flen - kstart) > csound->ksmps)) { - /* If we are not going to exceed the length of the table, then - * loopcount = ksmps. */ - loopcount = csound->ksmps; - - /* Write the kstart i/o variable to be ksmps higher than before. */ - *p->kstart += csound->ksmps; - } - else { - loopcount = p->ftp->flen - kstart; - - /* Otherwise loopcount is the number of locations between kstart and - * the end of the table - as calculated above. - * - * We have hit the end of the process of stepping kstart up by ksmps. - * Set it to 0 so the next time this ugen is run, with the same variable - * the cycle will start from the start of the table. - */ - *p->kstart = FL(0.0); - } - - /* Main loop: - * - * Read sequentially from the a rate variable. - * - * Write to masked total index in the table, where the total index - * is (kstart++ + kioff). - */ - - /* Initialise read location to start of a rate source array. - */ - readloc = p->asig; - /* Transfer the data, whilst updating pointers and masking to get - * final write address. - */ - do { - writeloc = p->ftp->ftable + ((kstart++ + kioff) & mask); - *writeloc = *readloc++; - } while (--loopcount); - return OK; -} - /*****************************************************************************/ /*****************************************************************************/ @@ -2153,13 +90,16 @@ csound->zklast = (int32) *p->isizek; length = (csound->zklast + 1L) * sizeof(MYFLT); + csound->zkstart = (MYFLT*) mcalloc(csound, length); + /* Likewise, allocate memory for za space, but do it in arrays of * length ksmps. * This is all set to 0 and there will be an error report if the * memory cannot be allocated. */ csound->zalast = (int32) *p->isizea; - length = (csound->zalast + 1L) * sizeof(MYFLT) * csound->ksmps; + + length = (csound->zalast + 1L) * sizeof(MYFLT) * CS_KSMPS; csound->zastart = (MYFLT*) mcalloc(csound, length); return OK; } @@ -2252,10 +192,12 @@ /* Check to see this index is within the limits of zk space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zklast)) { - return csound->PerfError(csound, Str("zkw index > isizek. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zkw index > isizek. Not writing.")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("zkw index < 0. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zkw index < 0. Not writing.")); } else { MYFLT *writeloc; @@ -2306,11 +248,12 @@ /* Check to see this index is within the limits of zk space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zklast)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zkwm index > isizek. Not writing.")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("zkwm index < 0. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zkwm index < 0. Not writing.")); } else { MYFLT *writeloc; @@ -2389,7 +332,7 @@ /* Check to see this index is within the limits of zk space. */ if (UNLIKELY(indx > csound->zklast)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zkmod kzkmod > isizek. Not writing.")); } else { @@ -2415,14 +358,14 @@ /* Check to see both kfirst and klast are within the limits of zk space * and that last is >= first. */ if (UNLIKELY((first > csound->zklast) || (last > csound->zklast))) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zkcl first or last > isizek. Not clearing.")); else if (UNLIKELY((first < 0) || (last < 0))) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zkcl first or last < 0. Not clearing.")); } else if (UNLIKELY(first > last)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zkcl first > last. Not clearing.")); } else { @@ -2461,7 +404,9 @@ { MYFLT *readloc, *writeloc; int32 indx; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; /*-----------------------------------*/ @@ -2471,17 +416,25 @@ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { memset(writeloc, 0, nsmps*sizeof(MYFLT)); - return csound->PerfError(csound, Str("zar index > isizea. Returning 0.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zar index > isizea. Returning 0.")); } else if (UNLIKELY(indx < 0)) { memset(writeloc, 0, nsmps*sizeof(MYFLT)); - return csound->PerfError(csound, Str("zar index < 0. Returning 0.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zar index < 0. Returning 0.")); } else { /* Now read from the array in za space and write to the destination. * See notes in zkr() on pointer arithmetic. */ - readloc = csound->zastart + (indx * csound->ksmps); - memcpy(writeloc, readloc, nsmps*sizeof(MYFLT)); + readloc = csound->zastart + (indx * CS_KSMPS); + if (UNLIKELY(offset)) memset(writeloc, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&writeloc[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&writeloc[offset], &readloc[offset], (nsmps-offset)*sizeof(MYFLT)); + } return OK; } @@ -2495,7 +448,9 @@ MYFLT *readloc, *writeloc; MYFLT kgain; /* Gain control */ int32 indx; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /*-----------------------------------*/ @@ -2506,19 +461,25 @@ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { memset(writeloc, 0, nsmps*sizeof(MYFLT)); - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zarg index > isizea. Returning 0.")); } else { if (UNLIKELY(indx < 0)) { memset(writeloc, 0, nsmps*sizeof(MYFLT)); - return csound->PerfError(csound, Str("zarg index < 0. Returning 0.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zarg index < 0. Returning 0.")); } else { /* Now read from the array in za space multiply by kgain and write * to the destination. */ - readloc = csound->zastart + (indx * csound->ksmps); - for (n=0; nzastart + (indx * CS_KSMPS); + if (UNLIKELY(offset)) memset(writeloc, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&writeloc[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; /* Set up the pointer for the source of data to write. */ readloc = p->sig; /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zaw index > isizea. Not writing.")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("zaw index < 0. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zaw index < 0. Not writing.")); } else { /* Now write to the array in za space pointed to by indx. */ - writeloc = csound->zastart + (indx * csound->ksmps); - memcpy(writeloc, readloc, nsmps*sizeof(MYFLT)); + writeloc = csound->zastart + (indx * CS_KSMPS); + if (UNLIKELY(offset)) memset(writeloc, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&writeloc[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&writeloc[offset], &readloc[offset], (nsmps-offset)*sizeof(MYFLT)); } return OK; } @@ -2565,7 +534,9 @@ { MYFLT *readloc, *writeloc; int32 indx; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /*-----------------------------------*/ /* Set up the pointer for the source of data to write. */ @@ -2574,22 +545,30 @@ /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { - return csound->PerfError(csound, Str("zaw index > isizea. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zaw index > isizea. Not writing.")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("zaw index < 0. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("zaw index < 0. Not writing.")); } else { /* Now write to the array in za space pointed to by indx. */ - writeloc = csound->zastart + (indx * csound->ksmps); + writeloc = csound->zastart + (indx * CS_KSMPS); if (*p->mix == 0) { /* Normal write mode. */ - memcpy(writeloc, readloc, nsmps*sizeof(MYFLT)); + if (UNLIKELY(offset)) memset(writeloc, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&writeloc[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&writeloc[offset], &readloc[offset], (nsmps-offset)*sizeof(MYFLT)); } else { /* Mix mode - add to the existing value. */ - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* Make a local copy of the pointer to the input signal, so we can auto- * increment it. Likewise the location to write the result to. */ readsig = p->sig; writeloc = p->rslt; + if (UNLIKELY(offset)) memset(writeloc, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&writeloc[nsmps], '\0', early*sizeof(MYFLT)); + } /* If zkmod = 0, then just copy input to output. */ if ((indx = (int32) *p->zamod) == 0) { - memcpy(writeloc, readsig, nsmps*sizeof(MYFLT)); -/* do { */ -/* *writeloc++ = *readsig++; */ -/* } while (--nsmps); */ + memcpy(&writeloc[offset], &readsig[offset], (nsmps-offset)*sizeof(MYFLT)); return OK; } /* Decide whether index is positive or negative. Make it postive. */ @@ -2629,18 +612,19 @@ } /* Check to see this index is within the limits of za space. */ if (UNLIKELY(indx > csound->zalast)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zamod kzamod > isizea. Not writing.")); } else { /* Now read the values from za space. */ - readloc = csound->zastart + (indx * csound->ksmps); + readloc = csound->zastart + (indx * CS_KSMPS); + if (UNLIKELY(early)) nsmps -= early; if (mflag == 0) { - for (n=0; n= first. */ if (UNLIKELY((first > csound->zalast) || (last > csound->zalast))) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zacl first or last > isizea. Not clearing.")); else { if (UNLIKELY((first < 0) || (last < 0))) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zacl first or last < 0. Not clearing.")); } else { if (UNLIKELY(first > last)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("zacl first > last. Not clearing.")); } else { /* Now clear the appropriate locations in za space. */ - loopcount = (last - first + 1) * csound->ksmps; - writeloc = csound->zastart + (first * csound->ksmps); + loopcount = (last - first + 1) * CS_KSMPS; + writeloc = csound->zastart + (first * CS_KSMPS); memset(writeloc, 0, loopcount*sizeof(MYFLT)); } } @@ -2701,7 +685,7 @@ int timek(CSOUND *csound, RDTIME *p) { /* Read the global variable kcounter and turn it into a float. */ - *p->rslt = (MYFLT) csound->kcounter; + *p->rslt = (MYFLT) CS_KCNT; return OK; } @@ -2710,7 +694,7 @@ { /* Read the global variable kcounter divide it by the k rate. */ - *p->rslt = (MYFLT) csound->kcounter * csound->onedkr; + *p->rslt = (MYFLT) CS_KCNT * CS_ONEDKR; return OK; } @@ -2724,7 +708,7 @@ */ int instimset(CSOUND *csound, RDTIME *p) { - p->instartk = csound->kcounter; + p->instartk = CS_KCNT; *p->rslt = FL(0.0); return OK; } @@ -2736,7 +720,7 @@ */ int instimek(CSOUND *csound, RDTIME *p) { - *p->rslt = (MYFLT) (csound->kcounter - p->instartk); + *p->rslt = (MYFLT) (CS_KCNT - p->instartk); return OK; } @@ -2747,7 +731,7 @@ */ int instimes(CSOUND *csound, RDTIME *p) { - *p->rslt = (MYFLT) (csound->kcounter - p->instartk) * csound->onedkr; + *p->rslt = (MYFLT) (CS_KCNT - p->instartk) * CS_ONEDKR; return OK; } @@ -2763,8 +747,8 @@ /* Set up ctime so that if it was 0 or negative, it is set to a low value * to ensure that the print cycle happens every k cycle. This low value is * 1 / ekr */ - if (*p->ptime < csound->onedkr) - p->ctime = csound->onedkr; + if (*p->ptime < CS_ONEDKR) + p->ctime = CS_ONEDKR; else p->ctime = *p->ptime; @@ -2780,7 +764,7 @@ /* Set the initime variable - how many seconds in absolute time * when this instance of the instrument was initialised. */ - p->initime = (MYFLT) csound->kcounter * csound->onedkr; + p->initime = (MYFLT) CS_KCNT * CS_ONEDKR; /* Set cysofar to - 1 so that on the first call to printk - when * cycle = 0, then there will be a print cycle. */ @@ -2803,8 +787,8 @@ /* Initialise variables. */ if (UNLIKELY(p->initialised != -1)) - csound->PerfError(csound, Str("printk not initialised")); - timel = ((MYFLT) csound->kcounter * csound->onedkr) - p->initime; + csound->PerfError(csound, p->h.insdshead, Str("printk not initialised")); + timel = ((MYFLT) CS_KCNT * CS_ONEDKR) - p->initime; /* Divide the current elapsed time by the cycle time and round down to * an integer. @@ -2844,48 +828,18 @@ #define ESC (0x1B) /* printksset is called when the instance of the instrument is initiallised. */ -int printksset(CSOUND *csound, PRINTKS *p) +int printksset_(CSOUND *csound, PRINTKS *p, char *sarg) { - char *sarg; char *sdest; char temp, tempn; p->initialised = -1; - if (*p->ptime < csound->onedkr) - p->ctime = csound->onedkr; + if (*p->ptime < CS_ONEDKR) + p->ctime = CS_ONEDKR; else p->ctime = *p->ptime; - - /* Set the initime variable - how many seconds in absolute time - * when this instance of the instrument was initialised. */ - - p->initime = (MYFLT) csound->kcounter * csound->onedkr; - - /* Set cysofar to - 1 so that on the first call to printk - when - * cycle = 0, then there will be a print cycle. */ + p->initime = (MYFLT) CS_KCNT * CS_ONEDKR; p->cysofar = -1; - - /* Set up the string to print. printf() will take care of the - * %f format specifiers, but we need to decode any other special - * codes we may want to put in here. - */ - - /* We get the string via the same mechanism used in ugens3.c for - * adsyn(). I have not checked everything which stands behind this. - */ - - /* If it was not valid string, then complain. - * Also complain if the string has nothing in it. However the - * program (under DJGPP at least) seems to crash elsewhere if - * the first parameter is "". */ - - if (!p->XSTRCODE && - (*p->ifilcod != SSTRCOD || csound->currevent->strarg == NULL)) { - return csound->InitError(csound, - Str("printks param 1 was not a \"quoted string\"")); - } - else { - sarg = (p->XSTRCODE ? (char*) p->ifilcod : csound->currevent->strarg); memset(p->txtstring, 0, 8192); /* This line from matt ingalls */ sdest = p->txtstring; /* Copy the string to the storage place in PRINTKS. @@ -2990,24 +944,36 @@ /* Increment pointer and process next character until end of string. */ ++sarg; } - } + return OK; } +int printksset_S(CSOUND *csound, PRINTKS *p){ + char *sarg; + sarg = ((STRINGDAT*)p->ifilcod)->data; + if(sarg == NULL) return csoundInitError(csound, Str("null string\n")); + p->old = cs_strdup(csound, sarg); + return printksset_(csound, p, sarg); +} + +int printksset(CSOUND *csound, PRINTKS *p){ + return printksset_(csound, p, get_arg_string(csound, *p->ifilcod)); +} + + /* perform a sprintf-style format -- matt ingalls */ void sprints(char *outstring, char *fmt, MYFLT **kvals, int32 numVals) { char strseg[8192]; int i = 0, j = 0; char *segwaiting = 0; - while (*fmt) { if (*fmt == '%') { /* if already a segment waiting, then lets print it */ if (segwaiting) { MYFLT xx = (j>=numVals? FL(0.0) : *kvals[j]); - /* printf("***xx = %f (int)(xx+.5)=%d round=%d\n", */ - /* xx, (int)(xx+.5), MYFLT2LRND(xx)); */ + /* printf("***xx = %f (int)(xx+.5)=%d round=%d mode=%d\n", */ + /* xx, (int)(xx+.5), MYFLT2LRND(xx), fegetround()); */ strseg[i] = '\0'; switch (*segwaiting) { @@ -3028,7 +994,7 @@ break; default: - sprintf(outstring, strseg, xx); + CS_SPRINTF(outstring, strseg, xx); break; } outstring += strlen(outstring); @@ -3057,7 +1023,9 @@ strseg[i] = '\0'; if (segwaiting) { MYFLT xx = (j>=numVals? FL(0.0) : *kvals[j]); - switch (*segwaiting) { + /* printf("***xx = %f (int)(xx+.5)=%d round=%d mode=%d\n", */ + /* xx, (int)(xx+.5), MYFLT2LRND(xx), fegetround()); */ + switch (*segwaiting) { case 'd': case 'i': case 'o': @@ -3065,17 +1033,17 @@ case 'X': case 'u': case 'c': - sprintf(outstring, strseg, (int)(xx+FL(0.5))); + sprintf(outstring, strseg, (int)MYFLT2LRND(xx)); break; case 'h': - sprintf(outstring, strseg, (int16)(xx+FL(0.5))); + sprintf(outstring, strseg, (int16)MYFLT2LRND(xx)); break; case 'l': - sprintf(outstring, strseg, (int32)(xx+FL(0.5))); + sprintf(outstring, strseg, (int32)MYFLT2LRND(xx)); break; default: - sprintf(outstring, strseg, xx); + CS_SPRINTF(outstring, strseg, xx); break; } } @@ -3096,10 +1064,22 @@ int32 cycles; char string[8192]; /* matt ingals replacement */ + if (ISSTRCOD(*p->ifilcod) == 0) { + char *sarg; + sarg = ((STRINGDAT*)p->ifilcod)->data; + if (strcmp(sarg, p->old) != 0) { + if (sarg == NULL) + return csoundPerfError(csound, p->h.insdshead, Str("null string\n")); + printksset_(csound, p, sarg); + mfree(csound, p->old); + p->old = cs_strdup(csound, sarg); + } + } + /*-----------------------------------*/ if (UNLIKELY(p->initialised != -1)) - csound->PerfError(csound, Str("printks not initialised")); - timel = ((MYFLT) csound->kcounter * csound->onedkr) - p->initime; + csound->PerfError(csound, p->h.insdshead, Str("printks not initialised")); + timel = ((MYFLT) CS_KCNT * CS_ONEDKR) - p->initime; /* Divide the current elapsed time by the cycle time and round down to * an integer. */ @@ -3112,7 +1092,7 @@ /* Do the print cycle. */ string[0]='\0'; /* incase of empty string */ sprints(string, p->txtstring, p->kvals, p->INOCOUNT-2); - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", string); + csound->MessageS(csound, CSOUNDMSG_ORCH, string); } return OK; } @@ -3129,7 +1109,22 @@ pk.ptime = &ptime; printksset(csound, &pk); sprints(string, pk.txtstring, p->kvals, p->INOCOUNT-1); - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", string); + csound->MessageS(csound, CSOUNDMSG_ORCH, string); + return OK; +} + +int printsset_S(CSOUND *csound, PRINTS *p) +{ + PRINTKS pk; + char string[8192]; + MYFLT ptime = 1; + string[0] = '\0'; /* necessary as sprints is not nice */ + pk.h = p->h; + pk.ifilcod = p->ifilcod; + pk.ptime = &ptime; + printksset_S(csound, &pk); + sprints(string, pk.txtstring, p->kvals, p->INOCOUNT-1); + csound->MessageS(csound, CSOUNDMSG_ORCH, string); return OK; } @@ -3154,15 +1149,17 @@ * Similar to peakk, but looks at an a rate input variable. */ int peaka(CSOUND *csound, PEAK *p) { - int loop, n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *peak, pp; MYFLT *asigin; - loop = csound->ksmps; asigin = p->xsigin; peak = p->kpeakout; pp = *peak; - for (n=0;nnchnls; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY((indx + csound->nchnls) >= csound->zalast)) goto err1; else if (UNLIKELY(indx < 0)) goto err2; else { MYFLT *writeloc; - int n = csound->ksmps; /* Now write to the array in za space pointed to by indx. */ - writeloc = csound->zastart + (indx * n); + writeloc = csound->zastart + (indx * nsmps); + early = nsmps - early; for (i = 0; i < nchns; i++) - for (nsmps = 0; nsmps < n; nsmps++) - *writeloc++ = csound->spin[i * n + nsmps]; + for (n = 0; n < nsmps; n++) + *writeloc++ = ((n>=offset && nPerfError(csound, Str("inz index > isizea. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("inz index > isizea. Not writing.")); err2: - return csound->PerfError(csound, Str("inz index < 0. Not writing.")); + return csound->PerfError(csound, p->h.insdshead, + Str("inz index < 0. Not writing.")); } /* outz reads from za space at a rate to output. */ @@ -3239,7 +1241,9 @@ { int32 indx; int i; - int nsmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int nchns = csound->nchnls; /* Check to see this index is within the limits of za space. */ @@ -3248,25 +1252,32 @@ else if (UNLIKELY(indx < 0)) goto err2; else { MYFLT *readloc; - int n = csound->ksmps; /* Now read from the array in za space and write to the output. */ - readloc = csound->zastart + (indx * csound->ksmps); + readloc = csound->zastart + (indx * CS_KSMPS); + early = nsmps-early; if (!csound->spoutactive) { for (i = 0; i < nchns; i++) - for (nsmps = 0; nsmps < n; nsmps++) - csound->spout[i * n + nsmps] = *readloc++; + for (n = 0; n < nsmps; n++) { + CS_SPOUT[i * nsmps + n] = ((n>=offset && nspoutactive = 1; } else { for (i = 0; i < nchns; i++) - for (nsmps = 0; nsmps < n; nsmps++) - csound->spout[i * n + nsmps] += *readloc++; + for (n = 0; n < nsmps; n++) { + CS_SPOUT[i * n + nsmps] += ((n>=offset && nPerfError(csound, Str("outz index > isizea. No output")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index > isizea. No output")); err2: - return csound->PerfError(csound, Str("outz index < 0. No output.")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index < 0. No output.")); } - diff -Nru csound-5.17.11~dfsg/OOps/ugrw2.c csound-6.02~dfsg/OOps/ugrw2.c --- csound-5.17.11~dfsg/OOps/ugrw2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugrw2.c 2014-01-07 16:53:47.000000000 +0000 @@ -40,6 +40,8 @@ * any alterations to the source code, including comments, are * clearly indicated as such. */ +#if SOME_FINE_DAY + #include "ugrw2.h" #include @@ -163,12 +165,6 @@ * */ -/* ! ! ! ! - * - * See the end of this file for details of what other things to - * add to entry.c and how to tweak the makefile. - */ - /*---------------------------------------------------------------------------*/ /* kport = portamento @@ -199,8 +195,10 @@ * c1 = 1 - c2 * */ + /* This previous comment is WRONG; do not be misled -- JPff */ + if (UNLIKELY(p->prvhtim != *p->khtim)) { - p->c2 = POWER(FL(0.5), csound->onedkr / *p->khtim); + p->c2 = POWER(FL(0.5), CS_ONEDKR / *p->khtim); p->c1 = FL(1.0) - p->c2; p->prvhtim = *p->khtim; } @@ -237,8 +235,9 @@ * tpidsr = 2 * pi / a sample rate * so tpidsr * ksmps = 2 * pi / k rate. * We need this since we are filtering at k rate, not a rate. */ + /* This previous comment is WRONG; do not be misled -- JPff */ - b = FL(2.0) - COS(*p->khp * csound->tpidsr * csound->ksmps); + b = FL(2.0) - COS(*p->khp * csound->tpidsr * CS_KSMPS); p->c2 = b - SQRT(b * b - FL(1.0)); p->c1 = FL(1.0) - p->c2; } @@ -257,7 +256,7 @@ if (UNLIKELY(*p->khp != p->prvhp)) { MYFLT b; p->prvhp = *p->khp; - b = FL(2.0) - COS(*p->khp * csound->tpidsr * csound->ksmps); + b = FL(2.0) - COS(*p->khp * csound->tpidsr * CS_KSMPS); p->c2 = b - SQRT(b * b - FL(1.0)); p->c1 = FL(1.0) - p->c2; } @@ -303,7 +302,7 @@ * cosf = cos (2pi * freq / krate) */ if (UNLIKELY(*p->kcf != p->prvcf)) { p->prvcf = *p->kcf; - p->cosf = COS(*p->kcf * csound->tpidsr * csound->ksmps); + p->cosf = COS(*p->kcf * csound->tpidsr * CS_KSMPS); flag = 1; } @@ -311,7 +310,7 @@ * c3 = exp (-2pi * bwidth / krate) */ if (UNLIKELY(*p->kbw != p->prvbw)) { p->prvbw = *p->kbw; - p->c3 = EXP(*p->kbw * csound->mtpdsr * csound->ksmps); + p->c3 = EXP(*p->kbw * csound->mtpdsr * CS_KSMPS); flag = 1; } /* Final calculations for the factors @@ -369,28 +368,28 @@ int kareson(CSOUND *csound, KRESON *p) { int flag = 0; - MYFLT c3p1, c3t4, omc3, c2sqr, D = FL(2.0); /* 1/RMS = root2 (rand) */ + MYFLT c3p1, c3t4, omc3, c2sqr /*,D = FL(2.0)*/; /* 1/RMS = root2 (rand) */ /* or 1/.5 (sine) */ if (UNLIKELY(*p->kcf != p->prvcf)) { p->prvcf = *p->kcf; - p->cosf = COS(*p->kcf * csound->tpidsr * csound->ksmps); + p->cosf = COS(*p->kcf * csound->tpidsr * CS_KSMPS); flag = 1; } if (UNLIKELY(*p->kbw != p->prvbw)) { p->prvbw = *p->kbw; - p->c3 = EXP(*p->kbw * csound->mtpdsr * csound->ksmps); + p->c3 = EXP(*p->kbw * csound->mtpdsr * CS_KSMPS); flag = 1; } if (UNLIKELY(flag)) { c3p1 = p->c3 + FL(1.0); c3t4 = p->c3 * FL(4.0); - omc3 = 1 - p->c3; + omc3 = FL(1.0) - p->c3; p->c2 = c3t4 * p->cosf / c3p1; c2sqr = p->c2 * p->c2; if (p->scale == 1) /* i.e. 1 - A(reson) */ p->c1 = FL(1.0) - omc3 * SQRT(FL(1.0) - c2sqr / c3t4); else if (p->scale == 2) /* i.e. D - A(reson) */ - p->c1 = D - SQRT((c3p1*c3p1-c2sqr)*omc3/c3p1); + p->c1 = FL(2.0) - SQRT((c3p1*c3p1-c2sqr)*omc3/c3p1); else p->c1 = FL(0.0); /* cannot tell */ } @@ -405,7 +404,7 @@ { *p->kr = p->c1 * *p->ksig + p->c2 * p->yt1 - p->c3 * p->yt2; p->yt2 = p->yt1; - p->yt1 = *p->kr - D * *p->ksig; /* yt1 contains yt1-D*xt1 */ + p->yt1 = *p->kr - (*p->ksig + *p->ksig); /* yt1 contains yt1-D*xt1 */ } return OK; } @@ -416,15 +415,6 @@ /* limit and ilimit */ -/* int limitset(CSOUND *csound, LIMIT *p) */ -/* /\* Because we are using Csounds facility (thread = 7) for deciding */ -/* * whether this is a or k rate, we must provide an init time setup */ -/* * function. In this case, we have nothing to do. *\/ */ -/* { */ - -/* return OK; */ -/* } */ - /* klimit() * * Used for k and i rate variables. @@ -445,7 +435,7 @@ * the mid point between them. */ if ( (xlow = *p->xlow) >= (xhigh = *p->xhigh) ) { - *p->xdest = FL(0.5) * (xlow + xhigh); /* times 0.2 rather that /2 -- JPff */ + *p->xdest = FL(0.5) * (xlow + xhigh); /* times 0.5 rather that /2 -- JPff */ } else { if (xsig > xhigh) @@ -466,7 +456,9 @@ { MYFLT *adest, *asig; MYFLT xlow, xhigh, xaverage, xsig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /*-----------------------------------*/ /* Optimise for speed when xsig is within the limits. */ @@ -480,14 +472,19 @@ * Whilst doing the test, load the limit local variables. */ + if (UNLIKELY(offset)) memset(adest, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early))) { + nsmps -= early; + memset(&adest[nsmps], '\0', early*sizeof(MYFLT)); + } if ((xlow = *p->xlow) >= (xhigh = *p->xhigh)) { - xaverage = (xlow + xhigh) * FL(0.5);/* times 0.2 rather that /2 -- JPff */ - for (n=0; n= xlow)) { /* xsig was within the limits. */ @@ -503,3 +500,4 @@ return OK; } +#endif /* SOME_FINE_DAY */ diff -Nru csound-5.17.11~dfsg/OOps/ugtabs.c csound-6.02~dfsg/OOps/ugtabs.c --- csound-5.17.11~dfsg/OOps/ugtabs.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/OOps/ugtabs.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,864 @@ +/* + ugtabs.c: new implementation of table readers and writers + + Copyright (C) 2013 V Lazzarini + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include "csoundCore.h" +#include "ugtabs.h" +#include + +//(x >= FL(0.0) ? (int32)x : (int32)((double)x - 0.99999999)) +#define MYFLOOR(x) FLOOR(x) + +int tabler_init(CSOUND *csound, TABL *p) { + + int ndx, len; + int mask; + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->InitError(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + mask = p->ftp->lenmask; + p->np2 = mask ? 0 : 1; + len = p->ftp->flen; + + if (*p->mode) + p->mul = len; + else + p->mul = 1; + + ndx = FLOOR((*p->ndx + *p->offset)*p->mul); + if (*p->wrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + *p->sig = p->ftp->ftable[ndx]; + return OK; +} + +int tabl_setup(CSOUND *csound, TABL *p) { + + if (UNLIKELY(p->XOUTCODE && p->XINCODE != p->XOUTCODE)) { + if (CS_KSMPS != 1) + return csound->InitError(csound, + Str("table: index type inconsistent with output")); + } + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->InitError(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + p->iwrap = (int32) *p->wrap; + return OK; +} + +int tabler_kontrol(CSOUND *csound, TABL *p) { + int ndx, len = p->len; + int mask = p->ftp->lenmask; + IGN(csound); + + ndx = MYFLOOR((*p->ndx + *p->offset)*p->mul); + if (p->iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + *p->sig = p->ftp->ftable[ndx]; + return OK; +} + + + +int tabler_audio(CSOUND *csound, TABL *p) +{ + int ndx, len = p->len, n, nsmps = CS_KSMPS; + int mask = p->ftp->lenmask; + MYFLT *sig = p->sig; + MYFLT *ndx_f = p->ndx; + MYFLT *func = p->ftp->ftable; + MYFLT offset = *p->offset; + MYFLT mul = p->mul; + int32 iwrap = p->iwrap; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + if (UNLIKELY(koffset)) memset(sig, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&sig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for (n=koffset; n < nsmps; n++) { + ndx = MYFLOOR((ndx_f[n] + offset)*mul); + if (iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + p->sig[n] = func[ndx]; + } + return OK; +} + +int tableir_init(CSOUND *csound, TABL *p) { + + int ndx, len; + int mask; + MYFLT tmp, frac; + MYFLT x1, x2; + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->InitError(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + mask = p->ftp->lenmask; + p->np2 = mask ? 0 : 1; + len = p->ftp->flen; + + if (*p->mode) + p->mul = len; + else + p->mul = 1; + + tmp = (*p->ndx + *p->offset)*p->mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + + if (*p->wrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + x1 = p->ftp->ftable[ndx]; + x2 = p->ftp->ftable[ndx+1]; + *p->sig = x1 + (x2 - x1)*frac; + return OK; +} + + + +int tableir_kontrol(CSOUND *csound, TABL *p) { + int ndx, len = p->len; + int mask = p->ftp->lenmask; + MYFLT tmp, frac; + MYFLT x1, x2; + IGN(csound); + + tmp = (*p->ndx + *p->offset)*p->mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + + if (p->iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + x1 = p->ftp->ftable[ndx]; + x2 = p->ftp->ftable[ndx+1]; + *p->sig = x1 + (x2 - x1)*frac; + return OK; +} + +int tableir_audio(CSOUND *csound, TABL *p) +{ + int ndx, len = p->len, n, nsmps = CS_KSMPS; + int mask = p->ftp->lenmask; + MYFLT *sig = p->sig; + MYFLT *ndx_f = p->ndx; + MYFLT *func = p->ftp->ftable; + MYFLT offset = *p->offset; + MYFLT mul = p->mul, tmp, frac; + int32 iwrap = p->iwrap; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + if (UNLIKELY(koffset)) memset(sig, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&sig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for (n=koffset; n < nsmps; n++) { + MYFLT x1, x2; + tmp = (ndx_f[n] + offset)*mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + if (iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + x1 = func[ndx]; + x2 = func[ndx+1]; + p->sig[n] = x1 + (x2 - x1)*frac; + } + return OK; +} + +int table3r_init(CSOUND *csound, TABL *p) { + + int ndx, len; + int mask; + MYFLT tmp, frac; + MYFLT x0, x1, x2, x3; + MYFLT fracub, fracsq, temp1; + MYFLT *func; + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->InitError(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + mask = p->ftp->lenmask; + p->np2 = mask ? 0 : 1; + len = p->ftp->flen; + func =p->ftp->ftable; + + if (*p->mode) + p->mul = len; + else + p->mul = 1; + + tmp = (*p->ndx + *p->offset)*p->mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + + if (*p->wrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + if (UNLIKELY(ndx<1 || ndx==len-1 || len <4)) { + x1 = func[ndx]; + x2 = func[ndx+1]; + *p->sig = x1 + (x2 - x1)*frac; + } else { + x0 = func[ndx-1]; + x1 = func[ndx]; + x2 = func[ndx+1]; + x3 = func[ndx+2]; + fracsq = frac*frac; + fracub = fracsq*x0; + temp1 = x3+FL(3.0)*x1; + *p->sig = x1 + FL(0.5)*fracub + + frac*(x2 - fracub/FL(6.0) - temp1/FL(6.0) - x0/FL(3.0)) + + frac*fracsq*(temp1/FL(6.0) - FL(0.5)*x2) + fracsq*(FL(0.5)*x2 - x1); + } + return OK; +} + + + +int table3r_kontrol(CSOUND *csound, TABL *p) { + int ndx, len = p->len; + int mask = p->ftp->lenmask; + MYFLT tmp, frac; + MYFLT x0, x1, x2, x3; + MYFLT *func =p->ftp->ftable; + MYFLT fracub, fracsq, temp1; + + IGN(csound); + + tmp = (*p->ndx + *p->offset)*p->mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + + if (p->iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + if (UNLIKELY(ndx<1 || ndx==len-1 || len <4)) { + x1 = func[ndx]; + x2 = func[ndx+1]; + *p->sig = x1 + (x2 - x1)*frac; + } else { + x0 = func[ndx-1]; + x1 = func[ndx]; + x2 = func[ndx+1]; + x3 = func[ndx+2]; + fracsq = frac*frac; + fracub = fracsq*x0; + temp1 = x3+FL(3.0)*x1; + *p->sig = x1 + FL(0.5)*fracub + + frac*(x2 - fracub/FL(6.0) - temp1/FL(6.0) - x0/FL(3.0)) + + frac*fracsq*(temp1/FL(6.0) - FL(0.5)*x2) + fracsq*(FL(0.5)*x2 - x1); + } + return OK; +} + +int table3r_audio(CSOUND *csound, TABL *p) +{ + int ndx, len = p->len, n, nsmps = CS_KSMPS; + int mask = p->ftp->lenmask; + MYFLT *sig = p->sig; + MYFLT *ndx_f = p->ndx; + MYFLT *func = p->ftp->ftable; + MYFLT offset = *p->offset; + MYFLT mul = p->mul, tmp, frac; + int32 iwrap = p->iwrap; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + if (UNLIKELY(koffset)) memset(sig, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&sig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for (n=koffset; n < nsmps; n++) { + MYFLT x0,x1,x2,x3,temp1,fracub,fracsq; + tmp = (ndx_f[n] + offset)*mul; + ndx = MYFLOOR(tmp); + frac = tmp - ndx; + if (iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + + if (UNLIKELY(ndx<1 || ndx==len-1 || len <4)) { + x1 = func[ndx]; + x2 = func[ndx+1]; + p->sig[n] = x1 + (x2 - x1)*frac; + } else { + x0 = func[ndx-1]; + x1 = func[ndx]; + x2 = func[ndx+1]; + x3 = func[ndx+2]; + fracsq = frac*frac; + fracub = fracsq*x0; + temp1 = x3+x1+x1+x1; + p->sig[n] = x1 + FL(0.5)*fracub + + frac*(x2 - fracub/FL(6.0) - temp1/FL(6.0) - x0/FL(3.0)) + + fracsq*frac*(temp1/FL(6.0) - FL(0.5)*x2) + fracsq*(FL(0.5)*x2 - x1); + } + } + return OK; +} + +int tablkt_setup(CSOUND *csound, TABL *p) { + + if (UNLIKELY(p->XOUTCODE && p->XINCODE != p->XOUTCODE)) { + if (CS_KSMPS != 1) + return + csound->InitError(csound, + Str("tablekt: index type inconsistent with output")); + } + + p->iwrap = (int32) *p->wrap; + return OK; +} + +int tablerkt_kontrol(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + + return tabler_kontrol(csound,p); +} + + +int tablerkt_audio(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + + return tabler_audio(csound,p); +} + +int tableirkt_kontrol(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + + return tableir_kontrol(csound,p); +} + +int tableirkt_audio(CSOUND *csound, TABL *p) +{ + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + return tableir_audio(csound,p); +} + +int table3rkt_kontrol(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + return table3r_kontrol(csound,p);; +} + +int table3rkt_audio(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + return table3r_audio(csound,p); +} + +int tablew_init(CSOUND *csound, TABL *p) { + + int ndx, len; + int mask; + MYFLT *func; + int32 iwrap = *p->wrap; + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->InitError(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + func = p->ftp->ftable; + mask = p->ftp->lenmask; + p->np2 = mask ? 0 : 1; + len = p->ftp->flen; + + if (*p->mode) + p->mul = len; + else + p->mul = 1; + + ndx = MYFLOOR((*p->ndx + *p->offset)*p->mul + (iwrap==2 ? 0.5:0)); + if (iwrap) { + ndx = iwrap == 2 ? MYFLOOR(ndx+0.5) : ndx; + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + p->ftp->ftable[ndx] = *p->sig; + if (ndx == 0 && iwrap==2) func[len] = func[ndx]; + return OK; +} + +int tablew_kontrol(CSOUND *csound, TABL *p) { + int ndx, len = p->len; + int mask = p->ftp->lenmask; + MYFLT *func = p->ftp->ftable; + int32 iwrap = p->iwrap; + IGN(csound); + + ndx = MYFLOOR((*p->ndx + *p->offset)*p->mul + (iwrap==2 ? 0.5:0)); + if (iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + func[ndx] = *p->sig; + if (ndx == 0 && iwrap==2) func[len] = func[ndx]; + return OK; +} + +int tablew_audio(CSOUND *csound, TABL *p) { + int ndx, len = p->len, n, nsmps = CS_KSMPS; + int mask = p->ftp->lenmask; + MYFLT *sig = p->sig; + MYFLT *ndx_f = p->ndx; + MYFLT *func = p->ftp->ftable; + MYFLT offset = *p->offset; + MYFLT mul = p->mul; + int32 iwrap = p->iwrap; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + if (UNLIKELY(early)) nsmps -= early; + + for (n=koffset; n < nsmps; n++) { + ndx = MYFLOOR((ndx_f[n] + offset)*mul + (iwrap==2 ? 0.5:0)); + if (iwrap) { + if (p->np2) { + while(ndx >= len) ndx -= len; + while(ndx < 0) ndx += len; + } + else ndx &= mask; + } else { + if (UNLIKELY(ndx >= len)) ndx = len - 1; + else if (UNLIKELY(ndx < 0)) ndx = 0; + } + func[ndx] = sig[n]; + if (iwrap==2 && ndx == 0) func[len] = func[ndx]; +} + return OK; +} + +int tablewkt_kontrol(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + + return tablew_kontrol(csound,p); +} + + +int tablewkt_audio(CSOUND *csound, TABL *p) { + + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + p->np2 = p->ftp->lenmask ? 0 : 1; + if (*p->mode) + p->mul = p->ftp->flen; + else + p->mul = 1; + p->len = p->ftp->flen; + return tablew_audio(csound,p);; +} + +int table_length(CSOUND *csound, TLEN *p) { + FUNC *ftp; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) { + csound->Warning(csound, Str("table: could not find ftable %d"), + (int) *p->ftable); + *p->ans = FL(-1.0); + return NOTOK; + } + else *p->ans = (MYFLT) ftp->flen; + return OK; +} + +int table_gpw(CSOUND *csound, TGP *p) { + FUNC *ftp; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) { + csound->Warning(csound, + Str("table: could not find ftable %d"), + (int) *p->ftable); + return NOTOK; + } + ftp->ftable[ftp->flen] = ftp->ftable[0]; + return OK; +} + +int table_copy(CSOUND *csound, TGP *p) { + FUNC *dest, *src; + int32 len1, len2, i, rp; + if (UNLIKELY((dest = csound->FTnp2Find(csound, p->ftable)) == NULL || + (src = csound->FTnp2Find(csound, p->ftsrc)) == NULL)) { + csound->Warning(csound, + Str("table: could not find ftables %d and/or %d"), + (int) *p->ftable, (int) *p->ftsrc); + return NOTOK; + } + len1 = dest->flen; + len2 = src->flen; + for (i=rp=0; iftable[i] = src->ftable[rp]; + rp = rp == len2 ? 0 : rp+1; + } + return OK; +} + +int table_mix(CSOUND *csound, TABLMIX *p) { + int32 np2, np21, np22; + FUNC *ftp, *ftp1, *ftp2; + int32 len, len1, len2, flen; + MYFLT g1, g2, *func, *func1, *func2; + int32 off, off1, off2; + + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->tab)) == NULL)) { + csound->Warning(csound, + Str("table: could not find ftable %d"), (int) *p->tab); + return NOTOK; + } + np2 = ftp->lenmask ? 0 : 1; + + if (UNLIKELY((ftp1 = csound->FTnp2Find(csound, p->tab1)) == NULL)) { + csound->Warning(csound, + Str("table: could not find ftable %d"), (int) *p->tab1); + return NOTOK; + } + np21 = ftp1->lenmask ? 0 : 1; + + if (UNLIKELY((ftp2 = csound->FTnp2Find(csound, p->tab2)) == NULL)) { + csound->Warning(csound, + Str("table: could not find ftable %d"), (int) *p->tab2); + return NOTOK; + } + np22 = ftp2->lenmask ? 0 : 1; + + len = MYFLOOR(*p->len); + flen = ftp->flen; + len1 = ftp1->flen; + len2 = ftp2->flen; + func = ftp->ftable; + func1 = ftp1->ftable; + func2 = ftp2->ftable; + off = *p->off; + off1 = *p->off1; + off2 = *p->off2; + g1 = *p->g1; + g2 = *p->g2; + + if (len>0) { + int i, p0, p1, p2; + for (i=0; i < len; i++) { + p0 = i+off; + p1 = i+off1; + p2 = i+off2; + if (np2) { + while(p0 < 0) p0 += flen; + while(p0 >= len1) p0 -= flen; + } + else p0 &= ftp->lenmask; + if (np21) { + while(p1 < 0) p1 += len1; + while(p1 >= len1) p1 -= len1; + } + else p1 &= ftp1->lenmask; + if (np22) { + while(p2 < 0) p2 += len2; + while(p2 >= len2) p1 -= len2; + } + else p2 &= ftp2->lenmask; + func[p0] = func1[p1]*g1 + func2[p2]*g2; + } + } else { + int i, p0, p1, p2; + for (i=0; i > len; i--) { + p0 = i+off; + p1 = i+off1; + p2 = i+off2; + if (np2) { + while(p0 < 0) p0 += flen; + while(p0 >= len1) p0 -= flen; + } + else p0 &= ftp->lenmask; + if (np21) { + while(p1 < 0) p1 += len1; + while(p1 >= len1) p1 -= len1; + } + else p1 &= ftp1->lenmask; + if (np22) { + while(p2 < 0) p2 += len2; + while(p2 >= len2) p1 -= len2; + } + else p2 &= ftp2->lenmask; + func[p0] = func1[p1]*g1 + func2[p2]*g2; + } + } + return OK; +} + +int table_ra_set(CSOUND *csound, TABLRA *p) { + IGN(csound); + return OK; +} + +int table_ra(CSOUND *csound, TABLRA *p) { + int32 pos, np2, nsmps, len, i; + MYFLT *sig= p->sig, *func; + int mask; + FUNC *ftp; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + nsmps = CS_KSMPS; + + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + np2 = ftp->lenmask ? 0 : 1; + + mask = ftp->lenmask; + pos = *p->strt + *p->off; + + if (pos < 0) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not read negative pos %d"), pos); + + if (UNLIKELY(koffset)) memset(sig, '\0', koffset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&sig[nsmps], '\0', early*sizeof(MYFLT)); + } + + func = ftp->ftable; + len = ftp->flen; + for (i=koffset; i < nsmps; i++) { + if (np2) pos %= len; + else pos &= mask; + sig[i] = func[pos]; + pos++; + } + + return OK; +} + +int table_wa_set(CSOUND *csound, TABLWA *p) { + IGN(csound); + p->pos =0; + return OK; +} + +int table_wa(CSOUND *csound, TABLWA *p) { + int32 pos, np2, nsmps, len, i; + MYFLT *sig= p->sig, *func; + int mask; + FUNC *ftp; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + nsmps = CS_KSMPS; + + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ftable)) == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not find ftable %d"), + (int) *p->ftable); + np2 = ftp->lenmask ? 0 : 1; + + mask = ftp->lenmask; + pos = p->pos + *p->off; + + if (pos < 0) + return csound->PerfError(csound, p->h.insdshead, + Str("table: could not read negative pos %d"), pos); + + if (UNLIKELY(early)) nsmps -= early; + + func = ftp->ftable; + len = ftp->flen; + for (i=koffset; i < nsmps; i++) { + if (np2) pos %= len; + else pos &= mask; + func[pos] = sig[i]; + pos++; + } + p->pos = pos; + *p->strt = pos; + return OK; +} diff -Nru csound-5.17.11~dfsg/OOps/vdelay.c csound-6.02~dfsg/OOps/vdelay.c --- csound-5.17.11~dfsg/OOps/vdelay.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/OOps/vdelay.c 2014-01-07 16:53:47.000000000 +0000 @@ -38,7 +38,7 @@ uint32 n = (int32)(*p->imaxd * ESR)+1; if (!*p->istod) { - if (p->aux.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux.size) + if (p->aux.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux.size) /* allocate space for delay buffer */ csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux); else { /* make sure buffer is empty */ @@ -51,7 +51,10 @@ int vdelay(CSOUND *csound, VDEL *p) /* vdelay routine */ { - int32 nn, nsmps = csound->ksmps, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out = p->sr; /* assign object data to local variables */ MYFLT *in = p->ain; MYFLT *del = p->adel; @@ -60,9 +63,14 @@ if (UNLIKELY(buf==NULL)) goto err1; /* RWD fix */ maxd = (uint32) (1+*p->imaxd * ESR); indx = p->left; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (XINARG2) { /* if delay is a-rate */ - for (nn=0; nnleft = indx; /* and keep track of where you are */ return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelay3(CSOUND *csound, VDEL *p) /* vdelay routine with cubic interp */ { - int32 nn, nsmps = csound->ksmps, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out = p->sr; /* assign object data to local variables */ MYFLT *in = p->ain; MYFLT *del = p->adel; @@ -143,11 +155,15 @@ if (UNLIKELY(buf==NULL)) goto err1; /* RWD fix */ maxd = (uint32) (*p->imaxd * ESR); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ - nn = csound->ksmps; indx = p->left; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (XINARG2) { /* if delay is a-rate */ - for (nn=0; nn= (int32)maxd)) v1 -= (int32)maxd; if (UNLIKELY(++indx >= maxd)) indx -= maxd; } @@ -214,7 +230,7 @@ z = fv1 * fv1; z--; z *= FL(0.1666666667); /* IV Oct 2001 */ y = fv1; y++; w = (y *= FL(0.5)); w--; x = FL(3.0) * z; y -= x; w -= z; x -= fv1; - for (nn=0; nnleft = indx; /* and keep track of where you are */ return OK; err1: - return csound->PerfError(csound, Str("vdelay3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay3: not initialised")); } /* vdelayx, vdelayxs, vdelayxq, vdelayxw, vdelayxws, vdelayxwq */ @@ -244,7 +261,7 @@ if (UNLIKELY(n == 0)) n = 1; /* fix due to Troxler */ if (!*p->istod) { - if (p->aux1.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux1.size) + if (p->aux1.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux1.size) /* allocate space for delay buffer */ csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux1); else @@ -264,12 +281,12 @@ if (UNLIKELY(n == 0)) n = 1; /* fix due to Troxler */ if (!*p->istod) { - if (p->aux1.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux1.size) + if (p->aux1.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux1.size) /* allocate space for delay buffer */ csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux1); else memset(p->aux1.auxp, 0, n*sizeof(MYFLT)); - if (p->aux2.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux2.size) + if (p->aux2.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux2.size) csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux2); else memset(p->aux2.auxp, 0, n*sizeof(MYFLT)); @@ -289,20 +306,20 @@ if (UNLIKELY(n == 0)) n = 1; /* fix due to Troxler */ if (!*p->istod) { - if (p->aux1.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux1.size) + if (p->aux1.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux1.size) /* allocate space for delay buffer */ csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux1); else memset(p->aux1.auxp, 0, n*sizeof(MYFLT)); - if (p->aux2.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux2.size) + if (p->aux2.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux2.size) csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux2); else memset(p->aux2.auxp, 0, n*sizeof(MYFLT)); - if (p->aux3.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux3.size) + if (p->aux3.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux3.size) csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux3); else memset(p->aux3.auxp, 0, n*sizeof(MYFLT)); - if (p->aux4.auxp == NULL || (int32)(n * sizeof(MYFLT)) > p->aux4.size) + if (p->aux4.auxp == NULL || (uint32_t)(n * sizeof(MYFLT)) > p->aux4.size) csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux4); else memset(p->aux4.auxp, 0, n*sizeof(MYFLT)); @@ -317,7 +334,10 @@ int vdelayx(CSOUND *csound, VDELX *p) /* vdelayx routine */ { - int32 nn, nsmps = csound->ksmps, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int32 indx, maxd; MYFLT *out1 = p->sr1; /* assign object data to local variables */ MYFLT *in1 = p->ain1; MYFLT *del = p->adel; @@ -332,8 +352,13 @@ indx = p->left; i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); + if (UNLIKELY(offset)) memset(out1, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + } - for (nn=0; nnleft = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelayxw(CSOUND *csound, VDELX *p) /* vdelayxw routine */ { - int32 nn, maxd, indx, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out1 = p->sr1; /* assign object data to local variables */ MYFLT *in1 = p->ain1; MYFLT *del = p->adel; @@ -395,7 +424,12 @@ i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); - for (nn=0;nn= maxd) xpos -= maxd; - if (x1 * (1.0 - x1) > 0.00000001) { + if (LIKELY(x1 * (1.0 - x1) > 0.00000001)) { n1 = (double)in1[nn] * x2; xpos += (1 - i2); while (xpos < 0) xpos += maxd; @@ -434,7 +468,8 @@ p->left = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelayxs(CSOUND *csound, VDELXS *p) /* vdelayxs routine */ @@ -450,7 +485,9 @@ int wsize = p->interp_size; double x1, x2, w, d, d2x, n1, n2; int32 i, i2, xpos; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY((buf1 == NULL) || (buf2 == NULL))) goto err1; /* RWD fix */ maxd = (int32)(*p->imaxd * csound->esr); @@ -458,8 +495,17 @@ indx = p->left; i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } - for (n=0; nleft = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelayxws(CSOUND *csound, VDELXS *p) /* vdelayxws routine */ { - int32 nn, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out1 = p->sr1; /* assign object data to local variables */ MYFLT *out2 = p->sr2; MYFLT *in1 = p->ain1; @@ -520,17 +570,25 @@ if (UNLIKELY((buf1 == NULL) || (buf2 == NULL))) goto err1; /* RWD fix */ maxd = (int32)(*p->imaxd * csound->esr); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ - nn = csound->ksmps; indx = p->left; i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); - do { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nesr); + x1 = (double)indx + ((double)del[n] * (double)csound->esr); while (UNLIKELY(x1 < 0.0)) x1 += (double)maxd; xpos = (int32)x1; x1 -= (double)xpos; @@ -538,7 +596,7 @@ while (UNLIKELY(xpos >= maxd)) xpos -= maxd; if (x1 * (1.0 - x1) > 0.00000001) { - n1 = (double)*in1 * x2; n2 = (double)*in2 * x2; + n1 = (double)in1[n] * x2; n2 = (double)in2[n] * x2; xpos += (1 - i2); while (UNLIKELY(xpos < 0)) xpos += maxd; d = (double)(1 - i2) - x1; @@ -554,24 +612,27 @@ else { /* integer sample */ xpos = (int32)((double)xpos + x1 + 0.5); /* position */ if (UNLIKELY(xpos >= maxd)) xpos -= maxd; - buf1[xpos] += *in1; buf2[xpos] += *in2; + buf1[xpos] += in1[n]; buf2[xpos] += in2[n]; } - *out1++ = buf1[indx]; buf1[indx] = FL(0.0); - *out2++ = buf2[indx]; buf2[indx] = FL(0.0); + out1[n] = buf1[indx]; buf1[indx] = FL(0.0); + out2[n] = buf2[indx]; buf2[indx] = FL(0.0); if (UNLIKELY(++indx == maxd)) indx = 0; - in1++; in2++; - } while (--nn); + } p->left = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelayxq(CSOUND *csound, VDELXQ *p) /* vdelayxq routine */ { - int32 nn, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out1 = p->sr1; /* assign object data to local variables */ MYFLT *out2 = p->sr2; MYFLT *out3 = p->sr3; @@ -593,14 +654,27 @@ (buf3 == NULL) || (buf4 == NULL))) goto err1; maxd = (int32)(*p->imaxd * csound->esr); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ - nn = csound->ksmps; indx = p->left; i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); - do { - buf1[indx] = *in1++; buf2[indx] = *in2++; - buf3[indx] = *in3++; buf4[indx] = *in4++; + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + memset(out3, '\0', offset*sizeof(MYFLT)); + memset(out4, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out3[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out4[nsmps], '\0', early*sizeof(MYFLT)); + } + + for (n=offset; n= maxd)) xpos -= maxd; - if (x1 * (1.0 - x1) > 0.00000001) { + if (LIKELY(x1 * (1.0 - x1) > 0.00000001)) { xpos += (1 - i2); while (UNLIKELY(xpos < 0)) xpos += maxd; d = (double)(1 - i2) - x1; @@ -622,35 +696,38 @@ w = 1.0 - d*d*d2x; w *= (w / d++); n1 += (double)buf1[xpos] * w; n2 += (double)buf2[xpos] * w; n3 += (double)buf3[xpos] * w; n4 += (double)buf4[xpos] * w; - if (++xpos >= maxd) xpos -= maxd; + if (UNLIKELY(++xpos >= maxd)) xpos -= maxd; w = 1.0 - d*d*d2x; w *= (w / d++); n1 -= (double)buf1[xpos] * w; n2 -= (double)buf2[xpos] * w; n3 -= (double)buf3[xpos] * w; n4 -= (double)buf4[xpos] * w; - if (++xpos >= maxd) xpos -= maxd; + if (UNLIKELY(++xpos >= maxd)) xpos -= maxd; } - *out1 = (MYFLT) (n1 * x2); *out2 = (MYFLT) (n2 * x2); - *out3 = (MYFLT) (n3 * x2); *out4 = (MYFLT) (n4 * x2); + out1[n] = (MYFLT) (n1 * x2); out2[n] = (MYFLT) (n2 * x2); + out3[n] = (MYFLT) (n3 * x2); out4[n] = (MYFLT) (n4 * x2); } else { /* integer sample */ xpos = (int32)((double)xpos + x1 + 0.5); /* position */ if (UNLIKELY(xpos >= maxd)) xpos -= maxd; - *out1 = buf1[xpos]; *out2 = buf2[xpos]; - *out3 = buf3[xpos]; *out4 = buf4[xpos]; + out1[n] = buf1[xpos]; out2[n] = buf2[xpos]; + out3[n] = buf3[xpos]; out4[n] = buf4[xpos]; } if (UNLIKELY(++indx == maxd)) indx = 0; - out1++; out2++; out3++; out4++; - } while (--nn); + } p->left = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int vdelayxwq(CSOUND *csound, VDELXQ *p) /* vdelayxwq routine */ { - int32 nn, maxd, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 maxd, indx; MYFLT *out1 = p->sr1; /* assign object data to local variables */ MYFLT *out2 = p->sr2; MYFLT *out3 = p->sr3; @@ -672,17 +749,30 @@ (buf3 == NULL) || (buf4 == NULL))) goto err1; maxd = (int32)(*p->imaxd * csound->esr); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ - nn = csound->ksmps; indx = p->left; i2 = (wsize >> 1); d2x = (1.0 - pow ((double)wsize * 0.85172, -0.89624)) / (double)(i2 * i2); - do { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + memset(out3, '\0', offset*sizeof(MYFLT)); + memset(out4, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out3[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out4[nsmps], '\0', early*sizeof(MYFLT)); + } + + for (n=offset; nesr); + x1 = (double)indx + ((double)del[n] * (double)csound->esr); while (UNLIKELY(x1 < 0.0)) x1 += (double)maxd; xpos = (int32)x1; x1 -= (double)xpos; @@ -690,8 +780,8 @@ while (UNLIKELY(xpos >= maxd)) xpos -= maxd; if (x1 * (1.0 - x1) > 0.00000001) { - n1 = (double)*in1 * x2; n2 = (double)*in2 * x2; - n3 = (double)*in3 * x2; n4 = (double)*in4 * x2; + n1 = (double)in1[n] * x2; n2 = (double)in2[n] * x2; + n3 = (double)in3[n] * x2; n4 = (double)in4[n] * x2; xpos += (1 - i2); while (UNLIKELY(xpos < 0)) xpos += maxd; d = (double)(1 - i2) - x1; @@ -709,39 +799,39 @@ else { /* integer sample */ xpos = (int32)((double)xpos + x1 + 0.5); /* position */ if (UNLIKELY(xpos >= maxd)) xpos -= maxd; - buf1[xpos] += *in1; buf2[xpos] += *in2; - buf3[xpos] += *in3; buf4[xpos] += *in4; + buf1[xpos] += in1[n]; buf2[xpos] += in2[n]; + buf3[xpos] += in3[n]; buf4[xpos] += in4[n]; } - *out1++ = buf1[indx]; buf1[indx] = FL(0.0); - *out2++ = buf2[indx]; buf2[indx] = FL(0.0); - *out3++ = buf3[indx]; buf3[indx] = FL(0.0); - *out4++ = buf4[indx]; buf4[indx] = FL(0.0); + out1[n] = buf1[indx]; buf1[indx] = FL(0.0); + out2[n] = buf2[indx]; buf2[indx] = FL(0.0); + out3[n] = buf3[indx]; buf3[indx] = FL(0.0); + out4[n] = buf4[indx]; buf4[indx] = FL(0.0); if (UNLIKELY(++indx == maxd)) indx = 0; - in1++; in2++; in3++; in4++; - } while (--nn); + } p->left = indx; return OK; err1: - return csound->PerfError(csound, Str("vdelay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdelay: not initialised")); } int multitap_set(CSOUND *csound, MDEL *p) { - int32 n; + uint32_t n, i; MYFLT max = FL(0.0); //if (UNLIKELY(p->INOCOUNT/2 == (MYFLT)p->INOCOUNT*FL(0.5))) /* Should this test just be p->INOCOUNT&1 == */ if (UNLIKELY((p->INOCOUNT&1)==0)) - csound->Die(csound, Str("Wrong input count in multitap\n")); + csound->InitError(csound, Str("Wrong input count in multitap\n")); - for (n = 0; n < p->INOCOUNT - 1; n += 2) { - if (max < *p->ndel[n]) max = *p->ndel[n]; + for (i = 0; i < p->INOCOUNT - 1; i += 2) { + if (max < *p->ndel[i]) max = *p->ndel[i]; } - n = (int32)(csound->esr * max * sizeof(MYFLT)); + n = (uint32_t)(csound->esr * max * sizeof(MYFLT)); if (p->aux.auxp == NULL || /* allocate space for delay buffer */ n > p->aux.size) csound->AuxAlloc(csound, n, &p->aux); @@ -756,34 +846,43 @@ int multitap_play(CSOUND *csound, MDEL *p) { /* assign object data to local variables */ - int i, n, nn = csound->ksmps, indx = p->left, delay; + int indx = p->left, delay; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, n, nsmps = CS_KSMPS; MYFLT *out = p->sr, *in = p->ain; MYFLT *buf = (MYFLT *)p->aux.auxp; MYFLT max = (MYFLT)p->max; if (UNLIKELY(buf==NULL)) goto err1; /* RWD fix */ - for (i=0; iINOCOUNT - 1; n += 2) { - delay = indx - (int32)(csound->esr * *p->ndel[n]); + for (i = 0; i < p->INOCOUNT - 1; i += 2) { + delay = indx - (int32)(csound->esr * *p->ndel[i]); if (UNLIKELY(delay < 0)) delay += (int32)max; - v += buf[delay] * *p->ndel[n+1]; /* Write output */ + v += buf[delay] * *p->ndel[i+1]; /* Write output */ } - out[i] = v; + out[n] = v; } p->left = indx; return OK; err1: - return csound->PerfError(csound, Str("multitap: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("multitap: not initialised")); } /* nreverb coded by Paris Smaragdis 1994 and Richard Karpen 1998 */ -#define LOG001 (-6.9078) /* log(.001) */ +#define LOG001 (-6.9077552789821370521) /* log(.001) */ static const int smallprime[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, @@ -911,9 +1010,9 @@ FUNC *ftCombs; p->numCombs = (int) *p->inumCombs; /* Get user-defined set of comb constants from table */ - if (UNLIKELY((ftCombs = csound->FTFind(csound, p->ifnCombs)) == NULL)) + if (UNLIKELY((ftCombs = csound->FTnp2Find(csound, p->ifnCombs)) == NULL)) return NOTOK; - if (UNLIKELY(ftCombs->flen < p->numCombs * 2)) { + if (UNLIKELY(ftCombs->flen < (uint32_t)p->numCombs * 2)) { return csound->InitError(csound, Str("reverbx; Combs ftable must have " "%d time and %d gain values"), p->numCombs, p->numCombs); @@ -943,9 +1042,9 @@ else { /* Have user-defined set of alpas constants */ FUNC *ftAlpas; p->numAlpas = (int) *p->inumAlpas; - if (UNLIKELY((ftAlpas = csound->FTFind(csound, p->ifnAlpas)) == NULL)) + if (UNLIKELY((ftAlpas = csound->FTnp2Find(csound, p->ifnAlpas)) == NULL)) return NOTOK; - if (UNLIKELY(ftAlpas->flen < p->numAlpas * 2)) { + if (UNLIKELY(ftAlpas->flen < (unsigned int)p->numAlpas * 2)) { return csound->InitError(csound, Str("reverbx; Alpas ftable must have" " %d time and %d gain values"), p->numAlpas, p->numAlpas); @@ -966,8 +1065,8 @@ /* Init variables */ if (*p->istor == FL(0.0) || - p->temp.auxp == NULL || p->temp.sizeksmps * sizeof(MYFLT)) { - csound->AuxAlloc(csound, csound->ksmps * sizeof(MYFLT), &p->temp); + p->temp.auxp == NULL || p->temp.sizeAuxAlloc(csound, CS_KSMPS * sizeof(MYFLT), &p->temp); n = 0; for (i = 0; i < p->numCombs; i++) { @@ -1044,7 +1143,10 @@ int reverbx(CSOUND *csound, NREV2 *p) { - int32 i, n, nsmps = csound->ksmps; + int32 i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *in, *out = p->out, *buf, *end; MYFLT gain, z; MYFLT hdif = *p->hdif; @@ -1057,6 +1159,7 @@ in = p->in; memcpy(buf, in, nsmps*sizeof(MYFLT)); memset(out, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (*p->time != p->prev_time || *p->hdif != p->prev_hdif) { if (UNLIKELY(hdif > FL(1.0))) { csound->Warning(csound, Str("High frequency diffusion>1\n")); @@ -1092,7 +1195,7 @@ gain = p->c_gain[i]; in = (MYFLT*) p->temp.auxp; out = p->out; - for (n=0;nz[i] * p->g[i]; p->z[i] = *buf; @@ -1107,13 +1210,11 @@ for (i = 0; i < numAlpas; i++) { in = (MYFLT*) p->temp.auxp; out = p->out; - memcpy(in, out, nsmps*sizeof(MYFLT)); + memcpy(in+offset, out+offset, (nsmps-offset)*sizeof(MYFLT)); buf = p->pabuf_cur[i]; end = p->abuf_cur[i + 1]; gain = p->a_gain[i]; - in = (MYFLT*) p->temp.auxp; - out = p->out; - for (n=0;nPerfError(csound, Str("reverbx: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("reverbx: not initialised")); } diff -Nru csound-5.17.11~dfsg/Opcodes/CMakeLists.txt csound-6.02~dfsg/Opcodes/CMakeLists.txt --- csound-5.17.11~dfsg/Opcodes/CMakeLists.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/CMakeLists.txt 2014-01-07 16:54:20.000000000 +0000 @@ -7,21 +7,45 @@ option(BUILD_IMAGE_OPCODES "Build the image opcodes" ON) option(BUILD_PYTHON_OPCODES "Build the Python opcodes" ON) option(BUILD_LUA_OPCODES "Build the Lua opcodes" ON) -option(BUILD_WIIMOTE_OPCODES "Build the Lua opcodes" ON) +option(BUILD_WIIMOTE_OPCODES "Build the Wiimote opcodes" ON) +option(BUILD_P5GLOVE_OPCODES "Build the P5Glove opcodes" ON) +option(BUILD_SERIAL_OPCODES "Build the serial opcode" ON) +option(BUILD_PLATEREV_OPCODES "Build the platerev opcode" ON) +option(BUILD_FAUST_OPCODES "Build the Faust opcodes" OFF) +option(BUILD_VST4CS_OPCODES "Build the vst4cs opcodes" OFF) find_package(Boost) check_include_file(ladspa.h LADSPA_H) check_include_file(fluidsynth.h FLUIDSYNTH_H) +find_library(FLUIDSYNTH_LIBRARY fluidsynth) find_library(JACK_LIBRARY jack) find_library(JACKDMP_LIBRARY jackdmp) check_include_file(jack/jack.h JACK_HEADER) check_include_file_cxx(gmm/gmm.h GMM_HEADER) -check_include_file(lo/lo.h OSC_HEADER) +check_include_file_cxx(eigen3/E.h GMM_HEADER) +#check_include_file(lo/lo.h OSC_HEADER) +find_library(LIBLO_LIBRARY lo) find_package(PNG) +set(PYTHON_INCLUDE_DIRS /usr/include/Python2.7) +set(Python_ADDITIONAL_VERSIONS 2.7) find_package(PythonLibs) -find_package(Lua51) + +find_library(LUAJIT_LIBRARY luajit) +if(NOT LUAJIT_LIBRARY) + find_library(LUAJIT_LIBRARY luajit-5.1) +endif() +find_path(LUA_H_PATH luajit-2.0/lua.h) + check_include_file(wiiuse.h WIIUSE_H) find_library(WIIUSE_LIB wiiuse) +check_include_file(p5glove.h P5GLOVE_H) +find_library(P5GLOVE_LIB p5glove) + +if(BUILD_FAUST_OPCODES) +find_package(LLVM) +exec_program(llvm-config ARGS --libs OUTPUT_VARIABLE LLVM_LIBS) +find_library(FAUST_LIBRARY faust HINTS /usr/local/lib/faust) +endif() ## OPCODE LIBS WITH NO EXTERNAL DEPENDENCIES ## @@ -38,12 +62,12 @@ make_plugin(cellular cellular.c) -# temporarily do not build on Windows until these opcodes are fixed -# to compile -if(NOT WIN32) - make_plugin(udprecv sockrecv.c) - make_plugin(udpsend socksend.c) +if(BUILD_SERIAL_OPCODES) + make_plugin(serial serial.c) +endif() +if(BUILD_PLATEREV_OPCODES) + make_plugin(platerev platerev.c m) endif() set(scansyn_SRCS @@ -56,6 +80,7 @@ if(LINUX) make_plugin(urandom urandom.c) + make_plugin(joystick linuxjoystick.c) endif() ## OPCODES WITH EXTERNAL DEPENDENCIES ## @@ -72,9 +97,13 @@ make_plugin(dssi4cs "${dssi_SRC}" dl) endif() -check_deps(BUILD_FLUID_OPCODES FLUIDSYNTH_H) +check_deps(BUILD_FLUID_OPCODES FLUIDSYNTH_H FLUIDSYNTH_LIBRARY) if(BUILD_FLUID_OPCODES) - make_plugin(fluidOpcodes fluidOpcodes/fluidOpcodes.cpp fluidsynth) + if(EXISTS ${FLUIDSYNTH_INCLUDE_DIR}) + include_directories("${FLUIDSYNTH_INCLUDE_DIR}") + endif() + make_plugin(fluidOpcodes fluidOpcodes/fluidOpcodes.cpp ${FLUIDSYNTH_LIBRARY}) + add_dependency_to_framework(fluidOpcodes ${FLUIDSYNTH_LIBRARY}) endif() set(JACK_LIB (JACK_LIBRARY OR JACKDMP_LIBRARY)) @@ -95,18 +124,23 @@ make_plugin(linear_algebra linear_algebra.cpp) endif() -check_deps(BUILD_OSC_OPCODES OSC_HEADER) +check_deps(BUILD_OSC_OPCODES LIBLO_LIBRARY) if(BUILD_OSC_OPCODES) make_plugin(osc OSC.c) - target_link_libraries(osc lo pthread) + if(WIN32) + target_link_libraries(osc ${LIBLO_LIBRARY} pthread wsock32 ws2_32) + else() + target_link_libraries(osc ${LIBLO_LIBRARY} pthread) + endif() + add_dependency_to_framework(osc ${LIBLO_LIBRARY}) endif() check_deps(BUILD_IMAGE_OPCODES PNG_FOUND) if(BUILD_IMAGE_OPCODES) include_directories(${PNG_INCLUDE_DIR}) make_plugin(image imageOpcodes.c "${PNG_LIBRARIES}") - set_target_properties(image - PROPERTIES COMPILER_FLAGS "${PNG_DEFINITIONS}") + add_compiler_flags(${PNG_DEFINITIONS} TARGETS image) + add_dependency_to_framework(image ${PNG_LIBRARY}) endif() check_deps(BUILD_PYTHON_OPCODES PYTHONLIBS_FOUND) @@ -115,15 +149,34 @@ make_plugin(py py/pythonopcodes.c ${PYTHON_LIBRARIES}) endif() -check_deps(BUILD_LUA_OPCODES LUA51_FOUND) -if(BUILD_LUA_OPCODES) - include_directories(${LUA_INCLUDE_DIR}) - make_plugin(LuaCsound LuaCsound.cpp ${LUA_LIBRARIES}) +if(NOT APPLE) + check_deps(BUILD_LUA_OPCODES LUAJIT_LIBRARY LUA_H_PATH) + if(BUILD_LUA_OPCODES) + make_plugin(LuaCsound LuaCsound.cpp ${LUAJIT_LIBRARY}) + add_compiler_flags(${OpenMP_CXX_FLAGS} TARGETS LuaCsound) + add_compiler_flags(${OpenMP_CXX_FLAGS} TARGETS LuaCsound LINKER) + include_directories(${LUA_H_PATH}/luajit-2.0) + endif() endif() check_deps(BUILD_WIIMOTE_OPCODES WIIUSE_H) if(BUILD_WIIMOTE_OPCODES) make_plugin(wiimote wiimote.c ${WIIUSE_LIB}) + add_dependency_to_framework(wiimote ${WIIUSE_LIB}) + +endif() + +check_deps(BUILD_P5GLOVE_OPCODES P5GLOVE_H) +if(BUILD_P5GLOVE_OPCODES) + make_plugin(p5g p5glove.c ${P5GLOVE_LIB}) +endif() + +check_deps(BUILD_FAUST_OPCODES LLVM_FOUND FAUST_LIBRARY) +if(BUILD_FAUST_OPCODES) + make_plugin(faustcsound faustgen.cpp) + add_compiler_flags("-DFAUSTFLOAT=double" TARGETS faustcsound) + target_link_libraries(faustcsound ${FAUST_LIBRARY} -L/usr/local/lib ${LLVM_LIBS}) + include_directories(${LLVM_INCLUDE_DIRS}) endif() @@ -133,6 +186,32 @@ # make_plugin(ogg ogg.c "${vorbis_LIBS}") #endif() +check_deps(BUILD_VST4CS_OPCODES VSTSDK2X_DIR FLTK_FOUND) +if(BUILD_VST4CS_OPCODES) + include_directories(${CMAKE_HOME_DIRECTORY}/interfaces) + include_directories(${VSTSDK2X_DIR}) + include_directories(${VSTSDK2X_DIR}/public.sdk/source/vst2.x) + include_directories(${VSTSDK2X_DIR}/pluginterfaces/source/vst2.x) + include_directories(${FLTK_INCLUDE_DIR}) + add_definitions(-DVST_FORCE_DEPRECATED=0 -DCS_VSTHOST) + set(VST4CS_SRCS + vst4cs/src/vst4cs.cpp + vst4cs/src/vsthost.cpp + vst4cs/src/fxbank.cpp + ${VSTSDK2X_DIR}/public.sdk/source/vst2.x/audioeffect.cpp + ${VSTSDK2X_DIR}/public.sdk/source/vst2.x/audioeffectx.cpp) + add_library(vst4cs SHARED ${VST4CS_SRCS}) + set_target_properties(vst4cs PROPERTIES + LINK_INTERFACE_LIBRARIES "" + RUNTIME_OUTPUT_DIRECTORY ${BUILD_BIN_DIR} + LIBRARY_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} + ARCHIVE_OUTPUT_DIRECTORY ${BUILD_LIB_DIR} + ) + target_link_libraries(vst4cs ${CSOUNDLIB} ${FLTK_LIBRARIES}) + install(TARGETS vst4cs + LIBRARY DESTINATION ${LIBRARY_INSTALL_DIR} + ARCHIVE DESTINATION ${LIBRARY_INSTALL_DIR}) +endif() #set(sfont_FLAGS "") @@ -148,14 +227,4 @@ #set_target_properties(sfont # PROPERTIES COMPILER_FLAGS "${sfont_FLAGS}") - - - -#if wiifound==1: -# WiiEnvironment = pluginEnvironment.Clone() -# makePlugin(WiiEnvironment, 'wiimote', ['wiimote.c']) -#if p5gfound==1: -# P5GEnvironment = pluginEnvironment.Clone() -# makePlugin(P5GEnvironment, 'p5g', ['p5glove.c']) - add_subdirectory(stk) diff -Nru csound-5.17.11~dfsg/Opcodes/Loris/README csound-6.02~dfsg/Opcodes/Loris/README --- csound-5.17.11~dfsg/Opcodes/Loris/README 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Loris/README 1970-01-01 00:00:00.000000000 +0000 @@ -1,72 +0,0 @@ -Welcome to Loris. - -Loris is an open source C++ class library implementing analysis, -manipulation, and synthesis of digitized sounds using the Reassigned -Bandwidth-Enhanced Additive Sound Model. - -For more information about Loris and the Reassigned Bandwidth-Enhanced -Additive Model, contact the developers at loris@cersloundgroup.org, or -visit them at http://www.cerlsoundgroup.org/Loris/. - -The primary distribution point for Loris is SourceForge -(http://loris.sourceforge.net) and its mirrors. - -Loris is free software. Please see the file COPYING for details. - -For documentation, please see the files in the doc subdirectory. - -For a list of major changes to Loris, organized by release number, -please see the file NEWS. - -INSTALLATION: - -For generic configuration and installation instructions, see -the file INSTALL. - -In order to compile and link the Loris library and scripting extensions, -you will need a modern, reasonably standard-compliant C++ compiler (and -linker, etc.). To build scripting extensions, such as the Python module, -you will also need SWIG, a tool that connects programs written in C and -C++ with a variety of high-level programming languages, available at -www.swig.org - -For best performance, you should also install the FFTW Fourier transform -library, available at www.fftw.org. Mac OS X users see note below. FFTW -is covered by its own license and copyright, and is entirely separate -from Loris. FFTW is not required to build or use Loris. - - -MacOS INSTALLATION: - -Loris can be built using the standard GNU tools from a Terminal window -under Mac OS X (Darwin), follow the instructions for the standard -distribution. You will, of course, need the developers' tools, available -from Apple, in order to compile Loris (or anything else) under OS X. It -is also possible to build Loris using Xcode under OS X. - -NOTE: By default, FFTW builds and installs only static libraries under -Mac OS X. Loris needs to link against the dynamic FFTW library. You need -to explicitly enable dynamic linking when building FFTW so that the -dynamic (shared) library is built. - - -COPYRIGHT AND LICENSE: - -Loris is Copyright (c) 1999-2010 by Kelly Fitz and Lippold Haken - -Loris is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY, without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -file COPYING or the GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -loris@cerlsoundgroup.org -http://www.cerlsoundgroup.org/Loris/ diff -Nru csound-5.17.11~dfsg/Opcodes/Loris/lorisgens5.C csound-6.02~dfsg/Opcodes/Loris/lorisgens5.C --- csound-5.17.11~dfsg/Opcodes/Loris/lorisgens5.C 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Loris/lorisgens5.C 1970-01-01 00:00:00.000000000 +0000 @@ -1,1157 +0,0 @@ -/* - * This is the Loris C++ Class Library, implementing analysis, - * manipulation, and synthesis of digitized sounds using the Reassigned - * Bandwidth-Enhanced Additive Sound Model. - * - * Loris is Copyright (c) 1999-2010 by Kelly Fitz and Lippold Haken - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY, without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * lorisgens5.C - * - * Implementation of Csound unit generators supporting bandwidth-enhanced - * synthesis using the Loris library. - * - * This lorisplay module was originally written by Corbin Champion, 2002. - * - * The Loris generator code has been modified such that it can also - * be built as a dynamically loaded module. Thanks to Michael Gogins - * for telling me how to do this! - * - * Kelly Fitz, 9 May 2002 - * loris@cerlsoundgroup.org - * - * http://www.cerlsoundgroup.org/Loris/ - * - * This file has been modified for Csound 5 by Michael Gogins - * - */ - -#include -/* why is this here, you ask? Well, Csound's prototyp.h, as of - version 4.21, declares modf, and does so differently from - the math header. - - double modf(double, double *); // not included in math.h - - The difference is in the throw() specification. Including - cmath here seems to suppress the compiler errors that - are the result of this bad idea. -*/ -#include "lorisgens5.h" -#include "string.h" - -#include "Breakpoint.h" -#include "Envelope.h" -#include "Exception.h" -#include "Morpher.h" -#include "Oscillator.h" -#include "Partial.h" -#include "PartialUtils.h" -#include "SdifFile.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Loris; -using namespace std; - -typedef std::vector< Partial > PARTIALS; -typedef std::vector< Oscillator > OSCILS; - -// debugging flag -// #define DEBUG_LORISGENS - -#pragma mark -- static helpers -- - -// --------------------------------------------------------------------------- -// import_partials -// --------------------------------------------------------------------------- -// -static void import_partials( const std::string & sdiffilname, PARTIALS & part ) -{ - try - { - // clear the dstination: - part.clear(); - - // import: - SdifFile f( sdiffilname ); - - // copy the Partials into the vector: - part.reserve( f.partials().size() ); - part.insert( part.begin(), f.partials().begin(), f.partials().end() ); - - // just for grins, sort the vector: - // std::sort( part.begin(), part.end(), PartialUtils::compare_label<>() ); - } - catch(Exception ex) - { - std::cerr << "\nERROR importing SDIF file: " << ex.what() << std::endl; - } - catch(std::exception ex) - { - std::cerr << "\nERROR importing SDIF file: " << ex.what() << std::endl; - } - -} - -// --------------------------------------------------------------------------- -// apply_fadetime -// --------------------------------------------------------------------------- -// Fade Partials in and out, if fadetime > 0. -// -static void apply_fadetime( PARTIALS & part, double fadetime ) -{ - // nothing to do if fadetime is zero: - if (fadetime <= 0.) - return; - - // iterator over all Partials, adding Breakpoints at both ends: - PARTIALS::iterator iter; - for ( iter = part.begin(); iter != part.end(); ++iter ) - { - Partial & partial = *iter; - - double btime = partial.startTime(); // get start time of partial - double etime = partial.endTime(); // get end time of partial - - // if a fadetime has been specified, introduce zero-amplitude - // Breakpoints to fade in and out over fadetime seconds: - if( fadetime != 0 ) - { - if ( partial.amplitudeAt(btime) > 0. ) - { - // only fade in if starting amplitude is non-zero: - if( btime > 0. ) - { - // if the Partial begins after time 0, insert a Breakpoint - // of zero amplitude at a time fadetime before the beginning, - // of the Partial, or at zero, whichever is later: - double t = std::max(btime - fadetime, 0.); - partial.insert( t, Breakpoint( partial.frequencyAt(t), - partial.amplitudeAt(t), - partial.bandwidthAt(t), - partial.phaseAt(t))); - } - else - { - // if the Partial begins at time zero, insert the zero-amplitude - // Breakpoint at time zero, and make sure that the next Breakpoint - // in the Partial is no more than fadetime away from the beginning - // of the Partial: - - // find the first Breakpoint later than time 0: - Partial::iterator pit = partial.begin(); - while (pit.time() < 0.) - ++pit; - if ( pit.time() > fadetime ) - { - // if first Breakpoint afer 0 is later than fadetime, - // insert a Breakpoint at fadetime: - double t = fadetime; - partial.insert( t, Breakpoint( partial.frequencyAt(t), - partial.amplitudeAt(t), - partial.bandwidthAt(t), - partial.phaseAt(t))); - } - - // insert the zero-amplitude Breakpoint at 0: - partial.insert( 0, Breakpoint( partial.frequencyAt(0), - 0, - partial.bandwidthAt(0), - partial.phaseAt(0))); - - } - } - - // add fadeout Breakpoint at end: - double t = etime + fadetime; - partial.insert( t, Breakpoint( partial.frequencyAt(t), - 0, - partial.bandwidthAt(t), - partial.phaseAt(t))); - } - } - -} - -// --------------------------------------------------------------------------- -// radianFreq -// --------------------------------------------------------------------------- -// Compute radian frequency (used by Loris::Oscillator) from frequency in Hz. -// -static inline double radianFreq( CSOUND *csound, double hz ) -{ - return hz * (double) csound->tpidsr; -} - -// --------------------------------------------------------------------------- -// accum_samples -// --------------------------------------------------------------------------- -// helper -// -static void accum_samples( CSOUND * csound, - Oscillator & oscil, Breakpoint & bp, - double * bufbegin ) -{ - if( bp.amplitude() > 0 || oscil.amplitude() > 0 ) - { - double radfreq = radianFreq( csound, bp.frequency() ); - double amp = bp.amplitude(); - double bw = bp.bandwidth(); - - // initialize the oscillator if it is changing from zero - // to non-zero amplitude in this control block: - if ( oscil.amplitude() == 0. ) - { - // don't initialize with bogus values, Oscillator - // only guards against out-of-range target values - // in generateSamples(), parameter mutators are - // dangerous: - - if ( radfreq > PI ) // don't alias - amp = 0.; - - if ( bw > 1. ) // clamp bandwidth - bw = 1.; - else if ( bw < 0. ) - bw = 0.; - -#ifdef DEBUG_LORISGENS - /* - std::cerr << "initializing oscillator " << std::endl; - std::cerr << "parameters: " << bp.frequency() << " "; - std::cerr << amp << " " << bw << std::endl; - */ -#endif - - // initialize frequency, amplitude, and bandwidth to - // their target values: - /* - oscil.setRadianFreq( radfreq ); - oscil.setAmplitude( amp ); - oscil.setBandwidth( bw ); - */ - oscil.resetEnvelopes( bp, (double) csound->esr ); - - // roll back the phase: - oscil.setPhase( bp.phase() - ( radfreq * (double) csound->ksmps ) ); - } - - // accumulate samples into buffer: - // oscil.generateSamples( bufbegin, bufbegin + nsamps, radfreq, amp, bw ); - oscil.oscillate( bufbegin, bufbegin + csound->ksmps, - bp, (double) csound->esr ); - } -} - -// --------------------------------------------------------------------------- -// clear_buffer -// --------------------------------------------------------------------------- -// helper -// -static inline void clear_buffer( double * buf, int nsamps ) -{ - std::fill( buf, buf + nsamps, 0. ); -} - -// --------------------------------------------------------------------------- -// convert_samples -// --------------------------------------------------------------------------- -// helper -// -static inline void convert_samples( CSOUND * csound, - const double * src, MYFLT * tgt ) -{ - double scaleFac = (double) csound->e0dbfs; - for(int i = 0; i < csound->ksmps; i++) - { - tgt[i] = (MYFLT) (src[i] * scaleFac); - } -} - -#pragma mark -- EnvelopeReader -- -// --------------------------------------------------------------------------- -// EnvelopeReader definition -// --------------------------------------------------------------------------- -// EnvelopeReader is a vector of Partial parameter envelope values sampled -// at some time, represented as Breakpoints, though not necessarily -// Breakpoints that are members of any Partial. Each set of parameters -// (Breakpoint) is paired with the label of the corresponding Partial. -// -// A static map of EnvelopeReader is maintained that allows EnvelopeReader -// to be found by index and Csound owner-instrument. A EnvelopeReader can -// be added to this map, by is parent LorisReader (below), and subsequently -// found by other generators having the same owner instrument. This is how -// lorisplay and lorismorph access the data read by a LorisReader. -// -class EnvelopeReader -{ - std::vector< std::pair< Breakpoint, long > > _vec; - - public: - // construction: - explicit EnvelopeReader( long n = 0 ) : _vec(n) {} - ~EnvelopeReader( void ) {} - - // access: - Breakpoint & valueAt( long idx ) { return _vec[idx].first; } - const Breakpoint & valueAt( long idx ) const { return _vec[idx].first; } - - long & labelAt( long idx ) { return _vec[idx].second; } - long labelAt( long idx ) const { return _vec[idx].second; } - - long size( void ) const { return _vec.size(); } - void resize( long n ) { _vec.resize(n); } - - // tagging: - typedef std::pair< INSDS *, int > Tag; - typedef std::map< Tag, EnvelopeReader * > TagMap; - static TagMap & Tags( void ); - static const EnvelopeReader * Find( INSDS * owner, int idx ); -}; - -// --------------------------------------------------------------------------- -// EnvelopeReader Tags -// --------------------------------------------------------------------------- -// Protect this map inside a function, because Csound has a C main() function, -// and global C++ objects cannot be guaranteed to be instantiated properly. -// -EnvelopeReader::TagMap & -EnvelopeReader::Tags( void ) -{ - static TagMap readers; // FIXME: should remove statics - return readers; -} - -// --------------------------------------------------------------------------- -// EnvelopeReader Tags -// --------------------------------------------------------------------------- -// May return NULL if no reader with the specified owner and index -// is found. -// -const EnvelopeReader * -EnvelopeReader::Find( INSDS * owner, int idx ) -{ - TagMap & readers = Tags(); - TagMap::iterator it = readers.find( Tag( owner, idx ) ); - if ( it != readers.end() ) - { -#ifdef DEBUG_LORISGENS - std::cerr << "** found EnvelopeReader with owner " << owner - << " and index " << idx; - std::cerr << " having " << it->second->size() << " envelopes." << std::endl; -#endif - return it->second; - } - else - { -#ifdef DEBUG_LORISGENS - std::cerr << "** could not find EnvelopeReader with owner " << owner - << " and index " << idx << std::endl; -#endif - return NULL; - } -} - -#pragma mark -- ImportedPartials -- - -// --------------------------------------------------------------------------- -// ImportedPartials definition -// --------------------------------------------------------------------------- -// ImportedPartials keeps track of a collection of imported Partials and the -// fadetime, if any, that is applied to them, and the name of the file from -// which they were imported. ImportedPartials instances can be compared using -// equivalence so that they can be stored in an associative container. -// ImportedPartials are stored in a std::set accessed by the static member -// GetPartials(), so that Partials from a particular file and using a -// particular fade time can be imported just once and reused. -// -// The PARTIALS member is mutable, since it is not involve in the equivalence -// test. Only const access to Partials is provided to clients, but the -// GetPartials() member needs to be able to import the Partials into a -// ImportedPartials that is already part of a std::set (and is thus immutable). -// (The alternative is to copy, which is wasteful.) -// -class ImportedPartials -{ - mutable PARTIALS _partials; - double _fadetime; - std::string _fname; - - public: - // construction: - ImportedPartials( void ) {} - ImportedPartials( const string & path, double fadetime ) : - _fadetime( fadetime ), _fname( path ) {} - ~ImportedPartials( void ) {} - - // access: - const Partial & operator [] ( long idx ) const { return _partials[idx]; } - - long size( void ) const { return _partials.size(); } - - // comparison: - friend bool operator < ( const ImportedPartials & lhs, - const ImportedPartials & rhs ) - { - return (lhs._fadetime < rhs._fadetime) || (lhs._fname < rhs._fname); - } - - // static member for managing a permanent collection: - static const ImportedPartials & GetPartials( const string & sdiffilname, - double fadetime ); -}; - -// --------------------------------------------------------------------------- -// GetPartials -// --------------------------------------------------------------------------- -// Return a reference to a collection of Partials from the specified file -// with the specified fadetime applied. Import if necessary, reuse previously -// imported Partials if possible. Store imported Partials in a permanent -// set of imported Partials. -// -const ImportedPartials & -ImportedPartials::GetPartials( const string & sdiffilname, double fadetime ) -{ - static std::set< ImportedPartials > AllPartials; - - ImportedPartials empty( sdiffilname, fadetime ); - std::set< ImportedPartials >::iterator it = AllPartials.find( empty ); - - if ( it == AllPartials.end() ) - { - it = AllPartials.insert( empty ).first; - - try - { - // import Partials and apply fadetime: -#ifdef DEBUG_LORISGENS - std::cerr << "** importing SDIF file " << sdiffilname << std::endl; -#endif - import_partials( sdiffilname, it->_partials ); - apply_fadetime( it->_partials, fadetime ); - } - catch( Exception & ex ) - { - std::string s("Loris exception in ImportedPartials::GetPartials(): " ); - s.append( ex.what() ); - std::cerr << s << std::endl; - } - catch( std::exception & ex ) - { - std::string s("std C++ exception in ImportedPartials::GetPartials(): " ); - s.append( ex.what() ); - std::cerr << s << std::endl; - } - } - else - { -#ifdef DEBUG_LORISGENS - std::cerr << "** reusing SDIF file " << sdiffilname << std::endl; -#endif - } - - return *it; -} - -#pragma mark -- LorisReader -- - -// --------------------------------------------------------------------------- -// LorisReader definition -// --------------------------------------------------------------------------- -// LorisReader samples a ImportedPartials instance at a given time, updated by -// calls to updateEnvelopePoints(). -// -class LorisReader -{ - const ImportedPartials & _partials; - EnvelopeReader _envelopes; - EnvelopeReader::Tag _tag; - - public: - // construction: - LorisReader( const string & fname, double fadetime, INSDS * owner, int idx ); - ~LorisReader( void ); - - // envelope parameter computation: - // (returns number of active Partials) - long updateEnvelopePoints( double time, double fscale, - double ascale, double bwscale ); -}; - -// --------------------------------------------------------------------------- -// LorisReader construction -// --------------------------------------------------------------------------- -// -LorisReader::LorisReader( const string & fname, double fadetime, - INSDS * owner, int idx ) : - _partials( ImportedPartials::GetPartials( fname, fadetime ) ), - _envelopes( _partials.size() ), - _tag( owner, idx ) -{ - // set the labels for the EnvelopeReader: - for ( size_t i = 0; i < _partials.size(); ++i ) - { - _envelopes.labelAt(i) = _partials[i].label(); - } - - // tag these envelopes: -#ifdef DEBUG_LORISGENS - std::cerr << "** constructed new EnvelopeReader with owner " << owner - << " and index " << idx; - std::cerr << " having " << _envelopes.size() << " envelopes." << std::endl; -#endif - EnvelopeReader::Tags()[ _tag ] = &_envelopes; -} - -// --------------------------------------------------------------------------- -// LorisReader destruction -// --------------------------------------------------------------------------- -// -LorisReader::~LorisReader( void ) -{ - // if this reader's envelopes are still in the tag map, - // remove them: - EnvelopeReader::TagMap & tags = EnvelopeReader::Tags(); - EnvelopeReader::TagMap::iterator it = tags.find( _tag ); - -#ifdef DEBUG_LORISGENS - std::cerr << "** destroying EnvelopeReader with owner " << _tag.first - << " and index " << _tag.second; - std::cerr << " having " << _envelopes.size() << " envelopes." << std::endl; -#endif - - if ( it != tags.end() && it->second == &_envelopes ) - { -#ifdef DEBUG_LORISGENS - std::cerr << "(Removing from Tag map.)" << std::endl; -#endif - tags.erase(it); - } -} - -// --------------------------------------------------------------------------- -// LorisReader updateEnvelopePoints -// --------------------------------------------------------------------------- -// -long -LorisReader::updateEnvelopePoints( double time, double fscale, - double ascale, double bwscale ) -{ - long countActive = 0; - - for (size_t i = 0; i < _partials.size(); ++i ) - { - const Partial & p = _partials[i]; - Breakpoint & bp = _envelopes.valueAt(i); - - // update envelope paramters for this Partial: - bp.setFrequency( fscale * p.frequencyAt( time ) ); - bp.setAmplitude( ascale * p.amplitudeAt( time ) ); - bp.setBandwidth( bwscale * p.bandwidthAt( time ) ); - bp.setPhase( p.phaseAt( time ) ); - - // update counter: - if ( bp.amplitude() > 0. ) - ++countActive; - } - - // tag these envelopes: - EnvelopeReader::Tags()[ _tag ] = &_envelopes; - - return countActive; -} - -#pragma mark -- lorisread generator functions -- - -extern "C" -int lorisread_cleanup(CSOUND *, void * p); - -// --------------------------------------------------------------------------- -// lorisread_setup -// --------------------------------------------------------------------------- -// Runs at initialization time for lorisplay. -// -extern "C" -int lorisread_setup( CSOUND *csound, LORISREAD * params ) -{ -#ifdef DEBUG_LORISGENS - std::cerr << "** Setting up lorisread (owner " << params->h.insdshead - << ")" << std::endl; -#endif - - std::string sdiffilname; - - // determine the name of the SDIF file to use: - { - char *tmp, *pathname; - // use strg name, if given: - tmp = csound->strarg2name( csound, (char*) 0, (void*) params->ifilnam, - "loris.sdif.", - (int) csound->GetInputArgSMask( (void*) params )); - pathname = csound->FindInputFile(csound, tmp, "SADIR"); - if (pathname == NULL) { - csound->InitError(csound, Str("lorisread cannot load %s"), tmp); - csound->Free(csound, (void*)tmp); - return NOTOK; - } - sdiffilname = pathname; - csound->Free( csound, (void*) tmp ); - csound->Free( csound, (void*) pathname ); - } - - // construct the implementation object: - params->imp = new LorisReader( sdiffilname, *params->fadetime, - params->h.insdshead, int(*params->readerIdx) ); - csound->NotifyFileOpened(csound, sdiffilname.c_str(), CSFTYPE_LORIS, 0, 0); - - // set lorisplay_cleanup as cleanup routine: - csound->RegisterDeinitCallback(csound, params, - (int (*)(CSOUND*, void*)) lorisread_cleanup); - return OK; -} - -// --------------------------------------------------------------------------- -// lorisread -// --------------------------------------------------------------------------- -// Control-rate generator function. -// -extern "C" -int lorisread( CSOUND *csound, LORISREAD * p ) -{ - //*(p->result) = - p->imp->updateEnvelopePoints( *p->time, *p->freqenv, *p->ampenv, *p->bwenv ); - return OK; -} - -// --------------------------------------------------------------------------- -// lorisread_cleanup -// --------------------------------------------------------------------------- -// Cleans up after lorisread. -// -extern "C" -int lorisread_cleanup(CSOUND *, void * p) -{ - LORISREAD * tp = (LORISREAD *)p; -#ifdef DEBUG_LORISGENS - std::cerr << "** Cleaning up lorisread (owner " << tp->h.insdshead - << ")" << std::endl; -#endif - delete tp->imp; - tp->imp = 0; - return OK; -} - -#pragma mark -- LorisPlayer -- - -// --------------------------------------------------------------------------- -// LorisPlayer definition -// --------------------------------------------------------------------------- -// Define a structure holding private internal data. -// -struct LorisPlayer -{ - const EnvelopeReader * reader; - OSCILS oscils; - - std::vector< double > dblbuffer; - - LorisPlayer( CSOUND *csound, LORISPLAY * params ); - ~LorisPlayer( void ) {} -}; - -// --------------------------------------------------------------------------- -// LorisPlayer contructor -// --------------------------------------------------------------------------- -// -LorisPlayer::LorisPlayer( CSOUND *csound, LORISPLAY * params ) : - reader( EnvelopeReader::Find( params->h.insdshead, (int)*(params->readerIdx))), - dblbuffer( csound->ksmps, 0.0 ) -{ - if ( reader != NULL ) { - oscils.resize( reader->size() ); - } else - std::cerr << "** Could not find lorisplay source with index " - << (int)*(params->readerIdx) << std::endl; -} - -#pragma mark -- lorisplay generator functions -- - -extern "C" -int lorisplay_cleanup(CSOUND *, void * p); - -// --------------------------------------------------------------------------- -// lorisplay_setup -// --------------------------------------------------------------------------- -// Runs at initialization time for lorisplay. -// -extern "C" -int lorisplay_setup( CSOUND *csound, LORISPLAY * p ) -{ -#ifdef DEBUG_LORISGENS - std::cerr << "** Setting up lorisplay (owner " << p->h.insdshead - << ")" << std::endl; -#endif - p->imp = new LorisPlayer( csound, p ); - csound->RegisterDeinitCallback(csound, p, - (int (*)(CSOUND*, void*)) lorisplay_cleanup); - return OK; -} - -// --------------------------------------------------------------------------- -// lorisplay -// --------------------------------------------------------------------------- -// Audio-rate generator function. -// -extern "C" -int lorisplay( CSOUND *csound, LORISPLAY * p ) -{ - LorisPlayer & player = *p->imp; - OSCILS & oscils = player.oscils; - // clear the buffer first! - double * bufbegin = &(player.dblbuffer[0]); - clear_buffer( bufbegin, csound->ksmps ); - - // now accumulate samples into the buffer: - long numOscils = player.oscils.size(); - for( long i = 0; i < numOscils; ++i ) - { - const Breakpoint & bp = player.reader->valueAt(i); - Breakpoint modifiedBp( (*p->freqenv) * bp.frequency(), - (*p->ampenv) * bp.amplitude(), - (*p->bwenv) * bp.bandwidth(), - bp.phase() ); - accum_samples( csound, oscils[i], modifiedBp, bufbegin ); - } - - // transfer samples into the result buffer: - convert_samples( csound, bufbegin, p->result ); - return OK; -} - -// --------------------------------------------------------------------------- -// lorisplay_cleanup -// --------------------------------------------------------------------------- -// Cleans up after lorisplay. -// -extern "C" -int lorisplay_cleanup(CSOUND *csound, void * p) -{ - LORISPLAY * tp = (LORISPLAY *)p; -#ifdef DEBUG_LORISGENS - std::cerr << "** Cleaning up lorisplay (owner " << tp->h.insdshead - << ")" << std::endl; -#endif - delete tp->imp; - tp->imp = 0; - return OK; -} - -#pragma mark -- LorisMorpher -- - -// --------------------------------------------------------------------------- -// LorisMorpher definition -// --------------------------------------------------------------------------- -// Define a structure holding private internal data for lorismorph -// -class LorisMorpher -{ - Morpher morpher; - const EnvelopeReader * src_reader; - const EnvelopeReader * tgt_reader; - - EnvelopeReader morphed_envelopes; - EnvelopeReader::Tag tag; - - typedef std::map< long, std::pair< long, long > > LabelMap; - LabelMap labelMap; - std::vector< long > src_unlabeled, tgt_unlabeled; - -public: - // construction: - LorisMorpher( LORISMORPH * params ); - ~LorisMorpher( void ); - - // envelope update: - long updateEnvelopes( void ); - - // - // Define Envelope classes that can access the - // morphing functions defined in the orchestra - // at the control rate: - struct GetFreqFunc : public Envelope - { - LORISMORPH * params; - GetFreqFunc( LORISMORPH * p ) : params(p) {} - GetFreqFunc( const GetFreqFunc & other ) : params( other.params ) {} - ~GetFreqFunc( void ) {} - - // Envelope interface: - GetFreqFunc * clone( void ) const { return new GetFreqFunc( *this ); } - - double valueAt( double /* time */ ) const - { - // ignore time, can only access the current value: - double val = *params->freqenv; - if ( val > 1 ) - val = 1; - else if ( val < 0 ) - val = 0; - return val; - } - }; - - struct GetAmpFunc : public Envelope - { - LORISMORPH * params; - GetAmpFunc( LORISMORPH * p ) : params(p) {} - GetAmpFunc( const GetAmpFunc & other ) : params( other.params ) {} - ~GetAmpFunc( void ) {} - - // Envelope interface: - GetAmpFunc * clone( void ) const { return new GetAmpFunc( *this ); } - - double valueAt( double /* time */ ) const - { - // ignore time, can only access the current value: - double val = *params->ampenv; - if ( val > 1 ) - val = 1; - else if ( val < 0 ) - val = 0; - return val; - } - }; - - struct GetBwFunc : public Envelope - { - LORISMORPH * params; - GetBwFunc( LORISMORPH * p ) : params(p) {} - GetBwFunc( const GetBwFunc & other ) : params( other.params ) {} - ~GetBwFunc( void ) {} - - // Envelope interface: - GetBwFunc * clone( void ) const { return new GetBwFunc( *this ); } - - double valueAt( double /* time */ ) const - { - // ignore time, can only access the current value: - double val = *params->bwenv; - if ( val > 1 ) - val = 1; - else if ( val < 0 ) - val = 0; - return val; - } - }; - -}; - -// --------------------------------------------------------------------------- -// LorisMorpher contructor -// --------------------------------------------------------------------------- -// This is a very ugly piece of code to set up an index map that makes it -// fast to associate the Breakpoints in the source and target readers with -// the correct Oscillator. There should be a nicer way to do this, but -// we cannot count on anything like unique labeling (though the results -// will be unpredictable if the labeling is not unique), so it seems -// like an index map is the most efficient way. -// -LorisMorpher::LorisMorpher( LORISMORPH * params ) : - morpher( GetFreqFunc( params ), GetAmpFunc( params ), GetBwFunc( params ) ), - src_reader( EnvelopeReader::Find( params->h.insdshead, - (int)*(params->srcidx) ) ), - tgt_reader( EnvelopeReader::Find( params->h.insdshead, - (int)*(params->tgtidx) ) ), - tag( params->h.insdshead, (int)*(params->morphedidx) ) -{ - if ( src_reader != NULL ) - { - // map source Partial indices: - // (make a note of the largest label we see) - src_unlabeled.reserve( src_reader->size() ); - long maxsrclabel = 0; - for ( size_t i = 0; i < src_reader->size(); ++i ) - { - long label = src_reader->labelAt(i); - if ( label != 0 ) - labelMap[ label ] = std::make_pair(i, long(-1)); - else - src_unlabeled.push_back( i ); - - if ( label > maxsrclabel ) - maxsrclabel = label; - } -#ifdef DEBUG_LORISGENS - std::cerr << "** Largest source label is " << maxsrclabel << std::endl; -#endif - } - else - { - std::cerr << "** Could not find lorismorph source with index " - << (int)*(params->srcidx) << std::endl; - } - - if ( tgt_reader != NULL ) - { - // map target Partial indices: - // (make a note of the largest label we see) - tgt_unlabeled.reserve( tgt_reader->size() ); - long maxtgtlabel = 0; - for ( size_t i = 0; i < tgt_reader->size(); ++i ) - { - long label = tgt_reader->labelAt(i); - if ( label != 0 ) - { - if ( labelMap.count( label ) > 0 ) - labelMap[ label ].second = i; - else - labelMap[ label ] = std::make_pair(long(-1), i); - } - else - tgt_unlabeled.push_back( i ); - - if ( label > maxtgtlabel ) - maxtgtlabel = label; - } -#ifdef DEBUG_LORISGENS - std::cerr << "** Largest target label is " << maxtgtlabel << std::endl; -#endif - } - else - { - std::cerr << "** Could not find lorismorph target with index " - << (int)*(params->tgtidx) << std::endl; - } - -#ifdef DEBUG_LORISGENS - std::cerr << "** Morph will use " << labelMap.size() << " labeled Partials, "; - std::cerr << src_unlabeled.size() << " unlabeled source Partials, and "; - std::cerr << tgt_unlabeled.size() << " unlabeled target Partials." - << std::endl; -#endif - - // allocate and set the labels for the morphed envelopes: - morphed_envelopes.resize( labelMap.size() + src_unlabeled.size() - + tgt_unlabeled.size() ); - long envidx = 0; - LabelMap::iterator it; - for( it = labelMap.begin(); it != labelMap.end(); ++it, ++envidx ) - { - morphed_envelopes.labelAt(envidx) = it->first; - } - - // tag these envelopes: - EnvelopeReader::Tags()[ tag ] = &morphed_envelopes; -} - -// --------------------------------------------------------------------------- -// LorisMorpher destruction -// --------------------------------------------------------------------------- -// -LorisMorpher::~LorisMorpher( void ) -{ - // if the morphed envelopes are still in the tag map, - // remove them: - EnvelopeReader::TagMap & tags = EnvelopeReader::Tags(); - EnvelopeReader::TagMap::iterator it = tags.find( tag ); - - if ( it != tags.end() && it->second == &morphed_envelopes ) - { - tags.erase(it); - } -} - -// --------------------------------------------------------------------------- -// LorisMorpher updateEnvelopes -// --------------------------------------------------------------------------- -// Taking it on faith that the EnvelopeReaders will not be destroyed before -// we are done using them! -// -long -LorisMorpher::updateEnvelopes( void ) -{ - // first render all the labeled (morphed) Partials: - // std::cerr << "** Morphing Partials labeled " << labelMap.begin()->first; - // std::cerr << " to " << (--labelMap.end())->first << std::endl; - - long envidx = 0; - LabelMap::iterator it; - for( it = labelMap.begin(); it != labelMap.end(); ++it, ++envidx ) - { - std::pair & indices = it->second; - Breakpoint bp = morphed_envelopes.valueAt(envidx); - - long isrc = indices.first; - long itgt = indices.second; - - // this should not happen: - if ( itgt < 0 && isrc < 0 ) - { -#ifdef DEBUG_LORISGENS - std::cerr << - "HEY!!!! The labelMap had a pair of bogus indices in it at pos " - << envidx << std::endl; -#endif - continue; - } - - // note: the time argument for all these morphParameters calls - // is irrelevant, since it is only used to index the morphing - // functions, which, as defined above, do not use the time - // argument, they can only return their current value. - if ( itgt < 0 ) - { - // morph from the source to a dummy: - // std::cerr << "** Fading from source " << envidx << std::endl; - bp = morpher.fadeSrcBreakpoint( src_reader->valueAt(isrc), 0.0 ); - } - else if ( isrc < 0 ) - { - // morph from a dummy to the target: - // std::cerr << "** Fading to target " << envidx << std::endl; - bp = morpher.fadeTgtBreakpoint( tgt_reader->valueAt(itgt), 0.0 ); - } - else - { - // morph from the source to the target: - // std::cerr << "** Morphing source to target " << envidx << std::endl; - bp = morpher.morphBreakpoints( src_reader->valueAt(isrc), - tgt_reader->valueAt(itgt), 0.0 ); - } - } - - // render unlabeled source Partials: - // std::cerr << "** Crossfading " << src_unlabeled.size(); - // std::cerr << " unlabeled source Partials" << std::endl; - for( size_t i = 0; i < src_unlabeled.size(); ++i, ++envidx ) - { - // fade from the source: - Breakpoint & bp = morphed_envelopes.valueAt(envidx); - bp = morpher.fadeSrcBreakpoint( src_reader->valueAt( src_unlabeled[i] ), - 0.0 ); - } - - // render unlabeled target Partials: - // std::cerr << "** Crossfading " << tgt_unlabeled.size(); - // std::cerr << " unlabeled target Partials" << std::endl; - for( size_t i = 0; i < tgt_unlabeled.size(); ++i, ++envidx ) - { - // fade to the target: - Breakpoint & bp = morphed_envelopes.valueAt(envidx); - bp = morpher.fadeTgtBreakpoint( tgt_reader->valueAt( tgt_unlabeled[i] ), - 0.0 ); - } - - // tag these envelopes: - EnvelopeReader::Tags()[ tag ] = &morphed_envelopes; - - return morphed_envelopes.size(); -} - -#pragma mark -- lorismorph generator functions -- - -extern "C" -int lorismorph_cleanup(CSOUND *csound, void * p); -// --------------------------------------------------------------------------- -// lorismorph_setup -// --------------------------------------------------------------------------- -// Runs at initialization time for lorismorph. -// -extern "C" -int lorismorph_setup( CSOUND *csound, LORISMORPH * p ) -{ -#ifdef DEBUG_LORISGENS - std::cerr << "** Setting up lorismorph (owner " << p->h.insdshead - << ")" << std::endl; -#endif - p->imp = new LorisMorpher( p ); - csound->RegisterDeinitCallback(csound, p, - (int (*)(CSOUND*, void*)) lorismorph_cleanup); - return OK; -} - -// --------------------------------------------------------------------------- -// lorismorph -// --------------------------------------------------------------------------- -// Audio-rate generator function. -// -extern "C" -int lorismorph( CSOUND *csound, LORISMORPH * p ) -{ - //*p->result = - p->imp->updateEnvelopes(); - return OK; -} - -// --------------------------------------------------------------------------- -// lorismorph_cleanup -// --------------------------------------------------------------------------- -// Cleans up after lorismorph. -// -extern "C" -int lorismorph_cleanup(CSOUND *csound, void * p) -{ - LORISMORPH * tp = (LORISMORPH *)p; -#ifdef DEBUG_LORISGENS - std::cerr << "** Cleaning up lorismorph (owner " << tp->h.insdshead - << ")" << std::endl; -#endif - delete tp->imp; - tp->imp = 0; - return OK; -} - -// --------------------------------------------------------------------------- -// Loris csounds plugin -// --------------------------------------------------------------------------- -// Added by Michael Gogins to make Loris generators work as a -// dynamically-loaded plugin to Csound. -// -extern "C" -{ - OENTRY loris_localops[] = - { - {(char*)"lorisread", sizeof(LORISREAD), 3, (char*)"", (char*)"kTikkko", - (SUBR) lorisread_setup, (SUBR) lorisread, 0 }, - {(char*)"lorisplay", sizeof(LORISPLAY), 5, (char*)"a", (char*)"ikkk", - (SUBR) lorisplay_setup, 0, (SUBR) lorisplay }, - {(char*)"lorismorph", sizeof(LORISMORPH), 3, (char*)"", (char*)"iiikkk", - (SUBR) lorismorph_setup, (SUBR) lorismorph, 0 } - }; - - LINKAGE1(loris_localops) - -} - -/* - This works: - - ../libtool --mode=compile g++ -DHAVE_CONFIG_H -I.. -I../src -I/usr/local/src/Csound-4.23 -g -O2 -c -o lorisgens.lo lorisgens.C - - ../libtool --mode=link g++ -o lorisgens.la -rpath /usr/local/lib -module -avoid-version lorisgens.lo ../src/libloris.la -lstdc++ - - csound --opcode-lib=.libs/lorisgens.so tryit.csd -*/ diff -Nru csound-5.17.11~dfsg/Opcodes/Loris/lorisgens5.h csound-6.02~dfsg/Opcodes/Loris/lorisgens5.h --- csound-5.17.11~dfsg/Opcodes/Loris/lorisgens5.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Loris/lorisgens5.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,96 +0,0 @@ -#ifndef INCLUDE_LORISGENS5_H -#define INCLUDE_LORISGENS5_H -/* - * This is the Loris C++ Class Library, implementing analysis, - * manipulation, and synthesis of digitized sounds using the Reassigned - * Bandwidth-Enhanced Additive Sound Model. - * - * Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY, without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * - * lorisgens.h - * - * Header file containing structure definitions for Csound unit generators - * supporting bandwidth-enhanced synthesis and sound morphing using the - * Loris library. - * - * The lorisplay module was originally written by Corbin Champion, 2002. - * - * Kelly Fitz, 9 May 2002 - * loris@cerlsoundgroup.org - * - * http://www.cerlsoundgroup.org/Loris/ - * - */ - -#include "csdl.h" - -/* declare structures holding private internal data */ -typedef struct LorisReader LorisReader; -typedef struct LorisPlayer LorisPlayer; -typedef struct LorisMorpher LorisMorpher; - -/* Define a structure to hold parameters for the lorisread module. */ -typedef struct -{ - /* standard structure holding csound global data (esr, ksmps, etc.) */ - OPDS h; - - /* no output - MYFLT *result; */ - - /* unit generator parameters/arguments */ - MYFLT *time, *ifilnam, *readerIdx, *freqenv, *ampenv, *bwenv, *fadetime; - - /* private internal data, used by generator */ - LorisReader *imp; -} LORISREAD; - -/* Define a structure to hold parameters for the lorisplay module. */ -typedef struct -{ - /* standard structure holding csound global data (esr, ksmps, etc.) */ - OPDS h; - - /* output */ - MYFLT *result; - - /* unit generator parameters/arguments */ - MYFLT *readerIdx, *freqenv, *ampenv, *bwenv; - - /* private internal data, used by generator */ - LorisPlayer *imp; -} LORISPLAY; - -/* Define a structure to hold parameters for the lorismorph module. */ -typedef struct -{ - /* standard structure holding csound global data (esr, ksmps, etc.) */ - OPDS h; - - /* no output - MYFLT *result; */ - - /* unit generator parameters/arguments */ - MYFLT *srcidx, *tgtidx, *morphedidx, *freqenv, *ampenv, *bwenv; - - /* private internal data, used by generator */ - LorisMorpher *imp; -} LORISMORPH; - -#endif /* nef INCLUDE_LORISGENS_H */ - diff -Nru csound-5.17.11~dfsg/Opcodes/Loris/morphdemo.py csound-6.02~dfsg/Opcodes/Loris/morphdemo.py --- csound-5.17.11~dfsg/Opcodes/Loris/morphdemo.py 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Loris/morphdemo.py 1970-01-01 00:00:00.000000000 +0000 @@ -1,232 +0,0 @@ -#!python -# -# This is the Loris C++ Class Library, implementing analysis, -# manipulation, and synthesis of digitized sounds using the Reassigned -# Bandwidth-Enhanced Additive Sound Model. -# -# Loris is Copyright (c) 1999-2004 by Kelly Fitz and Lippold Haken -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program (Loris); if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA, -# or to the authors at loris@cerlsoundgroup.org. -# -# -# morphdemo.py -# -# Loris instrument tone morphing demonstration. -# -# Kelly Fitz, 28 Sept 1999 -# loris@cerlsoundgroup.org -# -# http://www.cerlsoundgroup.org/Loris/ -# -# updated 7 May 2002 by kel -# -""" -Welcome to the Loris morphing demo! -Kelly Fitz 2002 - -Generates several morphs between a clarinet, -a flute, and a cello. The results can be compared -to those in the "reference" directory. - -In order to run this demo, the Loris module (loris.py -and _loris.so) must be in your PYTHONPATH. -""" -print __doc__ - -import loris, os, time -print '(in %s)\n' % os.getcwd() - -print '(using Loris version %s)\n' % loris.version() - -srcdir = 'source' - -# -# analyze flute tone -# -# The analysis process is as follows: -# - configure the analyzer (the flute and clarinet use the -# same analyzer configuration) -# - analyze, yielding a collection of partials -# - extract a reference envelope and distill partials -# (this reduces the number of partials considerably by -# connecting and condensing related partials; for example, -# in quasi-harmonic sounds, the distillation process yields -# one partial per harmonic) -# - a test synthesis of the distilled partials is performed, -# just as a sanity check, and to verify the suitability of the -# analysis configuration and distillation parameters -# -print 'analyzing flute 3D (%s)' % time.ctime(time.time()) -a = loris.Analyzer(.8*291, 1.0*291) -ff = loris.AiffFile( os.path.join(srcdir, 'flute.source.aiff') ) -v = ff.samples() -samplerate = ff.sampleRate() -flut = a.analyze( v, samplerate ) -print 'using fundamental as reference' -flut_env = loris.createFreqReference( flut, 250, 500, 20 ) -loris.channelize( flut, flut_env, 1 ) -loris.distill( flut ) - -# -# analyze clarinet tone -# -print 'analyzing clarinet 3G# (%s)' % time.ctime(time.time()) -a = loris.Analyzer(.8*415, 1.0*415) -cf = loris.AiffFile( os.path.join(srcdir, 'clarinet.source.aiff') ) -v = cf.samples() -samplerate = cf.sampleRate() -clar = a.analyze( v, samplerate ) -print 'using fundamental as reference' -env = loris.createFreqReference( clar, 350, 500, 20 ) -loris.channelize( clar, env, 1 ) -loris.distill( clar ) -print 'shifting clarinet pitch down by six half steps' -loris.shiftPitch( clar, loris.BreakpointEnvelopeWithValue( -600 ) ) -print 'doubling amplitude' -loris.scaleAmp( clar, loris.BreakpointEnvelopeWithValue( 2 ) ) - -# -# analyze cello tone -# -print 'analyzing cello 2D# (%s)' % time.ctime(time.time()) -a = loris.Analyzer(.7*135, 1.8*135) -celf = loris.AiffFile( os.path.join(srcdir, 'cello.source.aiff') ) -v = celf.samples() -samplerate = celf.sampleRate() -cel = a.analyze( v, samplerate ) -print 'using third harmonic as reference' -third = loris.createFreqReference( cel, 400, 500, 20 ) -loris.channelize( cel, third, 3 ) -loris.distill( cel ) - -# -# perform temporal dilation -# -# Times are the beginning and end times -# of the attack and the release. To change -# the duration of the morph, change the -# target times (tgt_times), as well as the -# morphing function, mf, defined below. -# -flute_times = [0.175, 0.4, 2.15, 2.31] -clar_times = [0., 0.185, 1.9, 2.15] -cel_times = [0., 0.13, 2.55, 3.9] -tgt_times = [0., 0.19, 3., 3.25] - -print 'dilating sounds to match', tgt_times, '(%s)' % time.ctime(time.time()) -print 'flute times:', flute_times -loris.dilate( flut, flute_times, tgt_times) -print 'clarinet times:', clar_times -loris.dilate( clar, clar_times, tgt_times ) -print 'cello times:', cel_times -loris.dilate( cel, cel_times, tgt_times ) - -# -# synthesize and save dilated sources -# -# Save the synthesized samples files, and SDIF files -# for each dilated source. -# -fname = 'flute.dilated.aiff' -print 'synthesizing', fname, '(%s)' % time.ctime(time.time()) -loris.exportAiff( fname, loris.synthesize( flut, samplerate ), samplerate, 16, 1 ) -fname = 'flute.dilated.sdif' -print 'exporting sdif file:', fname, '(%s)' % time.ctime(time.time()) -loris.exportSdif( fname, flut ) - -fname = 'clar.dilated.aiff' -print 'synthesizing', fname, '(%s)' % time.ctime(time.time()) -loris.exportAiff( fname, loris.synthesize( clar, samplerate ), samplerate, 16, 1 ) -fname = 'clarinet.dilated.sdif' -print 'exporting sdif file:', fname, '(%s)' % time.ctime(time.time()) -loris.exportSdif( fname, clar ) - -fname = 'cello.dilated.aiff' -print 'synthesizing', fname, '(%s)' % time.ctime(time.time()) -loris.exportAiff( fname, loris.synthesize( cel, samplerate ), samplerate, 16, 1 ) -fname = 'cello.dilated.sdif' -print 'exporting sdif file:', fname, '(%s)' % time.ctime(time.time()) -loris.exportSdif( fname, cel ) - -# -# perform morphs -# -# Morphs are from the first sound to the -# second over the time 0.6 to 1.6 seconds. -# -mf = loris.BreakpointEnvelope() -mf.insertBreakpoint( 0.6, 0 ) -mf.insertBreakpoint( 1.6, 1 ) - -samplerate = 44100. - -print 'morphing flute and clarinet (%s)' % time.ctime(time.time()) -m = loris.morph( clar, flut, mf, mf, mf ) -loris.exportAiff( 'clariflute.aiff', - loris.synthesize( m, samplerate ), - samplerate, 16, 1 ) -print 'exporting sdif file clariflute.aiff', '(%s)' % time.ctime(time.time()) -loris.exportSdif( 'clariflute.sdif', m ) - -loris.exportAiff( 'flutinet.aiff', - loris.synthesize( loris.morph( flut, clar, mf, mf, mf ), samplerate ), - samplerate, 16, 1 ) - -print 'morphing flute and cello (%s)' % time.ctime(time.time()) -print 'shifting flute pitch down by eleven half steps' -flut_low = flut.copy() -loris.shiftPitch( flut_low, loris.BreakpointEnvelopeWithValue( -1100 ) ) -loris.exportAiff( 'cellute.aiff', - loris.synthesize( loris.morph( cel, flut_low, mf, mf, mf ), samplerate ), - samplerate, 16, 1 ) -loris.exportAiff( 'flutello.aiff', - loris.synthesize( loris.morph( flut_low, cel, mf, mf, mf ), samplerate ), - samplerate, 16, 1 ) - -print 'morphing flute and cello again (%s)' % time.ctime(time.time()) -print 'shifting flute pitch up by one half step' -loris.shiftPitch( flut, loris.BreakpointEnvelopeWithValue( 100 ) ) - -# double all labels: -#it = flut.begin() -#while not it.equals(flut.end()): -for it in flut: - it.setLabel( it.label()*2) - #it = it.next() - -print 'exporting Spc files for pre-morphed flute and cello sounds.' -print 'exporting Spc file flute.premorph.spc', '(%s)' % time.ctime(time.time()) -loris.exportSpc('flute.premorph.spc', flut, 62, 0) -print 'exporting Spc file cello.premorph.spc', '(%s)' % time.ctime(time.time()) -loris.exportSpc('cello.premorph.spc', cel, 50, 0) - -m = loris.morph( cel, flut, mf, mf, mf ) -loris.exportAiff( 'cellute2.aiff', - loris.synthesize( m, samplerate ), - samplerate, 16, 1 ) - -print 'exporting Spc file for second flute and cello morph.' -print 'exporting Spc file cellute2.spc', '(%s)' % time.ctime(time.time()) -loris.exportSpc('cellute2.spc', m, 50, 0) - -m = loris.morph( flut, cel, mf, mf, mf ) -loris.exportAiff( 'flutello2.aiff', - loris.synthesize( m, samplerate ), - samplerate, 16, 1 ) - -# all done -print 'hey, I\'m spent. (%s)' % time.ctime(time.time()) - diff -Nru csound-5.17.11~dfsg/Opcodes/Loris/trymorph.csd csound-6.02~dfsg/Opcodes/Loris/trymorph.csd --- csound-5.17.11~dfsg/Opcodes/Loris/trymorph.csd 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Loris/trymorph.csd 1970-01-01 00:00:00.000000000 +0000 @@ -1,113 +0,0 @@ - - -csound -A -d -o trymurph.aiff temp.orc temp.sco - - -; originally tryit.orc -sr = 44100 -kr = 4410 -ksmps = 10 -nchnls = 1 - -; -; Morph the partials in clarinet.sdif into the -; partials in flute.sdif over the duration of -; the sustained portion of the two tones (from -; .2 to 2.0 seconds in the clarinet, and from -; .5 to 2.1 seconds in the flute). The onset -; and decay portions in the morphed sound are -; specified by parameters p4 and p5, respectively. -; The morphing time is the time between the -; onset and the decay. The clarinet partials are -; shfited in pitch to match the pitch of the flute -; tone (D above middle C). -; -instr 1 - ionset = p4 - idecay = p5 - itmorph = p3 - (ionset + idecay) - ipshift = cpspch(8.02)/cpspch(8.08) - - ktcl linseg 0, ionset, .2, itmorph, 2.0, idecay, 2.1 ; clarinet time function, morph from .2 to 2.0 seconds - ktfl linseg 0, ionset, .5, itmorph, 2.1, idecay, 2.3 ; flute time function, morph from .5 to 2.1 seconds - kmurph linseg 0, ionset, 0, itmorph, 1, idecay, 1 - lorisread ktcl, "clarinet.sdif", 1, ipshift, 2, 1, .001 - lorisread ktfl, "flute.sdif", 2, 1, 1, 1, .001 - lorismorph 1, 2, 3, kmurph, kmurph, kmurph - asig lorisplay 3, 1, 1, 1 - out asig -endin - -; -; Morph the partials in trombone.sdif into the -; partials in meow.sdif. The start and end times -; for the morph are specified by parameters p4 -; and p5, respectively. The morph occurs over the -; second of four pitches in each of the sounds, -; from .75 to 1.2 seconds in the flutter-tongued -; trombone tone, and from 1.7 to 2.2 seconds in -; the cat's meow. Different morphing functions are -; used for the frequency and amplitude envelopes, -; so that the partial amplitudes make a faster -; transition from trombone to cat than the frequencies. -; (The bandwidth envelopes use the same morphing -; function as the amplitudes.) -; -instr 2 - ionset = p4 - imorph = p5 - p4 - irelease = p3 - p5 - - kttbn linseg 0, ionset, .75, imorph, 1.2, irelease, 2.4 - ktmeow linseg 0, ionset, 1.7, imorph, 2.2, irelease, 3.4 - - kmfreq linseg 0, ionset, 0, .75*imorph, .25, .25*imorph, 1, irelease, 1 - kmamp linseg 0, ionset, 0, .75*imorph, .9, .25*imorph, 1, irelease, 1 - - lorisread kttbn, "trombone.sdif", 1, 1, 1, 1, .001 - lorisread ktmeow, "meow.sdif", 2, 1, 1, 1, .001 - lorismorph 1, 2, 3, kmfreq, kmamp, kmamp - asig lorisplay 3, 1, 1, 1 - out asig -endin - -;; -;; Morph the partials in carhorn.sdif into -;; the partials in meow.sdif linearly over -;; all but the last 2 seconds of the note. -;; The morph is performed over the first -;; .75 seconds of the source sounds. The last -;; 2.5 seconds (of meow) is unmodified. -;; Use 1 ms fade time. -;; -;instr 2 -; ktime1 linseg 0, p3, 3.4 -; ktime2 linseg 0, p3, 1.25 -; kmurph linseg 0, p3/3, 0, p3/3, 1, p3/3, 1 -; -; lorisread ktime1, "meow3.sdif", 1, 1, 1, 1, .001 -; lorisread ktime2, "carhorn.sdif", 2, 1, 1, 1, .001 -; lorismorph 1, 2, 3, kmurph, kmurph, kmurph -; asig lorisplay 3, 1, 1, 1 -; out asig -;endin - - - -; play instr 1 -; strt dur onset decay -i 1 0 3 .25 .15 -i 1 + 1 .10 .10 -i 1 + 6 1. 1. - -f 0 11 -s - -; play instr 2 -; strt dur morph_start morph_end -i 2 0 4 .75 2.75 - -e - - - diff -Nru csound-5.17.11~dfsg/Opcodes/LuaCsound.cpp csound-6.02~dfsg/Opcodes/LuaCsound.cpp --- csound-5.17.11~dfsg/Opcodes/LuaCsound.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/LuaCsound.cpp 2014-01-07 16:54:20.000000000 +0000 @@ -12,20 +12,23 @@ GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public - License along with Csound; if OPCODE_IOBUFSnot, write to the Free Software + License along with Csound; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include +#include #include #include #include #include #include -#include +#include #include #include +using namespace std; + extern "C" { #include @@ -59,15 +62,36 @@ int noteoff_key; }; +static pthread_mutex_t lc_getrefkey = PTHREAD_MUTEX_INITIALIZER; +static pthread_mutex_t lc_manageLuaState = PTHREAD_MUTEX_INITIALIZER; + +struct CriticalSection +{ + CriticalSection(pthread_mutex_t &mutex_) : mutex(mutex_), status(-1) + { + status = pthread_mutex_lock(&mutex); + } + ~CriticalSection() + { + if (status >= 0) { + pthread_mutex_unlock(&mutex); + } + } + pthread_mutex_t &mutex; + int status; +}; + /** * Thread-safe storage for Lua references to opcode subroutines. */ -keys_t &manageLuaReferenceKeys(const lua_State *L, const std::string &opcode, char operation = 'O') +keys_t &manageLuaReferenceKeys(const lua_State *L, + const std::string &opcode, char operation) { - static std::map > luaReferenceKeys; + static std::map > luaReferenceKeys; keys_t *keys = 0; - #pragma omp critical(lc_getrefkey) { + CriticalSection criticalSection(lc_getrefkey); switch(operation) { case 'O': @@ -86,46 +110,64 @@ return *keys; } + +struct LuaStateForThread +{ + pthread_t thread; + lua_State *L; +}; + +bool operator == (const LuaStateForThread& a, const LuaStateForThread &b) +{ + if (pthread_equal(a.thread, b.thread)) { + return true; + } else { + return false; + } +} + /** * Thread-safe storage for Lua states (virtual machines). There is one Lua state * per thread, rather than per instance of Csound, in case one instance of Csound * is running multiple threads with multiple instances of a Lua opcode. */ -lua_State *manageLuaState(char operation = 'O') +lua_State *manageLuaState(char operation) { - static std::map luaStatesForThreads; + static std::vector luaStatesForThreads; + CriticalSection criticalSection(lc_manageLuaState); + LuaStateForThread luaStateForThread; + luaStateForThread.thread = pthread_self(); + std::vector::iterator it = + std::find(luaStatesForThreads.begin(), + luaStatesForThreads.end(), + luaStateForThread); lua_State *L = 0; - #pragma omp critical(lc_manageLuaState) + switch(operation) { - int threadId = omp_get_thread_num(); - switch(operation) - { - case 'O': + case 'O': + { + if (it == luaStatesForThreads.end()) { - if (luaStatesForThreads.find(threadId) == luaStatesForThreads.end()) - { - L = lua_open(); - luaL_openlibs(L); - luaStatesForThreads[threadId] = L; - } - else - { - L = luaStatesForThreads[threadId]; - } + luaStateForThread.L = lua_open(); + luaL_openlibs(luaStateForThread.L); + luaStatesForThreads.push_back(luaStateForThread); + L = luaStateForThread.L; } - break; - case 'C': + else { - L = luaStatesForThreads[threadId]; - if (L) - { - manageLuaReferenceKeys(L, "", 'C'); - } - luaStatesForThreads.erase(threadId); + L = it->L; } - break; + } + break; + case 'C': + { + if (it != luaStatesForThreads.end()) { + manageLuaReferenceKeys(it->L, "", 'C'); + luaStatesForThreads.erase(it); } } + break; + } return L; } @@ -145,16 +187,13 @@ int init(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); + lua_State *L = manageLuaState('O'); /* Ensure that Csound is available in the global environment. */ lua_pushlightuserdata(L, csound); lua_setfield(L, LUA_GLOBALSINDEX, "csound"); - const char *luacode = csound->strarg2name(csound, - (char *) 0, - luacode_, - (char *)"default", - (int) csound->GetInputArgSMask(this)); - //log(csound, "Executing Lua code:\n%s\n", luacode); + const char *luacode = ((STRINGDAT *)luacode_)->data; + log(csound, "Executing (L: 0x%p) Lua code.\n", L); + warn(csound, "\n%s\n", luacode); result = luaL_dostring(L, luacode); if (result == 0) { @@ -179,22 +218,27 @@ * output and/or input arguments may be passed. * All arguments must be passed on the right-hand * side and outputs are returned in the argument. - * Requires opname_init and opname_kontrol to be defined in Lua. + * Requires opname_init and opname_kontrol to be + * defined in Lua. * * lua_iaopcall Sname, ... Calls a Lua opcode at i-rate and a-rate. Any number of * output and/or input arguments may be passed. * All arguments must be passed on the right-hand * side and outputs are returned in the argument. - * Requires opname_init and opname_audio to be defined in Lua. + * Requires opname_init and opname_audio to be defined + * in Lua. * * Opcode that actually implements arbitrary Lua opcodes * by calling from Csound into Lua functions. * * Lua functions access elements of arguments as follows - * (pointers to both scalars and arrays are dereferenced by the array access operator): - * ffi.cdef(' struct arguments_t { double *a_out, double *i_in, double *i_txt, double *f_sig };'); + * (pointers to both scalars and arrays are dereferenced by the array + * access operator): + * ffi.cdef(' struct arguments_t { double *a_out, double *i_in, + * double *i_txt, double *f_sig };'); * local arguments = ffi.cast("struct arguments_t *", carguments_lightuserdata) - * for i = 0, ksmps -1 do begin carguments.a_out[i] = carguments.i_in[0] * 3 end end + * for i = 0, ksmps -1 do begin carguments.a_out[i] = carguments.i_in[0] * 3 + * end end */ class cslua_opcall: public OpcodeBase { @@ -213,7 +257,7 @@ * additional data, e.g. for opcode state, after the opcode output and * input arguments, as limited by the available space. */ - MYFLT *arguments[0x3000]; + MYFLT *arguments[1000]; const char *opcodename; public: /** @@ -225,20 +269,17 @@ int init(CSOUND *csound) { int result = OK; - opcodename = csound->strarg2name(csound, - (char *) 0, - opcodename_, - (char *)"default", - (int) csound->GetInputArgSMask(this)); - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + opcodename = ((STRINGDAT *)opcodename_)->data; + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.init_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, &arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_init\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_init\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -248,15 +289,16 @@ int kontrol(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.kontrol_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, &arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_kontrol\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_kontrol\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -266,15 +308,16 @@ int audio(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.audio_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_audio\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_audio\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -289,17 +332,21 @@ * side and outputs are returned in the argument. * Requires opname_init to be defined in Lua. * - * lua_ikopcall_off Sname, ... Calls a Lua opcode at i-rate and k-rate. Any number of - * output and/or input arguments may be passed. + * lua_ikopcall_off Sname, ... Calls a Lua opcode at i-rate and k-rate. Any + * number of output and/or input arguments may be + * passed. * All arguments must be passed on the right-hand * side and outputs are returned in the argument. - * Requires opname_init and opname_kontrol to be defined in Lua. + * Requires opname_init and opname_kontrol to be + * defined in Lua. * - * lua_iaopcall_off Sname, ... Calls a Lua opcode at i-rate and a-rate. Any number of - * output and/or input arguments may be passed. + * lua_iaopcall_off Sname, ... Calls a Lua opcode at i-rate and a-rate. Any + * number of output and/or input arguments may be + * passed. * All arguments must be passed on the right-hand * side and outputs are returned in the argument. - * Requires opname_init and opname_audio to be defined in Lua. + * Requires opname_init and opname_audio to be + * defined in Lua. * * Opcode that actually implements arbitrary Lua opcodes * by calling from Csound into Lua functions; this variant @@ -309,10 +356,13 @@ * instrument with a reverb tail, and so on. * * Lua functions access elements of arguments as follows - * (pointers to both scalars and arrays are dereferenced by the array access operator): - * ffi.cdef(' struct arguments_t { double *a_out, double *i_in, double *i_txt, double *f_sig };'); + * (pointers to both scalars and arrays are dereferenced by the array + * access operator): + * ffi.cdef(' struct arguments_t { double *a_out, double *i_in, + * double *i_txt, double *f_sig };'); * local arguments = ffi.cast("struct arguments_t *", carguments_lightuserdata) - * for i = 0, ksmps -1 do begin carguments.a_out[i] = carguments.i_in[0] * 3 end end + * for i = 0, ksmps -1 do begin carguments.a_out[i] = carguments.i_in[0] * 3 + * end end */ class cslua_opcall_off: public OpcodeNoteoffBase { @@ -331,7 +381,7 @@ * additional data, e.g. for opcode state, after the opcode output and * input arguments, as limited by the available space. */ - MYFLT *arguments[0x3000]; + MYFLT *arguments[1000]; const char *opcodename; public: /** @@ -343,20 +393,17 @@ int init(CSOUND *csound) { int result = OK; - opcodename = csound->strarg2name(csound, - (char *) 0, - opcodename_, - (char *)"default", - (int) csound->GetInputArgSMask(this)); - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + opcodename = ((STRINGDAT *)opcodename_)->data; + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.init_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, &arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_init\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_init\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -366,15 +413,16 @@ int kontrol(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.kontrol_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, &arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_kontrol\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_kontrol\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -384,15 +432,16 @@ int audio(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.audio_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_audio\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_audio\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -402,19 +451,21 @@ int noteoff(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + lua_State *L = manageLuaState('O'); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); lua_rawgeti(L, LUA_REGISTRYINDEX, keys.noteoff_key); lua_pushlightuserdata(L, csound); lua_pushlightuserdata(L, this); lua_pushlightuserdata(L, arguments); if (lua_pcall(L, 3, 1, 0) != 0) { - log(csound, "Lua error in \"%s_noteoff\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua error in \"%s_noteoff\": %s.\n", + opcodename, lua_tostring(L, -1)); } else { - log(csound, "Lua called \"%s_noteoff\": %s.\n", opcodename, lua_tostring(L, -1)); + log(csound, "Lua called \"%s_noteoff\": %s.\n", + opcodename, lua_tostring(L, -1)); } result = lua_tonumber(L, -1); lua_pop(L, 1); @@ -467,26 +518,22 @@ int init(CSOUND *csound) { int result = OK; - lua_State *L = manageLuaState(); - const char *opcodename = csound->strarg2name(csound, - (char *) 0, - opcodename_, - (char *)"default", - (int) csound->GetInputArgSMask(this)); - const char *luacode = csound->strarg2name(csound, - (char *) 0, - luacode_, - (char *)"default", - (int) csound->GetInputArgSMask(this)); + lua_State *L = manageLuaState('O'); + /* Ensure that Csound is available in the global environment. */ + lua_pushlightuserdata(L, csound); + lua_setfield(L, LUA_GLOBALSINDEX, "csound"); + const char *opcodename = ((STRINGDAT *)opcodename_)->data; + const char *luacode = ((STRINGDAT *)luacode_)->data; //log(csound, "Executing Lua code:\n%s\n", luacode); result = luaL_dostring(L, luacode); if (result == 0) { - keys_t &keys = manageLuaReferenceKeys(L, opcodename); + keys_t &keys = manageLuaReferenceKeys(L, opcodename, 'O'); log(csound, "Opcode: %s\n", opcodename); log(csound, "Result: %d\n", result); char init_function[0x100]; - std::snprintf(init_function, 0x100, "%s_init", opcodename); //h.optext->t.opcod); + snprintf(init_function, 0x100, + "%s_init", opcodename); //h.optext->t.opcod); lua_getglobal(L, init_function); if (!lua_isnil(L, 1)) { @@ -494,7 +541,8 @@ lua_pop(L, 1); } char kontrol_function[0x100]; - std::snprintf(kontrol_function, 0x100, "%s_kontrol", opcodename); //h.optext->t.opcod); + snprintf(kontrol_function, 0x100, + "%s_kontrol", opcodename); //h.optext->t.opcod); lua_getglobal(L, kontrol_function); if (!lua_isnil(L, 1)) { @@ -502,7 +550,8 @@ lua_pop(L, 1); } char audio_function[0x100]; - std::snprintf(audio_function, 0x100, "%s_audio", opcodename); //h.optext->t.opcod); + snprintf(audio_function, 0x100, + "%s_audio", opcodename); //h.optext->t.opcod); lua_getglobal(L, audio_function); if (!lua_isnil(L, 1)) { @@ -510,7 +559,8 @@ lua_pop(L, 1); } char noteoff_function[0x100]; - std::snprintf(noteoff_function, 0x100, "%s_noteoff", opcodename); //h.optext->t.opcod); + snprintf(noteoff_function, 0x100, + "%s_noteoff", opcodename); //h.optext->t.opcod); lua_getglobal(L, noteoff_function); if (!lua_isnil(L, 1)) { @@ -539,6 +589,7 @@ { (char*)"lua_exec", sizeof(cslua_exec), + 0, 1, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -552,6 +603,7 @@ { (char*)"lua_iopcall", sizeof(cslua_opcall), + 0, 1, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -565,6 +617,7 @@ { (char*)"lua_ikopcall", sizeof(cslua_opcall), + 0, 3, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -578,6 +631,7 @@ { (char*)"lua_iaopcall", sizeof(cslua_opcall), + 0, 5, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -591,6 +645,7 @@ { (char*)"lua_iopcall_off", sizeof(cslua_opcall_off), + 0, 1, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -604,6 +659,7 @@ { (char*)"lua_ikopcall_off", sizeof(cslua_opcall_off), + 0, 3, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -617,6 +673,7 @@ { (char*)"lua_iaopcall_off", sizeof(cslua_opcall_off), + 0, 5, (char*)"", (char*)"TNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN" @@ -630,6 +687,7 @@ { (char*)"lua_opdef", sizeof(cslua_opdef), + 0, 1, // No outputs. (char*)"", @@ -649,6 +707,7 @@ 0, 0, 0, + 0, } }; @@ -665,6 +724,7 @@ status |= csound->AppendOpcode(csound, oentry->opname, oentry->dsblksiz, + oentry->flags, oentry->thread, oentry->outypes, oentry->intypes, diff -Nru csound-5.17.11~dfsg/Opcodes/OSC.c csound-6.02~dfsg/Opcodes/OSC.c --- csound-5.17.11~dfsg/Opcodes/OSC.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/OSC.c 2014-01-07 16:54:20.000000000 +0000 @@ -29,37 +29,31 @@ /* structure for real time event */ -typedef struct rtEvt_s { - struct rtEvt_s *nxt; - EVTBLK e; -} rtEvt_t; +/* typedef struct rtEvt_s { */ +/* struct rtEvt_s *nxt; */ +/* EVTBLK e; */ +/* } rtEvt_t; */ typedef struct { OPDS h; /* default header */ MYFLT *kwhen; - MYFLT *host; + STRINGDAT *host; MYFLT *port; /* UDP port */ - MYFLT *dest; - MYFLT *type; + STRINGDAT *dest; + STRINGDAT *type; MYFLT *arg[32]; /* only 26 can be used, but add a few more for safety */ lo_address addr; MYFLT last; int cnt; } OSCSEND; -#ifdef VARGA -typedef struct { - OPDS h; - MYFLT *i_port; - MYFLT *S_path; - MYFLT *i_absp2; -} OSCRECV; -#endif typedef struct osc_pat { struct osc_pat *next; - MYFLT *args[31]; - MYFLT data[1]; + union { + MYFLT number; + STRINGDAT string; + } args[31]; } OSC_PAT; typedef struct { @@ -76,14 +70,6 @@ /* for OSCinit/OSClisten */ int nPorts; OSC_PORT *ports; -#ifdef VARGA - /* for OSCrecv */ - rtEvt_t *eventQueue; - void *mutex_; - lo_server_thread st; - double baseTime; - int absp2mode; -#endif } OSC_GLOBALS; /* opcode for starting the OSC listener (called once from orchestra header) */ @@ -97,8 +83,8 @@ OPDS h; /* default header */ MYFLT *kans; MYFLT *ihandle; - MYFLT *dest; - MYFLT *type; + STRINGDAT *dest; + STRINGDAT *type; MYFLT *args[32]; OSC_PORT *port; char *saved_path; @@ -121,7 +107,7 @@ char *pp = port; char *hh; - /* with too many args, XINCODE/XSTRCODE may not work correctly */ + /* with too many args, XINCODE may not work correctly */ if (UNLIKELY(p->INOCOUNT > 31)) return csound->InitError(csound, Str("Too many arguments to OSCsend")); /* a-rate arguments are not allowed */ @@ -132,7 +118,7 @@ pp = NULL; else sprintf(port, "%d", (int) MYFLT2LRND(*p->port)); - hh = (char*) p->host; + hh = (char*) p->host->data; if (*hh=='\0') hh = NULL; p->addr = lo_address_new(hh, pp); p->cnt = 0; @@ -156,25 +142,19 @@ int i=0; int msk = 0x20; /* First argument */ lo_message msg = lo_message_new(); - char *type = (char*)p->type; + char *type = (char*)p->type->data; MYFLT **arg = p->arg; p->last = *p->kwhen; for (i=0; type[i]!='\0'; i++, msk <<=1) { /* Need to add type checks */ switch (type[i]) { case 'i': - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); lo_message_add_int32(msg, (int32_t) MYFLT2LRND(*arg[i])); break; case 'l': - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); lo_message_add_int64(msg, (int64_t) MYFLT2LRND(*arg[i])); break; case 'c': - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); lo_message_add_char(msg, (char) (*arg[i] + FL(0.5))); break; case 'm': @@ -183,43 +163,30 @@ int32_t x; uint8_t m[4]; } mm; - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); mm.x = *arg[i]+FL(0.5); lo_message_add_midi(msg, mm.m); break; } case 'f': - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); lo_message_add_float(msg, (float)(*arg[i])); break; case 'd': - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); lo_message_add_double(msg, (double)(*arg[i])); break; case 's': - if (LIKELY(p->XSTRCODE&msk)) - lo_message_add_string(msg, (char*)arg[i]); - else - return csound->PerfError(csound, Str("Not a string when needed")); + lo_message_add_string(msg, ((STRINGDAT *)arg[i])->data); break; case 'b': /* Boolean */ - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); if (*arg[i]==FL(0.0)) lo_message_add_true(msg); else lo_message_add_false(msg); break; case 't': /* timestamp */ { lo_timetag tt; - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); tt.sec = (uint32_t)(*arg[i]+FL(0.5)); msk <<= 1; i++; if (UNLIKELY(type[i]!='t')) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Time stamp is two values")); tt.frac = (uint32_t)(*arg[i]+FL(0.5)); lo_message_add_timetag(msg, tt); @@ -232,15 +199,13 @@ int len; FUNC *ftp; void *data; - if (UNLIKELY(p->XSTRCODE&msk)) - return csound->PerfError(csound, Str("String not expected")); /* make sure fn exists */ - if (LIKELY((ftp=csound->FTFind(csound,arg[i]))!=NULL)) { + if (LIKELY((ftp=csound->FTnp2Find(csound,arg[i]))!=NULL)) { data = ftp->ftable; len = ftp->flen-1; /* and set it up */ } else { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("ftable %.2f does not exist"), *arg[i]); } myblob = lo_blob_new(sizeof(MYFLT)*len, data); @@ -253,165 +218,17 @@ csound->Warning(csound, Str("Unknown OSC type %c\n"), type[1]); } } - lo_send_message(p->addr, (char*)p->dest, msg); + lo_send_message(p->addr, (char*)p->dest->data, msg); lo_message_free(msg); } return OK; } -#ifdef VARGA -/* callback function called by sensevents() once in every control period */ - -static void event_sense_callback(CSOUND *csound, OSC_GLOBALS *p) -{ - /* are there any pending events ? */ - if (p->eventQueue == NULL) - return; - - csound->LockMutex(p->mutex_); - while (p->eventQueue != NULL) { - long startTime; - rtEvt_t *ep = p->eventQueue; - p->eventQueue = ep->nxt; - csound->UnlockMutex(p->mutex_); - startTime = (p->absp2mode ? p->baseTime*csound->esr : csound->icurTime); - startTime += (double) ep->e.p[2]*csound->esr; - ep->e.p[2] = FL(0.0); - if (ep->e.pcnt < 3 || ep->e.p[3] < FL(0.0) || - ep->e.opcod == 'q' || ep->e.opcod == 'f' || ep->e.opcod == 'e' || - (double) ep->e.p[3] >= csound->icurTime - startTime) { - if (startTime < csound->icurTime) { - if (ep->e.pcnt >= 3 && ep->e.p[3] > FL(0.0) && - ep->e.opcod != 'q' && ep->e.opcod != 'f') - ep->e.p[3] -= (MYFLT) (csound->icurTime - startTime)/csound->esr; - startTime = csound->icurTime; - } - if (ep->e.opcod == 'T') - p->baseTime = csound->icurTime/csound->esr; - else - csound->insert_score_event_at_sample(csound, &(ep->e), startTime); - } - if (ep->e.strarg != NULL) - free(ep->e.strarg); - free(ep); - csound->LockMutex(p->mutex_); - } - csound->UnlockMutex(p->mutex_); -} - -/* callback function for OSC thread */ -/* NOTE: this function does not run in the main Csound audio thread, */ -/* so use of the API or access to CSOUND should be limited or avoided */ - -static int osc_event_handler(const char *path, const char *types, - lo_arg **argv, int argc, lo_message msg, - void *user_data) -{ - OSC_GLOBALS *p = (OSC_GLOBALS*) user_data; - CSOUND *csound = p->csound; - rtEvt_t *evt; - int i; - char opcod = '\0'; - - /* check for valid format */ - if ((unsigned int) (argc - 1) > (unsigned int) PMAX) - return 1; - switch ((int) types[0]) { - case 'i': opcod = (char) argv[0]->i; break; - case 'f': opcod = (char) MYFLT2LRND((MYFLT) argv[0]->f); break; - case 's': opcod = (char) argv[0]->s; break; - default: return 1; - } - switch ((int) opcod) { - case 'e': break; - case 'T': if (argc > 1) return 1; - break; - case 'f': if (argc < 6) return 1; - break; - case 'i': - case 'q': - case 'a': if (argc < 4) return 1; - break; - default: return 1; - } - /* Create the new event */ - evt = (rtEvt_t*) malloc(sizeof(rtEvt_t)); - if (evt == NULL) - return 1; - evt->nxt = NULL; - evt->e.strarg = NULL; - evt->e.opcod = opcod; - evt->e.pcnt = argc - 1; - evt->e.p[1] = evt->e.p[2] = evt->e.p[3] = FL(0.0); - for (i = 1; i < argc; i++) { - switch ((int) types[i]) { - case 'i': - evt->e.p[i] = (MYFLT) argv[i]->i; - break; - case 'f': - evt->e.p[i] = (MYFLT) argv[i]->f; - break; - case 's': - /* string argument: cannot have more than one */ - evt->e.p[i] = (MYFLT) SSTRCOD; - if (evt->e.strarg != NULL) { - free(evt->e.strarg); - free(evt); - return 1; - } - evt->e.strarg = (char*) malloc(strlen(&(argv[i]->s)) + 1); - if (evt->e.strarg == NULL) { - free(evt); - return 1; - } - strcpy(evt->e.strarg, &(argv[i]->s)); - break; - } - } - /* queue event for handling by main Csound thread */ - csound->LockMutex(p->mutex_); - if (p->eventQueue == NULL) - p->eventQueue = evt; - else { - rtEvt_t *ep = p->eventQueue; - while (ep->nxt != NULL) - ep = ep->nxt; - ep->nxt = evt; - } - csound->UnlockMutex(p->mutex_); - return 0; -} - -static void osc_error_handler(int n, const char *msg, const char *path) -{ - return; -} -#endif - /* RESET routine for cleaning up */ static int OSC_reset(CSOUND *csound, OSC_GLOBALS *p) { int i; - -#ifdef VARGA - if (p->mutex_ != NULL) { - /* stop and destroy OSC thread */ - lo_server_thread_stop(p->st); - lo_server_thread_free(p->st); - /* delete any pending events */ - csound->LockMutex(p->mutex_); - while (p->eventQueue != NULL) { - rtEvt_t *nxt = p->eventQueue->nxt; - if (p->eventQueue->e.strarg != NULL) - free(p->eventQueue->e.strarg); - free(p->eventQueue); - p->eventQueue = nxt; - } - csound->UnlockMutex(p->mutex_); - csound->DestroyMutex(p->mutex_); - } -#endif for (i = 0; i < p->nPorts; i++) if (p->ports[i].thread) { lo_server_thread_stop(p->ports[i].thread); @@ -432,8 +249,10 @@ if (pp != NULL) return pp; if (UNLIKELY(csound->CreateGlobalVariable(csound, "_OSC_globals", - sizeof(OSC_GLOBALS)) != 0)) - csound->Die(csound, Str("OSC: failed to allocate globals")); + sizeof(OSC_GLOBALS)) != 0)){ + csound->ErrorMsg(csound, Str("OSC: failed to allocate globals")); + return NULL; + } pp = (OSC_GLOBALS*) csound->QueryGlobalVariable(csound, "_OSC_globals"); pp->csound = csound; csound->RegisterResetCallback(csound, (void*) pp, @@ -441,40 +260,7 @@ return pp; } -#ifdef VARGA -/* OSCrecv opcode (called once from orchestra header) */ -static int OSCrecv_init(CSOUND *csound, OSCRECV *p) -{ - OSC_GLOBALS *pp; - char portName[256], *pathName; - - /* allocate and initialise the globals structure */ - pp = alloc_globals(csound); - if (UNLIKELY(pp->mutex_ != NULL)) - return csound->InitError(csound, Str("OSCrecv is already running")); - pp->eventQueue = NULL; - pp->mutex_ = csound->Create_Mutex(0); - pp->baseTime = 0.0; - pp->absp2mode = (*(p->i_absp2) == FL(0.0) ? 0 : 1); - /* create OSC thread */ - sprintf(portName, "%d", (int) MYFLT2LRND(*p->i_port)); - pp->st = lo_server_thread_new(portName, - (lo_err_handler) osc_error_handler); - /* register OSC event handler */ - pathName = (char*) p->S_path; - if (pathName[0] == '\0') - pathName = NULL; - lo_server_thread_add_method(pp->st, pathName, NULL, - (lo_method_handler) osc_event_handler, pp); - /* start thread */ - lo_server_thread_start(pp->st); - /* register callback function for sensevents() */ - csound->RegisterSenseEventCallback(csound, (void (*)(CSOUND*, void*)) - event_sense_callback, pp); - return OK; -} -#endif /* ------------------------------------------------------------------------ */ @@ -482,27 +268,14 @@ { CSOUND *csound; OSC_PAT *p; - size_t nbytes, str_smps; - int i, cnt, strArgMask; + size_t nbytes; csound = pp->h.insdshead->csound; - cnt = csound->GetInputArgCnt(pp) - 3; - strArgMask = (int) (csound->GetInputArgSMask(pp) >> 3); /* number of bytes to allocate */ - nbytes = sizeof(OSC_PAT) - sizeof(MYFLT); - str_smps = (size_t) csound->strVarMaxLen + sizeof(MYFLT) - (size_t) 1; - str_smps /= sizeof(MYFLT); - for (i = 0; i < cnt; i++) - nbytes += (((strArgMask & (1 << i)) ? str_smps : (size_t) 1) - * sizeof(MYFLT)); + nbytes = sizeof(OSC_PAT); /* allocate and initialise structure */ - p = (OSC_PAT*) malloc(nbytes); - if (p == NULL) - return NULL; - p->args[0] = &(p->data[0]); - for (i = 1; i < cnt; i++) - p->args[i] = (MYFLT*) p->args[i - 1] - + ((strArgMask & (1 << (i - 1))) ? (int) str_smps : 1); + p = (OSC_PAT*) csound->Calloc(csound, nbytes); + return p; } @@ -523,6 +296,7 @@ { OSC_PORT *pp = (OSC_PORT*) p; OSCLISTEN *o; + CSOUND *csound = (CSOUND *) pp->csound; int retval = 1; pp->csound->LockMutex(pp->mutex_); @@ -550,32 +324,42 @@ switch (types[i]) { default: /* Should not happen */ case 'i': - *(m->args[i]) = (MYFLT) argv[i]->i; break; + m->args[i].number = (MYFLT) argv[i]->i; break; case 'h': - *(m->args[i]) = (MYFLT) argv[i]->i64; break; + m->args[i].number = (MYFLT) argv[i]->i64; break; case 'c': - *(m->args[i]) = (MYFLT) argv[i]->c; break; + m->args[i].number= (MYFLT) argv[i]->c; break; case 'f': - *(m->args[i]) = (MYFLT) argv[i]->f; break; + m->args[i].number = (MYFLT) argv[i]->f; break; case 'd': - *(m->args[i]) = (MYFLT) argv[i]->d; break; + m->args[i].number= (MYFLT) argv[i]->d; break; case 's': { - char *src = (char*) &(argv[i]->s), *dst = (char*) m->args[i]; - char *endp = dst + (pp->csound->strVarMaxLen - 1); - while (*src != (char) '\0' && dst != endp) - *(dst++) = *(src++); - *dst = (char) '\0'; + char *src = (char*) &(argv[i]->s), *dst = m->args[i].string.data; + if(m->args[i].string.size <= (int) strlen(src)){ + if(dst != NULL) csound->Free(csound, dst); + dst = csound->Strdup(csound, src); + m->args[i].string.size = strlen(dst) + 1; + m->args[i].string.data = dst; + } + else strcpy(dst, src); + } break; } } + retval = 0; } + break; + } + + o = (OSCLISTEN*) o->nxt; } + pp->csound->UnlockMutex(pp->mutex_); return retval; } @@ -649,14 +433,14 @@ p->patterns = NULL; while (m != NULL) { OSC_PAT *mm = m->next; - free(m); + csound->Free(csound, m); m = mm; } m = p->freePatterns; p->freePatterns = NULL; while (m != NULL) { OSC_PAT *mm = m->next; - free(m); + csound->Free(csound, m); m = mm; } return OK; @@ -664,7 +448,7 @@ static int OSC_list_init(CSOUND *csound, OSCLISTEN *p) { - void *x; + //void *x; int i, n; OSC_GLOBALS *pp = (OSC_GLOBALS*) @@ -676,16 +460,17 @@ if (UNLIKELY(n < 0 || n >= pp->nPorts)) return csound->InitError(csound, Str("invalid handle")); p->port = &(pp->ports[n]); - p->saved_path = (char*) csound->Malloc(csound, strlen((char*) p->dest) + 1); - strcpy(p->saved_path, (char*) p->dest); + p->saved_path = (char*) csound->Malloc(csound, + strlen((char*) p->dest->data) + 1); + strcpy(p->saved_path, (char*) p->dest->data); /* check for a valid argument list */ n = csound->GetInputArgCnt(p) - 3; if (UNLIKELY(n < 1 || n > 28)) return csound->InitError(csound, Str("invalid number of arguments")); - if (UNLIKELY((int) strlen((char*) p->type) != n)) + if (UNLIKELY((int) strlen((char*) p->type->data) != n)) return csound->InitError(csound, "argument list inconsistent with format string"); - strcpy(p->saved_types, (char*) p->type); + strcpy(p->saved_types, (char*) p->type->data); for (i = 0; i < n; i++) { const char *s; s = csound->GetInputArgName(p, i + 3); @@ -718,9 +503,9 @@ p->nxt = p->port->oplst; p->port->oplst = (void*) p; csound->UnlockMutex(p->port->mutex_); - x = lo_server_thread_add_method(p->port->thread, - p->saved_path, p->saved_types, - OSC_handler, p->port); + (void) lo_server_thread_add_method(p->port->thread, + p->saved_path, p->saved_types, + OSC_handler, p->port); csound->RegisterDeinitCallback(csound, p, (int (*)(CSOUND *, void *)) OSC_listdeinit); return OK; @@ -744,10 +529,23 @@ p->patterns = m->next; /* copy arguments */ for (i = 0; p->saved_types[i] != '\0'; i++) { - if (p->saved_types[i] != 's') - *(p->args[i]) = *(m->args[i]); - else - strcpy((char*) p->args[i], (char*) m->args[i]); + if (p->saved_types[i] != 's') { + *(p->args[i]) = m->args[i].number; + } + else { + char *src = m->args[i].string.data; + char *dst = ((STRINGDAT*) p->args[i])->data; + if(src != NULL) { + if(((STRINGDAT*) p->args[i])->size <= (int) strlen(src)){ + if(dst != NULL) csound->Free(csound, dst); + dst = csound->Strdup(csound, src); + ((STRINGDAT*) p->args[i])->size = strlen(dst) + 1; + ((STRINGDAT*) p->args[i])->data = dst; + } + else + strcpy(dst, src); + } + } } /* push to stack of free message structures */ m->next = p->freePatterns; @@ -763,12 +561,9 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "OSCsend", S(OSCSEND), 3, "", "kSiSSN", (SUBR)osc_send_set, (SUBR)osc_send }, -#ifdef VARGA -{ "OSCrecv", S(OSCRECV), 1, "", "iSo", (SUBR)OSCrecv_init }, -#endif -{ "OSCinit", S(OSCINIT), 1, "i", "i", (SUBR)osc_listener_init }, -{ "OSClisten", S(OSCLISTEN),3, "k", "iSSN", (SUBR)OSC_list_init, (SUBR)OSC_list} +{ "OSCsend", S(OSCSEND), 0, 3, "", "kSiSSN", (SUBR)osc_send_set, (SUBR)osc_send }, +{ "OSCinit", S(OSCINIT), 0, 1, "i", "i", (SUBR)osc_listener_init }, +{ "OSClisten", S(OSCLISTEN),0, 3, "k", "iSSN", (SUBR)OSC_list_init, (SUBR)OSC_list} }; PUBLIC long csound_opcode_init(CSOUND *csound, OENTRY **ep) @@ -782,4 +577,3 @@ { return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - diff -Nru csound-5.17.11~dfsg/Opcodes/Vosim.c csound-6.02~dfsg/Opcodes/Vosim.c --- csound-5.17.11~dfsg/Opcodes/Vosim.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/Vosim.c 2014-01-07 16:53:47.000000000 +0000 @@ -74,9 +74,9 @@ Str("vosim: zero kfund. 'Infinite' length event generated.")); } else { - p->timrem = (int32)(csound->esr / fundabs); + p->timrem = (int32)(CS_ESR / fundabs); if (UNLIKELY(p->timrem == 0)) { - p->timrem = csound->ksmps; + p->timrem = CS_KSMPS; p->pulstogo = 0; csound->Warning(csound, Str("vosim: kfund (%f) > sr. Generating ksmps silence."), @@ -118,7 +118,9 @@ int vosim(CSOUND* csound, VOSIM *p) { - int32 nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar = p->ar; MYFLT *ftdata; int32 lobits; @@ -128,7 +130,12 @@ ftdata = ftp->ftable; lobits = ftp->lobits; - while (nsmps > 0) { + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; ntimrem == 0) vosim_event(csound, p); @@ -140,24 +147,25 @@ if (p->pulstogo > 0) { /* produce one sample */ p->pulsephs &= PHMASK; - *ar++ = *(ftdata + (p->pulsephs >> lobits)) * p->pulseamp; + ar[n] = *(ftdata + (p->pulsephs >> lobits)) * p->pulseamp; --p->timrem; - --nsmps; p->pulsephs += p->pulseinc; } else { /* silence after last pulse in burst: */ /* bypass regular synthesis and fill output with zeros */ - while (p->timrem && nsmps) { - *ar++ = FL(0.0); + while (p->timrem && ntimrem; - --nsmps; + n++; } + n--; } } return OK; err1: - return csound->PerfError(csound, Str("vosim: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vosim: not initialised")); } @@ -167,8 +175,8 @@ #define S(x) sizeof(x) static OENTRY vosim_localops[] = { - { "vosim", S(VOSIM), TR|5, "a", "kkkkkkio", (SUBR)vosimset, NULL, (SUBR)vosim } + { "vosim", S(VOSIM), TR, 5, "a", "kkkkkkio", (SUBR)vosimset, NULL, (SUBR)vosim } }; -LINKAGE1(vosim_localops) +LINKAGE_BUILTIN(vosim_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/afilters.c csound-6.02~dfsg/Opcodes/afilters.c --- csound-5.17.11~dfsg/Opcodes/afilters.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/afilters.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,696 @@ +/* + afilters.c: + + Copyright (C) 1991 Barry Vercoe, John ffitch, Gabriel Maldonado + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include "csoundCore.h" /* AFILTERS.C */ +#include "ugens5.h" +#include + +extern int rsnset(CSOUND *csound, RESON *p); + +static int aresonaa(CSOUND *csound, RESON *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t flag = 0, n, nsmps = CS_KSMPS; + MYFLT *ar, *asig; + double c3p1, c3t4, omc3, c2sqr; /* 1/RMS = root2 (rand) */ + /* or 1/.5 (sine) */ + double yt1, yt2, c1, c2, c3; + + asig = p->asig; + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + c1 = p->c1; c2 = p->c2; c3 = p->c3; yt1 = p->yt1; yt2 = p->yt2; + if (p->scale == 1 || p->scale == 0) { + for (n=offset; nkcf[n] != (MYFLT)p->prvcf) { + p->prvcf = (double)p->kcf[n]; + p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + flag = 1; + } + if (p->kbw[n] != (MYFLT)p->prvbw) { + p->prvbw = (double)p->kbw[n]; + p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + flag = 1; + } + if (flag) { + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - sig; /* yt1 contains yt1-xt1 */ + ar[n] = (MYFLT)ans; + } + } + else if (p->scale == 2) { + for (n=offset; nkcf[n] != (MYFLT)p->prvcf) { + p->prvcf = (double)p->kcf[n]; + p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + flag = 1; + } + if (p->kbw[n] != (MYFLT)p->prvbw) { + p->prvbw = (double)p->kbw[n]; + p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + flag = 1; + } + if (flag) { + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - 2.0 * sig; /* yt1 contains yt1-D*xt1 */ + ar[n] = (MYFLT)ans; + } + } + p->yt1 = yt1; p->yt2 = yt2; + return OK; +} + +static int aresonak(CSOUND *csound, RESON *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *ar, *asig; + double c3p1, c3t4, omc3, c2sqr; /* 1/RMS = root2 (rand) */ + /* or 1/.5 (sine) */ + double yt1, yt2, c1, c2, c3; + + if (*p->kbw != (MYFLT)p->prvbw) { + p->prvbw = (double)*p->kbw; + p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + asig = p->asig; + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + c1 = p->c1; c2 = p->c2; c3 = p->c3; yt1 = p->yt1; yt2 = p->yt2; + if (p->scale == 1 || p->scale == 0) { + for (n=offset; nkcf[n] != (MYFLT)p->prvcf) { + p->prvcf = (double)p->kcf[n]; + p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - sig; /* yt1 contains yt1-xt1 */ + ar[n] = (MYFLT)ans; + } + } + else if (p->scale == 2) { + for (n=offset; nkcf[n] != (MYFLT)p->prvcf) { + p->prvcf = (double)p->kcf[n]; + p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - 2.0 * sig; /* yt1 contains yt1-D*xt1 */ + ar[n] = (MYFLT)ans; + } + } + p->yt1 = yt1; p->yt2 = yt2; + return OK; +} + +static int aresonka(CSOUND *csound, RESON *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *ar, *asig; + double c3p1, c3t4, omc3, c2sqr; /* 1/RMS = root2 (rand) */ + /* or 1/.5 (sine) */ + double yt1, yt2, c1, c2, c3; + + if (*p->kcf != (MYFLT)p->prvcf) { + p->prvcf = (double)*p->kcf; + p->cosf = cos(p->prvcf * (double)(csound->tpidsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + asig = p->asig; + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + c1 = p->c1; c2 = p->c2; c3 = p->c3; yt1 = p->yt1; yt2 = p->yt2; + if (p->scale == 1 || p->scale == 0) { + for (n=offset; nkbw[n] != (MYFLT)p->prvbw) { + p->prvbw = (double)p->kbw[n]; + p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - sig; /* yt1 contains yt1-xt1 */ + ar[n] = (MYFLT)ans; + } + } + else if (p->scale == 2) { + for (n=offset; nkbw[n] != (MYFLT)p->prvbw) { + p->prvbw = (double)p->kbw[n]; + p->c3 = exp(p->prvbw * (double)(csound->mtpdsr)); + c3p1 = p->c3 + 1.0; + c3t4 = p->c3 * 4.0; + omc3 = 1.0 - p->c3; + p->c2 = c3t4 * p->cosf / c3p1; + c2sqr = p->c2 * p->c2; + if (p->scale == 1) /* i.e. 1 - A(reson) */ + p->c1 = 1.0 - omc3 * sqrt(1.0 - c2sqr / c3t4); + else if (p->scale == 2) /* i.e. D - A(reson) */ + p->c1 = 2.0 - sqrt((c3p1*c3p1-c2sqr)*omc3/c3p1); + else p->c1 = 0.0; /* cannot tell */ + } + ans = c1 * sig + c2 * yt1 - c3 * yt2; + yt2 = yt1; + yt1 = ans - 2.0 * sig; /* yt1 contains yt1-D*xt1 */ + ar[n] = (MYFLT)ans; + } + } + p->yt1 = yt1; p->yt2 = yt2; + return OK; +} + +extern int tonset(CSOUND*, TONE*); +extern int tonsetx(CSOUND *csound, TONEX *p); + +static int atonea(CSOUND *csound, TONE *p) +{ + MYFLT *ar, *asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + double c2 = p->c2, yt1 = p->yt1; + + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + asig = p->asig; + for (n=offset; nkhp[n] != p->prvhp) { + double b; + p->prvhp = p->khp[n]; + b = 2.0 - cos((double)(p->khp[n] * csound->tpidsr)); + p->c2 = c2 = b - sqrt(b * b - 1.0); + /* p->c1 = c1 = 1.0 - c2; */ + } + x = yt1 = c2 * (yt1 + sig); + ar[n] = (MYFLT)x; + yt1 -= sig; /* yt1 contains yt1-xt1 */ + } + p->yt1 = yt1; + return OK; +} + +static int tonea(CSOUND *csound, TONE *p) +{ + MYFLT *ar, *asig; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + double c1 = p->c1, c2 = p->c2; + double yt1 = p->yt1; + double prvhp = p->prvhp; + + ar = p->ar; + asig = p->asig; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nkhp[n] != prvhp) { + double b; + prvhp = (double)p->khp[n]; + b = 2.0 - cos((double)(prvhp * csound->tpidsr)); + c2 = b - sqrt(b * b - 1.0); + c1 = 1.0 - c2; + } + yt1 = c1 * (double)(asig[n]) + c2 * yt1; + ar[n] = (MYFLT)yt1; + } + p->yt1 = yt1; + p->prvhp = prvhp; + p->c1 = c1; + p->c2 = c2; + return OK; +} + +static int tonexa(CSOUND *csound, TONEX *p) /* From Gabriel Maldonado, modified */ +{ + MYFLT *ar = p->ar; + double c2 = p->c2, *yt1 = p->yt1,c1 = p->c1; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j, lp = p->loop; + + memmove(ar,p->asig,sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (j=0; j< lp; j++) { + /* Should *yt1 be reset to something?? */ + for (n=0; nkhp[n] != p->prvhp) { + double b; + p->prvhp = (double)p->khp[n]; + b = 2.0 - cos(p->prvhp * (double)csound->tpidsr); + p->c2 = b - sqrt(b * b - 1.0); + p->c1 = 1.0 - p->c2; + } + x = c1 * ar[n] + c2 * yt1[j]; + yt1[j] = x; + ar[n] = (MYFLT)x; + } + } + return OK; +} + +static int atonexa(CSOUND *csound, TONEX *p) /* Gabriel Maldonado, modified */ +{ + MYFLT *ar = p->ar; + double c2 = p->c2, *yt1 = p->yt1; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j, lp = p->loop; + MYFLT prvhp = p->prvhp; + + memmove(ar,p->asig,sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (j=1; jkhp[n] != prvhp) { + double b; + prvhp = p->khp[n]; + b = 2.0 - cos((double)(p->prvhp * csound->tpidsr)); + c2 = b - sqrt(b * b - 1.0); + } + x = c2 * (yt1[j] + sig); + yt1[j] = x - sig; /* yt1 contains yt1-xt1 */ + ar[n] = (MYFLT)x; + } + } + p->c2 = c2; + p->prvhp = prvhp; + return OK; +} + + +typedef struct { + OPDS h; + MYFLT *sr, *ain, *afc, *istor; + MYFLT lkf; + double a[8]; +} BFIL; + +typedef struct { + OPDS h; + MYFLT *sr, *ain, *kfo, *kbw, *istor; + MYFLT lkf, lkb; + double a[8]; +} BBFIL; + +#define ROOT2 (1.4142135623730950488) + +extern int butset(CSOUND *csound, BFIL *p); + +static int bbutset(CSOUND *csound, BBFIL *p) /* Band set-up */ +{ + if (*p->istor==FL(0.0)) { + p->a[6] = p->a[7] = 0.0; + p->lkb = FL(0.0); + p->lkf = FL(0.0); + } + return OK; +} + +static int hibuta(CSOUND *csound, BFIL *p) /* Hipass filter */ +{ + MYFLT *out, *in; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + double *a; + double t, y; + uint32_t nn; + a = p->a; + + in = p->ain; + out = p->sr; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + + if (p->afc[0] <= FL(0.0)) { + memcpy(&out[offset], &in[offset], (nsmps-offset)*sizeof(MYFLT)); + return OK; + } + + /* if (p->afc[0] != p->lkf) { */ + /* p->lkf = p->afc[0]; */ + /* c = tan((double)(csound->pidsr * p->lkf)); */ + + /* a[1] = 1.0 / ( 1.0 + ROOT2 * c + c * c); */ + /* a[2] = -(a[1] + a[1]); */ + /* a[3] = a[1]; */ + /* a[4] = 2.0 * ( c*c - 1.0) * a[1]; */ + /* a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; */ + /* } */ + for (nn=offset; nnafc[nn] != p->lkf) { + double c; + p->lkf = p->afc[nn]; + c = tan((double)(csound->pidsr * p->lkf)); + + a[1] = 1.0 / ( 1.0 + ROOT2 * c + c * c); + a[2] = -(a[1] + a[1]); + a[3] = a[1]; + a[4] = 2.0 * ( c*c - 1.0) * a[1]; + a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; + } + t = (double)in[nn] - a[4] * a[6] - a[5] * a[7]; + t = csoundUndenormalizeDouble(t); /* Not needed on AMD */ + y = t * a[1] + a[2] * a[6] + a[3] * a[7]; + a[7] = a[6]; + a[6] = t; + out[nn] = (MYFLT)y; + } + return OK; +} + +static int lobuta(CSOUND *csound, BFIL *p) /* Lopass filter */ +{ + MYFLT *out, *in; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + double *a = p->a; + double t, y; + uint32_t nn; + + in = p->ain; + out = p->sr; + + if (*p->afc <= FL(0.0)) { + memset(out, 0, CS_KSMPS*sizeof(MYFLT)); + return OK; + } + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + + /* if (p->afc[0] != p->lkf) { */ + /* p->lkf = p->afc[0]; */ + /* c = 1.0 / tan((double)(csound->pidsr * p->lkf)); */ + /* a[1] = 1.0 / ( 1.0 + ROOT2 * c + c * c); */ + /* a[2] = a[1] + a[1]; */ + /* a[3] = a[1]; */ + /* a[4] = 2.0 * ( 1.0 - c*c) * a[1]; */ + /* a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; */ + /* } */ + + for (nn=offset; nnafc[nn] != p->lkf) { + double c; + p->lkf = p->afc[nn]; + c = 1.0 / tan((double)(csound->pidsr * p->lkf)); + a[1] = 1.0 / ( 1.0 + ROOT2 * c + c * c); + a[2] = a[1] + a[1]; + a[3] = a[1]; + a[4] = 2.0 * ( 1.0 - c*c) * a[1]; + a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; + } + t = (double)in[nn] - a[4] * a[6] - a[5] * a[7]; + t = csoundUndenormalizeDouble(t); /* Not needed on AMD */ + y = t * a[1] + a[2] * a[6] + a[3] * a[7]; + a[7] = a[6]; + a[6] = t; + out[nn] = (MYFLT)y; + } + return OK; +} + +static int bppasxx(CSOUND *csound, BBFIL *p) /* Bandpass filter */ +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + MYFLT *out, *in; + double *a = p->a; + double t, y; + uint32_t nn; + + in = p->ain; + out = p->sr; + if (p->kbw[0] <= FL(0.0)) { + memset(out, 0, CS_KSMPS*sizeof(MYFLT)); + return OK; + } + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + /* if (p->kbw[0] != p->lkb || p->kfo[0] != p->lkf) { */ + /* p->lkf = p->kfo[0]; */ + /* p->lkb = p->kbw[0]; */ + /* c = 1.0 / tan((double)(csound->pidsr * p->lkb)); */ + /* d = 2.0 * cos((double)(csound->tpidsr * p->lkf)); */ + /* a[1] = 1.0 / (1.0 + c); */ + /* a[2] = 0.0; */ + /* a[3] = -a[1]; */ + /* a[4] = - c * d * a[1]; */ + /* a[5] = (c - 1.0) * a[1]; */ + /* } */ + //butter_filter(nsmps, offset, in, out, p->a); + for (nn=offset; nnkbw[nn] : *p->kbw); + fr = (XINARG2 ? p->kfo[nn] : *p->kfo); + if (bw != p->lkb || fr != p->lkf) { + double c, d; + p->lkf = fr; + p->lkb = bw; + c = 1.0 / tan((double)(csound->pidsr * bw)); + d = 2.0 * cos((double)(csound->tpidsr * fr)); + a[1] = 1.0 / (1.0 + c); + a[2] = 0.0; + a[3] = -a[1]; + a[4] = - c * d * a[1]; + a[5] = (c - 1.0) * a[1]; + } + t = (double)in[nn] - a[4] * a[6] - a[5] * a[7]; + t = csoundUndenormalizeDouble(t); /* Not needed on AMD */ + y = t * a[1] + a[2] * a[6] + a[3] * a[7]; + a[7] = a[6]; + a[6] = t; + out[nn] = (MYFLT)y; + } + return OK; +} + +static int bpcutxx(CSOUND *csound, BBFIL *p) /* Band reject filter */ +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + MYFLT *out, *in; + double *a = p->a; + double t, y; + uint32_t nn; + + in = p->ain; + out = p->sr; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + if (p->kbw[0] <= FL(0.0)) { + memcpy(&out[offset], &out[offset], (nsmps-offset)*sizeof(MYFLT)); + return OK; + } + + for (nn=offset; nnkbw[nn] : *p->kbw); + fr = (XINARG2 ? p->kfo[nn] : *p->kfo); + if (bw != p->lkb || fr != p->lkf) { + double c, d; + p->lkf = fr; + p->lkb = bw; + c = tan((double)(csound->pidsr * bw)); + d = 2.0 * cos((double)(csound->tpidsr * fr)); + a[1] = 1.0 / (1.0 + c); + a[2] = - d * a[1]; + a[3] = a[1]; + a[4] = a[2]; + a[5] = (1.0 - c) * a[1]; + } + t = (double)in[nn] - a[4] * a[6] - a[5] * a[7]; + t = csoundUndenormalizeDouble(t); /* Not needed on AMD */ + y = t * a[1] + a[2] * a[6] + a[3] * a[7]; + a[7] = a[6]; + a[6] = t; + out[nn] = (MYFLT)y; + } + return OK; +} + + + +static OENTRY afilts_localops[] = +{ + { "areson.aa", sizeof(RESON), 0,5,"a","aaaoo",(SUBR)rsnset,NULL,(SUBR)aresonaa}, + { "areson.ak", sizeof(RESON), 0,5,"a","aakoo",(SUBR)rsnset,NULL,(SUBR)aresonak}, + { "areson.ka", sizeof(RESON), 0,5,"a","akaoo",(SUBR)rsnset,NULL,(SUBR)aresonka}, + { "atone.a", sizeof(TONE), 0,5,"a","ako", (SUBR)tonset,NULL,(SUBR)atonea }, + { "atonex.a", sizeof(TONEX), 0,5, "a","aaoo",(SUBR)tonsetx,NULL,(SUBR)atonexa}, + { "tone.a", sizeof(TONE), 0,5,"a","aao", (SUBR)tonset,NULL,(SUBR)tonea }, + { "tonex.a", sizeof(TONEX), 0,5,"a","aaoo", (SUBR)tonsetx,NULL,(SUBR)tonexa }, + { "butterhp.a", sizeof(BFIL), 0,5,"a","aao", (SUBR)butset,NULL,(SUBR)hibuta }, + { "butterlp.a", sizeof(BFIL), 0,5,"a","aao", (SUBR)butset,NULL,(SUBR)lobuta }, + { "buthp.a", sizeof(BFIL), 0,5,"a","aao", (SUBR)butset,NULL,(SUBR)hibuta }, + { "butlp.a", sizeof(BFIL), 0,5,"a","aao", (SUBR)butset,NULL,(SUBR)lobuta }, + { "butterbp", sizeof(BBFIL),0,5,"a","axxo", (SUBR)bbutset,NULL,(SUBR)bppasxx}, + { "butbp", sizeof(BBFIL),0,5,"a","axxo", (SUBR)bbutset,NULL,(SUBR)bppasxx}, + { "butterbr", sizeof(BBFIL),0,5,"a","axxo", (SUBR)bbutset,NULL,(SUBR)bpcutxx}, + { "butbr", sizeof(BBFIL),0,5,"a","axxo", (SUBR)bbutset,NULL,(SUBR)bpcutxx}, +}; + +LINKAGE_BUILTIN(afilts_localops) + + diff -Nru csound-5.17.11~dfsg/Opcodes/ambicode.c csound-6.02~dfsg/Opcodes/ambicode.c --- csound-5.17.11~dfsg/Opcodes/ambicode.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ambicode.c 2014-01-07 16:53:47.000000000 +0000 @@ -21,8 +21,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include "csdl.h" +#include "csoundCore.h" +#include "interlocks.h" #include typedef struct { @@ -131,7 +131,9 @@ static int aambicode(CSOUND *csound, AMBIC *p) { - int nn = csound->ksmps; /* array size from orchestra */ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* array size from orchestra */ /* init input array pointer */ MYFLT *inptp = p->asig; @@ -163,78 +165,122 @@ /* update coefficients */ ambicode_set_coefficients(p); + if (UNLIKELY(offset)) { + memset(rsltp_w, '\0', offset*sizeof(MYFLT)); + memset(rsltp_x, '\0', offset*sizeof(MYFLT)); + memset(rsltp_y, '\0', offset*sizeof(MYFLT)); + memset(rsltp_z, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rsltp_w[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_x[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_y[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_z[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->OUTOCOUNT == 4 && p->INOCOUNT >= 5) { /* 1st order */ - do { + for (n=offset; nw * *p->kin[0]; + rsltp_w[n] = *inptp * p->w * *p->kin[0]; /* 1st order */ - *rsltp_x++ = *inptp * p->x * *p->kin[1]; - *rsltp_y++ = *inptp * p->y * *p->kin[1]; - *rsltp_z++ = *inptp * p->z * *p->kin[1]; - - /* increment input pointer */ - inptp++; + rsltp_x[n] = inptp[n] * p->x * *p->kin[1]; + rsltp_y[n] = inptp[n] * p->y * *p->kin[1]; + rsltp_z[n] = inptp[n] * p->z * *p->kin[1]; } - while (--nn); } else if (p->OUTOCOUNT == 9 && p->INOCOUNT >= 6) { /* 2nd order */ - do { + if (UNLIKELY(offset)) { + memset(rsltp_r, '\0', offset*sizeof(MYFLT)); + memset(rsltp_s, '\0', offset*sizeof(MYFLT)); + memset(rsltp_t, '\0', offset*sizeof(MYFLT)); + memset(rsltp_u, '\0', offset*sizeof(MYFLT)); + memset(rsltp_v, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + memset(&rsltp_r[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_s[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_t[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_u[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_v[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nw * *p->kin[0]; + rsltp_w[n] = inptp[n] * p->w * *p->kin[0]; /* 1st order */ - *rsltp_x++ = *inptp * p->x * *p->kin[1]; - *rsltp_y++ = *inptp * p->y * *p->kin[1]; - *rsltp_z++ = *inptp * p->z * *p->kin[1]; + rsltp_x[n] = inptp[n] * p->x * *p->kin[1]; + rsltp_y[n] = inptp[n] * p->y * *p->kin[1]; + rsltp_z[n] = inptp[n] * p->z * *p->kin[1]; /* 2nd order */ - *rsltp_r++ = *inptp * p->r * *p->kin[2]; - *rsltp_s++ = *inptp * p->s * *p->kin[2]; - *rsltp_t++ = *inptp * p->t * *p->kin[2]; - *rsltp_u++ = *inptp * p->u * *p->kin[2]; - *rsltp_v++ = *inptp * p->v * *p->kin[2]; + rsltp_r[n] = inptp[n] * p->r * *p->kin[2]; + rsltp_s[n] = inptp[n] * p->s * *p->kin[2]; + rsltp_t[n] = inptp[n] * p->t * *p->kin[2]; + rsltp_u[n] = inptp[n] * p->u * *p->kin[2]; + rsltp_v[n] = inptp[n] * p->v * *p->kin[2]; - /* increment input pointer */ - inptp++; } - while (--nn); } else if (p->OUTOCOUNT == 16 && p->INOCOUNT >= 7) { /* 3rd order */ - do { + if (UNLIKELY(offset)) { + memset(rsltp_r, '\0', offset*sizeof(MYFLT)); + memset(rsltp_s, '\0', offset*sizeof(MYFLT)); + memset(rsltp_t, '\0', offset*sizeof(MYFLT)); + memset(rsltp_u, '\0', offset*sizeof(MYFLT)); + memset(rsltp_v, '\0', offset*sizeof(MYFLT)); + memset(rsltp_k, '\0', offset*sizeof(MYFLT)); + memset(rsltp_l, '\0', offset*sizeof(MYFLT)); + memset(rsltp_m, '\0', offset*sizeof(MYFLT)); + memset(rsltp_n, '\0', offset*sizeof(MYFLT)); + memset(rsltp_o, '\0', offset*sizeof(MYFLT)); + memset(rsltp_p, '\0', offset*sizeof(MYFLT)); + memset(rsltp_q, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + memset(&rsltp_r[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_s[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_t[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_u[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_v[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_k[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_l[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_m[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_n[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_o[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_p[nsmps], '\0', early*sizeof(MYFLT)); + memset(&rsltp_q[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nw * *p->kin[0]; + rsltp_w[n] = inptp[n] * p->w * *p->kin[0]; /* 1st order */ - *rsltp_x++ = *inptp * p->x * *p->kin[1]; - *rsltp_y++ = *inptp * p->y * *p->kin[1]; - *rsltp_z++ = *inptp * p->z * *p->kin[1]; + rsltp_x[n] = inptp[n] * p->x * *p->kin[1]; + rsltp_y[n] = inptp[n] * p->y * *p->kin[1]; + rsltp_z[n] = inptp[n] * p->z * *p->kin[1]; /* 2nd order */ - *rsltp_r++ = *inptp * p->r * *p->kin[2]; - *rsltp_s++ = *inptp * p->s * *p->kin[2]; - *rsltp_t++ = *inptp * p->t * *p->kin[2]; - *rsltp_u++ = *inptp * p->u * *p->kin[2]; - *rsltp_v++ = *inptp * p->v * *p->kin[2]; + rsltp_r[n] = inptp[n] * p->r * *p->kin[2]; + rsltp_s[n] = inptp[n] * p->s * *p->kin[2]; + rsltp_t[n] = inptp[n] * p->t * *p->kin[2]; + rsltp_u[n] = inptp[n] * p->u * *p->kin[2]; + rsltp_v[n] = inptp[n] * p->v * *p->kin[2]; /* 3rd order */ - *rsltp_k++ = *inptp * p->k * *p->kin[3]; - *rsltp_l++ = *inptp * p->l * *p->kin[3]; - *rsltp_m++ = *inptp * p->m * *p->kin[3]; - *rsltp_n++ = *inptp * p->n * *p->kin[3]; - *rsltp_o++ = *inptp * p->o * *p->kin[3]; - *rsltp_p++ = *inptp * p->p * *p->kin[3]; - *rsltp_q++ = *inptp * p->q * *p->kin[3]; - - /* increment input pointer */ - inptp++; + rsltp_k[n] = inptp[n] * p->k * *p->kin[3]; + rsltp_l[n] = inptp[n] * p->l * *p->kin[3]; + rsltp_m[n] = inptp[n] * p->m * *p->kin[3]; + rsltp_n[n] = inptp[n] * p->n * *p->kin[3]; + rsltp_o[n] = inptp[n] * p->o * *p->kin[3]; + rsltp_p[n] = inptp[n] * p->p * *p->kin[3]; + rsltp_q[n] = inptp[n] * p->q * *p->kin[3]; } - while (--nn); } return OK; } @@ -287,7 +333,9 @@ Str("bformdec is deprecated; use bformdec1 instead\n")); if (setup<0) setup = -setup; /* check correct number of input arguments */ - if (UNLIKELY((p->INOCOUNT != 5) && (p->INOCOUNT != 10) && (p->INOCOUNT != 17))) { + if (UNLIKELY((p->INOCOUNT != 5) && + (p->INOCOUNT != 10) && + (p->INOCOUNT != 17))) { return csound->InitError(csound, Str("Wrong number of input arguments!")); } @@ -450,15 +498,20 @@ } else { int i; - static double w[] = {0.1768, 0.1768, 0.1768, 0.1768, 0.1768, 0.1768, 0.1768, 0.1768}; - static double x[] = {0.1591, 0.0659,-0.0659,-0.1591,-0.1591,-0.0659, 0.0659, 0.1591}; - static double y[] = {0.0659, 0.1591, 0.1591, 0.0659,-0.0659,-0.1591,-0.1591,-0.0659}; + static double w[] = {0.1768, 0.1768, 0.1768, 0.1768, + 0.1768, 0.1768, 0.1768, 0.1768}; + static double x[] = {0.1591, 0.0659, -0.0659,-0.1591, + -0.1591,-0.0659, 0.0659, 0.1591}; + static double y[] = {0.0659, 0.1591, 0.1591, 0.0659, + -0.0659,-0.1591,-0.1591,-0.0659}; /* static double z[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ /* static double r[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ /* static double s[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ /* static double t[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ - static double u[] = {0.0342,-0.0342,-0.0342, 0.0342, 0.0342,-0.0342,-0.0342, 0.0342}; - static double v[] = {0.0342, 0.0342,-0.0342,-0.0342, 0.0342, 0.0342,-0.0342,-0.0342}; + static double u[] = {0.0342,-0.0342,-0.0342, 0.0342, + 0.0342,-0.0342,-0.0342, 0.0342}; + static double v[] = {0.0342, 0.0342,-0.0342,-0.0342, + 0.0342, 0.0342,-0.0342,-0.0342}; for (i=0; i<8; i++) { p->w[i] = w[i]; p->x[i] = x[i]; @@ -500,15 +553,22 @@ } else { int i; - static double w[] = {0.1768,0.1768,0.1768,0.1768,0.1768,0.1768,0.1768,0.1768}; - static double x[] = {0.1140, 0.1140,-0.1140,-0.1140, 0.1140, 0.1140,-0.1140,-0.1140}; - static double y[] = {0.1140,-0.1140,-0.1140, 0.1140, 0.1140,-0.1140,-0.1140, 0.1140}; - static double z[] = {-0.1140,-0.1140,-0.1140,-0.1140, 0.1140, 0.1140, 0.1140, 0.1140}; + static double w[] = {0.1768,0.1768,0.1768,0.1768, + 0.1768,0.1768,0.1768,0.1768}; + static double x[] = {0.1140, 0.1140,-0.1140,-0.1140, + 0.1140, 0.1140,-0.1140,-0.1140}; + static double y[] = {0.1140,-0.1140,-0.1140, 0.1140, + 0.1140,-0.1140,-0.1140, 0.1140}; + static double z[] = {-0.1140,-0.1140,-0.1140,-0.1140, + 0.1140, 0.1140, 0.1140, 0.1140}; /* static double r[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ - static double s[] = {-0.0369,-0.0369, 0.0369, 0.0369, 0.0369, 0.0369,-0.0369,-0.0369}; - static double t[] = {-0.0369, 0.0369, 0.0369,-0.0369, 0.0369,-0.0369,-0.0369, 0.0369}; + static double s[] = {-0.0369,-0.0369, 0.0369, 0.0369, + 0.0369, 0.0369,-0.0369,-0.0369}; + static double t[] = {-0.0369, 0.0369, 0.0369,-0.0369, + 0.0369,-0.0369,-0.0369, 0.0369}; /* static double u[] = {0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}; */ - static double v[] = { 0.0369,-0.0369, 0.0369,-0.0369, 0.0369,-0.0369, 0.0369,-0.0369}; + static double v[] = { 0.0369,-0.0369, 0.0369,-0.0369, + 0.0369,-0.0369, 0.0369,-0.0369}; for (i=0; i<8; i++) { p->w[i] = w[i]; p->x[i] = x[i]; @@ -537,11 +597,11 @@ "There must be 5 output cells.")); } /* These are Wiggins' cpefficients */ -/* L 30° {0.4724, 0.7143, 0.7258, 0.0000, 0.3456} - R -30° {0.4724, 0.7143, -0.7258, 0.0000, -0.3456} - C 0° {0.3226, 0.7719, 0.0000, 0.0000, 0.4724} - LS 110° {0.9101, -0.7834, 0.9562, -0.0806, 0.0000} - RS -110° {0.9101, -0.7834, -0.9562, -0.0806, 0.0000} */ +/* L 30° {0.4724, 0.7143, 0.7258, 0.0000, 0.3456} + R -30° {0.4724, 0.7143, -0.7258, 0.0000, -0.3456} + C 0° {0.3226, 0.7719, 0.0000, 0.0000, 0.4724} + LS 110° {0.9101, -0.7834, 0.9562, -0.0806, 0.0000} + RS -110° {0.9101, -0.7834, -0.9562, -0.0806, 0.0000} */ { int i; static double w[] = {0.4724, 0.4724, 0.3226, 0.9101, 0.9101}; @@ -579,8 +639,9 @@ static int aambideco(CSOUND *csound, AMBID *p) { - int nn = csound->ksmps; /* array size from orchestra */ - int i = 0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i=0, n, nsmps = CS_KSMPS; /* init input array pointer 0th order */ MYFLT *inptp_w = p->aw; @@ -617,96 +678,54 @@ rsltp[5] = p->m5; rsltp[6] = p->m6; rsltp[7] = p->m7; + if (UNLIKELY(offset)) for (i = 0; i < p->OUTOCOUNT; i++) + memset(rsltp[i], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i = 0; i < p->OUTOCOUNT; i++) + memset(&rsltp[i][nsmps], '\0', early*sizeof(MYFLT)); + } /* L = 0.5 * (0.9397*W + 0.1856*X - j*0.342*W + j*0.5099*X + 0.655*Y) R = 0.5 * (0.9397*W+ 0.1856*X + j*0.342*W - j*0.5099*X - 0.655*Y) */ if (p->INOCOUNT == 5) { - do { + for (n=offset; nOUTOCOUNT; i++) { /* calculate output for every used loudspeaker */ - *rsltp[i]++ = *inptp_w * p->w[i] + *inptp_x * p->x[i] + - *inptp_y * p->y[i] + *inptp_z * p->z[i]; + rsltp[i][n] = inptp_w[n] * p->w[i] + inptp_x[n] * p->x[i] + + inptp_y[n] * p->y[i] + inptp_z[n] * p->z[i]; } - - /* increment input array pointer 0th order */ - inptp_w++; - - /* increment input array pointer 1st order */ - inptp_x++; - inptp_y++; - inptp_z++; - - } while (--nn); + } } else if (p->INOCOUNT == 10) { - do { + for (n=offset; nOUTOCOUNT; i++) { /* calculate output for every used loudspeaker */ - *rsltp[i]++ = *inptp_w * p->w[i] + *inptp_x * p->x[i] + - *inptp_y * p->y[i] + *inptp_z * p->z[i] + - *inptp_r * p->r[i] + *inptp_s * p->s[i] + - *inptp_t * p->t[i] + *inptp_u * p->u[i] + - *inptp_v * p->v[i]; - } - - /* increment input array pointer 0th order */ - inptp_w++; - - /* increment input array pointer 1st order */ - inptp_x++; - inptp_y++; - inptp_z++; - - /* increment input array pointer 2nd order */ - inptp_r++; - inptp_s++; - inptp_t++; - inptp_u++; - inptp_v++; - - } while (--nn); + rsltp[i][n] = inptp_w[n] * p->w[i] + inptp_x[n] * p->x[i] + + inptp_y[n] * p->y[i] + inptp_z[n] * p->z[i] + + inptp_r[n] * p->r[i] + inptp_s[n] * p->s[i] + + inptp_t[n] * p->t[i] + inptp_u[n] * p->u[i] + + inptp_v[n] * p->v[i]; + } + } } else if (p->INOCOUNT == 17) { - do { + for (n=offset; nOUTOCOUNT; i++) { /* calculate output for every used loudspeaker */ - *rsltp[i]++ = *inptp_w * p->w[i] + *inptp_x * p->x[i] + - *inptp_y * p->y[i] + *inptp_z * p->z[i] + - *inptp_r * p->r[i] + *inptp_s * p->s[i] + - *inptp_t * p->t[i] + *inptp_u * p->u[i] + - *inptp_v * p->v[i] + *inptp_k * p->k[i] + - *inptp_l * p->l[i] + *inptp_m * p->m[i] + - *inptp_n * p->n[i] + *inptp_o * p->o[i] + - *inptp_p * p->p[i] + *inptp_q * p->q[i]; - } - - /* increment input array pointer 0th order */ - inptp_w++; - - /* increment input array pointer 1st order */ - inptp_x++; - inptp_y++; - inptp_z++; - - /* increment input array pointer 2nd order */ - inptp_r++; - inptp_s++; - inptp_t++; - inptp_u++; - inptp_v++; - - /* increment input array pointer 3rd order */ - inptp_k++; - inptp_l++; - inptp_m++; - inptp_n++; - inptp_o++; - inptp_p++; - inptp_q++; - } while (--nn); + rsltp[i][n] = inptp_w[n] * p->w[i] + inptp_x[n] * p->x[i] + + inptp_y[n] * p->y[i] + inptp_z[n] * p->z[i] + + inptp_r[n] * p->r[i] + inptp_s[n] * p->s[i] + + inptp_t[n] * p->t[i] + inptp_u[n] * p->u[i] + + inptp_v[n] * p->v[i] + inptp_k[n] * p->k[i] + + inptp_l[n] * p->l[i] + inptp_m[n] * p->m[i] + + inptp_n[n] * p->n[i] + inptp_o[n] * p->o[i] + + inptp_p[n] * p->p[i] + inptp_q[n] * p->q[i]; + } + } } return OK; } @@ -714,9 +733,9 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "bformenc", S(AMBIC), _QQ|5, "mmmmmmmmmmmmmmmm", "akkPPPP", + { "bformenc", S(AMBIC), _QQ, 5, "mmmmmmmmmmmmmmmm", "akkPPPP", (SUBR)iambicode, NULL, (SUBR)aambicode }, - { "bformdec", S(AMBID), _QQ|5, "mmmmmmmm", "iaaay", + { "bformdec", S(AMBID), _QQ, 5, "mmmmmmmm", "iaaay", (SUBR)iambideco, NULL, (SUBR)aambideco } }; @@ -725,4 +744,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/ambicode1.c csound-6.02~dfsg/Opcodes/ambicode1.c --- csound-5.17.11~dfsg/Opcodes/ambicode1.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ambicode1.c 2014-01-07 16:53:47.000000000 +0000 @@ -28,7 +28,6 @@ 02111-1307 USA */ -// #include "csdl.h" #include "csoundCore.h" #include "interlocks.h" #include @@ -49,6 +48,19 @@ } AMBIC; +typedef struct { + + /* Required header: */ + OPDS h; + + /* Output channels (4, 9 or 16 in use): */ + ARRAYDAT *tabout; + + /* Input arguments: */ + MYFLT *ain, *kangle, *kelevation; + +} AMBICA; + /* ------------------------------------------------------------------------- */ typedef struct { @@ -65,6 +77,21 @@ } AMBID; +typedef struct { + + /* Required header: */ + OPDS h; + + /* Output channels (up to eight supported here, depending on the + isetup parameter). */ + ARRAYDAT *tabout; + + /* Input arguments: */ + MYFLT *isetup; + ARRAYDAT *tabin; + uint32_t dim; +} AMBIDA; + /* ------------------------------------------------------------------------- */ #define ROOT27 (5.1961524227066318806) #define ROOT135d16 (0.72618437741389066597) /* sqrt(135.0/256.0) */ @@ -83,16 +110,36 @@ } } +static int ibformenc_a(CSOUND * csound, AMBICA * p) +{ + if (p->tabout->data==NULL || p->tabout->dimensions!=1) + return csound->InitError(csound, + Str("array not initialised in ambibformenc1")); + + /* All we do in here is police our parameters. */ + switch (p->tabout->sizes[0]) { + case 4: + case 9: + case 16: + return OK; + default: + return csound->InitError + (csound, Str("The numbers of input and output arguments are not valid.")); + } +} + static int abformenc(CSOUND * csound, AMBIC * p) { - int sampleCount, sampleIndex, channelCount, channelIndex; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t sampleCount, sampleIndex, channelCount, channelIndex; double angle, elevation, x, y, z; MYFLT coefficients[16], coefficient, * output, * input; MYFLT x2, y2, z2; /* Find basic mode & angles: */ - sampleCount = csound->ksmps; + sampleCount = CS_KSMPS; channelCount = p->OUTOCOUNT; angle = (double)(*(p->kangle)) * (PI / 180.0); elevation = (double)(*(p->kelevation)) * (PI / 180.0); @@ -143,11 +190,91 @@ unoptimised code is doing the right thing!) */ /* Process channels: */ + if (UNLIKELY(early)) sampleCount -= early; for (channelIndex = 0; channelIndex < channelCount; channelIndex++) { coefficient = coefficients[channelIndex]; input = p->ain; output = p->aouts[channelIndex]; - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) + if (UNLIKELY(offset)) memset(output, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&output[sampleCount], '\0', early*sizeof(MYFLT)); + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) + output[sampleIndex] = coefficient * input[sampleIndex]; + } + + return OK; + +} + +static int +abformenc_a(CSOUND * csound, AMBICA * p) { + + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t sampleCount, sampleIndex, channelCount, channelIndex, ksmps; + double angle, elevation, x, y, z; + MYFLT coefficients[16], coefficient, * output, * input; + MYFLT x2, y2, z2; + + /* Find basic mode & angles: */ + ksmps = sampleCount = CS_KSMPS; + channelCount = p->tabout->sizes[0]; + angle = (double)(*(p->kangle)) * (PI / 180.0); + elevation = (double)(*(p->kelevation)) * (PI / 180.0); + + /* Find direction cosines: */ + x = cos(elevation); + y = x; + z = sin(elevation); + x *= cos(angle); + y *= sin(angle); + x2 = x * x; + y2 = y * y; + z2 = z * z; + + /* Find directional coefficients: */ + switch (channelCount) { + case 16: + /* Third order. */ + coefficients[ 9] = (MYFLT)((2.5 * z2 - 1.5) * z); + coefficients[10] = (MYFLT)(ROOT135d16 * x * (5.0 * z2 - 1)); + coefficients[11] = (MYFLT)(ROOT135d16 * y * (5.0 * z2 - 1)); + coefficients[12] = (MYFLT)(0.5*ROOT27 * z * (x2 - y2)); + coefficients[13] = (MYFLT)(ROOT27 * x * y * z); + coefficients[14] = (MYFLT)(x * (x2 - 3.0 * y2)); + coefficients[15] = (MYFLT)(y * (3.0 * x2 - y2)); + /* Deliberately no break;. */ + case 9: + /* Second order. */ + coefficients[ 4] = (MYFLT)(1.5 * z2 - 0.5); + coefficients[ 5] = (MYFLT)(2.0 * z * x); + coefficients[ 6] = (MYFLT)(2.0 * y * z); + coefficients[ 7] = (MYFLT)(x2 - y2); + coefficients[ 8] = (MYFLT)(2.0 * x * y); + /* Deliberately no break;. */ + case 4: + /* Zero and first order. */ + coefficients[ 0] = SQRT(FL(0.5)); + coefficients[ 1] = (MYFLT)x; + coefficients[ 2] = (MYFLT)y; + coefficients[ 3] = (MYFLT)z; + break; + default: + /* Should never be reached as this is policed at init time. */ + assert(0); + } + /* (There are some repeated multiplies in the code above, but I + suggest these aren't removed until everyone is sure the + unoptimised code is doing the right thing!) */ + + /* Process channels: */ + if (UNLIKELY(early)) sampleCount -= early; + for (channelIndex = 0; channelIndex < channelCount; channelIndex++) { + coefficient = coefficients[channelIndex]; + input = p->ain; + output = &p->tabout->data[ksmps*channelIndex]; + if (UNLIKELY(offset)) memset(output, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&output[sampleCount], '\0', early*sizeof(MYFLT)); + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) output[sampleIndex] = coefficient * input[sampleIndex]; } @@ -212,10 +339,11 @@ suggest these aren't removed until everyone is sure the unoptimised code is doing the right thing!) */ - int sampleCount, sampleIndex; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t sampleCount = CS_KSMPS, sampleIndex; MYFLT p0, q, u, v, w, x, y, z; - sampleCount = csound->ksmps; assert(p->INOCOUNT >= 5); switch ((int)*(p->isetup)) { @@ -225,7 +353,16 @@ array at the origin. Works better than front-facing arrangements for most purposes, as a composer using this opcode probably wants to hear the back stage. */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + if (UNLIKELY(offset)) { + memset(p->aouts[0], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[1], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&p->aouts[0][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[1][sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex] * SQRT(FL(0.5)); y = p->ains[2][sampleIndex] * FL(0.5); /* Left: */ @@ -236,8 +373,21 @@ break; case 2: /* Quad */ assert(p->OUTOCOUNT == 4); + if (UNLIKELY(offset)) { + memset(p->aouts[0], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[1], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[2], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[3], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&p->aouts[0][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[1][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[2][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[3][sampleCount], '\0', early*sizeof(MYFLT)); + } /* Use a first-order 'in-phase' decode. */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex] * FL(0.35355); x = p->ains[1][sampleIndex] * FL(0.17677); y = p->ains[2][sampleIndex] * FL(0.17677); @@ -253,13 +403,26 @@ break; case 3: /* 5.0 */ assert(p->OUTOCOUNT == 5); - /* This is a second order decoder provided by Bruce Wiggins. It is + if (UNLIKELY(offset)) { + memset(p->aouts[0], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[1], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[2], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[3], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&p->aouts[0][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[1][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[2][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[3][sampleCount], '\0', early*sizeof(MYFLT)); + } + /* This is a second order decoder provided by Bruce Wiggins. It is optimised for high frequency use within a dual-band decoder, - however it has good a low-frequency response. It isn't quite + however it has good a low-frequency response. It is not quite 'in-phase' but it is not far off. */ if (p->INOCOUNT == 1 + 4) { /* Matrix truncated to first order (not ideal). */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex]; x = p->ains[1][sampleIndex]; y = p->ains[2][sampleIndex]; @@ -282,7 +445,20 @@ } else { /* This is the full matrix. */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + if (UNLIKELY(offset)) { + memset(p->aouts[0], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[1], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[2], '\0', offset*sizeof(MYFLT)); + memset(p->aouts[3], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&p->aouts[0][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[1][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[2][sampleCount], '\0', early*sizeof(MYFLT)); + memset(&p->aouts[3][sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex]; x = p->ains[1][sampleIndex]; y = p->ains[2][sampleIndex]; @@ -315,7 +491,15 @@ assert(p->OUTOCOUNT == 8); if (p->INOCOUNT == 1 + 4) { /* First order 'in-phase' decode: */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(p->aouts[sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&p->aouts[sampleIndex][sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex] * FL(0.17677); x = p->ains[1][sampleIndex]; y = p->ains[2][sampleIndex]; @@ -339,7 +523,15 @@ } else if (p->INOCOUNT == 1 + 9) { /* Second order 'in-phase' / 'controlled opposites' decode: */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(p->aouts[sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&p->aouts[sampleIndex][sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex] * FL(0.17677); x = p->ains[1][sampleIndex]; y = p->ains[2][sampleIndex]; @@ -373,8 +565,16 @@ } else { assert(p->INOCOUNT == 1 + 16); + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(p->aouts[sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&p->aouts[sampleIndex][sampleCount], '\0', early*sizeof(MYFLT)); + } /* Third order 'in-phase' / 'controlled opposites' decode: */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[ 0][sampleIndex] * FL(0.176777); x = p->ains[ 1][sampleIndex]; y = p->ains[ 2][sampleIndex]; @@ -436,7 +636,15 @@ case 5: /* Cube: */ assert(p->OUTOCOUNT == 8); /* First order 'in-phase' decode: */ - for (sampleIndex = 0; sampleIndex < sampleCount; sampleIndex++) { + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(p->aouts[sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&p->aouts[sampleIndex][sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { w = p->ains[0][sampleIndex] * FL(0.17677); x = p->ains[1][sampleIndex] * FL(0.07216); y = p->ains[2][sampleIndex] * FL(0.07216); @@ -467,15 +675,414 @@ } +static int +ibformdec_a(CSOUND * csound, AMBIDA * p) { + int dim; + if (p->tabout->data==NULL || p->tabout->dimensions!=1) + return csound->InitError(csound, + Str("bformdec1 output array not initilised")); + dim = p->tabin->sizes[0]; + /* All we do in here is police our parameters. */ + if (UNLIKELY(dim != 4 && + dim != 9 && + dim != 16)) { + return csound->InitError(csound, + Str("The number of input arguments is not valid.")); + } + else if (UNLIKELY(*(p->isetup) < 1 || *(p->isetup) > 5)) { + return csound->InitError(csound, + Str("The isetup value should be between 1 and 5.")); + } + else { + p->dim = dim = p->tabout->sizes[0]; + /* Then we check the output arguments. */ + if (*(p->isetup) == 1 && dim == 2) { + /* Stereo. */ + return OK; + } + else if (*(p->isetup) == 2 && dim == 4) { + /* Quad. */ + return OK; + } + else if (*(p->isetup) == 3 && dim == 5) { + /* Surround 5.0. */ + return OK; + } + else if (*(p->isetup) == 4 && dim == 8) { + /* Octagon. */ + return OK; + } + else if (*(p->isetup) == 5 && dim == 8) { + /* Cube. */ + return OK; + } + else { + return csound->InitError(csound, + Str("The output channel count does not" + " match the isetup value.")); + } + } + return OK; /* Never used */ +} + +static int +abformdec_a(CSOUND * csound, AMBIDA * p) { + + /* All assert() calls in here should already have been validated in + ibformdec(). I've also abused the notation a fair bit, often + holding scaled values in w, x, y etc. */ + + /* (There are some repeated multiplies in the code below, but I + suggest these aren't removed until everyone is sure the + unoptimised code is doing the right thing!) */ + + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t sampleCount = CS_KSMPS, sampleIndex; + uint32_t ksmps = sampleCount; + MYFLT p0, q, u, v, w, x, y, z; + uint32_t dim = p->dim; + MYFLT *tabin = p->tabin->data, *tabout = p->tabout->data; + + switch ((int)*(p->isetup)) { + case 1: /* Stereo */ + /* Use a 90degree stereo decode, equivalent to a M+S microphone + array at the origin. Works better than front-facing + arrangements for most purposes, as a composer using this opcode + probably wants to hear the back stage. */ + if (UNLIKELY(offset)) { + memset(&tabout[0], '\0', offset*sizeof(MYFLT)); + memset(&tabout[ksmps], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&tabout[sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex] * SQRT(FL(0.5)); + y = tabin[2*ksmps+sampleIndex] * FL(0.5); + /* Left: */ + tabout[sampleIndex] = w + y; + /* Right: */ + tabout[ksmps+sampleIndex] = w - y; + } + break; + case 2: /* Quad */ + if (UNLIKELY(offset)) { + memset(&tabout[0], '\0', offset*sizeof(MYFLT)); + memset(&tabout[ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[2*ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[3*ksmps], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&tabout[sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[2*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[3*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + } + /* Use a first-order 'in-phase' decode. */ + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex] * FL(0.35355); + x = tabin[ksmps+sampleIndex] * FL(0.17677); + y = tabin[2*ksmps+sampleIndex] * FL(0.17677); + /* Front left: */ + tabout[sampleIndex] = w + x + y; + /* Back left: */ + tabout[ksmps+sampleIndex] = w - x + y; + /* Back right: */ + tabout[2*ksmps+sampleIndex] = w - x - y; + /* Front right: */ + tabout[3*ksmps+sampleIndex] = w + x - y; + } + break; + case 3: /* 5.0 */ + if (UNLIKELY(offset)) { + memset(&tabout[0], '\0', offset*sizeof(MYFLT)); + memset(&tabout[ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[2*ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[3*ksmps], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&tabout[sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[2*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[3*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + } + /* This is a second order decoder provided by Bruce Wiggins. It is + optimised for high frequency use within a dual-band decoder, + however it has good a low-frequency response. It is not quite + 'in-phase' but it is not far off. */ + if (dim == 4) { + /* Matrix truncated to first order (not ideal). */ + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex]; + x = tabin[ksmps+sampleIndex]; + y = tabin[2*ksmps+sampleIndex]; + /* Left: */ + tabout[sampleIndex] + = w * FL(0.405) + x * FL(0.32) + y * FL(0.31); + /* Right: */ + tabout[ksmps+sampleIndex] + = w * FL(0.405) + x * FL(0.32) - y * FL(0.31); + /* Centre: */ + tabout[2*ksmps+sampleIndex] + = w * FL(0.085) + x * FL(0.04); + /* Surround Left: */ + tabout[3*ksmps+sampleIndex] + = w * FL(0.635) - x * FL(0.335) + y * FL(0.28); + /* Surround Right: */ + tabout[4*ksmps+sampleIndex] + = w * FL(0.635) - x * FL(0.335) - y * FL(0.28); + } + } + else { + /* This is the full matrix. */ + if (UNLIKELY(offset)) { + memset(&tabout[0], '\0', offset*sizeof(MYFLT)); + memset(&tabout[ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[2*ksmps], '\0', offset*sizeof(MYFLT)); + memset(&tabout[3*ksmps], '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + sampleCount -= early; + memset(&tabout[0+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[2*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + memset(&tabout[3*ksmps+sampleCount], '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex]; + x = tabin[ksmps+sampleIndex]; + y = tabin[2*ksmps+sampleIndex]; + u = tabin[7*ksmps+sampleIndex]; + v = tabin[8*ksmps+sampleIndex]; + /* Left: */ + tabout[sampleIndex] + = (w * FL(0.405) + x * FL(0.32) + y * FL(0.31) + + u * FL(0.085) + v * FL(0.125)); + /* Right: */ + tabout[ksmps+sampleIndex] + = (w * FL(0.405) + x * FL(0.32) - y * FL(0.31) + + u * FL(0.085) - v * FL(0.125)); + /* Centre: */ + tabout[2*ksmps+sampleIndex] + = (w * FL(0.085) + x * FL(0.04) + + u * FL(0.045)); + /* Surround Left: */ + tabout[3*ksmps+sampleIndex] + = (w * FL(0.635) - x * FL(0.335) + y * FL(0.28) + - u * FL(0.08) + v * FL(0.08)); + /* Surround Right: */ + tabout[4*ksmps+sampleIndex] + = (w * FL(0.635) - x * FL(0.335) - y * FL(0.28) + - u * FL(0.08) - v * FL(0.08)); + } + } + break; + case 4: /* Octagon: */ + if (dim == 4) { + /* First order 'in-phase' decode: */ + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex+sampleCount], '\0', + early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex] * FL(0.17677); + x = tabin[ksmps+sampleIndex]; + y = tabin[2*ksmps+sampleIndex]; + /* About 11 o'clock: */ + tabout[sampleIndex] = w + x * FL(0.11548) + y * FL(0.04783); + /* About 10 o'clock: */ + tabout[ksmps+sampleIndex] = w + x * FL(0.04783) + y * FL(0.11546); + /* About 8 o'clock: */ + tabout[2*ksmps+sampleIndex] = w - x * FL(0.04783) + y * FL(0.11546); + /* About 7 o'clock: */ + tabout[3*ksmps+sampleIndex] = w - x * FL(0.11548) + y * FL(0.04783); + /* About 5 o'clock: */ + tabout[4*ksmps+sampleIndex] = w - x * FL(0.11548) - y * FL(0.04783); + /* About 4 o'clock: */ + tabout[5*ksmps+sampleIndex] = w - x * FL(0.04783) - y * FL(0.11546); + /* About 2 o'clock: */ + tabout[6*ksmps+sampleIndex] = w + x * FL(0.04783) - y * FL(0.11546); + /* About 1 o'clock: */ + tabout[7*ksmps+sampleIndex] = w + x * FL(0.11548) - y * FL(0.04783); + } + } + else if (dim == 9) { + /* Second order 'in-phase' / 'controlled opposites' decode: */ + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex+sampleCount], '\0', + early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex] * FL(0.17677); + x = tabin[ksmps+sampleIndex]; + y = tabin[2*ksmps+sampleIndex]; + u = tabin[7*ksmps+sampleIndex] * FL(0.03417); + v = tabin[8*ksmps+sampleIndex] * FL(0.03417); + /* About 11 o'clock: */ + tabout[sampleIndex] + = w + x * FL(0.15906) + y * FL(0.06588) + u + v; + /* About 10 o'clock: */ + tabout[ksmps+sampleIndex] + = w + x * FL(0.06588) + y * FL(0.15906) - u + v; + /* About 8 o'clock: */ + tabout[2*ksmps+sampleIndex] + = w - x * FL(0.06588) + y * FL(0.15906) - u - v; + /* About 7 o'clock: */ + tabout[3*ksmps+sampleIndex] + = w - x * FL(0.15906) + y * FL(0.06588) + u - v; + /* About 5 o'clock: */ + tabout[4*ksmps+sampleIndex] + = w - x * FL(0.15906) - y * FL(0.06588) + u + v; + /* About 4 o'clock: */ + tabout[5*ksmps+sampleIndex] + = w - x * FL(0.06588) - y * FL(0.15906) - u + v; + /* About 2 o'clock: */ + tabout[6*ksmps+sampleIndex] + = w + x * FL(0.06588) - y * FL(0.15906) - u - v; + /* About 1 o'clock: */ + tabout[7*ksmps+sampleIndex] + = w + x * FL(0.15906) - y * FL(0.06588) + u - v; + } + } + else { + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex+sampleCount], '\0', + early*sizeof(MYFLT)); + } + /* Third order 'in-phase' / 'controlled opposites' decode: */ + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[ksmps* 0+sampleIndex] * FL(0.176777); + x = tabin[ksmps* 1+sampleIndex]; + y = tabin[ksmps* 2+sampleIndex]; + u = tabin[ksmps* 7+sampleIndex] * FL(0.053033); + v = tabin[ksmps* 8+sampleIndex] * FL(0.053033); + p0 = tabin[ksmps*14+sampleIndex]; + q = tabin[ksmps*15+sampleIndex]; + /* About 11 o'clock: */ + tabout[0+sampleIndex] + = (w + + x * FL(0.173227) + y * FL(0.071753) + + u + v + + p0 * FL(0.004784) + q * FL(0.011548)); + /* About 10 o'clock: */ + tabout[ksmps+sampleIndex] + = (w + + x * FL(0.071753) + y * FL(0.173227) + - u + v + - p0 * FL(0.011548) - q * FL(0.004784)); + /* About 8 o'clock: */ + tabout[2*ksmps+sampleIndex] + = (w + - x * FL(0.071753) + y * FL(0.173227) + - u - v + + p0 * FL(0.004784) - q * FL(0.011548)); + /* About 7 o'clock: */ + tabout[3*ksmps+sampleIndex] + = (w + - x * FL(0.173227) + y * FL(0.071753) + + u - v + - p0 * FL(0.011548) + q * FL(0.004784)); + /* About 5 o'clock: */ + tabout[ksmps*4+sampleIndex] + = (w + - x * FL(0.173227) - y * FL(0.071753) + + u + v + - p0 * FL(0.004784) - q * FL(0.011548)); + /* About 4 o'clock: */ + tabout[ksmps*5+sampleIndex] + = (w + - x * FL(0.071753) - y * FL(0.173227) + - u + v + + p0 * FL(0.011548) + q * FL(0.004784)); + /* About 2 o'clock: */ + tabout[ksmps*6+sampleIndex] + = (w + + x * FL(0.071753) - y * FL(0.173227) + - u - v + - p0 * FL(0.004784) + q * FL(0.011548)); + /* About 1 o'clock: */ + tabout[ksmps*7+sampleIndex] + = (w + + x * FL(0.173227) - y * FL(0.071753) + + u - v + + p0 * FL(0.011548) - q * FL(0.004784)); + } + } + break; + case 5: /* Cube: */ + /* First order 'in-phase' decode: */ + if (UNLIKELY(offset)) + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + sampleCount -= early; + for (sampleIndex = 0; sampleIndex<8; sampleIndex++) + memset(&tabout[ksmps*sampleIndex+sampleCount], + '\0', early*sizeof(MYFLT)); + } + for (sampleIndex = offset; sampleIndex < sampleCount; sampleIndex++) { + w = tabin[sampleIndex] * FL(0.17677); + x = tabin[ksmps+sampleIndex] * FL(0.07216); + y = tabin[2*ksmps+sampleIndex] * FL(0.07216); + z = tabin[3*ksmps+sampleIndex] * FL(0.07216); + /* Front left bottom: */ + p->tabout->data[sampleIndex] = w + x + y - z; + /* Front left top: */ + p->tabout->data[ksmps+sampleIndex] = w + x + y + z; + /* Back left bottom: */ + p->tabout->data[2*ksmps+sampleIndex] = w - x + y - z; + /* Back left top: */ + p->tabout->data[3*ksmps+sampleIndex] = w - x + y + z; + /* Back right bottom: */ + p->tabout->data[ksmps*4+sampleIndex] = w - x - y - z; + /* Back right top: */ + p->tabout->data[ksmps*5+sampleIndex] = w - x - y + z; + /* Front right bottom: */ + p->tabout->data[ksmps*6+sampleIndex] = w + x - y - z; + /* Front right top: */ + p->tabout->data[ksmps*7+sampleIndex] = w + x - y + z; + } + break; + default: + assert(0); + } + + return OK; +} + /* ------------------------------------------------------------------------- */ #define S(x) sizeof(x) static OENTRY ambicode1_localops[] = { - { "bformenc1", S(AMBIC), 5, "mmmmmmmmmmmmmmmm", "akk", + { "bformenc1.a", S(AMBIC), 0, 5, "mmmmmmmmmmmmmmmm", "akk", (SUBR)ibformenc, NULL, (SUBR)abformenc }, - { "bformdec1", S(AMBID), 5, "mmmmmmmm", "iy", + { "bformenc1.A", S(AMBIC), 0, 5, "a[]", "akk", + (SUBR)ibformenc_a, NULL, (SUBR)abformenc_a }, + { "bformdec1.a", S(AMBID), 0, 5, "mmmmmmmm", "iy", (SUBR)ibformdec, NULL, (SUBR)abformdec }, + { "bformdec1.A", S(AMBIDA), 0, 5, "a[]", "ia[]", + (SUBR)ibformdec_a, NULL, (SUBR)abformdec_a }, }; -LINKAGE1(ambicode1_localops) +LINKAGE_BUILTIN(ambicode1_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/ampmidid.cpp csound-6.02~dfsg/Opcodes/ampmidid.cpp --- csound-5.17.11~dfsg/Opcodes/ampmidid.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ampmidid.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -116,6 +116,7 @@ int status = csound->AppendOpcode(csound, (char*)"ampmidid.k", sizeof(KAMPMIDID), + 0, 3, (char*)"k", (char*)"ki", @@ -125,6 +126,7 @@ status |= csound->AppendOpcode(csound, (char*)"ampmidid.i", sizeof(IAMPMIDID), + 0, 1, (char*)"i", (char*)"ii", @@ -139,6 +141,7 @@ 0, 0, 0, + 0, 0); return status; } diff -Nru csound-5.17.11~dfsg/Opcodes/arrays.c csound-6.02~dfsg/Opcodes/arrays.c --- csound-5.17.11~dfsg/Opcodes/arrays.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/arrays.c 2014-01-07 16:53:47.000000000 +0000 @@ -0,0 +1,1248 @@ +/* + arrays.c: + + Copyright (C) 2011,2012 John ffitch, Steven Yi + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +// #include "csdl.h" +#include "csoundCore.h" +#include "interlocks.h" +#include "aops.h" +#include "csound_orc_semantics.h" + +extern MYFLT MOD(MYFLT a, MYFLT bb); + +typedef struct { + OPDS h; + ARRAYDAT *arrayDat; +} ARRAYDEL; + +typedef struct { + OPDS h; + ARRAYDAT* arrayDat; + MYFLT *isizes[VARGMAX]; +} ARRAYINIT; + +typedef struct { + OPDS h; + ARRAYDAT* ans; + MYFLT *iargs[VARGMAX]; +} TABFILL; + +typedef struct { + OPDS h; + ARRAYDAT* arrayDat; + void* value; + MYFLT *indexes[VARGMAX]; +} ARRAY_SET; + +typedef struct { + OPDS h; + MYFLT* out; + ARRAYDAT* arrayDat; + MYFLT *indexes[VARGMAX]; +} ARRAY_GET; + +#ifdef SOME_FINE_DAY +static int array_del(CSOUND *csound, void *p) +{ + ARRAYDAT *t = ((ARRAYDEL*)p)->arrayDat; + t->arrayType = NULL; // types cleaned up later + mfree(csound, t->data); + mfree(csound, p); /* Unlikely to free the p */ + return OK; +} +#endif + +static inline void tabensure(CSOUND *csound, ARRAYDAT *p, int size) +{ + if (p->data==NULL || p->dimensions == 0 || + (p->dimensions==1 && p->sizes[0] < size)) { + uint32_t ss = sizeof(MYFLT)*size; + if (p->data==NULL) p->data = (MYFLT*)mmalloc(csound, ss); + else p->data = (MYFLT*) mrealloc(csound, p->data, ss); + p->dimensions = 1; + p->arrayMemberSize = sizeof(MYFLT); + p->sizes = (int*)mmalloc(csound, sizeof(int)); + p->sizes[0] = size; + } +} + +static int array_init(CSOUND *csound, ARRAYINIT *p) +{ + ARRAYDAT* arrayDat = p->arrayDat; + int i, size; + + int inArgCount = p->INOCOUNT; + + if (UNLIKELY(inArgCount == 0)) + return csound->InitError(csound, + Str("Error: no sizes set for array initialization")); + + arrayDat->dimensions = inArgCount; + arrayDat->sizes = mcalloc(csound, sizeof(int) * inArgCount); + for (i = 0; i < inArgCount; i++) { + arrayDat->sizes[i] = MYFLT2LRND(*p->isizes[i]); + } + + size = arrayDat->sizes[0]; + + if (inArgCount > 1) { + for (i = 1; i < inArgCount; i++) { + size *= arrayDat->sizes[i]; + } + size = MYFLT2LRND(size); + } + + CS_VARIABLE* var = arrayDat->arrayType->createVariable(csound, NULL); + +// if(arrayDat->data != NULL) { +// mfree(csound, arrayDat->data); +// } + arrayDat->arrayMemberSize = var->memBlockSize; + int memSize = var->memBlockSize*size; + arrayDat->data = mcalloc(csound, memSize); +// for (i=0; idata[i] = val; +// { // Need to recover space eventually +// TABDEL *op = (TABDEL*) mmalloc(csound, sizeof(TABDEL)); +// op->h.insdshead = ((OPDS*) p)->insdshead; +// op->tab = t; +// csound->RegisterDeinitCallback(csound, op, tabdel); +// } + return OK; +} + +static int tabfill(CSOUND *csound, TABFILL *p) +{ + int nargs = p->INOCOUNT; + int i; + MYFLT **valp = p->iargs; + tabensure(csound, p->ans, nargs); + for (i=0; ians->data[i] = *valp[i]; + return OK; +} + +static int array_set(CSOUND* csound, ARRAY_SET *p) { + ARRAYDAT* dat = p->arrayDat; + MYFLT* mem = dat->data; + int i; + int end, index, incr; + + int indefArgCount = p->INOCOUNT - 2; + + if (UNLIKELY(indefArgCount == 0)) { + csoundErrorMsg(csound, Str("Error: no indexes set for array set\n")); + return CSOUND_ERROR; + } + if (UNLIKELY(indefArgCount>dat->dimensions)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array dimension %d out of range " + "for dimensions %d\n"), + indefArgCount, dat->dimensions); + end = indefArgCount - 1; + index = MYFLT2LRND(*p->indexes[end]); + if (UNLIKELY(index >= dat->sizes[end] || index<0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array index %d out of range (0,%d) " + "for dimension %d\n"), + index, dat->sizes[end]-1, indefArgCount); + + if (indefArgCount > 1) { + for (i = end - 1; i >= 0; i--) { + int ind = MYFLT2LRND(*p->indexes[i]); + if (UNLIKELY(ind >= dat->sizes[i] || ind<0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array index %d out of range (0,%d) " + "for dimension %d\n"), ind, + dat->sizes[i]-1, i+1); + index += ind * dat->sizes[i + 1]; + } + } + + incr = (index * (dat->arrayMemberSize / sizeof(MYFLT))); + mem += incr; + memcpy(mem, p->value, dat->arrayMemberSize); + /* printf("array_set: mem = %p, incr = %d, value = %f\n", */ + /* mem, incr, *((MYFLT*)p->value)); */ + return OK; +} + +static int array_get(CSOUND* csound, ARRAY_GET *p) { + ARRAYDAT* dat = p->arrayDat; + MYFLT* mem = dat->data; + int i; + int incr; + int end; + int index; + int indefArgCount = p->INOCOUNT - 1; + + if (UNLIKELY(indefArgCount == 0)) + csound->PerfError(csound, p->h.insdshead, + Str("Error: no indexes set for array get")); + if (UNLIKELY(indefArgCount>dat->dimensions)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array dimension %d out of range " + "for dimensions %d\n"), + indefArgCount, dat->dimensions); + end = indefArgCount - 1; + index = MYFLT2LRND(*p->indexes[end]); + if (UNLIKELY(index >= dat->sizes[end] || index<0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array index %d out of range (0,%d) " + "for dimension %d\n"), + index, dat->sizes[end]-1, end+1); + if (indefArgCount > 1) { + for (i = end - 1; i >= 0; i--) { + int ind = MYFLT2LRND(*p->indexes[i]); + if (UNLIKELY(ind >= dat->sizes[i] || ind<0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Array index %d out of range (0,%d) " + "for dimension %d\n"), ind, + dat->sizes[i]-1, i+1); + index += ind * dat->sizes[i + 1]; + } + } + + incr = (index * (dat->arrayMemberSize / sizeof(MYFLT))); + mem += incr; + memcpy(p->out, mem, dat->arrayMemberSize); + return OK; +} + +typedef struct { + OPDS h; + ARRAYDAT *ans, *left, *right; +} TABARITH; + +typedef struct { + OPDS h; + ARRAYDAT *ans, *left; + MYFLT *right; +} TABARITH1; + +typedef struct { + OPDS h; + ARRAYDAT *ans; + MYFLT *left; + ARRAYDAT *right; +} TABARITH2; + +typedef struct { + OPDS h; + MYFLT *ans, *pos; + ARRAYDAT *tab; +} TABQUERY; + +typedef struct { + OPDS h; + MYFLT *ans; + ARRAYDAT *tab; +} TABQUERY1; + +typedef struct { + OPDS h; + ARRAYDAT *tab; + MYFLT *kfn; +} TABCOPY; + +typedef struct { + OPDS h; + ARRAYDAT *tab; + MYFLT *kmin, *kmax; + MYFLT *kstart, *kend; +} TABSCALE; + +static int tabarithset(CSOUND *csound, TABARITH *p) +{ + if (LIKELY(p->left->data && p->right->data)) { + int size; + if (p->left->dimensions!=1 || p->right->dimensions!=1) + return + csound->InitError(csound, + Str("Dimensions do not match in array arithmetic")); + /* size is the smallest of the two */ + size = p->left->sizes[0] < p->right->sizes[0] ? + p->left->sizes[0] : p->right->sizes[0]; + tabensure(csound, p->ans, size); + p->ans->sizes[0] = size; + return OK; + } + else return csound->InitError(csound, Str("array-variable not initialised")); +} +static int tabiadd(CSOUND *csound, ARRAYDAT *ans, ARRAYDAT *l, MYFLT r, void *p); +// For cases with array as first arg +static int tabarithset1(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *left = p->left; + if(p->ans->data == left->data) { + printf("same ptr \n"); + return OK; + } + + if (LIKELY(left->data)) { + int size; + if (left->dimensions!=1) + return + csound->InitError(csound, + Str("Dimension does not match in array arithmetic")); + size = left->sizes[0]; + tabensure(csound, p->ans, size); + p->ans->sizes[0] = size; + return OK; + } + else return csound->InitError(csound, Str("array-variable not initialised")); +} + +// For cases with array as second arg +static int tabarithset2(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *right = p->right; + if (LIKELY(right->data)) { + int size; + if (right->dimensions!=1) + return + csound->InitError(csound, + Str("Dimension does not match in array arithmetic")); + size = right->sizes[0]; + tabensure(csound, p->ans, size); + p->ans->sizes[0] = size; + return OK; + } + else return csound->InitError(csound, Str("array-variable not initialised")); +} + +static int tabadd(CSOUND *csound, TABARITH *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + ARRAYDAT *r = p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || + p->left->data==NULL || p->right->data==NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (r->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] + r->data[i]; + return OK; +} + +static int tabsub(CSOUND *csound, TABARITH *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + ARRAYDAT *r = p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || + p->left->data==NULL || p->right->data==NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (r->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] - r->data[i]; + return OK; +} + +/* static int tabneg(CSOUND *csound, TABARITH *p) */ +/* { */ +/* ARRAYDAT *ans = p->ans; */ +/* ARRAYDAT *l = p->left; */ +/* int size = ans->sizes[0]; */ +/* int i; */ + +/* if (UNLIKELY(p->ans->data == NULL || p->left->data==NULL)) */ +/* return csound->PerfError(csound, p->h.insdshead, */ +/* Str("array-variable not initialised")); */ + +/* if (l->sizes[0]sizes[0]; */ +/* for (i=0; idata[i] = - l->data[i]; */ +/* return OK; */ +/* } */ + +static int tabmult(CSOUND *csound, TABARITH *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + ARRAYDAT *r = p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || + p->left->data== NULL || p->right->data==NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + //printf("sizes %d %d %d\n", l->sizes[0], r->sizes[0], size); + if (l->sizes[0]sizes[0]; + if (r->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] * r->data[i]; + return OK; +} + +static int tabdiv(CSOUND *csound, TABARITH *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + ARRAYDAT *r = p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || + p->left->data== NULL || p->right->data==NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (r->sizes[0]sizes[0]; + for (i=0; idata[i]!=0)) + ans->data[i] = l->data[i] / r->data[i]; + else return csound->PerfError(csound, p->h.insdshead, + Str("division by zero in array-var")); + return OK; +} + +static int tabrem(CSOUND *csound, TABARITH *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + ARRAYDAT *r = p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || + p->left->data== NULL || p->right->data==NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (r->sizes[0]sizes[0]; + for (i=0; idata[i] = MOD(l->data[i], r->data[i]); + return OK; +} + +// Add array and scalar +static int tabiadd(CSOUND *csound, ARRAYDAT *ans, ARRAYDAT *l, MYFLT r, void *p) +{ + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, ((TABARITH *) p)->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] + r; + return OK; +} + +// K[]+K +static int tabaiadd(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + MYFLT r = *p->right; + return tabiadd(csound, ans, l, r, p); +} + +// K+K[] +static int tabiaadd(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->right; + MYFLT r = *p->left; + return tabiadd(csound, ans, l, r, p); +} + +// Subtract K[]-K +static int tabaisub(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + MYFLT r = *p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] - r; + return OK; +} + +// Subtract K-K[] +static int tabiasub(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->right; + MYFLT r = *p->left; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(p->ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = r - l->data[i]; + return OK; +} + +// Multiply scalar by array +static int tabimult(CSOUND *csound, ARRAYDAT *ans, ARRAYDAT *l, MYFLT r, void *p) +{ + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, ((TABARITH1 *)p)->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] * r; + return OK; +} + +// K[] * K +static int tabaimult(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + MYFLT r = *p->right; + return tabimult(csound, ans, l, r, p); +} + +// K * K[] +static int tabiamult(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->right; + MYFLT r = *p->left; + return tabimult(csound, ans, l, r, p); +} + +// K[] / K +static int tabaidiv(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + MYFLT r = *p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(r==FL(0.0))) + return csound->PerfError(csound, p->h.insdshead, + Str("division by zero in array-var")); + if (UNLIKELY(ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = l->data[i] / r; + return OK; +} + +// K / K[] +static int tabiadiv(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->right; + MYFLT r = *p->left; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(r==FL(0.0))) + return csound->PerfError(csound, p->h.insdshead, + Str("division by zero in array-var")); + if (UNLIKELY(ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = r / l->data[i]; + return OK; +} + +// K[] % K +static int tabairem(CSOUND *csound, TABARITH1 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->left; + MYFLT r = *p->right; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(r==FL(0.0))) + return csound->PerfError(csound, p->h.insdshead, + Str("division by zero in array-var")); + if (UNLIKELY(p->ans->data == NULL || p->left->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i] = MOD(l->data[i], r); + return OK; +} + +// K % K[] +static int tabiarem(CSOUND *csound, TABARITH2 *p) +{ + ARRAYDAT *ans = p->ans; + ARRAYDAT *l = p->right; + MYFLT r = *p->left; + int size = ans->sizes[0]; + int i; + + if (UNLIKELY(ans->data == NULL || l->data== NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + + if (l->sizes[0]sizes[0]; + if (ans->sizes[0]sizes[0]; + for (i=0; idata[i]==FL(0.0))) + return csound->PerfError(csound, p->h.insdshead, + Str("division by zero in array-var")); + else + ans->data[i] = MOD(r,l->data[i]); + } + return OK; +} + +static int tabqset(CSOUND *csound, TABQUERY *p) +{ + if (LIKELY(p->tab->data)) return OK; + return csound->InitError(csound, Str("array-variable not initialised")); +} + +static int tabqset1(CSOUND *csound, TABQUERY1 *p) +{ + if (LIKELY(p->tab->data)) return OK; + return csound->InitError(csound, Str("array-variable not initialised")); +} + +static int tabmax(CSOUND *csound, TABQUERY *p) +{ + ARRAYDAT *t = p->tab; + int i, size = 0, pos = 0;; + MYFLT ans; + + if (UNLIKELY(t->data == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + /* if (UNLIKELY(t->dimensions!=1)) */ + /* return csound->PerfError(csound, p->h.insdshead, */ + /* Str("array-variable not vector")); */ + + for (i=0; idimensions; i++) size += t->sizes[i]; + ans = t->data[0]; + for (i=1; idata[i]>ans) { + ans = t->data[i]; + pos = i; + } + *p->ans = ans; + if (p->OUTOCOUNT>1) *p->pos = (MYFLT)pos; + return OK; +} + +static int tabmax1(CSOUND *csound, TABQUERY *p) +{ + if (tabqset(csound, p) == OK) return tabmax(csound, p); + else return NOTOK; +} + +static int tabmin(CSOUND *csound, TABQUERY *p) +{ + ARRAYDAT *t = p->tab; + int i, size = 0, pos = 0; + MYFLT ans; + + if (UNLIKELY(t->data == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + /* if (UNLIKELY(t->dimensions!=1)) */ + /* return csound->PerfError(csound, + p->h.insdshead, Str("array-variable not a vector")); */ + + for (i=0; idimensions; i++) size += t->sizes[i]; + ans = t->data[0]; + for (i=1; idata[i]data[i]; + pos = i; + } + *p->ans = ans; + if (p->OUTOCOUNT>1) *p->pos = (MYFLT)pos; + return OK; +} + +static int tabmin1(CSOUND *csound, TABQUERY *p) +{ + if (tabqset(csound, p) == OK) return tabmax(csound, p); + else return NOTOK; +} + +static int tabsum(CSOUND *csound, TABQUERY1 *p) +{ + ARRAYDAT *t = p->tab; + int i, size = 0; + MYFLT ans; + + if (UNLIKELY(t->data == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not initialised")); + if (UNLIKELY(t->dimensions!=1)) + return csound->PerfError(csound, p->h.insdshead, + Str("array-variable not a vector")); + ans = t->data[0]; + for (i=0; idimensions; i++) size += t->sizes[i]; + for (i=1; idata[i]; + *p->ans = ans; + return OK; +} + +static int tabsum1(CSOUND *csound, TABQUERY1 *p) +{ + if (tabqset1(csound, p) == OK) return tabsum(csound, p); + else return NOTOK; +} + +static int tabscaleset(CSOUND *csound, TABSCALE *p) +{ + if (LIKELY(p->tab->data && p->tab->dimensions==1)) return OK; + return csound->InitError(csound, Str("array-variable not initialised")); +} + +static int tabscale(CSOUND *csound, TABSCALE *p) +{ + MYFLT min = *p->kmin, max = *p->kmax; + int strt = (int)MYFLT2LRND(*p->kstart), end = (int)MYFLT2LRND(*p->kend); + ARRAYDAT *t = p->tab; + MYFLT tmin; + MYFLT tmax; + int i; + MYFLT range; + + tmin = t->data[strt]; + tmax = tmin; + + // Correct start and ending points + if (end<0) end = t->sizes[0]; + else if (end>t->sizes[0]) end = t->sizes[0]; + if (strt<0) strt = 0; + else if (strt>t->sizes[0]) strt = t->sizes[0]; + if (enddata[i]data[i]; + if (t->data[i]>tmax) tmax = t->data[i]; + } + /* printf("start/end %d/%d max/min = %g/%g tmax/tmin = %g/%g range=%g\n", */ + /* strt, end, max, min, tmax, tmin, range); */ + range = (max-min)/(tmax-tmin); + for (i=strt; idata[i] = (t->data[i]-tmin)*range + min; + } + return OK; +} + +static int tabscale1(CSOUND *csound, TABSCALE *p) +{ + if (tabscaleset(csound, p) == OK) return tabscale(csound, p); + else return NOTOK; +} + +typedef struct { + OPDS h; + ARRAYDAT *dst; + ARRAYDAT *src; + int len; +} TABCPY; + +static int tabcopy_set(CSOUND *csound, TABCPY *p) +{ + tabensure(csound, p->dst, p->src->sizes[0]); + //memmove(p->dst->data, p->src->data, sizeof(MYFLT)*p->src->sizes[0]); + return OK; +} + +static int tabcopy1(CSOUND *csound, TABCPY *p) +{ + tabensure(csound, p->dst, p->src->sizes[0]); + memmove(p->dst->data, p->src->data, sizeof(MYFLT)*p->src->sizes[0]); + return OK; +} + +static int tabcopy(CSOUND *csound, TABCPY *p) +{ + if (UNLIKELY(p->src->data==NULL) || p->src->dimensions!=1) + return csound->InitError(csound, Str("array-variable not initialised")); + tabensure(csound, p->dst, p->src->sizes[0]); + memmove(p->dst->data, p->src->data, sizeof(MYFLT)*p->src->sizes[0]); + return OK; +} + +static int tab2ftab(CSOUND *csound, TABCOPY *p) +{ + FUNC *ftp; + int fsize; + MYFLT *fdata; + ARRAYDAT *t = p->tab; + int i, tlen = 0; + + if (UNLIKELY(p->tab->data==NULL)) + return csound->PerfError(csound, + p->h.insdshead, Str("array-var not initialised")); + if (UNLIKELY((ftp = csound->FTFindP(csound, p->kfn)) == NULL)) + return csound->PerfError(csound, + p->h.insdshead, Str("No table for copy2ftab")); + for (i=0; idimensions; i++) tlen += t->sizes[i]; + fsize = ftp->flen; + fdata = ftp->ftable; + if (fsizetab->data, sizeof(MYFLT)*tlen); + return OK; +} + +typedef struct { + OPDS h; + ARRAYDAT *tab; + MYFLT *start, *end, *incr; + int len; +} TABGEN; + + +static int tabgen(CSOUND *csound, TABGEN *p) +{ + MYFLT *data = p->tab->data; + MYFLT start = *p->start; + MYFLT end = *p->end; + MYFLT incr = *p->incr; + int i, size = (end - start)/incr + 1; + + //printf("start=%f end=%f incr=%f size=%d\n", start, end, incr, size); + if (UNLIKELY(size < 0)) + csound->InitError(csound, + Str("inconsistent start, end and increment parameters")); + tabensure(csound, p->tab, size); + if (UNLIKELY(p->tab->data==NULL)) { + tabensure(csound, p->tab, size); + p->tab->sizes[0] = size; + } + //else /* This is wrong if array exists only write to specified part */ + //size = p->tab->sizes[0]; + data = p->tab->data; + for (i=0; i < size; i++) { + data[i] = start; + //printf("%f ", start); + start += incr; + } + //printf("]\n"); + + return OK; +} + + +static int ftab2tab(CSOUND *csound, TABCOPY *p) +{ + FUNC *ftp; + int fsize; + MYFLT *fdata; + int tlen; + + if (UNLIKELY((ftp = csound->FTFindP(csound, p->kfn)) == NULL)) + return csound->PerfError(csound, + p->h.insdshead, Str("No table for copy2ftab")); + fsize = ftp->flen; + if (UNLIKELY(p->tab->data==NULL)) { + tabensure(csound, p->tab, fsize); + p->tab->sizes[0] = fsize; + } + tlen = p->tab->sizes[0]; + fdata = ftp->ftable; + if (fsizetab->data, fdata, sizeof(MYFLT)*tlen); + return OK; +} + +typedef struct { + OPDS h; + ARRAYDAT *tab, *tabin; + MYFLT *start, *end; + int len; +} TABSLICE; + + +static int tabslice(CSOUND *csound, TABSLICE *p){ + + MYFLT *tabin = p->tabin->data; + int start = (int) *p->start; + int end = (int) *p->end; + int size = end - start + 1; + if (UNLIKELY(size < 0)) + csound->InitError(csound, Str("inconsistent start, end parameters")); + if (UNLIKELY(p->tabin->dimensions!=1 || size > p->tabin->sizes[0])) { + //printf("size=%d old tab size = %d\n", size, p->tabin->sizes[0]); + csound->InitError(csound, Str("slice larger than original size")); + } + tabensure(csound, p->tab, size); + memcpy(p->tab->data, tabin+start,sizeof(MYFLT)*size); + return OK; +} + +typedef struct { + OPDS h; + ARRAYDAT *tab, *tabin; + STRINGDAT *str; + int len; + OENTRY *opc; +} TABMAP; + + + +static int tabmap_set(CSOUND *csound, TABMAP *p) +{ + MYFLT *data, *tabin = p->tabin->data; + int n, size; + OENTRY *opc = NULL; + EVAL eval; + + if (UNLIKELY(p->tabin->data == NULL)||p->tabin->dimensions!=1) + return csound->InitError(csound, Str("array-var not initialised")); + + size = p->tabin->sizes[0]; + if (UNLIKELY(p->tab->data==NULL)) { + tabensure(csound, p->tab, size); + p->tab->sizes[0] = size; + } + else size = size < p->tab->sizes[0] ? size : p->tab->sizes[0]; + data = p->tab->data; + + opc = find_opcode_new(csound, p->str->data, "i", "i"); + + if (UNLIKELY(opc == NULL)) + return csound->InitError(csound, Str("%s not found"), p->str->data); + p->opc = opc; + for (n=0; n < size; n++) { + eval.a = &tabin[n]; + eval.r = &data[n]; + opc->iopadr(csound, (void *) &eval); + } + + opc = find_opcode_new(csound, p->str->data, "k", "k"); + + p->opc = opc; + return OK; +} + +static int tabmap_perf(CSOUND *csound, TABMAP *p) +{ + MYFLT *data = p->tab->data, *tabin = p->tabin->data; + int n, size; + OENTRY *opc = p->opc; + EVAL eval; + + if (UNLIKELY(p->tabin->data == NULL) || p->tabin->dimensions !=1) + return csound->PerfError(csound, + p->h.insdshead, Str("array-var not initialised")); + if (UNLIKELY(p->tab->data==NULL) || p->tab->dimensions !=1) + return csound->PerfError(csound, + p->h.insdshead, Str("array-var not initialised")); + size = p->tab->sizes[0]; + + if (UNLIKELY(opc == NULL)) + return csound->PerfError(csound, + p->h.insdshead, Str("map fn not found at k rate")); + for (n=0; n < size; n++) { + eval.a = &tabin[n]; + eval.r = &data[n]; + opc->kopadr(csound, (void *) &eval); + } + + return OK; +} + +int tablength(CSOUND *csound, TABQUERY1 *p) +{ + if (UNLIKELY(p->tab==NULL || p->tab->dimensions!=1)) *p->ans = -FL(1.0); + else *p->ans = p->tab->sizes[0]; + return OK; +} + +typedef struct { + OPDS h; + ARRAYDAT *tabin; + unsigned int len; +} OUTA; + + +static int outa_set(CSOUND *csound, OUTA *p) +{ + int len = (p->tabin->dimensions==1?p->tabin->sizes[0]:-1); + if (len>(int)csound->nchnls) len = csound->nchnls; + if (len<=0) return NOTOK; + p->len = len; + if (p->tabin->arrayMemberSize != (int)(CS_KSMPS*sizeof(MYFLT))) + return NOTOK; + return OK; +} + +static int outa(CSOUND *csound, OUTA *p) +{ + unsigned int n, m=0, nsmps = CS_KSMPS; + unsigned int l, pl = p->len; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = nsmps - p->h.insdshead->ksmps_no_end; + MYFLT *data = p->tabin->data; + MYFLT *sp= CS_SPOUT; + if (!csound->spoutactive) { + for (n=0; n=offset && nspoutactive = 1; + } + else { + for (n=0; nlen; l++) { + if (n>=offset && ntabin; + // should call ensure here but it is a-rate + aa->dimensions = 1; + if (aa->sizes) csound->Free(csound, aa->sizes); + if (aa->data) csound->Free(csound, aa->data); + aa->sizes = (int*)csound->Malloc(csound, sizeof(int)); + aa->sizes[0] = p->len = csound->inchnls; + aa->data = (MYFLT*) + csound->Malloc(csound, CS_KSMPS*sizeof(MYFLT)*p->len); + aa->arrayMemberSize = CS_KSMPS*sizeof(MYFLT); + return OK; +} + +static int ina(CSOUND *csound, OUTA *p) +{ + ARRAYDAT *aa = p->tabin; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, l, nsmps = CS_KSMPS; + MYFLT *data = aa->data; + MYFLT *sp= CS_SPIN; + int len = p->len; + for (l=0; lesr))); + (size_t)MYFLT2LRND((MYFLT)ceil((double)(max_time*CS_ESR))); BaboMemory_create(csound, &this->core, num_floats); } @@ -289,8 +289,7 @@ * in the first place. */ /* a-rate function */ -static MYFLT BaboTapline_single_output(CSOUND *csound, - const BaboTapline *this, +static MYFLT BaboTapline_single_output(const BaboTapline *this, const BaboTapParameter *pp) { /* @@ -330,14 +329,14 @@ * direct_att=(1/2) when distance is 1 m * direct_att=1 when distance is 0 m. */ - this->delay_size = (distance / sound_speed) * csound->esr; + this->delay_size = (distance / sound_speed) * CS_ESR; this->attenuation = FL(1.0) / (FL(1.0) + distance); } /* k-rate function */ static BaboTaplineParameters * BaboTapline_precalculate_parameters( - CSOUND *csound, const BaboTapline *this, BaboTaplineParameters *results, + CSOUND *csound, BaboTaplineParameters *results, MYFLT r_x, MYFLT r_y, MYFLT r_z, /* receiver position (i-rate) */ MYFLT s_x, MYFLT s_y, MYFLT s_z, /* source position (k-rate) */ MYFLT l_x, MYFLT l_y, MYFLT l_z) /* room coords (i-rate) */ @@ -383,10 +382,10 @@ const BaboTaplineParameters *pars) { int i; - MYFLT output = BaboTapline_single_output(csound, this, &pars->direct); + MYFLT output = BaboTapline_single_output(this, &pars->direct); for (i = 0; i < BABO_TAPS; ++i) - output += BaboTapline_single_output(csound, this, &pars->tap[i]); + output += BaboTapline_single_output(this, &pars->tap[i]); return output; } @@ -533,7 +532,7 @@ int i = 0; MYFLT min = FL(0.0); - const static struct babo_diffusion_constants + static const struct babo_diffusion_constants { int x, y, z; @@ -709,7 +708,7 @@ static inline MYFLT load_value_or_default(const FUNC *table, int idx, MYFLT dEfault) { - MYFLT result = (table != (FUNC *) NULL && idx < table->flen) ? + MYFLT result = (table != (FUNC *) NULL && idx < (int32)table->flen) ? table->ftable[idx] : dEfault; return result; @@ -722,7 +721,7 @@ int n = 0; if (p->expert_values > 0) - ftp = csound->FTFind(csound, &(p->expert_values)); + ftp = csound->FTnp2Find(csound, &(p->expert_values)); p->decay = load_value_or_default(ftp, n++, BABO_DEFAULT_DECAY); p->hidecay = load_value_or_default(ftp, n++, BABO_DEFAULT_HIDECAY); @@ -738,8 +737,10 @@ static void verify_coherence(CSOUND *csound, BABO *p) { - if (UNLIKELY(*(p->lx) <= FL(0.0) || *(p->ly) <= FL(0.0) || *(p->lz) <= FL(0.0))) { - csound->Die(csound, Str("Babo: resonator dimensions are incorrect " + if (UNLIKELY(*(p->lx) <= FL(0.0) || + *(p->ly) <= FL(0.0) || + *(p->lz) <= FL(0.0))) { + csound->Warning(csound, Str("Babo: resonator dimensions are incorrect " "(%.1f, %.1f, %.1f)"), *(p->lx), *(p->ly), *(p->lz)); } @@ -772,27 +773,38 @@ babo(CSOUND *csound, void *entry) { BABO *p = (BABO *) entry; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *outleft = p->outleft, *outright = p->outright, *input = p->input; BaboTaplineParameters left = { {FL(0.0)}, {{FL(0.0)}} }, - right = { {FL(0.0)}, {{FL(0.0)}} }; + right = { {FL(0.0)}, {{FL(0.0)}} }; - BaboTapline_precalculate_parameters(csound, &p->tapline, &left, - p->receiver_x - p->inter_receiver_distance, - p->receiver_y, p->receiver_z, - *(p->ksource_x), *(p->ksource_y), *(p->ksource_z), - *(p->lx), *(p->ly), *(p->lz)); + BaboTapline_precalculate_parameters(csound, &left, + p->receiver_x - p->inter_receiver_distance, + p->receiver_y, p->receiver_z, + *(p->ksource_x), *(p->ksource_y), + *(p->ksource_z), + *(p->lx), *(p->ly), *(p->lz)); - BaboTapline_precalculate_parameters(csound, &p->tapline, &right, + BaboTapline_precalculate_parameters(csound, &right, p->receiver_x + p->inter_receiver_distance, p->receiver_y, p->receiver_z, *(p->ksource_x), *(p->ksource_y), *(p->ksource_z), *(p->lx), *(p->ly), *(p->lz)); - for (n=0; n @@ -78,7 +79,7 @@ /* allocate space- need no more than a half bar at current tempo and barlength */ - M = ((size_t)(csound->esr*(*p->barlength)/(*p->bps)))*sizeof(MYFLT); + M = ((size_t)(CS_ESR*(*p->barlength)/(*p->bps)))*sizeof(MYFLT); if (p->repeatbuffer.auxp == NULL || p->repeatbuffer.sizeAuxAlloc(csound, M, &p->repeatbuffer); } @@ -94,7 +95,7 @@ /* samp per unit= samp per bar/ subdiv */ /* = samp per beat * beats per bar /subdiv */ /* =(samp per sec / beats per sec)* (beats per bar/subdiv) */ - p->samplesperunit = roundoffint(((MYFLT)csound->esr*(FL(1.0)/(*p->bps)))* + p->samplesperunit = roundoffint(((MYFLT)CS_ESR*(FL(1.0)/(*p->bps)))* (*p->barlength/(MYFLT)p->Subdiv)); /* enveloping */ @@ -110,13 +111,19 @@ static int BBCutMono(CSOUND *csound, BBCUTMONO *p) { - int i; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int oddmax,unitproj; int unitb,unitl,unitd; /* temp for integer unitblock calculations */ MYFLT envmult,out; /* intermedaites for enveloping grains */ - for (i=0;iaout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aout[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset;iunitsdone+FL(0.000001))>=p->totalunits)) { /* a new phrase of cuts */ p->numbarsnow = random_number(csound, 1, p->Phrasebars); @@ -308,7 +315,7 @@ /* allocate space- need no more than a half bar at current tempo and barlength */ - M = 2*((size_t)(csound->esr*(*p->barlength)/(*p->bps)))*sizeof(MYFLT); + M = 2*((size_t)(CS_ESR*(*p->barlength)/(*p->bps)))*sizeof(MYFLT); if (p->repeatbuffer.auxp == NULL || p->repeatbuffer.sizeAuxAlloc(csound, M, &p->repeatbuffer); @@ -324,7 +331,7 @@ /* samp per unit= samp per bar/ subdiv */ /* = samp per beat * beats per bar /subdiv */ /* =(samp per sec / beats per sec)* (beats per bar/subdiv) */ - p->samplesperunit = roundoffint(((MYFLT)csound->esr/ + p->samplesperunit = roundoffint(((MYFLT)CS_ESR/ (*p->bps))*(*p->barlength/ (MYFLT)p->Subdiv)); @@ -340,14 +347,25 @@ /* only make floating point corrections for stutters with stutterspeed>1 */ static int BBCutStereo(CSOUND *csound, BBCUTSTEREO *p) { - int i; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int oddmax,unitproj; int unitb,unitl,unitd; /* temp for integer unitblock calculations */ MYFLT envmult,out1,out2;/* intermediates for enveloping grains */ - for (i=0;iunitsdone+FL(0.000001))>=p->totalunits)) {/* a new phrase of cuts */ + if (UNLIKELY(offset)) { + memset(p->aout1, '\0', offset*sizeof(MYFLT)); + memset(p->aout2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aout1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->aout2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset;iunitsdone+FL(0.000001))>=p->totalunits)) { p->numbarsnow = random_number(csound, 1, p->Phrasebars); p->totalunits = p->numbarsnow*p->Subdiv; @@ -514,9 +532,9 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "bbcutm",S(BBCUTMONO), 5, "a","aiiiiipop", + { "bbcutm",S(BBCUTMONO), 0, 5, "a","aiiiiipop", (SUBR)BBCutMonoInit, NULL, (SUBR)BBCutMono }, -{ "bbcuts",S(BBCUTSTEREO),5, "aa","aaiiiiipop", + { "bbcuts",S(BBCUTSTEREO), 0, 5, "aa","aaiiiiipop", (SUBR)BBCutStereoInit, NULL, (SUBR)BBCutStereo} }; diff -Nru csound-5.17.11~dfsg/Opcodes/bilbar.c csound-6.02~dfsg/Opcodes/bilbar.c --- csound-5.17.11~dfsg/Opcodes/bilbar.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/bilbar.c 2014-01-07 16:53:47.000000000 +0000 @@ -46,15 +46,15 @@ static int bar_init(CSOUND *csound, BAR *p) { - if (*p->iK >= FL(0.0)) { - double K = *p->iK; /* ~=3.0 stiffness parameter, dimensionless */ + if (*p->iK >= FL(0.0) || p->w_aux.auxp == NULL) { + double K = FABS(*p->iK); /* ~=3.0 stiffness parameter, dimensionless */ double T30 = *p->iT30; /* ~=5.0; 30 db decay time (s) */ double b = *p->ib; /* ~=0.001 high-frequency loss parameter (keep small) */ /* %%%%%%%%%%%%%%%%%% derived parameters */ double dt = (double)csound->onedsr; - double sig = (2.0*(double)csound->esr)*(pow(10.0,3.0*dt/T30)-1.0); + double sig = (2.0*(double)CS_ESR)*(pow(10.0,3.0*dt/T30)-1.0); double dxmin = sqrt(dt*(b+hypot(b, K+K))); int N = (int) (1.0/dxmin); double dx = 1.0/N; @@ -78,10 +78,12 @@ p->step = p->first = 0; p->N = N; } + /* else { if (UNLIKELY(p->w_aux.auxp == NULL)) return csound->InitError(csound, Str("No data to continue")); } + */ p->first = 0; return OK; @@ -89,12 +91,15 @@ static int bar_run(CSOUND *csound, BAR *p) { - double xofreq = TWOPI* (*p->kscan)/csound->esr; /* kspan ~=0.23; */ + double xofreq = TWOPI* (*p->kscan)/CS_ESR; /* kspan ~=0.23; */ double xo, xofrac; int xoint; int step = p->step; int first = p->first; - int n, N = p->N, rr; + int N = p->N, rr; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double *w = p->w, *w1 = p->w1, *w2 = p->w2; double s0 = p->s0, s1 = p->s1, s2 = p->s2, t0 = p->t0, t1 = p->t1; int bcL = (int)MYFLT2LONG(*p->kbcL); /* boundary condition pair */ @@ -103,13 +108,18 @@ double COSNW = cos(xofreq*step); /* formula rather than many calls */ double SIN1W = sin(xofreq); /* Wins in ksmps>4 */ double COS1W = cos(xofreq); + MYFLT *ar = p->ar; if (UNLIKELY((bcL|bcR)&(~3) && (bcL|bcR)!=0)) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Ends must be clamped(1), " "pivoting(2) or free(3)")); - - for (n = 0; n < csound->ksmps; n++) { + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { /* Fix ends */ if (bcL == 3) { w1[1] = 2.0*w1[2]-w1[3]; @@ -148,7 +158,7 @@ p->first = first = 1; for (rr = 0; rr < N; rr++) { if (fabs(rr/(double)N - *p->ipos) <= *p->iwid) { - w[rr+2] += (1.0/csound->esr)*(*p->ivel)*0.5* + w[rr+2] += (1.0/CS_ESR)*(*p->ivel)*0.5* (1.0+cos(PI*fabs(rr/(double)N-(*p->ipos))/(*p->iwid))); } } @@ -156,12 +166,12 @@ /* readouts */ - /* xo = (1.0/3.0) + 0.5*sin(TWOPI*xofreq*(step+1)/csound->esr); */ + /* xo = (1.0/3.0) + 0.5*sin(TWOPI*xofreq*(step+1)/CS_ESR); */ /* sin((N+1)w) = sin(Nw)cos(w) + cos(Nw)sin(w) */ /* cos((N+1)w) = cos(Nw)cos(w) - sin(Nw)sin(w) */ /* so can calculate sin on next line by iteration at less cost */ /* But is xofreq were to change could be difficult! */ - /* xo = 0.5 + 0.5*sin(TWOPI*xofreq*(step+1)/csound->esr); */ + /* xo = 0.5 + 0.5*sin(TWOPI*xofreq*(step+1)/CS_ESR); */ { double xx = SINNW*COS1W + COSNW*SIN1W; double yy = COSNW*COS1W - SINNW*SIN1W; @@ -175,7 +185,7 @@ /* csound->Message(csound, "xo = %f (%d %f) w=(%f,%f) ", xo, xoint, xofrac, w[xoint], w[xoint+1]); */ - p->ar[n] = (csound->e0dbfs)*((1.0-xofrac)*w[xoint] + xofrac*w[xoint+1]); + ar[n] = (csound->e0dbfs)*((1.0-xofrac)*w[xoint] + xofrac*w[xoint+1]); step++; { double *ww = w2; @@ -233,8 +243,9 @@ MYFLT *s0, *s1, s2, t0, t1; MYFLT *hammer_force; int stereo; - int NS, N, init, step; - int rattle_num, rubber_num; + uint32_t NS; + int N, init, step; + uint32_t rattle_num, rubber_num; int hammer_index, hammer_on, hammer_contact; MYFLT ham, ham1, ham2; AUXCH auxch; @@ -249,32 +260,32 @@ double f0 = *p->ifreq; /* fundamental freq. (Hz) */ double T30 = *p->iT30; /* 30 db decay time (s) */ double b = *p->ib; /* high-frequency loss parameter (keep small) */ - int NS = p->NS = (int)*p->iNS; /* number of strings */ + uint32_t NS = p->NS = (int)*p->iNS; /* number of strings */ double D = *p->iD; /* detune parameter (multiple strings) in cents */ /* I.e., a total of D cents diff between highest */ /* and lowest string in set */ /* initialize prepared objects and hammer */ /* derived parameters */ double dt = (double)csound->onedsr; - double sig = (2.0*(double)csound->esr)*(pow(10.0,3.0*dt/T30)-1.0); + double sig = (2.0*(double)CS_ESR)*(pow(10.0,3.0*dt/T30)-1.0); - int N, n; - double *c, dx, dxmin = 0.0; /* for stability */ + uint32_t N, n; + double *c, /*dx,*/ dxmin = 0.0; /* for stability */ FUNC *ftp; csound->AuxAlloc(csound, NS*sizeof(double), &p->auxch); c = (double *)p->auxch.auxp; if (*p->rattle_tab==FL(0.0) || - (ftp=csound->FTFind(csound, p->rattle_tab)) == NULL) p->rattle_num = 0; + (ftp=csound->FTnp2Find(csound, p->rattle_tab)) == NULL) p->rattle_num = 0; else { - p->rattle_num = (int)(*ftp->ftable); + p->rattle_num = (uint32_t)(*ftp->ftable); p->rattle = (RATTLE*)(&((MYFLT*)ftp->ftable)[1]); } if (*p->rubber_tab==FL(0.0) || - (ftp=csound->FTFind(csound, p->rubber_tab)) == NULL) p->rubber_num = 0; + (ftp=csound->FTnp2Find(csound, p->rubber_tab)) == NULL) p->rubber_num = 0; else { - p->rubber_num = (int)(*ftp->ftable); + p->rubber_num = (uint32_t)(*ftp->ftable); p->rubber = (RUBBER*)(&((MYFLT*)ftp->ftable)[1]); } @@ -288,8 +299,8 @@ double x = sqrt(y+hypot(y,4.0*K*dt))/sqrt(2); if (x>dxmin) dxmin = x; } - N = p->N = (int)(1.0/dxmin); - dx = 1.0/(double)N; + N = p->N = (uint32_t)(1.0/dxmin); + //dx = 1.0/(double)N; csound->AuxAlloc(csound, 3*((1+(N+5))*NS+p->rattle_num+p->rubber_num)*sizeof(MYFLT), @@ -340,10 +351,12 @@ { MYFLT *ar = p->ar; MYFLT *ar1 = p->ar1; - int NS = p->NS; - int N = p->N; + uint32_t NS = p->NS; + uint32_t N = p->N; int step = p->step; - int n, t, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t t, n, nsmps = CS_KSMPS; double dt = csound->onedsr; MYFLT *w = p->w, *w1 = p->w1, *w2 = p->w2, *rub = p->rub, *rub1 = p->rub1, *rub2 = p->rub2, @@ -359,8 +372,8 @@ double COS1W2 = 0; if (p->stereo) { - double f1 = (*p->scanfreq - FL(0.5)* *p->scanspread)/csound->esr; - double f2 = (*p->scanfreq + FL(0.5)* *p->scanspread)/csound->esr; + double f1 = (*p->scanfreq - FL(0.5)* *p->scanspread)/CS_ESR; + double f2 = (*p->scanfreq + FL(0.5)* *p->scanspread)/CS_ESR; SINNW = sin(f1*TWOPI*step); /* these are to calculate sin/cos by */ COSNW = cos(f1*TWOPI*step); /* formula rather than many calls */ SIN1W = sin(f1*TWOPI); /* Wins in ksmps>4 */ @@ -371,7 +384,7 @@ COS1W2 = cos(f2*TWOPI); } else { - double f1 = *p->scanfreq/csound->esr; + double f1 = *p->scanfreq/CS_ESR; SINNW = sin(f1*TWOPI*step); /* these are to calculate sin/cos by */ COSNW = cos(f1*TWOPI*step); /* formula rather than many calls */ SIN1W = sin(f1*TWOPI); /* Wins in ksmps>4 */ @@ -387,8 +400,17 @@ p->init = 0; } - for (t=0; tstereo) memset(ar1, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + if (p->stereo) memset(&ar1[nsmps], '\0', early*sizeof(MYFLT)); + } + for (t=offset; thammer_force[n] = 0.0; /* set boundary conditions on last state w1 */ if ((int)*p->kbcl==1) { @@ -530,7 +552,7 @@ step++; } { - int i; + uint32_t i; void *w3 = w2; w2 = w1; w1 = w; @@ -549,11 +571,10 @@ #define S(x) sizeof(x) static OENTRY bilbar_localops[] = { - {"barmodel", S(BAR), 5, "a", "kkiikiiii", (SUBR) bar_init, NULL, - (SUBR) bar_run}, - { "prepiano", S(CSPP), 5, "mm", "iiiiiikkiiiiiiioo", - (SUBR)init_pp, NULL, (SUBR)play_pp }, + {"barmodel", S(BAR), 0, 5, "a", "kkiikiiii", (SUBR) bar_init, NULL, + (SUBR) bar_run}, + { "prepiano", S(CSPP), 0, 5, "mm", "iiiiiikkiiiiiiioo", + ( SUBR)init_pp, NULL, (SUBR)play_pp }, }; -LINKAGE1(bilbar_localops) - +LINKAGE_BUILTIN(bilbar_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/biquad.c csound-6.02~dfsg/Opcodes/biquad.c --- csound-5.17.11~dfsg/Opcodes/biquad.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/biquad.c 2014-01-07 16:54:20.000000000 +0000 @@ -30,7 +30,7 @@ /* Nested allpass and Lorenz added */ /* October 1998 by Hans Mikelson */ /***************************************************************/ -#include "csdl.h" +//#include "csdl.h" #include #include "biquad.h" @@ -51,12 +51,20 @@ static int biquad(CSOUND *csound, BIQUAD *p) { - int n = 0, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double xn, yn; double xnm1 = p->xnm1, xnm2 = p->xnm2, ynm1 = p->ynm1, ynm2 = p->ynm2; double a0 = 1.0 / *p->a0, a1 = a0 * *p->a1, a2 = a0 * *p->a2; double b0 = a0 * *p->b0, b1 = a0 * *p->b1, b2 = a0 * *p->b2; - for (n=0; nout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nin[n]; yn = b0*xn + b1*xnm1 + b2*xnm2 - a1*ynm1 - a2*ynm2; xnm2 = xnm1; @@ -73,7 +81,9 @@ static int biquada(CSOUND *csound, BIQUAD *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *in; double xn, yn; MYFLT *a0 = p->a0, *a1 = p->a1, *a2 = p->a2; @@ -81,7 +91,12 @@ double xnm1 = p->xnm1, xnm2 = p->xnm2, ynm1 = p->ynm1, ynm2 = p->ynm2; in = p->in; out = p->out; - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *in; double xn; MYFLT *fcoptr, *resptr; @@ -143,7 +160,12 @@ scale = exp((1.0-pp1d2)*1.386249); /* Scaling factor */ k = res*scale; } - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -159,7 +181,7 @@ scale = exp((1.0-pp1d2)*1.386249); /* Scaling factor */ k = res*scale; } - xn = (double)in[n] * dmax; + xn = (double)in[n] * dmax/csound->e0dbfs; xn = xn - k * y4n; /* Inverted feed back for corner peaking */ /* Four cascaded onepole filters (bilinear transform) */ @@ -180,7 +202,7 @@ y1nm1 = y1n; /* Update Y1n-1 */ y2nm1 = y2n; /* Update Y2n-1 */ y3nm1 = y3n; /* Update Y3n-1 */ - out[n] = (MYFLT)(y4n * max); + out[n] = (MYFLT)(y4n * max * csound->e0dbfs); } p->xnm1 = xnm1; p->y1nm1 = y1nm1; p->y2nm1 = y2nm1; p->y3nm1 = y3nm1; p->y1n = y1n; p->y2n = y2n; p->y3n = y3n; p->y4n = y4n; @@ -205,7 +227,9 @@ static int rezzy(CSOUND *csound, REZZY *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *fcoptr, *rezptr, *in; double fco, rez, xn, yn; double fqcadj, a=0.0, /* Initialisations fake */ @@ -220,11 +244,17 @@ rez = (double)*rezptr; /* Freq. is adjusted based on sample rate */ - fqcadj = 0.149659863*(double)csound->esr; + fqcadj = 0.149659863*(double)CS_ESR; /* Try to keep the resonance under control */ if (rez < 1.0) rez = 1.0; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (*p->mode == FL(0.0)) { /* Low Pass */ - if (UNLIKELY((p->rezcod==0) && (p->fcocod==0))) {/* Only need to calculate once */ + if (UNLIKELY((p->rezcod==0) && (p->fcocod==0))) { + /* Only need to calculate once */ double c = fqcadj/fco; /* Filter constant c=1/Fco * adjustment */ double rez2 = rez/(1.0 + exp(fco/11000.0)); double b; @@ -233,7 +263,7 @@ b = 1.0 + a + csq; /* Normalization constant */ invb = 1.0/b; } - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -252,7 +282,8 @@ } xn = (double)in[n]; /* Get the next sample */ /* Mikelson Biquad Filter Guts*/ - yn = (1.0/sqrt(1.0+rez)*xn - (-a-2.0*csq)*ynm1 - csq*ynm2)*invb; + //yn = (1.0/sqrt(1.0+rez)*xn - (-a-2.0*csq)*ynm1 - csq*ynm2)*invb; + yn = (1.0/sqrt(1.0+rez)*xn - csq*((-a-2.0)*ynm1 + ynm2))*invb; xnm2 = xnm1; /* Update Xn-2 */ xnm1 = xn; /* Update Xn-1 */ @@ -264,7 +295,8 @@ } else { /* High Pass Rezzy */ double c=0.0, rez2=0.0; - if (UNLIKELY(p->fcocod==0 && p->rezcod==0)) {/* Only need to calculate once */ + if (UNLIKELY(p->fcocod==0 && p->rezcod==0)) { + /* Only need to calculate once */ double b; c = fqcadj/fco; /* Filter constant c=1/Fco * adjustment */ rez2 = rez/(1.0 + sqrt(sqrt(1.0/c))); @@ -273,7 +305,7 @@ b = (c/rez2 + csq); invb = 1.0/b; } - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -314,7 +346,9 @@ static int distort(CSOUND *csound, DISTORT *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *in; MYFLT pregain = *p->pregain, postgain = *p->postgain; MYFLT shape1 = *p->shape1, shape2 = *p->shape2; @@ -342,7 +376,12 @@ shape1 += pregain; shape2 -= pregain; postgain *= FL(0.5); - for (n=0; nmaxd * csound->esr); + uint32 ndel = (uint32)(*p->maxd * CS_ESR); FUNC *ftp; /* Pointer to a sine function */ - MYFLT ndsave; + //MYFLT ndsave; - ndsave = (MYFLT) ndel; + //ndsave = (MYFLT) ndel; if (UNLIKELY((ftp = csound->FTFind(csound, p->sine)) == NULL)) return NOTOK; @@ -390,8 +429,8 @@ if (UNLIKELY(ndel == 0)) ndel = 1; /* fix due to Troxler */ if (p->aux.auxp == NULL || - (int)(ndel*sizeof(MYFLT)) > p->aux.size) /* allocate space for delay - buffer */ + (unsigned int)(ndel*sizeof(MYFLT)) > p->aux.size) + /* allocate space for delay buffer */ csound->AuxAlloc(csound, ndel * sizeof(MYFLT), &p->aux); else if (*p->iskip==FL(0.0)) { memset(p->aux.auxp, 0, ndel*sizeof(MYFLT)); @@ -415,10 +454,13 @@ FUNC *ftp; MYFLT *ar, *ampp, *cpsp, *ftbl; int32 phs, inc, lobits, dwnphs, tnp1, lenmask, maxd, indx; - MYFLT leaky, rtfqc, amp, fqc; + MYFLT leaky, /*rtfqc,*/ amp, fqc; MYFLT sicvt2, over2n, scal, num, denom, pulse = FL(0.0), saw = FL(0.0); MYFLT sqr = FL(0.0), tri = FL(0.0); - int n, nsmps = csound->ksmps, knh; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int knh; /* VDelay Inserted here */ MYFLT *buf = (MYFLT *)p->aux.auxp; @@ -430,7 +472,7 @@ ftp = p->ftp; if (UNLIKELY(buf==NULL || ftp==NULL)) goto err1; /* RWD fix */ - maxd = (uint32) (*p->maxd * csound->esr); + maxd = (uint32) (*p->maxd * CS_ESR); if (UNLIKELY(maxd == 0)) maxd = 1; /* Degenerate case */ indx = p->left; /* End of VDelay insert */ @@ -442,8 +484,8 @@ ampp = p->xamp; cpsp = p->xcps; fqc = *cpsp; - rtfqc = SQRT(fqc); - knh = (int)(csound->esr*p->nyq/fqc); + //rtfqc = SQRT(fqc); + knh = (int)(CS_ESR*p->nyq/fqc); if (UNLIKELY((n = (int)knh) <= 0)) { csound->Warning(csound, "knh=%x nyq=%f fqc=%f\n" "vco knh (%d) <= 0; taken as 1\n", knh, p->nyq, fqc, n); @@ -457,13 +499,18 @@ inc = (int32)(fqc * sicvt2); ar = p->ar; phs = p->lphs; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } /*-----------------------------------------------------*/ /* PWM Wave */ /*-----------------------------------------------------*/ if (wave==2) { MYFLT pw = *p->pw; - for (n=0; n> lobits; denom = *(ftbl + dwnphs); if (denom > FL(0.00001) || denom < -FL(0.00001)) { @@ -484,7 +531,7 @@ /* VDelay inserted here */ buf[indx] = pulse; - fv1 = (MYFLT) indx - csound->esr * pw / fqc; + fv1 = (MYFLT) indx - CS_ESR * pw / fqc; v1 = (int32) fv1; if (fv1 < FL(0.0)) v1--; @@ -512,7 +559,7 @@ /*-----------------------------------------------------*/ else if (wave==3) { MYFLT pw = *p->pw; - for (n=0; n> lobits; denom = *(ftbl + dwnphs); if (denom > FL(0.0002) || denom < -FL(0.0002)) { @@ -534,7 +581,7 @@ /* VDelay inserted here */ buf[indx] = pulse; - fv1 = (MYFLT) indx - csound->esr * pw / fqc; + fv1 = (MYFLT) indx - CS_ESR * pw / fqc; v1 = (int32) fv1; if (fv1 < FL(0.0)) v1--; @@ -548,7 +595,7 @@ v2 = (v1 < (maxd - 1L) ? v1 + 1L : 0L); out1 = buf[v1] + fv1 * (buf[v2] - buf[v1]); - if (UNLIKELY(++indx == maxd)) indx = 0; /* Advance current pointer */ + if (UNLIKELY(++indx == maxd)) indx = 0; /* Advance current pointer */ /* End of VDelay */ /* Integrate twice and ouput */ @@ -557,14 +604,14 @@ p->ynm1 = sqr; p->ynm2 = tri; ar[n] = tri * amp * fqc - / (csound->esr * FL(0.42) * (FL(0.05) + pw - pw * pw)); + / (CS_ESR * FL(0.42) * (FL(0.05) + pw - pw * pw)); } } /*-----------------------------------------------------*/ /* Sawtooth Wave */ /*-----------------------------------------------------*/ else { - for (n=0; n> lobits; denom = *(ftbl + dwnphs); if (denom > FL(0.0002) || denom < -FL(0.0002)) { @@ -596,7 +643,7 @@ p->lphs = phs; return OK; err1: - return csound->PerfError(csound, Str("vco: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("vco: not initialised")); } /***************************************************************************/ @@ -623,7 +670,9 @@ MYFLT *outx, *outy, *outz; MYFLT sqradius1, sqradius2, radius1, radius2, fric; MYFLT xxpyy, dz1, dz2, mass1, mass2, msqror1, msqror2; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; fric = p->friction; @@ -637,7 +686,19 @@ mass1 = *p->mass1; mass2 = *p->mass2; - for (n=0; nx * p->x + p->y * p->y; dz1 = p->s1z - p->z; @@ -698,7 +759,9 @@ static int pareq(CSOUND *csound, PAREQ *p) { MYFLT xn, yn; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (*p->fc != p->prv_fc || *p->v != p->prv_v || *p->q != p->prv_q) { double omega = (double)(csound->tpidsr * *p->fc), k, kk, vkk, vk, vkdq, a0; @@ -749,12 +812,16 @@ a0 = 1.0 / a0; p->a1 *= a0; p->a2 *= a0; p->b0 *= a0; p->b1 *= a0; p->b2 *= a0; } - + if (UNLIKELY(offset)) memset(p->out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->out[nsmps], '\0', early*sizeof(MYFLT)); + } { double a1 = p->a1, a2 = p->a2; double b0 = p->b0, b1 = p->b1, b2 = p->b2; double xnm1 = p->xnm1, xnm2 = p->xnm2, ynm1 = p->ynm1, ynm2 = p->ynm2; - for (n=0; nin[n]; yn = b0 * xn + b1 * xnm1 + b2 * xnm2 - a1 * ynm1 - a2 * ynm2; xnm2 = xnm1; @@ -781,12 +848,13 @@ if (*p->istor && p->auxch.auxp != NULL) return OK; - npts2 = (int32)(*p->del2 * csound->esr); - npts3 = (int32)(*p->del3 * csound->esr); - npts1 = (int32)(*p->del1 * csound->esr) - npts2 -npts3; - - if (UNLIKELY(((int32)(*p->del1 * csound->esr)) <= - ((int32)(*p->del2 * csound->esr) + (int32)(*p->del3 * csound->esr)))) { + npts2 = (int32)(*p->del2 * CS_ESR); + npts3 = (int32)(*p->del3 * CS_ESR); + npts1 = (int32)(*p->del1 * CS_ESR) - npts2 -npts3; + + if (UNLIKELY(((int32)(*p->del1 * CS_ESR)) <= + ((int32)(*p->del2 * CS_ESR) + + (int32)(*p->del3 * CS_ESR)))) { return csound->InitError(csound, Str("illegal delay time")); } npts = npts1 + npts2 + npts3; @@ -843,13 +911,20 @@ MYFLT *beg1p, *beg2p, *beg3p, *end1p, *end2p, *end3p; MYFLT *del1p, *del2p, *del3p; MYFLT in1, g1, g2, g3; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ outp = p->out; inp = p->in; + if (UNLIKELY(offset)) memset(outp, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outp[nsmps], '\0', early*sizeof(MYFLT)); + } /* Ordinary All-Pass Filter */ if (*p->mode == FL(1.0)) { @@ -858,7 +933,7 @@ beg1p = p->beg1p; g1 = *p->gain1; - for (n=0; nout1 = *del1p - g1*in1; @@ -885,7 +960,7 @@ beg2p = p->beg2p; g2 = *p->gain2; - for (n=0; nout2 = *del2p - g2 * *del1p; @@ -926,7 +1001,7 @@ beg3p = p->beg3p; g3 = *p->gain3; - for (n=0; nout2 = *del2p - g2 * *del1p; @@ -957,7 +1032,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("delay: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("delay: not initialised")); } /***************************************************************************/ @@ -979,7 +1055,10 @@ { MYFLT *outx, *outy, *outz; MYFLT x, y, z, xx, yy, s, r, b, hstep; - int32 n, nsmps = csound->ksmps, skip; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 skip; outx = p->outx; outy = p->outy; @@ -994,7 +1073,19 @@ y = p->valy; z = p->valz; - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *in; double x; MYFLT *fcoptr, *resptr, *distptr, *asymptr; @@ -1069,7 +1162,12 @@ q = q1*fco1*fco1*0.0005; fc = fco1*(double)csound->onedsr*(44100.0/8.0); } - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -1110,7 +1208,9 @@ static int bqrez(CSOUND *csound, REZZY *p) { - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *fcoptr, *rezptr, *in; double fco, rez, xn, yn; double sin2 = 0.0, cos2 = 0.0, beta=0.0, alpha, gamma=0.0, mu, sigma, chi; @@ -1133,6 +1233,12 @@ gamma = (beta + 1.0) * cos2; } + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + if (mode < 3) { if (mode == 0) { /* Low Pass */ chi = -1.0; @@ -1151,7 +1257,7 @@ } alpha = (beta + 1.0 + chi*gamma) * 0.5; - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -1180,7 +1286,7 @@ } else if (mode == 3) { /* Band Stop */ alpha = (beta + 1.0) * 0.5; - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -1208,7 +1314,7 @@ } } else if (mode == 4) { /* All Pass */ - for (n=0; nfcocod) { fco = (double)fcoptr[n]; @@ -1249,39 +1355,57 @@ /* Initialize filter to zero if set to reinitialize. */ if (*p->reinit==FL(0.0)) { /* Only reset in in non-legato mode */ p->xnm1 = p->ynm1 = p->ynm2 = 0.0; + p->a0 = p->a1 = p->a2 = p->d = 0.0; } + p->lfq = -FL(1.0); p->lq = -FL(1.0); return OK; } static int mode(CSOUND *csound, MODE *p) { - int n = 0, nsmps = csound->ksmps; - - double kfreq = *p->kfreq*2*PI; - double kalpha = (csound->esr/kfreq); - double kbeta = kalpha*kalpha; - - double a0 = 1/ (kbeta+kalpha/(2* *p->kq)); - double a1 = a0 * (1-2*kbeta); - double a2 = a0 * (kbeta-kalpha/(2* *p->kq)); - - double xn, yn; - - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT lfq = p->lfq, lq = p->lq; + + double xn, yn, a0=p->a0, a1=p->a1, a2=p->a2,d=p->d; + double xnm1 = p->xnm1, ynm1 = p->ynm1, ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(p->aout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aout[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nkfreq[n] : *p->kfreq; + MYFLT kq = XINARG3 ? p->kq[n] : *p->kq; + if (lfq != kfq || lq != kq) { + double kfreq = kfq*TWOPI; + double kalpha = (CS_ESR/kfreq); + double kbeta = kalpha*kalpha; + d = 0.5*kalpha; + + lq = kq; lfq = kfq; + a0 = 1.0/ (kbeta+d/kq); + a1 = a0 * (1.0-2.0*kbeta); + a2 = a0 * (kbeta-d/kq); + } xn = (double)p->ain[n]; - yn = a0*p->xnm1 - a1*p->ynm1 - a2*p->ynm2; + yn = a0*xnm1 - a1*ynm1 - a2*ynm2; - p->xnm1 = xn; - p->ynm2 = p->ynm1; - p->ynm1 = yn; + xnm1 = xn; + ynm2 = ynm1; + ynm1 = yn; - yn = yn*csound->esr/(2*kfreq); + yn = yn*d; p->aout[n] = (MYFLT)yn; } - + p->xnm1 = xnm1; p->ynm1 = ynm1; p->ynm2 = ynm2; + p->lfq = lfq; p->lq = lq; p->d = d; + p->a0 = a0; p->a1 = a1; p->a2 = a2; return OK; } @@ -1290,21 +1414,28 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "biquad", S(BIQUAD), 5, "a", "akkkkkko",(SUBR)biquadset, NULL, (SUBR)biquad }, -{ "biquada", S(BIQUAD), 5, "a", "aaaaaaao",(SUBR)biquadset, NULL,(SUBR)biquada }, -{ "moogvcf", S(MOOGVCF), 5, "a", "axxpo", (SUBR)moogvcfset, NULL, (SUBR)moogvcf }, -{ "moogvcf2", S(MOOGVCF),5, "a", "axxoo", (SUBR)moogvcfset, NULL, (SUBR)moogvcf }, -{ "rezzy", S(REZZY), 5, "a", "axxoo", (SUBR)rezzyset, NULL, (SUBR)rezzy }, -{ "bqrez", S(REZZY), 5, "a", "axxoo", (SUBR)bqrezset, NULL, (SUBR)bqrez }, -{ "distort1", S(DISTORT),TR|4, "a", "akkkko", NULL, NULL, (SUBR)distort }, -{ "vco", S(VCO), TR|5, "a", "xxiVppovoo",(SUBR)vcoset, NULL, (SUBR)vco }, -{ "tbvcf", S(TBVCF), 5, "a", "axxkkp", (SUBR)tbvcfset, NULL, (SUBR)tbvcf }, -{ "planet", S(PLANET),5,"aaa","kkkiiiiiiioo", (SUBR)planetset, NULL, (SUBR)planet}, -{ "pareq", S(PAREQ), 5, "a", "akkkoo",(SUBR)pareqset, NULL, (SUBR)pareq }, -{ "nestedap", S(NESTEDAP),5,"a", "aiiiiooooo", + { "biquad", S(BIQUAD), 0, 5, "a", "akkkkkko", + (SUBR)biquadset, NULL, (SUBR)biquad }, +{ "biquada", S(BIQUAD), 0, 5, "a", "aaaaaaao", + (SUBR)biquadset, NULL,(SUBR)biquada }, +{ "moogvcf", S(MOOGVCF), 0, 5, "a", "axxpo", + (SUBR)moogvcfset, NULL, (SUBR)moogvcf }, +{ "moogvcf2", S(MOOGVCF),0, 5, "a", "axxoo", + (SUBR)moogvcfset, NULL, (SUBR)moogvcf }, +{ "rezzy", S(REZZY), 0, 5, "a", "axxoo", (SUBR)rezzyset, NULL, (SUBR)rezzy }, +{ "bqrez", S(REZZY), 0, 5, "a", "axxoo", (SUBR)bqrezset, NULL, (SUBR)bqrez }, +{ "distort1", S(DISTORT),TR, 4, "a", "akkkko", NULL, NULL, (SUBR)distort }, +{ "vco", S(VCO), TR, 5, "a", "xxiVppovoo",(SUBR)vcoset, NULL, (SUBR)vco }, +{ "tbvcf", S(TBVCF), 0, 5, "a", "axxkkp", + (SUBR)tbvcfset, NULL, (SUBR)tbvcf }, +{ "planet", S(PLANET),0, 5,"aaa","kkkiiiiiiioo", + (SUBR)planetset, NULL, (SUBR)planet}, +{ "pareq", S(PAREQ), 0, 5, "a", "akkkoo",(SUBR)pareqset, NULL, (SUBR)pareq }, +{ "nestedap", S(NESTEDAP),0, 5,"a", "aiiiiooooo", (SUBR)nestedapset, NULL, (SUBR)nestedap}, -{ "lorenz", S(LORENZ), 5, "aaa", "kkkkiiiio", (SUBR)lorenzset, NULL, (SUBR)lorenz}, -{ "mode", S(MODE), 5, "a", "akko", (SUBR)modeset, NULL, (SUBR)mode } +{ "lorenz", S(LORENZ),0, 5, "aaa", "kkkkiiiio", + (SUBR)lorenzset, NULL, (SUBR)lorenz}, +{ "mode", S(MODE), 0, 5, "a", "axxo", (SUBR)modeset, NULL, (SUBR)mode } }; int biquad_init_(CSOUND *csound) @@ -1312,4 +1443,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/biquad.h csound-6.02~dfsg/Opcodes/biquad.h --- csound-5.17.11~dfsg/Opcodes/biquad.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/biquad.h 2014-01-07 16:54:20.000000000 +0000 @@ -24,7 +24,7 @@ */ /* biquad.h */ -#include "csdl.h" +#include "stdopcod.h" /* Structure for biquadratic filter */ typedef struct { @@ -121,6 +121,7 @@ typedef struct { OPDS h; MYFLT *aout, *ain, *kfreq, *kq, *reinit; - double xnm1, ynm1, ynm2; + double xnm1, ynm1, ynm2, a0, a1, a2, d; + MYFLT lfq,lq; } MODE; diff -Nru csound-5.17.11~dfsg/Opcodes/bowedbar.c csound-6.02~dfsg/Opcodes/bowedbar.c --- csound-5.17.11~dfsg/Opcodes/bowedbar.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/bowedbar.c 2014-01-07 16:53:47.000000000 +0000 @@ -90,14 +90,14 @@ if (*p->lowestFreq>=FL(0.0)) { /* If no init skip */ if (*p->lowestFreq!=FL(0.0)) - p->length = (int32) (csound->esr / *p->lowestFreq + FL(1.0)); + p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0)); else if (*p->frequency!=FL(0.0)) - p->length = (int32) (csound->esr / *p->frequency + FL(1.0)); + p->length = (int32) (CS_ESR / *p->frequency + FL(1.0)); else { csound->Warning(csound, Str("unknown lowest frequency for bowed bar -- " "assuming 50Hz\n")); - p->length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } } @@ -128,7 +128,9 @@ int bowedbar(CSOUND *csound, BOWEDBAR *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ int32 k; int i; @@ -141,7 +143,7 @@ p->freq = *p->frequency; if (p->freq > FL(1568.0)) p->freq = FL(1568.0); - p->length = (int)(csound->esr/p->freq); + p->length = (int)(CS_ESR/p->freq); p->nr_modes = NR_MODES; /* reset for frequency shift */ for (i = 0; ilength/p->modes[i]) > 4) @@ -184,7 +186,12 @@ } maxVelocity = FL(0.03) + (FL(0.5) * amp); - for (n=0; n #define ROOT2 (1.4142135623730950488) -static void butter_filter(int32, MYFLT *, MYFLT *, double *); +static void butter_filter(uint32_t, uint32_t, MYFLT *, MYFLT *, double *); -static int butset(CSOUND *csound, BFIL *p) /* Hi/Lo pass set-up */ +int butset(CSOUND *csound, BFIL *p) /* Hi/Lo pass set-up */ { if (*p->istor==FL(0.0)) { p->a[6] = p->a[7] = 0.0; @@ -55,26 +55,23 @@ return OK; } -static int bbutset(CSOUND *csound, BBFIL *p) /* Band set-up */ -{ - if (*p->istor==FL(0.0)) { - p->a[6] = p->a[7] = 0.0; - p->lkb = FL(0.0); - p->lkf = FL(0.0); - } - return OK; -} - static int hibut(CSOUND *csound, BFIL *p) /* Hipass filter */ { MYFLT *out, *in; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; in = p->ain; out = p->sr; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (*p->kfc <= FL(0.0)) { - int32 n = csound->ksmps; - memcpy(out, in, n*sizeof(MYFLT)); + memcpy(&out[offset], &in[offset], (nsmps-offset)*sizeof(MYFLT)); return OK; } @@ -91,25 +88,33 @@ a[4] = 2.0 * ( c*c - 1.0) * a[1]; a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; } - butter_filter(csound->ksmps, in, out, p->a); + butter_filter(nsmps, offset, in, out, p->a); return OK; } static int lobut(CSOUND *csound, BFIL *p) /* Lopass filter */ { MYFLT *out, *in; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; in = p->ain; out = p->sr; if (*p->kfc <= FL(0.0)) { - memset(out, 0, csound->ksmps*sizeof(MYFLT)); + memset(out, 0, nsmps*sizeof(MYFLT)); return OK; } - if (*p->kfc != p->lkf) { - double *a, c; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + if (*p->kfc != p->lkf) { + double *a, c; a = p->a; p->lkf = *p->kfc; c = 1.0 / tan((double)(csound->pidsr * p->lkf)); @@ -120,75 +125,19 @@ a[5] = ( 1.0 - ROOT2 * c + c * c) * a[1]; } - butter_filter(csound->ksmps, in, out, p->a); - return OK; -} - -static int bpbut(CSOUND *csound, BBFIL *p) /* Bandpass filter */ -{ - MYFLT *out, *in; - - in = p->ain; - out = p->sr; - if (*p->kbw <= FL(0.0)) { - memset(out, 0, csound->ksmps*sizeof(MYFLT)); - return OK; - } - if (*p->kbw != p->lkb || *p->kfo != p->lkf) { - double *a, c, d; - a = p->a; - p->lkf = *p->kfo; - p->lkb = *p->kbw; - c = 1.0 / tan((double)(csound->pidsr * p->lkb)); - d = 2.0 * cos((double)(csound->tpidsr * p->lkf)); - a[1] = 1.0 / (1.0 + c); - a[2] = 0.0; - a[3] = -a[1]; - a[4] = - c * d * a[1]; - a[5] = (c - 1.0) * a[1]; - } - butter_filter(csound->ksmps, in, out, p->a); - return OK; -} - -static int bcbut(CSOUND *csound, BBFIL *p) /* Band reject filter */ -{ - MYFLT *out, *in; - - in = p->ain; - out = p->sr; - - if (*p->kbw <= FL(0.0)) { - memcpy(out, in, csound->ksmps*sizeof(MYFLT)); - return OK; - } - - if (*p->kbw != p->lkb || *p->kfo != p->lkf) { - double *a, c, d; - - a = p->a; - p->lkf = *p->kfo; - p->lkb = *p->kbw; - c = tan((double)(csound->pidsr * p->lkb)); - d = 2.0 * cos((double)(csound->tpidsr * p->lkf)); - a[1] = 1.0 / (1.0 + c); - a[2] = - d * a[1]; - a[3] = a[1]; - a[4] = a[2]; - a[5] = (1.0 - c) * a[1]; - } - - butter_filter(csound->ksmps, in, out, p->a); + butter_filter(nsmps, offset, in, out, p->a); return OK; } /* Filter loop */ -static void butter_filter(int32 n, MYFLT *in, MYFLT *out, double *a) +static void butter_filter(uint32_t n, uint32_t offset, + MYFLT *in, MYFLT *out, double *a) { double t, y; - int nn; - for (nn=0; nnAppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/cellular.c csound-6.02~dfsg/Opcodes/cellular.c --- csound-5.17.11~dfsg/Opcodes/cellular.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cellular.c 2014-01-07 16:53:47.000000000 +0000 @@ -39,19 +39,20 @@ static int cell_set(CSOUND *csound,CELL *p) { FUNC *ftp; - int elements; + int elements=0; MYFLT *currLine, *initVec = NULL; if (LIKELY((ftp = csound->FTnp2Find(csound,p->ioutFunc)) != NULL)) { p->outVec = ftp->ftable; elements = (p->elements = (int) *p->ielements); - if (UNLIKELY( elements > ftp->flen )) + + if (UNLIKELY( elements > (int)ftp->flen )) return csound->InitError(csound, Str("cell: invalid num of elements")); } else return csound->InitError(csound, Str("cell: invalid output table")); if (LIKELY((ftp = csound->FTnp2Find(csound,p->initStateFunc)) != NULL)) { initVec = (p->initVec = ftp->ftable); - if (UNLIKELY(elements > ftp->flen )) + if (UNLIKELY(elements > (int)ftp->flen )) return csound->InitError(csound, Str("cell: invalid num of elements")); } else @@ -70,6 +71,8 @@ /* do { */ /* *currLine++ = *initVec++; */ /* } while (--elements); */ + + return OK; } @@ -85,12 +88,15 @@ if (*p->ktrig) { int j, elements = p->elements, jm1; MYFLT *actual, *previous, *outVec = p->outVec , *ruleVec = p->ruleVec; + previous = &(p->currLine[elements * p->NewOld]); p->NewOld += 1; p->NewOld %= 2; actual = &(p->currLine[elements * p->NewOld]); // Cellular Engine + for (j=0; j < elements; j++) { + jm1 = (j < 1) ? elements-1 : j-1; outVec[j] = previous[j]; actual[j] = ruleVec[(int)(previous[jm1]*4 + previous[j]*2 + @@ -112,7 +118,7 @@ #define S sizeof static OENTRY localops[] = { - {"cell", S(CELL), 3|TB, "", "kkiiii",(SUBR)cell_set, (SUBR)cell } + {"cell", S(CELL), TB, 3, "", "kkiiii",(SUBR)cell_set, (SUBR)cell } }; LINKAGE diff -Nru csound-5.17.11~dfsg/Opcodes/chua/ChuaOscillator.cpp csound-6.02~dfsg/Opcodes/chua/ChuaOscillator.cpp --- csound-5.17.11~dfsg/Opcodes/chua/ChuaOscillator.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/chua/ChuaOscillator.cpp 2014-01-07 16:53:47.000000000 +0000 @@ -122,6 +122,9 @@ using namespace boost::numeric; #include +#undef CS_KSMPS +#define CS_KSMPS (opds.insdshead->ksmps) + class ChuasOscillatorCubic : public OpcodeBase { public: @@ -172,7 +175,7 @@ public: int init(CSOUND *csound) { - if (!csound->reinitflag && !csound->tieflag) { + if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { csound->RegisterDeinitCallback(csound, this, ¬eoff_); } // h = step_size; %*(G/C2); @@ -206,7 +209,7 @@ b = 0.0; c = -0.00121; d = 0.0; - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; warn(csound, "ChuasOscillatorCubic::init: L: %f R0: %f C2: %f G: %f" " C1: %f V1: %f V2: %f I3: %f step: %f\n", *L_, *R0_, *C2_, *G_, *C1_, M(1), M(2), M(3), h); @@ -234,6 +237,19 @@ // probaby by design. This is very handy and should prevent mistakes. // Start with aliases for the Csound inputs, in order // to preserve the clarity of the original code. + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + if (UNLIKELY(offset)) { + memset(I3, '\0', offset*sizeof(MYFLT)); + memset(V1, '\0', offset*sizeof(MYFLT)); + memset(V2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + memset(&I3[nsmps-early], '\0', early*sizeof(MYFLT)); + memset(&V1[nsmps-early], '\0', early*sizeof(MYFLT)); + memset(&V2[nsmps-early], '\0', early*sizeof(MYFLT)); + } MYFLT &L = *L_; MYFLT &R0 = *R0_; MYFLT &C2 = *C2_; @@ -422,7 +438,7 @@ size_t ksmps; int init(CSOUND *csound) { - if (!csound->reinitflag && !csound->tieflag) { + if (!csound->GetReinitFlag(csound) && !csound->GetTieFlag(csound)) { csound->RegisterDeinitCallback(csound, this, ¬eoff_); } // NOTE: The original MATLAB code uses 1-based indexing. @@ -444,7 +460,7 @@ M(2) = *V2_ / *E_; // M(3) = TimeSeries(1)/(E*G); M(3) = *I3_ / (*E_ * *G_); - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; warn(csound, "ChuasOscillatorPiecewise::init: L: %f R0: %f C2: %f G: " "%f Ga: %f Gb: %f E: %f C1: %f M(1): %f M(2):" " %f M(3): %f step: %f\n", @@ -472,6 +488,19 @@ // probaby by design. This is very handy and should prevent mistakes. // Start with aliases for the Csound inputs, in order // to preserve the clarity of the original code. + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + if (UNLIKELY(offset)) { + memset(I3, '\0', offset*sizeof(MYFLT)); + memset(V1, '\0', offset*sizeof(MYFLT)); + memset(V2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + ksmps -= early; + memset(&I3[ksmps], '\0', early*sizeof(MYFLT)); + memset(&V1[ksmps], '\0', early*sizeof(MYFLT)); + memset(&V2[ksmps], '\0', early*sizeof(MYFLT)); + } MYFLT &L = *L_; MYFLT &R0 = *R0_; MYFLT &C2 = *C2_; @@ -512,7 +541,7 @@ // omch2 = 1 - ch2; omch2 = 1.0 - ch2; // Standard 4th-order Runge-Kutta integration. - for (size_t i = 0; i < ksmps; i++) { + for (size_t i = offset; i < ksmps; i++) { // Stage 1. k1(1) = alpha*(M(2) - bnorplus1*M(1) - (.5)*(anor - bnor)*(abs(M(1) + 1) - abs(M(1) - 1))); @@ -556,6 +585,7 @@ // { // (char*)"chuac", // sizeof(ChuasOscillatorCubic), +// 0, // 5, // // kL, kR0, kC2, kG, kC1, iI3, iV2, iV1, kstep_size // // 0.00945, 7.5, 2e-007, 0.00105, 1.5e-008, 0, -0.1, 0.1, 5e-6 @@ -568,6 +598,7 @@ { (char*)"chuap", sizeof(ChuasOscillatorPiecewise), + 0, 5, // kL, kR0, kC2, kG, kGa, kGb, kE, kC1, // iI3, iV2, iV1, kstep_size @@ -588,6 +619,7 @@ 0, 0, 0, + 0, } }; @@ -602,7 +634,8 @@ for(OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) { status |= csound->AppendOpcode(csound, oentry->opname, - oentry->dsblksiz, oentry->thread, + oentry->dsblksiz, oentry->flags, + oentry->thread, oentry->outypes, oentry->intypes, (int (*)(CSOUND*,void*)) oentry->iopadr, (int (*)(CSOUND*,void*)) oentry->kopadr, diff -Nru csound-5.17.11~dfsg/Opcodes/clfilt.c csound-6.02~dfsg/Opcodes/clfilt.c --- csound-5.17.11~dfsg/Opcodes/clfilt.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/clfilt.c 2014-01-07 16:53:47.000000000 +0000 @@ -32,8 +32,9 @@ /* bilinear z-transform. */ /* April/May 2002 by Erik Spjut */ /***************************************************************/ -#include "csdl.h" + #include +#include "stdopcod.h" #include "clfilt.h" static int clfiltset(CSOUND *csound, CLFILT *p) @@ -289,7 +290,9 @@ static int clfilt(CSOUND *csound, CLFILT *p) { - int n, nsmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int m, nsec; MYFLT *out, *in; MYFLT xn[CL_LIM+1], yn[CL_LIM]; @@ -338,11 +341,12 @@ } break; case 3: /* Lowpass Elliptical */ - return csound->PerfError(csound, Str("Lowpass Elliptical " + return csound->PerfError(csound, p->h.insdshead, + Str("Lowpass Elliptical " "not implemented yet. Sorry!")); break; default: /* Because of earlier contditionals, should never get here. */ - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("code error, ikind out of range")); } break; @@ -375,22 +379,28 @@ } break; case 3: /* Highpass Elliptical */ - return csound->PerfError(csound, Str("Highpass Elliptical " - "not implemented yet. Sorry!")); + return csound->PerfError(csound, p->h.insdshead, + Str("Highpass Elliptical " + "not implemented yet. Sorry!")); break; default: /* Because of earlier contditionals, should never get here. */ - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("code error, ikind out of range")); } break; default: /* Because of earlier conditionals, should never get here. */ - return csound->PerfError(csound, Str("code error, ihilo out of range")); + return csound->PerfError(csound, p->h.insdshead, + Str("code error, ihilo out of range")); } } - nsmps = csound->ksmps; in = p->in; out = p->out; - for (n=0; ncuratt = (MYFLT) MAXPOS; p->currls = (MYFLT) MAXPOS; /* round to nearest integer */ - if ((delsmps = MYFLT2LONG(*p->ilook * csound->esr)) <= 0L) + if ((delsmps = MYFLT2LONG(*p->ilook * csound->GetSr(csound))) <= 0L) delsmps = 1L; /* alloc 2 delay bufs */ csound->AuxAlloc(csound, delsmps * 2 * sizeof(MYFLT), &p->auxch); p->abuf = (MYFLT *)p->auxch.auxp; @@ -77,9 +77,12 @@ static int compress(CSOUND *csound, CMPRS *p) { MYFLT *ar, *ainp, *cinp; - int32 nsmps = csound->ksmps; - int n; - MYFLT scal = 32768./csound->e0dbfs; /* VL: scale by 0dbfs, code is tuned to work in 16bit range */ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + /* VL: scale by 0dbfs, code is tuned to work in 16bit range */ + MYFLT scal = FL(32768.0)/csound->e0dbfs; if (*p->kthresh != p->thresh) { /* check for changes: */ p->thresh = *p->kthresh; @@ -123,14 +126,19 @@ ar = p->ar; ainp = p->aasig; cinp = p->acsig; - for (n=0; naptr; /* get signals from delay line */ csig = *p->cptr; *p->aptr = ainp[n]*scal; /* & replace with incoming */ - if ((lsig = cinp[n]*scal) < FL(0.0)) - lsig = -lsig; /* made abs for control */ + lsig = FABS(cinp[n]*scal); + //lsig = -lsig; /* made abs for control */ *p->cptr = lsig; if (p->cptr == p->lmaxp) { /* if prev ctrl was old lamax */ MYFLT *lap, newmax = FL(0.0); @@ -189,7 +197,7 @@ double b; FUNC *ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) return NOTOK; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; p->ftp = ftp; p->maxphs = (MYFLT)ftp->flen; /* set ftable params */ p->midphs = p->maxphs * FL(0.5); @@ -212,12 +220,13 @@ MYFLT *ar, *asig; MYFLT q, rms, dist, dnew, dcur, dinc; FUNC *ftp = p->ftp; - int32 nsmps = csound->ksmps; - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; asig = p->asig; q = p->prvq; - for (n=0; nc1 * asig[n] * asig[n] + p->c2 * q; } p->prvq = q; @@ -228,10 +237,15 @@ dist = FL(0.001); dnew = rms / dist; /* & compress factor */ dcur = p->prvd; - dinc = (dnew - dcur) * csound->onedksmps; asig = p->asig; ar = p->ar; - for (n=0; nmidphs * (FL(1.0) + sig); /* as index into table */ @@ -257,11 +271,10 @@ #define S(x) sizeof(x) static OENTRY compress_localops[] = { - { "compress", S(CMPRS), 5, "a", "aakkkkkki", + { "compress", S(CMPRS), 0, 5, "a", "aakkkkkki", (SUBR) compset, NULL, (SUBR) compress }, - { "distort", S(DIST), TR|5, "a", "akiqo", + { "distort", S(DIST), TR, 5, "a", "akiqo", (SUBR) distset, NULL, (SUBR) distort }, }; -LINKAGE1(compress_localops) - +LINKAGE_BUILTIN(compress_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/control.c csound-6.02~dfsg/Opcodes/control.c --- csound-5.17.11~dfsg/Opcodes/control.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/control.c 2014-01-07 16:53:47.000000000 +0000 @@ -28,6 +28,10 @@ #include #include +#if defined(__MACH__) +#include +#endif + static CS_NOINLINE CONTROL_GLOBALS *get_globals_(CSOUND *csound) { CONTROL_GLOBALS *p; @@ -36,8 +40,10 @@ if (p != NULL) return p; if (csound->CreateGlobalVariable(csound, "controlGlobals_", - sizeof(CONTROL_GLOBALS)) != 0) - csound->Die(csound, Str("control: failed to allocate globals")); + sizeof(CONTROL_GLOBALS)) != 0){ + csound->Warning(csound, Str("control: failed to allocate globals")); + return NULL; + } p = (CONTROL_GLOBALS*) csound->QueryGlobalVariable(csound, "controlGlobals_"); p->csound = csound; @@ -179,7 +185,7 @@ return OK; } -static int ocontrol(CSOUND *csound, SCNTRL *p) +static int ocontrol_(CSOUND *csound, SCNTRL *p, int istring) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int c = (int) *p->which; @@ -207,7 +213,12 @@ case 4: { char buffer[100]; - csound->strarg2name(csound, buffer, p->val, "Control ", p->XSTRCODE); + if(istring) { + csound->strarg2name(csound, buffer, + ((STRINGDAT *)p->val)->data, "Control ",istring); + } + else + csound->strarg2name(csound, buffer, p->val, "Control ",istring); csound->Message(csound, Str("Slider %d set to %s\n"), slider, buffer); fprintf(pp->wish_cmd, "setlab %d \"%s\"\n", slider, buffer); break; @@ -218,6 +229,14 @@ return OK; } +static int ocontrol(CSOUND *csound, SCNTRL *p){ + return ocontrol_(csound,p,0); +} + +static int ocontrol_S(CSOUND *csound, SCNTRL *p){ + return ocontrol_(csound,p,1); +} + static int button_set(CSOUND *csound, CNTRL *p) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); @@ -272,7 +291,7 @@ /* **** Text Windows **** */ -static int textflash(CSOUND *csound, TXTWIN *p) +static int textflash_(CSOUND *csound, TXTWIN *p, int istring) { CONTROL_GLOBALS *pp = get_globals(csound, &(p->p)); int wind = (int) MYFLT2LONG(*p->kcntl); @@ -280,11 +299,15 @@ if (pp->wish_pid == 0) start_tcl_tk(pp); - if (p->XSTRCODE || *p->val == SSTRCOD) { - csound->strarg2name(csound, buffer, p->val, "", p->XSTRCODE); + if (istring) { + csound->strarg2name(csound, buffer, ((STRINGDAT *)p->val)->data, "", istring); /* csound->Message(csound, "settext %d \"%s\"\n", wind, buffer); */ fprintf(pp->wish_cmd, "settext %d \"%s\"\n", wind, buffer); } + else if(ISSTRCOD(*p->val)) { + csound->strarg2name(csound, buffer, + csound->GetString(csound, *p->val), "", 1); + } else { /* csound->Message(csound, "deltext %d\n", wind); */ fprintf(pp->wish_cmd, "deltext %d\n", wind); @@ -292,15 +315,25 @@ return OK; } +static int textflash(CSOUND *csound, TXTWIN *p){ + return textflash_(csound, p, 0); +} + +static int textflash_S(CSOUND *csound, TXTWIN *p){ + return textflash_(csound, p, 1); +} + + #define S(x) sizeof(x) static OENTRY control_localops[] = { -{ "control", S(CNTRL), 3, "k", "k", (SUBR) cntrl_set, (SUBR) control, NULL }, -{ "setctrl", S(SCNTRL), 1, "", "iTi", (SUBR) ocontrol, NULL, NULL }, -{ "button", S(CNTRL), 3, "k", "k", (SUBR) button_set, (SUBR) button, NULL }, -{ "checkbox", S(CNTRL), 3, "k", "k", (SUBR) check_set, (SUBR) check, NULL }, -{ "flashtxt", S(TXTWIN), 1, "", "iT", (SUBR) textflash, NULL, NULL }, + { "control", S(CNTRL), 0, 3, "k", "k", (SUBR) cntrl_set, (SUBR) control, NULL }, +{ "setctrl", S(SCNTRL), 0, 1, "", "iii", (SUBR) ocontrol, NULL, NULL }, +{ "setctrl.S", S(SCNTRL), 0, 1, "", "iSi", (SUBR) ocontrol_S, NULL, NULL }, +{ "button", S(CNTRL), 0, 3, "k", "k", (SUBR) button_set, (SUBR) button, NULL }, +{ "checkbox", S(CNTRL), 0, 3, "k", "k", (SUBR) check_set, (SUBR) check, NULL }, +{ "flashtxt", S(TXTWIN), 0, 1, "", "ii", (SUBR) textflash, NULL, NULL }, +{ "flashtxt.S", S(TXTWIN), 0, 1, "", "iS", (SUBR) textflash_S, NULL, NULL }, }; -LINKAGE1(control_localops) - +LINKAGE_BUILTIN(control_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/cpumeter.c csound-6.02~dfsg/Opcodes/cpumeter.c --- csound-5.17.11~dfsg/Opcodes/cpumeter.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cpumeter.c 2014-01-07 16:53:48.000000000 +0000 @@ -53,7 +53,7 @@ MYFLT *k0, *kk[8], *itrig; AUXCH cpu_a; CPU_t *cpus; - int cpu_max; + uint32_t cpu_max; int cnt, trig; FILE *fp; } CPUMETER; @@ -82,7 +82,7 @@ for (k = 0; ; k++) { if (!fgets(buf, SMLBUFSIZ, p->fp)) return csound->InitError(csound,Str("failed /proc/stat read")); - num = sscanf(buf, "cpu%u %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", + num = sscanf(buf, "cpu%llu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", &id, &u, &n, &s, &i, &w, &x, &y, &z); if (num<4) break; } @@ -90,7 +90,7 @@ csound->AuxAlloc(csound,k*sizeof(CPU_t), &(p->cpu_a)); p->cpus = (CPU_t *) p->cpu_a.auxp; k = cpupercent_renew(csound, p); - p->cnt = (p->trig = (int)(*p->itrig * csound->esr)); + p->cnt = (p->trig = (int)(*p->itrig * csound->GetSr(csound))); return k; } @@ -100,7 +100,7 @@ SIC_t u_frme, s_frme, n_frme, i_frme, w_frme, x_frme, y_frme, z_frme, tot_frme, tz; double scale; - int k, num; + uint32_t k; CPU_t *cpu = p->cpus; char buf[SMLBUFSIZ]; @@ -108,10 +108,11 @@ fflush(p->fp); k = p->cpu_max; if (!fgets(buf, SMLBUFSIZ, p->fp)) - return csound->PerfError(csound,Str("failed /proc/stat read")); - num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", - &cpu[k].u, &cpu[k].n, &cpu[k].s, &cpu[k].i, - &cpu[k].w, &cpu[k].x, &cpu[k].y, &cpu[k].z); + return csound->PerfError(csound, p->h.insdshead, + Str("failed /proc/stat read")); + /*num = */sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", + &cpu[k].u, &cpu[k].n, &cpu[k].s, &cpu[k].i, + &cpu[k].w, &cpu[k].x, &cpu[k].y, &cpu[k].z); u_frme = cpu[k].u - cpu[k].u_sav; s_frme = cpu[k].s - cpu[k].s_sav; n_frme = cpu[k].n - cpu[k].n_sav; @@ -148,10 +149,11 @@ for (k=0; kcpu_max && k+1OUTOCOUNT; k++) { if (!fgets(buf, SMLBUFSIZ, p->fp)) - return csound->PerfError(csound,Str("failed /proc/stat read")); - num = sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", - &cpu[k].u, &cpu[k].n, &cpu[k].s, &cpu[k].i, - &cpu[k].w, &cpu[k].x, &cpu[k].y, &cpu[k].z); + return csound->PerfError(csound, p->h.insdshead, + Str("failed /proc/stat read")); + /*num = */ (void)sscanf(buf, "cpu %Lu %Lu %Lu %Lu %Lu %Lu %Lu %Lu", + &cpu[k].u, &cpu[k].n, &cpu[k].s, &cpu[k].i, + &cpu[k].w, &cpu[k].x, &cpu[k].y, &cpu[k].z); u_frme = cpu[k].u - cpu[k].u_sav; s_frme = cpu[k].s - cpu[k].s_sav; n_frme = cpu[k].n - cpu[k].n_sav; @@ -160,7 +162,8 @@ x_frme = cpu[k].x - cpu[k].x_sav; y_frme = cpu[k].y - cpu[k].y_sav; z_frme = cpu[k].z - cpu[k].z_sav; - tot_frme = u_frme + s_frme + n_frme + i_frme + w_frme + x_frme + y_frme + z_frme; + tot_frme = u_frme + s_frme + n_frme + i_frme + + w_frme + x_frme + y_frme + z_frme; if (tot_frme < 1) tot_frme = 1; scale = 100.0 / (double)tot_frme; //if (p->kk[k]==NULL) break; @@ -192,7 +195,7 @@ } static int cpupercent(CSOUND *csound, CPUMETER* p) { - p->cnt -= csound->ksmps; + p->cnt -= CS_KSMPS; if (p->cnt< 0) { int n = cpupercent_renew(csound, p); p->cnt = p->trig; @@ -204,10 +207,10 @@ #define S(x) sizeof(x) static OENTRY cpumeter_localops[] = { - { "cpumeter", S(CPUMETER), 5, "kzzzzzzzz", "i", + { "cpumeter", S(CPUMETER), 0,5, "kzzzzzzzz", "i", (SUBR)cpupercent_init, (SUBR)cpupercent, NULL }, }; -LINKAGE1(cpumeter_localops) +LINKAGE_BUILTIN(cpumeter_localops) #endif diff -Nru csound-5.17.11~dfsg/Opcodes/cross2.c csound-6.02~dfsg/Opcodes/cross2.c --- csound-5.17.11~dfsg/Opcodes/cross2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cross2.c 2014-01-07 16:53:48.000000000 +0000 @@ -308,7 +308,7 @@ static int Xsynthset(CSOUND *csound, CON *p) { - int32 flen, bufsize; + uint32_t flen, bufsize; MYFLT *b; FUNC *ftp; MYFLT ovlp = *p->ovlp; @@ -335,7 +335,7 @@ p->in1 = b; b += 2 * flen; p->in2 = b; b += 2 * flen; - if ((ftp = csound->FTFind(csound, p->iwin)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iwin)) != NULL) p->win = ftp; else return NOTOK; @@ -347,8 +347,11 @@ static int Xsynth(CSOUND *csound, CON *p) { MYFLT *s, *f, *out, *buf1, *buf2, *outbuf, rfn; - int32 n, size, samps, div; - int32 m; + int32 size, div; + int32 n, m; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; s = p->as; f = p->af; @@ -364,11 +367,16 @@ n = p->count; m = n % div; - for (samps = 0; samps < csound->ksmps; samps++) { - buf1[n] = s[samps]; - buf2[n] = f[samps]; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (nn = offset; nn < nsmps; nn++) { + buf1[n] = s[nn]; + buf2[n] = f[nn]; - out[samps] = outbuf[n]; + out[nn] = outbuf[n]; n++; m++; if (n == size) n = 0; /* Moved to here from inside loop */ if (m == div) { /* wrap */ @@ -430,7 +438,7 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "cross2", S(CON), TR|5, "a", "aaiiik",(SUBR)Xsynthset, NULL, (SUBR)Xsynth} +{ "cross2", S(CON), TR, 5, "a", "aaiiik",(SUBR)Xsynthset, NULL, (SUBR)Xsynth} }; int cross2_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/crossfm.c csound-6.02~dfsg/Opcodes/crossfm.c --- csound-5.17.11~dfsg/Opcodes/crossfm.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/crossfm.c 2014-01-07 16:53:48.000000000 +0000 @@ -28,8 +28,8 @@ int xfmset(CSOUND *csound, CROSSFM *p) { - FUNC *ftp1 = csound->FTFind(csound, p->ifn1); - FUNC *ftp2 = csound->FTFind(csound, p->ifn2); + FUNC *ftp1 = csound->FTnp2Find(csound, p->ifn1); + FUNC *ftp2 = csound->FTnp2Find(csound, p->ifn2); if (UNLIKELY(ftp1 == NULL || ftp2 == NULL)) { return csound->InitError(csound, Str("crossfm: ftable not found")); } @@ -62,8 +62,10 @@ MYFLT *tbl1, *tbl2; MYFLT phase1, phase2; MYFLT sig1, sig2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -83,7 +85,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; si1 = (frq1 + *xndx2 * frq2 * sig2) * k; @@ -122,8 +133,10 @@ MYFLT phase1, phase2; MYFLT sig1, sig2; MYFLT x, y1, y2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -143,7 +156,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; si1 = (frq1 + *xndx2 * frq2 * sig2) * k; @@ -185,8 +207,10 @@ MYFLT *tbl1, *tbl2; MYFLT phase1, phase2; MYFLT sig1, sig2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -206,7 +230,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; out1[i] = sig1; @@ -245,8 +278,10 @@ MYFLT phase1, phase2; MYFLT sig1, sig2; MYFLT x, y1, y2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -266,7 +301,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; out1[i] = sig1; @@ -308,8 +352,10 @@ MYFLT *tbl1, *tbl2; MYFLT phase1, phase2; MYFLT sig1, sig2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -329,7 +375,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; out1[i] = sig1; @@ -368,8 +423,10 @@ MYFLT phase1, phase2; MYFLT sig1, sig2; MYFLT x, y1, y2; - int i, n1, n2; - int nsmps = csound->ksmps; + int n1, n2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; out1 = p->aout1; out2 = p->aout2; @@ -389,7 +446,16 @@ sig1 = p->sig1; sig2 = p->sig2; - for (i = 0; i < nsmps; i++) { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { frq1 = *xfrq1 * cps; frq2 = *xfrq2 * cps; out1[i] = sig1; @@ -424,14 +490,15 @@ #define S sizeof static OENTRY crossfm_localops[] = { - { "crossfm", S(CROSSFM), TR|5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xfm }, - { "crossfmi", S(CROSSFM), TR|5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xfmi }, - { "crosspm", S(CROSSFM), TR|5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xpm }, - { "crosspmi", S(CROSSFM), TR|5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xpmi }, - { "crossfmpm", S(CROSSFM), TR|5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xfmpm }, - { "crossfmpmi", S(CROSSFM),TR| 5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xfmpmi }, + { "crossfm", S(CROSSFM), TR, 5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xfm }, + { "crossfmi", S(CROSSFM), TR, 5, "aa", "xxxxkiioo",(SUBR)xfmset,NULL, (SUBR)xfmi }, + { "crosspm", S(CROSSFM), TR, 5, "aa", "xxxxkiioo", (SUBR)xfmset, NULL, (SUBR)xpm }, + { "crosspmi", S(CROSSFM), TR, 5, "aa", "xxxxkiioo",(SUBR)xfmset,NULL, (SUBR)xpmi }, + { "crossfmpm", S(CROSSFM), TR, 5, "aa", "xxxxkiioo",(SUBR)xfmset,NULL,(SUBR)xfmpm}, + { "crossfmpmi", S(CROSSFM),TR, 5, "aa", "xxxxkiioo", + (SUBR)xfmset, NULL, (SUBR)xfmpmi }, }; -LINKAGE1(crossfm_localops) +LINKAGE_BUILTIN(crossfm_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/adsyn.cu csound-6.02~dfsg/Opcodes/cuda/adsyn.cu --- csound-5.17.11~dfsg/Opcodes/cuda/adsyn.cu 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/adsyn.cu 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,311 @@ +// -*- c++ -*- +// adsyn.cu +// experimental cuda opcodes +// +// V Lazzarini, 2013 + +#include +#include +#define VSAMPS 16 +#define MAXBLOCK 8192 + +#define PFRACLO(x) ((MYFLT)((x) & lomask) * lodiv) + +__global__ void component(MYFLT *out, int *ndx, MYFLT *tab, + float *amp, int *inc, int vsize, + int blocks, int lobits, MYFLT lodiv, + int lomask) { + + int h = threadIdx.x*blocks + blockIdx.x; + int i, offset, n, lndx; + + offset = h*vsize; + out += offset; + + for(i=0; i < vsize; i++) { + lndx = ndx[h]; + n = lndx >> lobits; + out[i] = amp[h]*(tab[n] + PFRACLO(lndx)*(tab[n+1] - tab[n])); + ndx[h] = (lndx + inc[h]) & PHMASK; + } + +} + +__global__ void mixdown(MYFLT *out, int comps, int vsize, float kamp){ + int h = threadIdx.x; + int i; + for(i=0; i < comps; i++) + out[h] += out[h + vsize*i]; + out[h] *= kamp; +} + + + +static int destroy_cudaop(CSOUND *csound, void *pp); + +typedef struct cudaop_ { + OPDS h; + MYFLT *asig; + MYFLT *kamp, *kfreq, *itabn; + MYFLT *ftabn, *atabn, *inum; + MYFLT *out; + float *amp; + MYFLT *tab; + int *ndx, *inc; + MYFLT *ap, *fp; + FUNC *itab, *ftab, *atab; + int N, blocks; +} CUDAOP; + +static int init_cudaop(CSOUND *csound, CUDAOP *p){ + + int a, b, asize, ipsize, fpsize, tsize; + int nsmps = CS_KSMPS; + if(nsmps > 1024) return csound->InitError(csound, "ksmps is too large\n"); + + if((p->itab = + csound->FTFind(csound, p->itabn))== NULL) + return csound->InitError(csound, + "could not find table %.0f\n", *p->itabn); + + if((p->ftab = + csound->FTnp2Find(csound, p->ftabn))== NULL) + return csound->InitError(csound, + "could not find table %.0f\n", *p->ftabn); + + if((p->atab = + csound->FTnp2Find(csound, p->atabn))== NULL) + return csound->InitError(csound, + "could not find table %.0f\n", *p->atabn); + + a = p->ftab->flen; + b = p->atab->flen; + p->N = a < b ? a : b; + + if(*p->inum > 0 && *p->inum < p->N) p->N = *p->inum; + + p->blocks = p->N > 1024 ? p->N/1024 : 1; + + asize = p->N*nsmps*sizeof(MYFLT); + ipsize = p->N*sizeof(int); + fpsize = p->N*sizeof(float); + tsize = (p->itab->flen+1)*sizeof(MYFLT); + + cudaMalloc(&p->out, asize); + cudaMalloc(&p->ndx, ipsize); + cudaMalloc(&p->amp, fpsize); + cudaMalloc(&p->inc, ipsize); + cudaMalloc(&p->tab, tsize); + cudaMemset(p->ndx, 0, ipsize); + cudaMemcpy(p->tab, p->itab->ftable, tsize, cudaMemcpyHostToDevice); + + p->ap = p->atab->ftable; + p->fp = p->ftab->ftable; + + csound->RegisterDeinitCallback(csound, p, destroy_cudaop); + csound->Message(csound, "%d threads, %d blocks\n", p->N, p->blocks); + return OK; +} + +static void update_params(CSOUND *csound, CUDAOP *p){ + + int ipsize = p->N*sizeof(int); + int fpsize = p->N*sizeof(float); + float amp[MAXBLOCK]; + int inc[MAXBLOCK], i, j; + int N = p->N > MAXBLOCK ? MAXBLOCK : p->N; + + for(j=0; N > 0; j++, N = p->N - N) { + for(i=0;i < N; i++){ + amp[i] = p->ap[i]; + inc[i] = *p->kfreq*p->fp[i]*FMAXLEN/csound->GetSr(csound); + } + cudaMemcpy(&p->amp[N*j],amp,fpsize, cudaMemcpyHostToDevice); + cudaMemcpy(&p->inc[N*j],inc,ipsize, cudaMemcpyHostToDevice); + } + +} + +static int perf_cudaop(CSOUND *csound, CUDAOP *p){ + + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + p->ap = p->atab->ftable; + p->fp = p->ftab->ftable; + + if (UNLIKELY(offset)) memset(p->asig, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&(p->asig[nsmps]), '\0', early*sizeof(MYFLT)); + } + + update_params(csound, p); + component<<blocks, + p->N/p->blocks>>>(p->out,p->ndx, + p->tab,p->amp, + p->inc,nsmps, + p->blocks, + p->itab->lobits, + p->itab->lodiv, + p->itab->lomask); + mixdown<<<1,nsmps>>>(p->out,p->N,nsmps,*p->kamp); + cudaMemcpy(p->asig,p->out,nsmps*sizeof(MYFLT),cudaMemcpyDeviceToHost); + + return OK; +} + +static int destroy_cudaop(CSOUND *csound, void *pp){ + CUDAOP *p = (CUDAOP *) pp; + cudaFree(p->out); + cudaFree(p->ndx); + cudaFree(p->tab); + cudaFree(p->amp); + cudaFree(p->inc); + return OK; +} + + +#include + +typedef struct cudaop2_ { + OPDS h; + MYFLT *asig; + PVSDAT *fsig; + MYFLT *kamp, *kfreq, *itabn; + MYFLT *inum; + MYFLT *out; + float *amp; + MYFLT *tab; + int *ndx, *inc; + float *fp; + AUXCH out_; + FUNC *itab; + int N, blocks; + int count; + int vsamps; + int framecount; +} CUDAOP2; + +static int destroy_cudaop2(CSOUND *csound, void *pp); + +static int init_cudaop2(CSOUND *csound, CUDAOP2 *p){ + + int asize, ipsize, fpsize, tsize; + if(p->fsig->overlap > 1024) + return csound->InitError(csound, "overlap is too large\n"); + + if((p->itab = + csound->FTFind(csound, p->itabn))== NULL) + return csound->InitError(csound, + "could not find table %.0f\n", *p->itabn); + p->N = (p->fsig->N)/2; + + if(*p->inum > 0 && *p->inum < p->N) p->N = *p->inum; + + p->blocks = p->N > 1024 ? p->N/1024 : 1; + p->vsamps = p->fsig->overlap < VSAMPS ? VSAMPS : p->fsig->overlap; + + asize = p->N*p->vsamps*sizeof(MYFLT); + ipsize = p->N*sizeof(int); + fpsize = p->N*sizeof(float); + tsize = (p->itab->flen+1)*sizeof(MYFLT); + + cudaMalloc(&p->out, asize); + cudaMalloc(&p->ndx, ipsize); + cudaMalloc(&p->amp, fpsize); + cudaMalloc(&p->inc, ipsize); + cudaMalloc(&p->tab, tsize); + cudaMemset(p->ndx, 0, ipsize); + cudaMemcpy(p->tab,p->itab->ftable,tsize, cudaMemcpyHostToDevice); + + asize = p->vsamps*sizeof(MYFLT); + if(p->out_.auxp == NULL || + p->out_.size < asize) + csound->AuxAlloc(csound, asize , &p->out_); + + csound->RegisterDeinitCallback(csound, p, destroy_cudaop2); + p->count = 0; + + csound->Message(csound, "%d threads, %d blocks\n", p->N, p->blocks); + + return OK; +} + +static void update_params2(CSOUND *csound, CUDAOP2 *p){ + + int ipsize = p->N*sizeof(int); + int fpsize = p->N*sizeof(float); + float amp[MAXBLOCK]; + int inc[MAXBLOCK], i, j, k; + int N = p->N > MAXBLOCK ? MAXBLOCK : p->N; + + for(k=0; N > 0; k++, N = p->N - N) { + for(j=i=0;i < N; i++, j+=2){ + amp[i] = p->fp[j]; + inc[i] = MYFLT2LONG(*p->kfreq * p->fp[j+1]*FMAXLEN/csound->GetSr(csound)); + } + cudaMemcpy(&p->amp[k*N],amp,fpsize, cudaMemcpyHostToDevice); + cudaMemcpy(&p->inc[k*N],inc,ipsize, cudaMemcpyHostToDevice); + } +} + +static int perf_cudaop2(CSOUND *csound, CUDAOP2 *p){ + + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *out_ = (MYFLT *) p->out_.auxp; + MYFLT *asig = p->asig; + int count = p->count, vsamps = p->vsamps; + p->fp = (float *) (p->fsig->frame.auxp); + + if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for(n=offset; n < nsmps; n++){ + if(count == 0) { + update_params2(csound, p); + component<<blocks, + p->N/p->blocks>>>(p->out,p->ndx, + p->tab,p->amp, + p->inc,p->vsamps, + p->blocks, + p->itab->lobits, + p->itab->lodiv, + p->itab->lomask); + mixdown<<<1,vsamps>>>(p->out,p->N,vsamps,*p->kamp); + cudaMemcpy(out_,p->out,vsamps*sizeof(MYFLT),cudaMemcpyDeviceToHost); + count = vsamps; + } + asig[n] = (MYFLT) out_[vsamps - count]; + count--; + } + p->count = count; + return OK; +} + +static int destroy_cudaop2(CSOUND *csound, void *pp){ + CUDAOP2 *p = (CUDAOP2 *) pp; + cudaFree(p->out); + cudaFree(p->ndx); + cudaFree(p->tab); + cudaFree(p->amp); + cudaFree(p->inc); + return OK; +} + + +static OENTRY localops[] = { + {"cudasynth", sizeof(CUDAOP),0, 5, "a", "kkiiio", (SUBR) init_cudaop, NULL, + (SUBR) perf_cudaop}, + {"cudasynth", sizeof(CUDAOP2),0, 5, "a", "fkkio", (SUBR) init_cudaop2, NULL, + (SUBR) perf_cudaop2} +}; + +extern "C" { + LINKAGE +} diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/build.sh csound-6.02~dfsg/Opcodes/cuda/build.sh --- csound-5.17.11~dfsg/Opcodes/cuda/build.sh 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/build.sh 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,5 @@ +#!/bin/sh +echo "building cuda opcodes ..." +nvcc -O3 -shared -o libcudaop1.dylib adsyn.cu -DUSE_DOUBLE -I../../include -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft +nvcc -O3 -shared -o libcudaop2.dylib pvsops.cu -DUSE_DOUBLE -I../../include -arch=sm_30 -I/usr/local/cuda/include -L/usr/local/cuda/lib -lcufft +echo "...done" \ No newline at end of file diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/cuda_pvs_example.csd csound-6.02~dfsg/Opcodes/cuda/cuda_pvs_example.csd --- csound-5.17.11~dfsg/Opcodes/cuda/cuda_pvs_example.csd 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/cuda_pvs_example.csd 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,51 @@ + + +--opcode-lib=./libcudaop2.dylib + + + +ksmps = 64 +0dbfs = 1 + +instr 1 +ifftsize = 2048 +asig diskin2 "flutec3.wav", 1, 0, 1 +fsig cudanal asig, ifftsize, ifftsize/8, ifftsize, 1 +a1 pvsynth fsig +a2 linenr a1*0.5,0.005,0.01,0.01 + out a2 +endin + +instr 2 +ifftsize = 2048 +asig diskin2 "flutec3.wav", 1, 0, 1 +fsig pvsanal asig, ifftsize, ifftsize/8, ifftsize, 1 +a1 cudasynth fsig +a2 linenr a1*0.5,0.005,0.01,0.01 + out a2 +endin + + + + +i1 0 5 +i2 5 5 + + + + + + 100 + 100 + 320 + 240 + true + + + 255 + 255 + 255 + + + + diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/cudadsyn_example.csd csound-6.02~dfsg/Opcodes/cuda/cudadsyn_example.csd --- csound-5.17.11~dfsg/Opcodes/cuda/cudadsyn_example.csd 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/cudadsyn_example.csd 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,41 @@ + + +--opcode-lib=./libcudaop1.dylib + + +ksmps = 64 +0dbfs = 1 + +i1 ftgen 1,0,512,7,1,512,0.001 +i2 ftgen 2,0,512,-7,1,512,512 +schedule 1,0,10 + +instr 1 + +a1 cudasynth 0.001, 100, -1, 2, 1, 128 + out a1 + +endin + + + +e 10 + + + + + + 100 + 100 + 320 + 240 + true + + + 255 + 255 + 255 + + + + diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/cudadsyn_pvs_example.csd csound-6.02~dfsg/Opcodes/cuda/cudadsyn_pvs_example.csd --- csound-5.17.11~dfsg/Opcodes/cuda/cudadsyn_pvs_example.csd 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/cudadsyn_pvs_example.csd 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,43 @@ + + +--opcode-lib=./libcudaop1.dylib + + + +ksmps = 64 +0dbfs = 1 + + +instr 1 + +asig diskin2 "flutec3.wav", 1 +fsig pvsanal asig, 1024, 128, 1024, 1 +a1 cudasynth fsig,p4,p5/cpspch(8.00),-1, 128 +a2 linenr a1,0.001,0.01,0.01 + out a2 + +endin + + + + +i1 0 5 0.5 440 + + + + + + 100 + 100 + 320 + 240 + true + + + 255 + 255 + 255 + + + + diff -Nru csound-5.17.11~dfsg/Opcodes/cuda/pvsops.cu csound-6.02~dfsg/Opcodes/cuda/pvsops.cu --- csound-5.17.11~dfsg/Opcodes/cuda/pvsops.cu 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/cuda/pvsops.cu 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,398 @@ +// -*- c++ -*- +// pvsops.cu +// experimental cuda opcodes +// +// V Lazzarini, 2013 + +#include +#include +#define VSAMPS 16 +#define MAXBLOCK 8192 +#include + +/* kernel to convert from pvs to rectangular frame */ +__global__ void frompvs(float* inframe, double* lastph, int blocks, + double scal, double fac) { + + int k = threadIdx.x*blocks + blockIdx.x + 1; + int i = k << 1; + float mag = inframe[i]; + double delta = (inframe[i+1] - k*scal)*fac; + double phi = fmod(lastph[k-1] + delta, TWOPI); + lastph[k-1] = phi; + inframe[i] = (float) (mag*cos(phi)); + inframe[i+1] = (float) (mag*sin(phi)); +} + +__global__ void winrotate(float* inframe, float *win, int blocks, + int N, int offset){ + int k = (threadIdx.x*blocks + blockIdx.x); + inframe[k] = win[k]*inframe[(k+offset)%N]; +} + +typedef struct _pvsyn{ + OPDS h; + MYFLT *asig; + PVSDAT *fsig; + float *inframe; /* N */ + double *lastph; /* N/2 */ + float *win; /* N */ + int framecount; + int curframe; + AUXCH frames; + AUXCH count; + cufftHandle plan; + double scal, fac; +} PVSYN; + +static int destroy_pvsyn(CSOUND *csound, void *pp); + +static int pvsynset(CSOUND *csound, PVSYN *p){ + + int N = p->fsig->N; + + if((N != 0) && !(N & (N - 1))) { + int hsize = p->fsig->overlap; + int size, numframes, i; + MYFLT sum = 0.0; + float *win; + + if(p->fsig->wintype != 1) + return csound->InitError(csound, + "window type not implemented yet\n"); + numframes = N/hsize; + size = N*sizeof(float)*numframes; + if(p->frames.auxp == NULL || + p->frames.size < size) + csound->AuxAlloc(csound, size, &p->frames); + memset(p->frames.auxp, 0, size); + + size = sizeof(int)*numframes; + if(p->count.auxp == NULL || + p->count.size < size) + csound->AuxAlloc(csound, size, &p->count); + *((int *)(p->count.auxp)) = 0; + for(i=1; i < numframes; i++) + ((int *)(p->count.auxp))[i] = + (i + (1.f - (float)i/numframes))*N; + + size = (N+2)*sizeof(float); + cudaMalloc(&p->inframe, size); + size = (N/2-1)*sizeof(double); + cudaMalloc(&p->lastph, size); + cudaMemset(p->lastph, 0, size); + size = N*sizeof(float); + cudaMalloc(&p->win, size); + + win = (float *) malloc(sizeof(float)*N); + for(i=0; i < N; i++) + win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N)); + for(i = 0; i < N; i++) sum += win[i]; + sum = FL(2.0) / sum; + for(i = 0; i < N; i++) win[i] *= sum; + sum = FL(0.0); + for(i = 0; i <= N; i+=hsize) + sum += win[i] * win[i]; + sum = 2.0/(sum*N); + for(i = 0; i < N; i++) win[i] *= sum; + cudaMemcpy(p->win,win,N*sizeof(float), + cudaMemcpyHostToDevice); + free(win); + + p->framecount = 0; + p->curframe = 0; + + p->fac = TWOPI*hsize/csound->GetSr(csound); + p->scal =csound->GetSr(csound)/N; + cufftPlan1d(&p->plan, N, CUFFT_C2R, 1); + cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); + csound->RegisterDeinitCallback(csound, p, destroy_pvsyn); + + return OK; + } + return csound->InitError(csound, "fftsize not power-of-two \n"); + +} + +static int pvsynperf(CSOUND *csound, PVSYN *p){ + + int N = p->fsig->N, i; + int hsize = p->fsig->overlap; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *asig = p->asig; + float *frames = (float *) p->frames.auxp; + int framecount = p->framecount; + int numframes = N/hsize; + int *count = (int *) p->count.auxp; + + if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for(n=offset; n < nsmps; n++) { + + if(framecount == 0) { + int bins = N/2; + int blocks; + int curframe = p->curframe; + /* start offset for current frame */ + int start = N*curframe; + float *cur = &(frames[start]); + float *win = (float *) p->win; + float *inframe = p->inframe; + float *fsig = (float *) p->fsig->frame.auxp; + /* copy fsig data to device */ + fsig[N+1] = fsig[1] = 0.f; + //csound->Message(csound, "syn %f, %f\n",fsig[41], fsig[40]); + cudaMemcpy(inframe,fsig,(N+2)*sizeof(float), + cudaMemcpyHostToDevice); + /* perf pvs to rect conversion */ + blocks = bins > 1024 ? bins/1024 : 1; + frompvs<<>>(inframe,p->lastph,blocks, + p->scal,p->fac); + /* execute inverse real FFT */ + if(cufftExecC2R(p->plan,(cufftComplex*)inframe,inframe) + != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); + if (cudaDeviceSynchronize() != cudaSuccess) + csound->Message(csound,"Cuda error: Failed to synchronize\n"); + /* window and rotate data on device */ + blocks = N > 1024 ? N/1024 : 1; + winrotate<<>>(inframe,win,blocks,N,hsize*curframe); + /* copy data to current out frame */ + cudaMemcpy(cur,inframe,N*sizeof(float),cudaMemcpyDeviceToHost); + /* reset counter for this frame to the start */ + count[curframe] = start; + /* move current to next frame circularly */ + p->curframe = ++(curframe) == numframes ? 0 : curframe; + framecount = hsize; + } + asig[n] = FL(0.0); + for(i=0; i < numframes; i++){ + /* overlap-add */ + asig[n] += frames[count[i]]; + count[i]++; + } + framecount--; + } + p->framecount = framecount; + return OK; +} + +static int destroy_pvsyn(CSOUND *csound, void *pp){ + PVSYN *p = (PVSYN *) pp; + cufftDestroy(p->plan); + cudaFree(p->inframe); + cudaFree(p->lastph); + cudaFree(p->win); + return OK; +} + +__device__ double modTwoPi(double x) +{ + x = fmod(x,TWOPI); + return x <= -PI ? x + TWOPI : + (x > PI ? x - TWOPI : x); +} + +/* kernel to convert from rectangular to pvs frame */ +__global__ void topvs(float* aframe, double* oldph, int blocks, + double scal, double fac) { + int k = threadIdx.x*blocks + blockIdx.x + 1; + int i = k << 1; + + float re = aframe[i], im = aframe[i+1]; + float mag = sqrtf(re*re + im*im); + double phi = atan2(im,re); + double delta = phi - oldph[k-1]; + oldph[k-1] = phi; + aframe[i] = mag; + aframe[i+1] = (float) ((modTwoPi(delta) + k*scal)*fac); +} + +__global__ void rotatewin(float* aframe, float *win, int blocks, + int N, int offset){ + int k = (threadIdx.x*blocks + blockIdx.x); + aframe[(k+offset)%N] = win[k]*aframe[k]; +} + +typedef struct _pvan { + OPDS h; + PVSDAT *fsig; + MYFLT *asig,*fftsize,*hsize,*winsize,*wintype; + + float *aframe; /* N */ + double *oldph; /* N/2 */ + float *win; /* N */ + + int framecount; + int curframe; + AUXCH frames; + AUXCH count; + cufftHandle plan; + double scal, fac; + +} PVAN; + +static int destroy_pvanal(CSOUND *csound, void *pp); + +static int pvanalset(CSOUND *csound, PVAN *p){ + + int N = *p->fftsize; + if((N != 0) && !(N & (N - 1))) { + int size, numframes, i; + int hsize = *p->hsize; + float *win; + + p->fsig->N = N; + p->fsig->overlap = hsize; + /* ignore winsize & wintype */ + p->fsig->winsize = N; + p->fsig->wintype = 1; + p->fsig->framecount = 0; + + numframes = N/hsize; + size = N*sizeof(float)*numframes; + if(p->frames.auxp == NULL || + p->frames.size < size) + csound->AuxAlloc(csound, size, &p->frames); + memset(p->frames.auxp, 0, size); + + size = N*sizeof(float); + if(p->fsig->frame.auxp == NULL || + p->fsig->frame.size < size) + csound->AuxAlloc(csound, size, &p->fsig->frame); + memset(p->fsig->frame.auxp, 0, size); + + + size = sizeof(int)*numframes; + if(p->count.auxp == NULL || + p->count.size < size) + csound->AuxAlloc(csound, size, &p->count); + *((int *)(p->count.auxp)) = 0; + for(i=1; i < numframes; i++) + ((int *)(p->count.auxp))[i] = + (i + (float)i/numframes)*N; + + size = (N+2)*sizeof(float); + cudaMalloc(&p->aframe, size); + size = (N/2-1)*sizeof(double); + cudaMalloc(&p->oldph, size); + cudaMemset(p->oldph, 0, size); + size = N*sizeof(float); + cudaMalloc(&p->win, size); + + win = (float *) malloc(sizeof(float)*N); + for(i=0; i < N; i++) + win[i] = (float) (0.5 - 0.5*cos(i*TWOPI/N))*(4./N); + cudaMemcpy(p->win,win,N*sizeof(float), + cudaMemcpyHostToDevice); + free(win); + + p->framecount = 1; + p->curframe = numframes-1; + p->fac = csound->GetSr(csound)/(TWOPI*hsize); + p->scal = (TWOPI*hsize)/N; + cufftPlan1d(&p->plan, N, CUFFT_R2C, 1); + cufftSetCompatibilityMode(p->plan, CUFFT_COMPATIBILITY_NATIVE); + csound->RegisterDeinitCallback(csound, p, destroy_pvanal); + csound->Message(csound, "%d threads, %d blocks\n", N, N/1024); + return OK; + } + return csound->InitError(csound, "fftsize not power-of-two \n"); +} + +static int pvanalperf(CSOUND *csound, PVAN *p){ + + int N = p->fsig->N, i; + int hsize = p->fsig->overlap; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *asig = p->asig; + float *frames = (float *) p->frames.auxp; + int framecount = p->framecount; + int numframes = N/hsize; + int *count = (int *) p->count.auxp; + + if (UNLIKELY(offset)) memset(asig, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&asig[nsmps], '\0', early*sizeof(MYFLT)); + } + + for(n=offset; n < nsmps; n++) { + for(i=0; i < numframes; i++){ + frames[count[i]] = asig[n]; + count[i]++; + } + framecount++; + + if(framecount == hsize) { + int bins = N/2; + int blocks; + int curframe = p->curframe; + /* start offset for current frame */ + int start = N*curframe; + float *cur = &(frames[start]); + float *win = (float *) p->win; + float *aframe = p->aframe; + float *fsig = (float *) p->fsig->frame.auxp; + /* copy fsig data to device */ + cudaMemcpy(aframe,cur,N*sizeof(float), + cudaMemcpyHostToDevice); + /* window and rotate data on device */ + blocks = N > 1024 ? N/1024 : 1; + rotatewin<<>>(aframe,win,blocks,N,hsize*(numframes-curframe)); + /* execute inverse real FFT */ + if(cufftExecR2C(p->plan,aframe,(cufftComplex*)aframe) + != CUFFT_SUCCESS) csound->Message(csound, "cuda fft error\n"); + if (cudaDeviceSynchronize() != cudaSuccess) + csound->Message(csound,"Cuda error: Failed to synchronize\n"); + /* perf rect to pvs conversion */ + blocks = bins > 1024 ? bins/1024 : 1; + topvs<<>>(aframe,p->oldph,blocks,p->scal,p->fac); + /* copy data to current out frame */ + cudaMemcpy(fsig,aframe,(N+2)*sizeof(float),cudaMemcpyDeviceToHost); + /* reset counter for this frame to the start */ + fsig[N+1] = fsig[1] = 0.f; + //printf("%f \n", fsig[43]); + //printf("%f \n", fsig[42]); + //csound->Message(csound, "%f, %f\n",fsig[41], fsig[40]); + count[curframe] = start; + /* move current to next frame circularly */ + p->curframe = --(curframe) < 0 ? numframes-1 : curframe; + framecount = 0; + p->fsig->framecount++; + } + } + p->framecount = framecount; + return OK; +} + +static int destroy_pvanal(CSOUND *csound, void *pp){ + PVAN *p = (PVAN *) pp; + cufftDestroy(p->plan); + cudaFree(p->aframe); + cudaFree(p->oldph); + cudaFree(p->win); + return OK; +} + +static OENTRY localops[] = { + {"cudasynth", sizeof(PVSYN),0, 5, "a", "f", (SUBR) pvsynset, NULL, + (SUBR) pvsynperf}, + {"cudanal", sizeof(PVAN),0, 5, "f", "aiiii", (SUBR) pvanalset, NULL, + (SUBR) pvanalperf} +}; + +extern "C" { + LINKAGE +} diff -Nru csound-5.17.11~dfsg/Opcodes/dam.c csound-6.02~dfsg/Opcodes/dam.c --- csound-5.17.11~dfsg/Opcodes/dam.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dam.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include "dam.h" #include @@ -64,7 +64,6 @@ static int dam(CSOUND *csound, DAM *p) { - int i; MYFLT *ain,*aout; MYFLT threshold; MYFLT gain; @@ -73,7 +72,9 @@ MYFLT *powerBuffer; MYFLT power; MYFLT tg; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; /* Initialize power value and buffer at first ksamp computed as * it depends on kthreshold @@ -99,8 +100,12 @@ power = p->power; /* Process ksmps samples */ - - for (i=0;i +#if defined(__MACH__) +#include +#endif + typedef struct { OPDS h; MYFLT *time_; @@ -31,7 +35,7 @@ typedef struct { OPDS h; - MYFLT *Stime_; + STRINGDAT *Stime_; MYFLT *timstmp; } DATESTRING; @@ -53,31 +57,142 @@ char *time_string; /* char *q; */ int32 tmp; + #if defined(MSVC) || (defined(__GNUC__) && defined(__i386__)) - tmp = (int32) MYFLT2LRND(*(p->timstmp)); + tmp = (int32) MYFLT2LRND(*(p->timstmp)); #else - tmp = (int32) (*(p->timstmp) + FL(0.5)); + tmp = (int32) (*(p->timstmp) + FL(0.5)); #endif - if (tmp < 0) temp_time = time(NULL); + if (tmp <= 0) temp_time = time(NULL); else temp_time = (time_t)tmp; time_string = ctime(&temp_time); /* printf("Timestamp = %f\ntimestring=>%s<\n", *p->timstmp, time_string); */ - ((char*) p->Stime_)[0] = '\0'; - if (UNLIKELY((int) strlen(time_string) >= csound->strVarMaxLen)) { - return csound->InitError(csound, Str("dates: buffer overflow")); - } + /* q = strchr(time_string, '\n'); */ /* if (q) *q='\0'; */ - strcpy((char*) p->Stime_, time_string); + if (p->Stime_->data != NULL) csound->Free(csound, p->Stime_->data); + p->Stime_->data = csound->Strdup(csound, time_string); + p->Stime_->size = strlen(time_string)+1; + return OK; +} + +typedef struct { + OPDS h; + STRINGDAT *Scd; +} GETCWD; + +static int getcurdir(CSOUND *csound, GETCWD *p) +{ + if (p->Scd->data == NULL) { + p->Scd->size = 1024; + p->Scd->data = csound->Calloc(csound, p->Scd->size); + } + +#if defined(__MACH__) || defined(LINUX) || defined(__HAIKU__) + if (UNLIKELY(getcwd(p->Scd->data, p->Scd->size-1)==NULL)) +#else + if (UNLIKELY( _getcwd(p->Scd->data, p->Scd->size-1)==NULL)) +#endif + return csound->InitError(csound, Str("cannot determine current directory")); + return OK; +} + +#ifndef MAXLINE +#define MAXLINE 1024 +#endif + +typedef struct { + OPDS h; + STRINGDAT *Sline; + MYFLT *line; + MYFLT *Sfile; + FILE *fd; + int lineno; +} READF; + +static int readf_delete(CSOUND *csound, void *p) +{ + READF *pp = (READF*)p; + + if (pp->fd) fclose(pp->fd); + return OK; +} + +static int readf_init_(CSOUND *csound, READF *p, int isstring) +{ + char name[1024]; + if(isstring) strncpy(name, ((STRINGDAT *)p->Sfile)->data, 1023); + else csound->strarg2name(csound, name, p->Sfile, "input.", 0); + p->fd = fopen(name, "r"); + p->lineno = 0; + if (p->Sline->data == NULL) { + p->Sline->data = (char *) csound->Calloc(csound, MAXLINE); + p->Sline->size = MAXLINE; + } + if (UNLIKELY(p->fd==NULL)) + return csound->InitError(csound, Str("readf: failed to open file")); + return csound->RegisterDeinitCallback(csound, p, readf_delete); +} + +static int readf_init(CSOUND *csound, READF *p){ + return readf_init_(csound,p,0); +} + +static int readf_init_S(CSOUND *csound, READF *p){ + return readf_init_(csound,p,1); +} + + +static int readf(CSOUND *csound, READF *p) +{ + p->Sline->data[0] = '\0'; + if (UNLIKELY(fgets(p->Sline->data, + p->Sline->size-1, p->fd)==NULL)) { + int ff = feof(p->fd); + fclose(p->fd); + p->fd = NULL; + if (ff) { + *p->line = -1; + return OK; + } + else + return csound->PerfError(csound, p->h.insdshead, + Str("readf: read failure")); + } + *p->line = ++p->lineno; return OK; } +static int readfi(CSOUND *csound, READF *p) +{ + if (p->fd==NULL) + if (UNLIKELY(readf_init(csound, p)!= OK)) + return csound->InitError(csound, Str("readi failed to initialise")); + return readf(csound, p); +} + +static int readfi_S(CSOUND *csound, READF *p) +{ + if (p->fd==NULL) + if (UNLIKELY(readf_init_S(csound, p)!= OK)) + return csound->InitError(csound, Str("readi failed to initialise")); + return readf(csound, p); +} + + static OENTRY date_localops[] = { - { "date", sizeof(DATEMYFLT), 1, "i", "",(SUBR)datemyfltset, NULL, NULL }, - { "dates", sizeof(DATESTRING), 1, "S", "j",(SUBR)datestringset, NULL, NULL }, -}; + { "date", sizeof(DATEMYFLT), 0, 1, "i", "", (SUBR)datemyfltset }, + { "dates", sizeof(DATESTRING), 0, 1, "S", "j", (SUBR)datestringset }, + { "pwd", sizeof(GETCWD), 0, 1, "S", "", (SUBR)getcurdir }, + { "readfi", sizeof(READF), 0, 1, "Si", "i", (SUBR)readfi, }, + { "readfi.S", sizeof(READF), 0, 1, "Si", "S", (SUBR)readfi_S, }, + { "readf", sizeof(READF), 0, 3, "Sk", "i", (SUBR)readf_init, + (SUBR)readf }, + { "readf.S", sizeof(READF), 0, 3, "Sk", "S", (SUBR)readf_init_S, + (SUBR)readf } -LINKAGE1(date_localops) +}; +LINKAGE_BUILTIN(date_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/dcblockr.c csound-6.02~dfsg/Opcodes/dcblockr.c --- csound-5.17.11~dfsg/Opcodes/dcblockr.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dcblockr.c 2014-01-07 16:53:48.000000000 +0000 @@ -31,7 +31,7 @@ /* structures. */ /*******************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "dcblockr.h" static int dcblockrset(CSOUND *csound, DCBlocker* p) @@ -47,13 +47,20 @@ static int dcblockr(CSOUND *csound, DCBlocker* p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double gain = p->gain; double outputs = p->outputs; double inputs = p->inputs; MYFLT *samp = p->in; - for (n=0; ninput; - MYFLT *out = p->output; - double *del1 = (double *)p->delay1.auxp; - double *iirdel[4],x1,x2,y,del; - double *ydels = p->ydels; - double scale = p->scaler; - int p1 = p->dp1; - int p2 = p->dp2; - int i,j,del1size, iirdelsize, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + MYFLT *in = p->input; + MYFLT *out = p->output; + double *del1 = (double *)p->delay1.auxp; + double *iirdel[4],x1,x2,y,del; + double *ydels = p->ydels; + double scale = p->scaler; + int p1 = p->dp1; + int p2 = p->dp2; + int j,del1size, iirdelsize; iirdel[0] = (double *) p->iirdelay1.auxp; iirdel[1] = (double *) p->iirdelay2.auxp; @@ -148,7 +158,12 @@ del1size = p->delay1.size/sizeof(double); iirdelsize = p->iirdelay1.size/sizeof(double); - for (i=0; i < nsmps; i++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset; i < nsmps; i++) { /* long delay */ del = del1[p1]; @@ -178,8 +193,10 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "dcblock", S(DCBlocker), 5, "a", "ao", (SUBR)dcblockrset, NULL, (SUBR)dcblockr}, - { "dcblock2", S(DCBlock2), 5, "a", "aoo", (SUBR)dcblock2set, NULL, (SUBR)dcblock2} + { "dcblock", S(DCBlocker), 0, 5, "a", "ao", + (SUBR)dcblockrset, NULL, (SUBR)dcblockr}, + { "dcblock2", S(DCBlock2), 0, 5, "a", "aoo", + (SUBR)dcblock2set, NULL, (SUBR)dcblock2} }; int dcblockr_init_(CSOUND *csound) @@ -187,4 +204,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/doppler.cpp csound-6.02~dfsg/Opcodes/doppler.cpp --- csound-5.17.11~dfsg/Opcodes/doppler.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/doppler.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -4,6 +4,7 @@ #include #include +/* *************** does not deal with unaligned signals ************** */ // Why not use the constants already defined? static MYFLT pi = std::atan(1.0) * MYFLT(4.0); @@ -79,7 +80,8 @@ } MYFLT delayFrames(int delayFrames_) { - //std::cout << "DelayLine::delayFrames: delayFrames: " << delayFrames_ << std::endl; + //std::cout << "DelayLine::delayFrames: delayFrames: " + // << delayFrames_ << std::endl; int readingFrame = writingFrame - delayFrames_; while (readingFrame < 0) { readingFrame += size_; @@ -87,7 +89,8 @@ while (readingFrame >= size_) { readingFrame -= size_; } - // std::cout << "DelayLine::delayFrames: readingFrame: " << readingFrame << std::endl; + // std::cout << "DelayLine::delayFrames: readingFrame: " + // << readingFrame << std::endl; return (*this)[(size_t) readingFrame]; } }; @@ -123,8 +126,8 @@ int init(CSOUND *csound) { sampleRate = csound->GetSr(csound); - blockSize = csound->GetKsmps(csound); - blockRate = sampleRate / blockSize; + blockRate = opds.insdshead->ekr; + blockSize = opds.insdshead->ksmps; // Take care of default values. if (*jSpeedOfSound == MYFLT(-1.0)) { speedOfSound = MYFLT(340.29); @@ -165,18 +168,24 @@ // because it must be initialized from a k-rate variable. if (!smoothingFilter) { smoothingFilter = new RCLowpassFilter(); - smoothingFilter->initialize(sampleRate, smoothingFilterCutoff, targetPosition); + smoothingFilter->initialize(sampleRate, + smoothingFilterCutoff, targetPosition); log(csound, "Doppler::kontrol: sizeof(MYFLT): %10d\n", sizeof(MYFLT)); log(csound, "Doppler::kontrol: PI: %10.3f\n", pi); log(csound, "Doppler::kontrol: this: %10p\n", this); log(csound, "Doppler::kontrol: sampleRate: %10.3f\n", sampleRate); log(csound, "Doppler::kontrol: blockSize: %10.3f\n", blockSize); log(csound, "Doppler::kontrol: blockRate: %10.3f\n", blockRate); - log(csound, "Doppler::kontrol: speedOfSound: %10.3f\n", speedOfSound); - log(csound, "Doppler::kontrol: samplesPerDistance: %10.3f\n", samplesPerDistance); - log(csound, "Doppler::kontrol: smoothingFilterCutoff: %10.3f\n", smoothingFilterCutoff); - log(csound, "Doppler::kontrol: kMicPosition: %10.3f\n", *kMicPosition); - log(csound, "Doppler::kontrol: kSourcePosition: %10.3f\n", *kSourcePosition); + log(csound, "Doppler::kontrol: speedOfSound: %10.3f\n", + speedOfSound); + log(csound, "Doppler::kontrol: samplesPerDistance: %10.3f\n", + samplesPerDistance); + log(csound, "Doppler::kontrol: smoothingFilterCutoff: %10.3f\n", + smoothingFilterCutoff); + log(csound, "Doppler::kontrol: kMicPosition: %10.3f\n", + *kMicPosition); + log(csound, "Doppler::kontrol: kSourcePosition: %10.3f\n", + *kSourcePosition); } for (size_t outputFrame = 0; @@ -215,7 +224,7 @@ audioBufferQueue->pop_front(); } delete audioBufferQueue; - audioBufferQueue = 0; + audioBufferQueue = 0; } if (sourcePositionQueue) { delete sourcePositionQueue; @@ -240,6 +249,7 @@ { (char*)"doppler", sizeof(Doppler), + 0, 3, (char*)"a", (char*)"akkjj", @@ -256,6 +266,8 @@ 0, 0, 0, + 0, + 0, } }; @@ -270,7 +282,8 @@ for(OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) { status |= csound->AppendOpcode(csound, oentry->opname, - oentry->dsblksiz, oentry->thread, + oentry->dsblksiz, oentry->flags, + oentry->thread, oentry->outypes, oentry->intypes, (int (*)(CSOUND*,void*)) oentry->iopadr, (int (*)(CSOUND*,void*)) oentry->kopadr, @@ -282,7 +295,7 @@ PUBLIC int csoundModuleDestroy(CSOUND *csound) { //csound->Message(csound, "Deleting C++ objects from doppler...\n"); - for (std::list::iterator it = smoothingFilterInstances.begin(); + for (std::list::iterator it=smoothingFilterInstances.begin(); it != smoothingFilterInstances.end(); ++it) { delete *it; @@ -297,4 +310,3 @@ return 0; } } - diff -Nru csound-5.17.11~dfsg/Opcodes/dsputil.c csound-6.02~dfsg/Opcodes/dsputil.c --- csound-5.17.11~dfsg/Opcodes/dsputil.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dsputil.c 2014-01-07 16:53:48.000000000 +0000 @@ -346,7 +346,7 @@ */ void PreWarpSpec( - PVOC_GLOBALS *p, + //PVOC_GLOBALS *p, MYFLT *spec, /* spectrum as magnitude,phase */ int32 size, /* full frame size, tho' we only use n/2+1 */ MYFLT warpFactor, /* How much pitches are being multd by */ @@ -357,11 +357,6 @@ int32 pkcnt, i, j; - /* if (dsputil_env == (MYFLT*) NULL){ */ - /* p->csound->Message(p->csound, "called warp\n"); */ - /* dsputil_env = (MYFLT*) p->csound->Malloc(p->csound, size * sizeof(MYFLT)); */ - /* } */ - eps = -FL(64.0) / size; /* for spectral envelope estimation */ lastmag = *spec; mag = spec[2*1]; diff -Nru csound-5.17.11~dfsg/Opcodes/dsputil.h csound-6.02~dfsg/Opcodes/dsputil.h --- csound-5.17.11~dfsg/Opcodes/dsputil.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dsputil.h 2014-01-07 16:53:48.000000000 +0000 @@ -43,5 +43,5 @@ void writeClrFromCircBuf(MYFLT *, MYFLT *, int32, int32, int32); void UDSample(PVOC_GLOBALS *, MYFLT *, MYFLT, MYFLT *, int32, int32, MYFLT); void MakeSinc(PVOC_GLOBALS *); -void PreWarpSpec(PVOC_GLOBALS *, MYFLT *, int32, MYFLT, MYFLT *); +void PreWarpSpec(MYFLT *, int32, MYFLT, MYFLT *); diff -Nru csound-5.17.11~dfsg/Opcodes/dssi4cs/src/dssi4cs.c csound-6.02~dfsg/Opcodes/dssi4cs/src/dssi4cs.c --- csound-5.17.11~dfsg/Opcodes/dssi4cs/src/dssi4cs.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dssi4cs/src/dssi4cs.c 2014-01-07 16:53:48.000000000 +0000 @@ -24,12 +24,15 @@ #include #include +#undef CS_KSMPS +#define CS_KSMPS (csound->GetKsmps(csound)) + #ifdef BETA #define DEBUG 1 #endif #define DSSI4CS_MAX_NUM_EVENTS 128 -static const char *version = "0.1alpha"; +//static const char *version = "0.1alpha"; /* TODO accomodate plugins which return control outputs */ @@ -38,7 +41,7 @@ *****************************************************************************/ void info(CSOUND * csound, DSSI4CS_PLUGIN * DSSIPlugin_) { - int Ksmps = csound->ksmps; + int Ksmps = csound->GetKsmps(csound); unsigned long PortCount; LADSPA_Descriptor *Descriptor; uint32 i; @@ -181,13 +184,13 @@ { /* TODO check if plugin has already been loaded and use same function */ csound = p->h.insdshead->csound; - int SampleRate = (int) MYFLT2LRND(csound->esr); - int Ksmps = csound->ksmps; - int i; + int SampleRate = (int) MYFLT2LRND(csound->GetSr(csound)); + int Ksmps = csound->GetKsmps(csound); + unsigned long i; LADSPA_Descriptor_Function pfDescriptorFunction; DSSI_Descriptor_Function pfDSSIDescriptorFunction; LADSPA_Descriptor *LDescriptor; - char dssiFilename[0x100]; + char dssiFilename[MAXNAME]; unsigned long PluginIndex; void *PluginLibrary; unsigned long PortCount; @@ -197,8 +200,14 @@ DSSI4CS_PLUGIN *DSSIPlugin_; DSSI4CS_PLUGIN *DSSIPlugin = (DSSI4CS_PLUGIN *) csound->QueryGlobalVariable(csound, "$DSSI4CS"); - csound->strarg2name(csound, dssiFilename, p->iplugin, "dssiinit.", - (int) csound->GetInputArgSMask(p)); + + if(csound->GetInputArgSMask(p)) + strncpy(dssiFilename,((STRINGDAT *)p->iplugin)->data, MAXNAME-1); + else + csound->strarg2name(csound, dssiFilename, ISSTRCOD(*p->iplugin) ? + csound->GetString(csound, *p->iplugin) : + (char *) p->iplugin, "dssiinit.", + (int) ISSTRCOD(*p->iplugin)); PluginIndex = (unsigned long) *p->iindex; PluginLibrary = dlopenLADSPA(csound, dssiFilename, RTLD_NOW); if (UNLIKELY(!PluginLibrary)) @@ -567,8 +576,9 @@ case -100: { if (p->printflag != -100) { - return csound->PerfError(csound, "DSSI4CS: dssiactivate " - "not properly initialised."); + return csound->PerfError(csound, p->h.insdshead, + "DSSI4CS: dssiactivate " + "not properly initialised."); p->printflag = -100; } } @@ -591,11 +601,15 @@ int ocnt = csound->GetOutputArgCnt(p); if (UNLIKELY(icnt > DSSI4CS_MAX_IN_CHANNELS)) - csound->Die(csound, Str("DSSI4CS: number of audio input channels is greater than %d"), + csound->Die(csound, + Str("DSSI4CS: number of audio input channels " + "is greater than %d"), DSSI4CS_MAX_IN_CHANNELS); if (UNLIKELY(ocnt > DSSI4CS_MAX_OUT_CHANNELS)) - csound->Die(csound, Str("DSSI4CS: number of audio output channels is greater than %d"), + csound->Die(csound, + Str("DSSI4CS: number of audio output channels " + "is greater than %d"), DSSI4CS_MAX_OUT_CHANNELS); #ifdef DEBUG @@ -618,10 +632,10 @@ Descriptor = (LADSPA_Descriptor *) p->DSSIPlugin_->DSSIDescriptor->LADSPA_Plugin; - long PortIndex = 0; - int ConnectedInputPorts = 0; - int ConnectedOutputPorts = 0; - int ConnectedPorts = 0; + unsigned long PortIndex = 0; + int ConnectedInputPorts = 0; + int ConnectedOutputPorts = 0; + int ConnectedPorts = 0; LADSPA_PortDescriptor PortDescriptor = 0; for (PortIndex = 0; PortIndex < Descriptor->PortCount; PortIndex++) { @@ -705,22 +719,22 @@ else Descriptor = (LADSPA_Descriptor *) p->DSSIPlugin_->DSSIDescriptor->LADSPA_Plugin; - int i, j; - int icnt = csound->GetInputArgCnt(p) - 1; - int ocnt = csound->GetOutputArgCnt(p); - unsigned long Ksmps = (unsigned long) csound->ksmps; + unsigned int i, j; + unsigned int icnt = csound->GetInputArgCnt(p) - 1; + unsigned int ocnt = csound->GetOutputArgCnt(p); + unsigned long Ksmps = (unsigned long) csound->GetKsmps(csound); if (p->DSSIPlugin_->Active == 1) { for (j = 0; j < icnt; j++) { for (i = 0; i < Ksmps; i++) p->DSSIPlugin_->audio[p->InputPorts[j]][i] = - p->ain[j][i] * csound->dbfs_to_float; + p->ain[j][i] * (1.0/csound->Get0dBFS(csound)); } Descriptor->run(p->DSSIPlugin_->Handle, Ksmps); for (j = 0; j < ocnt; j++) { for (i = 0; i < Ksmps; i++) p->aout[j][i] = - p->DSSIPlugin_->audio[p->OutputPorts[j]][i] * csound->e0dbfs; + p->DSSIPlugin_->audio[p->OutputPorts[j]][i] * csound->Get0dBFS(csound); } } else { @@ -739,7 +753,8 @@ { LADSPA_Data Value = *p->val; if (!p->DSSIPlugin_) { - return csound->PerfError(csound, "DSSI4CS: Invalid plugin handle."); + return csound->PerfError(csound, p->h.insdshead, + "DSSI4CS: Invalid plugin handle."); } if (*p->ktrig == 1) { *p->DSSIPlugin_->control[p->PortNumber] = Value * (p->HintSampleRate); @@ -749,7 +764,7 @@ int dssictls_ak(CSOUND * csound, DSSICTLS * p) { - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, "DSSI4CS: Audio Rate control ports not implemented yet."); return NOTOK; } @@ -760,9 +775,9 @@ Crash if audio port selected */ const LADSPA_Descriptor *Descriptor; int Number = *p->iDSSIhandle; - int Sr = (int) MYFLT2LRND(csound->esr); + int Sr = (int) MYFLT2LRND(csound->GetSr(csound)); unsigned long PortIndex = *p->iport; - int i; + unsigned int i; unsigned long ControlPort = 0; unsigned long AudioPort = 0; unsigned long Port = 0; @@ -829,7 +844,7 @@ int dssictls_dummy(CSOUND * csound, DSSICTLS * p) { - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str("DSSI4CS: Not initialised or wrong argument types.")); return NOTOK; } @@ -1053,30 +1068,30 @@ } static OENTRY dssi_localops[] = { - {"dssiinit", sizeof(DSSIINIT), 1, "i", "Tip", (SUBR) dssiinit, NULL, NULL } + {"dssiinit", sizeof(DSSIINIT), 0, 1, "i", "Tip", (SUBR) dssiinit, NULL, NULL } , - {"dssiactivate", sizeof(DSSIACTIVATE), 3, "", "ik", + {"dssiactivate", sizeof(DSSIACTIVATE), 0, 3, "", "ik", (SUBR) dssiactivate_init, (SUBR) dssiactivate, NULL } , - {"dssiaudio", sizeof(DSSIAUDIO), 5, "mmmmmmmmm", "iMMMMMMMMM", (SUBR) dssiaudio_init, - NULL, (SUBR) dssiaudio } + {"dssiaudio", sizeof(DSSIAUDIO), 0, 5, "mmmmmmmmm", "iMMMMMMMMM", + (SUBR) dssiaudio_init, + NULL, (SUBR) dssiaudio } , - {"dssictls", sizeof(DSSICTLS), 3, "", "iikk", (SUBR) dssictls_init, + {"dssictls", sizeof(DSSICTLS), 0, 3, "", "iikk", (SUBR) dssictls_init, (SUBR) dssictls_kk, NULL } , - {"dssilist", sizeof(DSSILIST), 1, "", "", (SUBR) dssilist, NULL, NULL } + {"dssilist", sizeof(DSSILIST), 0, 1, "", "", (SUBR) dssilist, NULL, NULL } #if 0 , - {"dssisynth", sizeof(DSSISYNTH), 5, "aa", "i", (SUBR) dssisynth_init, + {"dssisynth", sizeof(DSSISYNTH), 0, 5, "aa", "i", (SUBR) dssisynth_init, NULL, (SUBR) dssisynth} , - {"dssinote", sizeof(DSSINOTE), 3, "", "kikkk", (SUBR) dssinote_init, + {"dssinote", sizeof(DSSINOTE), 0, 3, "", "kikkk", (SUBR) dssinote_init, NULL, (SUBR) dssinote} , - {"dssievent", sizeof(DSSINOTEON), 3, "", "kikk", (SUBR) dssievent_init, + {"dssievent", sizeof(DSSINOTEON), 0, 3, "", "kikk", (SUBR) dssievent_init, NULL, (SUBR) dssievent} #endif }; -LINKAGE1(dssi_localops) - +LINKAGE_BUILTIN(dssi_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/dssi4cs/src/seq_event.h csound-6.02~dfsg/Opcodes/dssi4cs/src/seq_event.h --- csound-5.17.11~dfsg/Opcodes/dssi4cs/src/seq_event.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/dssi4cs/src/seq_event.h 1970-01-01 00:00:00.000000000 +0000 @@ -1,444 +0,0 @@ -/** - * \file include/seq_event.h - * \brief Application interface library for the ALSA driver - * \author Jaroslav Kysela - * \author Abramo Bagnara - * \author Takashi Iwai - * \date 1998-2001 - * - * Application interface library for the ALSA driver - */ -/* - * This library is free software; you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation; either version 2.1 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - */ - -#ifndef __ALSA_SEQ_EVENT_H -#define __ALSA_SEQ_EVENT_H - -/** - * \defgroup SeqEvents Sequencer Event Definitions - * Sequencer Event Definitions - * \ingroup Sequencer - * \{ - */ - -/** - * Sequencer event data type - */ -typedef unsigned char snd_seq_event_type_t; - -/** Sequencer event type */ -enum snd_seq_event_type { - /** system status; event data type = #snd_seq_result_t */ - SND_SEQ_EVENT_SYSTEM = 0, - /** returned result status; event data type = #snd_seq_result_t */ - SND_SEQ_EVENT_RESULT, - - /** note on and off with duration; event data type = #snd_seq_ev_note_t */ - SND_SEQ_EVENT_NOTE = 5, - /** note on; event data type = #snd_seq_ev_note_t */ - SND_SEQ_EVENT_NOTEON, - /** note off; event data type = #snd_seq_ev_note_t */ - SND_SEQ_EVENT_NOTEOFF, - /** key pressure change (aftertouch); event data type = #snd_seq_ev_note_t */ - SND_SEQ_EVENT_KEYPRESS, - - /** controller; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_CONTROLLER = 10, - /** program change; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_PGMCHANGE, - /** channel pressure; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_CHANPRESS, - /** pitchwheel; event data type = #snd_seq_ev_ctrl_t; data is from -8192 to 8191) */ - SND_SEQ_EVENT_PITCHBEND, - /** 14 bit controller value; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_CONTROL14, - /** 14 bit NRPN; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_NONREGPARAM, - /** 14 bit RPN; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_REGPARAM, - - /** SPP with LSB and MSB values; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_SONGPOS = 20, - /** Song Select with song ID number; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_SONGSEL, - /** midi time code quarter frame; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_QFRAME, - /** SMF Time Signature event; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_TIMESIGN, - /** SMF Key Signature event; event data type = #snd_seq_ev_ctrl_t */ - SND_SEQ_EVENT_KEYSIGN, - - /** MIDI Real Time Start message; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_START = 30, - /** MIDI Real Time Continue message; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_CONTINUE, - /** MIDI Real Time Stop message; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_STOP, - /** Set tick queue position; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_SETPOS_TICK, - /** Set real-time queue position; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_SETPOS_TIME, - /** (SMF) Tempo event; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_TEMPO, - /** MIDI Real Time Clock message; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_CLOCK, - /** MIDI Real Time Tick message; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_TICK, - /** Queue timer skew; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_QUEUE_SKEW, - /** Sync position changed; event data type = #snd_seq_ev_queue_control_t */ - SND_SEQ_EVENT_SYNC_POS, - - /** Tune request; event data type = none */ - SND_SEQ_EVENT_TUNE_REQUEST = 40, - /** Reset to power-on state; event data type = none */ - SND_SEQ_EVENT_RESET, - /** Active sensing event; event data type = none */ - SND_SEQ_EVENT_SENSING, - - /** Echo-back event; event data type = any type */ - SND_SEQ_EVENT_ECHO = 50, - /** OSS emulation raw event; event data type = any type */ - SND_SEQ_EVENT_OSS, - - /** New client has connected; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_CLIENT_START = 60, - /** Client has left the system; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_CLIENT_EXIT, - /** Client status/info has changed; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_CLIENT_CHANGE, - /** New port was created; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_PORT_START, - /** Port was deleted from system; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_PORT_EXIT, - /** Port status/info has changed; event data type = #snd_seq_addr_t */ - SND_SEQ_EVENT_PORT_CHANGE, - - /** Ports connected; event data type = #snd_seq_connect_t */ - SND_SEQ_EVENT_PORT_SUBSCRIBED, - /** Ports disconnected; event data type = #snd_seq_connect_t */ - SND_SEQ_EVENT_PORT_UNSUBSCRIBED, - - /** Sample select; event data type = #snd_seq_ev_sample_control_t */ - SND_SEQ_EVENT_SAMPLE = 70, - /** Sample cluster select; event data type = #snd_seq_ev_sample_control_t */ - SND_SEQ_EVENT_SAMPLE_CLUSTER, - /** voice start */ - SND_SEQ_EVENT_SAMPLE_START, - /** voice stop */ - SND_SEQ_EVENT_SAMPLE_STOP, - /** playback frequency */ - SND_SEQ_EVENT_SAMPLE_FREQ, - /** volume and balance */ - SND_SEQ_EVENT_SAMPLE_VOLUME, - /** sample loop */ - SND_SEQ_EVENT_SAMPLE_LOOP, - /** sample position */ - SND_SEQ_EVENT_SAMPLE_POSITION, - /** private (hardware dependent) event */ - SND_SEQ_EVENT_SAMPLE_PRIVATE1, - - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR0 = 90, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR1, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR2, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR3, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR4, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR5, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR6, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR7, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR8, - /** user-defined event; event data type = any (fixed size) */ - SND_SEQ_EVENT_USR9, - - /** begin of instrument management */ - SND_SEQ_EVENT_INSTR_BEGIN = 100, - /** end of instrument management */ - SND_SEQ_EVENT_INSTR_END, - /** query instrument interface info */ - SND_SEQ_EVENT_INSTR_INFO, - /** result of instrument interface info */ - SND_SEQ_EVENT_INSTR_INFO_RESULT, - /** query instrument format info */ - SND_SEQ_EVENT_INSTR_FINFO, - /** result of instrument format info */ - SND_SEQ_EVENT_INSTR_FINFO_RESULT, - /** reset instrument instrument memory */ - SND_SEQ_EVENT_INSTR_RESET, - /** get instrument interface status */ - SND_SEQ_EVENT_INSTR_STATUS, - /** result of instrument interface status */ - SND_SEQ_EVENT_INSTR_STATUS_RESULT, - /** put an instrument to port */ - SND_SEQ_EVENT_INSTR_PUT, - /** get an instrument from port */ - SND_SEQ_EVENT_INSTR_GET, - /** result of instrument query */ - SND_SEQ_EVENT_INSTR_GET_RESULT, - /** free instrument(s) */ - SND_SEQ_EVENT_INSTR_FREE, - /** get instrument list */ - SND_SEQ_EVENT_INSTR_LIST, - /** result of instrument list */ - SND_SEQ_EVENT_INSTR_LIST_RESULT, - /** set cluster parameters */ - SND_SEQ_EVENT_INSTR_CLUSTER, - /** get cluster parameters */ - SND_SEQ_EVENT_INSTR_CLUSTER_GET, - /** result of cluster parameters */ - SND_SEQ_EVENT_INSTR_CLUSTER_RESULT, - /** instrument change */ - SND_SEQ_EVENT_INSTR_CHANGE, - - /** system exclusive data (variable length); event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_SYSEX = 130, - /** error event; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_BOUNCE, - /** reserved for user apps; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_USR_VAR0 = 135, - /** reserved for user apps; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_USR_VAR1, - /** reserved for user apps; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_USR_VAR2, - /** reserved for user apps; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_USR_VAR3, - /** reserved for user apps; event data type = #snd_seq_ev_ext_t */ - SND_SEQ_EVENT_USR_VAR4, - - /** NOP; ignored in any case */ - SND_SEQ_EVENT_NONE = 255 -}; - -/** Sequencer event address */ -typedef struct snd_seq_addr { - unsigned char client; /**< Client id */ - unsigned char port; /**< Port id */ -} snd_seq_addr_t; - -/** Connection (subscription) between ports */ -typedef struct snd_seq_connect { - snd_seq_addr_t sender; /**< sender address */ - snd_seq_addr_t dest; /**< destination address */ -} snd_seq_connect_t; - -/** Real-time data record */ -typedef struct snd_seq_real_time { - unsigned int tv_sec; /**< seconds */ - unsigned int tv_nsec; /**< nanoseconds */ -} snd_seq_real_time_t; - -/** (MIDI) Tick-time data record */ -typedef unsigned int snd_seq_tick_time_t; - -/** unioned time stamp */ -typedef union snd_seq_timestamp { - snd_seq_tick_time_t tick; /**< tick-time */ - struct snd_seq_real_time time; /**< real-time */ -} snd_seq_timestamp_t; - -/** - * Event mode flags - * - * NOTE: only 8 bits available! - */ -#define SND_SEQ_TIME_STAMP_TICK (0<<0) /**< timestamp in clock ticks */ -#define SND_SEQ_TIME_STAMP_REAL (1<<0) /**< timestamp in real time */ -#define SND_SEQ_TIME_STAMP_MASK (1<<0) /**< mask for timestamp bits */ - -#define SND_SEQ_TIME_MODE_ABS (0<<1) /**< absolute timestamp */ -#define SND_SEQ_TIME_MODE_REL (1<<1) /**< relative to current time */ -#define SND_SEQ_TIME_MODE_MASK (1<<1) /**< mask for time mode bits */ - -#define SND_SEQ_EVENT_LENGTH_FIXED (0<<2) /**< fixed event size */ -#define SND_SEQ_EVENT_LENGTH_VARIABLE (1<<2) /**< variable event size */ -#define SND_SEQ_EVENT_LENGTH_VARUSR (2<<2) /**< variable event size - user memory space */ -#define SND_SEQ_EVENT_LENGTH_MASK (3<<2) /**< mask for event length bits */ - -#define SND_SEQ_PRIORITY_NORMAL (0<<4) /**< normal priority */ -#define SND_SEQ_PRIORITY_HIGH (1<<4) /**< event should be processed before others */ -#define SND_SEQ_PRIORITY_MASK (1<<4) /**< mask for priority bits */ - -/** Note event */ -typedef struct snd_seq_ev_note { - unsigned char channel; /**< channel number */ - unsigned char note; /**< note */ - unsigned char velocity; /**< velocity */ - unsigned char off_velocity; /**< note-off velocity; only for #SND_SEQ_EVENT_NOTE */ - unsigned int duration; /**< duration until note-off; only for #SND_SEQ_EVENT_NOTE */ -} snd_seq_ev_note_t; - -/** Controller event */ -typedef struct snd_seq_ev_ctrl { - unsigned char channel; /**< channel number */ - unsigned char unused[3]; /**< reserved */ - unsigned int param; /**< control parameter */ - signed int value; /**< control value */ -} snd_seq_ev_ctrl_t; - -/** generic set of bytes (12x8 bit) */ -typedef struct snd_seq_ev_raw8 { - unsigned char d[12]; /**< 8 bit value */ -} snd_seq_ev_raw8_t; - -/** generic set of integers (3x32 bit) */ -typedef struct snd_seq_ev_raw32 { - unsigned int d[3]; /**< 32 bit value */ -} snd_seq_ev_raw32_t; - -/** external stored data */ -typedef struct snd_seq_ev_ext { - unsigned int len; /**< length of data */ - void *ptr; /**< pointer to data (note: can be 64-bit) */ -} __attribute__((packed)) snd_seq_ev_ext_t; - -/** Instrument cluster type */ -typedef unsigned int snd_seq_instr_cluster_t; - -/** Instrument type */ -typedef struct snd_seq_instr { - snd_seq_instr_cluster_t cluster; /**< cluster id */ - unsigned int std; /**< instrument standard id; the upper byte means a private instrument (owner - client id) */ - unsigned short bank; /**< instrument bank id */ - unsigned short prg; /**< instrument program id */ -} snd_seq_instr_t; - -/** sample number */ -typedef struct snd_seq_ev_sample { - unsigned int std; /**< sample standard id */ - unsigned short bank; /**< sample bank id */ - unsigned short prg; /**< sample program id */ -} snd_seq_ev_sample_t; - -/** sample cluster */ -typedef struct snd_seq_ev_cluster { - snd_seq_instr_cluster_t cluster; /**< cluster id */ -} snd_seq_ev_cluster_t; - -/** sample position */ -typedef unsigned int snd_seq_position_t; /**< playback position (in samples) * 16 */ - -/** sample stop mode */ -typedef enum snd_seq_stop_mode { - SND_SEQ_SAMPLE_STOP_IMMEDIATELY = 0, /**< terminate playing immediately */ - SND_SEQ_SAMPLE_STOP_VENVELOPE = 1, /**< finish volume envelope */ - SND_SEQ_SAMPLE_STOP_LOOP = 2 /**< terminate loop and finish wave */ -} snd_seq_stop_mode_t; - -/** sample frequency */ -typedef int snd_seq_frequency_t; /**< playback frequency in HZ * 16 */ - -/** sample volume control; if any value is set to -1 == do not change */ -typedef struct snd_seq_ev_volume { - signed short volume; /**< range: 0-16383 */ - signed short lr; /**< left-right balance; range: 0-16383 */ - signed short fr; /**< front-rear balance; range: 0-16383 */ - signed short du; /**< down-up balance; range: 0-16383 */ -} snd_seq_ev_volume_t; - -/** simple loop redefinition */ -typedef struct snd_seq_ev_loop { - unsigned int start; /**< loop start (in samples) * 16 */ - unsigned int end; /**< loop end (in samples) * 16 */ -} snd_seq_ev_loop_t; - -/** Sample control events */ -typedef struct snd_seq_ev_sample_control { - unsigned char channel; /**< channel */ - unsigned char unused[3]; /**< reserved */ - union { - snd_seq_ev_sample_t sample; /**< sample number */ - snd_seq_ev_cluster_t cluster; /**< cluster number */ - snd_seq_position_t position; /**< position */ - snd_seq_stop_mode_t stop_mode; /**< stop mode */ - snd_seq_frequency_t frequency; /**< frequency */ - snd_seq_ev_volume_t volume; /**< volume */ - snd_seq_ev_loop_t loop; /**< loop control */ - unsigned char raw8[8]; /**< raw 8-bit */ - } param; /**< control parameters */ -} snd_seq_ev_sample_control_t; - -/** INSTR_BEGIN event */ -typedef struct snd_seq_ev_instr_begin { - int timeout; /**< zero = forever, otherwise timeout in ms */ -} snd_seq_ev_instr_begin_t; - -/** Result events */ -typedef struct snd_seq_result { - int event; /**< processed event type */ - int result; /**< status */ -} snd_seq_result_t; - -/** Queue skew values */ -typedef struct snd_seq_queue_skew { - unsigned int value; /**< skew value */ - unsigned int base; /**< skew base */ -} snd_seq_queue_skew_t; - -/** queue timer control */ -typedef struct snd_seq_ev_queue_control { - unsigned char queue; /**< affected queue */ - unsigned char unused[3]; /**< reserved */ - union { - signed int value; /**< affected value (e.g. tempo) */ - snd_seq_timestamp_t time; /**< time */ - unsigned int position; /**< sync position */ - snd_seq_queue_skew_t skew; /**< queue skew */ - unsigned int d32[2]; /**< any data */ - unsigned char d8[8]; /**< any data */ - } param; /**< data value union */ -} snd_seq_ev_queue_control_t; - -/** Sequencer event */ -typedef struct snd_seq_event { - snd_seq_event_type_t type; /**< event type */ - unsigned char flags; /**< event flags */ - unsigned char tag; /**< tag */ - - unsigned char queue; /**< schedule queue */ - snd_seq_timestamp_t time; /**< schedule time */ - - snd_seq_addr_t source; /**< source address */ - snd_seq_addr_t dest; /**< destination address */ - - union { - snd_seq_ev_note_t note; /**< note information */ - snd_seq_ev_ctrl_t control; /**< MIDI control information */ - snd_seq_ev_raw8_t raw8; /**< raw8 data */ - snd_seq_ev_raw32_t raw32; /**< raw32 data */ - snd_seq_ev_ext_t ext; /**< external data */ - snd_seq_ev_queue_control_t queue; /**< queue control */ - snd_seq_timestamp_t time; /**< timestamp */ - snd_seq_addr_t addr; /**< address */ - snd_seq_connect_t connect; /**< connect information */ - snd_seq_result_t result; /**< operation result code */ - snd_seq_ev_instr_begin_t instr_begin; /**< instrument */ - snd_seq_ev_sample_control_t sample; /**< sample control */ - } data; /**< event data... */ -} snd_seq_event_t; - -/** \} */ - -#endif /* __ALSA_SEQ_EVENT_H */ - diff -Nru csound-5.17.11~dfsg/Opcodes/eqfil.c csound-6.02~dfsg/Opcodes/eqfil.c --- csound-5.17.11~dfsg/Opcodes/eqfil.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/eqfil.c 2014-01-07 16:53:48.000000000 +0000 @@ -23,9 +23,7 @@ // #include "csdl.h" #include "csoundCore.h" -#ifdef PARCS #include "interlocks.h" -#endif typedef struct _equ { OPDS h; @@ -40,7 +38,7 @@ static int equ_init(CSOUND *csound, equ *p) { if (*p->ini==0) { - double sr = (double)csound->GetSr(csound); + double sr = (double)CS_ESR; p->z1 = p->z2 = 0.0; p->frv = *p->fr; p->bwv = *p->bw; p->d = cos(2*PI*p->frv/sr); @@ -54,10 +52,12 @@ { double z1 = p->z1, z2 = p->z2,c,d,w,a,y; MYFLT *in= p->sig,*out=p->out,g; - int i, ksmps = csound->GetKsmps(csound); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + int i, ksmps = CS_KSMPS; if (*p->bw != p->bwv || *p->fr != p->frv){ - double sr = (double)csound->GetSr(csound); + double sr = (double)CS_ESR; p->frv = *p->fr; p->bwv = *p->bw; p->d = cos(2*PI*p->frv/sr); p->c = tan(PI*p->bwv/sr); @@ -67,7 +67,12 @@ a = (1.0-c)/(1.0+c); g = *p->g; - for(i=0; i < ksmps; i++){ + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + ksmps -= early; + memset(&out[ksmps], '\0', early*sizeof(MYFLT)); + } + for (i=0; i < ksmps; i++){ w = (double)(in[i]) + d*(1.0 + a)*z1 - a*z2; y = w*a - d*(1.0 + a)*z1 + z2; z2 = z1; @@ -82,8 +87,8 @@ } static OENTRY eqfil_localops[] = { - {"eqfil", sizeof(equ), 5, + {"eqfil", sizeof(equ), 0, 5, "a", "akkko", (SUBR)equ_init, NULL, (SUBR)equ_process}, }; -LINKAGE1(eqfil_localops) +LINKAGE_BUILTIN(eqfil_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/fareygen.c csound-6.02~dfsg/Opcodes/fareygen.c --- csound-5.17.11~dfsg/Opcodes/fareygen.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/fareygen.c 2014-01-07 16:53:48.000000000 +0000 @@ -73,11 +73,11 @@ va_end(args); csound->Message(csound, "f%3.0f %8.2f %8.2f ", ff->e.p[1], ff->e.p2orig, ff->e.p3orig); - if (ff->e.p[4] == SSTRCOD) - csound->Message(csound, "%s", ff->e.strarg); + if (ISSTRCOD(ff->e.p[4])) + csound->Message(csound, ff->e.strarg); else csound->Message(csound, "%8.2f", ff->e.p[4]); - if (ff->e.p[5] == SSTRCOD) + if (ISSTRCOD(ff->e.p[5])) csound->Message(csound, " \"%s\" ...\n", ff->e.strarg); else csound->Message(csound, "%8.2f ...\n", ff->e.p[5]); @@ -131,7 +131,7 @@ int j, fareyseq, nvals, nargs, farey_length, mode; MYFLT *fp = ftp->ftable, *pp, *pp2; - CSOUND *csound = ff->csound; + //CSOUND *csound = ff->csound; RATIO *flist; nvals = ff->flen; @@ -144,7 +144,7 @@ fareyseq = (int) *pp; pp2 = &(ff->e.p[6]); mode = (int) *pp2; - farey_length = FareyLength (fareyseq); + farey_length = FareyLength(fareyseq); flist = (RATIO*) calloc(farey_length, sizeof(RATIO)); GenerateFarey (fareyseq, flist, farey_length); @@ -201,7 +201,6 @@ { int i; PFACTOR p[MAX_PFACTOR]; - int pcount; MYFLT result; if (n == 1) @@ -213,7 +212,7 @@ /* p[i].expon = 0; */ /* p[i].base = 0; */ /* } */ - pcount = PrimeFactors (n, p); + (void)PrimeFactors (n, p); result = (MYFLT) n; for (i = 0; i < MAX_PFACTOR; i++) { @@ -297,5 +296,4 @@ { NULL, NULL } }; -FLINKAGE1(farey_fgens) - +FLINKAGE_BUILTIN(farey_fgens) diff -Nru csound-5.17.11~dfsg/Opcodes/fareyseq.c csound-6.02~dfsg/Opcodes/fareyseq.c --- csound-5.17.11~dfsg/Opcodes/fareyseq.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/fareyseq.c 2014-01-07 16:53:48.000000000 +0000 @@ -247,12 +247,12 @@ /* Check the state of the two table number variables. * Error message if any are < 1 and no further action. */ if (UNLIKELY((*p->dft < 1) || (*p->sft < 1))) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Farey: Table no. < 1 dft=%.2f sft=%.2f"), *p->dft, *p->sft); } if (UNLIKELY((*p->ftype < 1))) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Farey: Filter type < 1 dft=%.2f sft=%.2f"), *p->ftype); } @@ -267,7 +267,7 @@ */ if (UNLIKELY((p->funcd = csound->FTFindP(csound, p->dft)) == NULL)) { return - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str("Farey: Destination dft table %.2f not found."), *p->dft); } @@ -278,7 +278,7 @@ /* Source */ if (p->psft != (int)*p->sft) { if (UNLIKELY((p->funcs = csound->FTFindP(csound, p->sft)) == NULL)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Farey: Source sft table %.2f not found."), *p->sft); } @@ -302,7 +302,7 @@ *p->dft, *p->sft); } if (UNLIKELY((*p->ftype < 1))) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Farey: Filter type < 1"), *p->ftype); } @@ -313,7 +313,7 @@ if (p->pdft != (int)*p->dft) { /* Get pointer to the function table data structure. * csoundFTFindP() for perf time. csoundFTFind() for init time. */ - if (UNLIKELY((p->funcd = csound->FTFind(csound, p->dft)) == NULL)) { + if (UNLIKELY((p->funcd = csound->FTnp2Find(csound, p->dft)) == NULL)) { return csound->InitError(csound, Str("Farey: Destination dft table %.2f not found."), @@ -325,7 +325,7 @@ } /* Source */ if (p->psft != (int)*p->sft) { - if (UNLIKELY((p->funcs = csound->FTFind(csound, p->sft)) == NULL)) { + if (UNLIKELY((p->funcs = csound->FTnp2Find(csound, p->sft)) == NULL)) { return csound->InitError(csound, Str("Farey: Source sft table %.2f not found."), *p->sft); @@ -357,12 +357,12 @@ MYFLT threshold; int32 ftype; MYFLT previous = FL(0.0); - int32 sourcelength; + //int32 sourcelength; ftype = (int32) *p->ftype; threshold = Digest (*p->threshold); loopcount = p->funcd->flen; - sourcelength = loopcount; + //sourcelength = loopcount; /* Now get the base addresses and length masks of the tables. */ based = p->funcd->ftable; @@ -441,7 +441,7 @@ int tableshuffle (CSOUND * csound, TABSHUFFLE *p) { if (UNLIKELY(*p->sft < 1)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Table no. < 1 sft=%.2f"), *p->sft); } @@ -449,7 +449,7 @@ /* Source */ if (p->psft != (int)*p->sft) { if (UNLIKELY((p->funcs = csound->FTFindP(csound, p->sft)) == NULL)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Source sft table %.2f not found."), *p->sft); } @@ -462,7 +462,7 @@ int tableishuffle (CSOUND *csound, TABSHUFFLE *p) { if (UNLIKELY(*p->sft < 1)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Table no. < 1 sft=%.2f"), *p->sft); } @@ -470,7 +470,7 @@ /* Source */ if (p->psft != (int)*p->sft) { - if (UNLIKELY((p->funcs = csound->FTFind(csound, p->sft)) == NULL)) { + if (UNLIKELY((p->funcs = csound->FTnp2Find(csound, p->sft)) == NULL)) { return csound->InitError(csound, Str("Source sft table %.2f not found."), *p->sft); @@ -490,19 +490,19 @@ { time_t now; unsigned int seed = (unsigned int) time (&now); - srand (seed); MYFLT *bases; /* Base address of the source table.*/ + MYFLT *temp; int32 sourcelength; int32 i = 0; + srand (seed); sourcelength = p->funcs->flen; /* Now get the base address of the table. */ bases = p->funcs->ftable; - MYFLT* temp; - temp = (MYFLT*) calloc (sourcelength, sizeof(MYFLT)); + temp = (MYFLT*) calloc (sourcelength, sizeof(MYFLT)); memset (temp, 0, sizeof(MYFLT) * sourcelength); for (i = 0; i < sourcelength; i++) { @@ -532,7 +532,7 @@ int EulerPhi (int n) { int i = 0; - int pcount; + //int pcount; MYFLT result; PFACTOR p[MAX_PFACTOR]; memset(p, 0, sizeof(PFACTOR)*MAX_PFACTOR); @@ -541,7 +541,7 @@ return 1; if (n == 0) return 0; - pcount = PrimeFactors (n, p); + (void)PrimeFactors (n, p); result = (MYFLT)n; for (i = 0; i < MAX_PFACTOR; i++) { @@ -733,13 +733,15 @@ #define S sizeof static OENTRY fareyseq_localops[] = { - {"tablefilteri", S (TABFILT),TB|1, "i", "iiii", (SUBR) tableifilter,NULL,NULL}, - {"tablefilter", S (TABFILT), TB|2, "k", "kkkk", - (SUBR) tablefilterset, (SUBR) tablefilter, NULL}, - {"fareyleni", S (FAREYLEN), TR|1, "i", "i", (SUBR) fareylen, NULL, NULL}, - {"fareylen", S (FAREYLEN), TR|2, "k", "k", NULL, (SUBR) fareylen, NULL}, - {"tableshufflei", S (TABSHUFFLE), TB|1, "", "i", (SUBR) tableshuffle, NULL, NULL}, - {"tableshuffle", S (TABSHUFFLE), TB|2, "", "k", (SUBR) tableshuffleset, (SUBR) tableshuffle, NULL}, + {"tablefilteri", S(TABFILT),TB, 1, "i", "iiii", (SUBR) tableifilter,NULL,NULL}, + {"tablefilter", S(TABFILT), TB, 2, "k", "kkkk", + (SUBR) tablefilterset, (SUBR) tablefilter, NULL}, + {"fareyleni", S(FAREYLEN), TR, 1, "i", "i", (SUBR) fareylen, NULL, NULL}, + {"fareylen", S(FAREYLEN), TR, 2, "k", "k", NULL, (SUBR) fareylen, NULL}, + {"tableshufflei", S(TABSHUFFLE), TB, 1, "", "i", + (SUBR) tableshuffle, NULL, NULL}, + {"tableshuffle", S(TABSHUFFLE), TB, 2, "", "k", + (SUBR) tableshuffleset, (SUBR) tableshuffle, NULL}, }; -LINKAGE1(fareyseq_localops) +LINKAGE_BUILTIN(fareyseq_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/faustgen.cpp csound-6.02~dfsg/Opcodes/faustgen.cpp --- csound-5.17.11~dfsg/Opcodes/faustgen.cpp 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/faustgen.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,713 @@ +/* faustgen.cpp + + (c) Victor Lazzarini, 2013 + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + + Faust Csound opcodes + + These four opcodes allow Faust to be embedded in Csound code: + + faustcompile: compiles a Faust program + faustaudio: creates a DSP instance from a compiled Faust program + (any number of instances from a single compiled program are + allowed) + faustctl: sets the value of a given control of a Faust DSP instance + + faustgen: compiles and creates a single DSP instance from a Faust program + (convenient for one-off Faust programs) + + +*/ +#include "csdl.h" +#include "faust/llvm-dsp.h" +#include "faust/gui/UI.h" +#define MAXARG 40 + +/** + * Faust controls class for Csound + * + **/ +class controls : public UI { + + struct ctl { + MYFLT *zone; + char label[64]; + MYFLT min, max; + ctl *nxt; + } anchor; + + void addctl(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT min, FAUSTFLOAT max){ + ctl *pctl = &anchor; + while(pctl->nxt) pctl = pctl->nxt; + pctl->nxt = new ctl; + pctl = pctl->nxt; + strncpy(pctl->label,label, 63); + pctl->zone = zone; + pctl->min = min; + pctl->max = max; + pctl->nxt = NULL; + } + +public: + controls() { anchor.nxt = NULL; anchor.label[0] = '\0';} + ~controls() { + ctl *pctl = &anchor, *tmp; + pctl = pctl->nxt; + while(pctl) { + tmp = pctl; + pctl = pctl->nxt; + delete tmp; + } + } + + virtual void openTabBox(const char* label) {}; + virtual void openHorizontalBox(const char* label) {}; + virtual void openVerticalBox(const char* label) {}; + virtual void closeBox() {}; + + virtual void addButton(const char* label, FAUSTFLOAT* zone) { + addctl(label, zone, 0, 0); + } + virtual void addCheckButton(const char* label, FAUSTFLOAT* zone){ + addctl(label, zone, 0, 0); + } + virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT init, FAUSTFLOAT min, + FAUSTFLOAT max, FAUSTFLOAT step){ + addctl(label, zone, min, max); + } + virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT init, FAUSTFLOAT min, + FAUSTFLOAT max, FAUSTFLOAT step) { + addctl(label, zone, min, max); + } + virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT init, FAUSTFLOAT min, + FAUSTFLOAT max, FAUSTFLOAT step) { + addctl(label, zone, min, max); + } + virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT min, FAUSTFLOAT max){}; + virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, + FAUSTFLOAT min, FAUSTFLOAT max) {}; + + MYFLT *getZone(char *label){ + ctl *pctl = &anchor; + pctl = pctl->nxt; + while(pctl){ + if(strcmp(pctl->label, label) == 0) break; + pctl = pctl->nxt; + } + if(pctl) + return pctl->zone; + else return NULL; + } + MYFLT getMax(char *label){ + ctl *pctl = &anchor; + pctl = pctl->nxt; + while(pctl){ + if(strcmp(pctl->label, label) == 0) break; + pctl = pctl->nxt; + } + if(pctl) + return pctl->max; + else return 0; + } + MYFLT getMin(char *label){ + ctl *pctl = &anchor; + pctl = pctl->nxt; + while(pctl){ + if(strcmp(pctl->label, label) == 0) break; + pctl = pctl->nxt; + } + if(pctl) + return pctl->min; + else return 0; + } + +}; + +/** + * Faust object handle + * + **/ +struct faustobj { + void *obj; + controls *ctls; + faustobj *nxt; + unsigned long cnt; +}; + +/** + * Faust compile opcode + + usage: + ihandle faustcompile Scode, Sargs[,istacksize] + + ihandle - handle to compiled code + Scode - Faust program + Sargs - Faust compiler args + istacksize - compiler stack size in megabytes (default 1MB). + +**/ +struct faustcompile { + OPDS h; + MYFLT *hptr; + STRINGDAT *code; + STRINGDAT *args; + MYFLT *stacksize; + llvm_dsp_factory *factory; +}; + +char **parse_cmd(char *str, int *argc){ + char **argv; int i = 0, n=0, end = strlen(str); + while(str[i] == ' ') i++; + if(str[i] != '\0') *argc = 1; + while(str[i] != '\0'){ + if(str[i] == ' ') { + while (str[++i] == ' '); + if(str[i] == '\0') break; + (*argc)++; + } + i++; + } + argv = (char **) calloc(sizeof(char *), *argc); + i = 0; + while(str[i] == ' ') i++; + for(n=0; n < *argc && i < end; n++) { + argv[n] = &(str[i]); + while(str[++i] != ' ' && i < end); + if(i >= end) break; + str[i] = '\0'; + while(str[++i] == ' ' && i < end); + } + return argv; +} + +int delete_faustcompile(CSOUND *csound, void *p) { + + faustcompile *pp = ((faustcompile *) p); + faustobj *fobj, *prv, **pfobj; + pfobj = (faustobj **) csound->QueryGlobalVariable(csound,"::factory"); + fobj = *pfobj; + prv = fobj; + while(fobj != NULL) { + if(fobj->obj == (void *) pp->factory) { + prv->nxt = fobj->nxt; + break; + } + prv = fobj; + fobj = fobj->nxt; + } + if(fobj != NULL) { + if(*pfobj == fobj) *pfobj = fobj->nxt; + deleteDSPFactory(pp->factory); + csound->Free(csound, fobj); + } + return OK; +} + +struct hdata { + faustcompile *p; + CSOUND *csound; +}; + +void *init_faustcompile_thread(void *pp) { + + faustcompile *p = ((hdata *) pp)->p; + faustobj **pffactory, *ffactory; + CSOUND *csound = ((hdata *) pp)->csound; + llvm_dsp_factory *factory; + int argc = 0; + char err_msg[256]; + char *cmd = (char *) malloc(p->args->size + 8); + int ret; + + strcpy(cmd, p->args->data); +#ifdef USE_DOUBLE + strcat(cmd, " -double"); +#endif + const char **argv = (const char **) parse_cmd(cmd, &argc); + const char* varname = "::factory"; + + + factory = createDSPFactory(argc, argv, "", + "", "faustop", (const char *) p->code->data, + "", err_msg, 3); + if(factory == NULL) { + csound->Message(csound, + Str("\nFaust compilation problem:\nline %s\n"), + &(err_msg[1])); + *(p->hptr) = FL(-2.0); // error code. + free(argv); + free(cmd); + free(pp); + ret = -1; + pthread_exit(&ret); + } + + pffactory = (faustobj **) csound->QueryGlobalVariable(csound,varname); + if(pffactory == NULL) { + csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); + pffactory = (faustobj **) csound->QueryGlobalVariable(csound,varname); + ffactory = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + ffactory->obj = factory; + ffactory->nxt = NULL; + ffactory->cnt = 0; + *pffactory = ffactory; + } + else { + ffactory = *pffactory; + while(ffactory->nxt){ + ffactory = ffactory->nxt; + } + ffactory->nxt = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + ffactory->nxt->cnt = ffactory->cnt+1; + ffactory = ffactory->nxt; + ffactory->obj = factory; + } + p->factory = factory; + *p->hptr = (MYFLT) ffactory->cnt; + csound->RegisterResetCallback(csound, p, delete_faustcompile); + free(argv); + free(cmd); + free(pp); + return NULL; +} + +#define MBYTE 1048576 +int init_faustcompile(CSOUND *csound, faustcompile *p){ + pthread_t thread; + pthread_attr_t attr; + hdata *data = (hdata *) malloc(sizeof(hdata)); + data->csound = csound; + data->p = p; + *p->hptr = -1; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, *p->stacksize*MBYTE); + pthread_create(&thread, &attr,init_faustcompile_thread, data); + return OK; +} + +/** + * faustgen and faustaudio opcodes + + usage: + ihandle[,asig1,...] faustgen Scode[,ain1,...] + ihandle[,asig1,...] faustaudio ifactory,[,ain1,...] + + Scode - Faust program + ifactory - handle pointing to compiled code from faustcompile + asig1 ... - audio outputs from Faust program + ain1 ... - audio inputs to Faust program + + ihandle - handle identifying this Faust DSP instance + +**/ +struct faustgen { + OPDS h; + MYFLT *ohptr; + MYFLT *outs[MAXARG]; /* outputs */ + STRINGDAT *code; /* faust code as string */ + MYFLT *ins[VARGMAX]; /* inputs */ + llvm_dsp *engine; /* faust DSP */ + llvm_dsp_factory* factory; /* DSP factory */ + controls *ctls; + AUXCH memin; + AUXCH memout; +}; + +struct hdata2 { + faustgen *p; + CSOUND *csound; +}; + +/* deinit function + delete faust objects +*/ +int delete_faustgen(CSOUND *csound, void *p) { + faustgen *pp = (faustgen *) p; + faustobj *fobj, *prv, **pfobj; + pfobj = (faustobj **) csound->QueryGlobalVariable(csound,"::dsp"); + fobj = *pfobj; + prv = fobj; + while(fobj != NULL) { + if(fobj->obj == (void *) pp->engine) { + prv->nxt = fobj->nxt; + break; + } + prv = fobj; + fobj = fobj->nxt; + } + if(fobj == NULL) + if(fobj != NULL) { + if(*pfobj == fobj) *pfobj = fobj->nxt; + csound->Free(csound, fobj); + delete pp->ctls; + deleteDSPInstance(pp->engine); + } else + csound->Warning(csound, + Str("could not find DSP %p for deletion"), pp->engine); + if(pp->factory) delete pp->factory; + return OK; +} + +int init_faustaudio(CSOUND *csound, faustgen *p){ + int factory; + OPARMS parms; + faustobj *fobj, **fobjp, **pfdsp, *fdsp; + llvm_dsp *dsp; + controls *ctls = new controls(); + const char *varname = "::dsp"; +#if defined(MACOSX) || defined(linux) || defined(HAIKU) + while((int) *((MYFLT *)p->code) == -1) usleep(1); +#else + while((int) *((MYFLT *)p->code) == -1) Sleep(1); +#endif + + factory = (int) *((MYFLT *)p->code); + + if(factory == -2) + return + csound->InitError(csound, + Str("Faust code did not compile properly.\n" + "Check above messages for Faust compiler errors\n")); + + fobjp = (faustobj **) csound->QueryGlobalVariable(csound,"::factory"); + if(fobj == NULL) + return csound->InitError(csound, + Str("no factory available\n")); + fobj = *fobjp; + while(fobj->cnt != factory) { + fobj = fobj->nxt; + if(fobj == NULL) + return csound->InitError(csound, + Str("factory not found %d\n"), (int) factory); + } + + dsp = createDSPInstance((llvm_dsp_factory *)fobj->obj); + if(dsp == NULL) + return csound->InitError(csound, Str("Faust instantiation problem \n")); + + dsp->buildUserInterface(ctls); + pfdsp = (faustobj **) csound->QueryGlobalVariable(csound,varname); + if(pfdsp == NULL) { + csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); + pfdsp = (faustobj **) csound->QueryGlobalVariable(csound,varname); + fdsp = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + fdsp->obj = dsp; + fdsp->ctls = ctls; + fdsp->nxt = NULL; + fdsp->cnt = 0; + *pfdsp = fdsp; + } + else { + fdsp = *pfdsp; + while(fdsp->nxt){ + fdsp = fdsp->nxt; + } + + fdsp->nxt = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + fdsp->nxt->cnt = fdsp->cnt+1; + fdsp = fdsp->nxt; + fdsp->obj = dsp; + fdsp->ctls = ctls; + } + + p->factory = NULL; // this opcode does not own the factory + p->engine = (llvm_dsp *) fdsp->obj; + p->engine->init(csound->GetSr(csound)); + + if(p->engine->getNumInputs() != p->INCOUNT-1) { + deleteDSPInstance(p->engine); + return csound->InitError(csound, Str("wrong number of input args\n")); + } + if(p->engine->getNumOutputs() != p->OUTCOUNT-1){ + deleteDSPInstance(p->engine); + return csound->InitError(csound, Str("wrong number of output args\n")); + } + + /* memory for sampAccurate offsets */ + csound->GetOParms(csound, &parms); + if(parms.sampleAccurate){ + int size; + size = p->engine->getNumInputs()*sizeof(MYFLT *); + if(p->memin.auxp == NULL || + p->memin.size < size) + csound->AuxAlloc(csound, size, &p->memin); + size = p->engine->getNumOutputs()*sizeof(MYFLT *); + if(p->memout.auxp == NULL || + p->memout.size < size) + csound->AuxAlloc(csound, size, &p->memout); + } + p->ctls = ctls; + csound->RegisterDeinitCallback(csound, p, delete_faustgen); + *p->ohptr = (MYFLT) fdsp->cnt; + return OK; +} + +void *init_faustgen_thread(void *pp){ + CSOUND *csound = ((hdata2 *) pp)->csound; + faustgen *p = ((hdata2 *) pp)->p; + OPARMS parms; + char err_msg[256]; + int size; + int argc = 3; + const char* argv[argc]; + faustobj **pfdsp, *fdsp; + llvm_dsp *dsp; + controls *ctls = new controls(); + const char *varname = "::dsp"; + argv[0] = "-vec"; + argv[1] = "-lv"; + argv[2] = " 1"; + p->engine == NULL; + +#ifdef USE_DOUBLE + argv[3] = "-double"; + argc += 1; +#endif + + p->factory = createDSPFactory(argc, argv, "", + "", "faustop", (const char *) p->code->data, + "", err_msg, 3); + if(p->factory == NULL) { + int ret = csound->InitError(csound, + Str("Faust compilation problem: %s\n"), err_msg); + free(pp); + pthread_exit(&ret); + } + + dsp = createDSPInstance(p->factory); + if(dsp == NULL) { + int ret = csound->InitError(csound, Str("Faust instantiation problem \n")); + free(pp); + pthread_exit(&ret); + } + + dsp->buildUserInterface(ctls); + + pfdsp = (faustobj **) csound->QueryGlobalVariable(csound,varname); + if(pfdsp == NULL) { + csound->CreateGlobalVariable(csound, varname, sizeof(faustobj *)); + pfdsp = (faustobj **) csound->QueryGlobalVariable(csound,varname); + fdsp = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + fdsp->obj = dsp; + fdsp->ctls = ctls; + fdsp->nxt = NULL; + fdsp->cnt = 0; + *pfdsp = fdsp; + } + else { + fdsp = *pfdsp; + while(fdsp->nxt){ + fdsp = fdsp->nxt; + } + fdsp->nxt = (faustobj *) csound->Calloc(csound, sizeof(faustobj)); + fdsp->nxt->cnt = fdsp->cnt++; + fdsp = fdsp->nxt; + fdsp->obj = dsp; + fdsp->ctls = ctls; + } + + p->engine = dsp; + dsp->buildUserInterface(ctls); + dsp->init(csound->GetSr(csound)); + if(p->engine->getNumInputs() != p->INCOUNT-1) { + int ret; + deleteDSPInstance(p->engine); + deleteDSPFactory(p->factory); + free(pp); + ret =csound->InitError(csound, Str("wrong number of input args\n")); + p->engine = NULL; + pthread_exit(&ret); + } + if(p->engine->getNumOutputs() != p->OUTCOUNT-1){ + int ret; + deleteDSPInstance(p->engine); + deleteDSPFactory(p->factory); + free(pp); + ret = csound->InitError(csound, Str("wrong number of output args\n")); + p->engine = NULL; + pthread_exit(&ret); + } + + /* memory for sampAccurate offsets */ + csound->GetOParms(csound, &parms); + if(parms.sampleAccurate){ + int size; + size = p->engine->getNumInputs()*sizeof(MYFLT *); + if(p->memin.auxp == NULL || + p->memin.size < size) + csound->AuxAlloc(csound, size, &p->memin); + size = p->engine->getNumOutputs()*sizeof(MYFLT *); + if(p->memout.auxp == NULL || + p->memout.size < size) + csound->AuxAlloc(csound, size, &p->memout); + } + p->ctls = ctls; + *p->ohptr = (MYFLT) fdsp->cnt; + csound->RegisterDeinitCallback(csound, p, delete_faustgen); + free(pp); + return NULL; +} + +int init_faustgen(CSOUND *csound, faustgen *p){ + pthread_t thread; + pthread_attr_t attr; + int *ret; + hdata2 *data = (hdata2 *) malloc(sizeof(hdata2)); + data->csound = csound; + data->p = p; + pthread_attr_init(&attr); + pthread_attr_setstacksize(&attr, MBYTE); + pthread_create(&thread, &attr, init_faustgen_thread, data); + pthread_join(thread, (void **) &ret); + if(ret == NULL) return OK; + else return NOTOK; +} + +int perf_faust(CSOUND *csound, faustgen *p){ + int nsmps = CS_KSMPS, i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + MYFLT **in_tmp = (MYFLT **) p->memin.auxp; + MYFLT **out_tmp = (MYFLT **) p->memout.auxp; + AVOIDDENORMALS; + + if (UNLIKELY(early)) { + for (i = 0; i < p->OUTCOUNT-1; i++) + memset(p->outs[i], '\0', nsmps*sizeof(MYFLT)); + nsmps -= early; + } + if(UNLIKELY(offset)) { + /* offset pointers, save current pos */ + for (i = 0; i < p->OUTCOUNT-1; i++){ + memset(p->outs[i], '\0', nsmps*sizeof(MYFLT)); + out_tmp[i] = p->outs[i]; + p->outs[i] = &(p->outs[i][offset]); + } + for (i = 0; i < p->INCOUNT-1; i++){ + in_tmp[i] = p->ins[i]; + p->ins[i] = &(p->ins[i][offset]); + } + nsmps -= offset; + } + p->engine->compute(nsmps, p->ins, p->outs); + + if(UNLIKELY(offset)) { + /* restore pos */ + for (i = 0; i < p->OUTCOUNT-1; i++) + p->outs[i] = out_tmp[i]; + for (i = 0; i < p->INCOUNT-1; i++) + p->ins[i] = in_tmp[i]; + } + return OK; +} + +/** + * faustctl opcode + + usage: + faustctl idsp, Slabel, kval + + idsp - handle from an existing Faust DSP instance + Slabel - name of control (in Faust program) + kval - value to be sent to control + +**/ +struct faustctl { + OPDS h; + MYFLT *inst; + STRINGDAT *label; + MYFLT *val; + MYFLT *zone; + MYFLT min, max; +}; + +int init_faustctl(CSOUND *csound, faustctl *p){ + + faustobj *fobj, **fobjp; + int instance = (int) *p->inst; + + fobjp = (faustobj **) csound->QueryGlobalVariable(csound,"::dsp"); + if(fobjp == NULL) + return csound->InitError(csound, + Str("no dsp instances available\n")); + fobj = *fobjp; + + while(fobj->cnt != instance) { + fobj = fobj->nxt; + if(fobj == NULL) + return csound->InitError(csound, + Str("dsp instance not found %d\n"), (int) *p->inst); + } + p->zone = fobj->ctls->getZone(p->label->data); + if(p->zone == NULL) + return csound->InitError(csound, + Str("dsp control %s not found\n"), p->label->data); + p->max = fobj->ctls->getMax(p->label->data); + p->min = fobj->ctls->getMin(p->label->data); + { + MYFLT val = *p->val; + if(p->min != p->max) + val = val < p->min ? p->min : (val > p->max ? p->max : val); + *p->zone = val; + } + return OK; +} + +int perf_faustctl(CSOUND *csound, faustctl *p) { + MYFLT val = *p->val; + if(p->min != p->max) + val = val < p->min ? p->min : (val > p->max ? p->max : val); + *p->zone = val; + return OK; +} + + +#define S(x) sizeof(x) + +static OENTRY localops[] = { + { (char *) "faustgen", S(faustgen), 0, 5, + (char *) "immmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + (char *)"SM",(SUBR)init_faustgen, NULL, (SUBR)perf_faust}, + { (char *) "faustcompile", S(faustcompile), 0, 1, + (char *) "i", + (char *)"SSp",(SUBR)init_faustcompile, NULL, NULL}, + { (char *) "faustaudio", S(faustgen), 0, 5, + (char *) "immmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + (char *)"iM",(SUBR)init_faustaudio, NULL, (SUBR)perf_faust}, + { (char *) "faustctl", S(faustgen), 0, 3, + (char *) "", + (char *)"iSk",(SUBR)init_faustctl, (SUBR) perf_faustctl} +}; + +PUBLIC long csound_opcode_init(CSOUND *csound, OENTRY **ep) +{ + IGN(csound); + *ep = localops; + return (long) sizeof(localops); +} + +PUBLIC int csoundModuleInfo(void) +{ + return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); +} diff -Nru csound-5.17.11~dfsg/Opcodes/filter.c csound-6.02~dfsg/Opcodes/filter.c --- csound-5.17.11~dfsg/Opcodes/filter.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/filter.c 2014-01-07 16:53:48.000000000 +0000 @@ -132,7 +132,7 @@ #include -#include "csdl.h" +#include "stdopcod.h" #include "filter.h" #include @@ -266,8 +266,10 @@ */ static int afilter(CSOUND *csound, FILTER* p) { - int n,i; - int nsmps = csound->ksmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double* a = p->dcoeffs+p->numb; double* b = p->dcoeffs+1; @@ -276,7 +278,12 @@ double poleSamp, zeroSamp, inSamp; /* Outer loop */ - for (n=0; nout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nin[n]; poleSamp = inSamp; @@ -360,8 +367,10 @@ */ static int azfilter(CSOUND *csound, ZFILTER* p) { - int n,i; - int nsmps = csound->ksmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double* a = p->dcoeffs+p->numb; double* b = p->dcoeffs+1; @@ -389,7 +398,12 @@ /* and a contains their associated real coefficients. */ /* Outer loop */ - for (n=0; nout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nin[n]; poleSamp = inSamp; zeroSamp = 0.0; @@ -573,8 +587,9 @@ if (fabs(b[i].i)>eps) a[i].mag *= nudgefact; } - else - /* Factor is out of range, do nothing */; + else { + /* Factor is out of range, do nothing */ + } } /* nudgePhases - Pole phase nudging routine @@ -612,8 +627,9 @@ if (fabs(b[i].i)>eps) a[i].ph *= nudgefact; } - else - /* Factor is out of range, do nothing */; + else { + /* Factor is out of range, do nothing */ + } } /* ------------------------------------------------------------ */ @@ -669,7 +685,7 @@ if (iter % MT) *x = x1; else *x = Csub(*x,RCmul(frac[iter/MT],dx)); } - csound->Die(csound, Str("too many iterations in laguer")); + csound->Warning(csound, Str("too many iterations in laguer")); return; } #undef EPSS @@ -849,9 +865,9 @@ static OENTRY localops[] = { { "filter2",0xffff, }, -{ "filter2.a", S(FILTER), 5, "a", "aiim", (SUBR)ifilter, NULL, (SUBR)afilter}, -{ "filter2.k", S(FILTER), 3, "k", "kiim", (SUBR)ifilter, (SUBR)kfilter,NULL }, -{ "zfilter2", S(ZFILTER), 5, "a", "akkiim", (SUBR)izfilter, NULL, (SUBR)azfilter} +{ "filter2.a", S(FILTER), 0, 5, "a", "aiim", (SUBR)ifilter, NULL, (SUBR)afilter}, +{ "filter2.k", S(FILTER), 0, 3, "k", "kiim", (SUBR)ifilter, (SUBR)kfilter,NULL }, +{ "zfilter2", S(ZFILTER), 0, 5, "a", "akkiim", (SUBR)izfilter, NULL, (SUBR)azfilter} }; int filter_init_(CSOUND *csound) @@ -859,4 +875,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/flanger.c csound-6.02~dfsg/Opcodes/flanger.c --- csound-5.17.11~dfsg/Opcodes/flanger.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/flanger.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" /* Flanger by Maldonado, with coding +#include "stdopcod.h" /* Flanger by Maldonado, with coding enhancements by JPff -- July 1998 */ #include #include "flanger.h" @@ -29,7 +29,7 @@ static int flanger_set (CSOUND *csound, FLANGER *p) { /*---------------- delay -----------------------*/ - p->maxdelay = (uint32)(*p->maxd * csound->esr); + p->maxdelay = (uint32)(*p->maxd * CS_ESR); csound->AuxAlloc(csound, p->maxdelay * sizeof(MYFLT), &p->aux); p->left = 0; p->yt1 = FL(0.0); @@ -52,12 +52,19 @@ int32 v1; MYFLT yt1= p->yt1; - int n,nsmps = csound->ksmps; - - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nesr); /* Make sure inside the buffer*/ + fv1 = indx - (*freq_del++ * CS_ESR); /* Make sure inside the buffer*/ while (fv1 < 0) fv1 += maxdelay; while (fv1 >= maxdelay) fv1 -= maxdelay; /* Is this necessary? JPff */ @@ -77,7 +84,7 @@ static int wguide1set (CSOUND *csound, WGUIDE1 *p) { /*---------------- delay -----------------------*/ - p->maxd = (uint32) (MAXDELAY * csound->esr); + p->maxd = (uint32) (MAXDELAY * CS_ESR); csound->AuxAlloc(csound, p->maxd * sizeof(MYFLT), &p->aux); p->left = 0; /*---------------- filter -----------------------*/ @@ -95,14 +102,16 @@ MYFLT *out = p->ar; /* assign object data to local variables */ MYFLT *in = p->asig; MYFLT *buf = (MYFLT *)p->aux.auxp; - MYFLT *freq_del = p->xdel; /*(1 / *p->xdel) * csound->esr; */ + MYFLT *freq_del = p->xdel; /*(1 / *p->xdel) * CS_ESR; */ MYFLT feedback = *p->kfeedback; MYFLT fv1, fv2, out_delay,bufv1 ; unsigned int maxdM1 = p->maxd-1; int32 v1; /*---------------- filter -----------------------*/ MYFLT c1, c2, yt1 = p->yt1; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /*---------------- delay -----------------------*/ indx = p->left; @@ -116,14 +125,19 @@ } c1= p->c1; c2= p->c2; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->xdelcod) { /* delay changes at audio-rate */ - for (n=0; nesr / fd); /* Make sure inside the buffer */ + fv1 = indx - (CS_ESR / fd); /* Make sure inside the buffer */ while (fv1 < 0) { fv1 = fv1 + (MYFLT)p->maxd; } @@ -137,13 +151,13 @@ } } else { - for (n=0; nesr / fd); /* Make sure inside the buffer */ + fv1 = indx - (CS_ESR / fd); /* Make sure inside the buffer */ while (fv1 < 0) { fv1 = fv1 + (MYFLT)p->maxd; } @@ -164,7 +178,7 @@ static int wguide2set (CSOUND *csound, WGUIDE2 *p) { /*---------------- delay1 -----------------------*/ - p->maxd = (uint32) (MAXDELAY * csound->esr); + p->maxd = (uint32) (MAXDELAY * CS_ESR); csound->AuxAlloc(csound, p->maxd * sizeof(MYFLT), &p->aux1); p->left1 = 0; /*---------------- delay2 -----------------------*/ @@ -194,14 +208,16 @@ { MYFLT *out = p->ar; MYFLT *in = p->asig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT out1,out2, old_out = p->old_out; unsigned int maxdM1 = p->maxd-1; /*---------------- delay1 -----------------------*/ uint32 indx1; MYFLT *buf1 = (MYFLT *)p->aux1.auxp; - MYFLT *freq_del1 = p->xdel1; /*(1 / *p->xdel1) * csound->esr; */ + MYFLT *freq_del1 = p->xdel1; /*(1 / *p->xdel1) * CS_ESR; */ MYFLT feedback1 = *p->kfeedback1; MYFLT fv1_1, fv2_1, out_delay1 ; int32 v1_1; @@ -210,7 +226,7 @@ /*---------------- delay2 -----------------------*/ uint32 indx2; MYFLT *buf2 = (MYFLT *)p->aux2.auxp; - MYFLT *freq_del2 = p->xdel2; /*(1 / *p->xdel2) * csound->esr;*/ + MYFLT *freq_del2 = p->xdel2; /*(1 / *p->xdel2) * CS_ESR;*/ MYFLT feedback2 = *p->kfeedback2; MYFLT fv1_2, fv2_2, out_delay2 ; int32 v1_2; @@ -241,8 +257,13 @@ yt1_1= p->yt1_1; yt1_2= p->yt1_2; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->xdel1cod) { /* delays change at audio-rate */ - for (n=0;nesr / fd1); /* Make sure inside the buffer */ - fv1_2 = indx2 - (csound->esr / fd2); /* Make sure inside the buffer */ + fv1_1 = indx1 - (CS_ESR / fd1); /* Make sure inside the buffer */ + fv1_2 = indx2 - (CS_ESR / fd2); /* Make sure inside the buffer */ while (fv1_1 < 0) fv1_1 += p->maxd; while (fv1_2 < 0) fv1_2 += p->maxd; fv2_1 = (fv1_1esr / fd1); /* Make sure inside the buffer */ - fv1_2 = indx2 - (csound->esr / fd2); /* Make sure inside the buffer */ + fv1_1 = indx1 - (CS_ESR / fd1); /* Make sure inside the buffer */ + fv1_2 = indx2 - (CS_ESR / fd2); /* Make sure inside the buffer */ while (fv1_1 < 0) fv1_1 += p->maxd; while (fv1_2 < 0) fv1_2 += p->maxd; fv2_1 = (fv1_1CreateGlobalVariable(csound, "fluid.engines", - sizeof(fluidSynthGlobals)) != 0) - csound->Die(csound, "fluid: error allocating globals\n"); - p = (fluidSynthGlobals *) csound->QueryGlobalVariable(csound, - "fluid.engines"); - p->fluid_engines = (fluid_synth_t **) NULL; - p->cnt = (size_t) 0; - - return p; -} - -static CS_NOINLINE fluidSynthGlobals * fluid_getGlobals(CSOUND *csound) -{ - fluidSynthGlobals *p; - - p = (fluidSynthGlobals *) csound->QueryGlobalVariable(csound, - "fluid.engines"); - if (p == NULL) - return fluid_allocGlobals(csound); - - return p; -} - -/* FLUID_ENGINE */ - -static int fluidEngine_Alloc(CSOUND *csound, fluid_synth_t *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - size_t ndx; - - ndx = pp->cnt; - pp->cnt++; - pp->fluid_engines = - (fluid_synth_t **) csound->ReAlloc(csound, pp->fluid_engines, - sizeof(fluid_synth_t *) * pp->cnt); - pp->fluid_engines[ndx] = p; - - return (int) ndx; -} - -/** - * Creates a fluidEngine and returns a MYFLT to user as identifier for - * engine - */ - -static int fluidEngineIopadr(CSOUND *csound, FLUIDENGINE *p) -{ - fluid_synth_t *fluidSynth = NULL; - fluid_settings_t *fluidSettings; - int ndx; - int chorusEnabled = (int) *p->iChorusEnabled; - int reverbEnabled = (int) *p->iReverbEnabled; - int numChannels = (int) *p->iNumChannels; - int polyphony = (int) *p->iPolyphony; - - if (numChannels <= 0) { - numChannels = 256; - } else if (numChannels < 16) { - numChannels = 16; - } else if (numChannels > 256) { - numChannels = 256; - } - - if (polyphony <= 0) { - polyphony = 4096; - } else if (polyphony < 16) { - polyphony = 16; - } else if (polyphony > 4096) { - polyphony = 4096; - } - - csound_global_mutex_lock(); - fluidSettings = new_fluid_settings(); - if (fluidSettings != NULL) { - fluid_settings_setnum(fluidSettings, - "synth.sample-rate", (double) csound->esr); - fluid_settings_setint(fluidSettings, - "synth.polyphony", polyphony); - fluid_settings_setint(fluidSettings, - "synth.midi-channels", numChannels); - fluidSynth = new_fluid_synth(fluidSettings); - } - csound_global_mutex_unlock(); - - if (fluidSynth == NULL) { - if (fluidSettings != NULL) - delete_fluid_settings(fluidSettings); - return csound->InitError(csound, Str("error allocating fluid engine\n")); - } - csound_global_mutex_lock(); - fluid_synth_set_chorus_on(fluidSynth, chorusEnabled); - fluid_synth_set_reverb_on(fluidSynth, reverbEnabled); - csound_global_mutex_unlock(); - - ndx = fluidEngine_Alloc(csound, fluidSynth); - csound->Message(csound, Str("Created fluidEngine %d with sampling rate = %f, " - "chorus %s, reverb %s, channels %d, " - "polyphony %d.\n"), - ndx, (double) csound->esr, - chorusEnabled ? Str("on") : Str("off"), - reverbEnabled ? Str("on") : Str("off"), - numChannels, - polyphony); - *(p->iEngineNum) = (MYFLT) ndx; - - return OK; -} - -/* FLUID_LOAD */ - -/** - * Loads a Soundfont into a Fluid Engine - */ - -static int fluidLoadIopadr(CSOUND *csound, FLUIDLOAD *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - char *filename, *filename_fullpath; - int engineNum = (int) *(p->iEngineNum); - int sfontId = -1; - - if (engineNum >= (int) pp->cnt || engineNum < 0) { - csound->InitError(csound, Str("Illegal Engine Number: %i.\n"), engineNum); - return NOTOK; - } - filename = csound->strarg2name(csound, - (char*) NULL, p->filename, "fluid.sf2.", - (int) csound->GetInputArgSMask(p)); - filename_fullpath = csound->FindInputFile(csound, filename, "SFDIR;SSDIR"); - if (filename_fullpath != NULL && fluid_is_soundfont(filename_fullpath)) { - csound->Message(csound, Str("Loading SoundFont : %s.\n"), filename_fullpath); - sfontId = fluid_synth_sfload(pp->fluid_engines[engineNum], - filename_fullpath, 0); - } - *(p->iInstrumentNumber) = (MYFLT) sfontId; - if (sfontId < 0) - csound->InitError(csound, Str("fluid: unable to load %s"), filename); - csound->NotifyFileOpened(csound, filename_fullpath, CSFTYPE_SOUNDFONT, 0, 0); - csound->Free(csound, filename_fullpath); - csound->Free(csound, filename); - if (sfontId < 0) - return NOTOK; - - if (*(p->iListPresets) != FL(0.0)) { - fluid_sfont_t *fluidSoundfont; - fluid_preset_t fluidPreset; - - fluidSoundfont = - fluid_synth_get_sfont_by_id(pp->fluid_engines[engineNum], sfontId); - - fluidSoundfont->iteration_start(fluidSoundfont); - if (csound->oparms->msglevel & 0x7) - while (fluidSoundfont->iteration_next(fluidSoundfont, &fluidPreset)) { - csound->Message(csound, - Str("SoundFont: %3d Bank: %3d Preset: %3d %s\n"), - sfontId, - fluidPreset.get_banknum(&fluidPreset), - fluidPreset.get_num(&fluidPreset), - fluidPreset.get_name(&fluidPreset)); - } - } - - return OK; -} - -/* FLUID_PROGRAM_SELECT */ - -static int fluidProgramSelectIopadr(CSOUND *csound, FLUID_PROGRAM_SELECT *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - int engineNum = (int) *(p->iEngineNumber); - int channelNum = (int) *(p->iChannelNumber); - int instrumentNum = (int) *(p->iInstrumentNumber); - int bankNum = (int) *(p->iBankNumber); - int presetNum = (int) *(p->iPresetNumber); - - fluid_synth_program_select(pp->fluid_engines[engineNum], - channelNum, - (unsigned int) instrumentNum, - (unsigned int) bankNum, - (unsigned int) presetNum); - - return OK; -} - -/* FLUID_CC */ - -static int fluidCC_I_Iopadr(CSOUND *csound, FLUID_CC *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - int engineNum = (int) *(p->iEngineNumber); - int channelNum = (int) *(p->iChannelNumber); - int controllerNum = (int) *(p->iControllerNumber); - int value = (int) *(p->kVal); - - fluid_synth_cc(pp->fluid_engines[engineNum], - channelNum, controllerNum, value); - - return OK; -} - -static int fluidCC_K_Iopadr(CSOUND *csound, FLUID_CC *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - - p->fluidEngine = pp->fluid_engines[(int) *(p->iEngineNumber)]; - p->priorMidiValue = -1; - - return OK; -} - -static int fluidCC_K_Kopadr(CSOUND *csound, FLUID_CC *p) -{ - int value = (int) *(p->kVal); - - (void) csound; - if (value != p->priorMidiValue) { - p->priorMidiValue = value; - fluid_synth_cc(p->fluidEngine, - (int) *(p->iChannelNumber), - (int) *(p->iControllerNumber), - value); - } - - return OK; -} - -/* FLUID_NOTE */ - -static int fluidNoteTurnoff(CSOUND *csound, FLUID_NOTE *p) -{ - (void) csound; - if (p->initDone > 0) - fluid_synth_noteoff(p->fluidEngine, p->iChn, p->iKey); - p->initDone = 0; - - return OK; -} - -static int fluidNoteIopadr(CSOUND *csound, FLUID_NOTE *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - int engineNum = (int) *(p->iEngineNumber); - int channelNum = (int) *(p->iChannelNumber); - int key = (int) *(p->iMidiKeyNumber); - int velocity = (int) *(p->iVelocity); - - /* csound->Message(csound, "%i : %i : %i : %i\n", - engineNum, instrNum, key, velocity); */ - p->iChn = channelNum; - p->iKey = key; - p->fluidEngine = pp->fluid_engines[engineNum]; - - if (p->initDone) - fluidNoteTurnoff(csound, p); - else - csound->RegisterDeinitCallback(csound, (void*) p, - (int (*)(CSOUND *, void *)) - fluidNoteTurnoff); - fluid_synth_noteon(p->fluidEngine, channelNum, key, velocity); - p->initDone = 1; - - return OK; -} - -static int fluidNoteKopadr(CSOUND *csound, FLUID_NOTE *p) -{ - if (p->h.insdshead->relesing) { - if (p->initDone > 0) { - fluidNoteTurnoff(csound, p); - p->initDone = -1; - } - } - return OK; -} - -/* FLUID_OUT */ - -static int fluidOutIopadr(CSOUND *csound, FLUIDOUT *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - int engineNum = (int) *(p->iEngineNum); - - if (engineNum >= (int) pp->cnt || engineNum < 0) { - csound->InitError(csound, Str("Illegal Engine Number: %i.\n"), engineNum); - return NOTOK; - } - p->fluidEngine = pp->fluid_engines[engineNum]; - - return OK; -} - -static int fluidOutAopadr(CSOUND *csound, FLUIDOUT *p) -{ - float leftSample, rightSample; - int n, nsmps = csound->ksmps; - for (n=0; nfluidEngine, 1, - &leftSample, 0, 1, &rightSample, 0, 1); - p->aLeftOut[n] = (MYFLT)leftSample /* * csound->e0dbfs */; - p->aRightOut[n] = (MYFLT)rightSample /* * csound->e0dbfs */; - } - - return OK; -} - -static int fluidAllOutIopadr(CSOUND *csound, FLUIDALLOUT *p) -{ - p->fluidGlobals = (void *) fluid_getGlobals(csound); - return OK; -} - -static int fluidAllOutAopadr(CSOUND *csound, FLUIDALLOUT *p) -{ - fluid_synth_t **fluid_engines; - float leftSample, rightSample; - int i = 0, j, cnt; - - cnt = (int) ((fluidSynthGlobals *) p->fluidGlobals)->cnt; - if (cnt <= 0) - return OK; - fluid_engines = ((fluidSynthGlobals *) p->fluidGlobals)->fluid_engines; - do { - p->aLeftOut[i] = FL(0.0); - p->aRightOut[i] = FL(0.0); - j = 0; - do { - leftSample = 0.0f; - rightSample = 0.0f; - fluid_synth_write_float(fluid_engines[j], 1, - &leftSample, 0, 1, &rightSample, 0, 1); - p->aLeftOut[i] += (MYFLT) leftSample /* * csound->e0dbfs */; - p->aRightOut[i] += (MYFLT) rightSample /* * csound->e0dbfs */; - } while (++j < cnt); - } while (++i < csound->ksmps); - - return OK; -} - -static int fluidControl_init(CSOUND *csound, FLUIDCONTROL *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - - p->fluidEngine = pp->fluid_engines[(int) *(p->iFluidEngine)]; - - p->priorMidiStatus = -1; - p->priorMidiChannel = -1; - p->priorMidiData1 = -1; - p->priorMidiData2 = -1; - - return OK; -} - -static int fluidControl_kontrol(CSOUND *csound, FLUIDCONTROL *p) -{ - int midiStatus = 0xF0 & (int) *(p->kMidiStatus); - int midiChannel = *(p->kMidiChannel); - int midiData1 = *(p->kMidiData1); - int midiData2 = *(p->kMidiData2); - int res = -1; - - if (midiData2 != p->priorMidiData2 || - midiData1 != p->priorMidiData1 || - midiChannel != p->priorMidiChannel || - midiStatus != p->priorMidiStatus) { - fluid_synth_t *fluidEngine = p->fluidEngine; - int printMsgs = ((csound->oparms->msglevel & 7) == 7 ? 1 : 0); - - switch (midiStatus) { - case (int) 0x80: - noteOff: - res = fluid_synth_noteoff(fluidEngine, midiChannel, midiData1); - if (printMsgs) - csound->Message(csound, Str("result: %d \n Note off: c:%3d k:%3d\n"),res, - midiChannel, midiData1); - break; - case (int) 0x90: - if (!midiData2) - goto noteOff; - res = fluid_synth_noteon(fluidEngine, midiChannel, midiData1, midiData2); - if (printMsgs) - csound->Message(csound, Str("result: %d \nNote on: c:%3d k:%3d v:%3d\n"), - res, midiChannel, midiData1, midiData2); - break; - case (int) 0xA0: - if (printMsgs) - csound->Message(csound, Str("Key pressure (not handled): " - "c:%3d k:%3d v:%3d\n"), - midiChannel, midiData1, midiData2); - break; - case (int) 0xB0: - res = fluid_synth_cc(fluidEngine, midiChannel, midiData1, midiData2); - if (printMsgs) - csound->Message(csound, - Str("Result: %d Control change: c:%3d c:%3d v:%3d\n"), - res, midiChannel, midiData1, midiData2); - break; - case (int) 0xC0: - res = fluid_synth_program_change(fluidEngine, midiChannel, midiData1); - if (printMsgs) - csound->Message(csound, - Str("Result: %d Program change: c:%3d p:%3d\n"),res, - midiChannel, midiData1); - break; - case (int) 0xD0: - if (printMsgs) - csound->Message(csound, "After touch (not handled): c:%3d v:%3d\n", - midiChannel, midiData1); - break; - case (int) 0xE0: - { - int pbVal = midiData1 + (midiData2 << 7); - fluid_synth_pitch_bend(fluidEngine, midiChannel, pbVal); - if (printMsgs) - csound->Message(csound, Str("Result: %d, Pitch bend: c:%d b:%d\n"), - res, midiChannel, pbVal); - } - break; - case (int) 0xF0: - if (printMsgs) - csound->Message(csound, Str("System exclusive (not handled): " - "c:%3d v1:%3d v2:%3d\n"), - midiChannel, midiData1, midiData2); - break; - } - p->priorMidiStatus = midiStatus; - p->priorMidiChannel = midiChannel; - p->priorMidiData1 = midiData1; - p->priorMidiData2 = midiData2; - } - - return OK; -} - -static int fluidSetInterpMethod(CSOUND *csound, FLUID_SET_INTERP_METHOD *p) -{ - fluidSynthGlobals *pp = fluid_getGlobals(csound); - int engineNum = (int) *(p->iEngineNumber); - int channelNum = (int) *(p->iChannelNumber); - int interpMethod = (int) *(p->iInterpMethod); - - if (engineNum >= (int) pp->cnt || engineNum < 0) - { - csound->InitError(csound, Str("Illegal Engine Number: %i.\n"), - engineNum); - return NOTOK; - } - - if(interpMethod != 0 && interpMethod != 1 && interpMethod != 4 && - interpMethod != 7) - { - csound->InitError(csound, - Str("Illegal Interpolation Method: Must " - "be either 0, 1, 4, or 7.\n")); - return NOTOK; - } - - fluid_synth_set_interp_method( - pp->fluid_engines[engineNum], channelNum, interpMethod); - - return OK; -} - -/* OPCODE LIBRARY STUFF */ - -static OENTRY localops[] = { - { "fluidEngine", sizeof(FLUIDENGINE), 1, "i", "ppoo", - (SUBR) fluidEngineIopadr, (SUBR) 0, (SUBR) 0 }, - { "fluidLoad", sizeof(FLUIDLOAD), 1, "i", "Tio", - (SUBR) fluidLoadIopadr, (SUBR) 0, (SUBR) 0 }, - { "fluidProgramSelect", sizeof(FLUID_PROGRAM_SELECT), 1, "", "iiiii", - (SUBR) fluidProgramSelectIopadr, (SUBR) 0, (SUBR) 0 }, - { "fluidCCi", sizeof(FLUID_CC), 1, "", "iiii", - (SUBR) fluidCC_I_Iopadr, (SUBR) 0, (SUBR) 0 }, - { "fluidCCk", sizeof(FLUID_CC), 3, "", "ikkk", - (SUBR) fluidCC_K_Iopadr, (SUBR) fluidCC_K_Kopadr, (SUBR) 0 }, - { "fluidNote", sizeof(FLUID_NOTE), 3, "", "iiii", - (SUBR) fluidNoteIopadr, (SUBR) fluidNoteKopadr, (SUBR) 0 }, - { "fluidOut", sizeof(FLUIDOUT), 5, "aa", "i", - (SUBR) fluidOutIopadr, (SUBR) 0, (SUBR) fluidOutAopadr }, - { "fluidAllOut", sizeof(FLUIDALLOUT), 5, "aa", "i", - (SUBR) fluidAllOutIopadr, (SUBR) 0, (SUBR) fluidAllOutAopadr }, - { "fluidControl", sizeof(FLUIDCONTROL), 3, "", "ikkkk", - (SUBR) fluidControl_init, (SUBR) fluidControl_kontrol, (SUBR) 0 }, - { "fluidSetInterpMethod", sizeof(FLUID_SET_INTERP_METHOD), 1, "", "iii", - (SUBR) fluidSetInterpMethod, (SUBR) 0, (SUBR) 0 }, - { NULL, 0, 0, NULL, NULL, - (SUBR) 0, (SUBR) 0, (SUBR) 0 } -}; - -PUBLIC int csoundModuleCreate(CSOUND *csound) -{ - (void) csound; - return 0; -} - -PUBLIC int csoundModuleInit(CSOUND *csound) -{ - OENTRY *ep; - int err = 0; - - for (ep = (OENTRY *) &(localops[0]); ep->opname != NULL; ep++) { - err |= csound->AppendOpcode(csound, ep->opname, - ep->dsblksiz, ep->thread, - ep->outypes, ep->intypes, - (int (*)(CSOUND *, void *)) ep->iopadr, - (int (*)(CSOUND *, void *)) ep->kopadr, - (int (*)(CSOUND *, void *)) ep->aopadr); - } - - return err; -} - -/** - * Called by Csound to de-initialize the opcode - * just before destroying it. - */ - -PUBLIC int csoundModuleDestroy(CSOUND *csound) -{ - fluidSynthGlobals *pp; - - pp = (fluidSynthGlobals *) csound->QueryGlobalVariable(csound, - "fluid.engines"); - if (pp != NULL && pp->cnt) { - size_t i; - csound->Message(csound, "Cleaning up Fluid Engines - Found: %d\n", - (int) pp->cnt); - for (i = (size_t) 0; i < pp->cnt; i++) { - fluid_settings_t *tmp; - tmp = fluid_synth_get_settings(pp->fluid_engines[i]); - delete_fluid_synth(pp->fluid_engines[i]); - pp->fluid_engines[i] = (fluid_synth_t *) NULL; - delete_fluid_settings(tmp); - } - } - - return 0; -} - -PUBLIC int csoundModuleInfo(void) -{ - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); -} - diff -Nru csound-5.17.11~dfsg/Opcodes/fluidOpcodes/fluidOpcodes.cpp csound-6.02~dfsg/Opcodes/fluidOpcodes/fluidOpcodes.cpp --- csound-5.17.11~dfsg/Opcodes/fluidOpcodes/fluidOpcodes.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/fluidOpcodes/fluidOpcodes.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -39,6 +39,7 @@ #include "OpcodeBase.hpp" #include +#include #ifdef USE_OPENMP #include #endif @@ -48,9 +49,11 @@ /** * This may help avoid problems with the order of static initializations. */ -static std::map > &getFluidSynthsForCsoundInstances() +static std::map > + &getFluidSynthsForCsoundInstances() { - static std::map > fluidSynthsForCsoundInstances; + static std::map > + fluidSynthsForCsoundInstances; return fluidSynthsForCsoundInstances; } @@ -134,7 +137,8 @@ fluidSettings = new_fluid_settings(); if (fluidSettings != NULL) { fluid_settings_setnum(fluidSettings, - (char *)"synth.sample-rate", (double) csound->esr); + (char *)"synth.sample-rate", + (double) csound->GetSr(csound)); fluid_settings_setint(fluidSettings, (char *)"synth.midi-channels", channelCount); fluid_settings_setint(fluidSettings, @@ -146,7 +150,8 @@ if (fluidSettings) { delete_fluid_settings(fluidSettings); } - result = csound->InitError(csound, Str("error allocating fluid engine\n")); + result = csound->InitError(csound, + Str("error allocating fluid engine\n")); } else { //csound_global_mutex_lock(); fluid_synth_set_chorus_on(fluidSynth, chorusEnabled); @@ -154,7 +159,7 @@ //csound_global_mutex_unlock(); log(csound, "Created fluidEngine 0x%p with sampling rate = %f, " "chorus %s, reverb %s, channels %d, voices %d.\n", - fluidSynth, (double) csound->esr, + fluidSynth, (double) csound->GetSr(csound), chorusEnabled ? "on" : "off", reverbEnabled ? "on" : "off", channelCount, @@ -189,11 +194,18 @@ soundFontId = -1; toa(iFluidSynth, fluidSynth); listPresets = (int) *iListPresets; - filename = csound->strarg2name(csound, + + if(csound->GetInputArgSMask(this)) + filename = csound->Strdup(csound, ((STRINGDAT *)iFilename)->data); + else + filename = csound->strarg2name(csound, (char*) NULL, - iFilename, + (std::isnan(*iFilename) ? + csound->GetString(csound, *iFilename) : + (char *) iFilename), (char *)"fluid.sf2.", - (int) csound->GetInputArgSMask(this)); + std::isnan(*iFilename)); + filepath = csound->FindInputFile(csound, filename, "SFDIR;SSDIR"); if (filepath && fluid_is_soundfont(filepath)) { log(csound, "Loading SoundFont : %s.\n", filepath); @@ -205,7 +217,8 @@ } *iInstrumentNumber = (MYFLT) soundFontId; if (soundFontId < 0) { - csound->InitError(csound, Str("fluid: unable to load %s"), filename); + csound->InitError(csound, + Str("fluid: unable to load %s"), filename); } csound->NotifyFileOpened(csound, filepath, CSFTYPE_SOUNDFONT, 0, 0); if (soundFontId < 0) { @@ -215,8 +228,11 @@ fluid_synth_get_sfont_by_id(fluidSynth, soundFontId); fluid_preset_t fluidPreset; fluidSoundfont->iteration_start(fluidSoundfont); - if (csound->oparms->msglevel & 0x7) - while (fluidSoundfont->iteration_next(fluidSoundfont, &fluidPreset)) { + OPARMS oparms; + csound->GetOParms(csound, &oparms); + if (oparms.msglevel & 0x7) + while (fluidSoundfont->iteration_next(fluidSoundfont, + &fluidPreset)) { log(csound, "SoundFont: %3d Bank: %3d Preset: %3d %s\n", soundFontId, @@ -378,21 +394,32 @@ #pragma omp critical (critical_section_fluid_out) { toa(iFluidSynth, fluidSynth); - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; } return OK; } int audio(CSOUND *csound) { #pragma omp critical (critical_section_fluid_out) { - for (frame = 0; frame < ksmps; frame++) { - leftSample = 0.0f; - rightSample = 0.0f; - fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, - &rightSample, 0, 1); - aLeftOut[frame] = leftSample /* * csound->e0dbfs */; - aRightOut[frame] = rightSample /* * csound->e0dbfs */; - } + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + if (UNLIKELY(offset)) { + memset(aLeftOut, '\0', offset*sizeof(MYFLT)); + memset(aRightOut, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + ksmps -= early; + memset(&aLeftOut[ksmps], '\0', early*sizeof(MYFLT)); + memset(&aRightOut[ksmps], '\0', early*sizeof(MYFLT)); + } + for (frame = offset; frame < ksmps; frame++) { + leftSample = 0.0f; + rightSample = 0.0f; + fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, + &rightSample, 0, 1); + aLeftOut[frame] = leftSample /* * csound->e0dbfs */; + aRightOut[frame] = rightSample /* * csound->e0dbfs */; + } } return OK; } @@ -412,27 +439,39 @@ int init(CSOUND *csound) { #pragma omp critical (critical_section_fluid_all_out) { - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; } return OK; } int audio(CSOUND *csound) { #pragma omp critical (critical_section_fluid_all_out) { - std::vector &fluidSynths = getFluidSynthsForCsoundInstances()[csound]; - for (frame = 0; frame < ksmps; frame++) { - aLeftOut[frame] = FL(0.0); - aRightOut[frame] = FL(0.0); - for (size_t i = 0, n = fluidSynths.size(); i < n; i++) { - fluid_synth_t *fluidSynth = fluidSynths[i]; - leftSample = FL(0.0); - rightSample = FL(0.0); - fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, - &rightSample, 0, 1); - aLeftOut[frame] += (MYFLT) leftSample /* * csound->e0dbfs */; - aRightOut[frame] += (MYFLT) rightSample /* * csound->e0dbfs */; - } + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + if (UNLIKELY(offset)) { + memset(aLeftOut, '\0', offset*sizeof(MYFLT)); + memset(aRightOut, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + ksmps -= early; + memset(&aLeftOut[ksmps], '\0', early*sizeof(MYFLT)); + memset(&aRightOut[ksmps], '\0', early*sizeof(MYFLT)); + } + std::vector &fluidSynths = + getFluidSynthsForCsoundInstances()[csound]; + for (frame = offset; frame < ksmps; frame++) { + aLeftOut[frame] = FL(0.0); + aRightOut[frame] = FL(0.0); + for (size_t i = 0, n = fluidSynths.size(); i < n; i++) { + fluid_synth_t *fluidSynth = fluidSynths[i]; + leftSample = FL(0.0); + rightSample = FL(0.0); + fluid_synth_write_float(fluidSynth, 1, &leftSample, 0, 1, + &rightSample, 0, 1); + aLeftOut[frame] += (MYFLT) leftSample /* * csound->e0dbfs */; + aRightOut[frame] += (MYFLT) rightSample /* * csound->e0dbfs */; } + } } return OK; } @@ -466,7 +505,9 @@ priorMidiChannel = -1; priorMidiData1 = -1; priorMidiData2 = -1; - printMsgs = ((csound->oparms->msglevel & 7) == 7 ? 1 : 0); + OPARMS oparms; + csound->GetOParms(csound, &oparms); + printMsgs = ((oparms.msglevel & 7) == 7 ? 1 : 0); } return OK; } @@ -478,7 +519,7 @@ midiData1 = (int) *kMidiData1; midiData2 = (int) *kMidiData2; int result = -1; - + if (midiData2 != priorMidiData2 || midiData1 != priorMidiData1 || midiChannel != priorMidiChannel || @@ -486,53 +527,60 @@ switch (midiStatus) { case (int) 0x80: noteOff: - result = fluid_synth_noteoff(fluidSynth, midiChannel, midiData1); + result = fluid_synth_noteoff(fluidSynth, + midiChannel, midiData1); if (printMsgs) - csound->Message(csound, - "result: %d \n Note off: c:%3d k:%3d\n", - result, - midiChannel, - midiData1); + csound->Message(csound, + Str("result: %d \n Note off: c:%3d k:%3d\n"), + result, + midiChannel, + midiData1); break; case (int) 0x90: if (!midiData2) { - goto noteOff; + goto noteOff; } result = fluid_synth_noteon(fluidSynth, midiChannel, - midiData1, midiData2); + midiData1, midiData2); if (printMsgs) - log(csound, "result: %d \nNote on: c:%3d k:%3d v:%3d\n",result, - midiChannel, midiData1, midiData2); + log(csound, + "result: %d \nNote on: c:%3d k:%3d v:%3d\n",result, + midiChannel, midiData1, midiData2); break; case (int) 0xA0: - if (printMsgs) - log(csound, "Key pressure (not handled): " - "c:%3d k:%3d v:%3d\n", - midiChannel, midiData1, midiData2); + if (printMsgs) + log(csound, "Key pressure (not handled): " + "c:%3d k:%3d v:%3d\n", + midiChannel, midiData1, midiData2); break; case (int) 0xB0: - result = fluid_synth_cc(fluidSynth, midiChannel, midiData1, midiData2); + result = fluid_synth_cc(fluidSynth, midiChannel, + midiData1, midiData2); if (printMsgs) - log(csound, "Result: %d Control change: c:%3d c:%3d v:%3d\n",result, - midiChannel, midiData1, midiData2); + log(csound, + "Result: %d Control change: c:%3d c:%3d v:%3d\n",result, + midiChannel, midiData1, midiData2); break; case (int) 0xC0: - result = fluid_synth_program_change(fluidSynth, midiChannel, midiData1); - if (printMsgs) - log(csound, "Result: %d Program change: c:%3d p:%3d\n",result, - midiChannel, midiData1); - break; + result = fluid_synth_program_change(fluidSynth, + midiChannel, midiData1); + if (printMsgs) + log(csound, + "Result: %d Program change: c:%3d p:%3d\n",result, + midiChannel, midiData1); + break; case (int) 0xD0: - if (printMsgs) - log(csound, "After touch (not handled): c:%3d v:%3d\n", - midiChannel, midiData1); - break; + if (printMsgs) + log(csound, "After touch (not handled): c:%3d v:%3d\n", + midiChannel, midiData1); + break; case (int) 0xE0: { - int pbVal = midiData1 + (midiData2 << 7); - fluid_synth_pitch_bend(fluidSynth, midiChannel, pbVal); - if (printMsgs) - log(csound, "Result: %d, Pitch bend: c:%d b:%d\n", result, - midiChannel, pbVal); + int pbVal = midiData1 + (midiData2 << 7); + fluid_synth_pitch_bend(fluidSynth, midiChannel, pbVal); + if (printMsgs) + log(csound, + "Result: %d, Pitch bend: c:%d b:%d\n", result, + midiChannel, pbVal); } break; case (int) 0xF0: @@ -548,7 +596,7 @@ priorMidiData2 = midiData2; } } - + return OK; } }; @@ -578,7 +626,8 @@ "either 0, 1, 4, or 7.\n")); result = NOTOK; } else { - fluid_synth_set_interp_method(fluidSynth, channel, interpolationMethod); + fluid_synth_set_interp_method(fluidSynth, channel, + interpolationMethod); } } return result; @@ -589,6 +638,7 @@ { (char *)"fluidEngine", sizeof(FluidEngine), + 0, 1, (char *)"i", (char *)"ppoo", @@ -599,6 +649,7 @@ { (char *)"fluidLoad", sizeof(FluidLoad), + 0, 1, (char *)"i", (char *)"Tio", @@ -609,6 +660,7 @@ { (char *)"fluidProgramSelect", sizeof(FluidProgramSelect), + 0, 1, (char *)"", (char *)"iiiii", @@ -619,6 +671,7 @@ { (char *)"fluidCCi", sizeof(FluidCCI), + 0, 1, (char *)"", (char *)"iiii", @@ -629,6 +682,7 @@ { (char *)"fluidCCk", sizeof(FluidCCK), + 0, 3, (char *)"", (char *)"ikkk", @@ -639,6 +693,7 @@ { (char *)"fluidNote", sizeof(FluidNote), + 0, 3, (char *)"", (char *)"iiii", @@ -649,6 +704,7 @@ { (char *)"fluidOut", sizeof(FluidOut), + 0, 5, (char *)"aa", (char *)"i", @@ -659,6 +715,7 @@ { (char *)"fluidAllOut", sizeof(FluidAllOut), + 0, 5, (char *)"aa", (char *)"", @@ -669,6 +726,7 @@ { (char *)"fluidControl", sizeof(FluidControl), + 0, 3, (char *)"", (char *)"ikkkk", @@ -679,6 +737,7 @@ { (char *)"fluidSetInterpMethod", sizeof(FluidSetInterpMethod), + 0, 1, (char *)"", (char *)"iii", @@ -692,6 +751,7 @@ 0, 0, 0, + 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 @@ -715,6 +775,7 @@ err |= csound->AppendOpcode(csound, ep->opname, ep->dsblksiz, + ep->flags, ep->thread, ep->outypes, ep->intypes, @@ -734,18 +795,16 @@ { #pragma omp critical (critical_section_fluidopcodes) { - for (std::map >::iterator it = getFluidSynthsForCsoundInstances().begin(); - it != getFluidSynthsForCsoundInstances().end(); - ++it) { - std::vector &fluidSynths = it->second; - for (size_t i = 0, n = fluidSynths.size(); i < n; i++) { - fluid_synth_t *fluidSynth = fluidSynths[i]; - fluid_settings_t *fluidSettings = fluid_synth_get_settings(fluidSynth); - delete_fluid_synth(fluidSynth); - delete_fluid_settings(fluidSettings); - } - fluidSynths.clear(); - } + std::vector &fluidSynths = + getFluidSynthsForCsoundInstances()[csound]; + + for (size_t i = 0, n = fluidSynths.size(); i < n; i++) { + fluid_synth_t *fluidSynth = fluidSynths[i]; + fluid_settings_t *fluidSettings = fluid_synth_get_settings(fluidSynth); + delete_fluid_synth(fluidSynth); + delete_fluid_settings(fluidSettings); + } + fluidSynths.clear(); } return 0; } @@ -754,4 +813,3 @@ { return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); } - diff -Nru csound-5.17.11~dfsg/Opcodes/fm4op.c csound-6.02~dfsg/Opcodes/fm4op.c --- csound-5.17.11~dfsg/Opcodes/fm4op.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/fm4op.c 2014-01-07 16:53:48.000000000 +0000 @@ -145,7 +145,7 @@ make_ADSR(&p->adsr[2]); make_ADSR(&p->adsr[3]); make_TwoZero(&p->twozero); - if (UNLIKELY((ftp = csound->FTFind(csound, p->vifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->vifn)) == NULL)) goto err1; p->vibWave = ftp; p->baseFreq = FL(440.0); @@ -162,25 +162,26 @@ return OK; err1: /* Expect sine wave */ - return csound->PerfError(csound, Str("No table for VibWaveato")); + return csound->PerfError(csound, p->h.insdshead, + Str("No table for VibWaveato")); } static int FM4Op_loadWaves(CSOUND *csound, FM4OP *p) { FUNC *ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn0)) == NULL)) goto err1; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn0)) == NULL)) goto err1; p->waves[0] = ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn1)) == NULL)) goto err1; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn1)) == NULL)) goto err1; p->waves[1] = ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn2)) == NULL)) goto err1; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn2)) == NULL)) goto err1; p->waves[2] = ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn3)) == NULL)) goto err1; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn3)) == NULL)) goto err1; p->waves[3] = ftp; p->w_time[0] = p->w_time[1] = p->w_time[2] = p->w_time[3] = FL(0.0); return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("No table for FM4Op")); /* Expect sine wave */ } @@ -261,7 +262,8 @@ MYFLT opt = *p->opt; if (UNLIKELY(make_FM4Op(csound,p))) return NOTOK; - if (UNLIKELY(FM4Op_loadWaves(csound,p))) return NOTOK; /* 4 x "rawwaves/sinewave.raw" */ + if (UNLIKELY(FM4Op_loadWaves(csound,p))) + return NOTOK; /* 4 x "rawwaves/sinewave.raw" */ FM4Op_setRatio(p, 0, FL(1.0) * FL(0.995)); FM4Op_setRatio(p, 1, FL(1.414) * FL(0.995)); @@ -299,7 +301,9 @@ { MYFLT amp = *p->amp * AMP_RSCALE; /* Normalised */ MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT c1 = *p->control1; MYFLT c2 = *p->control2; @@ -315,7 +319,12 @@ p->w_rate[3] = p->baseFreq * p->ratios[3] * p->waves[3]->flen * csound->onedsr; p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr; - for (n=0;namp * AMP_RSCALE; /* Normalised */ MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT c1 = *p->control1; MYFLT c2 = *p->control2; @@ -431,7 +442,12 @@ p->w_rate[3] = p->ratios[3] * p->waves[3]->flen * csound->onedsr; p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr; - for (n=0;nar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp * AMP_RSCALE; /* Normalised */ MYFLT c1 = *p->control1; MYFLT c2 = *p->control2; @@ -534,7 +552,12 @@ p->w_rate[2] = temp * p->ratios[2] * p->waves[2]->flen; p->w_rate[3] = temp * p->ratios[3] * p->waves[3]->flen; p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr; - for (n=0;namp * AMP_RSCALE; /* Normalised */ MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT c1 = *p->control1; MYFLT c2 = *p->control2; MYFLT temp; @@ -634,7 +659,12 @@ p->gains[1] = amp * FM4Op_gains[95]; p->gains[2] = amp * FM4Op_gains[99]; p->gains[3] = amp * FM4Op_gains[95]; - for (n=0;nmodDepth > FL(0.0)) { p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr; @@ -943,13 +973,6 @@ FM4Op_susLevels[15], FL(0.050)); ADSR_setAllTimes(csound, &p->adsr[3], FL(0.001), FL(0.010), FM4Op_susLevels[15], FL(0.500)); - /* ADSR_setAll(&p->adsr[0], FL(0.001), FL(0.001), - FM4Op_susLevels[15], FL(0.001)); */ - /* ADSR_setAll(&p->adsr[1], FL(0.001), FL(0.001), - FM4Op_susLevels[15], FL(0.001)); */ - /* ADSR_setAll(&p->adsr[2], FL(0.001), FL(0.001), - FM4Op_susLevels[15], FL(0.001)); */ - /* ADSR_setAll(&p->adsr[3], 0.05f, 0.05f, FM4Op_susLevels[15], 0.0001f); */ p->twozero.gain = FL(0.0); /* modDepth = 0.005; */ q->tilt[0] = FL(1.0); @@ -976,7 +999,9 @@ FM4OP *p = (FM4OP *)q; MYFLT amp = *q->amp * AMP_RSCALE; MYFLT *ar = q->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (p->baseFreq != *q->frequency || *q->control1 != q->last_control) { q->last_control = *q->control1; @@ -988,7 +1013,12 @@ q->tilt[2] = amp * amp * amp; p->gains[3] = FM4Op_gains[(int) (*p->control2 * FL(0.78125))]; - for (n=0;namp * AMP_RSCALE; /* Normalised */ if (UNLIKELY(make_FM4Op(csound,p))) return NOTOK; - if (UNLIKELY(FM4Op_loadWaves(csound,p))) return NOTOK; /* 3 x sines; 1 x fwavblnk */ + if (UNLIKELY(FM4Op_loadWaves(csound,p))) + return NOTOK; /* 3 x sines; 1 x fwavblnk */ FM4Op_setRatio(p, 0, FL(1.50) ); FM4Op_setRatio(p, 1, FL(3.00) * FL(0.995)); @@ -1072,10 +1103,6 @@ FM4Op_susLevels[11], FL(0.05)); ADSR_setAllTimes(csound, &p->adsr[3], FL(0.02), FL(0.05), FM4Op_susLevels[13], FL(0.01)); - /* ADSR_setAll(&p->adsr[0],FL(0.001),FL(0.001),FM4Op_susLevels[14], FL(0.001));*/ - /* ADSR_setAll(&p->adsr[1], 0.05f, 0.0001f, FM4Op_susLevels[13], 0.0001f); */ - /* ADSR_setAll(&p->adsr[2], 0.05f, 0.0020f, FM4Op_susLevels[11], FL(0.001)); */ - /* ADSR_setAll(&p->adsr[3], 0.05f, 0.0010f, FM4Op_susLevels[13], FL(0.005)); */ p->twozero.gain = FL(0.0); /* modDepth = FL(0.005); */ ADSR_keyOn(&p->adsr[0]); @@ -1088,7 +1115,9 @@ int percflute(CSOUND *csound, FM4OP *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp * AMP_RSCALE; /* Normalised */ MYFLT c1 = *p->control1; MYFLT c2 = *p->control2; @@ -1099,7 +1128,13 @@ p->gains[2] = amp * FM4Op_gains[93] * FL(0.5); p->gains[3] = amp * FM4Op_gains[85] * FL(0.5); p->v_rate = *p->vibFreq * p->vibWave->flen * csound->onedsr; - for (n=0;n #include "follow.h" static int flwset(CSOUND *csound, FOL *p) { p->wgh = p->max = FL(0.0); - p->length = (int32)(*p->len * csound->esr); + p->length = (int32)(*p->len * CS_ESR); if (UNLIKELY(p->length<=0L)) { /* RWD's suggestion */ csound->Warning(csound, Str("follow - zero length!")); - p->length = (int32)csound->esr; + p->length = (int32)CS_ESR; } p->count = p->length; return OK; @@ -45,14 +45,21 @@ /* Use absolute value rather than max/min */ static int follow(CSOUND *csound, FOL *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *in = p->in, *out = p->out; MYFLT max = p->max; int32 count = p->count; - for (n=0; n max) max = sig; - else if (sig < -max) max = -sig; if (--count == 0L) { p->wgh = max; max = FL(0.0); @@ -76,41 +83,51 @@ if (p->lastatt<=FL(0.0)) p->ga = EXP(- FL(69.0775527898)*csound->onedsr); else - p->ga = EXP(- FL(6.90775527898)/(csound->esr* p->lastatt)); + p->ga = EXP(- FL(6.90775527898)/(CS_ESR* p->lastatt)); p->lastrel = *p->release; if (p->lastrel<=FL(0.0)) - p->gr = (MYFLT) exp(- FL(69.0775527898)*csound->onedsr); + p->gr = EXP(- FL(69.0775527898)*csound->onedsr); else - p->gr = (MYFLT) exp(- FL(6.90775527898)/(csound->esr* p->lastrel)); + p->gr = EXP(- FL(6.90775527898)/(CS_ESR* p->lastrel)); p->envelope = FL(0.0); return OK; } static int envext(CSOUND *csound, ENV *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT envelope = p->envelope; MYFLT ga, gr; MYFLT *in = p->in, *out = p->out; - if (p->lastrel!=*p->attack) { + if (p->lastatt!=*p->attack) { p->lastatt = *p->attack; if (p->lastatt<=FL(0.0)) - ga = p->ga = EXP(-FL(10000.0)*csound->onedsr); + ga = p->ga = EXP(- FL(69.0775527898)*csound->onedsr); + // EXP(-FL(10000.0)*csound->onedsr); else - ga = p->ga = EXP(-FL(1.0)/(csound->esr* p->lastatt)); + ga = p->ga = EXP(- FL(6.90775527898)/(CS_ESR* p->lastatt)); + //EXP(-FL(1.0)/(CS_ESR* p->lastatt)); } else ga = p->ga; if (p->lastrel!=*p->release) { p->lastrel = *p->release; if (p->lastrel<=FL(0.0)) - gr = p->gr = EXP(-FL(100.0)*csound->onedsr); + gr = p->gr = EXP(- FL(69.0775527898)*csound->onedsr); + //EXP(-FL(100.0)*csound->onedsr); else - gr = p->gr = EXP(-FL(1.0)/(csound->esr* p->lastrel)); + gr = p->gr = EXP(- FL(6.90775527898)/(CS_ESR* p->lastrel)); + //EXP(-FL(1.0)/(CS_ESR* p->lastrel)); } else gr = p->gr; - for (n=0;n #include "fout.h" #include "soundio.h" @@ -54,7 +54,7 @@ pp->name = (char*) NULL; pp->do_scale = 0; pp->refCount = 0U; - + if (pp->fd != NULL) { if ((csound->oparms->msglevel & 7) == 7) csound->Message(csound, Str("Closing file '%s'...\n"), @@ -71,12 +71,13 @@ static CS_NOINLINE int fout_open_file(CSOUND *csound, FOUT_FILE *p, void *fp, int fileType, MYFLT *iFile, int isString, - void *fileParams) + void *fileParams, int forceSync) { STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; char *name; int idx, csFileType, need_deinit = 0; + if (p != (FOUT_FILE*) NULL) p->async = 0; if (fp != NULL) { if (fileType == CSFILE_STD) *((FILE**) fp) = (FILE*) NULL; @@ -91,13 +92,15 @@ need_deinit = 1; } /* get file name, */ - if (isString || *iFile == SSTRCOD) - name = csound->strarg2name(csound, NULL, iFile, "fout.", isString); + if (isString) name = cs_strdup(csound, ((STRINGDAT *)iFile)->data); + else if(ISSTRCOD(*iFile)) name = cs_strdup(csound, + get_arg_string(csound, *iFile)); + /* else csound->strarg2name(csound, NULL, iFile, "fout.", 0);*/ else { /* or handle to previously opened file */ idx = (int) MYFLT2LRND(*iFile); if (UNLIKELY(idx < 0 || idx > pp->file_num || - (fileType == CSFILE_STD && pp->file_opened[idx].raw == NULL) || + (fileType == CSFILE_STD && pp->file_opened[idx].raw == NULL) || (fileType != CSFILE_STD && pp->file_opened[idx].file == NULL))) { return csound->InitError(csound, Str("invalid file handle")); } @@ -174,18 +177,38 @@ else { SNDFILE *sf; void *fd; - int buf_reqd, do_scale = 0; + //int buf_reqd; + int do_scale = 0; - buf_reqd = (int) ((SF_INFO*) fileParams)->channels; if (fileType == CSFILE_SND_W) { do_scale = ((SF_INFO*) fileParams)->format; csFileType = csound->sftype2csfiletype(do_scale); - fd = csound->FileOpen2(csound, &sf, fileType, name, fileParams, - "SFDIR", csFileType, 0); + if(csound->realtime_audio_flag == 0 || forceSync == 1) { + fd = csound->FileOpen2(csound, &sf, fileType, name, fileParams, + "SFDIR", csFileType, 0); + p->async = 0; + } + else { + p->fd = fd = csound->FileOpenAsync(csound, &sf, fileType, name, fileParams, + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, + p->bufsize, 0); + p->async = 1; + } + p->nchnls = ((SF_INFO*) fileParams)->channels; } else { + if(csound->realtime_audio_flag == 0 || forceSync == 1) { fd = csound->FileOpen2(csound, &sf, fileType, name, fileParams, - "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + p->async = 0; + + } else { + p->fd = fd = csound->FileOpenAsync(csound, &sf, fileType, name, fileParams, + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, + p->bufsize, 0); + p->async = 1; + } + p->nchnls = ((SF_INFO*) fileParams)->channels; do_scale = ((SF_INFO*) fileParams)->format; } do_scale = (SF2TYPE(do_scale) == TYP_RAW ? 0 : 1); @@ -201,15 +224,17 @@ sf_command(sf, SFC_SET_NORM_FLOAT, NULL, SF_FALSE); #endif } - /* reallocate buffer if necessary */ - if ((int) ((SF_INFO*) fileParams)->channels > buf_reqd) - buf_reqd = (int) ((SF_INFO*) fileParams)->channels; - buf_reqd *= csound->ksmps; + /* if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * ((SF_INFO*) fileParams)->channels; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS + * ((SF_INFO*) fileParams)->channels; if (UNLIKELY(buf_reqd > pp->buf_size)) { pp->buf_size = buf_reqd; pp->buf = (MYFLT*) csound->ReAlloc(csound, pp->buf, sizeof(MYFLT) * buf_reqd); - } + } + */ /* VL - now using per-instance buffer */ pp->file_opened[idx].file = sf; pp->file_opened[idx].fd = fd; pp->file_opened[idx].do_scale = do_scale; @@ -247,15 +272,17 @@ static int outfile(CSOUND *csound, OUTFILE *p) { - STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; - int i, j, k; - int nsmps = csound->ksmps; - int nargs = p->nargs; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, j, k, nsmps = CS_KSMPS; + uint32_t nargs = p->nargs; + MYFLT *buf = (MYFLT *) p->buf.auxp; + if (UNLIKELY(early)) nsmps -= early; if (p->f.sf == NULL) { if (p->f.f != NULL) { /* VL: make sure there is an open file */ FILE *fp = p->f.f; - for (k = 0; k < nsmps; k++) { + for (k = offset; k < nsmps; k++) { for (j = 0; j < nargs; j++) fprintf(fp, "%g ", p->argums[j][k]); fprintf(fp, "\n"); @@ -263,14 +290,66 @@ } } else { - for (j = k = 0; j < nsmps; j++) + for (j = offset, k = p->buf_pos; j < nsmps; j++) for (i = 0; i < nargs; i++) - pp->buf[k++] = p->argums[i][j] * p->scaleFac; -#ifndef USE_DOUBLE - sf_writef_float(p->f.sf, (float*) pp->buf, nsmps); -#else - sf_writef_double(p->f.sf, (double*) pp->buf, nsmps); -#endif + buf[k++] = p->argums[i][j] * p->scaleFac; + p->buf_pos = k; + if (p->buf_pos >= p->guard_pos) { + + //#ifndef USE_DOUBLE + //sf_write_float(p->f.sf, buf, p->buf_pos); + //#else + //sf_write_double(p->f.sf, buf, p->buf_pos); + //#endif + if(p->f.async==1) + csound->WriteAsync(csound, p->f.fd, buf, p->buf_pos); + else sf_write_MYFLT(p->f.sf, buf, p->buf_pos); + p->buf_pos = 0; + } + + } + return OK; +} + +static int outfile_array(CSOUND *csound, OUTFILEA *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, j, k, nsmps = CS_KSMPS; + uint32_t nargs = p->tabin->sizes[0]; + MYFLT *buf = (MYFLT *) p->buf.auxp; + MYFLT *data = p->tabin->data; + + if (UNLIKELY(early)) nsmps -= early; + if (p->f.sf == NULL) { + if (p->f.f != NULL) { /* VL: make sure there is an open file */ + FILE *fp = p->f.f; + for (k = offset; k < nsmps; k++) { + for (j = 0; j < nargs; j++) + fprintf(fp, "%g ", data[j*CS_KSMPS+k]); + fprintf(fp, "\n"); + } + } + } + else { + for (j = offset, k = p->buf_pos; j < nsmps; j++) + for (i = 0; i < nargs; i++) + buf[k++] = data[i*CS_KSMPS+j] * p->scaleFac; + p->buf_pos = k; + if (p->buf_pos >= p->guard_pos) { + + //#ifndef USE_DOUBLE + //sf_write_float(p->f.sf, buf, p->buf_pos); + //#else + //sf_write_double(p->f.sf, buf, p->buf_pos); + //#endif + if (p->f.async==1) + csound->WriteAsync(csound, p->f.fd, buf, p->buf_pos); + else + sf_write_MYFLT(p->f.sf, buf, p->buf_pos); + p->buf_pos = 0; + } + } return OK; } @@ -306,10 +385,46 @@ (SF_FORMAT_PCM_24 | SF_FORMAT_IRCAM), (SF_FORMAT_DOUBLE | SF_FORMAT_IRCAM) }; -static int outfile_set(CSOUND *csound, OUTFILE *p) +static int fout_flush_callback(CSOUND *csound, void *p_) +{ + OUTFILE *p = (OUTFILE*) p_; + + if (p->f.sf != NULL && p->buf_pos > 0) { + //#ifndef USE_DOUBLE + //sf_write_float(p->f.sf, (float*) p->buf.auxp, p->buf_pos); + //#else + //sf_write_double(p->f.sf, (double*) p->buf.auxp, p->buf_pos); + //#endif + if(p->f.async == 1) + csound->WriteAsync(csound, p->f.fd, (MYFLT *) p->buf.auxp, p->buf_pos); + else + sf_write_MYFLT(p->f.sf, (MYFLT *) p->buf.auxp, p->buf_pos); + } + return OK; +} + +static int fouta_flush_callback(CSOUND *csound, void *p_) +{ + OUTFILEA *p = (OUTFILEA*) p_; + + if (p->f.sf != NULL && p->buf_pos > 0) { + //#ifndef USE_DOUBLE + //sf_write_float(p->f.sf, (float*) p->buf.auxp, p->buf_pos); + //#else + //sf_write_double(p->f.sf, (double*) p->buf.auxp, p->buf_pos); + //#endif + if (p->f.async == 1) + csound->WriteAsync(csound, p->f.fd, (MYFLT *) p->buf.auxp, p->buf_pos); + else + sf_write_MYFLT(p->f.sf, (MYFLT *) p->buf.auxp, p->buf_pos); + } + return OK; +} + +static int outfile_set_(CSOUND *csound, OUTFILE *p, int istring) { SF_INFO sfinfo; - int format_, n; + int format_, n, buf_reqd; memset(&sfinfo, 0, sizeof(SF_INFO)); format_ = (int) MYFLT2LRND(*p->iflag); @@ -321,11 +436,82 @@ sfinfo.format |= FORMAT2SF(csound->oparms->outformat); if (!SF2TYPE(sfinfo.format)) sfinfo.format |= TYPE2SF(csound->oparms->filetyp); - sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); + sfinfo.samplerate = (int) MYFLT2LRND(CS_ESR); p->nargs = p->INOCOUNT - 2; + p->buf_pos = 0; + + if (CS_KSMPS >= 512) + p->guard_pos = CS_KSMPS * p->nargs; + else + p->guard_pos = 512* p->nargs; + + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * p->nargs; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS * p->nargs; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; sfinfo.channels = p->nargs; n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_W, - p->fname, p->XSTRCODE, &sfinfo); + p->fname, istring, &sfinfo, 0); + if (UNLIKELY(n < 0)) + return NOTOK; + + if (((STDOPCOD_GLOBALS*) csound->stdOp_Env)->file_opened[n].do_scale) + p->scaleFac = csound->dbfs_to_float; + else + p->scaleFac = FL(1.0); + + csound->RegisterDeinitCallback(csound, p, fout_flush_callback); + return OK; +} + +static int outfile_set(CSOUND *csound, OUTFILE *p){ + return outfile_set_(csound,p,0); +} + +static int outfile_set_S(CSOUND *csound, OUTFILE *p){ + return outfile_set_(csound,p,1); +} + +static int outfile_set_A(CSOUND *csound, OUTFILEA *p) +{ + SF_INFO sfinfo; + int format_, n, buf_reqd; + int len = p->tabin->sizes[0]; + + memset(&sfinfo, 0, sizeof(SF_INFO)); + format_ = (int) MYFLT2LRND(*p->iflag); + if ((unsigned int) format_ >= (unsigned int) 50) + sfinfo.format = SF_FORMAT_PCM_16 | SF_FORMAT_RAW; + else + sfinfo.format = fout_format_table[format_]; + if (!SF2FORMAT(sfinfo.format)) + sfinfo.format |= FORMAT2SF(csound->oparms->outformat); + if (!SF2TYPE(sfinfo.format)) + sfinfo.format |= TYPE2SF(csound->oparms->filetyp); + sfinfo.samplerate = (int) MYFLT2LRND(CS_ESR); + p->buf_pos = 0; + + if (CS_KSMPS >= 512) + buf_reqd = p->guard_pos = CS_KSMPS * len; + else { + p->guard_pos = 512 * len; + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * p->guard_pos; + } + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * len; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS * len; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; + sfinfo.channels = len; + n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_W, + p->fname, 1, &sfinfo, 0); if (UNLIKELY(n < 0)) return NOTOK; @@ -334,41 +520,67 @@ else p->scaleFac = FL(1.0); + csound->RegisterDeinitCallback(csound, p, fouta_flush_callback); return OK; } + static int koutfile(CSOUND *csound, KOUTFILE *p) { - STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; - int i; + int i, k; int nargs = p->nargs; + MYFLT *buf = (MYFLT *) p->buf.auxp; - for (i = 0; i < nargs; i++) - pp->buf[i] = p->argums[i][0] * p->scaleFac; -#ifndef USE_DOUBLE - sf_writef_float(p->f.sf, (float*) pp->buf, 1); -#else - sf_writef_double(p->f.sf, (double*) pp->buf, 1); -#endif + for (i = 0, k = p->buf_pos; i < nargs; i++) + buf[k++] = p->argums[i][0] * p->scaleFac; + p->buf_pos = k; + if (p->buf_pos >= p->guard_pos) { + //#ifndef USE_DOUBLE + //sf_write_float(p->f.sf, buf, p->buf_pos); + //#else + //sf_write_double(p->f.sf, buf, p->buf_pos); + //#endif + if(p->f.async==1) + csound->WriteAsync(csound, p->f.fd, buf, p->buf_pos); + else sf_write_MYFLT(p->f.sf, buf, p->buf_pos); + p->buf_pos = 0; + } return OK; } -static int koutfile_set(CSOUND *csound, KOUTFILE *p) +static int koutfile_set_(CSOUND *csound, KOUTFILE *p, int istring) { SF_INFO sfinfo; - int format_, n; + int format_, n, buf_reqd; memset(&sfinfo, 0, sizeof(SF_INFO)); p->nargs = p->INOCOUNT - 2; + p->buf_pos = 0; + + if (CS_KSMPS >= 512) + p->guard_pos = CS_KSMPS * p->nargs; + else + p->guard_pos = 512 * p->nargs; + sfinfo.channels = p->nargs; - sfinfo.samplerate = (int) MYFLT2LRND(csound->ekr); + sfinfo.samplerate = (int) MYFLT2LRND(CS_EKR); format_ = (int) MYFLT2LRND(*p->iflag); if ((unsigned int) format_ >= (unsigned int) 10) sfinfo.format = SF_FORMAT_PCM_16 | SF_FORMAT_RAW; else sfinfo.format = fout_format_table[format_] | SF_FORMAT_RAW; - n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_W, - p->fname, p->XSTRCODE, &sfinfo); + + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * p->nargs; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS + * p->nargs; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; + n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_W, + p->fname, istring, &sfinfo, 0); if (UNLIKELY(n < 0)) return NOTOK; @@ -377,9 +589,19 @@ else p->scaleFac = FL(1.0); + csound->RegisterDeinitCallback(csound, p, fout_flush_callback); return OK; } +static int koutfile_set(CSOUND *csound, KOUTFILE *p){ + return koutfile_set_(csound,p,0); +} + +static int koutfile_set_S(CSOUND *csound, KOUTFILE *p){ + return koutfile_set_(csound,p,1); +} + + /*--------------*/ /* syntax: @@ -389,7 +611,7 @@ /* open a file and return its handle */ /* the handle is simply a stack index */ -static int fiopen(CSOUND *csound, FIOPEN *p) +static int fiopen_(CSOUND *csound, FIOPEN *p, int istring) { char *omodes[] = {"w", "r", "wb", "rb"}; FILE *rfp = (FILE*) NULL; @@ -398,7 +620,7 @@ if (idx < 0 || idx > 3) idx = 0; n = fout_open_file(csound, (FOUT_FILE*) NULL, &rfp, CSFILE_STD, - p->fname, p->XSTRCODE, omodes[idx]); + p->fname, istring, omodes[idx], 1); if (UNLIKELY(n < 0)) return NOTOK; if (idx > 1) @@ -408,16 +630,26 @@ return OK; } -static int ficlose_opcode(CSOUND *csound, FICLOSE *p) +static int fiopen(CSOUND *csound, FIOPEN *p){ + return fiopen_(csound, p, 0); +} + +static int fiopen_S(CSOUND *csound, FIOPEN *p){ + return fiopen_(csound, p, 1); +} + +static int ficlose_opcode_(CSOUND *csound, FICLOSE *p, int istring) { STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; int idx = -1; - if (p->XSTRCODE || *(p->iFile) == SSTRCOD) { - char *fname; - fname = csound->strarg2name(csound, NULL, p->iFile, "fout.", p->XSTRCODE); + if (istring || ISSTRCOD(*(p->iFile))){ + char *fname = NULL; + if(istring) fname = cs_strdup(csound, ((STRINGDAT *)p->iFile)->data); + else if(ISSTRCOD(*(p->iFile))) + fname = cs_strdup(csound, get_arg_string(csound, *p->iFile)); if (UNLIKELY(fname == NULL || fname[0] == (char) 0)) { - csound->Free(csound, fname); + if(fname != NULL) csound->Free(csound, fname); return csound->InitError(csound, Str("invalid file name")); } for (idx = 0; idx <= pp->file_num; idx++) { @@ -436,7 +668,8 @@ } else { idx = (int) MYFLT2LRND(*(p->iFile)); - if (UNLIKELY(idx < 0 || idx > pp->file_num || pp->file_opened[idx].fd == NULL)) { + if (UNLIKELY(idx < 0 || idx > pp->file_num || + pp->file_opened[idx].fd == NULL)) { csound->Warning(csound, Str("cannot close file #%d: not a valid handle"), idx); return OK; @@ -452,7 +685,8 @@ } else { FOUT_FILE tmp; - pp->file_opened[idx].refCount = 1; /*ref count was set to 0x80000001U, but it needs to be 1 */ + pp->file_opened[idx].refCount = 1; + /*ref count was set to 0x80000001U, but it needs to be 1 */ memset(&tmp, 0, sizeof(FOUT_FILE)); tmp.h.insdshead = p->h.insdshead; tmp.idx = idx + 1; @@ -462,6 +696,14 @@ return OK; } +static int ficlose_opcode(CSOUND *csound, FICLOSE *p){ + return ficlose_opcode_(csound,p,0); +} + +static int ficlose_opcode_S(CSOUND *csound, FICLOSE *p){ + return ficlose_opcode_(csound,p,1); +} + /* syntax: fouti ihandle, iascii, iflag, iarg1 [, iarg2, ...., iargN] */ @@ -471,19 +713,20 @@ STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; MYFLT **args = p->argums; FILE *rfil; - int j, n = (int) MYFLT2LRND(*p->ihandle); + uint32_t j; + int n = (int) MYFLT2LRND(*p->ihandle); if (UNLIKELY(n < 0 || n > pp->file_num)) - csound->Die(csound, Str("fouti: invalid file handle")); + return csound->InitError(csound, Str("fouti: invalid file handle")); rfil = pp->file_opened[n].raw; if (UNLIKELY(rfil == NULL)) - csound->Die(csound, Str("fouti: invalid file handle")); + return csound->InitError(csound, Str("fouti: invalid file handle")); if (*p->iascii == 0) { /* ascii format */ switch ((int) MYFLT2LRND(*p->iflag)) { case 1: { /* with prefix (i-statement, p1, p2 and p3) */ int p1 = (int) p->h.insdshead->p1; - double p2 = (double) csound->kcounter * csound->onedkr; + double p2 = (double) CS_KCNT * CS_ONEDKR; double p3 = p->h.insdshead->p3; if (p3 > FL(0.0)) fprintf(rfil, "i %i %f %f ", p1, p2, p3); @@ -493,11 +736,11 @@ break; case 2: /* with prefix (start at 0 time) */ if (pp->fout_kreset == 0) - pp->fout_kreset = csound->kcounter; + pp->fout_kreset = CS_KCNT; { int p1 = (int) p->h.insdshead->p1; - double p2 = (double) (csound->kcounter - pp->fout_kreset) - * csound->onedkr; + double p2 = (double) (CS_KCNT - pp->fout_kreset) + * CS_ONEDKR; double p3 = p->h.insdshead->p3; if (p3 > FL(0.0)) fprintf(rfil, "i %i %f %f ", p1, p2, p3); @@ -522,15 +765,17 @@ return OK; } + + static int ioutfile_set_r(CSOUND *csound, IOUTFILE_R *p) { STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; if (p->h.insdshead->xtratim < 1) p->h.insdshead->xtratim = 1; - p->counter = csound->kcounter; + p->counter = CS_KCNT; p->done = 1; if (*p->iflag == 2 && pp->fout_kreset == 0) - pp->fout_kreset = csound->kcounter; + pp->fout_kreset = CS_KCNT; return OK; } @@ -539,7 +784,8 @@ STDOPCOD_GLOBALS *pp; MYFLT **args; FILE *rfil; - int j, n; + uint32_t j; + int n; if (!p->h.insdshead->relesing || !p->done) return OK; @@ -548,27 +794,27 @@ args = p->argums; n = (int) MYFLT2LRND(*p->ihandle); if (UNLIKELY(n < 0 || n > pp->file_num)) - csound->Die(csound, Str("fouti: invalid file handle")); + return csound->InitError(csound, Str("fouti: invalid file handle")); rfil = pp->file_opened[n].raw; if (UNLIKELY(rfil == NULL)) - csound->Die(csound, Str("fouti: invalid file handle")); + return csound->InitError(csound, Str("fouti: invalid file handle")); if (*p->iascii == 0) { /* ascii format */ switch ((int) MYFLT2LRND(*p->iflag)) { case 1: { /* whith prefix (i-statement, p1, p2 and p3) */ int p1 = (int) p->h.insdshead->p1; - double p2 = p->counter * csound->onedkr; - double p3 = (double) (csound->kcounter - p->counter) - * csound->onedkr; + double p2 = p->counter * CS_ONEDKR; + double p3 = (double) (CS_KCNT - p->counter) + * CS_ONEDKR; fprintf(rfil, "i %i %f %f ", p1, p2, p3); } break; case 2: /* with prefix (start at 0 time) */ { int p1 = (int) p->h.insdshead->p1; - double p2 = (p->counter - pp->fout_kreset) * csound->onedkr; - double p3 = (double) (csound->kcounter - p->counter) - * csound->onedkr; + double p2 = (p->counter - pp->fout_kreset) * CS_ONEDKR; + double p3 = (double) (CS_KCNT - p->counter) + * CS_ONEDKR; fprintf(rfil, "i %i %f %f ", p1, p2, p3); } break; @@ -593,20 +839,36 @@ /*----------------------------------*/ -static int infile_set(CSOUND *csound, INFILE *p) +static int infile_set_(CSOUND *csound, INFILE *p, int istring) { SF_INFO sfinfo; - int n; - + int n, buf_reqd; + p->nargs = p->INOCOUNT - 3; + p->currpos = MYFLT2LRND(*p->iskpfrms); + p->flag = 1; memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.samplerate = (int) MYFLT2LRND(csound->esr); + sfinfo.samplerate = (int) MYFLT2LRND(CS_ESR); if ((int) MYFLT2LRND(*p->iflag) == 0) sfinfo.format = FORMAT2SF(AE_FLOAT) | TYPE2SF(TYP_RAW); else sfinfo.format = FORMAT2SF(AE_SHORT) | TYPE2SF(TYP_RAW); sfinfo.channels = p->INOCOUNT - 3; + if (CS_KSMPS >= 512) + p->frames = CS_KSMPS; + else + p->frames = (int)(512 / CS_KSMPS) * CS_KSMPS; + + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * sfinfo.channels; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS + * p->nargs; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_R, - p->fname, p->XSTRCODE, &sfinfo); + p->fname, istring, &sfinfo, 0); if (UNLIKELY(n < 0)) return NOTOK; @@ -614,57 +876,230 @@ p->scaleFac = csound->e0dbfs; else p->scaleFac = FL(1.0); - p->nargs = p->INOCOUNT - 3; + + + + p->guard_pos = p->frames * p->nargs; + p->buf_pos = p->guard_pos; + + if(p->f.async == 1) + csound->FSeekAsync(csound,p->f.fd, p->currpos*p->f.nchnls, SEEK_SET); + + return OK; +} + +static int infile_set(CSOUND *csound, INFILE *p){ + return infile_set_(csound,p,0); +} + +static int infile_set_S(CSOUND *csound, INFILE *p){ + return infile_set_(csound,p,1); +} + +static inline void tabensure(CSOUND *csound, ARRAYDAT *p, int size) +{ + if (p->data==NULL || p->dimensions == 0 || + (p->dimensions==1 && p->sizes[0] < size)) { + uint32_t ss = sizeof(MYFLT)*size; + if (p->data==NULL) p->data = (MYFLT*)mmalloc(csound, ss); + else p->data = (MYFLT*) mrealloc(csound, p->data, ss); + p->dimensions = 1; + p->arrayMemberSize = sizeof(MYFLT); + p->sizes = (int*)mmalloc(csound, sizeof(int)); + p->sizes[0] = size; + } +} + +static int infile_set_A(CSOUND *csound, INFILEA *p) +{ + SF_INFO sfinfo; + int n, buf_reqd; p->currpos = MYFLT2LRND(*p->iskpfrms); p->flag = 1; + memset(&sfinfo, 0, sizeof(SF_INFO)); + sfinfo.samplerate = (int) MYFLT2LRND(CS_ESR); + if ((int) MYFLT2LRND(*p->iflag) == 0) + sfinfo.format = FORMAT2SF(AE_FLOAT) | TYPE2SF(TYP_RAW); + else + sfinfo.format = FORMAT2SF(AE_SHORT) | TYPE2SF(TYP_RAW); + sfinfo.channels = p->INOCOUNT - 3; + if (CS_KSMPS >= 512) + p->frames = CS_KSMPS; + else + p->frames = (int)(512 / CS_KSMPS) * CS_KSMPS; + p->chn = sfinfo.channels; + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * sfinfo.channels; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS * sfinfo.channels; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; + n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_R, + p->fname, 1, &sfinfo, 0); + if (UNLIKELY(n < 0)) + return NOTOK; + if (((STDOPCOD_GLOBALS*) csound->stdOp_Env)->file_opened[n].do_scale) + p->scaleFac = csound->e0dbfs; + else + p->scaleFac = FL(1.0); + + p->guard_pos = p->frames * p->chn; + p->buf_pos = p->guard_pos; + + if(p->f.async == 1) + csound->FSeekAsync(csound,p->f.fd, p->currpos*p->f.nchnls, SEEK_SET); + + tabensure(csound, p->tabout, p->chn); return OK; } static int infile_act(CSOUND *csound, INFILE *p) { - STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; - int i, j = 0, k = 0, n; - int nsmps = csound->ksmps, nargs = p->nargs; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, k, j = offset; + uint32_t nsmps = CS_KSMPS, ksmps, nargs = p->nargs; + MYFLT *buf = (MYFLT *) p->buf.auxp; + ksmps = nsmps; + if (UNLIKELY(offset)) + for (i = 0; i < nargs; i++) + memset(p->argums[i], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i = 0; i < nargs; i++) + memset(&p->argums[i][nsmps], '\0', early*sizeof(MYFLT)); + } if (p->flag) { - sf_seek(p->f.sf, p->currpos, SEEK_SET); - p->currpos += nsmps; -#ifndef USE_DOUBLE - n = (int) sf_readf_float(p->f.sf, (float*) pp->buf, nsmps); -#else - n = (int) sf_readf_double(p->f.sf, (double*) pp->buf, nsmps); -#endif - for ( ; j < n; j++) + if (p->buf_pos >= p->guard_pos) { + if(UNLIKELY(p->f.async == 0)){ + sf_seek(p->f.sf, p->currpos*p->f.nchnls, SEEK_SET); + p->remain = (uint32_t) sf_read_MYFLT(p->f.sf, (MYFLT*) buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } else { + p->remain = csoundReadAsync(csound,p->f.fd,(MYFLT *)buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } + p->currpos += p->frames; + p->buf_pos = 0; + } + if (p->remain < nsmps) + nsmps = p->remain; + for (k = (uint32_t)p->buf_pos; j < nsmps; j++) for (i = 0; i < nargs; i++) - p->argums[i][j] = pp->buf[k++] * p->scaleFac; - if (n >= csound->ksmps) - return OK; - p->flag = 0; + p->argums[i][j] = buf[k++] * p->scaleFac; + p->buf_pos = k; + p->remain -= ksmps; + if (p->remain <= 0 && p->buf_pos < p->guard_pos) { + p->flag = 0; + for (; j < ksmps; j++) + for (i = 0; i < nargs; i++) + p->argums[i][j] = FL(0.0); + } + return OK; } - for ( ; j < nsmps; j++) + for ( ; j < ksmps; j++) for (i = 0; i < nargs; i++) p->argums[i][j] = FL(0.0); return OK; } +static int infile_arr(CSOUND *csound, INFILEA *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, k, j = offset; + uint32_t nsmps = CS_KSMPS, ksmps, chn = p->chn; + MYFLT *buf = (MYFLT *) p->buf.auxp; + MYFLT *data = p->tabout->data; + + ksmps = nsmps; + if (UNLIKELY(offset)) + for (i = 0; i < chn; i++) + memset(&data[i*chn], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (i = 0; i < chn; i++) + memset(&data[i*chn+nsmps], '\0', early*sizeof(MYFLT)); + } + if (p->flag) { + if (p->buf_pos >= p->guard_pos) { + if(UNLIKELY(p->f.async == 0)){ + sf_seek(p->f.sf, p->currpos*p->f.nchnls, SEEK_SET); + p->remain = (uint32_t) sf_read_MYFLT(p->f.sf, (MYFLT*) buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } else { + p->remain = csoundReadAsync(csound,p->f.fd,(MYFLT *)buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } + p->currpos += p->frames; + p->buf_pos = 0; + } + if (p->remain < nsmps) + nsmps = p->remain; + for (k = (uint32_t)p->buf_pos; j < nsmps; j++) + for (i = 0; i < chn; i++) + data[i*chn+j] = buf[k++] * p->scaleFac; + p->buf_pos = k; + p->remain -= ksmps; + if (p->remain <= 0 && p->buf_pos < p->guard_pos) { + p->flag = 0; + for (; j < ksmps; j++) + for (i = 0; i < chn; i++) + data[i*chn+j] = FL(0.0); + } + return OK; + } + for ( ; j < ksmps; j++) + for (i = 0; i < chn; i++) + data[i*chn+j] = FL(0.0); + + return OK; +} + /* ---------------------------- */ -static int kinfile_set(CSOUND *csound, KINFILE *p) +static int kinfile_set_(CSOUND *csound, KINFILE *p, int istring) { SF_INFO sfinfo; - int n; + int n, buf_reqd; memset(&sfinfo, 0, sizeof(SF_INFO)); - sfinfo.samplerate = (int) MYFLT2LRND(csound->ekr); + sfinfo.samplerate = (int) MYFLT2LRND(CS_EKR); if ((int) MYFLT2LRND(*p->iflag) == 0) sfinfo.format = FORMAT2SF(AE_FLOAT) | TYPE2SF(TYP_RAW); else sfinfo.format = FORMAT2SF(AE_SHORT) | TYPE2SF(TYP_RAW); sfinfo.channels = p->INOCOUNT - 3; + + p->nargs = p->INOCOUNT - 3; + p->currpos = MYFLT2LRND(*p->iskpfrms); + p->flag = 1; + + if (CS_KSMPS >= 512) + p->frames = CS_KSMPS; + else + p->frames = (int)(512 / CS_KSMPS) * CS_KSMPS; + + if (CS_KSMPS >= 512) + buf_reqd = CS_KSMPS * sfinfo.channels; + else + buf_reqd = (1 + (int)(512 / CS_KSMPS)) * CS_KSMPS + * p->nargs; + if (p->buf.auxp == NULL || p->buf.size < buf_reqd*sizeof(MYFLT)) { + csound->AuxAlloc(csound, sizeof(MYFLT)*buf_reqd, &p->buf); + } + p->f.bufsize = p->buf.size; n = fout_open_file(csound, &(p->f), NULL, CSFILE_SND_R, - p->fname, p->XSTRCODE, &sfinfo); + p->fname, istring, &sfinfo, 0); if (UNLIKELY(n < 0)) return NOTOK; @@ -672,30 +1107,51 @@ p->scaleFac = csound->e0dbfs; else p->scaleFac = FL(1.0); - p->nargs = p->INOCOUNT - 3; - p->currpos = MYFLT2LRND(*p->iskpfrms); - p->flag = 1; + + p->guard_pos = p->frames * p->nargs; + p->buf_pos = p->guard_pos; + + if(p->f.async == 1) + csound->FSeekAsync(csound,p->f.fd, p->currpos*p->f.nchnls, SEEK_SET); return OK; } +static int kinfile_set(CSOUND *csound, KINFILE *p){ + return kinfile_set_(csound,p,0); +} + +static int kinfile_set_S(CSOUND *csound, KINFILE *p){ + return kinfile_set_(csound,p,1); +} + + static int kinfile(CSOUND *csound, KINFILE *p) { - STDOPCOD_GLOBALS *pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; - int i, n; + int i, k; int nargs = p->nargs; + MYFLT *buf = (MYFLT *) p->buf.auxp; if (p->flag) { - sf_seek(p->f.sf, p->currpos, SEEK_SET); - p->currpos++; -#ifndef USE_DOUBLE - n = (int) sf_readf_float(p->f.sf, (float*) pp->buf, 1); -#else - n = (int) sf_readf_double(p->f.sf, (double*) pp->buf, 1); -#endif - if (n > 0) { - for (i = 0; i < nargs; i++) - p->argums[i][0] = pp->buf[i] * p->scaleFac; + if (p->buf_pos >= p->guard_pos) { + if(UNLIKELY(p->f.async == 0)){ + sf_seek(p->f.sf, p->currpos*p->f.nchnls, SEEK_SET); + p->remain = (uint32_t) sf_read_MYFLT(p->f.sf, (MYFLT*) buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } else { + p->remain = csoundReadAsync(csound,p->f.fd,(MYFLT *)buf, + p->frames*p->f.nchnls); + p->remain /= p->f.nchnls; + } + p->currpos += p->frames; + p->buf_pos = 0; + } + if (p->remain > 0) { + for (i = 0, k = p->buf_pos; i < nargs; i++) + p->argums[i][0] = buf[k++] * p->scaleFac; + p->buf_pos = k; + p->remain--; return OK; } p->flag = 0; @@ -705,7 +1161,7 @@ return OK; } -static int i_infile(CSOUND *csound, I_INFILE *p) +static int i_infile_(CSOUND *csound, I_INFILE *p, int istring) { int j, n, nargs; FILE *fp = NULL; @@ -716,7 +1172,7 @@ if (UNLIKELY(idx < 0 || idx > 2)) idx = 0; n = fout_open_file(csound, (FOUT_FILE*) NULL, &fp, CSFILE_STD, - p->fname, p->XSTRCODE, omodes[idx]); + p->fname, istring, omodes[idx], 0); if (UNLIKELY(n < 0)) return NOTOK; @@ -784,22 +1240,34 @@ return OK; } +static int i_infile(CSOUND *csound, I_INFILE *p){ + return i_infile_(csound,p,0); +} + +static int i_infile_S(CSOUND *csound, I_INFILE *p){ + return i_infile_(csound,p,1); +} + + /*---------------------------*/ static int incr(CSOUND *csound, INCR *p) { MYFLT *avar = p->avar, *aincr = p->aincr; - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; - for (n = 0; n < csound->ksmps; n++) + if (UNLIKELY(early)) nsmps -= early; + for (n = offset; n < nsmps; n++) avar[n] += aincr[n]; return OK; } static int clear(CSOUND *csound, CLEARS *p) { - int nsmps = csound->ksmps, j; - + uint32_t nsmps = CS_KSMPS, j; + for (j = 0; j < p->INOCOUNT; j++) { memset(p->argums[j], 0, sizeof(MYFLT)*nsmps); } @@ -809,20 +1277,20 @@ /*---------------------------------*/ /* formatted output to a text file */ -static int fprintf_set(CSOUND *csound, FPRINTF *p) +static int fprintf_set_(CSOUND *csound, FPRINTF *p, int istring) { int n; - char *sarg = (char*) p->fmt; + char *sarg = (char*) p->fmt->data; char *sdest = p->txtstring; memset(p->txtstring, 0, 8192); /* Nasty to have exposed constant in code */ if (p->h.opadr != (SUBR) NULL) /* fprintks */ n = fout_open_file(csound, &(p->f), NULL, CSFILE_STD, - p->fname, p->XSTRCODE & 1, "w"); + p->fname, istring, "w", 1); else /* fprints */ n = fout_open_file(csound, (FOUT_FILE*) NULL, &(p->f.f), CSFILE_STD, - p->fname, p->XSTRCODE & 1, "w"); + p->fname, istring, "w", 1); if (UNLIKELY(n < 0)) return NOTOK; setvbuf(p->f.f, (char*)NULL, _IOLBF, 0); /* Seems a good option */ @@ -927,6 +1395,14 @@ return OK; } +static int fprintf_set(CSOUND *csound, FPRINTF *p){ + return fprintf_set_(csound,p,0); +} + +static int fprintf_set_S(CSOUND *csound, FPRINTF *p){ + return fprintf_set_(csound,p,1); +} + /* perform a sprintf-style format -- matt ingalls */ static void sprints(char *outstring, char *fmt, MYFLT **kvals, int32 numVals) { @@ -942,7 +1418,7 @@ switch (*segwaiting) { case '%': - sprintf(outstring, "%"); + sprintf(outstring, "%%"); j--; break; case 'd': @@ -993,7 +1469,7 @@ if (segwaiting) { switch (*segwaiting) { case '%': - sprintf(outstring, "%"); + sprintf(outstring, "%%"); j--; break; case 'd': @@ -1046,35 +1522,72 @@ return OK; } -#define S(x) sizeof(x) +static int fprintf_i_S(CSOUND *csound, FPRINTF *p) +{ + char string[8192]; + + if (UNLIKELY(fprintf_set_S(csound, p) != OK)) + return NOTOK; + sprints(string, p->txtstring, p->argums, p->INOCOUNT - 2); + fprintf(p->f.f, string); + /* fflush(p->f.f); */ + return OK; +} +#define S(x) sizeof(x) static OENTRY localops[] = { - { "fprints", S(FPRINTF), 1, "", "TSM", - (SUBR) fprintf_i, (SUBR) NULL, (SUBR) NULL }, - { "fprintks", S(FPRINTF), 3, "", "TSM", - (SUBR) fprintf_set, (SUBR) fprintf_k, (SUBR) NULL }, - { "vincr", S(INCR), 4, "", "aa", - (SUBR) NULL, (SUBR) NULL, (SUBR) incr }, - { "clear", S(CLEARS), 4, "", "y", - (SUBR) NULL, (SUBR) NULL, (SUBR) clear }, - { "fout", S(OUTFILE), 5, "", "Tiy", - (SUBR) outfile_set, (SUBR) NULL, (SUBR) outfile }, - { "foutk", S(KOUTFILE), 3, "", "Tiz", - (SUBR) koutfile_set, (SUBR) koutfile, (SUBR) NULL }, - { "fouti", S(IOUTFILE), 1, "", "iiim", - (SUBR) ioutfile_set, (SUBR) NULL, (SUBR) NULL }, - { "foutir", S(IOUTFILE_R), 3, "", "iiim", - (SUBR) ioutfile_set_r, (SUBR) ioutfile_r, (SUBR) NULL }, - { "fiopen", S(FIOPEN), 1, "i", "Ti", - (SUBR) fiopen, (SUBR) NULL, (SUBR) NULL }, - { "ficlose", S(FICLOSE), 1, "", "T", - (SUBR) ficlose_opcode, (SUBR) NULL, (SUBR) NULL }, - { "fin", S(INFILE), 5, "", "Tiiy", - (SUBR) infile_set, (SUBR) NULL, (SUBR) infile_act }, - { "fink", S(KINFILE), 3, "", "Tiiz", - (SUBR) kinfile_set, (SUBR) kinfile, (SUBR) NULL }, - { "fini", S(I_INFILE), 1, "", "Tiim", - (SUBR) i_infile, (SUBR) NULL, (SUBR) NULL } + + {"fprints", S(FPRINTF), 0, 1, "", "SSM", + (SUBR) fprintf_i_S, (SUBR) NULL,(SUBR) NULL, NULL, }, + {"fprints.i", S(FPRINTF), 0, 1, "", "iSM", + (SUBR) fprintf_i, (SUBR) NULL,(SUBR) NULL, NULL}, + { "fprintks", S(FPRINTF), WR, 3, "", "SSM", + (SUBR) fprintf_set_S, (SUBR) fprintf_k, (SUBR) NULL, NULL,}, + { "fprintks.i", S(FPRINTF), WR, 3, "", "iSM", + (SUBR) fprintf_set, (SUBR) fprintf_k, (SUBR) NULL, NULL}, + { "vincr", S(INCR), 0, 4, "", "aa", + (SUBR) NULL, (SUBR) NULL, (SUBR) incr, NULL }, + { "clear", S(CLEARS), 0, 4, "", "y", + + (SUBR) NULL, (SUBR) NULL, (SUBR) clear, NULL}, + { "fout", S(OUTFILE), 0, 5, "", "Siy", + (SUBR) outfile_set_S, (SUBR) NULL, (SUBR) outfile, NULL}, + { "fout.A", S(OUTFILEA), 0, 5, "", "Sia[]", + (SUBR) outfile_set_A, (SUBR) NULL, (SUBR) outfile_array, NULL}, + { "fout.i", S(OUTFILE), 0, 5, "", "iiy", + (SUBR) outfile_set, (SUBR) NULL, (SUBR) outfile, NULL}, + { "foutk", S(KOUTFILE), 0, 3, "", "Siz", + (SUBR) koutfile_set_S, (SUBR) koutfile, (SUBR) NULL, NULL }, + { "foutk.i", S(KOUTFILE), 0, 3, "", "iiz", + (SUBR) koutfile_set, (SUBR) koutfile, (SUBR) NULL, NULL }, + + { "fouti", S(IOUTFILE), 0, 1, "", "iiim", + (SUBR) ioutfile_set, (SUBR) NULL, (SUBR) NULL, NULL }, + { "foutir", S(IOUTFILE_R), 0, 3, "", "iiim", + + (SUBR) ioutfile_set_r, (SUBR) ioutfile_r, (SUBR) NULL, NULL}, + { "fiopen", S(FIOPEN), 0, 1, "i", "Si", + (SUBR) fiopen_S, (SUBR) NULL, (SUBR) NULL, NULL}, + { "fiopen.i", S(FIOPEN), 0, 1, "i", "ii", + (SUBR) fiopen, (SUBR) NULL, (SUBR) NULL, NULL}, + { "ficlose", S(FICLOSE), 0, 1, "", "S", + (SUBR) ficlose_opcode_S, (SUBR) NULL, (SUBR) NULL, NULL}, + { "ficlose.S", S(FICLOSE), 0, 1, "", "i", + (SUBR) ficlose_opcode, (SUBR) NULL, (SUBR) NULL, NULL }, + { "fin.a", S(INFILE), 0, 5, "", "Siiy", + (SUBR) infile_set_S, (SUBR) NULL, (SUBR) infile_act, NULL}, + { "fin.A", S(INFILEA), 0, 5, "", "Siia[]", + (SUBR) infile_set_A, (SUBR) NULL, (SUBR) infile_arr, NULL}, + { "fin.i", S(INFILE), 0, 5, "", "iiiy", + (SUBR) infile_set, (SUBR) NULL, (SUBR) infile_act, NULL}, + { "fink", S(KINFILE), 0, 3, "", "Siiz", + (SUBR) kinfile_set_S, (SUBR) kinfile, (SUBR) NULL, NULL}, + { "fink.i", S(KINFILE), 0, 3, "", "iiiz", + (SUBR) kinfile_set, (SUBR) kinfile, (SUBR) NULL, NULL}, + { "fini", S(I_INFILE), 0, 1, "", "Siim", + (SUBR) i_infile_S, (SUBR) NULL, (SUBR) NULL, NULL }, + { "fini.i", S(I_INFILE), 0, 1, "", "iiim", + (SUBR) i_infile, (SUBR) NULL, (SUBR) NULL, NULL} }; int fout_init_(CSOUND *csound) @@ -1082,4 +1595,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/fout.h csound-6.02~dfsg/Opcodes/fout.h --- csound-5.17.11~dfsg/Opcodes/fout.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/fout.h 2014-01-07 16:53:48.000000000 +0000 @@ -30,6 +30,10 @@ OPDS h; SNDFILE *sf; FILE *f; + void *fd; + int bufsize; + int nchnls; + int async; int idx; /* file index + 1 */ } FOUT_FILE; @@ -38,14 +42,31 @@ MYFLT *fname, *iflag, *argums[VARGMAX]; MYFLT scaleFac; int nargs; + int buf_pos; + int guard_pos; + AUXCH buf; FOUT_FILE f; } OUTFILE; typedef struct { OPDS h; + MYFLT *fname, *iflag; + ARRAYDAT* tabin; + MYFLT scaleFac; + int buf_pos; + int guard_pos; + AUXCH buf; + FOUT_FILE f; +} OUTFILEA; + +typedef struct { + OPDS h; MYFLT *fname, *iflag, *argums[VARGMAX]; MYFLT scaleFac; - int nargs; + uint32_t nargs; + int buf_pos; + int guard_pos; + AUXCH buf; FOUT_FILE f; } KOUTFILE; @@ -56,16 +77,42 @@ int32 currpos; int flag; int nargs; + int buf_pos; + int guard_pos; + int frames; + uint32_t remain; + AUXCH buf; FOUT_FILE f; } INFILE; typedef struct { OPDS h; + MYFLT *fname, *iskpfrms, *iflag; + ARRAYDAT *tabout; + MYFLT scaleFac; + int32 currpos; + int flag; + int chn; + int buf_pos; + int guard_pos; + int frames; + uint32_t remain; + AUXCH buf; + FOUT_FILE f; +} INFILEA; + +typedef struct { + OPDS h; MYFLT *fname, *iskpfrms, *iflag, *argums[VARGMAX]; MYFLT scaleFac; int32 currpos; int flag; int nargs; + int buf_pos; + int guard_pos; + int frames; + int remain; + AUXCH buf; FOUT_FILE f; } KINFILE; @@ -112,7 +159,9 @@ typedef struct { OPDS h; - MYFLT *fname, *fmt, *argums[VARGMAX]; + MYFLT *fname; + STRINGDAT *fmt; + MYFLT *argums[VARGMAX]; FOUT_FILE f; char txtstring[8192]; /* Place to store the string printed */ } FPRINTF; diff -Nru csound-5.17.11~dfsg/Opcodes/freeverb.c csound-6.02~dfsg/Opcodes/freeverb.c --- csound-5.17.11~dfsg/Opcodes/freeverb.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/freeverb.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include #define DEFAULT_SRATE 44100.0 @@ -128,7 +128,7 @@ nbytes += allpass_nbytes(p, allpass_delays[i][0]); nbytes += allpass_nbytes(p, allpass_delays[i][1]); } - nbytes += (int) sizeof(MYFLT) * (int) csound->ksmps; + nbytes += (int) sizeof(MYFLT) * (int) CS_KSMPS; /* allocate space if size has changed */ if (nbytes != (int) p->auxData.size) csound->AuxAlloc(csound, (int32) nbytes, &(p->auxData)); @@ -172,8 +172,10 @@ double feedback, damp1, damp2, x; freeVerbComb *combp; freeVerbAllPass *allpassp; - int i, n; - int nsmps = csound->ksmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* check if opcode was correctly initialised */ if (UNLIKELY(p->auxData.size <= 0L || p->auxData.auxp == NULL)) goto err1; @@ -192,8 +194,6 @@ damp2 = 1.0 - damp1; /* comb filters (left channel) */ memset(p->tmpBuf,0, sizeof(MYFLT)*nsmps); - /* for (n = 0; n < nsmps; n++) */ - /* p->tmpBuf[n] = FL(0.0); */ for (i = 0; i < NR_COMB; i++) { combp = p->Comb[i][0]; for (n = 0; n < nsmps; n++) { @@ -218,8 +218,14 @@ p->tmpBuf[n] = (MYFLT) x; } } + /* write left channel output */ - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(p->aOutL, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aOutL[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) p->aOutL[n] = p->tmpBuf[n] * (MYFLT) fixedGain; /* comb filters (right channel) */ memset(p->tmpBuf, 0, sizeof(MYFLT)*nsmps); @@ -249,13 +255,20 @@ p->tmpBuf[n] = (MYFLT) x; } } + nsmps = CS_KSMPS; /* write right channel output */ - for (n = 0; n < nsmps; n++) + if (UNLIKELY(offset)) memset(p->aOutR, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aOutR[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) p->aOutR[n] = p->tmpBuf[n] * (MYFLT) fixedGain; return OK; err1: - return csound->PerfError(csound, Str("freeverb: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("freeverb: not initialised")); } /* module interface functions */ @@ -263,7 +276,7 @@ int freeverb_init_(CSOUND *csound) { return csound->AppendOpcode(csound, "freeverb", - (int) sizeof(FREEVERB), 5, "aa", "aakkjo", + (int) sizeof(FREEVERB), 0, 5, "aa", "aakkjo", (int (*)(CSOUND*, void*)) freeverb_init, (int (*)(CSOUND*, void*)) NULL, (int (*)(CSOUND*, void*)) freeverb_perf); diff -Nru csound-5.17.11~dfsg/Opcodes/ftconv.c csound-6.02~dfsg/Opcodes/ftconv.c --- csound-5.17.11~dfsg/Opcodes/ftconv.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ftconv.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include #define FTCONV_MAXCHN 8 @@ -64,7 +64,7 @@ irPtr = IR_Data; outBufPtr = outBuf; /* clear output buffer to zero */ - memset(outBuf, 0, sizeof(MYFLT)*(partSize - 2)); + memset(outBuf, 0, sizeof(MYFLT)*(partSize)); /* do { */ /* *(outBufPtr++) = FL(0.0); */ /* *(outBufPtr++) = FL(0.0); */ @@ -161,7 +161,7 @@ return csound->InitError(csound, Str("ftconv: invalid impulse response " "partition length")); } - ftp = csound->FTFind(csound, p->iFTNum); + ftp = csound->FTnp2Find(csound, p->iFTNum); if (UNLIKELY(ftp == NULL)) return NOTOK; /* ftfind should already have printed the error message */ /* calculate total length / number of partitions */ @@ -242,13 +242,23 @@ static int ftconv_perf(CSOUND *csound, FTCONV *p) { MYFLT *x, *rBuf; - int i, n, nn, nSamples, rBufPos; - int m = csound->ksmps; + int i, n, nSamples, rBufPos; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; if (p->initDone <= 0) goto err1; nSamples = p->partSize; rBuf = &(p->ringBuf[p->rbCnt * (nSamples << 1)]); - for (nn = 0; nn < m; nn++) { + if (UNLIKELY(offset)) + for (n = 0; n < p->nChannels; n++) + memset(p->aOut[n], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (n = 0; n < p->nChannels; n++) + memset(&p->aOut[n][nsmps], '\0', early*sizeof(MYFLT)); + } + for (nn = offset; nn < nsmps; nn++) { /* store input signal in buffer */ rBuf[p->cnt] = p->aIn[nn]; /* copy output signals from buffer */ @@ -286,7 +296,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("ftconv: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ftconv: not initialised")); } /* module interface functions */ @@ -294,7 +305,7 @@ int ftconv_init_(CSOUND *csound) { return csound->AppendOpcode(csound, "ftconv", - (int) sizeof(FTCONV), TR|5, "mmmmmmmm", "aiiooo", + (int) sizeof(FTCONV), TR, 5, "mmmmmmmm", "aiiooo", (int (*)(CSOUND *, void *)) ftconv_init, (int (*)(CSOUND *, void *)) NULL, (int (*)(CSOUND *, void *)) ftconv_perf); diff -Nru csound-5.17.11~dfsg/Opcodes/ftest.c csound-6.02~dfsg/Opcodes/ftest.c --- csound-5.17.11~dfsg/Opcodes/ftest.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ftest.c 2014-01-07 16:53:48.000000000 +0000 @@ -87,15 +87,15 @@ /* GENwave by Gleb Rogozinsky 2012 */ typedef struct { - MYFLT *pWF, *pSF; - MYFLT *pFil[2]; - int *size; + MYFLT *pWF, *pSF; + MYFLT *pFil[2]; + unsigned int *size; } WAVELET; -static int deconvolve(MYFLT *pInp, WAVELET *pwaveS, int *pnewLen, +static int deconvolve(MYFLT *pInp, WAVELET *pwaveS, unsigned int *pnewLen, MYFLT *pBuf, int *pOrder) { - int i, j; + unsigned int i, j; *pnewLen *= 2; for (j = 0; j < *pnewLen; j++) { for (i = 0; i < *pwaveS->size; i++) @@ -116,7 +116,8 @@ MYFLT order = ff->e.p[6]; MYFLT resc = ff->e.p[7]; int ffilno = (int)ff->e.p[5]; - int i, steps, newLen, *pnewLen; + unsigned int i; + unsigned int steps, newLen, *pnewLen; int nargs = ff->e.pcnt - 4; int *pOrder, *xfree; FUNC *srcfil = csound->flist[ffilno]; @@ -165,4 +166,4 @@ { NULL, NULL } }; -FLINKAGE1(ftest_fgens) +FLINKAGE_BUILTIN(ftest_fgens) diff -Nru csound-5.17.11~dfsg/Opcodes/ftgen.c csound-6.02~dfsg/Opcodes/ftgen.c --- csound-5.17.11~dfsg/Opcodes/ftgen.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ftgen.c 2014-01-07 16:54:20.000000000 +0000 @@ -24,7 +24,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include #include #include "soundio.h" @@ -84,7 +84,7 @@ /* set up and call any GEN routine */ -static int ftgen(CSOUND *csound, FTGEN *p) +static int ftgen_(CSOUND *csound, FTGEN *p, int istring1, int istring2) { MYFLT *fp; FUNC *ftp; @@ -92,7 +92,7 @@ int n; *p->ifno = FL(0.0); - ftevt = (EVTBLK*) malloc(sizeof(EVTBLK)); /* Can use malloc direct as local */ + ftevt =(EVTBLK*) malloc(sizeof(EVTBLK)); /* Can use malloc direct as local */ ftevt->opcod = 'f'; ftevt->strarg = NULL; fp = &ftevt->p[0]; @@ -101,25 +101,26 @@ fp[2] = ftevt->p2orig = FL(0.0); /* force time 0 */ fp[3] = ftevt->p3orig = *p->p3; fp[4] = *p->p4; - - if ((n = csound->GetInputArgSMask(p))) - if (n&0x8) { /* Named gen */ - NAMEDGEN *n = (NAMEDGEN*) csound->GetNamedGens(csound); - while (n) { - if (strcmp(n->name, (char *)p->p4) == 0) { /* Look up by name */ - break; + + + if (istring1) { /* Named gen */ + NAMEDGEN *named = (NAMEDGEN*) csound->GetNamedGens(csound); + while (named) { + if (strcmp(named->name, ((STRINGDAT *) p->p4)->data) == 0) { + /* Look up by name */ + break; } - n = n->next; /* and round again */ + named = named->next; /* and round again */ } - if (UNLIKELY(n == NULL)) { + if (UNLIKELY(named == NULL)) { return csound->InitError(csound, Str("Named gen \"%s\" not defined"), (char *)p->p4); } - else fp[4] = n->genum; - fp[5] = *p->p5; + else fp[4] = named->genum; } - else { /* string argument: */ + + if(istring2) { /* string argument: */ n = (int) fp[4]; fp[5] = SSTRCOD; if (n < 0) @@ -129,10 +130,10 @@ case 23: case 28: case 43: - ftevt->strarg = (char*) p->p5; + ftevt->strarg = ((STRINGDAT *) p->p5)->data; break; default: - csound->Free(csound, ftevt); + free(ftevt); return csound->InitError(csound, Str("ftgen string arg not allowed")); } } @@ -158,6 +159,22 @@ return OK; } +static int ftgen(CSOUND *csound, FTGEN *p) { + return ftgen_(csound,p,0,0); +} + +static int ftgen_S(CSOUND *csound, FTGEN *p) { + return ftgen_(csound,p,1,0); +} + +static int ftgen_iS(CSOUND *csound, FTGEN *p) { + return ftgen_(csound,p,0,1); +} + +static int ftgen_SS(CSOUND *csound, FTGEN *p) { + return ftgen_(csound,p,1,1); +} + static int ftgentmp(CSOUND *csound, FTGEN *p) { int p1, fno; @@ -171,6 +188,20 @@ return register_ftable_delete(csound, p, fno); } + +static int ftgentmp_S(CSOUND *csound, FTGEN *p) +{ + int p1, fno; + + if (UNLIKELY(ftgen_(csound, p,0,1) != OK)) + return NOTOK; + p1 = (int) MYFLT2LRND(*p->p1); + if (p1) + return OK; + fno = (int) MYFLT2LRND(*p->ifno); + return register_ftable_delete(csound, p, fno); +} + static int ftfree(CSOUND *csound, FTFREE *p) { int fno = (int) MYFLT2LRND(*p->iftno); @@ -185,32 +216,45 @@ return register_ftable_delete(csound, p, fno); } -static int ftload(CSOUND *csound, FTLOAD *p) +static int myInitError(CSOUND *csound, INSDS *p, const char *str, ...) +{ + return csound->InitError(csound, str); +} + +static int ftload_(CSOUND *csound, FTLOAD *p, int istring) { MYFLT **argp = p->argums; FUNC *ftp; char filename[MAXNAME]; int nargs = csound->GetInputArgCnt(p) - 2; FILE *file = NULL; - int (*err_func)(CSOUND *, const char *, ...); + int (*err_func)(CSOUND *, INSDS *, const char *, ...); FUNC *(*ft_func)(CSOUND *, MYFLT *); void *fd; - if (strcmp(csound->GetOpcodeName(p), "ftload") != 0) { + if (strncmp(csound->GetOpcodeName(p), "ftload", 6) != 0) { nargs--; ft_func = csound->FTFindP; err_func = csound->PerfError; } else { ft_func = csound->FTnp2Find; - err_func = csound->InitError; + err_func = myInitError; } if (UNLIKELY(nargs <= 0)) goto err2; - csound->strarg2name(csound, filename, p->ifilno, "ftsave.", - (int) csound->GetInputArgSMask(p)); + if(!istring) { + if(ISSTRCOD(*p->ifilno)) + csound->strarg2name(csound, filename, p->ifilno, "ftsave.", + 0); + else strncpy(filename, get_arg_string(csound,*p->ifilno), MAXNAME-1); + + } else { + strncpy(filename, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + } + if (*p->iflag <= FL(0.0)) { fd = csound->FileOpen2(csound, &file, CSFILE_STD, filename, "rb", "", CSFTYPE_FTABLES_BINARY, 0); @@ -219,7 +263,7 @@ FUNC header; int fno = (int) MYFLT2LRND(**argp); MYFLT fno_f = (MYFLT) fno; - int n; + size_t n; memset(&header, 0, sizeof(FUNC)); /* ***** Need to do byte order here ***** */ @@ -229,9 +273,9 @@ if (UNLIKELY(csound->FTAlloc(csound, fno, (int) header.flen) != 0)) goto err; ftp = ft_func(csound, &fno_f); - memcpy(ftp, &header, sizeof(FUNC) - sizeof(MYFLT) - SSTRSIZ); - memset(&(ftp->ftable[0]), 0, sizeof(MYFLT) * (ftp->flen + 1)); - n = fread(&(ftp->ftable[0]), sizeof(MYFLT), ftp->flen + 1, file); + memcpy(ftp, &header, sizeof(FUNC) - sizeof(MYFLT*) - SSTRSIZ); + memset(ftp->ftable, 0, sizeof(MYFLT) * (ftp->flen + 1)); + n = fread(ftp->ftable, sizeof(MYFLT), ftp->flen + 1, file); if (UNLIKELY(n!=ftp->flen + 1)) goto err4; /* ***** Need to do byte order here ***** */ argp++; @@ -246,7 +290,7 @@ char s[64], *s1; int fno = (int) MYFLT2LRND(**argp); MYFLT fno_f = (MYFLT) fno; - int32 j; + uint32_t j; char *endptr; memset(&header, 0, sizeof(FUNC)); @@ -306,22 +350,22 @@ header.fno = strtol(s1, &endptr, 10); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.gen01 = (MYFLT)strtod(s1, &endptr); + header.gen01args.gen01 = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.ifilno = (MYFLT)strtod(s1, &endptr); + header.gen01args.ifilno = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.iskptim = (MYFLT)strtod(s1, &endptr); + header.gen01args.iskptim = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.iformat = (MYFLT)strtod(s1, &endptr); + header.gen01args.iformat = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.channel = (MYFLT)strtod(s1, &endptr); + header.gen01args.channel = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; - header.gen01args.sample_rate = (MYFLT)strtod(s1, &endptr); + header.gen01args.sample_rate = (MYFLT)cs_strtod(s1, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; s1 = strchr(s, ' ')+1; /* WARNING! skips header.gen01args.strarg from saving/loading @@ -331,10 +375,10 @@ goto err; ftp = ft_func(csound, &fno_f); memcpy(ftp, &header, sizeof(FUNC) - sizeof(MYFLT)); - memset(&(ftp->ftable[0]), 0, sizeof(MYFLT) * (ftp->flen + 1)); + memset(ftp->ftable, 0, sizeof(MYFLT) * (ftp->flen + 1)); for (j = 0; j <= ftp->flen; j++) { if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; - ftp->ftable[j] = (MYFLT) strtod(s, &endptr); + ftp->ftable[j] = (MYFLT) cs_strtod(s, &endptr); if (UNLIKELY(endptr==NULL)) goto err4; } if (UNLIKELY(NULL==fgets(s, 64, file))) goto err4; @@ -345,48 +389,75 @@ return OK; err: csound->FileClose(csound, fd); - return err_func(csound, Str("ftload: error allocating ftable")); + return err_func(csound, p->h.insdshead, + Str("ftload: error allocating ftable")); err2: - return err_func(csound, Str("ftload: no table numbers")); + return err_func(csound, p->h.insdshead, Str("ftload: no table numbers")); err3: - return err_func(csound, Str("ftload: unable to open file")); + return err_func(csound, p->h.insdshead, Str("ftload: unable to open file")); err4: csound->FileClose(csound, fd); - return err_func(csound, Str("ftload: incorrect file")); + return err_func(csound, p->h.insdshead, Str("ftload: incorrect file")); +} + +static int ftload(CSOUND *csound, FTLOAD *p) +{ + return ftload_(csound, p, 0); +} + +static int ftload_S(CSOUND *csound, FTLOAD *p) +{ + return ftload_(csound, p, 1); } + static int ftload_k(CSOUND *csound, FTLOAD_K *p) { if (*p->ktrig != FL(0.0)) - return ftload(csound, &(p->p)); + return ftload_(csound, &(p->p),0); + return OK; +} + +static int ftload_kS(CSOUND *csound, FTLOAD_K *p) +{ + if (*p->ktrig != FL(0.0)) + return ftload_(csound, &(p->p), 1); return OK; } -static int ftsave(CSOUND *csound, FTLOAD *p) +static int ftsave_(CSOUND *csound, FTLOAD *p, int istring) { MYFLT **argp = p->argums; char filename[MAXNAME]; int nargs = csound->GetInputArgCnt(p) - 2; FILE *file = NULL; - int (*err_func)(CSOUND *, const char *, ...); + int (*err_func)(CSOUND *, INSDS *, const char *, ...); FUNC *(*ft_func)(CSOUND *, MYFLT *); void *fd; - if (strcmp(csound->GetOpcodeName(p), "ftsave") != 0) { + if (strncmp(csound->GetOpcodeName(p), "ftsave", 6) != 0) { nargs--; ft_func = csound->FTFindP; err_func = csound->PerfError; } else { ft_func = csound->FTnp2Find; - err_func = csound->InitError; + err_func = myInitError; } if (UNLIKELY(nargs <= 0)) goto err2; - csound->strarg2name(csound, filename, p->ifilno, "ftsave.", - (int) csound->GetInputArgSMask(p)); + if(!istring) { + if(ISSTRCOD(*p->ifilno)) + csound->strarg2name(csound, filename, p->ifilno, "ftsave.", + 0); + else strncpy(filename, get_arg_string(csound,*p->ifilno), MAXNAME-1); + + } else { + strncpy(filename, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + } + if (*p->iflag <= FL(0.0)) { fd = csound->FileOpen2(csound, &file, CSFILE_STD, filename, "wb", "", CSFTYPE_FTABLES_BINARY, 0); @@ -465,16 +536,26 @@ return OK; err: csound->FileClose(csound, fd); - return err_func(csound, Str("ftsave: Bad table number. Saving is possible " - "only for existing tables.")); + return err_func(csound, p->h.insdshead, + Str("ftsave: Bad table number. Saving is possible " + "only for existing tables.")); err2: - return err_func(csound, Str("ftsave: no table numbers")); + return err_func(csound, p->h.insdshead, Str("ftsave: no table numbers")); err3: - return err_func(csound, Str("ftsave: unable to open file")); + return err_func(csound, p->h.insdshead, Str("ftsave: unable to open file")); err4: - return err_func(csound, Str("ftsave: failed to write file")); + return err_func(csound, p->h.insdshead, Str("ftsave: failed to write file")); +} + +static int ftsave(CSOUND *csound, FTLOAD *p){ + return ftsave_(csound,p,0); +} + +static int ftsave_S(CSOUND *csound, FTLOAD *p){ + return ftsave_(csound,p,1); } + static int ftsave_k_set(CSOUND *csound, FTLOAD_K *p) { memcpy(&(p->p.h), &(p->h), sizeof(OPDS)); @@ -488,22 +569,39 @@ static int ftsave_k(CSOUND *csound, FTLOAD_K *p) { if (*p->ktrig != FL(0.0)) - return ftsave(csound, &(p->p)); + return ftsave_(csound, &(p->p), 0); + return OK; +} + +static int ftsave_kS(CSOUND *csound, FTLOAD_K *p) +{ + if (*p->ktrig != FL(0.0)) + return ftsave_(csound, &(p->p), 1); return OK; } #define S(x) sizeof(x) static OENTRY localops[] = { - { "ftgen", S(FTGEN), TW|1, "i", "iiiTTm", (SUBR) ftgen, NULL, NULL }, - { "ftgentmp", S(FTGEN), TW|1, "i", "iiiiTm", (SUBR) ftgentmp, NULL, NULL }, - { "ftfree", S(FTFREE), TW|1, "", "ii", (SUBR) ftfree, NULL, NULL }, - { "ftsave", S(FTLOAD), TR|1, "", "Tim", (SUBR) ftsave, NULL, NULL }, - { "ftload", S(FTLOAD), TR|1, "", "Tim", (SUBR) ftload, NULL, NULL }, - { "ftsavek", S(FTLOAD_K), TW|3, "", "Tkim", (SUBR) ftsave_k_set, + { "ftgen", S(FTGEN), TW, 1, "i", "iiiiim", (SUBR) ftgen, NULL, NULL }, + { "ftgen.S", S(FTGEN), TW, 1, "i", "iiiSim", (SUBR) ftgen_S, NULL, NULL }, + { "ftgen.iS", S(FTGEN), TW, 1, "i", "iiiiSm", (SUBR) ftgen_iS, NULL, NULL }, + { "ftgen.SS", S(FTGEN), TW, 1, "i", "iiiSSm", (SUBR) ftgen_SS, NULL, NULL }, + { "ftgentmp.i", S(FTGEN), TW, 1, "i", "iiiiim", (SUBR) ftgentmp, NULL, NULL }, + { "ftgentmp.iS", S(FTGEN), TW, 1, "i", "iiiiSm", (SUBR) ftgentmp_S, NULL,NULL}, + { "ftfree", S(FTFREE), TW, 1, "", "ii", (SUBR) ftfree, NULL, NULL }, + { "ftsave", S(FTLOAD), TR, 1, "", "iim", (SUBR) ftsave, NULL, NULL }, + { "ftsave.S", S(FTLOAD), TR, 1, "", "Sim", (SUBR) ftsave_S, NULL, NULL }, + { "ftload", S(FTLOAD), TR, 1, "", "iim", (SUBR) ftload, NULL, NULL }, + { "ftload.S", S(FTLOAD), TR, 1, "", "Sim", (SUBR) ftload_S, NULL, NULL }, + { "ftsavek", S(FTLOAD_K), TW, 3, "", "ikim", (SUBR) ftsave_k_set, (SUBR) ftsave_k, NULL }, - { "ftloadk", S(FTLOAD_K), TW|3, "", "Tkim", (SUBR) ftsave_k_set, - (SUBR) ftload_k, NULL } + { "ftsavek.S", S(FTLOAD_K), TW, 3, "", "Skim", (SUBR) ftsave_k_set, + (SUBR) ftsave_kS, NULL }, + { "ftloadk", S(FTLOAD_K), TW, 3, "", "ikim", (SUBR) ftsave_k_set, + (SUBR) ftload_k, NULL }, + { "ftloadk.S", S(FTLOAD_K), TW, 3, "", "Skim", (SUBR) ftsave_k_set, + (SUBR) ftload_kS, NULL } }; int ftgen_init_(CSOUND *csound) @@ -511,4 +609,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/gab/gab.c csound-6.02~dfsg/Opcodes/gab/gab.c --- csound-5.17.11~dfsg/Opcodes/gab/gab.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/gab.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,3 +1,4 @@ + /* Copyright (C) 2002-2004 Gabriel Maldonado */ /* The gab library is free software; you can redistribute it */ @@ -27,11 +28,13 @@ /*Check csystem, exitnow */ /*Check other opcodes commented out in Oentry */ -#include "csdl.h" +#include "stdopcod.h" #include "gab.h" #include #include "interlocks.h" +#define FLT_MAX ((MYFLT)0x7fffffff) + static int krsnsetx(CSOUND *csound, KRESONX *p) /* Gabriel Maldonado, modifies for arb order */ { @@ -40,7 +43,7 @@ if ((p->loop = MYFLT2LRND(*p->ord)) < 1) p->loop = 4; /*default value*/ if (!*p->istor && (p->aux.auxp == NULL || - (int)(p->loop*2*sizeof(MYFLT)) > p->aux.size)) + (unsigned int)(p->loop*2*sizeof(MYFLT)) > p->aux.size)) csound->AuxAlloc(csound, (long)(p->loop*2*sizeof(MYFLT)), &p->aux); p->yt1 = (MYFLT*)p->aux.auxp; p->yt2 = (MYFLT*)p->aux.auxp + p->loop; if (scale && scale != 1 && scale != 2) { @@ -66,12 +69,12 @@ if (*p->kcf != p->prvcf) { p->prvcf = *p->kcf; - p->cosf = COS(*p->kcf * csound->tpidsr * csound->ksmps); + p->cosf = COS(*p->kcf * csound->tpidsr * CS_KSMPS); flag = 1; } if (*p->kbw != p->prvbw) { p->prvbw = *p->kbw; - p->c3 = EXP(*p->kbw * csound->mtpdsr * csound->ksmps); + p->c3 = EXP(*p->kbw * csound->mtpdsr * CS_KSMPS); flag = 1; } if (flag) { @@ -122,25 +125,29 @@ static int fastabw(CSOUND *csound, FASTAB *p) { - int nsmps = csound->ksmps, n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *tab = p->table; MYFLT *rslt = p->rslt, *ndx = p->xndx; + + if (UNLIKELY(early)) nsmps -= early; if (p->xmode) { MYFLT xbmul = p->xbmul; /* load once */ - for (n=0; n p->tablen || i<0)) { csound->Message(csound, "ndx: %f \n", ndx[n]); - return csound->PerfError(csound, Str("tabw off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tabw off end")); } tab[i] = rslt[n]; } } else { - for (n=0; n p->tablen || i<0)) { - return csound->PerfError(csound, Str("tabw off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tabw off end")); } tab[i] = rslt[n]; } @@ -156,7 +163,7 @@ else i = (int) *p->xndx; if (UNLIKELY(i > p->tablen || i<0)) { - return csound->PerfError(csound, Str("tab off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tab off end")); } *p->rslt = p->table[i]; return OK; @@ -170,7 +177,7 @@ else i = (int) *p->xndx; if (UNLIKELY(i > p->tablen || i<0)) { - return csound->PerfError(csound, Str("tabw off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tabw off end")); } p->table[i] = *p->rslt; return OK; @@ -179,17 +186,19 @@ static int fastabi(CSOUND *csound, FASTAB *p) { FUNC *ftp; - int i; + int32 i; if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL)) { return csound->InitError(csound, Str("tab_i: incorrect table number")); } if (*p->ixmode) - i = (int) (*p->xndx * ftp->flen); + i = (int32) (*p->xndx * ftp->flen); else - i = (int) *p->xndx; - if (UNLIKELY(i >= ftp->flen || i<0)) { - return csound->PerfError(csound, Str("tab_i off end: table number: %d\n"), (int) *p->xfn); + i = (int32) *p->xndx; + if (UNLIKELY(i >= (int32)ftp->flen || i<0)) { + return csound->PerfError(csound, p->h.insdshead, + Str("tab_i off end: table number: %d\n"), + (int) *p->xfn); } *p->rslt = ftp->ftable[i]; return OK; @@ -198,17 +207,17 @@ static int fastabiw(CSOUND *csound, FASTAB *p) { FUNC *ftp; - int i; + int32 i; /*ftp = csound->FTFind(p->xfn); */ if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { return csound->InitError(csound, Str("tabw_i: incorrect table number")); } if (*p->ixmode) - i = (int) (*p->xndx * ftp->flen); + i = (int32) (*p->xndx * ftp->flen); else - i = (int) *p->xndx; - if (UNLIKELY(i >= ftp->flen || i<0)) { - return csound->PerfError(csound, Str("tabw_i off end")); + i = (int32) *p->xndx; + if (UNLIKELY(i >= (int32)ftp->flen || i<0)) { + return csound->PerfError(csound, p->h.insdshead, Str("tabw_i off end")); } ftp->ftable[i] = *p->rslt; return OK; @@ -216,24 +225,31 @@ static int fastab(CSOUND *csound, FASTAB *p) { - int i = 0, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; MYFLT *tab = p->table; MYFLT *rslt = p->rslt, *ndx = p->xndx; + if (UNLIKELY(offset)) memset(rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rslt[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->xmode) { MYFLT xbmul = p->xbmul; - for (i=0; i p->tablen || n<0)) { - return csound->PerfError(csound, Str("tab off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tab off end")); } rslt[i] = tab[n]; } } else { - for (i=0; i p->tablen || n<0)) { - return csound->PerfError(csound, Str("tab off end")); + return csound->PerfError(csound, p->h.insdshead, Str("tab off end")); } rslt[i] = tab[n]; } @@ -245,7 +261,7 @@ { MYFLT *ft; STDOPCOD_GLOBALS *pp; - if (UNLIKELY(csound->GetTable(csound, &ft, MYFLT2LRND(*p->ifn)) < 0)) + if (UNLIKELY(csoundGetTable(csound, &ft, MYFLT2LRND(*p->ifn)) < 0)) return csound->InitError(csound, Str("tab_init: incorrect table number")); pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; pp->tb_ptrs[ndx] = ft; @@ -346,7 +362,9 @@ static int nlalp(CSOUND *csound, NLALP *p) { - int nsmps = csound->ksmps, n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rp; MYFLT *ip; double m0; @@ -362,11 +380,16 @@ knfact = (double)*p->knfact; tm0 = p->m0; tm1 = p->m1; - if (knfact == 0.0) { /* linear case */ + if (UNLIKELY(offset)) memset(rp, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rp[nsmps], '\0', early*sizeof(MYFLT)); + } + if (knfact == 0.0) { /* linear case */ if (klfact == 0.0) { /* degenerated linear case */ m0 = (double)ip[0] - tm1; - rp[0] = (MYFLT)(tm0); - for (n=1; niphs; p->inerr = 0; - if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { p->ftp = ftp; } else { @@ -425,7 +448,7 @@ return csound->InitError(csound, Str("adsynt2: wavetable not found!")); } - count = (int)*p->icnt; + count = (unsigned int)*p->icnt; if (UNLIKELY(count < 1)) count = 1; p->count = count; @@ -458,12 +481,12 @@ } if (p->lphs.auxp==NULL || - p->lphs.size < (int32)(sizeof(int32)*count)) + p->lphs.size < sizeof(int32)*count) csound->AuxAlloc(csound, sizeof(int32)*count, &p->lphs); lphs = (int32*)p->lphs.auxp; if (iphs > 1) { - int c; + unsigned int c; for (c=0; cRand31(&(csound->randSeed1)) - 1) @@ -471,13 +494,13 @@ } } else if (iphs >= 0) { - int c; + unsigned int c; for (c=0; cpamp.auxp==NULL || - p->pamp.size < (int32)(sizeof(MYFLT)*p->count)) + p->pamp.size < (uint32_t)(sizeof(MYFLT)*p->count)) csound->AuxAlloc(csound, sizeof(MYFLT)*p->count, &p->pamp); else /* AuxAlloc clear anyway */ memset(p->pamp.auxp, 0, sizeof(MYFLT)*p->count); @@ -495,7 +518,10 @@ MYFLT amp0, amp, cps0, cps, ampIncr, amp2; int32 phs, inc, lobits; int32 *lphs; - int c, n, nsmps= csound->ksmps, count; + int c, count; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->inerr)) { return csound->InitError(csound, Str("adsynt2: not initialised")); @@ -516,6 +542,10 @@ ar = p->sr; memset(ar, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } for (c=0; csicvt); phs = lphs[c]; - ampIncr = (amp - amp2) * csound->onedksmps; - for (n=0; n> lobits)) * amp2; phs += inc; phs &= PHMASK; @@ -543,27 +573,8 @@ return OK; /* compiler only */ } -/*-----zak opcodes */ -/* int zread(CSOUND *csound,ZKR *p) */ -/* { */ -/* *p->rslt = zkstart[(long) *p->ndx]; */ -/* return OK; */ -/* } */ - -/*void a_k_set(INDIFF *p) -{ - p->prev = FL(0.0); -}*/ - static int tabrec_set(CSOUND *csound,TABREC *p) { - /*FUNC *ftp; */ - /*if ((ftp = csound->FTFind(p->ifn)) == NULL) { */ - /* csound->InitError(csound, Str("tabrec: incorrect table number")); */ - /* return; */ - /*} */ - /*p->table = ftp->ftable; */ - /*p->tablen = ftp->flen; */ p->recording = 0; p->currtic = 0; p->ndx = 0; @@ -576,8 +587,9 @@ if (*p->ktrig_start) { if (*p->kfn != p->old_fn) { int flen; - if ((flen = csound->GetTable(csound, &(p->table), (int) *p->kfn)) < 0) - return csound->PerfError(csound, Str("Invalid ftable no. %f"), *p->kfn); + if ((flen = csoundGetTable(csound, &(p->table), (int) *p->kfn)) < 0) + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->kfn); p->tablen = (long) flen; *(p->table++) = *p->numtics; p->old_fn = *p->kfn; @@ -630,8 +642,9 @@ if (*p->ktrig) { if (*p->kfn != p->old_fn) { int flen; - if ((flen = csound->GetTable(csound, &(p->table), (int) *p->kfn)) < 0) - return csound->PerfError(csound, Str("Invalid ftable no. %f"), *p->kfn); + if ((flen = csoundGetTable(csound, &(p->table), (int) *p->kfn)) < 0) + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->kfn); p->tablen = (long) flen; p->currtic = 0; p->ndx = 0; @@ -700,32 +713,46 @@ static int partial_maximum_set(CSOUND *csound,P_MAXIMUM *p) { - p->max = 0; + int flag = (int) *p->imaxflag; + switch (flag) { + case 1: + p->max = 0; break; + case 2: + p->max = -FLT_MAX; break; + case 3: + p->max = FLT_MAX; break; + case 4: + p->max = 0; break; + } p->counter = 0; return OK; } static int partial_maximum(CSOUND *csound,P_MAXIMUM *p) { - int n, nsmps = csound->ksmps, flag = (int) *p->imaxflag; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int flag = (int) *p->imaxflag; MYFLT *a = p->asig; MYFLT max = p->max; + if (UNLIKELY(early)) nsmps -= early; switch(flag) { case 1: /* absolute maximum */ - for (n=0; n max) max = temp; } if (max > p->max) p->max = max; break; case 2: /* actual maximum */ - for (n=0; n max) max = a[n]; } if (max > p->max) p->max = max; break; case 3: /* actual minimum */ - for (n=0; nmax) p->max = max; @@ -733,23 +760,33 @@ case 4: { /* average */ MYFLT temp = FL(0.0); p->counter += nsmps; - for (n=0; nmax += temp; } break; default: - return csound->PerfError(csound, Str("max_k: invalid imaxflag value")); + return csound->PerfError(csound, p->h.insdshead, + Str("max_k: invalid imaxflag value")); } if (*p->ktrig) { - if (flag == 4) { + switch (flag) { + case 4: *p->kout = p->max / (MYFLT) p->counter; p->counter = 0; - } - else + p->max = FL(0.0); + break; + case 1: + *p->kout = p->max; + p->max = 0; break; + case 2: *p->kout = p->max; - p->max = FL(0.0); + p->max = -FLT_MAX; break; + case 3: + *p->kout = p->max; + p->max = FLT_MAX; break; + } } return OK; } @@ -793,86 +830,88 @@ #define S(x) sizeof(x) OENTRY gab_localops[] = { - {"resonxk", S(KRESONX), 3, "k", "kkkooo", + {"resonxk", S(KRESONX), 0, 3, "k", "kkkooo", (SUBR) krsnsetx, (SUBR) kresonx, NULL }, - { "tab_i",S(FASTAB), TR|1, "i", "iio", (SUBR) fastabi, NULL, NULL }, - { "tab",S(FASTAB), TR|7, "s", "xio", - (SUBR) fastab_set, (SUBR)fastabk, (SUBR) fastab }, - { "tabw_i",S(FASTAB), TW|1, "", "iiio", (SUBR) fastabiw, NULL, NULL }, - { "tabw",S(FASTAB), TW|7, "", "xxio", + { "tab_i",S(FASTAB), TR, 1, "i", "iio", (SUBR) fastabi, NULL, NULL }, + { "tab",S(FASTAB), TR, 5, "a", "xio", + (SUBR) fastab_set, (SUBR)NULL, (SUBR) fastab }, + { "tab.k",S(FASTAB), TR, 3, "k", "kio", + (SUBR) fastab_set, (SUBR)fastabk, NULL }, + { "tabw_i",S(FASTAB), TW, 1, "", "iiio", (SUBR) fastabiw, NULL, NULL }, + { "tabw",S(FASTAB), TW, 7, "", "xxio", (SUBR)fastab_set, (SUBR)fastabkw, (SUBR)fastabw }, - { "tb0_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab0_init}, - { "tb1_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab1_init}, - { "tb2_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab2_init}, - { "tb3_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab3_init}, - { "tb4_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab4_init}, - { "tb5_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab5_init}, - { "tb6_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab6_init}, - { "tb7_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab7_init}, - { "tb8_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab8_init}, - { "tb9_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab9_init}, - { "tb10_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab10_init}, - { "tb11_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab11_init}, - { "tb12_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab12_init}, - { "tb13_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab13_init}, - { "tb14_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab14_init}, - { "tb15_init", S(TB_INIT), TR|1, "", "i", (SUBR)tab15_init}, - { "tb0.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab0_k_tmp, NULL }, - { "tb1.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab1_k_tmp, NULL }, - { "tb2.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab2_k_tmp, NULL }, - { "tb3.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab3_k_tmp, NULL }, - { "tb4.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab4_k_tmp, NULL }, - { "tb5.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab5_k_tmp, NULL }, - { "tb6.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab6_k_tmp, NULL }, - { "tb7.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab7_k_tmp, NULL }, - { "tb8.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab8_k_tmp, NULL }, - { "tb9.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab9_k_tmp, NULL }, - { "tb10.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab10_k_tmp, NULL }, - { "tb11.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab11_k_tmp, NULL }, - { "tb12.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab12_k_tmp, NULL }, - { "tb13.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab13_k_tmp, NULL }, - { "tb14.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab14_k_tmp, NULL }, - { "tb15.k", S(FASTB), 2, "k", "k", NULL, (SUBR) tab15_k_tmp, NULL }, + { "tb0_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab0_init}, + { "tb1_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab1_init}, + { "tb2_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab2_init}, + { "tb3_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab3_init}, + { "tb4_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab4_init}, + { "tb5_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab5_init}, + { "tb6_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab6_init}, + { "tb7_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab7_init}, + { "tb8_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab8_init}, + { "tb9_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab9_init}, + { "tb10_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab10_init}, + { "tb11_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab11_init}, + { "tb12_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab12_init}, + { "tb13_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab13_init}, + { "tb14_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab14_init}, + { "tb15_init", S(TB_INIT), TR, 1, "", "i", (SUBR)tab15_init}, + { "tb0.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab0_k_tmp, NULL }, + { "tb1.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab1_k_tmp, NULL }, + { "tb2.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab2_k_tmp, NULL }, + { "tb3.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab3_k_tmp, NULL }, + { "tb4.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab4_k_tmp, NULL }, + { "tb5.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab5_k_tmp, NULL }, + { "tb6.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab6_k_tmp, NULL }, + { "tb7.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab7_k_tmp, NULL }, + { "tb8.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab8_k_tmp, NULL }, + { "tb9.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab9_k_tmp, NULL }, + { "tb10.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab10_k_tmp, NULL }, + { "tb11.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab11_k_tmp, NULL }, + { "tb12.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab12_k_tmp, NULL }, + { "tb13.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab13_k_tmp, NULL }, + { "tb14.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab14_k_tmp, NULL }, + { "tb15.k", S(FASTB), 0, 2, "k", "k", NULL, (SUBR) tab15_k_tmp, NULL }, /* tbx_t (t-rate version removed here) */ - { "tb0.i", S(FASTB), 1, "i", "i", (SUBR) tab0_i_tmp }, - { "tb1.i", S(FASTB), 1, "i", "i", (SUBR) tab1_i_tmp }, - { "tb2.i", S(FASTB), 1, "i", "i", (SUBR) tab2_i_tmp }, - { "tb3.i", S(FASTB), 1, "i", "i", (SUBR) tab3_i_tmp }, - { "tb4.i", S(FASTB), 1, "i", "i", (SUBR) tab4_i_tmp }, - { "tb5.i", S(FASTB), 1, "i", "i", (SUBR) tab5_i_tmp }, - { "tb6.i", S(FASTB), 1, "i", "i", (SUBR) tab6_i_tmp }, - { "tb7.i", S(FASTB), 1, "i", "i", (SUBR) tab7_i_tmp }, - { "tb8.i", S(FASTB), 1, "i", "i", (SUBR) tab8_i_tmp }, - { "tb9.i", S(FASTB), 1, "i", "i", (SUBR) tab9_i_tmp }, - { "tb10.i", S(FASTB), 1, "i", "i", (SUBR) tab10_i_tmp }, - { "tb11.i", S(FASTB), 1, "i", "i", (SUBR) tab11_i_tmp }, - { "tb12.i", S(FASTB), 1, "i", "i", (SUBR) tab12_i_tmp }, - { "tb13.i", S(FASTB), 1, "i", "i", (SUBR) tab13_i_tmp }, - { "tb14.i", S(FASTB), 1, "i", "i", (SUBR) tab14_i_tmp }, - { "tb15.i", S(FASTB), 1, "i", "i", (SUBR) tab15_i_tmp }, - { "nlalp", S(NLALP), 5, "a", "akkoo", + { "tb0.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab0_i_tmp }, + { "tb1.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab1_i_tmp }, + { "tb2.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab2_i_tmp }, + { "tb3.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab3_i_tmp }, + { "tb4.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab4_i_tmp }, + { "tb5.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab5_i_tmp }, + { "tb6.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab6_i_tmp }, + { "tb7.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab7_i_tmp }, + { "tb8.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab8_i_tmp }, + { "tb9.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab9_i_tmp }, + { "tb10.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab10_i_tmp }, + { "tb11.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab11_i_tmp }, + { "tb12.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab12_i_tmp }, + { "tb13.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab13_i_tmp }, + { "tb14.i", S(FASTB), 0, 1, "i", "i", (SUBR) tab14_i_tmp }, + { "tb15.i", S(FASTB),0, 1, "i", "i", (SUBR) tab15_i_tmp }, + { "nlalp", S(NLALP), 0, 5, "a", "akkoo", (SUBR) nlalp_set, NULL, (SUBR) nlalp }, - { "adsynt2",S(ADSYNT2),TR|5, "a", "kkiiiio", + { "adsynt2",S(ADSYNT2),TR, 5, "a", "kkiiiio", (SUBR) adsynt2_set, NULL, (SUBR)adsynt2 }, - { "exitnow",S(EXITNOW), 1, "", "", (SUBR) exitnow, NULL, NULL }, -/* { "zr_i", S(ZKR), 1, "i", "i", (SUBR)zread, NULL, NULL}, */ -/* { "zr_k", S(ZKR), 2, "k", "k", NULL, (SUBR)zread, NULL}, */ -/* { "zr_a", S(ZAR), 5, "a", "a", (SUBR)zaset, NULL, (SUBR)zar}, */ -/* { "k_i", S(ASSIGN), 1, "k", "i", (SUBR)assign}, */ -/* { "k_t", S(ASSIGN), 2, "k", "t", NULL, (SUBR)assign}, */ -/* { "a_k", S(INDIFF), 5, "a", "k", (SUBR)a_k_set,NULL, (SUBR)interp }, */ - { "tabrec", S(TABREC), 3, "", "kkkkz", + { "exitnow",S(EXITNOW), 0, 1, "", "", (SUBR) exitnow, NULL, NULL }, +/* { "zr_i", S(ZKR), 0, 1, "i", "i", (SUBR)zread, NULL, NULL}, */ +/* { "zr_k", S(ZKR), 0, 2, "k", "k", NULL, (SUBR)zread, NULL}, */ +/* { "zr_a", S(ZAR), 0, 5, "a", "a", (SUBR)zaset, NULL, (SUBR)zar}, */ +/* { "k_i", S(ASSIGN), 0, 1, "k", "i", (SUBR)assign}, */ +/* { "k_t", S(ASSIGN), 0, 2, "k", "t", NULL, (SUBR)assign}, */ +/* { "a_k", S(INDIFF), 0, 5, "a", "k", (SUBR)a_k_set,NULL, (SUBR)interp }, */ + { "tabrec", S(TABREC), 0, 3, "", "kkkkz", (SUBR) tabrec_set, (SUBR) tabrec_k, NULL }, - { "tabplay", S(TABPLAY), TR|3, "", "kkkz", + { "tabplay", S(TABPLAY), TR, 3, "", "kkkz", (SUBR) tabplay_set, (SUBR) tabplay_k, NULL }, - { "changed", S(ISCHANGED), 3, "k", "z", + { "changed", S(ISCHANGED), 0, 3, "k", "z", (SUBR) isChanged_set, (SUBR)isChanged, NULL }, - /*{ "ftlen_k",S(EVAL), 2, "k", "k", NULL, (SUBR)ftlen }, */ - { "max_k", S(P_MAXIMUM), 5, "k", "aki", + /*{ "ftlen_k",S(EVAL), 0, 2, "k", "k", NULL, (SUBR)ftlen }, */ + { "max_k", S(P_MAXIMUM), 0, 5, "k", "aki", (SUBR) partial_maximum_set, (SUBR) NULL, (SUBR) partial_maximum }, -/*{ "maxk", S(P_MAXIMUM), 5, "k", "aki", */ +/*{ "maxk", S(P_MAXIMUM), 0, 5, "k", "aki", */ /* (SUBR) partial_maximum_set, (SUBR) NULL, (SUBR) partial_maximum }, */ - { "mandel",S(MANDEL), 3, "kk", "kkkk", + { "mandel",S(MANDEL), 0, 3, "kk", "kkkk", (SUBR) mandel_set, (SUBR) mandel, NULL } }; diff -Nru csound-5.17.11~dfsg/Opcodes/gab/hvs.c csound-6.02~dfsg/Opcodes/gab/hvs.c --- csound-5.17.11~dfsg/Opcodes/gab/hvs.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/hvs.c 2014-01-07 16:53:48.000000000 +0000 @@ -60,11 +60,11 @@ { FUNC *ftp; - if ((ftp = csound->FTFind(csound, p->iOutTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iOutTab)) != NULL) p->outTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iPositionsTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iPositionsTab)) != NULL) p->posTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iSnapTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iSnapTab)) != NULL) p->snapTable = ftp->ftable; if (*p->inumPointsX < 2 ) return csound->InitError(csound, Str("hvs1: a line segment must be " @@ -73,7 +73,7 @@ if (*p->iConfigTab == 0) p->iconfFlag = 0; else { - if ((ftp = csound->FTFind(csound, p->iConfigTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iConfigTab)) != NULL) p->outTable = ftp->ftable; p->iconfFlag = 1; } @@ -142,11 +142,11 @@ { FUNC *ftp; - if ((ftp = csound->FTFind(csound, p->iOutTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iOutTab)) != NULL) p->outTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iPositionsTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iPositionsTab)) != NULL) p->posTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iSnapTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iSnapTab)) != NULL) p->snapTable = ftp->ftable; if (*p->inumlinesX < 2 || *p->inumlinesY < 2) return csound->InitError(csound, Str("hvs2: a square area must be " @@ -155,7 +155,7 @@ if (*p->iConfigTab == 0) p->iconfFlag = 0; else { - if ((ftp = csound->FTFind(csound, p->iConfigTab)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, p->iConfigTab)) != NULL) { p->outTable = ftp->ftable; } p->iconfFlag = 1; @@ -238,11 +238,11 @@ { FUNC *ftp; - if ((ftp = csound->FTFind(csound, p->iOutTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iOutTab)) != NULL) p->outTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iPositionsTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iPositionsTab)) != NULL) p->posTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->iSnapTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iSnapTab)) != NULL) p->snapTable = ftp->ftable; if (*p->inumlinesX < 2 || *p->inumlinesY < 2) return csound->InitError(csound, Str("hvs3: a square area must be " @@ -252,7 +252,7 @@ if (*p->iConfigTab == 0) p->iconfFlag = 0; else { - if ((ftp = csound->FTFind(csound, p->iConfigTab)) != NULL) + if ((ftp = csound->FTnp2Find(csound, p->iConfigTab)) != NULL) p->outTable = ftp->ftable; p->iconfFlag = 1; } @@ -393,7 +393,7 @@ p->vector = ftp->ftable; p->elements = (int) *p->ielements; } - if ( p->elements > ftp->flen ) + if ( p->elements > (int)ftp->flen ) return csound->InitError(csound, Str("vphaseseg: invalid num. of elements")); /* vector = p->vector; */ @@ -483,13 +483,13 @@ #define S(x) sizeof(x) OENTRY hvs_localops[] = { - { "hvs1", S(HVS1), TB|3, "", "kiiiiio", + { "hvs1", S(HVS1), TB, 3, "", "kiiiiio", (SUBR)hvs1_set, (SUBR)hvs1, (SUBR)NULL }, - { "hvs2", S(HVS2), TB|3, "", "kkiiiiiio", + { "hvs2", S(HVS2), TB, 3, "", "kkiiiiiio", (SUBR)hvs2_set, (SUBR)hvs2, (SUBR)NULL }, - { "hvs3", S(HVS3), TB|3, "", "kkkiiiiiiio", + { "hvs3", S(HVS3), TB, 3, "", "kkkiiiiiiio", (SUBR)hvs3_set, (SUBR)hvs3, (SUBR)NULL }, - { "vphaseseg", S(VPSEG), TB|3, "", "kiim", + { "vphaseseg", S(VPSEG), TB, 3, "", "kiim", (SUBR)vphaseseg_set, (SUBR)vphaseseg } }; diff -Nru csound-5.17.11~dfsg/Opcodes/gab/newgabopc.c csound-6.02~dfsg/Opcodes/gab/newgabopc.c --- csound-5.17.11~dfsg/Opcodes/gab/newgabopc.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/newgabopc.c 2014-01-07 16:53:48.000000000 +0000 @@ -36,7 +36,7 @@ static int mtable1_set(CSOUND *csound, MTABLE1 *p) /* mtab by G.Maldonado */ { FUNC *ftp; - if ((ftp = csound->FTFind(csound, p->xfn)) == NULL) + if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) return csound->InitError(csound, Str("vtable1: incorrect table number")); p->ftable = ftp->ftable; p->nargs = p->INOCOUNT-1; @@ -52,7 +52,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTFindP(csound, p->xfn) ) == NULL) - return csound->PerfError(csound, Str("vtable1: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtable1: incorrect table number")); p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; } @@ -92,9 +93,10 @@ unquote(name, csound->currevent->strarg); evt.strarg = name; evt.p[1] = SSTRCOD; + evt.scnt = 1; } else { - evt.strarg = NULL; + evt.strarg = NULL; evt.scnt = 0; evt.p[1] = *args[1]; } evt.opcod = (char) *args[0]; @@ -106,7 +108,9 @@ if(starttime < FL(0.0)) { starttime = FL(0.0); } - starttime += (double) csound->global_kcounter / (double)csound->global_ekr; + starttime += (double) csound->GetKcounter(csound) / + (double) csound->GetKr(csound); + /*starttime += (double) csound->global_kcounter / (double)csound->global_ekr;*/ /* Copy all arguments to the new event */ for (i = 0; i < numargs; i++) evt.p[i] = *args[i]; @@ -140,7 +144,7 @@ O->RTevents = 1; /* Make sure kperf() looks for RT events */ /* O->ksensing = 1; */ /* O->OrcEvts = 1; */ /* - of the appropriate type */ - if (csound->kcounter > 0 && *p->trigger != FL(0.0) && p->h.insdshead->p3 == 0) + if (CS_KCNT > 0 && *p->trigger != FL(0.0) && p->h.insdshead->p3 == 0) schedk(csound,p); return OK; } @@ -181,7 +185,7 @@ p->argums[0]=&p->args2[0]; - if (csound->kcounter > 0 && *p->trigger != 0 && p->h.insdshead->p3 == 0) { + if (CS_KCNT > 0 && *p->trigger != 0 && p->h.insdshead->p3 == 0) { if (*p->argums[3] >= 0) *p->argums[3] = -1; /* start a held note */ *p->argums[1] += p->frac; Sched(csound, p->argums, p->nargs); @@ -221,7 +225,7 @@ /* -------------------------------------------------------------------- */ /* These opocdes were not implemented because the functionality of */ -/* CopyTabElements has already been included in vcopy and vcopy_i */ +/* CopyTabElements has already been included in vcopy and vcopy_i */ typedef struct { /* GAB 11/Jan/2001 */ OPDS h; @@ -236,9 +240,10 @@ { FUNC *ftp; int nelems = (int) *p->inumElems; - if ((ftp = csound->FTFind(csound, p->idestTab)) == NULL) + if ((ftp = csound->FTnp2Find(csound, p->idestTab)) == NULL) return csound->InitError(csound, - Str("copyTabElems: incorrect destination table number")); + Str("copyTabElems: incorrect destination " + "table number")); p->dLen = ftp->flen; if (nelems > p->dLen) @@ -247,7 +252,7 @@ "or number of elements to copy too big")); p->dTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->isourceTab)) == NULL) + if ((ftp = csound->FTnp2Find(csound, p->isourceTab)) == NULL) return csound->InitError(csound, Str("copyTabElems: incorrect source table number")); @@ -270,9 +275,11 @@ int j, sNdx = (int) *p->ksourceIndex * nelems, dNdx = (int) *p->kdestIndex * nelems; if (sNdx + nelems > p->sLen) - return csound->PerfError(csound, Str("copyTabElems: source table too short")); + return + csound->PerfError(csound, p->h.insdshead, + Str("copyTabElems: source table too short")); if (dNdx + nelems > p->dLen) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("copyTabElems: destination table too short")); for (j = 0; j< nelems; j++) @@ -291,7 +298,7 @@ FUNC *ftp; int nelems = (int) *p->inumElems, dLen, sLen; MYFLT *sTable, *dTable; - if ((ftp = csound->FTFind(csound, p->idestTab)) == NULL) + if ((ftp = csound->FTnp2Find(csound, p->idestTab)) == NULL) return csound->InitError(csound, Str("copyTabElems: incorrect destination " "table number")); @@ -301,7 +308,7 @@ Str("copyTabElems: destination table too short " "or number of elements to copy too big")); dTable = ftp->ftable; - if ((ftp = csound->FTFind(csound, p->isourceTab)) == NULL) + if ((ftp = csound->FTnp2Find(csound, p->isourceTab)) == NULL) return csound->InitError(csound, Str("copyTabElems: incorrect source table number")); sLen = ftp->flen; @@ -315,9 +322,11 @@ int j, sNdx = (int) *p->isourceIndex * nelems, dNdx = (int) *p->idestIndex * nelems; if (sNdx + nelems > sLen) - return csound->PerfError(csound, Str("copyTabElems: source table too short")); + return + csound->PerfError(csound, p->h.insdshead, + Str("copyTabElems: source table too short")); if (dNdx + nelems > dLen) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("copyTabElems: destination table too short")); for (j = 0; j< nelems; j++) { dTable[dNdx+j] = sTable[sNdx+j]; @@ -345,91 +354,41 @@ /*p->numChans = (PortaudioNumOfInPorts == -1) ? nchnls : PortaudioNumOfInPorts; */ if (!csound->oparms->sfread) return csound->InitError(csound, Str("inrg: audio input is not enabled")); - p->numChans = csound->nchnls; + p->numChans = csound->GetNchnls(csound); return OK; } static int inRange(CSOUND *csound, INRANGE *p) { - int j, nsmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t j, nsmps = CS_KSMPS; + int i; MYFLT *ara[VARGMAX]; int startChan = (int) *p->kstartChan -1; MYFLT *sp = csound->spin + startChan; int narg = p->narg, numchans = p->numChans; if (startChan < 0) - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("inrg: channel number cannot be < 1 " "(1 is the first channel)")); - for (j = 0; j < narg; j++) - ara[j] = p->argums[j]; - - nsmps = csound->ksmps; - do { - int i; + if (UNLIKELY(early)) nsmps -= early; + for (i = 0; i < narg; i++) { + ara[i] = p->argums[i]; + if (UNLIKELY(offset)) memset(ara[i], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&ara[i][nsmps], '\0', early*sizeof(MYFLT)); + } + for (j=offset; jnarg = p->INOCOUNT-1; - return OK; -} - -static int outRange(CSOUND *csound, OUTRANGE *p) -{ - int j, n, nsmps; - int ksmps = csound->ksmps, nchnls = csound->nchnls; - MYFLT *ara[VARGMAX]; - int startChan = (int) *p->kstartChan -1; - MYFLT *sp = csound->spout + startChan; - int narg = p->narg; - if (startChan < 0) - return csound->PerfError(csound, - Str("outrg: channel number cannot be < 1 " - "(1 is the first channel)")); - - for (j = 0; j < narg; j++) - ara[j] = p->argums[j]; - - nsmps = ksmps; - if (!csound->spoutactive) { - memset(sp, 0, ksmps * nchnls * sizeof(MYFLT)); - for (n=0; nspoutactive = 1; - } - else { - for (n=0; nMessage(csound, Str("lposc: no sample rate stored in function;" " assuming=sr\n")); - p->fsr=csound->esr; + p->fsr=CS_ESR; } p->ftp = ftp; p->tablen = ftp->flen; @@ -460,78 +419,16 @@ return OK; } -#if 0 - -/* These opcodes left out while GEN22 is implemented */ -static int lposcint(CSOUND *csound, LPOSC *p) -{ - double *phs= &p->phs; - double si= *p->freq * (p->fsr/ csound->esr); - - MYFLT *out = p->out; - short *ft = (short *) p->ftp->ftable, *curr_samp; - MYFLT fract; - long n = csound->ksmps; - long loop, end, looplength; /* = p->looplength ; */ - - if ((loop = (long) *p->kloop) < 0) loop=0;// gab - else if (loop > p->tablen-3) loop = p->tablen-3; - if ((end = (long) *p->kend) > p->tablen-1 ) end = p->tablen - 1; - else if (end <= 2) end = 2; - if (end < loop+2) end = loop + 2; - - looplength = end - loop; - - do { - curr_samp= ft + (long)*phs; - fract= (MYFLT)(*phs - (long)*phs); - *out++ = *p->amp * (*curr_samp +(*(curr_samp+1)-*curr_samp)*fract); - *phs += si; - while (*phs >= end) *phs -= looplength; - while (*phs < loop) *phs += looplength; - } while (--n); - return OK; -} - -static int lposcinta(CSOUND *csound, LPOSC *p) -{ - - double *phs= &p->phs; - double si= *p->freq * (p->fsr/csound->esr); - MYFLT *out = p->out, *amp=p->amp; - short *ft = (short *) p->ftp->ftable, *curr_samp; - MYFLT fract; - long n, nsmps = csound->ksmps; - long loop, end, looplength; /* = p->looplength ; */ - - if ((loop = (long) *p->kloop) < 0) loop=0;// gab - else if (loop > p->tablen-3) loop = p->tablen-3; - if ((end = (long) *p->kend) > p->tablen-1 ) end = p->tablen - 1; - else if (end <= 2) end = 2; - if (end < loop+2) end = loop + 2; - - looplength = end - loop; - for (n=0; n= end) *phs -= looplength; - while (*phs < loop) *phs += looplength; - } - return OK; -} -#endif - - static int lposca(CSOUND *csound, LPOSC *p) { double *phs= &p->phs; - double si= *p->freq * (p->fsr/csound->esr); + double si= *p->freq * (p->fsr/CS_ESR); MYFLT *out = p->out, *amp=p->amp; MYFLT *ft = p->ftp->ftable, *curr_samp; MYFLT fract; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 loop, end, looplength /* = p->looplength */ ; if ((loop = (long) *p->kloop) < 0) loop=0;/* gab */ @@ -540,7 +437,12 @@ else if (end <= 2) end = 2; if (end < loop+2) end = loop + 2; looplength = end - loop; - for (n=0; nFTnp2Find(csound, p->ift)) == NULL) - return csound->InitError(csound, Str("invalid function")); - if (!(fsr = ftp->gen01args.sample_rate)){ - csound->Message(csound, - Str("lposcil: no sample rate stored in function assuming=sr\n")); - p->fsr=csound->esr; - } - p->fsrUPsr = fsr/csound->esr; - p->ft = (short *) ftp->ftable; - p->tablen = ftp->flen/2; - /* changed from - p->phs = *p->iphs * p->tablen; */ - if ((loop = (long) *p->kloop) < 0) loop=0;// gab - else if (loop > p->tablen-3) loop = p->tablen-3; - if ((end = (long) *p->kend) > p->tablen-1 ) end = p->tablen - 1; - else if (end <= 2) end = 2; - if (end < loop+2) end = loop + 2; - looplength = end - loop; - - if (*p->iphs >= 0) - p->phs_int = (long) (p->phs = *p->iphs); - - while (p->phs >= end) - p->phs_int = (long) (p->phs -= looplength); - return OK; -} - -static int lposcinta_stereo(CSOUND *csound, LPOSCINT_ST *p) // stereo lposcinta -{ - double *phs= &p->phs, si= *p->freq * p->fsrUPsr; - MYFLT *out1 = p->out1, *out2 = p->out2, *amp=p->amp; - short *ft = p->ft; - long n = csound->ksmps; - long loop, end, looplength; - if ((loop = (long) *p->kloop) < 0) loop=0;// gab - else if (loop > p->tablen-3) loop = p->tablen-3; - if ((end = (long) *p->kend) > p->tablen-1 ) end = p->tablen - 1; - else if (end <= 2) end = 2; - if (end < loop+2) end = loop + 2; - looplength = end - loop; - do { - double fract; - short *curr_samp1 = ft + (long) *phs * 2; - short *curr_samp2 = curr_samp1 +1; - fract= *phs - (long) *phs; - *out1++ = *amp * (MYFLT) (*curr_samp1 +(*(curr_samp1+2)-*curr_samp1)*fract); - *out2++ = *amp++ * (MYFLT) (*curr_samp2 +(*(curr_samp2+2)-*curr_samp2)*fract); - *phs += si; - while (*phs >= end) *phs -= looplength; - while (*phs < loop) *phs += looplength; - } while (--n); - return OK; -} - -static int lposcinta_stereo_no_trasp(CSOUND *csound, LPOSCINT_ST *p) - /* trasposition is allowed only */ -{ /* in integer values (twice, three times etc.) */ - /* so it is faster */ - long *phs = &p->phs_int, si = (long) *p->freq; - MYFLT *out1 = p->out1, *out2 = p->out2, *amp=p->amp; - short *ft = p->ft; - long n = csound->ksmps; - long loop, end, looplength /* = p->looplength ; */ - if ((loop = (long) *p->kloop) < 0) loop=0;/* gab */ - else if (loop > p->tablen-3) loop = p->tablen-3; - if ((end = (long) *p->kend) > p->tablen-1 ) end = p->tablen - 1; - else if (end <= 2) end = 2; - if (end < loop+2) end = loop + 2; - looplength = end - loop; - - do { - short *curr_samp1 = ft + *phs * 2; - *out1++ = *amp * (MYFLT) *curr_samp1 ; - *out2++ = *amp++ * (MYFLT) *(curr_samp1+1) ; - *phs += si; - while (*phs >= end) *phs -= looplength; - while (*phs < loop) *phs += looplength; - } while (--n); - return OK; -} -#endif - -/* -------------------------------------------------------------------- */ - typedef struct { OPDS h; MYFLT *out1, *out2, *amp, *freq, *kloop, *kend, *ift, *iphs; @@ -673,9 +474,9 @@ if (!(fsr = ftp->gen01args.sample_rate)) { csound->Message(csound, Str("lposcil: no sample rate stored in function;" " assuming=sr\n")); - p->fsr=csound->esr; + p->fsr=CS_ESR; } - p->fsrUPsr = fsr/csound->esr; + p->fsrUPsr = fsr/CS_ESR; p->ft = ftp->ftable; p->tablen = ftp->flen/2; /* changed from @@ -700,7 +501,9 @@ double *phs= &p->phs, si= *p->freq * p->fsrUPsr; MYFLT *out1 = p->out1, *out2 = p->out2, *amp=p->amp; MYFLT *ft = p->ft; - int32 n = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 loop, end, looplength /* = p->looplength */ ; if ((loop = (long) *p->kloop) < 0) loop=0;/* gab */ else if (loop > p->tablen-3) loop = p->tablen-3; @@ -708,17 +511,26 @@ else if (end <= 2) end = 2; if (end < loop+2) end = loop + 2; looplength = end - loop; - do { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; n= end) *phs -= looplength; while (*phs < loop) *phs += looplength; - } while (--n); + } return OK; } @@ -728,7 +540,9 @@ long *phs = &p->phs_int, si = (long) *p->freq; MYFLT *out1 = p->out1, *out2 = p->out2, *amp=p->amp; MYFLT *ft = p->ft; - long n = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; long loop, end, looplength /* = p->looplength */ ; if ((loop = (long) *p->kloop) < 0) loop=0;/* gab */ else if (loop > p->tablen-3) loop = p->tablen-3; @@ -737,21 +551,29 @@ if (end < loop+2) end = loop + 2; looplength = end - loop; - do { + if (UNLIKELY(offset)) { + memset(out1, '\0', offset*sizeof(MYFLT)); + memset(out2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&out2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; n= end) *phs -= looplength; while (*phs < loop) *phs += looplength; - } while (--n); + } return OK; } /* -------------------------------------------------------------------- */ -/* #undef oneUp31Bit \/\* to avoid warnings */ #include "vectorial.h" typedef struct { /* gab d5*/ @@ -788,12 +610,12 @@ MYFLT range = *p->kband_max - *p->kband_min; if (range != FL(0.0)) *p->rmod = (*p->kfreq_max - *p->kfreq_min) / (*p->kband_max - *p->kband_min); - else + else *p->rmod = FL(0.0); *p->rcar = (*p->kfreq_max - (*p->kband_max * *p->rmod)); - if (*p->rmod <= FL(0.0)) *p->rmod = (MYFLT) fabs (*p->rmod); - if (*p->rcar <= FL(0.0)) *p->rcar = (MYFLT) fabs (*p->rcar); + if (*p->rmod <= FL(0.0)) *p->rmod = FABS (*p->rmod); + if (*p->rcar <= FL(0.0)) *p->rcar = FABS (*p->rcar); return OK; } #endif @@ -804,46 +626,38 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "vtable1k", S(MTABLE1), TR|3, "", "kz", (SUBR)mtable1_set, (SUBR)mtable1_k, (SUBR) NULL }, - /* { "schedk", S(SCHEDK), 3, "", "kkz", (SUBR)schedk_i, (SUBR) schedk, (SUBR) NULL }, */ - /* { "schedInTime", S(SCHEDINTIME), 3, "", "kz", (SUBR)schedInTime_set, (SUBR)schedInTime , (SUBR) NULL }, */ - /* { "copyTabElems", S(COPYTABELEMS), 3, "", "kikiki", (SUBR)copyTabElems_set, (SUBR)copyTabElems, (SUBR)NULL }, */ - /* { "copyTabElemsi", S(COPYTABELEMS_I), 1, "", "iiiii", (SUBR)copyTabElemsi, (SUBR)NULL, (SUBR)NULL }, */ - /* { "Trandom", S(TRANGERAND), 2, "k", "kkk", NULL, (SUBR)trRangeRand }, */ - { "trandom", S(TRANGERAND), 2, "k", "kkk", NULL, (SUBR)trRangeRand }, - /* { "lposcinta", S(LPOSC), 5, "a", "akkkio", (SUBR)lposc_set, NULL, (SUBR)lposcinta}, */ - /* { "lposcintsa", S(LPOSCINT_ST), 5, "aa","akkkio", (SUBR)lposcint_stereo_set,NULL, (SUBR)lposcinta_stereo}, */ - /* { "lposcintsa2", S(LPOSCINT_ST), 5, "aa","akkkio", (SUBR)lposcint_stereo_set,NULL, (SUBR)lposcinta_stereo_no_trasp}, */ - { "lposcila", S(LPOSC), TR|5, "a", "akkkio", (SUBR)lposc_set, NULL, (SUBR)lposca}, - { "lposcilsa", S(LPOSC_ST), TR|5, "aa","akkkio", (SUBR)lposc_stereo_set, NULL, (SUBR)lposca_stereo}, - { "lposcilsa2", S(LPOSC_ST), TR|5, "aa","akkkio", (SUBR)lposc_stereo_set, NULL, (SUBR)lposca_stereo_no_trasp}, - /* { "dashow.i", S(DSH), 1, "ii","iiii", (SUBR)dashow }, */ - /* { "dashow.k", S(DSH), 2, "kk","kkkk", NULL, (SUBR)dashow }, */ - { "inrg", S(INRANGE), 5, "", "ky", (SUBR)inRange_i, (SUBR)NULL, (SUBR)inRange }, - { "outrg", S(OUTRANGE), 5, "", "ky", (SUBR)outRange_i, (SUBR)NULL, (SUBR)outRange} -}; + { "vtable1k", S(MTABLE1), TR, 3, "", "kz", + (SUBR)mtable1_set, (SUBR)mtable1_k, (SUBR) NULL }, + /* { "schedk", S(SCHEDK), 0, 3, "", "kkz", + (SUBR)schedk_i, (SUBR) schedk, (SUBR) NULL }, */ + /* { "schedInTime", S(SCHEDINTIME), 0, 3, "", "kz", + (SUBR)schedInTime_set, (SUBR)schedInTime , (SUBR) NULL }, */ + /* { "copyTabElems", S(COPYTABELEMS),0, 3, "", "kikiki", + (SUBR)copyTabElems_set, (SUBR)copyTabElems, (SUBR)NULL }, */ + /* { "copyTabElemsi", S(COPYTABELEMS_I), 0, 1, "", "iiiii", + (SUBR)copyTabElemsi, (SUBR)NULL, (SUBR)NULL }, */ + /* { "Trandom", S(TRANGERAND), 0, 2, "k", "kkk", + NULL, (SUBR)trRangeRand }, */ + { "trandom", S(TRANGERAND), 0, 2, "k", "kkk", + NULL, (SUBR)trRangeRand }, + /* { "lposcinta", S(LPOSC), 0, 5, "a", "akkkio", + (SUBR)lposc_set, NULL, (SUBR)lposcinta}, */ + /* { "lposcintsa", S(LPOSCINT_ST), 0, 5, "aa","akkkio", + (SUBR)lposcint_stereo_set,NULL, (SUBR)lposcinta_stereo}, */ + /* { "lposcintsa2", S(LPOSCINT_ST), 0, 5, "aa","akkkio", + (SUBR)lposcint_stereo_set,NULL, (SUBR)lposcinta_stereo_no_trasp}, */ + { "lposcila", S(LPOSC), TR, 5, "a", "akkkio", + (SUBR)lposc_set, NULL, (SUBR)lposca}, + { "lposcilsa", S(LPOSC_ST), TR, 5, "aa","akkkio", + (SUBR)lposc_stereo_set, NULL, (SUBR)lposca_stereo}, + { "lposcilsa2", S(LPOSC_ST), TR, 5, "aa","akkkio", + (SUBR)lposc_stereo_set, NULL, (SUBR)lposca_stereo_no_trasp}, + /* { "dashow.i", S(DSH), 0,1, "ii","iiii", (SUBR)dashow }, */ + /* { "dashow.k", S(DSH), 0,2, "kk","kkkk", NULL, (SUBR)dashow }, */ + { "inrg", S(INRANGE), 0,5, "", "ky", (SUBR)inRange_i, (SUBR)NULL, (SUBR)inRange } - -typedef struct NEWGABOPC_GLOBALS_ { - int butta; - -} NEWGABOPC_GLOBALS; - -/* -PUBLIC int csoundModuleInfo(void) -{ - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); -} - - -PUBLIC int csoundModuleCreate(CSOUND *csound) -{ - (void)csound; - return 0; -} -*/ - +}; int newgabopc_init_(CSOUND *csound) { return csound->AppendOpcodes(csound, &(localops[0]), diff -Nru csound-5.17.11~dfsg/Opcodes/gab/radiobaton.c csound-6.02~dfsg/Opcodes/gab/radiobaton.c --- csound-5.17.11~dfsg/Opcodes/gab/radiobaton.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/radiobaton.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,341 +0,0 @@ -/* Copyright (C) 2007 Gabriel Maldonado - - Csound is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* #include "csdl.h" */ - -/* -extern unsigned long MIDIINbufIndex; -extern MIDIMESSAGE MIDIINbuffer2[]; -*/ - -#include "csoundCore.h" /* instead of "csd.h" in order to access - csound->midiGlobals */ - -/* These opcodes have not been implemented because csound->midiGlobals - is not there yet. */ - -PUBLIC int Sched(CSOUND *csound, MYFLT *args[], int numargs); - - -/* -------------------------------------------------------------------- */ - -typedef struct { - OPDS h; - MYFLT *x1, *y1, *z1, *x2, *y2, *z2; - - int local_buf_index; -} RB_XYZ; - - -static int rbatonXYZ_set(CSOUND *csound, RB_XYZ *p) -{ - p->local_buf_index = csound->midiGlobals->MIDIINbufIndex & MIDIINBUFMSK; - *p->x1 = *p->y1 = *p->z1 = *p->x2 = *p->y2 = *p->z2 = 0; - return OK; -} - -static int rbatonXYZ(CSOUND *csound, RB_XYZ *p) -{ - int status, data1, data2; - MGLOBAL* mg = csound->midiGlobals; - /* - if (p->local_buf_index < mg->MIDIINbufIndex) { - MIDIMESSAGE temp = mg->MIDIINbuffer2[(p->local_buf_index)++ % MIDIINBUFMAX]; - status = temp.bData[0]; - data1 = temp.bData[1]; - data2 = temp.bData[2]; - */ - if (p->local_buf_index != mg->MIDIINbufIndex) { - unsigned char *temp; - temp = &(mg->MIDIINbuffer2[p->local_buf_index++].bData[0]); - p->local_buf_index &= MIDIINBUFMSK; - status = (*temp ); - data1 = *++temp; - data2 = *++temp; - } - else return OK; - if (status == 0xA0) { - switch (data1) { - case 8: *p->x1 = data2/FL(127.0); break; - case 9: *p->y1 = data2/FL(127.0); break; - case 10: *p->z1 = data2/FL(127.0); break; - case 11: *p->x2 = data2/FL(127.0); break; - case 12: *p->y2 = data2/FL(127.0); break; - case 13: *p->z2 = data2/FL(127.0); break; - } - } - return OK; -} -/* -------------------------------------------------------------------- */ - -typedef struct { - OPDS h; - MYFLT *pot1, *pot2, *pot3, *pot4, *fsw1, *fsw2, *button; - int local_buf_index; -} RB_POT; - -static int rbatonPot_set(CSOUND *csound, RB_POT *p) -{ - p->local_buf_index = csound->midiGlobals->MIDIINbufIndex & MIDIINBUFMSK; - *p->pot1 = *p->pot2 = *p->pot3 = *p->pot4 = 0; - return OK; -} - -static int rbatonPot (CSOUND *csound, RB_POT *p) -{ - int status, data1, data2; - MGLOBAL* mg = csound->midiGlobals; - if (p->local_buf_index != csound->midiGlobals->MIDIINbufIndex) { - unsigned char *temp; - temp = &(mg->MIDIINbuffer2[p->local_buf_index++].bData[0]); - p->local_buf_index &= MIDIINBUFMSK; - status = (*temp ); - data1 = *++temp; - data2 = *++temp; - } - else return OK; - if (status == 0xA0) { - switch (data1) { - case 4: *p->pot1 = data2/FL(127.0); break; - case 5: *p->pot2 = data2/FL(127.0); break; - case 6: *p->pot3 = data2/FL(127.0); break; - case 7: *p->pot4 = data2/FL(127.0); break; - case 3: - switch (data2) { - case 1: *p->button = (*p->button == 0) ? FL(1.0) : FL(0.0); break; - case 2: *p->fsw1 = 1; break; - case 3: *p->fsw1 = 0; break; - case 4: *p->fsw2 = 1; break; - case 5: *p->fsw2 = 0; break; - } - break; - } - } - return OK; -} -/* -------------------------------------------------------------------- */ - -#define INCR (0.001f) - -typedef struct { - OPDS h; - MYFLT *kDur, *kBaton1instr, *kBaton2Instr, *kFootSw1dn, *kFootSw1up, - *kFootSw2dn, *kFootSw2up, *kButInstr; - MYFLT baton, whack, x, y, p0, p2, p3, p3neg; - MYFLT fs1dn, fs1up, fs2dn, fs2up; - MYFLT frac1, frac2; - MYFLT pot1, pot2, pot3; /* pontentiometer 4 is reserved to stick sensitivity */ - int local_buf_index; -} RB_PERCPAD; - -static int rbatonPercPad_set (CSOUND *csound, RB_PERCPAD *p) -{ - p->local_buf_index = csound->midiGlobals->MIDIINbufIndex & MIDIINBUFMSK; - p->p0 = 0; - p->p2 = 0; - p->p3 = 1; - p->p3neg = -1; - p->pot1 = p->pot2 = p->pot3 = 0; - p->fs1dn = -*p->kFootSw1dn; - p->fs2dn = -*p->kFootSw2dn; - p->fs1up = -*p->kFootSw1up; - p->fs2up = -*p->kFootSw2up; - p->frac1 = p->frac2 = 0; - return OK; -} - -static int rbatonPercPad(CSOUND *csound, RB_PERCPAD *p) -{ - int status, data1, data2; - MYFLT *args[10]; - - if (p->local_buf_index != csound->midiGlobals->MIDIINbufIndex) { - MGLOBAL* mg = csound->midiGlobals; - unsigned char *temp; - temp = &(mg->MIDIINbuffer2[p->local_buf_index++].bData[0]); - p->local_buf_index &= MIDIINBUFMSK; - status = (*temp ); - data1 = *++temp; - data2 = *++temp; - } - else return OK; - if (status == 0xA0) { - switch (data1) { - case 1: /* trigger baton and whack from stick 1 or 2 */ - case 2: - p->baton = (data1 == 1) ? *p->kBaton1instr : *p->kBaton2Instr; - p->whack = data2/FL(127.0); - break; - case 15: /* X coordinate at trigger */ - case 17: - p->x = data2/FL(127.0); - break; - - case 16: /* Y coordinate at trigger */ - case 18: - p->y = data2/FL(127.0); - args[0] = &(p->p0); /* this is the third baton trigger message */ - args[1] = &(p->baton); /* so activate corresponding instrument */ - args[2] = &(p->p2); - args[3] = &(*p->kDur); - args[4] = &(p->whack); - args[5] = &(p->x); - args[6] = &(p->y); - args[7] = &(p->pot1); - args[8] = &(p->pot2); - args[9] = &(p->pot3); - Sched(csound, args, 10); - break; - case 3: /* foot-switches and button */ - /* *kFootSw1dn, *kFootSw2dn, *kFootSw1up, *kFootSw2up, *kButInstr; */ - switch(data2) { - case 1: - if (*p->kButInstr) { /* if kButInstr is set */ - args[0] = &(p->p0); - args[1] = &(*p->kButInstr); - args[2] = &(p->p2); - args[3] = &(*p->kDur); - args[4] = &(p->pot1); - args[5] = &(p->pot2); - args[6] = &(p->pot3); - Sched(csound, args, 7); - } - printf("B15+ button\n"); - break; - case 2: /* footswitch 1 down */ - if (*p->kFootSw1dn) { /* if kFootSw1dn is set */ - p->fs1dn = (int) *p->kFootSw1dn + p->frac1; - args[0] = &(p->p0); - args[1] = &(p->fs1dn); - args[2] = &(p->p2); - args[3] = (*p->kFootSw1up) ? &(*p->kDur) : &(p->p3neg); - args[4] = &(p->pot1); - args[5] = &(p->pot2); - args[6] = &(p->pot3); - Sched(csound, args, 7); - } - else if (*p->kFootSw1up) { /* turn off the instrument */ - p->fs1up = -((int) *p->kFootSw1up + p->frac1); - args[0] = &(p->p0); - args[1] = &(p->fs1up); - args[2] = &(p->p2); - args[3] = &(p->p2); /* zero */ - Sched(csound, args, 4); - p->fs1up = -*p->kFootSw1up; - p->frac1 += INCR; - p->frac1 = (p->frac1 >= 1) ? p->frac1 = 0 : p->frac1; - } - printf("B14- foot switch down1\n"); - break; - case 3: - if (*p->kFootSw1up) { /* if kFootSw1up is set */ - p->fs1up = (int) *p->kFootSw1up + p->frac1; - args[0] = &(p->p0); - args[1] = &(p->fs1up); - args[2] = &(p->p2); - args[3] = (*p->kFootSw1dn) ? &(*p->kDur) : &(p->p3neg); - args[4] = &(p->pot1); - args[5] = &(p->pot2); - args[6] = &(p->pot3); - Sched(csound, args, 7); - } - else if (*p->kFootSw1dn) { /* turn off the instrument */ - p->fs1dn = -((int) *p->kFootSw1dn + p->frac1); - args[0] = &(p->p0); - args[1] = &(p->fs1dn); - args[2] = &(p->p2); - args[3] = &(p->p2); /* zero */ - Sched(csound, args, 4); - p->frac1 += INCR; - p->frac1 = (p->frac2 >= 1) ? p->frac1 = 0 : p->frac1; - } - printf("B14- foot switch up1\n"); - break; - case 4: - if (*p->kFootSw2dn) { /* if kFootSw1dn is set */ - /* CONTINUARE con frac1 e frac2 */ - p->fs2dn = (int) *p->kFootSw2dn + p->frac2; - args[0] = &(p->p0); - args[1] = &(p->fs2dn); - args[2] = &(p->p2); - args[3] = (*p->kFootSw2up) ? &(*p->kDur) : &(p->p3neg); - args[4] = &(p->pot1); - args[5] = &(p->pot2); - args[6] = &(p->pot3); - Sched(csound, args, 7); - } - else if (*p->kFootSw2up) { /* turn off the instrument */ - p->fs2up = -((int) *p->kFootSw2up + p->frac2); - args[0] = &(p->p0); - args[1] = &(p->fs2up); - args[2] = &(p->p2); - args[3] = &(p->p2); /* zero */ - Sched(csound, args, 4); - p->frac2 += INCR; - p->frac2 = (p->frac2 >= 1) ? p->frac2 = 0 : p->frac2; - } - printf("B15- foot switch down2\n"); - break; - case 5: - if (*p->kFootSw2up) { /* if kFootSw1up is set */ - p->fs2up = (int) *p->kFootSw2up + p->frac2; - args[0] = &(p->p0); - args[1] = &(p->fs2up); - args[2] = &(p->p2); - args[3] = (*p->kFootSw2dn) ? &(*p->kDur) : &(p->p3neg); - args[4] = &(p->pot1); - args[5] = &(p->pot2); - args[6] = &(p->pot3); - Sched(csound, args, 7); - - } - else if (*p->kFootSw2dn) { /* turn off the instrument */ - p->fs2dn = -((int) *p->kFootSw2dn + p->frac2); - args[0] = &(p->p0); - args[1] = &(p->fs2dn); - args[2] = &(p->p2); - args[3] = &(p->p2); /* zero */ - Sched(csound, args, 4); - p->frac2 += INCR; - p->frac2 = (p->frac2 >= 1) ? p->frac2 = 0 : p->frac2; - } - printf("B15- foot switch up2\n"); - break; - } - break; - case 4: p->pot1 = data2/FL(127.0); break; - case 5: p->pot2 = data2/FL(127.0); break; - case 6: p->pot3 = data2/FL(127.0); break; - } - } - return OK; -} - -#define S(x) sizeof(x) - -OENTRY radiobaton_localops[] = { - { "rbatonPercPad", S(RB_PERCPAD),3, "", "kkkkkkkk", - (SUBR)rbatonPercPad_set, (SUBR)rbatonPercPad }, - { "rbatonXYZ", S(RB_XYZ), 3, "kkkkkk", "", - (SUBR)rbatonXYZ_set, (SUBR)rbatonXYZ }, - { "rbatonPot", S(RB_POT), 3, "kkkkkkk", "", - (SUBR)rbatonPot_set, (SUBR)rbatonPot } -}; - -LINKAGE1(radiobaton_localops) - diff -Nru csound-5.17.11~dfsg/Opcodes/gab/sliderTable.c csound-6.02~dfsg/Opcodes/gab/sliderTable.c --- csound-5.17.11~dfsg/Opcodes/gab/sliderTable.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/sliderTable.c 2014-01-07 16:53:48.000000000 +0000 @@ -55,7 +55,7 @@ FUNC *outftp, **ftp = p->ftp; \ MYFLT *chanblock = (MYFLT *) csound->m_chnbp[chan]->ctl_val; \ \ - if((outftp = csound->FTFind(csound, p->ioutfn)) != NULL) \ + if((outftp = csound->FTnp2Find(csound, p->ioutfn)) != NULL) \ p->outTable = outftp->ftable; \ while (j < 8) { \ int t = (int) *sld->ifn; \ @@ -110,7 +110,7 @@ default: /* TABLE */ \ value = value; /* unchanged, value must be in the 0 to 1 range, */ \ /* representing the phase of the table */ \ - if (*sld->ifn > 0) *ftp = csound->FTFind(csound, sld->ifn); \ + if (*sld->ifn > 0) *ftp = csound->FTnp2Find(csound, sld->ifn); \ } \ chanblock[*slnum++] = (MYFLT)((int)(value * f7bit + FL(0.5))); \ min++; max++; ftp++; j++; sld++; \ @@ -268,7 +268,7 @@ MYFLT *yt1 = p->yt1, *c1=p->c1, *c2=p->c2; \ \ \ - if((outftp = csound->FTFind(csound, p->ioutfn)) != NULL) \ + if((outftp = csound->FTnp2Find(csound, p->ioutfn)) != NULL) \ p->outTable = outftp->ftable; \ while (j < n) { \ int t = (int) *sld->ifn; \ @@ -310,7 +310,7 @@ default: /* TABLE */ \ value = value; /* unchanged, value must be in the 0 to 1 range, */ \ /* representing the phase of the table */ \ - if (*sld->ifn > 0) *ftp = csound->FTFind(csound, sld->ifn); \ + if (*sld->ifn > 0) *ftp = csound->FTnp2Find(csound, sld->ifn); \ if (value >= 1 || value < 0) { \ sprintf(sbuf, Str("sliderXtable: illegal initvalue at " \ "position %d. When using table indexing," \ @@ -322,7 +322,7 @@ /*----- init filtering coeffs*/ \ *yt1++ = FL(0.0); \ b = (MYFLT)(2.0 - cos((double)(*(sld)->ihp * \ - csound->tpidsr * csound->ksmps))); \ + csound->tpidsr * CS_KSMPS))); \ *c2 = (MYFLT)(b - sqrt((double)(b * b - FL(1.0)))); \ *c1++ = FL(1.0) - *c2++; \ \ @@ -512,7 +512,7 @@ sprintf(sbuf, Str("illegal initvalue at position n.%d"), j); return csound->InitError(csound, sbuf); } - if (*sld->ifn > 0) *ftp++ = csound->FTFind(csound, sld->ifn); + if (*sld->ifn > 0) *ftp++ = csound->FTnp2Find(csound, sld->ifn); else *ftp++ = NULL; value = (*(sld++)->initvalue - *min) / (*max++ - *min); min++; @@ -569,7 +569,7 @@ else p->ctlno = ctlno; if (*p->ifn > 0) { - if (((p->ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) p->flag = 0; /* invalid ftable */ else p->flag= 1; } @@ -579,7 +579,7 @@ if (*p->icutoff <= 0) cutoff = 5; else cutoff = *p->icutoff; - b = FL(2.0) - COS(cutoff * csound->tpidsr * csound->ksmps); + b = FL(2.0) - COS(cutoff * csound->tpidsr * CS_KSMPS); p->c2 = b - SQRT(b * b - 1.0); p->c1 = FL(1.0) - p->c2; p->prev = 0; @@ -589,7 +589,9 @@ static int ctrl7a(CSOUND *csound, CTRL7a *p) { MYFLT *ar, val, incr; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT value = (MYFLT) (csound->m_chnbp[(int) *p->ichan-1]->ctl_val[p->ctlno] * oneTOf7bit); if (p->flag) { /* if valid ftable,use value as index */ @@ -597,14 +599,19 @@ value = *(p->ftp->ftable + (long)(value*(p->ftp->flen-1))); } /* scales the output */ - value = value * (*p->imax - *p->imin) + *p->imin + TOOSMALL; + value = value * (*p->imax - *p->imin) + *p->imin + TOOSMALL; value = p->yt1 = p->c1 * value + p->c2 * p->yt1; ar = p->r; val = p->prev; - incr = (value - val) / (MYFLT) csound->ksmps; - do { - *ar++ = val += incr; - } while (--nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + incr = (value - val) / (MYFLT)(nsmps-offset); + for (n=offset; nprev = val; return OK; } @@ -614,20 +621,20 @@ #define S(x) sizeof(x) OENTRY sliderTable_localops[] = { -{ "slider8table", S(SLIDER8t), 3, "k", "iii" +{ "slider8table", S(SLIDER8t), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i8, (SUBR)sliderTable8, (SUBR)NULL }, -{ "slider16table", S(SLIDER8t), 3, "k", "iii" +{ "slider16table", S(SLIDER8t), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i16, (SUBR)sliderTable16, (SUBR)NULL }, -{ "slider32table", S(SLIDER8t), 3, "k", "iii" +{ "slider32table", S(SLIDER8t), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i32, (SUBR)sliderTable32, (SUBR)NULL }, -{ "slider64table", S(SLIDER8t), 3, "k", "iii" +{ "slider64table", S(SLIDER8t), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" @@ -637,20 +644,20 @@ "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i64, (SUBR)sliderTable64, (SUBR)NULL }, -{ "slider8tablef", S(SLIDER8tf), 3, "k", "iii" +{ "slider8tablef", S(SLIDER8tf), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i8f, (SUBR)sliderTable8f, (SUBR)NULL }, -{ "slider16tablef",S(SLIDER16tf), 3, "k", "iii" +{ "slider16tablef",S(SLIDER16tf), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i16f, (SUBR)sliderTable16f, (SUBR)NULL }, -{ "slider32tablef",S(SLIDER32tf), 3, "k", "iii" +{ "slider32tablef",S(SLIDER32tf), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i32f, (SUBR)sliderTable32f, (SUBR)NULL }, -{ "slider64tablef",S(SLIDER64tf), 3, "k", "iii" +{ "slider64tablef",S(SLIDER64tf), 0, 3, "k", "iii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" @@ -660,11 +667,11 @@ "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderTable_i64f, (SUBR)sliderTable64f, (SUBR)NULL }, -{ "sliderKawai", S(SLIDERKAWAI), 3, "kkkkkkkkkkkkkkkk", +{ "sliderKawai", S(SLIDERKAWAI), 0, 3, "kkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)sliderKawai_i, (SUBR)sliderKawai, NULL }, -{ "ctrl7.a", S(CTRL7a), 5, "a", "iikkoo", +{ "ctrl7.a", S(CTRL7a), 0, 5, "a", "iikkoo", (SUBR) ctrl7a_set, NULL, (SUBR) ctrl7a }, }; @@ -673,4 +680,3 @@ csound->AppendOpcodes(csound, &(sliderTable_localops[0]), (int) (sizeof(sliderTable_localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/gab/stdopcod.h csound-6.02~dfsg/Opcodes/gab/stdopcod.h --- csound-5.17.11~dfsg/Opcodes/gab/stdopcod.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/stdopcod.h 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,120 @@ +/* + stdopcod.h: + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#ifndef CSOUND_STDOPCOD_H +#define CSOUND_STDOPCOD_H + +//#include "csdl.h" +#include "csoundCore.h" +#include + + +#include "interlocks.h" + +/* file structure for fout opcodes */ + +struct fileinTag { + SNDFILE *file; /* Used in audio cases */ + FILE *raw; /* Only used if text file */ + void *fd; /* file handle returned by CSOUND::FileOpen */ + char *name; /* short name */ + int do_scale; /* non-zero if 0dBFS scaling should be applied */ + uint32 refCount; /* reference count, | 0x80000000 if close reqd */ +}; + +typedef struct VCO2_TABLE_ARRAY_ VCO2_TABLE_ARRAY; +typedef struct _atsbufread ATSBUFREAD; + +typedef struct STDOPCOD_GLOBALS_ { + CSOUND *csound; + /* fout.c */ + struct fileinTag *file_opened; + int file_max; + int file_num; + int32 fout_kreset; + /* MYFLT *buf; + int buf_size; */ /* VL - now using per instance buffer */ + /* oscbnk.c */ + uint32 oscbnk_seed; + int32 rnd31i_seed; + int denorm_seed; + int vco2_nr_table_arrays; + VCO2_TABLE_ARRAY **vco2_tables; + /* ugnorman.c */ + ATSBUFREAD *atsbufreadaddr; + int swapped_warning; + /* locsig.c */ + void *locsigaddr; + /* space.c */ + void *spaceaddr; + /* gab/gab.c */ + MYFLT *tb_ptrs[16]; /* Left here while the rest is implemented */ + MYFLT *tb[16]; /* gab: updated */ + int tb_ixmode[16]; /* gab: added */ + int32 tb_size[16]; /* gab: added */ +} STDOPCOD_GLOBALS; + +extern int ambicode_init_(CSOUND *); +extern int bbcut_init_(CSOUND *); +extern int biquad_init_(CSOUND *); +extern int butter_init_(CSOUND *); +extern int clfilt_init_(CSOUND *); +extern int cross2_init_(CSOUND *); +extern int dam_init_(CSOUND *); +extern int dcblockr_init_(CSOUND *); +extern int filter_init_(CSOUND *); +extern int flanger_init_(CSOUND *); +extern int follow_init_(CSOUND *); +extern int fout_init_(CSOUND *); +extern int freeverb_init_(CSOUND *); +extern int ftconv_init_(CSOUND *); +extern int ftgen_init_(CSOUND *); +extern int gab_gab_init_(CSOUND *); +extern int gab_vectorial_init_(CSOUND *); +extern int grain_init_(CSOUND *); +extern int locsig_init_(CSOUND *); +extern int lowpassr_init_(CSOUND *); +extern int metro_init_(CSOUND *); +extern int midiops2_init_(CSOUND *); +extern int midiops3_init_(CSOUND *); +extern int newfils_init_(CSOUND *); +extern int nlfilt_init_(CSOUND *); +extern int oscbnk_init_(CSOUND *); +extern int pluck_init_(CSOUND *); +extern int repluck_init_(CSOUND *); +extern int reverbsc_init_(CSOUND *); +extern int seqtime_init_(CSOUND *); +extern int sndloop_init_(CSOUND *); +extern int sndwarp_init_(CSOUND *); +extern int space_init_(CSOUND *); +extern int spat3d_init_(CSOUND *); +extern int syncgrain_init_(CSOUND *); +extern int ugens7_init_(CSOUND *); +extern int ugens9_init_(CSOUND *); +extern int ugensa_init_(CSOUND *); +extern int uggab_init_(CSOUND *); +extern int ugmoss_init_(CSOUND *); +extern int ugnorman_init_(CSOUND *); +extern int ugsc_init_(CSOUND *); +extern int wave_terrain_init_(CSOUND *); + +#endif /* CSOUND_STDOPCOD_H */ + diff -Nru csound-5.17.11~dfsg/Opcodes/gab/tabmorph.c csound-6.02~dfsg/Opcodes/gab/tabmorph.c --- csound-5.17.11~dfsg/Opcodes/gab/tabmorph.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/tabmorph.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ typedef struct { OPDS h; - MYFLT *out, *xindex, *xinterpoint, *xtabndx1, *xtabndx2, + MYFLT *out, *xindex, *xinterpoint, *xtabndx1, *xtabndx2, *argums[VARGMAX]; MYFLT *table[VARGMAX]; int length; @@ -39,7 +39,7 @@ numOfTabs = p->numOfTabs =((p->INCOUNT-4)); /* count segs & alloc if nec */ argp = p->argums; for (j=0; j< numOfTabs; j++) { - if (UNLIKELY((ftp = csound->FTFind(csound, *argp++)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, *argp++)) == NULL)) return csound->InitError(csound, Str("tabmorph: invalid table number")); if (UNLIKELY(ftp->flen != flength && flength != 0)) return @@ -140,15 +140,22 @@ static int atabmorphia(CSOUND *csound, TABMORPH *p) /* all arguments at a-rate */ { - int n, nsmps = csound->ksmps, tablen = p->length; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int tablen = p->length; MYFLT *out = p->out; MYFLT *index = p->xindex; MYFLT *interpoint = p->xinterpoint; MYFLT *tabndx1 = p->xtabndx1; MYFLT *tabndx2 = p->xtabndx2; - - for (n=0; nnumOfTabs; @@ -200,7 +206,10 @@ /* all args k-rate except out and table index */ static int atabmorphi(CSOUND *csound, TABMORPH *p) { - int n, nsmps = csound->ksmps, tablen = p->length; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int tablen = p->length; MYFLT *out = p->out; MYFLT *index; @@ -223,7 +232,12 @@ interpoint = *p->xinterpoint; interpoint -= (int) interpoint; /* to limit to zero to 1 range */ - for (n=0; nAppendOpcodes(csound, &(tabmoroph_localops[0]), (int) (sizeof(tabmoroph_localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/gab/vectorial.c csound-6.02~dfsg/Opcodes/gab/vectorial.c --- csound-5.17.11~dfsg/Opcodes/gab/vectorial.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gab/vectorial.c 2014-01-07 16:53:48.000000000 +0000 @@ -20,7 +20,7 @@ Optional arguments to some opcodes and other fixes by Andres Cabrera and Istvan Varga. */ -//#include "csdl.h" +//#include "stdopcod.h" #include "csoundCore.h" #include "interlocks.h" #include "vectorial.h" @@ -32,7 +32,7 @@ int j, nargs; MYFLT *table, xbmul = FL(0.0), **out = p->outargs; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtablei: incorrect table number")); + return csound->InitError(csound, Str("vtablei: incorrect table number")); } table = ftp->ftable; nargs = p->INOCOUNT-4; @@ -62,7 +62,7 @@ { FUNC *ftp; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtable: incorrect table number")); + return csound->InitError(csound, Str("vtable: incorrect table number")); } p->ftable = ftp->ftable; p->nargs = p->INOCOUNT-4; @@ -82,7 +82,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtable: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtablek: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -123,7 +124,10 @@ static int mtable_a(CSOUND *csound,MTABLE *p) { int j, nargs = p->nargs; - int nsmps = csound->ksmps, ixmode = (int) *p->ixmode, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; + int ixmode = (int) *p->ixmode; MYFLT **out = p->outargs; MYFLT *table; MYFLT *xndx = p->xndx, xbmul; @@ -132,7 +136,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtable: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtablea: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -143,12 +148,20 @@ table = p->ftable; len = p->len; xbmul = p->xbmul; + if (UNLIKELY(offset)) + for (j=0; j < nargs; j++) + memset(out[j], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + for (j=0; j < nargs; j++) + memset(&out[j][nsmps], '\0', early*sizeof(MYFLT)); + } if (*p->kinterp) { MYFLT fndx; long indx; MYFLT fract; long indxp1; - for (k=0; k= len) @@ -166,7 +179,7 @@ } } else { - for (k=0; koutargs; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtabi: incorrect table number")); + return csound->InitError(csound, Str("vtabi: incorrect table number")); } table = ftp->ftable; nargs = p->INOCOUNT-2; @@ -199,7 +212,7 @@ { FUNC *ftp; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtable: incorrect table number")); + return csound->InitError(csound, Str("vtab: incorrect table number")); } p->ftable = ftp->ftable; p->nargs = p->INOCOUNT-2; @@ -226,14 +239,24 @@ static int mtab_a(CSOUND *csound,MTAB *p) { int j, nargs = p->nargs; - int nsmps = csound->ksmps, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; MYFLT **out = p->outargs; MYFLT *table; MYFLT *xndx = p->xndx; long len; table = p->ftable; len = p->len; - for (k=0;kinargs; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtablewi: incorrect table number")); + return csound->InitError(csound, Str("vtablewi: incorrect table number")); } table = ftp->ftable; nargs = p->INOCOUNT-3; @@ -267,7 +290,7 @@ { FUNC *ftp; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtabw: incorrect table number")); + return csound->InitError(csound, Str("vtablew: incorrect table number")); } p->ftable = ftp->ftable; p->nargs = p->INOCOUNT-3; @@ -287,7 +310,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtabw: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtablewk: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -307,7 +331,10 @@ static int mtablew_a(CSOUND *csound,MTABLEW *p) { int j, nargs = p->nargs; - int nsmps = csound->ksmps, ixmode = (int) *p->ixmode, k=0; + int ixmode = (int) *p->ixmode; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t k, nsmps = CS_KSMPS; + uint32_t early = p->h.insdshead->ksmps_no_end; MYFLT **in = p->inargs; MYFLT *table; MYFLT *xndx = p->xndx, xbmul; @@ -316,7 +343,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtabw: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtablewa: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -327,14 +355,14 @@ table = p->ftable; len = p->len; xbmul = p->xbmul; - do { + if (UNLIKELY(early)) nsmps -= early; + for (k=offset; kinargs; if ((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL) { - return csound->InitError(csound, Str("mtabwi: incorrect table number")); + return csound->InitError(csound, Str("vtabwi: incorrect table number")); } table = ftp->ftable; nargs = p->INOCOUNT-2; @@ -361,7 +389,7 @@ { FUNC *ftp; if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->xfn)) == NULL)) { - return csound->InitError(csound, Str("mtabw: incorrect table number")); + return csound->InitError(csound, Str("vtablew: incorrect table number")); } p->ftable = ftp->ftable; p->nargs = p->INOCOUNT-2; @@ -379,7 +407,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtablew: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtablewk: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -396,7 +425,9 @@ static int mtabw_a(CSOUND *csound,MTABW *p) { int j, nargs = p->nargs; - int nsmps = csound->ksmps, k=0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; MYFLT **in = p->inargs; MYFLT *table; MYFLT *xndx = p->xndx; @@ -405,7 +436,8 @@ if (p->pfn != (long)*p->xfn) { FUNC *ftp; if ( (ftp = csound->FTnp2Find(csound, p->xfn) ) == NULL) { - return csound->PerfError(csound, Str("mtabw: incorrect table number")); + return csound->PerfError(csound, p->h.insdshead, + Str("vtabwa: incorrect table number")); } p->pfn = (long)*p->xfn; p->ftable = ftp->ftable; @@ -413,13 +445,13 @@ } table = p->ftable; len = p->len; - do { + if (UNLIKELY(early)) nsmps -= early; + for (k=offset; kvector = ftp->ftable; p->elements = (int) *p->ielements; } - if (UNLIKELY(p->elements > ftp->flen )) { + if (UNLIKELY(p->elements > (int)ftp->flen )) { return csound->InitError(csound, Str("vectorop: invalid num of elements")); } return OK; @@ -1717,12 +1749,12 @@ { FUNC *ftp; int elements; - MYFLT *vector, *yt1,*vecInit = NULL; + MYFLT /* *vector,*/ *yt1,*vecInit = NULL; if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifn)) != NULL)) { - vector = (p->vector = ftp->ftable); + p->vector = ftp->ftable; elements = (p->elements = (int) *p->ielements); - if (UNLIKELY(elements > ftp->flen) ) + if (UNLIKELY(elements > (int)ftp->flen) ) return csound->InitError(csound, Str("vport: invalid table length or " "num of elements")); @@ -1731,7 +1763,7 @@ if (LIKELY(*p->ifnInit)) { if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifnInit)) != NULL)) { vecInit = ftp->ftable; - if (UNLIKELY(elements > ftp->flen) ) + if (UNLIKELY(elements > (int)ftp->flen) ) return csound->InitError(csound, Str("vport: invalid init table length" " or num of elements")); } @@ -1759,7 +1791,7 @@ int elements = p->elements; MYFLT *vector = p->vector, *yt1 = p->yt1, c1, c2; if (p->prvhtim != *p->khtim) { - p->c2 = (MYFLT)pow(0.5, (double)csound->onedkr / *p->khtim); + p->c2 = (MYFLT)pow(0.5, (double)CS_ONEDKR / *p->khtim); p->c1 = FL(1.0) - p->c2; p->prvhtim = *p->khtim; } @@ -1775,7 +1807,7 @@ /*-------------------------------*/ static int vwrap(CSOUND *csound,VLIMIT *p) { - int elements = p->elements; + int elements = p->elements; MYFLT *vector = p->vector; MYFLT min = *p->kmin, max = *p->kmax; @@ -1886,12 +1918,12 @@ p->offset = (int) *p->idstoffset; } else return csound->InitError(csound, Str("vrandh: Invalid table.")); - if (UNLIKELY(*p->idstoffset >= ftp->flen)) + if (UNLIKELY(*p->idstoffset >= (int)ftp->flen)) return csound->InitError(csound, Str("vrandh: idstoffset is greater than" " table length.")); p->vector = ftp->ftable + p->offset; - if (UNLIKELY(p->elements + p->offset > ftp->flen)) { + if (UNLIKELY(p->elements + p->offset > (int)ftp->flen)) { csound->Warning(csound, Str("randh: Table length exceeded, " "last elements discarded.")); @@ -1930,7 +1962,7 @@ *vector++ = (*num1++ * value) + *p->ioffset; } while (--elements); - p->phs += (int32)(*p->kcps * csound->kicvt); + p->phs += (int32)(*p->kcps * CS_KICVT); if (p->phs >= MAXLEN) { p->phs &= PHMASK; elements = p->elements; @@ -1985,12 +2017,12 @@ p->offset = (int) *p->idstoffset; } else return csound->InitError(csound, Str("vrandi: Invalid table.")); - if (UNLIKELY(p->offset >= ftp->flen)) + if (UNLIKELY(p->offset >= (int)ftp->flen)) return csound->InitError(csound, Str("vrandi: idstoffset is greater than" "table length.")); p->vector = ftp->ftable + p->offset; - if (UNLIKELY(p->elements > ftp->flen)) { + if (UNLIKELY(p->elements > (int)ftp->flen)) { csound->Warning(csound, Str("vrandi: Table length exceeded, " "last elements discarded.")); @@ -2035,7 +2067,7 @@ *p->ioffset; } while (--elements); - p->phs += (int32)(*p->kcps * csound->kicvt); + p->phs += (int32)(*p->kcps * CS_KICVT); if (p->phs >= MAXLEN) { p->phs &= PHMASK; elements = p->elements; @@ -2072,32 +2104,32 @@ if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifnOut)) != NULL)) { p->outvec = ftp->ftable; elements = (p->elements = (int) *p->ielements); - if (UNLIKELY( elements > ftp->flen )) + if (UNLIKELY( elements > (int)ftp->flen )) return csound->InitError(csound, Str("vecdelay: invalid num of elements")); } else return csound->InitError(csound, Str("vecdly: invalid output table")); if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifnIn)) != NULL)) { p->invec = ftp->ftable; - if (UNLIKELY(elements > ftp->flen)) + if (UNLIKELY(elements > (int)ftp->flen)) return csound->InitError(csound, Str("vecdelay: invalid num of elements")); } else return csound->InitError(csound, Str("vecdly: invalid input table")); if (LIKELY((ftp = csound->FTnp2Find(csound,p->ifnDel)) != NULL)) { p->dlyvec = ftp->ftable; - if (UNLIKELY( elements > ftp->flen )) + if (UNLIKELY( elements > (int)ftp->flen )) return csound->InitError(csound, Str("vecdelay: invalid num of elements")); } else return csound->InitError(csound, Str("vecdly: invalid delay table")); - n = (p->maxd = (int32) (*p->imaxd * csound->ekr)); + n = (p->maxd = (int32) (*p->imaxd * CS_EKR)); if (n == 0) n = (p->maxd = 1); if (!*p->istod) { if (p->aux.auxp == NULL || - (int)(elements * sizeof(MYFLT *) + (unsigned int)(elements * sizeof(MYFLT *) + n * elements * sizeof(MYFLT) + elements * sizeof(int32)) > p->aux.size) { csound->AuxAlloc(csound, elements * sizeof(MYFLT *) @@ -2139,7 +2171,7 @@ } do { (*buf)[*indx] = *inVec++; - fv1 = *indx - *dlyVec++ * csound->ekr; + fv1 = *indx - *dlyVec++ * CS_EKR; while (fv1 < FL(0.0)) fv1 += (MYFLT)maxd; while (fv1 >= (MYFLT)maxd) fv1 -= (MYFLT)maxd; if (fv1 < maxd - 1) fv2 = fv1 + 1; @@ -2176,7 +2208,7 @@ p->vector = ftp->ftable; p->elements = (int) *p->ielements; } - if (UNLIKELY( p->elements > ftp->flen )) + if (UNLIKELY( p->elements > (int)ftp->flen )) return csound->InitError(csound, Str("vlinseg/vexpseg: invalid num. of elements")); @@ -2199,7 +2231,7 @@ if (UNLIKELY((nxtfunc = csound->FTnp2Find(csound,*argp++)) == NULL)) return NOTOK; if (dur > FL(0.0)) { - segp->d = dur * csound->ekr; + segp->d = dur * CS_EKR; segp->function = curfunc; segp->nxtfunction = nxtfunc; segp->cnt = (int32) MYFLT2LRND(segp->d); @@ -2296,7 +2328,7 @@ p->vector = ftp->ftable; p->elements = (int) *p->ielements; } - if ( p->elements > ftp->flen ) + if ( p->elements > (int)ftp->flen ) return csound->InitError(csound, Str("vphaseseg: invalid num. of elements")); vector = p->vector; @@ -2317,7 +2349,7 @@ if ((nxtfunc = csound->FTnp2Find(csound,*argp++)) == NULL) return NOTOK; if (dur > FL(0.0)) { durtot+=dur; - segp->d = dur; /* * csound->ekr; */ + segp->d = dur; /* * CS_EKR; */ segp->function = curfunc; segp->nxtfunction = nxtfunc; /* segp->cnt = (int32) (segp->d + .5); */ @@ -2383,11 +2415,11 @@ static int kdel_set(CSOUND *csound,KDEL *p) { uint32 n; - n = (p->maxd = (int32) (*p->imaxd * csound->ekr)); + n = (p->maxd = (int32) (*p->imaxd * CS_EKR)); if (n == 0) n = (p->maxd = 1); if (!*p->istod) { - if (p->aux.auxp == NULL || (int)(n*sizeof(MYFLT)) > p->aux.size) + if (p->aux.auxp == NULL || (unsigned int)(n*sizeof(MYFLT)) > p->aux.size) csound->AuxAlloc(csound, n * sizeof(MYFLT), &p->aux); else { memset(p->aux.auxp, 0, sizeof(MYFLT)*n); @@ -2408,7 +2440,7 @@ indx = p->left; buf[indx] = *p->kin; - fv1 = indx - *p->kdel * csound->ekr; + fv1 = indx - *p->kdel * CS_EKR; while (fv1 < FL(0.0)) fv1 += (MYFLT)maxd; while (fv1 >= (MYFLT)maxd) fv1 -= (MYFLT)maxd; if (*p->interp) { /* no interpolation */ @@ -2435,13 +2467,13 @@ if (LIKELY((ftp = csound->FTnp2Find(csound,p->ioutFunc)) != NULL)) { p->outVec = ftp->ftable; elements = (p->elements = (int) *p->ielements); - if (UNLIKELY( elements > ftp->flen )) + if (UNLIKELY( elements > (int)ftp->flen )) return csound->InitError(csound, Str("cella: invalid num of elements")); } else return csound->InitError(csound, Str("cella: invalid output table")); if (LIKELY((ftp = csound->FTnp2Find(csound,p->initStateFunc)) != NULL)) { initVec = (p->initVec = ftp->ftable); - if (UNLIKELY(elements > ftp->flen )) + if (UNLIKELY(elements > (int)ftp->flen )) return csound->InitError(csound, Str("cella: invalid num of elements")); } else return csound->InitError(csound, @@ -2514,53 +2546,73 @@ #define S(x) sizeof(x) OENTRY vectorial_localops[] = { - { "vtablei", S(MTABLEI), TR|1, "", "iiiim", (SUBR)mtable_i, NULL }, - { "vtablek", S(MTABLE), TR|3, "", "kkkiz", (SUBR)mtable_set, (SUBR)mtable_k, NULL }, - { "vtablea", S(MTABLE), TR|5, "", "akkiy", (SUBR)mtable_set, NULL, (SUBR)mtable_a }, - { "vtablewi", S(MTABLEIW), TB|1, "", "iiim", (SUBR)mtablew_i, NULL }, - { "vtablewk", S(MTABLEW), TB|3, "", "kkiz", (SUBR)mtablew_set, (SUBR)mtablew_k, NULL }, - { "vtablewa", S(MTABLEW), TB|5, "", "akiy", (SUBR)mtablew_set, NULL, (SUBR)mtablew_a }, - { "vtabi", S(MTABI), TR|1, "", "iim", (SUBR)mtab_i, NULL }, - { "vtabk", S(MTAB), TR|3, "", "kiz", (SUBR)mtab_set, (SUBR)mtab_k, NULL }, - { "vtaba", S(MTAB), TR|5, "", "aiy", (SUBR)mtab_set, NULL, (SUBR)mtab_a }, - { "vtabwi", S(MTABIW), TB|1, "", "iim", (SUBR)mtabw_i, NULL }, - { "vtabwk", S(MTABW), TB|3, "", "kiz", (SUBR)mtabw_set, (SUBR)mtabw_k, NULL }, - { "vtabwa", S(MTABW), TB|5, "", "aiy", (SUBR)mtabw_set, NULL, (SUBR)mtabw_a }, - - { "vadd", S(VECTOROP), TB|3, "", "ikkOO", (SUBR)vectorOp_set, (SUBR) vaddk }, - { "vadd_i", S(VECTOROPI), TB|1, "", "iiio", (SUBR) vadd_i, NULL, NULL }, - { "vmult", S(VECTOROP), TB|3, "", "ikkOO", (SUBR)vectorOp_set, (SUBR) vmultk}, - { "vmult_i", S(VECTOROPI), TB|1, "", "iiio", (SUBR) vmult_i, NULL, NULL }, - { "vpow", S(VECTOROP), TB|3, "", "ikkOO", (SUBR)vectorOp_set, (SUBR) vpowk }, - { "vpow_i", S(VECTOROPI), TB|1, "", "iiio", (SUBR) vpow_i, NULL, NULL }, - { "vexp", S(VECTOROP), TB|3, "", "ikkOO", (SUBR)vectorOp_set, (SUBR) vexpk }, - { "vexp_i", S(VECTOROPI), TB|1, "", "iiio", (SUBR) vexp_i, NULL, NULL }, - { "vaddv", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vaddvk }, - { "vaddv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vaddv_i, NULL, NULL }, - { "vsubv", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vsubvk }, - { "vsubv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vsubv_i, NULL, NULL }, - { "vmultv", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vmultvk}, - { "vmultv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vmultv_i, NULL, NULL }, - { "vdivv", S(VECTORSOP), TB| 3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vdivvk }, - { "vdivv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vdivv_i, NULL, NULL }, - { "vpowv", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vpowvk }, - { "vpowv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vpowv_i, NULL, NULL }, - { "vexpv", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vexpvk }, - { "vexpv_i", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vexpv_i, NULL, NULL }, - { "vcopy", S(VECTORSOP), TB|3, "", "iikOOO", (SUBR)vectorsOp_set, (SUBR) vcopy }, - { "vcopy_i", S(VECTORSOP), TB|1, "", "iiioo", (SUBR) vcopy_i, NULL, NULL }, - { "vmap", S(VECTORSOPI), TB|1, "", "iiioo", (SUBR)vmap_i, NULL, NULL }, - { "vlimit", S(VLIMIT), TR|3, "", "ikki",(SUBR)vlimit_set, (SUBR)vlimit }, - { "vwrap", S(VLIMIT), TB|3, "", "ikki",(SUBR)vlimit_set, (SUBR) vwrap }, - { "vmirror", S(VLIMIT), 3, "", "ikki",(SUBR)vlimit_set, (SUBR)vmirror }, - { "vlinseg", S(VSEG), TB|3, "", "iin", (SUBR)vseg_set, (SUBR)vlinseg }, - { "vexpseg", S(VSEG), 3, "", "iin", (SUBR)vseg_set, (SUBR)vexpseg }, - { "vrandh", S(VRANDH), TB|3, "", "ikkiovoo",(SUBR)vrandh_set, (SUBR) vrandh}, - { "vrandi", S(VRANDI), TB|3, "", "ikkiovoo",(SUBR)vrandi_set, (SUBR)vrandi }, - { "vport", S(VPORT), TB|3, "", "ikio",(SUBR)vport_set, (SUBR)vport }, - { "vecdelay", S(VECDEL), 3, "", "iiiiio",(SUBR)vecdly_set, (SUBR)vecdly }, - { "vdelayk", S(KDEL), 3, "k", "kkioo",(SUBR)kdel_set, (SUBR)kdelay }, - { "vcella", S(CELLA), TR|3, "", "kkiiiiip",(SUBR)ca_set, (SUBR)ca } + { "vtablei", S(MTABLEI), TR, 1, "", "iiiim", (SUBR)mtable_i, NULL }, + { "vtablek", S(MTABLE), TR, 3, "", "kkkiz", + (SUBR)mtable_set, (SUBR)mtable_k, NULL }, + { "vtablea", S(MTABLE), TR, 5, "", "akkiy", + (SUBR)mtable_set, NULL, (SUBR)mtable_a }, + { "vtablewi", S(MTABLEIW), TB, 1, "", "iiim", (SUBR)mtablew_i, NULL }, + { "vtablewk", S(MTABLEW), TB, 3, "", "kkiz", + (SUBR)mtablew_set, (SUBR)mtablew_k, NULL }, + { "vtablewa", S(MTABLEW), TB, 5, "", "akiy", + (SUBR)mtablew_set, NULL, (SUBR)mtablew_a }, + { "vtabi", S(MTABI), TR, 1, "", "iim", (SUBR)mtab_i, NULL }, + { "vtabk", S(MTAB), TR, 3, "", "kiz", + (SUBR)mtab_set, (SUBR)mtab_k, NULL }, + { "vtaba", S(MTAB), TR, 5, "", "aiy", + (SUBR)mtab_set, NULL, (SUBR)mtab_a }, + { "vtabwi", S(MTABIW), TB, 1, "", "iim", (SUBR)mtabw_i, NULL }, + { "vtabwk", S(MTABW), TB, 3, "", "kiz", + (SUBR)mtabw_set, (SUBR)mtabw_k, NULL }, + { "vtabwa", S(MTABW), TB, 5, "", "aiy", + (SUBR)mtabw_set, NULL, (SUBR)mtabw_a }, + + { "vadd", S(VECTOROP), TB, 3, "", "ikkOO", + (SUBR)vectorOp_set, (SUBR) vaddk }, + { "vadd_i", S(VECTOROPI), TB, 1, "", "iiio", (SUBR) vadd_i, NULL, NULL }, + { "vmult", S(VECTOROP), TB, 3, "", "ikkOO", + (SUBR)vectorOp_set, (SUBR) vmultk}, + { "vmult_i", S(VECTOROPI), TB, 1, "", "iiio", (SUBR) vmult_i, NULL, NULL }, + { "vpow", S(VECTOROP), TB, 3, "", "ikkOO", + (SUBR)vectorOp_set, (SUBR) vpowk }, + { "vpow_i", S(VECTOROPI), TB, 1, "", "iiio", (SUBR) vpow_i, NULL, NULL }, + { "vexp", S(VECTOROP), TB, 3, "", "ikkOO", + (SUBR)vectorOp_set, (SUBR) vexpk }, + { "vexp_i", S(VECTOROPI), TB, 1, "", "iiio", (SUBR) vexp_i, NULL, NULL }, + { "vaddv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vaddvk }, + { "vaddv_i", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vaddv_i, NULL, NULL }, + { "vsubv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vsubvk }, + { "vsubv_i", S(VECTORSOPI), TB, 1, "", "iiioo", + (SUBR)vsubv_i, NULL, NULL }, + { "vmultv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vmultvk}, + { "vmultv_i", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vmultv_i, NULL, NULL }, + { "vdivv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vdivvk }, + { "vdivv_i", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vdivv_i, NULL, NULL }, + { "vpowv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vpowvk }, + { "vpowv_i", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vpowv_i, NULL, NULL }, + { "vexpv", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vexpvk }, + { "vexpv_i", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vexpv_i, NULL, NULL }, + { "vcopy", S(VECTORSOP), TB, 3, "", "iikOOO", + (SUBR)vectorsOp_set, (SUBR) vcopy }, + { "vcopy_i", S(VECTORSOP), TB, 1, "", "iiioo", (SUBR) vcopy_i, NULL, NULL}, + { "vmap", S(VECTORSOPI), TB, 1, "", "iiioo", (SUBR)vmap_i, NULL, NULL }, + { "vlimit", S(VLIMIT), TR, 3, "", "ikki",(SUBR)vlimit_set, (SUBR)vlimit }, + { "vwrap", S(VLIMIT), TB, 3, "", "ikki",(SUBR)vlimit_set, (SUBR) vwrap }, + { "vmirror", S(VLIMIT), 0, 3, "", "ikki",(SUBR)vlimit_set, (SUBR)vmirror }, + { "vlinseg", S(VSEG), TB, 3, "", "iin", (SUBR)vseg_set, (SUBR)vlinseg }, + { "vexpseg", S(VSEG), 0, 3, "", "iin", (SUBR)vseg_set, (SUBR)vexpseg }, + { "vrandh", S(VRANDH), TB, 3, "", "ikkiovoo",(SUBR)vrandh_set, (SUBR)vrandh}, + { "vrandi", S(VRANDI), TB, 3, "", "ikkiovoo",(SUBR)vrandi_set, (SUBR)vrandi }, + { "vport", S(VPORT), TB, 3, "", "ikio",(SUBR)vport_set, (SUBR)vport }, + { "vecdelay", S(VECDEL),0, 3, "", "iiiiio",(SUBR)vecdly_set, (SUBR)vecdly }, + { "vdelayk", S(KDEL), 0, 3, "k", "kkioo",(SUBR)kdel_set, (SUBR)kdelay }, + { "vcella", S(CELLA), TR, 3, "", "kkiiiiip",(SUBR)ca_set, (SUBR)ca } }; int gab_vectorial_init_(CSOUND *csound) @@ -2569,5 +2621,3 @@ csound->AppendOpcodes(csound, &(vectorial_localops[0]), (int) (sizeof(vectorial_localops) / sizeof(OENTRY))); } - - diff -Nru csound-5.17.11~dfsg/Opcodes/gendy.c csound-6.02~dfsg/Opcodes/gendy.c --- csound-5.17.11~dfsg/Opcodes/gendy.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/gendy.c 2014-01-07 16:53:48.000000000 +0000 @@ -182,7 +182,10 @@ static int agendy(CSOUND *csound, GENDY *p) { - int knum, n, nn = csound->ksmps; + int knum; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *memamp, *memdur, minfreq, maxfreq, dist; out = p->out; knum = (int)*p->knum; @@ -190,7 +193,12 @@ memdur = p->memdur.auxp; minfreq = *p->minfreq; maxfreq = *p->maxfreq; - for (n=0; nphase >= FL(1.0)) { int index = p->index; p->phase -= FL(1.0); @@ -309,7 +317,10 @@ static int agendyx(CSOUND *csound, GENDYX *p) { - int knum, n, nn = csound->ksmps; + int knum; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *memamp, *memdur, minfreq, maxfreq, dist, curve; out = p->out; knum = (int)*p->knum; @@ -317,7 +328,12 @@ memdur = p->memdur.auxp; minfreq = *p->minfreq; maxfreq = *p->maxfreq; - for (n=0; nphase >= FL(1.0)) { int index = p->index; p->phase -= FL(1.0); @@ -432,7 +448,7 @@ memdur[index] = p->dur; fphase = (minfreq + (maxfreq - minfreq) * p->dur) * knum; fphase = (fphase > FL(0.001) ? fphase : FL(0.001)); - p->phase = (int32)(csound->esr / fphase); + p->phase = (int32)(csound->GetSr(csound) / fphase); if (p->phase < 2) p->phase = 2; p->curve = FL(2.0) * (next_midpnt - p->midpnt - p->phase * p->slope); p->curve = p->curve / (p->phase * p->phase + p->phase); @@ -447,7 +463,10 @@ static int agendyc(CSOUND *csound, GENDYC *p) { - int knum, remain = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + int knum; + int remain = CS_KSMPS-offset-early; MYFLT *out, *memamp, *memdur, minfreq, maxfreq, dist; out = p->out; knum = (int)*p->knum; @@ -455,8 +474,12 @@ memdur = p->memdur.auxp; minfreq = *p->minfreq; maxfreq = *p->maxfreq; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + memset(&out[remain+offset], '\0', early*sizeof(MYFLT)); + } do { - int nsmps, n; + uint32_t n, nsmps = CS_KSMPS; if (p->phase <= 0) { int index = p->index; MYFLT fphase, next_midpnt; @@ -488,7 +511,7 @@ memdur[index] = p->dur; fphase = (minfreq + (maxfreq - minfreq) * p->dur) * knum; fphase = (fphase > FL(0.001) ? fphase : FL(0.001)); - p->phase = (int32)(csound->esr / fphase); + p->phase = (int32)(csound->GetSr(csound) / fphase); if (p->phase < 2) p->phase = 2; p->curve = FL(2.0) * (next_midpnt - p->midpnt - p->phase * p->slope); p->curve = p->curve / (p->phase * p->phase + p->phase); @@ -496,7 +519,7 @@ nsmps = (remain < p->phase ? remain : p->phase); remain -= nsmps; p->phase -= nsmps; - for (n=0; nkamp * p->midpnt; p->slope += p->curve; p->midpnt += p->slope; @@ -509,18 +532,18 @@ { "gendy", 0xffff }, { "gendyx", 0xffff }, { "gendyc", 0xffff }, - { "gendy.k", sizeof(GENDY), 3, "k", "kkkkkkkkkoO", + { "gendy.k", sizeof(GENDY), 0,3, "k", "kkkkkkkkkoO", (SUBR)gendyset, (SUBR)kgendy, (SUBR)NULL }, - { "gendy.a", sizeof(GENDY), 5, "a", "kkkkkkkkkoO", + { "gendy.a", sizeof(GENDY), 0,5, "a", "kkkkkkkkkoO", (SUBR)gendyset, (SUBR)NULL, (SUBR)agendy }, - { "gendyx.k", sizeof(GENDYX), 3, "k", "kkkkkkkkkkkoO", + { "gendyx.k", sizeof(GENDYX), 0,3, "k", "kkkkkkkkkkkoO", (SUBR)gendyxset, (SUBR)kgendyx, (SUBR)NULL }, - { "gendyx.a", sizeof(GENDYX), 5, "a", "kkkkkkkkkkkoO", + { "gendyx.a", sizeof(GENDYX), 0,5, "a", "kkkkkkkkkkkoO", (SUBR)gendyxset, (SUBR)NULL, (SUBR)agendyx }, - { "gendyc.k", sizeof(GENDYC), 3, "k", "kkkkkkkkkoO", + { "gendyc.k", sizeof(GENDYC), 0,3, "k", "kkkkkkkkkoO", (SUBR)gendycset, (SUBR)kgendyc, (SUBR)NULL }, - { "gendyc.a", sizeof(GENDYC), 5, "a", "kkkkkkkkkoO", + { "gendyc.a", sizeof(GENDYC), 0,5, "a", "kkkkkkkkkoO", (SUBR)gendycset, (SUBR)NULL, (SUBR)agendyc } }; -LINKAGE1(gendy_localops) +LINKAGE_BUILTIN(gendy_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/grain.c csound-6.02~dfsg/Opcodes/grain.c --- csound-5.17.11~dfsg/Opcodes/grain.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/grain.c 2014-01-07 16:53:48.000000000 +0000 @@ -27,7 +27,7 @@ /* Some speed hacks added by John Fitch */ -#include "csdl.h" +#include "stdopcod.h" #include "grain.h" static inline MYFLT Unirand(CSOUND *csound, MYFLT a) @@ -58,14 +58,14 @@ else p->pr = FL(0.0); - bufsize = sizeof(MYFLT) * (2L * (size_t) (csound->esr * *p->imkglen) - + (3L * csound->ksmps)); + bufsize = sizeof(MYFLT) * (2L * (size_t) (CS_ESR * *p->imkglen) + + (3L * CS_KSMPS)); - if (p->aux.auxp == NULL || bufsize > p->aux.size) + if (p->aux.auxp == NULL || (unsigned int)bufsize > p->aux.size) csound->AuxAlloc(csound, bufsize, &p->aux); else memset(p->aux.auxp, '\0', bufsize); /* Clear any old data */ d = p->x = (MYFLT *)p->aux.auxp; - d += (int)(csound->esr * *p->imkglen) + csound->ksmps; + d += (int)(CS_ESR * *p->imkglen) + CS_KSMPS; p->y = d; p->ampadv = (XINARG1) ? 1 : 0; @@ -80,16 +80,19 @@ MYFLT *buf, *out, *rem, *gtbl, *etbl; MYFLT *xdns, *xamp, *xlfr, *temp, amp; int32 isc, isc2, inc, inc2, lb, lb2; - int32 n, i, bufsize; + int32 n, bufsize; int32 ekglen; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; MYFLT kglen = *p->kglen; MYFLT gcount = p->gcount; /* Pick up common values to locals for speed */ if (UNLIKELY(p->aux.auxp==NULL)) goto err1; if (UNLIKELY(kglen<=FL(0.0))) - return csound->PerfError(csound, Str("grain: grain length zero")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain: grain length zero")); gtp = p->gftp; gtbl = gtp->ftable; @@ -105,16 +108,20 @@ if (kglen > *p->imkglen) kglen = *p->imkglen; - ekglen = (int32)(csound->esr * kglen); /* Useful constant */ + ekglen = (int32)(CS_ESR * kglen); /* Useful constant */ inc2 = (int32)(csound->sicvt / kglen); /* Constant for each cycle */ - bufsize = csound->ksmps + ekglen; + bufsize = CS_KSMPS + ekglen; xdns = p->xdns; xamp = p->xamp; xlfr = p->xlfr; memset(buf, '\0', bufsize*sizeof(MYFLT)); - - for (i = 0 ; i < nsmps ; i++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset ; i < nsmps ; i++) { if (gcount >= FL(1.0)) { /* I wonder..... */ gcount = FL(0.0); amp = *xamp + Unirand(csound, *p->kabnd); @@ -141,21 +148,22 @@ n = bufsize; temp = rem; do { - *temp = *buf++ + *(temp + csound->ksmps); + *temp = *buf++ + *(temp + CS_KSMPS); temp++; } while (--n); - memcpy(out, rem, csound->ksmps*sizeof(MYFLT)); + memcpy(&out[offset], rem, (nsmps-offset)*sizeof(MYFLT)); p->gcount = gcount; return OK; err1: - return csound->PerfError(csound, Str("grain: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain: not initialised")); } #define S(x) sizeof(x) static OENTRY localops[] = { -{ "grain", S(PGRA), TR|5, "a", "xxxkkkiiio", (SUBR)agsset, NULL, (SUBR)ags } +{ "grain", S(PGRA), TR, 5, "a", "xxxkkkiiio", (SUBR)agsset, NULL, (SUBR)ags } }; int grain_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/grain4.c csound-6.02~dfsg/Opcodes/grain4.c --- csound-5.17.11~dfsg/Opcodes/grain4.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/grain4.c 2014-01-07 16:53:48.000000000 +0000 @@ -47,12 +47,12 @@ { FUNC *ftp, *ftp_env; int nvoice, cnt; - int32 tmplong1, tmplong2; + int32_t tmplong1, tmplong2; MYFLT tmpfloat1; MYFLT pitch[4]; /* call ftfind() to get the function table...*/ - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { p->ftp = ftp; } else { @@ -62,7 +62,7 @@ /* call ftfind() to get the function table for the envelop...*/ if (*p->ifnenv > 0) { - if (LIKELY((ftp_env = csound->FTFind(csound, p->ifnenv)) != NULL)) { + if (LIKELY((ftp_env = csound->FTnp2Find(csound, p->ifnenv)) != NULL)) { p->ftp_env = ftp_env; } else { @@ -119,7 +119,7 @@ } } - if (UNLIKELY((*p->igskip < 0) || (*p->igskip * csound->esr > ftp->flen) )) { + if (UNLIKELY((*p->igskip < 0) || (*p->igskip * CS_ESR > ftp->flen) )) { return csound->InitError(csound, Str("granule_set: must be positive and " "less than function table length")); } @@ -128,8 +128,8 @@ "igskip_os must be greater then 0")); } - p->gstart = (int32)(*p->igskip * csound->esr); - p->glength = (int32)(*p->ilength * csound->esr); + p->gstart = (int32)(*p->igskip * CS_ESR); + p->glength = (int32)(*p->ilength * CS_ESR); p->gend = p->gstart + p->glength; if (UNLIKELY(*p->kgap < 0)) { @@ -160,7 +160,7 @@ } /* Initialize variables....*/ - p->gskip_os = (int32)(*p->igskip_os * csound->esr);/* in number of samples */ + p->gskip_os = (int32)(*p->igskip_os * CS_ESR);/* in number of samples */ p->gap_os = *p->igap_os / FL(100.0); p->gsize_os = *p->igsize_os / FL(100.0); @@ -168,8 +168,8 @@ p->fpnt[nvoice] = 0; p->cnt[nvoice] = 0; p->phs[nvoice] = FL(0.0); - p->gskip[nvoice] = (int32)(*p->igskip * csound->esr); - p->gap[nvoice] = (int32)(*p->kgap * csound->esr); + p->gskip[nvoice] = (int32)(*p->igskip * CS_ESR); + p->gap[nvoice] = (int32)(*p->kgap * CS_ESR); } if (*p->igap_os != 0) { @@ -206,7 +206,7 @@ } for (nvoice = 0; nvoice < *p->ivoice; nvoice++) - p->gsize[nvoice] = (int32)(*p->kgsize * csound->esr * p->pshift[nvoice]); + p->gsize[nvoice] = (int32)(*p->kgsize * CS_ESR * p->pshift[nvoice]); if (*p->igsize_os != 0) { for (nvoice = 0; nvoice < *p->ivoice; nvoice++) @@ -218,23 +218,24 @@ if (*p->igskip_os != 0) for (nvoice = 0; nvoice < *p->ivoice; nvoice++) { - tmplong1 = (int32)((p->gskip_os * grand(p)) + (MYFLT)p->gskip[nvoice]); - p->gskip[nvoice] = (tmplong1 < p->gstart) ? p->gstart : tmplong1; + tmplong1 = ((p->gskip_os * grand(p)) + (MYFLT)p->gskip[nvoice]); + p->gskip[nvoice] = + (tmplong1 < p->gstart) ? p->gstart : tmplong1; p->gskip[nvoice]= - ((p->gskip[nvoice]+p->stretch[nvoice])>p->gend) ? - p->gstart : + ((p->gskip[nvoice]+p->stretch[nvoice])>(int32)p->gend) ? + (int32)p->gstart : p->gskip[nvoice]; } if (*p->ithd != 0) { /* Do thresholding.... */ tmplong2 = 0; - for (tmplong1=0; tmplong1flen; tmplong1++) - if (fabs(*(ftp->ftable + tmplong1)) >= *p->ithd ) - *(ftp->ftable + tmplong2++) = *(ftp->ftable + tmplong1); + for (tmplong1=0; tmplong1< (int) ftp->flen; tmplong1++) + if (fabs(ftp->ftable[tmplong1]) >= *p->ithd ) + ftp->ftable[tmplong2++] = ftp->ftable[tmplong1]; ftp->flen = tmplong2; } - if (p->gend > ftp->flen) { + if (p->gend > (int) ftp->flen) { return csound->InitError(csound, Str("granule_set: Illegal combination " "of igskip and ilength")); } @@ -261,7 +262,9 @@ { FUNC *ftp, *ftp_env; MYFLT *ar, *ftbl, *ftbl_env=NULL; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int nvoice; int32 tmplong1, tmplong2, tmplong3, tmpfpnt, flen_env=0; MYFLT fract, v1, tmpfloat1; @@ -287,9 +290,13 @@ /* Recover audio output pointer... */ ar = p->ar; - + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } /* *** Start the loop .... *** */ - for (n=0; nfpnt, *cnt = p->cnt, *gskip = p->gskip; int32 *gap = p->gap, *gsize = p->gsize; @@ -297,7 +304,7 @@ MYFLT *pshift = p->pshift, *phs = p->phs; ar[n] = FL(0.0); - for (nvoice = 0; nvoice < *p->ivoice; nvoice++) { + for (nvoice = 0; nvoice < *p->ivoice ; nvoice++) { if (*fpnt >= (*gsize -1)) { ar[n] += 0; /* Is this necessary?? */ *cnt +=1L; @@ -396,12 +403,12 @@ (tmpfloat1*FL(0.5))+FL(1.0) : tmpfloat1+FL(1.0); } - *gap = (int32)(*p->kgap * csound->esr); + *gap = (int32)(*p->kgap * CS_ESR); if (*p->igap_os != 0) { *gap += (int32)((*gap * p->gap_os) * grand(p)); } - *gsize = (int32)(*p->kgsize * csound->esr * *pshift); + *gsize = (int32)(*p->kgsize * CS_ESR * *pshift); if (*p->igsize_os != 0) *gsize += (int32)((*gsize * p->gsize_os) * grand(p)); @@ -416,7 +423,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("grain4: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain4: not initialised")); } /* end graingenv4(p) */ @@ -430,9 +438,14 @@ #define S(x) sizeof(x) + + + + + static OENTRY grain4_localops[] = { - { "granule", S(GRAINV4), TR|5, "a", "xiiiiiiiiikikiiivppppo", + { "granule", S(GRAINV4), TR, 5, "a", "xiiiiiiiiikikiiivppppo", (SUBR)grainsetv4, NULL, (SUBR)graingenv4}, }; -LINKAGE1(grain4_localops) +LINKAGE_BUILTIN(grain4_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/grain4.h csound-6.02~dfsg/Opcodes/grain4.h --- csound-5.17.11~dfsg/Opcodes/grain4.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/grain4.h 2014-01-07 16:53:48.000000000 +0000 @@ -35,7 +35,8 @@ int32 gsize[MAXVOICE], stretch[MAXVOICE], mode[MAXVOICE]; MYFLT pshift[MAXVOICE], phs[MAXVOICE]; int16 grnd; - int32 clock, gskip_os,gstart, gend, glength; + int32 clock, gskip_os; + int32_t gstart, gend, glength; MYFLT gap_os, gsize_os; FUNC *ftp, *ftp_env; } GRAINV4; diff -Nru csound-5.17.11~dfsg/Opcodes/harmon.c csound-6.02~dfsg/Opcodes/harmon.c --- csound-5.17.11~dfsg/Opcodes/harmon.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/harmon.c 2014-01-07 16:53:48.000000000 +0000 @@ -79,87 +79,99 @@ #define SLEN 256 #define LCNT 75 -static int hm234set(CSOUND *csound, HARM234 *p) +static int hm234set(CSOUND *csound, HARM234 *q, HARMON2 *p) { - MYFLT minoct = *p->ilowest; - p->hmrngflg = 0; - if (p->auxch.auxp == NULL || minoct < p->minoct) { + MYFLT minoct = *q->ilowest; + q->hmrngflg = 0; + if (q->auxch.auxp == NULL || minoct < q->minoct) { MYFLT minfrq = POWER(FL(2.0), minoct) * ONEPT; - int16 nbufs = (int16)(csound->ekr * 3 / minfrq) + 1;/* recalc max pulse prd */ - int16 nbufsmps = nbufs * csound->ksmps; - int16 maxprd = (int16)(csound->esr * 2 / minfrq); /* incl sigmoid ends */ + int16 nbufs = + (int16)(CS_EKR * 3 / minfrq) + 1;/* recalc max pulse prd */ + int16 nbufsmps = nbufs * CS_KSMPS; + int16 maxprd = (int16)(CS_ESR * 2 / minfrq); /* incl sigmoid ends */ int16 cnt; int32 totalsiz = nbufsmps * 2 + maxprd * 4 + (SLEN+1); MYFLT *pulsbuf, *sigp; /* & realloc buffers */ - csound->AuxAlloc(csound, totalsiz * sizeof(MYFLT), &p->auxch); - p->bufp = (MYFLT *) p->auxch.auxp; - p->midp = p->bufp + nbufsmps; /* each >= maxprd * 3 */ - pulsbuf = p->midp + nbufsmps; - p->pulsbuf[0] = pulsbuf; pulsbuf += maxprd; - p->pulsbuf[1] = pulsbuf; pulsbuf += maxprd; - p->pulsbuf[2] = pulsbuf; pulsbuf += maxprd; - p->pulsbuf[3] = pulsbuf; pulsbuf += maxprd; /* cnt must = PBUFS */ - p->sigmoid = sigp = pulsbuf; + csound->AuxAlloc(csound, totalsiz * sizeof(MYFLT), &q->auxch); + q->bufp = (MYFLT *) q->auxch.auxp; + q->midp = q->bufp + nbufsmps; /* each >= maxprd * 3 */ + pulsbuf = q->midp + nbufsmps; + q->pulsbuf[0] = pulsbuf; pulsbuf += maxprd; + q->pulsbuf[1] = pulsbuf; pulsbuf += maxprd; + q->pulsbuf[2] = pulsbuf; pulsbuf += maxprd; + q->pulsbuf[3] = pulsbuf; pulsbuf += maxprd; /* cnt must = PBUFS */ + q->sigmoid = sigp = pulsbuf; for (cnt = 0; cnt < SLEN+1; cnt++) /* make sigmoid inplace */ *sigp++ = (FL(1.0) - COS(PI_F * cnt / SLEN)) * FL(0.5); - p->maxprd = maxprd; - p->nbufsmps = nbufsmps; - p->n2bufsmps = nbufsmps * 2; - p->minoct = minoct; + q->maxprd = maxprd; + q->nbufsmps = nbufsmps; + q->n2bufsmps = nbufsmps * 2; } - p->sicvt = FL(65536.0) * csound->onedsr; - p->cpsmode = ((*p->icpsmode != FL(0.0))); - p->polarity = (int16)*p->ipolarity; - p->poslead = 0; - p->inp1 = p->bufp; - p->inp2 = p->midp; - p->endp = p->puldat; /* nothing in PULDAT array */ - p->limp = p->puldat + PULMAX; - p->prvoct = FL(0.0); - p->period = 0; - p->curpuls = NULL; - p->pbufcnt = 0; - p->vocamp = FL(0.0); /* begin unvoiced */ - p->ampinc = FL(10.0) * csound->onedsr; /* .1 sec lin ramp for uv to v */ - p->switching = 0; + q->minoct = minoct; + q->sicvt = FL(65536.0) * csound->onedsr; + q->cpsmode = ((*q->icpsmode != FL(0.0))); + q->polarity = (int16)*q->ipolarity; + q->poslead = 0; + q->inp1 = q->bufp; + q->inp2 = q->midp; + q->endp = q->puldat; /* nothing in PULDAT array */ + q->limp = q->puldat + PULMAX; + q->prvoct = FL(0.0); + q->period = 0; + q->curpuls = NULL; + q->pbufcnt = 0; + q->vocamp = FL(0.0); /* begin unvoiced */ + q->ampinc = FL(10.0) * csound->onedsr; /* .1 sec lin ramp for uv to v */ + q->switching = 0; return OK; } -static int harmon234(CSOUND *csound, HARM234 *p) +static int harmon234(CSOUND *csound, HARM234 *q, HARMON2 *p) { - MYFLT *srcp, *outp, *dirp; + MYFLT *outp, *dirp; // *srcp, MYFLT *inp1, *inp2; MYFLT koct, vocamp, diramp; PULDAT *endp; VOCDAT *vdp; - int16 nsmps, oflow = 0; + int16 nsmps = CS_KSMPS, oflow = 0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; - if ((koct = *p->koct) != p->prvoct) { /* if new pitch estimate */ - if (koct >= p->minoct) { /* above requested low */ + if ((koct = *q->koct) != q->prvoct) { /* if new pitch estimate */ + if (koct >= q->minoct) { /* above requested low */ MYFLT cps = POWER(FL(2.0), koct) * ONEPT; /* recalc pulse period */ - p->period = (int16) (csound->esr / cps); - if (!p->cpsmode) - p->sicvt = cps * FL(65536.0) * csound->onedsr; /* k64dsr;*/ + q->period = (int16) (CS_ESR / cps); + if (!q->cpsmode) + q->sicvt = cps * FL(65536.0) * csound->onedsr; /* k64dsr;*/ } - p->prvoct = koct; + q->prvoct = koct; } - inp1 = p->inp1; - inp2 = p->inp2; - //memcpy(p->inp1, p->asig, sizeof(MYFLT)*nsmps); - //memcpy(p->inp2, p->asig, sizeof(MYFLT)*nsmps); - for (srcp = p->asig, nsmps = csound->ksmps; nsmps--; ) - *inp1++ = *inp2++ = *srcp++; /* dbl store the wavform */ + inp1 = q->inp1; + inp2 = q->inp2; + if (UNLIKELY(offset)) { + memset(inp1, '\0', offset*sizeof(MYFLT)); + memset(inp2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&inp1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&inp2[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&inp1[offset], &q->asig[offset], sizeof(MYFLT)*(nsmps-offset)); + memcpy(&inp2[offset], &q->asig[offset], sizeof(MYFLT)*(nsmps-offset)); + //for (srcp = q->asig, nsmps = CS_KSMPS; nsmps--; ) + // *inp1++ = *inp2++ = *srcp++; /* dbl store the wavform */ - if (koct >= p->minoct) { /* PERIODIC: find the pulse */ + if (koct >= q->minoct) { /* PERIODIC: find the pulse */ MYFLT val0, *buf0, *p0, *plim, *x; int16 period, triprd, xdist; - period = p->period; /* set srch range of 2 periods */ + period = q->period; /* set srch range of 2 periods */ triprd = period * 3; p0 = inp2 - triprd; /* btwn 3 prds back & 1 prd back */ plim = inp2 - period; - buf0 = p->bufp; + buf0 = q->bufp; if (UNLIKELY(p0 < buf0)) p0 = buf0; @@ -171,7 +183,7 @@ else while (*x < FL(0.0) && ++x < plim); if (x >= plim) goto nonprd; /* then non-periodic */ - if (p->polarity > 0) { + if (q->polarity > 0) { MYFLT pospk = FL(0.0); /* POSITIVE polarity: */ MYFLT *posp = NULL; for ( ; x < plim; x++) { /* find ensuing max val */ @@ -183,7 +195,8 @@ for (x = posp; x >= buf0 && *x > FL(0.0); x--); /* & its preceding z-crossing */ xdist = posp - x; - } else if (p->polarity < 0) { + } + else if (q->polarity < 0) { MYFLT negpk = FL(0.0); /* NEGATIVE polarity: */ MYFLT *negp = NULL; for ( ; x < plim; x++) { /* find ensuing min val */ @@ -221,20 +234,20 @@ if (pospk / posdist > -negpk / negdist) { /* find z-cross with grtst slope to peak */ - if (UNLIKELY(p->poslead < LCNT)) { /* and consistent polarity */ - if (p->poslead == 1) + if (UNLIKELY(q->poslead < LCNT)) { /* and consistent polarity */ + if (q->poslead == 1) csound->Warning(csound, Str("harm signal has positive lead\n")); - p->poslead += 1; + q->poslead += 1; } } else { - if (UNLIKELY(p->poslead > -LCNT)) { - if (p->poslead == -1) + if (UNLIKELY(q->poslead > -LCNT)) { + if (q->poslead == -1) csound->Warning(csound, Str("harm signal has negative lead\n")); - p->poslead -= 1; + q->poslead -= 1; } } - if (p->poslead >= 0) { /* use this as pulse beginning */ + if (q->poslead >= 0) { /* use this as pulse beginning */ x = poscross; xdist = posdist; } @@ -244,12 +257,12 @@ } } - if (x != p->curpuls) { /* if pulse positn is new */ + if (x != q->curpuls) { /* if pulse positn is new */ int16 nn, pulslen, sigdist, ndirect; MYFLT *bufp, signdx, siginc; MYFLT *z, zval; - p->curpuls = x; /* record this new positn */ + q->curpuls = x; /* record this new positn */ z = x + period; /* and from estimated end */ if ((zval = *z) != FL(0.0)) { int16 n, nlim = inp2 - z; @@ -270,19 +283,19 @@ else if (z > inp2) z = inp2; /* by input limits */ pulslen = z - x; - if (pulslen > p->maxprd) - pulslen = p->maxprd; /* & storage limits */ + if (pulslen > q->maxprd) + pulslen = q->maxprd; /* & storage limits */ sigdist = xdist * 2; ndirect = pulslen - sigdist*2; if (ndirect < 0) goto nostor; - p->pbufcnt++; /* select a new puls buffr */ - p->pbufcnt &= PBMSK; - bufp = p->pulsbuf[p->pbufcnt]; + q->pbufcnt++; /* select a new puls buffr */ + q->pbufcnt &= PBMSK; + bufp = q->pulsbuf[q->pbufcnt]; signdx = FL(0.0); /* & store extended pulse */ siginc = (MYFLT)SLEN / sigdist; for (nn = sigdist; nn--; signdx += siginc) { - MYFLT *sigp = p->sigmoid + (int)signdx; + MYFLT *sigp = q->sigmoid + (int)signdx; *bufp++ = *x++ * *sigp; /* w. sigmoid-envlpd ends */ } //memcpy(bufp, x, sizeof(MYFLT)*ndirect); @@ -290,36 +303,35 @@ *bufp++ = *x++; signdx = (MYFLT)SLEN - siginc; for (nn = sigdist; nn--; signdx -= siginc) { - MYFLT *sigp = p->sigmoid + (int)signdx; + MYFLT *sigp = q->sigmoid + (int)signdx; *bufp++ = *x++ * *sigp; } - p->pulslen = pulslen; + q->pulslen = pulslen; } nostor: - if (p->vocamp < FL(1.0)) { /* if onset */ - p->vocinc = p->ampinc; /* set pos voice ramp */ - p->switching = 1; + if (q->vocamp < FL(1.0)) { /* if onset */ + q->vocinc = q->ampinc; /* set pos voice ramp */ + q->switching = 1; } } else { /* NON-PERIODIC: */ nonprd: - if (p->vocamp > FL(0.0)) { /* if onset */ - p->vocinc = -p->ampinc; /* set neg voice ramp */ - p->switching = 1; + if (q->vocamp > FL(0.0)) { /* if onset */ + q->vocinc = -q->ampinc; /* set neg voice ramp */ + q->switching = 1; } - p->curpuls = NULL; /* start no new pulses */ + q->curpuls = NULL; /* start no new pulses */ } /* HARMONIZER */ - for (vdp=p->vocdat; vdpvlim; vdp++) /* get new frequencies */ - vdp->phsinc = (int32)(*vdp->kfrq * p->sicvt); - outp = p->ar; - nsmps = csound->ksmps; - vocamp = p->vocamp; + for (vdp=q->vocdat; vdpvlim; vdp++) /* get new frequencies */ + vdp->phsinc = (int32)(*vdp->kfrq * q->sicvt); + outp = q->ar; + vocamp = q->vocamp; diramp = FL(1.0) - vocamp; - dirp = p->asig; - endp = p->endp; + dirp = q->asig; + endp = q->endp; do { /* insert pulses into output: */ MYFLT sum = FL(0.0); - PULDAT *pdp = p->puldat; + PULDAT *pdp = q->puldat; while (pdp < endp) { addin: sum += *pdp->srcp++; /* get any ongoing pulsdata */ @@ -332,47 +344,47 @@ } pdp++; } /* if time to start a new one */ - for (vdp=p->vocdat; vdpvlim; vdp++) + for (vdp=q->vocdat; vdpvlim; vdp++) if (vdp->phsinc && (vdp->phase += vdp->phsinc) & (~0xFFFF)) { vdp->phase &= 0x0000FFFFL; - if (p->curpuls != NULL) { /* & pulses are current */ - if (endp < p->limp) { /* set one up */ - endp->srcp = p->pulsbuf[p->pbufcnt]; - endp->cntr = p->pulslen; /* w. extended len */ + if (q->curpuls != NULL) { /* & pulses are current */ + if (endp < q->limp) { /* set one up */ + endp->srcp = q->pulsbuf[q->pbufcnt]; + endp->cntr = q->pulslen; /* w. extended len */ endp++; } else oflow = 1; } } - if (p->switching) { /* if v/uv switching */ - vocamp += p->vocinc; /* do linear ramp */ + if (q->switching) { /* if v/uv switching */ + vocamp += q->vocinc; /* do linear ramp */ if (vocamp <= FL(0.0)) { vocamp = FL(0.0); - p->switching = 0; + q->switching = 0; } else if (vocamp >= FL(1.0)) { vocamp = FL(1.0); - p->switching = 0; + q->switching = 0; } diramp = FL(1.0) - vocamp; } *outp++ = sum * vocamp + *dirp++ * diramp; /* output combined */ } while (--nsmps); - p->endp = endp; - p->vocamp = vocamp; + q->endp = endp; + q->vocamp = vocamp; - if (UNLIKELY(oflow && ++p->hmrngflg > 10)) { + if (UNLIKELY(oflow && ++q->hmrngflg > 10)) { csound->Warning(csound, Str("harmon234: out of range\n")); - p->hmrngflg = 0; + q->hmrngflg = 0; } - if (inp1 >= p->midp) { /* if end of pq bufs */ - int32 bsmps = p->nbufsmps; - p->inp1 = p->bufp; /* reset all ptrs */ - p->inp2 = p->midp; - if (p->curpuls != NULL) - p->curpuls -= bsmps; + if (inp1 >= q->midp) { /* if end of pq bufs */ + int32 bsmps = q->nbufsmps; + q->inp1 = q->bufp; /* reset all ptrs */ + q->inp2 = q->midp; + if (q->curpuls != NULL) + q->curpuls -= bsmps; } else { - p->inp1 = inp1; - p->inp2 = inp2; + q->inp1 = inp1; + q->inp2 = inp2; } return OK; } @@ -390,7 +402,7 @@ q->icpsmode = p->icpsmode; q->ilowest = p->ilowest; q->ipolarity = p->ipolarity; - return hm234set(csound, q); + return hm234set(csound, q, p); } int harm3set(CSOUND *csound, HARMON3 *p) @@ -407,7 +419,7 @@ q->icpsmode = p->icpsmode; q->ilowest = p->ilowest; q->ipolarity = p->ipolarity; - return hm234set(csound, q); + return hm234set(csound, q, (HARMON2*)p); } int harm4set(CSOUND *csound, HARMON4 *p) @@ -425,20 +437,25 @@ q->icpsmode = p->icpsmode; q->ilowest = p->ilowest; q->ipolarity = p->ipolarity; - return hm234set(csound, q); + return hm234set(csound, q, (HARMON2*)p); } -int harmon2(CSOUND *csound, HARMON2 *p) { return harmon234(csound, &p->hrmdat);} -int harmon3(CSOUND *csound, HARMON3 *p) { return harmon234(csound, &p->hrmdat);} -int harmon4(CSOUND *csound, HARMON4 *p) { return harmon234(csound, &p->hrmdat);} +int harmon2(CSOUND *csound, HARMON2 *p) +{ return harmon234(csound, &p->hrmdat, p);} +int harmon3(CSOUND *csound, HARMON3 *p) +{ return harmon234(csound, &p->hrmdat, (HARMON2*)p);} +int harmon4(CSOUND *csound, HARMON4 *p) +{ return harmon234(csound, &p->hrmdat, (HARMON2*)p);} #define S(x) sizeof(x) static OENTRY harmon_localops[] = { - { "harmon2",S(HARMON2),5, "a", "akkkiip", (SUBR)harm2set,NULL, (SUBR)harmon2 }, - { "harmon3",S(HARMON3),5, "a", "akkkkiip", (SUBR)harm3set,NULL, (SUBR)harmon3 }, - { "harmon4",S(HARMON4),5, "a", "akkkkkiip",(SUBR)harm4set,NULL, (SUBR)harmon4 }, + { "harmon2",S(HARMON2),0, 5, "a", "akkkiip", + (SUBR)harm2set,NULL, (SUBR)harmon2 }, + { "harmon3",S(HARMON3),0, 5, "a", "akkkkiip", + (SUBR)harm3set,NULL, (SUBR)harmon3 }, + { "harmon4",S(HARMON4),0, 5, "a", + "akkkkkiip",(SUBR)harm4set,NULL, (SUBR)harmon4 }, }; -LINKAGE1(harmon_localops) - +LINKAGE_BUILTIN(harmon_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/hrtfearly.c csound-6.02~dfsg/Opcodes/hrtfearly.c --- csound-5.17.11~dfsg/Opcodes/hrtfearly.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/hrtfearly.c 2014-01-07 16:53:48.000000000 +0000 @@ -1,24 +1,24 @@ /* -Brian Carty -PhD Code August 2010 -binaural reverb: early reflections - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + Brian Carty + PhD Code August 2010 + binaural reverb: early reflections + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ /* #include "csdl.h" */ @@ -68,7 +68,7 @@ MYFLT freq; MYFLT check; MYFLT scale, nyqresponse, irttwo, highresponse, lowresponse, cosw, - a, b, c, x, y; + a, b, c, x, y; irttwo = FL(1.0) / SQRT(FL(2.0)); @@ -79,7 +79,7 @@ scale = lowresponse; nyqresponse = highresponse + lowcoeff; /* should always be lowpass! */ - if(nyqresponse > irttwo) + if (nyqresponse > irttwo) nyqresponse = irttwo; /* calculate cutoff, according to nyqresponse */ @@ -97,7 +97,7 @@ check = FL(2.0) - y; /* check for legal acos arg */ - if(check < -FL(1.0)) + if (check < -FL(1.0)) check = -FL(1.0); freq = FL(acos(check)); freq /= twopioversr; @@ -145,85 +145,86 @@ typedef struct { - OPDS h; - /* out l/r, low rt60, high rt60, amp, delay for latediffuse */ - MYFLT *outsigl, *outsigr, *irt60low, *irt60high, *imfp; - /* input, source, listener, hrtf files, default room, [fadelength, - sr, order, threed, headrot, roomsize, wall high and low absorb - coeffs, gain for 3 band pass, same for floor and ceiling] */ - MYFLT *in, *srcx, *srcy, *srcz, *lstnrx, *lstnry, *lstnrz, *ifilel, *ifiler, - *idefroom, *ofade, *osr, *porder, *othreed, *Oheadrot, - *ormx, *ormy, *ormz, *owlh, *owll, *owlg1, *owlg2, *owlg3, *oflh, - *ofll, *oflg1, *oflg2, *oflg3,*oclh, *ocll, *oclg1, *oclg2, *oclg3; - - /* check if relative source has changed, to avoid recalculations */ - MYFLT srcxv, srcyv, srczv, lstnrxv, lstnryv, lstnrzv; - MYFLT srcxk, srcyk, srczk, lstnrxk, lstnryk, lstnrzk; - MYFLT rotatev; - - /* processing buffer sizes, depends on sr */ - int irlength, irlengthpad, overlapsize; - MYFLT sr; - int counter; - - /* crossfade preparation and checks */ - int fade, fadebuffer; - int initialfade; - - /* interpolation buffer declaration */ - AUXCH lowl1, lowr1, lowl2, lowr2; - AUXCH highl1, highr1, highl2, highr2; - AUXCH hrtflinterp, hrtfrinterp, hrtflpad, hrtfrpad; - AUXCH hrtflpadold, hrtfrpadold; - - /* convolution and in/output buffers */ - AUXCH inbuf,inbufpad; - AUXCH outlspec, outrspec; - AUXCH outlspecold, outrspecold; - AUXCH overlapl, overlapr; - AUXCH overlaplold, overlaprold; - - /* no of impulses based on order */ - int impulses, order; - int M; - /* 3d check*/ - int threed; - - /* speed of sound*/ - MYFLT c; - - /* Image Model*/ - MYFLT rmx, rmy, rmz; - int maxdelsamps; - - /* for each reflection*/ - AUXCH hrtflpadspec, hrtfrpadspec, hrtflpadspecold, hrtfrpadspecold; - AUXCH outl, outr, outlold, outrold; - AUXCH currentphasel, currentphaser; - AUXCH dell, delr; - AUXCH tempsrcx, tempsrcy, tempsrcz; - AUXCH dist; - AUXCH dtime; - AUXCH amp; - - /* temp o/p buffers */ - AUXCH predell, predelr; - - /* processing values that need to be kept for each reflection*/ - /* dynamic values based on no. fo impulses*/ - AUXCH oldelevindex, oldangleindex; - AUXCH cross, l, delp, skipdel; - AUXCH vdt; - - /* wall details */ - MYFLT wallcoeflow, wallcoefhigh, wallg1, wallg2, wallg3; - MYFLT floorcoeflow, floorcoefhigh, floorg1, floorg2, floorg3; - MYFLT ceilingcoeflow, ceilingcoefhigh, ceilingg1, ceilingg2, ceilingg3; - /* wall filter q*/ - MYFLT q; + OPDS h; + /* out l/r, low rt60, high rt60, amp, delay for latediffuse */ + MYFLT *outsigl, *outsigr, *irt60low, *irt60high, *imfp; + /* input, source, listener, hrtf files, default room, [fadelength, + sr, order, threed, headrot, roomsize, wall high and low absorb + coeffs, gain for 3 band pass, same for floor and ceiling] */ + MYFLT *in, *srcx, *srcy, *srcz, *lstnrx, *lstnry, *lstnrz; + STRINGDAT *ifilel, *ifiler; + MYFLT *idefroom, *ofade, *osr, *porder, *othreed, *Oheadrot, + *ormx, *ormy, *ormz, *owlh, *owll, *owlg1, *owlg2, *owlg3, *oflh, + *ofll, *oflg1, *oflg2, *oflg3,*oclh, *ocll, *oclg1, *oclg2, *oclg3; + + /* check if relative source has changed, to avoid recalculations */ + MYFLT srcxv, srcyv, srczv, lstnrxv, lstnryv, lstnrzv; + MYFLT srcxk, srcyk, srczk, lstnrxk, lstnryk, lstnrzk; + MYFLT rotatev; + + /* processing buffer sizes, depends on sr */ + int irlength, irlengthpad, overlapsize; + MYFLT sr; + int counter; + + /* crossfade preparation and checks */ + int fade, fadebuffer; + int initialfade; + + /* interpolation buffer declaration */ + AUXCH lowl1, lowr1, lowl2, lowr2; + AUXCH highl1, highr1, highl2, highr2; + AUXCH hrtflinterp, hrtfrinterp, hrtflpad, hrtfrpad; + AUXCH hrtflpadold, hrtfrpadold; + + /* convolution and in/output buffers */ + AUXCH inbuf,inbufpad; + AUXCH outlspec, outrspec; + AUXCH outlspecold, outrspecold; + AUXCH overlapl, overlapr; + AUXCH overlaplold, overlaprold; + + /* no of impulses based on order */ + int impulses, order; + int M; + /* 3d check*/ + int threed; + + /* speed of sound*/ + MYFLT c; + + /* Image Model*/ + MYFLT rmx, rmy, rmz; + int maxdelsamps; + + /* for each reflection*/ + AUXCH hrtflpadspec, hrtfrpadspec, hrtflpadspecold, hrtfrpadspecold; + AUXCH outl, outr, outlold, outrold; + AUXCH currentphasel, currentphaser; + AUXCH dell, delr; + AUXCH tempsrcx, tempsrcy, tempsrcz; + AUXCH dist; + AUXCH dtime; + AUXCH amp; + + /* temp o/p buffers */ + AUXCH predell, predelr; + + /* processing values that need to be kept for each reflection*/ + /* dynamic values based on no. fo impulses*/ + AUXCH oldelevindex, oldangleindex; + AUXCH cross, l, delp, skipdel; + AUXCH vdt; + + /* wall details */ + MYFLT wallcoeflow, wallcoefhigh, wallg1, wallg2, wallg3; + MYFLT floorcoeflow, floorcoefhigh, floorg1, floorg2, floorg3; + MYFLT ceilingcoeflow, ceilingcoefhigh, ceilingg1, ceilingg2, ceilingg3; + /* wall filter q*/ + MYFLT q; - /* file pointers*/ - float *fpbeginl, *fpbeginr; + /* file pointers*/ + float *fpbeginl, *fpbeginr; } early; @@ -276,47 +277,45 @@ int order = (int)*p->porder; /* fade length: default 8, max 24, min 1 (fade is a local variable)*/ - if(fade < 1 || fade > 24) + if (fade < 1 || fade > 24) fade = 8; p->fade = fade; /* threed defaults to 2d! */ - if(threed < 0 || threed > 1) + if (threed < 0 || threed > 1) threed = 0; p->threed = threed; /* order: max 4, default 1 */ - if(order < 0 || order > 4) + if (order < 0 || order > 4) order = 1; p->order = order; /* sr, defualt 44100 */ - if(sr != 44100 && sr != 48000 && sr != 96000) + if (sr != 44100 && sr != 48000 && sr != 96000) sr = 44100; p->sr = sr; - if (UNLIKELY(csound->esr != sr)) + if (UNLIKELY(CS_ESR != sr)) csound->Message(csound, Str("\n\nWARNING!!:\nOrchestra SR not compatible " "with HRTF processing SR of: %.0f\n\n"), sr); /* setup as per sr */ - if(sr == 44100 || sr == 48000) - { - irlength = 128; - irlengthpad = 256; - overlapsize = (irlength - 1); - } - else if(sr == 96000) - { - irlength = 256; - irlengthpad = 512; - overlapsize = (irlength - 1); - } + if (sr == 44100 || sr == 48000) { + irlength = 128; + irlengthpad = 256; + overlapsize = (irlength - 1); + } + else if (sr == 96000) { + irlength = 256; + irlengthpad = 512; + overlapsize = (irlength - 1); + } /* copy in string name...*/ - strncpy(filel, (char*) p->ifilel, MAXNAME); - strncpy(filer, (char*) p->ifiler, MAXNAME); + strncpy(filel, (char*) p->ifilel->data, MAXNAME); + strncpy(filer, (char*) p->ifiler->data, MAXNAME); /* reading files, with byte swap */ fpl = csound->ldmemfile2withCB(csound, filel, CSFTYPE_FLOATS_BINARY, @@ -353,95 +352,89 @@ defroom = (int)*p->idefroom; /* 3 default rooms allowed*/ - if(defroom > 3) + if (defroom > 3) defroom = 1; /* setup wall coeffs: walls: plasterboard, ceiling: painted plaster, floor: carpet if any default room is chosen, default parameters for walls/ceiling/floor */ - if(defroom) - { - p->wallcoefhigh = FL(0.3); - p->wallcoeflow = FL(0.1); - p->wallg1 = FL(0.75); - p->wallg2 = FL(0.95); - p->wallg3 = FL(0.9); - p->floorcoefhigh = FL(0.6); - p->floorcoeflow = FL(0.1); - p->floorg1 = FL(0.95); - p->floorg2 = FL(0.6); - p->floorg3 = FL(0.35); - p->ceilingcoefhigh = FL(0.2); - p->ceilingcoeflow = FL(0.1); - p->ceilingg1 = FL(1.0); - p->ceilingg2 = FL(1.0); - p->ceilingg3 = FL(1.0); - } + if (defroom) { + p->wallcoefhigh = FL(0.3); + p->wallcoeflow = FL(0.1); + p->wallg1 = FL(0.75); + p->wallg2 = FL(0.95); + p->wallg3 = FL(0.9); + p->floorcoefhigh = FL(0.6); + p->floorcoeflow = FL(0.1); + p->floorg1 = FL(0.95); + p->floorg2 = FL(0.6); + p->floorg3 = FL(0.35); + p->ceilingcoefhigh = FL(0.2); + p->ceilingcoeflow = FL(0.1); + p->ceilingg1 = FL(1.0); + p->ceilingg2 = FL(1.0); + p->ceilingg3 = FL(1.0); + } /* otherwise use values, if valid */ - else - { - p->wallcoefhigh = (*p->owlh > FL(0.0) && *p->owlh < FL(1.0)) ? - *p->owlh : FL(0.3); - p->wallcoeflow = (*p->owll > FL(0.0) && *p->owll < FL(1.0)) ? - *p->owll : FL(0.1); - p->wallg1 = (*p->owlg1 > FL(0.0) && *p->owlg1 < FL(10.0)) ? - *p->owlg1 : FL(0.75); - p->wallg2 = (*p->owlg2 > FL(0.0) && *p->owlg2 < FL(10.0)) ? - *p->owlg2 : FL(0.95); - p->wallg3 = (*p->owlg3 > FL(0.0) && *p->owlg3 < FL(10.0)) ? - *p->owlg3 : FL(0.9); - p->floorcoefhigh = (*p->oflh > FL(0.0) && *p->oflh < FL(1.0)) ? - *p->oflh : FL(0.6); - p->floorcoeflow = (*p->ofll > FL(0.0) && *p->ofll < FL(1.0)) ? - *p->ofll : FL(0.1); - p->floorg1 = (*p->oflg1 > FL(0.0) && *p->oflg1 < FL(10.0)) ? - *p->oflg1 : FL(0.95); - p->floorg2 = (*p->oflg2 > FL(0.0) && *p->oflg2 < FL(10.0)) ? - *p->oflg2 : FL(0.6); - p->floorg3 = (*p->oflg3 > FL(0.0) && *p->oflg3 < FL(10.0)) ? - *p->oflg3 : FL(0.35); - p->ceilingcoefhigh = (*p->oclh > FL(0.0) && *p->oclh < FL(1.0)) ? - *p->oclh : FL(0.2); - p->ceilingcoeflow = (*p->ocll > FL(0.0) && *p->ocll < FL(1.0)) ? - *p->ocll : FL(0.1); - p->ceilingg1 = (*p->oclg1 > FL(0.0) && *p->oclg1 < FL(10.0)) ? - *p->oclg1 : FL(1.0); - p->ceilingg2 = (*p->oclg2 > FL(0.0) && *p->oclg2 < FL(10.0)) ? - *p->oclg2 : FL(1.0); - p->ceilingg3 = (*p->oclg3 > FL(0.0) && *p->oclg3 < FL(10.0)) ? - *p->oclg3 : FL(1.0); - } + else { + p->wallcoefhigh = (*p->owlh > FL(0.0) && *p->owlh < FL(1.0)) ? + *p->owlh : FL(0.3); + p->wallcoeflow = (*p->owll > FL(0.0) && *p->owll < FL(1.0)) ? + *p->owll : FL(0.1); + p->wallg1 = (*p->owlg1 > FL(0.0) && *p->owlg1 < FL(10.0)) ? + *p->owlg1 : FL(0.75); + p->wallg2 = (*p->owlg2 > FL(0.0) && *p->owlg2 < FL(10.0)) ? + *p->owlg2 : FL(0.95); + p->wallg3 = (*p->owlg3 > FL(0.0) && *p->owlg3 < FL(10.0)) ? + *p->owlg3 : FL(0.9); + p->floorcoefhigh = (*p->oflh > FL(0.0) && *p->oflh < FL(1.0)) ? + *p->oflh : FL(0.6); + p->floorcoeflow = (*p->ofll > FL(0.0) && *p->ofll < FL(1.0)) ? + *p->ofll : FL(0.1); + p->floorg1 = (*p->oflg1 > FL(0.0) && *p->oflg1 < FL(10.0)) ? + *p->oflg1 : FL(0.95); + p->floorg2 = (*p->oflg2 > FL(0.0) && *p->oflg2 < FL(10.0)) ? + *p->oflg2 : FL(0.6); + p->floorg3 = (*p->oflg3 > FL(0.0) && *p->oflg3 < FL(10.0)) ? + *p->oflg3 : FL(0.35); + p->ceilingcoefhigh = (*p->oclh > FL(0.0) && *p->oclh < FL(1.0)) ? + *p->oclh : FL(0.2); + p->ceilingcoeflow = (*p->ocll > FL(0.0) && *p->ocll < FL(1.0)) ? + *p->ocll : FL(0.1); + p->ceilingg1 = (*p->oclg1 > FL(0.0) && *p->oclg1 < FL(10.0)) ? + *p->oclg1 : FL(1.0); + p->ceilingg2 = (*p->oclg2 > FL(0.0) && *p->oclg2 < FL(10.0)) ? + *p->oclg2 : FL(1.0); + p->ceilingg3 = (*p->oclg3 > FL(0.0) && *p->oclg3 < FL(10.0)) ? + *p->oclg3 : FL(1.0); + } /* medium room */ - if(defroom == 1) - { - rmx = 10; - rmy = 10; - rmz = 3; - } + if (defroom == 1) { + rmx = 10; + rmy = 10; + rmz = 3; + } /* small */ - else if(defroom == 2) - { - rmx = 3; - rmy = 4; - rmz = 3; - } + else if (defroom == 2) { + rmx = 3; + rmy = 4; + rmz = 3; + } /* large */ - else if(defroom == 3) - { - rmx = 20; - rmy = 25; - rmz = 7; - } + else if (defroom == 3) { + rmx = 20; + rmy = 25; + rmz = 7; + } /* read values if they exist, use medium if not valid (must be at least a 2*2*2 room! */ - else - { - rmx = *p->ormx >= FL(2.0) ? *p->ormx : 10; - rmy = *p->ormy >= FL(2.0) ? *p->ormy : 10; - rmz = *p->ormz >= FL(2.0) ? *p->ormz : 4; - } + else { + rmx = *p->ormx >= FL(2.0) ? *p->ormx : 10; + rmy = *p->ormy >= FL(2.0) ? *p->ormy : 10; + rmz = *p->ormz >= FL(2.0) ? *p->ormz : 4; + } /* store */ p->rmx = rmx; @@ -449,12 +442,12 @@ p->rmz = rmz; /* how many sources? */ - if(threed) + if (threed) { for(i = 1; i <= order; i++) { impulses += (4 * i); - if(i <= (order - 1)) + if (i <= (order - 1)) /* sources = 2d impulses for order, plus 2 * each preceding no of impulses eg order 2: 2d = 1 + 4 + 8 = 13, 3d + 2*5 + 2 = 25*/ @@ -731,7 +724,7 @@ /* use hypotenuse rule to get max dist */ /* could calculate per order, but designed for low order use */ maxdist = (SQRT(SQUARE(rmx) + SQUARE(rmy))); - if(threed) + if (threed) maxdist = (SQRT(SQUARE(maxdist)+SQUARE(rmz))); maxdist = maxdist * (order + 1); @@ -784,7 +777,10 @@ static int early_process(CSOUND *csound, early *p) { /* iterators */ - int n, i, j; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t j, nsmps = CS_KSMPS; /* local pointers to p */ MYFLT *in = p->in; @@ -815,7 +811,7 @@ MYFLT *hrtflpadold = (MYFLT *)p->hrtflpadold.auxp; MYFLT *hrtfrpadold = (MYFLT *)p->hrtfrpadold.auxp; - /* pointers into HRTF files: floating point data(even in 64 bit csound)*/ + /* pointers into HRTF files: floating point data(even in 64 bit csound) */ float *fpindexl = (float *)p->fpbeginl; float *fpindexr = (float *)p->fpbeginr; @@ -937,33 +933,33 @@ MYFLT coselev; /* processing size! */ - n = csound->ksmps; + //n = CS_KSMPS; /* check for legal src/lstnr locations */ /* restricted to being inside room! */ - if(srcx > (rmx - FL(0.1))) + if (srcx > (rmx - FL(0.1))) srcx = rmx - FL(0.1); - if(srcx < FL(0.1)) + if (srcx < FL(0.1)) srcx = FL(0.1); - if(srcy > (rmy - FL(0.1))) + if (srcy > (rmy - FL(0.1))) srcy = rmy - FL(0.1); - if(srcy < FL(0.1)) + if (srcy < FL(0.1)) srcy = FL(0.1); - if(srcz > (rmz - FL(0.1))) + if (srcz > (rmz - FL(0.1))) srcz = rmz - FL(0.1); - if(srcz < FL(0.1)) + if (srcz < FL(0.1)) srcz = FL(0.1); - if(lstnrx > (rmx - FL(0.1))) + if (lstnrx > (rmx - FL(0.1))) lstnrx = rmx - FL(0.1); - if(lstnrx < FL(0.1)) + if (lstnrx < FL(0.1)) lstnrx = FL(0.1); - if(lstnry > (rmy - FL(0.1))) + if (lstnry > (rmy - FL(0.1))) lstnry = rmy - FL(0.1); - if(lstnry < FL(0.1)) + if (lstnry < FL(0.1)) lstnry = FL(0.1); - if(lstnrz > (rmz - FL(0.1))) + if (lstnrz > (rmz - FL(0.1))) lstnrz = rmz - FL(0.1); - if(lstnrz < FL(0.1)) + if (lstnrz < FL(0.1)) lstnrz = FL(0.1); /* k rate computations: sources, distances, delays, amps @@ -972,853 +968,835 @@ /* only update if relative source updates! improves speed in static sources by a factor of 2-3! */ - if(srcx != p->srcxk || srcy != p->srcyk || srcz != p->srczk || - lstnrx != p->lstnrxk || lstnry != p->lstnryk || lstnrz != p->lstnrzk) - { - p->srcxk = srcx; - p->srcyk = srcy; - p->srczk = srcz; - p->lstnrxk = lstnrx; - p->lstnryk = lstnry; - p->lstnrzk = lstnrz; - - for(xc = -order; xc <= order; xc++) - { - for(yc = abs(xc) - order; yc <= order - abs(xc); yc++) - { - /* only scroll through z plane if 3d required...*/ - if(threed) - { - lowz = abs(yc) - (order - abs(xc)); - highz = (order - abs(xc)) - abs(yc); - } - else - { - lowz = 0; - highz = 0; - } - for(zc = lowz; zc <= highz; zc++) - { - /* to avoid recalculation, especially at audio rate - for delay, later on */ - formxpow = (int)pow(-1.0, xc); - formypow = (int)pow(-1.0, yc); - formzpow = (int)pow(-1.0, zc); - formx = (xc + (1 - formxpow)/2) * rmx; - formy = (yc + (1 - formypow)/2) * rmy; - formz = (zc + (1 - formzpow)/2) * rmz; - - /* image */ - tempsrcx[M] = formxpow * srcx + formx; - tempsrcy[M] = formypow * srcy + formy; - tempsrcz[M] = formzpow * srcz + formz; - - /* Calculate delay here using source and listener location */ - dist[M] = (SQRT(SQUARE(tempsrcx[M] - lstnrx) + - SQUARE(tempsrcy[M] - lstnry) + - SQUARE(tempsrcz[M] - lstnrz))); - - /* in seconds... */ - dtime[M] = dist[M] / c; - - /* furthest allowable distance....max amp = 1. */ - tempdist = (dist[M] < FL(0.45) ? FL(0.45) : dist[M]); - - /* high amp value may cause clipping on early - reflections...reduce overall amp if so...*/ - /* SPL inverse distance law */ - amp[M] = FL(0.45) / tempdist; - - /* vdels for distance processing: */ - vdt[M] = dtime[M] * sr; - if(vdt[M] > maxdelsamps) - vdt[M] = (MYFLT)maxdelsamps; + if (srcx != p->srcxk || srcy != p->srcyk || srcz != p->srczk || + lstnrx != p->lstnrxk || lstnry != p->lstnryk || lstnrz != p->lstnrzk) { + p->srcxk = srcx; + p->srcyk = srcy; + p->srczk = srcz; + p->lstnrxk = lstnrx; + p->lstnryk = lstnry; + p->lstnrzk = lstnrz; + + for (xc = -order; xc <= order; xc++) { + for (yc = abs(xc) - order; yc <= order - abs(xc); yc++) { + /* only scroll through z plane if 3d required...*/ + if (threed) { + lowz = abs(yc) - (order - abs(xc)); + highz = (order - abs(xc)) - abs(yc); + } + else { + lowz = 0; + highz = 0; + } + for (zc = lowz; zc <= highz; zc++) { + /* to avoid recalculation, especially at audio rate + for delay, later on */ + formxpow = (int)pow(-1.0, xc); + formypow = (int)pow(-1.0, yc); + formzpow = (int)pow(-1.0, zc); + formx = (xc + (1 - formxpow)/2) * rmx; + formy = (yc + (1 - formypow)/2) * rmy; + formz = (zc + (1 - formzpow)/2) * rmz; + + /* image */ + tempsrcx[M] = formxpow * srcx + formx; + tempsrcy[M] = formypow * srcy + formy; + tempsrcz[M] = formzpow * srcz + formz; + + /* Calculate delay here using source and listener location */ + dist[M] = (SQRT(SQUARE(tempsrcx[M] - lstnrx) + + SQUARE(tempsrcy[M] - lstnry) + + SQUARE(tempsrcz[M] - lstnrz))); + + /* in seconds... */ + dtime[M] = dist[M] / c; + + /* furthest allowable distance....max amp = 1. */ + tempdist = (dist[M] < FL(0.45) ? FL(0.45) : dist[M]); + + /* high amp value may cause clipping on early + reflections...reduce overall amp if so...*/ + /* SPL inverse distance law */ + amp[M] = FL(0.45) / tempdist; + + /* vdels for distance processing: */ + vdt[M] = dtime[M] * sr; + if (vdt[M] > maxdelsamps) + vdt[M] = (MYFLT)maxdelsamps; - M++; - M = M % impulses; - } - } + M++; + M = M % impulses; } + } } + } /* a rate... */ - for(j=0;j= 0 ? (rp < maxdelsamps ? rp : rp - maxdelsamps) : + rp + maxdelsamps); + frac = rp - (int)rp; + /* shift into correct part of buffer */ + pos = (int)rp + skipdel[M]; + /* write to l and r del lines */ + dell[delp[M] + skipdel[M]] = predell[counter + M * irlength] * amp[M]; + delr[delp[M] + skipdel[M]] = predelr[counter + M * irlength] * amp[M]; + /* read, at variable interpolated speed */ + outltot += dell[pos] + + frac*(dell[(pos + 1 < (maxdelsamps + skipdel[M]) ? + pos + 1 : skipdel[M])] - dell[pos]); + outrtot += delr[pos] + + frac*(delr[(pos + 1 < (maxdelsamps + skipdel[M]) ? + pos + 1 : skipdel[M])] - delr[pos]); + delp[M] = (delp[M] != maxdelsamps - 1 ? delp[M] + 1 : 0); - /* output */ - outltot = 0.0; - outrtot = 0.0; + outsigl[j] = outltot; + outsigr[j] = outrtot; + } + counter++; - /* for each reflection */ - for(M = 0; M < impulses; M++) - { - /* a rate vdel: */ - rp = delp[M] - vdt[M]; - rp = (rp >= 0 ? (rp < maxdelsamps ? rp : rp - maxdelsamps) : - rp + maxdelsamps); - frac = rp - (int)rp; - /* shift into correct part of buffer */ - pos = (int)rp + skipdel[M]; - /* write to l and r del lines */ - dell[delp[M] + skipdel[M]] = predell[counter + M * irlength] * amp[M]; - delr[delp[M] + skipdel[M]] = predelr[counter + M * irlength] * amp[M]; - /* read, at variable interpolated speed */ - outltot += dell[pos] + - frac*(dell[(pos + 1 < (maxdelsamps + skipdel[M]) ? - pos + 1 : skipdel[M])] - dell[pos]); - outrtot += delr[pos] + - frac*(delr[(pos + 1 < (maxdelsamps + skipdel[M]) ? - pos + 1 : skipdel[M])] - delr[pos]); - delp[M] = (delp[M] != maxdelsamps - 1 ? delp[M] + 1 : 0); + /* used to ensure fade does not happen on first run */ + if (initialfade < (irlength + 2)) + initialfade++; + + /* 'hrtf buffer' rate */ + if (counter == irlength) { + /* reset */ + M = 0; + /* run according to formula */ + for (xc = -order; xc <= order; xc++) { + for (yc = abs(xc) - order; yc <= order - abs(xc); yc++) { + /* only scroll through z plane if 3d required... */ + if (threed) { + lowz = abs(yc) - (order - abs(xc)); + highz = (order - abs(xc)) - abs(yc); + } + else { + lowz = 0; + highz = 0; + } + for (zc = lowz; zc <= highz; zc++) { + /* zero */ + crossout = 0; + crossfade = 0; + + /* avoid unnecessary processing if relative + source location has not changed */ + if (srcx != p->srcxv || srcy != p->srcyv || + srcz != p->srczv || lstnrx != p->lstnrxv || + lstnry != p->lstnryv || lstnrz != p->lstnrzv || + rotate != p->rotatev) { + /* if first process complete (128 samps in) and + source is too close to listener: warning, do not + process duda and martens range dependence + jasa 98: 5 times radius: near field...hrtf + changes! */ + if (dist[M] < FL(0.45) && initialfade > irlength) + ; /* do not process... */ + else { + /* to avoid case where atan2 is invalid */ + tempx = tempsrcx[M] - lstnrx; + tempy = tempsrcy[M] - lstnry; + if (tempx == 0 && tempy == 0) + angle = 0; + else { + /* - to invert anticlockwise to clockwise */ + angle = (-(ATAN2(tempy, tempx)) * 180.0 / PI_F); + /* add 90 to go from y axis (front) */ + angle = angle + 90.0; + } - outsigl[j] = outltot; - outsigr[j] = outrtot; - } - counter++; + /* xy point will be same as source, z same as + listener: a workable triangle */ + newpntx = tempsrcx[M]; + newpnty = tempsrcy[M]; + newpntz = lstnrz; + + /* ab: source to listener, ac: source to new point + under/over source, bc listener to new point */ + /* a = source, b = listener, c = new point */ + ab = (SQRT(SQUARE(tempsrcx[M] - lstnrx) + + SQUARE(tempsrcy[M] - lstnry) + + SQUARE(tempsrcz[M] - lstnrz))); + ac = (SQRT(SQUARE(tempsrcx[M] - newpntx) + + SQUARE(tempsrcy[M] - newpnty) + + SQUARE(tempsrcz[M] - newpntz))); + bc = (SQRT(SQUARE(lstnrx - newpntx) + + SQUARE(lstnry - newpnty) + + SQUARE(lstnrz - newpntz))); + + /* elev: when bc == 0 -> source + listener at + same x,y point (may happen in first run, + checked after that) angle = 0, elev = 0 if + at same point, + or source may be directly above/below */ + if (bc == FL(0.0)) { + /* source at listener */ + if (ac == FL(0.0)) + elev = FL(0.0); + /* source above listener */ + else + elev = FL(90.0); + } + else { + /* cosine rule */ + coselev = ((SQUARE(bc) + + SQUARE(ab) - + SQUARE(ac)) / (2.0 * ab * bc)); + elev = (ACOS(coselev)* 180.0 / PI_F); + } - /* used to ensure fade does not happen on first run */ - if(initialfade < (irlength + 2)) - initialfade++; + /* if z coefficient of source < listener: + source below listener...*/ + if (tempsrcz[M] < lstnrz) elev *= -1; + + if (elev > FL(90.0)) + elev = FL(90.0); + if (elev < FL(-40.0)) + elev = FL(-40.0); + + /* two nearest elev indices + to avoid recalculating */ + elevindexstore = (elev - minelev) / elevincrement; + elevindexlow = (int)elevindexstore; + + if (elevindexlow < 13) + elevindexhigh = elevindexlow + 1; + /* highest index reached */ + else + elevindexhigh = elevindexlow; + + /* get percentage value for interpolation */ + elevindexhighper = elevindexstore - elevindexlow; + + /* head rotation */ + angle -= rotate; + + while(angle < FL(0.0)) + angle += FL(360.0); + while(angle >= FL(360.0)) + angle -= FL(360.0); + + /* as above,lookup index, used to check + for crossfade */ + elevindex = (int)(elevindexstore + 0.5); + + angleindex = (int)(angle / + (360.0 / + elevationarray[elevindex]) + + 0.5); + angleindex = angleindex % elevationarray[elevindex]; + + /* avoid recalculation */ + angleindexlowstore = angle / + (FL(360.0) / + elevationarray[elevindexlow]); + angleindexhighstore = angle / + (FL(360.0) / elevationarray[elevindexhigh]); + + /* 4 closest indices, 2 low and 2 high */ + angleindex1 = (int)angleindexlowstore; + + angleindex2 = angleindex1 + 1; + angleindex2 = angleindex2 % + elevationarray[elevindexlow]; + + angleindex3 = (int)angleindexhighstore; + + angleindex4 = angleindex3 + 1; + angleindex4 = angleindex4 % + elevationarray[elevindexhigh]; + + /* angle percentages for interp */ + angleindex2per = angleindexlowstore - angleindex1; + angleindex4per = angleindexhighstore - angleindex3; + + /* crossfade happens if index changes:nearest + measurement changes, 1st step: store old + values */ + if (oldelevindex[M] != elevindex || + oldangleindex[M] != angleindex) { + if (initialfade > irlength) { + /* warning on overlapping fades */ + if (cross[M]) { + printf(Str("\nWARNING: fades are " + "overlapping: this could " + "lead to noise: reduce " + "fade size or change " + "trajectory\n\n")); + cross[M] = 0; + } + /* reset l */ + l[M] = 0; + crossfade = 1; + for (i = 0; i < irlengthpad; i++) { + hrtflpadspecold[irlengthpad * M + i] = + hrtflpadspec[irlengthpad * M + i]; + hrtfrpadspecold[irlengthpad * M + i] = + hrtfrpadspec[irlengthpad * M + i]; + } + } - /* 'hrtf buffer' rate */ - if(counter == irlength) - { - /* reset */ - M = 0; - /* run according to formula */ - for(xc = -order; xc <= order; xc++) - { - for(yc = abs(xc) - order; yc <= order - abs(xc); yc++) - { - /* only scroll through z plane if 3d required... */ - if(threed) - { - lowz = abs(yc) - (order - abs(xc)); - highz = (order - abs(xc)) - abs(yc); + skip = 0; + /* store current phase */ + if (angleindex > elevationarray[elevindex] / 2) { + for (i = 0; i < elevindex; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; + i < (elevationarray[elevindex] - + angleindex); + i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + currentphasel[irlength * M + i] = + fpindexr[skip + i]; + currentphaser[irlength * M + i] = + fpindexl[skip + i]; } - else - { - lowz = 0; - highz = 0; + } + else { + for (i = 0; i < elevindex; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; i < angleindex; i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + currentphasel[irlength * M + i] = + fpindexl[skip+i]; + currentphaser[irlength * M + i] = + fpindexr[skip+i]; } - for(zc = lowz; zc <= highz; zc++) - { - /* zero */ - crossout = 0; - crossfade = 0; - - /* avoid unnecessary processing if relative - source location has not changed */ - if(srcx != p->srcxv || srcy != p->srcyv || - srcz != p->srczv || lstnrx != p->lstnrxv || - lstnry != p->lstnryv || lstnrz != p->lstnrzv || - rotate != p->rotatev) - { - /* if first process complete (128 samps in) and - source is too close to listener: warning, do not - process duda and martens range dependence - jasa 98: 5 times radius: near field...hrtf - changes! */ - if(dist[M] < FL(0.45) && initialfade > irlength) - ; /* do not process... */ - else - { - /* to avoid case where atan2 is invalid */ - tempx = tempsrcx[M] - lstnrx; - tempy = tempsrcy[M] - lstnry; - if(tempx == 0 && tempy == 0) - angle = 0; - else - { - /* - to invert anticlockwise to clockwise */ - angle = (-(ATAN2(tempy, tempx)) * 180.0 / PI_F); - /* add 90 to go from y axis (front) */ - angle = angle + 90.0; - } - - /* xy point will be same as source, z same as - listener: a workable triangle */ - newpntx = tempsrcx[M]; - newpnty = tempsrcy[M]; - newpntz = lstnrz; - - /* ab: source to listener, ac: source to new point - under/over source, bc listener to new point */ - /* a = source, b = listener, c = new point */ - ab = (SQRT(SQUARE(tempsrcx[M] - lstnrx) + - SQUARE(tempsrcy[M] - lstnry) + - SQUARE(tempsrcz[M] - lstnrz))); - ac = (SQRT(SQUARE(tempsrcx[M] - newpntx) + - SQUARE(tempsrcy[M] - newpnty) + - SQUARE(tempsrcz[M] - newpntz))); - bc = (SQRT(SQUARE(lstnrx - newpntx) + - SQUARE(lstnry - newpnty) + - SQUARE(lstnrz - newpntz))); - - /* elev: when bc == 0 -> source + listener at - same x,y point (may happen in first run, - checked after that) angle = 0, elev = 0 if - at same point, - or source may be directly above/below */ - if(bc == FL(0.0)) - { - /* source at listener */ - if(ac == FL(0.0)) - elev = FL(0.0); - /* source above listener */ - else - elev = FL(90.0); - } - else - { - /* cosine rule */ - coselev = ((SQUARE(bc) + - SQUARE(ab) - - SQUARE(ac)) / (2.0 * ab * bc)); - elev = (ACOS(coselev)* 180.0 / PI_F); - } - - /* if z coefficient of source < listener: - source below listener...*/ - if(tempsrcz[M] < lstnrz) elev *= -1; - - if(elev > FL(90.0)) - elev = FL(90.0); - if(elev < FL(-40.0)) - elev = FL(-40.0); - - /* two nearest elev indices - to avoid recalculating */ - elevindexstore = (elev - minelev) / elevincrement; - elevindexlow = (int)elevindexstore; - - if(elevindexlow < 13) - elevindexhigh = elevindexlow + 1; - /* highest index reached */ - else - elevindexhigh = elevindexlow; - - /* get percentage value for interpolation */ - elevindexhighper = elevindexstore - elevindexlow; - - /* head rotation */ - angle -= rotate; - - while(angle < FL(0.0)) - angle += FL(360.0); - while(angle >= FL(360.0)) - angle -= FL(360.0); - - /* as above,lookup index, used to check - for crossfade */ - elevindex = (int)(elevindexstore + 0.5); - - angleindex = (int)(angle / - (360.0 / - elevationarray[elevindex]) + - 0.5); - angleindex = angleindex % elevationarray[elevindex]; - - /* avoid recalculation */ - angleindexlowstore = angle / - (FL(360.0) / - elevationarray[elevindexlow]); - angleindexhighstore = angle / - (FL(360.0) / elevationarray[elevindexhigh]); - - /* 4 closest indices, 2 low and 2 high */ - angleindex1 = (int)angleindexlowstore; - - angleindex2 = angleindex1 + 1; - angleindex2 = angleindex2 % - elevationarray[elevindexlow]; - - angleindex3 = (int)angleindexhighstore; - - angleindex4 = angleindex3 + 1; - angleindex4 = angleindex4 % - elevationarray[elevindexhigh]; - - /* angle percentages for interp */ - angleindex2per = angleindexlowstore - angleindex1; - angleindex4per = angleindexhighstore - angleindex3; - - /* crossfade happens if index changes:nearest - measurement changes, 1st step: store old - values */ - if (oldelevindex[M] != elevindex || - oldangleindex[M] != angleindex) - { - if(initialfade > irlength) - { - /* warning on overlapping fades */ - if(cross[M]) - { - printf(Str("\nWARNING: fades are " - "overlapping: this could " - "lead to noise: reduce " - "fade size or change " - "trajectory\n\n")); - cross[M] = 0; - } - /* reset l */ - l[M] = 0; - crossfade = 1; - for(i = 0; i < irlengthpad; i++) - { - hrtflpadspecold[irlengthpad * M + i] = - hrtflpadspec[irlengthpad * M + i]; - hrtfrpadspecold[irlengthpad * M + i] = - hrtfrpadspec[irlengthpad * M + i]; - } - } - - skip = 0; - /* store current phase */ - if(angleindex > elevationarray[elevindex] / 2) - { - for(i = 0; i < elevindex; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; - i < (elevationarray[elevindex] - - angleindex); - i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - currentphasel[irlength * M + i] = - fpindexr[skip + i]; - currentphaser[irlength * M + i] = - fpindexl[skip + i]; - } - } - else - { - for(i = 0; i < elevindex; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; i < angleindex; i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - currentphasel[irlength * M + i] = - fpindexl[skip+i]; - currentphaser[irlength * M + i] = - fpindexr[skip+i]; - } - } - } - - /* for next check */ - oldelevindex[M] = elevindex; - oldangleindex[M] = angleindex; - - /* read 4 nearest HRTFs */ - /* switch l and r */ - skip = 0; - if(angleindex1 > elevationarray[elevindexlow] / 2) - { - for(i = 0; i < elevindexlow; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; - i < (elevationarray[elevindexlow] - - angleindex1); - i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - lowl1[i] = fpindexr[skip+i]; - lowr1[i] = fpindexl[skip+i]; - } - } - else - { - for(i = 0; i < elevindexlow; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; i < angleindex1; i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - lowl1[i] = fpindexl[skip+i]; - lowr1[i] = fpindexr[skip+i]; - } - } - - skip = 0; - if(angleindex2 > elevationarray[elevindexlow] / 2) - { - for(i = 0; i < elevindexlow; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; - i < (elevationarray[elevindexlow] - - angleindex2); - i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - lowl2[i] = fpindexr[skip+i]; - lowr2[i] = fpindexl[skip+i]; - } - } - else - { - for(i = 0; i < elevindexlow; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; i < angleindex2; i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - lowl2[i] = fpindexl[skip+i]; - lowr2[i] = fpindexr[skip+i]; - } - } - - skip = 0; - if(angleindex3 > elevationarray[elevindexhigh] / 2) - { - for(i = 0; i < elevindexhigh; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; - i < (elevationarray[elevindexhigh] - - angleindex3); - i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - highl1[i] = fpindexr[skip+i]; - highr1[i] = fpindexl[skip+i]; - } - } - else - { - for(i = 0; i < elevindexhigh; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; i < angleindex3; i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - highl1[i] = fpindexl[skip+i]; - highr1[i] = fpindexr[skip+i]; - } - } - - skip = 0; - if(angleindex4 > elevationarray[elevindexhigh] / 2) - { - for(i = 0; i < elevindexhigh; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; - i < (elevationarray[elevindexhigh] - - angleindex4); - i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - highl2[i] = fpindexr[skip+i]; - highr2[i] = fpindexl[skip+i]; - } - } - else - { - for(i = 0; i < elevindexhigh; i ++) - skip +=((int)(elevationarray[i] / 2) - + 1) * irlength; - for (i = 0; i < angleindex4; i++) - skip += irlength; - for(i = 0; i < irlength; i++) - { - highl2[i] = fpindexl[skip+i]; - highr2[i] = fpindexr[skip+i]; - } - } - - /* magnitude interpolation */ - /* 0hz and Nyq */ - magllow = (FABS(lowl1[0])) + - ((FABS(lowl2[0]) - FABS(lowl1[0]))) * - angleindex2per; - maglhigh = (FABS(highl1[0])) + - ((FABS(highl2[0]) - FABS(highl1[0]))) * - angleindex4per; - magrlow = (FABS(lowr1[0])) + - ((FABS(lowr2[0]) - FABS(lowr1[0]))) * - angleindex2per; - magrhigh = (FABS(highr1[0])) + - ((FABS(highr2[0]) - FABS(highr1[0]))) * - angleindex4per; - magl = magllow + (maglhigh - magllow) * - elevindexhighper; - magr = magrlow + (magrhigh - magrlow) * - elevindexhighper; - if(currentphasel[M * irlength] < FL(0.0)) - hrtflinterp[0] = - magl; - else - hrtflinterp[0] = magl; - if(currentphaser[M * irlength] < FL(0.0)) - hrtfrinterp[0] = - magr; - else - hrtfrinterp[0] = magr; - - magllow = (FABS(lowl1[1])) + - ((FABS(lowl2[1]) - FABS(lowl1[1]))) * - angleindex2per; - maglhigh = (FABS(highl1[1])) - + ((FABS(highl2[1]) - FABS(highl1[1]))) * - angleindex4per; - magrlow = (FABS(lowr1[1])) + - ((FABS(lowr2[1]) - FABS(lowr1[1]))) * - angleindex2per; - magrhigh = (FABS(highr1[1])) + - ((FABS(highr2[1]) - FABS(highr1[1]))) * - angleindex4per; - magl = magllow + (maglhigh - magllow) * - elevindexhighper; - magr = magrlow + (magrhigh - magrlow) * - elevindexhighper; - if(currentphasel[M * irlength + 1] < FL(0.0)) - hrtflinterp[1] = - magl; - else - hrtflinterp[1] = magl; - if(currentphaser[M * irlength + 1] < FL(0.0)) - hrtfrinterp[1] = - magr; - else - hrtfrinterp[1] = magr; - - /* other values are complex, in fftw format */ - for(i = 2; i < irlength; i += 2) - { - /* interpolate high and low magnitudes */ - magllow = lowl1[i] + (lowl2[i] - lowl1[i]) * - angleindex2per; - maglhigh = highl1[i] + (highl2[i] - highl1[i]) * - angleindex4per; - - magrlow = lowr1[i] + (lowr2[i] - lowr1[i]) * - angleindex2per; - magrhigh = highr1[i] + (highr2[i] - highr1[i]) * - angleindex4per; - - /* interpolate high and low results, - use current phase */ - magl = magllow + (maglhigh - magllow) * - elevindexhighper; - phasel = currentphasel[M * irlength + i + 1]; - - /* polar to rectangular */ - hrtflinterp[i] = magl * FL(cos(phasel)); - hrtflinterp[i + 1] = magl * FL(sin(phasel)); - - magr = magrlow + (magrhigh - magrlow) * - elevindexhighper; - phaser = currentphaser[M * irlength + i + 1]; - - hrtfrinterp[i] = magr * FL(cos(phaser)); - hrtfrinterp[i + 1] = magr * FL(sin(phaser)); - } - - csound->InverseRealFFT(csound, hrtflinterp, - irlength); - csound->InverseRealFFT(csound, hrtfrinterp, - irlength); - - /* wall filters... */ - /* all 4 walls are the same! (trivial to - make them different...) */ - /* x axis, wall1 (left) */ - wallreflections = - (int)abs((int)(xc * .5 - .25 + - (0.25 * pow(-1.0, xc)))); - /* wall2, x (right) */ - wallreflections += - (int)abs((int)(xc * .5 + .25 - - (0.25 * pow(-1.0, xc)))); - /* yaxis, wall3 (bottom) */ - wallreflections += - (int)abs((int)(yc * .5 - .25 + - (0.25 * pow(-1.0, yc)))); - /* yaxis, wall 4 (top) */ - wallreflections += - (int)abs((int)(yc * .5 + .25 - - (0.25 * pow(-1.0, yc)))); - if(threed) - { - /* floor (negative z) */ - floorreflections = - (int)abs((int)(zc * .5 - .25 + - (0.25 * pow(-1.0, zc)))); - /* ceiling (positive z) */ - ceilingreflections = - (int)abs((int)(zc * .5 + .25 - - (0.25 * pow(-1.0, zc)))); - } - - /* fixed parameters on bands etc (to limit no of - inputs), but these could trivially be variable */ - /* note: delay values can be reused: zeroed every - time as only used in - processing hrtf, once every irlength, so not - used continuously...*/ - /* if processing was continuous, would need - separate mem for each filter, store for - next run etc...*/ - for(i = 0; i < wallreflections; i++) - { - delsinglel = delsingler = FL(0.0); - filter(hrtflinterp, p->wallcoefhigh, - p->wallcoeflow, &delsinglel, - irlength, sr); - filter(hrtfrinterp, p->wallcoefhigh, - p->wallcoeflow, &delsingler, - irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(250.0), FL(250.0) / p->q, p->wallg1, deldoublel, irlength, sr); - band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, p->wallg1, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(1000.0), FL(1000.0) / p->q, p->wallg2, deldoublel, irlength, sr); - band(hrtfrinterp, FL(1000.0), FL(1000.0) / p->q, p->wallg2, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(4000.0), FL(4000.0) / p->q, p->wallg3, deldoublel, irlength, sr); - band(hrtfrinterp, FL(4000.0), FL(4000.0) / p->q, p->wallg3, deldoubler, irlength, sr); - } - if(threed) - { - for(i = 0; i < floorreflections; i++) - { - delsinglel = delsingler = FL(0.0); - filter(hrtflinterp, p->floorcoefhigh, p->floorcoeflow, &delsinglel, irlength, sr); - filter(hrtfrinterp, p->floorcoefhigh, p->floorcoeflow, &delsingler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(250.0), FL(250.0) / p->q, p->floorg1, deldoublel, irlength, sr); - band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, p->floorg1, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(1000.0), FL(1000.0) / p->q, p->floorg2, deldoublel, irlength, sr); - band(hrtfrinterp, FL(1000.0), FL(1000.0) / p->q, p->floorg2, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(4000.0), FL(4000.0) / p->q, p->floorg3, deldoublel, irlength, sr); - band(hrtfrinterp, FL(4000.0), FL(4000.0) / p->q, p->floorg3, deldoubler, irlength, sr); - } - for(i = 0; i < ceilingreflections; i++) - { - delsinglel = delsingler = FL(0.0); - filter(hrtflinterp, p->ceilingcoefhigh, p->ceilingcoeflow, &delsinglel, irlength, sr); - filter(hrtfrinterp, p->ceilingcoefhigh, p->ceilingcoeflow, &delsingler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(250.0), FL(250.0) / p->q, p->ceilingg1, deldoublel, irlength, sr); - band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, p->ceilingg1, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(1000.0), FL(1000.0) / p->q, p->ceilingg2, deldoublel, irlength, sr); - band(hrtfrinterp, FL(1000.0), FL(1000.0) / p->q, p->ceilingg2, deldoubler, irlength, sr); - deldoublel[0] = deldoublel[1] = deldoubler[0] = deldoubler[1] = 0.0; - band(hrtflinterp, FL(4000.0), FL(4000.0) / p->q, p->ceilingg3, deldoublel, irlength, sr); - band(hrtfrinterp, FL(4000.0), FL(4000.0) / p->q, p->ceilingg3, deldoubler, irlength, sr); - } - } - - for(i = 0; i < irlength; i++) - { - hrtflpad[i] = hrtflinterp[i]; - hrtfrpad[i] = hrtfrinterp[i]; - } - - for(i = irlength; i < irlengthpad; i++) - { - hrtflpad[i] = FL(0.0); - hrtfrpad[i] = FL(0.0); - } - - /* back to freq domain */ - csound->RealFFT(csound, hrtflpad, irlengthpad); - csound->RealFFT(csound, hrtfrpad, irlengthpad); - - /* store */ - for(i = 0; i < irlengthpad; i++) - { - hrtflpadspec[M * irlengthpad + i] = hrtflpad[i]; - hrtfrpadspec[M * irlengthpad + i] = hrtfrpad[i]; - } - } - } /* end of source / listener relative - change process */ - - /* look after overlap add */ - for(i = 0; i < overlapsize ; i++) - { - overlapl[i] = outl[M * irlengthpad + i + irlength]; - overlapr[i] = outr[M * irlengthpad + i + irlength]; - if(crossfade) - { - overlaplold[i] = - outl[M * irlengthpad + i + irlength]; - overlaprold[i] = - outr[M * irlengthpad + i + irlength]; - } - /* overlap will be previous fading out signal */ - if(cross[M]) - { - overlaplold[i] = - outlold[M * irlengthpad + i + irlength]; - overlaprold[i] = - outrold[M * irlengthpad + i + irlength]; - } - } - - /* insert insig */ - for (i = 0; i < irlength; i++) - inbufpad[i] = inbuf[i]; - - for (i = irlength; i < irlengthpad; i++) - inbufpad[i] = FL(0.0); - - csound->RealFFT(csound, inbufpad, irlengthpad); - - for(i = 0; i < irlengthpad; i ++) - { - hrtflpad[i] = hrtflpadspec[M * irlengthpad + i]; - hrtfrpad[i] = hrtfrpadspec[M * irlengthpad + i]; - } - - /* convolution: spectral multiplication */ - csound->RealFFTMult(csound, outlspec, hrtflpad, - inbufpad, irlengthpad, FL(1.0)); - csound->RealFFTMult(csound, outrspec, hrtfrpad, - inbufpad, irlengthpad, FL(1.0)); - - csound->InverseRealFFT(csound, outlspec, irlengthpad); - csound->InverseRealFFT(csound, outrspec, irlengthpad); - - /* scale */ - for(i = 0; i < irlengthpad; i++) - { - outlspec[i] = outlspec[i]/(sr/FL(38000.0)); - outrspec[i] = outrspec[i]/(sr/FL(38000.0)); - } - - /* store */ - for(i = 0; i < irlengthpad; i++) - { - outl[M * irlengthpad + i] = outlspec[i]; - outr[M * irlengthpad + i] = outrspec[i]; - } - - /* setup for fades */ - if(crossfade || cross[M]) - { - crossout = 1; - - /* need to put these values into a buffer for processing */ - for(i = 0; i < irlengthpad; i++) - { - hrtflpadold[i] = - hrtflpadspecold[M * irlengthpad + i]; - hrtfrpadold[i] = - hrtfrpadspecold[M * irlengthpad + i]; - } - - /* convolution */ - csound->RealFFTMult(csound, outlspecold, hrtflpadold, - inbufpad, irlengthpad, FL(1.0)); - csound->RealFFTMult(csound, outrspecold, hrtfrpadold, - inbufpad, irlengthpad, FL(1.0)); - - /* ifft, back to time domain */ - csound->InverseRealFFT(csound, outlspecold, - irlengthpad); - csound->InverseRealFFT(csound, outrspecold, - irlengthpad); - - /* scale */ - for(i = 0; i < irlengthpad; i++) - { - outlspecold[i] = outlspecold[i]/(sr/FL(38000.0)); - outrspecold[i] = outrspecold[i]/(sr/FL(38000.0)); - } - - /* o/p real values */ - for(i = 0; i < irlengthpad; i++) - { - outlold[M * irlengthpad + i] = outlspecold[i]; - outrold[M * irlengthpad + i] = outrspecold[i]; - } - - cross[M]++; - cross[M] = cross[M] % fade; - } - - if(crossout) - for(i = 0; i < irlength; i++) - { - predell[i + M * irlength] = - (outlspecold[i] + - (i < overlapsize ? overlaplold[i] : FL(0.0))) * - FL(1. - (FL(l[M]) / fadebuffer)) + - (outlspec[i] + - (i < overlapsize ? overlapl[i] : FL(0.0))) * - (FL(l[M]) / fadebuffer); - predelr[i + M * irlength] = - (outrspecold[i] + - (i < overlapsize ? overlaprold[i] : FL(0.0))) * - FL(1. - (FL(l[M]) / fadebuffer)) + - (outrspec[i] + - (i < overlapsize ? overlapr[i] : FL(0.0))) * - (FL(l[M]) / fadebuffer); - l[M]++; - } - else - for(i = 0; i < irlength; i++) - { - predell[i + M * irlength] = - outlspec[i] + - (i < overlapsize ? overlapl[i] : FL(0.0)); - predelr[i + M * irlength] = - outrspec[i] + - (i < overlapsize ? overlapr[i] : FL(0.0)); - } - - M++; - M = M % impulses; - - } /* z */ - } /* y */ - } /* x */ - - counter = 0; - /* need to store these values here, as storing them after check - would not allow each impulse to be processed! */ - p->srcxv = srcx; - p->srcyv = srcy; - p->srczv = srcz; - p->lstnrxv = lstnrx; - p->lstnryv = lstnry; - p->lstnrzv = lstnrz; - p->rotatev = rotate; - - } /* end of counter == irlength */ - - /* update */ - p->counter = counter; - p->initialfade = initialfade; + } + } + + /* for next check */ + oldelevindex[M] = elevindex; + oldangleindex[M] = angleindex; + + /* read 4 nearest HRTFs */ + /* switch l and r */ + skip = 0; + if (angleindex1 > elevationarray[elevindexlow] / 2) { + for (i = 0; i < elevindexlow; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; + i < (elevationarray[elevindexlow] - + angleindex1); + i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + lowl1[i] = fpindexr[skip+i]; + lowr1[i] = fpindexl[skip+i]; + } + } + else { + for (i = 0; i < elevindexlow; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; i < angleindex1; i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + lowl1[i] = fpindexl[skip+i]; + lowr1[i] = fpindexr[skip+i]; + } + } + + skip = 0; + if (angleindex2 > elevationarray[elevindexlow] / 2) { + for (i = 0; i < elevindexlow; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; + i < (elevationarray[elevindexlow] - + angleindex2); + i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + lowl2[i] = fpindexr[skip+i]; + lowr2[i] = fpindexl[skip+i]; + } + } + else { + for (i = 0; i < elevindexlow; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; i < angleindex2; i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + lowl2[i] = fpindexl[skip+i]; + lowr2[i] = fpindexr[skip+i]; + } + } + + skip = 0; + if (angleindex3 > elevationarray[elevindexhigh] / 2) { + for (i = 0; i < elevindexhigh; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; + i < (elevationarray[elevindexhigh] - + angleindex3); + i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + highl1[i] = fpindexr[skip+i]; + highr1[i] = fpindexl[skip+i]; + } + } + else { + for (i = 0; i < elevindexhigh; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; i < angleindex3; i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + highl1[i] = fpindexl[skip+i]; + highr1[i] = fpindexr[skip+i]; + } + } - } /* end of ksmps loop */ + skip = 0; + if (angleindex4 > elevationarray[elevindexhigh] / 2) { + for (i = 0; i < elevindexhigh; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; + i < (elevationarray[elevindexhigh] - + angleindex4); + i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + highl2[i] = fpindexr[skip+i]; + highr2[i] = fpindexl[skip+i]; + } + } + else { + for (i = 0; i < elevindexhigh; i ++) + skip +=((int)(elevationarray[i] / 2) + + 1) * irlength; + for (i = 0; i < angleindex4; i++) + skip += irlength; + for (i = 0; i < irlength; i++) { + highl2[i] = fpindexl[skip+i]; + highr2[i] = fpindexr[skip+i]; + } + } + + /* magnitude interpolation */ + /* 0hz and Nyq */ + magllow = (FABS(lowl1[0])) + + ((FABS(lowl2[0]) - FABS(lowl1[0]))) * + angleindex2per; + maglhigh = (FABS(highl1[0])) + + ((FABS(highl2[0]) - FABS(highl1[0]))) * + angleindex4per; + magrlow = (FABS(lowr1[0])) + + ((FABS(lowr2[0]) - FABS(lowr1[0]))) * + angleindex2per; + magrhigh = (FABS(highr1[0])) + + ((FABS(highr2[0]) - FABS(highr1[0]))) * + angleindex4per; + magl = magllow + (maglhigh - magllow) * + elevindexhighper; + magr = magrlow + (magrhigh - magrlow) * + elevindexhighper; + if (currentphasel[M * irlength] < FL(0.0)) + hrtflinterp[0] = - magl; + else + hrtflinterp[0] = magl; + if (currentphaser[M * irlength] < FL(0.0)) + hrtfrinterp[0] = - magr; + else + hrtfrinterp[0] = magr; + + magllow = (FABS(lowl1[1])) + + ((FABS(lowl2[1]) - FABS(lowl1[1]))) * + angleindex2per; + maglhigh = (FABS(highl1[1])) + + ((FABS(highl2[1]) - FABS(highl1[1]))) * + angleindex4per; + magrlow = (FABS(lowr1[1])) + + ((FABS(lowr2[1]) - FABS(lowr1[1]))) * + angleindex2per; + magrhigh = (FABS(highr1[1])) + + ((FABS(highr2[1]) - FABS(highr1[1]))) * + angleindex4per; + magl = magllow + (maglhigh - magllow) * + elevindexhighper; + magr = magrlow + (magrhigh - magrlow) * + elevindexhighper; + if (currentphasel[M * irlength + 1] < FL(0.0)) + hrtflinterp[1] = - magl; + else + hrtflinterp[1] = magl; + if (currentphaser[M * irlength + 1] < FL(0.0)) + hrtfrinterp[1] = - magr; + else + hrtfrinterp[1] = magr; + + /* other values are complex, in fftw format */ + for (i = 2; i < irlength; i += 2) { + /* interpolate high and low magnitudes */ + magllow = lowl1[i] + (lowl2[i] - lowl1[i]) * + angleindex2per; + maglhigh = highl1[i] + (highl2[i] - highl1[i]) * + angleindex4per; + + magrlow = lowr1[i] + (lowr2[i] - lowr1[i]) * + angleindex2per; + magrhigh = highr1[i] + (highr2[i] - highr1[i]) * + angleindex4per; + + /* interpolate high and low results, + use current phase */ + magl = magllow + (maglhigh - magllow) * + elevindexhighper; + phasel = currentphasel[M * irlength + i + 1]; + + /* polar to rectangular */ + hrtflinterp[i] = magl * FL(cos(phasel)); + hrtflinterp[i + 1] = magl * FL(sin(phasel)); + + magr = magrlow + (magrhigh - magrlow) * + elevindexhighper; + phaser = currentphaser[M * irlength + i + 1]; + + hrtfrinterp[i] = magr * FL(cos(phaser)); + hrtfrinterp[i + 1] = magr * FL(sin(phaser)); + } + + csound->InverseRealFFT(csound, hrtflinterp, + irlength); + csound->InverseRealFFT(csound, hrtfrinterp, + irlength); + + /* wall filters... */ + /* all 4 walls are the same! (trivial to + make them different...) */ + /* x axis, wall1 (left) */ + wallreflections = + (int)abs((int)(xc * .5 - .25 + + (0.25 * pow(-1.0, xc)))); + /* wall2, x (right) */ + wallreflections += + (int)abs((int)(xc * .5 + .25 - + (0.25 * pow(-1.0, xc)))); + /* yaxis, wall3 (bottom) */ + wallreflections += + (int)abs((int)(yc * .5 - .25 + + (0.25 * pow(-1.0, yc)))); + /* yaxis, wall 4 (top) */ + wallreflections += + (int)abs((int)(yc * .5 + .25 - + (0.25 * pow(-1.0, yc)))); + if (threed) { + /* floor (negative z) */ + floorreflections = + (int)abs((int)(zc * .5 - .25 + + (0.25 * pow(-1.0, zc)))); + /* ceiling (positive z) */ + ceilingreflections = + (int)abs((int)(zc * .5 + .25 + - (0.25 * pow(-1.0, zc)))); + } + + /* fixed parameters on bands etc (to limit no of + inputs), but these could trivially be variable */ + /* note: delay values can be reused: zeroed every + time as only used in + processing hrtf, once every irlength, so not + used continuously...*/ + /* if processing was continuous, would need + separate mem for each filter, store for + next run etc...*/ + for (i = 0; i < wallreflections; i++) { + delsinglel = delsingler = FL(0.0); + filter(hrtflinterp, p->wallcoefhigh, + p->wallcoeflow, &delsinglel, + irlength, sr); + filter(hrtfrinterp, p->wallcoefhigh, + p->wallcoeflow, &delsingler, + irlength, sr); + deldoublel[0] = deldoublel[1] = + deldoubler[0] = deldoubler[1] = 0.0; + band(hrtflinterp, FL(250.0), FL(250.0) / p->q, + p->wallg1, deldoublel, irlength, sr); + band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, + p->wallg1, deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = + deldoubler[0] = deldoubler[1] = 0.0; + band(hrtflinterp, FL(1000.0), + FL(1000.0) / p->q, p->wallg2, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(1000.0), + FL(1000.0) / p->q, p->wallg2, + deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = + deldoubler[0] = deldoubler[1] = 0.0; + band(hrtflinterp, FL(4000.0), + FL(4000.0) / p->q, p->wallg3, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(4000.0), + FL(4000.0) / p->q, p->wallg3, + deldoubler, irlength, sr); + } + if (threed) { + for (i = 0; i < floorreflections; i++) { + delsinglel = delsingler = FL(0.0); + filter(hrtflinterp, p->floorcoefhigh, + p->floorcoeflow, &delsinglel, + irlength, sr); + filter(hrtfrinterp, p->floorcoefhigh, p->floorcoeflow, + &delsingler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(250.0), FL(250.0) / p->q, p->floorg1, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, p->floorg1, + deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(1000.0), FL(1000.0) / p->q, p->floorg2, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(1000.0), FL(1000.0) / p->q, p->floorg2, + deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(4000.0), FL(4000.0) / p->q, p->floorg3, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(4000.0), FL(4000.0) / p->q, p->floorg3, + deldoubler, irlength, sr); + } + for (i = 0; i < ceilingreflections; i++) { + delsinglel = delsingler = FL(0.0); + filter(hrtflinterp, p->ceilingcoefhigh, p->ceilingcoeflow, + &delsinglel, irlength, sr); + filter(hrtfrinterp, p->ceilingcoefhigh, p->ceilingcoeflow, + &delsingler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(250.0), FL(250.0) / p->q, p->ceilingg1, + deldoublel, irlength, sr); + band(hrtfrinterp, FL(250.0), FL(250.0) / p->q, p->ceilingg1, + deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(1000.0), FL(1000.0) / p->q, + p->ceilingg2, deldoublel, irlength, sr); + band(hrtfrinterp, FL(1000.0), FL(1000.0) / p->q, + p->ceilingg2, deldoubler, irlength, sr); + deldoublel[0] = deldoublel[1] = deldoubler[0] = + deldoubler[1] = 0.0; + band(hrtflinterp, FL(4000.0), FL(4000.0) / p->q, + p->ceilingg3, deldoublel, irlength, sr); + band(hrtfrinterp, FL(4000.0), FL(4000.0) / p->q, + p->ceilingg3, deldoubler, irlength, sr); + } + } + + for (i = 0; i < irlength; i++) { + hrtflpad[i] = hrtflinterp[i]; + hrtfrpad[i] = hrtfrinterp[i]; + } + + for (i = irlength; i < irlengthpad; i++) { + hrtflpad[i] = FL(0.0); + hrtfrpad[i] = FL(0.0); + } + + /* back to freq domain */ + csound->RealFFT(csound, hrtflpad, irlengthpad); + csound->RealFFT(csound, hrtfrpad, irlengthpad); + + /* store */ + for (i = 0; i < irlengthpad; i++) { + hrtflpadspec[M * irlengthpad + i] = hrtflpad[i]; + hrtfrpadspec[M * irlengthpad + i] = hrtfrpad[i]; + } + } + } /* end of source / listener relative + change process */ + + /* look after overlap add */ + for (i = 0; i < overlapsize ; i++) { + overlapl[i] = outl[M * irlengthpad + i + irlength]; + overlapr[i] = outr[M * irlengthpad + i + irlength]; + if (crossfade) { + overlaplold[i] = + outl[M * irlengthpad + i + irlength]; + overlaprold[i] = + outr[M * irlengthpad + i + irlength]; + } + /* overlap will be previous fading out signal */ + if (cross[M]) { + overlaplold[i] = + outlold[M * irlengthpad + i + irlength]; + overlaprold[i] = + outrold[M * irlengthpad + i + irlength]; + } + } + + /* insert insig */ + for (i = 0; i < irlength; i++) + inbufpad[i] = inbuf[i]; + + for (i = irlength; i < irlengthpad; i++) + inbufpad[i] = FL(0.0); + + csound->RealFFT(csound, inbufpad, irlengthpad); + + for (i = 0; i < irlengthpad; i ++) { + hrtflpad[i] = hrtflpadspec[M * irlengthpad + i]; + hrtfrpad[i] = hrtfrpadspec[M * irlengthpad + i]; + } + + /* convolution: spectral multiplication */ + csound->RealFFTMult(csound, outlspec, hrtflpad, + inbufpad, irlengthpad, FL(1.0)); + csound->RealFFTMult(csound, outrspec, hrtfrpad, + inbufpad, irlengthpad, FL(1.0)); + + csound->InverseRealFFT(csound, outlspec, irlengthpad); + csound->InverseRealFFT(csound, outrspec, irlengthpad); + + /* scale */ + for (i = 0; i < irlengthpad; i++) { + outlspec[i] = outlspec[i]/(sr/FL(38000.0)); + outrspec[i] = outrspec[i]/(sr/FL(38000.0)); + } + + /* store */ + for (i = 0; i < irlengthpad; i++) { + outl[M * irlengthpad + i] = outlspec[i]; + outr[M * irlengthpad + i] = outrspec[i]; + } + + /* setup for fades */ + if (crossfade || cross[M]) { + crossout = 1; + + /* need to put these values into a buffer for processing */ + for (i = 0; i < irlengthpad; i++) { + hrtflpadold[i] = + hrtflpadspecold[M * irlengthpad + i]; + hrtfrpadold[i] = + hrtfrpadspecold[M * irlengthpad + i]; + } + + /* convolution */ + csound->RealFFTMult(csound, outlspecold, hrtflpadold, + inbufpad, irlengthpad, FL(1.0)); + csound->RealFFTMult(csound, outrspecold, hrtfrpadold, + inbufpad, irlengthpad, FL(1.0)); + + /* ifft, back to time domain */ + csound->InverseRealFFT(csound, outlspecold, + irlengthpad); + csound->InverseRealFFT(csound, outrspecold, + irlengthpad); + + /* scale */ + for (i = 0; i < irlengthpad; i++) { + outlspecold[i] = outlspecold[i]/(sr/FL(38000.0)); + outrspecold[i] = outrspecold[i]/(sr/FL(38000.0)); + } + + /* o/p real values */ + for (i = 0; i < irlengthpad; i++) { + outlold[M * irlengthpad + i] = outlspecold[i]; + outrold[M * irlengthpad + i] = outrspecold[i]; + } + + cross[M]++; + cross[M] = cross[M] % fade; + } + + if (crossout) + for (i = 0; i < irlength; i++) { + predell[i + M * irlength] = + (outlspecold[i] + + (i < overlapsize ? overlaplold[i] : FL(0.0))) * + FL(1. - (FL(l[M]) / fadebuffer)) + + (outlspec[i] + + (i < overlapsize ? overlapl[i] : FL(0.0))) * + (FL(l[M]) / fadebuffer); + predelr[i + M * irlength] = + (outrspecold[i] + + (i < overlapsize ? overlaprold[i] : FL(0.0))) * + FL(1. - (FL(l[M]) / fadebuffer)) + + (outrspec[i] + + (i < overlapsize ? overlapr[i] : FL(0.0))) * + (FL(l[M]) / fadebuffer); + l[M]++; + } + else + for (i = 0; i < irlength; i++) { + predell[i + M * irlength] = + outlspec[i] + + (i < overlapsize ? overlapl[i] : FL(0.0)); + predelr[i + M * irlength] = + outrspec[i] + + (i < overlapsize ? overlapr[i] : FL(0.0)); + } + + M++; + M = M % impulses; + + } /* z */ + } /* y */ + } /* x */ + + counter = 0; + /* need to store these values here, as storing them after check + would not allow each impulse to be processed! */ + p->srcxv = srcx; + p->srcyv = srcy; + p->srczv = srcz; + p->lstnrxv = lstnrx; + p->lstnryv = lstnry; + p->lstnrzv = lstnrz; + p->rotatev = rotate; + + } /* end of counter == irlength */ + + /* update */ + p->counter = counter; + p->initialfade = initialfade; + + } /* end of ksmps loop */ return OK; } static OENTRY hrtfearly_localops[] = -{ { - "hrtfearly", sizeof(early), 5, "aaiii", "axxxxxxSSioopoOoooooooooooooooooo", - (SUBR)early_init, NULL, (SUBR)early_process - } -}; + { + "hrtfearly", sizeof(early), 0,5, "aaiii", + "axxxxxxSSioopoOoooooooooooooooooo", + (SUBR)early_init, NULL, (SUBR)early_process + } + }; -LINKAGE1(hrtfearly_localops) +LINKAGE_BUILTIN(hrtfearly_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/hrtferX.c csound-6.02~dfsg/Opcodes/hrtferX.c --- csound-5.17.11~dfsg/Opcodes/hrtferX.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/hrtferX.c 2014-01-07 16:53:48.000000000 +0000 @@ -76,15 +76,15 @@ /* first check if orchestra's sampling rate is compatible with HRTF measurement's */ - if (UNLIKELY(csound->esr != SAMP_RATE)) { - csound->Die(csound, + if (UNLIKELY(CS_ESR != SAMP_RATE)) { + return csound->InitError(csound, Str("Orchestra sampling rate is not compatible with HRTF.\n" "Should be %d...exiting."), SAMP_RATE); return NOTOK; /* not reached */ } - if (LIKELY(p->XSTRCODE)) - strcpy(filename, (char*) p->ifilno); + if(!strcmp("HRTFcompact", p->ifilno->data)) + strcpy(filename, p->ifilno->data); else { csound->Message(csound, Str("\nLast argument must be the string " "'HRTFcompact' ...correcting.\n")); @@ -92,7 +92,7 @@ } if ((mfp = p->mfp) == NULL) - mfp = csound->ldmemfile2(csound, filename, CSFTYPE_HRTF); + mfp = csound->ldmemfile2withCB(csound, filename, CSFTYPE_HRTF, NULL); p->mfp = mfp; p->fpbegin = (int16*) mfp->beginp; bytrev_test = 0x1234; @@ -107,13 +107,6 @@ x++; len--; } } -#ifdef CLICKS - /* initialize ramp arrays for crossfading */ - for (i = 0; i < FILT_LEN; i++) { - p->rampup[i] = (MYFLT) i / (MYFLT) FILT_LEN; - p->rampdown[i] = FL(1.0) - p->rampup[i]; - } -#endif /* initialize counters and indices */ p->outcount = 0; p->incount = 0; @@ -126,10 +119,6 @@ /* initialize left output buffer */ /* initialize right output buffer */ for (i=0; ioldhrtf_data.left[i] = FL(0.0); - p->oldhrtf_data.right[i] = FL(0.0); -#endif p->x[i] = FL(0.0); p->yl[i] = FL(0.0); p->yr[i] = FL(0.0); @@ -153,29 +142,19 @@ { MYFLT *aLeft, *aRight; /* audio output streams */ MYFLT *aIn, *kAz, *kElev; /* audio and control input streams */ - int azim, elev, el_index, az_index,oldel_index; -#ifdef CLICKS - int oldaz_index; -#endif + int azim, elev, el_index, az_index; int nsmpsi, nsmpso; /* number of samples in/out */ /* input, out-left, out-right */ MYFLT *x, *yl, *yr; /* Local copies of address */ /* overlap left, overlap right */ MYFLT *bl, *br; /* copy of current input convolved with old HRTFs */ -#ifdef CLICKS - MYFLT yl2[BUF_LEN], yr2[BUF_LEN]; -#endif MYFLT *outl, *outr; /* output left/right */ int outfront, outend; /* circular output indices */ int incount, outcount; /* number of samples in/out */ - int toread; /* number of samples to read */ + uint32_t toread; /* number of samples to read */ int i; /* standard loop counter */ HRTF_DATUM hrtf_data; /* local hrtf instances */ -#ifdef CLICKS - HRTF_DATUM oldhrtf_data; - int crossfadeflag; /* flag - true if crossfading old and new HRTFs */ -#endif int flip; /* flag - true if we need to flip the channels */ int16 *fpindex; /* pointer into HRTF file */ int16 numskip; /* number of shorts to skip in HRTF file */ @@ -183,6 +162,9 @@ int16 sl[FILT_LEN], sr[FILT_LEN]; /* float versions of above to be sent to FFT routines */ MYFLT xl[BUF_LEN], xr[BUF_LEN]; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t ii; if (UNLIKELY(p->mfp==NULL)) goto err1; /* RWD fix */ /* update local variables */ @@ -190,13 +172,9 @@ kAz = p->kAz; elev = (int) *kElev; azim = (int) *kAz; - oldel_index = p->oldel_index; + //oldel_index = p->oldel_index; fpindex = (int16 *) p->fpbegin; flip = 0; -#ifdef CLICKS - crossfadeflag = 0; - oldaz_index = p->oldaz_index; -#endif /* Convert elevation in degrees to elevation array index. */ el_index = ROUND((elev - MIN_ELEV) / ELEV_INC); @@ -246,11 +224,6 @@ fpindex += (int16) (numskip); } -#ifdef CLICKS - if ((oldel_index != el_index) || (oldaz_index != az_index)) { - crossfadeflag = 1; - } -#endif /* read in (int16) data from stereo interleave HRTF file. Split into left and right channel data. */ for (i=0; ioutfront; outend = p->outend; -#ifdef CLICKS - for (i=0; ioldhrtf_data.left[i]; - oldhrtf_data.right[i] = p->oldhrtf_data.right[i]; - } -#endif /* Get local pointers to structures */ outl = &p->outl[0]; outr = &p->outr[0]; @@ -320,8 +287,7 @@ aLeft = p->aLeft; aRight = p->aRight; - nsmpsi = csound->ksmps; - nsmpso = csound->ksmps; + nsmpsi = nsmpso = CS_KSMPS; /* main loop for a-rate code. Audio read in, processed, and output in this loop. Loop exits when control period @@ -335,12 +301,12 @@ /* reading in audio into x */ if (incount == 0) { - for (i = 0; i < toread; i++) - x[i] = *aIn++; + for (ii = 0; ii < toread; ii++) + x[ii] = (iiearly ? FL(0.0) : aIn[ii]); } else { - for (i = incount; i<(incount + toread); i++) - x[i] = *aIn++; + for (ii = incount; ii<(incount + toread); ii++) + x[ii] = (iiearly ? FL(0.0) : aIn[ii]); } /* update counters for amount of audio read */ @@ -363,28 +329,7 @@ /* convolution is the inverse FFT of above result (yl,yr) */ csound->InverseRealFFT(csound, yl, BUF_LEN); csound->InverseRealFFT(csound, yr, BUF_LEN); - -#ifdef CLICKS - if (crossfadeflag) { /* convolve current input with old HRTFs */ - /* ***** THIS CODE IS SERIOUSLY BROKEN ***** */ - /* complex multiplication, y2 = oldhrtf_data * x */ - csound->RealFFTMult(csound, - yl2, oldhrtf_data.left, x, BUF_LEN, FL(1.0)); - csound->RealFFTMult(csound, - yr2, oldhrtf_data.right, x, BUF_LEN, FL(1.0)); - - /* convolution is the inverse FFT of above result (y) */ - csound->InverseRealFFT(csound, yl2, BUF_LEN); - csound->InverseRealFFT(csound, yr2, BUF_LEN); - - /* linear crossfade */ - for (i=0; irampup[i] + yl2[i]*p->rampdown[i]; - yr[i] = yr[i]*p->rampup[i] + yr2[i]*p->rampdown[i]; - } - } -#endif - /* overlap-add the results */ + /* overlap-add the results */ for (i = 0; i < FILT_LENm1; i++) { yl[i] += bl[i]; yr[i] += br[i]; @@ -480,22 +425,16 @@ p->outfront = outfront; p->outend = outend; p->oldel_index = el_index; -#ifdef CLICKS - p->oldaz_index = az_index; - - for (i=0; ioldhrtf_data.left[i] = hrtf_data.left[i]; - p->oldhrtf_data.right[i] = hrtf_data.right[i]; - } -#endif return OK; err1: - return csound->PerfError(csound, Str("hrtfer: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("hrtfer: not initialised")); } static OENTRY hrtferX_localops[] = { -{ "hrtfer", sizeof(HRTFER),5, "aa", "akkS", (SUBR)hrtferxkSet, NULL, (SUBR)hrtferxk}, + { "hrtfer", sizeof(HRTFER), 0, 5, "aa", "akkS", + (SUBR)hrtferxkSet, NULL, (SUBR)hrtferxk}, }; -LINKAGE1(hrtferX_localops) +LINKAGE_BUILTIN(hrtferX_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/hrtferx.h csound-6.02~dfsg/Opcodes/hrtferx.h --- csound-5.17.11~dfsg/Opcodes/hrtferx.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/hrtferx.h 2014-01-07 16:53:48.000000000 +0000 @@ -1,24 +1,24 @@ /* - hrtferx.h: + hrtferx.h: - Copyright (C) 1995, 2001 Eli Breder, David McIntyre, John ffitch + Copyright (C) 1995, 2001 Eli Breder, David McIntyre, John ffitch - This file is part of Csound. + This file is part of Csound. - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ /****************** hrtferxk.h *******************/ @@ -27,8 +27,10 @@ typedef struct { OPDS h; - MYFLT *aLeft, *aRight, *aIn, *kAz, *kElev, *ifilno; /* outputs and inputs */ - MEMFIL *mfp; /* file pointer */ + MYFLT *aLeft, *aRight, /* outputs */ + *aIn, *kAz, *kElev; + STRINGDAT *ifilno; /* and inputs */ + MEMFIL *mfp; /* file pointer */ int16 *fpbegin; int oldel_index, oldaz_index; int32 incount, outfront, outend, outcount; diff -Nru csound-5.17.11~dfsg/Opcodes/hrtfopcodes.c csound-6.02~dfsg/Opcodes/hrtfopcodes.c --- csound-5.17.11~dfsg/Opcodes/hrtfopcodes.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/hrtfopcodes.c 2014-01-07 16:53:48.000000000 +0000 @@ -143,7 +143,7 @@ /* Csound hrtf magnitude interpolation, phase truncation object */ -/* aleft,aright hrtfmove asrc, kaz, kel, ifilel, ifiler [, imode = 0, +/* aleft,aright hrtfmove asrc, kaz, kel, ifilel->data, ifiler [, imode = 0, ifade = 8, sr = 44100]... */ /* imode: minphase/phase truncation, ifade: no of buffers per fade for phase trunc., sr can be 44.1/48/96k */ @@ -153,7 +153,9 @@ OPDS h; /* outputs and inputs */ MYFLT *outsigl, *outsigr; - MYFLT *in, *kangle, *kelev, *ifilel, *ifiler, *omode, *ofade, *osr; + MYFLT *in, *kangle, *kelev; + STRINGDAT *ifilel, *ifiler; + MYFLT *omode, *ofade, *osr; /* check if relative source has changed! */ MYFLT anglev, elevv; @@ -255,7 +257,7 @@ sr = 44100; p->sr = sr; - if (UNLIKELY(csound->esr != sr)) + if (UNLIKELY(CS_ESR != sr)) csound->Message(csound, Str("\n\nWARNING!!:\nOrchestra SR not compatible" " with HRTF processing SR of: %.0f\n\n"), sr); @@ -275,8 +277,8 @@ } /* copy in string name */ - strncpy(filel, (char*) p->ifilel, MAXNAME); - strncpy(filer, (char*) p->ifiler, MAXNAME); + strncpy(filel, (char*) p->ifilel->data, MAXNAME); + strncpy(filer, (char*) p->ifiler->data, MAXNAME); /* reading files, with byte swap */ fpl = csound->ldmemfile2withCB(csound, filel, CSFTYPE_FLOATS_BINARY, @@ -503,13 +505,12 @@ MYFLT angle = *p->kangle; int counter = p->counter; - int n; /* pointers into HRTF files: floating point data (even in 64 bit csound) */ float *fpindexl; float *fpindexr; - int i,j,elevindex, angleindex, skip = 0; + int i,elevindex, angleindex, skip = 0; int minphase = p->minphase; int phasetrunc = p->phasetrunc; @@ -587,15 +588,25 @@ int mdtl = p->mdtl; int mdtr = p->mdtr; int posl, posr; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t j, nsmps = CS_KSMPS; MYFLT outvdl, outvdr, vdtl, vdtr, fracl, fracr, rpl, rpr; /* start indices at correct value (start of file)/ zero indices. */ fpindexl = (float *) p->fpbeginl; fpindexr = (float *) p->fpbeginr; - n = csound->ksmps; - - for(j = 0; j < n; j++) + if (UNLIKELY(offset)) { + memset(outsigl, '\0', offset*sizeof(MYFLT)); + memset(outsigr, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outsigl[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outsigr[nsmps], '\0', early*sizeof(MYFLT)); + } + for(j = offset; j < nsmps; j++) { /* ins and outs */ insig[counter] = in[j]; @@ -1326,7 +1337,7 @@ static source: January 10 */ /* overlap add convolution */ -/* aleft, aright hrtfstat ain, iang, iel, ifilel, ifiler [,iradius = 8.8, +/* aleft, aright hrtfstat ain, iang, iel, ifilel, ifiler->data [,iradius = 8.8, isr = 44100]...options of 48 and 96k sr */ /* see definitions above */ @@ -1336,7 +1347,9 @@ OPDS h; /* outputs and inputs */ MYFLT *outsigl, *outsigr; - MYFLT *in, *iangle, *ielev, *ifilel, *ifiler, *oradius, *osr; + MYFLT *in, *iangle, *ielev; + STRINGDAT *ifilel, *ifiler; + MYFLT *oradius, *osr; /*see definitions in INIT*/ int irlength, irlengthpad, overlapsize; @@ -1429,7 +1442,7 @@ sr = FL(44100.0); p->sr = sr; - if (UNLIKELY(csound->esr != sr)) + if (UNLIKELY(CS_ESR != sr)) csound->Message(csound, Str("\n\nWARNING!!:\nOrchestra SR not compatible with " "HRTF processing SR of: %.0f\n\n"), sr); @@ -1449,8 +1462,8 @@ } /* copy in string name... */ - strncpy(filel, (char*) p->ifilel, MAXNAME); - strncpy(filer, (char*) p->ifiler, MAXNAME); + strncpy(filel, (char*) p->ifilel->data, MAXNAME); + strncpy(filer, (char*) p->ifiler->data, MAXNAME); /* reading files, with byte swap */ fpl = csound->ldmemfile2withCB(csound, filel, CSFTYPE_FLOATS_BINARY, @@ -1474,7 +1487,7 @@ p->sroverN = sr/irlength; /* start indices at correct value (start of file)/ zero indices. - (don't need to store here, as only accessing in INIT) */ + (do not need to store here, as only accessing in INIT) */ fpindexl = (float *) fpl->beginp; fpindexr = (float *) fpr->beginp; @@ -1883,7 +1896,10 @@ MYFLT *overlapr = (MYFLT *)p->overlapr.auxp; int counter = p->counter; - int n, j, i; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t j, nsmps = CS_KSMPS; int irlength = p->irlength; int irlengthpad = p->irlengthpad; @@ -1891,9 +1907,16 @@ MYFLT sr = p->sr; - n = csound->ksmps; - - for(j = 0; j < n; j++) + if (UNLIKELY(offset)) { + memset(outsigl, '\0', offset*sizeof(MYFLT)); + memset(outsigr, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outsigl[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outsigr[nsmps], '\0', early*sizeof(MYFLT)); + } + for(j = offset; j < nsmps; j++) { /* ins and outs */ insig[counter] = in[j]; @@ -1975,7 +1998,9 @@ OPDS h; /* outputs and inputs */ MYFLT *outsigl, *outsigr; - MYFLT *in, *kangle, *kelev, *ifilel, *ifiler, *ooverlap, *oradius, *osr; + MYFLT *in, *kangle, *kelev; + STRINGDAT *ifilel, *ifiler; +MYFLT *ooverlap, *oradius, *osr; /* check if relative source has changed! */ MYFLT anglev, elevv; @@ -2047,7 +2072,7 @@ sr = 44100; p->sr = sr; - if (UNLIKELY(csound->esr != sr)) + if (UNLIKELY(CS_ESR != sr)) csound->Message(csound, Str("\n\nWARNING!!:\nOrchestra SR not compatible" "with HRTF processing SR of: %.0f\n\n"), sr); @@ -2059,8 +2084,8 @@ irlength = 256; /* copy in string name... */ - strncpy(filel, (char*) p->ifilel, MAXNAME); - strncpy(filer, (char*) p->ifiler, MAXNAME); + strncpy(filel, (char*) p->ifilel->data, MAXNAME); + strncpy(filer, (char*) p->ifiler->data, MAXNAME); /* reading files, with byte swap */ fpl = csound->ldmemfile2withCB(csound, filel, CSFTYPE_FLOATS_BINARY, @@ -2225,13 +2250,15 @@ int counter = p ->counter; int t = p ->t; - int n; /* pointers into HRTF files */ float *fpindexl; float *fpindexr; - int i, j, skip = 0; + int i, skip = 0; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t j, nsmps = CS_KSMPS; /* interpolation values */ MYFLT *lowl1 = (MYFLT *)p->lowl1.auxp; @@ -2264,10 +2291,17 @@ fpindexl = (float *) p->fpbeginl; fpindexr = (float *) p->fpbeginr; - n = csound->ksmps; - + if (UNLIKELY(offset)) { + memset(outsigl, '\0', offset*sizeof(MYFLT)); + memset(outsigr, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outsigl[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outsigr[nsmps], '\0', early*sizeof(MYFLT)); + } /* ksmps loop */ - for(j = 0; j < n; j++) + for(j = offset; j < nsmps; j++) { /* distribute the signal and apply the window */ /* according to a time pointer (kept by overlapskip[n]) */ @@ -2444,7 +2478,8 @@ } /* woodworth process */ - /* ITD formula, check which ear is relevant to calculate angle from */ + /* ITD formula, check which ear is relevant to calculate + angle from */ if(angle > FL(180.0)) radianangle = (angle - FL(180.0)) * PI_F / FL(180.0); else @@ -2502,7 +2537,8 @@ freq = (i / 2) * sroverN; - /* non linear itd...last value in array = 1.0, so back to itdww */ + /* non linear itd...last value in array = 1.0, + so back to itdww */ if(p->sr == 96000) { if ((i / 2) < 6) @@ -2620,12 +2656,12 @@ /* see csound manual (extending csound) for details of below */ static OENTRY hrtfopcodes_localops[] = { - { "hrtfmove", sizeof(hrtfmove),5, "aa", "akkSSooo", + { "hrtfmove", sizeof(hrtfmove),0, 5, "aa", "akkSSooo", (SUBR)hrtfmove_init, NULL, (SUBR)hrtfmove_process }, - { "hrtfstat", sizeof(hrtfstat),5, "aa", "aiiSSoo", + { "hrtfstat", sizeof(hrtfstat),0, 5, "aa", "aiiSSoo", (SUBR)hrtfstat_init, NULL, (SUBR)hrtfstat_process }, - { "hrtfmove2", sizeof(hrtfmove2),5, "aa", "akkSSooo", + { "hrtfmove2", sizeof(hrtfmove2),0, 5, "aa", "akkSSooo", (SUBR)hrtfmove2_init, NULL, (SUBR)hrtfmove2_process } }; -LINKAGE1(hrtfopcodes_localops) +LINKAGE_BUILTIN(hrtfopcodes_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/hrtfreverb.c csound-6.02~dfsg/Opcodes/hrtfreverb.c --- csound-5.17.11~dfsg/Opcodes/hrtfreverb.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/hrtfreverb.c 2014-01-07 16:53:48.000000000 +0000 @@ -78,58 +78,82 @@ msix,msix,msix,msix,msix,msix,msix,msix,msix,msix,msix,fsix}; static const MYFLT matrix24[576] = - {etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw, - mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw}; + {etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw, + mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,mtw,etw}; /* for delay line lengths */ static const int primes[229] = - { - 17, 23, 59, 71, 113, 127, 163, 191, 211, 229, - 271, 283, 313, 337, 359, 373, 409, 461, 541, 587, - 631, 691, 709, 773, 829, 863, 919, 971, 1039, 1069, - 1123, 1171, 1217, 1259, 1303, 1373, 1423, 1483, 1511, 1597, - 1627, 1669, 1733, 1787, 1847, 1867, 1913, 1951, 2027, 2081, - 2131, 2179, 2213, 2269, 2333, 2383, 2423, 2467, 2531, 2579, - 2617, 2671, 2729, 2789, 2837, 2861, 2917, 2999, 3011, 3083, - 3121, 3169, 3209, 3259, 3331, 3389, 3449, 3469, 3533, 3571, - 3613, 3671, 3727, 3779, 3821, 3889, 3917, 3989, 4001, 4051, - 4111, 4177, 4231, 4271, 4337, 4391, 4447, 4483, 4517, 4567, - 4621, 4691, 4733, 4787, 4817, 4861, 4919, 4967, 5023, 5077, - 5113, 5167, 5233, 5297, 5309, 5351, 5441, 5483, 5507, 5563, - 5641, 5683, 5711, 5783, 5821, 5857, 5927, 5981, 6011, 6067, - 6121, 6173, 6217, 6271, 6317, 6361, 6421, 6473, 6529, 6581, - 6607, 6661, 6733, 6793, 6841, 6883, 6911, 6961, 7027, 7057, - 7109, 7177, 7211, 7297, 7349, 7393, 7417, 7481, 7523, 7561, - 7607, 7673, 7717, 7789, 7841, 7879, 7919, 7963, 8017, 8081, - 8111, 8167, 8209, 8287, 8317, 8377, 8443, 8467, 8521, 8563, - 8623, 8677, 8713, 8761, 8831, 8867, 8923, 8963, 9013, 9059, - 9109, 9187, 9221, 9257, 9323, 9371, 9413, 9461, 9511, 9587, - 9631, 9679, 9721, 9781, 9803, 9859, 9949, 9973, 10039, 10079, - 10111, 10177, 10211, 10259, 10333, 10391, 10429, 10459, 10513, 10589, - 10607, 10663, 10711, 10799, 10831, 10859, 10909, 10979, 11003 - }; + { + 17, 23, 59, 71, 113, 127, 163, 191, 211, 229, + 271, 283, 313, 337, 359, 373, 409, 461, 541, 587, + 631, 691, 709, 773, 829, 863, 919, 971, 1039, 1069, + 1123, 1171, 1217, 1259, 1303, 1373, 1423, 1483, 1511, 1597, + 1627, 1669, 1733, 1787, 1847, 1867, 1913, 1951, 2027, 2081, + 2131, 2179, 2213, 2269, 2333, 2383, 2423, 2467, 2531, 2579, + 2617, 2671, 2729, 2789, 2837, 2861, 2917, 2999, 3011, 3083, + 3121, 3169, 3209, 3259, 3331, 3389, 3449, 3469, 3533, 3571, + 3613, 3671, 3727, 3779, 3821, 3889, 3917, 3989, 4001, 4051, + 4111, 4177, 4231, 4271, 4337, 4391, 4447, 4483, 4517, 4567, + 4621, 4691, 4733, 4787, 4817, 4861, 4919, 4967, 5023, 5077, + 5113, 5167, 5233, 5297, 5309, 5351, 5441, 5483, 5507, 5563, + 5641, 5683, 5711, 5783, 5821, 5857, 5927, 5981, 6011, 6067, + 6121, 6173, 6217, 6271, 6317, 6361, 6421, 6473, 6529, 6581, + 6607, 6661, 6733, 6793, 6841, 6883, 6911, 6961, 7027, 7057, + 7109, 7177, 7211, 7297, 7349, 7393, 7417, 7481, 7523, 7561, + 7607, 7673, 7717, 7789, 7841, 7879, 7919, 7963, 8017, 8081, + 8111, 8167, 8209, 8287, 8317, 8377, 8443, 8467, 8521, 8563, + 8623, 8677, 8713, 8761, 8831, 8867, 8923, 8963, 9013, 9059, + 9109, 9187, 9221, 9257, 9323, 9371, 9413, 9461, 9511, 9587, + 9631, 9679, 9721, 9781, 9803, 9859, 9949, 9973, 10039, 10079, + 10111, 10177, 10211, 10259, 10333, 10391, 10429, 10459, 10513, 10589, + 10607, 10663, 10711, 10799, 10831, 10859, 10909, 10979, 11003 + }; typedef struct { @@ -137,10 +161,12 @@ /* in / out */ /* outputs l/r and delay required for late del...*/ MYFLT *outsigl, *outsigr, *idel; - /* mean free path and order are optional, meanfp defaults to medium room, opcode - can be used as stand alone binaural reverb, or spatially accurate taking - meanfp and order from earlies opcode */ - MYFLT *insig, *ilowrt60, *ihighrt60, *ifilel, *ifiler, *osr, *omeanfp, *porder; + /* mean free path and order are optional, meanfp defaults to medium + room, opcode can be used as stand alone binaural reverb, or + spatially accurate taking meanfp and order from earlies opcode */ + MYFLT *insig, *ilowrt60, *ihighrt60; + STRINGDAT *ifilel, *ifiler; + MYFLT *osr, *omeanfp, *porder; /* internal data / class variables */ MYFLT delaytime; @@ -252,7 +278,7 @@ sr = 44100; p->sr = sr; - if (UNLIKELY(csound->esr != sr)) + if (UNLIKELY(CS_ESR != sr)) csound->Message(csound, Str("\n\nWARNING!!:\nOrchestra SR not compatible with" " HRTF processing SR of: %.0f\n\n"), sr); @@ -288,8 +314,8 @@ } /* copy in string name... */ - strcpy(filel, (char*) p->ifilel); - strcpy(filer, (char*) p->ifiler); + strcpy(filel, (char*) p->ifilel->data); + strcpy(filer, (char*) p->ifiler->data); /* reading files, with byte swap */ fpl = csound->ldmemfile2withCB(csound, filel, @@ -481,7 +507,7 @@ { basedelay = i - 1; if(primes[test] > meanfpordersamps) - csound->Message(csound, "\nfdn delay > earlies del..., fixed!"); + csound->Message(csound, Str("\nfdn delay > earlies del..., fixed!")); *p->idel = (meanfpordersamps - primes[test - 1]) / sr; break; } @@ -829,8 +855,9 @@ if(aip[i] > FL(0.99) || aip[i] < -FL(0.99)) { - csound->Message(csound, Str("\nwarning, approaching instability, fixed with " - "a flat late reverb!")); + csound->Message(csound, + Str("\nwarning, approaching instability, " + "fixed with a flat late reverb!")); clipcheck = 1; if(aip[i] > 0.99) rt60high = rt60low; @@ -853,7 +880,10 @@ int hrtfreverb_process(CSOUND *csound, hrtfreverb *p) { - int i, j, k, n = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int j, k; /* signals in, out */ MYFLT *in = p->insig, sigin; @@ -995,8 +1025,17 @@ ztf2 = p->ztf2; } + if (UNLIKELY(offset)) { + memset(outl, '\0', offset*sizeof(MYFLT)); + memset(outr, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outl[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outr[nsmps], '\0', early*sizeof(MYFLT)); + } /* processing loop */ - for(i=0; i < n; i++) + for(i=offset; i < nsmps; i++) { /* tonal filter: 1 - b pow(z,-1) / 1 - b 1/1-b in - b/1-b in(old) */ @@ -1297,11 +1336,10 @@ } static OENTRY hrtfreverb_localops[] = -{ - { - "hrtfreverb", sizeof(hrtfreverb), 5, "aai", "aiiSSoop", +{ { + "hrtfreverb", sizeof(hrtfreverb), 0,5, "aai", "aiiSSoop", (SUBR)hrtfreverb_init, NULL, (SUBR)hrtfreverb_process } }; -LINKAGE1(hrtfreverb_localops) +LINKAGE_BUILTIN(hrtfreverb_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/ifd.c csound-6.02~dfsg/Opcodes/ifd.c --- csound-5.17.11~dfsg/Opcodes/ifd.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ifd.c 2014-01-07 16:53:48.000000000 +0000 @@ -38,7 +38,7 @@ */ -#include "csdl.h" +#include "pvs_ops.h" #include "pstream.h" typedef struct _ifd { @@ -58,7 +58,7 @@ static int ifd_init(CSOUND * csound, IFD * p) { - int hsize, fftsize, hopsize, frames; + int fftsize, hopsize, frames; int *counter, wintype, i; MYFLT *winf, *dwinf; double alpha = 0.0, fac; @@ -71,14 +71,14 @@ frames = fftsize / hopsize; if (UNLIKELY((frames - (float) fftsize / hopsize) != 0.0f)) - csound->Die(csound, Str("pvsifd: fftsize should " + return csound->InitError(csound, Str("pvsifd: fftsize should " "be an integral multiple of hopsize")); if (UNLIKELY((fftsize & (fftsize - 1)))) - csound->Die(csound, Str("pvsifd: fftsize should be power-of-two")); + return csound->InitError(csound, + Str("pvsifd: fftsize should be power-of-two")); p->frames = frames; - hsize = fftsize / 2; if (p->sigframe.auxp == NULL || frames * fftsize * sizeof(MYFLT) > (unsigned int) p->sigframe.size) @@ -138,7 +138,8 @@ alpha = 0.5; break; default: - csound->Die(csound, Str("pvsifd: unsupported value for iwintype\n")); + return csound->InitError(csound, + Str("pvsifd: unsupported value for iwintype\n")); break; } fac = TWOPI / (fftsize - 1.0); @@ -152,8 +153,8 @@ p->norm += winf[i]; } - p->factor = csound->esr / TWOPI_F; - p->fund = csound->esr / fftsize; + p->factor = CS_ESR / TWOPI_F; + p->fund = CS_ESR / fftsize; return OK; } @@ -217,23 +218,26 @@ output[0] = outphases[0] = signal[0] * scl; output[1] = outphases[1] = outphases[fftsize + 1] = 0.0f; output[fftsize] = outphases[fftsize] = signal[1] * scl; - output[fftsize + 1] = csound->esr * FL(0.5); + output[fftsize + 1] = CS_ESR * FL(0.5); p->fout1->framecount++; p->fout2->framecount++; } static int ifd_process(CSOUND * csound, IFD * p) { - int i, n; + int i; MYFLT *sigin = p->in; MYFLT *sigframe = (MYFLT *) p->sigframe.auxp; int fftsize = p->fftsize; int *counter = (int *) p->counter.auxp; - int ksmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int frames = p->frames; int cnt = p->cnt; - for (n = 0; n < ksmps; n++) { + if (UNLIKELY(early)) nsmps -= early; + for (n = offset; n < nsmps; n++) { for (i = 0; i < frames; i++) { sigframe[i * fftsize + counter[i]] = sigin[n]; counter[i]++; @@ -253,7 +257,8 @@ static OENTRY localops[] = { - { "pvsifd", sizeof(IFD), 5, "ff", "aiiip", (SUBR) ifd_init, 0, (SUBR) ifd_process} + { "pvsifd", sizeof(IFD), 0, 5, "ff", "aiiip", + (SUBR) ifd_init, 0, (SUBR) ifd_process} }; int ifd_init_(CSOUND *csound) @@ -261,4 +266,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/imageOpcodes.c csound-6.02~dfsg/Opcodes/imageOpcodes.c --- csound-5.17.11~dfsg/Opcodes/imageOpcodes.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/imageOpcodes.c 2014-01-07 16:53:48.000000000 +0000 @@ -75,13 +75,16 @@ row (l->r t->b) so a pixel value in imageData is located at: (w*y+x)*3. */ +/* #undef CS_KSMPS */ +/* #define CS_KSMPS (csound->GetKsmps(csound)) */ + static Image * __doOpenImage(char * filename, CSOUND *csound) { #ifdef USE_LIBPNG +#define HS (8) FILE *fp; void *fd; - const int hs = 8; - unsigned char header[8]; + unsigned char header[HS]; png_structp png_ptr; png_infop info_ptr; /* png_infop end_ptr; */ @@ -91,7 +94,7 @@ int color_type; unsigned char *image_data; png_bytepp row_pointers; - int i; + unsigned int i; Image *img; @@ -103,11 +106,11 @@ return NULL; } - if (UNLIKELY(hs!=fread(header, 1, hs, fp))) + if (UNLIKELY(HS!=fread(header, 1, HS, fp))) csound->InitError(csound, Str("imageload: file %s is not in PNG format.\n"), filename); - is_png = !png_sig_cmp(header, 0, hs); + is_png = !png_sig_cmp(header, 0, HS); if (UNLIKELY(!is_png)) { csound->InitError(csound, @@ -140,7 +143,7 @@ /* } */ png_init_io(png_ptr, fp); - png_set_sig_bytes(png_ptr, hs); + png_set_sig_bytes(png_ptr, HS); png_read_info(png_ptr, info_ptr); { @@ -415,7 +418,7 @@ (Image **) csound->ReAlloc(csound, pimages->images, sizeof(Image *) * pimages->cnt); - strncpy(filename, (char*) p->ifilnam, 254); + strncpy(filename, (char*) (p->ifilnam->data), 254); img = __doOpenImage(filename, csound); @@ -490,7 +493,9 @@ MYFLT *tx = p->kx; MYFLT *ty = p->ky; - int i, n=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int w, h, x, y, pixel; pimages = (Images *) csound->QueryGlobalVariable(csound, @@ -499,12 +504,24 @@ w = img->w; h = img->h; - for (i = 0; i < n; i++) { + + if (UNLIKELY(offset)) { + memset(r, '\0', offset*sizeof(MYFLT)); + memset(g, '\0', offset*sizeof(MYFLT)); + memset(b, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + memset(&g[nsmps], '\0', early*sizeof(MYFLT)); + memset(&b[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = 0; i < nsmps; i++) { x = tx[i]*w; y = ty[i]*h; - if (x >= 0 && x < w && y >= 0 && y < h ) { + if ( x >= 0 && x < w && y >= 0 && y < h ) { pixel = (w*y+x)*3; r[i] = img->imageData[pixel]/FL(255.0); g[i] = img->imageData[pixel+1]/FL(255.0); @@ -532,7 +549,9 @@ MYFLT *tx = p->kx; MYFLT *ty = p->ky; - int i, n=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int h,w,x, y, pixel; pimages = (Images *) csound->QueryGlobalVariable(csound, @@ -542,7 +561,8 @@ w = img->w; h = img->h; - for (i = 0; i < n; i++) { + if (UNLIKELY(early)) nsmps -= early; + for (i = offset; i < nsmps; i++) { x = tx[i]*w; y = ty[i]*h; @@ -590,7 +610,7 @@ Image *img; char filename[255]; - strcpy(filename, (char*) p->ifilnam); + strcpy(filename, (char*) (p->ifilnam->data)); pimages = (Images *) csound->QueryGlobalVariable(csound, "imageOpcodes.images"); @@ -616,17 +636,16 @@ #define S(x) sizeof(x) static OENTRY image_localops[] = { - { "imageload", S(IMGLOAD), 1, "i", "S", (SUBR)imageload, NULL, NULL }, - { "imagecreate",S(IMGCREATE),1, "i", "ii", (SUBR)imagecreate, NULL, NULL }, - { "imagesize", S(IMGSIZE), 1, "ii", "i", (SUBR)imagesize, NULL, NULL }, - { "imagegetpixel", S(IMGGETPIXEL), 7, "sss", "ixx", + { "imageload", S(IMGLOAD), 0, 1, "i", "S", (SUBR)imageload, NULL, NULL }, + { "imagecreate",S(IMGCREATE),0, 1, "i", "ii", (SUBR)imagecreate, NULL, NULL }, + { "imagesize", S(IMGSIZE), 0, 1, "ii", "i", (SUBR)imagesize, NULL, NULL }, + { "imagegetpixel", S(IMGGETPIXEL), 0, 7, "sss", "ixx", (SUBR)imagegetpixel, (SUBR)imagegetpixel, (SUBR)imagegetpixel_a }, - { "imagesetpixel", S(IMGSETPIXEL), 7, "", "ixxxxx", + { "imagesetpixel", S(IMGSETPIXEL), 0, 7, "", "ixxxxx", (SUBR)imagesetpixel, (SUBR)imagesetpixel, (SUBR)imagesetpixel_a }, - { "imagesave", S(IMGSAVE), 1, "", "iS", (SUBR)imagesave, NULL, NULL }, - { "imagefree", S(IMGFREE), 1, "", "i", (SUBR)imagefree, NULL, NULL }, + { "imagesave", S(IMGSAVE), 0, 1, "", "iS", (SUBR)imagesave, NULL, NULL }, + { "imagefree", S(IMGFREE), 0, 1, "", "i", (SUBR)imagefree, NULL, NULL }, }; -LINKAGE1(image_localops) - +LINKAGE_BUILTIN(image_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/imageOpcodes.h csound-6.02~dfsg/Opcodes/imageOpcodes.h --- csound-5.17.11~dfsg/Opcodes/imageOpcodes.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/imageOpcodes.h 2014-01-07 16:54:20.000000000 +0000 @@ -38,7 +38,8 @@ typedef struct { OPDS h; - MYFLT *kn, *ifilnam ; + MYFLT *kn; + STRINGDAT *ifilnam ; } IMGLOAD; typedef struct @@ -67,7 +68,8 @@ typedef struct { OPDS h; - MYFLT *kn, *ifilnam; + MYFLT *kn; + STRINGDAT *ifilnam; } IMGSAVE; typedef struct diff -Nru csound-5.17.11~dfsg/Opcodes/jackTransport.c csound-6.02~dfsg/Opcodes/jackTransport.c --- csound-5.17.11~dfsg/Opcodes/jackTransport.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/jackTransport.c 2014-01-07 16:53:48.000000000 +0000 @@ -90,8 +90,8 @@ static OENTRY jackTransport_localops[] = { - { "jacktransport", S(JACKTRANSPORT), 1, "", "ij", + { "jacktransport", S(JACKTRANSPORT), 0, 1, "", "ij", (SUBR)jack_transport, NULL, NULL }, }; -LINKAGE1(jackTransport_localops) +LINKAGE_BUILTIN(jackTransport_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/jacko.cpp csound-6.02~dfsg/Opcodes/jacko.cpp --- csound-5.17.11~dfsg/Opcodes/jacko.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/jacko.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -802,8 +802,8 @@ struct JackoInit : public OpcodeBase { - MYFLT *ServerName; - MYFLT *SclientName; + STRINGDAT *ServerName; + STRINGDAT *SclientName; const char *serverName; const char *clientName; JackoState *jackoState; @@ -811,14 +811,14 @@ { serverName = csound->strarg2name(csound, (char *) 0, - ServerName, + ServerName->data, (char *)"default", - (int) csound->GetInputArgSMask(this)); + (int) 1); clientName = csound->strarg2name(csound, (char *) 0, - SclientName, + SclientName->data, (char *)"csound", - (int) csound->GetInputArgSMask(this)); + (int) 1); jackoState = new JackoState(csound, serverName, clientName); return OK; } @@ -920,8 +920,8 @@ { // Out. // Ins. - MYFLT *SexternalPortName; - MYFLT *ScsoundPortName; + STRINGDAT *SexternalPortName; + STRINGDAT *ScsoundPortName; // State. const char *csoundPortName; char csoundFullPortName[0x100]; @@ -937,15 +937,15 @@ clientName = jack_get_client_name(jackoState->jackClient); csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); externalPortName = csound->strarg2name(csound, (char *) 0, - SexternalPortName, + SexternalPortName->data, (char *)"csound", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); if (!csoundPort) { csoundPort = jack_port_register(jackoState->jackClient, @@ -990,7 +990,7 @@ // Out. MYFLT *asignal; // Ins. - MYFLT *ScsoundPortName; + STRINGDAT *ScsoundPortName; // State. const char *csoundPortName; JackoState *jackoState; @@ -1003,9 +1003,9 @@ csoundFramesPerTick = jackoState->csoundFramesPerTick; csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jackoState->audioInPorts[csoundPortName]; return result; } @@ -1025,8 +1025,8 @@ { // No outs. // Ins. - MYFLT *ScsoundPortName; - MYFLT *SexternalPortName; + STRINGDAT *ScsoundPortName; + STRINGDAT *SexternalPortName; // State. const char *csoundPortName; char csoundFullPortName[0x100]; @@ -1039,20 +1039,20 @@ int init(CSOUND *csound) { int result = OK; - frames = csound->GetKsmps(csound); + frames = opds.insdshead->ksmps; jackoState = getJackoState(csound); clientName = jack_get_client_name(jackoState->jackClient); csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); externalPortName = csound->strarg2name(csound, (char *) 0, - SexternalPortName, + SexternalPortName->data, (char *)"csound", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); if (!csoundPort) { csoundPort = jack_port_register(jackoState->jackClient, @@ -1097,7 +1097,7 @@ { // No outs. // Ins. - MYFLT *ScsoundPortName; + STRINGDAT *ScsoundPortName; MYFLT *asignal; // State. const char *csoundPortName; @@ -1111,9 +1111,9 @@ csoundFramesPerTick = jackoState->csoundFramesPerTick; csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jackoState->audioOutPorts[csoundPortName]; return result; } @@ -1133,8 +1133,8 @@ { // No outs. // Ins. - MYFLT *SexternalPortName; - MYFLT *ScsoundPortName; + STRINGDAT *SexternalPortName; + STRINGDAT *ScsoundPortName; // State. const char *csoundPortName; char csoundFullPortName[0x100]; @@ -1147,20 +1147,20 @@ int init(CSOUND *csound) { int result = OK; - frames = csound->GetKsmps(csound); + frames = opds.insdshead->ksmps; jackoState = getJackoState(csound); clientName = jack_get_client_name(jackoState->jackClient); csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); externalPortName = csound->strarg2name(csound, (char *) 0, - SexternalPortName, + SexternalPortName->data, (char *)"csound", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); if (!csoundPort) { csoundPort = jack_port_register(jackoState->jackClient, csoundPortName, @@ -1204,8 +1204,8 @@ { // No outs. // Ins. - MYFLT *ScsoundPortName; - MYFLT *SexternalPortName; + STRINGDAT *ScsoundPortName; + STRINGDAT *SexternalPortName; // State. const char *csoundPortName; char csoundFullPortName[0x100]; @@ -1218,20 +1218,20 @@ int init(CSOUND *csound) { int result = OK; - frames = csound->GetKsmps(csound); + frames = opds.insdshead->ksmps; jackoState = getJackoState(csound); clientName = jack_get_client_name(jackoState->jackClient); csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); std::sprintf(csoundFullPortName, "%s:%s", clientName, csoundPortName); externalPortName = csound->strarg2name(csound, (char *) 0, - SexternalPortName, + SexternalPortName->data, (char *)"csound", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jack_port_by_name(jackoState->jackClient, csoundFullPortName); if (!csoundPort) { csoundPort = jack_port_register(jackoState->jackClient, @@ -1275,7 +1275,7 @@ { // No outs. // Ins. - MYFLT *ScsoundPortName; + STRINGDAT *ScsoundPortName; MYFLT *kstatus; MYFLT *kchannel; MYFLT *kdata1; @@ -1301,9 +1301,9 @@ csoundFramesPerTick = jackoState->csoundFramesPerTick; csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jackoState->midiOutPorts[csoundPortName]; priorstatus = -1; priorchannel = -1; @@ -1351,7 +1351,7 @@ { // No outs. // Ins. - MYFLT *ScsoundPortName; + STRINGDAT *ScsoundPortName; MYFLT *ichannel; MYFLT *ikey; MYFLT *ivelocity; @@ -1372,9 +1372,9 @@ csoundFramesPerTick = jackoState->csoundFramesPerTick; csoundPortName = csound->strarg2name(csound, (char *)0, - ScsoundPortName, + ScsoundPortName->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 1); csoundPort = jackoState->midiOutPorts[csoundPortName]; status = 144; channel = (char) *ichannel; @@ -1465,6 +1465,7 @@ { (char *)"JackoInit", sizeof(JackoInit), + 0, 1, (char *)"", (char *)"SS", @@ -1475,6 +1476,7 @@ { (char *)"JackoInfo", sizeof(JackoInfo), + 0, 1, (char *)"", (char *)"", @@ -1485,6 +1487,7 @@ { (char *)"JackoFreewheel", sizeof(JackoFreewheel), + 0, 1, (char *)"", (char *)"i", @@ -1495,6 +1498,7 @@ { (char *)"JackoOn", sizeof(JackoOn), + 0, 1, (char *)"", (char *)"j", @@ -1505,6 +1509,7 @@ { (char *)"JackoAudioInConnect", sizeof(JackoAudioInConnect), + 0, 1, (char *)"", (char *)"SS", @@ -1515,6 +1520,7 @@ { (char *)"JackoAudioIn", sizeof(JackoAudioIn), + 0, 5, (char *)"a", (char *)"S", @@ -1525,6 +1531,7 @@ { (char *)"JackoAudioOutConnect", sizeof(JackoAudioOutConnect), + 0, 1, (char *)"", (char *)"SS", @@ -1535,6 +1542,7 @@ { (char *)"JackoAudioOut", sizeof(JackoAudioOut), + 0, 5, (char *)"", (char *)"Sa", @@ -1545,6 +1553,7 @@ { (char *)"JackoMidiInConnect", sizeof(JackoMidiInConnect), + 0, 1, (char *)"", (char *)"SS", @@ -1555,6 +1564,7 @@ { (char *)"JackoMidiOutConnect", sizeof(JackoMidiOutConnect), + 0, 1, (char *)"", (char *)"SS", @@ -1565,6 +1575,7 @@ { (char *)"JackoMidiOut", sizeof(JackoMidiOut), + 0, 3, (char *)"", (char *)"SkkkO", @@ -1575,6 +1586,7 @@ { (char *)"JackoNoteOut", sizeof(JackoNoteOut), + 0, 3, (char *)"", (char *)"Siii", @@ -1585,6 +1597,7 @@ { (char *)"JackoTransport", sizeof(JackoTransport), + 0, 3, (char *)"", (char *)"kO", // O defaults to 0. @@ -1592,7 +1605,7 @@ (SUBR)&JackoTransport::kontrol_, 0 }, - { 0, 0, 0, 0, 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 } + { 0, 0, 0, 0, 0, 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 } }; @@ -1609,6 +1622,7 @@ err |= csound->AppendOpcode(csound, ep->opname, ep->dsblksiz, + ep->flags, ep->thread, ep->outypes, ep->intypes, @@ -1625,7 +1639,8 @@ int result = OK; #pragma omp critical { - std::map::iterator it = jackoStatesForCsoundInstances.find(csound); + std::map::iterator it = + jackoStatesForCsoundInstances.find(csound); if (it != jackoStatesForCsoundInstances.end()) { //delete it->second; jackoStatesForCsoundInstances.erase(it); diff -Nru csound-5.17.11~dfsg/Opcodes/linear_algebra.cpp csound-6.02~dfsg/Opcodes/linear_algebra.cpp --- csound-5.17.11~dfsg/Opcodes/linear_algebra.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/linear_algebra.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -86,7 +86,8 @@ * ivr la_i_vr_create irows * ivc la_i_vc_create irows * imr la_i_mr_create irows, icolumns [, odiagonal] - * imc la_i_mc_create irows, icolumns [, odiagonal_r, odiagonal_i] + * imc la_i_mc_create irows, icolumns + [, odiagonal_r, odiagonal_i] * * Array Introspection * ------------------- @@ -152,8 +153,10 @@ * kvc la_k_vc_set krow, kvalue_r, kvalue_i * imr la_i mr_set irow, icolumn, ivalue * kmr la_k mr_set krow, kcolumn, ivalue - * imc la_i_mc_set irow, icolumn, ivalue_r, ivalue_i - * kmc la_k_mc_set krow, kcolumn, kvalue_r, kvalue_i + * imc la_i_mc_set irow, icolumn, ivalue_r, + ivalue_i + * kmc la_k_mc_set krow, kcolumn, kvalue_r, + kvalue_i * * ivalue la_i_get_vr ivr, irow * kvalue la_k_get_vr ivr, krow, @@ -330,6 +333,14 @@ #include } +#ifdef ST +#undef ST +#endif + +#ifdef WR +#undef WR +#endif + #include #include #include @@ -578,6 +589,7 @@ * endif * ; THIRD, assignments from vectors to a-rate variables. */ + class la_k_current_vr_t : public OpcodeBase { public: @@ -590,13 +602,13 @@ { rhs = 0; toa(rhs_ivr, rhs); - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; vector_size = gmm::vect_size(rhs->vr); return OK; } int kontrol(CSOUND *csound) { - size_t frame_count = csound->kcounter * ksmps; + size_t frame_count = opds.insdshead->kcounter * ksmps; size_t index = frame_count % vector_size; if (index == 0) { *k_current = 1.0; @@ -822,15 +834,18 @@ int init(CSOUND *csound) { toa(i_vr, lhs); - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; vector_size = gmm::vect_size(lhs->vr); return OK; } int kontrol(CSOUND *csound) { - size_t frame_count = csound->kcounter * ksmps; + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + size_t frame_count = opds.insdshead->ksmps * ksmps; size_t array_i = frame_count % vector_size; - for (size_t i = 0; i < ksmps; ++i, ++array_i) { + if (UNLIKELY(early)) ksmps -= early; + for (size_t i = offset; i < ksmps; ++i, ++array_i) { lhs->vr[array_i] = a_a[i]; } return OK; @@ -919,14 +934,18 @@ int init(CSOUND *csound) { toa(i_vr, rhs); - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; return OK; } int kontrol(CSOUND *csound) { - size_t frameCount = csound->kcounter * csound->ksmps; + uint32_t offset = opds.insdshead->ksmps_offset; + uint32_t early = opds.insdshead->ksmps_no_end; + memset(a_a, '\0', offset*sizeof(MYFLT)); + size_t frameCount = opds.insdshead->kcounter * opds.insdshead->ksmps; size_t vectorSize = gmm::vect_size(rhs->vr); size_t array_i = frameCount % vectorSize; + if (UNLIKELY(early)) ksmps -= early; for (size_t i = 0; i < ksmps; ++i, ++array_i) { a_a[i] = rhs->vr[array_i]; } @@ -1252,7 +1271,8 @@ int init(CSOUND *) { toa(i_mc, mc); - mc->mc(size_t(*i_row), size_t(*i_column)) = std::complex(*i_value_r, *i_value_i); + mc->mc(size_t(*i_row), size_t(*i_column)) = + std::complex(*i_value_r, *i_value_i); return OK; } }; @@ -1273,7 +1293,8 @@ } int kontrol(CSOUND *) { - mc->mc(size_t(*k_row), size_t(*k_column)) = std::complex(*k_value_r, *k_value_i); + mc->mc(size_t(*k_row), size_t(*k_column)) = + std::complex(*k_value_r, *k_value_i); return OK; } }; @@ -3196,7 +3217,8 @@ size_t columnN = gmm::mat_ncols(rhs_a->mr); for (size_t rowI = 0; rowI < rowN; ++rowI) { for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = rhs_a->mr(rowI, columnI) / rhs_b->mr(rowI, columnI); + lhs->mr(rowI, columnI) = rhs_a->mr(rowI, columnI) / + rhs_b->mr(rowI, columnI); } } return OK; @@ -3232,7 +3254,8 @@ { for (size_t rowI = 0; rowI < rowN; ++rowI) { for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mr(rowI, columnI) = rhs_a->mr(rowI, columnI) / rhs_b->mr(rowI, columnI); + lhs->mr(rowI, columnI) = rhs_a->mr(rowI, columnI) / + rhs_b->mr(rowI, columnI); } } return OK; @@ -3262,7 +3285,8 @@ size_t columnN = gmm::mat_ncols(rhs_a->mc); for (size_t rowI = 0; rowI < rowN; ++rowI) { for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = rhs_a->mc(rowI, columnI) / rhs_b->mc(rowI, columnI); + lhs->mc(rowI, columnI) = rhs_a->mc(rowI, columnI) / + rhs_b->mc(rowI, columnI); } } return OK; @@ -3298,7 +3322,8 @@ { for (size_t rowI = 0; rowI < rowN; ++rowI) { for (size_t columnI = 0; columnI < columnN; ++columnI) { - lhs->mc(rowI, columnI) = rhs_a->mc(rowI, columnI) / rhs_b->mc(rowI, columnI); + lhs->mc(rowI, columnI) = rhs_a->mc(rowI, columnI) / + rhs_b->mc(rowI, columnI); } } return OK; @@ -4193,7 +4218,8 @@ toa(lhs_eigenvalues_, lhs_eigenvalues); toa(lhs_eigenvectors_, lhs_eigenvectors); toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, lhs_eigenvectors->mr, double(*itolerance)); + gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, + lhs_eigenvectors->mr, double(*itolerance)); return OK; } }; @@ -4217,7 +4243,8 @@ } int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, lhs_eigenvectors->mr, double(*ktolerance)); + gmm::implicit_qr_algorithm(rhs_A->mr, lhs_eigenvalues->vr, + lhs_eigenvectors->mr, double(*ktolerance)); return OK; } }; @@ -4237,7 +4264,8 @@ toa(lhs_eigenvalues_, lhs_eigenvalues); toa(lhs_eigenvectors_, lhs_eigenvectors); toa(rhs_A_, rhs_A); - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, lhs_eigenvectors->mc, double(*itolerance)); + gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, + lhs_eigenvectors->mc, double(*itolerance)); return OK; } }; @@ -4261,7 +4289,8 @@ } int kontrol(CSOUND *) { - gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, lhs_eigenvectors->mc, double(*ktolerance)); + gmm::implicit_qr_algorithm(rhs_A->mc, lhs_eigenvalues->vc, + lhs_eigenvectors->mc, double(*ktolerance)); return OK; } }; @@ -4281,6 +4310,7 @@ csound->AppendOpcode(csound, "la_i_vr_create", sizeof(la_i_vr_create_t), + 0, 1, "i", "i", @@ -4291,6 +4321,7 @@ csound->AppendOpcode(csound, "la_i_vc_create", sizeof(la_i_vr_create_t), + 0, 1, "i", "i", @@ -4301,6 +4332,7 @@ csound->AppendOpcode(csound, "la_i_mr_create", sizeof(la_i_mr_create_t), + 0, 1, "i", "iio", @@ -4311,6 +4343,7 @@ csound->AppendOpcode(csound, "la_i_mc_create", sizeof(la_i_mc_create_t), + 0, 1, "i", "iioo", @@ -4321,6 +4354,7 @@ csound->AppendOpcode(csound, "la_i_size_vr", sizeof(la_i_size_vr_t), + 0, 1, "i", "i", @@ -4331,6 +4365,7 @@ csound->AppendOpcode(csound, "la_i_size_vc", sizeof(la_i_size_vc_t), + 0, 1, "i", "i", @@ -4341,6 +4376,7 @@ csound->AppendOpcode(csound, "la_i_size_mr", sizeof(la_i_size_mr_t), + 0, 1, "ii", "i", @@ -4351,6 +4387,7 @@ csound->AppendOpcode(csound, "la_i_size_mc", sizeof(la_i_size_mc_t), + 0, 1, "ii", "i", @@ -4361,6 +4398,7 @@ csound->AppendOpcode(csound, "la_k_current_f", sizeof(la_k_current_f_t), + 0, 3, "k", "f", @@ -4371,6 +4409,7 @@ csound->AppendOpcode(csound, "la_k_current_vr", sizeof(la_k_current_vr_t), + 0, 3, "k", "i", @@ -4381,6 +4420,7 @@ csound->AppendOpcode(csound, "la_i_print_vr", sizeof(la_i_print_vr_t), + 0, 1, "", "i", @@ -4391,6 +4431,7 @@ csound->AppendOpcode(csound, "la_i_print_vc", sizeof(la_i_print_vc_t), + 0, 1, "", "i", @@ -4401,6 +4442,7 @@ csound->AppendOpcode(csound, "la_i_print_mr", sizeof(la_i_print_mr_t), + 0, 1, "", "i", @@ -4411,6 +4453,7 @@ csound->AppendOpcode(csound, "la_i_print_mc", sizeof(la_i_print_mc_t), + 0, 1, "", "i", @@ -4421,6 +4464,7 @@ csound->AppendOpcode(csound, "la_i_assign_vr", sizeof(la_i_assign_vr_t), + 0, 1, "i", "i", @@ -4431,6 +4475,7 @@ csound->AppendOpcode(csound, "la_k_assign_vr", sizeof(la_k_assign_vr_t), + 0, 3, "i", "k", @@ -4441,6 +4486,7 @@ csound->AppendOpcode(csound, "la_i_assign_vc", sizeof(la_i_assign_vc_t), + 0, 1, "i", "i", @@ -4451,6 +4497,7 @@ csound->AppendOpcode(csound, "la_k_assign_vc", sizeof(la_k_assign_vc_t), + 0, 3, "i", "k", @@ -4461,6 +4508,7 @@ csound->AppendOpcode(csound, "la_i_assign_mr", sizeof(la_i_assign_mr_t), + 0, 1, "i", "i", @@ -4471,6 +4519,7 @@ csound->AppendOpcode(csound, "la_k_assign_mr", sizeof(la_k_assign_mr_t), + 0, 3, "i", "k", @@ -4481,6 +4530,7 @@ csound->AppendOpcode(csound, "la_i_assign_mc", sizeof(la_i_assign_mc_t), + 0, 1, "i", "i", @@ -4491,6 +4541,7 @@ csound->AppendOpcode(csound, "la_k_assign_mc", sizeof(la_k_assign_mc_t), + 0, 3, "i", "k", @@ -4501,6 +4552,7 @@ csound->AppendOpcode(csound, "la_k_assign_a", sizeof(la_k_assign_a_t), + 0, 3, "i", "a", @@ -4511,6 +4563,7 @@ csound->AppendOpcode(csound, "la_i_assign_t", sizeof(la_i_assign_t_t), + TR, 1, "i", "i", @@ -4521,6 +4574,7 @@ csound->AppendOpcode(csound, "la_k_assign_t", sizeof(la_k_assign_t_t), + TR, 3, "i", "k", @@ -4531,6 +4585,7 @@ csound->AppendOpcode(csound, "la_k_assign_f", sizeof(la_k_assign_f_t), + 0, 3, "i", "f", @@ -4541,6 +4596,7 @@ csound->AppendOpcode(csound, "la_k_a_assign", sizeof(la_k_a_assign_t), + 0, 3, "a", "k", @@ -4551,6 +4607,7 @@ csound->AppendOpcode(csound, "la_i_t_assign", sizeof(la_i_t_assign_t), + TW, 1, "i", "i", @@ -4561,6 +4618,7 @@ csound->AppendOpcode(csound, "la_k_t_assign", sizeof(la_k_t_assign_t), + TW, 3, "i", "k", @@ -4571,6 +4629,7 @@ csound->AppendOpcode(csound, "la_k_f_assign", sizeof(la_k_f_assign_t), + 0, 3, "f", "p", @@ -4581,6 +4640,7 @@ csound->AppendOpcode(csound, "la_i_random_vr", sizeof(la_i_random_vr_t), + 0, 1, "i", "p", @@ -4591,6 +4651,7 @@ csound->AppendOpcode(csound, "la_k_random_vr", sizeof(la_k_random_vr_t), + 0, 3, "i", "p", @@ -4601,6 +4662,7 @@ csound->AppendOpcode(csound, "la_i_random_vc", sizeof(la_i_random_vc_t), + 0, 1, "i", "p", @@ -4611,6 +4673,7 @@ csound->AppendOpcode(csound, "la_k_random_vc", sizeof(la_k_random_vc_t), + 0, 3, "i", "p", @@ -4621,6 +4684,7 @@ csound->AppendOpcode(csound, "la_i_random_mr", sizeof(la_i_random_mr_t), + 0, 1, "i", "p", @@ -4631,6 +4695,7 @@ csound->AppendOpcode(csound, "la_k_random_mr", sizeof(la_k_random_mr_t), + 0, 3, "i", "p", @@ -4641,6 +4706,7 @@ csound->AppendOpcode(csound, "la_i_random_mc", sizeof(la_i_random_mc_t), + 0, 1, "i", "p", @@ -4651,6 +4717,7 @@ csound->AppendOpcode(csound, "la_k_random_mc", sizeof(la_k_random_mc_t), + 0, 3, "i", "p", @@ -4661,6 +4728,7 @@ csound->AppendOpcode(csound, "la_i_vr_set", sizeof(la_i_vr_set_t), + 0, 1, "i", "ii", @@ -4671,6 +4739,7 @@ csound->AppendOpcode(csound, "la_k_vr_set", sizeof(la_k_vr_set_t), + 0, 3, "i", "kk", @@ -4681,6 +4750,7 @@ csound->AppendOpcode(csound, "la_i_vc_set", sizeof(la_i_vc_set_t), + 0, 1, "i", "iii", @@ -4691,6 +4761,7 @@ csound->AppendOpcode(csound, "la_k_vc_set", sizeof(la_k_vc_set_t), + 0, 3, "i", "kkk", @@ -4701,6 +4772,7 @@ csound->AppendOpcode(csound, "la_i_mr_set", sizeof(la_i_mr_set_t), + 0, 1, "i", "iii", @@ -4711,6 +4783,7 @@ csound->AppendOpcode(csound, "la_k_mr_set", sizeof(la_k_mr_set_t), + 0, 3, "i", "kkk", @@ -4721,6 +4794,7 @@ csound->AppendOpcode(csound, "la_i_mc_set", sizeof(la_i_mc_set_t), + 0, 1, "i", "iiii", @@ -4731,6 +4805,7 @@ csound->AppendOpcode(csound, "la_k_mc_set", sizeof(la_k_mc_set_t), + 0, 3, "i", "kkkk", @@ -4742,6 +4817,7 @@ csound->AppendOpcode(csound, "la_i_get_vr", sizeof(la_i_get_vr_t), + 0, 1, "i", "ii", @@ -4752,6 +4828,7 @@ csound->AppendOpcode(csound, "la_k_get_vr", sizeof(la_k_get_vr_t), + 0, 3, "k", "ik", @@ -4762,6 +4839,7 @@ csound->AppendOpcode(csound, "la_i_get_vc", sizeof(la_i_get_vc_t), + 0, 1, "ii", "ii", @@ -4772,6 +4850,7 @@ csound->AppendOpcode(csound, "la_k_get_vc", sizeof(la_k_get_vc_t), + 0, 3, "kk", "ik", @@ -4782,6 +4861,7 @@ csound->AppendOpcode(csound, "la_i_get_mr", sizeof(la_i_get_mr_t), + 0, 1, "i", "iii", @@ -4792,6 +4872,7 @@ csound->AppendOpcode(csound, "la_k_get_mr", sizeof(la_k_get_mr_t), + 0, 3, "k", "ikk", @@ -4802,6 +4883,7 @@ csound->AppendOpcode(csound, "la_i_get_mc", sizeof(la_i_get_mc_t), + 0, 1, "ii", "iii", @@ -4812,6 +4894,7 @@ csound->AppendOpcode(csound, "la_k_get_mc", sizeof(la_k_get_mc_t), + 0, 3, "kk", "ikk", @@ -4822,6 +4905,7 @@ csound->AppendOpcode(csound, "la_i_transpose_mr", sizeof(la_i_transpose_mr_t), + 0, 1, "i", "i", @@ -4832,6 +4916,7 @@ csound->AppendOpcode(csound, "la_i_transpose_mr", sizeof(la_k_transpose_mr_t), + 0, 3, "i", "k", @@ -4842,6 +4927,7 @@ csound->AppendOpcode(csound, "la_i_transpose_mc", sizeof(la_i_transpose_mc_t), + 0, 1, "i", "i", @@ -4852,6 +4938,7 @@ csound->AppendOpcode(csound, "la_i_transpose_mc", sizeof(la_k_transpose_mc_t), + 0, 2, "i", "i", @@ -4862,6 +4949,7 @@ csound->AppendOpcode(csound, "la_i_conjugate_vr", sizeof(la_i_conjugate_vr_t), + 0, 1, "i", "i", @@ -4872,6 +4960,7 @@ csound->AppendOpcode(csound, "la_k_conjugate_vr", sizeof(la_k_conjugate_vr_t), + 0, 3, "i", "i", @@ -4882,6 +4971,7 @@ csound->AppendOpcode(csound, "la_i_conjugate_vc", sizeof(la_i_conjugate_vc_t), + 0, 1, "i", "i", @@ -4892,6 +4982,7 @@ csound->AppendOpcode(csound, "la_k_conjugate_vc", sizeof(la_k_conjugate_vc_t), + 0, 3, "i", "i", @@ -4902,6 +4993,7 @@ csound->AppendOpcode(csound, "la_i_conjugate_mr", sizeof(la_i_conjugate_mr_t), + 0, 1, "i", "i", @@ -4912,6 +5004,7 @@ csound->AppendOpcode(csound, "la_k_conjugate_mr", sizeof(la_k_conjugate_mr_t), + 0, 3, "i", "i", @@ -4922,6 +5015,7 @@ csound->AppendOpcode(csound, "la_i_conjugate_mc", sizeof(la_i_conjugate_mc_t), + 0, 1, "i", "i", @@ -4932,6 +5026,7 @@ csound->AppendOpcode(csound, "la_k_conjugate_mc", sizeof(la_k_conjugate_mc_t), + 0, 3, "i", "i", @@ -4942,6 +5037,7 @@ csound->AppendOpcode(csound, "la_i_norm1_vr", sizeof(la_i_norm1_vr_t), + 0, 1, "i", "i", @@ -4952,6 +5048,7 @@ csound->AppendOpcode(csound, "la_k_norm1_vr", sizeof(la_k_norm1_vr_t), + 0, 3, "k", "i", @@ -4962,6 +5059,7 @@ csound->AppendOpcode(csound, "la_i_norm1_vc", sizeof(la_i_norm1_vc_t), + 0, 1, "i", "i", @@ -4972,6 +5070,7 @@ csound->AppendOpcode(csound, "la_k_norm1_vc", sizeof(la_k_norm1_vc_t), + 0, 3, "k", "i", @@ -4982,6 +5081,7 @@ csound->AppendOpcode(csound, "la_i_norm1_mr", sizeof(la_i_norm1_mr_t), + 0, 1, "i", "i", @@ -4992,6 +5092,7 @@ csound->AppendOpcode(csound, "la_k_norm1_mr", sizeof(la_k_norm1_mr_t), + 0, 3, "k", "i", @@ -5002,6 +5103,7 @@ csound->AppendOpcode(csound, "la_i_norm1_mc", sizeof(la_i_norm1_mc_t), + 0, 1, "i", "i", @@ -5012,6 +5114,7 @@ csound->AppendOpcode(csound, "la_k_norm1_mc", sizeof(la_k_norm1_mc_t), + 0, 3, "k", "i", @@ -5022,6 +5125,7 @@ csound->AppendOpcode(csound, "la_i_norm_euclid_vr", sizeof(la_i_norm_euclid_vr_t), + 0, 1, "i", "i", @@ -5032,6 +5136,7 @@ csound->AppendOpcode(csound, "la_k_norm_euclid_vr", sizeof(la_k_norm_euclid_vr_t), + 0, 3, "k", "i", @@ -5042,6 +5147,7 @@ csound->AppendOpcode(csound, "la_i_norm_euclid_vc", sizeof(la_i_norm_euclid_vc_t), + 0, 1, "i", "i", @@ -5052,6 +5158,7 @@ csound->AppendOpcode(csound, "la_k_norm_euclid_vc", sizeof(la_k_norm_euclid_vc_t), + 0, 3, "k", "i", @@ -5062,6 +5169,7 @@ csound->AppendOpcode(csound, "la_i_norm_euclid_mr", sizeof(la_i_norm_euclid_mr_t), + 0, 1, "i", "i", @@ -5072,6 +5180,7 @@ csound->AppendOpcode(csound, "la_k_norm_euclid_mr", sizeof(la_k_norm_euclid_mr_t), + 0, 3, "k", "i", @@ -5082,6 +5191,7 @@ csound->AppendOpcode(csound, "la_i_norm_euclid_mc", sizeof(la_i_norm_euclid_mc_t), + 0, 1, "i", "i", @@ -5092,16 +5202,18 @@ csound->AppendOpcode(csound, "la_k_norm_euclid_mc", sizeof(la_k_norm_euclid_mc_t), + 0, 3, "k", "i", (int (*)(CSOUND*,void*)) &la_k_norm_euclid_mc_t::init_, - (int (*)(CSOUND*,void*)) &la_k_norm_euclid_mc_t::kontrol_, + (int (*)(CSOUND*,void*))&la_k_norm_euclid_mc_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_distance_vr", sizeof(la_i_distance_vr_t), + 0, 1, "i", "ii", @@ -5112,6 +5224,7 @@ csound->AppendOpcode(csound, "la_k_distance_vr", sizeof(la_k_distance_vr_t), + 0, 3, "k", "ii", @@ -5122,6 +5235,7 @@ csound->AppendOpcode(csound, "la_i_distance_vc", sizeof(la_i_distance_vc_t), + 0, 1, "i", "ii", @@ -5132,6 +5246,7 @@ csound->AppendOpcode(csound, "la_k_distance_vc", sizeof(la_k_distance_vc_t), + 0, 3, "k", "ii", @@ -5142,6 +5257,7 @@ csound->AppendOpcode(csound, "la_i_norm_max_mr", sizeof(la_i_norm_max_mr_t), + 0, 1, "i", "i", @@ -5152,6 +5268,7 @@ csound->AppendOpcode(csound, "la_k_norm_max_mr", sizeof(la_k_norm_max_mr_t), + 0, 3, "k", "i", @@ -5162,6 +5279,7 @@ csound->AppendOpcode(csound, "la_i_norm_max_mc", sizeof(la_i_norm_max_mc_t), + 0, 1, "i", "i", @@ -5172,6 +5290,7 @@ csound->AppendOpcode(csound, "la_k_norm_max_mc", sizeof(la_k_norm_max_mc_t), + 0, 3, "k", "i", @@ -5182,6 +5301,7 @@ csound->AppendOpcode(csound, "la_i_norm_inf_vr", sizeof(la_i_norm_inf_vr_t), + 0, 1, "i", "i", @@ -5192,6 +5312,7 @@ csound->AppendOpcode(csound, "la_k_norm_inf_vr", sizeof(la_k_norm_inf_vr_t), + 0, 3, "k", "i", @@ -5202,6 +5323,7 @@ csound->AppendOpcode(csound, "la_i_norm_inf_vc", sizeof(la_i_norm_inf_vc_t), + 0, 1, "i", "i", @@ -5212,6 +5334,7 @@ csound->AppendOpcode(csound, "la_k_norm_inf_vc", sizeof(la_k_norm_inf_vc_t), + 0, 3, "k", "i", @@ -5222,6 +5345,7 @@ csound->AppendOpcode(csound, "la_i_norm_inf_mr", sizeof(la_i_norm_inf_mr_t), + 0, 1, "i", "i", @@ -5232,6 +5356,7 @@ csound->AppendOpcode(csound, "la_k_norm_inf_mr", sizeof(la_k_norm_inf_mr_t), + 0, 3, "k", "i", @@ -5242,6 +5367,7 @@ csound->AppendOpcode(csound, "la_i_norm_inf_mc", sizeof(la_i_norm_inf_mc_t), + 0, 1, "i", "i", @@ -5252,6 +5378,7 @@ csound->AppendOpcode(csound, "la_k_norm_inf_mc", sizeof(la_k_norm_inf_mc_t), + 0, 3, "k", "i", @@ -5262,6 +5389,7 @@ csound->AppendOpcode(csound, "la_i_trace_mr", sizeof(la_i_trace_mr_t), + 0, 1, "i", "i", @@ -5272,6 +5400,7 @@ csound->AppendOpcode(csound, "la_k_trace_mr", sizeof(la_k_trace_mr_t), + 0, 3, "k", "i", @@ -5282,6 +5411,7 @@ csound->AppendOpcode(csound, "la_i_trace_mc", sizeof(la_i_trace_mc_t), + 0, 1, "ii", "i", @@ -5292,6 +5422,7 @@ csound->AppendOpcode(csound, "la_k_trace_mc", sizeof(la_k_trace_mc_t), + 0, 3, "kk", "i", @@ -5302,6 +5433,7 @@ csound->AppendOpcode(csound, "la_i_lu_det_mr", sizeof(la_i_lu_det_mr_t), + 0, 1, "i", "i", @@ -5312,6 +5444,7 @@ csound->AppendOpcode(csound, "la_k_lu_det_mr", sizeof(la_k_lu_det_mr_t), + 0, 3, "k", "i", @@ -5322,6 +5455,7 @@ csound->AppendOpcode(csound, "la_i_lu_det_mc", sizeof(la_i_lu_det_mc_t), + 0, 1, "ii", "i", @@ -5332,6 +5466,7 @@ csound->AppendOpcode(csound, "la_k_lu_det_mc", sizeof(la_k_lu_det_mc_t), + 0, 3, "kk", "i", @@ -5342,6 +5477,7 @@ csound->AppendOpcode(csound, "la_i_add_vr", sizeof(la_i_add_vr_t), + 0, 1, "i", "ii", @@ -5352,6 +5488,7 @@ csound->AppendOpcode(csound, "la_k_add_vr", sizeof(la_k_add_vr_t), + 0, 3, "i", "ii", @@ -5362,6 +5499,7 @@ csound->AppendOpcode(csound, "la_i_add_vc", sizeof(la_i_add_vc_t), + 0, 1, "i", "ii", @@ -5372,6 +5510,7 @@ csound->AppendOpcode(csound, "la_k_add_vc", sizeof(la_k_add_vc_t), + 0, 3, "i", "ii", @@ -5382,6 +5521,7 @@ csound->AppendOpcode(csound, "la_i_add_mr", sizeof(la_i_add_mr_t), + 0, 1, "i", "ii", @@ -5392,6 +5532,7 @@ csound->AppendOpcode(csound, "la_k_add_mr", sizeof(la_k_add_mr_t), + 0, 3, "i", "ii", @@ -5402,6 +5543,7 @@ csound->AppendOpcode(csound, "la_i_add_mc", sizeof(la_i_add_mc_t), + 0, 1, "i", "ii", @@ -5412,6 +5554,7 @@ csound->AppendOpcode(csound, "la_k_add_mc", sizeof(la_k_add_mc_t), + 0, 3, "i", "ii", @@ -5422,6 +5565,7 @@ csound->AppendOpcode(csound, "la_i_subtract_vr", sizeof(la_i_subtract_vr_t), + 0, 1, "i", "ii", @@ -5432,6 +5576,7 @@ csound->AppendOpcode(csound, "la_k_subtract_vr", sizeof(la_k_subtract_vr_t), + 0, 3, "i", "ii", @@ -5442,6 +5587,7 @@ csound->AppendOpcode(csound, "la_i_subtract_vc", sizeof(la_i_subtract_vc_t), + 0, 1, "i", "ii", @@ -5452,6 +5598,7 @@ csound->AppendOpcode(csound, "la_k_subtract_vc", sizeof(la_k_subtract_vc_t), + 0, 3, "i", "ii", @@ -5462,6 +5609,7 @@ csound->AppendOpcode(csound, "la_i_subtract_mr", sizeof(la_i_subtract_mr_t), + 0, 1, "i", "ii", @@ -5472,6 +5620,7 @@ csound->AppendOpcode(csound, "la_k_subtract_mr", sizeof(la_k_subtract_mr_t), + 0, 3, "i", "ii", @@ -5482,6 +5631,7 @@ csound->AppendOpcode(csound, "la_i_subtract_mc", sizeof(la_i_subtract_mc_t), + 0, 1, "i", "ii", @@ -5492,6 +5642,7 @@ csound->AppendOpcode(csound, "la_k_subtract_mc", sizeof(la_k_subtract_mc_t), + 0, 3, "i", "ii", @@ -5502,6 +5653,7 @@ csound->AppendOpcode(csound, "la_i_multiply_vr", sizeof(la_i_multiply_vr_t), + 0, 1, "i", "ii", @@ -5512,6 +5664,7 @@ csound->AppendOpcode(csound, "la_k_multiply_vr", sizeof(la_k_multiply_vr_t), + 0, 3, "i", "ii", @@ -5522,6 +5675,7 @@ csound->AppendOpcode(csound, "la_i_multiply_vc", sizeof(la_i_multiply_vc_t), + 0, 1, "i", "ii", @@ -5532,6 +5686,7 @@ csound->AppendOpcode(csound, "la_k_multiply_vc", sizeof(la_k_multiply_vc_t), + 0, 3, "i", "ii", @@ -5542,6 +5697,7 @@ csound->AppendOpcode(csound, "la_i_multiply_mr", sizeof(la_i_multiply_mr_t), + 0, 1, "i", "ii", @@ -5552,6 +5708,7 @@ csound->AppendOpcode(csound, "la_k_multiply_mr", sizeof(la_k_multiply_mr_t), + 0, 3, "i", "ii", @@ -5562,6 +5719,7 @@ csound->AppendOpcode(csound, "la_i_multiply_mc", sizeof(la_i_multiply_mc_t), + 0, 1, "i", "ii", @@ -5572,6 +5730,7 @@ csound->AppendOpcode(csound, "la_k_multiply_mc", sizeof(la_k_multiply_mc_t), + 0, 3, "i", "ii", @@ -5584,6 +5743,7 @@ csound->AppendOpcode(csound, "la_i_divide_vr", sizeof(la_i_divide_vr_t), + 0, 1, "i", "ii", @@ -5594,6 +5754,7 @@ csound->AppendOpcode(csound, "la_k_divide_vr", sizeof(la_k_divide_vr_t), + 0, 3, "i", "ii", @@ -5604,6 +5765,7 @@ csound->AppendOpcode(csound, "la_i_divide_vc", sizeof(la_i_divide_vc_t), + 0, 1, "i", "ii", @@ -5614,6 +5776,7 @@ csound->AppendOpcode(csound, "la_k_divide_vc", sizeof(la_k_divide_vc_t), + 0, 3, "i", "kk", @@ -5624,6 +5787,7 @@ csound->AppendOpcode(csound, "la_i_divide_mr", sizeof(la_i_divide_mr_t), + 0, 1, "i", "ii", @@ -5634,6 +5798,7 @@ csound->AppendOpcode(csound, "la_k_divide_mr", sizeof(la_k_divide_mr_t), + 0, 3, "i", "ii", @@ -5644,6 +5809,7 @@ csound->AppendOpcode(csound, "la_i_divide_mc", sizeof(la_i_divide_mc_t), + 0, 1, "i", "ii", @@ -5654,6 +5820,7 @@ csound->AppendOpcode(csound, "la_k_divide_mc", sizeof(la_k_divide_mc_t), + 0, 3, "i", "ii", @@ -5664,6 +5831,7 @@ csound->AppendOpcode(csound, "la_i_dot_vr", sizeof(la_i_dot_vr_t), + 0, 1, "i", "ii", @@ -5674,6 +5842,7 @@ csound->AppendOpcode(csound, "la_k_dot_vr", sizeof(la_k_dot_vr_t), + 0, 3, "i", "ii", @@ -5684,6 +5853,7 @@ csound->AppendOpcode(csound, "la_i_dot_vc", sizeof(la_i_dot_vc_t), + 0, 1, "ii", "ii", @@ -5694,6 +5864,7 @@ csound->AppendOpcode(csound, "la_k_dot_vc", sizeof(la_k_dot_vc_t), + 0, 3, "ii", "ii", @@ -5704,6 +5875,7 @@ csound->AppendOpcode(csound, "la_i_dot_mr", sizeof(la_i_dot_mr_t), + 0, 1, "i", "ii", @@ -5714,6 +5886,7 @@ csound->AppendOpcode(csound, "la_k_dot_mr", sizeof(la_k_dot_mr_t), + 0, 3, "i", "ii", @@ -5724,6 +5897,7 @@ csound->AppendOpcode(csound, "la_i_dot_mc", sizeof(la_i_dot_mc_t), + 0, 1, "i", "ii", @@ -5734,6 +5908,7 @@ csound->AppendOpcode(csound, "la_k_dot_mc", sizeof(la_k_dot_mc_t), + 0, 3, "i", "ii", @@ -5744,6 +5919,7 @@ csound->AppendOpcode(csound, "la_i_dot_mr_vr", sizeof(la_i_dot_mr_vr_t), + 0, 1, "i", "ii", @@ -5754,6 +5930,7 @@ csound->AppendOpcode(csound, "la_k_dot_mr_vr", sizeof(la_k_dot_mr_vr_t), + 0, 3, "i", "ii", @@ -5764,6 +5941,7 @@ csound->AppendOpcode(csound, "la_i_dot_mc_vc", sizeof(la_i_dot_mc_vc_t), + 0, 1, "i", "ii", @@ -5774,6 +5952,7 @@ csound->AppendOpcode(csound, "la_k_dot_mc_vc", sizeof(la_k_dot_mc_vc_t), + 0, 3, "i", "ii", @@ -5784,6 +5963,7 @@ csound->AppendOpcode(csound, "la_i_invert_mr", sizeof(la_i_invert_mr_t), + 0, 1, "ii", "i", @@ -5794,6 +5974,7 @@ csound->AppendOpcode(csound, "la_k_invert_mr", sizeof(la_k_invert_mr_t), + 0, 3, "ik", "i", @@ -5804,6 +5985,7 @@ csound->AppendOpcode(csound, "la_i_invert_mc", sizeof(la_i_invert_mc_t), + 0, 1, "iii", "i", @@ -5814,6 +5996,7 @@ csound->AppendOpcode(csound, "la_k_invert_mc", sizeof(la_k_invert_mc_t), + 0, 3, "ikk", "i", @@ -5824,6 +6007,7 @@ csound->AppendOpcode(csound, "la_i_upper_solve_mr", sizeof(la_i_upper_solve_mr_t), + 0, 1, "i", "io", @@ -5834,16 +6018,19 @@ csound->AppendOpcode(csound, "la_k_upper_solve_mr", sizeof(la_k_upper_solve_mr_t), + 0, 3, "i", "iO", (int (*)(CSOUND*,void*)) &la_k_upper_solve_mr_t::init_, - (int (*)(CSOUND*,void*)) &la_k_upper_solve_mr_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_upper_solve_mr_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_upper_solve_mc", sizeof(la_i_upper_solve_mc_t), + 0, 1, "i", "io", @@ -5854,16 +6041,19 @@ csound->AppendOpcode(csound, "la_k_upper_solve_mc", sizeof(la_k_upper_solve_mc_t), + 0, 3, "i", "iO", (int (*)(CSOUND*,void*)) &la_k_upper_solve_mc_t::init_, - (int (*)(CSOUND*,void*)) &la_k_upper_solve_mc_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_upper_solve_mc_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_lower_solve_mr", sizeof(la_i_lower_solve_mr_t), + 0, 1, "i", "io", @@ -5874,16 +6064,19 @@ csound->AppendOpcode(csound, "la_k_lower_solve_mr", sizeof(la_k_lower_solve_mr_t), + 0, 3, "i", "iO", (int (*)(CSOUND*,void*)) &la_k_lower_solve_mr_t::init_, - (int (*)(CSOUND*,void*)) &la_k_lower_solve_mr_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_lower_solve_mr_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_lower_solve_mc", sizeof(la_i_lower_solve_mc_t), + 0, 1, "i", "io", @@ -5894,16 +6087,19 @@ csound->AppendOpcode(csound, "la_k_lower_solve_mc", sizeof(la_k_lower_solve_mc_t), + 0, 3, "i", "iO", (int (*)(CSOUND*,void*)) &la_k_lower_solve_mc_t::init_, - (int (*)(CSOUND*,void*)) &la_k_lower_solve_mc_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_lower_solve_mc_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_lu_factor_mr", sizeof(la_i_lu_factor_mr_t), + 0, 1, "iii", "i", @@ -5914,6 +6110,7 @@ csound->AppendOpcode(csound, "la_k_lu_factor_mr", sizeof(la_k_lu_factor_mr_t), + 0, 3, "iik", "i", @@ -5924,6 +6121,7 @@ csound->AppendOpcode(csound, "la_i_lu_factor_mc", sizeof(la_i_lu_factor_mc_t), + 0, 1, "iii", "i", @@ -5934,6 +6132,7 @@ csound->AppendOpcode(csound, "la_k_lu_factor_mc", sizeof(la_k_lu_factor_mc_t), + 0, 3, "i", "i", @@ -5944,6 +6143,7 @@ csound->AppendOpcode(csound, "la_i_lu_solve_mr", sizeof(la_i_lu_solve_mr_t), + 0, 1, "i", "ii", @@ -5954,6 +6154,7 @@ csound->AppendOpcode(csound, "la_k_lu_solve_mr", sizeof(la_k_lu_solve_mr_t), + 0, 3, "i", "ii", @@ -5964,6 +6165,7 @@ csound->AppendOpcode(csound, "la_i_lu_solve_mc", sizeof(la_i_lu_solve_mc_t), + 0, 1, "i", "ii", @@ -5974,6 +6176,7 @@ csound->AppendOpcode(csound, "la_k_lu_solve_mc", sizeof(la_k_lu_solve_mc_t), + 0, 3, "i", "ii", @@ -5984,6 +6187,7 @@ csound->AppendOpcode(csound, "la_i_qr_factor_mr", sizeof(la_i_qr_factor_mr_t), + 0, 1, "ii", "i", @@ -5994,6 +6198,7 @@ csound->AppendOpcode(csound, "la_k_qr_factor_mr", sizeof(la_k_qr_factor_mr_t), + 0, 3, "ii", "i", @@ -6004,6 +6209,7 @@ csound->AppendOpcode(csound, "la_i_qr_factor_mc", sizeof(la_i_qr_factor_mc_t), + 0, 1, "ii", "i", @@ -6014,6 +6220,7 @@ csound->AppendOpcode(csound, "la_k_qr_factor_mc", sizeof(la_k_qr_factor_mc_t), + 0, 3, "ii", "i", @@ -6024,6 +6231,7 @@ csound->AppendOpcode(csound, "la_i_qr_eigen_mr", sizeof(la_i_qr_eigen_mr_t), + 0, 1, "i", "ii", @@ -6034,6 +6242,7 @@ csound->AppendOpcode(csound, "la_k_qr_eigen_mr", sizeof(la_k_qr_eigen_mr_t), + 0, 3, "i", "ik", @@ -6044,6 +6253,7 @@ csound->AppendOpcode(csound, "la_i_qr_eigen_mc", sizeof(la_i_qr_eigen_mc_t), + 0, 1, "i", "ii", @@ -6054,6 +6264,7 @@ csound->AppendOpcode(csound, "la_k_qr_eigen_mc", sizeof(la_k_qr_eigen_mc_t), + 0, 3, "i", "ik", @@ -6064,6 +6275,7 @@ csound->AppendOpcode(csound, "la_i_qr_sym_eigen_mr", sizeof(la_i_qr_sym_eigen_mr_t), + 0, 1, "ii", "ii", @@ -6074,16 +6286,19 @@ csound->AppendOpcode(csound, "la_k_qr_sym_eigen_mr", sizeof(la_k_qr_sym_eigen_mr_t), + 0, 3, "ii", "ik", (int (*)(CSOUND*,void*)) &la_k_qr_sym_eigen_mr_t::init_, - (int (*)(CSOUND*,void*)) &la_k_qr_sym_eigen_mr_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_qr_sym_eigen_mr_t::kontrol_, (int (*)(CSOUND*,void*)) 0); status |= csound->AppendOpcode(csound, "la_i_qr_sym_eigen_mc", sizeof(la_i_qr_sym_eigen_mc_t), + 0, 1, "ii", "ii", @@ -6094,11 +6309,13 @@ csound->AppendOpcode(csound, "la_k_qr_sym_eigen_mc", sizeof(la_k_qr_sym_eigen_mc_t), + 0, 3, "ii", "ik", (int (*)(CSOUND*,void*)) &la_k_qr_sym_eigen_mc_t::init_, - (int (*)(CSOUND*,void*)) &la_k_qr_sym_eigen_mc_t::kontrol_, + (int (*)(CSOUND*,void*)) + &la_k_qr_sym_eigen_mc_t::kontrol_, (int (*)(CSOUND*,void*)) 0); return status; } diff -Nru csound-5.17.11~dfsg/Opcodes/linuxjoystick.c csound-6.02~dfsg/Opcodes/linuxjoystick.c --- csound-5.17.11~dfsg/Opcodes/linuxjoystick.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/linuxjoystick.c 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,150 @@ +/* + linuxjoystick.c: + Copyright (C) 2010 Justin Glenn Smith + + This Csound plugin is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This plugin is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this plugin; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA + + USAGE: + kresultmask linuxjoystick kdevice ktab + + kdevice = The index of the joystick device, either /dev/js or + /dev/input/js + + ktab = A table to hold input results, should be at least enough elements + to store one value for each stick axis and one for each button + 2. + The first two elements of the table are initialized with the number + of axes and the number of buttons, respectively, when a joystick is + opened. If a joystick is unplugged during performance, the opcode + will repeatedly attempt to reopen the device with a delay between + attempts. + + kresultmask: A bitmask, with a 1 bit for each table index with a new input + received. +*/ + +#include "linuxjoystick.h" +#include + +static int linuxjoystick (CSOUND *csound, LINUXJOYSTICK *stick) +{ + static int read_pos = 0; + struct js_event js; + int read_size; + int getmore; + int evtidx; + long long evtmask = 0; + char device[256]; + int olderr=0; + + if (UNLIKELY(stick->initme == 0)) { + stick->timeout = 0; + stick->devFD = -10; + stick->initme = 1; + } + if (UNLIKELY(*stick->ktable != stick->table)) { + if (UNLIKELY((void *)(stick->ftp = csound->FTnp2Find(csound, stick->ktable)) + == NULL)) { + csound->Warning(csound, Str("linuxjoystick: No such table %f"), + stick->ktable); + return OK; + } + stick->table = *stick->ktable; + } + if (stick->devFD < 0 || *stick->kdev != stick->dev) { + if (stick->timeout > 0 && *stick->kdev == stick->dev) { + (stick->timeout)--; + return OK; + } + stick->dev = (int)MYFLT2LRND(*stick->kdev); + sprintf(device, "/dev/js%i", stick->dev); + if ((stick->devFD = open(device, O_RDONLY, O_NONBLOCK)) < 0) { + olderr = errno; + sprintf(device, "/dev/input/js%i", stick->dev); + stick->devFD = open(device, O_RDONLY, O_NONBLOCK); + } + if (stick->devFD > 0) { + fcntl(stick->devFD, F_SETFL, fcntl(stick->devFD, F_GETFL, 0)|O_NONBLOCK); + ioctl(stick->devFD, JSIOCGAXES, &stick->numk); + ioctl(stick->devFD, JSIOCGBUTTONS, &stick->numb); + if (UNLIKELY(stick->ftp->flen < 2u+(stick->numk)+(stick->numb))) { + csound->Warning + (csound, + Str("linuxjoystick: table %d of size %d too small for data size %d"), + (int)stick->table, stick->ftp->flen, 2+stick->numk+stick->numb); + return OK; + } + stick->ftp->ftable[ 0 ] = (MYFLT) stick->numk; + stick->ftp->ftable[ 1 ] = (MYFLT) stick->numb; + evtmask = 3; + } + else { + stick->timeout = 10000; + csound->Warning(csound, + Str("linuxjoystick: could not open device " + "/dev/input/js%d for reason: %s\n"), + stick->dev, sys_errlist[errno]); + csound->Warning(csound, + Str("linuxjoystick: could not open device " + "/dev/js%d for reason: %s\n"), + stick->dev, sys_errlist[olderr]); + return OK; + } + } + getmore = 1; + while (getmore) { + read_size = read(stick->devFD, (void *) &js+read_pos, + sizeof(struct js_event)-read_pos); + if (read_size == -1 && errno == EAGAIN ) { + getmore = 0; + } + else if (read_size < 1) { + csound->Warning(csound, Str("linuxjoystick: read %d closing joystick"), + read_size); + close(stick->devFD); + stick->devFD = -1; + getmore = 0; + } + else { + read_pos += read_size; + if (read_pos == sizeof(struct js_event)) { + read_pos = 0; + if (js.type & JS_EVENT_AXIS) { + evtidx = 2 + js.number; + } + else if (js.type & JS_EVENT_BUTTON) { + evtidx = 2 + stick->numk + js.number; + } + else { + csound->Warning(csound, Str("unknown joystick event type %i"), + js.type); + return OK; + } + evtmask = evtmask | (1 << evtidx); + stick->ftp->ftable[ evtidx ] = (MYFLT) js.value; + } + } + } + *stick->kresult = (MYFLT) evtmask; + return OK; +} + +static OENTRY localops[] = { + { "joystick", sizeof(LINUXJOYSTICK), 0, 2, "k", "kk", + NULL, (SUBR) linuxjoystick, NULL + }, +}; + +LINKAGE diff -Nru csound-5.17.11~dfsg/Opcodes/linuxjoystick.h csound-6.02~dfsg/Opcodes/linuxjoystick.h --- csound-5.17.11~dfsg/Opcodes/linuxjoystick.h 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/linuxjoystick.h 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,15 @@ +#include +#include "csdl.h" +#include "linux/joystick.h" + +typedef struct +{ + OPDS h; + MYFLT *kresult, *kdev, *ktable; + int devFD; + unsigned int numk, numb; + int timeout, initme; + MYFLT table; + int dev; + FUNC *ftp; +} LINUXJOYSTICK; diff -Nru csound-5.17.11~dfsg/Opcodes/locsig.c csound-6.02~dfsg/Opcodes/locsig.c --- csound-5.17.11~dfsg/Opcodes/locsig.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/locsig.c 2014-01-07 16:53:48.000000000 +0000 @@ -29,7 +29,7 @@ /* University of Washington, Seattle 1998 */ /******************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "locsig.h" #include @@ -43,15 +43,15 @@ "must be 2 or 4")); if (p->auxch.auxp == NULL || - p->auxch.sizeksmps * 4)) { + p->auxch.sizeAuxAlloc(csound, (size_t) (csound->ksmps * 4) + csound->AuxAlloc(csound, (size_t) (CS_KSMPS * 4) * sizeof(MYFLT), &p->auxch); fltp = (MYFLT *) p->auxch.auxp; - p->rrev1 = fltp; fltp += csound->ksmps; - p->rrev2 = fltp; fltp += csound->ksmps; - p->rrev3 = fltp; fltp += csound->ksmps; - p->rrev4 = fltp; fltp += csound->ksmps; + p->rrev1 = fltp; fltp += CS_KSMPS; + p->rrev2 = fltp; fltp += CS_KSMPS; + p->rrev3 = fltp; fltp += CS_KSMPS; + p->rrev4 = fltp; fltp += CS_KSMPS; } p->prev_degree = -FL(918273645.192837465); @@ -68,7 +68,9 @@ MYFLT *r1, *r2, *r3=NULL, *r4=NULL, degree, *asig; MYFLT direct, *rrev1, *rrev2, *rrev3=NULL, *rrev4=NULL; MYFLT torev, localrev, globalrev; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (*p->distance != p->prev_distance) { p->distr=(FL(1.0) / *p->distance); @@ -111,7 +113,24 @@ rrev4 = p->rrev4; } - for (n=0; nOUTOCOUNT == 4) { + memset(r3, '\0', offset*sizeof(MYFLT)); + memset(r4, '\0', offset*sizeof(MYFLT)); + } + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&r2[nsmps], '\0', early*sizeof(MYFLT)); + if (p->OUTOCOUNT == 4) { + memset(&r3[nsmps], '\0', early*sizeof(MYFLT)); + memset(&r4[nsmps], '\0', early*sizeof(MYFLT)); + } + } + for (n=offset; ndistr; torev = asig[n] * p->distrsq * *p->reverbamount; globalrev = torev * p->distr; @@ -153,7 +172,9 @@ /* MYFLT *r1, *r2, *r3=NULL, *r4=NULL; */ /* MYFLT *rrev1, *rrev2, *rrev3=NULL, *rrev4=NULL; */ LOCSIG *q = p->locsig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* r1 = p->r1; */ /* r2 = p->r2; */ @@ -177,12 +198,29 @@ /* } */ /* Quicker form is: */ - n = nsmps*sizeof(MYFLT); - memcpy(p->r1, q->rrev1, n); - memcpy(p->r2, q->rrev2, n); + if (UNLIKELY(offset)) { + memset(p->r1, '\0', offset*sizeof(MYFLT)); + memset(p->r2, '\0', offset*sizeof(MYFLT)); + if (p->OUTOCOUNT == 4) { + memset(p->r3, '\0', offset*sizeof(MYFLT)); + memset(p->r4, '\0', offset*sizeof(MYFLT)); + } + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r1[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->r2[nsmps], '\0', early*sizeof(MYFLT)); + if (p->OUTOCOUNT == 4) { + memset(&p->r3[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->r4[nsmps], '\0', early*sizeof(MYFLT)); + } + } + n = (nsmps-offset)*sizeof(MYFLT); + memcpy(p->r1+offset, q->rrev1, n); + memcpy(p->r2+offset, q->rrev2, n); if (p->OUTOCOUNT == 4) { - memcpy(p->r3, q->rrev3, n); - memcpy(p->r4, q->rrev4, n); + memcpy(p->r3+offset, q->rrev3, n); + memcpy(p->r4+offset, q->rrev4, n); } return OK; } @@ -190,8 +228,9 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "locsig", S(LOCSIG), 5, "mmmm", "akkk", (SUBR)locsigset,NULL, (SUBR)locsig }, -{ "locsend", S(LOCSEND),5, "mmmm", "", (SUBR)locsendset, NULL, (SUBR)locsend } + { "locsig", S(LOCSIG), 0, 5, "mmmm", "akkk", + (SUBR)locsigset,NULL, (SUBR)locsig }, +{ "locsend", S(LOCSEND),0, 5, "mmmm", "",(SUBR)locsendset, NULL, (SUBR)locsend } }; int locsig_init_(CSOUND *csound) @@ -199,4 +238,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/loscilx.c csound-6.02~dfsg/Opcodes/loscilx.c --- csound-5.17.11~dfsg/Opcodes/loscilx.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/loscilx.c 2014-01-07 16:53:48.000000000 +0000 @@ -35,15 +35,20 @@ MYFLT *iLoopMode1, *iLoopStart1, *iLoopEnd1; } SNDLOAD_OPCODE; -static int sndload_opcode_init(CSOUND *csound, SNDLOAD_OPCODE *p) +static int sndload_opcode_init_(CSOUND *csound, SNDLOAD_OPCODE *p, int isstring) { char *fname; SNDMEMFILE *sf; SF_INFO sfinfo; int sampleFormat, loopMode; - fname = csound->strarg2name(csound, (char*) NULL, p->Sfname, "soundin.", - (int) csound->GetInputArgSMask(p)); + if(isstring) fname = ((STRINGDAT *)p->Sfname)->data; + else { + if(ISSTRCOD(*p->Sfname)) + fname = csound->Strdup(csound, get_arg_string(csound, *p->Sfname)); + else + fname = csound->strarg2name(csound, (char*) NULL, p->Sfname, "soundin.", 0); + } memset(&sfinfo, 0, sizeof(SF_INFO)); sampleFormat = (int) MYFLT2LRND(*(p->iFormat)); sfinfo.format = (int) TYPE2SF(TYP_RAW); @@ -69,7 +74,7 @@ tmp = (int) MYFLT2LRND(*(p->iChannels)); sfinfo.channels = (tmp > 0 ? tmp : 1); tmp = (int) MYFLT2LRND(*(p->iSampleRate)); - sfinfo.samplerate = (tmp > 0 ? tmp : (int) MYFLT2LRND(csound->esr)); + sfinfo.samplerate = (tmp > 0 ? tmp : (int) MYFLT2LRND(CS_ESR)); } sf = csound->LoadSoundFile(csound, fname, &sfinfo); if (UNLIKELY(sf == NULL)) { @@ -106,6 +111,15 @@ return OK; } +static int sndload_opcode_init(CSOUND *csound, SNDLOAD_OPCODE *p){ + return sndload_opcode_init_(csound,p,0); +} + +static int sndload_opcode_init_S(CSOUND *csound, SNDLOAD_OPCODE *p){ + return sndload_opcode_init_(csound,p,0); +} + + /* ------------------------------------------------------------------------ */ #define LOSCILX_MAXOUTS (16) @@ -169,13 +183,16 @@ p->dataPtr = NULL; nChannels = csound->GetOutputArgCnt(p); if (UNLIKELY(nChannels < 1 || nChannels > LOSCILX_MAXOUTS)) - csound->Die(csound, Str("loscilx: invalid number of output arguments")); + return csound->InitError(csound, + Str("loscilx: invalid number of output arguments")); p->nChannels = nChannels; - if (csound->GetInputArgSMask(p) != 0UL) { + if (ISSTRCOD(*p->ifn)) { SNDMEMFILE *sf; p->usingFtable = 0; - sf = csound->LoadSoundFile(csound, (char*) p->ifn, (SF_INFO *) NULL); + sf = csound->LoadSoundFile(csound, + (char*) get_arg_string(csound, *p->ifn), + (SF_INFO *) NULL); if (UNLIKELY(sf == NULL)) return csound->InitError(csound, Str("could not load '%s'"), (char*) p->ifn); @@ -203,10 +220,10 @@ } if (*(p->ibas) > FL(0.0)) { frqScale = sf->sampleRate - / ((double) csound->esr * (double) *(p->ibas)); + / ((double) CS_ESR * (double) *(p->ibas)); } else - frqScale = sf->sampleRate / ((double) csound->esr * sf->baseFreq); + frqScale = sf->sampleRate / ((double) CS_ESR * sf->baseFreq); p->ampScale = (MYFLT) sf->scaleFac * csound->e0dbfs; p->nFrames = (int32) sf->nFrames; } @@ -238,7 +255,7 @@ if (*(p->ibas) > FL(0.0)) { if (ftp->gen01args.sample_rate > FL(0.0)) frqScale = (double) ftp->gen01args.sample_rate - / ((double) csound->esr * (double) *(p->ibas)); + / ((double) CS_ESR * (double) *(p->ibas)); else frqScale = 1.0 / (double) *(p->ibas); } @@ -246,7 +263,7 @@ frqScale = (double) ftp->cpscvt * (1.0 / (double) LOFACT); } else if (ftp->gen01args.sample_rate > FL(0.0)) - frqScale = (double) ftp->gen01args.sample_rate / (double) csound->esr; + frqScale = (double) ftp->gen01args.sample_rate / (double) CS_ESR; p->ampScale = FL(1.0); p->nFrames = ftp->flenfrms + 1L; } @@ -344,7 +361,10 @@ static int loscilx_opcode_perf(CSOUND *csound, LOSCILX_OPCODE *p) { - int i, j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int j; double frac_d, pidwarp_d = 0.0, c = 0.0; MYFLT frac, ampScale, winFact = p->winFact; int32 ndx; @@ -393,9 +413,12 @@ winFact = (MYFLT) (((double) p->winFact - tmp1) * tmp2 + tmp1); } ampScale = *(p->xamp) * p->ampScale; - - i = 0; - do { + if (UNLIKELY(offset)) memset(p->ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; icurPos); frac = (MYFLT) frac_d; @@ -660,20 +683,23 @@ else p->curPos += p->curPosInc; - } while (++i < csound->ksmps); + } return OK; err1: - return csound->PerfError(csound, Str("loscilx: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("loscilx: not initialised")); } /* ------------------------------------------------------------------------ */ static OENTRY loscilx_localops[] = { - { "sndload", sizeof(SNDLOAD_OPCODE), 1, "", "Tooooojjoo", + { "sndload", sizeof(SNDLOAD_OPCODE), 0, 1, "", "iooooojjoo", (SUBR) sndload_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "loscilx", sizeof(LOSCILX_OPCODE), TR|5, "mmmmmmmmmmmmmmmm", "xkToojjoo", + { "sndload.S", sizeof(SNDLOAD_OPCODE), 0, 1, "", "Sooooojjoo", + (SUBR) sndload_opcode_init_S, (SUBR) NULL, (SUBR) NULL }, + { "loscilx", sizeof(LOSCILX_OPCODE), TR, 5, "mmmmmmmmmmmmmmmm", "xkioojjoo", (SUBR) loscilx_opcode_init, (SUBR) NULL, (SUBR) loscilx_opcode_perf } }; -LINKAGE1(loscilx_localops) +LINKAGE_BUILTIN(loscilx_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/lowpassr.c csound-6.02~dfsg/Opcodes/lowpassr.c --- csound-5.17.11~dfsg/Opcodes/lowpassr.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/lowpassr.c 2014-01-07 16:54:20.000000000 +0000 @@ -23,7 +23,7 @@ /* Resonant Lowpass filters by G.Maldonado */ -#include "csdl.h" +#include "stdopcod.h" #include "lowpassr.h" #include @@ -45,20 +45,31 @@ MYFLT kfco = *p->kfco; MYFLT kres = *p->kres; double coef1 = p->coef1, coef2 = p->coef2; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (p->okf != kfco || p->okr != kres) { /* Only if changed */ - b = 10.0 / (*p->kres * sqrt((double)kfco)) - 1.0; + if (kfco<=FL(0.0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (kres * sqrt((double)kfco)) - 1.0; p->k = k = 1000.0 / (double)kfco; p->coef1 = coef1 = (b+2.0 * k); p->coef2 = coef2 = 1.0/(1.0 + b + k); + p->okf = kfco; p->okr = kres; /* remember to save recalculation */ } ar = p->ar; asig = p->asig; ynm1 = p->ynm1; ynm2 = p->ynm2; - for (n=0; nk; + MYFLT *ar, *asig; + double yn, ynm1, ynm2 ; + MYFLT *fco = p->kfco; + MYFLT *res = p->kres; + MYFLT okf = p->okf, okr = p->okr; + double coef1 = p->coef1, coef2 = p->coef2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (okf!= fco[0] || okr != res[0]) { /* Only if changed */ + if (fco[0]<=FL(0.0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (res[0] * sqrt((double)fco[0])) - 1.0; + p->k = k = 1000.0 / (double)fco[0]; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okf = fco[0]; okr = res[0]; + /* remember to save recalculation */ + } + ar = p->ar; + asig = p->asig; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nPerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (res[n] * sqrt((double)fco[n])) - 1.0; + p->k = k = 1000.0 / (double)fco[0]; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okf = fco[n]; okr = res[n]; + /* remember to save recalculation */ + } + ar[n] = (MYFLT)(yn = (coef1 * ynm1 - k * ynm2 + (double)asig[n]) * coef2); + ynm2 = ynm1; + ynm1 = yn; + } + p->ynm1 = ynm1; + p->ynm2 = ynm2; /* And save */ + p->okf = okf; p->okr = okr; + return OK; +} + +static int lowprak(CSOUND *csound, LOWPR *p) +{ + double b, k = p->k; + MYFLT *ar, *asig; + double yn, ynm1, ynm2 ; + MYFLT *fco = p->kfco; + MYFLT kres = *p->kres; + MYFLT okf = p->okf, okr = p->okr; + double coef1 = p->coef1, coef2 = p->coef2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (okf != fco[0] || okr != kres) { /* Only if changed */ + if (fco[0]<=FL(0.0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (kres * sqrt((double)fco[0])) - 1.0; + p->k = k = 1000.0 / (double)fco[0]; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okf = fco[0]; okr = kres; /* remember to save recalculation */ + } + ar = p->ar; + asig = p->asig; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nPerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (kres * sqrt((double)fco[n])) - 1.0; + p->k = k = 1000.0 / (double)fco[n]; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okf = fco[n]; /* remember to save recalculation */ + } + ar[n] = (MYFLT)(yn = (coef1 * ynm1 - k * ynm2 + (double)asig[n]) * coef2); + ynm2 = ynm1; + ynm1 = yn; + } + p->ynm1 = ynm1; + p->ynm2 = ynm2; /* And save */ + p->okf = okf; p->okr = okr; + + return OK; +} + +static int lowprka(CSOUND *csound, LOWPR *p) +{ + double b, k = p->k; + MYFLT *ar, *asig; + double yn, ynm1, ynm2 ; + MYFLT fco = *p->kfco; + MYFLT *res = p->kres; + MYFLT okr = p->okr, okf = p->okf; + double coef1 = p->coef1, coef2 = p->coef2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (okf!= fco || okr != res[0]) { /* Only if changed */ + if (fco<=FL(0.0)) + return csound->PerfError(csound, p->h.insdshead, + Str("Cutoff parameter must be positive")); + b = 10.0 / (res[0] * sqrt((double)fco)) - 1.0; + p->k = k = 1000.0 / (double)fco; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okf = fco; okr = res[0]; /* remember to save recalculation */ + } + ar = p->ar; + asig = p->asig; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nk = k = 1000.0 / (double)fco; + p->coef1 = coef1 = (b+2.0 * k); + p->coef2 = coef2 = 1.0/(1.0 + b + k); + okr = res[n]; /* remember to save recalculation */ + } + ar[n] = (MYFLT)(yn = (coef1 * ynm1 - k * ynm2 + (double)asig[n]) * coef2); + ynm2 = ynm1; + ynm1 = yn; + } + p->ynm1 = ynm1; + p->ynm2 = ynm2; /* And save */ + p->okf = okf; p->okr = okr; + + return OK; +} + static int lowpr_setx(CSOUND *csound, LOWPRX *p) { int j; @@ -84,33 +259,47 @@ static int lowprx(CSOUND *csound, LOWPRX *p) { - MYFLT b, k = p->k; - MYFLT *ar, *asig, yn,*ynm1, *ynm2 ; - MYFLT coef1 = p->coef1, coef2 = p->coef2; - MYFLT kfco = *p->kfco, kres = *p->kres; - int n,nsmps = csound->ksmps, j; + MYFLT b, k = p->k; + MYFLT *ar, *asig, yn,*ynm1, *ynm2 ; + MYFLT coef1 = p->coef1, coef2 = p->coef2; + MYFLT *kfco = p->kfco, *kres = p->kres; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j; - if (p->okf != kfco || p->okr != kres) { /* Only if changed */ - b = FL(10.0) / (*p->kres * SQRT(kfco)) - FL(1.0); - p->k = k = FL(1000.0) / kfco; - p->coef1 = coef1 = (b+FL(2.0) * k); - p->coef2 = coef2 = FL(1.0)/(FL(1.0) + b + k); - } ynm1 = p->ynm1; ynm2 = p->ynm2; asig = p->asig; + if (UNLIKELY(offset)) memset(p->ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->ar[nsmps], '\0', early*sizeof(MYFLT)); + } for (j=0; j< p->loop; j++) { ar = p->ar; - for (n=0;nokf != fco || p->okr != res) { /* Only if changed */ + b = FL(10.0) / (res * SQRT(fco)) - FL(1.0); + k = FL(1000.0) / fco; + coef1 = (b+FL(2.0) * k); + coef2 = FL(1.0)/(FL(1.0) + b + k); + p->okf = fco; p->okr = res; /* remember to save recalculation */ + } ar[n] = yn = (coef1 * ynm1[j] - k * ynm2[j] + asig[n]) * coef2; ynm2[j] = ynm1[j]; ynm1[j] = yn; } asig= p->ar; } + p->k = k; + p->coef1 = coef1; + p->coef2 = coef2; return OK; } @@ -128,12 +317,15 @@ static int lowpr_w_sep(CSOUND *csound, LOWPR_SEP *p) { - MYFLT b, k; - MYFLT *ar, *asig, yn,*ynm1, *ynm2 ; - MYFLT coef1, coef2; - MYFLT kfcobase = *p->kfco; - MYFLT sep = (*p->sep / p->loop); - int n, nsmps=csound->ksmps, j; + MYFLT b, k; + MYFLT *ar, *asig, yn,*ynm1, *ynm2 ; + MYFLT coef1, coef2; + MYFLT kfcobase = *p->kfco; + MYFLT sep = (*p->sep / p->loop); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j; MYFLT kres = *p->kres; MYFLT kfco; @@ -141,6 +333,12 @@ ynm2 = p->ynm2; asig = p->asig; + if (UNLIKELY(offset)) memset(p->ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->ar[nsmps], '\0', early*sizeof(MYFLT)); + } + ar = p->ar; for (j=0; j< p->loop; j++) { MYFLT lynm1 = ynm1[j]; MYFLT lynm2 = ynm2[j]; @@ -156,8 +354,8 @@ coef1 = (b+FL(2.0) *k); coef2 = FL(1.0)/(FL(1.0) + b + k); - ar = p->ar; - for (n=0;nAppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/mandolin.c csound-6.02~dfsg/Opcodes/mandolin.c --- csound-5.17.11~dfsg/Opcodes/mandolin.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/mandolin.c 2014-01-07 16:53:48.000000000 +0000 @@ -76,20 +76,21 @@ { FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) p->soundfile = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) + p->soundfile = ftp; else { /* Expect pluck wave */ return csound->InitError(csound, Str("No table for Mandolin")); } if (*p->lowestFreq>=FL(0.0)) { /* Skip initialisation */ if (*p->lowestFreq!=FL(0.0)) { - p->length = (int32) (csound->esr / (*p->lowestFreq * FL(0.9)) + FL(1.0)); + p->length = (int32) (CS_ESR / (*p->lowestFreq * FL(0.9)) + FL(1.0)); } else if (LIKELY(*p->frequency!=FL(0.0))) { - p->length = (int32) (csound->esr / *p->frequency + FL(1.0)); + p->length = (int32) (CS_ESR / *p->frequency + FL(1.0)); } else { csound->Warning(csound, Str("No base frequency for mandolin")); - p->length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } p->lastFreq = FL(50.0); /* p->baseLoopGain = 0.995; */ @@ -101,7 +102,7 @@ make_OneZero(&p->filter2); p->lastLength = p->length * FL(0.5); /* soundfile->normalize(0.05); Empirical hack here transferred to use */ - p->lastLength = ( csound->esr / p->lastFreq); /* length - delays */ + p->lastLength = ( CS_ESR / p->lastFreq); /* length - delays */ /* DLineA_setDelay(&p->delayLine1, (p->lastLength / *p->detuning) - 0.5f); */ /* DLineA_setDelay(&p->delayLine2, (p->lastLength * *p->detuning) - 0.5f); */ @@ -116,12 +117,12 @@ p->dampTime = (int32) p->lastLength; /* See tick method below */ p->waveDone = 0; { - int relestim = (int)(csound->ekr * FL(0.1)); + int relestim = (int)(CS_EKR * FL(0.1)); /* 1/10th second decay extention */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; } - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr); /* ??? */ + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR); /* ??? */ } return OK; } @@ -129,7 +130,9 @@ int mandolin(CSOUND *csound, MANDOL *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT lastOutput; MYFLT loopGain; @@ -141,7 +144,7 @@ if (p->lastFreq != *p->frequency) { p->lastFreq = *p->frequency; - p->lastLength = ( csound->esr / p->lastFreq); /* length - delays */ + p->lastLength = ( CS_ESR / p->lastFreq); /* length - delays */ DLineA_setDelay(csound, &p->delayLine1, (p->lastLength / *p->detuning) - FL(0.5)); DLineA_setDelay(csound, &p->delayLine2, @@ -152,7 +155,12 @@ loopGain = (FL(1.0) - amp) * FL(0.5); } - for (n=0;nwaveDone) { p->waveDone = infoTick(p); /* as long as it goes . . . */ diff -Nru csound-5.17.11~dfsg/Opcodes/metro.c csound-6.02~dfsg/Opcodes/metro.c --- csound-5.17.11~dfsg/Opcodes/metro.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/metro.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include typedef struct { @@ -69,7 +69,7 @@ *p->sr = FL(1.0); p->flag = 0; } - else if ((phs += *p->xcps * csound->onedkr) >= 1.0) { + else if ((phs += *p->xcps * CS_ONEDKR) >= 1.0) { *p->sr = FL(1.0); phs -= 1.0; p->flag = 0; @@ -101,7 +101,7 @@ */ FUNC *ftp; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) { + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) { return csound->InitError(csound, Str("splitrig: incorrect table number")); } p->table = ftp->ftable; @@ -147,8 +147,8 @@ { FUNC *ftp; MYFLT *table; - int j; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) return NOTOK; + unsigned int j; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; table = p->table = ftp->ftable; p->numParm = p->INOCOUNT-2; /* ? */ for (j = 0; j < ftp->flen; j+= p->numParm) { @@ -164,7 +164,7 @@ static int timeseq(CSOUND *csound, TIMEDSEQ *p) { - MYFLT *table = p->table, minDist = csound->onedkr; + MYFLT *table = p->table, minDist = CS_ONEDKR; MYFLT phs = *p->kphs, endseq = p->endSeq; int j,k, numParm = p->numParm, endIndex = p->endIndex; while (phs > endseq) @@ -251,10 +251,10 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "metro", S(METRO), 3, "k", "ko", (SUBR)metro_set, (SUBR)metro }, - { "splitrig", S(SPLIT_TRIG), 3, "", "kkiiz", + { "metro", S(METRO), 9, 3, "k", "ko", (SUBR)metro_set, (SUBR)metro }, + { "splitrig", S(SPLIT_TRIG), 0, 3, "", "kkiiz", (SUBR)split_trig_set, (SUBR)split_trig }, - { "timedseq",S(TIMEDSEQ), TR|3, "k", "kiz", (SUBR)timeseq_set, (SUBR)timeseq } + { "timedseq",S(TIMEDSEQ), TR, 3, "k", "kiz", (SUBR)timeseq_set, (SUBR)timeseq } }; int metro_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/midiops2.c csound-6.02~dfsg/Opcodes/midiops2.c --- csound-5.17.11~dfsg/Opcodes/midiops2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/midiops2.c 2014-01-07 16:53:48.000000000 +0000 @@ -26,7 +26,7 @@ /** midicXX UGs by Gabriel Maldonado **/ /****************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "midiops2.h" #ifndef TRUE #define TRUE (1) @@ -60,7 +60,7 @@ else { value = (MYFLT)(csound->curip->m_chnbp->ctl_val[ctlno] * oneTOf7bit); if (*p->ifn > 0) { - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; /* if valid ftable, use value as index */ value = *(ftp->ftable + (int32)(value*ftp->flen)); /* no interpolation */ } @@ -77,7 +77,7 @@ } else p->ctlno = ctlno; if (*p->ifn > 0) { - if (((p->ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; } @@ -131,7 +131,7 @@ MYFLT diff; int32 length; - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; /* if valid ftable,use value as index */ phase = value * (length = ftp->flen); diff = phase - (int32) phase; @@ -156,7 +156,7 @@ p->ctlno1 = ctlno1; p->ctlno2 = ctlno2; if (*p->ifn > 0) { - if (UNLIKELY(((p->ftp = csound->FTFind(csound, p->ifn)) == NULL))) + if (UNLIKELY(((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL))) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; } @@ -226,7 +226,7 @@ * oneTOf21bit); if (*p->ifn > 0) { /* linear interpolation routine */ - FUNC *ftp = csound->FTFind(csound, p->ifn); /* gab-A1 */ + FUNC *ftp = csound->FTnp2Find(csound, p->ifn); /* gab-A1 */ MYFLT phase; MYFLT *base; if (UNLIKELY(ftp == NULL)) @@ -255,7 +255,7 @@ p->ctlno2 = ctlno2; p->ctlno3 = ctlno3; if (*p->ifn > 0) { - if (UNLIKELY(((p->ftp = csound->FTFind(csound, p->ifn)) == NULL))) + if (UNLIKELY(((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL))) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; @@ -318,7 +318,7 @@ value = (MYFLT) (csound->m_chnbp[(int) *p->ichan-1]->ctl_val[ctlno] * oneTOf7bit); if (*p->ifn > 0) { - if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; /* if valid ftable,use value as index */ value = *(ftp->ftable + (int32)(value*ftp->flen)); /* no interpolation */ } @@ -341,7 +341,7 @@ /*else if (midi_in_p_num < 0) midi_in_error("ctrl7");*/ else p->ctlno = ctlno; if (*p->ifn > 0) { - if (UNLIKELY(((p->ftp = csound->FTFind(csound, p->ifn)) == NULL))) + if (UNLIKELY(((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL))) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; } @@ -381,7 +381,7 @@ if (*p->ifn > 0) { /* linear interpolation routine */ - FUNC *ftp = csound->FTFind(csound, p->ifn); + FUNC *ftp = csound->FTnp2Find(csound, p->ifn); MYFLT phase; MYFLT *base; if (UNLIKELY(ftp == NULL)) @@ -411,7 +411,7 @@ p->ctlno1 = ctlno1; p->ctlno2 = ctlno2; if (*p->ifn > 0) { - if (UNLIKELY(((p->ftp = csound->FTFind(csound, p->ifn)) == NULL))) + if (UNLIKELY(((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL))) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; } @@ -463,7 +463,7 @@ if (*p->ifn > 0) { /* linear interpolation routine */ - FUNC *ftp = csound->FTFind(csound, p->ifn); + FUNC *ftp = csound->FTnp2Find(csound, p->ifn); MYFLT phase; MYFLT *base; if (UNLIKELY(ftp == NULL)) @@ -496,7 +496,7 @@ p->ctlno2 = ctlno2; p->ctlno3 = ctlno3; if (*p->ifn > 0) { - if (UNLIKELY(((p->ftp = csound->FTFind(csound, p->ifn)) == NULL))) + if (UNLIKELY(((p->ftp = csound->FTnp2Find(csound, p->ifn)) == NULL))) p->flag = FALSE; /* invalid ftable */ else p->flag= TRUE; @@ -617,22 +617,22 @@ { "midic14", 0xffff, }, { "midic21", 0xffff, }, { "midic7", 0xffff, }, -{ "midic7.i",S(MIDICTL2),1, "i", "iiio", (SUBR)imidic7, NULL, NULL }, -{ "midic7.k", S(MIDICTL2),3, "k", "ikko", (SUBR)midic7set, (SUBR)midic7, NULL }, -{ "midic14.i", S(MIDICTL3), 1,"i", "iiiio",(SUBR)imidic14, NULL, NULL }, -{ "midic14.k", S(MIDICTL3), 3,"k", "iikko",(SUBR)midic14set, (SUBR)midic14, NULL }, -{ "midic21.i", S(MIDICTL4),1,"i", "iiiiio",(SUBR)imidic21, NULL, NULL }, -{ "midic21.k", S(MIDICTL4), 3,"k", "iiikko",(SUBR)midic21set,(SUBR)midic21, NULL }, -{ "ctrl7.i", S(CTRL7), 1, "i", "iiiio", (SUBR)ictrl7, NULL, NULL }, -{ "ctrl7.k", S(CTRL7), 3, "k", "iikko", (SUBR)ctrl7set, (SUBR)ctrl7, NULL }, -{ "ctrl14.i", S(CTRL14),1, "i", "iiiiio",(SUBR)ictrl14, NULL, NULL }, -{ "ctrl14.k", S(CTRL14), 3, "k", "iiikko",(SUBR)ctrl14set, (SUBR)ctrl14, NULL }, -{ "ctrl21.i", S(CTRL21),1, "i", "iiiiiio", (SUBR)ictrl21, NULL, NULL }, -{ "ctrl21.k", S(CTRL21), 3, "k", "iiiikko", (SUBR)ctrl21set, (SUBR)ctrl21, NULL }, -{ "initc7", S(INITC7), 1, "", "iii", (SUBR)initc7, NULL, NULL }, -{ "initc14", S(INITC14), 1, "", "iiii", (SUBR)initc14, NULL, NULL }, -{ "initc21", S(INITC21), 1, "", "iiiii",(SUBR)initc21, NULL, NULL }, -{ "midipgm", S(MIDIPGM_OP), 1, "i", "o", (SUBR)midipgm_opcode, NULL, NULL } +{ "midic7.i",S(MIDICTL2),0, 1, "i", "iiio", (SUBR)imidic7, NULL, NULL }, +{ "midic7.k", S(MIDICTL2),0, 3, "k", "ikko", (SUBR)midic7set, (SUBR)midic7, NULL }, +{ "midic14.i", S(MIDICTL3), 0, 1,"i", "iiiio",(SUBR)imidic14, NULL, NULL }, +{ "midic14.k", S(MIDICTL3), 0, 3,"k", "iikko",(SUBR)midic14set, (SUBR)midic14,NULL}, +{ "midic21.i", S(MIDICTL4),0, 1,"i", "iiiiio",(SUBR)imidic21, NULL, NULL }, +{ "midic21.k", S(MIDICTL4), 0, 3,"k", "iiikko",(SUBR)midic21set,(SUBR)midic21,NULL}, +{ "ctrl7.i", S(CTRL7), 0, 1, "i", "iiiio", (SUBR)ictrl7, NULL, NULL }, +{ "ctrl7.k", S(CTRL7), 0, 3, "k", "iikko", (SUBR)ctrl7set, (SUBR)ctrl7, NULL }, +{ "ctrl14.i", S(CTRL14),0, 1, "i", "iiiiio",(SUBR)ictrl14, NULL, NULL }, +{ "ctrl14.k", S(CTRL14), 0, 3, "k", "iiikko",(SUBR)ctrl14set, (SUBR)ctrl14, NULL }, +{ "ctrl21.i", S(CTRL21),0, 1, "i", "iiiiiio", (SUBR)ictrl21, NULL, NULL }, +{ "ctrl21.k", S(CTRL21), 0, 3, "k", "iiiikko", (SUBR)ctrl21set,(SUBR)ctrl21,NULL}, +{ "initc7", S(INITC7), 0, 1, "", "iii", (SUBR)initc7, NULL, NULL }, +{ "initc14", S(INITC14), 0, 1, "", "iiii", (SUBR)initc14, NULL, NULL }, +{ "initc21", S(INITC21), 0, 1, "", "iiiii",(SUBR)initc21, NULL, NULL }, +{ "midipgm", S(MIDIPGM_OP), 0, 1, "i", "o", (SUBR)midipgm_opcode, NULL, NULL } }; int midiops2_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/midiops3.c csound-6.02~dfsg/Opcodes/midiops3.c --- csound-5.17.11~dfsg/Opcodes/midiops3.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/midiops3.c 2014-01-07 16:53:48.000000000 +0000 @@ -23,7 +23,7 @@ /* sliders and other MIDI opcodes by Gabriel Maldonado */ -#include "csdl.h" +#include "stdopcod.h" #include "midiops.h" #include "midiops3.h" #include @@ -65,7 +65,7 @@ j); \ return csound->InitError(csound, sbuf); \ } \ - if (*sld->ifn > 0) *ftp++ = csound->FTFind(csound, sld->ifn); \ + if (*sld->ifn > 0) *ftp++ = csound->FTnp2Find(csound, sld->ifn); \ else *ftp++ = NULL; \ value = (*(sld++)->initvalue - *min) / (*max++ - *min); \ min++; \ @@ -146,7 +146,7 @@ return csound->InitError(csound, Str("illegal channel")); \ } \ { \ - MYFLT value; \ + MYFLT value = FL(0.0); \ int j = 0; \ SLDf *sld = p->s; \ unsigned char *slnum = p->slnum; \ @@ -168,7 +168,7 @@ Str("illegal initvalue at position n.%d"), j); \ return csound->InitError(csound, sbuf); \ } \ - if (*sld->ifn > 0) *ftp++ = csound->FTFind(csound, sld->ifn); \ + if (*sld->ifn > 0) *ftp++ = csound->FTnp2Find(csound, sld->ifn); \ else *ftp++ = NULL; \ value = (*sld->initvalue - *min) / (*max++ - *min); \ min++;; \ @@ -178,7 +178,7 @@ *yt1++ = FL(0.0); \ b = (MYFLT)(2.0 - cos((double)(*(sld++)->ihp \ * csound->tpidsr \ - * csound->ksmps))); \ + * CS_KSMPS))); \ *c2 = (MYFLT)(b - sqrt((double)(b * b - FL(1.0)))); \ *c1++ = FL(1.0) - *c2++; \ } \ @@ -275,7 +275,7 @@ } \ value = chanblock[slnum] * oneTOf7bit; \ if (*sld->ifn > 0) { \ - ftp = csound->FTFind(csound, sld->ifn); \ + ftp = csound->FTnp2Find(csound, sld->ifn); \ value = *( ftp->ftable + (int32)(value * ftp->flen)); \ /* no interpolation */ \ } \ @@ -347,7 +347,7 @@ Str("illegal initvalue at position n.%d"), j); \ return csound->InitError(csound, sbuf); \ } \ - if (*sld->ifn > 0) *ftp++ = csound->FTFind(csound, sld->ifn); \ + if (*sld->ifn > 0) *ftp++ = csound->FTnp2Find(csound, sld->ifn); \ else *ftp++ = NULL; \ intvalue = (int) (((*(sld++)->initvalue - *min) / (*max++ - *min)) \ * f14bit+FL(0.5)); \ @@ -361,7 +361,7 @@ #define SLIDER14(p, n) \ { \ - MYFLT value; \ + MYFLT value = FL(0.0); \ int j = 0; \ FUNC **ftp = p->ftp-1; \ MYFLT *chanblock = (MYFLT *) csound->m_chnbp[p->slchan]->ctl_val; \ @@ -440,7 +440,7 @@ value = (MYFLT)((chanblock[slnum_msb] * 128 \ + chanblock[slnum_lsb]) * oneTOf14bit); \ if (*sld->ifn > 0) { /* linear interpolation routine */ \ - FUNC *ftp= csound->FTFind(csound, sld->ifn); \ + FUNC *ftp= csound->FTnp2Find(csound, sld->ifn); \ MYFLT phase = value * ftp->flen; \ MYFLT *base = ftp->ftable + (int32)(phase); \ value = *base + (*(base + 1) - *base) * (phase - (int32) phase); \ @@ -472,35 +472,35 @@ { "slider32", 0xffff, }, { "slider64", 0xffff, }, { "slider8", 0xffff, }, -{ "slider8.k", S(SLIDER8), 3, "kkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" +{ "slider8.k", S(SLIDER8), 0, 3, "kkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiii", (SUBR)slider_i8, (SUBR)slider8, NULL }, -{ "slider8f", S(SLIDER8f), 3, "kkkkkkkk","iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" +{ "slider8f", S(SLIDER8f), 0, 3, "kkkkkkkk","iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiii", (SUBR)slider_i8f, (SUBR)slider8f, NULL }, -{ "slider8.i", S(SLIDER8), 1, "iiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", +{ "slider8.i", S(SLIDER8), 0, 1, "iiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)islider8, NULL, NULL }, -{ "slider16.k", S(SLIDER16), 3, "kkkkkkkkkkkkkkkk", +{ "slider16.k", S(SLIDER16), 0, 3, "kkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiii", (SUBR)slider_i16, (SUBR)slider16, NULL }, -{ "slider16f", S(SLIDER16f), 3, "kkkkkkkkkkkkkkkk", +{ "slider16f", S(SLIDER16f), 0, 3, "kkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i16f, (SUBR)slider16f, NULL }, -{ "slider16.i", S(SLIDER16), 1, "iiiiiiiiiiiiiiii", +{ "slider16.i", S(SLIDER16), 0, 1, "iiiiiiiiiiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)islider16, NULL, NULL }, -{ "slider32.k", S(SLIDER32), 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", +{ "slider32.k", S(SLIDER32), 0, 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i32, (SUBR)slider32, NULL }, -{ "slider32f", S(SLIDER32f), 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", +{ "slider32f", S(SLIDER32f), 0, 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" @@ -508,13 +508,13 @@ "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiii", (SUBR)slider_i32f, (SUBR)slider32f, NULL }, -{ "slider32.i", S(SLIDER32), 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", +{ "slider32.i", S(SLIDER32), 0, 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiii", (SUBR)islider32, NULL, NULL }, -{ "slider64.k", S(SLIDER64), 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" +{ "slider64.k", S(SLIDER64), 0, 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" "kkkkkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiii" @@ -530,7 +530,7 @@ "iiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i64, (SUBR)slider64, NULL }, -{ "slider64f", S(SLIDER64f), 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" +{ "slider64f", S(SLIDER64f), 0, 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk" "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiii" @@ -549,7 +549,7 @@ "iiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i64f, (SUBR)slider64f, NULL }, -{ "slider64.i", S(SLIDER64), 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" +{ "slider64.i", S(SLIDER64), 0, 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiii" @@ -563,12 +563,12 @@ "iiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiii", (SUBR)islider64, NULL, NULL }, -{ "s16b14.k", S(SLIDER16BIT14), 3, "kkkkkkkkkkkkkkkk", +{ "s16b14.k", S(SLIDER16BIT14), 0, 3, "kkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i16bit14, (SUBR)slider16bit14, NULL}, -{ "s32b14.k", S(SLIDER32BIT14), 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", +{ "s32b14.k", S(SLIDER32BIT14), 0, 3, "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" @@ -576,14 +576,14 @@ "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", (SUBR)slider_i32bit14, (SUBR)slider32bit14, NULL}, -{ "s16b14.i", S(ISLIDER16BIT14), 1, "iiiiiiiiiiiiiiii", +{ "s16b14.i", S(ISLIDER16BIT14), 0, 1, "iiiiiiiiiiiiiiii", "iiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiii", (SUBR)islider16bit14, NULL, NULL }, -{ "s32b14.i", S(ISLIDER32BIT14), 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", +{ "s32b14.i", S(ISLIDER32BIT14), 0, 1, "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii", "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" diff -Nru csound-5.17.11~dfsg/Opcodes/minmax.c csound-6.02~dfsg/Opcodes/minmax.c --- csound-5.17.11~dfsg/Opcodes/minmax.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/minmax.c 2014-01-07 16:53:48.000000000 +0000 @@ -46,14 +46,21 @@ } MINMAX; /* Which implementation is faster ?? */ -static int MaxAccumulate(CSOUND *csound, MINMAXACCUM *data) +static int MaxAccumulate(CSOUND *csound, MINMAXACCUM *p) { MYFLT cur; - int n, nsmps = csound->ksmps; - MYFLT *out = data->accum; - MYFLT *in = data->ain; - - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *out = p->accum; + MYFLT *in = p->ain; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; n out[n])) out[n] = cur; @@ -62,14 +69,21 @@ return OK; } -static int MinAccumulate(CSOUND *csound, MINMAXACCUM *data) +static int MinAccumulate(CSOUND *csound, MINMAXACCUM *p) { MYFLT cur; - int n, nsmps = csound->ksmps; - MYFLT *out = data->accum; - MYFLT *in = data->ain; - - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *out = p->accum; + MYFLT *in = p->ain; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nksmps; - MYFLT *out = data->accum; - MYFLT *in = data->ain; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *out = p->accum; + MYFLT *in = p->ain; MYFLT inabs; - for (n=0; n out[n])) out[n] = inabs; @@ -95,14 +116,21 @@ return OK; } -static int MinAbsAccumulate(CSOUND *csound, MINMAXACCUM *data) +static int MinAbsAccumulate(CSOUND *csound, MINMAXACCUM *p) { - int n, nsmps = csound->ksmps; - MYFLT *out = data->accum; - MYFLT *in = data->ain; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT *out = p->accum; + MYFLT *in = p->ain; MYFLT inabs; - for (n=0; nksmps; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT max, temp; - for (n=0; nksmps; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT min, temp; - for (n=0; nksmps; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT max, temp; - for (n=0; nksmps; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT min, temp; - for (n=0; nINOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT max, temp; max = *in1; @@ -226,13 +282,13 @@ return OK; } -static int Min_krate(CSOUND *csound, MINMAX *data) +static int Min_krate(CSOUND *csound, MINMAX *p) { int i; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT min, temp; min = *in1; @@ -247,13 +303,13 @@ } /* Absolute value versions of k-rate opcodes */ -static int MaxAbs_krate(CSOUND *csound, MINMAX *data) +static int MaxAbs_krate(CSOUND *csound, MINMAX *p) { int i; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT max, temp; max = FABS(*in1); @@ -267,13 +323,13 @@ return OK; } -static int MinAbs_krate(CSOUND *csound, MINMAX *data) +static int MinAbs_krate(CSOUND *csound, MINMAX *p) { int i; - int nargs = ((int) data->INOCOUNT) - 1; - MYFLT *out = data->xout; - MYFLT *in1 = data->xin1; - MYFLT **in2 = data->xin2toN; + int nargs = ((int) p->INOCOUNT) - 1; + MYFLT *out = p->xout; + MYFLT *in1 = p->xin1; + MYFLT **in2 = p->xin2toN; MYFLT min, temp; min = FABS(*in1); @@ -292,24 +348,24 @@ #define S(x) sizeof(x) static OENTRY minmax_localops[] = { - {"maxaccum", S(MINMAXACCUM), 4, "", "aa", NULL, NULL, (SUBR) MaxAccumulate}, - {"minaccum", S(MINMAXACCUM), 4, "", "aa", NULL, NULL, (SUBR) MinAccumulate}, - {"maxabsaccum", S(MINMAXACCUM), 4, "", "aa", NULL, NULL, + {"maxaccum", S(MINMAXACCUM), 0, 4, "", "aa", NULL, NULL, (SUBR) MaxAccumulate}, + {"minaccum", S(MINMAXACCUM), 0, 4, "", "aa", NULL, NULL, (SUBR) MinAccumulate}, + {"maxabsaccum", S(MINMAXACCUM), 0, 4, "", "aa", NULL, NULL, (SUBR) MaxAbsAccumulate}, - {"minabsaccum", S(MINMAXACCUM), 4, "", "aa", NULL, NULL, + {"minabsaccum", S(MINMAXACCUM), 0, 4, "", "aa", NULL, NULL, (SUBR) MinAbsAccumulate}, {"max", 0xffff}, {"min", 0xffff}, {"maxabs", 0xffff}, {"minabs", 0xffff}, - {"max.a", S(MINMAX), 4, "a", "ay", NULL, NULL, (SUBR) Max_arate}, - {"min.a", S(MINMAX), 4, "a", "ay", NULL, NULL, (SUBR) Min_arate}, - {"maxabs.a", S(MINMAX), 4, "a", "ay", NULL, NULL, (SUBR) MaxAbs_arate}, - {"minabs.a", S(MINMAX), 4, "a", "ay", NULL, NULL, (SUBR) MinAbs_arate}, - {"max.k", S(MINMAX), 2, "k", "kz", NULL, (SUBR) Max_krate, NULL}, - {"min.k", S(MINMAX), 2, "k", "kz", NULL, (SUBR) Min_krate, NULL}, - {"maxabs.k", S(MINMAX), 2, "k", "kz", NULL, (SUBR) MaxAbs_krate, NULL}, - {"minabs.k", S(MINMAX), 2, "k", "kz", NULL, (SUBR) MinAbs_krate, NULL} + {"max.a", S(MINMAX), 0, 4, "a", "ay", NULL, NULL, (SUBR) Max_arate}, + {"min.a", S(MINMAX), 0, 4, "a", "ay", NULL, NULL, (SUBR) Min_arate}, + {"maxabs.a", S(MINMAX), 0, 4, "a", "ay", NULL, NULL, (SUBR) MaxAbs_arate}, + {"minabs.a", S(MINMAX), 0, 4, "a", "ay", NULL, NULL, (SUBR) MinAbs_arate}, + {"max.k", S(MINMAX), 0, 2, "k", "kz", NULL, (SUBR) Max_krate, NULL}, + {"min.k", S(MINMAX), 0, 2, "k", "kz", NULL, (SUBR) Min_krate, NULL}, + {"maxabs.k", S(MINMAX), 0, 2, "k", "kz", NULL, (SUBR) MaxAbs_krate, NULL}, + {"minabs.k", S(MINMAX), 0, 2, "k", "kz", NULL, (SUBR) MinAbs_krate, NULL} }; -LINKAGE1(minmax_localops) +LINKAGE_BUILTIN(minmax_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/mixer.cpp csound-6.02~dfsg/Opcodes/mixer.cpp --- csound-5.17.11~dfsg/Opcodes/mixer.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/mixer.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -32,8 +32,8 @@ #endif if(busses[csound].find(buss) == busses[csound].end()) { - size_t channels = csound->nchnls; - size_t frames = csound->ksmps; + size_t channels = csound->GetNchnls(csound); + size_t frames = csound->GetKsmps(csound); busses[csound][buss].resize(channels); for(size_t channel = 0; channel < channels; channel++) { @@ -76,7 +76,8 @@ createBuss(csound, buss); matrix[csound][send][buss] = *kgain; #ifdef ENABLE_MIXER_IDEBUG - warn(csound, "MixerSetLevel::init: csound %p send %d buss %d gain %f\n", csound, send, buss, matrix[csound][send][buss]); + warn(csound, "MixerSetLevel::init: csound %p send %d buss %d gain %f\n", + csound, send, buss, matrix[csound][send][buss]); #endif return OK; } @@ -171,7 +172,7 @@ buss = static_cast(*ibuss); createBuss(csound, buss); channel = static_cast(*ichannel); - frames = csound->ksmps; + frames = opds.insdshead->ksmps; busspointer = &busses[csound][buss][channel].front(); #ifdef ENABLE_MIXER_IDEBUG warn(csound, "MixerSend::init: instance %p send %d buss " @@ -225,7 +226,7 @@ { buss = static_cast(*ibuss); channel = static_cast(*ichannel); - frames = csound->ksmps; + frames = opds.insdshead->ksmps; createBuss(csound, buss); #ifdef ENABLE_MIXER_IDEBUG warn(csound, "MixerReceive::init...\n"); @@ -306,7 +307,8 @@ { (char*)"MixerSetLevel", sizeof(MixerSetLevel), - CW|3, + CW, + 3, (char*)"", (char*)"iik", (SUBR)&MixerSetLevel::init_, @@ -316,7 +318,8 @@ { (char*)"MixerSetLevel_i", sizeof(MixerSetLevel), - CW|1, + CW, + 1, (char*)"", (char*)"iii", (SUBR)&MixerSetLevel::init_, @@ -326,7 +329,8 @@ { (char*)"MixerGetLevel", sizeof(MixerGetLevel), - CR|3, + CR, + 3, (char*)"k", (char*)"ii", (SUBR)&MixerGetLevel::init_, @@ -336,7 +340,8 @@ { (char*)"MixerSend", sizeof(MixerSend), - CR|5, + CR, + 5, (char*)"", (char*)"aiii", (SUBR)&MixerSend::init_, @@ -346,7 +351,8 @@ { (char*)"MixerReceive", sizeof(MixerReceive), - CW|5, + CW, + 5, (char*)"a", (char*)"ii", (SUBR)&MixerReceive::init_, @@ -356,6 +362,7 @@ { (char*)"MixerClear", sizeof(MixerClear), + 0, 4, (char*)"", (char*)"", @@ -363,7 +370,7 @@ 0, (SUBR)&MixerClear::audio_ }, - { NULL, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } + { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } }; PUBLIC int csoundModuleCreate(CSOUND *csound) @@ -378,8 +385,8 @@ while (ep->opname != NULL) { err |= csound->AppendOpcode(csound, - ep->opname, ep->dsblksiz, ep->thread, - ep->outypes, ep->intypes, + ep->opname, ep->dsblksiz, ep->flags, + ep->thread, ep->outypes, ep->intypes, (int (*)(CSOUND *, void*)) ep->iopadr, (int (*)(CSOUND *, void*)) ep->kopadr, (int (*)(CSOUND *, void*)) ep->aopadr); diff -Nru csound-5.17.11~dfsg/Opcodes/modal4.c csound-6.02~dfsg/Opcodes/modal4.c --- csound-5.17.11~dfsg/Opcodes/modal4.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/modal4.c 2014-01-07 16:53:48.000000000 +0000 @@ -40,14 +40,15 @@ { FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound,ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound,ifn)) != NULL)) m->vibr = ftp; else { /* Expect sine wave */ - return csound->PerfError(csound, Str("No table for Modal4 case")); + csound->ErrorMsg(csound, Str("No table for Modal4 case")); + return NOTOK; } make_Envelope(&m->envelope); - /* We don't make the excitation wave here yet, */ - /* because we don't know what it's going to be. */ + /* We do not make the excitation wave here yet, */ + /* because we do not know what it's going to be. */ make_BiQuad(&m->filters[0]); make_BiQuad(&m->filters[1]); make_BiQuad(&m->filters[2]); @@ -95,12 +96,12 @@ Modal4 *m, int whichOne, MYFLT ratio,MYFLT reson) { MYFLT temp; - if (ratio* m->baseFreq < csound->esr * FL(0.5)) { + if (ratio* m->baseFreq < CS_ESR * FL(0.5)) { m->ratios[whichOne] = ratio; } else { temp = ratio; - while (temp* m->baseFreq > FL(0.5)*csound->esr) temp *= FL(0.5); + while (temp* m->baseFreq > FL(0.5)*CS_ESR) temp *= FL(0.5); m->ratios[whichOne] = temp; } m->resons[whichOne] = reson; @@ -120,7 +121,7 @@ OnePole_setPole(&m->onepole, FL(1.0) - amplitude); Envelope_tick(&m->envelope); m->w_time = FL(0.0); - m->w_lastOutput = FL(0.0); + //m->w_lastOutput = FL(0.0); m->w_allDone = 0; /* wave->reset(); */ for (i=0;i<4;i++) { @@ -149,7 +150,7 @@ { MYFLT temp,temp2; int32 itemp; - MYFLT temp_time, alpha; + MYFLT temp_time, alpha, lastOutput; int length = (int)m->wave->flen; m->w_time += m->w_rate; /* Update current time */ @@ -174,13 +175,13 @@ itemp = (int32) temp_time; /* Integer part of time address */ alpha = temp_time - (MYFLT)itemp; /* fractional part of time address */ - m->w_lastOutput = m->wave->ftable[itemp]; /* Do linear interpolation */ - m->w_lastOutput = m->w_lastOutput + /* same as alpha*data[temp+1] */ + lastOutput = m->wave->ftable[itemp]; /* Do linear interpolation */ + lastOutput = lastOutput + /* same as alpha*data[temp+1] */ (alpha * (m->wave->ftable[itemp+1] - - m->w_lastOutput)); /* + (1-alpha)data[temp] */ + lastOutput)); /* + (1-alpha)data[temp] */ temp = m->masterGain * - OnePole_tick(&m->onepole, m->w_lastOutput * Envelope_tick(&m->envelope)); + OnePole_tick(&m->onepole, lastOutput * Envelope_tick(&m->envelope)); temp2 = BiQuad_tick(&m->filters[0], temp); temp2 += BiQuad_tick(&m->filters[1], temp); temp2 += BiQuad_tick(&m->filters[2], temp); @@ -211,12 +212,12 @@ itemp = (int32) temp_time; /* Integer part of time address */ /* fractional part of time address */ alpha = temp_time - (MYFLT)itemp; - m->v_lastOutput = m->vibr->ftable[itemp]; /* Do linear interpolation */ + lastOutput = m->vibr->ftable[itemp]; /* Do linear interpolation */ /* same as alpha*data[itemp+1] + (1-alpha)data[temp] */ - m->v_lastOutput = m->v_lastOutput + - (alpha * (m->vibr->ftable[itemp+1] - m->v_lastOutput)); + lastOutput = /*m->v)*/lastOutput + + (alpha * (m->vibr->ftable[itemp+1] - lastOutput)); /* End of vibrato tick */ - temp = FL(1.0) + (m->v_lastOutput * m->vibrGain); /* Calculate AM */ + temp = FL(1.0) + (lastOutput * m->vibrGain); /* Calculate AM */ temp2 = temp * temp2; /* and apply to master out */ } @@ -240,14 +241,15 @@ int itemp; FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->m4.wave = ftp; else { /* Expect an impulslything */ return csound->InitError(csound, Str("No table for Marimba strike")); } if (UNLIKELY(make_Modal4(csound, - m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) return NOTOK; + m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) + return NOTOK; p->m4.w_phaseOffset = FL(0.0); /* p->m4.w_rate = 0.5; */ Modal4_setRatioAndReson(csound,m,0, FL(1.00), FL(0.9996)); /* Set all 132.0 */ @@ -295,13 +297,13 @@ Modal4_setFreq(csound, m, *p->frequency); p->first = 1; { - int relestim = (int) (csound->ekr * *p->dettack); + int relestim = (int) (CS_EKR * *p->dettack); /* 0.1 second decay extention */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; } - p->kloop = (int) ((int32) (p->h.insdshead->offtim * csound->ekr) - - (int32) (csound->ekr * *p->dettack)); + p->kloop = (int) ((int32) (p->h.insdshead->offtim * CS_EKR) + - (int32) (CS_EKR * *p->dettack)); return OK; } @@ -309,7 +311,9 @@ { Modal4 *m = &(p->m4); MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amplitude) * AMP_RSCALE; /* Normalise */ if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1; @@ -323,12 +327,17 @@ Modal4_setFreq(csound, m, *p->frequency); p->first = 0; } - for (n=0;nmultiStrike>0) if (p->m4.w_allDone) { p->m4.w_time = FL(0.0); - p->m4.w_lastOutput = FL(0.0); + //p->m4.w_lastOutput = FL(0.0); p->m4.w_allDone = 0; p->multiStrike -= 1; } @@ -354,14 +363,14 @@ MYFLT temp; FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->m4.wave = ftp; /* Expect an impulslything */ else { return csound->InitError(csound, Str("No table for Vibraphone strike")); } - if (UNLIKELY(make_Modal4(csound, - m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) return NOTOK; + if (UNLIKELY(make_Modal4(csound, m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) + return NOTOK; p->m4.w_phaseOffset = FL(0.0); /* p->m4.w_rate = 13.33; */ @@ -395,7 +404,9 @@ { Modal4 *m = &(p->m4); MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amplitude)*AMP_RSCALE; /* Normalise */ if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1; @@ -409,7 +420,12 @@ } p->m4.v_rate = *p->vibFreq; p->m4.vibrGain =*p->vibAmt; - for (n=0;nFTFind(csound, p->ifn)) != NULL)) p->m4.wave = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->m4.wave = ftp; else { return csound->InitError(csound, Str("No table for Agogobell strike")); } - if (UNLIKELY(make_Modal4(csound, - m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) return NOTOK; + if (UNLIKELY(make_Modal4(csound, m, p->ivfn, *p->vibAmt, *p->vibFreq)==NOTOK)) + return NOTOK; p->m4.w_phaseOffset = FL(0.0); /* p->m4.w_rate = 7.0; */ @@ -474,7 +490,9 @@ { Modal4 *m = &(p->m4); MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; p->m4.v_rate = *p->vibFreq; p->m4.vibrGain =*p->vibAmt; @@ -483,7 +501,12 @@ Modal4_setFreq(csound, m, *p->frequency); p->first = 0; } - for (n=0;nrestab = csound->FTnp2Find(csound, m->ires); m->modtab = csound->FTnp2Find(csound, m->imod); @@ -244,14 +244,14 @@ static OENTRY modmatrix_localops[] = { { - "modmatrix", sizeof(MODMATRIX), TB|3, - "", - "iiiiiik", - (SUBR)modmatrix_init, - (SUBR)modmatrix, - (SUBR)NULL + "modmatrix", sizeof(MODMATRIX), TB, 3, + "", + "iiiiiik", + (SUBR)modmatrix_init, + (SUBR)modmatrix, + (SUBR)NULL } }; -LINKAGE1(modmatrix_localops) +LINKAGE_BUILTIN(modmatrix_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/moog1.c csound-6.02~dfsg/Opcodes/moog1.c --- csound-5.17.11~dfsg/Opcodes/moog1.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/moog1.c 2014-01-07 16:53:48.000000000 +0000 @@ -139,7 +139,7 @@ temp = (int32) temp_time; /* Integer part of time address */ temp1 = temp + 1; - if (UNLIKELY(temp1==p->wave->flen)) temp1 = 0; /* Wrap!! */ + if (UNLIKELY(temp1==(int)p->wave->flen)) temp1 = 0; /* Wrap!! */ /* fractional part of time address */ alpha = temp_time - (MYFLT)temp; lastOutput = p->wave->ftable[temp]; /* Do linear interpolation */ @@ -163,13 +163,13 @@ make_FormSwep(&p->filters[0]); make_FormSwep(&p->filters[1]); - if (LIKELY((ftp = csound->FTFind(csound, p->iatt)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iatt)) != NULL)) p->attk.wave = ftp; /* mandpluk */ else return NOTOK; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn )) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn )) != NULL)) p->loop.wave = ftp; /* impuls20 */ else return NOTOK; - if (LIKELY((ftp = csound->FTFind(csound, p->ivfn)) != NULL)) + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ivfn)) != NULL)) p->vibr.wave = ftp; /* sinewave */ else return NOTOK; p->attk.time = p->attk.phase = FL(0.0); @@ -186,7 +186,9 @@ { MYFLT amp = *p->amp * AMP_RSCALE; /* Normalised */ MYFLT *ar = p->ar; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT temp; MYFLT vib = *p->vibAmt; @@ -215,7 +217,12 @@ } p->vibr.rate = *p->vibf * p->vibr.wave->flen * csound->onedsr; - for (n = 0; nInitError(csound, mp3dec_error(r)); } /* FIXME: name can overflow with very long string */ - csound->strarg2name(csound, name, p->iFileCode, "soundin.", p->XSTRCODE); + if(stringname==0){ + if (ISSTRCOD(*p->iFileCode)) + strncpy(name,get_arg_string(csound, *p->iFileCode), 1023); + else csound->strarg2name(csound, name, p->iFileCode, "soundin.",0); + } + else strncpy(name, ((STRINGDAT *)p->iFileCode)->data, 1023); + if (UNLIKELY(csound->FileOpen2(csound, &fd, CSFILE_FD_R, name, "rb", "SFDIR;SSDIR", CSFTYPE_OTHER_BINARY, 0) == NULL)) { @@ -113,7 +119,7 @@ mp3dec_uninit(mpa); return csound->InitError(csound, mp3dec_error(r)); } - skip = (int)(*p->iSkipTime*csound->esr+1); + skip = (int)(*p->iSkipTime*CS_ESR+1); /* maxsize = mpainfo.decoded_sample_size */ /* *mpainfo.decoded_frame_samples */ /* *mpainfo.frames; */ @@ -144,21 +150,21 @@ if (*(p->iSkipInit) != FL(0.0)) return OK; /* set file parameters from header info */ - if ((int) (csound->esr + FL(0.5)) != mpainfo.frequency) { + if ((int) (CS_ESR + FL(0.5)) != mpainfo.frequency) { csound->Warning(csound, Str("mp3in: file sample rate (%d) " "!= orchestra sr (%d)\n"), - mpainfo.frequency, (int) (csound->esr + FL(0.5))); + mpainfo.frequency, (int) (CS_ESR + FL(0.5))); } /* initialise buffer */ p->bufSize = buffersize; - if (p->auxch.auxp == NULL || p->auxch.size < buffersize) + if (p->auxch.auxp == NULL || p->auxch.size < (unsigned int)buffersize) csound->AuxAlloc(csound, buffersize, &p->auxch); p->buf = (uint8_t *) p->auxch.auxp; p->bufused = -1; buffersize /= mpainfo.decoded_sample_size; while (skip > 0) { - uint32_t xx= skip; - if ((uint32_t)xx > buffersize) xx = buffersize; + int xx= skip; + if (xx > buffersize) xx = buffersize; skip -= xx; r = mp3dec_decode(mpa, p->buf, mpainfo.decoded_sample_size*xx, &p->bufused); } @@ -171,6 +177,15 @@ return OK; } +int mp3ininit(CSOUND *csound, MP3IN *p){ + return mp3ininit_(csound,p,0); +} + +int mp3ininit_S(CSOUND *csound, MP3IN *p){ + return mp3ininit_(csound,p,1); +} + + int mp3in(CSOUND *csound, MP3IN *p) { int r = p->r; @@ -179,13 +194,24 @@ MYFLT *al = p->ar[0]; MYFLT *ar = p->ar[1]; int pos = p->pos; - int i, n, nsmps = csound->ksmps; - - for (n=0; nh.insdshead->ksmps_no_end; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t i, n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) { + memset(al, '\0', offset*sizeof(MYFLT)); + memset(ar, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&al[nsmps], '\0', early*sizeof(MYFLT)); + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; n= p->bufused) { + while (r != MP3DEC_RETCODE_OK || 2*pos >= (int)p->bufused) { r = mp3dec_decode(mpa, buffer, p->bufSize, &p->bufused); if (UNLIKELY(p->bufused == 0)) { memset(&al[n], 0, (nsmps-n)*sizeof(MYFLT)); @@ -211,7 +237,7 @@ return OK; } -int mp3len(CSOUND *csound, MP3LEN *p) +int mp3len_(CSOUND *csound, MP3LEN *p, int stringname) { char name[1024]; int fd; @@ -233,7 +259,13 @@ return csound->InitError(csound, mp3dec_error(r)); } /* FIXME: name can overflow with very long string */ - csound->strarg2name(csound, name, p->iFileCode, "soundin.", p->XSTRCODE); + + if(stringname==0){ + if(ISSTRCOD(*p->iFileCode)) + strncpy(name,get_arg_string(csound, *p->iFileCode), 1023); + else csound->strarg2name(csound, name, p->iFileCode, "soundin.",0); + } + else strncpy(name, ((STRINGDAT *)p->iFileCode)->data, 1023); if (UNLIKELY(csound->FileOpen2(csound, &fd, CSFILE_FD_R, name, "rb", "SFDIR;SSDIR", CSFTYPE_OTHER_BINARY, 0) == NULL)) { @@ -257,11 +289,21 @@ return OK; } +int mp3len(CSOUND *csound, MP3LEN *p){ + return mp3len_(csound,p,0); +} + +int mp3len_S(CSOUND *csound, MP3LEN *p){ + return mp3len_(csound,p,1); +} + #define S(x) sizeof(x) static OENTRY mp3in_localops[] = { - {"mp3in", S(MP3IN), 5, "aa", "Toooo", (SUBR) mp3ininit, NULL, (SUBR) mp3in}, - {"mp3len", S(MP3LEN), 1, "i", "T", (SUBR) mp3len, NULL, NULL} + {"mp3in", S(MP3IN), 0, 5, "aa", "Soooo", (SUBR) mp3ininit_S, NULL, (SUBR) mp3in}, + {"mp3in.i", S(MP3IN), 0, 5, "aa", "ioooo", (SUBR) mp3ininit, NULL, (SUBR) mp3in}, + {"mp3len", S(MP3LEN), 0, 1, "i", "S", (SUBR) mp3len_S, NULL, NULL}, + {"mp3len.i", S(MP3LEN), 0, 1, "i", "i", (SUBR) mp3len, NULL, NULL} }; -LINKAGE1(mp3in_localops) +LINKAGE_BUILTIN(mp3in_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/newfils.c csound-6.02~dfsg/Opcodes/newfils.c --- csound-5.17.11~dfsg/Opcodes/newfils.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/newfils.c 2014-01-07 16:54:20.000000000 +0000 @@ -22,7 +22,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include "newfils.h" #include @@ -35,6 +35,8 @@ p->delay[i] = 0.0; for (i = 0; i < 3; i++) p->tanhstg[i] = 0.0; + p->oldfreq = FL(0.0); + p->oldres = -FL(1.0); /* ensure calculation on first cycle */ } return OK; } @@ -49,40 +51,356 @@ double *delay = p->delay; double *tanhstg = p->tanhstg; double stg[4], input; - double f, fc, fc2, fc3, fcr, acr, tune; - double thermal = (1.0 / 40000.0); /* transistor thermal voltage */ - int j, k, i; + double acr, tune; +#define THERMAL (0.000025) /* (1.0 / 40000.0) transistor thermal voltage */ + int j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; if (res < 0) res = 0; - /* sr is half the actual filter sampling rate */ - fc = (double)(freq/csound->esr); - f = fc/2; - fc2 = fc*fc; - fc3 = fc2*fc; - /* frequency & amplitude correction */ - fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; - acr = -3.9364*fc2 + 1.8409*fc + 0.9968; - tune = (1.0 - exp(-(TWOPI*f*fcr))) / thermal; /* filter tuning */ + if (p->oldfreq != freq || p->oldres != res) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = freq; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = res; + p->oldacr = acr; + p->oldtune = tune; + } + else { + res = p->oldres; + acr = p->oldacr; + tune = p->oldtune; + } + res4 = 4.0*(double)res*acr; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { + /* oversampling */ + for (j = 0; j < 2; j++) { + /* filter stages */ + input = in[i] - res4 /*4.0*res*acr*/ *delay[5]; + delay[0] = stg[0] = delay[0] + tune*(tanh(input*THERMAL) - tanhstg[0]); +#if 0 + input = stg[0]; + stg[1] = delay[1] + tune*((tanhstg[0] = tanh(input*THERMAL)) - tanhstg[1]); + input = delay[1] = stg[1]; + stg[2] = delay[2] + tune*((tanhstg[1] = tanh(input*THERMAL)) - tanhstg[2]); + input = delay[2] = stg[2]; + stg[3] = delay[3] + tune*((tanhstg[2] = + tanh(input*THERMAL)) - tanh(delay[3]*THERMAL)); + delay[3] = stg[3]; +#else + for (k = 1; k < 4; k++) { + input = stg[k-1]; + stg[k] = delay[k] + + tune*((tanhstg[k-1] = tanh(input*THERMAL)) + - (k != 3 ? tanhstg[k] : tanh(delay[k]*THERMAL))); + delay[k] = stg[k]; + } +#endif + /* 1/2-sample delay for phase compensation */ + delay[5] = (stg[3] + delay[4])*0.5; + delay[4] = stg[3]; + } + out[i] = (MYFLT) delay[5]; + } + return OK; +} + +static int moogladder_process_aa(CSOUND *csound,moogladder *p) +{ + MYFLT *out = p->out; + MYFLT *in = p->in; + MYFLT *freq = p->freq; + MYFLT *res = p->res; + MYFLT cfreq = freq[0], cres = res[0]; + double res4; + double *delay = p->delay; + double *tanhstg = p->tanhstg; + double stg[4], input; + double acr, tune; +#define THERMAL (0.000025) /* (1.0 / 40000.0) transistor thermal voltage */ + int j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + + if (p->oldfreq != cfreq || p->oldres != cres) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = cfreq; + /* sr is half the actual filter sampling rate */ + fc = (double)(cfreq/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = cres; + p->oldacr = acr; + p->oldtune = tune; + } + else { + cres = p->oldres; + acr = p->oldacr; + tune = p->oldtune; + } + res4 = 4.0*(double)cres*acr; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { + if (p->oldfreq != freq[i] || p->oldres != res[i]) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = freq[i]; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq[i]/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = cres; + p->oldacr = acr; + p->oldtune = tune; + res4 = 4.0*(double)res[i]*acr; + } + /* oversampling */ + for (j = 0; j < 2; j++) { + /* filter stages */ + input = in[i] - res4 /*4.0*res*acr*/ *delay[5]; + delay[0] = stg[0] = delay[0] + tune*(tanh(input*THERMAL) - tanhstg[0]); +#if 0 + input = stg[0]; + stg[1] = delay[1] + tune*((tanhstg[0] = tanh(input*THERMAL)) - tanhstg[1]); + input = delay[1] = stg[1]; + stg[2] = delay[2] + tune*((tanhstg[1] = tanh(input*THERMAL)) - tanhstg[2]); + input = delay[2] = stg[2]; + stg[3] = delay[3] + tune*((tanhstg[2] = + tanh(input*THERMAL)) - tanh(delay[3]*THERMAL)); + delay[3] = stg[3]; +#else + for (k = 1; k < 4; k++) { + input = stg[k-1]; + stg[k] = delay[k] + + tune*((tanhstg[k-1] = tanh(input*THERMAL)) + - (k != 3 ? tanhstg[k] : tanh(delay[k]*THERMAL))); + delay[k] = stg[k]; + } +#endif + /* 1/2-sample delay for phase compensation */ + delay[5] = (stg[3] + delay[4])*0.5; + delay[4] = stg[3]; + } + out[i] = (MYFLT) delay[5]; + } + return OK; +} + +static int moogladder_process_ak(CSOUND *csound,moogladder *p) +{ + MYFLT *out = p->out; + MYFLT *in = p->in; + MYFLT *freq = p->freq; + MYFLT res = *p->res; + double res4; + double *delay = p->delay; + double *tanhstg = p->tanhstg; + double stg[4], input; + double acr, tune; +#define THERMAL (0.000025) /* (1.0 / 40000.0) transistor thermal voltage */ + int j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + + if (res < 0) res = 0; + + if (p->oldfreq != freq[0] || p->oldres != res) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = freq[0]; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq[0]/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = res; + p->oldacr = acr; + p->oldtune = tune; + } + else { + res = p->oldres; + acr = p->oldacr; + tune = p->oldtune; + } res4 = 4.0*(double)res*acr; - for (i = 0; i < csound->ksmps; i++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { + if (p->oldfreq != freq[i]) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = freq[i]; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq[i]/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldacr = acr; + p->oldtune = tune; + res4 = 4.0*(double)res*acr; + } /* oversampling */ for (j = 0; j < 2; j++) { /* filter stages */ - for (k = 0; k < 4; k++) { - if (k) { - input = stg[k-1]; - stg[k] = delay[k] - + tune*((tanhstg[k-1] = tanh(input*thermal)) - - (k != 3 ? tanhstg[k] : tanh(delay[k]*thermal))); - } - else { - input = in[i] - res4 /*4.0*res*acr*/ *delay[5]; - stg[k] = delay[k] + tune*(tanh(input*thermal) - tanhstg[k]); - } + input = in[i] - res4 /*4.0*res*acr*/ *delay[5]; + delay[0] = stg[0] = delay[0] + tune*(tanh(input*THERMAL) - tanhstg[0]); +#if 0 + input = stg[0]; + stg[1] = delay[1] + tune*((tanhstg[0] = tanh(input*THERMAL)) - tanhstg[1]); + input = delay[1] = stg[1]; + stg[2] = delay[2] + tune*((tanhstg[1] = tanh(input*THERMAL)) - tanhstg[2]); + input = delay[2] = stg[2]; + stg[3] = delay[3] + tune*((tanhstg[2] = + tanh(input*THERMAL)) - tanh(delay[3]*THERMAL)); + delay[3] = stg[3]; +#else + for (k = 1; k < 4; k++) { + input = stg[k-1]; + stg[k] = delay[k] + + tune*((tanhstg[k-1] = tanh(input*THERMAL)) + - (k != 3 ? tanhstg[k] : tanh(delay[k]*THERMAL))); delay[k] = stg[k]; } +#endif + /* 1/2-sample delay for phase compensation */ + delay[5] = (stg[3] + delay[4])*0.5; + delay[4] = stg[3]; + } + out[i] = (MYFLT) delay[5]; + } + return OK; +} + +static int moogladder_process_ka(CSOUND *csound,moogladder *p) +{ + MYFLT *out = p->out; + MYFLT *in = p->in; + MYFLT freq = *p->freq; + MYFLT *res = p->res; + MYFLT cres = res[0]; + double res4; + double *delay = p->delay; + double *tanhstg = p->tanhstg; + double stg[4], input; + double acr, tune; +#define THERMAL (0.000025) /* (1.0 / 40000.0) transistor thermal voltage */ + int j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + + if (cres < 0) cres = 0; + + if (p->oldfreq != freq || p->oldres != cres) { + double f, fc, fc2, fc3, fcr; + p->oldfreq = freq; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = cres; + p->oldacr = acr; + p->oldtune = tune; + } + else { + cres = p->oldres; + acr = p->oldacr; + tune = p->oldtune; + } + res4 = 4.0*(double)cres*acr; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) { + if (cres != res[i]) { + double f, fc, fc2, fc3, fcr; + /* sr is half the actual filter sampling rate */ + fc = (double)(freq/CS_ESR); + f = 0.5*fc; + fc2 = fc*fc; + fc3 = fc2*fc; + /* frequency & amplitude correction */ + fcr = 1.8730*fc3 + 0.4955*fc2 - 0.6490*fc + 0.9988; + acr = -3.9364*fc2 + 1.8409*fc + 0.9968; + tune = (1.0 - exp(-(TWOPI*f*fcr))) / THERMAL; /* filter tuning */ + p->oldres = cres = res[i]; + p->oldacr = acr; + p->oldtune = tune; + res4 = 4.0*(double)cres*acr; + } + /* oversampling */ + for (j = 0; j < 2; j++) { + /* filter stages */ + input = in[i] - res4 /*4.0*res*acr*/ *delay[5]; + delay[0] = stg[0] = delay[0] + tune*(tanh(input*THERMAL) - tanhstg[0]); +#if 0 + input = stg[0]; + stg[1] = delay[1] + tune*((tanhstg[0] = tanh(input*THERMAL)) - tanhstg[1]); + input = delay[1] = stg[1]; + stg[2] = delay[2] + tune*((tanhstg[1] = tanh(input*THERMAL)) - tanhstg[2]); + input = delay[2] = stg[2]; + stg[3] = delay[3] + tune*((tanhstg[2] = + tanh(input*THERMAL)) - tanh(delay[3]*THERMAL)); + delay[3] = stg[3]; +#else + for (k = 1; k < 4; k++) { + input = stg[k-1]; + stg[k] = delay[k] + + tune*((tanhstg[k-1] = tanh(input*THERMAL)) + - (k != 3 ? tanhstg[k] : tanh(delay[k]*THERMAL))); + delay[k] = stg[k]; + } +#endif /* 1/2-sample delay for phase compensation */ delay[5] = (stg[3] + delay[4])*0.5; delay[4] = stg[3]; @@ -96,6 +414,8 @@ { if (*p->istor==FL(0.0)) { p->bpd = p->lpd = p->lp = 0.0; + p->oldfreq = FL(0.0); + p->oldres = FL(0.0); } if (*p->osamp<=FL(0.0)) p->ostimes = 3; else p->ostimes = (int) *p->osamp; @@ -109,23 +429,49 @@ MYFLT *outbp = p->outbp; MYFLT *outbr = p->outbr; MYFLT *in = p->in; - MYFLT freq = *p->freq; - MYFLT res = *p->res; + MYFLT *freq = p->freq; + MYFLT *res = p->res; double lpd = p->lpd; double bpd = p->bpd; double lp = p->lp, hp = 0.0, bp = 0.0, br = 0.0; double f,q,lim; - int ostimes = p->ostimes,i,j; - - f = 2.0*sin(freq*(double)csound->pidsr/ostimes); - q = 1.0/res; - lim = 0.1*((2.0 - f) / 2.)*(1./ostimes); - /* csound->Message(csound, "lim: %f, q: %f \n", lim, q); */ - - if (q < lim) q = lim; + int ostimes = p->ostimes,j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) { + memset(outhp, '\0', offset*sizeof(MYFLT)); + memset(outlp, '\0', offset*sizeof(MYFLT)); + memset(outbp, '\0', offset*sizeof(MYFLT)); + memset(outbr, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outhp[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outlp[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outbp[nsmps], '\0', early*sizeof(MYFLT)); + memset(&outbr[nsmps], '\0', early*sizeof(MYFLT)); + } + q = p->oldq; + f = p->oldf; - for (i=0; iksmps;i++) { - for (j=0;joldfreq != fr|| p->oldres != rs) { + f = 2.0*sin(fr*(double)csound->pidsr/ostimes); + q = 1.0/rs; + lim = ((2.0 - f) *0.05)/ostimes; + /* csound->Message(csound, "lim: %f, q: %f \n", lim, q); */ + + if (q < lim) q = lim; + p->oldq = q; + p->oldf = f; + p->oldfreq = fr; + p->oldres = rs; + } + for (j=0; jout; MYFLT *in = p->in; - MYFLT freq = *p->freq; - MYFLT ris = *p->ris; - MYFLT dec = *p->dec; - double *delay = p->delay,ang,fsc,rad1,rad2; + MYFLT *freq = p->freq; + MYFLT *ris = p->ris; + MYFLT *dec = p->dec; + double *delay = p->delay,ang,fsc,rrad1,rrad2; double w1,y1,w2,y2; - int i; - - ang = (double)csound->tpidsr*freq; /* pole angle */ - fsc = sin(ang) - 3.0; /* freq scl */ - rad1 = pow(10.0, fsc/(dec*csound->esr)); /* filter radii */ - rad2 = pow(10.0, fsc/(ris*csound->esr)); - - for (i=0;iksmps;i++) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + MYFLT lfrq = -FL(1.0), lrs = -FL(1.0), ldc = -FL(1.0); + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset;itpidsr*frq; /* pole angle */ + fsc = sin(ang) - 3.0; /* freq scl */ + rrad1 = pow(10.0, fsc/(dc*CS_ESR)); /* filter radii */ + rrad2 = pow(10.0, fsc/(rs*CS_ESR)); + } - w1 = in[i] + 2.0*rad1*cos(ang)*delay[0] - rad1*rad1*delay[1]; + w1 = in[i] + 2.0*rrad1*cos(ang)*delay[0] - rrad1*rrad1*delay[1]; y1 = w1 - delay[1]; delay[1] = delay[0]; delay[0] = w1; - w2 = in[i] + 2.0*rad2*cos(ang)*delay[2] - rad2*rad2*delay[3]; + w2 = in[i] + 2.0*rrad2*cos(ang)*delay[2] - rrad2*rrad2*delay[3]; y2 = w2 - delay[3]; delay[3] = delay[2]; delay[2] = w2; @@ -193,11 +552,17 @@ } static OENTRY localops[] = { - {"moogladder", sizeof(moogladder), 5, "a", "akkp", + {"moogladder.kk", sizeof(moogladder), 0, 5, "a", "akkp", (SUBR) moogladder_init, NULL, (SUBR) moogladder_process }, - {"statevar", sizeof(statevar), 5, "aaaa", "akkop", + {"moogladder.aa", sizeof(moogladder), 0, 5, "a", "aaap", + (SUBR) moogladder_init, NULL, (SUBR) moogladder_process_aa }, + {"moogladder.ak", sizeof(moogladder), 0, 5, "a", "aakp", + (SUBR) moogladder_init, NULL, (SUBR) moogladder_process_ak }, + {"moogladder.ka", sizeof(moogladder), 0, 5, "a", "akap", + (SUBR) moogladder_init, NULL, (SUBR) moogladder_process_ka }, + {"statevar", sizeof(statevar), 0, 5, "aaaa", "axxop", (SUBR) statevar_init, NULL, (SUBR) statevar_process }, - {"fofilter", sizeof(fofilter), 5, "a", "akkkp", + {"fofilter", sizeof(fofilter), 0, 5, "a", "axxxp", (SUBR) fofilter_init, NULL, (SUBR) fofilter_process } }; @@ -206,4 +571,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/newfils.h csound-6.02~dfsg/Opcodes/newfils.h --- csound-5.17.11~dfsg/Opcodes/newfils.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/newfils.h 2014-01-07 16:53:48.000000000 +0000 @@ -98,6 +98,10 @@ double delay[6]; double tanhstg[3]; + MYFLT oldfreq; + MYFLT oldres; + double oldacr; + double oldtune; } moogladder; static int moogladder_init(CSOUND *csound,moogladder *p); @@ -119,6 +123,10 @@ double lpd; double lp; int ostimes; + MYFLT oldfreq; + MYFLT oldres; + double oldq; + double oldf; } statevar; static int statevar_init(CSOUND *csound,statevar *p); diff -Nru csound-5.17.11~dfsg/Opcodes/nlfilt.c csound-6.02~dfsg/Opcodes/nlfilt.c --- csound-5.17.11~dfsg/Opcodes/nlfilt.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/nlfilt.c 2014-01-07 16:53:48.000000000 +0000 @@ -30,7 +30,7 @@ * See paper by Dobson and ffitch, ICMC'96 * \***************************************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "nlfilt.h" typedef struct { @@ -64,7 +64,9 @@ static int nlfilt(CSOUND *csound, NLFILT *p) { MYFLT *ar; - int n, nsmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int point = p->point; int nm1 = point; int nm2 = point - 1; @@ -91,11 +93,15 @@ ynm1 = fp[nm1]; /* Pick up running values */ ynm2 = fp[nm2]; ynmL = fp[nmL]; - nsmps = csound->ksmps; maxamp = csound->e0dbfs * FL(1.953125); /* 64000 with default 0dBFS */ dvmaxamp = FL(1.0) / maxamp; maxampd2 = maxamp * FL(0.5); - for (n=0; npoint = point; return OK; err1: - return csound->PerfError(csound, Str("nlfilt: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("nlfilt: not initialised")); } /* end nlfilt(p) */ /* Y{n} = a Y{n-1} + b Y{n-2} + d Y^2{n-L} + X{n} - C */ +/* Revised version due to Risto Holopainen 12 Mar 2004 */ +/* Y{n} =tanh(a Y{n-1} + b Y{n-2} + d Y^2{n-L} + X{n} - C) */ + +static int nlfilt2(CSOUND *csound, NLFILT *p) +{ + MYFLT *ar; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int point = p->point; + int nm1 = point; + int nm2 = point - 1; + int nmL; + MYFLT ynm1, ynm2, ynmL; + MYFLT a = *p->a, b = *p->b, d = *p->d, C = *p->C; + MYFLT *in = p->in; + MYFLT *fp = (MYFLT*) p->delay.auxp; + MYFLT L = *p->L; + MYFLT maxamp, dvmaxamp, maxampd2; + + if (UNLIKELY(fp == NULL)) goto err1; /* RWD fix */ + ar = p->ar; + /* L is k-rate so need to check */ + if (L < FL(1.0)) + L = FL(1.0); + else if (L >= MAX_DELAY) { + L = (MYFLT) MAX_DELAY; + } + nmL = point - (int) (L) - 1; + if (UNLIKELY(nm1 < 0)) nm1 += MAX_DELAY; /* Deal with the wrapping */ + if (UNLIKELY(nm2 < 0)) nm2 += MAX_DELAY; + if (UNLIKELY(nmL < 0)) nmL += MAX_DELAY; + ynm1 = fp[nm1]; /* Pick up running values */ + ynm2 = fp[nm2]; + ynmL = fp[nmL]; + nsmps = CS_KSMPS; + maxamp = csound->e0dbfs * FL(1.953125); /* 64000 with default 0dBFS */ + dvmaxamp = FL(1.0) / maxamp; + maxampd2 = maxamp * FL(0.5); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; n maxamp) + out = maxampd2; + else if (out < -maxamp) + out = -maxampd2; + ar[n] = out; + if (UNLIKELY(++point == MAX_DELAY)) { + point = 0; + } + yn = TANH(yn); + fp[point] = yn; /* and delay line */ + if (UNLIKELY(++nmL == MAX_DELAY)) { + nmL = 0; + } + ynm2 = ynm1; /* Shuffle along */ + ynm1 = yn; + ynmL = fp[nmL]; + } + p->point = point; + return OK; + err1: + return csound->PerfError(csound, p->h.insdshead, + Str("nlfilt2: not initialised")); +} /* end nlfilt2(p) */ + /* ***************************************************************** */ /* ***************************************************************** */ /* ***************************************************************** */ @@ -159,19 +240,13 @@ if (nargs>pargs) csound->Warning(csound, Str("More arguments than p fields")); for (n=0; (nXOUTSTRCODE & x) { - /* printf("A string: n=%d x=%d\n", n, x); */ - if (UNLIKELY((int)strlen((char*)csound->currevent->strarg) >= - csound->strVarMaxLen)) - return csound->InitError(csound, Str("buffer overflow in passign")); - strcpy((char*) p->inits[n], (char*)csound->currevent->strarg); - x = 0; /* Only one string */ - } - else { - *p->inits[n] = csound->currevent->p[n+start]; + if(ISSTRCOD(csound->currevent->p[n+start])) { + ((STRINGDAT *)p->inits[n])->data = + cs_strdup(csound, get_arg_string(csound, csound->currevent->p[n+start])); + ((STRINGDAT *)p->inits[n])->size = + strlen(((STRINGDAT *)p->inits[n])->data)+1; } + else *p->inits[n] = csound->currevent->p[n+start]; x <<= 1; } return OK; @@ -180,10 +255,12 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "pcount", S(PFIELD), 1, "i", "", (SUBR)pcount, NULL, NULL }, -{ "pindex", S(PFIELD), 1, "i", "i", (SUBR)pvalue, NULL, NULL }, -{ "passign", S(PINIT), 1, "IIIIIIIIIIIIIIIIIIIIIIII", "p", (SUBR)pinit, NULL, NULL }, -{ "nlfilt", S(NLFILT), 5, "a", "akkkkk", (SUBR)nlfiltset, NULL, (SUBR)nlfilt } +{ "pcount", S(PFIELD), 0, 1, "i", "", (SUBR)pcount, NULL, NULL }, +{ "pindex", S(PFIELD), 0, 1, "i", "i", (SUBR)pvalue, NULL, NULL }, +{ "passign", S(PINIT), 0, 1, "IIIIIIIIIIIIIIIIIIIIIIII", "p", + (SUBR)pinit, NULL, NULL }, +{ "nlfilt", S(NLFILT), 0, 5, "a", "akkkkk", (SUBR)nlfiltset, NULL, (SUBR)nlfilt }, +{ "nlfilt2", S(NLFILT), 0, 5, "a", "akkkkk", (SUBR)nlfiltset, NULL, (SUBR)nlfilt2 } }; int nlfilt_init_(CSOUND *csound) @@ -191,4 +268,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/ogg.c csound-6.02~dfsg/Opcodes/ogg.c --- csound-5.17.11~dfsg/Opcodes/ogg.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ogg.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,163 +0,0 @@ -/* - Copyright (C) 2007 Simon Schampijer - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -#include -#include - -#include "csdl.h" - -#define OGGREAD_MAXCHAN 2 -#define OGGREAD_BUFLEN 1024 - -typedef struct -{ - OPDS h; - MYFLT *aout[OGGREAD_MAXCHAN]; /* outarg */ - MYFLT* *ifilename, *iseek; /* inargs */ - OggVorbis_File vf; - int bs; - int nsamples; - int doperf; - int nchannels; - int16_t *pint; - void *pbuf[OGGREAD_BUFLEN]; -} OGGREAD; - - -int oggread_init (CSOUND *csound, OGGREAD * p) -{ - FILE *in; - char name[1024]; - float iseek = *p->iseek; - vorbis_info *vi; - - /* check number of channels */ - p->nchannels = (int) (p->OUTOCOUNT); - if (p->nchannels < 1 || p->nchannels > OGGREAD_MAXCHAN) { - return csound->InitError(csound, Str("oggread: invalid number of channels")); - } - - csound->strarg2name(csound, name, p->ifilename, "oggread.", p->XSTRCODE); - in = fopen(name, "rb"); - if (!in) { - return csound->InitError(csound, Str("oggread: Failed to open file")); - } - - if (ov_open(in, &p->vf, NULL, 0) < 0) { - fclose(in); - return csound->InitError(csound, - Str("oggread: Failed to open input as vorbis")); - } - - /* check number of channels in file (must be equal the number of outargs) */ - if ((vi=ov_info(&p->vf, 0))->channels != p->nchannels) { - return csound->InitError(csound, Str("oggread: number of output args " - "inconsistent with number of file " - "channels")); - } - - /* Check samplerate */ - if ((MYFLT)(vi->rate) != csound->esr) { - csound->Warning(csound, Str("oggread: sample rate of file is %d " - "which coes not match sr (=%f)\n"), - vi->rate, csound->esr); - } - p->bs = 0; - p->nsamples = 0; -/* p->pint=NULL; */ - p->doperf = 1; - - if (iseek) { - if (ov_seekable(&p->vf)) { - /* get the total time in seconds of the physical bitstream */ - double length=ov_time_total(&p->vf,-1); - if (length > iseek) { - csound->Warning(csound, Str("oggread: seek file to sec=%f\n"), iseek); - ov_time_seek(&p->vf, iseek); - } - else - csound->Warning(csound, - Str("oggread: seek_point=%f > file_length=%f\n"), - iseek, length); - } - else - csound->Warning(csound, Str("oggread: file is not seekable\n")); - } - return OK; -} - -int oggread_perf (CSOUND *csound, OGGREAD * p) -{ - int ret; - int i, nsmps=csound->ksmps; - - for (i = 0; i < nsmps; i++) { - if (p->doperf == 1) { - if (p->nsamples < p->nchannels) { - if ((ret = ov_read(&p->vf, p->pbuf, OGGREAD_BUFLEN, - 0, 2, 1, &p->bs)) != 0) { - if (p->bs != 0) - csound->Warning(csound, - Str("oggread: Only one logical bitstream " - "currently supported\n")); - if (ret < 0 ) - csound->Warning(csound, Str("oggread: Warning hole in data\n")); - p->pint = (int16_t*) p->pbuf; - p->nsamples = ret/2; - p->doperf = 1; - } - else { - ov_clear(&p->vf); - /* End of file */ - p->doperf = 0; - return OK; - } - } - if (p->nchannels == 1) { - p->aout[0][i] = (MYFLT) (*p->pint++); - } - else if (p->nchannels == 2) { - p->aout[0][i] = (MYFLT) (*p->pint++); - p->nsamples--; - p->aout[1][i] = (MYFLT) (*p->pint++); - } - p->nsamples--; - } - else { - if (p->nchannels == 1) - p->aout[0][i] = FL(0.0); - else if (p->nchannels == 2) { - p->aout[0][i] = FL(0.0); - p->aout[1][i] = FL(0.0); - } - } - } - return OK; -} - - - -#define S(x) sizeof(x) - -static OENTRY ogg_localops[] = { - { "oggread", S(OGGREAD), 5, "mm", "To", - (SUBR) oggread_init, (SUBR) NULL, (SUBR) oggread_perf } -}; - -LINKAGE1(ogg_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/oggplay.c csound-6.02~dfsg/Opcodes/oggplay.c --- csound-5.17.11~dfsg/Opcodes/oggplay.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/oggplay.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,148 +0,0 @@ - -#include -#include - -#include "csdl.h" - -#define OGGPLAY_MAXCHAN 2 -#define OGGPLAY_BUFLEN 1024 - -typedef struct -{ - OPDS h; - MYFLT *aout[OGGPLAY_MAXCHAN]; /* outarg */ - MYFLT* *ifilename, *iseek; /* inargs */ - OggVorbis_File vf; - int bs; - int nsamples; - int buflen; - int doperf; - int nchannels; - int16_t *pint; - AUXCH pbuf; -} OGGPLAY; - - -int oggplay_init (CSOUND *csound, OGGPLAY * p) -{ - FILE *in; - char name[1024]; - float iseek = *p->iseek; - - /* check number of channels */ - p->nchannels = (int) (p->OUTOCOUNT); - if (p->nchannels < 1 || p->nchannels > OGGPLAY_MAXCHAN) { - return csound->InitError(csound, Str("oggplay: invalid number of channels")); - } - - csound->strarg2name(csound, name, p->ifilename, "oggplay.", p->XSTRCODE); - in = fopen(name, "rb"); - if (!in) { - return csound->InitError(csound, Str("oggplay: Failed to open file")); - } - - if (ov_open(in, &p->vf, NULL, 0) < 0) { - fclose(in); - return csound->InitError(csound, - Str("oggplay: Failed to open input as vorbis")); - } - - /* check number of channels in file (must be equal the number of outargs) */ - if (ov_info(&p->vf, 0)->channels != p->nchannels) { - return csound->InitError(csound, Str("oggplay: number of output args " - "inconsistent with number of file" - " channels")); - } - - p->bs = 0; - p->nsamples = 0; - p->buflen = OGGPLAY_BUFLEN; - p->pint = NULL; - p->doperf = 1; - - csound->AuxAlloc(csound, p->buflen, &(p->pbuf)); - - if (iseek) { - if (ov_seekable(&p->vf)) { - /* get the total time in seconds of the physical bitstream */ - double length=ov_time_total(&p->vf,-1); - if (length > iseek){ - csound->Warning(csound, Str("oggplay: seek file to sec=%f \n"), iseek); - ov_time_seek(&p->vf, iseek); - } - else - csound->Warning(csound, - Str("oggplay: seek_point=%f > file_length=%f \n"), - iseek, length); - } - else - csound->Warning(csound, Str("oggplay: file is not seekable \n")); - } - - return OK; -} - - -int oggplay_perf (CSOUND *csound, OGGPLAY * p) -{ - int ret; - int i, nsmps=csound->ksmps; - - - for (i = 0; i < nsmps; i++) { - if (p->doperf == 1) { - if (p->nsamples < p->nchannels) { - if ((ret = ov_read(&p->vf, p->pbuf.auxp, - p->buflen, 0, 2, 1, &p->bs)) != 0) { - if (p->bs != 0) - csound->Warning(csound, - Str("oggplay: Only one logical " - "bitstream currently supported\n")); - if (ret < 0 ) - csound->Warning(csound, - Str("oggplay: Warning hole in data\n")); - p->pint = (int16_t*) p->pbuf.auxp; - p->nsamples = ret/2; - p->doperf = 1; - } - else { - ov_clear(&p->vf); - /* End of file */ - p->doperf = 0; - return OK; - } - } - if (p->nchannels == 1) { - p->aout[0][i] = (MYFLT) (*p->pint); - } - else if (p->nchannels == 2) { - p->aout[0][i] = (MYFLT) (*p->pint); - p->pint += 1; - p->nsamples -= 1; - p->aout[1][i] = (MYFLT) (*p->pint); - } - p->pint += 1; - p->nsamples -= 1; - } - else { - if (p->nchannels == 1) - p->aout[0][i] = FL(0.0); - else if (p->nchannels == 2) { - p->aout[0][i] = FL(0.0); - p->aout[1][i] = FL(0.0); - } - } - } - return OK; -} - - - -#define S(x) sizeof(x) - -static OENTRY oggplay_localops[] = { - { "oggplay", S(OGGPLAY), 5, "mm", "To", - (SUBR) oggplay_init, (SUBR) NULL, (SUBR) oggplay_perf } -}; - -LINKAGE1(oggplay_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/oscbnk.c csound-6.02~dfsg/Opcodes/oscbnk.c --- csound-5.17.11~dfsg/Opcodes/oscbnk.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/oscbnk.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include "oscbnk.h" #include @@ -275,7 +275,7 @@ static int oscbnkset(CSOUND *csound, OSCBNK *p) { - int32 i; + uint32_t i; FUNC *ftp; MYFLT x; @@ -314,7 +314,8 @@ if (p->ilfomode & 0x0F) { ftp = csound->FTFind(csound, p->args[21]); /* LFO 2 */ - if (UNLIKELY((ftp == NULL) || ((p->l2t = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->l2t = ftp->ftable) == NULL))) + return NOTOK; oscbnk_flen_setup(ftp->flen, &(p->l2t_mask), &(p->l2t_lobits), &(p->l2t_pfrac)); } @@ -325,15 +326,18 @@ if (p->ieqmode >= 0) { ftp = csound->FTFind(csound, p->args[22]); /* EQ frequency */ - if (UNLIKELY((ftp == NULL) || ((p->eqft = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->eqft = ftp->ftable) == NULL))) + return NOTOK; p->eqft_len = ftp->flen; ftp = csound->FTFind(csound, p->args[23]); /* EQ level */ - if (UNLIKELY((ftp == NULL) || ((p->eqlt = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->eqlt = ftp->ftable) == NULL))) + return NOTOK; p->eqlt_len = ftp->flen; ftp = csound->FTFind(csound, p->args[24]); /* EQ Q */ - if (UNLIKELY((ftp == NULL) || ((p->eqqt = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->eqqt = ftp->ftable) == NULL))) + return NOTOK; p->eqqt_len = ftp->flen; } else { @@ -343,7 +347,8 @@ if (*(p->args[25]) >= FL(1.0)) { /* parameter table */ ftp = csound->FTFind(csound, p->args[25]); - if (UNLIKELY((ftp == NULL) || ((p->tabl = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->tabl = ftp->ftable) == NULL))) + return NOTOK; p->tabl_len = ftp->flen; } else { @@ -353,7 +358,8 @@ if (*(p->args[26]) >= FL(1.0)) { /* output table */ ftp = csound->FTFind(csound, p->args[26]); - if (UNLIKELY((ftp == NULL) || ((p->outft = ftp->ftable) == NULL))) return NOTOK; + if (UNLIKELY((ftp == NULL) || ((p->outft = ftp->ftable) == NULL))) + return NOTOK; p->outft_len = ftp->flen; } else { @@ -363,7 +369,7 @@ /* allocate space */ if (p->nr_osc < 1) return OK; - i = (int32) p->nr_osc * (int32) sizeof (OSCBNK_OSC); + i = (uint32_t) p->nr_osc * (int32) sizeof (OSCBNK_OSC); if ((p->auxdata.auxp == NULL) || (p->auxdata.size < i)) csound->AuxAlloc(csound, i, &(p->auxdata)); p->osc = (OSCBNK_OSC *) p->auxdata.auxp; @@ -374,7 +380,7 @@ /* initialise oscillators */ - for (i = 0; i < p->nr_osc; i++) { + for (i = 0; i < (uint32_t)p->nr_osc; i++) { /* oscillator phase */ x = oscbnk_rand(p); p->osc[i].osc_phs = OSCBNK_PHS2INT(x); /* LFO1 phase */ @@ -399,7 +405,7 @@ static int oscbnk(CSOUND *csound, OSCBNK *p) { - int nn, osc_cnt, pm_enabled, am_enabled; + int osc_cnt, pm_enabled, am_enabled; FUNC *ftp; MYFLT *ft; uint32 n, lobits, mask, ph, f_i; @@ -407,10 +413,12 @@ MYFLT k, a_d = FL(0.0), a1_d, a2_d, b0_d, b1_d, b2_d; MYFLT yn, xnm1, xnm2, ynm1, ynm2; OSCBNK_OSC *o; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* clear output signal */ - for (nn = 0; nn < nsmps; nn++) p->args[0][nn] = FL(0.0); + memset(p->args[0], '\0', nsmps*sizeof(MYFLT)); if (p->nr_osc == -1) { return OK; /* nothing to render */ @@ -428,10 +436,10 @@ pm_enabled = (p->ilfomode & 0x22 ? 1 : 0); am_enabled = (p->ilfomode & 0x44 ? 1 : 0); p->frq_scl = csound->onedsr; /* osc. freq. */ - p->lf1_scl = (*(p->args[8]) - *(p->args[7])) * csound->onedkr; - p->lf1_ofs = *(p->args[7]) * csound->onedkr; /* LFO1 freq. */ - p->lf2_scl = (*(p->args[10]) - *(p->args[9])) * csound->onedkr; - p->lf2_ofs = *(p->args[9]) * csound->onedkr; /* LFO2 freq. */ + p->lf1_scl = (*(p->args[8]) - *(p->args[7])) * CS_ONEDKR; + p->lf1_ofs = *(p->args[7]) * CS_ONEDKR; /* LFO1 freq. */ + p->lf2_scl = (*(p->args[10]) - *(p->args[9])) * CS_ONEDKR; + p->lf2_ofs = *(p->args[9]) * CS_ONEDKR; /* LFO2 freq. */ if (p->ieqmode >= 0) { p->eqo_scl = (*(p->args[13]) - *(p->args[12])) * csound->tpidsr; p->eqo_ofs = *(p->args[12]) * csound->tpidsr; /* EQ omega */ @@ -439,6 +447,7 @@ p->eqq_scl = *(p->args[17]) - (p->eqq_ofs= *(p->args[16]));/* EQ Q */ } + if (UNLIKELY(early)) nsmps -= early; for (osc_cnt = 0, o = p->osc; osc_cnt < p->nr_osc; osc_cnt++, o++) { if (p->init_k) oscbnk_lfo(p, o); ph = o->osc_phs; /* phase */ @@ -454,13 +463,13 @@ /* initialise ramps */ f = ((o->osc_frq + f) * FL(0.5) + *(p->args[1])) * p->frq_scl; if (pm_enabled) { - f += (MYFLT) ((double) o->osc_phm - (double) pm) * csound->onedksmps; + f += (MYFLT) ((double) o->osc_phm - (double) pm) / (nsmps-offset); f -= (MYFLT) ((int32) f); } f_i = OSCBNK_PHS2INT(f); - if (am_enabled) a_d = (o->osc_amp - a) * csound->onedksmps; + if (am_enabled) a_d = (o->osc_amp - a) / (nsmps-offset); /* oscillator */ - for (nn = 0; nn < nsmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { /* read from table */ n = ph >> lobits; k = ft[n++]; k += (ft[n] - k) * (MYFLT) ((int32) (ph & mask)) * pfrac; @@ -481,19 +490,19 @@ /* initialise ramps */ f = ((o->osc_frq + f) * FL(0.5) + *(p->args[1])) * p->frq_scl; if (pm_enabled) { - f += (MYFLT) ((double) o->osc_phm - (double) pm) * csound->onedksmps; + f += (MYFLT) ((double) o->osc_phm - (double) pm) / (nsmps-offset); f -= (MYFLT) ((int32) f); } f_i = OSCBNK_PHS2INT(f); - if (am_enabled) a_d = (o->osc_amp - a) * csound->onedksmps; + if (am_enabled) a_d = (o->osc_amp - a) / (nsmps-offset); if (p->eq_interp) { /* EQ w/ interpolation */ - a1_d = (o->a1 - a1) * csound->onedksmps; - a2_d = (o->a2 - a2) * csound->onedksmps; - b0_d = (o->b0 - b0) * csound->onedksmps; - b1_d = (o->b1 - b1) * csound->onedksmps; - b2_d = (o->b2 - b2) * csound->onedksmps; + a1_d = (o->a1 - a1) / (nsmps-offset); + a2_d = (o->a2 - a2) / (nsmps-offset); + b0_d = (o->b0 - b0) / (nsmps-offset); + b1_d = (o->b1 - b1) / (nsmps-offset); + b2_d = (o->b2 - b2) / (nsmps-offset); /* oscillator */ - for (nn = 0; nn < nsmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { /* update ramps */ a1 += a1_d; a2 += a2_d; b0 += b0_d; b1 += b1_d; b2 += b2_d; @@ -516,7 +525,7 @@ } else { /* EQ w/o interpolation */ /* oscillator */ - for (nn = 0; nn < nsmps; nn++) { + for (nn = offset; nn < nsmps; nn++) { /* read from table */ n = ph >> lobits; k = ft[n++]; k += (ft[n] - k) * (MYFLT) ((int32) (ph & mask)) * pfrac; @@ -541,7 +550,8 @@ p->init_k = 0; return OK; err1: - return csound->PerfError(csound, Str("oscbnk: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("oscbnk: not initialised")); } /* ---------------- grain2 set-up ---------------- */ @@ -550,7 +560,7 @@ { int i; FUNC *ftp; - int32 n; + uint32_t n; double x, y; /* check opcode params */ @@ -581,7 +591,7 @@ /* allocate space */ if (p->nr_osc == -1) return OK; /* no oscillators */ - n = (int32) p->nr_osc * (int32) sizeof(GRAIN2_OSC); + n = (uint32_t) p->nr_osc * (int32) sizeof(GRAIN2_OSC); if ((p->auxdata.auxp == NULL) || (p->auxdata.size < n)) csound->AuxAlloc(csound, n, &(p->auxdata)); p->osc = (GRAIN2_OSC *) p->auxdata.auxp; @@ -648,7 +658,10 @@ static int grain2(CSOUND *csound, GRAIN2 *p) { - int i, nn = csound->ksmps, w_interp, g_interp, f_nolock; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int i, w_interp, g_interp, f_nolock; MYFLT *aout, *ft, *w_ft, grain_frq, frq_scl, pfrac, w_pfrac, f, a, k; uint32 n, mask, lobits, w_mask, w_lobits; uint32 g_frq, w_frq; @@ -666,8 +679,8 @@ w_mask = p->wft_mask; w_lobits = p->wft_lobits; w_pfrac = p->wft_pfrac; /* clear output signal */ - memset(aout, 0, nn*sizeof(MYFLT)); - /* for (nn = 0; nn < csound->ksmps; nn++) aout[nn] = FL(0.0); */ + memset(aout, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (p->nr_osc == -1) { return OK; /* nothing to render */ @@ -704,7 +717,7 @@ } } aout = p->ar; /* audio output */ - do { + for (nn = offset; nnnr_osc; do { /* grain waveform */ @@ -720,7 +733,7 @@ * w_pfrac; o->window_phs += w_frq; /* mix to output */ - *aout += a * k; + aout[nn] += a * k; if (o->window_phs >= OSCBNK_PHSMAX) { o->window_phs &= OSCBNK_PHSMSK; /* new grain */ grain2_init_grain(p, o); @@ -733,11 +746,11 @@ o++; /* next grain */ } while (--i); o -= p->nr_osc; - aout++; - } while (--nn); + } return OK; err1: - return csound->PerfError(csound, Str("grain2: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain2: not initialised")); } /* ---------------- grain3 set-up ---------------- */ @@ -746,7 +759,7 @@ { int i; FUNC *ftp; - int32 n; + uint32_t n; /* check opcode params */ @@ -768,12 +781,12 @@ /* allocate space */ - n = ((int32) csound->ksmps + 1L) * (int32) sizeof(uint32); - n += (int32) p->ovrlap * (int32) sizeof(GRAIN2_OSC); + n = ((uint32_t) CS_KSMPS + 1L) * (int32) sizeof(uint32); + n += (uint32_t) p->ovrlap * (int32) sizeof(GRAIN2_OSC); if ((p->auxdata.auxp == NULL) || (p->auxdata.size < n)) csound->AuxAlloc(csound, n, &(p->auxdata)); p->phase = (uint32 *) p->auxdata.auxp; - p->osc = (GRAIN2_OSC *) ((uint32 *) p->phase + csound->ksmps + 1); + p->osc = (GRAIN2_OSC *) ((uint32 *) p->phase + CS_KSMPS + 1); p->osc_start = p->osc; p->osc_end = p->osc; p->osc_max = p->osc + (p->ovrlap - 1); @@ -812,18 +825,20 @@ static int grain3(CSOUND *csound, GRAIN3 *p) { - int i, nn, w_interp, g_interp, f_nolock; - MYFLT *aout0, *aout, *ft, *w_ft, frq_scl, pfrac, w_pfrac, f, a, k; + int i, w_interp, g_interp, f_nolock; + MYFLT *aout0, *ft, *w_ft, frq_scl, pfrac, w_pfrac, f, a, k; MYFLT wfdivxf, w_frq_f, x_frq_f; uint32 n, mask, lobits, w_mask, w_lobits; uint32 *phs, frq, x_ph, x_frq, g_ph, g_frq, w_ph, w_frq; GRAIN2_OSC *o; FUNC *ftp; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* clear output */ memset(p->ar, 0, nsmps*sizeof(MYFLT)); - /* for (nn = 0; nn < csound->ksmps; nn++) p->ar[nn] = FL(0.0); */ + if (UNLIKELY(early)) nsmps -= early; if (UNLIKELY((p->seed == 0L) || (p->osc == NULL))) goto err1; @@ -874,26 +889,28 @@ } p->phs0 = *(p->kphs); /* convert phase modulation to frequency modulation */ - f = (MYFLT) ((double) p->phs0 - (double) f) * csound->onedksmps; + f = (MYFLT) ((double) p->phs0 - (double) f) / (nsmps-offset); f -= (MYFLT) ((int32) f); g_frq = OSCBNK_PHS2INT(f); f = *(p->kcps) * csound->onedsr; /* grain frequency */ frq = (g_frq + OSCBNK_PHS2INT(f)) & OSCBNK_PHSMSK; if (p->mode & 0x40) g_frq = frq; /* phase sync */ /* calculate phase offset values for this k-cycle */ - for (nn = 0; nn <= nsmps; nn++) { + for (nn = offset; nn <= nsmps; nn++) { phs[nn] = g_ph; g_ph = (g_ph + g_frq) & OSCBNK_PHSMSK; } w_frq_f = csound->onedsr / *(p->kgdur); /* window frequency */ if (UNLIKELY((w_frq_f < (FL(1.0) / (MYFLT) OSCBNK_PHSMAX)) || (w_frq_f >= FL(1.0)))) { - return csound->PerfError(csound, Str("grain3: invalid grain duration")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain3: invalid grain duration")); } w_frq = OSCBNK_PHS2INT(w_frq_f); x_frq_f = csound->onedsr * *(p->kdens); /* density */ if (UNLIKELY((x_frq_f < (FL(1.0) / (MYFLT) OSCBNK_PHSMAX)) || (x_frq_f >= FL(1.0)))) { - return csound->PerfError(csound, Str("grain3: invalid grain density")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain3: invalid grain density")); } x_frq = OSCBNK_PHS2INT(x_frq_f); wfdivxf = w_frq_f / ((MYFLT) OSCBNK_PHSMAX * x_frq_f); @@ -922,8 +939,8 @@ } p->init_k = 0; - nn = nsmps; o = p->osc_start; - while (nn) { + o = p->osc_start; + for (nn=offset; nn= OSCBNK_PHSMAX) { /* check for new grain */ x_ph &= OSCBNK_PHSMSK; if (!(p->mode & 0x20)) { @@ -939,7 +956,7 @@ } if (o == p->osc_end) { /* no active grains */ - x_ph += x_frq; nn--; aout0++; phs++; continue; + x_ph += x_frq; phs++; continue; } g_ph = o->grain_phs; /* grain phase */ @@ -955,7 +972,7 @@ w_ph = o->window_phs; /* window phase */ /* render grain */ - aout = aout0; i = nn; + i = nsmps-nn; while (i--) { /* window waveform */ n = w_ph >> w_lobits; a = w_ft[n++]; @@ -966,7 +983,7 @@ if (g_interp) k += (ft[n] - k) * pfrac * (MYFLT) ((int32) (g_ph & mask)); /* mix to output */ - *(aout++) += a * k; + aout0[nn] += a * k; /* update phase */ g_ph = (g_ph + g_frq) & OSCBNK_PHSMSK; /* check for end of grain */ @@ -984,9 +1001,11 @@ p->x_phs = x_ph; return OK; err1: - return csound->PerfError(csound, Str("grain3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain3: not initialised")); err2: - return csound->PerfError(csound, Str("grain3 needs more overlaps")); + return csound->PerfError(csound, p->h.insdshead, + Str("grain3 needs more overlaps")); } /* ----------------------------- rnd31 opcode ------------------------------ */ @@ -1058,7 +1077,8 @@ *(p->out) = *(p->scl) * oscbnk_rnd_bipolar(&(p->seed), rpow, rmode); return OK; err1: - return csound->PerfError(csound, Str("rnd31: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("rnd31: not initialised")); } /* ---- rnd31 / a-rate ---- */ @@ -1066,21 +1086,28 @@ static int rnd31a(CSOUND *csound, RND31 *p) { MYFLT scl, *out, rpow; - int rmode, nn; + int rmode; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; if (UNLIKELY(!p->seed)) goto err1; - nn = csound->ksmps; scl = *(p->scl); out = p->out; /* random distribution */ rpow = *(p->rpow); + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if ((rpow == FL(0.0)) || (rpow == FL(-1.0)) || (rpow == FL(1.0))) { /* IV - Jan 30 2003: optimised code for uniform distribution */ scl *= (MYFLT) (1.0 / 1073741823.015625); - do { + for (nn=offset; nnseed = oscbnk_rand31(p->seed); - *(out++) = scl * (MYFLT) (p->seed - 0x3FFFFFFFL); - } while (--nn); + out[nn] = scl * (MYFLT) (p->seed - 0x3FFFFFFFL); + } return OK; } else if (rpow < FL(0.0)) { @@ -1090,12 +1117,13 @@ rmode = 1; } - do { - *(out++) = scl * oscbnk_rnd_bipolar(&(p->seed), rpow, rmode); - } while (--nn); + for (nn=offset; nnseed), rpow, rmode); + } return OK; err1: - return csound->PerfError(csound, Str("rnd31: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("rnd31: not initialised")); } /* ---- oscilikt initialisation ---- */ @@ -1134,9 +1162,9 @@ ft = p->ft; phs = p->phs; /* read from table with interpolation */ n = phs >> p->lobits; v = (MYFLT) ((int32) (phs & p->mask)) * p->pfrac; - *(p->sr) = (p->ft[n] + (p->ft[n + 1] - p->ft[n]) * v) * *(p->xamp); + *(p->sr) = (ft[n] + (ft[n + 1] - ft[n]) * v) * *(p->xamp); /* update phase */ - v = *(p->xcps) * csound->onedkr; + v = *(p->xcps) * CS_ONEDKR; p->phs = (phs + OSCBNK_PHS2INT(v)) & OSCBNK_PHSMSK; return OK; } @@ -1146,7 +1174,9 @@ FUNC *ftp; uint32 n, phs, lobits, mask, frq; MYFLT pfrac, *ft, v, a, *ar; - int nn; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1161,13 +1191,17 @@ lobits = p->lobits; mask = p->mask; pfrac = p->pfrac; /* read from table with interpolation */ v = *(p->xcps) * csound->onedsr; frq = OSCBNK_PHS2INT(v); - nn = csound->ksmps; - do { + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (nn=offset; nn> lobits; v = ft[n++]; v += (ft[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; phs = (phs + frq) & OSCBNK_PHSMSK; - *(ar++) = v * a; - } while (--nn); + ar[nn] = v * a; + } /* save new phase */ p->phs = phs; return OK; @@ -1178,7 +1212,9 @@ FUNC *ftp; uint32 n, phs, lobits, mask; MYFLT pfrac, *ft, v, a, *ar, *xcps; - int nn, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps=CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1192,7 +1228,12 @@ ft = p->ft; phs = p->phs; a = *(p->xamp); ar = p->sr; xcps = p->xcps; lobits = p->lobits; mask = p->mask; pfrac = p->pfrac; /* read from table with interpolation */ - for (nn=0; nn> lobits; v = ft[n++]; v += (ft[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; ar[nn] = v * a; @@ -1223,7 +1264,9 @@ FUNC *ftp; uint32 n, phs, lobits, mask, frq; MYFLT pfrac, *ft, v, *ar, *xamp; - int nn, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1238,7 +1281,12 @@ lobits = p->lobits; mask = p->mask; pfrac = p->pfrac; /* read from table with interpolation */ v = *(p->xcps) * csound->onedsr; frq = OSCBNK_PHS2INT(v); - for (nn=0; nn> lobits; v = ft[n++]; v += (ft[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; phs = (phs + frq) & OSCBNK_PHSMSK; @@ -1254,7 +1302,9 @@ FUNC *ftp; uint32 n, phs, lobits, mask; MYFLT pfrac, *ft, v, *ar, *xcps, *xamp; - int nn, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1268,7 +1318,12 @@ ft = p->ft; phs = p->phs; ar = p->sr; xcps = p->xcps; xamp = p->xamp; lobits = p->lobits; mask = p->mask; pfrac = p->pfrac; /* read from table with interpolation */ - for (nn=0; nn> lobits; v = ft[n++]; v += (ft[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; ar[nn] = v * xamp[nn]; @@ -1299,9 +1354,11 @@ static int oscktp(CSOUND *csound, OSCKTP *p) { FUNC *ftp; - uint32 n, phs, lobits, mask, frq; + uint32_t n, phs, lobits, mask, frq; MYFLT pfrac, *ft, v, *ar; - int nn, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1324,11 +1381,16 @@ phs = OSCBNK_PHS2INT(v); } /* convert phase modulation to frequency modulation */ - v = (MYFLT) ((double) *(p->kphs) - (double) p->old_phs) * csound->onedksmps; p->old_phs = *(p->kphs); frq = (frq + OSCBNK_PHS2INT(v)) & OSCBNK_PHSMSK; /* read from table with interpolation */ - for (nn=0; nnkphs) - (double) p->old_phs) / (nsmps-offset); + for (nn=offset; nn> lobits; v = ft[n++]; v += (ft[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; phs = (phs + frq) & OSCBNK_PHSMSK; @@ -1358,9 +1420,12 @@ static int osckts(CSOUND *csound, OSCKTS *p) { FUNC *ftp; - uint32 n, phs, lobits, mask, frq = 0UL; + uint32_t n, phs, lobits, mask, frq = 0UL; MYFLT pfrac, *ft, v, *ar, *xcps, *xamp, *async; - int nn, nsmps = csound->ksmps, a_amp, a_cps; + int a_amp, a_cps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; /* check if table number was changed */ if (*(p->kfn) != p->oldfn || p->ft == NULL) { @@ -1386,7 +1451,12 @@ phs = OSCBNK_PHS2INT(v); } /* read from table with interpolation */ - for (nn=0; nn FL(0.0)) { /* re-initialise phase */ v = *(p->kphs) - (MYFLT) ((int32) *(p->kphs)); phs = OSCBNK_PHS2INT(v); @@ -1660,7 +1730,7 @@ /* if base ftable was specified, generate empty table ... */ if (base_ftable > 0) { csound->FTAlloc(csound, base_ftable, (int) tables->tables[i].size); - csound->GetTable(csound, &(tables->tables[i].ftable), base_ftable); + csoundGetTable(csound, &(tables->tables[i].ftable), base_ftable); base_ftable++; /* next table number */ } else /* ... else allocate memory (cannot be accessed as a */ @@ -1691,7 +1761,7 @@ int waveforms, base_ftable, ftnum, i, w; VCO2_TABLE_PARAMS tp; FUNC *ftp; - + uint32_t j; /* check waveform number */ waveforms = (int) MYFLT2LRND(*(p->iwaveforms)); if (UNLIKELY(waveforms < -1000000 || waveforms > 31)) { @@ -1760,8 +1830,8 @@ i = ftp->flen; tp.w_npart = i >> 1; tp.w_fftbuf = (MYFLT*) csound->Malloc(csound, sizeof(MYFLT) * (i + 2)); - for (i = 0; i < ftp->flen; i++) - tp.w_fftbuf[i] = ftp->ftable[i] / (MYFLT) (ftp->flen >> 1); + for (j = 0; j < ftp->flen; j++) + tp.w_fftbuf[j] = ftp->ftable[j] / (MYFLT) (ftp->flen >> 1); csound->RealFFT(csound, tp.w_fftbuf, (int) ftp->flen); tp.w_fftbuf[ftp->flen] = tp.w_fftbuf[1]; tp.w_fftbuf[1] = tp.w_fftbuf[(int) ftp->flen + 1] = FL(0.0); @@ -1811,11 +1881,11 @@ #endif p->base_ftnum = (*(p->vco2_tables))[w]->base_ftnum; if (*(p->inyx) > FL(0.5)) - p->p_scl = FL(0.5) * csound->esr; + p->p_scl = FL(0.5) * CS_ESR; else if (*(p->inyx) < FL(0.001)) - p->p_scl = FL(0.001) * csound->esr; + p->p_scl = FL(0.001) * CS_ESR; else - p->p_scl = *(p->inyx) * csound->esr; + p->p_scl = *(p->inyx) * CS_ESR; p->p_min = p->p_scl / (MYFLT) VCO2_MAX_NPART; /* in case of vco2ift opcode, find table number now */ if (!strcmp(p->h.optext->t.opcod, "vco2ift")) @@ -1868,17 +1938,19 @@ static int vco2ft(CSOUND *csound, VCO2FT *p) { - return csound->PerfError(csound, Str("vco2ft: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vco2ft: not initialised")); } /* ---- vco2 opcode (initialisation) ---- */ static int vco2set(CSOUND *csound, VCO2 *p) { - int mode, min_args, tnum; + int mode, tnum; int tnums[8] = { 0, 0, 1, 2, 1, 3, 4, 5 }; int modes[8] = { 0, 1, 2, 0, 0, 0, 0, 0 }; MYFLT x; + uint32_t min_args; if (p->vco2_nr_table_arrays == NULL || p->vco2_tables == NULL) { STDOPCOD_GLOBALS *pp = get_oscbnk_globals(csound); @@ -1946,7 +2018,10 @@ static int vco2(CSOUND *csound, VCO2 *p) { - int nn, n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int n; VCO2_TABLE *tabl; uint32 phs, phs2, frq, frq2, lobits, mask; #ifdef VCO2FT_USE_TABLE @@ -1956,7 +2031,8 @@ MYFLT f, f1, npart, *nparts, pfrac, v, *ftable, kamp, *ar; if (UNLIKELY(p->tables == NULL)) { #endif - return csound->PerfError(csound, Str("vco2: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vco2: not initialised")); } /* if 1st k-cycle, initialise now */ if (p->init_k) { @@ -1971,12 +2047,18 @@ p->phs2 = (p->phs + OSCBNK_PHS2INT(f)) & OSCBNK_PHSMSK; } } + ar = p->ar; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } /* calculate frequency (including phase modulation) */ f = *(p->kcps) * p->f_scl; frq = OSCBNK_PHS2INT(f); if (p->pm_enabled) { f1 = (MYFLT) ((double) *(p->kphs) - (double) p->kphs_old) - * csound->onedksmps; + / (nsmps-offset); p->kphs_old = *(p->kphs); frq = (frq + OSCBNK_PHS2INT(f1)) & OSCBNK_PHSMSK; f += f1; @@ -2008,25 +2090,23 @@ tabl = p->tables + (int) (nparts - p->nparts); #endif /* copy object data to local variables */ - ar = p->ar; kamp = *(p->kamp); phs = p->phs; lobits = tabl->lobits; mask = tabl->mask; pfrac = tabl->pfrac; ftable = tabl->ftable; - nn = csound->ksmps; if (!p->mode) { /* - mode 0: simple table playback - */ - do { + for (nn=offset; nn> lobits; v = ftable[n++]; v += (ftable[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; phs = (phs + frq) & OSCBNK_PHSMSK; - *(ar++) = v * kamp; - } while (--nn); + ar[nn] = v * kamp; + } } else { v = -(*(p->kpw)); /* pulse width */ - f1 = (MYFLT) ((double) v - (double) p->kphs2_old) * csound->onedksmps; + f1 = (MYFLT) ((double) v - (double) p->kphs2_old) / (nsmps-offset); f = p->kphs2_old; f -= (MYFLT) ((int32) f); if (f < FL(0.0)) f++; p->kphs2_old = v; phs2 = p->phs2; @@ -2035,34 +2115,32 @@ /* DC correction offset */ f = FL(1.0) - FL(2.0) * f; f1 *= FL(-2.0); - do { + for (nn=offset; nn> lobits; v = ftable[n++]; - *ar = v + (ftable[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; + ar[nn] = v + (ftable[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; n = phs2 >> lobits; v = ftable[n++]; v += (ftable[n] - v) * (MYFLT) ((int32) (phs2 & mask)) * pfrac; - *ar = (*ar - v + f) * kamp; - ar++; + ar[nn] = (ar[nn] - v + f) * kamp; phs = (phs + frq) & OSCBNK_PHSMSK; phs2 = (phs2 + frq2) & OSCBNK_PHSMSK; f += f1; - } while (--nn); + } } else { /* - mode 2: saw / triangle ramp - */ - do { + for (nn=offset; nn> lobits; v = ftable[n++]; - *ar = v + (ftable[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; + ar[nn] = v + (ftable[n] - v) * (MYFLT) ((int32) (phs & mask)) * pfrac; n = phs2 >> lobits; v = ftable[n++]; v += (ftable[n] - v) * (MYFLT) ((int32) (phs2 & mask)) * pfrac; - *ar = (*ar - v) * (FL(0.25) / (f - f * f)) * kamp; - ar++; + ar[nn] = (ar[nn] - v) * (FL(0.25) / (f - f * f)) * kamp; phs = (phs + frq) & OSCBNK_PHSMSK; phs2 = (phs2 + frq2) & OSCBNK_PHSMSK; f += f1; - } while (--nn); + } } p->phs2 = phs2; } @@ -2084,20 +2162,25 @@ static int denorms(CSOUND *csound, DENORMS *p) { MYFLT r, *ar, **args = p->ar; - int n = p->INOCOUNT, nn, *seed; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn, nsmps = CS_KSMPS; + int n = p->INOCOUNT, *seed; seed = p->seedptr; if (seed == NULL) { STDOPCOD_GLOBALS *pp = get_oscbnk_globals(csound); seed = p->seedptr = &(pp->denorm_seed); } + if (UNLIKELY(early)) nsmps -= early; do { r = DENORM_RND; ar = *args++; - nn = csound->ksmps; - do { - *ar++ += r; - } while (--nn); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + for (nn=offset; nnmode = mode; /* calculate delay time */ - npts = (int) (*p->idel * csound->ekr + FL(1.5)); + npts = (int) (*p->idel * CS_EKR + FL(1.5)); if (UNLIKELY(npts < 1)) return csound->InitError(csound, Str("delayk: invalid delay time " "(must be >= 0)")); p->readp = 0; p->npts = npts; /* allocate space for delay buffer */ if (p->aux.auxp == NULL || - (npts * (int) sizeof(MYFLT)) > p->aux.size) { + (unsigned int)(npts * sizeof(MYFLT)) > p->aux.size) { csound->AuxAlloc(csound, (int32) (npts * sizeof(MYFLT)), &p->aux); } p->init_k = npts - 1; @@ -2130,7 +2213,8 @@ MYFLT *buf = (MYFLT*) p->aux.auxp; if (UNLIKELY(!buf)) - return csound->PerfError(csound, Str("delayk: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("delayk: not initialised")); buf[p->readp++] = *(p->ksig); /* write input signal to buffer */ if (p->readp >= p->npts) p->readp = 0; /* wrap index */ @@ -2151,14 +2235,14 @@ return OK; /* skip initialisation */ p->mode = mode; /* calculate max. delay time */ - npts = (int) (*p->imdel * csound->ekr + FL(1.5)); + npts = (int) (*p->imdel * CS_EKR + FL(1.5)); if (UNLIKELY(npts < 1)) return csound->InitError(csound, Str("vdel_k: invalid max delay time " "(must be >= 0)")); p->wrtp = 0; p->npts = npts; /* allocate space for delay buffer */ if (p->aux.auxp == NULL || - (npts * (int) sizeof(MYFLT)) > p->aux.size) { + (unsigned int)(npts * sizeof(MYFLT)) > p->aux.size) { csound->AuxAlloc(csound, (int32) (npts * sizeof(MYFLT)), &p->aux); } p->init_k = npts; /* not -1 this time ! */ @@ -2171,11 +2255,14 @@ int n, npts = p->npts; if (UNLIKELY(!buf)) - return csound->PerfError(csound, Str("vdel_k: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vdel_k: not initialised")); buf[p->wrtp] = *(p->ksig); /* write input signal to buffer */ - n = (int) MYFLT2LONG(*(p->kdel) * csound->ekr); /* calculate delay time */ + /* calculate delay time */ + n = (int) MYFLT2LONG(*(p->kdel) * CS_EKR); if (UNLIKELY(n < 0)) - return csound->PerfError(csound, Str("vdel_k: invalid delay time " + return csound->PerfError(csound, p->h.insdshead, + Str("vdel_k: invalid delay time " "(must be >= 0)")); n = p->wrtp - n; if (++p->wrtp >= npts) p->wrtp = 0; /* wrap index */ @@ -2241,7 +2328,10 @@ static int rbjeq(CSOUND *csound, RBJEQ *p) { - int nn, new_frq; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int new_frq; MYFLT b0, b1, b2, a1, a2, tmp; MYFLT xnm1, xnm2, ynm1, ynm2; MYFLT *ar, *asig; @@ -2252,7 +2342,7 @@ new_frq = 1; p->old_kcps = *(p->kcps); /* calculate variables that depend on freq., and are used by all modes */ - p->omega = (double) p->old_kcps * TWOPI / (double) csound->esr; + p->omega = (double) p->old_kcps * TWOPI / (double) CS_ESR; p->cs = cos(p->omega); p->sn = sqrt(1.0 - p->cs * p->cs); } @@ -2261,7 +2351,11 @@ /* copy object data to local variables */ ar = p->ar; asig = p->asig; xnm1 = p->xnm1; xnm2 = p->xnm2; ynm1 = p->ynm1; ynm2 = p->ynm2; - nn = (int) csound->ksmps; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } switch (p->ftype) { case 0: /* lowpass filter */ if (new_frq || *(p->kQ) != p->old_kQ) { @@ -2279,12 +2373,12 @@ p->a2 = (MYFLT) (dva0 - dva0 * alpha); } b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b2 * (tmp + xnm1 + xnm1 + xnm2) - a1 * ynm1 - a2 * ynm2; + for (n=offset; nkQ) != p->old_kQ) { @@ -2302,12 +2396,12 @@ p->a2 = (MYFLT) (dva0 - dva0 * alpha); } b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b2 * (tmp - xnm1 - xnm1 + xnm2) - a1 * ynm1 - a2 * ynm2; + for (n=offset; nkQ) != p->old_kQ) { @@ -2325,12 +2419,12 @@ p->a2 = (MYFLT) (dva0 - dva0 * alpha); } b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b2 * (tmp - xnm2) - a1 * ynm1 - a2 * ynm2; + for (n=offset; nkQ) != p->old_kQ) { @@ -2348,12 +2442,12 @@ p->a2 = (MYFLT) (dva0 - dva0 * alpha); } b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b2 * (tmp + xnm2) - a1 * (ynm1 - xnm1) - a2 * ynm2; + for (n=offset; nkQ) != p->old_kQ || *(p->klvl) != p->old_klvl) { @@ -2375,12 +2469,12 @@ p->a2 = (MYFLT) (dva0 - dva0 * tmp1); } b0 = p->b0; b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b0 * tmp + b2 * xnm2 - a1 * (ynm1 - xnm1) - a2 * ynm2; + for (n=offset; nklvl) != p->old_klvl || *(p->kS) != p->old_kS) { @@ -2403,12 +2497,12 @@ p->b2 = (MYFLT) (dva0 * (tmp1 - tmp4 - beta)); } b0 = p->b0; b1 = p->b1; b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b0 * tmp + b1 * xnm1 + b2 * xnm2 - a1 * ynm1 - a2 * ynm2; + for (n=offset; nklvl) != p->old_klvl || *(p->kS) != p->old_kS) { @@ -2431,15 +2525,16 @@ p->b2 = (MYFLT) (dva0 * (tmp1 + tmp4 - beta)); } b0 = p->b0; b1 = p->b1; b2 = p->b2; a1 = p->a1; a2 = p->a2; - do { - tmp = *asig++; - *ar = b0 * tmp + b1 * xnm1 + b2 * xnm2 - a1 * ynm1 - a2 * ynm2; + for (n=offset; nPerfError(csound, Str("rbjeq: invalid filter type")); + return csound->PerfError(csound, p->h.insdshead, + Str("rbjeq: invalid filter type")); break; } /* save filter state */ @@ -2450,49 +2545,50 @@ /* ------------------------------------------------------------------------- */ static const OENTRY localops[] = { - { "oscbnk", sizeof(OSCBNK), TR|5, "a", "kkkkiikkkkikkkkkkikooooooo", + { "oscbnk", sizeof(OSCBNK), TR, 5, "a", "kkkkiikkkkikkkkkkikooooooo", (SUBR) oscbnkset, (SUBR) NULL, (SUBR) oscbnk }, - { "grain2", sizeof(GRAIN2), TR|5, "a", "kkkikiooo", + { "grain2", sizeof(GRAIN2), TR, 5, "a", "kkkikiooo", (SUBR) grain2set, (SUBR) NULL, (SUBR) grain2 }, - { "grain3", sizeof(GRAIN3), TR|5, "a", "kkkkkkikikkoo", + { "grain3", sizeof(GRAIN3), TR, 5, "a", "kkkkkkikikkoo", (SUBR) grain3set, (SUBR) NULL, (SUBR) grain3 }, - { "rnd31", 0xFFFF, 0, NULL, NULL, + { "rnd31", 0xFFFF, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, - { "rnd31.i", sizeof(RND31), 1, "i", "iio", + { "rnd31.i", sizeof(RND31), 0, 1, "i", "iio", (SUBR) rnd31i, (SUBR) NULL, (SUBR) NULL }, - { "rnd31.k", sizeof(RND31), 3, "k", "kko", + { "rnd31.k", sizeof(RND31), 0, 3, "k", "kko", (SUBR) rnd31set, (SUBR) rnd31k, (SUBR) NULL }, - { "rnd31.a", sizeof(RND31), 5, "a", "kko", + { "rnd31.a", sizeof(RND31), 0, 5, "a", "kko", (SUBR) rnd31set, (SUBR) NULL, (SUBR) rnd31a }, - { "oscilikt", 0xFFFE, TR, NULL, NULL, - (SUBR) NULL, (SUBR) NULL, (SUBR) NULL }, - { "oscilikt.kk", sizeof(OSCKT), 7, "s", "kkkoo", - (SUBR) oscktset, (SUBR) kosclikt, (SUBR)osckkikt }, - { "oscilikt.ka", sizeof(OSCKT), 5, "a", "kakoo", + { "oscilikt", 0xFFFE, TR }, + { "oscilikt.a", sizeof(OSCKT), 0, 5, "a", "kkkoo", + (SUBR) oscktset, NULL, (SUBR)osckkikt }, + { "oscilikt.kk", sizeof(OSCKT), 0, 3, "k", "kkkoo", + (SUBR) oscktset, (SUBR) kosclikt, NULL }, + { "oscilikt.ka", sizeof(OSCKT), 0, 5, "a", "kakoo", (SUBR) oscktset, (SUBR) NULL, (SUBR) osckaikt }, - { "oscilikt.ak", sizeof(OSCKT), 5, "a", "akkoo", + { "oscilikt.ak", sizeof(OSCKT), 0, 5, "a", "akkoo", (SUBR) oscktset, (SUBR) NULL, (SUBR) oscakikt }, - { "oscilikt.aa", sizeof(OSCKT), 5, "a", "aakoo", + { "oscilikt.aa", sizeof(OSCKT), 0, 5, "a", "aakoo", (SUBR) oscktset, (SUBR) NULL, (SUBR) oscaaikt }, - { "osciliktp", sizeof(OSCKTP), TR|5, "a", "kkko", + { "osciliktp", sizeof(OSCKTP), TR, 5, "a", "kkko", (SUBR) oscktpset, (SUBR) NULL, (SUBR) oscktp }, - { "oscilikts", sizeof(OSCKTS), TR|5, "a", "xxkako", + { "oscilikts", sizeof(OSCKTS), TR, 5, "a", "xxkako", (SUBR) oscktsset, (SUBR) NULL, (SUBR) osckts }, - { "vco2init", sizeof(VCO2INIT), TW|1, "i", "ijjjjj", + { "vco2init", sizeof(VCO2INIT), TW, 1, "i", "ijjjjj", (SUBR) vco2init, (SUBR) NULL, (SUBR) NULL }, - { "vco2ift", sizeof(VCO2FT), TW|1, "i", "iov", + { "vco2ift", sizeof(VCO2FT), TW, 1, "i", "iov", (SUBR) vco2ftset, (SUBR) NULL, (SUBR) NULL }, - { "vco2ft", sizeof(VCO2FT), TW|3, "k", "kov", + { "vco2ft", sizeof(VCO2FT), TW, 3, "k", "kov", (SUBR) vco2ftset, (SUBR) vco2ft, (SUBR) NULL }, - { "vco2", sizeof(VCO2), TR|5, "a", "kkoM", + { "vco2", sizeof(VCO2), TR, 5, "a", "kkoM", (SUBR) vco2set, (SUBR) NULL, (SUBR) vco2 }, - { "denorm", sizeof(DENORMS), 4, "", "y", + { "denorm", sizeof(DENORMS), 0, 4, "", "y", (SUBR) NULL, (SUBR) NULL, (SUBR) denorms }, - { "delayk", sizeof(DELAYK), 3, "k", "kio", + { "delayk", sizeof(DELAYK), 0, 3, "k", "kio", (SUBR) delaykset, (SUBR) delayk, (SUBR) NULL }, - { "vdel_k", sizeof(VDELAYK), 3, "k", "kkio", + { "vdel_k", sizeof(VDELAYK), 0, 3, "k", "kkio", (SUBR) vdelaykset, (SUBR) vdelayk, (SUBR) NULL }, - { "rbjeq", sizeof(RBJEQ), 5, "a", "akkkko", + { "rbjeq", sizeof(RBJEQ), 0, 5, "a", "akkkko", (SUBR) rbjeqset, (SUBR) NULL, (SUBR) rbjeq } }; @@ -2501,4 +2597,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/oscbnk.h csound-6.02~dfsg/Opcodes/oscbnk.h --- csound-5.17.11~dfsg/Opcodes/oscbnk.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/oscbnk.h 2014-01-07 16:53:48.000000000 +0000 @@ -56,7 +56,7 @@ MYFLT *args[27]; /* opcode args (see manual) */ int init_k; /* 1st k-cycle (0: no, 1: yes) */ int nr_osc; /* number of oscillators */ - int32 seed; /* random seed */ + int32 seed; /* random seed */ int ilfomode, ieqmode; /* LFO and EQ mode */ int eq_interp; /* enable filter coeff. interp. */ MYFLT frq_scl; /* constants for calculating */ diff -Nru csound-5.17.11~dfsg/Opcodes/p5glove.c csound-6.02~dfsg/Opcodes/p5glove.c --- csound-5.17.11~dfsg/Opcodes/p5glove.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/p5glove.c 2014-01-07 16:53:48.000000000 +0000 @@ -89,7 +89,7 @@ int p5g_deinit(CSOUND *csound, P5GLOVEINIT *p) { p->on = 0; - return pthread_cancel(p->thread); + return pthread_cancel((pthread_t)(p->thread)); } int p5glove_find(CSOUND *csound, P5GLOVEINIT *p) @@ -112,14 +112,17 @@ int p5glove_poll(CSOUND *csound, P5GLOVE *p) { - /* P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound, "p5glove"); */ + /* P5Glove *glove = (P5Glove*)csound->QueryGlobalVariable(csound,"p5glove"); */ /* int res; */ /* if (glove == NULL) */ - /* return csound->PerfError(csound, Str("No glove open")); */ + /* return csound->PerfError(csound, p->h.insdshead, */ + /* Str("No glove open")); */ /* res = p5glove_sample(*glove, -1); */ - /* if (res < 0 && errno == EAGAIN) return OK;//res = p5glove_sample(*glove, -1); */ + /* if (res < 0 && errno == EAGAIN) return OK; */ + /* //res = p5glove_sample(*glove, -1); */ /* if (UNLIKELY(res < 0)) */ - /* return csound->PerfError(csound, Str("P5Glove failure")); */ + /* return csound->PerfError(csound, p->h.insdshead, */ + /* Str("P5Glove failure")); */ return OK; } @@ -141,6 +144,7 @@ /* if (UNLIKELY(p5g==NULL)) */ /* return csound->InitError(csound, Str("No p5glove open")); */ p->last = 0; + return OK; } int p5g_data(CSOUND *csound, P5GLOVE *p) @@ -149,7 +153,7 @@ int kontrol = (int)(*p->kControl+FL(0.5)); uint32_t buttons, just, rels; if (glove==NULL) - csound->PerfError(csound, Str("No open glove")); + csound->PerfError(csound, p->h.insdshead, Str("No open glove")); p5glove_get_buttons(*glove,&buttons); just = ((!p->last) & buttons); rels = (p->last & !buttons); @@ -248,8 +252,9 @@ #define S(x) sizeof(x) static OENTRY p5g_localops[] = { - {"p5gconnect", S(P5GLOVEINIT), 3, "", "", (SUBR)p5glove_find, (SUBR)p5glove_poll, NULL, (SUBR)p5glove_closer }, - {"p5gdata", S(P5GLOVE), 3, "k", "k", (SUBR)p5g_data_init, (SUBR)p5g_data } + {"p5gconnect", S(P5GLOVEINIT), 0, 3, "", "", + (SUBR)p5glove_find, (SUBR)p5glove_poll, NULL, (SUBR)p5glove_closer }, + {"p5gdata", S(P5GLOVE), 0, 3, "k", "k", (SUBR)p5g_data_init, (SUBR)p5g_data } }; -LINKAGE1(p5g_localops) +LINKAGE_BUILTIN(p5g_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/pan2.c csound-6.02~dfsg/Opcodes/pan2.c --- csound-5.17.11~dfsg/Opcodes/pan2.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pan2.c 2014-01-07 16:54:20.000000000 +0000 @@ -41,7 +41,7 @@ static int pan2set(CSOUND *csound, PAN2 *p) { int type = p->type = MYFLT2LRND(*p->itype); - if (UNLIKELY(type <0 || type > 2)) + if (UNLIKELY(type <0 || type > 3)) return csound->InitError(csound, Str("Unknown panning type")); return OK; } @@ -51,54 +51,70 @@ int type = p->type; MYFLT *ain = p->asig; MYFLT *al = p->aleft, *ar = p->aright; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) { + memset(ar, '\0', offset*sizeof(MYFLT)); + memset(al, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + memset(&al[nsmps], '\0', early*sizeof(MYFLT)); + } switch (type) { - case 0: { - MYFLT kangl = PI_F*FL(0.5) * *p->pan; - for (n=0; npan[n]; - ar[n] = ain[n] * SIN(kangl); + case 0: + { + MYFLT kangl = PI_F*FL(0.5) * *p->pan; + for (n=offset; npan[n]; + ar[n] = ain[n] * SIN(kangl); al[n] = ain[n] * COS(kangl); + } + break; } - break; - } - case 1: { - MYFLT kangl = *p->pan; - for (n=0; npan[n]; - ar[n] = ain[n] * SQRT(kangl); - al[n] = ain[n] * SQRT(FL(1.0)-kangl); + case 1: + { + MYFLT kangl = *p->pan; + for (n=offset; npan[n]; + ar[n] = ain[n] * SQRT(kangl); + al[n] = ain[n] * SQRT(FL(1.0)-kangl); + } + break; } - break; - } - case 2: { - MYFLT kangl = *p->pan; - for (n=0; npan[n]; - ar[n] = ain[n] * kangl; - al[n] = ain[n] * (FL(1.0)-kangl); + case 2: + { + MYFLT kangl = *p->pan; + for (n=offset; npan[n]; + ar[n] = ain[n] * kangl; + al[n] = ain[n] * (FL(1.0)-kangl); + } + break; } - break; - } - case 3: { - MYFLT kangl = *p->pan, cc, ss, l, r; - for (n=0; npan[n]; - cc = COS(PI*kangl*FL(0.5)); - ss = SIN(PI*kangl*FL(0.5)); - l = SQRT2*(cc+ss)*0.5; - r = SQRT2*(cc-ss)*0.5; - al[n] = ain[n] * l; - ar[n] = ain[n] * r; + case 3: + { + MYFLT kangl = *p->pan, cc, ss, l, r; + for (n=offset; npan[n]; + cc = COS(PI*kangl*FL(0.5)); + ss = SIN(PI*kangl*FL(0.5)); + l = SQRT2*(cc+ss)*0.5; + r = SQRT2*(cc-ss)*0.5; + al[n] = ain[n] * l; + ar[n] = ain[n] * r; + } } } - } return OK; } static OENTRY pan2_localops[] = { - { "pan2", sizeof(PAN2), 5, "aa", "axo", (SUBR) pan2set, 0, (SUBR) pan2run } + { "pan2", sizeof(PAN2), 0, 5, "aa", "axo", (SUBR) pan2set, 0, (SUBR) pan2run } }; -LINKAGE1(pan2_localops) +LINKAGE_BUILTIN(pan2_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/partials.c csound-6.02~dfsg/Opcodes/partials.c --- csound-5.17.11~dfsg/Opcodes/partials.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/partials.c 2014-01-07 16:53:48.000000000 +0000 @@ -37,7 +37,7 @@ */ -#include "csdl.h" +#include "pvs_ops.h" #include "pstream.h" typedef struct _parts { @@ -469,7 +469,8 @@ static OENTRY localops[] = { - { "partials", sizeof(_PARTS), 3, "f", "ffkkki", (SUBR) partials_init, (SUBR) partials_process } + { "partials", sizeof(_PARTS), 0, 3, "f", "ffkkki", + (SUBR) partials_init, (SUBR) partials_process } }; int partials_init_(CSOUND *csound) @@ -477,4 +478,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/partikkel.c csound-6.02~dfsg/Opcodes/partikkel.c --- csound-5.17.11~dfsg/Opcodes/partikkel.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/partikkel.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,6 +1,6 @@ /* Partikkel - a granular synthesis module for Csound 5 -Copyright (C) 2006-2009 Øyvind Brandtsegg, Torgeir Strand Henriksen, +Copyright (C) 2006-2009 Oeyvind Brandtsegg, Torgeir Strand Henriksen, Thom Johansen This library is free software; you can redistribute it and/or @@ -23,14 +23,13 @@ #include #define INITERROR(x) csound->InitError(csound, Str("partikkel: " x)) -#define PERFERROR(x) csound->PerfError(csound, Str("partikkel: " x)) +#define PERFERROR(x) csound->PerfError(csound, p->h.insdshead,Str("partikkel: " x)) #define WARNING(x) csound->Warning(csound, Str("partikkel: " x)) /* Assume csound and p pointers are always available */ #define frand() (csound->RandMT(&p->randstate)/(double)(0xffffffff)) - /* linear interpolation between x and y by z - * NOTE: arguments evaluated more than once, don't pass anything with side + * NOTE: arguments evaluated more than once, do not pass anything with side * effects */ #define lrp(x, y, z) ((x) + ((y) - (x))*(z)) @@ -43,7 +42,7 @@ /* here follows routines for maintaining a linked list of grains */ /* initialises a linked list of NODEs */ -static int init_pool(GRAINPOOL *s, unsigned max_grains) +static void init_pool(GRAINPOOL *s, unsigned max_grains) { unsigned i; NODE **p = &s->grainlist; @@ -58,7 +57,6 @@ node->next = NULL; p = &(node->next); } - return 1; } /* returns pointer to new node */ @@ -99,61 +97,61 @@ pg = csound->QueryGlobalVariable(csound, "partikkel"); if (pg == NULL) { - char *t; - int i; + int i; - if (UNLIKELY(csound->CreateGlobalVariable(csound, "partikkel", - sizeof(PARTIKKEL_GLOBALS)) != 0)) - return INITERROR("could not allocate globals"); - pg = csound->QueryGlobalVariable(csound, "partikkel"); - pg->rootentry = NULL; - /* build default tables. allocate enough for three, plus extra for the - * ftable data itself */ - t = pg->tablestorage = csound->Calloc(csound, 4*sizeof(FUNC) - + 12*sizeof(MYFLT)); - pg->ooo_tab = (FUNC *)t; - t += sizeof(FUNC) + 2*sizeof(MYFLT); - pg->zzz_tab = (FUNC *)t; - t += sizeof(FUNC) + 2*sizeof(MYFLT); - pg->zzo_tab = (FUNC *)t; - t += sizeof(FUNC) + 2*sizeof(MYFLT); - pg->zzhhhhz_tab = (FUNC *)t; - /* we only fill in the entries in the FUNC struct that we use */ - /* table with data [1.0, 1.0, 1.0], used as default by envelopes */ - pg->ooo_tab->flen = 2; - pg->ooo_tab->lobits = 31; - for (i = 0; i <= 2; ++i) - pg->ooo_tab->ftable[i] = FL(1.0); - /* table with data [0.0, 0.0, 0.0], used as default by grain - * distribution table, channel masks and grain waveforms */ - pg->zzz_tab->flen = 2; - pg->zzz_tab->lobits = 31; - /* table with data [0.0, 0.0, 1.0], used as default by gain masks, - * fm index table, and wave start and end freq tables */ - pg->zzo_tab->ftable[2] = FL(1.0); - /* table with data [0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0], used as default - * by wave gain table */ - for (i = 2; i <= 5; ++i) - pg->zzhhhhz_tab->ftable[i] = FL(0.5); + if (UNLIKELY(csound->CreateGlobalVariable(csound, "partikkel", + sizeof(PARTIKKEL_GLOBALS)) != 0)) + return INITERROR("could not allocate globals"); + pg = csound->QueryGlobalVariable(csound, "partikkel"); + pg->rootentry = NULL; + /* build default tables. allocate enough for three, plus extra for the + * ftable data itself */ + /* we only fill in the entries in the FUNC struct that we use */ + /* table with data [1.0, 1.0, 1.0], used as default by envelopes */ + pg->ooo_tab = (FUNC *)csound->Calloc(csound, sizeof(FUNC)); + pg->ooo_tab->ftable = (MYFLT*)csound->Calloc(csound, 3*sizeof(MYFLT)); + pg->ooo_tab->flen = 2; + pg->ooo_tab->lobits = 31; + for (i = 0; i <= 2; ++i) + pg->ooo_tab->ftable[i] = FL(1.0); + /* table with data [0.0, 0.0, 0.0], used as default by grain + * distribution table, channel masks and grain waveforms */ + pg->zzz_tab = (FUNC *)csound->Calloc(csound, sizeof(FUNC)); + pg->zzz_tab->ftable = (MYFLT*)csound->Calloc(csound, 3*sizeof(MYFLT)); + pg->zzz_tab->flen = 2; + pg->zzz_tab->lobits = 31; + /* table with data [0.0, 0.0, 1.0], used as default by gain masks, + * fm index table, and wave start and end freq tables */ + pg->zzo_tab = (FUNC *)csound->Calloc(csound, sizeof(FUNC)); + pg->zzo_tab->ftable = (MYFLT*)csound->Calloc(csound, 4*sizeof(MYFLT)); + pg->zzo_tab->ftable[2] = FL(1.0); + pg->zzo_tab->flen = 3; /* JPff */ + /* table with data [0.0, 0.0, 0.5, 0.5, 0.5, 0.5, 0.0], used as default + * by wave gain table */ + pg->zzhhhhz_tab = (FUNC *)csound->Calloc(csound, sizeof(FUNC)); + pg->zzhhhhz_tab->ftable = (MYFLT*)csound->Calloc(csound, 8*sizeof(MYFLT)); + for (i = 2; i <= 5; ++i) + pg->zzhhhhz_tab->ftable[i] = FL(0.5); } p->globals = pg; if ((int)*p->opcodeid == 0) { - /* opcodeid 0 means we don't bother with the sync opcode */ - p->globals_entry = NULL; - return OK; + /* opcodeid 0 means we do not bother with the sync opcode */ + p->globals_entry = NULL; + return OK; } /* try to find entry corresponding to our opcodeid */ pe = &pg->rootentry; while (*pe != NULL && (*pe)->id != *p->opcodeid) - pe = &((*pe)->next); + pe = &((*pe)->next); /* check if one already existed, if not, create one */ if (*pe == NULL) { - *pe = csound->Malloc(csound, sizeof(PARTIKKEL_GLOBALS_ENTRY)); - (*pe)->id = *p->opcodeid; - /* allocate table for sync data */ - (*pe)->synctab = csound->Calloc(csound, 2*csound->ksmps*sizeof(MYFLT)); - (*pe)->next = NULL; + *pe = csound->Malloc(csound, sizeof(PARTIKKEL_GLOBALS_ENTRY)); + (*pe)->id = *p->opcodeid; + (*pe)->partikkel = p; + /* allocate table for sync data */ + (*pe)->synctab = csound->Calloc(csound, 2*CS_KSMPS*sizeof(MYFLT)); + (*pe)->next = NULL; } p->globals_entry = *pe; return OK; @@ -220,7 +218,7 @@ static int partikkel_init(CSOUND *csound, PARTIKKEL *p) { - int32 size; + uint32_t size; int ret; if ((ret = setup_globals(csound, p)) != OK) @@ -264,6 +262,13 @@ p->wavgaintab = *p->waveamps >= FL(0.0) ? csound->FTFind(csound, p->waveamps) : p->globals->zzhhhhz_tab; + if (*p->pantable >= FL(0.0)) { + p->pantab = csound->FTFind(csound, p->pantable); + if (!p->pantab) + return INITERROR("unable to load panning function table"); + } else { + p->pantab = NULL; /* use default linear panning function */ + } if (UNLIKELY(!p->disttab)) return INITERROR("unable to load distribution table"); @@ -298,7 +303,7 @@ p->graininc = 0.0; /* allocate memory for the grain mix buffer */ - size = csound->ksmps*sizeof(MYFLT); + size = CS_KSMPS*sizeof(MYFLT); if (p->aux.auxp == NULL || p->aux.size < size) csound->AuxAlloc(csound, size, &p->aux); else @@ -396,20 +401,31 @@ return_grain(&p->gpool, node); return PERFERROR("channel mask specifies non-existing output channel"); } - grain->gain1 = FL(1.0) - (maskchannel - chan); - grain->gain2 = maskchannel - chan; + /* use panning law table if specified */ + if (p->pantab != NULL) { + unsigned tabsize = p->pantab->flen/8; + unsigned i1 = (unsigned)((FL(1.0) - maskchannel + 2*chan)*tabsize); + unsigned i2 = (unsigned)(maskchannel*tabsize); + + grain->gain1 = p->pantab->ftable[i1]; + grain->gain2 = p->pantab->ftable[i2]; + } else { + grain->gain1 = FL(1.0) - (maskchannel - chan); + grain->gain2 = maskchannel - chan; + } + grain->chan1 = chan; grain->chan2 = p->num_outputs > chan + 1 ? chan + 1 : 0; /* duration in samples */ - samples = (int)((csound->esr*(*p->duration)/1000.0) + 0.5); + samples = (int)((CS_ESR*(*p->duration)/1000.0) + 0.5); /* if grainlength is below one sample, we'll just cancel it */ if (samples <= 0) { return_grain(&p->gpool, node); return OK; } rcp_samples = 1.0/(double)samples; - grain->start = n + offset*csound->esr; + grain->start = n + offset*CS_ESR; grain->stop = grain->start + samples; /* implement sub-sample grain placement for synchronous grains */ if (offset == 0.0 && p->graininc > 1e-6) @@ -431,8 +447,7 @@ curwav->table = i != WAV_TRAINLET ? p->wavetabs[i] : p->costab; curwav->gain = wavgains[wavgainsindex + i + 2]*graingain; - /* check if waveform gets zero volume. if so, let's mark it as unused - * and move on to the next one */ + /* drop wavetables with close to zero gain */ if (fabs(curwav->gain) < FL(1e-8)) { curwav->table = NULL; continue; @@ -446,7 +461,7 @@ /* limit dsf harmonics to nyquist to avoid aliasing. * minumum number of harmonics is 2, since 1 would yield just dc, * which we remove anyway */ - nh = 0.5*csound->esr/fabs(maxfreq); + nh = 0.5*CS_ESR/fabs(maxfreq); if (nh > fabs(*p->harmonics)) nh = fabs(*p->harmonics); grain->harmonics = (unsigned)nh + 1; @@ -529,7 +544,9 @@ /* this function schedules the grains that are bound to happen this k-period */ static int schedule_grains(CSOUND *csound, PARTIKKEL *p) { - int32 n; + uint32_t koffset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; NODE *node; MYFLT **waveformparams = &p->waveform1; MYFLT grainfreq = fabs(*p->grainfreq); @@ -549,8 +566,9 @@ if (UNLIKELY(!p->fmenvtab)) return PERFERROR("unable to load FM envelope table"); + if (UNLIKELY(early)) nsmps -= early; /* start grain scheduling */ - for (n = 0; n < csound->ksmps; ++n) { + for (n = koffset; n < nsmps; ++n) { if (p->sync[n] >= FL(1.0)) { /* we got a full sync pulse, hardsync grain clock if needed */ if (!p->synced) { @@ -589,7 +607,7 @@ /* negative distrib, choose sequential point in table */ offset = p->disttab->ftable[p->distindex++]; offset *= -*p->distribution; - if (p->distindex >= p->disttab->flen) + if ((uint32_t)p->distindex >= p->disttab->flen) p->distindex = 0; } /* convert offset to seconds, also limiting it to 10 seconds to @@ -598,7 +616,7 @@ if (grainfreq < FL(0.001)) offset = 0; else if ((offset - p->grainphase)/grainfreq > 10.) - offset = 10.; + offset = 10.0; else offset = (offset - p->grainphase)/grainfreq; @@ -627,7 +645,7 @@ /* store away the scheduler phase for use in partikkelsync */ if (p->globals_entry) - p->globals_entry->synctab[csound->ksmps + n] = p->grainphase; + p->globals_entry->synctab[CS_KSMPS + n] = p->grainphase; if (p->grainfreq_arate) grainfreq = fabs(p->grainfreq[n]); @@ -637,6 +655,69 @@ return OK; } +/* Main synthesis loops */ +/* NOTE: the main synthesis loop is duplicated for both wavetable and + * trainlet synthesis for speed */ +static inline void render_wave(PARTIKKEL *p, GRAIN *grain, WAVEDATA *wav, + MYFLT *buf, unsigned stop) +{ + unsigned n; + double fmenvphase = grain->envphase; + + /* wavetable synthesis */ + for (n = grain->start; n < stop; ++n) { + double tablen = (double)wav->table->flen; + unsigned x0; + MYFLT frac, fmenv; + + /* make sure phase accumulator stays within bounds */ + while (UNLIKELY(wav->phase >= tablen)) + wav->phase -= tablen; + while (UNLIKELY(wav->phase < 0.0)) + wav->phase += tablen; + + /* sample table lookup with linear interpolation */ + x0 = (unsigned)wav->phase; + frac = (MYFLT)(wav->phase - x0); + buf[n] += lrp(wav->table->ftable[x0], wav->table->ftable[x0 + 1], + frac)*wav->gain; + + fmenv = grain->fmenvtab->ftable[(size_t)(fmenvphase*FMAXLEN) + >> grain->fmenvtab->lobits]; + fmenvphase += grain->envinc; + wav->phase += wav->delta + wav->delta*p->fm[n]*grain->fmamp*fmenv; + /* apply sweep */ + wav->delta = wav->delta*wav->sweepdecay + wav->sweepoffset; + } +} + +static inline void render_trainlet(PARTIKKEL *p, GRAIN *grain, WAVEDATA *wav, + MYFLT *buf, unsigned stop) +{ + unsigned n; + double fmenvphase = grain->envphase; + + /* trainlet synthesis */ + for (n = grain->start; n < stop; ++n) { + MYFLT fmenv; + + while (UNLIKELY(wav->phase >= 1.0)) + wav->phase -= 1.0; + while (UNLIKELY(wav->phase < 0.0)) + wav->phase += 1.0; + + /* dsf/trainlet synthesis */ + buf[n] += wav->gain*dsf(p->costab, grain, wav->phase, p->zscale, + p->cosineshift); + + fmenv = grain->fmenvtab->ftable[(size_t)(fmenvphase*FMAXLEN) + >> grain->fmenvtab->lobits]; + fmenvphase += grain->envinc; + wav->phase += wav->delta + wav->delta*p->fm[n]*grain->fmamp*fmenv; + wav->delta = wav->delta*wav->sweepdecay + wav->sweepoffset; + } +} + /* do the actual waveform synthesis */ static inline void render_grain(CSOUND *csound, PARTIKKEL *p, GRAIN *grain) { @@ -644,73 +725,23 @@ unsigned n; MYFLT *out1 = *(&(p->output1) + grain->chan1); MYFLT *out2 = *(&(p->output1) + grain->chan2); - unsigned stop = grain->stop > csound->ksmps - ? csound->ksmps : grain->stop; + unsigned stop = grain->stop > CS_KSMPS + ? CS_KSMPS : grain->stop; MYFLT *buf = (MYFLT *)p->aux.auxp; - if (grain->start >= csound->ksmps) + if (grain->start >= CS_KSMPS) return; /* grain starts at a later kperiod */ for (i = 0; i < 5; ++i) { WAVEDATA *curwav = &grain->wav[i]; - double fmenvphase = grain->envphase; - MYFLT fmenv; /* check if ftable is to be rendered */ if (curwav->table == NULL) continue; - /* NOTE: the main synthesis loop is duplicated for both wavetable and - * trainlet synthesis for speed */ - if (i != WAV_TRAINLET) { - /* wavetable synthesis */ - for (n = grain->start; n < stop; ++n) { - double tablen = (double)curwav->table->flen; - unsigned x0; - MYFLT frac; - - /* make sure phase accumulator stays within bounds */ - while (UNLIKELY(curwav->phase >= tablen)) - curwav->phase -= tablen; - while (UNLIKELY(curwav->phase < 0.0)) - curwav->phase += tablen; - - /* sample table lookup with linear interpolation */ - x0 = (unsigned)curwav->phase; - frac = (MYFLT)(curwav->phase - x0); - buf[n] += lrp(curwav->table->ftable[x0], - curwav->table->ftable[x0 + 1], - frac)*curwav->gain; - - fmenv = grain->fmenvtab->ftable[(size_t)(fmenvphase*FMAXLEN) - >> grain->fmenvtab->lobits]; - fmenvphase += grain->envinc; - curwav->phase += curwav->delta - + curwav->delta*p->fm[n]*grain->fmamp*fmenv; - /* apply sweep */ - curwav->delta = curwav->delta*curwav->sweepdecay - + curwav->sweepoffset; - } - } else { - /* trainlet synthesis */ - for (n = grain->start; n < stop; ++n) { - while (UNLIKELY(curwav->phase >= 1.0)) - curwav->phase -= 1.0; - while (UNLIKELY(curwav->phase < 0.0)) - curwav->phase += 1.0; - - /* dsf/trainlet synthesis */ - buf[n] += curwav->gain*dsf(p->costab, grain, curwav->phase, - p->zscale, p->cosineshift); - - fmenv = grain->fmenvtab->ftable[(size_t)(fmenvphase*FMAXLEN) - >> grain->fmenvtab->lobits]; - fmenvphase += grain->envinc; - curwav->phase += curwav->delta - + curwav->delta*p->fm[n]*grain->fmamp*fmenv; - curwav->delta = curwav->delta*curwav->sweepdecay - + curwav->sweepoffset; - } - } + if (i != WAV_TRAINLET) + render_wave(p, grain, curwav, buf, stop); + else + render_trainlet(p, grain, curwav, buf, stop); } /* apply envelopes */ @@ -758,7 +789,8 @@ static int partikkel(CSOUND *csound, PARTIKKEL *p) { - int ret, n; + int ret; + unsigned int n; NODE **nodeptr; MYFLT **outputs = &p->output1; @@ -770,7 +802,7 @@ /* clear output buffers, we'll be accumulating our outputs */ for (n = 0; n < p->num_outputs; ++n) - memset(outputs[n], 0, sizeof(MYFLT)*csound->ksmps); + memset(outputs[n], 0, sizeof(MYFLT)*CS_KSMPS); /* prepare to traverse grain list */ nodeptr = &p->grainroot; @@ -780,16 +812,16 @@ /* render current grain to outputs */ render_grain(csound, p, grain); /* check if grain is finished */ - if (grain->stop <= csound->ksmps) { + if (grain->stop <= CS_KSMPS) { /* grain is finished, deactivate it */ *nodeptr = return_grain(&p->gpool, *nodeptr); } else { /* extend grain lifetime with one k-period and find next grain */ - if (csound->ksmps > grain->start) + if (CS_KSMPS > grain->start) grain->start = 0; /* grain is active */ else - grain->start -= csound->ksmps; /* grain is not yet active */ - grain->stop -= csound->ksmps; + grain->start -= CS_KSMPS; /* grain is not yet active */ + grain->stop -= CS_KSMPS; nodeptr = &((*nodeptr)->next); } } @@ -797,7 +829,7 @@ } /* partikkelsync stuff */ -static int partikkelsync_init(CSOUND *csound, PARTIKKELSYNC *p) +static int partikkelsync_init(CSOUND *csound, PARTIKKEL_SYNC *p) { PARTIKKEL_GLOBALS *pg; PARTIKKEL_GLOBALS_ENTRY *pe; @@ -821,37 +853,137 @@ return OK; } -static int partikkelsync(CSOUND *csound, PARTIKKELSYNC *p) +static int partikkelsync(CSOUND *csound, PARTIKKEL_SYNC *p) { /* write sync pulse data */ - memcpy(p->syncout, p->ge->synctab, csound->ksmps*sizeof(MYFLT)); + memcpy(p->syncout, p->ge->synctab, CS_KSMPS*sizeof(MYFLT)); /* write scheduler phase data, if user wanted it */ if (p->output_schedphase) { - memcpy(p->schedphaseout, p->ge->synctab + csound->ksmps, - csound->ksmps*sizeof(MYFLT)); + memcpy(p->schedphaseout, p->ge->synctab + CS_KSMPS, + CS_KSMPS*sizeof(MYFLT)); } /* clear first half of sync table to get rid of old sync pulses */ - memset(p->ge->synctab, 0, csound->ksmps*sizeof(MYFLT)); + memset(p->ge->synctab, 0, CS_KSMPS*sizeof(MYFLT)); + return OK; +} + +static int get_global_entry(CSOUND *csound, PARTIKKEL_GLOBALS_ENTRY **entry, + MYFLT opcodeid, const char *prefix) +{ + PARTIKKEL_GLOBALS *pg; + PARTIKKEL_GLOBALS_ENTRY *pe; + + pg = csound->QueryGlobalVariable(csound, "partikkel"); + if (UNLIKELY(pg == NULL)) + return csound->InitError(csound, + Str("%s: partikkel not initialized"), prefix); + /* try to find entry corresponding to our opcodeid */ + pe = pg->rootentry; + while (pe != NULL && pe->id != opcodeid) + pe = pe->next; + + if (UNLIKELY(pe == NULL)) + return csound->InitError(csound, + Str("%s: could not find opcode id"), prefix); + *entry = pe; + return OK; +} + +static int partikkelget_init(CSOUND *csound, PARTIKKEL_GET *p) +{ + return get_global_entry(csound, &p->ge, *p->opcodeid, "partikkelget"); +} + +static int partikkelget(CSOUND *csound, PARTIKKEL_GET *p) +{ + PARTIKKEL *partikkel = p->ge->partikkel; + + switch ((int)*p->index) { + case 0: + *p->valout = (MYFLT)partikkel->gainmaskindex; + break; + case 1: + *p->valout = (MYFLT)partikkel->wavfreqstartindex; + break; + case 2: + *p->valout = (MYFLT)partikkel->wavfreqendindex; + break; + case 3: + *p->valout = (MYFLT)partikkel->fmampindex; + break; + case 4: + *p->valout = (MYFLT)partikkel->channelmaskindex; + break; + case 5: + *p->valout = (MYFLT)partikkel->wavgainindex; + break; + } + return OK; +} + +static int partikkelset_init(CSOUND *csound, PARTIKKEL_SET *p) +{ + return get_global_entry(csound, &p->ge, *p->opcodeid, "partikkelset"); +} + +static int partikkelset(CSOUND *csound, PARTIKKEL_SET *p) +{ + PARTIKKEL *partikkel = p->ge->partikkel; + + switch ((int)*p->index) { + case 0: + partikkel->gainmaskindex = (unsigned)*p->value; + break; + case 1: + partikkel->wavfreqstartindex = (unsigned)*p->value; + break; + case 2: + partikkel->wavfreqendindex = (unsigned)*p->value; + break; + case 3: + partikkel->fmampindex = (unsigned)*p->value; + break; + case 4: + partikkel->channelmaskindex = (unsigned)*p->value; + break; + case 5: + partikkel->wavgainindex = (unsigned)*p->value; + break; + } return OK; } static OENTRY partikkel_localops[] = { { - "partikkel", sizeof(PARTIKKEL), TR|5, + "partikkel", sizeof(PARTIKKEL), TR, 5, "ammmmmmm", - "xkiakiiikkkkikkiiaikikkkikkkkkiaaaakkkkio", + "xkiakiiikkkkikkiiaikikkkikkkkkiaaaakkkkioj", (SUBR)partikkel_init, (SUBR)NULL, (SUBR)partikkel }, { - "partikkelsync", sizeof(PARTIKKELSYNC), TR|5, + "partikkelsync", sizeof(PARTIKKEL_SYNC), TR, 5, "am", "i", (SUBR)partikkelsync_init, (SUBR)NULL, (SUBR)partikkelsync + }, + { + "partikkelget", sizeof(PARTIKKEL_GET), TR, 3, + "k", "ki", + (SUBR)partikkelget_init, + (SUBR)partikkelget, + (SUBR)NULL + }, + { + "partikkelset", sizeof(PARTIKKEL_SET), TR, 3, + "", "kki", + (SUBR)partikkelset_init, + (SUBR)partikkelset, + (SUBR)NULL } }; -LINKAGE1(partikkel_localops) +LINKAGE_BUILTIN(partikkel_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/partikkel.h csound-6.02~dfsg/Opcodes/partikkel.h --- csound-5.17.11~dfsg/Opcodes/partikkel.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/partikkel.h 2014-01-07 16:54:20.000000000 +0000 @@ -46,9 +46,9 @@ #define WAV_TRAINLET 4 /* support structs for the grain pool routines */ -typedef struct NODE_ { +typedef struct NODE { GRAIN grain; - struct NODE_ *next; + struct NODE *next; } NODE; typedef struct { @@ -57,10 +57,13 @@ unsigned free_nodes; } GRAINPOOL; -typedef struct PARTIKKEL_GLOBALS_ENTRY_ { +struct PARTIKKEL; + +typedef struct PARTIKKEL_GLOBALS_ENTRY { MYFLT id; MYFLT *synctab; - struct PARTIKKEL_GLOBALS_ENTRY_ *next; + struct PARTIKKEL *partikkel; + struct PARTIKKEL_GLOBALS_ENTRY *next; } PARTIKKEL_GLOBALS_ENTRY; typedef struct { @@ -70,11 +73,11 @@ FUNC *zzz_tab; FUNC *zzo_tab; FUNC *zzhhhhz_tab; - char *tablestorage; + //char *tablestorage; PARTIKKEL_GLOBALS_ENTRY *rootentry; } PARTIKKEL_GLOBALS; -typedef struct { +typedef struct PARTIKKEL { OPDS h; /* output arrays */ MYFLT *output1, *output2, *output3, *output4; @@ -113,6 +116,7 @@ MYFLT *wavekey1, *wavekey2, *wavekey3, *wavekey4; MYFLT *max_grains; MYFLT *opcodeid; + MYFLT *pantable; /* internal variables */ PARTIKKEL_GLOBALS *globals; @@ -145,6 +149,7 @@ FUNC *wavgaintab; unsigned wavgainindex; double grainphase, graininc; + FUNC *pantab; } PARTIKKEL; typedef struct { @@ -159,4 +164,25 @@ /* internal variables */ int output_schedphase; PARTIKKEL_GLOBALS_ENTRY *ge; -} PARTIKKELSYNC; +} PARTIKKEL_SYNC; + +typedef struct { + OPDS h; + /* output */ + MYFLT *valout; + + /* inputs */ + MYFLT *index; + MYFLT *opcodeid; + PARTIKKEL_GLOBALS_ENTRY *ge; +} PARTIKKEL_GET; + +typedef struct { + OPDS h; + /* inputs */ + MYFLT *index; + MYFLT *value; + MYFLT *opcodeid; + PARTIKKEL_GLOBALS_ENTRY *ge; +} PARTIKKEL_SET; + diff -Nru csound-5.17.11~dfsg/Opcodes/phisem.c csound-6.02~dfsg/Opcodes/phisem.c --- csound-5.17.11~dfsg/Opcodes/phisem.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/phisem.c 2014-01-07 16:53:48.000000000 +0000 @@ -190,8 +190,8 @@ static int cabasaset(CSOUND *csound, CABASA *p) { p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs0 = FL(0.0); p->outputs1 = FL(0.0); p->shake_maxSave = FL(0.0); @@ -213,7 +213,9 @@ static int cabasa(CSOUND *csound, CABASA *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; /* Use locals for speed */ MYFLT shakeEnergy = p->shakeEnergy; @@ -245,7 +247,7 @@ if (*p->shake_max != FL(0.0)) { shakeEnergy = p->shakeEnergy += - csound->ksmps * *p->shake_max * MAX_SHAKE * FL(0.1); + CS_KSMPS * *p->shake_max * MAX_SHAKE * FL(0.1); if (shakeEnergy > MAX_SHAKE) shakeEnergy = MAX_SHAKE; } @@ -254,7 +256,12 @@ shakeEnergy = FL(0.0); } - for (n=0;n MIN_ENERGY) { */ shakeEnergy *= systemDecay; /* Exponential system decay */ if (my_random(csound, 1024) < p->num_objects) { @@ -285,8 +292,8 @@ static int sekereset(CSOUND *csound, SEKERE *p) { p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs0 = FL(0.0); p->outputs1 = FL(0.0); p->finalZ2 = FL(0.0); @@ -312,7 +319,9 @@ static int sekere(CSOUND *csound, SEKERE *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; /* Use locals for speed */ MYFLT shakeEnergy = p->shakeEnergy; @@ -344,7 +353,7 @@ if (*p->shake_max != FL(0.0)) { shakeEnergy = p->shakeEnergy += - csound->ksmps * *p->shake_max * MAX_SHAKE * FL(0.1); + CS_KSMPS * *p->shake_max * MAX_SHAKE * FL(0.1); if (shakeEnergy > MAX_SHAKE) shakeEnergy = MAX_SHAKE; } @@ -353,7 +362,12 @@ shakeEnergy = FL(0.0); } - for (n=0;n MIN_ENERGY) { */ shakeEnergy *= systemDecay; /* Exponential system decay */ if (my_random(csound, 1024) < p->num_objects) { @@ -377,6 +391,7 @@ /* ar[n] = 0.0f; */ /* } */ } + printf("%d/%d:\n", offset, early); p->shakeEnergy = shakeEnergy; p->sndLevel = sndLevel; p->outputs0 = outputs0; @@ -387,8 +402,8 @@ static int sandset(CSOUND *csound, SEKERE *p) { p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs0 = FL(0.0); p->outputs1 = FL(0.0); p->finalZ2 = FL(0.0); @@ -415,8 +430,8 @@ static int stixset(CSOUND *csound, SEKERE *p) { p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs0 = FL(0.0); p->outputs1 = FL(0.0); p->finalZ2 = FL(0.0); @@ -442,8 +457,8 @@ static int crunchset(CSOUND *csound, CABASA *p) { p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs0 = FL(0.0); p->outputs1 = FL(0.0); p->shake_maxSave = FL(0.0); @@ -469,8 +484,8 @@ MYFLT temp; p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs00 = FL(0.0); p->outputs01 = FL(0.0); @@ -512,7 +527,9 @@ static int guiro(CSOUND *csound, GUIRO *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT lastOutput; if (*p->num_teeth != FL(0.0) && @@ -572,7 +589,12 @@ MYFLT gains0 = p->gains0; MYFLT gains1 = p->gains1; MYFLT amp = *p->amp; - for (n=0;n 0) { ratchet -= (ratchetDelta + (FL(0.002)*totalEnergy)); if (ratchet < FL(0.0)) { @@ -628,8 +650,8 @@ MYFLT temp; p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs00 = FL(0.0); p->outputs01 = FL(0.0); @@ -673,7 +695,9 @@ static int tambourine(CSOUND *csound, TAMBOURINE *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; MYFLT temp_rand; MYFLT lastOutput; @@ -718,7 +742,12 @@ MYFLT sndLevel = p->sndLevel; MYFLT soundDecay = p->soundDecay; MYFLT inputs0, inputs1, inputs2; - for (n=0;nnum_objects) { sndLevel += p->gain * shakeEnergy; @@ -766,8 +795,8 @@ MYFLT temp; p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs00 = FL(0.0); p->outputs01 = FL(0.0); @@ -806,7 +835,9 @@ static int bamboo(CSOUND *csound, BAMBOO *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; MYFLT temp_rand; MYFLT lastOutput; @@ -850,7 +881,12 @@ MYFLT sndLevel = p->sndLevel; MYFLT soundDecay = p->soundDecay; MYFLT inputs0, inputs1, inputs2; - for (n=0;nnum_objects) { sndLevel += shakeEnergy; @@ -901,8 +937,8 @@ MYFLT temp; p->sndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs00 = FL(0.0); p->outputs01 = FL(0.0); @@ -942,7 +978,9 @@ static int wuter(CSOUND *csound, WUTER *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; MYFLT lastOutput; @@ -987,7 +1025,12 @@ MYFLT soundDecay = p->soundDecay; MYFLT inputs0, inputs1, inputs2; - for (n=0;nsndLevel = FL(0.0); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->outputs00 = FL(0.0); p->outputs01 = FL(0.0); @@ -1123,7 +1166,9 @@ static int sleighbells(CSOUND *csound, SLEIGHBELLS *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT data; MYFLT temp_rand; MYFLT lastOutput; @@ -1167,7 +1212,12 @@ MYFLT sndLevel = p->sndLevel; MYFLT soundDecay = p->soundDecay; MYFLT inputs0, inputs1, inputs2, inputs3, inputs4; - for (n=0;nnum_objects) { sndLevel += p->gain * shakeEnergy; @@ -1234,18 +1284,19 @@ #define S(x) sizeof(x) static OENTRY phisem_localops[] = { -{ "cabasa", S(CABASA), 5, "a", "iiooo", (SUBR)cabasaset, NULL, (SUBR)cabasa}, -{ "crunch", S(CABASA), 5, "a", "iiooo", (SUBR)crunchset, NULL, (SUBR)cabasa}, -{ "sekere", S(SEKERE), 5, "a", "iiooo", (SUBR)sekereset, NULL, (SUBR)sekere}, -{ "sandpaper", S(SEKERE),5, "a", "iiooo", (SUBR)sandset, NULL, (SUBR)sekere}, -{ "stix", S(SEKERE), 5, "a", "iiooo", (SUBR)stixset, NULL, (SUBR)sekere}, -{ "guiro", S(GUIRO), 5, "a", "kiooooo", (SUBR)guiroset, NULL, (SUBR)guiro }, -{ "tambourine", S(TAMBOURINE),5,"a", "kioooooo", +{ "cabasa", S(CABASA), 0, 5, "a", "iiooo", (SUBR)cabasaset, NULL, (SUBR)cabasa}, +{ "crunch", S(CABASA), 0, 5, "a", "iiooo", (SUBR)crunchset, NULL, (SUBR)cabasa}, +{ "sekere", S(SEKERE), 0, 5, "a", "iiooo", (SUBR)sekereset, NULL, (SUBR)sekere}, +{ "sandpaper", S(SEKERE),0, 5, "a", "iiooo", (SUBR)sandset, NULL, (SUBR)sekere}, +{ "stix", S(SEKERE), 0, 5, "a", "iiooo", (SUBR)stixset, NULL, (SUBR)sekere}, +{ "guiro", S(GUIRO), 0, 5, "a", "kiooooo",(SUBR)guiroset, NULL, (SUBR)guiro }, +{ "tambourine", S(TAMBOURINE),0, 5,"a", "kioooooo", (SUBR)tambourset, NULL, (SUBR)tambourine}, -{ "bamboo", S(BAMBOO), 5, "a", "kioooooo", (SUBR)bambooset, NULL, (SUBR)bamboo }, -{ "dripwater", S(WUTER), 5, "a", "kioooooo", (SUBR)wuterset, NULL, (SUBR)wuter }, -{ "sleighbells", S(SLEIGHBELLS), 5, "a","kioooooo", +{ "bamboo", S(BAMBOO), 0, 5, "a", "kioooooo", + (SUBR)bambooset, NULL, (SUBR)bamboo }, +{ "dripwater", S(WUTER), 0, 5, "a", "kioooooo", (SUBR)wuterset, NULL, (SUBR)wuter }, +{ "sleighbells", S(SLEIGHBELLS), 0, 5, "a","kioooooo", (SUBR)sleighset, NULL, (SUBR)sleighbells } }; -LINKAGE1(phisem_localops) +LINKAGE_BUILTIN(phisem_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/physmod.c csound-6.02~dfsg/Opcodes/physmod.c --- csound-5.17.11~dfsg/Opcodes/physmod.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/physmod.c 2014-01-07 16:53:48.000000000 +0000 @@ -117,19 +117,19 @@ { FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) p->vibr = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp; else { /* Expect sine wave */ return csound->InitError(csound, Str("No table for Clarinet")); } if (*p->lowestFreq>=FL(0.0)) { /* Skip initialisation */ if (*p->lowestFreq) - p->length = (int32) (csound->esr / *p->lowestFreq + FL(1.0)); + p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0)); else if (*p->frequency) - p->length = (int32) (csound->esr / *p->frequency + FL(1.0)); + p->length = (int32) (CS_ESR / *p->frequency + FL(1.0)); else { csound->Warning(csound, Str("No base frequency for clarinet " "-- assuming 50Hz\n")); - p->length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } make_DLineL(csound, &p->delayLine, p->length); p->reedTable.offSet = FL(0.7); @@ -140,13 +140,13 @@ /* p->noiseGain = 0.2f; */ /* Arguemnts; suggested values? */ /* p->vibrGain = 0.1f; */ { - int relestim = (int)(csound->ekr * FL(0.1)); + int relestim = (int)(CS_EKR * FL(0.1)); /* 1/10th second decay extention */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; } - p->kloop = (int) ((int32) (p->h.insdshead->offtim * csound->ekr) - - (int32) (csound->ekr * *p->attack)); + p->kloop = (int) ((int32) (p->h.insdshead->offtim * CS_EKR) + - (int32) (CS_EKR * *p->attack)); #ifdef BETA csound->Message(csound, "offtim=%f kloop=%d\n", p->h.insdshead->offtim, p->kloop); @@ -160,7 +160,9 @@ int clarin(CSOUND *csound, CLARIN *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT nGain = *p->noiseGain; int v_len = (int)p->vibr->flen; @@ -169,73 +171,77 @@ MYFLT vTime = p->v_time; if (p->envelope.rate==FL(0.0)) { - p->envelope.rate = amp /(*p->attack*csound->esr); + p->envelope.rate = amp /(*p->attack*CS_ESR); p->envelope.value = p->envelope.target = FL(0.55) + amp*FL(0.30); } p->outputGain = amp + FL(0.001); DLineL_setDelay(&p->delayLine, /* length - approx filter delay */ - (csound->esr/ *p->frequency) * FL(0.5) - FL(1.5)); + (CS_ESR/ *p->frequency) * FL(0.5) - FL(1.5)); p->v_rate = *p->vibFreq * p->vibr->flen * csound->onedsr; /* Check to see if into decay yet */ if (p->kloop>0 && p->h.insdshead->relesing) p->kloop=1; if ((--p->kloop) == 0) { p->envelope.state = 1; /* Start change */ - p->envelope.rate = p->envelope.value / (*p->dettack * csound->esr); + p->envelope.rate = p->envelope.value / (*p->dettack * CS_ESR); p->envelope.target = FL(0.0); #ifdef BETA csound->Message(csound, "Set off phase time = %f Breath v,r = %f, %f\n", - (MYFLT) csound->kcounter * csound->onedkr, + (MYFLT) CS_KCNT * CS_ONEDKR, p->envelope.value, p->envelope.rate); #endif } + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset;nenvelope); + breathPressure += breathPressure * nGain * Noise_tick(csound,&p->noise); + /* Tick on vibrato table */ + vTime += p->v_rate; /* Update current time */ + while (vTime >= v_len) /* Check for end of sound */ + vTime -= v_len; /* loop back to beginning */ + while (vTime < FL(0.0)) /* Check for end of sound */ + vTime += v_len; /* loop back to beginning */ - for (n=0;nenvelope); - breathPressure += breathPressure * nGain * Noise_tick(csound,&p->noise); - /* Tick on vibrato table */ - vTime += p->v_rate; /* Update current time */ - while (vTime >= v_len) /* Check for end of sound */ - vTime -= v_len; /* loop back to beginning */ - while (vTime < FL(0.0)) /* Check for end of sound */ - vTime += v_len; /* loop back to beginning */ - - temp_time = vTime; + temp_time = vTime; #ifdef have_phase - if (p->v_phaseOffset != FL(0.0)) { - temp_time += p->v_phaseOffset; /* Add phase offset */ - while (temp_time >= v_len) /* Check for end of sound */ - temp_time -= v_len; /* loop back to beginning */ - while (temp_time < FL(0.0)) /* Check for end of sound */ - temp_time += v_len; /* loop back to beginning */ - } + if (p->v_phaseOffset != FL(0.0)) { + temp_time += p->v_phaseOffset; /* Add phase offset */ + while (temp_time >= v_len) /* Check for end of sound */ + temp_time -= v_len; /* loop back to beginning */ + while (temp_time < FL(0.0)) /* Check for end of sound */ + temp_time += v_len; /* loop back to beginning */ + } #endif - temp = (int32) temp_time; /* Integer part of time address */ - /* fractional part of time address */ - alpha = temp_time - (MYFLT)temp; - v_lastOutput = v_data[temp]; /* Do linear interpolation */ - /* same as alpha*data[temp+1] + (1-alpha)data[temp] */ - v_lastOutput += (alpha * (v_data[temp+1] - v_lastOutput)); - /* End of vibrato tick */ - breathPressure += breathPressure * vibGain * v_lastOutput; - pressureDiff = OneZero_tick(&p->filter, /* differential pressure */ - DLineL_lastOut(&p->delayLine)); - pressureDiff = (-FL(0.95)*pressureDiff) - breathPressure; - /* of reflected and mouth */ - nextsamp = pressureDiff * ReedTabl_LookUp(&p->reedTable,pressureDiff); - nextsamp = breathPressure + nextsamp; - /* perform scattering in economical way */ - lastOutput = DLineL_tick(&p->delayLine, nextsamp); - lastOutput *= p->outputGain; - ar[n] = lastOutput*AMP_SCALE; + temp = (int32) temp_time; /* Integer part of time address */ + /* fractional part of time address */ + alpha = temp_time - (MYFLT)temp; + v_lastOutput = v_data[temp]; /* Do linear interpolation */ + /* same as alpha*data[temp+1] + (1-alpha)data[temp] */ + v_lastOutput += (alpha * (v_data[temp+1] - v_lastOutput)); + /* End of vibrato tick */ + breathPressure += breathPressure * vibGain * v_lastOutput; + pressureDiff = OneZero_tick(&p->filter, /* differential pressure */ + DLineL_lastOut(&p->delayLine)); + pressureDiff = (-FL(0.95)*pressureDiff) - breathPressure; + /* of reflected and mouth */ + nextsamp = pressureDiff * ReedTabl_LookUp(&p->reedTable,pressureDiff); + nextsamp = breathPressure + nextsamp; + /* perform scattering in economical way */ + lastOutput = DLineL_tick(&p->delayLine, nextsamp); + lastOutput *= p->outputGain; + ar[n] = lastOutput*AMP_SCALE; } p->v_time = vTime; @@ -279,19 +285,19 @@ FUNC *ftp; int32 length; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) p->vibr = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp; else { /* Expect sine wave */ return csound->InitError(csound, Str("No table for Flute")); } if (*p->lowestFreq>=FL(0.0)) { /* Skip initialisation?? */ if (*p->lowestFreq!=FL(0.0)) - length = (int32) (csound->esr / *p->lowestFreq + FL(1.0)); + length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0)); else if (*p->frequency!=FL(0.0)) - length = (int32) (csound->esr / *p->frequency + FL(1.0)); + length = (int32) (CS_ESR / *p->frequency + FL(1.0)); else { csound->Warning(csound, Str("No base frequency for flute " "-- assumed to be 50Hz\n")); - length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } make_DLineL(csound, &p->boreDelay, length); length = length >> 1; /* ??? really; yes from later version */ @@ -323,8 +329,8 @@ p->maxPress = FL(2.3) / FL(0.8); p->outputGain = FL(1.001); ADSR_keyOn(&p->adsr); - p->kloop = (MYFLT)((int)(p->h.insdshead->offtim*csound->ekr - - csound->ekr*(*p->dettack))); + p->kloop = (MYFLT)((int)(p->h.insdshead->offtim*CS_EKR - + CS_EKR*(*p->dettack))); p->lastFreq = FL(0.0); p->lastJet = -FL(1.0); @@ -337,7 +343,9 @@ int flute(CSOUND *csound, FLUTE *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT temp; int v_len = (int)p->vibr->flen; @@ -361,27 +369,32 @@ /* freq = (2/3)*p->frequency as we're overblowing here */ /* but 1/(2/3) is 1.5 so multiply for speed */ /* Length - approx. filter delay */ - temp = FL(1.5)* csound->esr / p->lastFreq - FL(2.0); + temp = FL(1.5)* CS_ESR / p->lastFreq - FL(2.0); DLineL_setDelay(&p->boreDelay, temp); /* Length of bore tube */ DLineL_setDelay(&p->jetDelay, temp * p->lastJet); /* jet delay shorter */ } else if (*p->jetRatio != p->lastJet) { /* Freq same but jet changed */ p->lastJet = *p->jetRatio; /* Length - approx. filter delay */ - temp = FL(1.5)* csound->esr / p->lastFreq - FL(2.0); + temp = FL(1.5)* CS_ESR / p->lastFreq - FL(2.0); DLineL_setDelay(&p->jetDelay, temp * p->lastJet); /* jet delay shorter */ } /* End SetFreq */ if (p->kloop>FL(0.0) && p->h.insdshead->relesing) p->kloop=FL(1.0); if ((--p->kloop) == 0) { - p->adsr.releaseRate = p->adsr.value / (*p->dettack * csound->esr); + p->adsr.releaseRate = p->adsr.value / (*p->dettack * CS_ESR); p->adsr.target = FL(0.0); p->adsr.rate = p->adsr.releaseRate; p->adsr.state = RELEASE; } noisegain = *p->noiseGain; jetRefl = *p->jetRefl; endRefl = *p->endRefl; - for (n=0;namp)*AMP_RSCALE; /* Normalise */ - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) p->vibr = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp; else { /* Expect sine wave */ return csound->InitError(csound, Str("No table for wgbow vibrato")); } if (*p->lowestFreq>=FL(0.0)) { /* If no init skip */ if (*p->lowestFreq!=FL(0.0)) - length = (int32) (csound->esr / *p->lowestFreq + FL(1.0)); + length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0)); else if (*p->frequency!=FL(0.0)) - length = (int32) (csound->esr / *p->frequency + FL(1.0)); + length = (int32) (CS_ESR / *p->frequency + FL(1.0)); else { csound->Warning(csound, Str("unknown lowest frequency for bowed string " "-- assuming 50Hz\n")); - length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } make_DLineL(csound, &p->neckDelay, length); length = length >> 1; /* Unsure about this; seems correct in later code */ @@ -534,7 +547,9 @@ int bowed(CSOUND *csound, BOWED *p) { MYFLT *ar = p->ar; - int n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT maxVel; int freq_changed = 0; @@ -551,7 +566,7 @@ if (p->lastfreq != *p->frequency) { /* delay - approx. filter delay */ p->lastfreq = *p->frequency; - p->baseDelay = csound->esr / p->lastfreq - FL(4.0); + p->baseDelay = CS_ESR / p->lastfreq - FL(4.0); freq_changed = 1; } if (p->lastbeta != *p->betaRatio || @@ -571,7 +586,12 @@ p->adsr.state = RELEASE; } - for (n=0;ncoeff = (FL(1.0)-p->alpha)/(FL(1.0)+p->alpha); /* coefficient for all pass*/ return 0; err1: - return csound->PerfError(csound, Str("DlineA not initialised")); + csound->ErrorMsg(csound, Str("DlineA not initialised")); + return NOTOK; } MYFLT DLineA_tick(DLineA *p, MYFLT sample) /* Take sample, yield sample */ @@ -752,20 +773,20 @@ FUNC *ftp; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) p->vibr = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) p->vibr = ftp; else { /* Expect sine wave */ return csound->InitError(csound, Str("No table for Brass")); } p->frq = *p->frequency; /* Remember */ if (*p->lowestFreq>=FL(0.0)) { if (*p->lowestFreq!=FL(0.0)) - p->length = (int32) (csound->esr / *p->lowestFreq + FL(1.0)); + p->length = (int32) (CS_ESR / *p->lowestFreq + FL(1.0)); else if (p->frq!=FL(0.0)) - p->length = (int32) (csound->esr / p->frq + FL(1.0)); + p->length = (int32) (CS_ESR / p->frq + FL(1.0)); else { csound->Warning(csound, Str("No base frequency for brass " "-- assumed to be 50Hz\n")); - p->length = (int32) (csound->esr / FL(50.0) + FL(1.0)); + p->length = (int32) (CS_ESR / FL(50.0) + FL(1.0)); } make_DLineA(csound, &p->delayLine, p->length); make_LipFilt(&p->lipFilter); @@ -780,7 +801,7 @@ ADSR_keyOn(&p->adsr); /* Set frequency */ - /* p->slideTarget = (csound->esr / p->frq * FL(2.0)) + 3.0f; */ + /* p->slideTarget = (CS_ESR / p->frq * FL(2.0)) + 3.0f; */ /* fudge correction for filter delays */ /* DLineA_setDelay(&p->delayLine, p->slideTarget);*/ /* we'll play a harmonic */ @@ -793,13 +814,13 @@ /* p->lipTarget * (MYFLT)pow(4.0, (2.0* p->lipT) -1.0)); */ { - int relestim = (int)(csound->ekr * FL(0.1)); + int relestim = (int)(CS_EKR * FL(0.1)); /* 1/10th second decay extention */ if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = relestim; } - p->kloop = (int) ((int32) (p->h.insdshead->offtim * csound->ekr) - - (int32) (csound->ekr * *p->dettack)); + p->kloop = (int) ((int32) (p->h.insdshead->offtim * CS_EKR) + - (int32) (CS_EKR * *p->dettack)); } return OK; } @@ -807,7 +828,9 @@ int brass(CSOUND *csound, BRASS *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT maxPressure = p->maxPressure = amp; int v_len = (int)p->vibr->flen; @@ -825,7 +848,7 @@ } if (p->frq != *p->frequency) { /* Set frequency if changed */ p->frq = *p->frequency; - p->slideTarget = (csound->esr / p->frq * FL(2.0)) + FL(3.0); + p->slideTarget = (CS_ESR / p->frq * FL(2.0)) + FL(3.0); /* fudge correction for filter delays */ /* we'll play a harmonic */ if (DLineA_setDelay(csound, &p->delayLine, p->slideTarget)) return OK; @@ -838,7 +861,12 @@ p->lipTarget * (MYFLT)pow(4.0,(2.0* p->lipT) -1.0)); } - for (n=0;nWarning(csound, Str("negative times not allowed!!, correcting\n")); - a->attackRate = FL(1.0) /(-aTime*csound->esr); + a->attackRate = FL(1.0) /(-aTime*CS_ESR); } - else a->attackRate = FL(1.0) / (aTime*csound->esr); + else a->attackRate = FL(1.0) / (aTime*CS_ESR); } void ADSR_setDecayTime(CSOUND *csound, ADSR *a, MYFLT aTime) @@ -365,9 +365,9 @@ if (UNLIKELY(aTime < FL(0.0))) { csound->Warning(csound, Str("negative times not allowed!!, correcting\n")); - a->decayRate = FL(1.0) /(-aTime*csound->esr); + a->decayRate = FL(1.0) /(-aTime*CS_ESR); } - else a->decayRate = FL(1.0) / (aTime*csound->esr); + else a->decayRate = FL(1.0) / (aTime*CS_ESR); } void ADSR_setReleaseTime(CSOUND *csound, ADSR *a, MYFLT aTime) @@ -375,9 +375,9 @@ if (UNLIKELY(aTime < FL(0.0))) { csound->Warning(csound, Str("negative times not allowed!!, correcting\n")); - a->releaseRate = FL(1.0) /(-aTime*csound->esr); + a->releaseRate = FL(1.0) /(-aTime*CS_ESR); } - else a->releaseRate = FL(1.0) / (aTime*csound->esr); + else a->releaseRate = FL(1.0) / (aTime*CS_ESR); } void ADSR_setAllTimes(CSOUND *csound, ADSR *a, MYFLT attTime, MYFLT decTime, diff -Nru csound-5.17.11~dfsg/Opcodes/pitch.c csound-6.02~dfsg/Opcodes/pitch.c --- csound-5.17.11~dfsg/Opcodes/pitch.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pitch.c 2014-01-07 16:54:20.000000000 +0000 @@ -2,7 +2,7 @@ /* pitch.c: - Copyright (C) 1999 John ffitch, Istvan Varga, Peter Neubäcker, + Copyright (C) 1999 John ffitch, Istvan Varga, Peter Neubäcker, rasmus ekman, Phil Burk This file is part of Csound. @@ -73,7 +73,7 @@ /* End of rms */ /* Initialise spectrum */ /* for mac roundoff */ - p->timcount = (int)(csound->ekr * *p->iprd + FL(0.001)); + p->timcount = (int)(CS_EKR * *p->iprd + FL(0.001)); nocts = (int)*p->iocts; if (UNLIKELY(nocts<=0)) nocts = 6; nfreqs = (int)*p->ifrqs; if (UNLIKELY(nfreqs<=0)) nfreqs = 12; ncoefs = nocts * nfreqs; @@ -100,7 +100,7 @@ p->nfreqs = nfreqs; p->curq = Q; p->ncoefs = ncoefs; - dwnp->srate = csound->esr; + dwnp->srate = CS_ESR; hicps = dwnp->srate * 0.375; /* top freq is 3/4 pi/2 ... */ oct = log(hicps / ONEPT) / LOGTWO; /* octcps() (see aops.c) */ dwnp->looct = (MYFLT)(oct - nocts); /* true oct val of lowest frq */ @@ -249,7 +249,10 @@ double c1 = p->c1, c2 = p->c2; MYFLT a, b, *dftp, SIG, yt1, yt2; - int nocts, n, nsmps = csound->ksmps, winlen; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int nocts, winlen; DOWNDAT *downp = &p->downsig; OCTDAT *octp; SPECDAT *specp; @@ -258,7 +261,12 @@ /* RMS */ q = p->prvq; asig = p->asig; - for (n=0; ne0dbfs; /* Normalise.... */ q = c1 * as * as + c2 * q; SIG = as; /* for each source sample: */ @@ -273,7 +281,7 @@ if (UNLIKELY(curp >= octp->endp)) curp = octp->begp; /* & modulo the pointer */ octp->curp = curp; - if (UNLIKELY(!(--nocts))) break; /* if lastoct, break */ + if (UNLIKELY(!(--nocts))) break; /* if lastoct, break */ coefp = bicoefs; ytp = octp->feedback; for (nfilt = 3; nfilt--; ) { /* apply triple biquad: */ yt2 = *ytp++; yt1 = *ytp--; /* get prev feedback */ @@ -333,7 +341,7 @@ *dftp++ = c; /* store in out spectrum */ } } - specp->ktimstamp = csound->kcounter; /* time-stamp the output */ + specp->ktimstamp = CS_KCNT; /* time-stamp the output */ nxt: /* specptrk */ @@ -420,8 +428,7 @@ kval = realbin / specp->nfreqs; /* & cvt to true decoct */ if (p->playing == STARTING) { /* STARTING mode: */ - if ((absdiff = kval - p->kvalsav) < FL(0.0)) - absdiff = -absdiff; + absdiff = FABS(kval - p->kvalsav);// < FL(0.0)) absdiff = -absdiff; confirms = (int)(absdiff * p->confact); /* get interval dependency */ if (UNLIKELY(p->jmpcount < confirms)) { p->jmpcount += 1; /* if not enough confirms, */ @@ -433,8 +440,7 @@ p->kinc = FL(0.0); } } else { /* PLAYING mode: */ - if ((absdiff = kval - p->kval) < FL(0.0)) - absdiff = -absdiff; + absdiff = FABS(kval - p->kval); confirms = (int)(absdiff * p->confact); /* get interval dependency */ if (p->jmpcount < confirms) { p->jmpcount += 1; /* if not enough confirms, */ @@ -452,7 +458,8 @@ *p->kamp = p->kavl * FL(4.0); return OK; err1: - return csound->PerfError(csound, Str("pitch: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pitch: not initialised")); } /* Multiply and accumulate opcodes */ @@ -460,7 +467,7 @@ int macset(CSOUND *csound, SUM *p) { if (UNLIKELY((((int)p->INOCOUNT)&1)==1)) { - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("Must have even number of arguments in mac\n")); } return OK; @@ -468,9 +475,18 @@ int maca(CSOUND *csound, SUM *p) { - int nsmps=csound->ksmps, count=(int) p->INOCOUNT, j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; + int count=(int) p->INOCOUNT, j; MYFLT *ar = p->ar, **args = p->argums; - for (k=0; kksmps, count=(int) p->INOCOUNT, j, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; + int count=(int) p->INOCOUNT, j; MYFLT *ar = p->ar, **args = p->argums; - for (k=0; kindex); + if (index<0 || index>3) + return csound->PerfError(csound, p->h.insdshead, + Str("scratchpad index out of range")); + *p->val = p->h.insdshead->scratchpad[index]; + return OK; +} + +int scratchwrite(CSOUND *csound, SCRATCHPAD *p) +{ + int index = MYFLT2LRND(*p->index); + if (index<0 || index>3) + return csound->PerfError(csound, p->h.insdshead, + Str("scratchpad index out of range")); + p->h.insdshead->scratchpad[index] = *p->val; + return OK; +} + + /* ************************************************************ */ -/* Opcodes from Peter Neubäcker */ +/* Opcodes from Peter Neubäcker */ /* ************************************************************ */ int adsyntset(CSOUND *csound, ADSYNT *p) { FUNC *ftp; - int count; + unsigned int count; int32 *lphs; p->inerr = 0; @@ -579,12 +624,12 @@ return csound->InitError(csound, Str("adsynt: wavetable not found!")); } - count = (int)*p->icnt; + count = (unsigned int)*p->icnt; if (UNLIKELY(count < 1)) count = 1; p->count = count; - if (LIKELY((ftp = csound->FTFind(csound, p->ifreqtbl)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifreqtbl)) != NULL)) { p->freqtp = ftp; } else { @@ -597,7 +642,7 @@ "adsynt: partial count is greater than freqtable size!")); } - if (LIKELY((ftp = csound->FTFind(csound, p->iamptbl)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iamptbl)) != NULL)) { p->amptp = ftp; } else { @@ -625,6 +670,7 @@ *lphs++ = ((int32) (*p->iphs * FMAXLEN)) & PHMASK; } while (--count); } + return OK; } @@ -632,13 +678,17 @@ { FUNC *ftp, *freqtp, *amptp; MYFLT *ar, *ftbl, *freqtbl, *amptbl; - MYFLT amp0, amp, cps0, cps; + MYFLT amp0, amp, cps0, cps; int32 phs, inc, lobits; - int32 *lphs; - int n, nsmps = csound->ksmps, c, count; + int32 *lphs; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int c, count; if (UNLIKELY(p->inerr)) { - return csound->PerfError(csound, Str("adsynt: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("adsynt: not initialised")); } ftp = p->ftp; ftbl = ftp->ftable; @@ -655,13 +705,14 @@ ar = p->sr; memset(ar, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; for (c=0; csicvt); phs = lphs[c]; - for (n=0; n> lobits)) * amp; phs += inc; phs &= PHMASK; @@ -676,7 +727,7 @@ FUNC *ftp; int octcnt, i; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { p->ftp = ftp; if (UNLIKELY(*p->ioctcnt < 2)) octcnt = 3; @@ -691,7 +742,7 @@ } } else p->ftp = NULL; - if (LIKELY((ftp = csound->FTFind(csound, p->imixtbl)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->imixtbl)) != NULL)) { p->mixtp = ftp; } else p->mixtp = NULL; @@ -704,17 +755,20 @@ MYFLT fract, v1, amp0, amp, *ar, *ftab, *mtab; int32 phs, inc, lobits; int32 phases[10]; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT tonal, bright, freq, ampscl; int octcnt = p->octcnt; MYFLT octstart, octoffs, octbase; int octshift, i, mtablen; - MYFLT hesr = csound->esr / FL(2.0); + MYFLT hesr = CS_ESR / FL(2.0); ftp = p->ftp; mixtp = p->mixtp; if (UNLIKELY(ftp==NULL || mixtp==NULL)) { - return csound->PerfError(csound, Str("hsboscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("hsboscil: not initialised")); } tonal = *p->ktona; @@ -748,6 +802,7 @@ lobits = ftp->lobits; ar = p->sr; memset(ar, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; for (i=0; i hesr)) amp = FL(0.0); inc = (int32)(freq * csound->sicvt); - for (n=0; nftable + (phs >> lobits); v1 = *ftab++; @@ -774,7 +829,9 @@ int pitchamdfset(CSOUND *csound, PITCHAMDF *p) { MYFLT srate, downs; - int32 size, minperi, maxperi, downsamp, upsamp, msize, bufsize, interval; + int32 size, minperi, maxperi, downsamp, upsamp, msize, bufsize; + uint32_t interval; + uint32_t nsmps = CS_KSMPS; p->inerr = 0; @@ -782,13 +839,13 @@ if (downs < (-FL(1.9))) { upsamp = (int)MYFLT2LONG((-downs)); downsamp = 0; - srate = csound->esr * (MYFLT)upsamp; + srate = CS_ESR * (MYFLT)upsamp; } else { downsamp = (int)MYFLT2LONG(downs); if (UNLIKELY(downsamp < 1)) downsamp = 1; - srate = csound->esr / (MYFLT)downsamp; + srate = CS_ESR / (MYFLT)downsamp; upsamp = 0; } @@ -803,12 +860,12 @@ if (*p->iexcps < 1) interval = maxperi; else - interval = (int32)(srate / *p->iexcps); - if (interval < csound->ksmps) { + interval = (uint32_t)(srate / *p->iexcps); + if (interval < nsmps) { if (downsamp) - interval = csound->ksmps / downsamp; + interval = nsmps / downsamp; else - interval = csound->ksmps * upsamp; + interval = nsmps * upsamp; } size = maxperi + interval; @@ -935,7 +992,7 @@ MYFLT newval, delta; int32 readp = p->readp; int32 interval = size - maxperi; - int nsmps = csound->ksmps; + int nsmps = CS_KSMPS; int i; int32 i1, i2; MYFLT val, rms; @@ -943,7 +1000,8 @@ MYFLT acc, accmin, diff; if (UNLIKELY(p->inerr)) { - return csound->PerfError(csound, Str("pitchamdf: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pitchamdf: not initialised")); } if (upsamp) { @@ -1123,7 +1181,8 @@ int index = (int)(*p->kindx); if (UNLIKELY(curphs == NULL)) { - return csound->PerfError(csound, Str("phasorbnk: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("phasorbnk: not initialised")); } if (UNLIKELY(index<0 || index>=size)) { @@ -1142,7 +1201,9 @@ int phsorbnk(CSOUND *csound, PHSORBNK *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *rs; double phase, incr; double *curphs = (double*)p->curphs.auxp; @@ -1150,7 +1211,8 @@ int index = (int)(*p->kindx); if (UNLIKELY(curphs == NULL)) { - return csound->PerfError(csound, Str("phasorbnk: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("phasorbnk: not initialised")); } if (UNLIKELY(index<0 || index>=size)) { @@ -1160,9 +1222,14 @@ rs = p->sr; phase = curphs[index]; + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->XINCODE) { MYFLT *cps = p->xcps; - for (n=0; nonedsr); rs[n] = (MYFLT)phase; phase += incr; @@ -1174,7 +1241,7 @@ } else { incr = (double)(*p->xcps * csound->onedsr); - for (n=0; n= 1.0)) @@ -1241,10 +1308,16 @@ { MYFLT *aout, *ain; double c0, c1, c2, c3, c4, c5, c6, nxtin, nxtout; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; aout = p->aout; ain = p->xin; - + if (UNLIKELY(offset)) memset(aout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&aout[nsmps], '\0', early*sizeof(MYFLT)); + } if (*p->imethod == GARDNER_PINK) { /* Gardner method (default) */ GardnerPink_perf(csound,p); } @@ -1253,7 +1326,7 @@ /* Get filter states */ c0 = p->b0; c1 = p->b1; c2 = p->b2; c3 = p->b3; c4 = p->b4; c5 = p->b5; c6 = p->b6; - for (n=0;nb0; c1 = p->b1; c2 = p->b2; - for (n=0;nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS - p->h.insdshead->ksmps_no_end; aout = p->aout; amp = p->xin; @@ -1404,11 +1478,11 @@ rows = &(p->grd_Rows[0]); randSeed = p->randSeed; - for (n=0; nimethod); p->meth = meth; - p->arg = *p->iarg; + p->arg = FABS(*p->iarg); p->lim = *p->limit; - if (p->arg < FL(0.0)) p->arg = - p->arg; switch (meth) { case 0: /* Bram de Jong method */ if (p->arg > FL(1.0) || p->arg < FL(0.0)) p->arg = FL(0.999); @@ -1493,14 +1566,21 @@ int clip(CSOUND *csound, CLIP *p) { MYFLT *aout = p->aout, *ain = p->ain; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT a = p->arg, k1 = p->k1, k2 = p->k2; MYFLT limit = p->lim; MYFLT rlim = FL(1.0)/limit; + if (UNLIKELY(offset)) memset(aout, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&aout[nsmps], '\0', early*sizeof(MYFLT)); + } switch (p->meth) { case 0: /* Soft clip with division */ - for (n=0;n=FL(0.0)) { if (UNLIKELY(x>limit)) x = k2; @@ -1517,7 +1597,7 @@ } return OK; case 1: - for (n=0;n=limit)) x = limit; @@ -1529,7 +1609,7 @@ } return OK; case 2: - for (n=0;n=limit)) x = limit; @@ -1550,23 +1630,30 @@ int impulse_set(CSOUND *csound, IMPULSE *p) { - p->next = (int)MYFLT2LONG(*p->offset * csound->esr); + p->next = (unsigned int)MYFLT2LONG(*p->offset * CS_ESR); return OK; } int impulse(CSOUND *csound, IMPULSE *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int next = p->next; MYFLT *ar = p->ar; if (next<0) next = -next; - if (UNLIKELY(next < csound->ksmps)) { /* Impulse in this frame */ + if (UNLIKELY(next < (int32)nsmps)) { /* Impulse in this frame */ MYFLT frq = *p->freq; /* Freq at k-rate */ int sfreq; /* Converted to samples */ if (frq == FL(0.0)) sfreq = INT_MAX; /* Zero means infinite */ else if (frq < FL(0.0)) sfreq = -(int)frq; /* Negative cnts in sample */ - else sfreq = (int)(frq*csound->esr); /* Normal case */ - for (n=0;namp; next = sfreq - 1; /* Note can be less than k-rate */ @@ -1615,11 +1702,11 @@ MYFLT dur = **argp++; MYFLT alpha = **argp++; MYFLT nxtval = **argp++; - MYFLT d = dur * csound->esr; + MYFLT d = dur * CS_ESR; if ((segp->cnt = (int32)MYFLT2LONG(d)) < 0) segp->cnt = 0; else - segp->cnt = (int32)(dur * csound->ekr); + segp->cnt = (int32)(dur * CS_EKR); segp->nxtpt = nxtval; segp->val = val; if (alpha == FL(0.0)) { @@ -1669,11 +1756,11 @@ MYFLT d; dur -= totdur; totdur += dur; - d = dur * csound->esr; + d = dur * CS_ESR; if ((segp->cnt = (int32)MYFLT2LONG(d)) < 0) segp->cnt = 0; else - segp->cnt = (int32)(dur * csound->ekr); + segp->cnt = (int32)(dur * CS_EKR); segp->nxtpt = nxtval; segp->val = val; if (alpha == FL(0.0)) { @@ -1696,7 +1783,8 @@ { *p->rslt = p->curval; /* put the cur value */ if (UNLIKELY(p->auxch.auxp==NULL)) { /* RWD fix */ - csound->Die(csound, Str("Error: transeg not initialised (krate)\n")); + csound->PerfError(csound,p->h.insdshead, + Str("Error: transeg not initialised (krate)\n")); } if (p->segsrem) { /* done if no more segs */ if (--p->curcnt <= 0) { /* if done cur segment */ @@ -1716,11 +1804,11 @@ p->curx = FL(0.0); } if (p->alpha == FL(0.0)) - p->curval += p->curinc*csound->ksmps; /* advance the cur val */ + p->curval += p->curinc*CS_KSMPS; /* advance the cur val */ else p->curval = p->cursegp->val + p->curinc * (FL(1.0) - EXP(p->curx)); - p->curx += (MYFLT)csound->ksmps*p->alpha; + p->curx += (MYFLT)CS_KSMPS*p->alpha; } return OK; } @@ -1728,10 +1816,18 @@ int trnseg(CSOUND *csound, TRANSEG *p) { MYFLT val, *rs = p->rslt; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; NSEG *segp = p->cursegp; if (UNLIKELY(p->auxch.auxp==NULL)) { - return csound->PerfError(csound, Str("transeg: not initialised (arate)\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("transeg: not initialised (arate)\n")); + } + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); } val = p->curval; /* sav the cur value */ if (p->segsrem) { /* if no more segs putk */ @@ -1753,13 +1849,13 @@ p->curval = val; } if (p->alpha == FL(0.0)) { - for (n=0; ncurinc; } } else { - for (n=0; ncurx += p->alpha; val = segp->val + p->curinc * @@ -1769,7 +1865,7 @@ p->curval = val; return OK; putk: - for (n=0; nesr; + MYFLT d = dur * CS_ESR; if ((segp->cnt = (int32)(d + FL(0.5))) < 0) segp->cnt = 0; else - segp->cnt = (int32)(dur * csound->ekr); + segp->cnt = (int32)(dur * CS_EKR); segp->nxtpt = nxtval; segp->val = val; if (alpha == FL(0.0)) { segp->c1 = (nxtval-val)/d; + //printf("alpha zero val=%f c1=%f\n", segp->val, segp->c1); } else { p->lastalpha = alpha; @@ -1832,6 +1929,14 @@ p->xtra = relestim; if (relestim > p->h.insdshead->xtratim) p->h.insdshead->xtratim = (int)relestim; + /* { */ + /* int i; */ + /* int nseg = p->INOCOUNT / 3; */ + /* NSEG *segp = p->cursegp; */ + /* for (i=0; irslt = p->curval; /* put the cur value */ if (UNLIKELY(p->auxch.auxp==NULL)) { /* RWD fix */ - csound->Die(csound, Str("Error: transeg not initialised (krate)\n")); + csound->PerfError(csound,p->h.insdshead, + Str("Error: transeg not initialised (krate)\n")); } if (p->segsrem) { /* done if no more segs */ - NSEG *segp; + NSEG *segp; if (p->h.insdshead->relesing && p->segsrem > 1) { + //printf("releasing\n"); while (p->segsrem > 1) { /* reles flag new: */ segp = ++p->cursegp; /* go to last segment */ p->segsrem--; @@ -1851,6 +1958,8 @@ segp->cnt = p->xtra>=0 ? p->xtra : p->h.insdshead->xtratim; if (segp->alpha == FL(0.0)) { segp->c1 = (p->finalval-p->curval)/segp->cnt; + //printf("finalval = %f curval = %f, cnt = %d c1 = %f\n", + // p->finalval, p->curval, segp->cnt, segp->c1); } else { /* this is very wrong */ @@ -1866,20 +1975,24 @@ if (!(--p->segsrem)) return OK; /* seg Z now done all */ segp = ++p->cursegp; /* find the next */ newm: + //printf("curcnt = %d seg/cnt = %d\n", p->curcnt, segp->cnt); if (!(p->curcnt = segp->cnt)) { /* nonlen = discontin */ p->curval = segp->nxtpt; /* poslen = new slope */ + //printf("curval = %f\n", p->curval); goto chk1; } p->curinc = segp->c1; p->alpha = segp->alpha; p->curx = FL(0.0); } - if (p->alpha == FL(0.0)) - p->curval += p->curinc*csound->ksmps; /* advance the cur val */ + if (p->alpha == FL(0.0)) { + p->curval += p->curinc/**CS_KSMPS*/; /* advance the cur val */ + //printf("curval = %f\n", p->curval); + } else p->curval = p->cursegp->val + p->curinc * (FL(1.0) - EXP(p->curx)); - p->curx += (MYFLT)csound->ksmps*p->alpha; + p->curx += /* (MYFLT)CS_KSMPS* */ p->alpha; } return OK; } @@ -1887,9 +2000,17 @@ int trnsegr(CSOUND *csound, TRANSEG *p) { MYFLT val, *rs = p->rslt; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp==NULL)) { - return csound->PerfError(csound, Str("transeg: not initialised (arate)\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("transeg: not initialised (arate)\n")); + } + if (UNLIKELY(offset)) memset(rs, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&rs[nsmps], '\0', early*sizeof(MYFLT)); } val = p->curval; /* sav the cur value */ if (LIKELY(p->segsrem)) { /* if no more segs putk */ @@ -1931,14 +2052,14 @@ p->curval = val; } if (p->alpha == FL(0.0)) { - for (n=0; ncurinc; } } else { segp = p->cursegp; - for (n=0; ncurx += p->alpha; val = segp->val + p->curinc * (FL(1.0) - EXP(p->curx)); @@ -1947,7 +2068,7 @@ p->curval = val; return OK; putk: - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT beta = *p->beta; MYFLT sq1mb2 = p->sq1mb2; MYFLT lastx = p->last; @@ -1983,7 +2106,12 @@ ampmod = p->ampmod = FL(0.785)/(FL(1.0)+p->lastbeta); } - for (n=0; nksmps; - MYFLT kfcn = FL(2.0) * *p->fco * csound->onedsr; - MYFLT kp = ((-FL(2.7528)*kfcn + FL(3.0429))*kfcn + - FL(1.718))*kfcn - FL(0.9984); - MYFLT kp1 = kp+FL(1.0); - MYFLT kp1h = FL(0.5)*kp1; - /* Version using log */ - /* MYFLT kres = *p->res * (FL(2.2173) - FL(1.6519)*log(kp+FL(1.0))); */ - MYFLT kres = *p->res * (((-FL(2.7079)*kp1 + FL(10.963))*kp1 - - FL(14.934))*kp1 + FL(8.4974)); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT ay1 = p->ay1; MYFLT ay2 = p->ay2; MYFLT aout = p->aout; MYFLT *ain = p->ain; MYFLT *ar = p->ar; - double dist = (double)*p->dist; MYFLT lastin = p->lastin; - double value = 1.0+(dist*(1.5+2.0*(double)kres*(1.0-(double)kfcn))); - - for (n=0;nfco[n] : *p->fco); + res = (XINARG3 ? p->res[n] : *p->res); + dist = (double)(XINARG4 ? p->dist[n] : *p->dist); + if (fco != lfc || flag) { + lfc = fco; + kfcn = FL(2.0) * fco * csound->onedsr; + kp = ((-FL(2.7528)*kfcn + FL(3.0429))*kfcn + + FL(1.718))*kfcn - FL(0.9984); + kp1 = kp+FL(1.0); + kp1h = FL(0.5)*kp1; + flag = 1; + } + if (res != lrs || flag) { + lrs = res; + kres = res * (((-FL(2.7079)*kp1 + FL(10.963))*kp1 + - FL(14.934))*kp1 + FL(8.4974)); + flag = 1; + } + if (dist != lds || flag) { + lds = dist; + value = 1.0+(dist*(1.5+2.0*(double)kres*(1.0-(double)kfcn))); + } + flag = 0; + lastin = ain[n] - TANH(kres*aout); + ay1 = kp1h * (lastin + ax1) - kp*ay1; + ay2 = kp1h * (ay1 + ay11) - kp*ay2; + aout = kp1h * (ay2 + ay31) - kp*aout; ar[n] = TANH(aout*value); } @@ -2061,10 +2213,10 @@ int wavesetset(CSOUND *csound, BARRI *p) { if (*p->len == FL(0.0)) - p->length = 1 + (int)(p->h.insdshead->p3 * csound->esr * FL(0.5)); + p->length = 1 + (int)(p->h.insdshead->p3 * CS_ESR * FL(0.5)); else p->length = 1 + (int)*p->len; - if (UNLIKELY(p->length <= 1)) p->length = (int)csound->esr; + if (UNLIKELY(p->length <= 1)) p->length = (int)CS_ESR; csound->AuxAlloc(csound, (int32)p->length*sizeof(MYFLT), &p->auxch); p->cnt = 1; p->start = 0; @@ -2082,9 +2234,16 @@ MYFLT *out = p->ar; int index = p->end; MYFLT *insert = (MYFLT*)(p->auxch.auxp) + index; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->noinsert) goto output; - for (n=0;nstart) { p->noinsert = 1; @@ -2099,7 +2258,7 @@ p->end = index; index = p->current; insert = (MYFLT*)(p->auxch.auxp) + index; - for (n=0;nlength) { @@ -2154,9 +2313,12 @@ int maxwind = p->maxwind; int kwind = MYFLT2LONG(*p->kwind); int index = p->ind; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (UNLIKELY(p->b.auxp==NULL)) { - return csound->PerfError(csound, Str("median: not initialised (arate)\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("median: not initialised (arate)\n")); } if (UNLIKELY(kwind > maxwind)) { csound->Warning(csound, @@ -2164,7 +2326,12 @@ kwind, maxwind); kwind = maxwind; } - for (n=0; nkwind); int index = p->ind; if (UNLIKELY(p->b.auxp==NULL)) { - return csound->PerfError(csound, Str("median: not initialised (krate)\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("median: not initialised (krate)\n")); } if (UNLIKELY(kwind > maxwind)) { csound->Warning(csound, diff -Nru csound-5.17.11~dfsg/Opcodes/pitch.h csound-6.02~dfsg/Opcodes/pitch.h --- csound-5.17.11~dfsg/Opcodes/pitch.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pitch.h 2014-01-07 16:53:48.000000000 +0000 @@ -67,6 +67,12 @@ typedef struct { OPDS h; + MYFLT *val; + MYFLT *index; +} SCRATCHPAD; + +typedef struct { + OPDS h; MYFLT *ins; MYFLT *onoff; } MUTE; @@ -76,6 +82,7 @@ MYFLT *cnt; MYFLT *ins; MYFLT *opt; + MYFLT *norel; } INSTCNT; typedef struct { @@ -89,7 +96,7 @@ FUNC *ftp; FUNC *freqtp; FUNC *amptp; - int count; + unsigned int count; int inerr; AUXCH lphs; } ADSYNT; @@ -169,7 +176,7 @@ OPDS h; MYFLT *ar; MYFLT *amp, *freq, *offset; - int next; + unsigned int next; } IMPULSE; typedef struct { @@ -268,12 +275,16 @@ int clockon(CSOUND *, CLOCK *p); int clockread(CSOUND *, CLKRD *p); int clockset(CSOUND *, CLOCK *p); +int scratchread(CSOUND *, SCRATCHPAD *p); +int scratchwrite(CSOUND *, SCRATCHPAD *p); int cpuperc(CSOUND *, CPU_PERC *p); +int cpuperc_S(CSOUND *, CPU_PERC *p); int hsboscil(CSOUND *, HSBOSC *p); int hsboscset(CSOUND *, HSBOSC *p); int impulse(CSOUND *, IMPULSE *p); int impulse_set(CSOUND *, IMPULSE *p); int instcount(CSOUND *, INSTCNT *p); +int instcount_S(CSOUND *, INSTCNT *p); int totalcount(CSOUND *, INSTCNT *p); int kphsorbnk(CSOUND *, PHSORBNK *p); int ktrnseg(CSOUND *, TRANSEG *p); @@ -285,6 +296,8 @@ int macset(CSOUND *, SUM *p); int maxalloc(CSOUND *, CPU_PERC *p); int mute_inst(CSOUND *, MUTE *p); +int maxalloc_S(CSOUND *, CPU_PERC *p); +int mute_inst_S(CSOUND *, MUTE *p); int pfun(CSOUND *, PFUN *p); int pfunk_init(CSOUND *, PFUNK *p); int pfunk(CSOUND *, PFUNK *p); diff -Nru csound-5.17.11~dfsg/Opcodes/pitch0.c csound-6.02~dfsg/Opcodes/pitch0.c --- csound-5.17.11~dfsg/Opcodes/pitch0.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pitch0.c 2014-01-07 16:53:48.000000000 +0000 @@ -31,8 +31,14 @@ int mute_inst(CSOUND *csound, MUTE *p) { - int n = (int) csound->strarg2insno(csound, p->ins, p->XSTRCODE); + int n; int onoff = (*p->onoff == FL(0.0) ? 0 : 1); + + if(ISSTRCOD(*p->ins)) { + char *ss = get_arg_string(csound,*p->ins); + n = csound->strarg2insno(csound,ss,1); + } else n = *p->ins; + if (UNLIKELY(n < 1)) return NOTOK; if (onoff==0) { csound->Warning(csound, Str("Muting new instances of instr %d\n"), n); @@ -40,31 +46,81 @@ else { csound->Warning(csound, Str("Allowing instrument %d to start\n"), n); } - csound->instrtxtp[n]->muted = onoff; + csound->engineState.instrtxtp[n]->muted = onoff; + return OK; +} +int mute_inst_S(CSOUND *csound, MUTE *p) +{ + int n; + int onoff = (*p->onoff == FL(0.0) ? 0 : 1); + + n = csound->strarg2insno(csound, ((STRINGDAT *)p->ins)->data, 1); + + if (UNLIKELY(n < 1)) return NOTOK; + if (onoff==0) { + csound->Warning(csound, Str("Muting new instances of instr %d\n"), n); + } + else { + csound->Warning(csound, Str("Allowing instrument %d to start\n"), n); + } + csound->engineState.instrtxtp[n]->muted = onoff; return OK; } int instcount(CSOUND *csound, INSTCNT *p) { int n; - if (p->XSTRCODE) - n = (int) csound->strarg2insno(csound, p->ins, p->XSTRCODE); - else - n = *p->ins; - if (n<0 || n > csound->maxinsno || csound->instrtxtp[n] == NULL) + + if(ISSTRCOD(*p->ins)) { + char *ss = get_arg_string(csound,*p->ins); + n = csound->strarg2insno(csound,ss,1); + } else n = *p->ins; + + if (n<0 || n > csound->engineState.maxinsno || + csound->engineState.instrtxtp[n] == NULL) *p->cnt = FL(0.0); else if (n==0) { /* Count all instruments */ int tot = 1; - for (n=1; nmaxinsno; n++) - if (csound->instrtxtp[n]) /* If it exists */ - tot += ((*p->opt) ? csound->instrtxtp[n]->instcnt : - csound->instrtxtp[n]->active); + for (n=1; nengineState.maxinsno; n++) + if (csound->engineState.instrtxtp[n]) /* If it exists */ + tot += ((*p->opt) ? csound->engineState.instrtxtp[n]->instcnt : + csound->engineState.instrtxtp[n]->active); *p->cnt = (MYFLT)tot; } else { *p->cnt = ((*p->opt) ? - (MYFLT) csound->instrtxtp[n]->instcnt : - (MYFLT) csound->instrtxtp[n]->active); + (MYFLT) csound->engineState.instrtxtp[n]->instcnt : + (MYFLT) csound->engineState.instrtxtp[n]->active); + if (*p->norel) + *p->cnt -= csound->engineState.instrtxtp[n]->pending_release; + } + + return OK; +} + +int instcount_S(CSOUND *csound, INSTCNT *p) +{ + + + int n = csound->strarg2insno(csound, ((STRINGDAT *)p->ins)->data, 1); + + if (n<0 || n > csound->engineState.maxinsno || + csound->engineState.instrtxtp[n] == NULL) + *p->cnt = FL(0.0); + else if (n==0) { /* Count all instruments */ + int tot = 1; + for (n=1; nengineState.maxinsno; n++) + if (csound->engineState.instrtxtp[n]) /* If it exists */ + tot += ((*p->opt) ? csound->engineState.instrtxtp[n]->instcnt : + csound->engineState.instrtxtp[n]->active); + *p->cnt = (MYFLT)tot; + } + else { + *p->cnt = ((*p->opt) ? + (MYFLT) csound->engineState.instrtxtp[n]->instcnt : + (MYFLT) csound->engineState.instrtxtp[n]->active); + if (*p->norel) + *p->cnt -= csound->engineState.instrtxtp[n]->pending_release; } return OK; @@ -74,19 +130,52 @@ int cpuperc(CSOUND *csound, CPU_PERC *p) { - int n = (int) csound->strarg2insno(csound, p->instrnum, p->XSTRCODE); - if (n > 0 && n <= csound->maxinsno && csound->instrtxtp[n] != NULL) + int n; + + if(ISSTRCOD(*p->instrnum)) { + char *ss = get_arg_string(csound,*p->instrnum); + n = csound->strarg2insno(csound,ss,1); + } else n = *p->instrnum; + + if (n > 0 && n <= csound->engineState.maxinsno && + csound->engineState.instrtxtp[n] != NULL) + /* If instrument exists */ + csound->engineState.instrtxtp[n]->cpuload = *p->ipercent; + return OK; +} + +int cpuperc_S(CSOUND *csound, CPU_PERC *p) +{ + int n = csound->strarg2insno(csound, ((STRINGDAT *)p->instrnum)->data, 1); + if (n > 0 && n <= csound->engineState.maxinsno && + csound->engineState.instrtxtp[n] != NULL) /* If instrument exists */ - csound->instrtxtp[n]->cpuload = *p->ipercent; + csound->engineState.instrtxtp[n]->cpuload = *p->ipercent; return OK; } int maxalloc(CSOUND *csound, CPU_PERC *p) { - int n = (int) csound->strarg2insno(csound, p->instrnum, p->XSTRCODE); - if (n > 0 && n <= csound->maxinsno && csound->instrtxtp[n] != NULL) + int n; + + if(ISSTRCOD(*p->instrnum)) { + char *ss = get_arg_string(csound,*p->instrnum); + n = csound->strarg2insno(csound,ss,1); + } else n = *p->instrnum; + if (n > 0 && n <= csound->engineState.maxinsno && + csound->engineState.instrtxtp[n] != NULL) + /* If instrument exists */ + csound->engineState.instrtxtp[n]->maxalloc = (int)*p->ipercent; + return OK; +} + +int maxalloc_S(CSOUND *csound, CPU_PERC *p) +{ + int n = csound->strarg2insno(csound, ((STRINGDAT *)p->instrnum)->data, 1); + if (n > 0 && n <= csound->engineState.maxinsno && + csound->engineState.instrtxtp[n] != NULL) /* If instrument exists */ - csound->instrtxtp[n]->maxalloc = (int)*p->ipercent; + csound->engineState.instrtxtp[n]->maxalloc = (int)*p->ipercent; return OK; } @@ -108,7 +197,8 @@ if (n<1 || n>PMAX) ans = FL(0.0); else ans = csound->currevent->p[n]; /* save the pfields of the current event */ - csound->AuxAlloc(csound, (csound->currevent->pcnt+1)*sizeof(MYFLT), &p->pfield); + csound->AuxAlloc(csound, + (csound->currevent->pcnt+1)*sizeof(MYFLT), &p->pfield); pfield = p->pfield.auxp; for (i=1; i<=csound->currevent->pcnt; i++) pfield[i] = csound->currevent->p[i]; diff -Nru csound-5.17.11~dfsg/Opcodes/pitchtrack.c csound-6.02~dfsg/Opcodes/pitchtrack.c --- csound-5.17.11~dfsg/Opcodes/pitchtrack.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pitchtrack.c 2014-01-07 16:53:48.000000000 +0000 @@ -1,28 +1,28 @@ /* - pitchtrack.c + pitchtrack.c - kcps, kamp ptrack asig, ihopsize [, ipeaks] + kcps, kamp ptrack asig, ihopsize [, ipeaks] - (c) Victor Lazzarini, 2007 + (c) Victor Lazzarini, 2007 - based on M Puckette's pitch tracking algorithm. + based on M Puckette's pitch tracking algorithm. - This file is part of Csound. + This file is part of Csound. - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA */ #include "csoundCore.h" @@ -55,22 +55,22 @@ static const MYFLT partialonset[] = { - FL(0.0), - FL(48.0), - FL(76.0782000346154967102), - FL(96.0), - FL(111.45254855459339269887), - FL(124.07820003461549671089), - FL(134.75303625876499715823), - FL(144.0), - FL(152.15640006923099342109), - FL(159.45254855459339269887), - FL(166.05271769459026829915), - FL(172.07820003461549671088), - FL(177.62110647077242370064), - FL(182.75303625876499715892), - FL(187.53074858920888940907), - FL(192.0), + FL(0.0), + FL(48.0), + FL(76.0782000346154967102), + FL(96.0), + FL(111.45254855459339269887), + FL(124.07820003461549671089), + FL(134.75303625876499715823), + FL(144.0), + FL(152.15640006923099342109), + FL(159.45254855459339269887), + FL(166.05271769459026829915), + FL(172.07820003461549671088), + FL(177.62110647077242370064), + FL(182.75303625876499715892), + FL(187.53074858920888940907), + FL(192.0), }; #define NPARTIALONSET ((int)(sizeof(partialonset)/sizeof(MYFLT))) @@ -124,337 +124,337 @@ void ptrack(CSOUND *csound,PITCHTRACK *p) { - MYFLT *spec = (MYFLT *)p->spec1.auxp; - MYFLT *spectmp = (MYFLT *)p->spec2.auxp; - MYFLT *sig = (MYFLT *)p->signal.auxp; - MYFLT *sinus = (MYFLT *)p->sin.auxp; - MYFLT *prev = (MYFLT *)p->prev.auxp; - PEAK *peaklist = (PEAK *)p->peakarray.auxp; - HISTOPEAK histpeak; - int i, j, k, hop = p->hopsize, n = 2*hop, npeak, logn = -1, count, tmp; - MYFLT totalpower, totalloudness, totaldb; - MYFLT maxbin, *histogram = spectmp + BINGUARD; - MYFLT hzperbin = p->sr / (n + n); - int numpks = p->numpks; - int indx, halfhop = hop>>1; - MYFLT best; - MYFLT cumpow = 0, cumstrength = 0, freqnum = 0, freqden = 0; - int npartials = 0, nbelow8 = 0; - MYFLT putfreq; - - count = p->histcnt + 1; - if (count == NPREV) count = 0; - p->histcnt = count; - - tmp = n; - while (tmp) { - tmp >>= 1; - logn++; - } - maxbin = BINPEROCT * (logn-2); - - for (i = 0, k = 0; i < hop; i++, k += 2) { - spec[k] = sig[i] * sinus[k]; - spec[k+1] = sig[i] * sinus[k+1]; - } - - csound->ComplexFFT(csound, spec, hop); - - for (i = 0, k = 2*FLTLEN; i < hop; i+=2, k += 4) { - spectmp[k] = spec[i]; - spectmp[k+1] = spec[i+1]; - } - for (i = n - 2, k = 2*FLTLEN+2; i >= 0; i-=2, k += 4) { - spectmp[k] = spec[i]; - spectmp[k+1] = -spec[i+1]; - } - for (i = (2*FLTLEN), k = (2*FLTLEN-2);i=0; i-=2, k+=2) { - spectmp[k] = spectmp[i]; - spectmp[k+1] = -spectmp[k+1]; - } - - for (i = j = 0, k = 2*FLTLEN; i < halfhop; i++, j+=8, k+=2) { - MYFLT re, im; - - re= COEF1 * ( prev[k-2] - prev[k+1] + spectmp[k-2] - prev[k+1]) + - COEF2 * ( prev[k-3] - prev[k+2] + spectmp[k-3] - spectmp[ 2]) + - COEF3 * (-prev[k-6] +prev[k+5] -spectmp[k-6] +spectmp[k+5]) + - COEF4 * (-prev[k-7] +prev[k+6] -spectmp[k-7] +spectmp[k+6]) + - COEF5 * ( prev[k-10] -prev[k+9] +spectmp[k-10] -spectmp[k+9]); - - im= COEF1 * ( prev[k-1] +prev[k] +spectmp[k-1] +spectmp[k]) + - COEF2 * (-prev[k-4] -prev[k+3] -spectmp[k-4] -spectmp[k+3]) + - COEF3 * (-prev[k-5] -prev[k+4] -spectmp[k-5] -spectmp[k+4]) + - COEF4 * ( prev[k-8] +prev[k+7] +spectmp[k-8] +spectmp[k+7]) + - COEF5 * ( prev[k-9] +prev[k+8] +spectmp[k-9] +spectmp[k+8]); - - spec[j] = FL(0.707106781186547524400844362104849) * (re + im); - spec[j+1] = FL(0.707106781186547524400844362104849) * (im - re); - spec[j+4] = prev[k] + spectmp[k+1]; - spec[j+5] = prev[k+1] - spectmp[k]; - - j += 8; - k += 2; - re= COEF1 * ( prev[k-2] -prev[k+1] -spectmp[k-2] +spectmp[k+1]) + - COEF2 * ( prev[k-3] -prev[k+2] -spectmp[k-3] +spectmp[k+2]) + - COEF3 * (-prev[k-6] +prev[k+5] +spectmp[k-6] -spectmp[k+5]) + - COEF4 * (-prev[k-7] +prev[k+6] +spectmp[k-7] -spectmp[k+6]) + - COEF5 * ( prev[k-10] -prev[k+9] -spectmp[k-10] +spectmp[k+9]); - - im= COEF1 * ( prev[k-1] +prev[k] -spectmp[k-1] -spectmp[k]) + - COEF2 * (-prev[k-4] -prev[k+3] +spectmp[k-4] +spectmp[k+3]) + - COEF3 * (-prev[k-5] -prev[k+4] +spectmp[k-5] +spectmp[k+4]) + - COEF4 * ( prev[k-8] +prev[k+7] -spectmp[k-8] -spectmp[k+7]) + - COEF5 * ( prev[k-9] +prev[k+8] -spectmp[k-9] -spectmp[k+8]); - - spec[j] = FL(0.707106781186547524400844362104849) * (re + im); - spec[j+1] = FL(0.707106781186547524400844362104849) * (im - re); - spec[j+4] = prev[k] - spectmp[k+1]; - spec[j+5] = prev[k+1] + spectmp[k]; - - } - - - for (i = 0; i < n + 4*FLTLEN; i++) prev[i] = spectmp[i]; - - for (i = 0; i < MINBIN; i++) spec[4*i + 2] = spec[4*i + 3] = FL(0.0); - - for (i = 4*MINBIN, totalpower = 0; i < (n-2)*4; i += 4) { - MYFLT re = spec[i] - FL(0.5) * (spec[i-8] + spec[i+8]); - MYFLT im = spec[i+1] - FL(0.5) * (spec[i-7] + spec[i+9]); - spec[i+3] = (totalpower += (spec[i+2] = re * re + im * im)); - } - - if (totalpower > FL(1.0e-9)) { - totaldb = FL(DBSCAL) * LOG(totalpower/n); - totalloudness = SQRT(SQRT(totalpower)); - if (totaldb < 0) totaldb = 0; - } - else totaldb = totalloudness = FL(0.0); - - p->dbs[count] = totaldb + DBOFFSET; - - if (totaldb >= p->amplo) { - - npeak = 0; - - for (i = 4*MINBIN;i < (4*(n-2)) && npeak < numpks; i+=4) { - MYFLT height = spec[i+2], h1 = spec[i-2], h2 = spec[i+6]; - MYFLT totalfreq, peakfr, tmpfr1, tmpfr2, m, var, stdev; - - if (height < h1 || height < h2 || - h1 < FL(0.00001)*totalpower || - h2 < FL(0.00001)*totalpower) continue; - - peakfr= ((spec[i-8] - spec[i+8]) * (FL(2.0) * spec[i] - - spec[i+8] - spec[i-8]) + - (spec[i-7] - spec[i+9]) * (FL(2.0) * spec[i+1] - - spec[i+9] - spec[i-7])) / - (height + height); - tmpfr1= ((spec[i-12] - spec[i+4]) * - (FL(2.0) * spec[i-4] - spec[i+4] - spec[i-12]) + - (spec[i-11] - spec[i+5]) * (FL(2.0) * spec[i-3] - - spec[i+5] - spec[i-11])) / - (FL(2.0) * h1) - 1; - tmpfr2= ((spec[i-4] - spec[i+12]) * (FL(2.0) * spec[i+4] - - spec[i+12] - spec[i-4]) + - (spec[i-3] - spec[i+13]) * (FL(2.0) * spec[i+5] - - spec[i+13] - spec[i-3])) / - (FL(2.0) * h2) + 1; - - - m = FL(0.333333333333) * (peakfr + tmpfr1 + tmpfr2); - var = FL(0.5) * ((peakfr-m)*(peakfr-m) + - (tmpfr1-m)*(tmpfr1-m) + (tmpfr2-m)*(tmpfr2-m)); - - totalfreq = (i>>2) + m; - if (var * totalpower > THRSH * height - || var < FL(1.0e-30)) continue; - - stdev = (MYFLT)sqrt((double)var); - if (totalfreq < 4) totalfreq = 4; - - - peaklist[npeak].pwidth = stdev; - peaklist[npeak].ppow = height; - peaklist[npeak].ploudness = SQRT(SQRT(height)); - peaklist[npeak].pfreq = totalfreq; - npeak++; + MYFLT *spec = (MYFLT *)p->spec1.auxp; + MYFLT *spectmp = (MYFLT *)p->spec2.auxp; + MYFLT *sig = (MYFLT *)p->signal.auxp; + MYFLT *sinus = (MYFLT *)p->sin.auxp; + MYFLT *prev = (MYFLT *)p->prev.auxp; + PEAK *peaklist = (PEAK *)p->peakarray.auxp; + HISTOPEAK histpeak; + int i, j, k, hop = p->hopsize, n = 2*hop, npeak, logn = -1, count, tmp; + MYFLT totalpower, totalloudness, totaldb; + MYFLT maxbin, *histogram = spectmp + BINGUARD; + MYFLT hzperbin = p->sr / (n + n); + int numpks = p->numpks; + int indx, halfhop = hop>>1; + MYFLT best; + MYFLT cumpow = 0, cumstrength = 0, freqnum = 0, freqden = 0; + int npartials = 0, nbelow8 = 0; + MYFLT putfreq; + + count = p->histcnt + 1; + if (count == NPREV) count = 0; + p->histcnt = count; + + tmp = n; + while (tmp) { + tmp >>= 1; + logn++; + } + maxbin = BINPEROCT * (logn-2); + + for (i = 0, k = 0; i < hop; i++, k += 2) { + spec[k] = sig[i] * sinus[k]; + spec[k+1] = sig[i] * sinus[k+1]; + } + + csound->ComplexFFT(csound, spec, hop); + + for (i = 0, k = 2*FLTLEN; i < hop; i+=2, k += 4) { + spectmp[k] = spec[i]; + spectmp[k+1] = spec[i+1]; + } + for (i = n - 2, k = 2*FLTLEN+2; i >= 0; i-=2, k += 4) { + spectmp[k] = spec[i]; + spectmp[k+1] = -spec[i+1]; + } + for (i = (2*FLTLEN), k = (2*FLTLEN-2);i=0; i-=2, k+=2) { + spectmp[k] = spectmp[i]; + spectmp[k+1] = -spectmp[k+1]; + } + + for (i = j = 0, k = 2*FLTLEN; i < halfhop; i++, j+=8, k+=2) { + MYFLT re, im; + + re= COEF1 * ( prev[k-2] - prev[k+1] + spectmp[k-2] - prev[k+1]) + + COEF2 * ( prev[k-3] - prev[k+2] + spectmp[k-3] - spectmp[ 2]) + + COEF3 * (-prev[k-6] +prev[k+5] -spectmp[k-6] +spectmp[k+5]) + + COEF4 * (-prev[k-7] +prev[k+6] -spectmp[k-7] +spectmp[k+6]) + + COEF5 * ( prev[k-10] -prev[k+9] +spectmp[k-10] -spectmp[k+9]); + + im= COEF1 * ( prev[k-1] +prev[k] +spectmp[k-1] +spectmp[k]) + + COEF2 * (-prev[k-4] -prev[k+3] -spectmp[k-4] -spectmp[k+3]) + + COEF3 * (-prev[k-5] -prev[k+4] -spectmp[k-5] -spectmp[k+4]) + + COEF4 * ( prev[k-8] +prev[k+7] +spectmp[k-8] +spectmp[k+7]) + + COEF5 * ( prev[k-9] +prev[k+8] +spectmp[k-9] +spectmp[k+8]); + + spec[j] = FL(0.707106781186547524400844362104849) * (re + im); + spec[j+1] = FL(0.707106781186547524400844362104849) * (im - re); + spec[j+4] = prev[k] + spectmp[k+1]; + spec[j+5] = prev[k+1] - spectmp[k]; + + j += 8; + k += 2; + re= COEF1 * ( prev[k-2] -prev[k+1] -spectmp[k-2] +spectmp[k+1]) + + COEF2 * ( prev[k-3] -prev[k+2] -spectmp[k-3] +spectmp[k+2]) + + COEF3 * (-prev[k-6] +prev[k+5] +spectmp[k-6] -spectmp[k+5]) + + COEF4 * (-prev[k-7] +prev[k+6] +spectmp[k-7] -spectmp[k+6]) + + COEF5 * ( prev[k-10] -prev[k+9] -spectmp[k-10] +spectmp[k+9]); + + im= COEF1 * ( prev[k-1] +prev[k] -spectmp[k-1] -spectmp[k]) + + COEF2 * (-prev[k-4] -prev[k+3] +spectmp[k-4] +spectmp[k+3]) + + COEF3 * (-prev[k-5] -prev[k+4] +spectmp[k-5] +spectmp[k+4]) + + COEF4 * ( prev[k-8] +prev[k+7] -spectmp[k-8] -spectmp[k+7]) + + COEF5 * ( prev[k-9] +prev[k+8] -spectmp[k-9] -spectmp[k+8]); + + spec[j] = FL(0.707106781186547524400844362104849) * (re + im); + spec[j+1] = FL(0.707106781186547524400844362104849) * (im - re); + spec[j+4] = prev[k] - spectmp[k+1]; + spec[j+5] = prev[k+1] + spectmp[k]; + + } + + + for (i = 0; i < n + 4*FLTLEN; i++) prev[i] = spectmp[i]; + + for (i = 0; i < MINBIN; i++) spec[4*i + 2] = spec[4*i + 3] = FL(0.0); + + for (i = 4*MINBIN, totalpower = 0; i < (n-2)*4; i += 4) { + MYFLT re = spec[i] - FL(0.5) * (spec[i-8] + spec[i+8]); + MYFLT im = spec[i+1] - FL(0.5) * (spec[i-7] + spec[i+9]); + spec[i+3] = (totalpower += (spec[i+2] = re * re + im * im)); + } + + if (totalpower > FL(1.0e-9)) { + totaldb = FL(DBSCAL) * LOG(totalpower/n); + totalloudness = SQRT(SQRT(totalpower)); + if (totaldb < 0) totaldb = 0; + } + else totaldb = totalloudness = FL(0.0); + + p->dbs[count] = totaldb + DBOFFSET; + + if (totaldb >= p->amplo) { + + npeak = 0; + + for (i = 4*MINBIN;i < (4*(n-2)) && npeak < numpks; i+=4) { + MYFLT height = spec[i+2], h1 = spec[i-2], h2 = spec[i+6]; + MYFLT totalfreq, peakfr, tmpfr1, tmpfr2, m, var, stdev; + + if (height < h1 || height < h2 || + h1 < FL(0.00001)*totalpower || + h2 < FL(0.00001)*totalpower) continue; + + peakfr= ((spec[i-8] - spec[i+8]) * (FL(2.0) * spec[i] - + spec[i+8] - spec[i-8]) + + (spec[i-7] - spec[i+9]) * (FL(2.0) * spec[i+1] - + spec[i+9] - spec[i-7])) / + (height + height); + tmpfr1= ((spec[i-12] - spec[i+4]) * + (FL(2.0) * spec[i-4] - spec[i+4] - spec[i-12]) + + (spec[i-11] - spec[i+5]) * (FL(2.0) * spec[i-3] - + spec[i+5] - spec[i-11])) / + (FL(2.0) * h1) - 1; + tmpfr2= ((spec[i-4] - spec[i+12]) * (FL(2.0) * spec[i+4] - + spec[i+12] - spec[i-4]) + + (spec[i-3] - spec[i+13]) * (FL(2.0) * spec[i+5] - + spec[i+13] - spec[i-3])) / + (FL(2.0) * h2) + 1; + + + m = FL(0.333333333333) * (peakfr + tmpfr1 + tmpfr2); + var = FL(0.5) * ((peakfr-m)*(peakfr-m) + + (tmpfr1-m)*(tmpfr1-m) + (tmpfr2-m)*(tmpfr2-m)); + + totalfreq = (i>>2) + m; + if (var * totalpower > THRSH * height + || var < FL(1.0e-30)) continue; + + stdev = (MYFLT)sqrt((double)var); + if (totalfreq < 4) totalfreq = 4; + + + peaklist[npeak].pwidth = stdev; + peaklist[npeak].ppow = height; + peaklist[npeak].ploudness = SQRT(SQRT(height)); + peaklist[npeak].pfreq = totalfreq; + npeak++; + + } + + if (npeak > numpks) npeak = numpks; + for (i = 0; i < maxbin; i++) histogram[i] = 0; + for (i = 0; i < npeak; i++) { + MYFLT pit = (MYFLT)(BPEROOVERLOG2 * LOG(peaklist[i].pfreq) - 96.0); + MYFLT binbandwidth = FACTORTOBINS * peaklist[i].pwidth/peaklist[i].pfreq; + MYFLT putbandwidth = (binbandwidth < FL(2.0) ? FL(2.0) : binbandwidth); + MYFLT weightbandwidth = (binbandwidth < FL(1.0) ? FL(1.0) : binbandwidth); + MYFLT weightamp = FL(4.0) * peaklist[i].ploudness / totalloudness; + for (j = 0; j < NPARTIALONSET; j++) { + MYFLT bin = pit - partialonset[j]; + if (bin < maxbin) { + MYFLT para, pphase, score = FL(30.0) * weightamp / + ((j+p->npartial) * weightbandwidth); + int firstbin = bin + FL(0.5) - FL(0.5) * putbandwidth; + int lastbin = bin + FL(0.5) + FL(0.5) * putbandwidth; + int ibw = lastbin - firstbin; + if (firstbin < -BINGUARD) break; + para = FL(1.0) / (putbandwidth * putbandwidth); + for (k = 0, pphase = firstbin-bin; k <= ibw; + k++,pphase += FL(1.0)) + histogram[k+firstbin] += score * (FL(1.0) - para * pphase * pphase); - } - - if (npeak > numpks) npeak = numpks; - for (i = 0; i < maxbin; i++) histogram[i] = 0; - for (i = 0; i < npeak; i++) { - MYFLT pit = (MYFLT)(BPEROOVERLOG2 * LOG(peaklist[i].pfreq) - 96.0); - MYFLT binbandwidth = FACTORTOBINS * peaklist[i].pwidth/peaklist[i].pfreq; - MYFLT putbandwidth = (binbandwidth < FL(2.0) ? FL(2.0) : binbandwidth); - MYFLT weightbandwidth = (binbandwidth < FL(1.0) ? FL(1.0) : binbandwidth); - MYFLT weightamp = FL(4.0) * peaklist[i].ploudness / totalloudness; - for (j = 0; j < NPARTIALONSET; j++) { - MYFLT bin = pit - partialonset[j]; - if (bin < maxbin) { - MYFLT para, pphase, score = FL(30.0) * weightamp / - ((j+p->npartial) * weightbandwidth); - int firstbin = bin + FL(0.5) - FL(0.5) * putbandwidth; - int lastbin = bin + FL(0.5) + FL(0.5) * putbandwidth; - int ibw = lastbin - firstbin; - if (firstbin < -BINGUARD) break; - para = FL(1.0) / (putbandwidth * putbandwidth); - for (k = 0, pphase = firstbin-bin; k <= ibw; - k++,pphase += FL(1.0)) - histogram[k+firstbin] += score * (FL(1.0) - para * pphase * pphase); - - } } } + } - for (best = 0, indx = -1, j=0; j < maxbin; j++) - if (histogram[j] > best) - indx = j, best = histogram[j]; - - histpeak.hvalue = best; - histpeak.hindex = indx; - - putfreq = EXP((FL(1.0) / BPEROOVERLOG2) * - (histpeak.hindex + FL(96.0))); - for (j = 0; j < npeak; j++) { - MYFLT fpnum = peaklist[j].pfreq/putfreq; - int pnum = (int)(fpnum + FL(0.5)); - MYFLT fipnum = pnum; - MYFLT deviation; - if (pnum > 16 || pnum < 1) continue; - deviation = FL(1.0) - fpnum/fipnum; - if (deviation > -PARTIALDEVIANCE && deviation < PARTIALDEVIANCE) { - MYFLT stdev, weight; - npartials++; - if (pnum < 8) nbelow8++; - cumpow += peaklist[j].ppow; - cumstrength += SQRT(SQRT(peaklist[j].ppow)); - stdev = (peaklist[j].pwidth > MINBW ? - peaklist[j].pwidth : MINBW); - weight = FL(1.0) / ((stdev*fipnum) * (stdev*fipnum)); - freqden += weight; - freqnum += weight * peaklist[j].pfreq/fipnum; - } + for (best = 0, indx = -1, j=0; j < maxbin; j++) + if (histogram[j] > best) + indx = j, best = histogram[j]; + + histpeak.hvalue = best; + histpeak.hindex = indx; + + putfreq = EXP((FL(1.0) / BPEROOVERLOG2) * + (histpeak.hindex + FL(96.0))); + for (j = 0; j < npeak; j++) { + MYFLT fpnum = peaklist[j].pfreq/putfreq; + int pnum = (int)(fpnum + FL(0.5)); + MYFLT fipnum = pnum; + MYFLT deviation; + if (pnum > 16 || pnum < 1) continue; + deviation = FL(1.0) - fpnum/fipnum; + if (deviation > -PARTIALDEVIANCE && deviation < PARTIALDEVIANCE) { + MYFLT stdev, weight; + npartials++; + if (pnum < 8) nbelow8++; + cumpow += peaklist[j].ppow; + cumstrength += SQRT(SQRT(peaklist[j].ppow)); + stdev = (peaklist[j].pwidth > MINBW ? + peaklist[j].pwidth : MINBW); + weight = FL(1.0) / ((stdev*fipnum) * (stdev*fipnum)); + freqden += weight; + freqnum += weight * peaklist[j].pfreq/fipnum; } - if ((nbelow8 < 4 || npartials < 7) && cumpow < FL(0.01) * totalpower) + } + if ((nbelow8 < 4 || npartials < 7) && cumpow < FL(0.01) * totalpower) + histpeak.hvalue = 0; + else { + double pitchpow = (cumstrength * cumstrength); + MYFLT freqinbins = freqnum/freqden; + pitchpow = pitchpow * pitchpow; + if (freqinbins < MINFREQINBINS) histpeak.hvalue = 0; else { - double pitchpow = (cumstrength * cumstrength); - MYFLT freqinbins = freqnum/freqden; - pitchpow = pitchpow * pitchpow; - if (freqinbins < MINFREQINBINS) - histpeak.hvalue = 0; - else { - p->cps = histpeak.hpitch = hzperbin * freqnum/freqden; - histpeak.hloud = FL(DBSCAL) * LOG(pitchpow/n); - } + p->cps = histpeak.hpitch = hzperbin * freqnum/freqden; + histpeak.hloud = FL(DBSCAL) * LOG(pitchpow/n); } - } + + } } int pitchtrackinit(CSOUND *csound, PITCHTRACK *p) { - int i, winsize = *p->size*2, powtwo, tmp; - MYFLT *tmpb; - - if (UNLIKELY(winsize < MINWINSIZ || winsize > MAXWINSIZ)) { - csound->Warning(csound, Str("ptrack: FFT size out of range; using %d\n"), - winsize = DEFAULTWINSIZ); - } - - tmp = winsize; - powtwo = -1; + int i, winsize = *p->size*2, powtwo, tmp; + MYFLT *tmpb; - while (tmp) { - tmp >>= 1; - powtwo++; - } - - if (UNLIKELY(winsize != (1 << powtwo))) { - csound->Warning(csound, Str("ptrack: FFT size not a power of 2; using %d\n"), - winsize = (1 << powtwo)); - } - p->hopsize = *p->size; - if (!p->signal.auxp || p->signal.size < p->hopsize*sizeof(MYFLT)) { - csound->AuxAlloc(csound, p->hopsize*sizeof(MYFLT), &p->signal); - } - if (!p->prev.auxp || p->prev.size < (p->hopsize*2 + 4*FLTLEN)*sizeof(MYFLT)) { - csound->AuxAlloc(csound, (p->hopsize*2 + 4*FLTLEN)*sizeof(MYFLT), &p->prev); - } - if (!p->sin.auxp || p->sin.size < (p->hopsize*2)*sizeof(MYFLT)) { - csound->AuxAlloc(csound, (p->hopsize*2)*sizeof(MYFLT), &p->sin); - } - - if (!p->spec2.auxp || p->spec2.size < (winsize*4 + 4*FLTLEN)*sizeof(MYFLT)) { - csound->AuxAlloc(csound, (winsize*4 + 4*FLTLEN)*sizeof(MYFLT), &p->spec2); - } - - if (!p->spec1.auxp || p->spec1.size < (winsize*4)*sizeof(MYFLT)) { - csound->AuxAlloc(csound, (winsize*4)*sizeof(MYFLT), &p->spec1); - } - - for (i = 0, tmpb = (MYFLT *)p->signal.auxp; i < p->hopsize; i++) - tmpb[i] = FL(0.0); - for (i = 0, tmpb = (MYFLT *)p->prev.auxp; i < winsize + 4 * FLTLEN; i++) - tmpb[i] = FL(0.0); - for (i = 0, tmpb = (MYFLT *)p->sin.auxp; i < p->hopsize; i++) - tmpb[2*i] = (MYFLT) cos((PI*i)/(winsize)), + if (UNLIKELY(winsize < MINWINSIZ || winsize > MAXWINSIZ)) { + csound->Warning(csound, Str("ptrack: FFT size out of range; using %d\n"), + winsize = DEFAULTWINSIZ); + } + + tmp = winsize; + powtwo = -1; + + while (tmp) { + tmp >>= 1; + powtwo++; + } + + if (UNLIKELY(winsize != (1 << powtwo))) { + csound->Warning(csound, Str("ptrack: FFT size not a power of 2; using %d\n"), + winsize = (1 << powtwo)); + } + p->hopsize = *p->size; + if (!p->signal.auxp || p->signal.size < p->hopsize*sizeof(MYFLT)) { + csound->AuxAlloc(csound, p->hopsize*sizeof(MYFLT), &p->signal); + } + if (!p->prev.auxp || p->prev.size < (p->hopsize*2 + 4*FLTLEN)*sizeof(MYFLT)) { + csound->AuxAlloc(csound, (p->hopsize*2 + 4*FLTLEN)*sizeof(MYFLT), &p->prev); + } + if (!p->sin.auxp || p->sin.size < (p->hopsize*2)*sizeof(MYFLT)) { + csound->AuxAlloc(csound, (p->hopsize*2)*sizeof(MYFLT), &p->sin); + } + + if (!p->spec2.auxp || p->spec2.size < (winsize*4 + 4*FLTLEN)*sizeof(MYFLT)) { + csound->AuxAlloc(csound, (winsize*4 + 4*FLTLEN)*sizeof(MYFLT), &p->spec2); + } + + if (!p->spec1.auxp || p->spec1.size < (winsize*4)*sizeof(MYFLT)) { + csound->AuxAlloc(csound, (winsize*4)*sizeof(MYFLT), &p->spec1); + } + + for (i = 0, tmpb = (MYFLT *)p->signal.auxp; i < p->hopsize; i++) + tmpb[i] = FL(0.0); + for (i = 0, tmpb = (MYFLT *)p->prev.auxp; i < winsize + 4 * FLTLEN; i++) + tmpb[i] = FL(0.0); + for (i = 0, tmpb = (MYFLT *)p->sin.auxp; i < p->hopsize; i++) + tmpb[2*i] = (MYFLT) cos((PI*i)/(winsize)), tmpb[2*i+1] = -(MYFLT)sin((PI*i)/(winsize)); - p->cnt = 0; - if (*p->peak == 0 || *p->peak > MAXPEAKNOS) - p->numpks = DEFAULTPEAKNOS; - else - p->numpks = *p->peak; - - if (!p->peakarray.auxp || p->peakarray.size < (p->numpks+1)*sizeof(PEAK)) { - csound->AuxAlloc(csound, (p->numpks+1)*sizeof(PEAK), &p->peakarray); - } - - p->cnt = 0; - p->histcnt = 0; - p->sr = csound->GetSr(csound); - for (i = 0; i < NPREV; i++) p->dbs[i] = FL(-144.0); - p->amplo = MINAMPS; - p->amphi = MAXAMPS; - p->npartial = 7; - p->dbfs = FL(32768.0)/csound->e0dbfs; - p->prevf = p->cps = 100.0; - return (OK); + p->cnt = 0; + if (*p->peak == 0 || *p->peak > MAXPEAKNOS) + p->numpks = DEFAULTPEAKNOS; + else + p->numpks = *p->peak; + + if (!p->peakarray.auxp || p->peakarray.size < (p->numpks+1)*sizeof(PEAK)) { + csound->AuxAlloc(csound, (p->numpks+1)*sizeof(PEAK), &p->peakarray); + } + + p->cnt = 0; + p->histcnt = 0; + p->sr = CS_ESR; + for (i = 0; i < NPREV; i++) p->dbs[i] = FL(-144.0); + p->amplo = MINAMPS; + p->amphi = MAXAMPS; + p->npartial = 7; + p->dbfs = FL(32768.0)/csound->e0dbfs; + p->prevf = p->cps = 100.0; + return (OK); } int pitchtrackprocess(CSOUND *csound, PITCHTRACK *p) { - MYFLT *sig = p->asig; int i; - MYFLT *buf = (MYFLT *)p->signal.auxp; - int pos = p->cnt, h = p->hopsize; - MYFLT scale = p->dbfs; - int ksmps = csound->GetKsmps(csound); - - for (i=0; icps) - *p->freq = p->cps; - //else *p->freq = p->prevf; - //p->prevf = *p->freq; - *p->amp = p->dbs[p->histcnt]; - p->cnt = pos; + MYFLT *sig = p->asig; int i; + MYFLT *buf = (MYFLT *)p->signal.auxp; + int pos = p->cnt, h = p->hopsize; + MYFLT scale = p->dbfs; + int ksmps = CS_KSMPS; + + for (i=0; icps) + *p->freq = p->cps; + //else *p->freq = p->prevf; + //p->prevf = *p->freq; + *p->amp = p->dbs[p->histcnt]; + p->cnt = pos; - return OK; + return OK; } typedef struct _pitchaf{ @@ -468,7 +468,7 @@ } PITCHAF; int pitchafset(CSOUND *csound, PITCHAF *p){ - int siz = (int)(csound->GetSr(csound)/ (*p->iflow)); + int siz = (int)(CS_ESR/ (*p->iflow)); if (p->buff1.auxp == NULL || p->buff1.size < siz*sizeof(MYFLT)) csound->AuxAlloc(csound, siz*sizeof(MYFLT), &p->buff1); else @@ -491,56 +491,257 @@ int pitchafproc(CSOUND *csound, PITCHAF *p) { - int lag = p->lag,n, i, j, imax = 0, len = p->len, - ksmps = csound->GetKsmps(csound); - MYFLT *buff1 = (MYFLT *)p->buff1.auxp; - MYFLT *buff2 = (MYFLT *)p->buff2.auxp; - MYFLT *cor = (MYFLT *)p->cor.auxp; - MYFLT *s = p->asig, pitch; - //MYFLT ifmax = *p->kfmax; - - for (n=0; n < ksmps; n++) { - for (i=0,j=lag; i < len; i++) { - cor[lag] += buff1[i]*buff2[j]; - j = j != len ? j+1 : 0; - } - buff2[lag++] = s[n]; - - if (lag == len) { - float max = 0.0f; - for (i=0; i < len; i++) { - if (cor[i] > max) { - max = cor[i]; - if (i) imax = i; - } - buff1[i] = buff2[i]; - cor[i] = FL(0.0); + int lag = p->lag,n, i, j, imax = 0, len = p->len, + ksmps = CS_KSMPS; + MYFLT *buff1 = (MYFLT *)p->buff1.auxp; + MYFLT *buff2 = (MYFLT *)p->buff2.auxp; + MYFLT *cor = (MYFLT *)p->cor.auxp; + MYFLT *s = p->asig, pitch; + //MYFLT ifmax = *p->kfmax; + + for (n=0; n < ksmps; n++) { + for (i=0,j=lag; i < len; i++) { + cor[lag] += buff1[i]*buff2[j]; + j = j != len ? j+1 : 0; + } + buff2[lag++] = s[n]; + + if (lag == len) { + float max = 0.0f; + for (i=0; i < len; i++) { + if (cor[i] > max) { + max = cor[i]; + if (i) imax = i; } - len = csound->GetSr(csound)/(*p->kfmin); - if (len > p->size) len = p->size; - lag = 0; + buff1[i] = buff2[i]; + cor[i] = FL(0.0); } + len = CS_ESR/(*p->kfmin); + if (len > p->size) len = p->size; + lag = 0; + } + } + p->lag = lag; + p->len = len; + if (imax) { + pitch = CS_ESR/imax; + if (pitch <= *p->kfmax) p->pitch = pitch; + } + *p->kpitch = p->pitch; + + return OK; +} +/* PLL Pitch tracker (Zoelzer et al) + V Lazzarini, 2012 +*/ + +#define ROOT2 (1.4142135623730950488) +enum {LP1=0, LP2, HP}; + +typedef struct biquad_ { + double a0, a1, a2, b1, b2; + double del1, del2; +} BIQUAD; + +typedef struct plltrack_ +{ + OPDS h; + MYFLT *freq, *lock; + MYFLT *asig,*kd,*klpf,*klpfQ,*klf,*khf,*kthresh; + BIQUAD fils[6]; + double ace, xce; + double cos_x, sin_x, x1, x2; + MYFLT klpf_o, klpfQ_o, klf_o,khf_o; + +} PLLTRACK; + +void update_coefs(CSOUND *csound, double fr, double Q, BIQUAD *biquad, int TYPE) +{ + double k, ksq, div, ksqQ; + + switch(TYPE){ + case LP2: + k = tan(fr*csound->pidsr); + ksq = k*k; + ksqQ = ksq*Q; + div = ksqQ+k+Q; + biquad->b1 = (2*Q*(ksq-1.))/div; + biquad->b2 = (ksqQ-k+Q)/div; + biquad->a0 = ksqQ/div; + biquad->a1 = 2*biquad->a0; + biquad->a2 = biquad->a0; + break; + + case LP1: + k = 1.0/tan(csound->pidsr*fr); + ksq = k*k; + biquad->a0 = 1.0 / ( 1.0 + ROOT2 * k + ksq); + biquad->a1 = 2.0*biquad->a0; + biquad->a2 = biquad->a0; + biquad->b1 = 2.0 * (1.0 - ksq) * biquad->a0; + biquad->b2 = ( 1.0 - ROOT2 * k + ksq) * biquad->a0; + break; + + case HP: + k = tan(csound->pidsr*fr); + ksq = k*k; + biquad->a0 = 1.0 / ( 1.0 + ROOT2 * k + ksq); + biquad->a1 = -2.*biquad->a0; + biquad->a2 = biquad->a0; + biquad->b1 = 2.0 * (ksq - 1.0) * biquad->a0; + biquad->b2 = ( 1.0 - ROOT2 * k + ksq) * biquad->a0; + break; } - p->lag = lag; - p->len = len; - if (imax) { - pitch = csound->GetSr(csound)/imax; - if (pitch <= *p->kfmax) p->pitch = pitch; - } - *p->kpitch = p->pitch; + +} + + +int plltrack_set(CSOUND *csound, PLLTRACK *p) +{ + int i; + p->x1 = p->cos_x = p->sin_x = 0.0; + p->x2 = 1.0; + p->klpf_o = p->klpfQ_o = p->klf_o = p->khf_o = 0.0; + update_coefs(csound,10.0, 0.0, &p->fils[4], LP1); + p->ace = p->xce = 0.0; + for (i=0; i < 6; i++) + p->fils[i].del1 = p->fils[i].del2 = 0.0; return OK; } +int plltrack_perf(CSOUND *csound, PLLTRACK *p) +{ + int ksmps, i, k; + MYFLT _0dbfs; + double a0[6], a1[6], a2[6], b1[6], b2[6]; + double *mem1[6], *mem2[6]; + double *ace, *xce; + double *cos_x, *sin_x, *x1, *x2; + double scal,esr; + BIQUAD *biquad = p->fils; + MYFLT *asig=p->asig,kd=*p->kd,klpf,klpfQ,klf,khf,kthresh; + MYFLT *freq=p->freq, *lock =p->lock; + + if (*p->klpf == 0) klpf = 20.0; + else klpf = *p->klpf; + + if (*p->klpfQ == 0) klpfQ = 1./3.; + else klpfQ = *p->klpfQ; + + if (*p->klf == 0) klf = 20.0; + else klf = *p->klf; + + if (*p->khf == 0) khf = 1500.0; + else khf = *p->khf; + + if (*p->kthresh == 0.0) kthresh= 0.001; + else kthresh = *p->kthresh; + + _0dbfs = csound->e0dbfs; + ksmps = CS_KSMPS; + esr = CS_ESR; + scal = 2.0*csound->pidsr; + + if (p->khf_o != khf) { + update_coefs(csound, khf, 0.0, &biquad[0], LP1); + update_coefs(csound, khf, 0.0, &biquad[1], LP1); + update_coefs(csound, khf, 0.0, &biquad[2], LP1); + p->khf_o = khf; + } + + if (p->klf_o != klf) { + update_coefs(csound, klf, 0.0, &biquad[3], HP); + p->klf_o = klf; + } + + if (p->klpf_o != klpf || p->klpfQ_o != klpfQ ) { + update_coefs(csound, klpf, klpfQ, &biquad[5], LP2); + p->klpf_o = klpf; p->klpfQ_o = klpfQ; + } + + + + for(k=0; k < 6; k++) { + a0[k] = biquad[k].a0; + a1[k] = biquad[k].a1; + a2[k] = biquad[k].a2; + b1[k] = biquad[k].b1; + b2[k] = biquad[k].b2; + mem1[k] = &(biquad[k].del1); + mem2[k] = &(biquad[k].del2); + } + + cos_x = &p->cos_x; + sin_x = &p->sin_x; + x1 = &p->x1; + x2 = &p->x2; + xce = &p->xce; + ace = &p->ace; + + for (i=0; i < ksmps; i++){ + double input = (double) (asig[i]/_0dbfs), env; + double w, y, icef = 0.99, fosc, xd, c, s, oc; + + /* input stage filters */ + for (k=0; k < 4 ; k++){ + w = input - *(mem1[k])*b1[k] - *(mem2[k])*b2[k]; + y = w*a0[k] + *(mem1[k])*a1[k] + *(mem2[k])*a2[k]; + *(mem2[k]) = *(mem1[k]); + *(mem1[k]) = w; + input = y; + } + + /* envelope extraction */ + w = FABS(input) - *(mem1[k])*b1[k] - *(mem2[k])*b2[k]; + y = w*a0[k] + *(mem1[k])*a1[k] + *(mem2[k])*a2[k]; + *(mem2[k]) = *(mem1[k]); + *(mem1[k]) = w; + env = y; + k++; + + /* constant envelope */ + if (env > kthresh) + input /= env; + else input = 0.0; + + /*post-ce filter */ + *ace = (1.-icef)*(input + *xce)/2. + *ace*icef; + *xce = input; + + /* PLL */ + xd = *cos_x * (*ace) * kd * esr; + w = xd - *(mem1[k])*b1[k] - *(mem2[k])*b2[k]; + y = w*a0[k] + *(mem1[k])*a1[k] + *(mem2[k])*a2[k]; + *(mem2[k]) = *(mem1[k]); + *(mem1[k]) = w; + freq[i] = FABS(2*y); + lock[i] = *ace * (*sin_x); + fosc = y + xd; + + /* quadrature osc */ + *sin_x = *x1; + *cos_x = *x2; + oc = fosc*scal; + c = COS(oc); s = SIN(oc); + *x1 = *sin_x*c + *cos_x*s; + *x2 = -*sin_x*s + *cos_x*c; + } + return OK; +} #define S(x) sizeof(x) static OENTRY pitchtrack_localops[] = { - {"ptrack", S(PITCHTRACK), 5, "kk", "aio", (SUBR)pitchtrackinit, NULL, (SUBR)pitchtrackprocess}, - {"pitchac", S(PITCHTRACK), 5, "k", "akki", (SUBR)pitchafset, NULL, (SUBR)pitchafproc} -}; + {"ptrack", S(PITCHTRACK), 0, 5, "kk", "aio", + (SUBR)pitchtrackinit, NULL, (SUBR)pitchtrackprocess}, + {"pitchac", S(PITCHTRACK), 0, 5, "k", "akki", + (SUBR)pitchafset, NULL, (SUBR)pitchafproc}, + {"plltrack", S(PLLTRACK), 0, 5, "aa", "akOOOOO", + (SUBR)plltrack_set, NULL, (SUBR)plltrack_perf} -LINKAGE1(pitchtrack_localops) +}; +LINKAGE_BUILTIN(pitchtrack_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/platerev.c csound-6.02~dfsg/Opcodes/platerev.c --- csound-5.17.11~dfsg/Opcodes/platerev.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/platerev.c 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,253 @@ +/* + platerev.c: + + Copyright (C) 2006 by Stefan Bilbao + 2012 John ffitch + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +#include "csdl.h" +#include + +/* #undef CS_KSMPS */ +/* #define CS_KSMPS (csound->GetKsmps(csound)) */ + +typedef struct { + OPDS h; + MYFLT *aout[40]; + MYFLT *tabins; + MYFLT *tabout; + MYFLT *bndry; + MYFLT *asp; + MYFLT *stiff; + MYFLT *decay; + MYFLT *loss; + MYFLT *ain[40]; + // Internals + double s00, s10, s01, s11, s20, s02, t00, t01, t10; + uint32_t nin, nout, Nx, Ny; + double *u, *u1, *u2; + AUXCH auxch; + double L, dy, dt; + MYFLT *in_param, *out_param; + double ci[40], si[40], co[40], so[40]; + } PLATE; + + +static int platerev_init(CSOUND *csound, PLATE *p) +{ + FUNC *inp, *outp; + double a = *p->asp; + double dt = (p->dt = 1.0/csound->GetSr(csound)); /* time step */ + double sig = (csound->GetSr(csound)+csound->GetSr(csound))* + (POWER(10.0, FL(3.0)*dt/(*p->decay))-FL(1.0)); /* loss constant */ + double b2 = *p->loss; + double dxmin = 2.0*sqrt(dt*(b2+hypot(*p->loss, *p->stiff))); + uint32_t Nx = (p->Nx = (uint32_t)floor(1.0/dxmin)); + uint32_t Nx5 = Nx+5; + double dx = 1.0/(double)Nx; + uint32_t Ny = (p->Ny = (uint32_t)floor(a*Nx)); + double dy = (p->dy = *p->asp/Ny); + double alf = dx/dy; + double mu = dt*(*p->stiff)*Nx*Nx; + double mu2 = mu*mu; + double eta = 1.0/(1.0+sig*dt); + double V = 2.0*b2*dt*Nx*Nx; + uint32_t qq; + + p->nin = (int) (p->INOCOUNT) - 7; p->nout = (int) (p->OUTOCOUNT); + if (UNLIKELY((inp = csound->FTnp2Find(csound,p->tabins)) == NULL || + inp->flen < (unsigned)3*p->nin)) { + return csound->InitError(csound, Str("Missing input table or too short")); + } + if (UNLIKELY((outp = csound->FTnp2Find(csound,p->tabout)) == NULL || + outp->flen < (unsigned int)3*p->nout)) { + return csound->InitError(csound, Str("Missing output table or too short")); + } + p->in_param = inp->ftable; + p->out_param = outp->ftable; + p->L = (a<1.0 ? a : 1.0); + csound->AuxAlloc(csound, 3*Nx5*(Ny+5)*sizeof(double), &p->auxch); + p->u = (double*)p->auxch.auxp; + p->u1 = p->u+Nx5*(Ny+5); + p->u2 = p->u1+Nx5*(Ny+5); + p->s00 = 2.0*eta*(1.0-mu2*(3.0+4.0*alf*alf+3.0*alf*alf*alf*alf)- + V*(1.0+alf*alf)); + p->s10 = (4.0*mu2*(1.0+alf*alf)+V)*eta; + p->s01 = alf*alf*(4.0*mu2*(1.0+alf*alf)+V)*eta; + p->s11 = -2.0*mu2*eta*alf*alf; + p->s02 = (p->s20 = -eta*mu2)*alf*alf*alf*alf; + p->t00 = (-(1.0-sig*dt)+2.0*V*(1.0+alf*alf))*eta; + p->t10 = -V*eta; + p->t01 = -V*eta*alf*alf; + for (qq=0; qqnin; qq++) { + p->ci[qq] = cos((double)p->in_param[3*qq+2]); + p->si[qq] = sin((double)p->in_param[3*qq+2]); + } + for (qq=0; qqnout; qq++) { + p->co[qq] = cos((double)p->out_param[3*qq+2]); + p->so[qq] = sin((double)p->out_param[3*qq+2]); + } + + return OK; +} + + +static int platerev(CSOUND *csound, PLATE *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, j, nsmps = CS_KSMPS; + uint32_t Ny = p->Ny, Nx = p->Nx; + uint32_t Nx5 = Nx+5; + int bc = (int) MYFLT2LONG(*p->bndry); + double *u = p->u, *u1 = p->u1, *u2 = p->u2; + double s00 = p->s00, s10 = p->s10, s01 = p->s01, + s11 = p->s11, s20 = p->s20, s02 = p->s02, + t00 = p->t00, t10 = p->t10, t01 = p->t01; + double dt = p->dt, dy = p->dy; + uint32_t n, qq; + MYFLT *uin; + double wi[40], wo[40], sdi[40], cdi[40], sdo[40], cdo[40]; + + if (UNLIKELY(early)) nsmps -= early; + for (qq=0; qq<(uint32_t)p->nin; qq++) { + double delta = TWOPI*(double)p->in_param[3*qq]*dt; + cdi[qq] = cos(delta); + sdi[qq] = sin(delta); + wi[qq] = p->L*0.5*(double)p->in_param[3*qq+1]; + delta = TWOPI*(double)p->out_param[3*qq]*dt; + cdo[qq] = cos(delta); + sdo[qq] = sin(delta); + wo[qq] = (p->L*0.5)*(double)p->out_param[3*qq+1]; + if (UNLIKELY(offset)) memset(p->aout[qq], '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&p->aout[qq][nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nnin; qq++) { + double w = wi[qq]; + double cv = p->ci[qq]*cdi[qq] - p->si[qq]*sdi[qq]; + double sv = p->ci[qq]*sdi[qq] + p->si[qq]*cdi[qq]; + double xid = (0.5+w*cv)*Nx; + double yid = ((*p->asp)*0.5+w*sv)/dy; + int xi = (int)(floor(xid))+2; + int yi = (int)(floor(yid))+2; + double xf = xid-(double)(xi-2); + double yf = yid-(double)(yi-2); + double xyf = xf*yf; + uin=p->ain[qq]; + p->ci[qq] = cv; p->si[qq] = sv; + yi = Nx5*yi + xi; + u[yi] += (1.0-xf-yf+xyf)*uin[n]; + u[1+yi] += (xf-xyf)*uin[n]; + u[1+Nx5+yi] += xyf*uin[n]; + u[Nx5+yi] += (yf-xyf)*uin[n]; + } + /* %%%% readout */ + for (qq=0; qqnout; qq++) { + double w = wo[qq]; + double cv = p->co[qq]*cdo[qq] - p->so[qq]*sdo[qq]; + double sv = p->co[qq]*sdo[qq] + p->so[qq]*cdo[qq]; + double xod = (0.5+w*cv)*Nx; + double yod = (*p->asp*0.5+w*sv)/dy; + int xo = (int)(floor(xod))+2; + int yo = (int)(floor(yod))+2; + double xf = xod-(double)(xo-2); + double yf = yod-(double)(yo-2); + double xyf = xf*yf; + p->co[qq] = cv; p->so[qq] = sv; + yo = yo*Nx5 + xo; + (p->aout[qq])[n] = (MYFLT)((1.0-xf-yf+xyf)*u[yo]+ + (yf-xyf)*u[Nx5+yo]+ + (xf-xyf)*u[1+yo]+ + xyf*u[1+Nx5+yo])/FL(25.0); + } + { + double *tmp = u2; /* cycle U*/ + u2 = u1; + u1 = u; + u = tmp; + } + } + p->u = u; p->u1 = u1; p->u2 = u2; + return OK; +} + +static OENTRY localops[] = { + { "platerev", sizeof(PLATE), 0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "iikiiiiy", + (SUBR) platerev_init, NULL, (SUBR) platerev + }, +}; + +LINKAGE diff -Nru csound-5.17.11~dfsg/Opcodes/pluck.c csound-6.02~dfsg/Opcodes/pluck.c --- csound-5.17.11~dfsg/Opcodes/pluck.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pluck.c 2014-01-07 16:53:48.000000000 +0000 @@ -31,7 +31,7 @@ * Some modifications John ffitch, 2000, simplifying code */ -#include "csdl.h" +#include "stdopcod.h" #include "wavegde.h" #include "pluck.h" @@ -87,7 +87,7 @@ static int pluckPluck(CSOUND *csound, WGPLUCK* p) { /* ndelay = total required delay - 1.0 */ - len_t ndelay = (len_t) (csound->esr / *p->freq - FL(1.0)); + len_t ndelay = (len_t) (CS_ESR / *p->freq - FL(1.0)); #ifdef WG_VERBOSE csound->Message(csound, "pluckPluck -- allocating memory..."); @@ -140,7 +140,7 @@ /* Define the required magnitude response of H1 at w0 and PI */ /* Constrain attenuation specification to dB per second */ - MYFLT NRecip = p->wg.f0 * csound->onedsr; /* N=t*csound->esr/f0 */ + MYFLT NRecip = p->wg.f0 * csound->onedsr; /* N=t*CS_ESR/f0 */ MYFLT H1_w0 = POWER(FL(10.0),-A_w0*FL(0.05)*NRecip); MYFLT H1_PI = POWER(FL(10.0),-A_PI*FL(0.05)*NRecip); { @@ -198,14 +198,21 @@ MYFLT yr0,yl0,yrM,ylM; /* Key positions on the waveguide */ MYFLT *ar = p->out; /* The sample output buffer */ len_t M=p->wg.upperRail.size; /* Length of the guide rail */ - len_t n,nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + len_t n,nsmps=CS_KSMPS; /* int i = 0; */ MYFLT *fdbk = p->afdbk; /* set the delay element to pickup at */ len_t pickupSamp=(len_t)(M * *p->pickupPos); if (UNLIKELY(pickupSamp<1)) pickupSamp = 1; - for (n=0;nwg.upperRail,pickupSamp) +guideRailAccess(&p->wg.lowerRail,M-pickupSamp); yrM = guideRailAccess(&p->wg.upperRail,M-1);/* wave into the nut */ @@ -332,7 +339,7 @@ /* Calculate the size of the delay lines and set them */ /* Set pointers to appropriate positions in instrument memory */ - size = csound->esr / freq - FL(1.0); + size = CS_ESR / freq - FL(1.0); /* construct the fractional part of the delay */ df = (size - (len_t)size); /* fractional delay amount */ @@ -367,13 +374,14 @@ /* error -- report errors */ static void error(CSOUND *csound, const char* a, const char* b) { - csound->Die(csound, Str("Error: %s, %s"), a, b); + csound->ErrorMsg(csound, Str("Error: %s, %s"), a, b); } #define S(x) sizeof(x) static OENTRY localops[] = { -{ "wgpluck",S(WGPLUCK),5,"a","iikiiia",(SUBR)pluckPluck,NULL,(SUBR)pluckGetSamps} +{ "wgpluck",S(WGPLUCK),0, 5,"a","iikiiia", + (SUBR)pluckPluck,NULL,(SUBR)pluckGetSamps} }; int pluck_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/psynth.c csound-6.02~dfsg/Opcodes/psynth.c --- csound-5.17.11~dfsg/Opcodes/psynth.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/psynth.c 2014-01-07 16:53:48.000000000 +0000 @@ -63,7 +63,7 @@ */ -#include "csdl.h" +#include "pvs_ops.h" #include "pstream.h" typedef struct _psyn { @@ -143,13 +143,16 @@ double a, f, frac, incra, incrph, factor; MYFLT scale = *p->scal, pitch = *p->pitch; int ndx, size = p->func->flen; - int i, j, k, n, m, id; + int i, j, k, m, id; int notcontin = 0; int contin = 0; int tracks = p->tracks, maxtracks = (int) *p->maxtracks; MYFLT *tab = p->func->ftable, *out = p->out; float *fin = (float *) p->fin->frame.auxp; - int ksmps = csound->ksmps, pos = p->pos; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int pos = p->pos; double *amps = (double *) p->amps.auxp, *freqs = (double *) p->freqs.auxp; double *phases = (double *) p->phases.auxp; MYFLT *outsum = (MYFLT *) p->sum.auxp; @@ -161,7 +164,12 @@ maxtracks = p->numbins > maxtracks ? maxtracks : p->numbins; - for (n = 0; n < ksmps; n++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { out[n] = outsum[pos]; pos++; if (pos == hopsize) { @@ -301,13 +309,16 @@ double a, frac, incra, incrph, factor, lotwopi, cnt; MYFLT scale = *p->scal; int ndx, size = p->func->flen; - int i, j, k, n, m, id; + int i, j, k, m, id; int notcontin = 0; int contin = 0; int tracks = p->tracks, maxtracks = (int) *p->maxtracks; MYFLT *tab = p->func->ftable, *out = p->out; float *fin = (float *) p->fin->frame.auxp; - int ksmps = csound->ksmps, pos = p->pos; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int pos = p->pos; double *amps = (double *) p->amps.auxp, *freqs = (double *) p->freqs.auxp; double *phases = (double *) p->phases.auxp; MYFLT *outsum = (MYFLT *) p->sum.auxp; @@ -320,7 +331,12 @@ facsqr = p->facsqr; maxtracks = p->numbins > maxtracks ? maxtracks : p->numbins; - for (n = 0; n < ksmps; n++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { out[n] = outsum[pos]; pos++; if (pos == hopsize) { @@ -426,13 +442,16 @@ double a, frac, incra, incrph, factor, lotwopi, cnt; MYFLT scale = *p->scal, pitch = *p->pitch; int ndx, size = p->func->flen; - int i, j, k, n, m, id; + int i, j, k, m, id; int notcontin = 0; int contin = 0; int tracks = p->tracks, maxtracks = (int) *p->maxtracks; MYFLT *tab = p->func->ftable, *out = p->out; float *fin = (float *) p->fin->frame.auxp; - int ksmps = csound->ksmps, pos = p->pos; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int pos = p->pos; double *amps = (double *) p->amps.auxp, *freqs = (double *) p->freqs.auxp; double *phases = (double *) p->phases.auxp; MYFLT *outsum = (MYFLT *) p->sum.auxp; @@ -445,7 +464,12 @@ facsqr = p->facsqr; maxtracks = p->numbins > maxtracks ? maxtracks : p->numbins; - for (n = 0; n < ksmps; n++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { out[n] = outsum[pos]; pos++; if (pos == hopsize) { @@ -587,7 +611,7 @@ { MYFLT scale = *p->kpar; MYFLT gain = (p->kgain != NULL ? *p->kgain : FL(1.0)); - MYFLT nyq = csound->esr * FL(0.5); + MYFLT nyq = CS_ESR * FL(0.5); float *framein = (float *) p->fin->frame.auxp; float *frameout = (float *) p->fout->frame.auxp; int i = 0, id = (int) framein[3], end = p->numbins * 4; @@ -616,7 +640,7 @@ { MYFLT shift = *p->kpar; MYFLT gain = (p->kgain != NULL ? *p->kgain : FL(1.0)); - MYFLT nyq = csound->esr * FL(0.5); + MYFLT nyq = CS_ESR * FL(0.5); float *framein = (float *) p->fin->frame.auxp; float *frameout = (float *) p->fout->frame.auxp; int i = 0, id = (int) framein[3], end = p->numbins * 4; @@ -679,7 +703,7 @@ static int trlowest_process(CSOUND *csound, _PLOW *p) { MYFLT scale = *p->kpar; - MYFLT nyq = csound->esr * FL(0.5); + MYFLT nyq = CS_ESR * FL(0.5); float lowest = (float) nyq, outamp = 0.0f, outph = 0.0f, outid = -1.0f; float *framein = (float *) p->fin->frame.auxp; float *frameout = (float *) p->fout->frame.auxp; @@ -963,7 +987,7 @@ static int trfil_process(CSOUND *csound, _PSFIL *p) { MYFLT amnt = *p->kpar, gain = FL(1.0); - MYFLT nyq = csound->esr * FL(0.5); + MYFLT nyq = CS_ESR * FL(0.5); MYFLT *fil = p->tab->ftable; float *framein = (float *) p->fin->frame.auxp; float *frameout = (float *) p->fout->frame.auxp; @@ -981,8 +1005,8 @@ fr = framein[i + 1]; if (fr > nyq) fr = nyq; - if (fr < 0) - fr = -fr; + //if (fr < 0) + fr = FABS(fr); pos = fr * len / nyq; posi = (int) pos; frac = pos - posi; @@ -1155,8 +1179,8 @@ float *framein = (float *) p->fsig2->frame.auxp; int i = 0, n = 0, id = (int) framein[3], end = p->numbins * 4; int maxi = -1; - MYFLT bw = csound->esr / (MYFLT)N, boundup, boundown; - MYFLT nyq = csound->esr * FL(0.5), centre; + MYFLT bw = CS_ESR / (MYFLT)N, boundup, boundown; + MYFLT nyq = CS_ESR * FL(0.5), centre; if (p->lastframe < p->fsig2->framecount) { @@ -1197,40 +1221,40 @@ static OENTRY localops[] = { - {"tradsyn", sizeof(_PSYN), 5, "a", "fkkki", (SUBR) psynth_init, NULL, + {"tradsyn", sizeof(_PSYN),0, 5, "a", "fkkki", (SUBR) psynth_init, NULL, (SUBR) psynth_process} , - {"sinsyn", sizeof(_PSYN2), TR|5, "a", "fkki", (SUBR) psynth2_init, NULL, + {"sinsyn", sizeof(_PSYN2), TR, 5, "a", "fkki", (SUBR) psynth2_init, NULL, (SUBR) psynth2_process} , - {"resyn", sizeof(_PSYN), TR|5, "a", "fkkki", (SUBR) psynth_init, NULL, + {"resyn", sizeof(_PSYN), TR, 5, "a", "fkkki", (SUBR) psynth_init, NULL, (SUBR) psynth3_process} , - {"trscale", sizeof(_PTRANS), 3, "f", "fz", (SUBR) trans_init, + {"trscale", sizeof(_PTRANS),0, 3, "f", "fz", (SUBR) trans_init, (SUBR) trscale_process} , - {"trshift", sizeof(_PTRANS), 3, "f", "fz", (SUBR) trans_init, + {"trshift", sizeof(_PTRANS),0, 3, "f", "fz", (SUBR) trans_init, (SUBR) trshift_process} , - {"trsplit", sizeof(_PSPLIT), 3, "ff", "fz", (SUBR) trsplit_init, + {"trsplit", sizeof(_PSPLIT),0, 3, "ff", "fz", (SUBR) trsplit_init, (SUBR) trsplit_process} , - {"trmix", sizeof(_PSMIX), 3, "f", "ff", (SUBR) trmix_init, + {"trmix", sizeof(_PSMIX),0, 3, "f", "ff", (SUBR) trmix_init, (SUBR) trmix_process} , - {"trlowest", sizeof(_PLOW), 3, "fkk", "fk", (SUBR) trlowest_init, + {"trlowest", sizeof(_PLOW),0, 3, "fkk", "fk", (SUBR) trlowest_init, (SUBR) trlowest_process} , - {"trhighest", sizeof(_PLOW), 3, "fkk", "fk", (SUBR) trlowest_init, + {"trhighest", sizeof(_PLOW),0, 3, "fkk", "fk", (SUBR) trlowest_init, (SUBR) trhighest_process} , - {"trfilter", sizeof(_PSFIL), 3, "f", "fki", (SUBR) trfil_init, + {"trfilter", sizeof(_PSFIL),0, 3, "f", "fki", (SUBR) trfil_init, (SUBR) trfil_process} , - {"trcross", sizeof(_PSCROSS), 3, "f", "ffkz", (SUBR) trcross_init, + {"trcross", sizeof(_PSCROSS),0, 3, "f", "ffkz", (SUBR) trcross_init, (SUBR) trcross_process} , - {"binit", sizeof(_PSBIN), 3, "f", "fi", (SUBR) binit_init, + {"binit", sizeof(_PSBIN),0, 3, "f", "fi", (SUBR) binit_init, (SUBR) binit_process} }; diff -Nru csound-5.17.11~dfsg/Opcodes/pvadd.c csound-6.02~dfsg/Opcodes/pvadd.c --- csound-5.17.11~dfsg/Opcodes/pvadd.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvadd.c 2014-01-07 16:53:48.000000000 +0000 @@ -62,7 +62,7 @@ } } -int pvaddset(CSOUND *csound, PVADD *p) +int pvaddset_(CSOUND *csound, PVADD *p, int stringname) { int ibins; char pvfilnam[MAXNAME]; @@ -76,11 +76,17 @@ p->ftp = ftp; if (*p->igatefun > FL(0.0)) - if (UNLIKELY((AmpGateFunc = csound->FTFind(csound, p->igatefun)) == NULL)) + if (UNLIKELY((AmpGateFunc = csound->FTnp2Find(csound, p->igatefun)) == NULL)) return NOTOK; p->AmpGateFunc = AmpGateFunc; - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (UNLIKELY(pvx_loadfile(csound, pvfilnam, p) != OK)) return NOTOK; @@ -133,7 +139,10 @@ MYFLT *ar, *ftab; MYFLT frIndx; int size = pvfrsiz(p); - int i, binincr = (int) *p->ibinincr, n, nsmps = csound->ksmps; + int i, binincr = (int) *p->ibinincr; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp, frq, v1, fract, *oscphase; int32 phase, incr; FUNC *ftp; @@ -158,12 +167,13 @@ ar = p->rslt; memset(ar, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; oscphase = p->oscphase; for (i = (int) *p->ibinoffset; i < p->maxbin; i += binincr) { lobits = ftp->lobits; phase = (int32) *oscphase; frq = p->buf[i * 2 + 1] * *p->kfmod; - if (p->buf[i * 2 + 1] == FL(0.0) || frq >= csound->esr * FL(0.5)) { + if (p->buf[i * 2 + 1] == FL(0.0) || frq >= CS_ESR * FL(0.5)) { incr = 0; /* Hope then does not matter */ amp = FL(0.0); } @@ -172,7 +182,7 @@ incr = (int32) MYFLT2LONG(tmp); amp = p->buf[i * 2]; } - for (n=0;nftable + (phase >> lobits); v1 = *ftab++; @@ -185,11 +195,20 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvadd: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("pvadd: not initialised")); err2: - return csound->PerfError(csound, Str("PVADD timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, Str("PVADD timpnt < 0")); +} + +int pvaddset(CSOUND *csound, PVADD *p){ + return pvaddset_(csound, p, 0); } +int pvaddset_S(CSOUND *csound, PVADD *p){ + return pvaddset_(csound, p, 1); +} + + static int pvx_loadfile(CSOUND *csound, const char *fname, PVADD *p) { PVOCEX_MEMFILE pp; @@ -217,7 +236,7 @@ p->maxFr = pp.nframes - 1; p->asr = pp.srate; /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr / (MYFLT) pp.overlap; + p->frPrtim = CS_ESR / (MYFLT) pp.overlap; return OK; } diff -Nru csound-5.17.11~dfsg/Opcodes/pvinterp.c csound-6.02~dfsg/Opcodes/pvinterp.c --- csound-5.17.11~dfsg/Opcodes/pvinterp.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvinterp.c 2014-01-07 16:53:48.000000000 +0000 @@ -30,13 +30,13 @@ #include #define WLN 1 /* time window is WLN*2*ksmps long */ -#define OPWLEN (2*WLN*csound->ksmps) /* manifest used for final time wdw */ +#define OPWLEN (2*WLN*CS_KSMPS) /* manifest used for final time wdw */ /************************************************************/ /*************PVBUFREAD**************************************/ /************************************************************/ -int pvbufreadset(CSOUND *csound, PVBUFREAD *p) +int pvbufreadset_(CSOUND *csound, PVBUFREAD *p, int stringname) { char pvfilnam[MAXNAME]; PVOCEX_MEMFILE pp; @@ -58,7 +58,13 @@ p->fftBuf = fltp; /* fltp += PVFFTSIZE; */ /* Not needed */ } - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (UNLIKELY(csound->PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) return csound->InitError(csound, Str("PVBUFREAD cannot load %s"), pvfilnam); @@ -67,9 +73,9 @@ frInc = pp.overlap; chans = pp.chans; p->asr = pp.srate; - if (p->asr != csound->esr) { /* & chk the data */ + if (p->asr != CS_ESR) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), - pvfilnam, p->asr, csound->esr); + pvfilnam, p->asr, CS_ESR); } if (p->frSiz > PVFRAMSIZE) { return csound->InitError(csound, @@ -87,8 +93,8 @@ } p->frPtr = (float*) pp.data; p->maxFr = pp.nframes - 1; - p->frPktim = (MYFLT) csound->ksmps / (MYFLT) frInc; - p->frPrtim = csound->esr / (MYFLT) frInc; + p->frPktim = (MYFLT) CS_KSMPS / (MYFLT) frInc; + p->frPrtim = CS_ESR / (MYFLT) frInc; p->prFlg = 1; /* true */ /* amplitude scale for PVOC */ /* p->scale = (MYFLT) pp.fftsize * ((MYFLT) pp.fftsize / (MYFLT) pp.winsize); @@ -99,13 +105,21 @@ if (UNLIKELY((OPWLEN / 2 + 1) > PVWINLEN )) { return csound->InitError(csound, Str("ksmps of %d needs wdw of %d, " "max is %d for pv %s"), - csound->ksmps, (int) (OPWLEN / 2 + 1), + CS_KSMPS, (int) (OPWLEN / 2 + 1), (int) PVWINLEN, pvfilnam); } return OK; } +int pvbufreadset(CSOUND *csound, PVBUFREAD *p){ + return pvbufreadset_(csound,p,0); +} + +int pvbufreadset_S(CSOUND *csound, PVBUFREAD *p){ + return pvbufreadset_(csound,p,1); +} + int pvbufread(CSOUND *csound, PVBUFREAD *p) { MYFLT frIndx; @@ -126,17 +140,18 @@ return OK; err1: - return csound->PerfError(csound, Str("pvbufread: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvbufread: not initialised")); err2: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, Str("PVOC timpnt < 0")); } /************************************************************/ /*************PVINTERP**************************************/ /************************************************************/ -int pvinterpset(CSOUND *csound, PVINTERP *p) +int pvinterpset_(CSOUND *csound, PVINTERP *p, int stringname) { - int i; + unsigned int i; char pvfilnam[MAXNAME]; PVOCEX_MEMFILE pp; int frInc, chans; /* THESE SHOULD BE SAVED IN PVOC STRUCT */ @@ -160,7 +175,12 @@ p->window = fltp; } - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1);; if (UNLIKELY(csound->PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) return csound->InitError(csound, Str("PVINTERP cannot load %s"), pvfilnam); @@ -169,9 +189,9 @@ frInc = pp.overlap; chans = pp.chans; p->asr = pp.srate; - if (p->asr != csound->esr) { /* & chk the data */ + if (p->asr != CS_ESR) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), - pvfilnam, p->asr, csound->esr); + pvfilnam, p->asr, CS_ESR); } if (UNLIKELY(p->frSiz != p->pvbufread->frSiz)) { return csound->InitError(csound, @@ -188,9 +208,9 @@ p->baseFr = 0; /* point to first data frame */ p->maxFr = pp.nframes - 1; /* highest possible frame index */ - p->frPktim = (MYFLT) csound->ksmps / (MYFLT) frInc; + p->frPktim = (MYFLT) CS_KSMPS / (MYFLT) frInc; /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr / (MYFLT) frInc; + p->frPrtim = CS_ESR / (MYFLT) frInc; /* factor by which to mulitply 'real' time index to get frame index */ /* amplitude scale for PVOC */ /* p->scale = (MYFLT) pp.fftsize * ((MYFLT) pp.fftsize / (MYFLT) pp.winsize); @@ -209,7 +229,7 @@ if (UNLIKELY((OPWLEN / 2 + 1) > PVWINLEN)) { return csound->InitError(csound, Str("ksmps of %d needs wdw of %d, " "max is %d for pv %s"), - csound->ksmps, (OPWLEN / 2 + 1), + CS_KSMPS, (OPWLEN / 2 + 1), PVWINLEN, pvfilnam); } for (i = 0; i < OPWLEN / 2 + 1; ++i) /* time window is OPWLEN long */ @@ -223,6 +243,15 @@ return OK; } +int pvinterpset(CSOUND *csound, PVINTERP *p){ + return pvinterpset_(csound,p,0); +} + +int pvinterpset_S(CSOUND *csound, PVINTERP *p){ + return pvinterpset_(csound,p,1); +} + + int pvinterp(CSOUND *csound, PVINTERP *p) { MYFLT *ar = p->rslt; @@ -244,7 +273,8 @@ if (UNLIKELY(outlen>PVFFTSIZE)) /* Maximum transposition down is one octave */ /* ..so we won't run into buf2Size problems */ goto err2; - if (UNLIKELY(outlen<2*csound->ksmps)) goto err3; /* minimum post-squeeze windowlength */ + if (UNLIKELY(outlen<(int)(2*CS_KSMPS))) + goto err3; /* minimum post-squeeze windowlength */ buf2Size = OPWLEN; /* always window to same length after DS */ if (UNLIKELY((frIndx = *p->ktimpnt * p->frPrtim) < 0)) goto err4; if (frIndx > (MYFLT)p->maxFr) { /* not past last one */ @@ -268,7 +298,7 @@ buf[j] = (buf[j] + ((q->buf[j] - buf[j]) * *p->kfreqinterp)); } /*******************************************************************/ - FrqToPhase(buf, asize, pex * (MYFLT) csound->ksmps, p->asr, + FrqToPhase(buf, asize, pex * (MYFLT) CS_KSMPS, p->asr, (MYFLT) (0.5 * ((pex / p->lastPex) - 1))); /* accumulate phase and wrap to range -PI to PI */ RewrapPhase(buf, asize, p->lastPhase); @@ -284,32 +314,35 @@ sizeof(MYFLT) * buf2Size); ApplyHalfWin(buf2, p->window, buf2Size); - addToCircBuf(buf2, p->outBuf, p->opBpos, csound->ksmps, circBufSize); - writeClrFromCircBuf(p->outBuf, ar, p->opBpos, csound->ksmps, circBufSize); - p->opBpos += csound->ksmps; + addToCircBuf(buf2, p->outBuf, p->opBpos, CS_KSMPS, circBufSize); + writeClrFromCircBuf(p->outBuf, ar, p->opBpos, CS_KSMPS, circBufSize); + p->opBpos += CS_KSMPS; if (p->opBpos > circBufSize) p->opBpos -= circBufSize; - addToCircBuf(buf2 + csound->ksmps, p->outBuf, p->opBpos, - buf2Size - csound->ksmps, circBufSize); + addToCircBuf(buf2 + CS_KSMPS, p->outBuf, p->opBpos, + buf2Size - CS_KSMPS, circBufSize); p->lastPex = pex; /* needs to know last pitchexp to update phase */ return OK; err1: - return csound->PerfError(csound, Str("pvinterp: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvinterp: not initialised")); err2: - return csound->PerfError(csound, Str("PVOC transpose too low")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too low")); err3: - return csound->PerfError(csound, Str("PVOC transpose too high")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too high")); err4: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, Str("PVOC timpnt < 0")); } /************************************************************/ /************* PVCROSS **************************************/ /************************************************************/ -int pvcrossset(CSOUND *csound, PVCROSS *p) +int pvcrossset_(CSOUND *csound, PVCROSS *p, int stringname) { - int i; + uint32_t i; char pvfilnam[MAXNAME]; PVOCEX_MEMFILE pp; int frInc, chans; /* THESE SHOULD BE SAVED IN PVOC STRUCT */ @@ -332,7 +365,13 @@ p->outBuf = fltp; fltp += PVFFTSIZE; p->window = fltp; } - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if(stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (UNLIKELY(csound->PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) return csound->InitError(csound, Str("PVCROSS cannot load %s"), pvfilnam); @@ -340,9 +379,9 @@ frInc = pp.overlap; chans = pp.chans; p->asr = pp.srate; - if (p->asr != csound->esr) { /* & chk the data */ + if (p->asr != CS_ESR) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), - pvfilnam, p->asr, csound->esr); + pvfilnam, p->asr, CS_ESR); } if (UNLIKELY(p->frSiz != p->pvbufread->frSiz)) { return csound->InitError(csound, @@ -359,9 +398,9 @@ p->baseFr = 0; /* point to first data frame */ p->maxFr = pp.nframes - 1; /* highest possible frame index */ - p->frPktim = (MYFLT) csound->ksmps / (MYFLT) frInc; + p->frPktim = (MYFLT) CS_KSMPS / (MYFLT) frInc; /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr / (MYFLT) frInc; + p->frPrtim = CS_ESR / (MYFLT) frInc; /* factor by which to mulitply 'real' time index to get frame index */ /* amplitude scale for PVOC */ /* p->scale = (MYFLT) pp.fftsize * ((MYFLT) pp.fftsize / (MYFLT) pp.winsize); @@ -378,7 +417,7 @@ if (UNLIKELY((OPWLEN / 2 + 1) > PVWINLEN )) { return csound->InitError(csound, Str("ksmps of %d needs wdw of %d, " "max is %d for pv %s"), - csound->ksmps, (OPWLEN / 2 + 1), + CS_KSMPS, (OPWLEN / 2 + 1), PVWINLEN, pvfilnam); } for (i = 0; i < OPWLEN / 2 + 1; ++i) /* time window is OPWLEN long */ @@ -393,6 +432,14 @@ return OK; } +int pvcrossset(CSOUND *csound, PVCROSS *p){ + return pvcrossset_(csound,p,0); +} + +int pvcrossset_S(CSOUND *csound, PVCROSS *p) { +return pvcrossset_(csound,p,1); +} + int pvcross(CSOUND *csound, PVCROSS *p) { MYFLT *ar = p->rslt; @@ -414,10 +461,10 @@ pex = *p->kfmod; outlen = (int) (((MYFLT) size) / pex); /* use outlen to check window/krate/transpose combinations */ - if (UNLIKELY(outlen>PVFFTSIZE)) /* Maximum transposition down is one octave */ - /* ..so we won't run into buf2Size problems */ + if (UNLIKELY(outlen>PVFFTSIZE)) /* Maximum transposition down is one octave */ + /* ..so we won't run into buf2Size problems */ goto err2; - if (UNLIKELY(outlen<2*csound->ksmps)) /* minimum post-squeeze windowlength */ + if (UNLIKELY(outlen<(int)(2*CS_KSMPS))) /* minimum post-squeeze windowlength */ goto err3; buf2Size = OPWLEN; /* always window to same length after DS */ if ((frIndx = *p->ktimpnt * p->frPrtim) < 0) goto err4; @@ -438,7 +485,7 @@ buf[i] = ((buf[i] * ampscale2) + (q->buf[i] * ampscale1)) * scaleFac; /***************************************************/ - FrqToPhase(buf, asize, pex * (MYFLT) csound->ksmps, p->asr, + FrqToPhase(buf, asize, pex * (MYFLT) CS_KSMPS, p->asr, (MYFLT) (0.5 * ((pex / p->lastPex) - 1))); /* accumulate phase and wrap to range -PI to PI */ RewrapPhase(buf, asize, p->lastPhase); @@ -451,7 +498,7 @@ csound->Message(csound, Str("PVOC debug: one frame gets through\n")); #endif if (specwp > 0) - PreWarpSpec(p->pp, buf, asize, pex, (MYFLT *)p->memenv.auxp); + PreWarpSpec(buf, asize, pex, (MYFLT *)p->memenv.auxp); Polar2Real_PVOC(csound, buf, (int) size); @@ -469,23 +516,26 @@ memset(buf2, 0, buf2Size*sizeof(MYFLT)); } - addToCircBuf(buf2, p->outBuf, p->opBpos, csound->ksmps, circBufSize); - writeClrFromCircBuf(p->outBuf, ar, p->opBpos, csound->ksmps, circBufSize); - p->opBpos += csound->ksmps; + addToCircBuf(buf2, p->outBuf, p->opBpos, CS_KSMPS, circBufSize); + writeClrFromCircBuf(p->outBuf, ar, p->opBpos, CS_KSMPS, circBufSize); + p->opBpos += CS_KSMPS; if (p->opBpos > circBufSize) p->opBpos -= circBufSize; - addToCircBuf(buf2 + csound->ksmps, p->outBuf, p->opBpos, - buf2Size - csound->ksmps, circBufSize); + addToCircBuf(buf2 + CS_KSMPS, p->outBuf, p->opBpos, + buf2Size - CS_KSMPS, circBufSize); p->lastPex = pex; /* needs to know last pitchexp to update phase */ return OK; err1: - return csound->PerfError(csound, Str("pvcross: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvcross: not initialised")); err2: - return csound->PerfError(csound, Str("PVOC transpose too low")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too low")); err3: - return csound->PerfError(csound, Str("PVOC transpose too high")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too high")); err4: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC timpnt < 0")); } - diff -Nru csound-5.17.11~dfsg/Opcodes/pvlock.c csound-6.02~dfsg/Opcodes/pvlock.c --- csound-5.17.11~dfsg/Opcodes/pvlock.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvlock.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,5 +1,5 @@ /* - crossfm.c: + pvlock.c: Copyright (C) 2009 V Lazzarini @@ -28,25 +28,36 @@ typedef struct dats{ OPDS h; - MYFLT *out[MAXOUTS], *time, *kamp, *kpitch, *knum, *klock, *iN, *idecim, *konset, *offset, *dbthresh; - int cnt, hsize, curframe, N, decim,tscale,nchans; + MYFLT *out[MAXOUTS], *time, *kamp, *kpitch, *knum, *klock, *iN, + *idecim, *konset, *offset, *dbthresh; + int cnt, hsize, curframe, N, decim,tscale; + unsigned int nchans; double pos; MYFLT accum; - AUXCH outframe[MAXOUTS], win, bwin[MAXOUTS], fwin[MAXOUTS], nwin[MAXOUTS], prev[MAXOUTS], framecount[MAXOUTS]; + AUXCH outframe[MAXOUTS], win, bwin[MAXOUTS], fwin[MAXOUTS], + nwin[MAXOUTS], prev[MAXOUTS], framecount[MAXOUTS], indata[2]; + MYFLT *tab; + int curbuf; + SNDFILE *sf; + FDCH fdch; + MYFLT resamp; } DATASPACE; + static int sinit(CSOUND *csound, DATASPACE *p) { - int N = *p->iN, i,size, nchans; + int N = *p->iN, ui; + unsigned int nchans, i; + unsigned int size; int decim = *p->idecim; if (N) { for (i=0; N; i++){ N >>= 1; } - N = (int) pow(2., i-1.); + N = (int) pow(2.0, i-1); } else N = 2048; if (decim == 0) decim = 4; @@ -54,12 +65,14 @@ p->cnt = p->hsize; p->curframe = 0; - nchans = csound->GetOutputArgCnt(p); + nchans = p->nchans; + if (UNLIKELY(nchans < 1 || nchans > MAXOUTS)) - csound->Die(csound, Str("invalid number of output arguments")); + csound->InitError(csound, Str("invalid number of output arguments")); p->nchans = nchans; for (i=0; i < nchans; i++){ + size = (N+2)*sizeof(MYFLT); if (p->fwin[i].auxp == NULL || p->fwin[i].size < size) csound->AuxAlloc(csound, size, &p->fwin[i]); @@ -82,24 +95,35 @@ if (p->win.auxp == NULL || p->win.size < size) csound->AuxAlloc(csound, size, &p->win); - for (i=0; i < N; i++) - ((MYFLT *)p->win.auxp)[i] = 0.5 - 0.5*cos(i*2*PI/N); + { + MYFLT x = FL(2.0)*PI_F/N; + for (ui=0; ui < N; ui++) + ((MYFLT *)p->win.auxp)[ui] = FL(0.5) - FL(0.5)*COS((MYFLT)ui*x); + } p->N = N; p->decim = decim; + return OK; } +static int sinit1(CSOUND *csound, DATASPACE *p){ + p->nchans = csound->GetOutputArgCnt(p); + return sinit(csound, p); +} -static int sprocess(CSOUND *csound, DATASPACE *p) +static int sprocess1(CSOUND *csound, DATASPACE *p) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; MYFLT pitch = *p->kpitch, *time = p->time, lock = *p->klock, *out, amp =*p->kamp; MYFLT *tab, frac; FUNC *ft; int N = p->N, hsize = p->hsize, cnt = p->cnt, nchans = p->nchans; - int ksmps = csound->GetKsmps(csound), n; - int sizefrs, size, post, i, j, spos = p->pos; + int nsmps = CS_KSMPS, n; + int sizefrs, size, post, i, j; + long spos = p->pos; double pos; MYFLT *fwin, *bwin, in, *prev, *win = (MYFLT *) p->win.auxp; @@ -108,7 +132,22 @@ int *framecnt; int curframe = p->curframe, decim = p->decim; - for (n=0; n < ksmps; n++) { + if (UNLIKELY(early)) { + nsmps -= early; + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + } + if (UNLIKELY(offset)) { + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(out, '\0', offset*sizeof(MYFLT)); + } + } + + + for (n=offset; n < nsmps; n++) { if (cnt == hsize) { /* audio samples are stored in a function table */ @@ -117,9 +156,10 @@ size = ft->flen; if (UNLIKELY((int) ft->nchanls != nchans)) - return csound->PerfError(csound, Str("number of output arguments " - "inconsistent with number of " - "sound file channels")); + return csound->PerfError(csound, p->h.insdshead, + Str("number of output arguments " + "inconsistent with number of " + "sound file channels")); @@ -127,14 +167,13 @@ time[n] is current read position in secs esr is sampling rate */ - spos = hsize*(int)((time[n])*csound->esr/hsize); + spos = hsize*(long)((time[n])*CS_ESR/hsize); sizefrs = size/nchans; - while(spos > sizefrs - N) spos -= sizefrs; - while(spos <= hsize) spos += sizefrs; - pos = spos; + while(spos > sizefrs) spos -= sizefrs; + while(spos <= 0) spos += sizefrs; for (j = 0; j < nchans; j++) { - + pos = spos; bwin = (MYFLT *) p->bwin[j].auxp; fwin = (MYFLT *) p->fwin[j].auxp; prev = (MYFLT *)p->prev[j].auxp; @@ -150,17 +189,21 @@ frac = pos - post; post *= nchans; post += j; - if (post >= 0 && post < size) - in = tab[post] + frac*(tab[post+nchans] - tab[post]); - else in = (MYFLT) 0; + while (post < 0) post += size; + while (post >= size) post -= size; + + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + fwin[i] = in * win[i]; /* window it */ /* back windo, bwin */ post = (int) (pos - hsize*pitch); post *= nchans; post += j; - if (post >= 0 && post < size) - in = tab[post] + frac*(tab[post+nchans] - tab[post]); - else in = (MYFLT) 0; + while(post < 0) post += size; + while(post >= size) post -= size; + + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + bwin[i] = in * win[i]; /* window it */ /* increment read pos according to pitch transposition */ pos += pitch; @@ -269,13 +312,14 @@ static int sinit2(CSOUND *csound, DATASPACE *p) { - int size,i; + unsigned int size,i; + p->nchans = csound->GetOutputArgCnt(p); sinit(csound, p); size = p->N*sizeof(MYFLT); for (i=0; i < p->nchans; i++) if (p->nwin[i].auxp == NULL || p->nwin[i].size < size) csound->AuxAlloc(csound, size, &p->nwin[i]); - p->pos = *p->offset*csound->esr + p->hsize; + p->pos = *p->offset*CS_ESR + p->hsize; p->tscale = 0; p->accum = 0; return OK; @@ -283,12 +327,14 @@ static int sprocess2(CSOUND *csound, DATASPACE *p) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; MYFLT pitch = *p->kpitch, time = *p->time, lock = *p->klock; MYFLT *out, amp =*p->kamp; MYFLT *tab,frac, dbtresh = *p->dbthresh; FUNC *ft; int N = p->N, hsize = p->hsize, cnt = p->cnt, sizefrs, nchans = p->nchans; - int ksmps = csound->GetKsmps(csound), n; + int nsmps = CS_KSMPS, n; int size, post, i, j; double pos, spos = p->pos; MYFLT *fwin, *bwin; @@ -299,7 +345,21 @@ int *framecnt, curframe = p->curframe; int decim = p->decim; - for (n=0; n < ksmps; n++) { + if (UNLIKELY(early)) { + nsmps -= early; + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + } + if (UNLIKELY(offset)) { + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(out, '\0', offset*sizeof(MYFLT)); + } + } + + for (n=offset; n < nsmps; n++) { if (cnt == hsize){ ft = csound->FTnp2Find(csound,p->knum); @@ -319,17 +379,18 @@ p->tscale = 1; } if (UNLIKELY((int) ft->nchanls != nchans)) - return csound->PerfError(csound, Str("number of output arguments " - "inconsistent with number of " - "sound file channels")); + return csound->PerfError(csound, p->h.insdshead, + Str("number of output arguments " + "inconsistent with number of " + "sound file channels")); sizefrs = size/nchans; - while(spos > sizefrs - N - hsize) spos -= sizefrs; - while(spos <= hsize) spos += sizefrs; - pos = spos; + while(spos > sizefrs) spos -= sizefrs; + while(spos <= 0) spos += sizefrs; - for (j = 0; j < nchans; j++) { + for (j = 0; j < nchans; j++) { + pos = spos; bwin = (MYFLT *) p->bwin[j].auxp; fwin = (MYFLT *) p->fwin[j].auxp; nwin = (MYFLT *) p->nwin[j].auxp; @@ -342,9 +403,11 @@ frac = pos - post; post *= nchans; post += j; - if (post >= 0 && post < size) - in = tab[post] + frac*(tab[post+nchans] - tab[post]); - else in = (MYFLT) 0; + + while(post < 0) post += size; + while(post >= size) post -= size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + fwin[i] = in * win[i]; post = (int) (pos - hsize*pitch); @@ -357,8 +420,9 @@ post = (int) pos + hsize; post *= nchans; post += j; - if (post >= 0 && post < size) in = tab[post]; - else in = (MYFLT) 0; + while(post < 0) post += size; + while(post >= size) post -= size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); nwin[i] = in * win[i]; pos += pitch; } @@ -462,6 +526,288 @@ return OK; } +#if 0 +#define BUFS 10 + +/* file-reading version of temposcal */ +static int sinit3(CSOUND *csound, DATASPACE *p) +{ + unsigned int size,i; + char *name; + SF_INFO sfinfo; + // open file + name = ((STRINGDATA *)p->num)->data; + sf = (SNDFILE *) csound->FileOpen2(csound, &(p->sf), CSFILE_SND_R, name, &sfinfo, + "SFDIR;SSDIR", CSFTYPE_UNKNOWN_AUDIO, 0); + if(sfinfo.rate != CS_ESR) + p->resamp = CS_ESR/sfinfo.rate; + else + p->resamp = 1; + p->nchans = sfinfo.chans; + + sinit(csound, p); + size = p->N*sizeof(MYFLT); + for (i=0; i < p->nchans; i++) + if (p->nwin[i].auxp == NULL || p->nwin[i].size < size) + csound->AuxAlloc(csound, size, &p->nwin[i]); + + size = p->N*sizeof(MYFLT)*BUFS; + if (p->indata[0].auxp == NULL || p->indata[0].size < size) + csound->AuxAlloc(csound, size, &p->indata[0]); + if (p->indata[1].auxp == NULL || p->indata[1].size < size) + csound->AuxAlloc(csound, size, &p->indata[1]); + + memset(&(p->fdch), 0, sizeof(FDCH)); + p->fdch.fd = fd; + fdrecord(csound, &(p->fdch)); + + // fill buffers + fillbuffer(csound, p, 0); + fillbuffer(csound, p, size/sizeof(MYFLT)); + p->pos = *p->offset*CS_ESR + p->hsize; + p->tscale = 0; + p->accum = 0; + p->tab = (MYFLT *) p->indata[0].auxp; + p->curbuf = 0; + + + return OK; +} + +/* + this will read a buffer full of samples + from disk position offset samps from the last + call to fillbuf +*/ + +MYFLT *fillbuf(CSOUND *csound, DATASPACE *p, int offset){ + + sf_count_t sampsread; + + // find read position + sf_seek(p->sf, offset, SEEK_CUR); + + // fill p->curbuf + sampsread = sf_read_MYFLT(p->sf, p->indata[curbuf].auxp, + p->indata[curbuf].size/sizeof(MYFLT)); + + // place read pointer at the read position + sf_seek(p->sf, -sampsread, SEEK_CUR); + + // point to the other + p->curbuf = p->curbuf ? 0 : 1; + return (p->tab = (MYFLT *) p->indata[p->curbuf].auxp); +} + +static int sprocess3(CSOUND *csound, DATASPACE *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + MYFLT pitch = *p->kpitch*p->resamp, time = *p->time, lock = *p->klock; + MYFLT *out, amp =*p->kamp; + MYFLT *tab,frac, dbtresh = *p->dbthresh; + FUNC *ft; + int N = p->N, hsize = p->hsize, cnt = p->cnt, sizefrs, nchans = p->nchans; + int nsmps = CS_KSMPS, n; + int size, post, i, j; + double pos, spos = p->pos; + MYFLT *fwin, *bwin; + MYFLT in, *nwin, *prev; + MYFLT *win = (MYFLT *) p->win.auxp, *outframe; + MYFLT powrat; + MYFLT ph_real, ph_im, tmp_real, tmp_im, div; + int *framecnt, curframe = p->curframe; + int decim = p->decim; + int outnum = csound->GetOutputArgCnt(p); + + if (UNLIKELY(early)) { + nsmps -= early; + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + } + if (UNLIKELY(offset)) { + for (j=0; j < nchans; j++) { + out = p->out[j]; + memset(out, '\0', offset*sizeof(MYFLT)); + } + } + + for (n=offset; n < nsmps; n++) { + + if (cnt == hsize){ + tab = p->tab; + size = indata[0].size/sizeof(MYFLT); + + if (time < 0 || time >= 1 || !*p->konset) { + spos += hsize*time; + } + else if (p->tscale) { + spos += hsize*(time/(1+p->accum)); + p->accum=0.0; + } + else { + spos += hsize; + p->accum++; + p->tscale = 1; + } + if (UNLIKELY((int) ft->nchanls != nchans)) + return csound->PerfError(csound, p->h.insdshead, + Str("number of output arguments " + "inconsistent with number of " + "sound file channels")); + sizefrs = size/nchans; + + while(spos > sizefrs) { + tab = fillbuffer(csound, p, size*sizeof(MYFLT)); + spos -= sizefrs; + } + while(spos <= 0){ + tab = fillbuffer(csound, p, -size*sizeof(MYFLT)); + spos += sizefrs; + } + + for (j = 0; j < nchans; j++) { + pos = spos; + bwin = (MYFLT *) p->bwin[j].auxp; + fwin = (MYFLT *) p->fwin[j].auxp; + nwin = (MYFLT *) p->nwin[j].auxp; + prev = (MYFLT *)p->prev[j].auxp; + framecnt = (int *)p->framecount[j].auxp; + outframe= (MYFLT *) p->outframe[j].auxp; + + for (i=0; i < N; i++) { + post = (int) pos; + frac = pos - post; + post *= nchans; + post += j; + + while(post < 0) post += size; + while(post >= size) post -= size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + + fwin[i] = in * win[i]; + + post = (int) (pos - hsize*pitch); + post *= nchans; + post += j; + if (post >= 0 && post < size) + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + else in = (MYFLT) 0; + bwin[i] = in * win[i]; + post = (int) pos + hsize; + post *= nchans; + post += j; + while(post < 0) post += size; + while(post >= size) post -= size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); + nwin[i] = in * win[i]; + pos += pitch; + } + + csound->RealFFT(csound, bwin, N); + bwin[N] = bwin[1]; + bwin[N+1] = FL(0.0); + csound->RealFFT(csound, fwin, N); + csound->RealFFT(csound, nwin, N); + + tmp_real = tmp_im = (MYFLT) 1e-20; + for (i=2; i < N; i++) { + tmp_real += nwin[i]*nwin[i] + nwin[i+1]*nwin[i+1]; + tmp_im += fwin[i]*fwin[i] + fwin[i+1]*fwin[i+1]; + } + powrat = FL(20.0)*LOG10(tmp_real/tmp_im); + if (powrat > dbtresh) p->tscale=0; + /*else tscale=1;*/ + + fwin[N] = fwin[1]; + fwin[N+1] = FL(0.0); + + for (i=0; i < N + 2; i+=2) { + + div = FL(1.0)/(HYPOT(prev[i], prev[i+1]) + 1.0e-20); + ph_real = prev[i]*div; + ph_im = prev[i+1]*div; + + tmp_real = bwin[i] * ph_real + bwin[i+1] * ph_im; + tmp_im = bwin[i] * ph_im - bwin[i+1] * ph_real; + bwin[i] = tmp_real; + bwin[i+1] = tmp_im; + } + + for (i=0; i < N + 2; i+=2) { + if (lock) { + if (i > 0) { + if (i < N) { + tmp_real = bwin[i] + bwin[i-2] + bwin[i+2]; + tmp_im = bwin[i+1] + bwin[i-1] + bwin[i+3]; + } + else { + tmp_real = bwin[i] + bwin[i-2]; + tmp_im = FL(0.0); + } + } + else { + tmp_real = bwin[i] + bwin[i+2]; + tmp_im = FL(0.0); + } + } + else { + tmp_real = bwin[i]; + tmp_im = bwin[i+1]; + } + + tmp_real += 1e-15; + div = FL(1.0)/(HYPOT(tmp_real, tmp_im)); + + ph_real = tmp_real*div; + ph_im = tmp_im*div; + + tmp_real = fwin[i] * ph_real - fwin[i+1] * ph_im; + tmp_im = fwin[i] * ph_im + fwin[i+1] * ph_real; + + prev[i] = fwin[i] = tmp_real; + prev[i+1] = fwin[i+1] = tmp_im; + } + + fwin[1] = fwin[N]; + csound->InverseRealFFT(csound, fwin, N); + + framecnt[curframe] = curframe*N; + + for (i=0;iout[j]; + framecnt = (int *) p->framecount[j].auxp; + outframe = (MYFLT *) p->outframe[j].auxp; + out[n] = (MYFLT) 0; + + for (i = 0; i < decim; i++) { + out[n] += outframe[framecnt[i]]; + framecnt[i]++; + } + out[n] *= amp*(2./3.); + } + cnt++; + } + p->cnt = cnt; + p->curframe = curframe; + p->pos = spos; + return OK; + +} + +#endif + typedef struct { OPDS h; @@ -530,12 +876,12 @@ } static OENTRY pvlock_localops[] = { - {"mincer", sizeof(DATASPACE), 5, "mm", "akkkkoo", - (SUBR)sinit, NULL,(SUBR)sprocess }, - {"temposcal", sizeof(DATASPACE), 5, "mm", "kkkkkooPOP", + {"mincer", sizeof(DATASPACE), 0, 5, "mm", "akkkkoo", + (SUBR)sinit1, NULL,(SUBR)sprocess1 }, + {"temposcal", sizeof(DATASPACE), 0, 5, "mm", "kkkkkooPOP", (SUBR)sinit2, NULL,(SUBR)sprocess2 }, - {"pvslock", sizeof(PVSLOCK), 3, "f", "fk", (SUBR) pvslockset, + {"pvslock", sizeof(PVSLOCK), 0, 3, "f", "fk", (SUBR) pvslockset, (SUBR) pvslockproc}, }; -LINKAGE1(pvlock_localops) +LINKAGE_BUILTIN(pvlock_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/pvoc.c csound-6.02~dfsg/Opcodes/pvoc.c --- csound-5.17.11~dfsg/Opcodes/pvoc.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvoc.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,29 +21,43 @@ #include "pvoc.h" -int pvset(CSOUND *, void *), pvoc(CSOUND *, void *); +int pvset(CSOUND *, void *), pvset_S(CSOUND *, void *), pvoc(CSOUND *, void *); int pvaddset(CSOUND *, void *), pvadd(CSOUND *, void *); +int pvaddset_S(CSOUND *, void *); int tblesegset(CSOUND *, void *), ktableseg(CSOUND *, void *); int ktablexseg(CSOUND *, void *); -int vpvset(CSOUND *, void *), vpvoc(CSOUND *, void *); +int vpvset(CSOUND *, void *), vpvset_S(CSOUND *, void *), + vpvoc(CSOUND *, void *); int pvreadset(CSOUND *, void *), pvread(CSOUND *, void *); int pvcrossset(CSOUND *, void *), pvcross(CSOUND *, void *); int pvbufreadset(CSOUND *, void *), pvbufread(CSOUND *, void *); int pvinterpset(CSOUND *, void *), pvinterp(CSOUND *, void *); +int pvreadset_S(CSOUND *, void *); +int pvcrossset_S(CSOUND *, void *); +int pvbufreadset_S(CSOUND *, void *); +int pvinterpset_S(CSOUND *, void *); + #define S(x) sizeof(x) static OENTRY pvoc_localops[] = { -{ "pvoc", S(PVOC), 5, "a", "kkToooo", pvset, NULL, pvoc }, -{ "tableseg", S(TABLESEG), TR|3, "", "iin", tblesegset, ktableseg, NULL }, -{ "ktableseg", S(TABLESEG), _QQ|TR|3, "", "iin", tblesegset, ktableseg, NULL }, -{ "tablexseg", S(TABLESEG), TW|3, "", "iin", tblesegset, ktablexseg, NULL }, -{ "vpvoc", S(VPVOC), TR|5, "a", "kkToo", vpvset, NULL, vpvoc }, -{ "pvread", S(PVREAD), 3, "kk", "kTi", pvreadset, pvread, NULL }, -{ "pvcross", S(PVCROSS), 5, "a", "kkTkko", pvcrossset, NULL, pvcross }, -{ "pvbufread", S(PVBUFREAD), 3, "", "kT", pvbufreadset, pvbufread, NULL}, -{ "pvinterp", S(PVINTERP), 5, "a", "kkTkkkkkk", pvinterpset, NULL, pvinterp}, -{ "pvadd", S(PVADD), 5, "a", "kkTiiopooo", pvaddset, NULL, pvadd } +{ "pvoc", S(PVOC), 0, 5, "a", "kkSoooo", pvset_S, NULL, pvoc }, +{ "pvoc.i", S(PVOC), 0, 5, "a", "kkioooo", pvset, NULL, pvoc }, +{ "tableseg", S(TABLESEG), TR, 3, "", "iin", tblesegset, ktableseg, NULL }, +{ "ktableseg", S(TABLESEG), _QQ|TR, 3, "", "iin", tblesegset, ktableseg, NULL }, +{ "tablexseg", S(TABLESEG), TW, 3, "", "iin", tblesegset, ktablexseg, NULL }, +{ "vpvoc", S(VPVOC), TR, 5, "a", "kkSoo", vpvset_S, NULL, vpvoc }, +{ "vpvoc.i", S(VPVOC), TR, 5, "a", "kkioo", vpvset, NULL, vpvoc }, +{ "pvread", S(PVREAD), 0, 3, "kk", "kSi", pvreadset_S, pvread, NULL }, +{ "pvread.i", S(PVREAD), 0, 3, "kk", "kii", pvreadset, pvread, NULL }, +{ "pvcross", S(PVCROSS), 0, 5, "a", "kkSkko", pvcrossset_S, NULL, pvcross }, +{ "pvbufread", S(PVBUFREAD),0, 3, "", "kS", pvbufreadset_S, pvbufread, NULL}, +{ "pvinterp", S(PVINTERP), 0, 5, "a", "kkSkkkkkk", pvinterpset_S, NULL, pvinterp}, +{ "pvcross.i", S(PVCROSS), 0, 5, "a", "kkikko", pvcrossset, NULL, pvcross }, +{ "pvbufread.i", S(PVBUFREAD),0, 3, "", "ki", pvbufreadset, pvbufread, NULL}, +{ "pvinterp.i", S(PVINTERP), 0, 5, "a", "kkikkkkkk", pvinterpset, NULL, pvinterp}, +{ "pvadd", S(PVADD), 0, 5, "a", "kkSiiopooo", pvaddset_S, NULL, pvadd }, +{ "pvadd.i", S(PVADD), 0, 5, "a", "kkiiiopooo", pvaddset, NULL, pvadd } }; PVOC_GLOBALS *PVOC_AllocGlobals(CSOUND *csound) @@ -53,8 +67,10 @@ csound->Message(csound, "calling alloc globals"); #endif if (UNLIKELY(csound->CreateGlobalVariable(csound, "pvocGlobals", - sizeof(PVOC_GLOBALS)) != 0)) - csound->Die(csound, Str("Error allocating PVOC globals")); + sizeof(PVOC_GLOBALS)) != 0)){ + csound->ErrorMsg(csound, Str("Error allocating PVOC globals")); + return NULL; + } p = (PVOC_GLOBALS*) csound->QueryGlobalVariable(csound, "pvocGlobals"); p->csound = csound; p->dsputil_sncTab = (MYFLT*) NULL; @@ -64,5 +80,5 @@ return p; } -LINKAGE1(pvoc_localops) +LINKAGE_BUILTIN(pvoc_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/pvread.c csound-6.02~dfsg/Opcodes/pvread.c --- csound-5.17.11~dfsg/Opcodes/pvread.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvread.c 2014-01-07 16:53:48.000000000 +0000 @@ -68,11 +68,17 @@ } } -int pvreadset(CSOUND *csound, PVREAD *p) +int pvreadset_(CSOUND *csound, PVREAD *p, int stringname) { char pvfilnam[256]; - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (pvocex_loadfile(csound, pvfilnam, p) == OK) { p->prFlg = 1; p->mybin = MYFLT2LRND(*p->ibin); @@ -81,6 +87,14 @@ return NOTOK; } +int pvreadset(CSOUND *csound, PVREAD *p){ + return pvreadset_(csound,p,0); +} + +int pvreadset_S(CSOUND *csound, PVREAD *p){ + return pvreadset_(csound,p,1); +} + int pvread(CSOUND *csound, PVREAD *p) { MYFLT frIndx; @@ -100,7 +114,7 @@ *p->kamp = buf[0]; return OK; err1: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, Str("PVOC timpnt < 0")); } static int pvocex_loadfile(CSOUND *csound, const char *fname, PVREAD *p) @@ -122,7 +136,7 @@ p->asr = pp.srate; /* highest possible frame index */ /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr / ((MYFLT) pp.overlap); + p->frPrtim = CS_ESR / ((MYFLT) pp.overlap); return OK; } diff -Nru csound-5.17.11~dfsg/Opcodes/pvsband.c csound-6.02~dfsg/Opcodes/pvsband.c --- csound-5.17.11~dfsg/Opcodes/pvsband.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvsband.c 2014-01-07 16:53:48.000000000 +0000 @@ -22,7 +22,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "pvs_ops.h" #include "pstream.h" typedef struct { @@ -47,9 +47,9 @@ if (p->fin->sliding) { if (p->fout->frame.auxp==NULL || - csound->ksmps*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) - csound->AuxAlloc(csound, csound->ksmps*(N+2)*sizeof(MYFLT),&p->fout->frame); - else memset(p->fout->frame.auxp, 0, csound->ksmps*(N+2)*sizeof(MYFLT)); + CS_KSMPS*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) + csound->AuxAlloc(csound, CS_KSMPS*(N+2)*sizeof(MYFLT),&p->fout->frame); + else memset(p->fout->frame.auxp, 0, CS_KSMPS*(N+2)*sizeof(MYFLT)); } else { @@ -89,10 +89,13 @@ if (higbndfin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; - for (n=0; nfin->frame.auxp + n*NB; CMPLX *fout = (CMPLX *) p->fout->frame.auxp + n*NB; @@ -171,7 +174,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvsband: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsband: not initialised")); } static int pvsbrej(CSOUND *csound, PVSBAND *p) @@ -193,10 +197,13 @@ if (higbndfin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; - for (n=0; nfin->frame.auxp + n*NB; CMPLX *fout = (CMPLX *) p->fout->frame.auxp + n*NB; @@ -273,12 +280,15 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvsband: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsband: not initialised")); } static OENTRY localops[] = { - {"pvsbandp", sizeof(PVSBAND), 3, "f", "fxxxxO", (SUBR) pvsbandinit, (SUBR) pvsband, (SUBR) NULL }, - {"pvsbandr", sizeof(PVSBAND), 3, "f", "fxxxxO", (SUBR) pvsbandinit, (SUBR) pvsbrej, (SUBR) NULL } + {"pvsbandp", sizeof(PVSBAND), 0, 3, "f", "fxxxxO", + (SUBR) pvsbandinit, (SUBR) pvsband, (SUBR) NULL }, + {"pvsbandr", sizeof(PVSBAND), 0, 3, "f", "fxxxxO", + (SUBR) pvsbandinit, (SUBR) pvsbrej, (SUBR) NULL } }; int pvsband_init_(CSOUND *csound) @@ -286,5 +296,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - - diff -Nru csound-5.17.11~dfsg/Opcodes/pvsbasic.c csound-6.02~dfsg/Opcodes/pvsbasic.c --- csound-5.17.11~dfsg/Opcodes/pvsbasic.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvsbasic.c 2014-01-07 16:54:20.000000000 +0000 @@ -25,7 +25,7 @@ /* pvsmix */ -#include "csdl.h" +#include "pvs_ops.h" #include "pvsbasic.h" #include "pvfileio.h" #include @@ -47,8 +47,8 @@ p->fout->sliding = 0; if (p->fa->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->fout->frame.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); p->fout->NB = p->fa->NB; p->fout->sliding = 1; @@ -80,9 +80,22 @@ if (p->fa->sliding) { CMPLX * fout, *fa; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fa->NB; - for (n=0; nfout->frame.auxp +NB*n; + for (i = 0; i < NB; i++) + fout[i].re = fout[i].im = FL(0.0); + } + for (n=nsmps-early; nfout->frame.auxp +NB*n; + for (i = 0; i < NB; i++) + fout[i].re = fout[i].im = FL(0.0); + } + nsmps -= early; + for (n=offset; nfout->frame.auxp +NB*n; fa = (CMPLX*) p->fa->frame.auxp +NB*n; for (i = 0; i < NB; i++) { @@ -113,7 +126,9 @@ static int pvsinit(CSOUND *csound, PVSINI *p) { int i; - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; float *bframe; int32 N = (int32) *p->framesize; @@ -124,20 +139,21 @@ p->fout->format = (int32) *p->format; p->fout->framecount = 1; p->fout->sliding = 0; - if (p->fout->overlap < csound->ksmps || p->fout->overlap <=10) { + if (p->fout->overlap < (int)nsmps || p->fout->overlap <=10) { int NB = 1+N/2; MYFLT *bframe; p->fout->NB = NB; if (p->fout->frame.auxp == NULL || - p->fout->frame.size * csound->ksmps < sizeof(float) * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * csound->ksmps * sizeof(float), + p->fout->frame.size * CS_KSMPS < sizeof(float) * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * nsmps * sizeof(float), &p->fout->frame); p->fout->sliding = 1; bframe = (MYFLT *) p->fout->frame.auxp; - for (n=0; nksmps; n++) + for (n=0; n>1) * N * csound->onedsr; + bframe[i+n*NB + 1] = + (nnsmps-early ? FL(0.0) :(i >>1) * N * csound->onedsr); } } else @@ -163,54 +179,120 @@ MYFLT *file; int pvfile; AUXCH frame; + AUXCH buf; + AUXCH dframe; + CSOUND *csound; + void *cb; + int async; + pthread_t thread; + int N; uint32 lastframe; }PVSFWRITE; -static int pvsfwrite_destroy(CSOUND *csound, void *p) +void *pvs_io_thread(void *pp); + +static int pvsfwrite_destroy(CSOUND *csound, void *pp) { - csound->PVOC_CloseFile(csound,((PVSFWRITE *) p)->pvfile); - return OK; + PVSFWRITE *p = (PVSFWRITE *) pp; + if(p->async){ + p->async = 0; + pthread_join(p->thread, NULL); + csound->DestroyCircularBuffer(csound, p->cb); + } + csound->PVOC_CloseFile(csound,p->pvfile); + return OK; } -static int pvsfwriteset(CSOUND *csound, PVSFWRITE *p) +static int pvsfwriteset_(CSOUND *csound, PVSFWRITE *p, int stringname) { int N; - char *fname = csound->strarg2name(csound, NULL, p->file, - "pvoc.",p->XSTRCODE); + char fname[MAXNAME]; + + if (stringname==0){ + if (ISSTRCOD(*p->file)) + strncpy(fname,get_arg_string(csound, *p->file), MAXNAME-1); + else csound->strarg2name(csound, fname, p->file, "pvoc.",0); + } + else strncpy(fname, ((STRINGDAT *)p->file)->data, MAXNAME-1); + if (UNLIKELY(p->fin->sliding)) return csound->InitError(csound,Str("SDFT Not implemented in this case yet")); p->pvfile= -1; - N = p->fin->N; + N = p->N = p->fin->N; if ((p->pvfile = csound->PVOC_CreateFile(csound, fname, p->fin->N, p->fin->overlap, 1, p->fin->format, - csound->esr, STYPE_16, + CS_ESR, STYPE_16, p->fin->wintype, 0.0f, NULL, p->fin->winsize)) == -1) return csound->InitError(csound, Str("pvsfwrite: could not open file %s\n"), fname); - if (p->frame.auxp == NULL || p->frame.size < sizeof(float) * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->frame); + + if(csound->realtime_audio_flag) { + int bufframes = 16; + p->csound = csound; + if (p->frame.auxp == NULL || p->frame.size < sizeof(MYFLT) * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT), &p->frame); + if (p->buf.auxp == NULL || p->buf.size < sizeof(MYFLT) * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT), &p->buf); + if (p->dframe.auxp == NULL || p->dframe.size < sizeof(float) * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->dframe); + p->cb = csound->CreateCircularBuffer(csound, (N+2)*sizeof(float)*bufframes, + sizeof(MYFLT)); + pthread_create(&p->thread, NULL, pvs_io_thread, (void *) p); + p->async = 1; + } else{ + p->async = 0; + } csound->RegisterDeinitCallback(csound, p, pvsfwrite_destroy); p->lastframe = 0; return OK; } +static int pvsfwriteset(CSOUND *csound, PVSFWRITE *p){ + return pvsfwriteset_(csound,p,0); +} + +static int pvsfwriteset_S(CSOUND *csound, PVSFWRITE *p){ + return pvsfwriteset_(csound,p,1); +} + + +void *pvs_io_thread(void *pp){ + PVSFWRITE *p = (PVSFWRITE *) pp; + CSOUND *csound = p->csound; + MYFLT *buf = (MYFLT *) p->buf.auxp; + float *frame = (float *) p->dframe.auxp; + int *on = &p->async; + int lc,n, N2=p->N+2; + while (*on) { + lc = csound->ReadCircularBuffer(csound, p->cb, buf, N2); + if(lc) { + for (n=0; n < N2; n++) frame[n] = (float) buf[n]; + csound->PVOC_PutFrames(csound, p->pvfile, frame, 1); + } + } + return NULL; +} + + static int pvsfwrite(CSOUND *csound, PVSFWRITE *p) { - float *fout = p->frame.auxp; float *fin = p->fin->frame.auxp; if (p->lastframe < p->fin->framecount) { - int32 framesize = p->fin->N+2, i; - MYFLT scale = csound->e0dbfs; - for (i=0;i < framesize; i+=2) { - fout[i] = fin[i]/scale; - fout[i+1] = fin[i+1]; + int32 framesize = p->fin->N+2,i; + if(p->async == 0) { + if (UNLIKELY(!csound->PVOC_PutFrames(csound, p->pvfile, fin, 1))) + return csound->PerfError(csound, p->h.insdshead, + Str("pvsfwrite: could not write data\n")); + } + else { + MYFLT *fout = p->frame.auxp; + for (i=0;i < framesize; i++) fout[i] = (MYFLT) fin[i]; + csound->WriteCircularBuffer(csound, p->cb, fout, framesize); } - if (UNLIKELY(!csound->PVOC_PutFrames(csound, p->pvfile, fout, 1))) - return csound->PerfError(csound, Str("pvsfwrite: could not write data\n")); p->lastframe = p->fin->framecount; } return OK; @@ -236,16 +318,23 @@ #define FSIGBUFRAMES 2 -static int pvsdiskinset(CSOUND *csound, pvsdiskin *p) +static int pvsdiskinset_(CSOUND *csound, pvsdiskin *p, int stringname) { int N; WAVEFORMATEX fmt; PVOCDATA pvdata; - char *fname = csound->strarg2name(csound, NULL, p->file, - "pvoc.",p->XSTRCODE); + char fname[MAXNAME]; + + if (stringname==0){ + if (ISSTRCOD(*p->file)) + strncpy(fname,get_arg_string(csound, *p->file), MAXNAME-1); + else csound->strarg2name(csound, fname, p->file, "pvoc.",0); + } + else strncpy(fname, ((STRINGDAT *)p->file)->data, MAXNAME-1); if (UNLIKELY(p->fout->sliding)) - return csound->InitError(csound,Str("SDFT Not implemented in this case yet")); + return csound->InitError(csound, + Str("SDFT Not implemented in this case yet")); if ((p->pvfile = csound->PVOC_OpenFile(csound, fname, &pvdata, &fmt)) < 0) return csound->InitError(csound, @@ -289,7 +378,7 @@ p->fout->format = pvdata.wAnalFormat; p->fout->framecount = 1; p->scnt = p->fout->overlap; - p->pos = *p->ioff * csound->esr/N; + p->pos = *p->ioff * CS_ESR/N; p->oldpos = -1; p->chn = (int) (*p->ichn <= p->chans ? *p->ichn : p->chans) -1; @@ -297,9 +386,18 @@ return OK; } +static int pvsdiskinset(CSOUND *csound, pvsdiskin *p){ + return pvsdiskinset_(csound, p, 0); +} + +static int pvsdiskinset_S(CSOUND *csound, pvsdiskin *p){ + return pvsdiskinset_(csound, p, 1); +} + static int pvsdiskinproc(CSOUND *csound, pvsdiskin *p) { - int overlap = p->fout->overlap, frames, i, posi; + int overlap = p->fout->overlap, i; + unsigned int posi; double pos = p->pos; int32 N = p->fout->N; MYFLT frac; @@ -310,7 +408,7 @@ float amp = (float) (*p->kgain * csound->e0dbfs); if (p->scnt >= overlap) { - posi = (int) pos; + posi = (unsigned int) pos; if (posi != p->oldpos) { /* read new frame @@ -321,8 +419,8 @@ while(pos >= p->flen) pos -= p->flen; while(pos < 0) pos += p->flen; csound->PVOC_fseek(csound,p->pvfile, pos); - frames = csound->PVOC_GetFrames(csound, p->pvfile, buffer, 2*p->chans); - p->oldpos = posi = (int)pos; + (void)csound->PVOC_GetFrames(csound, p->pvfile, buffer, 2*p->chans); + p->oldpos = posi = (unsigned int)pos; } if (*p->interp) { @@ -332,7 +430,7 @@ fout[i] = amp*(frame1[i] + frac*(frame2[i] - frame1[i])); fout[i+1] = frame1[i+1] + frac*(frame2[i+1] - frame1[i+1]); } - } else /* don't */ + } else /* do not */ for (i=0; i < N+2; i+=2) { fout[i] = amp*(frame1[i]); fout[i+1] = frame1[i+1]; @@ -343,7 +441,7 @@ p->scnt -= overlap; p->fout->framecount++; } - p->scnt += csound->ksmps; + p->scnt += CS_KSMPS; return OK; } @@ -374,14 +472,16 @@ { int i, N, hsize, nChannels; + N = (*p->fftsize > 0 ? *p->fftsize : 2048); + hsize = (*p->hsize > 0 ? *p->hsize : 512); p->init = 0; nChannels = csound->GetOutputArgCnt(p); if (UNLIKELY(nChannels < 1 || nChannels > MAXOUTS)) - csound->Die(csound, Str("invalid number of output arguments")); + return csound->InitError(csound, Str("invalid number of output arguments")); p->nchans = nChannels; for (i=0; i < p->nchans; i++) { - N = p->fout[i]->N = (*p->fftsize > 0 ? *p->fftsize : 2048); - hsize = p->fout[i]->overlap = (*p->hsize > 0 ? *p->hsize : 512); + p->fout[i]->N = N; + p->fout[i]->overlap = hsize; p->fout[i]->wintype = PVS_WIN_HANN; p->fout[i]->winsize = N; p->fout[i]->framecount = 1; @@ -417,11 +517,11 @@ ((MYFLT *)p->win.auxp)[i] *= 2./p->scale; p->rotfac = hsize*TWOPI/N; - p->factor = csound->esr/(hsize*TWOPI); - p->fund = csound->esr/N; + p->factor = CS_ESR/(hsize*TWOPI); + p->fund = CS_ESR/N; p->scnt = p->fout[0]->overlap; p->tscale = 1; - p->pos = *p->offset*csound->esr; + p->pos = *p->offset*CS_ESR; p->accum = 0.0; return OK; } @@ -429,9 +529,10 @@ int pvstanal(CSOUND *csound, PVST *p) { - int hsize = p->fout[0]->overlap, i, k, j; - uint32 size, sizefrs, post, nchans = p->nchans; - int32 N = p->fout[0]->N; + int hsize = p->fout[0]->overlap, i, k; + unsigned int j; + uint32_t sizefrs, nchans = p->nchans; + int32 N = p->fout[0]->N, post, size; double frac, spos = p->pos, pos; MYFLT *tab, dbtresh = *p->dbthresh; FUNC *ft; @@ -442,12 +543,13 @@ MYFLT time = *p->ktime; float tmp_real, tmp_im, powrat; - if (p->scnt >= hsize) { + if ((int)p->scnt >= hsize) { /* audio samples are stored in a function table */ ft = csound->FTnp2Find(csound,p->knum); if (ft == NULL){ - csound->PerfError(csound, "could not find table number %d\n", (int) *p->knum); + csound->PerfError(csound, p->h.insdshead, + "could not find table number %d\n", (int) *p->knum); return NOTOK; } @@ -459,10 +561,11 @@ time is current read rate esr is sampling rate */ - if (UNLIKELY((int) ft->nchanls != nchans)) - return csound->PerfError(csound, Str("number of output arguments " - "inconsistent with number of " - "sound file channels")); + if (UNLIKELY(ft->nchanls != (int32)nchans)) + return csound->PerfError(csound, p->h.insdshead, + Str("number of output arguments " + "inconsistent with number of " + "sound file channels")); sizefrs = size/nchans; if (!*p->wrap && spos >= sizefrs) { @@ -474,7 +577,7 @@ } while (spos >= sizefrs) spos -= sizefrs; - while (spos < 0) spos += sizefrs; + while (spos < hsize) spos += (sizefrs + hsize); pos = spos; for (j=0; j < nchans; j++) { @@ -494,22 +597,25 @@ frac = pos - post; post *= nchans; post += j; - if (post < 0 || post >= size ) in = 0.0; - else in = tab[post] + frac*(tab[post+nchans] - tab[post]); + while (post >= size ) post -= size; + while (post < 0) post += size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); fwin[i] = amp * in * win[i]; /* window it */ /* back windo, bwin */ post = (int) (pos - hsize*pitch); post *= nchans; post += j; - if (post < 0 ||post >= size ) in = 0.0; - else in = tab[post] + frac*(tab[post+nchans] - tab[post]); + while (post >= size ) post -= size; + while (post < 0) post += size; + in = tab[post] + frac*(tab[post+nchans] - tab[post]); bwin[i] = in * win[i]; /* window it */ if (*p->konset){ post = (int) pos + hsize; post *= nchans; post += j; - if (post < 0 || post >= size ) in = 0.0; - else in = tab[post]; + while (post >= size ) post -= size; + while (post < 0) post += size; + in = tab[post]; nwin[i] = amp * in * win[i]; } /* increment read pos according to pitch transposition */ @@ -565,7 +671,7 @@ p->scnt -= hsize; p->pos = spos; } - p->scnt += csound->ksmps; + p->scnt += CS_KSMPS; return OK; } @@ -587,7 +693,7 @@ p->fout->NB = (N/2)+1; p->fout->sliding = p->fin->sliding; if (p->fin->sliding) { - int nsmps = csound->ksmps; + uint32_t nsmps = CS_KSMPS; if (p->fout->frame.auxp == NULL || p->fout->frame.size < sizeof(MYFLT) * (N + 2) * nsmps) csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * nsmps, @@ -614,12 +720,18 @@ static int pvssfreezeprocess(CSOUND *csound, PVSFREEZE *p) { - int i, n, k, nsmps = csound->ksmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fin->NB; MYFLT freeza = *p->kfra, freezf = *p->kfrf; + CMPLX *fz = (CMPLX*)p->freez.auxp; - for (n=0, k=nsmps-1; nfreez.auxp; + for (n=0; nfout->frame.auxp + n*NB; + for (i = 0; i < NB; i++) fo[i].re = fo[i].im = FL(0.0); + } + for (n=offset; nfout->frame.auxp + n*NB; CMPLX *fi = (CMPLX*)p->fin->frame.auxp + n*NB; for (i = 0; i < NB; i++) { @@ -676,23 +788,25 @@ p->fout->format = (int32) *p->format; p->fout->framecount = 0; p->fout->sliding = 0; - if (p->fout->overlapksmps || p->fout->overlap<=10) { + if (p->fout->overlap<(int)CS_KSMPS || p->fout->overlap<=10) { CMPLX *bframe; - int NB = 1+N/2, n; + int NB = 1+N/2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; return csound->InitError(csound, Str("pvsosc does not work while sliding")); p->fout->NB = NB; p->fout->sliding = 1; if (p->fout->frame.auxp == NULL || - p->fout->frame.size < csound->ksmps*sizeof(MYFLT) * (N + 2)) + p->fout->frame.size < CS_KSMPS*sizeof(MYFLT) * (N + 2)) csound->AuxAlloc(csound, - (N + 2) * csound->ksmps* sizeof(MYFLT), &p->fout->frame); + (N + 2) * CS_KSMPS* sizeof(MYFLT), &p->fout->frame); else memset(p->fout->frame.auxp, - '\0', (N + 2) * csound->ksmps* sizeof(MYFLT)); + '\0', (N + 2) * CS_KSMPS* sizeof(MYFLT)); bframe = (CMPLX *)p->fout->frame.auxp; - for (n=0; nksmps; n++) + for (n=0; nonedsr; + bframe[i+NB*n].im = (nonedsr); } return OK; } @@ -708,7 +822,7 @@ bframe[i + 1] = (i / 2) * N * csound->onedsr; } p->lastframe = 1; - p->incr = (MYFLT)csound->ksmps/p->fout->overlap; + p->incr = (MYFLT)CS_KSMPS/p->fout->overlap; } return OK; } @@ -732,9 +846,10 @@ if (p->fout->sliding) { CMPLX *fout; - int m, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; - harm = (int)(csound->esr/(2*ffun)); + harm = (int)(CS_ESR/(2*ffun)); if (type==1) famp *= FL(1.456)/POWER((MYFLT)harm, FL(1.0)/FL(2.4)); else if (type==2) famp *= FL(1.456)/POWER((MYFLT)harm, FL(0.25)); else if (type==3) famp *= FL(1.456)/POWER((MYFLT)harm, FL(1.0)/FL(160.0)); @@ -744,10 +859,12 @@ } for (n=0; nfout->frame.auxp + n*NB; - w = csound->esr/p->fout->N; - /* harm = (int)(csound->esr/(2*ffun)); */ + w = CS_ESR/p->fout->N; + /* harm = (int)(CS_ESR/(2*ffun)); */ memset(fout, '\0', NB*sizeof(CMPLX)); + if (nlastframe > p->fout->framecount) { - w = csound->esr/p->fout->N; - harm = (int)(csound->esr/(2*ffun)); + w = CS_ESR/p->fout->N; + harm = (int)(CS_ESR/(2*ffun)); if (type==1) famp *= FL(1.456)/pow(harm, FL(1.0)/FL(2.4)); else if (type==2) famp *= FL(1.456)/POWER(harm, FL(0.25)); else if (type==3) famp *= FL(1.456)/POWER(harm, FL(1.0)/FL(160.0)); @@ -801,7 +918,7 @@ } p->incr += p->incr; if (p->incr > 1) { - p->incr = (MYFLT)csound->ksmps/p->fout->overlap; + p->incr = (MYFLT)CS_KSMPS/p->fout->overlap; p->lastframe++; } return OK; @@ -845,27 +962,34 @@ static int pvsbinprocessa(CSOUND *csound, PVSBIN *p) { - int32 framesize, pos, k; + int32 framesize, pos; if (p->fin->sliding) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t k, nsmps = CS_KSMPS; CMPLX *fin = (CMPLX *) p->fin->frame.auxp; int NB = p->fin->NB; pos = *p->kbin; if (pos >= 0 && pos < NB) { - for (k=0; kksmps; k++) { - p->kamp[k] = (MYFLT)fin[pos+NB*k].re; + for (k=0; kkamp[k] = p->kfreq[k] = FL(0.0); + for (k=offset; kkamp[k] = (MYFLT)fin[pos+NB*k].re; p->kfreq[k] = (MYFLT)fin[pos+NB*k].im; } } } else { float *fin; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t k, nsmps = CS_KSMPS; fin = (float *) p->fin->frame.auxp; if (p->lastframe < p->fin->framecount) { framesize = p->fin->N + 2; pos=*p->kbin*2; if (pos >= 0 && pos < framesize) { - for (k=0; kksmps; k++) { - p->kamp[k] = (MYFLT)fin[pos]; + memset(p->kamp, '\0', offset*sizeof(MYFLT)); + memset(p->kfreq, '\0', offset*sizeof(MYFLT)); + for (k=offset; kkamp[k] = (MYFLT)fin[pos]; p->kfreq[k] = (MYFLT)fin[pos+1]; } p->lastframe = p->fin->framecount; @@ -885,12 +1009,12 @@ p->fout->sliding = p->fin->sliding; if (p->fin->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->fout->frame.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); if (p->del.auxp == NULL || - p->del.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->del.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->del); } else @@ -930,7 +1054,8 @@ if (p->fin->sliding) { CMPLX *fout, *fin, *del; double costh1, costh2, coef1, coef2; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fin->NB; ffa = ffa < 0.0 ? 0.0 : (ffa > 1.0 ? 1.0 : ffa); ffr = ffr < 0.0 ? 0.0 : (ffr > 1.0 ? 1.0 : ffr); @@ -939,7 +1064,13 @@ coef1 = sqrt(costh1 * costh1 - 1.0) - costh1; coef2 = sqrt(costh2 * costh2 - 1.0) - costh2; - for (n=0; nfout->frame.auxp +NB*n; + del = (CMPLX*) p->del.auxp +NB*n; + fout[i].re = fout[i].im = del[i].re = del[i].im = FL(0.0); + } + for (n=offset; nfout->frame.auxp +NB*n; fin = (CMPLX*) p->fin->frame.auxp +NB*n; del = (CMPLX*) p->del.auxp +NB*n; @@ -1001,8 +1132,8 @@ p->fout->sliding = 0; if (p->fa->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->fout->frame.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); p->fout->NB = p->fa->NB; p->fout->sliding = 1; @@ -1035,9 +1166,14 @@ if (UNLIKELY(!fsigs_equal(p->fa, p->fb))) goto err1; if (p->fa->sliding) { CMPLX * fout, *fa, *fb; - int n, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fa->NB; - for (n=0; nfout->frame.auxp +NB*n; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=offset; nfout->frame.auxp +NB*n; fa = (CMPLX*) p->fa->frame.auxp +NB*n; fb = (CMPLX*) p->fb->frame.auxp +NB*n; @@ -1070,7 +1206,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvsmix: formats are different.")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsmix: formats are different.")); } /* pvsfilter */ @@ -1088,8 +1225,8 @@ p->fout->sliding = 0; if (p->fin->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, sizeof(MYFLT) * csound->ksmps * (N + 2), + p->fout->frame.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, sizeof(MYFLT) * CS_KSMPS * (N + 2), &p->fout->frame); p->fout->NB = p->fin->NB; p->fout->sliding = 1; @@ -1123,12 +1260,17 @@ if (p->fin->sliding) { int NB = p->fout->NB; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; CMPLX *fin, *fout, *fil; MYFLT g = *p->gain; kdepth = kdepth >= FL(0.0) ? (kdepth <= FL(1.0) ? kdepth*g : g) : FL(0.0); dirgain = (FL(1.0) - kdepth)*g; - for (n=0; nfout->frame.auxp + NB*n; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=offset; nfin->frame.auxp + NB*n; fout = (CMPLX *)p->fout->frame.auxp + NB*n; fil = (CMPLX *)p->fil->frame.auxp + NB*n; @@ -1145,10 +1287,10 @@ return OK; } if (p->lastframe < p->fin->framecount) { - kdepth = kdepth >= 0 ? (kdepth <= 1 ? kdepth*g : g) : FL(0.0); - dirgain = (1 - kdepth)*g; + kdepth = kdepth >= 0 ? (kdepth <= 1 ? kdepth : 1) : FL(0.0); + dirgain = (1 - kdepth); for (i = 0; i < N + 2; i += 2) { - fout[i] = (float) (fin[i] * (dirgain + fil[i] * kdepth)); + fout[i] = (float) (fin[i] * (dirgain + fil[i] * kdepth))*g; fout[i + 1] = fin[i + 1]; } @@ -1156,9 +1298,10 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvsfilter: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsfilter: not initialised")); err2: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("pvsfilter: formats are different.")); } @@ -1177,7 +1320,7 @@ static int pvsscaleset(CSOUND *csound, PVSSCALE *p) { - int32 N = p->fin->N; + int32 N = p->fin->N, tmp; if (UNLIKELY(p->fin == p->fout)) csound->Warning(csound, Str("Unsafe to have same fsig as in and out")); @@ -1185,8 +1328,8 @@ p->fout->sliding = p->fin->sliding; if (p->fin->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < csound->ksmps * sizeof(MYFLT) * (N + 2)) - csound->AuxAlloc(csound, csound->ksmps * sizeof(MYFLT) * (N + 2), + p->fout->frame.size < CS_KSMPS * sizeof(MYFLT) * (N + 2)) + csound->AuxAlloc(csound, CS_KSMPS * sizeof(MYFLT) * (N + 2), &p->fout->frame); } else @@ -1202,11 +1345,11 @@ p->fout->format = p->fin->format; p->fout->framecount = 1; p->lastframe = 0; - + tmp = N + N%2; if (p->ceps.auxp == NULL || - p->ceps.size < sizeof(MYFLT) * (N+2)) - csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->ceps); - memset(p->ceps.auxp, 0, sizeof(MYFLT)*(N+2)); + p->ceps.size < sizeof(MYFLT) * (tmp+2)) + csound->AuxAlloc(csound, sizeof(MYFLT) * (tmp + 2), &p->ceps); + memset(p->ceps.auxp, 0, sizeof(MYFLT)*(tmp+2)); if (p->fenv.auxp == NULL || p->fenv.size < sizeof(MYFLT) * (N+2)) csound->AuxAlloc(csound, sizeof(MYFLT) * (N + 2), &p->fenv); @@ -1214,8 +1357,8 @@ return OK; } - - +void csoundInverseComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize); +void csoundComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize); static int pvsscale(CSOUND *csound, PVSSCALE *p) { @@ -1228,16 +1371,21 @@ float *fout = (float *) p->fout->frame.auxp; MYFLT *fenv = (MYFLT *) p->fenv.auxp; MYFLT *ceps = (MYFLT *) p->ceps.auxp; - float sr = csound->esr, binf; + float sr = CS_ESR, binf; int coefs = (int) *p->coefs; if (UNLIKELY(fout == NULL)) goto err1; if (p->fout->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; MYFLT g = *p->gain; - for (n=0; nfout->frame.auxp + n*NB; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=offset; nfin->frame.auxp + n*NB; CMPLX *fout = (CMPLX *) p->fout->frame.auxp + n*NB; @@ -1259,8 +1407,8 @@ fout[i].re = fin[i].re * (fin[i].re / max); fout[i].im = fin[i].im * pscal; /* Remove aliases */ - if (fout[i].im>=csound->esr*0.5 || - fout[i].im<= -csound->esr*0.5) + if (fout[i].im>=CS_ESR*0.5 || + fout[i].im<= -CS_ESR*0.5) fout[i].re=0.0; } @@ -1310,6 +1458,8 @@ } } else { /* new modes 1 & 2 */ + int tmp = N/2; + tmp = tmp + tmp%2; if (coefs < 1) coefs = 80; while(cond) { cond = 0; @@ -1317,9 +1467,15 @@ ceps[i] = fenv[i/2]; ceps[i+1] = 0.0; } - csound->InverseComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->InverseComplexFFT(csound, ceps, N/2); + else + csoundInverseComplexFFTnp2(csound, ceps, tmp); for (i=coefs; i < N-coefs; i++) ceps[i] = 0.0; - csound->ComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->ComplexFFT(csound, ceps, N/2); + else + csoundComplexFFTnp2(csound, ceps, tmp); for (i=0; i < N; i+=2) { if (keepform > 1) { if (fenv[i/2] < ceps[i]) @@ -1372,7 +1528,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvscale: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvscale: not initialised")); } /* pvshift */ @@ -1398,9 +1555,9 @@ csound->Warning(csound, Str("Unsafe to have same fsig as in and out")); if (p->fin->sliding) { if (p->fout->frame.auxp==NULL || - csound->ksmps*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) - csound->AuxAlloc(csound, csound->ksmps*(N+2)*sizeof(MYFLT),&p->fout->frame); - else memset(p->fout->frame.auxp, 0, csound->ksmps*(N+2)*sizeof(MYFLT)); + CS_KSMPS*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) + csound->AuxAlloc(csound, CS_KSMPS*(N+2)*sizeof(MYFLT),&p->fout->frame); + else memset(p->fout->frame.auxp, 0, CS_KSMPS*(N+2)*sizeof(MYFLT)); } else { @@ -1446,18 +1603,22 @@ float *fout = (float *) p->fout->frame.auxp; MYFLT *fenv = (MYFLT *) p->fenv.auxp; MYFLT *ceps = (MYFLT *) p->ceps.auxp; - float sr = csound->esr, binf; + float sr = CS_ESR, binf; int coefs = (int) *p->coefs; if (UNLIKELY(fout == NULL)) goto err1; if (p->fin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; MYFLT g = *p->gain; lowest = lowest ? (lowest > NB ? NB : lowest) : 1; - for (n=0; nfout->frame.auxp + n*NB; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=offset; nfin->frame.auxp + n*NB; CMPLX *fout = (CMPLX *) p->fout->frame.auxp + n*NB; fout[0] = fin[0]; @@ -1478,8 +1639,8 @@ fout[i].re = fin[i].re * (fin[i].re / max); fout[i].im = (fin[i].im + pshift); /* Remove aliases */ - if (fout[i].im>=csound->esr*0.5 || - fout[i].im<= -csound->esr*0.5) + if (fout[i].im>=CS_ESR*0.5 || + fout[i].im<= -CS_ESR*0.5) fout[i].re = 0.0; } if (g!=1.0f) @@ -1509,6 +1670,8 @@ } if (keepform) { /* new modes 1 & 2 */ int cond = 1; + int tmp = N/2; + tmp = tmp + tmp%2; for (i=0; i < N; i+=2) fenv[i/2] = log(fin[i] > 0.0 ? fin[i] : 1e-20); if (coefs < 1) coefs = 80; @@ -1518,9 +1681,15 @@ ceps[i] = fenv[i/2]; ceps[i+1] = 0.0; } - csound->InverseComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->InverseComplexFFT(csound, ceps, N/2); + else + csoundInverseComplexFFTnp2(csound, ceps, tmp); for (i=coefs; i < N-coefs; i++) ceps[i] = 0.0; - csound->ComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->ComplexFFT(csound, ceps, N/2); + else + csoundComplexFFTnp2(csound, ceps, tmp); for (i=0; i < N; i+=2) { if (keepform > 1) { if (fenv[i/2] < ceps[i]) @@ -1572,7 +1741,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvshift: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvshift: not initialised")); } /* pvswarp */ @@ -1639,7 +1809,7 @@ float *fout = (float *) p->fout->frame.auxp; MYFLT *fenv = (MYFLT *) p->fenv.auxp; MYFLT *ceps = (MYFLT *) p->ceps.auxp; - float sr = csound->esr, binf; + float sr = CS_ESR, binf; int lowest = abs((int) (*p->klowest * N * csound->onedsr));; int coefs = (int) *p->coefs; @@ -1686,6 +1856,8 @@ } } else { /* new modes 1 & 2 */ + int tmp = N/2; + tmp = tmp + tmp%2; if (coefs < 1) coefs = 80; while(cond) { cond = 0; @@ -1693,9 +1865,15 @@ ceps[i] = fenv[i/2]; ceps[i+1] = 0.0; } - csound->InverseComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->InverseComplexFFT(csound, ceps, N/2); + else + csoundInverseComplexFFTnp2(csound, ceps, tmp); for (i=coefs; i < N-coefs; i++) ceps[i] = 0.0; - csound->ComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->ComplexFFT(csound, ceps, N/2); + else + csoundComplexFFTnp2(csound, ceps, tmp); for (i=0; i < N; i+=2) { if (keepform > 1) { if (fenv[i/2] < ceps[i]) @@ -1745,7 +1923,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvswarp: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvswarp: not initialised")); } @@ -1763,21 +1942,21 @@ csound->Warning(csound, Str("Unsafe to have same fsig as in and out")); if (p->fin->sliding) { csound->InitError(csound, Str("pvsblur does not work sliding yet")); - delayframes = (int) (FL(0.5) + *p->maxdel * csound->esr); + delayframes = (int) (FL(0.5) + *p->maxdel * CS_ESR); if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->fout->frame.size < sizeof(MYFLT) * CS_KSMPS * (N + 2)) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); if (p->delframes.auxp == NULL || - p->delframes.size < (N + 2) * sizeof(MYFLT) * csound->ksmps * delayframes) + p->delframes.size < (N + 2) * sizeof(MYFLT) * CS_KSMPS * delayframes) csound->AuxAlloc(csound, - (N + 2) * sizeof(MYFLT) * csound->ksmps * delayframes, + (N + 2) * sizeof(MYFLT) * CS_KSMPS * delayframes, &p->delframes); } else { - p->frpsec = csound->esr / olap; + p->frpsec = CS_ESR / olap; delayframes = (int) (*p->maxdel * p->frpsec); @@ -1786,7 +1965,7 @@ csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); if (p->delframes.auxp == NULL || - p->delframes.size < (N + 2) * sizeof(float) * csound->ksmps * delayframes) + p->delframes.size < (N + 2) * sizeof(float) * CS_KSMPS * delayframes) csound->AuxAlloc(csound, (N + 2) * sizeof(float) * delayframes, &p->delframes); } @@ -1795,7 +1974,7 @@ for (j = 0; j < framesize * delayframes; j += framesize) for (i = 0; i < N + 2; i += 2) { delay[i + j] = 0.0f; - delay[i + j + 1] = i * csound->esr / N; + delay[i + j + 1] = i * CS_ESR / N; } p->fout->N = N; @@ -1826,10 +2005,15 @@ if (UNLIKELY(fout == NULL || delay == NULL)) goto err1; if (p->fin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fin->NB; kdel = kdel >= 0 ? (kdel < mdel ? kdel : mdel - framesize) : 0; - for (n=0; nfout->frame.auxp +NB*n; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=offset; nfin->frame.auxp +NB*n; CMPLX *fout = (CMPLX *) p->fout->frame.auxp +NB*n; CMPLX *delay = (CMPLX *) p->delframes.auxp +NB*n; @@ -1894,14 +2078,16 @@ return OK; err1: - return csound->PerfError(csound, Str("pvsblur: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsblur: not initialised")); } /* pvstencil */ static int pvstencilset(CSOUND *csound, PVSTENCIL *p) { - int32 N = p->fin->N, i; + int32 N = p->fin->N; + uint32_t i; int32 chans = N / 2 + 1; MYFLT *ftable; @@ -1916,8 +2102,8 @@ p->fout->NB = chans; if (p->fin->sliding) { if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(MYFLT) * (N + 2) * csound->ksmps) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + p->fout->frame.size < sizeof(MYFLT) * (N + 2) * CS_KSMPS) + csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * CS_KSMPS, &p->fout->frame); p->fout->sliding = 1; } @@ -1932,11 +2118,11 @@ return csound->InitError(csound, Str("pvstencil: signal format " "must be amp-phase or amp-freq.")); } - p->func = csound->FTFind(csound, p->ifn); + p->func = csound->FTnp2Find(csound, p->ifn); if (p->func == NULL) return OK; - if (UNLIKELY(p->func->flen + 1 < chans)) + if (UNLIKELY(p->func->flen + 1 < (unsigned int)chans)) return csound->InitError(csound, Str("pvstencil: ftable needs to equal " "the number of bins")); @@ -1954,13 +2140,25 @@ if (p->fin->sliding) { MYFLT g = FABS(*p->kgain); MYFLT masklevel = FABS(*p->klevel); - int NB = p->fin->NB, n, i; + int NB = p->fin->NB, i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; p->fout->NB = NB; p->fout->N = p->fin->N; p->fout->format = p->fin->format; p->fout->wintype = p->fin->wintype; ftable = p->func->ftable; - for (n=0; nksmps; n++) { + for (n=0; nfout->frame.auxp + n*NB; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + for (n=nsmps-early; nfout->frame.auxp + n*NB; + for (i = 0; i < NB; i++) fout[i].re = fout[i].im = FL(0.0); + } + nsmps -= early; + for (n=offset; nfout->frame.auxp + n*NB; CMPLX *fin = (CMPLX *) p->fin->frame.auxp + n*NB; for (i = 0; i < NB; i++) { @@ -2005,7 +2203,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("pvstencil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvstencil: not initialised")); } static int fsigs_equal(const PVSDAT *f1, const PVSDAT *f2) @@ -2070,7 +2269,8 @@ MYFLT *ftab; if (ft == NULL) { - csound->PerfError(csound, "could not find table number %d\n", (int) *p->ftab); + csound->PerfError(csound, p->h.insdshead, + Str("could not find table number %d\n"), (int) *p->ftab); return NOTOK; } size = ft->flen; @@ -2103,6 +2303,8 @@ }*/ } else { /* new modes 1 & 2 */ + int tmp = N/2; + tmp = tmp + tmp%2; if (coefs < 1) coefs = 80; while(cond) { cond = 0; @@ -2110,9 +2312,15 @@ ceps[i] = fenv[i/2]; ceps[i+1] = 0.0; } - csound->InverseComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->InverseComplexFFT(csound, ceps, N/2); + else + csoundInverseComplexFFTnp2(csound, ceps, tmp); for (i=coefs; i < N-coefs; i++) ceps[i] = 0.0; - csound->ComplexFFT(csound, ceps, N/2); + if (!(N & (N - 1))) + csound->ComplexFFT(csound, ceps, N/2); + else + csoundComplexFFTnp2(csound, ceps, tmp); for (i=0; i < N; i+=2) { if (keepform > 1) { if (fenv[i/2] < ceps[i]) @@ -2146,7 +2354,7 @@ typedef struct pvs2tab_t { OPDS h; MYFLT *framecount; - TABDAT *ans; + ARRAYDAT *ans; PVSDAT *fsig; } PVS2TAB_T; @@ -2157,12 +2365,12 @@ return csound->InitError(csound, Str("pvs2tab: signal format " "must be amp-phase or amp-freq.")); if (LIKELY(p->ans->data)) return OK; - return csound->InitError(csound, Str("t-variable not initialised")); + return csound->InitError(csound, Str("array-variable not initialised")); } int pvs2tab(CSOUND *csound, PVS2TAB_T *p){ - int size = p->ans->size, N = p->fsig->N, i; + int size = p->ans->sizes[0], N = p->fsig->N, i; float *fsig = (float *) p->fsig->frame.auxp; for(i = 0; i < size && i < N+2; i++) p->ans->data[i] = (MYFLT) fsig[i]; @@ -2173,8 +2381,9 @@ typedef struct tab2pvs_t { OPDS h; PVSDAT *fout; - TABDAT *in; + ARRAYDAT *in; MYFLT *olap, *winsize, *wintype, *format; + uint32 ktime; uint32 lastframe; } TAB2PVS_T; @@ -2182,13 +2391,14 @@ { if (LIKELY(p->in->data)){ int N; - p->fout->N = N = p->in->size - 2; + p->fout->N = N = p->in->sizes[0] - 2; p->fout->overlap = (int32)(*p->olap ? *p->olap : N/4); p->fout->winsize = (int32)(*p->winsize ? *p->winsize : N); p->fout->wintype = (int32) *p->wintype; p->fout->format = 0; p->fout->framecount = 1; p->lastframe = 0; + p->ktime = 0; if (p->fout->frame.auxp == NULL || p->fout->frame.size < sizeof(float) * (N + 2)) { csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); @@ -2197,20 +2407,27 @@ memset(p->fout->frame.auxp, 0, sizeof(float)*(N+2)); return OK; } - else return csound->InitError(csound, Str("t-variable not initialised")); + else return csound->InitError(csound, Str("array-variable not initialised")); } int tab2pvs(CSOUND *csound, TAB2PVS_T *p) { - int size = p->in->size, i; + int size = p->in->sizes[0], i; float *fout = (float *) p->fout->frame.auxp; + p->ktime += CS_KSMPS; + if(p->ktime > (uint32) p->fout->overlap) { + p->fout->framecount++; + p->ktime -= p->fout->overlap; + } + if (p->lastframe < p->fout->framecount){ for (i = 0; i < size; i++){ fout[i] = (float) p->in->data[i]; } p->lastframe = p->fout->framecount; } + return OK; } @@ -2218,45 +2435,58 @@ static OENTRY localops[] = { - {"pvsfwrite", sizeof(PVSFWRITE), 3, "", "fT", (SUBR) pvsfwriteset, + {"pvsfwrite", sizeof(PVSFWRITE),0, 3, "", "fS", (SUBR) pvsfwriteset_S, (SUBR) pvsfwrite}, - {"pvsfilter", sizeof(PVSFILTER), 3, "f", "ffxp", (SUBR) pvsfilterset, + {"pvsfwrite.i", sizeof(PVSFWRITE),0, 3, "", "fi", (SUBR) pvsfwriteset, + (SUBR) pvsfwrite}, + {"pvsfilter", sizeof(PVSFILTER),0, 3, "f", "ffxp", (SUBR) pvsfilterset, (SUBR) pvsfilter}, - {"pvscale", sizeof(PVSSCALE), 3, "f", "fxOPO", (SUBR) pvsscaleset, + {"pvscale", sizeof(PVSSCALE),0, 3, "f", "fxOPO", (SUBR) pvsscaleset, (SUBR) pvsscale}, - {"pvshift", sizeof(PVSSHIFT), 3, "f", "fxkOPO", (SUBR) pvsshiftset, + {"pvshift", sizeof(PVSSHIFT),0, 3, "f", "fxkOPO", (SUBR) pvsshiftset, (SUBR) pvsshift}, - {"pvsfilter", sizeof(PVSFILTER), 3, "f", "fffp", (SUBR) pvsfilterset, + {"pvsfilter", sizeof(PVSFILTER),0, 3, "f", "fffp", (SUBR) pvsfilterset, (SUBR) pvsfilter}, - {"pvscale", sizeof(PVSSCALE), 3, "f", "fkOPO", + {"pvscale", sizeof(PVSSCALE),0, 3, "f", "fkOPO", (SUBR) pvsscaleset, (SUBR) pvsscale}, - {"pvshift", sizeof(PVSSHIFT), 3, "f", "fkkOPO", (SUBR) pvsshiftset, + {"pvshift", sizeof(PVSSHIFT),0, 3, "f", "fkkOPO", (SUBR) pvsshiftset, (SUBR) pvsshift}, - {"pvsmix", sizeof(PVSMIX), 3, "f", "ff", (SUBR) pvsmixset, (SUBR) pvsmix, NULL}, - {"pvsfilter", sizeof(PVSFILTER), 3, "f", "ffxp", (SUBR) pvsfilterset, + {"pvsmix", sizeof(PVSMIX),0, 3, "f", "ff", (SUBR) pvsmixset, (SUBR)pvsmix, NULL}, + {"pvsfilter", sizeof(PVSFILTER),0, 3, "f", "ffxp", (SUBR) pvsfilterset, (SUBR) pvsfilter}, - {"pvsblur", sizeof(PVSBLUR), 3, "f", "fki", (SUBR) pvsblurset, (SUBR) pvsblur, + {"pvsblur", sizeof(PVSBLUR),0, 3, "f", "fki", (SUBR) pvsblurset, (SUBR) pvsblur, NULL}, - {"pvstencil", sizeof(PVSTENCIL), TR|3, "f", "fkki", (SUBR) pvstencilset, + {"pvstencil", sizeof(PVSTENCIL), TR, 3, "f", "fkki", (SUBR) pvstencilset, (SUBR) pvstencil}, - {"pvsinit", sizeof(PVSINI), 1, "f", "ioopo", (SUBR) pvsinit, NULL, NULL}, - {"pvsbin", sizeof(PVSBIN), 3, "ss", "fk", (SUBR) pvsbinset, + {"pvsinit", sizeof(PVSINI),0, 1, "f", "ioopo", (SUBR) pvsinit, NULL, NULL}, + {"pvsbin", sizeof(PVSBIN),0, 3, "ss", "fk", (SUBR) pvsbinset, (SUBR) pvsbinprocess, (SUBR) pvsbinprocessa}, - {"pvsfreeze", sizeof(PVSFREEZE), 3, "f", "fkk", (SUBR) pvsfreezeset, + {"pvsfreeze", sizeof(PVSFREEZE),0, 3, "f", "fkk", (SUBR) pvsfreezeset, (SUBR) pvsfreezeprocess, NULL}, - {"pvsmooth", sizeof(PVSFREEZE), 3, "f", "fxx", (SUBR) pvsmoothset, + {"pvsmooth", sizeof(PVSFREEZE),0, 3, "f", "fxx", (SUBR) pvsmoothset, (SUBR) pvsmoothprocess, NULL}, - {"pvsosc", sizeof(PVSOSC), 3, "f", "kkkioopo", (SUBR) pvsoscset, + {"pvsosc", sizeof(PVSOSC),0, 3, "f", "kkkioopo", (SUBR) pvsoscset, (SUBR) pvsoscprocess, NULL}, - {"pvsdiskin", sizeof(pvsdiskin), 3, "f", "SkkopP",(SUBR) pvsdiskinset, + {"pvsdiskin", sizeof(pvsdiskin),0, 3, "f", "SkkopP",(SUBR) pvsdiskinset_S, + (SUBR) pvsdiskinproc, NULL}, + {"pvsdiskin.i", sizeof(pvsdiskin),0, 3, "f", "ikkopP",(SUBR) pvsdiskinset, (SUBR) pvsdiskinproc, NULL}, - {"pvstanal", sizeof(PVST), 3, "FFFFFFFFFFFFFFFF", "kkkkPPoooP",(SUBR) pvstanalset, - (SUBR) pvstanal, NULL}, - {"pvswarp", sizeof(PVSWARP), 3, "f", "fkkOPPO", (SUBR) pvswarpset, (SUBR) pvswarp}, - {"pvsenvftw", sizeof(PVSENVW), 3, "k", "fkPPO", (SUBR) pvsenvwset, (SUBR) pvsenvw}, - {"pvsgain", sizeof(PVSGAIN), 3, "f", "fk", (SUBR) pvsgainset, (SUBR) pvsgain, NULL}, - {"pvs2tab", sizeof(PVS2TAB_T), 3, "k", "tf", (SUBR) pvs2tab_init, (SUBR) pvs2tab, NULL}, - {"tab2pvs", sizeof(TAB2PVS_T), 3, "f", "toop", (SUBR) tab2pvs_init, (SUBR) tab2pvs, NULL} + {"pvstanal", sizeof(PVST),0, 3, "FFFFFFFFFFFFFFFF", "kkkkPPoooP", + (SUBR) pvstanalset, (SUBR) pvstanal, NULL}, + {"pvswarp", sizeof(PVSWARP),0, 3, "f", "fkkOPPO", + (SUBR) pvswarpset, (SUBR) pvswarp}, + {"pvsenvftw", sizeof(PVSENVW),0, 3, "k", "fkPPO", + (SUBR) pvsenvwset, (SUBR) pvsenvw}, + {"pvsgain", sizeof(PVSGAIN), 0,3, "f", "fk", + (SUBR) pvsgainset, (SUBR) pvsgain, NULL}, + {"pvs2tab", sizeof(PVS2TAB_T), 0,3, "k", "k[]f", + (SUBR) pvs2tab_init, (SUBR) pvs2tab, NULL}, + {"tab2pvs", sizeof(TAB2PVS_T), 0, 3, "f", "k[]oop", (SUBR) tab2pvs_init, + (SUBR) tab2pvs, NULL}, + {"pvs2array", sizeof(PVS2TAB_T), 0,3, "k", "k[]f", + (SUBR) pvs2tab_init, (SUBR) pvs2tab, NULL}, + {"pvsfromarray", sizeof(TAB2PVS_T), 0, 3, "f", "k[]oop", + (SUBR) tab2pvs_init, (SUBR) tab2pvs, NULL} }; int pvsbasic_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/pvsbuffer.c csound-6.02~dfsg/Opcodes/pvsbuffer.c --- csound-5.17.11~dfsg/Opcodes/pvsbuffer.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvsbuffer.c 2014-01-07 16:53:48.000000000 +0000 @@ -63,7 +63,7 @@ p->handle->header.wintype = p->fin->wintype; p->handle->header.format = p->fin->format; p->handle->header.framecount = p->fin->framecount; - p->nframes = p->handle->frames = (*p->len) * csound->esr/hop; + p->nframes = p->handle->frames = (*p->len) * CS_ESR/hop; if (p->buffer.auxp == NULL || p->buffer.size < sizeof(float) * (N + 2) * p->nframes) csound->AuxAlloc(csound, (N + 2) * sizeof(float) * p->nframes, &p->buffer); @@ -111,7 +111,7 @@ fout[i+1] = fin[i+1]; } p->handle->header.framecount = p->lastframe = p->fin->framecount; - p->pos = p->cframes/(csound->esr/p->fin->overlap); + p->pos = p->cframes/(CS_ESR/p->fin->overlap); p->cframes++; if (p->cframes == p->nframes)p->cframes = 0; } @@ -131,7 +131,7 @@ MYFLT *clear; MYFLT iclear, optr; FSIG_HANDLE *handle; - int scnt; + unsigned int scnt; } PVSBUFFERREAD; static int pvsbufreadset(CSOUND *csound, PVSBUFFERREAD *p) @@ -181,11 +181,11 @@ static int pvsbufreadproc(CSOUND *csound, PVSBUFFERREAD *p){ unsigned int posi, frames; - MYFLT pos, sr = csound->esr; + MYFLT pos, sr = CS_ESR, frac; FSIG_HANDLE *handle = p->handle, **phandle; - MYFLT frac; float *fout, *buffer; - int strt = *p->strt, end = *p->end, overlap, i, N; + int strt = *p->strt, end = *p->end, i, N; + unsigned int overlap; p->iclear = *p->clear; if (*p->hptr != p->optr) { @@ -193,7 +193,7 @@ sprintf(varname, "::buffer%d", (int)(*p->hptr)); phandle = (FSIG_HANDLE **) csound->QueryGlobalVariable(csound,varname); if (phandle == NULL) - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str("error... could not read handle " "from global variable\n")); else @@ -221,7 +221,7 @@ while (pos < 0) pos += frames; posi = (int) pos; if (N == handle->header.N && - overlap == handle->header.overlap){ + overlap == (unsigned int)handle->header.overlap){ frame1 = buffer + (N + 2) * posi; frame2 = buffer + (N + 2)*(posi != frames-1 ? posi+1 : 0); frac = pos - posi; @@ -239,30 +239,32 @@ p->scnt -= overlap; p->fout->framecount++; } - p->scnt += csound->ksmps; + p->scnt += CS_KSMPS; return OK; err1: - return csound->PerfError(csound, Str("Invalid buffer handle")); + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid buffer handle")); } static int pvsbufreadproc2(CSOUND *csound, PVSBUFFERREAD *p) { unsigned int posi, frames; - MYFLT pos, sr = csound->esr; + MYFLT pos, sr = CS_ESR; FSIG_HANDLE *handle = p->handle, **phandle; - MYFLT frac, *tab1, *tab2, *tab; - FUNC *ftab; - float *fout, *buffer; - int overlap, i, N; + MYFLT frac, *tab1, *tab2, *tab; + FUNC *ftab; + float *fout, *buffer; + uint32_t overlap, i; + int N; if (*p->hptr != p->optr){ char varname[32]; sprintf(varname, "::buffer%d", (int)(*p->hptr)); phandle = (FSIG_HANDLE **) csound->QueryGlobalVariable(csound,varname); if (phandle == NULL) - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str("error... could not read handle from " "global variable\n")); else @@ -279,25 +281,25 @@ if (p->scnt >= overlap) { float *frame1, *frame2; frames = handle->frames-1; - ftab = csound->FTFind(csound, p->strt); - if (ftab->flen < N/2+1) - csound->PerfError(csound, + ftab = csound->FTnp2Find(csound, p->strt); + if (UNLIKELY((int)ftab->flen < N/2+1)) + csound->PerfError(csound, p->h.insdshead, Str("table length too small: needed %d, got %d\n"), N/2+1, ftab->flen); tab = tab1 = ftab->ftable; - ftab = csound->FTFind(csound, p->end); - if (ftab->flen < N/2+1) - csound->PerfError(csound, + ftab = csound->FTnp2Find(csound, p->end); + if (UNLIKELY((int)ftab->flen < N/2+1)) + csound->PerfError(csound, p->h.insdshead, Str("table length too small: needed %d, got %d\n"), N/2+1, ftab->flen); tab2 = ftab->ftable; - for (i=0; i < N+2; i++){ + for (i=0; i < (unsigned int)N+2; i++){ pos = (*p->ktime - tab[i])*(sr/overlap); while(pos >= frames) pos -= frames; while(pos < 0) pos += frames; posi = (int) pos; if (N == handle->header.N && - overlap == handle->header.overlap){ + overlap == (unsigned int)handle->header.overlap) { frame1 = buffer + (N + 2) * posi; frame2 = buffer + (N + 2)*(posi != frames-1 ? posi+1 : 0); frac = pos - posi; @@ -310,10 +312,11 @@ p->scnt -= overlap; p->fout->framecount++; } - p->scnt += csound->ksmps; + p->scnt += CS_KSMPS; return OK; err1: - return csound->PerfError(csound, Str("Invalid buffer handle")); + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid buffer handle")); } @@ -323,13 +326,13 @@ /* static */ static OENTRY pvsbuffer_localops[] = { - {"pvsbuffer", S(PVSBUFFER), 3, "ik", "fi", + {"pvsbuffer", S(PVSBUFFER), 0, 3, "ik", "fi", (SUBR)pvsbufferset, (SUBR)pvsbufferproc, NULL}, - {"pvsbufread", S(PVSBUFFERREAD), 3, "f", "kkOOo", + {"pvsbufread", S(PVSBUFFERREAD), 0, 3, "f", "kkOOo", (SUBR)pvsbufreadset, (SUBR)pvsbufreadproc, NULL}, - {"pvsbufread2", S(PVSBUFFERREAD), 3, "f", "kkkk", + {"pvsbufread2", S(PVSBUFFERREAD), 0, 3, "f", "kkkk", (SUBR)pvsbufreadset, (SUBR)pvsbufreadproc2, NULL} }; -LINKAGE1(pvsbuffer_localops) +LINKAGE_BUILTIN(pvsbuffer_localops) /* LINKAGE */ diff -Nru csound-5.17.11~dfsg/Opcodes/pvscent.c csound-6.02~dfsg/Opcodes/pvscent.c --- csound-5.17.11~dfsg/Opcodes/pvscent.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvscent.c 2014-01-07 16:53:48.000000000 +0000 @@ -2,7 +2,8 @@ Calculation of spectral centroid as Beauchamp (c) John ffitch, 2005 - (c) Alan OCinneide, 2005 + (c) Alan OCinneide, 2005 + (c) V Lazzarin, 2012 This file is part of Csound. @@ -22,22 +23,23 @@ 02111-1307 USA */ -#include "csdl.h" +#include "pvs_ops.h" #include "pstream.h" typedef struct { - OPDS h; - MYFLT *ans; - PVSDAT *fin; - uint32 lastframe; - MYFLT old; + OPDS h; + MYFLT *ans; + PVSDAT *fin; + uint32 lastframe; + MYFLT old; } PVSCENT; static int pvscentset(CSOUND *csound, PVSCENT *p) { *p->ans = FL(0.0); p->lastframe = 0; - if (UNLIKELY(!(p->fin->format==PVS_AMP_FREQ) || (p->fin->format==PVS_AMP_PHASE))) + if (UNLIKELY(!(p->fin->format==PVS_AMP_FREQ) || + (p->fin->format==PVS_AMP_PHASE))) return csound->InitError(csound, Str("pvscent: format must be amp-phase" " or amp-freq.\n")); @@ -49,7 +51,7 @@ int32 i,N = p->fin->N; MYFLT c = FL(0.0); MYFLT d = FL(0.0); - MYFLT j, binsize = FL(0.5)*csound->esr/(MYFLT)N; + MYFLT j, binsize = CS_ESR/(MYFLT)N; if (p->fin->sliding) { CMPLX *fin = (CMPLX*) p->fin->frame.auxp; int NB = p->fin->NB; @@ -58,17 +60,18 @@ d += fin[i].re; } } - else - { - float *fin = (float *) p->fin->frame.auxp; - if (p->lastframe < p->fin->framecount) { - for (i=0,j=FL(0.5)*binsize; ilastframe = p->fin->framecount; + else { + float *fin = (float *) p->fin->frame.auxp; + if (p->lastframe < p->fin->framecount) { + //printf("N=%d binsize=%f\n", N, binsize); + for (i=0,j=FL(0.5)*binsize; ilastframe = p->fin->framecount; } + } *p->ans = (d==FL(0.0) ? FL(0.0) : c/d); return OK; } @@ -77,14 +80,21 @@ { MYFLT *a = p->ans; if (p->fin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 i,N = p->fin->N; MYFLT c = FL(0.0); MYFLT d = FL(0.0); - MYFLT j, binsize = FL(0.5)*csound->esr/(MYFLT)N; + MYFLT j, binsize = CS_ESR/(MYFLT)N; int NB = p->fin->NB; - for (n=0; nfin->frame.auxp + n*NB; for (i=0,j=FL(0.5)*binsize; iksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT old = p->old; int32 i,N = p->fin->N; MYFLT c = FL(0.0); MYFLT d = FL(0.0); - MYFLT j, binsize = FL(0.5)*csound->esr/(MYFLT)N; + MYFLT j, binsize = CS_ESR/(MYFLT)N; float *fin = (float *) p->fin->frame.auxp; - for (n=0; nlastframe < p->fin->framecount) { for (i=0,j=FL(0.5)*binsize; ilastframe = p->fin->framecount; } else { @@ -119,57 +132,147 @@ return OK; } +typedef struct _cent { + OPDS h; + MYFLT *ans; + MYFLT *asig, *ktrig, *ifftsize; + uint32_t fsize, count; + MYFLT old; + AUXCH frame, windowed, win; +} CENT; + +static int cent_i(CSOUND *csound, CENT *p) +{ + int fftsize = *p->ifftsize; + p->count = 0; + p->fsize = 1; + while(fftsize >>= 1) p->fsize <<= 1; + if (p->fsize < *p->ifftsize) { + p->fsize <<= 1; + csound->Warning(csound, + Str("centroid requested fftsize = %.0f, actual = %d\n"), + *p->ifftsize, p->fsize); + } + if (p->frame.auxp == NULL || p->frame.size < p->fsize*sizeof(MYFLT)) + csound->AuxAlloc(csound, p->fsize*sizeof(MYFLT), &p->frame); + if (p->windowed.auxp == NULL || p->windowed.size < p->fsize*sizeof(MYFLT)) + csound->AuxAlloc(csound, p->fsize*sizeof(MYFLT), &p->windowed); + if (p->win.auxp == NULL || p->win.size < p->fsize*sizeof(MYFLT)) { + unsigned int i; + MYFLT *win; + csound->AuxAlloc(csound, p->fsize*sizeof(MYFLT), &p->win); + win = (MYFLT *) p->win.auxp; + for (i=0; i < p->fsize; i++) + win[i] = 0.5 - 0.5*cos(i*TWOPI/p->fsize); + } + p->old = 0; + memset(p->frame.auxp, 0, p->fsize*sizeof(MYFLT)); + memset(p->windowed.auxp, 0, p->fsize*sizeof(MYFLT)); + return OK; +} + + +static int cent_k(CSOUND *csound, CENT *p) +{ + unsigned int n = p->count, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + MYFLT *frame = (MYFLT *) p->frame.auxp, *asig = p->asig; + + uint32_t fsize = (uint32_t)p->fsize; + if (UNLIKELY(early)) nsmps -= early; + for (i=offset; i < nsmps; i++){ + frame[n] = asig[i]; + if (n == fsize-1) n=0; + else n++; + } + + if (*p->ktrig) { + MYFLT c = FL(0.0); + MYFLT d = FL(0.0); + MYFLT *windowed = (MYFLT *) p->windowed.auxp; + MYFLT *win = (MYFLT *) p->win.auxp; + MYFLT mag, cf, binsize = CS_ESR/(MYFLT)fsize; + for (i=0,k=n; i < fsize; i++){ + windowed[i] = frame[k]*win[i]; + if (k == fsize-1) k=0; + else k++; + } + csound->RealFFT(csound, windowed, fsize); + cf=FL(0.5)*binsize; + mag = windowed[0]; + c += mag*cf; + d += mag; + cf += binsize; + for (i=2; i < fsize; i+=2, cf += binsize) { + mag = sqrt(windowed[i]*windowed[i] + windowed[i+1]*windowed[i+1]); + c += mag*cf; + d += mag; + } + p->old = *p->ans = (d==FL(0.0) ? FL(0.0) : c/d); + } else *p->ans = p->old; + p->count = n; + return OK; +} + + + + /* PVSPITCH opcode by Ala OCinneide */ typedef struct _pvspitch { - /* OPDS data structure */ - OPDS h; + /* OPDS data structure */ + OPDS h; - /* Output */ - MYFLT *kfreq; - MYFLT *kamp; - - /* Inputs */ - PVSDAT *fin; - MYFLT *ithreshold; - - /* Internal arrays */ - AUXCH peakfreq; - AUXCH inharmonic; + /* Output */ + MYFLT *kfreq; + MYFLT *kamp; + + /* Inputs */ + PVSDAT *fin; + MYFLT *ithreshold; + + /* Internal arrays */ + AUXCH peakfreq; + AUXCH inharmonic; - uint32 lastframe; + uint32 lastframe; } PVSPITCH; - +#if !defined(FALSE) #define FALSE (0) +#endif +#if !defined(TRUE) #define TRUE (!FALSE) +#endif #define RoundNum(Number) (int)MYFLT2LRND(Number) /* Should one use remainder or drem ?? */ -#define Remainder(Numerator, Denominator) \ +#define Remainder(Numerator, Denominator) \ Numerator/Denominator - (int) (Numerator/Denominator) int pvspitch_init(CSOUND *csound, PVSPITCH *p) { /* Initialise frame count to zero. */ - int size; + unsigned int size; p->lastframe = 0; if (UNLIKELY(p->fin->sliding)) return csound->InitError(csound, Str("SDFT case not implemented yet")); size = sizeof(MYFLT)*(p->fin->N+2); if (p->peakfreq.auxp == NULL || p->peakfreq.size < size) - csound->AuxAlloc(csound, size, &p->peakfreq); + csound->AuxAlloc(csound, size, &p->peakfreq); if (p->inharmonic.auxp == NULL || p->inharmonic.size < size) - csound->AuxAlloc(csound, size, &p->inharmonic); + csound->AuxAlloc(csound, size, &p->inharmonic); if (UNLIKELY(p->fin->format!=PVS_AMP_FREQ)) { return csound->InitError(csound, - "PV Frames must be in AMP_FREQ format!\n"); + Str("PV Frames must be in AMP_FREQ format!\n")); } return OK; @@ -296,14 +399,15 @@ } static OENTRY localops[] = { - { "pvscent", sizeof(PVSCENT), 3, "s", "f", (SUBR)pvscentset, (SUBR)pvscent, (SUBR)pvsscent }, - { "pvspitch", sizeof(PVSPITCH), 3, "kk", "fk", - (SUBR)pvspitch_init, (SUBR)pvspitch_process, NULL} + { "pvscent", sizeof(PVSCENT), 0, 3, "s", "f", + (SUBR)pvscentset, (SUBR)pvscent, (SUBR)pvsscent }, + { "centroid", sizeof(CENT), 0, 3, "k", "aki", (SUBR)cent_i, (SUBR)cent_k, NULL}, + { "pvspitch", sizeof(PVSPITCH), 0, 3, "kk", "fk", + (SUBR)pvspitch_init, (SUBR)pvspitch_process, NULL} }; int pvscent_init_(CSOUND *csound) { - return csound->AppendOpcodes(csound, &(localops[0]), - (int) (sizeof(localops) / sizeof(OENTRY))); + return csound->AppendOpcodes(csound, &(localops[0]), + (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/pvsdemix.c csound-6.02~dfsg/Opcodes/pvsdemix.c --- csound-5.17.11~dfsg/Opcodes/pvsdemix.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvsdemix.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "pvs_ops.h" #include "pvsdemix.h" static int fsigs_equal(const PVSDAT *f1, const PVSDAT *f2) @@ -40,9 +40,9 @@ static int pvsdemix_init(CSOUND *csound, PVSDEMIX *p) { - int32 N = p->finleft->N; + uint32_t N = p->finleft->N; int olap = p->finleft->overlap; - int M; + uint32_t M; p->beta = (int)(*p->slices); if (UNLIKELY(p->finleft->sliding)) @@ -81,7 +81,7 @@ if (!(p->fout->format==PVS_AMP_FREQ) || (p->fout->format==PVS_AMP_PHASE)) - csound->Die(csound, + return csound->InitError(csound, "pvsdemix: signal format must be amp-phase or amp-freq.\n"); return OK; @@ -175,14 +175,17 @@ return OK; err1: - return csound->PerfError(csound, Str("pvsdemix : formats are different.\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsdemix : formats are different.\n")); err2: - return csound->PerfError(csound, Str("pvsdemix : not initialised \n")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsdemix : not initialised \n")); } static OENTRY localops[] = { - {"pvsdemix", sizeof(PVSDEMIX), 3, "f", "ffkki", (SUBR) pvsdemix_init, (SUBR) pvsdemix_process, (SUBR) NULL } + {"pvsdemix", sizeof(PVSDEMIX), 0, 3, "f", "ffkki", + (SUBR) pvsdemix_init, (SUBR) pvsdemix_process, (SUBR) NULL } }; int pvsdemix_init_(CSOUND *csound) @@ -190,4 +193,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/pvsgendy.c csound-6.02~dfsg/Opcodes/pvsgendy.c --- csound-5.17.11~dfsg/Opcodes/pvsgendy.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvsgendy.c 2014-01-07 16:53:48.000000000 +0000 @@ -22,7 +22,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "csoundCore.h" #include "pstream.h" typedef struct { @@ -31,7 +31,7 @@ PVSDAT *fin; MYFLT *kmrate; MYFLT *kfrate; - int lastframe; + unsigned int lastframe; } PVSGENDY; @@ -40,13 +40,13 @@ int N = p->fin->N; if (UNLIKELY(p->fin == p->fout)) - csound->Warning(csound, "Unsafe to have same fsig as in and out"); + csound->Warning(csound, Str("Unsafe to have same fsig as in and out")); if (p->fin->sliding) { if (p->fout->frame.auxp==NULL || - csound->ksmps*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) - csound->AuxAlloc(csound, csound->ksmps*(N+2)*sizeof(MYFLT),&p->fout->frame); - else memset(p->fout->frame.auxp, 0, csound->ksmps*(N+2)*sizeof(MYFLT)); + CS_KSMPS*(N+2)*sizeof(MYFLT) > (unsigned int)p->fout->frame.size) + csound->AuxAlloc(csound, CS_KSMPS*(N+2)*sizeof(MYFLT),&p->fout->frame); + else memset(p->fout->frame.auxp, 0, CS_KSMPS*(N+2)*sizeof(MYFLT)); } else { @@ -72,24 +72,29 @@ int i, N = p->fin->N; MYFLT mrate = *p->kmrate; MYFLT frate = *p->kfrate; - float *fin = (float *) p->fin->frame.auxp; - float *fout = (float *) p->fout->frame.auxp; + float *finf = (float *) p->fin->frame.auxp; + float *foutf = (float *) p->fout->frame.auxp; - if (UNLIKELY(fout == NULL)) goto err1; + if (UNLIKELY(foutf == NULL)) goto err1; if (p->fin->sliding) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int NB = p->fout->NB; - - for (n=0; nfin->frame.auxp + n*NB; CMPLX *fout = (CMPLX *) p->fout->frame.auxp + n*NB; for (i = 0; i < NB-1; i++) { MYFLT x = (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX; // printf("%f\n", x); fout[i].re = fin[i].re + mrate * x; - fout[i].im = fin[i].im + frate * (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX/(MYFLT)(i+1); + fout[i].im = fin[i].im + + frate * (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX/(MYFLT)(i+1); } } return OK; @@ -97,22 +102,23 @@ if (p->lastframe < p->fin->framecount) { for (i = 0; i < N; i += 2) { MYFLT x = frate * (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX/(MYFLT)(i+1); - fout[i+1] = fin[i+1] + x; - fout[i] = fin[i] + mrate * (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX; + foutf[i+1] = finf[i+1] + x; + foutf[i] = finf[i] + mrate * (MYFLT)(rand()-RAND_MAX/2)/(MYFLT)RAND_MAX; } p->fout->framecount = p->lastframe = p->fin->framecount; } return OK; err1: - return csound->PerfError(csound, Str("pvsgendy: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsgendy: not initialised")); } static OENTRY pvsgendy_localops[] = { - { "pvsgendy", sizeof(PVSGENDY), 3, "f", "fkk", + { "pvsgendy", sizeof(PVSGENDY), 0, 3, "f", "fkk", (SUBR) pvsgendyinit, (SUBR) pvsgendy, (SUBR) NULL } }; -LINKAGE1(pvsgendy_localops) +LINKAGE_BUILTIN(pvsgendy_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/pvslock.c csound-6.02~dfsg/Opcodes/pvslock.c --- csound-5.17.11~dfsg/Opcodes/pvslock.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/pvslock.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,80 +0,0 @@ -#include "csdl.h" -#include "pvsbasic.h" -#include "pvfileio.h" -#include - -typedef struct _pvslock { - OPDS h; - PVSDAT *fout; - PVSDAT *fin; - MYFLT *delta; - float mag; - uint32 lastframe; -} PVSLOCK; - -static int pvslockset(CSOUND *csound, PVSLOCK *p) -{ - int32 N = p->fin->N; - - if (UNLIKELY(p->fin == p->fout)) - csound->Warning(csound, Str("Unsafe to have same fsig as in and out")); - p->fout->N = N; - p->fout->overlap = p->fin->overlap; - p->fout->winsize = p->fin->winsize; - p->fout->wintype = p->fin->wintype; - p->fout->format = p->fin->format; - p->fout->framecount = 1; - p->lastframe = 0; - p->mag = 0.000001; - if (p->fout->frame.auxp == NULL || - p->fout->frame.size < sizeof(float) * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(float), &p->fout->frame); - - - if (UNLIKELY(!(p->fout->format == PVS_AMP_FREQ) || - (p->fout->format == PVS_AMP_PHASE))) - return csound->InitError(csound, Str("pvslock: signal format " - "must be amp-phase or amp-freq.")); - - return OK; -} - -static int pvslockprocess(CSOUND *csound, PVSLOCK *p) -{ - int i; - int32 framesize, N = p->fin->N; - float *fout, *fin, cmag = p->mag, mag=0.0f, diff; - fout = (float *) p->fout->frame.auxp; - fin = (float *) p->fin->frame.auxp; - framesize = N + 2; - if (p->lastframe < p->fin->framecount) { - - for (i = 0; i < framesize; i += 2) { - - mag += fin[i]; - fout[i] = fin[i]; fout[i+1] = fin[i+1]; - - } - mag /= N; - diff = 20.0f*log10f(mag/cmag); - if (diff > *p->delta) - csound->Warning(csound, "att= %f %f\n", diff, mag); - p->mag = mag; - p->fout->framecount = p->lastframe = p->fin->framecount; - } - return OK; -} - - - -static OENTRY localops[] = { - {"pvslock", sizeof(PVSLOCK), 3, "f", "fk", (SUBR) pvslockset, - (SUBR) pvslockprocess, NULL} -}; - -int pvslock_init_(CSOUND *csound) -{ - return csound->AppendOpcodes(csound, &(localops[0]), - (int) (sizeof(localops) / sizeof(OENTRY))); -} - diff -Nru csound-5.17.11~dfsg/Opcodes/py/pycall-gen.py csound-6.02~dfsg/Opcodes/py/pycall-gen.py --- csound-5.17.11~dfsg/Opcodes/py/pycall-gen.py 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pycall-gen.py 2014-01-07 16:53:48.000000000 +0000 @@ -31,6 +31,9 @@ print >> f, '{' print >> f, ' char command[1024];' print >> f, ' PyObject *result;' + print >> f, ' int *py_initialize_done;' + print >> f, ' if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||*py_initialize_done == 0)' + print >> f, ' return NOTOK;' print >> f if triggered: print >> f, ' if (!*p->trigger) {' @@ -50,7 +53,7 @@ skip = 2 else: skip = 1 - print >> f, ' format_call_statement(command, (char*) p->function,' + print >> f, ' format_call_statement(command, (char*) p->function->data,' print >> f, ' p->INOCOUNT, p->args, %d);' % skip print >> f if context == 'private': @@ -116,6 +119,9 @@ name = 'pylcall%d%s_irate' % (n, t) print >> f, 'static int %s(CSOUND *csound, PYCALL%d%s *p)' % (name, n, T) print >> f, '{' + print >> f, ' int *py_initialize_done;' + print >> f, ' if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||*py_initialize_done == 0)' + print >> f, ' return NOTOK;' print >> f, ' create_private_namespace_if_needed(&p->h);' print >> f, ' return OK;' print >> f, '}' @@ -149,7 +155,7 @@ print >> f, ' MYFLT *result%d;' % (i+1) if triggered: print >> f, ' MYFLT *trigger;' - print >> f, ' MYFLT *function;' + print >> f, ' STRINGDAT *function;' print >> f, ' MYFLT *args[VARGMAX-3];' if triggered: if n == 1: diff -Nru csound-5.17.11~dfsg/Opcodes/py/pycall.auto.c csound-6.02~dfsg/Opcodes/py/pycall.auto.c --- csound-5.17.11~dfsg/Opcodes/py/pycall.auto.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pycall.auto.c 2014-01-07 16:53:48.000000000 +0000 @@ -3,8 +3,13 @@ { char command[1024]; PyObject *result; + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); @@ -21,6 +26,11 @@ static int pylcall0_irate(CSOUND *csound, PYCALL0 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -29,16 +39,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (result != Py_None) + if (UNLIKELY(result != Py_None)) return errMsg(p, "callable must return None"); Py_DECREF(result); @@ -49,18 +63,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (result != Py_None) + if (UNLIKELY(result != Py_None)) return errMsg(p, "callable must return None"); Py_DECREF(result); @@ -71,20 +89,24 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (result != Py_None) + if (UNLIKELY(result != Py_None)) return errMsg(p, "callable must return None"); Py_DECREF(result); @@ -93,6 +115,11 @@ static int pylcall0t_irate(CSOUND *csound, PYCALL0T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -101,20 +128,24 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (result != Py_None) + if (UNLIKELY(result != Py_None)) return errMsg(p, "callable must return None"); Py_DECREF(result); @@ -125,16 +156,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyFloat_Check(result)) { + if (UNLIKELY(!PyFloat_Check(result))) { return errMsg(p, "callable must return a float"); } else { @@ -156,16 +191,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyFloat_Check(result)) { + if (UNLIKELY(!PyFloat_Check(result))) { return errMsg(p, "callable must return a float"); } else { @@ -181,18 +220,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyFloat_Check(result)) { + if (UNLIKELY(!PyFloat_Check(result))) { return errMsg(p, "callable must return a float"); } else { @@ -208,21 +251,25 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result = p->oresult; return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyFloat_Check(result)) { + if (UNLIKELY(!PyFloat_Check(result))) { return errMsg(p, "callable must return a float"); } else { @@ -237,6 +284,11 @@ static int pylcall1t_irate(CSOUND *csound, PYCALL1T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -245,21 +297,25 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result = p->oresult; return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyFloat_Check(result)) { + if (UNLIKELY(!PyFloat_Check(result))) { return errMsg(p, "callable must return a float"); } else { @@ -276,16 +332,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 2) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { return errMsg(p, "callable must return 2 values"); } else { @@ -299,6 +359,11 @@ static int pylcall2_irate(CSOUND *csound, PYCALL2 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -307,16 +372,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 2) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { return errMsg(p, "callable must return 2 values"); } else { @@ -332,18 +401,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 2) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { return errMsg(p, "callable must return 2 values"); } else { @@ -359,22 +432,26 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 2) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { return errMsg(p, "callable must return 2 values"); } else { @@ -390,7 +467,12 @@ static int pylcall2t_irate(CSOUND *csound, PYCALL2T *p) { - create_private_namespace_if_needed(&p->h); + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + create_private_namespace_if_needed(&p->h); return OK; } @@ -398,22 +480,26 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 2) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 2)) { return errMsg(p, "callable must return 2 values"); } else { @@ -431,16 +517,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { return errMsg(p, "callable must return 3 values"); } else { @@ -455,6 +545,11 @@ static int pylcall3_irate(CSOUND *csound, PYCALL3 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -463,16 +558,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { return errMsg(p, "callable must return 3 values"); } else { @@ -489,18 +588,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { return errMsg(p, "callable must return 3 values"); } else { @@ -517,7 +620,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -525,15 +632,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { return errMsg(p, "callable must return 3 values"); } else { @@ -551,6 +658,11 @@ static int pylcall3t_irate(CSOUND *csound, PYCALL3T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -559,7 +671,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -567,15 +683,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 3) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 3)) { return errMsg(p, "callable must return 3 values"); } else { @@ -595,16 +711,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 4) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { return errMsg(p, "callable must return 4 values"); } else { @@ -620,6 +740,11 @@ static int pylcall4_irate(CSOUND *csound, PYCALL4 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -628,16 +753,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 4) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { return errMsg(p, "callable must return 4 values"); } else { @@ -655,18 +784,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 4) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { return errMsg(p, "callable must return 4 values"); } else { @@ -684,7 +817,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -693,15 +830,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 4) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { return errMsg(p, "callable must return 4 values"); } else { @@ -721,6 +858,11 @@ static int pylcall4t_irate(CSOUND *csound, PYCALL4T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -729,7 +871,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -738,15 +884,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 4) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 4)) { return errMsg(p, "callable must return 4 values"); } else { @@ -768,16 +914,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 5) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { return errMsg(p, "callable must return 5 values"); } else { @@ -794,6 +944,11 @@ static int pylcall5_irate(CSOUND *csound, PYCALL5 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -802,16 +957,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 5) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { return errMsg(p, "callable must return 5 values"); } else { @@ -830,18 +989,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 5) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { return errMsg(p, "callable must return 5 values"); } else { @@ -860,7 +1023,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -870,15 +1037,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 5) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { return errMsg(p, "callable must return 5 values"); } else { @@ -900,6 +1067,11 @@ static int pylcall5t_irate(CSOUND *csound, PYCALL5T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -908,7 +1080,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -918,15 +1094,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 5) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 5)) { return errMsg(p, "callable must return 5 values"); } else { @@ -950,16 +1126,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 6) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { return errMsg(p, "callable must return 6 values"); } else { @@ -977,6 +1157,11 @@ static int pylcall6_irate(CSOUND *csound, PYCALL6 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -985,16 +1170,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 6) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { return errMsg(p, "callable must return 6 values"); } else { @@ -1014,18 +1203,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 6) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { return errMsg(p, "callable must return 6 values"); } else { @@ -1045,7 +1238,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1056,15 +1253,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 6) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { return errMsg(p, "callable must return 6 values"); } else { @@ -1088,6 +1285,11 @@ static int pylcall6t_irate(CSOUND *csound, PYCALL6T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -1096,7 +1298,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1107,15 +1313,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 6) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 6)) { return errMsg(p, "callable must return 6 values"); } else { @@ -1141,16 +1347,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 7) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { return errMsg(p, "callable must return 7 values"); } else { @@ -1169,6 +1379,11 @@ static int pylcall7_irate(CSOUND *csound, PYCALL7 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -1177,16 +1392,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 7) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { return errMsg(p, "callable must return 7 values"); } else { @@ -1207,18 +1426,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 7) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { return errMsg(p, "callable must return 7 values"); } else { @@ -1239,7 +1462,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1251,15 +1478,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 7) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { return errMsg(p, "callable must return 7 values"); } else { @@ -1285,6 +1512,11 @@ static int pylcall7t_irate(CSOUND *csound, PYCALL7T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -1293,7 +1525,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1305,15 +1541,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 7) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 7)) { return errMsg(p, "callable must return 7 values"); } else { @@ -1341,16 +1577,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 8) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { return errMsg(p, "callable must return 8 values"); } else { @@ -1370,6 +1610,11 @@ static int pylcall8_irate(CSOUND *csound, PYCALL8 *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -1378,16 +1623,20 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 8) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { return errMsg(p, "callable must return 8 values"); } else { @@ -1409,18 +1658,22 @@ { char command[1024]; PyObject *result; - - format_call_statement(command, (char*) p->function, + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 1); create_private_namespace_if_needed(&p->h); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 8) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { return errMsg(p, "callable must return 8 values"); } else { @@ -1442,7 +1695,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1455,15 +1712,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, 0); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 8) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { return errMsg(p, "callable must return 8 values"); } else { @@ -1491,6 +1748,11 @@ static int pylcall8t_irate(CSOUND *csound, PYCALL8T *p) { + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -1499,7 +1761,11 @@ { char command[1024]; PyObject *result; - + int *py_initialize_done; + if (UNLIKELY((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0)) + return NOTOK; if (!*p->trigger) { *p->result1 = p->oresult1; *p->result2 = p->oresult2; @@ -1512,15 +1778,15 @@ return OK; } - format_call_statement(command, (char*) p->function, + format_call_statement(command, (char*) p->function->data, p->INOCOUNT, p->args, 2); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); - if (result == NULL) + if (UNLIKELY(result == NULL)) return pyErrMsg(p, "python exception"); - if (!PyTuple_Check(result) || PyTuple_Size(result) != 8) { + if (UNLIKELY(!PyTuple_Check(result) || PyTuple_Size(result) != 8)) { return errMsg(p, "callable must return 8 values"); } else { @@ -1545,4 +1811,3 @@ Py_DECREF(result); return OK; } - diff -Nru csound-5.17.11~dfsg/Opcodes/py/pycall.auto.h csound-6.02~dfsg/Opcodes/py/pycall.auto.h --- csound-5.17.11~dfsg/Opcodes/py/pycall.auto.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pycall.auto.h 2014-01-07 16:53:48.000000000 +0000 @@ -1,21 +1,21 @@ typedef struct { OPDS h; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL0; typedef struct { OPDS h; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL0T; typedef struct { OPDS h; MYFLT *result; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL1; @@ -23,7 +23,7 @@ OPDS h; MYFLT *result; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult; } PYCALL1T; @@ -32,7 +32,7 @@ OPDS h; MYFLT *result1; MYFLT *result2; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL2; @@ -41,7 +41,7 @@ MYFLT *result1; MYFLT *result2; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -52,7 +52,7 @@ MYFLT *result1; MYFLT *result2; MYFLT *result3; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL3; @@ -62,7 +62,7 @@ MYFLT *result2; MYFLT *result3; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -75,7 +75,7 @@ MYFLT *result2; MYFLT *result3; MYFLT *result4; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL4; @@ -86,7 +86,7 @@ MYFLT *result3; MYFLT *result4; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -101,7 +101,7 @@ MYFLT *result3; MYFLT *result4; MYFLT *result5; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL5; @@ -113,7 +113,7 @@ MYFLT *result4; MYFLT *result5; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -130,7 +130,7 @@ MYFLT *result4; MYFLT *result5; MYFLT *result6; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL6; @@ -143,7 +143,7 @@ MYFLT *result5; MYFLT *result6; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -162,7 +162,7 @@ MYFLT *result5; MYFLT *result6; MYFLT *result7; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL7; @@ -176,7 +176,7 @@ MYFLT *result6; MYFLT *result7; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; @@ -197,7 +197,7 @@ MYFLT *result6; MYFLT *result7; MYFLT *result8; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; } PYCALL8; @@ -212,7 +212,7 @@ MYFLT *result7; MYFLT *result8; MYFLT *trigger; - MYFLT *function; + STRINGDAT *function; MYFLT *args[VARGMAX-3]; MYFLT oresult1; MYFLT oresult2; diff -Nru csound-5.17.11~dfsg/Opcodes/py/pythonopcodes.c csound-6.02~dfsg/Opcodes/py/pythonopcodes.c --- csound-5.17.11~dfsg/Opcodes/py/pythonopcodes.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pythonopcodes.c 2014-01-07 16:54:20.000000000 +0000 @@ -20,9 +20,6 @@ #include #include "csdl.h" -#ifdef mac_classic -# include -#endif #include "pythonopcodes.h" #include "pythonhelper.h" @@ -45,6 +42,25 @@ #endif } +static void format_call_statement2(char *statement, char *callable, + int argc, MYFLT *argv[], long skip) +{ + int i; + + statement[0] = '\0'; + if (argc-skip > 0) { + sprintf(statement, "%s(%0.6f", callable, *(argv[skip])); + for (i = skip+1; i < argc; ++i) { + sprintf(statement + strlen(statement), ", %f", *(argv[i])); + } + strcat(statement, ")"); + } + else { + sprintf(statement, "%s()", callable); + } + +} + static void format_call_statement(char *statement, char *callable, int argc, MYFLT *argv[], int skip) { @@ -63,6 +79,7 @@ } } + static PyObject * run_statement_in_given_context(char *string, PyObject *private) { @@ -125,13 +142,7 @@ { CSOUND *csound = ((OPDS*) p)->insdshead->csound; const char *opname = csound->GetOpcodeName(p); - - if (csound->ids != NULL && csound->pds == NULL) - csound->InitError(csound, "%s: %s", opname, msg); - else if (csound->ids == NULL && csound->pds != NULL) - csound->PerfError(csound, "%s: %s", opname, msg); - else - csound->ErrorMsg(csound, "%s: %s", opname, msg); + csound->ErrorMsg(csound, "%s: %s", opname, msg); return NOTOK; } @@ -140,32 +151,38 @@ { CSOUND *csound = ((OPDS*) p)->insdshead->csound; const char *opname = csound->GetOpcodeName(p); - - if (csound->ids != NULL && csound->pds == NULL) - csound->InitError(csound, "%s: %s", opname, msg); - else if (csound->ids == NULL && csound->pds != NULL) - csound->PerfError(csound, "%s: %s", opname, msg); - else - csound->ErrorMsg(csound, "%s: %s", opname, msg); + csound->ErrorMsg(csound, "%s: %s", opname, msg); PyErr_Print(); return NOTOK; } -static int pythonInitialized = 0; - static int pyinit(CSOUND *csound, PYINIT *p) { (void) csound; (void) p; - if (!pythonInitialized) { -#ifdef mac_classic - PyMac_Initialize(); -#else + int *py_initialize_done; + + if((py_initialize_done = csound->QueryGlobalVariable(csound, + "PY_INITIALIZE")) == NULL){ + csound->CreateGlobalVariable(csound, "PY_INITIALIZE", sizeof(int)); + py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE"); + *py_initialize_done = 0; + } + + if (*py_initialize_done == 0) { Py_Initialize(); -#endif - pythonInitialized = 1; + *py_initialize_done = 1; } + + PyObject *module = PyImport_AddModule("__main__"); + if (module == NULL) { + PyErr_SetString(PyExc_RuntimeError, "couldn't find module __main__"); + return NOTOK; + } + PyObject *public = PyModule_GetDict(module); + PyObject *csobj = Py_BuildValue("l", (long) csound); + PyDict_SetItemString(public, "_CSOUND_", csobj); return OK; } @@ -178,8 +195,9 @@ char command[1024]; PyObject *result; - format_call_statement(command, (char*) p->function, - p->INOCOUNT, p->args, (int) *p->nresult + 1); + + format_call_statement2(command, p->function->data, + p->INOCOUNT-2, p->args, *p->nresult); result = eval_string_in_given_context(command, 0); if (result != NULL && PyTuple_Check(result) && PyTuple_Size(result) == (int) *p->nresult) { @@ -205,8 +223,8 @@ char command[1024]; PyObject *result; - format_call_statement(command, (char*) p->function, - p->INOCOUNT, p->args, (int) *p->nresult + 1); + format_call_statement2(command, p->function->data, + p->INOCOUNT-2, p->args, *p->nresult); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); if (result != NULL && PyTuple_Check(result) && PyTuple_Size(result) == (int) *p->nresult) { @@ -227,8 +245,8 @@ PyObject *result; create_private_namespace_if_needed(&p->h); - format_call_statement(command, (char*) p->function, - p->INOCOUNT, p->args, (int) *p->nresult + 1); + format_call_statement2(command, p->function->data, + p->INOCOUNT-2, p->args, *p->nresult); result = eval_string_in_given_context(command, GETPYLOCAL(p->h.insdshead)); if (result != NULL && PyTuple_Check(result) && PyTuple_Size(result) == (int) *p->nresult) { @@ -248,155 +266,153 @@ /* INITIALIZATION */ -{ "pyinit", sizeof(PYINIT), 1, "", "", (SUBR)pyinit, NULL }, +{ "pyinit", sizeof(PYINIT), 0, 1, "", "", (SUBR)pyinit, NULL }, /* RUN GROUP */ - -{ "pyrun", sizeof(PYRUN), 2, "", "S", NULL, (SUBR)pyrun_krate }, -{ "pyruni", sizeof(PYRUN), 1, "", "S", (SUBR)pyruni_irate }, -{ "pylrun", sizeof(PYRUN), 3, "", "S", +{ "pyrun", sizeof(PYRUN), 0, 2, "", "S", NULL, (SUBR)pyrun_krate }, +{ "pyruni", sizeof(PYRUN), 0, 1, "", "S", (SUBR)pyruni_irate }, +{ "pylrun", sizeof(PYRUN), 0, 3, "", "S", (SUBR)pylrun_irate, (SUBR)pylrun_krate }, -{ "pylruni", sizeof(PYRUN), 1, "", "S", (SUBR)pylruni_irate }, +{ "pylruni", sizeof(PYRUN), 0, 1, "", "S", (SUBR)pylruni_irate }, -{ "pyrunt", sizeof(PYRUNT), 2, "", "kS", NULL, (SUBR)pyrunt_krate }, -{ "pylrunt", sizeof(PYRUNT), 3, "", "kS", +{ "pyrunt", sizeof(PYRUNT), 0, 2, "", "kS", NULL, (SUBR)pyrunt_krate }, +{ "pylrunt", sizeof(PYRUNT), 0, 3, "", "kS", (SUBR)pylrunt_irate, (SUBR)pylrunt_krate }, /* EXEC GROUP */ -{ "pyexec", sizeof(PYEXEC), 2, "", "S", NULL, (SUBR)pyexec_krate }, -{ "pyexeci", sizeof(PYEXEC), 1, "", "S", (SUBR)pyexec_krate }, -{ "pylexec", sizeof(PYEXEC), 3, "", "S", +{ "pyexec", sizeof(PYEXEC), 0, 2, "", "S", NULL, (SUBR)pyexec_krate }, +{ "pyexeci", sizeof(PYEXEC), 0, 1, "", "S", (SUBR)pyexec_krate }, +{ "pylexec", sizeof(PYEXEC), 0, 3, "", "S", (SUBR)pylexec_irate, (SUBR)pylexec_krate }, -{ "pylexeci", sizeof(PYEXEC), 1, "", "S", (SUBR)pylexeci_irate }, +{ "pylexeci", sizeof(PYEXEC), 0, 1, "", "S", (SUBR)pylexeci_irate }, -{ "pyexect", sizeof(PYEXECT), 2, "", "kS", NULL, (SUBR)pyexect_krate }, -{ "pylexect", sizeof(PYEXECT), 3, "", "kS", +{ "pyexect", sizeof(PYEXECT), 0, 2, "", "kS", NULL, (SUBR)pyexect_krate }, +{ "pylexect", sizeof(PYEXECT), 0, 3, "", "kS", (SUBR)pylexect_irate, (SUBR)pylexect_krate }, /* CALL GROUP */ -{ "pycall", sizeof(PYCALL0), 2, "" , "Sz", NULL, (SUBR)pycall0_krate }, -{ "pycall1", sizeof(PYCALL1), 2, "k", "Sz", NULL, (SUBR)pycall1_krate }, -{ "pycall2", sizeof(PYCALL2), 2, "kk", "Sz", NULL, (SUBR)pycall2_krate }, -{ "pycall3", sizeof(PYCALL3), 2, "kkk", "Sz", NULL, (SUBR)pycall3_krate }, -{ "pycall4", sizeof(PYCALL4), 2, "kkkk", "Sz", NULL, (SUBR)pycall4_krate }, -{ "pycall5", sizeof(PYCALL5), 2, "kkkkk", "Sz", NULL, (SUBR)pycall5_krate }, -{ "pycall6", sizeof(PYCALL6), 2, "kkkkkk", "Sz", NULL, (SUBR)pycall6_krate }, -{ "pycall7", sizeof(PYCALL7), 2, "kkkkkkk", "Sz", NULL, (SUBR)pycall7_krate }, -{ "pycall8", sizeof(PYCALL8), 2, "kkkkkkkk", "Sz", NULL, (SUBR)pycall8_krate }, - -{ "pycalln", sizeof(PYCALLN), 2, "", "Siz", NULL, (SUBR)pycalln_krate }, - -{ "pycallt", sizeof(PYCALL0T), 2, "" , "kSz", NULL, (SUBR)pycall0t_krate }, -{ "pycall1t", sizeof(PYCALL1T), 2, "k", "kSz", NULL, (SUBR)pycall1t_krate }, -{ "pycall2t", sizeof(PYCALL2T), 2, "kk", "kSz", NULL, (SUBR)pycall2t_krate }, -{ "pycall3t", sizeof(PYCALL3T), 2, "kkk", "kSz", NULL, (SUBR)pycall3t_krate }, -{ "pycall4t", sizeof(PYCALL4T), 2, "kkkk", "kSz", NULL, (SUBR)pycall4t_krate }, -{ "pycall5t", sizeof(PYCALL5T), 2, "kkkkk", "kSz", NULL, (SUBR)pycall5t_krate }, -{ "pycall6t", sizeof(PYCALL6T), 2, "kkkkkk", "kSz", NULL, (SUBR)pycall6t_krate }, -{ "pycall7t", sizeof(PYCALL7T), 2, "kkkkkkk", "kSz", NULL, (SUBR)pycall7t_krate }, -{ "pycall8t", sizeof(PYCALL8T), 2, "kkkkkkkk", "kSz", NULL, (SUBR)pycall8t_krate }, +{ "pycall", sizeof(PYCALL0), 0, 2, "" , "Sz", NULL, (SUBR)pycall0_krate }, +{ "pycall1", sizeof(PYCALL1), 0, 2, "k", "Sz", NULL, (SUBR)pycall1_krate }, +{ "pycall2", sizeof(PYCALL2), 0, 2, "kk", "Sz", NULL, (SUBR)pycall2_krate }, +{ "pycall3", sizeof(PYCALL3), 0, 2, "kkk", "Sz", NULL, (SUBR)pycall3_krate }, +{ "pycall4", sizeof(PYCALL4), 0, 2, "kkkk", "Sz", NULL, (SUBR)pycall4_krate }, +{ "pycall5", sizeof(PYCALL5), 0, 2, "kkkkk", "Sz", NULL, (SUBR)pycall5_krate }, +{ "pycall6", sizeof(PYCALL6), 0, 2, "kkkkkk", "Sz", NULL, (SUBR)pycall6_krate }, +{ "pycall7", sizeof(PYCALL7), 0, 2, "kkkkkkk", "Sz", NULL, (SUBR)pycall7_krate }, +{ "pycall8", sizeof(PYCALL8), 0, 2, "kkkkkkkk", "Sz", NULL,(SUBR)pycall8_krate }, + +{ "pycalln", sizeof(PYCALLN), 0, 2, "", "Siz", NULL, (SUBR)pycalln_krate }, + +{ "pycallt", sizeof(PYCALL0T), 0, 2, "" , "kSz", NULL, (SUBR)pycall0t_krate }, +{ "pycall1t", sizeof(PYCALL1T), 0, 2, "k", "kSz", NULL, (SUBR)pycall1t_krate }, +{ "pycall2t", sizeof(PYCALL2T), 0, 2, "kk", "kSz", NULL, (SUBR)pycall2t_krate }, +{ "pycall3t", sizeof(PYCALL3T),0, 2, "kkk", "kSz", NULL, (SUBR)pycall3t_krate }, +{ "pycall4t", sizeof(PYCALL4T), 0, 2, "kkkk", "kSz", NULL, (SUBR)pycall4t_krate }, +{ "pycall5t", sizeof(PYCALL5T), 0, 2, "kkkkk", "kSz", NULL, (SUBR)pycall5t_krate }, +{ "pycall6t", sizeof(PYCALL6T), 0, 2, "kkkkkk", "kSz", NULL,(SUBR)pycall6t_krate }, +{ "pycall7t", sizeof(PYCALL7T), 0, 2, "kkkkkkk","kSz", NULL,(SUBR)pycall7t_krate }, +{ "pycall8t", sizeof(PYCALL8T), 0, 2, "kkkkkkkk","kSz",NULL,(SUBR)pycall8t_krate }, #if 0 -{ "pycallnt", sizeof(PYCALLNT), 2, "", "Siz", NULL, (SUBR)pycallnt_krate }, +{ "pycallnt", sizeof(PYCALLNT), 0, 2, "", "Siz", NULL, (SUBR)pycallnt_krate }, #endif -{ "pycalli", sizeof(PYCALL0), 1, "", "Sm", (SUBR)pycall0_krate }, -{ "pycall1i", sizeof(PYCALL1), 1, "i", "Sm", (SUBR)pycall1_krate }, -{ "pycall2i", sizeof(PYCALL2), 1, "ii", "Sm", (SUBR)pycall2_krate }, -{ "pycall3i", sizeof(PYCALL3), 1, "iii", "Sm", (SUBR)pycall3_krate }, -{ "pycall4i", sizeof(PYCALL4), 1, "iiii", "Sm", (SUBR)pycall4_krate }, -{ "pycall5i", sizeof(PYCALL5), 1, "iiiii", "Sm", (SUBR)pycall5_krate }, -{ "pycall6i", sizeof(PYCALL6), 1, "iiiiii", "Sm", (SUBR)pycall6_krate }, -{ "pycall7i", sizeof(PYCALL7), 1, "iiiiiii", "Sm", (SUBR)pycall7_krate }, -{ "pycall8i", sizeof(PYCALL8), 1, "iiiiiiii", "Sm", (SUBR)pycall8_krate }, +{ "pycalli", sizeof(PYCALL0), 0, 1, "", "Sm", (SUBR)pycall0_krate }, +{ "pycall1i", sizeof(PYCALL1), 0, 1, "i", "Sm", (SUBR)pycall1_krate }, +{ "pycall2i", sizeof(PYCALL2), 0, 1, "ii", "Sm", (SUBR)pycall2_krate }, +{ "pycall3i", sizeof(PYCALL3), 0, 1, "iii", "Sm", (SUBR)pycall3_krate }, +{ "pycall4i", sizeof(PYCALL4), 0, 1, "iiii", "Sm", (SUBR)pycall4_krate }, +{ "pycall5i", sizeof(PYCALL5), 0, 1, "iiiii", "Sm", (SUBR)pycall5_krate }, +{ "pycall6i", sizeof(PYCALL6), 0, 1, "iiiiii", "Sm", (SUBR)pycall6_krate }, +{ "pycall7i", sizeof(PYCALL7), 0, 1, "iiiiiii", "Sm", (SUBR)pycall7_krate }, +{ "pycall8i", sizeof(PYCALL8), 0, 1, "iiiiiiii", "Sm", (SUBR)pycall8_krate }, -{ "pycallni", sizeof(PYCALLN), 1, "", "Sim", (SUBR)pycalln_krate }, +{ "pycallni", sizeof(PYCALLN), 0, 1, "", "Sim", (SUBR)pycalln_krate }, -{ "pylcall", sizeof(PYCALL0), 3, "" , "Sz", +{ "pylcall", sizeof(PYCALL0), 0, 3, "" , "Sz", (SUBR)pylcall0_irate, (SUBR)pylcall0_krate }, -{ "pylcall1", sizeof(PYCALL1), 3, "k", "Sz", +{ "pylcall1", sizeof(PYCALL1), 0, 3, "k", "Sz", (SUBR)pylcall1_irate, (SUBR)pylcall1_krate }, -{ "pylcall2", sizeof(PYCALL2), 3, "kk", "Sz", +{ "pylcall2", sizeof(PYCALL2), 0, 3, "kk", "Sz", (SUBR)pylcall2_irate, (SUBR)pylcall2_krate }, -{ "pylcall3", sizeof(PYCALL3), 3, "kkk", "Sz", +{ "pylcall3", sizeof(PYCALL3), 0, 3, "kkk", "Sz", (SUBR)pylcall3_irate, (SUBR)pylcall3_krate }, -{ "pylcall4", sizeof(PYCALL4), 3, "kkkk", "Sz", +{ "pylcall4", sizeof(PYCALL4), 0, 3, "kkkk", "Sz", (SUBR)pylcall4_irate, (SUBR)pylcall4_krate }, -{ "pylcall5", sizeof(PYCALL5), 3, "kkkkk", "Sz", +{ "pylcall5", sizeof(PYCALL5), 0, 3, "kkkkk", "Sz", (SUBR)pylcall5_irate, (SUBR)pylcall5_krate }, -{ "pylcall6", sizeof(PYCALL6), 3, "kkkkkk", "Sz", +{ "pylcall6", sizeof(PYCALL6), 0, 3, "kkkkkk", "Sz", (SUBR)pylcall6_irate, (SUBR)pylcall6_krate }, -{ "pylcall7", sizeof(PYCALL7), 3, "kkkkkkk", "Sz", +{ "pylcall7", sizeof(PYCALL7), 0, 3, "kkkkkkk", "Sz", (SUBR)pylcall7_irate, (SUBR)pylcall7_krate }, -{ "pylcall8", sizeof(PYCALL8), 3, "kkkkkkkk", "Sz", +{ "pylcall8", sizeof(PYCALL8), 0, 3, "kkkkkkkk", "Sz", (SUBR)pylcall8_irate, (SUBR)pylcall8_krate }, -{ "pylcalln", sizeof(PYCALLN), 3, "", "Siz", +{ "pylcalln", sizeof(PYCALLN), 0, 3, "", "Siz", (SUBR)pylcalln_irate, (SUBR)pylcalln_krate }, -{ "pylcallt", sizeof(PYCALL0T), 3, "" , "kSz", +{ "pylcallt", sizeof(PYCALL0T), 0, 3, "" , "kSz", (SUBR)pylcall0t_irate, (SUBR)pylcall0t_krate }, -{ "pylcall1t", sizeof(PYCALL1T), 3, "k", "kSz", +{ "pylcall1t", sizeof(PYCALL1T), 0, 3, "k", "kSz", (SUBR)pylcall1t_irate, (SUBR)pylcall1t_krate }, -{ "pylcall2t", sizeof(PYCALL2T), 3, "kk", "kSz", +{ "pylcall2t", sizeof(PYCALL2T), 0, 3, "kk", "kSz", (SUBR)pylcall2t_irate, (SUBR)pylcall2t_krate }, -{ "pylcall3t", sizeof(PYCALL3T), 3, "kkk", "kSz", +{ "pylcall3t", sizeof(PYCALL3T), 0, 3, "kkk", "kSz", (SUBR)pylcall3t_irate, (SUBR)pylcall3t_krate }, -{ "pylcall4t", sizeof(PYCALL4T), 3, "kkkk", "kSz", +{ "pylcall4t", sizeof(PYCALL4T), 0, 3, "kkkk", "kSz", (SUBR)pylcall4t_irate, (SUBR)pylcall4t_krate }, -{ "pylcall5t", sizeof(PYCALL5T), 3, "kkkkk", "kSz", +{ "pylcall5t", sizeof(PYCALL5T), 0, 3, "kkkkk", "kSz", (SUBR)pylcall5t_irate, (SUBR)pylcall5t_krate }, -{ "pylcall6t", sizeof(PYCALL6T), 3, "kkkkkk", "kSz", +{ "pylcall6t", sizeof(PYCALL6T), 0, 3, "kkkkkk", "kSz", (SUBR)pylcall6t_irate, (SUBR)pylcall6t_krate }, -{ "pylcall7t", sizeof(PYCALL7T), 3, "kkkkkkk", "kSz", +{ "pylcall7t", sizeof(PYCALL7T), 0, 3, "kkkkkkk", "kSz", (SUBR)pylcall7t_irate, (SUBR)pylcall7t_krate }, -{ "pylcall8t", sizeof(PYCALL8T), 3, "kkkkkkkk", "kSz", +{ "pylcall8t", sizeof(PYCALL8T), 0, 3, "kkkkkkkk", "kSz", (SUBR)pylcall8t_irate, (SUBR)pylcall8t_krate }, #if 0 -{ "pylcallnt", sizeof(PYCALLNT), 3, "", "Siz", +{ "pylcallnt", sizeof(PYCALLNT), 0, 3, "", "Siz", (SUBR)pylcalln_irate, (SUBR)pylcallnt_krate }, #endif -{ "pylcalli", sizeof(PYCALL0), 1, "", "Sm", (SUBR)pylcall0i_irate }, -{ "pylcall1i", sizeof(PYCALL1), 1, "i", "Sm", (SUBR)pylcall1i_irate }, -{ "pylcall2i", sizeof(PYCALL2), 1, "ii", "Sm", (SUBR)pylcall2i_irate }, -{ "pylcall3i", sizeof(PYCALL3), 1, "iii", "Sm", (SUBR)pylcall3i_irate }, -{ "pylcall4i", sizeof(PYCALL4), 1, "iiii", "Sm", (SUBR)pylcall4i_irate }, -{ "pylcall5i", sizeof(PYCALL5), 1, "iiiii", "Sm", (SUBR)pylcall5i_irate }, -{ "pylcall6i", sizeof(PYCALL6), 1, "iiiiii", "Sm", (SUBR)pylcall6i_irate }, -{ "pylcall7i", sizeof(PYCALL7), 1, "iiiiiii", "Sm", (SUBR)pylcall7i_irate }, -{ "pylcall8i", sizeof(PYCALL8), 1, "iiiiiiii", "Sm", (SUBR)pylcall8i_irate }, +{ "pylcalli", sizeof(PYCALL0), 0, 1, "", "Sm", (SUBR)pylcall0i_irate }, +{ "pylcall1i", sizeof(PYCALL1), 0, 1, "i", "Sm", (SUBR)pylcall1i_irate }, +{ "pylcall2i", sizeof(PYCALL2), 0, 1, "ii", "Sm", (SUBR)pylcall2i_irate }, +{ "pylcall3i", sizeof(PYCALL3), 0, 1, "iii", "Sm", (SUBR)pylcall3i_irate }, +{ "pylcall4i", sizeof(PYCALL4), 0, 1, "iiii", "Sm", (SUBR)pylcall4i_irate }, +{ "pylcall5i", sizeof(PYCALL5), 0, 1, "iiiii", "Sm", (SUBR)pylcall5i_irate }, +{ "pylcall6i", sizeof(PYCALL6), 0, 1, "iiiiii", "Sm", (SUBR)pylcall6i_irate }, +{ "pylcall7i", sizeof(PYCALL7), 0, 1, "iiiiiii", "Sm", (SUBR)pylcall7i_irate }, +{ "pylcall8i", sizeof(PYCALL8), 0, 1, "iiiiiiii", "Sm", (SUBR)pylcall8i_irate }, -{ "pylcallni", sizeof(PYCALLN), 1, "", "Sim", (SUBR)pylcallni_irate }, +{ "pylcallni", sizeof(PYCALLN), 0, 1, "", "Sim", (SUBR)pylcallni_irate }, /* EVAL GROUP */ -{ "pyeval", sizeof(PYEVAL), 2, "k", "S", NULL, (SUBR)pyeval_krate }, -{ "pyevali", sizeof(PYEVAL), 1, "i", "S", (SUBR)pyeval_krate }, -{ "pyleval", sizeof(PYEVAL), 3, "k", "S", +{ "pyeval", sizeof(PYEVAL), 0, 2, "k", "S", NULL, (SUBR)pyeval_krate }, +{ "pyevali", sizeof(PYEVAL), 0, 1, "i", "S", (SUBR)pyeval_krate }, +{ "pyleval", sizeof(PYEVAL), 0, 3, "k", "S", (SUBR)pyleval_irate, (SUBR)pyleval_krate }, -{ "pylevali", sizeof(PYEVAL), 1, "i", "S", (SUBR)pylevali_irate }, +{ "pylevali", sizeof(PYEVAL), 0, 1, "i", "S", (SUBR)pylevali_irate }, -{ "pyevalt", sizeof(PYEVALT), 2, "k", "S", NULL, (SUBR)pyevalt_krate }, -{ "pylevalt", sizeof(PYEVALT), 3, "k", "S", +{ "pyevalt", sizeof(PYEVALT), 0, 2, "k", "S", NULL, (SUBR)pyevalt_krate }, +{ "pylevalt", sizeof(PYEVALT), 0, 3, "k", "S", (SUBR)pylevalt_irate, (SUBR)pylevalt_krate }, /* ASSIGN GROUP */ -{ "pyassign", sizeof(PYASSIGN), 2, "", "Sz", NULL, (SUBR)pyassign_krate }, -{ "pyassigni", sizeof(PYASSIGN), 1, "", "Sz", (SUBR)pyassign_krate }, -{ "pylassign", sizeof(PYASSIGN), 3, "", "Sz", +{ "pyassign", sizeof(PYASSIGN), 0, 2, "", "Sz", NULL, (SUBR)pyassign_krate }, +{ "pyassigni", sizeof(PYASSIGN), 0, 1, "", "Sz", (SUBR)pyassign_krate }, +{ "pylassign", sizeof(PYASSIGN), 0, 3, "", "Sz", (SUBR)pylassign_irate, (SUBR)pylassign_krate }, -{ "pylassigni", sizeof(PYASSIGN), 1, "", "Sz", (SUBR)pylassigni_irate }, +{ "pylassigni", sizeof(PYASSIGN), 0, 1, "", "Sz", (SUBR)pylassigni_irate }, -{ "pyassignt", sizeof(PYASSIGNT), 2, "", "Sz", NULL, (SUBR)pyassignt_krate }, -{ "pylassignt", sizeof(PYASSIGNT), 3, "", "Sz", +{ "pyassignt", sizeof(PYASSIGNT), 0, 2, "", "Sz", NULL, (SUBR)pyassignt_krate }, +{ "pylassignt", sizeof(PYASSIGNT), 0, 3, "", "Sz", (SUBR)pylassignt_irate, (SUBR)pylassignt_krate }, }; -LINKAGE1(python_localops) - +LINKAGE_BUILTIN(python_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/py/pythonopcodes.h csound-6.02~dfsg/Opcodes/py/pythonopcodes.h --- csound-5.17.11~dfsg/Opcodes/py/pythonopcodes.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pythonopcodes.h 2014-01-07 16:53:48.000000000 +0000 @@ -32,7 +32,7 @@ typedef struct { OPDS h; - MYFLT *function; + STRINGDAT *function; MYFLT *nresult; MYFLT *args[VARGMAX]; } PYCALLN; diff -Nru csound-5.17.11~dfsg/Opcodes/py/pyx-gen.py csound-6.02~dfsg/Opcodes/py/pyx-gen.py --- csound-5.17.11~dfsg/Opcodes/py/pyx-gen.py 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pyx-gen.py 2014-01-07 16:53:48.000000000 +0000 @@ -47,6 +47,9 @@ print >> f, '{' print >> f, ' char source[%d];' % size print >> f, ' PyObject *result;' + print >> f, ' int *py_initialize_done;' + print >> f, ' if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||*py_initialize_done == 0)' + print >> f, ' return NOTOK;' print >> f if triggered: @@ -65,9 +68,9 @@ print >> f if action == 'assign': - print >> f, ' sprintf(source, "%s = %f", (char*) p->string, *p->value);' + print >> f, ' sprintf(source, "%s = %f", (char*) p->string->data, *p->value);' else: - print >> f, ' strcpy(source, (char*) p->string);' + print >> f, ' strcpy(source, (char*) p->string->data);' print >> f if action == 'exec': @@ -100,6 +103,9 @@ t, T = '', '' print >> f, 'static int pyl%(action)s%(t)s_irate(CSOUND *csound, PY%(ACTION)s%(T)s *p)' % locals() print >> f, '{' + print >> f, ' int *py_initialize_done;' + print >> f, ' if((py_initialize_done = csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL ||*py_initialize_done == 0)' + print >> f, ' return NOTOK;' print >> f, ' create_private_namespace_if_needed(&p->h);' print >> f, ' return OK;' print >> f, '}' diff -Nru csound-5.17.11~dfsg/Opcodes/py/pyx.auto.c csound-6.02~dfsg/Opcodes/py/pyx.auto.c --- csound-5.17.11~dfsg/Opcodes/py/pyx.auto.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pyx.auto.c 2014-01-07 16:53:48.000000000 +0000 @@ -3,8 +3,13 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if ((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, 0); if (result == NULL) { @@ -19,20 +24,30 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, 0); if (result == NULL) { return pyErrMsg(p, "python exception"); } Py_DECREF(result); - return OK; + return OK; } #endif static int pylexec_irate(CSOUND *csound, PYEXEC *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -41,8 +56,13 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -56,10 +76,15 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -73,11 +98,16 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, 0); if (result == NULL) { @@ -89,6 +119,11 @@ static int pylexect_irate(CSOUND *csound, PYEXECT *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -97,11 +132,16 @@ { char source[1024]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = exec_file_in_given_context(csound, source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -115,8 +155,13 @@ { char source[40960]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -130,8 +175,13 @@ { char source[40960]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -143,6 +193,11 @@ static int pylrun_irate(CSOUND *csound, PYRUN *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -151,8 +206,13 @@ { char source[40960]; PyObject *result; + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -166,10 +226,14 @@ { char source[40960]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -183,11 +247,15 @@ { char source[40960]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -199,6 +267,11 @@ static int pylrunt_irate(CSOUND *csound, PYRUNT *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -207,11 +280,15 @@ { char source[40960]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -225,8 +302,12 @@ { char source[1024]; PyObject *result; - - strcpy(source, (char*) p->string); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, 0); if (result == NULL) { @@ -247,8 +328,12 @@ { char source[1024]; PyObject *result; - - strcpy(source, (char*) p->string); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, 0); if (result == NULL) { @@ -267,6 +352,11 @@ static int pyleval_irate(CSOUND *csound, PYEVAL *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -275,8 +365,12 @@ { char source[1024]; PyObject *result; - - strcpy(source, (char*) p->string); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -296,10 +390,14 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -319,13 +417,17 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) { *p->result = p->oresult; return OK; } - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, 0); if (result == NULL) { @@ -344,6 +446,11 @@ static int pylevalt_irate(CSOUND *csound, PYEVALT *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -352,13 +459,17 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) { *p->result = p->oresult; return OK; } - strcpy(source, (char*) p->string); + strcpy(source, (char*) p->string->data); result = eval_string_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -379,8 +490,12 @@ { char source[1024]; PyObject *result; - - sprintf(source, "%s = %f", (char*) p->string, *p->value); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -395,8 +510,12 @@ { char source[1024]; PyObject *result; - - sprintf(source, "%s = %f", (char*) p->string, *p->value); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -409,6 +528,11 @@ static int pylassign_irate(CSOUND *csound, PYASSIGN *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -417,8 +541,12 @@ { char source[1024]; PyObject *result; - - sprintf(source, "%s = %f", (char*) p->string, *p->value); + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -432,10 +560,14 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); - sprintf(source, "%s = %f", (char*) p->string, *p->value); + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -449,11 +581,15 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - sprintf(source, "%s = %f", (char*) p->string, *p->value); + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, 0); if (result == NULL) { @@ -465,6 +601,11 @@ static int pylassignt_irate(CSOUND *csound, PYASSIGNT *p) { + int *py_initialize_done; + if((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; create_private_namespace_if_needed(&p->h); return OK; } @@ -473,11 +614,15 @@ { char source[1024]; PyObject *result; - + int *py_initialize_done; + if ((py_initialize_done = + csound->QueryGlobalVariable(csound,"PY_INITIALIZE")) == NULL || + *py_initialize_done == 0) + return NOTOK; if (!*p->trigger) return OK; - sprintf(source, "%s = %f", (char*) p->string, *p->value); + sprintf(source, "%s = %f", (char*) p->string->data, *p->value); result = run_statement_in_given_context(source, GETPYLOCAL(p->h.insdshead)); if (result == NULL) { @@ -486,4 +631,3 @@ Py_DECREF(result); return OK; } - diff -Nru csound-5.17.11~dfsg/Opcodes/py/pyx.auto.h csound-6.02~dfsg/Opcodes/py/pyx.auto.h --- csound-5.17.11~dfsg/Opcodes/py/pyx.auto.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/py/pyx.auto.h 2014-01-07 16:53:48.000000000 +0000 @@ -1,50 +1,50 @@ typedef struct { OPDS h; - MYFLT *string; + STRINGDAT *string; } PYEXEC; typedef struct { OPDS h; MYFLT *trigger; - MYFLT *string; + STRINGDAT *string; } PYEXECT; typedef struct { OPDS h; - MYFLT *string; + STRINGDAT *string; } PYRUN; typedef struct { OPDS h; MYFLT *trigger; - MYFLT *string; + STRINGDAT *string; } PYRUNT; typedef struct { OPDS h; MYFLT *result; - MYFLT *string; + STRINGDAT *string; } PYEVAL; typedef struct { OPDS h; MYFLT *result; MYFLT *trigger; - MYFLT *string; + STRINGDAT *string; MYFLT oresult; } PYEVALT; typedef struct { OPDS h; - MYFLT *string; + STRINGDAT *string; MYFLT *value; } PYASSIGN; typedef struct { OPDS h; MYFLT *trigger; - MYFLT *string; + STRINGDAT *string; MYFLT *value; } PYASSIGNT; diff -Nru csound-5.17.11~dfsg/Opcodes/repluck.c csound-6.02~dfsg/Opcodes/repluck.c --- csound-5.17.11~dfsg/Opcodes/repluck.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/repluck.c 2014-01-07 16:54:20.000000000 +0000 @@ -28,7 +28,7 @@ * 3 March 1996 John ffitch * \***************************************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "repluck.h" static int wgpsetin(CSOUND *, WGPLUCK2 *); @@ -54,9 +54,9 @@ DelayLine *lower_rail; MYFLT plk = *p->plk; /* Initialize variables....*/ - npts = (int)(csound->esr / *p->icps);/* Length of full delay */ + npts = (int)(CS_ESR / *p->icps);/* Length of full delay */ while (npts < 512) { /* Minimum rail length is 256 */ - npts += (int)(csound->esr / *p->icps); + npts += (int)(CS_ESR / *p->icps); scale++; } rail_len = npts/2/* + 1*/; /* but only need half length */ @@ -95,7 +95,7 @@ /* Set initial shape */ if (plk != FL(0.0)) { - initial_shape = (MYFLT*)malloc(rail_len*sizeof(MYFLT)); + initial_shape = (MYFLT*) malloc(rail_len*sizeof(MYFLT)); if (pickpt < 1) pickpt = 1; /* Place for pluck, in range (0,1.0) */ upslope = FL(1.0)/(MYFLT)pickpt; /* Slightly faster to precalculate */ downslope = FL(1.0)/(MYFLT)(rail_len - pickpt - 1); @@ -150,7 +150,9 @@ static int wgpluck(CSOUND *csound, WGPLUCK2 *p) { MYFLT *ar, *ain; - int n,nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT yp0,ym0,ypM,ymM; DelayLine *upper_rail; DelayLine *lower_rail; @@ -170,7 +172,8 @@ reflect = FL(1.0) - (FL(1.0) - reflect)/(MYFLT)scale; /* For over sapling */ upper_rail = (DelayLine*)p->upper.auxp; lower_rail = (DelayLine*)p->lower.auxp; - pickup = (int)((MYFLT)OVERCNT * *(p->pickup) * p->rail_len); /* fract delays */ + /* fractional delays */ + pickup = (int)((MYFLT)OVERCNT * *(p->pickup) * p->rail_len); pickfrac = pickup & OVERMSK; pickup = pickup>>OVERSHT; if (UNLIKELY(pickup<0 || pickup > p->rail_len)) { @@ -180,7 +183,12 @@ pickup = pickup>>OVERSHT; } - for (n=0;nsize = (int) (csound->esr/20); /* size of delay line */ + p->size = (int) (CS_ESR/20); /* size of delay line */ csound->AuxAlloc(csound, p->size*sizeof(MYFLT), &p->aux); p->Cdelay = (MYFLT*) p->aux.auxp; /* delay line */ p->LPdelay = p->APdelay = FL(0.0); /* reset the All-pass and Low-pass delays */ @@ -254,7 +262,10 @@ MYFLT g = *p->ifdbgain; MYFLT freq; double a, s, w, sample, tdelay, fracdelay; - int delay, n, nsmps = csound->ksmps; + int delay; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int rp = p->rpointer, wp = p->wpointer; int size = p->size; MYFLT APdelay = p->APdelay; @@ -263,12 +274,17 @@ freq = *p->afr; if (freq < FL(20.0)) freq = FL(20.0); /* lowest freq is 20 Hz */ - tdelay = csound->esr/freq; + tdelay = CS_ESR/freq; delay = (int) (tdelay - 0.5); /* comb delay */ fracdelay = tdelay - (delay + 0.5); /* fractional delay */ vdt = size - delay; /* set the var delay */ a = (1.0-fracdelay)/(1.0+fracdelay); /* set the all-pass gain */ - for (n=0;n #define DEFAULT_SRATE 44100.0 @@ -167,14 +167,15 @@ /* check for valid parameters */ if (*(p->iSampleRate) <= FL(0.0)) - p->sampleRate = (double) csound->esr; + p->sampleRate = (double) CS_ESR; else p->sampleRate = (double) *(p->iSampleRate); if (UNLIKELY(p->sampleRate < MIN_SRATE || p->sampleRate > MAX_SRATE)) { return csound->InitError(csound, Str("reverbsc: sample rate is out of range")); } - if (UNLIKELY(*(p->iPitchMod) < FL(0.0) || *(p->iPitchMod) > (MYFLT) MAX_PITCHMOD)) { + if (UNLIKELY(*(p->iPitchMod) < FL(0.0) || + *(p->iPitchMod) > (MYFLT) MAX_PITCHMOD)) { return csound->InitError(csound, Str("reverbsc: invalid pitch modulation factor")); } @@ -182,7 +183,7 @@ nBytes = 0; for (i = 0; i < 8; i++) nBytes += delay_line_bytes_alloc(p, i); - if (nBytes != p->auxData.size) + if (nBytes != (int)p->auxData.size) csound->AuxAlloc(csound, (size_t) nBytes, &(p->auxData)); else if (p->initDone && *(p->iSkipInit) != FL(0.0)) return OK; /* skip initialisation if requested */ @@ -206,7 +207,10 @@ double ainL, ainR, aoutL, aoutR; double vm1, v0, v1, v2, am1, a0, a1, a2, frac; delayLine *lp; - int i, n, nsmps = csound->ksmps, readPos; + int readPos; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, n, nsmps = CS_KSMPS; int bufferSize; /* Local copy */ double dampFact = p->dampFact; @@ -217,8 +221,17 @@ dampFact = 2.0 - cos(p->prv_LPFreq * TWOPI / p->sampleRate); dampFact = p->dampFact = dampFact - sqrt(dampFact * dampFact - 1.0); } + if (UNLIKELY(offset)) { + memset(p->aoutL, '\0', offset*sizeof(MYFLT)); + memset(p->aoutR, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->aoutL[nsmps], '\0', early*sizeof(MYFLT)); + memset(&p->aoutR[nsmps], '\0', early*sizeof(MYFLT)); + } /* update delay lines */ - for (i = 0; i < nsmps; i++) { + for (i = offset; i < nsmps; i++) { /* calculate "resultant junction pressure" and mix to input signals */ ainL = aoutL = aoutR = 0.0; for (n = 0; n < 8; n++) @@ -288,7 +301,8 @@ return OK; err1: - return csound->PerfError(csound, Str("reverbsc: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("reverbsc: not initialised")); } /* module interface functions */ @@ -296,7 +310,7 @@ int reverbsc_init_(CSOUND *csound) { return csound->AppendOpcode(csound, "reverbsc", - (int) sizeof(SC_REVERB), 5, "aa", "aakkjpo", + (int) sizeof(SC_REVERB), 0, 5, "aa", "aakkjpo", (int (*)(CSOUND *, void *)) sc_reverb_init, (int (*)(CSOUND *, void *)) NULL, (int (*)(CSOUND *, void *)) sc_reverb_perf); diff -Nru csound-5.17.11~dfsg/Opcodes/scoreline.c csound-6.02~dfsg/Opcodes/scoreline.c --- csound-5.17.11~dfsg/Opcodes/scoreline.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/scoreline.c 2014-01-07 16:53:48.000000000 +0000 @@ -23,10 +23,12 @@ //#include "csdl.h" #include "csoundCore.h" +extern void csoundInputMessageInternal(CSOUND *, const char *); typedef struct _inmess { OPDS h; - MYFLT *SMess, *ktrig; + STRINGDAT *SMess; + MYFLT *ktrig; } INMESS; @@ -37,31 +39,31 @@ int messi(CSOUND *csound, INMESS *p) { - csound->InputMessage(csound, (char *)p->SMess); + csoundInputMessageInternal(csound, (char *)p->SMess->data); return OK; } int messk(CSOUND *csound, INMESS *p){ - if (*p->ktrig) csound->InputMessage(csound, (char *)p->SMess); + if (*p->ktrig) csoundInputMessageInternal(csound, (char *)p->SMess->data); return OK; } int setscorepos(CSOUND *csound, SCOREPOS *p){ - csound->SetScoreOffsetSeconds(csound, *p->spos); + csoundSetScoreOffsetSeconds(csound, *p->spos); return OK; } int rewindscore(CSOUND *csound, SCOREPOS *p){ - csound->RewindScore(csound); + csoundRewindScore(csound); return OK; } static OENTRY scoreline_localops[] = { - {"scoreline_i", sizeof(INMESS), 1, "", "S", (SUBR)messi, NULL, NULL}, - {"scoreline", sizeof(INMESS), 2, "", "Sk", NULL, (SUBR)messk, NULL}, - {"setscorepos", sizeof(SCOREPOS), 1, "", "i", (SUBR)setscorepos, NULL, NULL}, - {"rewindscore", sizeof(SCOREPOS), 1, "", "", (SUBR)rewindscore, NULL, NULL} + {"scoreline_i", sizeof(INMESS), 0, 1, "", "S", (SUBR)messi, NULL, NULL}, + {"scoreline", sizeof(INMESS), 0, 2, "", "Sk", NULL, (SUBR)messk, NULL}, + {"setscorepos", sizeof(SCOREPOS), 0, 1, "", "i", (SUBR)setscorepos, NULL, NULL}, + {"rewindscore", sizeof(SCOREPOS), 0, 1, "", "", (SUBR)rewindscore, NULL, NULL} }; -LINKAGE1(scoreline_localops) +LINKAGE_BUILTIN(scoreline_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/seqtime.c csound-6.02~dfsg/Opcodes/seqtime.c --- csound-5.17.11~dfsg/Opcodes/seqtime.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/seqtime.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" typedef struct { OPDS h; @@ -49,7 +49,7 @@ int32 start, loop; int32 *ndx = &p->ndx; p->pfn = (int32) *p->kfn; - if (UNLIKELY((ftp = csound->FTFind(csound, p->kfn)) == NULL)) { + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->kfn)) == NULL)) { return csound->InitError(csound, Str("seqtime: incorrect table number")); } @@ -60,7 +60,7 @@ p->newtime = p->table[p->ndx-1]; else p->newtime = 0; - p->start = (double)csound->kcounter * csound->onedkr; + p->start = (double)CS_KCNT * CS_ONEDKR; start = (int32) *p->kstart; loop = (int32) *p->kloop; if (loop > 0) { @@ -95,14 +95,14 @@ } if (p->curr_unit_time != *p->unit_time) { - double constant = p->start - (double)csound->kcounter * csound->onedkr; + double constant = p->start - (double)CS_KCNT * CS_ONEDKR; double difference_new = p->newtime * p->curr_unit_time + constant; double difference_old = p->newtime * *p->unit_time + constant; double difference = difference_new - difference_old; p->start = p->start + difference; p->curr_unit_time = *p->unit_time; } - if (csound->kcounter * csound->onedkr + if (CS_KCNT * CS_ONEDKR > p->newtime * *p->unit_time + p->start) { MYFLT curr_val = p->table[p->ndx]; p->first_flag = 0; @@ -142,7 +142,7 @@ } return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("seqtime: incorrect table number")); } @@ -154,14 +154,14 @@ int32 start, loop; int32 *ndx = &p->ndx; p->pfn = (int32) *p->kfn; - if (UNLIKELY((ftp = csound->FTFind(csound, p->kfn)) == NULL)) { + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->kfn)) == NULL)) { return csound->InitError(csound, Str("seqtim: incorrect table number")); } *ndx = (int32) *p->kinitndx; p->done=0; p->table = ftp->ftable; p->newtime = p->table[p->ndx]; - p->start = csound->kcounter * csound->onedkr; + p->start = CS_KCNT * CS_ONEDKR; start = (int32) *p->kstart; loop = (int32) *p->kloop; if (loop > 0 ) { @@ -201,14 +201,14 @@ p->table = ftp->ftable; } if (p->curr_unit_time != *p->unit_time) { - double constant = p->start - csound->kcounter * csound->onedkr; + double constant = p->start - CS_KCNT * CS_ONEDKR; double difference_new = p->newtime * p->curr_unit_time + constant; double difference_old = p->newtime * *p->unit_time + constant; double difference = difference_new - difference_old; p->start = p->start + difference; p->curr_unit_time = *p->unit_time; } - if (csound->kcounter * csound->onedkr + if (CS_KCNT * CS_ONEDKR > p->newtime * *p->unit_time + p->start) { float curr_val = p->table[p->ndx]; p->newtime += p->table[p->ndx]; @@ -248,15 +248,15 @@ } return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("seqtim: incorrect table number")); } #define S(x) sizeof(x) static OENTRY localops[] = { -{ "seqtime", S(SEQTIM), TR|3, "k", "kkkkk", (SUBR)seqtim_set, (SUBR)seqtim }, -{ "seqtime2", S(SEQTIM2),TR|3, "k", "kkkkkk", (SUBR)seqtim2_set, (SUBR)seqtim2} +{ "seqtime", S(SEQTIM), TR, 3, "k", "kkkkk", (SUBR)seqtim_set, (SUBR)seqtim }, +{ "seqtime2", S(SEQTIM2),TR, 3, "k", "kkkkkk", (SUBR)seqtim2_set, (SUBR)seqtim2} }; int seqtime_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/serial.c csound-6.02~dfsg/Opcodes/serial.c --- csound-5.17.11~dfsg/Opcodes/serial.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/serial.c 2014-01-07 16:53:48.000000000 +0000 @@ -1,13 +1,14 @@ /***************************************************** - - CSOUND SERIAL PORT OPCODES - ma++ ingalls, 2011/9/4 +251 + + CSOUND SERIAL PORT OPCODES + ma++ ingalls, 2011/9/4 modified for WIndows John ffitch * based on "Arduino-serial" * Copyright (c) 2006, Tod E. Kurt, tod@todbot.com * http://todbot.com/blog/ - Copyright (C) 2011 matt ingalls + Copyright (C) 2011 matt ingalls based on "Arduino-serial", Copyright (c) 2006, Tod E. Kurt, tod@todbot.com http://todbot.com/blog/ and licenced LGPL to csound @@ -28,8 +29,8 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include + +#include #include /* Standard types */ #include /* String function definitions */ @@ -53,44 +54,44 @@ /***************************************************** open a port. baudRate defaults to 9600 - iPort serialBegin SPortName [, baudRate ] - + iPort serialBegin SPortName [, baudRate ] + close a port - serialEnd iPort + serialEnd iPort write byte(s) to the port, at i or k rate - serialWrite_i iPort, iByte - serialWrite_i iPort, kByte - serialWrite_i iPort, Sbytes - serialWrite iPort, iByte - serialWrite iPort, kByte - serialWrite iPort, Sbytes + serialWrite_i iPort, iByte + serialWrite_i iPort, kByte + serialWrite_i iPort, Sbytes + serialWrite iPort, iByte + serialWrite iPort, kByte + serialWrite iPort, Sbytes read the next byte from the input buffer returned value will be in the range of 0-255 - kByte serialRead iPort - + kByte serialRead iPort + print to screen any bytes (up to 32k) in input buffer note that these bytes will be cleared from the buffer. use this opcode mainly for debugging messages. -if you want to mix debugging and other communication +if you want to mix debugging and other communication messages over the same port, you will need to manually parse the data with the serialRead opcode. - serialPrint iPort - + serialPrint iPort + clear the input buffer - serialFlush iPort + serialFlush iPort + - TODO: (might need some kind of threaded buffer-read?) - + kNum serialAvailable iPort returns number of bytes available to read - + kByte serialPeekByte iPort returns the next byte in the input buffer does not remove the byte from the buffer - + *****************************************************/ #ifdef WIN32 @@ -107,17 +108,19 @@ q = (SERIAL_GLOBALS*) csound->QueryGlobalVariable(csound, "serialGlobals_"); if (q == NULL) { - csound->PerfError(csound, Str("No ports available")); + csound->ErrorMsg(csound, Str("No ports available")); return NULL; } - hport = (HANDLE)q->handles[port]; + hport = (HANDLE)q->handles[port]; return hport; } #endif typedef struct { OPDS h; - MYFLT *returnedPort, *portName, *baudRate; + MYFLT *returnedPort; + STRINGDAT *portName; + MYFLT *baudRate; } SERIALBEGIN; int serialBegin(CSOUND *csound, SERIALBEGIN *p); @@ -177,16 +180,16 @@ int fd; speed_t brate; - csound = NULL; /* Not used */ + //csound = NULL; /* Not used */ fprintf(stderr,"init_serialport: opening port %s @ %d bps\n", serialport,baud); - + fd = open(serialport, O_RDWR | O_NOCTTY | O_NDELAY); if (fd == -1) { perror("init_serialport: Unable to open port "); return -1; } - + if (tcgetattr(fd, &toptions) < 0) { perror("init_serialport: Couldn't get term attributes"); return -1; @@ -208,7 +211,7 @@ } cfsetispeed(&toptions, brate); cfsetospeed(&toptions, brate); - + // 8N1 toptions.c_cflag &= ~PARENB; toptions.c_cflag &= ~CSTOPB; @@ -216,22 +219,22 @@ toptions.c_cflag |= CS8; // no flow control toptions.c_cflag &= ~CRTSCTS; - + toptions.c_cflag |= CREAD | CLOCAL; // turn on READ & ignore ctrl lines toptions.c_iflag &= ~(IXON | IXOFF | IXANY); // turn off s/w flow ctrl - + toptions.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG); // make raw toptions.c_oflag &= ~OPOST; // make raw - + // see: http://unixwiz.net/techtips/termios-vmin-vtime.html toptions.c_cc[VMIN] = 0; toptions.c_cc[VTIME] = 20; - + if ( tcsetattr(fd, TCSANOW, &toptions) < 0) { perror("init_serialport: Couldn't set term attributes"); return -1; } - + return fd; } #else @@ -247,8 +250,10 @@ "serialGlobals_"); if (q == NULL) { if (csound->CreateGlobalVariable(csound, "serialGlobals_", - sizeof(SERIAL_GLOBALS)) != 0) - csound->Die(csound, Str("serial: failed to allocate globals")); + sizeof(SERIAL_GLOBALS)) != 0){ + csound->ErrorMsg(csound, Str("serial: failed to allocate globals")); + return 0; + } q = (SERIAL_GLOBALS*) csound->QueryGlobalVariable(csound, "serialGlobals_"); q->csound = csound; @@ -260,7 +265,7 @@ /* (LPCSTR)wport, 256); */ /* hSerial = CreateFile(serialport, GENERIC_READ | GENERIC_WRITE, 0, */ /* 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); */ - hSerial = CreateFileA(serialport, GENERIC_READ | GENERIC_WRITE, 0, + hSerial = CreateFileA(serialport, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); //Check if the connection was successfull if (hSerial==INVALID_HANDLE_VALUE) { @@ -326,7 +331,7 @@ int serialBegin(CSOUND *csound, SERIALBEGIN *p) { *p->returnedPort = - (MYFLT)serialport_init(csound, (char *)p->portName, *p->baudRate); + (MYFLT)serialport_init(csound, (char *)p->portName->data, *p->baudRate); return OK; } @@ -336,7 +341,7 @@ SERIAL_GLOBALS *q; q = (SERIAL_GLOBALS*) csound->QueryGlobalVariable(csound, "serialGlobals_"); - if (q = NULL) + if (q = NULL) return csound->PerfError(csound, Str("Nothing to close")); CloseHandle((HANDLE)q->handles[(int)p->port]); q->handles[(int)*p->port] = NULL; @@ -350,47 +355,57 @@ { #ifdef WIN32 HANDLE port = get_port(csound, (int)*p->port); - if (port==NULL) return NOTOK; -#endif - if (p->XSTRCODE & 2) { + if (port==NULL) return NOTOK; +#endif + { + unsigned char b = *p->toWrite; #ifndef WIN32 - if (UNLIKELY(write((int)*p->port, p->toWrite, strlen((char *)p->toWrite))<0)) + if (UNLIKELY(write((int)*p->port, &b, 1)<0)) return NOTOK; #else int nbytes; - WriteFile(port,p->toWrite, strlen((char *)p->toWrite), - (PDWORD)&nbytes, NULL); + WriteFile(port, &b, 1, (PDWORD)&nbytes, NULL); #endif } - else { - unsigned char b = *p->toWrite; + return OK; +} + +int serialWrite_S(CSOUND *csound, SERIALWRITE *p) +{ +#ifdef WIN32 + HANDLE port = get_port(csound, (int)*p->port); + if (port==NULL) return NOTOK; +#endif #ifndef WIN32 - if (UNLIKELY(write((int)*p->port, &b, 1)<0)) + if (UNLIKELY(write((int)*p->port, + ((STRINGDAT*)p->toWrite)->data, + ((STRINGDAT*)p->toWrite)->size))<0) return NOTOK; #else int nbytes; - WriteFile(port, &b, 1, (PDWORD)&nbytes, NULL); + WriteFile(port,p->toWrite, strlen((char *)p->toWrite), + (PDWORD)&nbytes, NULL); #endif - } return OK; } + int serialRead(CSOUND *csound, SERIALREAD *p) { unsigned char b = 0; ssize_t bytes; #ifdef WIN32 HANDLE port = get_port(csound, (int)*p->port); - if (port==NULL) return NOTOK; + if (port==NULL) return NOTOK; ReadFile(port, &b, 1, (PDWORD)&bytes, NULL); #else bytes = read((int)*p->port, &b, 1); #endif if (bytes > 0) *p->rChar = b; - else + else *p->rChar = -1; - + return OK; } @@ -400,14 +415,14 @@ ssize_t bytes; #ifdef WIN32 HANDLE port = get_port(csound, (int)*p->port); - if (port==NULL) return NOTOK; + if (port==NULL) return NOTOK; ReadFile(port, str, 32768, (PDWORD)&bytes, NULL); #else bytes = read((int)*p->port, str, 32768); #endif if (bytes > 0) { str[bytes] = 0; // terminate - csound->MessageS(csound, CSOUNDMSG_ORCH, "%s", str); + csound->MessageS(csound, CSOUNDMSG_ORCH, str); } return OK; } @@ -436,24 +451,28 @@ #define S(x) sizeof(x) static OENTRY serial_localops[] = { - { (char *)"serialBegin", S(SERIALBEGIN), 1, (char *)"i", (char *)"So", + { (char *)"serialBegin", S(SERIALBEGIN), 0, 1, (char *)"i", (char *)"So", (SUBR)serialBegin, (SUBR)NULL, (SUBR)NULL }, - { (char *)"serialEnd", S(SERIALEND), 2, (char *)"", (char *)"i", + { (char *)"serialEnd", S(SERIALEND), 0, 2, (char *)"", (char *)"i", (SUBR)NULL, (SUBR)serialEnd, (SUBR)NULL }, - { (char *)"serialWrite_i", S(SERIALWRITE), 1, (char *)"", (char *)"iT", + { (char *)"serialWrite_i", S(SERIALWRITE), 0, 1, (char *)"", (char *)"ii", (SUBR)serialWrite, (SUBR)NULL, (SUBR)NULL }, - { (char *)"serialWrite", S(SERIALWRITE), 2, (char *)"", (char *)"iU", + { (char *)"serialWrite_i.S", S(SERIALWRITE), 0, 1, (char *)"", (char *)"iS", + (SUBR)serialWrite_S, (SUBR)NULL, (SUBR)NULL }, + { (char *)"serialWrite", S(SERIALWRITE), WR, 2, (char *)"", (char *)"ik", (SUBR)NULL, (SUBR)serialWrite, (SUBR)NULL }, - { (char *)"serialRead", S(SERIALREAD), 2, (char *)"k", (char *)"i", + { (char *)"serialWrite.S", S(SERIALWRITE), WR, 2, (char *)"", (char *)"iS", + (SUBR)NULL, (SUBR)serialWrite_S, (SUBR)NULL }, + { (char *)"serialRead", S(SERIALREAD), 0, 2, (char *)"k", (char *)"i", (SUBR)NULL, (SUBR)serialRead, (SUBR)NULL }, - { (char *)"serialPrint", S(SERIALPRINT), 2, (char *)"", (char *)"i", + { (char *)"serialPrint", S(SERIALPRINT), WR,2, (char *)"", (char *)"i", (SUBR)NULL, (SUBR)serialPrint, (SUBR)NULL }, - { (char *)"serialFlush", S(SERIALFLUSH), 2, (char *)"", (char *)"i", + { (char *)"serialFlush", S(SERIALFLUSH), 0, 2, (char *)"", (char *)"i", (SUBR)NULL, (SUBR)serialFlush, (SUBR)NULL }, - /* { (char *)"serialAvailable", S(SERIALAVAIL), 2, (char *)"k", (char *)"i", */ - /* (SUBR)NULL, (SUBR)serialAvailable, (SUBR)NULL }, */ - /* { (char *)"serialPeekByte", S(SERIALPEEK), 2, (char *)"k", (char *)"i", */ - /* (SUBR)NULL, (SUBR)serialPeekByte, (SUBR)NULL } */ +/* { (char *)"serialAvailable", S(SERIALAVAIL), 0, 2, (char *)"k", (char *)"i", */ +/* (SUBR)NULL, (SUBR)serialAvailable, (SUBR)NULL }, */ +/* { (char *)"serialPeekByte", S(SERIALPEEK),0, 2, (char *)"k", (char *)"i", */ +/* (SUBR)NULL, (SUBR)serialPeekByte, (SUBR)NULL } */ }; -LINKAGE1(serial_localops) +LINKAGE_BUILTIN(serial_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/sf.h csound-6.02~dfsg/Opcodes/sf.h --- csound-5.17.11~dfsg/Opcodes/sf.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sf.h 2014-01-07 16:53:48.000000000 +0000 @@ -33,10 +33,6 @@ #ifdef MSVC # pragma pack(push, before, 1) #endif -#if defined(mac_classic) -# pragma pack(1) -# define PACKED -#endif struct _splitType { int num; diff -Nru csound-5.17.11~dfsg/Opcodes/sfont.c csound-6.02~dfsg/Opcodes/sfont.c --- csound-5.17.11~dfsg/Opcodes/sfont.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sfont.c 2014-01-07 16:54:20.000000000 +0000 @@ -51,7 +51,7 @@ static void splitDefaults(splitType *split); #define MAX_SFONT (10) -#define MAX_SFPRESET (512) +#define MAX_SFPRESET (16384) #define GLOBAL_ATTENUATION (FL(0.3)) #define ONETWELTH (0.08333333333333333333333333333) @@ -62,8 +62,8 @@ SFBANK *sfArray; int currSFndx; int maxSFndx; - presetType *presetp[MAX_SFPRESET]; - SHORT *sampleBase[MAX_SFPRESET]; + presetType **presetp; + SHORT **sampleBase; MYFLT pitches[128]; } sfontg; @@ -92,6 +92,9 @@ } free(sfArray); globals->currSFndx = 0; + csound->Free(csound, globals->presetp); + csound->Free(csound, globals->sampleBase); + csound->DestroyGlobalVariable(csound, "::sfontg"); return 0; } @@ -104,26 +107,19 @@ sfontg *globals; globals = (sfontg *) (csound->QueryGlobalVariable(csound, "::sfontg")); soundFont = globals->soundFont; - /* - if (csound->oparms->msglevel & 0x400) - csound->Message(csound, "\n" - "******************************************\n" - "** Csound SoundFont2 support ver. 1.2 **\n" - "** by Gabriel Maldonado **\n" - "** g.maldonado@agora.stm.it **\n" - "** http://web.tiscalinet.it/G-Maldonado **\n" - "******************************************\n\n"); - */ fd = csound->FileOpen2(csound, &fil, CSFILE_STD, fname, "rb", "SFDIR;SSDIR", CSFTYPE_SOUNDFONT, 0); if (UNLIKELY(fd == NULL)) { - csound->Die(csound, + csound->ErrorMsg(csound, Str("sfload: cannot open SoundFont file \"%s\" (error %s)"), fname, strerror(errno)); + return; } soundFont = &globals->sfArray[globals->currSFndx]; - if (UNLIKELY(soundFont==NULL)) - csound->Die(csound, Str("Sfload: cannot use globals")); + if (UNLIKELY(soundFont==NULL)){ + csound->ErrorMsg(csound, Str("Sfload: cannot use globals")); + return; + } strcpy(soundFont->name, csound->GetFileName(fd)); chunk_read(fil, &soundFont->chunk.main_chunk); csound->FileClose(csound, fd); @@ -146,7 +142,8 @@ static char *Gfname; -static int SfLoad(CSOUND *csound, SFLOAD *p) /* open a file and return its handle */ +static int SfLoad_(CSOUND *csound, SFLOAD *p, int istring) + /* open a file and return its handle */ { /* the handle is simply a stack index */ char *fname; SFBANK *sf; @@ -155,9 +152,14 @@ if (UNLIKELY(globals==NULL)) { return csound->InitError(csound, Str("sfload: could not open globals\n")); } - fname = csound->strarg2name(csound, + if(istring) fname = csound->Strdup(csound, ((STRINGDAT *)p->fname)->data); + else { + if(ISSTRCOD(*p->fname)) + fname = csound->Strdup(csound, get_arg_string(csound,*p->fname)); + else fname = csound->strarg2name(csound, NULL, p->fname, "sfont.", - (int) csound->GetInputArgSMask(p)); + 0); + } /* strcpy(fname, (char*) p->fname); */ Gfname = fname; SoundFontLoad(csound, fname); @@ -175,6 +177,14 @@ return OK; } +static int SfLoad(CSOUND *csound, SFLOAD *p){ + return SfLoad_(csound,p,0); +} + +static int SfLoad_S(CSOUND *csound, SFLOAD *p){ + return SfLoad_(csound,p,1); +} + static char *filter_string(char *s, char temp_string[24]) { int i=0, j=0; @@ -268,8 +278,9 @@ sf = &globals->sfArray[(DWORD) *p->isfhandle]; if (presetHandle >= MAX_SFPRESET) { - csound->Die(csound, Str("sfpreset: preset handle too big (%d), max: %d"), - presetHandle, (int) MAX_SFPRESET - 1); + return csound->InitError(csound, + Str("sfpreset: preset handle too big (%d), max: %d"), + presetHandle, (int) MAX_SFPRESET - 1); } for (j=0; j< sf->presets_num; j++) { @@ -284,11 +295,12 @@ *p->ipresethandle = (MYFLT) presetHandle; if (UNLIKELY(globals->presetp[presetHandle] == NULL)) { - csound->Die(csound, Str("sfpreset: cannot find any preset having prog " - "number %d and bank number %d in SoundFont file " - "\"%s\""), - (int) *p->iprog, (int) *p->ibank, - globals->sfArray[(DWORD) *p->isfhandle].name); + return csound->InitError(csound, + Str("sfpreset: cannot find any preset having prog " + "number %d and bank number %d in SoundFont file" + " \"%s\""), + (int) *p->iprog, (int) *p->ibank, + globals->sfArray[(DWORD) *p->isfhandle].name); } return OK; } @@ -362,21 +374,23 @@ p->leftlevel[spltNum] = (MYFLT) sqrt(1.0-pan) * attenuation; p->rightlevel[spltNum] = (MYFLT) sqrt(pan) * attenuation; p->mode[spltNum]= split->sampleModes; - p->attack[spltNum] = split->attack*csound->ekr; - p->decay[spltNum] = split->decay*csound->ekr; + p->attack[spltNum] = split->attack*CS_EKR; + p->decay[spltNum] = split->decay*CS_EKR; p->sustain[spltNum] = split->sustain; - p->release[spltNum] = split->release*csound->ekr; + p->release[spltNum] = split->release*CS_EKR; if (*p->ienv > 1) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); p->decr[spltNum] = pow((split->sustain+0.0001), - 1.0/(csound->ekr*split->decay+0.0001)); + 1.0/(CS_EKR* + split->decay+0.0001)); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } else if (*p->ienv > 0) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); - p->decr[spltNum] = (split->sustain-1.0)/(csound->ekr*split->decay); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); + p->decr[spltNum] = (split->sustain-1.0)/(CS_EKR* + split->decay); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } @@ -448,11 +462,14 @@ static int SfPlay(CSOUND *csound, SFPLAY *p) { - MYFLT *out1 = p->out1, *out2 = p->out2, *env = p->env; - int n, nsmps = csound->ksmps, j = p->spltNum, arate; + MYFLT *out1 = p->out1, *out2 = p->out2, *env = p->env; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; DWORD *end = p->end, *startloop= p->startloop, *endloop= p->endloop, - *tinc = p->ti; + *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *left= p->leftlevel, *right= p->rightlevel, *attack = p->attack, @@ -463,6 +480,7 @@ arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); memset(out2, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -473,7 +491,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nout1, *out2 = p->out2, *env = p->env; - int n, nsmps = csound->ksmps, j = p->spltNum, arate; + MYFLT *out1 = p->out1, *out2 = p->out2, *env = p->env; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; DWORD *end = p->end, *startloop = p->startloop, - *endloop = p->endloop, *tinc = p->ti; + *endloop = p->endloop, *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *left= p->leftlevel, *right= p->rightlevel, *attack = p->attack, - *decr = p->decr, *decay = p->decay, *sustain= p->sustain, - *release = p->release, *attr = p->attr; + *decr = p->decr, *decay = p->decay, *sustain= p->sustain, + *release = p->release, *attr = p->attr; arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); memset(out2, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { double looplength = *endloop - *startloop; MYFLT *freq = p->xfreq; -/* nsmps = csound->ksmps; */ +/* nsmps = CS_KSMPS; */ if (*mode == 1 || *mode ==3) { int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nstartLoopOffset - start; p->endloop[spltNum] = sample->dwEndloop + split->endLoopOffset - start; p->mode[spltNum]= split->sampleModes; - p->attack[spltNum] = split->attack*csound->ekr; - p->decay[spltNum] = split->decay*csound->ekr; + p->attack[spltNum] = split->attack*CS_EKR; + p->decay[spltNum] = split->decay*CS_EKR; p->sustain[spltNum] = split->sustain; - p->release[spltNum] = split->release*csound->ekr; + p->release[spltNum] = split->release*CS_EKR; if (*p->ienv > 1) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); p->decr[spltNum] = pow((split->sustain+0.0001), - 1.0/(csound->ekr*split->decay+0.0001)); + 1.0/(CS_EKR* + split->decay+0.0001)); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } else if (*p->ienv > 0) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); - p->decr[spltNum] = (split->sustain-1.0)/(csound->ekr*split->decay); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); + p->decr[spltNum] = (split->sustain-1.0)/(CS_EKR* + split->decay); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } @@ -713,20 +737,24 @@ static int SfPlayMono(CSOUND *csound, SFPLAYMONO *p) { - MYFLT *out1 = p->out1 , *env = p->env; - int n, nsmps = csound->ksmps, j = p->spltNum, arate; + MYFLT *out1 = p->out1 , *env = p->env; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; DWORD *end= p->end, *startloop= p->startloop, *endloop= p->endloop, - *tinc = p->ti; + *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *attenuation = p->attenuation, *attack = p->attack, *decr = p->decr, - *decay = p->decay, *sustain= p->sustain, *release = p->release, - *attr = p->attr; + *decay = p->decay, *sustain= p->sustain, *release = p->release, + *attr = p->attr; arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -735,7 +763,7 @@ if (*mode == 1 || *mode ==3) { int flag =0; - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } @@ -743,7 +771,7 @@ } } else if (*phs < *end) { - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } @@ -762,14 +790,14 @@ double si = *sampinc * freq; if (*mode == 1 || *mode ==3) { int flag =0; - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } { Linear_interpolation Mono_out Looped } } } else if (*phs < *end) { - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } { Linear_interpolation Mono_out Unlooped } @@ -782,13 +810,13 @@ } if (arate) { MYFLT *amp = p->xamp; - for (n=0;nxamp; - for (n=0;nout1, *env = p->env; - int n, nsmps = csound->ksmps, j = p->spltNum, arate; - SHORT **base = p->base; - DWORD *end = p->end, *startloop = p->startloop, - *endloop = p->endloop, *tinc = p->ti; - SHORT *mode = p->mode; + MYFLT *out1 = p->out1, *env = p->env; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; + SHORT **base = p->base; + DWORD *end = p->end, *startloop = p->startloop, + *endloop = p->endloop, *tinc = p->ti; + SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *attenuation = p->attenuation,*attack = p->attack, *decr = p->decr, - *decay = p->decay, *sustain= p->sustain, *release = p->release, - *attr = p->attr; + *decay = p->decay, *sustain= p->sustain, *release = p->release, + *attr = p->attr; arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); - + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { double looplength = *endloop - *startloop; @@ -821,7 +852,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nrightlevel[spltNum] = pan * attenuation; p->mode[spltNum]= split->sampleModes; - p->attack[spltNum] = split->attack*csound->ekr; - p->decay[spltNum] = split->decay*csound->ekr; + p->attack[spltNum] = split->attack*CS_EKR; + p->decay[spltNum] = split->decay*CS_EKR; p->sustain[spltNum] = split->sustain; - p->release[spltNum] = split->release*csound->ekr; + p->release[spltNum] = split->release*CS_EKR; if (*p->ienv > 1) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); p->decr[spltNum] = pow((split->sustain+0.0001), - 1.0/(csound->ekr*split->decay+0.0001)); + 1.0/(CS_EKR*split->decay+0.0001)); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } else if (*p->ienv > 0) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); - p->decr[spltNum] = (split->sustain-1.0)/(csound->ekr*split->decay); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); + p->decr[spltNum] = (split->sustain-1.0)/(CS_EKR* + split->decay); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } @@ -969,20 +1001,24 @@ static int SfInstrPlay(CSOUND *csound, SFIPLAY *p) { MYFLT *out1= p->out1, *out2= p->out2, *env = p->env; - int n, nsmps= csound->ksmps, j = p->spltNum, arate; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; DWORD *end= p->end, *startloop= p->startloop, - *endloop= p->endloop, *tinc = p->ti; + *endloop= p->endloop, *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *left= p->leftlevel, *right= p->rightlevel, *attack = p->attack, - *decr = p->decr, *decay = p->decay, *sustain= p->sustain, - *release = p->release, *attr = p->attr; + *decr = p->decr, *decay = p->decay, *sustain= p->sustain, + *release = p->release, *attr = p->attr; arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); memset(out2, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -993,7 +1029,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nout1, *out2= p->out2,*env =p->env; - int n, nsmps= csound->ksmps, j = p->spltNum, arate; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; - DWORD *end= p->end, *startloop= p->startloop, *endloop= p->endloop, *tinc = p->ti; + DWORD *end= p->end, *startloop= p->startloop, + *endloop= p->endloop, *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *left= p->leftlevel, *right= p->rightlevel, @@ -1071,6 +1111,7 @@ memset(out1, 0, nsmps*sizeof(MYFLT)); memset(out2, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -1081,7 +1122,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nstartLoopOffset - start; p->endloop[spltNum] = sample->dwEndloop + split->endLoopOffset - start; p->mode[spltNum]= split->sampleModes; - p->attack[spltNum] = split->attack*csound->ekr; - p->decay[spltNum] = split->decay*csound->ekr; + p->attack[spltNum] = split->attack*CS_EKR; + p->decay[spltNum] = split->decay*CS_EKR; p->sustain[spltNum] = split->sustain; - p->release[spltNum] = split->release*csound->ekr; + p->release[spltNum] = split->release*CS_EKR; if (*p->ienv > 1) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); p->decr[spltNum] = pow((split->sustain+0.0001), - 1.0/(csound->ekr*split->decay+0.0001)); + 1.0/(CS_EKR* + split->decay+0.0001)); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } else if (*p->ienv > 0) { - p->attr[spltNum] = 1.0/(csound->ekr*split->attack); - p->decr[spltNum] = (split->sustain-1.0)/(csound->ekr*split->decay); + p->attr[spltNum] = 1.0/(CS_EKR*split->attack); + p->decr[spltNum] = (split->sustain-1.0)/(CS_EKR* + split->decay); if (split->attack != 0.0) p->env[spltNum] = 0.0; else p->env[spltNum] = 1.0; } @@ -1224,7 +1267,10 @@ static int SfInstrPlayMono(CSOUND *csound, SFIPLAYMONO *p) { MYFLT *out1= p->out1, *env = p->env; - int n, nsmps= csound->ksmps, j = p->spltNum, arate; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; DWORD *end= p->end, *startloop= p->startloop, *endloop= p->endloop, *tinc = p->ti; @@ -1238,6 +1284,7 @@ arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -1248,7 +1295,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;nout1, *env = p->env ; - int n, nsmps= csound->ksmps, j = p->spltNum, arate; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int j = p->spltNum, arate; SHORT **base = p->base; - DWORD *end= p->end, *startloop= p->startloop, *endloop= p->endloop, *tinc = p->ti; + DWORD *end= p->end, *startloop= p->startloop, + *endloop= p->endloop, *tinc = p->ti; SHORT *mode = p->mode; double *sampinc = p->si, *phs = p->phs; MYFLT *attenuation = p->attenuation,*attack = p->attack, *decr = p->decr, @@ -1321,6 +1372,7 @@ arate = (p->XINCODE) ? 1 : 0; memset(out1, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; if (arate) { while (j--) { @@ -1331,7 +1383,7 @@ int flag =0; if (*p->ienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nienv > 1) { ExpEnvelope } else if (*p->ienv > 0) { LinEnvelope } - for (n=0;nxamp; - for (n=0;nxamp; - for (n=0;n 0) { fmt = fmt_org; while (*fmt) { c = *fmt++; if (isdigit(*fmt)) { - times = strtol(fmt, &fmt, 0); + times = strtol(fmt, &fmt, 10); } else { times = 1; } @@ -1434,9 +1487,6 @@ static void fill_SfStruct(CSOUND *csound) { -#if defined(SYMANTEC) -#pragma options(!global_optimizer) -#endif int j, k, i, l, m, size, iStart, iEnd, kk, ll, mStart, mEnd; int pbag_num,first_pbag,layer_num; int ibag_num,first_ibag,split_num; @@ -1598,12 +1648,13 @@ split->num= num; split->sample = &shdr[num]; if (UNLIKELY(split->sample->sfSampleType & 0x8000)) { - csound->Die(csound, Str("SoundFont file \"%s\" " + csound->ErrorMsg(csound, Str("SoundFont file \"%s\" " "contains ROM samples !\n" "At present time only RAM " "samples are allowed " "by sfload.\n" "Session aborted !"), Gfname); + return; } sglobal_zone = 0; ll++; @@ -1835,11 +1886,12 @@ split->num= num; split->sample = &shdr[num]; if (UNLIKELY(split->sample->sfSampleType & 0x8000)) { - csound->Die(csound, Str("SoundFont file \"%s\" contains " + csound->ErrorMsg(csound, Str("SoundFont file \"%s\" contains " "ROM samples !\n" "At present time only RAM samples " "are allowed by sfload.\n" "Session aborted !"), Gfname); + return; } sglobal_zone = 0; ll++; @@ -1989,16 +2041,21 @@ globals = (sfontg *) (csound->QueryGlobalVariable(csound, "::sfontg")); if (UNLIKELY(globals == NULL)) { - csound->Die(csound, Str("Sfont: cannot use globals/")); + csound->ErrorMsg(csound, Str("Sfont: cannot use globals/")); + return; } soundFont = globals->soundFont; if (LIKELY(soundFont != NULL)) main_chunk=&(soundFont->chunk.main_chunk); - else csound->Die(csound, Str("Sfont: cannot use globals/")); + else { + csound->ErrorMsg(csound, Str("Sfont: cannot use globals/")); + return; + } if (UNLIKELY(main_chunk->ckDATA == NULL)) { - csound->Die(csound, Str("Sfont format not compatible")); + csound->ErrorMsg(csound, Str("Sfont format not compatible")); + return; } chkp = (char *) main_chunk->ckDATA+4; @@ -2030,7 +2087,7 @@ else if (chkid == s2d("sdta")) { j +=4; chkp += 4; smplChunk = (CHUNK *) chkp; - soundFont->sampleData = (SHORT *) &smplChunk->ckDATA; + soundFont->sampleData = (void *) &(smplChunk->ckDATA); ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w", chkp + 8, size - 12); /* #ifdef BETA */ @@ -2059,7 +2116,7 @@ } else if (chkid == s2d("pbag")) { pbagChunk = (CHUNK *) chkp; - soundFont->chunk.pbag= (sfPresetBag *) &pbagChunk->ckDATA; + soundFont->chunk.pbag= (void *) &pbagChunk->ckDATA; ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w2", chkp + 8, pbagChunk->ckSize); chkp += pbagChunk->ckSize+8; @@ -2067,7 +2124,7 @@ } else if (chkid == s2d("pmod")) { pmodChunk = (CHUNK *) chkp; - soundFont->chunk.pmod= (sfModList *) &pmodChunk->ckDATA; + soundFont->chunk.pmod= (void *) &pmodChunk->ckDATA; ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w5", chkp + 8, pmodChunk->ckSize); chkp += pmodChunk->ckSize+8; @@ -2075,7 +2132,7 @@ } else if (chkid == s2d("pgen")) { pgenChunk = (CHUNK *) chkp; - soundFont->chunk.pgen= (sfGenList *) &pgenChunk->ckDATA; + soundFont->chunk.pgen= (void *) &pgenChunk->ckDATA; ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w2", chkp + 8, pgenChunk->ckSize); chkp += pgenChunk->ckSize+8; @@ -2091,7 +2148,7 @@ } else if (chkid == s2d("ibag")) { ibagChunk = (CHUNK *) chkp; - soundFont->chunk.ibag= (sfInstBag *) &ibagChunk->ckDATA; + soundFont->chunk.ibag= (void *) &ibagChunk->ckDATA; ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w2", chkp + 8, ibagChunk->ckSize); chkp += ibagChunk->ckSize+8; @@ -2099,7 +2156,7 @@ } else if (chkid == s2d("imod")) { imodChunk = (CHUNK *) chkp; - soundFont->chunk.imod= (sfInstModList *) &imodChunk->ckDATA; + soundFont->chunk.imod= (void *) &imodChunk->ckDATA; ChangeByteOrder("d", chkp + 4, 4); ChangeByteOrder("w5", chkp + 8, imodChunk->ckSize); chkp += imodChunk->ckSize+8; @@ -2240,7 +2297,7 @@ } } p->spltNum = spltNum; - if (*p->ifn2 != 0) p->efunc = csound->FTFind(csound, p->ifn2); + if (*p->ifn2 != 0) p->efunc = csound->FTnp2Find(csound, p->ifn2); else p->efunc = NULL; if (*p->iskip == 0){ @@ -2248,7 +2305,7 @@ for(j=0; j < spltNum; j++){ if (p->mode == 0 || p->mode == 2){ - if ((p->ndx[j][0] = *p->start*csound->GetSr(csound)+p->sstart[j]) < 0) + if ((p->ndx[j][0] = *p->start*CS_ESR+p->sstart[j]) < 0) p->ndx[j][0] = 0; if (p->ndx[j][0] >= p->end[j]) p->ndx[j][0] = (double) p->end[j] - 1.0; @@ -2263,10 +2320,13 @@ static int sflooper_process(CSOUND *csound, sflooper *p) { - int i,k, n = csound->ksmps; - MYFLT *outL = p->outL, *outR = p->outR, out, sr = csound->GetSr(csound); - MYFLT amp = *(p->amp), pit = *(p->pitch); - SHORT **base = p->sBase, *tab; + int k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + MYFLT *outL = p->outL, *outR = p->outR, out, sr = CS_ESR; + MYFLT amp = *(p->amp), pit = *(p->pitch); + SHORT **base = p->sBase, *tab; double *ndx; MYFLT frac0, frac1, *etab, left, right; int *nend = p->end, *loop_end = p->lend, *loop_start = p->lstart, @@ -2286,8 +2346,9 @@ /* loop parameters & check */ if (pit < FL(0.0)) pit = FL(0.0); - memset(outL, 0, n*sizeof(MYFLT)); - memset(outR, 0, n*sizeof(MYFLT)); + memset(outL, 0, nsmps*sizeof(MYFLT)); + memset(outR, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; for(k=0; k < spltNum; k++){ @@ -2324,7 +2385,7 @@ } *firsttime = 0; } - for (i=0; i < n; i++) { + for (i=offset; i < nsmps; i++) { if (mode == 1){ /* backwards */ tndx0 = (int) ndx[0]; frac0 = ndx[0] - tndx0; @@ -2501,30 +2562,31 @@ #define S sizeof static OENTRY localops[] = { -{ "sfload",S(SFLOAD), 1, "i", "T", (SUBR)SfLoad, NULL, NULL }, -{ "sfpreset",S(SFPRESET), 1, "i", "iiii", (SUBR)SfPreset }, -{ "sfplay", S(SFPLAY), 5, "aa", "iixxiooo", (SUBR)SfPlay_set, - NULL, (SUBR)SfPlay }, -{ "sfplaym", S(SFPLAYMONO), 5, "a", "iixxiooo", (SUBR)SfPlayMono_set, - NULL, (SUBR)SfPlayMono }, -{ "sfplist",S(SFPLIST), 1, "", "i", (SUBR)Sfplist }, -{ "sfilist",S(SFPLIST), 1, "", "i", (SUBR)Sfilist }, -{ "sfpassign",S(SFPASSIGN), 1, "", "iip", (SUBR)SfAssignAllPresets }, -{ "sfinstrm", S(SFIPLAYMONO),5, "a", "iixxiiooo", (SUBR)SfInstrPlayMono_set, + { "sfload",S(SFLOAD), 0, 1, "i", "S", (SUBR)SfLoad_S, NULL, NULL }, + { "sfload.i",S(SFLOAD), 0, 1, "i", "i", (SUBR)SfLoad, NULL, NULL }, + { "sfpreset",S(SFPRESET), 0, 1, "i", "iiii", (SUBR)SfPreset }, + { "sfplay", S(SFPLAY), 0, 5, "aa", "iixxiooo", (SUBR)SfPlay_set, + NULL, (SUBR)SfPlay }, + { "sfplaym", S(SFPLAYMONO), 0, 5, "a", "iixxiooo", (SUBR)SfPlayMono_set, + NULL, (SUBR)SfPlayMono }, + { "sfplist",S(SFPLIST), 0, 1, "", "i", (SUBR)Sfplist }, + { "sfilist",S(SFPLIST), 0, 1, "", "i", (SUBR)Sfilist }, + { "sfpassign",S(SFPASSIGN), 0, 1, "", "iip", (SUBR)SfAssignAllPresets }, + { "sfinstrm", S(SFIPLAYMONO),0, 5, "a", "iixxiiooo", (SUBR)SfInstrPlayMono_set, NULL, (SUBR)SfInstrPlayMono }, -{ "sfinstr", S(SFIPLAY), 5, "aa", "iixxiiooo", (SUBR)SfInstrPlay_set, - NULL,(SUBR)SfInstrPlay }, -{ "sfplay3", S(SFPLAY), 5, "aa", "iixxiooo", (SUBR)SfPlay_set, - NULL, (SUBR)SfPlay3 }, -{ "sfplay3m", S(SFPLAYMONO), 5, "a", "iixxiooo", (SUBR)SfPlayMono_set, - NULL,(SUBR)SfPlayMono3 }, -{ "sfinstr3", S(SFIPLAY), 5, "aa", "iixxiiooo", (SUBR)SfInstrPlay_set, - NULL, (SUBR)SfInstrPlay3 }, -{ "sfinstr3m", S(SFIPLAYMONO), 5, "a", "iixxiiooo",(SUBR)SfInstrPlayMono_set, - NULL, (SUBR)SfInstrPlayMono3 }, -{ "sflooper", S(sflooper), 5, "aa", "iikkikkkoooo", (SUBR)sflooper_init, - NULL, (SUBR)sflooper_process }, -{ NULL, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } + { "sfinstr", S(SFIPLAY), 0, 5, "aa", "iixxiiooo", (SUBR)SfInstrPlay_set, + NULL,(SUBR)SfInstrPlay }, + { "sfplay3", S(SFPLAY), 0, 5, "aa", "iixxiooo", (SUBR)SfPlay_set, + NULL, (SUBR)SfPlay3 }, + { "sfplay3m", S(SFPLAYMONO), 0, 5, "a", "iixxiooo", (SUBR)SfPlayMono_set, + NULL,(SUBR)SfPlayMono3 }, + { "sfinstr3", S(SFIPLAY), 0, 5, "aa", "iixxiiooo", (SUBR)SfInstrPlay_set, + NULL, (SUBR)SfInstrPlay3 }, + { "sfinstr3m", S(SFIPLAYMONO), 0, 5, "a", "iixxiiooo",(SUBR)SfInstrPlayMono_set, + NULL, (SUBR)SfInstrPlayMono3 }, + { "sflooper", S(sflooper), 0, 5, "aa", "iikkikkkoooo", (SUBR)sflooper_init, + NULL, (SUBR)sflooper_process }, + { NULL, 0, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } }; int sfont_ModuleCreate(CSOUND *csound) @@ -2538,14 +2600,18 @@ return csound->InitError(csound, Str("error... could not create sfont globals\n")); - globals->sfArray = (SFBANK *)malloc(MAX_SFONT*sizeof(SFBANK)); + globals->sfArray = (SFBANK *) malloc(MAX_SFONT*sizeof(SFBANK)); + globals->presetp = + (presetType **) csound->Malloc(csound, MAX_SFPRESET *sizeof(presetType *)); + globals->sampleBase = + (SHORT **) csound->Malloc(csound, MAX_SFPRESET*sizeof(SHORT *)); globals->currSFndx = 0; globals->maxSFndx = MAX_SFONT; for (j=0; j<128; j++) { - globals->pitches[j] = (MYFLT) (440.0 * pow (2.0,(j - 69.0)/12.0)); + globals->pitches[j] = (MYFLT) (440.0 * pow(2.0, (double)(j- 69)/12.0)); } - return OK; + return OK; } int sfont_ModuleInit(CSOUND *csound) @@ -2555,8 +2621,8 @@ while (ep->opname != NULL) { err |= csound->AppendOpcode(csound, - ep->opname, ep->dsblksiz, ep->thread, - ep->outypes, ep->intypes, + ep->opname, ep->dsblksiz, ep->flags, + ep->thread, ep->outypes, ep->intypes, (int (*)(CSOUND *, void*)) ep->iopadr, (int (*)(CSOUND *, void*)) ep->kopadr, (int (*)(CSOUND *, void*)) ep->aopadr); diff -Nru csound-5.17.11~dfsg/Opcodes/sfont.h csound-6.02~dfsg/Opcodes/sfont.h --- csound-5.17.11~dfsg/Opcodes/sfont.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sfont.h 2014-01-07 16:53:48.000000000 +0000 @@ -54,19 +54,22 @@ SHORT *base[MAXSPLT], mode[MAXSPLT]; DWORD end[MAXSPLT], startloop[MAXSPLT], endloop[MAXSPLT], ti[MAXSPLT]; double si[MAXSPLT],phs[MAXSPLT]; - MYFLT leftlevel[MAXSPLT], rightlevel[MAXSPLT], attack[MAXSPLT], decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; + MYFLT leftlevel[MAXSPLT], rightlevel[MAXSPLT], attack[MAXSPLT], + decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; MYFLT attr[MAXSPLT], decr[MAXSPLT]; MYFLT env[MAXSPLT]; } SFPLAY; typedef struct { OPDS h; - MYFLT *out1, *ivel, *inotnum,*xamp, *xfreq, *ipresethandle, *iflag, *ioffset, *ienv; + MYFLT *out1, *ivel, *inotnum,*xamp, *xfreq, *ipresethandle, + *iflag, *ioffset, *ienv; int spltNum; SHORT *base[MAXSPLT], mode[MAXSPLT]; DWORD end[MAXSPLT], startloop[MAXSPLT], endloop[MAXSPLT], ti[MAXSPLT]; double si[MAXSPLT],phs[MAXSPLT]; - MYFLT attenuation[MAXSPLT],attack[MAXSPLT], decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; + MYFLT attenuation[MAXSPLT],attack[MAXSPLT], decay[MAXSPLT], + sustain[MAXSPLT], release[MAXSPLT]; MYFLT attr[MAXSPLT], decr[MAXSPLT]; MYFLT env[MAXSPLT]; } SFPLAYMONO; @@ -79,7 +82,8 @@ SHORT *base[MAXSPLT], mode[MAXSPLT]; DWORD end[MAXSPLT], startloop[MAXSPLT], endloop[MAXSPLT], ti[MAXSPLT]; double si[MAXSPLT],phs[MAXSPLT]; - MYFLT attenuation[MAXSPLT],attack[MAXSPLT], decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; + MYFLT attenuation[MAXSPLT],attack[MAXSPLT], decay[MAXSPLT], + sustain[MAXSPLT], release[MAXSPLT]; MYFLT attr[MAXSPLT], decr[MAXSPLT]; MYFLT env[MAXSPLT]; } SFIPLAYMONO; @@ -92,7 +96,8 @@ SHORT *base[MAXSPLT], mode[MAXSPLT]; DWORD end[MAXSPLT], startloop[MAXSPLT], endloop[MAXSPLT], ti[MAXSPLT]; double si[MAXSPLT],phs[MAXSPLT]; - MYFLT leftlevel[MAXSPLT], rightlevel[MAXSPLT],attack[MAXSPLT], decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; + MYFLT leftlevel[MAXSPLT], rightlevel[MAXSPLT],attack[MAXSPLT], + decay[MAXSPLT], sustain[MAXSPLT], release[MAXSPLT]; MYFLT attr[MAXSPLT], decr[MAXSPLT]; MYFLT env[MAXSPLT]; } SFIPLAY; diff -Nru csound-5.17.11~dfsg/Opcodes/sftype.h csound-6.02~dfsg/Opcodes/sftype.h --- csound-5.17.11~dfsg/Opcodes/sftype.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sftype.h 2014-01-07 16:53:48.000000000 +0000 @@ -22,6 +22,7 @@ */ #if !defined(_SFTYPE_H) +#define _SFTYPE_H #ifdef __GNUC__ # ifndef PACKED # define PACKED __attribute__((packed)) @@ -29,21 +30,13 @@ #elif defined MSVC # pragma pack(push, before, 1) # define PACKED -#elif defined(mac_classic) -# pragma pack(1) -# define PACKED -#elif defined(__WATCOMC__) -# include -# define PACKED #else -# error No pack defined +# error "No pack defined." #endif #ifndef WORDS_BIGENDIAN # if defined(__POWERPC__) || defined(__PPC__) || defined(__ppc__) # define WORDS_BIGENDIAN 1 -# elif defined(mac_classic) -# define WORDS_BIGENDIAN 1 # endif #endif @@ -226,14 +219,8 @@ WORD sfSampleType; } PACKED sfSample; -#define _SFTYPE_H #ifdef MSVC # pragma pack(pop, before) #endif -#if defined(mac_classic) -# pragma pack(0) -#elif defined(__WATCOMC__) -#include -#endif #endif diff -Nru csound-5.17.11~dfsg/Opcodes/shaker.c csound-6.02~dfsg/Opcodes/shaker.c --- csound-5.17.11~dfsg/Opcodes/shaker.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/shaker.c 2014-01-07 16:53:48.000000000 +0000 @@ -78,8 +78,8 @@ p->gain_norm = FL(0.0005); p->shake_num = (int)*p->times; ADSR_keyOn(&p->envelope); - p->kloop = (int)(p->h.insdshead->offtim * csound->ekr) - - (int)(csound->ekr * *p->dettack); + p->kloop = (int)(p->h.insdshead->offtim * CS_EKR) + - (int)(CS_EKR * *p->dettack); p->freq = -FL(1.0); /* So will get changed */ return OK; } @@ -87,7 +87,9 @@ int shaker(CSOUND *csound, SHAKER *p) { MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = (*p->amp)*AMP_RSCALE; /* Normalise */ MYFLT shake = amp + amp; MYFLT damp = *p->shake_damp; @@ -111,8 +113,13 @@ if ((--p->kloop) == 0) { p->shake_num = 0; } + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } gain *= p->num_beans; /* Save work in loop */ - for (n=0; nmaxamplitude = *data->ifullscale; - if (UNLIKELY(data->maxamplitude<= 0.0)) + p->maxamplitude = *p->ifullscale; + if (UNLIKELY(p->maxamplitude<= 0.0)) return csound->InitError(csound, Str("powershape: ifullscale must be strictly positive")); - data->one_over_maxamp = FL(1.0) / data->maxamplitude; + p->one_over_maxamp = FL(1.0) / p->maxamplitude; return OK; } -static int PowerShape(CSOUND* csound, POWER_SHAPE* data) +static int PowerShape(CSOUND* csound, POWER_SHAPE* p) { MYFLT cur, amt, maxampl, invmaxampl; - int n, nsmps = csound->ksmps; - MYFLT* out = data->aout; - MYFLT* in = data->ain; - - amt = *(data->kshapeamount); - invmaxampl = data->one_over_maxamp; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT* out = p->aout; + MYFLT* in = p->ain; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + amt = *(p->kshapeamount); + invmaxampl = p->one_over_maxamp; if (amt == FL(0.0)) { /* treat zero-power with care */ - for (n=0; nmaxamplitude; - for (n=0; nmaxamplitude; + for (n=offset; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int ncoeff = /* index of the last coefficient */ - csound->GetInputArgCnt(data) - 2; - MYFLT *out = data->aout; - MYFLT *in = data->ain; - MYFLT **coeff = data->kcoefficients; + csound->GetInputArgCnt(p) - 2; + MYFLT *out = p->aout; + MYFLT *in = p->ain; + MYFLT **coeff = p->kcoefficients; MYFLT sum, x; - for (n=0; n= 0; --i) { @@ -122,15 +138,15 @@ AUXCH coeff; } CHEBPOLY; -static int ChebyshevPolyInit(CSOUND* csound, CHEBPOLY* data) +static int ChebyshevPolyInit(CSOUND* csound, CHEBPOLY* p) { - int ncoeff = csound->GetInputArgCnt(data) - 1; + int ncoeff = csound->GetInputArgCnt(p) - 1; /* Need two MYFLT arrays of length ncoeff: first for the coefficients of the sum of polynomials, and the second for the coefficients of the individual chebyshev polynomials as we are adding them up. */ - csound->AuxAlloc(csound, (2*ncoeff + 1)*sizeof(MYFLT), &(data->coeff)); - data->chebn = ((MYFLT*)data->coeff.auxp) + ncoeff; + csound->AuxAlloc(csound, (2*ncoeff + 1)*sizeof(MYFLT), &(p->coeff)); + p->chebn = ((MYFLT*)p->coeff.auxp) + ncoeff; return OK; } @@ -138,17 +154,19 @@ Coefficients (k0, k1, k2, ... ) are k-rate multipliers of each Chebyshev polynomial starting with the zero-order polynomial T0(x) = 1, then T1(x) = x, T2(x) = 2x^2 - 1, etc. */ -static int ChebyshevPolynomial(CSOUND* csound, CHEBPOLY* data) +static int ChebyshevPolynomial(CSOUND* csound, CHEBPOLY* p) { int i, j; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int ncoeff = /* index of the last coefficient */ - csound->GetInputArgCnt(data) - 2; - MYFLT *out = data->aout; - MYFLT *in = data->ain; - MYFLT **chebcoeff = data->kcoefficients; - MYFLT *chebn = data->chebn; - MYFLT *coeff = (MYFLT*)data->coeff.auxp; + csound->GetInputArgCnt(p) - 2; + MYFLT *out = p->aout; + MYFLT *in = p->ain; + MYFLT **chebcoeff = p->kcoefficients; + MYFLT *chebn = p->chebn; + MYFLT *coeff = (MYFLT*)p->coeff.auxp; MYFLT sum, x; /* Every other coefficient in a Cheb. poly. is 0, and @@ -185,7 +203,12 @@ } /* Use our final coeff. to evaluate the poly. for each input sample */ - for (n=0; n= 0 ; --i) { @@ -206,29 +229,32 @@ MYFLT *aout, *ain, *kwidth, *kcenter, *ibipolar, *ifullscale; } PD_CLIP; -static int PDClip(CSOUND* csound, PD_CLIP* data) +static int PDClip(CSOUND* csound, PD_CLIP* p) { MYFLT cur, low, high, maxampl, width, unwidth, center, outscalar; - int bipolarMode, n, nsmps = csound->ksmps; - MYFLT* out = data->aout; - MYFLT* in = data->ain; - - bipolarMode = (int) *(data->ibipolar); - maxampl = *(data->ifullscale); - width = (*(data->kwidth) > FL(1.0) ? FL(1.0) : - (*(data->kwidth) < FL(0.0) ? FL(0.0) : *(data->kwidth))); + int bipolarMode; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT* out = p->aout; + MYFLT* in = p->ain; + + bipolarMode = (int) *(p->ibipolar); + maxampl = *(p->ifullscale); + width = (*(p->kwidth) > FL(1.0) ? FL(1.0) : + (*(p->kwidth) < FL(0.0) ? FL(0.0) : *(p->kwidth))); unwidth = FL(1.0) - width; /* width of 1/2 unclipped region */ if (bipolarMode) { /* the unclipped region can only shift left or right by up to width */ - if (*(data->kcenter) < - width) center = - width * maxampl; - else if (*(data->kcenter) > width) center = width * maxampl; - else center = *(data->kcenter) * maxampl; + if (*(p->kcenter) < - width) center = - width * maxampl; + else if (*(p->kcenter) > width) center = width * maxampl; + else center = *(p->kcenter) * maxampl; } else { width = FL(0.5) * width; /* range reduced by 1/2 in unipolar mode */ unwidth = FL(0.5) * unwidth; - center = *(data->kcenter) * FL(0.5) + FL(0.5); /* make unipolar */ + center = *(p->kcenter) * FL(0.5) + FL(0.5); /* make unipolar */ if (center < (FL(0.5) - width)) center = (FL(0.5) - width) * maxampl; else if (center > (FL(0.5) + width)) center = (FL(0.5) + width) * maxampl; else center = center * maxampl; @@ -236,9 +262,15 @@ low = center - unwidth*maxampl; /* min value of unclipped input */ high = unwidth*maxampl + center; /* max value of unclipped input */ + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + if (bipolarMode) { outscalar = (unwidth == FL(0.0)) ? FL(0.0) : (FL(1.0) / unwidth); - for (n=0; n= high ? maxampl : (outscalar * (cur-center)))); @@ -246,7 +278,7 @@ } else { outscalar = (unwidth == FL(0.0)) ? FL(0.0) : (FL(0.5) / unwidth); - for (n=0; n= high ? maxampl : (outscalar * (cur-low)))); @@ -262,28 +294,35 @@ } PD_HALF; /* Casio-style phase distortion with "pivot point" on the X axis */ -static int PDHalfX(CSOUND* csound, PD_HALF* data) +static int PDHalfX(CSOUND* csound, PD_HALF* p) { MYFLT cur, maxampl, midpoint, leftslope, rightslope; - int n, nsmps = csound->ksmps; - MYFLT* out = data->aout; - MYFLT* in = data->ain; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT* out = p->aout; + MYFLT* in = p->ain; - maxampl = *(data->ifullscale); + maxampl = *(p->ifullscale); if (maxampl == FL(0.0)) maxampl = FL(1.0); - if (*(data->ibipolar) != FL(0.0)) { /* bipolar mode */ + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + if (*(p->ibipolar) != FL(0.0)) { /* bipolar mode */ /* clamp kamount in range [-1,1] */ - midpoint = (*(data->kamount) >= FL(1.0) ? maxampl : - (*(data->kamount) <= FL(-1.0) ? -maxampl : - (*(data->kamount) * maxampl))); + midpoint = (*(p->kamount) >= FL(1.0) ? maxampl : + (*(p->kamount) <= FL(-1.0) ? -maxampl : + (*(p->kamount) * maxampl))); if (midpoint != -maxampl) leftslope = maxampl / (midpoint + maxampl); else leftslope = FL(0.0); if (midpoint != maxampl) rightslope = maxampl / (maxampl - midpoint); else rightslope = FL(0.0); - for (n=0; nkamount) >= FL(1.0) ? maxampl : - (*(data->kamount) <= FL(-1.0) ? FL(0.0) : - ((*(data->kamount) + FL(1.0)) * halfmaxampl))); + midpoint = (*(p->kamount) >= FL(1.0) ? maxampl : + (*(p->kamount) <= FL(-1.0) ? FL(0.0) : + ((*(p->kamount) + FL(1.0)) * halfmaxampl))); if (midpoint != FL(0.0)) leftslope = halfmaxampl / midpoint; else leftslope = FL(0.0); if (midpoint != maxampl) rightslope = halfmaxampl / (maxampl - midpoint); else rightslope = FL(0.0); - for (n=0; nksmps; - MYFLT* out = data->aout; - MYFLT* in = data->ain; - - maxampl = *(data->ifullscale); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT* out = p->aout; + MYFLT* in = p->ain; + + maxampl = *(p->ifullscale); + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (maxampl == FL(0.0)) maxampl = FL(1.0); - if (*(data->ibipolar) != FL(0.0)) { /* bipolar mode */ + if (*(p->ibipolar) != FL(0.0)) { /* bipolar mode */ /* clamp kamount in range [-1,1] */ - midpoint = (*(data->kamount) > FL(1.0) ? maxampl : - (*(data->kamount) < FL(-1.0) ? -maxampl : - (*(data->kamount) * maxampl))); + midpoint = (*(p->kamount) > FL(1.0) ? maxampl : + (*(p->kamount) < FL(-1.0) ? -maxampl : + (*(p->kamount) * maxampl))); leftslope = (midpoint + maxampl) / maxampl; rightslope = (maxampl - midpoint) / maxampl; - for (n=0; nkamount) >= FL(1.0) ? maxampl : - (*(data->kamount) <= FL(-1.0) ? FL(0.0) : - ((*(data->kamount) + FL(1.0)) * halfmaxampl))); + midpoint = (*(p->kamount) >= FL(1.0) ? maxampl : + (*(p->kamount) <= FL(-1.0) ? FL(0.0) : + ((*(p->kamount) + FL(1.0)) * halfmaxampl))); leftslope = midpoint / halfmaxampl; rightslope = (maxampl - midpoint) / halfmaxampl; - for (n=0; nksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, *syncout, *syncin; double incr; int cpsIsARate; @@ -396,9 +444,14 @@ syncin = p->asyncin; phase = p->curphase; cpsIsARate = (csound->GetInputArgAMask(p) & 1); /* check first input arg rate */ + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (cpsIsARate) { MYFLT *cps = p->xcps; - for (n=0; nxcps * csound->onedsr); - for (n=0; nlastin = FL(0.0); - data->maxamplitude = *data->ifullscale; + p->lastin = FL(0.0); + p->maxamplitude = *p->ifullscale; return OK; } -static int Phasine(CSOUND* csound, PHASINE* data) +static int Phasine(CSOUND* csound, PHASINE* p) { MYFLT last, cur, phase, adjust, maxampl; - int n, nsmps = csound->ksmps; - MYFLT* out = data->aout; - MYFLT* in = data->ain; - - adjust = *(data->kphaseadjust); - last = data->lastin; - maxampl = data->maxamplitude; - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + MYFLT* out = p->aout; + MYFLT* in = p->ain; + + adjust = *(p->kphaseadjust); + last = p->lastin; + maxampl = p->maxamplitude; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nlastin = last; + p->lastin = last; return OK; } @@ -500,18 +560,18 @@ #define S(x) sizeof(x) static OENTRY shape_localops[] = { - /* { "phasine", S(PHASINE), 5, "a", "akp", + /* { "phasine", S(PHASINE), 0, 5, "a", "akp", (SUBR)PhasineInit, NULL, (SUBR)Phasine }, */ - { "powershape", S(POWER_SHAPE), 5, "a", "akp", + { "powershape", S(POWER_SHAPE), 0, 5, "a", "akp", (SUBR)PowerShapeInit, NULL, (SUBR)PowerShape }, - { "polynomial", S(POLYNOMIAL), 4, "a", "az", NULL, NULL, (SUBR)Polynomial }, - { "chebyshevpoly", S(CHEBPOLY), 5, "a", "az", + { "polynomial", S(POLYNOMIAL), 0, 4, "a", "az", NULL, NULL, (SUBR)Polynomial }, + { "chebyshevpoly", S(CHEBPOLY), 0, 5, "a", "az", (SUBR)ChebyshevPolyInit, NULL, (SUBR)ChebyshevPolynomial }, - { "pdclip", S(PD_CLIP), 4, "a", "akkop", NULL, NULL, (SUBR)PDClip }, - { "pdhalf", S(PD_HALF), 4, "a", "akop", NULL, NULL, (SUBR)PDHalfX }, - { "pdhalfy", S(PD_HALF), 4, "a", "akop", NULL, NULL, (SUBR)PDHalfY }, - { "syncphasor", S(SYNCPHASOR), 5, "aa", "xao", + { "pdclip", S(PD_CLIP), 0, 4, "a", "akkop", NULL, NULL, (SUBR)PDClip }, + { "pdhalf", S(PD_HALF), 0, 4, "a", "akop", NULL, NULL, (SUBR)PDHalfX }, + { "pdhalfy", S(PD_HALF), 0, 4, "a", "akop", NULL, NULL, (SUBR)PDHalfY }, + { "syncphasor", S(SYNCPHASOR), 0, 5, "aa", "xao", (SUBR)SyncPhasorInit, NULL, (SUBR)SyncPhasor }, }; -LINKAGE1(shape_localops) +LINKAGE_BUILTIN(shape_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/signalflowgraph.cpp csound-6.02~dfsg/Opcodes/signalflowgraph.cpp --- csound-5.17.11~dfsg/Opcodes/signalflowgraph.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/signalflowgraph.cpp 2014-01-07 16:54:20.000000000 +0000 @@ -32,20 +32,26 @@ * outleta Sname, asignal * outletk Sname, ksignal * outletf Sname, fsignal + * outletv Sname, xsignal[] * * Outlets send a, k, or f-rate signals out from an instrument. + * A- and k-rate signals may be arrays. * * The name of the outlet is implicitly qualified by the instrument name * or number,`so it is valid to use the same outlet name in more than one * instrument (but not to use the same outlet name twice in one instrument). * - * asignal inleta Sname - * ksignal inletk Sname - * fsignal inletf Sname + * asignal inleta Sname + * ksignal inletk Sname + * fsignal inletf Sname + * xsignal[] inletv SName + * + * Inlets receive a, k, or f-rate signals from outlets in + * other instruments. A- and k-rate signals may be arrays. * - * Inlets receive a, k, or f-rate signals from outlets in other instruments. * Outlets are connected to inlets of the same type using the connect - * opcode. + * opcode. If arrays are used, the inlets and outlets must be a-rate + * and the same shape. * * The name of the inlet is implicitly qualified by the instrument name, * or number, so it is valid to use the same inlet name in more than one @@ -91,31 +97,52 @@ * to ftgenonce with the same arguments receives the same instance of the * function table data. Every change in the value of any ftgenonce argument * causes the creation of a new function table. + * + * TODO: The inletv opcode always crashes. Not sure why. Perhaps the + * array operations are not ready for prime time at a-rate. */ #include "OpcodeBase.hpp" #include #include +#include #include #include #include #include #include #include +#include "text.h" + +namespace csound { struct SignalFlowGraph; struct Outleta; struct Outletk; struct Outletf; struct Outletkid; +struct Outletv; struct Inleta; struct Inletk; struct Inletf; struct Inletkid; +struct Inletv; struct Connect; struct AlwaysOn; struct FtGenOnce; +static void* cs_sfg_ftables = 0; +static void* cs_sfg_ports = 0; + +#if defined(ISSTRCOD) +#undef ISSTRCOD +#endif + +static bool ISSTRCOD(MYFLT myflt) +{ + return std::isnan(myflt); +} + std::ostream &operator << (std::ostream &stream, const EVTBLK &a) { stream << a.opcod; @@ -185,16 +212,19 @@ std::map > > aoutletsForCsoundsForSourceOutletIds; std::map > > koutletsForCsoundsForSourceOutletIds; std::map > > foutletsForCsoundsForSourceOutletIds; +std::map > > voutletsForCsoundsForSourceOutletIds; std::map > > kidoutletsForCsoundsForSourceOutletIds; std::map > > ainletsForCsoundsForSinkInletIds; std::map > > kinletsForCsoundsForSinkInletIds; std::map > > finletsForCsoundsForSinkInletIds; +std::map > > vinletsForCsoundsForSinkInletIds; std::map > > kidinletsForCsoundsForSinkInletIds; std::map > > connectionsForCsounds; std::map > functionTablesForCsoundsForEvtblks; std::map *> * > > aoutletVectorsForCsounds; std::map *> * > > koutletVectorsForCsounds; std::map *> * > > foutletVectorsForCsounds; +std::map *> * > > voutletVectorsForCsounds; std::map *> * > > kidoutletVectorsForCsounds; // For true thread-safety, access to shared data must be protected. @@ -207,7 +237,8 @@ */ struct SignalFlowGraph : public OpcodeBase { int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { aoutletsForCsoundsForSourceOutletIds[csound].clear(); ainletsForCsoundsForSinkInletIds[csound].clear(); @@ -215,14 +246,19 @@ kinletsForCsoundsForSinkInletIds[csound].clear(); foutletsForCsoundsForSourceOutletIds[csound].clear(); finletsForCsoundsForSinkInletIds[csound].clear(); + voutletsForCsoundsForSourceOutletIds[csound].clear(); + vinletsForCsoundsForSinkInletIds[csound].clear(); kidoutletsForCsoundsForSourceOutletIds[csound].clear(); kidinletsForCsoundsForSinkInletIds[csound].clear(); connectionsForCsounds[csound].clear(); } -#pragma omp critical (critical_section_ftables) + csound->UnlockMutex(cs_sfg_ports); +//#pragma omp critical (cs_sfg_ftables) + csound->LockMutex(cs_sfg_ftables); { functionTablesForCsoundsForEvtblks[csound].clear(); } + csound->UnlockMutex(cs_sfg_ftables); return OK; }; }; @@ -231,7 +267,7 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; MYFLT *asignal; /** * State. @@ -239,21 +275,27 @@ char sourceOutletId[0x100]; int init(CSOUND *csound) { //warn(csound, "BEGAN Outleta::init()...\n"); -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { sourceOutletId[0] = 0; - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sourceOutletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &aoutlets = aoutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + std::vector &aoutlets = + aoutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; if (std::find(aoutlets.begin(), aoutlets.end(), this) == aoutlets.end()) { aoutlets.push_back(this); - warn(csound, "Created instance 0x%x of %d instances of outlet %s\n", this, aoutlets.size(), sourceOutletId); + warn(csound, "Created instance 0x%x of %d instances of outlet %s\n", + this, aoutlets.size(), sourceOutletId); } } + csound->UnlockMutex(cs_sfg_ports); //warn(csound, "ENDED Outleta::init()...\n"); return OK; } @@ -267,7 +309,7 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; /** * State. */ @@ -275,10 +317,11 @@ std::vector< std::vector *> *sourceOutlets; int sampleN; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { warn(csound, "BEGAN Inleta::init()...\n"); - sampleN = csound->GetKsmps(csound); + sampleN = opds.insdshead->ksmps; warn(csound, "sourceOutlets: 0x%x\n", sourceOutlets); if (std::find(aoutletVectorsForCsounds[csound].begin(), aoutletVectorsForCsounds[csound].end(), @@ -288,39 +331,48 @@ } warn(csound, "sourceOutlets: 0x%x\n", sourceOutlets); sinkInletId[0] = 0; - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sinkInletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sinkInletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &ainlets = ainletsForCsoundsForSinkInletIds[csound][sinkInletId]; + std::vector &ainlets = + ainletsForCsoundsForSinkInletIds[csound][sinkInletId]; if (std::find(ainlets.begin(), ainlets.end(), this) == ainlets.end()) { ainlets.push_back(this); warn(csound, "Created instance 0x%x of inlet %s\n", this, sinkInletId); } // Find source outlets connecting to this. // Any number of sources may connect to any number of sinks. - std::vector &sourceOutletIds = connectionsForCsounds[csound][sinkInletId]; + std::vector &sourceOutletIds = + connectionsForCsounds[csound][sinkInletId]; for (size_t i = 0, n = sourceOutletIds.size(); i < n; i++) { const std::string &sourceOutletId = sourceOutletIds[i]; - std::vector &aoutlets = aoutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; - if (std::find(sourceOutlets->begin(), sourceOutlets->end(), &aoutlets) == sourceOutlets->end()) { + std::vector &aoutlets = + aoutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + if (std::find(sourceOutlets->begin(), sourceOutlets->end(), + &aoutlets) == sourceOutlets->end()) { sourceOutlets->push_back(&aoutlets); - warn(csound, "Connected instances of outlet %s to instance 0x%x of inlet %s.\n", sourceOutletId.c_str(), this, sinkInletId); + warn(csound, + Str("Connected instances of outlet %s to instance 0x%x of " + "inlet %s.\n"), sourceOutletId.c_str(), this, sinkInletId); } } warn(csound, "ENDED Inleta::init().\n"); } + csound->UnlockMutex(cs_sfg_ports); return OK; } /** * Sum arate values from active outlets feeding this inlet. */ int audio(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - //warn(csound, "BEGAN Inleta::audio()...\n"); // Zero the inlet buffer. for (int sampleI = 0; sampleI < sampleN; sampleI++) { @@ -337,11 +389,8 @@ instanceI++) { Outleta *sourceOutlet = instances->at(instanceI); // Skip inactive instances. - if (sourceOutlet->h.insdshead->actflg) { - // Loop over the samples in the inlet buffer. - for (int sampleI = 0; - sampleI < sampleN; - sampleI++) { + if (sourceOutlet->opds.insdshead->actflg) { + for (int sampleI = 0, sampleN = ksmps(); sampleI < sampleN; ++sampleI) { asignal[sampleI] += sourceOutlet->asignal[sampleI]; } } @@ -349,6 +398,7 @@ } //warn(csound, "ENDED Inleta::audio().\n"); } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -357,28 +407,33 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; MYFLT *ksignal; /** * State. */ char sourceOutletId[0x100]; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sourceOutletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &koutlets = koutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + std::vector &koutlets = + koutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; if (std::find(koutlets.begin(), koutlets.end(), this) == koutlets.end()) { koutlets.push_back(this); - warn(csound, "Created instance 0x%x of %d instances of outlet %s\n", this, koutlets.size(), sourceOutletId); + warn(csound, Str("Created instance 0x%x of %d instances of outlet %s\n"), + this, koutlets.size(), sourceOutletId); } } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -391,7 +446,7 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; /** * State. */ @@ -399,10 +454,11 @@ std::vector< std::vector *> *sourceOutlets; int ksmps; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; if (std::find(koutletVectorsForCsounds[csound].begin(), koutletVectorsForCsounds[csound].end(), sourceOutlets) == koutletVectorsForCsounds[csound].end()) { @@ -410,36 +466,45 @@ koutletVectorsForCsounds[csound].push_back(sourceOutlets); } sinkInletId[0] = 0; - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sinkInletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sinkInletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &kinlets = kinletsForCsoundsForSinkInletIds[csound][sinkInletId]; + std::vector &kinlets = + kinletsForCsoundsForSinkInletIds[csound][sinkInletId]; if (std::find(kinlets.begin(), kinlets.end(), this) == kinlets.end()) { kinlets.push_back(this); warn(csound, "Created instance 0x%x of inlet %s\n", this, sinkInletId); } // Find source outlets connecting to this. // Any number of sources may connect to any number of sinks. - std::vector &sourceOutletIds = connectionsForCsounds[csound][sinkInletId]; + std::vector &sourceOutletIds = + connectionsForCsounds[csound][sinkInletId]; for (size_t i = 0, n = sourceOutletIds.size(); i < n; i++) { const std::string &sourceOutletId = sourceOutletIds[i]; - std::vector &koutlets = koutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; - if (std::find(sourceOutlets->begin(), sourceOutlets->end(), &koutlets) == sourceOutlets->end()) { + std::vector &koutlets = + koutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + if (std::find(sourceOutlets->begin(), + sourceOutlets->end(), &koutlets) == sourceOutlets->end()) { sourceOutlets->push_back(&koutlets); - warn(csound, "Connected instances of outlet %s to instance 0x%x of inlet %s.\n", sourceOutletId.c_str(), this, sinkInletId); + warn(csound, Str("Connected instances of outlet %s to instance 0x%x" + "of inlet %s.\n"), + sourceOutletId.c_str(), this, sinkInletId); } } } + csound->UnlockMutex(cs_sfg_ports); return OK; } /** * Sum krate values from active outlets feeding this inlet. */ int kontrol(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) { // Zero the inlet buffer. *ksignal = FL(0.0); @@ -454,12 +519,13 @@ instanceI++) { const Outletk *sourceOutlet = instances->at(instanceI); // Skip inactive instances. - if (sourceOutlet->h.insdshead->actflg) { + if (sourceOutlet->opds.insdshead->actflg) { *ksignal += *sourceOutlet->ksignal; } } } } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -468,27 +534,31 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; PVSDAT *fsignal; /** * State. */ char sourceOutletId[0x100]; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) { - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sourceOutletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &foutlets = foutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + std::vector &foutlets = + foutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; if (std::find(foutlets.begin(), foutlets.end(), this) == foutlets.end()) { foutlets.push_back(this); warn(csound, "Created instance 0x%x of outlet %s\n", this, sourceOutletId); } } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -501,7 +571,7 @@ /** * Inputs. */ - MYFLT *Sname; + STRINGDAT *Sname; /** * State. */ @@ -511,9 +581,10 @@ int lastframe; bool fsignalInitialized; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; lastframe = 0; fsignalInitialized = false; if (std::find(foutletVectorsForCsounds[csound].begin(), @@ -523,29 +594,38 @@ foutletVectorsForCsounds[csound].push_back(sourceOutlets); } sinkInletId[0] = 0; - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sinkInletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sinkInletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); } - std::vector &finlets = finletsForCsoundsForSinkInletIds[csound][sinkInletId]; + std::vector &finlets = + finletsForCsoundsForSinkInletIds[csound][sinkInletId]; if (std::find(finlets.begin(), finlets.end(), this) == finlets.end()) { finlets.push_back(this); warn(csound, "Created instance 0x%x of inlet %s\n", this, sinkInletId); } // Find source outlets connecting to this. // Any number of sources may connect to any number of sinks. - std::vector &sourceOutletIds = connectionsForCsounds[csound][sinkInletId]; + std::vector &sourceOutletIds = + connectionsForCsounds[csound][sinkInletId]; for (size_t i = 0, n = sourceOutletIds.size(); i < n; i++) { const std::string &sourceOutletId = sourceOutletIds[i]; - std::vector &foutlets = foutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; - if (std::find(sourceOutlets->begin(), sourceOutlets->end(), &foutlets) == sourceOutlets->end()) { + std::vector &foutlets = + foutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + if (std::find(sourceOutlets->begin(), + sourceOutlets->end(), &foutlets) == sourceOutlets->end()) { sourceOutlets->push_back(&foutlets); - warn(csound, "Connected instances of outlet %s to instance 0x%x of inlet %s.\n", sourceOutletId.c_str(), this, sinkInletId); + warn(csound, + Str("Connected instances of outlet %s to instance 0x%x of inlet %s.\n"), + sourceOutletId.c_str(), this, sinkInletId); } } } + csound->UnlockMutex(cs_sfg_ports); return OK; } /** @@ -553,7 +633,8 @@ */ int audio(CSOUND *csound) { int result = OK; -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { float *sink = 0; float *source = 0; @@ -570,24 +651,28 @@ instanceI++) { const Outletf *sourceOutlet = instances->at(instanceI); // Skip inactive instances. - if (sourceOutlet->h.insdshead->actflg) { + if (sourceOutlet->opds.insdshead->actflg) { if (!fsignalInitialized) { int32 N = sourceOutlet->fsignal->N; if (UNLIKELY(sourceOutlet->fsignal == fsignal)) { - csound->Warning(csound, "Unsafe to have same fsig as in and out"); + csound->Warning(csound, + Str("Unsafe to have same fsig as in and out")); } fsignal->sliding = 0; if (sourceOutlet->fsignal->sliding) { if (fsignal->frame.auxp == NULL || - fsignal->frame.size < sizeof(MYFLT) * csound->ksmps * (N + 2)) - csound->AuxAlloc(csound, (N + 2) * sizeof(MYFLT) * csound->ksmps, + fsignal->frame.size < + sizeof(MYFLT) * opds.insdshead->ksmps * (N + 2)) + csound->AuxAlloc(csound, + (N + 2) * sizeof(MYFLT) * opds.insdshead->ksmps, &fsignal->frame); fsignal->NB = sourceOutlet->fsignal->NB; fsignal->sliding = 1; } else if (fsignal->frame.auxp == NULL || fsignal->frame.size < sizeof(float) * (N + 2)) { - csound->AuxAlloc(csound, (N + 2) * sizeof(float), &fsignal->frame); + csound->AuxAlloc(csound, + (N + 2) * sizeof(float), &fsignal->frame); } fsignal->N = N; fsignal->overlap = sourceOutlet->fsignal->overlap; @@ -598,14 +683,16 @@ lastframe = 0; if (UNLIKELY(!(fsignal->format == PVS_AMP_FREQ) || (fsignal->format == PVS_AMP_PHASE))) - result = csound->InitError(csound, Str("inletf: signal format " - "must be amp-phase or amp-freq.")); + result = + csound->InitError(csound, Str("inletf: signal format " + "must be amp-phase or amp-freq.")); fsignalInitialized = true; } if (fsignal->sliding) { for (int frameI = 0; frameI < ksmps; frameI++) { sinkFrame = (CMPLX*) fsignal->frame.auxp + (fsignal->NB * frameI); - sourceFrame = (CMPLX*) sourceOutlet->fsignal->frame.auxp + (fsignal->NB * frameI); + sourceFrame = + (CMPLX*) sourceOutlet->fsignal->frame.auxp + (fsignal->NB * frameI); for (size_t binI = 0, binN = fsignal->NB; binI < binN; binI++) { if (sourceFrame[binI].re > sinkFrame[binI].re) { sinkFrame[binI] = sourceFrame[binI]; @@ -631,16 +718,170 @@ } } } + csound->UnlockMutex(cs_sfg_ports); return result; } }; +struct Outletv : public OpcodeBase { + /** + * Inputs. + */ + STRINGDAT *Sname; + ARRAYDAT *vsignal; + /** + * State. + */ + char sourceOutletId[0x100]; + int init(CSOUND *csound) { + warn(csound, "BEGAN Outletv::init()...\n"); +//#pragma omp critical (cs_sfg_ports) + csound->UnlockMutex(cs_sfg_ports); + { + sourceOutletId[0] = 0; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; + if (insname) { + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); + } else { + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); + } + std::vector &voutlets = + voutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + if (std::find(voutlets.begin(), voutlets.end(), this) == voutlets.end()) { + voutlets.push_back(this); + warn(csound, "Created instance 0x%x of %d instances of outlet %s (out arraydat: 0x%x dims: %2d size: %4d [%4d] data: 0x%x (0x%x))\n", + this, voutlets.size(), sourceOutletId, vsignal, vsignal->dimensions, vsignal->sizes[0], vsignal->arrayMemberSize, vsignal->data, &vsignal->data); + } + } + warn(csound, "ENDED Outletv::init()...\n"); + csound->UnlockMutex(cs_sfg_ports); + return OK; + } +}; + +struct Inletv : public OpcodeBase { + /** + * Output. + */ + ARRAYDAT *vsignal; + /** + * Inputs. + */ + STRINGDAT *Sname; + /** + * State. + */ + char sinkInletId[0x100]; + std::vector< std::vector *> *sourceOutlets; + size_t arraySize; + size_t myFltsPerArrayElement; + int sampleN; + int init(CSOUND *csound) { +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); + { + warn(csound, "BEGAN Inletv::init()...\n"); + sampleN = opds.insdshead->ksmps; + // The array elements may be krate (1 MYFLT) or arate (ksmps MYFLT). + myFltsPerArrayElement = vsignal->arrayMemberSize / sizeof(MYFLT); + warn(csound, "myFltsPerArrayElement: %d\n", myFltsPerArrayElement); + arraySize = myFltsPerArrayElement; + for(size_t dimension = 0; dimension < vsignal->dimensions; ++dimension) { + arraySize *= MYFLT2LRND(vsignal->sizes[dimension]); + } + warn(csound, "arraySize: %d\n", arraySize); + warn(csound, "sourceOutlets: 0x%x\n", sourceOutlets); + if (std::find(voutletVectorsForCsounds[csound].begin(), + voutletVectorsForCsounds[csound].end(), + sourceOutlets) == voutletVectorsForCsounds[csound].end()) { + sourceOutlets = new std::vector< std::vector *>; + voutletVectorsForCsounds[csound].push_back(sourceOutlets); + } + warn(csound, "sourceOutlets: 0x%x\n", sourceOutlets); + sinkInletId[0] = 0; + const char *insname = + csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; + if (insname) { + std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname->data); + } else { + std::sprintf(sinkInletId, "%d:%s", opds.insdshead->insno, + (char *)Sname->data); + } + std::vector &vinlets = + vinletsForCsoundsForSinkInletIds[csound][sinkInletId]; + if (std::find(vinlets.begin(), vinlets.end(), this) == vinlets.end()) { + vinlets.push_back(this); + warn(csound, "Created instance 0x%x of inlet %s (in arraydat: 0x%x dims: %2d size: %4d [%4d] data: 0x%x (0x%x))\n", + this, sinkInletId, vsignal, vsignal->dimensions, vsignal->sizes[0], vsignal->arrayMemberSize, vsignal->data, &vsignal->data); + } + // Find source outlets connecting to this. + // Any number of sources may connect to any number of sinks. + std::vector &sourceOutletIds = + connectionsForCsounds[csound][sinkInletId]; + for (size_t i = 0, n = sourceOutletIds.size(); i < n; i++) { + const std::string &sourceOutletId = sourceOutletIds[i]; + std::vector &voutlets = + voutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; + if (std::find(sourceOutlets->begin(), sourceOutlets->end(), + &voutlets) == sourceOutlets->end()) { + sourceOutlets->push_back(&voutlets); + warn(csound, + Str("Connected instances of outlet %s to instance 0x%x of " + "inlet %s\n"), sourceOutletId.c_str(), this, sinkInletId); + } + } + warn(csound, "ENDED Inletv::init().\n"); + } + csound->UnlockMutex(cs_sfg_ports); + return OK; + } + /** + * Sum values from active outlets feeding this inlet. + */ + int audio(CSOUND *csound) { +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); + { + //warn(csound, "BEGAN Inletv::audio()...\n"); + //for (uint32_t signalI = 0; signalI < arraySize; ++signalI) { + // vsignal->data[signalI] = FL(0.0); + //} + // Loop over the source connections... + for (size_t sourceI = 0, sourceN = sourceOutlets->size(); + sourceI < sourceN; + sourceI++) { + // Loop over the source connection instances... + std::vector *instances = sourceOutlets->at(sourceI); + for (size_t instanceI = 0, instanceN = instances->size(); + instanceI < instanceN; + instanceI++) { + Outletv *sourceOutlet = instances->at(instanceI); + // Skip inactive instances. + if (sourceOutlet->opds.insdshead->actflg) { + for (uint32_t signalI = 0; signalI < arraySize; ++signalI) { + ARRAYDAT *insignal = sourceOutlet->vsignal; + MYFLT *indata = insignal->data; + //warn(csound, "Inletv::audio: sourceOutlet: 0%x in arraydat: 0x%x data: 0x%x (0x%x)\n", sourceOutlet, insignal, indata, &insignal->data); + vsignal->data[signalI] += indata[signalI]; + } + } + } + } + //warn(csound, "ENDED Inletv::audio().\n"); + } + csound->UnlockMutex(cs_sfg_ports); + return OK; + } +}; + struct Outletkid : public OpcodeBase { /** * Inputs. */ - MYFLT *Sname; - MYFLT *SinstanceId; + STRINGDAT *Sname; + STRINGDAT *SinstanceId; MYFLT *ksignal; /** * State. @@ -648,23 +889,24 @@ char sourceOutletId[0x100]; char *instanceId; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + const char *insname = csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; instanceId = csound->strarg2name(csound, (char*) NULL, - SinstanceId, + SinstanceId->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + 1); if (insname && instanceId) { - std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sourceOutletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, (char *)Sname->data); } if (insname) { - std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sourceOutletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sourceOutletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sourceOutletId, "%d:%s", opds.insdshead->insno, (char *)Sname->data); } std::vector &koutlets = kidoutletsForCsoundsForSourceOutletIds[csound][sourceOutletId]; if (std::find(koutlets.begin(), koutlets.end(), this) == koutlets.end()) { @@ -672,6 +914,7 @@ warn(csound, "Created instance 0x%x of %d instances of outlet %s\n", this, koutlets.size(), sourceOutletId); } } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -684,8 +927,8 @@ /** * Inputs. */ - MYFLT *Sname; - MYFLT *SinstanceId; + STRINGDAT *Sname; + STRINGDAT *SinstanceId; /** * State. */ @@ -694,10 +937,10 @@ std::vector< std::vector *> *sourceOutlets; int ksmps; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - - ksmps = csound->GetKsmps(csound); + ksmps = opds.insdshead->ksmps; if (std::find(kidoutletVectorsForCsounds[csound].begin(), kidoutletVectorsForCsounds[csound].end(), sourceOutlets) == kidoutletVectorsForCsounds[csound].end()) { @@ -707,14 +950,14 @@ sinkInletId[0] = 0; instanceId = csound->strarg2name(csound, (char*) NULL, - SinstanceId, + SinstanceId->data, (char *)"", - (int) csound->GetInputArgSMask(this)); - const char *insname = csound->instrtxtp[h.insdshead->insno]->insname; + 1); + const char *insname = csound->GetInstrumentList(csound)[opds.insdshead->insno]->insname; if (insname) { - std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname); + std::sprintf(sinkInletId, "%s:%s", insname, (char *)Sname->data); } else { - std::sprintf(sinkInletId, "%d:%s", h.insdshead->insno, (char *)Sname); + std::sprintf(sinkInletId, "%d:%s", opds.insdshead->insno, (char *)Sname->data); } std::vector &kinlets = kidinletsForCsoundsForSinkInletIds[csound][sinkInletId]; if (std::find(kinlets.begin(), kinlets.end(), this) == kinlets.end()) { @@ -733,15 +976,17 @@ } } } + csound->UnlockMutex(cs_sfg_ports); return OK; } /** * Replay instance signal. */ int kontrol(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - // Zero the inlet buffer. + // Zero the / buffer. *ksignal = FL(0.0); // Loop over the source connections... for (size_t sourceI = 0, sourceN = sourceOutlets->size(); @@ -754,7 +999,7 @@ instanceI++) { const Outletkid *sourceOutlet = instances->at(instanceI); // Skip inactive instances and also all non-matching instances. - if (sourceOutlet->h.insdshead->actflg) { + if (sourceOutlet->opds.insdshead->actflg) { if (std::strcmp(sourceOutlet->instanceId, instanceId) == 0) { *ksignal += *sourceOutlet->ksignal; } @@ -762,6 +1007,7 @@ } } } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; @@ -771,42 +1017,214 @@ * Inputs. */ MYFLT *Source; - MYFLT *Soutlet; - MYFLT *Sink; - MYFLT *Sinlet; + STRINGDAT *Soutlet; + MYFLT *Sink; + STRINGDAT *Sinlet; + int init(CSOUND *csound) { +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); + { + std::string sourceOutletId = csound->strarg2name(csound, + (char *) 0, + ((ISSTRCOD(*Source)) ? + csound->GetString(csound,*Source) : + (char *)Source), + (char *)"", + ISSTRCOD(*Source)); + sourceOutletId += ":"; + sourceOutletId += csound->strarg2name(csound, + (char *) 0, + Soutlet->data, + (char *)"", + 1); + + std::string sinkInletId = csound->strarg2name(csound, + (char *) 0, + ((ISSTRCOD(*Sink)) ? + csound->GetString(csound,*Sink) : + (char *)Sink), + (char *)"", + ISSTRCOD(*Sink)); + sinkInletId += ":"; + sinkInletId += csound->strarg2name(csound, + (char *) 0, + Sinlet->data, + (char *)"", + 1); + warn(csound, "Connected outlet %s to inlet %s.\n", sourceOutletId.c_str(), sinkInletId.c_str()); + connectionsForCsounds[csound][sinkInletId].push_back(sourceOutletId); + } + csound->UnlockMutex(cs_sfg_ports); + return OK; + } +}; + +struct Connecti : public OpcodeBase { + /** + * Inputs. + */ + MYFLT *Source; + STRINGDAT *Soutlet; + STRINGDAT *Sink; + STRINGDAT *Sinlet; int init(CSOUND *csound) { -#pragma omp critical (cs_sfg_ports) +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { std::string sourceOutletId = csound->strarg2name(csound, (char *) 0, - Source, + ((ISSTRCOD(*Source)) ? + csound->GetString(csound,*Source) : + (char *)Source), (char *)"", - (int) csound->GetInputArgSMask(this)); + ISSTRCOD(*Source)); sourceOutletId += ":"; sourceOutletId += csound->strarg2name(csound, (char *) 0, - Soutlet, + Soutlet->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + 1); std::string sinkInletId = csound->strarg2name(csound, (char *) 0, - Sink, + Sink->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + 1); sinkInletId += ":"; sinkInletId += csound->strarg2name(csound, (char *) 0, - Sinlet, + Sinlet->data, (char *)"", - (int) csound->GetInputArgSMask(this)); + 1); warn(csound, "Connected outlet %s to inlet %s.\n", sourceOutletId.c_str(), sinkInletId.c_str()); connectionsForCsounds[csound][sinkInletId].push_back(sourceOutletId); } + csound->UnlockMutex(cs_sfg_ports); + return OK; + } +}; + + +struct Connectii : public OpcodeBase { + /** + * Inputs. + */ + STRINGDAT *Source; + STRINGDAT *Soutlet; + MYFLT *Sink; + STRINGDAT *Sinlet; + int init(CSOUND *csound) { +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); + { + std::string sourceOutletId = csound->strarg2name(csound, + (char *) 0, + Source->data, + (char *)"", + 1); + sourceOutletId += ":"; + sourceOutletId += csound->strarg2name(csound, + (char *) 0, + Soutlet->data, + (char *)"", + 1); + std::string sinkInletId = + csound->strarg2name(csound, + (char *) 0, + ((ISSTRCOD(*Sink)) ? + csound->GetString(csound,*Sink) : + (char *)Sink), + (char *)"", + ISSTRCOD(*Sink));; + sinkInletId += ":"; + sinkInletId += csound->strarg2name(csound, + (char *) 0, + Sinlet->data, + (char *)"", + 1); + warn(csound, Str("Connected outlet %s to inlet %s.\n"), + sourceOutletId.c_str(), sinkInletId.c_str()); + connectionsForCsounds[csound][sinkInletId].push_back(sourceOutletId); + } + csound->UnlockMutex(cs_sfg_ports); + return OK; + } +}; + +struct ConnectS : public OpcodeBase { + /** + * Inputs. + */ + STRINGDAT *Source; + STRINGDAT *Soutlet; + STRINGDAT *Sink; + STRINGDAT *Sinlet; + int init(CSOUND *csound) { +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); + { + std::string sourceOutletId = csound->strarg2name(csound, + (char *) 0, + Source->data, + (char *)"", + 1); + sourceOutletId += ":"; + sourceOutletId += csound->strarg2name(csound, + (char *) 0, + Soutlet->data, + (char *)"", + 1); + std::string sinkInletId = csound->strarg2name(csound, + (char *) 0, + Sink->data, + (char *)"", + 1); + sinkInletId += ":"; + sinkInletId += csound->strarg2name(csound, + (char *) 0, + Sinlet->data, + (char *)"", + 1); + warn(csound, Str("Connected outlet %s to inlet %s.\n"), + sourceOutletId.c_str(), sinkInletId.c_str()); + connectionsForCsounds[csound][sinkInletId].push_back(sourceOutletId); + } + csound->UnlockMutex(cs_sfg_ports); return OK; } }; -struct AlwaysOn : public OpcodeBase { +struct AlwaysOnS : public OpcodeBase { + /** + * Inputs. + */ + STRINGDAT *Sinstrument; + MYFLT *argums[VARGMAX]; + /** + * State. + */ + EVTBLK evtblk; + int init(CSOUND *csound) { + evtblk.opcod = 'i'; + evtblk.strarg = NULL; + evtblk.p[0] = FL(0.0); + evtblk.p[1] = csound->strarg2insno(csound, Sinstrument->data, 1); + evtblk.p[2] = evtblk.p2orig = FL(0.0); + evtblk.p[3] = evtblk.p3orig = FL(-1.0); + size_t inArgCount = csound->GetInputArgCnt(this); + // Add 2, for hard-coded p2 and p3. + evtblk.pcnt = (int16) inArgCount + 2; + // Subtract 1, for only required inarg p1. + size_t argumN = inArgCount - 1; + // Start evtblk at 4, argums at 0. + for (size_t pfieldI = 4, argumI = 0; argumI < argumN; pfieldI++, argumI++) { + evtblk.p[pfieldI] = *argums[argumI]; + } + csound->insert_score_event(csound, &evtblk, FL(0.0)); + return OK; + } +}; + +struct AlwaysOn : public OpcodeBase { /** * Inputs. */ @@ -821,17 +1239,14 @@ (char *) 0, Sinstrument, (char *)"", - (int) csound->GetInputArgSMask(this)); + (int) 0); evtblk.opcod = 'i'; - evtblk.strarg = 0; + evtblk.strarg = NULL; evtblk.p[0] = FL(0.0); evtblk.p[1] = *Sinstrument; evtblk.p[2] = evtblk.p2orig = FL(0.0); evtblk.p[3] = evtblk.p3orig = FL(-1.0); - if (csound->GetInputArgSMask(this)) { - evtblk.p[1] = SSTRCOD; - evtblk.strarg = (char *)Sinstrument; - } + size_t inArgCount = csound->GetInputArgCnt(this); // Add 2, for hard-coded p2 and p3. evtblk.pcnt = (int16) inArgCount + 2; @@ -841,7 +1256,7 @@ for (size_t pfieldI = 4, argumI = 0; argumI < argumN; pfieldI++, argumI++) { evtblk.p[pfieldI] = *argums[argumI]; } - csound->insert_score_event(csound, &evtblk, FL(0.0)); + csound->insert_score_event_at_sample(csound, &evtblk, 0); return OK; } }; @@ -862,8 +1277,76 @@ MYFLT *argums[VARGMAX]; EventBlock eventBlock; int init(CSOUND *csound) { + int result; +//#pragma omp critical (cs_ftables) + csound->LockMutex(cs_sfg_ftables); + { + // Default output. + *ifno = FL(0.0); + EVTBLK &evtblk = eventBlock.evtblk; + std::memset(&evtblk, 0, sizeof(EVTBLK)); + evtblk.opcod = 'f'; + evtblk.strarg = 0; + evtblk.p[0] = FL(0.0); + evtblk.p[1] = *p1; + evtblk.p[2] = evtblk.p2orig = FL(0.0); + evtblk.p[3] = evtblk.p3orig = *p3; + evtblk.p[4] = *p4; + evtblk.p[5] = *p5; + evtblk.pcnt = (int16) csound->GetInputArgCnt(this); + int n = evtblk.pcnt - 5; + if (n > 0) { + MYFLT **argp = argums; + MYFLT *fp = &evtblk.p[0] + 6; + do { + *fp++ = **argp++; + } while (--n); + } + // If the arguments have not been used before for this instance of Csound, + // create a new function table and store the arguments and table number; + // otherwise, look up and return the already created function table's number. + if(functionTablesForCsoundsForEvtblks[csound].find(eventBlock) != functionTablesForCsoundsForEvtblks[csound].end()) { + *ifno = functionTablesForCsoundsForEvtblks[csound][eventBlock]; + // warn(csound, "ftgenonce: re-using existing func: %f\n", *ifno); + // std::cerr << "ftgenonce: re-using existing func:" << evtblk << std::endl; + } else { + FUNC *func = 0; + n = csound->hfgens(csound, &func, &evtblk, 1); + if (UNLIKELY(n != 0)) { + result = csound->InitError(csound, Str("ftgenonce error")); + } + if (func) { + functionTablesForCsoundsForEvtblks[csound][eventBlock] = func->fno; + *ifno = (MYFLT) func->fno; + warn(csound, "ftgenonce: created new func: %d\n", func->fno); + // std::cerr << "ftgenonce: created new func:" << evtblk << std::endl; + } + } + } + csound->UnlockMutex(cs_sfg_ftables); + return OK; + } +}; + +struct FtGenOnceS : public OpcodeBase { + /** + * Outputs. + */ + MYFLT *ifno; + /** + * Inputs. + */ + MYFLT *p1; + MYFLT *p2; + MYFLT *p3; + MYFLT *p4; + MYFLT *p5; + MYFLT *argums[VARGMAX]; + EventBlock eventBlock; + int init(CSOUND *csound) { int result = OK; -#pragma omp critical (cs_ftables) +//#pragma omp critical (cs_ftables) + csound->LockMutex(cs_sfg_ftables); { // Default output. *ifno = FL(0.0); @@ -877,26 +1360,23 @@ evtblk.p[3] = evtblk.p3orig = *p3; evtblk.p[4] = *p4; int n = 0; - if (csound->GetInputArgSMask(this)) { + n = (int) evtblk.p[4]; evtblk.p[5] = SSTRCOD; - if (n < 0) { - n = -n; - } + if (n < 0) n = -n; + // Only GEN 1, 23, 28, or 43 can take strings. switch (n) { case 1: case 23: case 28: case 43: - evtblk.strarg = (char *)p5; + evtblk.strarg = ((STRINGDAT *)p5)->data; break; default: result = csound->InitError(csound, Str("ftgen string arg not allowed")); } - } else { - evtblk.p[5] = *p5; - } + if (result == OK) { evtblk.pcnt = (int16) csound->GetInputArgCnt(this); n = evtblk.pcnt - 5; @@ -909,8 +1389,9 @@ } // If the arguments have not been used before for this instance of Csound, // create a new function table and store the arguments and table number; - // otherwise, look up and return the already created function table's number. - if(functionTablesForCsoundsForEvtblks[csound].find(eventBlock) != functionTablesForCsoundsForEvtblks[csound].end()) { + // otherwise look up and return the already created function table's number. + if(functionTablesForCsoundsForEvtblks[csound].find(eventBlock) != + functionTablesForCsoundsForEvtblks[csound].end()) { *ifno = functionTablesForCsoundsForEvtblks[csound][eventBlock]; // warn(csound, "ftgenonce: re-using existing func: %f\n", *ifno); // std::cerr << "ftgenonce: re-using existing func:" << evtblk << std::endl; @@ -929,16 +1410,19 @@ } } } + csound->UnlockMutex(cs_sfg_ftables); return OK; } }; + extern "C" { static OENTRY oentries[] = { /* { (char *)"signalflowgraph", sizeof(SignalFlowGraph), + 0, 1, (char *)"", (char *)"", @@ -949,7 +1433,8 @@ { (char *)"outleta", sizeof(Outleta), - CW|5, + CW, + 5, (char *)"", (char *)"Sa", (SUBR)&Outleta::init_, @@ -959,7 +1444,8 @@ { (char *)"inleta", sizeof(Inleta), - CR|5, + CR, + 5, (char *)"a", (char *)"S", (SUBR)&Inleta::init_, @@ -969,7 +1455,8 @@ { (char *)"outletk", sizeof(Outletk), - CW|3, + CW, + 3, (char *)"", (char *)"Sk", (SUBR)&Outletk::init_, @@ -979,7 +1466,8 @@ { (char *)"inletk", sizeof(Inletk), - CR|3, + CR, + 3, (char *)"k", (char *)"S", (SUBR)&Inletk::init_, @@ -989,7 +1477,8 @@ { (char *)"outletkid", sizeof(Outletkid), - CW|3, + CW, + 3, (char *)"", (char *)"SSk", (SUBR)&Outletk::init_, @@ -999,7 +1488,8 @@ { (char *)"inletkid", sizeof(Inletkid), - CR|3, + CR, + 3, (char *)"k", (char *)"SS", (SUBR)&Inletk::init_, @@ -1009,7 +1499,8 @@ { (char *)"outletf", sizeof(Outletf), - CW|5, + CW, + 5, (char *)"", (char *)"Sf", (SUBR)&Outletf::init_, @@ -1019,7 +1510,8 @@ { (char *)"inletf", sizeof(Inletf), - CR|5, + CR, + 5, (char *)"f", (char *)"S", (SUBR)&Inletf::init_, @@ -1027,51 +1519,144 @@ (SUBR)&Inletf::audio_ }, { + (char *)"outletv", + sizeof(Outletv), + CW, + 5, + (char *)"", + (char *)"Sa[]", + (SUBR)&Outletv::init_, + 0, + (SUBR)&Outletv::audio_ + }, + { + (char *)"inletv", + sizeof(Inletv), + CR, + 5, + (char *)"a[]", + (char *)"S", + (SUBR)&Inletv::init_, + 0, + (SUBR)&Inletv::audio_ + }, + { (char *)"connect", sizeof(Connect), + 0, 1, (char *)"", - (char *)"TSTS", + (char *)"iSiS", (SUBR)&Connect::init_, 0, 0 }, + { + (char *)"connect.i", + sizeof(Connecti), + 0, + 1, + (char *)"", + (char *)"iSSS", + (SUBR)&Connecti::init_, + 0, + 0 + }, + { + (char *)"connect.ii", + sizeof(Connectii), + 0, + 1, + (char *)"", + (char *)"SSiS", + (SUBR)&Connectii::init_, + 0, + 0 + }, + { + (char *)"connect.S", + sizeof(ConnectS), + 0, + 1, + (char *)"", + (char *)"SSSS", + (SUBR)&ConnectS::init_, + 0, + 0 + }, { (char *)"alwayson", sizeof(AlwaysOn), + 0, 1, (char *)"", - (char *)"Tm", + (char *)"im", (SUBR)&AlwaysOn::init_, 0, 0 }, + { + (char *)"alwayson.S", + sizeof(AlwaysOnS), + 0, + 1, + (char *)"", + (char *)"Sm", + (SUBR)&AlwaysOnS::init_, + 0, + 0 + }, { (char *)"ftgenonce", sizeof(FtGenOnce), - TW|1, + TW, + 1, (char *)"i", - (char *)"iiiiTm", + (char *)"iiiiim", (SUBR)&FtGenOnce::init_, 0, 0 }, - { 0, 0, 0, 0, 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 } + { + (char *)"ftgenonce.S", + sizeof(FtGenOnce), + TW, + 1, + (char *)"i", + (char *)"iiiiSm", + (SUBR)&FtGenOnceS::init_, + 0, + 0 + }, + { 0, 0, 0, 0, 0, 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 } }; PUBLIC int csoundModuleCreate(CSOUND *csound) { + if(csound->GetDebug(csound)) { + csound->Message(csound, "signalflowgraph: csoundModuleCreate(%p)\n", csound); + } + if (cs_sfg_ports == 0) { + cs_sfg_ports = csound->Create_Mutex(1); + } + if (cs_sfg_ftables == 0) { + cs_sfg_ftables = csound->Create_Mutex(1); + } return 0; } PUBLIC int csoundModuleInit(CSOUND *csound) { + if(csound->GetDebug(csound)) { + csound->Message(csound, "signalflowgraph: csoundModuleInit(%p)\n", csound); + } OENTRY *ep = (OENTRY *)&(oentries[0]); int err = 0; while (ep->opname != 0) { err |= csound->AppendOpcode(csound, ep->opname, ep->dsblksiz, + ep->flags, ep->thread, ep->outypes, ep->intypes, @@ -1085,34 +1670,54 @@ PUBLIC int csoundModuleDestroy(CSOUND *csound) { - //csound->Message(csound, "signalflowgraph: CsoundModuleDestroy(%p)\n", csound); -#pragma omp critical (cs_sfg_ports) + if(csound->GetDebug(csound)) { + csound->Message(csound, "signalflowgraph: csoundModuleDestroy(%p)\n", csound); + } +//#pragma omp critical (cs_sfg_ports) + csound->LockMutex(cs_sfg_ports); { - aoutletsForCsoundsForSourceOutletIds[csound].clear(); - ainletsForCsoundsForSinkInletIds[csound].clear(); - //for (size_t i = 0, n = aoutletVectorsForCsounds[csound].size(); i < n; i++) { - // delete aoutletVectorsForCsounds[csound][i]; - //} - aoutletVectorsForCsounds[csound].clear(); - koutletsForCsoundsForSourceOutletIds[csound].clear(); - kinletsForCsoundsForSinkInletIds[csound].clear(); - //for (size_t i = 0, n = koutletVectorsForCsounds[csound].size(); i < n; i++) { - // delete koutletVectorsForCsounds[csound][i]; - //} - koutletVectorsForCsounds[csound].clear(); - foutletsForCsoundsForSourceOutletIds[csound].clear(); - finletsForCsoundsForSinkInletIds[csound].clear(); - //for (size_t i = 0, n = foutletVectorsForCsounds[csound].size(); i < n; i++) { - // delete foutletVectorsForCsounds[csound][i]; - //} - foutletVectorsForCsounds[csound].clear(); - connectionsForCsounds[csound].clear(); + if (aoutletsForCsoundsForSourceOutletIds.find(csound) != aoutletsForCsoundsForSourceOutletIds.end()) { + aoutletsForCsoundsForSourceOutletIds[csound].clear(); + } + if (ainletsForCsoundsForSinkInletIds.find(csound) != ainletsForCsoundsForSinkInletIds.end()) { + ainletsForCsoundsForSinkInletIds[csound].clear(); + } + if (aoutletVectorsForCsounds.find(csound) != aoutletVectorsForCsounds.end()) { + aoutletVectorsForCsounds[csound].clear(); + } + if (koutletsForCsoundsForSourceOutletIds.find(csound) != koutletsForCsoundsForSourceOutletIds.end()) { + koutletsForCsoundsForSourceOutletIds[csound].clear(); + } + if (kinletsForCsoundsForSinkInletIds.find(csound) != kinletsForCsoundsForSinkInletIds.end()) { + kinletsForCsoundsForSinkInletIds[csound].clear(); + } + if (koutletVectorsForCsounds.find(csound) != koutletVectorsForCsounds.end()) { + koutletVectorsForCsounds[csound].clear(); + } + if (foutletsForCsoundsForSourceOutletIds.find(csound) != foutletsForCsoundsForSourceOutletIds.end()) { + foutletsForCsoundsForSourceOutletIds[csound].clear(); + } + if (finletsForCsoundsForSinkInletIds.find(csound) != finletsForCsoundsForSinkInletIds.end()) { + finletsForCsoundsForSinkInletIds[csound].clear(); + } + if (foutletVectorsForCsounds.find(csound) != foutletVectorsForCsounds.end()) { + foutletVectorsForCsounds[csound].clear(); + } + if (connectionsForCsounds.find(csound) != connectionsForCsounds.end()) { + connectionsForCsounds[csound].clear(); + } } -#pragma omp critical (critical_section_ftables) + csound->UnlockMutex(cs_sfg_ports); +//#pragma omp critical (cs_sfg_ftables) + csound->LockMutex(cs_sfg_ftables); { - functionTablesForCsoundsForEvtblks[csound].clear(); + if (functionTablesForCsoundsForEvtblks.find(csound) != functionTablesForCsoundsForEvtblks.end()) { + functionTablesForCsoundsForEvtblks[csound].clear(); + } } + csound->UnlockMutex(cs_sfg_ftables); return 0; } } +} diff -Nru csound-5.17.11~dfsg/Opcodes/signalflowgraphtest.csd csound-6.02~dfsg/Opcodes/signalflowgraphtest.csd --- csound-5.17.11~dfsg/Opcodes/signalflowgraphtest.csd 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/signalflowgraphtest.csd 2014-01-07 16:54:20.000000000 +0000 @@ -1,6 +1,6 @@ -csound -m255 -RWfo signalflowgraphtest.wav +csound -m255 -RWfdo dac @@ -63,8 +63,8 @@ i 2 2 1 101 i 1 5 10 i 2 7 1 102 -i 2 12 1 101 -i 2 17 1 102 +i 2 12 1 101 +i 2 17 1 102 i 3 20 10 1 1 i 3 21 10 2 1 diff -Nru csound-5.17.11~dfsg/Opcodes/singwave.c csound-6.02~dfsg/Opcodes/singwave.c --- csound-5.17.11~dfsg/Opcodes/singwave.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/singwave.c 2014-01-07 16:53:48.000000000 +0000 @@ -80,7 +80,7 @@ { FUNC *ftp; - if ((ftp = csound->FTFind(csound,i)) != NULL) + if ((ftp = csound->FTnp2Find(csound,i)) != NULL) p->wave = ftp; else { /* Expect sine wave */ return csound->InitError(csound, Str("No table for Modulatr")); @@ -123,7 +123,7 @@ { FUNC *ftp; - if (LIKELY((ftp = csound->FTFind(csound,ifn)) != NULL)) p->wave = ftp; + if (LIKELY((ftp = csound->FTnp2Find(csound,ifn)) != NULL)) p->wave = ftp; else { return csound->InitError(csound, Str("No table for Singwave")); } @@ -155,7 +155,7 @@ p->rate = (MYFLT)p->wave->flen * aFreq * csound->onedsr; temp -= p->rate; - if (temp<0) temp = -temp; + temp = FABS(temp); Envelope_setTarget(&p->pitchEnvelope, p->rate); Envelope_setRate(csound, &p->pitchEnvelope, p->sweepRate * temp); // Envelope_print(csound, &p->pitchEnvelope); @@ -190,7 +190,7 @@ alpha = mytime - (MYFLT) temp; /* fractional part of time address */ temp1 = temp + 1; - if (temp1==p->wave->flen) temp1 = temp; /* Wrap!! */ + if (temp1==(int)p->wave->flen) temp1 = temp; /* Wrap!! */ lastOutput = alpha * p->wave->ftable[temp1]; /* Do linear */ // printf(" : (%d %d) %f %f ", temp, temp1, alpha, lastOutput); @@ -360,9 +360,9 @@ FormSwep_clear(p->filters[3]); { MYFLT temp, freq = *p->frequency; - if ((freq * FL(22.0)) > csound->esr) { - csound->Warning(csound,"This note is too high!!\n"); - freq = csound->esr / FL(22.0); + if ((freq * FL(22.0)) > CS_ESR) { + csound->Warning(csound, Str("This note is too high!!\n")); + freq = CS_ESR / FL(22.0); } p->basef = freq; temp = FABS(FL(1500.0) - freq) + FL(200.0); @@ -379,7 +379,9 @@ int voicform(CSOUND *csound, VOICF *p) { MYFLT *ar = p->ar; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (p->basef != *p->frequency) { p->basef = *p->frequency; @@ -400,7 +402,12 @@ } /* voicprint(csound, p); */ - for (n=0; nonepole, diff -Nru csound-5.17.11~dfsg/Opcodes/sndloop.c csound-6.02~dfsg/Opcodes/sndloop.c --- csound-5.17.11~dfsg/Opcodes/sndloop.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sndloop.c 2014-01-07 16:53:48.000000000 +0000 @@ -60,7 +60,8 @@ FLOOPER2 -asig flooper2 kamp, kpitch, kloopstart, kloopend, kcrossfade, ifn [, istart, imode, ifenv] +asig flooper2 kamp, kpitch, kloopstart, kloopend, kcrossfade, + ifn [, istart, imode, ifenv] Function-table crossfading looper with variable loop parameters and different looping modes. @@ -69,7 +70,8 @@ ifn - sound source function table. Non-power-of-two and deferred allocation tables are allowed. -istart - playback starting point in secs, only applicable to loop modes 0 & 2 [def:0] +istart - playback starting point in secs, only applicable to loop modes 0 & 2 + [def:0] imode - loop modes: 0 forward, 1 backward, 2 back-and-forth [def: 0] ifenv - if non-zero, crossfade envelope shape table number. 0, the default, sets the crossfade to linear. @@ -116,7 +118,7 @@ */ -#include "csdl.h" +#include "stdopcod.h" #include "pstream.h" typedef struct _sndloop { @@ -211,8 +213,8 @@ static int sndloop_init(CSOUND *csound, sndloop *p) { - p->durs = (int32) (*(p->dur)*csound->esr); /* dur in samps */ - p->cfds = (int32) (*(p->cfd)*csound->esr); /* fade in samps */ + p->durs = (int32) (*(p->dur)*CS_ESR); /* dur in samps */ + p->cfds = (int32) (*(p->cfd)*CS_ESR); /* fade in samps */ if (UNLIKELY(p->durs < p->cfds)) return csound->InitError(csound, Str("crossfade cannot be longer than loop\n")); @@ -229,7 +231,10 @@ static int sndloop_process(CSOUND *csound, sndloop *p) { - int i, on = (int) *(p->on), recon, n = csound->ksmps; + int on = (int) *(p->on), recon; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int32 durs = p->durs, cfds = p->cfds, wp = p->wp; double rp = p->rp; MYFLT a = p->a, inc = p->inc; @@ -239,7 +244,12 @@ if (on) recon = p->rst; /* restart recording if switched on again */ else recon = 0; /* else do not record */ - for (i=0; i < n; i++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset; i < nsmps; i++) { if (recon) { /* if the recording is ON */ /* fade in portion */ if (wp < cfds) { @@ -287,9 +297,9 @@ static int flooper_init(CSOUND *csound, flooper *p) { MYFLT *tab, *buffer, a = FL(0.0), inc; - int32 cfds = (int32) (*(p->cfd)*csound->esr); /* fade in samps */ - int32 starts = (int32) (*(p->start)*csound->esr); /* start in samps */ - int32 durs = (int32) (*(p->dur)*csound->esr); /* dur in samps */ + int32 cfds = (int32) (*(p->cfd)*CS_ESR); /* fade in samps */ + int32 starts = (int32) (*(p->start)*CS_ESR); /* start in samps */ + int32 durs = (int32) (*(p->dur)*CS_ESR); /* dur in samps */ int32 len, i; if (UNLIKELY(cfds > durs)) @@ -342,7 +352,9 @@ static int flooper_process(CSOUND *csound, flooper *p) { - int i, n = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int32 end = p->strts+p->durs, durs = p->durs; MYFLT *out = p->out, *buffer = p->buffer.auxp; MYFLT amp = *(p->amp), pitch = *(p->pitch); @@ -351,7 +363,12 @@ MYFLT frac; int tndx, loop_off = p->loop_off; - for (i=0; i < n; i++) { + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i=offset; i < nsmps; i++) { tndx = (int) ndx; frac = ndx - tndx; /* this is the start portion of the sound */ @@ -362,8 +379,8 @@ /* this is the loop section */ else { if (loop_off) { - ndx -= end; - tndx -= end; + while(ndx >= end) ndx -= end; + tndx = (int) ndx; /* wrap-around, if reading backwards */ while (tndx < 0) tndx += durs; } @@ -388,13 +405,13 @@ if (UNLIKELY(p->sfunc==NULL)) { return csound->InitError(csound,Str("function table not found\n")); } - if (*p->ifn2 != 0) p->efunc = csound->FTFind(csound, p->ifn2); + if (*p->ifn2 != 0) p->efunc = csound->FTnp2Find(csound, p->ifn2); else p->efunc = NULL; if (*p->iskip == 0){ p->mode = (int) *p->imode; if (p->mode == 0 || p->mode == 2){ - if ((p->ndx[0] = *p->start*csound->GetSr(csound)) < 0) + if ((p->ndx[0] = *p->start*CS_ESR) < 0) p->ndx[0] = 0; if (p->ndx[0] >= p->sfunc->flen) p->ndx[0] = (double) p->sfunc->flen - 1.0; @@ -409,18 +426,33 @@ static int flooper2_process(CSOUND *csound, flooper2 *p) { - int i, n = csound->ksmps; - MYFLT *out = p->out, sr = csound->GetSr(csound); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + MYFLT *out = p->out, sr = CS_ESR; MYFLT amp = *(p->amp), pitch = *(p->pitch); - MYFLT *tab = p->sfunc->ftable; + MYFLT *tab; double *ndx = p->ndx; MYFLT frac0, frac1, *etab; int loop_end = p->lend, loop_start = p->lstart, - crossfade = p->cfade, len = p->sfunc->flen; + crossfade = p->cfade, len; MYFLT count = p->count,fadein, fadeout; int *firsttime = &p->firsttime, elen, mode=p->mode, init = p->init, ijump = *p->ijump; uint32 tndx0, tndx1; + FUNC *func; + func = csound->FTnp2Find(csound, p->ifn); + + if(p->sfunc != func) { + p->sfunc = func; + if (UNLIKELY(func == NULL)) + return csound->PerfError(csound, p->h.insdshead, + Str("table %d invalid\n"), (int) *p->ifn); + if (p->ndx[0] >= p->sfunc->flen) + p->ndx[0] = (double) p->sfunc->flen - 1.0; + } + tab = p->sfunc->ftable; + len = p->sfunc->flen; if (p->efunc != NULL) { etab = p->efunc->ftable; @@ -433,9 +465,15 @@ /* loop parameters & check */ if (pitch < FL(0.0)) pitch = FL(0.0); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (*firsttime) { int loopsize; + /* offset non zero only if firsttime */ + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); loop_start = (int) (*p->loop_start*sr); loop_end = (int) (*p->loop_end*sr); p->lstart = loop_start = loop_start < 0 ? 0 : loop_start; @@ -473,7 +511,7 @@ } } - for (i=0; i < n; i++) { + for (i=offset; i < nsmps; i++) { if (mode == 1){ /* backwards */ tndx0 = (int) ndx[0]; frac0 = ndx[0] - tndx0; @@ -675,7 +713,7 @@ if (*p->iskip == 0){ p->mode = (int) *p->imode; if (p->mode == 0 || p->mode == 2){ - if ((p->ndx[0] = *p->start*csound->GetSr(csound)) < 0) + if ((p->ndx[0] = *p->start*CS_ESR) < 0) p->ndx[0] = 0; if (p->ndx[0] >= p->sfunc->flen) p->ndx[0] = p->sfunc->flen - 1.0; @@ -691,8 +729,11 @@ static int flooper3_process(CSOUND *csound, flooper3 *p) { - int i, n = csound->ksmps, lobits = p->lobits,si,ei; - MYFLT *out = p->out, sr = csound->GetSr(csound); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int lobits = p->lobits,si,ei; + MYFLT *out = p->out, sr = CS_ESR; MYFLT amp = *(p->amp), pitch = *(p->pitch); MYFLT *tab = p->sfunc->ftable, cvt; int32 *ndx = p->ndx, lomask = p->lomask, pos; @@ -703,10 +744,14 @@ int *firsttime = &p->firsttime, elen, init = p->init; uint32 tndx0, tndx1; - + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } if (pitch < FL(0.0)) pitch = FL(0.0); if (*firsttime) { int loopsize; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); loop_start = MYFLT2LRND(*p->loop_start*sr); loop_end = MYFLT2LRND (*p->loop_end*sr); p->lstart = loop_start = (loop_start < 0 ? 0 : loop_start); @@ -744,7 +789,7 @@ si = MYFLT2LRND(pitch*(lomask)); ei = MYFLT2LRND(pitch*(lomask)); - for (i=0; i < n; i++) { + for (i=offset; i < nsmps; i++) { if (mode == 0){ tndx0 = ndx[0]>>lobits; frac0 = (ndx[0] & lomask)*lodiv; @@ -905,11 +950,13 @@ loop_start = MYFLT2LRND(*p->loop_start*sr); loop_end = MYFLT2LRND(*p->loop_end*sr); p->lstart = loop_start = (loop_start < 0 ? 0 : loop_start); - p->lend = loop_end = (loop_end > len ? len : - (loop_end < loop_start ? loop_start : loop_end)); + p->lend = loop_end = + (loop_end > len ? len : + (loop_end < loop_start ? loop_start : loop_end)); loopsize = (loop_end - loop_start); crossfade = MYFLT2LRND(*p->crossfade*sr); - p->cfade = crossfade = crossfade > loopsize/2 ? loopsize/2-1 : crossfade; + p->cfade = crossfade = + crossfade > loopsize/2 ? loopsize/2-1 : crossfade; cvt = (MYFLT)elen/p->cfade; } } @@ -972,7 +1019,8 @@ return OK; err1: - return csound->PerfError(csound,Str("pvsarp: not initialised\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsarp: not initialised\n")); } static int pvsvoc_init(CSOUND *csound, pvsvoc *p) @@ -1010,6 +1058,9 @@ return OK; } +void csoundComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize); +void csoundInverseComplexFFTnp2(CSOUND *csound, MYFLT *buf, int FFTsize); + static int pvsvoc_process(CSOUND *csound, pvsvoc *p) { int32 i,N = p->fout->N; @@ -1027,40 +1078,48 @@ if (UNLIKELY(fout==NULL)) goto err1; if (p->lastframe < p->fin->framecount) { - for(j=0; j < 2; j++) { + int tmp = N/2; + tmp = tmp + tmp%2; + for (j=0; j < 2; j++) { MYFLT a; maxe = 0.f; maxa = 0.f; - for(i=0; i < N; i+=2) { - a = (j ? fin[i] : (fexc[i] = ffr[i])); - maxa = maxa < a ? a : maxa; - if (a <= 0) a = 1e-20; - fenv[i/2] = log(a); - } - if (coefs < 1) coefs = 80; - for(i=0; i < N; i+=2){ + for (i=0; i < N; i+=2) { + a = (j ? fin[i] : (fexc[i] = ffr[i])); + maxa = maxa < a ? a : maxa; + if (a <= 0) a = 1e-20; + fenv[i/2] = log(a); + } + if (coefs < 1) coefs = 80; + for (i=0; i < N; i+=2){ ceps[i] = fenv[i/2]; ceps[i+1] = 0.0; } - csound->InverseComplexFFT(csound, ceps, N/2); - for(i=coefs; i < N-coefs; i++) ceps[i] = 0.0; - csound->ComplexFFT(csound, ceps, N/2); - for(i=0; i < N; i+=2) { + if (!(N & (N - 1))) + csound->InverseComplexFFT(csound, ceps, N/2); + else + csoundInverseComplexFFTnp2(csound, ceps, tmp); + for (i=coefs; i < N-coefs; i++) ceps[i] = 0.0; + if (!(N & (N - 1))) + csound->ComplexFFT(csound, ceps, N/2); + else + csoundComplexFFTnp2(csound, ceps, tmp); + for (i=0; i < N; i+=2) { fenv[i/2] = exp(ceps[i]); - maxe = maxe < fenv[i/2] ? fenv[i/2] : maxe; + maxe = maxe < fenv[i/2] ? fenv[i/2] : maxe; } if (maxe) - for(i=0; i= 0 ? (kdepth <= 1 ? kdepth : FL(1.0)): FL(0.0); - for(i=0;i < N+2;i+=2) { + for (i=0;i < N+2;i+=2) { fout[i] = fenv[i/2]*(fexc[i]*kdepth + fin[i]*(FL(1.0)-kdepth))*gain; fout[i+1] = ffr[i+1]*(kdepth) + fin[i+1]*(FL(1.0)-kdepth); } @@ -1069,7 +1128,8 @@ return OK; err1: - return csound->PerfError(csound,Str("pvsvoc: not initialised\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsvoc: not initialised\n")); } static int pvsmorph_init(CSOUND *csound, pvsmorph *p) @@ -1120,23 +1180,24 @@ return OK; err1: - return csound->PerfError(csound,Str("pvsmorph: not initialised\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("pvsmorph: not initialised\n")); } static OENTRY localops[] = { - {"sndloop", sizeof(sndloop), 5, + {"sndloop", sizeof(sndloop),0, 5, "ak", "akkii", (SUBR)sndloop_init, NULL, (SUBR)sndloop_process}, - {"flooper", sizeof(flooper), TR|5, + {"flooper", sizeof(flooper), TR, 5, "a", "kkiiii", (SUBR)flooper_init, NULL, (SUBR)flooper_process}, - {"pvsarp", sizeof(pvsarp), 3, + {"pvsarp", sizeof(pvsarp), 0,3, "f", "fkkk", (SUBR)pvsarp_init, (SUBR)pvsarp_process}, - {"pvsvoc", sizeof(pvsvoc), 3, + {"pvsvoc", sizeof(pvsvoc), 0,3, "f", "ffkkO", (SUBR)pvsvoc_init, (SUBR)pvsvoc_process}, - {"flooper2", sizeof(flooper2), TR|5, + {"flooper2", sizeof(flooper2), TR, 5, "a", "kkkkkiooooO", (SUBR)flooper2_init, NULL, (SUBR)flooper2_process}, - /* {"flooper3", sizeof(flooper3), TR|5, + /* {"flooper3", sizeof(flooper3), TR, 5, "a", "kkkkkioooo", (SUBR)flooper3_init, NULL, (SUBR)flooper3_process},*/ - {"pvsmorph", sizeof(pvsvoc), 3, + {"pvsmorph", sizeof(pvsvoc), 0,3, "f", "ffkk", (SUBR)pvsmorph_init, (SUBR)pvsmorph_process} }; diff -Nru csound-5.17.11~dfsg/Opcodes/sndwarp.c csound-6.02~dfsg/Opcodes/sndwarp.c --- csound-5.17.11~dfsg/Opcodes/sndwarp.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sndwarp.c 2014-01-07 16:53:48.000000000 +0000 @@ -29,7 +29,7 @@ /*from soundfiles. */ /**************************************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "sndwarp.h" #define unirand(x) ((MYFLT) (x->Rand31(&(x->randSeed1)) - 1) / FL(2147483645.0)) @@ -53,17 +53,19 @@ } p->exp = (WARPSECTION *)auxp; - if (UNLIKELY((ftpSamp = csound->FTFind(csound, p->isampfun)) == NULL)) return NOTOK; + if (UNLIKELY((ftpSamp = csound->FTnp2Find(csound, p->isampfun)) == NULL)) + return NOTOK; p->ftpSamp = ftpSamp; p->sampflen = ftpSamp->flen; - if (UNLIKELY((ftpWind = csound->FTFind(csound, p->ifn)) == NULL)) return NOTOK; + if (UNLIKELY((ftpWind = csound->FTnp2Find(csound, p->ifn)) == NULL)) + return NOTOK; p->ftpWind = ftpWind; p->flen = ftpWind->flen; p->maxFr = -1 + ftpSamp->flen; p->prFlg = 1; /* true */ - p->begin = (int)(*p->ibegin * csound->esr); + p->begin = (int)(*p->ibegin * CS_ESR); exp = p->exp; iwsize = *p->iwsize; @@ -91,7 +93,9 @@ static int sndwarp(CSOUND *csound, SNDWARP *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT frm_0,frm_1; int32 base, longphase; MYFLT frac, frIndx; @@ -118,18 +122,27 @@ ftpSamp = p->ftpSamp; for (i=0; iksmps; */ +/* nsmps = CS_KSMPS; */ /* r1 = p->r1; */ /* if (p->OUTOCOUNT >1) r2 = p->r2; */ resample = p->xresample; timewarpby = p->xtimewarp; amp = p->xamp; - for (n=0; nOUTOCOUNT >1) memset(r2, '\0', offset*sizeof(MYFLT)); + } + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r1[nsmps], '\0', early*sizeof(MYFLT)); + if (p->OUTOCOUNT >1) memset(&r2[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nitimemode!=0) - exp[i].offset=(csound->esr * *timewarpby)+p->begin; + exp[i].offset=(CS_ESR * *timewarpby)+p->begin; else exp[i].offset += (MYFLT)exp[i].wsize/(*timewarpby); @@ -180,7 +193,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("sndwarp: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("sndwarp: not initialised")); } /****************************************************************/ @@ -210,19 +224,19 @@ } p->exp = (WARPSECTION *)auxp; - if (UNLIKELY((ftpSamp = csound->FTFind(csound, p->isampfun)) == NULL)) + if (UNLIKELY((ftpSamp = csound->FTnp2Find(csound, p->isampfun)) == NULL)) return NOTOK; p->ftpSamp = ftpSamp; p->sampflen=ftpSamp->flen; - if (UNLIKELY((ftpWind = csound->FTFind(csound, p->ifn)) == NULL)) + if (UNLIKELY((ftpWind = csound->FTnp2Find(csound, p->ifn)) == NULL)) return NOTOK; p->ftpWind = ftpWind; p->flen=ftpWind->flen; p->maxFr = -1L + (int32)(ftpSamp->flen*FL(0.5)); p->prFlg = 1; /* true */ - p->begin = (int)(*p->ibegin * csound->esr); + p->begin = (int)(*p->ibegin * CS_ESR); iwsize = *p->iwsize; exp = p->exp; for (i=0; i< nsections; i++) { @@ -254,7 +268,9 @@ static int sndwarpst(CSOUND *csound, SNDWARPST *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT frm10,frm11, frm20, frm21; int32 base, longphase; MYFLT frac, frIndx; @@ -280,17 +296,17 @@ exp = p->exp; ftpWind = p->ftpWind; ftpSamp = p->ftpSamp; - + if (UNLIKELY(early)) nsmps -= early; for (i=0; i<*p->ioverlap; i++) { resample = p->xresample; timewarpby = p->xtimewarp; amp = p->xamp; - for (n=0; nitimemode!=0) - exp[i].offset=(csound->esr * *timewarpby)+p->begin; + exp[i].offset=(CS_ESR * *timewarpby)+p->begin; else exp[i].offset += (MYFLT)exp[i].wsize/(*timewarpby); @@ -349,15 +365,16 @@ } return OK; err1: - return csound->PerfError(csound, Str("sndwarpst: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("sndwarpst: not initialised")); } #define S(x) sizeof(x) static OENTRY localops[] = { - { "sndwarp", S(SNDWARP), TR|5, "mm", "xxxiiiiiii", + { "sndwarp", S(SNDWARP), TR, 5, "mm", "xxxiiiiiii", (SUBR)sndwarpgetset, NULL, (SUBR)sndwarp}, - { "sndwarpst", S(SNDWARPST), TR|5, "mmmm","xxxiiiiiii", + { "sndwarpst", S(SNDWARPST), TR, 5, "mmmm","xxxiiiiiii", (SUBR)sndwarpstset,NULL,(SUBR)sndwarpst} }; diff -Nru csound-5.17.11~dfsg/Opcodes/sockrecv.c csound-6.02~dfsg/Opcodes/sockrecv.c --- csound-5.17.11~dfsg/Opcodes/sockrecv.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/sockrecv.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "csoundCore.h" #include #include #include @@ -48,7 +48,9 @@ typedef struct { OPDS h; - MYFLT *asig, *ipaddress, *port; + MYFLT *asig; + STRINGDAT *ipaddress; + MYFLT *port; AUXCH aux, tmp; int sock, conn; struct sockaddr_in server_addr; @@ -62,12 +64,12 @@ AUXCH buffer, tmp; MYFLT *buf; int sock; - int wp, rp, wbufferuse, rbufferuse, canread; volatile int threadon; - int usedbuf[MAXBUFS]; - int bufnos, bufsamps[MAXBUFS]; + int buffsize; + int outsamps, rcvsamps; CSOUND *cs; void *thrid; + void *cb; struct sockaddr_in server_addr; } SOCKRECV; @@ -86,30 +88,23 @@ socklen_t clilen = sizeof(from); SOCKRECV *p = (SOCKRECV *) pdata; MYFLT *tmp = (MYFLT *) p->tmp.auxp; - MYFLT *buf; - int i, bytes, n, bufnos = p->bufnos; + int bytes; + CSOUND *csound = p->cs; while (p->threadon) { /* get the data from the socket and store it in a tmp buffer */ - if ((bytes = recvfrom(p->sock, (void *)tmp, MTU, 0, &from, &clilen))) { - p->wbufferuse++; - p->wbufferuse = (p->wbufferuse == bufnos ? 0 : p->wbufferuse); - buf = (MYFLT *) ((char *) p->buffer.auxp + (p->wbufferuse * MTU)); - p->usedbuf[p->wbufferuse] = 1; - p->bufsamps[p->wbufferuse] = n = bytes / sizeof(MYFLT); - for (i = 0; i < n; i++) - buf[i] = tmp[i]; - p->canread = 1; + if ((bytes = recvfrom(p->sock, (void *)tmp, MTU, 0, &from, &clilen)) > 0) { + csound->WriteCircularBuffer(csound, p->cb, tmp, bytes/sizeof(MYFLT)); } } return (uintptr_t) 0; } + /* UDP version one channel */ static int init_recv(CSOUND *csound, SOCKRECV *p) { MYFLT *buf; - int bufnos; #ifdef WIN32 WSADATA wsaData = {0}; int err; @@ -117,15 +112,11 @@ csound->InitError(csound, Str("Winsock2 failed to start: %d"), err); #endif - p->wp = 0; - p->rp = 0; p->cs = csound; - p->bufnos = *p->ptr3; - if (p->bufnos > MAXBUFS) - p->bufnos = MAXBUFS; - bufnos = p->bufnos; - p->sock = socket(AF_INET, SOCK_DGRAM, 0); +#ifndef WIN32 + fcntl(p->sock, F_SETFL, O_NONBLOCK); +#endif if (UNLIKELY(p->sock < 0)) { return csound->InitError (csound, Str("creating socket")); @@ -140,12 +131,12 @@ sizeof(p->server_addr)) < 0)) return csound->InitError(csound, Str("bind failed")); - if (p->buffer.auxp == NULL || (long) (MTU * bufnos) > p->buffer.size) + if (p->buffer.auxp == NULL || (unsigned long) (MTU) > p->buffer.size) /* allocate space for the buffer */ - csound->AuxAlloc(csound, MTU * bufnos, &p->buffer); + csound->AuxAlloc(csound, MTU, &p->buffer); else { buf = (MYFLT *) p->buffer.auxp; /* make sure buffer is empty */ - memset(buf, 0, MTU * bufnos); + memset(buf, 0, MTU); } /* create a buffer to store the received interleaved audio data */ if (p->tmp.auxp == NULL || (long) p->tmp.size < MTU) @@ -155,59 +146,60 @@ buf = (MYFLT *) p->tmp.auxp; /* make sure buffer is empty */ memset(buf, 0, MTU); } - + p->buffsize = p->buffer.size/sizeof(MYFLT); + p->cb = csound->CreateCircularBuffer(csound, *p->ptr3, sizeof(MYFLT)); /* create thread */ + p->threadon = 1; p->thrid = csound->CreateThread(udpRecv, (void *) p); csound->RegisterDeinitCallback(csound, (void *) p, deinit_udpRecv); - p->threadon = 1; - memset(p->usedbuf, 0, bufnos * sizeof(int)); - memset(p->bufsamps, 0, bufnos * sizeof(int)); p->buf = p->buffer.auxp; - p->rbufferuse = p->wbufferuse = 0; - p->canread = 0; + p->outsamps = p->rcvsamps = 0; + return OK; +} +static int send_recv_k(CSOUND *csound, SOCKRECV *p) +{ + MYFLT *ksig = p->ptr1; + *ksig = FL(0.0); + if(p->outsamps >= p->rcvsamps){ + p->outsamps = 0; + p->rcvsamps = + csound->ReadCircularBuffer(csound, p->cb, p->buf, p->buffsize); + } + *ksig = p->buf[p->outsamps++]; return OK; } + static int send_recv(CSOUND *csound, SOCKRECV *p) { MYFLT *asig = p->ptr1; MYFLT *buf = p->buf; - int i, n, ksmps = csound->ksmps; - int *bufsamps = p->bufsamps; - int bufnos = p->bufnos; - - if (p->canread) { - for (i = 0, n = p->rp; i < ksmps; i++, n++) { - if (n == bufsamps[p->rbufferuse]) { - p->usedbuf[p->rbufferuse] = 0; - p->rbufferuse++; - p->rbufferuse = (p->rbufferuse == bufnos ? 0 : p->rbufferuse); - buf = (MYFLT *) ((char *) p->buffer.auxp + (p->rbufferuse * MTU)); - n = 0; - if (p->usedbuf[p->rbufferuse] == 0) { - p->canread = 0; - break; - } - } - asig[i] = buf[n]; + int i, nsmps = CS_KSMPS; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + int outsamps = p->outsamps, rcvsamps = p->rcvsamps; + memset(asig, 0, sizeof(MYFLT)*nsmps); + if (UNLIKELY(early)) nsmps -= early; + + for(i=offset; i < nsmps ; i++){ + if(outsamps >= rcvsamps){ + outsamps = 0; + rcvsamps = csound->ReadCircularBuffer(csound, p->cb, buf, p->buffsize); } - p->rp = n; - p->buf = buf; - } - else { - memset(asig, 0, sizeof(MYFLT)*ksmps); - /* for (i = 0; i < ksmps; i++) */ - /* asig[i] = FL(0.0); */ + asig[i] = buf[outsamps]; + outsamps++; } + p->rcvsamps = rcvsamps; + p->outsamps = outsamps; return OK; } + /* UDP version two channel */ static int init_recvS(CSOUND *csound, SOCKRECV *p) { MYFLT *buf; - int bufnos; #ifdef WIN32 WSADATA wsaData = {0}; int err; @@ -215,14 +207,11 @@ csound->InitError(csound, Str("Winsock2 failed to start: %d"), err); #endif - p->wp = 0; - p->rp = 0; p->cs = csound; - p->bufnos = *p->ptr4; - if (p->bufnos > MAXBUFS) - p->bufnos = MAXBUFS; - bufnos = p->bufnos; p->sock = socket(AF_INET, SOCK_DGRAM, 0); +#ifndef WIN32 + fcntl(p->sock, F_SETFL, O_NONBLOCK); +#endif if (UNLIKELY(p->sock < 0)) { return csound->InitError(csound, Str("creating socket")); } @@ -236,12 +225,12 @@ sizeof(p->server_addr)) < 0)) return csound->InitError(csound, Str("bind failed")); - if (p->buffer.auxp == NULL || (long) (MTU * bufnos) > p->buffer.size) + if (p->buffer.auxp == NULL || (unsigned long) (MTU) > p->buffer.size) /* allocate space for the buffer */ - csound->AuxAlloc(csound, MTU * bufnos, &p->buffer); + csound->AuxAlloc(csound, MTU, &p->buffer); else { buf = (MYFLT *) p->buffer.auxp; /* make sure buffer is empty */ - memset(buf, 0, MTU * bufnos); + memset(buf, 0, MTU); } /* create a buffer to store the received interleaved audio data */ if (p->tmp.auxp == NULL || (long) p->tmp.size < MTU) @@ -251,17 +240,14 @@ buf = (MYFLT *) p->tmp.auxp; /* make sure buffer is empty */ memset(buf, 0, MTU); } - + p->cb = csound->CreateCircularBuffer(csound, *p->ptr4, sizeof(MYFLT)); /* create thread */ + p->threadon = 1; p->thrid = csound->CreateThread(udpRecv, (void *) p); csound->RegisterDeinitCallback(csound, (void *) p, deinit_udpRecv); - p->threadon = 1; - memset(p->usedbuf, 0, bufnos * sizeof(int)); - memset(p->bufsamps, 0, bufnos * sizeof(int)); p->buf = p->buffer.auxp; - p->rbufferuse = p->wbufferuse = 0; - p->canread = 0; - + p->outsamps = p->rcvsamps = 0; + p->buffsize = p->buffer.size/sizeof(MYFLT); return OK; } @@ -270,37 +256,26 @@ MYFLT *asigl = p->ptr1; MYFLT *asigr = p->ptr2; MYFLT *buf = p->buf; - int i, n, ksmps = csound->ksmps; - int *bufsamps = p->bufsamps; - int bufnos = p->bufnos; - - if (p->canread) { - for (i = 0, n = p->rp; i < ksmps; i++, n += 2) { - if (n == bufsamps[p->rbufferuse]) { - p->usedbuf[p->rbufferuse] = 0; - p->rbufferuse++; - p->rbufferuse = (p->rbufferuse == bufnos ? 0 : p->rbufferuse); - buf = (MYFLT *) ((char *) p->buffer.auxp + (p->rbufferuse * MTU)); - n = 0; - if (p->usedbuf[p->rbufferuse] == 0) { - p->canread = 0; - break; - } - } - asigl[i] = buf[n]; - asigr[i] = buf[n + 1]; + int i, nsmps = CS_KSMPS; + int outsamps = p->outsamps, rcvsamps = p->rcvsamps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + + memset(asigl, 0, sizeof(MYFLT)*nsmps); + memset(asigr, 0, sizeof(MYFLT)*nsmps); + + if (UNLIKELY(early)) nsmps -= early; + for(i=offset; i < nsmps ; i++){ + if(outsamps >= rcvsamps){ + outsamps = 0; + rcvsamps = csound->ReadCircularBuffer(csound, p->cb, buf, p->buffsize); } - p->rp = n; - p->buf = buf; - } - else { - memset(asigl, 0, sizeof(MYFLT)*ksmps); - memset(asigr, 0, sizeof(MYFLT)*ksmps); - /* for (i = 0; i < ksmps; i++) { */ - /* asigl[i] = FL(0.0); */ - /* asigr[i] = FL(0.0); */ - /* } */ - } + asigl[i] = buf[outsamps++]; + asigr[i] = buf[outsamps++]; + } + p->rcvsamps = rcvsamps; + p->outsamps = outsamps; + return OK; } @@ -331,9 +306,10 @@ /* the server IP address, in network byte order */ #ifdef WIN32 - p->server_addr.sin_addr.S_un.S_addr = inet_addr((const char *) p->ipaddress); + p->server_addr.sin_addr.S_un.S_addr = + inet_addr((const char *) p->ipaddress->data); #else - inet_aton((const char *) p->ipaddress, &(p->server_addr.sin_addr)); + inet_aton((const char *) p->ipaddress->data, &(p->server_addr.sin_addr)); #endif /* the port we are going to listen on, in network byte order */ p->server_addr.sin_port = htons((int) *p->port); @@ -360,10 +336,11 @@ static int send_srecv(CSOUND *csound, SOCKRECVT *p) { - int n = sizeof(MYFLT) * csound->ksmps; + int n = sizeof(MYFLT) * CS_KSMPS; - if (UNLIKELY(n != read(p->conn, p->asig, sizeof(MYFLT) * csound->ksmps))) { - return csound->PerfError(csound, Str("read from socket failed")); + if (UNLIKELY(n != read(p->conn, p->asig, sizeof(MYFLT) * CS_KSMPS))) { + return csound->PerfError(csound, p->h.insdshead, + Str("read from socket failed")); } return OK; } @@ -371,13 +348,12 @@ #define S(x) sizeof(x) static OENTRY sockrecv_localops[] = { - { "sockrecv", S(SOCKRECV), 5, "a", "ii", (SUBR) init_recv, NULL, + { "sockrecv", S(SOCKRECV), 0, 7, "a", "ii", (SUBR) init_recv, (SUBR) send_recv_k, (SUBR) send_recv }, - { "sockrecvs", S(SOCKRECV), 5, "aa", "ii", (SUBR) init_recvS, NULL, + { "sockrecvs", S(SOCKRECV), 0, 5, "aa", "ii", (SUBR) init_recvS, NULL, (SUBR) send_recvS }, - { "strecv", S(SOCKRECVT), 5, "a", "Si", (SUBR) init_srecv, NULL, + { "strecv", S(SOCKRECVT), 0, 5, "a", "Si", (SUBR) init_srecv, NULL, (SUBR) send_srecv } }; -LINKAGE1(sockrecv_localops) - +LINKAGE_BUILTIN(sockrecv_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/socksend.c csound-6.02~dfsg/Opcodes/socksend.c --- csound-5.17.11~dfsg/Opcodes/socksend.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/socksend.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,11 +21,10 @@ 02111-1307 USA */ -#include "csdl.h" +#include "csoundCore.h" #include #ifdef WIN32 #include -#include #else #include #include @@ -40,7 +39,9 @@ typedef struct { OPDS h; - MYFLT *asig, *ipaddress, *port, *buffersize; + MYFLT *asig; + STRINGDAT *ipaddress; + MYFLT *port, *buffersize; MYFLT *format; AUXCH aux; int sock; @@ -51,7 +52,9 @@ typedef struct { OPDS h; - MYFLT *asigl, *asigr, *ipaddress, *port, *buffersize; + MYFLT *asigl, *asigr; + STRINGDAT *ipaddress; +MYFLT *port, *buffersize; MYFLT *format; AUXCH aux; int sock; @@ -76,7 +79,8 @@ p->ff = (int)(*p->format); p->bsize = bsize = (int) *p->buffersize; /* if (UNLIKELY((sizeof(MYFLT) * bsize) > MTU)) { */ - /* return csound->InitError(csound, Str("The buffersize must be <= %d samples " */ + /* return csound->InitError(csound, + Str("The buffersize must be <= %d samples " */ /* "to fit in a udp-packet."), */ /* (int) (MTU / sizeof(MYFLT))); */ /* } */ @@ -90,16 +94,17 @@ memset(&p->server_addr, 0, sizeof(p->server_addr)); p->server_addr.sin_family = AF_INET; /* it is an INET address */ #ifdef WIN32 - p->server_addr.sin_addr.S_un.S_addr = inet_addr((const char *) p->ipaddress); + p->server_addr.sin_addr.S_un.S_addr = + inet_addr((const char *) p->ipaddress->data); #else - inet_aton((const char *) p->ipaddress, + inet_aton((const char *) p->ipaddress->data, &p->server_addr.sin_addr); /* the server IP address */ #endif p->server_addr.sin_port = htons((int) *p->port); /* the port */ if (p->ff) bwidth = sizeof(int16); /* create a buffer to write the interleaved audio to */ - if (p->aux.auxp == NULL || (long) (bsize * bwidth) > p->aux.size) + if (p->aux.auxp == NULL || (uint32_t) (bsize * bwidth) > p->aux.size) /* allocate space for the buffer */ csound->AuxAlloc(csound, (bsize * bwidth), &p->aux); else { @@ -112,19 +117,23 @@ static int send_send(CSOUND *csound, SOCKSEND *p) { const struct sockaddr *to = (const struct sockaddr *) (&p->server_addr); - int i, wp, ksmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int wp; int buffersize = p->bsize; MYFLT *asig = p->asig; MYFLT *out = (MYFLT *) p->aux.auxp; int16 *outs = (int16 *) p->aux.auxp; int ff = p->ff; - for (i = 0, wp = p->wp; i < ksmps; i++, wp++) { + if (UNLIKELY(early)) nsmps -= early; + for (i = offset, wp = p->wp; i < nsmps; i++, wp++) { if (wp == buffersize) { /* send the package when we have a full buffer */ if (UNLIKELY(sendto(p->sock, (void*)out, buffersize * p->bwidth, 0, to, sizeof(p->server_addr)) < 0)) { - return csound->PerfError(csound, Str("sendto failed")); + return csound->PerfError(csound, p->h.insdshead, Str("sendto failed")); } wp = 0; } @@ -146,6 +155,42 @@ return OK; } +static int send_send_k(CSOUND *csound, SOCKSEND *p) +{ + const struct sockaddr *to = (const struct sockaddr *) (&p->server_addr); + + int buffersize = p->bsize; + MYFLT *ksig = p->asig; + MYFLT *out = (MYFLT *) p->aux.auxp; + int16 *outs = (int16 *) p->aux.auxp; + int ff = p->ff; + + + if (p->wp == buffersize) { + /* send the package when we have a full buffer */ + if (UNLIKELY(sendto(p->sock, (void*)out, buffersize * p->bwidth, 0, to, + sizeof(p->server_addr)) < 0)) { + return csound->PerfError(csound, p->h.insdshead, Str("sendto failed")); + } + p->wp = 0; + } + if (ff) { // Scale for 0dbfs and make LE + int16 val = (int16)((32768.0* (*ksig))/csound->e0dbfs); + union cheat { + char benchar[2]; + int16 bensht; + } ch; + ch.benchar[0] = 0xFF & val; + ch.benchar[1] = 0xFF & (val >> 8); + outs[p->wp] = ch.bensht; + } + else out[p->wp++] = *ksig; + + return OK; +} + + + /* UDP version 2 channels */ static int init_sendS(CSOUND *csound, SOCKSENDS *p) { @@ -161,7 +206,8 @@ p->ff = (int)(*p->format); p->bsize = bsize = (int) *p->buffersize; /* if (UNLIKELY((sizeof(MYFLT) * bsize) > MTU)) { */ - /* return csound->InitError(csound, Str("The buffersize must be <= %d samples " */ + /* return csound->InitError(csound, + Str("The buffersize must be <= %d samples " */ /* "to fit in a udp-packet."), */ /* (int) (MTU / sizeof(MYFLT))); */ /* } */ @@ -175,16 +221,17 @@ memset(&p->server_addr, 0, sizeof(p->server_addr)); p->server_addr.sin_family = AF_INET; /* it is an INET address */ #ifdef WIN32 - p->server_addr.sin_addr.S_un.S_addr = inet_addr((const char *) p->ipaddress); + p->server_addr.sin_addr.S_un.S_addr = + inet_addr((const char *) p->ipaddress->data); #else - inet_aton((const char *) p->ipaddress, + inet_aton((const char *) p->ipaddress->data, &p->server_addr.sin_addr); /* the server IP address */ #endif p->server_addr.sin_port = htons((int) *p->port); /* the port */ if (p->ff) bwidth = sizeof(int16); /* create a buffer to write the interleaved audio to */ - if (p->aux.auxp == NULL || (long) (bsize * bwidth) > p->aux.size) + if (p->aux.auxp == NULL || (uint32_t) (bsize * bwidth) > p->aux.size) /* allocate space for the buffer */ csound->AuxAlloc(csound, (bsize * bwidth), &p->aux); else { @@ -201,19 +248,22 @@ MYFLT *asigr = p->asigr; MYFLT *out = (MYFLT *) p->aux.auxp; int16 *outs = (int16 *) p->aux.auxp; - int i; + int wp; int buffersize = p->bsize; - int wp, ksmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int ff = p->ff; + if (UNLIKELY(early)) nsmps -= early; /* store the samples of the channels interleaved in the packet */ /* (left, right) */ - for (i = 0, wp = p->wp; i < ksmps; i++, wp += 2) { + for (i = offset, wp = p->wp; i < nsmps; i++, wp += 2) { if (wp == buffersize) { /* send the package when we have a full buffer */ if (UNLIKELY(sendto(p->sock, (void*)out, buffersize * p->bwidth, 0, to, sizeof(p->server_addr)) < 0)) { - return csound->PerfError(csound, Str("sendto failed")); + return csound->PerfError(csound, p->h.insdshead, Str("sendto failed")); } wp = 0; } @@ -269,9 +319,10 @@ /* the server IP address, in network byte order */ #ifdef WIN32 - p->server_addr.sin_addr.S_un.S_addr = inet_addr((const char *) p->ipaddress); + p->server_addr.sin_addr.S_un.S_addr = + inet_addr((const char *) p->ipaddress->data); #else - inet_aton((const char *) p->ipaddress, &(p->server_addr.sin_addr)); + inet_aton((const char *) p->ipaddress->data, &(p->server_addr.sin_addr)); #endif /* the port we are going to listen on, in network byte order */ @@ -292,12 +343,15 @@ static int send_ssend(CSOUND *csound, SOCKSEND *p) { - int n = sizeof(MYFLT) * csound->ksmps; - - if (n != write(p->sock, p->asig, n)) { - csound->Message(csound, "Expected %d got %d\n", - (int) (sizeof(MYFLT) * csound->ksmps), n); - return csound->PerfError(csound, Str("write to socket failed")); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n = sizeof(MYFLT) * (CS_KSMPS-offset-early); + + if (n != write(p->sock, &p->asig[offset], n)) { + csound->Message(csound, Str("Expected %d got %d\n"), + (int) (sizeof(MYFLT) * CS_KSMPS), n); + return csound->PerfError(csound, p->h.insdshead, + Str("write to socket failed")); } return OK; @@ -306,12 +360,14 @@ #define S(x) sizeof(x) static OENTRY socksend_localops[] = { - { "socksend", S(SOCKSEND), 5, "", "aSiio", (SUBR) init_send, NULL, + { "socksend", S(SOCKSEND), 0, 5, "", "aSiio", (SUBR) init_send, NULL, (SUBR) send_send }, - { "socksends", S(SOCKSENDS), 5, "", "aaSiio", (SUBR) init_sendS, NULL, + { "socksend_k", S(SOCKSEND), 0, 3, "", "kSiio", (SUBR) init_send, + (SUBR) send_send_k, NULL }, + { "socksends", S(SOCKSENDS), 0, 5, "", "aaSiio", (SUBR) init_sendS, NULL, (SUBR) send_sendS }, - { "stsend", S(SOCKSEND), 5, "", "aSi", (SUBR) init_ssend, NULL, + { "stsend", S(SOCKSEND), 0, 5, "", "aSi", (SUBR) init_ssend, NULL, (SUBR) send_ssend } }; -LINKAGE1(socksend_localops) +LINKAGE_BUILTIN(socksend_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/space.c csound-6.02~dfsg/Opcodes/space.c --- csound-5.17.11~dfsg/Opcodes/space.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/space.c 2014-01-07 16:53:48.000000000 +0000 @@ -27,7 +27,7 @@ /* University of Washington, Seattle 1998 */ /******************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "space.h" #include @@ -45,15 +45,15 @@ } if (p->auxch.auxp == NULL || - p->auxch.sizeksmps * 4)) { + p->auxch.sizeAuxAlloc(csound, (size_t) (csound->ksmps * 4) + csound->AuxAlloc(csound, (size_t) (CS_KSMPS * 4) * sizeof(MYFLT), &p->auxch); fltp = (MYFLT *) p->auxch.auxp; - p->rrev1 = fltp; fltp += csound->ksmps; - p->rrev2 = fltp; fltp += csound->ksmps; - p->rrev3 = fltp; fltp += csound->ksmps; - p->rrev4 = fltp; fltp += csound->ksmps; + p->rrev1 = fltp; fltp += CS_KSMPS; + p->rrev2 = fltp; fltp += CS_KSMPS; + p->rrev3 = fltp; fltp += CS_KSMPS; + p->rrev4 = fltp; fltp += CS_KSMPS; } pp = (STDOPCOD_GLOBALS*) csound->stdOp_Env; @@ -71,11 +71,12 @@ MYFLT half_pi = FL(0.5)*PI_F; MYFLT sqrt2 = SQRT(FL(2.0)); MYFLT fabxndx, fabyndx; - int n; FUNC *ftp; int32 indx, length, halflen; MYFLT v1, v2, fract, ndx; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; if (*p->ifn > 0) { /* get xy vals from function table */ if (UNLIKELY((ftp = p->ftp) == NULL)) goto err1; @@ -146,7 +147,20 @@ rrev3 = p->rrev3; rrev4 = p->rrev4; sigp = p->asig; - for (n=0; nreverbamount; globalrev = torev * distr; @@ -162,7 +176,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("space: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("space: not initialised")); } static int spsendset(CSOUND *csound, SPSEND *p) @@ -177,7 +192,7 @@ static int spsend(CSOUND *csound, SPSEND *p) { SPACE *q = p->space; - int nbytes = csound->ksmps*sizeof(MYFLT); + int nbytes = CS_KSMPS*sizeof(MYFLT); memmove(p->r1, q->rrev1, nbytes); memmove(p->r2, q->rrev2, nbytes); @@ -244,15 +259,16 @@ *r=distance; return OK; err1: - return csound->PerfError(csound, Str("spdist: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("spdist: not initialised")); } #define S(x) sizeof(x) static OENTRY localops[] = { -{ "space", S(SPACE), TR|5, "aaaa", "aikkkk",(SUBR)spaceset, NULL, (SUBR)space }, -{ "spsend", S(SPSEND), 5, "aaaa", "", (SUBR)spsendset, NULL, (SUBR)spsend }, -{ "spdist", S(SPDIST), 3, "k", "ikkk", (SUBR)spdistset, (SUBR)spdist, NULL } + { "space", S(SPACE), TR,5, "aaaa", "aikkkk",(SUBR)spaceset, NULL, (SUBR)space }, + { "spsend", S(SPSEND), 0,5, "aaaa", "", (SUBR)spsendset, NULL, (SUBR)spsend }, + { "spdist", S(SPDIST), 0,3, "k", "ikkk", (SUBR)spdistset, (SUBR)spdist, NULL } }; int space_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/spat3d.c csound-6.02~dfsg/Opcodes/spat3d.c --- csound-5.17.11~dfsg/Opcodes/spat3d.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/spat3d.c 2014-01-07 16:53:48.000000000 +0000 @@ -23,7 +23,7 @@ /* ----- spat3d, spat3di, and spat3dt -- written by Istvan Varga, 2001 ----- */ -#include "csdl.h" +#include "stdopcod.h" #include #include #include @@ -45,7 +45,7 @@ o = p->oversamp << 5; /* window size = 32 * oversample */ i = ((o + 1) * (sizeof(int) + sizeof(MYFLT))); /* allocate */ - if ((p->fltr.auxp == NULL) || (p->fltr.size < i)) /* space */ + if ((p->fltr.auxp == NULL) || (p->fltr.size < (unsigned int)i)) /* space */ csound->AuxAlloc(csound, i, &(p->fltr)); p->sample = (int *) p->fltr.auxp; /* sample number */ p->window = (MYFLT *) (p->sample + o + 1); /* window value */ @@ -207,8 +207,8 @@ /* extend delay buffer */ if ((MYFLT) d0 > p->mdel) p->mdel = (MYFLT) d0; if ((MYFLT) d1 > p->mdel) p->mdel = (MYFLT) d1; - ws->D0 = d0 * (double) csound->esr + 0.5; - ws->D1 = d1 * (double) csound->esr + 0.5; + ws->D0 = d0 * (double) CS_ESR + 0.5; + ws->D1 = d1 * (double) CS_ESR + 0.5; ws->W0 = w; ws->X0 = x; ws->Y0 = y; ws->Z0 = z; } @@ -232,12 +232,12 @@ { int32 i, j; - i = ((int32) (p->mdel * csound->esr) + (int32) csound->ksmps + 34L) + i = ((int32) (p->mdel * CS_ESR) + (int32) CS_KSMPS + 34L) * (int32) p->oversamp; p->mdel_s = i; if (p->o_num == 1) i += 4; /* extra samples for spat3d */ j = i * (int32) sizeof(MYFLT) * (int32) (p->zout > 3 ? 4 : p->zout + 1); - if ((p->del.auxp == NULL) || (p->del.size < j)) /* allocate */ + if ((p->del.auxp == NULL) || (p->del.size < (unsigned int)j)) /* allocate */ csound->AuxAlloc(csound, j, &(p->del)); /* space */ p->Wb = (MYFLT *) p->del.auxp; /* W */ if (p->zout > 0) p->Yb = p->Wb + i; /* Y */ @@ -292,7 +292,7 @@ p->ftable = p->outft = NULL; /* no ftables */ p->zout = p->rseed = p->mindep = p->maxdep = p->outftlnth = wmask = 0; p->oversamp = 1; /* oversample */ - p->bs = (int) csound->ksmps; /* block size */ + p->bs = (int) CS_KSMPS; /* block size */ p->irlen = 2; /* IR length */ p->mdist = p->mdel = FL(0.001); /* unit circle dist., max. delay */ p->mdel_s = p->del_p = 0L; @@ -318,7 +318,7 @@ p->mdist = *(p->args[xidist]); if (xift >= 0) { /* ftable */ int fLen; - fLen = csound->GetTable(csound, &(p->ftable), (int) *(p->args[xift])); + fLen = csoundGetTable(csound, &(p->ftable), (int) *(p->args[xift])); if (fLen < 53) p->ftable = NULL; } @@ -327,10 +327,10 @@ if (xiovr >= 0) /* oversample */ p->oversamp = (int) MYFLT2LRND(*(p->args[xiovr])); if (xirlen >= 0) /* IR length */ - p->irlen = (int) MYFLT2LRND(*(p->args[xirlen]) * csound->esr); + p->irlen = (int) MYFLT2LRND(*(p->args[xirlen]) * CS_ESR); if (xioutft >= 0) { /* output table */ int fLen; - fLen = csound->GetTable(csound, &(p->outft), (int) *(p->args[xioutft])); + fLen = csoundGetTable(csound, &(p->outft), (int) *(p->args[xioutft])); if (fLen < 1) { p->outft = NULL; p->outftlnth = 0; } @@ -352,7 +352,7 @@ if (p->ftable[2] >= FL(0.0)) /* max. delay */ p->mdel = p->ftable[2]; if (p->ftable[3] >= FL(0.0)) /* IR length */ - p->irlen = (int) MYFLT2LRND(p->ftable[3] * csound->esr); + p->irlen = (int) MYFLT2LRND(p->ftable[3] * CS_ESR); if (p->ftable[4] >= FL(0.0)) /* unit circle dist. */ p->mdist = p->ftable[4]; p->rseed = (int32) MYFLT2LRND(p->ftable[5]); /* seed */ @@ -381,11 +381,11 @@ if (p->maxdep >= 0) { i = d = 0; spat3d_count_refl(&i, &d, 0, p->maxdep, 0, wmask); i *= (int32) sizeof(SPAT3D_WALL); - if ((p->ws.auxp == NULL) || (p->ws.size < i)) + if ((p->ws.auxp == NULL) || (p->ws.size < (unsigned int)i)) csound->AuxAlloc(csound, i, &(p->ws)); i = (int32) p->bs * (int32) d; i *= (int32) sizeof(MYFLT); - if ((p->y.auxp == NULL) || (p->y.size < i)) + if ((p->y.auxp == NULL) || (p->y.size < (unsigned int)i)) csound->AuxAlloc(csound, i, &(p->y)); } return OK; @@ -486,9 +486,9 @@ a = SPAT3D_DIST2AMP(d); /* amp. */ x = SQRT(FL(1.0) - (x / (d + FL(0.0001)))); x *= a; w = a - x; /* Lh, Ll */ - d1 *= (double) p->oversamp * (double) csound->esr;/* convert */ + d1 *= (double) p->oversamp * (double) CS_ESR;/* convert */ } /* delay to */ - d0 *= (double) p->oversamp * (double) csound->esr; /* samples */ + d0 *= (double) p->oversamp * (double) CS_ESR; /* samples */ /* interpolate W, X, Y, Z, and delay */ @@ -661,7 +661,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("spat3d: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("spat3d: not initialised")); } /* -------------------------- spat3di performance -------------------------- */ @@ -778,7 +779,8 @@ } while (--nn); return OK; err1: - return csound->PerfError(csound, Str("spat3di: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("spat3di: not initialised")); } /* ---------------------------- spat3dt opcode ----------------------------- */ @@ -848,7 +850,8 @@ spat3d_init_wall(p, 0, 0, &wmax, *(p->args[1]), *(p->args[2]), *(p->args[3])); p->outftlnth = ((p->outftlnth) >> 2) << 2; /* table length */ - if (UNLIKELY((p->outft == NULL) || (p->outftlnth < 4))) return NOTOK; /* no table */ + if (UNLIKELY((p->outft == NULL) || (p->outftlnth < 4))) + return NOTOK; /* no table */ /* initialise IR */ @@ -872,11 +875,11 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "spat3d", S(SPAT3D), 5, "aaaa", "akkkiiiiio", + { "spat3d", S(SPAT3D), 0, 5, "aaaa", "akkkiiiiio", (SUBR) spat3dset, NULL, (SUBR) spat3d }, - { "spat3di",S(SPAT3D), 5, "aaaa", "aiiiiiio", + { "spat3di",S(SPAT3D), 0, 5, "aaaa", "aiiiiiio", (SUBR) spat3diset, NULL, (SUBR) spat3di }, - { "spat3dt",S(SPAT3D), 1, "", "iiiiiiiio", + { "spat3dt",S(SPAT3D), 0, 1, "", "iiiiiiiio", (SUBR) spat3dt, NULL, NULL } }; diff -Nru csound-5.17.11~dfsg/Opcodes/spat3d.h csound-6.02~dfsg/Opcodes/spat3d.h --- csound-5.17.11~dfsg/Opcodes/spat3d.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/spat3d.h 2014-01-07 16:53:48.000000000 +0000 @@ -43,7 +43,8 @@ /* calculate distance */ -#define SPAT3D_XYZ2DIST(x,y,z) ((MYFLT) sqrt ((double) ((x) * (x) + (y) * (y) + (z) * (z)))) +#define SPAT3D_XYZ2DIST(x,y,z) \ + ((MYFLT) sqrt ((double) ((x) * (x) + (y) * (y) + (z) * (z)))) /* limit a number to a specified range */ diff -Nru csound-5.17.11~dfsg/Opcodes/spectra.c csound-6.02~dfsg/Opcodes/spectra.c --- csound-5.17.11~dfsg/Opcodes/spectra.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/spectra.c 2014-01-07 16:54:20.000000000 +0000 @@ -37,7 +37,7 @@ { int32 nbytes = npts * sizeof(MYFLT); - if (downdp->auxch.auxp == NULL || downdp->auxch.size != nbytes) + if (downdp->auxch.auxp == NULL || downdp->auxch.size != (uint32_t)nbytes) p->AuxAlloc(p, nbytes, &downdp->auxch); downdp->npts = npts; } @@ -46,7 +46,7 @@ { int32 nbytes = npts * sizeof(MYFLT); - if (specdp->auxch.auxp == NULL || nbytes != specdp->auxch.size) + if (specdp->auxch.auxp == NULL || (uint32_t)nbytes != specdp->auxch.size) p->AuxAlloc(p, nbytes, &specdp->auxch); specdp->npts = npts; } @@ -65,14 +65,15 @@ SPECDAT *specp = p->wsig; /* for mac roundoff */ - p->timcount = (int)(csound->ekr * *p->iprd + FL(0.001)); + p->timcount = (int)(CS_EKR * *p->iprd + FL(0.001)); nocts = (int)*p->iocts; nfreqs = (int)*p->ifrqs; ncoefs = nocts * nfreqs; Q = *p->iq; hanning = (*p->ihann) ? 1 : 0; p->dbout = (int)*p->idbout; - if ((p->disprd = (int)(csound->ekr * *p->idisprd)) < 0) p->disprd = 0; + if ((p->disprd = (int)(CS_EKR * *p->idisprd)) < 0) + p->disprd = 0; if (UNLIKELY(p->timcount <= 0)) return csound->InitError(csound, Str("illegal iprd")); @@ -107,12 +108,12 @@ (hanning) ? "hanning":"hamming", outstring[p->dbout]); if (p->h.optext->t.intype == 'k') { - dwnp->srate = csound->ekr; /* define the srate */ + dwnp->srate = CS_EKR; /* define the srate */ p->nsmps = 1; } else { - dwnp->srate = csound->esr; - p->nsmps = csound->ksmps; + dwnp->srate = CS_ESR; + p->nsmps = CS_KSMPS; } hicps = dwnp->srate * 0.375; /* top freq is 3/4 pi/2 ... */ oct = log(hicps / ONEPT) / LOGTWO; /* octcps() (see aops.c) */ @@ -248,13 +249,17 @@ { MYFLT a, b, *dftp, *sigp = p->signal, SIG, yt1, yt2; int nocts, nsmps = p->nsmps, winlen; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; DOWNDAT *downp = &p->downsig; OCTDAT *octp; SPECDAT *specp; double c; + if (UNLIKELY(early)) nsmps -= early; do { SIG = *sigp++; /* for each source sample: */ + if (offset--) SIG = FL(0.0); /* for sample accuracy */ octp = downp->octdata; /* align onto top octave */ nocts = downp->nocts; do { /* then for each oct: */ @@ -280,10 +285,10 @@ } while (!(++octp->scount & 01) && octp++); /* send alt samps to nxtoct */ } while (--nsmps); - if (p->disprd) /* if displays requested, */ - if (!(--p->dcountdown)) { /* on countdown */ + if (p->disprd) /* if displays requested, */ + if (!(--p->dcountdown)) { /* on countdown */ linocts(downp, (MYFLT *)p->auxch2.auxp); /* linearize the oct bufs */ - csound->display(csound, &p->octwindow); /* & display */ + csound->display(csound, &p->octwindow); /* & display */ p->dcountdown = p->disprd; } @@ -300,7 +305,7 @@ int len, *lenp, *offp, nfreqs; MYFLT *begp, *curp, *endp, *linbufp; int len2; - octp--; /* for each oct (low to high) */ + octp--; /* for each oct (low to high) */ begp = octp->begp; curp = octp->curp; endp = octp->endp; @@ -343,7 +348,7 @@ *dftp++ = (MYFLT)c; /* store in out spectrum */ } } - specp->ktimstamp = csound->kcounter; /* time-stamp the output */ + specp->ktimstamp = CS_KCNT; /* time-stamp the output */ return OK; } @@ -356,20 +361,21 @@ /* DOWNDAT *downp = p->dsig; */ /* SPECDAT *specp = p->wsig; */ -/* p->timcount = csound->ekr * *p->iprd; */ +/* p->timcount = CS_EKR * *p->iprd; */ /* nfreqs = *p->ifrqs; */ /* Q = *p->iq; */ /* hanning = (*p->ihann) ? 1 : 0; */ /* if ((p->dbout = *p->idbout) && p->dbout != 1 && p->dbout != 2) { */ -/* return csound->InitError(csound, Str("noctdft: unknown dbout code of %d"), */ +/* return csound->InitError(csound, + Str("noctdft: unknown dbout code of %d"), */ /* p->dbout); */ /* } */ /* nocts = downp->nocts; */ /* ncoefs = nocts * nfreqs; */ -/* if (nfreqs != p->nfreqs || Q != p->curq /\* if anything changed *\/ */ +/* if (nfreqs != p->nfreqs || Q != p->curq /\* if anything changed *\/ */ /* || p->timcount <= 0 || Q <= 0. */ /* || hanning != p->hanning */ -/* || ncoefs != p->ncoefs) { /\* make new tables *\/ */ +/* || ncoefs != p->ncoefs) { /\* make new tables *\/ */ /* double basfrq, curfrq, frqmlt, Qfactor; */ /* double theta, a, windamp, onedws, pidws; */ /* MYFLT *sinp, *cosp; */ @@ -390,16 +396,17 @@ /* p->curq = Q; */ /* p->hanning = hanning; */ /* p->ncoefs = ncoefs; */ -/* basfrq = downp->hifrq/2.0 * TWOPI/downp->srate; /\* oct below retuned top *\/ */ +/* basfrq = downp->hifrq/2.0 * TWOPI/downp->srate; + /\* oct below retuned top *\/ */ /* frqmlt = pow(2.0,1.0/(double)nfreqs); /\* nfreq interval mult *\/ */ /* Qfactor = TWOPI * Q; /\* Was incorrect value for 2pi?? *\/ */ /* curfrq = basfrq; */ /* for (sumk=0,wsizp=p->winlen,n=nfreqs; n--; ) { */ -/* *wsizp++ = k = Qfactor/curfrq + 0.5; /\* calc window sizes *\/ */ -/* sumk += k; /\* and find total *\/ */ +/* *wsizp++ = k = Qfactor/curfrq + 0.5; /\* calc window sizes *\/ */ +/* sumk += k; /\* and find total *\/ */ /* curfrq *= frqmlt; */ /* } */ -/* if ((windsiz = *(p->winlen)) > nsamps) { /\* chk longest windsiz *\/ */ +/* if ((windsiz = *(p->winlen)) > nsamps) {/\* chk longest windsiz *\/ */ /* return csound->InitError(csound, Str("Q %4.1f needs %d samples, " */ /* "octdown has just %d"), */ /* Q, windsiz, nsamps); */ @@ -407,14 +414,16 @@ /* else csound->Message(csound, Str("noctdft: Q %4.1f uses %d of " */ /* "%d samps per octdown\n"), */ /* Q, windsiz, nsamps); */ -/* auxsiz = (nsamps + 2*sumk) * sizeof(MYFLT); /\* calc local space reqd *\/ */ -/* csound->AuxAlloc(csound, (size_t)auxsiz, &p->auxch); /\* & alloc auxspace *\/ */ +/* auxsiz = (nsamps + 2*sumk) * sizeof(MYFLT);/\* calc local space reqd *\/ */ +/* csound->AuxAlloc(csound, (size_t)auxsiz, &p->auxch); + /\* & alloc auxspace *\/ */ /* fltp = (MYFLT *) p->auxch.auxp; */ -/* p->linbufp = fltp; fltp += nsamps; /\* linbuf must handle nsamps *\/ */ +/* p->linbufp = fltp; fltp += nsamps; + /\* linbuf must handle nsamps *\/ */ /* p->sinp = sinp = fltp; fltp += sumk; */ -/* p->cosp = cosp = fltp; /\* cos gets rem sumk *\/ */ +/* p->cosp = cosp = fltp; /\* cos gets rem sumk *\/ */ /* wsizp = p->winlen; */ -/* for (curfrq=basfrq,n=nfreqs; n--; ) { /\* now fill tables *\/ */ +/* for (curfrq=basfrq,n=nfreqs; n--; ) { /\* now fill tables *\/ */ /* windsiz = *wsizp++; */ /* onedws = 1.0 / windsiz; */ /* pidws = PI / windsiz; */ @@ -428,7 +437,7 @@ /* *sinp++ = windamp * sin(theta); */ /* *cosp++ = windamp * cos(theta); */ /* } */ -/* curfrq *= frqmlt; /\* step by log freq *\/ */ +/* curfrq *= frqmlt; /\* step by log freq *\/ */ /* } */ /* if (*p->idsines != FL(0.0)) { */ /* /\* if reqd, display windowed sines immediately *\/ */ @@ -437,14 +446,14 @@ /* csound->display(csound, &p->dwindow); */ /* } */ /* SPECset(csound, */ -/* specp, (long)ncoefs); /\* prep the spec dspace *\/ */ -/* specp->downsrcp = downp; /\* & record its source *\/ */ +/* specp, (long)ncoefs); /\* prep the spec dspace *\/ */ +/* specp->downsrcp = downp; /\* & record its source *\/ */ /* } */ -/* specp->nfreqs = p->nfreqs; /\* save the spec descriptors *\/ */ +/* specp->nfreqs = p->nfreqs; \* save the spec descriptors *\/ */ /* specp->dbout = p->dbout; */ -/* specp->ktimstamp = 0; /\* init specdata to not new *\/ */ +/* specp->ktimstamp = 0; \* init specdata to not new *\/ */ /* specp->ktimprd = p->timcount; */ -/* p->countdown = p->timcount; /\* & prime the countdown *\/ */ +/* p->countdown = p->timcount; \* & prime the countdown *\/ */ /* return OK; */ /* } */ @@ -458,11 +467,13 @@ /* MYFLT a, b; */ /* double c; */ -/* if ((--p->countdown)) return; /\* if not yet time for new spec, return *\/ */ +/* if ((--p->countdown)) return; + /\* if not yet time for new spec, return *\/ */ /* if (p->auxch.auxp==NULL) { /\* RWD fix *\/ */ -/* return csound->PerfError(csound, Str("noctdft: not initialised")); */ +/* return csound->PerfError(csound, p->h.insdshead, */ +/* Str("noctdft: not initialised")); */ /* } */ -/* p->countdown = p->timcount; /\* else reset counter & proceed: *\/ */ +/* p->countdown = p->timcount; /\* else reset counter & proceed: *\/ */ /* downp = p->dsig; */ /* specp = p->wsig; */ /* nocts = downp->nocts; */ @@ -472,38 +483,38 @@ /* MYFLT *bufp, *sinp, *cosp; */ /* int len, *lenp, nfreqs; */ /* MYFLT *begp, *curp, *endp; */ -/* octp--; /\* for each octave (low to high) *\/ */ +/* octp--; /\* for each octave (low to high) *\/ */ /* begp = octp->begp; */ /* curp = octp->curp; */ /* endp = octp->endp; */ /* wrap = curp - begp; */ /* bufp = p->linbufp; */ -/* while (curp < endp) /\* copy circbuf to linbuf *\/ */ +/* while (curp < endp) /\* copy circbuf to linbuf *\/ */ /* *bufp++ = *curp++; */ /* for (curp=begp,len=wrap; len--; ) */ /* *bufp++ = *curp++; */ -/* cosp = p->cosp; /\* get start windowed sines *\/ */ +/* cosp = p->cosp; /\* get start windowed sines *\/ */ /* sinp = p->sinp; */ /* lenp = p->winlen; */ -/* for (nfreqs=p->nfreqs; nfreqs--; ) { /\* now for each freq this oct: *\/ */ +/* for (nfreqs=p->nfreqs; nfreqs--; ) { /\* now for each freq this oct: *\/ */ /* a = 0.0; */ /* b = 0.0; */ /* bufp = p->linbufp; */ -/* for (len = *lenp++; len--; bufp++) { /\* apply windowed sine seg *\/ */ +/* for (len = *lenp++; len--; bufp++) {/\* apply windowed sine seg *\/ */ /* a += *bufp * *cosp++; */ /* b += *bufp * *sinp++; */ /* } */ -/* c = a*a + b*b; /\* get magnitude squared *\/ */ -/* if (!(p->dbout)) /\* & optionally convert *\/ */ -/* c = sqrt(c); /\* to mag or db *\/ */ +/* c = a*a + b*b; /\* get magnitude squared *\/ */ +/* if (!(p->dbout)) /\* & optionally convert *\/ */ +/* c = sqrt(c); /\* to mag or db *\/ */ /* else if (p->dbout == 1) { */ /* if (c < .001) c = .001; */ /* c = 10. * log10(c); */ /* } */ -/* *dftp++ = c; /\* store in out spectrum *\/ */ +/* *dftp++ = c; /\* store in out spectrum *\/ */ /* } */ /* } */ -/* specp->ktimstamp = csound->kcounter; /\* time-stamp the output *\/ */ +/* specp->ktimstamp = CS_KCNT; /\* time-stamp the output *\/ */ /* return OK; */ /* } */ @@ -514,7 +525,7 @@ if (UNLIKELY(p->wsig->auxch.auxp==NULL)) { return csound->InitError(csound, Str("specdisp: not initialised")); } - if (UNLIKELY((p->timcount = (int)(csound->ekr * *p->iprd)) <= 0)) { + if (UNLIKELY((p->timcount = (int)(CS_EKR * *p->iprd)) <= 0)) { return csound->InitError(csound, Str("illegal iperiod")); } if (!(p->dwindow.windid)) { @@ -552,7 +563,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("specdisp: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specdisp: not initialised")); } int sptrkset(CSOUND *csound, SPECPTRK *p) @@ -570,7 +582,8 @@ p->fundp = (MYFLT *) p->wfund.auxch.auxp; p->winpts = npts; } - if ((p->ftimcnt = (int)(csound->ekr**p->ifprd)) > 0) {/* if displaying wfund */ + if ((p->ftimcnt = (int)(CS_EKR**p->ifprd)) > 0) { + /* if displaying wfund */ SPECDISP *fdp = &p->fdisplay; fdp->h = p->h; fdp->wsig = &p->wfund; /* pass the param pntrs */ @@ -597,7 +610,7 @@ nfreqs = (MYFLT)inspecp->nfreqs; for (nn = 1; nn <= ptlmax; nn += inc) *dstp++ = (int) ((log((double) nn) / LOGTWO) * nfreqs + 0.5); - if ((rolloff = *p->irolloff) == 0. || rolloff == 1. || nptls == 1) { + if ((rolloff = *p->irolloff) == 0.0 || rolloff == 1.0 || nptls == 1) { p->rolloff = 0; weightsum = (MYFLT)nptls; } else { @@ -623,7 +636,7 @@ fendp = fundp + inspecp->npts; if (flop < fundp) flop = fundp; if (fhip > fendp) fhip = fendp; - if (flop >= fhip) { /* chk hi-lo range valid */ + if (UNLIKELY(flop >= fhip)) { /* chk hi-lo range valid */ return csound->InitError(csound, Str("illegal lo-hi values")); } for (fp = fundp; fp < flop; ) @@ -683,7 +696,7 @@ { SPECDAT *inspecp = p->wsig; - if (inspecp->ktimstamp == csound->kcounter) { /* if inspectrum is new: */ + if (inspecp->ktimstamp == CS_KCNT) { /* if inspectrum is new: */ MYFLT *inp = (MYFLT *) inspecp->auxch.auxp; MYFLT *endp = inp + inspecp->npts; MYFLT *inp2, sum, *fp; @@ -693,8 +706,7 @@ int32 lobin, hibin; if (UNLIKELY(inp==NULL)) goto err1; /* RWD fix */ - if ((kvar = *p->kvar) < FL(0.0)) - kvar = -kvar; + kvar = FABS(*p->kvar); kval = p->playing == PLAYING ? p->kval : p->kvalsav; lobin = (int32)((kval-kvar) * inspecp->nfreqs); /* set lims of frq interest */ hibin = (int32)((kval+kvar) * inspecp->nfreqs); @@ -774,8 +786,7 @@ kval = realbin / inspecp->nfreqs; /* & cvt to true decoct */ if (p->playing == STARTING) { /* STARTING mode: */ - if ((absdiff = kval - p->kvalsav) < FL(0.0)) - absdiff = -absdiff; + absdiff = FABS(kval - p->kvalsav); confirms = (int)(absdiff * p->confact); /* get interval dependency */ if (p->jmpcount < confirms) { p->jmpcount += 1; /* if not enough confirms, */ @@ -787,8 +798,7 @@ p->kinc = FL(0.0); } } else { /* PLAYING mode: */ - if ((absdiff = kval - p->kval) < FL(0.0)) - absdiff = -absdiff; + absdiff = FABS(kval - p->kval); confirms = (int)(absdiff * p->confact); /* get interval dependency */ if (p->jmpcount < confirms) { p->jmpcount += 1; /* if not enough confirms, */ @@ -816,7 +826,8 @@ specdisp(csound,&p->fdisplay); return OK; err1: - return csound->PerfError(csound, Str("specptrk: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specptrk: not initialised")); } int spsumset(CSOUND *csound, SPECSUM *p) @@ -832,7 +843,7 @@ { SPECDAT *specp = p->wsig; if (UNLIKELY(specp->auxch.auxp==NULL)) goto err1; /* RWD fix */ - if (specp->ktimstamp == csound->kcounter) { /* if spectrum is new */ + if (specp->ktimstamp == CS_KCNT) { /* if spectrum is new */ MYFLT *valp = (MYFLT *) specp->auxch.auxp; MYFLT sum = FL(0.0); int32 n,npts = specp->npts; /* sum all the values */ @@ -848,7 +859,8 @@ p->kval += p->kinc; return OK; err1: - return csound->PerfError(csound, Str("specsum: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specsum: not initialised")); } int spadmset(CSOUND *csound, SPECADDM *p) @@ -887,7 +899,7 @@ if (UNLIKELY((p->wsig1->auxch.auxp==NULL) || /* RWD fix */ (p->wsig2->auxch.auxp==NULL) || (p->waddm->auxch.auxp==NULL))) goto err1; - if (p->wsig1->ktimstamp == csound->kcounter) { /* if inspec1 is new: */ + if (p->wsig1->ktimstamp == CS_KCNT) { /* if inspec1 is new: */ MYFLT *in1p = (MYFLT *) p->wsig1->auxch.auxp; MYFLT *in2p = (MYFLT *) p->wsig2->auxch.auxp; MYFLT *outp = (MYFLT *) p->waddm->auxch.auxp; @@ -897,11 +909,12 @@ for (n=0;nwaddm->ktimstamp = csound->kcounter; /* mark the output spec as new */ + p->waddm->ktimstamp = CS_KCNT; /* mark the output spec as new */ } return OK; err1: - return csound->PerfError(csound, Str("specaddm: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specaddm: not initialised")); } int spdifset(CSOUND *csound, SPECDIFF *p) @@ -913,9 +926,9 @@ if ((npts = inspecp->npts) != p->specsave.npts) { /* if inspec not matched */ SPECset(csound, - &p->specsave, (int32)npts); /* reinit the save spec */ + &p->specsave, (int32)npts); /* reinit the save spec */ SPECset(csound, - p->wdiff, (int32)npts); /* & the out diff spec */ + p->wdiff, (int32)npts); /* & the out diff spec */ p->wdiff->downsrcp = inspecp->downsrcp; } p->wdiff->ktimprd = inspecp->ktimprd; /* pass the other specinfo */ @@ -942,7 +955,7 @@ (p->specsave.auxch.auxp==NULL) || (p->wdiff->auxch.auxp==NULL))) goto err1; - if (inspecp->ktimstamp == csound->kcounter) { /* if inspectrum is new: */ + if (inspecp->ktimstamp == CS_KCNT) { /* if inspectrum is new: */ MYFLT *newp = (MYFLT *) inspecp->auxch.auxp; MYFLT *prvp = (MYFLT *) p->specsave.auxch.auxp; MYFLT *difp = (MYFLT *) p->wdiff->auxch.auxp; @@ -959,11 +972,12 @@ else difp[n] = FL(0.0); /* else enter zero */ prvp[n] = newval; /* sav newval for nxt time */ } - p->wdiff->ktimstamp = csound->kcounter; /* mark the output spec as new */ + p->wdiff->ktimstamp = CS_KCNT; /* mark the output spec as new */ } return OK; err1: - return csound->PerfError(csound, Str("specdiff: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specdiff: not initialised")); } int spsclset(CSOUND *csound, SPECSCAL *p) @@ -1031,7 +1045,7 @@ (p->wscaled->auxch.auxp==NULL) || (p->fscale==NULL)) goto err1; - if (inspecp->ktimstamp == csound->kcounter) { /* if inspectrum is new: */ + if (inspecp->ktimstamp == CS_KCNT) { /* if inspectrum is new: */ SPECDAT *outspecp = p->wscaled; MYFLT *inp = (MYFLT *) inspecp->auxch.auxp; MYFLT *outp = (MYFLT *) outspecp->auxch.auxp; @@ -1052,11 +1066,12 @@ outp[n] = inp[n] * sclp[n]; /* no thresh: rescale only */ } } - outspecp->ktimstamp = csound->kcounter; /* mark the outspec as new */ + outspecp->ktimstamp = CS_KCNT; /* mark the outspec as new */ } return OK; err1: - return csound->PerfError(csound, Str("specscal: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specscal: not initialised")); } int sphstset(CSOUND *csound, SPECHIST *p) @@ -1068,9 +1083,9 @@ if ((npts = inspecp->npts) != p->accumer.npts) { /* if inspec not matched */ SPECset(csound, - &p->accumer, (int32)npts); /* reinit the accum spec */ + &p->accumer, (int32)npts); /* reinit the accum spec */ SPECset(csound, - p->wacout, (int32)npts); /* & the output spec */ + p->wacout, (int32)npts); /* & the output spec */ p->wacout->downsrcp = inspecp->downsrcp; } p->wacout->ktimprd = inspecp->ktimprd; /* pass the other specinfo */ @@ -1080,7 +1095,7 @@ outp = (MYFLT *) p->wacout->auxch.auxp; if (UNLIKELY(lclp==NULL || outp==NULL)) { /* RWD fix */ return csound->InitError(csound, - Str("spechist: local buffers not intiialised")); + Str("spechist: local buffers not initialised")); } memset(lclp,0,npts*sizeof(MYFLT)); /* clr local & out spec bufs */ memset(outp,0,npts*sizeof(MYFLT)); @@ -1096,7 +1111,7 @@ (p->accumer.auxch.auxp==NULL) || (p->wacout->auxch.auxp==NULL))) goto err1; - if (inspecp->ktimstamp == csound->kcounter) { /* if inspectrum is new: */ + if (inspecp->ktimstamp == CS_KCNT) { /* if inspectrum is new: */ MYFLT *newp = (MYFLT *) inspecp->auxch.auxp; MYFLT *acup = (MYFLT *) p->accumer.auxch.auxp; MYFLT *outp = (MYFLT *) p->wacout->auxch.auxp; @@ -1108,11 +1123,12 @@ acup[n] = newval; /* sav in accumulator */ outp[n] = newval; /* & copy to output */ } - p->wacout->ktimstamp = csound->kcounter; /* mark the output spec as new */ + p->wacout->ktimstamp = CS_KCNT; /* mark the output spec as new */ } return OK; err1: - return csound->PerfError(csound, Str("spechist: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("spechist: not initialised")); } int spfilset(CSOUND *csound, SPECFILT *p) @@ -1124,7 +1140,7 @@ if ((npts = inspecp->npts) != outspecp->npts) { /* if inspec not matched */ SPECset(csound, - outspecp, (int32)npts); /* reinit the out spec */ + outspecp, (int32)npts); /* reinit the out spec */ csound->AuxAlloc(csound, (size_t)npts*2* sizeof(MYFLT), &p->auxch); /* & local auxspace */ @@ -1158,7 +1174,7 @@ { int32 nn; MYFLT *flp = p->coefs; - double halftim, reittim = inspecp->ktimprd * csound->onedkr; + double halftim, reittim = inspecp->ktimprd * CS_ONEDKR; for (nn=0;nn 0.) flp[nn] = (MYFLT)pow(0.5, reittim/halftim); @@ -1180,7 +1196,7 @@ int specfilt(CSOUND *csound, SPECFILT *p) { - if (p->wsig->ktimstamp == csound->kcounter) { /* if input spec is new, */ + if (p->wsig->ktimstamp == CS_KCNT) { /* if input spec is new, */ SPECDAT *inspecp = p->wsig; SPECDAT *outspecp = p->wfil; MYFLT *newp = (MYFLT *) inspecp->auxch.auxp; @@ -1196,61 +1212,83 @@ outp[n] = curval = persp[n]; /* output current point */ persp[n] = coefp[n] * curval + newp[n]; /* decay & addin newval */ } - outspecp->ktimstamp = csound->kcounter; /* mark output spec as new */ + outspecp->ktimstamp = CS_KCNT; /* mark output spec as new */ } return OK; err1: - return csound->PerfError(csound, Str("specfilt: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("specfilt: not initialised")); } #define S sizeof static OENTRY spectra_localops[] = { -{ "spectrum", S(SPECTRUM),7, "w", "siiiqoooo", +{ "spectrum", S(SPECTRUM),_QQ, 7, "w", "siiiqoooo", (SUBR)spectset,(SUBR)spectrum,(SUBR)spectrum}, -{ "specaddm", S(SPECADDM),5, "w", "wwp", (SUBR)spadmset,NULL, (SUBR)specaddm}, -{ "specdiff", S(SPECDIFF),5, "w", "w", (SUBR)spdifset,NULL, (SUBR)specdiff}, -{ "specscal", S(SPECSCAL),5, "w", "wii", (SUBR)spsclset,NULL, (SUBR)specscal}, -{ "spechist", S(SPECHIST),5, "w", "w", (SUBR)sphstset,NULL, (SUBR)spechist}, -{ "specfilt", S(SPECFILT),5, "w", "wi", (SUBR)spfilset,NULL, (SUBR)specfilt}, -{ "specptrk", S(SPECPTRK),5, "kk", "wkiiiiiioqooo", - (SUBR)sptrkset,NULL,(SUBR)specptrk}, -{ "specsum", S(SPECSUM), 5, "k", "wo", (SUBR)spsumset,NULL, (SUBR)specsum }, -{ "specdisp", S(SPECDISP),5, "", "wio", (SUBR)spdspset,NULL, (SUBR)specdisp}, -{ "pitch", S(PITCH), 5, "kk", "aiiiiqooooojo", +{ "specaddm", S(SPECADDM),_QQ, 5, "w", "wwp", (SUBR)spadmset,NULL, (SUBR)specaddm}, +{ "specdiff", S(SPECDIFF),_QQ, 5, "w", "w", (SUBR)spdifset,NULL, (SUBR)specdiff}, +{ "specscal", S(SPECSCAL),_QQ, 5, "w", "wii", (SUBR)spsclset,NULL, (SUBR)specscal}, +{ "spechist", S(SPECHIST),_QQ, 5, "w", "w", (SUBR)sphstset,NULL, (SUBR)spechist}, +{ "specfilt", S(SPECFILT),_QQ, 5, "w", "wi", (SUBR)spfilset,NULL, (SUBR)specfilt}, +{ "specptrk", S(SPECPTRK),_QQ, 5, "kk", "wkiiiiiioqooo", + (SUBR)sptrkset,NULL,(SUBR)specptrk}, +{ "specsum", S(SPECSUM), _QQ, 5, "k", "wo", (SUBR)spsumset,NULL, (SUBR)specsum }, +{ "specdisp", S(SPECDISP),_QQ, 5, "", "wio", (SUBR)spdspset,NULL, (SUBR)specdisp}, +{ "pitch", S(PITCH), 0, 5, "kk", "aiiiiqooooojo", (SUBR)pitchset, NULL, (SUBR)pitch }, -{ "maca", S(SUM), 5, "a", "y", (SUBR)macset, NULL, (SUBR)maca }, -{ "mac", S(SUM), 5, "a", "Z", (SUBR)macset, NULL, (SUBR)mac }, -{ "clockon", S(CLOCK), 3, "", "i", (SUBR)clockset, (SUBR)clockon, NULL }, -{ "clockoff", S(CLOCK), 3, "", "i", (SUBR)clockset, (SUBR)clockoff, NULL }, -{ "readclock", S(CLKRD), 1, "i", "i", (SUBR)clockread, NULL, NULL }, -{ "pitchamdf",S(PITCHAMDF),5,"kk","aiioppoo", +{ "maca", S(SUM), 0, 5, "a", "y", (SUBR)macset, NULL, (SUBR)maca }, +{ "mac", S(SUM), 0, 5, "a", "Z", (SUBR)macset, NULL, (SUBR)mac }, +{ "clockon", S(CLOCK), 0, 3, "", "i", (SUBR)clockset, (SUBR)clockon, NULL }, +{ "clockoff", S(CLOCK),0, 3, "", "i", (SUBR)clockset, (SUBR)clockoff, NULL }, +{ "readclock", S(CLKRD),0, 1, "i", "i", (SUBR)clockread, NULL, NULL }, +{ "readscratch", S(SCRATCHPAD),0, 1, "i", "o", (SUBR)scratchread, NULL, NULL }, +{ "writescratch", S(SCRATCHPAD),0, 1, "", "io", (SUBR)scratchwrite, NULL, NULL }, +{ "pitchamdf",S(PITCHAMDF),0,5,"kk","aiioppoo", (SUBR)pitchamdfset, NULL, (SUBR)pitchamdf }, -{ "hsboscil",S(HSBOSC), TR|5, "a", "kkkiiioo",(SUBR)hsboscset,NULL,(SUBR)hsboscil }, -{ "phasorbnk", S(PHSORBNK),7,"s", "xkio", - (SUBR)phsbnkset, (SUBR)kphsorbnk, (SUBR)phsorbnk }, -{ "adsynt",S(HSBOSC), TR|5, "a", "kkiiiio", (SUBR)adsyntset, NULL, (SUBR)adsynt }, -{ "mpulse", S(IMPULSE), 5, "a", "kko", (SUBR)impulse_set, NULL, (SUBR)impulse }, -{ "lpf18", S(LPF18), 5, "a", "akkko", (SUBR)lpf18set, NULL, (SUBR)lpf18db }, -{ "waveset", S(BARRI), 5, "a", "ako", (SUBR)wavesetset, NULL, (SUBR)waveset}, -{ "pinkish", S(PINKISH), 5, "a", "xoooo", (SUBR)pinkset, NULL, (SUBR)pinkish }, -{ "noise", S(VARI), 5, "a", "xk", (SUBR)varicolset, NULL, (SUBR)varicol }, -{ "transeg", S(TRANSEG), 7, "s", "iiim", (SUBR)trnset,(SUBR)ktrnseg,(SUBR)trnseg}, -{ "transegb", S(TRANSEG), 7, "s", "iiim", - (SUBR)trnset_bkpt,(SUBR)ktrnseg,(SUBR)trnseg }, -{ "transegr", S(TRANSEG), 7, "s", "iiim", - (SUBR)trnsetr,(SUBR)ktrnsegr,(SUBR)trnsegr }, -{ "clip", S(CLIP), 5, "a", "aiiv", (SUBR)clip_set, NULL, (SUBR)clip }, -{ "cpuprc", S(CPU_PERC), 1, "", "Ti", (SUBR)cpuperc, NULL, NULL }, -{ "maxalloc", S(CPU_PERC), 1, "", "Ti", (SUBR)maxalloc, NULL, NULL }, +{ "hsboscil",S(HSBOSC), TR, 5, "a", "kkkiiioo", + + (SUBR)hsboscset,NULL,(SUBR)hsboscil }, +{ "phasorbnk", S(PHSORBNK),0,5,"a", "xkio", + (SUBR)phsbnkset, (SUBR)NULL, (SUBR)phsorbnk }, +{ "phasorbnk.k", S(PHSORBNK),0,3,"k", "xkio", + (SUBR)phsbnkset, (SUBR)kphsorbnk, NULL}, +{ "adsynt",S(HSBOSC), TR, 5, "a", "kkiiiio", (SUBR)adsyntset, NULL, (SUBR)adsynt }, +{ "mpulse", S(IMPULSE), 0, 5, "a", "kko", + (SUBR)impulse_set, NULL, (SUBR)impulse }, +{ "lpf18", S(LPF18), 0, 5, "a", "axxxo", (SUBR)lpf18set, NULL, (SUBR)lpf18db }, +{ "waveset", S(BARRI), 0, 5, "a", "ako", (SUBR)wavesetset, NULL, (SUBR)waveset}, +{ "pinkish", S(PINKISH), 0, 5, "a", "xoooo", (SUBR)pinkset, NULL, (SUBR)pinkish }, +{ "noise", S(VARI), 0, 5, "a", "xk", (SUBR)varicolset, NULL, (SUBR)varicol }, +{ "transeg", S(TRANSEG),0, 3, "k", "iiim", + (SUBR)trnset,(SUBR)ktrnseg, NULL}, +{ "transeg.a", S(TRANSEG),0, 5, "a", "iiim", + (SUBR)trnset,NULL,(SUBR)trnseg}, +{ "transegb", S(TRANSEG),0, 3, "k", "iiim", + (SUBR)trnset_bkpt,(SUBR)ktrnseg,(SUBR)NULL}, +{ "transegb.a", S(TRANSEG),0, 5, "a", "iiim", + (SUBR)trnset_bkpt,NULL,(SUBR)trnseg }, +{ "transegr", S(TRANSEG),0, 3, "k", "iiim", + (SUBR)trnsetr,(SUBR)ktrnsegr,(SUBR)NULL }, +{ "transegr.a", S(TRANSEG),0, 5, "a", "iiim", + (SUBR)trnsetr,NULL,(SUBR)trnsegr }, +{ "clip", S(CLIP), 0, 5, "a", "aiiv", (SUBR)clip_set, NULL, (SUBR)clip }, +{ "cpuprc", S(CPU_PERC),0, 1, "", "Si", (SUBR)cpuperc_S, NULL, NULL }, +{ "maxalloc", S(CPU_PERC),0, 1, "", "Si", (SUBR)maxalloc_S, NULL, NULL }, +{ "cpuprc", S(CPU_PERC),0, 1, "", "ii", (SUBR)cpuperc, NULL, NULL }, +{ "maxalloc", S(CPU_PERC),0, 1, "", "ii", (SUBR)maxalloc, NULL, NULL }, { "active", 0xffff }, -{ "active.i", S(INSTCNT),1, "i", "To", (SUBR)instcount, NULL, NULL }, -{ "active.k", S(INSTCNT),2, "k", "Uo", NULL, (SUBR)instcount, NULL }, -{ "p.i", S(PFUN), 1, "i", "i", (SUBR)pfun, NULL, NULL }, -{ "p.k", S(PFUNK), 3, "k", "k", (SUBR)pfunk_init, (SUBR)pfunk, NULL }, -{ "mute", S(MUTE), 1, "", "To", (SUBR)mute_inst }, -{ "median", S(MEDFILT), 5, "a", "akio", (SUBR)medfiltset, NULL, (SUBR)medfilt}, -{ "mediank", S(MEDFILT), 5, "k", "kkio", (SUBR)medfiltset, (SUBR)kmedfilt}, +{ "active.iS", S(INSTCNT),0,1, "i", "Soo", (SUBR)instcount_S, NULL, NULL }, +{ "active.kS", S(INSTCNT),0,2, "k", "Soo", NULL, (SUBR)instcount_S, NULL }, +{ "active.i", S(INSTCNT),0,1, "i", "ioo", (SUBR)instcount, NULL, NULL }, +{ "active.k", S(INSTCNT),0,2, "k", "koo", NULL, (SUBR)instcount, NULL }, +{ "p.i", S(PFUN), 0,1, "i", "i", (SUBR)pfun, NULL, NULL }, +{ "p.k", S(PFUNK), 0,3, "k", "k", + (SUBR)pfunk_init, (SUBR)pfunk, NULL }, +{ "mute", S(MUTE), 0,1, "", "So", (SUBR)mute_inst_S }, +{ "mute.i", S(MUTE), 0,1, "", "io", (SUBR)mute_inst }, +{ "median", S(MEDFILT), 0, 5, "a", "akio", + (SUBR)medfiltset, NULL, (SUBR)medfilt }, +{ "mediank", S(MEDFILT), 0,5, "k", "kkio", (SUBR)medfiltset, (SUBR)kmedfilt}, }; -LINKAGE1(spectra_localops) +LINKAGE_BUILTIN(spectra_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/stackops.c csound-6.02~dfsg/Opcodes/stackops.c --- csound-5.17.11~dfsg/Opcodes/stackops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/stackops.c 2014-01-07 16:53:48.000000000 +0000 @@ -72,20 +72,22 @@ int initDone; } POP_OPCODE; -/* fassign() was taken from pstream.c, written by Richard Dobson */ +/* fsg_assign() was taken from pstream.c, written by Richard Dobson */ -static CS_NOINLINE void fassign(CSOUND *csound, +static CS_NOINLINE void fsg_assign(CSOUND *csound, PVSDAT *fdst, const PVSDAT *fsrc) { - if (UNLIKELY(fsrc->frame.auxp == NULL)) - csound->Die(csound, Str("fsig = : source signal is not initialised")); + if (UNLIKELY(fsrc->frame.auxp == NULL)) { + csound->ErrorMsg(csound, Str("fsig = : source signal is not initialised")); + return; + } fdst->N = fsrc->N; fdst->overlap = fsrc->overlap; fdst->winsize = fsrc->winsize; fdst->wintype = fsrc->wintype; fdst->format = fsrc->format; if (fdst->frame.auxp == NULL || - fdst->frame.size != (fdst->N + 2L) * (long) sizeof(float)) + fdst->frame.size != (uint32_t)((fdst->N + 2L) * sizeof(float))) csound->AuxAlloc(csound, (fdst->N + 2L) * (long) sizeof(float), &(fdst->frame)); if (fdst->framecount != fsrc->framecount) { @@ -105,17 +107,18 @@ CSOUND *csound; csound = ((OPDS*) p)->insdshead->csound; - if (UNLIKELY(csound->ids != NULL && csound->pds == NULL)) { + if (UNLIKELY(csound->ids != NULL && ((OPDS*) p)->insdshead->pds == NULL)) { csound->InitError(csound, "%s: %s", csound->GetOpcodeName(p), msg); csound->LongJmp(csound, CSOUND_INITIALIZATION); } - else if (UNLIKELY(csound->ids == NULL && csound->pds != NULL)) { - csound->PerfError(csound, "%s: %s", csound->GetOpcodeName(p), msg); + else if (UNLIKELY(csound->ids == NULL && ((OPDS*) p)->insdshead->pds != NULL)) { + csound->PerfError(csound, ((OPDS*)p)->insdshead, + "%s: %s", csound->GetOpcodeName(p), msg); csound->LongJmp(csound, CSOUND_PERFORMANCE); } else - csound->Die(csound, "%s: %s", csound->GetOpcodeName(p), msg); - /* this is actually never reached */ + csound->ErrorMsg(csound, "%s: %s", csound->GetOpcodeName(p), msg); + return NOTOK; } @@ -137,11 +140,11 @@ return csoundStack_Error(p, Str("argument number or type mismatch")); } -static CS_NOINLINE int csoundStack_LengthError(void *p) -{ - /* CSOUND *csound = ((OPDS*) p)->insdshead->csound; */ - return csoundStack_Error(p, Str("string argument is too long")); -} +/* static CS_NOINLINE int csoundStack_LengthError(void *p) */ +/* { */ +/* /\* CSOUND *csound = ((OPDS*) p)->insdshead->csound; *\/ */ +/* return csoundStack_Error(p, Str("string argument is too long")); */ +/* } */ static CS_NOINLINE CsoundArgStack_t *csoundStack_AllocGlobals(CSOUND *csound, int stackSize) @@ -155,9 +158,12 @@ stackSize = 16777200; nBytes = csoundStack_Align((int) sizeof(CsoundArgStack_t)); nBytes += stackSize; - if (UNLIKELY(csound->CreateGlobalVariable(csound, "csArgStack", (size_t) nBytes) - != 0)) - csound->Die(csound, Str("Error allocating argument stack")); + if (UNLIKELY(csound->CreateGlobalVariable(csound, + "csArgStack", (size_t) nBytes) + != 0)) { + csound->ErrorMsg(csound, Str("Error allocating argument stack")); + return NULL; + } pp = (CsoundArgStack_t*) csound->QueryGlobalVariable(csound, "csArgStack"); pp->curBundle = (CsoundArgStack_t*) NULL; pp->dataSpace = @@ -179,7 +185,7 @@ return pp; } -static CS_NOINLINE int csoundStack_CreateArgMap(void *p, int *argMap, +static CS_NOINLINE int csoundStack_CreateArgMap(PUSH_OPCODE *p, int *argMap, int isOutput) { CSOUND *csound; @@ -240,7 +246,7 @@ /* performance time types */ if (aMask & maskVal) { argMap[i + 3] = (curOffs_p | CS_STACK_A); - curOffs_p += ((int) sizeof(MYFLT) * csound->ksmps); + curOffs_p += ((int) sizeof(MYFLT) * CS_KSMPS); } else { argMap[i + 3] = (curOffs_p | CS_STACK_K); @@ -251,8 +257,8 @@ /* init time types */ if (sMask & maskVal) { argMap[i + 3] = (curOffs_i | CS_STACK_S); - curOffs_i += csound->strVarMaxLen; - curOffs_i = csoundStack_Align(curOffs_i); + curOffs_i += (int) sizeof(STRINGDAT); + /* curOffs_i = csoundStack_Align(curOffs_i);*/ } else { argMap[i + 3] = (curOffs_i | CS_STACK_I); @@ -283,8 +289,9 @@ static int notinit_opcode_stub_perf(CSOUND *csound, void *p) { - return csound->PerfError(csound, Str("%s: not initialised"), - csound->GetOpcodeName(p)); + return csound->PerfError(csound, ((OPDS*)p)->insdshead, + Str("%s: not initialised"), + csound->GetOpcodeName(p)); } static int push_opcode_perf(CSOUND *csound, PUSH_OPCODE *p) @@ -311,12 +318,19 @@ case CS_STACK_A: { MYFLT *src, *dst; - int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; src = p->args[i]; dst = (MYFLT*) ((char*) bp + (int) (curOffs & (int) 0x00FFFFFF)); - //memcpy(dst, src, sizeof(MYFLT)*csound->ksmps; - for (j = 0; j < csound->ksmps; j++) - dst[j] = src[j]; + if (UNLIKELY(offset)) memset(dst, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&dst[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&dst[offset], &src[offset], sizeof(MYFLT)*(nsmps-offset)); + //for (j = 0; j < nsmps; j++) + //dst[j] = src[j]; } } } @@ -330,7 +344,7 @@ { if (!p->initDone) { p->pp = csoundStack_GetGlobals(csound); - if (UNLIKELY(csoundStack_CreateArgMap(p, &(p->argMap[0]), 0) != OK)) + if (UNLIKELY(csoundStack_CreateArgMap(p, (int*)&(p->argMap[0]), 0) != OK)) return NOTOK; p->h.opadr = (int (*)(CSOUND *, void *)) push_opcode_perf; p->initDone = 1; @@ -338,7 +352,8 @@ if (p->argMap[1] != 0) { void *bp; int i, *ofsp; - if (UNLIKELY(p->pp->freeSpaceOffset + p->argMap[1] > p->pp->freeSpaceEndOffset)) + if (UNLIKELY(p->pp->freeSpaceOffset + p->argMap[1] > + p->pp->freeSpaceEndOffset)) return csoundStack_OverflowError(p); bp = (void*) ((char*) p->pp->dataSpace + (int) p->pp->freeSpaceOffset); p->pp->freeSpaceOffset += p->argMap[1]; @@ -356,19 +371,26 @@ break; case CS_STACK_S: { - char *src, *dst; - int j, maxLen; - src = (char*) p->args[i]; - dst = (char*) bp + (int) (curOffs & (int) 0x00FFFFFF); - maxLen = csound->strVarMaxLen - 1; - for (j = 0; src[j] != (char) 0; j++) { - dst[j] = src[j]; - if (j >= maxLen) { - dst[j] = (char) 0; - csoundStack_LengthError(p); - } + char *src; + STRINGDAT *dst; + /* int j, maxLen; */ + src = ((STRINGDAT*) p->args[i])->data; + dst = ((STRINGDAT*)(char*) bp + (int) (curOffs & (int) 0x00FFFFFF)); + if(dst->size <= (int) strlen(src)){ + dst->data = csound->Strdup(csound, src); + dst->size = strlen(src) + 1; + } else { + strcpy(dst->data, src); } - dst[j] = (char) 0; + /* maxLen = ((STRINGDAT*) p->args[i])->size; */ + /* for (j = 0; src[j] != (char) 0; j++) { */ + /* dst[j] = src[j]; */ + /* if (j >= maxLen) { */ + /* dst[j] = (char) 0; */ + /* csoundStack_LengthError(p); */ + /* } */ + /* } */ + /* dst[j] = (char) 0; */ } } } @@ -401,11 +423,19 @@ case CS_STACK_A: { MYFLT *src, *dst; - int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; src = (MYFLT*) ((char*) bp + (int) (curOffs & (int) 0x00FFFFFF)); dst = p->args[i]; - for (j = 0; j < csound->ksmps; j++) - dst[j] = src[j]; + if (UNLIKELY(offset)) memset(dst, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&dst[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&dst[offset], &src[offset], (nsmps-offset)*sizeof(MYFLT)); + //for (j = 0; j < CS_KSMPS; j++) + // dst[j] = src[j]; } break; } @@ -421,7 +451,8 @@ { if (!p->initDone) { p->pp = csoundStack_GetGlobals(csound); - if (UNLIKELY(csoundStack_CreateArgMap(p, &(p->argMap[0]), 1) != OK)) + if (UNLIKELY(csoundStack_CreateArgMap((PUSH_OPCODE*)p, + &(p->argMap[0]), 1) != OK)) return NOTOK; p->h.opadr = (int (*)(CSOUND *, void *)) pop_opcode_perf; p->initDone = 1; @@ -463,7 +494,8 @@ int *ofsp; int offs; - if (UNLIKELY(p->pp->freeSpaceOffset + p->argMap[2] > p->pp->freeSpaceEndOffset)) + if (UNLIKELY(p->pp->freeSpaceOffset + p->argMap[2] > + p->pp->freeSpaceEndOffset)) return csoundStack_OverflowError(p); bp = (void*) ((char*) p->pp->dataSpace + (int) p->pp->freeSpaceOffset); p->pp->freeSpaceOffset += p->argMap[2]; @@ -537,7 +569,7 @@ ofsp++; if (UNLIKELY(*ofsp != CS_STACK_END)) csoundStack_TypeError(p); - fassign(csound, + fsg_assign(csound, (PVSDAT*) p->args[0], *((PVSDAT**) ((char*) bp + (int) (offs & (int) 0x00FFFFFF)))); p->pp->curBundle = *((void**) bp); @@ -582,7 +614,7 @@ ofsp++; if (UNLIKELY(*ofsp != CS_STACK_END)) csoundStack_TypeError(p); - fassign(csound, + fsg_assign(csound, (PVSDAT*) p->args[0], *((PVSDAT**) ((char*) bp + (int) (offs & (int) 0x00FFFFFF)))); p->pp->curBundle = *((void**) bp); @@ -591,64 +623,22 @@ return OK; } - /* ------------------------------------------------------------------------ */ -typedef struct MONITOR_OPCODE_ { - OPDS h; - MYFLT *ar[24]; -} MONITOR_OPCODE; - -static int monitor_opcode_perf(CSOUND *csound, MONITOR_OPCODE *p) -{ - int i, j; - - if (csound->spoutactive) { - int k = 0; - i = 0; - do { - j = 0; - do { - p->ar[j][i] = csound->spout[k++]; - } while (++j < csound->nchnls); - } while (++i < csound->ksmps); - } - else { - j = 0; - do { - i = 0; - do { - p->ar[j][i] = FL(0.0); - } while (++i < csound->ksmps); - } while (++j < csound->nchnls); - } - return OK; -} - -static int monitor_opcode_init(CSOUND *csound, MONITOR_OPCODE *p) -{ - if (UNLIKELY(csound->GetOutputArgCnt(p) != csound->nchnls)) - return csound->InitError(csound, Str("number of arguments != nchnls")); - p->h.opadr = (SUBR) monitor_opcode_perf; - return OK; -} /* ------------------------------------------------------------------------ */ static OENTRY stackops_localops[] = { - { "stack", sizeof(STACK_OPCODE), SB|1, "", "i", + { "stack", sizeof(STACK_OPCODE), SK, 1, "", "i", (SUBR) stack_opcode_init, (SUBR) NULL, (SUBR) NULL }, - { "push", sizeof(PUSH_OPCODE), SB|3, "", "N", + { "push", sizeof(PUSH_OPCODE), SK, 3, "", "N", (SUBR) push_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL }, - { "pop", sizeof(POP_OPCODE), SB|3, "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "", + { "pop", sizeof(POP_OPCODE), SK, 3, "NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN", "", (SUBR) pop_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL }, - { "push_f", sizeof(PUSH_OPCODE), SB|3, "", "f", + { "push_f", sizeof(PUSH_OPCODE), SK, 3, "", "f", (SUBR) push_f_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL }, - { "pop_f", sizeof(POP_OPCODE), SB|3, "f", "", - (SUBR) pop_f_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL }, - /* ----------------------------------------------------------------------- */ - { "monitor", sizeof(MONITOR_OPCODE), 3, "mmmmmmmmmmmmmmmmmmmmmmmm", "", - (SUBR) monitor_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL } + { "pop_f", sizeof(POP_OPCODE), SK, 3, "f", "", + (SUBR) pop_f_opcode_init, (SUBR) notinit_opcode_stub_perf, (SUBR) NULL } }; -LINKAGE1(stackops_localops) +LINKAGE_BUILTIN(stackops_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/stdopcod.c csound-6.02~dfsg/Opcodes/stdopcod.c --- csound-5.17.11~dfsg/Opcodes/stdopcod.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/stdopcod.c 2014-01-07 16:53:48.000000000 +0000 @@ -33,8 +33,10 @@ STDOPCOD_GLOBALS *p; int err = 0; - if (UNLIKELY(csound->stdOp_Env != NULL)) - csound->Die(csound, Str("stdopcod.c: error: globals already allocated")); + if (UNLIKELY(csound->stdOp_Env != NULL)) { + csound->ErrorMsg(csound, Str("stdopcod.c: error: globals already allocated")); + return CSOUND_ERROR; + } csound->stdOp_Env = csound->Calloc(csound, sizeof(STDOPCOD_GLOBALS)); p = (STDOPCOD_GLOBALS*) csound->stdOp_Env; @@ -42,7 +44,7 @@ /* fout.c */ p->file_opened = (struct fileinTag*) NULL; p->file_num = -1; - p->buf = (MYFLT*) NULL; + /*p->buf = (MYFLT*) NULL;*/ /* ugnorman.c */ p->atsbufreadaddr = NULL; err |= ambicode_init_(csound); diff -Nru csound-5.17.11~dfsg/Opcodes/stdopcod.h csound-6.02~dfsg/Opcodes/stdopcod.h --- csound-5.17.11~dfsg/Opcodes/stdopcod.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/stdopcod.h 2014-01-07 16:53:48.000000000 +0000 @@ -29,7 +29,6 @@ #include "interlocks.h" - /* file structure for fout opcodes */ struct fileinTag { @@ -51,8 +50,8 @@ int file_max; int file_num; int32 fout_kreset; - MYFLT *buf; - int buf_size; + /* MYFLT *buf; + int buf_size; */ /* VL - now using per instance buffer */ /* oscbnk.c */ uint32 oscbnk_seed; int32 rnd31i_seed; diff -Nru csound-5.17.11~dfsg/Opcodes/stk/CMakeLists.txt csound-6.02~dfsg/Opcodes/stk/CMakeLists.txt --- csound-5.17.11~dfsg/Opcodes/stk/CMakeLists.txt 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/stk/CMakeLists.txt 2014-01-07 16:53:48.000000000 +0000 @@ -11,14 +11,14 @@ if(STK_INCLUDE_DIR) include_directories(${STK_INCLUDE_DIR}) - make_plugin(stk-ops stkOpcodes.cpp "stk") + make_plugin(stk-ops stkOpcodes.cpp ${STK_LIBRARY}) set_target_properties(stk-ops PROPERTIES OUTPUT_NAME stk) endif() else() - set(stk_remove_srcs + set(stk_remove_srcs src/InetWvIn.cpp src/InetWvOut.cpp src/Mutex.cpp src/RtAudio.cpp src/RtMidi.cpp @@ -50,21 +50,21 @@ make_plugin(stk "${stk_srcs}") - set(stkdefs "__STK_REALTIME__") + set(stkdefs "-D__STK_REALTIME__") if(APPLE) - list(APPEND stkdefs "__OS_MACOSX__") - list(REMOVE_ITEM stkdefs "__STK_REALTIME__") + list(APPEND stkdefs "-D__OS_MACOSX__") + list(REMOVE_ITEM stkdefs "-D__STK_REALTIME__") elseif(LINUX) - list(APPEND stkdefs "__OS_LINUX__") - list(APPEND stkdefs "__LINUX_ALSA__") + list(APPEND stkdefs "-D__OS_LINUX__") + list(APPEND stkdefs "-D__LINUX_ALSA__") elseif(WIN32) - list(APPEND stkdefs "__OS_WINDOWS__") + list(APPEND stkdefs "-D__OS_WINDOWS__") endif() if(BIG_ENDIAN) - list(APPEND stkdefs "__BIG_ENDIAN__") + list(APPEND stkdefs "-D__BIG_ENDIAN__") else() - list(APPEND stkdefs "__LITTLE_ENDIAN__") + list(APPEND stkdefs "-D__LITTLE_ENDIAN__") endif() add_compiler_flags(${stkdefs} TARGETS stk) diff -Nru csound-5.17.11~dfsg/Opcodes/stk/stkOpcodes.cpp csound-6.02~dfsg/Opcodes/stk/stkOpcodes.cpp --- csound-5.17.11~dfsg/Opcodes/stk/stkOpcodes.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/stk/stkOpcodes.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -23,11 +23,11 @@ * same terms as the Synthesis Tookit in C++ by Perry R. Cook and Gary P. Scavone. * * To compile these opcodes, copy the STK include, src, and rawwaves directories - * to the csound5/Opcodes/stk directory as follows: + * to the csound6/Opcodes/stk directory as follows: * - * csound5/Opcodes/stk/include - * csound5/Opcodes/stk/src - * csound5/Opcodes/stk/rawwaves + * csound6/Opcodes/stk/include + * csound6/Opcodes/stk/src + * csound6/Opcodes/stk/rawwaves * * Also, specify buildStkOpcodes=1 for SCons. * @@ -80,6 +80,11 @@ using namespace stk; +#define __BUILDING_LIBCSOUND +#include +#include +#include + #include #include #include @@ -88,10 +93,6 @@ using namespace std; -#include - -#include "csGblMtx.h" - static std::map > &getStkInstances() { static std::map > stkInstances; @@ -148,11 +149,11 @@ { if(!instrument) { - Stk::setSampleRate(csound->esr); + Stk::setSampleRate(csound->GetSr(csound)); instrument = new T(); getStkInstances()[csound].push_back(instrument); } - ksmps = csound->ksmps; + ksmps = OpcodeBase< STKInstrumentAdapter >::opds.insdshead->ksmps; instrument->noteOn(*ifrequency, *igain); released = false; oldkcontroller0 = -1.0; @@ -175,6 +176,8 @@ } int kontrol(CSOUND *csound) { + uint32_t offset = + OpcodeBase< STKInstrumentAdapter >::opds.insdshead->ksmps_offset; if(!released) { if(*kcontroller0 != oldkcontroller0 || *kvalue0 != oldkvalue0) @@ -225,14 +228,15 @@ oldkcontroller7 = *kcontroller7; oldkvalue7 = *kvalue7; } - for(size_t i = 0; i < ksmps; i++) + memset(aoutput, '\0', offset*sizeof(MYFLT)); + for(size_t i = offset; i < ksmps; i++) { aoutput[i] = instrument->tick(); } } else { - // memset(aoutput, 0, ksmps*sizeof(MYFLT)); + //memset(aoutput, 0, ksmps*sizeof(MYFLT)); for(size_t i = 0; i < ksmps; i++) { aoutput[i] = 0; @@ -291,11 +295,11 @@ int init(CSOUND *csound) { if(!instrument) { - Stk::setSampleRate(csound->esr); + Stk::setSampleRate(csound->GetSr(csound)); instrument = new T((StkFloat) 10.0); getStkInstances()[csound].push_back(instrument); } - ksmps = csound->ksmps; + ksmps = OpcodeBase< STKInstrumentAdapter1 >::opds.insdshead->ksmps; instrument->noteOn(*ifrequency, *igain); released = false; oldkcontroller0 = -1.0; @@ -318,6 +322,8 @@ } int kontrol(CSOUND *csound) { + uint32_t offset = + OpcodeBase< STKInstrumentAdapter1 >::opds.insdshead->ksmps_offset; if(!released) { if(*kcontroller0 != oldkcontroller0 || *kvalue0 != oldkvalue0) @@ -368,7 +374,8 @@ oldkcontroller7 = *kcontroller7; oldkvalue7 = *kvalue7; } - for(size_t i = 0; i < ksmps; i++) + memset(aoutput, '\0', offset*sizeof(MYFLT)); + for(size_t i = offset; i < ksmps; i++) { aoutput[i] = instrument->tick(); } @@ -392,6 +399,7 @@ { (char*)"STKBandedWG", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -402,6 +410,7 @@ { (char*)"STKBeeThree", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -412,6 +421,7 @@ { (char*)"STKBlowBotl", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -422,6 +432,7 @@ { (char*)"STKBlowHole", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -432,6 +443,7 @@ { (char*)"STKBowed", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -442,6 +454,7 @@ { (char*)"STKBrass", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -452,6 +465,7 @@ { (char*)"STKClarinet", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -462,6 +476,7 @@ { (char*)"STKDrummer", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -472,6 +487,7 @@ { (char*)"STKFlute", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -482,6 +498,7 @@ { (char*)"STKFMVoices", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -492,6 +509,7 @@ { (char*)"STKHevyMetl", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -502,6 +520,7 @@ { (char*)"STKMandolin", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -512,6 +531,7 @@ { (char*)"STKModalBar", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -522,6 +542,7 @@ { (char*)"STKMoog", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -532,6 +553,7 @@ { (char*)"STKPercFlut", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -542,6 +564,7 @@ { (char*)"STKPlucked", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -552,6 +575,7 @@ { (char*)"STKResonate", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -562,6 +586,7 @@ { (char*)"STKRhodey", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -572,6 +597,7 @@ { (char*)"STKSaxofony", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -582,6 +608,7 @@ { (char*)"STKShakers", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -592,6 +619,7 @@ { (char*)"STKSimple", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -602,6 +630,7 @@ { (char*)"STKSitar", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -612,6 +641,7 @@ { (char*)"STKStifKarp", sizeof(STKInstrumentAdapter1), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -622,6 +652,7 @@ { (char*)"STKTubeBell", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -632,6 +663,7 @@ { (char*)"STKVoicForm", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -642,6 +674,7 @@ { (char*)"STKWhistle", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -652,6 +685,7 @@ { (char*)"STKWurley", sizeof(STKInstrumentAdapter), + 0, 3, (char*)"a", (char*)"iiJJJJJJJJJJJJJJJJ", @@ -691,14 +725,15 @@ csound_global_mutex_lock(); Stk::setRawwavePath(path); csound_global_mutex_unlock(); - csound->Message(csound, - Str("RAWWAVE_PATH: %s\n"), Stk::rawwavePath().c_str()); + csound->DebugMsg(csound, + Str("RAWWAVE_PATH: %s\n"), Stk::rawwavePath().c_str()); } int status = 0; for(OENTRY *oentry = &oentries[0]; oentry->opname; oentry++) { status |= csound->AppendOpcode(csound, oentry->opname, - oentry->dsblksiz, oentry->thread, + oentry->dsblksiz, oentry->flags, + oentry->thread, oentry->outypes, oentry->intypes, (int (*)(CSOUND*,void*)) oentry->iopadr, (int (*)(CSOUND*,void*)) oentry->kopadr, @@ -720,4 +755,3 @@ } } - diff -Nru csound-5.17.11~dfsg/Opcodes/syncgrain.c csound-6.02~dfsg/Opcodes/syncgrain.c --- csound-5.17.11~dfsg/Opcodes/syncgrain.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/syncgrain.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include "syncgrain.h" #include "soundio.h" #include "interlocks.h" @@ -40,7 +40,7 @@ static int syncgrain_init(CSOUND *csound, syncgrain *p) { int size; - p->efunc = csound->FTFind(csound, p->ifn2); + p->efunc = csound->FTnp2Find(csound, p->ifn2); if (UNLIKELY(p->efunc == NULL)) return NOTOK; @@ -54,12 +54,12 @@ p->olaps = 2; size = (p->olaps) * sizeof(double); - if (p->index.auxp == NULL || p->index.size < size) + if (p->index.auxp == NULL || p->index.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->index); - if (p->envindex.auxp == NULL || p->envindex.size < size) + if (p->envindex.auxp == NULL || p->envindex.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->envindex); size = (p->olaps) * sizeof(int); - if (p->streamon.auxp == NULL || p->streamon.size < size) + if (p->streamon.auxp == NULL || p->streamon.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->streamon); p->count = 0; /* sampling period counter */ @@ -85,22 +85,29 @@ float start = p->start, frac = p->frac; double *index = (double *) p->index.auxp; double *envindex = (double *) p->envindex.auxp; - int vecpos, vecsize=csound->ksmps, firststream = p->firststream; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t vecpos, vecsize=CS_KSMPS; + int firststream = p->firststream; int numstreams = p->numstreams, olaps = p->olaps; int count = p->count, i,j, newstream; int datasize = p->datasize, envtablesize = p->envtablesize; pitch = *p->pitch; - fperiod = csound->esr/(*p->fr); - if (UNLIKELY(fperiod < 0)) fperiod = -fperiod; + fperiod = FABS(CS_ESR/(*p->fr)); + //if (UNLIKELY(fperiod < 0)) fperiod = -fperiod; amp = *p->amp; - grsize = csound->esr * *p->grsize; + grsize = CS_ESR * *p->grsize; if (UNLIKELY(grsize<1)) goto err1; envincr = envtablesize/grsize; prate = *p->prate; - - for (vecpos = 0; vecpos < vecsize; vecpos++) { + if (UNLIKELY(offset)) memset(output, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + vecsize -= early; + memset(&output[vecsize], '\0', early*sizeof(MYFLT)); + } + for (vecpos = offset; vecpos < vecsize; vecpos++) { sig = FL(0.0); /* if a grain has finished, clean up */ if (UNLIKELY((!streamon[firststream]) && (numstreams) )) { @@ -172,14 +179,14 @@ return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("grain size smaller than 1 sample\n")); } static int syncgrainloop_init(CSOUND *csound, syncgrainloop *p) { - p->efunc = csound->FTFind(csound, p->ifn2); + p->efunc = csound->FTnp2Find(csound, p->ifn2); if (UNLIKELY(p->efunc == NULL)) return NOTOK; @@ -196,17 +203,17 @@ if (*p->iskip == 0) { int size = (p->olaps) * sizeof(double); - if (p->index.auxp == NULL || p->index.size < size) + if (p->index.auxp == NULL || p->index.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->index); - if (p->envindex.auxp == NULL || p->envindex.size < size) + if (p->envindex.auxp == NULL || p->envindex.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->envindex); size = (p->olaps) * sizeof(int); - if (p->streamon.auxp == NULL || p->streamon.size > size) + if (p->streamon.auxp == NULL || p->streamon.size > (unsigned int)size) csound->AuxAlloc(csound, size, &p->streamon); p->count = 0; /* sampling period counter */ p->numstreams = 0; /* curr num of streams */ p->firststream = 0; /* streams index (first stream) */ - p->start = *p->startpos*(csound->GetSr(csound)); + p->start = *p->startpos*(CS_ESR); p->frac = 0.0f; p->firsttime = 1; } @@ -223,7 +230,10 @@ float start = p->start, frac = p->frac; double *index = (double *) p->index.auxp; double *envindex = (double *) p->envindex.auxp; - int vecpos, vecsize=csound->ksmps, firststream = p->firststream; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t vecpos, vecsize=CS_KSMPS; + int firststream = p->firststream; int numstreams = p->numstreams, olaps = p->olaps; int count = p->count, i,j, newstream; int datasize = p->datasize, envtablesize = p->envtablesize; @@ -231,7 +241,7 @@ int loop_end; int loopsize; int firsttime = p->firsttime; - MYFLT sr = csound->GetSr(csound); + MYFLT sr = CS_ESR; /* loop points & checks */ loop_start = (int) (*p->loop_start*sr); @@ -244,16 +254,21 @@ loop_start, loop_end, loopsize); */ pitch = *p->pitch; - fperiod = csound->esr/(*p->fr); - if (UNLIKELY(fperiod < 0)) fperiod = -fperiod; + fperiod = FABS(CS_ESR/(*p->fr)); + //if (UNLIKELY(fperiod < 0)) fperiod = -fperiod; amp = *p->amp; - grsize = csound->esr * *p->grsize; + grsize = CS_ESR * *p->grsize; if (UNLIKELY(grsize<1)) goto err1; if (loopsize <= 0) loopsize = grsize; envincr = envtablesize/grsize; prate = *p->prate; - for (vecpos = 0; vecpos < vecsize; vecpos++) { + if (UNLIKELY(offset)) memset(output, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + vecsize -= early; + memset(&output[vecsize], '\0', early*sizeof(MYFLT)); + } + for (vecpos = offset; vecpos < vecsize; vecpos++) { sig = FL(0.0); /* if a grain has finished, clean up */ if (UNLIKELY((!streamon[firststream]) && (numstreams) )) { @@ -335,7 +350,7 @@ p->firsttime = firsttime; return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("grain size smaller than 1 sample\n")); } @@ -345,7 +360,7 @@ typedef struct _filegrain { OPDS h; MYFLT *output[DGRAIN_MAXCHAN]; - MYFLT *fname; + STRINGDAT *fname; MYFLT *amp; MYFLT *fr; MYFLT *pitch; @@ -379,32 +394,31 @@ void *fd; MYFLT *buffer; SF_INFO sfinfo; - char *fname = csound->strarg2name(csound, NULL, p->fname, - "soundin.",p->XSTRCODE); + char *fname = p->fname->data; p->nChannels = (int) (p->OUTOCOUNT); if (UNLIKELY(p->nChannels < 1 || p->nChannels > DGRAIN_MAXCHAN)) { return csound->InitError(csound, Str("diskgrain: invalid number of channels")); } - p->efunc = csound->FTFind(csound, p->ifn2); + p->efunc = csound->FTnp2Find(csound, p->ifn2); if (UNLIKELY(p->efunc == NULL)) return NOTOK; p->olaps = (int) *p->ols + 1; - p->dataframes = (int)(*p->max*csound->esr*4); + p->dataframes = (int)(*p->max*CS_ESR*4); if (p->dataframes < MINFBUFSIZE) p->dataframes = MINFBUFSIZE; if (UNLIKELY(p->olaps < 2)) p->olaps = 2; size = (p->olaps) * sizeof(double); - if (p->index.auxp == NULL || p->index.size < size) + if (p->index.auxp == NULL || p->index.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->index); - if (p->envindex.auxp == NULL || p->envindex.size < size) + if (p->envindex.auxp == NULL || p->envindex.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->envindex); size = (p->olaps) * sizeof(int); - if (p->streamon.auxp == NULL || p->streamon.size < size) + if (p->streamon.auxp == NULL || p->streamon.size < (unsigned int)size) csound->AuxAlloc(csound, size, &p->streamon); if (p->buffer.auxp == NULL || p->buffer.size < (p->dataframes+1)*sizeof(MYFLT)*p->nChannels) @@ -426,7 +440,7 @@ } if (*p->ioff >= 0) - sf_seek(p->sf,*p->ioff * csound->esr, SEEK_SET); + sf_seek(p->sf,*p->ioff * CS_ESR, SEEK_SET); if (LIKELY(sf_read_MYFLT(p->sf,buffer,p->dataframes*p->nChannels/2) != 0)) { p->read1 = 1; @@ -444,7 +458,7 @@ p->start = 0.0f; p->frac = 0.0f; - p->pos = *p->ioff*csound->esr; + p->pos = *p->ioff*CS_ESR; p->trigger = 0.0f; p->flen = sfinfo.frames; @@ -462,7 +476,10 @@ float start = p->start, frac = p->frac, jump; double *index = (double *) p->index.auxp; double *envindex = (double *) p->envindex.auxp; - int vecpos, vecsize=csound->ksmps, firststream = p->firststream; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t vecpos, vecsize=CS_KSMPS; + int firststream = p->firststream; int numstreams = p->numstreams, olaps = p->olaps; int count = p->count, i,j, newstream; int datasize, hdatasize, envtablesize = p->envtablesize; @@ -479,16 +496,21 @@ hdatasize = hdataframes*chans; pitch = *p->pitch; - fperiod = csound->esr/(*p->fr); - if (UNLIKELY(fperiod < FL(0.0))) fperiod = -fperiod; + fperiod = FABS(CS_ESR/(*p->fr)); + //if (UNLIKELY(fperiod < FL(0.0))) fperiod = -fperiod; amp = *p->amp; - grsize = csound->esr * *p->grsize; + grsize = CS_ESR * *p->grsize; if (UNLIKELY(grsize<1)) goto err1; if (grsize > hdataframes) grsize = hdataframes; envincr = envtablesize/grsize; prate = *p->prate; - for (vecpos = 0; vecpos < vecsize; vecpos++) { + if (UNLIKELY(offset)) memset(output, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + vecsize -= early; + memset(&output[vecsize], '\0', early*sizeof(MYFLT)); + } + for (vecpos = offset; vecpos < vecsize; vecpos++) { /* sig = (MYFLT) 0; */ /* if a grain has finished, clean up */ if (UNLIKELY((!streamon[firststream]) && (numstreams) )) { @@ -680,18 +702,18 @@ p->pos = pos; return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("grain size smaller than 1 sample\n")); } static OENTRY localops[] = { -{"syncgrain", sizeof(syncgrain), TR|5, "a", "kkkkkiii", +{"syncgrain", sizeof(syncgrain), TR, 5, "a", "kkkkkiii", (SUBR)syncgrain_init, NULL,(SUBR)syncgrain_process }, -{"syncloop", sizeof(syncgrainloop), TR|5, "a", "kkkkkkkiiioo", +{"syncloop", sizeof(syncgrainloop), TR, 5, "a", "kkkkkkkiiioo", (SUBR)syncgrainloop_init, NULL,(SUBR)syncgrainloop_process }, -{"diskgrain", sizeof(filegrain), TR|5, DGRAIN_OUTTYPES, "Skkkkkiipo", +{"diskgrain", sizeof(filegrain), TR, 5, DGRAIN_OUTTYPES, "Skkkkkiipo", (SUBR)filegrain_init, NULL,(SUBR)filegrain_process } }; diff -Nru csound-5.17.11~dfsg/Opcodes/system_call.c csound-6.02~dfsg/Opcodes/system_call.c --- csound-5.17.11~dfsg/Opcodes/system_call.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/system_call.c 2014-01-07 16:53:48.000000000 +0000 @@ -27,7 +27,7 @@ OPDS h; MYFLT *res; MYFLT *ktrig; - MYFLT *commandLine; + STRINGDAT *commandLine; MYFLT *nowait; MYFLT prv_ktrig; @@ -45,12 +45,12 @@ { _flushall(); if ( (int)*p->nowait != 0 ) { - char *command = strdup( (char *)p->commandLine ); - _beginthread( threadroutine, 0, command ); + char *command = strdup(p->commandLine->data); + _beginthread( threadroutine, 0, command); *p->res = OK; } else { - *p->res = (MYFLT) system( (char *)p->commandLine ); + *p->res = (MYFLT) system( (char *)p->commandLine->data ); } return OK; } @@ -64,12 +64,12 @@ if ((*p->res = fork())) return OK; else { - if (UNLIKELY(system((char*)p->commandLine)<0)) exit(1); + if (UNLIKELY(system((char*)p->commandLine->data)<0)) exit(1); exit(0); } } else { - *p->res = (MYFLT)system((char*)p->commandLine); + *p->res = (MYFLT)system((char*)p->commandLine->data); return OK; } } @@ -106,9 +106,9 @@ #define S(x) sizeof(x) static OENTRY system_localops[] = { - { "system", S(SYSTEM), 3, "k", "kSO", (SUBR)call_system_set,(SUBR)call_system_k}, - { "system_i", S(SYSTEM), 1, "i", "iSo", (SUBR)call_system_i} + { "system", S(SYSTEM), 0, 3, "k", "kSO", + (SUBR)call_system_set,(SUBR)call_system_k}, + { "system_i", S(SYSTEM), 0, 1, "i", "iSo", (SUBR)call_system_i} }; -LINKAGE1(system_localops) - +LINKAGE_BUILTIN(system_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/tabsum.c csound-6.02~dfsg/Opcodes/tabsum.c --- csound-5.17.11~dfsg/Opcodes/tabsum.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/tabsum.c 2014-01-07 16:53:48.000000000 +0000 @@ -36,7 +36,7 @@ static int tabsuminit(CSOUND *csound, TABSUM *p) { - if (UNLIKELY((p->ftp = csound->FTFind(csound, p->itab)) == NULL)) { + if (UNLIKELY((p->ftp = csound->FTnp2Find(csound, p->itab)) == NULL)) { return csound->InitError(csound, Str("tabsum: No table")); } return OK; @@ -52,7 +52,8 @@ MYFLT *t; if (ftp==NULL) - return csound->PerfError(csound, Str("tabsum: Not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tabsum: Not initialised")); t = p->ftp->ftable; min = MYFLT2LRND(*p->kmin); max = MYFLT2LRND(*p->kmax); @@ -69,11 +70,11 @@ #define S(x) sizeof(x) static OENTRY tabsum_localops[] = { -{ "tabsum", S(TABSUM), 3, "k", "iOO", +{ "tabsum", S(TABSUM), 0, 3, "k", "iOO", (SUBR)tabsuminit, (SUBR)tabsum }, }; -LINKAGE1(tabsum_localops) +LINKAGE_BUILTIN(tabsum_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/tabvars.c csound-6.02~dfsg/Opcodes/tabvars.c --- csound-5.17.11~dfsg/Opcodes/tabvars.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/tabvars.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,247 +0,0 @@ -/* - tabvars.c: - - Copyright (C) 2011 John ffitch - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -// #include "csdl.h" -#include "csoundCore.h" -#include "interlocks.h" - - -typedef struct { - OPDS h; - TABDAT *ans, *left, *right; -} TABARITH; - -typedef struct { - OPDS h; - MYFLT *ans; - TABDAT *tab; -} TABQUERY; - -typedef struct { - OPDS h; - TABDAT *tab; - MYFLT *kfn; -} TABCOPY; - -typedef struct { - OPDS h; - TABDAT *tab; - MYFLT *kmin, *kmax; - MYFLT *kstart, *kend; -} TABSCALE; - -static int tabarithset(CSOUND *csound, TABARITH *p) -{ - if (LIKELY(p->ans->data && p->left->data && p->right->data)) return OK; - return csound->InitError(csound, Str("t-variable not initialised")); -} - -static int tabadd(CSOUND *csound, TABARITH *p) -{ - TABDAT *ans = p->ans; - TABDAT *l = p->left; - TABDAT *r = p->right; - int size = ans->size; - int i; - - if (l->sizesize; - if (r->sizesize; - for (i=0; i<=size; i++) - ans->data[i] = l->data[i] + r->data[i]; - return OK; -} - -static int tabmult(CSOUND *csound, TABARITH *p) -{ - TABDAT *ans = p->ans; - TABDAT *l = p->left; - TABDAT *r = p->right; - int size = ans->size; - int i; - - if (l->sizesize; - if (r->sizesize; - for (i=0; i<=size; i++) - ans->data[i] = l->data[i] * r->data[i]; - return OK; -} - -static int tabqset(CSOUND *csound, TABQUERY *p) -{ - if (LIKELY(p->tab->data)) return OK; - return csound->InitError(csound, Str("t-variable not initialised")); -} - -static int tabmax(CSOUND *csound, TABQUERY *p) -{ - TABDAT *t = p->tab; - int i, size = t->size; - MYFLT ans = t->data[0]; - - for (i=1; i<=size; i++) - if (t->data[i]>ans) ans = t->data[i]; - *p->ans = ans; - return OK; -} - -static int tabmin(CSOUND *csound, TABQUERY *p) -{ - TABDAT *t = p->tab; - int i, size = t->size; - MYFLT ans = t->data[0]; - - for (i=1; i<=size; i++) - if (t->data[i]data[i]; - *p->ans = ans; - return OK; -} - -static int tabsum(CSOUND *csound, TABQUERY *p) -{ - TABDAT *t = p->tab; - int i, size = t->size; - MYFLT ans = FL(0.0); - - for (i=1; i<=size; i++) - ans += t->data[i]; - *p->ans = ans; - return OK; -} - -static int tabscaleset(CSOUND *csound, TABSCALE *p) -{ - if (LIKELY(p->tab->data)) return OK; - return csound->InitError(csound, Str("t-variable not initialised")); -} - -static int tabscale(CSOUND *csound, TABSCALE *p) -{ - MYFLT min = *p->kmin, max = *p->kmax; - int strt = (int)MYFLT2LRND(*p->kstart), end = (int)MYFLT2LRND(*p->kend); - TABDAT *t = p->tab; - MYFLT tmin = t->data[strt]; - MYFLT tmax = tmin; - int i; - MYFLT range; - - // Correct start an dening points - if (end<0) end = t->size; - else if (end>t->size) end = t->size; - else if (end<0) end = 0; - if (strt<0) strt = 0; - else if (strt>t->size) strt = t->size; - if (enddata[i]data[i]; - if (t->data[i]>tmax) tmax = t->data[i]; - } - range = (max-min)/(tmax-tmin); - for (i=strt; idata[i] = (t->data[i]-tmin)*range + min; - } - return OK; -} - -typedef struct { - OPDS h; - TABDAT *dst; - TABDAT *src; - int len; -} TABCPY; - -static int tabcopy_set(CSOUND *csound, TABCPY *p) -{ - int sizes,sized; - if (UNLIKELY(p->src->data==NULL)) - return csound->InitError(csound, Str("t-variable not initialised")); - if (UNLIKELY(p->dst->data==NULL)) - return csound->InitError(csound, Str("t-variable not initialised")); - sizes = p->src->size; - sized = p->dst->size; - p->len = sizeof(MYFLT)*(sizes>sized ? sized : sizes); - return OK; -} - -static int tabcopy(CSOUND *csound, TABCPY *p) -{ - memmove(p->dst->data, p->src->data, p->len); - return OK; -} - -static int tab2ftab(CSOUND *csound, TABCOPY *p) -{ - FUNC *ftp; - int fsize; - MYFLT *fdata; - int tlen = p->tab->size; - if (UNLIKELY(p->tab->data==NULL)) - return csound->PerfError(csound, Str("t-var not initialised")); - if (UNLIKELY((ftp = csound->FTFindP(csound, p->kfn)) == NULL)) - return csound->PerfError(csound, Str("No table for copy2ftab")); - fsize = ftp->flen; - fdata = ftp->ftable; - if (fsizetab->data, sizeof(MYFLT)*tlen); - return OK; -} - -static int ftab2tab(CSOUND *csound, TABCOPY *p) -{ - FUNC *ftp; - int fsize; - MYFLT *fdata; - int tlen = p->tab->size; - if (UNLIKELY(p->tab->data==NULL)) - return csound->PerfError(csound, Str("t-var not initialised")); - if (UNLIKELY((ftp = csound->FTFindP(csound, p->kfn)) == NULL)) - return csound->PerfError(csound, Str("No table for copy2ftab")); - fsize = ftp->flen; - fdata = ftp->ftable; - if (fsizetab->data, fdata, sizeof(MYFLT)*tlen); - return OK; -} - - - -static OENTRY tabvars_localops[] = -{ - { "plustab", sizeof(TABARITH), 3, "t", "tt", (SUBR) tabarithset, (SUBR) tabadd }, - { "multtab", sizeof(TABARITH), 3, "t", "tt", (SUBR) tabarithset, (SUBR) tabmult }, - { "maxtab", sizeof(TABQUERY), 3, "k", "t", (SUBR) tabqset, (SUBR) tabmax }, - { "mintab", sizeof(TABQUERY), 3, "k", "t", (SUBR) tabqset, (SUBR) tabmin }, - { "sumtab", sizeof(TABQUERY), 3, "k", "t", (SUBR) tabqset, (SUBR) tabsum }, - { "scalet", sizeof(TABSCALE), 3, "", "tkkOJ",(SUBR) tabscaleset,(SUBR) tabscale }, - { "#copytab", sizeof(TABCPY), 3, "t", "t", (SUBR) tabcopy_set, (SUBR)tabcopy }, - { "copy2ftab", sizeof(TABCOPY), TW|2, "", "tk", NULL, (SUBR) tab2ftab }, - { "copy2ttab", sizeof(TABCOPY), TR|2, "", "tk", NULL, (SUBR) ftab2tab } -}; -// reverse, scramble, mirror, stutter, rotate, ... -// jpff: stutter is an interesting one (very musical). It basically -// randomly repeats (holds) values based on a probability parameter - - -LINKAGE1(tabvars_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/tl/fractalnoise.cpp csound-6.02~dfsg/Opcodes/tl/fractalnoise.cpp --- csound-5.17.11~dfsg/Opcodes/tl/fractalnoise.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/tl/fractalnoise.cpp 2014-01-07 16:54:20.000000000 +0000 @@ -29,6 +29,10 @@ #define min(x,y) (((x)<(y)) ? (x) : (y)) #define dv2_31 (FL(4.656612873077392578125e-10)) +typedef struct opdata{ + OPDS h; +} OPDATA; + inline int lsr (int x, int n) { return int(((unsigned int)x) >> n); @@ -36,11 +40,11 @@ /* VECTOR INTRINSICS */ -inline void *aligned_calloc(size_t nmemb, size_t size) -{ - return (void*)(((unsigned long)(calloc((nmemb*size)+15, - (sizeof(char))))+15) & 0xfffffff0); -} +//inline void *aligned_calloc(size_t nmemb, size_t size) +//{ +// return (void*)(((unsigned long)(calloc((nmemb*size)+15, +// (sizeof(char))))+15) & 0xfffffff0); +//} /* ABSTRACT USER INTERFACE */ @@ -142,7 +146,7 @@ virtual int getNumOutputs() = 0; virtual void buildUserInterface(UserInterface* userInterface) = 0; virtual void init(int samplingRate) = 0; - virtual void compute(CSOUND* csound, MYFLT* output) = 0; + virtual void compute(CSOUND* csound, MYFLT* output, void *p) = 0; }; /* FAUST generated code */ @@ -302,9 +306,11 @@ FL(0.0), FL(10.0), FL(0.01)); userInterface->closeBox(); } - virtual void compute (CSOUND* csound, MYFLT* output) + virtual void compute (CSOUND* csound, MYFLT* output, void *p) { - int nn = csound->ksmps; + int nn = ((OPDATA*)p)->h.insdshead->ksmps; + uint32_t offset = ((OPDATA *) p)->h.insdshead->ksmps_offset; + uint32_t early = ((OPDATA *) p)->h.insdshead->ksmps_no_end; MYFLT fSlow0 = POWER(FL(10.0),(FL(0.08333333333333333) * fslider0)); MYFLT fSlow1 = EXP(-(fConst3 * fSlow0)); MYFLT fSlow2 = EXP(-(fConst5 * fSlow0)); @@ -337,21 +343,33 @@ MYFLT fSlow29 = (- EXP(-(fConst1 * fSlow0))); MYFLT fSlow30 = fslider1; MYFLT* output0 = output; - for (int i=0; irandSeed1 + (1103515245 * iRec8[1])); - fRec7[0] = -((fConst8 * fRec7[2]) + (fConst7 * fRec7[1])) + (iRec8[0] * dv2_31); + if (UNLIKELY(offset)) memset(output0, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nn -= early; + memset(&output0[nn], '\0', early*sizeof(MYFLT)); + } + for (int i=offset; iGetRandSeed(csound, 1) + (1103515245 * iRec8[1])); + fRec7[0] = -((fConst8 * fRec7[2]) + (fConst7 * fRec7[1])) + + (iRec8[0] * dv2_31); fRec6[0] = (0 - (((fConst14 * fRec6[2]) + (fConst13 * fRec6[1])) - - ((fSlow4 * fRec7[1]) + (fRec7[0] + (fSlow3 * fRec7[2]))))); + - ((fSlow4 * fRec7[1]) + + (fRec7[0] + (fSlow3 * fRec7[2]))))); fRec5[0] = (0 - (((fConst20 * fRec5[2]) + (fConst19 * fRec5[1])) - - ((fSlow8 * fRec6[1]) + (fRec6[0] + (fSlow7 * fRec6[2]))))); + - ((fSlow8 * fRec6[1]) + (fRec6[0] + + (fSlow7 * fRec6[2]))))); fRec4[0] = (0 - (((fConst26 * fRec4[2]) + (fConst25 * fRec4[1])) - - ((fSlow12 * fRec5[1]) + (fRec5[0] + (fSlow11 * fRec5[2]))))); + - ((fSlow12 * fRec5[1]) + + (fRec5[0] + (fSlow11 * fRec5[2]))))); fRec3[0] = (0 - (((fConst32 * fRec3[2]) + (fConst31 * fRec3[1])) - - ((fSlow16 * fRec4[1]) + (fRec4[0] + (fSlow15 * fRec4[2]))))); + - ((fSlow16 * fRec4[1]) + + (fRec4[0] + (fSlow15 * fRec4[2]))))); fRec2[0] = (0 - (((fConst38 * fRec2[2]) + (fConst37 * fRec2[1])) - - ((fSlow20 * fRec3[1]) + (fRec3[0] + (fSlow19 * fRec3[2]))))); + - ((fSlow20 * fRec3[1]) + + (fRec3[0] + (fSlow19 * fRec3[2]))))); fRec1[0] = (0 - (((fConst44 * fRec1[2]) + (fConst43 * fRec1[1])) - - ((fSlow24 * fRec2[1]) + (fRec2[0] + (fSlow23 * fRec2[2]))))); + - ((fSlow24 * fRec2[1]) + + (fRec2[0] + (fSlow23 * fRec2[2]))))); fRec0[0] = (((fSlow28 * fRec1[1]) + (fRec1[0] + (fSlow27 * fRec1[2]))) - (fConst2 * fRec0[1])); output0[i] = (MYFLT)(fSlow30 * (fRec0[0] + (fSlow29 * fRec0[1]))); @@ -393,24 +411,24 @@ { p->faust = new mydsp; p->cs_interface = new csUI; - p->faust->init((int)csound->esr); + p->faust->init((int)csound->GetSr(csound)); p->faust->buildUserInterface(p->cs_interface); csound->RegisterDeinitCallback(csound, p, - (int (*)(CSOUND*, void*)) fractalnoise_cleanup); + (int (*)(CSOUND*, void*)) fractalnoise_cleanup); return OK; } int fractalnoise_process(CSOUND *csound, FRACTALNOISE *p) { p->cs_interface->updateCtrlZones(p->kamp, p->kbeta); - p->faust->compute(csound, p->out); + p->faust->compute(csound, p->out, p); return OK; } static OENTRY localops[] = { - { (char*)"fractalnoise", sizeof(FRACTALNOISE), 5, (char*)"a", (char*)"kk", + { (char*)"fractalnoise", sizeof(FRACTALNOISE), 0, 5, (char*)"a", (char*)"kk", (SUBR)fractalnoise_init, NULL, (SUBR)fractalnoise_process }, - { 0, 0, 0, 0, 0, 0, 0, 0, } + { 0, 0, 0, 0, 0, 0, 0, 0, 0} }; PUBLIC int csoundModuleCreate(CSOUND *csound) @@ -425,6 +443,7 @@ status |= csound->AppendOpcode(csound, oentry->opname, oentry->dsblksiz, + oentry->flags, oentry->thread, oentry->outypes, oentry->intypes, diff -Nru csound-5.17.11~dfsg/Opcodes/tl/sc_noise.c csound-6.02~dfsg/Opcodes/tl/sc_noise.c --- csound-5.17.11~dfsg/Opcodes/tl/sc_noise.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/tl/sc_noise.c 2014-01-07 16:53:48.000000000 +0000 @@ -71,7 +71,8 @@ static int dust_process_arate(CSOUND *csound, DUST *p) { - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, density, thresh, scale; out = p->out; density = *p->kdensity; @@ -85,7 +86,8 @@ thresh = p->thresh; scale = p->scale; } - for (n=0; nrand = csoundRand31(&p->rand); r = (MYFLT)p->rand * dv2_31; @@ -116,7 +118,8 @@ static int dust2_process_arate(CSOUND *csound, DUST *p) { - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out, density, thresh, scale; out = p->out; density = *p->kdensity; @@ -130,7 +133,8 @@ thresh = p->thresh; scale = p->scale; } - for (n=0; nrand = csoundRand31(&p->rand); r = (MYFLT)p->rand * dv2_31; @@ -163,7 +167,7 @@ p->frq0 = *p->kfrq; frq = (*p->kfrq > FL(0.001) ? *p->kfrq : FL(0.001)); dev = *p->kdev; - nextsamps = (int)(csound->esr / frq); + nextsamps = (int)(csound->GetSr(csound) / frq); p->rand = csoundRand31(&p->rand); r1 = (MYFLT)p->rand * dv2_31; p->rand = csoundRand31(&p->rand); @@ -191,16 +195,18 @@ static int gausstrig_process_arate(CSOUND* csound, GAUSSTRIG *p) { - int n, nn = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t n, nsmps = CS_KSMPS; MYFLT *out = p->out; - for (n=0; ncount <= 0) { int nextsamps; MYFLT nextcount, frq, dev, r1, r2; p->frq0 = *p->kfrq; frq = (*p->kfrq > FL(0.001) ? *p->kfrq : FL(0.001)); dev = *p->kdev; - nextsamps = (int)(csound->esr / frq); + nextsamps = (int)(csound->GetSr(csound) / frq); p->rand = csoundRand31(&p->rand); r1 = (MYFLT)p->rand * dv2_31; p->rand = csoundRand31(&p->rand); @@ -231,18 +237,18 @@ { "dust", 0xffff }, { "dust2", 0xffff }, { "gausstrig", 0xffff }, - { "dust.k", sizeof(DUST), 3, "k", "kk", + { "dust.k", sizeof(DUST), 0,3, "k", "kk", (SUBR)dust_init, (SUBR)dust_process_krate, NULL }, - { "dust.a", sizeof(DUST), 5, "a", "kk", + { "dust.a", sizeof(DUST), 0,5, "a", "kk", (SUBR)dust_init, NULL, (SUBR)dust_process_arate }, - { "dust2.k", sizeof(DUST), 3, "k", "kk", + { "dust2.k", sizeof(DUST), 0,3, "k", "kk", (SUBR)dust_init, (SUBR)dust2_process_krate, NULL }, - { "dust2.a", sizeof(DUST), 5, "a", "kk", + { "dust2.a", sizeof(DUST), 0,5, "a", "kk", (SUBR)dust_init, NULL, (SUBR)dust2_process_arate }, - { "gausstrig.k", sizeof(GAUSSTRIG), 3, "k", "kkko", + { "gausstrig.k", sizeof(GAUSSTRIG), 0,3, "k", "kkko", (SUBR)gausstrig_init, (SUBR)gausstrig_process_krate, NULL }, - { "gausstrig.a", sizeof(GAUSSTRIG), 5, "a", "kkko", + { "gausstrig.a", sizeof(GAUSSTRIG), 0,5, "a", "kkko", (SUBR)gausstrig_init, NULL, (SUBR)gausstrig_process_arate } }; -LINKAGE1(scnoise_localops) +LINKAGE_BUILTIN(scnoise_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/ugakbari.c csound-6.02~dfsg/Opcodes/ugakbari.c --- csound-5.17.11~dfsg/Opcodes/ugakbari.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugakbari.c 2014-01-07 16:53:48.000000000 +0000 @@ -103,13 +103,13 @@ /* opcode library entries */ static OENTRY ugakbari_localops[] = { - { "scale", sizeof(scale), 2, "k", "kkk", NULL, (SUBR)scale_process, NULL }, - { "expcurve", sizeof(expcurve), 2, "k", "kk", NULL, + { "scale", sizeof(scale), 0, 2, "k", "kkk", NULL, (SUBR)scale_process, NULL }, + { "expcurve", sizeof(expcurve), 0, 2, "k", "kk", NULL, (SUBR)expcurve_perf, NULL }, - { "logcurve", sizeof(logcurve), 2, "k", "kk", NULL, + { "logcurve", sizeof(logcurve), 0, 2, "k", "kk", NULL, (SUBR)logcurve_perf, NULL }, - { "gainslider", sizeof(gainslider), 2, "k", "k", NULL, + { "gainslider", sizeof(gainslider), 0, 2, "k", "k", NULL, (SUBR)gainslider_perf, NULL } }; -LINKAGE1(ugakbari_localops) +LINKAGE_BUILTIN(ugakbari_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/ugens7.c csound-6.02~dfsg/Opcodes/ugens7.c --- csound-5.17.11~dfsg/Opcodes/ugens7.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugens7.c 2014-01-07 16:53:48.000000000 +0000 @@ -22,7 +22,7 @@ 02111-1307 USA */ -#include "csdl.h" /* UGENS7.C */ +#include "stdopcod.h" /* UGENS7.C */ #include "ugens7.h" #include @@ -37,7 +37,7 @@ (p->ftp2 = csound->FTFind(csound, p->ifnb)) != NULL) { OVRLAP *ovp, *nxtovp; int32 olaps; - p->durtogo = (int32)(*p->itotdur * csound->esr); + p->durtogo = (int32)(*p->itotdur * CS_ESR); if (!skip) { /* legato: skip all memory management */ if (*p->iphs == FL(0.0)) /* if fundphs zero, */ p->fundphs = MAXLEN; /* trigger new FOF */ @@ -89,7 +89,10 @@ OVRLAP *ovp; FUNC *ftp1, *ftp2; MYFLT *ar, *amp, *fund, *form; - int32 n, nsmps = csound->ksmps, fund_inc, form_inc; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 fund_inc, form_inc; MYFLT v1, fract ,*ftab; if (UNLIKELY(p->auxch.auxp==NULL)) goto err1; /* RWD fix */ @@ -100,8 +103,13 @@ ftp1 = p->ftp1; ftp2 = p->ftp2; fund_inc = (int32)(*fund * csound->sicvt); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } form_inc = (int32)(*form * csound->sicvt); - for (n=0; nfundphs & MAXLEN) { /* if phs has wrapped */ p->fundphs &= PHMASK; if ((ovp = p->basovrlap.nxtfree) == NULL) goto err2; @@ -166,9 +174,11 @@ } return OK; err1: - return csound->PerfError(csound, Str("fof: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("fof: not initialised")); err2: - return csound->PerfError(csound, Str("FOF needs more overlaps")); + return csound->PerfError(csound, p->h.insdshead, + Str("FOF needs more overlaps")); } static int newpulse(CSOUND *csound, @@ -177,7 +187,7 @@ MYFLT octamp = *amp, oct; int32 rismps, newexp = 0; - if ((ovp->timrem = (int32)(*p->kdur * csound->esr)) > p->durtogo && + if ((ovp->timrem = (int32)(*p->kdur * CS_ESR)) > p->durtogo && (*p->iskip==FL(0.0))) /* ringtime */ return(0); if ((oct = *p->koct) > FL(0.0)) { /* octaviation */ @@ -218,7 +228,7 @@ } ovp->curamp = octamp * p->preamp; /* set startamp */ ovp->expamp = p->expamp; - if ((ovp->dectim = (int32)(*p->kdec * csound->esr)) > 0) /* fnb dec */ + if ((ovp->dectim = (int32)(*p->kdec * CS_ESR)) > 0) /* fnb dec */ ovp->decinc = (int32)(csound->sicvt / *p->kdec); ovp->decphs = PHMASK; if (!p->foftype) { @@ -250,9 +260,9 @@ return csound->InitError(csound, Str("Minimum frequency too low")); } if (p->auxch.auxp == NULL || minfrq < p->minfrq) { - int32 nbufs = (int32)(csound->ekr * FL(3.0) / minfrq) + 1; - int32 nbufsmps = nbufs * csound->ksmps; - int32 maxprd = (int32)(csound->esr / minfrq); + int32 nbufs = (int32)(CS_EKR * FL(3.0) / minfrq) + 1; + int32 nbufsmps = nbufs * CS_KSMPS; + int32 maxprd = (int32)(CS_ESR / minfrq); int32 totalsiz = nbufsmps * 5 + maxprd; /* Surely 5! not 4 */ csound->AuxAlloc(csound, (size_t)totalsiz * sizeof(MYFLT), &p->auxch); p->bufp = (MYFLT *) p->auxch.auxp; @@ -265,7 +275,7 @@ p->lomaxdist = maxprd; p->minfrq = minfrq; } - if ((p->autoktim = MYFLT2LONG(*p->iptrkprd * csound->ekr)) < 1) + if ((p->autoktim = MYFLT2LONG(*p->iptrkprd * CS_EKR)) < 1) p->autoktim = 1; p->autokcnt = 1; /* init for immediate autocorr attempt */ p->lsicvt = FL(65536.0) * csound->onedsr; @@ -295,7 +305,10 @@ MYFLT sum, minval, *minqp = NULL, *minq1, *minq2, *endp; MYFLT *pulstrt, lin1, lin2, lin3; int32 cnt1, cnt2, cnt3; - int32 nn, n, nsmps, phase1, phase2, phsinc1, phsinc2, period; + int32 nn, phase1, phase2, phsinc1, phsinc2, period; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; inp1 = p->inp1; inp2 = p->inp2; @@ -304,7 +317,7 @@ qval = p->prvq; if (*p->kest != p->prvest && *p->kest != FL(0.0)) { /* if new pitch estimate */ - MYFLT estperiod = csound->esr / *p->kest; + MYFLT estperiod = CS_ESR / *p->kest; double b = 2.0 - cos((double)(*p->kest * csound->tpidsr)); p->c2 = (MYFLT)(b - sqrt(b*b - 1.0)); /* recalc lopass coefs */ p->c1 = FL(1.0) - p->c2; @@ -325,12 +338,12 @@ } c1 = p->c1; c2 = p->c2; - for (src1 = p->asig, nsmps = csound->ksmps; nsmps--; src1++) { - *inp1++ = *inp2++ = *src1; /* dbl store the wavform */ - if (*src1 > FL(0.0)) - qval = c1 * *src1 + c2 * qval; /* & its half-wave rect */ + for (src1 = p->asig, n = offset; n FL(0.0)) + qval = c1 * src1[n] + c2 * qval; /* & its half-wave rect */ else qval = c2 * qval; - *inq1++ = *inq2++ = qval; + inq1[n] = inq2[n] = qval; } if (!(--p->autokcnt)) { /* if time for new autocorr */ MYFLT *mid1, *mid2, *src4; @@ -398,10 +411,10 @@ if (period==0) { csound->Warning(csound, Str("Period zero\n")); outp = p->ar; - memset(outp, 0, sizeof(MYFLT)*csound->ksmps); + memset(outp, 0, sizeof(MYFLT)*CS_KSMPS); return OK; } - while (src1 + csound->ksmps > inp2) /* if not enough smps presnt */ + while (src1 + CS_KSMPS > inp2) /* if not enough smps presnt */ src1 -= period; /* back up 1 prd */ pulstrt = src1; /* curr available pulse beg */ @@ -419,8 +432,12 @@ phsinc1 = (int32)(*p->kfrq1 * p->lsicvt); phsinc2 = (int32)(*p->kfrq2 * p->lsicvt); outp = p->ar; - nsmps = csound->ksmps; - for (n=0; npnt11) { @@ -581,9 +598,9 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "fof", S(FOFS), TR|5, "a","xxxkkkkkiiiiooo",(SUBR)fofset,NULL,(SUBR)fof }, -{ "fof2", S(FOFS), TR|5, "a","xxxkkkkkiiiikko",(SUBR)fofset2,NULL,(SUBR)fof }, -{ "harmon", S(HARMON), 5, "a", "akkkkiii",(SUBR)harmset,NULL, (SUBR)harmon } +{ "fof", S(FOFS), TR, 5, "a","xxxkkkkkiiiiooo",(SUBR)fofset,NULL,(SUBR)fof }, +{ "fof2", S(FOFS), TR, 5, "a","xxxkkkkkiiiikko",(SUBR)fofset2,NULL,(SUBR)fof }, +{ "harmon", S(HARMON), 0,5, "a", "akkkkiii",(SUBR)harmset,NULL, (SUBR)harmon } }; int ugens7_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/ugens8.c csound-6.02~dfsg/Opcodes/ugens8.c --- csound-5.17.11~dfsg/Opcodes/ugens8.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugens8.c 2014-01-07 16:53:48.000000000 +0000 @@ -36,19 +36,25 @@ /********************************************/ #define WLN 1 /* time window is WLN*2*ksmps long */ -#define OPWLEN (2*WLN*csound->ksmps) /* manifest used for final time wdw */ +#define OPWLEN (2*WLN*CS_KSMPS) /* manifest used for final time wdw */ -int pvset(CSOUND *csound, PVOC *p) +int pvset_(CSOUND *csound, PVOC *p, int stringname) { - int i; - int32 memsize; + unsigned int i; + int32 memsize; char pvfilnam[MAXNAME]; int size; /* THESE SHOULD BE SAVED IN PVOC STRUCT */ FUNC *AmpGateFunc = NULL; p->pp = PVOC_GetGlobals(csound); - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (UNLIKELY(pvx_loadfile(csound, pvfilnam, p) != OK)) return NOTOK; @@ -76,9 +82,9 @@ } } p->mems = memsize; - p->frPktim = ((MYFLT)csound->ksmps)/((MYFLT) p->frInc); + p->frPktim = ((MYFLT)CS_KSMPS)/((MYFLT) p->frInc); /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr/((MYFLT) p->frInc); + p->frPrtim = CS_ESR/((MYFLT) p->frInc); /* factor by which to mulitply 'real' time index to get frame index */ size = pvfrsiz(p); /* size used in def of OPWLEN ? */ /* 2*incr/OPWLEN scales down for win ovlp, windo'd 1ce (but 2ce?) */ @@ -94,12 +100,12 @@ if (UNLIKELY((OPWLEN/2 + 1)>PVWINLEN )) { return csound->InitError(csound, Str("ksmps of %d needs wdw of %d, " "max is %d for pv %s"), - csound->ksmps, (OPWLEN/2 + 1), PVWINLEN, + CS_KSMPS, (OPWLEN/2 + 1), PVWINLEN, pvfilnam); } if (*p->igatefun > 0) - if (UNLIKELY((AmpGateFunc = csound->FTFind(csound, p->igatefun)) == NULL)) + if (UNLIKELY((AmpGateFunc = csound->FTnp2Find(csound, p->igatefun)) == NULL)) return NOTOK; p->AmpGateFunc = AmpGateFunc; @@ -126,6 +132,15 @@ return OK; } +int pvset(CSOUND *csound, PVOC *p){ + return pvset_(csound,p,0); +} + +int pvset_S(CSOUND *csound, PVOC *p){ + return pvset_(csound,p,1); +} + + int pvoc(CSOUND *csound, PVOC *p) { MYFLT *ar = p->rslt; @@ -134,10 +149,13 @@ MYFLT *buf2 = p->dsBuf; int asize = pvdasiz(p); /* new */ int size = pvfrsiz(p); - int i, buf2Size, outlen; + int buf2Size, outlen; int circBufSize = PVFFTSIZE; int specwp = (int)*p->ispecwp; /* spectral warping flag */ MYFLT pex, scaleFac; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; if (UNLIKELY(p->auxch.auxp == NULL)) goto err1; pex = *p->kfmod; @@ -145,7 +163,7 @@ /* use outlen to check window/krate/transpose combinations */ if (UNLIKELY(outlen>PVFFTSIZE)) /* Maximum transposition down is one octave */ goto err2; /* ..so we won't run into buf2Size problems */ - if (UNLIKELY(outlen<2*csound->ksmps)) /* minimum post-squeeze windowlength */ + if (UNLIKELY(outlen<(int)(2*nsmps))) /* minimum post-squeeze windowlength */ goto err3; buf2Size = OPWLEN; /* always window to same length after DS */ if (UNLIKELY((frIndx = *p->ktimpnt * p->frPrtim) < 0)) goto err4; @@ -161,14 +179,14 @@ if (*p->igatefun > 0) PvAmpGate(buf,size, p->AmpGateFunc, p->PvMaxAmp); - FrqToPhase(buf, asize, pex * (MYFLT) csound->ksmps, p->asr, + FrqToPhase(buf, asize, pex * (MYFLT) nsmps, p->asr, FL(0.5) * ((pex / p->lastPex) - FL(1.0))); /* accumulate phase and wrap to range -PI to PI */ RewrapPhase(buf, asize, p->lastPhase); if (specwp > 0){ /* RWD: THIS CAUSED MASSIVE MEMORY ERROR, BUT DOESN'T WORK ANYWAY */ - PreWarpSpec(p->pp, buf, asize, pex, (MYFLT *)p->memenv.auxp); + PreWarpSpec(buf, asize, pex, (MYFLT *)p->memenv.auxp); } Polar2Real_PVOC(csound, buf, size); @@ -180,30 +198,38 @@ memcpy(buf2, buf + (int) ((size - buf2Size) >> 1), sizeof(MYFLT) * buf2Size); ApplyHalfWin(buf2, p->window, buf2Size); - addToCircBuf(buf2, p->outBuf, p->opBpos, csound->ksmps, circBufSize); - writeClrFromCircBuf(p->outBuf, ar, p->opBpos, csound->ksmps, circBufSize); - p->opBpos += csound->ksmps; + addToCircBuf(buf2, p->outBuf, p->opBpos, nsmps, circBufSize); + writeClrFromCircBuf(p->outBuf, ar, p->opBpos, nsmps, circBufSize); + p->opBpos += nsmps; if (p->opBpos > circBufSize) p->opBpos -= circBufSize; - addToCircBuf(buf2 + csound->ksmps, p->outBuf, - p->opBpos, buf2Size - csound->ksmps, circBufSize); + addToCircBuf(buf2 + nsmps, p->outBuf, + p->opBpos, buf2Size - nsmps, circBufSize); p->lastPex = pex; /* needs to know last pitchexp to update phase */ /* scale output */ scaleFac = p->scale; if (pex > FL(1.0)) scaleFac /= pex; - for (i = 0; i < csound->ksmps; i++) + if (UNLIKELY(offset)) memset(p->rslt, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->rslt[nsmps], '\0', early*sizeof(MYFLT)); + } + for (i = offset; i < nsmps; i++) p->rslt[i] *= scaleFac; return OK; err1: - return csound->PerfError(csound, Str("pvoc: not initialised")); + return csound->PerfError(csound, p->h.insdshead, Str("pvoc: not initialised")); err2: - return csound->PerfError(csound, Str("PVOC transpose too low")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too low")); err3: - return csound->PerfError(csound, Str("PVOC transpose too high")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too high")); err4: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC timpnt < 0")); } /* RWD 8:2001: custom version of ldmemfile(); diff -Nru csound-5.17.11~dfsg/Opcodes/ugens8.h csound-6.02~dfsg/Opcodes/ugens8.h --- csound-5.17.11~dfsg/Opcodes/ugens8.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugens8.h 2014-01-07 16:53:48.000000000 +0000 @@ -46,7 +46,7 @@ #define pvfrsiz(p) (p->frSiz) #define pvffsiz(p) (2* p->frSiz) -#define pvdasiz(p) (1 + (p->frSiz)/2) /* as above, based on */ +#define pvdasiz(p) ((uint32_t)(1 + (p->frSiz)/2)) /* as above, based on */ #define pvfdsiz(p) (2 + p->frSiz) /* ACTUAL frameSize in use */ typedef struct { diff -Nru csound-5.17.11~dfsg/Opcodes/ugens9.c csound-6.02~dfsg/Opcodes/ugens9.c --- csound-5.17.11~dfsg/Opcodes/ugens9.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugens9.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,30 +21,37 @@ 02111-1307 USA */ -#include "csdl.h" /* UGENS9.C */ +#include "stdopcod.h" /* UGENS9.C */ #include #include "convolve.h" #include "ugens9.h" #include "soundio.h" -#include "oload.h" -static int cvset(CSOUND *csound, CONVOLVE *p) +static int cvset_(CSOUND *csound, CONVOLVE *p, int stringname) { char cvfilnam[MAXNAME]; MEMFIL *mfp; - MYFLT *fltp; + MYFLT *fltp; CVSTRUCT *cvh; - int siz; + int siz; int32 Hlenpadded = 1, obufsiz, Hlen; - int nchanls; + uint32_t nchanls; + uint32_t nsmps = CS_KSMPS; if (UNLIKELY(csound->oparms->odebug)) csound->Message(csound, CONVOLVE_VERSION_STRING); - csound->strarg2name(csound, cvfilnam, p->ifilno, "convolve.", p->XSTRCODE); + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(cvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, cvfilnam,p->ifilno, "convolve.",0); + } + else strncpy(cvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if ((mfp = p->mfp) == NULL || strcmp(mfp->filename, cvfilnam) != 0) { /* if file not already readin */ - if (UNLIKELY((mfp = csound->ldmemfile2(csound, cvfilnam, CSFTYPE_CVANAL)) + if (UNLIKELY((mfp = csound->ldmemfile2withCB(csound, cvfilnam, + CSFTYPE_CVANAL,NULL)) == NULL)) { return csound->InitError(csound, Str("CONVOLVE cannot load %s"), cvfilnam); @@ -92,10 +99,10 @@ if ((p->nchanls == 1) && (*p->channel > 0)) p->H += (Hlenpadded + 2) * (int)(*p->channel - 1); - if (UNLIKELY(cvh->samplingRate != csound->esr)) { + if (UNLIKELY(cvh->samplingRate != CS_ESR)) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), - cvfilnam, cvh->samplingRate, csound->esr); + cvfilnam, cvh->samplingRate, CS_ESR); } if (UNLIKELY(cvh->dataFormat != CVMYFLT)) { return csound->InitError(csound, @@ -105,11 +112,10 @@ } /* Determine size of circular output buffer */ - if (Hlen >= csound->ksmps) - obufsiz = (int32) CEIL((MYFLT) Hlen / csound->ksmps) - * csound->ksmps; + if (Hlen >= (int32)nsmps) + obufsiz = (int32) CEIL((MYFLT) Hlen / nsmps) * nsmps; else - obufsiz = (int32) CEIL(csound->ksmps / (MYFLT) Hlen) * Hlen; + obufsiz = (int32) CEIL(CS_KSMPS / (MYFLT) Hlen) * Hlen; siz = ((Hlenpadded + 2) + p->nchanls * ((Hlen - 1) + obufsiz) + (p->nchanls > 1 ? (Hlenpadded + 2) : 0)); @@ -135,6 +141,15 @@ return OK; } +static int cvset(CSOUND *csound, CONVOLVE *p){ + return cvset_(csound,p,0); + +} + +static int cvset_S(CSOUND *csound, CONVOLVE *p){ + return cvset_(csound,p,1); + +} /* Write from a circular buffer into a linear output buffer without clearing data UPDATES SOURCE & DESTINATION POINTERS TO REFLECT NEW POSITIONS */ @@ -167,7 +182,7 @@ static int convolve(CSOUND *csound, CONVOLVE *p) { - int nsmpso=csound->ksmps,nsmpsi=csound->ksmps,nsmpso_sav,outcnt_sav; + int nsmpso=CS_KSMPS,nsmpsi=CS_KSMPS,outcnt_sav; int nchm1 = p->nchanls - 1,chn; int32 i,j; MYFLT *ar[4]; @@ -184,6 +199,9 @@ MYFLT *X; int32 Hlenpadded = p->Hlenpadded; MYFLT scaleFac; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nn,nsmpso_sav; scaleFac = csound->GetInverseRealFFTScale(csound, (int) Hlenpadded); ar[0] = p->ar1; @@ -194,10 +212,10 @@ if (p->auxch.auxp==NULL) goto err1; /* First dump as much pre-existing audio in output buffer as possible */ if (outcnt > 0) { - if (outcnt <= csound->ksmps) + if (outcnt <= (int)CS_KSMPS) i = outcnt; else - i = csound->ksmps; + i = CS_KSMPS; nsmpso -= i; outcnt -= i; for (chn = nchm1;chn >= 0;chn--) { outhead = p->outhead + chn*obufsiz; @@ -216,8 +234,13 @@ i = Hlen - incount; nsmpsi -= i; incount += i; - while (i--) - *fftbufind++ = scaleFac * *ai++; + nsmpso_sav = CS_KSMPS-early; + for (nn=0; i>0; nn++, i--) { + if (nn(uint32_t)nsmpso_sav) + *fftbufind++ = FL(0.0); + else + *fftbufind++ = scaleFac * ai[nn]; + } if (incount == Hlen) { /* We have enough audio for a convolution. */ incount = 0; @@ -338,7 +361,8 @@ p->outail = outail; return OK; err1: - return csound->PerfError(csound, Str("convolve: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("convolve: not initialised")); } /* partitioned (low latency) overlap-save convolution. @@ -350,7 +374,7 @@ allow this opcode to accept .con files. -ma++ april 2004 */ -static int pconvset(CSOUND *csound, PCONVOLVE *p) +static int pconvset_(CSOUND *csound, PCONVOLVE *p, int stringname) { int channel = (*(p->channel) <= 0 ? ALLCHNLS : (int) *(p->channel)); SNDFILE *infd; @@ -365,8 +389,14 @@ memset(&IRfile, 0, sizeof(SOUNDIN)); /* open impulse response soundfile [code derived from SAsndgetset()] */ IRfile.skiptime = FL(0.0); - csound->strarg2name(csound, IRfile.sfname, p->ifilno, "soundin.", - p->XSTRCODE); + + if (stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(IRfile.sfname,get_arg_string(csound, *p->ifilno), 511); + else csound->strarg2name(csound, IRfile.sfname, p->ifilno, "soundin.",0); + } + else strncpy(IRfile.sfname, ((STRINGDAT *)p->ifilno)->data, 511); + IRfile.sr = 0; if (UNLIKELY(channel < 1 || ((channel > 4) && (channel != ALLCHNLS)))) { return csound->InitError(csound, Str("channel request %d illegal"), channel); @@ -391,19 +421,19 @@ (long) IRfile.getframes, ainput_dur); p->nchanls = (channel != ALLCHNLS ? 1 : IRfile.nchanls); - if (UNLIKELY(p->nchanls != p->OUTOCOUNT)) { + if (UNLIKELY(p->nchanls != (int)p->OUTOCOUNT)) { return csound->InitError(csound, Str("PCONVOLVE: number of output channels " "not equal to input channels")); } - if (UNLIKELY(IRfile.sr != csound->esr)) { + if (UNLIKELY(IRfile.sr != CS_ESR)) { /* ## RWD suggests performing sr conversion here! */ - csound->Warning(csound, "IR srate != orch's srate"); + csound->Warning(csound, Str("IR srate != orch's srate")); } /* make sure the partition size is nonzero and a power of 2 */ if (*p->partitionSize <= 0) - partitionSize = csound->oparms->outbufsamps / csound->nchnls; + partitionSize = csound->oparms->outbufsamps / csound->GetNchnls(csound); else partitionSize = *p->partitionSize; @@ -429,7 +459,8 @@ handles finding the right channel */ if (UNLIKELY((read_in = csound->getsndin(csound, infd, inbuf, p->Hlen*p->nchanls, &IRfile)) <= 0)) - csound->Die(csound, Str("PCONVOLVE: less sound than expected!")); + return csound->InitError(csound, + Str("PCONVOLVE: less sound than expected!")); /* take FFT of each channel */ scaleFac = csound->dbfs_to_float @@ -466,7 +497,7 @@ /* allocate circular output sample buffer */ p->outBufSiz = sizeof(MYFLT) * p->nchanls * - (p->Hlen >= csound->ksmps ? p->Hlenpadded : 2*csound->ksmps); + (p->Hlen >= (int)CS_KSMPS ? p->Hlenpadded : 2*(int)CS_KSMPS); csound->AuxAlloc(csound, p->outBufSiz, &p->output); p->outRead = (MYFLT *)p->output.auxp; @@ -474,8 +505,8 @@ empty ksmps pass after a few initial generated buffers. There is probably an equation to figure this out to reduce the delay, but I can't seem to figure it out */ - if (p->Hlen > csound->ksmps) { - p->outCount = p->Hlen + csound->ksmps; + if (p->Hlen > (int)CS_KSMPS) { + p->outCount = p->Hlen + CS_KSMPS; p->outWrite = p->outRead + (p->nchanls * p->outCount); } else { @@ -485,9 +516,19 @@ return OK; } +static int pconvset(CSOUND *csound, PCONVOLVE *p){ + return pconvset_(csound,p,0); +} + +static int pconvset_S(CSOUND *csound, PCONVOLVE *p){ + return pconvset_(csound,p,1); +} + static int pconvolve(CSOUND *csound, PCONVOLVE *p) { - int nsmpsi = csound->ksmps; + uint32_t nn, nsmps = CS_KSMPS; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = nsmps - p->h.insdshead->ksmps_no_end; MYFLT *ai = p->ain; MYFLT *buf; MYFLT *input = (MYFLT*) p->savedInput.auxp, *workWrite = p->workWrite; @@ -495,9 +536,9 @@ int32 i, j, count = p->inCount; int32 hlenpaddedplus2 = p->Hlenpadded+2; - while (nsmpsi-- > 0) { + for (nn=0; nnearly? FL(0.0) : ai[nn]); /* We have enough audio for a convolution. */ if (count == p->Hlen) { @@ -568,10 +609,10 @@ /* copy to output if we have enough samples [we always should except the first Hlen samples] */ - if (p->outCount >= csound->ksmps) { - int n; - p->outCount -= csound->ksmps; - for (n=0; n < csound->ksmps; n++) { + if (p->outCount >= (int)CS_KSMPS) { + unsigned int n; + p->outCount -= CS_KSMPS; + for (n=0; n < CS_KSMPS; n++) { switch (p->nchanls) { case 1: *a1++ = *p->outRead++; @@ -604,11 +645,17 @@ } static OENTRY localops[] = { - { "convolve", sizeof(CONVOLVE), 5, "mmmm", "aTo", + { "convolve", sizeof(CONVOLVE), 0, 5, "mmmm", "aSo", + (SUBR) cvset_S, (SUBR) NULL, (SUBR) convolve }, + { "convle", sizeof(CONVOLVE), 0, 5, "mmmm", "aSo", + (SUBR) cvset_S, (SUBR) NULL, (SUBR) convolve }, + { "pconvolve",sizeof(PCONVOLVE), 0, 5, "mmmm", "aSoo", + (SUBR) pconvset_S, (SUBR) NULL, (SUBR) pconvolve }, + { "convolve.i", sizeof(CONVOLVE), 0, 5, "mmmm", "aio", (SUBR) cvset, (SUBR) NULL, (SUBR) convolve }, - { "convle", sizeof(CONVOLVE), 5, "mmmm", "aTo", + { "convle.i", sizeof(CONVOLVE), 0, 5, "mmmm", "aio", (SUBR) cvset, (SUBR) NULL, (SUBR) convolve }, - { "pconvolve",sizeof(PCONVOLVE), 5, "mmmm", "aToo", + { "pconvolve.i",sizeof(PCONVOLVE), 0, 5, "mmmm", "aioo", (SUBR) pconvset, (SUBR) NULL, (SUBR) pconvolve } }; @@ -617,4 +664,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/ugensa.c csound-6.02~dfsg/Opcodes/ugensa.c --- csound-5.17.11~dfsg/Opcodes/ugensa.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugensa.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" /* UGENSA.C */ +#include "stdopcod.h" /* UGENSA.C */ #include "ugensa.h" #include "ugens7.h" #include @@ -39,7 +39,7 @@ OVERLAP *ovp, *nxtovp; int32 olaps; p->fogcvt = FMAXLEN/(p->ftp1)->flen; /*JMC for FOG*/ - p->durtogo = (int32)(*p->itotdur * csound->esr); + p->durtogo = (int32)(*p->itotdur * CS_ESR); if (!skip) { /* legato: skip all memory management */ p->spdphs = 0L; /*JMC for FOG*/ if (*p->iphs == FL(0.0)) /* if fundphs zero, */ @@ -82,7 +82,10 @@ FUNC *ftp1, *ftp2; MYFLT *ar, *amp, *fund, *ptch, *speed; MYFLT v1, fract ,*ftab, fogcvt = p->fogcvt; /*JMC added for FOG*/ - int32 n,nsmps = csound->ksmps, fund_inc, form_inc; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int32 fund_inc, form_inc; /* long speed_inc; */ /*JMC added last--out for phs version*/ ar = p->ar; @@ -95,7 +98,12 @@ fund_inc = (int32)(*fund * csound->sicvt); form_inc = (int32)(*ptch * fogcvt); /*form_inc = *form * csound->sicvt;*/ /* speed_inc = *speed * fogcvt; */ /*JMC for FOG--out for phs version*/ - for (n=0;nfundphs & MAXLEN) { /* if phs has wrapped */ p->fundphs &= PHMASK; if (UNLIKELY((ovp = p->basovrlap.nxtfree) == NULL)) goto err1; @@ -154,7 +162,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("FOF needs more overlaps")); + return csound->PerfError(csound, p->h.insdshead, + Str("FOF needs more overlaps")); } static int newpulse(CSOUND *csound, FOGS *p, OVERLAP *ovp, MYFLT *amp, @@ -163,7 +172,7 @@ MYFLT octamp = *amp, oct; MYFLT form = *ptch / csound->sicvt, fogcvt = p->fogcvt; int32 rismps, newexp = 0; - if ((ovp->timrem = (int32)(*p->kdur * csound->esr)) > p->durtogo && + if ((ovp->timrem = (int32)(*p->kdur * CS_ESR)) > p->durtogo && (*p->iskip==FL(0.0))) /* ringtime */ return(0); if ((oct = *p->koct) > 0.0) { /* octaviation */ @@ -208,7 +217,7 @@ } ovp->curamp = octamp * p->preamp; /* set startamp */ ovp->expamp = p->expamp; - if ((ovp->dectim = (int32)(*p->kdec * csound->esr)) > 0) /* fnb dec */ + if ((ovp->dectim = (int32)(*p->kdec * CS_ESR)) > 0) /* fnb dec */ ovp->decinc = (int32)(csound->sicvt / *p->kdec); ovp->decphs = PHMASK; return(1); @@ -218,7 +227,7 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "fog", S(FOGS), TR|5, "a","xxxakkkkkiiiiooo",(SUBR)fogset,NULL,(SUBR)fog} + { "fog", S(FOGS), TR, 5, "a","xxxakkkkkiiiiooo",(SUBR)fogset,NULL,(SUBR)fog} }; int ugensa_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/uggab.c csound-6.02~dfsg/Opcodes/uggab.c --- csound-5.17.11~dfsg/Opcodes/uggab.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/uggab.c 2014-01-07 16:53:48.000000000 +0000 @@ -27,7 +27,7 @@ /* Code adapted by JPff 1998 Sep 19 */ /********************************************/ -#include "csdl.h" +#include "stdopcod.h" #include "uggab.h" #include @@ -36,17 +36,24 @@ MYFLT *adest= p->xdest; MYFLT *asig = p->xsig; MYFLT xlow, xhigh, xsig; - int n,nsmps = csound->ksmps; - + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(adest, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&adest[nsmps], '\0', early*sizeof(MYFLT)); + } if ((xlow=*p->xlow) >= (xhigh=*p->xhigh)) { MYFLT xaverage; xaverage = (xlow + xhigh) * FL(0.5); - for (n=0; n= xlow ) adest[n] = xlow + FMOD(xsig - xlow, FABS(xlow-xhigh)); else @@ -96,22 +103,29 @@ { MYFLT *adest, *asig; MYFLT xlow, xhigh, xaverage, xsig; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; adest = p->xdest; asig = p->xsig; xlow = *p->xlow; xhigh = *p->xhigh; + if (UNLIKELY(offset)) memset(adest, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&adest[nsmps], '\0', early*sizeof(MYFLT)); + } if (xlow >= xhigh) { xaverage = (xlow + xhigh)*FL(0.5); - for (n=0;n xhigh) || ( xsig < xlow )) { if (xsig > xhigh) @@ -161,7 +175,7 @@ break; default: return - csound->PerfError(csound, + csound->PerfError(csound, p->h.insdshead, Str(" bad imode value")); } p->old_sig = sig; @@ -184,7 +198,7 @@ else return csound->InitError(csound, Str("Min and max the same")); return OK; -} + } static int knterpol(CSOUND *csound, INTERPOL *p) { @@ -197,8 +211,15 @@ { MYFLT point_value = (*p->point - *p->imin ) * p->point_factor; MYFLT *out = p->r, *val1 = p->val1, *val2 = p->val2; - int n, nsmps = csound->ksmps; - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nphs; double si = *p->freq * p->tablenUPsr; /* gab c3 */ - int32 n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil: not initialised")); ft = p->ftp->ftable; - for (n=0; nphs; MYFLT *freq = p->freq; - int32 n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *amp = p->amp; /*gab c3*/ if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil: not initialised")); ft = p->ftp->ftable; - for (n=0; nout, *ft; MYFLT *curr_samp, fract; double phs = p->phs; - int32 n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp; MYFLT *freq = p->freq; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil: not initialised")); ft = p->ftp->ftable; - for (n=0; nftp; MYFLT *out = p->out, *ft; MYFLT *curr_samp, fract; double phs = p->phs; double si = *p->freq * p->tablenUPsr; - int32 n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *amp = p->amp; /*gab c3*/ if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil: not initialised")); ft = p->ftp->ftable; - for (n=0; nphs; - double si = *p->freq * p->tablen * csound->onedkr; + double si = *p->freq * p->tablen * CS_ONEDKR; MYFLT *curr_samp = p->ftp->ftable + (int32)phs; MYFLT fract = (MYFLT)(phs - (double)((int32)phs)); @@ -356,15 +406,23 @@ MYFLT fract; double phs = p->phs; double si = *p->freq * p->tablen * csound->onedsr; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp; int x0; MYFLT y0, y1, ym1, y2; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil3: not initialised")); ftab = p->ftp->ftable; - for (n=0; nphs; double si = *p->freq * p->tablen * csound->onedsr; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ampp = p->amp; int x0; MYFLT y0, y1, ym1, y2; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil3: not initialised")); ftab = p->ftp->ftable; - for (n=0; nphs; /*double si = *p->freq * p->tablen * csound->onedsr;*/ MYFLT *freq = p->freq; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT amp = *p->amp; int x0; MYFLT y0, y1, ym1, y2; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil3: not initialised")); ftab = p->ftp->ftable; - for (n=0; nphs; /*double si = *p->freq * p->tablen * csound->onedsr;*/ MYFLT *freq = p->freq; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ampp = p->amp; int x0; MYFLT y0, y1, ym1, y2; if (UNLIKELY(ftp==NULL)) - return csound->PerfError(csound, Str("poscil3: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("poscil3: not initialised")); ftab = p->ftp->ftable; - for (n=0; nphs; - double si = *p->freq * p->tablen * csound->onedkr; + double si = *p->freq * p->tablen * CS_ONEDKR; MYFLT *ftab = p->ftp->ftable; int x0 = (int32)phs; MYFLT fract = (MYFLT)(phs - (double)x0); @@ -584,11 +666,12 @@ FUNC *ftp; MYFLT loop, end, looplength; - if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ift)) == NULL)) return NOTOK; + if (UNLIKELY((ftp = csound->FTnp2Find(csound, p->ift)) == NULL)) + return NOTOK; if (UNLIKELY(!(p->fsr=ftp->gen01args.sample_rate))) { csound->Warning(csound, Str("losc: no sample rate stored in function " "assuming=sr\n")); - p->fsr=csound->esr; + p->fsr=CS_ESR; } p->ftp = ftp; p->tablen = ftp->flen; @@ -612,7 +695,9 @@ MYFLT *out = p->out, *ft = p->ftp->ftable; MYFLT *curr_samp, fract; double phs= p->phs, si= *p->freq * (p->fsr*csound->onedsr); - int32 n,nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double loop, end, looplength = p->looplength; MYFLT amp = *p->amp; @@ -621,7 +706,12 @@ end = p->tablen; looplength = end - loop; - for (n=0; nout, *ftab = p->ftp->ftable; MYFLT fract; double phs = p->phs, si= *p->freq * (p->fsr*csound->onedsr); - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; double loop, end, looplength = p->looplength; MYFLT amp = *p->amp; int x0; @@ -647,7 +739,12 @@ if ((end = *p->kend) > p->tablen || end <=0 ) end = p->tablen; looplength = end - loop; - for (n=0; nINOCOUNT, nsmps = csound->ksmps, k; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; + int count = (int) p->INOCOUNT; MYFLT *ar = p->ar, **args = p->argums; MYFLT *ag = *args; - memcpy(ar, ag, sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&ar[offset], &ag[offset], sizeof(MYFLT)*(nsmps-offset)); while (--count) { ag = *(++args); /* over all arguments */ - for (k=0; kINOCOUNT, nsmps = csound->ksmps, k = 0; + int count = (int) p->INOCOUNT; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t k, nsmps = CS_KSMPS; MYFLT *ar = p->ar, **args = p->argums; MYFLT *ag = *args; - memcpy(ar, ag, sizeof(MYFLT)*nsmps); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + memcpy(&ar[offset], &ag[offset], sizeof(MYFLT)*(nsmps-offset)); while (--count) { ag = *(++args); /* over all arguments */ - for (k=0; kscale = scale = (int) *p->iscl; if ((p->loop = (int) MYFLT2LONG(*p->ord)) < 1) p->loop = 4; /* default value */ if (!*p->istor && (p->aux.auxp == NULL || - (int32) (p->loop * 2 * sizeof(MYFLT)) > p->aux.size)) + (uint32_t) (p->loop * 2 * sizeof(MYFLT)) > p->aux.size)) csound->AuxAlloc(csound, (size_t) (p->loop * 2 * sizeof(MYFLT)), &p->aux); p->yt1 = (MYFLT*)p->aux.auxp; p->yt2 = (MYFLT*)p->aux.auxp + p->loop; if (UNLIKELY(scale && scale != 1 && scale != 2)) { @@ -727,15 +841,15 @@ /* for (j = 0; j < p->loop; j++) */ /* p->yt1[j] = p->yt2[j] = FL(0.0); */ } - if (p->buffer.auxp == NULL || p->buffer.sizeksmps*sizeof(MYFLT)) - csound->AuxAlloc(csound, (size_t)(csound->ksmps*sizeof(MYFLT)), &p->buffer); + if (p->buffer.auxp == NULL || p->buffer.sizeAuxAlloc(csound, (size_t)(nsmps*sizeof(MYFLT)), &p->buffer); return OK; } static int resony(CSOUND *csound, RESONY *p) { - int nsmps, j; - MYFLT *ar, *asig; + int j; + MYFLT *ar = p->ar, *asig; MYFLT c3p1, c3t4, omc3, c2sqr; MYFLT *yt1, *yt2, c1, c2, c3, cosf; double cf; @@ -746,12 +860,18 @@ MYFLT sep = (*p->sep / (MYFLT) loop); int flag = (int) *p->iflag; MYFLT *buffer = (MYFLT*) (p->buffer.auxp); - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; - nsmps = csound->ksmps; asig = p->asig; memset(buffer, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } yt1 = p->yt1; yt2 = p->yt2; @@ -775,7 +895,7 @@ c1 = SQRT((c3p1*c3p1-c2sqr) * omc3/c3p1); else c1 = FL(1.0); - for (n = 0; n < nsmps; n++) { + for (n = offset; n < nsmps; n++) { MYFLT temp = c1 * asig[n] + c2 * *yt1 - c3 * *yt2; buffer[n] += temp; *yt2 = *yt1; @@ -784,8 +904,7 @@ yt1++; yt2++; } - ar = p->ar; - memcpy(ar, buffer, sizeof(MYFLT)*nsmps); + memcpy(&ar[offset], &buffer[offset], sizeof(MYFLT)*(nsmps-offset)); return OK; } } @@ -794,19 +913,27 @@ { p->sample_index = 0; p->index = 0.0; + p->value = FL(0.0); /* This was not initialised -- JPff */ return OK; } static int fold(CSOUND *csound, FOLD *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar = p->ar; MYFLT *asig = p->asig; MYFLT kincr = *p->kincr; double index = p->index; int32 sample_index = p->sample_index; MYFLT value = p->value; - for (n=0; nnsegs = p->INOCOUNT-3; + // Should check this is even + if (UNLIKELY((p->nsegs&1)!=0)) + csound->Warning(csound, Str("loop opcode: wrong argument count")); p->args[0] = FL(0.0); p->phs = *p->iphase; return OK; @@ -835,7 +965,7 @@ { MYFLT *argp=p->args; MYFLT beg_seg=FL(0.0), end_seg, durtot=FL(0.0); - double phs, si=*p->freq*csound->onedkr; + double phs, si=*p->freq*CS_ONEDKR; int nsegs=p->nsegs+1; int j; if (*p->retrig) @@ -877,7 +1007,7 @@ MYFLT exp1 = FL(1.0)/(FL(1.0)-EXP(FL(1.0))); MYFLT *argp=p->args; MYFLT beg_seg=FL(0.0), end_seg, durtot=FL(0.0); - double phs, si=*p->freq*csound->onedkr; + double phs, si=*p->freq*CS_ONEDKR; int nsegs=p->nsegs+1; int j; if (*p->retrig) @@ -924,7 +1054,7 @@ static int looptseg(CSOUND *csound, LOOPTSEG *p) { MYFLT beg_seg=FL(0.0), end_seg=FL(0.0), durtot=FL(0.0); - double phs, si=*p->freq*csound->onedkr; + double phs, si=*p->freq*CS_ONEDKR; int nsegs=p->nsegs; int j; @@ -965,7 +1095,7 @@ { MYFLT *argp=p->args; MYFLT beg_seg=0, end_seg, durtot=FL(0.0); - double phs, si=*p->freq*csound->onedkr; + double phs, si=*p->freq*CS_ONEDKR; int nsegs=p->nsegs+1; int j; @@ -1107,13 +1237,13 @@ p->val_incremented = p->current_val; p->current_time = FL(0.0); p->incr = (*p->ksig - p->current_val) - / ((int32) (csound->ekr * p->old_time) -1); /* by experiment */ + / ((int32) (CS_EKR * p->old_time) -1); /* by experiment */ p->current_val = *p->ksig; } else if (p->current_time < p->old_time) { p->val_incremented += p->incr; } - p->current_time += 1/csound->ekr; + p->current_time += 1/CS_EKR; *p->kr = p->val_incremented; return OK; } @@ -1138,11 +1268,11 @@ /* p->val_incremented = p->current_val; */ p->current_time = FL(0.0); p->incr = (*p->ksig - p->current_val) - / ((int32) (csound->ekr * p->old_time) + 1); + / ((int32) (CS_EKR * p->old_time) + 1); p->current_val = *p->ksig; } else if (p->current_time < p->old_time) { - p->current_time += csound->onedkr; + p->current_time += CS_ONEDKR; p->val_incremented += p->incr; } *p->kr = p->val_incremented; @@ -1156,7 +1286,7 @@ { FUNC *ftp; - if ((ftp = csound->FTFind(csound, p->ifn)) != NULL) { + if ((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL) { p->ftp = ftp; if (*p->iphs >= 0) p->lphs = ((int32)(*p->iphs * FMAXLEN)) & PHMASK; @@ -1167,7 +1297,7 @@ p->xcpsFreqRate = randGab *(*p->ampMaxRate - *p->ampMinRate) + *p->ampMinRate; p->tablen = ftp->flen; - p->tablenUPkr = p->tablen * csound->onedkr; + p->tablenUPkr = p->tablen * CS_ONEDKR; return OK; } @@ -1198,7 +1328,7 @@ while (phs < 0.0 ) phs += p->tablen; p->lphs = phs; - p->phsAmpRate += (int32)(p->xcpsAmpRate * csound->kicvt); + p->phsAmpRate += (int32)(p->xcpsAmpRate * CS_KICVT); if (p->phsAmpRate >= MAXLEN) { p->xcpsAmpRate = randGab * (*p->ampMaxRate - *p->ampMinRate) + *p->ampMinRate; @@ -1207,7 +1337,7 @@ p->num2amp = BiRandGab ; p->dfdmaxAmp = (p->num2amp - p->num1amp) / FMAXLEN; } - p->phsFreqRate += (int32)(p->xcpsFreqRate * csound->kicvt); + p->phsFreqRate += (int32)(p->xcpsFreqRate * CS_KICVT); if (p->phsFreqRate >= MAXLEN) { p->xcpsFreqRate = randGab * (*p->cpsMaxRate - *p->cpsMinRate) + *p->cpsMinRate; @@ -1218,7 +1348,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("vibrato(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vibrato(krate): not initialised")); } static int vibr_set(CSOUND *csound, VIBR *p) @@ -1234,7 +1365,7 @@ #define cpsMaxRate FL(2.28100) #define iphs FL(0.0) - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ifn)) != NULL)) { p->ftp = ftp; p->lphs = ((int32)(iphs * FMAXLEN)) & PHMASK; } @@ -1242,7 +1373,7 @@ p->xcpsAmpRate = randGab * (cpsMaxRate - cpsMinRate) + cpsMinRate; p->xcpsFreqRate = randGab * (ampMaxRate - ampMinRate) + ampMinRate; p->tablen = ftp->flen; - p->tablenUPkr = p->tablen * csound->onedkr; + p->tablenUPkr = p->tablen * CS_ONEDKR; return OK; } @@ -1260,7 +1391,8 @@ phs = p->lphs; ftp = p->ftp; if (UNLIKELY(ftp==NULL)) { - return csound->PerfError(csound, Str("vibrato(krate): not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vibrato(krate): not initialised")); } fract = (MYFLT) (phs - (int32)phs); /*PFRAC(phs);*/ ftab = ftp->ftable + (int32)phs; /*(phs >> ftp->lobits);*/ @@ -1275,7 +1407,7 @@ phs += p->tablen; p->lphs = phs; - p->phsAmpRate += (int32)(p->xcpsAmpRate * csound->kicvt); + p->phsAmpRate += (int32)(p->xcpsAmpRate * CS_KICVT); if (p->phsAmpRate >= MAXLEN) { p->xcpsAmpRate = randGab * (ampMaxRate - ampMinRate) + ampMinRate; p->phsAmpRate &= PHMASK; @@ -1284,7 +1416,7 @@ p->dfdmaxAmp = (p->num2amp - p->num1amp) / FMAXLEN; } - p->phsFreqRate += (int32)(p->xcpsFreqRate * csound->kicvt); + p->phsFreqRate += (int32)(p->xcpsFreqRate * CS_KICVT); if (p->phsFreqRate >= MAXLEN) { p->xcpsFreqRate = randGab * (cpsMaxRate - cpsMinRate) + cpsMinRate; p->phsFreqRate &= PHMASK; @@ -1324,15 +1456,15 @@ if (p->flag) { /* accept default values */ *p->out = (out1* FL(0.5) + out2 * FL(0.3) + out3* FL(0.2)) * *p->gamp; - p->phs1 += (int32) (FL(0.82071231913) * csound->kicvt); - p->phs2 += (int32) (FL(7.009019029039107) * csound->kicvt); - p->phs3 += (int32) (FL(10.0) * csound->kicvt); + p->phs1 += (int32) (FL(0.82071231913) * CS_KICVT); + p->phs2 += (int32) (FL(7.009019029039107) * CS_KICVT); + p->phs3 += (int32) (FL(10.0) * CS_KICVT); } else { *p->out = (out1* *p->amp1 + out2* *p->amp2 +out3* *p->amp3) * *p->gamp; - p->phs1 += (int32)( *p->cps1 * csound->kicvt); - p->phs2 += (int32)( *p->cps2 * csound->kicvt); - p->phs3 += (int32)( *p->cps3 * csound->kicvt); + p->phs1 += (int32)( *p->cps1 * CS_KICVT); + p->phs2 += (int32)( *p->cps2 * CS_KICVT); + p->phs3 += (int32)( *p->cps3 * CS_KICVT); } if (p->phs1 >= MAXLEN) { p->phs1 &= PHMASK; @@ -1371,7 +1503,7 @@ goto next; } *p->ar = (p->num1 + (MYFLT)p->phs * p->dfdmax) * *p->amp; - p->phs += (int32)(p->xcps * csound->kicvt); + p->phs += (int32)(p->xcps * CS_KICVT); if (p->phs >= MAXLEN) { next: @@ -1408,7 +1540,7 @@ if (p->phs >= 1.0) { MYFLT slope, resd1, resd0, f2, f1; next: - p->si = (randGab * (*p->cpsMax-*p->cpsMin) + *p->cpsMin)*csound->onedkr; + p->si = (randGab * (*p->cpsMax-*p->cpsMin) + *p->cpsMin)*CS_ONEDKR; if (p->si == 0) p->si = 1; /* Is this necessary? */ while (p->phs > 1.0) p->phs -= 1.0; @@ -1434,14 +1566,23 @@ MYFLT f0= p->num0, df0 = p->df0; MYFLT *ar = p->ar, *amp = p->amp; MYFLT cpsMax = *p->cpsMax, cpsMin = *p->cpsMin; - int n = 0, nsmps = csound->ksmps, cod = p->cod; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int cod = p->cod; double phs = p->phs, si = p->si; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->initflag) { p->initflag = 0; + n = offset; goto next; } - for (n=0; n= 1.0) { MYFLT slope, resd1, resd0, f2, f1; @@ -1473,13 +1614,15 @@ static int kDiscreteUserRand(CSOUND *csound, DURAND *p) { /* gab d5*/ if (p->pfn != (int32)*p->tableNum) { - if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) goto err1; + if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) + goto err1; p->pfn = (int32)*p->tableNum; } *p->out = p->ftp->ftable[(int32)(randGab * MYFLT2LONG(p->ftp->flen))]; return OK; err1: - return csound->PerfError(csound, Str("Invalid ftable no. %f"), + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->tableNum); } @@ -1493,20 +1636,29 @@ static int aDiscreteUserRand(CSOUND *csound, DURAND *p) { /* gab d5*/ MYFLT *out = p->out, *table; - int n, nsmps = csound->ksmps, flen; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS, flen; if (p->pfn != (int32)*p->tableNum) { - if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) goto err1; + if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) + goto err1; p->pfn = (int32)*p->tableNum; } table = p->ftp->ftable; flen = p->ftp->flen; - for (n=0; nPerfError(csound, Str("Invalid ftable no. %f"), + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->tableNum); } @@ -1515,7 +1667,8 @@ int32 indx; MYFLT findx, fract, v1, v2; if (p->pfn != (int32)*p->tableNum) { - if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) goto err1; + if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) + goto err1; p->pfn = (int32)*p->tableNum; } findx = (MYFLT) (randGab * MYFLT2LONG(p->ftp->flen)); @@ -1526,7 +1679,8 @@ *p->out = (v1 + (v2 - v1) * fract) * (*p->max - *p->min) + *p->min; return OK; err1: - return csound->PerfError(csound, Str("Invalid ftable no. %f"), + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->tableNum); } @@ -1547,11 +1701,15 @@ { /* gab d5*/ MYFLT min = *p->min, rge = *p->max; MYFLT *out = p->out, *table; - int32 n, nsmps = csound->ksmps, flen, indx; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS, flen; + int indx; MYFLT findx, fract,v1,v2; if (p->pfn != (int32)*p->tableNum) { - if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) goto err1; + if (UNLIKELY( (p->ftp = csound->FTFindP(csound, p->tableNum) ) == NULL)) + goto err1; p->pfn = (int32)*p->tableNum; } @@ -1559,7 +1717,12 @@ flen = p->ftp->flen; rge -= min; - for (n=0; nPerfError(csound, Str("Invalid ftable no. %f"), + return csound->PerfError(csound, p->h.insdshead, + Str("Invalid ftable no. %f"), *p->tableNum); } @@ -1582,10 +1746,17 @@ static int aRangeRand(CSOUND *csound, RANGERAND *p) { /* gab d5*/ MYFLT min = *p->min, max = *p->max, *out = p->out; - int32 n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT rge = max - min; - for (n=0; ndfdmax = (p->num2 - p->num1) / FMAXLEN; break; case 2: /* immediate interpolation between ifirstval and 1st random number */ - p->num1 = (*p->max - *p->min) ? (*p->fstval - *p->min) / (*p->max - *p->min) : FL(0.0); + p->num1 = (*p->max - *p->min) ? + (*p->fstval - *p->min) / (*p->max - *p->min) : FL(0.0); p->num2 = randGab; p->dfdmax = (p->num2 - p->num1) / FMAXLEN; break; @@ -1624,7 +1796,7 @@ static int krandomi(CSOUND *csound, RANDOMI *p) { *p->ar = (p->num1 + (MYFLT)p->phs * p->dfdmax) * (*p->max - *p->min) + *p->min; - p->phs += (int32)(*p->xcps * csound->kicvt); + p->phs += (int32)(*p->xcps * CS_KICVT); if (p->phs >= MAXLEN) { p->phs &= PHMASK; p->num1 = p->num2; @@ -1637,7 +1809,9 @@ static int randomi(CSOUND *csound, RANDOMI *p) { int32 phs = p->phs, inc; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *cpsp; MYFLT amp, min; @@ -1646,7 +1820,12 @@ amp = (*p->max - min); ar = p->ar; inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0; nnum1 + (MYFLT)phs * p->dfdmax) * amp + min; phs += inc; if (p->cpscod) @@ -1670,7 +1849,8 @@ int mode = (int)(*p->mode); switch (mode) { case 2: /* the first output value is ifirstval */ - p->num1 = (*p->max - *p->min) ? (*p->fstval - *p->min) / (*p->max - *p->min) : FL(0.0); + p->num1 = (*p->max - *p->min) ? + (*p->fstval - *p->min) / (*p->max - *p->min) : FL(0.0); break; case 3: /* the first output value is a random number within the defined range */ p->num1 = randGab; @@ -1685,7 +1865,7 @@ static int krandomh(CSOUND *csound, RANDOMH *p) { *p->ar = p->num1 * (*p->max - *p->min) + *p->min; - p->phs += (int32)(*p->xcps * csound->kicvt); + p->phs += (int32)(*p->xcps * CS_KICVT); if (p->phs >= MAXLEN) { p->phs &= PHMASK; p->num1 = randGab; @@ -1696,7 +1876,9 @@ static int randomh(CSOUND *csound, RANDOMH *p) { int32 phs = p->phs, inc; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar, *cpsp; MYFLT amp, min; @@ -1705,7 +1887,12 @@ amp = (*p->max - min); ar = p->ar; inc = (int32)(*cpsp++ * csound->sicvt); - for (n=0; nnum1 * amp + min; phs += inc; if (p->cpscod) @@ -1743,7 +1930,7 @@ if (p->phs >= 1.0) { MYFLT slope, resd1, resd0, f2, f1; next: - p->si = (randGab * (*p->cpsMax-*p->cpsMin) + *p->cpsMin)*csound->onedkr; + p->si = (randGab * (*p->cpsMax-*p->cpsMin) + *p->cpsMin)*CS_ONEDKR; while (p->phs > 1.0) p->phs -= 1.0; f0 = p->num0 = p->num1; @@ -1770,22 +1957,29 @@ MYFLT *ar = p->ar, *rangeMin = p->rangeMin; MYFLT *rangeMax = p->rangeMax; MYFLT cpsMin = *p->cpsMin, cpsMax = *p->cpsMax; - int n = 0, nsmps = csound->ksmps, cod = p->cod; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int cod = p->cod; double phs = p->phs, si = p->si; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->initflag) { p->initflag = 0; + n = offset; goto next; - } - for (n=0; n= 1.0) { MYFLT slope, resd1, resd0, f2, f1; next: si = (randGab * (cpsMax - cpsMin) + cpsMin)*csound->onedsr; - while (phs > 1.0) - phs -= 1.0; + while (phs > 1.0) phs -= 1.0; f0 = p->num0 = p->num1; f1 = p->num1 = p->num2; f2 = p->num2 = BiRandGab; @@ -1814,74 +2008,86 @@ static OENTRY localops[] = { { "wrap", 0xffff }, -{ "wrap.i", S(WRAP), 1, "i", "iii", (SUBR)kwrap, NULL, NULL }, -{ "wrap.k", S(WRAP), 2, "k", "kkk", NULL, (SUBR)kwrap, NULL }, -{ "wrap.a", S(WRAP), 4, "a", "akk", NULL, NULL, (SUBR)wrap }, +{ "wrap.i", S(WRAP), 0,1, "i", "iii", (SUBR)kwrap, NULL, NULL }, +{ "wrap.k", S(WRAP), 0,2, "k", "kkk", NULL, (SUBR)kwrap, NULL }, +{ "wrap.a", S(WRAP), 0,4, "a", "akk", NULL, NULL, (SUBR)wrap }, { "mirror", 0xffff }, -{ "mirror.i", S(WRAP), 1, "i", "iii", (SUBR)kmirror, NULL, NULL }, -{ "mirror.k", S(WRAP), 2, "k", "kkk", NULL, (SUBR)kmirror, NULL }, -{ "mirror.a", S(WRAP), 4, "a", "akk", NULL, NULL, (SUBR)mirror }, -{ "ntrpol.i",S(INTERPOL), 1, "i", "iiiop",(SUBR)interpol }, -{ "ntrpol.k",S(INTERPOL), 3, "k", "kkkop",(SUBR)nterpol_init, (SUBR)knterpol }, -{ "ntrpol.a",S(INTERPOL), 5, "a", "aakop",(SUBR)nterpol_init,NULL,(SUBR)anterpol }, -{ "fold", S(FOLD), 5, "a", "ak", (SUBR)fold_set, NULL, (SUBR)fold }, -{ "lineto", S(LINETO), 3, "k", "kk", (SUBR)lineto_set, (SUBR)lineto, NULL }, -{ "tlineto", S(LINETO2), 3, "k", "kkk", (SUBR)tlineto_set, (SUBR)tlineto, NULL }, -{ "vibrato", S(VIBRATO), TR|3, "k", "kkkkkkkkio", +{ "mirror.i", S(WRAP), 0,1, "i", "iii", (SUBR)kmirror, NULL, NULL }, +{ "mirror.k", S(WRAP), 0,2, "k", "kkk", NULL, (SUBR)kmirror, NULL }, +{ "mirror.a", S(WRAP), 0,4, "a", "akk", NULL, NULL, (SUBR)mirror }, +{ "ntrpol.i",S(INTERPOL), 0,1, "i", "iiiop",(SUBR)interpol }, +{ "ntrpol.k",S(INTERPOL), 0,3, "k", "kkkop",(SUBR)nterpol_init, (SUBR)knterpol }, +{ "ntrpol.a",S(INTERPOL), 0,5, "a", "aakop",(SUBR)nterpol_init,NULL,(SUBR)anterpol}, +{ "fold", S(FOLD), 0,5, "a", "ak", (SUBR)fold_set, NULL, (SUBR)fold }, +{ "lineto", S(LINETO), 0,3, "k", "kk", (SUBR)lineto_set, (SUBR)lineto, NULL }, +{ "tlineto", S(LINETO2), 0,3, "k", "kkk", (SUBR)tlineto_set, (SUBR)tlineto, NULL}, +{ "vibrato", S(VIBRATO), TR, 3, "k", "kkkkkkkkio", (SUBR)vibrato_set, (SUBR)vibrato, NULL }, -{ "vibr", S(VIBRATO), TR|3, "k", "kki", (SUBR)vibr_set, (SUBR)vibr, NULL }, -{ "jitter2", S(JITTER2), 3, "k", "kkkkkkk", (SUBR)jitter2_set, (SUBR)jitter2 }, -{ "jitter", S(JITTER), 3, "k", "kkk", (SUBR)jitter_set, (SUBR)jitter, NULL }, -{ "jspline", S(JITTERS), 7, "s", "xkk", - (SUBR)jitters_set, (SUBR)jitters, (SUBR)jittersa }, -{ "loopseg", S(LOOPSEG), 3, "k", "kkiz", (SUBR)loopseg_set, (SUBR)loopseg, NULL }, -{ "loopxseg", S(LOOPSEG), 3, "k", "kkiz", (SUBR)loopseg_set, (SUBR)loopxseg, NULL }, -{ "looptseg", S(LOOPSEG), 3, "k", "kkiz", (SUBR)looptseg_set, (SUBR)looptseg, NULL}, -{ "lpshold", S(LOOPSEG), 3, "k", "kkiz", (SUBR)loopseg_set, (SUBR)lpshold, NULL }, -{ "loopsegp", S(LOOPSEGP), 3,"k", "kz", (SUBR)loopsegp_set,(SUBR)loopsegp, NULL}, -{ "lpsholdp", S(LOOPSEGP), 3,"k", "kz", (SUBR)loopsegp_set,(SUBR)lpsholdp, NULL}, +{ "vibr", S(VIBRATO), TR, 3, "k", "kki", (SUBR)vibr_set, (SUBR)vibr, NULL }, +{ "jitter2", S(JITTER2), 0,3, "k", "kkkkkkk", (SUBR)jitter2_set, (SUBR)jitter2 }, +{ "jitter", S(JITTER), 0,3, "k", "kkk", (SUBR)jitter_set, (SUBR)jitter, NULL }, +{ "jspline", S(JITTERS), 0,3, "k", "xkk", + (SUBR)jitters_set, (SUBR)jitters, NULL }, +{ "jspline.a", S(JITTERS), 0,5, "a", "xkk", + (SUBR)jitters_set, NULL, (SUBR)jittersa }, +{ "loopseg", S(LOOPSEG), 0,3, "k", "kkiz", (SUBR)loopseg_set, (SUBR)loopseg, NULL}, +{ "loopxseg", S(LOOPSEG), 0,3, "k", "kkiz", (SUBR)loopseg_set,(SUBR)loopxseg, NULL}, +{ "looptseg", S(LOOPSEG), 0,3, "k", "kkiz",(SUBR)looptseg_set,(SUBR)looptseg, NULL}, +{ "lpshold", S(LOOPSEG), 0,3, "k", "kkiz",(SUBR)loopseg_set, (SUBR)lpshold, NULL }, +{ "loopsegp", S(LOOPSEGP), 0,3,"k", "kz", (SUBR)loopsegp_set,(SUBR)loopsegp, NULL}, +{ "lpsholdp", S(LOOPSEGP), 0,3,"k", "kz", (SUBR)loopsegp_set,(SUBR)lpsholdp, NULL}, { "cuserrnd", 0xffff, TR }, { "duserrnd", 0xffff, TR }, -{ "random", 0xffff }, -{ "cuserrnd.i", S(CURAND),1,"i", "iii", (SUBR)iContinuousUserRand, NULL, NULL }, -{ "cuserrnd.k", S(CURAND),2,"k", "kkk", +{ "random", 0xffff }, +{ "cuserrnd.i", S(CURAND),0,1,"i", "iii", (SUBR)iContinuousUserRand, NULL, NULL }, +{ "cuserrnd.k", S(CURAND),0,2,"k", "kkk", (SUBR)Cuserrnd_set, (SUBR)kContinuousUserRand, NULL }, -{ "cuserrnd.a",S(CURAND),4, "a", "kkk", +{ "cuserrnd.a",S(CURAND),0,4, "a", "kkk", (SUBR)Cuserrnd_set, NULL, (SUBR)aContinuousUserRand }, -{ "random.i", S(RANGERAND), 1, "i", "ii", (SUBR)ikRangeRand, NULL, NULL }, -{ "random.k", S(RANGERAND), 2, "k", "kk", NULL, (SUBR)ikRangeRand, NULL }, -{ "random.a", S(RANGERAND), 4, "a", "kk", NULL, NULL, (SUBR)aRangeRand }, -{ "rspline", S(RANDOM3), 7, "s", "xxkk", - (SUBR)random3_set, (SUBR)random3, (SUBR)random3a }, -{ "randomi", S(RANDOMI), 7, "s", "kkxoo", - (SUBR)randomi_set, (SUBR)krandomi, (SUBR)randomi }, -{ "randomh", S(RANDOMH), 7, "s", "kkxoo", - (SUBR)randomh_set,(SUBR)krandomh,(SUBR)randomh }, -{ "urd.i", S(DURAND), 1, "i", "i", (SUBR)iDiscreteUserRand, NULL, NULL }, -{ "urd.k", S(DURAND), 2, "k", "k", (SUBR)Cuserrnd_set,(SUBR)kDiscreteUserRand }, -{ "urd.a", S(DURAND), 4, "a", "k", +{ "random.i", S(RANGERAND), 0,1, "i", "ii", (SUBR)ikRangeRand, NULL, NULL }, +{ "random.k", S(RANGERAND), 0,2, "k", "kk", NULL, (SUBR)ikRangeRand, NULL }, +{ "random.a", S(RANGERAND), 0,4, "a", "kk", NULL, NULL, (SUBR)aRangeRand }, +{ "rspline", S(RANDOM3), 0,3, "k", "xxkk", + (SUBR)random3_set, (SUBR)random3, NULL }, +{ "rspline.a", S(RANDOM3), 0,5, "a", "xxkk", + (SUBR)random3_set, NULL, (SUBR)random3a }, +{ "randomi", S(RANDOMI), 0,5, "a", "kkxoo", + (SUBR)randomi_set, (SUBR)NULL, (SUBR)randomi }, +{ "randomi.k", S(RANDOMI), 0,3, "k", "kkkoo", + (SUBR)randomi_set, (SUBR)krandomi,NULL }, +{ "randomh", S(RANDOMH), 0,5, "a", "kkxoo", + (SUBR)randomh_set,(SUBR)NULL,(SUBR)randomh }, +{ "randomh.k", S(RANDOMH), 0,3, "k", "kkkoo", + (SUBR)randomh_set,(SUBR)krandomh,NULL}, +{ "urd.i", S(DURAND), 0,1, "i", "i", (SUBR)iDiscreteUserRand, NULL, NULL }, +{ "urd.k", S(DURAND), 0,2, "k", "k", (SUBR)Cuserrnd_set,(SUBR)kDiscreteUserRand }, +{ "urd.a", S(DURAND), 0,4, "a", "k", (SUBR)Cuserrnd_set, NULL, (SUBR)aDiscreteUserRand }, -{ "duserrnd.i", S(DURAND),1, "i", "i", (SUBR)iDiscreteUserRand, NULL, NULL }, -{ "duserrnd.k", S(DURAND),2, "k", "k", +{ "duserrnd.i", S(DURAND),0,1, "i", "i", (SUBR)iDiscreteUserRand, NULL, NULL }, +{ "duserrnd.k", S(DURAND),0,2, "k", "k", (SUBR)Cuserrnd_set,(SUBR)kDiscreteUserRand,NULL }, -{ "duserrnd.a", S(DURAND),4, "a", "k", +{ "duserrnd.a", S(DURAND),0,4, "a", "k", (SUBR)Cuserrnd_set,NULL,(SUBR)aDiscreteUserRand }, { "poscil", 0xfffe, TR }, -{ "poscil.kk", S(POSC), 7, "s", "kkio", (SUBR)posc_set,(SUBR)kposc,(SUBR)posckk }, -{ "poscil.ka", S(POSC), 5, "a", "kaio", (SUBR)posc_set, NULL, (SUBR)poscka }, -{ "poscil.ak", S(POSC), 5, "a", "akio", (SUBR)posc_set, NULL, (SUBR)poscak }, -{ "poscil.aa", S(POSC), 5, "a", "aaio", (SUBR)posc_set, NULL, (SUBR)poscaa }, -{ "lposcil", S(LPOSC), TR|5, "a", "kkkkio", (SUBR)lposc_set, NULL, (SUBR)lposc}, +{ "poscil.a", S(POSC), 0,5, "a", "kkjo", (SUBR)posc_set,(SUBR)NULL,(SUBR)posckk }, +{ "poscil.kk", S(POSC), 0,3, "k", "kkjo", (SUBR)posc_set,(SUBR)kposc,NULL }, +{ "poscil.ka", S(POSC), 0,5, "a", "kajo", (SUBR)posc_set, NULL, (SUBR)poscka }, +{ "poscil.ak", S(POSC), 0,5, "a", "akjo", (SUBR)posc_set, NULL, (SUBR)poscak }, +{ "poscil.aa", S(POSC), 0,5, "a", "aajo", (SUBR)posc_set, NULL, (SUBR)poscaa }, +{ "lposcil", S(LPOSC), TR, 5, "a", "kkkkjo", (SUBR)lposc_set, NULL, (SUBR)lposc}, { "poscil3", 0xfffe, TR }, -{ "poscil3.kk",S(POSC), 7, "s", "kkio", (SUBR)posc_set,(SUBR)kposc3,(SUBR)posc3kk }, -{ "poscil3.ak", S(POSC), 5, "a", "akio", (SUBR)posc_set, NULL, (SUBR)posc3ak }, -{ "poscil3.ka", S(POSC), 5, "a", "kaio", (SUBR)posc_set, NULL, (SUBR)posc3ka }, -{ "poscil3.aa", S(POSC), 5, "a", "aaio", (SUBR)posc_set, NULL, (SUBR)posc3aa }, -{ "lposcil3", S(LPOSC), TR|5, "a", "kkkkio", (SUBR)lposc_set, NULL,(SUBR)lposc3}, -{ "trigger", S(TRIG), 3, "k", "kkk", (SUBR)trig_set, (SUBR)trig, NULL }, -{ "sum", S(SUM), 4, "a", "y", NULL, NULL, (SUBR)sum }, -{ "product", S(SUM), 4, "a", "y", NULL, NULL, (SUBR)product }, -{ "resony", S(RESONY), 5, "a", "akkikooo", (SUBR)rsnsety, NULL, (SUBR)resony } +{ "poscil3.a",S(POSC), 0,5, "a", "kkjo", + (SUBR)posc_set,(SUBR)NULL,(SUBR)posc3kk }, +{ "poscil3.kk",S(POSC), 0,7, "k", "kkjo", + (SUBR)posc_set,(SUBR)kposc3,NULL}, +{ "poscil3.ak", S(POSC), 0,5, "a", "akjo", (SUBR)posc_set, NULL, (SUBR)posc3ak }, +{ "poscil3.ka", S(POSC), 0,5, "a", "kajo", (SUBR)posc_set, NULL, (SUBR)posc3ka }, +{ "poscil3.aa", S(POSC), 0,5, "a", "aajo", (SUBR)posc_set, NULL, (SUBR)posc3aa }, +{ "lposcil3", S(LPOSC), TR, 5, "a", "kkkkjo", (SUBR)lposc_set, NULL,(SUBR)lposc3}, +{ "trigger", S(TRIG), 0,3, "k", "kkk", (SUBR)trig_set, (SUBR)trig, NULL }, +{ "sum", S(SUM), 0,4, "a", "y", NULL, NULL, (SUBR)sum }, +{ "product", S(SUM), 0,4, "a", "y", NULL, NULL, (SUBR)product }, +{ "resony", S(RESONY), 0,5, "a", "akkikooo", (SUBR)rsnsety, NULL, (SUBR)resony } }; int uggab_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/ugmoss.c csound-6.02~dfsg/Opcodes/ugmoss.c --- csound-5.17.11~dfsg/Opcodes/ugmoss.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugmoss.c 2014-01-07 16:53:48.000000000 +0000 @@ -22,7 +22,7 @@ */ /* ugmoss.c */ -#include "csdl.h" +#include "stdopcod.h" #include "ugmoss.h" #include "aops.h" #include @@ -40,7 +40,8 @@ FUNC *ftp; p->len = (int)*p->isize; - if (LIKELY((ftp = csound->FTFind(csound, p->ifn)) != NULL)) { /* find table */ + if (LIKELY((ftp = csound->FTnp2Find(csound, + p->ifn)) != NULL)) { /* find table */ p->ftp = ftp; if ((unsigned)ftp->flen < p->len) p->len = ftp->flen; /* correct len if flen shorter */ @@ -49,8 +50,10 @@ return csound->InitError(csound, Str("No table for dconv")); } if (p->sigbuf.auxp == NULL || - p->sigbuf.size < (int)(p->len*sizeof(MYFLT))) + p->sigbuf.size < (unsigned int)(p->len*sizeof(MYFLT))) csound->AuxAlloc(csound, p->len*sizeof(MYFLT), &p->sigbuf); + else + memset(p->sigbuf.auxp, '\0', p->len*sizeof(MYFLT)); p->curp = (MYFLT *)p->sigbuf.auxp; return OK; } @@ -58,7 +61,9 @@ static int dconv(CSOUND *csound, DCONV *p) { int32 i = 0; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 len = p->len; MYFLT *ar, *ain, *ftp, *startp, *endp, *curp; MYFLT sum; @@ -70,14 +75,19 @@ endp = startp + len; curp = p->curp; - for (n=0; nr; MYFLT *in1 = p->a; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + int n, nsmps = CS_KSMPS; int32 input1, input2; for (n = 0; n < nsmps; n++) { @@ -115,10 +125,17 @@ { MYFLT *r = p->r; MYFLT *in1 = p->a; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2 = MYFLT2LRND(*p->b), input1; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); r[n] = (MYFLT)(input1 & input2); } @@ -129,10 +146,17 @@ { MYFLT *r = p->r; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2, input1 = MYFLT2LRND(*p->a); - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input2 = MYFLT2LRND(in2[n]); r[n] = (MYFLT)(input1 & input2); } @@ -152,10 +176,17 @@ MYFLT *r = p->r; MYFLT *in1 = p->a; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2, input1; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); input2 = MYFLT2LRND(in2[n]); r[n] = (MYFLT)(input1 | input2); @@ -167,10 +198,17 @@ { MYFLT *r = p->r; MYFLT *in1 = p->a; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2 = MYFLT2LRND(*p->b), input1; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); r[n] = (MYFLT)(input1 | input2); } @@ -181,10 +219,17 @@ { MYFLT *r = p->r; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2, input1 = MYFLT2LRND(*p->a); - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input2 = MYFLT2LRND(in2[n]); r[n] = (MYFLT)(input1 | input2); } @@ -204,9 +249,16 @@ MYFLT *r = p->r; MYFLT *in1 = p->a; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2, input1; + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } for (n = 0; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); input2 = MYFLT2LRND(in2[n]); @@ -219,10 +271,17 @@ { MYFLT *r = p->r; MYFLT *in1 = p->a; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2 = MYFLT2LRND(*p->b), input1; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); r[n] = (MYFLT)(input1 ^ input2); } @@ -233,10 +292,17 @@ { MYFLT *r = p->r; MYFLT *in2 = p->b; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input2, input1 = MYFLT2LRND(*p->a); - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input2 = MYFLT2LRND(in2[n]); r[n] = (MYFLT)(input1 ^ input2); } @@ -253,12 +319,19 @@ static int shift_left_aa(CSOUND *csound, AOP *p) { - int32 input1; - int input2, n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + int32 input1, input2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(p->a[n]); - input2 = (int) MYFLT2LRND(p->b[n]); + input2 = (int32) MYFLT2LRND(p->b[n]); p->r[n] = (MYFLT) (input1 << input2); } return OK; @@ -268,9 +341,16 @@ { int32 input1; int input2 = MYFLT2LRND(*p->b); - int n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(p->a[n]); p->r[n] = (MYFLT) (input1 << input2); } @@ -279,10 +359,17 @@ static int shift_left_ka(CSOUND *csound, AOP *p) { - int32 input1 = MYFLT2LRND(*p->a); - int input2, n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + int32 input1 = MYFLT2LRND(*p->a), input2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input2 = MYFLT2LRND(p->b[n]); p->r[n] = (MYFLT) (input1 << input2); } @@ -299,10 +386,17 @@ static int shift_right_aa(CSOUND *csound, AOP *p) { - int32 input1; - int input2, n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + int32 input1, input2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(p->a[n]); input2 = (int) MYFLT2LRND(p->b[n]); p->r[n] = (MYFLT) (input1 >> input2); @@ -313,10 +407,17 @@ static int shift_right_ak(CSOUND *csound, AOP *p) { int32 input1; - int input2 = MYFLT2LRND(*p->b); - int n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + int32 input2 = MYFLT2LRND(*p->b); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(p->a[n]); p->r[n] = (MYFLT) (input1 >> input2); } @@ -325,10 +426,17 @@ static int shift_right_ka(CSOUND *csound, AOP *p) { - int32 input1 = MYFLT2LRND(*p->a); - int input2, n, nsmps = csound->ksmps; - - for (n = 0; n < nsmps; n++) { + int32 input1 = MYFLT2LRND(*p->a), input2; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(p->r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input2 = MYFLT2LRND(p->b[n]); p->r[n] = (MYFLT) (input1 >> input2); } @@ -346,10 +454,17 @@ { MYFLT *r = p->r; MYFLT *in1 = p->a; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int32 input1; - for (n = 0; n < nsmps; n++) { + if (UNLIKELY(offset)) memset(r, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&r[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n = offset; n < nsmps; n++) { input1 = MYFLT2LRND(in1[n]); r[n] = (MYFLT)(~input1); } @@ -368,11 +483,11 @@ return csound->InitError(csound, Str("illegal loop time")); } } - else if (UNLIKELY((lpsiz = (int32)(*p->imaxlpt * csound->esr)) <= 0)) { + else if (UNLIKELY((lpsiz = (int32)(*p->imaxlpt * CS_ESR)) <= 0)) { return csound->InitError(csound, Str("illegal loop time")); } nbytes = lpsiz * sizeof(MYFLT); - if (p->auxch.auxp == NULL || nbytes != p->auxch.size) { + if (p->auxch.auxp == NULL || nbytes != (int)p->auxch.size) { csound->AuxAlloc(csound, (size_t)nbytes, &p->auxch); p->pntr = (MYFLT *) p->auxch.auxp; if (UNLIKELY(p->pntr==NULL)) { @@ -391,14 +506,16 @@ p->lpt = FL(0.0); p->g = FL(0.0); p->lpta = (XINARG3) ? 1 : 0; - if (*p->insmps == 0) p->maxlpt = *p->imaxlpt * csound->esr; + if (*p->insmps == 0) p->maxlpt = *p->imaxlpt * CS_ESR; else p->maxlpt = *p->imaxlpt; return OK; } static int vcomb(CSOUND *csound, VCOMB *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; uint32 xlpt, maxlpt = (uint32)p->maxlpt; MYFLT *ar, *asig, *rp, *endp, *startp, *wp, *lpt; MYFLT g = p->g; @@ -409,10 +526,15 @@ endp = (MYFLT *) p->auxch.endp; startp = (MYFLT *) p->auxch.auxp; wp = p->pntr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->lpta) { /* if xlpt is a-rate */ lpt = p->xlpt; - for (n=0; ninsmps != 0) ? *lpt : *lpt * csound->esr); + for (n=offset; ninsmps != 0) ? *lpt : *lpt * CS_ESR); if (xlpt > maxlpt) xlpt = maxlpt; if ((rp = wp - xlpt) < startp) rp += maxlpt; if ((p->rvt != *p->krvt) || (p->lpt != *lpt)) { @@ -428,14 +550,14 @@ } else { /* if xlpt is k-rate */ xlpt = (uint32) ((*p->insmps != 0) ? *p->xlpt - : *p->xlpt * csound->esr); + : *p->xlpt * CS_ESR); if (xlpt > maxlpt) xlpt = maxlpt; if ((rp = wp - xlpt) < startp) rp += maxlpt; if ((p->rvt != *p->krvt) || (p->lpt != *p->xlpt)) { p->rvt = *p->krvt, p->lpt = *p->xlpt; g = p->g = POWER(FL(0.001), (p->lpt / p->rvt)); } - for (n=0; n= endp) wp = startp; @@ -445,12 +567,15 @@ p->pntr = wp; return OK; err1: - return csound->PerfError(csound, Str("vcomb: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vcomb: not initialised")); } static int valpass(CSOUND *csound, VCOMB *p) { - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; uint32 xlpt, maxlpt = (uint32)p->maxlpt; MYFLT *ar, *asig, *rp, *startp, *endp, *wp, *lpt; MYFLT y, z, g = p->g; @@ -461,10 +586,15 @@ endp = (MYFLT *) p->auxch.endp; startp = (MYFLT *) p->auxch.auxp; wp = p->pntr; + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } if (p->lpta) { /* if xlpt is a-rate */ lpt = p->xlpt; - for (n=0; ninsmps != 0) ? lpt[n] : lpt[n] * csound->esr); + for (n=offset; ninsmps != 0) ? lpt[n] : lpt[n] * CS_ESR); if (xlpt > maxlpt) xlpt = maxlpt; if ((rp = wp - xlpt) < startp) rp += maxlpt; if ((p->rvt != *p->krvt) || (p->lpt != lpt[n])) { @@ -480,14 +610,14 @@ } else { /* if xlpt is k-rate */ xlpt = (uint32) ((*p->insmps != 0) ? *p->xlpt - : *p->xlpt * csound->esr); + : *p->xlpt * CS_ESR); if (xlpt > maxlpt) xlpt = maxlpt; if ((rp = wp - xlpt) < startp) rp += maxlpt; if ((p->rvt != *p->krvt) || (p->lpt != *p->xlpt)) { p->rvt = *p->krvt, p->lpt = *p->xlpt; g = p->g = POWER(FL(0.001), (p->lpt / p->rvt)); } - for (n=0; npntr = wp; return OK; err1: - return csound->PerfError(csound, Str("valpass: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("valpass: not initialised")); } static int ftmorfset(CSOUND *csound, FTMORF *p) @@ -507,14 +638,14 @@ int j = 0; unsigned int len; /* make sure resfn exists and set it up */ - if (LIKELY((ftp = csound->FTFind(csound, p->iresfn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iresfn)) != NULL)) { p->resfn = ftp, len = p->resfn->flen; } else { return csound->InitError(csound, Str("iresfn for ftmorf does not exist")); } /* make sure ftfn exists and set it up */ - if (LIKELY((ftp = csound->FTFind(csound, p->iftfn)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->iftfn)) != NULL)) { p->ftfn = ftp; } else { @@ -522,7 +653,7 @@ } do { /* make sure tables in ftfn exist and are right size*/ - if (LIKELY((ftp = csound->FTFind(csound, p->ftfn->ftable + j)) != NULL)) { + if (LIKELY((ftp = csound->FTnp2Find(csound, p->ftfn->ftable + j)) != NULL)) { if (UNLIKELY((unsigned int)ftp->flen != len)) { return csound->InitError(csound, Str("table in iftfn for ftmorf wrong size")); @@ -532,7 +663,7 @@ return csound->InitError(csound, Str("table in iftfn for ftmorf " "does not exist")); } - } while (++j < p->ftfn->flen); + } while (++j < (int)p->ftfn->flen); p->len = len; p->ftndx = -FL(1.0); @@ -551,8 +682,8 @@ f = *p->kftndx - i; if (p->ftndx != *p->kftndx) { p->ftndx = *p->kftndx; - ftp1 = csound->FTFind(csound, p->ftfn->ftable + i++); - ftp2 = csound->FTFind(csound, p->ftfn->ftable + i--); + ftp1 = csound->FTnp2Find(csound, p->ftfn->ftable + i++); + ftp2 = csound->FTnp2Find(csound, p->ftfn->ftable + i--); do { *(p->resfn->ftable + j) = (*(ftp1->ftable + j) * (1-f)) + (*(ftp2->ftable + j) * f); @@ -565,38 +696,38 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "dconv", S(DCONV), TR|5, "a", "aii", (SUBR)dconvset, NULL, (SUBR)dconv }, -{ "vcomb", S(VCOMB), 5, "a", "akxioo", (SUBR)vcombset, NULL, (SUBR)vcomb }, -{ "valpass", S(VCOMB),5, "a", "akxioo", (SUBR)vcombset, NULL, (SUBR)valpass }, -{ "ftmorf", S(FTMORF),TR|3, "", "kii", (SUBR)ftmorfset, (SUBR)ftmorf, NULL }, -{ "and.ii", S(AOP), 1, "i", "ii", (SUBR)and_kk }, -{ "and.kk", S(AOP), 2, "k", "kk", NULL, (SUBR)and_kk }, -{ "and.ka", S(AOP), 4, "a", "ka", NULL, NULL, (SUBR)and_ka }, -{ "and.ak", S(AOP), 4, "a", "ak", NULL, NULL, (SUBR)and_ak }, -{ "and.aa", S(AOP), 4, "a", "aa", NULL, NULL, (SUBR)and_aa }, -{ "or.ii", S(AOP), 1, "i", "ii", (SUBR)or_kk }, -{ "or.kk", S(AOP), 2, "k", "kk", NULL, (SUBR)or_kk }, -{ "or.ka", S(AOP), 4, "a", "ka", NULL, NULL, (SUBR)or_ka }, -{ "or.ak", S(AOP), 4, "a", "ak", NULL, NULL, (SUBR)or_ak }, -{ "or.aa", S(AOP), 4, "a", "aa", NULL, NULL, (SUBR)or_aa }, -{ "xor.ii", S(AOP), 1, "i", "ii", (SUBR)xor_kk }, -{ "xor.kk", S(AOP), 2, "k", "kk", NULL, (SUBR)xor_kk }, -{ "xor.ka", S(AOP), 4, "a", "ka", NULL, NULL, (SUBR)xor_ka }, -{ "xor.ak", S(AOP), 4, "a", "ak", NULL, NULL, (SUBR)xor_ak }, -{ "xor.aa", S(AOP), 4, "a", "aa", NULL, NULL, (SUBR)xor_aa }, -{ "not.i", S(AOP), 1, "i", "i", (SUBR)not_k }, -{ "not.k", S(AOP), 2, "k", "k", NULL, (SUBR)not_k }, -{ "not.a", S(AOP), 4, "a", "a", NULL, NULL, (SUBR)not_a }, -{ "shl.ii", S(AOP), 1, "i", "ii", (SUBR) shift_left_kk }, -{ "shl.kk", S(AOP), 2, "k", "kk", NULL, (SUBR) shift_left_kk }, -{ "shl.ka", S(AOP), 4, "a", "ka", NULL, NULL, (SUBR) shift_left_ka }, -{ "shl.ak", S(AOP), 4, "a", "ak", NULL, NULL, (SUBR) shift_left_ak }, -{ "shl.aa", S(AOP), 4, "a", "aa", NULL, NULL, (SUBR) shift_left_aa }, -{ "shr.ii", S(AOP), 1, "i", "ii", (SUBR) shift_right_kk }, -{ "shr.kk", S(AOP), 2, "k", "kk", NULL, (SUBR) shift_right_kk }, -{ "shr.ka", S(AOP), 4, "a", "ka", NULL, NULL, (SUBR) shift_right_ka }, -{ "shr.ak", S(AOP), 4, "a", "ak", NULL, NULL, (SUBR) shift_right_ak }, -{ "shr.aa", S(AOP), 4, "a", "aa", NULL, NULL, (SUBR) shift_right_aa } +{ "dconv", S(DCONV), TR, 5, "a", "aii", (SUBR)dconvset, NULL, (SUBR)dconv }, +{ "vcomb", S(VCOMB), 0,5, "a", "akxioo", (SUBR)vcombset, NULL, (SUBR)vcomb }, +{ "valpass", S(VCOMB),0,5, "a", "akxioo", (SUBR)vcombset, NULL, (SUBR)valpass }, +{ "ftmorf", S(FTMORF),TR, 3, "", "kii", (SUBR)ftmorfset, (SUBR)ftmorf, }, +{ "##and.ii", S(AOP), 0,1, "i", "ii", (SUBR)and_kk }, +{ "##and.kk", S(AOP), 0,2, "k", "kk", NULL, (SUBR)and_kk }, +{ "##and.ka", S(AOP), 0,4, "a", "ka", NULL, NULL, (SUBR)and_ka }, +{ "##and.ak", S(AOP), 0,4, "a", "ak", NULL, NULL, (SUBR)and_ak }, +{ "##and.aa", S(AOP), 0,4, "a", "aa", NULL, NULL, (SUBR)and_aa }, +{ "##or.ii", S(AOP), 0,1, "i", "ii", (SUBR)or_kk }, +{ "##or.kk", S(AOP), 0,2, "k", "kk", NULL, (SUBR)or_kk }, +{ "##or.ka", S(AOP), 0,4, "a", "ka", NULL, NULL, (SUBR)or_ka }, +{ "##or.ak", S(AOP), 0,4, "a", "ak", NULL, NULL, (SUBR)or_ak }, +{ "##or.aa", S(AOP), 0,4, "a", "aa", NULL, NULL, (SUBR)or_aa }, +{ "##xor.ii", S(AOP), 0,1, "i", "ii", (SUBR)xor_kk }, +{ "##xor.kk", S(AOP), 0,2, "k", "kk", NULL, (SUBR)xor_kk }, +{ "##xor.ka", S(AOP), 0,4, "a", "ka", NULL, NULL, (SUBR)xor_ka }, +{ "##xor.ak", S(AOP), 0,4, "a", "ak", NULL, NULL, (SUBR)xor_ak }, +{ "##xor.aa", S(AOP), 0,4, "a", "aa", NULL, NULL, (SUBR)xor_aa }, +{ "##not.i", S(AOP), 0,1, "i", "i", (SUBR)not_k }, +{ "##not.k", S(AOP), 0,2, "k", "k", NULL, (SUBR)not_k }, +{ "##not.a", S(AOP), 0,4, "a", "a", NULL, NULL, (SUBR)not_a }, +{ "##shl.ii", S(AOP), 0,1, "i", "ii", (SUBR) shift_left_kk }, +{ "##shl.kk", S(AOP), 0,2, "k", "kk", NULL, (SUBR) shift_left_kk }, +{ "##shl.ka", S(AOP), 0,4, "a", "ka", NULL, NULL, (SUBR) shift_left_ka }, +{ "##shl.ak", S(AOP), 0,4, "a", "ak", NULL, NULL, (SUBR) shift_left_ak }, +{ "##shl.aa", S(AOP), 0,4, "a", "aa", NULL, NULL, (SUBR) shift_left_aa }, +{ "##shr.ii", S(AOP), 0,1, "i", "ii", (SUBR) shift_right_kk }, +{ "##shr.kk", S(AOP), 0,2, "k", "kk", NULL, (SUBR) shift_right_kk }, +{ "##shr.ka", S(AOP), 0,4, "a", "ka", NULL, NULL, (SUBR) shift_right_ka }, +{ "##shr.ak", S(AOP), 0,4, "a", "ak", NULL, NULL, (SUBR) shift_right_ak }, +{ "##shr.aa", S(AOP), 0,4, "a", "aa", NULL, NULL, (SUBR) shift_right_aa } }; int ugmoss_init_(CSOUND *csound) @@ -604,4 +735,3 @@ return csound->AppendOpcodes(csound, &(localops[0]), (int) (sizeof(localops) / sizeof(OENTRY))); } - diff -Nru csound-5.17.11~dfsg/Opcodes/ugnorman.c csound-6.02~dfsg/Opcodes/ugnorman.c --- csound-5.17.11~dfsg/Opcodes/ugnorman.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugnorman.c 2014-01-07 16:53:48.000000000 +0000 @@ -100,7 +100,7 @@ /* load ATS file into memory; returns "is swapped" boolean, or -1 on error */ static int load_atsfile(CSOUND *csound, void *p, MEMFIL **mfp, char *fname, - void *name_arg) + void *name_arg, int istring) { char opname[64]; STDOPCOD_GLOBALS *pp; @@ -112,11 +112,15 @@ opname[i] = toupper(opname[i]); /* converted to upper case */ /* copy in ats file name */ - csound->strarg2name(csound, fname, name_arg, "ats.", - (int) csound->GetInputArgSMask(p)); - + if(istring) strncpy(fname, ((STRINGDAT*)name_arg)->data,MAXNAME-1) ; + else { + if(ISSTRCOD(*((MYFLT*)name_arg))) + strncpy(fname,get_arg_string(csound, *((MYFLT*)name_arg)),MAXNAME-1); + else csound->strarg2name(csound, fname, name_arg, "ats.",0); + } /* load memfile */ - if (UNLIKELY((*mfp = csound->ldmemfile2(csound, fname, CSFTYPE_ATS)) == NULL)) { + if (UNLIKELY((*mfp = csound->ldmemfile2withCB(csound, fname, + CSFTYPE_ATS, NULL)) == NULL)) { csound->InitError(csound, Str("%s: Ats file %s not read (does it exist?)"), opname, fname); @@ -147,6 +151,45 @@ } /* ats info simply reads data out of the header of an atsfile. (i-rate) */ +static int atsinfo_S(CSOUND *csound, ATSINFO *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + MEMFIL *memfile = NULL; + double *ret_data; /* data to return */ + int swapped = 0; /* flag to indicate if data needs to be swapped */ + + /* load memfile */ + swapped = load_atsfile(csound, p, &memfile, atsfilname, p->ifileno, 1); + if (UNLIKELY(swapped < 0)) + return NOTOK; + atsh = (ATSSTRUCT*) memfile->beginp; + + switch ((int) MYFLT2LRND(*p->ilocation)) { + case 0: ret_data = &(atsh->sampr); break; + case 1: ret_data = &(atsh->frmsz); break; + case 2: ret_data = &(atsh->winsz); break; + case 3: ret_data = &(atsh->npartials); break; + case 4: ret_data = &(atsh->nfrms); break; + case 5: ret_data = &(atsh->ampmax); break; + case 6: ret_data = &(atsh->freqmax); break; + case 7: ret_data = &(atsh->dur); break; + case 8: ret_data = &(atsh->type); break; + default: + return csound->InitError(csound, + Str("ATSINFO: location is out of bounds: " + "0-8 are the only possible selections")); + } + /* if not swapped then just return the data */ + if (!swapped) { + *p->ireturn = (MYFLT) *ret_data; + return OK; + } + /* otherwise do byteswapping */ + *p->ireturn = (MYFLT) bswap(ret_data); + return OK; +} + static int atsinfo(CSOUND *csound, ATSINFO *p) { char atsfilname[MAXNAME]; @@ -156,7 +199,7 @@ int swapped = 0; /* flag to indicate if data needs to be swapped */ /* load memfile */ - swapped = load_atsfile(csound, p, &memfile, atsfilname, p->ifileno); + swapped = load_atsfile(csound, p, &memfile, atsfilname, p->ifileno, 0); if (UNLIKELY(swapped < 0)) return NOTOK; atsh = (ATSSTRUCT*) memfile->beginp; @@ -242,7 +285,73 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); + if (UNLIKELY(p->swapped < 0)) + return NOTOK; + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; + + /* byte swap if necessary */ + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + n_partials = (int) bswap(&atsh->npartials); + type = (int) bswap(&atsh->type); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + n_partials = (int) atsh->npartials; + type = (int) atsh->type; + } + + /* check to see if partial is valid */ + if (UNLIKELY((int) (*p->ipartial) > n_partials || (int) (*p->ipartial) <= 0)) { + return csound->InitError(csound, Str("ATSREAD: partial %i out of range, " + "max allowed is %i"), + (int) (*p->ipartial), n_partials); + } + + /* point the data pointer to the correct partial */ + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + + switch (type) { + case 1: + p->partialloc = 1 + 2 * (*p->ipartial - 1); + p->frmInc = n_partials * 2 + 1; + break; + case 2: + p->partialloc = 1 + 3 * (*p->ipartial - 1); + p->frmInc = n_partials * 3 + 1; + break; + case 3: + p->partialloc = 1 + 2 * (*p->ipartial - 1); + p->frmInc = n_partials * 2 + 26; + break; + case 4: + p->partialloc = 1 + 3 * (*p->ipartial - 1); + p->frmInc = n_partials * 3 + 26; + break; + default: + return csound->InitError(csound, Str("Type not implemented")); + } + + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + return OK; +} + + +static int atsreadset_S(CSOUND *csound, ATSREAD *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + int n_partials; + int type; + + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); if (UNLIKELY(p->swapped < 0)) return NOTOK; atsh = (ATSSTRUCT*) p->atsmemfile->beginp; @@ -330,7 +439,8 @@ return OK; err1: - return csound->PerfError(csound, Str("ATSREAD: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ATSREAD: not initialised")); } /* @@ -368,7 +478,67 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); + if (UNLIKELY(p->swapped < 0)) + return NOTOK; + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; + + /* byte swap if necessary */ + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + n_partials = (int) bswap(&atsh->npartials); + type = (int) bswap(&atsh->type); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + n_partials = (int) atsh->npartials; + type = (int) atsh->type; + } + + /* point the data pointer to the correct partial */ + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + + /* check to see if band is valid */ + if (UNLIKELY((int) (*p->inzbin) > 25 || (int) (*p->inzbin) <= 0)) { + return csound->InitError(csound, Str("ATSREADNZ: band %i out of range, " + "1-25 are the valid band values"), + (int) (*p->inzbin)); + } + + switch (type) { + case 3: + /* get past the partial data to the noise */ + p->nzbandloc = (int) (2 * n_partials + *p->inzbin); + p->frmInc = n_partials * 2 + 26; + break; + + case 4: + p->nzbandloc = (int) (3 * n_partials + *p->inzbin); + p->frmInc = n_partials * 3 + 26; + break; + default: + return csound->InitError(csound, + Str("ATSREADNZ: Type either not implemented " + "or does not contain noise")); + } + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + return OK; +} + +static int atsreadnzset_S(CSOUND *csound, ATSREADNZ *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + int n_partials; + int type; + + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); if (UNLIKELY(p->swapped < 0)) return NOTOK; atsh = (ATSSTRUCT*) p->atsmemfile->beginp; @@ -419,6 +589,7 @@ return OK; } + static int atsreadnz(CSOUND *csound, ATSREADNZ *p) { MYFLT frIndx; @@ -447,7 +618,8 @@ *p->kenergy = FetchNzBand(p, frIndx); return OK; err1: - return csound->PerfError(csound, Str("ATSREADNZ: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ATSREADNZ: not initialised")); } /* @@ -482,7 +654,7 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); if (UNLIKELY(p->swapped < 0)) return NOTOK; atsh = (ATSSTRUCT*) p->atsmemfile->beginp; @@ -493,7 +665,7 @@ + (int) (*p->iptls) * sizeof(MYFLT); /* allocate space if we need it */ /* need room for a buffer and an array of oscillator phase increments */ - if (p->auxch.auxp == NULL || p->auxch.size < memsize) + if (p->auxch.auxp == NULL || p->auxch.size < (unsigned int)memsize) csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); /* set up the buffer, phase, etc. */ @@ -529,25 +701,25 @@ /* get increments for the partials */ switch (type) { case 1: - p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); p->partialinc = 2 * (int) (*p->iptlincr); p->frmInc = n_partials * 2 + 1; break; case 2: - p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); p->partialinc = 3 * (int) (*p->iptlincr); p->frmInc = n_partials * 3 + 1; break; case 3: - p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); p->partialinc = 2 * (int) (*p->iptlincr); p->frmInc = n_partials * 2 + 26; break; case 4: - p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); p->partialinc = 3 * (int) (*p->iptlincr); p->frmInc = n_partials * 3 + 26; break; @@ -562,66 +734,174 @@ return OK; } -static int atsadd(CSOUND *csound, ATSADD *p) -{ - MYFLT frIndx; - MYFLT *ar, amp, fract, v1, *ftab,a,inca, *oldamps = p->oldamps; - FUNC *ftp; - int32 lobits, phase, inc; - double *oscphase; - int i, n, nsmps = csound->ksmps; - int numpartials = (int) *p->iptls; - ATS_DATA_LOC *buf; - buf = p->buf; - /* ftp is a poiter to the ftable */ - if (UNLIKELY(p->auxch.auxp == NULL || (ftp = p->ftp) == NULL)) goto err1; +static int atsaddset_S(CSOUND *csound, ATSADD *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + FUNC *ftp, *AmpGateFunc; + int memsize, n_partials, type; - /* make sure time pointer is within range */ - if ((frIndx = *(p->ktimpnt) * p->timefrmInc) < FL(0.0)) { - frIndx = FL(0.0); - if (UNLIKELY(p->prFlg)) { - p->prFlg = 0; - csound->Warning(csound, Str("ATSADD: only positive time pointer " - "values are allowed, setting to zero\n")); - } + /* set up function table for synthesis */ + if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) { + return csound->InitError(csound, Str("ATSADD: Function table number " + "for synthesis waveform not valid")); } - else if (frIndx > p->maxFr) { - /* if we are trying to get frames past where we have data */ - frIndx = (MYFLT) p->maxFr; - if (UNLIKELY(p->prFlg)) { - p->prFlg = 0; /* set to false */ - csound->Warning(csound, Str("ATSADD: time pointer out of range, " - "truncating to last frame\n")); + p->ftp = ftp; + + /* set up gate function table */ + if (*p->igatefun > FL(0.0)) { + if (UNLIKELY((AmpGateFunc = csound->FTFind(csound, p->igatefun)) == NULL)) { + return csound->InitError(csound, Str("ATSADD: Gate Function table " + "number not valid")); } + else + p->AmpGateFunc = AmpGateFunc; } - else - p->prFlg = 1; - FetchADDPartials(p, buf, frIndx); + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); + if (UNLIKELY(p->swapped < 0)) + return NOTOK; + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; - oscphase = p->oscphase; - /* initialise output to zero */ - ar = p->aoutput; - memset(ar, 0, nsmps*sizeof(MYFLT)); -/* for (i = 0; i < nsmps; i++) */ -/* ar[i] = FL(0.0); */ + /* calculate how much memory we have to allocate for this */ + memsize = (int) (*p->iptls) * sizeof(ATS_DATA_LOC) + + (int) (*p->iptls) * sizeof(double) + + (int) (*p->iptls) * sizeof(MYFLT); + /* allocate space if we need it */ + /* need room for a buffer and an array of oscillator phase increments */ + if (p->auxch.auxp == NULL || p->auxch.size < (unsigned int)memsize) + csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); - if (*p->igatefun > FL(0.0)) - AtsAmpGate(buf, *p->iptls, p->AmpGateFunc, p->MaxAmp); + /* set up the buffer, phase, etc. */ + p->buf = (ATS_DATA_LOC *) (p->auxch.auxp); + p->oscphase = (double *) (p->buf + (int) (*p->iptls)); + p->oldamps = (MYFLT *) (p->oscphase + (int) (*p->iptls)); + /* byte swap if necessary */ + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + n_partials = (int) bswap(&atsh->npartials); + p->MaxAmp = bswap(&atsh->ampmax); /* store the maxium amplitude */ + type = (int) bswap(&atsh->type); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + n_partials = (int) atsh->npartials; + p->MaxAmp = atsh->ampmax; /* store the maxium amplitude */ + type = (int) atsh->type; + } - for (i = 0; i < numpartials; i++) { - lobits = ftp->lobits; - amp = csound->e0dbfs * (MYFLT) p->buf[i].amp; - phase = MYFLT2LONG(*oscphase); + /* make sure partials are in range */ + if (UNLIKELY((int) (*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || + (int) (*p->iptloffset) < 0)) { + return csound->InitError(csound, Str("ATSADD: Partial(s) out of range, " + "max partial allowed is %i"), + n_partials); + } + /* get a pointer to the beginning of the data */ + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + + /* get increments for the partials */ + switch (type) { + case 1: + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int) (*p->iptlincr); + p->frmInc = n_partials * 2 + 1; + break; + + case 2: + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int) (*p->iptlincr); + p->frmInc = n_partials * 3 + 1; + break; + + case 3: + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int) (*p->iptlincr); + p->frmInc = n_partials * 2 + 26; + break; + + case 4: + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int) (*p->iptlincr); + p->frmInc = n_partials * 3 + 26; + break; + + default: + return csound->InitError(csound, Str("ATSADD: Type not implemented")); + } + + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + return OK; +} + +static int atsadd(CSOUND *csound, ATSADD *p) +{ + MYFLT frIndx; + MYFLT *ar, amp, fract, v1, *ftab,a,inca, *oldamps = p->oldamps; + FUNC *ftp; + int32 lobits, phase, inc; + double *oscphase; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + int numpartials = (int) *p->iptls; + ATS_DATA_LOC *buf; + + buf = p->buf; + + /* ftp is a poiter to the ftable */ + if (UNLIKELY(p->auxch.auxp == NULL || (ftp = p->ftp) == NULL)) goto err1; + + /* make sure time pointer is within range */ + if ((frIndx = *(p->ktimpnt) * p->timefrmInc) < FL(0.0)) { + frIndx = FL(0.0); + if (UNLIKELY(p->prFlg)) { + p->prFlg = 0; + csound->Warning(csound, Str("ATSADD: only positive time pointer " + "values are allowed, setting to zero\n")); + } + } + else if (frIndx > p->maxFr) { + /* if we are trying to get frames past where we have data */ + frIndx = (MYFLT) p->maxFr; + if (UNLIKELY(p->prFlg)) { + p->prFlg = 0; /* set to false */ + csound->Warning(csound, Str("ATSADD: time pointer out of range, " + "truncating to last frame\n")); + } + } + else + p->prFlg = 1; + + FetchADDPartials(p, buf, frIndx); + + oscphase = p->oscphase; + /* initialise output to zero */ + ar = p->aoutput; + memset(ar, 0, nsmps*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; + if (*p->igatefun > FL(0.0)) + AtsAmpGate(buf, *p->iptls, p->AmpGateFunc, p->MaxAmp); + + for (i = 0; i < numpartials; i++) { + lobits = ftp->lobits; + amp = csound->e0dbfs * (MYFLT) p->buf[i].amp; + phase = MYFLT2LONG(*oscphase); ar = p->aoutput; /* ar is a pointer to the audio output */ - nsmps = csound->ksmps; inca = (amp-oldamps[i])/nsmps; a = oldamps[i]; /* put in * kfmod */ inc = MYFLT2LONG(p->buf[i].freq * csound->sicvt * *p->kfmod); - for (n=0; nftable + (phase >> lobits); v1 = *ftab++; fract = (MYFLT) PFRAC(phase); @@ -636,7 +916,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("ATSADD: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ATSADD: not initialised")); } static void FetchADDPartials(ATSADD *p, ATS_DATA_LOC *buf, MYFLT position) @@ -723,7 +1004,7 @@ static void randiats_setup(CSOUND *csound, MYFLT freq, RANDIATS *radat) { - radat->size = (int) MYFLT2LRND(csound->esr / freq); + radat->size = (int) MYFLT2LRND(CS_ESR / freq); radat->cnt = 0; radat->a1 = (int32) csound->Rand31(&(csound->randSeed1)); radat->a2 = (int32) csound->Rand31(&(csound->randSeed1)); @@ -749,26 +1030,6 @@ /* ------------------------------------------------------------------ */ -#if 0 -static MYFLT randifats(CSOUND *csound, RANDIATS *radat, MYFLT freq) -{ - MYFLT output; - - if (radat->cnt == radat->size) { /* get a new random value */ - radat->a1 = radat->a2; - radat->a2 = (int32) csound->Rand31(&(csound->randSeed1)); - radat->cnt = 0; - radat->size = (int) MYFLT2LRND(csound->esr / freq); - } - - output = (((MYFLT) (radat->a2 - radat->a1) / (MYFLT) radat->size) - * (MYFLT) radat->cnt) + (MYFLT) radat->a1; - radat->cnt++; - - return (FL(1.0) - ((MYFLT) output * (FL(2.0) / (MYFLT) 0x7FFFFFFF))); -} -#endif - static void FetchADDNZbands(int ptls, int firstband, double *datastart, int frmInc, int maxFr, int swapped, double *buf, MYFLT position) @@ -828,7 +1089,176 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); + if (p->swapped < 0) + return NOTOK; + p->bands = (int)(*p->ibands); + p->bandoffset = (int) (*p->ibandoffset); + p->bandincr = (int) (*p->ibandincr); + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; + + /* make sure that this file contains noise */ + type = (p->swapped == 1) ? (int) bswap(&atsh->type) : (int) atsh->type; + + if (UNLIKELY(type != 4 && type != 3)) { + if (type < 5) + return csound->InitError(csound, + Str("ATSADDNZ: " + "This file type contains no noise")); + else + return csound->InitError(csound, + Str("ATSADDNZ: This file type has not been " + "implemented in this code yet.")); + } + + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + /* byte swap if necessary */ + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + n_partials = (int) bswap(&atsh->npartials); + p->winsize = (MYFLT) bswap(&atsh->winsz); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + n_partials = (int) atsh->npartials; + p->winsize = (MYFLT) atsh->winsz; + } + + /* make sure partials are in range */ + if (UNLIKELY((p->bandoffset + p->bands * p->bandincr) > 25 || + p->bands <0 || /* Allow zero bands for no good reason */ + p->bandoffset < 0)) { + return csound->InitError(csound, Str("ATSADDNZ: Band(s) out of range, " + "max band allowed is 25")); + } + + /* point the data pointer to the correct partials */ + switch (type) { + case 3: + p->firstband = 1 + 2 * n_partials; + p->frmInc = n_partials * 2 + 26; + break; + + case 4: + p->firstband = 1 + 3 * n_partials; + p->frmInc = n_partials * 3 + 26; + break; + + default: + return csound->InitError(csound, Str("ATSADDNZ: Type either has no noise " + "or is not implemented " + "(only type 3 and 4 work now)")); + } + + /* save bandwidths for creating noise bands */ + memcpy(p->nfreq, freqs, 25*sizeof(double)); + /* p->nfreq[0] = 100.0; */ + /* p->nfreq[1] = 100.0; */ + /* p->nfreq[2] = 100.0; */ + /* p->nfreq[3] = 100.0; */ + /* p->nfreq[4] = 110.0; */ + /* p->nfreq[5] = 120.0; */ + /* p->nfreq[6] = 140.0; */ + /* p->nfreq[7] = 150.0; */ + /* p->nfreq[8] = 160.0; */ + /* p->nfreq[9] = 190.0; */ + /* p->nfreq[10] = 210.0; */ + /* p->nfreq[11] = 240.0; */ + /* p->nfreq[12] = 280.0; */ + /* p->nfreq[13] = 320.0; */ + /* p->nfreq[14] = 380.0; */ + /* p->nfreq[15] = 450.0; */ + /* p->nfreq[16] = 550.0; */ + /* p->nfreq[17] = 700.0; */ + /* p->nfreq[18] = 900.0; */ + /* p->nfreq[19] = 1100.0; */ + /* p->nfreq[20] = 1300.0; */ + /* p->nfreq[21] = 1800.0; */ + /* p->nfreq[22] = 2500.0; */ + /* p->nfreq[23] = 3500.0; */ + /* p->nfreq[24] = 4500.0; */ + + { + double tmp = TWOPI * csound->onedsr; + + /* initialise frequencies to modulate noise by */ + p->phaseinc[0] = 50.0 * tmp; + p->phaseinc[1] = 150.0 * tmp; + p->phaseinc[2] = 250.0 * tmp; + p->phaseinc[3] = 350.0 * tmp; + p->phaseinc[4] = 455.0 * tmp; + p->phaseinc[5] = 570.0 * tmp; + p->phaseinc[6] = 700.0 * tmp; + p->phaseinc[7] = 845.0 * tmp; + p->phaseinc[8] = 1000.0 * tmp; + p->phaseinc[9] = 1175.0 * tmp; + p->phaseinc[10] = 1375.0 * tmp; + p->phaseinc[11] = 1600.0 * tmp; + p->phaseinc[12] = 1860.0 * tmp; + p->phaseinc[13] = 2160.0 * tmp; + p->phaseinc[14] = 2510.0 * tmp; + p->phaseinc[15] = 2925.0 * tmp; + p->phaseinc[16] = 3425.0 * tmp; + p->phaseinc[17] = 4050.0 * tmp; + p->phaseinc[18] = 4850.0 * tmp; + p->phaseinc[19] = 5850.0 * tmp; + p->phaseinc[20] = 7050.0 * tmp; + p->phaseinc[21] = 8600.0 * tmp; + p->phaseinc[22] = 10750.0 * tmp; + p->phaseinc[23] = 13750.0 * tmp; + p->phaseinc[24] = 17750.0 * tmp; + } + /* initialise phase */ + memset(p->oscphase, '\0', 25*sizeof(double)); + /* p->oscphase[0] = 0.0; */ + /* p->oscphase[1] = 0.0; */ + /* p->oscphase[2] = 0.0; */ + /* p->oscphase[3] = 0.0; */ + /* p->oscphase[4] = 0.0; */ + /* p->oscphase[5] = 0.0; */ + /* p->oscphase[6] = 0.0; */ + /* p->oscphase[7] = 0.0; */ + /* p->oscphase[8] = 0.0; */ + /* p->oscphase[9] = 0.0; */ + /* p->oscphase[10] = 0.0; */ + /* p->oscphase[11] = 0.0; */ + /* p->oscphase[12] = 0.0; */ + /* p->oscphase[13] = 0.0; */ + /* p->oscphase[14] = 0.0; */ + /* p->oscphase[15] = 0.0; */ + /* p->oscphase[16] = 0.0; */ + /* p->oscphase[17] = 0.0; */ + /* p->oscphase[18] = 0.0; */ + /* p->oscphase[19] = 0.0; */ + /* p->oscphase[20] = 0.0; */ + /* p->oscphase[21] = 0.0; */ + /* p->oscphase[22] = 0.0; */ + /* p->oscphase[23] = 0.0; */ + /* p->oscphase[24] = 0.0; */ + + /* initialise band limited noise parameters */ + for (i = 0; i < 25; i++) { + randiats_setup(csound, p->nfreq[i], &(p->randinoise[i])); + } + + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + + return OK; +} + +static int atsaddnzset_S(CSOUND *csound, ATSADDNZ *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + int i, type, n_partials; + + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); if (p->swapped < 0) return NOTOK; p->bands = (int)(*p->ibands); @@ -993,7 +1423,10 @@ { MYFLT frIndx; MYFLT *ar, amp; - int i, n, nsmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int synthme; int nsynthed; @@ -1024,21 +1457,18 @@ /* set local pointer to output and initialise output to zero */ ar = p->aoutput; - memset(ar, 0, csound->ksmps*sizeof(MYFLT)); -/* for (i = 0; i < csound->ksmps; i++) */ -/* *ar++ = FL(0.0); */ + memset(ar, 0, CS_KSMPS*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; synthme = p->bandoffset; nsynthed = 0; - nsmps = csound->ksmps; - for (i = 0; i < 25; i++) { /* do we even have to synthesize it? */ if (i == synthme && nsynthed < p->bands) { /* synthesize cosine */ amp = csound->e0dbfs* SQRT((p->buf[i] / (p->winsize*(MYFLT)ATSA_NOISE_VARIANCE))); ar = p->aoutput; - for (n=0; noscphase[i]) * amp * randiats(csound, &(p->randinoise[i]))); p->oscphase[i] += p->phaseinc[i]; @@ -1073,8 +1503,6 @@ for (i = 0; i < (int) p->atshead->nfrms; i++) { /* init sums */ memset(bandsum, 0, 25*sizeof(double)); - /* for (k = 0; k < 25; k++) */ - /* bandsum[k] = 0.0; */ /* find sums per band */ for (j = 0; j < (int) p->atshead->npartials; j++) { partialfreq = *(curframe + 2 + j * (int) p->partialinc); @@ -1089,25 +1517,210 @@ } } - /* compute energy per partial */ - for (j = 0; j < (int) p->atshead->npartials; j++) { - if (bandsum[bandnum[j]] > 0.0) - *(p->nzdata + i * (int) p->atshead->npartials + j) = - (*(curframe + 1 + j * (int) p->partialinc) * *(partialband[j])) / - bandsum[bandnum[j]]; - else - *(p->nzdata + i * (int) p->atshead->npartials + j) = 0.0; - } - curframe += p->frmInc; + /* compute energy per partial */ + for (j = 0; j < (int) p->atshead->npartials; j++) { + if (bandsum[bandnum[j]] > 0.0) + *(p->nzdata + i * (int) p->atshead->npartials + j) = + (*(curframe + 1 + j * (int) p->partialinc) * *(partialband[j])) / + bandsum[bandnum[j]]; + else + *(p->nzdata + i * (int) p->atshead->npartials + j) = 0.0; + } + curframe += p->frmInc; + } + + free(partialband); + free(bandnum); +} + +static void fetchSINNOIpartials(ATSSINNOI *, MYFLT); + +static int atssinnoiset(CSOUND *csound, ATSSINNOI *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + int i, memsize, nzmemsize, type; + + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); + if (UNLIKELY(p->swapped < 0)){ + return NOTOK; + } + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; + p->atshead = atsh; + + /* calculate how much memory we have to allocate for this */ + /* need room for a buffer and the noise data and the noise info */ + /* per partial for synthesizing noise */ + memsize = (int) (*p->iptls) * (sizeof(ATS_DATA_LOC) + 2 * sizeof(double) + + sizeof(RANDIATS)); + /* allocate space if we need it */ + /* need room for a buffer and an array of oscillator phase increments */ + if(p->auxch.auxp != NULL || memsize > (int)p->auxch.size) + csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); + + /* set up the buffer, phase, etc. */ + p->oscbuf = (ATS_DATA_LOC *) (p->auxch.auxp); + p->randinoise = (RANDIATS *) (p->oscbuf + (int) (*p->iptls)); + p->oscphase = (double *) (p->randinoise + (int) (*p->iptls)); + p->nzbuf = (double *) (p->oscphase + (int) (*p->iptls)); + + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + p->npartials = (int) bswap(&atsh->npartials); + nzmemsize = (int) (p->npartials * bswap(&atsh->nfrms)); + type = (int) bswap(&atsh->type); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + p->npartials = (int) atsh->npartials; + nzmemsize = (int) (p->npartials * atsh->nfrms); + type = (int) atsh->type; + } + + /* see if we have to allocate memory for the nzdata */ + if (nzmemsize != p->nzmemsize) { + if (p->nzdata != NULL) + csound->Free(csound, p->nzdata); + p->nzdata = (double *) csound->Malloc(csound, sizeof(double) * nzmemsize); + } + + + /* make sure partials are in range */ + if (UNLIKELY((int) (*p->iptloffset + *p->iptls * *p->iptlincr) > p->npartials || + (int) (*p->iptloffset) < 0)) { + return csound->InitError(csound, + Str("ATSSINNOI: Partial(s) out of range, " + "max partial allowed is %i"), p->npartials); + } + /* get a pointer to the beginning of the data */ + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + /* get increments for the partials */ + + switch (type) { + case 1: + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int) (*p->iptlincr); + p->frmInc = p->npartials * 2 + 1; + p->firstband = -1; + break; + + case 2: + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int) (*p->iptlincr); + p->frmInc = p->npartials * 3 + 1; + p->firstband = -1; + break; + + case 3: + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int) (*p->iptlincr); + p->frmInc = p->npartials * 2 + 26; + p->firstband = 1 + 2 * p->npartials; + break; + + case 4: + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int) (*p->iptlincr); + p->frmInc = p->npartials * 3 + 26; + p->firstband = 1 + 3 * p->npartials; + break; + + default: + return csound->InitError(csound, Str("ATSSINNOI: Type not implemented")); + } + /* convert noise per band to noise per partial */ + /* make sure we do not do this if we have done it already. */ + if ((p->firstband != -1) && + ((p->filename == NULL) || (strcmp(atsfilname, p->filename) != 0) || + (p->nzmemsize != nzmemsize))) { + if (p->filename != NULL) + csound->Free(csound, p->filename); + p->filename = (char *) csound->Malloc(csound, + sizeof(char) * strlen(atsfilname)); + strcpy(p->filename, atsfilname); + /* csound->Message(csound, "\n band to energy res calculation %s \n", + p->filename); */ + /* calculate the band energys */ + band_energy_to_res(csound, p); + } + /* save the memory size of the noise */ + p->nzmemsize = nzmemsize; + + + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + + { + double tmp = TWOPI * csound->onedsr; + p->phaseinc[0] = 50.0 * tmp; + p->phaseinc[1] = 150.0 * tmp; + p->phaseinc[2] = 250.0 * tmp; + p->phaseinc[3] = 350.0 * tmp; + p->phaseinc[4] = 455.0 * tmp; + p->phaseinc[5] = 570.0 * tmp; + p->phaseinc[6] = 700.0 * tmp; + p->phaseinc[7] = 845.0 * tmp; + p->phaseinc[8] = 1000.0 * tmp; + p->phaseinc[9] = 1175.0 * tmp; + p->phaseinc[10] = 1375.0 * tmp; + p->phaseinc[11] = 1600.0 * tmp; + p->phaseinc[12] = 1860.0 * tmp; + p->phaseinc[13] = 2160.0 * tmp; + p->phaseinc[14] = 2510.0 * tmp; + p->phaseinc[15] = 2925.0 * tmp; + p->phaseinc[16] = 3425.0 * tmp; + p->phaseinc[17] = 4050.0 * tmp; + p->phaseinc[18] = 4850.0 * tmp; + p->phaseinc[19] = 5850.0 * tmp; + p->phaseinc[20] = 7050.0 * tmp; + p->phaseinc[21] = 8600.0 * tmp; + p->phaseinc[22] = 10750.0 * tmp; + p->phaseinc[23] = 13750.0 * tmp; + p->phaseinc[24] = 17750.0 * tmp; + } + + /* initialise phase */ + memset(p->noiphase, 0, 25*sizeof(double)); + /* p->noiphase[0] = 0.0; */ + /* p->noiphase[1] = 0.0; */ + /* p->noiphase[2] = 0.0; */ + /* p->noiphase[3] = 0.0; */ + /* p->noiphase[4] = 0.0; */ + /* p->noiphase[5] = 0.0; */ + /* p->noiphase[6] = 0.0; */ + /* p->noiphase[7] = 0.0; */ + /* p->noiphase[8] = 0.0; */ + /* p->noiphase[9] = 0.0; */ + /* p->noiphase[10] = 0.0; */ + /* p->noiphase[11] = 0.0; */ + /* p->noiphase[12] = 0.0; */ + /* p->noiphase[13] = 0.0; */ + /* p->noiphase[14] = 0.0; */ + /* p->noiphase[15] = 0.0; */ + /* p->noiphase[16] = 0.0; */ + /* p->noiphase[17] = 0.0; */ + /* p->noiphase[18] = 0.0; */ + /* p->noiphase[19] = 0.0; */ + /* p->noiphase[20] = 0.0; */ + /* p->noiphase[21] = 0.0; */ + /* p->noiphase[22] = 0.0; */ + /* p->noiphase[23] = 0.0; */ + /* p->oscphase[24] = 0.0; */ + + /* initialise band limited noise parameters */ + for (i = 0; i < (int) *p->iptls; i++) { + randiats_setup(csound, freqs[i], &(p->randinoise[i])); } - free(partialband); - free(bandnum); + return OK; } -static void fetchSINNOIpartials(ATSSINNOI *, MYFLT); - -static int atssinnoiset(CSOUND *csound, ATSSINNOI *p) +static int atssinnoiset_S(CSOUND *csound, ATSSINNOI *p) { char atsfilname[MAXNAME]; ATSSTRUCT *atsh; @@ -1115,7 +1728,7 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); if (UNLIKELY(p->swapped < 0)){ return NOTOK; } @@ -1129,7 +1742,7 @@ + sizeof(RANDIATS)); /* allocate space if we need it */ /* need room for a buffer and an array of oscillator phase increments */ - if(p->auxch.auxp != NULL || memsize > p->auxch.size) + if(p->auxch.auxp != NULL || memsize > (int)p->auxch.size) csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); /* set up the buffer, phase, etc. */ @@ -1174,29 +1787,29 @@ switch (type) { case 1: - p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); - p->partialinc = 2 * (int) (*p->iptlincr); + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int)(*p->iptlincr); p->frmInc = p->npartials * 2 + 1; p->firstband = -1; break; case 2: - p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); - p->partialinc = 3 * (int) (*p->iptlincr); + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int)(*p->iptlincr); p->frmInc = p->npartials * 3 + 1; p->firstband = -1; break; case 3: - p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); - p->partialinc = 2 * (int) (*p->iptlincr); + p->firstpartial = 1 + 2 * (int)(*p->iptloffset); + p->partialinc = 2 * (int)(*p->iptlincr); p->frmInc = p->npartials * 2 + 26; p->firstband = 1 + 2 * p->npartials; break; case 4: - p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); - p->partialinc = 3 * (int) (*p->iptlincr); + p->firstpartial = 1 + 3 * (int)(*p->iptloffset); + p->partialinc = 3 * (int)(*p->iptlincr); p->frmInc = p->npartials * 3 + 26; p->firstband = 1 + 3 * p->npartials; break; @@ -1258,31 +1871,6 @@ /* initialise phase */ memset(p->noiphase, 0, 25*sizeof(double)); - /* p->noiphase[0] = 0.0; */ - /* p->noiphase[1] = 0.0; */ - /* p->noiphase[2] = 0.0; */ - /* p->noiphase[3] = 0.0; */ - /* p->noiphase[4] = 0.0; */ - /* p->noiphase[5] = 0.0; */ - /* p->noiphase[6] = 0.0; */ - /* p->noiphase[7] = 0.0; */ - /* p->noiphase[8] = 0.0; */ - /* p->noiphase[9] = 0.0; */ - /* p->noiphase[10] = 0.0; */ - /* p->noiphase[11] = 0.0; */ - /* p->noiphase[12] = 0.0; */ - /* p->noiphase[13] = 0.0; */ - /* p->noiphase[14] = 0.0; */ - /* p->noiphase[15] = 0.0; */ - /* p->noiphase[16] = 0.0; */ - /* p->noiphase[17] = 0.0; */ - /* p->noiphase[18] = 0.0; */ - /* p->noiphase[19] = 0.0; */ - /* p->noiphase[20] = 0.0; */ - /* p->noiphase[21] = 0.0; */ - /* p->noiphase[22] = 0.0; */ - /* p->noiphase[23] = 0.0; */ - /* p->oscphase[24] = 0.0; */ /* initialise band limited noise parameters */ for (i = 0; i < (int) *p->iptls; i++) { @@ -1295,7 +1883,9 @@ static int atssinnoi(CSOUND *csound, ATSSINNOI *p) { MYFLT frIndx; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; MYFLT *ar; double noise; double inc; @@ -1339,9 +1929,8 @@ /* set local pointer to output and initialise output to zero */ ar = p->aoutput; - memset(ar, 0, csound->ksmps*sizeof(MYFLT)); -/* for (i = 0; i < csound->ksmps; i++) */ -/* *ar++ = FL(0.0); */ + memset(ar, 0, CS_KSMPS*sizeof(MYFLT)); + if (UNLIKELY(early)) nsmps -= early; oscbuf = p->oscbuf; @@ -1356,22 +1945,21 @@ inc = TWOPI * freq * csound->onedsr; nzamp = sqrt(*(p->nzbuf + i) / (p->atshead->winsz * ATSA_NOISE_VARIANCE)); - for (n=0; nnoiphase[i]) - * randiats(csound, &(p->randinoise[i])); - p->noiphase[i] += p->phaseinc[i]; + noise = nzamp * cos(p->noiphase[i]) * + randiats(csound, &(p->randinoise[i])); + p->noiphase[i] += p->phaseinc[i]; } else noise = FL(0.0); /* calc output */ ar[n] += csound->e0dbfs * (MYFLT)(amp * sinewave * *p->ksinamp + noise **p->knzamp); - } p->oscphase[i] = phase; } @@ -1384,7 +1972,7 @@ amp = oscbuf[i].amp; freq = (MYFLT) oscbuf[i].freq * *p->kfreq; inc = TWOPI * freq * csound->onedsr; - for (n=0; nswapped = load_atsfile(csound, p, &mfp, atsfilname, p->ifileno); + p->swapped = load_atsfile(csound, p, &mfp, atsfilname, p->ifileno, 0); if (UNLIKELY(p->swapped < 0)) return NOTOK; atsh = (ATSSTRUCT*) mfp->beginp; @@ -1578,8 +2166,102 @@ p->utable = fltp + ((int) *(p->iptls) + 2); /* check to see if partial is valid */ - if (UNLIKELY((int) (*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || - (int) (*p->iptloffset) < 0)) { + if (UNLIKELY((int)(*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || + (int)(*p->iptloffset) < 0)) { + return csound->InitError(csound, Str("ATSBUFREAD: Partial out of range, " + "max partial is %i"), n_partials); + } + + /* set up partial locations and frame increments */ + + switch (type) { + case 1: + p->firstpartial = 1 + 2 * (*p->iptloffset); + p->partialinc = 2; + p->frmInc = n_partials * 2 + 1; + break; + + case 2: + p->firstpartial = 1 + 3 * (*p->iptloffset); + p->partialinc = 3; + p->frmInc = n_partials * 3 + 1; + break; + + case 3: + p->firstpartial = 1 + 2 * (*p->iptloffset); + p->partialinc = 2; + p->frmInc = n_partials * 2 + 26; + break; + + case 4: + p->firstpartial = 1 + 3 * (*p->iptloffset); + p->partialinc = 3; + p->frmInc = n_partials * 3 + 26; + break; + + default: + return csound->InitError(csound, Str("ATSBUFREAD: Type not implemented")); + } + + /* put 20 hertz = 0amp and 20000 hz = 0amp */ + /* to make interpolation easier later */ + p->table[0].freq = p->utable[0].freq = 20; + p->table[0].amp = p->utable[0].amp = 0; + p->table[(int) *p->iptls + 1].freq = p->utable[(int) *p->iptls + 1].freq = + 20000; + p->table[(int) *p->iptls + 1].amp = p->utable[(int) *p->iptls + 1].amp = 0; + + *(get_atsbufreadaddrp(csound)) = p; + + return OK; +} + +static int atsbufreadset_S(CSOUND *csound, ATSBUFREAD *p) +{ + char atsfilname[MAXNAME]; + MEMFIL *mfp; + ATS_DATA_LOC *fltp; + ATSSTRUCT *atsh; + int type, n_partials; + int memsize; /* the size of the memory to request for AUX */ + + /* load memfile */ + p->swapped = load_atsfile(csound, p, &mfp, atsfilname, p->ifileno, 1); + if (UNLIKELY(p->swapped < 0)) + return NOTOK; + atsh = (ATSSTRUCT*) mfp->beginp; + + /* get past the header to the data, point frptr at time 0 */ + p->datastart = (double *) atsh + 10; + p->prFlg = 1; /* true */ + + /* is swapped? */ + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + type = (int) bswap(&atsh->type); + n_partials = (int) bswap(&atsh->npartials); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + type = (int) atsh->type; + n_partials = (int) atsh->npartials; + } + + /* we need room for 2 * (1 table + 2 for 20 and 20,000 hz) */ + /* (one sorted one unsorted) */ + memsize = 2 * ((int) *(p->iptls) + 2); + + csound->AuxAlloc(csound, (size_t)memsize * sizeof(ATS_DATA_LOC), &p->auxch); + + fltp = (ATS_DATA_LOC *) p->auxch.auxp; + p->table = fltp; + p->utable = fltp + ((int) *(p->iptls) + 2); + + /* check to see if partial is valid */ + if (UNLIKELY((int)(*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || + (int)(*p->iptloffset) < 0)) { return csound->InitError(csound, Str("ATSBUFREAD: Partial out of range, " "max partial is %i"), n_partials); } @@ -1628,6 +2310,7 @@ return OK; } + static int mycomp(const void *p1, const void *p2) { const ATS_DATA_LOC *a1 = p1; @@ -1748,7 +2431,8 @@ return OK; err1: - return csound->PerfError(csound, Str("ATSBUFREAD: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("ATSBUFREAD: not initialised")); } /* ATS partial tap */ @@ -1781,11 +2465,11 @@ atsbufreadaddr = *(get_atsbufreadaddrp(csound)); if (UNLIKELY(atsbufreadaddr == NULL)) goto err1; - *p->kfreq = (MYFLT) ((atsbufreadaddr->utable)[(int) (*p->iparnum)].freq); - *p->kamp = (MYFLT) ((atsbufreadaddr->utable)[(int) (*p->iparnum)].amp); + *p->kfreq = (MYFLT) ((atsbufreadaddr->utable)[(int)(*p->iparnum)].freq); + *p->kamp = (MYFLT) ((atsbufreadaddr->utable)[(int)(*p->iparnum)].amp); return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("ATSPARTIALTAP: you must have an " "atsbufread before an atspartialtap")); } @@ -1843,7 +2527,7 @@ /* *p->kamp = (MYFLT) (atsbufreadaddr->table[i]).amp; */ return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("ATSINTERPREAD: you must have an " "atsbufread before an atsinterpread")); } @@ -1867,23 +2551,23 @@ /* load memfile */ p->swapped = load_atsfile(csound, - p, &(p->atsmemfile), atsfilname, p->ifileno); + p, &(p->atsmemfile), atsfilname, p->ifileno, 0); if (p->swapped < 0) return NOTOK; atsh = (ATSSTRUCT*) p->atsmemfile->beginp; /* calculate how much memory we have to allocate for this */ - memsize = (int) (*p->iptls) * + memsize = (int)(*p->iptls) * (sizeof(ATS_DATA_LOC) + sizeof(double) + sizeof(MYFLT)) ; /* allocate space if we need it */ /* need room for a buffer and an array of oscillator phase increments */ - if (p->auxch.auxp == NULL || p->auxch.size >= memsize) + if (p->auxch.auxp == NULL || p->auxch.size >= (unsigned int)memsize) csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); /* set up the buffer, phase, etc. */ p->buf = (ATS_DATA_LOC *) (p->auxch.auxp); - p->oscphase = (double *) (p->buf + (int) (*p->iptls)); - p->oldamps = (MYFLT *) (p->oscphase + (int) (*p->iptls)); + p->oscphase = (double *) (p->buf + (int)(*p->iptls)); + p->oldamps = (MYFLT *) (p->oscphase + (int)(*p->iptls)); if (p->swapped == 1) { p->maxFr = (int) bswap(&atsh->nfrms) - 1; p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); @@ -1898,8 +2582,8 @@ } /* make sure partials are in range */ - if ((int) (*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || - (int) (*p->iptloffset) < 0) { + if ((int)(*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || + (int)(*p->iptloffset) < 0) { return csound->InitError(csound, Str("ATSCROSS: Partial(s) out of range, " "max partial allowed is %i"), n_partials); @@ -1911,25 +2595,119 @@ switch (type) { case 1: p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); - p->partialinc = 2 * (int) (*p->iptlincr); + p->partialinc = 2 * (int)(*p->iptlincr); p->frmInc = n_partials * 2 + 1; break; case 2: p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); - p->partialinc = 3 * (int) (*p->iptlincr); + p->partialinc = 3 * (int)(*p->iptlincr); p->frmInc = n_partials * 3 + 1; break; case 3: p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); - p->partialinc = 2 * (int) (*p->iptlincr); + p->partialinc = 2 * (int)(*p->iptlincr); p->frmInc = n_partials * 2 + 26; break; case 4: p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); - p->partialinc = 3 * (int) (*p->iptlincr); + p->partialinc = 3 * (int)(*p->iptlincr); + p->frmInc = n_partials * 3 + 26; + break; + + default: + return csound->InitError(csound, Str("ATSCROSS: Type not implemented")); + } + + /* flag set to reduce the amount of warnings sent out */ + /* for time pointer out of range */ + p->prFlg = 1; /* true */ + + return OK; +} + +static int atscrossset_S(CSOUND *csound, ATSCROSS *p) +{ + char atsfilname[MAXNAME]; + ATSSTRUCT *atsh; + FUNC *ftp; + int memsize; + int type, n_partials; + + /* set up function table for synthesis */ + if (UNLIKELY((ftp = csound->FTFind(csound, p->ifn)) == NULL)) { + return csound->InitError(csound, Str("ATSCROSS: Function table number for " + "synthesis waveform not valid")); + } + p->ftp = ftp; + + /* load memfile */ + p->swapped = load_atsfile(csound, + p, &(p->atsmemfile), atsfilname, p->ifileno, 1); + if (p->swapped < 0) + return NOTOK; + atsh = (ATSSTRUCT*) p->atsmemfile->beginp; + + /* calculate how much memory we have to allocate for this */ + memsize = (int)(*p->iptls) * + (sizeof(ATS_DATA_LOC) + sizeof(double) + sizeof(MYFLT)) ; + /* allocate space if we need it */ + /* need room for a buffer and an array of oscillator phase increments */ + if (p->auxch.auxp == NULL || p->auxch.size >= (unsigned int)memsize) + csound->AuxAlloc(csound, (size_t) memsize, &p->auxch); + + /* set up the buffer, phase, etc. */ + p->buf = (ATS_DATA_LOC *) (p->auxch.auxp); + p->oscphase = (double *) (p->buf + (int)(*p->iptls)); + p->oldamps = (MYFLT *) (p->oscphase + (int)(*p->iptls)); + if (p->swapped == 1) { + p->maxFr = (int) bswap(&atsh->nfrms) - 1; + p->timefrmInc = bswap(&atsh->nfrms) / bswap(&atsh->dur); + type = (int) bswap(&atsh->type); + n_partials = (int) bswap(&atsh->npartials); + } + else { + p->maxFr = (int) atsh->nfrms - 1; + p->timefrmInc = atsh->nfrms / atsh->dur; + type = (int) atsh->type; + n_partials = (int) atsh->npartials; + } + + /* make sure partials are in range */ + if ((int)(*p->iptloffset + *p->iptls * *p->iptlincr) > n_partials || + (int)(*p->iptloffset) < 0) { + return csound->InitError(csound, Str("ATSCROSS: Partial(s) out of range, " + "max partial allowed is %i"), + n_partials); + } + /* get a pointer to the beginning of the data */ + p->datastart = (double *) (p->atsmemfile->beginp + sizeof(ATSSTRUCT)); + + /* get increments for the partials */ + switch (type) { + case 1: + p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); + p->partialinc = 2 * (int)(*p->iptlincr); + p->frmInc = n_partials * 2 + 1; + break; + + case 2: + p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); + p->partialinc = 3 * (int)(*p->iptlincr); + p->frmInc = n_partials * 3 + 1; + break; + + case 3: + p->firstpartial = (int) (1 + 2 * (*p->iptloffset)); + p->partialinc = 2 * (int)(*p->iptlincr); + p->frmInc = n_partials * 2 + 26; + break; + + case 4: + p->firstpartial = (int) (1 + 3 * (*p->iptloffset)); + p->partialinc = 3 * (int)(*p->iptlincr); p->frmInc = n_partials * 3 + 26; break; @@ -2055,7 +2833,10 @@ FUNC *ftp; int32 lobits, phase, inc; double *oscphase; - int i, n, nsmps = csound->ksmps; + int i; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int numpartials = (int) *p->iptls; ATS_DATA_LOC *buf; @@ -2102,20 +2883,19 @@ /* initialise output to zero */ ar = p->aoutput; memset(ar, 0, nsmps*sizeof(MYFLT)); -/* for (i = 0; i < nsmps; i++) */ -/* ar[i] = FL(0.0); */ + if (UNLIKELY(early)) nsmps -= early; for (i = 0; i < numpartials; i++) { lobits = ftp->lobits; amp = csound->e0dbfs * (MYFLT) p->buf[i].amp; phase = MYFLT2LONG (oscphase[i]); ar = p->aoutput; /* ar is a pointer to the audio output */ - nsmps = csound->ksmps; + nsmps = CS_KSMPS; inca = (amp-oldamps[i])/nsmps; /* put in * kfmod */ inc = MYFLT2LONG(p->buf[i].freq * csound->sicvt * *p->kfmod); a = oldamps[i]; - for (n=0; nftable + (phase >> lobits); v1 = ftab[0]; fract = (MYFLT) PFRAC(phase); @@ -2130,7 +2910,7 @@ } return OK; err1: - return csound->PerfError(csound, + return csound->PerfError(csound, p->h.insdshead, Str("ATSCROSS: you must have an " "atsbufread before an atsinterpread")); } @@ -2140,25 +2920,41 @@ #define S(x) sizeof(x) static OENTRY localops[] = { - { "ATSread", S(ATSREAD), 3, "kk", "kTi", + { "ATSread", S(ATSREAD), 0, 3, "kk", "kSi", + (SUBR) atsreadset_S, (SUBR) atsread, (SUBR) NULL }, + { "ATSread.i", S(ATSREAD), 0, 3, "kk", "kii", (SUBR) atsreadset, (SUBR) atsread, (SUBR) NULL }, - { "ATSreadnz", S(ATSREADNZ), 3, "k", "kTi", + { "ATSreadnz", S(ATSREADNZ), 0, 3, "k", "kSi", + (SUBR) atsreadnzset_S, (SUBR) atsreadnz, (SUBR) NULL }, + { "ATSreadnz.i", S(ATSREADNZ), 0, 3, "k", "kii", (SUBR) atsreadnzset, (SUBR) atsreadnz, (SUBR) NULL }, - { "ATSadd", S(ATSADD), TR|5, "a", "kkTiiopo", + { "ATSadd", S(ATSADD), TR, 5, "a", "kkSiiopo", + (SUBR) atsaddset_S, (SUBR) NULL, (SUBR) atsadd }, + { "ATSadd.i", S(ATSADD), TR, 5, "a", "kkiiiopo", (SUBR) atsaddset, (SUBR) NULL, (SUBR) atsadd }, - { "ATSaddnz", S(ATSADDNZ), 5, "a", "kTiop", + { "ATSaddnz", S(ATSADDNZ), 0, 5, "a", "kSiop", + (SUBR) atsaddnzset_S, (SUBR) NULL, (SUBR) atsaddnz }, + { "ATSaddnz.i", S(ATSADDNZ), 0, 5, "a", "kiiop", (SUBR) atsaddnzset, (SUBR) NULL, (SUBR) atsaddnz }, - { "ATSsinnoi", S(ATSSINNOI), 5, "a", "kkkkTiop", + { "ATSsinnoi", S(ATSSINNOI), 0,5, "a", "kkkkSiop", + (SUBR) atssinnoiset_S, (SUBR) NULL, (SUBR) atssinnoi }, + { "ATSsinnoi.i", S(ATSSINNOI), 0,5, "a", "kkkkiiop", (SUBR) atssinnoiset, (SUBR) NULL, (SUBR) atssinnoi }, - { "ATSbufread", S(ATSBUFREAD), 3, "", "kkTiop", + { "ATSbufread", S(ATSBUFREAD), 0,3, "", "kkSiop", + (SUBR) atsbufreadset_S, (SUBR) atsbufread, (SUBR) NULL }, + { "ATSbufread.i", S(ATSBUFREAD), 0,3, "", "kkiiop", (SUBR) atsbufreadset, (SUBR) atsbufread, (SUBR) NULL }, - { "ATSpartialtap", S(ATSPARTIALTAP), 3, "kk", "i", + { "ATSpartialtap", S(ATSPARTIALTAP), 0,3, "kk", "i", (SUBR) atspartialtapset, (SUBR) atspartialtap, (SUBR) NULL }, - { "ATSinterpread", S(ATSINTERPREAD), 3, "k", "k", + { "ATSinterpread", S(ATSINTERPREAD), 0,3, "k", "k", (SUBR) atsinterpreadset, (SUBR) atsinterpread, (SUBR) NULL }, - { "ATScross", S(ATSCROSS), TR|5, "a", "kkTikkiopoo", + { "ATScross", S(ATSCROSS), TR, 5, "a", "kkSikkiopoo", + (SUBR) atscrossset_S, (SUBR) NULL, (SUBR) atscross }, + { "ATSinfo", S(ATSINFO), 0,1, "i", "Si", + (SUBR) atsinfo_S, (SUBR) NULL, (SUBR) NULL }, + { "ATScross.i", S(ATSCROSS), TR, 5, "a", "kkiikkiopoo", (SUBR) atscrossset, (SUBR) NULL, (SUBR) atscross }, - { "ATSinfo", S(ATSINFO), 1, "i", "Ti", + { "ATSinfo.i", S(ATSINFO), 0,1, "i", "ii", (SUBR) atsinfo, (SUBR) NULL, (SUBR) NULL } }; diff -Nru csound-5.17.11~dfsg/Opcodes/ugnorman.h csound-6.02~dfsg/Opcodes/ugnorman.h --- csound-5.17.11~dfsg/Opcodes/ugnorman.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugnorman.h 2014-01-07 16:53:48.000000000 +0000 @@ -77,7 +77,7 @@ /* indicates the maximun frame */ int maxFr; /* a flag used to indicate if we've steped out of the time range */ - /* of the data, so we don't print too many warnings */ + /* of the data, so we do not print too many warnings */ int prFlg; /* points to the start of the data */ double *datastart; @@ -95,7 +95,7 @@ MYFLT *kenergy, *ktimpnt, *ifileno, *inzbin; /* outputs (1) and inputs */ int maxFr; /* a flag used to indicate if we've steped out of the time range */ - /* of the data, so we don't print too many warnings */ + /* of the data, so we do not print too many warnings */ int prFlg; double *datastart; /* points to the start of the data */ int nzbandloc, frmInc; @@ -117,7 +117,7 @@ double maxFr; /* a flag used to indicate if we've steped out of the time range */ - /* of the data, so we don't print too many warnings */ + /* of the data, so we do not print too many warnings */ int prFlg; double timefrmInc; double MaxAmp; /* maximum amplitude in anaylsis file */ @@ -193,7 +193,7 @@ double maxFr; /* a flag used to indicate if we've steped out of the time range */ - /* of the data, so we don't print too many warnings */ + /* of the data, so we do not print too many warnings */ int prFlg; double timefrmInc; double MaxAmp; /* maximum amplitude in anaylsis file */ diff -Nru csound-5.17.11~dfsg/Opcodes/ugsc.c csound-6.02~dfsg/Opcodes/ugsc.c --- csound-5.17.11~dfsg/Opcodes/ugsc.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/ugsc.c 2014-01-07 16:54:20.000000000 +0000 @@ -23,7 +23,7 @@ /* ugsc.c -- Opcodes from Sean Costello */ -#include "csdl.h" +#include "stdopcod.h" #include "ugsc.h" /* svfilter.c @@ -47,17 +47,14 @@ static int svf(CSOUND *csound, SVF *p) { - MYFLT f1, q1, scale; + MYFLT f1 = FL(0.0), q1 = FL(1.0), scale = FL(1.0), + lfco = -FL(1.0), lq = -FL(1.0); MYFLT *low, *high, *band, *in, ynm1, ynm2; MYFLT low2, high2, band2; - MYFLT kfco = *p->kfco, kq = *p->kq; - int n, nsmps = csound->ksmps; - - /* calculate frequency and Q coefficients */ - f1 = FL(2.0) * (MYFLT)sin((double)(kfco * csound->pidsr)); - /* Protect against division by zero */ - if (UNLIKELY(kqkfco, *kq = p->kq; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; in = p->in; low = p->low; @@ -66,18 +63,36 @@ ynm1 = p->ynm1; ynm2 = p->ynm2; - /* if there is a non-zero value for iscl, set scale to be - * equal to the Q coefficient. - */ - if (*p->iscl) - scale = q1; - else - scale = FL(1.0); /* equations derived from Hal Chamberlin, "Musical Applications * of Microprocessors. */ - for (n=0; npidsr)); + /* Protect against division by zero */ + if (UNLIKELY(qiscl) scale = q1; + } low[n] = low2 = ynm2 + f1 * ynm1; high[n] = high2 = scale * in[n] - low2 - q1 * ynm1; band[n] = band2 = f1 * high2 + ynm1; @@ -110,8 +125,8 @@ double polefreq, rc, alpha, beta; /* calculate coefficients for allpass filters, based on sampling rate */ for (j=0; j<12; j++) { - /* p->coef[j] = (1 - (15 * PI * pole[j]) / csound->esr) / - (1 + (15 * PI * pole[j]) / csound->esr); */ + /* p->coef[j] = (1 - (15 * PI * pole[j]) / CS_ESR) / + (1 + (15 * PI * pole[j]) / CS_ESR); */ polefreq = poles[j] * 15.0; rc = 1.0 / (2.0 * PI * polefreq); alpha = 1.0 / rc; @@ -128,7 +143,9 @@ MYFLT xn1, yn1, xn2, yn2; MYFLT *out1, *out2, *in; MYFLT *coef; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int j; coef = p->coef; @@ -136,8 +153,16 @@ out2 = p->out2; in = p->in; - /* These two loops could be jammed */ - for (n=0; nistor)) p->xnm1 = p->xnm2 = p->ynm1 = p->ynm2 = 0.0; - -/* p->aratemod = (XINARG2) ? 1 : 0; */ - return OK; } @@ -208,23 +230,15 @@ * */ - double r, scale; /* radius & scaling factor */ - double c1, c2; /* filter coefficients */ + double r = 0.0, scale = 1.0; /* radius & scaling factor */ + double c1=0.0, c2=0.0; /* filter coefficients */ MYFLT *out, *in; double xn, yn, xnm1, xnm2, ynm1, ynm2; - MYFLT kcf = *p->kcf, kbw = *p->kbw; - int n, nsmps = csound->ksmps; - - r = exp((double)(kbw * csound->mpidsr)); - c1 = 2.0 * r * cos((double)(kcf * csound->tpidsr)); - c2 = r * r; - - /* calculation of scaling coefficients */ - if (p->scaletype == 1) - scale = 1.0 - r; - else if (p->scaletype == 2) - scale = sqrt(1.0 - r); - else scale = 1.0; + MYFLT *kcf = p->kcf, *kbw = p->kbw; + MYFLT lcf = -FL(1.0), lbw = -FL(1.0); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; out = p->out; in = p->in; @@ -233,7 +247,24 @@ ynm1 = p->ynm1; ynm2 = p->ynm2; - for (n=0; nmpidsr)); + c1 = 2.0 * r * cos((double)(cf * csound->tpidsr)); + c2 = r * r; + if (p->scaletype == 1) + scale = 1.0 - r; + else if (p->scaletype == 2) + scale = sqrt(1.0 - r); + } xn = (double)in[n]; out[n] = (MYFLT)(yn = scale * (xn - r * xnm2) + c1 * ynm1 - c2 * ynm2); xnm2 = xnm1; @@ -261,26 +292,20 @@ * */ - double r, scale; /* radius & scaling factor */ - double c1, c2; /* filter coefficients */ + double r = 0.0, scale = 1.0; /* radius & scaling factor */ + double c1=0.0, c2=0.0; /* filter coefficients */ MYFLT *out, *in; double xn, yn, xnm1, xnm2, ynm1, ynm2; - MYFLT kcf = *p->kcf, kbw = *p->kbw; - int n, nsmps = csound->ksmps; - - r = exp(-(double)(kbw * csound->pidsr)); - c1 = 2.0 * r * cos((double)(csound->tpidsr*kcf)); - c2 = r * r; + MYFLT *kcf = p->kcf, *kbw = p->kbw; + MYFLT lcf = -FL(1.0), lbw = -FL(1.0); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; /* Normalizing factors derived from equations in Ken Steiglitz, * "A Note on Constant-Gain Digital Resonators," Computer * Music Journal, vol. 18, no. 4, pp. 8-10, Winter 1982. */ - if (p->scaletype == 1) - scale = (1.0 - c2) * 0.5; - else if (p->scaletype == 2) - scale = sqrt((1.0 - c2) * 0.5); - else scale = 1.0; out = p->out; in = p->in; @@ -289,7 +314,24 @@ ynm1 = p->ynm1; ynm2 = p->ynm2; - for (n=0; npidsr)); + c1 = 2.0 * r * cos((double)(csound->tpidsr*cf)); + c2 = r * r; + if (p->scaletype == 1) + scale = (1.0 - c2) * 0.5; + else if (p->scaletype == 2) + scale = sqrt((1.0 - c2) * 0.5); + } xn = (double)in[n]; out[n] = (MYFLT)(yn = scale * (xn - xnm2) + c1 * ynm1 - c2 * ynm2); xnm2 = xnm1; @@ -310,8 +352,9 @@ int loop = (int) MYFLT2LONG(*p->iorder); int32 nBytes = (int32) loop * (int32) sizeof(MYFLT); - if (*p->istor == FL(0.0) || p->auxx.auxp == NULL || p->auxx.sizeauxy.auxp == NULL || p->auxy.sizeistor == FL(0.0) || p->auxx.auxp == NULL || + (int)p->auxx.sizeauxy.auxp == NULL || + (int)p->auxy.sizeAuxAlloc(csound, nBytes, &p->auxx); csound->AuxAlloc(csound, nBytes, &p->auxy); p->xnm1 = (MYFLT *) p->auxx.auxp; @@ -343,17 +386,18 @@ MYFLT xn = FL(0.0), yn = FL(0.0); MYFLT *out, *in; MYFLT feedback; - MYFLT coef = *p->kcoef, fbgain = *p->fbgain; + MYFLT coef = FABS(*p->kcoef), fbgain = *p->fbgain; MYFLT beta, wp; - int nsmps = csound->ksmps; - int i, j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int j; feedback = p->feedback; out = p->out; in = p->in; - if (coef <= FL(0.0)) - coef = -coef; /* frequency will "fold over" if <= 0 Hz */ + //if (coef<=FL(0.0)) coef = -coef; /* frequency will "fold over" if <= 0 Hz */ /* next two lines implement bilinear z-transform, to convert * frequency value into a useable coefficient for the * allpass filters. @@ -361,7 +405,12 @@ wp = csound->pidsr * coef; beta = (FL(1.0) - wp)/(FL(1.0) + wp); - for (i=0; iloop; j++) { /* Difference equation for 1st order @@ -410,7 +459,9 @@ MYFLT b, a, r, freq; MYFLT temp; MYFLT *nm1, *nm2, feedback; - int n, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; int j; nm1 = p->nm1; @@ -429,7 +480,12 @@ if (ksep <= FL(0.0)) ksep = -ksep; - for (n=0; nkfco, kres = *p->kres; - int nsmps = csound->ksmps; - int n; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; temp = (double)(csound->mpidsr * kfco / kres); - /* (-PI_F * kfco / (kres * csound->esr)); */ + /* (-PI_F * kfco / (kres * CS_ESR)); */ a = 2.0 * cos((double) (kfco * csound->tpidsr)) * exp(temp); b = exp(temp+temp); c = 1.0 - a + b; @@ -504,7 +561,147 @@ ynm1 = p->ynm1; ynm2 = p->ynm2; - for (n=0; nynm1 = ynm1; + p->ynm2 = ynm2; + return OK; +} + +static int lp2aa(CSOUND *csound, LP2 *p) +{ + double a, b, c, temp; + MYFLT *out, *in; + double yn, ynm1, ynm2; + MYFLT *fcop = p->kfco, *resp = p->kres; + MYFLT fco = fcop[0], res = resp[0]; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + temp = (double)(csound->mpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + + out = p->out; + in = p->in; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nmpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + } + out[n] = (MYFLT)(yn = a * ynm1 - b * ynm2 + c * (double)in[n]); + ynm2 = ynm1; + ynm1 = yn; + } + p->ynm1 = ynm1; + p->ynm2 = ynm2; + return OK; +} + +static int lp2ka(CSOUND *csound, LP2 *p) +{ + double a, b, c, temp; + MYFLT *out, *in; + double yn, ynm1, ynm2; + MYFLT *resp = p->kres; + MYFLT fco = *p->kfco, res = resp[0]; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + temp = (double)(csound->mpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + + out = p->out; + in = p->in; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nmpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + } + out[n] = (MYFLT)(yn = a * ynm1 - b * ynm2 + c * (double)in[n]); + ynm2 = ynm1; + ynm1 = yn; + } + p->ynm1 = ynm1; + p->ynm2 = ynm2; + return OK; +} + +static int lp2ak(CSOUND *csound, LP2 *p) +{ + double a, b, c, temp; + MYFLT *out, *in; + double yn, ynm1, ynm2; + MYFLT *fcop = p->kfco; + MYFLT fco = fcop[0], res = *p->kres; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + temp = (double)(csound->mpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + + out = p->out; + in = p->in; + ynm1 = p->ynm1; + ynm2 = p->ynm2; + + if (UNLIKELY(offset)) memset(out, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&out[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nmpidsr * fco / res); + /* (-PI_F * kfco / (kres * CS_ESR)); */ + a = 2.0 * cos((double) (fco * csound->tpidsr)) * exp(temp); + b = exp(temp+temp); + c = 1.0 - a + b; + } out[n] = (MYFLT)(yn = a * ynm1 - b * ynm2 + c * (double)in[n]); ynm2 = ynm1; ynm1 = yn; @@ -517,13 +714,16 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "svfilter", S(SVF), 5, "aaa", "akko", (SUBR)svfset, NULL, (SUBR)svf }, -{ "hilbert", S(HILBERT), 5, "aa", "a", (SUBR)hilbertset, NULL, (SUBR)hilbert }, -{ "resonr", S(RESONZ), 5, "a", "akkoo", (SUBR)resonzset, NULL, (SUBR)resonr }, -{ "resonz", S(RESONZ), 5, "a", "akkoo", (SUBR)resonzset, NULL, (SUBR)resonz }, -{ "lowpass2", S(LP2), 5, "a", "akko", (SUBR)lp2_set, NULL, (SUBR)lp2 }, -{ "phaser2", S(PHASER2), 5, "a", "akkkkkk",(SUBR)phaser2set, NULL, (SUBR)phaser2 }, -{ "phaser1", S(PHASER1), 5, "a", "akkko", (SUBR)phaser1set, NULL, (SUBR)phaser1 } +{ "svfilter", S(SVF), 0, 5, "aaa", "axxo", (SUBR)svfset, NULL, (SUBR)svf }, +{ "hilbert", S(HILBERT), 0, 5, "aa", "a", (SUBR)hilbertset, NULL, (SUBR)hilbert }, +{ "resonr", S(RESONZ), 0, 5, "a", "axxoo", (SUBR)resonzset, NULL, (SUBR)resonr}, +{ "resonz", S(RESONZ), 0, 5, "a", "axxoo", (SUBR)resonzset, NULL, (SUBR)resonz}, +{ "lowpass2.kk", S(LP2), 0, 5, "a", "akko", (SUBR)lp2_set, NULL, (SUBR)lp2 }, +{ "lowpass2.aa", S(LP2), 0, 5, "a", "aaao", (SUBR)lp2_set, NULL, (SUBR)lp2aa }, +{ "lowpass2.ak", S(LP2), 0, 5, "a", "aakao", (SUBR)lp2_set, NULL, (SUBR)lp2ak }, +{ "lowpass2.ka", S(LP2), 0, 5, "a", "akao", (SUBR)lp2_set, NULL, (SUBR)lp2ka }, +{ "phaser2", S(PHASER2), 0, 5, "a", "akkkkkk",(SUBR)phaser2set,NULL,(SUBR)phaser2}, +{ "phaser1", S(PHASER1), 0, 5, "a", "akkko", (SUBR)phaser1set, NULL,(SUBR)phaser1} }; int ugsc_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/urandom.c csound-6.02~dfsg/Opcodes/urandom.c --- csound-5.17.11~dfsg/Opcodes/urandom.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/urandom.c 2014-01-07 16:53:48.000000000 +0000 @@ -62,7 +62,7 @@ /* x.ieee.exponent = x.ieee.exponent& 0x377; */ /* printf("Debug: %s(%d): %g %d %03x %05x %08x\n", __FILE__, __LINE__, x.d, */ /* x.ieee.negative, x.ieee.exponent, x.ieee.mantissa0, x.ieee.mantissa1); */ - *p->ar = p->mul *((MYFLT)x/(MYFLT)0x7fffffffffffffff) + p->add; + *p->ar = p->mul *((MYFLT)x/(MYFLT)INT64_MAX) + p->add; return OK; } @@ -78,10 +78,18 @@ /* union ieee754_double x; */ int64_t x; MYFLT *ar = p->ar; - int n, nsmps = csound->ksmps; - for (n=0; nh.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t n, nsmps = CS_KSMPS; + + if (UNLIKELY(offset)) memset(ar, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&ar[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nmul *((MYFLT)x/(MYFLT)0x7fffffffffffffff) + p->add; + ar[n] = p->mul *((MYFLT)x/(MYFLT)INT64_MAX) + p->add; } return OK; } @@ -90,12 +98,12 @@ #define S(x) sizeof(x) static OENTRY urandom_localops[] = { - { "urandom", 0xFFFF, 0, NULL, NULL, NULL}, - { "urandom.i", S(URANDOM), 1, "k", "jp", (SUBR) urand_irate }, - { "urandom.k", S(URANDOM), 3, "k", "jp", (SUBR) urand_init, (SUBR) urand_run}, - { "urandom.a", S(URANDOM), 5, "a", "jp", + { "urandom", 0xFFFF, 0, 0, NULL, NULL, NULL}, + { "urandom.i", S(URANDOM), 0, 1, "i", "jp", (SUBR) urand_irate }, + { "urandom.k", S(URANDOM), 0, 3, "k", "jp", (SUBR) urand_init, (SUBR) urand_run}, + { "urandom.a", S(URANDOM), 0, 5, "a", "jp", (SUBR) urand_init, NULL, (SUBR) urand_arun} }; -LINKAGE1(urandom_localops) +LINKAGE_BUILTIN(urandom_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/vaops.c csound-6.02~dfsg/Opcodes/vaops.c --- csound-5.17.11~dfsg/Opcodes/vaops.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vaops.c 2014-01-07 16:53:48.000000000 +0000 @@ -36,27 +36,75 @@ MYFLT *kval, *kindx, *avar; } VA_SET; + +typedef struct { + OPDS h; + MYFLT *kout, *avar, *kindx; +} VASIG_GET; + +typedef struct { + OPDS h; + MYFLT *avar, *kval, *kindx; +} VASIG_SET; + static int vaget(CSOUND *csound, VA_GET *p) { int32 ndx = (int32) MYFLOOR((double)*p->kindx); - *p->kout = *(p->avar + ndx); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if (UNLIKELY(ndx<(int32)offset || ndx>=(int32)(CS_KSMPS-early))) + return csound->PerfError(csound, p->h.insdshead, + Str("Out of range in vaget (%d)"), ndx); + *p->kout = p->avar[ndx]; return OK; } static int vaset(CSOUND *csound, VA_SET *p) { int32 ndx = (int32) MYFLOOR((double)*p->kindx); - *(p->avar + ndx) = *p->kval; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if (UNLIKELY(ndx<(int32)offset || ndx>=(int32)(CS_KSMPS-early))) + return csound->PerfError(csound, p->h.insdshead, + Str("Out of range in vaset (%d)"), ndx); + p->avar[ndx] = *p->kval; + return OK; +} + + +static int vasigget(CSOUND *csound, VASIG_GET *p) +{ + int32 ndx = (int32) MYFLOOR((double)*p->kindx); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if (UNLIKELY(ndx<(int32)offset || ndx>=(int32)(CS_KSMPS-early))) + return csound->PerfError(csound, p->h.insdshead, + Str("Out of range in vaget (%d)"), ndx); + *p->kout = p->avar[ndx]; + return OK; +} + +static int vasigset(CSOUND *csound, VASIG_SET *p) +{ + int32 ndx = (int32) MYFLOOR((double)*p->kindx); + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + if (UNLIKELY(ndx<(int32)offset || ndx>=(int32)(CS_KSMPS-early))) + return csound->PerfError(csound, p->h.insdshead, + Str("Out of range in vaset (%d)"), ndx); + p->avar[ndx] = *p->kval; return OK; } #define S(x) sizeof(x) static OENTRY vaops_localops[] = { - { "vaget", S(VA_GET), 2, "k", "ka", NULL, (SUBR)vaget }, - { "vaset", S(VA_SET), 2, "", "kka", NULL, (SUBR)vaset } + { "vaget", S(VA_GET), 0, 2, "k", "ka", NULL, (SUBR)vaget }, + { "vaset", S(VA_SET), 0, 2, "", "kka", NULL, (SUBR)vaset }, + { "##array_get", S(VASIG_GET), 0, 2, "k", "ak", NULL, (SUBR)vasigget }, + { "##array_set", S(VASIG_SET), 0, 2, "", "akk", NULL, (SUBR)vasigset } }; -LINKAGE1(vaops_localops) +LINKAGE_BUILTIN(vaops_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/vbap.c csound-6.02~dfsg/Opcodes/vbap.c --- csound-5.17.11~dfsg/Opcodes/vbap.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap.c 2014-01-07 16:53:48.000000000 +0000 @@ -24,7 +24,8 @@ /* vbap.c assisting functions for VBAP -functions for loudspeaker table initialization */ +functions for loudspeaker table initialization +Re-written to take flexible number of outputs by JPff 2012 */ #include "csoundCore.h" @@ -44,20 +45,24 @@ ls *lss); static void calculate_3x3_matrixes(CSOUND *csound, ls_triplet_chain *ls_triplets, - ls lss[CHANNELS], int ls_amount); + ls lss[CHANNELS], int ls_amount, int ind); static void choose_ls_tuplets(CSOUND *csound, ls lss[CHANNELS], ls_triplet_chain **ls_triplets, - int ls_amount); + int ls_amount, int ind); static void sort_2D_lss(ls lss[CHANNELS], int sorted_lss[CHANNELS], int ls_amount); -static MYFLT *create_ls_table(CSOUND *csound, size_t cnt) +static MYFLT *create_ls_table(CSOUND *csound, size_t cnt, int ind) { - csound->DestroyGlobalVariable(csound, "vbap_ls_table"); - if (UNLIKELY(csound->CreateGlobalVariable(csound, "vbap_ls_table", - cnt * sizeof(MYFLT)) != 0)) - csound->Die(csound, Str("vbap: error allocating loudspeaker table")); - return get_ls_table(csound); + char name[24]; + sprintf(name, "vbap_ls_table_%d", ind); + csound->DestroyGlobalVariable(csound, name); + if (UNLIKELY(csound->CreateGlobalVariable(csound, name, + cnt * sizeof(MYFLT)) != 0)) { + csound->ErrorMsg(csound, Str("vbap: error allocating loudspeaker table")); + return NULL; + } + return (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, name)); } void calc_vbap_gns(int ls_set_am, int dim, LS_SET *sets, @@ -123,9 +128,6 @@ sets[j].set_gains[2] = FL(1.0); } -/* for (i=0;iDie(csound, Str("Number of loudspeakers is zero\nExiting")); + csound->ErrorMsg(csound, Str("Number of loudspeakers is zero\nExiting")); + return; } connections = calloc(CHANNELS * CHANNELS, sizeof(int)); @@ -555,33 +558,33 @@ } } -int vbap_ls_init (CSOUND *csound, VBAP_LS_INIT *p) +static inline int vbap_ls_init_sr (CSOUND *csound, int dim, int count, + MYFLT **f, int layout) /* Inits the loudspeaker data. Calls choose_ls_tuplets or _triplets according to current dimension. The inversion matrices are stored in transposed form to ease calculation at run time.*/ { - int dim, count; struct ls_triplet_chain *ls_triplets = NULL; ls lss[CHANNELS]; ANG_VEC a_vector; CART_VEC c_vector; int i=0,j; - int ls_amount; - dim = (int) *p->dim; + //dim = (int) *p->dim; csound->Warning(csound, "dim : %d\n",dim); if (UNLIKELY(!((dim==2) || (dim == 3)))) { - csound->Die(csound, Str("Error in loudspeaker dimension.")); + csound->ErrorMsg(csound, Str("Error in loudspeaker dimension.")); + return NOTOK; } - count = (int) *p->ls_amount; + //count = (int) *p->ls_amount; for (j=1;j<=count;j++) { if (dim == 3) { - a_vector.azi= (MYFLT) *p->f[2*j-2]; - a_vector.ele= (MYFLT) *p->f[2*j-1]; + a_vector.azi= (MYFLT) *f[2*j-2]; + a_vector.ele= (MYFLT) *f[2*j-1]; } else if (dim == 2) { - a_vector.azi= (MYFLT) *p->f[j-1]; + a_vector.azi= (MYFLT) *f[j-1]; a_vector.ele=FL(0.0); } angle_to_cart_II(&a_vector,&c_vector); @@ -593,24 +596,32 @@ lss[i].angles.length = FL(1.0); i++; } - ls_amount = (int)*p->ls_amount; - if (UNLIKELY(ls_amount < dim)) { - csound->Die(csound, Str("Too few loudspeakers")); + //ls_amount = (int)*p->ls_amount; + if (UNLIKELY(count < dim)) { + csound->ErrorMsg(csound, Str("Too few loudspeakers")); + return NOTOK; } if (dim == 3) { - choose_ls_triplets(csound, lss, &ls_triplets,ls_amount); - calculate_3x3_matrixes(csound, ls_triplets,lss,ls_amount); + choose_ls_triplets(csound, lss, &ls_triplets,count); + calculate_3x3_matrixes(csound, ls_triplets,lss,count, layout); } else if (dim ==2) { - choose_ls_tuplets(csound, lss, &ls_triplets,ls_amount); + choose_ls_tuplets(csound, lss, &ls_triplets,count, layout); } return OK; } +int vbap_ls_init (CSOUND *csound, VBAP_LS_INIT *p) +{ + int dim = (int) *p->dim; + MYFLT layout = (*p->dim-dim)*100; + return vbap_ls_init_sr(csound, dim, (int) *p->ls_amount, p->f, round(layout)); +} + static void calculate_3x3_matrixes(CSOUND *csound, struct ls_triplet_chain *ls_triplets, - ls lss[CHANNELS], int ls_amount) + ls lss[CHANNELS], int ls_amount, int ind) /* Calculates the inverse matrices for 3D */ { MYFLT invdet; @@ -621,7 +632,8 @@ int triplet_amount = 0, i,j,k; if (UNLIKELY(tr_ptr == NULL)) { - csound->Die(csound, Str("Not valid 3-D configuration")); + csound->ErrorMsg(csound, Str("Not valid 3-D configuration")); + return; } /* counting triplet amount */ @@ -631,7 +643,7 @@ } /* calculations and data storage to a global array */ - ls_table = create_ls_table(csound, triplet_amount * 12 + 3); + ls_table = create_ls_table(csound, triplet_amount * 12 + 3, ind); ls_table[0] = FL(3.0); /* dimension */ ls_table[1] = (MYFLT) ls_amount; ls_table[2] = (MYFLT) triplet_amount; @@ -675,19 +687,19 @@ } csound->Warning(csound, "\n"); - /* printf("\nMatrix "); */ - for (j = 0; j < 9; j++) { - /* printf("%f ", ls_table[k]); */ - k++; - } - /* printf("\n\n"); */ + /* printf("\nMatrix "); */ + /* for (j = 0; j < 9; j++) { */ + /* printf("%f ", ls_table[k]); */ + /* k++; */ + /* } */ + /* printf("\n\n"); */ } } static void choose_ls_tuplets(CSOUND *csound, ls lss[CHANNELS], ls_triplet_chain **ls_triplets, - int ls_amount) + int ls_amount, int ind) /* selects the loudspeaker pairs, calculates the inversion matrices and stores the data to a global array */ { @@ -710,26 +722,36 @@ /*csound->Message(csound, "%d %d %f %f\n",sorted_lss[i],sorted_lss[i+1], lss[sorted_lss[i]].angles.azi, lss[sorted_lss[i+1]].angles.azi);*/ - if ((lss[sorted_lss[i+1]].angles.azi - - lss[sorted_lss[i]].angles.azi) <= (PI - 0.175)) { - if (calc_2D_inv_tmatrix( lss[sorted_lss[i]].angles.azi, - lss[sorted_lss[i+1]].angles.azi, - inv_mat[i]) != 0) { + if (LIKELY((lss[sorted_lss[i+1]].angles.azi - + lss[sorted_lss[i]].angles.azi) <= (PI - 0.0175))) { + if (LIKELY(calc_2D_inv_tmatrix( lss[sorted_lss[i]].angles.azi, + lss[sorted_lss[i+1]].angles.azi, + inv_mat[i]) != 0)) { exist[i]=1; amount++; } } + else csound->Warning(csound, Str("Pair of speakers at %f and %f ignored\n"), + lss[sorted_lss[i]].angles.azi*FL(180.0)/PI_F, + lss[sorted_lss[i+1]].angles.azi*FL(180.0)/PI_F); } - if (((6.283 - lss[sorted_lss[ls_amount-1]].angles.azi) - +lss[sorted_lss[0]].angles.azi) <= (PI - 0.175)) { - if (calc_2D_inv_tmatrix(lss[sorted_lss[ls_amount-1]].angles.azi, - lss[sorted_lss[0]].angles.azi, - inv_mat[ls_amount-1]) != 0) { + if (LIKELY(((TWOPI_F - lss[sorted_lss[ls_amount-1]].angles.azi) + +lss[sorted_lss[0]].angles.azi) < (PI - 0.0175))) { + //printf("less than PI type 2- 0.175\n"); + if (LIKELY(calc_2D_inv_tmatrix(lss[sorted_lss[ls_amount-1]].angles.azi, + lss[sorted_lss[0]].angles.azi, + inv_mat[ls_amount-1]) != 0)) { exist[ls_amount-1]=1; amount++; } } + else csound->Warning(csound, Str("Pair of speakers at %f and %f ignored\n"), + lss[sorted_lss[ls_amount-1]].angles.azi*FL(180.0)/PI_F, + lss[sorted_lss[0]].angles.azi*FL(180.0)/PI_F); + + if (UNLIKELY(amount==0)) + csound->InitError(csound, Str("insufficient valid speakers")); #if 0 if ( amount*6 + 6 <= 16) ftable_size = 16; @@ -744,7 +766,7 @@ csound->Message(csound, "%.1f ", lss[i].angles.azi / atorad); csound->Message(csound, "\n"); #endif - ls_table = create_ls_table(csound, amount * 6 + 3 + 100); + ls_table = create_ls_table(csound, amount * 6 + 3 + 100, ind); ls_table[0] = FL(2.0); /* dimension */ ls_table[1] = (MYFLT) ls_amount; ls_table[2] = (MYFLT) amount; @@ -774,12 +796,12 @@ } csound->Warning(csound, "\n"); - /* csound->Message(csound, "\nMatrix "); */ - /* for (j=0; j < 4; j++) { */ - /* csound->Message(csound, "%f ", ls_table[k]); */ - /* k++; */ - /* } */ - /* csound->Message(csound, "\n\n"); */ + csound->Message(csound, "\nMatrix "); + for (j=0; j < 4; j++) { + csound->Message(csound, "%f ", ls_table[k]); + k++; + } + csound->Message(csound, "\n\n"); } } @@ -901,37 +923,53 @@ /* static */ static OENTRY vbap_localops[] = { - { "vbap4", S(VBAP_FOUR), TR|5, "aaaa", "akOO", - (SUBR) vbap_FOUR_init, (SUBR) NULL, (SUBR) vbap_FOUR }, - { "vbap8", S(VBAP_EIGHT), TR|5, "aaaaaaaa", "akOO", - (SUBR) vbap_EIGHT_init, (SUBR) NULL, (SUBR) vbap_EIGHT }, - { "vbap16", S(VBAP_SIXTEEN), TR|5, "aaaaaaaaaaaaaaaa", "akOO", - (SUBR) vbap_SIXTEEN_init, (SUBR) NULL, (SUBR) vbap_SIXTEEN }, - { "vbapz", S(VBAP_ZAK), ZW|TR|5, "", "iiakOO", + { "vbap.a", S(VBAP), + TR, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "akOOo", + (SUBR) vbap_init, (SUBR) NULL, (SUBR) vbap }, + { "vbap.A", S(VBAPA), TR, 5, "a[]", "akOOo", + (SUBR) vbap_init_a, (SUBR) NULL, (SUBR) vbap_a }, + { "vbap4", S(VBAP), + TR|_QQ, 5, "aaaa", "akOOo", (SUBR) vbap_init, (SUBR) NULL, (SUBR) vbap }, + { "vbap8", S(VBAP), + TR|_QQ, 5, "aaaaaaaa", "akOOo", + (SUBR) vbap_init, (SUBR) NULL, (SUBR) vbap }, + { "vbap16", S(VBAP), + TR|_QQ, 5, "aaaaaaaaaaaaaaaa", "akOOo", + (SUBR) vbap_init, (SUBR) NULL, (SUBR) vbap }, + { "vbapg.a", S(VBAP1), TR, 3, + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "kOOo", + (SUBR) vbap1_init, (SUBR) vbap1 }, + { "vbapg.A", S(VBAPA1), TR, 3, + "k[]", "kOOo", + (SUBR) vbap1_init_a, (SUBR) vbap1a }, + { "vbapz", S(VBAP_ZAK), ZW|TR, 5, "", "iiakOOo", (SUBR) vbap_zak_init, (SUBR) NULL, (SUBR) vbap_zak }, - { "vbaplsinit", S(VBAP_LS_INIT), TR|1, "", "iioooooooooooooooooooooooooooooooo", + { "vbaplsinit",S(VBAP_LS_INIT),TR,1, "", "iioooooooooooooooooooooooooooooooo", (SUBR) vbap_ls_init, (SUBR) NULL, (SUBR) NULL }, - { "vbap4move", S(VBAP_FOUR_MOVING), TR|5, "aaaa", "aiiim", - (SUBR) vbap_FOUR_moving_init, (SUBR) NULL, (SUBR) vbap_FOUR_moving }, - { "vbap8move", S(VBAP_EIGHT_MOVING), TR|5, "aaaaaaaa", "aiiim", - (SUBR) vbap_EIGHT_moving_init, (SUBR) NULL, (SUBR) vbap_EIGHT_moving }, - { "vbap16move", S(VBAP_SIXTEEN_MOVING), TR|5, "aaaaaaaaaaaaaaaa", "aiiim", - (SUBR) vbap_SIXTEEN_moving_init, (SUBR) NULL, (SUBR) vbap_SIXTEEN_moving }, - { "vbapzmove", S(VBAP_ZAK_MOVING), ZW|TR|5, "", "iiaiiim", - (SUBR) vbap_zak_moving_init, (SUBR) NULL, (SUBR) vbap_zak_moving } -}; + { "vbapmove.a", S(VBAP_MOVING), + TR, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "aiiim", + (SUBR) vbap_moving_init, (SUBR) NULL, (SUBR) vbap_moving }, + { "vbapgmove.a", S(VBAP1_MOVING), TR, 5, + "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", "iiim", + (SUBR) vbap1_moving_init, (SUBR) NULL, (SUBR) vbap1_moving }, + { "vbapmove.A", S(VBAPA_MOVING), + TR, 5, "a[]", "aiiim", + (SUBR) vbap_moving_init_a, (SUBR) NULL, (SUBR) vbap_moving_a }, + { "vbapgmove.A", S(VBAPA1_MOVING), TR, 5, + "k[]", "iiim", + (SUBR) vbap1_moving_init_a, (SUBR) NULL, (SUBR) vbap1_moving_a }, + { "vbapzmove", S(VBAP_ZAK_MOVING), ZW|TR, 5, "", "iiaiiim", + (SUBR) vbap_zak_moving_init, (SUBR) NULL, (SUBR) vbap_zak_moving }, + { "vbap4move", S(VBAP_MOVING), TR|_QQ, 5, "aaaa", + "aiiim", + (SUBR) vbap_moving_init, (SUBR) NULL, (SUBR) vbap_moving }, + { "vbap8move", S(VBAP_MOVING), + TR|_QQ, 5, "aaaaaaaa", + "aiiim", + (SUBR) vbap_moving_init, (SUBR) NULL, (SUBR) vbap_moving } -LINKAGE1(vbap_localops) - -/* PUBLIC long csound_opcode_init(CSOUND *csound, OENTRY **ep) -{ - create_ls_table(csound, 3); - *ep = localops; - return (long) sizeof(localops); -} +}; -PUBLIC int csoundModuleInfo(void) -{ - return ((CS_APIVERSION << 16) + (CS_APISUBVER << 8) + (int) sizeof(MYFLT)); -} -*/ +LINKAGE_BUILTIN(vbap_localops) diff -Nru csound-5.17.11~dfsg/Opcodes/vbap.h csound-6.02~dfsg/Opcodes/vbap.h --- csound-5.17.11~dfsg/Opcodes/vbap.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap.h 2014-01-07 16:53:48.000000000 +0000 @@ -24,10 +24,6 @@ #define LOWEST_ACCEPTABLE_WT FL(0.0) #define CHANNELS 64 #define MIN_VOL_P_SIDE_LGTH FL(0.01) -#define FOUR 4 -#define EIGHT 8 -#define SIXTEEN 16 -#define THIRTYTWO 32 typedef struct { MYFLT x; @@ -56,16 +52,13 @@ int neg_g_am; } LS_SET; -/* VBAP structure for FOUR loudspeaker panning */ +/* VBAP structure of n loudspeaker panning */ typedef struct { - OPDS h; /* required header */ - MYFLT *out_array[FOUR]; - MYFLT *audio, *azi, *ele, *spread; - - MYFLT beg_gains[FOUR]; - MYFLT curr_gains[FOUR]; - MYFLT end_gains[FOUR]; - MYFLT updated_gains[FOUR]; + int number; + MYFLT beg_gains[CHANNELS]; + MYFLT curr_gains[CHANNELS]; + MYFLT end_gains[CHANNELS]; + MYFLT updated_gains[CHANNELS]; int dim; AUXCH aux; LS_SET *ls_sets; @@ -74,41 +67,27 @@ CART_VEC cart_dir; CART_VEC spread_base; ANG_VEC ang_dir; -} VBAP_FOUR; +} VBAP_DATA; -/* VBAP structure of FOUR loudspeaker moving panning */ typedef struct { - OPDS h; /* required header */ - MYFLT *out_array[FOUR]; - MYFLT *audio, *dur, *spread, *field_am, - *fld[VARGMAX]; /* field_am positive: point to point - negative: angle velocities */ - MYFLT beg_gains[FOUR]; - MYFLT curr_gains[EIGHT]; - MYFLT end_gains[FOUR]; - MYFLT updated_gains[FOUR]; - int dim; - AUXCH aux; - LS_SET *ls_sets; - int ls_am; - int ls_set_am; - CART_VEC cart_dir; - CART_VEC spread_base; - ANG_VEC ang_dir, prev_ang_dir, next_ang_dir; - int point_change_interval, point_change_counter, curr_fld, next_fld; - MYFLT ele_vel; -} VBAP_FOUR_MOVING; + OPDS h; /* required header */ + MYFLT *out_array[CHANNELS]; + MYFLT *audio, *azi, *ele, *spread, *layout; + + VBAP_DATA q; +} VBAP; -/* VBAP structure of eight loudspeaker panning */ typedef struct { - OPDS h; /* required header */ - MYFLT *out_array[EIGHT]; - MYFLT *audio, *azi, *ele, *spread; + OPDS h; /* required header */ + ARRAYDAT *tabout; + MYFLT *audio, *azi, *ele, *spread, *layout; - MYFLT beg_gains[EIGHT]; - MYFLT curr_gains[EIGHT]; - MYFLT end_gains[EIGHT]; - MYFLT updated_gains[EIGHT]; + VBAP_DATA q; +} VBAPA; + +typedef struct { + int number; + MYFLT gains[CHANNELS]; int dim; AUXCH aux; LS_SET *ls_sets; @@ -117,67 +96,28 @@ CART_VEC cart_dir; CART_VEC spread_base; ANG_VEC ang_dir; -} VBAP_EIGHT; +} VBAP1_DATA; -/* VBAP structure of EIGHT loudspeaker moving panning */ typedef struct { OPDS h; /* required header */ - MYFLT *out_array[EIGHT]; - MYFLT *audio, *dur, *spread, *field_am, - *fld[VARGMAX]; /* field_am positive: point to point - negative: angle velocities */ - MYFLT beg_gains[EIGHT]; - MYFLT curr_gains[EIGHT]; - MYFLT updated_gains[EIGHT]; -/* int counter; */ - int upd_interval; - int dim; - AUXCH aux; - LS_SET *ls_sets; - int ls_am; - int ls_set_am; - CART_VEC cart_dir; - CART_VEC spread_base; - ANG_VEC ang_dir, prev_ang_dir, next_ang_dir; - int point_change_interval, point_change_counter, curr_fld, next_fld; - MYFLT ele_vel; - MYFLT end_gains[EIGHT]; -} VBAP_EIGHT_MOVING; + MYFLT *out_array[CHANNELS]; + MYFLT *azi, *ele, *spread, *layout; + + VBAP1_DATA q; +} VBAP1; -/* VBAP structure of SIXTEEN loudspeaker panning */ typedef struct { OPDS h; /* required header */ - MYFLT *out_array[SIXTEEN]; - MYFLT *audio, *azi, *ele, *spread; + ARRAYDAT *tabout; + MYFLT *azi, *ele, *spread, *layout; - MYFLT beg_gains[SIXTEEN]; - MYFLT curr_gains[SIXTEEN]; - MYFLT end_gains[SIXTEEN]; - MYFLT updated_gains[SIXTEEN]; -/* int counter; */ - int upd_interval; - int dim; - AUXCH aux; - LS_SET *ls_sets; - int ls_am; - int ls_set_am; - CART_VEC cart_dir; - CART_VEC spread_base; - ANG_VEC ang_dir; -} VBAP_SIXTEEN; + VBAP1_DATA q; +} VBAPA1; -/* VBAP structure of SIXTEEN loudspeaker moving panning */ +/* VBAP structure of loudspeaker moving panning */ typedef struct { - OPDS h; /* required header */ - MYFLT *out_array[SIXTEEN]; - MYFLT *audio, *dur, *spread, *field_am, - *fld[VARGMAX]; /* field_am positive: point to point - negative: angle velocities */ - MYFLT beg_gains[SIXTEEN]; - MYFLT curr_gains[SIXTEEN]; - MYFLT end_gains[SIXTEEN]; - MYFLT updated_gains[SIXTEEN]; -/* int counter; */ + MYFLT gains[CHANNELS]; + int number; int upd_interval; int dim; AUXCH aux; @@ -189,42 +129,33 @@ ANG_VEC ang_dir, prev_ang_dir, next_ang_dir; int point_change_interval, point_change_counter, curr_fld, next_fld; MYFLT ele_vel; -} VBAP_SIXTEEN_MOVING; + MYFLT end_gains[CHANNELS]; +} VBAP1_MOVE_DATA; -/* VBAP structure of THIRTYTWO loudspeaker panning */ typedef struct { OPDS h; /* required header */ - MYFLT *out_array[THIRTYTWO]; - MYFLT *audio, *azi, *ele, *spread; + MYFLT *out_array[CHANNELS]; + MYFLT *dur, *spread, *field_am, + *fld[VARGMAX]; /* field_am positive: point to point + negative: angle velocities */ + VBAP1_MOVE_DATA q; +} VBAP1_MOVING; - MYFLT beg_gains[THIRTYTWO]; - MYFLT curr_gains[THIRTYTWO]; - MYFLT end_gains[THIRTYTWO]; - MYFLT updated_gains[THIRTYTWO]; -/* int counter; */ - int upd_interval; - int dim; - AUXCH aux; - LS_SET *ls_sets; - int ls_am; - int ls_set_am; - CART_VEC cart_dir; - CART_VEC spread_base; - ANG_VEC ang_dir; -} VBAP_THIRTYTWO; +typedef struct { + OPDS h; /* required header */ + ARRAYDAT *tabout; + MYFLT *dur, *spread, *field_am, + *fld[VARGMAX]; /* field_am positive: point to point + negative: angle velocities */ + VBAP1_MOVE_DATA q; +} VBAPA1_MOVING; -/* VBAP structure of THIRTYTWO loudspeaker moving panning */ +/* VBAP structure of loudspeaker moving panning */ typedef struct { - OPDS h; /* required header */ - MYFLT *out_array[THIRTYTWO]; - MYFLT *audio, *dur, *spread, *field_am, - *fld[VARGMAX]; /* field_am positive: point to point - negative: angle velocities */ - MYFLT beg_gains[THIRTYTWO]; - MYFLT curr_gains[THIRTYTWO]; - MYFLT end_gains[THIRTYTWO]; - MYFLT updated_gains[THIRTYTWO]; -/* int counter; */ + MYFLT beg_gains[CHANNELS]; + MYFLT curr_gains[CHANNELS]; + MYFLT updated_gains[CHANNELS]; + int number; int upd_interval; int dim; AUXCH aux; @@ -236,12 +167,32 @@ ANG_VEC ang_dir, prev_ang_dir, next_ang_dir; int point_change_interval, point_change_counter, curr_fld, next_fld; MYFLT ele_vel; -} VBAP_THIRTYTWO_MOVING; + MYFLT end_gains[CHANNELS]; +} VBAP_MOVE_DATA; + +typedef struct { + OPDS h; /* required header */ + MYFLT *out_array[CHANNELS]; + MYFLT *audio, *dur, *spread, *field_am, + *fld[VARGMAX]; /* field_am positive: point to point + negative: angle velocities */ + VBAP_MOVE_DATA q; +} VBAP_MOVING; + + +typedef struct { + OPDS h; /* required header */ + ARRAYDAT *tabout; + MYFLT *audio, *dur, *spread, *field_am, + *fld[VARGMAX]; /* field_am positive: point to point + negative: angle velocities */ + VBAP_MOVE_DATA q; +} VBAPA_MOVING; typedef struct { OPDS h; /* required header */ MYFLT *dim, *ls_amount; - MYFLT *f[64]; + MYFLT *f[2*CHANNELS]; } VBAP_LS_INIT; /* A struct for a loudspeaker instance */ @@ -281,9 +232,7 @@ extern void angle_to_cart(ANG_VEC avec, CART_VEC *cvec); extern void normalize_wts(OUT_WTS *wts); -extern int vbap_FOUR_control(CSOUND*, VBAP_FOUR *p); -extern int vbap_EIGHT_control(CSOUND*, VBAP_EIGHT *p); -extern int vbap_SIXTEEN_control(CSOUND*, VBAP_SIXTEEN *p); +extern int vbap_control(CSOUND*, VBAP_DATA *p, MYFLT*, MYFLT*, MYFLT*); void calc_vbap_gns(int ls_set_am, int dim, LS_SET *sets, MYFLT *gains, int ls_amount, @@ -291,13 +240,15 @@ void scale_angles(ANG_VEC *avec); MYFLT vol_p_side_lgth(int i, int j, int k, ls lss[CHANNELS]); -void new_spread_dir(CART_VEC *spreaddir, CART_VEC vscartdir, CART_VEC spread_base, MYFLT azi, MYFLT spread); -void new_spread_base(CART_VEC spreaddir, CART_VEC vscartdir, MYFLT spread, CART_VEC *spread_base); +void new_spread_dir(CART_VEC *spreaddir, CART_VEC vscartdir, + CART_VEC spread_base, MYFLT azi, MYFLT spread); +void new_spread_base(CART_VEC spreaddir, CART_VEC vscartdir, + MYFLT spread, CART_VEC *spread_base); /* VBAP structure for ZAK loudspeaker panning */ typedef struct { OPDS h; /* required header */ - MYFLT *numb, *ndx, *audio, *azi, *ele, *spread; + MYFLT *numb, *ndx, *audio, *azi, *ele, *spread, *layout; int n; MYFLT *out_array; AUXCH auxch; @@ -340,27 +291,24 @@ MYFLT ele_vel; } VBAP_ZAK_MOVING; -int vbap_FOUR_init(CSOUND *, VBAP_FOUR *); -int vbap_FOUR(CSOUND *, VBAP_FOUR *); -int vbap_EIGHT_init(CSOUND *, VBAP_EIGHT *); -int vbap_EIGHT(CSOUND *, VBAP_EIGHT *); -int vbap_SIXTEEN_init(CSOUND *, VBAP_SIXTEEN *); -int vbap_SIXTEEN(CSOUND *, VBAP_SIXTEEN *); +int vbap_init(CSOUND *, VBAP *); +int vbap_init_a(CSOUND *, VBAPA *); +int vbap(CSOUND *, VBAP *); +int vbap_a(CSOUND *, VBAPA *); int vbap_zak_init(CSOUND *, VBAP_ZAK *); int vbap_zak(CSOUND *, VBAP_ZAK *); int vbap_ls_init(CSOUND *, VBAP_LS_INIT *); -int vbap_FOUR_moving_init(CSOUND *, VBAP_FOUR_MOVING *); -int vbap_FOUR_moving(CSOUND *, VBAP_FOUR_MOVING *); -int vbap_EIGHT_moving_init(CSOUND *, VBAP_EIGHT_MOVING *); -int vbap_EIGHT_moving(CSOUND *, VBAP_EIGHT_MOVING *); -int vbap_SIXTEEN_moving_init(CSOUND *, VBAP_SIXTEEN_MOVING *); -int vbap_SIXTEEN_moving(CSOUND *, VBAP_SIXTEEN_MOVING *); +int vbap_moving_init(CSOUND *, VBAP_MOVING *); +int vbap_moving(CSOUND *, VBAP_MOVING *); +int vbap_moving_init_a(CSOUND *, VBAPA_MOVING *); +int vbap_moving_a(CSOUND *, VBAPA_MOVING *); int vbap_zak_moving_init(CSOUND *, VBAP_ZAK_MOVING *); int vbap_zak_moving(CSOUND *, VBAP_ZAK_MOVING *); - -static inline MYFLT *get_ls_table(CSOUND *csound) -{ - return (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, - "vbap_ls_table")); -} - +int vbap1_init(CSOUND *, VBAP1 *); +int vbap1(CSOUND *, VBAP1 *); +int vbap1_init_a(CSOUND *, VBAPA1 *); +int vbap1a(CSOUND *, VBAPA1 *); +int vbap1_moving_init(CSOUND *, VBAP1_MOVING *); +int vbap1_moving(CSOUND *, VBAP1_MOVING *); +int vbap1_moving_init_a(CSOUND *, VBAPA1_MOVING *); +int vbap1_moving_a(CSOUND *, VBAPA1_MOVING *); diff -Nru csound-5.17.11~dfsg/Opcodes/vbap1.c csound-6.02~dfsg/Opcodes/vbap1.c --- csound-5.17.11~dfsg/Opcodes/vbap1.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap1.c 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,665 @@ +/* + vbap1.c: + + Copyright (C) 2000 Ville Pulkki + 2012 John ffitch + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +/* vbap1.c + +functions specific gains for loudspeaker VBAP + +Ville Pulkki heavily modified by John ffitch 2012 +*/ + + +#include "csoundCore.h" +#include "vbap.h" +#include +#include +#include + +static int vbap1_moving_control(CSOUND *, VBAP1_MOVE_DATA *, INSDS *, MYFLT, + MYFLT, MYFLT, MYFLT**); +static int vbap1_control(CSOUND *, VBAP1_DATA *, MYFLT*, MYFLT*, MYFLT*); + +int vbap1(CSOUND *csound, VBAP1 *p) /* during note performance: */ +{ + int j; + int cnt = p->q.number; + vbap1_control(csound,&p->q, p->azi, p->ele, p->spread); + + /* write gains */ + for (j=0; jout_array[j] = p->q.gains[j]; + } + return OK; +} + +static int vbap1_control(CSOUND *csound, VBAP1_DATA *p, + MYFLT* azi, MYFLT* ele, MYFLT* spread) +{ + CART_VEC spreaddir[16]; + CART_VEC spreadbase[16]; + ANG_VEC atmp; + int32 i,j, spreaddirnum; + int cnt = p->number; + MYFLT tmp_gains[CHANNELS],sum=FL(0.0); + if (UNLIKELY(p->dim == 2 && fabs(*ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *ele = FL(0.0); + } + + if (*spread FL(100.0)) + *spread = FL(100.0); + /* Current panning angles */ + p->ang_dir.azi = *azi; + p->ang_dir.ele = *ele; + p->ang_dir.length = FL(1.0); + angle_to_cart(p->ang_dir, &(p->cart_dir)); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + p->gains, cnt, p->cart_dir); + + /* Calculated gain factors of a spreaded virtual source*/ + if (*spread > FL(0.0)) { + if (p->dim == 3) { + spreaddirnum = 16; + /* four orthogonal dirs*/ + new_spread_dir(&spreaddir[0], p->cart_dir, + p->spread_base, *azi, *spread); + new_spread_base(spreaddir[0], p->cart_dir, + *spread, &p->spread_base); + cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); + cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); + cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); + /* four between them*/ + vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); + vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); + vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); + vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); + + /* four at half spreadangle*/ + vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); + vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); + vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); + vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); + + /* four at quarter spreadangle*/ + vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); + vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); + vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); + vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); + + for (i=1;icart_dir, + spreadbase[i],*azi,*spread); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jgains[j] += tmp_gains[j]; + } + } + } + else if (p->dim == 2) { + spreaddirnum = 6; + atmp.ele = FL(0.0); + atmp.azi = *azi - *spread; + angle_to_cart(atmp, &spreaddir[0]); + atmp.azi = *azi - *spread/2; + angle_to_cart(atmp, &spreaddir[1]); + atmp.azi = *azi - *spread/4; + angle_to_cart(atmp, &spreaddir[2]); + atmp.azi = *azi + *spread/4; + angle_to_cart(atmp, &spreaddir[3]); + atmp.azi = *azi + *spread/2; + angle_to_cart(atmp, &spreaddir[4]); + atmp.azi = *azi + *spread; + angle_to_cart(atmp, &spreaddir[5]); + + for (i=0;ils_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jgains[j] += tmp_gains[j]; + } + } + } + } + if (*spread > FL(70.0)) + for (i=0;igains[i] +=(*spread - FL(70.0))/FL(30.0) * + (*spread - FL(70.0))/FL(30.0)*FL(20.0); + } + + /*normalization*/ + for (i=0;igains[i]*p->gains[i]); + } + + sum=SQRT(sum); + for (i=0;igains[i] /= sum; + } + return OK; +} + +int vbap1_init(CSOUND *csound, VBAP1 *p) +{ /* Initializations before run time*/ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + char name[24]; + sprintf(name, "vbap_ls_table_%d", (int)*p->layout); + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, name)); + if (ls_table==NULL) + return csound->InitError(csound, + Str("could not find layout table no.%d"), + (int)*p->layout ); + p->q.number = p->OUTOCOUNT; + p->q.dim = (int)ls_table[0]; /* reading in loudspeaker info */ + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof (LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0; i < p->q.ls_set_am; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + if (UNLIKELY(p->q.dim == 2 && fabs(*p->ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *p->ele = FL(0.0); + } + p->q.ang_dir.azi = (MYFLT)*p->azi; + p->q.ang_dir.ele = (MYFLT)*p->ele; + p->q.ang_dir.length = FL(1.0); + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap1_control(csound,&p->q, p->azi, p->ele, p->spread); + return OK; +} + +int vbap1a(CSOUND *csound, VBAPA1 *p) /* during note performance: */ +{ + int j; + int cnt = p->q.number; + vbap1_control(csound,&p->q, p->azi, p->ele, p->spread); + + /* write gains */ + for (j=0; jtabout->data[j] = p->q.gains[j]; + } + return OK; +} + +int vbap1_init_a(CSOUND *csound, VBAPA1 *p) +{ /* Initializations before run time*/ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + char name[24]; + sprintf(name, "vbap_ls_table_%d", (int)*p->layout); + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, name)); + if (ls_table==NULL) + return csound->InitError(csound, + Str("could not find layout table no.%d"), + (int)*p->layout ); + p->q.number = p->tabout->sizes[0]; + p->q.dim = (int)ls_table[0]; /* reading in loudspeaker info */ + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof (LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0; i < p->q.ls_set_am; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + if (UNLIKELY(p->q.dim == 2 && fabs(*p->ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *p->ele = FL(0.0); + } + p->q.ang_dir.azi = (MYFLT)*p->azi; + p->q.ang_dir.ele = (MYFLT)*p->ele; + p->q.ang_dir.length = FL(1.0); + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap1_control(csound,&p->q, p->azi, p->ele, p->spread); + return OK; +} + +int vbap1_moving(CSOUND *csound, VBAP1_MOVING *p) +{ /* during note performance: */ + int j; + int cnt = p->q.number; + + vbap1_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + *p->spread, *p->field_am, p->fld); + + /* write audio to resulting audio streams weighted + with gain factors*/ + for (j=0; jout_array[j] = p->q.gains[j]; + } + return OK; +} + +int vbap1_moving_a(CSOUND *csound, VBAPA1_MOVING *p) +{ /* during note performance: */ + int j; + int cnt = p->q.number; + + vbap1_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + *p->spread, *p->field_am, p->fld); + + /* write audio to resulting audio streams weighted + with gain factors*/ + for (j=0; jtabout->data[j] = p->q.gains[j]; + } + return OK; +} + +static int vbap1_moving_control(CSOUND *csound, VBAP1_MOVE_DATA *p, + INSDS *insdshead, MYFLT ONEDKR, + MYFLT spread, MYFLT field_am, MYFLT **fld) +{ + CART_VEC spreaddir[16]; + CART_VEC spreadbase[16]; + ANG_VEC atmp; + int32 i,j, spreaddirnum; + CART_VEC tmp1, tmp2, tmp3; + MYFLT coeff, angle; + MYFLT tmp_gains[CHANNELS],sum=FL(0.0); + int cnt = p->number; + + printf("cnt=%d dim=%d\n", cnt, p->dim); + + if (UNLIKELY(p->dim == 2 && fabs(p->ang_dir.ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + p->ang_dir.ele = FL(0.0); + } + if (spread FL(100.0)) + spread = FL(100.0); + if (p->point_change_counter++ >= p->point_change_interval) { + p->point_change_counter = 0; + p->curr_fld = p->next_fld; + if (++p->next_fld >= (int) fabs(field_am)) { + if (field_am >= FL(0.0)) /* point-to-point */ + p->next_fld = 0; + else + p->next_fld = 1; + } + if (p->dim == 3) { /*jumping over second field */ + p->curr_fld = p->next_fld; + if (++p->next_fld >= ((int) fabs(field_am))) { + if (field_am >= FL(0.0)) /* point-to-point */ + p->next_fld = 0; + else + p->next_fld = 1; + } + } + if (UNLIKELY((fld[abs(p->next_fld)]==NULL))) + return csound->PerfError(csound, insdshead, + Str("Missing fields in vbapmove\n")); + if (field_am >= FL(0.0) && p->dim == 2) /* point-to-point */ + if (UNLIKELY(fabs(fabs(*fld[p->next_fld] - + *fld[p->curr_fld]) - 180.0) < 1.0)) + csound->Warning(csound, + Str("Warning: Ambiguous transition 180 degrees.\n")); + } + if (field_am >= FL(0.0)) { /* point-to-point */ + if (p->dim == 3) { /* 3-D*/ + p->prev_ang_dir.azi = *fld[p->curr_fld-1]; + p->next_ang_dir.azi = *fld[p->next_fld]; + p->prev_ang_dir.ele = *fld[p->curr_fld]; + p->next_ang_dir.ele = *fld[p->next_fld+1]; + coeff = ((MYFLT) p->point_change_counter) / + ((MYFLT) p->point_change_interval); + angle_to_cart( p->prev_ang_dir,&tmp1); + angle_to_cart( p->next_ang_dir,&tmp2); + tmp3.x = (FL(1.0)-coeff) * tmp1.x + coeff * tmp2.x; + tmp3.y = (FL(1.0)-coeff) * tmp1.y + coeff * tmp2.y; + tmp3.z = (FL(1.0)-coeff) * tmp1.z + coeff * tmp2.z; + coeff = (MYFLT)sqrt((double)(tmp3.x * tmp3.x + + tmp3.y * tmp3.y + + tmp3.z * tmp3.z)); + tmp3.x /= coeff; tmp3.y /= coeff; tmp3.z /= coeff; + cart_to_angle(tmp3,&(p->ang_dir)); + } + else if (p->dim == 2) { /* 2-D */ + p->prev_ang_dir.azi = *fld[p->curr_fld]; + p->next_ang_dir.azi = *fld[p->next_fld ]; + p->prev_ang_dir.ele = p->next_ang_dir.ele = FL(0.0); + scale_angles(&(p->prev_ang_dir)); + scale_angles(&(p->next_ang_dir)); + angle = (p->prev_ang_dir.azi - p->next_ang_dir.azi); + while (angle > FL(180.0)) + angle -= FL(360.0); + while (angle < -FL(180.0)) + angle += FL(360.0); + coeff = ((MYFLT) p->point_change_counter) / + ((MYFLT) p->point_change_interval); + angle *= (coeff); + p->ang_dir.azi = p->prev_ang_dir.azi - angle; + p->ang_dir.ele = FL(0.0); + } + else { + return csound->PerfError(csound, insdshead, + Str("Missing fields in vbapmove\n")); + } + } + else { /* angular velocities */ + if (p->dim == 2) { + p->ang_dir.azi = p->ang_dir.azi + + (*fld[p->next_fld] * ONEDKR); + scale_angles(&(p->ang_dir)); + } + else { /* 3D angular*/ + p->ang_dir.azi = p->ang_dir.azi + + (*fld[p->next_fld] * ONEDKR); + p->ang_dir.ele = p->ang_dir.ele + + p->ele_vel * (*fld[p->next_fld+1] * ONEDKR); + if (p->ang_dir.ele > FL(90.0)) { + p->ang_dir.ele = FL(90.0); + p->ele_vel = -p->ele_vel; + } + if (p->ang_dir.ele < FL(0.0)) { + p->ang_dir.ele = FL(0.0); + p->ele_vel = -p->ele_vel; + } + scale_angles(&(p->ang_dir)); + } + } + angle_to_cart(p->ang_dir, &(p->cart_dir)); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + p->gains, cnt, p->cart_dir); + if (spread > FL(0.0)) { + if (p->dim == 3) { + spreaddirnum=16; + /* four orthogonal dirs*/ + new_spread_dir(&spreaddir[0], p->cart_dir, + p->spread_base, p->ang_dir.azi, spread); + + new_spread_base(spreaddir[0], p->cart_dir, spread, &p->spread_base); + cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); + cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); + cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); + /* four between them*/ + vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); + vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); + vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); + vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); + + /* four at half spreadangle*/ + vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); + vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); + vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); + vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); + + /* four at quarter spreadangle*/ + vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); + vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); + vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); + vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); + + for (i=1;icart_dir, + spreadbase[i],p->ang_dir.azi,spread); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jgains[j] += tmp_gains[j]; + } + } + } + else if (p->dim == 2) { + spreaddirnum=6; + atmp.ele = FL(0.0); + atmp.azi = p->ang_dir.azi - spread; + angle_to_cart(atmp, &spreaddir[0]); + atmp.azi = p->ang_dir.azi - spread/2; + angle_to_cart(atmp, &spreaddir[1]); + atmp.azi = p->ang_dir.azi - spread/4; + angle_to_cart(atmp, &spreaddir[2]); + atmp.azi = p->ang_dir.azi + spread/4; + angle_to_cart(atmp, &spreaddir[3]); + atmp.azi = p->ang_dir.azi + spread/2; + angle_to_cart(atmp, &spreaddir[4]); + atmp.azi = p->ang_dir.azi + spread; + angle_to_cart(atmp, &spreaddir[5]); + + for (i=0;ils_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jgains[j] += tmp_gains[j]; + } + } + } + } + if (spread > FL(70.0)) + for (i=0;igains[i] +=(spread - FL(70.0))/FL(30.0) * + (spread - FL(70.0))/FL(30.0)*FL(10.0); + } + /*normalization*/ + for (i=0;igains[i]*p->gains[i]); + } + + sum=SQRT(sum); + for (i=0;igains[i] /= sum; + } + return OK; +} + +int vbap1_moving_init(CSOUND *csound, VBAP1_MOVING *p) +{ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + + p->q.number = p->OUTCOUNT; + ls_table = + (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, "vbap_ls_table_0")); + /* reading in loudspeaker info */ + p->q.dim = (int)ls_table[0]; + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, Str("vbap system NOT configured. \n" + "Missing vbaplsinit opcode" + " in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof(LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0 ; i < p->q.ls_set_am ; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + p->q.ele_vel = FL(1.0); /* functions specific to movement */ + if (UNLIKELY(fabs(*p->field_am) < (2+ (p->q.dim - 2)*2))) { + return csound->InitError(csound, + Str("Have to have at least %d directions in vbapmove"), + 2 + (p->q.dim - 2) * 2); + } + if (p->q.dim == 2) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am) - 1.0)); + else if (LIKELY(p->q.dim == 3)) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); + else + return csound->InitError(csound, Str("Wrong dimension")); + p->q.point_change_counter = 0; + p->q.curr_fld = 0; + p->q.next_fld = 1; + p->q.ang_dir.azi = *p->fld[0]; + if (p->q.dim == 3) { + p->q.ang_dir.ele = *p->fld[1]; + } else { + p->q.ang_dir.ele = FL(0.0); + } + if (p->q.dim == 3) { + p->q.curr_fld = 1; + p->q.next_fld = 2; + } + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap1_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + *p->spread, *p->field_am, p->fld); + return OK; +} + +int vbap1_moving_init_a(CSOUND *csound, VBAPA1_MOVING *p) +{ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + + if (p->tabout->data == NULL || p->tabout->dimensions!=1) + return csound->InitError(csound, Str("Output array not initialised")); + p->q.number = p->tabout->sizes[0]; + ls_table = + (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, "vbap_ls_table_0")); + /* reading in loudspeaker info */ + p->q.dim = (int)ls_table[0]; + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, Str("vbap system NOT configured. \n" + "Missing vbaplsinit opcode" + " in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof(LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0 ; i < p->q.ls_set_am ; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + p->q.ele_vel = FL(1.0); /* functions specific to movement */ + if (UNLIKELY(fabs(*p->field_am) < (2+ (p->q.dim - 2)*2))) { + return csound->InitError(csound, + Str("Have to have at least %d directions in vbapmove"), + 2 + (p->q.dim - 2) * 2); + } + if (p->q.dim == 2) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am) - 1.0)); + else if (LIKELY(p->q.dim == 3)) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); + else + return csound->InitError(csound, Str("Wrong dimension")); + p->q.point_change_counter = 0; + p->q.curr_fld = 0; + p->q.next_fld = 1; + p->q.ang_dir.azi = *p->fld[0]; + if (p->q.dim == 3) { + p->q.ang_dir.ele = *p->fld[1]; + } else { + p->q.ang_dir.ele = FL(0.0); + } + if (p->q.dim == 3) { + p->q.curr_fld = 1; + p->q.next_fld = 2; + } + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap1_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + *p->spread, *p->field_am, p->fld); + return OK; +} diff -Nru csound-5.17.11~dfsg/Opcodes/vbap_eight.c csound-6.02~dfsg/Opcodes/vbap_eight.c --- csound-5.17.11~dfsg/Opcodes/vbap_eight.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap_eight.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,548 +0,0 @@ -/* - vbap_eight.c: - - Copyright (C) 2000 Ville Pulkki - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* vbap_eight.c - -functions specific to four loudspeaker VBAP - -Ville Pulkki -*/ - - -#include "csdl.h" -#include "vbap.h" -#include -#include -#include - -int vbap_EIGHT_moving_control(CSOUND *, VBAP_EIGHT_MOVING *); - -int vbap_EIGHT(CSOUND *csound, VBAP_EIGHT *p) /* during note performance: */ -{ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int nsmps = csound->ksmps; - int i,j; - - vbap_EIGHT_control(csound,p); - for (i=0;i< EIGHT; i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - - /* write audio to result audio streams weighted - with gain factors*/ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) { - if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT) (i) * invfloatn * gainsubstr; - } - else { - for (i=0; idim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - - if (*p->spread spread = FL(0.0); - if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - /* Current panning angles */ - p->ang_dir.azi = (MYFLT) *p->azi; - p->ang_dir.ele = (MYFLT) *p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, EIGHT, p->cart_dir); - - /* Calculated gain factors of a spreaded virtual source*/ - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum = 16; - /* four orthogonal dirs*/ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, *p->azi, *p->spread); - new_spread_base(spreaddir[0], p->cart_dir,*p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them*/ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle*/ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle*/ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],*p->azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, EIGHT, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum = 6; - atmp.ele = FL(0.0); - atmp.azi = *p->azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = *p->azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = *p->azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = *p->azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = *p->azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = *p->azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, EIGHT, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(20.0); - } - - /*normalization*/ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum=SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_EIGHT_init(CSOUND *csound, VBAP_EIGHT *p) -{ /* Initializations before run time*/ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - p->dim = (int) ls_table[0]; /* reading in loudspeaker info */ - p->ls_am = (int) ls_table[1]; - p->ls_set_am = (int) ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured. \ - \nMissing vbaplsinit opcode in orchestra?")); - - csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp==NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0; i < p->ls_set_am; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); - } - } - - /* other initialization */ - if (UNLIKELY(p->dim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - p->ang_dir.azi = (MYFLT) *p->azi; - p->ang_dir.ele = (MYFLT) *p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_EIGHT_control(csound,p); - for (i=0;ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} - -int vbap_EIGHT_moving(CSOUND *csound, VBAP_EIGHT_MOVING *p) -/* during note performance: */ -{ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int i,j; - int nsmps = csound->ksmps; - - vbap_EIGHT_moving_control(csound,p); - for (i=0;i< (EIGHT); i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - - /* write audio to resulting audio streams weighted - with gain factors*/ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) - if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT) (i) * invfloatn * gainsubstr; - } - else - for (i=0; idim == 2 && fabs(p->ang_dir.ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - p->ang_dir.ele = FL(0.0); - } - if (*p->spread spread = FL(0.0); - if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - if (p->point_change_counter++ >= p->point_change_interval) { - p->point_change_counter = 0; - p->curr_fld = p->next_fld; - if (++p->next_fld >= (int) fabs(*p->field_am)) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - if (p->dim == 3) { /*jumping over second field */ - p->curr_fld = p->next_fld; - if (++p->next_fld >= ((int) fabs(*p->field_am))) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - } - if (UNLIKELY((p->fld[abs(p->next_fld)]==NULL))) - csound->Die(csound, Str("Missing fields in vbap8move\n")); - if (*p->field_am >= FL(0.0) && p->dim == 2) /* point-to-point */ - if (UNLIKELY(fabs(fabs(*p->fld[p->next_fld] - - *p->fld[p->curr_fld]) - 180.0) < 1.0)) - csound->Warning(csound, - Str("Warning: Ambiguous transition 180 degrees.\n")); - } - if (*p->field_am >= FL(0.0)) { /* point-to-point */ - if (p->dim == 3) { /* 3-D*/ - p->prev_ang_dir.azi = *p->fld[p->curr_fld-1]; - p->next_ang_dir.azi = *p->fld[p->next_fld]; - p->prev_ang_dir.ele = *p->fld[p->curr_fld]; - p->next_ang_dir.ele = *p->fld[p->next_fld+1]; - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle_to_cart( p->prev_ang_dir,&tmp1); - angle_to_cart( p->next_ang_dir,&tmp2); - tmp3.x = (FL(1.0)-coeff) * tmp1.x + coeff * tmp2.x; - tmp3.y = (FL(1.0)-coeff) * tmp1.y + coeff * tmp2.y; - tmp3.z = (FL(1.0)-coeff) * tmp1.z + coeff * tmp2.z; - coeff = (MYFLT)sqrt((double)(tmp3.x * tmp3.x + - tmp3.y * tmp3.y + - tmp3.z * tmp3.z)); - tmp3.x /= coeff; tmp3.y /= coeff; tmp3.z /= coeff; - cart_to_angle(tmp3,&(p->ang_dir)); - } - else if (p->dim == 2) { /* 2-D */ - p->prev_ang_dir.azi = *p->fld[p->curr_fld]; - p->next_ang_dir.azi = *p->fld[p->next_fld ]; - p->prev_ang_dir.ele = p->next_ang_dir.ele = FL(0.0); - scale_angles(&(p->prev_ang_dir)); - scale_angles(&(p->next_ang_dir)); - angle = (p->prev_ang_dir.azi - p->next_ang_dir.azi); - while(angle > FL(180.0)) - angle -= FL(360.0); - while(angle < -FL(180.0)) - angle += FL(360.0); - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle *= (coeff); - p->ang_dir.azi = p->prev_ang_dir.azi - angle; - p->ang_dir.ele = FL(0.0); - } - else { - csound->Die(csound, Str("Wrong dimension\n")); - } - } - else { /* angular velocities */ - if (p->dim == 2) { - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - scale_angles(&(p->ang_dir)); - } - else { /* 3D angular*/ - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - p->ang_dir.ele = p->ang_dir.ele + - p->ele_vel * (*p->fld[p->next_fld+1] * csound->onedkr); - if (p->ang_dir.ele > FL(90.0)) { - p->ang_dir.ele = FL(90.0); - p->ele_vel = -p->ele_vel; - } - if (p->ang_dir.ele < FL(0.0)) { - p->ang_dir.ele = FL(0.0); - p->ele_vel = -p->ele_vel; - } - scale_angles(&(p->ang_dir)); - } - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, EIGHT, p->cart_dir); - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum=16; - /* four orthogonal dirs*/ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, p->ang_dir.azi, *p->spread); - - new_spread_base(spreaddir[0], p->cart_dir,*p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them*/ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle*/ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle*/ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],p->ang_dir.azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, EIGHT, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum=6; - atmp.ele = FL(0.0); - atmp.azi = p->ang_dir.azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = p->ang_dir.azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = p->ang_dir.azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = p->ang_dir.azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = p->ang_dir.azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = p->ang_dir.azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, EIGHT, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(10.0); - } - /*normalization*/ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum= SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_EIGHT_moving_init(CSOUND *csound, VBAP_EIGHT_MOVING *p) -{ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - /* reading in loudspeaker info */ - p->dim = (int) ls_table[0]; - p->ls_am = (int) ls_table[1]; - p->ls_set_am = (int) ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured.\nMissing" - " vbaplsinit opcode in orchestra?")); - csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp == NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0 ; i < p->ls_set_am ; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); - } - } - - /* other initialization */ - p->ele_vel = FL(1.0); /* functions specific to movement */ - if (UNLIKELY(fabs(*p->field_am) < (2+ (p->dim - 2)*2))) { - csound->Die(csound, - Str("Have to have at least %d directions in vbap8move"), - 2 + (p->dim - 2) * 2); - } - if (p->dim == 2) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am) - 1.0)); - else if (p->dim == 3) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); - else - csound->Die(csound, Str("Wrong dimension")); - p->point_change_counter = 0; - p->curr_fld = 0; - p->next_fld = 1; - p->ang_dir.azi = *p->fld[0]; - if (p->dim == 3) { - p->ang_dir.ele = *p->fld[1]; - } else { - p->ang_dir.ele = FL(0.0); - } - if (p->dim == 3) { - p->curr_fld = 1; - p->next_fld = 2; - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_EIGHT_moving_control(csound,p); - for (i=0;ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} - diff -Nru csound-5.17.11~dfsg/Opcodes/vbap_four.c csound-6.02~dfsg/Opcodes/vbap_four.c --- csound-5.17.11~dfsg/Opcodes/vbap_four.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap_four.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,545 +0,0 @@ -/* - vbap_four.c: - - Copyright (C) 2000 Ville Pulkki - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* vbap_four.c - -functions specific to four loudspeaker VBAP - -Ville Pulkki -*/ - - -#include "csdl.h" -#include "vbap.h" -#include -#include -#include - -int vbap_FOUR_moving_control(CSOUND *, VBAP_FOUR_MOVING *); - -int vbap_FOUR(CSOUND *csound, VBAP_FOUR *p) /* during note performance: */ -{ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int i,j; - int nsmps = csound->ksmps; - - vbap_FOUR_control(csound,p); - for (i=0; i<(FOUR); i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - - /* write audio to result audio streams weighted - with gain factors*/ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) { - if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT)(i) * invfloatn * gainsubstr; - } - else { - for (i=0; idim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - - if (*p->spread spread = FL(0.0); - else if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - /* Current panning angles */ - p->ang_dir.azi = (MYFLT) *p->azi; - p->ang_dir.ele = (MYFLT) *p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, FOUR, p->cart_dir); - - /* Calculated gain factors of a spreaded virtual source*/ - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum = 16; - /* four orthogonal dirs*/ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, *p->azi, *p->spread); - new_spread_base(spreaddir[0], p->cart_dir, - *p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them*/ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle*/ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle*/ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],*p->azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, FOUR, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum = 6; - atmp.ele = FL(0.0); - atmp.azi = *p->azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = *p->azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = *p->azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = *p->azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = *p->azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = *p->azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, FOUR, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(20.0); - } - - /*normalization*/ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum=SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_FOUR_init(CSOUND *csound, VBAP_FOUR *p) -{ /* Initializations before run time*/ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - p->dim = (int)ls_table[0]; /* reading in loudspeaker info */ - p->ls_am = (int)ls_table[1]; - p->ls_set_am = (int)ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" - " vbaplsinit opcode in orchestra?")); - csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp == NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0; i < p->ls_set_am; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); - } - } - - /* other initialization */ - if (UNLIKELY(p->dim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound, - Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - p->ang_dir.azi = (MYFLT)*p->azi; - p->ang_dir.ele = (MYFLT)*p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_FOUR_control(csound,p); - for (i=0;ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} - -int vbap_FOUR_moving(CSOUND *csound, VBAP_FOUR_MOVING *p) -{ /* during note performance: */ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int i,j; - int nsmps = csound->ksmps; - - vbap_FOUR_moving_control(csound,p); - for (i=0;i< (FOUR); i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - - /* write audio to resulting audio streams weighted - with gain factors*/ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) - if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT)(i) * invfloatn * gainsubstr; - } - else - for (i=0; idim == 2 && fabs(p->ang_dir.ele) > 0.0)) { - csound->Warning(csound, - Str("Warning: truncating elevation to 2-D plane\n")); - p->ang_dir.ele = FL(0.0); - } - if (*p->spread spread = FL(0.0); - else if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - if (p->point_change_counter++ >= p->point_change_interval) { - p->point_change_counter = 0; - p->curr_fld = p->next_fld; - if (++p->next_fld >= (int) fabs(*p->field_am)) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - if (p->dim == 3) { /*jumping over second field */ - p->curr_fld = p->next_fld; - if (++p->next_fld >= ((int) fabs(*p->field_am))) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - } - if (UNLIKELY((p->fld[abs(p->next_fld)]==NULL))) - csound->Die(csound, Str("Missing fields in vbap4move\n")); - if (*p->field_am >= FL(0.0) && p->dim == 2) /* point-to-point */ - if (UNLIKELY(fabs(fabs(*p->fld[p->next_fld] - *p->fld[p->curr_fld]) - 180.0) < 1.0)) - csound->Warning(csound, - Str("Warning: Ambiguous transition 180 degrees.\n")); - } - if (*p->field_am >= FL(0.0)) { /* point-to-point */ - if (p->dim == 3) { /* 3-D*/ - p->prev_ang_dir.azi = *p->fld[p->curr_fld-1]; - p->next_ang_dir.azi = *p->fld[p->next_fld]; - p->prev_ang_dir.ele = *p->fld[p->curr_fld]; - p->next_ang_dir.ele = *p->fld[p->next_fld+1]; - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle_to_cart( p->prev_ang_dir,&tmp1); - angle_to_cart( p->next_ang_dir,&tmp2); - tmp3.x = (FL(1.0)-coeff) * tmp1.x + coeff * tmp2.x; - tmp3.y = (FL(1.0)-coeff) * tmp1.y + coeff * tmp2.y; - tmp3.z = (FL(1.0)-coeff) * tmp1.z + coeff * tmp2.z; - coeff = (MYFLT)sqrt((double)(tmp3.x * tmp3.x + - tmp3.y * tmp3.y + - tmp3.z * tmp3.z)); - tmp3.x /= coeff; tmp3.y /= coeff; tmp3.z /= coeff; - cart_to_angle(tmp3,&(p->ang_dir)); - } - else if (p->dim == 2) { /* 2-D */ - p->prev_ang_dir.azi = *p->fld[p->curr_fld]; - p->next_ang_dir.azi = *p->fld[p->next_fld ]; - p->prev_ang_dir.ele = p->next_ang_dir.ele = FL(0.0); - scale_angles(&(p->prev_ang_dir)); - scale_angles(&(p->next_ang_dir)); - angle = (p->prev_ang_dir.azi - p->next_ang_dir.azi); - while(angle > FL(180.0)) - angle -= FL(360.0); - while(angle < -FL(180.0)) - angle += FL(360.0); - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle *= (coeff); - p->ang_dir.azi = p->prev_ang_dir.azi - angle; - p->ang_dir.ele = FL(0.0); - } - else { - csound->Die(csound, Str("Wrong dimension\n")); - } - } - else { /* angular velocities */ - if (p->dim == 2) { - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - scale_angles(&(p->ang_dir)); - } - else { /* 3D angular*/ - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - p->ang_dir.ele = p->ang_dir.ele + - p->ele_vel * (*p->fld[p->next_fld+1] * csound->onedkr); - if (p->ang_dir.ele > FL(90.0)) { - p->ang_dir.ele = FL(90.0); - p->ele_vel = -p->ele_vel; - } - if (p->ang_dir.ele < FL(0.0)) { - p->ang_dir.ele = FL(0.0); - p->ele_vel = -p->ele_vel; - } - scale_angles(&(p->ang_dir)); - } - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, FOUR, p->cart_dir); - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum=16; - /* four orthogonal dirs*/ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, p->ang_dir.azi, *p->spread); - - new_spread_base(spreaddir[0], p->cart_dir,*p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them*/ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle*/ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle*/ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],p->ang_dir.azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, FOUR, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum=6; - atmp.ele = FL(0.0); - atmp.azi = p->ang_dir.azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = p->ang_dir.azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = p->ang_dir.azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = p->ang_dir.azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = p->ang_dir.azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = p->ang_dir.azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, FOUR, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(10.0); - } - /*normalization*/ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum=SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_FOUR_moving_init(CSOUND *csound, VBAP_FOUR_MOVING *p) -{ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - /* reading in loudspeaker info */ - p->dim = (int)ls_table[0]; - p->ls_am = (int)ls_table[1]; - p->ls_set_am = (int)ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" - " vbaplsinit opcode in orchestra?")); - csound->AuxAlloc(csound, p->ls_set_am * sizeof(LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp == NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0 ; i < p->ls_set_am ; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); - } - } - - /* other initialization */ - p->ele_vel = FL(1.0); /* functions specific to movement */ - if (UNLIKELY(fabs(*p->field_am) < (2+ (p->dim - 2)*2))) { - csound->Die(csound, - Str("Have to have at least %d directions in vbap4move"), - 2 + (p->dim - 2) * 2); - } - if (p->dim == 2) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am) - 1.0)); - else if (LIKELY(p->dim == 3)) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); - else - csound->Die(csound, Str("Wrong dimension")); - p->point_change_counter = 0; - p->curr_fld = 0; - p->next_fld = 1; - p->ang_dir.azi = *p->fld[0]; - if (p->dim == 3) { - p->ang_dir.ele = *p->fld[1]; - } else { - p->ang_dir.ele = FL(0.0); - } - if (p->dim == 3) { - p->curr_fld = 1; - p->next_fld = 2; - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_FOUR_moving_control(csound,p); - for (i = 0; ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} diff -Nru csound-5.17.11~dfsg/Opcodes/vbap_n.c csound-6.02~dfsg/Opcodes/vbap_n.c --- csound-5.17.11~dfsg/Opcodes/vbap_n.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap_n.c 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,854 @@ +/* + vbap_n.c: + + Copyright (C) 2000 Ville Pulkki + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ + +/* vbap_n.c + +functions specific to four loudspeaker VBAP + +Ville Pulkki heavily modified my Joh ffitch 2012 +*/ + + +#include "csoundCore.h" +#include "vbap.h" +#include +#include +#include + +int vbap_moving_control(CSOUND *, VBAP_MOVE_DATA *, INSDS*, MYFLT, + MYFLT *, MYFLT*,MYFLT**); + +int vbap(CSOUND *csound, VBAP *p) /* during note performance: */ +{ + MYFLT *outptr, *inptr; + MYFLT ogain, ngain, gainsubstr; + MYFLT invfloatn; + int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int cnt = p->q.number; + vbap_control(csound,&p->q, p->azi, p->ele, p->spread); + for (j=0; jq.beg_gains[j] = p->q.end_gains[j]; + p->q.end_gains[j] = p->q.updated_gains[j]; + } + + /* write audio to result audio streams weighted + with gain factors*/ + if (UNLIKELY(early)) nsmps -= early; + invfloatn = FL(1.0)/(nsmps-offset); + for (j=0; jaudio; + outptr = p->out_array[j]; + ogain = p->q.beg_gains[j]; + ngain = p->q.end_gains[j]; + gainsubstr = ngain - ogain; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); + //printf("cnt%d: ngain=%lf ogain=%f\n", j, ngain, ogain); + if (ngain != FL(0.0) || ogain != FL(0.0)) { + if (ngain != ogain) { + for (i = offset; i < nsmps; i++) { + outptr[i] = inptr[i] * + (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); + } + p->q.curr_gains[j]= ogain + + (MYFLT)(i) * invfloatn * gainsubstr; + } + else { + for (i=offset; ih.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + uint32_t ksmps = nsmps; + int cnt = p->q.number; + + vbap_control(csound,&p->q, p->azi, p->ele, p->spread); + for (j=0; jq.beg_gains[j] = p->q.end_gains[j]; + p->q.end_gains[j] = p->q.updated_gains[j]; + } + + /* write audio to result audio streams weighted + with gain factors*/ + if (UNLIKELY(early)) nsmps -= early; + invfloatn = FL(1.0)/(nsmps-offset); + for (j=0; jtabout->data[j*ksmps]; + inptr = p->audio; + ogain = p->q.beg_gains[j]; + ngain = p->q.end_gains[j]; + gainsubstr = ngain - ogain; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); + if (ngain != FL(0.0) || ogain != FL(0.0)) { + if (ngain != ogain) { + for (i = offset; i < nsmps; i++) { + outptr[i] = inptr[i] * + (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); + } + p->q.curr_gains[j]= ogain + + (MYFLT)(i) * invfloatn * gainsubstr; + } + else { + for (i=offset; inumber; + MYFLT tmp_gains[CHANNELS],sum=FL(0.0); + if (UNLIKELY(p->dim == 2 && fabs(*ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *ele = FL(0.0); + } + + if (*spread FL(100.0)) + *spread = FL(100.0); + /* Current panning angles */ + p->ang_dir.azi = (MYFLT) *azi; + p->ang_dir.ele = (MYFLT) *ele; + p->ang_dir.length = FL(1.0); + angle_to_cart(p->ang_dir, &(p->cart_dir)); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + p->updated_gains, cnt, p->cart_dir); + + /* Calculated gain factors of a spreaded virtual source*/ + if (*spread > FL(0.0)) { + if (p->dim == 3) { + spreaddirnum = 16; + /* four orthogonal dirs*/ + new_spread_dir(&spreaddir[0], p->cart_dir, + p->spread_base, *azi, *spread); + new_spread_base(spreaddir[0], p->cart_dir, + *spread, &p->spread_base); + cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); + cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); + cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); + /* four between them*/ + vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); + vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); + vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); + vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); + + /* four at half spreadangle*/ + vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); + vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); + vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); + vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); + + /* four at quarter spreadangle*/ + vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); + vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); + vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); + vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); + + for (i=1;icart_dir, + spreadbase[i],*azi,*spread); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jupdated_gains[j] += tmp_gains[j]; + } + } + } + else if (p->dim == 2) { + spreaddirnum = 6; + atmp.ele = FL(0.0); + atmp.azi = *azi - *spread; + angle_to_cart(atmp, &spreaddir[0]); + atmp.azi = *azi - *spread/2; + angle_to_cart(atmp, &spreaddir[1]); + atmp.azi = *azi - *spread/4; + angle_to_cart(atmp, &spreaddir[2]); + atmp.azi = *azi + *spread/4; + angle_to_cart(atmp, &spreaddir[3]); + atmp.azi = *azi + *spread/2; + angle_to_cart(atmp, &spreaddir[4]); + atmp.azi = *azi + *spread; + angle_to_cart(atmp, &spreaddir[5]); + + for (i=0;ils_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jupdated_gains[j] += tmp_gains[j]; + } + } + } + } + if (*spread > FL(70.0)) + for (i=0;iupdated_gains[i] +=(*spread - FL(70.0))/FL(30.0) * + (*spread - FL(70.0))/FL(30.0)*FL(20.0); + } + + /*normalization*/ + for (i=0;iupdated_gains[i]*p->updated_gains[i]; + } + + sum=SQRT(sum); + for (i=0;iupdated_gains[i] /= sum; + } + return OK; +} + +int vbap_init(CSOUND *csound, VBAP *p) +{ /* Initializations before run time*/ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + int cnt = p->q.number = (int)(p->OUTOCOUNT); + char name[24]; + + if((!strcmp(p->h.optext->t.opcod, "vbap.a")) == 0) { + p->audio = p->out_array[cnt]; + p->azi = p->out_array[cnt+1]; + p->ele = p->out_array[cnt+2]; + p->spread = p->out_array[cnt+3]; + p->layout = p->out_array[cnt+4]; + } + sprintf(name, "vbap_ls_table_%d", (int)*p->layout); + ls_table = (MYFLT*) (csound->QueryGlobalVariable(csound, name)); + + if (ls_table==NULL) + return csound->InitError(csound, + Str("could not find layout table no.%d"), + (int)*p->layout ); + + p->q.dim = (int)ls_table[0]; /* reading in loudspeaker info */ + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, + Str("vbap system NOT configured. \nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof (LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0; i < p->q.ls_set_am; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + if (UNLIKELY(p->q.dim == 2 && fabs(*p->ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *p->ele = FL(0.0); + } + p->q.ang_dir.azi = (MYFLT)*p->azi; + p->q.ang_dir.ele = (MYFLT)*p->ele; + p->q.ang_dir.length = FL(1.0); + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap_control(csound,&(p->q), p->azi, p->ele, p->spread); + for (i=0;iq.beg_gains[i] = p->q.updated_gains[i]; + p->q.end_gains[i] = p->q.updated_gains[i]; + } + return OK; +} + +int vbap_init_a(CSOUND *csound, VBAPA *p) +{ /* Initializations before run time*/ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + int cnt; + char name[24]; + + cnt = p->q.number = p->tabout->sizes[0]; + sprintf(name, "vbap_ls_table_%d", (int)*p->layout); + ls_table = (MYFLT*) (csound->QueryGlobalVariable(csound, name)); + + if (ls_table==NULL) + return csound->InitError(csound, + Str("could not find layout table no.%d"), + (int)*p->layout ); + + p->q.dim = (int)ls_table[0]; /* reading in loudspeaker info */ + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, + Str("vbap system NOT configured.\nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof(LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0; i < p->q.ls_set_am; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + if (UNLIKELY(p->q.dim == 2 && fabs(*p->ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + *p->ele = FL(0.0); + } + p->q.ang_dir.azi = *p->azi; + p->q.ang_dir.ele = *p->ele; + p->q.ang_dir.length = FL(1.0); + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap_control(csound,&(p->q), p->azi, p->ele, p->spread); + for (i=0;iq.beg_gains[i] = p->q.updated_gains[i]; + p->q.end_gains[i] = p->q.updated_gains[i]; + } + return OK; +} + +int vbap_moving(CSOUND *csound, VBAP_MOVING *p) +{ /* during note performance: */ + MYFLT *outptr, *inptr; + MYFLT ogain, ngain, gainsubstr; + MYFLT invfloatn; + int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + int cnt = p->q.number; + + vbap_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + p->spread, p->field_am, p->fld); + // vbap_moving_control(csound,p); + for (j=0;jq.beg_gains[j] = p->q.end_gains[j]; + p->q.end_gains[j] = p->q.updated_gains[j]; + } + + /* write audio to resulting audio streams weighted + with gain factors*/ + if (UNLIKELY(early)) nsmps -= early; + invfloatn = FL(1.0)/(nsmps-offset); + for (j=0; jaudio; + outptr = p->out_array[j]; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); + ogain = p->q.beg_gains[j]; + ngain = p->q.end_gains[j]; + gainsubstr = ngain - ogain; + if (ngain != FL(0.0) || ogain != FL(0.0)) + if (ngain != ogain) { + for (i = offset; i < nsmps; i++) { + outptr[i] = inptr[i] * + (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); + } + p->q.curr_gains[j]= ogain + + (MYFLT)(i) * invfloatn * gainsubstr; + } + else + for (i=offset; inumber; + + if (UNLIKELY(p->dim == 2 && fabs(p->ang_dir.ele) > 0.0)) { + csound->Warning(csound, + Str("Warning: truncating elevation to 2-D plane\n")); + p->ang_dir.ele = FL(0.0); + } + if (*spread FL(100.0)) + *spread = FL(100.0); + if (p->point_change_counter++ >= p->point_change_interval) { + p->point_change_counter = 0; + p->curr_fld = p->next_fld; + if (++p->next_fld >= (int) fabs(*field_am)) { + if (*field_am >= FL(0.0)) /* point-to-point */ + p->next_fld = 0; + else + p->next_fld = 1; + } + if (p->dim == 3) { /*jumping over second field */ + p->curr_fld = p->next_fld; + if (++p->next_fld >= ((int) fabs(*field_am))) { + if (*field_am >= FL(0.0)) /* point-to-point */ + p->next_fld = 0; + else + p->next_fld = 1; + } + } + if (UNLIKELY((fld[abs(p->next_fld)]==NULL))) + return csound->PerfError(csound, insdshead, + Str("Missing fields in vbapmove\n")); + if (*field_am >= FL(0.0) && p->dim == 2) /* point-to-point */ + if (UNLIKELY(fabs(fabs(*fld[p->next_fld] - + *fld[p->curr_fld]) - 180.0) < 1.0)) + csound->Warning(csound, + Str("Warning: Ambiguous transition 180 degrees.\n")); + } + if (*field_am >= FL(0.0)) { /* point-to-point */ + if (p->dim == 3) { /* 3-D*/ + p->prev_ang_dir.azi = *fld[p->curr_fld-1]; + p->next_ang_dir.azi = *fld[p->next_fld]; + p->prev_ang_dir.ele = *fld[p->curr_fld]; + p->next_ang_dir.ele = *fld[p->next_fld+1]; + coeff = ((MYFLT) p->point_change_counter) / + ((MYFLT) p->point_change_interval); + angle_to_cart( p->prev_ang_dir,&tmp1); + angle_to_cart( p->next_ang_dir,&tmp2); + tmp3.x = (FL(1.0)-coeff) * tmp1.x + coeff * tmp2.x; + tmp3.y = (FL(1.0)-coeff) * tmp1.y + coeff * tmp2.y; + tmp3.z = (FL(1.0)-coeff) * tmp1.z + coeff * tmp2.z; + coeff = (MYFLT)sqrt((double)(tmp3.x * tmp3.x + + tmp3.y * tmp3.y + + tmp3.z * tmp3.z)); + tmp3.x /= coeff; tmp3.y /= coeff; tmp3.z /= coeff; + cart_to_angle(tmp3,&(p->ang_dir)); + } + else if (p->dim == 2) { /* 2-D */ + p->prev_ang_dir.azi = *fld[p->curr_fld]; + p->next_ang_dir.azi = *fld[p->next_fld ]; + p->prev_ang_dir.ele = p->next_ang_dir.ele = FL(0.0); + scale_angles(&(p->prev_ang_dir)); + scale_angles(&(p->next_ang_dir)); + angle = (p->prev_ang_dir.azi - p->next_ang_dir.azi); + while(angle > FL(180.0)) + angle -= FL(360.0); + while(angle < -FL(180.0)) + angle += FL(360.0); + coeff = ((MYFLT) p->point_change_counter) / + ((MYFLT) p->point_change_interval); + angle *= (coeff); + p->ang_dir.azi = p->prev_ang_dir.azi - angle; + p->ang_dir.ele = FL(0.0); + } + else { + return csound->PerfError(csound, insdshead, + Str("Missing fields in vbapmove\n")); + } + } + else { /* angular velocities */ + if (p->dim == 2) { + p->ang_dir.azi = p->ang_dir.azi + + (*fld[p->next_fld] * ONEDKR); + scale_angles(&(p->ang_dir)); + } + else { /* 3D angular*/ + p->ang_dir.azi = p->ang_dir.azi + + (*fld[p->next_fld] * ONEDKR); + p->ang_dir.ele = p->ang_dir.ele + + p->ele_vel * (*fld[p->next_fld+1] * ONEDKR); + if (p->ang_dir.ele > FL(90.0)) { + p->ang_dir.ele = FL(90.0); + p->ele_vel = -p->ele_vel; + } + if (p->ang_dir.ele < FL(0.0)) { + p->ang_dir.ele = FL(0.0); + p->ele_vel = -p->ele_vel; + } + scale_angles(&(p->ang_dir)); + } + } + angle_to_cart(p->ang_dir, &(p->cart_dir)); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + p->updated_gains, cnt, p->cart_dir); + if (*spread > FL(0.0)) { + if (p->dim == 3) { + spreaddirnum=16; + /* four orthogonal dirs*/ + new_spread_dir(&spreaddir[0], p->cart_dir, + p->spread_base, p->ang_dir.azi, *spread); + + new_spread_base(spreaddir[0], p->cart_dir,*spread, &p->spread_base); + cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); + cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); + cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); + /* four between them*/ + vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); + vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); + vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); + vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); + + /* four at half spreadangle*/ + vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); + vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); + vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); + vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); + + /* four at quarter spreadangle*/ + vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); + vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); + vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); + vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); + + for (i=1;icart_dir, + spreadbase[i],p->ang_dir.azi,*spread); + calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jupdated_gains[j] += tmp_gains[j]; + } + } + } + else if (p->dim == 2) { + spreaddirnum=6; + atmp.ele = FL(0.0); + atmp.azi = p->ang_dir.azi - *spread; + angle_to_cart(atmp, &spreaddir[0]); + atmp.azi = p->ang_dir.azi - *spread/2; + angle_to_cart(atmp, &spreaddir[1]); + atmp.azi = p->ang_dir.azi - *spread/4; + angle_to_cart(atmp, &spreaddir[2]); + atmp.azi = p->ang_dir.azi + *spread/4; + angle_to_cart(atmp, &spreaddir[3]); + atmp.azi = p->ang_dir.azi + *spread/2; + angle_to_cart(atmp, &spreaddir[4]); + atmp.azi = p->ang_dir.azi + *spread; + angle_to_cart(atmp, &spreaddir[5]); + + for (i=0;ils_set_am, p->dim, p->ls_sets, + tmp_gains, cnt, spreaddir[i]); + for (j=0;jupdated_gains[j] += tmp_gains[j]; + } + } + } + } + if (*spread > FL(70.0)) + for (i=0;iupdated_gains[i] +=(*spread - FL(70.0))/FL(30.0) * + (*spread - FL(70.0))/FL(30.0)*FL(10.0); + } + /*normalization*/ + for (i=0;iupdated_gains[i]*p->updated_gains[i]); + } + + sum=SQRT(sum); + for (i=0;iupdated_gains[i] /= sum; + } + return OK; +} + +int vbap_moving_init(CSOUND *csound, VBAP_MOVING *p) +{ + int i, j; + MYFLT *ls_table, *ptr; + LS_SET *ls_set_ptr; + int cnt = (int)p->h.optext->t.outArgCount; + if ((!strncmp(p->h.optext->t.opcod, "vbapmove", 8)) == 0) { + p->audio = p->out_array[cnt]; + p->dur = p->out_array[cnt+1]; + p->spread = p->out_array[cnt+2]; + p->field_am = p->out_array[cnt+3]; + memcpy(p->fld, &(p->out_array[cnt+4]), + sizeof(MYFLT *)*(p->h.optext->t.inArgCount-4)); + } + + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, + "vbap_ls_table_0")); + if (ls_table==NULL) + return csound->InitError(csound, Str("could not find layout table no.0")); + p->q.number = cnt; + /* reading in loudspeaker info */ + p->q.dim = (int)ls_table[0]; + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof(LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0 ; i < p->q.ls_set_am ; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + p->q.ele_vel = FL(1.0); /* functions specific to movement */ + if (UNLIKELY(fabs(*p->field_am) < (2+ (p->q.dim - 2)*2))) { + return csound->InitError(csound, + Str("Have to have at least %d directions in vbapmove"), + 2 + (p->q.dim - 2) * 2); + } + if (p->q.dim == 2) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am) - 1.0)); + else if (LIKELY(p->q.dim == 3)) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); + else + return csound->InitError(csound, Str("Wrong dimension")); + p->q.point_change_counter = 0; + p->q.curr_fld = 0; + p->q.next_fld = 1; + p->q.ang_dir.azi = *p->fld[0]; + if (p->q.dim == 3) { + p->q.ang_dir.ele = *p->fld[1]; + } else { + p->q.ang_dir.ele = FL(0.0); + } + if (p->q.dim == 3) { + p->q.curr_fld = 1; + p->q.next_fld = 2; + } + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + p->spread, p->field_am, p->fld); + for (i = 0; iq.beg_gains[i] = p->q.updated_gains[i]; + p->q.end_gains[i] = p->q.updated_gains[i]; + } + return OK; +} + +int vbap_moving_a(CSOUND *csound, VBAPA_MOVING *p) +{ /* during note performance: */ + MYFLT *outptr, *inptr; + MYFLT ogain, ngain, gainsubstr; + MYFLT invfloatn; + int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; + uint32_t ksmps = nsmps; + int cnt = p->q.number; + + vbap_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + p->spread, p->field_am, p->fld); + // vbap_moving_control(csound,p); + for (j=0;jq.beg_gains[j] = p->q.end_gains[j]; + p->q.end_gains[j] = p->q.updated_gains[j]; + } + + /* write audio to resulting audio streams weighted + with gain factors*/ + if (UNLIKELY(early)) nsmps -= early; + invfloatn = FL(1.0)/(nsmps-offset); + outptr = p->tabout->data; + for (j=0; jaudio; + outptr = &p->tabout->data[j*ksmps]; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); + ogain = p->q.beg_gains[j]; + ngain = p->q.end_gains[j]; + gainsubstr = ngain - ogain; + if (ngain != FL(0.0) || ogain != FL(0.0)) + if (ngain != ogain) { + for (i = offset; i < nsmps; i++) { + outptr[i] = inptr[i] * + (ogain + (MYFLT)(i+1) * invfloatn * gainsubstr); + } + p->q.curr_gains[j]= ogain + + (MYFLT)(i) * invfloatn * gainsubstr; + } + else + for (i=offset; itabout->data==NULL) { + return csound->InitError(csound, + Str("Output array in vpabmove not initalised")); + } + cnt = p->tabout->sizes[0]; + + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, + "vbap_ls_table_0")); + if (ls_table==NULL) + return csound->InitError(csound, Str("could not find layout table no.0")); + p->q.number = cnt; + /* reading in loudspeaker info */ + p->q.dim = (int)ls_table[0]; + p->q.ls_am = (int)ls_table[1]; + p->q.ls_set_am = (int)ls_table[2]; + ptr = &(ls_table[3]); + if (!p->q.ls_set_am) + return csound->InitError(csound, + Str("vbap system NOT configured.\nMissing" + " vbaplsinit opcode in orchestra?")); + csound->AuxAlloc(csound, p->q.ls_set_am * sizeof(LS_SET), &p->q.aux); + if (UNLIKELY(p->q.aux.auxp == NULL)) { + return csound->InitError(csound, Str("could not allocate memory")); + } + p->q.ls_sets = (LS_SET*) p->q.aux.auxp; + ls_set_ptr = p->q.ls_sets; + for (i=0 ; i < p->q.ls_set_am ; i++) { + ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ + for (j=0 ; j < p->q.dim ; j++) { + ls_set_ptr[i].ls_nos[j] = (int)*(ptr++); + } + for (j=0 ; j < 9; j++) + ls_set_ptr[i].ls_mx[j] = FL(0.0); /*initial setting*/ + for (j=0 ; j < (p->q.dim) * (p->q.dim); j++) { + ls_set_ptr[i].ls_mx[j] = (MYFLT)*(ptr++); + } + } + + /* other initialization */ + p->q.ele_vel = FL(1.0); /* functions specific to movement */ + if (UNLIKELY(fabs(*p->field_am) < (2+ (p->q.dim - 2)*2))) { + return csound->InitError(csound, + Str("Have to have at least %d directions in vbapmove"), + 2 + (p->q.dim - 2) * 2); + } + if (p->q.dim == 2) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am) - 1.0)); + else if (LIKELY(p->q.dim == 3)) + p->q.point_change_interval = + (int)(CS_EKR * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); + else + return csound->InitError(csound, Str("Wrong dimension")); + p->q.point_change_counter = 0; + p->q.curr_fld = 0; + p->q.next_fld = 1; + p->q.ang_dir.azi = *p->fld[0]; + if (p->q.dim == 3) { + p->q.ang_dir.ele = *p->fld[1]; + } else { + p->q.ang_dir.ele = FL(0.0); + } + if (p->q.dim == 3) { + p->q.curr_fld = 1; + p->q.next_fld = 2; + } + angle_to_cart(p->q.ang_dir, &(p->q.cart_dir)); + p->q.spread_base.x = p->q.cart_dir.y; + p->q.spread_base.y = p->q.cart_dir.z; + p->q.spread_base.z = -p->q.cart_dir.x; + vbap_moving_control(csound,&p->q, p->h.insdshead, CS_ONEDKR, + p->spread, p->field_am, p->fld); + for (i = 0; iq.beg_gains[i] = p->q.updated_gains[i]; + p->q.end_gains[i] = p->q.updated_gains[i]; + } + return OK; +} + diff -Nru csound-5.17.11~dfsg/Opcodes/vbap_sixteen.c csound-6.02~dfsg/Opcodes/vbap_sixteen.c --- csound-5.17.11~dfsg/Opcodes/vbap_sixteen.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap_sixteen.c 1970-01-01 00:00:00.000000000 +0000 @@ -1,545 +0,0 @@ -/* - vbap_sixteen.c: - - Copyright (C) 2000 Ville Pulkki - - This file is part of Csound. - - The Csound Library is free software; you can redistribute it - and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - Csound is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with Csound; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 USA -*/ - -/* vbap_sixteen.c - -functions specific to sixteen loudspeaker VBAP - -Ville Pulkki -*/ - - -#include "csdl.h" -#include "vbap.h" -#include -#include -#include - -int vbap_SIXTEEN_moving_control(CSOUND *csound, VBAP_SIXTEEN_MOVING *p); - -int vbap_SIXTEEN(CSOUND *csound, VBAP_SIXTEEN *p) /* during note performance: */ -{ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int i,j; - int nsmps = csound->ksmps; - - vbap_SIXTEEN_control(csound,p); - for (i=0; i< (SIXTEEN); i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - - /* write audio to result audio streams weighted - with gain factors */ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) { - if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT) (i) * invfloatn * gainsubstr; - } - else { - for (i=0; idim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - - if (*p->spread spread = FL(0.0); - else if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - /* Current panning angles */ - p->ang_dir.azi = (MYFLT) *p->azi; - p->ang_dir.ele = (MYFLT) *p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, SIXTEEN, p->cart_dir); - - /* Calculated gain factors of a spreaded virtual source */ - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum = 16; - /* four orthogonal dirs */ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, *p->azi, *p->spread); - new_spread_base(spreaddir[0], p->cart_dir,*p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them */ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle */ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle */ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],*p->azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, SIXTEEN, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum = 6; - atmp.ele = FL(0.0); - atmp.azi = *p->azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = *p->azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = *p->azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = *p->azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = *p->azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = *p->azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, SIXTEEN, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(20.0); - } - - /* normalization */ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum = SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_SIXTEEN_init(CSOUND *csound, VBAP_SIXTEEN *p) -{ /* Initializations before run time */ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - p->dim = (int) ls_table[0]; /*reading in loudspeaker info */ - p->ls_am = (int) ls_table[1]; - p->ls_set_am = (int) ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured. \nMissing" - " vbaplsinit opcode in orchestra?")); - csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp == NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0; i < p->ls_set_am; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /* initial setting */ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); - } - } - - /* other initialization */ - if (UNLIKELY(p->dim == 2 && fabs(*p->ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - *p->ele = FL(0.0); - } - p->ang_dir.azi = (MYFLT) *p->azi; - p->ang_dir.ele = (MYFLT) *p->ele; - p->ang_dir.length = FL(1.0); - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_SIXTEEN_control(csound,p); - for (i = 0; ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} - -int vbap_SIXTEEN_moving(CSOUND *csound, VBAP_SIXTEEN_MOVING *p) /* during note performance: */ -{ - MYFLT *outptr, *inptr; - MYFLT ogain, ngain, gainsubstr; - MYFLT invfloatn; - int i,j; - - vbap_SIXTEEN_moving_control(csound,p); - for (i=0;i< (SIXTEEN); i++) { - p->beg_gains[i]=p->end_gains[i]; - p->end_gains[i]=p->updated_gains[i]; - } - - /* write audio to resulting audio streams weighted - with gain factors */ - invfloatn = csound->onedksmps; - for (j=0; jaudio; - outptr = p->out_array[j]; - ogain = p->beg_gains[j]; - ngain = p->end_gains[j]; - gainsubstr = ngain - ogain; - if (ngain != FL(0.0) || ogain != FL(0.0)) - if (ngain != ogain) { - for (i = 0; i < csound->ksmps; i++) { - outptr[i] = inptr[i] * - (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); - } - p->curr_gains[j]= ogain + - (MYFLT) (i) * invfloatn * gainsubstr; - } - else - for (i=0; iksmps; ++i) - outptr[i] = inptr[i] * ogain; - else - for (i=0; iksmps; ++i) - outptr[i] = FL(0.0); - } - return OK; -} - -int vbap_SIXTEEN_moving_control(CSOUND *csound, VBAP_SIXTEEN_MOVING *p) -{ - CART_VEC spreaddir[16]; - CART_VEC spreadbase[16]; - ANG_VEC atmp; - int32 i,j, spreaddirnum; - CART_VEC tmp1, tmp2, tmp3; - MYFLT coeff, angle; - MYFLT tmp_gains[SIXTEEN],sum=FL(0.0); - if (UNLIKELY(p->dim == 2 && fabs(p->ang_dir.ele) > 0.0)) { - csound->Warning(csound,Str("Warning: truncating elevation to 2-D plane\n")); - p->ang_dir.ele = FL(0.0); - } - if (*p->spread spread = FL(0.0); - else if (*p->spread >FL(100.0)) - *p->spread = FL(100.0); - if (p->point_change_counter++ >= p->point_change_interval) { - p->point_change_counter = 0; - p->curr_fld = p->next_fld; - if (++p->next_fld >= (int) fabs(*p->field_am)) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - if (p->dim == 3) { /*jumping over second field */ - p->curr_fld = p->next_fld; - if (++p->next_fld >= ((int) fabs(*p->field_am))) { - if (*p->field_am >= FL(0.0)) /* point-to-point */ - p->next_fld = 0; - else - p->next_fld = 1; - } - } - if (UNLIKELY((p->fld[abs(p->next_fld)]==NULL))) - csound->Die(csound, Str("Missing fields in vbap16move\n")); - if (*p->field_am >= 0.0 && p->dim == 2) /* point-to-point */ - if (UNLIKELY(fabs(fabs(*p->fld[p->next_fld] - *p->fld[p->curr_fld]) - - 180.0) < 1.0)) - csound->Warning(csound, - Str("Warning: Ambiguous transition 180 degrees.\n")); - } - if (*p->field_am >= FL(0.0)) { /* point-to-point */ - if (p->dim == 3) { /* 3-D */ - p->prev_ang_dir.azi = *p->fld[p->curr_fld-1]; - p->next_ang_dir.azi = *p->fld[p->next_fld]; - p->prev_ang_dir.ele = *p->fld[p->curr_fld]; - p->next_ang_dir.ele = *p->fld[p->next_fld+1]; - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle_to_cart( p->prev_ang_dir,&tmp1); - angle_to_cart( p->next_ang_dir,&tmp2); - tmp3.x = (FL(1.0)-coeff) * tmp1.x + coeff * tmp2.x; - tmp3.y = (FL(1.0)-coeff) * tmp1.y + coeff * tmp2.y; - tmp3.z = (FL(1.0)-coeff) * tmp1.z + coeff * tmp2.z; - coeff = (MYFLT)sqrt((double)(tmp3.x * tmp3.x + - tmp3.y * tmp3.y + - tmp3.z * tmp3.z)); - tmp3.x /= coeff; tmp3.y /= coeff; tmp3.z /= coeff; - cart_to_angle(tmp3,&(p->ang_dir)); - } - else if (p->dim == 2) { /* 2-D */ - p->prev_ang_dir.azi = *p->fld[p->curr_fld]; - p->next_ang_dir.azi = *p->fld[p->next_fld ]; - p->prev_ang_dir.ele = p->next_ang_dir.ele = FL(0.0); - scale_angles(&(p->prev_ang_dir)); - scale_angles(&(p->next_ang_dir)); - angle = (p->prev_ang_dir.azi - p->next_ang_dir.azi); - while(angle > FL(180.0)) - angle -= FL(360.0); - while(angle < -FL(180.0)) - angle += FL(360.0); - coeff = ((MYFLT) p->point_change_counter) / - ((MYFLT) p->point_change_interval); - angle *= (coeff); - p->ang_dir.azi = p->prev_ang_dir.azi - angle; - p->ang_dir.ele = FL(0.0); - } - else { - csound->Die(csound, Str("Wrong dimension\n")); - } - } - else { /* angular velocities */ - if (p->dim == 2) { - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - scale_angles(&(p->ang_dir)); - } - else { /* 3D angular */ - p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); - p->ang_dir.ele = p->ang_dir.ele + - p->ele_vel * (*p->fld[p->next_fld+1] * csound->onedkr); - if (p->ang_dir.ele > FL(90.0)) { - p->ang_dir.ele = FL(90.0); - p->ele_vel = -p->ele_vel; - } - if (p->ang_dir.ele < FL(0.0)) { - p->ang_dir.ele = FL(0.0); - p->ele_vel = -p->ele_vel; - } - scale_angles(&(p->ang_dir)); - } - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - p->updated_gains, SIXTEEN, p->cart_dir); - if (*p->spread > FL(0.0)) { - if (p->dim == 3) { - spreaddirnum=16; - /* four orthogonal dirs */ - new_spread_dir(&spreaddir[0], p->cart_dir, - p->spread_base, p->ang_dir.azi, *p->spread); - - new_spread_base(spreaddir[0], p->cart_dir,*p->spread, &p->spread_base); - cross_prod(p->spread_base, p->cart_dir, &spreadbase[1]); - cross_prod(spreadbase[1], p->cart_dir, &spreadbase[2]); - cross_prod(spreadbase[2], p->cart_dir, &spreadbase[3]); - /* four between them */ - vec_mean(p->spread_base, spreadbase[1], &spreadbase[4]); - vec_mean(spreadbase[1], spreadbase[2], &spreadbase[5]); - vec_mean(spreadbase[2], spreadbase[3], &spreadbase[6]); - vec_mean(spreadbase[3], p->spread_base, &spreadbase[7]); - - /* four at half spreadangle */ - vec_mean(p->cart_dir, p->spread_base, &spreadbase[8]); - vec_mean(p->cart_dir, spreadbase[1], &spreadbase[9]); - vec_mean(p->cart_dir, spreadbase[2], &spreadbase[10]); - vec_mean(p->cart_dir, spreadbase[3], &spreadbase[11]); - - /* four at quarter spreadangle */ - vec_mean(p->cart_dir, spreadbase[8], &spreadbase[12]); - vec_mean(p->cart_dir, spreadbase[9], &spreadbase[13]); - vec_mean(p->cart_dir, spreadbase[10], &spreadbase[14]); - vec_mean(p->cart_dir, spreadbase[11], &spreadbase[15]); - - for (i=1;icart_dir, - spreadbase[i],p->ang_dir.azi,*p->spread); - calc_vbap_gns(p->ls_set_am, p->dim, p->ls_sets, - tmp_gains, SIXTEEN, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - else if (p->dim == 2) { - spreaddirnum=6; - atmp.ele = FL(0.0); - atmp.azi = p->ang_dir.azi - *p->spread; - angle_to_cart(atmp, &spreaddir[0]); - atmp.azi = p->ang_dir.azi - *p->spread/2; - angle_to_cart(atmp, &spreaddir[1]); - atmp.azi = p->ang_dir.azi - *p->spread/4; - angle_to_cart(atmp, &spreaddir[2]); - atmp.azi = p->ang_dir.azi + *p->spread/4; - angle_to_cart(atmp, &spreaddir[3]); - atmp.azi = p->ang_dir.azi + *p->spread/2; - angle_to_cart(atmp, &spreaddir[4]); - atmp.azi = p->ang_dir.azi + *p->spread; - angle_to_cart(atmp, &spreaddir[5]); - - for (i=0;ils_set_am, p->dim, p->ls_sets, - tmp_gains, SIXTEEN, spreaddir[i]); - for (j=0;jupdated_gains[j] += tmp_gains[j]; - } - } - } - } - if (*p->spread > FL(70.0)) - for (i=0;iupdated_gains[i] +=(*p->spread - FL(70.0))/FL(30.0) * - (*p->spread - FL(70.0))/FL(30.0)*FL(10.0); - } - /* normalization */ - for (i=0;iupdated_gains[i]*p->updated_gains[i]); - } - - sum= SQRT(sum); - for (i=0;iupdated_gains[i] /= sum; - } - return OK; -} - -int vbap_SIXTEEN_moving_init(CSOUND *csound, VBAP_SIXTEEN_MOVING *p) -{ - int i, j; - MYFLT *ls_table, *ptr; - LS_SET *ls_set_ptr; - - ls_table = get_ls_table(csound); - /* reading in loudspeaker info */ - p->dim = (int) ls_table[0]; - p->ls_am = (int) ls_table[1]; - p->ls_set_am = (int) ls_table[2]; - ptr = &(ls_table[3]); - if (!p->ls_set_am) - return csound->InitError(csound, Str("vbap system NOT configured.\nMissing" - " vbaplsinit opcode in orchestra?")); - csound->AuxAlloc(csound, p->ls_set_am * sizeof (LS_SET), &p->aux); - if (UNLIKELY(p->aux.auxp == NULL)) { - return csound->InitError(csound, Str("could not allocate memory")); - } - p->ls_sets = (LS_SET*) p->aux.auxp; - ls_set_ptr = p->ls_sets; - for (i=0 ; i < p->ls_set_am ; i++) { - ls_set_ptr[i].ls_nos[2] = 0; /* initial setting */ - for (j=0 ; j < p->dim ; j++) { - ls_set_ptr[i].ls_nos[j] = (int) *(ptr++); - } - for (j=0 ; j < 9; j++) - ls_set_ptr[i].ls_mx[j] = FL(0.0); /* initial setting */ - for (j=0 ; j < (p->dim) * (p->dim); j++) { - ls_set_ptr[i].ls_mx[j] = (MYFLT) *(ptr++); - } - } - - /* other initialization */ - p->ele_vel = FL(1.0); /* functions specific to movement */ - if (UNLIKELY(fabs(*p->field_am) < (2+ (p->dim - 2)*2))) { - csound->Die(csound, - Str("Have to have at least %d directions in vbap16move"), - 2 + (p->dim - 2) * 2); - } - if (p->dim == 2) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am) - 1.0)); - else if (LIKELY(p->dim == 3)) - p->point_change_interval = - (int)(csound->ekr * *p->dur /(fabs(*p->field_am)*0.5 - 1.0)); - else - csound->Die(csound, Str("Wrong dimension")); - p->point_change_counter = 0; - p->curr_fld = 0; - p->next_fld = 1; - p->ang_dir.azi = *p->fld[0]; - if (p->dim == 3) { - p->ang_dir.ele = *p->fld[1]; - } - else { - p->ang_dir.ele = FL(0.0); - } - if (p->dim == 3) { - p->curr_fld = 1; - p->next_fld = 2; - } - angle_to_cart(p->ang_dir, &(p->cart_dir)); - p->spread_base.x = p->cart_dir.y; - p->spread_base.y = p->cart_dir.z; - p->spread_base.z = -p->cart_dir.x; - vbap_SIXTEEN_moving_control(csound,p); - for (i = 0; ibeg_gains[i] = p->updated_gains[i]; - p->end_gains[i] = p->updated_gains[i]; - } - return OK; -} diff -Nru csound-5.17.11~dfsg/Opcodes/vbap_zak.c csound-6.02~dfsg/Opcodes/vbap_zak.c --- csound-5.17.11~dfsg/Opcodes/vbap_zak.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vbap_zak.c 2014-01-07 16:53:48.000000000 +0000 @@ -29,7 +29,7 @@ */ -#include "csdl.h" +#include "csoundCore.h" #include "vbap.h" #include #include @@ -43,28 +43,33 @@ MYFLT *outptr, *inptr; MYFLT ogain, ngain, gainsubstr; MYFLT invfloatn; - int i,j; + int j; int n = p->n; - int nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; vbap_zak_control(csound,p); - for (i=0; ibeg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; + for (j=0; jbeg_gains[j] = p->end_gains[j]; + p->end_gains[j] = p->updated_gains[j]; } /* write audio to result audio streams weighted with gain factors */ - invfloatn = csound->onedksmps; outptr = p->out_array; + if (UNLIKELY(early)) nsmps -= early; + invfloatn = FL(1.0)/(nsmps-offset); for (j=0; jaudio; ogain = p->beg_gains[j]; ngain = p->end_gains[j]; gainsubstr = ngain - ogain; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); if (ngain != FL(0.0) || ogain != FL(0.0)) if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { + for (i = offset; i < nsmps; i++) { outptr[i] = inptr[i] * (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); } @@ -72,7 +77,7 @@ (MYFLT) (i) * invfloatn * gainsubstr; } else { - for (i=0; in = (int)MYFLT2LONG(*p->numb); /* Set size */ + char name[24]; /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { - return csound->PerfError(csound, Str("outz index > isizea. No output")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index > isizea. No output")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("outz index < 0. No output.")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index < 0. No output.")); } + if ((int)*p->layout==0) strcpy(name, "vbap_ls_table"); + else sprintf(name, "vbap_ls_table_%d", (int)*p->layout==0); /* Now read from the array in za space and write to the output. */ - p->out_array = csound->zastart + (indx * csound->ksmps);/* outputs */ + p->out_array = csound->zastart + (indx * CS_KSMPS);/* outputs */ csound->AuxAlloc(csound, p->n*sizeof(MYFLT)*4, &p->auxch); p->curr_gains = (MYFLT*)p->auxch.auxp; p->beg_gains = p->curr_gains + p->n; p->end_gains = p->beg_gains + p->n; p->updated_gains = p->end_gains + p->n; - ls_table = get_ls_table(csound); + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, name)); p->dim = (int) ls_table[0]; /* reading in loudspeaker info */ p->ls_am = (int) ls_table[1]; p->ls_set_am = (int) ls_table[2]; @@ -259,19 +269,26 @@ MYFLT *outptr, *inptr; MYFLT ogain, ngain, gainsubstr; MYFLT invfloatn; - int i,j; - int nsmps = csound->ksmps; + int j; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; vbap_zak_moving_control(csound,p); - for (i=0;i< p->n; i++) { - p->beg_gains[i] = p->end_gains[i]; - p->end_gains[i] = p->updated_gains[i]; + for (j=0;j< p->n; j++) { + p->beg_gains[j] = p->end_gains[j]; + p->end_gains[j] = p->updated_gains[j]; } - /* write audio to resulting audio streams wEIGHTed + /* write audio to resulting audio streams weighted with gain factors */ - invfloatn = csound->onedksmps; + invfloatn = FL(1.0)/(nsmps-offset); outptr = p->out_array; + if (UNLIKELY(offset)) memset(outptr, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&outptr[nsmps], '\0', early*sizeof(MYFLT)); + } for (j=0; jn ;j++) { inptr = p->audio; ogain = p->beg_gains[j]; @@ -279,7 +296,7 @@ gainsubstr = ngain - ogain; if (ngain != FL(0.0) || ogain != FL(0.0)) if (ngain != ogain) { - for (i = 0; i < nsmps; i++) { + for (i = offset; i < nsmps; i++) { outptr[i] = inptr[i] * (ogain + (MYFLT) (i+1) * invfloatn * gainsubstr); } @@ -287,7 +304,7 @@ (MYFLT) (i) * invfloatn * gainsubstr; } else - for (i=0; ifld[abs(p->next_fld)]==NULL))) - csound->Die(csound, Str("Missing fields in vbapzmove\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("Missing fields in vbapzmove\n")); if (*p->field_am >= FL(0.0) && p->dim == 2) /* point-to-point */ if (UNLIKELY(fabs(fabs(*p->fld[p->next_fld] - *p->fld[p->curr_fld]) - 180.0) < 1.0)) @@ -378,20 +396,21 @@ p->ang_dir.ele = FL(0.0); } else { - csound->Die(csound, Str("Wrong dimension\n")); + return csound->PerfError(csound, p->h.insdshead, + Str("Missing fields in vbapzmove\n")); } } else { /* angular velocities */ if (p->dim == 2) { p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); + (*p->fld[p->next_fld] * CS_ONEDKR); scale_angles(&(p->ang_dir)); } else { /* 3D angular */ p->ang_dir.azi = p->ang_dir.azi + - (*p->fld[p->next_fld] * csound->onedkr); + (*p->fld[p->next_fld] * CS_ONEDKR); p->ang_dir.ele = p->ang_dir.ele + - p->ele_vel * (*p->fld[p->next_fld+1] * csound->onedkr); + p->ele_vel * (*p->fld[p->next_fld+1] * CS_ONEDKR); if (p->ang_dir.ele > FL(90.0)) { p->ang_dir.ele = FL(90.0); p->ele_vel = -p->ele_vel; @@ -497,20 +516,23 @@ /* Check to see this index is within the limits of za space. */ indx = (int32) *p->ndx; if (UNLIKELY(indx > csound->zalast)) { - return csound->PerfError(csound, Str("outz index > isizea. No output")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index > isizea. No output")); } else if (UNLIKELY(indx < 0)) { - return csound->PerfError(csound, Str("outz index < 0. No output.")); + return csound->PerfError(csound, p->h.insdshead, + Str("outz index < 0. No output.")); } /* Now read from the array in za space and write to the output. */ - p->out_array = csound->zastart + (indx * csound->ksmps);/* outputs */ + p->out_array = csound->zastart + (indx * CS_KSMPS);/* outputs */ csound->AuxAlloc(csound, p->n*sizeof(MYFLT)*4, &p->auxch); p->curr_gains = (MYFLT*)p->auxch.auxp; p->beg_gains = p->curr_gains + p->n; p->end_gains = p->beg_gains + p->n; p->updated_gains = p->end_gains + p->n; /* reading in loudspeaker info */ - ls_table = get_ls_table(csound); + ls_table = (MYFLT*) (csound->QueryGlobalVariableNoCheck(csound, + "vbap_ls_table_0")); p->dim = (int) ls_table[0]; p->ls_am = (int) ls_table[1]; p->ls_set_am = (int) ls_table[2]; @@ -536,18 +558,18 @@ /* other initialization */ p->ele_vel = FL(1.0); /* functions specific to movement */ if (UNLIKELY(fabs(*p->field_am) < (2+ (p->dim - 2)*2))) { - csound->Die(csound, + return csound->InitError(csound, Str("Have to have at least %d directions in vbapzmove"), 2 + (p->dim - 2) * 2); } if (p->dim == 2) - p->point_change_interval = (int) (csound->ekr * *p->dur + p->point_change_interval = (int) (CS_EKR * *p->dur / (fabs(*p->field_am) - 1.0)); else if (LIKELY(p->dim == 3)) - p->point_change_interval = (int) (csound->ekr * *p->dur + p->point_change_interval = (int) (CS_EKR * *p->dur / (fabs(*p->field_am) * 0.5 - 1.0)); else - csound->Die(csound, Str("Wrong dimension")); + return csound->InitError(csound, Str("Wrong dimension")); p->point_change_counter = 0; p->curr_fld = 0; p->next_fld = 1; diff -Nru csound-5.17.11~dfsg/Opcodes/vpvoc.c csound-6.02~dfsg/Opcodes/vpvoc.c --- csound-5.17.11~dfsg/Opcodes/vpvoc.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vpvoc.c 2014-01-07 16:54:20.000000000 +0000 @@ -51,11 +51,13 @@ (segp+nsegs)->cnt = MAXPOS; } argp = p->argums; - if (UNLIKELY((nxtfunc = csound->FTFind(csound, *argp++)) == NULL)) + if (UNLIKELY((nxtfunc = csound->FTnp2Find(csound, *argp++)) == NULL)) return NOTOK; flength = nxtfunc->flen; p->outfunc = - (FUNC*) csound->Calloc(csound, sizeof(FUNC) + flength * sizeof(MYFLT)); + (FUNC*) csound->Calloc(csound, sizeof(FUNC)); + p->outfunc->ftable = + (MYFLT*)csound->Calloc(csound, (1 + flength) * sizeof(MYFLT)); p->outfunc->flen = nxtfunc->flen; p->outfunc->lenmask = nxtfunc->lenmask; p->outfunc->lobits = nxtfunc->lobits; @@ -69,10 +71,10 @@ segp++; /* init each seg .. */ curfunc = nxtfunc; dur = **argp++; - if (UNLIKELY((nxtfunc = csound->FTFind(csound, *argp++)) == NULL)) + if (UNLIKELY((nxtfunc = csound->FTnp2Find(csound, *argp++)) == NULL)) return OK; if (dur > FL(0.0)) { - segp->d = dur * csound->ekr; + segp->d = dur * CS_EKR; segp->function = curfunc; segp->nxtfunction = nxtfunc; segp->cnt = (int32) (segp->d + FL(0.5)); @@ -115,7 +117,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("tableseg: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tableseg: not initialised")); } int ktablexseg(CSOUND *csound, TABLESEG *p) @@ -143,7 +146,8 @@ } return OK; err1: - return csound->PerfError(csound, Str("tablexseg: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("tablexseg: not initialised")); } /************************************************************/ @@ -151,12 +155,12 @@ /************************************************************/ #define WLN 1 /* time window is WLN*2*ksmps long */ -#define OPWLEN (2*WLN*csound->ksmps) /* manifest used for final time wdw */ +#define OPWLEN (2*WLN*CS_KSMPS) /* manifest used for final time wdw */ -int vpvset(CSOUND *csound, VPVOC *p) +int vpvset_(CSOUND *csound, VPVOC *p, int stringname) { - int i; - char pvfilnam[64]; + unsigned int i; + char pvfilnam[MAXNAME]; PVOCEX_MEMFILE pp; int frInc, chans; /* THESE SHOULD BE SAVED IN PVOC STRUCT */ @@ -168,7 +172,7 @@ csound->AuxAlloc(csound, sizeof(TABLESEG), &p->auxtab); p->tableseg = (TABLESEG*) p->auxtab.auxp; if (UNLIKELY((p->tableseg->outfunc = - csound->FTFind(csound, p->isegtab)) == NULL)) { + csound->FTnp2Find(csound, p->isegtab)) == NULL)) { return csound->InitError(csound, Str("vpvoc: Could not find ifnmagctrl table %f"), *p->isegtab); @@ -190,7 +194,13 @@ p->outBuf = fltp; fltp += PVFFTSIZE; p->window = fltp; } - csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.", p->XSTRCODE); + if( stringname==0){ + if (ISSTRCOD(*p->ifilno)) + strncpy(pvfilnam,get_arg_string(csound, *p->ifilno), MAXNAME-1); + else csound->strarg2name(csound, pvfilnam, p->ifilno, "pvoc.",0); + } + else strncpy(pvfilnam, ((STRINGDAT *)p->ifilno)->data, MAXNAME-1); + if (UNLIKELY(csound->PVOCEX_LoadFile(csound, pvfilnam, &pp) != 0)) return csound->InitError(csound, Str("VPVOC cannot load %s"), pvfilnam); @@ -198,9 +208,9 @@ frInc = pp.overlap; chans = pp.chans; p->asr = pp.srate; - if (UNLIKELY(p->asr != csound->esr)) { /* & chk the data */ + if (UNLIKELY(p->asr != CS_ESR)) { /* & chk the data */ csound->Warning(csound, Str("%s's srate = %8.0f, orch's srate = %8.0f"), - pvfilnam, p->asr, csound->esr); + pvfilnam, p->asr, CS_ESR); } if (UNLIKELY(p->frSiz > PVFRAMSIZE)) { return csound->InitError(csound, @@ -221,9 +231,9 @@ p->baseFr = 0; /* point to first data frame */ p->maxFr = pp.nframes - 1; /* highest possible frame index */ - p->frPktim = (MYFLT) csound->ksmps / (MYFLT) frInc; + p->frPktim = (MYFLT) CS_KSMPS / (MYFLT) frInc; /* factor by which to mult expand phase diffs (ratio of samp spacings) */ - p->frPrtim = csound->esr / (MYFLT) frInc; + p->frPrtim = CS_ESR / (MYFLT) frInc; /* factor by which to mulitply 'real' time index to get frame index */ /* amplitude scale for PVOC */ /* p->scale = (MYFLT) pp.fftsize * ((MYFLT) pp.fftsize / (MYFLT) pp.winsize); @@ -243,7 +253,7 @@ if (UNLIKELY((OPWLEN / 2 + 1) > PVWINLEN)) { return csound->InitError(csound, Str("ksmps of %d needs wdw of %d, " "max is %d for pv %s"), - csound->ksmps, (OPWLEN / 2 + 1), + CS_KSMPS, (OPWLEN / 2 + 1), PVWINLEN, pvfilnam); } for (i = 0; i < OPWLEN / 2 + 1; ++i) /* time window is OPWLEN long */ @@ -258,6 +268,14 @@ return OK; } +int vpvset(CSOUND *csound, VPVOC *p){ + return vpvset_(csound,p,0); +} + +int vpvset_S(CSOUND *csound, VPVOC *p){ + return vpvset_(csound,p,1); +} + int vpvoc(CSOUND *csound, VPVOC *p) { MYFLT *ar = p->rslt; @@ -283,7 +301,8 @@ /* ..so we won't run into buf2Size problems */ goto err2; } - if (UNLIKELY(outlen<2*csound->ksmps)) { /* minimum post-squeeze windowlength */ + if (UNLIKELY(outlen<(int)(2*CS_KSMPS))) { + /* minimum post-squeeze windowlength */ goto err3; } buf2Size = OPWLEN; /* always window to same length after DS */ @@ -310,7 +329,7 @@ } /***************************************************/ - FrqToPhase(buf, asize, pex * (MYFLT) csound->ksmps, p->asr, + FrqToPhase(buf, asize, pex * (MYFLT) CS_KSMPS, p->asr, (MYFLT) (0.5 * ((pex / p->lastPex) - 1))); /* accumulate phase and wrap to range -PI to PI */ RewrapPhase(buf, asize, p->lastPhase); @@ -321,7 +340,7 @@ if (specwp < 0) csound->Warning(csound, Str("PVOC debug: one frame gets through\n")); if (specwp > 0) - PreWarpSpec(p->pp, buf, asize, pex, (MYFLT *)p->memenv.auxp); + PreWarpSpec(buf, asize, pex, (MYFLT *)p->memenv.auxp); Polar2Real_PVOC(csound, buf, size); @@ -341,23 +360,27 @@ /* buf2[n] = FL(0.0); */ } - addToCircBuf(buf2, p->outBuf, p->opBpos, csound->ksmps, circBufSize); - writeClrFromCircBuf(p->outBuf, ar, p->opBpos, csound->ksmps, circBufSize); - p->opBpos += csound->ksmps; + addToCircBuf(buf2, p->outBuf, p->opBpos, CS_KSMPS, circBufSize); + writeClrFromCircBuf(p->outBuf, ar, p->opBpos, CS_KSMPS, circBufSize); + p->opBpos += CS_KSMPS; if (p->opBpos > circBufSize) p->opBpos -= circBufSize; - addToCircBuf(buf2 + csound->ksmps, p->outBuf, p->opBpos, - buf2Size - csound->ksmps, circBufSize); + addToCircBuf(buf2 + CS_KSMPS, p->outBuf, p->opBpos, + buf2Size - CS_KSMPS, circBufSize); p->lastPex = pex; /* needs to know last pitchexp to update phase */ return OK; err1: - return csound->PerfError(csound, Str("vpvoc: not initialised")); + return csound->PerfError(csound, p->h.insdshead, + Str("vpvoc: not initialised")); err2: - return csound->PerfError(csound, Str("PVOC transpose too low")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too low")); err3: - return csound->PerfError(csound, Str("PVOC transpose too high")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC transpose too high")); err4: - return csound->PerfError(csound, Str("PVOC timpnt < 0")); + return csound->PerfError(csound, p->h.insdshead, + Str("PVOC timpnt < 0")); } diff -Nru csound-5.17.11~dfsg/Opcodes/vst4cs/src/fxbank.cpp csound-6.02~dfsg/Opcodes/vst4cs/src/fxbank.cpp --- csound-5.17.11~dfsg/Opcodes/vst4cs/src/fxbank.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vst4cs/src/fxbank.cpp 2014-01-07 16:53:48.000000000 +0000 @@ -187,7 +187,7 @@ { FILE *fp = fopen(pszFile, "rb"); /* try to open the file */ - if (!fp) { /* upon error */ + if (!fp) { /* upon error */ printf("Error loading bank: %s \n", pszFile); return false; /* return an error */ } @@ -204,7 +204,7 @@ nBank = new unsigned char[tLen]; /* allocate storage */ //if (!nBank) // throw (int)1; - /* read chunk set to determine cnt. */ + /* read chunk set to determine cnt. */ if (fread(nBank, 1, tLen, fp) != tLen) return false; // throw (int)1; @@ -233,12 +233,12 @@ if (pSet->fxMagic == bankMagic) { //printf("bankMagic\n"); - fxProgram * pProg = pSet->programs; /* position on 1st program */ + fxProgram * pProg = pSet->programs; /* position on 1st program */ //printf ("Number of programs = %i",numPrograms); int nProg = 0; - while (nProg < pSet->numPrograms) /* walk program list */ + while (nProg < pSet->numPrograms) /* walk program list */ { - if (NeedsBSwap) /* eventually swap necessary bytes */ + if (NeedsBSwap) /* eventually swap necessary bytes */ { SwapBytes(pProg->chunkMagic); SwapBytes(pProg->byteSize); @@ -251,12 +251,12 @@ //printf("bankMagic-Swapped\n"); if ((pProg->chunkMagic != cMagic)|| (pProg->fxMagic != fMagic)) - { /* if erroneous data */ + { /* if erroneous data */ printf("Erroneous data.\n"); - return 0; /* get out */ + return 0; /* get out */ }; - if (NeedsBSwap) /* if necessary */ - { /* swap all parameter bytes */ + if (NeedsBSwap) /* if necessary */ + { /* swap all parameter bytes */ int j; for (j = 0; j < pProg->numParams; j++) SwapBytes(pProg->params[j]); @@ -264,7 +264,7 @@ //printf("bankMagic-swap parameter\n"); unsigned char *pNext = (unsigned char *)(pProg + 1); pNext += (sizeof(float) * (pProg->numParams - 1)); - //if (pNext > nBank + tLen) /* VERY simple fuse */ + //if (pNext > nBank + tLen) /* VERY simple fuse */ // throw (int)1; pProg = (fxProgram *)pNext; @@ -277,7 +277,7 @@ { //printf("chunkBankMagic\n"); fxChunkSet * pCSet = (fxChunkSet *)nBank; - if (NeedsBSwap) /* eventually swap necessary bytes */ + if (NeedsBSwap) /* eventually swap necessary bytes */ { SwapBytes(pCSet->chunkSize); /* size check - must not be too large*/ @@ -295,8 +295,8 @@ } //catch(...) // { - // brc = false; /* if any error occured, say NOPE */ - // if (nBank) /* and remove loaded data */ + // brc = false; /* if any error occured, say NOPE */ + // if (nBank) /* and remove loaded data */ // delete[] nBank; // } @@ -425,7 +425,7 @@ { unsigned char *pNext = (unsigned char *)(pProg + 1); pNext += (sizeof(float) * (pProg->numParams - 1)); - if (pNext > bBank + nBankLen) /* VERY simple fuse */ + if (pNext > bBank + nBankLen) /* VERY simple fuse */ return NULL; pProg = (fxProgram *)pNext; diff -Nru csound-5.17.11~dfsg/Opcodes/vst4cs/src/fxbank.h csound-6.02~dfsg/Opcodes/vst4cs/src/fxbank.h --- csound-5.17.11~dfsg/Opcodes/vst4cs/src/fxbank.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vst4cs/src/fxbank.h 2014-01-07 16:54:20.000000000 +0000 @@ -132,14 +132,26 @@ public: long GetVersion() { if (!bBank) return 0; return ((fxSet*)bBank)->version; } long GetFxID() { if (!bBank) return 0; return ((fxSet*)bBank)->fxID; } - void SetFxID(long id) { if (bBank) ((fxSet*)bBank)->fxID = id; if (!bChunk) for (int i = GetNumPrograms() -1; i >= 0; i--) GetProgram(i)->fxID = id; } + void SetFxID(long id) + { if (bBank) ((fxSet*)bBank)->fxID = id; + if (!bChunk) + for (int i = GetNumPrograms() -1; i >= 0; i--) GetProgram(i)->fxID = id; } long GetFxVersion() { if (!bBank) return 0; return ((fxSet*)bBank)->fxVersion; } - void SetFxVersion(long v) { if (bBank) ((fxSet*)bBank)->fxVersion = v; if (!bChunk) for (int i = GetNumPrograms() -1; i >= 0; i--) GetProgram(i)->fxVersion = v; } - long GetNumPrograms() { if (!bBank) return 0; return ((fxSet*)bBank)->numPrograms; } + void SetFxVersion(long v) { + if (bBank) ((fxSet*)bBank)->fxVersion = v; + if (!bChunk) for (int i = GetNumPrograms() -1; i >= 0; i--) + GetProgram(i)->fxVersion = v; } + long GetNumPrograms() { + if (!bBank) return 0; return ((fxSet*)bBank)->numPrograms; } long GetNumParams() { if (bChunk) return 0; return GetProgram(0)->numParams; } - long GetChunkSize() { if (!bChunk) return 0; return ((fxChunkSet *)bBank)->chunkSize; } + long GetChunkSize() { + if (!bChunk) return 0; return ((fxChunkSet *)bBank)->chunkSize; } void *GetChunk() { if (!bChunk) return 0; return ((fxChunkSet *)bBank)->chunk; } - bool SetChunk(void *chunk) { if (!bChunk) return false; memcpy(((fxChunkSet *)bBank)->chunk, chunk, ((fxChunkSet *)bBank)->chunkSize); return true; } + bool SetChunk(void *chunk) { + if (!bChunk) return false; + memcpy(((fxChunkSet *)bBank)->chunk, chunk, + ((fxChunkSet *)bBank)->chunkSize); + return true; } fxProgram * GetProgram(int nProgNum); @@ -150,7 +162,7 @@ return NULL; return p->prgName; } - void SetProgramName(int nProgram, char *name = "") + void SetProgramName(int nProgram, const char *name = "") { fxProgram *p = GetProgram(nProgram); if (!p) @@ -229,9 +241,11 @@ virtual bool LoadBank(char *name); virtual bool SaveBank(char *name); - virtual long EffDispatch(long opCode, long index=0, long value=0, void *ptr=0, float opt=0.); + virtual long EffDispatch(long opCode, long index=0, long value=0, + void *ptr=0, float opt=0.); virtual void EffProcess(float **inputs, float **outputs, long sampleframes); - virtual void EffProcessReplacing(float **inputs, float **outputs, long sampleframes); + virtual void EffProcessReplacing(float **inputs, float **outputs, + long sampleframes); virtual void EffSetParameter(long index, float parameter); virtual float EffGetParameter(long index); @@ -241,82 +255,134 @@ long EffGetProgram() { return EffDispatch(effGetProgram); } void EffSetProgramName(char *ptr) { EffDispatch(effSetProgramName, 0, 0, ptr); } void EffGetProgramName(char *ptr) { EffDispatch(effGetProgramName, 0, 0, ptr); } - void EffGetParamLabel(long index, char *ptr) { EffDispatch(effGetParamLabel, index, 0, ptr); } - void EffGetParamDisplay(long index, char *ptr) { EffDispatch(effGetParamDisplay, index, 0, ptr); } - void EffGetParamName(long index, char *ptr) { EffDispatch(effGetParamName, index, 0, ptr); } - void EffSetSampleRate(float fSampleRate) { EffDispatch(effSetSampleRate, 0, 0, 0, fSampleRate); } + void EffGetParamLabel(long index, char *ptr) { + EffDispatch(effGetParamLabel, index, 0, ptr); } + void EffGetParamDisplay(long index, char *ptr) { + EffDispatch(effGetParamDisplay, index, 0, ptr); } + void EffGetParamName(long index, char *ptr) { + EffDispatch(effGetParamName, index, 0, ptr); } + void EffSetSampleRate(float fSampleRate) { + EffDispatch(effSetSampleRate, 0, 0, 0, fSampleRate); } void EffSetBlockSize(long value) { EffDispatch(effSetBlockSize, 0, value); } void EffMainsChanged(bool bOn) { EffDispatch(effMainsChanged, 0, bOn); } float EffGetVu() { return (float)EffDispatch(effGetVu) / (float)32767.; } - long EffEditGetRect(ERect **ptr) { return EffDispatch(effEditGetRect, 0, 0, ptr); } - long EffEditOpen(void *ptr) { long l = EffDispatch(effEditOpen, 0, 0, ptr); if (l > 0) bEditOpen = true; return l; } + long EffEditGetRect(ERect **ptr) { + return EffDispatch(effEditGetRect, 0, 0, ptr); } + long EffEditOpen(void *ptr) { long l = EffDispatch(effEditOpen, 0, 0, ptr); + if (l > 0) bEditOpen = true; return l; } void EffEditClose() { EffDispatch(effEditClose); bEditOpen = false; } void EffEditIdle() { if (bEditOpen) EffDispatch(effEditIdle); } #if MAC void EffEditDraw(void *ptr) { EffDispatch(nEffect, effEditDraw, 0, 0, ptr); } - long EffEditMouse(long index, long value) { return EffDispatch(nEffect, effEditMouse, index, value); } + long EffEditMouse(long index, long value) { + return EffDispatch(nEffect, effEditMouse, index, value); } long EffEditKey(long value) { return EffDispatch(effEditKey, 0, value); } void EffEditTop() { EffDispatch(effEditTop); } void EffEditSleep() { EffDispatch(effEditSleep); } #endif long EffIdentify() { return EffDispatch(effIdentify); } - long EffGetChunk(void **ptr, bool isPreset = false) { return EffDispatch(effGetChunk, isPreset, 0, ptr); } - long EffSetChunk(void *data, long byteSize, bool isPreset = false) { return EffDispatch(effSetChunk, isPreset, byteSize, data); } + long EffGetChunk(void **ptr, bool isPreset = false) { + return EffDispatch(effGetChunk, isPreset, 0, ptr); } + long EffSetChunk(void *data, long byteSize, bool isPreset = false) { + return EffDispatch(effSetChunk, isPreset, byteSize, data); } //VST 2.0 - long EffProcessEvents(VstEvents* ptr) { return EffDispatch(effProcessEvents, 0, 0, ptr); } - long EffCanBeAutomated(long index) { return EffDispatch(effCanBeAutomated, index); } - long EffString2Parameter(long index, char *ptr) { return EffDispatch(effString2Parameter, index, 0, ptr); } - long EffGetNumProgramCategories() { return EffDispatch(effGetNumProgramCategories); } - long EffGetProgramNameIndexed(long category, long index, char* text) { return EffDispatch(effGetProgramNameIndexed, index, category, text); } + long EffProcessEvents(VstEvents* ptr) { + return EffDispatch(effProcessEvents, 0, 0, ptr); } + long EffCanBeAutomated(long index) { + return EffDispatch(effCanBeAutomated, index); } + long EffString2Parameter(long index, char *ptr) { + return EffDispatch(effString2Parameter, index, 0, ptr); } + long EffGetNumProgramCategories() { + return EffDispatch(effGetNumProgramCategories); } + long EffGetProgramNameIndexed(long category, long index, char* text) { + return EffDispatch(effGetProgramNameIndexed, index, category, text); } long EffCopyProgram(long index) { return EffDispatch(effCopyProgram, index); } - long EffConnectInput(long index, bool state) { return EffDispatch(effConnectInput, index, state); } - long EffConnectOutput(long index, bool state) { return EffDispatch(effConnectOutput, index, state); } - long EffGetInputProperties(long index, VstPinProperties *ptr) { return EffDispatch(effGetInputProperties, index, 0, ptr); } - long EffGetOutputProperties(long index, VstPinProperties *ptr) { return EffDispatch(effGetOutputProperties, index, 0, ptr); } + long EffConnectInput(long index, bool state) { + return EffDispatch(effConnectInput, index, state); } + long EffConnectOutput(long index, bool state) { + return EffDispatch(effConnectOutput, index, state); } + long EffGetInputProperties(long index, VstPinProperties *ptr) { + return EffDispatch(effGetInputProperties, index, 0, ptr); } + long EffGetOutputProperties(long index, VstPinProperties *ptr) { + return EffDispatch(effGetOutputProperties, index, 0, ptr); } long EffGetPlugCategory() { return EffDispatch(effGetPlugCategory); } long EffGetCurrentPosition() { return EffDispatch(effGetCurrentPosition); } long EffGetDestinationBuffer() { return EffDispatch(effGetDestinationBuffer); } - long EffOfflineNotify(VstAudioFile* ptr, long numAudioFiles, bool start) { return EffDispatch(effOfflineNotify, start, numAudioFiles, ptr); } - long EffOfflinePrepare(VstOfflineTask *ptr, long count) { return EffDispatch(effOfflinePrepare, 0, count, ptr); } - long EffOfflineRun(VstOfflineTask *ptr, long count) { return EffDispatch(effOfflineRun, 0, count, ptr); } - long EffProcessVarIo(VstVariableIo* varIo) { return EffDispatch(effProcessVarIo, 0, 0, varIo); } - long EffSetSpeakerArrangement(VstSpeakerArrangement* pluginInput, VstSpeakerArrangement* pluginOutput) { return EffDispatch(effSetSpeakerArrangement, 0, (long)pluginInput, pluginOutput); } - long EffSetBlockSizeAndSampleRate(long blockSize, float sampleRate) { return EffDispatch(effSetBlockSizeAndSampleRate, 0, blockSize, 0, sampleRate); } + long EffOfflineNotify(VstAudioFile* ptr, long numAudioFiles, bool start) { + return EffDispatch(effOfflineNotify, start, numAudioFiles, ptr); } + long EffOfflinePrepare(VstOfflineTask *ptr, long count) { + return EffDispatch(effOfflinePrepare, 0, count, ptr); } + long EffOfflineRun(VstOfflineTask *ptr, long count) { + return EffDispatch(effOfflineRun, 0, count, ptr); } + long EffProcessVarIo(VstVariableIo* varIo) { + return EffDispatch(effProcessVarIo, 0, 0, varIo); } + long EffSetSpeakerArrangement(VstSpeakerArrangement* pluginInput, + VstSpeakerArrangement* pluginOutput) { + return EffDispatch(effSetSpeakerArrangement, 0, (long)pluginInput, + pluginOutput); } + long EffSetBlockSizeAndSampleRate(long blockSize, float sampleRate) { + return EffDispatch(effSetBlockSizeAndSampleRate, 0, blockSize, + 0, sampleRate); } long EffSetBypass(bool onOff) { return EffDispatch(effSetBypass, 0, onOff); } - long EffGetEffectName(char *ptr) { return EffDispatch(effGetEffectName, 0, 0, ptr); } - long EffGetErrorText(char *ptr) { return EffDispatch(effGetErrorText, 0, 0, ptr); } - long EffGetVendorString(char *ptr) { return EffDispatch(effGetVendorString, 0, 0, ptr); } - long EffGetProductString(char *ptr) { return EffDispatch(effGetProductString, 0, 0, ptr); } + long EffGetEffectName(char *ptr) { + return EffDispatch(effGetEffectName, 0, 0, ptr); } + long EffGetErrorText(char *ptr) { + return EffDispatch(effGetErrorText, 0, 0, ptr); } + long EffGetVendorString(char *ptr) { + return EffDispatch(effGetVendorString, 0, 0, ptr); } + long EffGetProductString(char *ptr) { + return EffDispatch(effGetProductString, 0, 0, ptr); } long EffGetVendorVersion() { return EffDispatch(effGetVendorVersion); } - long EffVendorSpecific(long index, long value, void *ptr, float opt) { return EffDispatch(effVendorSpecific, index, value, ptr, opt); } - long EffCanDo(const char *ptr) { return EffDispatch(effCanDo, 0, 0, (void *)ptr); } + long EffVendorSpecific(long index, long value, void *ptr, float opt) { + return EffDispatch(effVendorSpecific, index, value, ptr, opt); } + long EffCanDo(const char *ptr) { + return EffDispatch(effCanDo, 0, 0, (void *)ptr); } long EffGetTailSize() { return EffDispatch(effGetTailSize); } long EffIdle() { if (bNeedIdle) return EffDispatch(effIdle); else return 0; } long EffGetIcon() { return EffDispatch(effGetIcon); } - long EffSetViewPosition(long x, long y) { return EffDispatch(effSetViewPosition, x, y); } - long EffGetParameterProperties(long index, VstParameterProperties* ptr) { return EffDispatch(effGetParameterProperties, index, 0, ptr); } + long EffSetViewPosition(long x, long y) { + return EffDispatch(effSetViewPosition, x, y); } + long EffGetParameterProperties(long index, VstParameterProperties* ptr) { + return EffDispatch(effGetParameterProperties, index, 0, ptr); } long EffKeysRequired() { return EffDispatch(effKeysRequired); } long EffGetVstVersion() { return EffDispatch(effGetVstVersion); } //VST 2.1 extensions - long EffKeyDown(VstKeyCode &keyCode) { return EffDispatch(effEditKeyDown, keyCode.character, keyCode.virt, 0, keyCode.modifier); } - long EffKeyUp(VstKeyCode &keyCode) { return EffDispatch(effEditKeyUp, keyCode.character, keyCode.virt, 0, keyCode.modifier); } + long EffKeyDown(VstKeyCode &keyCode) { + return EffDispatch(effEditKeyDown, keyCode.character, keyCode.virt, + 0, keyCode.modifier); } + long EffKeyUp(VstKeyCode &keyCode) { + return EffDispatch(effEditKeyUp, keyCode.character, keyCode.virt, + 0, keyCode.modifier); } void EffSetKnobMode(long value) { EffDispatch(effSetEditKnobMode, 0, value); } - long EffGetMidiProgramName(long channel, MidiProgramName* midiProgramName) { return EffDispatch(effGetMidiProgramName, channel, 0, midiProgramName); } - long EffGetCurrentMidiProgram (long channel, MidiProgramName* currentProgram) { return EffDispatch(effGetCurrentMidiProgram, channel, 0, currentProgram); } - long EffGetMidiProgramCategory (long channel, MidiProgramCategory* category) { return EffDispatch(effGetMidiProgramCategory, channel, 0, category); } - long EffHasMidiProgramsChanged (long channel) { return EffDispatch(effHasMidiProgramsChanged, channel); } - long EffGetMidiKeyName(long channel, MidiKeyName* keyName) { return EffDispatch(effGetMidiKeyName, channel, 0, keyName); } + long EffGetMidiProgramName(long channel, MidiProgramName* midiProgramName) { + return EffDispatch(effGetMidiProgramName, channel, 0, midiProgramName); } + long EffGetCurrentMidiProgram (long channel, MidiProgramName* currentProgram) { + return EffDispatch(effGetCurrentMidiProgram, channel, 0, currentProgram); } + long EffGetMidiProgramCategory (long channel, MidiProgramCategory* category) { + return EffDispatch(effGetMidiProgramCategory, channel, 0, category); } + long EffHasMidiProgramsChanged (long channel) { + return EffDispatch(effHasMidiProgramsChanged, channel); } + long EffGetMidiKeyName(long channel, MidiKeyName* keyName) { + return EffDispatch(effGetMidiKeyName, channel, 0, keyName); } long EffBeginSetProgram() { return EffDispatch(effBeginSetProgram); } long EffEndSetProgram() { return EffDispatch(effEndSetProgram); } // VST 2.3 Extensions - long EffGetSpeakerArrangement(VstSpeakerArrangement** pluginInput, VstSpeakerArrangement** pluginOutput) {EffDispatch(effGetSpeakerArrangement, 0, (long)pluginInput, pluginOutput); } - long EffSetTotalSampleToProcess (long value) { return EffDispatch(effSetTotalSampleToProcess, 0, value); } - long EffGetNextShellPlugin(char *name) { return EffDispatch(effShellGetNextPlugin, 0, 0, name); } + long EffGetSpeakerArrangement(VstSpeakerArrangement** pluginInput, + VstSpeakerArrangement** pluginOutput) { + EffDispatch(effGetSpeakerArrangement, 0, (long)pluginInput, + pluginOutput); } + long EffSetTotalSampleToProcess (long value) { + return EffDispatch(effSetTotalSampleToProcess, 0, value); } + long EffGetNextShellPlugin(char *name) { + return EffDispatch(effShellGetNextPlugin, 0, 0, name); } long EffStartProcess() { return EffDispatch(effStartProcess); } long EffStopProcess() { return EffDispatch(effStopProcess); } - long EffSetPanLaw(long type, float val) { return EffDispatch(effSetPanLaw, 0, type, 0, val); } - long EffBeginLoadBank(VstPatchChunkInfo* ptr) { return EffDispatch(effBeginLoadBank, 0, 0, ptr); } - long EffBeginLoadProgram(VstPatchChunkInfo* ptr) { return EffDispatch(effBeginLoadProgram, 0, 0, ptr); } + long EffSetPanLaw(long type, float val) { + return EffDispatch(effSetPanLaw, 0, type, 0, val); } + long EffBeginLoadBank(VstPatchChunkInfo* ptr) { + return EffDispatch(effBeginLoadBank, 0, 0, ptr); } + long EffBeginLoadProgram(VstPatchChunkInfo* ptr) { + return EffDispatch(effBeginLoadProgram, 0, 0, ptr); } // overridables public: @@ -347,21 +413,28 @@ void **aEffects; static CVSTHost * pHost; - static long VSTCALLBACK AudioMasterCallback(AEffect *effect, long opcode, long index, long value, void *ptr, float opt); + static long VSTCALLBACK AudioMasterCallback(AEffect *effect, long opcode, + long index, long value, + void *ptr, float opt); int Search(AEffect *pEffect); int GetPreviousPlugIn(int nEffect); int GetNextPlugIn(int nEffect); - long EffDispatch(int nEffect, long opCode, long index=0, long value=0, void *ptr=0, float opt=0.); + long EffDispatch(int nEffect, long opCode, long index=0, long value=0, + void *ptr=0, float opt=0.); public: int LoadPlugin(const char * lpszName); int GetSize() { return naEffects; } - CEffect *GetAt(int nIndex) { if ((nIndex >= 0) && (nIndex < naEffects)) return (CEffect *)aEffects[nIndex]; else return 0; } + CEffect *GetAt(int nIndex) { + if ((nIndex >= 0) && (nIndex < naEffects)) + return (CEffect *)aEffects[nIndex]; else return 0; } void RemoveAt(int nIndex); void RemoveAll(); - void EffProcess(int nEffect, float **inputs, float **outputs, long sampleframes); - void EffProcessReplacing(int nEffect, float **inputs, float **outputs, long sampleframes); + void EffProcess(int nEffect, float **inputs, float **outputs, + long sampleframes); + void EffProcessReplacing(int nEffect, float **inputs, float **outputs, + long sampleframes); void EffSetParameter(int nEffect, long index, float parameter); float EffGetParameter(int nEffect, long index); @@ -372,7 +445,8 @@ void EffSetProgram(int nEffect, long lValue) { if (GetAt(nEffect)) GetAt(nEffect)->EffSetProgram(lValue); } long EffGetProgram(int nEffect) - { if (GetAt(nEffect)) return (GetAt(nEffect))->EffGetProgram(); else return 0; } + { if (GetAt(nEffect)) return (GetAt(nEffect))->EffGetProgram(); + else return 0; } void EffSetProgramName(int nEffect, char *ptr) { if (GetAt(nEffect)) GetAt(nEffect)->EffSetProgramName(ptr); } void EffGetProgramName(int nEffect, char *ptr) @@ -392,9 +466,11 @@ float EffGetVu(int nEffect) { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVu(); else return 0.f; } long EffEditGetRect(int nEffect, ERect **ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditGetRect(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditGetRect(ptr); + else return 0; } long EffEditOpen(int nEffect, void *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditOpen(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditOpen(ptr); + else return 0; } void EffEditClose(int nEffect) { if (GetAt(nEffect)) GetAt(nEffect)->EffEditClose(); } void EffEditIdle(int nEffect) @@ -403,9 +479,11 @@ void EffEditDraw(int nEffect, void *ptr) { if (GetAt(nEffect)) GetAt(nEffect)->EffEditDraw(ptr); } long EffEditMouse(int nEffect, long index, long value) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditMouse(index, value); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditMouse(index, value); + else return 0; } long EffEditKey(int nEffect, long value) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditKey(value); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffEditKey(value); + else return 0; } void EffEditTop(int nEffect) { if (GetAt(nEffect)) GetAt(nEffect)->EffEditTop(); } void EffEditSleep(int nEffect) @@ -414,116 +492,197 @@ long EffIdentify(int nEffect) { if (GetAt(nEffect)) return GetAt(nEffect)->EffIdentify(); else return 0; } long EffGetChunk(int nEffect, void **ptr, bool isPreset = false) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetChunk(ptr, isPreset); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetChunk(ptr, isPreset); + else return 0; } long EffSetChunk(int nEffect, void *data, long byteSize, bool isPreset = false) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetChunk(data, byteSize, isPreset); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffSetChunk(data, byteSize, isPreset); + else return 0; } // VST 2.0 long EffProcessEvents(int nEffect, VstEvents* ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffProcessEvents(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffProcessEvents(ptr); + else return 0; } long EffCanBeAutomated(int nEffect, long index) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffCanBeAutomated(index); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffCanBeAutomated(index); + else return 0; } long EffString2Parameter(int nEffect, long index, char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffString2Parameter(index, ptr); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffString2Parameter(index, ptr); else return 0; } long EffGetNumProgramCategories(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetNumProgramCategories(); else return 0; } - long EffGetProgramNameIndexed(int nEffect, long category, long index, char* text) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetProgramNameIndexed(category, index, text); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetNumProgramCategories(); + else return 0; } + long EffGetProgramNameIndexed(int nEffect, long category, long index, + char* text) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetProgramNameIndexed(category, index, text); + else return 0; } long EffCopyProgram(int nEffect, long index) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffCopyProgram(index); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffCopyProgram(index); + else return 0; } long EffConnectInput(int nEffect, long index, bool state) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffConnectInput(index, state); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffConnectInput(index, state); + else return 0; } long EffConnectOutput(int nEffect, long index, bool state) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffConnectOutput(index, state); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffConnectOutput(index, state); + else return 0; } long EffGetInputProperties(int nEffect, long index, VstPinProperties *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetInputProperties(index, ptr); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetInputProperties(index, ptr); else return 0; } long EffGetOutputProperties(int nEffect, long index, VstPinProperties *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetOutputProperties(index, ptr); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetOutputProperties(index, ptr); + else return 0; } long EffGetPlugCategory(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetPlugCategory(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetPlugCategory(); + else return 0; } long EffGetCurrentPosition(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetCurrentPosition(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetCurrentPosition(); + else return 0; } long EffGetDestinationBuffer(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetDestinationBuffer(); else return 0; } - long EffOfflineNotify(int nEffect, VstAudioFile* ptr, long numAudioFiles, bool start) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffOfflineNotify(ptr, numAudioFiles, start); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetDestinationBuffer(); + else return 0; } + long EffOfflineNotify(int nEffect, VstAudioFile* ptr, + long numAudioFiles, bool start) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffOfflineNotify(ptr, numAudioFiles, start); + else return 0; } long EffOfflinePrepare(int nEffect, VstOfflineTask *ptr, long count) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffOfflinePrepare(ptr, count); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffOfflinePrepare(ptr, count); else return 0; } long EffOfflineRun(int nEffect, VstOfflineTask *ptr, long count) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffOfflineRun(ptr, count); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffOfflineRun(ptr, count); else return 0; } long EffProcessVarIo(int nEffect, VstVariableIo* varIo) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffProcessVarIo(varIo); else return 0; } - long EffSetSpeakerArrangement(int nEffect, VstSpeakerArrangement* pluginInput, VstSpeakerArrangement* pluginOutput) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetSpeakerArrangement(pluginInput, pluginOutput); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffProcessVarIo(varIo); + else return 0; } + long EffSetSpeakerArrangement(int nEffect, VstSpeakerArrangement* pluginInput, + VstSpeakerArrangement* pluginOutput) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffSetSpeakerArrangement(pluginInput, + pluginOutput); + else return 0; } long EffSetBlockSizeAndSampleRate(int nEffect, long blockSize, float sampleRate) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetBlockSizeAndSampleRate(blockSize, sampleRate); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffSetBlockSizeAndSampleRate(blockSize, + sampleRate); + else return 0; } long EffSetBypass(int nEffect, bool onOff) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetBypass(onOff); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetBypass(onOff); + else return 0; } long EffGetEffectName(int nEffect, char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetEffectName(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetEffectName(ptr); + else return 0; } long EffGetErrorText(int nEffect, char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetErrorText(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetErrorText(ptr); + else return 0; } long EffGetVendorString(int nEffect, char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVendorString(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVendorString(ptr); + else return 0; } long EffGetProductString(int nEffect, char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetProductString(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetProductString(ptr); + else return 0; } long EffGetVendorVersion(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVendorVersion(); else return 0; } - long EffVendorSpecific(int nEffect, long index, long value, void *ptr, float opt) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffVendorSpecific(index, value, ptr, opt); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVendorVersion(); + else return 0; } + long EffVendorSpecific(int nEffect, long index, long value, + void *ptr, float opt) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffVendorSpecific(index, value, ptr, opt); + else return 0; } long EffCanDo(int nEffect, const char *ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffCanDo(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffCanDo(ptr); + else return 0; } long EffGetTailSize(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetTailSize(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetTailSize(); + else return 0; } long EffIdle(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffIdle(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffIdle(); + else return 0; } long EffGetIcon(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetIcon(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetIcon(); + else return 0; } long EffSetViewPosition(int nEffect, long x, long y) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetViewPosition(x, y); else return 0; } - long EffGetParameterProperties(int nEffect, long index, VstParameterProperties* ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetParameterProperties(index, ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetViewPosition(x, y); + else return 0; } + long EffGetParameterProperties(int nEffect, long index, + VstParameterProperties* ptr) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetParameterProperties(index, ptr); + else return 0; } long EffKeysRequired(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeysRequired(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeysRequired(); + else return 0; } long EffGetVstVersion(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVstVersion(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetVstVersion(); + else return 0; } // VST 2.1 extensions long EffKeyDown(int nEffect, VstKeyCode &keyCode) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeyDown(keyCode); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeyDown(keyCode); + else return 0; } long EffKeyUp(int nEffect, VstKeyCode &keyCode) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeyUp(keyCode); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffKeyUp(keyCode); + else return 0; } void EffSetKnobMode(int nEffect, long value) { if (GetAt(nEffect)) GetAt(nEffect)->EffSetKnobMode(value); } - long EffGetMidiProgramName(int nEffect, long channel, MidiProgramName* midiProgramName) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetMidiProgramName(channel, midiProgramName); else return 0; } - long EffGetCurrentMidiProgram(int nEffect, long channel, MidiProgramName* currentProgram) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetCurrentMidiProgram(channel, currentProgram); else return 0; } - long EffGetMidiProgramCategory(int nEffect, long channel, MidiProgramCategory* category) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetMidiProgramCategory(channel, category); else return 0; } + long EffGetMidiProgramName(int nEffect, long channel, + MidiProgramName* midiProgramName) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetMidiProgramName(channel, midiProgramName); + else return 0; } + long EffGetCurrentMidiProgram(int nEffect, long channel, + MidiProgramName* currentProgram) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetCurrentMidiProgram(channel, currentProgram); + else return 0; } + long EffGetMidiProgramCategory(int nEffect, long channel, + MidiProgramCategory* category) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetMidiProgramCategory(channel, category); + else return 0; } long EffHasMidiProgramsChanged(int nEffect, long channel) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffHasMidiProgramsChanged(channel); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffHasMidiProgramsChanged(channel); + else return 0; } long EffGetMidiKeyName(int nEffect, long channel, MidiKeyName* keyName) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetMidiKeyName(channel, keyName); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetMidiKeyName(channel, keyName); + else return 0; } long EffBeginSetProgram(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginSetProgram(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginSetProgram(); + else return 0; } long EffEndSetProgram(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginSetProgram(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginSetProgram(); + else return 0; } // VST 2.3 Extensions - long EffGetSpeakerArrangement(int nEffect, VstSpeakerArrangement** pluginInput, VstSpeakerArrangement** pluginOutput) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetSpeakerArrangement(pluginInput, pluginOutput); else return 0; } + long EffGetSpeakerArrangement(int nEffect, + VstSpeakerArrangement** pluginInput, + VstSpeakerArrangement** pluginOutput) + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffGetSpeakerArrangement(pluginInput, + pluginOutput); + else return 0; } long EffSetTotalSampleToProcess(int nEffect, long value) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetTotalSampleToProcess(value); else return 0; } + { if (GetAt(nEffect)) + return GetAt(nEffect)->EffSetTotalSampleToProcess(value); + else return 0; } long EffGetNextShellPlugin(int nEffect, char *name) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetNextShellPlugin(name); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffGetNextShellPlugin(name); + else return 0; } long EffStartProcess(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffStartProcess(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffStartProcess(); + else return 0; } long EffStopProcess(int nEffect) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffStopProcess(); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffStopProcess(); + else return 0; } long EffSetPanLaw(int nEffect, long type, float val) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetPanLaw(type, val); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffSetPanLaw(type, val); + else return 0; } long EffBeginLoadBank(int nEffect, VstPatchChunkInfo* ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginLoadBank(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginLoadBank(ptr); + else return 0; } long EffBeginLoadProgram(int nEffect, VstPatchChunkInfo* ptr) - { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginLoadProgram(ptr); else return 0; } + { if (GetAt(nEffect)) return GetAt(nEffect)->EffBeginLoadProgram(ptr); + else return 0; } // overridable functions public: @@ -531,16 +690,27 @@ virtual void SetSampleRate(float fSampleRate=44100.); virtual void SetBlockSize(long lSize=1024); virtual void Process(float **inputs, float **outputs, long sampleframes); - virtual void ProcessReplacing(float **inputs, float **outputs, long sampleframes); + virtual void ProcessReplacing(float **inputs, float **outputs, + long sampleframes); - virtual bool OnGetVendorString(char *text) { strcpy(text, "Seib"); return true; } // forgive this little vanity :-) + virtual bool OnGetVendorString(char *text) { + strcpy(text, "Seib"); return true; } // forgive this little vanity :-) virtual long OnGetHostVendorVersion() { return 1; } - virtual bool OnGetProductString(char *text) { strcpy(text, "Default CVSTHost"); return true; } - virtual bool OnGetSpeakerArrangement(int nEffect, VstSpeakerArrangement* pluginInput, VstSpeakerArrangement* pluginOutput) { return false; } + virtual bool OnGetProductString(char *text) { + strcpy(text, "Default CVSTHost"); return true; } + virtual bool OnGetSpeakerArrangement(int nEffect, + VstSpeakerArrangement* pluginInput, + VstSpeakerArrangement* pluginOutput) { + return false; } virtual void OnSetOutputSampleRate(int nEffect, float sampleRate) { } - virtual bool OnOfflineStart(int nEffect, VstAudioFile* audioFiles, long numAudioFiles, long numNewAudioFiles) { return false; } - virtual bool OnOfflineRead(int nEffect, VstOfflineTask* offline, VstOfflineOption option, bool readSource) { return false; } - virtual bool OnOfflineWrite(int nEffect, VstOfflineTask* offline, VstOfflineOption option) { return false; } + virtual bool OnOfflineStart(int nEffect, VstAudioFile* audioFiles, + long numAudioFiles, long numNewAudioFiles) { + return false; } + virtual bool OnOfflineRead(int nEffect, VstOfflineTask* offline, + VstOfflineOption option, bool readSource) { + return false; } + virtual bool OnOfflineWrite(int nEffect, VstOfflineTask* offline, + VstOfflineOption option) { return false; } virtual long OnOfflineGetCurrentPass(int nEffect) { return 0; } virtual long OnOfflineGetCurrentMetaPass(int nEffect) { return 0; } virtual long OnGetAutomationState(int nEffect) { return 0; } @@ -553,21 +723,25 @@ virtual void OnUpdateSampleRate(int nEffect); virtual bool OnSizeWindow(int nEffect, long width, long height); virtual bool OnNeedIdle(int nEffect); - virtual long OnAudioMasterCallback(int nEffect, long opcode, long index, long value, void *ptr, float opt); + virtual long OnAudioMasterCallback(int nEffect, long opcode, long index, + long value, void *ptr, float opt); virtual long OnGetVersion(int nEffect); virtual bool OnCanDo(const char *ptr); virtual bool OnWantEvents(int nEffect, long filter); virtual long OnIdle(int nEffect=-1); virtual bool OnInputConnected(int nEffect, long input) { return true; } virtual bool OnOutputConnected(int nEffect, long output) { return true; } - virtual bool OnSetParameterAutomated(int nEffect, long index, float value) { return false; } + virtual bool OnSetParameterAutomated(int nEffect, long index, float value) { + return false; } virtual bool OnProcessEvents(int nEffect, VstEvents* events) { return false; } virtual VstTimeInfo *OnGetTime(int nEffect) { return &vstTimeInfo; } - virtual bool OnSetTime(int nEffect, long filter, VstTimeInfo *timeInfo) { return false; } + virtual bool OnSetTime(int nEffect, long filter, VstTimeInfo *timeInfo) { + return false; } virtual long OnGetNumAutomatableParameters(int nEffect) { return 0; } virtual long OnGetParameterQuantization(int nEffect) { return 0x40000000; } virtual bool OnIoChanged(int nEffect) { return false; } - virtual long OnHostVendorSpecific(int nEffect, long lArg1, long lArg2, void* ptrArg, float floatArg) { return 0; } + virtual long OnHostVendorSpecific(int nEffect, long lArg1, long lArg2, + void* ptrArg, float floatArg) { return 0; } virtual long OnGetHostLanguage() { return 0; } virtual void * OnOpenWindow(int nEffect, VstWindow* window) { return 0; } virtual bool OnCloseWindow(int nEffect, VstWindow* window) { return false; } @@ -576,14 +750,16 @@ // VST 2.1 Extensions virtual bool OnBeginEdit(int nEffect) { return false; } virtual bool OnEndEdit(int nEffect) { return false; } - virtual bool OnOpenFileSelector (int nEffect, VstFileSelect *ptr) { return false; } + virtual bool OnOpenFileSelector (int nEffect, VstFileSelect *ptr) { + return false; } // VST 2.2 Extensions - virtual bool OnCloseFileSelector (int nEffect, VstFileSelect *ptr) { return false; } + virtual bool OnCloseFileSelector (int nEffect, VstFileSelect *ptr) { + return false; } virtual bool OnEditFile(int nEffect, char *ptr) { return false; } virtual bool OnGetChunkFile(int nEffect, void * nativePath) { return false; } // VST 2.3 Extensions - virtual VstSpeakerArrangement *OnGetInputSpeakerArrangement(int nEffect) { return 0; } + virtual VstSpeakerArrangement *OnGetInputSpeakerArrangement(int nEffect) { + return 0; } }; */ #endif - diff -Nru csound-5.17.11~dfsg/Opcodes/vst4cs/src/vst4cs.cpp csound-6.02~dfsg/Opcodes/vst4cs/src/vst4cs.cpp --- csound-5.17.11~dfsg/Opcodes/vst4cs/src/vst4cs.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vst4cs/src/vst4cs.cpp 2014-01-07 16:54:20.000000000 +0000 @@ -35,7 +35,20 @@ #include "vsthost.h" #include "fxbank.h" -#include "InOut/widglobals.h" //gab +// These two collections replace similar ones that used to be in widglobals.h. + +std::vector &vstPlugEditors() +{ + static std::vector vstPlugEditors_; + return vstPlugEditors_; +} + +std::vector &vstPlugins() +{ + static std::vector vstPlugins_; + return vstPlugins_; +} + extern "C" { std::string version = "0.2beta"; @@ -43,23 +56,28 @@ static void path_convert(char *in); #endif + static MYFLT getCurrentTime(CSOUND *csound) + { + return csound->GetCurrentTimeSamples(csound) / csound->GetSr(csound); + } + static int vstinit(CSOUND *csound, void *data) { VSTINIT *p = (VSTINIT *) data; VSTPlugin *plugin = new VSTPlugin(csound); - - *p->iVSThandle = (MYFLT) ST(vstPlugins).size(); - ST(vstPlugins).push_back(plugin); - if ((int) ST(vstPlugins).size() == 1) { - plugin->Log("=============================================================\n"); - plugin->Log("vst4cs version %s by Andres Cabrera and Michael Gogins\n", version.c_str()); + *p->iVSThandle = (MYFLT) vstPlugins().size(); + vstPlugins().push_back(plugin); + if ((int) vstPlugins().size() == 1) { + plugin->Log("============================================================\n"); + plugin->Log("vst4cs version %s by Andres Cabrera and Michael Gogins\n", + version.c_str()); plugin->Log("Using code from H. Seib's VstHost and T. Grill's vst~ object\n"); plugin->Log("VST is a trademark of Steinberg Media Technologies GmbH\n"); plugin->Log("VST Plug-In Technology by Steinberg\n"); - plugin->Log("=============================================================\n"); + plugin->Log("============================================================\n"); } - char vstplugname[0x100]; - strcpy(vstplugname, (char *) p->iplugin); + char vstplugname[0x100]; + strncpy(vstplugname,((STRINGDAT *)p->iplugin)->data, MAXNAME-1); #if WIN32 path_convert(vstplugname); #endif @@ -76,8 +94,7 @@ static int vstinfo(CSOUND *csound, void *data) { VSTINFO *p = (VSTINFO *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->Info(); return OK; } @@ -89,18 +106,12 @@ p->opcodeInChannels = (size_t) (csound->GetInputArgCnt(data) - 1); if (p->opcodeInChannels > 32) csound->InitError(csound, "vstaudio: too many input args"); - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - // if (!plugin) { - // csound->InitError(csound, "vstaudio_init: invalid plugin pointer!"); - // return NOTOK; - // } - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->Debug("vstaudio_init.\n"); - p->framesPerBlock = csound->ksmps; + p->framesPerBlock = csound->GetKsmps(csound); p->pluginInChannels = (size_t) plugin->getNumInputs(); p->pluginOutChannels = (size_t) plugin->getNumOutputs(); p->opcodeOutChannels = (size_t) csound->GetOutputArgCnt(data); - return OK; } @@ -108,31 +119,34 @@ { VSTAUDIO *p = (VSTAUDIO *) data; size_t i, j; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; + uint32_t offset = p->h.insdshead->ksmps_offset; + for(j=0; j < p->pluginOutChannels; j++) + memset(p->aouts[j], '\0', offset*sizeof(MYFLT)); // plugin->Debug("vstaudio: plugin %x.\n", plugin); if (!p->h.insdshead->nxtact) { for (j = 0; j < p->pluginInChannels && j < p->opcodeInChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) + for (i = offset; i < p->framesPerBlock; i++) plugin->inputs_[j][i] = - (float) (p->ains[j][i] * csound->dbfs_to_float); + (float) (p->ains[j][i] / csound->Get0dBFS(csound)); for ( ; j < p->pluginInChannels; j++) for (i = 0; i < p->framesPerBlock; i++) plugin->inputs_[j][i] = 0.0f; for (j = 0; j < p->pluginOutChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) + for (i = offset; i < p->framesPerBlock; i++) plugin->outputs_[j][i] = 0.0f; plugin->process(&plugin->inputs.front(), &plugin->outputs.front(), p->framesPerBlock); for (j = 0; j < p->pluginOutChannels && j < p->opcodeOutChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) - p->aouts[j][i] = (MYFLT) plugin->outputs_[j][i] * csound->e0dbfs; + for (i = offset; i < p->framesPerBlock; i++) + p->aouts[j][i] = (MYFLT) plugin->outputs_[j][i] * csound->Get0dBFS(csound); for ( ; j < p->opcodeOutChannels; j++) for (i = 0; i < p->framesPerBlock; i++) p->aouts[j][i] = FL(0.0); } else { for (j = 0; j < p->opcodeInChannels && j < p->opcodeOutChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) + for (i = offset; i < p->framesPerBlock; i++) p->aouts[j][i] = p->ains[j][i]; for ( ; j < p->opcodeOutChannels; j++) for (i = 0; i < p->framesPerBlock; i++) @@ -145,93 +159,40 @@ { VSTAUDIO *p = (VSTAUDIO *) data; size_t i, j; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - // plugin->Debug("vstaudio: plugin %x.\n", plugin); + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; + uint32_t offset = p->h.insdshead->ksmps_offset; + for(j=0; j < p->pluginOutChannels; j++) + memset(p->aouts[j], '\0', offset*sizeof(MYFLT)); for (j = 0; j < p->pluginInChannels && j < p->opcodeInChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) + for (i = offset; i < p->framesPerBlock; i++) plugin->inputs_[j][i] = - (float) (p->ains[j][i] * csound->dbfs_to_float); + (float) (p->ains[j][i] / csound->Get0dBFS(csound)); for ( ; j < p->pluginInChannels; j++) for (i = 0; i < p->framesPerBlock; i++) plugin->inputs_[j][i] = 0.0f; for (j = 0; j < p->pluginOutChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) + for (i = offset; i < p->framesPerBlock; i++) plugin->outputs_[j][i] = 0.0f; plugin->process(&plugin->inputs.front(), &plugin->outputs.front(), p->framesPerBlock); for (j = 0; j < p->pluginOutChannels && j < p->opcodeOutChannels; j++) - for (i = 0; i < p->framesPerBlock; i++) - p->aouts[j][i] = (MYFLT) plugin->outputs_[j][i] * csound->e0dbfs; + for (i = offset; i < p->framesPerBlock; i++) + p->aouts[j][i] = (MYFLT) plugin->outputs_[j][i] * csound->Get0dBFS(csound); for ( ; j < p->opcodeOutChannels; j++) for (i = 0; i < p->framesPerBlock; i++) p->aouts[j][i] = FL(0.0); - return OK; } - //~ static int vstnote_init(CSOUND *csound, void *data) - //~ { - //~ VSTNOTE *p = (VSTNOTE *) data; - //~ p->vstHandle = (size_t) *p->iVSThandle; - //~ VSTPlugin *vstPlugin = ST(vstPlugins)[p->vstHandle]; - - //~ int rounded = (int) ((double) *p->knote + 0.5); - //~ int cents = (int) (((double) *p->knote - (double) rounded) * 100.0 - //~ + 100.5) - 100; - //~ int veloc = (int) *p->kveloc; - //~ double deltaTime = - //~ ((double) p->h.insdshead->p2 + csound->timeOffs) - csound->curTime; - //~ int deltaFrames = - //~ (int) (deltaTime * (double) vstPlugin->framesPerSecond - //~ + (deltaTime < 0.0 ? -0.5 : 0.5)); - //~ long framesRemaining = - //~ (long) ((double) *p->kdur * (double) vstPlugin->framesPerSecond + 0.5) - //~ + (long) deltaFrames; - - //~ p->chn = (int) *p->kchan & 15; - //~ p->note = (rounded >= 0 ? (rounded < 128 ? rounded : 127) : 0); - //~ veloc = (veloc >= 0 ? (veloc < 128 ? veloc : 127) : 0); - //~ if (deltaFrames < 0) - //~ deltaFrames = 0; - //~ else if (deltaFrames >= (int) vstPlugin->framesPerBlock) - //~ deltaFrames = (int) vstPlugin->framesPerBlock - 1; - //~ if (framesRemaining < 0L) - //~ framesRemaining = 0L; - //~ p->framesRemaining = (size_t) framesRemaining; - - //~ vstPlugin->Debug("vstnote_init\n"); - //~ vstPlugin->AddMIDI(144 | p->chn | (p->note << 8) | (veloc << 16), - //~ deltaFrames, cents); - - //~ return OK; - //~ } - - //~ static int vstnote(CSOUND *csound, void *data) - //~ { - //~ VSTNOTE *p = (VSTNOTE *) data; - - //~ if (p->framesRemaining >= (size_t) csound->ksmps) { - //~ p->framesRemaining -= (size_t) csound->ksmps; - //~ return OK; - //~ } - - //~ VSTPlugin *plugin = ST(vstPlugins)[p->vstHandle]; - //~ plugin->Debug("vstnote.\n"); - //~ plugin->AddMIDI(128 | p->chn | (p->note << 8), (int) p->framesRemaining, 0); - //~ p->framesRemaining = 0; /* ~((size_t) 0); */ - //~ return OK; - //~ } static int vstmidiout_init(CSOUND *csound, void *data) { VSTMIDIOUT *p = (VSTMIDIOUT *) data; VSTPlugin *plugin; - p->vstHandle = (size_t) *p->iVSThandle; - plugin = ST(vstPlugins)[p->vstHandle]; + plugin = vstPlugins()[p->vstHandle]; plugin->Debug("vstmidiout_init.\n"); p->prvMidiData = 0; - return OK; } @@ -240,7 +201,6 @@ VSTMIDIOUT *p = (VSTMIDIOUT *) data; VSTPlugin *plugin; int st, ch, d1, d2, midiData; - st = (int) *(p->kstatus); if (st < 128 || st >= 240) { p->prvMidiData = 0; @@ -263,19 +223,17 @@ d2 = 0; d1 = (d1 >= 0 ? (d1 < 128 ? d1 : 127) : 0); midiData = st | ch | (d1 << 8) | (d2 << 16); - if (midiData == p->prvMidiData) return OK; - p->prvMidiData = midiData; - plugin = ST(vstPlugins)[p->vstHandle]; - plugin->Debug("vstmidiout. kstatus = %i kdata1 = %i kdata2 = %i--- mididata = %i\n", + plugin = vstPlugins()[p->vstHandle]; + plugin->Debug("vstmidiout. kstatus = %i kdata1 = %i kdata2 = %i" + "--- mididata = %i\n", (int) *(p->kstatus), (int) *(p->kdata1), (int) *(p->kdata2), midiData); plugin->AddMIDI(midiData, 0, 0); - return OK; } @@ -287,11 +245,9 @@ static int vstparamget(CSOUND *csound, void *data) { VSTPARAMGET *p = (VSTPARAMGET *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->Debug("vstparamset(%d).\n", int(*p->kparam)); *p->kvalue = plugin->GetParamValue(int(*p->kparam)); - if (*(p->kvalue) == FL(-1.0)) plugin->Log("Invalid parameter number %d.\n", int(*p->kparam)); return OK; @@ -300,8 +256,7 @@ static int vstparamset_init(CSOUND *csound, void *data) { VSTPARAMSET *p = (VSTPARAMSET *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->Debug("vstparamset_init.\n"); p->oldkparam = 0; p->oldkvalue = 0; @@ -311,25 +266,22 @@ static int vstparamset(CSOUND *csound, void *data) { VSTPARAMSET *p = (VSTPARAMSET *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; if (*p->kparam == p->oldkparam && *p->kvalue == p->oldkvalue) return OK; p->oldkparam = *p->kparam; p->oldkvalue = *p->kvalue; plugin->Debug("vstsend(%d, %f).\n", int(*p->kparam), *p->kvalue); plugin->SetParameter(int(*p->kparam), float(*p->kvalue)); - return OK; } + static int vstbankload(CSOUND *csound, void *data) { VSTBANKLOAD *p = (VSTBANKLOAD *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; void *dummyPointer = 0; - CFxBank fxBank((char *) p->ibank); /* load the bank */ - plugin->Dispatch(effBeginLoadBank, 0, 0, (VstPatchChunkInfo *) fxBank.GetChunk(), 0); if (plugin->Dispatch(effBeginLoadBank, @@ -337,7 +289,6 @@ csound->InitError(csound, "Error: BeginLoadBank."); return NOTOK; } - // csound->Message(csound, "EffBeginLoadBank\n"); if (fxBank.IsLoaded()) { if (plugin->aeffect->uniqueID != fxBank.GetFxID()) { csound->InitError(csound, "Loaded bank ID doesn't match plug-in ID."); @@ -354,13 +305,9 @@ plugin->Log("Chunks loaded OK.\n"); } else { - // int cProg = plugin->EffGetProgram(); int cProg = plugin->Dispatch(effGetProgram, 0, 0, dummyPointer, 0); - // csound->Message(csound, "Current Program= %i\n", cProg); int i, j; int nParms = fxBank.GetNumParams(); - - // csound->Message(csound, "nParms= %i\n", nParms); for (i = 0; i < fxBank.GetNumPrograms(); i++) { plugin->Dispatch(effSetProgram, 0, i, dummyPointer, 0); plugin->Dispatch(effSetProgramName, 0, 0, fxBank.GetProgramName(i), @@ -368,21 +315,14 @@ for (j = 0; j < nParms; j++) plugin->SetParameter(j, fxBank.GetProgParm(i, j)); } - // pEffect->EffSetProgram(cProg); plugin->Dispatch(effSetProgram, 0, cProg, dummyPointer, 0); - // csound->Message(csound, "Programs OK\n"); } - // pEffect->SetChunkFile(dlg.GetPathName()); - // ShowDetails(); - // OnSetProgram(); } else { csound->InitError(csound, "Problem loading bank."); return NOTOK; /* check if error loading */ } plugin->Log("Bank loaded OK.\n"); - // if (fxBank.SetChunk()) { - // } return OK; } @@ -391,7 +331,7 @@ // The changes here are part of an attempt to map 0 to 1 and others VSTPROGSET *p = (VSTPROGSET *) data; int program = (int)*p->iprogram; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; if (program<=0) { csound->Message(csound, "VSTprogset: Program %d treated as 1\n", program); program = 1; @@ -403,18 +343,17 @@ static int vstedit_init(CSOUND *csound, void *data) { VSTEDIT *p = (VSTEDIT *) data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; - + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->OpenEditor(); - plugin->targetFLpanel = ST(fl_windows).size()-1; //gab - ST(VSTplugEditors).push_back(plugin); //gab + //plugin->targetFLpanel = vstPlugEditors().size()-1; //gab + vstPlugEditors().push_back(plugin); //gab return OK; } static int vstSetTempo(CSOUND *csound, void *data) { VSTTEMPO *p = (VSTTEMPO *)data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; plugin->vstTimeInfo.tempo = *p->tempo; return OK; } @@ -422,17 +361,11 @@ int vstbanksave(CSOUND *csound, void *data) { VSTBANKLOAD *p = (VSTBANKLOAD *)data; - VSTPlugin *plugin = ST(vstPlugins)[(size_t) *p->iVSThandle]; + VSTPlugin *plugin = vstPlugins()[(size_t) *p->iVSThandle]; char bankname[512]; //gab - // if (*p->ibank == SSTRCOD) { strcpy(bankname, (char *) p->ibank); /* use that */ - // } - - //------------ - //CSmpEffect *pEffect = (CSmpEffect *)GetApp()->vstHost.GetAt(nEffect); if (!plugin) return NOTOK; - CFxBank b; if (plugin->aeffect->flags & effFlagsProgramChunks) @@ -460,7 +393,8 @@ plugin->EffGetProgramName(szName); b.SetProgramName(i, szName); for (j = 0; j < nParms; j++) - b.SetProgParm(i, j, plugin->aeffect->getParameter(plugin->aeffect,j)); + b.SetProgParm(i, j, + plugin->aeffect->getParameter(plugin->aeffect,j)); } plugin->EffSetProgram(cProg); } @@ -475,9 +409,6 @@ if (b.SaveBank(bankname)) { plugin->Log("%s Bank saved OK.\n",bankname); - //pEffect->SetChunkFile(bankname); - // ShowDetails(); - // OnSetProgram(); } else { plugin->Log("Error: Error saving file\n"); @@ -517,12 +448,10 @@ { VSTNOTEOUT *p = (VSTNOTEOUT *)data; size_t vstHandle = (size_t) *p->iVSThandle; - p->vstPlugin = ST(vstPlugins)[vstHandle]; - p->startTime = CURTIME; - // The note may be scheduled to turn on some frames after the actual start of this kperiod. - // Use the warped p2 to compute this time. - double onTime = double(csound->timeOffs + p->h.insdshead->p2); - double deltaTime = onTime - CURTIME; + p->vstPlugin = vstPlugins()[vstHandle]; + p->startTime = getCurrentTime(csound); + double onTime = double(p->h.insdshead->p2); + double deltaTime = onTime - getCurrentTime(csound); int deltaFrames = 0; if (deltaTime > 0) { deltaFrames = int(deltaTime / csound->GetSr(csound)); @@ -541,17 +470,21 @@ } p->channel = int(*p->iChannel) & 0xf; // Split the real-valued MIDI key number - // into an integer key number and an integer number of cents (plus or minus 50 cents). + // into an integer key number and an integer number of cents (plus or + // minus 50 cents). p->key = int(double(*p->iKey) + 0.5); - int cents = int( ( ( double(*p->iKey) - double(p->key) ) * double(100.0) ) + double(0.5) ); + int cents = int( ( ( double(*p->iKey) - double(p->key) ) * double(100.0) ) + + double(0.5) ); p->velocity = int(*p->iVelocity) & 0x7f; - p->vstPlugin->AddMIDI(144 | p->channel | (p->key << 8) | (p->velocity << 16), deltaFrames, cents); - // Ensure that the opcode instance is still active when we are scheduled to turn the note off! + p->vstPlugin->AddMIDI(144 | p->channel | (p->key << 8) | (p->velocity << 16), + deltaFrames, cents); + // Ensure that the opcode instance is still active when we are scheduled + // to turn the note off! p->h.insdshead->xtratim = p->h.insdshead->xtratim + 2; p->on = true; if (csound->GetDebug(csound)) { csound->Message(csound, "vstnote_init: on time: %f\n", onTime); - csound->Message(csound, " csound time: %f\n", CURTIME); + csound->Message(csound, " csound time: %f\n", getCurrentTime(csound)); csound->Message(csound, " delta time: %f\n", deltaTime); csound->Message(csound, " delta frames: %d\n", deltaFrames); csound->Message(csound, " off time: %f\n", p->offTime); @@ -567,23 +500,30 @@ { VSTNOTEOUT *p = (VSTNOTEOUT *)data; if (p->on) { - if (CURTIME >= p->offTime || p->h.insdshead->relesing) { + if (getCurrentTime(csound) >= p->offTime || p->h.insdshead->relesing) { // The note may be scheduled to turn off // some frames after the actual start of this kperiod. - double deltaTime = p->offTime - CURTIME; + double deltaTime = p->offTime - getCurrentTime(csound); int deltaFrames = 0; if (deltaTime > 0) { deltaFrames = int(deltaTime / csound->GetSr(csound)); } - p->vstPlugin->AddMIDI(128 | p->channel | (p->key << 8) | (0 << 16), deltaFrames, 0); + p->vstPlugin->AddMIDI(128 | p->channel | (p->key << 8) | (0 << 16), + deltaFrames, 0); p->on = false; if (csound->GetDebug(csound)) { - csound->Message(csound, "vstnote_perf: csound time: %f\n", CURTIME); - csound->Message(csound, " off time: %f\n", p->offTime); - csound->Message(csound, " delta time: %f\n", deltaTime); - csound->Message(csound, " delta frames: %d\n", deltaFrames); - csound->Message(csound, " channel: %d\n", p->channel); - csound->Message(csound, " key: %d\n", p->key); + csound->Message(csound, "vstnote_perf: csound time: %f\n", + getCurrentTime(csound)); + csound->Message(csound, " off time: %f\n", + p->offTime); + csound->Message(csound, " delta time: %f\n", + deltaTime); + csound->Message(csound, " delta frames: %d\n", + deltaFrames); + csound->Message(csound, " channel: %d\n", + p->channel); + csound->Message(csound, " key: %d\n", + p->key); } } } @@ -591,21 +531,26 @@ } static OENTRY localops[] = { - { "vstinit", sizeof(VSTINIT), 1, "i", "So", &vstinit, 0, 0 }, - { "vstinfo", sizeof(VSTINFO), 1, "", "i", &vstinfo, 0, 0 }, - { "vstaudio", sizeof(VSTAUDIO), 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "iy", &vstaudio_init, 0, &vstaudio }, - { "vstaudiog", sizeof(VSTAUDIO), 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", "iy", &vstaudio_init, 0, &vstaudiog }, - { "vstmidiout", sizeof(VSTMIDIOUT), 3, "", "ikkkk", &vstmidiout_init, &vstmidiout, 0 }, - { "vstparamget", sizeof(VSTPARAMGET), 3, "k", "ik", &vstparamget_init, &vstparamget, 0 }, - { "vstparamset", sizeof(VSTPARAMSET), 3, "", "ikk", &vstparamset_init, &vstparamset, 0 }, - { "vstbankload", sizeof(VSTBANKLOAD), 1, "", "iS", &vstbankload, 0, 0 }, - { "vstprogset", sizeof(VSTPROGSET), 1, "", "ii", &vstprogset, 0, 0 }, - { "vstedit", sizeof(VSTEDIT), 1, "", "i", &vstedit_init, 0, 0 }, - { "vsttempo", sizeof(VSTTEMPO), 2, "" ,"ki", 0, &vstSetTempo, 0/*, &vstedit_deinit*/}, - { "vstnote", sizeof(VSTNOTEOUT), 3, "" ,"iiiii", &vstnote_init, &vstnote_perf, 0 }, - { "vstbanksave", sizeof(VSTBANKLOAD), 1, "" ,"iS", &vstbanksave, 0, 0/*, 0 */}, - //{ "vstnote", sizeof(VSTNOTE), 3, "", "iiiii", &vstnote_init, &vstnote, 0 }, - { NULL, 0, 0, NULL, NULL, (SUBR) NULL, (SUBR) NULL, (SUBR) NULL } + { "vstinit", sizeof(VSTINIT), 0, 1, "i", "To", &vstinit, 0, 0 }, + { "vstinfo", sizeof(VSTINFO), 0, 1, "", "i", &vstinfo, 0, 0 }, + { "vstaudio", sizeof(VSTAUDIO), 0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "iy", &vstaudio_init, 0, &vstaudio }, + { "vstaudiog", sizeof(VSTAUDIO), 0, 5, "mmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm", + "iy", &vstaudio_init, 0, &vstaudiog }, + { "vstmidiout", sizeof(VSTMIDIOUT), 0, 3, "", "ikkkk", &vstmidiout_init, + &vstmidiout, 0 }, + { "vstparamget", sizeof(VSTPARAMGET),0, 3, "k", "ik", &vstparamget_init, + &vstparamget, 0 }, + { "vstparamset", sizeof(VSTPARAMSET),0, 3, "", "ikk", &vstparamset_init, + &vstparamset, 0 }, + { "vstbankload", sizeof(VSTBANKLOAD),0, 1, "", "iT", &vstbankload, 0, 0 }, + { "vstprogset", sizeof(VSTPROGSET), 0, 1, "", "ii", &vstprogset, 0, 0 }, + { "vstedit", sizeof(VSTEDIT), 0, 1, "", "i", &vstedit_init, 0, 0 }, + { "vsttempo", sizeof(VSTTEMPO), 0, 2, "", "ki", 0, + &vstSetTempo, 0/*, &vstedit_deinit*/}, + { "vstnote", sizeof(VSTNOTEOUT), 0, 3, "", "iiiii", &vstnote_init, &vstnote_perf, 0 }, + { "vstbanksave", sizeof(VSTBANKLOAD),0, 1, "", "iT", &vstbanksave, 0, 0 }, + { 0, 0, 0, 0, 0, 0, (SUBR) 0, (SUBR) 0, (SUBR) 0 } }; PUBLIC int csoundModuleCreate(CSOUND *csound) @@ -619,8 +564,12 @@ int err = 0; while (ep->opname != NULL) { err |= csound->AppendOpcode(csound, - ep->opname, ep->dsblksiz, ep->thread, - ep->outypes, ep->intypes, + ep->opname, + ep->dsblksiz, + ep->flags, + ep->thread, + ep->outypes, + ep->intypes, (int (*)(CSOUND *, void *)) ep->iopadr, (int (*)(CSOUND *, void *)) ep->kopadr, (int (*)(CSOUND *, void *)) ep->aopadr); @@ -631,13 +580,11 @@ PUBLIC int csoundModuleDestroy(CSOUND *csound) { - if (csound->widgetGlobals) { - for (size_t i = 0, n = ST(vstPlugins).size(); i < n; ++i) { - if (ST(vstPlugins)[i]) { - delete ST(vstPlugins)[i]; + for (size_t i = 0, n = vstPlugins().size(); i < n; ++i) { + if (vstPlugins()[i]) { + delete vstPlugins()[i]; } - } - ST(vstPlugins).clear(); + vstPlugins().clear(); } return 0; } diff -Nru csound-5.17.11~dfsg/Opcodes/vst4cs/src/vsthost.cpp csound-6.02~dfsg/Opcodes/vst4cs/src/vsthost.cpp --- csound-5.17.11~dfsg/Opcodes/vst4cs/src/vsthost.cpp 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/vst4cs/src/vsthost.cpp 2014-01-07 16:54:20.000000000 +0000 @@ -289,8 +289,9 @@ std::string>((long) audioMasterTempoAt, "audioMasterTempoAt")); masterOpcodes().insert(std::pair((long) audioMasterGetNumAutomatableParameters, - "audioMasterGetNumAutomatableParameters")); + std::string>( + (long)audioMasterGetNumAutomatableParameters, + "audioMasterGetNumAutomatableParameters")); masterOpcodes().insert(std::pair((long) audioMasterGetParameterQuantization, "audioMasterGetParameterQuantization")); @@ -354,8 +355,9 @@ // // "audioMasterGetSpeakerArrangement")); masterOpcodes().insert(std::pair((long) audioMasterGetOutputSpeakerArrangement, - "audioMasterGetOutputSpeakerArrangement")); + std::string>( + (long) audioMasterGetOutputSpeakerArrangement, + "audioMasterGetOutputSpeakerArrangement")); masterOpcodes().insert(std::pair((long) audioMasterGetVendorString, "audioMasterGetVendorString")); @@ -408,7 +410,7 @@ std::string>((long) audioMasterGetChunkFile, "audioMasterGetChunkFile")); masterOpcodes().insert(std::pair((long) audioMasterGetInputSpeakerArrangement, + std::string>((long)audioMasterGetInputSpeakerArrangement, "audioMasterGetInputSpeakerArrangement")); opcodeRefCount()++; @@ -653,8 +655,8 @@ { size_t i; Debug("VSTPlugin::Init.\n"); - framesPerSecond = (size_t) ((long) (csound->esr + FL(0.5))); - framesPerBlock = csound->ksmps; + framesPerSecond = (size_t) ((long) (csound->GetSr(csound) + FL(0.5))); + framesPerBlock = csound->GetKsmps(csound); Log("VSTPlugin::Init framesPerSecond %d framesPerBlock %d " "channels %d in / %d out.\n", framesPerSecond, framesPerBlock, getNumInputs(), getNumOutputs()); @@ -924,7 +926,7 @@ { Debug("VSGPlugin::GetTime().\n"); if (csound) - vstTimeInfo.samplePos = csound->icurTime; + vstTimeInfo.samplePos = csound->GetCurrentTimeSamples(csound); else vstTimeInfo.samplePos = 0; vstTimeInfo.sampleRate = framesPerSecond; diff -Nru csound-5.17.11~dfsg/Opcodes/wave-terrain.c csound-6.02~dfsg/Opcodes/wave-terrain.c --- csound-5.17.11~dfsg/Opcodes/wave-terrain.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/wave-terrain.c 2014-01-07 16:53:48.000000000 +0000 @@ -21,7 +21,7 @@ 02111-1307 USA */ -#include "csdl.h" +#include "stdopcod.h" #include "wave-terrain.h" #include @@ -34,8 +34,8 @@ static int wtinit(CSOUND *csound, WAVETER *p) { /* DECLARE */ - FUNC *ftpx = csound->FTFind(csound, p->i_tabx); - FUNC *ftpy = csound->FTFind(csound, p->i_taby); + FUNC *ftpx = csound->FTnp2Find(csound, p->i_tabx); + FUNC *ftpy = csound->FTnp2Find(csound, p->i_taby); /* CHECK */ if (UNLIKELY((ftpx == NULL)||(ftpy == NULL))) { @@ -55,7 +55,9 @@ static int wtPerf(CSOUND *csound, WAVETER *p) { - int i, nsmps=csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; int xloc, yloc; MYFLT xc, yc; MYFLT amp = *p->kamp; @@ -65,8 +67,14 @@ MYFLT sizx = p->sizx, sizy = p->sizy; MYFLT theta = p->theta; MYFLT dtpidsr = csound->tpidsr; + MYFLT *aout = p->aout; - for (i=0; iaout[i] = p->xarr[xloc] * p->yarr[yloc] * amp; + aout[i] = p->xarr[xloc] * p->yarr[yloc] * amp; /* MOVE SCANNING POINT ROUND THE ELLIPSE */ theta += pch * dtpidsr; @@ -103,11 +111,11 @@ static int scanhinit(CSOUND *csound, SCANHAMMER *p) { - int srcpos = 0; - int dstpos = (int)MYFLT2LONG(*p->ipos); + unsigned int srcpos = 0; + unsigned int dstpos = (unsigned int)MYFLT2LONG(*p->ipos); - FUNC *fsrc = csound->FTFind(csound, p->isrc); /* Source table */ - FUNC *fdst = csound->FTFind(csound, p->idst); /* Destination table */ + FUNC *fsrc = csound->FTnp2Find(csound, p->isrc); /* Source table */ + FUNC *fdst = csound->FTnp2Find(csound, p->idst); /* Destination table */ if (UNLIKELY(fsrc->flen > fdst->flen)) { return csound->InitError(csound, Str( @@ -138,11 +146,11 @@ static int scantinit(CSOUND *csound, SCANTABLE *p) { /* DECLARE */ - FUNC *fpoint = csound->FTFind(csound, p->i_point); - FUNC *fmass = csound->FTFind(csound, p->i_mass); - FUNC *fstiff = csound->FTFind(csound, p->i_stiff); - FUNC *fdamp = csound->FTFind(csound, p->i_damp); - FUNC *fvel = csound->FTFind(csound, p->i_vel); + FUNC *fpoint = csound->FTnp2Find(csound, p->i_point); + FUNC *fmass = csound->FTnp2Find(csound, p->i_mass); + FUNC *fstiff = csound->FTnp2Find(csound, p->i_stiff); + FUNC *fdamp = csound->FTnp2Find(csound, p->i_damp); + FUNC *fvel = csound->FTnp2Find(csound, p->i_vel); /* CHECK */ if (UNLIKELY(fpoint == NULL)) { @@ -198,7 +206,9 @@ static int scantPerf(CSOUND *csound, SCANTABLE *p) { - int i, nsmps = csound->ksmps; + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t i, nsmps = CS_KSMPS; MYFLT force, fc1, fc2; int next, last; @@ -211,6 +221,7 @@ MYFLT inc = p->size * *(p->kpch) * csound->onedsr; MYFLT amp = *(p->kamp); MYFLT pos = p->pos; + MYFLT *aout = p->aout; /* CALCULATE NEW POSITIONS * @@ -244,17 +255,22 @@ fc2 = (fpoint->ftable[i] - fpoint->ftable[next]) * fstiff->ftable[i]; force = fc1 + fc2; p->newvel[i] = (fvel->ftable[i] - - force / (fmass->ftable[i] * csound->ekr)) + - force / (fmass->ftable[i] * CS_EKR)) * fdamp->ftable[i]; - p->newloc[i] = fpoint->ftable[i] + p->newvel[i] * csound->onedkr; + p->newloc[i] = fpoint->ftable[i] + p->newvel[i] * CS_ONEDKR; } } - for (i=0; iaout[i] = fpoint->ftable[(int)pos] * amp; + aout[i] = fpoint->ftable[(int)pos] * amp; pos += inc /* p->size * *(p->kpch) * csound->onedsr */; if (pos > p->size) { @@ -278,9 +294,11 @@ #define S(x) sizeof(x) static OENTRY localops[] = { -{ "wterrain", S(WAVETER), TR|5, "a", "kkkkkkii",(SUBR)wtinit, NULL, (SUBR)wtPerf }, -{ "scantable", S(SCANTABLE),TR|5,"a", "kkiiiii",(SUBR)scantinit,NULL,(SUBR)scantPerf}, -{ "scanhammer",S(SCANHAMMER),TB|1,"", "iiii", (SUBR)scanhinit, NULL, NULL } +{ "wterrain", S(WAVETER), TR, 5, "a", "kkkkkkii", + (SUBR)wtinit, NULL, (SUBR)wtPerf }, +{ "scantable", S(SCANTABLE),TR, 5,"a", "kkiiiii", + (SUBR)scantinit,NULL,(SUBR)scantPerf}, +{ "scanhammer",S(SCANHAMMER),TB, 1,"", "iiii", (SUBR)scanhinit, NULL, NULL } }; int wave_terrain_init_(CSOUND *csound) diff -Nru csound-5.17.11~dfsg/Opcodes/wavegde.h csound-6.02~dfsg/Opcodes/wavegde.h --- csound-5.17.11~dfsg/Opcodes/wavegde.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/wavegde.h 2014-01-07 16:53:48.000000000 +0000 @@ -60,12 +60,8 @@ } circularBuffer; /* circular buffer member functions */ -static void circularBufferCircularBuffer(CSOUND *,circularBuffer*,len_t);/* constructor */ -#if 0 -static void circularBufferWrite(circularBuffer*, MYFLT); /* write a sample */ -static MYFLT circularBufferRead(circularBuffer*); /* read next sample */ -#endif - +static void circularBufferCircularBuffer(CSOUND *, + circularBuffer*,len_t);/* constructor */ /* class filter -- recursive filter implementation class */ typedef struct { circularBuffer buffer; /* The filter's delay line */ diff -Nru csound-5.17.11~dfsg/Opcodes/wiimote.c csound-6.02~dfsg/Opcodes/wiimote.c --- csound-5.17.11~dfsg/Opcodes/wiimote.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Opcodes/wiimote.c 2014-01-07 16:53:48.000000000 +0000 @@ -80,10 +80,12 @@ MYFLT *num; } WIIRANGE; -#ifdef WIIUSE_0_12 -# define WIIMOTE_STATE_CONNECTED (0x0008) -#else +#ifndef WIIMOTE_STATE_CONNECTED +# if defined(WIIUSE_0_13) # define WIIMOTE_STATE_CONNECTED (0x0010) +# else +# define WIIMOTE_STATE_CONNECTED (0x0008) +# endif #endif int wiimote_find(CSOUND *csound, WIIMOTE *p) @@ -213,14 +215,17 @@ int kontrol = (int)(*p->kControl+FL(0.5)); if (UNLIKELY(n>=MAX_WIIMOTES || !(wii[n]->state & WIIMOTE_STATE_CONNECTED))) { printf("state of wii %d is %x\n", n, wii[n]->state); - return csound->PerfError(csound, Str("wiimote %d does not exist"), n); + return csound->PerfError(csound, p->h.insdshead, + Str("wiimote %d does not exist"), n); } if (kontrol<0) { printf("%f -- %.4x: " "tilt=[%f %f];\nforce=(%f %f %f)\n", 100.0*wii[n]->battery_level, wii[n]->btns, - wiir[n].pitch_min+wiir[n].pitch_scale*(FL(90.0)+(MYFLT)wii[n]->orient.pitch), - wiir[n].roll_min+wiir[n].roll_scale*(FL(90.0)-(MYFLT)wii[n]->orient.roll), + wiir[n].pitch_min+wiir[n].pitch_scale*(FL(90.0)+ + (MYFLT)wii[n]->orient.pitch), + wiir[n].roll_min+wiir[n].roll_scale*(FL(90.0)- + (MYFLT)wii[n]->orient.roll), wii[n]->gforce.x, wii[n]->gforce.y, wii[n]->gforce.z); *p->res = FL(0.0); return OK; @@ -291,11 +296,13 @@ return OK; case WII_NUNCHUK_PITCH: *p->res = wiir[n].nunchuk_pitch_min+ - wiir[n].nunchuk_pitch_scale*(FL(90.0)-(MYFLT)wii[n]->exp.nunchuk.orient.pitch); + wiir[n].nunchuk_pitch_scale*(FL(90.0)- + (MYFLT)wii[n]->exp.nunchuk.orient.pitch); return OK; case WII_NUNCHUK_ROLL: *p->res = wiir[n].nunchuk_roll_min+ - wiir[n].nunchuk_roll_scale*(FL(90.0)-(MYFLT)wii[n]->exp.nunchuk.orient.roll); + wiir[n].nunchuk_roll_scale*(FL(90.0)- + (MYFLT)wii[n]->exp.nunchuk.orient.roll); return OK; /* case 32: */ /* *p->res = (MYFLT)wii[n]->exp.nunchuk.axis.z; */ @@ -341,7 +348,7 @@ wiimote **wii = p->wii; int num = (int)*p->num; if (UNLIKELY(!(wii[num]->state & WIIMOTE_STATE_CONNECTED))) - return csound->PerfError(csound, Str("Not open")); + return csound->PerfError(csound, p->h.insdshead, Str("Not open")); switch ((int)(*p->kControl+FL(0.5))) { /* case 1: */ /* wii->mode.acc = (int)*p->kValue; */ @@ -408,10 +415,11 @@ #define S(x) sizeof(x) static OENTRY wiimote_localops[] = { - {"wiiconnect", S(WIIMOTE), 3, "i", "oo", (SUBR)wiimote_find, (SUBR)wiimote_poll }, - {"wiidata", S(WIIMOTE), 3, "k", "ko", (SUBR)wii_data_init, (SUBR)wii_data }, - {"wiisend", S(WIIMOTES), 3, "", "kko", (SUBR)wii_data_inits, (SUBR)wii_send }, - {"wiirange", S(WIIRANGE), 1, "", "iiio", (SUBR)wiimote_range, NULL, NULL } + {"wiiconnect", S(WIIMOTE), 0, 3, "i", "oo", (SUBR)wiimote_find, + (SUBR)wiimote_poll }, + {"wiidata", S(WIIMOTE), 0, 3, "k", "ko", (SUBR)wii_data_init, (SUBR)wii_data }, + {"wiisend", S(WIIMOTES), 0, 3, "", "kko", (SUBR)wii_data_inits, (SUBR)wii_send }, + {"wiirange", S(WIIRANGE), 0, 1, "", "iiio", (SUBR)wiimote_range, NULL, NULL } }; -LINKAGE1(wiimote_localops) +LINKAGE_BUILTIN(wiimote_localops) diff -Nru csound-5.17.11~dfsg/Release_Notes/Version_6.00 csound-6.02~dfsg/Release_Notes/Version_6.00 --- csound-5.17.11~dfsg/Release_Notes/Version_6.00 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Release_Notes/Version_6.00 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,406 @@ +============================ +CSOUND VERSION 6.00 +RELEASE NOTES +============================ + +Csound version 6 provides significant advances in functionality over +version 5, not only for the Csound application, but also for the Csound +library and application programming interface (API). Complete backward +compatibility has been retained for all orc/sco/csd based works, but changes +in the API are not backwardly compatible. + +The major changes for Csound 6 are: + + +o A --sample-accurate option provides sample-accurate timing + of score events. This breaks backward compatibility for plugin opcodes, + which require code changes for tracking current sample frame + position in audio type variables (see below for an example). + +o A --realtime option, which can also be enabled by setting the + CSOUND_PARAMS field realtime_mode to 1, provides asynchronous execution + of file reading and writing, and of init-time orchestra code. + This should make real-time operation of Csound more resistant to dropouts. + +o New opcodes and syntax support arrays of arbitrary dimensionality. + Arrays are created (usually) with the init opcode or with fillarray: + k1[] init 4 + generates a k-rate 1-dimensional array of length 4. Similarly, + a2[][] init 4, 4 + creates a square, 4 x 4 a-rate array. Or, + k2[] fillarray 1, 2, 3, 4 + creates a 4-element vector filled with {1, 2, 3, 4}, and implicitly + defines a length. Array elements are indexed with brackets [] such as k1[2] or + a2[2][3]. One dimensional arrays replace tvars, and can be used in opcodes like + maxtab/maxarray, mintab/minarray and sumtab/sumarray (see below). + Array setting can also be done on the left-hand side of opcodes, e.g.: + aSigs[0] vco2 .1, 440 + aSigs[1] vco2 .1, 880 + +o Multicore support has been completely rewritten using an improved + algorithm for task dispatching, which should use less memory and fewer locks. + Multicore benchmarks are now much faster than before. Multithreading often + provides significant speedups over single-threaded rendering. + +o Compilation of instruments and orchestra code can be done at any stage; + new instruments can be added or can replace old instruments with the + same name/number even while Csound is running. + +o The Csound API has been cleaned up and extended to support new functionality. + + +================== +USER-LEVEL CHANGES +================== + +New opcodes: + + o faustgen + + o array -- many new or revised opcodes -- see below under orchestra. + + o compileorc -- takes a filename containing a collection if instrument + definitions and compiles them, replacing existing versions. + It returns 0 on success. + + o compilestr -- like compileorc, but takes a string of orchestra code. + + o readscore -- runs the score preprocessor on a string and then schedules + new events via the RT event mechanism, returning 0 if successful. + +New Gen and Macros: + +Orchestra: + + o Note events can start and end in mid-kcycle. As this is an + incompatible change it is only invoked with the command-line option + --sample-accurate + is specified. Note that this does not work for tied notes, and + skipping initialisation is probably not useful. + + o Instruments can run at local values of ksmps using + setksmps iksmps + as in Csound 5 UDOs. + + o Compilation can be done at any stage; new instruments can be + added or can replace old instruments with the same name/number. + Running instances of old instrument definitions are not affected. + The only limitation is that header constants in instr 0 are read only + once at the time of the first compilation. Init-time code can be + placed outside instruments in the global space, but this also will be + executed only once following the compilation. In this way, score event + generation can be completely replaced by orchestra code. + See also the new opcodes compileorc and compilestr. + + o New syntax operators +=, -=, *= and /=. These are more than + syntactic sugar; please use += and -= for accumulating reverbs + as it gives better multicore behaviour. + + o The opcodes add, sub, mul and div have been deleted; use the + forms + - * /. Not many people were aware of these opcodes. + + o Any opcode with zero outputs or one output can be used + as a function. Some opcodes might require type annotation to + resolve ambiguities; see the the new syntax page in + the Csound 6.00 manual. + + o A statement can be broken across lines after a , = or + any arithmetic operation. + + o There are a range of new or recoded operations on k-valued + arrays, most restricted to 1 dimensional arrays (vectors): + kans minarray ktab returns the smallest value in the + (possibly) multidimensional array + kans maxarray ktab returns its largest value + kabs sumarray ktab returns sum of all values in the array + ktab genarray imin, imax[, inc] + generates vector of values from imin + to imax by increments of inc (default 1) + ktab2 maparray ktab1, "sin" maps the k-rate 1-arg function in + the string to every element of the vector + ktab2 maparray_i ktab1, "sin" maps the i-rate 1-arg function + in the string to every element of the vector + ktab2 slicearray ktab1, istart, iend + returns a slice of ktab1 from ktab1[istart] + to ktab1[iend] + copyf2array ktab, kfn copies data from an ftable to a vector + copya2ftab ktab, kfn copies data from a vector to an ftable. + + o Arithmetic on arrays is allowed. In particular addition, + subtraction, multiplication, and division are provided in arithmetic + syntax on vectors. Similar operations between arrays and scalars are + also allowed. + + o Each instance of every instrument has a scratchpad of 4 values + that persists after turnoff; this allows values to carry to next use of the + instrument; this may be useful for legato etc. + + o If a table number is given as -1 then an internal sine wave + equivalent to "f. 0 16384 10 1" is used. Attempts to write to + this table will give unpredictable results, but is not + policed. The 16384 can be change by command line option + --sine-size=# where the # is rounded up to a power of two. + + o A number of oscil opcodes now have the f-table parameter as + optional, defaulting to the internal sine wave. (oscil1, + oscil1i, oscil, oscil3, oscili, foscil, foscil1, loscil, + loscil3, poscil, poscil3) + +Score: + + o Score lines can have multiple strings. + + o Change to escape characters in score strings -- they do not happen. + + o Also see readscore opcode + + +Modified Opcodes and Gens: + + o The k() function can take an a-rate argument, in which case it + invokes a call to the downsamp opcode. + +Utilities: + + o Hetro/adsyn analysis files can be machine byte-order + independent if created with -X. The down side is a longer file + and a little slower loading. The het_export utility will + create the independent format from the old, and het_import is + no longer necessary. + + o cvanal and lpanal will produce machine independent files if the -X + option is used. The convolve and lpread etc. opcodes will + accept either format. You are encouraged to use the machine + independent form. Analysis files produced with -X can be used + on other systems. + +Frontends: + + o CsoundQt has been ported to Csound 6. + + o CsoundVST has been ported to Csound 6. + + o A new Csound6 app for Android has been developed, extending the + Csound 5 app with: + + (1) An improved user interface, including text editing, scrolling + performance messages, a built-in User Guide, and links to the + Csound manual and Web site. + + (2) Plugin opcodes, including the signal flow graph opcodes, the + FluidSynth opcodes, and the Lua opcodes, which enable executing + arbitrary Lua coded in Csound using the very fast LuaJIT engine, + even writing opcodes in Lua, and calling any public C function from + Csound using LuaJIT's FFI. + +General usage: + + o The environment variables for module directories have been renamed + OPCODE6DIR64 or OPCODE6DIR (note the 6) so they can co-exist with + directories for Csound 5 modules. + + o Similarly, .csoundrc has been renamed .csound6rc. + +Bugs fixed: + + o Too many to record! + + +=========== +API CHANGES +=========== + +New configuration/parameter setting functions: + + PUBLIC int csoundSetOption(CSOUND *csound, char *option); + PUBLIC void csoundSetParams(CSOUND *csound, CSOUND_PARAMS *p); + PUBLIC void csoundGetParams(CSOUND *csound, CSOUND_PARAMS *p); + PUBLIC void csoundSetOutput(CSOUND *csound, char *name, char *type, + char *format); + PUBLIC void csoundSetInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIFileInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIOutput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIFileOutput(CSOUND *csound, char *name); + +New parsing/compilation functions: + + PUBLIC TREE *csoundParseOrc(CSOUND *csound, char *str); + PUBLIC int csoundCompileTree(CSOUND *csound, TREE *root); + PUBLIC int csoundCompileOrc(CSOUND *csound, const char *str); + PUBLIC int csoundReadScore(CSOUND *csound, char *str); + PUBLIC int csoundCompileArgs(CSOUND *, int argc, char **argv); + +New function for starting csound after the first compilation: + + PUBLIC int csoundStart(CSOUND *csound); + +New threadsafe getters/setters for the software bus: + + PUBLIC MYFLT csoundGetControlChannel(CSOUND *csound, const char *name); + PUBLIC void csoundSetControlChannel(CSOUND *csound, const char *name, + MYFLT val); + PUBLIC void csoundGetAudioChannel(CSOUND *csound, const char *name, + MYFLT *samples); + PUBLIC void csoundSetAudioChannel(CSOUND *csound, const char *name, + MYFLT *samples); + PUBLIC void csoundSetStringChannel(CSOUND *csound, const char *name, + char *string); + PUBLIC void csoundGetStringChannel(CSOUND *csound, const char *name, + char *string); + +New threadsafe copy functions for tables: + + PUBLIC void csoundTableCopyOut(CSOUND *csound, int table, MYFLT *dest); + PUBLIC void csoundTableCopyIn(CSOUND *csound, int table, MYFLT *src); + +The entire Csound API has been made threadsafe so that performance and control +can occur in separate threads (after a call to csoundStart() +or csoundCompile()). Thread safety has been implemented by: + + o Using atomic operations for reading and writing in control channels, + + o Using spinlocks in audio and string channels, + + o Using mutexes to protect compilation, score + events, and table access. + + +The Csound API and SDK for iOS has been changed to use Automatic Resource +Counting (ARC). All projects using Csound 6 for iOS will require +the use of ARC. The Csound for iOS Examples project shows how to use +ARC compliant code with Csound. Users with existing Csound 5-based +iOS projects can use the "Edit->Refactor->Convert to Objective-C +ARC..." wizard to help with updating their projects to use ARC. +For more information about ARC, consult the "Transitioning to ARC +Release Notes" on Apple's Developer website at +https://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/ + +The Csound API and SDK for Android has been changed to use the new Csound API. + +==================== +SYSTEM LEVEL CHANGES +==================== + +System changes: + + o in Linux and OSX, locales are now thread-safe + and local. + +Internal changes: + + o The build system now uses CMake (instead of SCons as in Csound 5). + + o A number of table access opcodes have been rewritten, but + should behave the same. + + o Similarly diskin and diskin2 now use the same code, so that diskin + should be more stable + + o The old parser has been completely removed. + + o New internal functions in CSOUND: + + void (*FlushCircularBuffer)(CSOUND *, void *); + void *(*FileOpenAsync)(CSOUND *, void *, int, const char *, void *, + const char *, int, int, int); + unsigned int (*ReadAsync)(CSOUND *, void *, MYFLT *, int); + unsigned int (*WriteAsync)(CSOUND *, void *, MYFLT *, int); + int (*FSeekAsync)(CSOUND *, void *, int, int); + char *(*GetString)(CSOUND *, MYFLT); + Extract a string originating from a score-event argument. + + o Functions removed from CSOUND: + + void *(*FileOpen)(CSOUND *, + void*, int, const char*, void*, const char*); + + o The "private" parts of the API have been changed considerably. + Also structures like EVTBLK have been changed. + + o The LINKAGE1/FLINKAGE1 macros have been renamed to + LINKAGE_BUILTIN/FLINKAGE_BUILTIN + +The template for arate perf-pass opcodes is: + + int perf_myopcode(CSOUND *csound, MYOPCODE *p) + { + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + ... + if (UNLIKELY(offset)) memset(p->res, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->res[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nres[n] = .... + } + return OK; + } + +Csound's string variable type has been re-implemented. + +The OENTRY structure has been changed. It has a new dependency field. +This field is now required for multicore semantics. Setting this field to -1 +safely disables parallel execution, but it is recommended to enable parallel +execution by using the flags defined in include/interlocks.h +If your opcode reads or writes to zak space, use ZR or ZW, or ZB for both. +Similarly, if it reads or writes tables, use TR, TW or TB. If it reads or +writes to channels, use CR, CW and CB. If it uses the stack, use SK. +If it outputs text, then use WR to stop mixing of output. The _QQ flag marks +an opcode as deprecated. Other flags may be added later. + +All opcodes that touch audio should take note of sample-accurate code. + +A number of previous API functions have been removed. OpenFile and OpenFile2 +have both been replaced by new OpenFile2 with an additional argument. + +Additions have been made for arg type specifications for opcodes. + + o Any-types have been added, as follows: + + * '.' signifies a required arg of any-type + * '?' signifies an optional arg of any-type + * '*' signifies a var-arg list of any-type + + o Arrays are now specified using "[x]" where x is a type-specifier. + The type-specifier can be any of the of the current specifiers, + including any-types. See Opcodes/arrays.c for examples of usage. + +New Type System +=============== + +A new type system has been added to Csound6, and significant changes +have been made to the compiler. The previous system for handling types +involved reading the first letter of a variable's name every time +the variable was used to determine its type. This meant there was much +re-checking of types. Also, adding new types was difficult, because much +custom code had to be updated to check for new type letters. + +In Csound6, a separate system of types has been added. Types are defined as +CS_TYPEs. The creation of variables from types and the initialisation +of memory has been encapsulated within the CS_TYPEs. This change +allows easier addition of new types, as well as generic calculations of +memory pools, amongst other things. + +The compiler has been changed to use the new type system in its semantic +checking phase. Variables are now registered into a CS_VAR_POOL when they +are first defined, with the CS_VARIABLE having a reference to its CS_TYPE. +After first time definition within the pool, the type information is looked +up in consequent variable uses, rather than re-calculated from the variable +name. This opens up possibilities for new variable naming and typing +strategies, i.e. using "myVar:K" to denote a k-rate arg. It also +opens up possibilities for user-defined types, such as +"data myType kval, aval", then using "myVar:myType" to define a var +of that type. (The previous is speculative, and is not an active +proposal at this time.) + +The addition of the type system has formalised the static type system +that has existed in Csound prior to Csound6. It has, arguably, simplified +the code-base in terms of type handling, as well as laid groundwork +for future type-related research to be integrated into Csound. + +======================================================================== diff -Nru csound-5.17.11~dfsg/SConstruct csound-6.02~dfsg/SConstruct --- csound-5.17.11~dfsg/SConstruct 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/SConstruct 1970-01-01 00:00:00.000000000 +0000 @@ -1,2900 +0,0 @@ -#J vim:syntax=python -print ''' - C S O U N D 5 - -SCons build file for Csound 5: -API library, plugin opcodes, utilities, and front ends. - -By Michael Gogins - -For custom options, run 'scons -h'. -For default options, run 'scons -H'. -If headers or libraries are not found, edit 'custom.py'. -For Linux, run in the standard shell - with standard Python and just run 'scons'. -For MinGW, run in the MSys shell - and use www.python.org WIN32 Python to run scons. -For Microsoft Visual C++, run in the Platform SDK - command shell, and use www.python.org WIN32 Python to run scons. -''' - -import time -import glob -import os -import os.path -import sys -import string -import shutil -import copy - -############################################################################# -# -# UTILITY FUNCTIONS -# -############################################################################# - -pluginLibraries = [] -executables = [] -headers = Split(''' - H/cfgvar.h H/cscore.h H/csdl.h H/csound.h H/csound.hpp H/csoundCore.h - H/cwindow.h H/msg_attr.h H/OpcodeBase.hpp H/pstream.h H/pvfileio.h - H/soundio.h H/sysdep.h H/text.h H/version.h H/float-version.h - interfaces/CsoundFile.hpp interfaces/CppSound.hpp interfaces/filebuilding.h -''') -libs = [] -pythonModules = [] - -def today(): - return time.strftime("%Y-%m-%d", time.localtime()) - -# Detect OPERATING SYSTEM platform. - -def getPlatform(): - if sys.platform[:5] == 'linux': - return 'linux' - elif sys.platform[:3] == 'win': - return 'win32' - elif sys.platform[:6] == 'darwin': - return 'darwin' - elif sys.platform[:5] == 'sunos': - return 'sunos' - else: - return 'unsupported' - -############################################################################# -# -# DEFINE CONFIGURATION -# -############################################################################# - -print "System platform is '" + getPlatform() + "'." - - -# Create options that can be set from the command line. - -commandOptions = Variables() # was Options() -commandOptions.Add('CC') -commandOptions.Add('CXX') -commandOptions.Add('LINK') -commandOptions.Add('LINKFLAGS') -commandOptions.Add('custom', - 'Specify name of custom options file (default is "custom.py")', - 'custom.py') -commandOptions.Add('useDouble', - 'Set to 1 to use double-precision floating point for audio samples.', - '0') -commandOptions.Add('usePortAudio', - 'Set to 1 to use PortAudio for real-time audio input and output.', - '1') -commandOptions.Add('usePortMIDI', - 'Build PortMidi plugin for real time MIDI input and output.', - '1') -commandOptions.Add('useALSA', - 'Set to 1 to use ALSA for real-time audio and MIDI input and output.', - '1') -commandOptions.Add('useJack', - 'Set to 1 if you compiled PortAudio to use Jack; also builds Jack plugin.', - '1') -commandOptions.Add('useFLTK', - 'Set to 1 to use FLTK for graphs and widget opcodes.', - '1') -commandOptions.Add('noFLTKThreads', - 'Set to 1 to disable use of a separate thread for FLTK widgets.', - '1') -commandOptions.Add('pythonVersion', - 'Set to the Python version to be used.', - '%d.%d' % (int(sys.hexversion) >> 24, (int(sys.hexversion) >> 16) & 255)) -commandOptions.Add('buildCsoundVST', - 'Set to 1 to build CsoundVST (needs CsoundAC, FLTK, boost, Python, SWIG).', - '0') -commandOptions.Add('buildCsoundAC', - 'Set to 1 to build CsoundAC (needs Eigen 3, FLTK, boost, Python, SWIG).', - '0') -commandOptions.Add('buildCsound5GUI', - 'Build FLTK GUI frontend (requires FLTK 1.1.7 or later).', - '0') -commandOptions.Add('generateTags', - 'Set to 1 to generate TAGS', - '0') -commandOptions.Add('generatePdf', - 'Set to 1 to generate PDF documentation', - '0') -#commandOptions.Add('buildLoris', -# 'Set to 1 to build the Loris Python extension and opcodes', -# '1') -commandOptions.Add('useOSC', - 'Set to 1 if you want OSC support', - '0') -commandOptions.Add('bufferoverflowu', - 'Set to 1 to use the Windows buffer overflow library, required if you use MinGW to link with MSVC-built libraries', - '0') -if getPlatform() != 'win32': - commandOptions.Add('useUDP', - 'Set to 0 if you do not want UDP support', - '1') -else: - commandOptions.Add('useUDP', - 'Set to 1 if you want UDP support', - '0') -commandOptions.Add('buildPythonOpcodes', - 'Set to 1 to build Python opcodes', - '0') -commandOptions.Add('buildLuaOpcodes', - 'Set to 1 to build Lua opcodes', - '0') -commandOptions.Add('prefix', - 'Base directory for installs. Defaults to /usr/local.', - '/usr/local') -commandOptions.Add('instdir', - 'For the install target: puts instdir before the prefix', - '') -commandOptions.Add('buildRelease', - 'Set to 1 to build for release (implies noDebug).', - '0') -commandOptions.Add('noDebug', - 'Build without debugging information.', - '0') -commandOptions.Add('gcc3opt', - 'Enable gcc 3.3.x or later optimizations for the specified CPU architecture (e.g. pentium3); implies noDebug.', - '0') -commandOptions.Add('gcc4opt', - 'Enable gcc 4.0 or later optimizations for the specified CPU architecture (e.g. pentium3); implies noDebug.', - '0') -commandOptions.Add('useLrint', - 'Use lrint() and lrintf() for converting floating point values to integers.', - '0') -commandOptions.Add('useGprof', - 'Build with profiling information (-pg).', - '0') -commandOptions.Add('Word64', - 'Build for 64bit computer', - '0') -commandOptions.Add('Lib64', - 'Build for lib64 rather than lib', - '0') -if getPlatform() == 'win32': - commandOptions.Add('dynamicCsoundLibrary', - 'Set to 0 to build static Csound library instead of csound.dll', - '1') -else: - commandOptions.Add('dynamicCsoundLibrary', - 'Build dynamic Csound library instead of libcsound.a', - '0') -commandOptions.Add('buildStkOpcodes', - "Build opcodes encapsulating Perry Cook's Synthesis Toolkit in C++ instruments and effects", - '0') -commandOptions.Add('install', - 'Enables the Install targets', - '0') -commandOptions.Add('buildPDClass', - "build csoundapi~ PD class (needs m_pd.h in the standard places)", - '0') -commandOptions.Add('useCoreAudio', - "Set to 1 to use CoreAudio for real-time audio input and output.", - '1') -commandOptions.Add('useAltivec', - "On OSX use the gcc AltiVec optmisation flags", - '0') -commandOptions.Add('buildDSSI', - "Build DSSI/LADSPA host opcodes", - '1') -commandOptions.Add('buildUtilities', - "Build stand-alone executables for utilities that can also be used with -U", - '1') -commandOptions.Add('buildTclcsound', - "Build Tclcsound frontend (cstclsh, cswish and tclcsound dynamic module). Requires Tcl/Tk headers and libs", - '0') -commandOptions.Add('buildWinsound', - "Build Winsound frontend. Requires FLTK headers and libs", - '0') -commandOptions.Add('buildVirtual', - "Build Virtual MIDI keyboard. Requires FLTK 1.1.7 or later headers and libs", - '0') -commandOptions.Add('buildInterfaces', - "Build C++ interface library.", - '0') -commandOptions.Add('buildLuaWrapper', - 'Set to 1 to build Lua wrapper for the C++ interface library (needs buildInterfaces).', - '0') -commandOptions.Add('buildPythonWrapper', - 'Set to 1 to build Python wrapper for the C++ interface library (needs buildInterfaces).', - '0') -commandOptions.Add('buildJavaWrapper', - 'Set to 1 to build Java wrapper for the C++ interface library (needs buildInterfaces).', - '0') -#commandOptions.Add('buildOSXGUI', -# 'On OSX, set to 1 to build the basic GUI frontend', -# '0') -#commandOptions.Add('buildCSEditor', -# 'Set to 1 to build the Csound syntax highlighting text editor. Requires FLTK headers and libs', -# '0') -commandOptions.Add('withICL', - 'On Windows, set to 1 to build with the Intel C++ Compiler (also requires Microsoft Visual C++), or set to 0 to build with MinGW', - '0') -commandOptions.Add('withMSVC', - 'On Windows, set to 1 to build with Microsoft Visual C++, or set to 0 to build with MinGW', - '0') -commandOptions.Add('withSunStudio', - 'On Solaris, set to 1 to build with Sun Studio, or set to 0 to build with gcc', - '1') -commandOptions.Add('buildNewParser', - 'Enable building new parser (requires Flex/Bison)', - '1') -commandOptions.Add('NewParserDebug', - 'Enable tracing of new parser', - '0') -commandOptions.Add('buildMultiCore', - 'Enable building for multicore sytem (requires new parser)', - '1') -commandOptions.Add('buildvst4cs', - 'Set to 1 to build vst4cs plugins (requires Steinberg VST headers)', - '0') -if getPlatform() == 'win32': - commandOptions.Add('useGettext', - 'Set to 1 to use the GBU internationalisation/localisation scheme', - '0') -else: - commandOptions.Add('useGettext', - 'Set to 0 for none and 1 for GNU internationalisation/localisation scheme', - '1') -commandOptions.Add('buildImageOpcodes', - 'Set to 0 to avoid building image opcodes', - '1') -commandOptions.Add('useOpenMP', - 'Set to 1 to use OpenMP for parallel performance', - '0') -commandOptions.Add('tclversion', - 'Set to 8.4 or 8.5', - '8.5') -commandOptions.Add('includeWii', - 'Set to 12 or 13 if using libwiiuse v0.12 or v0.13', - '0') -commandOptions.Add('includeP5Glove', - 'Set to 1 if using P5 Glove', - '0') -commandOptions.Add('buildBeats', - 'Set to 1 if building beats score language', - '1') -commandOptions.Add('buildcatalog', - 'Set to 1 if building opcode/library catalogue', - '0') -commandOptions.Add('includeSerial', - 'Set to 1 if compiling serial code', - '1') -# Define the common part of the build environment. -# This section also sets up customized options for third-party libraries, which -# should take priority over default options. - -commonEnvironment = Environment(ENV = os.environ) -commandOptions.Update(commonEnvironment) - -def compilerIntel(): - if getPlatform() == 'win32' and commonEnvironment['withICL'] == '1': - return True - else: - return False - -def compilerMicrosoft(): - if getPlatform() == 'win32' and commonEnvironment['withMSVC'] == '1': - return True - else: - return False - -def compilerSun(): - if getPlatform() == 'sunos' and commonEnvironment['withSunStudio'] == '1': - return True - else: - return False - -def compilerGNU(): - if not compilerIntel() and not compilerMicrosoft() and not compilerSun(): - return True - else: - return False - -optionsFilename = 'custom.py' - -if compilerIntel(): - Tool('icl')(commonEnvironment) - optionsFilename = 'custom-msvc.py' -elif compilerMicrosoft(): - optionsFilename = 'custom-msvc.py' -elif getPlatform() == 'win32': - # On Windows, to exclude MSVC tools, - # we have to force MinGW tools and then re-create - # the environment from scratch. - commonEnvironment = Environment(ENV = os.environ, tools = ['mingw', 'swig', 'javac', 'jar']) - commandOptions.Update(commonEnvironment) - #Tool('mingw')(commonEnvironment) - optionsFilename = 'custom-mingw.py' - -if(not FindFile(optionsFilename, '.')): - print "\n\n*************************************************" - print "%s NOT FOUND, please copy one of the custom-***.py" % optionsFilename - print "as %s and modify it to suit your system, if necessary" % optionsFilename - print "*************************************************" - Exit(-1) - - -Help(commandOptions.GenerateHelpText(commonEnvironment)) - -if commonEnvironment['custom']: - optionsFilename = commonEnvironment['custom'] - -Requires(optionsFilename, commonEnvironment) - - -print "Using options from '%s.'" % optionsFilename - -fileOptions = Options(optionsFilename) -fileOptions.Add('customCPPPATH', 'List of custom CPPPATH variables') -fileOptions.Add('customCCFLAGS') -fileOptions.Add('customCXXFLAGS') -fileOptions.Add('customLIBS') -fileOptions.Add('customLIBPATH') -fileOptions.Add('customSHLINKFLAGS') -fileOptions.Add('customSWIGFLAGS') -fileOptions.Update(commonEnvironment) - -customCPPPATH = commonEnvironment['customCPPPATH'] -commonEnvironment.Prepend(CPPPATH = customCPPPATH) -customCCFLAGS = commonEnvironment['customCCFLAGS'] -commonEnvironment.Prepend(CCFLAGS = customCCFLAGS) -customCXXFLAGS = commonEnvironment['customCXXFLAGS'] -commonEnvironment.Prepend(CXXFLAGS = customCXXFLAGS) -customLIBS = commonEnvironment['customLIBS'] -commonEnvironment.Prepend(LIBS = customLIBS) -customLIBPATH = commonEnvironment['customLIBPATH'] -commonEnvironment.Prepend(LIBPATH = customLIBPATH) -customSHLINKFLAGS = commonEnvironment['customSHLINKFLAGS'] -commonEnvironment.Prepend(SHLINKFLAGS = customSHLINKFLAGS) -customSWIGFLAGS = commonEnvironment['customSWIGFLAGS'] -commonEnvironment.Prepend(SWIGFLAGS = customSWIGFLAGS) - -# Define options for different platforms. -if getPlatform() != 'win32' and getPlatform() != 'sunos': - print "Build platform is '" + getPlatform() + "'." -elif getPlatform() == 'sunos': - if compilerSun(): - print "Build platform is Sun Studio." - elif compilerGNU(): - print "Build platform is '" + getPlatform() + "'." -else: - if compilerMicrosoft(): - print "Build platform is Microsoft Visual C++ (MSVC)." - elif compilerIntel(): - print "Build platform is the Intel C++ Compiler (ICL)." - elif compilerGNU(): - print "Build platform is MinGW/MSYS" - -print "SCons tools on this platform: ", commonEnvironment['TOOLS'] - -commonEnvironment.Prepend(CPPPATH = ['.', './H']) -if commonEnvironment['useLrint'] != '0': - commonEnvironment.Prepend(CCFLAGS = ['-DUSE_LRINT']) - -cf = Configure(commonEnvironment) -if commonEnvironment['useGettext'] == '1': - if cf.CheckHeader("libintl.h"): - print "CONFIGURATION DECISION: Using GNU gettext scheme" - commonEnvironment.Prepend(CCFLAGS = ['-DGNU_GETTEXT']) - if getPlatform() == "win32": - commonEnvironment.Append(LIBS=['intl']) - if getPlatform() == "darwin": - commonEnvironment.Append(LIBS=['intl']) - if getPlatform() == "sunos": - commonEnvironment.Append(LIBS=['intl']) -else: - print "CONFIGURATION DECISION: No localisation" - -commonEnvironment = cf.Finish() - -if compilerGNU(): - commonEnvironment.Prepend(CCFLAGS = ['-Wno-format']) - commonEnvironment.Prepend(CXXFLAGS = ['-Wno-format']) - -if commonEnvironment['gcc4opt'] == 'atom': - commonEnvironment.Prepend(CCFLAGS = Split('-mtune=prescott -O2 -fomit-frame-pointer')) -elif commonEnvironment['gcc3opt'] != '0' or commonEnvironment['gcc4opt'] != '0': - commonEnvironment.Prepend(CCFLAGS = ['-ffast-math']) - if commonEnvironment['gcc4opt'] != '0': - commonEnvironment.Prepend(CCFLAGS = ['-ftree-vectorize']) - cpuType = commonEnvironment['gcc4opt'] - else: - cpuType = commonEnvironment['gcc3opt'] - if getPlatform() == 'darwin': - if cpuType == 'universal': - commonEnvironment.Prepend(CCFLAGS = Split('-O3 -arch i386 -arch ppc ')) - commonEnvironment.Prepend(CXXFLAGS = Split('-O3 -arch i386 -arch ppc ')) - commonEnvironment.Prepend(LINKFLAGS = Split('-arch i386 -arch ppc ')) - elif cpuType == 'universalX86': - commonEnvironment.Prepend(CCFLAGS = Split('-O3 -arch i386 -arch x86_64 -msse -mfpmath=sse')) - commonEnvironment.Prepend(CXXFLAGS = Split('-O3 -arch i386 -arch x86_64 -msse -mfpmath=sse ')) - commonEnvironment.Prepend(LINKFLAGS = Split('-arch i386 -arch x86_64 ')) - else: - commonEnvironment.Prepend(CCFLAGS = Split('-O3 -arch %s' % cpuType)) - commonEnvironment.Prepend(CXXFLAGS = Split('-O3 -arch %s' % cpuType)) - else: - commonEnvironment.Prepend(CCFLAGS = Split('-Wall -O3 -mtune=%s' % (cpuType))) - - -if commonEnvironment['buildRelease'] != '0': - if compilerMicrosoft(): - commonEnvironment.Append(CCFLAGS = Split('/O2')) - elif compilerIntel(): - commonEnvironment.Append(CCFLAGS = Split('/O3')) - -if commonEnvironment['noDebug'] == '0': - if compilerGNU() : - commonEnvironment.Append(CCFLAGS = ['-g']) - -if commonEnvironment['useGprof'] == '1': - commonEnvironment.Append(CCFLAGS = ['-pg']) - commonEnvironment.Append(CXXFLAGS = ['-pg']) - commonEnvironment.Append(LINKFLAGS = ['-pg']) - commonEnvironment.Append(SHLINKFLAGS = ['-pg']) -elif commonEnvironment['gcc3opt'] != 0 or commonEnvironment['gcc4opt'] != '0': - if not compilerSun() and commonEnvironment['gcc4opt'] != 'atom': - commonEnvironment.Append(CCFLAGS = ['-fomit-frame-pointer']) - commonEnvironment.Append(CCFLAGS = ['-freorder-blocks']) - -if getPlatform() == 'win32' and compilerGNU(): - commonEnvironment.Prepend(CCFLAGS = Split('-fexceptions -shared-libgcc')) - commonEnvironment.Prepend(CXXFLAGS = Split('-fexceptions -shared-libgcc')) - commonEnvironment.Prepend(LINKFLAGS = Split('-fexceptions -shared-libgcc')) - commonEnvironment.Prepend(SHLINKFLAGS = Split('-fexceptions -shared-libgcc')) - -commonEnvironment.Prepend(LIBPATH = ['.', '#.']) - -if commonEnvironment['buildRelease'] == '0': - commonEnvironment.Prepend(CPPFLAGS = ['-DBETA']) - -if commonEnvironment['Lib64'] == '1': - if getPlatform() == 'sunos': - commonEnvironment.Prepend(LIBPATH = ['.', '#.', '/lib/64', '/usr/lib/64']) - else: - commonEnvironment.Prepend(LIBPATH = ['.', '#.', '/usr/local/lib64']) -else: - commonEnvironment.Prepend(LIBPATH = ['.', '#.', '/usr/local/lib']) - -if commonEnvironment['Word64'] == '1': - if compilerSun(): - commonEnvironment.Append(CCFLAGS = ['-xcode=pic32']) - else: - commonEnvironment.Append(CCFLAGS = ['-fPIC']) - -if commonEnvironment['useDouble'] == '0': - print 'CONFIGURATION DECISION: Using single-precision floating point for audio samples.' -else: - print 'CONFIGURATION DECISION: Using double-precision floating point for audio samples.' - commonEnvironment.Append(CPPFLAGS = ['-DUSE_DOUBLE']) - -# Define different build environments for different types of targets. - -if getPlatform() == 'linux': - commonEnvironment.Append(CCFLAGS = ["-DLINUX"]) - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_SOCKETS']) - commonEnvironment.Append(CPPPATH = ['/usr/local/include']) - commonEnvironment.Append(CPPPATH = ['/usr/include']) - commonEnvironment.Append(CPPPATH = ['/usr/include']) - commonEnvironment.Append(CPPPATH = ['/usr/X11R6/include']) - commonEnvironment.Append(CCFLAGS = ["-DPIPES"]) - commonEnvironment.Append(LINKFLAGS = ['-Wl,-Bdynamic']) -elif getPlatform() == 'sunos': - commonEnvironment.Append(CCFLAGS = "-D_SOLARIS") - commonEnvironment.Append(CPPPATH = '/usr/local/include') - commonEnvironment.Append(CPPPATH = '/usr/include') - commonEnvironment.Append(CPPPATH = '/usr/jdk/instances/jdk1.5.0/include') - if compilerGNU(): - commonEnvironment.Append(CCFLAGS = "-DPIPES") - commonEnvironment.Append(LINKFLAGS = ['-Wl,-Bdynamic']) -elif getPlatform() == 'darwin': - commonEnvironment.Append(CCFLAGS = "-DMACOSX") - commonEnvironment.Append(CPPPATH = '/usr/local/include') - commonEnvironment.Append(CCFLAGS = "-DPIPES") - if commonEnvironment['useAltivec'] == '1': - print 'CONFIGURATION DECISION: Using Altivec optimisation' - commonEnvironment.Append(CCFLAGS = "-faltivec") -elif getPlatform() == 'win32': - commonEnvironment.Append(CCFLAGS = '-D_WIN32') - commonEnvironment.Append(CCFLAGS = '-DWIN32') - commonEnvironment.Append(CCFLAGS = '-DPIPES') - commonEnvironment.Append(CCFLAGS = '-DOS_IS_WIN32') - commonEnvironment.Append(CXXFLAGS = '-D_WIN32') - commonEnvironment.Append(CXXFLAGS = '-DWIN32') - commonEnvironment.Append(CXXFLAGS = '-DPIPES') - commonEnvironment.Append(CXXFLAGS = '-DOS_IS_WIN32') - commonEnvironment.Append(CXXFLAGS = '-DFL_DLL') - if compilerGNU(): - commonEnvironment.Prepend(CCFLAGS = ["-Wall"]) - commonEnvironment.Append(CPPPATH = '/usr/local/include') - commonEnvironment.Append(CPPPATH = '/usr/include') - commonEnvironment.Append(SHLINKFLAGS = Split('-Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc')) - commonEnvironment.Append(LINKFLAGS = Split('-Wl,--enable-auto-import -Wl,--enable-runtime-pseudo-reloc')) - else: - commonEnvironment.Append(CCFLAGS = '/DMSVC') - commonEnvironment.Append(CXXFLAGS = '/EHsc') - commonEnvironment.Append(CCFLAGS = '/D_CRT_SECURE_NO_DEPRECATE') - commonEnvironment.Append(CCFLAGS = '/MD') - commonEnvironment.Append(CCFLAGS = '/W2') - commonEnvironment.Append(CCFLAGS = '/wd4251') - commonEnvironment.Append(CCFLAGS = '/wd4996') - commonEnvironment.Append(CCFLAGS = '/MP') - commonEnvironment.Append(CCFLAGS = '/GR') - commonEnvironment.Append(CCFLAGS = '/G7') - commonEnvironment.Append(CCFLAGS = '/D_SCL_SECURE_NO_DEPRECATE') - commonEnvironment.Prepend(CCFLAGS = Split('''/Zi /D_NDEBUG /DNDEBUG''')) - commonEnvironment.Prepend(LINKFLAGS = Split('''/INCREMENTAL:NO /OPT:REF /OPT:ICF /DEBUG''')) - commonEnvironment.Prepend(SHLINKFLAGS = Split('''/INCREMENTAL:NO /OPT:REF /OPT:ICF /DEBUG''')) - # With Visual C++ it is now necessary to embed the manifest into the target. - commonEnvironment['LINKCOM'] = [commonEnvironment['LINKCOM'], - 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;1'] - commonEnvironment['SHLINKCOM'] = [commonEnvironment['SHLINKCOM'], - 'mt.exe -nologo -manifest ${TARGET}.manifest -outputresource:$TARGET;2'] - if compilerMicrosoft(): - commonEnvironment.Append(CCFLAGS = '/arch:sse') - if compilerIntel(): - print 'Generating code optimized for Intel Core 2 Duo and Pentium 4 that will run on other processors also.' - commonEnvironment.Append(CCFLAGS = Split('/O3 /QaxTP')) - -if getPlatform() == 'linux': - path1 = '/usr/include/python%s' % commonEnvironment['pythonVersion'] - path2 = '/usr/local/include/python%s' % commonEnvironment['pythonVersion'] - pythonIncludePath = [path1, path2] - path1 = '/usr/include/tcl%s' % commonEnvironment['tclversion'] - path2 = '/usr/include/tk%s' % commonEnvironment['tclversion'] - tclIncludePath = [path1, path2] - pythonLinkFlags = [] - if commonEnvironment['Lib64'] == '1': - tmp = '/usr/lib64/python%s/config' % commonEnvironment['pythonVersion'] - pythonLibraryPath = ['/usr/local/lib64', '/usr/lib64', tmp] - else: - tmp = '/usr/lib/python%s/config' % commonEnvironment['pythonVersion'] - pythonLibraryPath = ['/usr/local/lib', '/usr/lib', tmp] - pythonLibs = ['python%s' % commonEnvironment['pythonVersion']] -elif getPlatform() == 'sunos': - path1 = '/usr/include/python%s' % commonEnvironment['pythonVersion'] - path2 = '/usr/local/include/python%s' % commonEnvironment['pythonVersion'] - pythonIncludePath = [path1, path2] - pythonLinkFlags = [] - if commonEnvironment['Lib64'] == '1': - pythonLibraryPath = ['/usr/local/lib/64', '/usr/lib/64'] - else: - pythonLibraryPath = ['/usr/local/lib', '/usr/lib'] - pythonLibs = ['python%s' % commonEnvironment['pythonVersion']] - tclIncludePath = [] -elif getPlatform() == 'darwin': - # find Mac OS X major version - fout = os.popen("uname -r") - kernelstr = fout.readline() - fout.close() - OSXvers = int(kernelstr[:kernelstr.find('.')]) - 4 - print "Mac OS X version 10.%d" % OSXvers - # dictionary mapping OS X version to Apple Python version - # ex. 4:3 maps OS X 10.4 to Python 2.3 - # Note that OS X 10.2 did not ship with a Python framework - # and 10.0 and 10.1 shipped with no Python at all - OSXSystemPythonVersions = { 0:0, 1:0, 2:2, 3:3, 4:3, 5:5, 6:6, 7:7 } - sysPyVers = OSXSystemPythonVersions[OSXvers] - if OSXvers >= 2: - print "Apple Python version is 2.%d" % sysPyVers - # vers = (int(sys.hexversion) >> 24, (int(sys.hexversion) >> 16) & 255) - vers = sys.version_info - pvers = "%s.%s" % (vers[0], vers[1]) - # This logic is not quite right on OS X 10.2 and earlier - # or if the MacPython version equals the expected Apple Python version - if vers[1] == sysPyVers: - print "Current Python version is %s, using Apple Python Framework" % pvers - pyBasePath = '/System/Library/Frameworks' - else: - print "Current Python version is %s, using MacPython Framework" % pvers - pyBasePath = '/Library/Frameworks' - if commonEnvironment['pythonVersion'] != pvers: - commonEnvironment['pythonVersion'] = pvers - print "WARNING python version used is " + pvers - pythonIncludePath = ['%s/Python.Framework/Headers' % pyBasePath] - pythonLinkFlags = [ '-F' + pyBasePath, '-framework', 'python'] - path1 = '%s/Python.framework/Versions/Current/lib' % pyBasePath - path2 = '%s/python%s/config' % (path1, commonEnvironment['pythonVersion']) - pythonLibraryPath = [path1, path2] - pythonLibs = [] - tclIncludePath = [] -elif getPlatform() == 'win32': - pythonIncludePath = [] - pythonLinkFlags = [] - pythonLibraryPath = [] - tclIncludePath = [] - pythonLibs = ['python%s' % commonEnvironment['pythonVersion'].replace('.', '')] -else: - pythonIncludePath = [] - pythonLinkFlags = [] - pythonLibaryPath = [] - tclIncludePath = [] - pythonLibs = [] - - -# Check for prerequisites. -# We check only for headers; checking for libs may fail -# even if they are present, due to secondary dependencies. - -libsndfileTests = [ - 'int foobar(void)\n{\nreturn (int) SF_FORMAT_SD2;\n}', - 'int foobar(SF_INSTRUMENT *p)\n{\nreturn (int) p->loop_count;\n}', - 'int foobar(void)\n{\nreturn (int) SFC_GET_SIGNAL_MAX;\n}' -] - -def CheckSndFile1011(context): - context.Message('Checking for libsndfile version 1.0.11 or later... ') - testProgram = '\n#include \n\n' + libsndfileTests[0] + '\n\n' - result = context.TryCompile(testProgram, '.c') - context.Result(result) - return result - -def CheckSndFile1013(context): - context.Message('Checking for libsndfile version 1.0.13 or later... ') - testProgram = '\n#include \n\n' + libsndfileTests[1] + '\n\n' - result = context.TryCompile(testProgram, '.c') - context.Result(result) - return result - -def CheckSndFile1016(context): - context.Message('Checking for libsndfile version 1.0.16 or later... ') - testProgram = '\n#include \n\n' + libsndfileTests[2] + '\n\n' - result = context.TryCompile(testProgram, '.c') - context.Result(result) - return result - -def CheckGcc4(context): - # We need gcc4 if we want -fvisibility=hidden - context.Message('Checking for gcc version 4 or later... ') - testProgram = '''int main() { - #if __GNUC__ >= 4 - /* OK */ - return 0; - #else /* GCC < 4.0 */ - #error __GNUC__ < 4 - #endif - } - ''' - result = context.TryCompile(testProgram, '.c' ) - context.Result(result) - return result - -configure = commonEnvironment.Configure(custom_tests = { - 'CheckSndFile1011' : CheckSndFile1011, - 'CheckSndFile1013' : CheckSndFile1013, - 'CheckSndFile1016' : CheckSndFile1016, - 'CheckGcc4' : CheckGcc4 -}) - -if not configure.CheckHeader("stdio.h", language = "C"): - print " *** Failed to compile a simple test program. The compiler is" - print " *** possibly not set up correctly, or is used with invalid flags." - print " *** Check config.log to find out more about the error." - Exit(-1) -if not configure.CheckLibWithHeader("sndfile", "sndfile.h", language = "C"): - print "The sndfile library is required to build Csound 5." - Exit(-1) -if not configure.CheckLibWithHeader("pthread", "pthread.h", language = "C"): - print "The pthread library is required to build Csound 5." - Exit(-1) - -# Support for GEN49 (load MP3 file) - -if commonEnvironment['includeWii'] != '0' and configure.CheckHeader("wiiuse.h", language = "C"): - wiifound = 1 - wiiversion = commonEnvironment['includeWii'] - print 'CONFIGURATION DECISION: Building with Wiimote support' -else: - wiifound = 0 - print 'CONFIGURATION DECISION: No Wiimote support' - -if commonEnvironment['includeP5Glove'] == '1' : - p5gfound = 1 - print 'CONFIGURATION DECISION: Building with P5 Glove support' -else: - p5gfound = 0 - print 'CONFIGURATION DECISION: No P5 Glove support' - -if commonEnvironment['includeSerial'] == '1' : - serialfound = 1 - print 'CONFIGURATION DECISION: Building with Serial code support' -else: - serialfound = 0 - print 'CONFIGURATION DECISION: No Serial code support' - - -#pthreadSpinlockFound = configure.CheckLibWithHeader('pthread', 'pthread.h', 'C', 'pthread_spin_lock(0);') -if getPlatform() != 'darwin': # pthreadSpinlockFound: - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_PTHREAD_SPIN_LOCK']) -pthreadBarrierFound = configure.CheckLibWithHeader('pthread', 'pthread.h', 'C', 'pthread_barrier_init(0, NULL, 0);') -if pthreadBarrierFound: - print 'CONFIGURATION DECISION: Using HAVE_PTHREAD_BARRIER_INIT' - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_PTHREAD_BARRIER_INIT']) -else: - print 'CONFIGURATION DECISION: Not using HAVE_PTHREAD_BARRIER_INIT' -openMpFound = configure.CheckLibWithHeader('gomp', 'omp.h', 'C++', 'int n = omp_get_num_threads();') -if openMpFound and pthreadBarrierFound and commonEnvironment['useOpenMP'] == '1': - print 'CONFIGURATION DECISION: Using OpenMP.' - commonEnvironment.Append(CFLAGS = ['-fopenmp']) - commonEnvironment.Append(CXXFLAGS = ['-fopenmp']) - commonEnvironment.Append(CPPFLAGS = ['-DUSE_OPENMP']) - useOpenMP = True; -else: - useOpenMP = False; -if compilerMicrosoft(): - syncLockTestAndSetFound = False -else: - syncLockTestAndSetFound = configure.CheckLibWithHeader('m', 'stdint.h', 'C', '__sync_lock_test_and_set((int32_t *)0, 0);') -if syncLockTestAndSetFound: - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_SYNC_LOCK_TEST_AND_SET']) - print 'found sync lock' -vstSdkFound = configure.CheckHeader("frontends/CsoundVST/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.h", language = "C++") -portaudioFound = configure.CheckHeader("portaudio.h", language = "C") -#portmidiFound = configure.CheckHeader("portmidi.h", language = "C") -portmidiFound = configure.CheckHeader("portmidi.h", language = "C") -fltkFound = configure.CheckHeader("FL/Fl.H", language = "C++") -if fltkFound: - fltk117Found = configure.CheckHeader("FL/Fl_Spinner.H", language = "C++") -else: - fltk117Found = 0 -eigenFound = configure.CheckHeader("eigen3/Eigen/Dense", language = "C++") -boostFound = configure.CheckHeader("boost/any.hpp", language = "C++") -gmmFound = configure.CheckHeader("gmm/gmm.h", language = "C++") -alsaFound = configure.CheckLibWithHeader("asound", "alsa/asoundlib.h", language = "C") -oscFound = configure.CheckHeader("lo/lo.h", language = "C") -musicXmlFound = configure.CheckLibWithHeader('musicxml2', 'xmlfile.h', 'C++', 'MusicXML2::SXMLFile f = MusicXML2::TXMLFile::create();', autoadd=0) -if musicXmlFound: - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_MUSICXML2']) - -jackFound = configure.CheckHeader("jack/jack.h", language = "C") -pulseaudioFound = configure.CheckHeader("pulse/simple.h", language = "C") -stkFound = configure.CheckHeader("Opcodes/stk/include/Stk.h", language = "C++") -pdhfound = configure.CheckHeader("m_pd.h", language = "C") -tclhfound = configure.CheckHeader("tcl.h", language = "C") -if not tclhfound: - for i in tclIncludePath: - tmp = '%s/tcl.h' % i - tclhfound = tclhfound or configure.CheckHeader(tmp, language = "C") -zlibhfound = configure.CheckHeader("zlib.h", language = "C") -midiPluginSdkFound = configure.CheckHeader("funknown.h", language = "C++") -luaFound = configure.CheckHeader("lua.h", language = "C") -#print 'LUA: %s' % (['no', 'yes'][int(luaFound)]) -swigFound = 'swig' in commonEnvironment['TOOLS'] -print 'Checking for SWIG... %s' % (['no', 'yes'][int(swigFound)]) -print "Python Version: " + commonEnvironment['pythonVersion'] -pythonFound = configure.CheckHeader("Python.h", language = "C") -if not pythonFound: - if getPlatform() == 'darwin': - pythonFound = configure.CheckHeader('%s/Python.h' % pythonIncludePath[0], language = "C") - else: - for i in pythonIncludePath: - tmp = '%s/Python.h' % i - pythonFound = pythonFound or configure.CheckHeader(tmp, language = "C") -if getPlatform() == 'darwin': - tmp = "/System/Library/Frameworks/JavaVM.framework/Headers/jni.h" - javaFound = configure.CheckHeader(tmp, language = "C++") -else: - javaFound = configure.CheckHeader("jni.h", language = "C++") -if getPlatform() == 'linux' and not javaFound: - if commonEnvironment['buildInterfaces'] != '0': - if commonEnvironment['buildJavaWrapper'] != '0': - baseDir = '/usr/lib' - if commonEnvironment['Lib64'] == '1': - baseDir += '64' - for i in ['java', 'jvm/java', 'jvm/java-1.5.0']: - javaIncludePath = '%s/%s/include' % (baseDir, i) - tmp = '%s/linux/jni_md.h' % javaIncludePath - if configure.CheckHeader(tmp, language = "C++"): - javaFound = 1 - break - if javaFound: - commonEnvironment.Append(CPPPATH = [javaIncludePath]) - commonEnvironment.Append(CPPPATH = [javaIncludePath + '/linux']) - -if getPlatform() == 'win32': - commonEnvironment['ENV']['PATH'] = os.environ['PATH'] - commonEnvironment['SYSTEMROOT'] = os.environ['SYSTEMROOT'] - -if (commonEnvironment['useFLTK'] == '1' and fltkFound): - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_FLTK']) - -if vstSdkFound: - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_VST_SDK']) - - -# Define macros that configure and config.h used to define. -headerMacroCheck = [ - ['io.h', '-DHAVE_IO_H' ], - ['fcntl.h', '-DHAVE_FCNTL_H' ], - ['unistd.h', '-DHAVE_UNISTD_H' ], - ['stdint.h', '-DHAVE_STDINT_H' ], - ['sys/time.h', '-DHAVE_SYS_TIME_H' ], - ['sys/types.h', '-DHAVE_SYS_TYPES_H'], - ['termios.h', '-DHAVE_TERMIOS_H' ], - ['values.h', '-DHAVE_VALUES_H' ]] - -for h in headerMacroCheck: - if configure.CheckHeader(h[0], language = "C"): - commonEnvironment.Append(CPPFLAGS = [h[1]]) - -if getPlatform() == 'win32': - if configure.CheckHeader("winsock.h", language = "C"): - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_SOCKETS']) -elif configure.CheckHeader("sys/socket.h", language = "C"): - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_SOCKETS']) - -if getPlatform() == 'darwin': - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_DIRENT_H']) -elif configure.CheckHeader("dirent.h", language = "C"): - commonEnvironment.Append(CPPFLAGS = ['-DHAVE_DIRENT_H']) - -if configure.CheckSndFile1016(): - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_LIBSNDFILE=1016']) -elif configure.CheckSndFile1013(): - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_LIBSNDFILE=1013']) -elif configure.CheckSndFile1011(): - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_LIBSNDFILE=1011']) -else: - commonEnvironment.Prepend(CPPFLAGS = ['-DHAVE_LIBSNDFILE=1000']) - -# Package contents. - -# library version is CS_VERSION.CS_APIVERSION -csoundLibraryVersion = '5.2' -csoundLibraryName = 'csound' -if commonEnvironment['useDouble'] != '0': - csoundLibraryName += '64' -elif getPlatform() == 'win32': - csoundLibraryName += '32' -# flags for linking with the Csound library -libCsoundLinkFlags = commonEnvironment['LINKFLAGS'] -if getPlatform() == 'sunos': - libCsoundLibs = ['sndfile', 'socket', 'rt', 'nsl'] -else: - libCsoundLibs = ['sndfile'] - -buildOSXFramework = 0 -if getPlatform() == 'darwin': - if commonEnvironment['dynamicCsoundLibrary'] != '0': - buildOSXFramework = 1 - CsoundLib_OSX = 'CsoundLib' - # comment the next two lines out to disable building a separate - # framework (CsoundLib64) for double precision - if commonEnvironment['useDouble'] != '0': - CsoundLib_OSX += '64' - OSXFrameworkBaseDir = '%s.framework' % CsoundLib_OSX - tmp = OSXFrameworkBaseDir + '/Versions/%s' - OSXFrameworkCurrentVersion = tmp % csoundLibraryVersion - -if getPlatform() == "win32": - Tool('lex')(commonEnvironment) - Tool('yacc')(commonEnvironment) -csoundLibraryEnvironment = commonEnvironment.Clone() - -if commonEnvironment['buildMultiCore'] != '0': - if commonEnvironment['buildNewParser'] != '0': - csoundLibraryEnvironment.Append(CPPFLAGS = ['-DPARCS']) - -if commonEnvironment['buildNewParser'] != '0': - if commonEnvironment['buildMultiCore'] != '0': - csoundLibraryEnvironment.Append(CPPFLAGS = ['-DPARCS']) - print 'CONFIGURATION DECISION: Building with new parser enabled' - reportflag='--report=itemset' - csoundLibraryEnvironment.Append(YACCFLAGS = ['-d', reportflag, '-p','csound_orc']) - csoundLibraryEnvironment.Append(LEXFLAGS = ['-B']) - csoundLibraryEnvironment.Append(CPPFLAGS = ['-DENABLE_NEW_PARSER']) - csoundLibraryEnvironment.Append(CPPPATH = ['Engine']) - yaccBuild = csoundLibraryEnvironment.CFile(target = 'Engine/csound_orcparse.c', - source = 'Engine/csound_orc.y') - lexBuild = csoundLibraryEnvironment.CFile(target = 'Engine/csound_orclex.c', - source = 'Engine/csound_orc.l') - preBuild = csoundLibraryEnvironment.CFile(target = 'Engine/csound_prelex.c', - source = 'Engine/csound_pre.lex') - if commonEnvironment['NewParserDebug'] != '0': - print 'CONFIGURATION DECISION: Building with new parser debugging' - csoundLibraryEnvironment.Append(CPPFLAGS = ['-DPARSER_DEBUG=1']) - else: print 'CONFIGURATION DECISION: Not building with new parser debugging' -else: - print 'CONFIGURATION DECISION: Not building with new parser' - -csoundLibraryEnvironment.Append(CPPFLAGS = ['-D__BUILDING_LIBCSOUND']) -if commonEnvironment['buildRelease'] != '0': - csoundLibraryEnvironment.Append(CPPFLAGS = ['-D_CSOUND_RELEASE_']) - if getPlatform() == 'linux': - if commonEnvironment['Lib64'] == '0': - tmp = '%s/lib/csound/plugins' % commonEnvironment['prefix'] - else: - tmp = '%s/lib64/csound/plugins' % commonEnvironment['prefix'] - if commonEnvironment['useDouble'] != '0': - tmp += '64' - s = '-DCS_DEFAULT_PLUGINDIR=\\"%s\\"' % tmp - csoundLibraryEnvironment.Append(CPPFLAGS = [s]) - elif buildOSXFramework != 0: - tmp = '/Library/Frameworks/%s' % OSXFrameworkCurrentVersion - tmp += '/Resources/Opcodes' - if commonEnvironment['useDouble'] != '0': - tmp += '64' - s = '-DCS_DEFAULT_PLUGINDIR=\\"%s\\"' % tmp - csoundLibraryEnvironment.Append(CPPFLAGS = [s]) -csoundDynamicLibraryEnvironment = csoundLibraryEnvironment.Clone() -csoundDynamicLibraryEnvironment.Append(LIBS = ['sndfile']) -if getPlatform() == 'win32': - # These are the Windows system call libraries. - if compilerGNU(): - csoundWindowsLibraries = Split(''' -setupapi -advapi32 -comctl32 -comdlg32 -glu32 -kernel32 -msvcrt -odbc32 -odbccp32 -ole32 -oleaut32 -shell32 -user32 -uuid -winmm -winspool -ws2_32 -wsock32 -setupapi -advapi32 -comctl32 -comdlg32 -glu32 -kernel32 -odbc32 -odbccp32 -ole32 -oleaut32 -shell32 -user32 -uuid -winmm -winspool -ws2_32 - ''') - else: - csoundWindowsLibraries = Split(''' - setupapi kernel32 gdi32 wsock32 ole32 uuid winmm user32.lib ws2_32.lib - comctl32.lib gdi32.lib comdlg32.lib advapi32.lib shell32.lib - ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib - setupapi kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib - advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib - odbc32.lib odbccp32.lib pthread.lib - ''') - if commonEnvironment['bufferoverflowu'] != '0': - csoundWindowsLibraries.append('bufferoverflowu') - csoundDynamicLibraryEnvironment.Append(LIBS = csoundWindowsLibraries) - if compilerGNU(): - csoundDynamicLibraryEnvironment.Append(SHLINKFLAGS = ['-module']) -elif getPlatform() == 'linux' or getPlatform() == 'sunos' or getPlatform() == 'darwin': - csoundDynamicLibraryEnvironment.Append(LIBS = ['dl', 'm', 'pthread']) -csoundInterfacesEnvironment = csoundDynamicLibraryEnvironment.Clone() - -if buildOSXFramework: - csoundFrameworkEnvironment = csoundDynamicLibraryEnvironment.Clone() - # create directory structure for the framework - if commonEnvironment['buildNewParser'] != '0': - csoundFrameworkEnvironment.Append(LINKFLAGS=["-Wl,-single_module"]) - tmp = [OSXFrameworkBaseDir] - tmp += ['%s/Versions' % OSXFrameworkBaseDir] - tmp += [OSXFrameworkCurrentVersion] - tmp += ['%s/Headers' % OSXFrameworkCurrentVersion] - tmp += ['%s/Resources' % OSXFrameworkCurrentVersion] - if commonEnvironment['useDouble'] == '0': - tmp += ['%s/Resources/Opcodes' % OSXFrameworkCurrentVersion] - else: - tmp += ['%s/Resources/Opcodes64' % OSXFrameworkCurrentVersion] - for i in tmp: - try: - os.mkdir(i, 0755) - except: - pass - # set up symbolic links - tmp = [['/Versions/Current', csoundLibraryVersion]] - tmp += [['/' + CsoundLib_OSX, 'Versions/Current/' + CsoundLib_OSX]] - tmp += [['/Headers', 'Versions/Current/Headers']] - tmp += [['/Resources', 'Versions/Current/Resources']] - for i in tmp: - try: - os.remove('%s/%s' % (OSXFrameworkBaseDir, i[0])) - except: - pass - os.symlink(i[1], '%s/%s' % (OSXFrameworkBaseDir, i[0])) - -def MacOSX_InstallHeader(headerName): - if not buildOSXFramework: - return - baseName = headerName[(headerName.rfind('/') + 1):] - targetName = '%s/Headers/%s' % (OSXFrameworkCurrentVersion, baseName) - # to set USE_DOUBLE in installed headers - cmd = 'cp -f %s %s' % (headerName, targetName) - if commonEnvironment['useDouble'] != '0': - if baseName == 'float-version.h': - cmd = 'cp -f %s %s' % ('H/float-version-double.h', targetName) - csoundFrameworkEnvironment.Command(targetName, headerName, cmd) - -def MacOSX_InstallPlugin(fileName): - if buildOSXFramework: - print "COPYINNG plugin" - pluginDir = '%s/Resources/Opcodes' % OSXFrameworkCurrentVersion - if commonEnvironment['useDouble'] != '0': - pluginDir += '64' - cmd = 'cp -f %s %s/' % (fileName, pluginDir) - csoundFrameworkEnvironment.Command('%s/%s' % (pluginDir, fileName), - fileName, cmd) - -def makePlugin(env, pluginName, srcs): - pluginLib = env.SharedLibrary(pluginName, srcs) - pluginLibraries.append(pluginLib) - MacOSX_InstallPlugin('lib' + pluginName + '.dylib') - return pluginLib - -libCsoundSources = Split(''' -Engine/auxfd.c -Engine/cfgvar.c -Engine/corfiles.c -Engine/entry1.c -Engine/envvar.c -Engine/express.c -Engine/extract.c -Engine/fgens.c -Engine/insert.c -Engine/linevent.c -Engine/memalloc.c -Engine/memfiles.c -Engine/musmon.c -Engine/namedins.c -Engine/otran.c -Engine/rdorch.c -Engine/rdscor.c -Engine/scsort.c -Engine/scxtract.c -Engine/sort.c -Engine/sread.c -Engine/swrite.c -Engine/swritestr.c -Engine/twarp.c -InOut/libsnd.c -InOut/libsnd_u.c -InOut/midifile.c -InOut/midirecv.c -InOut/midisend.c -InOut/winascii.c -InOut/windin.c -InOut/window.c -InOut/winEPS.c -InOut/libmpadec/layer1.c -InOut/libmpadec/layer2.c -InOut/libmpadec/layer3.c -InOut/libmpadec/synth.c -InOut/libmpadec/tables.c -InOut/libmpadec/mpadec.c -InOut/libmpadec/mp3dec.c -OOps/aops.c -OOps/bus.c -OOps/cmath.c -OOps/diskin.c -OOps/diskin2.c -OOps/disprep.c -OOps/dumpf.c -OOps/fftlib.c -OOps/goto_ops.c -OOps/midiinterop.c -OOps/midiops.c -OOps/midiout.c -OOps/mxfft.c -OOps/oscils.c -OOps/pstream.c -OOps/pvfileio.c -OOps/pvsanal.c -OOps/random.c -OOps/remote.c -OOps/schedule.c -OOps/sndinfUG.c -OOps/str_ops.c -OOps/ugens1.c -OOps/ugens2.c -OOps/ugens2a.c -OOps/ugens3.c -OOps/ugens4.c -OOps/ugens5.c -OOps/ugens6.c -OOps/ugrw1.c -OOps/ugrw2.c -OOps/vdelay.c -Opcodes/Vosim.c -Opcodes/babo.c -Opcodes/bilbar.c -Opcodes/compress.c -Opcodes/eqfil.c -Opcodes/ftest.c -Top/argdecode.c -Top/cscore_internal.c -Top/cscorfns.c -Top/csmodule.c -Top/csound.c -Top/getstring.c -Top/main.c -Top/new_opts.c -Top/one_file.c -Top/opcode.c -Top/threads.c -Top/utility.c -''') - -newParserSources = Split(''' -Engine/csound_prelex.c -Engine/csound_orclex.c -Engine/csound_orcparse.c -Engine/csound_orc_semantics.c -Engine/csound_orc_expressions.c -Engine/csound_orc_optimize.c -Engine/csound_orc_compile.c -Engine/symbtab.c -Engine/new_orc_parser.c -''') - -MultiCoreSources = Split(''' -Engine/cs_par_base.c -Engine/cs_par_orc_semantic_analysis.c -Engine/cs_par_dispatch.c -''') - -stdopcodes = Split(''' - Opcodes/ambicode.c Opcodes/bbcut.c Opcodes/biquad.c - Opcodes/butter.c Opcodes/clfilt.c Opcodes/cross2.c - Opcodes/dam.c Opcodes/dcblockr.c Opcodes/filter.c - Opcodes/flanger.c Opcodes/follow.c Opcodes/fout.c - Opcodes/freeverb.c Opcodes/ftconv.c Opcodes/ftgen.c - Opcodes/gab/gab.c Opcodes/gab/vectorial.c Opcodes/grain.c - Opcodes/locsig.c Opcodes/lowpassr.c Opcodes/metro.c - Opcodes/midiops2.c Opcodes/midiops3.c Opcodes/newfils.c - Opcodes/nlfilt.c Opcodes/oscbnk.c Opcodes/pluck.c - Opcodes/repluck.c Opcodes/reverbsc.c Opcodes/seqtime.c - Opcodes/sndloop.c Opcodes/sndwarp.c Opcodes/space.c - Opcodes/spat3d.c Opcodes/syncgrain.c Opcodes/ugens7.c - Opcodes/ugens9.c Opcodes/ugensa.c Opcodes/uggab.c - Opcodes/ugmoss.c Opcodes/ugnorman.c Opcodes/ugsc.c - Opcodes/wave-terrain.c Opcodes/stdopcod.c - ''') - -pvs_opcodes = Split(''' - Opcodes/ifd.c Opcodes/partials.c Opcodes/psynth.c Opcodes/pvsbasic.c - Opcodes/pvscent.c Opcodes/pvsdemix.c Opcodes/pvs_ops.c Opcodes/pvsband.c - Opcodes/pvsbuffer.c -''') - -folded_ops = Split('''Opcodes/modmatrix.c Opcodes/scoreline.c Opcodes/modal4.c -Opcodes/physutil.c Opcodes/physmod.c Opcodes/mandolin.c Opcodes/singwave.c -Opcodes/fm4op.c Opcodes/moog1.c Opcodes/shaker.c Opcodes/bowedbar.c -Opcodes/pitch.c Opcodes/pitch0.c Opcodes/spectra.c Opcodes/ambicode1.c -Opcodes/sfont.c Opcodes/grain4.c Opcodes/hrtferX.c Opcodes/loscilx.c -Opcodes/minmax.c Opcodes/pan2.c Opcodes/tabvars.c Opcodes/phisem.c -Opcodes/hrtfopcodes.c Opcodes/stackops.c Opcodes/vbap.c -Opcodes/vbap_eight.c Opcodes/vbap_four.c Opcodes/vbap_sixteen.c -Opcodes/vbap_zak.c Opcodes/vaops.c Opcodes/ugakbari.c Opcodes/harmon.c -Opcodes/pitchtrack.c Opcodes/partikkel.c Opcodes/shape.c Opcodes/tabsum.c -Opcodes/crossfm.c Opcodes/pvlock.c Opcodes/fareyseq.c Opcodes/hrtfearly.c -Opcodes/hrtfreverb.c Opcodes/cpumeter.c Opcodes/mp3in.c Opcodes/gendy.c -Opcodes/tl/sc_noise.c -''') - -oldpvoc = Split(''' - Opcodes/dsputil.c Opcodes/pvadd.c Opcodes/pvinterp.c Opcodes/pvocext.c - Opcodes/pvread.c Opcodes/ugens8.c Opcodes/vpvoc.c Opcodes/pvoc.c -''') - -gabnewopc = Split(''' - Opcodes/gab/tabmorph.c Opcodes/gab/hvs.c - Opcodes/gab/sliderTable.c - Opcodes/gab/newgabopc.c''') - -libCsoundSources += stdopcodes -libCsoundSources += pvs_opcodes -libCsoundSources += folded_ops -libCsoundSources += oldpvoc -libCsoundSources += gabnewopc - -if commonEnvironment['buildMultiCore'] != '0': - if commonEnvironment['buildNewParser'] != '0': - libCsoundSources += MultiCoreSources - -if commonEnvironment['buildNewParser'] != '0': - libCsoundSources += newParserSources - -csoundLibraryEnvironment.Append(CCFLAGS='-fPIC') -if commonEnvironment['dynamicCsoundLibrary'] == '1': - print 'CONFIGURATION DECISION: Building dynamic Csound library' - if getPlatform() == 'linux' or getPlatform() == 'sunos': - libName = 'lib' + csoundLibraryName + '.so' - libName2 = libName + '.' + csoundLibraryVersion - os.spawnvp(os.P_WAIT, 'rm', ['rm', '-f', libName]) - os.symlink(libName2, libName) - tmp = csoundDynamicLibraryEnvironment['SHLINKFLAGS'] - if compilerSun(): - tmp = tmp + ['-soname=%s' % libName2] - else: - tmp = tmp + ['-Wl,-soname=%s' % libName2] - cflags = csoundDynamicLibraryEnvironment['CCFLAGS'] - if configure.CheckGcc4(): - cflags += ['-fvisibility=hidden'] - csoundLibrary = csoundDynamicLibraryEnvironment.SharedLibrary( - libName2, libCsoundSources, - SHLINKFLAGS = tmp, SHLIBPREFIX = '', SHLIBSUFFIX = '', - CCFLAGS = cflags) - elif getPlatform() == 'darwin': - libName = CsoundLib_OSX - libVersion = csoundLibraryVersion - csoundFrameworkEnvironment.Append(SHLINKFLAGS = Split(''' - -Xlinker -compatibility_version -Xlinker %s - ''' % libVersion)) - csoundFrameworkEnvironment.Append(SHLINKFLAGS = Split(''' - -Xlinker -current_version -Xlinker %s - ''' % libVersion)) - csoundFrameworkEnvironment.Append(SHLINKFLAGS = Split(''' - -install_name /Library/Frameworks/%s/%s - ''' % (OSXFrameworkCurrentVersion, libName))) - csoundLibraryFile = csoundFrameworkEnvironment.SharedLibrary( - libName, libCsoundSources, SHLIBPREFIX = '', SHLIBSUFFIX = '') - csoundFrameworkEnvironment.Command( - '%s/%s' % (OSXFrameworkCurrentVersion, libName), - libName, - 'cp -f %s %s/' % (libName, OSXFrameworkCurrentVersion)) - for i in headers: - MacOSX_InstallHeader(i) - csoundLibrary = csoundFrameworkEnvironment.Command( - 'CsoundLib_install', - libName, - 'rm -r /Library/Frameworks/%s; cp -R %s /Library/Frameworks/' % (OSXFrameworkBaseDir, OSXFrameworkBaseDir)) - libCsoundLinkFlags += ['-F.', '-framework', libName, '-lsndfile'] - libCsoundLibs = [] - elif getPlatform() == 'win32': - csoundLibrary = csoundDynamicLibraryEnvironment.SharedLibrary( - csoundLibraryName, libCsoundSources, - SHLIBSUFFIX = '.dll.%s' % csoundLibraryVersion) - else: - csoundLibrary = csoundDynamicLibraryEnvironment.SharedLibrary( - csoundLibraryName, libCsoundSources) -else: - print 'CONFIGURATION DECISION: Building static Csound library' - csoundLibraryEnvironment.Append(CCFLAGS='-fPIC') - csoundLibrary = csoundLibraryEnvironment.Library( - csoundLibraryName, libCsoundSources) -if getPlatform() == 'linux' or getPlatform() == 'sunos': - # We need the library before sndfile in case we are building a static - # libcsound and passing -Wl,-as-needed - libCsoundLibs.insert(0,csoundLibrary) -elif getPlatform() == 'win32' or (getPlatform() == 'darwin' and commonEnvironment['dynamicCsoundLibrary']=='0'): - libCsoundLibs.append(csoundLibraryName) -libs.append(csoundLibrary) - -pluginEnvironment = commonEnvironment.Clone() -pluginEnvironment.Append(LIBS = Split('sndfile')) - -if getPlatform() == 'darwin': - pluginEnvironment.Append(LINKFLAGS = Split(''' - -framework CoreMIDI -framework CoreFoundation -framework CoreServices -framework CoreAudio - ''')) - # pluginEnvironment.Append(LINKFLAGS = ['-dynamiclib']) - pluginEnvironment['SHLIBSUFFIX'] = '.dylib' - # pluginEnvironment.Prepend(CXXFLAGS = "-fno-rtti") - -############################################################################# -# -# Build csound command line front end -############################################################################# - -csoundProgramEnvironment = commonEnvironment.Clone() -csoundProgramEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) -csoundProgramEnvironment.Append(LIBS = libCsoundLibs) - - -############################################################################# -# -# DEFINE TARGETS AND SOURCES -# -############################################################################# - -if getPlatform() == 'win32': - PYDLL = r'%s\%s' % (os.environ['SystemRoot'], pythonLibs[0]) -if getPlatform() == 'win32' and pythonLibs[0] < 'python24' and compilerGNU(): - pythonImportLibrary = csoundInterfacesEnvironment.Command( - '/usr/local/lib/lib%s.a' % (pythonLibs[0]), - PYDLL, - ['pexports %s > %s.def' % (PYDLL, pythonLibs[0]), - 'dlltool --input-def %s.def --dllname %s.dll --output-lib /usr/local/lib/lib%s.a' % (pythonLibs[0], PYDLL, pythonLibs[0])]) - -def fixCFlagsForSwig(env): - if '-pedantic' in env['CCFLAGS']: - env['CCFLAGS'].remove('-pedantic') - if '-pedantic' in env['CXXFLAGS']: - env['CXXFLAGS'].remove('-pedantic') - # if compilerGNU(): - # work around non-ANSI type punning in SWIG generated wrapper files - #if(getPlatform != 'darwin'): - #env['CCFLAGS'].append('-fno-strict-aliasing') - #env['CXXFLAGS'].append('-fno-strict-aliasing') - -def makePythonModule(env, targetName, sources): - if getPlatform() == 'darwin': - env.Prepend(LINKFLAGS = ['-bundle']) - pyModule_ = env.Program('_%s.so' % targetName, sources) - else: - if getPlatform() == 'linux' or getPlatform() == 'sunos': - pyModule_ = env.SharedLibrary('%s' % targetName, sources, SHLIBPREFIX="_", SHLIBSUFFIX = '.so') - else: - pyModule_ = env.SharedLibrary('_%s' % targetName, sources, SHLIBSUFFIX = '.pyd') - if getPlatform() == 'win32' and pythonLibs[0] < 'python24': - Depends(pyModule_, pythonImportLibrary) - print "PYTHON MODULE %s..." % targetName - pythonModules.append(pyModule_) - pythonModules.append('%s.py' % targetName) - return pyModule_ - -def makeLuaModule(env, targetName, srcs): - if getPlatform() == 'darwin': - env.Prepend(LINKFLAGS = ['-bundle']) - luaModule_ = env.Program('%s.so' % targetName, srcs) - else: - if getPlatform() == 'linux' or getPlatform() == 'sunos': - luaModule_ = env.SharedLibrary('%s' % targetName, srcs, SHLIBPREFIX="", SHLIBSUFFIX = '.so') - else: - luaModule_ = env.SharedLibrary('%s' % targetName, srcs, SHLIBSUFFIX = '.dll') - print "LUA MODULE %s..." % targetName - return luaModule_ - -# libcsnd.so is used by all wrapper libraries. - -if not (commonEnvironment['buildInterfaces'] == '1'): - print 'CONFIGURATION DECISION: Not building Csound C++ interface library.' -else: - print 'CONFIGURATION DECISION: Building Csound C++ interface library.' - csoundInterfacesEnvironment.Append(CPPPATH = ['interfaces']) - if musicXmlFound: - csoundInterfacesEnvironment.Prepend(LIBS = 'musicxml2') - csoundInterfacesSources = [] - headers += ['interfaces/csPerfThread.hpp'] - for i in Split('CppSound CsoundFile Soundfile csPerfThread cs_glue filebuilding'): - csoundInterfacesSources.append(csoundInterfacesEnvironment.SharedObject('interfaces/%s.cpp' % i)) - if commonEnvironment['dynamicCsoundLibrary'] == '1' or getPlatform() == 'win32': - csoundInterfacesEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - csoundInterfacesEnvironment.Prepend(LIBS = libCsoundLibs) - else: - for i in libCsoundSources: - csoundInterfacesSources.append(csoundInterfacesEnvironment.SharedObject(i)) - if getPlatform() == 'win32' and compilerGNU(): - csoundInterfacesEnvironment.Append(SHLINKFLAGS = '-Wl,--add-stdcall-alias') - elif getPlatform() == 'linux': - csoundInterfacesEnvironment.Prepend(LIBS = ['util']) - if compilerGNU() and getPlatform() != 'win32': - csoundInterfacesEnvironment.Prepend(LIBS = ['stdc++']) - if getPlatform() == 'darwin': - if commonEnvironment['dynamicCsoundLibrary'] == '1': - ilibName = "lib_csnd.dylib" - ilibVersion = csoundLibraryVersion - csoundInterfacesEnvironment.Append(SHLINKFLAGS = Split( - '''-Xlinker -compatibility_version - -Xlinker %s''' % ilibVersion)) - csoundInterfacesEnvironment.Append(SHLINKFLAGS = Split( - '''-Xlinker -current_version -Xlinker %s''' % ilibVersion)) - tmp = '''-install_name - /Library/Frameworks/%s/%s''' - csoundInterfacesEnvironment.Append(SHLINKFLAGS = Split( - tmp % (OSXFrameworkCurrentVersion,ilibName))) - csnd = csoundInterfacesEnvironment.SharedLibrary( - '_csnd', csoundInterfacesSources) - try: os.symlink('lib_csnd.dylib', 'libcsnd.dylib') - except: pass - csoundInterfacesEnvironment.Command('interfaces install', csnd, "cp lib_csnd.dylib /Library/Frameworks/%s/lib_csnd.dylib" % (OSXFrameworkCurrentVersion)) - else: - csnd = csoundInterfacesEnvironment.Library('csnd', csoundInterfacesSources) - elif getPlatform() == 'linux': - csoundInterfacesEnvironment.Append(LINKFLAGS = ['-Wl,-rpath-link,interfaces']) - name = 'libcsnd.so' - soname = name + '.' + csoundLibraryVersion - # This works because scons chdirs while reading SConscripts - # When building stuff scons doesn't chdir by default! - try : os.symlink(soname, '%s' % name) - except : pass - Clean(soname, name) #Delete symlink on clean - linkflags = csoundInterfacesEnvironment['SHLINKFLAGS'] - soflag = [ '-Wl,-soname=%s' % soname ] - extraflag = ['-L.'] - csnd = csoundInterfacesEnvironment.SharedLibrary( - soname, csoundInterfacesSources, - SHLINKFLAGS = linkflags+soflag+extraflag, - SHLIBPREFIX = '', SHLIBSUFFIX = '') - else: - csnd = csoundInterfacesEnvironment.SharedLibrary('csnd', csoundInterfacesSources) - Depends(csnd, csoundLibrary) - libs.append(csnd) - - # Common stuff for SWIG for all wrappers. - - csoundWrapperEnvironment = csoundInterfacesEnvironment.Clone() - #csoundWrapperEnvironment.Append(LIBS = [csnd]) - csoundWrapperEnvironment.Append(SWIGFLAGS = Split('''-c++ -includeall -verbose ''')) - fixCFlagsForSwig(csoundWrapperEnvironment) - csoundWrapperEnvironment.Append(CPPFLAGS = ['-D__BUILDING_CSOUND_INTERFACES']) - for option in csoundWrapperEnvironment['CCFLAGS']: - if string.find(option, '-D') == 0: - csoundWrapperEnvironment.Append(SWIGFLAGS = [option]) - for option in csoundWrapperEnvironment['CPPFLAGS']: - if string.find(option, '-D') == 0: - csoundWrapperEnvironment.Append(SWIGFLAGS = [option]) - for option in csoundWrapperEnvironment['CPPPATH']: - option = '-I' + option - csoundWrapperEnvironment.Append(SWIGFLAGS = [option]) - swigflags = csoundWrapperEnvironment['SWIGFLAGS'] - print 'swigflags:', swigflags - luaWrapper = None - if not (luaFound and commonEnvironment['buildLuaWrapper'] != '0'): - print 'CONFIGURATION DECISION: Not building Lua wrapper to Csound C++ interface library.' - else: - print 'CONFIGURATION DECISION: Building Lua wrapper to Csound C++ interface library.' - luaWrapperEnvironment = csoundWrapperEnvironment.Clone() - if getPlatform() != 'win32': - csoundWrapperEnvironment.Append(CPPPATH=['/usr/include/lua5.1']) - if getPlatform() == 'win32': - csoundLuaInterface = luaWrapperEnvironment.SharedObject( - 'interfaces/lua_interface.i', - SWIGFLAGS = [swigflags, '-lua', '-module', 'luaCsnd', '-outdir', '.']) - luaWrapperEnvironment.Prepend(LIBS = ['csnd','lua51']) - else: - csoundLuaInterface = luaWrapperEnvironment.SharedObject( - 'interfaces/lua_interface.i', - SWIGFLAGS = [swigflags, '-lua', '-module', 'luaCsnd', '-outdir', '.']) - luaWrapperEnvironment.Prepend(LIBS = ['csnd','luajit-5.1']) - luaWrapper = makeLuaModule(luaWrapperEnvironment, 'luaCsnd', [csoundLuaInterface]) - Depends(luaWrapper, csoundLuaInterface) - - if not (javaFound and commonEnvironment['buildJavaWrapper'] != '0'): - print 'CONFIGURATION DECISION: Not building Java wrapper to Csound C++ interface library.' - else: - print 'CONFIGURATION DECISION: Building Java wrapper to Csound C++ interface library.' - javaWrapperEnvironment = csoundWrapperEnvironment.Clone() - if getPlatform() == 'darwin': - javaWrapperEnvironment.Append(LINKFLAGS = ['-L.', '-l_csnd']) - else: javaWrapperEnvironment.Prepend(LIBS = ['csnd']) - if getPlatform() == 'darwin': - javaWrapperEnvironment.Append(CPPPATH = - ['/System/Library/Frameworks/JavaVM.framework/Headers']) - if getPlatform() == 'linux' or getPlatform() == 'darwin': - # ugly hack to work around bug that requires running scons twice - tmp = [javaWrapperEnvironment['SWIG']] - for i in swigflags: - tmp += [i] - tmp += ['-java', '-package', 'csnd'] - tmp += ['-o', 'interfaces/java_interface_wrap.cc'] - tmp += ['interfaces/java_interface.i'] - if os.spawnvp(os.P_WAIT, tmp[0], tmp) != 0: - Exit(-1) - javaWrapperSources = [javaWrapperEnvironment.SharedObject( - 'interfaces/java_interface_wrap.cc')] - else: - javaWrapperSources = [javaWrapperEnvironment.SharedObject( - 'interfaces/java_interface.i', - SWIGFLAGS = [swigflags, '-java', '-package', 'csnd'])] - if getPlatform() == 'darwin': - if commonEnvironment['dynamicCsoundLibrary'] == '0': - if commonEnvironment['useDouble'] == '0': csoundlibLink = '-lcsound' - else: csoundlibLink = '-lcsound64' - else: csoundliblink = '' - javaWrapperEnvironment.Prepend(LINKFLAGS = ['-bundle']) - javaWrapperEnvironment.Append(LINKFLAGS = - ['-framework', 'JavaVM', '-Wl', csoundliblink]) - javaWrapper = javaWrapperEnvironment.Program( - 'lib_jcsound.jnilib', javaWrapperSources) - else: - javaWrapper = javaWrapperEnvironment.SharedLibrary( - '_jcsound', javaWrapperSources) - #Depends(javaWrapper, csoundLibrary) - Depends(javaWrapper, csnd) - libs.append(javaWrapper) - jcsnd = javaWrapperEnvironment.Java( - target = './interfaces', source = './interfaces', - JAVACFLAGS = ['-source', '5', '-target', '5']) - try: - os.mkdir('interfaces/csnd', 0755) - except: - pass - jcsndJar = javaWrapperEnvironment.Jar( - 'csnd.jar', ['interfaces/csnd'], JARCHDIR = 'interfaces') - Depends(jcsndJar, jcsnd) - libs.append(jcsndJar) - # Please do not remove these two variables, needed to get things to build on Windows... - pythonWrapper = None - if not (pythonFound and commonEnvironment['buildPythonWrapper'] != '0'): - print 'CONFIGURATION DECISION: Not building Python wrapper to Csound C++ interface library.' - else: - print 'CONFIGURATION DECISION: Building Python wrapper to Csound C++ interface library.' - pythonWrapperEnvironment = csoundWrapperEnvironment.Clone() - if getPlatform() == 'darwin': - pythonWrapperEnvironment.Append(LINKFLAGS = ['-L.', '-l_csnd']) - else: pythonWrapperEnvironment.Prepend(LIBS = Split('csnd')) - if getPlatform() == 'linux': - os.spawnvp(os.P_WAIT, 'rm', ['rm', '-f', '_csnd.so']) - # os.symlink('lib_csnd.so', '_csnd.so') - pythonWrapperEnvironment.Append(LINKFLAGS = ['-Wl,-rpath-link,.']) - if getPlatform() == 'darwin': - pythonWrapperEnvironment.Append(LINKFLAGS = pythonLinkFlags) - if commonEnvironment['dynamicCsoundLibrary'] == '1': - #ilibName = "lib_csnd.dylib" - #ilibVersion = csoundLibraryVersion - #pythonWrapperEnvironment.Append(SHLINKFLAGS = Split('''-Xlinker -compatibility_version -Xlinker %s''' % ilibVersion)) - #pythonWrapperEnvironment.Append(SHLINKFLAGS = Split('''-Xlinker -current_version -Xlinker %s''' % ilibVersion)) - #pythonWrapperEnvironment.Append(SHLINKFLAGS = Split('''-install_name /Library/Frameworks/%s/%s''' % (OSXFrameworkCurrentVersion, ilibName))) - pythonWrapperEnvironment.Append(CPPPATH = pythonIncludePath) - #pythonWrapper = pythonWrapperEnvironment.SharedLibrary('_csnd', pythonWrapperSources) - pyVersToken = '-DPYTHON_24_or_newer' - csoundPythonInterface = pythonWrapperEnvironment.SharedObject( - 'interfaces/python_interface.i', - SWIGFLAGS = [swigflags, '-python', '-outdir', '.', pyVersToken]) - pythonWrapperEnvironment.Clean('.', 'interfaces/python_interface_wrap.h') - #try: os.symlink('lib_csnd.dylib', 'libcsnd.dylib') - #except: print "link exists..." - else: - pythonWrapperEnvironment.Append(LINKFLAGS = pythonLinkFlags) - if getPlatform() != 'darwin': - pythonWrapperEnvironment.Prepend(LIBPATH = pythonLibraryPath) - pythonWrapperEnvironment.Prepend(LIBS = pythonLibs) - pythonWrapperEnvironment.Append(CPPPATH = pythonIncludePath) - fixCFlagsForSwig(pythonWrapperEnvironment) - pyVersToken = '-DPYTHON_24_or_newer' - csoundPythonInterface = pythonWrapperEnvironment.SharedObject( - 'interfaces/python_interface.i', - SWIGFLAGS = [swigflags, '-python', '-outdir', '.', pyVersToken]) - pythonWrapperEnvironment.Clean('.', 'interfaces/python_interface_wrap.h') - if getPlatform() == 'win32' and pythonLibs[0] < 'python24' and compilerGNU(): - Depends(csoundPythonInterface, pythonImportLibrary) - pythonWrapper = makePythonModule(pythonWrapperEnvironment, 'csnd', [csoundPythonInterface]) - pythonModules.append('csnd.py') - Depends(pythonWrapper, csnd) - -if commonEnvironment['generatePdf'] == '0': - print 'CONFIGURATION DECISION: Not generating Csound API PDF documentation.' -else: - print 'CONFIGURATION DECISION: Generating Csound API PDF documentation.' - refmanTex = commonEnvironment.Command('doc/latex/refman.tex', 'Doxyfile', ['doxygen $SOURCE']) - Depends(refmanTex, csoundLibrary) - csoundPdf = commonEnvironment.Command('refman.pdf', 'doc/latex/refman.tex', ['pdflatex --include-directory=doc/latex --interaction=nonstopmode --job-name=CsoundAPI $SOURCE']) - Depends(csoundPdf, refmanTex) - -############################################################################# -# -# Plugin opcodes. -############################################################################# - - -# these opcodes have been folded back into csoundLib -# makePlugin(pluginEnvironment, 'stdopcd', Split(''' -# Opcodes/ambicode.c Opcodes/bbcut.c Opcodes/biquad.c -# Opcodes/butter.c Opcodes/clfilt.c Opcodes/cross2.c -# Opcodes/dam.c Opcodes/dcblockr.c Opcodes/filter.c -# Opcodes/flanger.c Opcodes/follow.c Opcodes/fout.c -# Opcodes/freeverb.c Opcodes/ftconv.c Opcodes/ftgen.c -# Opcodes/gab/gab.c Opcodes/gab/vectorial.c Opcodes/grain.c -# Opcodes/locsig.c Opcodes/lowpassr.c Opcodes/metro.c -# Opcodes/midiops2.c Opcodes/midiops3.c Opcodes/newfils.c -# Opcodes/nlfilt.c Opcodes/oscbnk.c Opcodes/pluck.c -# Opcodes/repluck.c Opcodes/reverbsc.c Opcodes/seqtime.c -# Opcodes/sndloop.c Opcodes/sndwarp.c Opcodes/space.c -# Opcodes/spat3d.c Opcodes/syncgrain.c Opcodes/ugens7.c -# Opcodes/ugens9.c Opcodes/ugensa.c Opcodes/uggab.c -# Opcodes/ugmoss.c Opcodes/ugnorman.c Opcodes/ugsc.c -# Opcodes/wave-terrain.c Opcodes/stdopcod.c -# ''')) -# makePlugin(pluginEnvironment, 'pvsbuffer', ['Opcodes/pvsbuffer.c']) -# makePlugin(pluginEnvironment, 'eqfil', ['Opcodes/eqfil.c']) -# makePlugin(pluginEnvironment, 'vosim', ['Opcodes/Vosim.c']) -# makePlugin(pluginEnvironment, 'modmatrix', ['Opcodes/modmatrix.c']) -# makePlugin(pluginEnvironment, 'scoreline', ['Opcodes/scoreline.c']) -# makePlugin(pluginEnvironment, 'modal4', -# ['Opcodes/modal4.c', 'Opcodes/physutil.c']) -# makePlugin(pluginEnvironment, 'physmod', Split(''' -# Opcodes/physmod.c Opcodes/physutil.c Opcodes/mandolin.c Opcodes/singwave.c -# Opcodes/fm4op.c Opcodes/moog1.c Opcodes/shaker.c Opcodes/bowedbar.c -#''')) -# makePlugin(pluginEnvironment, 'babo', ['Opcodes/babo.c']) -# makePlugin(pluginEnvironment, 'barmodel', ['Opcodes/bilbar.c']) -# makePlugin(pluginEnvironment, 'compress', ['Opcodes/compress.c']) -# makePlugin(pluginEnvironment, 'cs_pvs_ops', Split(''' -# Opcodes/ifd.c Opcodes/partials.c Opcodes/psynth.c Opcodes/pvsbasic.c -# Opcodes/pvscent.c Opcodes/pvsdemix.c Opcodes/pvs_ops.c Opcodes/pvsband.c -#''')) -# makePlugin(pluginEnvironment, 'pitch', -# ['Opcodes/pitch.c', 'Opcodes/pitch0.c', 'Opcodes/spectra.c']) -# makePlugin(pluginEnvironment, 'ambicode1', ['Opcodes/ambicode1.c']) -# sfontEnvironment = pluginEnvironment.Clone() -# if compilerGNU(): -# if getPlatform() != 'darwin': -# sfontEnvironment.Append(CCFLAGS = ['-fno-strict-aliasing']) -# if sys.byteorder == 'big': -# sfontEnvironment.Append(CCFLAGS = ['-DWORDS_BIGENDIAN']) -# makePlugin(sfontEnvironment, 'sfont', ['Opcodes/sfont.c']) -# makePlugin(pluginEnvironment, 'grain4', ['Opcodes/grain4.c']) -# makePlugin(pluginEnvironment, 'hrtferX', ['Opcodes/hrtferX.c']) -# makePlugin(pluginEnvironment, 'loscilx', ['Opcodes/loscilx.c']) -# makePlugin(pluginEnvironment, 'minmax', ['Opcodes/minmax.c']) -# makePlugin(pluginEnvironment, 'cs_pan2', ['Opcodes/pan2.c']) -# makePlugin(pluginEnvironment, 'tabfns', ['Opcodes/tabvars.c']) -# makePlugin(pluginEnvironment, 'phisem', ['Opcodes/phisem.c']) -# makePlugin(pluginEnvironment, 'pvoc', Split(''' -# Opcodes/dsputil.c Opcodes/pvadd.c Opcodes/pvinterp.c Opcodes/pvocext.c -# Opcodes/pvread.c Opcodes/ugens8.c Opcodes/vpvoc.c Opcodes/pvoc.c -#''')) -#hrtfnewEnvironment = pluginEnvironment.Clone() -#if sys.byteorder == 'big': -# hrtfnewEnvironment.Append(CCFLAGS = ['-DWORDS_BIGENDIAN']) -# makePlugin(hrtfnewEnvironment, 'hrtfnew', 'Opcodes/hrtfopcodes.c') -# makePlugin(pluginEnvironment, 'stackops', ['Opcodes/stackops.c']) -# makePlugin(pluginEnvironment, 'vbap', -# ['Opcodes/vbap.c', 'Opcodes/vbap_eight.c', 'Opcodes/vbap_four.c', -# 'Opcodes/vbap_sixteen.c', 'Opcodes/vbap_zak.c']) -# makePlugin(pluginEnvironment, 'vaops', ['Opcodes/vaops.c']) -# makePlugin(pluginEnvironment, 'ugakbari', ['Opcodes/ugakbari.c']) -# makePlugin(pluginEnvironment, 'harmon', ['Opcodes/harmon.c']) -# makePlugin(pluginEnvironment, 'ptrack', ['Opcodes/pitchtrack.c']) -# makePlugin(pluginEnvironment, 'partikkel', ['Opcodes/partikkel.c']) -# makePlugin(pluginEnvironment, 'shape', ['Opcodes/shape.c']) -# makePlugin(pluginEnvironment, 'tabsum', ['Opcodes/tabsum.c']) -# makePlugin(pluginEnvironment, 'crossfm', ['Opcodes/crossfm.c']) -# makePlugin(pluginEnvironment, 'pvlock', ['Opcodes/pvlock.c']) -# makePlugin(pluginEnvironment, 'fareyseq', ['Opcodes/fareyseq.c']) -# makePlugin(pluginEnvironment, 'gabnew', Split(''' -# Opcodes/gab/tabmorph.c Opcodes/gab/hvs.c -# Opcodes/gab/sliderTable.c -# Opcodes/gab/newgabopc.c''')) - -#============================== ================================== - -# system opcodes -makePlugin(pluginEnvironment, 'cs_date', ['Opcodes/date.c']) -makePlugin(pluginEnvironment, 'system_call', ['Opcodes/system_call.c']) - -# C++ opcodes -makePlugin(pluginEnvironment, 'ampmidid', ['Opcodes/ampmidid.cpp']) -makePlugin(pluginEnvironment, 'doppler', ['Opcodes/doppler.cpp']) -makePlugin(pluginEnvironment, 'mixer', ['Opcodes/mixer.cpp']) -makePlugin(pluginEnvironment, 'signalflowgraph', ['Opcodes/signalflowgraph.cpp']) -makePlugin(pluginEnvironment, 'fractalnoise', ['Opcodes/tl/fractalnoise.cpp']) - -# platform-specific -if (getPlatform() == 'linux' or getPlatform() == 'darwin'): - makePlugin(pluginEnvironment, 'control', ['Opcodes/control.c']) -# makePlugin(pluginEnvironment, 'cpumeter', ['Opcodes/cpumeter.c']) -if getPlatform() == 'linux': - makePlugin(pluginEnvironment, 'urandom', ['Opcodes/urandom.c']) - - -# scanned synthesis -makePlugin(pluginEnvironment, 'scansyn', - ['Opcodes/scansyn.c', 'Opcodes/scansynx.c']) - -# tables -makePlugin(pluginEnvironment, 'fareygen', ['Opcodes/fareygen.c']) -##makePlugin(pluginEnvironment, 'ftest', ['Opcodes/ftest.c']) - -# Cellular automaton -makePlugin(pluginEnvironment, 'cellular', ['Opcodes/cellular.c']) - -############################################################################# -# -# Plugins with External Dependencies -############################################################################# -# UDP opcodes -if commonEnvironment['useUDP'] == '0': - print "CONFIGURATION DECISION: Not building UDP plugins." -else: - print "CONFIGURATION DECISION: Building UDP plugins." - udpEnvironment = pluginEnvironment.Clone() - udpEnvironment.Append(LIBS = ['pthread']) - if getPlatform() == 'win32': - udpEnvironment.Append(LIBS = ['ws2_32']) - makePlugin(udpEnvironment, 'udprecv', ['Opcodes/sockrecv.c']) - makePlugin(udpEnvironment, 'udpsend', ['Opcodes/socksend.c']) - -# end udp opcodes - -# OSC opcodes -if not (commonEnvironment['useOSC'] == '1' and oscFound): - print "CONFIGURATION DECISION: Not building OSC plugin." -else: - print "CONFIGURATION DECISION: Building OSC plugin." - oscEnvironment = pluginEnvironment.Clone() - oscEnvironment.Append(LIBS = ['lo', 'pthread']) - if getPlatform() == 'win32': - oscEnvironment.Append(LIBS = csoundWindowsLibraries) - if compilerGNU(): - oscEnvironment.Append(SHLINKFLAGS = ['-Wl,--enable-stdcall-fixup']) - makePlugin(oscEnvironment, 'osc', ['Opcodes/OSC.c']) - -##commonEnvironment.Append(LINKFLAGS = ['-Wl,-as-needed']) -if wiifound==1: - WiiEnvironment = pluginEnvironment.Clone() - makePlugin(WiiEnvironment, 'wiimote', ['Opcodes/wiimote.c']) - if wiiversion=='12': - WiiEnvironment.Append(CCFLAGS = ['-DWIIUSE_0_12']) -if p5gfound==1: - P5GEnvironment = pluginEnvironment.Clone() - makePlugin(P5GEnvironment, 'p5g', ['Opcodes/p5glove.c']) -if serialfound==1: - SerEnvironment = pluginEnvironment.Clone() - makePlugin(SerEnvironment, 'serial', ['Opcodes/serial.c']) - -#oggEnvironment = pluginEnvironment.Clone() -#makePlugin(oggEnvironment, 'ogg', ['Opcodes/ogg.c']) -#oggEnvironment.Append(LIBS=['vorbisfile']) - -if jackFound and commonEnvironment['useJack'] == '1': - jpluginEnvironment = pluginEnvironment.Clone() - if getPlatform() == 'linux': - jpluginEnvironment.Append(LIBS = ['jack', 'asound', 'pthread']) - elif getPlatform() == 'win32': - jpluginEnvironment.Append(LIBS = ['jackdmp']) - elif getPlatform() == 'darwin': - jpluginEnvironment.Append(LIBS = ['pthread']) - jpluginEnvironment.Append(LINKFLAGS = ['-framework', 'Jackmp']) - makePlugin(jpluginEnvironment, 'jackTransport', 'Opcodes/jackTransport.c') - makePlugin(jpluginEnvironment, 'jacko', 'Opcodes/jacko.cpp') -if boostFound: - makePlugin(pluginEnvironment, 'chua', 'Opcodes/chua/ChuaOscillator.cpp') -if gmmFound and commonEnvironment['useDouble'] != '0': - makePlugin(pluginEnvironment, 'linear_algebra', 'Opcodes/linear_algebra.cpp') - print 'CONFIGURATION DECISION: Building linear algebra opcodes.' -else: - print 'CONFIGURATION DECISION: Not building linear algebra opcodes.' - -if commonEnvironment['buildImageOpcodes'] == '1': - if getPlatform() == 'win32': - if configure.CheckHeader("png.h", language="C") and zlibhfound: - print 'CONFIGURATION DECISION: Building image opcodes' - imEnv = pluginEnvironment.Clone() - imEnv.Append(LIBS= Split(''' fltk_png fltk_z ''')) - makePlugin(imEnv, 'image', ['Opcodes/imageOpcodes.c']) - else: - if configure.CheckHeader("png.h", language="C") and zlibhfound: - print 'CONFIGURATION DECISION: Building image opcodes' - imEnv = pluginEnvironment.Clone() - imEnv.Append(LIBS= Split(''' png z ''')) - makePlugin(imEnv, 'image', ['Opcodes/imageOpcodes.c']) -else: - print 'CONFIGURATION DECISION: Not building image opcodes' - -# FLTK widgets - -vstEnvironment = commonEnvironment.Clone() -vstEnvironment.Append(CXXFLAGS = '-DVST_FORCE_DEPRECATED=0') -guiProgramEnvironment = commonEnvironment.Clone() - -fltkConfigFlags = 'fltk-config --use-images --cflags --cxxflags' -if getPlatform() != 'darwin': - fltkConfigFlags += ' --ldflags' -if ((commonEnvironment['buildCsoundVST'] == '1') and boostFound and fltkFound): - try: - if vstEnvironment.ParseConfig(fltkConfigFlags): - print 'Parsed fltk-config.' - else: - print 'Could not parse fltk-config.' - except: - print 'Exception when attempting to parse fltk-config.' -if getPlatform() == 'darwin': - vstEnvironment.Append(LIBS = ['fltk', 'fltk_images']) # png z jpeg are not on OSX at the mo -if getPlatform() == 'win32': - if compilerGNU(): - vstEnvironment.Append(LINKFLAGS = "-mwindows") - guiProgramEnvironment.Append(LINKFLAGS = "-mwindows") - #vstEnvironment.Append(LIBS = ['stdc++', 'supc++']) - #guiProgramEnvironment.Append(LIBS = ['stdc++', 'supc++']) - else: - csoundProgramEnvironment.Append(LINKFLAGS = ["/IMPLIB:dummy.lib"]) - csoundProgramEnvironment.Append(LIBS = csoundWindowsLibraries) - vstEnvironment.Append(LIBS = csoundWindowsLibraries) - guiProgramEnvironment.Append(LIBS = csoundWindowsLibraries) -else: - if getPlatform() == 'linux': - csoundProgramEnvironment.Append(LIBS = ['dl']) - vstEnvironment.Append(LIBS = ['dl']) - guiProgramEnvironment.Append(LIBS = ['dl']) - csoundProgramEnvironment.Append(LIBS = ['pthread', 'm']) - if wiifound : - if getPlatform() == 'darwin': - WiiEnvironment.Append(LIBS = ['wiiuse']) - else: - WiiEnvironment.Append(LIBS = ['wiiuse', 'bluetooth']) - if p5gfound : - P5GEnvironment.Append(LIBS = ['p5glove']) - vstEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm']) - guiProgramEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm']) - if getPlatform() == 'darwin': - csoundProgramEnvironment.Append(LINKFLAGS = Split('''-framework Carbon -framework CoreAudio -framework CoreMIDI''')) - -if (not (commonEnvironment['useFLTK'] == '1' and fltkFound)): - print 'CONFIGURATION DECISION: Not building with FLTK graphs and widgets.' -else: - widgetsEnvironment = pluginEnvironment.Clone() - if (commonEnvironment['buildvst4cs'] == '1'): - widgetsEnvironment.Append(CCFLAGS = ['-DCS_VSTHOST']) - if (commonEnvironment['noFLTKThreads'] == '1'): - widgetsEnvironment.Append(CCFLAGS = ['-DNO_FLTK_THREADS']) - if getPlatform() == 'linux' or (getPlatform() == 'sunos' and compilerGNU()): - ## dont do this widgetsEnvironment.Append(CCFLAGS = ['-DCS_VSTHOST']) - widgetsEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - widgetsEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm']) - elif compilerSun(): - widgetsEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - widgetsEnvironment.Append(LIBS = ['pthread', 'm']) - elif getPlatform() == 'win32': - if compilerGNU(): - widgetsEnvironment.Append(CPPFLAGS = Split('-DWIN32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_THREAD_SAFE -D_REENTRANT -DFL_DLL -DFL_LIBRARY')) - widgetsEnvironment.Append(LIBS = Split('fltk_images fltk_png fltk_jpeg fltk_z fltk')) - # widgetsEnvironment.Append(LIBS = Split('mgwfltknox_images-1.3 mgwfltknox-1.3 mgwfltknox_forms-1.3')) - else: - widgetsEnvironment.Append(LIBS = Split('fltkimages fltkpng fltkz fltkjpeg fltk')) - widgetsEnvironment.Append(LIBS = csoundWindowsLibraries) - elif getPlatform() == 'darwin': - widgetsEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - makePlugin(widgetsEnvironment, 'widgets', - ['InOut/FL_graph.cpp', 'InOut/winFLTK.c', 'InOut/widgets.cpp']) - - if commonEnvironment['buildVirtual'] == '0' or not fltk117Found: - print "CONFIGURATION DECISION: Not building Virtual Keyboard plugin. (FLTK 1.1.7+ required)" - else: - print "CONFIGURATION DECISION: Building Virtual Keyboard plugin." - widgetsEnvironment.Append(CPPPATH = ['./InOut', './InOut/virtual_keyboard']) - makePlugin(widgetsEnvironment, 'virtual', - ['InOut/virtual_keyboard/FLTKKeyboard.cpp', - 'InOut/virtual_keyboard/FLTKKeyboardWindow.cpp', - 'InOut/virtual_keyboard/FLTKKeyboardWidget.cpp', - 'InOut/virtual_keyboard/virtual_keyboard.cpp', - 'InOut/virtual_keyboard/Bank.cpp', - 'InOut/virtual_keyboard/KeyboardMapping.cpp', - 'InOut/virtual_keyboard/Program.cpp', - 'InOut/virtual_keyboard/SliderBank.cpp', - 'InOut/virtual_keyboard/SliderData.cpp']) - -# REAL TIME AUDIO AND MIDI - -if commonEnvironment['useCoreAudio'] == '1' and getPlatform() == 'darwin': - print "CONFIGURATION DECISION: Building CoreAudio plugin." - coreaudioEnvironment = pluginEnvironment.Clone() - coreaudioEnvironment.Append(CCFLAGS = ['-I/System/Library/Frameworks/CoreAudio.framework/Headers']) -# makePlugin(coreaudioEnvironment, 'rtcoreaudio', ['InOut/rtcoreaudio.c']) - coreaudioEnvironment.Append(CCFLAGS = ['-I/System/Library/Frameworks/AudioUnit.framework/Headers']) - coreaudioEnvironment.Append(LINKFLAGS = ['-framework', 'AudioUnit']) - makePlugin(coreaudioEnvironment, 'rtauhal', ['InOut/rtauhal.c']) -else: - print "CONFIGURATION DECISION: Not building CoreAudio plugin." - -if not (commonEnvironment['useALSA'] == '1' and alsaFound): - print "CONFIGURATION DECISION: Not building ALSA plugin." -else: - print "CONFIGURATION DECISION: Building ALSA plugin." - alsaEnvironment = pluginEnvironment.Clone() - alsaEnvironment.Append(LIBS = ['asound', 'pthread']) - makePlugin(alsaEnvironment, 'rtalsa', ['InOut/rtalsa.c']) - -if pulseaudioFound and (getPlatform() == 'linux' or getPlatform() == 'sunos'): - print "CONFIGURATION DECISION: Building PulseAudio plugin" - pulseaudioEnv = pluginEnvironment.Clone() - pulseaudioEnv.Append(LIBS = ['pulse-simple']) - makePlugin(pulseaudioEnv, 'rtpulse', ['InOut/rtpulse.c']) - -if getPlatform() == 'win32': - winmmEnvironment = pluginEnvironment.Clone() - winmmEnvironment.Append(LIBS = ['winmm', 'gdi32', 'kernel32']) - makePlugin(winmmEnvironment, 'rtwinmm', ['InOut/rtwinmm.c']) - -if not (commonEnvironment['usePortAudio'] == '1' and portaudioFound): - print "CONFIGURATION DECISION: Not building PortAudio module." -else: - print "CONFIGURATION DECISION: Building PortAudio module." - portaudioEnvironment = pluginEnvironment.Clone() - if getPlatform() == 'win32': - portaudioEnvironment.Append(LIBS = ['portaudio']) - else: - portaudioEnvironment.Append(LIBS = ['portaudio']) - if (getPlatform() == 'linux'): - if (commonEnvironment['useJack']=='1' and jackFound): - print "Adding Jack library for PortAudio" - portaudioEnvironment.Append(LIBS = ['jack']) - portaudioEnvironment.Append(LIBS = ['asound', 'pthread']) - makePlugin(portaudioEnvironment, 'rtpa', ['InOut/rtpa.c']) - elif getPlatform() == 'win32': - portaudioEnvironment.Append(LIBS = ['winmm', 'dsound']) - portaudioEnvironment.Append(LIBS = csoundWindowsLibraries) - makePlugin(portaudioEnvironment, 'rtpa', ['InOut/rtpa.cpp']) - else: - makePlugin(portaudioEnvironment, 'rtpa', ['InOut/rtpa.c']) - -if not (commonEnvironment['useJack'] == '1' and jackFound): - print "CONFIGURATION DECISION: Not building JACK plugin." -else: - print "CONFIGURATION DECISION: Building JACK plugin." - jackEnvironment = pluginEnvironment.Clone() - if getPlatform() == 'linux': - jackEnvironment.Append(LIBS = ['jack', 'asound', 'pthread']) - elif getPlatform() == 'win32': - jackEnvironment.Append(LIBS = ['jackdmp']) - else: - jackEnvironment.Append(LIBS = ['pthread', 'jack']) - makePlugin(jackEnvironment, 'rtjack', ['InOut/rtjack.c']) - -if commonEnvironment['usePortMIDI'] == '1' and portmidiFound: - print 'CONFIGURATION DECISION: Building with PortMIDI.' - portMidiEnvironment = pluginEnvironment.Clone() - portMidiEnvironment.Append(LIBS = ['portmidi']) - if getPlatform() != 'darwin' and getPlatform() != 'win32': - if configure.CheckLibWithHeader("porttimer","porttimmer.h",language="C"): - portMidiEnvironment.Append(LIBS = ['porttime']) - if getPlatform() == 'win32': - portMidiEnvironment.Append(LIBS = csoundWindowsLibraries) - if getPlatform() == 'linux' and alsaFound: - portMidiEnvironment.Append(LIBS = ['asound']) - makePlugin(portMidiEnvironment, 'pmidi', ['InOut/pmidi.c']) -else: - print 'CONFIGURATION DECISION: Not building with PortMIDI.' - -if getPlatform() == 'darwin': - coreMidiEnvironment = pluginEnvironment.Clone() - makePlugin(coreMidiEnvironment, 'cmidi', ['InOut/cmidi.c']) - - - - -# FLUIDSYNTH OPCODES - -if not configure.CheckHeader("fluidsynth.h", language = "C"): - print "CONFIGURATION DECISION: Not building fluid opcodes." -else: - print "CONFIGURATION DECISION: Building fluid opcodes." - fluidEnvironment = pluginEnvironment.Clone() - if getPlatform() == 'win32': - if compilerGNU(): - fluidEnvironment.Append(LIBS = ['fluidsynth']) - else: - fluidEnvironment.Append(LIBS = ['fluidsynth']) - fluidEnvironment.Append(CPPFLAGS = ['-DFLUIDSYNTH_NOT_A_DLL']) - fluidEnvironment.Append(LIBS = ['winmm', 'dsound']) - fluidEnvironment.Append(LIBS = csoundWindowsLibraries) - elif getPlatform() == 'linux' or getPlatform() == 'darwin': - fluidEnvironment.Append(LIBS = ['fluidsynth']) - fluidEnvironment.Append(LIBS = ['pthread']) - makePlugin(fluidEnvironment, 'fluidOpcodes', - ['Opcodes/fluidOpcodes/fluidOpcodes.cpp']) - -# VST HOST OPCODES - -if (commonEnvironment['buildvst4cs'] != '1'): - print "CONFIGURATION DECISION: Not building vst4cs opcodes." -else: - print "CONFIGURATION DECISION: Building vst4cs opcodes." - if (getPlatform() == 'win32'or getPlatform() == 'linux') and fltkFound: - vst4Environment = vstEnvironment.Clone() - vst4Environment.Append(CPPFLAGS = ['-DCS_VSTHOST']) - vst4Environment.Append(CPPPATH = ['frontends/CsoundVST']) - if compilerGNU(): - if getPlatform() == 'win32': - vst4Environment.Append(LIBS = Split('fltk_images fltk_png fltk_jpeg fltk_z fltk')) - else: - vst4Environment.Append(LIBS = Split('fltk_images png z jpeg fltk')) - vst4Environment.Append(LIBS = ['stdc++']) - if getPlatform() == 'win32': - vst4Environment.Append(LIBS = csoundWindowsLibraries) - makePlugin(vst4Environment, 'vst4cs', Split(''' - Opcodes/vst4cs/src/vst4cs.cpp - Opcodes/vst4cs/src/fxbank.cpp - Opcodes/vst4cs/src/vsthost.cpp - ''')) - elif getPlatform() == 'darwin' and fltkFound: - vst4Environment = vstEnvironment.Clone() - vst4Environment.Append(LIBS = ['fltk']) - vst4Environment.Append(LIBS = ['stdc++']) - vst4Environment.Append(LINKFLAGS=['-framework', 'Carbon', '-framework', - 'ApplicationServices']) - vst4Environment.Append(CPPPATH = ['frontends/CsoundVST']) - vst4Environment.Append(CPPFLAGS = ['-DCS_VSTHOST']) - makePlugin(vst4Environment, 'vst4cs', Split(''' - Opcodes/vst4cs/src/vst4cs.cpp Opcodes/vst4cs/src/fxbank.cpp - Opcodes/vst4cs/src/vsthost.cpp - ''')) - -# DSSI HOST OPCODES - -if (commonEnvironment['buildDSSI'] == '1' and (getPlatform() == 'linux' or getPlatform() == 'darwin') and configure.CheckHeader("ladspa.h", language = "C")) and configure.CheckHeader("dssi.h", language = "C"): - print "CONFIGURATION DECISION: Building DSSI plugin host opcodes." - dssiEnvironment = pluginEnvironment.Clone() - dssiEnvironment.Append(LIBS = ['dl']) - makePlugin(dssiEnvironment, 'dssi4cs', - ['Opcodes/dssi4cs/src/load.c', 'Opcodes/dssi4cs/src/dssi4cs.c']) -else: - print "CONFIGURATION DECISION: Not building DSSI plugin host opcodes." - -# Loris opcodes -#if not (commonEnvironment['buildLoris'] == '1' and configure.CheckHeader("Opcodes/Loris/src/loris.h") and configure.CheckHeader("fftw3.h")): -# print "CONFIGURATION DECISION: Not building Loris Python extension and Csound opcodes." -#else: -# print "CONFIGURATION DECISION: Building Loris Python extension and Csound opcodes." - # For Loris, we build only the loris Python extension module and - # the Csound opcodes (modified for Csound 5). - # It is assumed that you have copied all contents of the Loris - # distribution into the csound5/Opcodes/Loris directory, e.g. - # csound5/Opcodes/Loris/src/*, etc. -# lorisEnvironment = pluginEnvironment.Clone() -# lorisEnvironment.Append(CCFLAGS = '-DHAVE_FFTW3_H') -# if commonEnvironment['buildRelease'] == '0': -# lorisEnvironment.Append(CCFLAGS = '-DDEBUG_LORISGENS') -# if getPlatform() == 'win32': -# lorisEnvironment.Append(CCFLAGS = '-D_MSC_VER') -# if compilerGNU(): -# if getPlatform() != 'win32': -# lorisEnvironment.Prepend(LIBS = ['stdc++']) -# lorisEnvironment.Append(CCFLAGS = Split(''' -# -Wno-comment -Wno-unknown-pragmas -Wno-sign-compare -# ''')) -# lorisEnvironment.Append(CPPPATH = Split(''' -# Opcodes/Loris Opcodes/Loris/src ./ -# ''')) -# lorisSources = glob.glob('Opcodes/Loris/src/*.[Cc]') -# if 'Opcodes/Loris/src/lorisgens.C' in lorisSources: -# lorisSources.remove('Opcodes/Loris/src/lorisgens.C') -# lorisLibrarySources = [] -# for i in lorisSources: -# lorisLibrarySources += lorisEnvironment.SharedObject(i) -# lorisLibrary = lorisEnvironment.StaticLibrary( -# 'lorisbase', lorisLibrarySources) -# lorisEnvironment.Prepend(LIBS = ['lorisbase', 'fftw3']) - # The following file has been patched for Csound 5 - # and you should update it from Csound 5 CVS. -# lorisOpcodes = makePlugin(lorisEnvironment, 'loris', -# ['Opcodes/Loris/lorisgens5.C']) -# Depends(lorisOpcodes, lorisLibrary) -# lorisPythonEnvironment = lorisEnvironment.Clone() -# fixCFlagsForSwig(lorisPythonEnvironment) -# lorisPythonEnvironment.Append(CPPPATH = pythonIncludePath) -# lorisPythonEnvironment.Append(LINKFLAGS = pythonLinkFlags) -# lorisPythonEnvironment.Append(LIBPATH = pythonLibraryPath) -# if getPlatform() != 'darwin': -# lorisPythonEnvironment.Prepend(LIBS = pythonLibs) -# lorisPythonEnvironment.Append(SWIGPATH = ['./']) -# lorisPythonEnvironment.Prepend(SWIGFLAGS = Split(''' -# -module loris -c++ -includeall -verbose -outdir . -python -# -DHAVE_FFTW3_H -I./Opcodes/Loris/src -I. -# ''')) -# lorisPythonWrapper = lorisPythonEnvironment.SharedObject( -# 'Opcodes/Loris/scripting/loris.i') -# lorisPythonEnvironment['SHLIBPREFIX'] = '' -# lorisPythonModule = makePythonModule(lorisPythonEnvironment, -# 'loris', lorisPythonWrapper) -# Depends(lorisPythonModule, lorisLibrary) - -# STK opcodes - -if not (commonEnvironment['buildStkOpcodes'] == '1' and stkFound): - print 'CONFIGURATION DECISION: Not building STK opcodes.' -else: - print 'CONFIGURATION DECISION: Building STK opcodes.' - # For the STK opcodes, the STK distribution include, src, and rawwaves - # directories should be copied thusly: - # csound5/Opcodes/stk/include - # csound5/Opcodes/stk/src - # csound5/Opcodes/stk/rawwaves - # Then, the following sources (and any other future I/O or OS dependent - # sources) should be ignored: - removeSources = Split(''' - Opcodes/stk/src/InetWvIn.cpp Opcodes/stk/src/InetWvOut.cpp - Opcodes/stk/src/Mutex.cpp Opcodes/stk/src/RtAudio.cpp - Opcodes/stk/src/RtMidi.cpp - Opcodes/stk/src/RtWvIn.cpp Opcodes/stk/src/RtWvOut.cpp - Opcodes/stk/src/Socket.cpp Opcodes/stk/src/TcpClient.cpp - Opcodes/stk/src/TcpServer.cpp Opcodes/stk/src/Thread.cpp - Opcodes/stk/src/UdpSocket.cpp - ''') - stkEnvironment = pluginEnvironment.Clone() - if getPlatform() == 'win32': - stkEnvironment.Append(CCFLAGS = '-D__OS_WINDOWS__') - stkEnvironment.Append(CCFLAGS = '-D__STK_REALTIME__') - elif getPlatform() == 'linux': - stkEnvironment.Append(CCFLAGS = '-D__OS_LINUX__') - stkEnvironment.Append(CCFLAGS = '-D__LINUX_ALSA__') - stkEnvironment.Append(CCFLAGS = '-D__STK_REALTIME__') - elif getPlatform() == 'darwin': - stkEnvironment.Append(CCFLAGS = '-D__OS_MACOSX__') - if sys.byteorder == 'big': - stkEnvironment.Append(CCFLAGS = '-D__BIG_ENDIAN__') - else: - stkEnvironment.Append(CCFLAGS = '-D__LITTLE_ENDIAN__') - stkEnvironment.Prepend(CPPPATH = Split(''' - Opcodes/stk/include Opcodes/stk/src ./ ./../include - ''')) - stkSources_ = glob.glob('Opcodes/stk/src/*.cpp') - stkSources = [] - for source in stkSources_: - stkSources.append(source.replace('\\', '/')) - for removeMe in removeSources: - stkSources.remove(removeMe) - stkLibrarySources = [] - for i in stkSources: - stkLibrarySources += stkEnvironment.SharedObject(i) - stkLibrary = stkEnvironment.StaticLibrary('stk_base', stkLibrarySources) - stkEnvironment.Prepend(LIBS = ['stk_base']) - if compilerGNU() and getPlatform() != 'win32': - stkEnvironment.Append(LIBS = ['stdc++']) - if getPlatform() == 'win32': - stkEnvironment.Append(LIBS = csoundWindowsLibraries) - elif getPlatform() == 'linux' or getPlatform() == 'darwin' or getPlatform() == 'sunos': - stkEnvironment.Append(LIBS = ['pthread']) - # This is the one that actually defines the opcodes. - # They are straight wrappers, as simple as possible. - stk = makePlugin(stkEnvironment, 'stk', ['Opcodes/stk/stkOpcodes.cpp']) - Depends(stk, stkLibrary) - -# Python opcodes - -if not (pythonFound and commonEnvironment['buildPythonOpcodes'] != '0'): - print "CONFIGURATION DECISION: Not building Python opcodes." -else: - print "CONFIGURATION DECISION: Building Python opcodes." - pyEnvironment = pluginEnvironment.Clone() - if getPlatform() != 'darwin': - pyEnvironment.Append(CPPPATH = pythonIncludePath) - pyEnvironment.Append(LIBPATH = pythonLibraryPath) - else: - pyEnvironment.Append(CPPPATH = "/System/Library/Frameworks/Python.framework/Headers") - - pyEnvironment.Append(LINKFLAGS = pythonLinkFlags) - pyEnvironment.Append(LIBS = pythonLibs) - if getPlatform() == 'linux': - pyEnvironment.Append(LIBS = ['util', 'dl', 'm']) - elif getPlatform() == 'darwin' or getPlatform() == 'sunos': - pyEnvironment.Append(LIBS = ['dl', 'm']) - elif getPlatform() == 'win32': - pyEnvironment['ENV']['PATH'] = os.environ['PATH'] - pythonOpcodes = makePlugin(pyEnvironment, 'py', - ['Opcodes/py/pythonopcodes.c']) - if getPlatform() == 'win32' and pythonLibs[0] < 'python24': - Depends(pythonOpcodes, pythonImportLibrary) - -# Python opcodes - -if not (commonEnvironment['buildLuaOpcodes'] != '0'): - print "CONFIGURATION DECISION: Not building Lua opcodes." -else: - print "CONFIGURATION DECISION: Building Lua opcodes." - luaEnvironment = pluginEnvironment.Clone() - - if getPlatform() == 'linux': - if(luaFound == 1): - luaEnvironment.Append(LIBS = ['luajit-5.1']) - luaEnvironment.Append(LIBS = ['util', 'dl', 'm']) - luaEnvironment.Append(CPPPATH = '/usr/local/include/luajit-2.0') - elif getPlatform() == 'win32': - if(luaFound == 1): - luaEnvironment.Append(LIBS = ['lua51']) - luaEnvironment['ENV']['PATH'] = os.environ['PATH'] - elif getPlatform() == 'darwin': - luaEnvironment.Append(LIBS = 'luajit-51') - luaEnvironment.Append(CPPPATH = '/usr/local/include/luajit-2.0') - luaEnvironment.Append(CPPFLAGS = '-fopenmp') - luaOpcodes = makePlugin(luaEnvironment, 'LuaCsound', - ['Opcodes/LuaCsound.cpp']) - -############################################################################# -# -# Utility programs. -stdutilSources = Split(''' - util/atsa.c util/cvanal.c util/dnoise.c - util/envext.c util/xtrct.c util/het_export.c - util/het_import.c util/hetro.c util/lpanal.c - util/lpc_export.c util/lpc_import.c util/mixer.c - util/pvanal.c util/pvlook.c util/scale.c - util/sndinfo.c util/srconv.c util/pv_export.c - util/pv_import.c - util/std_util.c - ''') -stdutilSources += pluginEnvironment.SharedObject('util/sdif', 'SDIF/sdif.c') - -makePlugin(pluginEnvironment, 'stdutil', stdutilSources) - -if (commonEnvironment['buildUtilities'] != '0'): - utils = [ - ['atsa', 'util/atsa_main.c' ], - ['cvanal', 'util/cvl_main.c' ], - ['dnoise', 'util/dnoise_main.c' ], - ['envext', 'util/env_main.c' ], - ['extractor', 'util/xtrc_main.c' ], - ['het_export', 'util/hetx_main.c' ], - ['het_import', 'util/heti_main.c' ], - ['hetro', 'util/het_main.c' ], - ['lpanal', 'util/lpc_main.c' ], - ['lpc_export', 'util/lpcx_main.c' ], - ['lpc_import', 'util/lpci_main.c' ], - ['mixer', 'util/mixer_main.c' ], - ['pvanal', 'util/pvc_main.c' ], - ['pvlook', 'util/pvl_main.c' ], - ['pv_export', 'util/pvx_main.c' ], - ['pv_import', 'util/pvi_main.c' ], - ['scale', 'util/scale_main.c' ], - ['sndinfo', 'util/sndinfo_main.c' ], - ['srconv', 'util/srconv_main.c' ]] - for i in utils: - executables.append(csoundProgramEnvironment.Program(i[0], i[1])) - -executables.append(csoundProgramEnvironment.Program('scsort', - ['util1/sortex/smain.c'])) -executables.append(csoundProgramEnvironment.Program('extract', - ['util1/sortex/xmain.c'])) -if compilerGNU(): - executables.append(commonEnvironment.Program('cs', - ['util1/csd_util/cs.c'])) - executables.append(commonEnvironment.Program('csb64enc', - ['util1/csd_util/base64.c', 'util1/csd_util/csb64enc.c'])) - executables.append(commonEnvironment.Program('makecsd', - ['util1/csd_util/base64.c', 'util1/csd_util/makecsd.c'])) - executables.append(commonEnvironment.Program('scot', - ['util1/scot/scot_main.c', 'util1/scot/scot.c'])) -#executables.append(csoundProgramEnvironment.Program('cscore', -# ['util1/cscore/cscore_main.c'])) -executables.append(commonEnvironment.Program('sdif2ad', - ['SDIF/sdif2adsyn.c', 'SDIF/sdif.c', 'SDIF/sdif-mem.c'])) - -for i in executables: - Depends(i, csoundLibrary) - -############################################################################# -# -# Front ends. -############################################################################# - -def addOSXResourceFork(env, baseName, dirName): - if getPlatform() == 'darwin': - if dirName != '': - fileName = dirName + '/' + baseName - else: - fileName = baseName - env.Command(('%s/resources' % fileName).replace('/', '_'), fileName, - "Rez -i APPL -o $SOURCE cs5.r") - -csoundProgramSources = ['frontends/csound/csound_main.c'] -if getPlatform() == 'linux': - csoundProgramSources = ['frontends/csound/sched.c'] + csoundProgramSources -csoundProgram = csoundProgramEnvironment.Program('csound', csoundProgramSources) -executables.append(csoundProgram) -Depends(csoundProgram, csoundLibrary) -os -def fluidTarget(env, dirName, baseName, objFiles): - flFile = dirName + '/' + baseName + '.fl' - cppFile = dirName + '/' + baseName + '.cpp' - hppFile = dirName + '/' + baseName + '.hpp' - env.Command([cppFile, hppFile], flFile, - 'fluid -c -o %s -h %s %s' % (cppFile, hppFile, flFile)) - for i in objFiles: - Depends(i, cppFile) - return cppFile - -# Build Csound5gui (FLTK frontend) - -if not (commonEnvironment['buildCsound5GUI'] != '0' and fltk117Found): - print 'CONFIGURATION DECISION: Not building FLTK CSOUND5GUI frontend.' -else: - print 'CONFIGURATION DECISION: Building FLTK GUI CSOUND5GUI frontend.' - csound5GUIEnvironment = csoundProgramEnvironment.Clone() - csound5GUIEnvironment.Append(CPPPATH = ['./interfaces']) - if jackFound: - csound5GUIEnvironment.Append(LIBS = ['jack']) - csound5GUIEnvironment.Prepend(CPPFLAGS = ['-DHAVE_JACK']) - if getPlatform() == 'linux' or (getPlatform() == 'sunos' and compilerGNU()): - csound5GUIEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - csound5GUIEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm']) - elif compilerSun(): - csound5GUIEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - csound5GUIEnvironment.Append(LIBS = ['pthread', 'm']) - elif getPlatform() == 'win32': - if compilerGNU(): - #csound5GUIEnvironment.Append(LIBS = ['stdc++', 'supc++']) - csound5GUIEnvironment.Prepend(LINKFLAGS = Split(''' - -mwindows -Wl,--enable-runtime-pseudo-reloc - ''')) - csound5GUIEnvironment.Append(LIBS = Split('fltk_images fltk_png fltk_jpeg fltk_z fltk')) - else: - csound5GUIEnvironment.Append(LIBS = Split('fltkimages fltkpng fltkz fltkjpeg fltk')) - csound5GUIEnvironment.Append(LIBS = csoundWindowsLibraries) - elif getPlatform() == 'darwin': - csound5GUIEnvironment.Prepend(CXXFLAGS = "-fno-rtti") - csound5GUIEnvironment.Append(LIBS = Split(''' - fltk stdc++ pthread m - ''')) - csound5GUIEnvironment.Append(LINKFLAGS = Split(''' - -framework Carbon -framework ApplicationServices - ''')) - csound5GUISources = Split(''' - frontends/fltk_gui/ConfigFile.cpp - frontends/fltk_gui/CsoundCopyrightInfo.cpp - frontends/fltk_gui/CsoundGlobalSettings.cpp - frontends/fltk_gui/CsoundGUIConsole.cpp - frontends/fltk_gui/CsoundGUIMain.cpp - frontends/fltk_gui/CsoundPerformance.cpp - frontends/fltk_gui/CsoundPerformanceSettings.cpp - frontends/fltk_gui/CsoundUtility.cpp - frontends/fltk_gui/CsoundEditor.cpp - frontends/fltk_gui/Fl_Native_File_Chooser.cxx - frontends/fltk_gui/main.cpp - ''') - csound5GUIFluidSources = Split(''' - CsoundAboutWindow_FLTK - CsoundGlobalSettingsPanel_FLTK - CsoundGUIConsole_FLTK - CsoundGUIMain_FLTK - CsoundPerformanceSettingsPanel_FLTK - CsoundUtilitiesWindow_FLTK - ''') - csound5GUIObjectFiles = [] - csound5GUIFluidObjectFiles = [] - for i in csound5GUISources: - csound5GUIObjectFiles += csound5GUIEnvironment.Object(i) - csound5GUIObjectFiles += csound5GUIEnvironment.Object( - 'frontends/fltk_gui/csPerfThread', 'interfaces/csPerfThread.cpp') - for i in csound5GUIFluidSources: - csound5GUIFluidObjectFiles += csound5GUIEnvironment.Object( - fluidTarget(csound5GUIEnvironment, 'frontends/fltk_gui', i, - csound5GUIObjectFiles)) - csound5GUIObjectFiles += csound5GUIFluidObjectFiles - csound5GUI = csound5GUIEnvironment.Program('csound5gui', - csound5GUIObjectFiles) - Depends(csound5GUI, csoundLibrary) - executables.append(csound5GUI) - if getPlatform() == 'darwin': - appDir = 'frontends/fltk_gui/Csound5GUI.app/Contents/MacOS' - addOSXResourceFork(csound5GUIEnvironment, 'csound5gui', '') - csound5GUIEnvironment.Command( - '%s/csound5gui' % appDir, 'csound5gui', "cp $SOURCE %s/" % appDir) - addOSXResourceFork(csound5GUIEnvironment, 'csound5gui', appDir) - -# Build CsoundAC - -if not ((commonEnvironment['buildCsoundAC'] == '1') and fltkFound and boostFound and fltkFound and eigenFound): - print 'CONFIGURATION DECISION: Not building CsoundAC extension module for Csound with algorithmic composition.' -else: - print 'CONFIGURATION DECISION: Building CsoundAC extension module for Csound with algorithmic composition.' - acEnvironment = vstEnvironment.Clone() - if getPlatform() == 'linux': - acEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - headers += glob.glob('frontends/CsoundAC/*.hpp') - acEnvironment.Prepend(CPPPATH = ['frontends/CsoundAC', 'interfaces']) - acEnvironment.Append(CPPPATH = pythonIncludePath) - acEnvironment.Append(LINKFLAGS = pythonLinkFlags) - acEnvironment.Append(LIBPATH = pythonLibraryPath) - acEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - if getPlatform() != 'darwin': - acEnvironment.Prepend(LIBS = pythonLibs) - if musicXmlFound: - acEnvironment.Prepend(LIBS = 'musicxml2') - if getPlatform() != 'win32': - acEnvironment.Prepend(LIBS = csnd) - else: - acEnvironment.Prepend(LIBS = 'csnd') - else: - if getPlatform() != 'darwin': - acEnvironment.Prepend(LIBS = '_csnd') - else: - acEnvironment.Append(LINKFLAGS = ['-L.', '-l_csnd']) - if not getPlatform() == 'darwin' or commonEnvironment['dynamicCsoundLibrary'] == '0': - acEnvironment.Prepend(LIBS = libCsoundLibs) - else: - if commonEnvironment['useDouble'] == 1: - acEnvironment.Prepend(LINKFLAGS = ['-F.', '-framework', 'CsoundLib64']) - else: acEnvironment.Prepend(LINKFLAGS = ['-F.', '-framework', 'CsoundLib64']) - acEnvironment.Append(SWIGFLAGS = Split('-c++ -includeall -verbose -outdir .')) - # csoundAC uses fltk_images, but -Wl,-as-needed willl wrongly discard it - flag = '-Wl,-as-needed' - if flag in acEnvironment['SHLINKFLAGS']: - acEnvironment['SHLINKFLAGS'].remove(flag) - if flag in acEnvironment['LINKFLAGS']: - acEnvironment['LINKFLAGS'].remove(flag) - if getPlatform() == 'linux': - acEnvironment.Append(LIBS = ['util', 'dl', 'm']) - #acEnvironment.Append(SHLINKFLAGS = '--no-export-dynamic') - acEnvironment.Append(LINKFLAGS = ['-Wl,-rpath-link,.']) - acEnvironment.Append(LIBS = ['fltk_images']) - guiProgramEnvironment.Prepend(LINKFLAGS = ['-Wl,-rpath-link,.']) - os.spawnvp(os.P_WAIT, 'rm', ['rm', '-f', '_CsoundAC.so']) - #os.symlink('lib_CsoundAC.so', '_CsoundAC.so') - elif getPlatform() == 'darwin': - acEnvironment.Append(LIBS = ['fltk']) - acEnvironment.Append(LIBS = ['dl', 'm', 'fltk_images', 'png', 'jpeg']) - #acEnvironment.Append(SHLINKFLAGS = '--no-export-all-symbols') - acEnvironment.Append(SHLINKFLAGS = '--add-stdcall-alias') - acEnvironment['SHLIBSUFFIX'] = '.dylib' - elif getPlatform() == 'win32': - acEnvironment.Prepend(CCFLAGS = Split('-D__Windows__ -D__BuildLib__')) - if compilerGNU(): - acEnvironment.Prepend(LIBS = Split('fltk fltk_images fltk_png fltk_jpeg fltk_z')) - else: - acEnvironment.Prepend(LIBS = Split('fltk fltkimages fltkpng fltkjpeg fltkz')) - for option in acEnvironment['CCFLAGS']: - if string.find(option, '-D') == 0: - acEnvironment.Append(SWIGFLAGS = [option]) - for option in acEnvironment['CPPFLAGS']: - if string.find(option, '-D') == 0: - acEnvironment.Append(SWIGFLAGS = [option]) - for option in acEnvironment['CPPPATH']: - option = '-I' + option - acEnvironment.Append(SWIGFLAGS = [option]) - print 'PATH =', commonEnvironment['ENV']['PATH'] - csoundAcSources = Split(''' - frontends/CsoundAC/allegro.cpp - frontends/CsoundAC/allegrord.cpp - frontends/CsoundAC/allegroserial.cpp - frontends/CsoundAC/allegrosmfrd.cpp - frontends/CsoundAC/allegrosmfwr.cpp - frontends/CsoundAC/allegrowr.cpp - frontends/CsoundAC/mfmidi.cpp - frontends/CsoundAC/strparse.cpp - frontends/CsoundAC/trace.cpp - frontends/CsoundAC/Cell.cpp - frontends/CsoundAC/ChordLindenmayer.cpp - frontends/CsoundAC/Composition.cpp - frontends/CsoundAC/Conversions.cpp - frontends/CsoundAC/Counterpoint.cpp - frontends/CsoundAC/CounterpointNode.cpp - frontends/CsoundAC/Event.cpp - frontends/CsoundAC/Hocket.cpp - frontends/CsoundAC/ImageToScore.cpp - frontends/CsoundAC/Lindenmayer.cpp - frontends/CsoundAC/MCRM.cpp - frontends/CsoundAC/Midifile.cpp - frontends/CsoundAC/MusicModel.cpp - frontends/CsoundAC/Node.cpp - frontends/CsoundAC/Random.cpp - frontends/CsoundAC/Rescale.cpp - frontends/CsoundAC/Score.cpp - frontends/CsoundAC/ScoreModel.cpp - frontends/CsoundAC/ScoreNode.cpp - frontends/CsoundAC/Sequence.cpp - frontends/CsoundAC/Shell.cpp - frontends/CsoundAC/Soundfile.cpp - frontends/CsoundAC/StrangeAttractor.cpp - frontends/CsoundAC/System.cpp - frontends/CsoundAC/Voicelead.cpp - frontends/CsoundAC/VoiceleadingNode.cpp - ''') - swigflags = acEnvironment['SWIGFLAGS'] - acWrapperEnvironment = csoundWrapperEnvironment.Clone() - fixCFlagsForSwig(acWrapperEnvironment) - if commonEnvironment['dynamicCsoundLibrary'] == '1': - csoundac = acEnvironment.Library('CsoundAC', csoundAcSources) - else: - csoundac = acEnvironment.Library('CsoundAC', csoundAcSources) - libs.append(csoundac) - Depends(csoundac, csnd) - pythonWrapperEnvironment = csoundWrapperEnvironment.Clone() - if getPlatform() == 'darwin': - pythonWrapperEnvironment.Append(LINKFLAGS = Split('-L. -l_csnd')) - else: pythonWrapperEnvironment.Prepend(LIBS = Split('csnd')) - pythonCsoundACWrapperEnvironment = pythonWrapperEnvironment.Clone() - if getPlatform() == 'darwin': - pythonCsoundACWrapperEnvironment.Prepend(LIBS = ['CsoundAC']) - pythonCsoundACWrapperEnvironment.Prepend(LIBS = ['fltk_images', 'fltk']) - pythonCsoundACWrapperEnvironment.Append(LINKFLAGS = pythonLinkFlags) - pythonCsoundACWrapperEnvironment.Prepend(LIBPATH = pythonLibraryPath) - pythonCsoundACWrapperEnvironment.Prepend(LIBS = pythonLibs) - pythonCsoundACWrapperEnvironment.Append(CPPPATH = pythonIncludePath) - else: - pythonCsoundACWrapperEnvironment.Append(LINKFLAGS = pythonLinkFlags) - pythonCsoundACWrapperEnvironment.Prepend(LIBPATH = pythonLibraryPath) - pythonCsoundACWrapperEnvironment.Prepend(LIBS = pythonLibs) - pythonCsoundACWrapperEnvironment.Append(CPPPATH = pythonIncludePath) - pythonCsoundACWrapperEnvironment.Prepend(LIBS = ['CsoundAC', 'csnd', 'fltk_images']) - csoundAcPythonWrapper = pythonCsoundACWrapperEnvironment.SharedObject( - 'frontends/CsoundAC/CsoundAC.i', SWIGFLAGS = [swigflags, Split('-python')]) - pythonCsoundACWrapperEnvironment.Clean('.', 'frontends/CsoundAC/CsoundAC_wrap.h') - csoundAcPythonModule = makePythonModule(pythonCsoundACWrapperEnvironment, 'CsoundAC', - csoundAcPythonWrapper) - if getPlatform() == 'win32' and pythonLibs[0] < 'python24' and compilerGNU(): - Depends(csoundAcPythonModule, pythonImportLibrary) - pythonModules.append('CsoundAC.py') - Depends(csoundAcPythonModule, pythonWrapper) - Depends(csoundAcPythonModule, csoundac) - Depends(csoundAcPythonModule, csnd) - if luaFound and commonEnvironment['buildLuaWrapper'] != '0': - luaCsoundACWrapperEnvironment = acWrapperEnvironment.Clone() - if getPlatform() == 'win32': - luaCsoundACWrapperEnvironment.Prepend(LIBS = Split('luaCsnd lua51 CsoundAC csnd fltk_images')) - else: - luaCsoundACWrapperEnvironment.Prepend(LIBS = [luaWrapper]) - luaCsoundACWrapperEnvironment.Prepend(LIBS = Split('luajit-5.1 CsoundAC csnd fltk_images')) - luaCsoundACWrapper = luaCsoundACWrapperEnvironment.SharedObject( - 'frontends/CsoundAC/luaCsoundAC.i', SWIGFLAGS = [swigflags, Split('-lua ')]) - luaCsoundACWrapperEnvironment.Clean('.', 'frontends/CsoundAC/luaCsoundAC_wrap.h') - CsoundAclModule = makeLuaModule(luaCsoundACWrapperEnvironment, 'luaCsoundAC', [luaCsoundACWrapper]) - Depends(CsoundAclModule, luaCsoundACWrapper) - Depends(CsoundAclModule, luaWrapper) - Depends(CsoundAclModule, csoundac) - Depends(CsoundAclModule, csnd) - - -# Build CsoundVST - -if not ((commonEnvironment['buildCsoundVST'] == '1') and boostFound and fltkFound): - print 'CONFIGURATION DECISION: Not building CsoundVST plugin and standalone.' -else: - print 'CONFIGURATION DECISION: Building CsoundVST plugin and standalone.' - headers += glob.glob('frontends/CsoundVST/*.h') - headers += glob.glob('frontends/CsoundVST/*.hpp') - vstEnvironment.Prepend(CPPPATH = ['interfaces', 'frontends/CsoundVST']) - guiProgramEnvironment.Append(CPPPATH = ['frontends/CsoundVST', 'interfaces']) - vstEnvironment.Prepend(LIBS = ['csnd']) - vstEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - vstEnvironment.Append(LIBS = libCsoundLibs) - if getPlatform() == 'linux': - vstEnvironment.Append(LIBS = ['util', 'dl', 'm']) - #vstEnvironment.Append(SHLINKFLAGS = '-Wl,--no-export-dynamic') - vstEnvironment.Append(LINKFLAGS = ['-Wl,-rpath-link,.']) - guiProgramEnvironment.Prepend(LINKFLAGS = ['-Wl,-rpath-link,.']) - elif getPlatform() == 'darwin': - vstEnvironment.Append(LIBS = ['dl', 'm']) - # vstEnvironment.Append(CXXFLAGS = ['-fabi-version=0']) # if gcc3.2-3 - vstEnvironment.Append(SHLINKFLAGS = '--no-export-all-symbols') - vstEnvironment.Append(SHLINKFLAGS = '--add-stdcall-alias') - vstEnvironment['SHLIBSUFFIX'] = '.dylib' - elif getPlatform() == 'win32': - if compilerGNU(): - vstEnvironment['ENV']['PATH'] = os.environ['PATH'] - vstEnvironment.Append(SHLINKFLAGS = Split('-Wl,--add-stdcall-alias')) - vstEnvironment.Append(CCFLAGS = ['-DNDEBUG']) - guiProgramEnvironment.Prepend(LINKFLAGS = Split(''' - -mwindows -Wl,--enable-runtime-pseudo-reloc - ''')) - vstEnvironment.Prepend(LINKFLAGS = ['-Wl,--enable-runtime-pseudo-reloc']) - guiProgramEnvironment.Append(LINKFLAGS = '-mwindows') - vstEnvironment.Append(LIBS = Split('fltk fltk_images fltk_png fltk_jpeg fltk_z')) - else: - vstEnvironment.Append(LIBS = Split('csound64 csnd fltk fltkimages fltkpng fltkjpeg fltkz')) - print 'PATH =', commonEnvironment['ENV']['PATH'] - csoundVstSources = Split(''' - frontends/CsoundVST/vstsdk2.4/public.sdk/source/vst2.x/audioeffect.cpp - frontends/CsoundVST/vstsdk2.4/public.sdk/source/vst2.x/audioeffectx.cpp - frontends/CsoundVST/vstsdk2.4/public.sdk/source/vst2.x/vstplugmain.cpp - frontends/CsoundVST/CsoundVST.cpp - frontends/CsoundVST/CsoundVstFltk.cpp - frontends/CsoundVST/CsoundVSTMain.cpp - frontends/CsoundVST/CsoundVstUi.cpp - ''') - if getPlatform() == 'win32': - vstEnvironment.Append(LIBS = csoundWindowsLibraries) - if compilerGNU(): - vstEnvironment.Append(SHLINKFLAGS = ['-module']) - vstEnvironment['ENV']['PATH'] = os.environ['PATH'] - csoundVstSources.append('frontends/CsoundVST/_CsoundVST.def') - csoundvst = vstEnvironment.SharedLibrary('CsoundVST', csoundVstSources) - libs.append(csoundvst) - Depends(csoundvst, csnd) - Depends(csoundvst, csoundLibrary) - guiProgramEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - if commonEnvironment['useDouble'] != '0': - csoundvstGui = guiProgramEnvironment.Program( - 'CsoundVSTShell', ['frontends/CsoundVST/csoundvst_main.cpp'], - LIBS = Split('csound64 csnd CsoundVST')) - else: - csoundvstGui = guiProgramEnvironment.Program( - 'CsoundVSTShell', ['frontends/CsoundVST/csoundvst_main.cpp'], - LIBS = Split('csound32 csnd CsoundVST')) - executables.append(csoundvstGui) - Depends(csoundvstGui, csoundvst) - -# Build csoundapi~ (pd class) - -print commonEnvironment['buildPDClass'], pdhfound -if commonEnvironment['buildPDClass'] == '1' and pdhfound: - print "CONFIGURATION DECISION: Building PD csoundapi~ class" - pdClassEnvironment = commonEnvironment.Clone() - pdClassEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - pdClassEnvironment.Append(LIBS = libCsoundLibs) - if getPlatform() == 'darwin': - pdClassEnvironment.Append(LINKFLAGS = Split(''' - -bundle -flat_namespace -undefined suppress - -framework Carbon -framework ApplicationServices - ''')) - pdClass = pdClassEnvironment.Program( - 'csoundapi~.pd_darwin', - 'frontends/csoundapi_tilde/csoundapi_tilde.c') - elif getPlatform() == 'linux': - pdClass = pdClassEnvironment.SharedLibrary( - 'csoundapi~.pd_linux', - 'frontends/csoundapi_tilde/csoundapi_tilde.c', - SHLIBPREFIX = '', SHLIBSUFFIX = '') - elif getPlatform() == 'win32': - pdClassEnvironment.Append(LIBS = ['pd']) - pdClassEnvironment.Append(LIBS = csoundWindowsLibraries) - pdClassEnvironment.Append(SHLINKFLAGS = ['-module']) - pdClassEnvironment['ENV']['PATH'] = os.environ['PATH'] - pdClass = pdClassEnvironment.SharedLibrary( - 'csoundapi~', 'frontends/csoundapi_tilde/csoundapi_tilde.c') - Depends(pdClass, csoundLibrary) - libs.append(pdClass) - -# Build tclcsound - -if commonEnvironment['buildTclcsound'] == '1' and tclhfound: - print "CONFIGURATION DECISION: Building Tclcsound frontend" - csTclEnvironment = commonEnvironment.Clone() - csTclEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - csTclEnvironment.Append(LIBS = libCsoundLibs) - if getPlatform() == 'darwin': - csTclEnvironment.Append(CCFLAGS = Split(''' - -I/Library/Frameworks/Tcl.framework/Headers - -I/Library/Frameworks/Tk.framework/Headers - -I/System/Library/Frameworks/Tcl.framework/Headers - -I/System/Library/Frameworks/Tk.framework/Headers - ''')) - csTclEnvironment.Append(LINKFLAGS = Split(''' - -framework tk -framework tcl - ''')) - elif getPlatform() == 'linux': - csTclEnvironment.Append(CPPPATH = tclIncludePath) - lib1 = 'tcl%s' % commonEnvironment['tclversion'] - lib2 = 'tk%s' % commonEnvironment['tclversion'] - csTclEnvironment.Append(LIBS = [lib1, lib2, 'dl', 'pthread']) - elif getPlatform() == 'win32': - lib1 = 'tcl%s' % commonEnvironment['tclversion'] - lib2 = 'tk%s' % commonEnvironment['tclversion'] - csTclEnvironment.Append(LIBS = [lib1, lib2]) - csTclEnvironment.Append(LIBS = csoundWindowsLibraries) - csTclEnvironment.Append(SHLINKFLAGS = ['-module']) - csTclCmdObj = csTclEnvironment.SharedObject( - 'frontends/tclcsound/commands.c') - csTcl = csTclEnvironment.Program( - 'cstclsh', ['frontends/tclcsound/main_tclsh.c', csTclCmdObj]) - csTk = csTclEnvironment.Program( - 'cswish', ['frontends/tclcsound/main_wish.c', csTclCmdObj]) - Tclcsoundlib = csTclEnvironment.SharedLibrary( - 'tclcsound', ['frontends/tclcsound/tclcsound.c', csTclCmdObj], - SHLIBPREFIX = '') - if getPlatform() == 'darwin': - csTclEnvironment.Command('cswish_resources', 'cswish', - "Rez -i APPL -o cswish frontends/tclcsound/cswish.r") - #if commonEnvironment['dynamicCsoundLibrary'] == '1': - # if commonEnvironment['useDouble'] == '0': - # tcloc = 'CsoundLib.framework/Resources/TclTk/' - # else: - # tcloc = 'CsoundLib64.framework/Resources/TclTk/' - # csTclEnvironment.Command('tclcsound_install', 'tclcsound.dylib', - # 'mkdir ' + tcloc + ';cp -R tclcsound.dylib ' + tcloc) - - Depends(csTcl, csoundLibrary) - Depends(csTk, csoundLibrary) - Depends(Tclcsoundlib, csoundLibrary) - executables.append(csTcl) - executables.append(csTk) - libs.append(Tclcsoundlib) - try: - os.mkdir('tclcsound', 0755) - except: - pass -# if getPlatform() == 'darwin': -# csTclEnvironment.Command('tclcsound/pkgIndex.tcl', 'tclcsound.dylib','cp tclcsound.dylib tclcsound; tclsh pkgbuild.tcl') -# elif getPlatform() == 'linux': -# csTclEnvironment.Command('tclcsound/pkgIndex.tcl', 'tclcsound.so','cp tclcsound.so tclcsound; tclsh pkgbuild.tcl') -# elif getPlatform() == 'win32': -# csTclEnvironment.Command('tclcsound/tclcsound.dll', 'tclcsound.dll','cp tclcsound.dll tclcsound') -# csTclEnvironment.Command('tclcsound/pkgIndex.tcl', 'tclcsound/tclcsound.dll','tclsh84 pkgbuild.tcl') - -else: - print "CONFIGURATION DECISION: Not building Tclcsound" - -# Build Winsound FLTK frontend - -if commonEnvironment['buildWinsound'] == '1' and fltkFound: - print "CONFIGURATION DECISION: Building Winsound frontend" - # should these be installed ? - # headers += glob.glob('frontends/winsound/*.h') - csWinEnvironment = commonEnvironment.Clone() - csWinEnvironment.Append(LINKFLAGS = libCsoundLinkFlags) - csWinEnvironment.Append(LIBS = libCsoundLibs) - # not used - # if (commonEnvironment['noFLTKThreads'] == '1'): - # csWinEnvironment.Append(CCFLAGS = ['-DNO_FLTK_THREADS']) - if getPlatform() == 'linux': - csWinEnvironment.ParseConfig('fltk-config --use-images --cflags --cxxflags --ldflags') - csWinEnvironment.Append(LIBS = ['stdc++', 'pthread', 'm']) - elif getPlatform() == 'win32': - if compilerGNU(): - csWinEnvironment.Append(LIBS = Split('fltk_images fltk_png fltk_jpeg fltk_z fltk')) - #csWinEnvironment.Append(LIBS = ['stdc++', 'supc++']) - csWinEnvironment.Prepend(LINKFLAGS = Split(''' - -mwindows -Wl,--enable-runtime-pseudo-reloc - ''')) - else: - csWinEnvironment.Append(LIBS = Split('fltkimages fltkpng fltkz fltkjpeg fltk')) - csWinEnvironment.Append(LIBS = csoundWindowsLibraries) - elif getPlatform() == 'darwin': - csWinEnvironment.Append(CXXFLAGS = ['-fno-rtti']) - csWinEnvironment.Append(LIBS = ['fltk', 'stdc++', 'pthread', 'm']) - csWinEnvironment.Append(LINKFLAGS = Split(''' - -framework Carbon -framework CoreAudio -framework CoreMIDI - -framework ApplicationServices - ''')) - appDir = 'frontends/winsound/Winsound.app/Contents/MacOS' - addOSXResourceFork(csWinEnvironment, 'winsound', '') - csWinEnvironment.Command( - '%s/winsound' % appDir, 'winsound', "cp $SOURCE %s/" % appDir) - addOSXResourceFork(csWinEnvironment, 'winsound', appDir) - winsoundFL = 'frontends/winsound/winsound.fl' - winsoundSrc = 'frontends/winsound/winsound.cxx' - winsoundHdr = 'frontends/winsound/winsound.h' - csWinEnvironment.Command( - [winsoundSrc, winsoundHdr], winsoundFL, - 'fluid -c -o %s -h %s %s' % (winsoundSrc, winsoundHdr, winsoundFL)) - winsoundMain = csWinEnvironment.Object('frontends/winsound/main.cxx') - Depends(winsoundMain, winsoundSrc) - winsound5 = csWinEnvironment.Program( - 'winsound', [winsoundMain, winsoundSrc]) - Depends(winsound5, csoundLibrary) - executables.append(winsound5) -else: - print "CONFIGURATION DECISION: Not building Winsound" - -#if (getPlatform() == 'darwin' and commonEnvironment['buildOSXGUI'] == '1'): -# print "CONFIGURATION DECISION: building OSX GUI frontend" -# csOSXGUIEnvironment = commonEnvironment.Clone() -# OSXGUI = csOSXGUIEnvironment.Command( -# '''frontends/OSX/build/Csound 5.app/Contents/MacOS/Csound 5''', -# 'frontends/OSX/main.c', -# "cd frontends/OSX; xcodebuild -buildstyle Deployment") -# Depends(OSXGUI, csoundLibrary) -#else: -# print "CONFIGURATION DECISION: Not building OSX GUI frontend" - -# build csLADSPA -print "CONFIGURATION DEFAULT: Building csLadspa." -csLadspaEnv = commonEnvironment.Clone() -csLadspaEnv.Append(LINKFLAGS = libCsoundLinkFlags) -csLadspaEnv.Append(LIBS=libCsoundLibs) -csLadspaEnv.Append(CCFLAGS='-I./frontends/csladspa') -if getPlatform() == "darwin": - if commonEnvironment['dynamicCsoundLibrary'] != '0': - csLadspaEnv.Append(LINKFLAGS=Split('''-bundle -undefined suppress -flat_namespace''')) - else: - csLadspaEnv.Append(LINKFLAGS="-bundle") - csladspa = csLadspaEnv.Program('csladspa.so', 'frontends/csladspa/csladspa.cpp' ) -else: - csladspa = csLadspaEnv.SharedLibrary('csladspa', 'frontends/csladspa/csladspa.cpp') -Depends(csladspa, csoundLibrary) -libs.append(csladspa) - -# Build beats (score generator) - -if not (commonEnvironment['buildBeats'] != '0'): - print 'CONFIGURATION DECISION: Not building beats score frontend.' -else: - print "CONFIGURATION DECISION: Building beats score frontend" - csBeatsEnvironment = commonEnvironment.Clone() - csBeatsEnvironment.Append(LINKFLAGS = ['-lm']) - csBeatsEnvironment.Append(YACCFLAGS = ['-d']) - #csBeatsEnvironment.Append(LEXFLAGS = ['-Pbeats']) - byb = csBeatsEnvironment.CFile(target = 'frontends/beats/beats.tab.c', - source = 'frontends/beats/beats.y') - blb = csBeatsEnvironment.CFile(target = 'frontends/beats/lex.yy.c', - source = 'frontends/beats/beats.l') - bb = csBeatsEnvironment.Program('csbeats', - ['frontends/beats/main.c', - byb, - blb]) - executables.append(bb) - -if not (commonEnvironment['buildcatalog'] != '0'): - print 'CONFIGURATION DECISION: Not building catalog builder.' -else: - print "CONFIGURATION DECISION: Building catalog builder" - catEnvironment = Environment(ENV = os.environ) - catEnvironment.Append(LINKFLAGS = ['-ldl']) - bb = catEnvironment.Program('mkdb', ['mkdb.c']) - executables.append(bb) - - -if (commonEnvironment['generateTags']=='0') or (getPlatform() != 'darwin' and getPlatform() != 'linux'): - print "CONFIGURATION DECISION: Not calling TAGS" -else: - print "CONFIGURATION DECISION: Calling TAGS" - allSources = string.join(glob.glob('*/*.h*')) - allSources = allSources + ' ' + string.join(glob.glob('*/*.c')) - allSources = allSources + ' ' + string.join(glob.glob('*/*.cpp')) - allSources = allSources + ' ' + string.join(glob.glob('*/*.hpp')) - allSources = allSources + ' ' + string.join(glob.glob('*/*/*.c')) - allSources = allSources + ' ' + string.join(glob.glob('*/*/*.cpp')) - allSources = allSources + ' ' + string.join(glob.glob('*/*/*.h')) - allSources = allSources + ' ' + string.join(glob.glob('*/*/*.hpp')) - tags = commonEnvironment.Command('TAGS', Split(allSources), 'etags $SOURCES') - Depends(tags, csoundLibrary) - -def gettextTarget(env, baseName, target): - gtFile = 'po/' + baseName + '.po' - ttFile = 'po/' + target + '/LC_MESSAGES/csound5.mo' - env.Command(ttFile, gtFile, - 'msgfmt -o %s %s' % (ttFile, gtFile)) - return ttFile - -if commonEnvironment['useGettext'] == '1': - csound5GettextEnvironment = csoundProgramEnvironment.Clone() - gettextTarget(csound5GettextEnvironment, 'french', 'fr') - gettextTarget(csound5GettextEnvironment, 'american', 'en_US') - gettextTarget(csound5GettextEnvironment, 'csound', 'en_GB') - gettextTarget(csound5GettextEnvironment, 'es_CO', 'es_CO') - ## The following are incomplete - gettextTarget(csound5GettextEnvironment, 'german', 'de') - gettextTarget(csound5GettextEnvironment, 'italian', 'it') - gettextTarget(csound5GettextEnvironment, 'romanian', 'ro') - gettextTarget(csound5GettextEnvironment, 'russian', 'ru') - -# INSTALL OPTIONS - -INSTDIR = commonEnvironment['instdir'] -PREFIX = INSTDIR + commonEnvironment['prefix'] - -BIN_DIR = PREFIX + "/bin" -INCLUDE_DIR = PREFIX + "/include/csound" - -if (commonEnvironment['Lib64'] == '1'): - LIB_DIR = PREFIX + "/lib64" - PYTHON_DIR = '%s/lib64' % sys.prefix -else: - LIB_DIR = PREFIX + "/lib" - PYTHON_DIR = '%s/lib' % sys.prefix -PYTHON_DIR += '/python%s/site-packages' % commonEnvironment['pythonVersion'] - -for i in sys.path: - if i[:sys.prefix.__len__()] == sys.prefix and i[-13:] == 'site-packages': - PYTHON_DIR = i - -if commonEnvironment['useDouble'] == '0': - PLUGIN_DIR = LIB_DIR + "/csound/plugins" -else: - PLUGIN_DIR = LIB_DIR + "/csound/plugins64" - -if commonEnvironment['install'] == '1': - installExecutables = Alias('install-executables', - Install(BIN_DIR, executables)) - installOpcodes = Alias('install-opcodes', - Install(PLUGIN_DIR, pluginLibraries)) - installHeaders = Alias('install-headers', - Install(INCLUDE_DIR, headers)) - installLibs = Alias('install-libs', - Install(LIB_DIR, libs)) - installPythonModules = Alias('install-py', - Install(PYTHON_DIR, pythonModules)) - Alias('install', [installExecutables, installOpcodes, installLibs, installHeaders, installPythonModules]) - -if getPlatform() == 'darwin' and commonEnvironment['useFLTK'] == '1': - print "CONFIGURATION DECISION: Adding resource fork for csound" - addOSXResourceFork(commonEnvironment, 'csound', '') - -###Code to create pkconfig files -#env = Environment(tools=['default', 'scanreplace'], toolpath=['tools']) -#env['prefix'] = '/usr/local' -#env.ScanReplace('csound5.pc.in') diff -Nru csound-5.17.11~dfsg/SDIF/sdif.h csound-6.02~dfsg/SDIF/sdif.h --- csound-5.17.11~dfsg/SDIF/sdif.h 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/SDIF/sdif.h 2014-01-07 16:53:48.000000000 +0000 @@ -306,8 +306,6 @@ #if defined(__POWERPC__) || defined(__PPC__) || defined(__ppc__) # undef LITTLE_ENDIAN -#elif defined(mac_classic) -# undef LITTLE_ENDIAN #endif SDIFresult SDIF_Write1(const void *block, size_t n, FILE *f); diff -Nru csound-5.17.11~dfsg/SDIF/sdif2adsyn.c csound-6.02~dfsg/SDIF/sdif2adsyn.c --- csound-5.17.11~dfsg/SDIF/sdif2adsyn.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/SDIF/sdif2adsyn.c 2014-01-07 16:53:48.000000000 +0000 @@ -8,8 +8,12 @@ #include "sdif.h" #include "sdif-mem.h" +#ifndef max #define max(x,y) ((x)>(y) ? (x) : (y)) +#endif +#ifndef min #define min(x,y) ((x)>(y) ? (y) : (x)) +#endif /* SDIF indices start from 1 */ #define MAXPARTIALS (1025) @@ -182,7 +186,7 @@ } result = SDIF_OpenRead(argv[1],&infile); - if (infile == NULL) { + if (result != ESDIF_SUCCESS) { fprintf(stderr,"Couldn't open %s: %s\n", argv[1], SDIF_GetErrorString(result)); exit(1); diff -Nru csound-5.17.11~dfsg/SuSE/README.SuSE csound-6.02~dfsg/SuSE/README.SuSE --- csound-5.17.11~dfsg/SuSE/README.SuSE 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/SuSE/README.SuSE 2014-01-07 16:53:48.000000000 +0000 @@ -3,11 +3,11 @@ The plugin binaries are installed under /usr/lib/csound/plugins (/usr/lib64/csound/plugins in x86_64). Please set the environment variable -"OPCODEDIR" to this direcrory before starting csound. +"OPCODE6DIR" to this directory before starting csound. in bash style, - export OPCODEDIR64=/usr/lib/csound/plugins + export OPCODE6DIR64=/usr/lib/csound/plugins in tcsh style, - setenv OPCODEDIR64 /usr/lib/csound/plugins + setenv OPCODE6DIR64 /usr/lib/csound/plugins Binary Renaming diff -Nru csound-5.17.11~dfsg/SuSE/csound.spec csound-6.02~dfsg/SuSE/csound.spec --- csound-5.17.11~dfsg/SuSE/csound.spec 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/SuSE/csound.spec 2014-01-07 16:53:48.000000000 +0000 @@ -20,13 +20,13 @@ Name: csound %define support_fltk 0 -BuildRequires: alsa-devel fdupes fluidsynth-devel gcc-c++ jack-devel liblo-devel portaudio-devel python-devel scons swig +BuildRequires: alsa-devel fdupes fluidsynth-devel gcc-c++ jack-devel liblo-devel portaudio-devel python-devel cmake swig %if %support_fltk BuildRequires: fltk-devel libjpeg-devel libpng-devel xorg-x11-devel %endif Summary: Computer Sound Synthesis and Composition Program -Version: 5.17.2 -Release: 135 +Version: 6.00 +Release: 141 License: GFDL-1.2 ; LGPL-2.1+ ; MIT Group: Productivity/Multimedia/Sound/Utilities Source: Csound%{version}.tar.bz2 @@ -48,9 +48,7 @@ %setup -q -n Csound%{version} cp %{SOURCE1} . # fix encoding -iconv -f latin1 -t utf8 readme-csound5.txt > readme-csound5.txt.utf8 -mv readme-csound5.txt.utf8 readme-csound5.txt -test -f custom.py || cp custom.py.mkg custom.py +iconv -f latin1 -t utf8 readme-csound6.txt > readme-csound6.txt.utf8 %build %if %_lib == "lib64" @@ -58,7 +56,8 @@ %else args="" %endif -scons prefix=%{_prefix} buildRelease=1 useDouble=1 useOSC=1 \ +cmake -DCMAKE_INSTALL_PREFIX=$RPM_BUILD_ROOT%{_prefix} -DUSE_LIB64=1 . +make prefix=%{_prefix} buildRelease=1 useDouble=1 useOSC=1 \ buildVirtual=1 buildBeats=1 $args \ customCCFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" \ customCXXFLAGS="$RPM_OPT_FLAGS -fno-strict-aliasing" @@ -70,8 +69,8 @@ args="" %endif mkdir -pv $RPM_BUILD_ROOT%{_datadir}/csound -./install.py --prefix=%{_prefix} --instdir="$RPM_BUILD_ROOT" $args -rm -f $RPM_BUILD_ROOT%{_prefix}/csound5-*.md5sums +make install +rm -f $RPM_BUILD_ROOT%{_prefix}/csound6-*.md5sums rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/csound # rename conflicting binary names mv $RPM_BUILD_ROOT%{_bindir}/sndinfo $RPM_BUILD_ROOT%{_bindir}/csndinfo @@ -87,7 +86,7 @@ %files %defattr(-,root,root) -%doc COPYING ChangeLog INSTALL readme-csound5.txt README.SuSE +%doc COPYING readme-csound6.txt README.SuSE %{_bindir}/* %{_libdir}/csound %{_datadir}/csound diff -Nru csound-5.17.11~dfsg/To-fix-and-do csound-6.02~dfsg/To-fix-and-do --- csound-5.17.11~dfsg/To-fix-and-do 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/To-fix-and-do 2014-01-07 16:53:48.000000000 +0000 @@ -1,3 +1,27 @@ +[CSOUND 6 TODOs] + +2) analyze and assess changes for CSOUND struct + There is a list below of fields not in API that are only used once + +3) Introduce Context Struct + +4) xtratim + +5) reparsing with active CSOUND instance + +6) Investigate the CSGLOBALS_USE_TREE option + +7) Should OENTRY table be hashed or tree? + +[These are not all checked and need investigation] +instxtcount 1 // set in Engine/csound_orc_compile.c but not used +optxtsize 1 // set in Engine/csound_orc_compile.c but not used +tran_nchnlsi 1 // in Engine/csound_orc_compile +sstrlen0 1 // Unfinished multiple strings + +gblacount etc replicated in otran structure and CSOUND +[ OLDER TODOs] + POWER OF TWO ISSUES ------------------- @@ -99,3 +123,15 @@ -look into creating API functions for programmatically building orc from opcodes, exposing INSTRTXT chain +----------------------------------------- +AGENDA + 1: Loadable instruments + 2: integration of UDOs + 3: I need to follow what you are doing over types + 4: ditto victor with sample-accuracy + 5: I relly need to code the better parallel dispatch + Can we simplify the environment variables? + Wht language changes do we need + also... removing power-of-2 tables in oscillators really slows things. + Should we implement a separate set of opcodes, or switch internally + diff -Nru csound-5.17.11~dfsg/Top/argdecode.c csound-6.02~dfsg/Top/argdecode.c --- csound-5.17.11~dfsg/Top/argdecode.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/argdecode.c 2014-01-07 16:54:20.000000000 +0000 @@ -1,7 +1,7 @@ /* argdecode.c: - Copyright (C) 1998 John ffitch + Copyright (C) 1998-2013 John ffitch, Victor Lazzarini This file is part of Csound. @@ -26,6 +26,7 @@ #include "csmodule.h" #include + extern void strset_option(CSOUND *csound, char *s); /* from str_ops.c */ #define FIND(MSG) if (*s == '\0') \ @@ -42,7 +43,7 @@ /* IV - Feb 19 2005 */ -static void set_stdin_assign(CSOUND *csound, int type, int state) +static inline void set_stdin_assign(CSOUND *csound, int type, int state) { if (state) csound->stdin_assign_flg |= type; @@ -50,7 +51,7 @@ csound->stdin_assign_flg &= (~type); } -static void set_stdout_assign(CSOUND *csound, int type, int state) +static inline void set_stdout_assign(CSOUND *csound, int type, int state) { if (state) csound->stdout_assign_flg |= type; @@ -63,9 +64,7 @@ Str_noop("--help\tprint long usage options"), Str_noop("-U unam\trun utility program unam"), Str_noop("-C\tuse Cscore processing of scorefile"), -#ifdef PARCS - Str_noop("-j N\tuse N processes"), -#endif + Str_noop("-j N\tuse N threads in performance"), Str_noop("-I\tI-time only orch run"), Str_noop("-n\tno sound onto disk"), Str_noop("-i fnam\tsound input filename"), @@ -123,13 +122,14 @@ static const char *longUsageList[] = { "--format={wav,aiff,au,raw,paf,svx,nist,voc,ircam,w64,mat4,mat5", - " pvf,xi,htk,sds,avr,wavex,sd2,flac,caf,WVE,ogg,MPC,W64}", - "--format={alaw,ulaw,schar,uchar,float,short,long,24bit}", + " pvf,xi,htk,sds,avr,wavex,sd2,flac,caf,wve,ogg,mpc2k,rf64}", + "--format={alaw,ulaw,schar,uchar,float,double,short,long,24bit,vorbis}", Str_noop("\t\t\tSet output file format"), Str_noop("--aiff\t\t\tSet AIFF format"), Str_noop("--au\t\t\tSet AU format"), Str_noop("--wave\t\t\tSet WAV format"), Str_noop("--ircam\t\t\tSet IRCAM format"), + Str_noop("--ogg\t\t\tSet OGG/VORBIS format"), Str_noop("--noheader\t\tRaw format"), Str_noop("--nopeaks\t\tDo not write peak information"), " ", @@ -138,30 +138,36 @@ Str_noop("--postscriptdisplay\tSuppress graphics, use Postscript displays"), " ", Str_noop("--defer-gen1\t\tDefer GEN01 soundfile loads until performance time"), - Str_noop("--iobufsamps=N\t\tSample frames (or -kprds) per software sound I/O buffer"), + Str_noop("--iobufsamps=N\t\tSample frames (or -kprds) per software " + "sound I/O buffer"), Str_noop("--hardwarebufsamps=N\tSamples per hardware sound I/O buffer"), Str_noop("--cscore\t\tUse Cscore processing of scorefile"), + Str_noop("--orc\t\t\tUse orchfile without scorefile"), " ", Str_noop("--midifile=FNAME\tRead MIDIfile event stream from file"), Str_noop("--midioutfile=FNAME\tWrite MIDI output to file FNAME"), Str_noop("--midi-device=FNAME\tRead MIDI realtime events from device"), Str_noop("--terminate-on-midi\tTerminate the performance when miditrack is done"), " ", - Str_noop("--heartbeat=N\t\tPrint a heartbeat style 1, 2 or 3 at each soundfile write"), + Str_noop("--heartbeat=N\t\tPrint a heartbeat style 1, 2 or 3 at " + "each soundfile write"), Str_noop("--notify\t\tNotify (ring the bell) when score or miditrack is done"), - Str_noop("--rewrite\t\tContinually rewrite header while writing soundfile (WAV/AIFF)"), + Str_noop("--rewrite\t\tContinually rewrite header while writing " + "soundfile (WAV/AIFF)"), " ", Str_noop("--input=FNAME\t\tSound input filename"), Str_noop("--output=FNAME\t\tSound output filename"), Str_noop("--logfile=FNAME\t\tLog output to file"), " ", Str_noop("--nosound\t\tNo sound onto disk or device"), - Str_noop("--tempo=N\t\tUse uninterpreted beats of the score, initially at tempo N"), + Str_noop("--tempo=N\t\tUse uninterpreted beats of the score, initially" + " at tempo N"), Str_noop("--i-only\t\tI-time only orch run"), Str_noop("--syntax-check-only\tStop after checking orchestra and score syntax"), Str_noop("--control-rate=N\tOrchestra krate override"), Str_noop("--sample-rate=N\t\tOrchestra srate override"), - Str_noop("--score-in=FNAME\tRead Line-oriented realtime score events from device"), + Str_noop("--score-in=FNAME\tRead Line-oriented realtime score events" + " from device"), Str_noop("--messagelevel=N\ttty message level, sum of:"), Str_noop("--messageolevel=O\ttty message level in octal, of:"), Str_noop("\t\t\t\t1=note amps, 2=out-of-range msg, 4=warnings,"), @@ -179,7 +185,6 @@ Str_noop("\t\t\t1=use CSD line #s (default), 0=use ORC/SCO-relative line #s"), Str_noop("--extract-score=FNAME\tExtract from score.srt using extract file"), Str_noop("--keep-sorted-score"), - Str_noop("--expression-opt\tOptimise use of temporary variables in expressions"), Str_noop("--env:NAME=VALUE\tSet environment variable NAME to VALUE"), Str_noop("--env:NAME+=VALUE\tAppend VALUE to environment variable NAME"), Str_noop("--strsetN=VALUE\t\tSet strset table at index N to VALUE"), @@ -209,12 +214,19 @@ Str_noop("--midi-velocity-amp=N\tRoute MIDI note on message"), Str_noop("\t\t\tvelocity number to pfield N as amplitude"), Str_noop("--no-default-paths\tTurn off relative paths from CSD/ORC/SCO"), -#if ENABLE_NEW_PARSER - Str_noop("--new-parser\t\tUse new Bison-based parser"), - Str_noop("--old-parser\t\tUse old parser"), -#endif + Str_noop("--sample-accurate\t\tUse sample-accurate timing of score events"), + Str_noop("--realtime\t\trealtime priority mode"), + Str_noop("--nchnls=N\t\t override number of audio channels"), + Str_noop("--nchnls_i=N\t\t override number of input audio channels"), + Str_noop("--0dbfs=N\t\t override 0dbfs (max positive signal amplitude)"), + Str_noop("--sinesize\t\tlength of internal sine table"), + Str_noop("--daemon\t\t daemon mode: do not exit if CSD/orchestra is " + "not given, is empty or does not compile"), + Str_noop("--port=N\t\t listen to UDP port N for instruments/orchestra " + "code (implies --daemon)"), " ", Str_noop("--help\t\t\tLong help"), + NULL }; @@ -245,7 +257,7 @@ dump_cfg_variables(p); p->Message(p, Str("\nShort form:\n")); print_short_usage(p); - p->LongJmp(p, 0); + // p->LongJmp(p, 0); } void dieu(CSOUND *csound, char *s, ...) @@ -258,8 +270,10 @@ va_start(args, s); csound->ErrMsgV(csound, Str("Csound Command ERROR:\t"), s, args); va_end(args); - + if(csound->info_message_request == 0){ + csound->info_message_request = 0; csound->LongJmp(csound, 1); + } } void set_output_format(OPARMS *O, char c) @@ -281,6 +295,10 @@ O->outformat = AE_FLOAT; /* float soundfile */ break; + case 'd': + O->outformat = AE_DOUBLE; /* double soundfile */ + break; + case 's': O->outformat = AE_SHORT; /* short_int soundfile*/ break; @@ -301,6 +319,10 @@ O->outformat = AE_FLOAT; /* float soundfile (for rescaling) */ break; + case 'v': + O->outformat = AE_VORBIS; /* Xiph Vorbis encoding */ + break; + default: return; /* do nothing */ }; @@ -313,9 +335,9 @@ static const SAMPLE_FORMAT_ENTRY sample_format_map[] = { { "alaw", 'a' }, { "schar", 'c' }, { "uchar", '8' }, - { "float", 'f' }, { "long", 'l' }, + { "float", 'f' }, { "double", 'd' }, { "long", 'l' }, { "short", 's' }, { "ulaw", 'u' }, { "24bit", '3' }, - { NULL, '\0' } + { "vorbis", 'v' }, { NULL, '\0' } }; typedef struct { @@ -333,18 +355,10 @@ { "pvf", TYP_PVF }, { "xi", TYP_XI }, { "htk", TYP_HTK }, { "sds", TYP_SDS }, { "avr", TYP_AVR }, { "wavex", TYP_WAVEX }, -#if defined(HAVE_LIBSNDFILE) && HAVE_LIBSNDFILE >= 1011 { "sd2", TYP_SD2 }, -# if HAVE_LIBSNDFILE >= 1013 { "flac", TYP_FLAC }, { "caf", TYP_CAF }, -# endif -# if HAVE_LIBSNDFILE >= 1018 - { "WVE", TYP_WVE }, { "ogg", TYP_OGG }, -# endif -# if HAVE_LIBSNDFILE >= 1019 - { "MPC", TYPE_MPC2K }, { "W64", TYP_RF64 }, -# endif -#endif + { "wve", TYP_WVE }, { "ogg", TYP_OGG }, + { "mpc2k", TYP_MPC2K }, { "rf64", TYP_RF64 }, { NULL , -1 } }; @@ -418,6 +432,10 @@ O->inbufsamps = O->outbufsamps = atoi(s); return 1; } + else if (!(strcmp (s, "orc"))) { + csound->use_only_orchfile = 1; /* orchfile without scorefile */ + return 1; + } else if (!(strcmp (s, "cscore"))) { O->usingcscore = 1; /* use cscore processing */ return 1; @@ -439,9 +457,10 @@ if (UNLIKELY(*s == '\0')) dieu(csound, Str("no midifile name")); O->FMidiname = s; /* Midifile name */ if (!strcmp(O->FMidiname, "stdin")) { - set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("-F: stdin not supported on this platform")); +#else + set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 1); #endif } else @@ -492,7 +511,7 @@ csoundDie(csound, Str("input cannot be stdout")); if (strcmp(O->infilename, "stdin") == 0) { set_stdin_assign(csound, STDINASSIGN_SNDFILE, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("stdin audio not supported")); #endif } @@ -518,6 +537,11 @@ O->filetyp = TYP_IRCAM; /* IRCAM output request */ return 1; } + else if (!(strcmp (s, "ogg"))) { + O->filetyp = TYP_OGG; /* OGG output request */ + O->outformat = AE_VORBIS; /* Xiph Vorbis encoding */ + return 1; + } /* -k N orchestra krate override */ @@ -541,9 +565,6 @@ O->Linename = s; if (!strcmp(O->Linename, "stdin")) { set_stdin_assign(csound, STDINASSIGN_LINEIN, 1); -#if defined(mac_classic) - csoundDie(csound, Str("-L: stdin not supported on this platform")); -#endif } else set_stdin_assign(csound, STDINASSIGN_LINEIN, 0); @@ -644,7 +665,7 @@ O->Midiname = s; if (!strcmp(O->Midiname, "stdin")) { set_stdin_assign(csound, STDINASSIGN_MIDIDEV, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("-M: stdin not supported on this platform")); #endif } @@ -671,7 +692,7 @@ dieu(csound, Str("-o cannot be stdin")); if (strcmp(O->outfilename, "stdout") == 0) { set_stdout_assign(csound, STDOUTASSIGN_SNDFILE, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("stdout audio not supported")); #endif } @@ -738,8 +759,15 @@ int retval; s += 8; if (*s=='\0') dieu(csound, Str("no utility name")); + retval = csoundRunUtility(csound, s, argc, argv); - csound->LongJmp(csound, retval); + if(retval) { + csound->info_message_request = 1; + csound->orchname = NULL; + return 0; + } + else csound->LongJmp(csound, retval); + return 1; } /* -v */ else if (!(strcmp (s, "verbose"))) { @@ -764,11 +792,13 @@ if (*s != '\0') { if (isdigit(*s)) full = *s++ - '0'; } - csoundLoadExternals(csound); - if (csoundInitModules(csound) != 0) - csound->LongJmp(csound, 1); + /* VL: moved to csoundReset() in csound.c + csoundLoadExternals(csound); + if (csoundInitModules(csound) != 0) + csound->LongJmp(csound, 1); */ list_opcodes(csound, full); - csound->LongJmp(csound, 0); + return 1; + //csound->LongJmp(csound, 0); } /* -Z */ else if (!(strcmp (s, "dither"))) { @@ -852,48 +882,62 @@ } else if (!(strcmp(s, "help"))) { longusage(csound); - csound->LongJmp(csound, 0); - } -#ifdef ENABLE_NEW_PARSER - else if (!(strcmp(s, "new-parser"))) { - O->newParser = 1; /* Use New Parser */ + csound->info_message_request = 1; return 1; + //csound->LongJmp(csound, 0); } -#ifdef PARCS - else if (!(strncmp(s, "weight-info=", 12))) { - s += 12; - if (*s=='\0') dieu(csound, Str("no weight-info")); - csound->weight_info = s; + else if (!(strcmp(s, "sample-accurate"))) { + O->sampleAccurate = 1; return 1; } - else if (!(strncmp(s, "weight-dump=", 12))) { - s += 12; - if (*s=='\0') dieu(csound, Str("no weight-dump")); - csound->weight_dump = s; + else if (!(strcmp(s, "realtime"))) { + O->realtime = 1; return 1; } - else if (!(strncmp(s, "weights=", 8))) { - s += 8; - if (*s=='\0') dieu(csound, Str("no weights")); - csound->weights = s; + else if (!(strncmp(s, "nchnls=", 7))) { + s += 7; + O->nchnls_override = atoi(s); return 1; } - else if (!(strcmp(s, "compute-weights"))) { - O->calculateWeights = 1; + else if (!(strncmp(s, "0dbfs=", 6))) { + s += 6; + O->e0dbfs_override = atoi(s); return 1; } -#endif - else if (!(strcmp(s, "old-parser"))) { - O->newParser = 0; /* Use Old Parser */ + else if (!(strncmp(s, "nchnls_i=", 9))) { + s += 9; + O->nchnls_i_override = atoi(s); return 1; } -#endif + else if (!(strncmp(s, "sinesize=", 9))) { + { + int i = 1, n; + s += 9; + n = atoi(s); + while (i<=n && i< MAXLEN) i <<= 1; + csound->sinelength = i; + return 1; + } + } + else if (!(strcmp(s, "new-parser")) || + !(strcmp(s, "old-parser"))) { + return 1; /* ignore flag, this is here for backwards compatibility */ + } + else if (!(strcmp(s, "daemon"))) { + O->daemon = 1; + return 1; + } + else if (!(strncmp(s, "port=",5))) { + s += 5; + O->daemon = atoi(s); + return 1; + } csoundErrorMsg(csound, Str("unknown long option: '--%s'"), s); return 0; } -int argdecode(CSOUND *csound, int argc, char **argv_) +PUBLIC int argdecode(CSOUND *csound, int argc, char **argv_) { OPARMS *O = csound->oparms; char *s, **argv; @@ -927,7 +971,12 @@ FIND(Str("no utility name")); { int retval = csoundRunUtility(csound, s, argc, argv); - csound->LongJmp(csound, retval); + if(retval) { + csound->info_message_request = 1; + csound->orchname = NULL; + goto end; + } + else csound->LongJmp(csound, retval); } break; case 'C': @@ -947,7 +996,7 @@ csoundDie(csound, Str("input cannot be stdout")); if (strcmp(O->infilename, "stdin") == 0) { set_stdin_assign(csound, STDINASSIGN_SNDFILE, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("stdin audio not supported")); #endif } @@ -963,7 +1012,7 @@ dieu(csound, Str("-o cannot be stdin")); if (strcmp(O->outfilename, "stdout") == 0) { set_stdout_assign(csound, STDOUTASSIGN_SNDFILE, 1); -#if defined(WIN32) || defined(mac_classic) +#if defined(WIN32) csoundDie(csound, Str("stdout audio not supported")); #endif } @@ -1059,9 +1108,6 @@ s += (int) strlen(s); if (!strcmp(O->Linename, "stdin")) { set_stdin_assign(csound, STDINASSIGN_LINEIN, 1); -#if defined(mac_classic) - csoundDie(csound, Str("-L: stdin not supported on this platform")); -#endif } else set_stdin_assign(csound, STDINASSIGN_LINEIN, 0); @@ -1071,10 +1117,11 @@ FIND(Str("no midi device_name")); O->Midiname = s; /* Midi device name */ s += (int) strlen(s); - if (!strcmp(O->Midiname, "stdin")) { - set_stdin_assign(csound, STDINASSIGN_MIDIDEV, 1); -#if defined(WIN32) || defined(mac_classic) + if (strcmp(O->Midiname, "stdin")==0) { +#if defined(WIN32) csoundDie(csound, Str("-M: stdin not supported on this platform")); +#else + set_stdin_assign(csound, STDINASSIGN_MIDIDEV, 1); #endif } else @@ -1085,10 +1132,11 @@ FIND(Str("no midifile name")); O->FMidiname = s; /* Midifile name */ s += (int) strlen(s); - if (!strcmp(O->FMidiname, "stdin")) { - set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 1); -#if defined(WIN32) || defined(mac_classic) + if (strcmp(O->FMidiname, "stdin")==0) { +#if defined(WIN32) csoundDie(csound, Str("-F: stdin not supported on this platform")); +#else + set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 1); #endif } else @@ -1129,12 +1177,14 @@ if (*s != '\0') { if (isdigit(*s)) full = *s++ - '0'; } + /* VL: moved to csoundReset() in csound.c csoundLoadExternals(csound); if (csoundInitModules(csound) != 0) - csound->LongJmp(csound, 1); + csound->LongJmp(csound, 1); */ list_opcodes(csound, full); } - csound->LongJmp(csound, 0); + csound->info_message_request = 1; + // csound->LongJmp(csound, 0); break; case 'Z': { @@ -1192,6 +1242,7 @@ while (*(++s)); break; default: + if(csound->info_message_request == 0) dieu(csound, Str("unknown flag -%c"), c); } } @@ -1200,7 +1251,7 @@ /* 0: normal, 1: ignore, 2: fail */ if (csound->orcname_mode == 2) { csound->Die(csound, Str("error: orchestra and score name not " - "allowed in .csoundrc")); + "allowed in .csound6rc")); } else if (csound->orcname_mode == 0) { if (csound->orchname == NULL) @@ -1214,6 +1265,245 @@ } } } while (--argc); + end: return 1; } +PUBLIC int csoundSetOption(CSOUND *csound, char *option){ + /* if already compiled and running, return */ + csound->info_message_request = 1; + if(csound->engineStatus & CS_STATE_COMP) return 1; + char *args[2] = {"csound", option}; + return (argdecode(csound, 1, args) ? 0 : 1); +} + +PUBLIC void csoundSetParams(CSOUND *csound, CSOUND_PARAMS *p){ + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + OPARMS *oparms = csound->oparms; + /* simple ON/OFF switches */ + oparms->odebug = p->debug_mode; + oparms->displays = p->displays; + oparms->graphsoff = p->ascii_graphs; + oparms->postscript = p->postscript_graphs; + oparms->usingcscore = p->use_cscore; + oparms->ringbell = p->ring_bell; + oparms->gen01defer = p->defer_gen01_load; + oparms->termifend = p->terminate_on_midi; + oparms->noDefaultPaths = p->no_default_paths; + oparms->syntaxCheckOnly = p->syntax_check_only; + oparms->sampleAccurate = p->sample_accurate; + oparms->realtime = p->realtime_mode; + oparms->useCsdLineCounts = p->csd_line_counts; + oparms->heartbeat = p->heartbeat; + oparms->ringbell = p->ring_bell; + oparms->daemon = p->daemon; + + /* message level */ + if(p->message_level > 0) + oparms->msglevel = p->message_level; + + /* tempo / beatmode */ + if(p->tempo > 0) { + oparms->cmdTempo = p->tempo; + oparms->Beatmode = 1; + } + /* buffer frames */ + if(p->buffer_frames > 0) + oparms->inbufsamps = oparms->outbufsamps = p->buffer_frames; + + /* hardware buffer frames */ + if(p->hardware_buffer_frames > 0) + oparms->oMaxLag = p->hardware_buffer_frames; + + /* multicore threads */ + if(p->number_of_threads > 1) + oparms->numThreads = p->number_of_threads; + + /* MIDI interop */ + if(p->midi_key > 0) oparms->midiKey = p->midi_key; + else if(p->midi_key_cps > 0) oparms->midiKeyCps = p->midi_key_cps; + else if(p->midi_key_pch > 0) oparms->midiKeyPch = p->midi_key_pch; + else if(p->midi_key_oct > 0) oparms->midiKeyOct = p->midi_key_oct; + + if(p->midi_velocity > 0) oparms->midiVelocity = p->midi_velocity; + else if(p->midi_velocity_amp > 0) oparms->midiVelocityAmp = p->midi_velocity_amp; + + /* CSD line counts */ + if(p->csd_line_counts > 0) oparms->useCsdLineCounts = p->csd_line_counts; + + /* kr override */ + if(p->control_rate_override > 0) oparms->kr_override = p->control_rate_override; + + /* sr override */ + if(p->sample_rate_override > 0) oparms->sr_override = p->sample_rate_override; + + oparms->nchnls_override = p->nchnls_override; + oparms->nchnls_i_override = p->nchnls_i_override; + oparms->e0dbfs_override = p->e0dbfs_override; +} + +PUBLIC void csoundGetParams(CSOUND *csound, CSOUND_PARAMS *p){ + + OPARMS *oparms = csound->oparms; + + p->debug_mode = oparms->odebug; + p->displays = oparms->displays; + p->ascii_graphs = oparms->graphsoff; + p->postscript_graphs = oparms->postscript; + p->use_cscore = oparms->usingcscore; + p->ring_bell = oparms->ringbell; + p->defer_gen01_load = oparms->gen01defer; + p->terminate_on_midi = oparms->termifend; + p->no_default_paths = oparms->noDefaultPaths; + p->syntax_check_only = oparms->syntaxCheckOnly; + p->sample_accurate = oparms->sampleAccurate; + p->realtime_mode = oparms->realtime; + p->message_level = oparms->msglevel; + p->tempo = oparms->cmdTempo; + p->buffer_frames = oparms->outbufsamps; + p->hardware_buffer_frames = oparms->oMaxLag; + p->number_of_threads = oparms->numThreads; + p->midi_key = oparms->midiKey; + p->midi_key_cps = oparms->midiKeyCps; + p->midi_key_pch = oparms->midiKeyPch; + p->midi_key_oct = oparms->midiKeyOct; + p->midi_velocity = oparms->midiVelocity; + p->midi_velocity_amp = oparms->midiVelocityAmp; + p->csd_line_counts = oparms->useCsdLineCounts; + p->control_rate_override = oparms->kr_override; + p->sample_rate_override = oparms->sr_override; + p->nchnls_override = oparms->nchnls_override; + p->nchnls_i_override = oparms->nchnls_i_override; + p->e0dbfs_override = oparms->e0dbfs_override; + p->heartbeat = oparms->heartbeat; + p->ring_bell = oparms->ringbell; + p->daemon = oparms->daemon; +} + + +PUBLIC void csoundSetOutput(CSOUND *csound, char *name, char *type, char *format){ + + OPARMS *oparms = csound->oparms; + char *typename; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->outfilename = + csound->Malloc(csound, strlen(name) + 1); /* will be freed by memRESET */ + strcpy(oparms->outfilename, name); + if (strcmp(oparms->outfilename, "stdout") == 0) { + set_stdout_assign(csound, STDOUTASSIGN_SNDFILE, 1); +#if defined(WIN32) + csound->Warning(csound, Str("stdout not supported on this platform")); +#endif + } + else set_stdout_assign(csound, STDOUTASSIGN_SNDFILE, 0); + + oparms->sfwrite = 1; + if(type != NULL){ + int i=0; + while((typename = file_type_map[i].format) != NULL) { + if(!strcmp(type,typename)) break; + i++; + } + if(typename != NULL) { + oparms->filetyp = file_type_map[i].type; + } + } + if(format != NULL){ + int i=0; + while((typename = sample_format_map[i].longformat) != NULL) { + if(!strcmp(type,typename)) break; + i++; + } + if(format != NULL) { + set_output_format(oparms, sample_format_map[i].shortformat); + } + } +} + +PUBLIC void csoundSetInput(CSOUND *csound, char *name) { + OPARMS *oparms = csound->oparms; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->infilename = + csound->Malloc(csound, strlen(name)); /* will be freed by memRESET */ + strcpy(oparms->infilename, name); + if (strcmp(oparms->infilename, "stdin") == 0) { + set_stdin_assign(csound, STDINASSIGN_SNDFILE, 1); +#if defined(WIN32) + csound->Warning(csound, Str("stdin not supported on this platform")); +#endif + } + else + set_stdin_assign(csound, STDINASSIGN_SNDFILE, 0); + oparms->sfread = 1; +} + +PUBLIC void csoundSetMIDIInput(CSOUND *csound, char *name) { + OPARMS *oparms = csound->oparms; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->Midiname = + csound->Malloc(csound, strlen(name)); /* will be freed by memRESET */ + strcpy(oparms->Midiname, name); + if (!strcmp(oparms->Midiname, "stdin")) { + set_stdin_assign(csound, STDINASSIGN_MIDIDEV, 1); +#if defined(WIN32) + csound->Warning(csound, Str("stdin not supported on this platform")); +#endif + } + else + set_stdin_assign(csound, STDINASSIGN_MIDIDEV, 0); + oparms->Midiin = 1; +} + +PUBLIC void csoundSetMIDIFileInput(CSOUND *csound, char *name) { + OPARMS *oparms = csound->oparms; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->FMidiname = + csound->Malloc(csound, strlen(name)); /* will be freed by memRESET */ + strcpy(oparms->FMidiname, name); + if (!strcmp(oparms->FMidiname, "stdin")) { + set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 1); +#if defined(WIN32) + csound->Warning(csound, Str("stdin not supported on this platform")); +#endif + } + else + set_stdin_assign(csound, STDINASSIGN_MIDIFILE, 0); + oparms->FMidiin = 1; +} + +PUBLIC void csoundSetMIDIFileOutput(CSOUND *csound, char *name) { + OPARMS *oparms = csound->oparms; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->FMidioutname = + csound->Malloc(csound, strlen(name)); /* will be freed by memRESET */ + strcpy(oparms->FMidioutname, name); +} + +PUBLIC void csoundSetMIDIOutput(CSOUND *csound, char *name) { + OPARMS *oparms = csound->oparms; + + /* if already compiled and running, return */ + if(csound->engineStatus & CS_STATE_COMP) return; + + oparms->Midioutname = + csound->Malloc(csound, strlen(name)); /* will be freed by memRESET */ + strcpy(oparms->Midioutname, name); +} diff -Nru csound-5.17.11~dfsg/Top/cscorfns.c csound-6.02~dfsg/Top/cscorfns.c --- csound-5.17.11~dfsg/Top/cscorfns.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/cscorfns.c 2014-01-07 16:53:48.000000000 +0000 @@ -270,9 +270,9 @@ p = &evtmp->p[1]; q = &evtmp->p[PMAX]; #ifdef USE_DOUBLE - while (sscanf(s,"%lf",p++) > 0) /* read pfields */ + while (CS_SSCANF(s,"%lf",p++) > 0) /* read pfields */ #else - while (sscanf(s,"%f",p++) > 0) /* read pfields */ + while (CS_SSCANF(s,"%f",p++) > 0) /* read pfields */ #endif { while ((*s >= '0' && *s <= '9') || *s == '.' || *s == '-') @@ -843,7 +843,7 @@ next = cscoreCreateEvent(csound, PMAX); /* creat EVENT blk receiving buf */ next->op = '\0'; savinfdata(csound, csound->scfp, - next, FL(0.0), 1, 0, 0); /* curuntil 0, wasend, non-warp, not eof */ + next, FL(0.0), 1, 0, 0);/* curuntil 0, wasend, non-warp, not eof */ makecurrent(csound, csound->scfp); /* make all this current */ return CSOUND_SUCCESS; @@ -873,7 +873,7 @@ next->op = '\0'; savinfdata(csound, csound->scfp, - next, FL(0.0), 1, 0, 0); /* curuntil 0, wasend, non-warp, not eof */ + next, FL(0.0), 1, 0, 0);/* curuntil 0, wasend, non-warp, not eof */ makecurrent(csound, csound->scfp); /* make all this current */ return CSOUND_SUCCESS; diff -Nru csound-5.17.11~dfsg/Top/csmodule.c csound-6.02~dfsg/Top/csmodule.c --- csound-5.17.11~dfsg/Top/csmodule.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/csmodule.c 2014-01-07 16:54:20.000000000 +0000 @@ -27,7 +27,7 @@ * ==================== * * * * Plugin libraries are loaded from the directory defined by the environment * - * variable OPCODEDIR (or the current directory if OPCODEDIR is unset) by * + * variable OPCODE6DIR (or the current directory if OPCODE6DIR is unset) by * * csoundPreCompile() while initialising a Csound instance, and are unloaded * * at the end of performance by csoundReset(). * * A library may export any of the following five interface functions, * @@ -81,19 +81,20 @@ #if defined(__MACH__) #include #if (TARGET_OS_IPHONE == 0) && (TARGET_IPHONE_SIMULATOR == 0) -#if defined(MAC_OS_X_VERSION_10_6) && (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_6) +#if defined(MAC_OS_X_VERSION_10_6) && \ + (MAC_OS_X_VERSION_MIN_REQUIRED>=MAC_OS_X_VERSION_10_6) #define NEW_MACH_CODE -#else -#define OLD_MACH_CODE #endif #endif #endif +#if !(defined (NACL)) #if defined(LINUX) || defined(NEW_MACH_CODE) #include #elif defined(WIN32) #include #endif +#endif #if defined(HAVE_DIRENT_H) @@ -109,9 +110,6 @@ #if defined(WIN32) # include # include -#elif defined (OLD_MACH_CODE) -# define ERR_STR_LEN 255 -# include #endif extern int allocgen(CSOUND *, char *, int (*)(FGDATA *, FUNC *)); @@ -129,10 +127,11 @@ static const char *InfoFunc_Name = "csoundModuleInfo"; /* environment variable storing path to plugin libraries */ -static const char *plugindir_envvar = "OPCODEDIR"; -static const char *plugindir64_envvar = "OPCODEDIR64"; +static const char *plugindir_envvar = "OPCODE6DIR"; +static const char *plugindir64_envvar = "OPCODE6DIR64"; /* default directory to load plugins from if environment variable is not set */ +#if !(defined (NACL)) #if !(defined(_CSOUND_RELEASE_) && (defined(LINUX) || defined(__MACH__))) # define ENABLE_OPCODEDIR_WARNINGS 1 # ifdef CS_DEFAULT_PLUGINDIR @@ -149,6 +148,7 @@ # endif # endif #endif +#endif #if (TARGET_OS_IPHONE != 0) && (TARGET_IPHONE_SIMULATOR != 0) # define ENABLE_OPCODEDIR_WARNINGS 0 @@ -182,12 +182,12 @@ const char *fmt, const char *fname, const csoundModule_t *m, int err) { - csound->MessageS(csound, CSOUNDMSG_ERROR, Str(fmt), fname); + csoundMessageS(csound, CSOUNDMSG_ERROR, Str(fmt), fname); if (m != NULL && m->fn.p.ErrCodeToStr != NULL) - csound->MessageS(csound, CSOUNDMSG_ERROR, + csoundMessageS(csound, CSOUNDMSG_ERROR, ": %s\n", Str(m->fn.p.ErrCodeToStr(err))); else - csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); + csoundMessageS(csound, CSOUNDMSG_ERROR, "\n"); } static int check_plugin_compatibility(CSOUND *csound, const char *fname, int n) @@ -196,7 +196,7 @@ myfltSize = n & 0xFF; if (UNLIKELY(myfltSize != 0 && myfltSize != (int) sizeof(MYFLT))) { - csound->Warning(csound, Str("not loading '%s' (uses incompatible " + csoundWarning(csound, Str("not loading '%s' (uses incompatible " "floating point type)"), fname); return -1; } @@ -204,9 +204,8 @@ minorVersion = (n & 0xFF00) >> 8; majorVersion = (n & (~0xFFFF)) >> 16; if (majorVersion != (int) CS_APIVERSION || - (minorVersion > (int) CS_APISUBVER) || - (minorVersion <= 5)) { /* NOTE **** REFACTOR *** */ - csound->Warning(csound, Str("not loading '%s' (incompatible " + (minorVersion > (int) CS_APISUBVER)) { /* NOTE **** REFACTOR *** */ + csoundWarning(csound, Str("not loading '%s' (incompatible " "with this version of Csound (%d.%d/%d.%d)"), fname, majorVersion,minorVersion, CS_APIVERSION,CS_APISUBVER); @@ -243,12 +242,12 @@ return CSOUND_ERROR; /* load library */ /* #if defined(LINUX) */ -/* printf("About to open library '%s'\n", libraryPath); */ + // printf("About to open library '%s'\n", libraryPath); /* #endif */ - err = csound->OpenLibrary(&h, libraryPath); + err = csoundOpenLibrary(&h, libraryPath); if (UNLIKELY(err)) { char ERRSTR[256]; - #if defined(LINUX) +#if !(defined(NACL)) && defined(LINUX) sprintf(ERRSTR, Str("could not open library '%s' (%s)"), libraryPath, dlerror()); #else @@ -260,9 +259,14 @@ strcpy(csound->delayederrormessages, ERRSTR); } else { - csound->delayederrormessages = + char *new = realloc(csound->delayederrormessages, strlen(csound->delayederrormessages)+strlen(ERRSTR)+11); + if (new==NULL) { + free(csound->delayederrormessages); + return CSOUND_ERROR; + } + csound->delayederrormessages = new; strcat(csound->delayederrormessages, "\nWARNING: "); strcat(csound->delayederrormessages, ERRSTR); } @@ -354,6 +358,7 @@ { /* Check to see if the fname is on the do-not-load list */ char buff[256]; + char *th; char *p, *deny; char *list = getenv("CS_OMIT_LIBS"); /* printf("DEBUG %s(%d): check fname=%s\n", __FILE__, __LINE__, fname); */ @@ -362,7 +367,7 @@ strcpy(buff, fname); strrchr(buff, '.')[0] = '\0'; /* Remove .so etc */ p = strdup(list); - deny = strtok(p, ","); + deny = cs_strtok_r(p, ",", &th); /* printf("DEBUG %s(%d): check buff=%s\n", __FILE__, __LINE__, deny); */ while (deny) { /* printf("DEBUG %s(%d): deny=%s\n", __FILE__, __LINE__, deny); */ @@ -371,293 +376,13 @@ /* printf("DEBUG %s(%d): found\n", __FILE__, __LINE__); */ return 1; } - deny = strtok(NULL, ","); + deny = cs_strtok_r(NULL, ",", &th); } free(p); /* printf("DEBUG %s(%d): not found\n", __FILE__, __LINE__); */ return 0; } -#ifdef mac_classic -/* The following code implements scanning of "OPCODEDIR" - and auto-loading of plugins for MacOS 9 */ - - -/* These structures describe the 'cfrg' resource used by system sw */ -typedef struct { - OSType codeType; - long updateLevel; - long curVersion; - long oldVersion; - long stackSize; - int16 libraryDir; - char fragType; - char fragLocation; - long fragOffset; - long fragLength; - long reservedA; - long reservedB; - int16 descLength; - Str63 fragName; -} cfrg_desc; - -typedef struct { - long reserved1; - long reserved2; - long version; - long reserved3; - long reserved4; - long reserved5; - long reserved6; - long numFragDesc; - cfrg_desc firstDesc; -} cfrg_rsrc; - - -static void CopyPascalString(StringPtr to, StringPtr from) -{ - BlockMoveData(from, to, *from+1); - return; -} - -/* Copies a pascal string to a C string in space you provide. - Returns false if it runs out of space. */ -static Boolean CopyPascalToCString(char* target, const StringPtr source, - size_t availspace) -{ - Boolean enough_space = ((size_t)source[0] < availspace); - size_t bytes2copy = (enough_space ? (size_t)source[0] : (availspace-1)); - unsigned char* pos = source + 1; - - while (bytes2copy--) *target++ = *pos++; - *target = '\0'; - return enough_space; -} - -/* Returns in "me" the location of the currently running host application. */ -static OSErr GetHostLocation( FSSpecPtr me ) -{ - ProcessSerialNumber psn; - ProcessInfoRec pinfo; - OSErr err; - - /* get info for current process */ - err = GetCurrentProcess(&psn); - if (UNLIKELY(err != noErr)) return err; - pinfo.processInfoLength = sizeof(ProcessInfoRec); - pinfo.processName = NULL; - pinfo.processAppSpec = me; - err = GetProcessInformation(&psn, &pinfo); - if (UNLIKELY(err != noErr)) return err; - return noErr; -} - -#define kCsoundExtFolder "\pCsound" - -/* Looks for a folder or alias to one named "Csound" in the extensions folder */ -static OSErr FindCsoundExtensionsFolder(FSSpecPtr location) -{ - OSErr err; - int16 systemVRefNum; - long extDirID; - long csoundDirID; - - /* find the system extensions folder */ - err = FindFolder(kOnSystemDisk, kExtensionFolderType, kCreateFolder, - &systemVRefNum, &extDirID); - if (UNLIKELY(err != noErr)) return err; - - /* look for subfolder named "Csound" */ - err = FSMakeFSSpec(systemVRefNum, extDirID, kCsoundExtFolder, location); - if (err != noErr) return err; /* does not exist */ - else { - Boolean targetIsFolder; - Boolean wasAliased; - - err = ResolveAliasFile(location, true, &targetIsFolder, &wasAliased); - if (UNLIKELY(err != noErr)) return err; - if (UNLIKELY(!targetIsFolder)) - return paramErr; /* "Csound" is a file, not a folder */ - } - - return noErr; -} - -/* Gets the folder ID for a directory specified via a full FSSpec. */ -static OSErr GetFolderID(const FSSpecPtr loc, long* dirID) -{ - OSErr err; - CInfoPBRec catinfo; - Str255 name; - - CopyPascalString(name, loc->name); - catinfo.dirInfo.ioCompletion = NULL; - catinfo.dirInfo.ioNamePtr = name; - catinfo.dirInfo.ioVRefNum = loc->vRefNum; - catinfo.dirInfo.ioFDirIndex = 0; /* we want info about the named folder */ - catinfo.dirInfo.ioDrDirID = loc->parID; - - err = PBGetCatInfo(&catinfo, false); - *dirID = catinfo.dirInfo.ioDrDirID; - return err; -} - -/* Gets the name for a library that the Code Fragment Manager needs to load it */ -static OSErr GetFragmentName(CSOUND* csound, FSSpecPtr libr, char* name) -{ - OSErr err; - Handle cfrgh; - cfrg_rsrc* cfrg; - int16 refnum; - - const char kIsLib = 0; /* fragType for import libraries */ - - /* open the plugin's resource fork */ - refnum = FSpOpenResFile(libr, fsRdPerm); - err = ResError(); - if (UNLIKELY(err != noErr)) return err; - - /* load the plugin's 'cfrg' resource */ - cfrgh = GetResource('cfrg', 0); - err = ResError(); - if (UNLIKELY(err != noErr)) { - CloseResFile(refnum); - return err; - } - cfrg = (cfrg_rsrc*)*cfrgh; - if (UNLIKELY(cfrg->version != 0x00000001 || cfrg->numFragDesc < 1)) { - ReleaseResource(cfrgh); - CloseResFile(refnum); - return -1; - } - /* we assume the library we want is the first fragment descriptor */ - if (LIKELY(cfrg->firstDesc.fragType == kIsLib)) { - CopyPascalToCString(name, cfrg->firstDesc.fragName, 255); - err = noErr; - } - else err = -1; - - ReleaseResource(cfrgh); - CloseResFile(refnum); - return err; -} - -/* Examine each file in theFolder and load it if it is a Csound plugin */ -static OSErr SearchFolderAndLoadPlugins(CSOUND *csound, FSSpecPtr theFolder, int* cserr) -{ - OSErr err, err2; - int result; - Str63 name; - char fragname[255]; - CInfoPBRec catinfo; - FSSpec spec; - long folderID; - int16 idx = 1; - - const char kFolderBit = (1<<4); - - err = GetFolderID(theFolder, &folderID); - if (UNLIKELY(err != noErr)) return err; - - *cserr = CSOUND_SUCCESS; - catinfo.hFileInfo.ioCompletion = NULL; - catinfo.hFileInfo.ioVRefNum = theFolder->vRefNum; - catinfo.hFileInfo.ioNamePtr = name; - do { - catinfo.hFileInfo.ioFDirIndex = idx; - catinfo.hFileInfo.ioDirID = folderID; - catinfo.hFileInfo.ioACUser = 0; - err = PBGetCatInfo(&catinfo, false); - /* ignore folders */ - if (err == noErr && !(catinfo.hFileInfo.ioFlAttrib & kFolderBit)) { - if (catinfo.hFileInfo.ioFlFndrInfo.fdType == 'shlb' && - catinfo.hFileInfo.ioFlFndrInfo.fdCreator == 'Csnd') { - /* this is a Csound plugin library */ - err2 = FSMakeFSSpec(catinfo.hFileInfo.ioVRefNum, - catinfo.hFileInfo.ioFlParID, catinfo.hFileInfo.ioNamePtr, &spec); - if (err2 != noErr) continue; /* this really should not happen */ - err2 = GetFragmentName(csound, &spec, fragname); - result = CSOUND_SUCCESS; - if (err2 == noErr) result = csoundLoadExternal(csound, fragname); - /* record serious errors */ - if (result != CSOUND_SUCCESS && result != CSOUND_ERROR) *cserr = result; - /* continue to search folder when one file fails to load */ - } - } - ++idx; - } while (err == noErr); - return noErr; -} - -int csoundLoadModules(CSOUND *csound) -{ - OSErr err; - int cserr; - Handle cfrgh; - AliasHandle alias; - cfrg_rsrc* cfrg; - int16 alisID; - Boolean wasChanged; - FSSpec pluginDir, fromFile; - - /* find the "Plugins" folder */ - /* first load the host application's 'cfrg' resource */ - cfrgh = GetResource('cfrg', 0); - err = ResError(); - if (UNLIKELY(err != noErr || cfrgh == NULL)) { - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - cfrg = (cfrg_rsrc*)*cfrgh; - if (UNLIKELY(cfrg->version != 0x00000001 || cfrg->numFragDesc < 1)) { - ReleaseResource(cfrgh); - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - alisID = cfrg->firstDesc.libraryDir; - ReleaseResource(cfrgh); - cfrgh = NULL; cfrg = NULL; - - /* now load the 'alis' resource that points to "Plugins" */ - alias = (AliasHandle)GetResource('alis', alisID); - err = ResError(); - if (UNLIKELY(err != noErr || alias == NULL)) { - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - /* resolve alias relative to host application */ - err = GetHostLocation(&fromFile); - if (UNLIKELY(err != noErr)) { - ReleaseResource((Handle)alias); - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - err = ResolveAlias(&fromFile, alias, &pluginDir, &wasChanged); - ReleaseResource((Handle)alias); - if (UNLIKELY(err != noErr)) { - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - - cserr = CSOUND_SUCCESS; - /* search the "Plugins" folder for Csound plugin libraries */ - err = SearchFolderAndLoadPlugins(csound, &pluginDir, &cserr); - if (UNLIKELY(err != noErr)) { - csound->ErrorMsg(csound, Str("Error opening plugin directory\n")); - return CSOUND_ERROR; - } - if (UNLIKELY(cserr != CSOUND_SUCCESS)) return cserr; - - /* finally, locate and search our Extensions subfolder for plugins */ - err = FindCsoundExtensionsFolder(&pluginDir); - if (err == noErr) - SearchFolderAndLoadPlugins(csound, &pluginDir, &cserr); - /* ignore errors from search & we don't care if unable to locate */ - - return cserr; -} -#endif /* mac_classic library searching */ -#ifndef mac_classic /** * Load plugin libraries for Csound instance 'csound', and call * pre-initialisation functions. @@ -667,7 +392,7 @@ */ int csoundLoadModules(CSOUND *csound) { -#ifdef HAVE_DIRENT_H +#if (defined(HAVE_DIRENT_H) && (TARGET_OS_IPHONE == 0)) DIR *dir; struct dirent *f; const char *dname, *fname; @@ -688,13 +413,22 @@ if (dname == NULL) # endif #endif +#ifdef CS_DEFAULT_PLUGINDIR dname = CS_DEFAULT_PLUGINDIR; +#else + dname = ""; +#endif + } dir = opendir(dname); if (UNLIKELY(dir == (DIR*) NULL)) { - csound->ErrorMsg(csound, Str("Error opening plugin directory '%s': %s"), + if(dname != NULL) + csound->Warning(csound, Str("Error opening plugin directory '%s': %s"), dname, strerror(errno)); - return CSOUND_ERROR; + else + csound->Warning(csound, Str("Error opening plugin directory: %s"), + strerror(errno)); + return CSOUND_SUCCESS; } /* load database for deferred plugin loading */ /* n = csoundLoadOpcodeDB(csound, dname); */ @@ -733,13 +467,13 @@ } /* printf("DEBUG %s(%d): possibly deny %s\n", __FILE__, __LINE__,fname); */ if (csoundCheckOpcodeDeny(fname)) { - csound->Warning(csound, Str("Library %s omitted\n"), fname); + csoundWarning(csound, Str("Library %s omitted\n"), fname); continue; } - if (csoundCheckOpcodePluginFile(csound, fname) != 0) - continue; /* skip file if marked for deferred loading */ sprintf(buf, "%s%c%s", dname, DIRSEP, fname); -/* printf("Loading: %s\n", buf); */ + if (csound->oparms->odebug) { + csoundMessage(csound, Str("Loading '%s'\n"), buf); + } n = csoundLoadExternal(csound, buf); if (UNLIKELY(n == CSOUND_ERROR)) continue; /* ignore non-plugin files */ @@ -752,7 +486,6 @@ return CSOUND_SUCCESS; #endif /* HAVE_DIRENT_H */ } -#endif /* not mac_classic */ static int cmp_func(const void *p1, const void *p2) { @@ -769,7 +502,7 @@ return 0; /* IV - Feb 19 2005 */ csound->dl_opcodes_oplibs = NULL; - csound->Message(csound, Str("Loading command-line libraries:\n")); + csoundMessage(csound, Str("Loading command-line libraries:\n")); cnt = 1; i = 0; do { @@ -792,9 +525,9 @@ if (fname[0] != '\0' && !(i && strcmp(fname, lst[i - 1]) == 0)) { err = csoundLoadExternal(csound, fname); if (UNLIKELY(err == CSOUND_INITIALIZATION || err == CSOUND_MEMORY)) - csound->Die(csound, Str(" *** error loading '%s'"), fname); + csoundDie(csound, Str(" *** error loading '%s'"), fname); else if (!err) - csound->Message(csound, " %s\n", fname); + csoundMessage(csound, " %s\n", fname); } } while (++i < cnt); /* file list is no longer needed */ @@ -837,7 +570,7 @@ else { length /= (long) sizeof(OENTRY); if (length) { - if (UNLIKELY(csound->AppendOpcodes(csound, opcodlst_n, + if (UNLIKELY(csoundAppendOpcodes(csound, opcodlst_n, (int) length) != 0)) return CSOUND_ERROR; } @@ -951,7 +684,7 @@ return (void*) GetProcAddress((HMODULE) library, procedureName); } -#elif defined(LINUX) || defined (NEW_MACH_CODE) +#elif !(defined(NACL)) && (defined(LINUX) || defined (NEW_MACH_CODE)) PUBLIC int csoundOpenLibrary(void **library, const char *libraryPath) { @@ -976,257 +709,6 @@ return (void*) dlsym(library, procedureName); } -#elif defined (OLD_MACH_CODE) - -/* Set and get the error string for use by dlerror */ -static const char *error(int setget, const char *str, ...) -{ - static char errstr[ERR_STR_LEN]; - static int err_filled = 0; - const char *retval; - NSLinkEditErrors ler; - int lerno; - const char *dylderrstr; - const char *file; - va_list arg; - if (setget <= 0) { - va_start(arg, str); - strncpy(errstr, "dlsimple: ", ERR_STR_LEN); - vsnprintf(errstr + 10, ERR_STR_LEN - 10, str, arg); - va_end(arg); - /* We prefer to use the dyld error string if getset is 1*/ - if (setget == 0) { - NSLinkEditError(&ler, &lerno, &file, &dylderrstr); -#if 0 - fprintf(stderr, "dyld: %s\n", dylderrstr); -#endif - if (dylderrstr && strlen(dylderrstr)) - strncpy(errstr, dylderrstr, ERR_STR_LEN); - } - err_filled = 1; - retval = NULL; - } - else { - if (!err_filled) - retval = NULL; - else - retval = errstr; - err_filled = 0; - } - return retval; -} - -/* dlsymIntern is used by dlsym to find the symbol */ -static void *dlsymIntern(void *handle, const char *symbol) -{ - NSSymbol nssym = (NSSymbol) 0; - /* If the handle is -1, if is the app global context */ - if (handle == (void*) -1L) { - /* Global context, use NSLookupAndBindSymbol */ - if (NSIsSymbolNameDefined(symbol)) { - nssym = NSLookupAndBindSymbol(symbol); - } - } - /* Now see if the handle is a struct mach_header* or not, - use NSLookupSymbol in image for libraries, and - NSLookupSymbolInModule for bundles */ - else { - /* Check for both possible magic numbers depending - on x86/ppc byte order */ - if ((((struct mach_header *)handle)->magic == MH_MAGIC) || - (((struct mach_header *)handle)->magic == MH_CIGAM)) { - if (NSIsSymbolNameDefinedInImage((struct mach_header *)handle, - symbol)) { - nssym = NSLookupSymbolInImage( - (struct mach_header *)handle, symbol, - NSLOOKUPSYMBOLINIMAGE_OPTION_BIND | - NSLOOKUPSYMBOLINIMAGE_OPTION_RETURN_ON_ERROR); - } - } - else { - nssym = NSLookupSymbolInModule(handle, symbol); - } - } - if (UNLIKELY(!nssym)) { - error(0, "Symbol \"%s\" Not found", symbol); - return NULL; - } - return NSAddressOfSymbol(nssym); -} - -int csoundOpenLibrary(void **library, const char *libraryPath) -{ - NSObjectFileImage ofi = 0; - NSObjectFileImageReturnCode ofirc; - static int (*make_private_module_public) (NSModule module) = NULL; - unsigned int flags = NSLINKMODULE_OPTION_RETURN_ON_ERROR | - NSLINKMODULE_OPTION_PRIVATE; - - /* If we got no path, the app wants the global namespace, - use -1 as the marker in this case */ - if (!libraryPath) { - *library = (void*) -1L; - return 0; - } - *library = NULL; - - /* Create the object file image, works for things linked - with the -bundle arg to ld */ - ofirc = NSCreateObjectFileImageFromFile(libraryPath, &ofi); - switch (ofirc) { - case NSObjectFileImageSuccess: - /* It was okay, so use NSLinkModule to link in the image */ - *library = NSLinkModule(ofi, libraryPath, flags); - /* Don't forget to destroy the object file - image, unless you like leaks */ - NSDestroyObjectFileImage(ofi); - /* If the mode was global, then change the module, this avoids - multiply defined symbol errors to first load private then - make global. Silly, isn't it. */ - if (!make_private_module_public) { - _dyld_func_lookup("__dyld_NSMakePrivateModulePublic", - (void **) &make_private_module_public); - } - make_private_module_public(*library); - break; - case NSObjectFileImageInappropriateFile: - /* It may have been a dynamic library rather - than a bundle, try to load it */ - *library = (void*) NSAddImage(libraryPath, - NSADDIMAGE_OPTION_RETURN_ON_ERROR); - break; - case NSObjectFileImageFailure: - error(0, "Object file setup failure : \"%s\"", libraryPath); - return -1; - case NSObjectFileImageArch: - error(0, "No object for this architecture : \"%s\"", libraryPath); - return -1; - case NSObjectFileImageFormat: - error(0, "Bad object file format : \"%s\"", libraryPath); - return -1; - case NSObjectFileImageAccess: - error(0, "Can't read object file : \"%s\"", libraryPath); - return -1; - } - if (UNLIKELY(*library == NULL)) { - error(0, "Can not open \"%s\"", libraryPath); - return -1; - } - return 0; -} - -int csoundCloseLibrary(void *library) -{ - if (UNLIKELY((((struct mach_header *)library)->magic == MH_MAGIC) || - (((struct mach_header *)library)->magic == MH_CIGAM))) { - error(-1, "Can't remove dynamic libraries on darwin"); - return -1; - } - if (UNLIKELY(!NSUnLinkModule(library, 0))) { - error(0, "unable to unlink module %s", NSNameOfModule(library)); - return -1; - } - return 0; -} - -void *csoundGetLibrarySymbol(void *library, const char *procedureName) -{ - char undersym[257]; - - if (UNLIKELY((int) strlen(procedureName) > 255)) { - error(-1, "Symbol name is too long"); - return NULL; - } - sprintf(undersym, "_%s", procedureName); - return (void*) dlsymIntern(library, undersym); -} - -#elif defined(mac_classic) - -PUBLIC int csoundOpenLibrary(void **library, const char *libraryName) -{ - CFragConnectionID connID; - Ptr mainAddr; - OSErr err; - Str63 macLibName; - Str255 errName; - - *library = NULL; - if (LIKELY(strlen(libraryName) < 64)) { - strcpy((char*) macLibName, libraryName); - c2pstr((char*) macLibName); - } - else { - /* csoundMessage("%s is not a valid library name because it is too long.\n", - libraryName); */ - return -1; - } - /* first, test to see if the library is already loaded */ - err = GetSharedLibrary(macLibName, kPowerPCCFragArch, kFindCFrag, - &connID, &mainAddr, errName); - if (UNLIKELY(err == noErr)) - return -1; /* already loaded */ - else if (UNLIKELY(err != cfragLibConnErr)) { /* some other error occurred */ - /* csoundMessage("Failed to load plugin library %s with Mac error %d.\n", - libraryName, err); */ - return -1; - } - else { /* attempt to load the library */ - err = GetSharedLibrary(macLibName, kPowerPCCFragArch, kLoadCFrag, - &connID, &mainAddr, errName); - if (UNLIKELY(err != noErr)) { - /* csoundMessage("Failed to load plugin library %s with Mac error %d.\n", - libraryName, err); */ - return -1; - } - } - *library = (void*) connID; - return 0; -} - -PUBLIC int csoundCloseLibrary(void *library) -{ - CFragConnectionID connID; - OSErr err; - - connID = (CFragConnectionID) library; - err = CloseConnection(&connID); - return 0 /* (err != noErr) */; /* ignore errors */ -} - -PUBLIC void *csoundGetLibrarySymbol(void *library, const char *procedureName) -{ - OSErr err; - Ptr symAddr; - CFragSymbolClass symClass; - CFragConnectionID connID; - Str255 macProcName; - - connID = (CFragConnectionID) library; - if (LIKELY(strlen(procedureName) < 256)) { - strcpy((char*) macProcName, procedureName); - c2pstr((char*) macProcName); - } - else { - /* csoundMessage("%s is not a valid library procedure name " - "because it is too long.\n", procedureName); */ - return NULL; - } - err = FindSymbol(connID, macProcName, &symAddr, &symClass); - if (UNLIKELY(err != noErr)) { - /* csoundMessage("Failed to find library procedure %s with Mac error %d.\n", - procedureName, err); */ - return NULL; - } - else if (UNLIKELY(symClass == kDataCFragSymbol)) { - /* csoundMessage("Failed to load procedure %s " - "because it is not a code symbol.\n", procedureName); */ - return NULL; - } - - return (void*) symAddr; -} - #else /* case for platforms without shared libraries -- added 062404, akozar */ int csoundOpenLibrary(void **library, const char *libraryPath) @@ -1251,9 +733,9 @@ static const char *opcodedirWarnMsg[] = { "################################################################", #ifndef USE_DOUBLE - "# WARNING: OPCODEDIR IS NOT SET ! #", + "# WARNING: OPCODE6DIR IS NOT SET ! #", #else - "# WARNING: OPCODEDIR64 IS NOT SET ! #", + "# WARNING: OPCODE6DIR64 IS NOT SET ! #", #endif "# Csound requires this environment variable to be set to find #", "# its plugin libraries. If it is not set, you may experience #", @@ -1282,6 +764,7 @@ extern long bilbar_localops_init(CSOUND *, void *); extern long compress_localops_init(CSOUND *, void *); extern long pvsbuffer_localops_init(CSOUND *, void *); +extern long pvsgendy_localops_init(CSOUND *, void *); extern long vosim_localops_init(CSOUND *, void *); extern long eqfil_localops_init(CSOUND *, void *); extern long modal4_localops_init(CSOUND *, void *); @@ -1294,7 +777,7 @@ extern long hrtferX_localops_init(CSOUND *, void *); extern long loscilx_localops_init(CSOUND *, void *); extern long pan2_localops_init(CSOUND *, void *); -extern long tabvars_localops_init(CSOUND *, void *); +extern long arrayvars_localops_init(CSOUND *, void *); extern long phisem_localops_init(CSOUND *, void *); extern long pvoc_localops_init(CSOUND *, void *); extern long hrtfopcodes_localops_init(CSOUND *, void *); @@ -1316,9 +799,14 @@ extern long pvlock_localops_init(CSOUND *, void *); extern long fareyseq_localops_init(CSOUND *, void *); extern long cpumeter_localops_init(CSOUND *, void *); -extern long mp3in_localops_init(CSOUND *, void *); extern long gendy_localops_init(CSOUND *, void *); extern long scnoise_localops_init(CSOUND *, void *); +#ifndef NACL +extern long socksend_localops_init(CSOUND *, void *); +extern long mp3in_localops_init(CSOUND *, void *); +extern long sockrecv_localops_init(CSOUND *, void *); +#endif +extern long afilts_localops_init(CSOUND *, void *); extern int stdopc_ModuleInit(CSOUND *csound); extern int pvsopc_ModuleInit(CSOUND *csound); @@ -1335,7 +823,7 @@ modmatrix_localops_init, spectra_localops_init, ambicode1_localops_init, grain4_localops_init, hrtferX_localops_init, loscilx_localops_init, - pan2_localops_init, tabvars_localops_init, + pan2_localops_init, arrayvars_localops_init, phisem_localops_init, pvoc_localops_init, stackops_localops_init, vbap_localops_init, ugakbari_localops_init, harmon_localops_init, @@ -1344,12 +832,18 @@ crossfm_localops_init, pvlock_localops_init, fareyseq_localops_init, hrtfearly_localops_init, hrtfreverb_localops_init, minmax_localops_init, - vaops_localops_init, + vaops_localops_init, pvsgendy_localops_init, #ifndef WIN32 cpumeter_localops_init, #endif - mp3in_localops_init, gendy_localops_init, - scnoise_localops_init, NULL }; +#ifndef NACL + mp3in_localops_init, + sockrecv_localops_init, + socksend_localops_init, +#endif + gendy_localops_init, + scnoise_localops_init, afilts_localops_init, + NULL }; typedef NGFENS* (*FGINITFN)(CSOUND *); @@ -1369,7 +863,7 @@ if (UNLIKELY(length <= 0L)) return CSOUND_ERROR; length /= (long) sizeof(OENTRY); if (length) { - if (UNLIKELY(csound->AppendOpcodes(csound, opcodlst_n, + if (UNLIKELY(csoundAppendOpcodes(csound, opcodlst_n, (int) length) != 0)) return CSOUND_ERROR; } diff -Nru csound-5.17.11~dfsg/Top/csound.c csound-6.02~dfsg/Top/csound.c --- csound-5.17.11~dfsg/Top/csound.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/csound.c 2014-01-07 16:54:20.000000000 +0000 @@ -5,7 +5,8 @@ * by means of software alone. * * Copyright (C) 2001-2006 Michael Gogins, Matt Ingalls, John D. Ramsdell, - * John P. ffitch, Istvan Varga + * John P. ffitch, Istvan Varga, Victor Lazzarini, + * Steven Yi * * L I C E N S E * @@ -23,26 +24,21 @@ * License along with this software; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * 29 May 2002 - ma++ merge with CsoundLib. - * 30 May 2002 - mkg add csound "this" pointer argument back into merge. - * 27 Jun 2002 - mkg complete Linux dl code and Makefile */ -#ifdef __cplusplus -extern "C" { -#endif +//#ifdef __cplusplus +//extern "C" { +//#endif #if defined(HAVE_UNISTD_H) || defined (__unix) || defined(__unix__) #include #endif #include "csoundCore.h" #include "csmodule.h" +#include "corfile.h" #include "csGblMtx.h" #include #include -#ifndef mac_classic -#include -#endif #include #include #include @@ -59,177 +55,215 @@ #include "namedins.h" #include "pvfileio.h" #include "fftlib.h" -#ifdef ENABLE_NEW_PARSER -#include "csound_orc.h" -#endif -#ifdef PARCS #include "cs_par_base.h" #include "cs_par_orc_semantics.h" #include "cs_par_dispatch.h" +#include "csound_orc_semantics.h" - /* **** MAJOR PROBLEM: PTHREAD_SPINLOCK_INITIALIZER is not defined in Linux */ - -#ifdef linux - #define PTHREAD_SPINLOCK_INITIALIZER 0 +#if defined(linux) || defined(__HAIKU__) +#define PTHREAD_SPINLOCK_INITIALIZER 0 #endif -#endif /* PARCS */ #if defined(USE_OPENMP) #include #endif /* USE_OPENMP */ - MYFLT csoundPow2(CSOUND *csound, MYFLT a); - extern void MakeAscii(CSOUND *, WINDAT *, const char *); - extern void DrawAscii(CSOUND *, WINDAT *); - extern void KillAscii(CSOUND *, WINDAT *); - extern int csoundInitStaticModules(CSOUND *); - - static void SetInternalYieldCallback(CSOUND *, int (*yieldCallback)(CSOUND *)); - static int playopen_dummy(CSOUND *, const csRtAudioParams *parm); - static void rtplay_dummy(CSOUND *, const MYFLT *outBuf, int nbytes); - static int recopen_dummy(CSOUND *, const csRtAudioParams *parm); - static int rtrecord_dummy(CSOUND *, MYFLT *inBuf, int nbytes); - static void rtclose_dummy(CSOUND *); - static void csoundDefaultMessageCallback(CSOUND *, int, const char *, va_list); - static void defaultCsoundMakeXYin(CSOUND *, XYINDAT *, MYFLT, MYFLT); - static void defaultCsoundReadKillXYin(CSOUND *, XYINDAT *); - static int defaultCsoundExitGraph(CSOUND *); - static int defaultCsoundYield(CSOUND *); - static int csoundDoCallback_(CSOUND *, void *, unsigned int); - - extern void close_all_files(CSOUND *); - - static const CSOUND cenviron_ = { - /* ----------------- interface functions (322 total) ----------------- */ - csoundGetVersion, - csoundGetAPIVersion, - csoundGetHostData, - csoundSetHostData, - csoundCreate, - csoundCompile, - csoundPerform, - csoundPerformKsmps, - csoundPerformBuffer, - csoundCleanup, - csoundReset, - csoundDestroy, +#include "csound_standard_types.h" + +static void SetInternalYieldCallback(CSOUND *, int (*yieldCallback)(CSOUND *)); +int playopen_dummy(CSOUND *, const csRtAudioParams *parm); +void rtplay_dummy(CSOUND *, const MYFLT *outBuf, int nbytes); +int recopen_dummy(CSOUND *, const csRtAudioParams *parm); +int rtrecord_dummy(CSOUND *, MYFLT *inBuf, int nbytes); +void rtclose_dummy(CSOUND *); +int audio_dev_list_dummy(CSOUND *, CS_AUDIODEVICE *, int); +int midi_dev_list_dummy(CSOUND *, CS_MIDIDEVICE *, int); +static void csoundDefaultMessageCallback(CSOUND *, int, const char *, va_list); +static int defaultCsoundYield(CSOUND *); +static int csoundDoCallback_(CSOUND *, void *, unsigned int); +static void reset(CSOUND *); +static int csoundPerformKsmpsInternal(CSOUND *csound); +static void csoundTableSetInternal(CSOUND *csound, int table, int index, + MYFLT value); +static INSTRTXT **csoundGetInstrumentList(CSOUND *csound); +static long csoundGetKcounter(CSOUND *csound); +static void set_util_sr(CSOUND *csound, MYFLT sr); +static void set_util_nchnls(CSOUND *csound, int nchnls); + +extern void cscoreRESET(CSOUND *); +extern void memRESET(CSOUND *); +extern MYFLT csoundPow2(CSOUND *csound, MYFLT a); +extern int csoundInitStaticModules(CSOUND *); +extern void close_all_files(CSOUND *); +extern void csoundInputMessageInternal(CSOUND *csound, const char *message); + +void (*msgcallback_)(CSOUND *, int, const char *, va_list) = NULL; + +extern OENTRY opcodlst_1[]; + +static void free_opcode_table(CSOUND* csound) { + int i; + CS_HASH_TABLE_ITEM* bucket; + CONS_CELL* head; + + for (i = 0; i < HASH_SIZE; i++) { + bucket = csound->opcodes->buckets[i]; + + while(bucket != NULL) { + head = bucket->value; + cs_cons_free(csound, head); + bucket = bucket->next; + } + } + + cs_hash_table_free(csound, csound->opcodes); +} +static void create_opcode_table(CSOUND *csound) +{ + + int err; + + if (csound->opcodes != NULL) { + free_opcode_table(csound); + } + csound->opcodes = cs_hash_table_create(csound); + + /* Basic Entry1 stuff */ + err = csoundAppendOpcodes(csound, &(opcodlst_1[0]), -1); + + if (err) + csoundDie(csound, Str("Error allocating opcode list")); +} + +#define MAX_MODULES 64 + +static void module_list_add(CSOUND *csound, char *drv, char *type){ + MODULE_INFO **modules = + (MODULE_INFO **) csoundQueryGlobalVariable(csound, "_MODULES"); + if(modules != NULL){ + int i = 0; + while(modules[i] != NULL && i < MAX_MODULES){ + if(!strcmp(modules[i]->module, drv)) return; + i++; + } + modules[i] = (MODULE_INFO *) csound->Malloc(csound, sizeof(MODULE_INFO)); + strncpy(modules[i]->module, drv, 11); + strncpy(modules[i]->type, type, 11); + } +} + +static int csoundGetRandSeed(CSOUND *csound, int which){ + if(which > 1) return csound->randSeed1; + else return csound->randSeed2; +} + +static char *csoundGetStrsets(CSOUND *csound, long p){ + if(csound->strsets == NULL) return NULL; + else return csound->strsets[p]; +} + +static int csoundGetStrsmax(CSOUND *csound){ + return csound->strsmax; +} + +static void csoundGetOParms(CSOUND *csound, OPARMS *p){ + memcpy(p, csound->oparms, sizeof(OPARMS)); +} + +static int csoundGetDitherMode(CSOUND *csound){ + return csound->dither_output; +} + +static int csoundGetZakBounds(CSOUND *csound, MYFLT **zkstart){ + *zkstart = csound->zkstart; + return csound->zklast; +} + +static int csoundGetReinitFlag(CSOUND *csound){ + return csound->reinitflag; +} + +static int csoundGetTieFlag(CSOUND *csound){ + return csound->tieflag; +} + +static const CSOUND cenviron_ = { + /* attributes */ csoundGetSr, csoundGetKr, csoundGetKsmps, csoundGetNchnls, - csoundGetSampleFormat, - csoundGetSampleSize, + csoundGetNchnlsInput, + csoundGet0dBFS, + csoundGetKcounter, + csoundGetCurrentTimeSamples, csoundGetInputBufferSize, csoundGetOutputBufferSize, csoundGetInputBuffer, csoundGetOutputBuffer, - csoundGetSpin, - csoundGetSpout, - csoundGetScoreTime, - csoundSetMakeXYinCallback, - csoundSetReadXYinCallback, - csoundSetKillXYinCallback, - csoundIsScorePending, - csoundSetScorePending, - csoundGetScoreOffsetSeconds, - csoundSetScoreOffsetSeconds, - csoundRewindScore, + csoundSetDebug, + csoundGetDebug, + csoundGetSizeOfMYFLT, + csoundGetOParms, + csoundGetEnv, + /* message printout */ csoundMessage, csoundMessageS, csoundMessageV, - csoundDeleteUtilityList, - csoundDeleteChannelList, - csoundSetMessageCallback, - csoundDeleteCfgVarList, csoundGetMessageLevel, csoundSetMessageLevel, - csoundInputMessage, - csoundKeyPress, - csoundSetInputValueCallback, - csoundSetOutputValueCallback, - csoundScoreEvent, - csoundScoreEventAbsolute, - csoundSetExternalMidiInOpenCallback, - csoundSetExternalMidiReadCallback, - csoundSetExternalMidiInCloseCallback, - csoundSetExternalMidiOutOpenCallback, - csoundSetExternalMidiWriteCallback, - csoundSetExternalMidiOutCloseCallback, - csoundSetExternalMidiErrorStringCallback, - csoundSetIsGraphable, - csoundSetMakeGraphCallback, - csoundSetDrawGraphCallback, - csoundSetKillGraphCallback, - csoundSetExitGraphCallback, - csoundNewOpcodeList, - csoundDisposeOpcodeList, - csoundAppendOpcode, - csoundAppendOpcodes, - csoundOpenLibrary, - csoundCloseLibrary, - csoundGetLibrarySymbol, - csoundYield, - csoundSetYieldCallback, - csoundGetEnv, - csoundFindInputFile, - csoundFindOutputFile, - csoundSetPlayopenCallback, - csoundSetRtplayCallback, - csoundSetRecopenCallback, - csoundSetRtrecordCallback, - csoundSetRtcloseCallback, + csoundSetMessageCallback, + /* Event and MIDI functionality for opcodes */ + csoundSetReleaseLength, + csoundSetReleaseLengthSeconds, + csoundGetMidiChannelNumber, + csoundGetMidiChannel, + csoundGetMidiNoteNumber, + csoundGetMidiVelocity, + csoundGetReleaseFlag, + csoundGetOffTime, + csoundGetPFields, + csoundGetInstrumentNumber, + csoundGetZakBounds, + csoundGetTieFlag, + csoundGetReinitFlag, + csoundGetStrsmax, + csoundGetStrsets, + csoundPow2, + intpow, + type2string, + /* arguments to opcodes */ + csoundGetInputArgCnt, + csoundGetInputArgAMask, + csoundGetInputArgSMask, + csoundGetInputArgName, + csoundGetOutputArgCnt, + csoundGetOutputArgAMask, + csoundGetOutputArgSMask, + csoundGetOutputArgName, + get_arg_string, + strarg2insno, + strarg2name, + /* memory allocation */ csoundAuxAlloc, mmalloc, mcalloc, mrealloc, + cs_strdup, mfree, - dispset, - display, - dispexit, - intpow, - ldmemfile, - strarg2insno, - strarg2name, + /* function tables */ hfgens, - insert_score_event, csoundFTAlloc, csoundFTDelete, csoundFTFind, csoundFTFindP, csoundFTnp2Find, csoundGetTable, - csoundLoadSoundFile, - getstrformat, - sfsampsize, - type2string, - SAsndgetset, - sndgetset, - getsndin, - rewriteheader, - csoundRand31, - fdrecord, - fdclose, - csoundSetDebug, - csoundGetDebug, csoundTableLength, csoundTableGet, - csoundTableSet, - csoundCreateThread, - csoundJoinThread, - csoundCreateThreadLock, - csoundDestroyThreadLock, - csoundWaitThreadLock, - csoundNotifyThreadLock, - csoundWaitThreadLockNoTimeout, - csoundSleep, - csoundInitTimerStruct, - csoundGetRealTime, - csoundGetCPUTime, - csoundGetRandomSeedFromTime, - csoundSeedRandMT, - csoundRandMT, - csoundPerformKsmpsAbsolute, - csoundLocalizeString, + csoundTableSetInternal, + csoundGetNamedGens, + /* global and config variable manipulation */ csoundCreateGlobalVariable, csoundQueryGlobalVariable, csoundQueryGlobalVariableNoCheck, @@ -241,9 +275,7 @@ csoundListConfigurationVariables, csoundDeleteConfigurationVariable, csoundCfgErrorCodeToString, - csoundGetSizeOfMYFLT, - csoundGetRtRecordUserData, - csoundGetRtPlayUserData, + /* FFT support */ csoundGetInverseComplexFFTScale, csoundGetInverseRealFFTScale, csoundComplexFFT, @@ -253,20 +285,9 @@ csoundRealFFTMult, csoundRealFFTnp2, csoundInverseRealFFTnp2, - csoundAddUtility, - csoundRunUtility, - csoundListUtilities, - csoundSetUtilityDescription, - csoundGetUtilityDescription, - csoundRegisterSenseEventCallback, - csoundRegisterDeinitCallback, - csoundRegisterResetCallback, - csoundCreateFileHandle, - csoundFileOpen, - csoundGetFileName, - csoundFileClose, + /* PVOC-EX system */ pvoc_createfile, - (int (*)(CSOUND *, const char *, void *, void *)) pvoc_openfile, + pvoc_openfile, pvoc_closefile, pvoc_putframes, pvoc_getframes, @@ -274,25 +295,7 @@ pvoc_fseek, pvoc_errorstr, PVOCEX_LoadFile, - csoundGetOpcodeName, - csoundGetInputArgCnt, - csoundGetInputArgAMask, - csoundGetInputArgSMask, - csoundGetInputArgName, - csoundGetOutputArgCnt, - csoundGetOutputArgAMask, - csoundGetOutputArgSMask, - csoundGetOutputArgName, - csoundSetReleaseLength, - csoundSetReleaseLengthSeconds, - csoundGetMidiChannelNumber, - csoundGetMidiChannel, - csoundGetMidiNoteNumber, - csoundGetMidiVelocity, - csoundGetReleaseFlag, - csoundGetOffTime, - csoundGetPFields, - csoundGetInstrumentNumber, + /* error messages */ csoundDie, csoundInitError, csoundPerfError, @@ -301,154 +304,148 @@ csoundLongJmp, csoundErrorMsg, csoundErrMsgV, - csoundGetChannelPtr, - csoundListChannels, - csoundSetControlChannelParams, - csoundGetControlChannelParams, - csoundChanIKSet, - csoundChanOKGet, - csoundChanIASet, - csoundChanOAGet, - dispinit, + /* random numbers */ + csoundGetRandomSeedFromTime, + csoundSeedRandMT, + csoundRandMT, + csoundRand31, + csoundGetRandSeed, + /* threads and locks */ + csoundCreateThread, + csoundJoinThread, + csoundCreateThreadLock, + csoundDestroyThreadLock, + csoundWaitThreadLock, + csoundNotifyThreadLock, + csoundWaitThreadLockNoTimeout, csoundCreateMutex, csoundLockMutexNoWait, csoundLockMutex, csoundUnlockMutex, csoundDestroyMutex, - csoundRunCommand, - csoundGetCurrentThreadId, - csoundSetChannelIOCallback, - csoundSetCallback, - csoundRemoveCallback, - csoundPvsinSet, - csoundPvsoutGet, - SetInternalYieldCallback, csoundCreateBarrier, csoundDestroyBarrier, csoundWaitBarrier, + csoundGetCurrentThreadId, + csoundSleep, + csoundInitTimerStruct, + csoundGetRealTime, + csoundGetCPUTime, + /* circular buffer */ + csoundCreateCircularBuffer, + csoundReadCircularBuffer, + csoundWriteCircularBuffer, + csoundFlushCircularBuffer, + csoundDestroyCircularBuffer, + /* File access */ + csoundFindInputFile, + csoundFindOutputFile, + SAsndgetset, + sndgetset, + getsndin, + rewriteheader, + csoundLoadSoundFile, + fdrecord, + fdclose, + csoundCreateFileHandle, + csoundGetFileName, + csoundFileClose, csoundFileOpenWithType, type2csfiletype, - ldmemfile2, csoundNotifyFileOpened, sftype2csfiletype, - insert_score_event_at_sample, - csoundGetChannelLock, ldmemfile2withCB, - csoundAddSpinSample, - csoundGetSpoutSample, - csoundChanIKSetValue, - csoundChanOKGetValue, - csoundChanIASetSample, - csoundChanOAGetSample, - csoundStop, - csoundGetNamedGens, - csoundPow2, - /* NULL, */ + csoundFileOpenWithType_Async, + csoundReadAsync, + csoundWriteAsync, + csoundFSeekAsync, + getstrformat, + sfsampsize, + /* RT audio IO and callbacks */ + csoundSetPlayopenCallback, + csoundSetRtplayCallback, + csoundSetRecopenCallback, + csoundSetRtrecordCallback, + csoundSetRtcloseCallback, + csoundSetAudioDeviceListCallback, + csoundGetRtRecordUserData, + csoundGetRtPlayUserData, + csoundGetDitherMode, + /* MIDI and callbacks */ + csoundSetExternalMidiInOpenCallback, + csoundSetExternalMidiReadCallback, + csoundSetExternalMidiInCloseCallback, + csoundSetExternalMidiOutOpenCallback, + csoundSetExternalMidiWriteCallback, + csoundSetExternalMidiOutCloseCallback, + csoundSetExternalMidiErrorStringCallback, + csoundSetMIDIDeviceListCallback, + module_list_add, + /* displays & graphs */ + dispset, + display, + dispexit, + dispinit, + csoundSetIsGraphable, + csoundSetMakeGraphCallback, + csoundSetDrawGraphCallback, + csoundSetKillGraphCallback, + csoundSetExitGraphCallback, + /* generic callbacks */ + csoundSetYieldCallback, + csoundRegisterKeyboardCallback, + csoundRemoveKeyboardCallback, + csoundRegisterSenseEventCallback, + csoundRegisterDeinitCallback, + csoundRegisterResetCallback, + SetInternalYieldCallback, + /* opcodes and instruments */ + csoundAppendOpcode, + csoundAppendOpcodes, + csoundGetOpcodeName, + csoundGetInstrumentList, + /* events and performance */ + csoundYield, + insert_score_event, + insert_score_event_at_sample, + csoundPerformKsmpsInternal, + /* utilities */ + csoundAddUtility, + csoundRunUtility, + csoundListUtilities, + csoundSetUtilityDescription, + csoundGetUtilityDescription, + set_util_sr, + set_util_nchnls, + /* miscellaneous */ + csoundRunCommand, + csoundOpenLibrary, + csoundCloseLibrary, + csoundGetLibrarySymbol, + csoundLocalizeString, + cs_strtok_r, + cs_strtod, + cs_sprintf, + cs_sscanf, { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, NULL, NULL, NULL, NULL + NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, }, - 0, /* dither_output */ - NULL, /* flgraphsGlobals */ - NULL, NULL, /* Delayed messages */ - /* ----------------------- public data fields ----------------------- */ - (OPDS*) NULL, /* ids */ - (OPDS*) NULL, /* pds */ - DFLT_KSMPS, /* ksmps */ - DFLT_KSMPS, /* global_ksmps */ - DFLT_NCHNLS, /* nchnls */ - 0, /* spoutactive */ - 0L, /* kcounter */ - 0L, /* global_kcounter */ - 0, /* reinitflag */ - 0, /* tieflag */ - DFLT_SR, /* esr */ - FL(0.0), /* onedsr */ - FL(0.0), /* sicvt */ - FL(-1.0), /* tpidsr */ - FL(-1.0), /* pidsr */ - FL(-1.0), /* mpidsr */ - FL(-1.0), /* mtpdsr */ - FL(0.0), /* onedksmps */ - DFLT_KR, /* ekr */ - DFLT_KR, /* global_ekr */ - FL(0.0), /* onedkr */ - FL(0.0), /* kicvt */ - DFLT_DBFS, /* e0dbfs */ - FL(1.0) / DFLT_DBFS, /* dbfs_to_float ( = 1.0 / e0dbfs) */ - 0.0, /* timeOffs */ - 0.0, /* beatOffs */ - 0l, /* curTime */ - 0l, /* curTime_inc */ - 0.0, /* curBeat */ - 0.0, /* curBeat_inc */ - 0.0, /* beatTime */ -#if defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS) - PTHREAD_SPINLOCK_INITIALIZER, /* spoutlock */ - PTHREAD_SPINLOCK_INITIALIZER, /* spinlock */ -#else - 0, /* spoutlock */ - 0, /* spinlock */ -#endif - NULL, /* widgetGlobals */ - NULL, /* stdOp_Env */ - NULL, /* zkstart */ - NULL, /* zastart */ - 0L, /* zklast */ - 0L, /* zalast */ - NULL, /* spin */ - NULL, /* spout */ - 0, /* nspin */ - 0, /* nspout */ - (OPARMS*) NULL, /* oparms */ - (EVTBLK*) NULL, /* currevent */ - (INSDS*) NULL, /* curip */ - NULL, /* hostdata */ - NULL, /* rtRecord_userdata */ - NULL, /* rtPlay_userdata */ - NULL, NULL, /* orchname, scorename */ - NULL, NULL, /* orchstr, *scorestr */ - 2345678, /* holdrand */ - 256, /* strVarMaxLen */ - MAXINSNO, /* maxinsno */ - 0, /* strsmax */ - (char**) NULL, /* strsets */ - NULL, /* instrtxtp */ - { NULL }, /* m_chnbp */ - NULL, /* csRtClock */ - NULL, /* csRandState */ - 0, /* randSeed1 */ - 0, /* randSeed2 */ -#if defined(HAVE_PTHREAD_SPIN_LOCK) && defined(PARCS) - PTHREAD_SPINLOCK_INITIALIZER, /* memlock */ -#else - 0, /* memlock */ -#endif - sizeof(MYFLT), /* floatsize */ - -1, /* inchns */ - {0, 0, 0, 0, 0, 0, 0}, /* dummyint[7]; */ - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, /* dummyint32[10]; */ /* ------- private data (not to be used by hosts or externals) ------- */ /* callback function pointers */ (SUBR) NULL, /* first_callback_ */ - (void (*)(CSOUND *, const char *, MYFLT *)) NULL, - (void (*)(CSOUND *, const char *, MYFLT)) NULL, + (channelCallback_t) NULL, + (channelCallback_t) NULL, csoundDefaultMessageCallback, (int (*)(CSOUND *)) NULL, - MakeAscii, - DrawAscii, - KillAscii, - defaultCsoundExitGraph, + (void (*)(CSOUND *, WINDAT *, const char *)) NULL, /* was: MakeAscii,*/ + (void (*)(CSOUND *, WINDAT *windat)) NULL, /* was: DrawAscii,*/ + (void (*)(CSOUND *, WINDAT *windat)) NULL, /* was: KillAscii,*/ + (int (*)(CSOUND *)) NULL, /* was: defaultCsoundExitGraph, */ defaultCsoundYield, - defaultCsoundMakeXYin, - defaultCsoundReadKillXYin, - defaultCsoundReadKillXYin, cscore_, /* cscoreCallback_ */ (void(*)(CSOUND*, const char*, int, int, int)) NULL, /* FileOpenCallback_ */ (SUBR) NULL, /* last_callback_ */ @@ -458,21 +455,79 @@ recopen_dummy, rtrecord_dummy, rtclose_dummy, + audio_dev_list_dummy, + midi_dev_list_dummy, + csoundDoCallback_, /* doCsoundCallback */ + defaultCsoundYield, /* csoundInternalYieldCallback_*/ /* end of callbacks */ - 0, 0, /* nchanik, nchania */ - 0, 0, /* nchanok, nchanoa */ - NULL, NULL, /* chanik, chania */ - NULL, NULL, /* chanok, chanoa */ + (void (*)(CSOUND *)) NULL, /* spinrecv */ + (void (*)(CSOUND *)) NULL, /* spoutran */ + (int (*)(CSOUND *, MYFLT *, int)) NULL, /* audrecv */ + (void (*)(CSOUND *, const MYFLT *, int)) NULL, /* audtran */ + NULL, /* hostdata */ + NULL, NULL, /* orchname, scorename */ + NULL, NULL, /* orchstr, *scorestr */ + (OPDS*) NULL, /* ids */ + { (CS_VAR_POOL*)NULL, + (MYFLT_POOL *) NULL, + (CS_HASH_TABLE *) NULL, + -1, + (INSTRTXT**)NULL, + { NULL, + { + 0,0, + NULL, NULL, NULL, NULL, + 0, + NULL, + 0,0,0,0,0,0,0}, + 0,0,0, + 0, + NULL, + 0, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + 0, + 0, + 0, + FL(0.0), + NULL, + NULL, + 0, + 0 + }, + NULL, + MAXINSNO, /* engineState */ + }, + (INSTRTXT *) NULL, /* instr0 */ + (INSTRTXT**)NULL, /* dead_instr_pool */ + 0, /* dead_instr_no */ + (TYPE_POOL*)NULL, + DFLT_KSMPS, /* ksmps */ + DFLT_NCHNLS, /* nchnls */ + -1, /* inchns */ + 0, /* spoutactive */ + 0L, /* kcounter */ + 0L, /* global_kcounter */ + DFLT_SR, /* esr */ + DFLT_KR, /* ekr */ + 0l, /* curTime */ + 0l, /* curTime_inc */ + 0.0, /* timeOffs */ + 0.0, /* beatOffs */ + 0.0, /* curBeat */ + 0.0, /* curBeat_inc */ + 0.0, /* beatTime */ + (EVTBLK*) NULL, /* currevent */ + (INSDS*) NULL, /* curip */ FL(0.0), /* cpu_power_busy */ (char*) NULL, /* xfilename */ - NLABELS, /* nlabels */ - NGOTOS, /* ngotos */ 1, /* peakchunks */ 0, /* keep_tmp */ - (OENTRY*) NULL, /* opcodlst */ - (int*) NULL, /* opcode_list */ - (OENTRY*) NULL, /* opcodlstend */ - -1, /* maxopcno */ + (CS_HASH_TABLE*)NULL, /* Opcode hash table */ 0, /* nrecs */ NULL, /* Linepipe */ 0, /* Linefd */ @@ -485,19 +540,54 @@ { FL(0.0) }, /* omaxamp */ {0}, {0}, {0}, /* maxpos, smaxpos, omaxpos */ NULL, NULL, /* scorein, scoreout */ - NULL, /* pool */ NULL, /* argoffspace */ NULL, /* frstoff */ -#if defined(__WATCOMC__) || defined(MSVC) ||defined(__POWERPC__) || defined(mac_classic) || \ - (defined(_WIN32) && defined(__GNUC__)) + NULL, /* zkstart */ + 0L, /* zklast */ + NULL, /* zastart */ + 0L, /* zalast */ + NULL, /* stdOp_Env */ + 2345678, /* holdrand */ + 0, /* randSeed1 */ + 0, /* randSeed2 */ + NULL, /* csRandState */ + NULL, /* csRtClock */ + // 16384, /* strVarMaxLen */ + 0, /* strsmax */ + (char**) NULL, /* strsets */ + NULL, /* spin */ + NULL, /* spout */ + 0, /* nspin */ + 0, /* nspout */ + NULL, /* auxspin */ + (OPARMS*) NULL, /* oparms */ + { NULL }, /* m_chnbp */ + 0, /* dither_output */ + FL(0.0), /* onedsr */ + FL(0.0), /* sicvt */ + FL(-1.0), /* tpidsr */ + FL(-1.0), /* pidsr */ + FL(-1.0), /* mpidsr */ + FL(-1.0), /* mtpdsr */ + FL(0.0), /* onedksmps */ + FL(0.0), /* onedkr */ + FL(0.0), /* kicvt */ + 0, /* reinitflag */ + 0, /* tieflag */ + DFLT_DBFS, /* e0dbfs */ + FL(1.0) / DFLT_DBFS, /* dbfs_to_float ( = 1.0 / e0dbfs) */ + NULL, /* rtRecord_userdata */ + NULL, /* rtPlay_userdata */ +#if defined(MSVC) ||defined(__POWERPC__) || defined(MACOSX) || \ + (defined(_WIN32) && defined(__GNUC__)) {0}, #else - {{{0}}}, /* exitjmp of type jmp_buf */ + {{{0}}}, /* exitjmp of type jmp_buf */ #endif NULL, /* frstbp */ 0, /* sectcnt */ 0, 0, 0, /* inerrcnt, synterrcnt, perferrcnt */ - {NULL}, /* instxtanchor */ + /* {NULL}, */ /* instxtanchor in engineState */ {NULL}, /* actanchor */ {0L }, /* rngcnt */ 0, 0, /* rngflg, multichan */ @@ -510,27 +600,17 @@ 0, /* evt_poll_cnt */ 0, /* evt_poll_maxcnt */ 0, 0, 0, /* Mforcdecs, Mxtroffs, MTrkend */ - FL(-1.0), FL(-1.0), /* tran_sr,tran_kr */ - FL(-1.0), /* tran_ksmps */ - DFLT_DBFS, /* tran_0dbfs */ - DFLT_NCHNLS, /* tran_nchnls */ - NULL, /* opcodeInfo */ - NULL, /* instrumentNames */ - NULL, /* strsav_str */ - NULL, /* strsav_space */ + NULL, /* opcodeInfo */ NULL, /* flist */ 0, /* maxfnum */ NULL, /* gensub */ GENMAX+1, /* genmax */ - 100, /* ftldno */ NULL, /* namedGlobals */ - 0, /* namedGlobalsCurrLimit */ - 0, /* namedGlobalsMaxLimit */ NULL, /* cfgVariableDB */ - 0.0, 0.0, 0.0, /* prvbt, curbt, nxtbt */ - 0.0, 0.0, /* curp2, nxtim */ + FL(0.0), FL(0.0), FL(0.0), /* prvbt, curbt, nxtbt */ + FL(0.0), FL(0.0), /* curp2, nxtim */ 0, /* cyclesRemaining */ - { NULL, '\0', 0, FL(0.0), FL(0.0), { FL(0.0) }, NULL }, /* evt */ + { 0, NULL, NULL, '\0', 0, FL(0.0), FL(0.0), { FL(0.0) }, {NULL}}, /* evt */ NULL, /* memalloc_db */ (MGLOBAL*) NULL, /* midiGlobals */ NULL, /* envVarDB */ @@ -540,36 +620,98 @@ NULL, /* FFT_table_1 */ NULL, /* FFT_table_2 */ NULL, NULL, NULL, /* tseg, tpsave, tplim */ - /* express.c */ - 0L, /* polmax */ - 0L, /* toklen */ - NULL, /* tokenstring */ - NULL, /* polish */ - NULL, /* token */ - NULL, /* tokend */ - NULL, /* tokens */ - NULL, /* tokenlist */ - TOKMAX, /* toklength */ - 0, 0, 0, 0, 0, /* acount, kcount, icount, Bcount, bcount */ - (char*) NULL, /* stringend */ - NULL, NULL, /* revp, pushp */ - NULL, NULL, /* argp, endlist */ - (char*) NULL, /* assign_outarg */ - 0, 0, 0, /* argcnt_offs, opcode_is_assign, assign_type */ - 0, /* strVarSamples */ + 0, 0, 0, 0, 0, 0, /* acount, kcount, icount, Bcount, bcount, tcount */ (MYFLT*) NULL, /* gbloffbas */ - NULL, /* otranGlobals */ - NULL, /* rdorchGlobals */ - NULL, /* sreadGlobals */ - NULL, /* extractGlobals */ - NULL, /* oneFileGlobals */ - NULL, /* lineventGlobals */ - NULL, /* musmonGlobals */ - NULL, /* libsndGlobals */ - (void (*)(CSOUND *)) NULL, /* spinrecv */ - (void (*)(CSOUND *)) NULL, /* spoutran */ - (int (*)(CSOUND *, MYFLT *, int)) NULL, /* audrecv */ - (void (*)(CSOUND *, const MYFLT *, int)) NULL, /* audtran */ +#if defined(WIN32) //&& (__GNUC_VERSION__ < 40800) + (pthread_t){0, 0}, /* file_io_thread */ +#else + (pthread_t)0, /* file_io_thread */ +#endif + 0, /* file_io_start */ + NULL, /* file_io_threadlock */ + 0, /* realtime_audio_flag */ +#if defined(WIN32) //&& (__GNUC_VERSION__ < 40800) + (pthread_t){0, 0}, /* init pass thread */ +#else + (pthread_t)0, /* init pass thread */ +#endif + 0, /* init pass loop */ + NULL, /* init pass threadlock */ + NULL, /* API_lock */ +#if defined(HAVE_PTHREAD_SPIN_LOCK) + PTHREAD_SPINLOCK_INITIALIZER, /* spoutlock */ + PTHREAD_SPINLOCK_INITIALIZER, /* spinlock */ +#else + 0, /* spoutlock */ + 0, /* spinlock */ +#endif +#if defined(HAVE_PTHREAD_SPIN_LOCK) + PTHREAD_SPINLOCK_INITIALIZER, /* memlock */ + PTHREAD_SPINLOCK_INITIALIZER, /* spinlock1 */ +#else + 0, 0, /* memlock, spinlock1 */ +#endif + NULL, NULL, /* Delayed messages */ + { + NULL, NULL, NULL, NULL, /* bp, prvibp, sp, nx */ + 0, 0, 0, 0, /* op warpin linpos lincnt */ + -FL(1.0), FL(0.0), FL(1.0), /* prvp2 clock_base warp_factor */ + NULL, /* curmem */ + NULL, /* memend */ + NULL, /* macros */ + -1, /* next_name */ + NULL, NULL, /* inputs, str */ + 0,0,0, /* input_size, input_cnt, pop */ + 1, /* ingappop */ + -1, /* linepos */ + {{NULL, 0, 0, NULL}}, /* names */ + {""}, /* repeat_name_n[RPTDEPTH][NAMELEN] */ + {0}, /* repeat_cnt_n[RPTDEPTH] */ + {0}, /* repeat_point_n[RPTDEPTH] */ + 1, {NULL}, 0, /* repeat_inc_n,repeat_mm_n repeat_index */ + "", /* repeat_name[NAMELEN] */ + 0,0,1, /* repeat_cnt, repeat_point, repeat_inc */ + NULL, /* repeat_mm */ + }, + { + NULL, + NULL, NULL, NULL, /* orcname, sconame, midname */ + 0, 0 /* midiSet, csdlinecount */ + }, + { + NULL, NULL, /* Linep, Linebufend */ + 0, /* stdmode */ + { + 0, NULL, NULL, 0, 0, FL(0.0), FL(0.0), { FL(0.0) }, + {NULL}, + }, /* EVTBLK prve */ + NULL, /* Linebuf */ + 0 /* linebufsiz */ + }, + { + {0,0}, {0,0}, /* srngcnt, orngcnt */ + 0, 0, 0, 0, 0, /* srngflg, sectno, lplayed, segamps, sormsg */ + NULL, NULL, /* ep, epend */ + NULL /* lsect */ + }, + //NULL, /* musmonGlobals */ + { + NULL, /* outfile */ + NULL, /* infile */ + NULL, /* sfoutname; */ + NULL, /* inbuf */ + NULL, /* outbuf */ + NULL, /* outbufp */ + 0, /* inbufrem */ + 0, /* outbufrem */ + 0,0, /* inbufsiz, outbufsiz */ + 0, /* isfopen */ + 0, /* osfopen */ + 0,0, /* pipdevin, pipdevout */ + 1U, /* nframes */ + NULL, NULL, /* pin, pout */ + 0, /*dither */ + }, 0, /* warped */ 0, /* sstrlen */ (char*) NULL, /* sstrbuf */ @@ -594,14 +736,15 @@ NULL, /* pvFileTable */ 0, /* pvNumFiles */ 0, /* pvErrorCode */ - NULL, /* pluginOpcodeFiles */ - NULL, /* pluginOpcodeDB */ + // NULL, /* pluginOpcodeFiles */ 0, /* enableHostImplementedAudioIO */ + 0, /* MIDI IO */ 0, /* hostRequestedBufferSize */ - 0, /* engineState */ + 0, /* engineStatus */ 0, /* stdin_assign_flg */ 0, /* stdout_assign_flg */ 0, /* orcname_mode */ + 0, /* use_only_orchfile */ NULL, /* csmodule_db */ (char*) NULL, /* dl_opcodes_oplibs */ (char*) NULL, /* SF_csd_licence */ @@ -624,8 +767,6 @@ 1000, /* ugens4_rand_16 */ 1000, /* ugens4_rand_15 */ NULL, /* schedule_kicked */ - (LBLBLK**) NULL, /* lopds */ - NULL, /* larg */ (MYFLT*) NULL, /* disprep_fftcoefs */ NULL, /* winEPS_globals */ { /* oparms_ */ @@ -633,8 +774,13 @@ 0, 1, 1, 0, /* sfread, ... */ 0, 0, 0, 0, /* inbufsamps, ... */ 0, /* sfsampsize */ +#ifdef LINUX 1, /* displays */ - 0, 0, 135, /* disp.. graphsoff ... */ + 1, 0, 135, /* graphsoff postscript, msglevel */ +#else + 1, /* displa */ + 1, 0, 135, /* disp.. graphsoff ... */ +#endif 0, 0, 0, /* Beatmode, ... */ 0, 0, /* usingcscore, ... */ 0, 0, 0, 0, /* RTevents, ... */ @@ -642,6 +788,7 @@ 0, 0, 0, /* rewrt_hdr, ... */ 0, /* expr_opt */ 0.0f, 0.0f, /* sr_override ... */ + 0, 0, /* nchnls_override ... */ (char*) NULL, (char*) NULL, NULL, (char*) NULL, (char*) NULL, (char*) NULL, (char*) NULL, (char*) NULL, @@ -655,46 +802,39 @@ 1, /* numThreads */ 0, /* syntaxCheckOnly */ 1, /* useCsdLineCounts */ - 1, /* newParser */ - 0, /* calculateWeights */ + 0, /* samp acc */ + 0, /* realtime */ + 0.0, /* 0dbfs override */ + 0 /* no exit on compile error */ }, - 0L, 0L, /* instxtcount, optxtsize */ - 0L, 0L, /* poolcount, gblfixed */ - 0L, 0L, /* gblacount, gblscount */ - (CsoundChannelIOCallback_t) NULL, /* channelIOCallback_ */ - csoundDoCallback_, /* doCsoundCallback */ - &(strhash_tabl_8[0]), /* strhash_tabl_8 */ - csound_str_hash_32, /* strHash32 */ + {0, 0, {0}}, /* REMOT_BUF */ NULL, /* remoteGlobals */ 0, 0, /* nchanof, nchanif */ NULL, NULL, /* chanif, chanof */ - defaultCsoundYield, /* csoundInternalYieldCallback_*/ NULL, /* multiThreadedBarrier1 */ NULL, /* multiThreadedBarrier2 */ 0, /* multiThreadedComplete */ NULL, /* multiThreadedThreadInfo */ - NULL, /* multiThreadedStart */ - NULL, /* multiThreadedEnd */ -#ifdef PARCS - NULL, /* weight_info */ - NULL, /* weight_dump */ - NULL, /* weights */ NULL, /* multiThreadedDag */ NULL, /* barrier1 */ NULL, /* barrier2 */ NULL, /* global_var_lock_root */ NULL, /* global_var_lock_cache */ 0, /* global_var_lock_count */ - 0, /* opcode_weight_cache_ctr */ - {NULL,NULL}, /* opcode_weight_cache[OPCODE_WEIGHT_CACHE_SIZE] */ - 0, /* opcode_weight_have_cache */ - {NULL,NULL}, /* ache[DAG_2_CACHE_SIZE] */ /* statics from cs_par_orc_semantic_analysis */ NULL, /* instCurr */ NULL, /* instRoot */ 0, /* inInstr */ -#endif /* PARCS */ + /* new dag model statics */ + 1, /* dag_changed */ + 0, /* dag_num_active */ + NULL, /* dag_task_map */ + NULL, /* dag_task_status */ + NULL, /* dag_task_watch */ + NULL, /* dag_wlmm */ + NULL, /* dag_task_dep */ + 100, /* dag_task_max_size */ 0, /* tempStatus */ 0, /* orcLineOffset */ 0, /* scoLineOffset */ @@ -702,2191 +842,2323 @@ -1, /* parserUdoflag */ 0, /* parserNamedInstrFlag */ 0, /* tran_nchnlsi */ - 0, /* Count of extra strings */ - {NULL, NULL, NULL}, /* For extra strings in scores */ - {0, 0, 0}, /* For extra strings in scores */ - 300, /* Count for generated labels */ - NULL, /* pow2 table */ - NULL, /* cps conv table */ - NULL, /* output of preprocessor */ - { NULL, NULL, NULL}/* for location directory */ - }; - - /* from threads.c */ - void csoundLock(void); - void csoundUnLock(void); - /* aops.c */ - /*void aops_init_tables(void);*/ - void csound_aops_init_tables(CSOUND *cs); + 0, /* Count of score strings */ + 0, /* length of current strings space */ + NULL, /* sinetable */ + 16384, /* sinesize */ + NULL, /* pow2 table */ + NULL, /* cps conv table */ + NULL, /* output of preprocessor */ + NULL, /* filedir */ + {NULL}, /* message buffer struct */ + 0, /* jumpset */ + 0, /* info_message_request */ + 0 /* modules loaded */ + /*, NULL */ /* self-reference */ +}; + +/* from threads.c */ +void csoundLock(void); +void csoundUnLock(void); +void csound_aops_init_tables(CSOUND *cs); - typedef struct csInstance_s { +typedef struct csInstance_s { CSOUND *csound; struct csInstance_s *nxt; - } csInstance_t; - - /* initialisation state: */ - /* 0: not done yet, 1: complete, 2: in progress, -1: failed */ - static volatile int init_done = 0; - /* chain of allocated Csound instances */ - static volatile csInstance_t *instance_list = NULL; - /* non-zero if performance should be terminated now */ - static volatile int exitNow_ = 0; - - static void destroy_all_instances(void) - { - volatile csInstance_t *p; +} csInstance_t; +/* initialisation state: */ +/* 0: not done yet, 1: complete, 2: in progress, -1: failed */ +static volatile int init_done = 0; +/* chain of allocated Csound instances */ +static volatile csInstance_t *instance_list = NULL; +/* non-zero if performance should be terminated now */ +static volatile int exitNow_ = 0; + +static void destroy_all_instances(void) +{ + volatile csInstance_t *p; + + csoundLock(); + init_done = -1; /* prevent the creation of any new instances */ + if (instance_list == NULL) { + csoundUnLock(); + return; + } + csoundUnLock(); + csoundSleep(250); + while (1) { csoundLock(); - init_done = -1; /* prevent the creation of any new instances */ - if (instance_list == NULL) { - csoundUnLock(); - return; - } + p = instance_list; csoundUnLock(); - csoundSleep(250); - while (1) { - csoundLock(); - p = instance_list; - csoundUnLock(); - if (p == NULL) { - break; - } - csoundDestroy(p->csound); + if (p == NULL) { + break; } - } + csoundDestroy(p->csound); + } +} -#if defined(ANDROID) || (!defined(LINUX) && !defined(SGI) && !defined(__BEOS__) && !defined(__MACH__)) - static char *signal_to_string(int sig) - { - switch(sig) { +#if defined(ANDROID) || (!defined(LINUX) && !defined(SGI) && \ + !defined(__HAIKU__) && !defined(__BEOS__) && \ + !defined(__MACH__)) +static char *signal_to_string(int sig) +{ + switch(sig) { #ifdef SIGHUP - case SIGHUP: - return "Hangup"; + case SIGHUP: + return "Hangup"; #endif #ifdef SIGINT - case SIGINT: - return "Interrupt"; + case SIGINT: + return "Interrupt"; #endif #ifdef SIGQUIT - case SIGQUIT: - return "Quit"; + case SIGQUIT: + return "Quit"; #endif #ifdef SIGILL - case SIGILL: - return "Illegal instruction"; + case SIGILL: + return "Illegal instruction"; #endif #ifdef SIGTRAP - case SIGTRAP: - return "Trace trap"; + case SIGTRAP: + return "Trace trap"; #endif #ifdef SIGABRT - case SIGABRT: - return "Abort"; + case SIGABRT: + return "Abort"; #endif #ifdef SIGBUS - case SIGBUS: - return "BUS error"; + case SIGBUS: + return "BUS error"; #endif #ifdef SIGFPE - case SIGFPE: - return "Floating-point exception"; + case SIGFPE: + return "Floating-point exception"; #endif #ifdef SIGUSR1 - case SIGUSR1: - return "User-defined signal 1"; + case SIGUSR1: + return "User-defined signal 1"; #endif #ifdef SIGSEGV - case SIGSEGV: - return "Segmentation violation"; + case SIGSEGV: + return "Segmentation violation"; #endif #ifdef SIGUSR2 - case SIGUSR2: - return "User-defined signal 2"; + case SIGUSR2: + return "User-defined signal 2"; #endif #ifdef SIGPIPE - case SIGPIPE: - return "Broken pipe"; + case SIGPIPE: + return "Broken pipe"; #endif #ifdef SIGALRM - case SIGALRM: - return "Alarm clock"; + case SIGALRM: + return "Alarm clock"; #endif #ifdef SIGTERM - case SIGTERM: - return "Termination"; + case SIGTERM: + return "Termination"; #endif #ifdef SIGSTKFLT - case SIGSTKFLT: - return "???"; + case SIGSTKFLT: + return "???"; #endif #ifdef SIGCHLD - case SIGCHLD: - return "Child status has changed"; + case SIGCHLD: + return "Child status has changed"; #endif #ifdef SIGCONT - case SIGCONT: - return "Continue"; + case SIGCONT: + return "Continue"; #endif #ifdef SIGSTOP - case SIGSTOP: - return "Stop, unblockable"; + case SIGSTOP: + return "Stop, unblockable"; #endif #ifdef SIGTSTP - case SIGTSTP: - return "Keyboard stop"; + case SIGTSTP: + return "Keyboard stop"; #endif #ifdef SIGTTIN - case SIGTTIN: - return "Background read from tty"; + case SIGTTIN: + return "Background read from tty"; #endif #ifdef SIGTTOU - case SIGTTOU: - return "Background write to tty"; + case SIGTTOU: + return "Background write to tty"; #endif #ifdef SIGURG - case SIGURG: - return "Urgent condition on socket "; + case SIGURG: + return "Urgent condition on socket "; #endif #ifdef SIGXCPU - case SIGXCPU: - return "CPU limit exceeded"; + case SIGXCPU: + return "CPU limit exceeded"; #endif #ifdef SIGXFSZ - case SIGXFSZ: - return "File size limit exceeded "; + case SIGXFSZ: + return "File size limit exceeded "; #endif #ifdef SIGVTALRM - case SIGVTALRM: - return "Virtual alarm clock "; + case SIGVTALRM: + return "Virtual alarm clock "; #endif #ifdef SIGPROF - case SIGPROF: - return "Profiling alarm clock"; + case SIGPROF: + return "Profiling alarm clock"; #endif #ifdef SIGWINCH - case SIGWINCH: - return "Window size change "; + case SIGWINCH: + return "Window size change "; #endif #ifdef SIGIO - case SIGIO: - return "I/O now possible"; + case SIGIO: + return "I/O now possible"; #endif #ifdef SIGPWR - case SIGPWR: - return "Power failure restart"; + case SIGPWR: + return "Power failure restart"; #endif - default: - return "???"; - } - } + default: + return "???"; + } +} - static void psignal(int sig, char *str) - { - fprintf(stderr, "%s: %s\n", str, signal_to_string(sig)); - } +static void psignal(int sig, char *str) +{ + fprintf(stderr, "%s: %s\n", str, signal_to_string(sig)); +} #elif defined(__BEOS__) - static void psignal(int sig, char *str) - { - fprintf(stderr, "%s: %s\n", str, strsignal(sig)); - } +static void psignal(int sig, char *str) +{ + fprintf(stderr, "%s: %s\n", str, strsignal(sig)); +} #endif - static void signal_handler(int sig) - { +static void signal_handler(int sig) +{ #if defined(SIGPIPE) - if (sig == (int) SIGPIPE) { - psignal(sig, "Csound ignoring SIGPIPE"); - return; - } + if (sig == (int) SIGPIPE) { + psignal(sig, "Csound ignoring SIGPIPE"); + return; + } #endif - psignal(sig, "Csound tidy up"); - if ((sig == (int) SIGINT || sig == (int) SIGTERM) && !exitNow_) { - exitNow_ = -1; - return; - } - exit(1); - } + psignal(sig, "Csound tidy up"); + if ((sig == (int) SIGINT || sig == (int) SIGTERM) && !exitNow_) { + exitNow_ = -1; + return; + } + exit(1); +} - static const int sigs[] = { +static const int sigs[] = { #if defined(LINUX) || defined(SGI) || defined(sol) || defined(__MACH__) - SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT, SIGBUS, - SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, SIGXCPU, SIGXFSZ, + SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGIOT, SIGBUS, + SIGFPE, SIGSEGV, SIGPIPE, SIGTERM, SIGXCPU, SIGXFSZ, #elif defined(WIN32) - SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTERM, + SIGINT, SIGILL, SIGABRT, SIGFPE, SIGSEGV, SIGTERM, #elif defined(__EMX__) - SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, - SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGTERM, SIGCHLD, + SIGHUP, SIGINT, SIGQUIT, SIGILL, SIGTRAP, SIGABRT, SIGBUS, SIGFPE, + SIGUSR1, SIGSEGV, SIGUSR2, SIGPIPE, SIGTERM, SIGCHLD, #endif - -1 - }; + -1 +}; - static void install_signal_handler(void) - { - int i; - for (i = 0; sigs[i] >= 0; i++) { - signal(sigs[i], signal_handler); - } - } +static void install_signal_handler(void) +{ + unsigned int i; + for (i = 0; sigs[i] >= 0; i++) { + signal(sigs[i], signal_handler); + } +} - static int getTimeResolution(void); +static int getTimeResolution(void); - PUBLIC int csoundInitialize(int *argc, char ***argv, int flags) - { - int n; +PUBLIC int csoundInitialize(int flags) +{ + int n; - (void) argc; - (void) argv; - do { - csoundLock(); - n = init_done; - switch (n) { - case 2: - csoundUnLock(); - csoundSleep(1); - case 0: - break; - default: - csoundUnLock(); - return n; - } - } while (n); - init_done = 2; - csoundUnLock(); - init_getstring(); - if (getTimeResolution() != 0) { - csoundLock(); - init_done = -1; + do { + csoundLock(); + n = init_done; + switch (n) { + case 2: csoundUnLock(); - return -1; - } - if (!(flags & CSOUNDINIT_NO_SIGNAL_HANDLER)) { - install_signal_handler(); + csoundSleep(1); + case 0: + break; + default: + csoundUnLock(); + return n; } -#if !defined(WIN32) - if (!(flags & CSOUNDINIT_NO_ATEXIT)) - atexit(destroy_all_instances); -#endif - /*aops_init_tables();*/ + } while (n); + init_done = 2; + csoundUnLock(); + if (getTimeResolution() != 0) { csoundLock(); - init_done = 1; + init_done = -1; csoundUnLock(); - return 0; - } - - PUBLIC CSOUND *csoundCreate(void *hostdata) - { - CSOUND *csound; - csInstance_t *p; + return -1; + } + if (!(flags & CSOUNDINIT_NO_SIGNAL_HANDLER)) { + install_signal_handler(); + } +#if !defined(WIN32) + if (!(flags & CSOUNDINIT_NO_ATEXIT)) + atexit(destroy_all_instances); +#endif + csoundLock(); + init_done = 1; + csoundUnLock(); + return 0; + } + +PUBLIC CSOUND *csoundCreate(void *hostdata) +{ + CSOUND *csound; + csInstance_t *p; + + if (init_done != 1) { + if (csoundInitialize(0) < 0) return NULL; + } + csound = (CSOUND*) malloc(sizeof(CSOUND)); + if (UNLIKELY(csound == NULL)) return NULL; + memcpy(csound, &cenviron_, sizeof(CSOUND)); + init_getstring(csound); + csound->oparms = &(csound->oparms_); + csound->hostdata = hostdata; + p = (csInstance_t*) malloc(sizeof(csInstance_t)); + if (UNLIKELY(p == NULL)) { + free(csound); + return NULL; + } + csoundLock(); + p->csound = csound; + p->nxt = (csInstance_t*) instance_list; + instance_list = p; + csoundUnLock(); + csoundReset(csound); + csound->API_lock = csoundCreateMutex(1); + /* NB: as suggested by F Pinot, keep the + address of the pointer to CSOUND inside + the struct, so it can be cleared later */ + //csound->self = &csound; - if (init_done != 1) { - if (csoundInitialize(NULL, NULL, 0) < 0) return NULL; - } - csound = (CSOUND*) malloc(sizeof(CSOUND)); - if (UNLIKELY(csound == NULL)) return NULL; - memcpy(csound, &cenviron_, sizeof(CSOUND)); - csound->oparms = &(csound->oparms_); - csound->hostdata = hostdata; - p = (csInstance_t*) malloc(sizeof(csInstance_t)); - if (UNLIKELY(p == NULL)) { - free(csound); - return NULL; - } - csoundLock(); - p->csound = csound; - p->nxt = (csInstance_t*) instance_list; - instance_list = p; - csoundUnLock(); - csoundReset(csound); - //csound_aops_init_tables(csound); - return csound; - } + return csound; +} /* dummy real time MIDI functions */ - static int DummyMidiInOpen(CSOUND *csound, void **userData, - const char *devName); - static int DummyMidiRead(CSOUND *csound, void *userData, - unsigned char *buf, int nbytes); - static int DummyMidiOutOpen(CSOUND *csound, void **userData, - const char *devName); - static int DummyMidiWrite(CSOUND *csound, void *userData, - const unsigned char *buf, int nbytes); - /* random.c */ - extern void csound_init_rand(CSOUND *); - - /** - * Reset and prepare an instance of Csound for compilation. - * Returns CSOUND_SUCCESS on success, and CSOUND_ERROR or - * CSOUND_MEMORY if an error occured. - */ - PUBLIC int csoundPreCompile(CSOUND *p) - { - char *s; - int i, max_len; - int n; - - if ((n = setjmp(p->exitjmp)) != 0) { - return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); - } - /* reset instance */ - csoundReset(p); - /* copy system environment variables */ - i = csoundInitEnv(p); - if (UNLIKELY(i != CSOUND_SUCCESS)) { - p->engineState |= CS_STATE_JMP; - return i; - } - csound_init_rand(p); - /* allow selecting real time audio module */ - max_len = 21; - csoundCreateGlobalVariable(p, "_RTAUDIO", (size_t) max_len); - s = csoundQueryGlobalVariable(p, "_RTAUDIO"); - strcpy(s, "PortAudio"); - csoundCreateConfigurationVariable(p, "rtaudio", s, CSOUNDCFG_STRING, - 0, NULL, &max_len, - "Real time audio module name", NULL); - - /* initialise real time MIDI */ - p->midiGlobals = (MGLOBAL*) mcalloc(p, sizeof(MGLOBAL)); - p->midiGlobals->Midevtblk = (MEVENT*) NULL; - p->midiGlobals->MidiInOpenCallback = DummyMidiInOpen; - p->midiGlobals->MidiReadCallback = DummyMidiRead; - p->midiGlobals->MidiInCloseCallback = (int (*)(CSOUND *, void *)) NULL; - p->midiGlobals->MidiOutOpenCallback = DummyMidiOutOpen; - p->midiGlobals->MidiWriteCallback = DummyMidiWrite; - p->midiGlobals->MidiOutCloseCallback = (int (*)(CSOUND *, void *)) NULL; - p->midiGlobals->MidiErrorStringCallback = (const char *(*)(int)) NULL; - p->midiGlobals->midiInUserData = NULL; - p->midiGlobals->midiOutUserData = NULL; - p->midiGlobals->midiFileData = NULL; - p->midiGlobals->midiOutFileData = NULL; - p->midiGlobals->bufp = &(p->midiGlobals->mbuf[0]); - p->midiGlobals->endatp = p->midiGlobals->bufp; - csoundCreateGlobalVariable(p, "_RTMIDI", (size_t) max_len); - s = csoundQueryGlobalVariable(p, "_RTMIDI"); - strcpy(s, "portmidi"); - csoundCreateConfigurationVariable(p, "rtmidi", s, CSOUNDCFG_STRING, - 0, NULL, &max_len, - "Real time MIDI module name", NULL); - max_len = 256; /* should be the same as in csoundCore.h */ - csoundCreateConfigurationVariable(p, "mute_tracks", - &(p->midiGlobals->muteTrackList[0]), - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Ignore events (other than tempo changes)" - " in tracks defined by pattern", - NULL); - csoundCreateConfigurationVariable(p, "raw_controller_mode", - &(p->midiGlobals->rawControllerMode), - CSOUNDCFG_BOOLEAN, 0, NULL, NULL, - "Do not handle special MIDI controllers" - " (sustain pedal etc.)", NULL); - /* sound file tag options */ - max_len = 201; - i = (max_len + 7) & (~7); - p->SF_id_title = (char*) mcalloc(p, (size_t) i * (size_t) 6); - csoundCreateConfigurationVariable(p, "id_title", p->SF_id_title, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Title tag in output soundfile " - "(no spaces)", NULL); - p->SF_id_copyright = (char*) p->SF_id_title + (int) i; - csoundCreateConfigurationVariable(p, "id_copyright", p->SF_id_copyright, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Copyright tag in output soundfile" - " (no spaces)", NULL); - p->SF_id_software = (char*) p->SF_id_copyright + (int) i; - csoundCreateConfigurationVariable(p, "id_software", p->SF_id_software, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Software tag in output soundfile" - " (no spaces)", NULL); - p->SF_id_artist = (char*) p->SF_id_software + (int) i; - csoundCreateConfigurationVariable(p, "id_artist", p->SF_id_artist, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Artist tag in output soundfile " - "(no spaces)", - NULL); - p->SF_id_comment = (char*) p->SF_id_artist + (int) i; - csoundCreateConfigurationVariable(p, "id_comment", p->SF_id_comment, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Comment tag in output soundfile" - " (no spaces)", NULL); - p->SF_id_date = (char*) p->SF_id_comment + (int) i; - csoundCreateConfigurationVariable(p, "id_date", p->SF_id_date, - CSOUNDCFG_STRING, 0, NULL, &max_len, - "Date tag in output soundfile " - "(no spaces)", - NULL); - { - int minVal = 10; - int maxVal = 10000; - MYFLT minValF = FL(0.0); - /* max. length of string variables */ - csoundCreateConfigurationVariable(p, "max_str_len", &(p->strVarMaxLen), - CSOUNDCFG_INTEGER, 0, &minVal, &maxVal, - "Maximum length of string variables + 1", - NULL); - csoundCreateConfigurationVariable(p, "msg_color", &(p->enableMsgAttr), - CSOUNDCFG_BOOLEAN, 0, NULL, NULL, - "Enable message attributes (colors etc.)", - NULL); - csoundCreateConfigurationVariable(p, "skip_seconds", - &(p->csoundScoreOffsetSeconds_), - CSOUNDCFG_MYFLT, 0, &minValF, NULL, - "Start score playback at the specified" - " time, skipping earlier events", - NULL); - } - csoundCreateConfigurationVariable(p, "ignore_csopts", - &(p->disable_csd_options), - CSOUNDCFG_BOOLEAN, 0, NULL, NULL, - "Ignore in CSD files" - " (default: no)", NULL); - p->opcode_list = (int*) mcalloc(p, sizeof(int) * 256); - p->engineState |= CS_STATE_PRE; - csound_aops_init_tables(p); - /* now load and pre-initialise external modules for this instance */ - /* this function returns an error value that may be worth checking */ - { - int err = csoundInitStaticModules(p); - if (p->delayederrormessages && p->printerrormessagesflag==NULL) { - p->Warning(p, p->delayederrormessages); - free(p->delayederrormessages); - p->delayederrormessages = NULL; - } - if (UNLIKELY(err==CSOUND_ERROR)) return err; - err = csoundLoadModules(p); - if (p->delayederrormessages && p->printerrormessagesflag==NULL) { - p->Warning(p, p->delayederrormessages); - free(p->delayederrormessages); - p->delayederrormessages = NULL; - } - return err; - } - } - - - PUBLIC int csoundQueryInterface(const char *name, void **iface, int *version) - { - if (strcmp(name, "CSOUND") != 0) - return 1; - *iface = csoundCreate(NULL); - *version = csoundGetAPIVersion(); - return 0; - } +int DummyMidiInOpen(CSOUND *csound, void **userData, + const char *devName); +int DummyMidiRead(CSOUND *csound, void *userData, + unsigned char *buf, int nbytes); +int DummyMidiOutOpen(CSOUND *csound, void **userData, + const char *devName); +int DummyMidiWrite(CSOUND *csound, void *userData, + const unsigned char *buf, int nbytes); +/* random.c */ +extern void csound_init_rand(CSOUND *); + +/* +PUBLIC int csoundQueryInterface(const char *name, void **iface, int *version) +{ + if (strcmp(name, "CSOUND") != 0) + return 1; + *iface = csoundCreate(NULL); + *version = csoundGetAPIVersion(); + return 0; +} +*/ - typedef struct CsoundCallbackEntry_s CsoundCallbackEntry_t; +typedef struct CsoundCallbackEntry_s CsoundCallbackEntry_t; - struct CsoundCallbackEntry_s { +struct CsoundCallbackEntry_s { unsigned int typeMask; CsoundCallbackEntry_t *nxt; void *userData; int (*func)(void *, void *, unsigned int); - }; - - PUBLIC void csoundDestroy(CSOUND *csound) - { - csInstance_t *p, *prv = NULL; +}; - csoundLock(); - p = (csInstance_t*) instance_list; - while (p != NULL && p->csound != csound) { - prv = p; - p = p->nxt; - } - if (p == NULL) { - csoundUnLock(); - return; - } - if (prv == NULL) - instance_list = p->nxt; - else - prv->nxt = p->nxt; +PUBLIC void csoundDestroy(CSOUND *csound) +{ + csInstance_t *p, *prv = NULL; + + csoundLock(); + p = (csInstance_t*) instance_list; + while (p != NULL && p->csound != csound) { + prv = p; + p = p->nxt; + } + if (p == NULL) { csoundUnLock(); - free(p); - csoundReset(csound); - if (csound->csoundCallbacks_ != NULL) { - CsoundCallbackEntry_t *pp, *nxt; - pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; - do { - nxt = pp->nxt; - free((void*) pp); - pp = nxt; - } while (pp != (CsoundCallbackEntry_t*) NULL); - } - free((void*) csound); - } + return; + } + if (prv == NULL) + instance_list = p->nxt; + else + prv->nxt = p->nxt; + csoundUnLock(); + free(p); - PUBLIC int csoundGetVersion(void) - { - return (int) (CS_VERSION * 1000 + CS_SUBVER * 10 + CS_PATCHLEVEL); - } + reset(csound); - PUBLIC int csoundGetAPIVersion(void) - { - return CS_APIVERSION * 100 + CS_APISUBVER; - } + if (csound->csoundCallbacks_ != NULL) { + CsoundCallbackEntry_t *pp, *nxt; + pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; + do { + nxt = pp->nxt; + free((void*) pp); + pp = nxt; + } while (pp != (CsoundCallbackEntry_t*) NULL); + } + if(csound->API_lock != NULL) { + //csoundLockMutex(csound->API_lock); + csoundDestroyMutex(csound->API_lock); + } + /* clear the pointer */ + //*(csound->self) = NULL; + free((void*) csound); +} - PUBLIC void *csoundGetHostData(CSOUND *csound) - { - return csound->hostdata; - } +PUBLIC int csoundGetVersion(void) +{ + return (int) (CS_VERSION * 1000 + CS_SUBVER * 10 + CS_PATCHLEVEL); +} - PUBLIC void csoundSetHostData(CSOUND *csound, void *hostData) - { - csound->hostdata = hostData; - } +PUBLIC int csoundGetAPIVersion(void) +{ + return CS_APIVERSION * 100 + CS_APISUBVER; +} + +PUBLIC void *csoundGetHostData(CSOUND *csound) +{ + return csound->hostdata; +} - /* - * PERFORMANCE - */ - - extern int sensevents(CSOUND *); - - /** - * perform currently active instrs for one kperiod - * & send audio result to output buffer - * returns non-zero if this kperiod was skipped - */ - - static int getThreadIndex(CSOUND *csound, void *threadId) - { -#ifndef mac_classic - int index = 0; - THREADINFO *current = csound->multiThreadedThreadInfo; +PUBLIC void csoundSetHostData(CSOUND *csound, void *hostData) +{ + csound->hostdata = hostData; +} - if (current == NULL) { - return -1; - } +/* + * PERFORMANCE + */ - while(current != NULL) { - if (pthread_equal(*(pthread_t *)threadId, *(pthread_t *)current->threadId)) - return index; - index++; - current = current->next; - } -#endif +extern int sensevents(CSOUND *); + +/** + * perform currently active instrs for one kperiod + * & send audio result to output buffer + * returns non-zero if this kperiod was skipped + */ + +static int getThreadIndex(CSOUND *csound, void *threadId) +{ + int index = 0; + THREADINFO *current = csound->multiThreadedThreadInfo; + + if (current == NULL) { return -1; - } + } + + while(current != NULL) { + if (pthread_equal(*(pthread_t *)threadId, *(pthread_t *)current->threadId)) + return index; + index++; + current = current->next; + } + return -1; +} #if 0 - static int getNumActive(INSDS *start, INSDS *end) - { - INSDS *current = start; - int counter = 1; - while(((current = current->nxtact) != NULL) && current != end) { - counter++; - } - return counter; - } +static int getNumActive(INSDS *start, INSDS *end) +{ + INSDS *current = start; + int counter = 1; + while(((current = current->nxtact) != NULL) && current != end) { + counter++; + } + return counter; +} #endif - inline void advanceINSDSPointer(INSDS ***start, int num) - { - int i; - INSDS *s = **start; - - if (s == NULL) return; - for (i = 0; i < num; i++) { - s = s->nxtact; - - if (s == NULL) { - **start = NULL; - return; - } +inline void advanceINSDSPointer(INSDS ***start, int num) +{ + int i; + INSDS *s = **start; + + if (s == NULL) return; + for (i = 0; i < num; i++) { + s = s->nxtact; + + if (s == NULL) { + **start = NULL; + return; } - **start = s; - } -#if defined(USE_OPENMP) - inline void multiThreadedLayer(CSOUND *csound, INSDS *layerBegin, INSDS *layerEnd) - { - // A single thread iterates over all instrument instances - // in the current layer... - INSDS *currentInstance; -#pragma omp parallel - { -#pragma omp single - { - for (currentInstance = layerBegin; - currentInstance && (currentInstance != layerEnd); - currentInstance = currentInstance->nxtact) { - // ...but each instance is computed in its own thread. -#pragma omp task firstprivate(currentInstance) - { - OPDS *currentOpcode = (OPDS *)currentInstance; - while ((currentOpcode = currentOpcode->nxtp)) { - (*currentOpcode->opadr)(csound, currentOpcode); - } - } - } - } - } - } -#endif - - - - -#ifdef PARCS - static int inline nodePerf(CSOUND *csound, int index) - { -#if (TRACE&4) == 4 - struct instr_semantics_t *instr; -#endif - INSDS *insds = NULL; - OPDS *opstart = NULL; - int update_hdl = -1; - int played_count = 0; - DAG_NODE *node; + } + **start = s; +} - do { - TRACE_2("Consume DAG [%i]\n", index); - csp_dag_consume(csound, csound->multiThreadedDag, &node, &update_hdl); +int dag_get_task(CSOUND *csound); +int dag_end_task(CSOUND *csound, int task); +void dag_build(CSOUND *csound, INSDS *chain); +void dag_reinit(CSOUND *csound); + +inline static int nodePerf(CSOUND *csound, int index) +{ + INSDS *insds = NULL; + OPDS *opstart = NULL; + int played_count = 0; + int which_task; + INSDS **task_map = (INSDS**)csound->dag_task_map; + double time_end; +#define INVALID (-1) +#define WAIT (-2) + IGN(index); - if (UNLIKELY(node == NULL)) { - return played_count; - } - - if (node->hdr.type == DAG_NODE_INDV) { -#if (TRACE&4) == 4 - instr = node->instr; -#endif - insds = node->insds; - played_count++; - - TRACE_2("DAG_NODE_INDV [%i] Playing: %s [%p]\n", index, instr->name, insds); - - opstart = (OPDS *)insds; - while ((opstart = opstart->nxtp) != NULL) { - (*opstart->opadr)(csound, opstart); /* run each opcode */ + while(1) { + int done; + which_task = dag_get_task(csound); + //printf("******** Select task %d\n", which_task); + if (which_task==WAIT) continue; + if (which_task==INVALID) return played_count; + /* VL: the validity of icurTime needs to be checked */ + time_end = (csound->ksmps+csound->icurTime)/csound->esr; + insds = task_map[which_task]; + if (insds->offtim > 0 && time_end > insds->offtim){ + /* this is the last cycle of performance */ + insds->ksmps_no_end = insds->no_end; } - - TRACE_2("[%i] Played: %s [%p]\n", index, instr->name, insds); +#ifdef HAVE_ATOMIC_BUILTIN + done = __sync_fetch_and_add((int *) &insds->init_done, 0); +#else + done = insds->init_done; +#endif + if(done) { + opstart = (OPDS*)task_map[which_task]; + if(insds->ksmps == csound->ksmps) { + insds->spin = csound->spin; + insds->spout = csound->spout; + insds->kcounter = csound->kcounter; + while ((opstart = opstart->nxtp) != NULL) { + /* In case of jumping need this repeat of opstart */ + opstart->insdshead->pds = opstart; + (*opstart->opadr)(csound, opstart); /* run each opcode */ + opstart = opstart->insdshead->pds; } - else if (node->hdr.type == DAG_NODE_LIST) { - played_count += node->count; - - int node_ctr = 0; - while (node_ctr < node->count) { - DAG_NODE *play_node = node->nodes[node_ctr]; -#if (TRACE&4) == 4 - instr = play_node->instr; -#endif - insds = play_node->insds; - TRACE_1("DAG_NODE_LIST: node->nodes=%p: play_node = %p, " - "instr=%p, insds=%p\n", - node->nodes, play_node, instr, insds); - - TRACE_2("[%i] Playing: %s [%p]\n", index, instr->name, insds); + } else { + int i, n = csound->nspout, start = 0; + int lksmps = insds->ksmps; + int incr = csound->nchnls*lksmps; + int offset = insds->ksmps_offset; + int early = insds->ksmps_no_end; + OPDS *opstart; + insds->spin = csound->spin; + insds->spout = csound->spout; + insds->kcounter = csound->kcounter*csound->ksmps; + + /* we have to deal with sample-accurate code + whole CS_KSMPS blocks are offset here, the + remainder is left to each opcode to deal with. + */ + while(offset >= lksmps) { + offset -= lksmps; + start += csound->nchnls; + } + insds->ksmps_offset = offset; + if(early){ + n -= (early*csound->nchnls); + insds->ksmps_no_end = early % lksmps; + } - opstart = (OPDS *)insds; + for (i=start; i < n; i+=incr, insds->spin+=incr, insds->spout+=incr) { + opstart = (OPDS*) insds; while ((opstart = opstart->nxtp) != NULL) { - /* csound->Message(csound, "**opstart=%p; opadr=%p (%s)\n", opstart, */ - /* opstart->opadr, opstart->optext->t.opcod); */ + opstart->insdshead->pds = opstart; (*opstart->opadr)(csound, opstart); /* run each opcode */ + opstart = opstart->insdshead->pds; } - - TRACE_2("[%i] Played: %s [%p]\n", index, instr->name, insds); - node_ctr++; + insds->kcounter++; } } - else if (node->hdr.type == DAG_NODE_DAG) { - csound->Die(csound, "Recursive DAGs not implemented"); - } - else { - csound->Die(csound, "Unknown DAG node type"); - } - - csp_dag_consume_update(csound, csound->multiThreadedDag, update_hdl); - } while (!csp_dag_is_finished(csound, csound->multiThreadedDag)); + insds->ksmps_offset = 0; /* reset sample-accuracy offset */ + insds->ksmps_no_end = 0; /* reset end of loop samples */ + played_count++; + } + //printf("******** finished task %d\n", which_task); + dag_end_task(csound, which_task); + } + return played_count; +} - return played_count; - } +unsigned long kperfThread(void * cs) +{ + INSDS *start; + CSOUND *csound = (CSOUND *)cs; + void *threadId; + int index; + int numThreads; + + csound->WaitBarrier(csound->barrier2); + + threadId = csound->GetCurrentThreadID(); + index = getThreadIndex(csound, threadId); + numThreads = csound->oparms->numThreads; + start = NULL; + csound->Message(csound, + Str("Multithread performance: insno: %3d thread %d of " + "%d starting.\n"), + start ? start->insno : -1, + index, + numThreads); + if (index < 0) { + csound->Die(csound, Str("Bad ThreadId")); + return ULONG_MAX; + } + index++; - unsigned long kperfThread(void * cs) - { - INSDS *start; - CSOUND *csound = (CSOUND *)cs; - void *threadId; - int index; - int numThreads; + while (1) { - csound->WaitBarrier(csound->barrier2); + csound->WaitBarrier(csound->barrier1); - threadId = csound->GetCurrentThreadID(); - index = getThreadIndex(csound, threadId); - numThreads = csound->oparms->numThreads; - start = NULL; - csound->Message(csound, - "Multithread performance: insno: %3d thread %d of " - "%d starting.\n", - start ? start->insno : -1, - index, - numThreads); - if (index < 0) { - csound->Die(csound, "Bad ThreadId"); - return ULONG_MAX; + csound_global_mutex_lock(); + if (csound->multiThreadedComplete == 1) { + csound_global_mutex_unlock(); + free(threadId); + return 0UL; } - index++; + csound_global_mutex_unlock(); - while (1) { + nodePerf(csound, index); - TRACE_1("[%i] Barrier1 Reached\n", index); - SHARK_SIGNPOST(BARRIER_1_WAIT_SYM); - csound->WaitBarrier(csound->barrier1); - - TRACE_1("[%i] Go\n", index); - - /* TIMER_INIT(mutex, "Mutex "); - TIMER_T_START(mutex, index, "Mutex "); */ - - csound_global_mutex_lock(); - if (csound->multiThreadedComplete == 1) { - csound_global_mutex_unlock(); - free(threadId); - /* csound->Message(csound, - "Multithread performance: insno: %3d thread " - "%d of %d exiting.\n", - start->insno, - index, - numThreads); */ - return 0UL; - } - csound_global_mutex_unlock(); + csound->WaitBarrier(csound->barrier2); + } +} - /* TIMER_T_END(mutex, index, "Mutex "); */ +int kperf(CSOUND *csound) +{ + INSDS *ip; + /* update orchestra time */ + csound->kcounter = ++(csound->global_kcounter); + csound->icurTime += csound->ksmps; + csound->curBeat += csound->curBeat_inc; - TIMER_INIT(thread, ""); - TIMER_T_START(thread, index, ""); - nodePerf(csound, index); + /* if skipping time on request by 'a' score statement: */ + if (UNLIKELY(csound->advanceCnt)) { + csound->advanceCnt--; + return 1; + } + /* if i-time only, return now */ + if (UNLIKELY(csound->initonly)) + return 1; + /* PC GUI needs attention, but avoid excessively frequent */ + /* calls of csoundYield() */ + if (UNLIKELY(--(csound->evt_poll_cnt) < 0)) { + csound->evt_poll_cnt = csound->evt_poll_maxcnt; + if (UNLIKELY(!csoundYield(csound))) csound->LongJmp(csound, 1); + } + + /* for one kcnt: */ + if (csound->oparms_.sfread) /* if audio_infile open */ + csound->spinrecv(csound); /* fill the spin buf */ + csound->spoutactive = 0; /* make spout inactive */ + /* clear spout */ + memset(csound->spout, 0, csound->nspout*sizeof(MYFLT)); + ip = csound->actanchor.nxtact; + + if (ip != NULL) { + /* There are 2 partitions of work: 1st by inso, + 2nd by inso count / thread count. */ + if (csound->multiThreadedThreadInfo != NULL) { + if (csound->dag_changed) dag_build(csound, ip); + else dag_reinit(csound); /* set to initial state */ - TIMER_T_END(thread, index, ""); + /* process this partition */ + csound->WaitBarrier(csound->barrier1); - TRACE_1("[%i] Done\n", index); + (void) nodePerf(csound, 0); - SHARK_SIGNPOST(BARRIER_2_WAIT_SYM); + /* wait until partition is complete */ csound->WaitBarrier(csound->barrier2); - TRACE_1("[%i] Barrier2 Done\n", index); + csound->multiThreadedDag = NULL; } - } -#endif /* ! PARCS */ + else { + int done; + double time_end = (csound->ksmps+csound->icurTime)/csound->esr; - inline void singleThreadedLayer(CSOUND *csound, - INSDS *layerBegin, INSDS *layerEnd) - { - INSDS *currentInstance; - for (currentInstance = layerBegin; - currentInstance && (currentInstance != layerEnd); - currentInstance = currentInstance->nxtact) { - csound->pds = (OPDS *)currentInstance; - while ((csound->pds = csound->pds->nxtp)) { - (*csound->pds->opadr)(csound, csound->pds); - } - } - } + while (ip != NULL) { /* for each instr active: */ + INSDS *nxt = ip->nxtact; + if (UNLIKELY(csound->oparms->sampleAccurate && + ip->offtim > 0 && + time_end > ip->offtim)) { + /* this is the last cycle of performance */ + // csound->Message(csound, "last cycle %d: %f %f %d\n", + // ip->insno, csound->icurTime/csound->esr, + // ip->offtim, ip->no_end); + ip->ksmps_no_end = ip->no_end; + } +#ifdef HAVE_ATOMIC_BUILTIN + done = __sync_fetch_and_add((int *) &ip->init_done, 0); +#else + done = ip->init_done; +#endif - int kperf(CSOUND *csound) - { -#ifdef PARCS - /* void *barrier1, *barrier2; */ - INSDS *ip; -#endif /* PARCS */ - /* update orchestra time */ - csound->kcounter = ++(csound->global_kcounter); - csound->icurTime += csound->ksmps; - csound->curBeat += csound->curBeat_inc; - /* if skipping time on request by 'a' score statement: */ - if (UNLIKELY(csound->advanceCnt)) { - csound->advanceCnt--; - return 1; - } - /* if i-time only, return now */ - if (UNLIKELY(csound->initonly)) - return 1; - /* PC GUI needs attention, but avoid excessively frequent */ - /* calls of csoundYield() */ - if (--(csound->evt_poll_cnt) < 0) { - csound->evt_poll_cnt = csound->evt_poll_maxcnt; - if (!csoundYield(csound)) - csound->LongJmp(csound, 1); - } - /* for one kcnt: */ - if (csound->oparms_.sfread) /* if audio_infile open */ - csound->spinrecv(csound); /* fill the spin buf */ - csound->spoutactive = 0; /* make spout inactive */ -#ifndef PARCS - if (csound->actanchor.nxtact) { -#if defined(USE_OPENMP) - if (csound->oparms->numThreads > 1) { - INSDS *layerBegin; - INSDS *currentInstance; - int layerInstances = 0; - for (currentInstance = layerBegin = csound->actanchor.nxtact; - currentInstance; - currentInstance = currentInstance->nxtact) { - if (!currentInstance->nxtact) { - if (layerInstances > 1) { - multiThreadedLayer(csound, layerBegin, 0); - } else { - singleThreadedLayer(csound, layerBegin, 0); + if (done == 1) {/* if init-pass has been done */ + OPDS *opstart = (OPDS*) ip; + ip->spin = csound->spin; + ip->spout = csound->spout; + ip->kcounter = csound->kcounter; + if(ip->ksmps == csound->ksmps) { + while ((opstart = opstart->nxtp) != NULL) { + opstart->insdshead->pds = opstart; + (*opstart->opadr)(csound, opstart); /* run each opcode */ + opstart = opstart->insdshead->pds; } } else { - layerInstances++; - if (((int) layerBegin->insno) != ((int) currentInstance->insno)) { - if (layerInstances > 1) { - multiThreadedLayer(csound, layerBegin, currentInstance); - } else { - singleThreadedLayer(csound, layerBegin, currentInstance); + int i, n = csound->nspout, start = 0; + int lksmps = ip->ksmps; + int incr = csound->nchnls*lksmps; + int offset = ip->ksmps_offset; + int early = ip->ksmps_no_end; + OPDS *opstart; + ip->spin = csound->spin; + ip->spout = csound->spout; + ip->kcounter = csound->kcounter*csound->ksmps/lksmps; + + /* we have to deal with sample-accurate code + whole CS_KSMPS blocks are offset here, the + remainder is left to each opcode to deal with. + */ + while(offset >= lksmps) { + offset -= lksmps; + start += csound->nchnls; + } + ip->ksmps_offset = offset; + if(early){ + n -= (early*csound->nchnls); + ip->ksmps_no_end = early % lksmps; + } + + for (i=start; i < n; i+=incr, ip->spin+=incr, ip->spout+=incr) { + opstart = (OPDS*) ip; + while ((opstart = opstart->nxtp) != NULL) { + opstart->insdshead->pds = opstart; + (*opstart->opadr)(csound, opstart); /* run each opcode */ + opstart = opstart->insdshead->pds; + } + ip->kcounter++; } - layerBegin = currentInstance; - layerInstances = 0; - } } } - } else { - singleThreadedLayer(csound, csound->actanchor.nxtact, 0); - } -#else /* MPI */ - INSDS *ip = csound->actanchor.nxtact; - while (ip != NULL) { /* for each instr active: */ - INSDS *nxt = ip->nxtact; - csound->pds = (OPDS*) ip; - while ((csound->pds = csound->pds->nxtp) != NULL) { - (*csound->pds->opadr)(csound, csound->pds); /* run each opcode */ - } + ip->ksmps_offset = 0; /* reset sample-accuracy offset */ + ip->ksmps_no_end = 0; /* reset end of loop samples */ ip = nxt; /* but this does not allow for all deletions */ } -#endif } -#else /* PARCS */ - /* barrier1 = csound->multiThreadedBarrier1; */ - /* barrier2 = csound->multiThreadedBarrier2; */ - ip = csound->actanchor.nxtact; - - if (ip != NULL) { - TIMER_INIT(thread, ""); - TIMER_START(thread, "Clock Sync "); - TIMER_END(thread, "Clock Sync "); - - SHARK_SIGNPOST(KPERF_SYM); - TRACE_1("[%i] kperf\n", 0); + } - /* There are 2 partitions of work: 1st by inso, - 2nd by inso count / thread count. */ - if (csound->multiThreadedThreadInfo != NULL) { - struct dag_t *dag2 = NULL; - - TIMER_START(thread, "Dag "); -#if defined(LINEAR_CACHE) || defined(HASH_CACHE) - csp_dag_cache_fetch(csound, &dag2, ip); - csp_dag_build(csound, &dag2, ip); -#endif - TIMER_END(thread, "Dag "); - - TRACE_1("{Time: %f}\n", csound->GetScoreTime(csound)); -#if TRACE > 1 - csp_dag_print(csound, dag2); -#endif - csound->multiThreadedDag = dag2; - - /* process this partition */ - TRACE_1("[%i] Barrier1 Reached\n", 0); - SHARK_SIGNPOST(BARRIER_1_WAIT_SYM); - csound->WaitBarrier(csound->barrier1); - - TIMER_START(thread, "[0] "); - - (void) nodePerf(csound, 0); - - TIMER_END(thread, "[0] "); + if (!csound->spoutactive) { /* results now in spout? */ + memset(csound->spout, 0, csound->nspout * sizeof(MYFLT)); + } + csound->spoutran(csound); /* send to audio_out */ + return 0; +} - SHARK_SIGNPOST(BARRIER_2_WAIT_SYM); - /* wait until partition is complete */ - csound->WaitBarrier(csound->barrier2); - TRACE_1("[%i] Barrier2 Done\n", 0); - TIMER_END(thread, ""); +PUBLIC int csoundReadScore(CSOUND *csound, char *str) +{ + OPARMS *O = csound->oparms; + /* protect resource */ + if(csound->scorestr != NULL && + csound->scorestr->body != NULL) + corfile_rewind(csound->scorestr); + + csound->scorestr = corfile_create_w(); + corfile_puts(str, csound->scorestr); + corfile_flush(csound->scorestr); + /* copy sorted score name */ + csoundLockMutex(csound->API_lock); + if(csound->scstr == NULL && (csound->engineStatus & CS_STATE_COMP) == 0) { + scsortstr(csound, csound->scorestr); + O->playscore = csound->scstr; + } + else { + char *sc = scsortstr(csound, csound->scorestr); + csoundInputMessageInternal(csound, (const char *) sc); + free(sc); + corfile_rm(&(csound->scorestr)); + } + csoundUnlockMutex(csound->API_lock); + return CSOUND_SUCCESS; +} -/* #if !defined(LINEAR_CACHE) && !defined(HASH_CACHE) */ -#if defined(LINEAR_CACHE) || defined(HASH_CACHE) - csp_dag_dealloc(csound, &dag2); -#else - dag2 = NULL; -#endif - csound->multiThreadedDag = NULL; - } - else { - while (ip != NULL) { /* for each instr active: */ - INSDS *nxt = ip->nxtact; - csound->pds = (OPDS*) ip; - while ((csound->pds = csound->pds->nxtp) != NULL) { - (*csound->pds->opadr)(csound, csound->pds); /* run each opcode */ - } - ip = nxt; /* but this does not allow for all deletions */ - } - } - } -#endif /* PARCS */ - if (!csound->spoutactive) { /* results now in spout? */ - memset(csound->spout, 0, csound->nspout * sizeof(MYFLT)); - } - csound->spoutran(csound); /* send to audio_out */ - return 0; - } - PUBLIC int csoundPerformKsmps(CSOUND *csound) - { - int done; +PUBLIC int csoundPerformKsmps(CSOUND *csound) +{ + int done; + + /* VL: 1.1.13 if not compiled (csoundStart() not called) */ + if (UNLIKELY(!(csound->engineStatus & CS_STATE_COMP))) { + csound->Warning(csound, + Str("Csound not ready for performance: csoundStart() " + "has not been called \n")); + return CSOUND_ERROR; + } + if (csound->jumpset == 0) { int returnValue; + csound->jumpset = 1; /* setup jmp for return after an exit() */ - if ((returnValue = setjmp(csound->exitjmp))) { -#ifndef MACOSX - csoundMessage(csound, Str("Early return from csoundPerformKsmps().\n")); -#endif + if (UNLIKELY((returnValue = setjmp(csound->exitjmp)))) return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + csoundLockMutex(csound->API_lock); + do { + done = sensevents(csound); + if (UNLIKELY(done)) { + csoundUnlockMutex(csound->API_lock); + csoundMessage(csound, Str("Score finished in csoundPerformKsmps().\n")); + return done; } - do { - if (UNLIKELY((done = sensevents(csound)))) { - csoundMessage(csound, Str("Score finished in csoundPerformKsmps().\n")); - return done; - } - } while (kperf(csound)); + } while (kperf(csound)); + csoundUnlockMutex(csound->API_lock); return 0; - } +} - PUBLIC int csoundPerformKsmpsAbsolute(CSOUND *csound) - { - int done = 0; - int returnValue; - /* setup jmp for return after an exit() */ - if ((returnValue = setjmp(csound->exitjmp))) { +static int csoundPerformKsmpsInternal(CSOUND *csound) +{ + int done; + int returnValue; + + /* VL: 1.1.13 if not compiled (csoundStart() not called) */ + if (UNLIKELY(!(csound->engineStatus & CS_STATE_COMP))) { + csound->Warning(csound, + Str("Csound not ready for performance: csoundStart() " + "has not been called \n")); + return CSOUND_ERROR; + } + /* setup jmp for return after an exit() */ + if (UNLIKELY((returnValue = setjmp(csound->exitjmp)))) { #ifndef MACOSX - csoundMessage(csound, Str("Early return from csoundPerformKsmps().\n")); + csoundMessage(csound, Str("Early return from csoundPerformKsmps().\n")); #endif - return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + do { + if ((done = sensevents(csound))) { + csoundMessage(csound, Str("Score finished in csoundPerformKsmps().\n")); + return done; } - do { - done |= sensevents(csound); - } while (kperf(csound)); - return done; - } - - /* external host's outbuffer passed in csoundPerformBuffer() */ + } while (kperf(csound)); + return 0; +} - PUBLIC int csoundPerformBuffer(CSOUND *csound) - { - int returnValue; - int done; - /* Setup jmp for return after an exit(). */ - if ((returnValue = setjmp(csound->exitjmp))) { +/* external host's outbuffer passed in csoundPerformBuffer() */ +PUBLIC int csoundPerformBuffer(CSOUND *csound) +{ + int returnValue; + int done; + /* VL: 1.1.13 if not compiled (csoundStart() not called) */ + if (UNLIKELY(!(csound->engineStatus & CS_STATE_COMP))) { + csound->Warning(csound, + Str("Csound not ready for performance: csoundStart() " + "has not been called \n")); + return CSOUND_ERROR; + } + /* Setup jmp for return after an exit(). */ + if (UNLIKELY((returnValue = setjmp(csound->exitjmp)))) { #ifndef MACOSX - csoundMessage(csound, Str("Early return from csoundPerformBuffer().\n")); + csoundMessage(csound, Str("Early return from csoundPerformBuffer().\n")); #endif - return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); - } - csound->sampsNeeded += csound->oparms_.outbufsamps; - while (csound->sampsNeeded > 0) { - do { - if (UNLIKELY((done = sensevents(csound)))) - return done; - } while (kperf(csound)); - csound->sampsNeeded -= csound->nspout; - } - return 0; - } + return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + csound->sampsNeeded += csound->oparms_.outbufsamps; + while (csound->sampsNeeded > 0) { + csoundLockMutex(csound->API_lock); + do { + if (UNLIKELY((done = sensevents(csound)))){ + csoundLockMutex(csound->API_lock); + return done; + } + } while (kperf(csound)); + csoundUnlockMutex(csound->API_lock); + csound->sampsNeeded -= csound->nspout; + } + return 0; +} - /* perform an entire score */ +/* perform an entire score */ - PUBLIC int csoundPerform(CSOUND *csound) - { - int done; - int returnValue; - csound->performState = 0; - /* setup jmp for return after an exit() */ - if ((returnValue = setjmp(csound->exitjmp))) { +PUBLIC int csoundPerform(CSOUND *csound) +{ + int done; + int returnValue; + + /* VL: 1.1.13 if not compiled (csoundStart() not called) */ + if (UNLIKELY(!(csound->engineStatus & CS_STATE_COMP))) { + csound->Warning(csound, + Str("Csound not ready for performance: csoundStart() " + "has not been called \n")); + return CSOUND_ERROR; + } + + csound->performState = 0; + /* setup jmp for return after an exit() */ + if (UNLIKELY((returnValue = setjmp(csound->exitjmp)))) { #ifndef MACOSX - csoundMessage(csound, Str("Early return from csoundPerform().\n")); + csoundMessage(csound, Str("Early return from csoundPerform().\n")); #endif - return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); - } + return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + do { + csoundLockMutex(csound->API_lock); do { - do { - if ((done = sensevents(csound))) { - csoundMessage(csound, Str("Score finished in csoundPerform().\n")); -#ifdef PARCS - if (csound->oparms->numThreads > 1) { -#if defined(LINEAR_CACHE) || defined(HASH_CACHE) - csp_dag_cache_print(csound); -#endif - csound->multiThreadedComplete = 1; + if ((done = sensevents(csound))) { + csoundMessage(csound, Str("Score finished in csoundPerform().\n")); + csoundUnlockMutex(csound->API_lock); + if (csound->oparms->numThreads > 1) { + csound->multiThreadedComplete = 1; + csound->WaitBarrier(csound->barrier1); + } + return done; + } + } while (kperf(csound)); + csoundUnlockMutex(csound->API_lock); + } while ((unsigned char) csound->performState == (unsigned char) '\0'); + csoundMessage(csound, Str("csoundPerform(): stopped.\n")); + csound->performState = 0; + return 0; +} - csound->WaitBarrier(csound->barrier1); - } - if (csound->oparms->calculateWeights) { - /* csp_weights_dump(csound); */ - csp_weights_dump_normalised(csound); - } +/* stop a csoundPerform() running in another thread */ -#endif /* PARCS */ - return done; - } - } while (kperf(csound)); - } while ((unsigned char) csound->performState == (unsigned char) 0); - csoundMessage(csound, Str("csoundPerform(): stopped.\n")); - csound->performState = 0; - return 0; - } +PUBLIC void *csoundGetNamedGens(CSOUND *csound) +{ + return csound->namedgen; +} - /* stop a csoundPerform() running in another thread */ +PUBLIC void csoundStop(CSOUND *csound) +{ + csound->performState = -1; +} - PUBLIC void *csoundGetNamedGens(CSOUND *csound) - { - return csound->namedgen; - } +/* + * ATTRIBUTES + */ - PUBLIC void csoundStop(CSOUND *csound) - { - csound->performState = -1; - } +PUBLIC int64_t csoundGetCurrentTimeSamples(CSOUND *csound){ + return csound->icurTime; +} - /* - * ATTRIBUTES - */ - - PUBLIC MYFLT csoundGetSr(CSOUND *csound) - { - return csound->esr; - } +PUBLIC MYFLT csoundGetSr(CSOUND *csound) +{ + return csound->esr; +} - PUBLIC MYFLT csoundGetKr(CSOUND *csound) - { - return csound->ekr; - } +PUBLIC MYFLT csoundGetKr(CSOUND *csound) +{ + return csound->ekr; +} - PUBLIC int csoundGetKsmps(CSOUND *csound) - { - return csound->ksmps; - } +PUBLIC uint32_t csoundGetKsmps(CSOUND *csound) +{ + return csound->ksmps; +} - PUBLIC int csoundGetNchnls(CSOUND *csound) - { - return csound->nchnls; - } +PUBLIC uint32_t csoundGetNchnls(CSOUND *csound) +{ + return csound->nchnls; +} - PUBLIC MYFLT csoundGet0dBFS(CSOUND *csound) - { - return csound->e0dbfs; - } +PUBLIC uint32_t csoundGetNchnlsInput(CSOUND *csound) +{ + if(csound->inchnls > 0) + return (uint32_t) csound->inchnls; + else return csound->nchnls; +} - PUBLIC int csoundGetStrVarMaxLen(CSOUND *csound) - { - return csound->strVarMaxLen; - } +PUBLIC MYFLT csoundGet0dBFS(CSOUND *csound) +{ + return csound->e0dbfs; +} - PUBLIC int csoundGetSampleFormat(CSOUND *csound) - { - /* should we assume input is same as output ? */ - return csound->oparms_.outformat; - } +PUBLIC long csoundGetInputBufferSize(CSOUND *csound) +{ + return csound->oparms_.inbufsamps; +} - PUBLIC int csoundGetSampleSize(CSOUND *csound) - { - /* should we assume input is same as output ? */ - return csound->oparms_.sfsampsize; - } +PUBLIC long csoundGetOutputBufferSize(CSOUND *csound) +{ + return csound->oparms_.outbufsamps; +} - PUBLIC long csoundGetInputBufferSize(CSOUND *csound) - { - return csound->oparms_.inbufsamps; - } +PUBLIC MYFLT *csoundGetSpin(CSOUND *csound) +{ + return csound->spin; +} - PUBLIC long csoundGetOutputBufferSize(CSOUND *csound) - { - return csound->oparms_.outbufsamps; - } +PUBLIC void csoundAddSpinSample(CSOUND *csound, int frame, + int channel, MYFLT sample) +{ - PUBLIC MYFLT *csoundGetSpin(CSOUND *csound) - { - return csound->spin; - } + int index = (frame * csound->inchnls) + channel; + csound->spin[index] += sample; +} - PUBLIC void csoundAddSpinSample(CSOUND *csound, int frame, - int channel, MYFLT sample) - { +PUBLIC MYFLT *csoundGetSpout(CSOUND *csound) +{ + return csound->spout; +} - int index = (frame * csound->inchnls) + channel; - csound->spin[index] += sample; - } +PUBLIC MYFLT csoundGetSpoutSample(CSOUND *csound, int frame, int channel) +{ + int index = (frame * csound->nchnls) + channel; + return csound->spout[index]; +} - PUBLIC MYFLT *csoundGetSpout(CSOUND *csound) - { - return csound->spout; - } +PUBLIC const char *csoundGetOutputName(CSOUND *csound) +{ + return (const char*) csound->oparms_.outfilename; +} - PUBLIC MYFLT csoundGetSpoutSample(CSOUND *csound, int frame, int channel) - { - int index = (frame * csound->nchnls) + channel; - return csound->spout[index]; - } +/** + * Calling this function with a non-zero will disable all default + * handling of sound I/O by the Csound library, allowing the host + * application to use the spin/spout/input/output buffers directly. + * If 'bufSize' is greater than zero, the buffer size (-b) will be + * set to the integer multiple of ksmps that is nearest to the value + * specified. + */ - PUBLIC const char *csoundGetOutputFileName(CSOUND *csound) - { - return (const char*) csound->oparms_.outfilename; - } +PUBLIC void csoundSetHostImplementedAudioIO(CSOUND *csound, + int state, int bufSize) +{ + csound->enableHostImplementedAudioIO = state; + csound->hostRequestedBufferSize = (bufSize > 0 ? bufSize : 0); +} - /** - * Calling this function with a non-zero 'state' value between - * csoundPreCompile() and csoundCompile() will disable all default - * handling of sound I/O by the Csound library, allowing the host - * application to use the spin/spout/input/output buffers directly. - * If 'bufSize' is greater than zero, the buffer size (-b) will be - * set to the integer multiple of ksmps that is nearest to the value - * specified. - */ - - PUBLIC void csoundSetHostImplementedAudioIO(CSOUND *csound, - int state, int bufSize) - { - csound->enableHostImplementedAudioIO = state; - csound->hostRequestedBufferSize = (bufSize > 0 ? bufSize : 0); - } +PUBLIC void csoundSetHostImplementedMIDIIO(CSOUND *csound, + int state) +{ + csound->enableHostImplementedMIDIIO = state; +} - PUBLIC double csoundGetScoreTime(CSOUND *csound) - { - return (double)csound->icurTime/csound->esr; - } +PUBLIC double csoundGetScoreTime(CSOUND *csound) +{ + return (double)csound->icurTime/csound->esr; +} - /* - * SCORE HANDLING - */ - - PUBLIC int csoundIsScorePending(CSOUND *csound) - { - return csound->csoundIsScorePending_; - } +/* + * SCORE HANDLING + */ - PUBLIC void csoundSetScorePending(CSOUND *csound, int pending) - { - csound->csoundIsScorePending_ = pending; - } +PUBLIC int csoundIsScorePending(CSOUND *csound) +{ + return csound->csoundIsScorePending_; +} - PUBLIC void csoundSetScoreOffsetSeconds(CSOUND *csound, MYFLT offset) - { - double aTime; - MYFLT prv = (MYFLT) csound->csoundScoreOffsetSeconds_; +PUBLIC void csoundSetScorePending(CSOUND *csound, int pending) +{ + csound->csoundIsScorePending_ = pending; +} - csound->csoundScoreOffsetSeconds_ = offset; - if (offset < FL(0.0)) - return; - /* if csoundCompile() was not called yet, just store the offset */ - if (!(csound->engineState & CS_STATE_COMP)) - return; - /* otherwise seek to the requested time now */ - aTime = (double) offset - (csound->icurTime/csound->esr); - if (aTime < 0.0 || offset < prv) { - csoundRewindScore(csound); /* will call csoundSetScoreOffsetSeconds */ - return; - } - if (aTime > 0.0) { - EVTBLK evt; - evt.strarg = NULL; - evt.opcod = 'a'; - evt.pcnt = 3; - evt.p[2] = evt.p[1] = FL(0.0); - evt.p[3] = (MYFLT) aTime; - insert_score_event_at_sample(csound, &evt, csound->icurTime); - } - } +PUBLIC void csoundSetScoreOffsetSeconds(CSOUND *csound, MYFLT offset) +{ + double aTime; + MYFLT prv = (MYFLT) csound->csoundScoreOffsetSeconds_; - PUBLIC MYFLT csoundGetScoreOffsetSeconds(CSOUND *csound) - { - return csound->csoundScoreOffsetSeconds_; - } + csound->csoundScoreOffsetSeconds_ = offset; + if (offset < FL(0.0)) + return; + /* if csoundCompile() was not called yet, just store the offset */ + if (!(csound->engineStatus & CS_STATE_COMP)) + return; + /* otherwise seek to the requested time now */ + aTime = (double) offset - (csound->icurTime/csound->esr); + if (aTime < 0.0 || offset < prv) { + csoundRewindScore(csound); /* will call csoundSetScoreOffsetSeconds */ + return; + } + if (aTime > 0.0) { + EVTBLK evt; + memset(&evt, 0, sizeof(EVTBLK)); + evt.strarg = NULL; evt.scnt = 0; + evt.opcod = 'a'; + evt.pcnt = 3; + evt.p[2] = evt.p[1] = FL(0.0); + evt.p[3] = (MYFLT) aTime; + insert_score_event_at_sample(csound, &evt, csound->icurTime); + } +} - extern void musmon_rewind_score(CSOUND *csound); /* musmon.c */ - extern void midifile_rewind_score(CSOUND *csound); /* midifile.c */ +PUBLIC MYFLT csoundGetScoreOffsetSeconds(CSOUND *csound) +{ + return csound->csoundScoreOffsetSeconds_; +} - PUBLIC void csoundRewindScore(CSOUND *csound) - { - musmon_rewind_score(csound); - midifile_rewind_score(csound); - } +extern void musmon_rewind_score(CSOUND *csound); /* musmon.c */ +extern void midifile_rewind_score(CSOUND *csound); /* midifile.c */ - PUBLIC void csoundSetCscoreCallback(CSOUND *p, - void (*cscoreCallback)(CSOUND *)) - { - p->cscoreCallback_ = (cscoreCallback != NULL ? cscoreCallback : cscore_); - } +PUBLIC void csoundRewindScore(CSOUND *csound) +{ + musmon_rewind_score(csound); + midifile_rewind_score(csound); +} - static void csoundDefaultMessageCallback(CSOUND *csound, int attr, - const char *format, va_list args) - { -#if defined(WIN32) || defined(MAC) - switch (attr & CSOUNDMSG_TYPE_MASK) { - case CSOUNDMSG_ERROR: - case CSOUNDMSG_WARNING: - case CSOUNDMSG_REALTIME: - vfprintf(stderr, format, args); - break; - default: - vfprintf(stdout, format, args); - } +PUBLIC void csoundSetCscoreCallback(CSOUND *p, + void (*cscoreCallback)(CSOUND *)) +{ + p->cscoreCallback_ = (cscoreCallback != NULL ? cscoreCallback : cscore_); +} + +static void csoundDefaultMessageCallback(CSOUND *csound, int attr, + const char *format, va_list args) +{ +#if defined(WIN32) + switch (attr & CSOUNDMSG_TYPE_MASK) { + case CSOUNDMSG_ERROR: + case CSOUNDMSG_WARNING: + case CSOUNDMSG_REALTIME: + vfprintf(stderr, format, args); + break; + default: + vfprintf(stdout, format, args); + } #else - if (!attr || !csound->enableMsgAttr) { - vfprintf(stderr, format, args); - return; - } - if ((attr & CSOUNDMSG_TYPE_MASK) == CSOUNDMSG_ORCH) + if (!attr || !csound->enableMsgAttr) { + vfprintf(stderr, format, args); + return; + } + if ((attr & CSOUNDMSG_TYPE_MASK) == CSOUNDMSG_ORCH) if (attr & CSOUNDMSG_BG_COLOR_MASK) fprintf(stderr, "\033[4%cm", ((attr & 0x70) >> 4) + '0'); - if (attr & CSOUNDMSG_FG_ATTR_MASK) { - if (attr & CSOUNDMSG_FG_BOLD) - fprintf(stderr, "\033[1m"); - if (attr & CSOUNDMSG_FG_UNDERLINE) - fprintf(stderr, "\033[4m"); - } - if (attr & CSOUNDMSG_FG_COLOR_MASK) - fprintf(stderr, "\033[3%cm", (attr & 7) + '0'); - vfprintf(stderr, format, args); - fprintf(stderr, "\033[m"); + if (attr & CSOUNDMSG_FG_ATTR_MASK) { + if (attr & CSOUNDMSG_FG_BOLD) + fprintf(stderr, "\033[1m"); + if (attr & CSOUNDMSG_FG_UNDERLINE) + fprintf(stderr, "\033[4m"); + } + if (attr & CSOUNDMSG_FG_COLOR_MASK) + fprintf(stderr, "\033[3%cm", (attr & 7) + '0'); + vfprintf(stderr, format, args); + fprintf(stderr, "\033[m"); #endif - } +} - PUBLIC void csoundSetMessageCallback(CSOUND *csound, - void (*csoundMessageCallback)(CSOUND *csound, - int attr, - const char *format, - va_list args)) - { - /* Protect against a null callback. */ - if (csoundMessageCallback) { - csound->csoundMessageCallback_ = csoundMessageCallback; - } else { - csound->csoundMessageCallback_ = csoundDefaultMessageCallback; - } - } +PUBLIC void csoundSetDefaultMessageCallback( + void (*csoundMessageCallback)(CSOUND *csound, + int attr, + const char *format, + va_list args)) +{ + if (csoundMessageCallback) { + msgcallback_ = csoundMessageCallback; + } else { + msgcallback_ = csoundDefaultMessageCallback; + } +} - PUBLIC void csoundMessageV(CSOUND *csound, - int attr, const char *format, va_list args) - { - csound->csoundMessageCallback_(csound, attr, format, args); - } +PUBLIC void csoundSetMessageCallback(CSOUND *csound, + void (*csoundMessageCallback)(CSOUND *csound, + int attr, + const char *format, + va_list args)) +{ + /* Protect against a null callback. */ + if (csoundMessageCallback) { + csound->csoundMessageCallback_ = csoundMessageCallback; + } else { + csound->csoundMessageCallback_ = csoundDefaultMessageCallback; + } +} - PUBLIC void csoundMessage(CSOUND *csound, const char *format, ...) - { - va_list args; - va_start(args, format); - csound->csoundMessageCallback_(csound, 0, format, args); - va_end(args); - } +PUBLIC void csoundMessageV(CSOUND *csound, + int attr, const char *format, va_list args) +{ + csound->csoundMessageCallback_(csound, attr, format, args); +} - PUBLIC void csoundMessageS(CSOUND *csound, int attr, const char *format, ...) - { - va_list args; - va_start(args, format); - csound->csoundMessageCallback_(csound, attr, format, args); - va_end(args); - } +PUBLIC void csoundMessage(CSOUND *csound, const char *format, ...) +{ + va_list args; + va_start(args, format); + csound->csoundMessageCallback_(csound, 0, format, args); + va_end(args); +} - void csoundDie(CSOUND *csound, const char *msg, ...) - { - va_list args; - va_start(args, msg); - csound->ErrMsgV(csound, (char*) 0, msg, args); - va_end(args); - csound->perferrcnt++; - csound->LongJmp(csound, 1); - } +PUBLIC void csoundMessageS(CSOUND *csound, int attr, const char *format, ...) +{ + va_list args; + va_start(args, format); + csound->csoundMessageCallback_(csound, attr, format, args); + va_end(args); +} - void csoundWarning(CSOUND *csound, const char *msg, ...) - { - va_list args; - if (!(csound->oparms_.msglevel & WARNMSG)) - return; - csoundMessageS(csound, CSOUNDMSG_WARNING, Str("WARNING: ")); - va_start(args, msg); - csound->csoundMessageCallback_(csound, CSOUNDMSG_WARNING, msg, args); - va_end(args); - csoundMessageS(csound, CSOUNDMSG_WARNING, "\n"); - } +void csoundDie(CSOUND *csound, const char *msg, ...) +{ + va_list args; + va_start(args, msg); + csound->ErrMsgV(csound, (char*) 0, msg, args); + va_end(args); + csound->perferrcnt++; + csound->LongJmp(csound, 1); +} - void csoundDebugMsg(CSOUND *csound, const char *msg, ...) - { - va_list args; - if (!(csound->oparms_.odebug)) - return; - va_start(args, msg); - csound->csoundMessageCallback_(csound, 0, msg, args); - va_end(args); - csoundMessage(csound, "\n"); - } +void csoundWarning(CSOUND *csound, const char *msg, ...) +{ + va_list args; + if (!(csound->oparms_.msglevel & WARNMSG)) + return; + csoundMessageS(csound, CSOUNDMSG_WARNING, Str("WARNING: ")); + va_start(args, msg); + csound->csoundMessageCallback_(csound, CSOUNDMSG_WARNING, msg, args); + va_end(args); + csoundMessageS(csound, CSOUNDMSG_WARNING, "\n"); +} - void csoundErrorMsg(CSOUND *csound, const char *msg, ...) - { - va_list args; - va_start(args, msg); - csound->csoundMessageCallback_(csound, CSOUNDMSG_ERROR, msg, args); - va_end(args); - csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); - } +void csoundDebugMsg(CSOUND *csound, const char *msg, ...) +{ + va_list args; + if (!(csound->oparms_.odebug)) + return; + va_start(args, msg); + csound->csoundMessageCallback_(csound, 0, msg, args); + va_end(args); + csoundMessage(csound, "\n"); +} - void csoundErrMsgV(CSOUND *csound, - const char *hdr, const char *msg, va_list args) - { - if (hdr != NULL) - csound->MessageS(csound, CSOUNDMSG_ERROR, "%s", hdr); - csound->csoundMessageCallback_(csound, CSOUNDMSG_ERROR, msg, args); - csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); - } +void csoundErrorMsg(CSOUND *csound, const char *msg, ...) +{ + va_list args; + va_start(args, msg); + csound->csoundMessageCallback_(csound, CSOUNDMSG_ERROR, msg, args); + va_end(args); + csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); +} - void csoundLongJmp(CSOUND *csound, int retval) - { - int n = CSOUND_EXITJMP_SUCCESS; - - n = (retval < 0 ? n + retval : n - retval) & (CSOUND_EXITJMP_SUCCESS - 1); - if (!n) - n = CSOUND_EXITJMP_SUCCESS; - - csound->curip = NULL; - csound->ids = NULL; - csound->pds = NULL; - csound->reinitflag = 0; - csound->tieflag = 0; - csound->perferrcnt += csound->inerrcnt; - csound->inerrcnt = 0; - csound->engineState |= CS_STATE_JMP; +void csoundErrMsgV(CSOUND *csound, + const char *hdr, const char *msg, va_list args) +{ + if (hdr != NULL) + csound->MessageS(csound, CSOUNDMSG_ERROR, hdr); + csound->csoundMessageCallback_(csound, CSOUNDMSG_ERROR, msg, args); + csound->MessageS(csound, CSOUNDMSG_ERROR, "\n"); +} - longjmp(csound->exitjmp, n); - } +void csoundLongJmp(CSOUND *csound, int retval) +{ + int n = CSOUND_EXITJMP_SUCCESS; + + n = (retval < 0 ? n + retval : n - retval) & (CSOUND_EXITJMP_SUCCESS - 1); + if (!n) + n = CSOUND_EXITJMP_SUCCESS; + + csound->curip = NULL; + csound->ids = NULL; + csound->reinitflag = 0; + csound->tieflag = 0; + csound->perferrcnt += csound->inerrcnt; + csound->inerrcnt = 0; + csound->engineStatus |= CS_STATE_JMP; - PUBLIC void csoundSetMessageLevel(CSOUND *csound, int messageLevel) - { - csound->oparms_.msglevel = messageLevel; - } + longjmp(csound->exitjmp, n); +} - PUBLIC int csoundGetMessageLevel(CSOUND *csound) - { - return csound->oparms_.msglevel; - } +PUBLIC void csoundSetMessageLevel(CSOUND *csound, int messageLevel) +{ + csound->oparms_.msglevel = messageLevel; +} - PUBLIC void csoundKeyPress(CSOUND *csound, char c) - { - csound->inChar_ = (int) ((unsigned char) c); - } +PUBLIC int csoundGetMessageLevel(CSOUND *csound) +{ + return csound->oparms_.msglevel; +} - /* - * CONTROL AND EVENTS - */ - - PUBLIC void csoundSetInputValueCallback(CSOUND *csound, - void (*inputValueCalback)(CSOUND *csound, - const char *channelName, - MYFLT *value)) - { - csound->InputValueCallback_ = inputValueCalback; - } +PUBLIC void csoundKeyPress(CSOUND *csound, char c) +{ + csound->inChar_ = (int) ((unsigned char) c); +} - PUBLIC void csoundSetOutputValueCallback(CSOUND *csound, - void (*outputValueCalback)(CSOUND *csound, - const char *channelName, - MYFLT value)) - { - csound->OutputValueCallback_ = outputValueCalback; - } +/* + * CONTROL AND EVENTS + */ - PUBLIC int csoundScoreEvent(CSOUND *csound, char type, - const MYFLT *pfields, long numFields) - { - EVTBLK evt; - int i; +PUBLIC void +csoundSetInputChannelCallback(CSOUND *csound, + channelCallback_t inputChannelCalback) +{ + csound->InputChannelCallback_ = inputChannelCalback; +} - evt.strarg = NULL; - evt.opcod = type; - evt.pcnt = (int16) numFields; - for (i = 0; i < (int) numFields; i++) /* Could be memcpy */ - evt.p[i + 1] = pfields[i]; - //memcpy(&evt.p[1],pfields, numFields*sizeof(MYFLT)); - return insert_score_event_at_sample(csound, &evt, csound->icurTime); - } +PUBLIC void +csoundSetOutputChannelCallback(CSOUND *csound, + channelCallback_t outputChannelCalback) +{ + csound->OutputChannelCallback_ = outputChannelCalback; +} - PUBLIC int csoundScoreEventAbsolute(CSOUND *csound, char type, - const MYFLT *pfields, long numFields, - double time_ofs) - { - EVTBLK evt; - int i; +PUBLIC int csoundScoreEvent(CSOUND *csound, char type, + const MYFLT *pfields, long numFields) +{ + EVTBLK evt; + int i; + int ret; + memset(&evt, 0, sizeof(EVTBLK)); + + evt.strarg = NULL; evt.scnt = 0; + evt.opcod = type; + evt.pcnt = (int16) numFields; + for (i = 0; i < (int) numFields; i++) /* Could be memcpy */ + evt.p[i + 1] = pfields[i]; + //memcpy(&evt.p[1],pfields, numFields*sizeof(MYFLT)); + csoundLockMutex(csound->API_lock); + ret = insert_score_event_at_sample(csound, &evt, csound->icurTime); + csoundUnlockMutex(csound->API_lock); + return ret; +} - evt.strarg = NULL; - evt.opcod = type; - evt.pcnt = (int16) numFields; - for (i = 0; i < (int) numFields; i++) - evt.p[i + 1] = pfields[i]; - return insert_score_event(csound, &evt, time_ofs); - } +PUBLIC int csoundScoreEventAbsolute(CSOUND *csound, char type, + const MYFLT *pfields, long numFields, + double time_ofs) +{ + EVTBLK evt; + int i; + int ret; + memset(&evt, 0, sizeof(EVTBLK)); + + evt.strarg = NULL; evt.scnt = 0; + evt.opcod = type; + evt.pcnt = (int16) numFields; + for (i = 0; i < (int) numFields; i++) + evt.p[i + 1] = pfields[i]; + csoundLockMutex(csound->API_lock); + ret = insert_score_event(csound, &evt, time_ofs); + csoundUnlockMutex(csound->API_lock); + return ret; +} - /* - * REAL-TIME AUDIO - */ - - /* dummy functions for the case when no real-time audio module is available */ - - static double *get_dummy_rtaudio_globals(CSOUND *csound) - { - double *p; +/* + * REAL-TIME AUDIO + */ +/* dummy functions for the case when no real-time audio module is available */ + +static double *get_dummy_rtaudio_globals(CSOUND *csound) +{ + double *p; + + p = (double*) csound->QueryGlobalVariable(csound, "__rtaudio_null_state"); + if (p == NULL) { + if (UNLIKELY(csound->CreateGlobalVariable(csound, "__rtaudio_null_state", + sizeof(double) * 4) != 0)) + csound->Die(csound, Str("rtdummy: failed to allocate globals")); + csound->Message(csound, Str("rtaudio: dummy module enabled\n")); p = (double*) csound->QueryGlobalVariable(csound, "__rtaudio_null_state"); - if (p == NULL) { - if (UNLIKELY(csound->CreateGlobalVariable(csound, "__rtaudio_null_state", - sizeof(double) * 4) != 0)) - csound->Die(csound, Str("rtdummy: failed to allocate globals")); - csound->Message(csound, Str("rtaudio: dummy module enabled\n")); - p = (double*) csound->QueryGlobalVariable(csound, "__rtaudio_null_state"); - } - return p; - } + } + return p; +} - static void dummy_rtaudio_timer(CSOUND *csound, double *p) - { - double timeWait; - int i; +static void dummy_rtaudio_timer(CSOUND *csound, double *p) +{ + double timeWait; + int i; + + timeWait = p[0] - csoundGetRealTime(csound->csRtClock); + i = (int) (timeWait * 1000.0 + 0.5); + if (i > 0) + csoundSleep((size_t) i); +} - timeWait = p[0] - csoundGetRealTime(csound->csRtClock); - i = (int) (timeWait * 1000.0 + 0.5); - if (i > 0) - csoundSleep((size_t) i); - } +int playopen_dummy(CSOUND *csound, const csRtAudioParams *parm) +{ + double *p; + char *s; + + /* find out if the use of dummy real-time audio functions was requested, */ + /* or an unknown plugin name was specified; the latter case is an error */ + s = (char*) csoundQueryGlobalVariable(csound, "_RTAUDIO"); + if (s != NULL && !(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0)) { + if (s[0] == '\0') + csoundErrorMsg(csound, + Str(" *** error: rtaudio module set to empty string")); + else { + // print_opcodedir_warning(csound); + csoundErrorMsg(csound, + Str(" unknown rtaudio module: '%s', using dummy module"), + s); + } + // return CSOUND_ERROR; + } + p = get_dummy_rtaudio_globals(csound); + csound->rtPlay_userdata = (void*) p; + p[0] = csound->GetRealTime(csound->csRtClock); + p[1] = 1.0 / ((double) ((int) sizeof(MYFLT) * parm->nChannels) + * (double) parm->sampleRate); + return CSOUND_SUCCESS; +} - static int playopen_dummy(CSOUND *csound, const csRtAudioParams *parm) - { - double *p; - char *s; - - /* find out if the use of dummy real-time audio functions was requested, */ - /* or an unknown plugin name was specified; the latter case is an error */ - s = (char*) csoundQueryGlobalVariable(csound, "_RTAUDIO"); - if (s != NULL && !(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || - strcmp(s, "NULL") == 0)) { - if (s[0] == '\0') - csoundErrorMsg(csound, - Str(" *** error: rtaudio module set to empty string")); - else { - print_opcodedir_warning(csound); - csoundErrorMsg(csound, - Str(" *** error: unknown rtaudio module: '%s'"), s); - } - return CSOUND_ERROR; - } - p = get_dummy_rtaudio_globals(csound); - csound->rtPlay_userdata = (void*) p; - p[0] = csound->GetRealTime(csound->csRtClock); - p[1] = 1.0 / ((double) ((int) sizeof(MYFLT) * parm->nChannels) - * (double) parm->sampleRate); - return CSOUND_SUCCESS; - } +void rtplay_dummy(CSOUND *csound, const MYFLT *outBuf, int nbytes) +{ + double *p = (double*) csound->rtPlay_userdata; + (void) outBuf; + p[0] += ((double) nbytes * p[1]); + dummy_rtaudio_timer(csound, p); +} - static void rtplay_dummy(CSOUND *csound, const MYFLT *outBuf, int nbytes) - { - double *p = (double*) csound->rtPlay_userdata; - (void) outBuf; - p[0] += ((double) nbytes * p[1]); - dummy_rtaudio_timer(csound, p); - } +int recopen_dummy(CSOUND *csound, const csRtAudioParams *parm) +{ + double *p; + char *s; + + /* find out if the use of dummy real-time audio functions was requested, */ + /* or an unknown plugin name was specified; the latter case is an error */ + s = (char*) csoundQueryGlobalVariable(csound, "_RTAUDIO"); + if (s != NULL && !(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0)) { + if (s[0] == '\0') + csoundErrorMsg(csound, + Str(" *** error: rtaudio module set to empty string")); + else { + // print_opcodedir_warning(csound); + csoundErrorMsg(csound, + Str(" unknown rtaudio module: '%s', using dummy module"), + s); + } + // return CSOUND_ERROR; + } + p = (double*) get_dummy_rtaudio_globals(csound) + 2; + csound->rtRecord_userdata = (void*) p; + p[0] = csound->GetRealTime(csound->csRtClock); + p[1] = 1.0 / ((double) ((int) sizeof(MYFLT) * parm->nChannels) + * (double) parm->sampleRate); + return CSOUND_SUCCESS; +} - static int recopen_dummy(CSOUND *csound, const csRtAudioParams *parm) - { - double *p; - char *s; - - /* find out if the use of dummy real-time audio functions was requested, */ - /* or an unknown plugin name was specified; the latter case is an error */ - s = (char*) csoundQueryGlobalVariable(csound, "_RTAUDIO"); - if (s != NULL && !(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || - strcmp(s, "NULL") == 0)) { - if (s[0] == '\0') - csoundErrorMsg(csound, - Str(" *** error: rtaudio module set to empty string")); - else { - print_opcodedir_warning(csound); - csoundErrorMsg(csound, - Str(" *** error: unknown rtaudio module: '%s'"), s); - } - return CSOUND_ERROR; - } - p = (double*) get_dummy_rtaudio_globals(csound) + 2; - csound->rtRecord_userdata = (void*) p; - p[0] = csound->GetRealTime(csound->csRtClock); - p[1] = 1.0 / ((double) ((int) sizeof(MYFLT) * parm->nChannels) - * (double) parm->sampleRate); - return CSOUND_SUCCESS; - } +int rtrecord_dummy(CSOUND *csound, MYFLT *inBuf, int nbytes) +{ + double *p = (double*) csound->rtRecord_userdata; + + /* for (i = 0; i < (nbytes / (int) sizeof(MYFLT)); i++) */ + /* ((MYFLT*) inBuf)[i] = FL(0.0); */ + memset(inBuf, 0, nbytes); - static int rtrecord_dummy(CSOUND *csound, MYFLT *inBuf, int nbytes) - { - double *p = (double*) csound->rtRecord_userdata; - - /* for (i = 0; i < (nbytes / (int) sizeof(MYFLT)); i++) */ - /* ((MYFLT*) inBuf)[i] = FL(0.0); */ - memset(inBuf, 0, nbytes); + p[0] += ((double) nbytes * p[1]); + dummy_rtaudio_timer(csound, p); - p[0] += ((double) nbytes * p[1]); - dummy_rtaudio_timer(csound, p); + return nbytes; +} - return nbytes; - } +void rtclose_dummy(CSOUND *csound) +{ + csound->rtPlay_userdata = NULL; + csound->rtRecord_userdata = NULL; +} - static void rtclose_dummy(CSOUND *csound) - { - csound->rtPlay_userdata = NULL; - csound->rtRecord_userdata = NULL; - } +int audio_dev_list_dummy(CSOUND *csound, + CS_AUDIODEVICE *list, int isOutput) +{ + IGN(csound); IGN(list); IGN(isOutput); + return 0; +} - PUBLIC void csoundSetPlayopenCallback(CSOUND *csound, - int (*playopen__)(CSOUND *, - const csRtAudioParams - *parm)) - { - csound->playopen_callback = playopen__; - } +int midi_dev_list_dummy(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput){ + IGN(csound); IGN(list); IGN(isOutput); + return 0; +} - PUBLIC void csoundSetRtplayCallback(CSOUND *csound, - void (*rtplay__)(CSOUND *, - const MYFLT *outBuf, - int nbytes)) - { - csound->rtplay_callback = rtplay__; - } +PUBLIC void csoundSetPlayopenCallback(CSOUND *csound, + int (*playopen__)(CSOUND *, + const csRtAudioParams + *parm)) +{ + csound->playopen_callback = playopen__; +} - PUBLIC void csoundSetRecopenCallback(CSOUND *csound, - int (*recopen__)(CSOUND *, - const csRtAudioParams *parm)) - { - csound->recopen_callback = recopen__; - } +PUBLIC void csoundSetRtplayCallback(CSOUND *csound, + void (*rtplay__)(CSOUND *, + const MYFLT *outBuf, + int nbytes)) +{ + csound->rtplay_callback = rtplay__; +} - PUBLIC void csoundSetRtrecordCallback(CSOUND *csound, - int (*rtrecord__)(CSOUND *, - MYFLT *inBuf, - int nbytes)) - { - csound->rtrecord_callback = rtrecord__; - } +PUBLIC void csoundSetRecopenCallback(CSOUND *csound, + int (*recopen__)(CSOUND *, + const csRtAudioParams *parm)) +{ + csound->recopen_callback = recopen__; +} - PUBLIC void csoundSetRtcloseCallback(CSOUND *csound, - void (*rtclose__)(CSOUND *)) - { - csound->rtclose_callback = rtclose__; - } +PUBLIC void csoundSetRtrecordCallback(CSOUND *csound, + int (*rtrecord__)(CSOUND *, + MYFLT *inBuf, + int nbytes)) +{ + csound->rtrecord_callback = rtrecord__; +} - /* dummy real time MIDI functions */ +PUBLIC void csoundSetRtcloseCallback(CSOUND *csound, + void (*rtclose__)(CSOUND *)) +{ + csound->rtclose_callback = rtclose__; +} - static int DummyMidiInOpen(CSOUND *csound, void **userData, - const char *devName) - { - char *s; - - (void) devName; - *userData = NULL; - s = (char*) csoundQueryGlobalVariable(csound, "_RTMIDI"); - if (s == NULL || - (strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || - strcmp(s, "NULL") == 0)) { - csoundMessage(csound, Str("WARNING: real time midi input disabled, " - "using dummy functions\n")); - return 0; - } - if (s[0] == '\0') - csoundErrorMsg(csound, Str("error: -+rtmidi set to empty string")); - else { - print_opcodedir_warning(csound); - csoundErrorMsg(csound, Str("error: -+rtmidi='%s': unknown module"), s); - } - return -1; - } +PUBLIC void csoundSetAudioDeviceListCallback(CSOUND *csound, + int (*audiodevlist__)(CSOUND *, CS_AUDIODEVICE *list, int isOutput)) +{ + csound->audio_dev_list_callback = audiodevlist__; +} - static int DummyMidiRead(CSOUND *csound, void *userData, - unsigned char *buf, int nbytes) - { - (void) csound; - (void) userData; - (void) buf; - (void) nbytes; +PUBLIC void csoundSetMIDIDeviceListCallback(CSOUND *csound, + int (*mididevlist__)(CSOUND *, CS_MIDIDEVICE *list, int isOutput)) +{ + csound->midi_dev_list_callback = mididevlist__; +} + +PUBLIC int csoundGetAudioDevList(CSOUND *csound, + CS_AUDIODEVICE *list, int isOutput){ + return csound->audio_dev_list_callback(csound,list,isOutput); +} + +PUBLIC int csoundGetMIDIDevList(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput) +{ + return csound->midi_dev_list_callback(csound,list,isOutput); +} + + +/* dummy real time MIDI functions */ +int DummyMidiInOpen(CSOUND *csound, void **userData, + const char *devName) +{ + char *s; + + (void) devName; + *userData = NULL; + s = (char*) csoundQueryGlobalVariable(csound, "_RTMIDI"); + if (s == NULL || + (strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0)) { + csoundMessage(csound, Str("WARNING: real time midi input disabled, " + "using dummy functions\n")); return 0; - } + } + if (s[0] == '\0') + csoundErrorMsg(csound, Str("error: -+rtmidi set to empty string")); + else { + print_opcodedir_warning(csound); + csoundErrorMsg(csound, Str("error: -+rtmidi='%s': unknown module"), s); + } + return -1; +} - static int DummyMidiOutOpen(CSOUND *csound, void **userData, - const char *devName) - { - char *s; - - (void) devName; - *userData = NULL; - s = (char*) csoundQueryGlobalVariable(csound, "_RTMIDI"); - if (s == NULL || - (strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || - strcmp(s, "NULL") == 0)) { - csoundMessage(csound, Str("WARNING: real time midi output disabled, " - "using dummy functions\n")); - return 0; - } - if (s[0] == '\0') - csoundErrorMsg(csound, Str("error: -+rtmidi set to empty string")); - else { - print_opcodedir_warning(csound); - csoundErrorMsg(csound, Str("error: -+rtmidi='%s': unknown module"), s); - } - return -1; - } +int DummyMidiRead(CSOUND *csound, void *userData, + unsigned char *buf, int nbytes) +{ + (void) csound; + (void) userData; + (void) buf; + (void) nbytes; + return 0; +} - static int DummyMidiWrite(CSOUND *csound, void *userData, - const unsigned char *buf, int nbytes) - { - (void) csound; - (void) userData; - (void) buf; - return nbytes; - } +int DummyMidiOutOpen(CSOUND *csound, void **userData, + const char *devName) +{ + char *s; + + (void) devName; + *userData = NULL; + s = (char*) csoundQueryGlobalVariable(csound, "_RTMIDI"); + if (s == NULL || + (strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0)) { + csoundMessage(csound, Str("WARNING: real time midi output disabled, " + "using dummy functions\n")); + return 0; + } + if (s[0] == '\0') + csoundErrorMsg(csound, Str("error: -+rtmidi set to empty string")); + else { + print_opcodedir_warning(csound); + csoundErrorMsg(csound, Str("error: -+rtmidi='%s': unknown module"), s); + } + return -1; +} - static const char *midi_err_msg = Str_noop("Unknown MIDI error"); +int DummyMidiWrite(CSOUND *csound, void *userData, + const unsigned char *buf, int nbytes) +{ + (void) csound; + (void) userData; + (void) buf; + return nbytes; +} - /** - * Returns pointer to a string constant storing an error massage - * for error code 'errcode'. - */ - const char *csoundExternalMidiErrorString(CSOUND *csound, int errcode) - { - if (csound->midiGlobals->MidiErrorStringCallback == NULL) - return midi_err_msg; - return (csound->midiGlobals->MidiErrorStringCallback(errcode)); - } +static const char *midi_err_msg = Str_noop("Unknown MIDI error"); - /* Set real time MIDI function pointers. */ +/** + * Returns pointer to a string constant storing an error massage + * for error code 'errcode'. + */ +const char *csoundExternalMidiErrorString(CSOUND *csound, int errcode) +{ + if (csound->midiGlobals->MidiErrorStringCallback == NULL) + return midi_err_msg; + return (csound->midiGlobals->MidiErrorStringCallback(errcode)); +} - PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *csound, - int (*func)(CSOUND *, - void **, - const char *)) - { - csound->midiGlobals->MidiInOpenCallback = func; - } +/* Set real time MIDI function pointers. */ - PUBLIC void csoundSetExternalMidiReadCallback(CSOUND *csound, +PUBLIC void csoundSetExternalMidiInOpenCallback(CSOUND *csound, int (*func)(CSOUND *, - void *, - unsigned char *, int)) - { - csound->midiGlobals->MidiReadCallback = func; - } + void **, + const char *)) +{ + csound->midiGlobals->MidiInOpenCallback = func; +} - PUBLIC void csoundSetExternalMidiInCloseCallback(CSOUND *csound, - int (*func)(CSOUND *, void *)) - { - csound->midiGlobals->MidiInCloseCallback = func; - } +PUBLIC void csoundSetExternalMidiReadCallback(CSOUND *csound, + int (*func)(CSOUND *, + void *, + unsigned char *, int)) +{ + csound->midiGlobals->MidiReadCallback = func; +} - PUBLIC void csoundSetExternalMidiOutOpenCallback(CSOUND *csound, - int (*func)(CSOUND *, - void **, - const char *)) - { - csound->midiGlobals->MidiOutOpenCallback = func; - } +PUBLIC void csoundSetExternalMidiInCloseCallback(CSOUND *csound, + int (*func)(CSOUND *, void *)) +{ + csound->midiGlobals->MidiInCloseCallback = func; +} - PUBLIC void csoundSetExternalMidiWriteCallback(CSOUND *csound, +PUBLIC void csoundSetExternalMidiOutOpenCallback(CSOUND *csound, int (*func)(CSOUND *, - void *, - const unsigned char *, - int)) - { - csound->midiGlobals->MidiWriteCallback = func; - } + void **, + const char *)) +{ + csound->midiGlobals->MidiOutOpenCallback = func; +} - PUBLIC void csoundSetExternalMidiOutCloseCallback(CSOUND *csound, - int (*func)(CSOUND *, void *)) - { - csound->midiGlobals->MidiOutCloseCallback = func; - } +PUBLIC void csoundSetExternalMidiWriteCallback(CSOUND *csound, + int (*func)(CSOUND *, + void *, + const unsigned char *, + int)) +{ + csound->midiGlobals->MidiWriteCallback = func; +} - PUBLIC void csoundSetExternalMidiErrorStringCallback(CSOUND *csound, - const char *(*func)(int)) - { - csound->midiGlobals->MidiErrorStringCallback = func; - } +PUBLIC void csoundSetExternalMidiOutCloseCallback(CSOUND *csound, + int (*func)(CSOUND *, void *)) +{ + csound->midiGlobals->MidiOutCloseCallback = func; +} - /* - * FUNCTION TABLE DISPLAY. - */ - - PUBLIC int csoundSetIsGraphable(CSOUND *csound, int isGraphable) - { - int prv = csound->isGraphable_; - csound->isGraphable_ = isGraphable; - return prv; - } +PUBLIC void csoundSetExternalMidiErrorStringCallback(CSOUND *csound, + const char *(*func)(int)) +{ + csound->midiGlobals->MidiErrorStringCallback = func; +} - PUBLIC void csoundSetMakeGraphCallback(CSOUND *csound, - void (*makeGraphCB)(CSOUND *csound, - WINDAT *windat, - const char *name)) - { - csound->csoundMakeGraphCallback_ = makeGraphCB; - } +/* + * FUNCTION TABLE DISPLAY. + */ - PUBLIC void csoundSetDrawGraphCallback(CSOUND *csound, - void (*drawGraphCallback)(CSOUND *csound, - WINDAT *windat)) - { - csound->csoundDrawGraphCallback_ = drawGraphCallback; - } +PUBLIC int csoundSetIsGraphable(CSOUND *csound, int isGraphable) +{ + int prv = csound->isGraphable_; + csound->isGraphable_ = isGraphable; + return prv; +} - PUBLIC void csoundSetKillGraphCallback(CSOUND *csound, - void (*killGraphCallback)(CSOUND *csound, - WINDAT *windat)) - { - csound->csoundKillGraphCallback_ = killGraphCallback; - } +PUBLIC void csoundSetMakeGraphCallback(CSOUND *csound, + void (*makeGraphCB)(CSOUND *csound, + WINDAT *windat, + const char *name)) +{ + csound->csoundMakeGraphCallback_ = makeGraphCB; +} - static int defaultCsoundExitGraph(CSOUND *csound) - { - (void) csound; - return CSOUND_SUCCESS; - } +PUBLIC void csoundSetDrawGraphCallback(CSOUND *csound, + void (*drawGraphCallback)(CSOUND *csound, + WINDAT *windat)) +{ + csound->csoundDrawGraphCallback_ = drawGraphCallback; +} - PUBLIC void csoundSetExitGraphCallback(CSOUND *csound, - int (*exitGraphCallback)(CSOUND *)) - { - csound->csoundExitGraphCallback_ = exitGraphCallback; - } +PUBLIC void csoundSetKillGraphCallback(CSOUND *csound, + void (*killGraphCallback)(CSOUND *csound, + WINDAT *windat)) +{ + csound->csoundKillGraphCallback_ = killGraphCallback; +} - static void defaultCsoundMakeXYin(CSOUND *csound, - XYINDAT *xyindat, MYFLT x, MYFLT y) - { - (void) x; - (void) y; - memset(xyindat, 0, sizeof(XYINDAT)); - csoundWarning(csound, - Str("xyin not supported. use invalue opcode instead.")); - } - static void defaultCsoundReadKillXYin(CSOUND *csound, XYINDAT *xyindat) - { - (void) csound; - (void) xyindat; - } +PUBLIC void csoundSetExitGraphCallback(CSOUND *csound, + int (*exitGraphCallback)(CSOUND *)) +{ + csound->csoundExitGraphCallback_ = exitGraphCallback; +} - PUBLIC void csoundSetMakeXYinCallback(CSOUND *csound, - void (*makeXYinCallback)(CSOUND *, - XYINDAT *xyindat, - MYFLT x, - MYFLT y)) - { - csound->csoundMakeXYinCallback_ = makeXYinCallback; - } +/* + * OPCODES + */ - PUBLIC void csoundSetReadXYinCallback(CSOUND *csound, - void (*readXYinCallback)(CSOUND *, - XYINDAT *xyindat)) - { - csound->csoundReadXYinCallback_ = readXYinCallback; - } +static CS_NOINLINE int opcode_list_new_oentry(CSOUND *csound, + const OENTRY *ep) +{ + CONS_CELL *head; + OENTRY *entryCopy; + char *shortName; + + if (ep->opname == NULL || csound->opcodes == NULL) + return CSOUND_ERROR; + + shortName = get_opcode_short_name(csound, ep->opname); + + head = cs_hash_table_get(csound, csound->opcodes, shortName); + entryCopy = mmalloc(csound, sizeof(OENTRY)); + memcpy(entryCopy, ep, sizeof(OENTRY)); + entryCopy->useropinfo = NULL; + + if (head != NULL) { + cs_cons_append(head, cs_cons(csound, entryCopy, NULL)); + } else { + head = cs_cons(csound, entryCopy, NULL); + cs_hash_table_put(csound, csound->opcodes, shortName, head); + } + + if (shortName != ep->opname) { + mfree(csound, shortName); + } + return 0; +} - PUBLIC void csoundSetKillXYinCallback(CSOUND *csound, - void (*killXYinCallback)(CSOUND *, - XYINDAT *xyindat)) - { - csound->csoundKillXYinCallback_ = killXYinCallback; - } +PUBLIC int csoundAppendOpcode(CSOUND *csound, + const char *opname, int dsblksiz, int flags, + int thread, const char *outypes, const char *intypes, + int (*iopadr)(CSOUND *, void *), + int (*kopadr)(CSOUND *, void *), + int (*aopadr)(CSOUND *, void *)) +{ + OENTRY tmpEntry; + int err; + + tmpEntry.opname = (char*) opname; + tmpEntry.dsblksiz = (uint16) dsblksiz; + tmpEntry.flags = (uint16) flags; + tmpEntry.thread = (uint8_t) thread; + tmpEntry.outypes = (char*) outypes; + tmpEntry.intypes = (char*) intypes; + tmpEntry.iopadr = (SUBR) iopadr; + tmpEntry.kopadr = (SUBR) kopadr; + tmpEntry.aopadr = (SUBR) aopadr; + err = opcode_list_new_oentry(csound, &tmpEntry); + if (UNLIKELY(err)) + csoundErrorMsg(csound, Str("Failed to allocate new opcode entry.")); + return err; +} - /* - * OPCODES - */ - - static CS_NOINLINE int opcode_list_new_oentry(CSOUND *csound, - const OENTRY *ep) - { - int oldCnt = 0; - int h = 0; +/** + * Appends a list of opcodes implemented by external software to Csound's + * internal opcode list. The list should either be terminated with an entry + * that has a NULL opname, or the number of entries (> 0) should be specified + * in 'n'. Returns zero on success. + */ - if (ep->opname == NULL) - return CSOUND_ERROR; - if (ep->opname[0] != (char) 0) - h = (int) name_hash_2(csound, ep->opname); - else if (csound->opcodlst != NULL) - return CSOUND_ERROR; - if (csound->opcodlst != NULL) { - int n; - oldCnt = (int) ((OENTRY*) csound->oplstend - (OENTRY*) csound->opcodlst); - /* check if this opcode is already defined */ - n = csound->opcode_list[h]; - while (n) { - if (!sCmp(csound->opcodlst[n].opname, ep->opname)) { - int tmp = csound->opcodlst[n].prvnum; - /* redefine existing opcode */ - memcpy(&(csound->opcodlst[n]), ep, sizeof(OENTRY)); - csound->opcodlst[n].useropinfo = NULL; - csound->opcodlst[n].prvnum = tmp; - return CSOUND_SUCCESS; - } - n = csound->opcodlst[n].prvnum; - } - } - if (!(oldCnt & 0x7F)) { - OENTRY *newList; - size_t nBytes = (size_t) (oldCnt + 0x80) * sizeof(OENTRY); - if (!oldCnt) - newList = (OENTRY*) malloc(nBytes); - else - newList = (OENTRY*) realloc(csound->opcodlst, nBytes); - if (newList == NULL) - return CSOUND_MEMORY; - csound->opcodlst = newList; - csound->oplstend = ((OENTRY*) newList + (int) oldCnt); - memset(&(csound->opcodlst[oldCnt]), 0, sizeof(OENTRY) * 0x80); +int csoundAppendOpcodes(CSOUND *csound, const OENTRY *opcodeList, int n) +{ + OENTRY *ep = (OENTRY*) opcodeList; + int err, retval = 0; + + if (UNLIKELY(opcodeList == NULL)) + return -1; + if (UNLIKELY(n <= 0)) + n = 0x7FFFFFFF; + while (n && ep->opname != NULL) { + if (UNLIKELY((err = opcode_list_new_oentry(csound, ep)) != 0)) { + csoundErrorMsg(csound, Str("Failed to allocate opcode entry for %s."), + ep->opname); + retval = err; } - memcpy(&(csound->opcodlst[oldCnt]), ep, sizeof(OENTRY)); - csound->opcodlst[oldCnt].useropinfo = NULL; - csound->opcodlst[oldCnt].prvnum = csound->opcode_list[h]; - csound->opcode_list[h] = oldCnt; - csound->oplstend = (OENTRY*) csound->oplstend + (int) 1; - return 0; - } + n--, ep++; + } + return retval; +} - PUBLIC int csoundAppendOpcode(CSOUND *csound, - const char *opname, int dsblksiz, int thread, - const char *outypes, const char *intypes, - int (*iopadr)(CSOUND *, void *), - int (*kopadr)(CSOUND *, void *), - int (*aopadr)(CSOUND *, void *)) - { - OENTRY tmpEntry; - int err; - - tmpEntry.opname = (char*) opname; - tmpEntry.dsblksiz = (uint16) dsblksiz; - tmpEntry.thread = (uint16) thread; - tmpEntry.outypes = (char*) outypes; - tmpEntry.intypes = (char*) intypes; - tmpEntry.iopadr = (SUBR) iopadr; - tmpEntry.kopadr = (SUBR) kopadr; - tmpEntry.aopadr = (SUBR) aopadr; - err = opcode_list_new_oentry(csound, &tmpEntry); - if (UNLIKELY(err)) - csoundErrorMsg(csound, Str("Failed to allocate new opcode entry.")); +/* + * MISC FUNCTIONS + */ - return err; - } +int defaultCsoundYield(CSOUND *csound) +{ + (void) csound; + return 1; +} - /** - * Appends a list of opcodes implemented by external software to Csound's - * internal opcode list. The list should either be terminated with an entry - * that has a NULL opname, or the number of entries (> 0) should be specified - * in 'n'. Returns zero on success. - */ - - int csoundAppendOpcodes(CSOUND *csound, const OENTRY *opcodeList, int n) - { - OENTRY *ep = (OENTRY*) opcodeList; - int err, retval = 0; - - if (UNLIKELY(opcodeList == NULL)) - return -1; - if (UNLIKELY(n <= 0)) - n = 0x7FFFFFFF; - while (n && ep->opname != NULL) { - if (UNLIKELY((err = opcode_list_new_oentry(csound, ep)) != 0)) { - csoundErrorMsg(csound, Str("Failed to allocate opcode entry for %s."), - ep->opname); - retval = err; - } - n--, ep++; - } - return retval; - } +PUBLIC void csoundSetYieldCallback(CSOUND *csound, + int (*yieldCallback)(CSOUND *)) +{ + csound->csoundYieldCallback_ = yieldCallback; +} - /* - * MISC FUNCTIONS - */ - - int defaultCsoundYield(CSOUND *csound) - { - (void) csound; - return 1; - } +void SetInternalYieldCallback(CSOUND *csound, + int (*yieldCallback)(CSOUND *)) +{ + csound->csoundInternalYieldCallback_ = yieldCallback; +} - PUBLIC void csoundSetYieldCallback(CSOUND *csound, - int (*yieldCallback)(CSOUND *)) - { - csound->csoundYieldCallback_ = yieldCallback; - } +int csoundYield(CSOUND *csound) +{ + if (exitNow_) + csound->LongJmp(csound, CSOUND_SIGNAL); + csound->csoundInternalYieldCallback_(csound); + return csound->csoundYieldCallback_(csound); +} + +extern void csoundDeleteAllGlobalVariables(CSOUND *csound); - void SetInternalYieldCallback(CSOUND *csound, - int (*yieldCallback)(CSOUND *)) - { - csound->csoundInternalYieldCallback_ = yieldCallback; +typedef struct resetCallback_s { + void *userData; + int (*func)(CSOUND *, void *); + struct resetCallback_s *nxt; +} resetCallback_t; + + +static void reset(CSOUND *csound) +{ + CSOUND *saved_env; + void *p1, *p2; + uintptr_t length; + uintptr_t end, start; + int n = 0; + + csoundCleanup(csound); + + /* call registered reset callbacks */ + while (csound->reset_list != NULL) { + resetCallback_t *p = (resetCallback_t*) csound->reset_list; + p->func(csound, p->userData); + csound->reset_list = (void*) p->nxt; + free(p); + } + /* call local destructor routines of external modules */ + /* should check return value... */ + csoundDestroyModules(csound); + + /* IV - Feb 01 2005: clean up configuration variables and */ + /* named dynamic "global" variables of Csound instance */ + csoundDeleteAllConfigurationVariables(csound); + csoundDeleteAllGlobalVariables(csound); + +#ifdef CSCORE + cscoreRESET(csound); +#endif + if (csound->opcodes != NULL) { + free_opcode_table(csound); + csound->opcodes = NULL; + } + + csound->oparms_.odebug = 0; + /* RWD 9:2000 not terribly vital, but good to do this somewhere... */ + pvsys_release(csound); + close_all_files(csound); + /* delete temporary files created by this Csound instance */ + remove_tmpfiles(csound); + rlsmemfiles(csound); + + memRESET(csound); + + while (csound->filedir[n]) /* Clear source directory */ + free(csound->filedir[n++]); + /** + * Copy everything EXCEPT the function pointers. + * We do it by saving them and copying them back again... + * hope that this does not fail... + */ + /* VL 07.06.2013 - check if the status is COMP before + resetting. + */ + //CSOUND **self = csound->self; + saved_env = (CSOUND*) malloc(sizeof(CSOUND)); + memcpy(saved_env, csound, sizeof(CSOUND)); + memcpy(csound, &cenviron_, sizeof(CSOUND)); + end = (uintptr_t) &(csound->first_callback_); /* used to be &(csound->ids) */ + start =(uintptr_t) csound; + length = end - start; + memcpy((void*) csound, (void*) saved_env, (size_t) length); + csound->oparms = &(csound->oparms_); + csound->hostdata = saved_env->hostdata; + p1 = (void*) &(csound->first_callback_); + p2 = (void*) &(csound->last_callback_); + length = (uintptr_t) p2 - (uintptr_t) p1; + memcpy(p1, (void*) &(saved_env->first_callback_), (size_t) length); + csound->csoundCallbacks_ = saved_env->csoundCallbacks_; + csound->API_lock = saved_env->API_lock; +#ifdef HAVE_PTHREAD_SPIN_LOCK + csound->memlock = saved_env->memlock; + csound->spinlock = saved_env->spinlock; + csound->spoutlock = saved_env->spoutlock; + csound->spinlock1= saved_env->spinlock1; +#endif + csound->enableHostImplementedMIDIIO = saved_env->enableHostImplementedMIDIIO; + memcpy(&(csound->exitjmp), &(saved_env->exitjmp), sizeof(jmp_buf)); + csound->memalloc_db = saved_env->memalloc_db; + //csound->self = self; + free(saved_env); + +} + + +PUBLIC void csoundSetRTAudioModule(CSOUND *csound, char *module){ + char *s; + if((s = csoundQueryGlobalVariable(csound, "_RTAUDIO")) != NULL) + strncpy(s, module, 20); + if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0) { + csound->Message(csound, Str("setting dummy interface\n")); + csound->SetPlayopenCallback(csound, playopen_dummy); + csound->SetRecopenCallback(csound, recopen_dummy); + csound->SetRtplayCallback(csound, rtplay_dummy); + csound->SetRtrecordCallback(csound, rtrecord_dummy); + csound->SetRtcloseCallback(csound, rtclose_dummy); + csound->SetAudioDeviceListCallback(csound, audio_dev_list_dummy); + return; } + if (csoundInitModules(csound) != 0) + csound->LongJmp(csound, 1); +} + + +PUBLIC void csoundSetMIDIModule(CSOUND *csound, char *module){ + char *s; + + if((s = csoundQueryGlobalVariable(csound, "_RTMIDI")) != NULL) + strncpy(s, module, 20); + if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0) { + csound->SetMIDIDeviceListCallback(csound, midi_dev_list_dummy); + csound->SetExternalMidiInOpenCallback(csound, DummyMidiInOpen); + csound->SetExternalMidiReadCallback(csound, DummyMidiRead); + csound->SetExternalMidiInCloseCallback(csound, NULL); + csound->SetExternalMidiOutOpenCallback(csound, DummyMidiOutOpen); + csound->SetExternalMidiWriteCallback(csound, DummyMidiWrite); + csound->SetExternalMidiOutCloseCallback(csound, NULL); - int csoundYield(CSOUND *csound) - { - if (exitNow_) - csound->LongJmp(csound, CSOUND_SIGNAL); - csound->csoundInternalYieldCallback_(csound); - return csound->csoundYieldCallback_(csound); + return; } + if (csoundInitModules(csound) != 0) + csound->LongJmp(csound, 1); +} + + +PUBLIC int csoundGetModule(CSOUND *csound, int no, char **module, char **type){ + MODULE_INFO **modules = + (MODULE_INFO **) csoundQueryGlobalVariable(csound, "_MODULES"); + if(modules[no] == NULL || no >= MAX_MODULES) return CSOUND_ERROR; + *module = modules[no]->module; + *type = modules[no]->type; + return CSOUND_SUCCESS; +} + + + +PUBLIC void csoundReset(CSOUND *csound) +{ + char *s; + int i, max_len; + OPARMS *O = csound->oparms; + + #ifdef HAVE_PTHREAD_SPIN_LOCK + pthread_spin_init(&csound->spoutlock, PTHREAD_PROCESS_PRIVATE); + pthread_spin_init(&csound->spinlock, PTHREAD_PROCESS_PRIVATE); + pthread_spin_init(&csound->memlock, PTHREAD_PROCESS_PRIVATE); + pthread_spin_init(&csound->spinlock1, PTHREAD_PROCESS_PRIVATE); + #endif + + if(csound->engineStatus & CS_STATE_COMP || + csound->engineStatus & CS_STATE_PRE) { + /* and reset */ + csound->Message(csound, "resetting Csound instance\n"); + reset(csound); + /* clear compiled flag */ + csound->engineStatus |= ~(CS_STATE_COMP); + } + + if (msgcallback_ != NULL) { + csoundSetMessageCallback(csound, msgcallback_); + } + csound->printerrormessagesflag = (void*)1234; + /* copy system environment variables */ + i = csoundInitEnv(csound); + if (UNLIKELY(i != CSOUND_SUCCESS)) { + csound->engineStatus |= CS_STATE_JMP; + csound->Die(csound, Str("Failed during csoundInitEnv")); + } + csound_init_rand(csound); + + + + csound->engineState.stringPool = cs_hash_table_create(csound); + csound->engineState.constantsPool = myflt_pool_create(csound); + csound->engineStatus |= CS_STATE_PRE; + csound_aops_init_tables(csound); + create_opcode_table(csound); + /* now load and pre-initialise external modules for this instance */ + /* this function returns an error value that may be worth checking */ + { + int err = csoundInitStaticModules(csound); + if (csound->delayederrormessages && + csound->printerrormessagesflag==NULL) { + csound->Warning(csound, csound->delayederrormessages); + free(csound->delayederrormessages); + csound->delayederrormessages = NULL; + } + if (UNLIKELY(err==CSOUND_ERROR)) + csound->Die(csound, Str("Failed during csoundInitStaticModules")); + + + csoundCreateGlobalVariable(csound, "_MODULES", + (size_t) MAX_MODULES*sizeof(MODULE_INFO *)); + char *modules = (char *) csoundQueryGlobalVariable(csound, "_MODULES"); + memset(modules, 0, sizeof(MODULE_INFO *)*MAX_MODULES); + + err = csoundLoadModules(csound); + if (csound->delayederrormessages && + csound->printerrormessagesflag==NULL) { + csound->Warning(csound, csound->delayederrormessages); + free(csound->delayederrormessages); + csound->delayederrormessages = NULL; + } + if (err != CSOUND_SUCCESS) + csound->Die(csound, Str("Failed during csoundLoadModules")); + + /* VL: moved here from main.c */ + if (csoundInitModules(csound) != 0) + csound->LongJmp(csound, 1); + + init_pvsys(csound); + /* utilities depend on this as well as orchs; may get changed by an orch */ + dbfs_init(csound, DFLT_DBFS); + csound->csRtClock = (RTCLOCK*) csound->Calloc(csound, sizeof(RTCLOCK)); + csoundInitTimerStruct(csound->csRtClock); + csound->engineStatus |= /*CS_STATE_COMP |*/ CS_STATE_CLN; + +#ifndef USE_DOUBLE +#ifdef BETA + csound->Message(csound, Str("Csound version %s beta (float samples) %s\n"), + CS_PACKAGE_VERSION, __DATE__); +#else + csound->Message(csound, Str("Csound version %s (float samples) %s\n"), + CS_PACKAGE_VERSION, __DATE__); +#endif +#else +#ifdef BETA + csound->Message(csound, Str("Csound version %s beta (double samples) %s\n"), + CS_PACKAGE_VERSION, __DATE__); +#else + csound->Message(csound, Str("Csound version %s (double samples) %s\n"), + CS_PACKAGE_VERSION, __DATE__); +#endif +#endif + { + char buffer[128]; + sf_command(NULL, SFC_GET_LIB_VERSION, buffer, 128); + csound->Message(csound, "%s\n", buffer); + } + + /* do not know file type yet */ + O->filetyp = -1; + O->sfheader = 0; + csound->peakchunks = 1; + csound->typePool = csound->Calloc(csound, sizeof(TYPE_POOL)); + csound->engineState.varPool = csound->Calloc(csound, sizeof(CS_VAR_POOL)); + csoundAddStandardTypes(csound, csound->typePool); + /* csoundLoadExternals(csound); */ + } + + /* allow selecting real time audio module */ + max_len = 21; + csoundCreateGlobalVariable(csound, "_RTAUDIO", (size_t) max_len); + s = csoundQueryGlobalVariable(csound, "_RTAUDIO"); +#ifndef LINUX + strcpy(s, "PortAudio"); +#else + strcpy(s, "alsa"); +#endif + csoundCreateConfigurationVariable(csound, "rtaudio", s, CSOUNDCFG_STRING, + 0, NULL, &max_len, + Str("Real time audio module name"), NULL); + + /* initialise real time MIDI */ + csound->midiGlobals = (MGLOBAL*) mcalloc(csound, sizeof(MGLOBAL)); + csound->midiGlobals->bufp = &(csound->midiGlobals->mbuf[0]); + csound->midiGlobals->endatp = csound->midiGlobals->bufp; + csoundCreateGlobalVariable(csound, "_RTMIDI", (size_t) max_len); + csound->SetMIDIDeviceListCallback(csound, midi_dev_list_dummy); + csound->SetExternalMidiInOpenCallback(csound, DummyMidiInOpen); + csound->SetExternalMidiReadCallback(csound, DummyMidiRead); + csound->SetExternalMidiOutOpenCallback(csound, DummyMidiOutOpen); + csound->SetExternalMidiWriteCallback(csound, DummyMidiWrite); + + s = csoundQueryGlobalVariable(csound, "_RTMIDI"); + strcpy(s, "null"); + if(csound->enableHostImplementedMIDIIO == 0) +#ifndef LINUX + strcpy(s, "portmidi"); +#else + strcpy(s, "alsa"); +#endif + else strcpy(s, "hostbased"); - extern void csoundDeleteAllGlobalVariables(CSOUND *csound); + csoundCreateConfigurationVariable(csound, "rtmidi", s, CSOUNDCFG_STRING, + 0, NULL, &max_len, + Str("Real time MIDI module name"), NULL); + max_len = 256; /* should be the same as in csoundCore.h */ + csoundCreateConfigurationVariable(csound, "mute_tracks", + &(csound->midiGlobals->muteTrackList[0]), + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Ignore events (other than tempo changes)" + " in tracks defined by pattern"), + NULL); + csoundCreateConfigurationVariable(csound, "raw_controller_mode", + &(csound->midiGlobals->rawControllerMode), + CSOUNDCFG_BOOLEAN, 0, NULL, NULL, + Str("Do not handle special MIDI controllers" + " (sustain pedal etc.)"), NULL); + /* sound file tag options */ + max_len = 201; + i = (max_len + 7) & (~7); + csound->SF_id_title = (char*) mcalloc(csound, (size_t) i * (size_t) 6); + csoundCreateConfigurationVariable(csound, "id_title", csound->SF_id_title, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Title tag in output soundfile " + "(no spaces)"), NULL); + csound->SF_id_copyright = (char*) csound->SF_id_title + (int) i; + csoundCreateConfigurationVariable(csound, "id_copyright", + csound->SF_id_copyright, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Copyright tag in output soundfile" + " (no spaces)"), NULL); + csound->SF_id_software = (char*) csound->SF_id_copyright + (int) i; + csoundCreateConfigurationVariable(csound, "id_software", + csound->SF_id_software, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Software tag in output soundfile" + " (no spaces)"), NULL); + csound->SF_id_artist = (char*) csound->SF_id_software + (int) i; + csoundCreateConfigurationVariable(csound, "id_artist", csound->SF_id_artist, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Artist tag in output soundfile " + "(no spaces)"), + NULL); + csound->SF_id_comment = (char*) csound->SF_id_artist + (int) i; + csoundCreateConfigurationVariable(csound, "id_comment", + csound->SF_id_comment, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Comment tag in output soundfile" + " (no spaces)"), NULL); + csound->SF_id_date = (char*) csound->SF_id_comment + (int) i; + csoundCreateConfigurationVariable(csound, "id_date", csound->SF_id_date, + CSOUNDCFG_STRING, 0, NULL, &max_len, + Str("Date tag in output soundfile " + "(no spaces)"), + NULL); + { - typedef struct resetCallback_s { - void *userData; - int (*func)(CSOUND *, void *); - struct resetCallback_s *nxt; - } resetCallback_t; - - extern void cscoreRESET(CSOUND *); - extern void tranRESET(CSOUND *); - extern void memRESET(CSOUND *); - - PUBLIC void csoundReset(CSOUND *csound) - { - CSOUND *saved_env; - void *p1, *p2; - uintptr_t length; - int n = 0; - - csoundCleanup(csound); - - /* call registered reset callbacks */ - while (csound->reset_list != NULL) { - resetCallback_t *p = (resetCallback_t*) csound->reset_list; - p->func(csound, p->userData); - csound->reset_list = (void*) p->nxt; - free(p); - } - /* call local destructor routines of external modules */ - /* should check return value... */ - csoundDestroyModules(csound); - - /* IV - Feb 01 2005: clean up configuration variables and */ - /* named dynamic "global" variables of Csound instance */ - csoundDeleteAllConfigurationVariables(csound); - csoundDeleteAllGlobalVariables(csound); + MYFLT minValF = FL(0.0); -#ifdef CSCORE - cscoreRESET(csound); -#endif - tranRESET(csound); + csoundCreateConfigurationVariable(csound, "msg_color", + &(csound->enableMsgAttr), + CSOUNDCFG_BOOLEAN, 0, NULL, NULL, + Str("Enable message attributes " + "(colors etc.)"), + NULL); + csoundCreateConfigurationVariable(csound, "skip_seconds", + &(csound->csoundScoreOffsetSeconds_), + CSOUNDCFG_MYFLT, 0, &minValF, NULL, + Str("Start score playback at the specified" + " time, skipping earlier events"), + NULL); + } + csoundCreateConfigurationVariable(csound, "ignore_csopts", + &(csound->disable_csd_options), + CSOUNDCFG_BOOLEAN, 0, NULL, NULL, + Str("Ignore in CSD files" + " (default: no)"), NULL); - csound->oparms_.odebug = 0; - /* RWD 9:2000 not terribly vital, but good to do this somewhere... */ - pvsys_release(csound); - close_all_files(csound); - /* delete temporary files created by this Csound instance */ - remove_tmpfiles(csound); - rlsmemfiles(csound); - memRESET(csound); - while (csound->filedir[n]) /* Clear source directory */ - free(csound->filedir[n++]); - /** - * Copy everything EXCEPT the function pointers. - * We do it by saving them and copying them back again... - */ - /* hope that this does not fail... */ - saved_env = (CSOUND*) malloc(sizeof(CSOUND)); - memcpy(saved_env, csound, sizeof(CSOUND)); - memcpy(csound, &cenviron_, sizeof(CSOUND)); - length = (uintptr_t) &(csound->ids) - (uintptr_t) csound; - memcpy((void*) csound, (void*) saved_env, (size_t) length); - csound->oparms = &(csound->oparms_); - csound->hostdata = saved_env->hostdata; - p1 = (void*) &(csound->first_callback_); - p2 = (void*) &(csound->last_callback_); - length = (uintptr_t) p2 - (uintptr_t) p1; - memcpy(p1, (void*) &(saved_env->first_callback_), (size_t) length); - csound->csoundCallbacks_ = saved_env->csoundCallbacks_; - memcpy(&(csound->exitjmp), &(saved_env->exitjmp), sizeof(jmp_buf)); - csound->memalloc_db = saved_env->memalloc_db; - free(saved_env); - } +} - PUBLIC int csoundGetDebug(CSOUND *csound) - { - return csound->oparms_.odebug; - } +PUBLIC int csoundGetDebug(CSOUND *csound) +{ + return csound->oparms_.odebug; +} - PUBLIC void csoundSetDebug(CSOUND *csound, int debug) - { - csound->oparms_.odebug = debug; - } +PUBLIC void csoundSetDebug(CSOUND *csound, int debug) +{ + csound->oparms_.odebug = debug; +} - PUBLIC int csoundTableLength(CSOUND *csound, int table) - { - MYFLT *tablePtr; - return csound->GetTable(csound, &tablePtr, table); - } +PUBLIC int csoundTableLength(CSOUND *csound, int table) +{ + MYFLT *tablePtr; + return csoundGetTable(csound, &tablePtr, table); +} - PUBLIC MYFLT csoundTableGet(CSOUND *csound, int table, int index) - { - return csound->flist[table]->ftable[index]; - } +PUBLIC MYFLT csoundTableGet(CSOUND *csound, int table, int index) +{ + return csound->flist[table]->ftable[index]; +} - PUBLIC void csoundTableSet(CSOUND *csound, int table, int index, MYFLT value) - { - csound->flist[table]->ftable[index] = value; - } +static void csoundTableSetInternal(CSOUND *csound, + int table, int index, MYFLT value) +{ + csound->flist[table]->ftable[index] = value; +} - static int csoundDoCallback_(CSOUND *csound, void *p, unsigned int type) - { - if (csound->csoundCallbacks_ != NULL) { - CsoundCallbackEntry_t *pp; - pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; - do { - if (pp->typeMask & type) { - int retval = pp->func(pp->userData, p, type); - if (retval <= 0) - return retval; - } - pp = pp->nxt; - } while (pp != (CsoundCallbackEntry_t*) NULL); - } - return 1; - } +PUBLIC void csoundTableSet(CSOUND *csound, int table, int index, MYFLT value) +{ + /* in realtime mode init pass is executed in a separate thread, so + we need to protect it */ + csoundUnlockMutex(csound->API_lock); + if(csound->oparms->realtime) csoundLockMutex(csound->init_pass_threadlock); + csound->flist[table]->ftable[index] = value; + if(csound->oparms->realtime) csoundUnlockMutex(csound->init_pass_threadlock); + csoundUnlockMutex(csound->API_lock); +} - /** - * Sets general purpose callback function that will be called on various - * events. The callback is preserved on csoundReset(), and multiple - * callbacks may be set and will be called in reverse order of - * registration. If the same function is set again, it is only moved - * in the list of callbacks so that it will be called first, and the - * user data and type mask parameters are updated. 'typeMask' can be the - * bitwise OR of callback types for which the function should be called, - * or zero for all types. - * Returns zero on success, CSOUND_ERROR if the specified function - * pointer or type mask is invalid, and CSOUND_MEMORY if there is not - * enough memory. - * - * The callback function takes the following arguments: - * void *userData - * the "user data" pointer, as specified when setting the callback - * void *p - * data pointer, depending on the callback type - * unsigned int type - * callback type, can be one of the following (more may be added in - * future versions of Csound): - * CSOUND_CALLBACK_KBD_EVENT - * CSOUND_CALLBACK_KBD_TEXT - * called by the sensekey opcode to fetch key codes. The data - * pointer is a pointer to a single value of type 'int', for - * returning the key code, which can be in the range 1 to 65535, - * or 0 if there is no keyboard event. - * For CSOUND_CALLBACK_KBD_EVENT, both key press and release - * events should be returned (with 65536 (0x10000) added to the - * key code in the latter case) as unshifted ASCII codes. - * CSOUND_CALLBACK_KBD_TEXT expects key press events only as the - * actual text that is typed. - * The return value should be zero on success, negative on error, and - * positive if the callback was ignored (for example because the type is - * not known). - */ - - PUBLIC int csoundSetCallback(CSOUND *csound, - int (*func)(void *userData, void *p, - unsigned int type), - void *userData, unsigned int typeMask) - { +static int csoundDoCallback_(CSOUND *csound, void *p, unsigned int type) +{ + if (csound->csoundCallbacks_ != NULL) { CsoundCallbackEntry_t *pp; + pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; + do { + if (pp->typeMask & type) { + int retval = pp->func(pp->userData, p, type); + if (retval != CSOUND_SUCCESS) + return retval; + } + pp = pp->nxt; + } while (pp != (CsoundCallbackEntry_t*) NULL); + } + return 1; +} + +/** + * Sets a callback function that will be called on keyboard + * events. The callback is preserved on csoundReset(), and multiple + * callbacks may be set and will be called in reverse order of + * registration. If the same function is set again, it is only moved + * in the list of callbacks so that it will be called first, and the + * user data and type mask parameters are updated. 'typeMask' can be the + * bitwise OR of callback types for which the function should be called, + * or zero for all types. + * Returns zero on success, CSOUND_ERROR if the specified function + * pointer or type mask is invalid, and CSOUND_MEMORY if there is not + * enough memory. + * + * The callback function takes the following arguments: + * void *userData + * the "user data" pointer, as specified when setting the callback + * void *p + * data pointer, depending on the callback type + * unsigned int type + * callback type, can be one of the following (more may be added in + * future versions of Csound): + * CSOUND_CALLBACK_KBD_EVENT + * CSOUND_CALLBACK_KBD_TEXT + * called by the sensekey opcode to fetch key codes. The data + * pointer is a pointer to a single value of type 'int', for + * returning the key code, which can be in the range 1 to 65535, + * or 0 if there is no keyboard event. + * For CSOUND_CALLBACK_KBD_EVENT, both key press and release + * events should be returned (with 65536 (0x10000) added to the + * key code in the latter case) as unshifted ASCII codes. + * CSOUND_CALLBACK_KBD_TEXT expects key press events only as the + * actual text that is typed. + * The return value should be zero on success, negative on error, and + * positive if the callback was ignored (for example because the type is + * not known). + */ - if (UNLIKELY(func == (int (*)(void *, void *, unsigned int)) NULL || - (typeMask -#ifndef PARCS - & (~(CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT))) - != 0U)) { -#else /* PARCS */ - & (~(CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT))) != 0U)) -#endif /* PARCS */ +PUBLIC int csoundRegisterKeyboardCallback(CSOUND *csound, + int (*func)(void *userData, void *p, + unsigned int type), + void *userData, unsigned int typeMask) +{ + CsoundCallbackEntry_t *pp; + + if (UNLIKELY(func == (int (*)(void *, void *, unsigned int)) NULL || + (typeMask + & (~(CSOUND_CALLBACK_KBD_EVENT | CSOUND_CALLBACK_KBD_TEXT))) + != 0U)) return CSOUND_ERROR; -#ifndef PARCS - } -#endif /* ! PARCS */ - csoundRemoveCallback(csound, func); - pp = (CsoundCallbackEntry_t*) malloc(sizeof(CsoundCallbackEntry_t)); -#ifndef PARCS - if (UNLIKELY(pp == (CsoundCallbackEntry_t*) NULL)) { -#else /* PARCS */ - if (UNLIKELY(pp == (CsoundCallbackEntry_t*) NULL)) -#endif /* PARCS */ + csoundRemoveKeyboardCallback(csound, func); + pp = (CsoundCallbackEntry_t*) malloc(sizeof(CsoundCallbackEntry_t)); + if (UNLIKELY(pp == (CsoundCallbackEntry_t*) NULL)) return CSOUND_MEMORY; -#ifndef PARCS - } -#endif /* ! PARCS */ - pp->typeMask = (typeMask ? typeMask : 0xFFFFFFFFU); - pp->nxt = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; - pp->userData = userData; - pp->func = func; - csound->csoundCallbacks_ = (void*) pp; + pp->typeMask = (typeMask ? typeMask : 0xFFFFFFFFU); + pp->nxt = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; + pp->userData = userData; + pp->func = func; + csound->csoundCallbacks_ = (void*) pp; - return CSOUND_SUCCESS; - } + return CSOUND_SUCCESS; +} - /** - * Removes a callback previously set with csoundSetCallback(). - */ - - PUBLIC void csoundRemoveCallback(CSOUND *csound, - int (*func)(void *, void *, unsigned int)) - { - CsoundCallbackEntry_t *pp, *prv; - pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; - prv = (CsoundCallbackEntry_t*) NULL; - while (pp != (CsoundCallbackEntry_t*) NULL) { - if (pp->func == func) { -#ifndef PARCS - if (prv != (CsoundCallbackEntry_t*) NULL) { -#else /* PARCS */ - if (prv != (CsoundCallbackEntry_t*) NULL) -#endif /* PARCS */ - prv->nxt = pp->nxt; -#ifndef PARCS - } else { -#else /* PARCS */ - else -#endif /* PARCS */ - csound->csoundCallbacks_ = (void*) pp->nxt; -#ifndef PARCS - } -#endif /* ! PARCS */ - free((void*) pp); - return; - } - prv = pp; - pp = pp->nxt; +/** + * Removes a callback previously set with csoundSetCallback(). + */ + +PUBLIC void csoundRemoveKeyboardCallback(CSOUND *csound, + int (*func)(void *, void *, unsigned int)) +{ + CsoundCallbackEntry_t *pp, *prv; + + pp = (CsoundCallbackEntry_t*) csound->csoundCallbacks_; + prv = (CsoundCallbackEntry_t*) NULL; + while (pp != (CsoundCallbackEntry_t*) NULL) { + if (pp->func == func) { + if (prv != (CsoundCallbackEntry_t*) NULL) + prv->nxt = pp->nxt; + else + csound->csoundCallbacks_ = (void*) pp->nxt; + free((void*) pp); + return; } - } + prv = pp; + pp = pp->nxt; + } +} - PUBLIC void csoundSetFileOpenCallback(CSOUND *p, -#ifndef PARCS - void (*fileOpenCallback)(CSOUND*, - const char*, - int, int, int)) -#else /* PARCS */ - void (*fileOpenCallback)(CSOUND*, const char*, int, int, int)) -#endif /* PARCS */ - { - p->FileOpenCallback_ = fileOpenCallback; - } - /* csoundNotifyFileOpened() should be called by plugins via - csound->NotifyFileOpened() to let Csound know that they opened a file - without using one of the standard mechanisms (csound->FileOpen2() or - ldmemfile2()). The notification is passed on to the host if it has set - the FileOpen callback. */ - void csoundNotifyFileOpened(CSOUND* csound, const char* pathname, - int csFileType, int writing, int temporary) - { - if (csound->FileOpenCallback_ != NULL) - csound->FileOpenCallback_(csound, pathname, csFileType, writing, - temporary); - return; +PUBLIC void csoundSetFileOpenCallback(CSOUND *p, + void (*fileOpenCallback)(CSOUND*, + const char*, + int, int, int)) +{ + p->FileOpenCallback_ = fileOpenCallback; +} - } +/* csoundNotifyFileOpened() should be called by plugins via + csound->NotifyFileOpened() to let Csound know that they opened a file + without using one of the standard mechanisms (csound->FileOpen2() or + ldmemfile2withCB()). The notification is passed on to the host if it + has set the FileOpen callback. */ +void csoundNotifyFileOpened(CSOUND* csound, const char* pathname, + int csFileType, int writing, int temporary) +{ + if (csound->FileOpenCallback_ != NULL) + csound->FileOpenCallback_(csound, pathname, csFileType, writing, + temporary); + return; + +} - /* -------- IV - Jan 27 2005: timer functions -------- */ +/* -------- IV - Jan 27 2005: timer functions -------- */ #ifdef HAVE_GETTIMEOFDAY #undef HAVE_GETTIMEOFDAY @@ -2896,13 +3168,13 @@ #include #endif - /* enable use of high resolution timer (Linux/i586/GCC only) */ - /* could in fact work under any x86/GCC system, but do not */ - /* know how to query the actual CPU frequency ... */ +/* enable use of high resolution timer (Linux/i586/GCC only) */ +/* could in fact work under any x86/GCC system, but do not */ +/* know how to query the actual CPU frequency ... */ #define HAVE_RDTSC 1 - /* ------------------------------------ */ +/* ------------------------------------ */ #if defined(HAVE_RDTSC) #if !(defined(LINUX) && defined(__GNUC__) && defined(__i386__)) @@ -2910,832 +3182,726 @@ #endif #endif - /* hopefully cannot change during performance */ - static double timeResolutionSeconds = -1.0; +/* hopefully cannot change during performance */ +static double timeResolutionSeconds = -1.0; - /* find out CPU frequency based on /proc/cpuinfo */ +/* find out CPU frequency based on /proc/cpuinfo */ - static int getTimeResolution(void) - { +static int getTimeResolution(void) +{ #if defined(HAVE_RDTSC) - FILE *f; - char buf[256]; + FILE *f; + char buf[256]; - /* if frequency is not known yet */ - f = fopen("/proc/cpuinfo", "r"); - if (UNLIKELY(f == NULL)) { - fprintf(stderr, Str("Cannot open /proc/cpuinfo. " - "Support for RDTSC is not available.\n")); - return -1; - } - /* find CPU frequency */ - while (fgets(buf, 256, f) != NULL) { - int i; - char *s = (char*) buf - 1; - - buf[255] = '\0'; /* safety */ -#ifndef PARCS - if (strlen(buf) < 9) { - continue; /* too short, skip */ - } -#else /* PARCS */ - if (strlen(buf) < 9) - continue; /* too short, skip */ -#endif /* PARCS */ - while (*++s != '\0') -#ifndef PARCS - if (isupper(*s)) { - *s = tolower(*s); /* convert to lower case */ - } - if (strncmp(buf, "cpu mhz", 7) != 0) { - continue; /* check key name */ - } -#else /* PARCS */ - if (isupper(*s)) - *s = tolower(*s); /* convert to lower case */ - if (strncmp(buf, "cpu mhz", 7) != 0) - continue; /* check key name */ -#endif /* PARCS */ - s = strchr(buf, ':'); /* find frequency value */ -#ifndef PARCS - if (s == NULL) { - continue; /* invalid entry */ - } -#else /* PARCS */ - if (s == NULL) continue; /* invalid entry */ -#endif /* PARCS */ - do { - s++; - } while (*s == ' ' || *s == '\t'); /* skip white space */ - i = sscanf(s, "%lf", &timeResolutionSeconds); - if (i < 1 || timeResolutionSeconds < 1.0) { - timeResolutionSeconds = -1.0; /* invalid entry */ - continue; - } - } - fclose(f); - if (UNLIKELY(timeResolutionSeconds <= 0.0)) { - fprintf(stderr, Str("No valid CPU frequency entry " - "was found in /proc/cpuinfo.\n")); - return -1; - } - /* MHz -> seconds */ - timeResolutionSeconds = 0.000001 / timeResolutionSeconds; + /* if frequency is not known yet */ + f = fopen("/proc/cpuinfo", "r"); + if (UNLIKELY(f == NULL)) { + fprintf(stderr, Str("Cannot open /proc/cpuinfo. " + "Support for RDTSC is not available.\n")); + return -1; + } + /* find CPU frequency */ + while (fgets(buf, 256, f) != NULL) { + int i; + char *s = (char*) buf - 1; + + buf[255] = '\0'; /* safety */ + if (strlen(buf) < 9) + continue; /* too short, skip */ + while (*++s != '\0') + if (isupper(*s)) + *s = tolower(*s); /* convert to lower case */ + if (strncmp(buf, "cpu mhz", 7) != 0) + continue; /* check key name */ + s = strchr(buf, ':'); /* find frequency value */ + if (s == NULL) continue; /* invalid entry */ + do { + s++; + } while (*s == ' ' || *s == '\t'); /* skip white space */ + i = CS_SSCANF(s, "%lf", &timeResolutionSeconds); + if (i < 1 || timeResolutionSeconds < 1.0) { + timeResolutionSeconds = -1.0; /* invalid entry */ + continue; + } + } + fclose(f); + if (UNLIKELY(timeResolutionSeconds <= 0.0)) { + fprintf(stderr, Str("No valid CPU frequency entry " + "was found in /proc/cpuinfo.\n")); + return -1; + } + /* MHz -> seconds */ + timeResolutionSeconds = 0.000001 / timeResolutionSeconds; #elif defined(WIN32) - LARGE_INTEGER tmp1; - int_least64_t tmp2; - QueryPerformanceFrequency(&tmp1); - tmp2 = (int_least64_t) tmp1.LowPart + ((int_least64_t) tmp1.HighPart << 32); - timeResolutionSeconds = 1.0 / (double) tmp2; + LARGE_INTEGER tmp1; + int_least64_t tmp2; + QueryPerformanceFrequency(&tmp1); + tmp2 = (int_least64_t) tmp1.LowPart + ((int_least64_t) tmp1.HighPart << 32); + timeResolutionSeconds = 1.0 / (double) tmp2; #elif defined(HAVE_GETTIMEOFDAY) - timeResolutionSeconds = 0.000001; + timeResolutionSeconds = 0.000001; #else - timeResolutionSeconds = 1.0; + timeResolutionSeconds = 1.0; #endif #ifdef BETA - fprintf(stderr, "time resolution is %.3f ns\n", - 1.0e9 * timeResolutionSeconds); + fprintf(stderr, "time resolution is %.3f ns\n", + 1.0e9 * timeResolutionSeconds); #endif - return 0; - } + return 0; +} - /* function for getting real time */ +/* function for getting real time */ - static inline int_least64_t get_real_time(void) - { +static inline int_least64_t get_real_time(void) +{ #if defined(HAVE_RDTSC) - /* optimised high resolution timer for Linux/i586/GCC only */ - uint32_t l, h; + /* optimised high resolution timer for Linux/i586/GCC only */ + uint32_t l, h; #ifndef __STRICT_ANSI__ - asm volatile ("rdtsc" : "=a" (l), "=d" (h)); + asm volatile ("rdtsc" : "=a" (l), "=d" (h)); #else - __asm__ volatile ("rdtsc" : "=a" (l), "=d" (h)); + __asm__ volatile ("rdtsc" : "=a" (l), "=d" (h)); #endif - return ((int_least64_t) l + ((int_least64_t) h << 32)); + return ((int_least64_t) l + ((int_least64_t) h << 32)); #elif defined(WIN32) - /* Win32: use QueryPerformanceCounter - resolution depends on system, */ - /* but is expected to be better than 1 us. GetSystemTimeAsFileTime */ - /* seems to have much worse resolution under Win95. */ - LARGE_INTEGER tmp; - QueryPerformanceCounter(&tmp); -#ifndef PARCS - return ((int_least64_t) tmp.LowPart + ((int_least64_t) tmp.HighPart << 32)); -#else /* PARCS */ - return ((int_least64_t) tmp.LowPart + ((int_least64_t) tmp.HighPart <<32)); -#endif /* PARCS */ + /* Win32: use QueryPerformanceCounter - resolution depends on system, */ + /* but is expected to be better than 1 us. GetSystemTimeAsFileTime */ + /* seems to have much worse resolution under Win95. */ + LARGE_INTEGER tmp; + QueryPerformanceCounter(&tmp); + return ((int_least64_t) tmp.LowPart + ((int_least64_t) tmp.HighPart <<32)); #elif defined(HAVE_GETTIMEOFDAY) - /* UNIX: use gettimeofday() - allows 1 us resolution */ - struct timeval tv; - gettimeofday(&tv, NULL); - return ((int_least64_t) tv.tv_usec - + (int_least64_t) ((uint32_t) tv.tv_sec * (uint64_t) 1000000)); + /* UNIX: use gettimeofday() - allows 1 us resolution */ + struct timeval tv; + gettimeofday(&tv, NULL); + return ((int_least64_t) tv.tv_usec + + (int_least64_t) ((uint32_t) tv.tv_sec * (uint64_t) 1000000)); #else - /* other systems: use time() - allows 1 second resolution */ - return ((int_least64_t) time(NULL)); + /* other systems: use time() - allows 1 second resolution */ + return ((int_least64_t) time(NULL)); #endif - } +} - /* function for getting CPU time */ +/* function for getting CPU time */ - static inline int_least64_t get_CPU_time(void) - { - return ((int_least64_t) ((uint32_t) clock())); - } +static inline int_least64_t get_CPU_time(void) +{ + return ((int_least64_t) ((uint32_t) clock())); +} - /* initialise a timer structure */ +/* initialise a timer structure */ - PUBLIC void csoundInitTimerStruct(RTCLOCK *p) - { - p->starttime_real = get_real_time(); - p->starttime_CPU = get_CPU_time(); - } +PUBLIC void csoundInitTimerStruct(RTCLOCK *p) +{ + p->starttime_real = get_real_time(); + p->starttime_CPU = get_CPU_time(); +} - /** - * return the elapsed real time (in seconds) since the specified timer - * structure was initialised - */ - PUBLIC double csoundGetRealTime(RTCLOCK *p) - { - return ((double) (get_real_time() - p->starttime_real) - * (double) timeResolutionSeconds); - } +/** + * return the elapsed real time (in seconds) since the specified timer + * structure was initialised + */ +PUBLIC double csoundGetRealTime(RTCLOCK *p) +{ + return ((double) (get_real_time() - p->starttime_real) + * (double) timeResolutionSeconds); +} - /** - * return the elapsed CPU time (in seconds) since the specified timer - * structure was initialised - */ - PUBLIC double csoundGetCPUTime(RTCLOCK *p) - { - return ((double) ((uint32_t) get_CPU_time() - (uint32_t) p->starttime_CPU) - * (1.0 / (double) CLOCKS_PER_SEC)); - } +/** + * return the elapsed CPU time (in seconds) since the specified timer + * structure was initialised + */ +PUBLIC double csoundGetCPUTime(RTCLOCK *p) +{ + return ((double) ((uint32_t) get_CPU_time() - (uint32_t) p->starttime_CPU) + * (1.0 / (double) CLOCKS_PER_SEC)); +} - /* return a 32-bit unsigned integer to be used as seed from current time */ +/* return a 32-bit unsigned integer to be used as seed from current time */ - PUBLIC uint32_t csoundGetRandomSeedFromTime(void) - { - return (uint32_t) get_real_time(); - } +PUBLIC uint32_t csoundGetRandomSeedFromTime(void) +{ + return (uint32_t) get_real_time(); +} - /** - * Return the size of MYFLT in bytes. - */ - PUBLIC int csoundGetSizeOfMYFLT(void) - { - return (int) sizeof(MYFLT); - } +/** + * Return the size of MYFLT in bytes. + */ +PUBLIC int csoundGetSizeOfMYFLT(void) +{ + return (int) sizeof(MYFLT); +} - /** - * Return pointer to user data pointer for real time audio input. - */ - PUBLIC void **csoundGetRtRecordUserData(CSOUND *csound) - { - return &(csound->rtRecord_userdata); - } +/** + * Return pointer to user data pointer for real time audio input. + */ +PUBLIC void **csoundGetRtRecordUserData(CSOUND *csound) +{ + return &(csound->rtRecord_userdata); +} - /** - * Return pointer to user data pointer for real time audio output. - */ - PUBLIC void **csoundGetRtPlayUserData(CSOUND *csound) - { - return &(csound->rtPlay_userdata); - } +/** + * Return pointer to user data pointer for real time audio output. + */ +PUBLIC void **csoundGetRtPlayUserData(CSOUND *csound) +{ + return &(csound->rtPlay_userdata); +} - typedef struct opcodeDeinit_s { - void *p; - int (*func)(CSOUND *, void *); - void *nxt; - } opcodeDeinit_t; - - /** - * Register a function to be called at note deactivation. - * Should be called from the initialisation routine of an opcode. - * 'p' is a pointer to the OPDS structure of the opcode, and 'func' - * is the function to be called, with the same arguments and return - * value as in the case of opcode init/perf functions. - * The functions are called in reverse order of registration. - * Returns zero on success. - */ - - int csoundRegisterDeinitCallback(CSOUND *csound, void *p, - int (*func)(CSOUND *, void *)) - { - INSDS *ip = ((OPDS*) p)->insdshead; - opcodeDeinit_t *dp = (opcodeDeinit_t*) malloc(sizeof(opcodeDeinit_t)); - - (void) csound; -#ifndef PARCS - if (UNLIKELY(dp == NULL)) { -#else /* PARCS */ - if (UNLIKELY(dp == NULL)) -#endif /* PARCS */ - return CSOUND_MEMORY; -#ifndef PARCS - } -#endif /* ! PARCS */ - dp->p = p; - dp->func = func; - dp->nxt = ip->nxtd; - ip->nxtd = dp; - return CSOUND_SUCCESS; - } +typedef struct opcodeDeinit_s { + void *p; + int (*func)(CSOUND *, void *); + void *nxt; +} opcodeDeinit_t; + +/** + * Register a function to be called at note deactivation. + * Should be called from the initialisation routine of an opcode. + * 'p' is a pointer to the OPDS structure of the opcode, and 'func' + * is the function to be called, with the same arguments and return + * value as in the case of opcode init/perf functions. + * The functions are called in reverse order of registration. + * Returns zero on success. + */ - /** - * Register a function to be called by csoundReset(), in reverse order - * of registration, before unloading external modules. The function takes - * the Csound instance pointer as the first argument, and the pointer - * passed here as 'userData' as the second, and is expected to return zero - * on success. - * The return value of csoundRegisterResetCallback() is zero on success. - */ - - int csoundRegisterResetCallback(CSOUND *csound, void *userData, - int (*func)(CSOUND *, void *)) - { - resetCallback_t *dp = (resetCallback_t*) malloc(sizeof(resetCallback_t)); - -#ifndef PARCS - if (UNLIKELY(dp == NULL)) { -#else /* PARCS */ - if (UNLIKELY(dp == NULL)) -#endif /* PARCS */ - return CSOUND_MEMORY; -#ifndef PARCS - } -#endif /* ! PARCS */ - dp->userData = userData; - dp->func = func; - dp->nxt = csound->reset_list; - csound->reset_list = (void*) dp; - return CSOUND_SUCCESS; - } +int csoundRegisterDeinitCallback(CSOUND *csound, void *p, + int (*func)(CSOUND *, void *)) +{ + INSDS *ip = ((OPDS*) p)->insdshead; + opcodeDeinit_t *dp = (opcodeDeinit_t*) malloc(sizeof(opcodeDeinit_t)); + + (void) csound; + if (UNLIKELY(dp == NULL)) + return CSOUND_MEMORY; + dp->p = p; + dp->func = func; + dp->nxt = ip->nxtd; + ip->nxtd = dp; + return CSOUND_SUCCESS; +} - /* call the opcode deinitialisation routines of an instrument instance */ - /* called from deact() in insert.c */ +/** + * Register a function to be called by csoundReset(), in reverse order + * of registration, before unloading external modules. The function takes + * the Csound instance pointer as the first argument, and the pointer + * passed here as 'userData' as the second, and is expected to return zero + * on success. + * The return value of csoundRegisterResetCallback() is zero on success. + */ - int csoundDeinitialiseOpcodes(CSOUND *csound, INSDS *ip) - { - int err = 0; - - while (ip->nxtd != NULL) { - opcodeDeinit_t *dp = (opcodeDeinit_t*) ip->nxtd; - err |= dp->func(csound, dp->p); - ip->nxtd = (void*) dp->nxt; - free(dp); - } - return err; - } +int csoundRegisterResetCallback(CSOUND *csound, void *userData, + int (*func)(CSOUND *, void *)) +{ + resetCallback_t *dp = (resetCallback_t*) malloc(sizeof(resetCallback_t)); + + if (UNLIKELY(dp == NULL)) + return CSOUND_MEMORY; + dp->userData = userData; + dp->func = func; + dp->nxt = csound->reset_list; + csound->reset_list = (void*) dp; + return CSOUND_SUCCESS; +} - /** - * Returns the name of the opcode of which the data structure - * is pointed to by 'p'. - */ - char *csoundGetOpcodeName(void *p) - { - CSOUND *csound = (CSOUND*) ((OPDS*) p)->insdshead->csound; - return (char*) csound->opcodlst[((OPDS*) p)->optext->t.opnum].opname; - } +/* call the opcode deinitialisation routines of an instrument instance */ +/* called from deact() in insert.c */ - /** - * Returns the number of input arguments for opcode 'p'. - */ - int csoundGetInputArgCnt(void *p) - { - return (int) ((OPDS*) p)->optext->t.inoffs->count; - } +int csoundDeinitialiseOpcodes(CSOUND *csound, INSDS *ip) +{ + int err = 0; + + while (ip->nxtd != NULL) { + opcodeDeinit_t *dp = (opcodeDeinit_t*) ip->nxtd; + err |= dp->func(csound, dp->p); + ip->nxtd = (void*) dp->nxt; + free(dp); + } + return err; +} - /** - * Returns a binary value of which bit 0 is set if the first input - * argument is a-rate, bit 1 is set if the second input argument is - * a-rate, and so on. - * Only the first 31 arguments are guaranteed to be reported correctly. - */ - unsigned long csoundGetInputArgAMask(void *p) - { - return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xincod); - } +/** + * Returns the name of the opcode of which the data structure + * is pointed to by 'p'. + */ +char *csoundGetOpcodeName(void *p) +{ + return ((OPDS*) p)->optext->t.oentry->opname; +} - /** - * Returns a binary value of which bit 0 is set if the first input - * argument is a string, bit 1 is set if the second input argument is - * a string, and so on. - * Only the first 31 arguments are guaranteed to be reported correctly. - */ - unsigned long csoundGetInputArgSMask(void *p) - { - return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xincod_str); - } +/** + * Returns the number of input arguments for opcode 'p'. + */ +int csoundGetInputArgCnt(void *p) +{ + return (int) ((OPDS*) p)->optext->t.inArgCount; +} - /** - * Returns the name of input argument 'n' (counting from 0) for opcode 'p'. - */ - char *csoundGetInputArgName(void *p, int n) - { -#ifndef PARCS - if ((unsigned int) n >= - (unsigned int) ((OPDS*) p)->optext->t.inoffs->count) { -#else /* PARCS */ - if ((unsigned int) n >= (unsigned int) ((OPDS*) p)->optext->t.inoffs->count) -#endif /* PARCS */ - return (char*) NULL; -#ifndef PARCS - } -#endif /* ! PARCS */ - return (char*) ((OPDS*) p)->optext->t.inlist->arg[n]; - } +/** + * Returns a binary value of which bit 0 is set if the first input + * argument is a-rate, bit 1 is set if the second input argument is + * a-rate, and so on. + * Only the first 31 arguments are guaranteed to be reported correctly. + */ +unsigned long csoundGetInputArgAMask(void *p) +{ + return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xincod); +} - /** - * Returns the number of output arguments for opcode 'p'. - */ - int csoundGetOutputArgCnt(void *p) - { - return (int) ((OPDS*) p)->optext->t.outoffs->count; - } +/** + * Returns a binary value of which bit 0 is set if the first input + * argument is a string, bit 1 is set if the second input argument is + * a string, and so on. + * Only the first 31 arguments are guaranteed to be reported correctly. + */ +unsigned long csoundGetInputArgSMask(void *p) +{ + return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xincod_str); +} - /** - * Returns a binary value of which bit 0 is set if the first output - * argument is a-rate, bit 1 is set if the second output argument is - * a-rate, and so on. - * Only the first 31 arguments are guaranteed to be reported correctly. - */ - unsigned long csoundGetOutputArgAMask(void *p) - { - return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xoutcod); - } +/** + * Returns the name of input argument 'n' (counting from 0) for opcode 'p'. + */ +char *csoundGetInputArgName(void *p, int n) +{ + if ((unsigned int) n >= + (unsigned int) ((OPDS*) p)->optext->t.inArgCount) + return (char*) NULL; + return (char*) ((OPDS*) p)->optext->t.inlist->arg[n]; +} - /** - * Returns a binary value of which bit 0 is set if the first output - * argument is a string, bit 1 is set if the second output argument is - * a string, and so on. - * Only the first 31 arguments are guaranteed to be reported correctly. - */ - unsigned long csoundGetOutputArgSMask(void *p) - { - return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xoutcod_str); - } +/** + * Returns the number of output arguments for opcode 'p'. + */ +int csoundGetOutputArgCnt(void *p) +{ + return (int) ((OPDS*) p)->optext->t.outArgCount; +} - /** - * Returns the name of output argument 'n' (counting from 0) for opcode 'p'. - */ - char *csoundGetOutputArgName(void *p, int n) - { - if ((unsigned int) n -#ifndef PARCS - >= (unsigned int) ((OPDS*) p)->optext->t.outoffs->count) { -#else /* PARCS */ - >= (unsigned int) ((OPDS*) p)->optext->t.outoffs->count) -#endif /* PARCS */ - return (char*) NULL; -#ifndef PARCS - } -#endif /* ! PARCS */ - return (char*) ((OPDS*) p)->optext->t.outlist->arg[n]; - } +/** + * Returns a binary value of which bit 0 is set if the first output + * argument is a-rate, bit 1 is set if the second output argument is + * a-rate, and so on. + * Only the first 31 arguments are guaranteed to be reported correctly. + */ +unsigned long csoundGetOutputArgAMask(void *p) +{ + return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xoutcod); +} - /** - * Set release time in control periods (1 / csound->ekr second units) - * for opcode 'p' to 'n'. If the current release time is longer than - * the specified value, it is not changed. - * Returns the new release time. - */ - int csoundSetReleaseLength(void *p, int n) - { -#ifndef PARCS - if (n > (int) ((OPDS*) p)->insdshead->xtratim) { -#else /* PARCS */ - if (n > (int) ((OPDS*) p)->insdshead->xtratim) -#endif /* PARCS */ - ((OPDS*) p)->insdshead->xtratim = n; -#ifndef PARCS - } -#endif /* ! PARCS */ - return (int) ((OPDS*) p)->insdshead->xtratim; - } +/** + * Returns a binary value of which bit 0 is set if the first output + * argument is a string, bit 1 is set if the second output argument is + * a string, and so on. + * Only the first 31 arguments are guaranteed to be reported correctly. + */ +unsigned long csoundGetOutputArgSMask(void *p) +{ + return (unsigned long) ((unsigned int) ((OPDS*) p)->optext->t.xoutcod_str); +} - /** - * Set release time in seconds for opcode 'p' to 'n'. - * If the current release time is longer than the specified value, - * it is not changed. - * Returns the new release time in seconds. - */ - MYFLT csoundSetReleaseLengthSeconds(void *p, MYFLT n) - { - int kcnt = (int) (n * ((OPDS*) p)->insdshead->csound->ekr + FL(0.5)); -#ifndef PARCS - if (kcnt > (int) ((OPDS*) p)->insdshead->xtratim) { -#else /* PARCS */ - if (kcnt > (int) ((OPDS*) p)->insdshead->xtratim) -#endif /* PARCS */ - ((OPDS*) p)->insdshead->xtratim = kcnt; -#ifndef PARCS - } -#endif /* ! PARCS */ - return ((MYFLT) ((OPDS*) p)->insdshead->xtratim - * ((OPDS*) p)->insdshead->csound->onedkr); - } +/** + * Returns the name of output argument 'n' (counting from 0) for opcode 'p'. + */ +char *csoundGetOutputArgName(void *p, int n) +{ + if ((unsigned int) n + >= (unsigned int) ((OPDS*) p)->optext->t.outArgCount) + return (char*) NULL; + return (char*) ((OPDS*) p)->optext->t.outlist->arg[n]; +} - /** - * Returns MIDI channel number (0 to 15) for the instrument instance - * that called opcode 'p'. - * In the case of score notes, -1 is returned. - */ - int csoundGetMidiChannelNumber(void *p) - { - MCHNBLK *chn = ((OPDS*) p)->insdshead->m_chnbp; - int i; -#ifndef PARCS - if (chn == NULL) { -#else /* PARCS */ - if (chn == NULL) -#endif /* PARCS */ - return -1; -#ifndef PARCS - } -#endif /* ! PARCS */ - for (i = 0; i < 16; i++) { -#ifndef PARCS - if (chn == ((OPDS*) p)->insdshead->csound->m_chnbp[i]) { -#else /* PARCS */ - if (chn == ((OPDS*) p)->insdshead->csound->m_chnbp[i]) -#endif /* PARCS */ - return i; -#ifndef PARCS - } -#endif /* ! PARCS */ - } +/** + * Set release time in control periods (1 / csound->ekr second units) + * for opcode 'p' to 'n'. If the current release time is longer than + * the specified value, it is not changed. + * Returns the new release time. + */ +int csoundSetReleaseLength(void *p, int n) +{ + if (n > (int) ((OPDS*) p)->insdshead->xtratim) + ((OPDS*) p)->insdshead->xtratim = n; + return (int) ((OPDS*) p)->insdshead->xtratim; +} + +/** + * Set release time in seconds for opcode 'p' to 'n'. + * If the current release time is longer than the specified value, + * it is not changed. + * Returns the new release time in seconds. + */ +MYFLT csoundSetReleaseLengthSeconds(void *p, MYFLT n) +{ + int kcnt = (int) (n * ((OPDS*) p)->insdshead->csound->ekr + FL(0.5)); + if (kcnt > (int) ((OPDS*) p)->insdshead->xtratim) + ((OPDS*) p)->insdshead->xtratim = kcnt; + return ((MYFLT) ((OPDS*) p)->insdshead->xtratim + * ((OPDS*) p)->insdshead->csound->onedkr); +} + +/** + * Returns MIDI channel number (0 to 15) for the instrument instance + * that called opcode 'p'. + * In the case of score notes, -1 is returned. + */ +int csoundGetMidiChannelNumber(void *p) +{ + MCHNBLK *chn = ((OPDS*) p)->insdshead->m_chnbp; + int i; + if (chn == NULL) return -1; - } + for (i = 0; i < 16; i++) { + if (chn == ((OPDS*) p)->insdshead->csound->m_chnbp[i]) + return i; + } + return -1; +} - /** - * Returns a pointer to the MIDI channel structure for the instrument - * instance that called opcode 'p'. - * In the case of score notes, NULL is returned. - */ - MCHNBLK *csoundGetMidiChannel(void *p) - { - return ((OPDS*) p)->insdshead->m_chnbp; - } +/** + * Returns a pointer to the MIDI channel structure for the instrument + * instance that called opcode 'p'. + * In the case of score notes, NULL is returned. + */ +MCHNBLK *csoundGetMidiChannel(void *p) +{ + return ((OPDS*) p)->insdshead->m_chnbp; +} - /** - * Returns MIDI note number (in the range 0 to 127) for opcode 'p'. - * If the opcode was not called from a MIDI activated instrument - * instance, the return value is undefined. - */ - int csoundGetMidiNoteNumber(void *p) - { - return (int) ((OPDS*) p)->insdshead->m_pitch; - } +/** + * Returns MIDI note number (in the range 0 to 127) for opcode 'p'. + * If the opcode was not called from a MIDI activated instrument + * instance, the return value is undefined. + */ +int csoundGetMidiNoteNumber(void *p) +{ + return (int) ((OPDS*) p)->insdshead->m_pitch; +} - /** - * Returns MIDI velocity (in the range 0 to 127) for opcode 'p'. - * If the opcode was not called from a MIDI activated instrument - * instance, the return value is undefined. - */ - int csoundGetMidiVelocity(void *p) - { - return (int) ((OPDS*) p)->insdshead->m_veloc; - } +/** + * Returns MIDI velocity (in the range 0 to 127) for opcode 'p'. + * If the opcode was not called from a MIDI activated instrument + * instance, the return value is undefined. + */ +int csoundGetMidiVelocity(void *p) +{ + return (int) ((OPDS*) p)->insdshead->m_veloc; +} - /** - * Returns non-zero if the current note (owning opcode 'p') is releasing. - */ - int csoundGetReleaseFlag(void *p) - { - return (int) ((OPDS*) p)->insdshead->relesing; - } +/** + * Returns non-zero if the current note (owning opcode 'p') is releasing. + */ +int csoundGetReleaseFlag(void *p) +{ + return (int) ((OPDS*) p)->insdshead->relesing; +} - /** - * Returns the note-off time in seconds (measured from the beginning of - * performance) of the current instrument instance, from which opcode 'p' - * was called. The return value may be negative if the note has indefinite - * duration. - */ - double csoundGetOffTime(void *p) - { - return (double) ((OPDS*) p)->insdshead->offtim; - } +/** + * Returns the note-off time in seconds (measured from the beginning of + * performance) of the current instrument instance, from which opcode 'p' + * was called. The return value may be negative if the note has indefinite + * duration. + */ +double csoundGetOffTime(void *p) +{ + return (double) ((OPDS*) p)->insdshead->offtim; +} - /** - * Returns the array of p-fields passed to the instrument instance - * that owns opcode 'p', starting from p0. Only p1, p2, and p3 are - * guaranteed to be available. p2 is measured in seconds from the - * beginning of the current section. - */ - MYFLT *csoundGetPFields(void *p) - { - return (MYFLT*) &(((OPDS*) p)->insdshead->p0); - } +/** + * Returns the array of p-fields passed to the instrument instance + * that owns opcode 'p', starting from p0. Only p1, p2, and p3 are + * guaranteed to be available. p2 is measured in seconds from the + * beginning of the current section. + */ +MYFLT *csoundGetPFields(void *p) +{ + return (MYFLT*) &(((OPDS*) p)->insdshead->p0); +} - /** - * Returns the instrument number (p1) for opcode 'p'. - */ - int csoundGetInstrumentNumber(void *p) - { - return (int) ((OPDS*) p)->insdshead->p1; - } +/** + * Returns the instrument number (p1) for opcode 'p'. + */ +int csoundGetInstrumentNumber(void *p) +{ + return (int) ((OPDS*) p)->insdshead->p1; +} + +typedef struct csMsgStruct_ { + struct csMsgStruct_ *nxt; + int attr; + char s[1]; +} csMsgStruct; + +typedef struct csMsgBuffer_ { + void *mutex_; + csMsgStruct *firstMsg; + csMsgStruct *lastMsg; + int msgCnt; + char *buf; +} csMsgBuffer; + +// callback for storing messages in the buffer only +static void csoundMessageBufferCallback_1_(CSOUND *csound, int attr, + const char *fmt, va_list args); + +// callback for writing messages to the buffer, and also stdout/stderr +static void csoundMessageBufferCallback_2_(CSOUND *csound, int attr, + const char *fmt, va_list args); + +/** + * Creates a buffer for storing messages printed by Csound. + * Should be called after creating a Csound instance; note that + * the message buffer uses the host data pointer, and the buffer + * should be freed by calling csoundDestroyMessageBuffer() before + * deleting the Csound instance. + * If 'toStdOut' is non-zero, the messages are also printed to + * stdout and stderr (depending on the type of the message), + * in addition to being stored in the buffer. + */ - typedef struct csMsgStruct_ { - struct csMsgStruct_ *nxt; - int attr; - char s[1]; - } csMsgStruct; - - typedef struct csMsgBuffer_ { - void *mutex_; - csMsgStruct *firstMsg; - csMsgStruct *lastMsg; - int msgCnt; - char *buf; - } csMsgBuffer; - - // callback for storing messages in the buffer only - static void csoundMessageBufferCallback_1_(CSOUND *csound, int attr, - const char *fmt, va_list args); - - // callback for writing messages to the buffer, and also stdout/stderr - static void csoundMessageBufferCallback_2_(CSOUND *csound, int attr, - const char *fmt, va_list args); - - /** - * Creates a buffer for storing messages printed by Csound. - * Should be called after creating a Csound instance; note that - * the message buffer uses the host data pointer, and the buffer - * should be freed by calling csoundDestroyMessageBuffer() before - * deleting the Csound instance. - * If 'toStdOut' is non-zero, the messages are also printed to - * stdout and stderr (depending on the type of the message), - * in addition to being stored in the buffer. - */ - - void PUBLIC csoundEnableMessageBuffer(CSOUND *csound, int toStdOut) - { - csMsgBuffer *pp; - size_t nBytes; - - csoundDestroyMessageBuffer(csound); - nBytes = sizeof(csMsgBuffer); -#ifndef PARCS - if (!toStdOut) { -#else /* PARCS */ - if (!toStdOut) -#endif /* PARCS */ +void PUBLIC csoundCreateMessageBuffer(CSOUND *csound, int toStdOut) +{ + csMsgBuffer *pp; + size_t nBytes; + + pp = (csMsgBuffer*) csound->message_buffer; + if (pp) { + csoundDestroyMessageBuffer(csound); + } + nBytes = sizeof(csMsgBuffer); + if (!toStdOut) { nBytes += (size_t) 16384; -#ifndef PARCS - } -#endif /* ! PARCS */ - pp = (csMsgBuffer*) malloc(nBytes); - pp->mutex_ = csoundCreateMutex(0); - pp->firstMsg = (csMsgStruct*) 0; - pp->lastMsg = (csMsgStruct*) 0; - pp->msgCnt = 0; - if (!toStdOut) { + } + pp = (csMsgBuffer*) malloc(nBytes); + pp->mutex_ = csoundCreateMutex(0); + pp->firstMsg = (csMsgStruct*) NULL; + pp->lastMsg = (csMsgStruct*) NULL; + pp->msgCnt = 0; + if (!toStdOut) { pp->buf = (char*) pp + (int) sizeof(csMsgBuffer); pp->buf[0] = (char) '\0'; -#ifndef PARCS - } else { - pp->buf = (char*) 0; -#endif /* ! PARCS */ - } -#ifdef PARCS - else - pp->buf = (char*) 0; -#endif /* PARCS */ - csoundSetHostData(csound, (void*) pp); -#ifndef PARCS - if (!toStdOut) { -#else /* PARCS */ - if (!toStdOut) -#endif /* PARCS */ - csoundSetMessageCallback(csound, csoundMessageBufferCallback_1_); -#ifndef PARCS - } else { -#else /* PARCS */ - else -#endif /* PARCS */ + } else { + pp->buf = (char*) NULL; + } + csound->message_buffer = (void*) pp; + if (toStdOut) { csoundSetMessageCallback(csound, csoundMessageBufferCallback_2_); -#ifndef PARCS - } -#endif /* ! PARCS */ - } + } else { + csoundSetMessageCallback(csound, csoundMessageBufferCallback_1_); + } +} - /** - * Returns the first message from the buffer. - */ +/** + * Returns the first message from the buffer. + */ #ifdef MSVC - const char PUBLIC *csoundGetFirstMessage(CSOUND *csound) +const char PUBLIC *csoundGetFirstMessage(CSOUND *csound) #else -#ifndef PARCS - const char * PUBLIC csoundGetFirstMessage(CSOUND *csound) -#else /* PARCS */ - const char *PUBLIC csoundGetFirstMessage(CSOUND *csound) -#endif /* PARCS */ -#endif - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - char *msg = NULL; +const char */*PUBLIC*/ csoundGetFirstMessage(CSOUND *csound) +#endif +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + char *msg = NULL; - if (pp && pp->msgCnt) { - csoundLockMutex(pp->mutex_); -#ifndef PARCS - if (pp->firstMsg) { -#else /* PARCS */ - if (pp->firstMsg) -#endif /* PARCS */ - msg = &(pp->firstMsg->s[0]); -#ifndef PARCS - } -#endif /* ! PARCS */ - csoundUnlockMutex(pp->mutex_); - } - return msg; - } + if (pp && pp->msgCnt) { + csoundLockMutex(pp->mutex_); + if (pp->firstMsg) + msg = &(pp->firstMsg->s[0]); + csoundUnlockMutex(pp->mutex_); + } + return msg; +} + +/** + * Returns the attribute parameter (see msg_attr.h) of the first message + * in the buffer. + */ - /** - * Returns the attribute parameter (see msg_attr.h) of the first message - * in the buffer. - */ - - int PUBLIC csoundGetFirstMessageAttr(CSOUND *csound) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - int attr = 0; +int PUBLIC csoundGetFirstMessageAttr(CSOUND *csound) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + int attr = 0; - if (pp && pp->msgCnt) { + if (pp && pp->msgCnt) { csoundLockMutex(pp->mutex_); -#ifndef PARCS if (pp->firstMsg) { -#else /* PARCS */ - if (pp->firstMsg) -#endif /* PARCS */ - attr = pp->firstMsg->attr; -#ifndef PARCS + attr = pp->firstMsg->attr; } -#endif /* ! PARCS */ csoundUnlockMutex(pp->mutex_); - } - return attr; - } - - /** - * Removes the first message from the buffer. - */ - - void PUBLIC csoundPopFirstMessage(CSOUND *csound) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); + } + return attr; +} - if (pp) { - csMsgStruct *tmp; - csoundLockMutex(pp->mutex_); - tmp = pp->firstMsg; - if (tmp) { - pp->firstMsg = tmp->nxt; - pp->msgCnt--; -#ifndef PARCS - if (!pp->firstMsg) { -#else /* PARCS */ - if (!pp->firstMsg) -#endif /* PARCS */ - pp->lastMsg = (csMsgStruct*) 0; -#ifndef PARCS - } -#endif /* ! PARCS */ - } - csoundUnlockMutex(pp->mutex_); -#ifndef PARCS - if (tmp) { -#else /* PARCS */ - if (tmp) -#endif /* PARCS */ - free((void*) tmp); -#ifndef PARCS - } -#endif /* ! PARCS */ - } - } +/** + * Removes the first message from the buffer. + */ - /** - * Returns the number of pending messages in the buffer. - */ - - int PUBLIC csoundGetMessageCnt(CSOUND *csound) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - int cnt = 0; +void PUBLIC csoundPopFirstMessage(CSOUND *csound) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; - if (pp) { - csoundLockMutex(pp->mutex_); - cnt = pp->msgCnt; - csoundUnlockMutex(pp->mutex_); + if (pp) { + csMsgStruct *tmp; + csoundLockMutex(pp->mutex_); + tmp = pp->firstMsg; + if (tmp) { + pp->firstMsg = tmp->nxt; + pp->msgCnt--; + if (!pp->firstMsg) + pp->lastMsg = (csMsgStruct*) 0; } - return cnt; - } + csoundUnlockMutex(pp->mutex_); + if (tmp) + free((void*) tmp); + } +} - /** - * Releases all memory used by the message buffer. - */ - - void PUBLIC csoundDestroyMessageBuffer(CSOUND *csound) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - -#ifndef PARCS - if (!pp) { -#else /* PARCS */ - if (!pp) -#endif /* PARCS */ - return; -#ifndef PARCS - } - while (csoundGetMessageCnt(csound) > 0) { -#else /* PARCS */ - while (csoundGetMessageCnt(csound) > 0) -#endif /* PARCS */ - csoundPopFirstMessage(csound); -#ifndef PARCS - } -#endif /* ! PARCS */ - csoundSetHostData(csound, (void*) 0); - csoundDestroyMutex(pp->mutex_); - free((void*) pp); - } +/** + * Returns the number of pending messages in the buffer. + */ - static void csoundMessageBufferCallback_1_(CSOUND *csound, int attr, - const char *fmt, va_list args) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - csMsgStruct *p; - int len; +int PUBLIC csoundGetMessageCnt(CSOUND *csound) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + int cnt = -1; + if (pp) { csoundLockMutex(pp->mutex_); - len = vsprintf(pp->buf, fmt, args); // FIXME: this can overflow - if (UNLIKELY((unsigned int) len >= (unsigned int) 16384)) { - csoundUnlockMutex(pp->mutex_); - fprintf(stderr, "csound: internal error: message buffer overflow\n"); - exit(-1); - } - p = (csMsgStruct*) malloc(sizeof(csMsgStruct) + (size_t) len); - p->nxt = (csMsgStruct*) 0; - p->attr = attr; - strcpy(&(p->s[0]), pp->buf); -#ifndef PARCS - if (pp->firstMsg == (csMsgStruct*) 0) { -#else /* PARCS */ - if (pp->firstMsg == (csMsgStruct*) 0) -#endif /* PARCS */ - pp->firstMsg = p; -#ifndef PARCS - } else { -#else /* PARCS */ - else -#endif /* PARCS */ - pp->lastMsg->nxt = p; -#ifndef PARCS - } -#endif /* ! PARCS */ - pp->lastMsg = p; - pp->msgCnt++; + cnt = pp->msgCnt; csoundUnlockMutex(pp->mutex_); - } + } + return cnt; +} - static void csoundMessageBufferCallback_2_(CSOUND *csound, int attr, - const char *fmt, va_list args) - { - csMsgBuffer *pp = (csMsgBuffer*) csoundGetHostData(csound); - csMsgStruct *p; - int len = 0; - va_list args_save; - - va_copy(args_save, args); - switch (attr & CSOUNDMSG_TYPE_MASK) { - case CSOUNDMSG_ERROR: - case CSOUNDMSG_REALTIME: - case CSOUNDMSG_WARNING: - len = vfprintf(stderr, fmt, args); - break; - default: - len = vfprintf(stdout, fmt, args); - } - p = (csMsgStruct*) malloc(sizeof(csMsgStruct) + (size_t) len); - p->nxt = (csMsgStruct*) 0; - p->attr = attr; - vsprintf(&(p->s[0]), fmt, args_save); - va_end(args_save); - csoundLockMutex(pp->mutex_); - if (pp->firstMsg == (csMsgStruct*) 0) +/** + * Releases all memory used by the message buffer. + */ + +void PUBLIC csoundDestroyMessageBuffer(CSOUND *csound) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + if (!pp) { + csound->Warning(csound, + Str("csoundDestroyMessageBuffer: " + "Message buffer not allocated.")); + return; + } + csMsgStruct *msg = pp->firstMsg; + while (msg) { + csMsgStruct *tmp = msg; + msg = tmp->nxt; + free(tmp); + } + csound->message_buffer = NULL; + csoundSetMessageCallback(csound, NULL); + while (csoundGetMessageCnt(csound) > 0) { + csoundPopFirstMessage(csound); + } + csoundSetHostData(csound, NULL); + csoundDestroyMutex(pp->mutex_); + free((void*) pp); +} + +static void csoundMessageBufferCallback_1_(CSOUND *csound, int attr, + const char *fmt, va_list args) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + csMsgStruct *p; + int len; + + csoundLockMutex(pp->mutex_); + len = vsprintf(pp->buf, fmt, args); // FIXME: this can overflow + if (UNLIKELY((unsigned int) len >= (unsigned int) 16384)) { + csoundUnlockMutex(pp->mutex_); + fprintf(stderr, Str("csound: internal error: message buffer overflow\n")); + exit(-1); + } + p = (csMsgStruct*) malloc(sizeof(csMsgStruct) + (size_t) len); + p->nxt = (csMsgStruct*) NULL; + p->attr = attr; + strcpy(&(p->s[0]), pp->buf); + if (pp->firstMsg == (csMsgStruct*) 0) { pp->firstMsg = p; - else + } else { pp->lastMsg->nxt = p; - pp->lastMsg = p; - pp->msgCnt++; - csoundUnlockMutex(pp->mutex_); - } + } + pp->lastMsg = p; + pp->msgCnt++; + csoundUnlockMutex(pp->mutex_); +} - void PUBLIC sigcpy(MYFLT *dest, MYFLT *src, int size) - { /* Surely a memcpy*/ - memcpy(dest, src, size*sizeof(MYFLT)); - } +static void csoundMessageBufferCallback_2_(CSOUND *csound, int attr, + const char *fmt, va_list args) +{ + csMsgBuffer *pp = (csMsgBuffer*) csound->message_buffer; + csMsgStruct *p; + int len = 0; + va_list args_save; + + va_copy(args_save, args); + switch (attr & CSOUNDMSG_TYPE_MASK) { + case CSOUNDMSG_ERROR: + case CSOUNDMSG_REALTIME: + case CSOUNDMSG_WARNING: + len = vfprintf(stderr, fmt, args); + break; + default: + len = vfprintf(stdout, fmt, args); + } + p = (csMsgStruct*) malloc(sizeof(csMsgStruct) + (size_t) len); + p->nxt = (csMsgStruct*) NULL; + p->attr = attr; + vsprintf(&(p->s[0]), fmt, args_save); + va_end(args_save); + csoundLockMutex(pp->mutex_); + if (pp->firstMsg == (csMsgStruct*) NULL) + pp->firstMsg = p; + else + pp->lastMsg->nxt = p; + pp->lastMsg = p; + pp->msgCnt++; + csoundUnlockMutex(pp->mutex_); +} + +static INSTRTXT **csoundGetInstrumentList(CSOUND *csound){ + return csound->engineState.instrtxtp; +} -#ifdef __cplusplus +static long csoundGetKcounter(CSOUND *csound){ + return csound->kcounter; } + +static void set_util_sr(CSOUND *csound, MYFLT sr){ csound->esr = sr; } +static void set_util_nchnls(CSOUND *csound, int nchnls){ csound->nchnls = nchnls; } + +#if 0 +PUBLIC int csoundPerformKsmpsAbsolute(CSOUND *csound) +{ + int done = 0; + int returnValue; + + /* VL: 1.1.13 if not compiled (csoundStart() not called) */ + if (UNLIKELY(!(csound->engineStatus & CS_STATE_COMP))) { + csound->Warning(csound, + Str("Csound not ready for performance: csoundStart() " + "has not been called \n")); + return CSOUND_ERROR; + } + /* setup jmp for return after an exit() */ + if (UNLIKELY((returnValue = setjmp(csound->exitjmp)))) { +#ifndef MACOSX + csoundMessage(csound, Str("Early return from csoundPerformKsmps().\n")); #endif + return ((returnValue - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + csoundLockMutex(csound->API_lock); + do { + done |= sensevents(csound); + } while (kperf(csound)); + csoundUnlockMutex(csound->API_lock); + return done; +} +#endif + + +//#ifdef __cplusplus +//} +//#endif diff -Nru csound-5.17.11~dfsg/Top/getstring.c csound-6.02~dfsg/Top/getstring.c --- csound-5.17.11~dfsg/Top/getstring.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/getstring.c 2014-01-07 16:53:48.000000000 +0000 @@ -24,6 +24,11 @@ */ #include "csoundCore.h" +#ifdef HAVE_STRTOD_L +static locale_t csound_c_locale = NULL; +#else +static char *csound_c_locale = NULL; +#endif #ifdef HAVE_DIRENT_H # include @@ -41,10 +46,18 @@ #define CSSTRNGS_VERSION 0x2000 #include #ifndef GNU_GETTEXT -void init_getstring(void) +void init_getstring(void *cs) { - setlocale(LC_NUMERIC, "C"); /* Ensure C syntax */ +#ifndef HAVE_STRTOD_L + setlocale(LC_NUMERIC, "C"); /* Ensure C syntax */ + csound_c_locale = setlocale(LC_NUMERIC, "C"); /* and remwmber */ +#else + if (csound_c_locale == NULL) { + csound_c_locale = newlocale (0, "C", NULL); + } +#endif } + PUBLIC char *csoundLocalizeString(const char *s) { return (char*)s; @@ -55,25 +68,31 @@ return; } #else -void init_getstring(void) +void init_getstring(void *cs) { /* s = csoundGetEnv(NULL, "CS_LANG"); */ /* if (s == NULL) /\* Default locale *\/ */ /* setlocale (LC_MESSAGES, ""); */ /* else */ /* setlocale (LC_MESSAGES, s); /\* Set to particular value *\/ */ -/* textdomain("csound5"); */ /* This is not needed when using dgettext */ - /* bind_textdomain_codeset("csound5", "UTF-8"); */ +/* textdomain("csound6"); */ /* This is not needed when using dgettext */ + /* bind_textdomain_codeset("csound6", "UTF-8"); */ #ifdef never /* This is experimental; where should these be?? */ - bindtextdomain("csound5", "/home/jpff/Sourceforge/csound/csound5/po"); + bindtextdomain("csound6", "/home/jpff/Sourceforge/csound/csound6/po"); #endif +#ifndef HAVE_STRTOD_L setlocale(LC_NUMERIC, "C"); /* Ensure C syntax */ +#else + if (csound_c_locale == NULL) { + csound_c_locale = newlocale (0, "C", NULL); + } +#endif } PUBLIC char *csoundLocalizeString(const char *s) { - return dgettext("csound5", s); + return dgettext("csound6", s); } static const char *language_names[] = {"", /* Default */ @@ -164,5 +183,123 @@ } return; } + +#endif + +PUBLIC char* cs_strtok_r(char* str, char* delim, char** nextp) { +#ifdef HAVE_STRTOK_R + return strtok_r(str, delim, nextp); +#else + /* + * public domain strtok_r() by Charlie Gordon + * + * from comp.lang.c 9/14/2007 + * + * http://groups.google.com/group/comp.lang.c/msg/2ab1ecbb86646684 + * + * (Declaration that it's public domain): + * http://groups.google.com/group/comp.lang.c/msg/7c7b39328fefab9c + */ + char *ret; + if (str == NULL) + { + str = *nextp; + } + str += strspn(str, delim); + if (*str == '\0') + { + return NULL; + } + ret = str; + str += strcspn(str, delim); + if (*str) + { + *str++ = '\0'; + } + *nextp = str; + return ret; +#endif +} + +PUBLIC double cs_strtod(char* nptr, char** endptr) { +#ifdef HAVE_STRTOD_L + return strtod_l(nptr, endptr, csound_c_locale); +#else + return strtod(nptr, endptr); #endif +} + +#if defined(HAVE_SPRINTF_L) +PUBLIC int cs_sprintf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + va_start(args, format); + retVal = vsprintf_l(str,csound_c_locale,format,args); + va_end(args); + return retVal; +} +PUBLIC int cs_sscanf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + va_start(args, format); + retVal = vsscanf_l(str,csound_c_locale,format,args); + va_end(args); + return retVal; +} +#else +#if defined(HAVE__SPRINT_L) +PUBLIC int cs_sprintf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + va_start(args, format); + retVal = __vsprintf_l(str,csound_c_locale,format,args); + va_end(args); + return retVal; +} + +PUBLIC int cs_sscanf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + va_start(args, format); + retVal = __vsscanf_l(str,csound_c_locale,format,args); + va_end(args); + return retVal; +} +#else +PUBLIC int cs_sprintf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + char *curlocale = setlocale(LC_NUMERIC, "C"); + va_start(args, format); + retVal = vsprintf(str,format,args); + va_end(args); + setlocale(LC_NUMERIC, curlocale); + return retVal; +} + +PUBLIC int cs_sscanf(char *str, const char *format, ...) +{ + // This is not thread-safe but no idea how to fix + va_list args; + int retVal; + char *curlocale = setlocale(LC_NUMERIC, "C"); + va_start(args, format); + retVal = vsscanf(str,format,args); + va_end(args); + setlocale(LC_NUMERIC, curlocale); + return retVal; +} + +#endif +#endif diff -Nru csound-5.17.11~dfsg/Top/main.c csound-6.02~dfsg/Top/main.c --- csound-5.17.11~dfsg/Top/main.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/main.c 2014-01-07 16:54:20.000000000 +0000 @@ -27,116 +27,94 @@ #include "csmodule.h" #include "corfile.h" -#ifdef ENABLE_NEW_PARSER #include "csound_orc.h" -#endif -#ifdef PARCS #include "cs_par_base.h" #include "cs_par_orc_semantics.h" #include "cs_par_dispatch.h" -#endif #if defined(USE_OPENMP) #include #endif - +extern int UDPServerStart(CSOUND *csound, int port); extern void dieu(CSOUND *, char *, ...); extern int argdecode(CSOUND *, int, char **); extern int init_pvsys(CSOUND *); -extern char *get_sconame(CSOUND *); +//extern char *get_sconame(CSOUND *); extern void print_benchmark_info(CSOUND *, const char *); extern void openMIDIout(CSOUND *); extern int read_unified_file(CSOUND *, char **, char **); -extern OENTRY opcodlst_1[]; extern uintptr_t kperfThread(void * cs); -#if defined(ENABLE_NEW_PARSER) -extern void cs_init_math_constants_macros(CSOUND *csound,void *yyscanner); -extern void cs_init_omacros(CSOUND *csound, NAMES *nn); -#endif +extern void cs_init_math_constants_macros(CSOUND *csound, PRE_PARM *yyscanner); +extern void cs_init_omacros(CSOUND *csound, PRE_PARM*, NAMES *nn); -static void create_opcodlst(CSOUND *csound) +void checkOptions(CSOUND *csound) { - OENTRY *saved_opcodlst = csound->opcodlst; - int old_cnt = 0, err; - - if (saved_opcodlst != NULL) { - csound->opcodlst = NULL; - if (csound->oplstend != NULL) - old_cnt = (int) ((OENTRY*) csound->oplstend - (OENTRY*) saved_opcodlst); - csound->oplstend = NULL; - memset(csound->opcode_list, 0, sizeof(int) * 256); - } - /* Basic Entry1 stuff */ - err = csoundAppendOpcodes(csound, &(opcodlst_1[0]), -1); - /* Add opcodes registered by host application */ - if (old_cnt) - err |= csoundAppendOpcodes(csound, saved_opcodlst, old_cnt); - if (saved_opcodlst != NULL) - free(saved_opcodlst); - if (err) - csoundDie(csound, Str("Error allocating opcode list")); + const char *csrcname; + const char *home_dir; + FILE *csrc = NULL; + void *fd = NULL; + char *s; + /* IV - Feb 17 2005 */ + csrcname = csoundGetEnv(csound, "CSOUND6RC"); + if (csrcname != NULL && csrcname[0] != '\0') { + fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, csrcname, "r", NULL, + CSFTYPE_OPTIONS, 0); + if (fd == NULL) + csoundMessage(csound, Str("WARNING: cannot open csound6rc file %s\n"), + csrcname); + else + csound->Message(csound, Str("Reading options from $CSOUND6RC: %s \n"), + csrcname); + } + if (fd == NULL && ((home_dir = csoundGetEnv(csound, "HOME")) != NULL && + home_dir[0] != '\0')) { + s = csoundConcatenatePaths(csound, home_dir, ".csound6rc"); + fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, s, "r", NULL, + CSFTYPE_OPTIONS, 0); + if (fd != NULL) + csound->Message(csound, Str("Reading options from $HOME/.csound6rc\n")); + mfree(csound, s); + } + /* read global .csound6rc file (if exists) */ + if (fd != NULL) { + + readOptions(csound, csrc, 0); + csound->FileClose(csound, fd); + } + /* check for .csound6rc in current directory */ + fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, ".csound6rc", "r", NULL, + CSFTYPE_OPTIONS, 0); + if (fd != NULL) { + readOptions(csound, csrc, 0); + csound->Message(csound, + Str("Reading options from local directory .csound6rc \n")); + csound->FileClose(csound, fd); + } } -PUBLIC int csoundCompile(CSOUND *csound, int argc, char **argv) + +PUBLIC int csoundCompileArgs(CSOUND *csound, int argc, char **argv) { OPARMS *O = csound->oparms; char *s; - char *sortedscore = NULL; - // char *xtractedscore = "score.xtr"; FILE *xfile = NULL; int n; int csdFound = 0; char *fileDir; - /* IV - Feb 05 2005: find out if csoundPreCompile() needs to be called */ - if (csound->engineState != CS_STATE_PRE) { - csound->printerrormessagesflag = (void*)1234; - if ((n = csoundPreCompile(csound)) != CSOUND_SUCCESS) - return n; - } if ((n = setjmp(csound->exitjmp)) != 0) { return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); } - init_pvsys(csound); - /* utilities depend on this as well as orchs; may get changed by an orch */ - dbfs_init(csound, DFLT_DBFS); - csound->csRtClock = (RTCLOCK*) csound->Calloc(csound, sizeof(RTCLOCK)); - csoundInitTimerStruct(csound->csRtClock); - csound->engineState |= CS_STATE_COMP | CS_STATE_CLN; - -#ifndef USE_DOUBLE -#ifdef BETA - csound->Message(csound, Str("Csound version %s beta (float samples) %s\n"), - CS_PACKAGE_VERSION, __DATE__); -#else - csound->Message(csound, Str("Csound version %s (float samples) %s\n"), - CS_PACKAGE_VERSION, __DATE__); -#endif -#else -#ifdef BETA - csound->Message(csound, Str("Csound version %s beta (double samples) %s\n"), - CS_PACKAGE_VERSION, __DATE__); -#else - csound->Message(csound, Str("Csound version %s (double samples) %s\n"), - CS_PACKAGE_VERSION, __DATE__); -#endif -#endif - { - char buffer[128]; - sf_command(NULL, SFC_GET_LIB_VERSION, buffer, 128); - csound->Message(csound, "%s\n", buffer); + if(csound->engineStatus & CS_STATE_COMP){ + csound->Message(csound, Str("Csound is already started, call csoundReset()\n" + "before starting again \n")); + return CSOUND_ERROR; } - /* do not know file type yet */ - O->filetyp = -1; - O->sfheader = 0; - csound->peakchunks = 1; - create_opcodlst(csound); - if (--argc <= 0) { dieu(csound, Str("insufficient arguments")); } @@ -144,50 +122,9 @@ csound->orcname_mode = 0; /* 0: normal, 1: ignore, 2: fail */ if (argdecode(csound, argc, argv) == 0) csound->LongJmp(csound, 1); - /* do not allow orc/sco/csd name in .csoundrc */ + /* do not allow orc/sco/csd name in .csound6rc */ csound->orcname_mode = 2; - { - const char *csrcname; - const char *home_dir; - FILE *csrc = NULL; - void *fd = NULL; - /* IV - Feb 17 2005 */ - csrcname = csoundGetEnv(csound, "CSOUNDRC"); - if (csrcname != NULL && csrcname[0] != '\0') { - fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, csrcname, "r", NULL, - CSFTYPE_OPTIONS, 0); - if (fd == NULL) - csoundMessage(csound, Str("WARNING: cannot open csoundrc file %s\n"), - csrcname); - else - csound->Message(csound, Str("Reading options from $CSOUNDRC: %s \n"), - csrcname); - } - if (fd == NULL && ((home_dir = csoundGetEnv(csound, "HOME")) != NULL && - home_dir[0] != '\0')) { - s = csoundConcatenatePaths(csound, home_dir, ".csoundrc"); - fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, s, "r", NULL, - CSFTYPE_OPTIONS, 0); - if (fd != NULL) - csound->Message(csound, Str("Reading options from $HOME/.csoundrc\n")); - mfree(csound, s); - } - /* read global .csoundrc file (if exists) */ - if (fd != NULL) { - - readOptions(csound, csrc, 0); - csound->FileClose(csound, fd); - } - /* check for .csoundrc in current directory */ - fd = csound->FileOpen2(csound, &csrc, CSFILE_STD, ".csoundrc", "r", NULL, - CSFTYPE_OPTIONS, 0); - if (fd != NULL) { - readOptions(csound, csrc, 0); - csound->Message(csound, - "Reading options from local directory .csoundrc \n"); - csound->FileClose(csound, fd); - } - } + checkOptions(csound); if (csound->delayederrormessages) { if (O->msglevel>8) csound->Warning(csound, csound->delayederrormessages); @@ -195,36 +132,40 @@ csound->delayederrormessages = NULL; } /* check for CSD file */ - if (csound->orchname == NULL) - dieu(csound, Str("no orchestra name")); - else if (csound->scorename == NULL || csound->scorename[0] == (char) 0) { - int tmp = (int) strlen(csound->orchname) - 4; - if (tmp >= 0 && csound->orchname[tmp] == '.' && - tolower(csound->orchname[tmp + 1]) == 'c' && - tolower(csound->orchname[tmp + 2]) == 's' && - tolower(csound->orchname[tmp + 3]) == 'd') { - /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */ - csound->orcname_mode = 0; - csound->Message(csound, "UnifiedCSD: %s\n", csound->orchname); - - /* Add directory of CSD file to search paths before orchname gets - * replaced with temp orch name if default paths is enabled */ - if (!O->noDefaultPaths) { - fileDir = csoundGetDirectoryForPath(csound, csound->orchname); - csoundAppendEnv(csound, "SADIR", fileDir); - csoundAppendEnv(csound, "SSDIR", fileDir); - csoundAppendEnv(csound, "INCDIR", fileDir); - csoundAppendEnv(csound, "MFDIR", fileDir); - mfree(csound, fileDir); - } + if (csound->orchname == NULL) { + if(csound->info_message_request) { + csound->info_message_request = 0; + csound->LongJmp(csound, 1); + } + else if(csound->oparms->daemon == 0) + dieu(csound, Str("no orchestra name")); - csound->csdname = csound->orchname; /* save original CSD name */ - if (!read_unified_file(csound, &(csound->orchname), - &(csound->scorename))) { - csound->Die(csound, Str("Reading CSD failed ... stopping")); - } + } + else if (csound->use_only_orchfile == 0 + && (csound->scorename == NULL || csound->scorename[0] == (char) 0) + && csound->orchname[0] != '\0') { + /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */ + csound->orcname_mode = 0; + csound->Message(csound, "UnifiedCSD: %s\n", csound->orchname); + + /* Add directory of CSD file to search paths before orchname gets + * replaced with temp orch name if default paths is enabled */ + if (!O->noDefaultPaths) { + fileDir = csoundGetDirectoryForPath(csound, csound->orchname); + csoundAppendEnv(csound, "SADIR", fileDir); + csoundAppendEnv(csound, "SSDIR", fileDir); + csoundAppendEnv(csound, "INCDIR", fileDir); + csoundAppendEnv(csound, "MFDIR", fileDir); + mfree(csound, fileDir); + } - csdFound = 1; + if(csound->orchname != NULL) { + csound->csdname = csound->orchname; /* save original CSD name */ + if (!read_unified_file(csound, &(csound->orchname), + &(csound->scorename))) { + csound->Die(csound, Str("Reading CSD failed ... stopping")); + } + csdFound = 1; } } @@ -242,50 +183,11 @@ (csound->stdout_assign_flg & (csound->stdout_assign_flg - 1)) != 0) { csound->Die(csound, Str("error: multiple uses of stdout")); } - /* done parsing csoundrc, CSD, and command line options */ - /* if sound file type is still not known, check SFOUTYP */ - if (O->filetyp <= 0) { - const char *envoutyp; - envoutyp = csoundGetEnv(csound, "SFOUTYP"); - if (envoutyp != NULL && envoutyp[0] != '\0') { - if (strcmp(envoutyp, "AIFF") == 0) - O->filetyp = TYP_AIFF; - else if (strcmp(envoutyp, "WAV") == 0 || strcmp(envoutyp, "WAVE") == 0) - O->filetyp = TYP_WAV; - else if (strcmp(envoutyp, "IRCAM") == 0) - O->filetyp = TYP_IRCAM; - else if (strcmp(envoutyp, "RAW") == 0) - O->filetyp = TYP_RAW; - else { - dieu(csound, Str("%s not a recognised SFOUTYP env setting"), - envoutyp); - } - } - else -#if !defined(__MACH__) && !defined(mac_classic) - O->filetyp = TYP_WAV; /* default to WAV if even SFOUTYP is unset */ -#else - O->filetyp = TYP_AIFF; /* ... or AIFF on the Mac */ -#endif - } - /* everything other than a raw sound file has a header */ - O->sfheader = (O->filetyp == TYP_RAW ? 0 : 1); - if (O->Linein || O->Midiin || O->FMidiin) - O->RTevents = 1; - if (!O->sfheader) - O->rewrt_hdr = 0; /* cannot rewrite header of headerless file */ - if (O->sr_override || O->kr_override) { - if (!O->sr_override || !O->kr_override) - dieu(csound, Str("srate and krate overrides must occur jointly")); - } - if (!O->outformat) /* if no audioformat yet */ - O->outformat = AE_SHORT; /* default to short_ints */ - O->sfsampsize = sfsampsize(FORMAT2SF(O->outformat)); - O->informat = O->outformat; /* informat default */ + /* done parsing csound6rc, CSD, and command line options */ if (csound->scorename == NULL && csound->scorestr==NULL) { /* No scorename yet */ - csound->scorestr = corfile_create_r("f0 42000\n"); + csound->scorestr = corfile_create_r("f0 800000000000.0\n"); corfile_flush(csound->scorestr); if (O->RTevents) csound->Message(csound, Str("realtime performance using dummy " @@ -309,59 +211,57 @@ mfree(csound, fileDir); } - if (csound->orchstr==NULL) { + if (csound->orchstr==NULL && csound->orchname) { /* does not deal with search paths */ csound->Message(csound, Str("orchname: %s\n"), csound->orchname); csound->orchstr = copy_to_corefile(csound, csound->orchname, NULL, 0); if (csound->orchstr==NULL) csound->Die(csound, - Str("Failed to open input file %s\n"), csound->orchname); -#ifdef ENABLE_NEW_PARSER - if (O->newParser) corfile_puts("\n#exit\n", csound->orchstr); -#endif + Str("Failed to open input file - %s\n"), csound->orchname); + corfile_puts("\n#exit\n", csound->orchstr); corfile_putc('\0', csound->orchstr); corfile_putc('\0', csound->orchstr); //csound->orchname = NULL; } if (csound->xfilename != NULL) csound->Message(csound, "xfilename: %s\n", csound->xfilename); - /* IV - Oct 31 2002: moved orchestra compilation here, so that named */ - /* instrument numbers are known at the score read/sort stage */ + csoundLoadExternals(csound); /* load plugin opcodes */ - /* IV - Jan 31 2005: initialise external modules */ + /* VL: added this also to csoundReset() in csound.c */ if (csoundInitModules(csound) != 0) csound->LongJmp(csound, 1); - -#ifdef ENABLE_NEW_PARSER - if (O->newParser) { - int new_orc_parser(CSOUND *); - if (new_orc_parser(csound)) { - csoundDie(csound, Str("Stopping on parser failure\n")); - } - } - else { - csound->Message(csound, "********************\n"); - csound->Message(csound, "* USING OLD PARSER *\n"); - csound->Message(csound, "********************\n"); - otran(csound); /* read orcfile, setup desblks & spaces */ - } -#else - otran(csound); /* read orcfile, setup desblks & spaces */ -#endif -#if defined(USE_OPENMP) - if (csound->oparms->numThreads > 1) { - omp_set_num_threads(csound->oparms->numThreads); - csound->Message(csound, "OpenMP enabled: requested %d threads.\n", - csound->oparms->numThreads); + if(csoundCompileOrc(csound, NULL) != 0){ + if(csound->oparms->daemon == 0) + csoundDie(csound, Str("cannot compile orchestra \n")); + else { + /* VL -- 21-10-13 Csound does not need to die on + failure to compile. It can carry on, because new + instruments can be compiled again */ + csound->Warning(csound, Str("cannot compile orchestra.")); + csound->Warning(csound, Str("Csound will start with no instruments")); + } + } + csound->modules_loaded = 1; + + s = csoundQueryGlobalVariable(csound, "_RTMIDI"); + if(csound->enableHostImplementedMIDIIO == 1) { + if (s == NULL) { + s = strdup("hostbased"); + } else { + strcpy(s, "hostbased"); + } + csoundSetConfigurationVariable(csound,"rtmidi", s); } -#endif + + /* IV - Jan 28 2005 */ print_benchmark_info(csound, Str("end of orchestra compile")); if (!csoundYield(csound)) return -1; /* IV - Oct 31 2002: now we can read and sort the score */ - if ((n = strlen(csound->scorename)) > 4 && /* if score ?.srt or ?.xtr */ + if (csound->scorename != NULL && + (n = strlen(csound->scorename)) > 4 && /* if score ?.srt or ?.xtr */ (!strcmp(csound->scorename + (n - 4), ".srt") || !strcmp(csound->scorename + (n - 4), ".xtr"))) { csound->Message(csound, Str("using previous %s\n"), csound->scorename); @@ -370,7 +270,7 @@ csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); } else { - sortedscore = NULL; + //sortedscore = NULL; if (csound->scorestr==NULL) { csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); if (csound->scorestr==NULL) @@ -412,7 +312,142 @@ if (O->Midioutname != NULL || O->FMidioutname != NULL) openMIDIout(csound); -#ifdef PARCS + return CSOUND_SUCCESS; +} + +extern int playopen_dummy(CSOUND *, const csRtAudioParams *parm); +extern void rtplay_dummy(CSOUND *, const MYFLT *outBuf, int nbytes); +extern int recopen_dummy(CSOUND *, const csRtAudioParams *parm); +extern int rtrecord_dummy(CSOUND *, MYFLT *inBuf, int nbytes); +extern void rtclose_dummy(CSOUND *); +extern int audio_dev_list_dummy(CSOUND *, CS_AUDIODEVICE *, int); +extern int midi_dev_list_dummy(CSOUND *csound, CS_MIDIDEVICE *list, int isOutput); +extern int DummyMidiInOpen(CSOUND *csound, void **userData, + const char *devName); +extern int DummyMidiRead(CSOUND *csound, void *userData, + unsigned char *buf, int nbytes); +extern int DummyMidiOutOpen(CSOUND *csound, void **userData, + const char *devName); +extern int DummyMidiWrite(CSOUND *csound, void *userData, + const unsigned char *buf, int nbytes); + + +PUBLIC int csoundStart(CSOUND *csound) // DEBUG +{ + OPARMS *O = csound->oparms; + int n; + + /* if a CSD was not used, check options */ + if(csound->csdname == NULL) + checkOptions(csound); + + if(csound->engineStatus & CS_STATE_COMP){ + csound->Message(csound, "Csound is already started, call csoundReset()\n" + "before starting again \n"); + return CSOUND_ERROR; + } + + + + + { /* test for dummy module request */ + char *s; + if((s = csoundQueryGlobalVariable(csound, "_RTAUDIO")) != NULL) + if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0) { + csound->Message(csound, Str("setting dummy interface\n")); + csound->SetPlayopenCallback(csound, playopen_dummy); + csound->SetRecopenCallback(csound, recopen_dummy); + csound->SetRtplayCallback(csound, rtplay_dummy); + csound->SetRtrecordCallback(csound, rtrecord_dummy); + csound->SetRtcloseCallback(csound, rtclose_dummy); + csound->SetAudioDeviceListCallback(csound, audio_dev_list_dummy); + } + + /* and midi */ + if(csound->enableHostImplementedMIDIIO == 0){ + if((s = csoundQueryGlobalVariable(csound, "_RTMIDI")) != NULL) + if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || + strcmp(s, "NULL") == 0) { + csound->SetMIDIDeviceListCallback(csound, midi_dev_list_dummy); + csound->SetExternalMidiInOpenCallback(csound, DummyMidiInOpen); + csound->SetExternalMidiReadCallback(csound, DummyMidiRead); + csound->SetExternalMidiInCloseCallback(csound, NULL); + csound->SetExternalMidiOutOpenCallback(csound, DummyMidiOutOpen); + csound->SetExternalMidiWriteCallback(csound, DummyMidiWrite); + csound->SetExternalMidiOutCloseCallback(csound, NULL); + } + } + else { + s = csoundQueryGlobalVariable(csound, "_RTMIDI"); + strcpy(s, "hostbased"); + csoundSetConfigurationVariable(csound,"rtmidi", s); + } + } + + + /* VL 30-12-12 csoundInitModules is always called here now to enable + Csound to start without calling csoundCompile, but directly from + csoundCompileOrc() and csoundReadSco() + */ + if(csound->modules_loaded == 0){ + csoundLoadExternals(csound); /* load plugin opcodes */ + if (csoundInitModules(csound) != 0) + csound->LongJmp(csound, 1); + csound->modules_loaded = 1; + } + if (csound->instr0 == NULL) { /* compile dummy instr0 to allow csound to + start with no orchestra */ + csoundCompileOrc(csound, "idummy = 0 \n"); + } + + if ((n = setjmp(csound->exitjmp)) != 0) { + return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); + } + + + + /* if sound file type is still not known, check SFOUTYP */ + if (O->filetyp <= 0) { + const char *envoutyp; + envoutyp = csoundGetEnv(csound, "SFOUTYP"); + if (envoutyp != NULL && envoutyp[0] != '\0') { + if (strcmp(envoutyp, "AIFF") == 0) + O->filetyp = TYP_AIFF; + else if (strcmp(envoutyp, "WAV") == 0 || strcmp(envoutyp, "WAVE") == 0) + O->filetyp = TYP_WAV; + else if (strcmp(envoutyp, "IRCAM") == 0) + O->filetyp = TYP_IRCAM; + else if (strcmp(envoutyp, "RAW") == 0) + O->filetyp = TYP_RAW; + else { + dieu(csound, Str("%s not a recognised SFOUTYP env setting"), + envoutyp); + } + } + else +#if !defined(__MACH__) + O->filetyp = TYP_WAV; /* default to WAV if even SFOUTYP is unset */ +#else + O->filetyp = TYP_AIFF; /* ... or AIFF on the Mac */ +#endif + } + /* everything other than a raw sound file has a header */ + O->sfheader = (O->filetyp == TYP_RAW ? 0 : 1); + if (O->Linein || O->Midiin || O->FMidiin) + O->RTevents = 1; + if (!O->sfheader) + O->rewrt_hdr = 0; /* cannot rewrite header of headerless file */ + if (O->sr_override || O->kr_override) { + if (!O->sr_override || !O->kr_override) + dieu(csound, Str("srate and krate overrides must occur jointly")); + } + if (!O->outformat) /* if no audioformat yet */ + O->outformat = AE_SHORT; /* default to short_ints */ + O->sfsampsize = sfsampsize(FORMAT2SF(O->outformat)); + O->informat = O->outformat; /* informat default */ + + if (O->numThreads > 1) { void csp_barrier_alloc(CSOUND *, pthread_barrier_t **, int); int i; @@ -442,11 +477,19 @@ } csound->WaitBarrier(csound->barrier2); - - csp_parallel_compute_spec_setup(csound); } -#endif + csound->engineStatus |= CS_STATE_COMP; + if(csound->oparms->daemon > 1) + UDPServerStart(csound,csound->oparms->daemon); return musmon(csound); } + +PUBLIC int csoundCompile(CSOUND *csound, int argc, char **argv){ + + int result = csoundCompileArgs(csound,argc,argv); + + if(result == CSOUND_SUCCESS) return csoundStart(csound); + else return result; +} diff -Nru csound-5.17.11~dfsg/Top/new_opts.c csound-6.02~dfsg/Top/new_opts.c --- csound-5.17.11~dfsg/Top/new_opts.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/new_opts.c 2014-01-07 16:53:48.000000000 +0000 @@ -118,82 +118,94 @@ csCfgVariable_t *p; if (UNLIKELY((int) strlen(s) < 3)) { - csound->Message(csound, Str(" *** '%s' is not a valid " - "Csound command line option.\n"), s); - csound->Message(csound, Str(" *** Type 'csound --help' for the list of " - "available options.\n")); - return -1; + csound->Warning(csound, Str(" *** '%s' is not a valid " + "Csound command line option."), s); + csound->Warning(csound, Str(" *** Type 'csound --help' for the list of " + "available options")); + return 0; } if (UNLIKELY(strncmp(s, "-+", 2) != 0)) { - csound->Message(csound, Str(" *** '%s' is not a valid " - "Csound command line option.\n"), s); - csound->Message(csound, Str(" *** Type 'csound --help' for the list of " - "available options.\n")); - return -1; + csound->Warning(csound, Str(" *** '%s' is not a valid " + "Csound command line option."), s); + csound->Warning(csound, Str(" *** Type 'csound --help' for the list of " + "available options")); + return 0; } if (strchr(s, '=') == NULL) { /* there is no '=' character, must be a boolean */ p = csoundQueryConfigurationVariable(csound, s + 2); if (p != NULL) { if (UNLIKELY(p->h.type != CSOUNDCFG_BOOLEAN)) { - csound->Message(csound, Str(" *** type of option '%s' " - "is not boolean\n"), s + 2); - return -1; + csound->Warning(csound, Str(" *** type of option '%s' " + "is not boolean"), s + 2); + return 0; } *(p->b.p) = 1; } else if (LIKELY((int) strlen(s) > 5)) { if (UNLIKELY(strncmp(s, "-+no-", 5) != 0)) { - csound->Message(csound, Str(" *** '%s': invalid option name\n"), + csound->Warning(csound, Str(" *** '%s': invalid option name"), s + 2); - return -1; + return 0; } p = csoundQueryConfigurationVariable(csound, s + 5); if (UNLIKELY(p == NULL)) { - csound->Message(csound, Str(" *** '%s': invalid option name\n"), + csound->Warning(csound, Str(" *** '%s': invalid option name"), s + 2); return -1; } if (UNLIKELY(p->h.type != CSOUNDCFG_BOOLEAN)) { - csound->Message(csound, Str(" *** type of option '%s' " - "is not boolean\n"), s + 2); - return -1; + csound->Warning(csound, Str(" *** type of option '%s' " + "is not boolean"), s + 2); + return 0; } *(p->b.p) = 0; } else { - csound->Message(csound, Str(" *** '%s': invalid option name\n"), s + 2); - return -1; + csound->Warning(csound, Str(" *** '%s': invalid option name"), s + 2); + return 0; } } else if (LIKELY((int) strlen(s) > 3)) { - char *buf, *val; + char *buf, *val, *tmp; int retval; buf = (char*) malloc(sizeof(char) * (size_t) ((int) strlen(s) - 1)); if (UNLIKELY(buf == NULL)) { - csound->Message(csound, Str(" *** memory allocation failure\n")); + csound->Warning(csound, Str(" *** memory allocation failure")); return -1; } - strcpy(buf, s + 2); + /* strcpy(buf, s + 2); */ + val = (char*) s+2; + tmp = buf; + while (*val!='\0') { + /* + * CAN char used during the parsing in CsOptions to mark + * the removable characters '\'. ETX char used to mark + * the limits of a string. + */ + if (*val != 0x18 && *val != 3) + *tmp++ = *val; + val++; + } + *tmp='\0'; val = strchr(buf, '='); *(val++) = '\0'; /* 'buf' is now the name, 'val' is the value string */ retval = csoundParseConfigurationVariable(csound, buf, val); if (UNLIKELY(retval != CSOUNDCFG_SUCCESS)) { - csound->Message(csound, Str(" *** error setting option '%s' to '%s': " - "%s\n"), - buf, val, csoundCfgErrorCodeToString(retval)); + csound->Warning(csound, + Str(" *** error setting option '%s' to '%s': %s"), + buf, val, csoundCfgErrorCodeToString(retval)); free((void*) buf); - return -1; + return 0; } free((void*) buf); } else { - csound->Message(csound, Str(" *** '%s' is not a valid " - "Csound command line option.\n"), s); - csound->Message(csound, Str(" *** Type 'csound --help' for the list of " - "available options.\n")); - return -1; + csound->Warning(csound, Str(" *** '%s' is not a valid " + "Csound command line option."), s); + csound->Warning(csound, Str(" *** Type 'csound --help' for the list of " + "available options.")); + return 0; } return 0; } - diff -Nru csound-5.17.11~dfsg/Top/one_file.c csound-6.02~dfsg/Top/one_file.c --- csound-5.17.11~dfsg/Top/one_file.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/one_file.c 2014-01-07 16:54:20.000000000 +0000 @@ -56,23 +56,7 @@ const uint32_t csMidiScoMask = 8; const uint32_t csPlayScoMask = 16; -typedef struct namelst { - char *name; - struct namelst *next; -} NAMELST; - -typedef struct { - NAMELST *toremove; - char orcname[L_tmpnam + 4]; - char sconame[L_tmpnam + 4]; - char midname[L_tmpnam + 4]; - int midiSet; - int csdlinecount; - char *orcstr; - char *scostr; -} ONE_FILE_GLOBALS; - -#define ST(x) (((ONE_FILE_GLOBALS*) csound->oneFileGlobals)->x) +#define STA(x) (csound->onefileStatics.x) #if !defined(WIN32) char *mytmpnam(char *name) @@ -89,94 +73,77 @@ #endif -CS_NOINLINE char *csoundTmpFileName(CSOUND *csound, char *buf, const char *ext) +CS_NOINLINE char *csoundTmpFileName(CSOUND *csound, const char *ext) { - size_t nBytes = L_tmpnam+4; - if (buf == NULL) { - nBytes = (size_t) (L_tmpnam); - if (ext != NULL && ext[0] != (char) 0) - nBytes += strlen(ext); - buf = csound->Malloc(csound, nBytes); - } - { + size_t nBytes = 256; + char lbuf[256]; #if defined(LINUX) || defined(__MACH__) - struct stat tmp; - do { + struct stat tmp; #elif defined(WIN32) - struct _stat tmp; - do { + struct _stat tmp; #endif + do { #ifndef WIN32 - // if (UNLIKELY(mytmpnam(buf) == NULL)) - // csound->Die(csound, Str(" *** cannot create temporary file")); - int fd; - char *tmpdir = getenv("TMPDIR"); - if (tmpdir != NULL && tmpdir[0] != '\0') - snprintf(buf, nBytes, "%s/csound-XXXXXX", tmpdir); - else - strcpy(buf, "/tmp/csound-XXXXXX"); - umask(0077); /* ensure exclusive access on buggy implementations of mkstemp */ - if (UNLIKELY((fd = mkstemp(buf)) < 0)) - csound->Die(csound, Str(" *** cannot create temporary file")); - close(fd); - unlink(buf); + int fd; + char *tmpdir = getenv("TMPDIR"); + if (tmpdir != NULL && tmpdir[0] != '\0') + snprintf(lbuf, nBytes, "%s/csound-XXXXXX", tmpdir); + else + strcpy(lbuf, "/tmp/csound-XXXXXX"); + umask(0077); + /* ensure exclusive access on buggy implementations of mkstemp */ + if (UNLIKELY((fd = mkstemp(lbuf)) < 0)) + csound->Die(csound, Str(" *** cannot create temporary file")); + close(fd); + unlink(lbuf); #else - { - char *s = (char*) csoundGetEnv(csound, "SFDIR"); - if (s == NULL) - s = (char*) csoundGetEnv(csound, "HOME"); - s = _tempnam(s, "cs"); - if (UNLIKELY(s == NULL)) - csound->Die(csound, Str(" *** cannot create temporary file")); - strncpy(buf, s, nBytes); - free(s); - } + { + char *s = (char*) csoundGetEnv(csound, "SFDIR"); + if (s == NULL) + s = (char*) csoundGetEnv(csound, "HOME"); + s = _tempnam(s, "cs"); + if (UNLIKELY(s == NULL)) + csound->Die(csound, Str(" *** cannot create temporary file")); + strncpy(lbuf, s, nBytes); + free(s); + } #endif - if (ext != NULL && ext[0] != (char) 0) { + if (ext != NULL && ext[0] != (char) 0) { #if !defined(LINUX) && !defined(__MACH__) && !defined(WIN32) - char *p; - /* remove original extension (does not work on OS X */ - /* and may be a bad idea) */ - if ((p = strrchr(buf, '.')) != NULL) - *p = '\0'; + char *p; + /* remove original extension (does not work on OS X */ + /* and may be a bad idea) */ + if ((p = strrchr(lbuf, '.')) != NULL) + *p = '\0'; #endif - strncat(buf, ext, nBytes); - } + strncat(lbuf, ext, nBytes); + } #ifdef __MACH__ - /* on MacOS X, store temporary files in /tmp instead of /var/tmp */ - /* (suggested by Matt Ingalls) */ - if (strncmp(buf, "/var/tmp/", 9) == 0) { - int i = 3; - do { - i++; - buf[i - 4] = buf[i]; - } while (buf[i] != (char) 0); - } + /* on MacOS X, store temporary files in /tmp instead of /var/tmp */ + /* (suggested by Matt Ingalls) */ + if (strncmp(lbuf, "/var/tmp/", 9) == 0) { + int i = 3; + do { + i++; + lbuf[i - 4] = lbuf[i]; + } while (lbuf[i] != '\0'); + } #endif #if defined(LINUX) || defined(__MACH__) - /* if the file already exists, try again */ - } while (stat(buf, &tmp) == 0); + /* if the file already exists, try again */ + } while (stat(lbuf, &tmp) == 0); #elif defined(WIN32) - } while (_stat(buf, &tmp) == 0); + } while (_stat(lbuf, &tmp) == 0); #endif - } - - return buf; + return strdup(lbuf); } -static void alloc_globals(CSOUND *csound) +static inline void alloc_globals(CSOUND *csound) { - if (UNLIKELY(csound->oneFileGlobals == NULL)) { - csound->oneFileGlobals = mcalloc(csound, sizeof(ONE_FILE_GLOBALS)); + /* if (UNLIKELY(csound->oneFileGlobals == NULL)) { */ + /* csound->oneFileGlobals = mcalloc(csound, sizeof(ONE_FILE_GLOBALS)); */ /* count lines from 0 so that it adds OK to orc/sco counts */ - ST(csdlinecount) = 0; - } -} - -char *get_sconame(CSOUND *csound) -{ - alloc_globals(csound); - return ST(sconame); + STA(csdlinecount) = 0; } static char *my_fgets(CSOUND *csound, char *s, int n, FILE *stream) @@ -191,7 +158,7 @@ break; /* add NULL even if ferror(), spec says 'indeterminate' */ } if (ch == '\n' || ch == '\r') { /* end of line ? */ - ++(ST(csdlinecount)); /* count the lines */ + ++(STA(csdlinecount)); /* count the lines */ *(s++) = '\n'; /* convert */ if (ch == '\r') { ch = getc(stream); @@ -209,18 +176,18 @@ void remove_tmpfiles(CSOUND *csound) /* IV - Feb 03 2005 */ { /* use one fn to delete all temporary files */ alloc_globals(csound); - while (ST(toremove) != NULL) { - NAMELST *nxt = ST(toremove)->next; + while (STA(toremove) != NULL) { + NAMELST *nxt = STA(toremove)->next; #ifdef BETA csoundMessage(csound, Str("Removing temporary file %s ...\n"), - ST(toremove)->name); + STA(toremove)->name); #endif - if (remove(ST(toremove)->name)) + if (remove(STA(toremove)->name)) csoundMessage(csound, Str("WARNING: could not remove %s\n"), - ST(toremove)->name); - mfree(csound, ST(toremove)->name); - mfree(csound, ST(toremove)); - ST(toremove) = nxt; + STA(toremove)->name); + mfree(csound, STA(toremove)->name); + mfree(csound, STA(toremove)); + STA(toremove) = nxt; } } @@ -231,8 +198,8 @@ tmp = (NAMELST*) mmalloc(csound, sizeof(NAMELST)); tmp->name = (char*) mmalloc(csound, strlen(name) + 1); strcpy(tmp->name, name); - tmp->next = ST(toremove); - ST(toremove) = tmp; + tmp->next = STA(toremove); + STA(toremove) = tmp; } /* readingCsOptions should be non-zero when readOptions() is called @@ -244,7 +211,7 @@ char *argv[CSD_MAX_ARGS]; char buffer[CSD_MAX_LINE_LEN]; - alloc_globals(csound); + //alloc_globals(csound); while (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, unf) != NULL) { p = buffer; /* Remove trailing spaces; rather heavy handed */ @@ -286,9 +253,15 @@ csoundDie(csound, Str("More than %d arguments in "), CSD_MAX_ARGS); argv[++argc] = ++p; - while (*p != '"' && *p != '\0') p++; - - if (*p == '"') *p = '\0'; + while (*p != '"' && *p != '\0') { + if (*p == '\\' && *(p+1) != '\0') + p++; + p++; + } + if (*p == '"') { + /* ETX char used to mark the limits of a string */ + *p = (isspace(*(p+1)) ? '\0' : 3); + } break; } @@ -319,6 +292,27 @@ *p = '\0'; break; } + else if (*p=='"') { + int is_escape = 0; + char *old = NULL; + *p=3; /* ETX char used to mark the limits of a string */ + while ((*p != '"' || is_escape) && *p != '\0') { + if (is_escape) + *old = 0x18; /* CAN char used to mark a removable character */ + is_escape = (*p == '\\' ? !is_escape : 0); + old = p; + p++; + } + if (*p == '"') { + if (isspace(*(p+1))) { + *p = '\0'; + break; + } + else { + *p = 3; + } + } + } p++; } #ifdef _DEBUG @@ -338,9 +332,7 @@ } if (UNLIKELY(readingCsOptions)) csoundErrorMsg(csound, Str("Missing end tag ")); - else - ST(csdlinecount) = 0; - return FALSE; + return FALSE; } static int createOrchestra(CSOUND *csound, FILE *unf) @@ -351,15 +343,13 @@ CORFIL *incore = corfile_create_w(); char buffer[CSD_MAX_LINE_LEN]; - csound->orcLineOffset = ST(csdlinecount)+1; + csound->orcLineOffset = STA(csdlinecount)+1; while (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, unf)!= NULL) { p = buffer; while (*p == ' ' || *p == '\t') p++; if (strstr(p, "") == p) { //corfile_flush(incore); -#ifdef ENABLE_NEW_PARSER - if (csound->oparms->newParser) corfile_puts("\n#exit\n", incore); -#endif + corfile_puts("\n#exit\n", incore); corfile_putc('\0', incore); corfile_putc('\0', incore); csound->orchstr = incore; @@ -379,7 +369,7 @@ if (csound->scorestr == NULL) csound->scorestr = corfile_create_w(); - csound->scoLineOffset = ST(csdlinecount); + csound->scoLineOffset = STA(csdlinecount); while (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, unf)!= NULL) { p = buffer; while (*p == ' ' || *p == '\t') p++; @@ -394,12 +384,12 @@ static int createExScore(CSOUND *csound, char *p, FILE *unf) { - char extname[L_tmpnam + 4]; + char *extname; char *q; - char prog[L_tmpnam + 4]; + char prog[256]; void *fd; FILE *scof; - char buffer[CSD_MAX_LINE_LEN]; + char buffer[CSD_MAX_LINE_LEN]; p = strstr(p, "bin=\""); if (UNLIKELY(p==NULL)) { @@ -414,8 +404,9 @@ *q = '\0'; strcpy(prog, p+5); /* after "tempStatus |= csScoInMask; @@ -425,31 +416,32 @@ if (UNLIKELY(fd == NULL)) return FALSE; - csound->scoLineOffset = ST(csdlinecount); + csound->scoLineOffset = STA(csdlinecount); while (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, unf)!= NULL) { p = buffer; if (strstr(p, "") == p) { char sys[1024]; csoundFileClose(csound, fd); - sprintf(sys, "%s %s %s", prog, extname, ST(sconame)); + sprintf(sys, "%s %s %s", prog, extname, STA(sconame)); if (UNLIKELY(system(sys) != 0)) { csoundErrorMsg(csound, Str("External generation failed")); remove(extname); - remove(ST(sconame)); + remove(STA(sconame)); return FALSE; } remove(extname); if (csound->scorestr == NULL) csound->scorestr = corfile_create_w(); - fd = csoundFileOpen(csound, &scof, CSFILE_STD, ST(sconame), "r", NULL); + fd = csoundFileOpenWithType(csound, &scof, CSFILE_STD, STA(sconame), + "r", NULL, CSFTYPE_SCORE, 0); if (UNLIKELY(fd == NULL)) { - remove(ST(sconame)); + remove(STA(sconame)); return FALSE; } while (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, scof)!= NULL) corfile_puts(buffer, csound->scorestr); csoundFileClose(csound, fd); - remove(ST(sconame)); + remove(STA(sconame)); return TRUE; } else fputs(buffer, scof); @@ -467,11 +459,11 @@ while ((c = getc(in)) != '=' && c != '<') { while (c == ' ' || c == '\t' || c == '\n' || c == '\r') { if (c == '\n') { /* count lines */ - ++(ST(csdlinecount)); + ++(STA(csdlinecount)); c = getc(in); } else if (c == '\r') { - ++(ST(csdlinecount)); + ++(STA(csdlinecount)); c = getc(in); if (c == '\n') c = getc(in); /* DOS format */ } @@ -523,18 +515,19 @@ char buffer[CSD_MAX_LINE_LEN]; /* Generate MIDI file name */ - csoundTmpFileName(csound, ST(midname), ".mid"); - fd = csoundFileOpenWithType(csound, &midf, CSFILE_STD, ST(midname), "wb", NULL, - CSFTYPE_STD_MIDI, 1); + if (STA(midname)) free(STA(midname)); + STA(midname) = csoundTmpFileName(csound, ".mid"); + fd = csoundFileOpenWithType(csound, &midf, CSFILE_STD, STA(midname), + "wb", NULL, CSFTYPE_STD_MIDI, 1); if (UNLIKELY(fd == NULL)) { csoundDie(csound, Str("Cannot open temporary file (%s) for MIDI subfile"), - ST(midname)); + STA(midname)); } csound->tempStatus |= csMidiScoMask; read_base64(csound, unf, midf); csoundFileClose(csound, fd); - add_tmpfile(csound, ST(midname)); /* IV - Feb 03 2005 */ - ST(midiSet) = TRUE; + add_tmpfile(csound, STA(midname)); /* IV - Feb 03 2005 */ + STA(midiSet) = TRUE; while (TRUE) { if (my_fgets(csound, buffer, CSD_MAX_LINE_LEN, unf)!= NULL) { p = buffer; @@ -604,7 +597,8 @@ strcpy(filename, p); //sscanf(buffer, "", filename); // if (filename[0] != '\0' && -// filename[strlen(filename) - 1] == '>' && filename[strlen(filename) - 2] == '"') +// filename[strlen(filename) - 1] == '>' && +// filename[strlen(filename) - 2] == '"') // filename[strlen(filename) - 2] = '\0'; if (UNLIKELY((smpf = fopen(filename, "rb")) != NULL)) { fclose(smpf); @@ -690,7 +684,7 @@ csound->SF_csd_licence = licence; return TRUE; } - csoundMessage(csound, "%s", p); + csoundMessage(csound, p); len += strlen(p); licence = mrealloc(csound, licence, len); strncat(licence, p, len); @@ -732,8 +726,8 @@ return 0; } alloc_globals(csound); - ST(orcname)[0] = ST(sconame)[0] = ST(midname)[0] = '\0'; - ST(midiSet) = FALSE; + STA(orcname) = STA(sconame) = STA(midname) = NULL; + STA(midiSet) = FALSE; #ifdef _DEBUG csoundMessage(csound, "Calling unified file system with %s\n", name); #endif @@ -749,10 +743,10 @@ strstr(p, "") == p) { if (csound->scorestr != NULL) corfile_flush(csound->scorestr); - *pname = ST(orcname); - *score = ST(sconame); - if (ST(midiSet)) { - csound->oparms->FMidiname = ST(midname); + *pname = STA(orcname); + *score = STA(sconame); + if (STA(midiSet)) { + csound->oparms->FMidiname = STA(midname); csound->oparms->FMidiin = 1; } csoundFileClose(csound, fd); @@ -792,10 +786,6 @@ r = createExScore(csound, p, unf); result = r && result; } - /* else if (strstr(p, "") == p) { */ - /* r = createMIDI(csound, unf); */ - /* result = r && result; */ - /* } */ else if (strstr(p, "") == p) { r = createMIDI2(csound, unf); result = r && result; @@ -822,15 +812,15 @@ csoundMessage(csound, Str("unknown CSD tag: %s\n"), buffer); } } - if (UNLIKELY(!started)) { + if (UNLIKELY(!started)) { csoundMessage(csound, Str("Could not find tag in CSD file.\n")); result = FALSE; } - *pname = ST(orcname); - *score = ST(sconame); - if (ST(midiSet)) { - csound->oparms->FMidiname = ST(midname); + *pname = STA(orcname); + *score = STA(sconame); + if (STA(midiSet)) { + csound->oparms->FMidiname = STA(midname); csound->oparms->FMidiin = 1; } csoundFileClose(csound, fd); diff -Nru csound-5.17.11~dfsg/Top/opcode.c csound-6.02~dfsg/Top/opcode.c --- csound-5.17.11~dfsg/Top/opcode.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/opcode.c 2014-01-07 16:53:48.000000000 +0000 @@ -65,28 +65,33 @@ char *s; size_t nBytes = (size_t) 0; int i, cnt = 0; + CONS_CELL *head, *items, *temp; (*lstp) = NULL; - i = csoundLoadAllPluginOpcodes(csound); - if (i != 0) - return i; - ep = (OENTRY*) csound->opcodlst; - if (UNLIKELY(ep == NULL)) + if (UNLIKELY(csound->opcodes == NULL)) return -1; + + head = items = cs_hash_table_values(csound, csound->opcodes); + /* count the number of opcodes, and bytes to allocate */ - for ( ; ep < (OENTRY*) csound->oplstend; ep++) { - if (ep->opname != NULL && - ep->opname[0] != '\0' && isalpha(ep->opname[0]) && - ep->outypes != NULL && ep->intypes != NULL) { - cnt++; - nBytes += sizeof(opcodeListEntry); - for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++) - ; - nBytes += (size_t) i; - nBytes += strlen(ep->outypes); - nBytes += strlen(ep->intypes); - nBytes += 3; /* for null characters */ + while (items != NULL) { + temp = items->value; + while (temp != NULL) { + ep = temp->value; + if (ep->opname != NULL && + ep->opname[0] != '\0' && isalpha(ep->opname[0]) && + ep->outypes != NULL && ep->intypes != NULL) { + cnt++; + nBytes += sizeof(opcodeListEntry); + for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++); + nBytes += (size_t) i; + nBytes += strlen(ep->outypes); + nBytes += strlen(ep->intypes); + nBytes += 3; /* for null characters */ + } + temp = temp->next; } + items = items->next; } nBytes += sizeof(opcodeListEntry); /* allocate memory for opcode list */ @@ -95,31 +100,43 @@ return CSOUND_MEMORY; (*lstp) = (opcodeListEntry*) lst; /* store opcodes in list */ - ep = (OENTRY*) csound->opcodlst; + items = head; s = (char*) lst + ((int) sizeof(opcodeListEntry) * (cnt + 1)); - for (cnt = 0; ep < (OENTRY*) csound->oplstend; ep++) { - if (ep->opname != NULL && - ep->opname[0] != '\0' && isalpha(ep->opname[0]) && - ep->outypes != NULL && ep->intypes != NULL) { - for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++) - s[i] = ep->opname[i]; - s[i++] = '\0'; - ((opcodeListEntry*) lst)[cnt].opname = s; - s += i; - strcpy(s, ep->outypes); - ((opcodeListEntry*) lst)[cnt].outypes = s; - s += ((int) strlen(ep->outypes) + 1); - strcpy(s, ep->intypes); - ((opcodeListEntry*) lst)[cnt].intypes = s; - s += ((int) strlen(ep->intypes) + 1); - cnt++; - } + cnt = 0; + while (items != NULL) { + temp = items->value; + while (temp != NULL) { + ep = temp->value; + + if (ep->opname != NULL && + ep->opname[0] != '\0' && isalpha(ep->opname[0]) && + ep->outypes != NULL && ep->intypes != NULL) { + for (i = 0; ep->opname[i] != '\0' && ep->opname[i] != '.'; i++) + s[i] = ep->opname[i]; + s[i++] = '\0'; + ((opcodeListEntry*) lst)[cnt].opname = s; + s += i; + strcpy(s, ep->outypes); + ((opcodeListEntry*) lst)[cnt].outypes = s; + s += ((int) strlen(ep->outypes) + 1); + strcpy(s, ep->intypes); + ((opcodeListEntry*) lst)[cnt].intypes = s; + s += ((int) strlen(ep->intypes) + 1); + cnt++; + } + temp = temp->next; + } + items = items->next; } ((opcodeListEntry*) lst)[cnt].opname = NULL; ((opcodeListEntry*) lst)[cnt].outypes = NULL; ((opcodeListEntry*) lst)[cnt].intypes = NULL; + + cs_cons_free(csound, head); + /* sort list */ qsort(lst, (size_t) cnt, sizeof(opcodeListEntry), opcode_cmp_func); + /* return the number of opcodes */ return cnt; } @@ -157,31 +174,30 @@ xlen = len - 19; len = 19; } - csound->Message(csound, "%s", sp + len); + csound->Message(csound, sp + len); } - csound->Message(csound, "%s", lst[j].opname); + csound->Message(csound, lst[j].opname); len = (int) strlen(lst[j].opname) + xlen; } else { char *ans = lst[j].outypes, *arg = lst[j].intypes; - csound->Message(csound, "%s", lst[j].opname); + csound->Message(csound, lst[j].opname); len = (int) strlen(lst[j].opname); if (len > 11) { xlen = len - 11; len = 11; } - csound->Message(csound, "%s", sp + (len + 8)); + csound->Message(csound, sp + (len + 8)); if (ans == NULL || *ans == '\0') ans = "(null)"; if (arg == NULL || *arg == '\0') arg = "(null)"; - csound->Message(csound, "%s", ans); + csound->Message(csound, ans); len = (int) strlen(ans) + xlen; len = (len < 11 ? len : 11); xlen = 0; - csound->Message(csound, "%s", sp + (len + 8)); + csound->Message(csound, sp + (len + 8)); csound->Message(csound, "%s\n", arg); } } csound->Message(csound, "\n"); csoundDisposeOpcodeList(csound, lst); } - diff -Nru csound-5.17.11~dfsg/Top/server.c csound-6.02~dfsg/Top/server.c --- csound-5.17.11~dfsg/Top/server.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Top/server.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,132 @@ +/* + server.c: + + Copyright (C) 2013 V Lazzarini, John ffitch + + This file is part of Csound. + + The Csound Library is free software; you can redistribute it + and/or modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + Csound is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with Csound; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA +*/ +#ifdef NACL +typedef unsigned int u_int32_t; +#endif + +#include "csoundCore.h" +#ifdef WIN32 +#include +#include +#else +#include +#include +#include +#endif + + + +typedef struct { + int port; + int sock; + CSOUND *cs; + void *thrid; + void *cb; + struct sockaddr_in server_addr; +} UDPCOM; + +#define MAXSTR 1048576 /* 1MB */ + +static uintptr_t udp_recv(void *pdata) +{ + struct sockaddr from; + socklen_t clilen = sizeof(from); + UDPCOM *p = (UDPCOM *) pdata; + CSOUND *csound = p->cs; + int port = p->port; + char *orchestra = csound->Malloc(csound, MAXSTR); + + csound->Message(csound, "UDP server started on port %d \n",port); + while(recvfrom(p->sock, (void *)orchestra, MAXSTR, 0, &from, &clilen) > 0) { + if(csound->oparms->odebug) + csound->Message(csound, "orchestra: \n%s\n", orchestra); + if(strncmp("##close##",orchestra,9)==0) break; + csoundCompileOrc(csound, orchestra); + } + csound->Message(csound, "UDP server on port %d stopped\n",port); + csound->Free(csound, orchestra); + return (uintptr_t) 0; + +} + +static int udp_start(CSOUND *csound, UDPCOM *p) +{ +#ifdef WIN32 + WSADATA wsaData = {0}; + int err; + if ((err=WSAStartup(MAKEWORD(2,2), &wsaData))!= 0) + csound->InitError(csound, Str("Winsock2 failed to start: %d"), err); +#endif + p->cs = csound; + p->sock = socket(AF_INET, SOCK_DGRAM, 0); + if (UNLIKELY(p->sock < 0)) { + return csound->InitError + (csound, Str("creating socket")); + } + /* create server address: where we want to send to and clear it out */ + memset(&p->server_addr, 0, sizeof(p->server_addr)); + p->server_addr.sin_family = AF_INET; /* it is an INET address */ + p->server_addr.sin_addr.s_addr = htonl(INADDR_ANY); + + p->server_addr.sin_port = htons((int) p->port); /* the port */ + /* associate the socket with the address and port */ + if (UNLIKELY(bind(p->sock, (struct sockaddr *) &p->server_addr, + sizeof(p->server_addr)) < 0)){ + csound->Warning(csound, Str("bind failed")); + return NOTOK; + } + /* create thread */ + p->thrid = csoundCreateThread(udp_recv, (void *) p); + + return OK; +} + +int UDPServerClose(CSOUND *csound) +{ + UDPCOM *p = (UDPCOM *) csound->QueryGlobalVariable(csound,"::UDPCOM"); + + if(p != NULL){ + const char *mess = "##close##"; + const struct sockaddr *to = (const struct sockaddr *) (&p->server_addr); + sendto(p->sock,mess,sizeof(mess)+1,0,to,sizeof(p->server_addr)); + csoundJoinThread(p->thrid); +#ifndef WIN32 + close(p->sock); +#else + closesocket(p->sock); +#endif + csound->DestroyGlobalVariable(csound,"::UDPCOM"); + } + return OK; +} + +int UDPServerStart(CSOUND *csound, int port){ + UDPCOM *connection; + csound->CreateGlobalVariable(csound, "::UDPCOM", sizeof(UDPCOM)); + connection = (UDPCOM *) csound->QueryGlobalVariable(csound, "::UDPCOM"); + if(connection != NULL){ + connection->port = port; + return udp_start(csound, connection); + } + else return NOTOK; +} diff -Nru csound-5.17.11~dfsg/Top/threads.c csound-6.02~dfsg/Top/threads.c --- csound-5.17.11~dfsg/Top/threads.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/threads.c 2014-01-07 16:54:20.000000000 +0000 @@ -25,7 +25,8 @@ #endif #ifndef HAVE_GETTIMEOFDAY -#if defined(LINUX) || defined(__unix) || defined(__unix__) || defined(__MACH__) +#if defined(LINUX) || defined(__unix) || defined(__unix__) || \ + defined(__MACH__) || defined(__HAIKU__) #define HAVE_GETTIMEOFDAY 1 #endif #endif @@ -39,7 +40,7 @@ #include #ifndef MSVC -void __stdcall GetSystemTimeAsFileTime(FILETIME*); +//void __stdcall GetSystemTimeAsFileTime(FILETIME*); #endif void gettimeofday_(struct timeval* p, void* tz /* IGNORED */) @@ -85,24 +86,6 @@ Sleep((DWORD) milliseconds); } -#elif defined(mac_classic) - -static CS_NOINLINE void notImplementedWarning_(const char *name) -{ - fprintf(stderr, Str("%s() is not implemented on this platform.\n"), name); -} - -PUBLIC long csoundRunCommand(const char * const *argv, int noWait) -{ - notImplementedWarning_("csoundRunCommand"); - return -1L; -} - -PUBLIC void csoundSleep(size_t milliseconds) -{ - notImplementedWarning_("csoundSleep"); -} - #else #include @@ -168,7 +151,8 @@ -#if defined(LINUX) || defined(__MACH__) || defined(WIN32) +#if defined(LINUX) || defined(__MACH__) || defined(__HAIKU__) || \ + defined(ANDROID) || defined(WIN32) #include #include @@ -183,7 +167,7 @@ #define BARRIER_SERIAL_THREAD (-1) #if !defined(HAVE_PTHREAD_BARRIER_INIT) -#ifndef __MACH__ +#if !defined(__MACH__) && !defined(__HAIKU__) && !defined(ANDROID) && !defined(NACL) typedef struct barrier { pthread_mutex_t mut; @@ -225,7 +209,7 @@ } } -#if !defined(ANDROID) && (defined(LINUX) || defined(WIN32)) +#if !defined(ANDROID) && (defined(LINUX) || defined(__HAIKU__) || defined(WIN32)) PUBLIC void *csoundCreateThreadLock(void) { @@ -382,7 +366,7 @@ PUBLIC void csoundDestroyThreadLock(void *threadLock) { - CsoundThreadLock_t *p; + CsoundThreadLock_t *p; if (threadLock == NULL) return; @@ -391,6 +375,7 @@ pthread_cond_destroy(&(p->c)); pthread_mutex_destroy(&(p->m)); free(threadLock); + } #endif /* !LINUX */ @@ -416,7 +401,7 @@ pthread_barrier_t *barrier = (pthread_barrier_t *) malloc(sizeof(pthread_barrier_t)); int status = pthread_barrier_init(barrier, 0, max-1); - fprintf(stderr, "Create barrier %d => %p ($d)\n", max, barrier, status); + fprintf(stderr, "Create barrier %d => %p (%d)\n", max, barrier, status); if (status) return 0; return barrier; #endif diff -Nru csound-5.17.11~dfsg/Top/threadsafe.c csound-6.02~dfsg/Top/threadsafe.c --- csound-5.17.11~dfsg/Top/threadsafe.c 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/Top/threadsafe.c 2014-01-07 16:54:20.000000000 +0000 @@ -0,0 +1,230 @@ +/* + * threadsafe.c: threadsafe API functions + * (c) V Lazzarini, 2013 + * + * L I C E N S E + * + * This software is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "csoundCore.h" +#include + +#ifdef USE_DOUBLE +# define MYFLT_INT_TYPE int64_t +#else +# define MYFLT_INT_TYPE int32_t +#endif + +extern void csoundInputMessageInternal(CSOUND *csound, const char *message); +extern void set_channel_data_ptr(CSOUND *csound, const char *name, + void *ptr, int newSize); + +void csoundInputMessage(CSOUND *csound, const char *message){ + csoundLockMutex(csound->API_lock); + csoundInputMessageInternal(csound, message); + csoundUnlockMutex(csound->API_lock); +} + +void csoundTableCopyOut(CSOUND *csound, int table, MYFLT *ptable){ + int len; + MYFLT *ftab; + + csoundLockMutex(csound->API_lock); + /* in realtime mode init pass is executed in a separate thread, so + we need to protect it */ + if(csound->oparms->realtime) csoundLockMutex(csound->init_pass_threadlock); + len = csoundGetTable(csound, &ftab, table); + memcpy(ptable, ftab, len*sizeof(MYFLT)); + if(csound->oparms->realtime) csoundUnlockMutex(csound->init_pass_threadlock); + csoundUnlockMutex(csound->API_lock); +} + +void csoundTableCopyIn(CSOUND *csound, int table, MYFLT *ptable){ + int len; + MYFLT *ftab; + csoundLockMutex(csound->API_lock); + /* in realtime mode init pass is executed in a separate thread, so + we need to protect it */ + if(csound->oparms->realtime) csoundLockMutex(csound->init_pass_threadlock); + len = csoundGetTable(csound, &ftab, table); + memcpy(ftab, ptable, len*sizeof(MYFLT)); + if(csound->oparms->realtime) csoundUnlockMutex(csound->init_pass_threadlock); + csoundUnlockMutex(csound->API_lock); +} + +MYFLT csoundGetControlChannel(CSOUND *csound, const char *name, int *err) +{ + MYFLT *pval; + int err_; + union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.d = FL(0.0); + if ((err_ = csoundGetChannelPtr(csound, &pval, name, + CSOUND_CONTROL_CHANNEL | CSOUND_OUTPUT_CHANNEL)) + == CSOUND_SUCCESS) { +#ifdef HAVE_ATOMIC_BUILTIN + x.i = __sync_fetch_and_add((MYFLT_INT_TYPE *)pval, 0); +#else + x.d = *pval; +#endif + } + if (err) { + *err = err_; + } + return x.d; +} + +void csoundSetControlChannel(CSOUND *csound, const char *name, MYFLT val){ + MYFLT *pval; + union { + MYFLT d; + MYFLT_INT_TYPE i; + } x; + x.d = val; + if(csoundGetChannelPtr(csound, &pval, name, + CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL) + == CSOUND_SUCCESS) +#ifdef HAVE_ATOMIC_BUILTIN + __sync_lock_test_and_set((MYFLT_INT_TYPE *)pval,x.i); +#else + { + int *lock = + csoundGetChannelLock(csound, (char*) name); + csoundSpinLock(lock); + *pval = val; + csoundSpinUnLock(lock); + } +#endif +} + +void csoundGetAudioChannel(CSOUND *csound, const char *name, MYFLT *samples) +{ + + MYFLT *psamples; + + if (csoundGetChannelPtr(csound, &psamples, name, + CSOUND_AUDIO_CHANNEL | CSOUND_OUTPUT_CHANNEL) + == CSOUND_SUCCESS) { + int *lock = csoundGetChannelLock(csound, (char*) name); + csoundSpinLock(lock); + memcpy(samples, psamples, csoundGetKsmps(csound)*sizeof(MYFLT)); + csoundSpinUnLock(lock); + } +} + +void csoundSetAudioChannel(CSOUND *csound, const char *name, MYFLT *samples) +{ + MYFLT *psamples; + if (csoundGetChannelPtr(csound, &psamples, name, + CSOUND_AUDIO_CHANNEL | CSOUND_INPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = csoundGetChannelLock(csound, (char*) name); + csoundSpinLock(lock); + memcpy(psamples, samples, csoundGetKsmps(csound)*sizeof(MYFLT)); + csoundSpinUnLock(lock); + } +} + +void csoundSetStringChannel(CSOUND *csound, const char *name, char *string) +{ + MYFLT *pstring; + + if (csoundGetChannelPtr(csound, &pstring, name, + CSOUND_STRING_CHANNEL | CSOUND_INPUT_CHANNEL) + == CSOUND_SUCCESS){ + + STRINGDAT* stringdat = (STRINGDAT*) pstring; + int size = stringdat->size; //csoundGetChannelDatasize(csound, name); + int *lock = csoundGetChannelLock(csound, (char*) name); + + csoundSpinLock(lock); + if(strlen(string) + 1 > (unsigned int) size) { + if(stringdat->data!=NULL) mfree(csound,stringdat->data); + stringdat->data = cs_strdup(csound, string); + stringdat->size = strlen(string) + 1; + //set_channel_data_ptr(csound,name,(void*)pstring, strlen(string)+1); + } else strcpy((char *) stringdat->data, string); + csoundSpinUnLock(lock); + } +} + +void csoundGetStringChannel(CSOUND *csound, const char *name, char *string) +{ + MYFLT *pstring; + if (csoundGetChannelPtr(csound, &pstring, name, + CSOUND_STRING_CHANNEL | CSOUND_OUTPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = csoundGetChannelLock(csound, (char*) name); + csoundSpinLock(lock); + strcpy(string, ((STRINGDAT *) pstring)->data); + csoundSpinUnLock(lock); + } +} + +PUBLIC int csoundSetPvsChannel(CSOUND *csound, const PVSDATEXT *fin, + const char *name) +{ + MYFLT *pp; + PVSDATEXT *f; + if (csoundGetChannelPtr(csound, &pp, name, + CSOUND_PVS_CHANNEL | CSOUND_INPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = + csoundGetChannelLock(csound, name); + f = (PVSDATEXT *) pp; + csoundSpinLock(lock); + + + if(f->frame == NULL) { + f->frame = mcalloc(csound, sizeof(float)*(fin->N+2)); + } else if(f->N < fin->N) { + f->frame = mrealloc(csound, f->frame, sizeof(float)*(fin->N+2)); + } + + memcpy(f, fin, sizeof(PVSDATEXT)-sizeof(float *)); + if(fin->frame != NULL) + memcpy(f->frame, fin->frame, (f->N+2)*sizeof(float)); + csoundSpinUnLock(lock); + } else { + return CSOUND_ERROR; + } + return CSOUND_SUCCESS; +} + +PUBLIC int csoundGetPvsChannel(CSOUND *csound, PVSDATEXT *fout, + const char *name) +{ + MYFLT *pp; + PVSDATEXT *f; + if (csoundGetChannelPtr(csound, &pp, name, + CSOUND_PVS_CHANNEL | CSOUND_OUTPUT_CHANNEL) + == CSOUND_SUCCESS){ + int *lock = + csoundGetChannelLock(csound, name); + f = (PVSDATEXT *) pp; + if(pp == NULL) return CSOUND_ERROR; + csoundSpinLock(lock); + memcpy(fout, f, sizeof(PVSDATEXT)-sizeof(float *)); + if(fout->frame != NULL && f->frame != NULL) + memcpy(fout->frame, f->frame, sizeof(float)*(fout->N)); + csoundSpinUnLock(lock); + } else { + return CSOUND_ERROR; + } + return CSOUND_SUCCESS; +} diff -Nru csound-5.17.11~dfsg/Top/utility.c csound-6.02~dfsg/Top/utility.c --- csound-5.17.11~dfsg/Top/utility.c 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/Top/utility.c 2014-01-07 16:53:48.000000000 +0000 @@ -36,7 +36,8 @@ int (*UtilFunc)(CSOUND*, int, char**)) { csUtility_t *p; - /* csound->Message(csound, "csoundAddUtility: name: %s function: 0x%p\n", name, UtilFunc); */ + /* csound->Message(csound, "csoundAddUtility: name: %s function: 0x%p\n", + name, UtilFunc); */ if (csound == NULL || name == NULL || name[0] == '\0' || UtilFunc == NULL) return -1; p = (csUtility_t*) csound->utility_db; @@ -94,7 +95,7 @@ break; p = p->nxt; } - csound->engineState |= CS_STATE_UTIL; + csound->engineStatus |= CS_STATE_UTIL; csound->scorename = csound->orchname = (char*) name; /* needed ? */ csound->Message(csound, Str("util %s:\n"), name); n = p->UtilFunc(csound, argc, argv); @@ -119,7 +120,7 @@ csound->Message(csound, " %s\n", lst[i]); } } - csound->DeleteUtilityList(csound, lst); + csoundDeleteUtilityList(csound, lst); n = -1; err_return: memcpy((void*) &(csound->exitjmp), (void*) saved_exitjmp, sizeof(jmp_buf)); diff -Nru csound-5.17.11~dfsg/What_is_New.txt csound-6.02~dfsg/What_is_New.txt --- csound-5.17.11~dfsg/What_is_New.txt 1970-01-01 00:00:00.000000000 +0000 +++ csound-6.02~dfsg/What_is_New.txt 2014-01-07 16:53:48.000000000 +0000 @@ -0,0 +1,347 @@ +Changes since 6.00RC2 (from logs) +===================== + +Many bug fixes and code improvements + +New opcodes: faustgen, array + +Added 0dbfs and nchnls override + +Added delete tree to the API + +Greatly improve array arithmetic operations + +Removed limit on number of instances in parallel code + +Fixed schedwhen for named instrs + +Change to escape characters in score strings -- they do not happen +(this is still subject to change) + +Fixed dssi + +Use thread-safe internal functions in compilaton etc + +Thread-safe use of locales + +String variables re-implemented + + +What is New, What has Changed +============================= + +- Build system in cmake (and not scons as in Csound5). + + - The loadable opcodes are found in the directory named in the +environment variables OPCODE6DIR64 or OPCODE6DIR (note the 6) so it +can co-exist with Csound5 + +- Support for old hardware and C compilers has been removed; this +includes Macintosh OS9 and earlier, Watcom, Borland and Symmantec C +compilers. + +- Note events can start and end in mid-kcycle. As this is an +incompatible change it is only invoked with the command-line option + --sample-accurate +is specified. Not that this does not work for tied notes, and use of +skipping initialisation has questionable use. + +- Instruments can run at local ksmps values using + +setksmps iksmps + +as in Csound 5 UDOs. + +- A number of table access opcodes have been rewritten but should behave +the same. Similarly diskin and diskin2 now use the same code and so +diskin should be more stable + +- Compilation can be done at any stage, new instruments are added or +replace old ones. Running instances of old instrument definitions are +not affected. Only limitation is that header constants in instr 0 are +read only once at the time of the first compilation. Init-time code +can be placed outside instruments in the global space, and this will +be executed once-only following the compilation. In this case, score +event generation can be completely replaced by orchestra code. + +- Two i-time opcodes for compilation: +ires compileorc ifilename +compiles an orchestra in ifilename (instr0 ignored) + +ires compilestr Sinstruments +compiles an orchestra defined in Sinstruments + +ires is 0 if successful and non-0 if compilation failed. + + - An i-time opcode for score compilation: + +ires readscore Sco +this opcode runs the score preprocessor on Sco and then schedules +new events via the RT event mechanism. + +- The old parser is totally gone. + +- New syntax in csound6 includes +=, -=, *= and /= operators +Please use += and -= for accumulating reverbs as it gives better +multicore behaviour. + +- Multicore support is totally rewritten using a different algorithm for +task-dispatch, which should use less memory and fewer locks. + +- Opcodes like add, sub, mul and div are no longer available in opcode +format, only via + - * / + +- Any opcode that returns one answer and whose type is the same as the +first argument can be used as a function. This incorporates all +functions in CS5, but also functions of two arguments such as taninv2 +and divz, and opcodes like vco2. + +- A statement can be broken across lines after a , = or arithmetic +operation. + +- Arrays exist in multidimensional format. They are created (usually) +with init opcode or fillarray + k1[] init 4 +generates a k-rate 1-D array of length 4. Similarly + a2[][] init 4,4 +create a square 4x4 a-rate array. + k2[] fillarray 1,2,3,4 +creates a 4-element vector filled with 1,..4, which also defines the +length. + +- Elements are used via indexing in [] such as k1[2] or a2[2][3] +One dimensional arrays replace tvars, and can be used in opcodes like +maxtab, mintab and sumtab (see below). Array setting can be done in +left-hand side of opcodes, i.e.: + aSigs[0] vco2 .1, 440 + aSigs[1] vco2 .1, 880 + +- There are a range of new or recoded operations on k-valued arrays, + most restricted to 1 dimensional arrays (vectors): + kans minarray ktab returns the smallest value in the + (possibly) multidimensional array + kans maxarray ktab is like mintab + kabs sumarray ktab returns sum of all values in the array + ktab genarray imin, imax[, inc] + generates vector of values from imin to imax by + increments of inc (default 1) + ktab2 maparray ktab1, "sin" maps the k-rate 1-arg function in the string to + every element of the vector + ktab2 maparray_i ktab1, "sin" maps the i-rate 1-arg function in the string + to every element of the vector + ktab2 slicearray ktab1, istart, iend + returns a slice of ktab1 from ktab1[istart] + to ktab1[iend] + copyf2array ktab, kfn copies data from an ftable to a vector + copya2ftab ktab, kfn copies data from a vector to an ftable. + +In addition arithmetic on arrays is allowed. In particular addition, +subtraction, multiplication, division on a element-by-element version +is provided in arithmetic format. Similar operations between an array +and a scalar are allowed. + +- The new realtime priority mode can be switched on with by passing the +--realtime or setting the CSOUND_PARAMS field realtime_mode to 1. + +This has the following effects: +1) all opcode audio file reading/writing is handled asynchronously by +a separate thread +2) all init-pass operations are also performed asynchronously. + +Functions for asynchronous audio file access have been added (see +below) + + +The k() fumction can take an a-rate argument in which case it is a +call to downsamp. + + +Analysis formats: +Hetro/adsyn analysis files can be machine byte-order independent if +created with -X. Down side is a longer file and a little slower +loading. The het_export utility will create the independent format +from the old, and het_import is no longer necessary. + +cvanal and lpanal will produce machine independent files if -X option +is used. The convolve and lpread etc opcodes will accept either +format. You are encouraged to use the machine independent form. +Analysis files produced with -X can be used on other systems. + +The number of strings that can be used in a score line is no longer +just one. It is open ended. + +Each instance of any instrument has a scratchpad of 4 values that +persist; allows values to carry to next use of the instrument; hope it +may be useful in legato etc. + +If a table number is given as -1 then an internal sine wave equivalent +to "f. 0 16382 10 1" is used. Attempts to write to this table will +give unpredictable results, but is not policed. The 16382 can be +change by command line option --sine-size=# where the # is rounded up +to a power of two. + +A number of oscil opcodes no have the f-table parameter as optional, +defaulting to the internal sine wave. +(oscil1, oscil1i, oscil, oscil3, oscili, foscil, foscil1, +loscil, loscil3) + + +in Linux and OSX the treatment of locales is now thread-safe and +local. + + +New API functions..... + + new configuration/parameter setting functions + PUBLIC int csoundSetOption(CSOUND *csound, char *option); + PUBLIC void csoundSetParams(CSOUND *csound, CSOUND_PARAMS *p); + PUBLIC void csoundGetParams(CSOUND *csound, CSOUND_PARAMS *p); + PUBLIC void csoundSetOutput(CSOUND *csound, char *name, char *type, + char *format); + PUBLIC void csoundSetInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIFileInput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIOutput(CSOUND *csound, char *name); + PUBLIC void csoundSetMIDIFileOutput(CSOUND *csound, char *name); + + new parsing/compilation functions + PUBLIC TREE *csoundParseOrc(CSOUND *csound, char *str); + PUBLIC int csoundCompileTree(CSOUND *csound, TREE *root); + PUBLIC int csoundCompileOrc(CSOUND *csound, const char *str); + PUBLIC int csoundReadScore(CSOUND *csound, char *str); + PUBLIC int csoundCompileArgs(CSOUND *, int argc, char **argv); + + new function for starting csound after first compilation + PUBLIC int csoundStart(CSOUND *csound); + + new software bus threadsafe getters/setters + PUBLIC MYFLT csoundGetControlChannel(CSOUND *csound, const char *name); + PUBLIC void csoundSetControlChannel(CSOUND *csound, const char *name, + MYFLT val); + PUBLIC void csoundGetAudioChannel(CSOUND *csound, const char *name, + MYFLT *samples); + PUBLIC void csoundSetAudioChannel(CSOUND *csound, const char *name, + MYFLT *samples); + PUBLIC void csoundSetStringChannel(CSOUND *csound, const char *name, + char *string); + PUBLIC void csoundGetStringChannel(CSOUND *csound, const char *name, + char *string); + + new table threadsafe copy functions + PUBLIC void csoundTableCopyOut(CSOUND *csound, int table, MYFLT *dest); + PUBLIC void csoundTableCopyIn(CSOUND *csound, int table, MYFLT *src); + + API has been made threadsafe so that performance and control can + occur in separate threads (after a call to csoundStart() or + csoundCompile()). Threadsafety is ensure by 1) use of atomic + read/writing to control channels 2) spinlocks in audio and string + channels 3) mutexes protecting compilation, score events and table access + +Invalue/outvalue and channel callbacks and callback setters have been removed. +csoundQueryInterface() has been removed + +New internal functions in CSOUND: + + void (*FlushCircularBuffer)(CSOUND *, void *); + flush circular buffer. + void *(*FileOpenAsync)(CSOUND *, void *, int, const char *, void *, + const char *, int, int, int); + unsigned int (*ReadAsync)(CSOUND *, void *, MYFLT *, int); + unsigned int (*WriteAsync)(CSOUND *, void *, MYFLT *, int); + int (*FSeekAsync)(CSOUND *, void *, int, int); + async file access. + char *(*GetString)(CSOUND *, MYFLT); + Extract a string originating from a score-event argument. + +functions removed + void *(*FileOpen)(CSOUND *, + void*, int, const char*, void*, const char*); + +The "private" parts of the API have been changed considerably. Also +structures like EVTBLK have changed + + + +The LINKAGE1/FLINKAGE1 macros are renamed as LINKAGE_BUILTIN/FLINKAGE_BUILTIN + + + +Template for arate perf-pass opcodes is +------------------------------------------------------------------------ +int perf_myopcode(CSOUND *csound, MYOPCODE *p) +{ + uint32_t offset = p->h.insdshead->ksmps_offset; + uint32_t early = p->h.insdshead->ksmps_no_end; + uint32_t nsmps = CS_KSMPS; + ... + if (UNLIKELY(offset)) memset(p->res, '\0', offset*sizeof(MYFLT)); + if (UNLIKELY(early)) { + nsmps -= early; + memset(&p->res[nsmps], '\0', early*sizeof(MYFLT)); + } + for (n=offset; nres[n] = .... + } + return OK; +} +------------------------------------------------------------------------ + + +for opcode developers..... + +TECHNICAL CHANGES +================= + +OENTRY structure has changed and has a new dependency field; please +use this field as it is required for multicore semantics. You could +set it to -1 and disallow all parallelism, but at least it is safe. + +All opcodes that touch audio should take note of sample-accurate code + +A number of previous API functions are removed; OpenFile and OpenFile2 +both replaced by new OpenFile2 with additional argument. + +Additions have been made for arg type specifications for opcodes. + * Any-types have been added, as follows: + * '.' signifies a required arg of any-type + * '?' signifies an optional arg of any-type + * '*' signifies a var-arg list of any-type + * Arrays are now specified using "[x]" where x is a type-specifier. + The type-specifier can be any of the of the current specifiers, + including any-types. See Opcodes/arrays.c for example usage. + +New Type System +=============== +A new type system has been added to Csound6, and significant changes +have been made to the compiler. The previous system for handling types +involved depending on the first-letter of a variable's name every time +it was used to determine type. This meant there was a lot of re-checking +of types. Also, adding new types was difficult, as there was a lot of +custom code that had to be updated to check for new type letters. + +In Csound6, a separate system of types was added. Types are defined as +CS_TYPE's. The creation of variables from types and the initialisation +of memory has been encapsulated within the CS_TYPE's. This change +allows easier addition of new types, as well as generic calculations of +memory pools, amongst other things. + +The compiler has been modified since Csound5 to now use the type system +as an integral part of its semantic checking phase. Variables are now +registered into a CS_VAR_POOL when they are first defined, with the +CS_VARIABLE having a reference to its CS_TYPE. After first time +definition within the pool, the type information is then looked up in +consequent variable lookups, rather than re-calculated from the variable +name. This opens up possibilities for new variable naming and typing +strategies, i.e. using "myVar:K" to denote a k-rate arg. This also +opens up possibilities for user-defined types, such as +"data myType kval, aval", then using "myVar:myType" to define a var +of that type. (The previous is speculative, and is not an active +proposal at this time.) + +The addition of the type system has formalised the static type system +that has existed in Csound prior to Csound6. It has, arguably, simplified +the code-base in terms of type handling, as well as laid the ground work +for future type-related research to be integrated into Csound. + + diff -Nru csound-5.17.11~dfsg/after_osx csound-6.02~dfsg/after_osx --- csound-5.17.11~dfsg/after_osx 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/after_osx 1970-01-01 00:00:00.000000000 +0000 @@ -1,2 +0,0 @@ -#!/bin/sh -/Developer/Tools/Rez -i APPL -o csound cs5.r diff -Nru csound-5.17.11~dfsg/all_string_files csound-6.02~dfsg/all_string_files --- csound-5.17.11~dfsg/all_string_files 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/all_string_files 2014-01-07 16:54:20.000000000 +0000 @@ -1,16 +1,19 @@ ./Engine/auxfd.c ./Engine/cfgvar.c ./Engine/corfiles.c +./Engine/cs_new_dispatch.c +./Engine/cs_par_base.c +./Engine/cs_par_dispatch.c +./Engine/cs_par_orc_semantic_analysis.c +./Engine/csound_data_structures.c ./Engine/csound_orc_compile.c ./Engine/csound_orc_expressions.c ./Engine/csound_orc_optimize.c ./Engine/csound_orc_semantics.c -./Engine/cs_par_base.c -./Engine/cs_par_dispatch.c -./Engine/cs_par_orc_semantic_analysis.c +./Engine/csound_standard_types.c +./Engine/csound_type_system.c ./Engine/entry1.c ./Engine/envvar.c -./Engine/express.c ./Engine/extract.c ./Engine/fgens.c ./Engine/insert.c @@ -20,163 +23,32 @@ ./Engine/musmon.c ./Engine/namedins.c ./Engine/new_orc_parser.c -./Engine/otran.c ./Engine/parse_param.h -./Engine/rdorch.c +./Engine/pools.c ./Engine/rdscor.c ./Engine/scsort.c ./Engine/scxtract.c ./Engine/sort.c ./Engine/sread.c -./Engine/swrite.c ./Engine/swritestr.c ./Engine/symbtab.c ./Engine/twarp.c ./Engine/typetabl.h -./frontends/cscore/cscore.c -./frontends/cscore/cscoremain.c -./frontends/cscore/cscoremain_MacOS9.c -./frontends/cseditor/cseditor.cxx -./frontends/csladspa/csladspa.cpp -./frontends/csladspa/ladspa.h -./frontends/CsoundAC/Cell.cpp -./frontends/CsoundAC/Cell.hpp -./frontends/CsoundAC/Composition.cpp -./frontends/CsoundAC/Composition.hpp -./frontends/CsoundAC/Conversions.cpp -./frontends/CsoundAC/Conversions.hpp -./frontends/CsoundAC/Counterpoint.cpp -./frontends/CsoundAC/Counterpoint.hpp -./frontends/CsoundAC/CounterpointMain.cpp -./frontends/CsoundAC/CounterpointNode.cpp -./frontends/CsoundAC/CounterpointNode.hpp -./frontends/CsoundAC/Event.cpp -./frontends/CsoundAC/Event.hpp -./frontends/CsoundAC/Exception.hpp -./frontends/CsoundAC/Hocket.cpp -./frontends/CsoundAC/Hocket.hpp -./frontends/CsoundAC/ImageToScore.cpp -./frontends/CsoundAC/ImageToScore.hpp -./frontends/CsoundAC/Lindenmayer.cpp -./frontends/CsoundAC/Lindenmayer.hpp -./frontends/CsoundAC/MCRM.cpp -./frontends/CsoundAC/MCRM.hpp -./frontends/CsoundAC/Midifile.cpp -./frontends/CsoundAC/Midifile.hpp -./frontends/CsoundAC/MusicModel.cpp -./frontends/CsoundAC/MusicModel.hpp -./frontends/CsoundAC/Node.cpp -./frontends/CsoundAC/Node.hpp -./frontends/CsoundAC/OrchestraNode.hpp -./frontends/CsoundAC/Platform.hpp -./frontends/CsoundAC/Random.cpp -./frontends/CsoundAC/Random.hpp -./frontends/CsoundAC/Rescale.cpp -./frontends/CsoundAC/Rescale.hpp -./frontends/CsoundAC/Score.cpp -./frontends/CsoundAC/Score.hpp -./frontends/CsoundAC/ScoreNode.cpp -./frontends/CsoundAC/ScoreNode.hpp -./frontends/CsoundAC/Sequence.cpp -./frontends/CsoundAC/Sequence.hpp -./frontends/CsoundAC/Shell.cpp -./frontends/CsoundAC/Shell.hpp -./frontends/CsoundAC/Silence.hpp -./frontends/CsoundAC/Soundfile.cpp -./frontends/CsoundAC/Soundfile.hpp -./frontends/CsoundAC/StrangeAttractor.cpp -./frontends/CsoundAC/StrangeAttractor.hpp -./frontends/CsoundAC/System.cpp -./frontends/CsoundAC/System.hpp -./frontends/CsoundAC/Voicelead.cpp -./frontends/CsoundAC/Voicelead.hpp -./frontends/CsoundAC/VoiceleadingNode.cpp -./frontends/CsoundAC/VoiceleadingNode.hpp -./frontends/csoundapi_tilde/csoundapi_tilde.c -./frontends/csound/csound_main.c -./frontends/csound/sched.c -./frontends/CsoundVST/CsoundVST.cpp -./frontends/CsoundVST/CsoundVstFltk.cpp -./frontends/CsoundVST/CsoundVstFltk.hpp -./frontends/CsoundVST/CsoundVST.hpp -./frontends/CsoundVST/csoundvst_main.cpp -./frontends/CsoundVST/CsoundVSTMain.cpp -./frontends/CsoundVST/CsoundVstUi.cpp -./frontends/CsoundVST/CsoundVstUi.h -./frontends/CsoundVST/Platform.hpp -./frontends/CsoundVST/pyrun.c -./frontends/CsoundVST/ScoreGenerator.cpp -./frontends/CsoundVST/ScoreGenerator.hpp -./frontends/CsoundVST/ScoreGeneratorVst.cpp -./frontends/CsoundVST/ScoreGeneratorVstFltk.cpp -./frontends/CsoundVST/ScoreGeneratorVstFltk.hpp -./frontends/CsoundVST/ScoreGeneratorVst.hpp -./frontends/CsoundVST/ScoreGeneratorVstMain.cpp -./frontends/CsoundVST/ScoreGeneratorVstUi.cpp -./frontends/CsoundVST/ScoreGeneratorVstUi.h -./frontends/flcsound/canvas.cpp -./frontends/flcsound/canvas.hpp -./frontends/flcsound/curve.cpp -./frontends/flcsound/curve.hpp -./frontends/flcsound/main.cpp -./frontends/flcsound/plots.cpp -./frontends/flcsound/plots.hpp -./frontends/flcsound/px2pt.c -./frontends/flcsound/synthesizer.cpp -./frontends/flcsound/synthesizer.hpp -./frontends/flcsound/u2d.c -./frontends/fltk_gui/common.cxx -./frontends/fltk_gui/ConfigFile.cpp -./frontends/fltk_gui/ConfigFile.hpp -./frontends/fltk_gui/CsoundCopyrightInfo.cpp -./frontends/fltk_gui/CsoundCopyrightInfo.hpp -./frontends/fltk_gui/CsoundEditor.cpp -./frontends/fltk_gui/CsoundEditor.hpp -./frontends/fltk_gui/CsoundGlobalSettings.cpp -./frontends/fltk_gui/CsoundGlobalSettings.hpp -./frontends/fltk_gui/CsoundGUIConsole.cpp -./frontends/fltk_gui/CsoundGUI.hpp -./frontends/fltk_gui/CsoundGUIMain.cpp -./frontends/fltk_gui/CsoundPerformance.cpp -./frontends/fltk_gui/CsoundPerformance.hpp -./frontends/fltk_gui/CsoundPerformanceSettings.cpp -./frontends/fltk_gui/CsoundPerformanceSettings.hpp -./frontends/fltk_gui/CsoundPerformanceSettingsPanel.cpp -./frontends/fltk_gui/CsoundUtility.cpp -./frontends/fltk_gui/CsoundUtility.hpp -./frontends/fltk_gui/Fl_Native_File_Chooser.cxx -./frontends/fltk_gui/Fl_Native_File_Chooser_FLTK.cxx -./frontends/fltk_gui/Fl_Native_File_Chooser_MAC.cxx -./frontends/fltk_gui/Fl_Native_File_Chooser_WIN32.cxx -./frontends/fltk_gui/Keywords.cpp -./frontends/fltk_gui/main.cpp -./frontends/OSX/main.c -./frontends/tclcsound/commands.c -./frontends/tclcsound/main_tclsh.c -./frontends/tclcsound/main_wish.c -./frontends/tclcsound/tclcsound.c -./frontends/tclcsound/tclcsound.h -./frontends/winsound/main.cxx -./frontends/winsound/winsound.cxx -./frontends/winsound/winsound.h ./H/aops.h ./H/bus.h -./H/cfgvar.h ./H/cmath.h +./H/compile_ops.h ./H/convolve.h ./H/corfile.h -./H/cscore.h -./H/csdl.h ./H/csGblMtx.h ./H/cs_jack.h +./H/cs_par_base.h +./H/cs_par_dispatch.h +./H/cs_par_ops.h +./H/cs_par_orc_semantics.h ./H/csmodule.h -./H/csoundCore.h -./H/csound.h -./H/csound.hpp ./H/csound_orc.h -./H/cwindow.h ./H/diskin2.h -./H/diskin.h ./H/disprep.h ./H/dumpf.h ./H/entry1.h @@ -192,25 +64,19 @@ ./H/midiops.h ./H/midiout.h ./H/mp3dec.h +./H/mp3dec_internal.h ./H/mpadec.h -./H/msg_attr.h ./H/namedins.h ./H/new_opts.h ./H/oload.h -./H/OpcodeBase.hpp ./H/oscils.h ./H/prototyp.h -./H/pstream.h -./H/pvfileio.h ./H/remote.h -./H/resource.h +./H/resize.h ./H/schedule.h ./H/sndinfUG.h ./H/sort.h -./H/soundio.h ./H/str_ops.h -./H/sysdep.h -./H/text.h ./H/tok.h ./H/ugens1.h ./H/ugens2.h @@ -221,12 +87,14 @@ ./H/ugens7.h ./H/ugrw1.h ./H/ugrw2.h +./H/ugtabs.h ./H/vdelay.h -./H/version.h -./H/windin.h ./H/winEPS.h +./H/windin.h ./InOut/FL_graph.cpp +./InOut/circularbuffer.c ./InOut/cmidi.c +./InOut/ipmidi.c ./InOut/libsnd.c ./InOut/libsnd_u.c ./InOut/midifile.c @@ -235,19 +103,10 @@ ./InOut/pmidi.c ./InOut/rtalsa.c ./InOut/rtauhal.c -./InOut/rtcoreaudio.c ./InOut/rtjack.c ./InOut/rtpa.c ./InOut/rtpulse.c ./InOut/rtwinmm.c -./InOut/widgets.h -./InOut/widglobals.h -./InOut/winascii.c -./InOut/windin.c -./InOut/window.c -./InOut/winEPS.c -./InOut/winFLTK.c -./InOut/winFLTK.h ./InOut/virtual_keyboard/Bank.cpp ./InOut/virtual_keyboard/Bank.hpp ./InOut/virtual_keyboard/FLTKKeyboard.cpp @@ -265,27 +124,20 @@ ./InOut/virtual_keyboard/SliderData.cpp ./InOut/virtual_keyboard/SliderData.hpp ./InOut/virtual_keyboard/virtual_keyboard.cpp -./interfaces/CppSound.cpp -./interfaces/CppSound.hpp -./interfaces/cs_glue.cpp -./interfaces/cs_glue.hpp -./interfaces/CsoundFile.cpp -./interfaces/CsoundFile.hpp -./interfaces/csPerfThread.cpp -./interfaces/csPerfThread.hpp -./interfaces/filebuilding.cpp -./interfaces/filebuilding.h -./interfaces/java_interface_wrap.h -./interfaces/pyMsgCb.cpp -./interfaces/pyMsgCb_stub.cpp -./interfaces/python_interface_wrap.h -./interfaces/Soundfile.cpp -./interfaces/Soundfile.hpp +./InOut/widgets.cpp +./InOut/widgets.h +./InOut/widglobals.h +./InOut/winEPS.c +./InOut/winFLTK.c +./InOut/winFLTK.h +./InOut/winascii.c +./InOut/windin.c +./InOut/window.c ./OOps/aops.c ./OOps/bus.c ./OOps/cmath.c +./OOps/compile_ops.c ./OOps/diskin2.c -./OOps/diskin.c ./OOps/disprep.c ./OOps/dumpf.c ./OOps/fftlib.c @@ -305,17 +157,24 @@ ./OOps/str_ops.c ./OOps/ugens1.c ./OOps/ugens2.c +./OOps/ugens2a.c ./OOps/ugens3.c ./OOps/ugens4.c ./OOps/ugens5.c ./OOps/ugens6.c ./OOps/ugrw1.c ./OOps/ugrw2.c +./OOps/ugtabs.c ./OOps/vdelay.c ./Opcodes/3Dug.h -./Opcodes/ambicode1.c +./Opcodes/LuaCsound.cpp +./Opcodes/OSC.c +./Opcodes/Vosim.c +./Opcodes/afilters.c ./Opcodes/ambicode.c +./Opcodes/ambicode1.c ./Opcodes/ampmidid.cpp +./Opcodes/arrays.c ./Opcodes/babo.c ./Opcodes/babo.h ./Opcodes/bbcut.c @@ -323,9 +182,9 @@ ./Opcodes/bilbar.c ./Opcodes/biquad.c ./Opcodes/biquad.h +./Opcodes/bowed.h ./Opcodes/bowedbar.c ./Opcodes/bowedbar.h -./Opcodes/bowed.h ./Opcodes/brass.h ./Opcodes/butter.c ./Opcodes/cellular.c @@ -340,29 +199,73 @@ ./Opcodes/cross2.c ./Opcodes/crossfm.c ./Opcodes/crossfm.h -./Opcodes/gendy.c +./Opcodes/dam.c +./Opcodes/dam.h +./Opcodes/date.c +./Opcodes/dcblockr.c +./Opcodes/dcblockr.h +./Opcodes/doppler.cpp +./Opcodes/dsputil.c +./Opcodes/dsputil.h +./Opcodes/dssi4cs/src/dssi.h +./Opcodes/dssi4cs/src/dssi4cs.c +./Opcodes/dssi4cs/src/dssi4cs.h +./Opcodes/dssi4cs/src/ladspa.h +./Opcodes/dssi4cs/src/load.c +./Opcodes/dssi4cs/src/utils.h +./Opcodes/eqfil.c +./Opcodes/fareygen.c +./Opcodes/fareyseq.c +./Opcodes/faustgen.cpp +./Opcodes/fhtfun.h +./Opcodes/filter.c +./Opcodes/filter.h +./Opcodes/flanger.c +./Opcodes/flanger.h +./Opcodes/fluidOpcodes/fluidOpcodes.cpp +./Opcodes/fluidOpcodes/fluidOpcodes.h +./Opcodes/flute.h +./Opcodes/fm4op.c +./Opcodes/fm4op.h +./Opcodes/follow.c +./Opcodes/follow.h +./Opcodes/fout.c +./Opcodes/fout.h +./Opcodes/freeverb.c +./Opcodes/ftconv.c +./Opcodes/ftest.c +./Opcodes/ftgen.c +./Opcodes/gab/gab.c +./Opcodes/gab/gab.h +./Opcodes/gab/hvs.c +./Opcodes/gab/newgabopc.c +./Opcodes/gab/radiobaton.c +./Opcodes/gab/sliderTable.c +./Opcodes/gab/stdopcod.h +./Opcodes/gab/tabmorph.c +./Opcodes/gab/vectorial.c ./Opcodes/gab/vectorial.h -./Opcodes/grain4.c -./Opcodes/grain4.h +./Opcodes/gendy.c ./Opcodes/grain.c ./Opcodes/grain.h +./Opcodes/grain4.c +./Opcodes/grain4.h ./Opcodes/harmon.c +./Opcodes/hrtfearly.c ./Opcodes/hrtferX.c ./Opcodes/hrtferx.h ./Opcodes/hrtfopcodes.c -./Opcodes/hrtfearly.c ./Opcodes/hrtfreverb.c ./Opcodes/ifd.c ./Opcodes/imageOpcodes.c ./Opcodes/imageOpcodes.h -./Opcodes/jacko.cpp ./Opcodes/jackTransport.c +./Opcodes/jacko.cpp ./Opcodes/linear_algebra.cpp +./Opcodes/linuxjoystick.c +./Opcodes/linuxjoystick.h ./Opcodes/locsig.c ./Opcodes/locsig.h -./Opcodes/Loris/lorisgens5.C -./Opcodes/Loris/lorisgens5.h -./Opcodes/LuaCsound.cpp ./Opcodes/loscilx.c ./Opcodes/lowpassr.c ./Opcodes/lowpassr.h @@ -379,6 +282,7 @@ ./Opcodes/modal4.c ./Opcodes/modal4.h ./Opcodes/modmatrix.c +./Opcodes/modmatrix.h ./Opcodes/moog1.c ./Opcodes/moog1.h ./Opcodes/mp3in.c @@ -386,11 +290,8 @@ ./Opcodes/newfils.h ./Opcodes/nlfilt.c ./Opcodes/nlfilt.h -./Opcodes/ogg.c -./Opcodes/oggplay.c ./Opcodes/oscbnk.c ./Opcodes/oscbnk.h -./Opcodes/OSC.c ./Opcodes/p5glove.c ./Opcodes/pan2.c ./Opcodes/partials.c @@ -401,10 +302,11 @@ ./Opcodes/physmod.c ./Opcodes/physutil.c ./Opcodes/physutil.h -./Opcodes/pitch0.c ./Opcodes/pitch.c ./Opcodes/pitch.h +./Opcodes/pitch0.c ./Opcodes/pitchtrack.c +./Opcodes/platerev.c ./Opcodes/pluck.c ./Opcodes/pluck.h ./Opcodes/psynth.c @@ -415,11 +317,13 @@ ./Opcodes/pvinterp.h ./Opcodes/pvlock.c ./Opcodes/pvoc.c +./Opcodes/pvoc.h ./Opcodes/pvocext.c ./Opcodes/pvocext.h -./Opcodes/pvoc.h ./Opcodes/pvread.c ./Opcodes/pvread.h +./Opcodes/pvs_ops.c +./Opcodes/pvs_ops.h ./Opcodes/pvsband.c ./Opcodes/pvsbasic.c ./Opcodes/pvsbasic.h @@ -428,9 +332,6 @@ ./Opcodes/pvsdemix.c ./Opcodes/pvsdemix.h ./Opcodes/pvsgendy.c -./Opcodes/pvslock.c -./Opcodes/pvs_ops.c -./Opcodes/pvs_ops.h ./Opcodes/py/pycall.auto.c ./Opcodes/py/pycall.auto.h ./Opcodes/py/pythonhelper.h @@ -446,11 +347,11 @@ ./Opcodes/scansynx.c ./Opcodes/scoreline.c ./Opcodes/seqtime.c -./Opcodes/sfenum.h +./Opcodes/serial.c ./Opcodes/sf.h +./Opcodes/sfenum.h ./Opcodes/sfont.c ./Opcodes/sfont.h -./Opcodes/sft.c ./Opcodes/sftype.h ./Opcodes/shaker.c ./Opcodes/shaker.h @@ -464,7 +365,6 @@ ./Opcodes/sockrecv.c ./Opcodes/socksend.c ./Opcodes/space.c -./Opcodes/space_cm.c ./Opcodes/space.h ./Opcodes/spat3d.c ./Opcodes/spat3d.h @@ -472,12 +372,12 @@ ./Opcodes/spectra.h ./Opcodes/stackops.c ./Opcodes/stdopcod.c +./Opcodes/stdopcod.h ./Opcodes/stk/stkOpcodes.cpp ./Opcodes/syncgrain.c ./Opcodes/syncgrain.h ./Opcodes/system_call.c ./Opcodes/tabsum.c -./Opcodes/tabvars.c ./Opcodes/tl/fractalnoise.cpp ./Opcodes/tl/sc_noise.c ./Opcodes/ugakbari.c @@ -499,13 +399,11 @@ ./Opcodes/urandom.c ./Opcodes/vaops.c ./Opcodes/vbap.c -./Opcodes/vbap_eight.c -./Opcodes/vbap_four.c ./Opcodes/vbap.h -./Opcodes/vbap_sixteen.c +./Opcodes/vbap1.c +./Opcodes/vbap_n.c ./Opcodes/vbap_zak.c ./Opcodes/vibraphn.h -./Opcodes/Vosim.c ./Opcodes/vpvoc.c ./Opcodes/vpvoc.h ./Opcodes/vst4cs/src/fxbank.cpp @@ -514,16 +412,16 @@ ./Opcodes/vst4cs/src/vst4cs.h ./Opcodes/vst4cs/src/vsthost.cpp ./Opcodes/vst4cs/src/vsthost.h -./Opcodes/wavegde.h ./Opcodes/wave-terrain.c ./Opcodes/wave-terrain.h +./Opcodes/wavegde.h ./Opcodes/wii_mac.h ./Opcodes/wiimote.c -./SDIF/sdif2adsyn.c -./SDIF/sdif.c -./SDIF/sdif.h ./SDIF/sdif-mem.c ./SDIF/sdif-mem.h +./SDIF/sdif.c +./SDIF/sdif.h +./SDIF/sdif2adsyn.c ./Top/argdecode.c ./Top/cscore_internal.c ./Top/cscorfns.c @@ -535,47 +433,172 @@ ./Top/one_file.c ./Top/opcode.c ./Top/threads.c +./Top/threadsafe.c ./Top/utility.c -./util1/cscore/cscore.c -./util1/cscore/cscore.h -./util1/cscore/cscore_main.c -./util1/cscore/main.c -./util1/csd_util/base64.c -./util1/csd_util/csb64enc.c -./util1/csd_util/cs.c -./util1/csd_util/makecsd.c -./util1/scot/scot.c -./util1/scot/scot.h -./util1/scot/scot_main.c -./util1/sortex/smain.c -./util1/sortex/xmain.c +./frontends/CsoundAC/Cell.cpp +./frontends/CsoundAC/Cell.hpp +./frontends/CsoundAC/ChordLindenmayer.cpp +./frontends/CsoundAC/ChordLindenmayer.hpp +./frontends/CsoundAC/Composition.cpp +./frontends/CsoundAC/Composition.hpp +./frontends/CsoundAC/Conversions.cpp +./frontends/CsoundAC/Conversions.hpp +./frontends/CsoundAC/Counterpoint.cpp +./frontends/CsoundAC/Counterpoint.hpp +./frontends/CsoundAC/CounterpointMain.cpp +./frontends/CsoundAC/CounterpointNode.cpp +./frontends/CsoundAC/CounterpointNode.hpp +./frontends/CsoundAC/Event.cpp +./frontends/CsoundAC/Event.hpp +./frontends/CsoundAC/Exception.hpp +./frontends/CsoundAC/Hocket.cpp +./frontends/CsoundAC/Hocket.hpp +./frontends/CsoundAC/ImageToScore.cpp +./frontends/CsoundAC/ImageToScore.hpp +./frontends/CsoundAC/Lindenmayer.cpp +./frontends/CsoundAC/Lindenmayer.hpp +./frontends/CsoundAC/MCRM.cpp +./frontends/CsoundAC/MCRM.hpp +./frontends/CsoundAC/Midifile.cpp +./frontends/CsoundAC/Midifile.hpp +./frontends/CsoundAC/MusicModel.cpp +./frontends/CsoundAC/MusicModel.hpp +./frontends/CsoundAC/Node.cpp +./frontends/CsoundAC/Node.hpp +./frontends/CsoundAC/OrchestraNode.hpp +./frontends/CsoundAC/Platform.hpp +./frontends/CsoundAC/Random.cpp +./frontends/CsoundAC/Random.hpp +./frontends/CsoundAC/Rescale.cpp +./frontends/CsoundAC/Rescale.hpp +./frontends/CsoundAC/Score.cpp +./frontends/CsoundAC/Score.hpp +./frontends/CsoundAC/ScoreModel.cpp +./frontends/CsoundAC/ScoreModel.hpp +./frontends/CsoundAC/ScoreNode.cpp +./frontends/CsoundAC/ScoreNode.hpp +./frontends/CsoundAC/Sequence.cpp +./frontends/CsoundAC/Sequence.hpp +./frontends/CsoundAC/Shell.cpp +./frontends/CsoundAC/Shell.hpp +./frontends/CsoundAC/Silence.hpp +./frontends/CsoundAC/Soundfile.cpp +./frontends/CsoundAC/Soundfile.hpp +./frontends/CsoundAC/StrangeAttractor.cpp +./frontends/CsoundAC/StrangeAttractor.hpp +./frontends/CsoundAC/System.cpp +./frontends/CsoundAC/System.hpp +./frontends/CsoundAC/Voicelead.cpp +./frontends/CsoundAC/Voicelead.hpp +./frontends/CsoundAC/VoiceleadingNode.cpp +./frontends/CsoundAC/VoiceleadingNode.hpp +./frontends/CsoundAC/algrd_internal.h +./frontends/CsoundAC/algsmfrd_internal.h +./frontends/CsoundAC/allegro.cpp +./frontends/CsoundAC/allegro.h +./frontends/CsoundAC/allegrord.cpp +./frontends/CsoundAC/allegroserial.cpp +./frontends/CsoundAC/allegrosmfrd.cpp +./frontends/CsoundAC/allegrosmfwr.cpp +./frontends/CsoundAC/allegrowr.cpp +./frontends/CsoundAC/mfmidi.cpp +./frontends/CsoundAC/mfmidi.h +./frontends/CsoundAC/strparse.cpp +./frontends/CsoundAC/strparse.h +./frontends/CsoundAC/trace.cpp +./frontends/CsoundAC/trace.h +./frontends/CsoundVST/CsoundVST.cpp +./frontends/CsoundVST/CsoundVST.hpp +./frontends/CsoundVST/CsoundVSTMain.cpp +./frontends/CsoundVST/CsoundVstFltk.cpp +./frontends/CsoundVST/CsoundVstFltk.hpp +./frontends/CsoundVST/CsoundVstUi.cpp +./frontends/CsoundVST/CsoundVstUi.h +./frontends/CsoundVST/Platform.hpp +./frontends/CsoundVST/ScoreGenerator.cpp +./frontends/CsoundVST/ScoreGenerator.hpp +./frontends/CsoundVST/ScoreGeneratorVst.cpp +./frontends/CsoundVST/ScoreGeneratorVst.hpp +./frontends/CsoundVST/ScoreGeneratorVstFltk.cpp +./frontends/CsoundVST/ScoreGeneratorVstFltk.hpp +./frontends/CsoundVST/ScoreGeneratorVstMain.cpp +./frontends/CsoundVST/ScoreGeneratorVstUi.cpp +./frontends/CsoundVST/ScoreGeneratorVstUi.h +./frontends/CsoundVST/csoundvst_main.cpp +./frontends/CsoundVST/pyrun.c +./frontends/csladspa/csladspa.cpp +./frontends/csladspa/ladspa.h +./frontends/csound/csound_main.c +./frontends/csound/sched.c +./frontends/csoundapi_tilde/csoundapi_tilde.c +./frontends/winsound.cxx +./frontends/winsound.h +./frontends/winsound/main.cxx +./include/OpcodeBase.hpp +./include/cfgvar.h +./include/cs_par_structs.h +./include/cscore.h +./include/csdl.h +./include/csound.h +./include/csound.hpp +./include/csoundCore.h +./include/csound_standard_types.h +./include/csound_type_system.h +./include/cwindow.h +./include/float-version-double.h +./include/float-version.h +./include/interlocks.h +./include/msg_attr.h +./include/pools.h +./include/pstream.h +./include/pvfileio.h +./include/soundio.h +./include/sysdep.h +./include/text.h +./include/version.h +./interfaces/CppSound.cpp +./interfaces/CppSound.hpp +./interfaces/CsoundFile.cpp +./interfaces/CsoundFile.hpp +./interfaces/Soundfile.cpp +./interfaces/Soundfile.hpp +./interfaces/csPerfThread.cpp +./interfaces/csPerfThread.hpp +./interfaces/cs_glue.cpp +./interfaces/cs_glue.hpp +./interfaces/filebuilding.cpp +./interfaces/filebuilding.h +./interfaces/pyMsgCb.cpp +./interfaces/pyMsgCb_stub.cpp +./pluginSDK/examplePlugin.c ./util/atsa.c ./util/atsa_main.c +./util/csanalyze.c ./util/cvanal.c ./util/cvl_main.c ./util/dnoise.c ./util/dnoise_main.c -./util/envext.c ./util/env_main.c +./util/envext.c ./util/het_export.c -./util/heti_main.c ./util/het_import.c ./util/het_main.c +./util/heti_main.c ./util/hetro.c ./util/hetx_main.c ./util/lpanal.c ./util/lpc_export.c -./util/lpci_main.c ./util/lpc_import.c ./util/lpc_main.c +./util/lpci_main.c ./util/lpcx_main.c ./util/mixer.c ./util/mixer_main.c +./util/pv_export.c +./util/pv_import.c ./util/pvanal.c ./util/pvc_main.c -./util/pv_export.c ./util/pvi_main.c -./util/pv_import.c ./util/pvl_main.c ./util/pvlook.c ./util/pvx_main.c @@ -590,3 +613,14 @@ ./util/utilmain.h ./util/xtrc_main.c ./util/xtrct.c +./util1/csd_util/base64.c +./util1/csd_util/cs.c +./util1/csd_util/csb64enc.c +./util1/csd_util/makecsd.c +./util1/scot/scot.c +./util1/scot/scot.h +./util1/scot/scot_main.c +./util1/sortex/smain.c +./util1/sortex/xmain.c +./Opcodes/cuda/adsyn.cu +./Opcodes/cuda/pvsops.cu diff -Nru csound-5.17.11~dfsg/android/COPYING csound-6.02~dfsg/android/COPYING --- csound-5.17.11~dfsg/android/COPYING 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/COPYING 1970-01-01 00:00:00.000000000 +0000 @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/.classpath csound-6.02~dfsg/android/CSDPlayer/.classpath --- csound-5.17.11~dfsg/android/CSDPlayer/.classpath 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/.classpath 1970-01-01 00:00:00.000000000 +0000 @@ -1,8 +0,0 @@ - - - - - - - - diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/.gitignore csound-6.02~dfsg/android/CSDPlayer/.gitignore --- csound-5.17.11~dfsg/android/CSDPlayer/.gitignore 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/.gitignore 1970-01-01 00:00:00.000000000 +0000 @@ -1,10 +0,0 @@ -*DS_Store -obj -libs -bin -gen -src/csnd* -*swp -jni/csound_orc* -jni/csound_prelex.c -jni/java_interface* diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/.project csound-6.02~dfsg/android/CSDPlayer/.project --- csound-5.17.11~dfsg/android/CSDPlayer/.project 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/.project 1970-01-01 00:00:00.000000000 +0000 @@ -1,33 +0,0 @@ - - - CsoundApp - - - - - - com.android.ide.eclipse.adt.ResourceManagerBuilder - - - - - com.android.ide.eclipse.adt.PreCompilerBuilder - - - - - org.eclipse.jdt.core.javabuilder - - - - - com.android.ide.eclipse.adt.ApkBuilder - - - - - - com.android.ide.eclipse.adt.AndroidNature - org.eclipse.jdt.core.javanature - - diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/AndroidManifest.xml csound-6.02~dfsg/android/CSDPlayer/AndroidManifest.xml --- csound-5.17.11~dfsg/android/CSDPlayer/AndroidManifest.xml 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/AndroidManifest.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,25 +0,0 @@ - - - - - - - - - - - - - - - - - - \ No newline at end of file diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/COPYING csound-6.02~dfsg/android/CSDPlayer/COPYING --- csound-5.17.11~dfsg/android/CSDPlayer/COPYING 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/COPYING 1970-01-01 00:00:00.000000000 +0000 @@ -1,504 +0,0 @@ - GNU LESSER GENERAL PUBLIC LICENSE - Version 2.1, February 1999 - - Copyright (C) 1991, 1999 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - -[This is the first released version of the Lesser GPL. It also counts - as the successor of the GNU Library Public License, version 2, hence - the version number 2.1.] - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -Licenses are intended to guarantee your freedom to share and change -free software--to make sure the software is free for all its users. - - This license, the Lesser General Public License, applies to some -specially designated software packages--typically libraries--of the -Free Software Foundation and other authors who decide to use it. You -can use it too, but we suggest you first think carefully about whether -this license or the ordinary General Public License is the better -strategy to use in any particular case, based on the explanations below. - - When we speak of free software, we are referring to freedom of use, -not price. Our General Public Licenses are designed to make sure that -you have the freedom to distribute copies of free software (and charge -for this service if you wish); that you receive source code or can get -it if you want it; that you can change the software and use pieces of -it in new free programs; and that you are informed that you can do -these things. - - To protect your rights, we need to make restrictions that forbid -distributors to deny you these rights or to ask you to surrender these -rights. These restrictions translate to certain responsibilities for -you if you distribute copies of the library or if you modify it. - - For example, if you distribute copies of the library, whether gratis -or for a fee, you must give the recipients all the rights that we gave -you. You must make sure that they, too, receive or can get the source -code. If you link other code with the library, you must provide -complete object files to the recipients, so that they can relink them -with the library after making changes to the library and recompiling -it. And you must show them these terms so they know their rights. - - We protect your rights with a two-step method: (1) we copyright the -library, and (2) we offer you this license, which gives you legal -permission to copy, distribute and/or modify the library. - - To protect each distributor, we want to make it very clear that -there is no warranty for the free library. Also, if the library is -modified by someone else and passed on, the recipients should know -that what they have is not the original version, so that the original -author's reputation will not be affected by problems that might be -introduced by others. - - Finally, software patents pose a constant threat to the existence of -any free program. We wish to make sure that a company cannot -effectively restrict the users of a free program by obtaining a -restrictive license from a patent holder. Therefore, we insist that -any patent license obtained for a version of the library must be -consistent with the full freedom of use specified in this license. - - Most GNU software, including some libraries, is covered by the -ordinary GNU General Public License. This license, the GNU Lesser -General Public License, applies to certain designated libraries, and -is quite different from the ordinary General Public License. We use -this license for certain libraries in order to permit linking those -libraries into non-free programs. - - When a program is linked with a library, whether statically or using -a shared library, the combination of the two is legally speaking a -combined work, a derivative of the original library. The ordinary -General Public License therefore permits such linking only if the -entire combination fits its criteria of freedom. The Lesser General -Public License permits more lax criteria for linking other code with -the library. - - We call this license the "Lesser" General Public License because it -does Less to protect the user's freedom than the ordinary General -Public License. It also provides other free software developers Less -of an advantage over competing non-free programs. These disadvantages -are the reason we use the ordinary General Public License for many -libraries. However, the Lesser license provides advantages in certain -special circumstances. - - For example, on rare occasions, there may be a special need to -encourage the widest possible use of a certain library, so that it becomes -a de-facto standard. To achieve this, non-free programs must be -allowed to use the library. A more frequent case is that a free -library does the same job as widely used non-free libraries. In this -case, there is little to gain by limiting the free library to free -software only, so we use the Lesser General Public License. - - In other cases, permission to use a particular library in non-free -programs enables a greater number of people to use a large body of -free software. For example, permission to use the GNU C Library in -non-free programs enables many more people to use the whole GNU -operating system, as well as its variant, the GNU/Linux operating -system. - - Although the Lesser General Public License is Less protective of the -users' freedom, it does ensure that the user of a program that is -linked with the Library has the freedom and the wherewithal to run -that program using a modified version of the Library. - - The precise terms and conditions for copying, distribution and -modification follow. Pay close attention to the difference between a -"work based on the library" and a "work that uses the library". The -former contains code derived from the library, whereas the latter must -be combined with the library in order to run. - - GNU LESSER GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License Agreement applies to any software library or other -program which contains a notice placed by the copyright holder or -other authorized party saying it may be distributed under the terms of -this Lesser General Public License (also called "this License"). -Each licensee is addressed as "you". - - A "library" means a collection of software functions and/or data -prepared so as to be conveniently linked with application programs -(which use some of those functions and data) to form executables. - - The "Library", below, refers to any such software library or work -which has been distributed under these terms. A "work based on the -Library" means either the Library or any derivative work under -copyright law: that is to say, a work containing the Library or a -portion of it, either verbatim or with modifications and/or translated -straightforwardly into another language. (Hereinafter, translation is -included without limitation in the term "modification".) - - "Source code" for a work means the preferred form of the work for -making modifications to it. For a library, complete source code means -all the source code for all modules it contains, plus any associated -interface definition files, plus the scripts used to control compilation -and installation of the library. - - Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running a program using the Library is not restricted, and output from -such a program is covered only if its contents constitute a work based -on the Library (independent of the use of the Library in a tool for -writing it). Whether that is true depends on what the Library does -and what the program that uses the Library does. - - 1. You may copy and distribute verbatim copies of the Library's -complete source code as you receive it, in any medium, provided that -you conspicuously and appropriately publish on each copy an -appropriate copyright notice and disclaimer of warranty; keep intact -all the notices that refer to this License and to the absence of any -warranty; and distribute a copy of this License along with the -Library. - - You may charge a fee for the physical act of transferring a copy, -and you may at your option offer warranty protection in exchange for a -fee. - - 2. You may modify your copy or copies of the Library or any portion -of it, thus forming a work based on the Library, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) The modified work must itself be a software library. - - b) You must cause the files modified to carry prominent notices - stating that you changed the files and the date of any change. - - c) You must cause the whole of the work to be licensed at no - charge to all third parties under the terms of this License. - - d) If a facility in the modified Library refers to a function or a - table of data to be supplied by an application program that uses - the facility, other than as an argument passed when the facility - is invoked, then you must make a good faith effort to ensure that, - in the event an application does not supply such function or - table, the facility still operates, and performs whatever part of - its purpose remains meaningful. - - (For example, a function in a library to compute square roots has - a purpose that is entirely well-defined independent of the - application. Therefore, Subsection 2d requires that any - application-supplied function or table used by this function must - be optional: if the application does not supply it, the square - root function must still compute square roots.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Library, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Library, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote -it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Library. - -In addition, mere aggregation of another work not based on the Library -with the Library (or with a work based on the Library) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may opt to apply the terms of the ordinary GNU General Public -License instead of this License to a given copy of the Library. To do -this, you must alter all the notices that refer to this License, so -that they refer to the ordinary GNU General Public License, version 2, -instead of to this License. (If a newer version than version 2 of the -ordinary GNU General Public License has appeared, then you can specify -that version instead if you wish.) Do not make any other change in -these notices. - - Once this change is made in a given copy, it is irreversible for -that copy, so the ordinary GNU General Public License applies to all -subsequent copies and derivative works made from that copy. - - This option is useful when you wish to copy part of the code of -the Library into a program that is not a library. - - 4. You may copy and distribute the Library (or a portion or -derivative of it, under Section 2) in object code or executable form -under the terms of Sections 1 and 2 above provided that you accompany -it with the complete corresponding machine-readable source code, which -must be distributed under the terms of Sections 1 and 2 above on a -medium customarily used for software interchange. - - If distribution of object code is made by offering access to copy -from a designated place, then offering equivalent access to copy the -source code from the same place satisfies the requirement to -distribute the source code, even though third parties are not -compelled to copy the source along with the object code. - - 5. A program that contains no derivative of any portion of the -Library, but is designed to work with the Library by being compiled or -linked with it, is called a "work that uses the Library". Such a -work, in isolation, is not a derivative work of the Library, and -therefore falls outside the scope of this License. - - However, linking a "work that uses the Library" with the Library -creates an executable that is a derivative of the Library (because it -contains portions of the Library), rather than a "work that uses the -library". The executable is therefore covered by this License. -Section 6 states terms for distribution of such executables. - - When a "work that uses the Library" uses material from a header file -that is part of the Library, the object code for the work may be a -derivative work of the Library even though the source code is not. -Whether this is true is especially significant if the work can be -linked without the Library, or if the work is itself a library. The -threshold for this to be true is not precisely defined by law. - - If such an object file uses only numerical parameters, data -structure layouts and accessors, and small macros and small inline -functions (ten lines or less in length), then the use of the object -file is unrestricted, regardless of whether it is legally a derivative -work. (Executables containing this object code plus portions of the -Library will still fall under Section 6.) - - Otherwise, if the work is a derivative of the Library, you may -distribute the object code for the work under the terms of Section 6. -Any executables containing that work also fall under Section 6, -whether or not they are linked directly with the Library itself. - - 6. As an exception to the Sections above, you may also combine or -link a "work that uses the Library" with the Library to produce a -work containing portions of the Library, and distribute that work -under terms of your choice, provided that the terms permit -modification of the work for the customer's own use and reverse -engineering for debugging such modifications. - - You must give prominent notice with each copy of the work that the -Library is used in it and that the Library and its use are covered by -this License. You must supply a copy of this License. If the work -during execution displays copyright notices, you must include the -copyright notice for the Library among them, as well as a reference -directing the user to the copy of this License. Also, you must do one -of these things: - - a) Accompany the work with the complete corresponding - machine-readable source code for the Library including whatever - changes were used in the work (which must be distributed under - Sections 1 and 2 above); and, if the work is an executable linked - with the Library, with the complete machine-readable "work that - uses the Library", as object code and/or source code, so that the - user can modify the Library and then relink to produce a modified - executable containing the modified Library. (It is understood - that the user who changes the contents of definitions files in the - Library will not necessarily be able to recompile the application - to use the modified definitions.) - - b) Use a suitable shared library mechanism for linking with the - Library. A suitable mechanism is one that (1) uses at run time a - copy of the library already present on the user's computer system, - rather than copying library functions into the executable, and (2) - will operate properly with a modified version of the library, if - the user installs one, as long as the modified version is - interface-compatible with the version that the work was made with. - - c) Accompany the work with a written offer, valid for at - least three years, to give the same user the materials - specified in Subsection 6a, above, for a charge no more - than the cost of performing this distribution. - - d) If distribution of the work is made by offering access to copy - from a designated place, offer equivalent access to copy the above - specified materials from the same place. - - e) Verify that the user has already received a copy of these - materials or that you have already sent this user a copy. - - For an executable, the required form of the "work that uses the -Library" must include any data and utility programs needed for -reproducing the executable from it. However, as a special exception, -the materials to be distributed need not include anything that is -normally distributed (in either source or binary form) with the major -components (compiler, kernel, and so on) of the operating system on -which the executable runs, unless that component itself accompanies -the executable. - - It may happen that this requirement contradicts the license -restrictions of other proprietary libraries that do not normally -accompany the operating system. Such a contradiction means you cannot -use both them and the Library together in an executable that you -distribute. - - 7. You may place library facilities that are a work based on the -Library side-by-side in a single library together with other library -facilities not covered by this License, and distribute such a combined -library, provided that the separate distribution of the work based on -the Library and of the other library facilities is otherwise -permitted, and provided that you do these two things: - - a) Accompany the combined library with a copy of the same work - based on the Library, uncombined with any other library - facilities. This must be distributed under the terms of the - Sections above. - - b) Give prominent notice with the combined library of the fact - that part of it is a work based on the Library, and explaining - where to find the accompanying uncombined form of the same work. - - 8. You may not copy, modify, sublicense, link with, or distribute -the Library except as expressly provided under this License. Any -attempt otherwise to copy, modify, sublicense, link with, or -distribute the Library is void, and will automatically terminate your -rights under this License. However, parties who have received copies, -or rights, from you under this License will not have their licenses -terminated so long as such parties remain in full compliance. - - 9. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Library or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Library (or any work based on the -Library), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Library or works based on it. - - 10. Each time you redistribute the Library (or any work based on the -Library), the recipient automatically receives a license from the -original licensor to copy, distribute, link with or modify the Library -subject to these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties with -this License. - - 11. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Library at all. For example, if a patent -license would not permit royalty-free redistribution of the Library by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Library. - -If any portion of this section is held invalid or unenforceable under any -particular circumstance, the balance of the section is intended to apply, -and the section as a whole is intended to apply in other circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 12. If the distribution and/or use of the Library is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Library under this License may add -an explicit geographical distribution limitation excluding those countries, -so that distribution is permitted only in or among countries not thus -excluded. In such case, this License incorporates the limitation as if -written in the body of this License. - - 13. The Free Software Foundation may publish revised and/or new -versions of the Lesser General Public License from time to time. -Such new versions will be similar in spirit to the present version, -but may differ in detail to address new problems or concerns. - -Each version is given a distinguishing version number. If the Library -specifies a version number of this License which applies to it and -"any later version", you have the option of following the terms and -conditions either of that version or of any later version published by -the Free Software Foundation. If the Library does not specify a -license version number, you may choose any version ever published by -the Free Software Foundation. - - 14. If you wish to incorporate parts of the Library into other free -programs whose distribution conditions are incompatible with these, -write to the author to ask for permission. For software which is -copyrighted by the Free Software Foundation, write to the Free -Software Foundation; we sometimes make exceptions for this. Our -decision will be guided by the two goals of preserving the free status -of all derivatives of our free software and of promoting the sharing -and reuse of software generally. - - NO WARRANTY - - 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO -WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. -EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR -OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY -KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE -LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME -THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN -WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY -AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU -FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR -CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE -LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING -RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A -FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF -SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH -DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Libraries - - If you develop a new library, and you want it to be of the greatest -possible use to the public, we recommend making it free software that -everyone can redistribute and change. You can do so by permitting -redistribution under these terms (or, alternatively, under the terms of the -ordinary General Public License). - - To apply these terms, attach the following notices to the library. It is -safest to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least the -"copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Lesser General Public License for more details. - - You should have received a copy of the GNU Lesser General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - -Also add information on how to contact you by electronic and paper mail. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the library, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the - library `Frob' (a library for tweaking knobs) written by James Random Hacker. - - , 1 April 1990 - Ty Coon, President of Vice - -That's all there is to it! - - diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/proguard.cfg csound-6.02~dfsg/android/CSDPlayer/proguard.cfg --- csound-5.17.11~dfsg/android/CSDPlayer/proguard.cfg 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/proguard.cfg 1970-01-01 00:00:00.000000000 +0000 @@ -1,40 +0,0 @@ --optimizationpasses 5 --dontusemixedcaseclassnames --dontskipnonpubliclibraryclasses --dontpreverify --verbose --optimizations !code/simplification/arithmetic,!field/*,!class/merging/* - --keep public class * extends android.app.Activity --keep public class * extends android.app.Application --keep public class * extends android.app.Service --keep public class * extends android.content.BroadcastReceiver --keep public class * extends android.content.ContentProvider --keep public class * extends android.app.backup.BackupAgentHelper --keep public class * extends android.preference.Preference --keep public class com.android.vending.licensing.ILicensingService - --keepclasseswithmembernames class * { - native ; -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet); -} - --keepclasseswithmembers class * { - public (android.content.Context, android.util.AttributeSet, int); -} - --keepclassmembers class * extends android.app.Activity { - public void *(android.view.View); -} - --keepclassmembers enum * { - public static **[] values(); - public static ** valueOf(java.lang.String); -} - --keep class * implements android.os.Parcelable { - public static final android.os.Parcelable$Creator *; -} diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/project.properties csound-6.02~dfsg/android/CSDPlayer/project.properties --- csound-5.17.11~dfsg/android/CSDPlayer/project.properties 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/project.properties 1970-01-01 00:00:00.000000000 +0000 @@ -1,12 +0,0 @@ -# This file is automatically generated by Android Tools. -# Do not modify this file -- YOUR CHANGES WILL BE ERASED! -# -# This file must be checked in Version Control Systems. -# -# To customize properties used by the Ant build system use, -# "ant.properties", and override values to adapt the script to your -# project structure. - -# Project target. -target=android-9 -android.library.reference.1=../CsoundAndroid Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-hdpi/directory_icon.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-hdpi/directory_icon.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-hdpi/directory_up.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-hdpi/directory_up.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-hdpi/file_icon.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-hdpi/file_icon.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-hdpi/ic_launcher.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-hdpi/ic_launcher.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-hdpi/icon.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-hdpi/icon.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-ldpi/ic_launcher.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-ldpi/ic_launcher.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-ldpi/icon.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-ldpi/icon.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-mdpi/ic_launcher.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-mdpi/ic_launcher.png differ Binary files /tmp/TS7HIRzQGr/csound-5.17.11~dfsg/android/CSDPlayer/res/drawable-mdpi/icon.png and /tmp/soxM_lCYvY/csound-6.02~dfsg/android/CSDPlayer/res/drawable-mdpi/icon.png differ diff -Nru csound-5.17.11~dfsg/android/CSDPlayer/res/layout/main.xml csound-6.02~dfsg/android/CSDPlayer/res/layout/main.xml --- csound-5.17.11~dfsg/android/CSDPlayer/res/layout/main.xml 2012-05-28 17:41:30.000000000 +0000 +++ csound-6.02~dfsg/android/CSDPlayer/res/layout/main.xml 1970-01-01 00:00:00.000000000 +0000 @@ -1,142 +0,0 @@ - - - - - -