Skip to content

Commit

Permalink
Added real-time support
Browse files Browse the repository at this point in the history
  • Loading branch information
Quinticx committed Apr 11, 2022
1 parent 82548a0 commit 7c59de1
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 0 deletions.
63 changes: 63 additions & 0 deletions examples/wave_to_sdl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import nimbus
import nimbus.sources
import nimbus.sinks
import nimbus.transformers
import numpy as np

sync_frame = np.array(
[
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
1,
1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
-1,
]
)
wave_source = nimbus.sources.Wave("examples/10080101_16bit.wav", buffer_size=5512)
sdl_sink = nimbus.sinks.SDL(width=2080, height=1200)

pipeline = nimbus.Pipeline(
wave_source,
[
nimbus.transformers.Caster(np.float32),
nimbus.transformers.Hilbert(),
nimbus.transformers.Caster(np.float32),
nimbus.transformers.Tee(nimbus.sinks.Audio()),
nimbus.transformers.Resample(sample_rate=4160),
nimbus.transformers.Apt_Sync(sync_frame),
nimbus.transformers.Caster(np.uint8),
],
sdl_sink,
)
pipeline.run()
1 change: 1 addition & 0 deletions nimbus/sinks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
from .image import *
from .audio import *
from .iq import *
from .sdl import *
32 changes: 32 additions & 0 deletions nimbus/sinks/sdl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import numpy as np
from PIL import Image as pil
from nimbus import Samples
import sdl2.ext
import sdl2.ext.pixelaccess


class SDL:
def __init__(self, width: int, height: int):
sdl2.ext.init()
self.window = sdl2.ext.Window("Real Time Window", size=(width, height))
self.pixels = sdl2.ext.pixelaccess.pixels2d(self.window.get_surface())
self.window.show()
self.row = 0
self.width = width
self.height = height

def execute(self, signal: Samples):
if not signal.data.dtype == np.uint8:
raise ValueError(f"SDL Sink requires np.uint8 signal: {signal.data.dtype}")

for col in range(self.width):
if col >= signal.data.size:
self.pixels[col][self.row] = 0
else:
lum = signal.data[col]
self.pixels[col][self.row] = lum << 16 | lum << 8 | lum

self.row += 1
self.row = self.row % self.height

self.window.refresh()
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ numpy = "^1.22.3"
Pillow = "^9.0.1"
PyAudio = "^0.2.11"
pyrtlsdr = "^0.2.92"
PySDL2 = "^0.9.11"

[tool.poetry.dev-dependencies]
pytest = "^7.0.1"
Expand Down

0 comments on commit 7c59de1

Please sign in to comment.