bastibe/PyAudio — pull request #4 by mbyt (2013-02-16 05:47:24+00:00)
Title: Adding compile support for windows MSC v.1500

## Adding compile support for windows MSC v.1500
PyAudio does not ship the asiosdk for licensing issues. Therefore, the installer
of PyAudio, depending on PortAudio needs to be built manually. In order to avoid artifacts, all python
libraries should be compiled with the same version of the MSC as the python
used. In this case this it is the MSC v1500, 3.5 version of windows SDK.

## Setup Windows SDK
Download, burn and install Windows SDK `GRMSDK_EN_DVD.iso` (32bit version) from here
http://www.microsoft.com/downloads/en/details.aspx?familyid=71DEB800-C591-4F97-A900-BEA146E4FAE1&displaylang=en.

In order to build, start a sdk command line (MSCSHELL) via `Start/Programme/Microsoft windows SDK v7.0/CMD Shell`.

Now get ready for build by entering the commands on this SDK command shell,
which should turn to green afterwards.
```
set DISTUTILS_USE_SDK=1
set MSSdk=1
setenv /x86 /release
```

See also:
* http://www.pybytes.com/pywavelets/dev/preparing_windows_build_environment.html
* http://wiki.cython.org/64BitCythonExtensionsOnWindows

## Compile PortAudio with ASIO support
The SConstruct file delivered with PortAudio does not work with MSC. Therefore,
we provide our own SConstruct, which allows to build PortAudio with ASIO
support (for GUI build with MSV see
http://portaudio.com/docs/v19-doxydocs/compile_windows_asio_msvc.html).

Download PortAudio (the current matching version to PyAudio is 19) from
http://www.portaudio.com/ and extract it to a folder
`portaudio-v19` inside the \texttt{PyAudio} folder.

Download the ASIO support from http://www.steinberg.net/en/company/developer.html
(registration required) or grab it from
r:/MbbmAST/Tech/Tools/Asio/asiosdk2.2.zip and extract it to the
`PyAudio` folder.

The folder Structure should now be:
```
\---PyAudio-0.2.7
+---ASIOSDK2
| +---asio
| +---common
| +---driver
| +---host
+---portaudio-v19
| +---bindings
| +---build
| +---include
| +---src
| ...
+---sphinx
+---src
\---test
```

Copy SConstruct_MSC (remove trailing .py):
```python
from os.path import join, pardir, splitext
from glob import glob

src = []
for path in ( \
"bindings/cpp/source/portaudiocpp",
"src/hostapi/asio",
"src/hostapi/wdmks",
"src/hostapi/wasapi",
"src/hostapi/wmme",
"src/common",
"src/os/win",
"../Asiosdk2/host",
"../Asiosdk2/host/pc"):
for suffix in ('cxx', 'c','cpp'):
src += glob("%s/*.%s" % (path, suffix))
src += glob("../Asiosdk2/common/asio.cpp") # only one file here

incl = [ \
"include",
"bindings/cpp/include",
"src/common",
"src/os/win",
"../Asiosdk2/common",
"../Asiosdk2/host",
"../Asiosdk2/host/pc",
]

defs = ["/DPA_USE_%s=1" % i for i in ('ASIO', 'WMME', 'WASAPI', 'DIRECTX', 'WDMKS')]

# main recipes
env = Environment()
lib = env.Library("lib/.libs/libportaudio", src,
CCFLAGS=defs + ["/EHsc"],
CPPPATH=incl)
```
inside the `portaudio-v19` folder, change to this folder with the (MSCSHELL) and
run `scons -f SConstruct_MSC`.

## Compile PyAudio with PortAudio and ASIO support
The python wrapper `_portaudiomodule.c` is written in a modern C style, with adhoc
/ local variables. In order to compile it with MSC, we need to compile it as C++
file (thus `/Tp` instead of `/Tc`). The following patches are
necessary:

Use `src/_portaudiomodule.c` patch for MSC conformance from this pull
request.

Use `setup.py` patho to support MSC compilation from this pull request.

Finally compile the whole from the MSCSHELL. Change directory to
`PyAudio-0.2.7` and execute:
```python
python setup.py clean --all build --static-link bdist_wininst
```

This will produce the final installer exe in `PyAudio-0.2.7/dist`