From: <man...@us...> - 2013-05-30 18:38:41
|
Revision: 2234 http://sourceforge.net/p/modplug/code/2234 Author: manxorist Date: 2013-05-30 18:38:34 +0000 (Thu, 30 May 2013) Log Message: ----------- [Ref] Simplify symbol export for xmp-openmpt.dll. [Ref] Do not build winamp or xmplay plugin if libopenmpt is not built as a dll. Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp Removed Paths: ------------- trunk/OpenMPT/libopenmpt/libopenmpt_xmplay_c.c trunk/OpenMPT/libopenmpt/xmpin.def Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/common/BuildSettings.h 2013-05-30 18:38:34 UTC (rev 2234) @@ -173,8 +173,20 @@ #undef MODPLUG_NO_FILESAVE // tests require file saving #endif +#if !defined(NO_WINAMP) +#if !defined(LIBOPENMPT_BUILD) || (defined(LIBOPENMPT_BUILD) && !defined(LIBOPENMPT_BUILD_DLL)) +#define NO_WINAMP // winamp plugin requires libopenmpt dll build +#endif +#endif +#if !defined(NO_XMPLAY) +#if !defined(LIBOPENMPT_BUILD) || (defined(LIBOPENMPT_BUILD) && !defined(LIBOPENMPT_BUILD_DLL)) +#define NO_XMPLAY // xmplay plugin requires libopenmpt dll build +#endif +#endif + + #if MPT_COMPILER_MSVC #define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers #endif Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-05-30 18:38:34 UTC (rev 2234) @@ -130,7 +130,6 @@ </ClCompile> <Link> <GenerateDebugInformation>true</GenerateDebugInformation> - <ModuleDefinitionFile>xmpin.def</ModuleDefinitionFile> <DelayLoadDLLs>libopenmpt_settings.dll</DelayLoadDLLs> </Link> <PreBuildEvent> @@ -151,7 +150,6 @@ </ClCompile> <Link> <GenerateDebugInformation>true</GenerateDebugInformation> - <ModuleDefinitionFile>xmpin.def</ModuleDefinitionFile> <DelayLoadDLLs>libopenmpt_settings.dll</DelayLoadDLLs> </Link> <PreBuildEvent> @@ -218,7 +216,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <ModuleDefinitionFile>xmpin.def</ModuleDefinitionFile> <DelayLoadDLLs>libopenmpt_settings.dll</DelayLoadDLLs> </Link> <PreBuildEvent> @@ -251,7 +248,6 @@ <GenerateDebugInformation>true</GenerateDebugInformation> <EnableCOMDATFolding>true</EnableCOMDATFolding> <OptimizeReferences>true</OptimizeReferences> - <ModuleDefinitionFile>xmpin.def</ModuleDefinitionFile> <DelayLoadDLLs>libopenmpt_settings.dll</DelayLoadDLLs> </Link> <PreBuildEvent> @@ -470,16 +466,6 @@ <ClCompile Include="libopenmpt_version.cpp" /> <ClCompile Include="libopenmpt_winamp.cpp" /> <ClCompile Include="libopenmpt_xmplay.cpp" /> - <ClCompile Include="libopenmpt_xmplay_c.c"> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='DebugStatic|Win32'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='DebugStatic|x64'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|Win32'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='ReleaseStatic|x64'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsC</CompileAs> - <CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsC</CompileAs> - </ClCompile> </ItemGroup> <ItemGroup> <ProjectReference Include="..\include\zlib\contrib\vstudio\vc10\zlibstat.vcxproj"> Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-05-30 18:38:34 UTC (rev 2234) @@ -458,9 +458,6 @@ <ClCompile Include="libopenmpt_xmplay.cpp"> <Filter>Source Files</Filter> </ClCompile> - <ClCompile Include="libopenmpt_xmplay_c.c"> - <Filter>Source Files</Filter> - </ClCompile> <ClCompile Include="..\soundlib\Load_digi.cpp"> <Filter>Source Files\soundlib</Filter> </ClCompile> Modified: trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp 2013-05-30 18:38:34 UTC (rev 2234) @@ -895,9 +895,7 @@ xmpin.exts = NULL; } -extern "C" { - -XMPIN * XMPIN_GetInterface_cxx( DWORD face, InterfaceProc faceproc ) { +static XMPIN * XMPIN_GetInterface_cxx( DWORD face, InterfaceProc faceproc ) { if (face!=XMPIN_FACE) return NULL; xmpfin=(XMPFUNC_IN*)faceproc(XMPFUNC_IN_FACE); xmpfmisc=(XMPFUNC_MISC*)faceproc(XMPFUNC_MISC_FACE); @@ -907,6 +905,14 @@ return &xmpin; } +extern "C" { + +// XMPLAY expects a WINAPI (which is __stdcall) function using an undecorated symbol name. +XMPIN * WINAPI XMPIN_GetInterface( DWORD face, InterfaceProc faceproc ) { + return XMPIN_GetInterface_cxx( face, faceproc ); +} +#pragma comment(linker, "/EXPORT:XMPIN_GetInterface=_XMPIN_GetInterface@8") + }; // extern "C" #endif // NO_XMPLAY Deleted: trunk/OpenMPT/libopenmpt/libopenmpt_xmplay_c.c =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_xmplay_c.c 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/libopenmpt/libopenmpt_xmplay_c.c 2013-05-30 18:38:34 UTC (rev 2234) @@ -1,34 +0,0 @@ -/* - * libopenmpt_xmplay_c.c - * --------------------- - * Purpose: libopenmpt xmplay input plugin interface - * Notes : (currently none) - * Authors: OpenMPT Devs - * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. - */ - -#include "BuildSettings.h" - -#ifndef NO_XMPLAY - -#include "xmplay/xmpin.h" - -XMPIN * XMPIN_GetInterface_cxx( DWORD face, InterfaceProc faceproc ); -// Stupid MSVC does not undecorate function name when using linker pragma. -// So, we have to use EXPORTS in the .def file. -/*LIBOPENMPT_XMPLAY_API*/ XMPIN * WINAPI XMPIN_GetInterface( DWORD face, InterfaceProc faceproc ) { - return XMPIN_GetInterface_cxx( face, faceproc ); -} -//#pragma comment(linker, "/EXPORT:XMPIN_GetInterface") - -#else // !NO_XMPLAY - -#ifdef _MSC_VER -#include <windows.h> -// to prevent linking failure with symbols from .def file ... this is getting complicated -void * XMPIN_GetInterface( DWORD face, void * faceproc ) { - return NULL; -} -#endif // _MSC_VER - -#endif // NO_XMPLAY Deleted: trunk/OpenMPT/libopenmpt/xmpin.def =================================================================== --- trunk/OpenMPT/libopenmpt/xmpin.def 2013-05-30 18:08:56 UTC (rev 2233) +++ trunk/OpenMPT/libopenmpt/xmpin.def 2013-05-30 18:38:34 UTC (rev 2234) @@ -1,2 +0,0 @@ -EXPORTS -XMPIN_GetInterface This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-05-31 16:57:04
|
Revision: 2247 http://sourceforge.net/p/modplug/code/2247 Author: manxorist Date: 2013-05-31 16:56:55 +0000 (Fri, 31 May 2013) Log Message: ----------- [Ref] Split implementation from libopenmpt_impl.hpp into libopenmpt_impl.cpp. [Fix] class openmpt::detail::version_mismatch needs to be exported. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.cpp trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp trunk/OpenMPT/openmpt123/Makefile Added Paths: ----------- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.cpp 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt.cpp 2013-05-31 16:56:55 UTC (rev 2247) @@ -38,22 +38,20 @@ #endif // NOXMPLAY BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) { - #ifndef NO_XMPLAY - switch ( fdwReason ) { - case DLL_PROCESS_ATTACH: - #ifndef NO_XMPLAY - xmp_openmpt_on_dll_load(); - #endif // NOXMPLAY - break; - case DLL_PROCESS_DETACH: - #ifndef NO_XMPLAY - xmp_openmpt_on_dll_unload(); - #endif // NOXMPLAY - break; - } - #endif // NOXMPLAY + switch ( fdwReason ) { + case DLL_PROCESS_ATTACH: + #ifndef NO_XMPLAY + xmp_openmpt_on_dll_load(); + #endif // NOXMPLAY + break; + case DLL_PROCESS_DETACH: + #ifndef NO_XMPLAY + xmp_openmpt_on_dll_unload(); + #endif // NOXMPLAY + break; + } return TRUE; } -#endif -#endif +#endif // _WIN32 +#endif // LIBOPENMPT_BUILD_DLL Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-05-31 16:56:55 UTC (rev 2247) @@ -452,6 +452,7 @@ <ClCompile Include="libopenmpt.cpp" /> <ClCompile Include="libopenmpt_c.cpp" /> <ClCompile Include="libopenmpt_cxx.cpp" /> + <ClCompile Include="libopenmpt_impl.cpp" /> <ClCompile Include="libopenmpt_interactive.cpp" /> <ClCompile Include="libopenmpt_modplug.c"> <CompileAs Condition="'$(Configuration)|$(Platform)'=='DebugStatic|Win32'">CompileAsC</CompileAs> Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj.filters 2013-05-31 16:56:55 UTC (rev 2247) @@ -464,5 +464,8 @@ <ClCompile Include="..\test\test.cpp"> <Filter>Source Files\test</Filter> </ClCompile> + <ClCompile Include="libopenmpt_impl.cpp"> + <Filter>Source Files</Filter> + </ClCompile> </ItemGroup> </Project> \ No newline at end of file Modified: trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt_cxx.cpp 2013-05-31 16:56:55 UTC (rev 2247) @@ -15,6 +15,7 @@ #include "libopenmpt_impl.hpp" #include <algorithm> +#include <iterator> #include <stdexcept> //#ifndef NO_LIBOPENMPT_CXX Copied: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp (from rev 2237, trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp) =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp (rev 0) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-05-31 16:56:55 UTC (rev 2247) @@ -0,0 +1,639 @@ +/* + * libopenmpt_impl.cpp + * ------------------- + * Purpose: libopenmpt private interface implementation + * Notes : (currently none) + * Authors: OpenMPT Devs + * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. + */ + +#include "common/stdafx.h" + +#include "libopenmpt_internal.h" +#include "libopenmpt.hpp" +#include "libopenmpt.h" + +#include "libopenmpt_impl.hpp" + +#include <algorithm> +#include <memory> +#include <iostream> + +#include <cmath> +#include <cstdlib> +#include <cstring> + +namespace openmpt { + +exception_message::exception_message( const char * text_ ) throw() : text(text_) { + return; +} +exception_message::~exception_message() throw() { + return; +} +const char * exception_message::what() const throw() { + return text; +} + +log_interface::log_interface() { + return; +} +log_interface::~log_interface() { + return; +} +void log_interface::AddToLog( LogLevel level, const std::string & text ) const { + log( LogLevelToString(level) + std::string(": ") + text ); +} + +std_ostream_log::std_ostream_log( std::ostream & dst ) : destination(dst) { + return; +} +std_ostream_log::~std_ostream_log() { + return; +} +void std_ostream_log::log( const std::string & message ) const { + destination.flush(); + destination << message << std::endl; + destination.flush(); +} + +static std::int32_t float_to_fx16( float x ) { + return static_cast<std::int32_t>( x * (1<<16) ); +} +static float fx16_to_float( std::int32_t x ) { + return static_cast<float>( x * (1.0f/(1<<16)) ); +} +template < typename T > static T scale_percent( T percent, T min, T max ) { + return Clamp( min + ( percent * ( max - min ) ) / 100, min, max ); +} +template < typename T > static T unscale_percent( T value, T min, T max ) { + return Clamp( ( value - min ) * 100 / ( max - min ), 0, 100 ); +} + +module_impl::loader_log::loader_log( module_impl & s ) : self(s) { + return; +} +void module_impl::loader_log::AddToLog( LogLevel level, const std::string & text ) const { + self.m_loaderMessages.push_back( std::make_pair( level, text ) ); +} + +void module_impl::PushToCSoundFileLog( LogLevel level, const std::string & text ) const { + m_sndFile.AddToLog( level, text ); +} + +std::int32_t module_impl::get_quality() const { + return unscale_percent<int>( m_sndFile.m_Resampler.m_Settings.SrcMode, SRCMODE_NEAREST, SRCMODE_FIRFILTER ); +} +void module_impl::set_quality( std::int32_t value ) { + CResamplerSettings resamplersettings = m_sndFile.m_Resampler.m_Settings; + resamplersettings.SrcMode = (ResamplingMode)scale_percent<int>( value, SRCMODE_NEAREST, SRCMODE_FIRFILTER ); + resamplersettings.gdWFIRCutoff = CResamplerSettings().gdWFIRCutoff; // use default + resamplersettings.gbWFIRType = CResamplerSettings().gbWFIRType; // use default + m_sndFile.SetResamplerSettings( resamplersettings ); +} +void module_impl::apply_mixer_settings( std::int32_t samplerate, int channels, SampleFormat format ) { + if ( + static_cast<std::int32_t>( m_sndFile.m_MixerSettings.gdwMixingFreq ) != samplerate || + static_cast<int>( m_sndFile.m_MixerSettings.gnChannels ) != channels || + m_sndFile.m_MixerSettings.m_SampleFormat != format + ) { + MixerSettings mixersettings = m_sndFile.m_MixerSettings; + std::int32_t volrampin_us = mixersettings.GetVolumeRampUpMicroseconds(); + std::int32_t volrampout_us = mixersettings.GetVolumeRampDownMicroseconds(); + mixersettings.gdwMixingFreq = samplerate; + mixersettings.gnChannels = channels; + mixersettings.m_SampleFormat = format; + mixersettings.SetVolumeRampUpMicroseconds( volrampin_us ); + mixersettings.SetVolumeRampDownMicroseconds( volrampout_us ); + m_sndFile.SetMixerSettings( mixersettings ); + } +} +void module_impl::apply_libopenmpt_defaults() { + set_render_param( module::RENDER_STEREOSEPARATION_PERCENT, 100 ); + set_render_param( module::RENDER_QUALITY_PERCENT, 100 ); +} +void module_impl::init() { + m_sndFile.SetCustomLog( m_LogForwarder.get() ); + m_currentPositionSeconds = 0.0; +} +void module_impl::load( CSoundFile & sndFile, FileReader file ) { + if ( !sndFile.Create( file, CSoundFile::loadCompleteModule ) ) { + throw openmpt::exception_message("error loading file"); + } +} +void module_impl::load( FileReader file ) { + loader_log loaderlog(*this); + m_sndFile.SetCustomLog( &loaderlog ); + load( m_sndFile, file ); + m_sndFile.SetCustomLog( m_LogForwarder.get() ); + for ( std::vector<std::pair<LogLevel,std::string> >::iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { + PushToCSoundFileLog( i->first, i->second ); + } +} +std::size_t module_impl::read_wrapper( void * buffer, std::size_t count ) { + std::size_t count_read = 0; + while ( count > 0 ) { + std::size_t count_chunk = m_sndFile.Read( buffer, static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ) ); // safety margin / samplesize / channels + if ( count_chunk == 0 ) { + break; + } + count -= count_chunk; + count_read += count_chunk; + } + return count_read; +} + +double module_impl::could_open_propability( std::istream & stream, double effort, std::shared_ptr<log_interface> log ) { + CSoundFile sndFile; + sndFile.SetCustomLog( log.get() ); + + try { + + if ( effort >= 0.8 ) { + if ( !sndFile.Create( FileReader( &stream ), CSoundFile::loadCompleteModule ) ) { + return 0.0; + } + sndFile.Destroy(); + return 1.0; + } else if ( effort >= 0.6 ) { + if ( !sndFile.Create( FileReader( &stream ), CSoundFile::loadNoPatternData ) ) { + return 0.0; + } + sndFile.Destroy(); + return 0.8; + } else if ( effort >= 0.2 ) { + if ( !sndFile.Create( FileReader( &stream ), CSoundFile::onlyVerifyHeader ) ) { + return 0.0; + } + sndFile.Destroy(); + return 0.6; + } else { + return 0.2; + } + + } catch ( ... ) { + return 0.0; + } + +} + +module_impl::module_impl( std::istream & stream, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( &stream ) ); + apply_libopenmpt_defaults(); +} +module_impl::module_impl( const std::vector<std::uint8_t> & data, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( data.data(), data.size() ) ); + apply_libopenmpt_defaults(); +} +module_impl::module_impl( const std::vector<char> & data, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( data.data(), data.size() ) ); + apply_libopenmpt_defaults(); +} +module_impl::module_impl( const std::uint8_t * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( data, size ) ); + apply_libopenmpt_defaults(); +} +module_impl::module_impl( const char * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( data, size ) ); + apply_libopenmpt_defaults(); +} +module_impl::module_impl( const void * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { + init(); + load( FileReader( data, size ) ); + apply_libopenmpt_defaults(); +} +module_impl::~module_impl() { + m_sndFile.Destroy(); +} + +std::int32_t module_impl::get_render_param( int command ) const { + switch ( command ) { + case module::RENDER_MASTERGAIN_MILLIBEL: { + return static_cast<std::int32_t>( 1000.0f * 2.0f * std::log10( fx16_to_float( m_sndFile.m_MixerSettings.m_FinalOutputGain ) ) ); + } break; + case module::RENDER_STEREOSEPARATION_PERCENT: { + return m_sndFile.m_MixerSettings.m_nStereoSeparation * 100 / 128; + } break; + case module::RENDER_REPEATCOUNT: { + return m_sndFile.m_nRepeatCount; + } break; + case module::RENDER_QUALITY_PERCENT: { + return get_quality(); + } break; + case module::RENDER_MAXMIXCHANNELS: { + return m_sndFile.m_MixerSettings.m_nMaxMixChannels; + } break; + case module::RENDER_INTERPOLATION_MODE: { + switch ( m_sndFile.m_Resampler.m_Settings.SrcMode ) { + case SRCMODE_NEAREST: return module::INTERPOLATION_NEAREST; break; + case SRCMODE_LINEAR: return module::INTERPOLATION_LINEAR; break; + case SRCMODE_SPLINE: return module::INTERPOLATION_SPLINE; break; + case SRCMODE_POLYPHASE: return module::INTERPOLATION_POLYPHASE; break; + case SRCMODE_DEFAULT: + case SRCMODE_FIRFILTER: { + switch ( m_sndFile.m_Resampler.m_Settings.gbWFIRType ) { + case WFIR_HANN: return module::INTERPOLATION_FIR_HANN; break; + case WFIR_HAMMING: return module::INTERPOLATION_FIR_HAMMING; break; + case WFIR_BLACKMANEXACT: return module::INTERPOLATION_FIR_BLACKMANEXACT; break; + case WFIR_BLACKMAN3T61: return module::INTERPOLATION_FIR_BLACKMAN3T61; break; + case WFIR_BLACKMAN3T67: return module::INTERPOLATION_FIR_BLACKMAN3T67; break; + case WFIR_BLACKMAN4T92: return module::INTERPOLATION_FIR_BLACKMAN4T92; break; + case WFIR_BLACKMAN4T74: return module::INTERPOLATION_FIR_BLACKMAN4T74; break; + case WFIR_KAISER4T: return module::INTERPOLATION_FIR_KAISER4T; break; + } + } break; + default: + break; + } + throw openmpt::exception_message("unknown interpolation mode set internally"); + } break; + case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { + return m_sndFile.m_MixerSettings.GetVolumeRampUpMicroseconds(); + } break; + case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { + return m_sndFile.m_MixerSettings.GetVolumeRampDownMicroseconds(); + } break; + default: throw openmpt::exception_message("unknown command"); break; + } + return 0; +} +void module_impl::set_render_param( int command, std::int32_t value ) { + switch ( command ) { + case module::RENDER_MASTERGAIN_MILLIBEL: { + float gainFactor = static_cast<float>( std::pow( 10.0f, value * 0.001f * 0.5f ) ); + if ( static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_FinalOutputGain ) != float_to_fx16( gainFactor ) ) { + MixerSettings settings = m_sndFile.m_MixerSettings; + settings.m_FinalOutputGain = float_to_fx16( gainFactor ); + m_sndFile.SetMixerSettings( settings ); + } + } break; + case module::RENDER_STEREOSEPARATION_PERCENT: { + std::int32_t newvalue = value * 128 / 100; + if ( newvalue != static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_nStereoSeparation ) ) { + MixerSettings settings = m_sndFile.m_MixerSettings; + settings.gdwMixingFreq = newvalue; + m_sndFile.SetMixerSettings( settings ); + } + } break; + case module::RENDER_REPEATCOUNT: { + m_sndFile.SetRepeatCount( value ); + } break; + case module::RENDER_QUALITY_PERCENT: { + set_quality( value ); + } break; + case module::RENDER_MAXMIXCHANNELS: { + if ( value != static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_nMaxMixChannels ) ) { + MixerSettings settings = m_sndFile.m_MixerSettings; + settings.m_nMaxMixChannels = value; + m_sndFile.SetMixerSettings( settings ); + } + } break; + case module::RENDER_INTERPOLATION_MODE: { + CResamplerSettings newsettings; + switch ( value ) { + case module::INTERPOLATION_NEAREST: newsettings.SrcMode = SRCMODE_NEAREST; break; + case module::INTERPOLATION_LINEAR: newsettings.SrcMode = SRCMODE_LINEAR; break; + case module::INTERPOLATION_SPLINE: newsettings.SrcMode = SRCMODE_SPLINE; break; + case module::INTERPOLATION_POLYPHASE: newsettings.SrcMode = SRCMODE_POLYPHASE; break; + case module::INTERPOLATION_FIR_HANN: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_HANN; break; + case module::INTERPOLATION_FIR_HAMMING: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_HAMMING; break; + case module::INTERPOLATION_FIR_BLACKMANEXACT: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMANEXACT; break; + case module::INTERPOLATION_FIR_BLACKMAN3T61: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN3T61; break; + case module::INTERPOLATION_FIR_BLACKMAN3T67: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN3T67; break; + case module::INTERPOLATION_FIR_BLACKMAN4T92: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN4T92; break; + case module::INTERPOLATION_FIR_BLACKMAN4T74: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN4T74; break; + case module::INTERPOLATION_FIR_KAISER4T: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_KAISER4T; break; + } + if ( newsettings != m_sndFile.m_Resampler.m_Settings ) { + m_sndFile.SetResamplerSettings( newsettings ); + } + } break; + case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { + MixerSettings newsettings = m_sndFile.m_MixerSettings; + newsettings.SetVolumeRampUpMicroseconds( value ); + if ( m_sndFile.m_MixerSettings.glVolumeRampUpSamples != newsettings.glVolumeRampUpSamples ) { + m_sndFile.SetMixerSettings( newsettings ); + } + } break; + case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { + MixerSettings newsettings = m_sndFile.m_MixerSettings; + newsettings.SetVolumeRampDownMicroseconds( value ); + if ( m_sndFile.m_MixerSettings.glVolumeRampDownSamples != newsettings.glVolumeRampDownSamples ) { + m_sndFile.SetMixerSettings( newsettings ); + } + } break; + default: throw openmpt::exception_message("unknown command"); break; + } +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, std::int16_t * mono ) { + if ( !mono ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 1, SampleFormatInt16 ); + m_int16Buffer.resize( count * 1 ); + count = read_wrapper( &m_int16Buffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + mono[i] = m_int16Buffer[i*1]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right ) { + if ( !left || !right ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 2, SampleFormatInt16 ); + m_int16Buffer.resize( count * 2 ); + count = read_wrapper( &m_int16Buffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + left[i] = m_int16Buffer[i*2+0]; + right[i] = m_int16Buffer[i*2+1]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ) { + if ( !left || !right || !rear_left || !rear_right ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 4, SampleFormatInt16 ); + m_int16Buffer.resize( count * 4 ); + count = read_wrapper( &m_int16Buffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + left[i] = m_int16Buffer[i*4+0]; + right[i] = m_int16Buffer[i*4+1]; + rear_left[i] = m_int16Buffer[i*4+2]; + rear_right[i] = m_int16Buffer[i*4+3]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, float * mono ) { + if ( !mono ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 1, SampleFormatFloat32 ); + m_floatBuffer.resize( count * 1 ); + count = read_wrapper( &m_floatBuffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + mono[i] = m_floatBuffer[i*1]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, float * left, float * right ) { + if ( !left || !right ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 2, SampleFormatFloat32 ); + m_floatBuffer.resize( count * 2 ); + count = read_wrapper( &m_floatBuffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + left[i] = m_floatBuffer[i*2+0]; + right[i] = m_floatBuffer[i*2+1]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +std::size_t module_impl::read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right ) { + if ( !left || !right || !rear_left || !rear_right ) { + throw openmpt::exception_message("null pointer"); + } + apply_mixer_settings( samplerate, 4, SampleFormatFloat32 ); + m_floatBuffer.resize( count * 4 ); + count = read_wrapper( &m_floatBuffer[0], count ); + for ( std::size_t i = 0; i < count; ++i ) { + left[i] = m_floatBuffer[i*4+0]; + right[i] = m_floatBuffer[i*4+1]; + rear_left[i] = m_floatBuffer[i*4+2]; + rear_right[i] = m_floatBuffer[i*4+3]; + } + m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); + return count; +} +double module_impl::get_duration_seconds() const { + return m_sndFile.GetLength( eNoAdjust ).duration; +} +double module_impl::get_current_position_seconds() const { + return m_currentPositionSeconds; +} +void module_impl::select_subsong( std::int32_t subsong ) { + if ( subsong < -1 || subsong >= m_sndFile.Order.GetNumSequences() ) { + return; + } + if ( subsong == -1 ) { + // default subsong + m_sndFile.Order.SetSequence( 0 ); + return; + } + m_sndFile.Order.SetSequence( subsong ); +} +double module_impl::seek_seconds( double seconds ) { + GetLengthType t = m_sndFile.GetLength( eNoAdjust, GetLengthTarget( seconds ) ); + m_sndFile.InitializeVisitedRows(); + m_sndFile.m_nCurrentOrder = t.lastOrder; + m_sndFile.SetCurrentOrder( t.lastOrder ); + m_sndFile.m_nNextRow = t.lastRow; + m_currentPositionSeconds = m_sndFile.GetLength( eAdjust, GetLengthTarget( t.lastOrder, t.lastRow ) ).duration; + return m_currentPositionSeconds; +} +std::vector<std::string> module_impl::get_metadata_keys() const { + std::vector<std::string> retval; + retval.push_back("type"); + retval.push_back("type_long"); + retval.push_back("tracker"); + retval.push_back("author"); + retval.push_back("title"); + retval.push_back("message"); + retval.push_back("warnings"); + return retval; +} +std::string module_impl::get_metadata( const std::string & key ) const { + if ( key == std::string("type") ) { + return CSoundFile::ModTypeToString( m_sndFile.GetType() ); + } else if ( key == std::string("type_long") ) { + return CSoundFile::ModTypeToTracker( m_sndFile.GetType() ); + } else if ( key == std::string("tracker") ) { + return m_sndFile.madeWithTracker; + } else if ( key == std::string("title") ) { + return m_sndFile.GetTitle(); + } else if ( key == std::string("message") ) { + std::string retval = m_sndFile.songMessage.GetFormatted( SongMessage::leLF ); + if ( retval.empty() ) { + std::ostringstream tmp; + bool valid = false; + for ( INSTRUMENTINDEX i = 1; i <= m_sndFile.GetNumInstruments(); ++i ) { + std::string instname = m_sndFile.GetInstrumentName( i ); + if ( !instname.empty() ) { + valid = true; + } + tmp << instname << std::endl; + } + if ( valid ) { + retval = tmp.str(); + } + } + if ( retval.empty() ) { + std::ostringstream tmp; + bool valid = false; + for ( SAMPLEINDEX i = 1; i <= m_sndFile.GetNumSamples(); ++i ) { + std::string samplename = m_sndFile.GetSampleName( i ); + if ( !samplename.empty() ) { + valid = true; + } + tmp << samplename << std::endl; + } + if ( valid ) { + retval = tmp.str(); + } + } + return retval; + } else if ( key == std::string("warnings") ) { + std::ostringstream retval; + bool first = true; + for ( std::vector<std::pair<LogLevel,std::string> >::const_iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { + if ( !first ) { + retval << std::endl; + first = false; + } + retval << LogLevelToString( i->first ) << std::string(": ") << i->second; + } + return retval.str(); + } + return ""; +} +std::int32_t module_impl::get_current_speed() const { + return m_sndFile.m_nMusicSpeed; +} +std::int32_t module_impl::get_current_tempo() const { + return m_sndFile.m_nMusicTempo; +} +std::int32_t module_impl::get_current_order() const { + return m_sndFile.GetCurrentOrder(); +} +std::int32_t module_impl::get_current_pattern() const { + return m_sndFile.GetCurrentPattern(); +} +std::int32_t module_impl::get_current_row() const { + return m_sndFile.m_nRow; +} +std::int32_t module_impl::get_current_playing_channels() const { + return m_sndFile.m_nMixChannels; +} +std::int32_t module_impl::get_num_subsongs() const { + return m_sndFile.Order.GetNumSequences(); +} +std::int32_t module_impl::get_num_channels() const { + return m_sndFile.GetNumChannels(); +} +std::int32_t module_impl::get_num_orders() const { + return m_sndFile.Order.GetLengthTailTrimmed(); +} +std::int32_t module_impl::get_num_patterns() const { + return m_sndFile.Patterns.GetNumPatterns(); +} +std::int32_t module_impl::get_num_instruments() const { + return m_sndFile.GetNumInstruments(); +} +std::int32_t module_impl::get_num_samples() const { + return m_sndFile.GetNumSamples(); +} + +std::vector<std::string> module_impl::get_subsong_names() const { + std::vector<std::string> retval; + for ( SEQUENCEINDEX i = 0; i < m_sndFile.Order.GetNumSequences(); ++i ) { + retval.push_back( m_sndFile.Order.GetSequence( i ).m_sName ); + } + return retval; +} +std::vector<std::string> module_impl::get_channel_names() const { + std::vector<std::string> retval; + for ( CHANNELINDEX i = 0; i < m_sndFile.GetNumChannels(); ++i ) { + retval.push_back( m_sndFile.ChnSettings[i].szName ); + } + return retval; +} +std::vector<std::string> module_impl::get_order_names() const { + std::vector<std::string> retval; + for ( ORDERINDEX i = 0; i < m_sndFile.Order.GetLengthTailTrimmed(); ++i ) { + PATTERNINDEX pat = m_sndFile.Order[i]; + if ( m_sndFile.Patterns.IsValidIndex( pat ) ) { + retval.push_back( m_sndFile.Patterns[ m_sndFile.Order[i] ].GetName() ); + } else { + if ( pat == m_sndFile.Order.GetIgnoreIndex() ) { + retval.push_back( "+++ skip" ); + } else if ( pat == m_sndFile.Order.GetInvalidPatIndex() ) { + retval.push_back( "--- stop" ); + } else { + retval.push_back( "???" ); + } + } + } + return retval; +} +std::vector<std::string> module_impl::get_pattern_names() const { + std::vector<std::string> retval; + for ( PATTERNINDEX i = 0; i < m_sndFile.Patterns.GetNumPatterns(); ++i ) { + retval.push_back( m_sndFile.Patterns[i].GetName() ); + } + return retval; +} +std::vector<std::string> module_impl::get_instrument_names() const { + std::vector<std::string> retval; + for ( INSTRUMENTINDEX i = 1; i <= m_sndFile.GetNumInstruments(); ++i ) { + retval.push_back( m_sndFile.GetInstrumentName( i ) ); + } + return retval; +} +std::vector<std::string> module_impl::get_sample_names() const { + std::vector<std::string> retval; + for ( SAMPLEINDEX i = 1; i <= m_sndFile.GetNumSamples(); ++i ) { + retval.push_back( m_sndFile.GetSampleName( i ) ); + } + return retval; +} + +std::int32_t module_impl::get_order_pattern( std::int32_t o ) const { + if ( o < 0 || o >= m_sndFile.Order.GetLengthTailTrimmed() ) { + return -1; + } + return m_sndFile.Order[o]; +} +std::int32_t module_impl::get_pattern_num_rows( std::int32_t p ) const { + if ( p < 0 || p >= m_sndFile.Patterns.Size() ) { + return 0; + } + return m_sndFile.Patterns[p].GetNumRows(); +} + +std::uint8_t module_impl::get_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const { + CHANNELINDEX numchannels = m_sndFile.GetNumChannels(); + if ( p < 0 || p >= m_sndFile.Patterns.Size() ) { + return 0; + } + if ( r < 0 || r >= (std::int32_t)m_sndFile.Patterns[p].GetNumRows() ) { + return 0; + } + if ( c < 0 || c >= numchannels ) { + return 0; + } + if ( cmd < module::command_note || cmd > module::command_parameter ) { + return 0; + } + switch ( cmd ) { + case module::command_note: return m_sndFile.Patterns[p][r*numchannels+c].note; break; + case module::command_instrument: return m_sndFile.Patterns[p][r*numchannels+c].instr; break; + case module::command_volumeffect: return m_sndFile.Patterns[p][r*numchannels+c].volcmd; break; + case module::command_effect: return m_sndFile.Patterns[p][r*numchannels+c].command; break; + case module::command_volume: return m_sndFile.Patterns[p][r*numchannels+c].vol; break; + case module::command_parameter: return m_sndFile.Patterns[p][r*numchannels+c].param; break; + } + return 0; +} + +} // namespace openmpt Property changes on: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-c++src \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-05-31 16:56:55 UTC (rev 2247) @@ -1,7 +1,7 @@ /* * libopenmpt_impl.hpp * ------------------- - * Purpose: libopenmpt private interface implementation + * Purpose: libopenmpt private interface * Notes : This is not a public header. Do NOT ship in distributions dev packages. * Authors: OpenMPT Devs * The OpenMPT source code is released under the BSD license. Read LICENSE for more details. @@ -16,17 +16,8 @@ #include "libopenmpt.hpp" #include "libopenmpt.h" -#include <algorithm> -#include <exception> #include <memory> -#include <iostream> -#include <iterator> -#include <string> -#include <cmath> -#include <cstdlib> -#include <cstring> - #include "soundlib/Sndfile.h" #include "soundlib/FileReader.h" @@ -44,47 +35,31 @@ // has to be exported for type_info lookup to work class LIBOPENMPT_CXX_API exception_message : public exception { public: - exception_message( const char * text_ ) throw() : text(text_) { } - virtual ~exception_message() throw() { } + exception_message( const char * text_ ) throw(); + virtual ~exception_message() throw(); public: - virtual const char * what() const throw() { - return text; - } + virtual const char * what() const throw(); private: const char * text; }; // class exception_message class log_interface : public ILog { protected: - log_interface() { - return; - } + log_interface(); public: - virtual ~log_interface() { - return; - } + virtual ~log_interface(); virtual void log( const std::string & message ) const = 0; private: - void AddToLog( LogLevel level, const std::string & text ) const { - log( LogLevelToString(level) + std::string(": ") + text ); - } + void AddToLog( LogLevel level, const std::string & text ) const; }; // class log_interface class std_ostream_log : public log_interface { private: std::ostream & destination; public: - std_ostream_log( std::ostream & dst ) : destination(dst) { - return; - } - virtual ~std_ostream_log() { - return; - } - virtual void log( const std::string & message ) const { - destination.flush(); - destination << message << std::endl; - destination.flush(); - } + std_ostream_log( std::ostream & dst ); + virtual ~std_ostream_log(); + virtual void log( const std::string & message ) const; }; // class CSoundFileLog_std_ostream class module_impl { @@ -100,586 +75,66 @@ private: module_impl & self; public: - loader_log( module_impl & s ) : self(s) { - return; - } + loader_log( module_impl & s ); private: - void AddToLog( LogLevel level, const std::string & text ) const { - self.m_loaderMessages.push_back( std::make_pair( level, text ) ); - } + void AddToLog( LogLevel level, const std::string & text ) const; }; // class loader_log public: - void PushToCSoundFileLog( LogLevel level, const std::string & text ) const { - m_sndFile.AddToLog( level, text ); - } + void PushToCSoundFileLog( LogLevel level, const std::string & text ) const; private: - static std::int32_t float_to_fx16( float x ) { - return static_cast<std::int32_t>( x * (1<<16) ); - } - static float fx16_to_float( std::int32_t x ) { - return static_cast<float>( x * (1.0f/(1<<16)) ); - } - template < typename T > static T scale_percent( T percent, T min, T max ) { - return Clamp( min + ( percent * ( max - min ) ) / 100, min, max ); - } - template < typename T > static T unscale_percent( T value, T min, T max ) { - return Clamp( ( value - min ) * 100 / ( max - min ), 0, 100 ); - } -private: - std::int32_t get_quality() const { - return unscale_percent<int>( m_sndFile.m_Resampler.m_Settings.SrcMode, SRCMODE_NEAREST, SRCMODE_FIRFILTER ); - } - void set_quality( std::int32_t value ) { - CResamplerSettings resamplersettings = m_sndFile.m_Resampler.m_Settings; - resamplersettings.SrcMode = (ResamplingMode)scale_percent<int>( value, SRCMODE_NEAREST, SRCMODE_FIRFILTER ); - resamplersettings.gdWFIRCutoff = CResamplerSettings().gdWFIRCutoff; // use default - resamplersettings.gbWFIRType = CResamplerSettings().gbWFIRType; // use default - m_sndFile.SetResamplerSettings( resamplersettings ); - } - void apply_mixer_settings( std::int32_t samplerate, int channels, SampleFormat format ) { - if ( - static_cast<std::int32_t>( m_sndFile.m_MixerSettings.gdwMixingFreq ) != samplerate || - static_cast<int>( m_sndFile.m_MixerSettings.gnChannels ) != channels || - m_sndFile.m_MixerSettings.m_SampleFormat != format - ) { - MixerSettings mixersettings = m_sndFile.m_MixerSettings; - std::int32_t volrampin_us = mixersettings.GetVolumeRampUpMicroseconds(); - std::int32_t volrampout_us = mixersettings.GetVolumeRampDownMicroseconds(); - mixersettings.gdwMixingFreq = samplerate; - mixersettings.gnChannels = channels; - mixersettings.m_SampleFormat = format; - mixersettings.SetVolumeRampUpMicroseconds( volrampin_us ); - mixersettings.SetVolumeRampDownMicroseconds( volrampout_us ); - m_sndFile.SetMixerSettings( mixersettings ); - } - } - void apply_libopenmpt_defaults() { - set_render_param( module::RENDER_STEREOSEPARATION_PERCENT, 100 ); - set_render_param( module::RENDER_QUALITY_PERCENT, 100 ); - } - void init() { - m_sndFile.SetCustomLog( m_LogForwarder.get() ); - m_currentPositionSeconds = 0.0; - } - static void load( CSoundFile & sndFile, FileReader file ) { - if ( !sndFile.Create( file, CSoundFile::loadCompleteModule ) ) { - throw openmpt::exception_message("error loading file"); - } - } - void load( FileReader file ) { - loader_log loaderlog(*this); - m_sndFile.SetCustomLog( &loaderlog ); - load( m_sndFile, file ); - m_sndFile.SetCustomLog( m_LogForwarder.get() ); - for ( std::vector<std::pair<LogLevel,std::string> >::iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { - PushToCSoundFileLog( i->first, i->second ); - } - } - std::size_t read_wrapper( void * buffer, std::size_t count ) { - std::size_t count_read = 0; - while ( count > 0 ) { - std::size_t count_chunk = m_sndFile.Read( buffer, static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ) ); // safety margin / samplesize / channels - if ( count_chunk == 0 ) { - break; - } - count -= count_chunk; - count_read += count_chunk; - } - return count_read; - } + std::int32_t get_quality() const; + void set_quality( std::int32_t value ); + void apply_mixer_settings( std::int32_t samplerate, int channels, SampleFormat format ); + void apply_libopenmpt_defaults(); + void init(); + static void load( CSoundFile & sndFile, FileReader file ); + void load( FileReader file ); + std::size_t read_wrapper( void * buffer, std::size_t count ); public: - static double could_open_propability( std::istream & stream, double effort, std::shared_ptr<log_interface> log ) { - CSoundFile sndFile; - sndFile.SetCustomLog( log.get() ); - - try { - - if ( effort >= 0.8 ) { - if ( !sndFile.Create( FileReader( &stream ), CSoundFile::loadCompleteModule ) ) { - return 0.0; - } - sndFile.Destroy(); - return 1.0; - } else if ( effort >= 0.6 ) { - if ( !sndFile.Create( FileReader( &stream ), CSoundFile::loadNoPatternData ) ) { - return 0.0; - } - sndFile.Destroy(); - return 0.8; - } else if ( effort >= 0.2 ) { - if ( !sndFile.Create( FileReader( &stream ), CSoundFile::onlyVerifyHeader ) ) { - return 0.0; - } - sndFile.Destroy(); - return 0.6; - } else { - return 0.2; - } - - } catch ( ... ) { - return 0.0; - } - - } - module_impl( std::istream & stream, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( &stream ) ); - apply_libopenmpt_defaults(); - } - module_impl( const std::vector<std::uint8_t> & data, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( data.data(), data.size() ) ); - apply_libopenmpt_defaults(); - } - module_impl( const std::vector<char> & data, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( data.data(), data.size() ) ); - apply_libopenmpt_defaults(); - } - module_impl( const std::uint8_t * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( data, size ) ); - apply_libopenmpt_defaults(); - } - module_impl( const char * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( data, size ) ); - apply_libopenmpt_defaults(); - } - module_impl( const void * data, std::size_t size, std::shared_ptr<log_interface> log ) : m_LogForwarder(log) { - init(); - load( FileReader( data, size ) ); - apply_libopenmpt_defaults(); - } - ~module_impl() { - m_sndFile.Destroy(); - } + static double could_open_propability( std::istream & stream, double effort, std::shared_ptr<log_interface> log ); + module_impl( std::istream & stream, std::shared_ptr<log_interface> log ); + module_impl( const std::vector<std::uint8_t> & data, std::shared_ptr<log_interface> log ); + module_impl( const std::vector<char> & data, std::shared_ptr<log_interface> log ); + module_impl( const std::uint8_t * data, std::size_t size, std::shared_ptr<log_interface> log ); + module_impl( const char * data, std::size_t size, std::shared_ptr<log_interface> log ); + module_impl( const void * data, std::size_t size, std::shared_ptr<log_interface> log ); + ~module_impl(); public: - std::int32_t get_render_param( int command ) const { - switch ( command ) { - case module::RENDER_MASTERGAIN_MILLIBEL: { - return static_cast<std::int32_t>( 1000.0f * 2.0f * std::log10( fx16_to_float( m_sndFile.m_MixerSettings.m_FinalOutputGain ) ) ); - } break; - case module::RENDER_STEREOSEPARATION_PERCENT: { - return m_sndFile.m_MixerSettings.m_nStereoSeparation * 100 / 128; - } break; - case module::RENDER_REPEATCOUNT: { - return m_sndFile.m_nRepeatCount; - } break; - case module::RENDER_QUALITY_PERCENT: { - return get_quality(); - } break; - case module::RENDER_MAXMIXCHANNELS: { - return m_sndFile.m_MixerSettings.m_nMaxMixChannels; - } break; - case module::RENDER_INTERPOLATION_MODE: { - switch ( m_sndFile.m_Resampler.m_Settings.SrcMode ) { - case SRCMODE_NEAREST: return module::INTERPOLATION_NEAREST; break; - case SRCMODE_LINEAR: return module::INTERPOLATION_LINEAR; break; - case SRCMODE_SPLINE: return module::INTERPOLATION_SPLINE; break; - case SRCMODE_POLYPHASE: return module::INTERPOLATION_POLYPHASE; break; - case SRCMODE_DEFAULT: - case SRCMODE_FIRFILTER: { - switch ( m_sndFile.m_Resampler.m_Settings.gbWFIRType ) { - case WFIR_HANN: return module::INTERPOLATION_FIR_HANN; break; - case WFIR_HAMMING: return module::INTERPOLATION_FIR_HAMMING; break; - case WFIR_BLACKMANEXACT: return module::INTERPOLATION_FIR_BLACKMANEXACT; break; - case WFIR_BLACKMAN3T61: return module::INTERPOLATION_FIR_BLACKMAN3T61; break; - case WFIR_BLACKMAN3T67: return module::INTERPOLATION_FIR_BLACKMAN3T67; break; - case WFIR_BLACKMAN4T92: return module::INTERPOLATION_FIR_BLACKMAN4T92; break; - case WFIR_BLACKMAN4T74: return module::INTERPOLATION_FIR_BLACKMAN4T74; break; - case WFIR_KAISER4T: return module::INTERPOLATION_FIR_KAISER4T; break; - } - } break; - default: - break; - } - throw openmpt::exception_message("unknown interpolation mode set internally"); - } break; - case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { - return m_sndFile.m_MixerSettings.GetVolumeRampUpMicroseconds(); - } break; - case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { - return m_sndFile.m_MixerSettings.GetVolumeRampDownMicroseconds(); - } break; - default: throw openmpt::exception_message("unknown command"); break; - } - return 0; - } - void set_render_param( int command, std::int32_t value ) { - switch ( command ) { - case module::RENDER_MASTERGAIN_MILLIBEL: { - float gainFactor = static_cast<float>( std::pow( 10.0f, value * 0.001f * 0.5f ) ); - if ( static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_FinalOutputGain ) != float_to_fx16( gainFactor ) ) { - MixerSettings settings = m_sndFile.m_MixerSettings; - settings.m_FinalOutputGain = float_to_fx16( gainFactor ); - m_sndFile.SetMixerSettings( settings ); - } - } break; - case module::RENDER_STEREOSEPARATION_PERCENT: { - std::int32_t newvalue = value * 128 / 100; - if ( newvalue != static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_nStereoSeparation ) ) { - MixerSettings settings = m_sndFile.m_MixerSettings; - settings.gdwMixingFreq = newvalue; - m_sndFile.SetMixerSettings( settings ); - } - } break; - case module::RENDER_REPEATCOUNT: { - m_sndFile.SetRepeatCount( value ); - } break; - case module::RENDER_QUALITY_PERCENT: { - set_quality( value ); - } break; - case module::RENDER_MAXMIXCHANNELS: { - if ( value != static_cast<std::int32_t>( m_sndFile.m_MixerSettings.m_nMaxMixChannels ) ) { - MixerSettings settings = m_sndFile.m_MixerSettings; - settings.m_nMaxMixChannels = value; - m_sndFile.SetMixerSettings( settings ); - } - } break; - case module::RENDER_INTERPOLATION_MODE: { - CResamplerSettings newsettings; - switch ( value ) { - case module::INTERPOLATION_NEAREST: newsettings.SrcMode = SRCMODE_NEAREST; break; - case module::INTERPOLATION_LINEAR: newsettings.SrcMode = SRCMODE_LINEAR; break; - case module::INTERPOLATION_SPLINE: newsettings.SrcMode = SRCMODE_SPLINE; break; - case module::INTERPOLATION_POLYPHASE: newsettings.SrcMode = SRCMODE_POLYPHASE; break; - case module::INTERPOLATION_FIR_HANN: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_HANN; break; - case module::INTERPOLATION_FIR_HAMMING: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_HAMMING; break; - case module::INTERPOLATION_FIR_BLACKMANEXACT: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMANEXACT; break; - case module::INTERPOLATION_FIR_BLACKMAN3T61: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN3T61; break; - case module::INTERPOLATION_FIR_BLACKMAN3T67: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN3T67; break; - case module::INTERPOLATION_FIR_BLACKMAN4T92: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN4T92; break; - case module::INTERPOLATION_FIR_BLACKMAN4T74: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_BLACKMAN4T74; break; - case module::INTERPOLATION_FIR_KAISER4T: newsettings.SrcMode = SRCMODE_FIRFILTER; newsettings.gbWFIRType = WFIR_KAISER4T; break; - } - if ( newsettings != m_sndFile.m_Resampler.m_Settings ) { - m_sndFile.SetResamplerSettings( newsettings ); - } - } break; - case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { - MixerSettings newsettings = m_sndFile.m_MixerSettings; - newsettings.SetVolumeRampUpMicroseconds( value ); - if ( m_sndFile.m_MixerSettings.glVolumeRampUpSamples != newsettings.glVolumeRampUpSamples ) { - m_sndFile.SetMixerSettings( newsettings ); - } - } break; - case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { - MixerSettings newsettings = m_sndFile.m_MixerSettings; - newsettings.SetVolumeRampDownMicroseconds( value ); - if ( m_sndFile.m_MixerSettings.glVolumeRampDownSamples != newsettings.glVolumeRampDownSamples ) { - m_sndFile.SetMixerSettings( newsettings ); - } - } break; - default: throw openmpt::exception_message("unknown command"); break; - } - } - std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono ) { - if ( !mono ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 1, SampleFormatInt16 ); - m_int16Buffer.resize( count * 1 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - mono[i] = m_int16Buffer[i*1]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right ) { - if ( !left || !right ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 2, SampleFormatInt16 ); - m_int16Buffer.resize( count * 2 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_int16Buffer[i*2+0]; - right[i] = m_int16Buffer[i*2+1]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ) { - if ( !left || !right || !rear_left || !rear_right ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 4, SampleFormatInt16 ); - m_int16Buffer.resize( count * 4 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_int16Buffer[i*4+0]; - right[i] = m_int16Buffer[i*4+1]; - rear_left[i] = m_int16Buffer[i*4+2]; - rear_right[i] = m_int16Buffer[i*4+3]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - std::size_t read( std::int32_t samplerate, std::size_t count, float * mono ) { - if ( !mono ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 1, SampleFormatFloat32 ); - m_floatBuffer.resize( count * 1 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - mono[i] = m_floatBuffer[i*1]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right ) { - if ( !left || !right ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 2, SampleFormatFloat32 ); - m_floatBuffer.resize( count * 2 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_floatBuffer[i*2+0]; - right[i] = m_floatBuffer[i*2+1]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right ) { - if ( !left || !right || !rear_left || !rear_right ) { - throw openmpt::exception_message("null pointer"); - } - apply_mixer_settings( samplerate, 4, SampleFormatFloat32 ); - m_floatBuffer.resize( count * 4 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_floatBuffer[i*4+0]; - right[i] = m_floatBuffer[i*4+1]; - rear_left[i] = m_floatBuffer[i*4+2]; - rear_right[i] = m_floatBuffer[i*4+3]; - } - m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); - return count; - } - double get_duration_seconds() const { - return m_sndFile.GetLength( eNoAdjust ).duration; - } - double get_current_position_seconds() const { - return m_currentPositionSeconds; - } - void select_subsong( std::int32_t subsong ) { - if ( subsong < -1 || subsong >= m_sndFile.Order.GetNumSequences() ) { - return; - } - if ( subsong == -1 ) { - // default subsong - m_sndFile.Order.SetSequence( 0 ); - return; - } - m_sndFile.Order.SetSequence( subsong ); - } - double seek_seconds( double seconds ) { - GetLengthType t = m_sndFile.GetLength( eNoAdjust, GetLengthTarget( seconds ) ); - m_sndFile.InitializeVisitedRows(); - m_sndFile.m_nCurrentOrder = t.lastOrder; - m_sndFile.SetCurrentOrder( t.lastOrder ); - m_sndFile.m_nNextRow = t.lastRow; - m_currentPositionSeconds = m_sndFile.GetLength( eAdjust, GetLengthTarget( t.lastOrder, t.lastRow ) ).duration; - return m_currentPositionSeconds; - } - std::vector<std::string> get_metadata_keys() const { - std::vector<std::string> retval; - retval.push_back("type"); - retval.push_back("type_long"); - retval.push_back("tracker"); - retval.push_back("author"); - retval.push_back("title"); - retval.push_back("message"); - retval.push_back("warnings"); - return retval; - } - std::string get_metadata( const std::string & key ) const { - if ( key == std::string("type") ) { - return CSoundFile::ModTypeToString( m_sndFile.GetType() ); - } else if ( key == std::string("type_long") ) { - return CSoundFile::ModTypeToTracker( m_sndFile.GetType() ); - } else if ( key == std::string("tracker") ) { - return m_sndFile.madeWithTracker; - } else if ( key == std::string("title") ) { - return m_sndFile.GetTitle(); - } else if ( key == std::string("message") ) { - std::string retval = m_sndFile.songMessage.GetFormatted( SongMessage::leLF ); - if ( retval.empty() ) { - std::ostringstream tmp; - bool valid = false; - for ( INSTRUMENTINDEX i = 1; i <= m_sndFile.GetNumInstruments(); ++i ) { - std::string instname = m_sndFile.GetInstrumentName( i ); - if ( !instname.empty() ) { - valid = true; - } - tmp << instname << std::endl; - } - if ( valid ) { - retval = tmp.str(); - } - } - if ( retval.empty() ) { - std::ostringstream tmp; - bool valid = false; - for ( SAMPLEINDEX i = 1; i <= m_sndFile.GetNumSamples(); ++i ) { - std::string samplename = m_sndFile.GetSampleName( i ); - if ( !samplename.empty() ) { - valid = true; - } - tmp << samplename << std::endl; - } - if ( valid ) { - retval = tmp.str(); - } - } - return retval; - } else if ( key == std::string("warnings") ) { - std::ostringstream retval; - bool first = true; - for ( std::vector<std::pair<LogLevel,std::string> >::const_iterator i = m_loaderMessages.begin(); i != m_loaderMessages.end(); ++i ) { - if ( !first ) { - retval << std::endl; - first = false; - } - retval << LogLevelToString( i->first ) << std::string(": ") << i->second; - } - return retval.str(); - } - return ""; - } - std::int32_t get_current_speed() const { - return m_sndFile.m_nMusicSpeed; - } - std::int32_t get_current_tempo() const { - return m_sndFile.m_nMusicTempo; - } - std::int32_t get_current_order() const { - return m_sndFile.GetCurrentOrder(); - } - std::int32_t get_current_pattern() const { - return m_sndFile.GetCurrentPattern(); - } - std::int32_t get_current_row() const { - return m_sndFile.m_nRow; - } - std::int32_t get_current_playing_channels() const { - return m_sndFile.m_nMixChannels; - } - std::int32_t get_num_subsongs() const { - return m_sndFile.Order.GetNumSequences(); - } - std::int32_t get_num_channels() const { - return m_sndFile.GetNumChannels(); - } - std::int32_t get_num_orders() const { - return m_sndFile.Order.GetLengthTailTrimmed(); - } - std::int32_t get_num_patterns() const { - return m_sndFile.Patterns.GetNumPatterns(); - } - std::int32_t get_num_instruments() const { - return m_sndFile.GetNumInstruments(); - } - std::int32_t get_num_samples() const { - return m_sndFile.GetNumSamples(); - } - - std::vector<std::string> get_subsong_names() const { - std::vector<std::string> retval; - for ( SEQUENCEINDEX i = 0; i < m_sndFile.Order.GetNumSequences(); ++i ) { - retval.push_back( m_sndFile.Order.GetSequence( i ).m_sName ); - } - return retval; - } - std::vector<std::string> get_channel_names() const { - std::vector<std::string> retval; - for ( CHANNELINDEX i = 0; i < m_sndFile.GetNumChannels(); ++i ) { - retval.push_back( m_sndFile.ChnSettings[i].szName ); - } - return retval; - } - std::vector<std::string> get_order_names() const { - std::vector<std::string> retval; - for ( ORDERINDEX i = 0; i < m_sndFile.Order.GetLengthTailTrimmed(); ++i ) { - PATTERNINDEX pat = m_sndFile.Order[i]; - if ( m_sndFile.Patterns.IsValidIndex( pat ) ) { - retval.push_back( m_sndFile.Patterns[ m_sndFile.Order[i] ].GetName() ); - } else { - if ( pat == m_sndFile.Order.GetIgnoreIndex() ) { - retval.push_back( "+++ skip" ); - } else if ( pat == m_sndFile.Order.GetInvalidPatIndex() ) { - retval.push_back( "--- stop" ); - } else { - retval.push_back( "???" ); - } - } - } - return retval; - } - std::vector<std::string> get_pattern_names() const { - std::vector<std::string> retval; - for ( PATTERNINDEX i = 0; i < m_sndFile.Patterns.GetNumPatterns(); ++i ) { - retval.push_back( m_sndFile.Patterns[i].GetName() ); - } - return retval; - } - std::vector<std::string> get_instrument_names() const { - std::vector<std::string> retval; - for ( INSTRUMENTINDEX i = 1; i <= m_sndFile.GetNumInstruments(); ++i ) { - retval.push_back( m_sndFile.GetInstrumentName( i ) ); - } - return retval; - } - std::vector<std::string> get_sample_names() const { - std::vector<std::string> retval; - for ( SAMPLEINDEX i = 1; i <= m_sndFile.GetNumSamples(); ++i ) { - retval.push_back( m_sndFile.GetSampleName( i ) ); - } - return retval; - } - - std::int32_t get_order_pattern( std::int32_t o ) const { - if ( o < 0 || o >= m_sndFile.Order.GetLengthTailTrimmed() ) { - return -1; - } - return m_sndFile.Order[o]; - } - std::int32_t get_pattern_num_rows( std::int32_t p ) const { - if ( p < 0 || p >= m_sndFile.Patterns.Size() ) { - return 0; - } - return m_sndFile.Patterns[p].GetNumRows(); - } - - std::uint8_t get_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const { - CHANNELINDEX numchannels = m_sndFile.GetNumChannels(); - if ( p < 0 || p >= m_sndFile.Patterns.Size() ) { - return 0; - } - if ( r < 0 || r >= (std::int32_t)m_sndFile.Patterns[p].GetNumRows() ) { - return 0; - } - if ( c < 0 || c >= numchannels ) { - return 0; - } - if ( cmd < module::command_note || cmd > module::command_parameter ) { - return 0; - } - switch ( cmd ) { - case module::command_note: return m_sndFile.Patterns[p][r*numchannels+c].note; break; - case module::command_instrument: return m_sndFile.Patterns[p][r*numchannels+c].instr; break; - case module::command_volumeffect: return m_sndFile.Patterns[p][r*numchannels+c].volcmd; break; - case module::command_effect: return m_sndFile.Patterns[p][r*numchannels+c].command; break; - case module::command_volume: return m_sndFile.Patterns[p][r*numchannels+c].vol; break; - case module::command_parameter: return m_sndFile.Patterns[p][r*numchannels+c].param; break; - } - return 0; - } - + std::int32_t get_render_param( int command ) const; + void set_render_param( int command, std::int32_t value ); + std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * mono ); + std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right ); + std::size_t read( std::int32_t samplerate, std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ); + std::size_t read( std::int32_t samplerate, std::size_t count, float * mono ); + std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right ); + std::size_t read( std::int32_t samplerate, std::size_t count, float * left, float * right, float * rear_left, float * rear_right ); + double get_duration_seconds() const; + double get_current_position_seconds() const; + void select_subsong( std::int32_t subsong ); + double seek_seconds( double seconds ); + std::vector<std::string> get_metadata_keys() const; + std::string get_metadata( const std::string & key ) const; + std::int32_t get_current_speed() const; + std::int32_t get_current_tempo() const; + std::int32_t get_current_order() const; + std::int32_t get_current_pattern() const; + std::int32_t get_current_row() const; + std::int32_t get_current_playing_channels() const; + std::int32_t get_num_subsongs() const; + std::int32_t get_num_channels() const; + std::int32_t get_num_orders() const; + std::int32_t get_num_patterns() const; + std::int32_t get_num_instruments() const; + std::int32_t get_num_samples() const; + std::vector<std::string> get_subsong_names() const; + std::vector<std::string> get_channel_names() const; + std::vector<std::string> get_order_names() const; + std::vector<std::string> get_pattern_names() const; + std::vector<std::string> get_instrument_names() const; + std::vector<std::string> get_sample_names() const; + std::int32_t get_order_pattern( std::int32_t o ) const; + std::int32_t get_pattern_num_rows( std::int32_t p ) const; + std::uint8_t get_pattern_row_channel_command( std::int32_t p, std::int32_t r, std::int32_t c, int cmd ) const; }; // class module_impl } // namespace openmpt Modified: trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/libopenmpt/libopenmpt_version.cpp 2013-05-31 16:56:55 UTC (rev 2247) @@ -107,7 +107,8 @@ namespace detail { -class version_mismatch : public openmpt::exception { +// has to be exported for type_info lookup to work +class LIBOPENMPT_CXX_API version_mismatch : public openmpt::exception { public: version_mismatch() throw() { } virtual ~version_mismatch() throw() { } Modified: trunk/OpenMPT/openmpt123/Makefile =================================================================== --- trunk/OpenMPT/openmpt123/Makefile 2013-05-31 16:07:47 UTC (rev 2246) +++ trunk/OpenMPT/openmpt123/Makefile 2013-05-31 16:56:55 UTC (rev 2247) @@ -49,6 +49,7 @@ ../libopenmpt/libopenmpt.cpp \ ../libopenmpt/libopenmpt_c.cpp \ ../libopenmpt/libopenmpt_cxx.cpp \ + ../libopenmpt/libopenmpt_impl.cpp \ ../libopenmpt/libopenmpt_interactive.cpp \ ../libopenmpt/libopenmpt_version.cpp \ @@ -70,8 +71,8 @@ bin/openmpt123: $(OPENMPT123_OBJECTS) $(LD) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ -bin/modplug123: $(OPENMPT123_OBJECTS) - $(LD) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ +bin/modplug123: bin/openmpt123 + cp $^ $@ clean: rm -f bin/openmpt123 bin/modplug123 $(OPENMPT123_OBJECTS) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sag...@us...> - 2013-05-31 20:08:04
|
Revision: 2252 http://sourceforge.net/p/modplug/code/2252 Author: saga-games Date: 2013-05-31 20:07:57 +0000 (Fri, 31 May 2013) Log Message: ----------- [Fix] FT2 Compatibility: Note-Off + Note Delay + Panning ignores the panning effect (test case: PanOff.xm). [Mod] OpenMPT: Version is now 1.22.03.02 Modified Paths: -------------- trunk/OpenMPT/common/versionNumber.h trunk/OpenMPT/soundlib/Snd_fx.cpp Modified: trunk/OpenMPT/common/versionNumber.h =================================================================== --- trunk/OpenMPT/common/versionNumber.h 2013-05-31 19:34:17 UTC (rev 2251) +++ trunk/OpenMPT/common/versionNumber.h 2013-05-31 20:07:57 UTC (rev 2252) @@ -17,7 +17,7 @@ #define VER_MAJORMAJOR 1 #define VER_MAJOR 22 #define VER_MINOR 03 -#define VER_MINORMINOR 01 +#define VER_MINORMINOR 02 //Version string. For example "1.17.02.28" #define MPT_VERSION_STR VER_STRINGIZE(VER_MAJORMAJOR)"."VER_STRINGIZE(VER_MAJOR)"."VER_STRINGIZE(VER_MINOR)"."VER_STRINGIZE(VER_MINORMINOR) Modified: trunk/OpenMPT/soundlib/Snd_fx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-05-31 19:34:17 UTC (rev 2251) +++ trunk/OpenMPT/soundlib/Snd_fx.cpp 2013-05-31 20:07:57 UTC (rev 2252) @@ -1723,8 +1723,15 @@ } } + if(nStartTick != 0 && pChn->rowCommand.note == NOTE_KEYOFF && pChn->rowCommand.volcmd == VOLCMD_PANNING && IsCompatibleMode(TRK_FASTTRACKER2)) + { + // FT2 compatibility: If there's a delayed note off, panning commands are ignored. WTF! + // Test case: PanOff.xm + pChn->rowCommand.volcmd = VOLCMD_NONE; + } + bool triggerNote = (m_nTickCount == nStartTick); // Can be delayed by a note delay effect - // IT Compatibility: Delayed notes (using SDx) that are on the same row as a Row Delay effect are retriggered. Scream Tracker 3 does the same. + // IT compatibility: Delayed notes (using SDx) that are on the same row as a Row Delay effect are retriggered. Scream Tracker 3 does the same. // Test case: PatternDelay-NoteDelay.it if((GetType() & (MOD_TYPE_S3M | MOD_TYPE_IT | MOD_TYPE_MPT)) && nStartTick > 0 && (m_nTickCount % (m_nMusicSpeed + m_nFrameDelay)) == nStartTick) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-01 19:28:28
|
Revision: 2269 http://sourceforge.net/p/modplug/code/2269 Author: manxorist Date: 2013-06-01 19:28:20 +0000 (Sat, 01 Jun 2013) Log Message: ----------- Merged revision(s) 2204, 2208, 2212, 2214, 2217, 2220, 2224, 2259, 2261-2262, 2264, 2267 from branches/manx/mptstring-stdstring-support: [Ref] Add support for std::string in addition to fixed size char arrays to mpt::String::Read, mpt::String::Write, mpt::String::Copy and related mpt::String functions. [Ref] Support std::String with FileReader::ReadString. ........ [Ref] Use the new std::string-enabled mpt::String::CopyN and mpt::String::Write. ........ [Fix] Correctly handle the case of zero length std::string in mpt::String::Write and mpt::String::Copy. [Ref] Add testcases for strings with \0 as the first character. ........ [Ref] Support mpt::String::Write writing to already allocated, but dynamically sized, std::vector<char>. ........ [Ref] More std::string support overloads for mpt::String::Write and mpt::String::Copy. [Ref] Add SanitizeFilename(std::string). ........ [Fix] StringFixer.h needs <string> and <vector>. ........ [Fix] GCC build fixes. ........ [Ref] Remove pointless mpt::String::CopyN(char &[], std::string, size_t). [Ref] Add SanitizeFilename(CString &). ........ [Var] Fixup comments. ........ [Ref] Add mpt::strnlen(const char *, std::size_t). [Fix] Fix mpt::String::CopyN(std::string &, const char *, size_t) to not overrun source buffer if it is not null-terminated. ........ [Ref] Base mpt::String::Copy(std::string &, const char &[]) on mpt::String::CopyN. [Ref] Cleanup StringFixer.h. ........ [Ref] Remove SetNullTerminator(std::string &). ........ Modified Paths: -------------- trunk/OpenMPT/common/StringFixer.h trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/mptString.h trunk/OpenMPT/soundlib/FileReader.h trunk/OpenMPT/soundlib/Load_umx.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/test/test.cpp Property Changed: ---------------- trunk/OpenMPT/ Index: trunk/OpenMPT =================================================================== --- trunk/OpenMPT 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT 2013-06-01 19:28:20 UTC (rev 2269) Property changes on: trunk/OpenMPT ___________________________________________________________________ Modified: svn:mergeinfo ## -1,6 +1,7 ## /branches/manx/build-speedup:1586-1589 /branches/manx/gcc-fixes:2018-2022,2024-2048,2052-2071,2075-2077,2080,2087-2089 /branches/manx/header-dependencies-cleanups:1394-1397,1401-1402,1405-1406 +/branches/manx/mptstring-stdstring-support:2204,2208,2212,2214,2217,2220,2224,2259,2261-2262,2264,2267 /branches/manx/nonglobal-mixer:1715-1841 /branches/manx/profiler:1813 /branches/manx/project-files-cleanups:1378-1382 \ No newline at end of property Modified: trunk/OpenMPT/common/StringFixer.h =================================================================== --- trunk/OpenMPT/common/StringFixer.h 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/common/StringFixer.h 2013-06-01 19:28:20 UTC (rev 2269) @@ -11,6 +11,9 @@ #pragma once +#include <string> +#include <vector> +#include <cstring> #include <string.h> namespace mpt { namespace String @@ -26,7 +29,14 @@ buffer[size - 1] = 0; } + inline void SetNullTerminator(char *buffer, size_t size) + //------------------------------------------------------ + { + ASSERT(size > 0); + buffer[size - 1] = 0; + } + // Remove any chars after the first null char template <size_t size> void FixNullString(char (&buffer)[size]) @@ -47,7 +57,21 @@ } } + inline void FixNullString(std::string & str) + //------------------------------------------ + { + for(std::size_t i = 0; i < str.length(); ++i) + { + if(str[i] == '\0') + { + // if we copied \0 in the middle of the buffer, terminate std::string here + str.resize(i); + break; + } + } + } + enum ReadWriteMode { // Reading / Writing: Standard null-terminated string handling. @@ -65,12 +89,78 @@ // Copy a string from srcBuffer to destBuffer using a given read mode. + // Used for reading strings from files. + // Only use this version of the function if the size of the source buffer is variable. + template <ReadWriteMode mode> + void Read(std::string &dest, const char *srcBuffer, const size_t srcSize) + //----------------------------------------------------------------------- + { + //ASSERT(srcSize > 0); + + dest.clear(); + + if(mode == nullTerminated || mode == maybeNullTerminated) + { + // Copy null-terminated string + // We cannot use std::string::assign(const char*, size_t) because that would not stop at \0s in the middle of the buffer. + for(const char *src = srcBuffer; src != srcBuffer + srcSize && *src; ++src) + { + dest.push_back(*src); + } + + if(mode == nullTerminated) + { + // We assume that the last character of the source buffer is null. + if(dest.length() == srcSize) + { + dest.resize(dest.length() - 1); + } + } + + } else if(mode == spacePadded || mode == spacePaddedNull) + { + // Copy string over, but convert null characters to spaces. + for(const char *src = srcBuffer; src != srcBuffer + srcSize; ++src) + { + char c = *src; + if(c == '\0') + { + c = ' '; + } + dest.push_back(c); + } + + if(mode == spacePaddedNull) + { + if(dest.length() == srcSize) + { + dest.resize(dest.length() - 1); + } + } + + // Trim trailing spaces. + dest = mpt::String::RTrim(dest); + + } + } + + // Used for reading strings from files. + // Preferrably use this version of the function, it is safer. + template <ReadWriteMode mode, size_t srcSize> + void Read(std::string &dest, const char (&srcBuffer)[srcSize]) + //------------------------------------------------------------ + { + STATIC_ASSERT(srcSize > 0); + Read<mode>(dest, srcBuffer, srcSize); + } + + // Copy a string from srcBuffer to destBuffer using a given read mode. // Used for reading strings from files. // Only use this version of the function if the size of the source buffer is variable. template <ReadWriteMode mode, size_t destSize> void Read(char (&destBuffer)[destSize], const char *srcBuffer, const size_t srcSize) - //---------------------------------------------------------------------------------------- + //---------------------------------------------------------------------------------- { STATIC_ASSERT(destSize > 0); //ASSERT(srcSize > 0); @@ -148,12 +238,11 @@ } } - // Used for reading strings from files. // Preferrably use this version of the function, it is safer. template <ReadWriteMode mode, size_t destSize, size_t srcSize> void Read(char (&destBuffer)[destSize], const char (&srcBuffer)[srcSize]) - //----------------------------------------------------------------------------- + //----------------------------------------------------------------------- { STATIC_ASSERT(destSize > 0); STATIC_ASSERT(srcSize > 0); @@ -162,13 +251,13 @@ // Copy a string from srcBuffer to destBuffer using a given write mode. - // Used for writing strings to files. - // Only use this version of the function if the size of the source buffer is variable. - template <ReadWriteMode mode, size_t destSize> - void Write(char (&destBuffer)[destSize], const char *srcBuffer, const size_t srcSize) - //----------------------------------------------------------------------------------------- + // You should only use this function if src and dest are dynamically sized, + // otherwise use one of the safer overloads below. + template <ReadWriteMode mode> + void Write(char *destBuffer, const size_t destSize, const char *srcBuffer, const size_t srcSize) + //---------------------------------------------------------------------------------------------- { - STATIC_ASSERT(destSize > 0); + ASSERT(destSize > 0); ASSERT(srcSize > 0); const size_t maxSize = MIN(destSize, srcSize); @@ -201,33 +290,89 @@ if(mode == nullTerminated || mode == spacePaddedNull) { // Make sure that destination is really null-terminated. - SetNullTerminator(destBuffer); + SetNullTerminator(destBuffer, destSize); } } + // Copy a string from srcBuffer to a dynamically sized std::vector destBuffer using a given write mode. + // Used for writing strings to files. + // Only use this version of the function if the size of the source buffer is variable and the destination buffer also has variable size. + template <ReadWriteMode mode> + void Write(std::vector<char> &destBuffer, const char *srcBuffer, const size_t srcSize) + //------------------------------------------------------------------------------------ + { + ASSERT(destBuffer.size() > 0); + ASSERT(srcSize > 0); + Write<mode>(destBuffer.data(), destBuffer.size(), srcBuffer, srcSize); + } + // Copy a string from srcBuffer to destBuffer using a given write mode. // Used for writing strings to files. + // Only use this version of the function if the size of the source buffer is variable. + template <ReadWriteMode mode, size_t destSize> + void Write(char (&destBuffer)[destSize], const char *srcBuffer, const size_t srcSize) + //----------------------------------------------------------------------------------- + { + STATIC_ASSERT(destSize > 0); + ASSERT(srcSize > 0); + Write<mode>(destBuffer, destSize, srcBuffer, srcSize); + } + + // Copy a string from srcBuffer to destBuffer using a given write mode. + // Used for writing strings to files. // Preferrably use this version of the function, it is safer. template <ReadWriteMode mode, size_t destSize, size_t srcSize> void Write(char (&destBuffer)[destSize], const char (&srcBuffer)[srcSize]) - //------------------------------------------------------------------------------ + //------------------------------------------------------------------------ { STATIC_ASSERT(destSize > 0); STATIC_ASSERT(srcSize > 0); Write<mode, destSize>(destBuffer, srcBuffer, srcSize); } + template <ReadWriteMode mode> + void Write(char *destBuffer, const size_t destSize, const std::string &src) + //------------------------------------------------------------------------- + { + ASSERT(destSize > 0); + Write<mode>(destBuffer, destSize, src.c_str(), src.length()); + } + template <ReadWriteMode mode> + void Write(std::vector<char> &destBuffer, const std::string &src) + //--------------------------------------------------------------- + { + ASSERT(destBuffer.size() > 0); + Write<mode>(destBuffer, src.c_str(), src.length()); + } + + template <ReadWriteMode mode, size_t destSize> + void Write(char (&destBuffer)[destSize], const std::string &src) + //-------------------------------------------------------------- + { + STATIC_ASSERT(destSize > 0); + Write<mode, destSize>(destBuffer, src.c_str(), src.length()); + } + + // Copy from a char array to a fixed size char array. template <size_t destSize> void CopyN(char (&destBuffer)[destSize], const char *srcBuffer, const size_t srcSize = SIZE_MAX) //---------------------------------------------------------------------------------------------- { const size_t copySize = MIN(destSize - 1, srcSize); - strncpy(destBuffer, srcBuffer, copySize); + std::strncpy(destBuffer, srcBuffer, copySize); destBuffer[copySize] = '\0'; } + // Copy at most srcSize characters from srcBuffer to a std::string. + static inline void CopyN(std::string &dest, const char *srcBuffer, const size_t srcSize = SIZE_MAX) + //------------------------------------------------------------------------------------------------- + { + dest.assign(srcBuffer, srcBuffer + mpt::strnlen(srcBuffer, srcSize)); + } + + // Copy from one fixed size char array to another one. template <size_t destSize, size_t srcSize> void Copy(char (&destBuffer)[destSize], const char (&srcBuffer)[srcSize]) @@ -236,6 +381,29 @@ CopyN(destBuffer, srcBuffer, srcSize); } + // Copy from a std::string to a fixed size char array. + template <size_t destSize> + void Copy(char (&destBuffer)[destSize], const std::string &src) + //------------------------------------------------------------- + { + CopyN(destBuffer, src.c_str(), src.length()); + } + // Copy from a fixed size char array to a std::string. + template <size_t srcSize> + void Copy(std::string &dest, const char (&srcBuffer)[srcSize]) + //---------------------------------------------------------------------------- + { + CopyN(dest, srcBuffer, srcSize); + } + + // Copy from a std::string to a std::string. + static inline void Copy(std::string &dest, const std::string &src) + //---------------------------------------------------------------- + { + dest.assign(src); + } + + } } // namespace mpt::String Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/common/misc_util.h 2013-06-01 19:28:20 UTC (rev 2269) @@ -184,6 +184,23 @@ #endif // MODPLUG_TRACKER +static inline char SanitizeFilenameChar(char c) +//--------------------------------------------- +{ + if( c == '\\' || + c == '\"' || + c == '/' || + c == ':' || + c == '?' || + c == '<' || + c == '>' || + c == '*') + { + c = '_'; + } + return c; +} + // Sanitize a filename (remove special chars) template <size_t size> void SanitizeFilename(char (&buffer)[size]) @@ -192,19 +209,26 @@ STATIC_ASSERT(size > 0); for(size_t i = 0; i < size; i++) { - if( buffer[i] == '\\' || - buffer[i] == '\"' || - buffer[i] == '/' || - buffer[i] == ':' || - buffer[i] == '?' || - buffer[i] == '<' || - buffer[i] == '>' || - buffer[i] == '*') - { - buffer[i] = '_'; - } + buffer[i] = SanitizeFilenameChar(buffer[i]); } } +static inline void SanitizeFilename(std::string &str) +//--------------------------------------------------- +{ + for(size_t i = 0; i < str.length(); i++) + { + str[i] = SanitizeFilenameChar(str[i]); + } +} +#ifdef MODPLUG_TRACKER +static inline void SanitizeFilename(CString &str) +//----------------------------------------------- +{ + std::string tmp = str; + SanitizeFilename(tmp); + str = tmp.c_str(); +} +#endif // Greatest Common Divisor. Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/common/mptString.h 2013-06-01 19:28:20 UTC (rev 2269) @@ -12,6 +12,7 @@ #include <string> #include <cstdio> +#include <cstring> #include <stdio.h> #if MPT_COMPILER_GCC || MPT_COMPILER_CLANG #include <strings.h> // for strcasecmp @@ -105,6 +106,24 @@ } // namespace String +static inline std::size_t strnlen(const char *str, std::size_t n) +//--------------------------------------------------------------- +{ + if(n >= SIZE_MAX) + { + return std::strlen(str); + } + for(std::size_t i = 0; i < n; ++i) + { + if(str[i] == '\0') + { + return i; + } + } + return n; +} + + } // namespace mpt Modified: trunk/OpenMPT/soundlib/FileReader.h =================================================================== --- trunk/OpenMPT/soundlib/FileReader.h 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/soundlib/FileReader.h 2013-06-01 19:28:20 UTC (rev 2269) @@ -772,6 +772,22 @@ } } + // Read a string of length srcSize into a std::string dest using a given read mode. + // The file cursor is advanced by "srcSize" bytes. + template<mpt::String::ReadWriteMode mode> + bool ReadString(std::string &dest, const off_t srcSize) + { + if(CanRead(srcSize)) + { + mpt::String::Read<mode>(dest, DataContainer().GetPartialRawData(streamPos, srcSize), srcSize); + streamPos += srcSize; + return true; + } else + { + return false; + } + } + // Read an array. // If successful, the file cursor is advanced by the size of the array. // Otherwise, the target is zeroed. Modified: trunk/OpenMPT/soundlib/Load_umx.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_umx.cpp 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/soundlib/Load_umx.cpp 2013-06-01 19:28:20 UTC (rev 2269) @@ -296,7 +296,7 @@ m_nSamples++; if(static_cast<size_t>(objName) < names.size()) { - mpt::String::CopyN(m_szNames[GetNumSamples()], names[objName].c_str()); + mpt::String::Copy(m_szNames[GetNumSamples()], names[objName]); } } } Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-06-01 19:28:20 UTC (rev 2269) @@ -654,7 +654,7 @@ mpt::String::Write<mpt::String::spacePadded>(fileHeader.songName, m_szNames[0]); fileHeader.eof = 0x1A; std::string openMptTrackerName = MptVersion::GetOpenMPTVersionStr(); - mpt::String::Write<mpt::String::spacePadded>(fileHeader.trackerName, openMptTrackerName.c_str(), openMptTrackerName.length()); + mpt::String::Write<mpt::String::spacePadded>(fileHeader.trackerName, openMptTrackerName); // Writing song header fileHeader.version = 0x0104; // XM Format v1.04 Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-06-01 19:23:32 UTC (rev 2268) +++ trunk/OpenMPT/test/test.cpp 2013-06-01 19:28:20 UTC (rev 2269) @@ -429,6 +429,11 @@ VERIFY_EQUAL( mpt::String::RTrim(" "), "" ); VERIFY_EQUAL( mpt::String::Trim(" "), "" ); + // weird things with std::string containing \0 in the middle and trimming \0 + VERIFY_EQUAL( std::string("\0\ta\0b ",6).length(), 6 ); + VERIFY_EQUAL( mpt::String::RTrim(std::string("\0\ta\0b ",6)), std::string("\0\ta\0b",5) ); + VERIFY_EQUAL( mpt::String::Trim(std::string("\0\ta\0b\0",6),std::string("\0",1)), std::string("\ta\0b",4) ); + // These should fail to compile //Util::Round<std::string>(1.0); //Util::Round<int64>(1.0); @@ -1393,6 +1398,7 @@ void TestStringIO() //----------------- { + char src0[4] = { '\0', 'X', ' ', 'X' }; // Weird empty buffer char src1[4] = { 'X', ' ', '\0', 'X' }; // Weird buffer (hello Impulse Tracker) char src2[4] = { 'X', 'Y', 'Z', ' ' }; // Full buffer, last character space char src3[4] = { 'X', 'Y', 'Z', '!' }; // Full buffer, last character non-space @@ -1412,21 +1418,25 @@ VERIFY_EQUAL_NONCONT(dst[i], '\0'); /* Ensure that rest of the buffer is completely nulled */ // Check reading of null-terminated string into larger buffer + ReadTest(nullTerminated, dst1, src0, ""); ReadTest(nullTerminated, dst1, src1, "X "); ReadTest(nullTerminated, dst1, src2, "XYZ"); ReadTest(nullTerminated, dst1, src3, "XYZ"); // Check reading of string that should be null-terminated, but is maybe too long to still hold the null character. + ReadTest(maybeNullTerminated, dst1, src0, ""); ReadTest(maybeNullTerminated, dst1, src1, "X "); ReadTest(maybeNullTerminated, dst1, src2, "XYZ "); ReadTest(maybeNullTerminated, dst1, src3, "XYZ!"); // Check reading of space-padded strings with ignored last character + ReadTest(spacePaddedNull, dst1, src0, " X"); ReadTest(spacePaddedNull, dst1, src1, "X"); ReadTest(spacePaddedNull, dst1, src2, "XYZ"); ReadTest(spacePaddedNull, dst1, src3, "XYZ"); // Check reading of space-padded strings + ReadTest(spacePadded, dst1, src0, " X X"); ReadTest(spacePadded, dst1, src1, "X X"); ReadTest(spacePadded, dst1, src2, "XYZ"); ReadTest(spacePadded, dst1, src3, "XYZ!"); @@ -1434,21 +1444,25 @@ /////////////////////////////// // Check reading of null-terminated string into smaller buffer + ReadTest(nullTerminated, dst2, src0, ""); ReadTest(nullTerminated, dst2, src1, "X "); ReadTest(nullTerminated, dst2, src2, "XY"); ReadTest(nullTerminated, dst2, src3, "XY"); // Check reading of string that should be null-terminated, but is maybe too long to still hold the null character. + ReadTest(maybeNullTerminated, dst2, src0, ""); ReadTest(maybeNullTerminated, dst2, src1, "X "); ReadTest(maybeNullTerminated, dst2, src2, "XY"); ReadTest(maybeNullTerminated, dst2, src3, "XY"); // Check reading of space-padded strings with ignored last character + ReadTest(spacePaddedNull, dst2, src0, " X"); ReadTest(spacePaddedNull, dst2, src1, "X"); ReadTest(spacePaddedNull, dst2, src2, "XY"); ReadTest(spacePaddedNull, dst2, src3, "XY"); // Check reading of space-padded strings + ReadTest(spacePadded, dst2, src0, " X"); ReadTest(spacePadded, dst2, src1, "X"); ReadTest(spacePadded, dst2, src2, "XY"); ReadTest(spacePadded, dst2, src3, "XY"); @@ -1456,21 +1470,25 @@ /////////////////////////////// // Check writing of null-terminated string into larger buffer + WriteTest(nullTerminated, dst1, src0, ""); WriteTest(nullTerminated, dst1, src1, "X "); WriteTest(nullTerminated, dst1, src2, "XYZ "); WriteTest(nullTerminated, dst1, src3, "XYZ!"); // Check writing of string that should be null-terminated, but is maybe too long to still hold the null character. + WriteTest(maybeNullTerminated, dst1, src0, ""); WriteTest(maybeNullTerminated, dst1, src1, "X "); WriteTest(maybeNullTerminated, dst1, src2, "XYZ "); WriteTest(maybeNullTerminated, dst1, src3, "XYZ!"); // Check writing of space-padded strings with last character set to null + WriteTest(spacePaddedNull, dst1, src0, " "); WriteTest(spacePaddedNull, dst1, src1, "X "); WriteTest(spacePaddedNull, dst1, src2, "XYZ "); WriteTest(spacePaddedNull, dst1, src3, "XYZ! "); // Check writing of space-padded strings + WriteTest(spacePadded, dst1, src0, " "); WriteTest(spacePadded, dst1, src1, "X "); WriteTest(spacePadded, dst1, src2, "XYZ "); WriteTest(spacePadded, dst1, src3, "XYZ! "); @@ -1478,27 +1496,133 @@ /////////////////////////////// // Check writing of null-terminated string into smaller buffer + WriteTest(nullTerminated, dst2, src0, ""); WriteTest(nullTerminated, dst2, src1, "X "); WriteTest(nullTerminated, dst2, src2, "XY"); WriteTest(nullTerminated, dst2, src3, "XY"); // Check writing of string that should be null-terminated, but is maybe too long to still hold the null character. + WriteTest(maybeNullTerminated, dst2, src0, ""); WriteTest(maybeNullTerminated, dst2, src1, "X "); WriteTest(maybeNullTerminated, dst2, src2, "XYZ"); WriteTest(maybeNullTerminated, dst2, src3, "XYZ"); // Check writing of space-padded strings with last character set to null + WriteTest(spacePaddedNull, dst2, src0, " "); WriteTest(spacePaddedNull, dst2, src1, "X "); WriteTest(spacePaddedNull, dst2, src2, "XY"); WriteTest(spacePaddedNull, dst2, src3, "XY"); // Check writing of space-padded strings + WriteTest(spacePadded, dst2, src0, " "); WriteTest(spacePadded, dst2, src1, "X "); WriteTest(spacePadded, dst2, src2, "XYZ"); WriteTest(spacePadded, dst2, src3, "XYZ"); - /////////////////////////////// +#undef ReadTest +#undef WriteTest + { + + std::string dststring; + std::string src0string = std::string(src0, CountOf(src0)); + std::string src1string = std::string(src1, CountOf(src1)); + std::string src2string = std::string(src2, CountOf(src2)); + std::string src3string = std::string(src3, CountOf(src3)); + +#define ReadTest(mode, dst, src, expectedResult) \ + mpt::String::Read<mpt::String:: mode >(dst, src); \ + VERIFY_EQUAL_NONCONT(dst, expectedResult); /* Ensure that the strings are identical */ \ + +#define WriteTest(mode, dst, src, expectedResult) \ + mpt::String::Write<mpt::String:: mode >(dst, src); \ + VERIFY_EQUAL_NONCONT(strncmp(dst, expectedResult, CountOf(dst)), 0); /* Ensure that the strings are identical */ \ + for(size_t i = strlen(dst); i < CountOf(dst); i++) \ + VERIFY_EQUAL_NONCONT(dst[i], '\0'); /* Ensure that rest of the buffer is completely nulled */ + + // Check reading of null-terminated string into std::string + ReadTest(nullTerminated, dststring, src0, ""); + ReadTest(nullTerminated, dststring, src1, "X "); + ReadTest(nullTerminated, dststring, src2, "XYZ"); + ReadTest(nullTerminated, dststring, src3, "XYZ"); + + // Check reading of string that should be null-terminated, but is maybe too long to still hold the null character. + ReadTest(maybeNullTerminated, dststring, src0, ""); + ReadTest(maybeNullTerminated, dststring, src1, "X "); + ReadTest(maybeNullTerminated, dststring, src2, "XYZ "); + ReadTest(maybeNullTerminated, dststring, src3, "XYZ!"); + + // Check reading of space-padded strings with ignored last character + ReadTest(spacePaddedNull, dststring, src0, " X"); + ReadTest(spacePaddedNull, dststring, src1, "X"); + ReadTest(spacePaddedNull, dststring, src2, "XYZ"); + ReadTest(spacePaddedNull, dststring, src3, "XYZ"); + + // Check reading of space-padded strings + ReadTest(spacePadded, dststring, src0, " X X"); + ReadTest(spacePadded, dststring, src1, "X X"); + ReadTest(spacePadded, dststring, src2, "XYZ"); + ReadTest(spacePadded, dststring, src3, "XYZ!"); + + /////////////////////////////// + + // Check writing of null-terminated string into larger buffer + WriteTest(nullTerminated, dst1, src0string, ""); + WriteTest(nullTerminated, dst1, src1string, "X "); + WriteTest(nullTerminated, dst1, src2string, "XYZ "); + WriteTest(nullTerminated, dst1, src3string, "XYZ!"); + + // Check writing of string that should be null-terminated, but is maybe too long to still hold the null character. + WriteTest(maybeNullTerminated, dst1, src0string, ""); + WriteTest(maybeNullTerminated, dst1, src1string, "X "); + WriteTest(maybeNullTerminated, dst1, src2string, "XYZ "); + WriteTest(maybeNullTerminated, dst1, src3string, "XYZ!"); + + // Check writing of space-padded strings with last character set to null + WriteTest(spacePaddedNull, dst1, src0string, " "); + WriteTest(spacePaddedNull, dst1, src1string, "X "); + WriteTest(spacePaddedNull, dst1, src2string, "XYZ "); + WriteTest(spacePaddedNull, dst1, src3string, "XYZ! "); + + // Check writing of space-padded strings + WriteTest(spacePadded, dst1, src0string, " "); + WriteTest(spacePadded, dst1, src1string, "X "); + WriteTest(spacePadded, dst1, src2string, "XYZ "); + WriteTest(spacePadded, dst1, src3string, "XYZ! "); + + /////////////////////////////// + + // Check writing of null-terminated string into smaller buffer + WriteTest(nullTerminated, dst2, src0string, ""); + WriteTest(nullTerminated, dst2, src1string, "X "); + WriteTest(nullTerminated, dst2, src2string, "XY"); + WriteTest(nullTerminated, dst2, src3string, "XY"); + + // Check writing of string that should be null-terminated, but is maybe too long to still hold the null character. + WriteTest(maybeNullTerminated, dst2, src0string, ""); + WriteTest(maybeNullTerminated, dst2, src1string, "X "); + WriteTest(maybeNullTerminated, dst2, src2string, "XYZ"); + WriteTest(maybeNullTerminated, dst2, src3string, "XYZ"); + + // Check writing of space-padded strings with last character set to null + WriteTest(spacePaddedNull, dst2, src0string, " "); + WriteTest(spacePaddedNull, dst2, src1string, "X "); + WriteTest(spacePaddedNull, dst2, src2string, "XY"); + WriteTest(spacePaddedNull, dst2, src3string, "XY"); + + // Check writing of space-padded strings + WriteTest(spacePadded, dst2, src0string, " "); + WriteTest(spacePadded, dst2, src1string, "X "); + WriteTest(spacePadded, dst2, src2string, "XYZ"); + WriteTest(spacePadded, dst2, src3string, "XYZ"); + + /////////////////////////////// + +#undef ReadTest +#undef WriteTest + + } + // Test FixNullString() mpt::String::FixNullString(src1); mpt::String::FixNullString(src2); @@ -1507,9 +1631,6 @@ VERIFY_EQUAL_NONCONT(strncmp(src2, "XYZ", CountOf(src2)), 0); VERIFY_EQUAL_NONCONT(strncmp(src3, "XYZ", CountOf(src3)), 0); -#undef ReadTest -#undef WriteTest - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-01 19:51:25
|
Revision: 2271 http://sourceforge.net/p/modplug/code/2271 Author: manxorist Date: 2013-06-01 19:51:19 +0000 (Sat, 01 Jun 2013) Log Message: ----------- Merged revision(s) 2203-2238 from branches/manx/instrument-fields-fixes: [Fix] Make instrument fields reading and writing endian aware. [Ref] Add ReadTruncatedIntLE to class FileReader. ........ [Fix] Correctly calculate array size in GET_MPTHEADER_array_member. (broke in r2203) ........ [Fix] GCC build fix. ........ [Ref] Fix a bunch of gcc warnings in WriteInstrumentHeaderStructOrField(). ........ [Ref] Use Util::MaxValueOfType instead of ~0u. ........ [Ref] Silence a stupid GCC warning about unsigned type comparison against 0 in WriteInstrumentHeaderStructOrField() in cases where a smaller type needs to be sign or zero extended. ........ Revision Links: -------------- http://sourceforge.net/p/modplug/code/2203 Modified Paths: -------------- trunk/OpenMPT/soundlib/Endianness.h trunk/OpenMPT/soundlib/FileReader.h trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Property Changed: ---------------- trunk/OpenMPT/ Index: trunk/OpenMPT =================================================================== --- trunk/OpenMPT 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT 2013-06-01 19:51:19 UTC (rev 2271) Property changes on: trunk/OpenMPT ___________________________________________________________________ Modified: svn:mergeinfo ## -1,6 +1,7 ## /branches/manx/build-speedup:1586-1589 /branches/manx/gcc-fixes:2018-2022,2024-2048,2052-2071,2075-2077,2080,2087-2089 /branches/manx/header-dependencies-cleanups:1394-1397,1401-1402,1405-1406 +/branches/manx/instrument-fields-fixes:2203-2238 /branches/manx/mptstring-stdstring-support:2204,2208,2212,2214,2217,2220,2224,2259,2261-2262,2264,2267 /branches/manx/nonglobal-mixer:1715-1841 /branches/manx/profiler:1813 \ No newline at end of property Modified: trunk/OpenMPT/soundlib/Endianness.h =================================================================== --- trunk/OpenMPT/soundlib/Endianness.h 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/Endianness.h 2013-06-01 19:51:19 UTC (rev 2271) @@ -79,6 +79,16 @@ inline int32 SwapBytesLE_(unaligned_int32 *value) { return *value; } inline int16 SwapBytesLE_(unaligned_int16 *value) { return *value; } #endif +// Do NOT remove these overloads, even if they seem useless. +// We do not want risking to extend 8bit integers to int and then endian-converting and casting back to int. +// Thus these overloads. +inline uint8 SwapBytesLE_(uint8 *value) { return *value; } +inline int8 SwapBytesLE_(int8 *value) { return *value; } +inline char SwapBytesLE_(char *value) { return *value; } +inline uint8 SwapBytesBE_(uint8 *value) { return *value; } +inline int8 SwapBytesBE_(int8 *value) { return *value; } +inline char SwapBytesBE_(char *value) { return *value; } + // GCC will not bind references to members of packed structures, workaround it by using a raw pointer. // This is a temporary solution as this pointer might of course be unaligned which GCC seems to not care about in that case. #define SwapBytesBE(value) SwapBytesBE_(&(value)) Modified: trunk/OpenMPT/soundlib/FileReader.h =================================================================== --- trunk/OpenMPT/soundlib/FileReader.h 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/FileReader.h 2013-06-01 19:51:19 UTC (rev 2271) @@ -22,6 +22,7 @@ #endif #include <limits> #include <vector> +#include <cstring> // change to show warnings for functions which trigger pre-caching the whole file for unseekable streams @@ -566,7 +567,8 @@ return true; } -protected: +public: + // Read some kind of integer in little-endian format. // If successful, the file cursor is advanced by the size of the integer. template <typename T> @@ -599,7 +601,46 @@ } } -public: + // Read a integer in little-endian format which has some of its higher bytes not stored in file. + // If successful, the file cursor is advanced by the given size. + template <typename T> + T ReadTruncatedIntLE(off_t size) + { + static_assert(std::numeric_limits<T>::is_integer == true, "Target type is a not an integer"); + ASSERT(sizeof(T) >= size); + if(size == 0) + { + return 0; + } + if(!CanRead(size)) + { + return 0; + } + uint8 buf[sizeof(T)]; + for(std::size_t i = 0; i < size; ++i) + { + Read(buf[i]); + } + if(std::numeric_limits<T>::is_signed) + { + for(std::size_t i = size; i < sizeof(T); ++i) + { + // sign extend + buf[i] = (buf[size-1] & 0x80) ? 0xff : 0x00; + } + } else + { + for(std::size_t i = size; i < sizeof(T); ++i) + { + // zero extend + buf[i] = 0x00; + } + } + T target; + std::memcpy(&target, buf, sizeof(T)); + return SwapBytesLE(target); + } + // Read unsigned 32-Bit integer in little-endian format. // If successful, the file cursor is advanced by the size of the integer. uint32 ReadUint32LE() Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-01 19:51:19 UTC (rev 2271) @@ -1955,17 +1955,15 @@ fwrite(&size, 1, sizeof(int16), f); //write size for(UINT nins=1; nins<=nInstruments; nins++) //for all instruments... { - char *pField; if (Instruments[nins]) { - pField = GetInstrumentHeaderFieldPointer(Instruments[nins], code, size); //get ptr to field + WriteInstrumentHeaderStructOrField(Instruments[nins], f, code, size); } else { ModInstrument *emptyInstrument = new ModInstrument(); - pField = GetInstrumentHeaderFieldPointer(emptyInstrument, code, size); //get ptr to field + WriteInstrumentHeaderStructOrField(emptyInstrument, f, code, size); delete emptyInstrument; } - fwrite(pField, 1, size, f); //write field data } } Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2013-06-01 19:51:19 UTC (rev 2271) @@ -504,7 +504,7 @@ // instruments' header for(i=0; i<m_nInstruments; i++) { - if(Instruments[i+1]) WriteInstrumentHeaderStruct(Instruments[i+1], f); + if(Instruments[i+1]) WriteInstrumentHeaderStructOrField(Instruments[i+1], f); // write separator tag code = 'SEP@'; fwrite(&code, 1, sizeof(uint32), f); Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-06-01 19:51:19 UTC (rev 2271) @@ -1122,7 +1122,7 @@ int32 code = MULTICHAR4_LE_MSVC('M','P','T','X'); fwrite(&code, 1, sizeof(int32), f); // Write extension tag - WriteInstrumentHeaderStruct(pIns, f); // Write full extended header. + WriteInstrumentHeaderStructOrField(pIns, f); // Write full extended header. fclose(f); return true; @@ -1708,7 +1708,7 @@ int32 code = MULTICHAR4_LE_MSVC('M','P','T','X'); SwapBytesLE(code); fwrite(&code, 1, sizeof(int32), f); // Write extension tag - WriteInstrumentHeaderStruct(pIns, f); // Write full extended header. + WriteInstrumentHeaderStructOrField(pIns, f); // Write full extended header. fclose(f); return true; @@ -1720,18 +1720,27 @@ void ReadInstrumentExtensionField(ModInstrument* pIns, const uint32 code, const uint16 size, FileReader &file) //------------------------------------------------------------------------------------------------------------ { - // get field's address in instrument's header - char *fadr = GetInstrumentHeaderFieldPointer(pIns, code, size); - - if(fadr && code != MULTICHAR4_LE_MSVC('K','[','.','.')) // copy field data in instrument's header - memcpy(fadr, file.GetRawData(), size); // (except for keyboard mapping) - if(fadr && code == MULTICHAR4_LE_MSVC('n','[','.','.')) + if(code == MULTICHAR4_LE_MSVC('K','[','.','.')) + { + // skip keyboard mapping + file.Skip(size); + return; + } + + bool success = ReadInstrumentHeaderField(pIns, code, size, file); + + if(!success) + { + file.Skip(size); + return; + } + + if(code == MULTICHAR4_LE_MSVC('n','[','.','.')) mpt::String::SetNullTerminator(pIns->name); - if(fadr && code == MULTICHAR4_LE_MSVC('f','n','[','.')) + if(code == MULTICHAR4_LE_MSVC('f','n','[','.')) mpt::String::SetNullTerminator(pIns->filename); - file.Skip(size); - if(code == MULTICHAR4_LE_MSVC('d','F','.','.') && fadr != nullptr) // 'dF..' field requires additional processing. + if(code == MULTICHAR4_LE_MSVC('d','F','.','.')) // 'dF..' field requires additional processing. ConvertReadExtendedFlags(pIns); } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-01 19:51:19 UTC (rev 2271) @@ -44,8 +44,8 @@ - both following functions need to be updated when adding a new member in ModInstrument : -void WriteInstrumentHeaderStruct(ModInstrument * input, FILE * file); -BYTE * GetInstrumentHeaderFieldPointer(ModInstrument * input, uint32 fcode, int16 fsize); +void WriteInstrumentHeaderStructOrField(ModInstrument * input, FILE * file, uint32 only_this_code, int16 fixedsize); +bool ReadInstrumentHeaderField(ModInstrument * input, uint32 fcode, int16 fsize, FileReader &file); - see below for body declaration. @@ -166,27 +166,73 @@ #define MULTICHAR_STRING_TO_INT(str) MULTICHAR4_LE_MSVC((str)[0],(str)[1],(str)[2],(str)[3]) +template<typename T, bool is_signed> struct IsNegativeFunctor { bool operator()(T val) const { return val < 0; } }; +template<typename T> struct IsNegativeFunctor<T, true> { bool operator()(T val) const { return val < 0; } }; +template<typename T> struct IsNegativeFunctor<T, false> { bool operator()(T /*val*/) const { return false; } }; + +template<typename T> +bool IsNegative(const T &val) +{ + return IsNegativeFunctor<T, std::numeric_limits<T>::is_signed>()(val); +} + // -------------------------------------------------------------------------------------------- // Convenient macro to help WRITE_HEADER declaration for single type members ONLY (non-array) // -------------------------------------------------------------------------------------------- #define WRITE_MPTHEADER_sized_member(name,type,code) \ -static_assert(sizeof(input->name) >= sizeof(type), "Instrument property does not fit into specified type!");\ -fcode = MULTICHAR_STRING_TO_INT(#code);\ -fwrite(& fcode , 1 , sizeof( uint32 ) , file);\ -fsize = sizeof( type );\ -fwrite(& fsize , 1 , sizeof( int16 ) , file);\ -fwrite(&input-> name , 1 , fsize , file); + static_assert(sizeof(input->name) >= sizeof(type), "Instrument property does not fit into specified type!");\ + fcode = MULTICHAR_STRING_TO_INT(#code);\ + fsize = sizeof( type );\ + if(only_this_code == Util::MaxValueOfType(only_this_code)) \ + { \ + fwrite(& fcode , 1 , sizeof( uint32 ) , file);\ + fwrite(& fsize , 1 , sizeof( int16 ) , file);\ + fwrite(&input-> name , 1 , fsize , file); \ + } else if(only_this_code == fcode)\ + { \ + /* hackish workaround to resolve mismatched size values: */ \ + /* nResampling was a long time declared as uint32 but these macro tables used uint16 and UINT. */ \ + /* This worked fine on little-endian, on big-endian not so much. Thus support writing size-mismatched fields. */ \ + ASSERT(fixedsize >= fsize); /* ASSERT(fixedsize == fsize); */ \ + type tmp = input-> name; \ + tmp = SwapBytesLE(tmp); \ + fwrite(&tmp , 1 , fsize , file); \ + if(fixedsize > fsize) \ + { \ + for(int16 i = 0; i < fixedsize - fsize; ++i) \ + { \ + uint8 fillbyte = !IsNegative(tmp) ? 0 : 0xff; /* sign extend */ \ + fwrite(&fillbyte, 1, 1, file); \ + } \ + } \ + } \ +/**/ // -------------------------------------------------------------------------------------------- // Convenient macro to help WRITE_HEADER declaration for array members ONLY // -------------------------------------------------------------------------------------------- #define WRITE_MPTHEADER_array_member(name,type,code,arraysize) \ -ASSERT(sizeof(input->name) >= sizeof(type) * arraysize);\ -fcode = MULTICHAR_STRING_TO_INT(#code);\ -fwrite(& fcode , 1 , sizeof( uint32 ) , file);\ -fsize = sizeof( type ) * arraysize;\ -fwrite(& fsize , 1 , sizeof( int16 ) , file);\ -fwrite(&input-> name , 1 , fsize , file); + ASSERT(sizeof(input->name) >= sizeof(type) * arraysize);\ + fcode = MULTICHAR_STRING_TO_INT(#code);\ + fsize = sizeof( type ) * arraysize;\ + if(only_this_code == Util::MaxValueOfType(only_this_code)) \ + { \ + fwrite(& fcode , 1 , sizeof( uint32 ) , file);\ + fwrite(& fsize , 1 , sizeof( int16 ) , file);\ + fwrite(&input-> name , 1 , fsize , file); \ + } else if(only_this_code == fcode)\ + { \ + /* ASSERT(fixedsize <= fsize); */ \ + fsize = fixedsize; /* just trust the size we got passed */ \ + for(std::size_t i = 0; i < fsize/sizeof(type); ++i) \ + { \ + type tmp; \ + tmp = input-> name [i]; \ + tmp = SwapBytesLE(tmp); \ + fwrite(&tmp, 1, sizeof(type), file); \ + } \ + } \ +/**/ namespace { // Create 'dF..' entry. @@ -214,19 +260,29 @@ } // unnamed namespace. // Write (in 'file') 'input' ModInstrument with 'code' & 'size' extra field infos for each member -void WriteInstrumentHeaderStruct(ModInstrument * input, FILE * file) +void WriteInstrumentHeaderStructOrField(ModInstrument * input, FILE * file, uint32 only_this_code, int16 fixedsize) { uint32 fcode; int16 fsize; + +if(only_this_code != Util::MaxValueOfType(only_this_code)) +{ + ASSERT(fixedsize > 0); +} + WRITE_MPTHEADER_sized_member( nFadeOut , UINT , FO.. ) -{ // dwFlags needs to be constructed so write it manually. +if(only_this_code == Util::MaxValueOfType(only_this_code) || only_this_code == MULTICHAR_STRING_TO_INT("dF..")){ // dwFlags needs to be constructed so write it manually. //WRITE_MPTHEADER_sized_member( dwFlags , DWORD , dF.. ) - const DWORD dwFlags = CreateExtensionFlags(*input); + uint32 dwFlags = CreateExtensionFlags(*input); fcode = MULTICHAR_STRING_TO_INT("dF.."); - fwrite(&fcode, 1, sizeof(int32), file); fsize = sizeof(dwFlags); - fwrite(&fsize, 1, sizeof(int16), file); + if(!only_this_code) + { + fwrite(&fcode, 1, sizeof(int32), file); + fwrite(&fsize, 1, sizeof(int16), file); + } + dwFlags = SwapBytesLE(dwFlags); fwrite(&dwFlags, 1, fsize, file); } @@ -288,30 +344,52 @@ WRITE_MPTHEADER_sized_member( midiPWD , int8 , MPWD ) } + // -------------------------------------------------------------------------------------------- // Convenient macro to help GET_HEADER declaration for single type members ONLY (non-array) // -------------------------------------------------------------------------------------------- #define GET_MPTHEADER_sized_member(name,type,code) \ -if(fcode == MULTICHAR_STRING_TO_INT(#code)) {\ -if( fsize <= sizeof( type ) ) pointer = (char *)(&input-> name);\ -} else + if(fcode == MULTICHAR_STRING_TO_INT(#code)) {\ + if( fsize <= sizeof( type ) ) \ + { \ + /* hackish workaround to resolve mismatched size values: */ \ + /* nResampling was a long time declared as uint32 but these macro tables used uint16 and UINT. */ \ + /* This worked fine on little-endian, on big-endian not so much. Thus support reading size-mismatched fields. */ \ + type tmp; \ + if(!file.CanRead(fsize)) return false; \ + tmp = file.ReadTruncatedIntLE<type>(fsize); \ + STATIC_ASSERT(sizeof(tmp) == sizeof(input-> name )); \ + memcpy(&(input-> name ), &tmp, sizeof(type)); \ + return true; \ + } \ + } else \ +/**/ // -------------------------------------------------------------------------------------------- // Convenient macro to help GET_HEADER declaration for array members ONLY // -------------------------------------------------------------------------------------------- #define GET_MPTHEADER_array_member(name,type,code,arraysize) \ -if(fcode == MULTICHAR_STRING_TO_INT(#code)) {\ -if( fsize <= sizeof( type ) * arraysize ) pointer = (char *)(&input-> name);\ -} else + if(fcode == MULTICHAR_STRING_TO_INT(#code)) {\ + if( fsize <= sizeof( type ) * arraysize ) \ + { \ + if(!file.CanRead(sizeof(type) * arraysize)) return false; \ + for(std::size_t i = 0; i < arraysize; ++i) \ + { \ + input-> name [i] = file.ReadIntLE<type>(); \ + } \ + return true; \ + } \ + } else \ +/**/ + // Return a pointer on the wanted field in 'input' ModInstrument given field code & size -char *GetInstrumentHeaderFieldPointer(const ModInstrument *input, uint32 fcode, uint16 fsize) +bool ReadInstrumentHeaderField(ModInstrument *input, uint32 fcode, uint16 fsize, FileReader &file) { -if(input == nullptr) return nullptr; -char *pointer = nullptr; +if(input == nullptr) return false; GET_MPTHEADER_sized_member( nFadeOut , UINT , FO.. ) -GET_MPTHEADER_sized_member( dwFlags , DWORD , dF.. ) +GET_MPTHEADER_sized_member( dwFlags , uint32 , dF.. ) GET_MPTHEADER_sized_member( nGlobalVol , UINT , GV.. ) GET_MPTHEADER_sized_member( nPan , UINT , P... ) GET_MPTHEADER_sized_member( VolEnv.nNodes , UINT , VE.. ) @@ -370,7 +448,8 @@ GET_MPTHEADER_sized_member( midiPWD , int8 , MPWD ) {} -return pointer; +return false; + } // -! NEW_FEATURE#0027 Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-01 19:30:14 UTC (rev 2270) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-01 19:51:19 UTC (rev 2271) @@ -40,11 +40,13 @@ #include "../sounddsp/DSP.h" #include "../sounddsp/EQ.h" + +class FileReader; // ----------------------------------------------------------------------------------------- // MODULAR ModInstrument FIELD ACCESS : body content at the (near) top of Sndfile.cpp !!! // ----------------------------------------------------------------------------------------- -extern void WriteInstrumentHeaderStruct(ModInstrument * input, FILE * file); -extern char *GetInstrumentHeaderFieldPointer(const ModInstrument * input, uint32 fcode, uint16 fsize); +extern void WriteInstrumentHeaderStructOrField(ModInstrument * input, FILE * file, uint32 only_this_code = -1 /* -1 for all */, int16 fixedsize = 0); +extern bool ReadInstrumentHeaderField(ModInstrument * input, uint32 fcode, uint16 fsize, FileReader &file); // -------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------- This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-01 23:10:14
|
Revision: 2277 http://sourceforge.net/p/modplug/code/2277 Author: manxorist Date: 2013-06-01 23:10:08 +0000 (Sat, 01 Jun 2013) Log Message: ----------- [Ref] Add a simple int24 type to typedefs.h. Useful for reading or writing 24bit integer audio data. [Ref] Optionally support non-interleaved output in CSoundFile::Read. [Fix] Fix openmpt::module::read when rendering some GB of audio data at once on 64bit architectures. [Fix] Avoid allocating memory in render path in openmpt::module::read by using the new non-interleaved output of CSoundFile::Read. Modified Paths: -------------- trunk/OpenMPT/common/typedefs.h trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp trunk/OpenMPT/soundlib/Fastmix.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/common/typedefs.h =================================================================== --- trunk/OpenMPT/common/typedefs.h 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/common/typedefs.h 2013-06-01 23:10:08 UTC (rev 2277) @@ -208,6 +208,33 @@ #endif +struct int24 +{ + uint8 bytes[3]; + int24() { bytes[0] = bytes[1] = bytes[2] = 0; } + explicit int24(int other) + { + #ifdef PLATFORM_BIG_ENDIAN + bytes[0] = ((unsigned int)other>>16)&0xff; + bytes[1] = ((unsigned int)other>> 8)&0xff; + bytes[2] = ((unsigned int)other>> 0)&0xff; + #else + bytes[0] = ((unsigned int)other>> 0)&0xff; + bytes[1] = ((unsigned int)other>> 8)&0xff; + bytes[2] = ((unsigned int)other>>16)&0xff; + #endif + } + operator int() const + { + #ifdef PLATFORM_BIG_ENDIAN + return ((int8)bytes[0] * 65536) + (bytes[1] * 256) + bytes[2]; + #else + return ((int8)bytes[2] * 65536) + (bytes[1] * 256) + bytes[0]; + #endif + } +}; +STATIC_ASSERT(sizeof(int24) == 3); + typedef float float32; STATIC_ASSERT(sizeof(float32) == 4); Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-01 23:10:08 UTC (rev 2277) @@ -141,8 +141,6 @@ set_render_param( module::RENDER_QUALITY_PERCENT, 100 ); } void module_impl::init() { - m_int16Buffer.resize( 4096 * 4 ); - m_floatBuffer.resize( 4096 * 4 ); m_sndFile = std::unique_ptr<CSoundFile>(new CSoundFile()); m_LogForwarder = std::unique_ptr<log_forwarder>(new log_forwarder(m_Log)); m_sndFile->SetCustomLog( m_LogForwarder.get() ); @@ -164,10 +162,15 @@ m_loaderMessages.push_back( LogLevelToString( i->first ) + std::string(": ") + i->second ); } } -std::size_t module_impl::read_wrapper( void * buffer, std::size_t count ) { +std::size_t module_impl::read_wrapper( std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ) { std::size_t count_read = 0; while ( count > 0 ) { - std::size_t count_chunk = m_sndFile->Read( buffer, static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ) ); // safety margin / samplesize / channels + std::int16_t * const buffers[4] = { left + count_read, right + count_read, rear_left + count_read, rear_right + count_read }; + std::size_t count_chunk = m_sndFile->Read( + 0, + static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ), // safety margin / samplesize / channels + reinterpret_cast<void*const*>( buffers ) + ); if ( count_chunk == 0 ) { break; } @@ -176,6 +179,23 @@ } return count_read; } +std::size_t module_impl::read_wrapper( std::size_t count, float * left, float * right, float * rear_left, float * rear_right ) { + std::size_t count_read = 0; + while ( count > 0 ) { + float * const buffers[4] = { left + count_read, right + count_read, rear_left + count_read, rear_right + count_read }; + std::size_t count_chunk = m_sndFile->Read( + 0, + static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ), // safety margin / samplesize / channels + reinterpret_cast<void*const*>( buffers ) + ); + if ( count_chunk == 0 ) { + break; + } + count -= count_chunk; + count_read += count_chunk; + } + return count_read; +} std::vector<std::string> module_impl::get_supported_extensions() { std::vector<std::string> retval; @@ -382,11 +402,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 1, false ); - m_int16Buffer.resize( count * 1 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - mono[i] = m_int16Buffer[i*1]; - } + count = read_wrapper( count, mono, 0, 0, 0 ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } @@ -395,12 +411,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 2, false ); - m_int16Buffer.resize( count * 2 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_int16Buffer[i*2+0]; - right[i] = m_int16Buffer[i*2+1]; - } + count = read_wrapper( count, left, right, 0, 0 ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } @@ -409,14 +420,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 4, false ); - m_int16Buffer.resize( count * 4 ); - count = read_wrapper( &m_int16Buffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_int16Buffer[i*4+0]; - right[i] = m_int16Buffer[i*4+1]; - rear_left[i] = m_int16Buffer[i*4+2]; - rear_right[i] = m_int16Buffer[i*4+3]; - } + count = read_wrapper( count, left, right, rear_left, rear_right ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } @@ -425,11 +429,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 1, true ); - m_floatBuffer.resize( count * 1 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - mono[i] = m_floatBuffer[i*1]; - } + count = read_wrapper( count, mono, 0, 0, 0 ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } @@ -438,12 +438,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 2, true ); - m_floatBuffer.resize( count * 2 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_floatBuffer[i*2+0]; - right[i] = m_floatBuffer[i*2+1]; - } + count = read_wrapper( count, left, right, 0, 0 ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } @@ -452,14 +447,7 @@ throw openmpt::exception_message("null pointer"); } apply_mixer_settings( samplerate, 4, true ); - m_floatBuffer.resize( count * 4 ); - count = read_wrapper( &m_floatBuffer[0], count ); - for ( std::size_t i = 0; i < count; ++i ) { - left[i] = m_floatBuffer[i*4+0]; - right[i] = m_floatBuffer[i*4+1]; - rear_left[i] = m_floatBuffer[i*4+2]; - rear_right[i] = m_floatBuffer[i*4+3]; - } + count = read_wrapper( count, left, right, rear_left, rear_right ); m_currentPositionSeconds += static_cast<double>( count ) / static_cast<double>( samplerate ); return count; } Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.hpp 2013-06-01 23:10:08 UTC (rev 2277) @@ -65,8 +65,6 @@ protected: std::shared_ptr<log_interface> m_Log; std::unique_ptr<log_forwarder> m_LogForwarder; - std::vector<std::int16_t> m_int16Buffer; - std::vector<float> m_floatBuffer; double m_currentPositionSeconds; std::unique_ptr<CSoundFile> m_sndFile; std::vector<std::string> m_loaderMessages; @@ -81,7 +79,8 @@ void init(); static void load( CSoundFile & sndFile, const FileReader & file ); void load( const FileReader & file ); - std::size_t read_wrapper( void * buffer, std::size_t count ); + std::size_t read_wrapper( std::size_t count, std::int16_t * left, std::int16_t * right, std::int16_t * rear_left, std::int16_t * rear_right ); + std::size_t read_wrapper( std::size_t count, float * left, float * right, float * rear_left, float * rear_right ); public: static std::vector<std::string> get_supported_extensions(); static bool is_extension_supported( const std::string & extension ); Modified: trunk/OpenMPT/soundlib/Fastmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-01 23:10:08 UTC (rev 2277) @@ -1796,7 +1796,23 @@ #endif } +void Convert32ToNonInterleaved(uint8 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count) +//-------------------------------------------------------------------------------------------------------------------------- +{ + for(std::size_t i = 0; i < count; ++i) + { + for(std::size_t channel = 0; channel < channels; ++channel) + { + int v = *mixbuffer; + if(v < MIXING_CLIPMIN) v = MIXING_CLIPMIN; + else if(v > MIXING_CLIPMAX) v = MIXING_CLIPMAX; + buffers[channel][i] = (uint8)((v >> (24-MIXING_ATTENUATION))+0x80); // unsigned + mixbuffer++; + } + } +} + #ifdef ENABLE_X86 static DWORD X86_Convert32To16(LPVOID lp16, int *pBuffer, DWORD lSampleCount) //--------------------------------------------------------------------------- @@ -1861,7 +1877,20 @@ #endif } +void Convert32ToNonInterleaved(int16 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count) +//-------------------------------------------------------------------------------------------------------------------------- +{ + for(std::size_t i = 0; i < count; ++i) + { + for(std::size_t channel = 0; channel < channels; ++channel) + { + buffers[channel][i] = (int16)(Clamp(*mixbuffer, MIXING_CLIPMIN, MIXING_CLIPMAX) >> (16-MIXING_ATTENUATION)); + mixbuffer++; + } + } +} + #ifdef ENABLE_X86 static DWORD X86_Convert32To24(LPVOID lp16, int *pBuffer, DWORD lSampleCount) //--------------------------------------------------------------------------- @@ -1906,22 +1935,14 @@ static DWORD C_Convert32To24(LPVOID lp16, int *pBuffer, DWORD lSampleCount) //------------------------------------------------------------------------- { - uint8 * p = (uint8*)lp16; + int24 * p = (int24*)lp16; for(DWORD i=0; i<lSampleCount; i++) { int v = pBuffer[i]; if(v < MIXING_CLIPMIN) v = MIXING_CLIPMIN; else if(v > MIXING_CLIPMAX) v = MIXING_CLIPMAX; v >>= (8-MIXING_ATTENUATION); -#ifndef PLATFORM_BIG_ENDIAN - p[i*3+0] = ((unsigned)v>>0)&0xff; - p[i*3+1] = ((unsigned)v>>8)&0xff; - p[i*3+2] = ((unsigned)v>>16)&0xff; -#else - p[i*3+0] = ((unsigned)v>>16)&0xff; - p[i*3+1] = ((unsigned)v>>8)&0xff; - p[i*3+2] = ((unsigned)v>>0)&0xff; -#endif + p[i] = (int24)v; } return lSampleCount * 3; } @@ -1936,6 +1957,18 @@ #endif } +void Convert32ToNonInterleaved(int24 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count) +//-------------------------------------------------------------------------------------------------------------------------- +{ + for(std::size_t i = 0; i < count; ++i) + { + for(std::size_t channel = 0; channel < channels; ++channel) + { + buffers[channel][i] = (int24)(Clamp(*mixbuffer, MIXING_CLIPMIN, MIXING_CLIPMAX) >> (8-MIXING_ATTENUATION)); + mixbuffer++; + } + } +} #ifdef ENABLE_X86 @@ -2001,7 +2034,20 @@ #endif } +void Convert32ToNonInterleaved(int32 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count) +//-------------------------------------------------------------------------------------------------------------------------- +{ + for(std::size_t i = 0; i < count; ++i) + { + for(std::size_t channel = 0; channel < channels; ++channel) + { + buffers[channel][i] = (int32)(Clamp(*mixbuffer, MIXING_CLIPMIN, MIXING_CLIPMAX) << MIXING_ATTENUATION); + mixbuffer++; + } + } +} + // convert to 32 bit floats and do NOT clip to [-1,1] DWORD Convert32ToFloat32(LPVOID lpBuffer, int *pBuffer, DWORD lSampleCount) //------------------------------------------------------------------------- @@ -2015,7 +2061,21 @@ return lSampleCount * 4; } +void Convert32ToNonInterleaved(float * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count) +//-------------------------------------------------------------------------------------------------------------------------- +{ + const float factor = (1.0f/(float)MIXING_CLIPMAX); + for(std::size_t i = 0; i < count; ++i) + { + for(std::size_t channel = 0; channel < channels; ++channel) + { + buffers[channel][i] = *mixbuffer * factor; + mixbuffer++; + } + } +} + void InitMixBuffer(int *pBuffer, UINT nSamples) //--------------------------------------------- { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-01 23:10:08 UTC (rev 2277) @@ -590,7 +590,7 @@ void StopAllVsti(); //rewbs.VSTCompliance void RecalculateGainForAllPlugs(); void ResetChannels(); - UINT Read(LPVOID lpBuffer, UINT cbBuffer); + UINT Read(LPVOID lpBuffer, UINT cbBuffer, void * const *outputBuffers = nullptr); UINT CreateStereoMix(int count); BOOL FadeSong(UINT msec); BOOL GlobalFadeSong(UINT msec); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-01 22:34:49 UTC (rev 2276) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-01 23:10:08 UTC (rev 2277) @@ -40,6 +40,28 @@ extern DWORD Convert32To24(LPVOID lpBuffer, int *, DWORD nSamples); extern DWORD Convert32To32(LPVOID lpBuffer, int *, DWORD nSamples); extern DWORD Convert32ToFloat32(LPVOID lpBuffer, int *pBuffer, DWORD lSampleCount); + +extern void Convert32ToNonInterleaved(uint8 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count); +extern void Convert32ToNonInterleaved(int16 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count); +extern void Convert32ToNonInterleaved(int24 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count); +extern void Convert32ToNonInterleaved(int32 * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count); +extern void Convert32ToNonInterleaved(float * const * const buffers, const int *mixbuffer, std::size_t channels, std::size_t count); + +template<typename Tsample> +void Convert32ToNonInterleaved(void * const *outputBuffers, std::size_t offset, const int *mixbuffer, std::size_t channels, std::size_t count) +{ + Tsample *buffers[4]; + MemsetZero(buffers); + for(std::size_t channel = 0; channel < channels; ++channel) + { + buffers[channel] = reinterpret_cast<Tsample*>(outputBuffers[channel]); + buffers[channel] += offset; // skip to output position + } + Convert32ToNonInterleaved(buffers, mixbuffer, channels, count); +} + + + #ifdef ENABLE_X86 extern VOID X86_Dither(int *pBuffer, UINT nSamples, UINT nBits); #endif @@ -173,8 +195,8 @@ } -UINT CSoundFile::Read(LPVOID lpDestBuffer, UINT count) -//---------------------------------------------------- +UINT CSoundFile::Read(LPVOID lpDestBuffer, UINT count, void * const *outputBuffers) +//--------------------------------------------------------------------------------- { LPBYTE lpBuffer = (LPBYTE)lpDestBuffer; LPCONVERTPROC pCvt = nullptr; @@ -182,6 +204,7 @@ size_t lSampleSize; UINT nStat = 0; UINT nMaxPlugins; + std::size_t renderedCount = 0; nMaxPlugins = MAX_MIXPLUGINS; while ((nMaxPlugins > 0) && (!m_MixPlugins[nMaxPlugins-1].pMixPlugin)) nMaxPlugins--; @@ -200,7 +223,7 @@ lSampleSize *= m_MixerSettings.GetBitsPerSample()/8; lMax = count; - if ((!lMax) || (!lpBuffer) || (!m_nChannels)) return 0; + if((!lMax) || ((!lpBuffer) && (!outputBuffers)) || (!m_nChannels)) return 0; samplecount_t lRead = lMax; if(m_SongFlags[SONG_ENDREACHED]) goto MixDone; @@ -357,6 +380,8 @@ } #endif + if(lpBuffer) // old style interleaved output buffer + { #ifndef MODPLUG_TRACKER LPBYTE buf_beg = lpBuffer; #endif @@ -372,8 +397,34 @@ ApplyFinalOutputGainFloat(reinterpret_cast<float*>(buf_beg), reinterpret_cast<float*>(buf_end)); } #endif + } + if(outputBuffers) // non-interleaved one output buffer per channel + { + switch(m_MixerSettings.m_SampleFormat) + { + case SampleFormatUnsigned8: Convert32ToNonInterleaved<uint8>(outputBuffers, renderedCount, MixSoundBuffer, m_MixerSettings.gnChannels, lCount); break; + case SampleFormatInt16: Convert32ToNonInterleaved<int16>(outputBuffers, renderedCount, MixSoundBuffer, m_MixerSettings.gnChannels, lCount); break; + case SampleFormatInt24: Convert32ToNonInterleaved<int24>(outputBuffers, renderedCount, MixSoundBuffer, m_MixerSettings.gnChannels, lCount); break; + case SampleFormatInt32: Convert32ToNonInterleaved<int32>(outputBuffers, renderedCount, MixSoundBuffer, m_MixerSettings.gnChannels, lCount); break; + case SampleFormatFloat32: Convert32ToNonInterleaved<float>(outputBuffers, renderedCount, MixSoundBuffer, m_MixerSettings.gnChannels, lCount); break; + default: + break; + } + #ifndef MODPLUG_TRACKER + if(m_MixerSettings.IsFloatSampleFormat()) + { + // Apply final output gain for floating point output after conversion so we do not suffer underflow or clipping + for(std::size_t channel = 0; channel < m_MixerSettings.gnChannels; ++channel) + { + ApplyFinalOutputGainFloat(reinterpret_cast<float*>(outputBuffers[channel]) + renderedCount, reinterpret_cast<float*>(outputBuffers[channel]) + renderedCount + lCount); + } + } + #endif // !MODPLUG_TRACKER + } + // Buffer ready + renderedCount += lCount; lRead -= lCount; m_nBufferCount -= lCount; m_lTotalSampleCount += lCount; // increase sample count for VSTTimeInfo. @@ -381,7 +432,7 @@ MixDone: if (lRead) memset(lpBuffer, (m_MixerSettings.m_SampleFormat == SampleFormatUnsigned8) ? 0x80 : 0, lRead * lSampleSize); if (nStat) { m_nMixStat += nStat-1; m_nMixStat /= nStat; } - return lMax - lRead; + return renderedCount; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-01 23:38:39
|
Revision: 2278 http://sourceforge.net/p/modplug/code/2278 Author: manxorist Date: 2013-06-01 23:38:30 +0000 (Sat, 01 Jun 2013) Log Message: ----------- [Ref] Rename mpt_strnicmp to mpt::strnicmp. Modified Paths: -------------- trunk/OpenMPT/common/mptString.h trunk/OpenMPT/mptrack/Modedit.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/soundlib/Load_mid.cpp trunk/OpenMPT/soundlib/Load_stm.cpp trunk/OpenMPT/soundlib/Load_xm.cpp trunk/OpenMPT/soundlib/SampleFormats.cpp Modified: trunk/OpenMPT/common/mptString.h =================================================================== --- trunk/OpenMPT/common/mptString.h 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/common/mptString.h 2013-06-01 23:38:30 UTC (rev 2278) @@ -124,10 +124,7 @@ } -} // namespace mpt - - -static inline int mpt_strnicmp(const char *a, const char *b, size_t count) +static inline int strnicmp(const char *a, const char *b, size_t count) { #if MPT_COMPILER_MSVC return _strnicmp(a, b, count); @@ -137,6 +134,9 @@ } +} // namespace mpt + + #if MPT_COMPILER_MSVC #define snprintf _snprintf #endif Modified: trunk/OpenMPT/mptrack/Modedit.cpp =================================================================== --- trunk/OpenMPT/mptrack/Modedit.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/mptrack/Modedit.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -1014,7 +1014,7 @@ UINT susBegin = 0, susEnd = 0, loopBegin = 0, loopEnd = 0, bSus = 0, bLoop = 0, bCarry = 0, nPoints = 0, releaseNode = ENV_RELEASE_NODE_UNSET; DWORD dwMemSize = GlobalSize(hCpy), dwPos = strlen(pszEnvHdr); - if ((dwMemSize > dwPos) && (!mpt_strnicmp(p, pszEnvHdr, dwPos - 2))) + if ((dwMemSize > dwPos) && (!mpt::strnicmp(p, pszEnvHdr, dwPos - 2))) { sscanf(p + dwPos, pszEnvFmt, &nPoints, &susBegin, &susEnd, &loopBegin, &loopEnd, &bSus, &bLoop, &bCarry); while ((dwPos < dwMemSize) && (p[dwPos] != '\r') && (p[dwPos] != '\n')) dwPos++; Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -505,7 +505,7 @@ { b1 = true; } - if (!mpt_strnicmp(p->szLibraryName, mixPlugin.GetLibraryName(), 64)) + if (!mpt::strnicmp(p->szLibraryName, mixPlugin.GetLibraryName(), 64)) { b2 = true; } @@ -1634,7 +1634,7 @@ TrackerSettings::Instance().SetWorkingDirectory(files.workingDirectory.c_str(), DIR_PLUGINPRESETS, true); } - bool bank = !mpt_strnicmp(files.first_file.substr(files.first_file.length() - 3).c_str(), "fxb", 3); + bool bank = !mpt::strnicmp(files.first_file.substr(files.first_file.length() - 3).c_str(), "fxb", 3); std::fstream f; f.open(files.first_file.c_str(), std::ios::out | std::ios::trunc | std::ios::binary); Modified: trunk/OpenMPT/soundlib/Load_mid.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mid.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/soundlib/Load_mid.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -742,7 +742,7 @@ CHAR s[32]; memcpy(s, ptrk->ptracks, k); s[k] = 0; - if ((!mpt_strnicmp(s, "Copyri", 6)) || (!s[0])) break; + if ((!mpt::strnicmp(s, "Copyri", 6)) || (!s[0])) break; if (i == 0x03) { if (!m_szNames[0][0]) strcpy(m_szNames[0], s); Modified: trunk/OpenMPT/soundlib/Load_stm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_stm.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/soundlib/Load_stm.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -123,8 +123,8 @@ if(!file.Read(fileHeader) || fileHeader.filetype != 2 || fileHeader.dosEof != 0x1A - || (mpt_strnicmp(fileHeader.trackername, "!SCREAM!", 8) - && mpt_strnicmp(fileHeader.trackername, "BMOD2STM", 8))) + || (mpt::strnicmp(fileHeader.trackername, "!SCREAM!", 8) + && mpt::strnicmp(fileHeader.trackername, "BMOD2STM", 8))) { return false; } else if(loadFlags == onlyVerifyHeader) Modified: trunk/OpenMPT/soundlib/Load_xm.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_xm.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/soundlib/Load_xm.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -262,7 +262,7 @@ if(!file.ReadConvertEndianness(fileHeader) || fileHeader.channels == 0 || fileHeader.channels > MAX_BASECHANNELS - || mpt_strnicmp(fileHeader.signature, "Extended Module: ", 17) + || mpt::strnicmp(fileHeader.signature, "Extended Module: ", 17) || !file.CanRead(fileHeader.orders)) { return false; Modified: trunk/OpenMPT/soundlib/SampleFormats.cpp =================================================================== --- trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-06-01 23:10:08 UTC (rev 2277) +++ trunk/OpenMPT/soundlib/SampleFormats.cpp 2013-06-01 23:38:30 UTC (rev 2278) @@ -2072,7 +2072,7 @@ { const char *tag = reinterpret_cast<const char *>(metadata->data.vorbis_comment.comments[i].entry); const FLAC__uint32 length = metadata->data.vorbis_comment.comments[i].length; - if(length > 6 && !mpt_strnicmp(tag, "TITLE=", 6)) + if(length > 6 && !mpt::strnicmp(tag, "TITLE=", 6)) { mpt::String::Read<mpt::String::maybeNullTerminated>(client.sndFile.m_szNames[client.sample], tag + 6, length - 6); break; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-02 11:31:08
|
Revision: 2280 http://sourceforge.net/p/modplug/code/2280 Author: manxorist Date: 2013-06-02 11:30:59 +0000 (Sun, 02 Jun 2013) Log Message: ----------- [Ref] Split tracker-only-related misc functions from common/misc_util into mptrack/MPTrackUtil. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/Mptrack.h trunk/OpenMPT/mptrack/mptrack_08.vcproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/common/misc_util.cpp 2013-06-02 11:30:59 UTC (rev 2280) @@ -10,65 +10,3 @@ #include "stdafx.h" #include "misc_util.h" -#include <ctime> - -#ifdef MODPLUG_TRACKER - -/* - * Loads resource. - * [in] lpName and lpType: parameters passed to FindResource(). - * [out] pData: Pointer to loaded resource data, nullptr if load not successful. - * [out] nSize: Size of the data in bytes, zero if load not succesfull. - * [out] hglob: HGLOBAL returned by LoadResource-function. - * Return: pData. - */ -LPCCH LoadResource(LPCTSTR lpName, LPCTSTR lpType, LPCCH& pData, size_t& nSize, HGLOBAL& hglob) -//--------------------------------------------------------------------------------------------- -{ - pData = nullptr; - nSize = 0; - hglob = nullptr; - HINSTANCE hInstance = AfxGetInstanceHandle(); - HRSRC hrsrc = FindResource(hInstance, lpName, lpType); - if (hrsrc != NULL) - { - hglob = LoadResource(hInstance, hrsrc); - if (hglob != NULL) - { - pData = reinterpret_cast<const char*>(LockResource(hglob)); - nSize = SizeofResource(hInstance, hrsrc); - } - } - return pData; -} - - -// Returns WinAPI error message corresponding to error code returned by GetLastError(). -std::string GetErrorMessage(DWORD nErrorCode) -//------------------------------------------- -{ - LPVOID lpMsgBuf; - - FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, - NULL, - nErrorCode, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), - (LPTSTR)&lpMsgBuf, - 0, - NULL ); - - std::string msg = (LPTSTR)lpMsgBuf; - LocalFree(lpMsgBuf); - - return msg; -} -#endif // MODPLUG_TRACKER - - - -#ifdef MODPLUG_TRACKER -time_t Util::sdTime::MakeGmTime(tm& timeUtc) -{ - return _mkgmtime(&timeUtc); -} -#endif // MODPLUG_TRACKER Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/common/misc_util.h 2013-06-02 11:30:59 UTC (rev 2280) @@ -21,10 +21,6 @@ #include "typedefs.h" -#ifdef MODPLUG_TRACKER -#include <io.h> // for _taccess -#endif - #if defined(HAS_TYPE_TRAITS) #include <type_traits> #endif @@ -178,12 +174,6 @@ #endif -#ifdef MODPLUG_TRACKER -LPCCH LoadResource(LPCTSTR lpName, LPCTSTR lpType, LPCCH& pData, size_t& nSize, HGLOBAL& hglob); -std::string GetErrorMessage(DWORD nErrorCode); -#endif // MODPLUG_TRACKER - - static inline char SanitizeFilenameChar(char c) //--------------------------------------------- { @@ -220,7 +210,7 @@ str[i] = SanitizeFilenameChar(str[i]); } } -#ifdef MODPLUG_TRACKER +#ifdef _MFC_VER static inline void SanitizeFilename(CString &str) //----------------------------------------------- { @@ -371,23 +361,6 @@ }; -#ifdef MODPLUG_TRACKER -namespace Util { namespace sdTime -{ - - time_t MakeGmTime(tm& timeUtc); - -}}; // namespace Util::sdTime - -namespace Util { namespace sdOs -{ - /// Checks whether file or folder exists and whether it has the given mode. - enum FileMode {FileModeExists = 0, FileModeRead = 4, FileModeWrite = 2, FileModeReadWrite = 6}; - inline bool IsPathFileAvailable(LPCTSTR pszFilePath, FileMode fm) {return (_taccess(pszFilePath, fm) == 0);} - -} } // namespace Util::sdOs -#endif // MODPLUG_TRACKER - namespace Util { inline int32 muldiv(int32 a, int32 b, int32 c) Modified: trunk/OpenMPT/mptrack/Mptrack.h =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.h 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/mptrack/Mptrack.h 2013-06-02 11:30:59 UTC (rev 2280) @@ -13,6 +13,7 @@ #include "resource.h" // main symbols #include "ACMConvert.h" #include <windows.h> +#include "../mptrack/MpTrackUtil.h" #include "../mptrack/Reporting.h" #include "../soundlib/MIDIMacros.h" #include "../soundlib/modcommand.h" Modified: trunk/OpenMPT/mptrack/mptrack_08.vcproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/mptrack/mptrack_08.vcproj 2013-06-02 11:30:59 UTC (rev 2280) @@ -471,6 +471,10 @@ > </File> <File + RelativePath=".\MPTrackUtil.cpp" + > + </File> + <File RelativePath="..\common\mptString.cpp" > </File> @@ -1013,6 +1017,10 @@ > </File> <File + RelativePath=".\MPTrackUtil.h" + > + </File> + <File RelativePath="..\common\mptString.h" > </File> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj 2013-06-02 11:30:59 UTC (rev 2280) @@ -439,6 +439,7 @@ <ClCompile Include="Mpdlgs.cpp" /> <ClCompile Include="MPTHacks.cpp" /> <ClCompile Include="Mptrack.cpp" /> + <ClCompile Include="MPTrackUtil.cpp" /> <ClCompile Include="Mpt_midi.cpp" /> <ClCompile Include="PatternClipboard.cpp" /> <ClCompile Include="PatternEditorDialogs.cpp" /> @@ -613,6 +614,7 @@ <ClInclude Include="ModConvert.h" /> <ClInclude Include="Moddoc.h" /> <ClInclude Include="Mptrack.h" /> + <ClInclude Include="MPTrackUtil.h" /> <ClInclude Include="Notification.h" /> <ClInclude Include="PatternClipboard.h" /> <ClInclude Include="PatternCursor.h" /> Modified: trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters =================================================================== --- trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-06-02 11:25:38 UTC (rev 2279) +++ trunk/OpenMPT/mptrack/mptrack_10.vcxproj.filters 2013-06-02 11:30:59 UTC (rev 2280) @@ -511,6 +511,9 @@ <ClCompile Include="..\test\test.cpp"> <Filter>test</Filter> </ClCompile> + <ClCompile Include="MPTrackUtil.cpp"> + <Filter>Source Files\mptrack</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="..\soundlib\Loaders.h"> @@ -918,6 +921,9 @@ <ClInclude Include="..\test\test.h"> <Filter>test</Filter> </ClInclude> + <ClInclude Include="MPTrackUtil.h"> + <Filter>Header Files\mptrack</Filter> + </ClInclude> </ItemGroup> <ItemGroup> <None Include="res\bitmap1.bmp"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-02 12:04:06
|
Revision: 2286 http://sourceforge.net/p/modplug/code/2286 Author: manxorist Date: 2013-06-02 12:04:00 +0000 (Sun, 02 Jun 2013) Log Message: ----------- [New] Try building a shared library via unix makefile. [Imp] Add dependency tracking to unix makefile. [Imp] Make make output more readable by default. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt_config.h trunk/OpenMPT/openmpt123/Makefile Property Changed: ---------------- trunk/OpenMPT/common/ trunk/OpenMPT/libopenmpt/ trunk/OpenMPT/openmpt123/ trunk/OpenMPT/soundlib/ trunk/OpenMPT/test/ Index: trunk/OpenMPT/common =================================================================== --- trunk/OpenMPT/common 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/common 2013-06-02 12:04:00 UTC (rev 2286) Property changes on: trunk/OpenMPT/common ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +*.d Index: trunk/OpenMPT/libopenmpt =================================================================== --- trunk/OpenMPT/libopenmpt 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/libopenmpt 2013-06-02 12:04:00 UTC (rev 2286) Property changes on: trunk/OpenMPT/libopenmpt ___________________________________________________________________ Modified: svn:ignore ## -15,3 +15,4 ## libopenmpt_foobar2000.opensdf libopenmpt_foobar2000.suo x64 +*.d Modified: trunk/OpenMPT/libopenmpt/libopenmpt_config.h =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_config.h 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/libopenmpt/libopenmpt_config.h 2013-06-02 12:04:00 UTC (rev 2286) @@ -15,7 +15,7 @@ #define LIBOPENMPT_DLL_HELPER_EXPORT __declspec(dllexport) #define LIBOPENMPT_DLL_HELPER_IMPORT __declspec(dllimport) #define LIBOPENMPT_DLL_HELPER_LOCAL -#elif defined(__GNUC__) +#elif defined(__GNUC__) || defined(__clang__) #define LIBOPENMPT_DLL_HELPER_EXPORT __attribute__((visibility("default"))) #define LIBOPENMPT_DLL_HELPER_IMPORT __attribute__((visibility("default"))) #define LIBOPENMPT_DLL_HELPER_LOCAL __attribute__((visibility("hidden"))) Index: trunk/OpenMPT/openmpt123 =================================================================== --- trunk/OpenMPT/openmpt123 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/openmpt123 2013-06-02 12:04:00 UTC (rev 2286) Property changes on: trunk/OpenMPT/openmpt123 ___________________________________________________________________ Modified: svn:ignore ## -8,3 +8,4 ## ipch DebugStatic x64 +*.d Modified: trunk/OpenMPT/openmpt123/Makefile =================================================================== --- trunk/OpenMPT/openmpt123/Makefile 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/openmpt123/Makefile 2013-06-02 12:04:00 UTC (rev 2286) @@ -1,50 +1,104 @@ -CC = $(SILENT)gcc -CXX = $(SILENT)g++ -LD = $(SILENT)g++ +INFO = @echo +SILENT = @ +VERYSILENT = @ + +ifeq ($(VERBOSE),2) +INFO = @true +SILENT = +VERYSILENT = +endif + +ifeq ($(VERBOSE),1) +INFO = @true +SILENT = +VERYSILENT = @ +endif + + +ifeq ($(QUIET),1) +INFO = @true +SILENT = @ +VERYSILENT = @ +endif + + +CC = gcc +CXX = g++ +LD = g++ +AR = ar + +DYNLINK = 1 + + CPPFLAGS = -I../common -I.. -CXXFLAGS = -std=gnu++0x -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align -CFLAGS = -std=gnu99 -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align +CXXFLAGS = -std=c++0x -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align +CFLAGS = -std=c99 -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align LDFLAGS = LDLIBS = -lm +ARFLAGS = rcs +ifeq ($(DYNLINK),1) +LDFLAGS += -Wl,-rpath,./bin -Wl,-rpath,../bin +endif + CXXFLAGS += -mtune=generic CFLAGS += -mtune=generic -#CPPFLAGS += $(shell pkg-config --cflags-only-I zlib ) -#LDFLAGS += $(shell pkg-config --libs-only-other zlib ) -#LDFLAGS += $(shell pkg-config --libs-only-L zlib ) -#LDLIBS += $(shell pkg-config --libs-only-l zlib ) -LDLIBS += -lz +CPPFLAGS += $(shell pkg-config --cflags-only-I zlib ) +LDFLAGS += $(shell pkg-config --libs-only-other zlib ) +LDFLAGS += $(shell pkg-config --libs-only-L zlib ) +LDLIBS += $(shell pkg-config --libs-only-l zlib ) +#LDLIBS += -lz CPPFLAGS += $(shell pkg-config --cflags-only-I portaudio-2.0 ) LDFLAGS += $(shell pkg-config --libs-only-other portaudio-2.0 ) LDFLAGS += $(shell pkg-config --libs-only-L portaudio-2.0 ) LDLIBS += $(shell pkg-config --libs-only-l portaudio-2.0 ) +#LDLIBS += -lportaudio %: %.o - $(LD) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@ %.o: %.CPP - $(COMPILE.cc) $(OUTPUT_OPTION) $< + $(INFO) [CXX] $< + $(VERYSILENT)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M -MT$@ $< > $*.d + $(SILENT)@$(COMPILE.cc) $(OUTPUT_OPTION) $< +%.o: %.cpp + $(INFO) [CXX] $< + $(VERYSILENT)$(CXX) $(CXXFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M -MT$@ $< > $*.d + $(SILENT)$(COMPILE.cc) $(OUTPUT_OPTION) $< +%.o: %.c + $(INFO) [CC ] $< + $(VERYSILENT)$(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -M -MT$@ $< > $*.d + $(SILENT)$(COMPILE.c) $(OUTPUT_OPTION) $< + + BUILD_SVNVERSION = $(shell svnversion -n .. ) CPPFLAGS += -I../common/svn_version_svnversion -D BUILD_SVNVERSION=\"$(BUILD_SVNVERSION)\" #CPPFLAGS += -I../common/svn_version_default -COMMON_SOURCES += \ +CPPFLAGS += -DLIBOPENMPT_BUILD -DLIBOPENMPT_BUILD_DLL + + +COMMON_CXX_SOURCES += \ $(wildcard ../common/*.cpp) \ -SOUNDLIB_SOURCES += \ - $(COMMON_SOURCES) \ +SOUNDLIB_CXX_SOURCES += \ + $(COMMON_CXX_SOURCES) \ $(wildcard ../soundlib/*.cpp) \ - $(wildcard ../soundlib/*.CPP) \ + +SOUNDLIB_CXX_SOURCES_UPPERCASE += $(wildcard ../soundlib/*.CPP) +SOUNDLIB_CXX_SOURCES += $(SOUNDLIB_CXX_SOURCES_UPPERCASE:.CPP=.cpp) -LIBOPENMPT_SOURCES += \ - $(SOUNDLIB_SOURCES) \ + +LIBOPENMPT_CXX_SOURCES += \ + $(SOUNDLIB_CXX_SOURCES) \ $(wildcard ../test/*.cpp) \ ../libopenmpt/libopenmpt.cpp \ ../libopenmpt/libopenmpt_c.cpp \ @@ -53,27 +107,78 @@ ../libopenmpt/libopenmpt_interactive.cpp \ ../libopenmpt/libopenmpt_version.cpp \ -OPENMPT123_SOURCES += \ - $(LIBOPENMPT_SOURCES) \ +LIBOPENMPT_OBJECTS = $(LIBOPENMPT_CXX_SOURCES:.cpp=.o) +LIBOPENMPT_DEPENDS = $(LIBOPENMPT_OBJECTS:.o=.d) +ALL_OBJECTS += $(LIBOPENMPT_OBJECTS) +ALL_DEPENDS += $(LIBOPENMPT_DEPENDS) + + +LIBOPENMPT_MODPLUG_C_SOURCES += \ + ../libopenmpt/libopenmpt_modplug.c \ + +LIBOPENMPT_MODPLUG_OBJECTS = $(LIBOPENMPT_MODPLUG_C_SOURCES:.c=.o) +LIBOPENMPT_MODPLUG_DEPENDS = $(LIBOPENMPT_MODPLUG_OBJECTS:.o=.d) +ALL_OBJECTS += $(LIBOPENMPT_MODPLUG_OBJECTS) +ALL_DEPENDS += $(LIBOPENMPT_MODPLUG_DEPENDS) + + +ifeq ($(DYNLINK),1) +OPENMPT123_CXX_SOURCES += \ $(wildcard ../openmpt123/*.cpp) \ +else +OPENMPT123_CXX_SOURCES += \ + $(LIBOPENMPT_CXX_SOURCES) \ + $(wildcard ../openmpt123/*.cpp) \ -CPPFLAGS += -DLIBOPENMPT_BUILD +endif -OPENMPT123_OBJECTS1 = $(OPENMPT123_SOURCES) -OPENMPT123_OBJECTS2 = $(OPENMPT123_OBJECTS1:.cpp=.o) -OPENMPT123_OBJECTS3 = $(OPENMPT123_OBJECTS2:.CPP=.o) -OPENMPT123_OBJECTS = $(OPENMPT123_OBJECTS3) +OPENMPT123_OBJECTS += $(OPENMPT123_CXX_SOURCES:.cpp=.o) +OPENMPT123_DEPENDS = $(OPENMPT123_OBJECTS:.o=.d) +ALL_OBJECTS += $(OPENMPT123_OBJECTS) +ALL_DEPENDS += $(OPENMPT123_DEPENDS) + .PHONY: all -all: bin/openmpt123 bin/modplug123 +all: +-include $(ALL_DEPENDS) + +OUTPUTS = bin/openmpt123 bin/modplug123 bin/libopenmpt.so bin/openmpt.a +#OUTPUTS += lib/libopenmpt_modplug.so +all: $(OUTPUTS) + +bin/libopenmpt.so: $(LIBOPENMPT_OBJECTS) + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@ + +ifeq ($(DYNLINK),1) +bin/libopenmpt_modplug.so: $(LIBOPENMPT_MODPLUG_OBJECTS) + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) -shared -Lbin $^ $(LOADLIBES) $(LDLIBS) -o $@ +else +bin/libopenmpt_modplug.so: $(LIBOPENMPT_OBJECTS) $(LIBOPENMPT_MODPLUG_OBJECTS) + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) -shared $^ $(LOADLIBES) $(LDLIBS) -o $@ +endif + +bin/openmpt.a: $(LIBOPENMPT_OBJECTS) + $(INFO) [AR ] $@ + $(SILENT)$(AR) $(ARFLAGS) $@ $^ + +ifeq ($(DYNLINK),1) +bin/openmpt123: $(OPENMPT123_OBJECTS) bin/libopenmpt.so + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) -Lbin $(OPENMPT123_OBJECTS) $(LOADLIBES) $(LDLIBS) -lopenmpt -o $@ +else bin/openmpt123: $(OPENMPT123_OBJECTS) - $(LD) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ + $(INFO) [LD ] $@ + $(SILENT)$(LINK.cc) $(OPENMPT123_OBJECTS) $(LOADLIBES) $(LDLIBS) -o $@ +endif bin/modplug123: bin/openmpt123 cp $^ $@ clean: - rm -f bin/openmpt123 bin/modplug123 $(OPENMPT123_OBJECTS) + rm -f $(OUTPUTS) $(ALL_OBJECTS) $(ALL_DEPENDS) Index: trunk/OpenMPT/soundlib =================================================================== --- trunk/OpenMPT/soundlib 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/soundlib 2013-06-02 12:04:00 UTC (rev 2286) Property changes on: trunk/OpenMPT/soundlib ___________________________________________________________________ Added: svn:ignore ## -0,0 +1 ## +*.d Index: trunk/OpenMPT/test =================================================================== --- trunk/OpenMPT/test 2013-06-02 11:51:50 UTC (rev 2285) +++ trunk/OpenMPT/test 2013-06-02 12:04:00 UTC (rev 2286) Property changes on: trunk/OpenMPT/test ___________________________________________________________________ Modified: svn:ignore ## -1,3 +1,4 ## test.saved.mptm test.saved.s3m test.saved.xm +*.d This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-02 12:09:12
|
Revision: 2287 http://sourceforge.net/p/modplug/code/2287 Author: manxorist Date: 2013-06-02 12:09:05 +0000 (Sun, 02 Jun 2013) Log Message: ----------- [Ref] Remove empty semicolons after closing namespace scope. [Ref] Remove comma at the end of enum members list in common/ (makes common/ gcc -pedantic clean). [Ref] sscanf %x expects pointer to unsigned int instead of int. Modified Paths: -------------- trunk/OpenMPT/common/Logging.h trunk/OpenMPT/common/StringFixer.h trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/common/serialization_utils.h trunk/OpenMPT/common/version.cpp trunk/OpenMPT/common/version.h trunk/OpenMPT/soundlib/MIDIEvents.h trunk/OpenMPT/soundlib/ModInstrument.cpp trunk/OpenMPT/soundlib/modsmp_ctrl.cpp trunk/OpenMPT/soundlib/tuning.cpp trunk/OpenMPT/soundlib/tuningbase.h trunk/OpenMPT/soundlib/tuningcollection.h Modified: trunk/OpenMPT/common/Logging.h =================================================================== --- trunk/OpenMPT/common/Logging.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/Logging.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -16,7 +16,7 @@ LogNotification = 2, LogInformation = 3, LogWarning = 4, - LogError = 5, + LogError = 5 }; Modified: trunk/OpenMPT/common/StringFixer.h =================================================================== --- trunk/OpenMPT/common/StringFixer.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/StringFixer.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -84,7 +84,7 @@ spacePadded, // Reading: String may contain null characters anywhere. The last character is ignored (it is supposed to be 0). // Writing: A space-padded string with a trailing null is written. - spacePaddedNull, + spacePaddedNull }; Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/misc_util.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -359,7 +359,7 @@ return intval; } -}; +} namespace Util { Modified: trunk/OpenMPT/common/serialization_utils.h =================================================================== --- trunk/OpenMPT/common/serialization_utils.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/serialization_utils.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -76,7 +76,7 @@ SNW_DATASIZETYPE_OVERFLOW = (0x13) | SNT_FAILURE, SNW_MAX_WRITE_COUNT_REACHED = (0x14) | SNT_FAILURE, SNW_SUBENTRY_FAILURE = (0x15) | SNT_FAILURE, - SNW_INSUFFICIENT_DATASIZETYPE = (0x16) | SNT_FAILURE, + SNW_INSUFFICIENT_DATASIZETYPE = (0x16) | SNT_FAILURE }; bool IsPrintableId(const void* pvId, const size_t nLength); // Return true if given id is printable, false otherwise. Modified: trunk/OpenMPT/common/version.cpp =================================================================== --- trunk/OpenMPT/common/version.cpp 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/version.cpp 2013-06-02 12:09:05 UTC (rev 2287) @@ -90,7 +90,7 @@ VersionNum ToNum(const std::string &s_) { const char *s = s_.c_str(); - int v1, v2, v3, v4; + unsigned int v1, v2, v3, v4; sscanf(s, "%x.%x.%x.%x", &v1, &v2, &v3, &v4); return ((v1 << 24) | (v2 << 16) | (v3 << 8) | v4); } Modified: trunk/OpenMPT/common/version.h =================================================================== --- trunk/OpenMPT/common/version.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/common/version.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -84,4 +84,4 @@ // Returns a multi-line string containing developer contact and community addresses std::string GetContactString(); -}; //namespace MptVersion +} //namespace MptVersion Modified: trunk/OpenMPT/soundlib/MIDIEvents.h =================================================================== --- trunk/OpenMPT/soundlib/MIDIEvents.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/MIDIEvents.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -286,4 +286,4 @@ // Get second data byte from a MIDI event uint8 GetDataByte2FromEvent(uint32 midiMsg); -}; +} Modified: trunk/OpenMPT/soundlib/ModInstrument.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModInstrument.cpp 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/ModInstrument.cpp 2013-06-02 12:09:05 UTC (rev 2287) @@ -70,7 +70,7 @@ } } } -}; +} // Get envelope value at a given tick. Returns value in range [0.0, 1.0]. @@ -117,7 +117,7 @@ } return Clamp(value, 0.0f, 1.0f); -}; +} ModInstrument::ModInstrument(SAMPLEINDEX sample) Modified: trunk/OpenMPT/soundlib/modsmp_ctrl.cpp =================================================================== --- trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/modsmp_ctrl.cpp 2013-06-02 12:09:05 UTC (rev 2287) @@ -348,7 +348,7 @@ *p = static_cast<T>(dVal); } } -}; +} // Remove DC offset Modified: trunk/OpenMPT/soundlib/tuning.cpp =================================================================== --- trunk/OpenMPT/soundlib/tuning.cpp 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/tuning.cpp 2013-06-02 12:09:05 UTC (rev 2287) @@ -43,7 +43,7 @@ uint16 m_nWriteCount; static const uint16 s_nDefaultWriteCount = (uint16_max >> 2); }; -}; +} using namespace CTuningS11n; Modified: trunk/OpenMPT/soundlib/tuningbase.h =================================================================== --- trunk/OpenMPT/soundlib/tuningbase.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/tuningbase.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -35,7 +35,7 @@ using std::ostream; using std::map; -namespace srlztn {class Ssb;}; +namespace srlztn {class Ssb;} #ifdef BUILD_TUNINGBASE_AS_TEMPLATE Modified: trunk/OpenMPT/soundlib/tuningcollection.h =================================================================== --- trunk/OpenMPT/soundlib/tuningcollection.h 2013-06-02 12:04:00 UTC (rev 2286) +++ trunk/OpenMPT/soundlib/tuningcollection.h 2013-06-02 12:09:05 UTC (rev 2287) @@ -19,7 +19,7 @@ namespace CTuningS11n { void ReadTuning(istream& iStrm, CTuningCollection& Tc, const size_t); -}; +} //===================== This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-02 12:44:15
|
Revision: 2289 http://sourceforge.net/p/modplug/code/2289 Author: manxorist Date: 2013-06-02 12:44:08 +0000 (Sun, 02 Jun 2013) Log Message: ----------- [Ref] Rename mptrack/res/built-inTunings.tc to soundlib/Tunings/built-inTunings.tc. [Ref] Add a conversion to header file for built-inTunings.tc. [New] Support builtin tunings in libopenmpt. Modified Paths: -------------- trunk/OpenMPT/mptrack/mptrack.rc trunk/OpenMPT/soundlib/Load_it.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Added Paths: ----------- trunk/OpenMPT/soundlib/Tunings/ trunk/OpenMPT/soundlib/Tunings/built-inTunings.h trunk/OpenMPT/soundlib/Tunings/built-inTunings.tc Removed Paths: ------------- trunk/OpenMPT/mptrack/res/built-inTunings.tc Modified: trunk/OpenMPT/mptrack/mptrack.rc =================================================================== --- trunk/OpenMPT/mptrack/mptrack.rc 2013-06-02 12:27:48 UTC (rev 2288) +++ trunk/OpenMPT/mptrack/mptrack.rc 2013-06-02 12:44:08 UTC (rev 2289) @@ -2839,7 +2839,7 @@ // TUNING // -IDR_BUILTIN_TUNINGS TUNING "res\\built-inTunings.tc" +IDR_BUILTIN_TUNINGS TUNING "..\\soundlib\\Tunings\\built-inTunings.tc" #endif // English (United Kingdom) resources ///////////////////////////////////////////////////////////////////////////// Deleted: trunk/OpenMPT/mptrack/res/built-inTunings.tc =================================================================== (Binary files differ) Modified: trunk/OpenMPT/soundlib/Load_it.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-02 12:27:48 UTC (rev 2288) +++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-02 12:44:08 UTC (rev 2289) @@ -189,6 +189,7 @@ csf.Instruments[i]->pTuning = csf.GetLocalTunings().GetTuning(str); if(csf.Instruments[i]->pTuning) continue; +#endif csf.Instruments[i]->pTuning = csf.GetBuiltInTunings().GetTuning(str); if(csf.Instruments[i]->pTuning) @@ -196,7 +197,6 @@ if(str == "TET12" && csf.GetBuiltInTunings().GetNumTunings() > 0) csf.Instruments[i]->pTuning = &csf.GetBuiltInTunings().GetTuning(0); -#endif if(csf.Instruments[i]->pTuning) continue; Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-02 12:27:48 UTC (rev 2288) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-02 12:44:08 UTC (rev 2289) @@ -529,6 +529,10 @@ m_lTotalSampleCount = 0; m_bPositionChanged = true; +#ifndef MODPLUG_TRACKER + m_pTuningsBuiltIn = new CTuningCollection(); + LoadBuiltInTunings(); +#endif m_pTuningsTuneSpecific = new CTuningCollection("Tune specific tunings"); } @@ -536,8 +540,13 @@ CSoundFile::~CSoundFile() //----------------------- { + Destroy(); delete m_pTuningsTuneSpecific; - Destroy(); + m_pTuningsTuneSpecific = nullptr; +#ifndef MODPLUG_TRACKER + delete m_pTuningsBuiltIn; + m_pTuningsBuiltIn = nullptr; +#endif } @@ -1664,6 +1673,15 @@ return false; } +#else +#include "Tunings/built-inTunings.h" +void CSoundFile::LoadBuiltInTunings() +//----------------------------------- +{ + std::string data(built_inTunings_tc_data, built_inTunings_tc_data + built_inTunings_tc_size); + std::istringstream iStrm(data); + m_pTuningsBuiltIn->Deserialize(iStrm); +} #endif Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-02 12:27:48 UTC (rev 2288) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-02 12:44:08 UTC (rev 2289) @@ -247,6 +247,9 @@ static void DeleteStaticdata(); static CTuningCollection& GetBuiltInTunings() {return *s_pTuningsSharedBuiltIn;} static CTuningCollection& GetLocalTunings() {return *s_pTuningsSharedLocal;} +#else + void LoadBuiltInTunings(); + CTuningCollection& GetBuiltInTunings() {return *m_pTuningsBuiltIn;} #endif static CTuning *GetDefaultTuning() {return nullptr;} CTuningCollection& GetTuneSpecificTunings() {return *m_pTuningsTuneSpecific;} @@ -257,6 +260,8 @@ #ifdef MODPLUG_TRACKER static CTuningCollection* s_pTuningsSharedBuiltIn; static CTuningCollection* s_pTuningsSharedLocal; +#else + CTuningCollection* m_pTuningsBuiltIn; #endif //<--Tuning Index: trunk/OpenMPT/soundlib/Tunings =================================================================== --- trunk/OpenMPT/soundlib/Tunings 2013-06-02 12:27:48 UTC (rev 2288) +++ trunk/OpenMPT/soundlib/Tunings 2013-06-02 12:44:08 UTC (rev 2289) Property changes on: trunk/OpenMPT/soundlib/Tunings ___________________________________________________________________ Added: tsvn:logminsize ## -0,0 +1 ## +10 \ No newline at end of property Added: trunk/OpenMPT/soundlib/Tunings/built-inTunings.h =================================================================== --- trunk/OpenMPT/soundlib/Tunings/built-inTunings.h (rev 0) +++ trunk/OpenMPT/soundlib/Tunings/built-inTunings.h 2013-06-02 12:44:08 UTC (rev 2289) @@ -0,0 +1,28 @@ +//file auto-generated from built-inTunings.tc by bin2h.exe +static const size_t built_inTunings_tc_size = 244; +static const unsigned char built_inTunings_tc_data[244]= +{ + 0x32,0x32,0x38,0x02,0x54,0x43,0x1F,0x08,0x00,0x01,0x0C, + 0x01,0x0D,0x00,0x9F,0x03,0x00,0x00,0x00,0x00,0x00,0x00, + 0x40,0x42,0x75,0x69,0x6C,0x74,0x2D,0x69,0x6E,0x20,0x74, + 0x75,0x6E,0x69,0x6E,0x67,0x73,0xFF,0xFF,0x32,0x32,0x38, + 0x09,0x43,0x54,0x42,0x32,0x34,0x34,0x52,0x54,0x49,0x1F, + 0x08,0x00,0x01,0x12,0x00,0x00,0x10,0x01,0x25,0x00,0x27, + 0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x64,0x31,0x32,0x54, + 0x45,0x54,0x20,0x5B,0x5B,0x66,0x73,0x31,0x35,0x20,0x31, + 0x2E,0x31,0x37,0x2E,0x30,0x32,0x2E,0x34,0x39,0x5D,0x5D, + 0x00,0x00,0x03,0x00,0x30,0x00,0x00,0x02,0x43,0x2D,0x01, + 0x00,0x02,0x43,0x23,0x02,0x00,0x02,0x44,0x2D,0x03,0x00, + 0x02,0x44,0x23,0x04,0x00,0x02,0x45,0x2D,0x05,0x00,0x02, + 0x46,0x2D,0x06,0x00,0x02,0x46,0x23,0x07,0x00,0x02,0x47, + 0x2D,0x08,0x00,0x02,0x47,0x23,0x09,0x00,0x02,0x41,0x2D, + 0x0A,0x00,0x02,0x41,0x23,0x0B,0x00,0x02,0x42,0x2D,0x0F, + 0x00,0x00,0x00,0x00,0x00,0x00,0x40,0x0C,0x00,0x80,0x00, + 0xC0,0xFF,0x02,0x30,0x80,0x68,0x02,0x31,0xE8,0x08,0x02, + 0x32,0xF0,0x08,0x02,0x33,0xF8,0xF4,0x02,0x34,0xED,0x01, + 0x10,0x08,0x52,0x54,0x49,0x33,0xFD,0x01,0x10,0x08,0x52, + 0x54,0x49,0x32,0x0D,0x02,0x08,0x08,0x52,0x54,0x49,0x34, + 0x15,0x02,0x08,0x08,0x52,0x54,0x49,0x31,0x1D,0x02,0x08, + 0x02,0x30,0x58,0x44,0x02,0x31,0x9C,0x08,0x02,0x32,0xA4, + 0xF9,0x02 +}; Property changes on: trunk/OpenMPT/soundlib/Tunings/built-inTunings.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Copied: trunk/OpenMPT/soundlib/Tunings/built-inTunings.tc (from rev 2277, trunk/OpenMPT/mptrack/res/built-inTunings.tc) =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-03 16:12:03
|
Revision: 2292 http://sourceforge.net/p/modplug/code/2292 Author: manxorist Date: 2013-06-03 16:11:55 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Fix] Always build libmodplug emulation layer against our own copy of the modplug headers instead of accidentally catching up system-wide headers. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj trunk/OpenMPT/openmpt123/Makefile Added Paths: ----------- trunk/OpenMPT/include/modplug/ trunk/OpenMPT/include/modplug/include/ trunk/OpenMPT/include/modplug/include/libmodplug/ Removed Paths: ------------- trunk/OpenMPT/include/libmodplug/ Index: trunk/OpenMPT/include/modplug =================================================================== --- trunk/OpenMPT/include/modplug 2013-06-03 13:59:03 UTC (rev 2291) +++ trunk/OpenMPT/include/modplug 2013-06-03 16:11:55 UTC (rev 2292) Property changes on: trunk/OpenMPT/include/modplug ___________________________________________________________________ Added: tsvn:logminsize ## -0,0 +1 ## +10 \ No newline at end of property Index: trunk/OpenMPT/include/modplug/include =================================================================== --- trunk/OpenMPT/include/modplug/include 2013-06-03 13:59:03 UTC (rev 2291) +++ trunk/OpenMPT/include/modplug/include 2013-06-03 16:11:55 UTC (rev 2292) Property changes on: trunk/OpenMPT/include/modplug/include ___________________________________________________________________ Added: tsvn:logminsize ## -0,0 +1 ## +10 \ No newline at end of property Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-06-03 13:59:03 UTC (rev 2291) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-06-03 16:11:55 UTC (rev 2292) @@ -124,7 +124,7 @@ <ClCompile> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <PreprocessorDefinitions>_WINDLL;LIBOPENMPT_BUILD;LIBOPENMPT_BUILD_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> @@ -164,7 +164,7 @@ <ClCompile> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <PreprocessorDefinitions>LIBOPENMPT_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> @@ -205,7 +205,7 @@ <MultiProcessorCompilation>true</MultiProcessorCompilation> <FloatingPointModel>Fast</FloatingPointModel> <PreprocessorDefinitions>_WINDLL;LIBOPENMPT_BUILD;LIBOPENMPT_BUILD_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> @@ -267,7 +267,7 @@ <MultiProcessorCompilation>true</MultiProcessorCompilation> <FloatingPointModel>Fast</FloatingPointModel> <PreprocessorDefinitions>LIBOPENMPT_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> Modified: trunk/OpenMPT/openmpt123/Makefile =================================================================== --- trunk/OpenMPT/openmpt123/Makefile 2013-06-03 13:59:03 UTC (rev 2291) +++ trunk/OpenMPT/openmpt123/Makefile 2013-06-03 16:11:55 UTC (rev 2292) @@ -32,7 +32,7 @@ DYNLINK = 1 -CPPFLAGS = -I../common -I.. +CPPFLAGS = -I../common -I.. -I../include/modplug/include CXXFLAGS = -std=c++0x -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align CFLAGS = -std=c99 -O3 -fPIC -fvisibility=hidden -fno-strict-aliasing -ffast-math -Wall -Wextra -Wcast-align LDFLAGS = @@ -144,8 +144,12 @@ -include $(ALL_DEPENDS) -OUTPUTS = bin/openmpt123 bin/modplug123 bin/libopenmpt.so bin/openmpt.a -#OUTPUTS += lib/libopenmpt_modplug.so +OUTPUTS += bin/libopenmpt.so +OUTPUTS += bin/openmpt.a +OUTPUTS += bin/openmpt123 +#OUTPUTS += bin/libopenmpt_modplug.so +#OUTPUTS += bin/modplug123 + all: $(OUTPUTS) bin/libopenmpt.so: $(LIBOPENMPT_OBJECTS) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-03 17:03:17
|
Revision: 2294 http://sourceforge.net/p/modplug/code/2294 Author: manxorist Date: 2013-06-03 17:03:07 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Fix] Acutally store a copy of the libmodplug headers in the repository. [Fix] Update include paths for win64 libopenmpt. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj Added Paths: ----------- trunk/OpenMPT/include/modplug/include/libmodplug/it_defs.h trunk/OpenMPT/include/modplug/include/libmodplug/modplug.h trunk/OpenMPT/include/modplug/include/libmodplug/sndfile.h trunk/OpenMPT/include/modplug/include/libmodplug/stdafx.h Added: trunk/OpenMPT/include/modplug/include/libmodplug/it_defs.h =================================================================== --- trunk/OpenMPT/include/modplug/include/libmodplug/it_defs.h (rev 0) +++ trunk/OpenMPT/include/modplug/include/libmodplug/it_defs.h 2013-06-03 17:03:07 UTC (rev 2294) @@ -0,0 +1,134 @@ +#ifndef _ITDEFS_H_ +#define _ITDEFS_H_ + +#pragma pack(1) + +typedef struct tagITFILEHEADER +{ + DWORD id; // 0x4D504D49 + CHAR songname[26]; + WORD reserved1; // 0x1004 + WORD ordnum; + WORD insnum; + WORD smpnum; + WORD patnum; + WORD cwtv; + WORD cmwt; + WORD flags; + WORD special; + BYTE globalvol; + BYTE mv; + BYTE speed; + BYTE tempo; + BYTE sep; + BYTE zero; + WORD msglength; + DWORD msgoffset; + DWORD reserved2; + BYTE chnpan[64]; + BYTE chnvol[64]; +} ITFILEHEADER; + + +typedef struct tagITENVELOPE +{ + BYTE flags; + BYTE num; + BYTE lpb; + BYTE lpe; + BYTE slb; + BYTE sle; + BYTE data[25*3]; + BYTE reserved; +} ITENVELOPE; + +// Old Impulse Instrument Format (cmwt < 0x200) +typedef struct tagITOLDINSTRUMENT +{ + DWORD id; // IMPI = 0x49504D49 + CHAR filename[12]; // DOS file name + BYTE zero; + BYTE flags; + BYTE vls; + BYTE vle; + BYTE sls; + BYTE sle; + WORD reserved1; + WORD fadeout; + BYTE nna; + BYTE dnc; + WORD trkvers; + BYTE nos; + BYTE reserved2; + CHAR name[26]; + WORD reserved3[3]; + BYTE keyboard[240]; + BYTE volenv[200]; + BYTE nodes[50]; +} ITOLDINSTRUMENT; + + +// Impulse Instrument Format +typedef struct tagITINSTRUMENT +{ + DWORD id; + CHAR filename[12]; + BYTE zero; + BYTE nna; + BYTE dct; + BYTE dca; + WORD fadeout; + signed char pps; + BYTE ppc; + BYTE gbv; + BYTE dfp; + BYTE rv; + BYTE rp; + WORD trkvers; + BYTE nos; + BYTE reserved1; + CHAR name[26]; + BYTE ifc; + BYTE ifr; + BYTE mch; + BYTE mpr; + WORD mbank; + BYTE keyboard[240]; + ITENVELOPE volenv; + ITENVELOPE panenv; + ITENVELOPE pitchenv; + BYTE dummy[4]; // was 7, but IT v2.17 saves 554 bytes +} ITINSTRUMENT; + + +// IT Sample Format +typedef struct ITSAMPLESTRUCT +{ + DWORD id; // 0x53504D49 + CHAR filename[12]; + BYTE zero; + BYTE gvl; + BYTE flags; + BYTE vol; + CHAR name[26]; + BYTE cvt; + BYTE dfp; + DWORD length; + DWORD loopbegin; + DWORD loopend; + DWORD C5Speed; + DWORD susloopbegin; + DWORD susloopend; + DWORD samplepointer; + BYTE vis; + BYTE vid; + BYTE vir; + BYTE vit; +} ITSAMPLESTRUCT; + +#pragma pack() + +extern BYTE autovibit2xm[8]; +extern BYTE autovibxm2it[8]; + +#endif Property changes on: trunk/OpenMPT/include/modplug/include/libmodplug/it_defs.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/include/modplug/include/libmodplug/modplug.h =================================================================== --- trunk/OpenMPT/include/modplug/include/libmodplug/modplug.h (rev 0) +++ trunk/OpenMPT/include/modplug/include/libmodplug/modplug.h 2013-06-03 17:03:07 UTC (rev 2294) @@ -0,0 +1,171 @@ +/* + * This source code is public domain. + * + * Authors: Kenton Varda <tem...@ga...> (C interface wrapper) + */ + +#ifndef MODPLUG_H__INCLUDED +#define MODPLUG_H__INCLUDED + +#ifdef __cplusplus +extern "C" { +#endif + +struct _ModPlugFile; +typedef struct _ModPlugFile ModPlugFile; + +struct _ModPlugNote { + unsigned char Note; + unsigned char Instrument; + unsigned char VolumeEffect; + unsigned char Effect; + unsigned char Volume; + unsigned char Parameter; +}; +typedef struct _ModPlugNote ModPlugNote; + +typedef void (*ModPlugMixerProc)(int*, unsigned long, unsigned long); + +/* Load a mod file. [data] should point to a block of memory containing the complete + * file, and [size] should be the size of that block. + * Return the loaded mod file on success, or NULL on failure. */ +ModPlugFile* ModPlug_Load(const void* data, int size); +/* Unload a mod file. */ +void ModPlug_Unload(ModPlugFile* file); + +/* Read sample data into the buffer. Returns the number of bytes read. If the end + * of the mod has been reached, zero is returned. */ +int ModPlug_Read(ModPlugFile* file, void* buffer, int size); + +/* Get the name of the mod. The returned buffer is stored within the ModPlugFile + * structure and will remain valid until you unload the file. */ +const char* ModPlug_GetName(ModPlugFile* file); + +/* Get the length of the mod, in milliseconds. Note that this result is not always + * accurate, especially in the case of mods with loops. */ +int ModPlug_GetLength(ModPlugFile* file); + +/* Seek to a particular position in the song. Note that seeking and MODs don't mix very + * well. Some mods will be missing instruments for a short time after a seek, as ModPlug + * does not scan the sequence backwards to find out which instruments were supposed to be + * playing at that time. (Doing so would be difficult and not very reliable.) Also, + * note that seeking is not very exact in some mods -- especially those for which + * ModPlug_GetLength() does not report the full length. */ +void ModPlug_Seek(ModPlugFile* file, int millisecond); + +enum _ModPlug_Flags +{ + MODPLUG_ENABLE_OVERSAMPLING = 1 << 0, /* Enable oversampling (*highly* recommended) */ + MODPLUG_ENABLE_NOISE_REDUCTION = 1 << 1, /* Enable noise reduction */ + MODPLUG_ENABLE_REVERB = 1 << 2, /* Enable reverb */ + MODPLUG_ENABLE_MEGABASS = 1 << 3, /* Enable megabass */ + MODPLUG_ENABLE_SURROUND = 1 << 4 /* Enable surround sound. */ +}; + +enum _ModPlug_ResamplingMode +{ + MODPLUG_RESAMPLE_NEAREST = 0, /* No interpolation (very fast, extremely bad sound quality) */ + MODPLUG_RESAMPLE_LINEAR = 1, /* Linear interpolation (fast, good quality) */ + MODPLUG_RESAMPLE_SPLINE = 2, /* Cubic spline interpolation (high quality) */ + MODPLUG_RESAMPLE_FIR = 3 /* 8-tap fir filter (extremely high quality) */ +}; + +typedef struct _ModPlug_Settings +{ + int mFlags; /* One or more of the MODPLUG_ENABLE_* flags above, bitwise-OR'ed */ + + /* Note that ModPlug always decodes sound at 44100kHz, 32 bit, stereo and then + * down-mixes to the settings you choose. */ + int mChannels; /* Number of channels - 1 for mono or 2 for stereo */ + int mBits; /* Bits per sample - 8, 16, or 32 */ + int mFrequency; /* Sampling rate - 11025, 22050, or 44100 */ + int mResamplingMode; /* One of MODPLUG_RESAMPLE_*, above */ + + int mStereoSeparation; /* Stereo separation, 1 - 256 */ + int mMaxMixChannels; /* Maximum number of mixing channels (polyphony), 32 - 256 */ + + int mReverbDepth; /* Reverb level 0(quiet)-100(loud) */ + int mReverbDelay; /* Reverb delay in ms, usually 40-200ms */ + int mBassAmount; /* XBass level 0(quiet)-100(loud) */ + int mBassRange; /* XBass cutoff in Hz 10-100 */ + int mSurroundDepth; /* Surround level 0(quiet)-100(heavy) */ + int mSurroundDelay; /* Surround delay in ms, usually 5-40ms */ + int mLoopCount; /* Number of times to loop. Zero prevents looping. + -1 loops forever. */ +} ModPlug_Settings; + +/* Get and set the mod decoder settings. All options, except for channels, bits-per-sample, + * sampling rate, and loop count, will take effect immediately. Those options which don't + * take effect immediately will take effect the next time you load a mod. */ +void ModPlug_GetSettings(ModPlug_Settings* settings); +void ModPlug_SetSettings(const ModPlug_Settings* settings); + +/* New ModPlug API Functions */ +/* NOTE: Master Volume (1-512) */ +unsigned int ModPlug_GetMasterVolume(ModPlugFile* file) ; +void ModPlug_SetMasterVolume(ModPlugFile* file,unsigned int cvol) ; + +int ModPlug_GetCurrentSpeed(ModPlugFile* file); +int ModPlug_GetCurrentTempo(ModPlugFile* file); +int ModPlug_GetCurrentOrder(ModPlugFile* file); +int ModPlug_GetCurrentPattern(ModPlugFile* file); +int ModPlug_GetCurrentRow(ModPlugFile* file); +int ModPlug_GetPlayingChannels(ModPlugFile* file); + +void ModPlug_SeekOrder(ModPlugFile* file,int order); +int ModPlug_GetModuleType(ModPlugFile* file); +char* ModPlug_GetMessage(ModPlugFile* file); + + +#ifndef MODPLUG_NO_FILESAVE +/* + * EXPERIMENTAL Export Functions + */ +/*Export to a Scream Tracker 3 S3M module. EXPERIMENTAL (only works on Little-Endian platforms)*/ +char ModPlug_ExportS3M(ModPlugFile* file, const char* filepath); + +/*Export to a Extended Module (XM). EXPERIMENTAL (only works on Little-Endian platforms)*/ +char ModPlug_ExportXM(ModPlugFile* file, const char* filepath); + +/*Export to a Amiga MOD file. EXPERIMENTAL.*/ +char ModPlug_ExportMOD(ModPlugFile* file, const char* filepath); + +/*Export to a Impulse Tracker IT file. Should work OK in Little-Endian & Big-Endian platforms :-) */ +char ModPlug_ExportIT(ModPlugFile* file, const char* filepath); +#endif // MODPLUG_NO_FILESAVE + +unsigned int ModPlug_NumInstruments(ModPlugFile* file); +unsigned int ModPlug_NumSamples(ModPlugFile* file); +unsigned int ModPlug_NumPatterns(ModPlugFile* file); +unsigned int ModPlug_NumChannels(ModPlugFile* file); +unsigned int ModPlug_SampleName(ModPlugFile* file, unsigned int qual, char* buff); +unsigned int ModPlug_InstrumentName(ModPlugFile* file, unsigned int qual, char* buff); + +/* + * Retrieve pattern note-data + */ +ModPlugNote* ModPlug_GetPattern(ModPlugFile* file, int pattern, unsigned int* numrows); + +/* + * ================= + * Mixer callback + * ================= + * + * Use this callback if you want to 'modify' the mixed data of LibModPlug. + * + * void proc(int* buffer,unsigned long channels,unsigned long nsamples) ; + * + * 'buffer': A buffer of mixed samples + * 'channels': N. of channels in the buffer + * 'nsamples': N. of samples in the buffeer (without taking care of n.channels) + * + * (Samples are signed 32-bit integers) + */ +void ModPlug_InitMixerCallback(ModPlugFile* file,ModPlugMixerProc proc) ; +void ModPlug_UnloadMixerCallback(ModPlugFile* file) ; + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif Property changes on: trunk/OpenMPT/include/modplug/include/libmodplug/modplug.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/include/modplug/include/libmodplug/sndfile.h =================================================================== --- trunk/OpenMPT/include/modplug/include/libmodplug/sndfile.h (rev 0) +++ trunk/OpenMPT/include/modplug/include/libmodplug/sndfile.h 2013-06-03 17:03:07 UTC (rev 2294) @@ -0,0 +1,1017 @@ +/* + * This source code is public domain. + * + * Authors: Olivier Lapicque <oli...@jp...>, + * Adam Goode <ad...@ev...> (endian and char fixes for PPC) +*/ + +#if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) +#include "config.h" +#define CONFIG_H_INCLUDED 1 +#endif + +#ifndef __SNDFILE_H +#define __SNDFILE_H + +#ifdef UNDER_CE +int _strnicmp(const char *str1,const char *str2, int n); +#endif + +#ifndef LPCBYTE +typedef const BYTE * LPCBYTE; +#endif + +#define MOD_AMIGAC2 0x1AB +#define MAX_SAMPLE_LENGTH 16000000 +#define MAX_SAMPLE_RATE 192000 +#define MAX_ORDERS 256 +#define MAX_PATTERNS 240 +#define MAX_SAMPLES 240 +#define MAX_INSTRUMENTS MAX_SAMPLES +#ifdef MODPLUG_FASTSOUNDLIB +#define MAX_CHANNELS 80 +#else +#define MAX_CHANNELS 128 +#endif +#define MAX_BASECHANNELS 64 +#define MAX_ENVPOINTS 32 +#define MIN_PERIOD 0x0020 +#define MAX_PERIOD 0xFFFF +#define MAX_PATTERNNAME 32 +#define MAX_CHANNELNAME 20 +#define MAX_INFONAME 80 +#define MAX_EQ_BANDS 6 +#define MAX_MIXPLUGINS 8 + + +#define MOD_TYPE_NONE 0x00 +#define MOD_TYPE_MOD 0x01 +#define MOD_TYPE_S3M 0x02 +#define MOD_TYPE_XM 0x04 +#define MOD_TYPE_MED 0x08 +#define MOD_TYPE_MTM 0x10 +#define MOD_TYPE_IT 0x20 +#define MOD_TYPE_669 0x40 +#define MOD_TYPE_ULT 0x80 +#define MOD_TYPE_STM 0x100 +#define MOD_TYPE_FAR 0x200 +#define MOD_TYPE_WAV 0x400 +#define MOD_TYPE_AMF 0x800 +#define MOD_TYPE_AMS 0x1000 +#define MOD_TYPE_DSM 0x2000 +#define MOD_TYPE_MDL 0x4000 +#define MOD_TYPE_OKT 0x8000 +#define MOD_TYPE_MID 0x10000 +#define MOD_TYPE_DMF 0x20000 +#define MOD_TYPE_PTM 0x40000 +#define MOD_TYPE_DBM 0x80000 +#define MOD_TYPE_MT2 0x100000 +#define MOD_TYPE_AMF0 0x200000 +#define MOD_TYPE_PSM 0x400000 +#define MOD_TYPE_J2B 0x800000 +#define MOD_TYPE_ABC 0x1000000 +#define MOD_TYPE_PAT 0x2000000 +#define MOD_TYPE_UMX 0x80000000 // Fake type +#define MAX_MODTYPE 24 + + + +// Channel flags: +// Bits 0-7: Sample Flags +#define CHN_16BIT 0x01 +#define CHN_LOOP 0x02 +#define CHN_PINGPONGLOOP 0x04 +#define CHN_SUSTAINLOOP 0x08 +#define CHN_PINGPONGSUSTAIN 0x10 +#define CHN_PANNING 0x20 +#define CHN_STEREO 0x40 +#define CHN_PINGPONGFLAG 0x80 +// Bits 8-31: Channel Flags +#define CHN_MUTE 0x100 +#define CHN_KEYOFF 0x200 +#define CHN_NOTEFADE 0x400 +#define CHN_SURROUND 0x800 +#define CHN_NOIDO 0x1000 +#define CHN_HQSRC 0x2000 +#define CHN_FILTER 0x4000 +#define CHN_VOLUMERAMP 0x8000 +#define CHN_VIBRATO 0x10000 +#define CHN_TREMOLO 0x20000 +#define CHN_PANBRELLO 0x40000 +#define CHN_PORTAMENTO 0x80000 +#define CHN_GLISSANDO 0x100000 +#define CHN_VOLENV 0x200000 +#define CHN_PANENV 0x400000 +#define CHN_PITCHENV 0x800000 +#define CHN_FASTVOLRAMP 0x1000000 +#define CHN_EXTRALOUD 0x2000000 +#define CHN_REVERB 0x4000000 +#define CHN_NOREVERB 0x8000000 + + +#define ENV_VOLUME 0x0001 +#define ENV_VOLSUSTAIN 0x0002 +#define ENV_VOLLOOP 0x0004 +#define ENV_PANNING 0x0008 +#define ENV_PANSUSTAIN 0x0010 +#define ENV_PANLOOP 0x0020 +#define ENV_PITCH 0x0040 +#define ENV_PITCHSUSTAIN 0x0080 +#define ENV_PITCHLOOP 0x0100 +#define ENV_SETPANNING 0x0200 +#define ENV_FILTER 0x0400 +#define ENV_VOLCARRY 0x0800 +#define ENV_PANCARRY 0x1000 +#define ENV_PITCHCARRY 0x2000 + +#define CMD_NONE 0 +#define CMD_ARPEGGIO 1 +#define CMD_PORTAMENTOUP 2 +#define CMD_PORTAMENTODOWN 3 +#define CMD_TONEPORTAMENTO 4 +#define CMD_VIBRATO 5 +#define CMD_TONEPORTAVOL 6 +#define CMD_VIBRATOVOL 7 +#define CMD_TREMOLO 8 +#define CMD_PANNING8 9 +#define CMD_OFFSET 10 +#define CMD_VOLUMESLIDE 11 +#define CMD_POSITIONJUMP 12 +#define CMD_VOLUME 13 +#define CMD_PATTERNBREAK 14 +#define CMD_RETRIG 15 +#define CMD_SPEED 16 +#define CMD_TEMPO 17 +#define CMD_TREMOR 18 +#define CMD_MODCMDEX 19 +#define CMD_S3MCMDEX 20 +#define CMD_CHANNELVOLUME 21 +#define CMD_CHANNELVOLSLIDE 22 +#define CMD_GLOBALVOLUME 23 +#define CMD_GLOBALVOLSLIDE 24 +#define CMD_KEYOFF 25 +#define CMD_FINEVIBRATO 26 +#define CMD_PANBRELLO 27 +#define CMD_XFINEPORTAUPDOWN 28 +#define CMD_PANNINGSLIDE 29 +#define CMD_SETENVPOSITION 30 +#define CMD_MIDI 31 + + +// Volume Column commands +#define VOLCMD_VOLUME 1 +#define VOLCMD_PANNING 2 +#define VOLCMD_VOLSLIDEUP 3 +#define VOLCMD_VOLSLIDEDOWN 4 +#define VOLCMD_FINEVOLUP 5 +#define VOLCMD_FINEVOLDOWN 6 +#define VOLCMD_VIBRATOSPEED 7 +#define VOLCMD_VIBRATO 8 +#define VOLCMD_PANSLIDELEFT 9 +#define VOLCMD_PANSLIDERIGHT 10 +#define VOLCMD_TONEPORTAMENTO 11 +#define VOLCMD_PORTAUP 12 +#define VOLCMD_PORTADOWN 13 + +#define RSF_16BIT 0x04 +#define RSF_STEREO 0x08 + +#define RS_PCM8S 0 // 8-bit signed +#define RS_PCM8U 1 // 8-bit unsigned +#define RS_PCM8D 2 // 8-bit delta values +#define RS_ADPCM4 3 // 4-bit ADPCM-packed +#define RS_PCM16D 4 // 16-bit delta values +#define RS_PCM16S 5 // 16-bit signed +#define RS_PCM16U 6 // 16-bit unsigned +#define RS_PCM16M 7 // 16-bit motorola order +#define RS_STPCM8S (RS_PCM8S|RSF_STEREO) // stereo 8-bit signed +#define RS_STPCM8U (RS_PCM8U|RSF_STEREO) // stereo 8-bit unsigned +#define RS_STPCM8D (RS_PCM8D|RSF_STEREO) // stereo 8-bit delta values +#define RS_STPCM16S (RS_PCM16S|RSF_STEREO) // stereo 16-bit signed +#define RS_STPCM16U (RS_PCM16U|RSF_STEREO) // stereo 16-bit unsigned +#define RS_STPCM16D (RS_PCM16D|RSF_STEREO) // stereo 16-bit delta values +#define RS_STPCM16M (RS_PCM16M|RSF_STEREO) // stereo 16-bit signed big endian +// IT 2.14 compressed samples +#define RS_IT2148 0x10 +#define RS_IT21416 0x14 +#define RS_IT2158 0x12 +#define RS_IT21516 0x16 +// AMS Packed Samples +#define RS_AMS8 0x11 +#define RS_AMS16 0x15 +// DMF Huffman compression +#define RS_DMF8 0x13 +#define RS_DMF16 0x17 +// MDL Huffman compression +#define RS_MDL8 0x20 +#define RS_MDL16 0x24 +#define RS_PTM8DTO16 0x25 +// Stereo Interleaved Samples +#define RS_STIPCM8S (RS_PCM8S|0x40|RSF_STEREO) // stereo 8-bit signed +#define RS_STIPCM8U (RS_PCM8U|0x40|RSF_STEREO) // stereo 8-bit unsigned +#define RS_STIPCM16S (RS_PCM16S|0x40|RSF_STEREO) // stereo 16-bit signed +#define RS_STIPCM16U (RS_PCM16U|0x40|RSF_STEREO) // stereo 16-bit unsigned +#define RS_STIPCM16M (RS_PCM16M|0x40|RSF_STEREO) // stereo 16-bit signed big endian +// 24-bit signed +#define RS_PCM24S (RS_PCM16S|0x80) // mono 24-bit signed +#define RS_STIPCM24S (RS_PCM16S|0x80|RSF_STEREO) // stereo 24-bit signed +#define RS_PCM32S (RS_PCM16S|0xC0) // mono 24-bit signed +#define RS_STIPCM32S (RS_PCM16S|0xC0|RSF_STEREO) // stereo 24-bit signed + +// NNA types +#define NNA_NOTECUT 0 +#define NNA_CONTINUE 1 +#define NNA_NOTEOFF 2 +#define NNA_NOTEFADE 3 + +// DCT types +#define DCT_NONE 0 +#define DCT_NOTE 1 +#define DCT_SAMPLE 2 +#define DCT_INSTRUMENT 3 + +// DNA types +#define DNA_NOTECUT 0 +#define DNA_NOTEOFF 1 +#define DNA_NOTEFADE 2 + +// Mixer Hardware-Dependent features +#define SYSMIX_ENABLEMMX 0x01 +#define SYSMIX_WINDOWSNT 0x02 +#define SYSMIX_SLOWCPU 0x04 +#define SYSMIX_FASTCPU 0x08 + +// Module flags +#define SONG_EMBEDMIDICFG 0x0001 +#define SONG_FASTVOLSLIDES 0x0002 +#define SONG_ITOLDEFFECTS 0x0004 +#define SONG_ITCOMPATMODE 0x0008 +#define SONG_LINEARSLIDES 0x0010 +#define SONG_PATTERNLOOP 0x0020 +#define SONG_STEP 0x0040 +#define SONG_PAUSED 0x0080 +#define SONG_FADINGSONG 0x0100 +#define SONG_ENDREACHED 0x0200 +#define SONG_GLOBALFADE 0x0400 +#define SONG_CPUVERYHIGH 0x0800 +#define SONG_FIRSTTICK 0x1000 +#define SONG_MPTFILTERMODE 0x2000 +#define SONG_SURROUNDPAN 0x4000 +#define SONG_EXFILTERRANGE 0x8000 +#define SONG_AMIGALIMITS 0x10000 + +// Global Options (Renderer) +#define SNDMIX_REVERSESTEREO 0x0001 +#define SNDMIX_NOISEREDUCTION 0x0002 +#define SNDMIX_AGC 0x0004 +#define SNDMIX_NORESAMPLING 0x0008 +#define SNDMIX_HQRESAMPLER 0x0010 +#define SNDMIX_MEGABASS 0x0020 +#define SNDMIX_SURROUND 0x0040 +#define SNDMIX_REVERB 0x0080 +#define SNDMIX_EQ 0x0100 +#define SNDMIX_SOFTPANNING 0x0200 +#define SNDMIX_ULTRAHQSRCMODE 0x0400 +// Misc Flags (can safely be turned on or off) +#define SNDMIX_DIRECTTODISK 0x10000 +#define SNDMIX_ENABLEMMX 0x20000 +#define SNDMIX_NOBACKWARDJUMPS 0x40000 +#define SNDMIX_MAXDEFAULTPAN 0x80000 // Used by the MOD loader + + +// Reverb Types (GM2 Presets) +enum { + REVERBTYPE_SMALLROOM, + REVERBTYPE_MEDIUMROOM, + REVERBTYPE_LARGEROOM, + REVERBTYPE_SMALLHALL, + REVERBTYPE_MEDIUMHALL, + REVERBTYPE_LARGEHALL, + NUM_REVERBTYPES +}; + + +enum { + SRCMODE_NEAREST, + SRCMODE_LINEAR, + SRCMODE_SPLINE, + SRCMODE_POLYPHASE, + NUM_SRC_MODES +}; + + +// Sample Struct +typedef struct _MODINSTRUMENT +{ + UINT nLength,nLoopStart,nLoopEnd; + UINT nSustainStart, nSustainEnd; + signed char *pSample; + UINT nC4Speed; + WORD nPan; + WORD nVolume; + WORD nGlobalVol; + WORD uFlags; + signed char RelativeTone; + signed char nFineTune; + BYTE nVibType; + BYTE nVibSweep; + BYTE nVibDepth; + BYTE nVibRate; + CHAR name[22]; +} MODINSTRUMENT; + + +// Instrument Struct +typedef struct _INSTRUMENTHEADER +{ + UINT nFadeOut; + DWORD dwFlags; + WORD nGlobalVol; + WORD nPan; + WORD VolPoints[MAX_ENVPOINTS]; + WORD PanPoints[MAX_ENVPOINTS]; + WORD PitchPoints[MAX_ENVPOINTS]; + BYTE VolEnv[MAX_ENVPOINTS]; + BYTE PanEnv[MAX_ENVPOINTS]; + BYTE PitchEnv[MAX_ENVPOINTS]; + BYTE Keyboard[128]; + BYTE NoteMap[128]; + + BYTE nVolEnv; + BYTE nPanEnv; + BYTE nPitchEnv; + BYTE nVolLoopStart; + BYTE nVolLoopEnd; + BYTE nVolSustainBegin; + BYTE nVolSustainEnd; + BYTE nPanLoopStart; + BYTE nPanLoopEnd; + BYTE nPanSustainBegin; + BYTE nPanSustainEnd; + BYTE nPitchLoopStart; + BYTE nPitchLoopEnd; + BYTE nPitchSustainBegin; + BYTE nPitchSustainEnd; + BYTE nNNA; + BYTE nDCT; + BYTE nDNA; + BYTE nPanSwing; + BYTE nVolSwing; + BYTE nIFC; + BYTE nIFR; + WORD wMidiBank; + BYTE nMidiProgram; + BYTE nMidiChannel; + BYTE nMidiDrumKey; + signed char nPPS; + unsigned char nPPC; + CHAR name[32]; + CHAR filename[12]; +} INSTRUMENTHEADER; + + +// Channel Struct +typedef struct _MODCHANNEL +{ + // First 32-bytes: Most used mixing information: don't change it + signed char * pCurrentSample; + DWORD nPos; + DWORD nPosLo; // actually 16-bit + LONG nInc; // 16.16 + LONG nRightVol; + LONG nLeftVol; + LONG nRightRamp; + LONG nLeftRamp; + // 2nd cache line + DWORD nLength; + DWORD dwFlags; + DWORD nLoopStart; + DWORD nLoopEnd; + LONG nRampRightVol; + LONG nRampLeftVol; + LONG nFilter_Y1, nFilter_Y2, nFilter_Y3, nFilter_Y4; + LONG nFilter_A0, nFilter_B0, nFilter_B1; + LONG nROfs, nLOfs; + LONG nRampLength; + // Information not used in the mixer + signed char * pSample; + LONG nNewRightVol, nNewLeftVol; + LONG nRealVolume, nRealPan; + LONG nVolume, nPan, nFadeOutVol; + LONG nPeriod, nC4Speed, nPortamentoDest; + INSTRUMENTHEADER *pHeader; + MODINSTRUMENT *pInstrument; + DWORD nVolEnvPosition, nPanEnvPosition, nPitchEnvPosition; + DWORD nMasterChn, nVUMeter; + LONG nGlobalVol, nInsVol; + LONG nFineTune, nTranspose; + LONG nPortamentoSlide, nAutoVibDepth; + UINT nAutoVibPos, nVibratoPos, nTremoloPos, nPanbrelloPos; + // 16-bit members + signed short nVolSwing, nPanSwing; + // 8-bit members + BYTE nNote, nNNA; + BYTE nNewNote, nNewIns, nCommand, nArpeggio; + BYTE nOldVolumeSlide, nOldFineVolUpDown; + BYTE nOldPortaUpDown, nOldFinePortaUpDown; + BYTE nOldPanSlide, nOldChnVolSlide; + BYTE nVibratoType, nVibratoSpeed, nVibratoDepth; + BYTE nTremoloType, nTremoloSpeed, nTremoloDepth; + BYTE nPanbrelloType, nPanbrelloSpeed, nPanbrelloDepth; + BYTE nOldCmdEx, nOldVolParam, nOldTempo; + BYTE nOldOffset, nOldHiOffset; + BYTE nCutOff, nResonance; + BYTE nRetrigCount, nRetrigParam; + BYTE nTremorCount, nTremorParam; + BYTE nPatternLoop, nPatternLoopCount; + BYTE nRowNote, nRowInstr; + BYTE nRowVolCmd, nRowVolume; + BYTE nRowCommand, nRowParam; + BYTE nLeftVU, nRightVU; + BYTE nActiveMacro, nPadding; +} MODCHANNEL; + + +typedef struct _MODCHANNELSETTINGS +{ + UINT nPan; + UINT nVolume; + DWORD dwFlags; + UINT nMixPlugin; + char szName[MAX_CHANNELNAME]; // changed from CHAR +} MODCHANNELSETTINGS; + + +typedef struct _MODCOMMAND +{ + BYTE note; + BYTE instr; + BYTE volcmd; + BYTE command; + BYTE vol; + BYTE param; +} MODCOMMAND, *LPMODCOMMAND; + +//////////////////////////////////////////////////////////////////// +// Mix Plugins +#define MIXPLUG_MIXREADY 0x01 // Set when cleared + +class IMixPlugin +{ +public: + virtual ~IMixPlugin(); + virtual int AddRef() = 0; + virtual int Release() = 0; + virtual void SaveAllParameters() = 0; + virtual void RestoreAllParameters() = 0; + virtual void Process(float *pOutL, float *pOutR, unsigned long nSamples) = 0; + virtual void Init(unsigned long nFreq, int bReset) = 0; + virtual void MidiSend(DWORD dwMidiCode) = 0; + virtual void MidiCommand(UINT nMidiCh, UINT nMidiProg, UINT note, UINT vol) = 0; +}; + + +#define MIXPLUG_INPUTF_MASTEREFFECT 0x01 // Apply to master mix +#define MIXPLUG_INPUTF_BYPASS 0x02 // Bypass effect +#define MIXPLUG_INPUTF_WETMIX 0x04 // Wet Mix (dry added) + +typedef struct _SNDMIXPLUGINSTATE +{ + DWORD dwFlags; // MIXPLUG_XXXX + LONG nVolDecayL, nVolDecayR; // Buffer click removal + int *pMixBuffer; // Stereo effect send buffer + float *pOutBufferL; // Temp storage for int -> float conversion + float *pOutBufferR; +} SNDMIXPLUGINSTATE, *PSNDMIXPLUGINSTATE; + +typedef struct _SNDMIXPLUGININFO +{ + DWORD dwPluginId1; + DWORD dwPluginId2; + DWORD dwInputRouting; // MIXPLUG_INPUTF_XXXX + DWORD dwOutputRouting; // 0=mix 0x80+=fx + DWORD dwReserved[4]; // Reserved for routing info + CHAR szName[32]; + CHAR szLibraryName[64]; // original DLL name +} SNDMIXPLUGININFO, *PSNDMIXPLUGININFO; // Size should be 128 + +typedef struct _SNDMIXPLUGIN +{ + IMixPlugin *pMixPlugin; + PSNDMIXPLUGINSTATE pMixState; + ULONG nPluginDataSize; + PVOID pPluginData; + SNDMIXPLUGININFO Info; +} SNDMIXPLUGIN, *PSNDMIXPLUGIN; + +typedef BOOL (*PMIXPLUGINCREATEPROC)(PSNDMIXPLUGIN); + +//////////////////////////////////////////////////////////////////// + +enum { + MIDIOUT_START=0, + MIDIOUT_STOP, + MIDIOUT_TICK, + MIDIOUT_NOTEON, + MIDIOUT_NOTEOFF, + MIDIOUT_VOLUME, + MIDIOUT_PAN, + MIDIOUT_BANKSEL, + MIDIOUT_PROGRAM, +}; + + +typedef struct MODMIDICFG +{ + char szMidiGlb[9*32]; // changed from CHAR + char szMidiSFXExt[16*32]; // changed from CHAR + char szMidiZXXExt[128*32]; // changed from CHAR +} MODMIDICFG, *LPMODMIDICFG; + +#define NOTE_MAX 120 //Defines maximum notevalue as well as maximum number of notes. + +typedef VOID (* LPSNDMIXHOOKPROC)(int *, unsigned long, unsigned long); // buffer, samples, channels + + + +//============== +class CSoundFile +//============== +{ +public: // Static Members + static UINT m_nXBassDepth, m_nXBassRange; + static UINT m_nReverbDepth, m_nReverbDelay, gnReverbType; + static UINT m_nProLogicDepth, m_nProLogicDelay; + static UINT m_nStereoSeparation; + static UINT m_nMaxMixChannels; + static LONG m_nStreamVolume; + static DWORD gdwSysInfo, gdwSoundSetup, gdwMixingFreq, gnBitsPerSample, gnChannels; + static UINT gnAGC, gnVolumeRampSamples, gnVUMeter, gnCPUUsage; + static LPSNDMIXHOOKPROC gpSndMixHook; + static PMIXPLUGINCREATEPROC gpMixPluginCreateProc; + +public: // for Editing + MODCHANNEL Chn[MAX_CHANNELS]; // Channels + UINT ChnMix[MAX_CHANNELS]; // Channels to be mixed + MODINSTRUMENT Ins[MAX_SAMPLES]; // Instruments + INSTRUMENTHEADER *Headers[MAX_INSTRUMENTS]; // Instrument Headers + MODCHANNELSETTINGS ChnSettings[MAX_BASECHANNELS]; // Channels settings + MODCOMMAND *Patterns[MAX_PATTERNS]; // Patterns + WORD PatternSize[MAX_PATTERNS]; // Patterns Lengths + BYTE Order[MAX_ORDERS]; // Pattern Orders + MODMIDICFG m_MidiCfg; // Midi macro config table + SNDMIXPLUGIN m_MixPlugins[MAX_MIXPLUGINS]; // Mix plugins + UINT m_nDefaultSpeed, m_nDefaultTempo, m_nDefaultGlobalVolume; + DWORD m_dwSongFlags; // Song flags SONG_XXXX + UINT m_nChannels, m_nMixChannels, m_nMixStat, m_nBufferCount; + UINT m_nType, m_nSamples, m_nInstruments; + UINT m_nTickCount, m_nTotalCount, m_nPatternDelay, m_nFrameDelay; + UINT m_nMusicSpeed, m_nMusicTempo; + UINT m_nNextRow, m_nRow; + UINT m_nPattern,m_nCurrentPattern,m_nNextPattern,m_nRestartPos; + UINT m_nMasterVolume, m_nGlobalVolume, m_nSongPreAmp; + UINT m_nFreqFactor, m_nTempoFactor, m_nOldGlbVolSlide; + LONG m_nMinPeriod, m_nMaxPeriod, m_nRepeatCount, m_nInitialRepeatCount; + DWORD m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples; + UINT m_nMaxOrderPosition; + UINT m_nPatternNames; + LPSTR m_lpszSongComments, m_lpszPatternNames; + char m_szNames[MAX_INSTRUMENTS][32]; // changed from CHAR + CHAR CompressionTable[16]; + +public: + CSoundFile(); + ~CSoundFile(); + +public: + BOOL Create(LPCBYTE lpStream, DWORD dwMemLength=0); + BOOL Destroy(); + UINT GetType() const { return m_nType; } + UINT GetNumChannels() const; + UINT GetLogicalChannels() const { return m_nChannels; } + BOOL SetMasterVolume(UINT vol, BOOL bAdjustAGC=FALSE); + UINT GetMasterVolume() const { return m_nMasterVolume; } + UINT GetNumPatterns() const; + UINT GetNumInstruments() const; + UINT GetNumSamples() const { return m_nSamples; } + UINT GetCurrentPos() const; + UINT GetCurrentPattern() const { return m_nPattern; } + UINT GetCurrentOrder() const { return m_nCurrentPattern; } + UINT GetSongComments(LPSTR s, UINT cbsize, UINT linesize=32); + UINT GetRawSongComments(LPSTR s, UINT cbsize, UINT linesize=32); + UINT GetMaxPosition() const; + void SetCurrentPos(UINT nPos); + void SetCurrentOrder(UINT nOrder); + void GetTitle(LPSTR s) const { lstrcpyn(s,m_szNames[0],32); } + LPCSTR GetTitle() const { return m_szNames[0]; } + UINT GetSampleName(UINT nSample,LPSTR s=NULL) const; + UINT GetInstrumentName(UINT nInstr,LPSTR s=NULL) const; + UINT GetMusicSpeed() const { return m_nMusicSpeed; } + UINT GetMusicTempo() const { return m_nMusicTempo; } + DWORD GetLength(BOOL bAdjust, BOOL bTotal=FALSE); + DWORD GetSongTime() { return GetLength(FALSE, TRUE); } + void SetRepeatCount(int n) { m_nRepeatCount = n; m_nInitialRepeatCount = n; } + int GetRepeatCount() const { return m_nRepeatCount; } + BOOL IsPaused() const { return (m_dwSongFlags & SONG_PAUSED) ? TRUE : FALSE; } + void LoopPattern(int nPat, int nRow=0); + void CheckCPUUsage(UINT nCPU); + BOOL SetPatternName(UINT nPat, LPCSTR lpszName); + BOOL GetPatternName(UINT nPat, LPSTR lpszName, UINT cbSize=MAX_PATTERNNAME) const; + // Module Loaders + BOOL ReadXM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadS3M(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMod(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMed(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMTM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadSTM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadIT(LPCBYTE lpStream, DWORD dwMemLength); + BOOL Read669(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadUlt(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadWav(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadDSM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadFAR(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadAMS(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadAMS2(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMDL(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadOKT(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadDMF(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadPTM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadDBM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadAMF(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMT2(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadPSM(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadJ2B(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadUMX(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadABC(LPCBYTE lpStream, DWORD dwMemLength); + BOOL TestABC(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadMID(LPCBYTE lpStream, DWORD dwMemLength); + BOOL TestMID(LPCBYTE lpStream, DWORD dwMemLength); + BOOL ReadPAT(LPCBYTE lpStream, DWORD dwMemLength); + BOOL TestPAT(LPCBYTE lpStream, DWORD dwMemLength); + // Save Functions +#ifndef MODPLUG_NO_FILESAVE + UINT WriteSample(FILE *f, MODINSTRUMENT *pins, UINT nFlags, UINT nMaxLen=0); + BOOL SaveXM(LPCSTR lpszFileName, UINT nPacking=0); + BOOL SaveS3M(LPCSTR lpszFileName, UINT nPacking=0); + BOOL SaveMod(LPCSTR lpszFileName, UINT nPacking=0); + BOOL SaveIT(LPCSTR lpszFileName, UINT nPacking=0); +#endif // MODPLUG_NO_FILESAVE + // MOD Convert function + UINT GetBestSaveFormat() const; + UINT GetSaveFormats() const; + void ConvertModCommand(MODCOMMAND *) const; + void S3MConvert(MODCOMMAND *m, BOOL bIT) const; + void S3MSaveConvert(UINT *pcmd, UINT *pprm, BOOL bIT) const; + WORD ModSaveCommand(const MODCOMMAND *m, BOOL bXM) const; + +public: + // Real-time sound functions + VOID ResetChannels(); + + UINT Read(LPVOID lpBuffer, UINT cbBuffer); + UINT CreateStereoMix(int count); + BOOL FadeSong(UINT msec); + BOOL GlobalFadeSong(UINT msec); + UINT GetTotalTickCount() const { return m_nTotalCount; } + VOID ResetTotalTickCount() { m_nTotalCount = 0; } + +public: + // Mixer Config + static BOOL InitPlayer(BOOL bReset=FALSE); + static BOOL SetMixConfig(UINT nStereoSeparation, UINT nMaxMixChannels); + static BOOL SetWaveConfig(UINT nRate,UINT nBits,UINT nChannels,BOOL bMMX=FALSE); + static BOOL SetResamplingMode(UINT nMode); // SRCMODE_XXXX + static BOOL IsStereo() { return (gnChannels > 1) ? TRUE : FALSE; } + static DWORD GetSampleRate() { return gdwMixingFreq; } + static DWORD GetBitsPerSample() { return gnBitsPerSample; } + static DWORD InitSysInfo(); + static DWORD GetSysInfo() { return gdwSysInfo; } + // AGC + static BOOL GetAGC() { return (gdwSoundSetup & SNDMIX_AGC) ? TRUE : FALSE; } + static void SetAGC(BOOL b); + static void ResetAGC(); + static void ProcessAGC(int count); + + //GCCFIX -- added these functions back in! + static BOOL SetWaveConfigEx(BOOL bSurround,BOOL bNoOverSampling,BOOL bReverb,BOOL hqido,BOOL bMegaBass,BOOL bNR,BOOL bEQ); + // DSP Effects + static void InitializeDSP(BOOL bReset); + static void ProcessStereoDSP(int count); + static void ProcessMonoDSP(int count); + // [Reverb level 0(quiet)-100(loud)], [delay in ms, usually 40-200ms] + static BOOL SetReverbParameters(UINT nDepth, UINT nDelay); + // [XBass level 0(quiet)-100(loud)], [cutoff in Hz 10-100] + static BOOL SetXBassParameters(UINT nDepth, UINT nRange); + // [Surround level 0(quiet)-100(heavy)] [delay in ms, usually 5-40ms] + static BOOL SetSurroundParameters(UINT nDepth, UINT nDelay); +public: + BOOL ReadNote(); + BOOL ProcessRow(); + BOOL ProcessEffects(); + UINT GetNNAChannel(UINT nChn) const; + void CheckNNA(UINT nChn, UINT instr, int note, BOOL bForceCut); + void NoteChange(UINT nChn, int note, BOOL bPorta=FALSE, BOOL bResetEnv=TRUE); + void InstrumentChange(MODCHANNEL *pChn, UINT instr, BOOL bPorta=FALSE,BOOL bUpdVol=TRUE,BOOL bResetEnv=TRUE); + // Channel Effects + void PortamentoUp(MODCHANNEL *pChn, UINT param); + void PortamentoDown(MODCHANNEL *pChn, UINT param); + void FinePortamentoUp(MODCHANNEL *pChn, UINT param); + void FinePortamentoDown(MODCHANNEL *pChn, UINT param); + void ExtraFinePortamentoUp(MODCHANNEL *pChn, UINT param); + void ExtraFinePortamentoDown(MODCHANNEL *pChn, UINT param); + void TonePortamento(MODCHANNEL *pChn, UINT param); + void Vibrato(MODCHANNEL *pChn, UINT param); + void FineVibrato(MODCHANNEL *pChn, UINT param); + void VolumeSlide(MODCHANNEL *pChn, UINT param); + void PanningSlide(MODCHANNEL *pChn, UINT param); + void ChannelVolSlide(MODCHANNEL *pChn, UINT param); + void FineVolumeUp(MODCHANNEL *pChn, UINT param); + void FineVolumeDown(MODCHANNEL *pChn, UINT param); + void Tremolo(MODCHANNEL *pChn, UINT param); + void Panbrello(MODCHANNEL *pChn, UINT param); + void RetrigNote(UINT nChn, UINT param); + void NoteCut(UINT nChn, UINT nTick); + void KeyOff(UINT nChn); + int PatternLoop(MODCHANNEL *, UINT param); + void ExtendedMODCommands(UINT nChn, UINT param); + void ExtendedS3MCommands(UINT nChn, UINT param); + void ExtendedChannelEffect(MODCHANNEL *, UINT param); + void ProcessMidiMacro(UINT nChn, LPCSTR pszMidiMacro, UINT param=0); + void SetupChannelFilter(MODCHANNEL *pChn, BOOL bReset, int flt_modifier=256) const; + // Low-Level effect processing + void DoFreqSlide(MODCHANNEL *pChn, LONG nFreqSlide); + // Global Effects + void SetTempo(UINT param); + void SetSpeed(UINT param); + void GlobalVolSlide(UINT param); + DWORD IsSongFinished(UINT nOrder, UINT nRow) const; + BOOL IsValidBackwardJump(UINT nStartOrder, UINT nStartRow, UINT nJumpOrder, UINT nJumpRow) const; + // Read/Write sample functions + signed char GetDeltaValue(signed char prev, UINT n) const { return (signed char)(prev + CompressionTable[n & 0x0F]); } + UINT PackSample(int &sample, int next); + BOOL CanPackSample(LPSTR pSample, UINT nLen, UINT nPacking, BYTE *result=NULL); + UINT ReadSample(MODINSTRUMENT *pIns, UINT nFlags, LPCSTR pMemFile, DWORD dwMemLength); + BOOL DestroySample(UINT nSample); + BOOL DestroyInstrument(UINT nInstr); + BOOL IsSampleUsed(UINT nSample); + BOOL IsInstrumentUsed(UINT nInstr); + BOOL RemoveInstrumentSamples(UINT nInstr); + UINT DetectUnusedSamples(BOOL *); + BOOL RemoveSelectedSamples(BOOL *); + void AdjustSampleLoop(MODINSTRUMENT *pIns); + // I/O from another sound file + BOOL ReadInstrumentFromSong(UINT nInstr, CSoundFile *, UINT nSrcInstrument); + BOOL ReadSampleFromSong(UINT nSample, CSoundFile *, UINT nSrcSample); + // Period/Note functions + UINT GetNoteFromPeriod(UINT period) const; + UINT GetPeriodFromNote(UINT note, int nFineTune, UINT nC4Speed) const; + UINT GetFreqFromPeriod(UINT period, UINT nC4Speed, int nPeriodFrac=0) const; + // Misc functions + MODINSTRUMENT *GetSample(UINT n) { return Ins+n; } + void ResetMidiCfg(); + UINT MapMidiInstrument(DWORD dwProgram, UINT nChannel, UINT nNote); + BOOL ITInstrToMPT(const void *p, INSTRUMENTHEADER *penv, UINT trkvers); + UINT SaveMixPlugins(FILE *f=NULL, BOOL bUpdate=TRUE); + UINT LoadMixPlugins(const void *pData, UINT nLen); +#ifndef NO_FILTER + DWORD CutOffToFrequency(UINT nCutOff, int flt_modifier=256) const; // [0-255] => [1-10KHz] +#endif + + // Static helper functions +public: + static DWORD TransposeToFrequency(int transp, int ftune=0); + static int FrequencyToTranspose(DWORD freq); + static void FrequencyToTranspose(MODINSTRUMENT *psmp); + + // System-Dependant functions +public: + static MODCOMMAND *AllocatePattern(UINT rows, UINT nchns); + static signed char* AllocateSample(UINT nbytes); + static void FreePattern(LPVOID pat); + static void FreeSample(LPVOID p); + static UINT Normalize24BitBuffer(LPBYTE pbuffer, UINT cbsizebytes, DWORD lmax24, DWORD dwByteInc); +}; + + +// inline DWORD BigEndian(DWORD x) { return ((x & 0xFF) << 24) | ((x & 0xFF00) << 8) | ((x & 0xFF0000) >> 8) | ((x & 0xFF000000) >> 24); } +// inline WORD BigEndianW(WORD x) { return (WORD)(((x >> 8) & 0xFF) | ((x << 8) & 0xFF00)); } + + +////////////////////////////////////////////////////////// +// WAVE format information + +#pragma pack(1) + +// Standard IFF chunks IDs +#define IFFID_FORM 0x4d524f46 +#define IFFID_RIFF 0x46464952 +#define IFFID_WAVE 0x45564157 +#define IFFID_LIST 0x5453494C +#define IFFID_INFO 0x4F464E49 + +// IFF Info fields +#define IFFID_ICOP 0x504F4349 +#define IFFID_IART 0x54524149 +#define IFFID_IPRD 0x44525049 +#define IFFID_INAM 0x4D414E49 +#define IFFID_ICMT 0x544D4349 +#define IFFID_IENG 0x474E4549 +#define IFFID_ISFT 0x54465349 +#define IFFID_ISBJ 0x4A425349 +#define IFFID_IGNR 0x524E4749 +#define IFFID_ICRD 0x44524349 + +// Wave IFF chunks IDs +#define IFFID_wave 0x65766177 +#define IFFID_fmt 0x20746D66 +#define IFFID_wsmp 0x706D7377 +#define IFFID_pcm 0x206d6370 +#define IFFID_data 0x61746164 +#define IFFID_smpl 0x6C706D73 +#define IFFID_xtra 0x61727478 + +typedef struct WAVEFILEHEADER +{ + DWORD id_RIFF; // "RIFF" + DWORD filesize; // file length-8 + DWORD id_WAVE; +} WAVEFILEHEADER; + + +typedef struct WAVEFORMATHEADER +{ + DWORD id_fmt; // "fmt " + DWORD hdrlen; // 16 + WORD format; // 1 + WORD channels; // 1:mono, 2:stereo + DWORD freqHz; // sampling freq + DWORD bytessec; // bytes/sec=freqHz*samplesize + WORD samplesize; // sizeof(sample) + WORD bitspersample; // bits per sample (8/16) +} WAVEFORMATHEADER; + + +typedef struct WAVEDATAHEADER +{ + DWORD id_data; // "data" + DWORD length; // length of data +} WAVEDATAHEADER; + + +typedef struct WAVESMPLHEADER +{ + // SMPL + DWORD smpl_id; // "smpl" -> 0x6C706D73 + DWORD smpl_len; // length of smpl: 3Ch (54h with sustain loop) + DWORD dwManufacturer; + DWORD dwProduct; + DWORD dwSamplePeriod; // 1000000000/freqHz + DWORD dwBaseNote; // 3Ch = C-4 -> 60 + RelativeTone + DWORD dwPitchFraction; + DWORD dwSMPTEFormat; + DWORD dwSMPTEOffset; + DWORD dwSampleLoops; // number of loops + DWORD cbSamplerData; +} WAVESMPLHEADER; + + +typedef struct SAMPLELOOPSTRUCT +{ + DWORD dwIdentifier; + DWORD dwLoopType; // 0=normal, 1=bidi + DWORD dwLoopStart; + DWORD dwLoopEnd; // Byte offset ? + DWORD dwFraction; + DWORD dwPlayCount; // Loop Count, 0=infinite +} SAMPLELOOPSTRUCT; + + +typedef struct WAVESAMPLERINFO +{ + WAVESMPLHEADER wsiHdr; + SAMPLELOOPSTRUCT wsiLoops[2]; +} WAVESAMPLERINFO; + + +typedef struct WAVELISTHEADER +{ + DWORD list_id; // "LIST" -> 0x5453494C + DWORD list_len; + DWORD info; // "INFO" +} WAVELISTHEADER; + + +typedef struct WAVEEXTRAHEADER +{ + DWORD xtra_id; // "xtra" -> 0x61727478 + DWORD xtra_len; + DWORD dwFlags; + WORD wPan; + WORD wVolume; + WORD wGlobalVol; + WORD wReserved; + BYTE nVibType; + BYTE nVibSweep; + BYTE nVibDepth; + BYTE nVibRate; +} WAVEEXTRAHEADER; + +#pragma pack() + +/////////////////////////////////////////////////////////// +// Low-level Mixing functions + +#define MIXBUFFERSIZE 512 +#define MIXING_ATTENUATION 4 +#define MIXING_CLIPMIN (-0x08000000) +#define MIXING_CLIPMAX (0x07FFFFFF) +#define VOLUMERAMPPRECISION 12 +#define FADESONGDELAY 100 +#define EQ_BUFFERSIZE (MIXBUFFERSIZE) +#define AGC_PRECISION 9 +#define AGC_UNITY (1 << AGC_PRECISION) + +// Calling conventions +#ifdef MSC_VER +#define MPPASMCALL __cdecl +#define MPPFASTCALL __fastcall +#else +#define MPPASMCALL +#define MPPFASTCALL +#endif + +#define MOD2XMFineTune(k) ((int)( (signed char)((k)<<4) )) +#define XM2MODFineTune(k) ((int)( (k>>4)&0x0f )) + +int _muldiv(long a, long b, long c); +int _muldivr(long a, long b, long c); + + +// Byte swapping functions from the GNU C Library and libsdl + +/* Swap bytes in 16 bit value. */ +#ifdef __GNUC__ +# define bswap_16(x) \ + (__extension__ \ + ({ unsigned short int __bsx = (x); \ + ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); })) +#else +static __inline unsigned short int +bswap_16 (unsigned short int __bsx) +{ + return ((((__bsx) >> 8) & 0xff) | (((__bsx) & 0xff) << 8)); +} +#endif + +/* Swap bytes in 32 bit value. */ +#ifdef __GNUC__ +# define bswap_32(x) \ + (__extension__ \ + ({ unsigned int __bsx = (x); \ + ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | \ + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); })) +#else +static __inline unsigned int +bswap_32 (unsigned int __bsx) +{ + return ((((__bsx) & 0xff000000) >> 24) | (((__bsx) & 0x00ff0000) >> 8) | + (((__bsx) & 0x0000ff00) << 8) | (((__bsx) & 0x000000ff) << 24)); +} +#endif + +#if (defined ARM) && (defined _WIN32_WCE) +static __inline unsigned short int +ARM_get16(const void *data) +{ + unsigned short int s; + memcpy(&s,data,sizeof(s)); + return s; +} + +static __inline unsigned int +ARM_get32(const void *data) +{ + unsigned int s; + memcpy(&s,data,sizeof(s)); + return s; +} + +#define bswapLE16(X) ARM_get16(&X) +#define bswapLE32(X) ARM_get32(&X) +#define bswapBE16(X) bswap_16(ARM_get16(&X)) +#define bswapBE32(X) bswap_32(ARM_get32(&X)) + +// From libsdl +#elif defined(WORDS_BIGENDIAN) && WORDS_BIGENDIAN +#define bswapLE16(X) bswap_16(X) +#define bswapLE32(X) bswap_32(X) +#define bswapBE16(X) (X) +#define bswapBE32(X) (X) +#else +#define bswapLE16(X) (X) +#define bswapLE32(X) (X) +#define bswapBE16(X) bswap_16(X) +#define bswapBE32(X) bswap_32(X) +#endif + +#endif Property changes on: trunk/OpenMPT/include/modplug/include/libmodplug/sndfile.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: trunk/OpenMPT/include/modplug/include/libmodplug/stdafx.h =================================================================== --- trunk/OpenMPT/include/modplug/include/libmodplug/stdafx.h (rev 0) +++ trunk/OpenMPT/include/modplug/include/libmodplug/stdafx.h 2013-06-03 17:03:07 UTC (rev 2294) @@ -0,0 +1,127 @@ +/* + * This source code is public domain. + * + * Authors: Rani Assaf <ra...@ma...>, + * Olivier Lapicque <oli...@jp...>, + * Adam Goode <ad...@ev...> (endian and char fixes for PPC) + */ + +#ifndef _STDAFX_H_ +#define _STDAFX_H_ + +/* Autoconf detection of stdint/inttypes */ +#if defined(HAVE_CONFIG_H) && !defined(CONFIG_H_INCLUDED) +# include "config.h" +# define CONFIG_H_INCLUDED 1 +#endif +#ifdef HAVE_INTTYPES_H +# include <inttypes.h> +#endif +#ifdef HAVE_STDINT_H +# include <stdint.h> +#endif + + +#ifdef _WIN32 + +#ifdef MSC_VER +#pragma warning (disable:4201) +#pragma warning (disable:4514) +#endif + +#define WIN32_LEAN_AND_MEAN +#include <windows.h> +#include <windowsx.h> +#include <mmsystem.h> +#include <stdio.h> +#include <malloc.h> +#include <stdint.h> + +#define srandom(_seed) srand(_seed) +#define random() rand() +#define sleep(_ms) Sleep(_ms) + +inline void ProcessPlugins(int n) {} + +#define strncasecmp(a,b,c) strncmp(a,b,c) +#define strcasecmp(a,b) strcmp(a,b) +#define strnicmp(a,b,c) strncasecmp(a,b,c) +#define HAVE_SINF 1 + +#else + +#include <stdlib.h> +#include <stdio.h> +#include <string.h> +#ifdef HAVE_MALLOC_H +#include <malloc.h> +#endif + +typedef int8_t CHAR; +typedef uint8_t UCHAR; +typedef uint8_t* PUCHAR; +typedef uint16_t USHORT; +typedef uint32_t ULONG; +typedef uint32_t UINT; +typedef uint32_t DWORD; +typedef int32_t LONG; +typedef int64_t LONGLONG; +typedef int32_t* LPLONG; +typedef uint32_t* LPDWORD; +typedef uint16_t WORD; +typedef uint8_t BYTE; +typedef uint8_t* LPBYTE; +typedef bool BOOL; +typedef char* LPSTR; +typedef void* LPVOID; +typedef uint16_t* LPWORD; +typedef const char* LPCSTR; +typedef void* PVOID; +typedef void VOID; + +inline LONG MulDiv (long a, long b, long c) +{ + // if (!c) return 0; + return ((uint64_t) a * (uint64_t) b ) / c; +} + +#define MODPLUG_NO_FILESAVE +#define NO_AGC +#define LPCTSTR LPCSTR +#define lstrcpyn strncpy +#define lstrcpy strcpy +#define lstrcmp strcmp +#define WAVE_FORMAT_PCM 1 +//#define ENABLE_EQ + +#define GHND 0 + +inline int8_t * GlobalAllocPtr(unsigned int, size_t size) +{ + int8_t * p = (int8_t *) malloc(size); + + if (p != NULL) memset(p, 0, size); + return p; +} + +inline void ProcessPlugins(int n) {} + +#define GlobalFreePtr(p) free((void *)(p)) + +#define strnicmp(a,b,c) strncasecmp(a,b,c) +#define wsprintf sprintf + +#ifndef FALSE +#define FALSE false +#endif + +#ifndef TRUE +#define TRUE true +#endif + +#endif // _WIN32 + +#endif + + + Property changes on: trunk/OpenMPT/include/modplug/include/libmodplug/stdafx.h ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/x-chdr \ No newline at end of property Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Modified: trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-06-03 16:15:48 UTC (rev 2293) +++ trunk/OpenMPT/libopenmpt/libopenmpt.vcxproj 2013-06-03 17:03:07 UTC (rev 2294) @@ -144,7 +144,7 @@ <ClCompile> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <PreprocessorDefinitions>_WINDLL;LIBOPENMPT_BUILD;LIBOPENMPT_BUILD_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> @@ -182,7 +182,7 @@ <ClCompile> <WarningLevel>Level3</WarningLevel> <Optimization>Disabled</Optimization> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <PreprocessorDefinitions>LIBOPENMPT_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions> <RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary> </ClCompile> @@ -237,7 +237,7 @@ <MultiProcessorCompilation>true</MultiProcessorCompilation> <FloatingPointModel>Fast</FloatingPointModel> <PreprocessorDefinitions>_WINDLL;LIBOPENMPT_BUILD;LIBOPENMPT_BUILD_DLL;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> @@ -294,7 +294,7 @@ <MultiProcessorCompilation>true</MultiProcessorCompilation> <FloatingPointModel>Fast</FloatingPointModel> <PreprocessorDefinitions>LIBOPENMPT_BUILD;%(PreprocessorDefinitions)</PreprocessorDefinitions> - <AdditionalIncludeDirectories>..;../common;../include;../common/svn_version;../common/svn_version_default</AdditionalIncludeDirectories> + <AdditionalIncludeDirectories>..;../common;../common/svn_version;../common/svn_version_default;../include;../include/modplug/include</AdditionalIncludeDirectories> <RuntimeLibrary>MultiThreaded</RuntimeLibrary> <InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion> <FavorSizeOrSpeed>Speed</FavorSizeOrSpeed> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-03 17:10:52
|
Revision: 2295 http://sourceforge.net/p/modplug/code/2295 Author: manxorist Date: 2013-06-03 17:10:45 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Ref] Compiling libopenmpt on non-windows should not require -DLIBOPENMPT_BUILD_DLL. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt_config.h trunk/OpenMPT/libopenmpt/libopenmpt_internal.h trunk/OpenMPT/openmpt123/Makefile Modified: trunk/OpenMPT/libopenmpt/libopenmpt_config.h =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_config.h 2013-06-03 17:03:07 UTC (rev 2294) +++ trunk/OpenMPT/libopenmpt/libopenmpt_config.h 2013-06-03 17:10:45 UTC (rev 2295) @@ -10,49 +10,55 @@ #ifndef LIBOPENMPT_CONFIG_H #define LIBOPENMPT_CONFIG_H -#if defined(LIBOPENMPT_BUILD_DLL) || defined(LIBOPENMPT_USE_DLL) -#if defined(_MSC_VER) || defined(_WIN32) -#define LIBOPENMPT_DLL_HELPER_EXPORT __declspec(dllexport) -#define LIBOPENMPT_DLL_HELPER_IMPORT __declspec(dllimport) -#define LIBOPENMPT_DLL_HELPER_LOCAL +/* provoke warnings if already defined */ +#define LIBOPENMPT_API +#undef LIBOPENMPT_API +#define LIBOPENMPT_CXX_API +#undef LIBOPENMPT_CXX_API + +#if defined(_MSC_VER) + +#define LIBOPENMPT_API_HELPER_EXPORT __declspec(dllexport) +#define LIBOPENMPT_API_HELPER_IMPORT __declspec(dllimport) +#define LIBOPENMPT_API_HELPER_PUBLIC +#define LIBOPENMPT_API_HELPER_LOCAL + #elif defined(__GNUC__) || defined(__clang__) -#define LIBOPENMPT_DLL_HELPER_EXPORT __attribute__((visibility("default"))) -#define LIBOPENMPT_DLL_HELPER_IMPORT __attribute__((visibility("default"))) -#define LIBOPENMPT_DLL_HELPER_LOCAL __attribute__((visibility("hidden"))) + +#if defined(_WIN32) +#define LIBOPENMPT_API_HELPER_EXPORT __declspec(dllexport) +#define LIBOPENMPT_API_HELPER_IMPORT __declspec(dllimport) #else -#define LIBOPENMPT_DLL_HELPER_EXPORT -#define LIBOPENMPT_DLL_HELPER_IMPORT -#define LIBOPENMPT_DLL_HELPER_LOCAL +#define LIBOPENMPT_API_HELPER_EXPORT __attribute__((visibility("default"))) +#define LIBOPENMPT_API_HELPER_IMPORT __attribute__((visibility("default"))) #endif +#define LIBOPENMPT_API_HELPER_PUBLIC __attribute__((visibility("default"))) +#define LIBOPENMPT_API_HELPER_LOCAL __attribute__((visibility("hidden"))) + #else -#define LIBOPENMPT_DLL_HELPER_EXPORT -#define LIBOPENMPT_DLL_HELPER_IMPORT -#define LIBOPENMPT_DLL_HELPER_LOCAL + +#define LIBOPENMPT_API_HELPER_EXPORT +#define LIBOPENMPT_API_HELPER_IMPORT +#define LIBOPENMPT_API_HELPER_PUBLIC +#define LIBOPENMPT_API_HELPER_LOCAL + #endif #if defined(LIBOPENMPT_BUILD_DLL) -#define LIBOPENMPT_API LIBOPENMPT_DLL_HELPER_EXPORT -#ifdef __cplusplus -#define LIBOPENMPT_CXX_API LIBOPENMPT_DLL_HELPER_EXPORT -#endif +#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_EXPORT #elif defined(LIBOPENMPT_USE_DLL) -#define LIBOPENMPT_API LIBOPENMPT_DLL_HELPER_IMPORT -#ifdef __cplusplus -#define LIBOPENMPT_CXX_API LIBOPENMPT_DLL_HELPER_IMPORT -#endif +#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_IMPORT #else -#define LIBOPENMPT_API extern -#ifdef __cplusplus -#define LIBOPENMPT_CXX_API +#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_PUBLIC #endif -#endif #ifdef __cplusplus +#define LIBOPENMPT_CXX_API LIBOPENMPT_API #if defined(LIBOPENMPT_USE_DLL) #if defined(_MSC_VER) && !defined(_DLL) #error "C++ interface is disabled if libopenmpt is built as a DLL and the runtime is statically linked. This is not supported by microsoft and cannot possibly work. Ever." #undef LIBOPENMPT_CXX_API -#define LIBOPENMPT_CXX_API LIBOPENMPT_DLL_HELPER_LOCAL +#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_LOCAL #endif #endif #endif Modified: trunk/OpenMPT/libopenmpt/libopenmpt_internal.h =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_internal.h 2013-06-03 17:03:07 UTC (rev 2294) +++ trunk/OpenMPT/libopenmpt/libopenmpt_internal.h 2013-06-03 17:10:45 UTC (rev 2295) @@ -17,12 +17,12 @@ #if defined(NO_LIBOPENMPT_C) #undef LIBOPENMPT_API -#define LIBOPENMPT_API LIBOPENMPT_DLL_HELPER_LOCAL +#define LIBOPENMPT_API LIBOPENMPT_API_HELPER_LOCAL #endif #if defined(NO_LIBOPENMPT_CXX) #undef LIBOPENMPT_CXX_API -#define LIBOPENMPT_CXX_API LIBOPENMPT_DLL_HELPER_LOCAL +#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_LOCAL #endif #ifdef __cplusplus @@ -33,7 +33,7 @@ #pragma message( "libopenmpt C++ interface is disabled if libopenmpt is built as a DLL and the runtime is statically linked. This is not supported by microsoft and cannot possibly work. Ever." ) #endif #undef LIBOPENMPT_CXX_API -#define LIBOPENMPT_CXX_API LIBOPENMPT_DLL_HELPER_LOCAL +#define LIBOPENMPT_CXX_API LIBOPENMPT_API_HELPER_LOCAL #endif #endif #endif Modified: trunk/OpenMPT/openmpt123/Makefile =================================================================== --- trunk/OpenMPT/openmpt123/Makefile 2013-06-03 17:03:07 UTC (rev 2294) +++ trunk/OpenMPT/openmpt123/Makefile 2013-06-03 17:10:45 UTC (rev 2295) @@ -83,7 +83,7 @@ #CPPFLAGS += -I../common/svn_version_default -CPPFLAGS += -DLIBOPENMPT_BUILD -DLIBOPENMPT_BUILD_DLL +CPPFLAGS += -DLIBOPENMPT_BUILD COMMON_CXX_SOURCES += \ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-03 18:29:15
|
Revision: 2298 http://sourceforge.net/p/modplug/code/2298 Author: manxorist Date: 2013-06-03 18:29:05 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Ref] Do not build libmodplug interface when building a static library. [Ref] Export libmodplug functions with linker pragma instead of __declspec on the function definition for MSVC, so we can include modplug.h. Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2013-06-03 17:58:45 UTC (rev 2297) +++ trunk/OpenMPT/common/BuildSettings.h 2013-06-03 18:29:05 UTC (rev 2298) @@ -173,6 +173,12 @@ #undef MODPLUG_NO_FILESAVE // tests require file saving #endif +#if !defined(NO_LIBMODPLUG) +#if !defined(LIBOPENMPT_BUILD) || (defined(LIBOPENMPT_BUILD) && defined(_WIN32) && !defined(LIBOPENMPT_BUILD_DLL)) +#define NO_LIBMODPLUG // libmodplug interface emulation requires libopenmpt dll build on windows +#endif +#endif + #if !defined(NO_WINAMP) #if !defined(LIBOPENMPT_BUILD) || (defined(LIBOPENMPT_BUILD) && !defined(LIBOPENMPT_BUILD_DLL)) #define NO_WINAMP // winamp plugin requires libopenmpt dll build Modified: trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2013-06-03 17:58:45 UTC (rev 2297) +++ trunk/OpenMPT/libopenmpt/libopenmpt_modplug.c 2013-06-03 18:29:05 UTC (rev 2298) @@ -13,14 +13,12 @@ #ifdef _MSC_VER #define _CRT_SECURE_NO_WARNINGS -#endif +#endif /* _MSC_VER */ #include "libopenmpt_internal.h" #include "libopenmpt.h" -#define LIBOPENMPT_MODPLUG_API LIBOPENMPT_API - #include <limits.h> #include <math.h> #include <memory.h> @@ -28,55 +26,17 @@ #include <stdlib.h> #include <string.h> -/* from libmodplug/modplug.h */ -/* declared here, because otherwise msvc errors when seeing dllexport declarations later on */ -typedef void (*ModPlugMixerProc)(int*, unsigned long, unsigned long); -struct _ModPlugFile; -typedef struct _ModPlugFile ModPlugFile; -struct _ModPlug_Settings; -typedef struct _ModPlug_Settings ModPlug_Settings; -struct _ModPlugNote; -typedef struct _ModPlugNote ModPlugNote; -LIBOPENMPT_MODPLUG_API ModPlugFile* ModPlug_Load(const void* data, int size); -LIBOPENMPT_MODPLUG_API void ModPlug_Unload(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_Read(ModPlugFile* file, void* buffer, int size); -LIBOPENMPT_MODPLUG_API const char* ModPlug_GetName(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetLength(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API void ModPlug_Seek(ModPlugFile* file, int millisecond); -LIBOPENMPT_MODPLUG_API void ModPlug_GetSettings(ModPlug_Settings* settings); -LIBOPENMPT_MODPLUG_API void ModPlug_SetSettings(const ModPlug_Settings* settings); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_GetMasterVolume(ModPlugFile* file) ; -LIBOPENMPT_MODPLUG_API void ModPlug_SetMasterVolume(ModPlugFile* file,unsigned int cvol); -LIBOPENMPT_MODPLUG_API int ModPlug_GetCurrentSpeed(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetCurrentTempo(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetCurrentOrder(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetCurrentPattern(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetCurrentRow(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API int ModPlug_GetPlayingChannels(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API void ModPlug_SeekOrder(ModPlugFile* file,int order); -LIBOPENMPT_MODPLUG_API int ModPlug_GetModuleType(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API char* ModPlug_GetMessage(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_NumInstruments(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_NumSamples(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_NumPatterns(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_NumChannels(ModPlugFile* file); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_SampleName(ModPlugFile* file, unsigned int qual, char* buff); -LIBOPENMPT_MODPLUG_API unsigned int ModPlug_InstrumentName(ModPlugFile* file, unsigned int qual, char* buff); -LIBOPENMPT_MODPLUG_API ModPlugNote* ModPlug_GetPattern(ModPlugFile* file, int pattern, unsigned int* numrows); -LIBOPENMPT_MODPLUG_API void ModPlug_InitMixerCallback(ModPlugFile* file,ModPlugMixerProc proc); -LIBOPENMPT_MODPLUG_API void ModPlug_UnloadMixerCallback(ModPlugFile* file) ; -LIBOPENMPT_MODPLUG_API char ModPlug_ExportS3M(ModPlugFile* file, const char* filepath); -LIBOPENMPT_MODPLUG_API char ModPlug_ExportXM(ModPlugFile* file, const char* filepath); -LIBOPENMPT_MODPLUG_API char ModPlug_ExportMOD(ModPlugFile* file, const char* filepath); -LIBOPENMPT_MODPLUG_API char ModPlug_ExportIT(ModPlugFile* file, const char* filepath); - +#ifdef _MSC_VER +/* msvc errors when seeing dllexport declarations after prototypes have been declared in modplug.h */ +#define LIBOPENMPT_MODPLUG_API +#else /* !_MSC_VER */ +#define LIBOPENMPT_MODPLUG_API LIBOPENMPT_API +#endif /* _MSC_VER */ #include "libmodplug/modplug.h" /* from libmodplug/sndfile.h */ /* header is not c clean */ - #define MIXING_ATTENUATION 4 - #define MOD_TYPE_NONE 0x0 #define MOD_TYPE_MOD 0x1 #define MOD_TYPE_S3M 0x2 @@ -621,4 +581,39 @@ return 0; } -#endif // NO_LIBMODPLUG +#ifdef _MSC_VER +#pragma comment(linker, "/EXPORT:ModPlug_Load=_ModPlug_Load") +#pragma comment(linker, "/EXPORT:ModPlug_Unload=_ModPlug_Unload") +#pragma comment(linker, "/EXPORT:ModPlug_Read=_ModPlug_Read") +#pragma comment(linker, "/EXPORT:ModPlug_GetName=_ModPlug_GetName") +#pragma comment(linker, "/EXPORT:ModPlug_GetLength=_ModPlug_GetLength") +#pragma comment(linker, "/EXPORT:ModPlug_Seek=_ModPlug_Seek") +#pragma comment(linker, "/EXPORT:ModPlug_GetSettings=_ModPlug_GetSettings") +#pragma comment(linker, "/EXPORT:ModPlug_SetSettings=_ModPlug_SetSettings") +#pragma comment(linker, "/EXPORT:ModPlug_GetMasterVolume=_ModPlug_GetMasterVolume") +#pragma comment(linker, "/EXPORT:ModPlug_SetMasterVolume=_ModPlug_SetMasterVolume") +#pragma comment(linker, "/EXPORT:ModPlug_GetCurrentSpeed=_ModPlug_GetCurrentSpeed") +#pragma comment(linker, "/EXPORT:ModPlug_GetCurrentTempo=_ModPlug_GetCurrentTempo") +#pragma comment(linker, "/EXPORT:ModPlug_GetCurrentOrder=_ModPlug_GetCurrentOrder") +#pragma comment(linker, "/EXPORT:ModPlug_GetCurrentPattern=_ModPlug_GetCurrentPattern") +#pragma comment(linker, "/EXPORT:ModPlug_GetCurrentRow=_ModPlug_GetCurrentRow") +#pragma comment(linker, "/EXPORT:ModPlug_GetPlayingChannels=_ModPlug_GetPlayingChannels") +#pragma comment(linker, "/EXPORT:ModPlug_SeekOrder=_ModPlug_SeekOrder") +#pragma comment(linker, "/EXPORT:ModPlug_GetModuleType=_ModPlug_GetModuleType") +#pragma comment(linker, "/EXPORT:ModPlug_GetMessage=_ModPlug_GetMessage") +#pragma comment(linker, "/EXPORT:ModPlug_NumInstruments=_ModPlug_NumInstruments") +#pragma comment(linker, "/EXPORT:ModPlug_NumSamples=_ModPlug_NumSamples") +#pragma comment(linker, "/EXPORT:ModPlug_NumPatterns=_ModPlug_NumPatterns") +#pragma comment(linker, "/EXPORT:ModPlug_NumChannels=_ModPlug_NumChannels") +#pragma comment(linker, "/EXPORT:ModPlug_SampleName=_ModPlug_SampleName") +#pragma comment(linker, "/EXPORT:ModPlug_InstrumentName=_ModPlug_InstrumentName") +#pragma comment(linker, "/EXPORT:ModPlug_GetPattern=_ModPlug_GetPattern") +#pragma comment(linker, "/EXPORT:ModPlug_InitMixerCallback=_ModPlug_InitMixerCallback") +#pragma comment(linker, "/EXPORT:ModPlug_UnloadMixerCallback=_ModPlug_UnloadMixerCallback") +#pragma comment(linker, "/EXPORT:ModPlug_ExportS3M=_ModPlug_ExportS3M") +#pragma comment(linker, "/EXPORT:ModPlug_ExportXM=_ModPlug_ExportXM") +#pragma comment(linker, "/EXPORT:ModPlug_ExportMOD=_ModPlug_ExportMOD") +#pragma comment(linker, "/EXPORT:ModPlug_ExportIT=_ModPlug_ExportIT") +#endif /* _MSC_VER */ + +#endif /* NO_LIBMODPLUG */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-03 20:18:57
|
Revision: 2299 http://sourceforge.net/p/modplug/code/2299 Author: manxorist Date: 2013-06-03 20:18:48 +0000 (Mon, 03 Jun 2013) Log Message: ----------- [Ref] Fix UINT to CHANNELINDEX conversion warning in Fastmix.cpp. [Fix] ASSERT(lCount <= MIXBUFFERSIZE) before we fill the buffer. [Ref] Cleanup mixer statistics calculation. [Ref] Transfer mixer statistics via Notification system. Modified Paths: -------------- trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Notification.h trunk/OpenMPT/soundlib/Fastmix.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -975,8 +975,6 @@ notifyType = m_pSndFile->m_pModDoc->GetNotificationType(); notifyItem = m_pSndFile->m_pModDoc->GetNotificationItem(); } - if(m_nMixChn < m_pSndFile->m_nMixStat) m_nMixChn++; - if(m_nMixChn > m_pSndFile->m_nMixStat) m_nMixChn--; // Notify Client //if(m_NotifyBuffer.read_size() > 0) { @@ -984,7 +982,7 @@ } // Add an entry to the notification history - Notification notification(notifyType, notifyItem, notificationtimestamp, m_pSndFile->m_nRow, m_pSndFile->m_nTickCount, m_pSndFile->m_nCurrentOrder, m_pSndFile->m_nPattern); + Notification notification(notifyType, notifyItem, notificationtimestamp, m_pSndFile->m_nRow, m_pSndFile->m_nTickCount, m_pSndFile->m_nCurrentOrder, m_pSndFile->m_nPattern, m_pSndFile->m_nMixStat); if(endOfStream) notification.type.set(Notification::EOS); @@ -1322,8 +1320,6 @@ if(m_pSndFile) { m_pSndFile->SuspendPlugins(); - m_nMixChn = 0; - m_nAvgMixChn = 0; if(m_pSndFile->GetpModDoc()) { m_wndTree.UpdatePlayPos(m_pSndFile->GetpModDoc(), nullptr); @@ -1398,8 +1394,6 @@ gnLVuMeter = gnRVuMeter = 0; gnClipLeft = gnClipRight = false; - m_nMixChn = 0; - m_nAvgMixChn = 0; if(!StartPlayback()) { @@ -2305,6 +2299,7 @@ if (GetFollowSong()) ::SendMessage(GetFollowSong(), WM_MOD_UPDATEPOSITION, 0, lParam); } + m_nMixChn = pnotify->mixedChannels; m_wndToolBar.m_VuMeter.SetVuMeter(pnotify->masterVU[0], pnotify->masterVU[1], pnotify->type[Notification::Stop]); } return 0; Modified: trunk/OpenMPT/mptrack/Notification.h =================================================================== --- trunk/OpenMPT/mptrack/Notification.h 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/mptrack/Notification.h 2013-06-03 20:18:48 UTC (rev 2299) @@ -47,10 +47,11 @@ uint32 tick; // dito ORDERINDEX order; // dito PATTERNINDEX pattern; // dito + uint32 mixedChannels; // dito uint32 masterVU[2]; // dito SmpLength pos[MAX_CHANNELS]; // Sample / envelope pos for each channel if != PosInvalid, or pattern channel VUs - Notification(Type t = Default, Item i = 0, int64 s = 0, ROWINDEX r = 0, uint32 ti = 0, ORDERINDEX o = 0, PATTERNINDEX p = 0) : timestampSamples(s), type(t), item(i), row(r), tick(ti), order(o), pattern(p) + Notification(Type t = Default, Item i = 0, int64 s = 0, ROWINDEX r = 0, uint32 ti = 0, ORDERINDEX o = 0, PATTERNINDEX p = 0, uint32 x = 0) : timestampSamples(s), type(t), item(i), row(r), tick(ti), order(o), pattern(p), mixedChannels(x) { MemsetZero(masterVU); } Modified: trunk/OpenMPT/soundlib/Fastmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -1441,17 +1441,17 @@ -UINT CSoundFile::CreateStereoMix(int count) +void CSoundFile::CreateStereoMix(int count) //----------------------------------------- { LPLONG pOfsL, pOfsR; - DWORD nchused, nchmixed; + CHANNELINDEX nchused, nchmixed; - if (!count) return 0; + if (!count) return; bool ITPingPongMode = IsITPingPongMode(); if (m_MixerSettings.gnChannels > 2) InitMixBuffer(MixRearBuffer, count*2); nchused = nchmixed = 0; - for (UINT nChn=0; nChn<m_nMixChannels; nChn++) + for(CHANNELINDEX nChn=0; nChn<m_nMixChannels; nChn++) { const LPMIXINTERFACE *pMixFuncTable; ModChannel * const pChannel = &Chn[ChnMix[nChn]]; @@ -1548,7 +1548,7 @@ continue; } // Should we mix this channel ? - UINT naddmix; + bool addmix; if (((nchmixed >= m_MixerSettings.m_nMaxMixChannels) && !IsRenderingToDisc()) || ((!pChannel->nRampLength) && (!(pChannel->rightVol|pChannel->leftVol)))) { @@ -1557,7 +1557,7 @@ pChannel->nPos += (delta >> 16); pChannel->nROfs = pChannel->nLOfs = 0; pbuffer += nSmpCount*2; - naddmix = 0; + addmix = false; } else // Do mixing { @@ -1571,7 +1571,7 @@ pChannel->nROfs += *(pbufmax-2); pChannel->nLOfs += *(pbufmax-1); pbuffer = pbufmax; - naddmix = 1; + addmix = true; } nsamples -= nSmpCount; if (pChannel->nRampLength) @@ -1591,9 +1591,9 @@ } } if (nsamples > 0) goto SampleLooping; - nchmixed += naddmix; + nchmixed += addmix?1:0; } - return nchused; + m_nMixStat += nchused; } Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-03 20:18:48 UTC (rev 2299) @@ -336,7 +336,8 @@ INSTRUMENTINDEX m_nInstruments; UINT m_nDefaultSpeed, m_nDefaultTempo, m_nDefaultGlobalVolume; FlagSet<SongFlags> m_SongFlags; - UINT m_nMixChannels, m_nMixStat; + CHANNELINDEX m_nMixChannels; + UINT m_nMixStat; samplecount_t m_nBufferCount; double m_dBufferDiff; UINT m_nTickCount; @@ -371,7 +372,7 @@ LONG m_nRepeatCount; // -1 means repeat infinitely. DWORD m_nGlobalFadeSamples, m_nGlobalFadeMaxSamples; UINT m_nMaxOrderPosition; - UINT ChnMix[MAX_CHANNELS]; // Channels to be mixed + CHANNELINDEX ChnMix[MAX_CHANNELS]; // Channels to be mixed ModChannel Chn[MAX_CHANNELS]; // Mixing channels... First m_nChannel channels are master channels (i.e. they are never NNA channels)! ModChannelSettings ChnSettings[MAX_BASECHANNELS]; // Initial channels settings CPatternContainer Patterns; // Patterns @@ -596,7 +597,7 @@ void RecalculateGainForAllPlugs(); void ResetChannels(); UINT Read(LPVOID lpBuffer, UINT cbBuffer, void * const *outputBuffers = nullptr); - UINT CreateStereoMix(int count); + void CreateStereoMix(int count); BOOL FadeSong(UINT msec); BOOL GlobalFadeSong(UINT msec); void ProcessPlugins(UINT nCount); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-03 18:29:05 UTC (rev 2298) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-03 20:18:48 UTC (rev 2299) @@ -202,13 +202,13 @@ LPCONVERTPROC pCvt = nullptr; samplecount_t lMax, lCount, lSampleCount; size_t lSampleSize; - UINT nStat = 0; UINT nMaxPlugins; std::size_t renderedCount = 0; nMaxPlugins = MAX_MIXPLUGINS; while ((nMaxPlugins > 0) && (!m_MixPlugins[nMaxPlugins-1].pMixPlugin)) nMaxPlugins--; - m_nMixStat = 0; + + UINT nMixStatCount = 0; lSampleSize = m_MixerSettings.gnChannels; switch(m_MixerSettings.m_SampleFormat) @@ -279,20 +279,28 @@ if (!lCount) break; + ASSERT(lCount <= MIXBUFFERSIZE); // ensure MIXBUFFERSIZE really is our max buffer size + lSampleCount = lCount; #ifndef NO_REVERB m_Reverb.gnReverbSend = 0; #endif // NO_REVERB + if(nMixStatCount == 0) + { + // reset mixer channel count before we are calling CreateStereoMix the first time this round, if we are not updating the mixer state, we do not reset statistics + m_nMixStat = 0; + } + nMixStatCount++; + // Resetting sound buffer StereoFill(MixSoundBuffer, lCount, &gnDryROfsVol, &gnDryLOfsVol); - ASSERT(lCount<=MIXBUFFERSIZE); // ensure MIXBUFFERSIZE really is our max buffer size if (m_MixerSettings.gnChannels >= 2) { lSampleCount *= 2; - m_nMixStat += CreateStereoMix(lCount); + CreateStereoMix(lCount); #ifndef NO_REVERB m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); @@ -307,7 +315,7 @@ } } else { - m_nMixStat += CreateStereoMix(lCount); + CreateStereoMix(lCount); #ifndef NO_REVERB m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); @@ -338,8 +346,6 @@ } #endif // NO_EQ - nStat++; - #ifndef MODPLUG_TRACKER if(!m_MixerSettings.IsFloatSampleFormat()) { @@ -431,7 +437,10 @@ } MixDone: if (lRead && lpBuffer) memset(lpBuffer, (m_MixerSettings.m_SampleFormat == SampleFormatUnsigned8) ? 0x80 : 0, lRead * lSampleSize); // clear remaining interleaved output buffer - if (nStat) { m_nMixStat += nStat-1; m_nMixStat /= nStat; } + if(nMixStatCount > 0) + { + m_nMixStat = (m_nMixStat + nMixStatCount - 1) / nMixStatCount; // round up + } return renderedCount; } @@ -2113,12 +2122,12 @@ // Checking Max Mix Channels reached: ordering by volume if ((m_nMixChannels >= m_MixerSettings.m_nMaxMixChannels) && !IsRenderingToDisc()) { - for (UINT i=0; i<m_nMixChannels; i++) + for(CHANNELINDEX i=0; i<m_nMixChannels; i++) { - UINT j=i; + CHANNELINDEX j=i; while ((j+1<m_nMixChannels) && (Chn[ChnMix[j]].nRealVolume < Chn[ChnMix[j+1]].nRealVolume)) { - UINT n = ChnMix[j]; + CHANNELINDEX n = ChnMix[j]; ChnMix[j] = ChnMix[j+1]; ChnMix[j+1] = n; j++; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-05 13:07:19
|
Revision: 2304 http://sourceforge.net/p/modplug/code/2304 Author: manxorist Date: 2013-06-05 13:07:13 +0000 (Wed, 05 Jun 2013) Log Message: ----------- [Fix] Fix uninitialized memory read in ModSequenceSet when contructing a CSoundFile (found with valgrind). [Fix] Do not read past destination buffer in WriteTest in TestStringIO (found with valgrind). [Ref] Log test suite progress to std::cout instead of std::cerr for libopenmpt. Modified Paths: -------------- trunk/OpenMPT/soundlib/ModSequence.cpp trunk/OpenMPT/test/test.cpp Modified: trunk/OpenMPT/soundlib/ModSequence.cpp =================================================================== --- trunk/OpenMPT/soundlib/ModSequence.cpp 2013-06-03 22:02:59 UTC (rev 2303) +++ trunk/OpenMPT/soundlib/ModSequence.cpp 2013-06-05 13:07:13 UTC (rev 2304) @@ -375,6 +375,7 @@ m_nCurrentSeq(0) //-------------------------------------------------------------- { + std::fill(m_Cache, m_Cache + s_nCacheSize, GetInvalidPatIndex(MOD_TYPE_MPT)); m_Sequences.push_back(ModSequence(sndFile, s_nCacheSize)); } Modified: trunk/OpenMPT/test/test.cpp =================================================================== --- trunk/OpenMPT/test/test.cpp 2013-06-03 22:02:59 UTC (rev 2303) +++ trunk/OpenMPT/test/test.cpp 2013-06-05 13:07:13 UTC (rev 2304) @@ -68,6 +68,8 @@ #ifdef MODPLUG_TRACKER #define MULTI_TEST_TRY try { +#define MULTI_TEST_START +#define MULTI_TEST_END #define MULTI_TEST_CATCH } catch ( std::exception & e) { \ Reporting::Error((std::string() + "Test \"" + func_description + "\" threw an exception, message: " + e.what()).c_str(), (std::string() + "Test \"" + func_description + "\": Exception was thrown").c_str()); \ } catch ( ... ) { \ @@ -75,9 +77,10 @@ } #define TEST_TRY { #define TEST_CATCH } -#define TEST_OK() do{UNREFERENCED_PARAMETER(ok_description);}while(0) +#define TEST_OK() do{UNREFERENCED_PARAMETER(test_description);}while(0) #define TEST_FAIL() Reporting::Error(mpt::String::Format("File: %s\nLine: " STRINGIZE(__LINE__) "\n\n" "%s", THIS_FILE, fail_description).c_str(), "VERIFY_EQUAL failed") #define TEST_FAIL_STOP() throw std::runtime_error(mpt::String::Format("File: %s\nLine: " STRINGIZE(__LINE__) "\n\n %s", THIS_FILE, fail_description)) +#define TEST_START() do{}while(0) #else // !MODPLUG_TRACKER @@ -86,31 +89,34 @@ return mpt::String::Replace(mpt::String::Replace(str, "\n", " "), "\r", " "); } +static void show_start(const char * const file, const int line, const char * const description) +{ + std::cout << "Test: " << file << "(" << line << "): " << remove_newlines(description) << ": "; +} + +static void show_ok(const char * const file, const int line, const char * const description) +{ + UNREFERENCED_PARAMETER(file); + UNREFERENCED_PARAMETER(line); + UNREFERENCED_PARAMETER(description); + std::cout << "PASS" << std::endl; +} + static void show_fail(const char * const file, const int line, const char * const description, bool exception = false, const char * const exception_text = nullptr) { + std::cout << "FAIL" << std::endl; if(!exception) { - std::cerr << "FAIL: " << file << "(" << line << ") : " << remove_newlines(description) << std::endl; + std::cerr << "FAIL: " << file << "(" << line << "): " << remove_newlines(description) << std::endl; } else if(!exception_text || (exception_text && std::string(exception_text).empty())) { - std::cerr << "FAIL: " << file << "(" << line << ") : " << remove_newlines(description) << " EXCEPTION!" << std::endl; + std::cerr << "FAIL: " << file << "(" << line << "): " << remove_newlines(description) << " EXCEPTION!" << std::endl; } else { - std::cerr << "FAIL: " << file << "(" << line << ") : " << remove_newlines(description) << " EXCEPTION: " << exception_text << std::endl; + std::cerr << "FAIL: " << file << "(" << line << "): " << remove_newlines(description) << " EXCEPTION: " << exception_text << std::endl; } } -static void show_ok(const char * const file, const int line, const char * const description) -{ -#if 1 - std::cerr << "OK: " << file << "(" << line << ") : " << remove_newlines(description) << std::endl; -#else - UNREFERENCED_PARAMETER(file); - UNREFERENCED_PARAMETER(line); - UNREFERENCED_PARAMETER(description); -#endif -} - static int fail_count = 0; static void ReportException(const char * const file, const int line, const char * const description) @@ -131,9 +137,12 @@ #define MULTI_TEST_TRY try { \ fail_count = 0; +#define MULTI_TEST_START show_start(THIS_FILE, __LINE__, func_description); std::cout << "..." << std::endl; +#define MULTI_TEST_END show_start(THIS_FILE, __LINE__, func_description); #define MULTI_TEST_CATCH if(fail_count > 0) { \ throw std::runtime_error("Test failed."); \ } \ + show_ok(THIS_FILE, __LINE__, func_description); \ } catch ( ... ) { \ ReportException(THIS_FILE, __LINE__, func_description); \ } @@ -142,7 +151,8 @@ ReportException(THIS_FILE, __LINE__, fail_description); \ throw; \ } -#define TEST_OK() show_ok(THIS_FILE, __LINE__, ok_description) +#define TEST_START() show_start(THIS_FILE, __LINE__, test_description) +#define TEST_OK() show_ok(THIS_FILE, __LINE__, test_description) #define TEST_FAIL() do { show_fail(THIS_FILE, __LINE__, fail_description); fail_count++; } while(0) #define TEST_FAIL_STOP() do { show_fail(THIS_FILE, __LINE__, fail_description); fail_count++; throw std::runtime_error("Test failed."); } while(0) @@ -155,9 +165,10 @@ //The macro is active in both 'debug' and 'release' build. #define VERIFY_EQUAL(x,y) \ do{ \ - const char * const ok_description = #x " == " #y ; \ + const char * const test_description = #x " == " #y ; \ const char * const fail_description = "VERIFY_EQUAL failed when comparing\n" #x "\nand\n" #y ; \ TEST_TRY \ + TEST_START(); \ if((x) != (y)) \ { \ TEST_FAIL(); \ @@ -172,9 +183,10 @@ // Like VERIFY_EQUAL, but throws exception if comparison fails. #define VERIFY_EQUAL_NONCONT(x,y) \ do{ \ - const char * const ok_description = #x " == " #y ; \ + const char * const test_description = #x " == " #y ; \ const char * const fail_description = "VERIFY_EQUAL failed when comparing\n" #x "\nand\n" #y ; \ TEST_TRY \ + TEST_START(); \ if((x) != (y)) \ { \ TEST_FAIL_STOP(); \ @@ -203,7 +215,9 @@ do{ \ const char * func_description = #func ; \ MULTI_TEST_TRY \ + MULTI_TEST_START \ func(); \ + MULTI_TEST_END \ MULTI_TEST_CATCH \ }while(0) @@ -1414,7 +1428,7 @@ #define WriteTest(mode, dst, src, expectedResult) \ mpt::String::Write<mpt::String:: mode >(dst, src); \ VERIFY_EQUAL_NONCONT(strncmp(dst, expectedResult, CountOf(dst)), 0); /* Ensure that the strings are identical */ \ - for(size_t i = strlen(dst); i < CountOf(dst); i++) \ + for(size_t i = mpt::strnlen(dst, CountOf(dst)); i < CountOf(dst); i++) \ VERIFY_EQUAL_NONCONT(dst[i], '\0'); /* Ensure that rest of the buffer is completely nulled */ // Check reading of null-terminated string into larger buffer @@ -1537,7 +1551,7 @@ #define WriteTest(mode, dst, src, expectedResult) \ mpt::String::Write<mpt::String:: mode >(dst, src); \ VERIFY_EQUAL_NONCONT(strncmp(dst, expectedResult, CountOf(dst)), 0); /* Ensure that the strings are identical */ \ - for(size_t i = strlen(dst); i < CountOf(dst); i++) \ + for(size_t i = mpt::strnlen(dst, CountOf(dst)); i < CountOf(dst); i++) \ VERIFY_EQUAL_NONCONT(dst[i], '\0'); /* Ensure that rest of the buffer is completely nulled */ // Check reading of null-terminated string into std::string This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-05 21:34:30
|
Revision: 2306 http://sourceforge.net/p/modplug/code/2306 Author: manxorist Date: 2013-06-05 21:34:21 +0000 (Wed, 05 Jun 2013) Log Message: ----------- [New] Support output directly to flac (via libflac++) and other pcm file formats (via libsndfile) in openmpt123. [Ref] Support building openmpt123 without portaudio on unix. [Ref] Rename volume ramping parameters in libopenmpt interface. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt.h trunk/OpenMPT/libopenmpt/libopenmpt.hpp trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/libopenmpt/libopenmpt_winamp.cpp trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp trunk/OpenMPT/openmpt123/Makefile trunk/OpenMPT/openmpt123/openmpt123.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt.h =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.h 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/libopenmpt/libopenmpt.h 2013-06-05 21:34:21 UTC (rev 2306) @@ -64,14 +64,14 @@ LIBOPENMPT_API void openmpt_module_destroy( openmpt_module * mod ); -#define OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL 1 -#define OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT 2 -#define OPENMPT_MODULE_RENDER_REPEATCOUNT 3 -#define OPENMPT_MODULE_RENDER_QUALITY_PERCENT 4 -#define OPENMPT_MODULE_RENDER_MAXMIXCHANNELS 5 -#define OPENMPT_MODULE_RENDER_INTERPOLATION_MODE 6 -#define OPENMPT_MODULE_RENDER_VOLUMERAMP_IN_MICROSECONDS 7 -#define OPENMPT_MODULE_RENDER_VOLUMERAMP_OUT_MICROSECONDS 8 +#define OPENMPT_MODULE_RENDER_MASTERGAIN_MILLIBEL 1 +#define OPENMPT_MODULE_RENDER_STEREOSEPARATION_PERCENT 2 +#define OPENMPT_MODULE_RENDER_REPEATCOUNT 3 +#define OPENMPT_MODULE_RENDER_QUALITY_PERCENT 4 +#define OPENMPT_MODULE_RENDER_MAXMIXCHANNELS 5 +#define OPENMPT_MODULE_RENDER_INTERPOLATION_MODE 6 +#define OPENMPT_MODULE_RENDER_VOLUMERAMP_UP_MICROSECONDS 7 +#define OPENMPT_MODULE_RENDER_VOLUMERAMP_DOWN_MICROSECONDS 8 #define OPENMPT_MODULE_RENDER_INTERPOLATION_NEAREST 1 #define OPENMPT_MODULE_RENDER_INTERPOLATION_LINEAR 2 Modified: trunk/OpenMPT/libopenmpt/libopenmpt.hpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt.hpp 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/libopenmpt/libopenmpt.hpp 2013-06-05 21:34:21 UTC (rev 2306) @@ -77,14 +77,14 @@ public: enum render_param { - RENDER_MASTERGAIN_MILLIBEL = 1, - RENDER_STEREOSEPARATION_PERCENT = 2, - RENDER_REPEATCOUNT = 3, - RENDER_QUALITY_PERCENT = 4, - RENDER_MAXMIXCHANNELS = 5, - RENDER_INTERPOLATION_MODE = 6, - RENDER_VOLUMERAMP_IN_MICROSECONDS = 7, - RENDER_VOLUMERAMP_OUT_MICROSECONDS = 8 + RENDER_MASTERGAIN_MILLIBEL = 1, + RENDER_STEREOSEPARATION_PERCENT = 2, + RENDER_REPEATCOUNT = 3, + RENDER_QUALITY_PERCENT = 4, + RENDER_MAXMIXCHANNELS = 5, + RENDER_INTERPOLATION_MODE = 6, + RENDER_VOLUMERAMP_UP_MICROSECONDS = 7, + RENDER_VOLUMERAMP_DOWN_MICROSECONDS = 8 }; enum interpolation_mode { Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-05 21:34:21 UTC (rev 2306) @@ -319,10 +319,10 @@ } throw openmpt::exception_message("unknown interpolation mode set internally"); } break; - case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { + case module::RENDER_VOLUMERAMP_UP_MICROSECONDS: { return m_sndFile->m_MixerSettings.GetVolumeRampUpMicroseconds(); } break; - case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { + case module::RENDER_VOLUMERAMP_DOWN_MICROSECONDS: { return m_sndFile->m_MixerSettings.GetVolumeRampDownMicroseconds(); } break; default: throw openmpt::exception_message("unknown command"); break; @@ -380,14 +380,14 @@ m_sndFile->SetResamplerSettings( newsettings ); } } break; - case module::RENDER_VOLUMERAMP_IN_MICROSECONDS: { + case module::RENDER_VOLUMERAMP_UP_MICROSECONDS: { MixerSettings newsettings = m_sndFile->m_MixerSettings; newsettings.SetVolumeRampUpMicroseconds( value ); if ( m_sndFile->m_MixerSettings.glVolumeRampUpSamples != newsettings.glVolumeRampUpSamples ) { m_sndFile->SetMixerSettings( newsettings ); } } break; - case module::RENDER_VOLUMERAMP_OUT_MICROSECONDS: { + case module::RENDER_VOLUMERAMP_DOWN_MICROSECONDS: { MixerSettings newsettings = m_sndFile->m_MixerSettings; newsettings.SetVolumeRampDownMicroseconds( value ); if ( m_sndFile->m_MixerSettings.glVolumeRampDownSamples != newsettings.glVolumeRampDownSamples ) { Modified: trunk/OpenMPT/libopenmpt/libopenmpt_winamp.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_winamp.cpp 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/libopenmpt/libopenmpt_winamp.cpp 2013-06-05 21:34:21 UTC (rev 2306) @@ -113,8 +113,8 @@ self->mod->set_render_param( openmpt::module::RENDER_REPEATCOUNT, self->settings->repeatcount ); self->mod->set_render_param( openmpt::module::RENDER_MAXMIXCHANNELS, self->settings->maxmixchannels ); self->mod->set_render_param( openmpt::module::RENDER_INTERPOLATION_MODE, self->settings->interpolationmode ); - self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_IN_MICROSECONDS, self->settings->volrampinus ); - self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_OUT_MICROSECONDS, self->settings->volrampoutus ); + self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_UP_MICROSECONDS, self->settings->volrampinus ); + self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_DOWN_MICROSECONDS, self->settings->volrampoutus ); } self->settings->save(); } Modified: trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/libopenmpt/libopenmpt_xmplay.cpp 2013-06-05 21:34:21 UTC (rev 2306) @@ -97,8 +97,8 @@ self->mod->set_render_param( openmpt::module::RENDER_REPEATCOUNT, self->settings->repeatcount ); self->mod->set_render_param( openmpt::module::RENDER_MAXMIXCHANNELS, self->settings->maxmixchannels ); self->mod->set_render_param( openmpt::module::RENDER_INTERPOLATION_MODE, self->settings->interpolationmode ); - self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_IN_MICROSECONDS, self->settings->volrampinus ); - self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_OUT_MICROSECONDS, self->settings->volrampoutus ); + self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_UP_MICROSECONDS, self->settings->volrampinus ); + self->mod->set_render_param( openmpt::module::RENDER_VOLUMERAMP_DOWN_MICROSECONDS, self->settings->volrampoutus ); } self->settings->save(); } Modified: trunk/OpenMPT/openmpt123/Makefile =================================================================== --- trunk/OpenMPT/openmpt123/Makefile 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/openmpt123/Makefile 2013-06-05 21:34:21 UTC (rev 2306) @@ -57,18 +57,42 @@ #CXXFLAGS += -mtune=generic #CFLAGS += -mtune=generic +#LDLIBS += -lz +ifeq ($(shell pkg-config --exists zlib && echo yes),yes) +CPPFLAGS += -DMPT_WITH_ZLIB CPPFLAGS += $(shell pkg-config --cflags-only-I zlib ) LDFLAGS += $(shell pkg-config --libs-only-other zlib ) LDFLAGS += $(shell pkg-config --libs-only-L zlib ) LDLIBS += $(shell pkg-config --libs-only-l zlib ) -#LDLIBS += -lz +endif +#LDLIBS += -lportaudio +ifeq ($(shell pkg-config --exists portaudio-2.0 && echo yes),yes) +CPPFLAGS += -DMPT_WITH_PORTAUDIO CPPFLAGS += $(shell pkg-config --cflags-only-I portaudio-2.0 ) LDFLAGS += $(shell pkg-config --libs-only-other portaudio-2.0 ) LDFLAGS += $(shell pkg-config --libs-only-L portaudio-2.0 ) LDLIBS += $(shell pkg-config --libs-only-l portaudio-2.0 ) -#LDLIBS += -lportaudio +endif +#LDLIBS += -lFLAC++ -lFLAC +ifeq ($(shell pkg-config --exists flac++ flac && echo yes),yes) +CPPFLAGS += -DMPT_WITH_FLAC +CPPFLAGS += $(shell pkg-config --cflags-only-I flac++ flac ) +LDFLAGS += $(shell pkg-config --libs-only-other flac++ flac ) +LDFLAGS += $(shell pkg-config --libs-only-L flac++ flac ) +LDLIBS += $(shell pkg-config --libs-only-l flac++ flac ) +endif + +#LDLIBS += -lsndfile +ifeq ($(shell pkg-config --exists sndfile && echo yes),yes) +CPPFLAGS += -DMPT_WITH_SNDFILE +CPPFLAGS += $(shell pkg-config --cflags-only-I sndfile ) +LDFLAGS += $(shell pkg-config --libs-only-other sndfile ) +LDFLAGS += $(shell pkg-config --libs-only-L sndfile ) +LDLIBS += $(shell pkg-config --libs-only-l sndfile ) +endif + %: %.o $(INFO) [LD ] $@ $(SILENT)$(LINK.cc) $^ $(LOADLIBES) $(LDLIBS) -o $@ Modified: trunk/OpenMPT/openmpt123/openmpt123.cpp =================================================================== --- trunk/OpenMPT/openmpt123/openmpt123.cpp 2013-06-05 13:10:52 UTC (rev 2305) +++ trunk/OpenMPT/openmpt123/openmpt123.cpp 2013-06-05 21:34:21 UTC (rev 2306) @@ -9,6 +9,11 @@ #define LIBOPENMPT_ALPHA_WARNING_SEEN_AND_I_KNOW_WHAT_I_AM_DOING +#if defined(_MSC_VER) +#define MPT_WITH_PORTAUDIO +#define MPT_WITH_ZLIB +#endif + #define OPENMPT123_VERSION_STRING "0.1" #include <algorithm> @@ -20,6 +25,7 @@ #include <string> #include <vector> +#include <cmath> #include <cstdint> #include <cstring> @@ -33,7 +39,19 @@ #include <libopenmpt/libopenmpt.hpp> +#ifdef MPT_WITH_FLAC +#include <FLAC++/encoder.h> +#include <FLAC/metadata.h> +#include <FLAC/format.h> +#endif + +#ifdef MPT_WITH_SNDFILE +#include <sndfile.h> +#endif + +#ifdef MPT_WITH_PORTAUDIO #include <portaudio.h> +#endif struct show_help_exception { std::string message; @@ -57,22 +75,26 @@ show_version_number_exception() throw() { } }; +#ifdef MPT_WITH_PORTAUDIO struct portaudio_exception : public openmpt123_exception { portaudio_exception( PaError code ) throw() : openmpt123_exception( Pa_GetErrorText( code ) ) { } }; +#endif struct openmpt123_flags { bool run_tests; bool modplug123; +#ifdef MPT_WITH_PORTAUDIO int device; +#endif std::int32_t channels; std::int32_t buffer; std::int32_t repeatcount; std::int32_t samplerate; std::int32_t gain; std::int32_t quality; - std::int32_t rampinus; - std::int32_t rampoutus; + std::int32_t rampupus; + std::int32_t rampdownus; bool quiet; bool verbose; bool show_message; @@ -81,18 +103,24 @@ bool use_float; bool use_stdout; std::vector<std::string> filenames; +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + std::string output_filename; + bool force_overwrite; +#endif openmpt123_flags() { run_tests = false; modplug123 = false; +#ifdef MPT_WITH_PORTAUDIO device = -1; +#endif channels = 2; buffer = 250; repeatcount = 0; samplerate = 48000; gain = 0; quality = 100; - rampinus = ( 16 * 1000000 + ( 44100 / 2 ) ) / 44100; // openmpt defaults at 44KHz, rounded - rampoutus = ( 42 * 1000000 + ( 44100 / 2 ) ) / 44100; // openmpt defaults at 44KHz, rounded + rampupus = ( 16 * 1000000 + ( 44100 / 2 ) ) / 44100; // openmpt defaults at 44KHz, rounded + rampdownus = ( 42 * 1000000 + ( 44100 / 2 ) ) / 44100; // openmpt defaults at 44KHz, rounded quiet = false; verbose = false; show_message = false; @@ -100,11 +128,22 @@ seek_target = 0.0; use_float = false; use_stdout = false; +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + force_overwrite = false; +#endif } void check_and_sanitize() { if ( filenames.size() == 0 ) { throw show_help_exception(); } +#if defined(MPT_WITH_PORTAUDIO) && ( defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) ) + if ( use_stdout && ( device != openmpt123_flags().device || !output_filename.empty() ) ) { + throw show_help_exception(); + } + if ( !output_filename.empty() && ( device != openmpt123_flags().device || use_stdout ) ) { + throw show_help_exception(); + } +#endif if ( quiet ) { verbose = false; show_progress = false; @@ -123,7 +162,9 @@ s << "Verbose: " << flags.verbose << std::endl; s << "Show message: " << flags.show_message << std::endl; s << "Show progress: " << flags.show_progress << std::endl; +#ifdef MPT_WITH_PORTAUDIO s << "Device: " << flags.device << std::endl; +#endif s << "Channels: " << flags.channels << std::endl; s << "Buffer: " << flags.buffer << std::endl; s << "Repeat count: " << flags.repeatcount << std::endl; @@ -133,6 +174,10 @@ s << "Seek target: " << flags.seek_target << std::endl; s << "Float: " << flags.use_float << std::endl; s << "Standard output: " << flags.use_stdout << std::endl; +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + s << "Output filename: " << flags.output_filename << std::endl; + s << "Force overwrite output file: " << flags.force_overwrite << std::endl; +#endif s << std::endl; s << "Files: " << std::endl; for ( std::vector<std::string>::const_iterator filename = flags.filenames.begin(); filename != flags.filenames.end(); ++filename ) { @@ -175,6 +220,32 @@ return str.str(); } +static std::string append_software_tag( std::string software ) { + std::string openmpt123 = std::string() + "openmpt123 " + OPENMPT123_VERSION_STRING + ", libopenmpt " + openmpt::string::get( openmpt::string::library_version ) + ", OpenMPT " + openmpt::string::get( openmpt::string::core_version ); + if ( software.empty() ) { + software = openmpt123; + } else { + software += " (" + openmpt123 + ")"; + } + return software; +} + +class write_buffers_interface { +public: + virtual void write_metadata( const openmpt::module & mod ) { + (void)mod; + return; + } + virtual void write_updated_metadata( const openmpt::module & mod ) { + (void)mod; + return; + } + virtual void write( const std::vector<float*> buffers, std::size_t frames ) = 0; + virtual void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) = 0; +}; + +#ifdef MPT_WITH_PORTAUDIO + typedef void (*PaUtilLogCallback ) (const char *log); #ifdef _MSC_VER extern "C" void PaUtil_SetDebugPrintFunction(PaUtilLogCallback cb); @@ -236,12 +307,6 @@ std::ostream * portaudio_raii::portaudio_log_stream = 0; -class write_buffers_interface { -public: - virtual void write( const std::vector<float*> buffers, std::size_t frames ) = 0; - virtual void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) = 0; -}; - class portaudio_stream_raii : public portaudio_raii, public write_buffers_interface { private: PaStream * stream; @@ -292,6 +357,279 @@ } }; +#endif + +static float mpt_round( float val ) { + if ( val >= 0.0f ) { + return std::floor( val + 0.5f ); + } else { + return std::ceil( val - 0.5f ); + } +} + +static long mpt_lround( float val ) { + return static_cast< long >( mpt_round( val ) ); +} + +#ifdef MPT_WITH_FLAC + +class flac_stream_raii : public write_buffers_interface { +private: + openmpt123_flags flags; + bool called_init; + std::vector< std::pair< std::string, std::string > > tags; + FLAC__StreamMetadata * metadata[1]; + FLAC__StreamMetadata_VorbisComment_Entry entry; + FLAC::Encoder::File encoder; + std::vector<FLAC__int32> interleaved_buffer; + void add_vorbiscomment_field( FLAC__StreamMetadata * vorbiscomment, const std::string & field, const std::string & value ) { + if ( !value.empty() ) { + FLAC__metadata_object_vorbiscomment_entry_from_name_value_pair( &entry, field.c_str(), value.c_str() ); + FLAC__metadata_object_vorbiscomment_append_comment( vorbiscomment, entry, true ); + } + } +public: + flac_stream_raii( const openmpt123_flags & flags_ ) : flags(flags_), called_init(false) { + metadata[0] = 0; + encoder.set_channels( flags.channels ); + encoder.set_bits_per_sample( flags.use_float ? 24 : 16 ); + encoder.set_sample_rate( flags.samplerate ); + encoder.set_compression_level( 8 ); + } + ~flac_stream_raii() { + encoder.finish(); + FLAC__metadata_object_delete( metadata[0] ); + } + void write_metadata( const openmpt::module & mod ) { + if ( called_init ) { + return; + } + tags.clear(); + tags.push_back( std::make_pair<std::string, std::string>( "TITLE", mod.get_metadata( "title" ) ) ); + tags.push_back( std::make_pair<std::string, std::string>( "ARTIST", mod.get_metadata( "author" ) ) ); + tags.push_back( std::make_pair<std::string, std::string>( "COMMENTS", mod.get_metadata( "message" ) ) ); + tags.push_back( std::make_pair<std::string, std::string>( "ENCODING", append_software_tag( mod.get_metadata( "tracker" ) ) ) ); + metadata[0] = FLAC__metadata_object_new( FLAC__METADATA_TYPE_VORBIS_COMMENT ); + for ( std::vector< std::pair< std::string, std::string > >::iterator tag = tags.begin(); tag != tags.end(); ++tag ) { + add_vorbiscomment_field( metadata[0], tag->first, tag->second ); + } + encoder.set_metadata( metadata, 1 ); + } + void write( const std::vector<float*> buffers, std::size_t frames ) { + if ( !called_init ) { + encoder.init( flags.output_filename ); + called_init = true; + } + interleaved_buffer.clear(); + for ( std::size_t frame = 0; frame < frames; frame++ ) { + for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) { + float in = buffers[channel][frame]; + if ( in <= -1.0f ) { + in = -1.0f; + } else if ( in >= 1.0f ) { + in = 1.0f; + } + FLAC__int32 out = mpt_lround( in * (1<<23) ); + out = std::max( 0 - (1<<23), out ); + out = std::min( out, 0 + (1<<23) - 1 ); + interleaved_buffer.push_back( out ); + } + } + encoder.process_interleaved( interleaved_buffer.data(), frames ); + } + void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) { + if ( !called_init ) { + encoder.init( flags.output_filename ); + called_init = true; + } + interleaved_buffer.clear(); + for ( std::size_t frame = 0; frame < frames; frame++ ) { + for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) { + interleaved_buffer.push_back( buffers[channel][frame] ); + } + } + encoder.process_interleaved( interleaved_buffer.data(), frames ); + } +}; + +#endif + +static std::string get_extension( std::string filename ) { + if ( filename.find_last_of( "." ) != std::string::npos ) { + return filename.substr( filename.find_last_of( "." ) + 1 ); + } + return ""; +} + +#ifdef MPT_WITH_SNDFILE + +class sndfile_stream_raii : public write_buffers_interface { +private: + openmpt123_flags flags; + std::ostream & log; + SNDFILE * sndfile; + std::vector<float> interleaved_float_buffer; + std::vector<std::int16_t> interleaved_int_buffer; +private: + enum match_mode_enum { + match_print, + match_recurse, + match_exact, + match_better, + match_any + }; + int matched_result( const SF_FORMAT_INFO & format_info, const SF_FORMAT_INFO & subformat_info ) { + if ( flags.verbose ) { + log << "sndfile: using format '" + << format_info.name << " (" << format_info.extension << ")" << " / " << subformat_info.name + << "'" + << std::endl; + } + return ( format_info.format & SF_FORMAT_TYPEMASK ) | subformat_info.format; + } + int find_format( std::string extension, match_mode_enum match_mode ) { + + if ( match_mode == match_recurse ) { + int result = 0; + result = find_format( extension, match_exact ); + if ( result ) { + return result; + } + result = find_format( extension, match_better ); + if ( result ) { + return result; + } + result = find_format( extension, match_any ); + if ( result ) { + return result; + } + if ( result ) { + return result; + } + return 0; + } + + int format = 0; + int major_count; + sf_command( 0, SFC_GET_FORMAT_MAJOR_COUNT, &major_count, sizeof( int ) ); + for ( int m = 0; m < major_count; m++ ) { + + SF_FORMAT_INFO format_info; + format_info.format = m; + sf_command( 0, SFC_GET_FORMAT_MAJOR, &format_info, sizeof( SF_FORMAT_INFO ) ); + format = format_info.format; + + int subtype_count; + sf_command( 0, SFC_GET_FORMAT_SUBTYPE_COUNT, &subtype_count, sizeof( int ) ); + for ( int s = 0; s < subtype_count; s++ ) { + + SF_FORMAT_INFO subformat_info; + subformat_info.format = s; + sf_command( 0, SFC_GET_FORMAT_SUBTYPE, &subformat_info, sizeof( SF_FORMAT_INFO ) ); + format = ( format & SF_FORMAT_TYPEMASK ) | subformat_info.format; + + SF_INFO sfinfo; + std::memset( &sfinfo, 0, sizeof( SF_INFO ) ); + sfinfo.channels = flags.channels; + sfinfo.format = format; + if ( sf_format_check( &sfinfo ) ) { + + switch ( match_mode ) { + case match_print: + log << "sndfile: " + << ( format_info.name ? format_info.name : "" ) << " (" << ( format_info.extension ? format_info.extension : "" ) << ")" + << " / " + << ( subformat_info.name ? subformat_info.name : "" ) + << std::endl; + break; + case match_recurse: + break; + case match_exact: + if ( extension == format_info.extension ) { + if ( flags.use_float && ( format_info.format & SF_FORMAT_FLOAT ) ) { + return matched_result( format_info, subformat_info ); + } else if ( !flags.use_float && ( format_info.format & SF_FORMAT_PCM_16 ) ) { + return matched_result( format_info, subformat_info ); + } + } + break; + case match_better: + if ( extension == format_info.extension ) { + if ( flags.use_float && ( format_info.format & ( SF_FORMAT_FLOAT | SF_FORMAT_DOUBLE ) ) ) { + return matched_result( format_info, subformat_info ); + } else if ( !flags.use_float && ( format_info.format & ( SF_FORMAT_PCM_16 | SF_FORMAT_PCM_24 | SF_FORMAT_PCM_32 ) ) ) { + return matched_result( format_info, subformat_info ); + } + } + break; + case match_any: + if ( extension == format_info.extension ) { + return matched_result( format_info, subformat_info ); + } + break; + } + + } + } + } + + return 0; + + } + void write_metadata_field( int str_type, const std::string & str ) { + if ( !str.empty() ) { + sf_set_string( sndfile, str_type, str.c_str() ); + } + } +public: + sndfile_stream_raii( const openmpt123_flags & flags_, std::ostream & log_ = std::cerr ) : flags(flags_), log(log_),sndfile(0) { + if ( flags.verbose ) { + find_format( "", match_print ); + log << std::endl; + } + int format = find_format( get_extension( flags.output_filename ), match_recurse ); + if ( !format ) { + throw openmpt123_exception( "unknown file type" ); + } + SF_INFO info; + std::memset( &info, 0, sizeof( SF_INFO ) ); + info.samplerate = flags.samplerate; + info.channels = flags.channels; + info.format = format; + sndfile = sf_open( flags.output_filename.c_str(), SFM_WRITE, &info ); + } + ~sndfile_stream_raii() { + sf_close( sndfile ); + sndfile = 0; + } + void write_metadata( const openmpt::module & mod ) { + write_metadata_field( SF_STR_TITLE, mod.get_metadata( "title" ) ); + write_metadata_field( SF_STR_ARTIST, mod.get_metadata( "author" ) ); + write_metadata_field( SF_STR_COMMENT, mod.get_metadata( "message" ) ); + write_metadata_field( SF_STR_SOFTWARE, append_software_tag( mod.get_metadata( "tracker" ) ) ); + } + void write( const std::vector<float*> buffers, std::size_t frames ) { + interleaved_float_buffer.clear(); + for ( std::size_t frame = 0; frame < frames; frame++ ) { + for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) { + interleaved_float_buffer.push_back( buffers[channel][frame] ); + } + } + sf_writef_float( sndfile, interleaved_float_buffer.data(), frames ); + } + void write( const std::vector<std::int16_t*> buffers, std::size_t frames ) { + interleaved_int_buffer.clear(); + for ( std::size_t frame = 0; frame < frames; frame++ ) { + for ( std::size_t channel = 0; channel < buffers.size(); channel++ ) { + interleaved_int_buffer.push_back( buffers[channel][frame] ); + } + } + sf_writef_short( sndfile, interleaved_int_buffer.data(), frames ); + } +}; + +#endif + class stdout_stream_raii : public write_buffers_interface { private: std::vector<float> interleaved_float_buffer; @@ -326,9 +664,19 @@ static void show_info( std::ostream & log, bool modplug123 = false ) { log << ( modplug123 ? "modplug123 emulated by " : "" ) << "openmpt123" << " version " << OPENMPT123_VERSION_STRING << std::endl; log << " Copyright (c) 2013 OpenMPT developers (http://openmpt.org/)" << std::endl; - log << " libopenmpt version " << openmpt::string::get( openmpt::string::library_version ) << " " << "(built " << openmpt::string::get( openmpt::string::build ) << ")" << std::endl; - log << " OpenMPT version " << openmpt::string::get( openmpt::string::core_version ) << std::endl; + log << " libopenmpt " << openmpt::string::get( openmpt::string::library_version ) << " " << "(built " << openmpt::string::get( openmpt::string::build ) << ")" << std::endl; + log << " OpenMPT " << openmpt::string::get( openmpt::string::core_version ) << std::endl; +#ifdef MPT_WITH_PORTAUDIO log << " " << Pa_GetVersionText() << " (http://portaudio.com/)" << std::endl; +#endif +#ifdef MPT_WITH_FLAC + log << " FLAC " << FLAC__VERSION_STRING << ", " << FLAC__VENDOR_STRING << ", API " << FLAC_API_VERSION_CURRENT << "." << FLAC_API_VERSION_REVISION << "." << FLAC_API_VERSION_AGE << " (https://xiph.org/flac/)" << std::endl; +#endif +#ifdef MPT_WITH_SNDFILE + char sndfile_info[128]; + sf_command( 0, SFC_GET_LIB_VERSION, sndfile_info, sizeof( sndfile_info ) ); + log << " libsndfile " << sndfile_info << " (http://mega-nerd.com/libsndfile/)" << std::endl; +#endif log << std::endl; } @@ -357,7 +705,9 @@ return; } std::clog << " -l Loop song [default: " << openmpt123_flags().repeatcount << "]" << std::endl; +#ifdef MPT_WITH_PORTAUDIO std::clog << " -ao n Set output device [default: " << openmpt123_flags().device << "]," << std::endl; +#endif std::clog << " use -ao help to show available devices" << std::endl; } else { std::clog << "Usage: openmpt123 [options] [--] file1 [file2] ..." << std::endl; @@ -372,8 +722,15 @@ } std::clog << " --[no-]message Show song message [default: " << openmpt123_flags().show_message << "]" << std::endl; std::clog << " --[no-]progress Show playback progress [default: " << openmpt123_flags().show_progress << "]" << std::endl; +#ifdef MPT_WITH_PORTAUDIO std::clog << " --device n Set output device [default: " << get_device_string( openmpt123_flags().device ) << "]," << std::endl; std::clog << " use --device help to show available devices" << std::endl; +#endif + std::clog << " --stdout Write raw audio data to stdout [default: " << openmpt123_flags().use_stdout << "]" << std::endl; +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + std::clog << " -o, --output f Write FLAC flac output instead of streaming to audio device [default: " << openmpt123_flags().output_filename << "]" << std::endl; + std::clog << " --force Force overwriting of output file [default: " << openmpt123_flags().force_overwrite << "]" << std::endl; +#endif std::clog << " --channels n use n [1,2,4] output channels [default: " << openmpt123_flags().channels << "]" << std::endl; std::clog << " --[no]-float Output 32bit floating point instead of 16bit integer [default: " << openmpt123_flags().use_float << "]" << std::endl; std::clog << " --buffer n Set output buffer size to n ms [default: " << openmpt123_flags().buffer << "]," << std::endl; @@ -382,8 +739,8 @@ std::clog << " --repeat n Repeat song n times (-1 means forever) [default: " << openmpt123_flags().repeatcount << "]" << std::endl; std::clog << " --quality n Set rendering quality to n % [default: " << openmpt123_flags().quality << "]" << std::endl; std::clog << " --seek n Seek to n seconds on start [default: " << openmpt123_flags().seek_target << "]" << std::endl; - std::clog << " --volrampin n Use n microseconds volume ramping on sample begin [default: " << openmpt123_flags().rampinus << "]" << std::endl; - std::clog << " --volrampout n Use n microseconds volume ramping on sample end [default: " << openmpt123_flags().rampoutus << "]" << std::endl; + std::clog << " --volrampup n Use n microseconds volume ramping up [default: " << openmpt123_flags().rampupus << "]" << std::endl; + std::clog << " --volrampdown n Use n microseconds volume ramping down [default: " << openmpt123_flags().rampdownus << "]" << std::endl; std::clog << std::endl; std::clog << " -- Interpret further arguments as filenames" << std::endl; std::clog << std::endl; @@ -410,6 +767,8 @@ } } +#ifdef MPT_WITH_PORTAUDIO + static void show_audio_devices() { std::ostringstream devices; devices << " Available devices:" << std::endl; @@ -424,6 +783,8 @@ throw show_help_exception( devices.str() ); } +#endif + template < typename Tsample > void render_loop( const openmpt123_flags & flags, openmpt::module & mod, double & duration, std::ostream & log, write_buffers_interface & audio_stream ) { @@ -508,6 +869,12 @@ log << "Patterns: " << mod.get_num_patterns() << std::endl; log << "Instruments: " << mod.get_num_instruments() << std::endl; log << "Samples: " << mod.get_num_samples() << std::endl; + + if ( flags.filenames.size() == 1 ) { + audio_stream.write_metadata( mod ); + } else { + audio_stream.write_updated_metadata( mod ); + } if ( flags.show_message ) { log << "Message: " << std::endl; @@ -518,8 +885,8 @@ mod.set_render_param( openmpt::module::RENDER_REPEATCOUNT, flags.repeatcount ); mod.set_render_param( openmpt::module::RENDER_QUALITY_PERCENT, flags.quality ); mod.set_render_param( openmpt::module::RENDER_MASTERGAIN_MILLIBEL, flags.gain ); - mod.set_render_param( openmpt::module::RENDER_VOLUMERAMP_IN_MICROSECONDS, flags.rampinus ); - mod.set_render_param( openmpt::module::RENDER_VOLUMERAMP_OUT_MICROSECONDS, flags.rampoutus ); + mod.set_render_param( openmpt::module::RENDER_VOLUMERAMP_UP_MICROSECONDS, flags.rampupus ); + mod.set_render_param( openmpt::module::RENDER_VOLUMERAMP_DOWN_MICROSECONDS, flags.rampdownus ); if ( flags.seek_target > 0.0 ) { mod.seek_seconds( flags.seek_target ); @@ -571,15 +938,19 @@ } else if ( arg == "-l" ) { flags.repeatcount = -1; } else if ( arg == "-ao" && nextarg != "" ) { - if ( nextarg == "help" ) { - show_audio_devices(); + if ( false ) { + // nothing } else if ( nextarg == "stdout" ) { flags.use_stdout = true; +#ifdef MPT_WITH_PORTAUDIO + } else if ( nextarg == "help" ) { + show_audio_devices(); } else if ( nextarg == "default" ) { flags.device = -1; } else { std::istringstream istr( nextarg ); istr >> flags.device; +#endif } ++i; } @@ -625,17 +996,30 @@ } else if ( arg == "--no-progress" ) { flags.show_progress = false; } else if ( arg == "--device" && nextarg != "" ) { - if ( nextarg == "help" ) { - show_audio_devices(); + if ( false ) { + // nothing } else if ( nextarg == "stdout" ) { flags.use_stdout = true; +#ifdef MPT_WITH_PORTAUDIO + } else if ( nextarg == "help" ) { + show_audio_devices(); } else if ( nextarg == "default" ) { flags.device = -1; } else { std::istringstream istr( nextarg ); istr >> flags.device; +#endif } ++i; + } else if ( arg == "--stdout" ) { + flags.use_stdout = true; +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + } else if ( ( arg == "-o" || arg == "--output" ) && nextarg != "" ) { + flags.output_filename = nextarg; + ++i; + } else if ( arg == "--force" ) { + flags.force_overwrite = true; +#endif } else if ( arg == "--channels" && nextarg != "" ) { std::istringstream istr( nextarg ); istr >> flags.channels; @@ -670,13 +1054,13 @@ std::istringstream istr( nextarg ); istr >> flags.seek_target; ++i; - } else if ( arg == "--volrampin" && nextarg != "" ) { + } else if ( arg == "--volrampup" && nextarg != "" ) { std::istringstream istr( nextarg ); - istr >> flags.rampinus; + istr >> flags.rampupus; ++i; - } else if ( arg == "--volrampout" && nextarg != "" ) { + } else if ( arg == "--volrampdown" && nextarg != "" ) { std::istringstream istr( nextarg ); - istr >> flags.rampoutus; + istr >> flags.rampdownus; ++i; } else if ( arg == "--runtests" ) { flags.run_tests = true; @@ -791,6 +1175,35 @@ render_file( flags, *filename, log, stdout_audio_stream ); } +#if defined(MPT_WITH_FLAC) || defined(MPT_WITH_SNDFILE) + } else if ( !flags.output_filename.empty() ) { + + if ( !flags.force_overwrite ) { + std::ifstream testfile( flags.output_filename, std::ios::binary ); + if ( testfile ) { + throw openmpt123_exception( "file already exists" ); + } + } + + if ( false ) { + // nothing +#ifdef MPT_WITH_FLAC + } else if ( get_extension( flags.output_filename ) == "flac" ) { + flac_stream_raii flac_audio_stream( flags ); + for ( std::vector<std::string>::iterator filename = flags.filenames.begin(); filename != flags.filenames.end(); ++filename ) { + render_file( flags, *filename, log, flac_audio_stream ); + } +#endif +#ifdef MPT_WITH_SNDFILE + } else { + sndfile_stream_raii sndfile_audio_stream( flags, log ); + for ( std::vector<std::string>::iterator filename = flags.filenames.begin(); filename != flags.filenames.end(); ++filename ) { + render_file( flags, *filename, log, sndfile_audio_stream ); + } +#endif + } +#endif +#ifdef MPT_WITH_PORTAUDIO } else { portaudio_stream_raii portaudio_stream( flags, log ); @@ -798,7 +1211,7 @@ for ( std::vector<std::string>::iterator filename = flags.filenames.begin(); filename != flags.filenames.end(); ++filename ) { render_file( flags, *filename, log, portaudio_stream ); } - +#endif } } catch ( show_help_exception & e ) { @@ -810,8 +1223,10 @@ } catch ( show_version_number_exception & ) { show_version(); return 0; +#ifdef MPT_WITH_PORTAUDIO } catch ( portaudio_exception & e ) { std::cerr << "PortAudio error: " << e.what() << std::endl; +#endif } catch ( silent_exit_exception & ) { return 0; } catch ( std::exception & e ) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-06 05:02:32
|
Revision: 2307 http://sourceforge.net/p/modplug/code/2307 Author: manxorist Date: 2013-06-06 05:02:26 +0000 (Thu, 06 Jun 2013) Log Message: ----------- [Ref] Move knowledge and state handling of when to clear the MixReverbBuffer into CReverb. [Ref] Add comments describing reverb on/off state handling. [Ref] Call GetProcSupport() directly in CReverb::Process and avoid having to pass it around as a parameter. Modified Paths: -------------- trunk/OpenMPT/sounddsp/Reverb.cpp trunk/OpenMPT/sounddsp/Reverb.h trunk/OpenMPT/soundlib/Fastmix.cpp trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/sounddsp/Reverb.cpp =================================================================== --- trunk/OpenMPT/sounddsp/Reverb.cpp 2013-06-05 21:34:21 UTC (rev 2306) +++ trunk/OpenMPT/sounddsp/Reverb.cpp 2013-06-06 05:02:26 UTC (rev 2307) @@ -396,15 +396,42 @@ } +void CReverb::ProcessPrepare(int *MixReverbBuffer, UINT nSamples) +//--------------------------------------------------------------- +{ + gnReverbSend = 0; // no data sent yet + if(!gnReverbSamples) + { + // reverb had decayed completely, we will probably not process reverb, so no need to clear buffer + return; + } + StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); +} + + +void CReverb::ProcessWillSend(int *MixReverbBuffer, UINT nSamples) +//---------------------------------------------------------------- +{ + if(!gnReverbSend && !gnReverbSamples) + { + // reverb had decayed completely before, and we did not clear the buffer yet, do it now because we get new data + StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); + } + gnReverbSend = 1; // we will have to process reverb +} + + // Reverb -void CReverb::Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples, DWORD sysinfo) -//-------------------------------------------------------------------------------------------- +void CReverb::Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples) +//----------------------------------------------------------------------------- { UINT nIn, nOut; - if ((!gnReverbSend) && (!gnReverbSamples)) return; - if (!gnReverbSend) StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); - if (!(sysinfo & PROCSUPPORT_MMX)) return; + if((!gnReverbSend) && (!gnReverbSamples)) + { // no data is sent to reverb and reverb decayed completely + return; + } + if (!(GetProcSupport() & PROCSUPPORT_MMX)) return; // Dynamically adjust reverb master gains LONG lMasterGain; lMasterGain = ((g_RefDelay.lMasterGain * m_Settings.m_nReverbDepth) >> 4); @@ -460,11 +487,11 @@ // Upsample 2x MMX_ReverbProcessPostFiltering1x(MixReverbBuffer, MixSoundBuffer, nSamples); // Automatically shut down if needed - if (gnReverbSend) gnReverbSamples = gnReverbDecaySamples; - else if (gnReverbSamples > nSamples) gnReverbSamples -= nSamples; - else + if(gnReverbSend) gnReverbSamples = gnReverbDecaySamples; // reset decay counter + else if(gnReverbSamples > nSamples) gnReverbSamples -= nSamples; // decay + else // decayed { - if (gnReverbSamples) Shutdown(); + Shutdown(); gnReverbSamples = 0; } } Modified: trunk/OpenMPT/sounddsp/Reverb.h =================================================================== --- trunk/OpenMPT/sounddsp/Reverb.h 2013-06-05 21:34:21 UTC (rev 2306) +++ trunk/OpenMPT/sounddsp/Reverb.h 2013-06-06 05:02:26 UTC (rev 2307) @@ -126,12 +126,13 @@ CReverbSettings m_Settings; // Shared reverb state - UINT gnReverbSend; LONG gnRvbROfsVol; LONG gnRvbLOfsVol; private: + UINT gnReverbSend; + UINT gnReverbSamples; UINT gnReverbDecaySamples; @@ -153,10 +154,19 @@ public: CReverb(); - ~CReverb() {} public: void Initialize(BOOL bReset, DWORD MixingFreq); - void Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples, DWORD sysinfo); + + // call once before calling Process + void ProcessPrepare(int *MixReverbBuffer, UINT nSamples); + + // call after ProcessPrepare and before you are putting data into MixReverbBuffer, + // can be called multiple times or never (if no data is sent to reverb) + void ProcessWillSend(int *MixReverbBuffer, UINT nSamples); + + // call once after all data has been sent + void Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples); + // [Reverb level 0(quiet)-100(loud)], [REVERBTYPE_XXXX] bool SetReverbParameters(UINT nDepth, UINT nType); private: Modified: trunk/OpenMPT/soundlib/Fastmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-05 21:34:21 UTC (rev 2306) +++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-06 05:02:26 UTC (rev 2307) @@ -1515,11 +1515,8 @@ #ifndef NO_REVERB if (pbuffer == MixReverbBuffer) { - if (!m_Reverb.gnReverbSend) - { - StereoFill(MixReverbBuffer, count, &m_Reverb.gnRvbROfsVol, &m_Reverb.gnRvbLOfsVol); - } - m_Reverb.gnReverbSend += count; + // notify reverb that there will be data in the reverb buffer to be processed + m_Reverb.ProcessWillSend(MixReverbBuffer, count); pOfsR = &m_Reverb.gnRvbROfsVol; pOfsL = &m_Reverb.gnRvbLOfsVol; } Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-05 21:34:21 UTC (rev 2306) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-06 05:02:26 UTC (rev 2307) @@ -283,10 +283,6 @@ lSampleCount = lCount; -#ifndef NO_REVERB - m_Reverb.gnReverbSend = 0; -#endif // NO_REVERB - if(nMixStatCount == 0) { // reset mixer channel count before we are calling CreateStereoMix the first time this round, if we are not updating the mixer state, we do not reset statistics @@ -296,6 +292,9 @@ // Resetting sound buffer StereoFill(MixSoundBuffer, lCount, &gnDryROfsVol, &gnDryLOfsVol); +#ifndef NO_REVERB + m_Reverb.ProcessPrepare(MixReverbBuffer, lCount); +#endif // NO_REVERB if (m_MixerSettings.gnChannels >= 2) { @@ -303,7 +302,7 @@ CreateStereoMix(lCount); #ifndef NO_REVERB - m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); + m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount); #endif // NO_REVERB if (nMaxPlugins) ProcessPlugins(lCount); @@ -318,7 +317,7 @@ CreateStereoMix(lCount); #ifndef NO_REVERB - m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount, GetProcSupport()); + m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount); #endif // NO_REVERB if (nMaxPlugins) ProcessPlugins(lCount); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-06 18:09:31
|
Revision: 2308 http://sourceforge.net/p/modplug/code/2308 Author: manxorist Date: 2013-06-06 18:09:24 +0000 (Thu, 06 Jun 2013) Log Message: ----------- [Ref] The equalizer uses the MixFloatBuffer solely for temporal storage of the MixSoundBuffer and does not interact at all with general floating point mixing of plugins. There is thus no reason to apply the mixlevels-specific floating point normalizaton which is stored in CSoundFilePlayConfig. Instead, always normalize floating point values to nominal -1.0...1.0 range in equalizer now. Modified Paths: -------------- trunk/OpenMPT/sounddsp/EQ.cpp trunk/OpenMPT/sounddsp/EQ.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/sounddsp/EQ.cpp =================================================================== --- trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-06 05:02:26 UTC (rev 2307) +++ trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-06 18:09:24 UTC (rev 2308) @@ -309,34 +309,32 @@ #endif -void CEQ::ProcessMono(int *pbuffer, float *MixFloatBuffer, UINT nCount, CSoundFilePlayConfig &config) -//--------------------------------------------------------------------------------------------------- +void CEQ::ProcessMono(int *pbuffer, float *MixFloatBuffer, UINT nCount) +//--------------------------------------------------------------------- { - MonoMixToFloat(pbuffer, MixFloatBuffer, nCount, config.getIntToFloat()); + MonoMixToFloat(pbuffer, MixFloatBuffer, nCount, 1.0f/static_cast<float>(MIXING_CLIPMAX)); for (UINT b=0; b<MAX_EQ_BANDS; b++) { if ((gEQ[b].bEnable) && (gEQ[b].Gain != 1.0f)) EQFilter(&gEQ[b], MixFloatBuffer, nCount); } - FloatToMonoMix(MixFloatBuffer, pbuffer, nCount, config.getFloatToInt()); + FloatToMonoMix(MixFloatBuffer, pbuffer, nCount, static_cast<float>(MIXING_CLIPMAX)); } -void CEQ::ProcessStereo(int *pbuffer, float *MixFloatBuffer, UINT nCount, CSoundFilePlayConfig &config) -//----------------------------------------------------------------------------------------------------- +void CEQ::ProcessStereo(int *pbuffer, float *MixFloatBuffer, UINT nCount) +//----------------------------------------------------------------------- { #ifdef ENABLE_SSE #ifdef ENABLE_MMX - // Still allow the check, because the user can turn this on/off - if(GetProcSupport() & PROCSUPPORT_SSE) { int sse_state, sse_eqstate; - MonoMixToFloat(pbuffer, MixFloatBuffer, nCount*2, config.getIntToFloat()); + MonoMixToFloat(pbuffer, MixFloatBuffer, nCount*2, 1.0f/static_cast<float>(MIXING_CLIPMAX)); _asm stmxcsr sse_state; - sse_eqstate = sse_state | 0xFF80; + sse_eqstate = sse_state | 0xFF80; // set flush-to-zero, denormals-are-zero, round-to-zero, mask all exception, leave flags alone _asm ldmxcsr sse_eqstate; for (UINT b=0; b<MAX_EQ_BANDS; b++) { @@ -345,7 +343,7 @@ } _asm ldmxcsr sse_state; - FloatToMonoMix(MixFloatBuffer, pbuffer, nCount*2, config.getFloatToInt()); + FloatToMonoMix(MixFloatBuffer, pbuffer, nCount*2, static_cast<float>(MIXING_CLIPMAX)); } else @@ -354,11 +352,9 @@ #ifdef ENABLE_3DNOW - // We still perform the MMX check because the user can enable/disable this - if(GetProcSupport() & PROCSUPPORT_3DNOW) { - MonoMixToFloat(pbuffer, MixFloatBuffer, nCount*2, config.getIntToFloat()); + MonoMixToFloat(pbuffer, MixFloatBuffer, nCount*2, 1.0f/static_cast<float>(MIXING_CLIPMAX)); for (UINT b=0; b<MAX_EQ_BANDS; b++) { @@ -367,14 +363,14 @@ AMD_StereoEQ(&gEQ[b], &gEQ[b+MAX_EQ_BANDS], MixFloatBuffer, nCount); } - FloatToMonoMix(MixFloatBuffer, pbuffer, nCount*2, config.getFloatToInt()); + FloatToMonoMix(MixFloatBuffer, pbuffer, nCount*2, static_cast<float>(MIXING_CLIPMAX)); } else #endif // ENABLE_3DNOW { - StereoMixToFloat(pbuffer, MixFloatBuffer, MixFloatBuffer+MIXBUFFERSIZE, nCount, config.getIntToFloat()); + StereoMixToFloat(pbuffer, MixFloatBuffer, MixFloatBuffer+MIXBUFFERSIZE, nCount, 1.0f/static_cast<float>(MIXING_CLIPMAX)); for (UINT bl=0; bl<MAX_EQ_BANDS; bl++) { @@ -385,7 +381,7 @@ if ((gEQ[br].bEnable) && (gEQ[br].Gain != 1.0f)) EQFilter(&gEQ[br], MixFloatBuffer+MIXBUFFERSIZE, nCount); } - FloatToStereoMix(MixFloatBuffer, MixFloatBuffer+MIXBUFFERSIZE, pbuffer, nCount, config.getFloatToInt()); + FloatToStereoMix(MixFloatBuffer, MixFloatBuffer+MIXBUFFERSIZE, pbuffer, nCount, static_cast<float>(MIXING_CLIPMAX)); } } Modified: trunk/OpenMPT/sounddsp/EQ.h =================================================================== --- trunk/OpenMPT/sounddsp/EQ.h 2013-06-06 05:02:26 UTC (rev 2307) +++ trunk/OpenMPT/sounddsp/EQ.h 2013-06-06 18:09:24 UTC (rev 2308) @@ -12,9 +12,6 @@ #pragma once -#include "../soundlib/SoundFilePlayConfig.h" - - #define MAX_EQ_BANDS 6 typedef struct ALIGN(4) _EQBANDSTRUCT @@ -41,11 +38,10 @@ EQBANDSTRUCT gEQ[MAX_EQ_BANDS*2]; public: CEQ(); - ~CEQ() {} public: void Initialize(BOOL bReset, DWORD MixingFreq); - void ProcessStereo(int *pbuffer, float *MixFloatBuffer, UINT nCount, CSoundFilePlayConfig &config); - void ProcessMono(int *pbuffer, float *MixFloatBuffer, UINT nCount, CSoundFilePlayConfig &config); + void ProcessStereo(int *pbuffer, float *MixFloatBuffer, UINT nCount); + void ProcessMono(int *pbuffer, float *MixFloatBuffer, UINT nCount); void SetEQGains(const UINT *pGains, UINT nGains, const UINT *pFreqs, BOOL bReset, DWORD MixingFreq); }; Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-06 05:02:26 UTC (rev 2307) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-06 18:09:24 UTC (rev 2308) @@ -339,9 +339,9 @@ if (m_MixerSettings.DSPMask & SNDDSP_EQ) { if (m_MixerSettings.gnChannels >= 2) - m_EQ.ProcessStereo(MixSoundBuffer, MixFloatBuffer, lCount, m_PlayConfig); + m_EQ.ProcessStereo(MixSoundBuffer, MixFloatBuffer, lCount); else - m_EQ.ProcessMono(MixSoundBuffer, MixFloatBuffer, lCount, m_PlayConfig); + m_EQ.ProcessMono(MixSoundBuffer, MixFloatBuffer, lCount); } #endif // NO_EQ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-06 18:42:41
|
Revision: 2309 http://sourceforge.net/p/modplug/code/2309 Author: manxorist Date: 2013-06-06 18:42:34 +0000 (Thu, 06 Jun 2013) Log Message: ----------- [Fix] In quad channel output mode, also apply equalizer to rear channels. Modified Paths: -------------- trunk/OpenMPT/sounddsp/EQ.cpp trunk/OpenMPT/sounddsp/EQ.h trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/sounddsp/EQ.cpp =================================================================== --- trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-06 18:09:24 UTC (rev 2308) +++ trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-06 18:42:34 UTC (rev 2309) @@ -513,3 +513,34 @@ Initialize(bReset, MixingFreq); } + + +void CQuadEQ::Initialize(BOOL bReset, DWORD MixingFreq) +//----------------------------------------------------- +{ + front.Initialize(bReset, MixingFreq); + rear.Initialize(bReset, MixingFreq); +} + +void CQuadEQ::SetEQGains(const UINT *pGains, UINT nGains, const UINT *pFreqs, BOOL bReset, DWORD MixingFreq) +//---------------------------------------------------------------------------------------------------------- +{ + front.SetEQGains(pGains, nGains, pFreqs, bReset, MixingFreq); + rear.SetEQGains(pGains, nGains, pFreqs, bReset, MixingFreq); +} + +void CQuadEQ::Process(int *frontBuffer, int *rearBuffer, float *tempFloatBuffer, UINT nCount, UINT nChannels) +//----------------------------------------------------------------------------------------------------------- +{ + if(nChannels == 1) + { + front.ProcessMono(frontBuffer, tempFloatBuffer, nCount); + } else if(nChannels == 2) + { + front.ProcessStereo(frontBuffer, tempFloatBuffer, nCount); + } else if(nChannels == 4) + { + front.ProcessStereo(frontBuffer, tempFloatBuffer, nCount); + rear.ProcessStereo(rearBuffer, tempFloatBuffer, nCount); + } +} Modified: trunk/OpenMPT/sounddsp/EQ.h =================================================================== --- trunk/OpenMPT/sounddsp/EQ.h 2013-06-06 18:09:24 UTC (rev 2308) +++ trunk/OpenMPT/sounddsp/EQ.h 2013-06-06 18:42:34 UTC (rev 2309) @@ -45,3 +45,17 @@ void SetEQGains(const UINT *pGains, UINT nGains, const UINT *pFreqs, BOOL bReset, DWORD MixingFreq); }; + +//=========== +class CQuadEQ +//=========== +{ +private: + CEQ front; + CEQ rear; +public: + void Initialize(BOOL bReset, DWORD MixingFreq); + void Process(int *frontBuffer, int *rearBuffer, float *tempFloatBuffer, UINT nCount, UINT nChannels); + void SetEQGains(const UINT *pGains, UINT nGains, const UINT *pFreqs, BOOL bReset, DWORD MixingFreq); +}; + Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-06 18:09:24 UTC (rev 2308) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-06 18:42:34 UTC (rev 2309) @@ -311,7 +311,7 @@ CDSP m_DSP; #endif #ifndef NO_EQ - CEQ m_EQ; + CQuadEQ m_EQ; #endif #ifndef NO_AGC CAGC m_AGC; Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-06 18:09:24 UTC (rev 2308) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-06 18:42:34 UTC (rev 2309) @@ -338,10 +338,7 @@ // Graphic Equalizer if (m_MixerSettings.DSPMask & SNDDSP_EQ) { - if (m_MixerSettings.gnChannels >= 2) - m_EQ.ProcessStereo(MixSoundBuffer, MixFloatBuffer, lCount); - else - m_EQ.ProcessMono(MixSoundBuffer, MixFloatBuffer, lCount); + m_EQ.Process(MixSoundBuffer, MixRearBuffer, MixFloatBuffer, lCount, m_MixerSettings.gnChannels); } #endif // NO_EQ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-07 00:18:26
|
Revision: 2311 http://sourceforge.net/p/modplug/code/2311 Author: manxorist Date: 2013-06-07 00:18:17 +0000 (Fri, 07 Jun 2013) Log Message: ----------- [Ref] Rewrite cpuid feature detection in more readable C with intrinsics and move it from soundlib/Mmx_mix.cpp into common/misc_util.cpp. [Fix] Fix the semantics and naming of the feature flags and feature flag macros to more closely match commonly used feature names. Modified Paths: -------------- trunk/OpenMPT/common/BuildSettings.h trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/mptrack/View_smp.cpp trunk/OpenMPT/mptrack/Vstplug.cpp trunk/OpenMPT/sounddsp/EQ.cpp trunk/OpenMPT/soundlib/Mmx_mix.cpp trunk/OpenMPT/soundlib/Snd_defs.h trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/common/BuildSettings.h =================================================================== --- trunk/OpenMPT/common/BuildSettings.h 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/common/BuildSettings.h 2013-06-07 00:18:17 UTC (rev 2311) @@ -44,12 +44,12 @@ // Generate inline assembly using MMX instructions (only used when the CPU supports it). #define ENABLE_MMX -// Generate inline assembly using 3DNOW instructions (only used when the CPU supports it). -#define ENABLE_3DNOW - // Generate inline assembly using SSE instructions (only used when the CPU supports it). #define ENABLE_SSE +// Generate inline assembly using AMD specific instruction set extensions (only used when the CPU supports it). +#define ENABLE_X86_AMD + #endif // ENABLE_ASM Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/common/misc_util.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -10,3 +10,124 @@ #include "stdafx.h" #include "misc_util.h" + + +#if defined(ENABLE_ASM) + + +uint32 ProcSupport = 0; + + +#if MPT_COMPILER_MSVC && defined(ENABLE_X86) + + +#include <intrin.h> + + +typedef char cpuid_result_string[12]; + + +struct cpuid_result { + uint32 a; + uint32 b; + uint32 c; + uint32 d; + std::string as_string() const + { + cpuid_result_string result; + result[0+0] = (b >> 0) & 0xff; + result[0+1] = (b >> 8) & 0xff; + result[0+2] = (b >>16) & 0xff; + result[0+3] = (b >>24) & 0xff; + result[4+0] = (d >> 0) & 0xff; + result[4+1] = (d >> 8) & 0xff; + result[4+2] = (d >>16) & 0xff; + result[4+3] = (d >>24) & 0xff; + result[8+0] = (c >> 0) & 0xff; + result[8+1] = (c >> 8) & 0xff; + result[8+2] = (c >>16) & 0xff; + result[8+3] = (c >>24) & 0xff; + return std::string(result, result + 12); + } +}; + + +static cpuid_result cpuid(uint32 function) +//---------------------------------------- +{ + cpuid_result result; + int CPUInfo[4]; + __cpuid(CPUInfo, function); + result.a = CPUInfo[0]; + result.b = CPUInfo[1]; + result.c = CPUInfo[2]; + result.d = CPUInfo[3]; + return result; +} + + +static bool has_cpuid() +//--------------------- +{ + const uint32 eflags_cpuid = 1<<21; + uint32 old_eflags = __readeflags(); + __writeeflags(old_eflags ^ eflags_cpuid); + bool result = ((__readeflags() ^ old_eflags) & eflags_cpuid) ? true : false; + __writeeflags(old_eflags); + return result; +} + + +void InitProcSupport() +//-------------------- +{ + + ProcSupport = 0; + + if(has_cpuid()) + { + + cpuid_result VendorString = cpuid(0x00000000u); + + cpuid_result StandardFeatureFlags = cpuid(0x00000001u); + if(StandardFeatureFlags.d & (1<<23)) ProcSupport |= PROCSUPPORT_MMX; + if(StandardFeatureFlags.d & (1<<25)) ProcSupport |= PROCSUPPORT_SSE; + if(StandardFeatureFlags.d & (1<<26)) ProcSupport |= PROCSUPPORT_SSE2; + if(StandardFeatureFlags.c & (1<< 0)) ProcSupport |= PROCSUPPORT_SSE3; + + if(VendorString.as_string() == "AuthenticAMD") + { + + cpuid_result ExtendedVendorString = cpuid(0x80000000u); + if(ExtendedVendorString.a >= 0x80000001u) + { + + cpuid_result ExtendedFeatureFlags = cpuid(0x80000001u); + if(ExtendedFeatureFlags.d & (1<<22)) ProcSupport |= PROCSUPPORT_AMD_MMXEXT; + if(ExtendedFeatureFlags.d & (1<<31)) ProcSupport |= PROCSUPPORT_AMD_3DNOW; + if(ExtendedFeatureFlags.d & (1<<30)) ProcSupport |= PROCSUPPORT_AMD_3DNOW2; + + } + + } + + } + +} + + +#else // !( MPT_COMPILER_MSVC && ENABLE_X86 ) + + +void InitProcSupport() +//-------------------- +{ + ProcSupport = 0; +} + + +#endif // MPT_COMPILER_MSVC && ENABLE_X86 + + +#endif // ENABLE_ASM + Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/common/misc_util.h 2013-06-07 00:18:17 UTC (rev 2311) @@ -441,3 +441,21 @@ }; } // namespace Util + + +#ifdef ENABLE_ASM +#define PROCSUPPORT_MMX 0x00001 // Processor supports MMX instructions +#define PROCSUPPORT_SSE 0x00010 // Processor supports SSE instructions +#define PROCSUPPORT_SSE2 0x00020 // Processor supports SSE2 instructions +#define PROCSUPPORT_SSE3 0x00040 // Processor supports SSE3 instructions +#define PROCSUPPORT_AMD_MMXEXT 0x10000 // Processor supports AMD MMX extensions +#define PROCSUPPORT_AMD_3DNOW 0x20000 // Processor supports AMD 3DNow! instructions +#define PROCSUPPORT_AMD_3DNOW2 0x40000 // Processor supports AMD 3DNow!2 instructions +extern uint32 ProcSupport; +void InitProcSupport(); +static inline uint32 GetProcSupport() +{ + return ProcSupport; +} +#endif // ENABLE_ASM + Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -874,7 +874,7 @@ { TrackerSettings::Instance().m_ResamplerSettings.SrcMode = SRCMODE_SPLINE; } - if(GetProcSupport() & PROCSUPPORT_MMXEX) + if(GetProcSupport() & PROCSUPPORT_SSE) { TrackerSettings::Instance().m_ResamplerSettings.SrcMode = SRCMODE_POLYPHASE; } Modified: trunk/OpenMPT/mptrack/View_smp.cpp =================================================================== --- trunk/OpenMPT/mptrack/View_smp.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/mptrack/View_smp.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -521,10 +521,10 @@ } -#ifdef ENABLE_MMX +#if defined(ENABLE_X86_AMD) || defined(ENABLE_SSE) -static void mmxex_findminmax16(void *p, int scanlen, int smplsize, int *smin, int *smax) -//-------------------------------------------------------------------------------------- +static void amdmmxext_or_sse_findminmax16(void *p, int scanlen, int smplsize, int *smin, int *smax) +//------------------------------------------------------------------------------------------------- { _asm { mov ebx, p @@ -585,8 +585,8 @@ } -static void mmxex_findminmax8(void *p, int scanlen, int smplsize, int *smin, int *smax) -//------------------------------------------------------------------------------------- +static void amdmmxext_or_sse_findminmax8(void *p, int scanlen, int smplsize, int *smin, int *smax) +//------------------------------------------------------------------------------------------------ { _asm { mov ebx, p @@ -715,10 +715,10 @@ signed short *p = (signed short *)(psample + poshi*smplsize); smin = 32767; smax = -32768; -#ifdef ENABLE_MMX - if(GetProcSupport() & PROCSUPPORT_MMXEX) +#if defined(ENABLE_X86_AMD) || defined(ENABLE_SSE) + if(GetProcSupport() & (PROCSUPPORT_AMD_MMXEXT|PROCSUPPORT_SSE)) { - mmxex_findminmax16(p, scanlen, smplsize, &smin, &smax); + amdmmxext_or_sse_findminmax16(p, scanlen, smplsize, &smin, &smax); } else #endif { @@ -738,10 +738,10 @@ signed char *p = psample + poshi * smplsize; smin = 127; smax = -128; -#ifdef ENABLE_MMX - if(GetProcSupport() & PROCSUPPORT_MMXEX) +#if defined(ENABLE_X86_AMD) || defined(ENABLE_SSE) + if(GetProcSupport() & (PROCSUPPORT_AMD_MMXEXT|PROCSUPPORT_SSE)) { - mmxex_findminmax8(p, scanlen, smplsize, &smin, &smax); + amdmmxext_or_sse_findminmax8(p, scanlen, smplsize, &smin, &smax); } else #endif { Modified: trunk/OpenMPT/mptrack/Vstplug.cpp =================================================================== --- trunk/OpenMPT/mptrack/Vstplug.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/mptrack/Vstplug.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -3413,7 +3413,6 @@ return; } -#ifdef ENABLE_MMX #ifdef ENABLE_SSE if(GetProcSupport() & PROCSUPPORT_SSE) { @@ -3422,7 +3421,6 @@ SSEDeinterleaveInt16ToFloat(outputs[0], outputs[1], samples); } else #endif // ENABLE_SSE -#endif // ENABLE_MMX { InterleaveFloatToInt16(inputs[0], inputs[1], samples); m_pMediaProcess->Process(samples * 2 * sizeof(int16), reinterpret_cast<BYTE *>(m_pMixBuffer), m_DataTime, DMO_INPLACE_NORMAL); Modified: trunk/OpenMPT/sounddsp/EQ.cpp =================================================================== --- trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -109,10 +109,11 @@ } +#ifdef ENABLE_X86_AMD + static void AMD_StereoEQ(EQBANDSTRUCT *pbl, EQBANDSTRUCT *pbr, float32 *pbuffer, UINT nCount) //------------------------------------------------------------------------------------------- { -#ifdef ENABLE_3DNOW float tmp[16]; _asm { @@ -189,14 +190,16 @@ movd [edx+EQBANDSTRUCT.y2], mm7 emms } -#endif } +#endif // ENABLE_X86_AMD + +#ifdef ENABLE_SSE + static void SSE_StereoEQ(EQBANDSTRUCT *pbl, EQBANDSTRUCT *pbr, float32 *pbuffer, UINT nCount) //------------------------------------------------------------------------------------------- { -#ifdef ENABLE_SSE static const float gk1 = 1.0f; _asm { mov eax, pbl @@ -284,9 +287,10 @@ movss [edx+EQBANDSTRUCT.y2], xmm1 done:; } -#endif // ENABLE_SSE } +#endif // ENABLE_SSE + #pragma warning(default:4100) #else @@ -326,7 +330,6 @@ { #ifdef ENABLE_SSE -#ifdef ENABLE_MMX if(GetProcSupport() & PROCSUPPORT_SSE) { @@ -347,12 +350,11 @@ } else -#endif // ENABLE_MMX #endif // ENABLE_SSE -#ifdef ENABLE_3DNOW +#ifdef ENABLE_X86_AMD - if(GetProcSupport() & PROCSUPPORT_3DNOW) + if(GetProcSupport() & PROCSUPPORT_AMD_3DNOW) { MonoMixToFloat(pbuffer, MixFloatBuffer, nCount*2, 1.0f/static_cast<float>(MIXING_CLIPMAX)); @@ -366,7 +368,7 @@ FloatToMonoMix(MixFloatBuffer, pbuffer, nCount*2, static_cast<float>(MIXING_CLIPMAX)); } else -#endif // ENABLE_3DNOW +#endif // ENABLE_X86_AMD { @@ -390,10 +392,10 @@ CEQ::CEQ() //-------- { - #if defined(ENABLE_MMX) || defined(ENABLE_SSE) + #if defined(ENABLE_SSE) || defined(ENABLE_X86_AMD) ALWAYS_ASSERT(((uintptr_t)&(gEQ[0])) % 4 == 0); ALWAYS_ASSERT(((uintptr_t)&(gEQ[1])) % 4 == 0); - #endif + #endif // ENABLE_SSE || ENABLE_X86_AMD memcpy(gEQ, gEQDefaults, sizeof(gEQ)); } Modified: trunk/OpenMPT/soundlib/Mmx_mix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Mmx_mix.cpp 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/soundlib/Mmx_mix.cpp 2013-06-07 00:18:17 UTC (rev 2311) @@ -24,75 +24,10 @@ #include "Sndfile.h" -#ifdef ENABLE_ASM - -static uint32 gdwSysInfo = 0; - -void InitProcSupport() -//-------------------- -{ -#ifdef ENABLE_X86 - static unsigned int fProcessorExtensions = 0; - _asm - { - pushfd // Store original EFLAGS on stack - pop eax // Get original EFLAGS in EAX - mov ecx, eax // Duplicate original EFLAGS in ECX for toggle check - xor eax, 0x00200000L // Flip ID bit in EFLAGS - push eax // Save new EFLAGS value on stack - popfd // Replace current EFLAGS value - pushfd // Store new EFLAGS on stack - pop eax // Get new EFLAGS in EAX - xor eax, ecx // Can we toggle ID bit? - jz Done // Jump if no, Processor is older than a Pentium so CPU_ID is not supported - mov fProcessorExtensions, PROCSUPPORT_CPUID - mov eax, 1 // Set EAX to tell the CPUID instruction what to return - push ebx - cpuid // Get family/model/stepping/features - pop ebx - test edx, 0x00800000L // Check if mmx technology available - jz Done // Jump if no - // Tests have passed, this machine supports the Intel MultiMedia Instruction Set! - or fProcessorExtensions, PROCSUPPORT_MMX - // Check for SSE: PROCSUPPORT_SSE - test edx, 0x02000000L // check if SSE is present (bit 25) - jz nosse // done if no - // else set the correct bit in fProcessorExtensions - or fProcessorExtensions, (PROCSUPPORT_MMXEX|PROCSUPPORT_SSE) - jmp Done - nosse: - // Check for AMD 3DNow! - mov eax, 0x80000000 - cpuid - cmp eax, 0x80000000 - jbe Done - mov eax, 0x80000001 - cpuid // CPU_ID - test edx, 0x80000000 - jz Done - or fProcessorExtensions, PROCSUPPORT_3DNOW // 3DNow! supported - test edx, (1<<22) // Bit 22: AMD MMX extensions - jz Done - or fProcessorExtensions, PROCSUPPORT_MMXEX // MMX extensions supported - Done: - } - gdwSysInfo = fProcessorExtensions; -#endif -} - -uint32 GetProcSupport() -//--------------------- -{ - return gdwSysInfo; -} - -#endif - - //////////////////////////////////////////////////////////////////////////////////// // 3DNow! optimizations -#ifdef ENABLE_3DNOW +#ifdef ENABLE_X86_AMD // Convert integer mix to floating-point static void AMD_StereoMixToFloat(const int *pSrc, float *pOut1, float *pOut2, UINT nCount, const float _i2fc) @@ -222,7 +157,7 @@ } } -#endif +#endif // ENABLE_X86_AMD /////////////////////////////////////////////////////////////////////////////////////// // SSE Optimizations @@ -442,19 +377,19 @@ { #ifdef ENABLE_SSE - if(gdwSysInfo & PROCSUPPORT_SSE) + if(GetProcSupport() & PROCSUPPORT_SSE) { SSE_StereoMixToFloat(pSrc, pOut1, pOut2, nCount, _i2fc); return; } #endif // ENABLE_SSE - #ifdef ENABLE_3DNOW - if(gdwSysInfo & PROCSUPPORT_3DNOW) + #ifdef ENABLE_X86_AMD + if(GetProcSupport() & PROCSUPPORT_AMD_3DNOW) { AMD_StereoMixToFloat(pSrc, pOut1, pOut2, nCount, _i2fc); return; } - #endif // ENABLE_3DNOW + #endif // ENABLE_X86_AMD #ifdef ENABLE_X86 X86_StereoMixToFloat(pSrc, pOut1, pOut2, nCount, _i2fc); @@ -468,13 +403,13 @@ void FloatToStereoMix(const float *pIn1, const float *pIn2, int *pOut, UINT nCount, const float _f2ic) { - #ifdef ENABLE_3DNOW - if(gdwSysInfo & PROCSUPPORT_3DNOW) + #ifdef ENABLE_X86_AMD + if(GetProcSupport() & PROCSUPPORT_AMD_3DNOW) { AMD_FloatToStereoMix(pIn1, pIn2, pOut, nCount, _f2ic); return; } - #endif // ENABLE_3DNOW + #endif // ENABLE_X86_AMD #ifdef ENABLE_X86 X86_FloatToStereoMix(pIn1, pIn2, pOut, nCount, _f2ic); @@ -489,19 +424,19 @@ { #ifdef ENABLE_SSE - if(gdwSysInfo & PROCSUPPORT_SSE) + if(GetProcSupport() & PROCSUPPORT_SSE) { SSE_MonoMixToFloat(pSrc, pOut, nCount, _i2fc); return; } #endif // ENABLE_SSE - #ifdef ENABLE_3DNOW - if(gdwSysInfo & PROCSUPPORT_3DNOW) + #ifdef ENABLE_X86_AMD + if(GetProcSupport() & PROCSUPPORT_AMD_3DNOW) { AMD_MonoMixToFloat(pSrc, pOut, nCount, _i2fc); return; } - #endif // ENABLE_3DNOW + #endif // ENABLE_X86_AMD #ifdef ENABLE_X86 X86_MonoMixToFloat(pSrc, pOut, nCount, _i2fc); @@ -515,13 +450,13 @@ void FloatToMonoMix(const float *pIn, int *pOut, UINT nCount, const float _f2ic) { - #ifdef ENABLE_3DNOW - if(gdwSysInfo & PROCSUPPORT_3DNOW) + #ifdef ENABLE_X86_AMD + if(GetProcSupport() & PROCSUPPORT_AMD_3DNOW) { AMD_FloatToMonoMix(pIn, pOut, nCount, _f2ic); return; } - #endif // ENABLE_3DNOW + #endif // ENABLE_X86_AMD #ifdef ENABLE_X86 X86_FloatToMonoMix(pIn, pOut, nCount, _f2ic); Modified: trunk/OpenMPT/soundlib/Snd_defs.h =================================================================== --- trunk/OpenMPT/soundlib/Snd_defs.h 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/soundlib/Snd_defs.h 2013-06-07 00:18:17 UTC (rev 2311) @@ -242,15 +242,6 @@ #define DNA_NOTEFADE 2 -#ifdef ENABLE_ASM -#define PROCSUPPORT_CPUID 0x01 -#define PROCSUPPORT_MMX 0x02 // Processor supports MMX instructions -#define PROCSUPPORT_MMXEX 0x04 // Processor supports AMD MMX extensions -#define PROCSUPPORT_3DNOW 0x08 // Processor supports AMD 3DNow! instructions -#define PROCSUPPORT_SSE 0x10 // Processor supports SSE instructions -#endif - - // Module flags enum SongFlags { Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-06 23:16:28 UTC (rev 2310) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-07 00:18:17 UTC (rev 2311) @@ -186,12 +186,6 @@ #endif // MODPLUG_TRACKER -#ifdef ENABLE_ASM -void InitProcSupport(); -uint32 GetProcSupport(); -#endif - - void StereoMixToFloat(const int *pSrc, float *pOut1, float *pOut2, UINT nCount, const float _i2fc); void FloatToStereoMix(const float *pIn1, const float *pIn2, int *pOut, UINT nCount, const float _f2ic); void MonoMixToFloat(const int *pSrc, float *pOut, UINT nCount, const float _i2fc); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-07 21:55:52
|
Revision: 2316 http://sourceforge.net/p/modplug/code/2316 Author: manxorist Date: 2013-06-07 21:55:44 +0000 (Fri, 07 Jun 2013) Log Message: ----------- [Ref] Move MixReverbBuffer into CReverb. [Ref] Simplify CReverb interface and do ReverbSend flag tracking in the new MixReverbBuffer getter function GetReverbSendBuffer(). [Ref] This removes a performance optimization in cases where all channels with have reverb flag set are also plugin or rear channels. In this case, processing reverb is not strictly needed (because reverb is not processed for plugin or rear channels). This case is really rare. Remove this optimization to gain better code readability. Modified Paths: -------------- trunk/OpenMPT/sounddsp/Reverb.cpp trunk/OpenMPT/sounddsp/Reverb.h trunk/OpenMPT/soundlib/Fastmix.cpp trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/sounddsp/Reverb.cpp =================================================================== --- trunk/OpenMPT/sounddsp/Reverb.cpp 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/sounddsp/Reverb.cpp 2013-06-07 21:55:44 UTC (rev 2316) @@ -35,12 +35,18 @@ { // Shared reverb state - gnReverbSamples = 0; - gnReverbDecaySamples = 0; - gnReverbSend = 0; + +#ifndef NO_REVERB + MemsetZero(MixReverbBuffer); +#endif gnRvbROfsVol = 0; gnRvbLOfsVol = 0; + gnReverbSend = 0; + + gnReverbSamples = 0; + gnReverbDecaySamples = 0; + // Internal reverb state g_bLastInPresent = 0; g_bLastOutPresent = 0; @@ -247,6 +253,8 @@ void CReverb::Shutdown() //---------------------- { + gnReverbSend = 0; + gnRvbLOfsVol = 0; gnRvbROfsVol = 0; @@ -396,42 +404,33 @@ } -void CReverb::ProcessPrepare(int *MixReverbBuffer, UINT nSamples) -//--------------------------------------------------------------- +int *CReverb::GetReverbSendBuffer(UINT nSamples) +//---------------------------------------------- { - gnReverbSend = 0; // no data sent yet - if(!gnReverbSamples) - { - // reverb had decayed completely, we will probably not process reverb, so no need to clear buffer - return; - } - StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); -} - - -void CReverb::ProcessWillSend(int *MixReverbBuffer, UINT nSamples) -//---------------------------------------------------------------- -{ - if(!gnReverbSend && !gnReverbSamples) - { - // reverb had decayed completely before, and we did not clear the buffer yet, do it now because we get new data + if(!gnReverbSend) + { // and we did not clear the buffer yet, do it now because we will get new data StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); } gnReverbSend = 1; // we will have to process reverb + return MixReverbBuffer; } // Reverb -void CReverb::Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples) -//----------------------------------------------------------------------------- +void CReverb::Process(int *MixSoundBuffer, UINT nSamples) +//------------------------------------------------------- { - UINT nIn, nOut; - + if(!(GetProcSupport() & PROCSUPPORT_MMX)) return; if((!gnReverbSend) && (!gnReverbSamples)) { // no data is sent to reverb and reverb decayed completely return; } - if (!(GetProcSupport() & PROCSUPPORT_MMX)) return; + if(!gnReverbSend) + { // no input data in MixReverbBuffer, so the buffer got not cleared in GetReverbSendBuffer(), do it now for decay + StereoFill(MixReverbBuffer, nSamples, &gnRvbROfsVol, &gnRvbLOfsVol); + } + + UINT nIn, nOut; // Dynamically adjust reverb master gains LONG lMasterGain; lMasterGain = ((g_RefDelay.lMasterGain * m_Settings.m_nReverbDepth) >> 4); @@ -494,6 +493,7 @@ Shutdown(); gnReverbSamples = 0; } + gnReverbSend = 0; // no input data in MixReverbBuffer } Modified: trunk/OpenMPT/sounddsp/Reverb.h =================================================================== --- trunk/OpenMPT/sounddsp/Reverb.h 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/sounddsp/Reverb.h 2013-06-07 21:55:44 UTC (rev 2316) @@ -126,6 +126,9 @@ CReverbSettings m_Settings; // Shared reverb state +private: + int MixReverbBuffer[MIXBUFFERSIZE * 2]; +public: LONG gnRvbROfsVol; LONG gnRvbLOfsVol; @@ -157,15 +160,11 @@ public: void Initialize(BOOL bReset, DWORD MixingFreq); - // call once before calling Process - void ProcessPrepare(int *MixReverbBuffer, UINT nSamples); - - // call after ProcessPrepare and before you are putting data into MixReverbBuffer, // can be called multiple times or never (if no data is sent to reverb) - void ProcessWillSend(int *MixReverbBuffer, UINT nSamples); + int *GetReverbSendBuffer(UINT nSamples); - // call once after all data has been sent - void Process(int *MixSoundBuffer, int *MixReverbBuffer, UINT nSamples); + // call once after all data has been sent. + void Process(int *MixSoundBuffer, UINT nSamples); // [Reverb level 0(quiet)-100(loud)], [REVERBTYPE_XXXX] bool SetReverbParameters(UINT nDepth, UINT nType); Modified: trunk/OpenMPT/soundlib/Fastmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/soundlib/Fastmix.cpp 2013-06-07 21:55:44 UTC (rev 2316) @@ -1485,10 +1485,15 @@ pbuffer = MixSoundBuffer; #ifndef NO_REVERB #ifdef ENABLE_MMX - if((m_MixerSettings.DSPMask & SNDDSP_REVERB) && (GetProcSupport() & PROCSUPPORT_MMX) && !pChannel->dwFlags[CHN_NOREVERB]) - pbuffer = MixReverbBuffer; - if(pChannel->dwFlags[CHN_REVERB] && (GetProcSupport() & PROCSUPPORT_MMX)) - pbuffer = MixReverbBuffer; + if(GetProcSupport() & PROCSUPPORT_MMX) + { + if(((m_MixerSettings.DSPMask & SNDDSP_REVERB) && !pChannel->dwFlags[CHN_NOREVERB]) || pChannel->dwFlags[CHN_REVERB]) + { + pbuffer = m_Reverb.GetReverbSendBuffer(count); + pOfsR = &m_Reverb.gnRvbROfsVol; + pOfsL = &m_Reverb.gnRvbLOfsVol; + } + } #endif #endif if(pChannel->dwFlags[CHN_SURROUND] && m_MixerSettings.gnChannels > 2) @@ -1512,15 +1517,6 @@ } } } -#ifndef NO_REVERB - if (pbuffer == MixReverbBuffer) - { - // notify reverb that there will be data in the reverb buffer to be processed - m_Reverb.ProcessWillSend(MixReverbBuffer, count); - pOfsR = &m_Reverb.gnRvbROfsVol; - pOfsL = &m_Reverb.gnRvbLOfsVol; - } -#endif nchused++; //////////////////////////////////////////////////// SampleLooping: Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2013-06-07 21:55:44 UTC (rev 2316) @@ -511,9 +511,6 @@ { MemsetZero(MixSoundBuffer); MemsetZero(MixRearBuffer); -#ifndef NO_REVERB - MemsetZero(MixReverbBuffer); -#endif MemsetZero(MixFloatBuffer); gnDryLOfsVol = 0; gnDryROfsVol = 0; Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-07 21:55:44 UTC (rev 2316) @@ -288,9 +288,6 @@ // Front Mix Buffer (Also room for interleaved rear mix) int MixSoundBuffer[MIXBUFFERSIZE * 4]; int MixRearBuffer[MIXBUFFERSIZE * 2]; -#ifndef NO_REVERB - int MixReverbBuffer[MIXBUFFERSIZE * 2]; -#endif float MixFloatBuffer[MIXBUFFERSIZE * 2]; LONG gnDryLOfsVol; LONG gnDryROfsVol; Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 20:34:46 UTC (rev 2315) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 21:55:44 UTC (rev 2316) @@ -290,9 +290,6 @@ // Resetting sound buffer StereoFill(MixSoundBuffer, lCount, &gnDryROfsVol, &gnDryLOfsVol); -#ifndef NO_REVERB - m_Reverb.ProcessPrepare(MixReverbBuffer, lCount); -#endif // NO_REVERB if (m_MixerSettings.gnChannels >= 2) { @@ -300,7 +297,7 @@ CreateStereoMix(lCount); #ifndef NO_REVERB - m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount); + m_Reverb.Process(MixSoundBuffer, lCount); #endif // NO_REVERB if (nMaxPlugins) ProcessPlugins(lCount); @@ -315,7 +312,7 @@ CreateStereoMix(lCount); #ifndef NO_REVERB - m_Reverb.Process(MixSoundBuffer, MixReverbBuffer, lCount); + m_Reverb.Process(MixSoundBuffer, lCount); #endif // NO_REVERB if (nMaxPlugins) ProcessPlugins(lCount); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-07 22:36:31
|
Revision: 2319 http://sourceforge.net/p/modplug/code/2319 Author: manxorist Date: 2013-06-07 22:36:21 +0000 (Fri, 07 Jun 2013) Log Message: ----------- [Ref] Simplify equalizer interface by using a dedicated temporary floating point buffer and avoid having to pass one to Process(). Modified Paths: -------------- trunk/OpenMPT/sounddsp/EQ.cpp trunk/OpenMPT/sounddsp/EQ.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/sounddsp/EQ.cpp =================================================================== --- trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-07 22:21:06 UTC (rev 2318) +++ trunk/OpenMPT/sounddsp/EQ.cpp 2013-06-07 22:36:21 UTC (rev 2319) @@ -516,7 +516,6 @@ } - void CQuadEQ::Initialize(BOOL bReset, DWORD MixingFreq) //----------------------------------------------------- { @@ -531,18 +530,18 @@ rear.SetEQGains(pGains, nGains, pFreqs, bReset, MixingFreq); } -void CQuadEQ::Process(int *frontBuffer, int *rearBuffer, float *tempFloatBuffer, UINT nCount, UINT nChannels) -//----------------------------------------------------------------------------------------------------------- +void CQuadEQ::Process(int *frontBuffer, int *rearBuffer, UINT nCount, UINT nChannels) +//----------------------------------------------------------------------------------- { if(nChannels == 1) { - front.ProcessMono(frontBuffer, tempFloatBuffer, nCount); + front.ProcessMono(frontBuffer, EQTempFloatBuffer, nCount); } else if(nChannels == 2) { - front.ProcessStereo(frontBuffer, tempFloatBuffer, nCount); + front.ProcessStereo(frontBuffer, EQTempFloatBuffer, nCount); } else if(nChannels == 4) { - front.ProcessStereo(frontBuffer, tempFloatBuffer, nCount); - rear.ProcessStereo(rearBuffer, tempFloatBuffer, nCount); + front.ProcessStereo(frontBuffer, EQTempFloatBuffer, nCount); + rear.ProcessStereo(rearBuffer, EQTempFloatBuffer, nCount); } } Modified: trunk/OpenMPT/sounddsp/EQ.h =================================================================== --- trunk/OpenMPT/sounddsp/EQ.h 2013-06-07 22:21:06 UTC (rev 2318) +++ trunk/OpenMPT/sounddsp/EQ.h 2013-06-07 22:36:21 UTC (rev 2319) @@ -53,9 +53,10 @@ private: CEQ front; CEQ rear; + float EQTempFloatBuffer[MIXBUFFERSIZE * 2]; public: void Initialize(BOOL bReset, DWORD MixingFreq); - void Process(int *frontBuffer, int *rearBuffer, float *tempFloatBuffer, UINT nCount, UINT nChannels); + void Process(int *frontBuffer, int *rearBuffer, UINT nCount, UINT nChannels); void SetEQGains(const UINT *pGains, UINT nGains, const UINT *pFreqs, BOOL bReset, DWORD MixingFreq); }; Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 22:21:06 UTC (rev 2318) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-07 22:36:21 UTC (rev 2319) @@ -333,7 +333,7 @@ // Graphic Equalizer if (m_MixerSettings.DSPMask & SNDDSP_EQ) { - m_EQ.Process(MixSoundBuffer, MixRearBuffer, MixFloatBuffer, lCount, m_MixerSettings.gnChannels); + m_EQ.Process(MixSoundBuffer, MixRearBuffer, lCount, m_MixerSettings.gnChannels); } #endif // NO_EQ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <man...@us...> - 2013-06-08 17:35:03
|
Revision: 2325 http://sourceforge.net/p/modplug/code/2325 Author: manxorist Date: 2013-06-08 17:34:54 +0000 (Sat, 08 Jun 2013) Log Message: ----------- [Ref] Add seperate CSoundFile::ReadInterleved and ReadNonInterleaved as wrappers around Read. [Ref] Make Read and CreateStereoMix private. Modified Paths: -------------- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/MainFrm.cpp trunk/OpenMPT/mptrack/Mod2wave.cpp trunk/OpenMPT/soundlib/Sndfile.h trunk/OpenMPT/soundlib/Sndmix.cpp Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-08 17:20:22 UTC (rev 2324) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2013-06-08 17:34:54 UTC (rev 2325) @@ -166,10 +166,9 @@ std::size_t count_read = 0; while ( count > 0 ) { std::int16_t * const buffers[4] = { left + count_read, right + count_read, rear_left + count_read, rear_right + count_read }; - std::size_t count_chunk = m_sndFile->Read( - 0, - static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ), // safety margin / samplesize / channels - reinterpret_cast<void*const*>( buffers ) + std::size_t count_chunk = m_sndFile->ReadNonInterleaved( + reinterpret_cast<void*const*>( buffers ), + static_cast<CSoundFile::samplecount_t>( std::min<std::uint64_t>( count, std::numeric_limits<CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) // safety margin / samplesize / channels ); if ( count_chunk == 0 ) { break; @@ -183,10 +182,9 @@ std::size_t count_read = 0; while ( count > 0 ) { float * const buffers[4] = { left + count_read, right + count_read, rear_left + count_read, rear_right + count_read }; - std::size_t count_chunk = m_sndFile->Read( - 0, - static_cast<UINT>( std::min<std::size_t>( count, std::numeric_limits<UINT>::max() / 2 / 4 / 4 ) ), // safety margin / samplesize / channels - reinterpret_cast<void*const*>( buffers ) + std::size_t count_chunk = m_sndFile->ReadNonInterleaved( + reinterpret_cast<void*const*>( buffers ), + static_cast<CSoundFile::samplecount_t>( std::min<std::uint64_t>( count, std::numeric_limits<CSoundFile::samplecount_t>::max() / 2 / 4 / 4 ) ) // safety margin / samplesize / channels ); if ( count_chunk == 0 ) { break; Modified: trunk/OpenMPT/mptrack/MainFrm.cpp =================================================================== --- trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-08 17:20:22 UTC (rev 2324) +++ trunk/OpenMPT/mptrack/MainFrm.cpp 2013-06-08 17:34:54 UTC (rev 2325) @@ -784,7 +784,7 @@ //------------------------------------------------------------------------------- { OPENMPT_PROFILE_FUNCTION(Profiler::Audio); - return m_pSndFile->Read(pvData, MaxSamples); + return m_pSndFile->ReadInterleaved(pvData, MaxSamples); } Modified: trunk/OpenMPT/mptrack/Mod2wave.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-06-08 17:20:22 UTC (rev 2324) +++ trunk/OpenMPT/mptrack/Mod2wave.cpp 2013-06-08 17:34:54 UTC (rev 2325) @@ -778,7 +778,7 @@ CMainFrame::GetMainFrame()->InitRenderer(m_pSndFile); //rewbs.VSTTimeInfo for (UINT n = 0; ; n++) { - UINT lRead = m_pSndFile->Read(buffer, sizeof(buffer)/(m_pSndFile->m_MixerSettings.gnChannels*m_pSndFile->m_MixerSettings.GetBitsPerSample()/8)); + UINT lRead = m_pSndFile->ReadInterleaved(buffer, sizeof(buffer)/(m_pSndFile->m_MixerSettings.gnChannels*m_pSndFile->m_MixerSettings.GetBitsPerSample()/8)); // Process cue points (add base offset), if there are any to process. vector<PatternCuePoint>::reverse_iterator iter; @@ -1152,7 +1152,7 @@ UINT lRead = 0; if (!bFinished) { - lRead = m_pSndFile->Read(pcmBuffer + WAVECONVERTBUFSIZE - pcmBufSize, pcmBufSize/(m_pSndFile->m_MixerSettings.gnChannels*m_pSndFile->m_MixerSettings.GetBitsPerSample()/8)); + lRead = m_pSndFile->ReadInterleaved(pcmBuffer + WAVECONVERTBUFSIZE - pcmBufSize, pcmBufSize/(m_pSndFile->m_MixerSettings.gnChannels*m_pSndFile->m_MixerSettings.GetBitsPerSample()/8)); if (!lRead) bFinished = true; } ullSamples += lRead; Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2013-06-08 17:20:22 UTC (rev 2324) +++ trunk/OpenMPT/soundlib/Sndfile.h 2013-06-08 17:34:54 UTC (rev 2325) @@ -587,8 +587,12 @@ void StopAllVsti(); //rewbs.VSTCompliance void RecalculateGainForAllPlugs(); void ResetChannels(); - UINT Read(LPVOID lpBuffer, UINT cbBuffer, void * const *outputBuffers = nullptr); + samplecount_t ReadInterleaved(void *outputBuffer, samplecount_t count); + samplecount_t ReadNonInterleaved(void * const *outputBuffers, samplecount_t count); +private: + UINT Read(UINT cbBuffer, LPVOID lpBuffer, void * const *outputBuffers = nullptr); void CreateStereoMix(int count); +public: BOOL FadeSong(UINT msec); BOOL GlobalFadeSong(UINT msec); void ProcessPlugins(UINT nCount); Modified: trunk/OpenMPT/soundlib/Sndmix.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-08 17:20:22 UTC (rev 2324) +++ trunk/OpenMPT/soundlib/Sndmix.cpp 2013-06-08 17:34:54 UTC (rev 2325) @@ -193,7 +193,21 @@ } -UINT CSoundFile::Read(LPVOID lpDestBuffer, UINT count, void * const *outputBuffers) +CSoundFile::samplecount_t CSoundFile::ReadInterleaved(void *outputBuffer, samplecount_t count) +//-------------------------------------------------------------------------------------------- +{ + return Read(count, outputBuffer, nullptr); +} + + +CSoundFile::samplecount_t CSoundFile::ReadNonInterleaved(void * const *outputBuffers, samplecount_t count) +//-------------------------------------------------------------------------------------------------------- +{ + return Read(count, nullptr, outputBuffers); +} + + +UINT CSoundFile::Read(UINT count, LPVOID lpDestBuffer, void * const *outputBuffers) //--------------------------------------------------------------------------------- { LPBYTE lpBuffer = (LPBYTE)lpDestBuffer; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |