palace
Advanced tools
@@ -29,3 +29,3 @@ #!/usr/bin/env python3 | ||
| QUEUE_SIZE: int = 4 | ||
| PERIOD: float = 0.01 | ||
| PERIOD: float = 0.025 | ||
@@ -32,0 +32,0 @@ |
@@ -26,3 +26,4 @@ #!/usr/bin/env python3 | ||
| from palace import reverb_preset_names, decode, Device, Context, Source, Effect | ||
| from palace import (reverb_preset_names, decode, | ||
| Device, Context, Source, ReverbEffect) | ||
@@ -52,7 +53,5 @@ CHUNK_LEN: int = 12000 | ||
| print('Opened', dev.name) | ||
| with Source() as src, Effect() as fx: | ||
| print('Loading reverb preset', reverb) | ||
| fx.reverb_preset = reverb | ||
| print('Loading reverb preset', reverb) | ||
| with Source() as src, ReverbEffect(reverb) as fx: | ||
| src.sends[0].effect = fx | ||
| for filename in files: | ||
@@ -59,0 +58,0 @@ try: |
| Metadata-Version: 2.1 | ||
| Name: palace | ||
| Version: 0.1.3 | ||
| Version: 0.1.5 | ||
| Summary: Pythonic Audio Library and Codecs Environment | ||
@@ -61,14 +61,5 @@ Home-page: https://github.com/McSinyx/palace | ||
| To ensure that palace can run without any dependencies outside of the [pip] | ||
| toolchain, the wheels are bundled with dynamically linked libraries from | ||
| the build machine, which is similar to static linking: | ||
| Credits to the works bundled with palace can be found in our user | ||
| documentation. | ||
| | Library | License | | ||
| | -------------- | ------------ | | ||
| | [Alure][alure] | ZLib | | ||
| | [OpenAL Soft] | GNU LGPLv2+ | | ||
| | [Vorbis] | 3-clause BSD | | ||
| | [Opus] | 3-clause BSD | | ||
| | [libsndfile] | GNU LGPL2.1+ | | ||
| [alure]: https://github.com/kcat/alure | ||
@@ -75,0 +66,0 @@ [OpenAL Soft]: https://kcat.strangesoft.net/openal.html |
@@ -28,6 +28,2 @@ CMakeLists.txt | ||
| src/util.pxd | ||
| tests/conftest.py | ||
| tests/fmath.py | ||
| tests/test_context.py | ||
| tests/test_listener.py | ||
| tests/test_source.py | ||
| tests/conftest.py |
+3
-12
| Metadata-Version: 2.1 | ||
| Name: palace | ||
| Version: 0.1.3 | ||
| Version: 0.1.5 | ||
| Summary: Pythonic Audio Library and Codecs Environment | ||
@@ -61,14 +61,5 @@ Home-page: https://github.com/McSinyx/palace | ||
| To ensure that palace can run without any dependencies outside of the [pip] | ||
| toolchain, the wheels are bundled with dynamically linked libraries from | ||
| the build machine, which is similar to static linking: | ||
| Credits to the works bundled with palace can be found in our user | ||
| documentation. | ||
| | Library | License | | ||
| | -------------- | ------------ | | ||
| | [Alure][alure] | ZLib | | ||
| | [OpenAL Soft] | GNU LGPLv2+ | | ||
| | [Vorbis] | 3-clause BSD | | ||
| | [Opus] | 3-clause BSD | | ||
| | [libsndfile] | GNU LGPL2.1+ | | ||
| [alure]: https://github.com/kcat/alure | ||
@@ -75,0 +66,0 @@ [OpenAL Soft]: https://kcat.strangesoft.net/openal.html |
+2
-11
@@ -53,14 +53,5 @@ # palace | ||
| To ensure that palace can run without any dependencies outside of the [pip] | ||
| toolchain, the wheels are bundled with dynamically linked libraries from | ||
| the build machine, which is similar to static linking: | ||
| Credits to the works bundled with palace can be found in our user | ||
| documentation. | ||
| | Library | License | | ||
| | -------------- | ------------ | | ||
| | [Alure][alure] | ZLib | | ||
| | [OpenAL Soft] | GNU LGPLv2+ | | ||
| | [Vorbis] | 3-clause BSD | | ||
| | [Opus] | 3-clause BSD | | ||
| | [libsndfile] | GNU LGPL2.1+ | | ||
| [alure]: https://github.com/kcat/alure | ||
@@ -67,0 +58,0 @@ [OpenAL Soft]: https://kcat.strangesoft.net/openal.html |
+1
-1
| [metadata] | ||
| name = palace | ||
| version = 0.1.3 | ||
| version = 0.1.5 | ||
| url = https://github.com/McSinyx/palace | ||
@@ -5,0 +5,0 @@ author = Nguyễn Gia Phong |
+30
-181
@@ -28,3 +28,3 @@ # Cython declarations of alure | ||
| from std cimport duration, nanoseconds, milliseconds, shared_future, streambuf | ||
| from std cimport duration, nanoseconds, milliseconds, streambuf | ||
@@ -88,33 +88,33 @@ | ||
| cdef cppclass EFXEAXREVERBPROPERTIES: | ||
| float flDensity | ||
| float flDiffusion | ||
| float flGain | ||
| float flGainHF | ||
| float flGainLF | ||
| float flDecayTime | ||
| float flDecayHFRatio | ||
| float flDecayLFRatio | ||
| float flReflectionsGain | ||
| float flReflectionsDelay | ||
| float flReflectionsPan[3] | ||
| float flLateReverbGain | ||
| float flLateReverbDelay | ||
| float flLateReverbPan[3] | ||
| float flEchoTime | ||
| float flEchoDepth | ||
| float flModulationTime | ||
| float flModulationDepth | ||
| float flAirAbsorptionGainHF | ||
| float flHFReference | ||
| float flLFReference | ||
| float flRoomRolloffFactor | ||
| int iDecayHFLimit | ||
| float density 'flDensity' | ||
| float diffusion 'flDiffusion' | ||
| float gain 'flGain' | ||
| float gain_hf 'flGainHF' | ||
| float gain_lf 'flGainLF' | ||
| float decay_time 'flDecayTime' | ||
| float decay_hf_ratio 'flDecayHFRatio' | ||
| float decay_lf_ratio 'flDecayLFRatio' | ||
| float reflections_gain 'flReflectionsGain' | ||
| float reflections_delay 'flReflectionsDelay' | ||
| float reflections_pan 'flReflectionsPan'[3] | ||
| float late_reverb_gain 'flLateReverbGain' | ||
| float late_reverb_delay 'flLateReverbDelay' | ||
| float late_reverb_pan 'flLateReverbPan'[3] | ||
| float echo_time 'flEchoTime' | ||
| float echo_depth 'flEchoDepth' | ||
| float modulation_time 'flModulationTime' | ||
| float modulation_depth 'flModulationDepth' | ||
| float air_absorption_gain_hf 'flAirAbsorptionGainHF' | ||
| float hf_reference 'flHFReference' | ||
| float lf_reference 'flLFReference' | ||
| float room_rolloff_factor 'flRoomRolloffFactor' | ||
| int decay_hf_limit 'iDecayHFLimit' | ||
| cdef cppclass EFXCHORUSPROPERTIES: | ||
| int iWaveform | ||
| int iPhase | ||
| float flRate | ||
| float flDepth | ||
| float flFeedback | ||
| float flDelay | ||
| int waveform 'iWaveform' | ||
| int phase 'iPhase' | ||
| float rate 'flRate' | ||
| float depth 'flDepth' | ||
| float feedback 'flFeedback' | ||
| float delay 'flDelay' | ||
@@ -134,3 +134,2 @@ | ||
| # SharedPtr: shared_ptr | ||
| # SharedFuture: shared_future | ||
@@ -215,28 +214,12 @@ # Structs: | ||
| DeviceManager get_instance 'getInstance'() except + | ||
| DeviceManager() # nil | ||
| DeviceManager(const DeviceManager&) | ||
| DeviceManager(DeviceManager&&) | ||
| boolean operator bool() | ||
| boolean query_extension 'queryExtension'(const string&) except + | ||
| vector[string] enumerate(DeviceEnumeration) except + | ||
| string default_device_name 'defaultDeviceName'(DefaultDeviceType) except + | ||
| Device open_playback 'openPlayback'() except + | ||
| Device open_playback 'openPlayback'(const string&) except + | ||
| cdef cppclass Device: | ||
| ctypedef DeviceImpl* handle_type | ||
| Device() # nil | ||
| Device(DeviceImpl*) | ||
| Device(const Device&) | ||
| Device(Device&&) | ||
| Device& operator=(const Device&) | ||
| Device& operator=(Device&&) | ||
| boolean operator==(const Device&) | ||
@@ -248,7 +231,4 @@ boolean operator!=(const Device&) | ||
| boolean operator>(const Device&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| string get_name 'getName'() except + | ||
@@ -258,3 +238,2 @@ string get_name 'getName'(PlaybackName) except + | ||
| boolean query_extension 'queryExtension'(const string&) except + | ||
| Version get_alc_version 'getALCVersion'() except + | ||
@@ -283,12 +262,3 @@ Version get_efx_version 'getEFXVersion'() except + | ||
| cdef cppclass Context: | ||
| ctypedef ContextImpl* handle_type | ||
| Context() # nil | ||
| Context(ContextImpl*) | ||
| Context(const Context&) | ||
| Context(Context&&) | ||
| Context& operator=(const Context&) | ||
| Context& operator=(Context&&) | ||
| boolean operator==(const Context&) | ||
@@ -300,7 +270,4 @@ boolean operator!=(const Context&) | ||
| boolean operator>(const Context&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| @staticmethod | ||
@@ -339,9 +306,4 @@ void make_current 'MakeCurrent'(Context) except + | ||
| void precache_buffers_async 'precacheBuffersAsync'(vector[StringView]) except + | ||
| Buffer create_buffer_from 'createBufferFrom'(string, shared_ptr[Decoder]) except + | ||
| shared_future[Buffer] create_buffer_async_from 'createBufferAsyncFrom'(string, shared_ptr[Decoder]) except + | ||
| Buffer find_buffer 'findBuffer'(string) except + | ||
| shared_future[Buffer] find_buffer_async 'findBufferAsync'(string) except + | ||
| void remove_buffer 'removeBuffer'(string) except + | ||
@@ -362,48 +324,13 @@ void remove_buffer 'removeBuffer'(Buffer) except + | ||
| cdef cppclass Listener: | ||
| ctypedef ListenerImpl* handle_type | ||
| Listener() # nil | ||
| Listener(ListenerImpl*) | ||
| Listener(const Listener&) | ||
| Listener(Listener&&) | ||
| Listener& operator=(const Listener&) | ||
| Listener& operator=(Listener&&) | ||
| boolean operator==(const Listener&) | ||
| boolean operator!=(const Listener&) | ||
| boolean operator<=(const Listener&) | ||
| boolean operator>=(const Listener&) | ||
| boolean operator<(const Listener&) | ||
| boolean operator>(const Listener&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| float set_gain 'setGain'(float) except + | ||
| float set_3d_parameters 'set3DParameters'(const Vector3&, const Vector3&, const Vector3&) except + | ||
| void set_position 'setPosition'(const Vector3 &) except + | ||
| void set_position 'setPosition'(const float*) except + | ||
| void set_velocity 'setVelocity'(const Vector3&) except + | ||
| void set_velocity 'setVelocity'(const float*) except + | ||
| void set_orientation 'setOrientation'(const pair[Vector3, Vector3]&) except + | ||
| void set_orientation 'setOrientation'(const float*, const float*) except + | ||
| void set_orientation 'setOrientation'(const float*) except + | ||
| void set_meters_per_unit 'setMetersPerUnit'(float) except + | ||
| cdef cppclass Buffer: | ||
| ctypedef BufferImpl* handle_type | ||
| Buffer() # nil | ||
| Buffer(BufferImpl*) | ||
| Buffer(const Buffer&) | ||
| Buffer(Buffer&&) | ||
| Buffer& operator=(const Buffer&) | ||
| Buffer& operator=(Buffer&&) | ||
| boolean operator==(const Buffer&) | ||
@@ -415,7 +342,4 @@ boolean operator!=(const Buffer&) | ||
| boolean operator>(const Buffer&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| unsigned get_length 'getLength'() except + | ||
@@ -428,3 +352,2 @@ unsigned get_frequency 'getFrequency'() except + | ||
| vector[Source] get_sources 'getSources'() except + | ||
| # name is implemented as a read-only attribute in Cython | ||
| pair[unsigned, unsigned] get_loop_points 'getLoopPoints'() except + | ||
@@ -434,12 +357,3 @@ void set_loop_points 'setLoopPoints'(unsigned, unsigned) except + | ||
| cdef cppclass Source: | ||
| ctypedef SourceImpl* handle_type | ||
| Source() # nil | ||
| Source(SourceImpl*) | ||
| Source(const Source&) | ||
| Source(Source&&) | ||
| Source& operator=(const Source&) | ||
| Source& operator=(Source&&) | ||
| boolean operator==(const Source&) | ||
@@ -451,10 +365,6 @@ boolean operator!=(const Source&) | ||
| boolean operator>(const Source&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| void play(Buffer) except + | ||
| void play(shared_ptr[Decoder], int, int) except + | ||
| void play(shared_future[Buffer]) except + | ||
@@ -466,6 +376,4 @@ void stop() except + | ||
| boolean is_pending 'isPending'() except + | ||
| boolean is_playing 'isPlaying'() except + | ||
| boolean is_paused 'isPaused'() except + | ||
| boolean is_playing_or_pending 'isPlayingOrPending'() except + | ||
@@ -494,28 +402,16 @@ void set_group 'setGroup'(SourceGroup) except + | ||
| pair[float, float] get_gain_range 'getGainRange'() except + | ||
| float get_min_gain 'getMinGain'() except + | ||
| float get_max_gain 'getMaxGain'() except + | ||
| void set_distance_range 'setDistanceRange'(float, float) except + | ||
| pair[float, float] get_distance_range 'getDistanceRange'() except + | ||
| float get_reference_distance 'getReferenceDistance'() except + | ||
| float get_max_distance 'getMaxDistance'() except + | ||
| void set_3d_parameters 'set3DParameters'(const Vector3&, const Vector3&, const Vector3&) except + | ||
| void set_3d_parameters 'set3DParameters'(const Vector3&, const Vector3&, const pair[Vector3, Vector3]&) except + | ||
| void set_position 'setPosition'(const Vector3&) except + | ||
| void set_position 'setPosition'(const float*) except + | ||
| Vector3 get_position 'getPosition'() except + | ||
| void set_velocity 'setVelocity'(const Vector3&) except + | ||
| void set_velocity 'setVelocity'(const float*) except + | ||
| Vector3 get_velocity 'getVelocity'() except + | ||
| void set_direction 'setDirection'(const Vector3&) except + | ||
| void set_direction 'setDirection'(const float*) except + | ||
| Vector3 get_direction 'getDirection'() except + | ||
| void set_orientation 'setOrientation'(const pair[Vector3, Vector3]&) except + | ||
| void set_orientation 'setOrientation'(const float*, const float*) except + | ||
| void set_orientation 'setOrientation'(const float*) except + | ||
| pair[Vector3, Vector3] get_orientation 'getOrientation'() except + | ||
@@ -525,16 +421,8 @@ | ||
| pair[float, float] get_cone_angles 'getConeAngles'() except + | ||
| float get_inner_cone_angle 'getInnerConeAngle'() except + | ||
| float get_outer_cone_angle 'getOuterConeAngle'() except + | ||
| void set_outer_cone_gains 'setOuterConeGains'(float) except + | ||
| void set_outer_cone_gains 'setOuterConeGains'(float, float) except + | ||
| pair[float, float] get_outer_cone_gains 'getOuterConeGains'() except + | ||
| float get_outer_cone_gain 'getOuterConeGain'() except + | ||
| float get_outer_cone_gainhf 'getOuterConeGainHF'() except + | ||
| void set_rolloff_factors 'setRolloffFactors'(float) except + | ||
| void set_rolloff_factors 'setRolloffFactors'(float, float) except + | ||
| pair[float, float] get_rolloff_factors 'getRolloffFactors'() except + | ||
| float get_rolloff_factor 'getRolloffFactor'() except + | ||
| float get_room_rolloff_factor 'getRoomRolloffFactor'() except + | ||
@@ -576,12 +464,3 @@ void set_doppler_factor 'setDopplerFactor'(float) except + | ||
| cdef cppclass SourceGroup: | ||
| ctypedef SourceImpl* handle_type | ||
| SourceGroup() # nil | ||
| SourceGroup(SourceGroupImpl*) | ||
| SourceGroup(const SourceGroup&) | ||
| SourceGroup(SourceGroup&&) | ||
| SourceGroup& operator=(const SourceGroup&) | ||
| SourceGroup& operator=(SourceGroup&&) | ||
| boolean operator==(const SourceGroup&) | ||
@@ -593,6 +472,4 @@ boolean operator!=(const SourceGroup&) | ||
| boolean operator>(const SourceGroup&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| void set_parent_group 'setParentGroup'(SourceGroup) except + | ||
@@ -617,12 +494,3 @@ SourceGroup get_parent_group 'getParentGroup'() except + | ||
| cdef cppclass AuxiliaryEffectSlot: | ||
| ctypedef AuxiliaryEffectSlotImpl* handle_type | ||
| AuxiliaryEffectSlot() # nil | ||
| AuxiliaryEffectSlot(AuxiliaryEffectSlotImpl*) | ||
| AuxiliaryEffectSlot(const AuxiliaryEffectSlot&) | ||
| AuxiliaryEffectSlot(AuxiliaryEffectSlot&&) | ||
| AuxiliaryEffectSlot& operator=(const AuxiliaryEffectSlot&) | ||
| AuxiliaryEffectSlot& operator=(AuxiliaryEffectSlot&&) | ||
| boolean operator==(const AuxiliaryEffectSlot&) | ||
@@ -634,7 +502,4 @@ boolean operator!=(const AuxiliaryEffectSlot&) | ||
| boolean operator>(const AuxiliaryEffectSlot&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| void set_gain 'setGain'(float) except + | ||
@@ -649,12 +514,3 @@ void set_send_auto 'setSendAuto'(bool) except + | ||
| cdef cppclass Effect: | ||
| ctypedef EffectImpl* handle_type | ||
| Effect() # nil | ||
| Effect(EffectImpl*) | ||
| Effect(const Effect&) | ||
| Effect(Effect&&) | ||
| Effect& operator=(const Effect&) | ||
| Effect& operator=(Effect&&) | ||
| boolean operator==(const Effect&) | ||
@@ -666,10 +522,6 @@ boolean operator!=(const Effect&) | ||
| boolean operator>(const Effect&) | ||
| boolean operator bool() | ||
| handle_type get_handle 'getHandle'() | ||
| void set_reverb_properties 'setReverbProperties'(const EFXEAXREVERBPROPERTIES&) except + | ||
| void set_chorus_properties 'setChorusProperties'(const EFXCHORUSPROPERTIES&) except + | ||
| void destroy() except + | ||
@@ -681,8 +533,5 @@ | ||
| SampleType get_sample_type 'getSampleType'() | ||
| uint64_t get_length 'getLength'() | ||
| boolean seek(uint64_t) | ||
| pair[uint64_t, uint64_t] get_loop_points 'getLoopPoints'() | ||
| int read(void*, int) | ||
@@ -689,0 +538,0 @@ |
+0
-6
@@ -40,8 +40,2 @@ # Cython declarations of some missing C++ standard libraries | ||
| cdef extern from '<future>' namespace 'std' nogil: | ||
| cdef cppclass shared_future[R]: | ||
| R& get() except + | ||
| boolean valid() const | ||
| cdef extern from '<ratio>' namespace 'std' nogil: | ||
@@ -48,0 +42,0 @@ cdef cppclass nano: |
+31
-15
@@ -1,2 +0,3 @@ | ||
| # test environment | ||
| # Common test fixtures | ||
| # Copyright (C) 2020 Ngô Ngọc Đức Huy | ||
| # Copyright (C) 2020 Nguyễn Gia Phong | ||
@@ -19,21 +20,36 @@ # | ||
| """This module provide default objects of palace classes as fixtures | ||
| for convenient testing. | ||
| """ | ||
| from os.path import abspath, dirname, join | ||
| from pytest import fixture | ||
| from palace import Device, Context | ||
| DATA_DIR = abspath(join(dirname(__file__), 'data')) | ||
| @fixture(scope='session') | ||
| def device(): | ||
| """Provide the default device.""" | ||
| with Device() as dev: yield dev | ||
| @fixture | ||
| def aiff(): | ||
| """Provide a sample AIFF file.""" | ||
| return join(DATA_DIR, '24741__tim-kahn__b23-c1-raw.aiff') | ||
| @fixture(scope='session') | ||
| def context(device): | ||
| """Provide a context creared from the default device | ||
| (default context). | ||
| """ | ||
| with Context(device) as ctx: yield ctx | ||
| @fixture | ||
| def flac(): | ||
| """Provide a sample FLAC file.""" | ||
| return join(DATA_DIR, '261590__kwahmah-02__little-glitch.flac') | ||
| @fixture | ||
| def mp3(): | ||
| """Provide a sample MP3 file.""" | ||
| return join(DATA_DIR, '353684__tec-studio__drip2.mp3') | ||
| @fixture | ||
| def ogg(): | ||
| """Provide a sample Ogg Vorbis file.""" | ||
| return join(DATA_DIR, '164957__zonkmachine__white-noise.ogg') | ||
| @fixture | ||
| def wav(): | ||
| """Provide a sample WAVE file.""" | ||
| return join(DATA_DIR, '99642__jobro__deconvoluted-20hz-to-20khz.wav') |
| # single-precision floating-point math | ||
| # Copyright (C) 2020 Nguyễn Gia Phong | ||
| # | ||
| # This file is part of palace. | ||
| # | ||
| # palace is free software: you can redistribute it and/or modify it | ||
| # under the terms of the GNU Lesser General Public License as published | ||
| # by the Free Software Foundation, either version 3 of the License, | ||
| # or (at your option) any later version. | ||
| # | ||
| # palace is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with palace. If not, see <https://www.gnu.org/licenses/>. | ||
| """This module provides access to mathematical functions | ||
| for single-precision floating-point numbers. | ||
| """ | ||
| __all__ = ['FLT_MAX', 'allclose', 'isclose'] | ||
| from math import isclose as _isclose | ||
| from typing import Sequence | ||
| FLT_EPSILON: float = 2.0 ** -23 | ||
| FLT_MAX: float = 2.0**128 - 2.0**104 | ||
| def isclose(a: float, b: float) -> bool: | ||
| """Determine whether two single-precision floating-point numbers | ||
| are close in value. | ||
| For the values to be considered close, the relative difference | ||
| between them must be smaller than FLT_EPSILON. | ||
| -inf, inf and NaN behave similarly to the IEEE 754 Standard. | ||
| That is, NaN is not close to anything, even itself. | ||
| inf and -inf are only close to themselves. | ||
| """ | ||
| return _isclose(a, b, rel_tol=FLT_EPSILON) | ||
| def allclose(a: Sequence[float], b: Sequence[float]) -> bool: | ||
| """Determine whether two sequences of single-precision | ||
| floating-point numbers are close in value. | ||
| For the values to be considered close, the relative difference | ||
| between them must be smaller than FLT_EPSILON. | ||
| -inf, inf and NaN behave similarly to the IEEE 754 Standard. | ||
| That is, NaN is not close to anything, even itself. | ||
| inf and -inf are only close to themselves. | ||
| """ | ||
| return all(map(isclose, a, b)) |
| # Source pytest module | ||
| # Copyright (C) 2020 Ngô Ngọc Đức Huy | ||
| # Copyright (C) 2020 Nguyễn Gia Phong | ||
| # Copyright (C) 2020 Ngô Xuân Minh | ||
| # | ||
| # This file is part of palace. | ||
| # | ||
| # palace is free software: you can redistribute it and/or modify it | ||
| # under the terms of the GNU Lesser General Public License as published | ||
| # by the Free Software Foundation, either version 3 of the License, | ||
| # or (at your option) any later version. | ||
| # | ||
| # palace is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with palace. If not, see <https://www.gnu.org/licenses/>. | ||
| """This pytest module tries to test the correctness of the class Context.""" | ||
| from palace import current_context, distance_models, Context, MessageHandler | ||
| from pytest import raises | ||
| from math import inf | ||
| def test_with_context(device): | ||
| """Test if `with` can be used to start a context | ||
| and is destroyed properly. | ||
| """ | ||
| with Context(device) as context: | ||
| assert current_context() == context | ||
| def test_nested_context_manager(device): | ||
| """Test if the context manager returns to the | ||
| previous context. | ||
| """ | ||
| with Context(device) as context: | ||
| with Context(device): pass | ||
| assert current_context() == context | ||
| def test_message_handler(device): | ||
| """Test read-write property MessageHandler.""" | ||
| context = Context(device) | ||
| assert type(context.message_handler) is MessageHandler | ||
| message_handler_test = type('MessageHandlerTest', (MessageHandler,), {})() | ||
| context.message_handler = message_handler_test | ||
| assert context.message_handler is message_handler_test | ||
| with context: | ||
| assert current_context().message_handler is context.message_handler | ||
| def test_async_wake_interval(device): | ||
| """Test read-write property async_wake_interval.""" | ||
| with Context(device) as context: | ||
| context.async_wake_interval = 42 | ||
| assert context.async_wake_interval == 42 | ||
| def test_default_resampler_index(device): | ||
| """Test return values default_resampler_index.""" | ||
| with Context(device) as context: | ||
| index = context.default_resampler_index | ||
| assert index >= 0 | ||
| assert len(context.available_resamplers) > index | ||
| def test_doppler_factor(device): | ||
| """Test write property doppler_factor.""" | ||
| with Context(device) as context: | ||
| context.doppler_factor = 4/9 | ||
| context.doppler_factor = 9/4 | ||
| context.doppler_factor = 0 | ||
| context.doppler_factor = inf | ||
| with raises(ValueError): context.doppler_factor = -1 | ||
| def test_speed_of_sound(device): | ||
| """Test write property speed_of_sound.""" | ||
| with Context(device) as context: | ||
| context.speed_of_sound = 5/7 | ||
| context.speed_of_sound = 7/5 | ||
| with raises(ValueError): context.speed_of_sound = 0 | ||
| context.speed_of_sound = inf | ||
| with raises(ValueError): context.speed_of_sound = -1 | ||
| def test_distance_model(device): | ||
| """Test preset values distance_model.""" | ||
| with Context(device) as context: | ||
| for model in distance_models: context.distance_model = model | ||
| with raises(ValueError): context.distance_model = 'EYYYYLMAO' |
| # Listener pytest module | ||
| # Copyright (C) 2020 Ngô Xuân Minh | ||
| # | ||
| # This file is part of palace. | ||
| # | ||
| # palace is free software: you can redistribute it and/or modify it | ||
| # under the terms of the GNU Lesser General Public License as published | ||
| # by the Free Software Foundation, either version 3 of the License, | ||
| # or (at your option) any later version. | ||
| # | ||
| # palace is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with palace. If not, see <https://www.gnu.org/licenses/>. | ||
| """This pytest module tries to test the correctness of the class Listener.""" | ||
| from pytest import raises | ||
| from math import inf | ||
| def test_gain(context): | ||
| """Test write property gain.""" | ||
| context.listener.gain = 5/7 | ||
| context.listener.gain = 7/5 | ||
| context.listener.gain = 0 | ||
| context.listener.gain = inf | ||
| with raises(ValueError): context.listener.gain = -1 | ||
| def test_position(context): | ||
| """Test write property position.""" | ||
| context.listener.position = 1, 0, 1 | ||
| context.listener.position = 1, 0, -1 | ||
| context.listener.position = 1, -1, 0 | ||
| context.listener.position = 1, 1, 0 | ||
| context.listener.position = 0, 0, 0 | ||
| context.listener.position = 1, 1, 1 | ||
| def test_velocity(context): | ||
| """Test write property velocity.""" | ||
| context.listener.velocity = 420, 0, 69 | ||
| context.listener.velocity = 69, 0, -420 | ||
| context.listener.velocity = 0, 420, -69 | ||
| context.listener.velocity = 0, 0, 42 | ||
| context.listener.velocity = 0, 0, 0 | ||
| context.listener.velocity = 420, 69, 420 | ||
| def test_orientaion(context): | ||
| """Test write property orientation.""" | ||
| context.listener.orientation = (420, 0, 69), (0, 42, 0) | ||
| context.listener.orientation = (69, 0, -420), (0, -69, 420) | ||
| context.listener.orientation = (0, 420, -69), (420, -69, 69) | ||
| context.listener.orientation = (0, 0, 42), (-420, -420, 0) | ||
| context.listener.orientation = (0, 0, 0), (-420, -69, -69) | ||
| context.listener.orientation = (420, 69, 420), (69, -420, 0) | ||
| def test_meters_per_unit(context): | ||
| """Test write property meter_per_unit.""" | ||
| context.listener.meters_per_unit = 4/9 | ||
| context.listener.meters_per_unit = 9/4 | ||
| with raises(ValueError): context.listener.meters_per_unit = 0 | ||
| context.listener.meters_per_unit = inf | ||
| with raises(ValueError): context.listener.meters_per_unit = -1 |
| # Source pytest module | ||
| # Copyright (C) 2020 Nguyễn Gia Phong | ||
| # | ||
| # This file is part of palace. | ||
| # | ||
| # palace is free software: you can redistribute it and/or modify it | ||
| # under the terms of the GNU Lesser General Public License as published | ||
| # by the Free Software Foundation, either version 3 of the License, | ||
| # or (at your option) any later version. | ||
| # | ||
| # palace is distributed in the hope that it will be useful, | ||
| # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| # GNU Lesser General Public License for more details. | ||
| # | ||
| # You should have received a copy of the GNU Lesser General Public License | ||
| # along with palace. If not, see <https://www.gnu.org/licenses/>. | ||
| """This pytest module tries to test the correctness of the class Source.""" | ||
| from itertools import product, repeat | ||
| from math import inf, pi | ||
| from operator import is_ | ||
| from palace import Source, SourceGroup | ||
| from pytest import raises | ||
| from fmath import FLT_MAX, allclose, isclose | ||
| def test_group(context): | ||
| """Test read-write property group.""" | ||
| with Source(context) as source, SourceGroup(context) as source_group: | ||
| assert source.group is None | ||
| source.group = source_group | ||
| assert source.group == source_group | ||
| assert source in source_group.sources | ||
| source.group = None | ||
| assert source.group is None | ||
| def test_priority(context): | ||
| """Test read-write property priority.""" | ||
| with Source(context) as source: | ||
| assert source.priority == 0 | ||
| source.priority = 42 | ||
| assert source.priority == 42 | ||
| def test_offset(context): | ||
| """Test read-write property offset.""" | ||
| with Source(context) as source: | ||
| assert source.offset == 0 | ||
| # TODO: give the source a decoder to seek | ||
| def test_looping(context): | ||
| """Test read-write property looping.""" | ||
| with Source(context) as source: | ||
| assert source.looping is False | ||
| source.looping = True | ||
| assert source.looping is True | ||
| source.looping = False | ||
| assert source.looping is False | ||
| def test_pitch(context): | ||
| """Test read-write property pitch.""" | ||
| with Source(context) as source: | ||
| assert isclose(source.pitch, 1) | ||
| with raises(ValueError): source.pitch = -1 | ||
| source.pitch = 5 / 7 | ||
| assert isclose(source.pitch, 5/7) | ||
| def test_gain(context): | ||
| """Test read-write property gain.""" | ||
| with Source(context) as source: | ||
| assert isclose(source.gain, 1) | ||
| with raises(ValueError): source.gain = -1 | ||
| source.gain = 5 / 7 | ||
| assert isclose(source.gain, 5/7) | ||
| def test_gain_range(context): | ||
| """Test read-write property gain_range.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.gain_range, (0, 1)) | ||
| with raises(ValueError): source.gain_range = 9/11, 5/7 | ||
| with raises(ValueError): source.gain_range = 6/9, 420 | ||
| with raises(ValueError): source.gain_range = -420, 6/9 | ||
| source.gain_range = 5/7, 9/11 | ||
| assert allclose(source.gain_range, (5/7, 9/11)) | ||
| def test_distance_range(context): | ||
| """Test read-write property distance_range.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.distance_range, (1, FLT_MAX)) | ||
| with raises(ValueError): source.distance_range = 9/11, 5/7 | ||
| with raises(ValueError): source.distance_range = -420, 6/9 | ||
| with raises(ValueError): source.distance_range = 420, inf | ||
| source.distance_range = 5/7, 9/11 | ||
| assert allclose(source.distance_range, (5/7, 9/11)) | ||
| source.distance_range = 1, FLT_MAX | ||
| assert allclose(source.distance_range, (1, FLT_MAX)) | ||
| def test_position(context): | ||
| """Test read-write property position.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.position, (0, 0, 0)) | ||
| source.position = -1, 0, 1 | ||
| assert allclose(source.position, (-1, 0, 1)) | ||
| source.position = 4, 20, 69 | ||
| assert allclose(source.position, (4, 20, 69)) | ||
| def test_velocity(context): | ||
| """Test read-write property velocity.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.velocity, (0, 0, 0)) | ||
| source.velocity = -1, 0, 1 | ||
| assert allclose(source.velocity, (-1, 0, 1)) | ||
| source.velocity = 4, 20, 69 | ||
| assert allclose(source.velocity, (4, 20, 69)) | ||
| def test_orientation(context): | ||
| """Test read-write property orientation.""" | ||
| with Source(context) as source: | ||
| assert all(map(allclose, source.orientation, ((0, 0, -1), (0, 1, 0)))) | ||
| source.orientation = (1, 1, -2), (3, -5, 8) | ||
| assert all(map(allclose, source.orientation, ((1, 1, -2), (3, -5, 8)))) | ||
| def test_cone_angles(context): | ||
| """Test read-write property cone_angles.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.cone_angles, (360, 360)) | ||
| with raises(ValueError): source.cone_angles = 420, 69 | ||
| with raises(ValueError): source.cone_angles = -4.20, 69 | ||
| with raises(ValueError): source.cone_angles = 4.20, -69 | ||
| source.cone_angles = 4.20, 69 | ||
| assert allclose(source.cone_angles, (4.20, 69)) | ||
| def test_outer_cone_gains(context): | ||
| """Test read-write property outer_cone_gains.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.outer_cone_gains, (0, 1)) | ||
| with raises(ValueError): source.outer_cone_gains = 6/9, -420 | ||
| with raises(ValueError): source.outer_cone_gains = 6/9, 420 | ||
| with raises(ValueError): source.outer_cone_gains = -420, 6/9 | ||
| with raises(ValueError): source.outer_cone_gains = 420, 6/9 | ||
| source.outer_cone_gains = 5/7, 9/11 | ||
| assert allclose(source.outer_cone_gains, (5/7, 9/11)) | ||
| def test_rolloff_factors(context): | ||
| """Test read-write property rolloff_factors.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.rolloff_factors, (1, 0)) | ||
| with raises(ValueError): source.rolloff_factors = -6, 9 | ||
| with raises(ValueError): source.rolloff_factors = 6, -9 | ||
| source.rolloff_factors = 6, 9 | ||
| assert allclose(source.rolloff_factors, (6, 9)) | ||
| def test_doppler_factor(context): | ||
| """Test read-write property doppler_factor.""" | ||
| with Source(context) as source: | ||
| assert isclose(source.doppler_factor, 1) | ||
| with raises(ValueError): source.doppler_factor = -6.9 | ||
| with raises(ValueError): source.doppler_factor = 4.20 | ||
| source.doppler_factor = 5 / 7 | ||
| assert isclose(source.doppler_factor, 5/7) | ||
| def test_relative(context): | ||
| """Test read-write property relative.""" | ||
| with Source(context) as source: | ||
| assert source.relative is False | ||
| source.relative = True | ||
| assert source.relative is True | ||
| source.relative = False | ||
| assert source.relative is False | ||
| def test_radius(context): | ||
| """Test read-write property radius.""" | ||
| with Source(context) as source: | ||
| assert isclose(source.radius, 0) | ||
| with raises(ValueError): source.radius = -1 | ||
| source.radius = 5 / 7 | ||
| assert isclose(source.radius, 5/7) | ||
| def test_stereo_angles(context): | ||
| """Test read-write property stereo_angles.""" | ||
| with Source(context) as source: | ||
| assert allclose(source.stereo_angles, (pi/6, -pi/6)) | ||
| source.stereo_angles = 420, -69 | ||
| assert allclose(source.stereo_angles, (420, -69)) | ||
| source.stereo_angles = -5/7, 9/11 | ||
| assert allclose(source.stereo_angles, (-5/7, 9/11)) | ||
| def test_spatialize(context): | ||
| """Test read-write property spatialize.""" | ||
| with Source(context) as source: | ||
| assert source.spatialize is None | ||
| source.spatialize = False | ||
| assert source.spatialize is False | ||
| source.spatialize = True | ||
| assert source.spatialize is True | ||
| source.spatialize = None | ||
| assert source.spatialize is None | ||
| def test_resampler_index(context): | ||
| """Test read-write property resampler_index.""" | ||
| with Source(context) as source: | ||
| # TODO: test initial value | ||
| with raises(ValueError): source.resampler_index = -1 | ||
| source.resampler_index = 69 | ||
| assert source.resampler_index == 69 | ||
| def test_air_absorption_factor(context): | ||
| """Test read-write property air_absorption_factor.""" | ||
| with Source(context) as source: | ||
| assert isclose(source.air_absorption_factor, 0) | ||
| with raises(ValueError): source.air_absorption_factor = -1 | ||
| with raises(ValueError): source.air_absorption_factor = 11 | ||
| source.air_absorption_factor = 420 / 69 | ||
| assert isclose(source.air_absorption_factor, 420/69) | ||
| def test_gain_auto(context): | ||
| """Test read-write property gain_auto.""" | ||
| with Source(context) as source: | ||
| assert all(gain is True for gain in source.gain_auto) | ||
| for gain_auto in product(*repeat((False, True), 3)): | ||
| source.gain_auto = gain_auto | ||
| assert all(map(is_, source.gain_auto, gain_auto)) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
3121898
5.12%28
-12.5%605
-37.89%