Skip to content

Commit

Permalink
Add missing stubs for AudioFrame
Browse files Browse the repository at this point in the history
  • Loading branch information
WyattBlue committed Mar 25, 2024
1 parent 1dfe776 commit 554f2c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
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

0 comments on commit 554f2c3

Please sign in to comment.