Improved flush() for better output stream duration accuracy

This commit is contained in:
oparviai 2012-06-13 19:29:53 +00:00
parent 19ea2358c0
commit 657d07b5e6
7 changed files with 205 additions and 94 deletions

View File

@ -501,6 +501,8 @@ and estimates the BPM rate:</p>
<p><b>1.7.0:</b></p> <p><b>1.7.0:</b></p>
<ul> <ul>
<li>Sound quality improvements</li> <li>Sound quality improvements</li>
<li>Improved flush() to adjust output sound stream duration to match better with
ideal duration</li>
<li>Rewrote x86 cpu feature check to resolve compatibility problems</li> <li>Rewrote x86 cpu feature check to resolve compatibility problems</li>
<li>Configure script automatically checks if CPU supports mmx & sse compatibility for GNU platform, and <li>Configure script automatically checks if CPU supports mmx & sse compatibility for GNU platform, and
the script support now "--enable-x86-optimizations" switch to allow disabling x86-specific optimizations.</li> the script support now "--enable-x86-optimizations" switch to allow disabling x86-specific optimizations.</li>
@ -712,6 +714,7 @@ submitted bugfixes since SoundTouch v1.3.1: </p>
<li> Takashi Iwai </li> <li> Takashi Iwai </li>
<li> Yuval Naveh </li> <li> Yuval Naveh </li>
<li> Paulo Pizarro </li> <li> Paulo Pizarro </li>
<li> Blaise Potard</li>
<li> RJ Ryan </li> <li> RJ Ryan </li>
<li> John Sheehy</li> <li> John Sheehy</li>
<li> Tim Shuttleworth</li> <li> Tim Shuttleworth</li>

View File

@ -89,7 +89,7 @@ private:
/// Returns current capacity. /// Returns current capacity.
uint getCapacity() const; uint getCapacity() const;
public: public:
/// Constructor /// Constructor
@ -167,6 +167,10 @@ public:
/// Clears all the samples. /// Clears all the samples.
virtual void clear(); virtual void clear();
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
uint adjustAmountOfSamples(uint numSamples);
}; };
} }

View File

@ -114,6 +114,11 @@ public:
/// Clears all the samples. /// Clears all the samples.
virtual void clear() = 0; virtual void clear() = 0;
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
virtual uint adjustAmountOfSamples(uint numSamples) = 0;
}; };
@ -214,6 +219,14 @@ public:
{ {
return output->isEmpty(); return output->isEmpty();
} }
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
virtual uint adjustAmountOfSamples(uint numSamples)
{
return output->adjustAmountOfSamples(numSamples);
}
}; };
} }

View File

@ -259,3 +259,16 @@ void FIFOSampleBuffer::clear()
samplesInBuffer = 0; samplesInBuffer = 0;
bufferPos = 0; bufferPos = 0;
} }
/// allow trimming (downwards) amount of samples in pipeline.
/// Returns adjusted amount of samples
uint FIFOSampleBuffer::adjustAmountOfSamples(uint numSamples)
{
if (numSamples < samplesInBuffer)
{
samplesInBuffer = numSamples;
}
return samplesInBuffer;
}

View File

@ -345,12 +345,19 @@ void SoundTouch::putSamples(const SAMPLETYPE *samples, uint nSamples)
void SoundTouch::flush() void SoundTouch::flush()
{ {
int i; int i;
uint nOut; int nUnprocessed;
SAMPLETYPE buff[128]; int nOut;
SAMPLETYPE buff[64*2]; // note: allocate 2*64 to cater 64 sample frames of stereo sound
nOut = numSamples(); // check how many samples still await processing, and scale
// that by tempo & rate to get expected output sample count
nUnprocessed = numUnprocessedSamples();
nUnprocessed = (int)((double)nUnprocessed / (tempo * rate) + 0.5);
memset(buff, 0, 128 * sizeof(SAMPLETYPE)); nOut = numSamples(); // ready samples currently in buffer ...
nOut += nUnprocessed; // ... and how many we expect there to be in the end
memset(buff, 0, 64 * channels * sizeof(SAMPLETYPE));
// "Push" the last active samples out from the processing pipeline by // "Push" the last active samples out from the processing pipeline by
// feeding blank samples into the processing pipeline until new, // feeding blank samples into the processing pipeline until new,
// processed samples appear in the output (not however, more than // processed samples appear in the output (not however, more than
@ -358,7 +365,16 @@ void SoundTouch::flush()
for (i = 0; i < 128; i ++) for (i = 0; i < 128; i ++)
{ {
putSamples(buff, 64); putSamples(buff, 64);
if (numSamples() != nOut) break; // new samples have appeared in the output! if ((int)numSamples() >= nOut)
{
// Enough new samples have appeared into the output!
// As samples come from processing with bigger chunks, now truncate it
// back to maximum "nOut" samples to improve duration accuracy
adjustAmountOfSamples(nOut);
// finish
break;
}
} }
// Clear working buffers // Clear working buffers

View File

@ -1,32 +1,28 @@
Microsoft Visual Studio Solution File, Format Version 8.00 Microsoft Visual Studio Solution File, Format Version 10.00
# Visual Studio 2008
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouchDLL", "SoundTouchDLL.vcproj", "{164DE61D-6391-4265-8273-30740117D356}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouchDLL", "SoundTouchDLL.vcproj", "{164DE61D-6391-4265-8273-30740117D356}"
ProjectSection(ProjectDependencies) = postProject ProjectSection(ProjectDependencies) = postProject
{68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509} {68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509}
EndProjectSection EndProjectSection
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject EndProject
Global Global
GlobalSection(SolutionConfiguration) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug = Debug Debug|Win32 = Debug|Win32
Release = Release Release|Win32 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ProjectDependencies) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.ActiveCfg = Debug|Win32
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.Build.0 = Debug|Win32
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.ActiveCfg = Release|Win32
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.Build.0 = Release|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.ActiveCfg = Debug|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.Build.0 = Debug|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.ActiveCfg = Release|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution GlobalSection(SolutionProperties) = preSolution
{164DE61D-6391-4265-8273-30740117D356}.Debug.ActiveCfg = Debug|Win32 HideSolutionNode = FALSE
{164DE61D-6391-4265-8273-30740117D356}.Debug.Build.0 = Debug|Win32
{164DE61D-6391-4265-8273-30740117D356}.Release.ActiveCfg = Release|Win32
{164DE61D-6391-4265-8273-30740117D356}.Release.Build.0 = Release|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.ActiveCfg = Debug|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.Build.0 = Debug|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.ActiveCfg = Release|Win32
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

View File

@ -1,127 +1,185 @@
<?xml version="1.0" encoding="Windows-1252"?> <?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject <VisualStudioProject
ProjectType="Visual C++" ProjectType="Visual C++"
Version="7.10" Version="9,00"
Name="SoundTouchDLL" Name="SoundTouchDLL"
ProjectGUID="{164DE61D-6391-4265-8273-30740117D356}" ProjectGUID="{164DE61D-6391-4265-8273-30740117D356}"
Keyword="Win32Proj"> Keyword="Win32Proj"
TargetFrameworkVersion="131072"
>
<Platforms> <Platforms>
<Platform <Platform
Name="Win32"/> Name="Win32"
/>
</Platforms> </Platforms>
<ToolFiles>
</ToolFiles>
<Configurations> <Configurations>
<Configuration <Configuration
Name="Debug|Win32" Name="Debug|Win32"
OutputDirectory="Debug" OutputDirectory="Debug"
IntermediateDirectory="Debug" IntermediateDirectory="Debug"
ConfigurationType="2" ConfigurationType="2"
CharacterSet="2"> InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="0" Optimization="0"
AdditionalIncludeDirectories="..\..\include" AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;DLL_EXPORTS" PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;DLL_EXPORTS"
MinimalRebuild="TRUE" MinimalRebuild="true"
BasicRuntimeChecks="3" BasicRuntimeChecks="3"
RuntimeLibrary="1" RuntimeLibrary="1"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="true"
DebugInformationFormat="3"/> DebugInformationFormat="3"
/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="$(OutDir)/SoundTouchD.dll" OutputFile="$(OutDir)/SoundTouchD.dll"
LinkIncremental="2" LinkIncremental="2"
IgnoreDefaultLibraryNames="libcd" IgnoreDefaultLibraryNames="libcd"
GenerateDebugInformation="TRUE" GenerateDebugInformation="true"
ProgramDatabaseFile="$(OutDir)/SoundTouchD.pdb" ProgramDatabaseFile="$(OutDir)/SoundTouchD.pdb"
SubSystem="2" SubSystem="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/SoundTouchDllD.lib" ImportLibrary="$(OutDir)/SoundTouchDllD.lib"
TargetMachine="1"/> TargetMachine="1"
/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
CommandLine="copy $(OutDir)\*.dll ..\..\lib CommandLine="copy $(OutDir)\*.dll ..\..\lib&#x0D;&#x0A;copy $(OutDir)\*.lib ..\..\lib&#x0D;&#x0A;"
copy $(OutDir)\*.lib ..\..\lib />
"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
<Configuration <Configuration
Name="Release|Win32" Name="Release|Win32"
OutputDirectory="Release" OutputDirectory="Release"
IntermediateDirectory="Release" IntermediateDirectory="Release"
ConfigurationType="2" ConfigurationType="2"
CharacterSet="2"> InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC71.vsprops"
CharacterSet="2"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
Optimization="3" Optimization="3"
GlobalOptimizations="FALSE"
InlineFunctionExpansion="2" InlineFunctionExpansion="2"
EnableIntrinsicFunctions="TRUE" EnableIntrinsicFunctions="true"
OmitFramePointers="FALSE" OmitFramePointers="false"
AdditionalIncludeDirectories="..\..\include" AdditionalIncludeDirectories="..\..\include"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;DLL_EXPORTS" PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;_CRT_SECURE_NO_WARNINGS;DLL_EXPORTS"
RuntimeLibrary="0" RuntimeLibrary="0"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
Detect64BitPortabilityProblems="TRUE" Detect64BitPortabilityProblems="true"
DebugInformationFormat="0" DebugInformationFormat="0"
CallingConvention="0"/> CallingConvention="0"
/>
<Tool <Tool
Name="VCCustomBuildTool"/> Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool <Tool
Name="VCLinkerTool" Name="VCLinkerTool"
OutputFile="$(OutDir)/SoundTouch.dll" OutputFile="$(OutDir)/SoundTouch.dll"
LinkIncremental="1" LinkIncremental="1"
IgnoreDefaultLibraryNames="libc" IgnoreDefaultLibraryNames="libc"
GenerateDebugInformation="FALSE" GenerateDebugInformation="false"
GenerateMapFile="TRUE" GenerateMapFile="true"
SubSystem="2" SubSystem="2"
OptimizeReferences="2" OptimizeReferences="2"
EnableCOMDATFolding="2" EnableCOMDATFolding="2"
RandomizedBaseAddress="1"
DataExecutionPrevention="0"
ImportLibrary="$(OutDir)/SoundTouchDll.lib" ImportLibrary="$(OutDir)/SoundTouchDll.lib"
TargetMachine="1"/> TargetMachine="1"
/>
<Tool <Tool
Name="VCMIDLTool"/> Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool <Tool
Name="VCPostBuildEventTool" Name="VCPostBuildEventTool"
CommandLine="copy $(OutDir)\*.dll ..\..\lib CommandLine="copy $(OutDir)\*.dll ..\..\lib&#x0D;&#x0A;copy $(OutDir)\*.lib ..\..\lib&#x0D;&#x0A;"
copy $(OutDir)\*.lib ..\..\lib />
"/>
<Tool
Name="VCPreBuildEventTool"/>
<Tool
Name="VCPreLinkEventTool"/>
<Tool
Name="VCResourceCompilerTool"/>
<Tool
Name="VCWebServiceProxyGeneratorTool"/>
<Tool
Name="VCXMLDataGeneratorTool"/>
<Tool
Name="VCWebDeploymentTool"/>
<Tool
Name="VCManagedWrapperGeneratorTool"/>
<Tool
Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
</Configuration> </Configuration>
</Configurations> </Configurations>
<References> <References>
@ -130,32 +188,40 @@ copy $(OutDir)\*.lib ..\..\lib
<Filter <Filter
Name="Source Files" Name="Source Files"
Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx" Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"> UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
>
<File <File
RelativePath=".\SoundTouchDLL.cpp"> RelativePath=".\SoundTouchDLL.cpp"
>
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Header Files" Name="Header Files"
Filter="h;hpp;hxx;hm;inl;inc;xsd" Filter="h;hpp;hxx;hm;inl;inc;xsd"
UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"> UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
>
<File <File
RelativePath=".\resource.h"> RelativePath=".\resource.h"
>
</File> </File>
<File <File
RelativePath=".\SoundTouchDLL.h"> RelativePath=".\SoundTouchDLL.h"
>
</File> </File>
</Filter> </Filter>
<Filter <Filter
Name="Resource Files" Name="Resource Files"
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx" Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"> UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
>
<File <File
RelativePath=".\SoundTouchDLL.rc"> RelativePath=".\SoundTouchDLL.rc"
>
</File> </File>
</Filter> </Filter>
<File <File
RelativePath=".\ReadMe.txt"> RelativePath=".\ReadMe.txt"
>
</File> </File>
</Files> </Files>
<Globals> <Globals>