Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing stubs for AudioFrame #1357

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions av/audio/frame.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import numpy as np

from av.frame import Frame

from .format import AudioFormat
from .layout import AudioLayout
from .plane import AudioPlane

format_dtypes: dict[str, str]
Expand All @@ -20,6 +22,8 @@ class AudioFrame(Frame):
samples: int
sample_rate: int
rate: int
format: AudioFormat
layout: AudioLayout

def __init__(
self,
Expand Down
18 changes: 9 additions & 9 deletions tests/test_audioframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,30 @@


class TestAudioFrameConstructors(TestCase):
def test_null_constructor(self):
def test_null_constructor(self) -> None:
frame = AudioFrame()
self.assertEqual(frame.format.name, "s16")
self.assertEqual(frame.layout.name, "stereo")
self.assertEqual(len(frame.planes), 0)
self.assertEqual(frame.samples, 0)

def test_manual_flt_mono_constructor(self):
def test_manual_flt_mono_constructor(self) -> None:
frame = AudioFrame(format="flt", layout="mono", samples=160)
self.assertEqual(frame.format.name, "flt")
self.assertEqual(frame.layout.name, "mono")
self.assertEqual(len(frame.planes), 1)
self.assertEqual(frame.planes[0].buffer_size, 640)
self.assertEqual(frame.samples, 160)

def test_manual_flt_stereo_constructor(self):
def test_manual_flt_stereo_constructor(self) -> None:
frame = AudioFrame(format="flt", layout="stereo", samples=160)
self.assertEqual(frame.format.name, "flt")
self.assertEqual(frame.layout.name, "stereo")
self.assertEqual(len(frame.planes), 1)
self.assertEqual(frame.planes[0].buffer_size, 1280)
self.assertEqual(frame.samples, 160)

def test_manual_fltp_stereo_constructor(self):
def test_manual_fltp_stereo_constructor(self) -> None:
frame = AudioFrame(format="fltp", layout="stereo", samples=160)
self.assertEqual(frame.format.name, "fltp")
self.assertEqual(frame.layout.name, "stereo")
Expand All @@ -38,31 +38,31 @@ def test_manual_fltp_stereo_constructor(self):
self.assertEqual(frame.planes[1].buffer_size, 640)
self.assertEqual(frame.samples, 160)

def test_manual_s16_mono_constructor(self):
def test_manual_s16_mono_constructor(self) -> None:
frame = AudioFrame(format="s16", layout="mono", samples=160)
self.assertEqual(frame.format.name, "s16")
self.assertEqual(frame.layout.name, "mono")
self.assertEqual(len(frame.planes), 1)
self.assertEqual(frame.planes[0].buffer_size, 320)
self.assertEqual(frame.samples, 160)

def test_manual_s16_mono_constructor_align_8(self):
def test_manual_s16_mono_constructor_align_8(self) -> None:
frame = AudioFrame(format="s16", layout="mono", samples=159, align=8)
self.assertEqual(frame.format.name, "s16")
self.assertEqual(frame.layout.name, "mono")
self.assertEqual(len(frame.planes), 1)
self.assertEqual(frame.planes[0].buffer_size, 320)
self.assertEqual(frame.samples, 159)

def test_manual_s16_stereo_constructor(self):
def test_manual_s16_stereo_constructor(self) -> None:
frame = AudioFrame(format="s16", layout="stereo", samples=160)
self.assertEqual(frame.format.name, "s16")
self.assertEqual(frame.layout.name, "stereo")
self.assertEqual(len(frame.planes), 1)
self.assertEqual(frame.planes[0].buffer_size, 640)
self.assertEqual(frame.samples, 160)

def test_manual_s16p_stereo_constructor(self):
def test_manual_s16p_stereo_constructor(self) -> None:
frame = AudioFrame(format="s16p", layout="stereo", samples=160)
self.assertEqual(frame.format.name, "s16p")
self.assertEqual(frame.layout.name, "stereo")
Expand All @@ -73,7 +73,7 @@ def test_manual_s16p_stereo_constructor(self):


class TestAudioFrameConveniences(TestCase):
def test_basic_to_ndarray(self):
def test_basic_to_ndarray(self) -> None:
frame = AudioFrame(format="s16p", layout="stereo", samples=160)
array = frame.to_ndarray()
self.assertEqual(array.dtype, "i2")
Expand Down
Loading