Skip to content

Instantly share code, notes, and snippets.

@Giermann
Forked from SteveALee/README.md
Last active January 11, 2024 06:06
Show Gist options
  • Save Giermann/c3f88ee2a147f9a688a2ca76e1334a54 to your computer and use it in GitHub Desktop.
Save Giermann/c3f88ee2a147f9a688a2ca76e1334a54 to your computer and use it in GitHub Desktop.
Build audacity with ASIO support on Windows

Build your own Audacity for Windows with ASIO driver support

Note, if you have come here from a video the instructions for installing the tools have now changed.

Due to licensing rules Audacity cannot provide a prebuilt version with ASIO support. But you can build your own and this guide makes it easy for you to do so.

Note that this builds Audacity 3.2.3. Audacity 3.0.0 introduced a new project file format so you will hit compatability problems if you try to use Audacity 2.x.x to open projects saved with this version.**

The Audacity program is the "go to" solution for many audio recording and editing tasks. However, unlike many more advanced DAWs, it doesn't support Windows ASIO drivers "out of the box". Fortunately, Audiacity's standard MME support is fine for most uses. That said, common reasons for needing ASIO are using digital audio or music equipment that only comes with ASIO drivers, such as Behringer mixers (which actually use the ASIO4ALL ASIO <> WDM bridging driver). Another common reason is to take advantage of the low latency or multiple channels supported by ASIO.

While it is possible to build your own Audacity with ASIO support this usually requires considerable technical skills.

To reduce this requirement, the instructions provided here make it easy to build your own version of Audacity with ASIO support on a Windows PC. The instructions for the few manual steps should be straight forward to follow. A script checks everything is installed and builds a 64 bit release version of Audacity for you.

NB. If you do use this to build Audacity with ASIO support you must not redistribute it due to the ASIO SDK licensing terms - see below.

Unfortunately, it turns out the Audacity ASIO build has limited multi channel support. For example, the peak meters always show channels 1 & 2 and to record channels 3 & 4 requires recording 1, 2, 3 & 4. So While Audacity still works really well for simple recording tasks, you might want to eventually switch to a full DAW with AISO support. I'll probably use Reaper.

Here's a brief blog post explaining why I needed ASIO and it includes a screen shot.

Since writing that, I discovered my McMillen K-Mix digital interface mixer facilities alow routing of inputs 3 & 4 to the main outputs on 1 and 2 so can use the default MME Audacity build after all. For playback from PC, I found the HiFi Driver and ASIO Bridge from VB Audio lets me re-route PC audio out to channels 3 & 4 on the K-Mix, Leaving Channels 1 & 2 free for instruments and Mics.

Licensing

The reason for Audacity's lack of ASIO support is licensing, not technical. Steinberg do not alow the ASIO SDK to be redistributed (as required by open source projects). In addition, Audacity is GPL licensed and so is incompatible with the ASIO SDK licence redistribution rules.

Detailed instructions

Note for developers: These instructions assume a clean dev. env. If you have existing installations of the tools you may hit errors due to differing versions. Perhaps use a VM (difficult with Windows licencing) or a Windows container.

This video by @Renamesk walks you through the process, but the tool installation method has changed.

  • ensure you have a PC with modern Windows installed. 11 and 10 are known to work but 7 and 8 should too.
  • install "Git For Windows" - click the "download" button.
  • make a new folder C:\projects
  • click on the 'raw' button at the top of the script (below) in this Gist.
  • use the browser Save As feature to save the script as \projects\build-audacity.cmd (be careful there's no ".txt")
  • open a new Windows cmd terminal (Windows + R keys and then type cmd)
  • type cd \projects and enter key
  • install required tools by typing build-audacity.cmd --install and enter.
    • NB for Visual Studio, make sure you check the "desktop development with C++" workload
    • if you have a non English Windows or Visual Studio then you must also install the VS English language pack.
  • when the install completes open a cmd temrinal again and start the build by typing build-audacity.cmd and enter.
  • come back later - it will take at least 10 minutes
  • Audactiy will be launched to test it was built correctly
    • to it run again see the program location printed out at the end of the build
    • or copy the specified folder to where you want to run Audacity from, optionally renaming it

If you have any ASIO drivers installed you should find ASIO is now available in the the Audacity driver selection combo box.

When things go wrong

As with any complex software build there are many moving parts (including Windows itself) and things can sometimes go wrong. Here are some tips if you hit build errors.

  • make sure you have latest script
  • run the script with --cleanall and try again
  • uninstall all the tools (Python, cmake, Visual Studio and its installer) and then reboot before trying again
    • note having other versions of any of the tools installed may well cause problems - remove them
  • read the error output - clues are often buried in reams of impenetrable text
  • disable any Anti Virus - the built-in Microsoft one is usually not a problem

Thanks

  • @diogodh for finding and fixing the bug with conan installations
  • The Audacity team for an fantastic audio tool.
@echo off
rem Version: 2.0.1
rem
rem Build audacity with ASIO support on Windows
rem See the following gist for details
rem https://gist.github.com/SteveALee/da24c2be633340b8791066dd98eb5d0b
rem
rem Options (only one may be specified)
rem
rem --install - install tools
rem --uninstall - uninstall all tools (CMake, Python, Visual Studio)
rem --clean - remove built files
rem --cleanall - remove fetched and built files
rem --getonly - only get the files
rem --noget - don't fetch again from git
rem --gui - run cmake-gui
rem
rem MIT licence
rem [email protected]
rem
rem See https://wiki.audacityteam.org/wiki/Building_On_Windows
rem TODO:
rem - include 'git' in installed tools and checks for presence
rem - do not force download on "--uninstall", if still present
rem - maybe avoid the need to close and restart CMD after installation
rem (see https://github.com/chocolatey/choco/blob/master/src/chocolatey.resources/redirects/RefreshEnv.cmd)
rem - extend PATH variable, when installed without the option "add to path":
rem * %ProgramFiles%\Git\cmd (or simply call Git.exe from there)
rem * %ProgramFiles%\CMake\bin
rem * %LocalAppData%\Programs\Python\Python311\Scripts\;%LocalAppData%\Programs\Python\Python311\
SETLOCAL
set VISUALSTUDIO_REL=2022
rem ...find latest version -> https://github.com/audacity/audacity/releases
set AUDACITY_REL=3.3.3
rem ...find latest version -> https://github.com/Kitware/CMake/releases
set CMAKE_REL=3.25.1
rem ...find latest version -> https://www.python.org/ftp/python
set PYTHON_REL=3.11.1
set CONAN_REL=1.59.0
rem set PROJROOT=C:\projects
set PROJROOT=%~dp0
set AUDACITY=%PROJROOT%\audacity
set AUDACITY_BUILD=%PROJROOT%\audacity-asio
set EXEDIR=%AUDACITY_BUILD%\Release
if [%VISUALSTUDIO_REL%] == [2019] goto vs2019
if [%VISUALSTUDIO_REL%] == [2017] goto vs2017
:vs2022
rem Visual Studio 2022
set VISUALSTUDIOCMAKE=Visual Studio 17 2022
set VISUALSTUDIOVER=2022\Community
set VSDIR=%ProgramFiles%\Microsoft Visual Studio\%VISUALSTUDIOVER%
set vs-url=https://aka.ms/vs/17/release/vs_community.exe
set msbuild="%VSDIR%\MSBuild\Current\Bin\MsBuild.exe"
goto start
:vs2019
rem Visual Studio 2019
set VISUALSTUDIOCMAKE=Visual Studio 16 2019
set VISUALSTUDIOVER=2019\Community
set VSDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VISUALSTUDIOVER%
set vs-url=https://aka.ms/vs/16/release/vs_community.exe
set msbuild="%VSDIR%\MSBuild\Current\Bin\MsBuild.exe"
goto start
:vs2017
rem Visual Studio 2017
set VISUALSTUDIOCMAKE=Visual Studio 15 2017
set VISUALSTUDIOVER=2017\Community
set VSDIR=%ProgramFiles(x86)%\Microsoft Visual Studio\%VISUALSTUDIOVER%
set vs-url=https://aka.ms/vs/15/release/vs_community.exe
set msbuild="%VSDIR%\MSBuild\15.0\Bin\MsBuild.exe"
goto start
:start
rem rem check projroot exists
rem if /I not [%~dp0] == [%PROJROOT%\] (
rem echo.
rem echo Error: This script must be run in %PROJROOT% - see %%PROJROOT%% in file
rem echo.
rem if not exist %PROJROOT% (
rem echo Create %PROJROOT
rem goto exit
rem ) else (
rem echo copy script to %PROJROOT%
rem goto exit
rem )
rem )
cd /d %PROJROOT%
if /I not [%1] == [--install] if /I not [%1] == [--uninstall] goto clean
rem Get tools
rem ANSI escape sequences do not work in if () block so we use goto
set cmake-url=https://github.com/Kitware/CMake/releases/download/v%CMAKE_REL%/cmake-%CMAKE_REL%-windows-x86_64.msi
set python-url=https://www.python.org/ftp/python/%PYTHON_REL%/python-%PYTHON_REL%-amd64.exe
echo 
echo.
echo Fetching tools..
echo 
mkdir bin 2> :null
curl -L %cmake-url% -o bin\cmake.msi
curl -L %vs-url% -o bin\vs.exe
curl -L %python-url% -o bin\python.exe
if /I [%1] == [--uninstall] goto uninstall
echo 
echo.
echo Installing tools...
echo.
echo IMPORTANT!! Follow the instructions below for each installer
echo Close each installer when it is done
echo.
rem echo CMake: make sure you select "add cmake to system PATH"
rem pause
rem bin\cmake.msi
echo CMake %CMAKE_REL%...
msiexec /i bin\cmake.msi ALLUSERS=1 ADD_CMAKE_TO_PATH=System /qn
echo.
rem echo Python: make sure you select "add python.exe to PATH"
rem pause
rem bin\python.exe
echo Python %PYTHON_REL%...
start /wait bin\python.exe /quiet InstallAllUsers=1 PrependPath=1 Include_launcher=0
echo.
rem echo Visual Studio: make sure you select the Workload "desktop development with C++"
rem pause
rem bin\vs.exe
echo Visual Studio %VISUALSTUDIO_REL%...
bin\vs.exe --add "Microsoft.VisualStudio.Workload.NativeDesktop" --includeRecommended --addProductLang "En-us" --passive --wait
echo.
echo.
echo This window will now close!
echo Open another "cmd" window (Wnd + R, cmd) and run "%0" again to build Audactity
echo 
echo.
pause
exit
:uninstall
echo 
echo.
echo Uninstalling tools...
echo.
echo CMake...
msiexec /x bin\cmake.msi /qn
echo.
echo Python...
start /wait bin\python.exe /uninstall /quiet InstallAllUsers=1
echo.
echo Visual Studio...
bin\vs.exe uninstall --passive --wait
echo.
echo.
echo Please reboot and run "%0 --install" again if you want to build Audacity in future.
echo 
echo.
goto exit
:clean
if /I not [%1] == [--getonly] (
if /I [%1] == [--clean] echo Cleaning built files... & rmdir /s/q %AUDACITY_BUILD% 2> :null
if /I [%1] == [--cleanall] echo Cleaning source and built files... & rmdir /s/q %AUDACITY% %AUDACITY_BUILD% 2> :null
if /I [%1] == [--cleanall] where /q conan & if ERRORLEVEL 0 echo Cleaning conan modules... & conan remove -f * 2> :null
)
rem Launch cmake-gui
if /I [%1] == [--gui] cmake-gui -Daudacity_has_asio_support=On -DAUDACITY_BUILD_LEVEL=2 -S %AUDACITY% -B %AUDACITY_BUILD% & goto build
rem ensure tools are installed
if /I not [%1] == [--getonly] (
rem NB this sets 64bit arch for cmake
if not exist "%VSDIR%\VC\Auxiliary\Build\vcvars64.bat" echo Error: Install Visual Studio %VISUALSTUDIOVER% & goto exit /b
if not defined VisualStudioVersion call "%VSDIR%\VC\Auxiliary\Build\vcvars64.bat"
where /q cmake & if ERRORLEVEL 1 echo Cmake does not appear to be installed & goto exit /b
where /q python & if ERRORLEVEL 1 echo Python does not appear to be installed & goto exit /b
where /q conan & if ERRORLEVEL 0 pip show --version conan | findstr /R /C:"Version: %CONAN_REL%" & if ERRORLEVEL 1 echo uninstalling conan & pip uninstall -y -q conan
echo installing conan %CONAN_REL%
where /q conan & if ERRORLEVEL 1 pip install conan==%CONAN_REL%
)
rem Get source code
set getsrc=0
if /I [%1] == [] set getsrc=1
if /I [%1] == [--getonly] set getsrc=1
if /I [%1] == [--cleanall] set getsrc=1
if /I not [%1] == [--noget] (
where /q git & if ERRORLEVEL 1 echo Error Install Git for Windows. Choose the option "Git from the command line" && goto exit /b
if [%getsrc%] == [1] (
echo.
echo Fetching code for Audacity %AUDACITY_REL%...
echo.
git clone -b Audacity-%AUDACITY_REL% --depth 1 https://github.com/audacity/audacity/ %AUDACITY%
if ERRORLEVEL 1 echo Error: cannot fetch the Audacity code. Try the --cleanall or --noget options & goto exit
if not exist %AUDACITY%\CMakeLists.txt echo Something is wrong with %AUDACITY% files & goto exit
)
)
if /I [%1] == [--getonly] goto exit
echo.
echo Building Audacity %AUDACITY_REL% 64 bit release with ASIO support...
echo.
cd /d %AUDACITY%
cmake -G "%VISUALSTUDIOCMAKE%" -DCMAKE_CONFIGURATION_TYPES=Release -Daudacity_has_asio_support=On -DAUDACITY_BUILD_LEVEL=2 -S %AUDACITY% -B %AUDACITY_BUILD% & if ERRORLEVEL 1 echo Error: Cannot create Audacity buildfiles & goto exit
:build
cd /d %AUDACITY_BUILD%
set msbuild="%VSDIR%\MSBuild\Current\Bin\MsBuild.exe"
%msbuild% audacity.sln -t:Audacity -p:configuration=Release
if ERRORLEVEL 1 echo Error: cannot build Audacity & goto exit
cd /d %PROJROOT%
rem All done
echo 
echo.
echo Congratulations!
echo Your new Audacity with ASIO support will now launch.
echo The ASIO options will appear if you have ASIO drivers and connected hardware
echo In future just run the audacity.exe. No need to install.
echo.
echo %EXEDIR%\audacity.exe
echo.
echo Or copy the folder
echo.
echo %EXEDIR%\
echo.
echo and run the included audacity.exe
echo.
echo 
start %EXEDIR%\audacity.exe
:exit
cd /d %PROJROOT%
ENDLOCAL
@Giermann
Copy link
Author

@phuzzyday
Please have a look at the original fork, which you also see on the top just beneath the title: https://gist.github.com/SteveALee/da24c2be633340b8791066dd98eb5d0b

All credits go to SteveALee, who did most of the work to get it compiled with a single script (and of course the Audacity team)!
I only use this fork to publish my modifications, mainly for different Visual Studio versions.

Maybe the preinstalled Visual Studio would have been suitable, but as you already uninstalled it, you should be able to simply use the "--install" option and at least the latest version should then install all required tools automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment