1. Introduction

Have you encountered such a situation in which the tempo of a sound is too fast, you want to slow it down to make it more clear. Or you just want to joke with
your boyfriend by modifying his voice as if it was uttered by a female. This article will show you how to change the pitch and tempo of a sound
to achieve the above sound effect.

The article is organized as follows. Sections 2-4 introduce how to use cpct_dll.dll. Sections 5-7 illustrate how to develop cpct_dll.dll.
Section 8 shows how to use C# to wrap cpct_dll.dll into CpctDotNet.dll. Section 9 gives a simple demo. Conclusions are drawn in Section 10.

2. Interact with a .wav file

Download CPCT for Windows. You will find WavManipulateDll.dll in the package. It is used to interact with a .wav file. Some important APIs we will use are as follows:

DATA_LENGTH is the data length in each Wav data reading. When you have built the project, you will get cpct.exe. Copy cpct.exe, cpct_dll.dll,
WavManipulateDll.dll, and your .wav file into the same folder. Run commands on the console as follows:

4. CPCT for Linux

The process on Linux is similar to that on Windows. The substitute for cpct_dll.dll is libCpctDll.so, the substitute
for WavManipulateDll.dll is libWavManipulateDll.so.

5. Background knowledge on changing the pitch and tempo of a sound

In this part, I will introduce the background theory of cpct_dll.dll and how to develop cpct_dll.dll using C++. If you want to change a discrete signal sequence
like x(n), n= 1,2,..., you may simply modify each x(n) in the time domain. However, in many cases, we need to first transform the original signal into a frequency domain through
a Short Time Fourier Transform (STFT), then modify the spectrogram of the signal in the frequency domain, and finally transform the modified signal back to the time domain.

Short time analysis is an important analysis technology in sound processing. Sound signals like human speech, are time varying. However, in a very short time
span of about 10-20 millisecond order of magnitude, the parameters of the sound signal can be considered constant. So, we usually cut the sound signal into many small pieces
for analyzing and processing. Implementing STFT, we can get a parameter matrix of the original signal x(n), which we usually call spectrogram,
that can be considered as a representation of x(n) in the frequency domain. The horizontal axis denotes the lapsing time, the vertical axis denotes a frame of frequency parameters
at the right time spot. Daniel W. Griffin illustrated how to estimate a signal from a Modified Short-Time Fourier Transform in his paper "Signal Estimation from Modified
Short-Time Fourier Transform, IEEE Transactions on Acoustics, Speech, and Signal Processing".

5.1. How to change the tempo of a sound

Fig. 1 shows how to change the tempo of a sound. L is the length of the analysis window. La is the hop analysis length. Ls is the hop synthesis length.
If La > Ls, a faster sound will be produced, while La < Ls, a slower sound will be produced. In Fig. 1, when the tempo process is finished,
the length of the sound file will reduce. A faster sound is produced.

Fig.1 The process of changing the tempo of a sound

5.2. How to change the pitch of a sound

Fig. 2 shows how to change the pitch of a sound. The hop analysis length La is equal to the hop synthesis length. However, the analysis window L is
different from the synthesis window. L length sound data is resampled to L' length. If L > L', a higher pitch sound will be produced, while L < L', a lower pitch sound will be produced.
In Fig. 2, when the pitch process is finished, the length of the sound file is the same. A higher pitch sound is produced.

Fig. 2 The process of changing the pitch of a sound

6. Design of the CPCT library

All things are defined in the namespace CPCT. The most important functions are void tsm() and void pm().
The principles of void tsm() and void pm() are illustrated above. The fast Fourier transform function void fft1(...)
and the resampling function int resample(...) are from the class aflibFFT and class aflibConverter. The two classes
are from the free Open Source Audio Library Project (OSALP).

8. CpctDotNetDll: A C# wrapper for cpct_dll.dll

.NET development is now more and more popular. GUI development is very easy in C#. In this part, I will try to use C# to wrap cpct_dll.dll.
I hope it will make it convenient for .NET developers to use the CPCT library.

cpct_dll.dll exposes six functions, including createCpctByDefault(), createCpctByParams(...), setData(...), setParams(...),
getData(...), and destroyCpct(...). The following code is used to wrap these six APIs:

Hi.
Thanks for sharing this code. As a programmer i'm happy with it, to learn the theory of this field. For other users, which only want to use the resulting tool, there should be some things pointed out:
- as far as i could try, only mono 16 bits wav files are processed, the rest just let the app crash
- Sounds quality of the result is not comparable to the 'professional' pitch apps
- pitch change -12 to 12: one digit is not equal one semi tone
- it can't handle spaces in the file names
- it takes a minute for a normal song, and no feedback in between

I have tried to use your DLLs with Borland C++ Builder
But exported functions can't link to make application.
How do you know why?
By the way, could you tell me more detail about design WavManipulateDll.dll?

You needn't to be so cynical. This article focuses on how to change the tempo and pitch of a sound. Google tells you how to port android to arm platform, tells you everything about android. However google needn't to tell you how arm architecture is designed. If you want to get the knowledge about arm, you'd better contact with ARM instead of Google.

So why does the title of the article indicate that the focus of the article is something different?
Shouldn't the title of the article be something like "How to use cpct_dll to manipulate sound files" ??