diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 9010351..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "_sounddevice_data"] - path = _sounddevice_data - url = https://github.com/spatialaudio/portaudio-binaries.git diff --git a/_sounddevice_data b/_sounddevice_data deleted file mode 160000 index bab7ef6..0000000 --- a/_sounddevice_data +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bab7ef6a62415c2c83bdb632585fa439d3edc48b diff --git a/setup.py b/setup.py index 9a2b175..e8dbe13 100644 --- a/setup.py +++ b/setup.py @@ -1,77 +1,26 @@ -import os -import platform from setuptools import setup __version__ = 'unknown' # "import" __version__ -for line in open('sounddevice.py'): +for line in open('src/sounddevice.py'): if line.startswith('__version__'): exec(line) break -PYTHON_INTERPRETERS = '.'.join([ - 'cp26', 'cp27', - 'cp32', 'cp33', 'cp34', 'cp35', 'cp36', - 'pp27', - 'pp32', 'pp33', 'pp34', 'pp35', 'pp36', -]) -MACOSX_VERSIONS = '.'.join([ - 'macosx_10_6_x86_64', -]) - -# environment variables for cross-platform package creation -system = os.environ.get('PYTHON_SOUNDDEVICE_PLATFORM', platform.system()) -architecture0 = os.environ.get('PYTHON_SOUNDDEVICE_ARCHITECTURE', - platform.architecture()[0]) - -if system == 'Darwin': - libname = 'libportaudio.dylib' -elif system == 'Windows': - libname = 'libportaudio' + architecture0 + '.dll' -else: - libname = None - -if libname and os.path.isdir('_sounddevice_data'): - packages = ['_sounddevice_data'] - package_data = {'_sounddevice_data': [libname, 'README.md']} - zip_safe = False -else: - packages = None - package_data = None - zip_safe = True - -try: - from wheel.bdist_wheel import bdist_wheel -except ImportError: - cmdclass = {} -else: - class bdist_wheel_half_pure(bdist_wheel): - """Create OS-dependent, but Python-independent wheels.""" - def get_tag(self): - pythons = 'py2.py3.' + PYTHON_INTERPRETERS - if system == 'Darwin': - oses = MACOSX_VERSIONS - elif system == 'Windows': - if architecture0 == '32bit': - oses = 'win32' - else: - oses = 'win_amd64' - else: - pythons = 'py2.py3' - oses = 'any' - return pythons, 'none', oses - - cmdclass = {'bdist_wheel': bdist_wheel_half_pure} - setup( name='sounddevice', version=__version__, + package_dir={'': 'src'}, py_modules=['sounddevice'], - packages=packages, - package_data=package_data, - zip_safe=zip_safe, - install_requires=['CFFI>=1.0'], + cffi_modules=['sounddevice_build.py:ffibuilder'], + setup_requires=[ + 'CFFI>=1.4.0', + ], + install_requires=[ + 'CFFI>=1', # for _cffi_backend + ], + zip_safe=True, extras_require={'NumPy': ['NumPy']}, author='Matthias Geier', author_email='Matthias.Geier@gmail.com', @@ -89,5 +38,4 @@ def get_tag(self): 'Programming Language :: Python :: 3', 'Topic :: Multimedia :: Sound/Audio', ], - cmdclass=cmdclass, ) diff --git a/sounddevice_build.py b/sounddevice_build.py new file mode 100644 index 0000000..e5bb2fd --- /dev/null +++ b/sounddevice_build.py @@ -0,0 +1,330 @@ +# This is used to create the _sounddevice extension module (see setup.py). + +import platform + +from cffi import FFI + +OS = platform.system() + +DECLARATIONS = """ +int Pa_GetVersion( void ); +const char* Pa_GetVersionText( void ); +typedef int PaError; +typedef enum PaErrorCode +{ + paNoError = 0, + paNotInitialized = -10000, + paUnanticipatedHostError, + paInvalidChannelCount, + paInvalidSampleRate, + paInvalidDevice, + paInvalidFlag, + paSampleFormatNotSupported, + paBadIODeviceCombination, + paInsufficientMemory, + paBufferTooBig, + paBufferTooSmall, + paNullCallback, + paBadStreamPtr, + paTimedOut, + paInternalError, + paDeviceUnavailable, + paIncompatibleHostApiSpecificStreamInfo, + paStreamIsStopped, + paStreamIsNotStopped, + paInputOverflowed, + paOutputUnderflowed, + paHostApiNotFound, + paInvalidHostApi, + paCanNotReadFromACallbackStream, + paCanNotWriteToACallbackStream, + paCanNotReadFromAnOutputOnlyStream, + paCanNotWriteToAnInputOnlyStream, + paIncompatibleStreamHostApi, + paBadBufferPtr +} PaErrorCode; +const char *Pa_GetErrorText( PaError errorCode ); +PaError Pa_Initialize( void ); +PaError Pa_Terminate( void ); +typedef int PaDeviceIndex; +#define paNoDevice -1 +#define paUseHostApiSpecificDeviceSpecification -2 +typedef int PaHostApiIndex; +PaHostApiIndex Pa_GetHostApiCount( void ); +PaHostApiIndex Pa_GetDefaultHostApi( void ); +typedef enum PaHostApiTypeId +{ + paInDevelopment=0, + paDirectSound=1, + paMME=2, + paASIO=3, + paSoundManager=4, + paCoreAudio=5, + paOSS=7, + paALSA=8, + paAL=9, + paBeOS=10, + paWDMKS=11, + paJACK=12, + paWASAPI=13, + paAudioScienceHPI=14 +} PaHostApiTypeId; +typedef struct PaHostApiInfo +{ + int structVersion; + PaHostApiTypeId type; + const char *name; + int deviceCount; + PaDeviceIndex defaultInputDevice; + PaDeviceIndex defaultOutputDevice; +} PaHostApiInfo; +const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); +PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); +PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, + int hostApiDeviceIndex ); +typedef struct PaHostErrorInfo{ + PaHostApiTypeId hostApiType; + long errorCode; + const char *errorText; +}PaHostErrorInfo; +const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); +PaDeviceIndex Pa_GetDeviceCount( void ); +PaDeviceIndex Pa_GetDefaultInputDevice( void ); +PaDeviceIndex Pa_GetDefaultOutputDevice( void ); +typedef double PaTime; +typedef unsigned long PaSampleFormat; +#define paFloat32 0x00000001 +#define paInt32 0x00000002 +#define paInt24 0x00000004 +#define paInt16 0x00000008 +#define paInt8 0x00000010 +#define paUInt8 0x00000020 +#define paCustomFormat 0x00010000 +#define paNonInterleaved 0x80000000 +typedef struct PaDeviceInfo +{ + int structVersion; + const char *name; + PaHostApiIndex hostApi; + int maxInputChannels; + int maxOutputChannels; + PaTime defaultLowInputLatency; + PaTime defaultLowOutputLatency; + PaTime defaultHighInputLatency; + PaTime defaultHighOutputLatency; + double defaultSampleRate; +} PaDeviceInfo; +const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); +typedef struct PaStreamParameters +{ + PaDeviceIndex device; + int channelCount; + PaSampleFormat sampleFormat; + PaTime suggestedLatency; + void *hostApiSpecificStreamInfo; +} PaStreamParameters; +#define paFormatIsSupported 0 +PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate ); +typedef void PaStream; +#define paFramesPerBufferUnspecified 0 +typedef unsigned long PaStreamFlags; +#define paNoFlag 0 +#define paClipOff 0x00000001 +#define paDitherOff 0x00000002 +#define paNeverDropInput 0x00000004 +#define paPrimeOutputBuffersUsingStreamCallback 0x00000008 +#define paPlatformSpecificFlags 0xFFFF0000 +typedef struct PaStreamCallbackTimeInfo{ + PaTime inputBufferAdcTime; + PaTime currentTime; + PaTime outputBufferDacTime; +} PaStreamCallbackTimeInfo; +typedef unsigned long PaStreamCallbackFlags; +#define paInputUnderflow 0x00000001 +#define paInputOverflow 0x00000002 +#define paOutputUnderflow 0x00000004 +#define paOutputOverflow 0x00000008 +#define paPrimingOutput 0x00000010 +typedef enum PaStreamCallbackResult +{ + paContinue=0, + paComplete=1, + paAbort=2 +} PaStreamCallbackResult; +typedef int PaStreamCallback( + const void *input, void *output, + unsigned long frameCount, + const PaStreamCallbackTimeInfo* timeInfo, + PaStreamCallbackFlags statusFlags, + void *userData ); +PaError Pa_OpenStream( PaStream** stream, + const PaStreamParameters *inputParameters, + const PaStreamParameters *outputParameters, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamFlags streamFlags, + PaStreamCallback *streamCallback, + void *userData ); +PaError Pa_OpenDefaultStream( PaStream** stream, + int numInputChannels, + int numOutputChannels, + PaSampleFormat sampleFormat, + double sampleRate, + unsigned long framesPerBuffer, + PaStreamCallback *streamCallback, + void *userData ); +PaError Pa_CloseStream( PaStream *stream ); +typedef void PaStreamFinishedCallback( void *userData ); +PaError Pa_SetStreamFinishedCallback( PaStream *stream, + PaStreamFinishedCallback* streamFinishedCallback ); +PaError Pa_StartStream( PaStream *stream ); +PaError Pa_StopStream( PaStream *stream ); +PaError Pa_AbortStream( PaStream *stream ); +PaError Pa_IsStreamStopped( PaStream *stream ); +PaError Pa_IsStreamActive( PaStream *stream ); +typedef struct PaStreamInfo +{ + int structVersion; + PaTime inputLatency; + PaTime outputLatency; + double sampleRate; +} PaStreamInfo; +const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); +PaTime Pa_GetStreamTime( PaStream *stream ); +double Pa_GetStreamCpuLoad( PaStream* stream ); +PaError Pa_ReadStream( PaStream* stream, + void *buffer, + unsigned long frames ); +PaError Pa_WriteStream( PaStream* stream, + const void *buffer, + unsigned long frames ); +signed long Pa_GetStreamReadAvailable( PaStream* stream ); +signed long Pa_GetStreamWriteAvailable( PaStream* stream ); +PaHostApiTypeId Pa_GetStreamHostApiType( PaStream* stream ); +PaError Pa_GetSampleSize( PaSampleFormat format ); +void Pa_Sleep( long msec ); +""" + +if OS == 'Darwin': + DECLARATIONS += """ +/* pa_mac_core.h */ + +typedef int32_t SInt32; +typedef struct +{ + unsigned long size; + PaHostApiTypeId hostApiType; + unsigned long version; + unsigned long flags; + SInt32 const * channelMap; + unsigned long channelMapSize; +} PaMacCoreStreamInfo; +void PaMacCore_SetupStreamInfo( PaMacCoreStreamInfo *data, unsigned long flags ); +void PaMacCore_SetupChannelMap( PaMacCoreStreamInfo *data, const SInt32 * const channelMap, unsigned long channelMapSize ); +const char *PaMacCore_GetChannelName( int device, int channelIndex, bool input ); +#define paMacCoreChangeDeviceParameters 0x01 +#define paMacCoreFailIfConversionRequired 0x02 +#define paMacCoreConversionQualityMin 0x0100 +#define paMacCoreConversionQualityMedium 0x0200 +#define paMacCoreConversionQualityLow 0x0300 +#define paMacCoreConversionQualityHigh 0x0400 +#define paMacCoreConversionQualityMax 0x0000 +#define paMacCorePlayNice 0x00 +#define paMacCorePro 0x01 +#define paMacCoreMinimizeCPUButPlayNice 0x0100 +#define paMacCoreMinimizeCPU 0x0101 +""" +elif OS == 'Windows': + DECLARATIONS += """ +/* pa_asio.h */ + +#define paAsioUseChannelSelectors 0x01 + +typedef struct PaAsioStreamInfo +{ + unsigned long size; + PaHostApiTypeId hostApiType; + unsigned long version; + unsigned long flags; + int *channelSelectors; +} PaAsioStreamInfo; + +/* pa_win_wasapi.h */ + +typedef enum PaWasapiFlags +{ + paWinWasapiExclusive = 1, + paWinWasapiRedirectHostProcessor = 2, + paWinWasapiUseChannelMask = 4, + paWinWasapiPolling = 8, + paWinWasapiThreadPriority = 16 +} PaWasapiFlags; + +typedef void (*PaWasapiHostProcessorCallback) ( + void *inputBuffer, long inputFrames, + void *outputBuffer, long outputFrames, void *userData); + +typedef enum PaWasapiThreadPriority +{ + eThreadPriorityNone = 0, + eThreadPriorityAudio, + eThreadPriorityCapture, + eThreadPriorityDistribution, + eThreadPriorityGames, + eThreadPriorityPlayback, + eThreadPriorityProAudio, + eThreadPriorityWindowManager +} PaWasapiThreadPriority; + +typedef enum PaWasapiStreamCategory +{ + eAudioCategoryOther = 0, + eAudioCategoryCommunications = 3, + eAudioCategoryAlerts = 4, + eAudioCategorySoundEffects = 5, + eAudioCategoryGameEffects = 6, + eAudioCategoryGameMedia = 7, + eAudioCategoryGameChat = 8, + eAudioCategorySpeech = 9, + eAudioCategoryMovie = 10, + eAudioCategoryMedia = 11 +} PaWasapiStreamCategory; + +typedef enum PaWasapiStreamOption +{ + eStreamOptionNone = 0, + eStreamOptionRaw = 1, + eStreamOptionMatchFormat = 2 +} PaWasapiStreamOption; + +typedef struct PaWasapiStreamInfo +{ + unsigned long size; + PaHostApiTypeId hostApiType; + unsigned long version; + unsigned long flags; + PaWinWaveFormatChannelMask channelMask; + PaWasapiHostProcessorCallback hostProcessorOutput; + PaWasapiHostProcessorCallback hostProcessorInput; + PaWasapiThreadPriority threadPriority; + PaWasapiStreamCategory streamCategory; + PaWasapiStreamOption streamOption; +} PaWasapiStreamInfo; + +/* pa_win_waveformat.h */ + +typedef unsigned long PaWinWaveFormatChannelMask; +""" + +ffibuilder = FFI() +ffibuilder.cdef(DECLARATIONS) +ffibuilder.set_source( + '_sounddevice', + 'typedef int bool;\n' + DECLARATIONS, + libraries=['portaudio'], +) + +if __name__ == '__main__': + ffibuilder.compile(verbose=True) diff --git a/sounddevice.py b/src/sounddevice.py similarity index 90% rename from sounddevice.py rename to src/sounddevice.py index 8695ce2..73da103 100644 --- a/sounddevice.py +++ b/src/sounddevice.py @@ -31,328 +31,7 @@ import platform as _platform import sys as _sys -_ffi = _FFI() -_ffi.cdef(""" -int Pa_GetVersion( void ); -const char* Pa_GetVersionText( void ); -typedef int PaError; -typedef enum PaErrorCode -{ - paNoError = 0, - paNotInitialized = -10000, - paUnanticipatedHostError, - paInvalidChannelCount, - paInvalidSampleRate, - paInvalidDevice, - paInvalidFlag, - paSampleFormatNotSupported, - paBadIODeviceCombination, - paInsufficientMemory, - paBufferTooBig, - paBufferTooSmall, - paNullCallback, - paBadStreamPtr, - paTimedOut, - paInternalError, - paDeviceUnavailable, - paIncompatibleHostApiSpecificStreamInfo, - paStreamIsStopped, - paStreamIsNotStopped, - paInputOverflowed, - paOutputUnderflowed, - paHostApiNotFound, - paInvalidHostApi, - paCanNotReadFromACallbackStream, - paCanNotWriteToACallbackStream, - paCanNotReadFromAnOutputOnlyStream, - paCanNotWriteToAnInputOnlyStream, - paIncompatibleStreamHostApi, - paBadBufferPtr -} PaErrorCode; -const char *Pa_GetErrorText( PaError errorCode ); -PaError Pa_Initialize( void ); -PaError Pa_Terminate( void ); -typedef int PaDeviceIndex; -#define paNoDevice -1 -#define paUseHostApiSpecificDeviceSpecification -2 -typedef int PaHostApiIndex; -PaHostApiIndex Pa_GetHostApiCount( void ); -PaHostApiIndex Pa_GetDefaultHostApi( void ); -typedef enum PaHostApiTypeId -{ - paInDevelopment=0, - paDirectSound=1, - paMME=2, - paASIO=3, - paSoundManager=4, - paCoreAudio=5, - paOSS=7, - paALSA=8, - paAL=9, - paBeOS=10, - paWDMKS=11, - paJACK=12, - paWASAPI=13, - paAudioScienceHPI=14 -} PaHostApiTypeId; -typedef struct PaHostApiInfo -{ - int structVersion; - PaHostApiTypeId type; - const char *name; - int deviceCount; - PaDeviceIndex defaultInputDevice; - PaDeviceIndex defaultOutputDevice; -} PaHostApiInfo; -const PaHostApiInfo * Pa_GetHostApiInfo( PaHostApiIndex hostApi ); -PaHostApiIndex Pa_HostApiTypeIdToHostApiIndex( PaHostApiTypeId type ); -PaDeviceIndex Pa_HostApiDeviceIndexToDeviceIndex( PaHostApiIndex hostApi, - int hostApiDeviceIndex ); -typedef struct PaHostErrorInfo{ - PaHostApiTypeId hostApiType; - long errorCode; - const char *errorText; -}PaHostErrorInfo; -const PaHostErrorInfo* Pa_GetLastHostErrorInfo( void ); -PaDeviceIndex Pa_GetDeviceCount( void ); -PaDeviceIndex Pa_GetDefaultInputDevice( void ); -PaDeviceIndex Pa_GetDefaultOutputDevice( void ); -typedef double PaTime; -typedef unsigned long PaSampleFormat; -#define paFloat32 0x00000001 -#define paInt32 0x00000002 -#define paInt24 0x00000004 -#define paInt16 0x00000008 -#define paInt8 0x00000010 -#define paUInt8 0x00000020 -#define paCustomFormat 0x00010000 -#define paNonInterleaved 0x80000000 -typedef struct PaDeviceInfo -{ - int structVersion; - const char *name; - PaHostApiIndex hostApi; - int maxInputChannels; - int maxOutputChannels; - PaTime defaultLowInputLatency; - PaTime defaultLowOutputLatency; - PaTime defaultHighInputLatency; - PaTime defaultHighOutputLatency; - double defaultSampleRate; -} PaDeviceInfo; -const PaDeviceInfo* Pa_GetDeviceInfo( PaDeviceIndex device ); -typedef struct PaStreamParameters -{ - PaDeviceIndex device; - int channelCount; - PaSampleFormat sampleFormat; - PaTime suggestedLatency; - void *hostApiSpecificStreamInfo; -} PaStreamParameters; -#define paFormatIsSupported 0 -PaError Pa_IsFormatSupported( const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate ); -typedef void PaStream; -#define paFramesPerBufferUnspecified 0 -typedef unsigned long PaStreamFlags; -#define paNoFlag 0 -#define paClipOff 0x00000001 -#define paDitherOff 0x00000002 -#define paNeverDropInput 0x00000004 -#define paPrimeOutputBuffersUsingStreamCallback 0x00000008 -#define paPlatformSpecificFlags 0xFFFF0000 -typedef struct PaStreamCallbackTimeInfo{ - PaTime inputBufferAdcTime; - PaTime currentTime; - PaTime outputBufferDacTime; -} PaStreamCallbackTimeInfo; -typedef unsigned long PaStreamCallbackFlags; -#define paInputUnderflow 0x00000001 -#define paInputOverflow 0x00000002 -#define paOutputUnderflow 0x00000004 -#define paOutputOverflow 0x00000008 -#define paPrimingOutput 0x00000010 -typedef enum PaStreamCallbackResult -{ - paContinue=0, - paComplete=1, - paAbort=2 -} PaStreamCallbackResult; -typedef int PaStreamCallback( - const void *input, void *output, - unsigned long frameCount, - const PaStreamCallbackTimeInfo* timeInfo, - PaStreamCallbackFlags statusFlags, - void *userData ); -PaError Pa_OpenStream( PaStream** stream, - const PaStreamParameters *inputParameters, - const PaStreamParameters *outputParameters, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamFlags streamFlags, - PaStreamCallback *streamCallback, - void *userData ); -PaError Pa_OpenDefaultStream( PaStream** stream, - int numInputChannels, - int numOutputChannels, - PaSampleFormat sampleFormat, - double sampleRate, - unsigned long framesPerBuffer, - PaStreamCallback *streamCallback, - void *userData ); -PaError Pa_CloseStream( PaStream *stream ); -typedef void PaStreamFinishedCallback( void *userData ); -PaError Pa_SetStreamFinishedCallback( PaStream *stream, - PaStreamFinishedCallback* streamFinishedCallback ); -PaError Pa_StartStream( PaStream *stream ); -PaError Pa_StopStream( PaStream *stream ); -PaError Pa_AbortStream( PaStream *stream ); -PaError Pa_IsStreamStopped( PaStream *stream ); -PaError Pa_IsStreamActive( PaStream *stream ); -typedef struct PaStreamInfo -{ - int structVersion; - PaTime inputLatency; - PaTime outputLatency; - double sampleRate; -} PaStreamInfo; -const PaStreamInfo* Pa_GetStreamInfo( PaStream *stream ); -PaTime Pa_GetStreamTime( PaStream *stream ); -double Pa_GetStreamCpuLoad( PaStream* stream ); -PaError Pa_ReadStream( PaStream* stream, - void *buffer, - unsigned long frames ); -PaError Pa_WriteStream( PaStream* stream, - const void *buffer, - unsigned long frames ); -signed long Pa_GetStreamReadAvailable( PaStream* stream ); -signed long Pa_GetStreamWriteAvailable( PaStream* stream ); -PaHostApiTypeId Pa_GetStreamHostApiType( PaStream* stream ); -PaError Pa_GetSampleSize( PaSampleFormat format ); -void Pa_Sleep( long msec ); - -/* pa_mac_core.h */ - -typedef int32_t SInt32; -typedef struct -{ - unsigned long size; - PaHostApiTypeId hostApiType; - unsigned long version; - unsigned long flags; - SInt32 const * channelMap; - unsigned long channelMapSize; -} PaMacCoreStreamInfo; -void PaMacCore_SetupStreamInfo( PaMacCoreStreamInfo *data, unsigned long flags ); -void PaMacCore_SetupChannelMap( PaMacCoreStreamInfo *data, const SInt32 * const channelMap, unsigned long channelMapSize ); -const char *PaMacCore_GetChannelName( int device, int channelIndex, bool input ); -#define paMacCoreChangeDeviceParameters 0x01 -#define paMacCoreFailIfConversionRequired 0x02 -#define paMacCoreConversionQualityMin 0x0100 -#define paMacCoreConversionQualityMedium 0x0200 -#define paMacCoreConversionQualityLow 0x0300 -#define paMacCoreConversionQualityHigh 0x0400 -#define paMacCoreConversionQualityMax 0x0000 -#define paMacCorePlayNice 0x00 -#define paMacCorePro 0x01 -#define paMacCoreMinimizeCPUButPlayNice 0x0100 -#define paMacCoreMinimizeCPU 0x0101 - -/* pa_win_waveformat.h */ - -typedef unsigned long PaWinWaveFormatChannelMask; - -/* pa_asio.h */ - -#define paAsioUseChannelSelectors 0x01 - -typedef struct PaAsioStreamInfo -{ - unsigned long size; - PaHostApiTypeId hostApiType; - unsigned long version; - unsigned long flags; - int *channelSelectors; -} PaAsioStreamInfo; - -/* pa_win_wasapi.h */ - -typedef enum PaWasapiFlags -{ - paWinWasapiExclusive = 1, - paWinWasapiRedirectHostProcessor = 2, - paWinWasapiUseChannelMask = 4, - paWinWasapiPolling = 8, - paWinWasapiThreadPriority = 16 -} PaWasapiFlags; - -typedef void (*PaWasapiHostProcessorCallback) ( - void *inputBuffer, long inputFrames, - void *outputBuffer, long outputFrames, void *userData); - -typedef enum PaWasapiThreadPriority -{ - eThreadPriorityNone = 0, - eThreadPriorityAudio, - eThreadPriorityCapture, - eThreadPriorityDistribution, - eThreadPriorityGames, - eThreadPriorityPlayback, - eThreadPriorityProAudio, - eThreadPriorityWindowManager -} PaWasapiThreadPriority; - -typedef enum PaWasapiStreamCategory -{ - eAudioCategoryOther = 0, - eAudioCategoryCommunications = 3, - eAudioCategoryAlerts = 4, - eAudioCategorySoundEffects = 5, - eAudioCategoryGameEffects = 6, - eAudioCategoryGameMedia = 7, - eAudioCategoryGameChat = 8, - eAudioCategorySpeech = 9, - eAudioCategoryMovie = 10, - eAudioCategoryMedia = 11 -} PaWasapiStreamCategory; - -typedef enum PaWasapiStreamOption -{ - eStreamOptionNone = 0, - eStreamOptionRaw = 1, - eStreamOptionMatchFormat = 2 -} PaWasapiStreamOption; - -typedef struct PaWasapiStreamInfo -{ - unsigned long size; - PaHostApiTypeId hostApiType; - unsigned long version; - unsigned long flags; - PaWinWaveFormatChannelMask channelMask; - PaWasapiHostProcessorCallback hostProcessorOutput; - PaWasapiHostProcessorCallback hostProcessorInput; - PaWasapiThreadPriority threadPriority; - PaWasapiStreamCategory streamCategory; - PaWasapiStreamOption streamOption; -} PaWasapiStreamInfo; -""") - -try: - _lib = _ffi.dlopen('portaudio') -except OSError: - if _platform.system() == 'Darwin': - _libname = 'libportaudio.dylib' - elif _platform.system() == 'Windows': - _libname = 'libportaudio' + _platform.architecture()[0] + '.dll' - else: - raise - _lib = _ffi.dlopen(_os.path.join( - _os.path.dirname(_os.path.abspath(__file__)), - '_sounddevice_data', - _libname - )) +from _sounddevice import ffi as _ffi, lib as _lib _sampleformats = { 'float32': _lib.paFloat32,