pax_global_header00006660000000000000000000000064124574022550014520gustar00rootroot0000000000000052 comment=de35d7fc53c1fb972531ab88ddb4588b6d2b8b52 wildmidi-wildmidi-0.3.8/000077500000000000000000000000001245740225500151325ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/.gitignore000066400000000000000000000004051245740225500171210ustar00rootroot00000000000000# compiled objects # *.o *.so *.dll # logs and other texts # *.log # OS generated files # .DS_Store .DS_Store? ._* .Spotlight-V100 .Trashes Icon? ehthumbs.db Thumbs.db # Eclipse .cproject .preferences.xml .project .settings/ # config files include/config.h wildmidi-wildmidi-0.3.8/.travis.yml000066400000000000000000000021271245740225500172450ustar00rootroot00000000000000language: c compiler: - gcc - clang env: - BUILD_TYPE=Debug - BUILD_TYPE=Release branches: only: - master - /wildmidi-.*$/ before_install: - pwd - git submodule update --init --recursive - echo "yes" | sudo add-apt-repository "deb http://archive.ubuntu.com/ubuntu `lsb_release -sc` main universe restricted multiverse" - sudo apt-get update -qq - sudo apt-get install -qq libgtest-dev google-mock - sudo apt-get install -qq libasound2-dev libopenal-dev - sudo mkdir /usr/src/gtest/build - cd /usr/src/gtest/build - sudo cmake .. -DBUILD_SHARED_LIBS=1 - sudo make -j4 - sudo ln -s /usr/src/gtest/build/libgtest.so /usr/lib/libgtest.so - sudo ln -s /usr/src/gtest/build/libgtest_main.so /usr/lib/libgtest_main.so before_script: - cd - - mkdir build - cd build - cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE .. script: - make -j2 #after_script: # - ./runtests notifications: recipients: - psi29a+travis.ci@gmail.com email: on_success: change on_failure: always irc: channels: - "chat.freenode.net#wildmidi" on_success: change on_failure: always wildmidi-wildmidi-0.3.8/CMakeLists.txt000066400000000000000000000211431245740225500176730ustar00rootroot00000000000000# ########## Project setup ########## PROJECT(wildmidi C) CMAKE_MINIMUM_REQUIRED(VERSION 2.8) # WildMIDI Version SET(VERSION_MAJOR 0) SET(VERSION_MINOR 3) SET(VERSION_RELEASE 8) SET(WILDMIDI_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_RELEASE}") # Lib Versions SET(SOVERSION 1) SET(VERSION 1.1.2) # Find Macros SET(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) INCLUDE(CMakeDependentOption) INCLUDE(CheckCCompilerFlag) INCLUDE(CheckCSourceCompiles) INCLUDE(CheckIncludeFile) INCLUDE(TestBigEndian) # Set a default build type if none was specified IF(NOT DEFINED CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "") MESSAGE(STATUS "Setting build type to 'Debug' as none was specified.") SET(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) # Set the possible values of build type for cmake-gui SET_PROPERTY(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo") ENDIF() SET(CMAKE_CONFIGURATION_TYPES "${CMAKE_BUILD_TYPE}") MESSAGE(STATUS "Build Type: ${CMAKE_BUILD_TYPE}") # Set our optoins OPTION(WANT_PLAYER "Build WildMIDI player in addition to the libraries" ON) OPTION(WANT_STATIC "Build static library in addition to dynamic library" OFF) CMAKE_DEPENDENT_OPTION(WANT_PLAYERSTATIC "Build a statically linked WildMIDI player" ON "WANT_STATIC" OFF) OPTION(WANT_ALSA "Include ALSA (Advanced Linux Sound Architecture) support" OFF) OPTION(WANT_OSS "Include OSS (Open Sound System) support" OFF) OPTION(WANT_OPENAL "Include OpenAL suport (Cross Platform) support" OFF) IF(UNIX AND NOT APPLE) SET(WILDMIDI_CFG "/etc/wildmidi/wildmidi.cfg" CACHE STRING "default config location") ELSE() SET(WILDMIDI_CFG "wildmidi.cfg" CACHE STRING "default config location") ENDIF() # Platform specific defines IF(UNIX) # allow 'large' files in 32 bit builds ADD_DEFINITIONS( -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGE_FILES ) ENDIF() IF(WIN32) ADD_DEFINITIONS( -DWIN32_LEAN_AND_MEAN -D_CRT_SECURE_NO_WARNINGS ) ENDIF() # Compiler specific settings IF(CMAKE_COMPILER_IS_GNUCC OR "${CMAKE_C_COMPILER_ID}" MATCHES "Clang") ADD_DEFINITIONS( -Wall -W -fno-common ) IF(NOT WIN32 AND NOT CYGWIN) SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -Werror") CHECK_C_SOURCE_COMPILES("int foo(void) __attribute__((visibility(\"default\"))); int main(void) {return 0;}" HAVE_VISIBILITY_DEFAULT) IF(HAVE_VISIBILITY_DEFAULT) CHECK_C_COMPILER_FLAG(-fvisibility=hidden HAVE_VISIBILITY_HIDDEN) ENDIF() SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}") ENDIF() IF (CMAKE_BUILD_TYPE STREQUAL "Debug") ADD_DEFINITIONS( -ggdb3 -O0 ) ELSEIF(CMAKE_BUILD_TYPE STREQUAL "Release") ADD_DEFINITIONS( -O3 ) ENDIF(CMAKE_BUILD_TYPE STREQUAL "Debug") ENDIF() IF("${CMAKE_C_COMPILER_ID}" MATCHES "SunPro") SET(OLD_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS} -xldscope=hidden") # __SUNPRO_C >= 0x590 # CHECK_C_SOURCE_COMPILES("int foo(void) __attribute__((visibility(\"default\"))); # int main(void) {return 0;}" HAVE_VISIBILITY_DEFAULT) # __SUNPRO_C >= 0x550 CHECK_C_SOURCE_COMPILES("__global int foo(void); int main(void) {return 0;}" HAVE_LDSCOPE_GLOBAL) IF(HAVE_LDSCOPE_GLOBAL)# OR HAVE_VISIBILITY_DEFAULT SET(HAVE_LDSCOPE_HIDDEN 1) ENDIF() SET(CMAKE_REQUIRED_FLAGS "${OLD_REQUIRED_FLAGS}") ENDIF() CHECK_C_SOURCE_COMPILES("int main(void) {__builtin_expect(0,0); return 0;}" HAVE___BUILTIN_EXPECT) CHECK_C_SOURCE_COMPILES("static inline int static_foo() {return 0;} int main(void) {return 0;}" HAVE_C_INLINE) CHECK_C_SOURCE_COMPILES("static __inline__ int static_foo() {return 0;} int main(void) {return 0;}" HAVE_C___INLINE__) CHECK_C_SOURCE_COMPILES("static __inline int static_foo() {return 0;} int main(void) {return 0;}" HAVE_C___INLINE) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) SET(AUDIODRV_ALSA) SET(AUDIODRV_OSS) SET(AUDIODRV_OPENAL) # UNIX-like environments IF(UNIX AND NOT APPLE) # Go looking for available sound packages for WildMIDI player IF(WANT_PLAYER OR WANT_PLAYERSTATIC) FIND_PACKAGE(ALSA) FIND_PACKAGE(OpenAL) FIND_PACKAGE(OSS) # Set preferred output IF(WANT_ALSA) IF(NOT ALSA_FOUND) MESSAGE(FATAL_ERROR "ALSA required but not found.") ENDIF() SET(AUDIODRV_ALSA 1) SET(AUDIO_LIBRARY ${ALSA_LIBRARY}) # FIXME: we need to add ALSA_INCLUDE_DIR only to the wildmidi # target in src/CMakeLists.txt using TARGET_INCLUDE_DIRECTORIES() # but that requires cmake-2.8.11 or newer INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIR}) ELSEIF(WANT_OSS) IF(NOT OSS_FOUND) MESSAGE(FATAL_ERROR "OSS required but not found.") ENDIF() # no special header paths SET(AUDIODRV_OSS 1) SET(AUDIO_LIBRARY ${OSS_LIBRARY}) ELSEIF(WANT_OPENAL) IF(NOT OPENAL_FOUND) MESSAGE(FATAL_ERROR "OpenAL required but not found.") ENDIF() SET(AUDIODRV_OPENAL 1) SET(AUDIO_LIBRARY ${OPENAL_LIBRARY}) # FIXME: we need to add OPENAL_INCLUDE_DIR only to the wildmidi # target in src/CMakeLists.txt using TARGET_INCLUDE_DIRECTORIES() # but that requires cmake-2.8.11 or newer INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) ELSE() # Try to auto-detect IF(ALSA_FOUND) SET(AUDIO_LIBRARY ${ALSA_LIBRARY}) SET(AUDIODRV_ALSA 1) # FIXME: we need to add ALSA_INCLUDE_DIR only to the wildmidi # target in src/CMakeLists.txt using TARGET_INCLUDE_DIRECTORIES() # but that requires cmake-2.8.11 or newer INCLUDE_DIRECTORIES(${ALSA_INCLUDE_DIR}) ELSEIF(OSS_FOUND) # no special header paths SET(AUDIO_LIBRARY ${OSS_LIBRARY}) SET(AUDIODRV_OSS 1) ELSEIF(OPENAL_FOUND) SET(AUDIO_LIBRARY ${OPENAL_LIBRARY}) SET(AUDIODRV_OPENAL 1) # FIXME: we need to add OPENAL_INCLUDE_DIR only to the wildmidi # target in src/CMakeLists.txt using TARGET_INCLUDE_DIRECTORIES() # but that requires cmake-2.8.11 or newer INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) ELSE() MESSAGE(WARNING "Could not find an audio sub-system!") SET(AUDIO_LIBRARY "") ENDIF() ENDIF() ENDIF() # find our math lib FIND_LIBRARY(M_LIBRARY m REQUIRED) ## Debian and non debian Linux building IF (DPKG_PROGRAM) ## Debian specific ELSE () ## Non debian specific ENDIF (DPKG_PROGRAM) ENDIF(UNIX AND NOT APPLE) IF (APPLE AND (WANT_PLAYER OR WANT_PLAYERSTATIC)) FIND_PACKAGE(OpenAL) IF(WANT_OPENAL) IF(NOT OPENAL_FOUND) MESSAGE(FATAL_ERROR "OpenAL required but not found.") ENDIF() SET(AUDIO_LIBRARY ${OPENAL_LIBRARY}) ELSE() IF(OPENAL_FOUND) SET(AUDIO_LIBRARY ${OPENAL_LIBRARY}) SET(AUDIODRV_OPENAL 1) # FIXME: we need to add OPENAL_INCLUDE_DIR only to the wildmidi # target in src/CMakeLists.txt using TARGET_INCLUDE_DIRECTORIES() # but that requires cmake-2.8.11 or newer INCLUDE_DIRECTORIES(${OPENAL_INCLUDE_DIR}) ELSE() MESSAGE(WARNING "Could not find an audio sub-system!") SET(AUDIO_LIBRARY "") ENDIF() ENDIF() ENDIF() IF(WIN32) IF (WANT_PLAYER OR WANT_PLAYERSTATIC) LINK_LIBRARIES(winmm) ENDIF() ENDIF(WIN32) # ######### General setup ########## INCLUDE_DIRECTORIES(BEFORE "${CMAKE_SOURCE_DIR}/include") FILE (MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/include") INCLUDE_DIRECTORIES(BEFORE "${CMAKE_BINARY_DIR}/include") IF(APPLE) SET(APP_BUNDLE_NAME "${CMAKE_PROJECT_NAME}.app") SET(APP_BUNDLE_DIR "${wildmidi_BINARY_DIR}/${APP_BUNDLE_NAME}") ENDIF(APPLE) IF(APPLE) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${APP_BUNDLE_DIR}/Contents/MacOS") ELSE(APPLE) SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${wildmidi_BINARY_DIR}") ENDIF(APPLE) # Setup up our config file CONFIGURE_FILE("${CMAKE_SOURCE_DIR}/include/config.h.cmake" "${CMAKE_BINARY_DIR}/include/config.h") ADD_SUBDIRECTORY(src) wildmidi-wildmidi-0.3.8/COPYING000066400000000000000000000001341245740225500161630ustar00rootroot00000000000000For the player see docs/license/GPLv3.txt For the library see docs/license/LGPLv3.txt wildmidi-wildmidi-0.3.8/README.md000066400000000000000000000070551245740225500164200ustar00rootroot00000000000000WildMIDI is a simple software midi player which has a core softsynth library that can be use with other applications. The WildMIDI library uses Gravis Ultrasound patch files to convert MIDI files into audio which is then passed back to the calling application. The library API is designed so that it is easy to include WildMIDI into applications that wish to include MIDI file playback. Version: 0.3.8 Licenses: GPLv3+ and LGPLv3 Website: http://www.mindwerks.net/projects/wildmidi PLATFORMS: * Linux: Arch, Debian, Fedora, Ubuntu (player: ALSA, OSS, OpenAL output) * Windows: x86 and x64 * OSX: x86, x64 and powerpc (in Xterm. player: OpenAL output) * BSD: Debian, FreeBSD, NetBSD, OpenBSD. (player: OSS output) * kFreeBSD: Debian (player: OSS output) * Hurd: Debian * DOS (player: sound blaster or compatibles output.) BUILD FROM SOURCE: Requirements: * git * cmake * GCC or clang / Xcode / VisualStudio / MinGW or MinGW-w64 * DOS port: DJGPP / GNU make CHANGELOG 0.3.8 * Library: Fixed a seek-to-0 bug in order to cure an issue of truncated start (bug #100, gnome/gstreamer bug #694811.) * Player, OpenAL: reduced buffers from 8 to 4 so as to cure some output delay issues (bug #85.) 0.3.7 * Plug a memory leak in case of broken midis. * Properly reset global state upon library shutdown. * Support for type-2 midi files. * Fix a possible crash in WildMidi_SetOption. * DOS port: Support for Sound Blaster output in player. * Uglify the library's private global variable and function names. * Build: Add option for a statically linked player. * Build: Add headers to project files. Use -fno-common flag. * Other small fixes/clean-ups. 0.3.6 * Fix some portability issues. * Fix a double-free issue during library shutdown when several midis were alive. * Fix the invalid option checking in WildMidi_Init(). * Fix the roundtempo option which had been broken since its invention in 0.2.3.5 (WM_MO_ROUNDTEMPO: was 0xA000 instead of 0x2000.) * Fix cfg files without a newline at the end weren't parsed correctly. * Handle cfg files with mac line-endings. * Refuse loading suspiciously long files. 0.3.5 * Greatly reduced the heap usage (was a regression introduced in 0.2.3) * OpenAL support: Fixed audio output on big-endian systems. Fixed audio skips at song start. * OSS support: No longer uses mmap mode for better compatibility. This gains us NetBSD and OpenBSD support. * Worked around an invalid memory read found by valgrind when playing Beethoven's Fur Elise.rmi at 44100 Hz using the old MIDIA patch-set from 1994. * Build fixes for MSVC. Revised visibility attributes usage. 0.3.4 * OpenAL support: This gains us OSX and other platforms that OpenAL supports for sound output! * DOS (DJGPP) support: This goes a long way to helping other DOS based applications. * MinGW support: This gains us win32 and win64 support using this toolchain. * OSS fixes. * Add missing parts of the absolute paths fix in config parsing. * New portable file and path-name system to handle cross-platform support. * Support for Debian/kFreeBSD, Debian/Hurd and other Debian archs. * Many bug fixes, code clean-ups and cosmetic fixes. 0.3.3 * default to hidden visibility and only export our API functions * windows lean and mean to help compile times on Windows * cli and xcode work now on OSX * better FreeBSD support * Supported platforms are Debian, FreeBSD, Windows and OSX (but only for WAV output) 0.3.1 - 0.3.2 * Cmake updates/fixes/cleanups. 0.3.0 * initial CMake support. * process non-registered params. fix issue of notes ending before attack envelope completed. (sf.net svn r149/r151.) wildmidi-wildmidi-0.3.8/cfg/000077500000000000000000000000001245740225500156715ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/cfg/wildmidi.cfg000066400000000000000000000110571245740225500201600ustar00rootroot00000000000000dir /usr/share/midi/freepats # Automatically generated on Sun Feb 19 19:22:39 EST 2006 # by http://freepats.opensrc.org/mkcfg.sh.txt drumset 0 25 Drum_000/025_Snare_Roll.pat 26 Drum_000/026_Snap.pat 27 Drum_000/027_High_Q.pat 31 Drum_000/031_Sticks.pat 32 Drum_000/032_Square_Click.pat 33 Drum_000/033_Metronome_Click.pat 34 Drum_000/034_Metronome_Bell.pat 35 Drum_000/035_Kick_1.pat amp=100 36 Drum_000/036_Kick_2.pat amp=100 37 Drum_000/037_Stick_Rim.pat 38 Drum_000/038_Snare_1.pat 39 Drum_000/039_Clap_Hand.pat amp=100 40 Drum_000/040_Snare_2.pat 41 Drum_000/041_Tom_Low_2.pat amp=100 42 Drum_000/042_Hi-Hat_Closed.pat 43 Drum_000/043_Tom_Low_1.pat amp=100 44 Drum_000/044_Hi-Hat_Pedal.pat 45 Drum_000/045_Tom_Mid_2.pat amp=100 46 Drum_000/046_Hi-Hat_Open.pat 47 Drum_000/047_Tom_Mid_1.pat amp=100 48 Drum_000/048_Tom_High_2.pat amp=100 49 Drum_000/049_Cymbal_Crash_1.pat 50 Drum_000/050_Tom_High_1.pat amp=100 51 Drum_000/051_Cymbal_Ride_1.pat 52 Drum_000/052_Cymbal_Chinese.pat 53 Drum_000/053_Cymbal_Ride_Bell.pat amp=100 54 Drum_000/054_Tombourine.pat 55 Drum_000/055_Cymbal_Splash.pat 56 Drum_000/056_Cow_Bell.pat 57 Drum_000/057_Cymbal_Crash_2.pat 58 Drum_000/058_Vibra-Slap.pat 59 Drum_000/059_Cymbal_Ride_2.pat 60 Drum_000/060_Bongo_High.pat 61 Drum_000/061_Bongo_Low.pat 62 Drum_000/062_Conga_High_1_Mute.pat 63 Drum_000/063_Conga_High_2_Open.pat 64 Drum_000/064_Conga_Low.pat 65 Drum_000/065_Timbale_High.pat 66 Drum_000/066_Timbale_Low.pat 67 Drum_000/067_Agogo_High.pat 68 Drum_000/068_Agogo_Low.pat 69 Drum_000/069_Cabasa.pat amp=100 70 Drum_000/070_Maracas.pat 71 Drum_000/071_Whistle_1_High_Short.pat 72 Drum_000/072_Whistle_2_Low_Long.pat 73 Drum_000/073_Guiro_1_Short.pat 74 Drum_000/074_Guiro_2_Long.pat 75 Drum_000/075_Claves.pat amp=100 76 Drum_000/076_Wood_Block_1_High.pat 77 Drum_000/077_Wood_Block_2_Low.pat 78 Drum_000/078_Cuica_1_Mute.pat amp=100 79 Drum_000/079_Cuica_2_Open.pat amp=100 80 Drum_000/080_Triangle_1_Mute.pat 81 Drum_000/081_Triangle_2_Open.pat 82 Drum_000/082_Shaker.pat 84 Drum_000/084_Belltree.pat bank 0 0 Tone_000/000_Acoustic_Grand_Piano.pat amp=120 pan=center 1 Tone_000/001_Acoustic_Brite_Piano.pat 2 Tone_000/002_Electric_Grand_Piano.pat 4 Tone_000/004_Electric_Piano_1_Rhodes.pat 5 Tone_000/005_Electric_Piano_2_Chorused_Yamaha_DX.pat 6 Tone_000/006_Harpsichord.pat 7 Tone_000/007_Clavinet.pat 8 Tone_000/008_Celesta.pat 9 Tone_000/009_Glockenspiel.pat 13 Tone_000/013_Xylophone.pat 14 Tone_000/014_Tubular_Bells.pat 15 Tone_000/015_Dulcimer.pat 16 Tone_000/016_Hammond_Organ.pat 19 Tone_000/019_Church_Organ.pat 21 Tone_000/021_Accordion.pat 23 Tone_000/023_Tango_Accordion.pat 24 Tone_000/024_Nylon_Guitar.pat 25 Tone_000/025_Steel_Guitar.pat 26 Tone_000/026_Jazz_Guitar.pat 27 Tone_000/027_Clean_Electric_Guitar.pat 28 Tone_000/028_Muted_Electric_Guitar.pat 29 Tone_000/029_Overdriven_Guitar.pat 30 Tone_000/030_Distortion_Guitar.pat 32 Tone_000/032_Acoustic_Bass.pat 33 Tone_000/033_Finger_Bass.pat 34 Tone_000/034_Pick_Bass.pat 35 Tone_000/035_Fretless_Bass.pat 36 Tone_000/036_Slap_Bass_1.pat 37 Tone_000/037_Slap_Bass_2.pat 38 Tone_000/038_Synth_Bass_1.pat 40 Tone_000/040_Violin.pat 42 Tone_000/042_Cello.pat 44 Tone_000/044_Tremolo_Strings.pat 45 Tone_000/045_Pizzicato_Strings.pat 46 Tone_000/046_Harp.pat 47 Tone_000/047_Timpani.pat 48 Tone_000/048_String_Ensemble_1_Marcato.pat 53 Tone_000/053_Voice_Oohs.pat 56 Tone_000/056_Trumpet.pat 57 Tone_000/057_Trombone.pat 58 Tone_000/058_Tuba.pat 59 Tone_000/059_Muted_Trumpet.pat 60 Tone_000/060_French_Horn.pat 61 Tone_000/061_Brass_Section.pat 64 Tone_000/064_Soprano_Sax.pat 65 Tone_000/065_Alto_Sax.pat 66 Tone_000/066_Tenor_Sax.pat 67 Tone_000/067_Baritone_Sax.pat 68 Tone_000/068_Oboe.pat 69 Tone_000/069_English_Horn.pat 70 Tone_000/070_Bassoon.pat 71 Tone_000/071_Clarinet.pat 72 Tone_000/072_Piccolo.pat 73 Tone_000/073_Flute.pat 74 Tone_000/074_Recorder.pat 75 Tone_000/075_Pan_Flute.pat 76 Tone_000/076_Bottle_Blow.pat 79 Tone_000/079_Ocarina.pat 80 Tone_000/080_Square_Wave.pat 84 Tone_000/084_Charang.pat 88 Tone_000/088_New_Age.pat 94 Tone_000/094_Halo_Pad.pat 95 Tone_000/095_Sweep_Pad.pat 98 Tone_000/098_Crystal.pat 101 Tone_000/101_Goblins--Unicorn.pat 102 Tone_000/102_Echo_Voice.pat 104 Tone_000/104_Sitar.pat 114 Tone_000/114_Steel_Drums.pat 115 Tone_000/115_Wood_Block.pat 120 Tone_000/120_Guitar_Fret_Noise.pat 122 Tone_000/122_Seashore.pat 125 Tone_000/125_Helicopter.pat wildmidi-wildmidi-0.3.8/cmake/000077500000000000000000000000001245740225500162125ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/cmake/FindOSS.cmake000066400000000000000000000042421245740225500204630ustar00rootroot00000000000000# - Find OSS # Find OSS headers and libraries. # # OSS_INCLUDE_DIR - where to find soundcard.h, etc. # OSS_LIBRARY - link library, if any, needed for OSS. # OSS_FOUND - True if OSS found. INCLUDE(CheckIncludeFiles) INCLUDE(CheckCSourceCompiles) SET(OSS_LIBRARY "") SET(OSS_INCLUDE_DIR) # system header must suffice SET(OSS_FOUND) MESSAGE(STATUS "Looking for OSS...") #CHECK_INCLUDE_FILES(linux/soundcard.h HAVE_LINUX_SOUNDCARD_H) # Linux does provide CHECK_INCLUDE_FILES(sys/soundcard.h HAVE_SYS_SOUNDCARD_H) CHECK_INCLUDE_FILES(machine/soundcard.h HAVE_MACHINE_SOUNDCARD_H) CHECK_INCLUDE_FILES(soundcard.h HAVE_SOUNDCARD_H) # less common, but exists. # NetBSD and OpenBSD uses ossaudio emulation layer, # otherwise no link library is needed. IF(CMAKE_SYSTEM_NAME MATCHES "kNetBSD.*|NetBSD.*|kOpenBSD.*|OpenBSD.*") # AND HAVE_SOUNDCARD_H ??? FIND_LIBRARY(OSSAUDIO_LIBRARIES "ossaudio") IF(OSSAUDIO_LIBRARIES STREQUAL "OSSAUDIO_LIBRARIES-NOTFOUND") SET(OSSAUDIO_LIBRARIES) ELSE() MESSAGE(STATUS "Found libossaudio: ${OSSAUDIO_LIBRARIES}") SET(OSS_LIBRARY ${OSSAUDIO_LIBRARIES}) ENDIF() ELSE() SET(OSSAUDIO_LIBRARIES) ENDIF() SET(OLD_REQUIRED_LIBRARIES "${CMAKE_REQUIRED_LIBRARIES}") IF(OSSAUDIO_LIBRARIES) SET(CMAKE_REQUIRED_LIBRARIES ${OSSAUDIO_LIBRARIES}) ENDIF() IF(HAVE_SYS_SOUNDCARD_H) CHECK_C_SOURCE_COMPILES("#include #include int main() {return SNDCTL_DSP_RESET;}" OSS_FOUND) ELSEIF(HAVE_MACHINE_SOUNDCARD_H) CHECK_C_SOURCE_COMPILES("#include #include int main() {return SNDCTL_DSP_RESET;}" OSS_FOUND) ELSEIF(HAVE_SOUNDCARD_H) CHECK_C_SOURCE_COMPILES("#include #include int main() {return SNDCTL_DSP_RESET;}" OSS_FOUND) ENDIF() SET(CMAKE_REQUIRED_LIBRARIES "${OLD_REQUIRED_LIBRARIES}") MARK_AS_ADVANCED ( OSS_FOUND OSS_INCLUDE_DIR OSS_LIBRARY ) IF(OSS_FOUND) MESSAGE(STATUS "Found OSS.") ELSE() MESSAGE(STATUS "Could not find OSS.") ENDIF() wildmidi-wildmidi-0.3.8/cmake/Toolchain-MinGW32.cmake000066400000000000000000000014211245740225500222560ustar00rootroot00000000000000# toolchain file I use to cross compile on Linux # targetting Windows (x86/mingw). running: # cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-MinGW32.cmake .... SET(CMAKE_SYSTEM_NAME Windows) SET(CMAKE_C_COMPILER /usr/local/cross-win32/bin/i686-pc-mingw32-gcc) SET(CMAKE_CXX_COMPILER /usr/local/cross-win32/bin/i686-pc-mingw32-g++) SET(CMAKE_RC_COMPILER /usr/local/cross-win32/bin/i686-pc-mingw32-windres) # where is the target environment SET(CMAKE_FIND_ROOT_PATH /usr/local/cross-win32) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) wildmidi-wildmidi-0.3.8/cmake/Toolchain-MinGW64.cmake000066400000000000000000000014521245740225500222670ustar00rootroot00000000000000# toolchain file I use to cross compile on Linux # targetting Windows (x64/mingw-w64). running: # cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-MinGW64.cmake .... SET(CMAKE_SYSTEM_NAME Windows) SET(CMAKE_C_COMPILER /opt/cross_win64/bin/x86_64-w64-mingw32-gcc) SET(CMAKE_CXX_COMPILER /opt/cross_win64/bin/x86_64-w64-mingw32-g++) SET(CMAKE_RC_COMPILER /opt/cross_win64/bin/x86_64-w64-mingw32-windres) # where is the target environment SET(CMAKE_FIND_ROOT_PATH /opt/cross_win64 /opt/cross_win64/x86_64-w64-mingw32) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) wildmidi-wildmidi-0.3.8/cmake/Toolchain-OSX-ppc.cmake000066400000000000000000000013071245740225500223640ustar00rootroot00000000000000# toolchain file I use to cross compile on Linux # targetting OSX/Darwin (powerpc). running: # cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-OSX-ppc.cmake .... SET(CMAKE_SYSTEM_NAME Darwin) SET(CMAKE_C_COMPILER /opt/cross_osx-ppc/bin/powerpc-apple-darwin9-gcc) SET(CMAKE_CXX_COMPILER /opt/cross_osx-ppc/bin/powerpc-apple-darwin9-g++) # where is the target environment SET(CMAKE_FIND_ROOT_PATH /opt/cross_osx-ppc) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) wildmidi-wildmidi-0.3.8/cmake/Toolchain-OSX-x86.cmake000066400000000000000000000012751245740225500222330ustar00rootroot00000000000000# toolchain file I use to cross compile on Linux # targetting OSX/Darwin (x86). running: # cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-OSX-x86.cmake .... SET(CMAKE_SYSTEM_NAME Darwin) SET(CMAKE_C_COMPILER /opt/cross_osx-x86/bin/i686-apple-darwin9-gcc) SET(CMAKE_CXX_COMPILER /opt/cross_osx-x86/bin/i686-apple-darwin9-g++) # where is the target environment SET(CMAKE_FIND_ROOT_PATH /opt/cross_osx-x86) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) wildmidi-wildmidi-0.3.8/cmake/Toolchain-OSX-x86_64.cmake000066400000000000000000000013301245740225500225340ustar00rootroot00000000000000# toolchain file I use to cross compile on Linux # targetting OSX/Darwin (x86_64). running: # cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/Toolchain-OSX-x86_64.cmake .... SET(CMAKE_SYSTEM_NAME Darwin) SET(CMAKE_C_COMPILER /opt/cross_osx-x86_64/usr/bin/x86_64-apple-darwin9-gcc) SET(CMAKE_CXX_COMPILER /opt/cross_osx-x86_64/usr/bin/x86_64-apple-darwin9-g++) # where is the target environment SET(CMAKE_FIND_ROOT_PATH /opt/cross_osx-x86_64) # adjust the default behaviour of the FIND_XXX() commands: # search headers and libraries in the target environment, search # programs in the host environment SET(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) SET(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) SET(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) wildmidi-wildmidi-0.3.8/djgpp/000077500000000000000000000000001245740225500162365ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/djgpp/Makefile000066400000000000000000000032041245740225500176750ustar00rootroot00000000000000#------------------------------------------------------------------------------# # This is a Makefile for building libWildMidi using GNU Make and GNU C compiler # You will need a GCC/DJGPP package and GNU make to do it painlessly. #------------------------------------------------------------------------------# # Targets: # - all (default): make libWildMidi.a library and wildmidi.exe # - clean: clean up (remove all generated files) #------------------------------------------------------------------------------# # Set to 1 for debug build DEBUG = 0 # The tools ifeq ($(CROSS),) CC=gcc AS=as AR=ar RANLIB=ranlib else CC=$(CROSS)-gcc AS=$(CROSS)-as AR=$(CROSS)-ar RANLIB=$(CROSS)-ranlib endif INCLUDE = -I. -I../include CFLAGS = $(INCLUDE) -Wall -W -fno-common ARFLAGS = cr # SB output support (comment out if not wanted) CFLAGS+= -DAUDIODRV_DOSSB SB_OBJ = dosirq.o dosdma.o dossb.o LD = $(CC) LDFLAGS = -L. -lWildMidi -lm # build for pentium and newer (comment out if not wanted) CFLAGS += -march=i586 ifeq ($(DEBUG),1) CFLAGS += -g else CFLAGS += -O2 -fomit-frame-pointer -ffast-math LDFLAGS+= -s endif # Build rules %.o: %.c $(CC) -c $(CFLAGS) -o $@ $< %.o: ../src/%.c $(CC) -c $(CFLAGS) -o $@ $< # Objects LIB_OBJ= wm_error.o file_io.o lock.o wildmidi_lib.o reverb.o gus_pat.o PLAYER_OBJ= $(SB_OBJ) getopt_long.o wm_tty.o wildmidi.o # Build targets TARGETS = libWildMidi.a wildmidi.exe .PHONY: clean distclean all: $(TARGETS) libWildMidi.a: $(LIB_OBJ) $(AR) $(ARFLAGS) $@ $^ $(RANLIB) $@ wildmidi.exe: libWildMidi.a $(PLAYER_OBJ) $(LD) -o $@ $(PLAYER_OBJ) $(LDFLAGS) clean: rm -rf $(LIB_OBJ) $(PLAYER_OBJ) distclean: clean rm -rf $(TARGETS) wildmidi-wildmidi-0.3.8/djgpp/README000066400000000000000000000017071245740225500171230ustar00rootroot00000000000000This directory contains the Makefile and config.h needed to compile libWilMidi library and wildmidi player for DOS using DJGPP. To compile, you need DJGPP library and its associated compiler suite. Both djgpp-v2.03 and v2.04 should work. DJGPP is available from its official site at Cd in to the djgpp directory and run 'make', i.e.: cd djgpp make .. which will generate libWildMidi.a and wildmidi.exe. If necessary, edit the Makefile to meet your needs/environment. The player (wildmidi.exe) can either output to a Sound Blaster (SB1, SB2, SBPro, SB16, or compatible) hardware: wildmidi mymidi.mid ... or, it can generate a wav file: wildmidi -o output.wav mymidi.mid Use -r to specify a sample rate, use -c to point to your wildmidi.cfg config file: wildmidi -c c:\wildmidi.cfg -r 22050 mymidi.mid Run "wildmidi -h" to see other command line switches. wildmidi-wildmidi-0.3.8/djgpp/config.h000066400000000000000000000006501245740225500176550ustar00rootroot00000000000000#define VERSION "0.3.8" #define WILDMIDI_CFG "wildmidi.cfg" #define PACKAGE_URL "http://www.mindwerks.net/projects/wildmidi/" #define PACKAGE_BUGREPORT "https://github.com/Mindwerks/wildmidi/issues" #define PACKAGE_VERSION VERSION #define HAVE_C_INLINE #if (__GNUC__ > 2) || (__GNUC__ == 2 && __GNUC_MINOR >= 96) #define HAVE___BUILTIN_EXPECT #endif #ifndef HAVE___BUILTIN_EXPECT #define __builtin_expect(x,c) x #endif wildmidi-wildmidi-0.3.8/djgpp/dosdma.c000066400000000000000000000140141245740225500176510ustar00rootroot00000000000000/* Implementation of DMA routines on DOS - from libMikMod. Copyright (C) 1999 by Andrew Zabolotny, This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "dosdma.h" #include /* includes sys/version.h (djgpp >= 2.02) */ #include #include #include #include /* BUG WARNING: there is an error in DJGPP libraries <= 2.01: * src/libc/dpmi/api/d0102.s loads the selector and allocsize * arguments in the wrong order. DJGPP >= 2.02 have it fixed. */ #if !defined(__DJGPP_MINOR__) || (__DJGPP_MINOR__-0 < 2) #warning __dpmi_resize_dos_memory() from DJGPP <= 2.01 is broken! #endif __dma_regs dma[8] = { /* *INDENT-OFF* */ {DMA_ADDR_0, DMA_PAGE_0, DMA_SIZE_0, DMA1_MASK_REG, DMA1_CLEAR_FF_REG, DMA1_MODE_REG}, {DMA_ADDR_1, DMA_PAGE_1, DMA_SIZE_1, DMA1_MASK_REG, DMA1_CLEAR_FF_REG, DMA1_MODE_REG}, {DMA_ADDR_2, DMA_PAGE_2, DMA_SIZE_2, DMA1_MASK_REG, DMA1_CLEAR_FF_REG, DMA1_MODE_REG}, {DMA_ADDR_3, DMA_PAGE_3, DMA_SIZE_3, DMA1_MASK_REG, DMA1_CLEAR_FF_REG, DMA1_MODE_REG}, {DMA_ADDR_4, 0, DMA_SIZE_4, DMA2_MASK_REG, DMA2_CLEAR_FF_REG, DMA2_MODE_REG}, {DMA_ADDR_5, DMA_PAGE_5, DMA_SIZE_5, DMA2_MASK_REG, DMA2_CLEAR_FF_REG, DMA2_MODE_REG}, {DMA_ADDR_6, DMA_PAGE_6, DMA_SIZE_6, DMA2_MASK_REG, DMA2_CLEAR_FF_REG, DMA2_MODE_REG}, {DMA_ADDR_7, DMA_PAGE_7, DMA_SIZE_7, DMA2_MASK_REG, DMA2_CLEAR_FF_REG, DMA2_MODE_REG} /* *INDENT-ON* */ }; static int __initialized = 0; static int __buffer_count = 0; static __dpmi_meminfo __locked_data; int dma_initialize() { if (!__djgpp_nearptr_enable()) return 0; /* Trick: Avoid re-setting DS selector limit on each memory allocation call */ __djgpp_selector_limit = 0xffffffff; __locked_data.address = __djgpp_base_address + (unsigned long)&dma; __locked_data.size = sizeof(dma); if (__dpmi_lock_linear_region(&__locked_data)) return 0; return (__initialized = 1); } void dma_finalize() { if (!__initialized) return; __dpmi_unlock_linear_region(&__locked_data); __djgpp_nearptr_disable(); } dma_buffer *dma_allocate(unsigned int channel, unsigned int size) { int parsize = (size + 15) >> 4; /* size in paragraphs */ int par = 0; /* Real-mode paragraph */ int selector = 0; /* Protected-mode selector */ int mask = channel <= 3 ? 0xfff : 0x1fff; /* Alignment mask in para. */ int allocsize = parsize; /* Allocated size in paragraphs */ int count; /* Try count */ int bound = 0; /* Nearest bound address */ int maxsize; /* Maximal possible block size */ dma_buffer *buffer = NULL; __dpmi_meminfo buff_info, struct_info; if (!dma_initialize()) return NULL; /* Loop until we'll get a properly aligned memory block */ for (count = 8; count; count--) { int resize = (selector != 0); /* Try first to resize (possibly previously) allocated block */ if (resize) { maxsize = (bound + parsize) - par; if (maxsize > parsize * 2) maxsize = parsize * 2; if (maxsize == allocsize) resize = 0; else { allocsize = maxsize; if (__dpmi_resize_dos_memory(selector, allocsize, &maxsize) != 0) resize = 0; } } if (!resize) { if (selector) __dpmi_free_dos_memory(selector), selector = 0; par = __dpmi_allocate_dos_memory(allocsize, &selector); } if ((par == 0) || (par == -1)) goto exit; /* If memory block contains a properly aligned portion, quit loop */ bound = (par + mask + 1) & ~mask; if (par + parsize <= bound) break; if (bound + parsize <= par + allocsize) { par = bound; break; } } if (!count) { __dpmi_free_dos_memory(selector); goto exit; } buffer = (dma_buffer *) malloc(sizeof(dma_buffer)); buffer->linear = (unsigned char *)(__djgpp_conventional_base + bound * 16); buffer->physical = bound * 16; buffer->size = parsize * 16; buffer->selector = selector; buffer->channel = channel; buff_info.address = buffer->physical; buff_info.size = buffer->size; /* Don't pay attention to return code since under plain DOS it often returns error (at least under HIMEM/CWSDPMI and EMM386/DPMI) */ __dpmi_lock_linear_region(&buff_info); /* Lock the DMA buffer control structure as well */ struct_info.address = __djgpp_base_address + (unsigned long)buffer; struct_info.size = sizeof(dma_buffer); if (__dpmi_lock_linear_region(&struct_info)) { __dpmi_unlock_linear_region(&buff_info); __dpmi_free_dos_memory(selector); free(buffer); buffer = NULL; goto exit; } exit: if (buffer) __buffer_count++; else if (--__buffer_count == 0) dma_finalize(); return buffer; } void dma_free(dma_buffer * buffer) { __dpmi_meminfo buff_info; if (!buffer) return; buff_info.address = buffer->physical; buff_info.size = buffer->size; __dpmi_unlock_linear_region(&buff_info); __dpmi_free_dos_memory(buffer->selector); free(buffer); if (--__buffer_count == 0) dma_finalize(); } void dma_start(dma_buffer * buffer, unsigned long count, unsigned char mode) { /* Disable interrupts */ int old_ints = disable(); dma_disable(buffer->channel); dma_set_mode(buffer->channel, mode); dma_clear_ff(buffer->channel); dma_set_addr(buffer->channel, buffer->physical); dma_clear_ff(buffer->channel); dma_set_count(buffer->channel, count); dma_enable(buffer->channel); /* Re-enable interrupts */ if (old_ints) enable(); } wildmidi-wildmidi-0.3.8/djgpp/dosdma.h000066400000000000000000000143761245740225500176710ustar00rootroot00000000000000/* Interface for DMA routines on DOS -- from libMikMod. Copyright (C) 1999 by Andrew Zabolotny, This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __DOSDMA_H__ #define __DOSDMA_H__ #include #define DMA1_BASE 0x00 /* 8 bit slave DMA, channels 0..3 */ #define DMA2_BASE 0xC0 /* 16 bit master DMA, ch 4(=slave input)..7 */ #define DMA1_CMD_REG 0x08 /* command register (w) */ #define DMA1_STAT_REG 0x08 /* status register (r) */ #define DMA1_REQ_REG 0x09 /* request register (w) */ #define DMA1_MASK_REG 0x0A /* single-channel mask (w) */ #define DMA1_MODE_REG 0x0B /* mode register (w) */ #define DMA1_CLEAR_FF_REG 0x0C /* clear pointer flip-flop (w) */ #define DMA1_TEMP_REG 0x0D /* Temporary Register (r) */ #define DMA1_RESET_REG 0x0D /* Master Clear (w) */ #define DMA1_CLR_MASK_REG 0x0E /* Clear Mask */ #define DMA1_MASK_ALL_REG 0x0F /* all-channels mask (w) */ #define DMA2_CMD_REG 0xD0 /* command register (w) */ #define DMA2_STAT_REG 0xD0 /* status register (r) */ #define DMA2_REQ_REG 0xD2 /* request register (w) */ #define DMA2_MASK_REG 0xD4 /* single-channel mask (w) */ #define DMA2_MODE_REG 0xD6 /* mode register (w) */ #define DMA2_CLEAR_FF_REG 0xD8 /* clear pointer flip-flop (w) */ #define DMA2_TEMP_REG 0xDA /* Temporary Register (r) */ #define DMA2_RESET_REG 0xDA /* Master Clear (w) */ #define DMA2_CLR_MASK_REG 0xDC /* Clear Mask */ #define DMA2_MASK_ALL_REG 0xDE /* all-channels mask (w) */ #define DMA_ADDR_0 0x00 /* DMA address registers */ #define DMA_ADDR_1 0x02 #define DMA_ADDR_2 0x04 #define DMA_ADDR_3 0x06 #define DMA_ADDR_4 0xC0 #define DMA_ADDR_5 0xC4 #define DMA_ADDR_6 0xC8 #define DMA_ADDR_7 0xCC #define DMA_SIZE_0 0x01 /* DMA transfer size registers */ #define DMA_SIZE_1 0x03 #define DMA_SIZE_2 0x05 #define DMA_SIZE_3 0x07 #define DMA_SIZE_4 0xC2 #define DMA_SIZE_5 0xC6 #define DMA_SIZE_6 0xCA #define DMA_SIZE_7 0xCE #define DMA_PAGE_0 0x87 /* DMA page registers */ #define DMA_PAGE_1 0x83 #define DMA_PAGE_2 0x81 #define DMA_PAGE_3 0x82 #define DMA_PAGE_5 0x8B #define DMA_PAGE_6 0x89 #define DMA_PAGE_7 0x8A #define DMA_MODE_AUTOINIT 0x10 /* Auto-init mode bit */ #define DMA_MODE_READ 0x44 /* I/O to memory, no autoinit, increment, single mode */ #define DMA_MODE_WRITE 0x48 /* memory to I/O, no autoinit, increment, single mode */ #define DMA_MODE_CASCADE 0xC0 /* pass thru DREQ->HRQ, DACK<-HLDA only */ /* Indexable specific DMA registers */ typedef struct __dma_regs_s { unsigned char addr; /* DMA transfer address register */ unsigned char page; /* DMA page register */ unsigned char size; /* DMA transfer size register */ unsigned char mask; /* DMA mask/unmask register */ unsigned char flip; /* DMA flip-flop reset register */ unsigned char mode; /* DMA mode register */ } __dma_regs; extern __dma_regs dma[8]; /* Enable a specific DMA channel */ static inline void dma_enable(unsigned int channel) { outportb(dma[channel].mask, channel & 3); } /* Disable a specific DMA channel */ static inline void dma_disable(unsigned int channel) { outportb(dma[channel].mask, (channel & 3) | 0x04); } /* Clear the 'DMA Flip Flop' flag */ static inline void dma_clear_ff(unsigned int channel) { outportb(dma[channel].flip, 0); } /* Set mode for a specific DMA channel */ static inline void dma_set_mode(unsigned int channel, char mode) { outportb(dma[channel].mode, mode | (channel & 3)); } /* Set DMA page register */ static inline void dma_set_page(unsigned int channel, char page) { if (channel > 3) page &= 0xfe; outportb(dma[channel].page, page); } /* Set transfer address & page bits for specific DMA channel. Assumes dma flipflop is clear. */ static inline void dma_set_addr(unsigned int channel, unsigned int address) { unsigned char dma_reg = dma[channel].addr; dma_set_page(channel, address >> 16); if (channel <= 3) { outportb(dma_reg, (address) & 0xff); outportb(dma_reg, (address >> 8) & 0xff); } else { outportb(dma_reg, (address >> 1) & 0xff); outportb(dma_reg, (address >> 9) & 0xff); } } /* Set transfer size for a specific DMA channel. Assumes dma flip-flop is clear. */ static inline void dma_set_count(unsigned int channel, unsigned int count) { unsigned char dma_reg = dma[channel].size; count--; /* number of DMA transfers is bigger by one */ if (channel > 3) count >>= 1; outportb(dma_reg, (count) & 0xff); outportb(dma_reg, (count >> 8) & 0xff); } /* Query the number of bytes left to transfer. Assumes DMA flip-flop is clear. */ static inline int dma_get_count(unsigned int channel) { unsigned char dma_reg = dma[channel].size; /* using short to get 16-bit wrap around */ unsigned short count; count = inportb(dma_reg); count |= inportb(dma_reg) << 8; count++; return (channel <= 3) ? count : (count << 1); } typedef struct dma_buffer_s { unsigned char *linear; /* Linear address */ unsigned long physical; /* Physical address */ unsigned long size; /* Buffer size */ unsigned short selector; /* The selector assigned to this memory */ unsigned char channel; /* The DMA channel */ } dma_buffer; /* Allocate a block of memory suitable for using as a DMA buffer */ extern dma_buffer *dma_allocate(unsigned int channel, unsigned int size); /* Deallocate a DMA buffer */ extern void dma_free(dma_buffer * buffer); /* Start DMA transfer to or from given buffer */ extern void dma_start(dma_buffer * buffer, unsigned long count, unsigned char mode); #endif /* __DOSDMA_H__ */ wildmidi-wildmidi-0.3.8/djgpp/dosirq.c000066400000000000000000000210631245740225500177050ustar00rootroot00000000000000/* Implementation of IRQ routines on DOS -- from libMikMod. Copyright (C) 1999 by Andrew Zabolotny, This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "dosirq.h" #include #include #include #include #include #include unsigned int __irq_stack_size = 0x4000; unsigned int __irq_stack_count = 1; static void __int_stub_template (void) { /* *INDENT-OFF* */ asm(" pushal\n" " pushl %ds\n" " pushl %es\n" " pushl %fs\n" " pushl %gs\n" " movw $0x1234,%ax\n" /* Get DPMI data selector */ " movw %ax,%ds\n" /* Set DS and ES to data selector */ " movw %ax,%es\n" " movl $0x12345678,%ebx\n" /* Interrupt stack top */ " movl (%ebx),%ecx\n" " movl %ecx,%edx\n" " subl $0x12345678,%ecx\n" /* Subtract irq_stack_count */ " movl %ecx,(%ebx)\n" " movw %ss,%si\n" /* Save old SS:ESP */ " movl %esp,%edi\n" " movl %edx,%esp\n" /* Set SS:ESP to interrupt stack */ " movw %ax,%ss\n" " pushl %esi\n" " pushl %edi\n" " pushl %ebx\n" " pushl %edx\n" " call 1f\n" /* Call user interrupt handler */ "1: popl %edx\n" " popl %ebx\n" " movl %edx,(%ebx)\n" " popl %edi\n" " popl %esi\n" " movl %edi,%esp\n" /* Restore old SS:ESP */ " movw %si,%ss\n" " popl %gs\n" " popl %fs\n" " popl %es\n" " popl %ds\n" " popal\n" " iret\n"); /* *INDENT-ON* */ } #include static int _allocate_iret_wrapper(_go32_dpmi_seginfo * info) { unsigned char *irqtpl = (unsigned char *)__int_stub_template; unsigned char *irqend, *irqwrapper, *tmp; __dpmi_meminfo handler_info; unsigned int wrappersize; /* First, skip until pushal */ while (*irqtpl != 0x60) irqtpl++; /* Now find the iret */ irqend = irqtpl; while (*irqend++ != 0xcf); wrappersize = 4 + __irq_stack_size * __irq_stack_count + 4 + ((long)irqend - (long)irqtpl); irqwrapper = (unsigned char *) malloc(wrappersize); /* Lock the wrapper */ handler_info.address = __djgpp_base_address + (unsigned long)irqwrapper; handler_info.size = wrappersize; if (__dpmi_lock_linear_region(&handler_info)) { free(irqwrapper); return -1; } /* First comes the interrupt wrapper size */ *(unsigned long *)irqwrapper = wrappersize; /* Next comes the interrupt stack */ tmp = irqwrapper + 4 + __irq_stack_size * __irq_stack_count; /* The following dword is interrupt stack pointer */ *((void **)tmp) = tmp; tmp += 4; /* Now comes the interrupt wrapper itself */ memcpy(tmp, irqtpl, irqend - irqtpl); *(unsigned short *)(tmp + 9) = _my_ds(); *(unsigned long *)(tmp + 16) = (unsigned long)tmp - 4; *(unsigned long *)(tmp + 26) = __irq_stack_size; *(unsigned long *)(tmp + 46) = info->pm_offset - (unsigned long)(tmp + 50); info->pm_offset = (unsigned long)tmp; info->pm_selector = _my_cs(); return 0; } static void _free_iret_wrapper(_go32_dpmi_seginfo * info) { __dpmi_meminfo handler_info; info->pm_offset -= 4 + __irq_stack_size * __irq_stack_count + 4; handler_info.address = __djgpp_base_address + info->pm_offset; handler_info.size = *(unsigned long *)info->pm_offset; __dpmi_unlock_linear_region(&handler_info); free((void *)info->pm_offset); } struct irq_handle *irq_hook(int irqno, void (*handler)(), unsigned long size) { int interrupt; struct irq_handle *irq; __dpmi_version_ret version; __dpmi_meminfo handler_info, struct_info; _go32_dpmi_seginfo info; unsigned long old_sel, old_ofs; __dpmi_get_version(&version); if (irqno < 8) interrupt = version.master_pic + irqno; else interrupt = version.slave_pic + (irqno - 8); if (_go32_dpmi_get_protected_mode_interrupt_vector(interrupt, &info)) return NULL; old_sel = info.pm_selector; old_ofs = info.pm_offset; info.pm_offset = (unsigned long)handler; if (_allocate_iret_wrapper(&info)) return NULL; /* Lock the interrupt handler in memory */ handler_info.address = __djgpp_base_address + (unsigned long)handler; handler_info.size = size; if (__dpmi_lock_linear_region(&handler_info)) { _free_iret_wrapper(&info); return NULL; } irq = (struct irq_handle *) malloc(sizeof(struct irq_handle)); irq->c_handler = handler; irq->handler_size = size; irq->handler = info.pm_offset; irq->prev_selector = old_sel; irq->prev_offset = old_ofs; irq->int_num = interrupt; irq->irq_num = irqno; irq->pic_base = irqno < 8 ? PIC1_BASE : PIC2_BASE; struct_info.address = __djgpp_base_address + (unsigned long)irq; struct_info.size = sizeof(struct irq_handle); if (__dpmi_lock_linear_region(&struct_info)) { free(irq); __dpmi_unlock_linear_region(&handler_info); _free_iret_wrapper(&info); return NULL; } _go32_dpmi_set_protected_mode_interrupt_vector(interrupt, &info); irq->pic_mask = irq_state(irq); return irq; } void irq_unhook(struct irq_handle *irq) { _go32_dpmi_seginfo info; __dpmi_meminfo mem_info; if (!irq) return; /* Restore the interrupt vector */ irq_disable(irq); info.pm_offset = irq->prev_offset; info.pm_selector = irq->prev_selector; _go32_dpmi_set_protected_mode_interrupt_vector(irq->int_num, &info); /* Unlock the interrupt handler */ mem_info.address = __djgpp_base_address + (unsigned long)irq->c_handler; mem_info.size = irq->handler_size; __dpmi_unlock_linear_region(&mem_info); /* Unlock the irq_handle structure */ mem_info.address = __djgpp_base_address + (unsigned long)irq; mem_info.size = sizeof(struct irq_handle); __dpmi_unlock_linear_region(&mem_info); info.pm_offset = irq->handler; _free_iret_wrapper(&info); /* If IRQ was enabled before we hooked, restore enabled state */ if (irq->pic_mask) irq_enable(irq); else irq_disable(irq); free(irq); } /*---------------------------------------------- IRQ detection mechanism -----*/ static struct irq_handle *__irqs[16]; static int (*__irq_confirm) (int irqno); static volatile unsigned int __irq_mask; static volatile unsigned int __irq_count[16]; #define DECLARE_IRQ_HANDLER(irqno) \ static void __irq##irqno##_handler () \ { \ if (irq_check (__irqs [irqno]) && __irq_confirm (irqno)) \ { \ __irq_count [irqno]++; \ __irq_mask |= (1 << irqno); \ } \ irq_ack (__irqs [irqno]); \ } /* *INDENT-OFF* */ DECLARE_IRQ_HANDLER(0) DECLARE_IRQ_HANDLER(1) DECLARE_IRQ_HANDLER(2) DECLARE_IRQ_HANDLER(3) DECLARE_IRQ_HANDLER(4) DECLARE_IRQ_HANDLER(5) DECLARE_IRQ_HANDLER(6) DECLARE_IRQ_HANDLER(7) DECLARE_IRQ_HANDLER(8) DECLARE_IRQ_HANDLER(9) DECLARE_IRQ_HANDLER(10) DECLARE_IRQ_HANDLER(11) DECLARE_IRQ_HANDLER(12) DECLARE_IRQ_HANDLER(13) DECLARE_IRQ_HANDLER(14) DECLARE_IRQ_HANDLER(15) /* *INDENT-ON* */ static void (*__irq_handlers[16]) () = { __irq0_handler, __irq1_handler, __irq2_handler, __irq3_handler, __irq4_handler, __irq5_handler, __irq6_handler, __irq7_handler, __irq8_handler, __irq9_handler, __irq10_handler, __irq11_handler, __irq12_handler, __irq13_handler, __irq14_handler, __irq15_handler}; void irq_detect_start(unsigned int irqs, int (*irq_confirm) (int irqno)) { int i; __irq_mask = 0; __irq_confirm = irq_confirm; memset(&__irqs, 0, sizeof(__irqs)); memset((void *) &__irq_count, 0, sizeof(__irq_count)); /* Hook all specified IRQs */ for (i = 1; i <= 15; i++) if (irqs & (1 << i)) { __irqs[i] = irq_hook(i, __irq_handlers[i], 200); /* Enable the interrupt */ irq_enable(__irqs[i]); } /* Enable IRQ2 if we need at least one IRQ above 7 */ if (irqs & 0xff00) _irq_enable(2); } void irq_detect_end() { int i; for (i = 15; i >= 1; i--) if (__irqs[i]) irq_unhook(__irqs[i]); } int irq_detect_get(int irqno, unsigned int *irqmask) { int oldirq = disable(); int count = __irq_count[irqno]; *irqmask = __irq_mask; __irq_mask = 0; if (oldirq) enable(); return count; } void irq_detect_clear() { int oldirq = disable(); memset((void *) &__irq_count, 0, sizeof(__irq_count)); __irq_mask = 0; if (oldirq) enable(); } wildmidi-wildmidi-0.3.8/djgpp/dosirq.h000066400000000000000000000107241245740225500177140ustar00rootroot00000000000000/* Interface for IRQ routines on DOS -- from libMikMod. Copyright (C) 1999 by Andrew Zabolotny, This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __DOSIRQ_H__ #define __DOSIRQ_H__ #include #define PIC1_BASE 0x20 /* PIC1 base */ #define PIC2_BASE 0xA0 /* PIC2 base */ struct irq_handle { void (*c_handler) (); /* The real interrupt handler */ unsigned long handler_size; /* The size of interrupt handler */ unsigned long handler; /* Interrupt wrapper address */ unsigned long prev_selector; /* Selector of previous handler */ unsigned long prev_offset; /* Offset of previous handler */ unsigned char irq_num; /* IRQ number */ unsigned char int_num; /* Interrupt number */ unsigned char pic_base; /* PIC base (0x20 or 0xA0) */ unsigned char pic_mask; /* Old PIC mask state */ }; /* Return the enabled state for specific IRQ */ static inline unsigned char irq_state(struct irq_handle * irq) { return ((~inportb(irq->pic_base + 1)) & (0x01 << (irq->irq_num & 7))); } /* Acknowledge the end of interrupt */ static inline void _irq_ack(int irqno) { outportb(irqno > 7 ? PIC2_BASE : PIC1_BASE, 0x60 | (irqno & 7)); /* For second controller we also should acknowledge first controller */ if (irqno > 7) outportb(PIC1_BASE, 0x20); /* 0x20, 0x62? */ } /* Acknowledge the end of interrupt */ static inline void irq_ack(struct irq_handle * irq) { outportb(irq->pic_base, 0x60 | (irq->irq_num & 7)); /* For second controller we also should acknowledge first controller */ if (irq->pic_base != PIC1_BASE) outportb(PIC1_BASE, 0x20); /* 0x20, 0x62? */ } /* Mask (disable) the particular IRQ given his ordinal */ static inline void _irq_disable(int irqno) { unsigned int port_no = (irqno < 8 ? PIC1_BASE : PIC2_BASE) + 1; outportb(port_no, inportb(port_no) | (1 << (irqno & 7))); } /* Unmask (enable) the particular IRQ given its ordinal */ static inline void _irq_enable(int irqno) { unsigned int port_no = (irqno < 8 ? PIC1_BASE : PIC2_BASE) + 1; outportb(port_no, inportb(port_no) & ~(1 << (irqno & 7))); } /* Mask (disable) the particular IRQ given its irq_handle structure */ static inline void irq_disable(struct irq_handle * irq) { outportb(irq->pic_base + 1, inportb(irq->pic_base + 1) | (1 << (irq->irq_num & 7))); } /* Unmask (enable) the particular IRQ given its irq_handle structure */ static inline void irq_enable(struct irq_handle * irq) { outportb(irq->pic_base + 1, inportb(irq->pic_base + 1) & ~(1 << (irq->irq_num & 7))); } /* Check if a specific IRQ is pending: return 0 is no */ static inline int irq_check(struct irq_handle * irq) { outportb(irq->pic_base, 0x0B); /* Read IRR vector */ return (inportb(irq->pic_base) & (1 << (irq->irq_num & 7))); } /* Hook a specific IRQ; NOTE: IRQ is disabled upon return, irq_enable() it */ extern struct irq_handle *irq_hook(int irqno, void (*handler)(), unsigned long size); /* Unhook a previously hooked IRQ */ extern void irq_unhook(struct irq_handle * irq); /* Start IRQ detection process (IRQ list is given with irq mask) */ /* irq_confirm should return "1" if the IRQ really comes from the device */ extern void irq_detect_start(unsigned int irqs, int (*irq_confirm) (int irqno)); /* Finish IRQ detection process */ extern void irq_detect_end(); /* Get the count of specific irqno that happened */ extern int irq_detect_get(int irqno, unsigned int *irqmask); /* Clear IRQ counters */ extern void irq_detect_clear(); /* The size of interrupt stack */ extern unsigned int __irq_stack_size; /* The number of nested interrupts that can be handled */ extern unsigned int __irq_stack_count; #endif /* __DOSIRQ_H__ */ wildmidi-wildmidi-0.3.8/djgpp/dossb.c000066400000000000000000000313021245740225500175130ustar00rootroot00000000000000/* Sound Blaster I/O routines, common for SB8, SBPro and SB16 -- from libMikMod. Written by Andrew Zabolotny Further bug fixes by O. Sezer This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include #include #include #include #include #include #include #include "dossb.h" /********************************************* Private variables/routines *****/ __sb_state sb; /* Wait for SoundBlaster for some time */ #if (__GNUC__ < 3) || (__GNUC__ == 3 && __GNUC_MINOR__ == 0) # define _func_noinline volatile /* match original code */ # define _func_noclone #else /* avoid warnings from newer gcc: * "function definition has qualified void return type" and * function return types not compatible due to 'volatile' */ # define _func_noinline __attribute__((__noinline__)) # if (__GNUC__ < 4) || (__GNUC__ == 4 && __GNUC_MINOR__ < 5) # define _func_noclone # else # define _func_noclone __attribute__((__noclone__)) # endif #endif _func_noinline _func_noclone void __sb_wait() { inportb(SB_DSP_RESET); inportb(SB_DSP_RESET); inportb(SB_DSP_RESET); inportb(SB_DSP_RESET); inportb(SB_DSP_RESET); inportb(SB_DSP_RESET); } static void sb_irq() { /* Make sure its not a spurious IRQ */ if (!irq_check(sb.irq_handle)) return; sb.irqcount++; /* Acknowledge DMA transfer is complete */ if (sb.mode & SBMODE_16BITS) __sb_dsp_ack_dma16(); else __sb_dsp_ack_dma8(); /* SoundBlaster 1.x cannot do autoinit ... */ if (sb.dspver < SBVER_20) __sb_dspreg_outwlh(SBDSP_DMA_PCM8, (sb.dma_buff->size >> 1) - 1); /* Send EOI */ irq_ack(sb.irq_handle); enable(); if (sb.timer_callback) sb.timer_callback(); } static void sb_irq_end() { } static boolean __sb_reset() { /* Disable the output */ sb_output(FALSE); /* Clear pending ints if any */ __sb_dsp_ack_dma8(); __sb_dsp_ack_dma16(); /* Reset the DSP */ outportb(SB_DSP_RESET, SBM_DSP_RESET); __sb_wait(); __sb_wait(); outportb(SB_DSP_RESET, 0); /* Now wait for AA coming from datain port */ if (__sb_dsp_in() != 0xaa) return FALSE; /* Finally, get the DSP version */ if ((sb.dspver = __sb_dsp_version()) == 0xffff) return FALSE; /* Check again */ if (sb.dspver != __sb_dsp_version()) return FALSE; return TRUE; } /***************************************************** SB detection stuff *****/ static int __sb_irq_irqdetect(int irqno) { (void)irqno; __sb_dsp_ack_dma8(); return 1; } static void __sb_irq_dmadetect() { /* Make sure its not a spurious IRQ */ if (!irq_check(sb.irq_handle)) return; sb.irqcount++; /* Acknowledge DMA transfer is complete */ if (sb.mode & SBMODE_16BITS) __sb_dsp_ack_dma16(); else __sb_dsp_ack_dma8(); /* Send EOI */ irq_ack(sb.irq_handle); } static boolean __sb_detect() { /* First find the port number */ if (!sb.port) { int i; for (i = 5; i >= 0; i--) { sb.port = 0x210 + i * 0x10; if (__sb_reset()) break; } if (i < 0) { sb.port = 0; return FALSE; } } /* Now detect the IRQ and DMA numbers */ if (!sb.irq) { unsigned int irqmask, sbirqmask, sbirqcount; unsigned long timer; /* IRQ can be one of 2,3,5,7,10 */ irq_detect_start(0x04ac, __sb_irq_irqdetect); /* Prepare timeout counter */ _farsetsel(_dos_ds); timer = _farnspeekl(0x46c); sbirqmask = 0; sbirqcount = 10; /* Emit 10 SB irqs */ /* Tell SoundBlaster to emit IRQ for 8-bit transfers */ __sb_dsp_out(SBDSP_GEN_IRQ8); __sb_wait(); for (;;) { irq_detect_get(0, &irqmask); if (irqmask) { sbirqmask |= irqmask; if (!--sbirqcount) break; __sb_dsp_out(SBDSP_GEN_IRQ8); } if (_farnspeekl(0x46c) - timer >= 9) /* Wait ~1/2 secs */ break; } if (sbirqmask) for (sb.irq = 15; sb.irq > 0; sb.irq--) if (irq_detect_get(sb.irq, &irqmask) == 10) break; irq_detect_end(); if (!sb.irq) return FALSE; } /* Detect the 8-bit and 16-bit DMAs */ if (!sb.dma8 || ((sb.dspver >= SBVER_16) && !sb.dma16)) { static int __dma8[] = { 0, 1, 3 }; static int __dma16[] = { 5, 6, 7 }; int *dma; sb_output(FALSE); /* Temporary hook SB IRQ */ sb.irq_handle = irq_hook(sb.irq, __sb_irq_dmadetect, 200); irq_enable(sb.irq_handle); if (sb.irq > 7) _irq_enable(2); /* Start a short DMA transfer and check if IRQ happened */ for (;;) { int i, oldcount; unsigned int timer; if (!sb.dma8) dma = &sb.dma8; else if ((sb.dspver >= SBVER_16) && !sb.dma16) dma = &sb.dma16; else break; for (i = 0; i < 3; i++) { boolean success = 1; *dma = (dma == &sb.dma8) ? __dma8[i] : __dma16[i]; oldcount = sb.irqcount; dma_disable(*dma); dma_set_mode(*dma, DMA_MODE_WRITE); dma_clear_ff(*dma); dma_set_count(*dma, 2); dma_enable(*dma); __sb_dspreg_out(SBDSP_SET_TIMING, 206); /* 20KHz */ if (dma == &sb.dma8) { sb.mode = 0; __sb_dspreg_outwlh(SBDSP_DMA_PCM8, 1); } else { sb.mode = SBMODE_16BITS; __sb_dspreg_out(SBDSP_DMA_GENERIC16, 0); __sb_dsp_out(0); __sb_dsp_out(1); } _farsetsel(_dos_ds); timer = _farnspeekl(0x46c); while (oldcount == sb.irqcount) if (_farnspeekl(0x46c) - timer >= 2) { success = 0; break; } dma_disable(*dma); if (success) break; *dma = 0; } if (!*dma) break; } irq_unhook(sb.irq_handle); sb.irq_handle = NULL; if (!sb.dma8 || ((sb.dspver >= SBVER_16) && !sb.dma16)) return FALSE; } return TRUE; } /*************************************************** High-level interface *****/ /* Detect whenever SoundBlaster is present and fill "sb" structure */ boolean sb_detect() { char *env; /* Try to find the port and DMA from environment */ env = getenv("BLASTER"); while (env && *env) { /* Skip whitespace */ while ((*env == ' ') || (*env == '\t')) env++; if (!*env) break; switch (*env++) { case 'A': case 'a': if (!sb.port) sb.port = strtol(env, &env, 16); break; case 'E': case 'e': if (!sb.aweport) sb.aweport = strtol(env, &env, 16); break; case 'I': case 'i': if (!sb.irq) sb.irq = strtol(env, &env, 10); break; case 'D': case 'd': if (!sb.dma8) sb.dma8 = strtol(env, &env, 10); break; case 'H': case 'h': if (!sb.dma16) sb.dma16 = strtol(env, &env, 10); break; default: /* Skip other values (H == MIDI, T == model, any other?) */ while (*env && (*env != ' ') && (*env != '\t')) env++; break; } } /* Try to detect missing sound card parameters */ __sb_detect(); if (!sb.port || !sb.irq || !sb.dma8) return FALSE; if (!__sb_reset()) return FALSE; if ((sb.dspver >= SBVER_16) && !sb.dma16) return FALSE; if (sb.dspver >= SBVER_PRO) sb.caps |= SBMODE_STEREO; if (sb.dspver >= SBVER_16 && sb.dma16) sb.caps |= SBMODE_16BITS; if (sb.dspver < SBVER_20) sb.maxfreq_mono = 22222; else sb.maxfreq_mono = 45454; if (sb.dspver <= SBVER_16) sb.maxfreq_stereo = 22727; else sb.maxfreq_stereo = 45454; sb.ok = 1; return TRUE; } /* Reset SoundBlaster */ void sb_reset() { sb_stop_dma(); __sb_reset(); } /* Start working with SoundBlaster */ boolean sb_open() { __dpmi_meminfo struct_info; if (!sb.ok) if (!sb_detect()) return FALSE; if (sb.open) return FALSE; /* Now lock the sb structure in memory */ struct_info.address = __djgpp_base_address + (unsigned long)&sb; struct_info.size = sizeof(sb); if (__dpmi_lock_linear_region(&struct_info)) return FALSE; /* Hook the SB IRQ */ sb.irq_handle = irq_hook(sb.irq, sb_irq, (long)sb_irq_end - (long)sb_irq); if (!sb.irq_handle) { __dpmi_unlock_linear_region(&struct_info); return FALSE; } /* Enable the interrupt */ irq_enable(sb.irq_handle); if (sb.irq > 7) _irq_enable(2); sb.open++; return TRUE; } /* Finish working with SoundBlaster */ boolean sb_close() { __dpmi_meminfo struct_info; if (!sb.open) return FALSE; sb.open--; /* Stop/free DMA buffer */ sb_stop_dma(); /* Unhook IRQ */ irq_unhook(sb.irq_handle); sb.irq_handle = NULL; /* Unlock the sb structure */ struct_info.address = __djgpp_base_address + (unsigned long)&sb; struct_info.size = sizeof(sb); __dpmi_unlock_linear_region(&struct_info); return TRUE; } /* Enable/disable stereo DSP mode */ /* Enable/disable speaker output */ void sb_output(boolean enable) { __sb_dsp_out(enable ? SBDSP_SPEAKER_ENA : SBDSP_SPEAKER_DIS); } /* Start playing from DMA buffer */ boolean sb_start_dma(unsigned char mode, unsigned int freq) { int dmachannel = (mode & SBMODE_16BITS) ? sb.dma16 : sb.dma8; int dmabuffsize; unsigned int tc = 0; /* timing constant (<=sbpro only) */ /* Stop DMA transfer if it is enabled */ sb_stop_dma(); /* Sanity check */ if ((mode & SBMODE_MASK & sb.caps) != (mode & SBMODE_MASK)) return FALSE; /* Check this SB can perform at requested frequency */ if (((mode & SBMODE_STEREO) && (freq > sb.maxfreq_stereo)) || (!(mode & SBMODE_STEREO) && (freq > sb.maxfreq_mono))) return FALSE; /* Check the timing constant here to avoid failing later */ if (sb.dspver < SBVER_16) { /* SBpro cannot do signed transfer */ if (mode & SBMODE_SIGNED) return FALSE; /* Old SBs have a different way on setting DMA timing constant */ tc = freq; if (mode & SBMODE_STEREO) tc *= 2; tc = 1000000 / tc; if (tc > 255) return FALSE; } sb.mode = mode; /* Get a DMA buffer enough for a 1/4sec interval... 4K <= dmasize <= 32K */ dmabuffsize = freq; if (mode & SBMODE_STEREO) dmabuffsize *= 2; if (mode & SBMODE_16BITS) dmabuffsize *= 2; dmabuffsize >>= 2; if (dmabuffsize < 4096) dmabuffsize = 4096; if (dmabuffsize > 32768) dmabuffsize = 32768; dmabuffsize = (dmabuffsize + 255) & 0xffffff00; sb.dma_buff = dma_allocate(dmachannel, dmabuffsize); if (!sb.dma_buff) return FALSE; /* Fill DMA buffer with silence */ dmabuffsize = sb.dma_buff->size; if (mode & SBMODE_SIGNED) memset(sb.dma_buff->linear, 0, dmabuffsize); else memset(sb.dma_buff->linear, 0x80, dmabuffsize); /* Prime DMA for transfer */ dma_start(sb.dma_buff, dmabuffsize, DMA_MODE_WRITE | DMA_MODE_AUTOINIT); /* Tell SoundBlaster to start transfer */ if (sb.dspver >= SBVER_16) { /* SB16 */ __sb_dspreg_outwhl(SBDSP_SET_RATE, freq); /* Start DMA->DAC transfer */ __sb_dspreg_out(SBM_GENDAC_AUTOINIT | SBM_GENDAC_FIFO | ((mode & SBMODE_16BITS) ? SBDSP_DMA_GENERIC16 : SBDSP_DMA_GENERIC8), ((mode & SBMODE_SIGNED) ? SBM_GENDAC_SIGNED : 0) | ((mode & SBMODE_STEREO) ? SBM_GENDAC_STEREO : 0)); /* Write the length of transfer */ dmabuffsize = (dmabuffsize >> 2) - 1; __sb_dsp_out(dmabuffsize); __sb_dsp_out(dmabuffsize >> 8); } else { __sb_dspreg_out(SBDSP_SET_TIMING, 256 - tc); dmabuffsize = (dmabuffsize >> 1) - 1; if (sb.dspver >= SBVER_20) { /* SB 2.0/Pro */ /* Set stereo mode */ __sb_stereo((mode & SBMODE_STEREO) ? TRUE : FALSE); __sb_dspreg_outwlh(SBDSP_SET_DMA_BLOCK, dmabuffsize); if (sb.dspver >= SBVER_PRO) __sb_dsp_out(SBDSP_HS_DMA_DAC8_AUTO); else __sb_dsp_out(SBDSP_DMA_PCM8_AUTO); } else { /* Original SB */ /* Start DMA->DAC transfer */ __sb_dspreg_outwlh(SBDSP_DMA_PCM8, dmabuffsize); } } return TRUE; } /* Stop playing from DMA buffer */ void sb_stop_dma() { if (!sb.dma_buff) return; if (sb.mode & SBMODE_16BITS) __sb_dsp_out(SBDSP_DMA_HALT16); else __sb_dsp_out(SBDSP_DMA_HALT8); dma_disable(sb.dma_buff->channel); dma_free(sb.dma_buff); sb.dma_buff = NULL; } /* Query current position/total size of the DMA buffer */ void sb_query_dma(unsigned int *dma_size, unsigned int *dma_pos) { unsigned int dma_left; *dma_size = sb.dma_buff->size; /* It can happen we try to read DMA count when HI/LO bytes will be inconsistent */ for (;;) { unsigned int dma_left_test; dma_clear_ff(sb.dma_buff->channel); dma_left_test = dma_get_count(sb.dma_buff->channel); dma_left = dma_get_count(sb.dma_buff->channel); if ((dma_left >= dma_left_test) && (dma_left - dma_left_test < 10)) break; } *dma_pos = *dma_size - dma_left; } wildmidi-wildmidi-0.3.8/djgpp/dossb.h000066400000000000000000000353041245740225500175260ustar00rootroot00000000000000/* SoundBlaster and compatible soundcards definitions -- from libMikMod. Written by Andrew Zabolotny Further bug fixes by O.Sezer This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __DOSSB_H__ #define __DOSSB_H__ #include "dosdma.h" #include "dosirq.h" #define SB_FM_LEFT_STATUS (sb.port + 0x00) /* (r) Left FM status */ #define SB_FM_LEFT_REGSEL (sb.port + 0x00) /* (w) Left FM register select */ #define SB_FM_LEFT_DATA (sb.port + 0x01) /* (w) Left FM data */ #define SB_FM_RIGHT_STATUS (sb.port + 0x02) /* (r) Right FM status */ #define SB_FM_RIGHT_REGSEL (sb.port + 0x02) /* (w) Right FM register select */ #define SB_FM_RIGHT_DATA (sb.port + 0x03) /* (w) Right FM data */ #define SB_MIXER_REGSEL (sb.port + 0x04) /* (w) Mixer register select */ #define SB_MIXER_DATA (sb.port + 0x05) /* (rw)Mixer data */ #define SB_DSP_RESET (sb.port + 0x06) /* (w) DSP reset */ #define SB_FM_STATUS (sb.port + 0x08) /* (r) FM status */ #define SB_FM_REGSEL (sb.port + 0x08) /* (w) FM register select */ #define SB_FM_DATA (sb.port + 0x09) /* (w) FM data */ #define SB_DSP_DATA_IN (sb.port + 0x0a) /* (r) DSP data input */ #define SB_DSP_DATA_OUT (sb.port + 0x0c) /* (w) DSP data output */ #define SB_DSP_DATA_OUT_STATUS (sb.port + 0x0c) /* (r) DSP data output status */ #define SB_DSP_TIMER_IRQ (sb.port + 0x0d) /* (r) clear timer IRQ? */ #define SB_DSP_DATA_IN_STATUS (sb.port + 0x0e) /* (r) DSP data input status */ #define SB_DSP_DMA8_IRQ (sb.port + 0x0e) /* (r) Acknowledge 8-bit DMA transfer */ #define SB_DSP_DMA16_IRQ (sb.port + 0x0f) /* (r) Acknowledge 16-bit DMA transfer */ /* DSP commands */ #define SBDSP_ASP_STATUS 0x03 /* ASP Status (SB16ASP) */ #define SBDSP_STATUS_OLD 0x04 /* DSP Status (Obsolete) (SB2.0-Pro2) */ #define SBDSP_DIRECT_DAC 0x10 /* Direct DAC, 8-bit (SB) */ #define SBDSP_DMA_PCM8 0x14 /* DMA DAC, 8-bit (SB) */ #define SBDSP_DMA_ADPCM2 0x16 /* DMA DAC, 2-bit ADPCM (SB) */ #define SBDSP_DMA_ADPCM2R 0x17 /* DMA DAC, 2-bit ADPCM Reference (SB) */ #define SBDSP_DMA_PCM8_AUTO 0x1C /* Auto-Initialize DMA DAC, 8-bit (SB2.0) */ #define SBDSP_DMA_ADPCM2R_AUTO 0x1F /* Auto-Initialize DMA DAC, 2-bit ADPCM Reference (SB2.0) */ #define SBDSP_DIRECT_ADC 0x20 /* Direct ADC, 8-bit (SB) */ #define SBDSP_DMA_ADC8 0x24 /* DMA ADC, 8-bit (SB) */ #define SBDSP_DIRECT_ADC8_BURST 0x28 /* Direct ADC, 8-bit (Burst) (SB-Pro2) */ #define SBDSP_DMA_ADC8_AUTO 0x2C /* Auto-Initialize DMA ADC, 8-bit (SB2.0) */ #define SBDSP_MIDI_READ_POLL 0x30 /* MIDI Read Poll (SB) */ #define SBDSP_MIDI_READ_IRQ 0x31 /* MIDI Read Interrupt (SB) */ #define SBDSP_MIDI_READ_TIME 0x32 /* MIDI Read Timestamp Poll (SB???) */ #define SBDSP_MIDI_READ_TIME_IRQ 0x33 /* MIDI Read Timestamp Interrupt (SB???) */ #define SBDSP_MIDI_RW_POLL 0x34 /* MIDI Read Poll + Write Poll (UART) (SB2.0) */ #define SBDSP_MIDI_RW_IRQ 0x35 /* MIDI Read Interrupt + Write Poll (UART) (SB2.0???) */ #define SBDSP_MIDI_RW_TIME_IRQ 0x37 /* MIDI Read Timestamp Interrupt + Write Poll (UART) (SB2.0???) */ #define SBDSP_MIDI_WRITE_POLL 0x38 /* MIDI Write Poll (SB) */ #define SBDSP_SET_TIMING 0x40 /* Set Time Constant (SB) */ #define SBDSP_SET_RATE 0x41 /* Set Sample Rate, Hz (SB16) */ #define SBDSP_DMA_CONT8_AUTO 0x45 /* Continue Auto-Initialize DMA, 8-bit (SB16) */ #define SBDSP_DMA_CONT16_AUTO 0x47 /* Continue Auto-Initialize DMA, 16-bit (SB16) */ #define SBDSP_SET_DMA_BLOCK 0x48 /* Set DMA Block Size (SB2.0) */ #define SBDSP_DMA_ADPCM4 0x74 /* DMA DAC, 4-bit ADPCM (SB) */ #define SBDSP_DMA_ADPCM4_REF 0x75 /* DMA DAC, 4-bit ADPCM Reference (SB) */ #define SBDSP_DMA_ADPCM26 0x76 /* DMA DAC, 2.6-bit ADPCM (SB) */ #define SBDSP_DMA_ADPCM26_REF 0x77 /* DMA DAC, 2.6-bit ADPCM Reference (SB) */ #define SBDSP_DMA_ADPCM4R_AUTO 0x7D /* Auto-Initialize DMA DAC, 4-bit ADPCM Reference (SB2.0) */ #define SBDSP_DMA_ADPCM26R_AUTO 0x7F /* Auto-Initialize DMA DAC, 2.6-bit ADPCM Reference (SB2.0) */ #define SBDSP_DISABLE_DAC 0x80 /* Silence DAC (SB) */ #define SBDSP_HS_DMA_DAC8_AUTO 0x90 /* Auto-Initialize DMA DAC, 8-bit (High Speed) (SB2.0-Pro2) */ #define SBDSP_HS_DMA_ADC8_AUTO 0x98 /* Auto-Initialize DMA ADC, 8-bit (High Speed) (SB2.0-Pro2) */ #define SBDSP_STEREO_ADC_DIS 0xA0 /* Disable Stereo Input Mode (SBPro Only) */ #define SBDSP_STEREO_ADC_ENA 0xA8 /* Enable Stereo Input Mode (SBPro Only) */ #define SBDSP_DMA_GENERIC16 0xB0 /* Generic DAC/ADC DMA (16-bit) (SB16) */ #define SBDSP_DMA_GENERIC8 0xC0 /* Generic DAC/ADC DMA (8-bit) (SB16) */ #define SBDSP_DMA_HALT8 0xD0 /* Halt DMA Operation, 8-bit (SB) */ #define SBDSP_SPEAKER_ENA 0xD1 /* Enable Speaker (SB) */ #define SBDSP_SPEAKER_DIS 0xD3 /* Disable Speaker (SB) */ #define SBDSP_DMA_CONT8 0xD4 /* Continue DMA Operation, 8-bit (SB) */ #define SBDSP_DMA_HALT16 0xD5 /* Halt DMA Operation, 16-bit (SB16) */ #define SBDSP_DMA_CONT16 0xD6 /* Continue DMA Operation, 16-bit (SB16) */ #define SBDSP_SPEAKER_STATUS 0xD8 /* Speaker Status (SB) */ #define SBDSP_DMA_EXIT16_AUTO 0xD9 /* Exit Auto-Initialize DMA Operation, 16-bit (SB16) */ #define SBDSP_DMA_EXIT8_AUTO 0xDA /* Exit Auto-Initialize DMA Operation, 8-bit (SB2.0) */ #define SBDSP_IDENTIFY 0xE0 /* DSP Identification (SB2.0) */ #define SBDSP_VERSION 0xE1 /* DSP Version (SB) */ #define SBDSP_COPYRIGHT 0xE3 /* DSP Copyright (SBPro2???) */ #define SBDSP_WRITE_TEST 0xE4 /* Write Test Register (SB2.0) */ #define SBDSP_READ_TEST 0xE8 /* Read Test Register (SB2.0) */ #define SBDSP_SINE_GEN 0xF0 /* Sine Generator (SB) */ #define SBDSP_AUX_STATUS_PRO 0xF1 /* DSP Auxiliary Status (Obsolete) (SB-Pro2) */ #define SBDSP_GEN_IRQ8 0xF2 /* IRQ Request, 8-bit (SB) */ #define SBDSP_GEN_IRQ16 0xF3 /* IRQ Request, 16-bit (SB16) */ #define SBDSP_STATUS 0xFB /* DSP Status (SB16) */ #define SBDSP_AUX_STATUS_16 0xFC /* DSP Auxiliary Status (SB16) */ #define SBDSP_CMD_STATUS 0xFD /* DSP Command Status (SB16) */ /* Mixer commands */ #define SBMIX_RESET 0x00 /* Reset Write SBPro */ #define SBMIX_STATUS 0x01 /* Status Read SBPro */ #define SBMIX_MASTER_LEVEL1 0x02 /* Master Volume Read/Write SBPro Only */ #define SBMIX_DAC_LEVEL 0x04 /* DAC Level Read/Write SBPro */ #define SBMIX_FM_OUTPUT 0x06 /* FM Output Control Read/Write SBPro Only */ #define SBMIX_MIC_LEVEL 0x0A /* Microphone Level Read/Write SBPro */ #define SBMIX_INPUT_SELECT 0x0C /* Input/Filter Select Read/Write SBPro Only */ #define SBMIX_OUTPUT_SELECT 0x0E /* Output/Stereo Select Read/Write SBPro Only */ #define SBMIX_FM_LEVEL 0x22 /* Master Volume Read/Write SBPro */ #define SBMIX_MASTER_LEVEL 0x26 /* FM Level Read/Write SBPro */ #define SBMIX_CD_LEVEL 0x28 /* CD Audio Level Read/Write SBPro */ #define SBMIX_LINEIN_LEVEL 0x2E /* Line In Level Read/Write SBPro */ #define SBMIX_MASTER_LEVEL_L 0x30 /* Master Volume Left Read/Write SB16 */ #define SBMIX_MASTER_LEVEL_R 0x31 /* Master Volume Right Read/Write SB16 */ #define SBMIX_DAC_LEVEL_L 0x32 /* DAC Level Left Read/Write SB16 */ #define SBMIX_DAC_LEVEL_R 0x33 /* DAC Level Right Read/Write SB16 */ #define SBMIX_FM_LEVEL_L 0x34 /* FM Level Left Read/Write SB16 */ #define SBMIX_FM_LEVEL_R 0x35 /* FM Level Right Read/Write SB16 */ #define SBMIX_CD_LEVEL_L 0x36 /* CD Audio Level Left Read/Write SB16 */ #define SBMIX_CD_LEVEL_R 0x37 /* CD Audio Level Right Read/Write SB16 */ #define SBMIX_LINEIN_LEVEL_L 0x38 /* Line In Level Left Read/Write SB16 */ #define SBMIX_LINEIN_LEVEL_R 0x39 /* Line In Level Right Read/Write SB16 */ #define SBMIX_MIC_LEVEL_16 0x3A /* Microphone Level Read/Write SB16 */ #define SBMIX_PCSPK_LEVEL 0x3B /* PC Speaker Level Read/Write SB16 */ #define SBMIX_OUTPUT_CONTROL 0x3C /* Output Control Read/Write SB16 */ #define SBMIX_INPUT_CONTROL_L 0x3D /* Input Control Left Read/Write SB16 */ #define SBMIX_INPUT_CONTROL_R 0x3E /* Input Control Right Read/Write SB16 */ #define SBMIX_INPUT_GAIN_L 0x3F /* Input Gain Control Left Read/Write SB16 */ #define SBMIX_INPUT_GAIN_R 0x40 /* Input Gain Control Right Read/Write SB16 */ #define SBMIX_OUTPUT_GAIN_L 0x41 /* Output Gain Control Left Read/Write SB16 */ #define SBMIX_OUTPUT_GAIN_R 0x42 /* Output Gain Control Right Read/Write SB16 */ #define SBMIX_AGC_CONTROL 0x43 /* Automatic Gain Control (AGC) Read/Write SB16 */ #define SBMIX_TREBLE_L 0x44 /* Treble Left Read/Write SB16 */ #define SBMIX_TREBLE_R 0x45 /* Treble Right Read/Write SB16 */ #define SBMIX_BASS_L 0x46 /* Bass Left Read/Write SB16 */ #define SBMIX_BASS_R 0x47 /* Bass Right Read/Write SB16 */ #define SBMIX_IRQ_SELECT 0x80 /* IRQ Select Read/Write SB16 */ #define SBMIX_DMA_SELECT 0x81 /* DMA Select Read/Write SB16 */ #define SBMIX_IRQ_STATUS 0x82 /* IRQ Status Read SB16 */ /* SB_DSP_DATA_OUT_STATUS and SB_DSP_DATA_IN_STATUS bits */ #define SBM_DSP_READY 0x80 /* SB_DSP_RESET / SBMIX_RESET */ #define SBM_DSP_RESET 0x01 /* SBMIX_OUTPUT_SELECT */ #define SBM_MIX_STEREO 0x02 #define SBM_MIX_FILTER 0x20 /* SBDSP_DMA_GENERIC16/SBDSP_DMA_GENERIC8 */ #define SBM_GENDAC_FIFO 0x02 #define SBM_GENDAC_AUTOINIT 0x04 #define SBM_GENDAC_ADC 0x08 /* Second (mode) byte */ #define SBM_GENDAC_SIGNED 0x10 #define SBM_GENDAC_STEREO 0x20 /* DSP version masks */ #define SBVER_10 0x0100 /* Original SoundBlaster */ #define SBVER_15 0x0105 /* SoundBlaster 1.5 */ #define SBVER_20 0x0200 /* SoundBlaster 2.0 */ #define SBVER_PRO 0x0300 /* SoundBlaster Pro */ #define SBVER_PRO2 0x0301 /* SoundBlaster Pro 2 */ #define SBVER_16 0x0400 /* SoundBlaster 16 */ #define SBVER_AWE32 0x040c /* SoundBlaster AWE32 */ typedef unsigned char boolean; #ifndef FALSE #define FALSE 0 #define TRUE 1 #endif /* Play mode bits */ #define SBMODE_16BITS 0x0001 #define SBMODE_STEREO 0x0002 #define SBMODE_SIGNED 0x0004 /* Mask for capabilities that never change */ #define SBMODE_MASK (SBMODE_16BITS | SBMODE_STEREO) /* You can fill some members of this struct (i.e. port,irq,dma) before * calling sb_detect() or sb_open()... this will ignore environment settings. */ typedef struct __sb_state_s { boolean ok; /* Are structure contents valid? */ int port, aweport; /* sb/awe32 base port */ int irq; /* SoundBlaster IRQ */ int dma8, dma16; /* 8-bit and 16-bit DMAs */ unsigned maxfreq_mono; /* Maximum discretization frequency / mono mode */ unsigned maxfreq_stereo; /* Maximum discretization frequency / stereo mode */ unsigned short dspver; /* DSP version number */ struct irq_handle *irq_handle; /* The interrupt handler */ dma_buffer *dma_buff; /* Pre-allocated DMA buffer */ unsigned char caps; /* SoundBlaster capabilities (SBMODE_XXX) */ unsigned char mode; /* Current SB mode (SBMODE_XXX) */ boolean open; /* Whenever the card has been opened */ volatile int irqcount; /* Incremented on each IRQ... for diagnostics */ void (*timer_callback) (); /* Called TWICE per buffer play */ } __sb_state; extern __sb_state sb; extern void __sb_wait(); static inline boolean __sb_dsp_ready_in() { int count; for (count = 10000; count >= 0; count--) if (inportb(SB_DSP_DATA_IN_STATUS) & SBM_DSP_READY) return TRUE; return FALSE; } static inline boolean __sb_dsp_ready_out() { int count; for (count = 10000; count >= 0; count--) if ((inportb(SB_DSP_DATA_OUT_STATUS) & SBM_DSP_READY) == 0) return TRUE; return FALSE; } static inline void __sb_dsp_out(unsigned char reg) { __sb_dsp_ready_out(); outportb(SB_DSP_DATA_OUT, reg); } static inline unsigned char __sb_dsp_in() { __sb_dsp_ready_in(); return inportb(SB_DSP_DATA_IN); } static inline void __sb_dspreg_out(unsigned char reg, unsigned char val) { __sb_dsp_out(reg); __sb_dsp_out(val); } static inline void __sb_dspreg_outwlh(unsigned char reg, unsigned short val) { __sb_dsp_out(reg); __sb_dsp_out(val); __sb_dsp_out(val >> 8); } static inline void __sb_dspreg_outwhl(unsigned char reg, unsigned short val) { __sb_dsp_out(reg); __sb_dsp_out(val >> 8); __sb_dsp_out(val); } static inline unsigned char __sb_dspreg_in(unsigned char reg) { __sb_dsp_out(reg); return __sb_dsp_in(); } static inline void __sb_dsp_ack_dma8() { inportb(SB_DSP_DMA8_IRQ); } static inline void __sb_dsp_ack_dma16() { inportb(SB_DSP_DMA16_IRQ); } static inline unsigned short __sb_dsp_version() { unsigned short ver; __sb_dsp_out(SBDSP_VERSION); __sb_dsp_ready_in(); ver = ((unsigned short)__sb_dsp_in()) << 8; ver |= __sb_dsp_in(); return ver; } static inline void __sb_mixer_out(unsigned char reg, unsigned char val) { outportb(SB_MIXER_REGSEL, reg); outportb(SB_MIXER_DATA, val); } static inline unsigned char __sb_mixer_in(unsigned char reg) { outportb(SB_MIXER_REGSEL, reg); return inportb(SB_MIXER_DATA); } /* Enable stereo transfers: sbpro mode only */ static inline void __sb_stereo(boolean stereo) { unsigned char val = __sb_mixer_in(SBMIX_OUTPUT_SELECT); if (stereo) val |= SBM_MIX_STEREO; else val &= ~SBM_MIX_STEREO; __sb_mixer_out(SBMIX_OUTPUT_SELECT, val); } /* Detect whenever SoundBlaster is present and fill "sb" structure */ extern boolean sb_detect(); /* Reset SoundBlaster */ extern void sb_reset(); /* Start working with SoundBlaster */ extern boolean sb_open(); /* Finish working with SoundBlaster */ extern boolean sb_close(); /* Enable/disable speaker output */ extern void sb_output(boolean enable); /* Start playing from DMA buffer in either 8/16 bit mono/stereo */ extern boolean sb_start_dma(unsigned char mode, unsigned int freq); /* Stop playing from DMA buffer */ extern void sb_stop_dma(); /* Query current position/total size of the DMA buffer */ extern void sb_query_dma(unsigned int *dma_size, unsigned int *dma_pos); #endif /* __DOSSB_H__ */ wildmidi-wildmidi-0.3.8/docs/000077500000000000000000000000001245740225500160625ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/docs/ProgRef.odt000066400000000000000000000345201245740225500201420ustar00rootroot00000000000000PKâe‚D^Æ2 ''mimetypeapplication/vnd.oasis.opendocument.textPKâe‚DConfigurations2/statusbar/PKâe‚D'Configurations2/accelerator/current.xmlPKPKâe‚DConfigurations2/floater/PKâe‚DConfigurations2/popupmenu/PKâe‚DConfigurations2/progressbar/PKâe‚DConfigurations2/toolpanel/PKâe‚DConfigurations2/menubar/PKâe‚DConfigurations2/toolbar/PKâe‚DConfigurations2/images/Bitmaps/PKâe‚D layout-cachecd`d(Hf``àd``†1ôa s#Äàe`È2Ba¢]0ÆbcŒq Ƹ dPK++-3gPKâe‚D content.xmlå]ë’Û6–þ¿OÒ”=¥KK}±»'îYÇv2®ê¶³i;Ù­­­.ˆ„ZˆI‚C­ÖüʃÌþݪ}}”<Éž x“(‰ºôØ)WM’|88Wóí_Â@Ü«Äj½è ûG¡"Ïø:º{ÑùøáûÞóÎ_.ÿå[3™hO]øÆËB¥=ÏD)üWÀèÈ^pë‹N–DFZm/"*{‘z&VQ>ê¢Úû‚æâ'6­‡SçêèT=¤mcßÚX9n?3u®Žö9k;û¨ÕáÓvðƒ z¨‡±LõŽ>½èLÓ4¾ f³YvÜ7ÉÝ`x~~> Ö‚a¯ègI@½|o …“ÙÁ°?ä}C•ʶüaß*KQŽUҙʥ]µ÷w­%âþn4ÞT&­eƒ:×·÷Øo¿½Ç~ul(ÓéŠ=y>¸†Fú×õU) IØv.ì[ƒÊKtÜz™Ü»:ÞS°Šø€»£££“ÿ®ôž­í>Ktª’JwomwO^¸ ›@ƒ~Ãôè©{ÓBð»bÀhÀÍEgë¯$ýï×W7ÞT…²ì¬7wîéȦ2BdœJ«èÑaç2Wš ¸& <{驞¯¼À^~ËÂ_<ü7ñEçJÃIÉ6‘¸Q‰žtˆ{Þ7ÔÁüEçûçÅŽü´#jÄq@ïNEÐv%1¡Œj=bz ·÷2Ѩì:ƒöÌÉȶâ úµ`Íδµû°öZý*ÎÖ³UéÓ†¥¹MU¸‰§ÁªMvÏe–ê©özD§Ø}úwm?‹¹×±Lä]"ãiÞÐÓº‘ôeâwrÂÅ ^œÀùKR­¬˜2…=è;W¨à‘å¿f6Õ“yÏ‚½º3“ÀÑ™ÈÀV@§Ñu‚´b«ÿL ŸÇi (|ÜÕ$£U¨ÀõàšÈ .k@ýÁAÊŸÍ”¾›‚›ÀoÊ››ÇÖ‘m]t ñí¡?þÃB?:Ùz²+ô«Fï ýÉ? zv;ì[rú‡œáQÿtj[Ñ\AîЪ³?.T£íÕÛh/õ¶bô®gìÙ }KæŸïÂü_•ÄÀÿvtt;ܸ€q¢ä§ÞX—­üÝ6ìïÂÞ+N:Xäϱú¸\vaóì,²86þ|#¡LîtÔ ÔÇQÿä|tª£N¥%ássäž’ØèȇIÝC¦ne¯Ö¸­Ä wr7÷Yìùó“³ÏµØÜƪ¯]m¡"å(˜xéA>‰±:¥ñ¬\.0Ç0¡‘? @àUÂì¼èø&M•¿ÐƉ°~†Êôƒu̶Em'¯ŠÚzµ² jgç£ó/¸üµ*p£ƒwr~vúå·“«¸‡Rú<úèÃ’îEj¯ÃÑú°¤‹×.¾ò4´“@G*ÒÈD[ ~£¼t x á„Ó»ßË(_»êov>À3AF´Iü'à’¡L ;•gw2fªp»4ÓâB+sH®¾ø *xd2€üŸ¹DPN2äšzXõ·LEe²jù!Sòµ9ï™,%Üu¯XH‡›×·A.,çûp}{û'Öö£‚µ/‘×\¡-[ZÌCªúèGp®ôøø×Ú×â¨?ê÷ŽúÇâÇÄ€N C +~R• 9G=^CpT,¦©¬ìwsñjšh+ÞZµ 8\Kð´sùÿ+FGã UñMþ™ÇHAe&gE¬F=ÐqϦ‰š¼è„R©¹˜žñÕ¿‚H&¶oM–xè›ß©~¤à̯owë—ßÜÁÌ›uºaQëZÏ:—¦°Ò¼z"ào0!©0‘od žå'l3Dy½ˆ‡@|qñƒâ¬Æ2Zž LÈå& ¹ØËËV8n½ˆÙ¬BíÏTòÉÒÜ Õ~g îÚ/g3­VëkáP}~‘‘§­gºâ0’iÙç'ãӮøxó²ßB:O6Àž·’µî™IqyayÙ!`Z‰Iá§ò¡\²Ihî¡;+æèñäÁ Æe˜[4Ïè8>ôÀíDËœ;ÔÊ-©NpªàÄÉT-³Þ˜YâÓ¡ÙDrÕàŸd¾0ñâB:ëù֗½©ŒAr Mø ñy=˜Y²`%ß…%KDÈâû …ß°è= m€fôõBs¼šã¯š“ М|½Ðœn€æôë…æl4g_/4Ï6@óìë…æùhž½Ðœo€æüë…¦ð]Wú|GxpVtc¾6 §Ý]ëõñŪH‚¼÷»¦€æ|µ__.;øër>àb /Ä[X·ñ3J>1¸FR¶Bë¬5­à-‘ãq¾à… yÖšÐé…ø^GÚN•/f:–ðùu’Ï[“VÑNDΈ|—M&*»IcUA7°F¨µ§UÊ›i–úf¶=)8o K`'ú.KV›á°ÙV² o6ù­²‹Ó†ÖÜ·^Ê—-™]žxºz¦ªRÒ^“ï¬õ»¬êmÁRaÐÎAµŒ  $S‘fIdíSf…ŽR#dækCÚTddàÁó‰|a%fým‹Ììn<€}3ààéH"æú˜˜I+|DÏÄ œu$ðUŒRIOUs‚[‰Ëä'®yÀL0FÊH¨‡X%š 9Ò%®e‘œô§æ¡/ú~ v‡n4"QÀ…c±×X*©‚sͦ8*çuÔe³ ev‘±‰Nl*âlh«ÜRNSžÉ[1Îî ÷CÞÉ ;5IÀô`®/^3´kL$¦’&B"Õ-OT(Aî !Íßñ£ÚãAÑ©¸ãÖØÄY –ë#ª±L=´…ã¹ðõ„Š“)вøm‹Ê„í‹Ç“ÀþW—Å>Æ$ ž*‘ƒƒj#‹2àÀS¶+°’(<À0‚qÝ:ÆÐSú>݆9›( ‡¤Z\˜E‡1.#Ä®ßÀǸOÁ'€‰Er¡?ª?¿5çpŽÛ l6æ+<)N:Õ5ù?ÙIþ¯'Oûâ? <Ýp´|_8Ê0Ì"¥fžqžöiÁM˜ i‹þÉãÝ÷h"q]Êï.éßÀFG†Õ²>Îû ‰nAWdÈ‚]vÍa0ì%÷}<Ëÿv»ãyÀÁ$[Öš Èe3 –É •pþ°7t–¬´•w$î~/Õ¦¾J’GÂjÚ)O™¾vB ŠäÀ÷Q䮬Ðà»ÛÁ•i¯í ;@èÄÌép@¸bÉÉ9®x }ñl‡ÛØ@a [(\7;G¨Pr‘K@Ç$¹ðѹ?ñx1dìÎÓþŠIž<Ù§ãfœŽÛeô¶Ì€ª¿WD+÷ x×3SÕº >ªœÜ'à'ê 8 šn UÎ<Ûl‹6ŠbL“0Ðu„«GjaŽw¯®ølA@•$@©rÄ,]©ÙõtÂÓ¸7Úb öq7˜BÕãÀèr`È×w ~–òËŒF¿Åʼnê9$”]8Àjä¥ü rÖÀŽBÌ]f•*ãñ‘Ĉo.0 ÆÝ2¦Ê£[~¡ôÕÖî Í]ç åU<™åìɈ”ƈ’ÞÍgçõü2Eí@ç— [bù¤â&àXW! ¾¸(çY$Ü•748, î¼ï²„–÷ÚCK3X¼_¹&ÞTÙR箩ã9®#Ï#‘ƒ%3@¢2‚IÖŒ'DHT0!ˆH;Ôž ÒVŽç¤Ä‘uÒà²!ÏZ õ¤ï' ;ç<}Aº4‹ÜQÇò¬øk„í $1²D‚øvÊ>’>Ö9Qp¼rÔ­ÒâÁ-Nˆ‡“b'ø{¿¹vp!I8Ì'Ûƒöï¿ýÏ~œÝàß‚·º¯·­ðn6°î ä ï{ûx––B¤æÓZÄ8]ÒÔ ¾Ñ²ù® XàØÝ¥€K‰ã„Ú5–ox›È «¦‘ m‚Æž$J+ŠùZ2l`ˆ@'u™^`€™$·ñ˜o{4óýÒe:œÔ®p›¸Ò/‹éur,“©#s‹Ê–^&@r+1žævñÜ’#º¤Sw£ÖUÑ·´GËbV&JA#oÍ–£X±qK«½.Ø+ŒÔ6Ÿ.`Tð‚B–.ø£´X¦Í£ ·}àËÜk“Ù`îðç|ÿª,Èl±ÀÿÊÀÿrǪù¥ØØ_®o«o‹$d–Ó}¬HN£ªÖæOìÇÍ<ÖdâC™V…é.2wD©óˆŸ|É^ê¡"òÙ³,ÌA‡Ø?I1ÐÛ¬ÿç¡nÅB}ΜB"3™€Ë1ÅD¤×ŠpðvãÁ*ê¥3˜kÊç]q´µÛ¸¦V¾ÔøñWñÓ›Ÿßüô]ý×ãùâ7E‰b*ë4[å„W *µúeoÈ!³‹Â§Î²S9]&»žù%ß½²{¼Wï¸ýùýÕÇë7-M$ À/÷g˜j¡Äù=ݯEy¿ n¦Ä‹ð•§Ç*°Îep›*Ü̬¨çÚ©ô¨Cˆœ’‚š ¼,e¿ÈÚü¾Óœ½š±R”A÷3'¶9‹û;+ÁÊ“ÚÏïæ€ÑDfAÚ]LsãÇ"hP4‚.:°‚,u‘ƒ‡ŒÎk–Ò~b/EáMöñ]#áÞt§r† Žr÷¯[Ôñãù82M$ÅvÈVÑÉLj{d”:ò]žÞ=3*g³VÇ811EõÇ u@ v±v{Ç0wëœèñ½Ên…*¿Æ c`Ì'‹YÀâ;n4¬uq½)\‚R'¬–ÚGW àIs ¸Ê|0•ÞøÒ×ö·kŠË4e¶¨¼ˆ¸x—¦x›¨!(# åò²H¯Ïã.<»r]‘ëó{4eà† /6l”´à’^ÆÕÊ—TIt™Ð—¼})1Ãï@;X9ùP¥äë"”ÌïÈ}î@²z[%–«j¨_v¯a¯óï÷cc»†ÃœGv¼†®xÜúðO¦±óä²eÊtÚ±ÄïVüLŒ¬œ(LjÒ _F¾¿,4ŸÄJ?9µ!„šÚE€'…YdeY9N»[DÑd·™¨s÷6&ä0¿œ{›î TZ¹ÀX4³¯†ÎÍñˆúàõÿ>³Oi9D:ÜEï oÀoé_ìÎØl»ó3Äž–8(.u}I–ØÇÀ½Ø¯’=VU\êš;—¥o¬º‡°» ®ýdÂ?_ÿ®YùÖË@k«¶·í·Ýë¡+¿M±Û‹è» PÓw-¶”Üò:Aé E´³w¸û¢?³±Ïºr"≨­­ÛPåÿÛ™[°jŸaéMÙråî"×í/×·|;kùÛ â3,´ùË%ûlrAeA€»¢ë6íù^QÐî4seK ðÝý4_â29ñdá:„¦·Q'æ3¬wéË0ûl7Oj«ç—‡oùÕ°†eóKà ®P÷ Yù›} ©ªì?¡RÛ-×ç>—¾Å³åBÝÑ^xµ¬*ØEà3,nÕ7‚°FGêIà !Ök+SS‡qzW~ýh‰/¨,éþÕ§½±ÍÕÁ>ƒì4Çi/P0÷ZrQk|ã5ß‘ÚÚ;Tþ¿XÊ_ØZþÊ¿!S|nêÿPK;ˆ|,x•PKâe‚D styles.xmlÕZKã6¾ï¯0do²%»Ûm;Ó,²X쓹L²×€–h›‰HªmϯßâK¢dÉ–ÁLúЀY«¾zˆÒ»Ÿy6zÃ\F_ƒx#L–º} ~ÿí?á"øùý?ޱ͆$x•²¤Ì1•¡Ç ‹S±2Ä× ätÅ bEQŽÅJ&+V`ê„V>÷JoeV´²¡âšÙ—–ø ‡ +Þ†,ZßY3ûÒ)Gû¡ÂŠ|ê‹oØPáƒÈ –H’–‡ŒÐ/¯ÁNÊb5™ì÷ûñ~6f|;‰—ËåDS+ƒ“Н(y¦¹Òd‚3¬6“xOoŽ%jŸâõM¢e¾Æ|°kD'QoÛÁˆxÛö¸&Ù!>š¹ÞY:<¼³Ô—Í‘ÜõÄd1ùˆú߯k,ð|è^Š·áª„“bð1 ·/Ï«LU&Aµ¹Ó(zš˜ß÷þ,ûž‰¹ÇžœeOP–Tgy—Ó€/žGˆßLƒ‘-!^ÙŠƒ÷®FmÔ§ Jp˜â$ïßlUË#ó[ùè5øH¨FGŸ1'›`hr¼9ÉŽ¯Á?QÁÄOmF³ŒÊ•@¸ÅàМåˆ68 "€ÅâDÕ’`2Ü8DÅ Û€o€ibO„¸Ç´ã?ÑÿÊófyjT½3ÃgmKcEÝ‘¶ÎŠôáSP;´‘tC2±Š@pJà´Ý±Øaª+]˜¡4oi[tjf$'•ùW”4‘¥Q¨RN çï_†¤ƒR˜ÈMª6‰ÆOËés0MÔàÍ:[n€–·¾æõW¢Oíé`Ô,ÿ%Bõ®ÐÎîûû0î|´±ÇqŽ ÕÄè8=a*J±k±Ü‘$úáïcöácžMÖŒ«œPxƒú àÉP!šïÝ8älßÚVZÙùã"”l‹åN ÿ*û.mìoh0ýr)E< z‹„ ^†„ó ê¬:Õ÷_ŒR/Ÿ{ÕÁBõ\v›BUÊú ¿ÁÂÓè5K]f]*g9âPkÀe…n¶ó¹®5aͤTq4Ž3GÓ^Ö]˜ê.Œ²=:ŠK…¥§jè*šãxÙ~üþ!}²Fü]BÚSF«ÞTGÒ™MoÒÙß)žó ñœÓx.Ó—oÏçñKM¿÷~€pqŠõ´a¾ÿ芪ãù,Õµ¯¹Õ1qØ7?Dð·ˆZo¾Í× ”Ñêe‚VVB¸ySgü$XFÒ–=IÕ×úB¹›ÃZS¿3é}íp¨‘Ø|ïà›xúÒ CÎC)>ß|ÒÇv ý|Ìa:Ýñ©8G-¶FŒ`cýäíÆE»}cMövß<¦»G?gZ™‡ê³°<ÑØ'=½Kzv—ôÓ]ÒÏwIÏï’~¹Kzq—ôò.é8êŸô"2‰¤ Ýmiß:T„Ð6ƒ cRýîRÛ‹%óýÃÊJõ¢Õ.:AÖZ¿fõe¨K£Pés_CU§d!¦iŸ¤Û@§^y¤¶ k›Þ»4óåˆ?›ö»Çj©Ý z¦¥špýŸ¾÷ ÖV:£Ê+è$Iè®A!„ªám²"ƒžVŸÐ[ÀãéÜ|ã;ûxÇ­§™Öí.àCx.æ΂l´—éö¦ÿeñòÔwÓJs3Æ)ÅÍÉsö“Ë0G‡êˆj©¿©² »ú(GÑK\ïâ>.×Ü¡4Ól¹è`Bõ ¿“¥–Bl˜u©n÷žÖ×m~w"¯¹uÚkç>ÿ°Þâ©¢‘§´„‰JGµ›]TšÀl¿mðm®¡ë%BKû¤ûcç÷ÿPKâŽm7,-PKâe‚Dˆ¨·55meta.xml OpenOffice.org/2.4$Linux OpenOffice.org_project/680m18$Build-9364Chris 2010-06-10T14:09:572014-04-02T15:47:051PT0SPKâe‚DThumbnails/thumbnail.pngí–mTš‡ÇY»³¤Y󲜼øn—ê$Ñ*­z 3µ0[£qUˆ!Ñ":c‰EàÌSgùä黇OÎ+ݱhc5h8ÊO iÿ4+{Æ*Ò5Ÿ¶ÜNh~}Ãa³ÙÎx¹iI{K8-m)›ý&á·O‚”W¸EïbO‡IŽuäýTóCx4{vÄâ²ÉŠ9æu:³DEõ¹Í©ȵÁu&;œÔ×EÖÜtù*¢YëB]·×!‡*`2nåcw°jÎo¼Ú¼X(OÀêpš#ÕtE#š˜â7ÙÖÁ½:ËY3á?5ÐBsO^ï‹yPQlŽga¨âå.Åáq²Ýk{¸6qý!ÏHû) ÷’š<7"\Ž5 ²ÀzI”êÍ‘‹oƒÎ.Œ×í´cÈ2üÈÏNw¨˜Ùr…·/M3ÞhIz@nKÌ[ 3‡·)¦¹ÿ”x£<÷¼lããçü`è÷¶¬…ƒ+í3ÑQ&ô[_$é fÍ(Þí=Tƒ^ Öø©Ä`6Ä-hÿycþƒÞ ‰;U.ÂrZ.!‰± Êð™¼Ö‡z¦| ø„ü5¡“Ö4ûlTRº#…ÿÃ*óÜMÈóá1¤õºepßêxe”IðÌÀÒ~ëÛJ€ô¨:ÿÔGZÛ´RV·ŸSÀ G,‡N>Vد*×á’_TÖÛ³ñ¡]®z›ñ&’$è\ŒÇ[ÚÝe4Õê51 Ô„¹Œƒ­ç0óრŸ¨Ø4ÇX2…ÌÉ íwÆr5¦à+d.C$àm)ê?÷dø:/ØMë=¶iÁ1hòs¨«àæóøþ¥»x©)Ý4¨‹ƒËÐx J +ÁXæ˜j)Qe›M¨{ÜBTÏÐRº%…@ZÆû„¬WmNAª·aëÛ¯9Õ5èãÜeÿ%KAM:ÈëYÝÂð:”$ÆÕbý²GÞºÎoõšÂGRIn^z¨º~î—yÆžgÐø[ÜGÝtMO1"‹,C±ÝæO\å‰/8„µ[ã”G1zÓC1 3ÕÉk‚Æ.ª¯Ë™–¨ú¾ä§MQ_zŽ~JåˆëÄd ßqy˜¶%E[ðIê5~ú«GNµ ¾—Ëf£†#V.ÓA§·¢ÛÔù 5g$5ð¸ê%tð»™éÛ¤wäÁÿýqù?þ_bƒŠ÷Y9¥ŽÞ³û\ ²ÞÏÉ<{©ùPK¼1‹f˜ƒPKâe‚D settings.xmlµY[sÚ:~?¿"ãw $i˜„Ž!¥' fNß„½€Nd­G’üû®dÈ$\R‚щ-íMß~»+_~›'â䔿(¯‚ê§Jp2˜ËÉUð0l—.‚o.q<æÔcŒ²¤)i0†–èÚ.u=}dJÖ‘i®ë’% ë&ªc rµ­þzuÝ)ËŸÌ—OWÁÔ˜´^.Ïf³O³³O¨&åj­V+»·«¥Ê1Ÿì«*_ýZ"¾(²rcœ²ÓJ弜ÿœ,|šjÐXÅaå~ãr© ÿ)q‰ÍÉò±5í* •õg³—¨Ûö½Ýó‹Ö‡ ØÓ`õÆ,RzÃ¥ •Ëò¦„ý¥v`l¶‰-]œŸ~)&ú‘ÇfºMöYíâü¬˜ìO¦[ ¯ÖªÕĦ8ëCLƒÖ”É è5#DL £28LÇl*œi¸ÃvI3¡÷_JXZâ2†9Ä›±Ú0·‡RC-ö‹øM¼fª6ŠÐ4,–O?É]àûZý\;¥zzQ9ØVÍG¼äŠ“|ìÜvBû»Rä¬z^ý\HtÁdGú}­&û7b2$IëX›¢:<Vh›EÕv±ÕÊ‚oôDâ¶¢äò–‡¯s×ëe®o_@ueÿJ”?È3T×>R’Â8î1ņŒ 0HYd¹àèLÙ#Š1}°eÖùç0ª|+¿›ËôÒ þã b}Ÿ%#Pï8S@[‡—‡4ffó¯°X Pß“Ô,zÌOÍšHTÐæJrn€ÒÜHŸá¢ú«(kAµ0IhÛy\à䀀Ÿ8Ú¸nä'ÞVDl¤‚þö”'=–‚²z`²õZr O(åÏuÇc" ±r~Øë ÅËή§Ðmžna±®…iørÞä’©EPÞÓdÇ‚ìµ)`ÂÌ`"OÀi!UìwâAmäãœZ‡2n &Ÿt•å¢Q&\óÉPJ4NÃnæ>€:Èâ>°¥Ø€âqrÖ–ée…¢Cj „Ó&]ßçtÜ’‰yä¥#ÓT,4¨kf˜‡xµmà3ãì~å×]Ù¨3n*ù!pÄÄõòÄö>ûFßÒ‡š3ÙËdd2_y >‘„ÞÁ´‡š¿§¦á ž†ú¥óeDÉ ñ£¢¥ª-®þùˆc+SŠŽÉ¢Ú2£ý`¦¢ ²É§î=óïÑ´Xj2׊ͺ£ÿuWÚÂêÁ|G+}œÝøè<–uä~sÈÚ?NF›Í ¡R©y jsó¨XÚ•V‚£¾QCWÄKÏï€LŒ¼µ\îšÀ×ä ;l/Dä'RÔ $຿̢ÅKéë‰74CÚñƒöâÒ h©ŸIôÚyëZhŒ²]MumôrTù ¢P§Ôû’ÿƒâ5}'[ tBàÌé a±ÅdÂC z[ húM˜Œ·L¾EîÝÁÿÌ´áã…MýÈÍôŽÉŒ‰¦öä3M‰2éôWEܰ—¼iï)ìw Û±fë˜[]bO‰K 4ŠÌÚT„±}^‰,çü 4Yô4Q˜É·bÇÆ_±ºkw±ègĤy0z²”å¥Ë9á6‚ߠ替Œ6¼ìu—µå‰å]ŸXPK%ðŠsͤPKâe‚DMETA-INF/manifest.xmlµ•Mnà F÷9…ÅÞ¦íª²âDj¥ž =À$< ¢øöÅ‘òÓ6ªšÖì@‚÷†ÁþX®ƒ)ö胶ԈÇêAHʶšúF¼oÞÊg±^-–î0p}i…ó´ÑSm!èP jVµuH­Uq@âúóúz2­ÅÜiƒeZèÇâ"ÃVCÉ£ÃF€sF+àT§ÜS[]Õµ¢b<°¸ìî¢1¥Þ5B y—ì6åÕR§ûèE„'8†-ø Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, 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 them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If 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 convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "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 PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM 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 PROGRAM (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 PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state 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 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 3 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, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . wildmidi-wildmidi-0.3.8/docs/license/LGPLv3.txt000066400000000000000000000167271245740225500212710ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. This version of the GNU Lesser General Public License incorporates the terms and conditions of version 3 of the GNU General Public License, supplemented by the additional permissions listed below. 0. Additional Definitions. As used herein, "this License" refers to version 3 of the GNU Lesser General Public License, and the "GNU GPL" refers to version 3 of the GNU General Public License. "The Library" refers to a covered work governed by this License, other than an Application or a Combined Work as defined below. An "Application" is any work that makes use of an interface provided by the Library, but which is not otherwise based on the Library. Defining a subclass of a class defined by the Library is deemed a mode of using an interface provided by the Library. A "Combined Work" is a work produced by combining or linking an Application with the Library. The particular version of the Library with which the Combined Work was made is also called the "Linked Version". The "Minimal Corresponding Source" for a Combined Work means the Corresponding Source for the Combined Work, excluding any source code for portions of the Combined Work that, considered in isolation, are based on the Application, and not on the Linked Version. The "Corresponding Application Code" for a Combined Work means the object code and/or source code for the Application, including any data and utility programs needed for reproducing the Combined Work from the Application, but excluding the System Libraries of the Combined Work. 1. Exception to Section 3 of the GNU GPL. You may convey a covered work under sections 3 and 4 of this License without being bound by section 3 of the GNU GPL. 2. Conveying Modified Versions. If you modify a copy of the Library, and, in your modifications, a facility refers to a function or data to be supplied by an Application that uses the facility (other than as an argument passed when the facility is invoked), then you may convey a copy of the modified version: a) under this License, provided that you make a good faith effort to ensure that, in the event an Application does not supply the function or data, the facility still operates, and performs whatever part of its purpose remains meaningful, or b) under the GNU GPL, with none of the additional permissions of this License applicable to that copy. 3. Object Code Incorporating Material from Library Header Files. The object code form of an Application may incorporate material from a header file that is part of the Library. You may convey such object code under terms of your choice, provided that, if the incorporated material is not limited to numerical parameters, data structure layouts and accessors, or small macros, inline functions and templates (ten or fewer lines in length), you do both of the following: a) Give prominent notice with each copy of the object code that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the object code with a copy of the GNU GPL and this license document. 4. Combined Works. You may convey a Combined Work under terms of your choice that, taken together, effectively do not restrict modification of the portions of the Library contained in the Combined Work and reverse engineering for debugging such modifications, if you also do each of the following: a) Give prominent notice with each copy of the Combined Work that the Library is used in it and that the Library and its use are covered by this License. b) Accompany the Combined Work with a copy of the GNU GPL and this license document. c) For a Combined Work that displays copyright notices during execution, include the copyright notice for the Library among these notices, as well as a reference directing the user to the copies of the GNU GPL and this license document. d) Do one of the following: 0) Convey the Minimal Corresponding Source under the terms of this License, and the Corresponding Application Code in a form suitable for, and under terms that permit, the user to recombine or relink the Application with a modified version of the Linked Version to produce a modified Combined Work, in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source. 1) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (a) uses at run time a copy of the Library already present on the user's computer system, and (b) will operate properly with a modified version of the Library that is interface-compatible with the Linked Version. e) Provide Installation Information, but only if you would otherwise be required to provide such information under section 6 of the GNU GPL, and only to the extent that such information is necessary to install and execute a modified version of the Combined Work produced by recombining or relinking the Application with a modified version of the Linked Version. (If you use option 4d0, the Installation Information must accompany the Minimal Corresponding Source and Corresponding Application Code. If you use option 4d1, you must provide the Installation Information in the manner specified by section 6 of the GNU GPL for conveying Corresponding Source.) 5. Combined Libraries. 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 that are not Applications and are not covered by this License, and convey such a combined library under terms of your choice, if you do both of the following: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities, conveyed under the terms of this License. b) Give prominent notice with the combined library that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 6. Revised Versions of the GNU Lesser General Public License. The Free Software Foundation may publish revised and/or new versions of the GNU 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 as you received it specifies that a certain numbered version of the GNU Lesser General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that published version or of any later version published by the Free Software Foundation. If the Library as you received it does not specify a version number of the GNU Lesser General Public License, you may choose any version of the GNU Lesser General Public License ever published by the Free Software Foundation. If the Library as you received it specifies that a proxy can decide whether future versions of the GNU Lesser General Public License shall apply, that proxy's public statement of acceptance of any version is permanent authorization for you to choose that version for the Library. wildmidi-wildmidi-0.3.8/docs/man/000077500000000000000000000000001245740225500166355ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/docs/man/man1/000077500000000000000000000000001245740225500174715ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/docs/man/man1/wildmidi.1000066400000000000000000000117331245740225500213620ustar00rootroot00000000000000.TH wildmidi 1 "27 February 2014" "" "WildMidi Player" .SH NAME wildmidi \- example player for libWildMidi .PP .SH LIBRARY .B libWildMidi .PP .SH FILES .B /etc/wildmidi/wildmidi.cfg .PP .SH SYNOPSIS .B wildmidi [\-behlvwn] [\-c \fIconfig\-file\fB] [\-d \fIaudiodev\fB] [\-m \fIvolume\-level\fB] [\-o \fIwav\-file\fB] \fImidifile ... .PP .SH DESCRIPTION This is a demonstration program to show the capabilities of libWildMidi. .PP \fImidifile\fP is processed by libWildMidi and the resulting audio is output by the player. .PP You can have more than one \fImidifile\fP on the command line and \fBwildmidi\fP will pass them to libWildMidi for processing, one after the other. You can also use wildcards, for example: \fBwildmidi *.mid\fP .PP .SH OPTIONS .IP "\fB\-b\fP | \fB\-\-reverb\fP" Turns on an 8 point reverb engine that adds depth to the final mix. .P .IP "\fB\-c\fP \fIconfig\-file\fP | \fB\-\-config\fP \fIconfig\-file\fP" Uses the configuration file stated by \fIconfig\-file\fP instead of /etc/wildmidi/wildmidi.cfg .PP .IP "\fB\-d\fP \fIaudiodev\fP | \fB\-\-device=\fIaudiodev\fP" Send the audio to \fIaudiodev\fP instead of the default. ALSA defaults to the system "default" while OSS defaults to "/dev/dsp". Other environments do not support this option. .PP .IP "\fB\-e\fP | \fB\-\-enhanced\fP" Switches to a gauss based resampling algorithm which can improve the shape of the sound. .PP .IP "\fB\-h\fP | \fB\-\-help\fP" Displays command line options .PP .IP "\fB\-l\fP | \fB\-\-log_vol\fP" Some MIDI files have been recorded on hardware that uses a volume curve, making them sound really badly mixed on other MIDI devices. Use this option to use volume curves. .PP .IP "\fB\-m\fP \fIvolume\-level\fP | \fB\-\-mastervol=\fIvolume\-level\fP" Set the overall volume level to \fIvolume\-level\fP. The minimum is 0 and the maximum is 127, with the default being 100. .PP .IP "\fB\-o\fP \fIwav\-file\fP | \fB\-\-wavout=\fIwav\-file\fP" Records the audio in wav format to \fIwav-file\fP. .PP .IP "\fB\-r\fP \fIsndrate\fP | \fB\-\-rate=\fIsndrate\fP" Set the audio output rate to \fIsndrate\fP. The default rate is 32072. .PP .IP "\fB\-w\fP | \fB\-\-wholetempo\fP" Round down tempo to whole number .PP .IP "\fB\-n\fP | \fB\-\-roundtempo\fP" Round tempo to nearest whole number .PP .IP "\fB\-v\fP | \fB\-\-version\fP" Display version and copyright information .PP .SH TEST OPTIONS These options are not designed for general use. Instead these options are designed to make it easier to listen to specific sound samples. .PP Note: These options are not displayed by \fB\-h\fP | \fB\-\-help\fP .PP .IP "\fB-k\fP \fIN\fP | \fB\-\-test_bank=\fIN\fP" Set the test bank to \fIN\fP. Range is 0 to 127. .PP .IP "\fB\-p\fP \fIN\fP | \fB\-\-test_patch=\fIN\fP" Set the test patch to \fIN\fP. Range is 0 to 127. .PP .IP "\fB\-t\fP | \fB\-\-test_midi\fP" Plays the built in test midi which plays all 127 notes. .PP .SH USER INTERFACE The player accepts limited user input that allows some interaction while playing midi files. .PP .IP \fB\+\fP Turns the master volume up. .PP .IP \fB\-\fP Turns the master volume down. .PP .IP \fBe\fP Turns enhanced resampling on and off. .PP .IP \fBl\fP Turns volume curves on and off. .PP .IP \fBr\fP Turns the final mix reverb on and off. .PP .IP \fBn\fP Play the next midi on the command line. .PP .IP \fBp\fP Pause the playback. Note: since the audio is buffered it will stop when the audio buffer is empty. .PP .IP \fB.\fP Seek forward 1 second. Note: Clears active midi events and will only play midi events from after the new position. .PP .IP \fB,\fP Seek backwards 1 second. Note: Clears active midi events and will only play midi events from after the new position. .PP .IP \fBq\fP Quit wildmidi. .PP .SH SEE ALSO .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons AttributionShare Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/000077500000000000000000000000001245740225500174735ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_Close.3000066400000000000000000000041171245740225500224110ustar00rootroot00000000000000.TH WildMidi_Close 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_Close \- Close an open midi handle .SH LIBRARY .B libWildMidi .SH SYNOPSIS .B #include .PP .B int WildMidi_Close (midi *\fIhandle\fB) .PP .SH DESCRIPTION Finish processing MIDI data or file. .PP .IP \fIhandle\fP The identifier obtained from opening a midi file with \fBWildMidi_Open\fR(3)\fP or \fBWildMidi_OpenBuffer\fR(3)\fP .PP .SH "RETURN VALUE" returns \-1 on error, otherwise returns 0 .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_FastSeek.3000066400000000000000000000051561245740225500230550ustar00rootroot00000000000000.TH WildMidi_FastSeek 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_FastSeek \- Move to a position in a midi file .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B int WildMidi_FastSeek (midi *\fIhandle\fB, unsigned long int *\fIsample_pos\fB); .PP .SH DESCRIPTION Resets all note specific midi states and active notes before scanning to \fIsample_pos\fP samples from the beginning taking note of any changes to midi channel states. The next call to \fIWildMidi_GetOutput\fP\fR(3)\fP will behave as if you started to play the midi from that position. .PP .IP \fIhandle\fP The identifier obtained from opening a midi file with \fBWildMidi_Open\fR(3)\fP or \fBWildMidi_OpenBuffer\fR(3)\fP .PP .IP \fIsample_pos\fP The number of samples from the beginning you want libWildMidi to seek to. .PP NOTE: significant delay can occur when using this function. You can expect even more delay if you select a position that's already been passed forcing the library to start from the beginning. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_GetInfo.3000066400000000000000000000100531245740225500226730ustar00rootroot00000000000000.TH WildMidi_GetInfo 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_GetInfo \- get information on a midi .SH LIBRARY .B libWildMidi .SH SYNOPSIS .B #include .PP .B struct _WM_Info *WildMidi_GetInfo (midi *\fIhandle\fP); .PP .SH DESCRIPTION Obtains information allowing you to determine song position, current options, and any copyright information. .PP .IP \fIhandle\fP The identifier obtained from opening a midi file with \fBWildMidi_Open\fR(3)\fP or \fBWildMidi_OpenBuffer\fR(3)\fP .PP .SH RETURN VALUE On error returns NULL with an error message displayed to stderr. .PP Otherwise returns a pointer to a struct containing the information. .PP .nf struct _WM_Info { char *\fIcopyright\fP; unsigned long int \fIcurrent_sample\fP; unsigned long int \fIapprox_total_samples\fP; unsigned long int \fItotal_midi_time\fP; unsigned short int \fImixer_options\fP; unsigned long int \fItotal_midi_time\fP; }; .fi .PP .IP \fIcopyright\fP A pointer to a \\0 terminated string containing any copyright MIDI events found while processing the MIDI file \fIhandle\fP refers to. If more than one copyright event was found then each one is separated by \\n .PP If \fIcopyright\fP is NULL then no copyright MIDI events were found. .PP .IP \fIcurrent_sample\fP This is the number of stereo samples libWildMidi has processed for the MIDI file referred to by \fIhandle\fP. You can use this value to determine the current playing time by dividing this value by the \fIrate\fP given when libWildMidi was initialized by \fBWildMidi_Init\fR(3)\fP. .PP .IP \fIapprox_total_samples\fP This is the total number of stereo samples libWildMidi expects to process. This can be used to obtain the total playing time by dividing this value by the \fIrate\fP given when libWildMidi was initialized by \fBWildMidi_Init\fP\fR(3).\fP Also when you divide \fIcurrent_sample\fP by this value and multiplying by 100, you have the percentage currently processed. .PP .IP \fItotal_midi_time\fP This is the total time of MIDI events in 1/1000's of a second. It differs from \fIapprox_total_samples\fP in that it only states the total time within the MIDI file and does not take into account the extra bit of time to finish playing sampling smoothly. .PP .IP \fImixer_options\fP .RS .IP WM_MO_LOG_VOLUME Using curved volume settings instead of linear ones. .PP .IP WM_MO_ENHANCED_RESAMPLING The enhanced resampler is active .PP .IP WM_MO_REVERB Reverb is being added to the final output. .RE .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_GetOutput.3000066400000000000000000000061471245740225500233110ustar00rootroot00000000000000.TH WildMidi_GetOutput 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_GetOutput \- retrieve raw audio data .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B int WildMidi_GetOutput (midi *\fIhandle\fP, char *\fIbuffer\fP, unsigned long int \fIsize\fP); .PP .SH DESCRIPTION Places \fIsize\fP bytes of audio data from a \fIhandle\fP, previously opened by \fBWildMidi_Open\fP\fR(3)\fP or \fBWildMidi_OpenBuffer\fP\fR(3)\fP, into a buffer pointer to by \fIbuffer\fP. .PP \fIbuffer\fP must be at least \fIsize\fP bytes, with \fIsize\fP being a multiple of 4 as the data is stored in 16bit interleaved stereo format. .PP .IP \fIhandle\fP The identifier obtained from opening a midi file with \fBWildMidi_Open\fR(3)\fP or \fBWildMidi_OpenBuffer\fR(3)\fP .PP .IP \fIbuffer\fP The location supplied by the calling program where libWildMidi is to store the audio data. The audio data will be stored as signed 16bit interleaved stereo in little endian byte order. .PP .IP \fIsize\fP The size of the buffer in bytes. Since libWildMidi processes the audio in 16bit interleaved stereo format, this value needs to be a multiple of 4. .PP .SH "RETURN VALUE" Returns \-1 on error along with an error message sent to stderr, 0 when there is no more audio data, otherwise the number of bytes of audio data written to \fIbuffer\fP. .PP NOTE: if the return value is less than the size you gave, this does not denote an error, it simply means the lib reached the end of the midi before it could fill the buffer. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_GetString.3000066400000000000000000000042711245740225500232530ustar00rootroot00000000000000.TH WildMidi_GetString 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_GetString \- Get string from library .SH LIBRARY .B libWildMidi .SH SYNOPSIS .B #include .PP .B const char *WildMidi_GetString (unsigned short int \fIinfo\fP); .PP .SH DESCRIPTION Returns a pointer to a string depending on what \fIinfo\fP is set to. .PP At this stage WM_GS_VERSION is the only setting for \fIinfo\fP which returns a pointer to a string containing libWildMidi version information. .PP .SH "RETURN VALUE" Returns a const char pointer to a string containing the string requested. .PP .SH SEE ALSO .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_Init.3000066400000000000000000000070701245740225500222500ustar00rootroot00000000000000.TH WildMidi_Init 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_Init \- Initialize the library .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B WildMidi_Init (const char *\fIconfig_file\fP, unsigned short int \fIrate\fP, unsigned short int \fIoptions\fP) .PP .SH DESCRIPTION Initializes libWildMidi in preparation for playback. This function only needs to be called once by the program using libWildMidi. .PP .IP \fIconfig-file\fP The file that contains the instrument configuration for the library. .PP .IP \fIrate\fP The sound rate you want the the audio data output at. Rates accepted by libWildMidi are 11025 \- 65000. .PP .IP \fIoptions\fP The initial options to set for the library. see below. .RS .PP .IP WM_MO_LOG_VOLUME By default the library uses linear volume levels typically used in computer MIDI players. These can differ somewhat to volume levels found on some midi hardware which may use a volume curve based on decibels. This option sets the volume levels to what you'd expect on such devices. .PP .IP WM_MO_ENHANCED_RESAMPLING By default libWildMidi uses linear interpolation for the resampling of the sound samples. Setting this option enables the library to use a resampling method that attempts to fill in the gaps giving richer sound. .PP .IP WM_MO_REVERB libWildMidi has an 8 reflection reverb engine. Use this option to give more depth to the output. .PP .IP WM_MO_WHOLETEMPO Ignores the fractional or decimal part of a tempo setting. If you are having timing issues try \fIWM_MO_ROUNDTEMPO\fP before trying this option. This option added due to some software not supporting fractional tempos allowable in the MIDI specification. .PP .IP WM_MO_ROUNDTEMPO Rounds the fractional or decimal part of a tempo setting. Try this option is you are having timing issues, if this fails then try \fIWM_MO_WHOLETEMPO\fP. This option added due to some software not supporting fractional tempos allowable in the MIDI specification. .RE .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_MasterVolume.3000066400000000000000000000041521245740225500237660ustar00rootroot00000000000000.TH WildMidi_MasterVolume 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_MasterVolume \- sets the overall audio level of the library. .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B int WildMidi_MasterVolume (unsigned char \fImaster_volume\fP) .PP .SH DESCRIPTION Sets the overall library volume level to \fImaster_volume\fP. The range of \fImaster_volume\fP is between 0 and 127 with 100 being the default. .PP .SH "RETURN VALUE" Returns \-1 on error, otherwise returns 0. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3), .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_Open.3000066400000000000000000000043071245740225500222460ustar00rootroot00000000000000.TH WildMidi_Open 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_Open \- Open a midi file for processing .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B midi *WildMidi_Open (const char *\fImidifile\fP) .PP .SH DESCRIPTION Open a MIDI file pointed to by \fImidifile\fP for processing. This file must be in standard midi format. .PP .SH "RETURN VALUE" Returns NULL on error and sends a message to stderr, otherwise returns a handle for the midi file opened. This handle is used by most functions in libWildMidi to identify which midi file we are referring to. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_OpenBuffer.3000066400000000000000000000045751245740225500234070ustar00rootroot00000000000000.TH WildMidi_OpenBuffer 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_OpenBuffer \- Open a midi file buffer for processing .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B midi *WildMidi_OpenBuffer (unsigned char *\fImidibuffer\fP, unsigned long int \fIsize\fP) .PP .SH DESCRIPTION Open a midi file, that you have buffered in memory, for processing. .PP .IP \fImidibuffer\fP The memory location of the buffered midi file. This buffer needs to be in standard midi file format. Once this function is called, any changes to the buffer will have no effect. .PP .IP \fIsize\fP This is the size of the midi file in bytes that is stored in memory. .PP .SH "RETURN VALUE" Returns NULL on error, otherwise returns a handle for the midi buffer opened. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_SetOption.3000066400000000000000000000066061245740225500232750ustar00rootroot00000000000000.TH WildMidi_SetOption 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_SetOption \- Set a library option for a specific midi .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B int WildMidi_SetOption (midi *\fIhandle\fP, unsigned short int \fIoptions\fP, unsigned short int \fIsetting\fP) .PP .SH DESCRIPTION Set a library option for a specific midi. .PP .IP \fIhandle\fP The identifier obtained from opening a midi file with \fBWildMidi_Open\fR(3)\fP or \fBWildMidi_OpenBuffer\fR(3)\fP .PP .B \fIoptions\fP The option or options you wish to change. .PP .RS .IP WM_MO_LOG_VOLUME By default the library uses linear volume levels typically used in computer MIDI players. These can differ somewhat to volume levels found on some midi hardware which may use a volume curve based on decibels. This option sets the volume levels to what you'd expect on such devices. .PP .IP WM_MO_ENHANCED_RESAMPLING By default libWildMidi uses linear interpolation for the resampling of the sound samples. Setting this option enables the library to use a resampling method that attempts to fill in the gaps giving richer sound. .PP .IP WM_MO_REVERB libWildMidi has an 8 reflection reverb engine. Use this option to give more depth to the output. .PP .RE .IP setting To turn on an option, repeat that option here. To turn off an option, do not put the option here. .PP .IP "Example: To turn on Reverb" WildMidi_SetOption(handle, WM_MO_REVERB, WM_MO_REVERB); .IP "Example: To turn off Reverb" WildMidi_SetOption(handle, WM_MO_REVERB, 0); .IP "Example: To turn on Reverb and Enhanced Resampling" WildMidi_SetOption(handle, (WM_MO_REVERB | WM_MO_ENHANCED_RESAMPLING), (WM_MO_REVERB | WM_MO_ENHANCED_RESAMPLING)); .PP .SH "RETURN VALUE" Returns \-1 on error, otherwise returns 0. .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR WildMidi_Shutdown (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man3/WildMidi_Shutdown.3000066400000000000000000000040761245740225500231630ustar00rootroot00000000000000.TH WildMidi_Shutdown 3 "27 February 2014" "" "WildMidi Programmer's Manual" .SH NAME WildMidi_Shutdown \- Shutdown the library .PP .SH LIBRARY .B libWildMidi .PP .SH SYNOPSIS .B #include .PP .B void WildMidi_Shutdown(\fIvoid\fP) .PP .SH DESCRIPTION Shuts down the wildmidi library, resetting data and freeing up memory used by the library. .PP Once this is called, the library is no longer initialized and \fBWildMidi_Init\fP\fR(3)\fP will need to be called again. .PP .SH SEE ALSO .BR WildMidi_GetString (3) , .BR WildMidi_Init (3) , .BR WildMidi_MasterVolume (3) , .BR WildMidi_Open (3) , .BR WildMidi_OpenBuffer (3) , .BR WildMidi_SetOption (3) , .BR WildMidi_GetOutput (3) , .BR WildMidi_GetInfo (3) , .BR WildMidi_FastSeek (3) , .BR WildMidi_Close (3) , .BR wildmidi.cfg (5) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/docs/man/man5/000077500000000000000000000000001245740225500174755ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/docs/man/man5/wildmidi.cfg.5000066400000000000000000000133771245740225500221360ustar00rootroot00000000000000.TH wildmidi.cfg 5 "25 February 2014" "" "WildMidi Config File" .SH NAME wildmidi.cfg \- Config file for libWildMidi .PP .SH LIBRARY .B libWildMidi .PP .SH DESCRIPTION Contains the patch configuration for libWildMidi and location of Gravis Ultrasound compatible patch files. .PP .nf dir ~/guspats/ source /etc/wildmidi.cfg bank 0 0 acpiano.pat amp=110 env_time4=300 1 brpiano.pat amp=100 drumset 0 25 snarerol keep=env amp=225 note=60 26 snap note=65 .fi .PP .SH SYNTAX .IP "\fBguspat_editor_author_cant_read_so_fix_release_time_for_me\fP" Some patch file editors switch the 4th and 5th envelopes around making the sound play much longer than intended in players that stuck to the Gravis Ultrasound patch standard. Including this option in the config enables a fix that detects this oversight, playing the sound samples as if they were correct. .IP NOTE: This is a global setting. If it is found to affect good patch samples it will be moved to a per patch setting in a future version. .PP .IP "\fBauto_amp\fP" Forces WildMIDI to amplify samples to their maximum level ignoring the amp=% in the patch lines of the config. .PP .IP "\fBauto_amp_with_amp\fP" Forces WildMIDI to amplify samples to their maximum level then apply the amp=% in the patch lines of the config. .PP .IP "\fBdir\fP \fIdir\-name\fP" Change the search path for config and patch files to \fIdir\-name\fP. This is specific to the current config file and carried to any included config file unless they have their own \fBdir\fP setting. Any included file that has its own \fBdir\fP setting does not effect the \fBdir\fP setting of the current config file. .PP .IP "\fBsource\fP \fIinclude\-confg\fP" Include the settings from \fIinclude\-config\fP. Any patch already set will be over\-ridden by the included config file. .PP .IP "\fBbank\fP \fIN\fP" The patches following this setting belong to MIDI instrument bank \fIN\fP. .PP .IP "\fBdrumset\fP \fIN\fP" The patches following this setting belong to MIDI drum bank \fIN\fP. .PP .IP "\fIpatchno\fP \fIpatchfile\fP [\fBamp=\fP\fIvolume\fP] [\fBnote=\fP\fImiodinte\fP] [\fBkeep=loop\fP] [\fBkeep=env\fP] [\fBremove=sustain\fP] [\fBremove=clamped\fP] [\fBenv_level\fP[\fI0\-5\fP]\fB=\fP\fIlevel\fP] [\fBenv_time\fP[\fI0\-5\fP]\fB=\fP\fItime\fP]" .PP Example: 0 acpiano.pat amp=110 .PP .RS .IP "\fIpatchno\fP" This is the MIDI patch number the instrument belongs to. .PP .IP "\fIpatchfile\fP" The filename of the Gravis Ultrasound compatible patch file. If the filename is missing the .pat extension, libWildMidi will add .pat when attempting to load the file. .PP .IP "\fBamp=\fP\fIvolume\fP" Force the volume of the samples in this patch to \fIvolume\fP% prior to using it. .PP .IP "\fBnote=\fP\fImidinote\fP" Use note \fImidinote\fP when playing the samples in this patch. NOTE: this is for instruments listed under drumset. .PP .IP "\fBkeep=loop\fP" Play the samples in this patch with the loop, when normally we would not for this instrument. .PP .IP "\fBkeep=env\fP" Use the envelope data in this patch, when normally we wouldn't for this instrument. .PP .IP "\fBremove=sustain\fP" Do note hold the note after the 3rd envelope until note off, which is what happens if the sustain bit is set in the patch file. .PP .IP "\fBremove=clamped\fP" Do not jump to 6th envelope on note off, which is what happens if the clamped bit is set in the patch file. .PP .IP "\fBenv_level\fP[\fI0\-5\fP]\fB=\fP\fIlevel\fP" Set the envelope level to \fIlevel\fP with 1.0 being maximum, and 0.0 being minimum. .IP Example: set 5th envelope level to 10% \- \fBenv_level[0\-5]=\fP0.1 .PP .IP "\fBenv_time\fP[\fI0\-5\fP]\fB=\fP\fItime\fP" Set the envelope time to \fItime\fP with a resolution of 1/1000th of a second. This setting is the time it should take for the envelope to reach maximum level. .IP Example: set 1st envelope time to 1sec \- \fBenv_time0=\fP1000 .IP Example: set 3rd envelope time to 0.5secs \- \fBenv_time2=\fP500 .RE .PP .IP "\fBreverb_room_width\fP \fIfval\fP" Set the room width for the reverb engine in meters. \fIfval\fP is a float value in meters. Minimum setting is 1.0 meter, maximum setting is 100.0 meters, and default is 15.0 meters. .IP Example: set room width to 30 meters \- \fBreverb_room_width 30\fP .PP .IP "\fBreverb_room_length\fP \fIfval\fP" Set the room length for the reverb engine in meters. \fIfval\fP is a float value in meters. Minimum setting is 1.0 meter, maximum setting is 100.0 meters, and default is 20.0 meters. .IP Example: set room length to 40 meters \- \fBreverb_room_length 40\fP .PP .SH SEE ALSO .BR wildmidi (1) .PP .SH AUTHOR Chris Ison Bret Curtis .PP .SH COPYRIGHT Copyright (C) Chris Ison 2001\-2010 Copyright (C) Bret Curtis 2013\-2014 .PP This file is part of WildMIDI. .PP WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. .PP WildMIDI 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 and the GNU Lesser General Public License for more details. .PP You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . .PP This manpage is licensed under the Creative Commons Attribution\-Share Alike 3.0 Unported License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. .PP wildmidi-wildmidi-0.3.8/include/000077500000000000000000000000001245740225500165555ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/include/common.h000066400000000000000000000045441245740225500202250ustar00rootroot00000000000000/* common.h Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __COMMON_H #define __COMMON_H #define SAMPLE_16BIT 0x01 #define SAMPLE_UNSIGNED 0x02 #define SAMPLE_LOOP 0x04 #define SAMPLE_PINGPONG 0x08 #define SAMPLE_REVERSE 0x10 #define SAMPLE_SUSTAIN 0x20 #define SAMPLE_ENVELOPE 0x40 #define SAMPLE_CLAMPED 0x80 #ifdef DEBUG_SAMPLES #define SAMPLE_CONVERT_DEBUG(dx) printf("\r%s\n",dx) #else #define SAMPLE_CONVERT_DEBUG(dx) #endif extern unsigned short int _WM_SampleRate; struct _sample { unsigned long int data_length; unsigned long int loop_start; unsigned long int loop_end; unsigned long int loop_size; unsigned char loop_fraction; unsigned short int rate; unsigned long int freq_low; unsigned long int freq_high; unsigned long int freq_root; unsigned char modes; signed long int env_rate[7]; signed long int env_target[7]; unsigned long int inc_div; signed short *data; struct _sample *next; }; struct _env { float time; float level; unsigned char set; }; struct _patch { unsigned short patchid; unsigned char loaded; char *filename; signed short int amp; unsigned char keep; unsigned char remove; struct _env env[6]; unsigned char note; unsigned long int inuse_count; struct _sample *first_sample; struct _patch *next; }; /* Set our global defines here */ #ifndef M_PI #define M_PI 3.14159265358979323846 #endif #ifndef M_LN2 #define M_LN2 0.69314718055994530942 #endif #endif /* __COMMON_H */ wildmidi-wildmidi-0.3.8/include/config.h.cmake000066400000000000000000000036551245740225500212630ustar00rootroot00000000000000/* include/config.h. Generated from config.h.cmake by configure. */ /* Name of package */ #define PACKAGE "wildmidi" /* Define to the home page for this package. */ #define PACKAGE_URL "http://www.mindwerks.net/projects/wildmidi/" /* Define to the address where bug reports for this package should be sent. */ #define PACKAGE_BUGREPORT "https://github.com/Mindwerks/wildmidi/issues" /* Define to the full name of this package. */ #define PACKAGE_NAME "WildMidi" /* Define to the full name and version of this package. */ #define PACKAGE_STRING "WildMidi @WILDMIDI_VERSION@" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "wildmidi" /* Define to the version of this package. */ #define PACKAGE_VERSION "@WILDMIDI_VERSION@" /* Version number of package */ #define VERSION "@WILDMIDI_VERSION@" /* Define this to the location of the wildmidi config file */ #define WILDMIDI_CFG "@WILDMIDI_CFG@" /* Define if the C compiler supports the `inline' keyword. */ #cmakedefine HAVE_C_INLINE /* Define if the C compiler supports the `__inline__' keyword. */ #cmakedefine HAVE_C___INLINE__ /* Define if the C compiler supports the `__inline' keyword. */ #cmakedefine HAVE_C___INLINE #if !defined(HAVE_C_INLINE) && !defined(__cplusplus) # ifdef HAVE_C___INLINE__ # define inline __inline__ # elif defined(HAVE_C___INLINE) # define inline __inline # else # define inline # endif #endif /* Define if the compiler has the `__builtin_expect' built-in function */ #cmakedefine HAVE___BUILTIN_EXPECT #ifndef HAVE___BUILTIN_EXPECT #define __builtin_expect(x,c) x #endif /* define this if you are running a bigendian system (motorola, sparc, etc) */ #cmakedefine WORDS_BIGENDIAN 1 /* Define our audio drivers */ #cmakedefine HAVE_LINUX_SOUNDCARD_H #cmakedefine HAVE_SYS_SOUNDCARD_H #cmakedefine HAVE_MACHINE_SOUNDCARD_H #cmakedefine HAVE_SOUNDCARD_H #cmakedefine AUDIODRV_ALSA #cmakedefine AUDIODRV_OSS #cmakedefine AUDIODRV_OPENAL wildmidi-wildmidi-0.3.8/include/file_io.h000066400000000000000000000022371245740225500203400ustar00rootroot00000000000000/* file_io.c file handling Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __FILE_IO_H #define __FILE_IO_H #define WM_MAXFILESIZE 0x1fffffff extern unsigned char *_WM_BufferFile (const char *filename, unsigned long int *size); #endif /* __FILE_IO_H */ wildmidi-wildmidi-0.3.8/include/filenames.h000066400000000000000000000151211245740225500206710ustar00rootroot00000000000000/* Macros for taking apart, interpreting and processing file names. * * These are here because some non-Posix (a.k.a. DOSish) systems have * drive letter brain-damage at the beginning of an absolute file name, * use forward- and back-slash in path names interchangeably, and * some of them have case-insensitive file names. * * Copyright 2000, 2001, 2007 Free Software Foundation, Inc. * * This is based on filenames.h from BFD, the Binary File Descriptor * library, changed further for our needs. * * 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., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef FILENAMES_H #define FILENAMES_H #include /* ---------------------- Windows, DOS, OS2: ---------------------- */ #if defined(__MSDOS__) || defined(MSDOS) || defined(__DOS__) || \ defined(__DJGPP__) || defined(__OS2__) || defined(__EMX__) || \ defined(_WIN32) || defined(__CYGWIN__) #define HAVE_DOS_BASED_FILE_SYSTEM 1 #define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 #define HAS_DRIVE_SPEC(f) ((f)[0] && ((f)[1] == ':')) #define STRIP_DRIVE_SPEC(f) ((f) + 2) #define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == '\\') /* both '/' and '\\' work as dir separator. djgpp likes changing * '\\' into '/', so I define DIR_SEPARATOR_CHAR as '/' for djgpp, * '\\' otherwise. */ #ifdef __DJGPP__ #define DIR_SEPARATOR_CHAR '/' #define DIR_SEPARATOR_STR "/" #else #define DIR_SEPARATOR_CHAR '\\' #define DIR_SEPARATOR_STR "\\" #endif /* Note that IS_ABSOLUTE_PATH accepts d:foo as well, although it is only semi-absolute. This is because the users of IS_ABSOLUTE_PATH want to know whether to prepend the current working directory to a file name, which should not be done with a name like d:foo. */ #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || HAS_DRIVE_SPEC((f))) #ifdef __cplusplus static inline char *FIND_FIRST_DIRSEP(char *_the_path) { /* FIXME: What about C:FOO ? */ char *p1 = strchr(_the_path, '/'); char *p2 = strchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 < p2)? p1 : p2; } static inline char *FIND_LAST_DIRSEP (char *_the_path) { /* FIXME: What about C:FOO ? */ char *p1 = strrchr(_the_path, '/'); char *p2 = strrchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 > p2)? p1 : p2; } static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) { /* FIXME: What about C:FOO ? */ const char *p1 = strchr(_the_path, '/'); const char *p2 = strchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 < p2)? p1 : p2; } static inline const char *FIND_LAST_DIRSEP (const char *_the_path) { /* FIXME: What about C:FOO ? */ const char *p1 = strrchr(_the_path, '/'); const char *p2 = strrchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 > p2)? p1 : p2; } #else static inline char *FIND_FIRST_DIRSEP(const char *_the_path) { /* FIXME: What about C:FOO ? */ char *p1 = strchr(_the_path, '/'); char *p2 = strchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 < p2)? p1 : p2; } static inline char *FIND_LAST_DIRSEP (const char *_the_path) { /* FIXME: What about C:FOO ? */ char *p1 = strrchr(_the_path, '/'); char *p2 = strrchr(_the_path, '\\'); if (p1 == NULL) return p2; if (p2 == NULL) return p1; return (p1 > p2)? p1 : p2; } #endif /* C++ */ /* ----------------- AmigaOS, MorphOS, AROS, etc: ----------------- */ #elif defined(__MORPHOS__) || defined(__AROS__) || \ defined(__amigaos__) || defined(__amigaos4__) || \ defined(__amigados__) || defined(__AMIGA) || defined(__AMIGA__) #define HAS_DRIVE_SPEC(f) (0) /* */ #define STRIP_DRIVE_SPEC(f) (f) /* */ #define IS_DIR_SEPARATOR(c) ((c) == '/' || (c) == ':') #define DIR_SEPARATOR_CHAR '/' #define DIR_SEPARATOR_STR "/" #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0]) || (strchr((f), ':'))) #define HAVE_CASE_INSENSITIVE_FILE_SYSTEM 1 #ifdef __cplusplus static inline char *FIND_FIRST_DIRSEP(char *_the_path) { char *p = strchr(_the_path, ':'); if (p != NULL) return p; return strchr(_the_path, '/'); } static inline char *FIND_LAST_DIRSEP (char *_the_path) { char *p = strrchr(_the_path, '/'); if (p != NULL) return p; return strchr(_the_path, ':'); } static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) { const char *p = strchr(_the_path, ':'); if (p != NULL) return p; return strchr(_the_path, '/'); } static inline const char *FIND_LAST_DIRSEP (const char *_the_path) { const char *p = strrchr(_the_path, '/'); if (p != NULL) return p; return strchr(_the_path, ':'); } #else static inline char *FIND_FIRST_DIRSEP(const char *_the_path) { char *p = strchr(_the_path, ':'); if (p != NULL) return p; return strchr(_the_path, '/'); } static inline char *FIND_LAST_DIRSEP (const char *_the_path) { char *p = strrchr(_the_path, '/'); if (p != NULL) return p; return strchr(_the_path, ':'); } #endif /* C++ */ /* ---------------------- assumed UNIX-ish : ---------------------- */ #else /* */ #define IS_DIR_SEPARATOR(c) ((c) == '/') #define DIR_SEPARATOR_CHAR '/' #define DIR_SEPARATOR_STR "/" #define IS_ABSOLUTE_PATH(f) (IS_DIR_SEPARATOR((f)[0])) #define HAS_DRIVE_SPEC(f) (0) #define STRIP_DRIVE_SPEC(f) (f) #ifdef __cplusplus static inline char *FIND_FIRST_DIRSEP(char *_the_path) { return strchr(_the_path, '/'); } static inline char *FIND_LAST_DIRSEP (char *_the_path) { return strrchr(_the_path, '/'); } static inline const char *FIND_FIRST_DIRSEP(const char *_the_path) { return strchr(_the_path, '/'); } static inline const char *FIND_LAST_DIRSEP (const char *_the_path) { return strrchr(_the_path, '/'); } #else static inline char *FIND_FIRST_DIRSEP(const char *_the_path) { return strchr(_the_path, '/'); } static inline char *FIND_LAST_DIRSEP (const char *_the_path) { return strrchr(_the_path, '/'); } #endif /* C++ */ #endif #endif /* FILENAMES_H */ wildmidi-wildmidi-0.3.8/include/getopt_long.h000066400000000000000000000051721245740225500212540ustar00rootroot00000000000000/* $OpenBSD: getopt.h,v 1.3 2013/11/22 21:32:49 millert Exp $ */ /* $NetBSD: getopt.h,v 1.4 2000/07/07 10:43:54 ad Exp $ */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Dieter Baron and Thomas Klausner. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #ifndef _GETOPT_H_ #define _GETOPT_H_ /* * GNU-like getopt_long() */ #define no_argument 0 #define required_argument 1 #define optional_argument 2 struct option { /* name of long option */ const char *name; /* * one of no_argument, required_argument, and optional_argument: * whether option takes an argument */ int has_arg; /* if not NULL, set *flag to val when option found */ int *flag; /* if flag not NULL, value to set *flag to; else return value */ int val; }; #if defined(__cplusplus) extern "C" { #endif int getopt_long(int, char * const *, const char *, const struct option *, int *); int getopt_long_only(int, char * const *, const char *, const struct option *, int *); #ifndef _GETOPT_DEFINED_ #define _GETOPT_DEFINED_ int getopt(int, char * const *, const char *); extern char *optarg; /* getopt(3) external variables */ extern int opterr; extern int optind; extern int optopt; extern int optreset; #endif #if defined(__cplusplus) } #endif #endif /* !_GETOPT_H_ */ wildmidi-wildmidi-0.3.8/include/gus_pat.h000066400000000000000000000120431245740225500203700ustar00rootroot00000000000000/* gus_pat.h Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __GUS_PAT_H #define __GUS_PAT_H /* Guspat Envelope Rate Timings */ static float env_time_table[] = { /* Row 1 = (4095.0 / (x * ( 1.0 / (1.6 * 14.0) ))) / 1000000.0 */ 0.0f, 0.091728000f, 0.045864000f, 0.030576000f, 0.022932000f, 0.018345600f, 0.015288000f, 0.013104000f, 0.011466000f, 0.010192000f, 0.009172800f, 0.008338909f, 0.007644000f, 0.007056000f, 0.006552000f, 0.006115200f, 0.005733000f, 0.005395765f, 0.005096000f, 0.004827789f, 0.004586400f, 0.004368000f, 0.004169455f, 0.003988174f, 0.003822000f, 0.003669120f, 0.003528000f, 0.003397333f, 0.003276000f, 0.003163034f, 0.003057600f, 0.002958968f, 0.002866500f, 0.002779636f, 0.002697882f, 0.002620800f, 0.002548000f, 0.002479135f, 0.002413895f, 0.002352000f, 0.002293200f, 0.002237268f, 0.002184000f, 0.002133209f, 0.002084727f, 0.002038400f, 0.001994087f, 0.001951660f, 0.001911000f, 0.001872000f, 0.001834560f, 0.001798588f, 0.001764000f, 0.001730717f, 0.001698667f, 0.001667782f, 0.001638000f, 0.001609263f, 0.001581517f, 0.001554712f, 0.001528800f, 0.001503738f, 0.001479484f, 0.001456000f, /* Row 2 = (4095.0 / (x * ((1.0 / (1.6 * 14.0)) / 8.0 ))) / 1000000.0 */ 0.0f, 0.733824000f, 0.366912000f, 0.244608000f, 0.183456000f, 0.146764800f, 0.122304000f, 0.104832000f, 0.091728000f, 0.081536000f, 0.073382400f, 0.066711273f, 0.061152000f, 0.056448000f, 0.052416000f, 0.048921600f, 0.045864000f, 0.043166118f, 0.040768000f, 0.038622316f, 0.036691200f, 0.034944000f, 0.033355636f, 0.031905391f, 0.030576000f, 0.029352960f, 0.028224000f, 0.027178667f, 0.026208000f, 0.025304276f, 0.024460800f, 0.023671742f, 0.022932000f, 0.022237091f, 0.021583059f, 0.020966400f, 0.020384000f, 0.019833081f, 0.019311158f, 0.018816000f, 0.018345600f, 0.017898146f, 0.017472000f, 0.017065674f, 0.016677818f, 0.016307200f, 0.015952696f, 0.015613277f, 0.015288000f, 0.014976000f, 0.014676480f, 0.014388706f, 0.014112000f, 0.013845736f, 0.013589333f, 0.013342255f, 0.013104000f, 0.012874105f, 0.012652138f, 0.012437695f, 0.012230400f, 0.012029902f, 0.011835871f, 0.011648000f, /* Row 3 = (4095.0 / (x * ((1.0 / (1.6 * 14.0)) / 64.0 ))) / 1000000.0 */ 0.0f, 5.870592000f, 2.935296000f, 1.956864000f, 1.467648000f, 1.174118400f, 0.978432000f, 0.838656000f, 0.733824000f, 0.652288000f, 0.587059200f, 0.533690182f, 0.489216000f, 0.451584000f, 0.419328000f, 0.391372800f, 0.366912000f, 0.345328941f, 0.326144000f, 0.308978526f, 0.293529600f, 0.279552000f, 0.266845091f, 0.255243130f, 0.244608000f, 0.234823680f, 0.225792000f, 0.217429333f, 0.209664000f, 0.202434207f, 0.195686400f, 0.189373935f, 0.183456000f, 0.177896727f, 0.172664471f, 0.167731200f, 0.163072000f, 0.158664649f, 0.154489263f, 0.150528000f, 0.146764800f, 0.143185171f, 0.139776000f, 0.136525395f, 0.133422545f, 0.130457600f, 0.127621565f, 0.124906213f, 0.122304000f, 0.119808000f, 0.117411840f, 0.115109647f, 0.112896000f, 0.110765887f, 0.108714667f, 0.106738036f, 0.104832000f, 0.102992842f, 0.101217103f, 0.099501559f, 0.097843200f, 0.096239213f, 0.094686968f, 0.093184000f, /* Row 4 = (4095.0 / (x * ((1.0 / (1.6 * 14.0)) / 512.0))) / 1000000.0 */ 0.0f, 46.964736000f,23.482368000f,15.654912000f,11.741184000f, 9.392947200f, 7.827456000f, 6.709248000f, 5.870592000f, 5.218304000f, 4.696473600f, 4.269521455f, 3.913728000f, 3.612672000f, 3.354624000f, 3.130982400f, 2.935296000f, 2.762631529f, 2.609152000f, 2.471828211f, 2.348236800f, 2.236416000f, 2.134760727f, 2.041945043f, 1.956864000f, 1.878589440f, 1.806336000f, 1.739434667f, 1.677312000f, 1.619473655f, 1.565491200f, 1.514991484f, 1.467648000f, 1.423173818f, 1.381315765f, 1.341849600f, 1.304576000f, 1.269317189f, 1.235914105f, 1.204224000f, 1.174118400f, 1.145481366f, 1.118208000f, 1.092203163f, 1.067380364f, 1.043660800f, 1.020972522f, 0.999249702f, 0.978432000f, 0.958464000f, 0.939294720f, 0.920877176f, 0.903168000f, 0.886127094f, 0.869717333f, 0.853904291f, 0.838656000f, 0.823942737f, 0.809736828f, 0.796012475f, 0.782745600f, 0.769913705f, 0.757495742f, 0.745472000f }; extern struct _sample * _WM_load_gus_pat (const char *filename, int _fix_release); #endif /* __GUS_PAT_H */ wildmidi-wildmidi-0.3.8/include/lock.h000066400000000000000000000023301245740225500176540ustar00rootroot00000000000000/* lock.h - data locking code for lib Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __LOCK_H #define __LOCK_H extern void _WM_Lock (int * wmlock); extern void _WM_Unlock (int *wmlock); #ifdef __DJGPP__ #define _WM_Lock(p) do {} while (0) #define _WM_Unlock(p) do {} while (0) #endif #endif /* __LOCK_H */ wildmidi-wildmidi-0.3.8/include/reverb.h000066400000000000000000000034541245740225500202210ustar00rootroot00000000000000/* reverb.h Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __REVERB_H #define __REVERB_H struct _rvb { /* filter data */ signed long int l_buf_flt_in[8][6][2]; signed long int l_buf_flt_out[8][6][2]; signed long int r_buf_flt_in[8][6][2]; signed long int r_buf_flt_out[8][6][2]; signed long int coeff[8][6][5]; /* buffer data */ signed long int *l_buf; signed long int *r_buf; int l_buf_size; int r_buf_size; int l_out; int r_out; int l_sp_in[8]; int r_sp_in[8]; int l_in[4]; int r_in[4]; int gain; unsigned long int max_reverb_time; }; extern void _WM_reset_reverb (struct _rvb *rvb); extern struct _rvb *_WM_init_reverb(int rate, float room_x, float room_y, float listen_x, float listen_y); extern void _WM_free_reverb (struct _rvb *rvb); extern void _WM_do_reverb (struct _rvb *rvb, signed long int *buffer, int size); #endif /* __REVERB_H */ wildmidi-wildmidi-0.3.8/include/wildmidi_lib.h000066400000000000000000000070141245740225500213600ustar00rootroot00000000000000/* wildmidi_lib.h Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef WILDMIDI_LIB_H #define WILDMIDI_LIB_H #define WM_MO_LOG_VOLUME 0x0001 #define WM_MO_ENHANCED_RESAMPLING 0x0002 #define WM_MO_REVERB 0x0004 #define WM_MO_WHOLETEMPO 0x8000 #define WM_MO_ROUNDTEMPO 0x2000 #define WM_GS_VERSION 0x0001 /* set our symbol export visiblity */ #if defined _WIN32 || defined __CYGWIN__ /* ========== NOTE TO WINDOWS DEVELOPERS: * If you are compiling for Windows and will link to the static library * (libWildMidi.a with MinGW, or wildmidi_static.lib with MSVC, etc), * you must define WILDMIDI_STATIC in your project. Otherwise dllimport * will be assumed. */ # if defined(WILDMIDI_BUILD) && defined(DLL_EXPORT) /* building libWildMidi as a dll for windows */ # define WM_SYMBOL __declspec(dllexport) # elif defined(WILDMIDI_BUILD) || defined(WILDMIDI_STATIC) /* building or using static libWildMidi for windows */ # define WM_SYMBOL # else /* using libWildMidi dll for windows */ # define WM_SYMBOL __declspec(dllimport) # endif #elif defined(WILDMIDI_BUILD) # if defined(SYM_VISIBILITY) /* __GNUC__ >= 4, or older gcc with backported feature */ # define WM_SYMBOL __attribute__ ((visibility ("default"))) /* # elif defined(__SUNPRO_C) && (__SUNPRO_C >= 0x590) # define WM_SYMBOL __attribute__ ((visibility ("default"))) */ # elif defined(SYM_LDSCOPE) /* __SUNPRO_C >= 0x550 */ # define WM_SYMBOL __global # else # define WM_SYMBOL # endif #else # define WM_SYMBOL #endif #if defined(__cplusplus) extern "C" { #endif struct _WM_Info { char *copyright; unsigned long int current_sample; unsigned long int approx_total_samples; unsigned short int mixer_options; unsigned long int total_midi_time; }; typedef void midi; WM_SYMBOL const char * WildMidi_GetString (unsigned short int info); WM_SYMBOL int WildMidi_Init (const char * config_file, unsigned short int rate, unsigned short int options); WM_SYMBOL int WildMidi_MasterVolume (unsigned char master_volume); WM_SYMBOL midi * WildMidi_Open (const char *midifile); WM_SYMBOL midi * WildMidi_OpenBuffer (unsigned char *midibuffer, unsigned long int size); WM_SYMBOL int WildMidi_GetOutput (midi * handle, char * buffer, unsigned long int size); WM_SYMBOL int WildMidi_SetOption (midi * handle, unsigned short int options, unsigned short int setting); WM_SYMBOL struct _WM_Info * WildMidi_GetInfo (midi * handle); WM_SYMBOL int WildMidi_FastSeek (midi * handle, unsigned long int *sample_pos); WM_SYMBOL int WildMidi_Close (midi * handle); WM_SYMBOL int WildMidi_Shutdown (void); #if defined(__cplusplus) } #endif #endif /* WILDMIDI_LIB_H */ wildmidi-wildmidi-0.3.8/include/wm_error.h000066400000000000000000000027161245740225500205700ustar00rootroot00000000000000/* wm_error.h error reporting Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef __WM_ERROR_H #define __WM_ERROR_H enum { WM_ERR_NONE = 0, WM_ERR_MEM, WM_ERR_STAT, WM_ERR_LOAD, WM_ERR_OPEN, WM_ERR_READ, WM_ERR_INVALID, WM_ERR_CORUPT, WM_ERR_NOT_INIT, WM_ERR_INVALID_ARG, WM_ERR_ALR_INIT, WM_ERR_NOT_MIDI, WM_ERR_LONGFIL, WM_ERR_MAX }; extern void _WM_ERROR_NEW(const char * wmfmt, ...) #ifdef __GNUC__ __attribute__((format(printf, 1, 2))) #endif ; extern void _WM_ERROR(const char * func, unsigned int lne, int wmerno, const char * wmfor, int error); #endif /* __WM_ERROR_H */ wildmidi-wildmidi-0.3.8/include/wm_tty.h000066400000000000000000000023631245740225500202550ustar00rootroot00000000000000/* wm_tty.h - unix termios code for player Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #ifndef wm_tty_h #define wm_tty_h void wm_inittty(void); void wm_resetty(void); #if defined(_WIN32) || defined(__DJGPP__) #define wm_inittty() do {} while (0) #define wm_resetty() do {} while (0) #endif /* !_WIN32, !__DJGPP__ */ #endif /* wm_tty_h */ wildmidi-wildmidi-0.3.8/src/000077500000000000000000000000001245740225500157215ustar00rootroot00000000000000wildmidi-wildmidi-0.3.8/src/CMakeLists.txt000066400000000000000000000127621245740225500204710ustar00rootroot00000000000000# Setup our wildmidi library that we link to SET(wildmidi_library_SRCS wm_error.c file_io.c lock.c wildmidi_lib.c reverb.c gus_pat.c ) SET(wildmidi_library_HDRS ../include/wm_error.h ../include/file_io.h ../include/lock.h ../include/wildmidi_lib.h ../include/reverb.h ../include/gus_pat.h ../include/common.h ../include/filenames.h ) IF(MSVC) SET(GETOPT getopt_long.c) ELSE() SET(GETOPT) ENDIF() SET(wildmidi_executable_SRCS ${GETOPT} wm_tty.c wildmidi.c ) SET(wildmidi_executable_HDRS ../include/wm_tty.h ../include/getopt_long.h ) # set our target paths SET(EXECUTABLE_OUTPUT_PATH "${CMAKE_BINARY_DIR}") SET(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}") # set our library names IF(WIN32 AND NOT CMAKE_COMPILER_IS_MINGW) # windows uses *.lib for both static and dynamic, workaround SET(LIBRARY_DYN_NAME "wildmidi_dynamic") SET(LIBRARY_STATIC_NAME "wildmidi_static") ELSE() # everyone else uses .a and .so SET(LIBRARY_DYN_NAME "WildMidi") SET(LIBRARY_STATIC_NAME "WildMidi") ENDIF() # do we want a static library? IF(WANT_STATIC) ADD_LIBRARY(libwildmidi_static STATIC ${wildmidi_library_SRCS} ${wildmidi_library_HDRS} ) TARGET_LINK_LIBRARIES(libwildmidi_static ${M_LIBRARY} ) SET_TARGET_PROPERTIES(libwildmidi_static PROPERTIES OUTPUT_NAME ${LIBRARY_STATIC_NAME} CLEAN_DIRECT_OUTPUT 1 COMPILE_DEFINITIONS WILDMIDI_BUILD ) ENDIF(WANT_STATIC) # always build our dynamic library ADD_LIBRARY(libwildmidi_dynamic SHARED ${wildmidi_library_SRCS} ${wildmidi_library_HDRS} ) TARGET_LINK_LIBRARIES(libwildmidi_dynamic ${M_LIBRARY} ) SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES SOVERSION ${SOVERSION} VERSION ${VERSION} OUTPUT_NAME ${LIBRARY_DYN_NAME} CLEAN_DIRECT_OUTPUT 1 ) IF(WIN32) SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES DEFINE_SYMBOL DLL_EXPORT COMPILE_DEFINITIONS WILDMIDI_BUILD ) ELSEIF(HAVE_VISIBILITY_HIDDEN AND HAVE_VISIBILITY_DEFAULT) # GCC, Clang SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES COMPILE_DEFINITIONS "WILDMIDI_BUILD;SYM_VISIBILITY" COMPILE_FLAGS "-fvisibility=hidden" ) #ELSEIF(HAVE_LDSCOPE_HIDDEN AND HAVE_VISIBILITY_DEFAULT) # SunPro (__SUNPRO_C >= 0x590) # SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES # COMPILE_DEFINITIONS "WILDMIDI_BUILD;SYM_VISIBILITY" # COMPILE_FLAGS "-xldscope=hidden" # ) ELSEIF(HAVE_LDSCOPE_HIDDEN AND HAVE_LDSCOPE_GLOBAL) # SunPro (__SUNPRO_C >= 0x550) SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES COMPILE_DEFINITIONS "WILDMIDI_BUILD;SYM_LDSCOPE" COMPILE_FLAGS "-xldscope=hidden" ) ELSE() SET_TARGET_PROPERTIES(libwildmidi_dynamic PROPERTIES COMPILE_DEFINITIONS WILDMIDI_BUILD ) ENDIF() # Set our default and then look at the possible locations SET(WILDMIDILIB "${CMAKE_BINARY_DIR}/lib${LIBRARY_DYN_NAME}.so") SET(WILDMIDILIBSTATIC "${CMAKE_BINARY_DIR}/lib${LIBRARY_STATIC_NAME}.a") # MS Visual Studio IF(MSVC) SET(WILDMIDILIB "${CMAKE_BINARY_DIR}\\${CMAKE_BUILD_TYPE}\\${LIBRARY_DYN_NAME}.lib") SET(WILDMIDILIBSTATIC "${CMAKE_BINARY_DIR}\\${CMAKE_BUILD_TYPE}\\${LIBRARY_STATIC_NAME}.lib") ENDIF(MSVC) # MinGW or MinGW-w64 IF(CMAKE_COMPILER_IS_MINGW) SET(WILDMIDILIB "${CMAKE_BINARY_DIR}\\lib${LIBRARY_DYN_NAME}.dll.a") SET(WILDMIDILIBSTATIC "${CMAKE_BINARY_DIR}\\lib${LIBRARY_STATIC_NAME}.a") ENDIF(CMAKE_COMPILER_IS_MINGW) # Apple's Xcode IF(CMAKE_GENERATOR STREQUAL "Xcode") SET(WILDMIDILIB "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib${LIBRARY_DYN_NAME}.dylib") SET(WILDMIDILIBSTATIC "${CMAKE_BINARY_DIR}/${CMAKE_BUILD_TYPE}/lib${LIBRARY_STATIC_NAME}.a") ELSEIF(APPLE) # Apple's CLI default SET(WILDMIDILIB "${CMAKE_BINARY_DIR}/lib${LIBRARY_DYN_NAME}.dylib") SET(WILDMIDILIBSTATIC "${CMAKE_BINARY_DIR}/lib${LIBRARY_STATIC_NAME}.a") ENDIF(CMAKE_GENERATOR STREQUAL "Xcode") # do we want the wildmidi player? IF(WANT_PLAYER) ADD_EXECUTABLE(wildmidi ${wildmidi_executable_SRCS} ${wildmidi_executable_HDRS} ) ADD_DEPENDENCIES(wildmidi libwildmidi_dynamic) TARGET_LINK_LIBRARIES(wildmidi ${WILDMIDILIB} ${M_LIBRARY} ${AUDIO_LIBRARY} ) ENDIF(WANT_PLAYER) IF(WANT_PLAYERSTATIC) ADD_EXECUTABLE(wildmidi-static ${wildmidi_executable_SRCS} ${wildmidi_executable_HDRS} ) ADD_DEPENDENCIES(wildmidi-static libwildmidi_static) SET_TARGET_PROPERTIES(wildmidi-static PROPERTIES COMPILE_DEFINITIONS WILDMIDI_STATIC ) TARGET_LINK_LIBRARIES(wildmidi-static ${WILDMIDILIBSTATIC} ${M_LIBRARY} ${AUDIO_LIBRARY} ) ENDIF(WANT_PLAYERSTATIC) # add install target: IF(UNIX AND NOT APPLE) # install our libraries IF(WANT_STATIC) INSTALL(TARGETS libwildmidi_static DESTINATION "lib${LIB_SUFFIX}/${CMAKE_LIBRARY_ARCHITECTURE}") ENDIF(WANT_STATIC) INSTALL(TARGETS libwildmidi_dynamic DESTINATION "lib${LIB_SUFFIX}/${CMAKE_LIBRARY_ARCHITECTURE}") # install our player if asked for IF(WANT_PLAYER) INSTALL(TARGETS wildmidi DESTINATION bin) ENDIF(WANT_PLAYER) IF(WANT_PLAYERSTATIC) INSTALL(TARGETS wildmidi-static DESTINATION bin) ENDIF(WANT_PLAYERSTATIC) # install supporting man pages and headers INSTALL(FILES ${CMAKE_SOURCE_DIR}/include/wildmidi_lib.h DESTINATION include) INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/docs/man/ DESTINATION share/man) ENDIF(UNIX AND NOT APPLE) wildmidi-wildmidi-0.3.8/src/DevTest.c000066400000000000000000000635341245740225500174560ustar00rootroot00000000000000/* DevTest.c: Display Information about the Gravis Ultrasound patch file. Display Information about MIDI file. NOTE: This file is intended for developer use to aide in feature development, and bug hunting. COMPILING: gcc -Wall -W -O2 -o devtest DevTest.c Copyright (C) Chris Ison 2001-2014 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License and you can redistribute the player and DevTest under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include #include #include #include #include #include #include #include #include #include #ifndef _WIN32 # include #endif static struct option const long_options[] = { { "debug-level", 1, 0, 'd' }, { "version", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { NULL, 0, NULL, 0 } }; static float env_time_table[] = { 0.0f, 0.091728000f, 0.045864000f, 0.030576000f, 0.022932000f, 0.018345600f, 0.015288000f, 0.013104000f, 0.011466000f, 0.010192000f, 0.009172800f, 0.008338909f, 0.007644000f, 0.007056000f, 0.006552000f, 0.006115200f, 0.005733000f, 0.005395765f, 0.005096000f, 0.004827789f, 0.004586400f, 0.004368000f, 0.004169455f, 0.003988174f, 0.003822000f, 0.003669120f, 0.003528000f, 0.003397333f, 0.003276000f, 0.003163034f, 0.003057600f, 0.002958968f, 0.002866500f, 0.002779636f, 0.002697882f, 0.002620800f, 0.002548000f, 0.002479135f, 0.002413895f, 0.002352000f, 0.002293200f, 0.002237268f, 0.002184000f, 0.002133209f, 0.002084727f, 0.002038400f, 0.001994087f, 0.001951660f, 0.001911000f, 0.001872000f, 0.001834560f, 0.001798588f, 0.001764000f, 0.001730717f, 0.001698667f, 0.001667782f, 0.001638000f, 0.001609263f, 0.001581517f, 0.001554712f, 0.001528800f, 0.001503738f, 0.001479484f, 0.001456000f, 0.0f, 0.733824000f, 0.366912000f, 0.244608000f, 0.183456000f, 0.146764800f, 0.122304000f, 0.104832000f, 0.091728000f, 0.081536000f, 0.073382400f, 0.066711273f, 0.061152000f, 0.056448000f, 0.052416000f, 0.048921600f, 0.045864000f, 0.043166118f, 0.040768000f, 0.038622316f, 0.036691200f, 0.034944000f, 0.033355636f, 0.031905391f, 0.030576000f, 0.029352960f, 0.028224000f, 0.027178667f, 0.026208000f, 0.025304276f, 0.024460800f, 0.023671742f, 0.022932000f, 0.022237091f, 0.021583059f, 0.020966400f, 0.020384000f, 0.019833081f, 0.019311158f, 0.018816000f, 0.018345600f, 0.017898146f, 0.017472000f, 0.017065674f, 0.016677818f, 0.016307200f, 0.015952696f, 0.015613277f, 0.015288000f, 0.014976000f, 0.014676480f, 0.014388706f, 0.014112000f, 0.013845736f, 0.013589333f, 0.013342255f, 0.013104000f, 0.012874105f, 0.012652138f, 0.012437695f, 0.012230400f, 0.012029902f, 0.011835871f, 0.011648000f, 0.0f, 5.870592000f, 2.935296000f, 1.956864000f, 1.467648000f, 1.174118400f, 0.978432000f, 0.838656000f, 0.733824000f, 0.652288000f, 0.587059200f, 0.533690182f, 0.489216000f, 0.451584000f, 0.419328000f, 0.391372800f, 0.366912000f, 0.345328941f, 0.326144000f, 0.308978526f, 0.293529600f, 0.279552000f, 0.266845091f, 0.255243130f, 0.244608000f, 0.234823680f, 0.225792000f, 0.217429333f, 0.209664000f, 0.202434207f, 0.195686400f, 0.189373935f, 0.183456000f, 0.177896727f, 0.172664471f, 0.167731200f, 0.163072000f, 0.158664649f, 0.154489263f, 0.150528000f, 0.146764800f, 0.143185171f, 0.139776000f, 0.136525395f, 0.133422545f, 0.130457600f, 0.127621565f, 0.124906213f, 0.122304000f, 0.119808000f, 0.117411840f, 0.115109647f, 0.112896000f, 0.110765887f, 0.108714667f, 0.106738036f, 0.104832000f, 0.102992842f, 0.101217103f, 0.099501559f, 0.097843200f, 0.096239213f, 0.094686968f, 0.093184000f, 0.0f, 46.964736000f,23.482368000f,15.654912000f,11.741184000f, 9.392947200f, 7.827456000f, 6.709248000f, 5.870592000f, 5.218304000f, 4.696473600f, 4.269521455f, 3.913728000f, 3.612672000f, 3.354624000f, 3.130982400f, 2.935296000f, 2.762631529f, 2.609152000f, 2.471828211f, 2.348236800f, 2.236416000f, 2.134760727f, 2.041945043f, 1.956864000f, 1.878589440f, 1.806336000f, 1.739434667f, 1.677312000f, 1.619473655f, 1.565491200f, 1.514991484f, 1.467648000f, 1.423173818f, 1.381315765f, 1.341849600f, 1.304576000f, 1.269317189f, 1.235914105f, 1.204224000f, 1.174118400f, 1.145481366f, 1.118208000f, 1.092203163f, 1.067380364f, 1.043660800f, 1.020972522f, 0.999249702f, 0.978432000f, 0.958464000f, 0.939294720f, 0.920877176f, 0.903168000f, 0.886127094f, 0.869717333f, 0.853904291f, 0.838656000f, 0.823942737f, 0.809736828f, 0.796012475f, 0.782745600f, 0.769913705f, 0.757495742f, 0.745472000f }; /* the following hardcoded to avoid the need for a config.h : */ static const char *PACKAGE_URL = "http://www.mindwerks.net/projects/wildmidi/"; static const char *PACKAGE_BUGREPORT = "https://github.com/Mindwerks/wildmidi/issues"; static const char *PACKAGE_VERSION = "0.3"; static void do_version(void) { printf("DevTest for WildMIDI %s - For testing purposes only\n\n", PACKAGE_VERSION); printf("Copyright (C) Chris Ison 2001-2014 wildcode@users.sourceforge.net\n\n"); printf("DevTest comes with ABSOLUTELY NO WARRANTY\n"); printf("This is free software, and you are welcome to redistribute it\n"); printf("under the terms and conditions of the GNU General Public License version 3.\n"); printf("For more information see COPYING\n\n"); printf("Report bugs to %s\n", PACKAGE_BUGREPORT); printf("WildMIDI homepage at %s\n", PACKAGE_URL); printf("\n"); } static void do_help(void) { do_version(); printf(" -d N --debug-level N Verbose output\n"); printf(" -h --help Display this information\n"); printf(" -v --version Display version information\n\n"); } static unsigned char * DT_BufferFile(const char *filename, unsigned long int *size) { int buffer_fd; unsigned char *data; char *ret_data = NULL; struct stat buffer_stat; #ifndef _WIN32 const char *home = NULL; struct passwd *pwd_ent; char buffer_dir[1024]; #endif char *buffer_file = NULL; #ifndef _WIN32 if (strncmp(filename, "~/", 2) == 0) { if ((pwd_ent = getpwuid(getuid()))) { home = pwd_ent->pw_dir; } else { home = getenv("HOME"); } if (home) { buffer_file = malloc(strlen(filename) + strlen(home) + 1); if (buffer_file == NULL) { printf("Unable to get ram to expand %s: %s\n", filename, strerror(errno)); return NULL; } strcpy(buffer_file, home); strcat(buffer_file, filename + 1); } } else if (filename[0] != '/') { ret_data = getcwd(buffer_dir, 1024); if (ret_data != NULL) buffer_file = malloc(strlen(filename) + strlen(buffer_dir) + 2); if (buffer_file == NULL || ret_data == NULL) { printf("Unable to get ram to expand %s: %s\n", filename, strerror(errno)); return NULL; } strcpy(buffer_file, buffer_dir); if (buffer_dir[strlen(buffer_dir) - 1] != '/') strcat(buffer_file, "/"); strcat(buffer_file, filename); } #endif if (buffer_file == NULL) { buffer_file = malloc(strlen(filename) + 1); if (buffer_file == NULL) { printf("Unable to get ram to expand %s: %s\n", filename, strerror(errno)); return NULL; } strcpy(buffer_file, filename); } if (stat(buffer_file, &buffer_stat)) { printf("Unable to stat %s: %s\n", filename, strerror(errno)); free(buffer_file); return NULL; } *size = buffer_stat.st_size; data = malloc(*size); if (data == NULL) { printf("Unable to get ram for %s: %s\n", filename, strerror(errno)); free(buffer_file); return NULL; } #ifdef _WIN32 if ((buffer_fd = open(buffer_file,(O_RDONLY | O_BINARY))) == -1) { #else if ((buffer_fd = open(buffer_file, O_RDONLY)) == -1) { #endif printf("Unable to open %s: %s\n", filename, strerror(errno)); free(buffer_file); free(data); return NULL; } if (read(buffer_fd, data, *size) != buffer_stat.st_size) { printf("Unable to read %s: %s\n", filename, strerror(errno)); free(buffer_file); free(data); close(buffer_fd); return NULL; } close(buffer_fd); free(buffer_file); return data; } static int test_midi(unsigned char * midi_data, unsigned long int midi_size, int verbose) { unsigned int tmp_val; unsigned int track_size; unsigned char *next_track; unsigned char event; unsigned int delta; unsigned long int delta_accum; unsigned int meta_length; unsigned int no_tracks; unsigned int i; unsigned int divisions = 96; unsigned char running_event = 0; unsigned char *sysex_store = NULL; unsigned long int sysex_store_ofs = 0; unsigned long int tempo = 500000; float beats_per_minute = 0.0; float microseconds_per_pulse = 0.0; float pulses_per_second = 0.0; float samples_per_delta_f = 0.0; if (strncmp((char *) midi_data, "RIFF", 4) == 0) { midi_data += 20; midi_size -= 20; } if (strncmp((char *) midi_data, "MThd", 4) != 0) { printf("Not a midi file\n"); return -1; } midi_data += 4; midi_size -= 4; if (midi_size < 10) { printf("Midi File Too Short\n"); return -1; } /* * Get Midi Header Size - must always be 6 */ tmp_val = *midi_data++ << 24; tmp_val |= *midi_data++ << 16; tmp_val |= *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 4; if (verbose) printf("Header Size: %i\n", tmp_val); if (tmp_val != 6) { printf("Corrupt Midi Header\n"); return -1; } /* * Get Midi Format - we only support 0, 1 and 2 */ tmp_val = *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 2; if (verbose) printf("Format: %i\n", tmp_val); if (tmp_val > 2) { printf("Midi Format Not Supported\n"); return -1; } /* * Get No. of Tracks */ tmp_val = *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 2; if (verbose) printf("Number of Tracks: %i\n", tmp_val); if (tmp_val < 1) { printf("Midi Contains No Tracks\n"); return -1; } no_tracks = tmp_val; /* * Get Divisions */ divisions = *midi_data++ << 8; divisions |= *midi_data++; midi_size -= 2; if (verbose) { printf("Divisions: %i\n", divisions); if (divisions & 0x00008000) { printf("Division Type Not Supported\n"); return -1; } /* Slow but needed for accuracy */ beats_per_minute = 60000000.0 / (float) tempo; microseconds_per_pulse = (float) tempo / (float) divisions; pulses_per_second = 1000000.0 / microseconds_per_pulse; samples_per_delta_f = 44100.0 / pulses_per_second; if (verbose) printf("BPM: %f, SPD @ 44100: %f\n", beats_per_minute, samples_per_delta_f); } for (i = 0; i < no_tracks; i++) { if (midi_size < 8) { printf("Midi File Too Short\n"); return -1; } if (strncmp((char *) midi_data, "MTrk", 4) != 0) { printf("Expected Track Header\n"); return -1; } if (verbose) printf("Start of Track\n"); midi_data += 4; midi_size -= 4; track_size = *midi_data++ << 24; track_size |= *midi_data++ << 16; track_size |= *midi_data++ << 8; track_size |= *midi_data++; midi_size -= 4; if (verbose) printf("Track Size: %i\n", track_size); if (midi_size < track_size) { printf("Midi File Too Short: Missing Track Data\n"); return -1; } if ((midi_data[track_size - 3] != 0xFF) || (midi_data[track_size - 2] != 0x2F) || (midi_data[track_size - 1] != 0x00)) { printf("Corrupt Midi, Expected EOT\n"); return -1; } next_track = midi_data + track_size; delta_accum = 0; while (midi_data < next_track) { delta = 0; while (*midi_data > 0x7F) { delta = (delta << 7) | (*midi_data & 0x7F); midi_data++; midi_size--; if (midi_size == 0) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } } delta = (delta << 7) | (*midi_data & 0x7F); midi_data++; if (midi_size == 0) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } midi_size--; delta_accum += delta; /* tempo microseconds per quarter note * divisions pulses per quarter note */ /*if (verbose) printf("Est Seconds: %f\n",(((float)tempo/(float)divisions*(float)delta_accum)/1000000.0));*/ if (verbose) printf("Delta: %i, Accumilated Delta: %ld\n", delta, delta_accum); if (*midi_data < 0x80) { if (running_event == 0) { printf("Currupt Midi: expected event, got data\n"); return -1; } event = running_event; } else { event = *midi_data; midi_data++; if (midi_size == 0) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } midi_size--; } switch (event >> 4) { case 0x8: if ((midi_size < 2) || (midi_data[0] > 0x7F) || (midi_data[1] > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Note Off: chan(%i) note(%i) vel(%i)\n", (event & 0x0F), midi_data[0], midi_data[1]); midi_data += 2; midi_size -= 2; running_event = event; break; case 0x9: if ((midi_size < 2) || (midi_data[0] > 0x7F) || (midi_data[1] > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Note On: chan(%i) note(%i) vel(%i)\n", (event & 0x0F), midi_data[0], midi_data[1]); midi_data += 2; midi_size -= 2; running_event = event; break; case 0xA: if ((midi_size < 2) || (midi_data[0] > 0x7F) || (midi_data[1] > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Aftertouch: chan(%i) note(%i) vel(%i)\n", (event & 0x0F), midi_data[0], midi_data[1]); midi_data += 2; midi_size -= 2; running_event = event; break; case 0xB: if ((midi_size < 2) || (midi_data[0] > 0x7F) || (midi_data[1] > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("controler: chan(%i) ctrl(%i) set(%i)\n", (event & 0x0F), midi_data[0], midi_data[1]); midi_data += 2; midi_size -= 2; running_event = event; break; case 0xC: if ((midi_size == 0) || (*midi_data > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Set Patch: chan(%i) patch(%i)\n", (event & 0x4), *midi_data); midi_data++; midi_size--; running_event = event; break; case 0xD: if ((midi_size == 0) || (*midi_data > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Channel Pressure: chan(%i) pres(%i)\n", (event & 0x0F), *midi_data); midi_data++; midi_size--; running_event = event; break; case 0xE: if ((midi_size < 2) || (midi_data[0] > 0x7F) || (midi_data[1] > 0x7F)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } if (verbose) printf("Set Pitch: chan(%i) note(%i)\n", (event & 0x0F), ((midi_data[0] << 7) | midi_data[1])); midi_data += 2; midi_size -= 2; running_event = event; break; case 0xF: if ((event == 0xF0) || (event == 0xF7)) { unsigned long int sysex_size = 0; if (verbose) printf("Sysex Event which we mostly ignore\n"); running_event = 0; while (*midi_data > 0x7F) { sysex_size = (sysex_size << 7) | (*midi_data & 0x7F); midi_data++; } sysex_size = (sysex_size << 7) | (*midi_data & 0x7F); midi_data++; sysex_store = realloc(sysex_store, (sysex_store_ofs + sysex_size)); memcpy(&sysex_store[sysex_store_ofs], midi_data, sysex_size); sysex_store_ofs += sysex_size; if (sysex_store[sysex_store_ofs - 1] == 0xF7) { unsigned long int sysex_ofs = 0; unsigned char tmpsysexdata[] = { 0x41, 0x10, 0x42, 0x12 }; if (strncmp((const char *) tmpsysexdata, (const char *) sysex_store, 4) == 0) { unsigned char sysex_cs = 0; sysex_ofs = 4; do { sysex_cs += sysex_store[sysex_ofs]; if (sysex_cs > 0x7F) { sysex_cs -= 0x80; } sysex_ofs++; } while (sysex_store[sysex_ofs + 1] != 0xF7); sysex_cs = 0x80 - sysex_cs; if (sysex_cs != sysex_store[sysex_ofs]) { printf("Roland Sysex Checksum Error: "); sysex_ofs = 0; do { printf("%02x ", sysex_store[sysex_ofs]); sysex_ofs++; } while (sysex_ofs != sysex_store_ofs); printf("\n"); } else { if (sysex_store[4] == 0x40) { if (((sysex_store[5] & 0xF0) == 0x10) && (sysex_store[6] == 0x15)) { /* Roland Drum Track Setting */ unsigned char sysex_ch = 0x0F & sysex_store[5]; if (sysex_ch == 0x00) { sysex_ch = 0x09; } else if (sysex_ch <= 0x09) { sysex_ch -= 1; } if (verbose) printf("Additional Drum Channel(0x%02x) Setting: 0x%02x\n", sysex_ch, sysex_store[7]); } else if ((sysex_store[5] == 0x00) && (sysex_store[6] == 0x7F) && (sysex_store[7] == 0x00)) { /* Roland GS Reset */ if (verbose) printf("GS Reset\n"); } else { goto UNKNOWNSYSEX; } } else { goto UNKNOWNSYSEX; } } } else { UNKNOWNSYSEX: if (verbose) { printf("Unknown Sysex: "); sysex_ofs = 0; do { printf("%02x ", sysex_store[sysex_ofs]); sysex_ofs++; } while (sysex_ofs != sysex_store_ofs); printf("\n"); } } } free(sysex_store); sysex_store = NULL; sysex_store_ofs = 0; midi_data += sysex_size; } else if (event == 0xFF) { if (*midi_data == 0x02) { if (verbose) printf("Meta Event: Copyright\n"); } else if (*midi_data == 0x2F) { if (verbose) printf("Meta Event: End Of Track\n"); if (midi_size < 2) { printf("Corrupt Midi, Corrupt or Missing Data\n"); return -1; } if (midi_data[1] != 0x00) { printf("Corrupt Midi, Bad End Of Track\n"); return -1; } } else if (*midi_data == 0x21) { if (verbose) printf("Meta Event: Port Prefix: "); if (midi_size < 3) { printf("Corrupt Midi, Corrupt or Missing Data\n"); return -1; } if (midi_data[1] != 0x01) { printf("Corrupt Midi, Bad Port Prefix\n"); return -1; } if (verbose) printf("%i\n", (int) midi_data[2]); } else if (*midi_data == 0x51) { if (verbose) printf("Meta Event: Tempo\n"); if (midi_size < 2) { printf("Corrupt Midi, Corrupt or Missing Data\n"); return -1; } if (midi_data[1] != 0x03) { printf("Corrupt Midi, Bad Tempo\n"); return -1; } tempo = (midi_data[2] << 16) | (midi_data[3] << 8) | midi_data[4]; beats_per_minute = 60000000.0 / (float) tempo; microseconds_per_pulse = (float) tempo / (float) divisions; pulses_per_second = 1000000.0 / microseconds_per_pulse; samples_per_delta_f = 44100.0 / pulses_per_second; if (verbose) printf("BPM: %f, SPD @ 44100: %f\n", beats_per_minute, samples_per_delta_f); } else { if (verbose) printf("Meta Event: Unsupported (%i)\n", *midi_data); } midi_data++; midi_size--; meta_length = 0; while (*midi_data > 0x7F) { meta_length = (meta_length << 7) | (*midi_data & 0x7F); midi_data++; if (midi_size == 0) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } midi_size--; } meta_length = (meta_length << 7) | (*midi_data & 0x7F); midi_data++; if ((midi_size == 0) || (midi_size < meta_length)) { printf("Corrupt Midi, Missing or Corrupt Track Data\n"); return -1; } midi_size--; midi_data += meta_length; midi_size -= meta_length; } else { printf("Corrupt Midi, Unknown Event Data\n"); return -1; } break; } if (midi_data > next_track) { printf("Corrupt Midi, Track Data went beyond track boundries.\n"); return -1; } } } return 0; } static int test_guspat(unsigned char * gus_patch, unsigned long int filesize, int verbose) { unsigned long int gus_ptr = 0; unsigned char no_of_samples = 0; if (filesize < 239) { printf("File too short\n"); return -1; } if (memcmp(gus_patch, "GF1PATCH110\0ID#000002", 22) && memcmp(gus_patch, "GF1PATCH100\0ID#000002", 22)) { printf("Unsupported format\n"); return -1; } if ((gus_patch[82] > 1) || (gus_patch[151] > 1)) { printf("Unsupported format\n"); return -1; } no_of_samples = gus_patch[198]; if (verbose) printf("Number of samples: %i\n", no_of_samples); gus_ptr = 239; do { if ((gus_ptr + 96) > filesize) { printf("File too short\n"); return -1; } if (verbose) { printf("Sample Start\n"); printf("Loop Fraction: 0x%x, ", gus_patch[gus_ptr + 7]); printf("Data Length: %i, ", ((gus_patch[gus_ptr + 11] << 24) | (gus_patch[gus_ptr + 10] << 16) | (gus_patch[gus_ptr + 9] << 8) | gus_patch[gus_ptr + 8])); printf("Loop Start: %i, ", ((gus_patch[gus_ptr + 15] << 24) | (gus_patch[gus_ptr + 14] << 16) | (gus_patch[gus_ptr + 13] << 8) | gus_patch[gus_ptr + 12])); printf("Loop End: %i\n", ((gus_patch[gus_ptr + 19] << 24) | (gus_patch[gus_ptr + 18] << 16) | (gus_patch[gus_ptr + 17] << 8) | gus_patch[gus_ptr + 16])); printf("Rate: %i, ", ((gus_patch[gus_ptr + 21] << 8) | gus_patch[gus_ptr + 20])); printf("Low Freq: %fHz, ", (float) ((gus_patch[gus_ptr + 25] << 24) | (gus_patch[gus_ptr + 24] << 16) | (gus_patch[gus_ptr + 23] << 8) | gus_patch[gus_ptr + 22]) / 1000.0); printf("High Freq: %fHz, ", (float) ((gus_patch[gus_ptr + 29] << 24) | (gus_patch[gus_ptr + 28] << 16) | (gus_patch[gus_ptr + 27] << 8) | gus_patch[gus_ptr + 26]) / 1000.0); printf("Root Freq: %fHz\n", (float) ((gus_patch[gus_ptr + 33] << 24) | (gus_patch[gus_ptr + 32] << 16) | (gus_patch[gus_ptr + 31] << 8) | gus_patch[gus_ptr + 30]) / 1000.0); printf("Attack Level: %i, Attack Time: %fsecs\n", gus_patch[gus_ptr + 43], env_time_table[gus_patch[gus_ptr + 37]]); printf("Decay Level: %i, Decay Time: %fsecs\n", gus_patch[gus_ptr + 44], env_time_table[gus_patch[gus_ptr + 38]]); printf("Sustain Level: %i, Sustain Time: %fsecs\n", gus_patch[gus_ptr + 45], env_time_table[gus_patch[gus_ptr + 39]]); printf("Sustained Release Level: %i, Sustained Release Time: %fsecs\n", gus_patch[gus_ptr + 46], env_time_table[gus_patch[gus_ptr + 40]]); printf("Normal Release Level: %i, Normal Release Time: %fsecs\n", gus_patch[gus_ptr + 47], env_time_table[gus_patch[gus_ptr + 41]]); printf("Clamped Release Level: %i, Clamped Release Time: %fsecs\n", gus_patch[gus_ptr + 48], env_time_table[gus_patch[gus_ptr + 42]]); } if (env_time_table[gus_patch[gus_ptr + 40]] < env_time_table[gus_patch[gus_ptr + 41]]) { printf("WARNING!! Normal release envelope longer than sustained release envelope\n"); printf(" Caused by patch editor not following the file format set by Gravis\n"); printf(" Add guspat_editor_author_cant_read_so_fix_release_time_for_me to top of wildmidi.cfg\n"); } if (verbose) { printf("Modes: "); if (gus_patch[gus_ptr + 55] & 0x01) printf("16 Bit "); if (gus_patch[gus_ptr + 55] & 0x02) printf("Unsigned "); if (gus_patch[gus_ptr + 55] & 0x04) printf("Loop "); if (gus_patch[gus_ptr + 55] & 0x08) printf("Ping Pong "); if (gus_patch[gus_ptr + 55] & 0x10) printf("Reverse "); if (gus_patch[gus_ptr + 55] & 0x20) printf("Sustain "); if (gus_patch[gus_ptr + 55] & 0x40) printf("Envelope "); if (gus_patch[gus_ptr + 55] & 0x80) printf("Clamped Release "); printf("\n"); printf("Sample End\n\n"); } gus_ptr += 96 + ((gus_patch[gus_ptr + 11] << 24) | (gus_patch[gus_ptr + 10] << 16) | (gus_patch[gus_ptr + 9] << 8) | gus_patch[gus_ptr + 8]); } while (--no_of_samples); return 0; } int main(int argc, char ** argv) { int i; int option_index = 0; int verbose = 0; int testret = 0; unsigned char *filebuffer = NULL; unsigned long int filesize = 0; do_version(); while (1) { i = getopt_long(argc, argv, "d:vh", long_options, &option_index); if (i == -1) break; switch (i) { case 'd': /* Verbose */ verbose = atoi(optarg); break; case 'v': /* Version */ return 0; case 'h': /* help */ do_help(); return 0; default: printf("Unknown Option -%o ??\n", i); return 0; } } if (optind >= argc) { return 0; } while (optind < argc) { if ((strcasecmp((argv[optind] + strlen(argv[optind]) - 4), ".mid") != 0) && (strcasecmp((argv[optind] + strlen(argv[optind]) - 4), ".pat") != 0)) { printf("Testing of %s is not supported\n", argv[optind]); optind++; continue; } printf("Testing: %s\n", argv[optind]); testret = 0; if ((filebuffer = DT_BufferFile(argv[optind], &filesize)) != NULL) { if (strcasecmp((argv[optind] + strlen(argv[optind]) - 4), ".mid") == 0) { testret = test_midi(filebuffer, filesize, verbose); } else if (strcasecmp((argv[optind] + strlen(argv[optind]) - 4), ".pat") == 0) { testret = test_guspat(filebuffer, filesize, verbose); } free(filebuffer); if (testret != 0) { printf("FAILED: %s will not work correctly with WildMIDI\n\n", argv[optind]); } else { printf("Success\n\n"); } } optind++; } return 0; } wildmidi-wildmidi-0.3.8/src/file_io.c000066400000000000000000000110121245740225500174660ustar00rootroot00000000000000/* file_io.c file handling Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #include #include #include #include #include #include #ifdef _WIN32 #include #undef close #define close _close #undef open #define open _open #undef read #define read _read #elif defined(__DJGPP__) #include #include #include #else #include #include #include #endif #if !defined(O_BINARY) # if defined(_O_BINARY) # define O_BINARY _O_BINARY # else # define O_BINARY 0 # endif #endif #include "wm_error.h" #include "file_io.h" unsigned char *_WM_BufferFile(const char *filename, unsigned long int *size) { int buffer_fd; unsigned char *data; #ifdef __DJGPP__ struct ffblk f; #else struct stat buffer_stat; #endif #if !defined(_WIN32) && !defined(__DJGPP__) const char *home = NULL; struct passwd *pwd_ent; char buffer_dir[1024]; #endif /* unix builds */ char *buffer_file = NULL; #if !defined(_WIN32) && !defined(__DJGPP__) if (strncmp(filename, "~/", 2) == 0) { if ((pwd_ent = getpwuid(getuid()))) { home = pwd_ent->pw_dir; } else { home = getenv("HOME"); } if (home) { buffer_file = malloc(strlen(filename) + strlen(home) + 1); if (buffer_file == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); return NULL; } strcpy(buffer_file, home); strcat(buffer_file, filename + 1); } } else if (filename[0] != '/') { char* cwdresult = getcwd(buffer_dir, 1024); if (cwdresult != NULL) buffer_file = malloc(strlen(filename) + strlen(buffer_dir) + 2); if (buffer_file == NULL || cwdresult == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); return NULL; } strcpy(buffer_file, buffer_dir); if (buffer_dir[strlen(buffer_dir) - 1] != '/') strcat(buffer_file, "/"); strcat(buffer_file, filename); } #endif if (buffer_file == NULL) { buffer_file = malloc(strlen(filename) + 1); if (buffer_file == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); return NULL; } strcpy(buffer_file, filename); } #ifdef __DJGPP__ if (findfirst(buffer_file, &f, FA_ARCH | FA_RDONLY) != 0) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_STAT, filename, errno); free(buffer_file); return NULL; } *size = f.ff_fsize; #else if (stat(buffer_file, &buffer_stat)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_STAT, filename, errno); free(buffer_file); return NULL; } *size = buffer_stat.st_size; #endif if (__builtin_expect((*size > WM_MAXFILESIZE), 0)) { /* don't bother loading suspiciously long files */ _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LONGFIL, filename, 0); free(buffer_file); return NULL; } /* +1 needed for parsing text files without a newline at the end */ data = (unsigned char *) malloc(*size + 1); if (data == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, errno); free(buffer_file); return NULL; } if ((buffer_fd = open(buffer_file,(O_RDONLY | O_BINARY))) == -1) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_OPEN, filename, errno); free(buffer_file); free(data); return NULL; } if (read(buffer_fd, data, *size) != (long) *size) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_READ, filename, errno); free(buffer_file); free(data); close(buffer_fd); return NULL; } data[*size] = '\0'; close(buffer_fd); free(buffer_file); return data; } wildmidi-wildmidi-0.3.8/src/getopt_long.c000066400000000000000000000347331245740225500204200ustar00rootroot00000000000000/* $OpenBSD: getopt_long.c,v 1.26 2013/06/08 22:47:56 millert Exp $ */ /* $NetBSD: getopt_long.c,v 1.15 2002/01/31 22:43:40 tv Exp $ */ /* * Copyright (c) 2002 Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * * Sponsored in part by the Defense Advanced Research Projects * Agency (DARPA) and Air Force Research Laboratory, Air Force * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ /*- * Copyright (c) 2000 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Dieter Baron and Thomas Klausner. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ #include #include #include #include #include "getopt_long.h" int opterr = 1; /* if error message should be printed */ int optind = 1; /* index into parent argv vector */ int optopt = '?'; /* character checked for validity */ int optreset; /* reset getopt */ char *optarg; /* argument associated with option */ #define PRINT_ERROR ((opterr) && (*options != ':')) #define FLAG_PERMUTE 0x01 /* permute non-options to the end of argv */ #define FLAG_ALLARGS 0x02 /* treat non-options as args to option "-1" */ #define FLAG_LONGONLY 0x04 /* operate as getopt_long_only */ /* return values */ #define BADCH (int)'?' #define BADARG ((*options == ':') ? (int)':' : (int)'?') #define INORDER (int)1 #define EMSG "" static int getopt_internal(int, char * const *, const char *, const struct option *, int *, int); static int parse_long_options(char * const *, const char *, const struct option *, int *, int, int); static int gcd(int, int); static void permute_args(int, int, int, char * const *); static char *place = EMSG; /* option letter processing */ /* XXX: set optreset to 1 rather than these two */ static int nonopt_start = -1; /* first non option argument (for permute) */ static int nonopt_end = -1; /* first option after non options (for permute) */ /* Error messages */ static const char recargchar[] = "option requires an argument -- %c"; static const char recargstring[] = "option requires an argument -- %s"; static const char ambig[] = "ambiguous option -- %.*s"; static const char noarg[] = "option doesn't take an argument -- %.*s"; static const char illoptchar[] = "unknown option -- %c"; static const char illoptstring[] = "unknown option -- %s"; /* * Compute the greatest common divisor of a and b. */ static int gcd(int a, int b) { int c; c = a % b; while (c != 0) { a = b; b = c; c = a % b; } return (b); } /* * Exchange the block from nonopt_start to nonopt_end with the block * from nonopt_end to opt_end (keeping the same order of arguments * in each block). */ static void permute_args(int panonopt_start, int panonopt_end, int opt_end, char * const *nargv) { int cstart, cyclelen, i, j, ncycle, nnonopts, nopts, pos; char *swap; /* * compute lengths of blocks and number and size of cycles */ nnonopts = panonopt_end - panonopt_start; nopts = opt_end - panonopt_end; ncycle = gcd(nnonopts, nopts); cyclelen = (opt_end - panonopt_start) / ncycle; for (i = 0; i < ncycle; i++) { cstart = panonopt_end+i; pos = cstart; for (j = 0; j < cyclelen; j++) { if (pos >= panonopt_end) pos -= nnonopts; else pos += nopts; swap = nargv[pos]; /* LINTED const cast */ ((char **) nargv)[pos] = nargv[cstart]; /* LINTED const cast */ ((char **)nargv)[cstart] = swap; } } } /* * parse_long_options -- * Parse long options in argc/argv argument vector. * Returns -1 if short_too is set and the option does not match long_options. */ static int parse_long_options(char * const *nargv, const char *options, const struct option *long_options, int *idx, int short_too, int flags) { char *current_argv, *has_equal; size_t current_argv_len; int i, match, exact_match, second_partial_match; current_argv = place; match = -1; exact_match = 0; second_partial_match = 0; optind++; if ((has_equal = strchr(current_argv, '=')) != NULL) { /* argument found (--option=arg) */ current_argv_len = has_equal - current_argv; has_equal++; } else current_argv_len = strlen(current_argv); for (i = 0; long_options[i].name; i++) { /* find matching long option */ if (strncmp(current_argv, long_options[i].name, current_argv_len)) continue; if (strlen(long_options[i].name) == current_argv_len) { /* exact match */ match = i; exact_match = 1; break; } /* * If this is a known short option, don't allow * a partial match of a single character. */ if (short_too && current_argv_len == 1) continue; if (match == -1) /* first partial match */ match = i; else if ((flags & FLAG_LONGONLY) || long_options[i].has_arg != long_options[match].has_arg || long_options[i].flag != long_options[match].flag || long_options[i].val != long_options[match].val) second_partial_match = 1; } if (!exact_match && second_partial_match) { /* ambiguous abbreviation */ if (PRINT_ERROR) fprintf(stderr, ambig, (int)current_argv_len, current_argv); optopt = 0; return (BADCH); } if (match != -1) { /* option found */ if (long_options[match].has_arg == no_argument && has_equal) { if (PRINT_ERROR) fprintf(stderr, noarg, (int)current_argv_len, current_argv); /* * XXX: GNU sets optopt to val regardless of flag */ if (long_options[match].flag == NULL) optopt = long_options[match].val; else optopt = 0; return (BADARG); } if (long_options[match].has_arg == required_argument || long_options[match].has_arg == optional_argument) { if (has_equal) optarg = has_equal; else if (long_options[match].has_arg == required_argument) { /* * optional argument doesn't use next nargv */ optarg = nargv[optind++]; } } if ((long_options[match].has_arg == required_argument) && (optarg == NULL)) { /* * Missing argument; leading ':' indicates no error * should be generated. */ if (PRINT_ERROR) fprintf(stderr, recargstring, current_argv); /* * XXX: GNU sets optopt to val regardless of flag */ if (long_options[match].flag == NULL) optopt = long_options[match].val; else optopt = 0; --optind; return (BADARG); } } else { /* unknown option */ if (short_too) { --optind; return (-1); } if (PRINT_ERROR) fprintf(stderr, illoptstring, current_argv); optopt = 0; return (BADCH); } if (idx) *idx = match; if (long_options[match].flag) { *long_options[match].flag = long_options[match].val; return (0); } else return (long_options[match].val); } /* * getopt_internal -- * Parse argc/argv argument vector. Called by user level routines. */ static int getopt_internal(int nargc, char * const *nargv, const char *options, const struct option *long_options, int *idx, int flags) { char *oli; /* option letter list index */ int optchar, short_too; static int posixly_correct = -1; if (options == NULL) return (-1); /* * XXX Some GNU programs (like cvs) set optind to 0 instead of * XXX using optreset. Work around this braindamage. */ if (optind == 0) optind = optreset = 1; /* * Disable GNU extensions if POSIXLY_CORRECT is set or options * string begins with a '+'. */ if (posixly_correct == -1 || optreset) posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); if (*options == '-') flags |= FLAG_ALLARGS; else if (posixly_correct || *options == '+') flags &= ~FLAG_PERMUTE; if (*options == '+' || *options == '-') options++; optarg = NULL; if (optreset) nonopt_start = nonopt_end = -1; start: if (optreset || !*place) { /* update scanning pointer */ optreset = 0; if (optind >= nargc) { /* end of argument vector */ place = EMSG; if (nonopt_end != -1) { /* do permutation, if we have to */ permute_args(nonopt_start, nonopt_end, optind, nargv); optind -= nonopt_end - nonopt_start; } else if (nonopt_start != -1) { /* * If we skipped non-options, set optind * to the first of them. */ optind = nonopt_start; } nonopt_start = nonopt_end = -1; return (-1); } if (*(place = nargv[optind]) != '-' || (place[1] == '\0' && strchr(options, '-') == NULL)) { place = EMSG; /* found non-option */ if (flags & FLAG_ALLARGS) { /* * GNU extension: * return non-option as argument to option 1 */ optarg = nargv[optind++]; return (INORDER); } if (!(flags & FLAG_PERMUTE)) { /* * If no permutation wanted, stop parsing * at first non-option. */ return (-1); } /* do permutation */ if (nonopt_start == -1) nonopt_start = optind; else if (nonopt_end != -1) { permute_args(nonopt_start, nonopt_end, optind, nargv); nonopt_start = optind - (nonopt_end - nonopt_start); nonopt_end = -1; } optind++; /* process next argument */ goto start; } if (nonopt_start != -1 && nonopt_end == -1) nonopt_end = optind; /* * If we have "-" do nothing, if "--" we are done. */ if (place[1] != '\0' && *++place == '-' && place[1] == '\0') { optind++; place = EMSG; /* * We found an option (--), so if we skipped * non-options, we have to permute. */ if (nonopt_end != -1) { permute_args(nonopt_start, nonopt_end, optind, nargv); optind -= nonopt_end - nonopt_start; } nonopt_start = nonopt_end = -1; return (-1); } } /* * Check long options if: * 1) we were passed some * 2) the arg is not just "-" * 3) either the arg starts with -- we are getopt_long_only() */ if (long_options != NULL && place != nargv[optind] && (*place == '-' || (flags & FLAG_LONGONLY))) { short_too = 0; if (*place == '-') place++; /* --foo long option */ else if (*place != ':' && strchr(options, *place) != NULL) short_too = 1; /* could be short option too */ optchar = parse_long_options(nargv, options, long_options, idx, short_too, flags); if (optchar != -1) { place = EMSG; return (optchar); } } if ((optchar = (int)*place++) == (int)':' || (optchar == (int)'-' && *place != '\0') || (oli = strchr(options, optchar)) == NULL) { /* * If the user specified "-" and '-' isn't listed in * options, return -1 (non-option) as per POSIX. * Otherwise, it is an unknown option character (or ':'). */ if (optchar == (int)'-' && *place == '\0') return (-1); if (!*place) ++optind; if (PRINT_ERROR) fprintf(stderr, illoptchar, optchar); optopt = optchar; return (BADCH); } if (long_options != NULL && optchar == 'W' && oli[1] == ';') { /* -W long-option */ if (*place) /* no space */ /* NOTHING */; else if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else /* white space */ place = nargv[optind]; optchar = parse_long_options(nargv, options, long_options, idx, 0, flags); place = EMSG; return (optchar); } if (*++oli != ':') { /* doesn't take argument */ if (!*place) ++optind; } else { /* takes (optional) argument */ optarg = NULL; if (*place) /* no white space */ optarg = place; else if (oli[1] != ':') { /* arg not optional */ if (++optind >= nargc) { /* no arg */ place = EMSG; if (PRINT_ERROR) fprintf(stderr, recargchar, optchar); optopt = optchar; return (BADARG); } else optarg = nargv[optind]; } place = EMSG; ++optind; } /* dump back option letter */ return (optchar); } /* * getopt -- * Parse argc/argv argument vector. * * [eventually this will replace the BSD getopt] */ int getopt(int nargc, char * const *nargv, const char *options) { /* * We don't pass FLAG_PERMUTE to getopt_internal() since * the BSD getopt(3) (unlike GNU) has never done this. * * Furthermore, since many privileged programs call getopt() * before dropping privileges it makes sense to keep things * as simple (and bug-free) as possible. */ return (getopt_internal(nargc, nargv, options, NULL, NULL, 0)); } /* * getopt_long -- * Parse argc/argv argument vector. */ int getopt_long(int nargc, char * const *nargv, const char *options, const struct option *long_options, int *idx) { return (getopt_internal(nargc, nargv, options, long_options, idx, FLAG_PERMUTE)); } /* * getopt_long_only -- * Parse argc/argv argument vector. */ int getopt_long_only(int nargc, char * const *nargv, const char *options, const struct option *long_options, int *idx) { return (getopt_internal(nargc, nargv, options, long_options, idx, FLAG_PERMUTE|FLAG_LONGONLY)); } wildmidi-wildmidi-0.3.8/src/gus_pat.c000066400000000000000000000747671245740225500175540ustar00rootroot00000000000000/* gus_pat.c Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #include #include #include #include #include "gus_pat.h" #include "common.h" #include "wm_error.h" #include "file_io.h" #ifdef DEBUG_GUSPAT #define GUSPAT_FILENAME_DEBUG(dx) fprintf(stderr,"\r%s\n",dx) #define GUSPAT_INT_DEBUG(dx,dy) fprintf(stderr,"\r%s: %i\n",dx,dy) #define GUSPAT_FLOAT_DEBUG(dx,dy) fprintf(stderr,"\r%s: %f\n",dx,dy) #define GUSPAT_START_DEBUG() fprintf(stderr,"\r") #define GUSPAT_MODE_DEBUG(dx,dy,dz) if (dx & dy) fprintf(stderr,"%s",dz) #define GUSPAT_END_DEBUG() fprintf(stderr,"\n") #else #define GUSPAT_FILENAME_DEBUG(dx) #define GUSPAT_INT_DEBUG(dx,dy) #define GUSPAT_FLOAT_DEBUG(dx,dy) #define GUSPAT_START_DEBUG() #define GUSPAT_MODE_DEBUG(dx,dy,dz) #define GUSPAT_END_DEBUG() #endif /* * sample data conversion functions * convert data to signed shorts */ /* 8bit signed */ static int convert_8s(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((gus_sample->data_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = (*read_data++) << 8; } while (read_data != read_end); return 0; } _WM_ERROR_NEW("(%s:%i) ERROR: calloc failed (%s)", __FUNCTION__, __LINE__, strerror(errno)); return -1; } /* 8bit signed ping pong */ static int convert_8sp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->loop_start; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((new_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = (*read_data++) << 8; } while (read_data != read_end); *write_data = (*read_data++ << 8); write_data_a = write_data + dloop_length; *write_data_a-- = *write_data; write_data++; write_data_b = write_data + dloop_length; read_end = data + gus_sample->loop_end; do { *write_data = (*read_data++) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data != read_end); *write_data = (*read_data++ << 8); *write_data_b++ = *write_data; read_end = data + gus_sample->data_length; if (__builtin_expect((read_data != read_end), 1)) { do { *write_data_b++ = (*read_data++) << 8; } while (read_data != read_end); } gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit signed reverse */ static int convert_8sr(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; unsigned long int tmp_loop = 0; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((gus_sample->data_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data + gus_sample->data_length - 1; do { *write_data-- = (*read_data++) << 8; } while (read_data != read_end); tmp_loop = gus_sample->loop_end; gus_sample->loop_end = gus_sample->data_length - gus_sample->loop_start; gus_sample->loop_start = gus_sample->data_length - tmp_loop; gus_sample->loop_fraction = ((gus_sample->loop_fraction & 0x0f) << 4) | ((gus_sample->loop_fraction & 0xf0) >> 4); gus_sample->modes ^= SAMPLE_REVERSE; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit signed reverse ping pong */ static int convert_8srp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data + gus_sample->data_length - 1; unsigned char *read_end = data + gus_sample->loop_end; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((new_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = (*read_data--) << 8; } while (read_data != read_end); *write_data = (*read_data-- << 8); write_data_a = write_data + dloop_length; *write_data_a-- = *write_data; write_data++; write_data_b = write_data + dloop_length; read_end = data + gus_sample->loop_start; do { *write_data = (*read_data--) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data != read_end); *write_data = (*read_data-- << 8); *write_data_b++ = *write_data; read_end = data - 1; do { *write_data_b++ = (*read_data--) << 8; write_data_b++; } while (read_data != read_end); gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG | SAMPLE_REVERSE; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit unsigned */ static int convert_8u(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((gus_sample->data_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = ((*read_data++) ^ 0x80) << 8; } while (read_data != read_end); gus_sample->modes ^= SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit unsigned ping pong */ static int convert_8up(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->loop_start; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((new_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = ((*read_data++) ^ 0x80) << 8; } while (read_data != read_end); *write_data = ((*read_data++) ^ 0x80) << 8; write_data_a = write_data + dloop_length; *write_data_a-- = *write_data; write_data++; write_data_b = write_data + dloop_length; read_end = data + gus_sample->loop_end; do { *write_data = ((*read_data++) ^ 0x80) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data != read_end); *write_data = ((*read_data++) ^ 0x80) << 8; *write_data_b++ = *write_data; read_end = data + gus_sample->data_length; if (__builtin_expect((read_data != read_end), 1)) { do { *write_data_b++ = ((*read_data++) ^ 0x80) << 8; } while (read_data != read_end); } gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG | SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit unsigned reverse */ static int convert_8ur(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; unsigned long int tmp_loop = 0; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((gus_sample->data_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data + gus_sample->data_length - 1; do { *write_data-- = ((*read_data++) ^ 0x80) << 8; } while (read_data != read_end); tmp_loop = gus_sample->loop_end; gus_sample->loop_end = gus_sample->data_length - gus_sample->loop_start; gus_sample->loop_start = gus_sample->data_length - tmp_loop; gus_sample->loop_fraction = ((gus_sample->loop_fraction & 0x0f) << 4) | ((gus_sample->loop_fraction & 0xf0) >> 4); gus_sample->modes ^= SAMPLE_REVERSE | SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 8bit unsigned reverse ping pong */ static int convert_8urp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data + gus_sample->data_length - 1; unsigned char *read_end = data + gus_sample->loop_end; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc((new_length + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data++ = ((*read_data--) ^ 0x80) << 8; } while (read_data != read_end); *write_data = ((*read_data--) ^ 0x80) << 8; write_data_a = write_data + dloop_length; *write_data_a-- = *write_data; write_data++; write_data_b = write_data + dloop_length; read_end = data + gus_sample->loop_start; do { *write_data = ((*read_data--) ^ 0x80) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data != read_end); *write_data = ((*read_data--) ^ 0x80) << 8; *write_data_b++ = *write_data; read_end = data - 1; do { *write_data_b++ = ((*read_data--) ^ 0x80) << 8; } while (read_data != read_end); gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG | SAMPLE_REVERSE | SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit signed */ static int convert_16s(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((gus_sample->data_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = *read_data++; *write_data++ |= (*read_data++) << 8; } while (read_data < read_end); gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit signed ping pong */ static int convert_16sp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->loop_start; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((new_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = (*read_data++); *write_data++ |= (*read_data++) << 8; } while (read_data < read_end); *write_data = (*read_data++); *write_data |= (*read_data++) << 8; write_data_a = write_data + (dloop_length >> 1); *write_data_a-- = *write_data; write_data++; write_data_b = write_data + (dloop_length >> 1); read_end = data + gus_sample->loop_end; do { *write_data = (*read_data++); *write_data |= (*read_data++) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data < read_end); *write_data = *(read_data++); *write_data |= (*read_data++) << 8; *write_data_b++ = *write_data; read_end = data + gus_sample->data_length; if (__builtin_expect((read_data != read_end), 1)) { do { *write_data_b = *(read_data++); *write_data_b++ |= (*read_data++) << 8; } while (read_data < read_end); } gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG; gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit signed reverse */ static int convert_16sr(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; unsigned long int tmp_loop = 0; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((gus_sample->data_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data + (gus_sample->data_length >> 1) - 1; do { *write_data = *read_data++; *write_data-- |= (*read_data++) << 8; } while (read_data < read_end); tmp_loop = gus_sample->loop_end; gus_sample->loop_end = gus_sample->data_length - gus_sample->loop_start; gus_sample->loop_start = gus_sample->data_length - tmp_loop; gus_sample->loop_fraction = ((gus_sample->loop_fraction & 0x0f) << 4) | ((gus_sample->loop_fraction & 0xf0) >> 4); gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; gus_sample->modes ^= SAMPLE_REVERSE; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit signed reverse ping pong */ static int convert_16srp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data + gus_sample->data_length - 1; unsigned char *read_end = data + gus_sample->loop_end; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((new_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = (*read_data--) << 8; *write_data++ |= *read_data--; } while (read_data < read_end); *write_data = (*read_data-- << 8); *write_data |= *read_data--; write_data_a = write_data + (dloop_length >> 1); *write_data_a-- = *write_data; write_data++; write_data_b = write_data + (dloop_length >> 1); read_end = data + gus_sample->loop_start; do { *write_data = (*read_data--) << 8; *write_data |= *read_data--; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data < read_end); *write_data = ((*read_data--) << 8); *write_data |= *read_data--; *write_data_b++ = *write_data; read_end = data - 1; do { *write_data_b = (*read_data--) << 8; *write_data_b++ |= *read_data--; } while (read_data < read_end); gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG | SAMPLE_REVERSE; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit unsigned */ static int convert_16u(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((gus_sample->data_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = *read_data++; *write_data++ |= ((*read_data++) ^ 0x80) << 8; } while (read_data < read_end); gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; gus_sample->modes ^= SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit unsigned ping pong */ static int convert_16up(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->loop_start; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((new_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = (*read_data++); *write_data++ |= ((*read_data++) ^ 0x80) << 8; } while (read_data < read_end); *write_data = (*read_data++); *write_data |= ((*read_data++) ^ 0x80) << 8; write_data_a = write_data + (dloop_length >> 1); *write_data_a-- = *write_data; write_data++; write_data_b = write_data + (dloop_length >> 1); read_end = data + gus_sample->loop_end; do { *write_data = (*read_data++); *write_data |= ((*read_data++) ^ 0x80) << 8; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data < read_end); *write_data = (*read_data++); *write_data |= ((*read_data++) ^ 0x80) << 8; *write_data_b++ = *write_data; read_end = data + gus_sample->data_length; if (__builtin_expect((read_data != read_end), 1)) { do { *write_data_b = (*read_data++); *write_data_b++ |= ((*read_data++) ^ 0x80) << 8; } while (read_data < read_end); } gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG; gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit unsigned reverse */ static int convert_16ur(unsigned char *data, struct _sample *gus_sample) { unsigned char *read_data = data; unsigned char *read_end = data + gus_sample->data_length; signed short int *write_data = NULL; unsigned long int tmp_loop = 0; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((gus_sample->data_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data + (gus_sample->data_length >> 1) - 1; do { *write_data = *read_data++; *write_data-- |= ((*read_data++) ^ 0x80) << 8; } while (read_data < read_end); tmp_loop = gus_sample->loop_end; gus_sample->loop_end = gus_sample->data_length - gus_sample->loop_start; gus_sample->loop_start = gus_sample->data_length - tmp_loop; gus_sample->loop_fraction = ((gus_sample->loop_fraction & 0x0f) << 4) | ((gus_sample->loop_fraction & 0xf0) >> 4); gus_sample->loop_start >>= 1; gus_sample->loop_end >>= 1; gus_sample->data_length >>= 1; gus_sample->modes ^= SAMPLE_REVERSE | SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* 16bit unsigned reverse ping pong */ static int convert_16urp(unsigned char *data, struct _sample *gus_sample) { unsigned long int loop_length = gus_sample->loop_end - gus_sample->loop_start; unsigned long int dloop_length = loop_length * 2; unsigned long int new_length = gus_sample->data_length + dloop_length; unsigned char *read_data = data + gus_sample->data_length - 1; unsigned char *read_end = data + gus_sample->loop_end; signed short int *write_data = NULL; signed short int *write_data_a = NULL; signed short int *write_data_b = NULL; SAMPLE_CONVERT_DEBUG(__FUNCTION__); gus_sample->data = calloc(((new_length >> 1) + 2), sizeof(signed short int)); if (__builtin_expect((gus_sample->data != NULL), 1)) { write_data = gus_sample->data; do { *write_data = ((*read_data--) ^ 0x80) << 8; *write_data++ |= *read_data--; } while (read_data < read_end); *write_data = ((*read_data--) ^ 0x80) << 8; *write_data |= *read_data--; write_data_a = write_data + (dloop_length >> 1); *write_data_a-- = *write_data; write_data++; write_data_b = write_data + (dloop_length >> 1); read_end = data + gus_sample->loop_start; do { *write_data = ((*read_data--) ^ 0x80) << 8; *write_data |= *read_data--; *write_data_a-- = *write_data; *write_data_b++ = *write_data; write_data++; } while (read_data < read_end); *write_data = ((*read_data--) ^ 0x80) << 8; *write_data |= *read_data--; *write_data_b++ = *write_data; read_end = data - 1; do { *write_data_b = ((*read_data--) ^ 0x80) << 8; *write_data_b++ |= *read_data--; } while (read_data < read_end); gus_sample->loop_start += loop_length; gus_sample->loop_end += dloop_length; gus_sample->data_length = new_length; gus_sample->modes ^= SAMPLE_PINGPONG | SAMPLE_REVERSE | SAMPLE_UNSIGNED; return 0; } _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse sample", errno); return -1; } /* sample loading */ struct _sample * _WM_load_gus_pat(const char *filename, int fix_release) { unsigned char *gus_patch; unsigned long int gus_size; unsigned long int gus_ptr; unsigned char no_of_samples; struct _sample *gus_sample = NULL; struct _sample *first_gus_sample = NULL; unsigned long int i = 0; int (*do_convert[])(unsigned char *data, struct _sample *gus_sample) = { convert_8s, convert_16s, convert_8u, convert_16u, convert_8sp, convert_16sp, convert_8up, convert_16up, convert_8sr, convert_16sr, convert_8ur, convert_16ur, convert_8srp, convert_16srp, convert_8urp, convert_16urp }; unsigned long int tmp_loop; SAMPLE_CONVERT_DEBUG(__FUNCTION__); SAMPLE_CONVERT_DEBUG(filename); if ((gus_patch = _WM_BufferFile(filename, &gus_size)) == NULL) { return NULL; } if (gus_size < 239) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(too short)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, 0); free(gus_patch); return NULL; } if (memcmp(gus_patch, "GF1PATCH110\0ID#000002", 22) && memcmp(gus_patch, "GF1PATCH100\0ID#000002", 22)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(unsupported format)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, 0); free(gus_patch); return NULL; } if (gus_patch[82] > 1) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(unsupported format)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, 0); free(gus_patch); return NULL; } if (gus_patch[151] > 1) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(unsupported format)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, 0); free(gus_patch); return NULL; } GUSPAT_FILENAME_DEBUG(filename); GUSPAT_INT_DEBUG("voices",gus_patch[83]); no_of_samples = gus_patch[198]; gus_ptr = 239; while (no_of_samples) { unsigned long int tmp_cnt; if (first_gus_sample == NULL) { first_gus_sample = malloc(sizeof(struct _sample)); gus_sample = first_gus_sample; } else { gus_sample->next = malloc(sizeof(struct _sample)); gus_sample = gus_sample->next; } if (gus_sample == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, filename, 0); free(gus_patch); return NULL; } gus_sample->next = NULL; gus_sample->loop_fraction = gus_patch[gus_ptr + 7]; gus_sample->data_length = (gus_patch[gus_ptr + 11] << 24) | (gus_patch[gus_ptr + 10] << 16) | (gus_patch[gus_ptr + 9] << 8) | gus_patch[gus_ptr + 8]; gus_sample->loop_start = (gus_patch[gus_ptr + 15] << 24) | (gus_patch[gus_ptr + 14] << 16) | (gus_patch[gus_ptr + 13] << 8) | gus_patch[gus_ptr + 12]; gus_sample->loop_end = (gus_patch[gus_ptr + 19] << 24) | (gus_patch[gus_ptr + 18] << 16) | (gus_patch[gus_ptr + 17] << 8) | gus_patch[gus_ptr + 16]; gus_sample->rate = (gus_patch[gus_ptr + 21] << 8) | gus_patch[gus_ptr + 20]; gus_sample->freq_low = ((gus_patch[gus_ptr + 25] << 24) | (gus_patch[gus_ptr + 24] << 16) | (gus_patch[gus_ptr + 23] << 8) | gus_patch[gus_ptr + 22]); gus_sample->freq_high = ((gus_patch[gus_ptr + 29] << 24) | (gus_patch[gus_ptr + 28] << 16) | (gus_patch[gus_ptr + 27] << 8) | gus_patch[gus_ptr + 26]); gus_sample->freq_root = ((gus_patch[gus_ptr + 33] << 24) | (gus_patch[gus_ptr + 32] << 16) | (gus_patch[gus_ptr + 31] << 8) | gus_patch[gus_ptr + 30]); /* This is done this way instead of ((freq * 1024) / rate) to avoid 32bit overflow. */ /* Result is 0.001% inacurate */ gus_sample->inc_div = ((gus_sample->freq_root * 512) / gus_sample->rate) * 2; #if 0 /* We dont use this info at this time, kept in here for info */ printf("\rTremolo Sweep: %i, Rate: %i, Depth %i\n", gus_patch[gus_ptr+49], gus_patch[gus_ptr+50], gus_patch[gus_ptr+51]); printf("\rVibrato Sweep: %i, Rate: %i, Depth %i\n", gus_patch[gus_ptr+52], gus_patch[gus_ptr+53], gus_patch[gus_ptr+54]); #endif gus_sample->modes = gus_patch[gus_ptr + 55]; GUSPAT_START_DEBUG(); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_16BIT, "16bit "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_UNSIGNED, "Unsigned "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_LOOP, "Loop "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_PINGPONG, "PingPong "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_REVERSE, "Reverse "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_SUSTAIN, "Sustain "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_ENVELOPE, "Envelope "); GUSPAT_MODE_DEBUG(gus_patch[gus_ptr+55], SAMPLE_CLAMPED, "Clamped "); GUSPAT_END_DEBUG(); if (gus_sample->loop_start > gus_sample->loop_end) { tmp_loop = gus_sample->loop_end; gus_sample->loop_end = gus_sample->loop_start; gus_sample->loop_start = tmp_loop; gus_sample->loop_fraction = ((gus_sample->loop_fraction & 0x0f) << 4) | ((gus_sample->loop_fraction & 0xf0) >> 4); } /* FIXME: Experimental Hacky Fix */ if (fix_release) { if (env_time_table[gus_patch[gus_ptr + 40]] < env_time_table[gus_patch[gus_ptr + 41]]) { unsigned char tmp_hack_rate = gus_patch[gus_ptr + 41]; gus_patch[gus_ptr + 41] = gus_patch[gus_ptr + 40]; gus_patch[gus_ptr + 40] = tmp_hack_rate; } } for (i = 0; i < 6; i++) { if (gus_sample->modes & SAMPLE_ENVELOPE) { unsigned char env_rate = gus_patch[gus_ptr + 37 + i]; gus_sample->env_target[i] = 16448 * gus_patch[gus_ptr + 43 + i]; GUSPAT_INT_DEBUG("Envelope Level",gus_patch[gus_ptr+43+i]); GUSPAT_FLOAT_DEBUG("Envelope Time",env_time_table[env_rate]); gus_sample->env_rate[i] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * env_time_table[env_rate])); GUSPAT_INT_DEBUG("Envelope Rate",gus_sample->env_rate[i]); GUSPAT_INT_DEBUG("GUSPAT Rate",env_rate); if (gus_sample->env_rate[i] == 0) { _WM_ERROR_NEW("%s: Warning: found invalid envelope(%lu) rate setting in %s. Using %f instead.", __FUNCTION__, i, filename, env_time_table[63]); gus_sample->env_rate[i] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * env_time_table[63])); GUSPAT_FLOAT_DEBUG("Envelope Time",env_time_table[63]); } } else { gus_sample->env_target[i] = 4194303; gus_sample->env_rate[i] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * env_time_table[63])); GUSPAT_FLOAT_DEBUG("Envelope Time",env_time_table[63]); } } gus_sample->env_target[6] = 0; gus_sample->env_rate[6] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * env_time_table[63])); gus_ptr += 96; tmp_cnt = gus_sample->data_length; if (do_convert[(((gus_sample->modes & 0x18) >> 1) | (gus_sample->modes & 0x03))](&gus_patch[gus_ptr], gus_sample) == -1) { free(gus_patch); return NULL; } gus_ptr += tmp_cnt; gus_sample->loop_start = (gus_sample->loop_start << 10) | (((gus_sample->loop_fraction & 0x0f) << 10) / 16); gus_sample->loop_end = (gus_sample->loop_end << 10) | (((gus_sample->loop_fraction & 0xf0) << 6) / 16); gus_sample->loop_size = gus_sample->loop_end - gus_sample->loop_start; gus_sample->data_length = gus_sample->data_length << 10; no_of_samples--; } free(gus_patch); return first_gus_sample; } wildmidi-wildmidi-0.3.8/src/internal_midi.c000066400000000000000000000043261245740225500207100ustar00rootroot00000000000000/* internal_midi.c Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include #include "internal_midi.h" struct _event { void (*do_event)(struct _mdi *mdi, struct _event_data *data); unsigned long int event_data; unsigned long int samples_to_next; unsigned long int samples_to_next_fixed; }; struct _event_list { struct _event *events; struct _event *current_event; unsigned long int event_count; }; void free_event_list(struct _event_list *event_list) { if (event_list) { free(event_list->events); free(event_list); } } struct _event_list *add_event(struct _event_list *event_list, void (*do_event)(struct _mdi *mdi, struct _event_data *data), unsigned long int event_data) { struct _event *tmp_events = NULL; if (!event_list) { if (!(event_list = malloc(sizeof(struct _event_list)))) { /* TODO: ERROR */ return NULL; } event_list->events = NULL; event_list->current_event = NULL; event_list->event_count = 0; } if (!(tmp_events = realloc(event_list->events, ((event_list->event_count + 1) * sizeof(struct _event))))) { free_event_list(event_list); return NULL; } event_list->events = tmp_events; event_list->events[event_list->event_count]->do_event = do_event; event_list->events[event_list->event_count]->event_data = event_data; event_list->event_count++; return event_list; } wildmidi-wildmidi-0.3.8/src/lock.c000066400000000000000000000040571245740225500170230ustar00rootroot00000000000000/* lock.c - data locking code for lib Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #ifndef __DJGPP__ #ifdef _WIN32 #include #else #define _GNU_SOURCE #include #endif #include "lock.h" #include "common.h" /* _WM_Lock(wmlock) wmlock = a pointer to a value returns nothing Attempts to set a lock on the MDI tree so that only 1 library command may access it at any time. If lock fails the process retries until successful. */ void _WM_Lock(int * wmlock) { LOCK_START: /* Check if lock is clear, if so set it */ if (__builtin_expect(((*wmlock) == 0), 1)) { (*wmlock)++; /* Now that the lock is set, make sure we * don't have a race condition. If so, * decrement the lock by one and retry. */ if (__builtin_expect(((*wmlock) == 1), 1)) { return; /* Lock cleanly set */ } (*wmlock)--; } #ifdef _WIN32 Sleep(10); #else usleep(500); #endif goto LOCK_START; } /* _WM_Unlock(wmlock) wmlock = a pointer to a value returns nothing Removes a lock previously placed on the MDI tree. */ void _WM_Unlock(int *wmlock) { /* We don't want a -1 lock, so just to make sure */ if ((*wmlock) != 0) { (*wmlock)--; } } #endif /* __DJGPP__ */ wildmidi-wildmidi-0.3.8/src/reverb.c000066400000000000000000000262401245740225500173560ustar00rootroot00000000000000/* reverb.c Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #include #include #include "common.h" #include "reverb.h" /* reverb function */ void _WM_reset_reverb(struct _rvb *rvb) { int i, j, k; for (i = 0; i < rvb->l_buf_size; i++) { rvb->l_buf[i] = 0; } for (i = 0; i < rvb->r_buf_size; i++) { rvb->r_buf[i] = 0; } for (k = 0; k < 8; k++) { for (i = 0; i < 6; i++) { for (j = 0; j < 2; j++) { rvb->l_buf_flt_in[k][i][j] = 0; rvb->l_buf_flt_out[k][i][j] = 0; rvb->r_buf_flt_in[k][i][j] = 0; rvb->r_buf_flt_out[k][i][j] = 0; } } } } /* _WM_init_reverb ========================= Engine Description 8 reflective points around the room 2 speaker positions 1 listener position Sounds come from the speakers to all points and to the listener. Sound comes from the reflective points to the listener. These sounds are combined, put through a filter that mimics surface absorbtion. The combined sounds are also sent to the reflective points on the opposite side. */ struct _rvb * _WM_init_reverb(int rate, float room_x, float room_y, float listen_x, float listen_y) { /* filters set at 125Hz, 250Hz, 500Hz, 1000Hz, 2000Hz, 4000Hz */ double Freq[] = {125.0, 250.0, 500.0, 1000.0, 2000.0, 4000.0}; /* numbers calculated from * 101.325 kPa, 20 deg C, 50% relative humidity */ double dbAirAbs[] = {-0.00044, -0.00131, -0.002728, -0.004665, -0.009887, -0.029665}; /* modify these to adjust the absorption qualities of the surface. * Remember that lower frequencies are less effected by surfaces * Note: I am currently playing with the values and finding the ideal surfaces * for nice default reverb. */ double dbAttn[8][6] = { {-1.839, -6.205, -8.891, -12.059, -15.935, -20.942}, {-0.131, -6.205, -12.059, -20.933, -20.933, -15.944}, {-0.131, -6.205, -12.059, -20.933, -20.933, -15.944}, {-1.839, -6.205, -8.891, -12.059, -15.935, -20.942}, {-1.839, -6.205, -8.891, -12.059, -15.935, -20.942}, {-0.131, -6.205, -12.059, -20.933, -20.933, -15.944}, {-0.131, -6.205, -12.059, -20.933, -20.933, -15.944}, {-1.839, -6.205, -8.891, -12.059, -15.935, -20.942} }; /* double dbAttn[6] = { // concrete covered in carpet // -0.175, -0.537, -1.412, -4.437, -7.959, -7.959 // pleated drapes -0.630, -3.223, -5.849, -12.041, -10.458, -7.959 }; */ /* distance */ double SPL_DST[8] = {0.0}; double SPR_DST[8] = {0.0}; double RFN_DST[8] = {0.0}; double MAXL_DST = 0.0; double MAXR_DST = 0.0; double SPL_LSN_XOFS = 0.0; double SPL_LSN_YOFS = 0.0; double SPL_LSN_DST = 0.0; double SPR_LSN_XOFS = 0.0; double SPR_LSN_YOFS = 0.0; double SPR_LSN_DST = 0.0; struct _rvb *rtn_rvb = malloc(sizeof(struct _rvb)); int j = 0; int i = 0; struct _coord { double x; double y; }; #if 0 struct _coord SPL = {2.5, 5.0}; /* Left Speaker Position */ struct _coord SPR = {7.5, 5.0}; /* Right Speaker Position */ /* position of the reflective points */ struct _coord RFN[] = { { 5.0, 0.0}, { 0.0, 6.66666}, { 0.0, 13.3333}, { 5.0, 20.0}, { 10.0, 20.0}, { 15.0, 13.3333}, { 15.0, 6.66666}, { 10.0, 0.0} }; #else struct _coord SPL; /* Left Speaker Position */ struct _coord SPR; /* Right Speaker Position */ /* position of the reflective points */ struct _coord RFN[8]; SPL.x = room_x / 4.0; SPR.x = room_x / 4.0 * 3.0; SPL.y = room_y / 10.0; SPR.y = room_y / 10.0; RFN[0].x = room_x / 3.0; RFN[0].y = 0.0; RFN[1].x = 0.0; RFN[1].y = room_y / 3.0; RFN[2].x = 0.0; RFN[2].y = room_y / 3.0 * 2.0; RFN[3].x = room_x / 3.0; RFN[3].y = room_y; RFN[4].x = room_x / 3.0 * 2.0; RFN[4].y = room_y; RFN[5].x = room_x; RFN[5].y = room_y / 3.0 * 2.0; RFN[6].x = room_x; RFN[6].y = room_y / 3.0; RFN[7].x = room_x / 3.0 * 2.0; RFN[7].y = 0.0; #endif SPL_LSN_XOFS = SPL.x - listen_x; SPL_LSN_YOFS = SPL.y - listen_y; SPL_LSN_DST = sqrt((SPL_LSN_XOFS * SPL_LSN_XOFS) + (SPL_LSN_YOFS * SPL_LSN_YOFS)); if (SPL_LSN_DST > MAXL_DST) MAXL_DST = SPL_LSN_DST; SPR_LSN_XOFS = SPR.x - listen_x; SPR_LSN_YOFS = SPR.y - listen_y; SPR_LSN_DST = sqrt((SPR_LSN_XOFS * SPR_LSN_XOFS) + (SPR_LSN_YOFS * SPR_LSN_YOFS)); if (SPR_LSN_DST > MAXR_DST) MAXR_DST = SPR_LSN_DST; if (rtn_rvb == NULL) { return NULL; } for (j = 0; j < 8; j++) { double SPL_RFL_XOFS = 0; double SPL_RFL_YOFS = 0; double SPR_RFL_XOFS = 0; double SPR_RFL_YOFS = 0; double RFN_XOFS = listen_x - RFN[j].x; double RFN_YOFS = listen_y - RFN[j].y; RFN_DST[j] = sqrt((RFN_XOFS * RFN_XOFS) + (RFN_YOFS * RFN_YOFS)); SPL_RFL_XOFS = SPL.x - RFN[i].x; SPL_RFL_YOFS = SPL.y - RFN[i].y; SPR_RFL_XOFS = SPR.x - RFN[i].x; SPR_RFL_YOFS = SPR.y - RFN[i].y; SPL_DST[i] = sqrt( (SPL_RFL_XOFS * SPL_RFL_XOFS) + (SPL_RFL_YOFS * SPL_RFL_YOFS)); SPR_DST[i] = sqrt( (SPR_RFL_XOFS * SPR_RFL_XOFS) + (SPR_RFL_YOFS * SPR_RFL_YOFS)); /* add the 2 distances together and remove the speaker to listener distance so we dont have to delay the initial output */ SPL_DST[i] += RFN_DST[i]; /* so i dont have to delay speaker output */ SPL_DST[i] -= SPL_LSN_DST; if (i < 4) { if (SPL_DST[i] > MAXL_DST) MAXL_DST = SPL_DST[i]; } else { if (SPL_DST[i] > MAXR_DST) MAXR_DST = SPL_DST[i]; } SPR_DST[i] += RFN_DST[i]; /* so i dont have to delay speaker output */ SPR_DST[i] -= SPR_LSN_DST; if (i < 4) { if (SPR_DST[i] > MAXL_DST) MAXL_DST = SPR_DST[i]; } else { if (SPR_DST[i] > MAXR_DST) MAXR_DST = SPR_DST[i]; } RFN_DST[j] *= 2.0; if (j < 4) { if (RFN_DST[j] > MAXL_DST) MAXL_DST = RFN_DST[j]; } else { if (RFN_DST[j] > MAXR_DST) MAXR_DST = RFN_DST[j]; } for (i = 0; i < 6; i++) { double srate = (double) rate; double bandwidth = 2.0; double omega = 2.0 * M_PI * Freq[i] / srate; double sn = sin(omega); double cs = cos(omega); double alpha = sn * sinh(M_LN2 / 2 * bandwidth * omega / sn); double A = pow(10.0, ((/*dbAttn[i]*/dbAttn[j][i] + (dbAirAbs[i] * RFN_DST[j])) / 40.0) ); /* Peaking band EQ filter */ double b0 = 1 + (alpha * A); double b1 = -2 * cs; double b2 = 1 - (alpha * A); double a0 = 1 + (alpha / A); double a1 = -2 * cs; double a2 = 1 - (alpha / A); rtn_rvb->coeff[j][i][0] = (signed long int) ((b0 / a0) * 1024.0); rtn_rvb->coeff[j][i][1] = (signed long int) ((b1 / a0) * 1024.0); rtn_rvb->coeff[j][i][2] = (signed long int) ((b2 / a0) * 1024.0); rtn_rvb->coeff[j][i][3] = (signed long int) ((a1 / a0) * 1024.0); rtn_rvb->coeff[j][i][4] = (signed long int) ((a2 / a0) * 1024.0); } } /* init the reverb buffers */ rtn_rvb->l_buf_size = (int) ((float) rate * (MAXL_DST / 340.29)); rtn_rvb->l_buf = malloc( sizeof(signed long int) * (rtn_rvb->l_buf_size + 1)); rtn_rvb->l_out = 0; rtn_rvb->r_buf_size = (int) ((float) rate * (MAXR_DST / 340.29)); rtn_rvb->r_buf = malloc( sizeof(signed long int) * (rtn_rvb->r_buf_size + 1)); rtn_rvb->r_out = 0; for (i = 0; i < 4; i++) { rtn_rvb->l_sp_in[i] = (int) ((float) rate * (SPL_DST[i] / 340.29)); rtn_rvb->l_sp_in[i + 4] = (int) ((float) rate * (SPL_DST[i + 4] / 340.29)); rtn_rvb->r_sp_in[i] = (int) ((float) rate * (SPR_DST[i] / 340.29)); rtn_rvb->r_sp_in[i + 4] = (int) ((float) rate * (SPR_DST[i + 4] / 340.29)); rtn_rvb->l_in[i] = (int) ((float) rate * (RFN_DST[i] / 340.29)); rtn_rvb->r_in[i] = (int) ((float) rate * (RFN_DST[i + 4] / 340.29)); } rtn_rvb->gain = 4; _WM_reset_reverb(rtn_rvb); return rtn_rvb; } /* _WM_free_reverb - free up memory used for reverb */ void _WM_free_reverb(struct _rvb *rvb) { if (!rvb) return; free(rvb->l_buf); free(rvb->r_buf); free(rvb); } void _WM_do_reverb(struct _rvb *rvb, signed long int *buffer, int size) { int i, j, k; signed long int l_buf_flt = 0; signed long int r_buf_flt = 0; signed long int l_rfl = 0; signed long int r_rfl = 0; int vol_div = 64; for (i = 0; i < size; i += 2) { signed long int tmp_l_val = 0; signed long int tmp_r_val = 0; /* add the initial reflections from each speaker, 4 to go the left, 4 go to the right buffers */ tmp_l_val = buffer[i] / vol_div; tmp_r_val = buffer[i + 1] / vol_div; for (j = 0; j < 4; j++) { rvb->l_buf[rvb->l_sp_in[j]] += tmp_l_val; rvb->l_sp_in[j] = (rvb->l_sp_in[j] + 1) % rvb->l_buf_size; rvb->l_buf[rvb->r_sp_in[j]] += tmp_r_val; rvb->r_sp_in[j] = (rvb->r_sp_in[j] + 1) % rvb->l_buf_size; rvb->r_buf[rvb->l_sp_in[j + 4]] += tmp_l_val; rvb->l_sp_in[j + 4] = (rvb->l_sp_in[j + 4] + 1) % rvb->r_buf_size; rvb->r_buf[rvb->r_sp_in[j + 4]] += tmp_r_val; rvb->r_sp_in[j + 4] = (rvb->r_sp_in[j + 4] + 1) % rvb->r_buf_size; } /* filter the reverb output and add to buffer */ l_rfl = rvb->l_buf[rvb->l_out]; rvb->l_buf[rvb->l_out] = 0; rvb->l_out = (rvb->l_out + 1) % rvb->l_buf_size; r_rfl = rvb->r_buf[rvb->r_out]; rvb->r_buf[rvb->r_out] = 0; rvb->r_out = (rvb->r_out + 1) % rvb->r_buf_size; for (k = 0; k < 8; k++) { for (j = 0; j < 6; j++) { l_buf_flt = ((l_rfl * rvb->coeff[k][j][0]) + (rvb->l_buf_flt_in[k][j][0] * rvb->coeff[k][j][1]) + (rvb->l_buf_flt_in[k][j][1] * rvb->coeff[k][j][2]) - (rvb->l_buf_flt_out[k][j][0] * rvb->coeff[k][j][3]) - (rvb->l_buf_flt_out[k][j][1] * rvb->coeff[k][j][4])) / 1024; rvb->l_buf_flt_in[k][j][1] = rvb->l_buf_flt_in[k][j][0]; rvb->l_buf_flt_in[k][j][0] = l_rfl; rvb->l_buf_flt_out[k][j][1] = rvb->l_buf_flt_out[k][j][0]; rvb->l_buf_flt_out[k][j][0] = l_buf_flt; buffer[i] += l_buf_flt / 8; r_buf_flt = ((r_rfl * rvb->coeff[k][j][0]) + (rvb->r_buf_flt_in[k][j][0] * rvb->coeff[k][j][1]) + (rvb->r_buf_flt_in[k][j][1] * rvb->coeff[k][j][2]) - (rvb->r_buf_flt_out[k][j][0] * rvb->coeff[k][j][3]) - (rvb->r_buf_flt_out[k][j][1] * rvb->coeff[k][j][4])) / 1024; rvb->r_buf_flt_in[k][j][1] = rvb->r_buf_flt_in[k][j][0]; rvb->r_buf_flt_in[k][j][0] = r_rfl; rvb->r_buf_flt_out[k][j][1] = rvb->r_buf_flt_out[k][j][0]; rvb->r_buf_flt_out[k][j][0] = r_buf_flt; buffer[i + 1] += r_buf_flt / 8; } } /* add filtered result back into the buffers but on the opposite side */ tmp_l_val = buffer[i + 1] / vol_div; tmp_r_val = buffer[i] / vol_div; for (j = 0; j < 4; j++) { rvb->l_buf[rvb->l_in[j]] += tmp_l_val; rvb->l_in[j] = (rvb->l_in[j] + 1) % rvb->l_buf_size; rvb->r_buf[rvb->r_in[j]] += tmp_r_val; rvb->r_in[j] = (rvb->r_in[j] + 1) % rvb->r_buf_size; } } } wildmidi-wildmidi-0.3.8/src/wildmidi.c000066400000000000000000001211731245740225500176740ustar00rootroot00000000000000/* wildmidi.c Midi Player using the WildMidi Midi Processing Library Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #include #include #include #include #include #include #include #include #if defined(__DJGPP__) #include "getopt_long.h" #include #define getopt dj_getopt /* hack */ #include #undef getopt #define msleep(s) usleep((s)*1000) #include #ifdef AUDIODRV_DOSSB #include "dossb.h" #endif #endif #if (defined _WIN32) || (defined __CYGWIN__) #include #include #include #define msleep(s) Sleep((s)) #include #undef close #define close _close #undef open #define open _open #undef read #define read _read #undef write #define write _write #undef lseek #define lseek _lseek #include "getopt_long.h" #endif #if !defined(_WIN32) && !defined(__DJGPP__) /* unix build */ static int msleep(unsigned long millisec); #include #include #include #include #ifdef AUDIODRV_ALSA # include #elif defined AUDIODRV_OSS # if defined HAVE_SYS_SOUNDCARD_H # include # elif defined HAVE_MACHINE_SOUNDCARD_H # include # elif defined HAVE_SOUNDCARD_H # include /* less common, but exists. */ # endif #elif defined AUDIODRV_OPENAL # include # include #endif #endif /* !_WIN32, !__DJGPP__ (unix build) */ #include "wildmidi_lib.h" #include "wm_tty.h" #include "filenames.h" struct _midi_test { unsigned char *data; unsigned long int size; }; /* scale test from 0 to 127 * test a * offset 18-21 (0x12-0x15) - track size * offset 25 (0x1A) = bank number * offset 28 (0x1D) = patch number */ static unsigned char midi_test_c_scale[] = { 0x4d, 0x54, 0x68, 0x64, 0x00, 0x00, 0x00, 0x06, /* 0x00 */ 0x00, 0x00, 0x00, 0x01, 0x00, 0x06, 0x4d, 0x54, /* 0x08 */ 0x72, 0x6b, 0x00, 0x00, 0x02, 0x63, 0x00, 0xb0, /* 0x10 */ 0x00, 0x00, 0x00, 0xC0, 0x00, 0x00, 0x90, 0x00, /* 0x18 C */ 0x64, 0x08, 0x80, 0x00, 0x00, 0x08, 0x90, 0x02, /* 0x20 D */ 0x64, 0x08, 0x80, 0x02, 0x00, 0x08, 0x90, 0x04, /* 0x28 E */ 0x64, 0x08, 0x80, 0x04, 0x00, 0x08, 0x90, 0x05, /* 0x30 F */ 0x64, 0x08, 0x80, 0x05, 0x00, 0x08, 0x90, 0x07, /* 0x38 G */ 0x64, 0x08, 0x80, 0x07, 0x00, 0x08, 0x90, 0x09, /* 0x40 A */ 0x64, 0x08, 0x80, 0x09, 0x00, 0x08, 0x90, 0x0b, /* 0x48 B */ 0x64, 0x08, 0x80, 0x0b, 0x00, 0x08, 0x90, 0x0c, /* 0x50 C */ 0x64, 0x08, 0x80, 0x0c, 0x00, 0x08, 0x90, 0x0e, /* 0x58 D */ 0x64, 0x08, 0x80, 0x0e, 0x00, 0x08, 0x90, 0x10, /* 0x60 E */ 0x64, 0x08, 0x80, 0x10, 0x00, 0x08, 0x90, 0x11, /* 0x68 F */ 0x64, 0x08, 0x80, 0x11, 0x00, 0x08, 0x90, 0x13, /* 0x70 G */ 0x64, 0x08, 0x80, 0x13, 0x00, 0x08, 0x90, 0x15, /* 0x78 A */ 0x64, 0x08, 0x80, 0x15, 0x00, 0x08, 0x90, 0x17, /* 0x80 B */ 0x64, 0x08, 0x80, 0x17, 0x00, 0x08, 0x90, 0x18, /* 0x88 C */ 0x64, 0x08, 0x80, 0x18, 0x00, 0x08, 0x90, 0x1a, /* 0x90 D */ 0x64, 0x08, 0x80, 0x1a, 0x00, 0x08, 0x90, 0x1c, /* 0x98 E */ 0x64, 0x08, 0x80, 0x1c, 0x00, 0x08, 0x90, 0x1d, /* 0xA0 F */ 0x64, 0x08, 0x80, 0x1d, 0x00, 0x08, 0x90, 0x1f, /* 0xA8 G */ 0x64, 0x08, 0x80, 0x1f, 0x00, 0x08, 0x90, 0x21, /* 0xB0 A */ 0x64, 0x08, 0x80, 0x21, 0x00, 0x08, 0x90, 0x23, /* 0xB8 B */ 0x64, 0x08, 0x80, 0x23, 0x00, 0x08, 0x90, 0x24, /* 0xC0 C */ 0x64, 0x08, 0x80, 0x24, 0x00, 0x08, 0x90, 0x26, /* 0xC8 D */ 0x64, 0x08, 0x80, 0x26, 0x00, 0x08, 0x90, 0x28, /* 0xD0 E */ 0x64, 0x08, 0x80, 0x28, 0x00, 0x08, 0x90, 0x29, /* 0xD8 F */ 0x64, 0x08, 0x80, 0x29, 0x00, 0x08, 0x90, 0x2b, /* 0xE0 G */ 0x64, 0x08, 0x80, 0x2b, 0x00, 0x08, 0x90, 0x2d, /* 0xE8 A */ 0x64, 0x08, 0x80, 0x2d, 0x00, 0x08, 0x90, 0x2f, /* 0xF0 B */ 0x64, 0x08, 0x80, 0x2f, 0x00, 0x08, 0x90, 0x30, /* 0xF8 C */ 0x64, 0x08, 0x80, 0x30, 0x00, 0x08, 0x90, 0x32, /* 0x100 D */ 0x64, 0x08, 0x80, 0x32, 0x00, 0x08, 0x90, 0x34, /* 0x108 E */ 0x64, 0x08, 0x80, 0x34, 0x00, 0x08, 0x90, 0x35, /* 0x110 F */ 0x64, 0x08, 0x80, 0x35, 0x00, 0x08, 0x90, 0x37, /* 0x118 G */ 0x64, 0x08, 0x80, 0x37, 0x00, 0x08, 0x90, 0x39, /* 0x120 A */ 0x64, 0x08, 0x80, 0x39, 0x00, 0x08, 0x90, 0x3b, /* 0X128 B */ 0x64, 0x08, 0x80, 0x3b, 0x00, 0x08, 0x90, 0x3c, /* 0x130 C */ 0x64, 0x08, 0x80, 0x3c, 0x00, 0x08, 0x90, 0x3e, /* 0x138 D */ 0x64, 0x08, 0x80, 0x3e, 0x00, 0x08, 0x90, 0x40, /* 0X140 E */ 0x64, 0x08, 0x80, 0x40, 0x00, 0x08, 0x90, 0x41, /* 0x148 F */ 0x64, 0x08, 0x80, 0x41, 0x00, 0x08, 0x90, 0x43, /* 0x150 G */ 0x64, 0x08, 0x80, 0x43, 0x00, 0x08, 0x90, 0x45, /* 0x158 A */ 0x64, 0x08, 0x80, 0x45, 0x00, 0x08, 0x90, 0x47, /* 0x160 B */ 0x64, 0x08, 0x80, 0x47, 0x00, 0x08, 0x90, 0x48, /* 0x168 C */ 0x64, 0x08, 0x80, 0x48, 0x00, 0x08, 0x90, 0x4a, /* 0x170 D */ 0x64, 0x08, 0x80, 0x4a, 0x00, 0x08, 0x90, 0x4c, /* 0x178 E */ 0x64, 0x08, 0x80, 0x4c, 0x00, 0x08, 0x90, 0x4d, /* 0x180 F */ 0x64, 0x08, 0x80, 0x4d, 0x00, 0x08, 0x90, 0x4f, /* 0x188 G */ 0x64, 0x08, 0x80, 0x4f, 0x00, 0x08, 0x90, 0x51, /* 0x190 A */ 0x64, 0x08, 0x80, 0x51, 0x00, 0x08, 0x90, 0x53, /* 0x198 B */ 0x64, 0x08, 0x80, 0x53, 0x00, 0x08, 0x90, 0x54, /* 0x1A0 C */ 0x64, 0x08, 0x80, 0x54, 0x00, 0x08, 0x90, 0x56, /* 0x1A8 D */ 0x64, 0x08, 0x80, 0x56, 0x00, 0x08, 0x90, 0x58, /* 0x1B0 E */ 0x64, 0x08, 0x80, 0x58, 0x00, 0x08, 0x90, 0x59, /* 0x1B8 F */ 0x64, 0x08, 0x80, 0x59, 0x00, 0x08, 0x90, 0x5b, /* 0x1C0 G */ 0x64, 0x08, 0x80, 0x5b, 0x00, 0x08, 0x90, 0x5d, /* 0x1C8 A */ 0x64, 0x08, 0x80, 0x5d, 0x00, 0x08, 0x90, 0x5f, /* 0x1D0 B */ 0x64, 0x08, 0x80, 0x5f, 0x00, 0x08, 0x90, 0x60, /* 0x1D8 C */ 0x64, 0x08, 0x80, 0x60, 0x00, 0x08, 0x90, 0x62, /* 0x1E0 D */ 0x64, 0x08, 0x80, 0x62, 0x00, 0x08, 0x90, 0x64, /* 0x1E8 E */ 0x64, 0x08, 0x80, 0x64, 0x00, 0x08, 0x90, 0x65, /* 0x1F0 F */ 0x64, 0x08, 0x80, 0x65, 0x00, 0x08, 0x90, 0x67, /* 0x1F8 G */ 0x64, 0x08, 0x80, 0x67, 0x00, 0x08, 0x90, 0x69, /* 0x200 A */ 0x64, 0x08, 0x80, 0x69, 0x00, 0x08, 0x90, 0x6b, /* 0x208 B */ 0x64, 0x08, 0x80, 0x6b, 0x00, 0x08, 0x90, 0x6c, /* 0x210 C */ 0x64, 0x08, 0x80, 0x6c, 0x00, 0x08, 0x90, 0x6e, /* 0x218 D */ 0x64, 0x08, 0x80, 0x6e, 0x00, 0x08, 0x90, 0x70, /* 0x220 E */ 0x64, 0x08, 0x80, 0x70, 0x00, 0x08, 0x90, 0x71, /* 0x228 F */ 0x64, 0x08, 0x80, 0x71, 0x00, 0x08, 0x90, 0x73, /* 0x230 G */ 0x64, 0x08, 0x80, 0x73, 0x00, 0x08, 0x90, 0x75, /* 0x238 A */ 0x64, 0x08, 0x80, 0x75, 0x00, 0x08, 0x90, 0x77, /* 0x240 B */ 0x64, 0x08, 0x80, 0x77, 0x00, 0x08, 0x90, 0x78, /* 0x248 C */ 0x64, 0x08, 0x80, 0x78, 0x00, 0x08, 0x90, 0x7a, /* 0x250 D */ 0x64, 0x08, 0x80, 0x7a, 0x00, 0x08, 0x90, 0x7c, /* 0x258 E */ 0x64, 0x08, 0x80, 0x7c, 0x00, 0x08, 0x90, 0x7d, /* 0x260 F */ 0x64, 0x08, 0x80, 0x7d, 0x00, 0x08, 0x90, 0x7f, /* 0x268 G */ 0x64, 0x08, 0x80, 0x7f, 0x00, 0x08, 0xff, 0x2f, /* 0x270 */ 0x00 /* 0x278 */ }; static struct _midi_test midi_test[] = { { midi_test_c_scale, 663 }, { NULL, 0 } }; static int midi_test_max = 1; /* ============================== Audio Output Functions We have two 'drivers': first is the wav file writer which is always available. the second, if it is really compiled in, is the system audio output driver. only _one of the two_ can be active, not both. ============================== */ static unsigned int rate = 32072; static int (*send_output)(char * output_data, int output_size); static void (*close_output)(void); static void (*pause_output)(void); static void (*resume_output)(void); static int audio_fd = -1; static void pause_output_nop(void) { } static void resume_output_nop(void) { } /* Wav Output Functions */ static char wav_file[1024]; #if (INT_MAX == 2147483647) static unsigned int wav_size; #else static unsigned long int wav_size; #endif static int write_wav_output(char * output_data, int output_size); static void close_wav_output(void); static int open_wav_output(void) { unsigned char wav_hdr[] = { 0x52, 0x49, 0x46, 0x46, /* "RIFF" */ 0x00, 0x00, 0x00, 0x00, /* riffsize: pcm size + 36 (filled when closing.) */ 0x57, 0x41, 0x56, 0x45, /* "WAVE" */ 0x66, 0x6D, 0x74, 0x20, /* "fmt " */ 0x10, 0x00, 0x00, 0x00, /* length of this RIFF block: 16 */ 0x01, 0x00, /* wave format == 1 (WAVE_FORMAT_PCM) */ 0x02, 0x00, /* channels == 2 */ 0x00, 0x00, 0x00, 0x00, /* sample rate (filled below) */ 0x00, 0x00, 0x00, 0x00, /* bytes_per_sec: rate * channels * format bytes */ 0x04, 0x00, /* block alignment: channels * format bytes == 4 */ 0x10, 0x00, /* format bits == 16 */ 0x64, 0x61, 0x74, 0x61, /* "data" */ 0x00, 0x00, 0x00, 0x00 /* datasize: the pcm size (filled when closing.) */ }; if (wav_file[0] == '\0') return (-1); #if defined(_WIN32) || defined(__DJGPP__) audio_fd = open(wav_file, (O_RDWR | O_CREAT | O_TRUNC | O_BINARY), 0664); #else audio_fd = open(wav_file, (O_RDWR | O_CREAT | O_TRUNC), (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH)); #endif if (audio_fd < 0) { fprintf(stderr, "Error: unable to open file for writing (%s)\r\n", strerror(errno)); return (-1); } else { unsigned long int bytes_per_sec; wav_hdr[24] = (rate) & 0xFF; wav_hdr[25] = (rate >> 8) & 0xFF; bytes_per_sec = rate * 4; wav_hdr[28] = (bytes_per_sec) & 0xFF; wav_hdr[29] = (bytes_per_sec >> 8) & 0xFF; wav_hdr[30] = (bytes_per_sec >> 16) & 0xFF; wav_hdr[31] = (bytes_per_sec >> 24) & 0xFF; } if (write(audio_fd, &wav_hdr, 44) < 0) { fprintf(stderr, "ERROR: failed writing wav header (%s)\r\n", strerror(errno)); close(audio_fd); audio_fd = -1; return (-1); } wav_size = 0; send_output = write_wav_output; close_output = close_wav_output; pause_output = pause_output_nop; resume_output = resume_output_nop; return (0); } static int write_wav_output(char * output_data, int output_size) { /* the library specifically outputs LE data - no need swapping. */ if (write(audio_fd, output_data, output_size) < 0) { fprintf(stderr, "\nERROR: failed writing wav (%s)\r\n", strerror(errno)); close(audio_fd); audio_fd = -1; return (-1); } wav_size += output_size; return (0); } static void close_wav_output(void) { unsigned char wav_count[4]; if (audio_fd < 0) return; printf("Finishing and closing wav output\r"); wav_count[0] = (wav_size) & 0xFF; wav_count[1] = (wav_size >> 8) & 0xFF; wav_count[2] = (wav_size >> 16) & 0xFF; wav_count[3] = (wav_size >> 24) & 0xFF; lseek(audio_fd, 40, SEEK_SET); if (write(audio_fd, &wav_count, 4) < 0) { fprintf(stderr, "\nERROR: failed writing wav (%s)\r\n", strerror(errno)); goto end; } wav_size += 36; wav_count[0] = (wav_size) & 0xFF; wav_count[1] = (wav_size >> 8) & 0xFF; wav_count[2] = (wav_size >> 16) & 0xFF; wav_count[3] = (wav_size >> 24) & 0xFF; lseek(audio_fd, 4, SEEK_SET); if (write(audio_fd, &wav_count, 4) < 0) { fprintf(stderr, "\nERROR: failed writing wav (%s)\r\n", strerror(errno)); goto end; } end: printf("\n"); if (audio_fd >= 0) close(audio_fd); audio_fd = -1; } #if (defined _WIN32) || (defined __CYGWIN__) static HWAVEOUT hWaveOut = NULL; static CRITICAL_SECTION waveCriticalSection; #define open_audio_output open_mm_output static int write_mm_output (char * output_data, int output_size); static void close_mm_output (void); static WAVEHDR *mm_blocks = NULL; #define MM_BLOCK_SIZE 16384 #define MM_BLOCK_COUNT 3 static DWORD mm_free_blocks = MM_BLOCK_COUNT; static DWORD mm_current_block = 0; #if defined(_MSC_VER) && (_MSC_VER < 1300) typedef DWORD DWORD_PTR; #endif static void CALLBACK mmOutProc (HWAVEOUT hWaveOut, UINT uMsg, DWORD_PTR dwInstance, DWORD_PTR dwParam1, DWORD_PTR dwParam2) { /* unused params */ (void)hWaveOut; (void)dwParam1; (void)dwParam2; if(uMsg != WOM_DONE) return; /* increment mm_free_blocks */ EnterCriticalSection(&waveCriticalSection); (*(DWORD *)dwInstance)++; LeaveCriticalSection(&waveCriticalSection); } static int open_mm_output (void) { WAVEFORMATEX wfx; char *mm_buffer; int i; InitializeCriticalSection(&waveCriticalSection); if((mm_buffer = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ((MM_BLOCK_SIZE + sizeof(WAVEHDR)) * MM_BLOCK_COUNT))) == NULL) { fprintf(stderr, "Memory allocation error\r\n"); return -1; } mm_blocks = (WAVEHDR*)mm_buffer; mm_buffer += sizeof(WAVEHDR) * MM_BLOCK_COUNT; for(i = 0; i < MM_BLOCK_COUNT; i++) { mm_blocks[i].dwBufferLength = MM_BLOCK_SIZE; mm_blocks[i].lpData = mm_buffer; mm_buffer += MM_BLOCK_SIZE; } wfx.nSamplesPerSec = rate; wfx.wBitsPerSample = 16; wfx.nChannels = 2; wfx.cbSize = 0; wfx.wFormatTag = WAVE_FORMAT_PCM; wfx.nBlockAlign = (wfx.wBitsPerSample >> 3) * wfx.nChannels; wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec; if(waveOutOpen(&hWaveOut, WAVE_MAPPER, &wfx, (DWORD_PTR)mmOutProc, (DWORD_PTR)&mm_free_blocks, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { fprintf(stderr, "unable to open WAVE_MAPPER device\r\n"); HeapFree(GetProcessHeap(), 0, mm_blocks); hWaveOut = NULL; mm_blocks = NULL; return -1; } send_output = write_mm_output; close_output = close_mm_output; pause_output = pause_output_nop; resume_output = resume_output_nop; return (0); } static int write_mm_output (char * output_data, int output_size) { WAVEHDR* current; int free_size = 0; int data_read = 0; current = &mm_blocks[mm_current_block]; while (output_size) { if(current->dwFlags & WHDR_PREPARED) waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR)); free_size = MM_BLOCK_SIZE - current->dwUser; if (free_size > output_size) free_size = output_size; memcpy(current->lpData + current->dwUser, &output_data[data_read], free_size); current->dwUser += free_size; output_size -= free_size; data_read += free_size; if (current->dwUser < MM_BLOCK_SIZE) { return (0); } current->dwBufferLength = MM_BLOCK_SIZE; waveOutPrepareHeader(hWaveOut, current, sizeof(WAVEHDR)); waveOutWrite(hWaveOut, current, sizeof(WAVEHDR)); EnterCriticalSection(&waveCriticalSection); mm_free_blocks--; LeaveCriticalSection(&waveCriticalSection); while(!mm_free_blocks) Sleep(10); mm_current_block++; mm_current_block %= MM_BLOCK_COUNT; current = &mm_blocks[mm_current_block]; current->dwUser = 0; } return (0); } static void close_mm_output (void) { int i; if (!hWaveOut) return; printf("Shutting down sound output\r\n"); for (i = 0; i < MM_BLOCK_COUNT; i++) { while (waveOutUnprepareHeader(hWaveOut, &mm_blocks[i], sizeof(WAVEHDR)) == WAVERR_STILLPLAYING) { Sleep(10); } } waveOutClose (hWaveOut); HeapFree(GetProcessHeap(), 0, mm_blocks); hWaveOut = NULL; mm_blocks = NULL; } #elif defined(__DJGPP__) && defined(AUDIODRV_DOSSB) /* SoundBlaster/Pro/16/AWE32 driver for DOS -- adapted from * libMikMod, written by Andrew Zabolotny , * further fixes by O.Sezer . * Timer callback functionality replaced by a push mechanism * to keep the wildmidi player changes to a minimum, for now. */ /* The last buffer byte filled with sound */ static unsigned int buff_tail = 0; static int write_sb_output(char *data, unsigned int siz) { unsigned int dma_size, dma_pos; unsigned int cnt; sb_query_dma(&dma_size, &dma_pos); /* There isn't much sense in filling less than 256 bytes */ dma_pos &= ~255; /* If nothing to mix, quit */ if (buff_tail == dma_pos) return 0; /* If DMA pointer still didn't wrapped around ... */ if (dma_pos > buff_tail) { if ((cnt = dma_pos - buff_tail) > siz) cnt = siz; memcpy(sb.dma_buff->linear + buff_tail, data, cnt); buff_tail += cnt; /* If we arrived right to the DMA buffer end, jump to the beginning */ if (buff_tail >= dma_size) buff_tail = 0; } else { /* If wrapped around, fill first to the end of buffer */ if ((cnt = dma_size - buff_tail) > siz) cnt = siz; memcpy(sb.dma_buff->linear + buff_tail, data, cnt); buff_tail += cnt; siz -= cnt; if (!siz) return cnt; /* Now fill from buffer beginning to current DMA pointer */ if (dma_pos > siz) dma_pos = siz; data += cnt; cnt += dma_pos; memcpy(sb.dma_buff->linear, data, dma_pos); buff_tail = dma_pos; } return cnt; } static int write_sb_s16stereo(char *data, int siz) { /* libWildMidi sint16 stereo -> SB16 sint16 stereo */ int i; while (1) { i = write_sb_output(data, siz); if ((siz -= i) <= 0) return 0; data += i; /*usleep(100);*/ } } static int write_sb_u8stereo(char *data, int siz) { /* libWildMidi sint16 stereo -> SB uint8 stereo */ signed short *src = (signed short *) data; unsigned char *dst = (unsigned char *) data; int i = (siz /= 2); for (; i >= 0; --i) { *dst++ = (*src++ >> 8) + 128; } while (1) { i = write_sb_output(data, siz); if ((siz -= i) <= 0) return 0; data += i; /*usleep(100);*/ } } static int write_sb_u8mono(char *data, int siz) { /* libWildMidi sint16 stereo -> SB uint8 mono */ signed short *src = (signed short *) data; unsigned char *dst = (unsigned char *) data; int i = (siz /= 4); int val; for (; i >= 0; --i) { /* do a cheap (left+right)/2 */ val = *src++; val += *src++; *dst++ = (val >> 9) + 128; } while (1) { i = write_sb_output(data, siz); if ((siz -= i) <= 0) return 0; data += i; /*usleep(100);*/ } } static void sb_silence_s16(void) { memset(sb.dma_buff->linear, 0, sb.dma_buff->size); } static void sb_silence_u8(void) { memset(sb.dma_buff->linear, 0x80, sb.dma_buff->size); } static void close_sb_output(void) { sb.timer_callback = NULL; sb_output(FALSE); sb_stop_dma(); sb_close(); } #define open_audio_output open_sb_output static int open_sb_output(void) { if (!sb_open()) { fprintf(stderr, "Sound Blaster initialization failed.\n"); return -1; } if (rate < 4000) rate = 4000; if (sb.caps & SBMODE_STEREO) { if (rate > sb.maxfreq_stereo) rate = sb.maxfreq_stereo; } else { if (rate > sb.maxfreq_mono) rate = sb.maxfreq_mono; } /* Enable speaker output */ sb_output(TRUE); /* Set our routine to be called during SB IRQs */ buff_tail = 0; sb.timer_callback = NULL;/* see above */ /* Start cyclic DMA transfer */ if (!sb_start_dma(((sb.caps & SBMODE_16BITS) ? SBMODE_16BITS | SBMODE_SIGNED : 0) | (sb.caps & SBMODE_STEREO), rate)) { sb_output(FALSE); sb_close(); fprintf(stderr, "Sound Blaster: DMA start failed.\n"); return -1; } if (sb.caps & SBMODE_16BITS) { /* can do stereo, too */ send_output = write_sb_s16stereo; pause_output = sb_silence_s16; resume_output = resume_output_nop; printf("Sound Blaster 16 or compatible (16 bit, stereo, %u Hz)\n", rate); } else if (sb.caps & SBMODE_STEREO) { send_output = write_sb_u8stereo; pause_output = sb_silence_u8; resume_output = resume_output_nop; printf("Sound Blaster Pro or compatible (8 bit, stereo, %u Hz)\n", rate); } else { send_output = write_sb_u8mono; pause_output = sb_silence_u8; resume_output = resume_output_nop; printf("Sound Blaster %c or compatible (8 bit, mono, %u Hz)\n", (sb.dspver < SBVER_20)? '1' : '2', rate); } close_output = close_sb_output; return 0; } #else #ifdef AUDIODRV_ALSA static int alsa_first_time = 1; static snd_pcm_t *pcm = NULL; static char pcmname[64]; #define open_audio_output open_alsa_output static int write_alsa_output(char * output_data, int output_size); static void close_alsa_output(void); static int open_alsa_output(void) { snd_pcm_hw_params_t *hw; snd_pcm_sw_params_t *sw; int err; unsigned int alsa_buffer_time; unsigned int alsa_period_time; unsigned int r; if (!pcmname[0]) { strcpy(pcmname, "default"); } if ((err = snd_pcm_open(&pcm, pcmname, SND_PCM_STREAM_PLAYBACK, 0)) < 0) { fprintf(stderr, "Error: audio open error: %s\r\n", snd_strerror(err)); return -1; } snd_pcm_hw_params_alloca(&hw); if ((err = snd_pcm_hw_params_any(pcm, hw)) < 0) { fprintf(stderr, "ERROR: No configuration available for playback: %s\r\n", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_access(pcm, hw, SND_PCM_ACCESS_RW_INTERLEAVED)) < 0) { fprintf(stderr, "Cannot set access mode: %s.\r\n", snd_strerror(err)); goto fail; } /* the library specifically outputs LE data. */ if (snd_pcm_hw_params_set_format(pcm, hw, SND_PCM_FORMAT_S16_LE) < 0) { fprintf(stderr, "ALSA does not support 16bit signed audio for your soundcard\r\n"); goto fail; } if (snd_pcm_hw_params_set_channels(pcm, hw, 2) < 0) { fprintf(stderr, "ALSA does not support stereo for your soundcard\r\n"); goto fail; } r = rate; if (snd_pcm_hw_params_set_rate_near(pcm, hw, &rate, 0) < 0) { fprintf(stderr, "ALSA does not support %uHz for your soundcard\r\n", rate); goto fail; } if (r != rate) { fprintf(stderr, "ALSA: sample rate set to %uHz instead of %u\r\n", rate, r); } alsa_buffer_time = 500000; alsa_period_time = 50000; if ((err = snd_pcm_hw_params_set_buffer_time_near(pcm, hw, &alsa_buffer_time, 0)) < 0) { fprintf(stderr, "Set buffer time failed: %s.\r\n", snd_strerror(err)); goto fail; } if ((err = snd_pcm_hw_params_set_period_time_near(pcm, hw, &alsa_period_time, 0)) < 0) { fprintf(stderr, "Set period time failed: %s.\r\n", snd_strerror(err)); goto fail; } if (snd_pcm_hw_params(pcm, hw) < 0) { fprintf(stderr, "Unable to install hw params\r\n"); goto fail; } snd_pcm_sw_params_alloca(&sw); snd_pcm_sw_params_current(pcm, sw); if (snd_pcm_sw_params(pcm, sw) < 0) { fprintf(stderr, "Unable to install sw params\r\n"); goto fail; } send_output = write_alsa_output; close_output = close_alsa_output; pause_output = pause_output_nop; resume_output = resume_output_nop; return (0); fail: close_alsa_output(); return -1; } static int write_alsa_output(char * output_data, int output_size) { int err; snd_pcm_uframes_t frames; while (output_size > 0) { frames = snd_pcm_bytes_to_frames(pcm, output_size); if ((err = snd_pcm_writei(pcm, output_data, frames)) < 0) { if (snd_pcm_state(pcm) == SND_PCM_STATE_XRUN) { if ((err = snd_pcm_prepare(pcm)) < 0) fprintf(stderr, "\nsnd_pcm_prepare() failed.\r\n"); alsa_first_time = 1; continue; } return err; } output_size -= snd_pcm_frames_to_bytes(pcm, err); output_data += snd_pcm_frames_to_bytes(pcm, err); if (alsa_first_time) { alsa_first_time = 0; snd_pcm_start(pcm); } } return (0); } static void close_alsa_output(void) { if (!pcm) return; printf("Shutting down sound output\r\n"); snd_pcm_close(pcm); pcm = NULL; } #elif defined AUDIODRV_OSS #if !defined(AFMT_S16_NE) #ifdef WORDS_BIGENDIAN #define AFMT_S16_NE AFMT_S16_BE #else #define AFMT_S16_NE AFMT_S16_LE #endif #endif #define DEFAULT_FRAGSIZE 14 #define DEFAULT_NUMFRAGS 16 static char pcmname[64]; #define open_audio_output open_oss_output static int write_oss_output(char * output_data, int output_size); static void close_oss_output(void); static void pause_output_oss(void) { ioctl(audio_fd, SNDCTL_DSP_POST, 0); } static int open_oss_output(void) { int tmp; unsigned int r; if (!pcmname[0]) { strcpy(pcmname, "/dev/dsp"); } if ((audio_fd = open(pcmname, O_WRONLY)) < 0) { fprintf(stderr, "ERROR: Unable to open dsp (%s)\r\n", strerror(errno)); return -1; } if (ioctl(audio_fd, SNDCTL_DSP_RESET, 0) < 0) { fprintf(stderr, "ERROR: Unable to reset dsp\r\n"); goto fail; } /* the library specifically outputs LE data. */ tmp = AFMT_S16_LE; if (ioctl(audio_fd, SNDCTL_DSP_SETFMT, &tmp) < 0) { fprintf(stderr, "ERROR: Unable to set 16bit sound format\r\n"); goto fail; } tmp = 2; if (ioctl(audio_fd, SNDCTL_DSP_CHANNELS, &tmp) < 0) { fprintf(stderr, "ERROR: Unable to set stereo\r\n"); goto fail; } r = rate; if (ioctl(audio_fd, SNDCTL_DSP_SPEED, &rate) < 0) { fprintf(stderr, "ERROR: Unable to set %uHz sample rate\r\n", rate); goto fail; } if (r != rate) { fprintf(stderr, "OSS: sample rate set to %uHz instead of %u\r\n", rate, r); } tmp = (DEFAULT_NUMFRAGS<<16)|DEFAULT_FRAGSIZE; if (ioctl(audio_fd, SNDCTL_DSP_SETFRAGMENT, &tmp) < 0) { fprintf(stderr, "ERROR: Unable to set fragment size\r\n"); goto fail; } send_output = write_oss_output; close_output = close_oss_output; pause_output = pause_output_oss; resume_output = resume_output_nop; return (0); fail: close_oss_output(); return -1; } static int write_oss_output(char * output_data, int output_size) { int res = 0; while (output_size > 0) { res = write(audio_fd, output_data, output_size); if (res > 0) { output_size -= res; output_data += res; } else { fprintf(stderr, "\nOSS: write failure to dsp: %s.\r\n", strerror(errno)); return -1; } } return (0); } static void close_oss_output(void) { if (audio_fd < 0) return; printf("Shutting down sound output\r\n"); ioctl(audio_fd, SNDCTL_DSP_RESET, 0); close(audio_fd); audio_fd = -1; } #elif defined AUDIODRV_OPENAL #define NUM_BUFFERS 4 static ALCdevice *device; static ALCcontext *context; static ALuint sourceId = 0; static ALuint buffers[NUM_BUFFERS]; static ALuint frames = 0; #define open_audio_output open_openal_output static void pause_output_openal(void) { alSourcePause(sourceId); } static int write_openal_output(char * output_data, int output_size) { ALint processed, state; ALuint bufid; if (frames < NUM_BUFFERS) { /* initial state: fill the buffers */ alBufferData(buffers[frames], AL_FORMAT_STEREO16, output_data, output_size, rate); /* Now queue and start playback! */ if (++frames == NUM_BUFFERS) { alSourceQueueBuffers(sourceId, frames, buffers); alSourcePlay(sourceId); } return 0; } /* Get relevant source info */ alGetSourcei(sourceId, AL_SOURCE_STATE, &state); if (state == AL_PAUSED) { /* resume it, then.. */ alSourcePlay(sourceId); if (alGetError() != AL_NO_ERROR) { fprintf(stderr, "\nError restarting playback\r\n"); return (-1); } } processed = 0; while (processed == 0) { /* Wait until we have a processed buffer */ alGetSourcei(sourceId, AL_BUFFERS_PROCESSED, &processed); } /* Unqueue and handle each processed buffer */ alSourceUnqueueBuffers(sourceId, 1, &bufid); /* Read the next chunk of data, refill the buffer, and queue it * back on the source */ alBufferData(bufid, AL_FORMAT_STEREO16, output_data, output_size, rate); alSourceQueueBuffers(sourceId, 1, &bufid); if (alGetError() != AL_NO_ERROR) { fprintf(stderr, "\nError buffering data\r\n"); return (-1); } /* Make sure the source hasn't underrun */ alGetSourcei(sourceId, AL_SOURCE_STATE, &state); /*printf("STATE: %#08x - %d\n", state, queued);*/ if (state != AL_PLAYING) { ALint queued; /* If no buffers are queued, playback is finished */ alGetSourcei(sourceId, AL_BUFFERS_QUEUED, &queued); if (queued == 0) { fprintf(stderr, "\nNo buffers queued for playback\r\n"); return (-1); } alSourcePlay(sourceId); } return (0); } static void close_openal_output(void) { if (!context) return; printf("Shutting down sound output\r\n"); alSourceStop(sourceId); /* stop playing */ alSourcei(sourceId, AL_BUFFER, 0); /* unload buffer from source */ alDeleteBuffers(NUM_BUFFERS, buffers); alDeleteSources(1, &sourceId); alcDestroyContext(context); alcCloseDevice(device); context = NULL; device = NULL; frames = 0; } static int open_openal_output(void) { /* setup our audio devices and contexts */ device = alcOpenDevice(NULL); if (!device) { fprintf(stderr, "OpenAL: Unable to open default device.\r\n"); return (-1); } context = alcCreateContext(device, NULL); if (context == NULL || alcMakeContextCurrent(context) == ALC_FALSE) { if (context != NULL) alcDestroyContext(context); alcCloseDevice(device); context = NULL; device = NULL; fprintf(stderr, "OpenAL: Failed to create the default context.\r\n"); return (-1); } /* setup our sources and buffers */ alGenSources(1, &sourceId); alGenBuffers(NUM_BUFFERS, buffers); send_output = write_openal_output; close_output = close_openal_output; pause_output = pause_output_openal; resume_output = resume_output_nop; return (0); } #else /* no audio output driver compiled in: */ #define open_audio_output open_noaudio_output static int open_noaudio_output(void) { return -1; } #endif /* AUDIODRV_ALSA */ #endif /* _WIN32 || __CYGWIN__ */ static struct option const long_options[] = { { "version", 0, 0, 'v' }, { "help", 0, 0, 'h' }, { "rate", 1, 0, 'r' }, { "mastervol", 1, 0, 'm' }, { "config", 1, 0, 'c' }, { "wavout", 1, 0, 'o' }, { "log_vol", 0, 0, 'l' }, { "reverb", 0, 0, 'b' }, { "test_midi", 0, 0, 't' }, { "test_bank", 1, 0, 'k' }, { "test_patch", 1, 0, 'p' }, { "enhanced", 0, 0, 'e' }, #if defined(AUDIODRV_OSS) || defined(AUDIODRV_ALSA) { "device", 1, 0, 'd' }, #endif { "wholetempo", 0, 0, 'w' }, { "roundtempo", 0, 0, 'n' }, { NULL, 0, NULL, 0 } }; static void do_help(void) { printf(" -v --version Display version info and exit\n"); printf(" -h --help Display this help and exit\n"); #if defined(AUDIODRV_OSS) || defined(AUDIODRV_ALSA) printf(" -d D --device=D Use device D for audio output instead of default\n"); #endif printf("MIDI Options:\n"); printf(" -w --wholetempo Round down tempo to whole number\n"); printf(" -n --roundtempo Round tempo to nearest whole number\n"); printf("Software Wavetable Options:\n"); printf(" -o W --wavout=W Save output to W in 16bit stereo format wav file\n"); printf(" -l --log_vol Use log volume adjustments\n"); printf(" -r N --rate=N Set sample rate to N samples per second (Hz)\n"); printf(" -c P --config=P Point to your wildmidi.cfg config file name/path\n"); printf(" defaults to: %s\n", WILDMIDI_CFG); printf(" -m V --mastervol=V Set the master volume (0..127), default is 100\n"); printf(" -b --reverb Enable final output reverb engine\n"); } static void do_version(void) { printf("\nWildMidi %s Open Source Midi Sequencer\n", PACKAGE_VERSION); printf("Copyright (C) WildMIDI Developers 2001-2014\n\n"); printf("WildMidi comes with ABSOLUTELY NO WARRANTY\n"); printf("This is free software, and you are welcome to redistribute it under\n"); printf("the terms and conditions of the GNU General Public License version 3.\n"); printf("For more information see COPYING\n\n"); printf("Report bugs to %s\n", PACKAGE_BUGREPORT); printf("WildMIDI homepage is at %s\n\n", PACKAGE_URL); } static void do_syntax(void) { printf("Usage: wildmidi [options] filename.mid\n\n"); } static char config_file[1024]; int main(int argc, char **argv) { struct _WM_Info *wm_info; int i, res; int option_index = 0; unsigned short mixer_options = 0; void *midi_ptr; unsigned char master_volume = 100; char *output_buffer; unsigned long int perc_play; unsigned long int pro_mins; unsigned long int pro_secs; unsigned long int apr_mins; unsigned long int apr_secs; char modes[4]; unsigned long int count_diff; unsigned char ch; unsigned char test_midi = 0; unsigned char test_count = 0; unsigned char *test_data; unsigned char test_bank = 0; unsigned char test_patch = 0; static char spinner[] = "|/-\\"; static int spinpoint = 0; unsigned long int seek_to_sample; int inpause = 0; #if defined(AUDIODRV_OSS) || defined(AUDIODRV_ALSA) pcmname[0] = 0; #endif config_file[0] = 0; wav_file[0] = 0; do_version(); while (1) { i = getopt_long(argc, argv, "vho:lr:c:m:btk:p:ed:wn", long_options, &option_index); if (i == -1) break; switch (i) { case 'v': /* Version */ return (0); case 'h': /* help */ do_syntax(); do_help(); return (0); case 'r': /* Sample Rate */ res = atoi(optarg); if (res < 0 || res > 65535) { fprintf(stderr, "Error: bad rate %i.\n", res); return (1); } rate = res; break; case 'b': /* Reverb */ mixer_options |= WM_MO_REVERB; break; case 'm': /* Master Volume */ master_volume = (unsigned char) atoi(optarg); break; case 'o': /* Wav Output */ if (!*optarg) { fprintf(stderr, "Error: empty wavfile name.\n"); return (1); } strncpy(wav_file, optarg, sizeof(wav_file)); wav_file[sizeof(wav_file) - 1] = 0; break; case 'c': /* Config File */ if (!*optarg) { fprintf(stderr, "Error: empty config name.\n"); return (1); } strncpy(config_file, optarg, sizeof(config_file)); config_file[sizeof(config_file) - 1] = 0; break; #if defined(AUDIODRV_OSS) || defined(AUDIODRV_ALSA) case 'd': /* Output device */ if (!*optarg) { fprintf(stderr, "Error: empty device name.\n"); return (1); } strncpy(pcmname, optarg, sizeof(pcmname)); pcmname[sizeof(pcmname) - 1] = 0; break; #endif case 'e': /* Enhanced Resampling */ mixer_options |= WM_MO_ENHANCED_RESAMPLING; break; case 'l': /* log volume */ mixer_options |= WM_MO_LOG_VOLUME; break; case 't': /* play test midis */ test_midi = 1; break; case 'k': /* set test bank */ test_bank = (unsigned char) atoi(optarg); break; case 'p': /* set test patch */ test_patch = (unsigned char) atoi(optarg); break; case 'w': /* whole number tempo */ mixer_options |= WM_MO_WHOLETEMPO; break; case 'n': /* whole number tempo */ mixer_options |= WM_MO_ROUNDTEMPO; break; default: do_syntax(); return (1); } } if (optind < argc || test_midi) { if (!config_file[0]) { strncpy(config_file, WILDMIDI_CFG, sizeof(config_file)); config_file[sizeof(config_file) - 1] = 0; } printf("Initializing Sound System\n"); if (wav_file[0] != '\0') { if (open_wav_output() == -1) { return (1); } } else { if (open_audio_output() == -1) { return (1); } } printf("Initializing %s\n\r\n", WildMidi_GetString(WM_GS_VERSION)); if (WildMidi_Init(config_file, rate, mixer_options) == -1) { return (1); } printf(" + Volume up e Better resampling n Next Midi\n"); printf(" - Volume down l Log volume q Quit\n"); printf(" , 1sec Seek Back r Reverb . 1sec Seek Forward\n"); printf(" p Pause On/Off\n\n"); output_buffer = malloc(16384); if (output_buffer == NULL) { fprintf(stderr, "Not enough memory, exiting\n"); WildMidi_Shutdown(); return (1); } wm_inittty(); WildMidi_MasterVolume(master_volume); while (optind < argc || test_midi) { if (!test_midi) { const char *real_file = FIND_LAST_DIRSEP(argv[optind]); if (!real_file) real_file = argv[optind]; else real_file++; printf("Playing %s \r\n", real_file); midi_ptr = WildMidi_Open(argv[optind]); optind++; if (midi_ptr == NULL) { fprintf(stderr, "\rSkipping %s\r\n", real_file); continue; } } else { if (test_count == midi_test_max) { break; } test_data = malloc(midi_test[test_count].size); memcpy(test_data, midi_test[test_count].data, midi_test[test_count].size); test_data[25] = test_bank; test_data[28] = test_patch; midi_ptr = WildMidi_OpenBuffer(test_data, 633); test_count++; if (midi_ptr == NULL) { fprintf(stderr, "\rFailed loading test midi no. %i\r\n", test_count); continue; } printf("Playing test midi no. %i\r\n", test_count); } wm_info = WildMidi_GetInfo(midi_ptr); apr_mins = wm_info->approx_total_samples / (rate * 60); apr_secs = (wm_info->approx_total_samples % (rate * 60)) / rate; mixer_options = wm_info->mixer_options; modes[0] = (mixer_options & WM_MO_LOG_VOLUME)? 'l' : ' '; modes[1] = (mixer_options & WM_MO_REVERB)? 'r' : ' '; modes[2] = (mixer_options & WM_MO_ENHANCED_RESAMPLING)? 'e' : ' '; modes[3] = '\0'; fprintf(stderr, "\r"); while (1) { count_diff = wm_info->approx_total_samples - wm_info->current_sample; if (count_diff == 0) break; ch = 0; #ifdef _WIN32 if (_kbhit()) { ch = _getch(); _putch(ch); } #elif defined(__DJGPP__) if (kbhit()) { ch = getch(); putch(ch); } #else if (read(STDIN_FILENO, &ch, 1) != 1) ch = 0; #endif if (ch) { switch (ch) { case 'l': WildMidi_SetOption(midi_ptr, WM_MO_LOG_VOLUME, ((mixer_options & WM_MO_LOG_VOLUME) ^ WM_MO_LOG_VOLUME)); mixer_options ^= WM_MO_LOG_VOLUME; modes[0] = (mixer_options & WM_MO_LOG_VOLUME)? 'l' : ' '; break; case 'r': WildMidi_SetOption(midi_ptr, WM_MO_REVERB, ((mixer_options & WM_MO_REVERB) ^ WM_MO_REVERB)); mixer_options ^= WM_MO_REVERB; modes[1] = (mixer_options & WM_MO_REVERB)? 'r' : ' '; break; case 'e': WildMidi_SetOption(midi_ptr, WM_MO_ENHANCED_RESAMPLING, ((mixer_options & WM_MO_ENHANCED_RESAMPLING) ^ WM_MO_ENHANCED_RESAMPLING)); mixer_options ^= WM_MO_ENHANCED_RESAMPLING; modes[2] = (mixer_options & WM_MO_ENHANCED_RESAMPLING)? 'e' : ' '; break; case 'n': goto NEXTMIDI; case 'p': if (inpause) { inpause = 0; fprintf(stderr, " \r"); resume_output(); } else { inpause = 1; fprintf(stderr, "Paused \r"); pause_output(); continue; } break; case 'q': printf("\r\n"); if (inpause) goto end2; goto end1; case '-': if (master_volume > 0) { master_volume--; WildMidi_MasterVolume(master_volume); } break; case '+': if (master_volume < 127) { master_volume++; WildMidi_MasterVolume(master_volume); } break; case ',': /* fast seek backwards */ if (wm_info->current_sample < rate) { seek_to_sample = 0; } else { seek_to_sample = wm_info->current_sample - rate; } WildMidi_FastSeek(midi_ptr, &seek_to_sample); break; case '.': /* fast seek forwards */ if ((wm_info->approx_total_samples - wm_info->current_sample) < rate) { seek_to_sample = wm_info->approx_total_samples; } else { seek_to_sample = wm_info->current_sample + rate; } WildMidi_FastSeek(midi_ptr, &seek_to_sample); break; default: break; } } if (inpause) { wm_info = WildMidi_GetInfo(midi_ptr); perc_play = (wm_info->current_sample * 100) / wm_info->approx_total_samples; pro_mins = wm_info->current_sample / (rate * 60); pro_secs = (wm_info->current_sample % (rate * 60)) / rate; fprintf(stderr, " [Approx %2lum %2lus Total] [%s] [%3i] [%2lum %2lus Processed] [%2lu%%] 0 \r", apr_mins, apr_secs, modes, master_volume, pro_mins, pro_secs, perc_play); msleep(5); continue; } res = WildMidi_GetOutput(midi_ptr, output_buffer, (count_diff >= 4096)? 16384 : (count_diff * 4)); if (res <= 0) break; wm_info = WildMidi_GetInfo(midi_ptr); perc_play = (wm_info->current_sample * 100) / wm_info->approx_total_samples; pro_mins = wm_info->current_sample / (rate * 60); pro_secs = (wm_info->current_sample % (rate * 60)) / rate; fprintf(stderr, " [Approx %2lum %2lus Total] [%s] [%3i] [%2lum %2lus Processed] [%2lu%%] %c \r", apr_mins, apr_secs, modes, master_volume, pro_mins, pro_secs, perc_play, spinner[spinpoint++ % 4]); #if defined(AUDIODRV_OPENAL) && defined(WORDS_BIGENDIAN) if (context != NULL) { /* OpenAL is active, not wav writer */ unsigned short *swp = (unsigned short *) output_buffer; /* the library specifically outputs LE data * but OpenAL expects host-endian: do swap. */ for (i = 0; i < res / 2; ++i) { swp[i] = (swp[i] << 8) | (swp[i] >> 8); } } #endif if (send_output(output_buffer, res) < 0) { /* driver prints an error message already. */ printf("\r"); goto end2; } } NEXTMIDI: fprintf(stderr, "\r\n"); if (WildMidi_Close(midi_ptr) == -1) { fprintf(stderr, "OOPS: failed closing midi handle!\r\n"); } memset(output_buffer, 0, 16384); send_output(output_buffer, 16384); } end1: memset(output_buffer, 0, 16384); send_output(output_buffer, 16384); msleep(5); end2: close_output(); free(output_buffer); if (WildMidi_Shutdown() == -1) fprintf(stderr, "OOPS: failure shutting down libWildMidi\r\n"); wm_resetty(); } else { fprintf(stderr, "ERROR: No midi file given\r\n"); do_syntax(); return (1); } printf("\r\n"); return (0); } /* helper / replacement functions: */ #if !defined(_WIN32) && !defined(__DJGPP__) static int msleep(unsigned long milisec) { struct timespec req = { 0, 0 }; time_t sec = (int) (milisec / 1000); milisec = milisec - (sec * 1000); req.tv_sec = sec; req.tv_nsec = milisec * 1000000L; while (nanosleep(&req, &req) == -1) continue; return (1); } #endif wildmidi-wildmidi-0.3.8/src/wildmidi_lib.c000066400000000000000000003752141245740225500205310ustar00rootroot00000000000000/* wildmidi_lib.c Midi Wavetable Processing library Copyright (C) Chris Ison 2001-2014 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #define UNUSED(x) (void)(x) #include #include #include #ifndef _WIN32 #include #include #include #endif #include #include #include #include #include #include #ifdef _WIN32 #include #include #undef strcasecmp #define strcasecmp _stricmp #undef strncasecmp #define strncasecmp _tcsnicmp #endif #include "common.h" #include "wm_error.h" #include "file_io.h" #include "lock.h" #include "reverb.h" #include "gus_pat.h" #include "wildmidi_lib.h" #include "filenames.h" /* * ========================= * Global Data and Data Structs * ========================= */ #define MEM_CHUNK 8192 static int WM_Initialized = 0; static signed short int WM_MasterVolume = 948; static unsigned short int WM_MixerOptions = 0; static char WM_Version[] = "WildMidi Processing Library " PACKAGE_VERSION; unsigned short int _WM_SampleRate; static struct _patch *patch[128]; static float reverb_room_width = 16.875f; static float reverb_room_length = 22.5f; static float reverb_listen_posx = 8.4375f; static float reverb_listen_posy = 16.875f; static int fix_release = 0; static int auto_amp = 0; static int auto_amp_with_amp = 0; static int patch_lock; struct _channel { unsigned char bank; struct _patch *patch; unsigned char hold; unsigned char volume; unsigned char pressure; unsigned char expression; signed char balance; signed char pan; signed short int left_adjust; signed short int right_adjust; signed short int pitch; signed short int pitch_range; signed long int pitch_adjust; unsigned short reg_data; unsigned char reg_non; unsigned char isdrum; }; #define HOLD_OFF 0x02 struct _note { unsigned short noteid; unsigned char velocity; struct _patch *patch; struct _sample *sample; unsigned long int sample_pos; unsigned long int sample_inc; signed long int env_inc; unsigned char env; signed long int env_level; unsigned char modes; unsigned char hold; unsigned char active; struct _note *replay; struct _note *next; unsigned long int vol_lvl; unsigned char is_off; }; struct _miditrack { unsigned long int length; unsigned long int ptr; unsigned long int delta; unsigned char running_event; unsigned char EOT; }; struct _mdi_patches { struct _patch *patch; struct _mdi_patch *next; }; struct _event_data { unsigned char channel; unsigned long int data; }; struct _mdi { int lock; unsigned long int samples_to_mix; struct _event *events; struct _event *current_event; unsigned long int event_count; unsigned long int events_size; /* try to stay optimally ahead to prevent reallocs */ unsigned short midi_master_vol; struct _WM_Info info; struct _WM_Info *tmp_info; struct _channel channel[16]; struct _note *note; struct _note note_table[2][16][128]; struct _patch **patches; unsigned long int patch_count; signed short int amp; signed long int *mix_buffer; unsigned long int mix_buffer_size; struct _rvb *reverb; }; struct _event { void (*do_event)(struct _mdi *mdi, struct _event_data *data); struct _event_data event_data; unsigned long int samples_to_next; unsigned long int samples_to_next_fixed; }; #define FPBITS 10 #define FPMASK ((1L<> 1); int j; int sign; double ck; double x, x_inc, xz; double z[35]; double *gptr, *t; _WM_Lock(&gauss_lock); if (gauss_table) { _WM_Unlock(&gauss_lock); return; } newt_coeffs[0][0] = 1; for (i = 0; i <= n; i++) { newt_coeffs[i][0] = 1; newt_coeffs[i][i] = 1; if (i > 1) { newt_coeffs[i][0] = newt_coeffs[i - 1][0] / i; newt_coeffs[i][i] = newt_coeffs[i - 1][0] / i; } for (j = 1; j < i; j++) { newt_coeffs[i][j] = newt_coeffs[i - 1][j - 1] + newt_coeffs[i - 1][j]; if (i > 1) newt_coeffs[i][j] /= i; } z[i] = i / (4 * M_PI); } for (i = 0; i <= n; i++) for (j = 0, sign = pow(-1, i); j <= i; j++, sign *= -1) newt_coeffs[i][j] *= sign; t = malloc((1<event_count >= mdi->events_size) { mdi->events_size += MEM_CHUNK; mdi->events = realloc(mdi->events, (mdi->events_size * sizeof(struct _event))); } } static void WM_InitPatches(void) { int i; for (i = 0; i < 128; i++) { patch[i] = NULL; } } static void WM_FreePatches(void) { int i; struct _patch * tmp_patch; struct _sample * tmp_sample; _WM_Lock(&patch_lock); for (i = 0; i < 128; i++) { while (patch[i]) { while (patch[i]->first_sample) { tmp_sample = patch[i]->first_sample->next; free(patch[i]->first_sample->data); free(patch[i]->first_sample); patch[i]->first_sample = tmp_sample; } free(patch[i]->filename); tmp_patch = patch[i]->next; free(patch[i]); patch[i] = tmp_patch; } } _WM_Unlock(&patch_lock); } /* wm_strdup -- adds extra space for appending up to 4 chars */ static char *wm_strdup (const char *str) { size_t l = strlen(str) + 5; char *d = (char *) malloc(l * sizeof(char)); if (d) { strcpy(d, str); return d; } return NULL; } static inline int wm_isdigit(int c) { return (c >= '0' && c <= '9'); } #define TOKEN_CNT_INC 8 static char** WM_LC_Tokenize_Line(char *line_data) { int line_length = strlen(line_data); int token_data_length = 0; int line_ofs = 0; int token_start = 0; char **token_data = NULL; int token_count = 0; if (line_length == 0) return NULL; do { /* ignore everything after # */ if (line_data[line_ofs] == '#') { break; } if ((line_data[line_ofs] == ' ') || (line_data[line_ofs] == '\t')) { /* whitespace means we aren't in a token */ if (token_start) { token_start = 0; line_data[line_ofs] = '\0'; } } else { if (!token_start) { /* the start of a token in the line */ token_start = 1; if (token_count >= token_data_length) { token_data_length += TOKEN_CNT_INC; token_data = realloc(token_data, token_data_length * sizeof(char *)); if (token_data == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM,"to parse config", errno); return NULL; } } token_data[token_count] = &line_data[line_ofs]; token_count++; } } line_ofs++; } while (line_ofs != line_length); /* if we have found some tokens then add a null token to the end */ if (token_count) { if (token_count >= token_data_length) { token_data = realloc(token_data, ((token_count + 1) * sizeof(char *))); } token_data[token_count] = NULL; } return token_data; } static int WM_LoadConfig(const char *config_file) { unsigned long int config_size = 0; char *config_buffer = NULL; const char *dir_end = NULL; char *config_dir = NULL; unsigned long int config_ptr = 0; unsigned long int line_start_ptr = 0; unsigned short int patchid = 0; struct _patch * tmp_patch; char **line_tokens = NULL; int token_count = 0; config_buffer = (char *) _WM_BufferFile(config_file, &config_size); if (!config_buffer) { WM_FreePatches(); return -1; } dir_end = FIND_LAST_DIRSEP(config_file); if (dir_end) { config_dir = malloc((dir_end - config_file + 2)); if (config_dir == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_buffer); return -1; } strncpy(config_dir, config_file, (dir_end - config_file + 1)); config_dir[dir_end - config_file + 1] = '\0'; } config_ptr = 0; line_start_ptr = 0; /* handle files without a newline at the end: this relies on * _WM_BufferFile() allocating the buffer with one extra byte */ config_buffer[config_size] = '\n'; while (config_ptr <= config_size) { if (config_buffer[config_ptr] == '\r' || config_buffer[config_ptr] == '\n') { config_buffer[config_ptr] = '\0'; if (config_ptr != line_start_ptr) { line_tokens = WM_LC_Tokenize_Line(&config_buffer[line_start_ptr]); if (line_tokens) { if (strcasecmp(line_tokens[0], "dir") == 0) { free(config_dir); if (!line_tokens[1]) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(missing name in dir line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(line_tokens); free(config_buffer); return -1; } else if (!(config_dir = wm_strdup(line_tokens[1]))) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(line_tokens); free(config_buffer); return -1; } if (!IS_DIR_SEPARATOR(config_dir[strlen(config_dir) - 1])) { config_dir[strlen(config_dir) + 1] = '\0'; config_dir[strlen(config_dir)] = DIR_SEPARATOR_CHAR; } } else if (strcasecmp(line_tokens[0], "source") == 0) { char *new_config = NULL; if (!line_tokens[1]) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(missing name in source line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(line_tokens); free(config_buffer); return -1; } else if (!IS_ABSOLUTE_PATH(line_tokens[1]) && config_dir) { new_config = malloc( strlen(config_dir) + strlen(line_tokens[1]) + 1); if (new_config == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } strcpy(new_config, config_dir); strcpy(&new_config[strlen(config_dir)], line_tokens[1]); } else { if (!(new_config = wm_strdup(line_tokens[1]))) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to parse config", errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(line_tokens); free(config_buffer); return -1; } } if (WM_LoadConfig(new_config) == -1) { free(new_config); free(line_tokens); free(config_buffer); free(config_dir); return -1; } free(new_config); } else if (strcasecmp(line_tokens[0], "bank") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in bank line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } patchid = (atoi(line_tokens[1]) & 0xFF) << 8; } else if (strcasecmp(line_tokens[0], "drumset") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in drumset line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } patchid = ((atoi(line_tokens[1]) & 0xFF) << 8) | 0x80; } else if (strcasecmp(line_tokens[0], "reverb_room_width") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in reverb_room_width line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } reverb_room_width = (float) atof(line_tokens[1]); if (reverb_room_width < 1.0f) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_room_width < 1 meter, setting to minimum of 1 meter)", 0); reverb_room_width = 1.0f; } else if (reverb_room_width > 100.0f) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_room_width > 100 meters, setting to maximum of 100 meters)", 0); reverb_room_width = 100.0f; } } else if (strcasecmp(line_tokens[0], "reverb_room_length") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in reverb_room_length line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } reverb_room_length = (float) atof(line_tokens[1]); if (reverb_room_length < 1.0f) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_room_length < 1 meter, setting to minimum of 1 meter)", 0); reverb_room_length = 1.0f; } else if (reverb_room_length > 100.0f) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_room_length > 100 meters, setting to maximum of 100 meters)", 0); reverb_room_length = 100.0f; } } else if (strcasecmp(line_tokens[0], "reverb_listener_posx") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in reverb_listen_posx line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } reverb_listen_posx = (float) atof(line_tokens[1]); if ((reverb_listen_posx > reverb_room_width) || (reverb_listen_posx < 0.0f)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_listen_posx set outside of room)", 0); reverb_listen_posx = reverb_room_width / 2.0f; } } else if (strcasecmp(line_tokens[0], "reverb_listener_posy") == 0) { if (!line_tokens[1] || !wm_isdigit(line_tokens[1][0])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in reverb_listen_posy line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } reverb_listen_posy = (float) atof(line_tokens[1]); if ((reverb_listen_posy > reverb_room_width) || (reverb_listen_posy < 0.0f)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(reverb_listen_posy set outside of room)", 0); reverb_listen_posy = reverb_room_length * 0.75f; } } else if (strcasecmp(line_tokens[0], "guspat_editor_author_cant_read_so_fix_release_time_for_me") == 0) { fix_release = 1; } else if (strcasecmp(line_tokens[0], "auto_amp") == 0) { auto_amp = 1; } else if (strcasecmp(line_tokens[0], "auto_amp_with_amp") == 0) { auto_amp = 1; auto_amp_with_amp = 1; } else if (wm_isdigit(line_tokens[0][0])) { patchid = (patchid & 0xFF80) | (atoi(line_tokens[0]) & 0x7F); if (patch[(patchid & 0x7F)] == NULL) { patch[(patchid & 0x7F)] = malloc( sizeof(struct _patch)); if (patch[(patchid & 0x7F)] == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } tmp_patch = patch[(patchid & 0x7F)]; tmp_patch->patchid = patchid; tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; tmp_patch->next = NULL; tmp_patch->first_sample = NULL; tmp_patch->loaded = 0; tmp_patch->inuse_count = 0; } else { tmp_patch = patch[(patchid & 0x7F)]; if (tmp_patch->patchid == patchid) { free(tmp_patch->filename); tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; } else { if (tmp_patch->next) { while (tmp_patch->next) { if (tmp_patch->next->patchid == patchid) break; tmp_patch = tmp_patch->next; } if (tmp_patch->next == NULL) { if ((tmp_patch->next = malloc( sizeof(struct _patch))) == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } tmp_patch = tmp_patch->next; tmp_patch->patchid = patchid; tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; tmp_patch->next = NULL; tmp_patch->first_sample = NULL; tmp_patch->loaded = 0; tmp_patch->inuse_count = 0; } else { tmp_patch = tmp_patch->next; free(tmp_patch->filename); tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; } } else { tmp_patch->next = malloc( sizeof(struct _patch)); if (tmp_patch->next == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, errno); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } tmp_patch = tmp_patch->next; tmp_patch->patchid = patchid; tmp_patch->filename = NULL; tmp_patch->amp = 1024; tmp_patch->note = 0; tmp_patch->next = NULL; tmp_patch->first_sample = NULL; tmp_patch->loaded = 0; tmp_patch->inuse_count = 0; } } } if (!line_tokens[1]) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(missing name in patch line)", 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } else if (!IS_ABSOLUTE_PATH(line_tokens[1]) && config_dir) { tmp_patch->filename = malloc( strlen(config_dir) + strlen(line_tokens[1]) + 5); if (tmp_patch->filename == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } strcpy(tmp_patch->filename, config_dir); strcat(tmp_patch->filename, line_tokens[1]); } else { if (!(tmp_patch->filename = wm_strdup(line_tokens[1]))) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, NULL, 0); _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LOAD, config_file, 0); WM_FreePatches(); free(config_dir); free(line_tokens); free(config_buffer); return -1; } } if (strncasecmp( &tmp_patch->filename[strlen(tmp_patch->filename) - 4], ".pat", 4) != 0) { strcat(tmp_patch->filename, ".pat"); } tmp_patch->env[0].set = 0x00; tmp_patch->env[1].set = 0x00; tmp_patch->env[2].set = 0x00; tmp_patch->env[3].set = 0x00; tmp_patch->env[4].set = 0x00; tmp_patch->env[5].set = 0x00; tmp_patch->keep = 0; tmp_patch->remove = 0; token_count = 0; while (line_tokens[token_count]) { if (strncasecmp(line_tokens[token_count], "amp=", 4) == 0) { if (!wm_isdigit(line_tokens[token_count][4])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { tmp_patch->amp = (atoi( &line_tokens[token_count][4]) << 10) / 100; } } else if (strncasecmp(line_tokens[token_count], "note=", 5) == 0) { if (!wm_isdigit(line_tokens[token_count][5])) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { tmp_patch->note = atoi( &line_tokens[token_count][5]); } } else if (strncasecmp(line_tokens[token_count], "env_time", 8) == 0) { if ((!wm_isdigit(line_tokens[token_count][8])) || (!wm_isdigit( line_tokens[token_count][10])) || (line_tokens[token_count][9] != '=')) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { unsigned int env_no = atoi( &line_tokens[token_count][8]); if (env_no > 5) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { tmp_patch->env[env_no].time = (float) atof( &line_tokens[token_count][10]); if ((tmp_patch->env[env_no].time > 45000.0f) || (tmp_patch->env[env_no].time < 1.47f)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(range error in patch line)", 0); tmp_patch->env[env_no].set &= 0xFE; } else { tmp_patch->env[env_no].set |= 0x01; } } } } else if (strncasecmp(line_tokens[token_count], "env_level", 9) == 0) { if ((!wm_isdigit(line_tokens[token_count][9])) || (!wm_isdigit( line_tokens[token_count][11])) || (line_tokens[token_count][10] != '=')) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { unsigned int env_no = atoi( &line_tokens[token_count][9]); if (env_no > 5) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(syntax error in patch line)", 0); } else { tmp_patch->env[env_no].level = (float) atof( &line_tokens[token_count][11]); if ((tmp_patch->env[env_no].level > 1.0f) || (tmp_patch->env[env_no].level < 0.0f)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(range error in patch line)", 0); tmp_patch->env[env_no].set &= 0xFD; } else { tmp_patch->env[env_no].set |= 0x02; } } } } else if (strcasecmp(line_tokens[token_count], "keep=loop") == 0) { tmp_patch->keep |= SAMPLE_LOOP; } else if (strcasecmp(line_tokens[token_count], "keep=env") == 0) { tmp_patch->keep |= SAMPLE_ENVELOPE; } else if (strcasecmp(line_tokens[token_count], "remove=sustain") == 0) { tmp_patch->remove |= SAMPLE_SUSTAIN; } else if (strcasecmp(line_tokens[token_count], "remove=clamped") == 0) { tmp_patch->remove |= SAMPLE_CLAMPED; } token_count++; } } } /* free up tokens */ free(line_tokens); } line_start_ptr = config_ptr + 1; } config_ptr++; } free(config_buffer); free(config_dir); return 0; } /* sample loading */ static int load_sample(struct _patch *sample_patch) { struct _sample *guspat = NULL; struct _sample *tmp_sample = NULL; unsigned int i = 0; /* we only want to try loading the guspat once. */ sample_patch->loaded = 1; if ((guspat = _WM_load_gus_pat(sample_patch->filename, fix_release)) == NULL) { return -1; } if (auto_amp) { signed short int tmp_max = 0; signed short int tmp_min = 0; signed short samp_max = 0; signed short samp_min = 0; tmp_sample = guspat; do { samp_max = 0; samp_min = 0; for (i = 0; i < (tmp_sample->data_length >> 10); i++) { if (tmp_sample->data[i] > samp_max) samp_max = tmp_sample->data[i]; if (tmp_sample->data[i] < samp_min) samp_min = tmp_sample->data[i]; } if (samp_max > tmp_max) tmp_max = samp_max; if (samp_min < tmp_min) tmp_min = samp_min; tmp_sample = tmp_sample->next; } while (tmp_sample); if (auto_amp_with_amp) { if (tmp_max >= -tmp_min) { sample_patch->amp = (sample_patch->amp * ((32767 << 10) / tmp_max)) >> 10; } else { sample_patch->amp = (sample_patch->amp * ((32768 << 10) / -tmp_min)) >> 10; } } else { if (tmp_max >= -tmp_min) { sample_patch->amp = (32767 << 10) / tmp_max; } else { sample_patch->amp = (32768 << 10) / -tmp_min; } } } sample_patch->first_sample = guspat; if (sample_patch->patchid & 0x0080) { if (!(sample_patch->keep & SAMPLE_LOOP)) { do { guspat->modes &= 0xFB; guspat = guspat->next; } while (guspat); } guspat = sample_patch->first_sample; if (!(sample_patch->keep & SAMPLE_ENVELOPE)) { do { guspat->modes &= 0xBF; guspat = guspat->next; } while (guspat); } guspat = sample_patch->first_sample; } if (sample_patch->patchid == 47) { do { if (!(guspat->modes & SAMPLE_LOOP)) { for (i = 3; i < 6; i++) { guspat->env_target[i] = guspat->env_target[2]; guspat->env_rate[i] = guspat->env_rate[2]; } } guspat = guspat->next; } while (guspat); guspat = sample_patch->first_sample; } do { if ((sample_patch->remove & SAMPLE_SUSTAIN) && (guspat->modes & SAMPLE_SUSTAIN)) { guspat->modes ^= SAMPLE_SUSTAIN; } if ((sample_patch->remove & SAMPLE_CLAMPED) && (guspat->modes & SAMPLE_CLAMPED)) { guspat->modes ^= SAMPLE_CLAMPED; } if (sample_patch->keep & SAMPLE_ENVELOPE) { guspat->modes |= SAMPLE_ENVELOPE; } for (i = 0; i < 6; i++) { if (guspat->modes & SAMPLE_ENVELOPE) { if (sample_patch->env[i].set & 0x02) { guspat->env_target[i] = 16448 * (signed long int) (255.0 * sample_patch->env[i].level); } if (sample_patch->env[i].set & 0x01) { guspat->env_rate[i] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * (sample_patch->env[i].time / 1000.0))); } } else { guspat->env_target[i] = 4194303; guspat->env_rate[i] = (signed long int) (4194303.0 / ((float) _WM_SampleRate * env_time_table[63])); } } guspat = guspat->next; } while (guspat); return 0; } static struct _patch * get_patch_data(struct _mdi *mdi, unsigned short patchid) { struct _patch *search_patch; _WM_Lock(&patch_lock); search_patch = patch[patchid & 0x007F]; if (search_patch == NULL) { _WM_Unlock(&patch_lock); return NULL; } while (search_patch) { if (search_patch->patchid == patchid) { _WM_Unlock(&patch_lock); return search_patch; } search_patch = search_patch->next; } if ((patchid >> 8) != 0) { _WM_Unlock(&patch_lock); return (get_patch_data(mdi, patchid & 0x00FF)); } _WM_Unlock(&patch_lock); return NULL; } static void load_patch(struct _mdi *mdi, unsigned short patchid) { unsigned int i; struct _patch *tmp_patch = NULL; for (i = 0; i < mdi->patch_count; i++) { if (mdi->patches[i]->patchid == patchid) { return; } } tmp_patch = get_patch_data(mdi, patchid); if (tmp_patch == NULL) { return; } _WM_Lock(&patch_lock); if (!tmp_patch->loaded) { if (load_sample(tmp_patch) == -1) { _WM_Unlock(&patch_lock); return; } } if (tmp_patch->first_sample == NULL) { _WM_Unlock(&patch_lock); return; } mdi->patch_count++; mdi->patches = realloc(mdi->patches, (sizeof(struct _patch*) * mdi->patch_count)); mdi->patches[mdi->patch_count - 1] = tmp_patch; tmp_patch->inuse_count++; _WM_Unlock(&patch_lock); } static struct _sample * get_sample_data(struct _patch *sample_patch, unsigned long int freq) { struct _sample *last_sample = NULL; struct _sample *return_sample = NULL; _WM_Lock(&patch_lock); if (sample_patch == NULL) { _WM_Unlock(&patch_lock); return NULL; } if (sample_patch->first_sample == NULL) { _WM_Unlock(&patch_lock); return NULL; } if (freq == 0) { _WM_Unlock(&patch_lock); return sample_patch->first_sample; } return_sample = sample_patch->first_sample; last_sample = sample_patch->first_sample; while (last_sample) { if (freq > last_sample->freq_low) { if (freq < last_sample->freq_high) { _WM_Unlock(&patch_lock); return last_sample; } else { return_sample = last_sample; } } last_sample = last_sample->next; } _WM_Unlock(&patch_lock); return return_sample; } static void do_note_off_extra(struct _note *nte) { nte->is_off = 0; if (nte->hold) { nte->hold |= HOLD_OFF; } else { if (!(nte->modes & SAMPLE_ENVELOPE)) { if (nte->modes & SAMPLE_LOOP) { nte->modes ^= SAMPLE_LOOP; } nte->env_inc = 0; } else if (nte->modes & SAMPLE_CLAMPED) { if (nte->env < 5) { nte->env = 5; if (nte->env_level > nte->sample->env_target[5]) { nte->env_inc = -nte->sample->env_rate[5]; } else { nte->env_inc = nte->sample->env_rate[5]; } } #if 1 } else if (nte->modes & SAMPLE_SUSTAIN) { if (nte->env < 3) { nte->env = 3; if (nte->env_level > nte->sample->env_target[3]) { nte->env_inc = -nte->sample->env_rate[3]; } else { nte->env_inc = nte->sample->env_rate[3]; } } #endif } else if (nte->env < 4) { nte->env = 4; if (nte->env_level > nte->sample->env_target[4]) { nte->env_inc = -nte->sample->env_rate[4]; } else { nte->env_inc = nte->sample->env_rate[4]; } } } } static void do_note_off(struct _mdi *mdi, struct _event_data *data) { struct _note *nte; unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); nte = &mdi->note_table[0][ch][(data->data >> 8)]; if (!nte->active) nte = &mdi->note_table[1][ch][(data->data >> 8)]; if (!nte->active) { return; } if ((mdi->channel[ch].isdrum) && (!(nte->modes & SAMPLE_LOOP))) { return; } if (nte->env == 0) { nte->is_off = 1; } else { do_note_off_extra(nte); } } static inline unsigned long int get_inc(struct _mdi *mdi, struct _note *nte) { int ch = nte->noteid >> 8; signed long int note_f; unsigned long int freq; if (__builtin_expect((nte->patch->note != 0), 0)) { note_f = nte->patch->note * 100; } else { note_f = (nte->noteid & 0x7f) * 100; } note_f += mdi->channel[ch].pitch_adjust; if (__builtin_expect((note_f < 0), 0)) { note_f = 0; } else if (__builtin_expect((note_f > 12700), 0)) { note_f = 12700; } freq = freq_table[(note_f % 1200)] >> (10 - (note_f / 1200)); return (((freq / ((_WM_SampleRate * 100) / 1024)) * 1024 / nte->sample->inc_div)); } static inline unsigned long int get_volume(struct _mdi *mdi, unsigned char ch, struct _note *nte) { signed long int volume; if (mdi->info.mixer_options & WM_MO_LOG_VOLUME) { volume = (sqr_volume[mdi->channel[ch].volume] * sqr_volume[mdi->channel[ch].expression] * sqr_volume[nte->velocity]) / 1048576; } else { volume = (lin_volume[mdi->channel[ch].volume] * lin_volume[mdi->channel[ch].expression] * lin_volume[nte->velocity]) / 1048576; } volume = volume * nte->patch->amp / 100; return (volume); } static void do_note_on(struct _mdi *mdi, struct _event_data *data) { struct _note *nte; struct _note *prev_nte; struct _note *nte_array; unsigned long int freq = 0; struct _patch *patch; struct _sample *sample; unsigned char ch = data->channel; unsigned char note = (data->data >> 8); unsigned char velocity = (data->data & 0xFF); if (velocity == 0x00) { do_note_off(mdi, data); return; } MIDI_EVENT_DEBUG(__FUNCTION__,ch); if (!mdi->channel[ch].isdrum) { patch = mdi->channel[ch].patch; if (patch == NULL) { return; } freq = freq_table[(note % 12) * 100] >> (10 - (note / 12)); } else { patch = get_patch_data(mdi, ((mdi->channel[ch].bank << 8) | note | 0x80)); if (patch == NULL) { return; } if (patch->note) { freq = freq_table[(patch->note % 12) * 100] >> (10 - (patch->note / 12)); } else { freq = freq_table[(note % 12) * 100] >> (10 - (note / 12)); } } sample = get_sample_data(patch, (freq / 100)); if (sample == NULL) { return; } nte = &mdi->note_table[0][ch][note]; if (nte->active) { if ((nte->modes & SAMPLE_ENVELOPE) && (nte->env < 3) && (!(nte->hold & HOLD_OFF))) return; nte->replay = &mdi->note_table[1][ch][note]; nte->env = 6; nte->env_inc = -nte->sample->env_rate[6]; nte = nte->replay; } else { if (mdi->note_table[1][ch][note].active) { if ((nte->modes & SAMPLE_ENVELOPE) && (nte->env < 3) && (!(nte->hold & HOLD_OFF))) return; mdi->note_table[1][ch][note].replay = nte; mdi->note_table[1][ch][note].env = 6; mdi->note_table[1][ch][note].env_inc = -mdi->note_table[1][ch][note].sample->env_rate[6]; } else { nte_array = mdi->note; if (nte_array == NULL) { mdi->note = nte; } else { do { prev_nte = nte_array; nte_array = nte_array->next; } while (nte_array); prev_nte->next = nte; } nte->active = 1; nte->next = NULL; } } nte->noteid = (ch << 8) | note; nte->patch = patch; nte->sample = sample; nte->sample_pos = 0; nte->sample_inc = get_inc(mdi, nte); nte->velocity = velocity; nte->env = 0; nte->env_inc = nte->sample->env_rate[0]; nte->env_level = 0; nte->modes = sample->modes; nte->hold = mdi->channel[ch].hold; nte->vol_lvl = get_volume(mdi, ch, nte); nte->replay = NULL; nte->is_off = 0; } static void do_aftertouch(struct _mdi *mdi, struct _event_data *data) { struct _note *nte; unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); nte = &mdi->note_table[0][ch][(data->data >> 8)]; if (!nte->active) { nte = &mdi->note_table[1][ch][(data->data >> 8)]; if (!nte->active) { return; } } nte->velocity = data->data & 0xff; nte->vol_lvl = get_volume(mdi, ch, nte); if (nte->replay) { nte->replay->velocity = data->data & 0xff; nte->replay->vol_lvl = get_volume(mdi, ch, nte->replay); } } static void do_pan_adjust(struct _mdi *mdi, unsigned char ch) { signed short int pan_adjust = mdi->channel[ch].balance + mdi->channel[ch].pan; signed short int left, right; int amp = 32; if (pan_adjust > 63) { pan_adjust = 63; } else if (pan_adjust < -64) { pan_adjust = -64; } pan_adjust += 64; /* if (mdi->info.mixer_options & WM_MO_LOG_VOLUME) {*/ left = (pan_volume[127 - pan_adjust] * WM_MasterVolume * amp) / 1048576; right = (pan_volume[pan_adjust] * WM_MasterVolume * amp) / 1048576; /* } else { left = (lin_volume[127 - pan_adjust] * WM_MasterVolume * amp) / 1048576; right= (lin_volume[pan_adjust] * WM_MasterVolume * amp) / 1048576; }*/ mdi->channel[ch].left_adjust = left; mdi->channel[ch].right_adjust = right; } static void do_control_bank_select(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].bank = data->data; } static void do_control_data_entry_course(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; int data_tmp; if ((mdi->channel[ch].reg_non == 0) && (mdi->channel[ch].reg_data == 0x0000)) { /* Pitch Bend Range */ data_tmp = mdi->channel[ch].pitch_range % 100; mdi->channel[ch].pitch_range = data->data * 100 + data_tmp; /* printf("Data Entry Course: pitch_range: %i\n\r",mdi->channel[ch].pitch_range);*/ /* printf("Data Entry Course: data %li\n\r",data->data);*/ } } static void do_control_channel_volume(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; mdi->channel[ch].volume = data->data; if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->vol_lvl = get_volume(mdi, ch, note_data); if (note_data->replay) note_data->replay->vol_lvl = get_volume(mdi, ch, note_data->replay); } note_data = note_data->next; } while (note_data); } } static void do_control_channel_balance(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].balance = data->data - 64; do_pan_adjust(mdi, ch); } static void do_control_channel_pan(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].pan = data->data - 64; do_pan_adjust(mdi, ch); } static void do_control_channel_expression(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; mdi->channel[ch].expression = data->data; if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->vol_lvl = get_volume(mdi, ch, note_data); if (note_data->replay) note_data->replay->vol_lvl = get_volume(mdi, ch, note_data->replay); } note_data = note_data->next; } while (note_data); } } static void do_control_data_entry_fine(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; int data_tmp; if ((mdi->channel[ch].reg_non == 0) && (mdi->channel[ch].reg_data == 0x0000)) { /* Pitch Bend Range */ data_tmp = mdi->channel[ch].pitch_range / 100; mdi->channel[ch].pitch_range = (data_tmp * 100) + data->data; /* printf("Data Entry Fine: pitch_range: %i\n\r",mdi->channel[ch].pitch_range);*/ /* printf("Data Entry Fine: data: %li\n\r", data->data);*/ } } static void do_control_channel_hold(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; if (data->data > 63) { mdi->channel[ch].hold = 1; } else { mdi->channel[ch].hold = 0; if (note_data) { do { if ((note_data->noteid >> 8) == ch) { if (note_data->hold & HOLD_OFF) { if (note_data->modes & SAMPLE_ENVELOPE) { if (note_data->modes & SAMPLE_CLAMPED) { if (note_data->env < 5) { note_data->env = 5; if (note_data->env_level > note_data->sample->env_target[5]) { note_data->env_inc = -note_data->sample->env_rate[5]; } else { note_data->env_inc = note_data->sample->env_rate[5]; } } } else if (note_data->env < 4) { note_data->env = 4; if (note_data->env_level > note_data->sample->env_target[4]) { note_data->env_inc = -note_data->sample->env_rate[4]; } else { note_data->env_inc = note_data->sample->env_rate[4]; } } } else { if (note_data->modes & SAMPLE_LOOP) { note_data->modes ^= SAMPLE_LOOP; } note_data->env_inc = 0; } } note_data->hold = 0x00; } note_data = note_data->next; } while (note_data); } } } static void do_control_data_increment(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; if ((mdi->channel[ch].reg_non == 0) && (mdi->channel[ch].reg_data == 0x0000)) { /* Pitch Bend Range */ if (mdi->channel[ch].pitch_range < 0x3FFF) mdi->channel[ch].pitch_range++; } } static void do_control_data_decrement(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; if ((mdi->channel[ch].reg_non == 0) && (mdi->channel[ch].reg_data == 0x0000)) { /* Pitch Bend Range */ if (mdi->channel[ch].pitch_range > 0) mdi->channel[ch].pitch_range--; } } static void do_control_non_registered_param(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].reg_non = 1; } static void do_control_registered_param_fine(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].reg_data = (mdi->channel[ch].reg_data & 0x3F80) | data->data; mdi->channel[ch].reg_non = 0; } static void do_control_registered_param_course(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; mdi->channel[ch].reg_data = (mdi->channel[ch].reg_data & 0x7F) | (data->data << 7); mdi->channel[ch].reg_non = 0; } static void do_control_channel_sound_off(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->active = 0; if (note_data->replay) { note_data->replay = NULL; } } note_data = note_data->next; } while (note_data); } } static void do_control_channel_controllers_off(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; mdi->channel[ch].expression = 127; mdi->channel[ch].pressure = 127; mdi->channel[ch].volume = 100; mdi->channel[ch].pan = 0; mdi->channel[ch].balance = 0; mdi->channel[ch].reg_data = 0xffff; mdi->channel[ch].pitch_range = 200; mdi->channel[ch].pitch = 0; mdi->channel[ch].pitch_adjust = 0; mdi->channel[ch].hold = 0; do_pan_adjust(mdi, ch); if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->sample_inc = get_inc(mdi, note_data); note_data->velocity = 0; note_data->vol_lvl = get_volume(mdi, ch, note_data); note_data->hold = 0; if (note_data->replay) { note_data->replay->velocity = data->data; note_data->replay->vol_lvl = get_volume(mdi, ch, note_data->replay); } } note_data = note_data->next; } while (note_data); } } static void do_control_channel_notes_off(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; if (mdi->channel[ch].isdrum) return; if (note_data) { do { if ((note_data->noteid >> 8) == ch) { if (!note_data->hold) { if (note_data->modes & SAMPLE_ENVELOPE) { if (note_data->env < 5) { if (note_data->env_level > note_data->sample->env_target[5]) { note_data->env_inc = -note_data->sample->env_rate[5]; } else { note_data->env_inc = note_data->sample->env_rate[5]; } note_data->env = 5; } } } else { note_data->hold |= HOLD_OFF; } } note_data = note_data->next; } while (note_data); } } static void do_patch(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); if (!mdi->channel[ch].isdrum) { mdi->channel[ch].patch = get_patch_data(mdi, ((mdi->channel[ch].bank << 8) | data->data)); } else { mdi->channel[ch].bank = data->data; } } static void do_channel_pressure(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->velocity = data->data; note_data->vol_lvl = get_volume(mdi, ch, note_data); if (note_data->replay) { note_data->replay->velocity = data->data; note_data->replay->vol_lvl = get_volume(mdi, ch, note_data->replay); } } note_data = note_data->next; } while (note_data); } } static void do_pitch(struct _mdi *mdi, struct _event_data *data) { struct _note *note_data = mdi->note; unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); mdi->channel[ch].pitch = data->data - 0x2000; if (mdi->channel[ch].pitch < 0) { mdi->channel[ch].pitch_adjust = mdi->channel[ch].pitch_range * mdi->channel[ch].pitch / 8192; } else { mdi->channel[ch].pitch_adjust = mdi->channel[ch].pitch_range * mdi->channel[ch].pitch / 8191; } if (note_data) { do { if ((note_data->noteid >> 8) == ch) { note_data->sample_inc = get_inc(mdi, note_data); } note_data = note_data->next; } while (note_data); } } static void do_sysex_roland_drum_track(struct _mdi *mdi, struct _event_data *data) { unsigned char ch = data->channel; MIDI_EVENT_DEBUG(__FUNCTION__,ch); if (data->data > 0) { mdi->channel[ch].isdrum = 1; mdi->channel[ch].patch = NULL; } else { mdi->channel[ch].isdrum = 0; mdi->channel[ch].patch = get_patch_data(mdi, 0); } } static void do_sysex_roland_reset(struct _mdi *mdi, struct _event_data *data) { int i; for (i = 0; i < 16; i++) { mdi->channel[i].bank = 0; if (i != 9) { mdi->channel[i].patch = get_patch_data(mdi, 0); } else { mdi->channel[i].patch = NULL; } mdi->channel[i].hold = 0; mdi->channel[i].volume = 100; mdi->channel[i].pressure = 127; mdi->channel[i].expression = 127; mdi->channel[i].balance = 0; mdi->channel[i].pan = 0; mdi->channel[i].left_adjust = 1; mdi->channel[i].right_adjust = 1; mdi->channel[i].pitch = 0; mdi->channel[i].pitch_range = 200; mdi->channel[i].reg_data = 0xFFFF; mdi->channel[i].isdrum = 0; do_pan_adjust(mdi, i); } mdi->channel[9].isdrum = 1; UNUSED(data); /* NOOP, to please the compiler gods */ } static void WM_ResetToStart(midi * handle) { struct _mdi *mdi = (struct _mdi *) handle; mdi->current_event = mdi->events; mdi->samples_to_mix = 0; mdi->info.current_sample = 0; do_sysex_roland_reset(mdi, NULL); } static int midi_setup_noteoff(struct _mdi *mdi, unsigned char channel, unsigned char note, unsigned char velocity) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_note_off; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = (note << 8) | velocity; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_note_off; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = (note << 8) | velocity; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int midi_setup_noteon(struct _mdi *mdi, unsigned char channel, unsigned char note, unsigned char velocity) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_note_on; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = (note << 8) | velocity; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_note_on; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = (note << 8) | velocity; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } if (mdi->channel[channel].isdrum) load_patch(mdi, ((mdi->channel[channel].bank << 8) | (note | 0x80))); return 0; } static int midi_setup_aftertouch(struct _mdi *mdi, unsigned char channel, unsigned char note, unsigned char pressure) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_aftertouch; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = (note << 8) | pressure; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_aftertouch; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = (note << 8) | pressure; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int midi_setup_control(struct _mdi *mdi, unsigned char channel, unsigned char controller, unsigned char setting) { void (*tmp_event)(struct _mdi *mdi, struct _event_data *data) = NULL; switch (controller) { case 0: tmp_event = *do_control_bank_select; mdi->channel[channel].bank = setting; break; case 6: tmp_event = *do_control_data_entry_course; break; case 7: tmp_event = *do_control_channel_volume; mdi->channel[channel].volume = setting; break; case 8: tmp_event = *do_control_channel_balance; break; case 10: tmp_event = *do_control_channel_pan; break; case 11: tmp_event = *do_control_channel_expression; break; case 38: tmp_event = *do_control_data_entry_fine; break; case 64: tmp_event = *do_control_channel_hold; break; case 96: tmp_event = *do_control_data_increment; break; case 97: tmp_event = *do_control_data_decrement; break; case 98: case 99: tmp_event = *do_control_non_registered_param; break; case 100: tmp_event = *do_control_registered_param_fine; break; case 101: tmp_event = *do_control_registered_param_course; break; case 120: tmp_event = *do_control_channel_sound_off; break; case 121: tmp_event = *do_control_channel_controllers_off; break; case 123: tmp_event = *do_control_channel_notes_off; break; default: return 0; } if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = tmp_event; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = setting; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = tmp_event; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = setting; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int midi_setup_patch(struct _mdi *mdi, unsigned char channel, unsigned char patch) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_patch; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = patch; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_patch; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = patch; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } if (mdi->channel[channel].isdrum) { mdi->channel[channel].bank = patch; } else { load_patch(mdi, ((mdi->channel[channel].bank << 8) | patch)); mdi->channel[channel].patch = get_patch_data(mdi, ((mdi->channel[channel].bank << 8) | patch)); } return 0; } static int midi_setup_channel_pressure(struct _mdi *mdi, unsigned char channel, unsigned char pressure) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_channel_pressure; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = pressure; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_channel_pressure; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = pressure; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int midi_setup_pitch(struct _mdi *mdi, unsigned char channel, unsigned short pitch) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_pitch; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = pitch; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_pitch; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = pitch; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int midi_setup_sysex_roland_drum_track(struct _mdi *mdi, unsigned char channel, unsigned short setting) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_sysex_roland_drum_track; mdi->events[mdi->event_count - 1].event_data.channel = channel; mdi->events[mdi->event_count - 1].event_data.data = setting; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_sysex_roland_drum_track; mdi->events[mdi->event_count].event_data.channel = channel; mdi->events[mdi->event_count].event_data.data = setting; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } if (setting > 0) { mdi->channel[channel].isdrum = 1; } else { mdi->channel[channel].isdrum = 0; } return 0; } static int midi_setup_sysex_roland_reset(struct _mdi *mdi) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].do_event = *do_sysex_roland_reset; mdi->events[mdi->event_count - 1].event_data.channel = 0; mdi->events[mdi->event_count - 1].event_data.data = 0; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = *do_sysex_roland_reset; mdi->events[mdi->event_count].event_data.channel = 0; mdi->events[mdi->event_count].event_data.data = 0; mdi->events[mdi->event_count].samples_to_next = 0; mdi->event_count++; } return 0; } static int add_handle(void * handle) { struct _hndl *tmp_handle = NULL; if (first_handle == NULL) { first_handle = malloc(sizeof(struct _hndl)); if (first_handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, " to get ram", errno); return -1; } first_handle->handle = handle; first_handle->prev = NULL; first_handle->next = NULL; } else { tmp_handle = first_handle; if (tmp_handle->next) { while (tmp_handle->next) tmp_handle = tmp_handle->next; } tmp_handle->next = malloc(sizeof(struct _hndl)); if (tmp_handle->next == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, " to get ram", errno); return -1; } tmp_handle->next->prev = tmp_handle; tmp_handle = tmp_handle->next; tmp_handle->next = NULL; tmp_handle->handle = handle; } return 0; } static struct _mdi * Init_MDI(void) { struct _mdi *mdi; mdi = malloc(sizeof(struct _mdi)); memset(mdi, 0, (sizeof(struct _mdi))); mdi->info.copyright = NULL; mdi->info.mixer_options = WM_MixerOptions; load_patch(mdi, 0x0000); mdi->events_size = MEM_CHUNK; mdi->events = malloc(mdi->events_size * sizeof(struct _event)); mdi->events[0].do_event = NULL; mdi->events[0].event_data.channel = 0; mdi->events[0].event_data.data = 0; mdi->events[0].samples_to_next = 0; mdi->event_count++; mdi->current_event = mdi->events; mdi->samples_to_mix = 0; mdi->info.current_sample = 0; mdi->info.total_midi_time = 0; mdi->info.approx_total_samples = 0; do_sysex_roland_reset(mdi, NULL); return mdi; } static void freeMDI(struct _mdi *mdi) { struct _sample *tmp_sample; unsigned long int i; if (mdi->patch_count != 0) { _WM_Lock(&patch_lock); for (i = 0; i < mdi->patch_count; i++) { mdi->patches[i]->inuse_count--; if (mdi->patches[i]->inuse_count == 0) { /* free samples here */ while (mdi->patches[i]->first_sample) { tmp_sample = mdi->patches[i]->first_sample->next; free(mdi->patches[i]->first_sample->data); free(mdi->patches[i]->first_sample); mdi->patches[i]->first_sample = tmp_sample; } mdi->patches[i]->loaded = 0; } } _WM_Unlock(&patch_lock); free(mdi->patches); } free(mdi->events); free(mdi->tmp_info); _WM_free_reverb(mdi->reverb); free(mdi->mix_buffer); free(mdi); } static unsigned long int get_decay_samples(struct _patch *patch, unsigned char note) { struct _sample *sample = NULL; unsigned long int freq = 0; unsigned long int decay_samples = 0; if (patch == NULL) return 0; /* first get the freq we need so we can check the right sample */ if (patch->patchid & 0x80) { /* is a drum patch */ if (patch->note) { freq = freq_table[(patch->note % 12) * 100] >> (10 - (patch->note / 12)); } else { freq = freq_table[(note % 12) * 100] >> (10 - (note / 12)); } } else { freq = freq_table[(note % 12) * 100] >> (10 - (note / 12)); } /* get the sample */ sample = get_sample_data(patch, (freq / 100)); if (sample == NULL) return 0; if (patch->patchid & 0x80) { float sratedata = ((float) sample->rate / (float) _WM_SampleRate) * (float) (sample->data_length >> 10); decay_samples = (unsigned long int) sratedata; /* printf("Drums (%i / %i) * %lu = %f\n", sample->rate, _WM_SampleRate, (sample->data_length >> 10), sratedata);*/ } else if (sample->modes & SAMPLE_CLAMPED) { decay_samples = (4194303 / sample->env_rate[5]); /* printf("clamped 4194303 / %lu = %lu\n", sample->env_rate[5], decay_samples);*/ } else { decay_samples = ((4194303 - sample->env_target[4]) / sample->env_rate[4]) + (sample->env_target[4] / sample->env_rate[5]); /* printf("NOT clamped ((4194303 - %lu) / %lu) + (%lu / %lu)) = %lu\n", sample->env_target[4], sample->env_rate[4], sample->env_target[4], sample->env_rate[5], decay_samples);*/ } return decay_samples; } static struct _mdi * WM_ParseNewMidi(unsigned char *midi_data, unsigned int midi_size) { struct _mdi *mdi; unsigned int tmp_val; unsigned int midi_type; unsigned int track_size; unsigned char **tracks; unsigned int end_of_tracks = 0; unsigned int no_tracks; unsigned int i; unsigned int divisions = 96; unsigned int tempo = 500000; float samples_per_delta_f = 0.0; float microseconds_per_pulse = 0.0; float pulses_per_second = 0.0; unsigned long int sample_count = 0; float sample_count_tmp = 0; float sample_remainder = 0; unsigned char *sysex_store = NULL; unsigned long int sysex_store_len = 0; unsigned long int *track_delta; unsigned char *track_end; unsigned long int smallest_delta = 0; unsigned long int subtract_delta = 0; unsigned long int tmp_length = 0; unsigned char current_event = 0; unsigned char current_event_ch = 0; unsigned char *running_event; unsigned long int decay_samples = 0; if (memcmp(midi_data, "RIFF", 4) == 0) { midi_data += 20; midi_size -= 20; } if (memcmp(midi_data, "MThd", 4)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_MIDI, NULL, 0); return NULL; } midi_data += 4; midi_size -= 4; if (midi_size < 10) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(too short)", 0); return NULL; } /* * Get Midi Header Size - must always be 6 */ tmp_val = *midi_data++ << 24; tmp_val |= *midi_data++ << 16; tmp_val |= *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 4; if (tmp_val != 6) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, NULL, 0); return NULL; } /* * Get Midi Format - we only support 0, 1 & 2 */ tmp_val = *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 2; if (tmp_val > 2) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, NULL, 0); return NULL; } midi_type = tmp_val; /* * Get No. of Tracks */ tmp_val = *midi_data++ << 8; tmp_val |= *midi_data++; midi_size -= 2; if (tmp_val < 1) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(no tracks)", 0); return NULL; } no_tracks = tmp_val; /* * Check that type 0 midi file has only 1 track */ if ((midi_type == 0) && (no_tracks > 1)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, "(expected 1 track for type 0 midi file, found more)", 0); return NULL; } /* * Get Divisions */ divisions = *midi_data++ << 8; divisions |= *midi_data++; midi_size -= 2; if (divisions & 0x00008000) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID, NULL, 0); return NULL; } if ((WM_MixerOptions & WM_MO_WHOLETEMPO)) { float bpm_f = (float) (60000000 / tempo); tempo = 60000000 / (unsigned long int) bpm_f; } else if ((WM_MixerOptions & WM_MO_ROUNDTEMPO)) { float bpm_fr = (float) (60000000 / tempo) + 0.5f; tempo = 60000000 / (unsigned long int) bpm_fr; } /* Slow but needed for accuracy */ microseconds_per_pulse = (float) tempo / (float) divisions; pulses_per_second = 1000000.0f / microseconds_per_pulse; samples_per_delta_f = (float) _WM_SampleRate / pulses_per_second; mdi = Init_MDI(); tracks = malloc(sizeof(unsigned char *) * no_tracks); track_delta = malloc(sizeof(unsigned long int) * no_tracks); track_end = malloc(sizeof(unsigned char) * no_tracks); running_event = malloc(sizeof(unsigned char) * no_tracks); for (i = 0; i < no_tracks; i++) { if (midi_size < 8) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(too short)", 0); goto _end; } if (memcmp(midi_data, "MTrk", 4) != 0) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(missing track header)", 0); goto _end; } midi_data += 4; midi_size -= 4; track_size = *midi_data++ << 24; track_size |= *midi_data++ << 16; track_size |= *midi_data++ << 8; track_size |= *midi_data++; midi_size -= 4; if (midi_size < track_size) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(too short)", 0); goto _end; } if ((midi_data[track_size - 3] != 0xFF) || (midi_data[track_size - 2] != 0x2F) || (midi_data[track_size - 1] != 0x00)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(missing EOT)", 0); goto _end; } tracks[i] = midi_data; midi_data += track_size; midi_size -= track_size; track_end[i] = 0; running_event[i] = 0; track_delta[i] = 0; decay_samples = 0; while (*tracks[i] > 0x7F) { track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; } track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; } /* * Handle type 0 & 1 the same, but type 2 differently */ switch (midi_type) { case 0: case 1: /* Type 0 & 1 can use the same code */ while (end_of_tracks != no_tracks) { smallest_delta = 0; for (i = 0; i < no_tracks; i++) { if (track_end[i]) continue; if (track_delta[i]) { track_delta[i] -= subtract_delta; if (track_delta[i]) { if ((!smallest_delta) || (smallest_delta > track_delta[i])) { smallest_delta = track_delta[i]; } continue; } } do { if (*tracks[i] > 0x7F) { current_event = *tracks[i]; tracks[i]++; } else { current_event = running_event[i]; if (running_event[i] < 0x80) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(missing event)", 0); goto _end; } } current_event_ch = current_event & 0x0F; switch (current_event >> 4) { case 0x8: NOTEOFF: midi_setup_noteoff(mdi, current_event_ch, tracks[i][0], tracks[i][1]); /* To better calculate samples needed after the end of midi, * we calculate samples for decay for note off */ { unsigned long int tmp_decay_samples = 0; struct _patch *tmp_patch = NULL; if (mdi->channel[current_event_ch].isdrum) { tmp_patch = get_patch_data(mdi, ((mdi->channel[current_event_ch].bank << 8) | tracks[i][0] | 0x80)); /* if (tmp_patch == NULL) printf("Drum patch not loaded 0x%02x on channel %i\n",((mdi->channel[current_event_ch].bank << 8) | tracks[i][0] | 0x80),current_event_ch);*/ } else { tmp_patch = mdi->channel[current_event_ch].patch; /* if (tmp_patch == NULL) printf("Channel %i patch not loaded\n", current_event_ch);*/ } tmp_decay_samples = get_decay_samples(tmp_patch, tracks[i][0]); /* if the note off decay is more than the decay we currently tracking then * we set it to new decay. */ if (tmp_decay_samples > decay_samples) { decay_samples = tmp_decay_samples; } } tracks[i] += 2; running_event[i] = current_event; break; case 0x9: if (tracks[i][1] == 0) { goto NOTEOFF; } midi_setup_noteon(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xA: midi_setup_aftertouch(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xB: midi_setup_control(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xC: midi_setup_patch(mdi, (current_event & 0x0F), *tracks[i]); tracks[i]++; running_event[i] = current_event; break; case 0xD: midi_setup_channel_pressure(mdi, (current_event & 0x0F), *tracks[i]); tracks[i]++; running_event[i] = current_event; break; case 0xE: midi_setup_pitch(mdi, (current_event & 0x0F), ((tracks[i][1] << 7) | (tracks[i][0] & 0x7F))); tracks[i] += 2; running_event[i] = current_event; break; case 0xF: /* Meta Event */ if (current_event == 0xFF) { if (tracks[i][0] == 0x02) { /* Copyright Event */ /* Get Length */ tmp_length = 0; tracks[i]++; while (*tracks[i] > 0x7f) { tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i]++; } tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); /* Copy copyright info in the getinfo struct */ if (mdi->info.copyright) { mdi->info.copyright = realloc( mdi->info.copyright, (strlen(mdi->info.copyright) + 1 + tmp_length + 1)); strncpy( &mdi->info.copyright[strlen( mdi->info.copyright) + 1], (char *) tracks[i], tmp_length); mdi->info.copyright[strlen(mdi->info.copyright) + 1 + tmp_length] = '\0'; mdi->info.copyright[strlen(mdi->info.copyright)] = '\n'; } else { mdi->info.copyright = malloc(tmp_length + 1); strncpy(mdi->info.copyright, (char *) tracks[i], tmp_length); mdi->info.copyright[tmp_length] = '\0'; } tracks[i] += tmp_length + 1; } else if ((tracks[i][0] == 0x2F) && (tracks[i][1] == 0x00)) { /* End of Track */ end_of_tracks++; track_end[i] = 1; goto NEXT_TRACK; } else if ((tracks[i][0] == 0x51) && (tracks[i][1] == 0x03)) { /* Tempo */ tempo = (tracks[i][2] << 16) + (tracks[i][3] << 8) + tracks[i][4]; tracks[i] += 5; if (!tempo) tempo = 500000; if ((WM_MixerOptions & WM_MO_WHOLETEMPO)) { float bpm_f = (float) (60000000 / tempo); tempo = 60000000 / (unsigned long int) bpm_f; } else if ((WM_MixerOptions & WM_MO_ROUNDTEMPO)) { float bpm_fr = (float) (60000000 / tempo) + 0.5f; tempo = 60000000 / (unsigned long int) bpm_fr; } /* Slow but needed for accuracy */ microseconds_per_pulse = (float) tempo / (float) divisions; pulses_per_second = 1000000.0f / microseconds_per_pulse; samples_per_delta_f = (float) _WM_SampleRate / pulses_per_second; } else { tmp_length = 0; tracks[i]++; while (*tracks[i] > 0x7f) { tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i]++; } tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i] += tmp_length + 1; } } else if ((current_event == 0xF0) || (current_event == 0xF7)) { /* Roland Sysex Events */ unsigned long int sysex_len = 0; while (*tracks[i] > 0x7F) { sysex_len = (sysex_len << 7) + (*tracks[i] & 0x7F); tracks[i]++; } sysex_len = (sysex_len << 7) + (*tracks[i] & 0x7F); tracks[i]++; running_event[i] = 0; sysex_store = realloc(sysex_store, sizeof(unsigned char) * (sysex_store_len + sysex_len)); memcpy(&sysex_store[sysex_store_len], tracks[i], sysex_len); sysex_store_len += sysex_len; if (sysex_store[sysex_store_len - 1] == 0xF7) { unsigned char tmpsysexdata[] = { 0x41, 0x10, 0x42, 0x12 }; if (memcmp(tmpsysexdata, sysex_store, 4) == 0) { /* checksum */ unsigned char sysex_cs = 0; unsigned int sysex_ofs = 4; do { sysex_cs += sysex_store[sysex_ofs]; if (sysex_cs > 0x7F) { sysex_cs -= 0x80; } sysex_ofs++; } while (sysex_store[sysex_ofs + 1] != 0xF7); sysex_cs = 128 - sysex_cs; /* is roland sysex message valid */ if (sysex_cs == sysex_store[sysex_ofs]) { /* process roland sysex event */ if (sysex_store[4] == 0x40) { if (((sysex_store[5] & 0xF0) == 0x10) && (sysex_store[6] == 0x15)) { /* Roland Drum Track Setting */ unsigned char sysex_ch = 0x0F & sysex_store[5]; if (sysex_ch == 0x00) { sysex_ch = 0x09; } else if (sysex_ch <= 0x09) { sysex_ch -= 1; } midi_setup_sysex_roland_drum_track( mdi, sysex_ch, sysex_store[7]); } else if ((sysex_store[5] == 0x00) && (sysex_store[6] == 0x7F) && (sysex_store[7] == 0x00)) { /* Roland GS Reset */ midi_setup_sysex_roland_reset(mdi); } } } } free(sysex_store); sysex_store = NULL; sysex_store_len = 0; } tracks[i] += sysex_len; } else { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(unrecognized meta event)", 0); goto _end; } break; default: _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(unrecognized event)", 0); goto _end; } while (*tracks[i] > 0x7F) { track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; } track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; } while (!track_delta[i]); if ((!smallest_delta) || (smallest_delta > track_delta[i])) { smallest_delta = track_delta[i]; } NEXT_TRACK: continue; } subtract_delta = smallest_delta; sample_count_tmp = (((float) smallest_delta * samples_per_delta_f) + sample_remainder); sample_count = (unsigned long int) sample_count_tmp; sample_remainder = sample_count_tmp - (float) sample_count; if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].samples_to_next += sample_count; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = NULL; mdi->events[mdi->event_count].event_data.channel = 0; mdi->events[mdi->event_count].event_data.data = 0; mdi->events[mdi->event_count].samples_to_next = sample_count; mdi->event_count++; } mdi->info.approx_total_samples += sample_count; /* printf("Decay Samples = %lu\n",decay_samples);*/ if (decay_samples > sample_count) { decay_samples -= sample_count; } else { decay_samples = 0; } } break; case 2: /* Type 2 has to be handled differently */ for (i = 0; i < no_tracks; i++) { sample_remainder = 0.0; decay_samples = 0; track_delta[i] = 0; do { if(track_delta[i]) { sample_count_tmp = (((float) track_delta[i] * samples_per_delta_f) + sample_remainder); sample_count = (unsigned long int) sample_count_tmp; sample_remainder = sample_count_tmp - (float) sample_count; if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].samples_to_next += sample_count; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = NULL; mdi->events[mdi->event_count].event_data.channel = 0; mdi->events[mdi->event_count].event_data.data = 0; mdi->events[mdi->event_count].samples_to_next = sample_count; mdi->event_count++; } mdi->info.approx_total_samples += sample_count; /* printf("Decay Samples = %lu\n",decay_samples);*/ if (decay_samples > sample_count) { decay_samples -= sample_count; } else { decay_samples = 0; } } if (*tracks[i] > 0x7F) { current_event = *tracks[i]; tracks[i]++; } else { current_event = running_event[i]; if (running_event[i] < 0x80) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(missing event)", 0); goto _end; } } current_event_ch = current_event & 0x0F; switch (current_event >> 4) { case 0x8: NOTEOFF2: midi_setup_noteoff(mdi, current_event_ch, tracks[i][0], tracks[i][1]); /* To better calculate samples needed after the end of midi, * we calculate samples for decay for note off */ { unsigned long int tmp_decay_samples = 0; struct _patch *tmp_patch = NULL; if (mdi->channel[current_event_ch].isdrum) { tmp_patch = get_patch_data(mdi, ((mdi->channel[current_event_ch].bank << 8) | tracks[i][0] | 0x80)); /* if (tmp_patch == NULL) printf("Drum patch not loaded 0x%02x on channel %i\n",((mdi->channel[current_event_ch].bank << 8) | tracks[i][0] | 0x80),current_event_ch);*/ } else { tmp_patch = mdi->channel[current_event_ch].patch; /* if (tmp_patch == NULL) printf("Channel %i patch not loaded\n", current_event_ch);*/ } tmp_decay_samples = get_decay_samples(tmp_patch, tracks[i][0]); /* if the note off decay is more than the decay we currently tracking then * we set it to new decay. */ if (tmp_decay_samples > decay_samples) { decay_samples = tmp_decay_samples; } } tracks[i] += 2; running_event[i] = current_event; break; case 0x9: if (tracks[i][1] == 0) { goto NOTEOFF2; } midi_setup_noteon(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xA: midi_setup_aftertouch(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xB: midi_setup_control(mdi, (current_event & 0x0F), tracks[i][0], tracks[i][1]); tracks[i] += 2; running_event[i] = current_event; break; case 0xC: midi_setup_patch(mdi, (current_event & 0x0F), *tracks[i]); tracks[i]++; running_event[i] = current_event; break; case 0xD: midi_setup_channel_pressure(mdi, (current_event & 0x0F), *tracks[i]); tracks[i]++; running_event[i] = current_event; break; case 0xE: midi_setup_pitch(mdi, (current_event & 0x0F), ((tracks[i][1] << 7) | (tracks[i][0] & 0x7F))); tracks[i] += 2; running_event[i] = current_event; break; case 0xF: /* Meta Event */ if (current_event == 0xFF) { if (tracks[i][0] == 0x02) { /* Copyright Event */ /* Get Length */ tmp_length = 0; tracks[i]++; while (*tracks[i] > 0x7f) { tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i]++; } tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); /* Copy copyright info in the getinfo struct */ if (mdi->info.copyright) { mdi->info.copyright = realloc( mdi->info.copyright, (strlen(mdi->info.copyright) + 1 + tmp_length + 1)); strncpy( &mdi->info.copyright[strlen( mdi->info.copyright) + 1], (char *) tracks[i], tmp_length); mdi->info.copyright[strlen(mdi->info.copyright) + 1 + tmp_length] = '\0'; mdi->info.copyright[strlen(mdi->info.copyright)] = '\n'; } else { mdi->info.copyright = malloc(tmp_length + 1); strncpy(mdi->info.copyright, (char *) tracks[i], tmp_length); mdi->info.copyright[tmp_length] = '\0'; } tracks[i] += tmp_length + 1; } else if ((tracks[i][0] == 0x2F) && (tracks[i][1] == 0x00)) { /* End of Track */ end_of_tracks++; track_end[i] = 1; goto NEXT_TRACK2; } else if ((tracks[i][0] == 0x51) && (tracks[i][1] == 0x03)) { /* Tempo */ tempo = (tracks[i][2] << 16) + (tracks[i][3] << 8) + tracks[i][4]; tracks[i] += 5; if (!tempo) tempo = 500000; if ((WM_MixerOptions & WM_MO_WHOLETEMPO)) { float bpm_f = (float) (60000000 / tempo); tempo = 60000000 / (unsigned long int) bpm_f; } else if ((WM_MixerOptions & WM_MO_ROUNDTEMPO)) { float bpm_fr = (float) (60000000 / tempo) + 0.5f; tempo = 60000000 / (unsigned long int) bpm_fr; } /* Slow but needed for accuracy */ microseconds_per_pulse = (float) tempo / (float) divisions; pulses_per_second = 1000000.0f / microseconds_per_pulse; samples_per_delta_f = (float) _WM_SampleRate / pulses_per_second; } else { tmp_length = 0; tracks[i]++; while (*tracks[i] > 0x7f) { tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i]++; } tmp_length = (tmp_length << 7) + (*tracks[i] & 0x7f); tracks[i] += tmp_length + 1; } } else if ((current_event == 0xF0) || (current_event == 0xF7)) { /* Roland Sysex Events */ unsigned long int sysex_len = 0; while (*tracks[i] > 0x7F) { sysex_len = (sysex_len << 7) + (*tracks[i] & 0x7F); tracks[i]++; } sysex_len = (sysex_len << 7) + (*tracks[i] & 0x7F); tracks[i]++; running_event[i] = 0; sysex_store = realloc(sysex_store, sizeof(unsigned char) * (sysex_store_len + sysex_len)); memcpy(&sysex_store[sysex_store_len], tracks[i], sysex_len); sysex_store_len += sysex_len; if (sysex_store[sysex_store_len - 1] == 0xF7) { unsigned char tmpsysexdata[] = { 0x41, 0x10, 0x42, 0x12 }; if (memcmp(tmpsysexdata, sysex_store, 4) == 0) { /* checksum */ unsigned char sysex_cs = 0; unsigned int sysex_ofs = 4; do { sysex_cs += sysex_store[sysex_ofs]; if (sysex_cs > 0x7F) { sysex_cs -= 0x80; } sysex_ofs++; } while (sysex_store[sysex_ofs + 1] != 0xF7); sysex_cs = 128 - sysex_cs; /* is roland sysex message valid */ if (sysex_cs == sysex_store[sysex_ofs]) { /* process roland sysex event */ if (sysex_store[4] == 0x40) { if (((sysex_store[5] & 0xF0) == 0x10) && (sysex_store[6] == 0x15)) { /* Roland Drum Track Setting */ unsigned char sysex_ch = 0x0F & sysex_store[5]; if (sysex_ch == 0x00) { sysex_ch = 0x09; } else if (sysex_ch <= 0x09) { sysex_ch -= 1; } midi_setup_sysex_roland_drum_track( mdi, sysex_ch, sysex_store[7]); } else if ((sysex_store[5] == 0x00) && (sysex_store[6] == 0x7F) && (sysex_store[7] == 0x00)) { /* Roland GS Reset */ midi_setup_sysex_roland_reset(mdi); } } } } free(sysex_store); sysex_store = NULL; sysex_store_len = 0; } tracks[i] += sysex_len; } else { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(unrecognized meta event)", 0); goto _end; } break; default: _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_CORUPT, "(unrecognized event)", 0); goto _end; } track_delta[i] = 0; while (*tracks[i] > 0x7F) { track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; } track_delta[i] = (track_delta[i] << 7) + (*tracks[i] & 0x7F); tracks[i]++; NEXT_TRACK2: smallest_delta = track_delta[i]; /* Added just to keep Xcode happy */ UNUSED(smallest_delta); /* Added to just keep clang happy */ } while (track_end[i] == 0); /* * Add decay at the end of each song */ if (decay_samples) { if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->events[mdi->event_count - 1].samples_to_next += decay_samples; } else { WM_CheckEventMemoryPool(mdi); mdi->events[mdi->event_count].do_event = NULL; mdi->events[mdi->event_count].event_data.channel = 0; mdi->events[mdi->event_count].event_data.data = 0; mdi->events[mdi->event_count].samples_to_next = decay_samples; mdi->event_count++; } } } break; default: break; /* Don't expect to get here, added for completeness */ } if ((mdi->event_count) && (mdi->events[mdi->event_count - 1].do_event == NULL)) { mdi->info.approx_total_samples -= mdi->events[mdi->event_count - 1].samples_to_next; mdi->event_count--; } /* Set total MIDI time to 1/1000's seconds */ mdi->info.total_midi_time = (mdi->info.approx_total_samples * 1000) / _WM_SampleRate; /*mdi->info.approx_total_samples += _WM_SampleRate * 3;*/ /* Add additional samples needed for decay */ mdi->info.approx_total_samples += decay_samples; /*printf("decay_samples = %lu\n",decay_samples);*/ if ((mdi->reverb = _WM_init_reverb(_WM_SampleRate, reverb_room_width, reverb_room_length, reverb_listen_posx, reverb_listen_posy)) == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to init reverb", 0); goto _end; } mdi->info.current_sample = 0; mdi->current_event = &mdi->events[0]; mdi->samples_to_mix = 0; mdi->note = NULL; WM_ResetToStart(mdi); _end: free(sysex_store); free(track_end); free(track_delta); free(running_event); free(tracks); if (mdi->reverb) return mdi; freeMDI(mdi); return NULL; } static int WM_GetOutput_Linear(midi * handle, char * buffer, unsigned long int size) { unsigned long int buffer_used = 0; unsigned long int i; struct _mdi *mdi = (struct _mdi *) handle; unsigned long int real_samples_to_mix = 0; unsigned long int data_pos; signed long int premix, left_mix, right_mix; signed long int vol_mul; struct _note *note_data = NULL; unsigned long int count; struct _event *event = mdi->current_event; signed long int *tmp_buffer; signed long int *out_buffer; _WM_Lock(&mdi->lock); buffer_used = 0; memset(buffer, 0, size); if ( (size / 2) > mdi->mix_buffer_size) { if ( (size / 2) <= ( mdi->mix_buffer_size * 2 )) { mdi->mix_buffer_size += MEM_CHUNK; } else { mdi->mix_buffer_size = size / 2; } mdi->mix_buffer = realloc(mdi->mix_buffer, mdi->mix_buffer_size * sizeof(signed long int)); } tmp_buffer = mdi->mix_buffer; memset(tmp_buffer, 0, ((size / 2) * sizeof(signed long int))); out_buffer = tmp_buffer; do { if (__builtin_expect((!mdi->samples_to_mix), 0)) { while ((!mdi->samples_to_mix) && (event->do_event)) { event->do_event(mdi, &event->event_data); event++; mdi->samples_to_mix = event->samples_to_next; mdi->current_event = event; } if (!mdi->samples_to_mix) { if (mdi->info.current_sample >= mdi->info.approx_total_samples) { break; } else if ((mdi->info.approx_total_samples - mdi->info.current_sample) > (size >> 2)) { mdi->samples_to_mix = size >> 2; } else { mdi->samples_to_mix = mdi->info.approx_total_samples - mdi->info.current_sample; } } } if (__builtin_expect((mdi->samples_to_mix > (size >> 2)), 1)) { real_samples_to_mix = size >> 2; } else { real_samples_to_mix = mdi->samples_to_mix; if (real_samples_to_mix == 0) { continue; } } /* do mixing here */ count = real_samples_to_mix; do { note_data = mdi->note; left_mix = right_mix = 0; if (__builtin_expect((note_data != NULL), 1)) { while (note_data) { /* * =================== * resample the sample * =================== */ data_pos = note_data->sample_pos >> FPBITS; vol_mul = ((note_data->vol_lvl * (note_data->env_level >> 12)) >> FPBITS); premix = (note_data->sample->data[data_pos] + ((note_data->sample->data[data_pos + 1] - note_data->sample->data[data_pos]) * (signed long int) (note_data->sample_pos & FPMASK)>> FPBITS)) * vol_mul / 1024; left_mix += premix * mdi->channel[note_data->noteid >> 8].left_adjust; right_mix += premix * mdi->channel[note_data->noteid >> 8].right_adjust; /* * ======================== * sample position checking * ======================== */ note_data->sample_pos += note_data->sample_inc; if (__builtin_expect( (note_data->sample_pos > note_data->sample->loop_end), 0)) { if (note_data->modes & SAMPLE_LOOP) { note_data->sample_pos = note_data->sample->loop_start + ((note_data->sample_pos - note_data->sample->loop_start) % note_data->sample->loop_size); } else if (__builtin_expect( (note_data->sample_pos >= note_data->sample->data_length), 0)) { if (__builtin_expect((note_data->replay == NULL), 1)) { goto KILL_NOTE; } goto RESTART_NOTE; } } if (__builtin_expect((note_data->env_inc == 0), 0)) { note_data = note_data->next; continue; } note_data->env_level += note_data->env_inc; if (__builtin_expect((note_data->env_level > 4194304), 0)) { note_data->env_level = note_data->sample->env_target[note_data->env]; } if (__builtin_expect( ((note_data->env_inc < 0) && (note_data->env_level > note_data->sample->env_target[note_data->env])) || ((note_data->env_inc > 0) && (note_data->env_level < note_data->sample->env_target[note_data->env])), 1)) { note_data = note_data->next; continue; } note_data->env_level = note_data->sample->env_target[note_data->env]; switch (note_data->env) { case 0: #if 0 if (!(note_data->modes & SAMPLE_ENVELOPE)) { note_data->env_inc = 0; note_data = note_data->next; continue; } #endif break; case 2: if (note_data->modes & SAMPLE_SUSTAIN) { note_data->env_inc = 0; note_data = note_data->next; continue; } else if (note_data->modes & SAMPLE_CLAMPED) { note_data->env = 5; if (note_data->env_level > note_data->sample->env_target[5]) { note_data->env_inc = -note_data->sample->env_rate[5]; } else { note_data->env_inc = note_data->sample->env_rate[5]; } continue; } break; case 5: if (__builtin_expect((note_data->env_level == 0), 1)) { goto KILL_NOTE; } /* sample release */ if (note_data->modes & SAMPLE_LOOP) note_data->modes ^= SAMPLE_LOOP; note_data->env_inc = 0; note_data = note_data->next; continue; case 6: if (__builtin_expect((note_data->replay != NULL), 1)) { RESTART_NOTE: note_data->active = 0; { struct _note *prev_note = NULL; struct _note *nte_array = mdi->note; if (nte_array != note_data) { do { prev_note = nte_array; nte_array = nte_array->next; } while (nte_array != note_data); } if (prev_note) { prev_note->next = note_data->replay; } else { mdi->note = note_data->replay; } note_data->replay->next = note_data->next; note_data = note_data->replay; note_data->active = 1; } } else { KILL_NOTE: note_data->active = 0; { struct _note *prev_note = NULL; struct _note *nte_array = mdi->note; if (nte_array != note_data) { do { prev_note = nte_array; nte_array = nte_array->next; } while ((nte_array != note_data) && (nte_array)); } if (prev_note) { prev_note->next = note_data->next; } else { mdi->note = note_data->next; } note_data = note_data->next; } } continue; } note_data->env++; if (note_data->is_off == 1) { do_note_off_extra(note_data); } if (note_data->env_level > note_data->sample->env_target[note_data->env]) { note_data->env_inc = -note_data->sample->env_rate[note_data->env]; } else { note_data->env_inc = note_data->sample->env_rate[note_data->env]; } note_data = note_data->next; continue; } /* * ========================= * mix the channels together * ========================= */ left_mix /= 1024; right_mix /= 1024; } *tmp_buffer++ = left_mix; *tmp_buffer++ = right_mix; } while (--count); buffer_used += real_samples_to_mix * 4; size -= (real_samples_to_mix << 2); mdi->info.current_sample += real_samples_to_mix; mdi->samples_to_mix -= real_samples_to_mix; } while (size); tmp_buffer = out_buffer; if (mdi->info.mixer_options & WM_MO_REVERB) { _WM_do_reverb(mdi->reverb, tmp_buffer, (buffer_used / 2)); } for (i = 0; i < buffer_used; i += 4) { left_mix = *tmp_buffer++; right_mix = *tmp_buffer++; if (left_mix > 32767) { left_mix = 32767; } else if (left_mix < -32768) { left_mix = -32768; } if (right_mix > 32767) { right_mix = 32767; } else if (right_mix < -32768) { right_mix = -32768; } /* * =================== * Write to the buffer * =================== */ (*buffer++) = left_mix & 0xff; (*buffer++) = ((left_mix >> 8) & 0x7f) | ((left_mix >> 24) & 0x80); (*buffer++) = right_mix & 0xff; (*buffer++) = ((right_mix >> 8) & 0x7f) | ((right_mix >> 24) & 0x80); } _WM_Unlock(&mdi->lock); return buffer_used; } static int WM_GetOutput_Gauss(midi * handle, char * buffer, unsigned long int size) { unsigned long int buffer_used = 0; unsigned long int i; struct _mdi *mdi = (struct _mdi *) handle; unsigned long int real_samples_to_mix = 0; unsigned long int data_pos; signed long int premix, left_mix, right_mix; signed long int vol_mul; struct _note *note_data = NULL; unsigned long int count; signed short int *sptr; double y, xd; double *gptr, *gend; int left, right, temp_n; int ii, jj; struct _event *event = mdi->current_event; signed long int *tmp_buffer; signed long int *out_buffer; _WM_Lock(&mdi->lock); buffer_used = 0; memset(buffer, 0, size); if ( (size / 2) > mdi->mix_buffer_size) { if ( (size / 2) <= ( mdi->mix_buffer_size * 2 )) { mdi->mix_buffer_size += MEM_CHUNK; } else { mdi->mix_buffer_size = size / 2; } mdi->mix_buffer = realloc(mdi->mix_buffer, mdi->mix_buffer_size * sizeof(signed long int)); } tmp_buffer = mdi->mix_buffer; memset(tmp_buffer, 0, ((size / 2) * sizeof(signed long int))); out_buffer = tmp_buffer; do { if (__builtin_expect((!mdi->samples_to_mix), 0)) { while ((!mdi->samples_to_mix) && (event->do_event)) { event->do_event(mdi, &event->event_data); event++; mdi->samples_to_mix = event->samples_to_next; mdi->current_event = event; } if (!mdi->samples_to_mix) { if (mdi->info.current_sample >= mdi->info.approx_total_samples) { break; } else if ((mdi->info.approx_total_samples - mdi->info.current_sample) > (size >> 2)) { mdi->samples_to_mix = size >> 2; } else { mdi->samples_to_mix = mdi->info.approx_total_samples - mdi->info.current_sample; } } } if (__builtin_expect((mdi->samples_to_mix > (size >> 2)), 1)) { real_samples_to_mix = size >> 2; } else { real_samples_to_mix = mdi->samples_to_mix; if (real_samples_to_mix == 0) { continue; } } /* do mixing here */ count = real_samples_to_mix; do { note_data = mdi->note; left_mix = right_mix = 0; if (__builtin_expect((note_data != NULL), 1)) { while (note_data) { /* * =================== * resample the sample * =================== */ data_pos = note_data->sample_pos >> FPBITS; vol_mul = ((note_data->vol_lvl * (note_data->env_level >> 12)) >> FPBITS); /* check to see if we're near one of the ends */ left = data_pos; right = (note_data->sample->data_length >> FPBITS) - left - 1; temp_n = (right << 1) - 1; if (temp_n <= 0) temp_n = 1; if (temp_n > (left << 1) + 1) temp_n = (left << 1) + 1; /* use Newton if we can't fill the window */ if (temp_n < gauss_n) { xd = note_data->sample_pos & FPMASK; xd /= (1L << FPBITS); xd += temp_n >> 1; y = 0; sptr = note_data->sample->data + (note_data->sample_pos >> FPBITS) - (temp_n >> 1); for (ii = temp_n; ii;) { for (jj = 0; jj <= ii; jj++) y += sptr[jj] * newt_coeffs[ii][jj]; y *= xd - --ii; } y += *sptr; } else { /* otherwise, use Gauss as usual */ y = 0; gptr = &gauss_table[(note_data->sample_pos & FPMASK) * (gauss_n + 1)]; gend = gptr + gauss_n; sptr = note_data->sample->data + (note_data->sample_pos >> FPBITS) - (gauss_n >> 1); do { y += *(sptr++) * *(gptr++); } while (gptr <= gend); } premix = (long) (y * vol_mul / 1024); left_mix += premix * mdi->channel[note_data->noteid >> 8].left_adjust; right_mix += premix * mdi->channel[note_data->noteid >> 8].right_adjust; /* * ======================== * sample position checking * ======================== */ note_data->sample_pos += note_data->sample_inc; if (__builtin_expect( (note_data->sample_pos > note_data->sample->loop_end), 0)) { if (note_data->modes & SAMPLE_LOOP) { note_data->sample_pos = note_data->sample->loop_start + ((note_data->sample_pos - note_data->sample->loop_start) % note_data->sample->loop_size); } else if (__builtin_expect( (note_data->sample_pos >= note_data->sample->data_length), 0)) { if (__builtin_expect((note_data->replay == NULL), 1)) { goto KILL_NOTE; } goto RESTART_NOTE; } } if (__builtin_expect((note_data->env_inc == 0), 0)) { note_data = note_data->next; continue; } note_data->env_level += note_data->env_inc; if (__builtin_expect((note_data->env_level > 4194304), 0)) { note_data->env_level = note_data->sample->env_target[note_data->env]; } if (__builtin_expect( ((note_data->env_inc < 0) && (note_data->env_level > note_data->sample->env_target[note_data->env])) || ((note_data->env_inc > 0) && (note_data->env_level < note_data->sample->env_target[note_data->env])), 1)) { note_data = note_data->next; continue; } note_data->env_level = note_data->sample->env_target[note_data->env]; switch (note_data->env) { case 0: #if 0 if (!(note_data->modes & SAMPLE_ENVELOPE)) { note_data->env_inc = 0; note_data = note_data->next; continue; } #endif break; case 2: if (note_data->modes & SAMPLE_SUSTAIN) { note_data->env_inc = 0; note_data = note_data->next; continue; } else if (note_data->modes & SAMPLE_CLAMPED) { note_data->env = 5; if (note_data->env_level > note_data->sample->env_target[5]) { note_data->env_inc = -note_data->sample->env_rate[5]; } else { note_data->env_inc = note_data->sample->env_rate[5]; } continue; } break; case 5: if (__builtin_expect((note_data->env_level == 0), 1)) { goto KILL_NOTE; } /* sample release */ if (note_data->modes & SAMPLE_LOOP) note_data->modes ^= SAMPLE_LOOP; note_data->env_inc = 0; note_data = note_data->next; continue; case 6: if (__builtin_expect((note_data->replay != NULL), 1)) { RESTART_NOTE: note_data->active = 0; { struct _note *prev_note = NULL; struct _note *nte_array = mdi->note; if (nte_array != note_data) { do { prev_note = nte_array; nte_array = nte_array->next; } while (nte_array != note_data); } if (prev_note) { prev_note->next = note_data->replay; } else { mdi->note = note_data->replay; } note_data->replay->next = note_data->next; note_data = note_data->replay; note_data->active = 1; } } else { KILL_NOTE: note_data->active = 0; { struct _note *prev_note = NULL; struct _note *nte_array = mdi->note; if (nte_array != note_data) { do { prev_note = nte_array; nte_array = nte_array->next; } while ((nte_array != note_data) && (nte_array)); } if (prev_note) { prev_note->next = note_data->next; } else { mdi->note = note_data->next; } note_data = note_data->next; } } continue; } note_data->env++; if (note_data->is_off == 1) { do_note_off_extra(note_data); } if (note_data->env_level > note_data->sample->env_target[note_data->env]) { note_data->env_inc = -note_data->sample->env_rate[note_data->env]; } else { note_data->env_inc = note_data->sample->env_rate[note_data->env]; } note_data = note_data->next; continue; } /* * ========================= * mix the channels together * ========================= */ left_mix /= 1024; right_mix /= 1024; } *tmp_buffer++ = left_mix; *tmp_buffer++ = right_mix; } while (--count); buffer_used += real_samples_to_mix * 4; size -= (real_samples_to_mix << 2); mdi->info.current_sample += real_samples_to_mix; mdi->samples_to_mix -= real_samples_to_mix; } while (size); tmp_buffer = out_buffer; if (mdi->info.mixer_options & WM_MO_REVERB) { _WM_do_reverb(mdi->reverb, tmp_buffer, (buffer_used / 2)); } for (i = 0; i < buffer_used; i += 4) { left_mix = *tmp_buffer++; right_mix = *tmp_buffer++; if (left_mix > 32767) { left_mix = 32767; } else if (left_mix < -32768) { left_mix = -32768; } if (right_mix > 32767) { right_mix = 32767; } else if (right_mix < -32768) { right_mix = -32768; } /* * =================== * Write to the buffer * =================== */ (*buffer++) = left_mix & 0xff; (*buffer++) = ((left_mix >> 8) & 0x7f) | ((left_mix >> 24) & 0x80); (*buffer++) = right_mix & 0xff; (*buffer++) = ((right_mix >> 8) & 0x7f) | ((right_mix >> 24) & 0x80); } _WM_Unlock(&mdi->lock); return buffer_used; } /* * ========================= * External Functions * ========================= */ WM_SYMBOL const char * WildMidi_GetString(unsigned short int info) { switch (info) { case WM_GS_VERSION: return WM_Version; } return NULL; } WM_SYMBOL int WildMidi_Init(const char * config_file, unsigned short int rate, unsigned short int options) { if (WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_ALR_INIT, NULL, 0); return -1; } if (config_file == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL config file pointer)", 0); return -1; } WM_InitPatches(); if (WM_LoadConfig(config_file) == -1) { return -1; } if (options & 0x5FF8) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(invalid option)", 0); WM_FreePatches(); return -1; } WM_MixerOptions = options; if (rate < 11025) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(rate out of bounds, range is 11025 - 65535)", 0); WM_FreePatches(); return -1; } _WM_SampleRate = rate; gauss_lock = 0; patch_lock = 0; WM_Initialized = 1; return 0; } WM_SYMBOL int WildMidi_MasterVolume(unsigned char master_volume) { struct _mdi *mdi = NULL; struct _hndl * tmp_handle = first_handle; int i = 0; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } if (master_volume > 127) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(master volume out of range, range is 0-127)", 0); return -1; } WM_MasterVolume = lin_volume[master_volume]; if (tmp_handle) { while (tmp_handle) { mdi = (struct _mdi *) tmp_handle->handle; for (i = 0; i < 16; i++) { do_pan_adjust(mdi, i); } tmp_handle = tmp_handle->next; } } return 0; } WM_SYMBOL int WildMidi_Close(midi * handle) { struct _mdi *mdi = (struct _mdi *) handle; struct _hndl * tmp_handle; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } if (handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL handle)", 0); return -1; } if (first_handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(no midi's open)", 0); return -1; } _WM_Lock(&mdi->lock); if (first_handle->handle == handle) { tmp_handle = first_handle->next; free(first_handle); first_handle = tmp_handle; if (first_handle) first_handle->prev = NULL; } else { tmp_handle = first_handle; while (tmp_handle->handle != handle) { tmp_handle = tmp_handle->next; if (tmp_handle == NULL) { break; } } if (tmp_handle) { tmp_handle->prev->next = tmp_handle->next; if (tmp_handle->next) { tmp_handle->next->prev = tmp_handle->prev; } free(tmp_handle); } } freeMDI(mdi); return 0; } WM_SYMBOL midi * WildMidi_Open(const char *midifile) { unsigned char *mididata = NULL; unsigned long int midisize = 0; midi * ret = NULL; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return NULL; } if (midifile == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL filename)", 0); return NULL; } if ((mididata = _WM_BufferFile(midifile, &midisize)) == NULL) { return NULL; } ret = (void *) WM_ParseNewMidi(mididata, midisize); free(mididata); if (ret) { if (add_handle(ret) != 0) { WildMidi_Close(ret); ret = NULL; } } return ret; } WM_SYMBOL midi * WildMidi_OpenBuffer(unsigned char *midibuffer, unsigned long int size) { midi * ret = NULL; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return NULL; } if (midibuffer == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL midi data buffer)", 0); return NULL; } if (size > WM_MAXFILESIZE) { /* don't bother loading suspiciously long files */ _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_LONGFIL, NULL, 0); return NULL; } ret = (void *) WM_ParseNewMidi(midibuffer, size); if (ret) { if (add_handle(ret) != 0) { WildMidi_Close(ret); ret = NULL; } } return ret; } WM_SYMBOL int WildMidi_FastSeek(midi * handle, unsigned long int *sample_pos) { struct _mdi *mdi; struct _event *event; struct _note *note_data; unsigned long int real_samples_to_mix; unsigned long int count; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } if (handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL handle)", 0); return -1; } if (sample_pos == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL seek position pointer)", 0); return -1; } mdi = (struct _mdi *) handle; _WM_Lock(&mdi->lock); event = mdi->current_event; /* make sure we havent asked for a positions beyond the end of the song. */ if (*sample_pos > mdi->info.approx_total_samples) { /* if so set the position to the end of the song */ *sample_pos = mdi->info.approx_total_samples; } /* was end of song requested and are we are there? */ if (*sample_pos == mdi->info.current_sample) { /* yes */ _WM_Unlock(&mdi->lock); return 0; } /* did we want to fast forward? */ if (mdi->info.current_sample < *sample_pos) { /* yes */ count = *sample_pos - mdi->info.current_sample; } else { /* no, reset values to start as the beginning */ count = *sample_pos; WM_ResetToStart(handle); event = mdi->current_event; } /* clear the reverb buffers since we not gonna be using them here */ _WM_reset_reverb(mdi->reverb); while (count) { if (__builtin_expect((!mdi->samples_to_mix), 0)) { while ((!mdi->samples_to_mix) && (event->do_event)) { event->do_event(mdi, &event->event_data); event++; mdi->samples_to_mix = event->samples_to_next; mdi->current_event = event; } if (!mdi->samples_to_mix) { if (event->do_event == NULL) { mdi->samples_to_mix = mdi->info.approx_total_samples - *sample_pos; } else { mdi->samples_to_mix = count; } } } if (__builtin_expect((mdi->samples_to_mix > count), 0)) { real_samples_to_mix = count; } else { real_samples_to_mix = mdi->samples_to_mix; } if (real_samples_to_mix == 0) { break; } count -= real_samples_to_mix; mdi->info.current_sample += real_samples_to_mix; mdi->samples_to_mix -= real_samples_to_mix; } note_data = mdi->note; if (note_data) { do { note_data->active = 0; if (note_data->replay) { note_data->replay = NULL; } note_data = note_data->next; } while (note_data); } mdi->note = NULL; _WM_Unlock(&mdi->lock); return 0; } WM_SYMBOL int WildMidi_GetOutput(midi * handle, char *buffer, unsigned long int size) { if (__builtin_expect((!WM_Initialized), 0)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } if (__builtin_expect((handle == NULL), 0)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL handle)", 0); return -1; } if (__builtin_expect((buffer == NULL), 0)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL buffer pointer)", 0); return -1; } if (__builtin_expect((size == 0), 0)) { return 0; } if (__builtin_expect((!!(size % 4)), 0)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(size not a multiple of 4)", 0); return -1; } if (((struct _mdi *) handle)->info.mixer_options & WM_MO_ENHANCED_RESAMPLING) { if (!gauss_table) init_gauss(); return WM_GetOutput_Gauss(handle, buffer, size); } return WM_GetOutput_Linear(handle, buffer, size); } WM_SYMBOL int WildMidi_SetOption(midi * handle, unsigned short int options, unsigned short int setting) { struct _mdi *mdi; int i; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } if (handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL handle)", 0); return -1; } mdi = (struct _mdi *) handle; _WM_Lock(&mdi->lock); if ((!(options & 0x0007)) || (options & 0xFFF8)) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(invalid option)", 0); _WM_Unlock(&mdi->lock); return -1; } if (setting & 0xFFF8) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(invalid setting)", 0); _WM_Unlock(&mdi->lock); return -1; } mdi->info.mixer_options = ((mdi->info.mixer_options & (0x00FF ^ options)) | (options & setting)); if (options & WM_MO_LOG_VOLUME) { struct _note *note_data = mdi->note; for (i = 0; i < 16; i++) { do_pan_adjust(mdi, i); } if (note_data) { do { note_data->vol_lvl = get_volume(mdi, (note_data->noteid >> 8), note_data); if (note_data->replay) note_data->replay->vol_lvl = get_volume(mdi, (note_data->noteid >> 8), note_data->replay); note_data = note_data->next; } while (note_data); } } else if (options & WM_MO_REVERB) { _WM_reset_reverb(mdi->reverb); } _WM_Unlock(&mdi->lock); return 0; } WM_SYMBOL struct _WM_Info * WildMidi_GetInfo(midi * handle) { struct _mdi *mdi = (struct _mdi *) handle; if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return NULL; } if (handle == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_INVALID_ARG, "(NULL handle)", 0); return NULL; } _WM_Lock(&mdi->lock); if (mdi->tmp_info == NULL) { mdi->tmp_info = malloc(sizeof(struct _WM_Info)); if (mdi->tmp_info == NULL) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_MEM, "to set info", 0); _WM_Unlock(&mdi->lock); return NULL; } mdi->tmp_info->copyright = NULL; } mdi->tmp_info->current_sample = mdi->info.current_sample; mdi->tmp_info->approx_total_samples = mdi->info.approx_total_samples; mdi->tmp_info->mixer_options = mdi->info.mixer_options; if (mdi->info.copyright) { free(mdi->tmp_info->copyright); mdi->tmp_info->copyright = malloc(strlen(mdi->info.copyright) + 1); strcpy(mdi->tmp_info->copyright, mdi->info.copyright); } else { mdi->tmp_info->copyright = NULL; } _WM_Unlock(&mdi->lock); return mdi->tmp_info; } WM_SYMBOL int WildMidi_Shutdown(void) { if (!WM_Initialized) { _WM_ERROR(__FUNCTION__, __LINE__, WM_ERR_NOT_INIT, NULL, 0); return -1; } while (first_handle) { /* closes open handle and rotates the handles list. */ WildMidi_Close((struct _mdi *) first_handle->handle); } WM_FreePatches(); free_gauss(); /* reset the globals */ WM_MasterVolume = 948; WM_MixerOptions = 0; fix_release = 0; auto_amp = 0; auto_amp_with_amp = 0; reverb_room_width = 16.875f; reverb_room_length = 22.5f; reverb_listen_posx = 8.4375f; reverb_listen_posy = 16.875f; WM_Initialized = 0; return 0; } wildmidi-wildmidi-0.3.8/src/wm_error.c000066400000000000000000000044321245740225500177240ustar00rootroot00000000000000/* wm_error.c error reporting Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #include #include #include #include "wm_error.h" void _WM_ERROR_NEW(const char * wmfmt, ...) { va_list args; fprintf(stderr, "\r"); va_start(args, wmfmt); vfprintf(stderr, wmfmt, args); va_end(args); fprintf(stderr, "\n"); } void _WM_ERROR(const char * func, unsigned int lne, int wmerno, const char * wmfor, int error) { static const char *errors[WM_ERR_MAX+1] = { "No error", "Unable to obtain memory", "Unable to stat", "Unable to load", "Unable to open", "Unable to read", "Invalid or Unsuported file format", "File corrupt", "Library not Initialized", "Invalid argument", "Library Already Initialized", "Not a midi file", "Refusing to load unusually long file", "Invalid error code" }; if (wmerno < 0 || wmerno > WM_ERR_MAX) wmerno = WM_ERR_MAX; if (wmfor != NULL) { if (error != 0) { fprintf(stderr, "\rlibWildMidi(%s:%u): ERROR %s %s (%s)\n", func, lne, errors[wmerno], wmfor, strerror(error)); } else { fprintf(stderr, "\rlibWildMidi(%s:%u): ERROR %s %s\n", func, lne, errors[wmerno], wmfor); } } else { if (error != 0) { fprintf(stderr, "\rlibWildMidi(%s:%u): ERROR %s (%s)\n", func, lne, errors[wmerno], strerror(error)); } else { fprintf(stderr, "\rlibWildMidi(%s:%u): ERROR %s\n", func, lne, errors[wmerno]); } } } wildmidi-wildmidi-0.3.8/src/wm_tty.c000066400000000000000000000035241245740225500174140ustar00rootroot00000000000000/* wm_tty.c - unix termios code for player Copyright (C) Chris Ison 2001-2011 Copyright (C) Bret Curtis 2013-2014 This file is part of WildMIDI. WildMIDI is free software: you can redistribute and/or modify the player under the terms of the GNU General Public License and you can redistribute and/or modify the library under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the licenses, or(at your option) any later version. WildMIDI 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 and the GNU Lesser General Public License for more details. You should have received a copy of the GNU General Public License and the GNU Lesser General Public License along with WildMIDI. If not, see . */ #include "config.h" #if !defined(_WIN32) && !defined(__DJGPP__) #define _XOPEN_SOURCE 600 /* for ONLCR */ #include #include #include #ifndef FNONBLOCK #define FNONBLOCK O_NONBLOCK #endif struct termios _tty; static tcflag_t _res_oflg = 0; static tcflag_t _res_lflg = 0; void wm_inittty(void) { if (!isatty(STDIN_FILENO)) return; /* save tty: */ tcgetattr(STDIN_FILENO, &_tty); _res_oflg = _tty.c_oflag; _res_lflg = _tty.c_lflag; /* set raw: */ _tty.c_lflag &= ~(ICANON | ICRNL | ISIG); _tty.c_oflag &= ~ONLCR; tcsetattr(STDIN_FILENO, TCSANOW, &_tty); fcntl(STDIN_FILENO, F_SETFL, FNONBLOCK); } void wm_resetty(void) { if (!isatty(STDIN_FILENO)) return; /* reset tty: */ _tty.c_oflag = _res_oflg; _tty.c_lflag = _res_lflg; tcsetattr(STDIN_FILENO, TCSADRAIN, &_tty); } #endif /* !_WIN32, !__DJGPP__ */