├── .gitattributes ├── .gitignore ├── assets ├── 1526981472041.png ├── 1527062406650.png ├── 1527066610820.png └── 1527069146098.png ├── pitchshifting.sln ├── pitchshifting ├── AudioFile.cpp ├── Library │ └── fftw_32 │ │ ├── libfftw3-3.dll │ │ ├── libfftw3-3.lib │ │ ├── libfftw3f-3.dll │ │ ├── libfftw3f-3.lib │ │ ├── libfftw3l-3.dll │ │ └── libfftw3l-3.lib ├── audioCut_2.wav ├── include │ ├── AudioFile.h │ └── fftw3.h ├── pitchshifting.cpp ├── pitchshifting.vcxproj ├── pitchshifting.vcxproj.filters ├── stdafx.cpp ├── stdafx.h ├── targetver.h └── wav.vcxproj └── readme.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | *.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | project.fragment.lock.json 46 | artifacts/ 47 | 48 | *_i.c 49 | *_p.c 50 | *_i.h 51 | *.ilk 52 | *.meta 53 | *.obj 54 | *.pch 55 | *.pdb 56 | *.pgc 57 | *.pgd 58 | *.rsp 59 | *.sbr 60 | *.tlb 61 | *.tli 62 | *.tlh 63 | *.tmp 64 | *.tmp_proj 65 | *.log 66 | *.vspscc 67 | *.vssscc 68 | .builds 69 | *.pidb 70 | *.svclog 71 | *.scc 72 | 73 | # Chutzpah Test files 74 | _Chutzpah* 75 | 76 | # Visual C++ cache files 77 | ipch/ 78 | *.aps 79 | *.ncb 80 | *.opendb 81 | *.opensdf 82 | *.sdf 83 | *.cachefile 84 | *.VC.db 85 | *.VC.VC.opendb 86 | 87 | # Visual Studio profiler 88 | *.psess 89 | *.vsp 90 | *.vspx 91 | *.sap 92 | 93 | # TFS 2012 Local Workspace 94 | $tf/ 95 | 96 | # Guidance Automation Toolkit 97 | *.gpState 98 | 99 | # ReSharper is a .NET coding add-in 100 | _ReSharper*/ 101 | *.[Rr]e[Ss]harper 102 | *.DotSettings.user 103 | 104 | # JustCode is a .NET coding add-in 105 | .JustCode 106 | 107 | # TeamCity is a build add-in 108 | _TeamCity* 109 | 110 | # DotCover is a Code Coverage Tool 111 | *.dotCover 112 | 113 | # NCrunch 114 | _NCrunch_* 115 | .*crunch*.local.xml 116 | nCrunchTemp_* 117 | 118 | # MightyMoose 119 | *.mm.* 120 | AutoTest.Net/ 121 | 122 | # Web workbench (sass) 123 | .sass-cache/ 124 | 125 | # Installshield output folder 126 | [Ee]xpress/ 127 | 128 | # DocProject is a documentation generator add-in 129 | DocProject/buildhelp/ 130 | DocProject/Help/*.HxT 131 | DocProject/Help/*.HxC 132 | DocProject/Help/*.hhc 133 | DocProject/Help/*.hhk 134 | DocProject/Help/*.hhp 135 | DocProject/Help/Html2 136 | DocProject/Help/html 137 | 138 | # Click-Once directory 139 | publish/ 140 | 141 | # Publish Web Output 142 | *.[Pp]ublish.xml 143 | *.azurePubxml 144 | # TODO: Comment the next line if you want to checkin your web deploy settings 145 | # but database connection strings (with potential passwords) will be unencrypted 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 150 | # checkin your Azure Web App publish settings, but sensitive information contained 151 | # in these scripts will be unencrypted 152 | PublishScripts/ 153 | 154 | # NuGet Packages 155 | *.nupkg 156 | # The packages folder can be ignored because of Package Restore 157 | **/packages/* 158 | # except build/, which is used as an MSBuild target. 159 | !**/packages/build/ 160 | # Uncomment if necessary however generally it will be regenerated when needed 161 | #!**/packages/repositories.config 162 | # NuGet v3's project.json files produces more ignoreable files 163 | *.nuget.props 164 | *.nuget.targets 165 | 166 | # Microsoft Azure Build Output 167 | csx/ 168 | *.build.csdef 169 | 170 | # Microsoft Azure Emulator 171 | ecf/ 172 | rcf/ 173 | 174 | # Windows Store app package directories and files 175 | AppPackages/ 176 | BundleArtifacts/ 177 | Package.StoreAssociation.xml 178 | _pkginfo.txt 179 | 180 | # Visual Studio cache files 181 | # files ending in .cache can be ignored 182 | *.[Cc]ache 183 | # but keep track of directories ending in .cache 184 | !*.[Cc]ache/ 185 | 186 | # Others 187 | ClientBin/ 188 | ~$* 189 | *~ 190 | *.dbmdl 191 | *.dbproj.schemaview 192 | *.jfm 193 | *.pfx 194 | *.publishsettings 195 | node_modules/ 196 | orleans.codegen.cs 197 | 198 | # Since there are multiple workflows, uncomment next line to ignore bower_components 199 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 200 | #bower_components/ 201 | 202 | # RIA/Silverlight projects 203 | Generated_Code/ 204 | 205 | # Backup & report files from converting an old project file 206 | # to a newer Visual Studio version. Backup files are not needed, 207 | # because we have git ;-) 208 | _UpgradeReport_Files/ 209 | Backup*/ 210 | UpgradeLog*.XML 211 | UpgradeLog*.htm 212 | 213 | # SQL Server files 214 | *.mdf 215 | *.ldf 216 | 217 | # Business Intelligence projects 218 | *.rdl.data 219 | *.bim.layout 220 | *.bim_*.settings 221 | 222 | # Microsoft Fakes 223 | FakesAssemblies/ 224 | 225 | # GhostDoc plugin setting file 226 | *.GhostDoc.xml 227 | 228 | # Node.js Tools for Visual Studio 229 | .ntvs_analysis.dat 230 | 231 | # Visual Studio 6 build log 232 | *.plg 233 | 234 | # Visual Studio 6 workspace options file 235 | *.opt 236 | 237 | # Visual Studio LightSwitch build output 238 | **/*.HTMLClient/GeneratedArtifacts 239 | **/*.DesktopClient/GeneratedArtifacts 240 | **/*.DesktopClient/ModelManifest.xml 241 | **/*.Server/GeneratedArtifacts 242 | **/*.Server/ModelManifest.xml 243 | _Pvt_Extensions 244 | 245 | # Paket dependency manager 246 | .paket/paket.exe 247 | paket-files/ 248 | 249 | # FAKE - F# Make 250 | .fake/ 251 | 252 | # JetBrains Rider 253 | .idea/ 254 | *.sln.iml 255 | 256 | # CodeRush 257 | .cr/ 258 | 259 | # Python Tools for Visual Studio (PTVS) 260 | __pycache__/ 261 | *.pyc -------------------------------------------------------------------------------- /assets/1526981472041.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/assets/1526981472041.png -------------------------------------------------------------------------------- /assets/1527062406650.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/assets/1527062406650.png -------------------------------------------------------------------------------- /assets/1527066610820.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/assets/1527066610820.png -------------------------------------------------------------------------------- /assets/1527069146098.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/assets/1527069146098.png -------------------------------------------------------------------------------- /pitchshifting.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 15 4 | VisualStudioVersion = 15.0.27703.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pitchshifting", "pitchshifting\pitchshifting.vcxproj", "{F67C049B-AC7F-48C9-A87C-C398E417CD63}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Debug|x64.ActiveCfg = Debug|x64 17 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Debug|x64.Build.0 = Debug|x64 18 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Debug|x86.ActiveCfg = Debug|Win32 19 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Debug|x86.Build.0 = Debug|Win32 20 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Release|x64.ActiveCfg = Release|x64 21 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Release|x64.Build.0 = Release|x64 22 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Release|x86.ActiveCfg = Release|Win32 23 | {F67C049B-AC7F-48C9-A87C-C398E417CD63}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {71F276E6-FC1A-42A6-96C9-EBEA7D2FBB07} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /pitchshifting/AudioFile.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/AudioFile.cpp -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3-3.dll -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3-3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3-3.lib -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3f-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3f-3.dll -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3f-3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3f-3.lib -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3l-3.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3l-3.dll -------------------------------------------------------------------------------- /pitchshifting/Library/fftw_32/libfftw3l-3.lib: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/Library/fftw_32/libfftw3l-3.lib -------------------------------------------------------------------------------- /pitchshifting/audioCut_2.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/audioCut_2.wav -------------------------------------------------------------------------------- /pitchshifting/include/AudioFile.h: -------------------------------------------------------------------------------- 1 | //======================================================================= 2 | /** @file AudioFile.h 3 | * @author Adam Stark 4 | * @copyright Copyright (C) 2017 Adam Stark 5 | * 6 | * This file is part of the 'AudioFile' library 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. 12 | * 13 | * This program is distributed in the hope that it will be useful, 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 | * GNU General Public License for more details. 17 | * 18 | * You should have received a copy of the GNU General Public License 19 | * along with this program. If not, see . 20 | */ 21 | //======================================================================= 22 | 23 | #ifndef _AS_AudioFile_h 24 | #define _AS_AudioFile_h 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | 32 | //============================================================= 33 | /** The different types of audio file, plus some other types to 34 | * indicate a failure to load a file, or that one hasn't been 35 | * loaded yet 36 | */ 37 | enum class AudioFileFormat 38 | { 39 | Error, 40 | NotLoaded, 41 | Wave, 42 | Aiff 43 | }; 44 | 45 | //============================================================= 46 | template 47 | class AudioFile 48 | { 49 | public: 50 | 51 | //============================================================= 52 | typedef std::vector > AudioBuffer; 53 | 54 | //============================================================= 55 | /** Constructor */ 56 | AudioFile(); 57 | 58 | //============================================================= 59 | /** Loads an audio file from a given file path. 60 | * @Returns true if the file was successfully loaded 61 | */ 62 | bool load (std::string filePath); 63 | 64 | /** Saves an audio file to a given file path. 65 | * @Returns true if the file was successfully saved 66 | */ 67 | bool save (std::string filePath, AudioFileFormat format = AudioFileFormat::Wave); 68 | 69 | //============================================================= 70 | /** @Returns the sample rate */ 71 | uint32_t getSampleRate() const; 72 | 73 | /** @Returns the number of audio channels in the buffer */ 74 | int getNumChannels() const; 75 | 76 | /** @Returns true if the audio file is mono */ 77 | bool isMono() const; 78 | 79 | /** @Returns true if the audio file is stereo */ 80 | bool isStereo() const; 81 | 82 | /** @Returns the bit depth of each sample */ 83 | int getBitDepth() const; 84 | 85 | /** @Returns the number of samples per channel */ 86 | int getNumSamplesPerChannel() const; 87 | 88 | /** @Returns the length in seconds of the audio file based on the number of samples and sample rate */ 89 | double getLengthInSeconds() const; 90 | 91 | /** Prints a summary of the audio file to the console */ 92 | void printSummary() const; 93 | 94 | //============================================================= 95 | 96 | /** Set the audio buffer for this AudioFile by copying samples from another buffer. 97 | * @Returns true if the buffer was copied successfully. 98 | */ 99 | bool setAudioBuffer (AudioBuffer& newBuffer); 100 | 101 | /** Sets the audio buffer to a given number of channels and number of samples per channel. This will try to preserve 102 | * the existing audio, adding zeros to any new channels or new samples in a given channel. 103 | */ 104 | void setAudioBufferSize (int numChannels, int numSamples); 105 | 106 | /** Sets the number of samples per channel in the audio buffer. This will try to preserve 107 | * the existing audio, adding zeros to new samples in a given channel if the number of samples is increased. 108 | */ 109 | void setNumSamplesPerChannel (int numSamples); 110 | 111 | /** Sets the number of channels. New channels will have the correct number of samples and be initialised to zero */ 112 | void setNumChannels (int numChannels); 113 | 114 | /** Sets the bit depth for the audio file. If you use the save() function, this bit depth rate will be used */ 115 | void setBitDepth (int numBitsPerSample); 116 | 117 | /** Sets the sample rate for the audio file. If you use the save() function, this sample rate will be used */ 118 | void setSampleRate (uint32_t newSampleRate); 119 | 120 | //============================================================= 121 | /** A vector of vectors holding the audio samples for the AudioFile. You can 122 | * access the samples by channel and then by sample index, i.e: 123 | * 124 | * samples[channel][sampleIndex] 125 | */ 126 | AudioBuffer samples; 127 | 128 | private: 129 | 130 | //============================================================= 131 | enum class Endianness 132 | { 133 | LittleEndian, 134 | BigEndian 135 | }; 136 | 137 | //============================================================= 138 | AudioFileFormat determineAudioFileFormat (std::vector& fileData); 139 | bool decodeWaveFile (std::vector& fileData); 140 | bool decodeAiffFile (std::vector& fileData); 141 | 142 | //============================================================= 143 | bool saveToWaveFile (std::string filePath); 144 | bool saveToAiffFile (std::string filePath); 145 | 146 | //============================================================= 147 | void clearAudioBuffer(); 148 | 149 | //============================================================= 150 | int32_t fourBytesToInt (std::vector& source, int startIndex, Endianness endianness = Endianness::LittleEndian); 151 | int16_t twoBytesToInt (std::vector& source, int startIndex, Endianness endianness = Endianness::LittleEndian); 152 | int getIndexOfString (std::vector& source, std::string s); 153 | T sixteenBitIntToSample (int16_t sample); 154 | uint32_t getAiffSampleRate (std::vector& fileData, int sampleRateStartIndex); 155 | bool tenByteMatch (std::vector& v1, int startIndex1, std::vector& v2, int startIndex2); 156 | void addSampleRateToAiffData (std::vector& fileData, uint32_t sampleRate); 157 | 158 | //============================================================= 159 | void addStringToFileData (std::vector& fileData, std::string s); 160 | void addInt32ToFileData (std::vector& fileData, int32_t i, Endianness endianness = Endianness::LittleEndian); 161 | void addInt16ToFileData (std::vector& fileData, int16_t i, Endianness endianness = Endianness::LittleEndian); 162 | 163 | //============================================================= 164 | bool writeDataToFile (std::vector& fileData, std::string filePath); 165 | 166 | //============================================================= 167 | AudioFileFormat audioFileFormat; 168 | uint32_t sampleRate; 169 | int bitDepth; 170 | }; 171 | 172 | #endif /* AudioFile_h */ 173 | -------------------------------------------------------------------------------- /pitchshifting/include/fftw3.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2003, 2007-14 Matteo Frigo 3 | * Copyright (c) 2003, 2007-14 Massachusetts Institute of Technology 4 | * 5 | * The following statement of license applies *only* to this header file, 6 | * and *not* to the other files distributed with FFTW or derived therefrom: 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 12 | * 1. Redistributions of source code must retain the above copyright 13 | * notice, this list of conditions and the following disclaimer. 14 | * 15 | * 2. Redistributions in binary form must reproduce the above copyright 16 | * notice, this list of conditions and the following disclaimer in the 17 | * documentation and/or other materials provided with the distribution. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS 20 | * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 21 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 23 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 25 | * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 27 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | */ 31 | 32 | /***************************** NOTE TO USERS ********************************* 33 | * 34 | * THIS IS A HEADER FILE, NOT A MANUAL 35 | * 36 | * If you want to know how to use FFTW, please read the manual, 37 | * online at http://www.fftw.org/doc/ and also included with FFTW. 38 | * For a quick start, see the manual's tutorial section. 39 | * 40 | * (Reading header files to learn how to use a library is a habit 41 | * stemming from code lacking a proper manual. Arguably, it's a 42 | * *bad* habit in most cases, because header files can contain 43 | * interfaces that are not part of the public, stable API.) 44 | * 45 | ****************************************************************************/ 46 | 47 | #ifndef FFTW3_H 48 | #define FFTW3_H 49 | 50 | #include 51 | 52 | #ifdef __cplusplus 53 | extern "C" 54 | { 55 | #endif /* __cplusplus */ 56 | 57 | /* If is included, use the C99 complex type. Otherwise 58 | define a type bit-compatible with C99 complex */ 59 | #if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 60 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R _Complex C 61 | #else 62 | # define FFTW_DEFINE_COMPLEX(R, C) typedef R C[2] 63 | #endif 64 | 65 | #define FFTW_CONCAT(prefix, name) prefix ## name 66 | #define FFTW_MANGLE_DOUBLE(name) FFTW_CONCAT(fftw_, name) 67 | #define FFTW_MANGLE_FLOAT(name) FFTW_CONCAT(fftwf_, name) 68 | #define FFTW_MANGLE_LONG_DOUBLE(name) FFTW_CONCAT(fftwl_, name) 69 | #define FFTW_MANGLE_QUAD(name) FFTW_CONCAT(fftwq_, name) 70 | 71 | /* IMPORTANT: for Windows compilers, you should add a line 72 | */ 73 | #define FFTW_DLL 74 | /* 75 | here and in kernel/ifftw.h if you are compiling/using FFTW as a 76 | DLL, in order to do the proper importing/exporting, or 77 | alternatively compile with -DFFTW_DLL or the equivalent 78 | command-line flag. This is not necessary under MinGW/Cygwin, where 79 | libtool does the imports/exports automatically. */ 80 | #if defined(FFTW_DLL) && (defined(_WIN32) || defined(__WIN32__)) 81 | /* annoying Windows syntax for shared-library declarations */ 82 | # if defined(COMPILING_FFTW) /* defined in api.h when compiling FFTW */ 83 | # define FFTW_EXTERN extern __declspec(dllexport) 84 | # else /* user is calling FFTW; import symbol */ 85 | # define FFTW_EXTERN extern __declspec(dllimport) 86 | # endif 87 | #else 88 | # define FFTW_EXTERN extern 89 | #endif 90 | 91 | enum fftw_r2r_kind_do_not_use_me { 92 | FFTW_R2HC=0, FFTW_HC2R=1, FFTW_DHT=2, 93 | FFTW_REDFT00=3, FFTW_REDFT01=4, FFTW_REDFT10=5, FFTW_REDFT11=6, 94 | FFTW_RODFT00=7, FFTW_RODFT01=8, FFTW_RODFT10=9, FFTW_RODFT11=10 95 | }; 96 | 97 | struct fftw_iodim_do_not_use_me { 98 | int n; /* dimension size */ 99 | int is; /* input stride */ 100 | int os; /* output stride */ 101 | }; 102 | 103 | #include /* for ptrdiff_t */ 104 | struct fftw_iodim64_do_not_use_me { 105 | ptrdiff_t n; /* dimension size */ 106 | ptrdiff_t is; /* input stride */ 107 | ptrdiff_t os; /* output stride */ 108 | }; 109 | 110 | typedef void (*fftw_write_char_func_do_not_use_me)(char c, void *); 111 | typedef int (*fftw_read_char_func_do_not_use_me)(void *); 112 | 113 | /* 114 | huge second-order macro that defines prototypes for all API 115 | functions. We expand this macro for each supported precision 116 | 117 | X: name-mangling macro 118 | R: real data type 119 | C: complex data type 120 | */ 121 | 122 | #define FFTW_DEFINE_API(X, R, C) \ 123 | \ 124 | FFTW_DEFINE_COMPLEX(R, C); \ 125 | \ 126 | typedef struct X(plan_s) *X(plan); \ 127 | \ 128 | typedef struct fftw_iodim_do_not_use_me X(iodim); \ 129 | typedef struct fftw_iodim64_do_not_use_me X(iodim64); \ 130 | \ 131 | typedef enum fftw_r2r_kind_do_not_use_me X(r2r_kind); \ 132 | \ 133 | typedef fftw_write_char_func_do_not_use_me X(write_char_func); \ 134 | typedef fftw_read_char_func_do_not_use_me X(read_char_func); \ 135 | \ 136 | FFTW_EXTERN void X(execute)(const X(plan) p); \ 137 | \ 138 | FFTW_EXTERN X(plan) X(plan_dft)(int rank, const int *n, \ 139 | C *in, C *out, int sign, unsigned flags); \ 140 | \ 141 | FFTW_EXTERN X(plan) X(plan_dft_1d)(int n, C *in, C *out, int sign, \ 142 | unsigned flags); \ 143 | FFTW_EXTERN X(plan) X(plan_dft_2d)(int n0, int n1, \ 144 | C *in, C *out, int sign, unsigned flags); \ 145 | FFTW_EXTERN X(plan) X(plan_dft_3d)(int n0, int n1, int n2, \ 146 | C *in, C *out, int sign, unsigned flags); \ 147 | \ 148 | FFTW_EXTERN X(plan) X(plan_many_dft)(int rank, const int *n, \ 149 | int howmany, \ 150 | C *in, const int *inembed, \ 151 | int istride, int idist, \ 152 | C *out, const int *onembed, \ 153 | int ostride, int odist, \ 154 | int sign, unsigned flags); \ 155 | \ 156 | FFTW_EXTERN X(plan) X(plan_guru_dft)(int rank, const X(iodim) *dims, \ 157 | int howmany_rank, \ 158 | const X(iodim) *howmany_dims, \ 159 | C *in, C *out, \ 160 | int sign, unsigned flags); \ 161 | FFTW_EXTERN X(plan) X(plan_guru_split_dft)(int rank, const X(iodim) *dims, \ 162 | int howmany_rank, \ 163 | const X(iodim) *howmany_dims, \ 164 | R *ri, R *ii, R *ro, R *io, \ 165 | unsigned flags); \ 166 | \ 167 | FFTW_EXTERN X(plan) X(plan_guru64_dft)(int rank, \ 168 | const X(iodim64) *dims, \ 169 | int howmany_rank, \ 170 | const X(iodim64) *howmany_dims, \ 171 | C *in, C *out, \ 172 | int sign, unsigned flags); \ 173 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft)(int rank, \ 174 | const X(iodim64) *dims, \ 175 | int howmany_rank, \ 176 | const X(iodim64) *howmany_dims, \ 177 | R *ri, R *ii, R *ro, R *io, \ 178 | unsigned flags); \ 179 | \ 180 | FFTW_EXTERN void X(execute_dft)(const X(plan) p, C *in, C *out); \ 181 | FFTW_EXTERN void X(execute_split_dft)(const X(plan) p, R *ri, R *ii, \ 182 | R *ro, R *io); \ 183 | \ 184 | FFTW_EXTERN X(plan) X(plan_many_dft_r2c)(int rank, const int *n, \ 185 | int howmany, \ 186 | R *in, const int *inembed, \ 187 | int istride, int idist, \ 188 | C *out, const int *onembed, \ 189 | int ostride, int odist, \ 190 | unsigned flags); \ 191 | \ 192 | FFTW_EXTERN X(plan) X(plan_dft_r2c)(int rank, const int *n, \ 193 | R *in, C *out, unsigned flags); \ 194 | \ 195 | FFTW_EXTERN X(plan) X(plan_dft_r2c_1d)(int n,R *in,C *out,unsigned flags); \ 196 | FFTW_EXTERN X(plan) X(plan_dft_r2c_2d)(int n0, int n1, \ 197 | R *in, C *out, unsigned flags); \ 198 | FFTW_EXTERN X(plan) X(plan_dft_r2c_3d)(int n0, int n1, \ 199 | int n2, \ 200 | R *in, C *out, unsigned flags); \ 201 | \ 202 | \ 203 | FFTW_EXTERN X(plan) X(plan_many_dft_c2r)(int rank, const int *n, \ 204 | int howmany, \ 205 | C *in, const int *inembed, \ 206 | int istride, int idist, \ 207 | R *out, const int *onembed, \ 208 | int ostride, int odist, \ 209 | unsigned flags); \ 210 | \ 211 | FFTW_EXTERN X(plan) X(plan_dft_c2r)(int rank, const int *n, \ 212 | C *in, R *out, unsigned flags); \ 213 | \ 214 | FFTW_EXTERN X(plan) X(plan_dft_c2r_1d)(int n,C *in,R *out,unsigned flags); \ 215 | FFTW_EXTERN X(plan) X(plan_dft_c2r_2d)(int n0, int n1, \ 216 | C *in, R *out, unsigned flags); \ 217 | FFTW_EXTERN X(plan) X(plan_dft_c2r_3d)(int n0, int n1, \ 218 | int n2, \ 219 | C *in, R *out, unsigned flags); \ 220 | \ 221 | FFTW_EXTERN X(plan) X(plan_guru_dft_r2c)(int rank, const X(iodim) *dims, \ 222 | int howmany_rank, \ 223 | const X(iodim) *howmany_dims, \ 224 | R *in, C *out, \ 225 | unsigned flags); \ 226 | FFTW_EXTERN X(plan) X(plan_guru_dft_c2r)(int rank, const X(iodim) *dims, \ 227 | int howmany_rank, \ 228 | const X(iodim) *howmany_dims, \ 229 | C *in, R *out, \ 230 | unsigned flags); \ 231 | \ 232 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_r2c)( \ 233 | int rank, const X(iodim) *dims, \ 234 | int howmany_rank, \ 235 | const X(iodim) *howmany_dims, \ 236 | R *in, R *ro, R *io, \ 237 | unsigned flags); \ 238 | FFTW_EXTERN X(plan) X(plan_guru_split_dft_c2r)( \ 239 | int rank, const X(iodim) *dims, \ 240 | int howmany_rank, \ 241 | const X(iodim) *howmany_dims, \ 242 | R *ri, R *ii, R *out, \ 243 | unsigned flags); \ 244 | \ 245 | FFTW_EXTERN X(plan) X(plan_guru64_dft_r2c)(int rank, \ 246 | const X(iodim64) *dims, \ 247 | int howmany_rank, \ 248 | const X(iodim64) *howmany_dims, \ 249 | R *in, C *out, \ 250 | unsigned flags); \ 251 | FFTW_EXTERN X(plan) X(plan_guru64_dft_c2r)(int rank, \ 252 | const X(iodim64) *dims, \ 253 | int howmany_rank, \ 254 | const X(iodim64) *howmany_dims, \ 255 | C *in, R *out, \ 256 | unsigned flags); \ 257 | \ 258 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_r2c)( \ 259 | int rank, const X(iodim64) *dims, \ 260 | int howmany_rank, \ 261 | const X(iodim64) *howmany_dims, \ 262 | R *in, R *ro, R *io, \ 263 | unsigned flags); \ 264 | FFTW_EXTERN X(plan) X(plan_guru64_split_dft_c2r)( \ 265 | int rank, const X(iodim64) *dims, \ 266 | int howmany_rank, \ 267 | const X(iodim64) *howmany_dims, \ 268 | R *ri, R *ii, R *out, \ 269 | unsigned flags); \ 270 | \ 271 | FFTW_EXTERN void X(execute_dft_r2c)(const X(plan) p, R *in, C *out); \ 272 | FFTW_EXTERN void X(execute_dft_c2r)(const X(plan) p, C *in, R *out); \ 273 | \ 274 | FFTW_EXTERN void X(execute_split_dft_r2c)(const X(plan) p, \ 275 | R *in, R *ro, R *io); \ 276 | FFTW_EXTERN void X(execute_split_dft_c2r)(const X(plan) p, \ 277 | R *ri, R *ii, R *out); \ 278 | \ 279 | FFTW_EXTERN X(plan) X(plan_many_r2r)(int rank, const int *n, \ 280 | int howmany, \ 281 | R *in, const int *inembed, \ 282 | int istride, int idist, \ 283 | R *out, const int *onembed, \ 284 | int ostride, int odist, \ 285 | const X(r2r_kind) *kind, unsigned flags); \ 286 | \ 287 | FFTW_EXTERN X(plan) X(plan_r2r)(int rank, const int *n, R *in, R *out, \ 288 | const X(r2r_kind) *kind, unsigned flags); \ 289 | \ 290 | FFTW_EXTERN X(plan) X(plan_r2r_1d)(int n, R *in, R *out, \ 291 | X(r2r_kind) kind, unsigned flags); \ 292 | FFTW_EXTERN X(plan) X(plan_r2r_2d)(int n0, int n1, R *in, R *out, \ 293 | X(r2r_kind) kind0, X(r2r_kind) kind1, \ 294 | unsigned flags); \ 295 | FFTW_EXTERN X(plan) X(plan_r2r_3d)(int n0, int n1, int n2, \ 296 | R *in, R *out, X(r2r_kind) kind0, \ 297 | X(r2r_kind) kind1, X(r2r_kind) kind2, \ 298 | unsigned flags); \ 299 | \ 300 | FFTW_EXTERN X(plan) X(plan_guru_r2r)(int rank, const X(iodim) *dims, \ 301 | int howmany_rank, \ 302 | const X(iodim) *howmany_dims, \ 303 | R *in, R *out, \ 304 | const X(r2r_kind) *kind, unsigned flags); \ 305 | \ 306 | FFTW_EXTERN X(plan) X(plan_guru64_r2r)(int rank, const X(iodim64) *dims, \ 307 | int howmany_rank, \ 308 | const X(iodim64) *howmany_dims, \ 309 | R *in, R *out, \ 310 | const X(r2r_kind) *kind, unsigned flags); \ 311 | \ 312 | FFTW_EXTERN void X(execute_r2r)(const X(plan) p, R *in, R *out); \ 313 | \ 314 | FFTW_EXTERN void X(destroy_plan)(X(plan) p); \ 315 | FFTW_EXTERN void X(forget_wisdom)(void); \ 316 | FFTW_EXTERN void X(cleanup)(void); \ 317 | \ 318 | FFTW_EXTERN void X(set_timelimit)(double t); \ 319 | \ 320 | FFTW_EXTERN void X(plan_with_nthreads)(int nthreads); \ 321 | FFTW_EXTERN int X(init_threads)(void); \ 322 | FFTW_EXTERN void X(cleanup_threads)(void); \ 323 | FFTW_EXTERN void X(make_planner_thread_safe)(void); \ 324 | \ 325 | FFTW_EXTERN int X(export_wisdom_to_filename)(const char *filename); \ 326 | FFTW_EXTERN void X(export_wisdom_to_file)(FILE *output_file); \ 327 | FFTW_EXTERN char *X(export_wisdom_to_string)(void); \ 328 | FFTW_EXTERN void X(export_wisdom)(X(write_char_func) write_char, \ 329 | void *data); \ 330 | FFTW_EXTERN int X(import_system_wisdom)(void); \ 331 | FFTW_EXTERN int X(import_wisdom_from_filename)(const char *filename); \ 332 | FFTW_EXTERN int X(import_wisdom_from_file)(FILE *input_file); \ 333 | FFTW_EXTERN int X(import_wisdom_from_string)(const char *input_string); \ 334 | FFTW_EXTERN int X(import_wisdom)(X(read_char_func) read_char, void *data); \ 335 | \ 336 | FFTW_EXTERN void X(fprint_plan)(const X(plan) p, FILE *output_file); \ 337 | FFTW_EXTERN void X(print_plan)(const X(plan) p); \ 338 | FFTW_EXTERN char *X(sprint_plan)(const X(plan) p); \ 339 | \ 340 | FFTW_EXTERN void *X(malloc)(size_t n); \ 341 | FFTW_EXTERN R *X(alloc_real)(size_t n); \ 342 | FFTW_EXTERN C *X(alloc_complex)(size_t n); \ 343 | FFTW_EXTERN void X(free)(void *p); \ 344 | \ 345 | FFTW_EXTERN void X(flops)(const X(plan) p, \ 346 | double *add, double *mul, double *fmas); \ 347 | FFTW_EXTERN double X(estimate_cost)(const X(plan) p); \ 348 | FFTW_EXTERN double X(cost)(const X(plan) p); \ 349 | \ 350 | FFTW_EXTERN int X(alignment_of)(R *p); \ 351 | FFTW_EXTERN const char X(version)[]; \ 352 | FFTW_EXTERN const char X(cc)[]; \ 353 | FFTW_EXTERN const char X(codelet_optim)[]; 354 | 355 | 356 | /* end of FFTW_DEFINE_API macro */ 357 | 358 | FFTW_DEFINE_API(FFTW_MANGLE_DOUBLE, double, fftw_complex) 359 | FFTW_DEFINE_API(FFTW_MANGLE_FLOAT, float, fftwf_complex) 360 | FFTW_DEFINE_API(FFTW_MANGLE_LONG_DOUBLE, long double, fftwl_complex) 361 | 362 | /* __float128 (quad precision) is a gcc extension on i386, x86_64, and ia64 363 | for gcc >= 4.6 (compiled in FFTW with --enable-quad-precision) */ 364 | #if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) \ 365 | && !(defined(__ICC) || defined(__INTEL_COMPILER) || defined(__CUDACC__) || defined(__PGI)) \ 366 | && (defined(__i386__) || defined(__x86_64__) || defined(__ia64__)) 367 | # if !defined(FFTW_NO_Complex) && defined(_Complex_I) && defined(complex) && defined(I) 368 | /* note: __float128 is a typedef, which is not supported with the _Complex 369 | keyword in gcc, so instead we use this ugly __attribute__ version. 370 | However, we can't simply pass the __attribute__ version to 371 | FFTW_DEFINE_API because the __attribute__ confuses gcc in pointer 372 | types. Hence redefining FFTW_DEFINE_COMPLEX. Ugh. */ 373 | # undef FFTW_DEFINE_COMPLEX 374 | # define FFTW_DEFINE_COMPLEX(R, C) typedef _Complex float __attribute__((mode(TC))) C 375 | # endif 376 | FFTW_DEFINE_API(FFTW_MANGLE_QUAD, __float128, fftwq_complex) 377 | #endif 378 | 379 | #define FFTW_FORWARD (-1) 380 | #define FFTW_BACKWARD (+1) 381 | 382 | #define FFTW_NO_TIMELIMIT (-1.0) 383 | 384 | /* documented flags */ 385 | #define FFTW_MEASURE (0U) 386 | #define FFTW_DESTROY_INPUT (1U << 0) 387 | #define FFTW_UNALIGNED (1U << 1) 388 | #define FFTW_CONSERVE_MEMORY (1U << 2) 389 | #define FFTW_EXHAUSTIVE (1U << 3) /* NO_EXHAUSTIVE is default */ 390 | #define FFTW_PRESERVE_INPUT (1U << 4) /* cancels FFTW_DESTROY_INPUT */ 391 | #define FFTW_PATIENT (1U << 5) /* IMPATIENT is default */ 392 | #define FFTW_ESTIMATE (1U << 6) 393 | #define FFTW_WISDOM_ONLY (1U << 21) 394 | 395 | /* undocumented beyond-guru flags */ 396 | #define FFTW_ESTIMATE_PATIENT (1U << 7) 397 | #define FFTW_BELIEVE_PCOST (1U << 8) 398 | #define FFTW_NO_DFT_R2HC (1U << 9) 399 | #define FFTW_NO_NONTHREADED (1U << 10) 400 | #define FFTW_NO_BUFFERING (1U << 11) 401 | #define FFTW_NO_INDIRECT_OP (1U << 12) 402 | #define FFTW_ALLOW_LARGE_GENERIC (1U << 13) /* NO_LARGE_GENERIC is default */ 403 | #define FFTW_NO_RANK_SPLITS (1U << 14) 404 | #define FFTW_NO_VRANK_SPLITS (1U << 15) 405 | #define FFTW_NO_VRECURSE (1U << 16) 406 | #define FFTW_NO_SIMD (1U << 17) 407 | #define FFTW_NO_SLOW (1U << 18) 408 | #define FFTW_NO_FIXED_RADIX_LARGE_N (1U << 19) 409 | #define FFTW_ALLOW_PRUNING (1U << 20) 410 | 411 | #ifdef __cplusplus 412 | } /* extern "C" */ 413 | #endif /* __cplusplus */ 414 | 415 | #endif /* FFTW3_H */ 416 | -------------------------------------------------------------------------------- /pitchshifting/pitchshifting.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/pitchshifting.cpp -------------------------------------------------------------------------------- /pitchshifting/pitchshifting.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {F67C049B-AC7F-48C9-A87C-C398E417CD63} 24 | Win32Proj 25 | pitchshifting 26 | 10.0.17134.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v141 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v141 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v141 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v141 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | $(IncludePath) 76 | $(LibraryPath) 77 | $(ReferencePath) 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | false 87 | 88 | 89 | 90 | Use 91 | Level3 92 | Disabled 93 | true 94 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | D:\Repository\PitchShifting\pitchshifting\include;%(AdditionalIncludeDirectories) 97 | 98 | 99 | Console 100 | true 101 | libfftw3-3.lib;libfftw3l-3.lib;libfftw3f-3.lib;%(AdditionalDependencies) 102 | D:\Repository\PitchShifting\pitchshifting\Library\fftw_32;%(AdditionalLibraryDirectories) 103 | 104 | 105 | xcopy $(ProjectDir)Library\fftw_32\*.dll $(SolutionDir)\$(Configuration)\ /y 106 | 107 | 108 | 109 | 110 | Use 111 | Level3 112 | Disabled 113 | true 114 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 115 | true 116 | 117 | 118 | Console 119 | true 120 | 121 | 122 | 123 | 124 | Use 125 | Level3 126 | MaxSpeed 127 | true 128 | true 129 | true 130 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 131 | true 132 | 133 | 134 | Console 135 | true 136 | true 137 | true 138 | 139 | 140 | 141 | 142 | Use 143 | Level3 144 | MaxSpeed 145 | true 146 | true 147 | true 148 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 149 | true 150 | 151 | 152 | Console 153 | true 154 | true 155 | true 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | Create 167 | Create 168 | Create 169 | Create 170 | 171 | 172 | 173 | 174 | 175 | 176 | -------------------------------------------------------------------------------- /pitchshifting/pitchshifting.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 头文件 20 | 21 | 22 | 头文件 23 | 24 | 25 | 头文件 26 | 27 | 28 | 头文件 29 | 30 | 31 | 32 | 33 | 源文件 34 | 35 | 36 | 源文件 37 | 38 | 39 | -------------------------------------------------------------------------------- /pitchshifting/stdafx.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/stdafx.cpp -------------------------------------------------------------------------------- /pitchshifting/stdafx.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/stdafx.h -------------------------------------------------------------------------------- /pitchshifting/targetver.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jagger2048/PitchShifting/04c49c43f5f3c9bccb1ef95e333b242151107474/pitchshifting/targetver.h -------------------------------------------------------------------------------- /pitchshifting/wav.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 15.0 23 | {F67C049B-AC7F-48C9-A87C-C398E417CD63} 24 | Win32Proj 25 | pitchshifting 26 | 10.0.17134.0 27 | 28 | 29 | 30 | Application 31 | true 32 | v141 33 | Unicode 34 | 35 | 36 | Application 37 | false 38 | v141 39 | true 40 | Unicode 41 | 42 | 43 | Application 44 | true 45 | v141 46 | Unicode 47 | 48 | 49 | Application 50 | false 51 | v141 52 | true 53 | Unicode 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | true 75 | D:\Repository\AudioEffect\pitchshifting\pitchshifting\AudioFIle;D:\Repository\AudioEffect\pitchshifting\pitchshifting\Library\fftw_32;D:\Repository\AudioEffect\pitchshifting\pitchshifting;$(IncludePath) 76 | D:\Repository\AudioEffect\pitchshifting\pitchshifting;D:\Repository\AudioEffect\pitchshifting\pitchshifting\Library\fftw_32;$(LibraryPath) 77 | D:\Repository\AudioEffect\pitchshifting\pitchshifting;$(ReferencePath) 78 | 79 | 80 | true 81 | 82 | 83 | false 84 | 85 | 86 | false 87 | 88 | 89 | 90 | Use 91 | Level3 92 | Disabled 93 | true 94 | WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) 95 | true 96 | 97 | 98 | Console 99 | true 100 | libfftw3-3.lib;libfftw3l-3.lib;libfftw3f-3.lib;%(AdditionalDependencies) 101 | 102 | 103 | 104 | 105 | Use 106 | Level3 107 | Disabled 108 | true 109 | _DEBUG;_CONSOLE;%(PreprocessorDefinitions) 110 | true 111 | 112 | 113 | Console 114 | true 115 | 116 | 117 | 118 | 119 | Use 120 | Level3 121 | MaxSpeed 122 | true 123 | true 124 | true 125 | WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 126 | true 127 | 128 | 129 | Console 130 | true 131 | true 132 | true 133 | 134 | 135 | 136 | 137 | Use 138 | Level3 139 | MaxSpeed 140 | true 141 | true 142 | true 143 | NDEBUG;_CONSOLE;%(PreprocessorDefinitions) 144 | true 145 | 146 | 147 | Console 148 | true 149 | true 150 | true 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | Create 160 | Create 161 | Create 162 | Create 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # Pitch shifting User manual 2 | 3 | v1.0 初步完善pitch shifting的原理介绍及实现方式 4 | 5 | ## Introduction 6 | 7 | **Pitch shifting** effect: 变调,移相效果器,该效果器可以实现对原始音频音调的调整,进行升调或者降调,升降的程度通过半音阶^[1]^ (semetone)来衡量。可用于电子变声器、吉他变调器以及卡拉Ok应用中^[2]^。 8 | 9 | ### 实现方式 10 | 11 | ​ 实现pitch shifting effect的方式有以下几种: 12 | 13 | - **Time scaling and resampling** 14 | 15 | ​ 最简单的方式,通过调整采样率改变最终播放的时长(duration),从而改变音调,实现变调功能。 16 | 17 | - **Pitch Synchronous Overlap and Add ,PSOLA^[3]^ ,基音同步叠加** 18 | 19 | ​ 将信号分割成重叠帧 ***overlap segment*** ,在叠加前需要确定基音周期以及起始点(Pitch control,一般在 **时域处理** ),根据需要调整叠加区域的大小,达到升降调的目的,处理后的信号将会改变音调和时长。基音频率及起始点判别的准确与否对处理后的信号是否平稳至关重要。多用于话音信号中。 20 | 21 | - **Phase vocoder** 22 | 23 | ​ 将信号分割成较短的互相重叠的重叠帧,通过FFT处理(STFT),在**频域**中按照升降比例调整信号的相角$\phi$,然后通过IFFT还原至时域信号,并叠加输出。由于频域中相位的变化等价于时域中频率的变化,因此可以实现信号音调的升降。Phase vocoder的处理思路与PSOLA类似,由于是在频域中调整信号音调,因此更为精确可控,由此衍生出不少基于phase vocoder的处理方案。 24 | 25 | 本文将会重点讲解Phase vocoder。 26 | 27 | ## 预备知识 28 | 29 | ​ 在进入下一阶段讲解基于Phase vocoder的Pitch shifting effect之前,先补充一些前置理论:声乐理论。 30 | 31 | ### 声乐理论 32 | 33 | ​ Pitch,可以用来衡量声调高低的物理量,有别于音量。通常情况下,可以将pitch与频率联系起来,对于特定的pitch,特定频率的信号对其影响较大。在声乐领域,Standard Pitch的频率为A440,升高一个octave为A880,降低为A220^[6]^。 34 | 35 | ​ 半音阶(semitone),声乐学中衡量音调高低的单位之一,一个八度(octave)的音程按12平均律分为12个半音,提升一个半音相当于在音调频率的基础上乘上2^1/12^ 36 | 37 | 以下为各个音阶对应的频率: 38 | 39 | ![1527066610820](https://github.com/jagger2048/PitchShifting/blob/master/assets/1527066610820.png) 40 | 41 | 更多内容请参阅 [6]. 42 | 43 | #### 简单应用:**Time scaling and resampling** 44 | 45 | ​ 原始信号长度为 L ,采样率为 fs ,要实现升一个半音高(semeton),可以先将原始信号从 L 插样至 L * 2^1/12^ ,然后以 2^1/12^ *fs 的采样率播放即可升一个半音高。升两个半音高时需要插样的 系数为 2^1/12^,以此类推。对于降调来说对应的系数rate则为 2^1/12^ (one semetone),最后播放时也需以对应系数的采样率进行播放。 46 | 47 | ```matlab 48 | %%matlab参考代码: 49 | [y_in,fs] = audioread('test.wav'); 50 | rate = 2^(6/12); % raise 6 semetones 51 | y_out_len = y_in_len * rate; 52 | y_out = interp1( linspace(0,1,y_in_len),y_in,linspace(0,1,y_out_len)); 53 | p = audioplayer(y_out,fs*rate); 54 | p.play 55 | ``` 56 | 57 | ## Phase Vocoder 58 | 59 | ### 原理介绍 60 | 61 | ​ **Vocoder** 是一类直接对特定频率信号的幅值和相位进行编辑修改的工具的总称,Phase vocoder属于其中的一种,主要用于调整信号特定频率的相位信息。Phase vocoder有两种实现模型,其中一种是滤波组总和模型(*Filter Bank Summation Model*),通过一簇等宽、中心频率从0~fs/2的带通滤波器将信号分割成一个个频段的“单频”信号,然后进行处理,最后叠加还原。 62 | 63 | ​ 另一种为逐块分析/综合模型 (*Block by Block Analysis / Synthesis Model*),通过逐步步进的方式,重叠地从原始信号中取出 Analysis_block,步进长度为analysis len。之后对Analysis block中的信号进行FFT变换至频域,在频域中对频域信息(幅值、相位)按需求进行处理(Processing),最后通过IFFT还原频域信号至时域,并进行综合相加(*Synthesis and overlap*),得出Synthesis block。同样的,综合相加也有步进长度,为Synthesis len。 64 | 65 | ​ 实际上根据FFT计算公式,可以将FFT看成是一系列的带通滤波器的组合,这些带通滤波器的中心频率为 $[0:fft_n]*fs/2$ Hz,具体信息可参阅[5]。逐块分析/综合模型的具体过程可归纳如下,本文所要介绍的Phase vocoder将会基于该模型: 66 | 67 | 68 | 69 | ![1526981472041](https://github.com/jagger2048/PitchShifting/blob/master/assets/1526981472041.png) 70 | 71 | 72 | ### 实现过程 73 | 74 | 重点介绍实现的过程,演示的时候可以使用matlab 75 | 76 | ​ 上一节提到,基于*Block by Block Analysis / Synthesis Model* 的Phase vocoder主要分为三个步骤,analysis-->processing-->synthesis。 本节将会具体拆解这些步骤,介绍如何通过Phase vocoder实现Pitch shifting的效果。 77 | ```mermaid 78 | graph LR 79 | A(Analysis) -->B(Processing) 80 | B --> C(Synthesis) 81 | ``` 82 | 83 | #### Analysis 84 | 85 | ​ Analysis 阶段主要进行的是STFT(*Short time fouria transform*),即重叠地向前取固定长度的点,并将点存储在 *Frame* 的buffer中进行FFT处理,处理后的数据将会在*Processing*中使用。具体步骤如下: 86 | 87 | 1. 重叠分帧。以*analysis hop*为步进长度,向前取值分帧,所取的点数 88 | 为 win len,存在Frame 的寄存器中,用于后续的FFT变换。 89 | 2. 加窗,FFT。对Frame中的数据乘上一个*win len*长度的 *hanning* 90 | *window*,加窗后的信号应用FFT。 91 | 3. 计算幅值、相角。计算FFT后信号的幅值 mag 和 相角 angle 。 92 | 93 | 其中analysis hop的取值与win len有较大的联系,由于向前取点分帧需要重叠75%的数据以获得较大的频率分辨率和良好的处理效果^[4]^,因此 analysis hop = (1-0.75)win len*,当win len取256时,analysis hop = 64。 94 | 95 | 96 | 以下为此部分对应的matlab代码: 97 | 98 | ```matlab 99 | for n = 0:step_num-1 100 |    if n == step_num-1 % 分帧,按照analysis_len 移动 101 |        frame = x( end - win_len + 1:end); 102 |    else 103 |        frame = x(analysis*n +1 : analysis*n + win_len); 104 |    end 105 |    frame_fft =  fft((win.*frame) ) ;    % 加窗, 后fft 106 |    angle_pre = frame_angle; 107 |    frame_angle = angle(frame_fft); 108 |    frame_mag = abs(frame_fft); 109 |    ... 110 | ``` 111 | 112 | **需要注意的地方:** 113 | 114 | ​ 在matlab/python中,*mag* 可以通过abs()函数求解, *angle* 可以通过angle()函 115 | 数求解,输入均为FFT后的复数。而在C/C++中由于无法调用库因此需要将复数拆分成实部 *real* 和虚部 *imag* 分别计算:*mag =sqrt( real^2^+imag^2^),angle = atan2(imag,real)。* 116 | 117 | #### Processing 118 | 119 | ​ 此部分是Phase vocoder的重点,将会调整信号的音调,主要的处理为*Phase unwrap*。为了便于理解,先回顾一下角频率$\omega$与相位(相角)$\varphi$的关系: 120 | $$ 121 | \omega \times t = \varphi 122 | $$ 123 | 而$2\pi\omega=f$,因此瞬时频率与相角的关系为: 124 | $$ 125 | f_i=2\pi\varphi/t 126 | $$ 127 | 而analysis阶段向前步进长度 analysis len 可以看成是时间间隔$t$。 128 | 129 | **unwrap的主要步骤** 130 | 131 | 1. 计算前后两帧角频率的变化: 132 | $$ 133 | \Delta = (angle_{cur}-angle_{pre})-\Omega 134 | $$ 135 | 其中$\Omega = 2\pi[0:win_{len}]/win_{len}$,对应FFT后每一个点的标准角频率,角频率乘上时间间隔即为相位角 $\omega \times t = \varphi $ 136 | 137 | 2. 计算在analysis hop的时间间隔中的相位差异: 138 | $$ 139 | \Delta \varphi = \Delta angle -Round(\Delta /2\pi)*2\pi 140 | $$ 141 | 其中,Round()为取整函数,$\Delta \varphi$将会在$(-\pi,\pi)$之间, 142 | 143 | 3. 根据相位差异(变化率)$\Delta \varphi$计算瞬时角频率: 144 | $$ 145 | \omega_i = \Omega + \Delta \varphi/analysis_{hop} 146 | $$ 147 | 148 | 4. 计算同步相位 149 | $$ 150 | angle_{syn} = angle_{syn} + \omega_i *Synthesis_{hop} 151 | $$ 152 | 注意,这里计算出的相位是累积相位,并根据比值对相位进行了综合同步 153 | 154 | 5. 输出 同步相位 $angle_{syn}$ 及同步振幅 *mag* 155 | 156 | 157 | 本节参考代码如下: 158 | 159 | ```matlab 160 | %% unwrap 161 | omega = 2*pi*analysis.* ( 0:win_len-1 )' ./win_len; 162 | delta = frame_angle - (angle_pre + omega); 163 | phase_unwrap = delta - round(delta/(2*pi))*2*pi; 164 | % caculate the principal argument of the nomial inital phase 165 | % also called delta_phi 166 | phase_inc = (phase_unwrap + omega) / analysis; 167 | % phase(omega)increment 168 | if first_time 169 | first_time = false; 170 | y_angle = frame_angle; 171 | else 172 | y_angle = y_angle + phase_inc * synthesis; 173 | % synthesis phase caculation 174 | % 用前一帧的angle!!! 175 | end 176 | ``` 177 | 178 | 179 | 180 | #### Synthesis 181 | 182 | ​ 在上一节里我们已经在时域处理中求解出了同步相位以及同步振幅,为了进一步的处理,我们需要将信号通过IFFT还原至时域,以下是具体的步骤: 183 | 184 | 1. 根据复数的复指数形式$y = K*e^{\phi j}$,将信号还原成复数: 185 | $$ 186 | y_{complex} = mag*e^{angle_{syn}*j} 187 | $$ 188 | 189 | 2. IFFT,后加窗输出待混叠信号 190 | $$ 191 | y_{toSyn} = real(IFFT(y_{comples}))*HanningWindow 192 | $$ 193 | 194 | 3. 混合叠加输出,叠加步长为 *Synthesis hop* 195 | 196 | 此部分matlab参考代码如下: 197 | 198 | ```matlab 199 | %% overlapped and add,with resampling 200 | h = frame_mag.*exp(y_angle*1j); 201 | y_ifft = (real(ifft(h)) ).*win; 202 | overlap = temp(synthesis+1:win_len) + y_ifft(1:win_len-synthesis); % 叠加 203 | temp = [overlap ; y_ifft(win_len-synthesis+1:win_len) ]; % 组合 204 | toSyn = temp(1:synthesis); 205 | ``` 206 | 207 | 需要注意的地方: 208 | 209 | ​ 在C/C++的基础库中不支持复数运算,因此根据公式$y = K*e^{\phi j}$还原的方式行不通,需要通过三角函数分别还原出实部和虚部,公式如下: 210 | $$ 211 | real = mag*cos(angle_{syn}),imag = mag*sin(angle_{syn}) 212 | $$ 213 | 214 | 215 | 216 | ### 实现效果 217 | 218 | 此处记录使用phase vocoder 实现pitch shifting 时的实际使用效果。 219 | 220 | **测试用例1**: 使用matlab生成1k Hz 及 4k Hz的正弦信号作为测试信号,通过matlab 编写的Phase vocoder 程序,对比处理前后信号的频域信息。 221 | 222 | ​ 输入的测试信号: 223 | 224 | ```matlab 225 | fs = 44100; 226 | f1 = 1000;f2 = 4000; 227 | t = linspace(0,1,fs); 228 | x = sin(2*pi*f1*t)+cos(2*pi*f2*t); 229 | ra = rand(length(x),1); 230 | x = x + 0.2.*ra';% 下图中为x=x + *ra'; 231 | x = x'/max(x); 232 | ``` 233 | 234 | ![1527062406650](https://github.com/jagger2048/PitchShifting/blob/master/assets/1527062406650.png) 235 | 236 | ​ 从上图中可以看到使用1kHz,4kHz叠加的正弦信号作为测试信号,pitch shifting 的比例为1.406(约等于2^6/12^),理论上经过pitch shifting 后1K 与4k分别变成:1000\*1.406 = 1406, 4000*1.406=5624,前后对比可以发现实际处理出来的信号主频十分接近理论频率,由此说明Phase vocoder效果较为理想。 237 | 238 | **测试用例2**: 使用常规的音乐信号作为测试信号,在处理后(如升高6 semetones)与使用Adobe Audition 进行同样处理后的信号进行对比,比较两者差异。 239 | 240 | ​ 测试文件为Long Live.wav,使用matlab编写的Phase vocoder进行测试,程序见附录。处理后的文件为 test_matlab.wav。而在Adobe Audition中,使用的设置如下: 241 | 242 | ![1527069146098](https://github.com/jagger2048/PitchShifting/blob/master/assets/1527069146098.png) 243 | 244 | 处理后的文件为 test_AU.wav,听音测试。 245 | 246 | ### Matlab/Python实现 247 | 248 | ​ Phase vocoder的matlab实现前面的章节已经有提及,在此不再赘述,可参见附件。Python实现与matlab类似,附录同样摘录有其实现的代码,不过需要注意的是使用python时,无论是向量还是数组的形式,其第一位的下标是0而不是1 。 249 | 250 | ### C/C++实现 251 | 252 | ​ 考虑到Matlab/Python实现时使用的是向量的形式,与实际生产环境中使用C/C++的流实现方式有所不同,这里给出C/C++实现Phase vocoder的参考代码,主要程序如下: 253 | 254 | ```C++ 255 | for (int i=0,offset=0; i < ana_count; i++,offset++) { // 分帧 以ana_len 为间隔向前移动,取出win_len点数据 256 | for (int n = 0; n < win_len; n++) { 257 | double input_temp = wav.data[offset*ana_len +n]; 258 | fft_in[n][0] = input_temp * hanning_win[n]; // 加窗 259 | fft_in[n][1] = 0; 260 | original_input.push_back(input_temp); // test 记录即将进行处理的原始数据 261 | } 262 | 263 | fftw_execute(fft); // 对输入信号使用fft 264 | for (int n = 0; n < win_len; n++) { 265 | real[n] = fft_out[n][0]; // 保存实部 266 | imag[n] = fft_out[n][1]; // 保存虚部 267 | angle_pre[n] = angle[n]; 268 | // Notice the different between real() and abs() func 269 | mag[n] = sqrt(real[n] * real[n] + imag[n] * imag[n]); 270 | // Notice:angle(x+yj) = actan2(y,x); 271 | angle[n] = atan2(imag[n],real[n]); 272 | 273 | // phase unwrap 274 | double delta = (angle[n] - angle_pre[n]) - omega[n] * ana_len; // phi 数组! 275 | double delta_phi = delta - round( delta / (2 * PI) ) * (2 * PI);// phi 276 | double y_unwrap = delta_phi/ana_len + omega[n]; 277 | if (is_firstTime) { 278 | angle_syn[n] = angle[n]; 279 | } 280 | else { 281 | angle_syn[n] = angle_syn[n] + y_unwrap * syn_len; // phi,shifted angle 282 | } 283 | syn_angle.push_back(angle_syn[n]); // 记录同步相位 test 284 | 285 | // prepare for ifft 286 | ifft_in[n][0] = mag[n] * cos(angle_syn[n]); // 还原实部 287 | ifft_in[n][1] = mag[n] * sin(angle_syn[n]); // 还原虚部 288 | } 289 | is_firstTime = false; 290 | 291 | // Notice:fftw库中 ifft输出的值没有进行归一化,需要除以ifft_points 才与matlab中的结果相等 292 | fftw_execute(ifft); 293 | 294 | // 使用ifft_out中的实数部分进行synthesis and overlap add 295 | double toSOA[win_len]; 296 | double overlap[win_len - syn_len]; 297 | for (int n = 0; n < win_len; n++) { 298 | toSOA[n]=hanning_win[n]*ifft_out[n][0] / double(win_len); // 归一化,加窗 299 | if (n < win_len - syn_len) { 300 | overlap[n] = overlap_buff[syn_len + n] + toSOA[n]; // overlap add 301 | overlap_buff[n] = overlap[n]; 302 | } 303 | else 304 | { 305 | overlap_buff[n] = toSOA[n]; 306 | } 307 | } 308 | // output is in overlap_buff[0:syn_len] 309 | for (int output_n = 0; output_n < syn_len; output_n++) { // output the phase shifting signal ,test 310 | audio_out << overlap_buff[output_n] << endl; 311 | } 312 | 313 | } 314 | ``` 315 | 316 | 317 | 318 | ## Reference 319 | 320 | [1] 参考来源: 321 | 322 | [2] https://en.wikipedia.org/wiki/Pitch_shift 323 | 324 | [3] https://en.wikipedia.org/wiki/PSOLA 325 | 326 | [4] Bernardini.pdf Trational implementations of a phase-vocoder: The tricks 327 | of the trade. 328 | 329 | [5] https://en.wikipedia.org/wiki/Filter_bank#FFT_filter_banks 330 | 331 | [6] https://en.wikipedia.org/wiki/Pitch_(music)#Pitch_and_frequency 332 | --------------------------------------------------------------------------------