Soundtouch audio processing database source code analysis and algorithm extraction (3)
Soundtouch audio processing database Initialization Process Analysis 2
Next to soundtouch audio processing database initialization process
Relationship between the tdstretch class and the base class: Export osamplepipe-> export oprocessor-> tdstretch
The class tdstretch * ptdstretch variable of the soundtouch class is initialized in the soundtouch constructor.
Soundtouch: soundtouch.
Ptdstretch = tdstretch: newinstance ();
It is constructed by calling the tdstretch class member function newinstance (). The Code is as follows:
Tdstretch * tdstretch: newinstance ()
{
Uint uextensions;
Uextensions = detectcpuextensions ();
// Check if MMX/SSE/3 dnow! Instruction Set extensions supported by CPU
# Ifdef allow_mmx
// MMX routines available only with integer sample types
If (uextensions & support_mmx)
{
Return: New tdstretchmmx;
}
Else
# Endif // allow_mmx
# Ifdef allow_sse
If (uextensions & support_sse)
{
// SSE support
Return: New tdstretchsse;
}
Else
# Endif // allow_sse
# Ifdef allow_3dnow
If (uextensions & support_3dnow)
{
// 3 dnow! Support
Return: New tdstretch3dnow;
}
Else
# Endif // allow_3dnow
{
// ISA optimizations not supported, use plain C version
Return: New tdstretch;
}
}
Similar to pratetransposer, it also constructs a subclass that supports Multimedia Instruction Set processing by detecting the CPU enhancement instruction set. For different instruction sets, he derived tdstretchmmx, tdstretch3dnow, tdstretchsse for three classes of different instruction sets, mainly through the override tdstretch class member function calccrosw.stereo, if not, tdstretch's own class member function calccroscorrstereo will be used for processing, floating point Processing Using Double tdstretch: calccroscorrstereo (const float * mixingpos, const float * compare) const, fixed point Processing Using Double tdstretch :: calccroscorrstereo (const float * mixingpos, const float * compare) const, defined by macro # define integer_samples or # define float _ Samples for pre-compilation. Because tdstretchmmx, tdstretch3dnow, and tdstretchsse are just simple override class member functions calccroscorrstereo, there is no initialization, and naturally no constructor is written, therefore, the constructor generated by the compiler will be used for construction. For my competition CPU:
If (uextensions & support_mmx)
{
Return: New tdstretchmmx;
}
It constructs tdstretchmmx and returns a pointer to this class. Tdstretchmmx is constructed according to the following process:
Export osamplepipe-> export oprocessor-> tdstretch-> tdstretchmmx
According to the above analysis, we need to implement an algorithm for extending and compressing sound signals in the tdstretch class member function tdstretch: calccrosw.stereo, the three optimization codes for different CPUs are in the source file 3dnow_win.cpp, mmx_optimized.cpp, and see_optimized.cpp. For details about the calling parameters of the calccrosse corrstereo (const float * mixingpos, const float * compare) function, I 'd like to make a specific analysis later.
Return to our soundtouch constructor soundtouch: soundtouch ();
Soundtouch: soundtouch ()
{
// Initialize rate transposer and tempo changer instances
Pratetransposer = ratetransposer: newinstance ();
Ptdstretch = tdstretch: newinstance ();
Setoutpipe (ptdstretch );
Rate = tempo = 0;
Virtualpitch =
Virtualrate =
Virtualtempo = 1.0;
Calceffectiverateandtempo ();
Channels = 0;
Bsrateset = false;
}
Now we initialize a pratetransposer instance for processing the rate, and a ptdstretch instance for shortening the audio. The rest is to initialize some variables. Soundtouch m_soundtouch; the variable is instantiated.