pyquist 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pyquist-0.2.0/pyquist.egg-info → pyquist-0.2.1}/PKG-INFO +1 -1
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/__init__.py +1 -1
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/audio.py +33 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/audio_test.py +60 -2
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/cli.py +4 -0
- {pyquist-0.2.0 → pyquist-0.2.1/pyquist.egg-info}/PKG-INFO +1 -1
- {pyquist-0.2.0 → pyquist-0.2.1}/LICENSE +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/README.md +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyproject.toml +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/device.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/device_test.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/helper.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/helper_test.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/paths.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/plot.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/plot_test.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/py.typed +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/score.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/score_test.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/232009__danmitch3ll__xylophone-sweep.wav +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/434013__mrpearch__drum-patern.mp3 +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/ATTRIBUTION.md +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/ravel_bolero.mid +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/web/__init__.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/web/freesound.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist/web/theorytab.py +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist.egg-info/SOURCES.txt +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist.egg-info/dependency_links.txt +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist.egg-info/entry_points.txt +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist.egg-info/requires.txt +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/pyquist.egg-info/top_level.txt +0 -0
- {pyquist-0.2.0 → pyquist-0.2.1}/setup.cfg +0 -0
|
@@ -386,6 +386,39 @@ class Audio:
|
|
|
386
386
|
f"Cannot convert audio with {self.num_channels} channels to stereo."
|
|
387
387
|
)
|
|
388
388
|
|
|
389
|
+
def pan(self, position: float = 0.0, *, in_place: bool = True) -> "Audio":
|
|
390
|
+
"""Pans stereo audio to ``position`` using an equal-power pan law.
|
|
391
|
+
|
|
392
|
+
Channel gains are ``cos(theta)`` and ``sin(theta)`` for
|
|
393
|
+
``theta = (position + 1) * pi / 4``, so the total power is the same at
|
|
394
|
+
every position. Mono audio must be widened first, e.g.
|
|
395
|
+
``audio.as_stereo().pan(1.0)``.
|
|
396
|
+
|
|
397
|
+
Args:
|
|
398
|
+
position: Stereo position in ``[-1.0, 1.0]``. ``-1.0`` is hard
|
|
399
|
+
left, ``0.0`` (default) is center, ``1.0`` is hard right.
|
|
400
|
+
in_place: If ``True`` (default), modifies and returns ``self``.
|
|
401
|
+
If ``False``, returns a new ``Audio`` and leaves the original
|
|
402
|
+
untouched.
|
|
403
|
+
|
|
404
|
+
Raises:
|
|
405
|
+
ValueError: If ``position`` is outside ``[-1.0, 1.0]``, or if the
|
|
406
|
+
audio is not stereo.
|
|
407
|
+
"""
|
|
408
|
+
position = float(position)
|
|
409
|
+
if not -1.0 <= position <= 1.0:
|
|
410
|
+
raise ValueError("position must be in [-1.0, 1.0].")
|
|
411
|
+
if self.num_channels != 2:
|
|
412
|
+
raise ValueError(
|
|
413
|
+
f"Cannot pan audio with {self.num_channels} channels (stereo only)."
|
|
414
|
+
)
|
|
415
|
+
theta = (position + 1.0) * (np.pi / 4.0)
|
|
416
|
+
gains = np.array([np.cos(theta), np.sin(theta)], dtype=np.float32)
|
|
417
|
+
if in_place:
|
|
418
|
+
self._samples *= gains
|
|
419
|
+
return self
|
|
420
|
+
return Audio(self._samples * gains, sample_rate=self._sample_rate)
|
|
421
|
+
|
|
389
422
|
def resample(self, new_sample_rate: int, **kwargs) -> "Audio":
|
|
390
423
|
"""Returns a new ``Audio`` resampled to ``new_sample_rate``.
|
|
391
424
|
|
|
@@ -101,11 +101,17 @@ class TestAudio(unittest.TestCase):
|
|
|
101
101
|
Audio.concatenate([])
|
|
102
102
|
with self.assertRaises(ValueError):
|
|
103
103
|
Audio.concatenate(
|
|
104
|
-
[
|
|
104
|
+
[
|
|
105
|
+
Audio(np.ones(3), sample_rate=44100),
|
|
106
|
+
Audio(np.ones(3), sample_rate=22050),
|
|
107
|
+
]
|
|
105
108
|
)
|
|
106
109
|
with self.assertRaises(ValueError):
|
|
107
110
|
Audio.concatenate(
|
|
108
|
-
[
|
|
111
|
+
[
|
|
112
|
+
Audio(np.ones((3, 1)), sample_rate=44100),
|
|
113
|
+
Audio(np.ones((3, 2)), sample_rate=44100),
|
|
114
|
+
]
|
|
109
115
|
)
|
|
110
116
|
|
|
111
117
|
def test_from_file_wav(self):
|
|
@@ -242,6 +248,58 @@ class TestAudio(unittest.TestCase):
|
|
|
242
248
|
with self.assertRaises(ValueError):
|
|
243
249
|
multi4.as_stereo()
|
|
244
250
|
|
|
251
|
+
def test_pan(self):
|
|
252
|
+
stereo = Audio(np.ones((10, 2), dtype=np.float32), sample_rate=44100)
|
|
253
|
+
|
|
254
|
+
# Center: equal gain of -3 dB in both channels.
|
|
255
|
+
centered = stereo.pan(in_place=False)
|
|
256
|
+
self.assertEqual(centered.shape, (10, 2))
|
|
257
|
+
self.assertEqual(centered.samples.dtype, np.float32)
|
|
258
|
+
self.assertEqual(centered.sample_rate, 44100)
|
|
259
|
+
self.assertTrue(np.allclose(centered.samples, np.sqrt(0.5), atol=1e-6))
|
|
260
|
+
|
|
261
|
+
# Hard left/right mute the opposite channel and pass the other through.
|
|
262
|
+
left = stereo.pan(-1.0, in_place=False)
|
|
263
|
+
self.assertTrue(np.allclose(left.samples[:, 0], 1.0, atol=1e-6))
|
|
264
|
+
self.assertTrue(np.allclose(left.samples[:, 1], 0.0, atol=1e-6))
|
|
265
|
+
right = stereo.pan(1.0, in_place=False)
|
|
266
|
+
self.assertTrue(np.allclose(right.samples[:, 0], 0.0, atol=1e-6))
|
|
267
|
+
self.assertTrue(np.allclose(right.samples[:, 1], 1.0, atol=1e-6))
|
|
268
|
+
|
|
269
|
+
# Equal power: the summed power is constant across positions.
|
|
270
|
+
for position in [-1.0, -0.5, -0.25, 0.0, 0.25, 0.5, 1.0]:
|
|
271
|
+
panned = stereo.pan(position, in_place=False)
|
|
272
|
+
self.assertAlmostEqual(
|
|
273
|
+
float((panned.samples**2).sum()),
|
|
274
|
+
float((stereo.samples**2).sum()) / 2,
|
|
275
|
+
places=5,
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
# in_place=False above didn't mutate the source; in_place=True does.
|
|
279
|
+
self.assertTrue(np.allclose(stereo.samples, 1.0))
|
|
280
|
+
self.assertIs(stereo.pan(1.0), stereo)
|
|
281
|
+
self.assertTrue(np.allclose(stereo.samples[:, 0], 0.0, atol=1e-6))
|
|
282
|
+
self.assertTrue(np.allclose(stereo.samples[:, 1], 1.0, atol=1e-6))
|
|
283
|
+
|
|
284
|
+
# Mono is widened first: as_stereo().pan() is a full-amplitude hard pan.
|
|
285
|
+
mono = Audio(np.ones((10, 1), dtype=np.float32), sample_rate=44100)
|
|
286
|
+
panned = mono.as_stereo().pan(1.0)
|
|
287
|
+
self.assertTrue(np.allclose(panned.samples[:, 0], 0.0, atol=1e-6))
|
|
288
|
+
self.assertTrue(np.allclose(panned.samples[:, 1], 1.0, atol=1e-6))
|
|
289
|
+
|
|
290
|
+
# Out-of-range positions raise.
|
|
291
|
+
with self.assertRaises(ValueError):
|
|
292
|
+
stereo.pan(-1.5)
|
|
293
|
+
with self.assertRaises(ValueError):
|
|
294
|
+
stereo.pan(1.5)
|
|
295
|
+
|
|
296
|
+
# Non-stereo: raises
|
|
297
|
+
with self.assertRaises(ValueError):
|
|
298
|
+
mono.pan()
|
|
299
|
+
multi = Audio(np.zeros((10, 3), dtype=np.float32), sample_rate=44100)
|
|
300
|
+
with self.assertRaises(ValueError):
|
|
301
|
+
multi.pan()
|
|
302
|
+
|
|
245
303
|
def test_segment(self):
|
|
246
304
|
sr = 1000
|
|
247
305
|
# 1s = 1000 samples; values 0..999 in channel 0
|
|
@@ -7,6 +7,7 @@ and audio loading lives in :mod:`pyquist.audio` / :mod:`pyquist.web`.
|
|
|
7
7
|
|
|
8
8
|
import argparse
|
|
9
9
|
|
|
10
|
+
from . import __version__
|
|
10
11
|
from .audio import Audio
|
|
11
12
|
from .device import (
|
|
12
13
|
play,
|
|
@@ -52,6 +53,9 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
52
53
|
parser = argparse.ArgumentParser(
|
|
53
54
|
prog="pyquist", description="Pyquist command-line interface."
|
|
54
55
|
)
|
|
56
|
+
parser.add_argument(
|
|
57
|
+
"--version", "-v", action="version", version=f"pyquist {__version__}"
|
|
58
|
+
)
|
|
55
59
|
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
56
60
|
|
|
57
61
|
p_devices = subparsers.add_parser(
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyquist-0.2.0 → pyquist-0.2.1}/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|