mirror of
https://github.com/markqvist/LXST
synced 2026-11-22 23:10:31 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d7412401e1 |
No files matched your search
@@ -0,0 +1,55 @@
|
||||
import RNS
|
||||
from .Pipeline import Pipeline
|
||||
from .Codecs import *
|
||||
from .Sources import *
|
||||
from .Sinks import *
|
||||
from . import APP_NAME
|
||||
|
||||
class CallEndpoint():
|
||||
def __init__(self, identity):
|
||||
self.identity = identity
|
||||
self.destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, "call", "endpoint")
|
||||
self.destination.set_link_established_callback(self._incoming_call)
|
||||
self.active_call = None
|
||||
self.auto_answer = True
|
||||
self.receive_pipeline = None
|
||||
self.transmit_pipeline = None
|
||||
self._incoming_call_callback = None
|
||||
|
||||
def announce(self):
|
||||
if self.destination:
|
||||
self.destination.announce()
|
||||
|
||||
@property
|
||||
def incoming_call_callback(self):
|
||||
return self._incoming_call_callback
|
||||
|
||||
@incoming_call_callback.setter
|
||||
def incoming_call_callback(self, callback):
|
||||
if callable(callback):
|
||||
self._incoming_call_callback = callback
|
||||
else:
|
||||
raise TypeError(f"Invalid callback for {self}: Not callable")
|
||||
|
||||
def _incoming_call(self, link):
|
||||
RNS.log(f"Incoming call on {self}", RNS.LOG_DEBUG)
|
||||
if callable(self._incoming_call_callback):
|
||||
self._incoming_call_callback(link)
|
||||
|
||||
def answer(self, call_link):
|
||||
RNS.log(f"Answering call on {call_link}", RNS.LOG_DEBUG)
|
||||
self.active_call = call_link
|
||||
|
||||
self.receive_pipeline = Pipeline(source=PacketSource(self),
|
||||
codec=Opus(),
|
||||
sink=LineSink())
|
||||
|
||||
self.transmit_pipeline = Pipeline(source=LineSource(target_frame_ms=target_frame_ms),
|
||||
codec=Opus(),
|
||||
sink=PacketSink(self))
|
||||
|
||||
def terminate(self):
|
||||
self.receive_pipeline.stop()
|
||||
self.transmit_pipeline.stop()
|
||||
if self.active_call:
|
||||
self.active_call.teardown()
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import numpy as np
|
||||
from .libs.pydub import AudioSegment
|
||||
|
||||
@@ -13,8 +11,6 @@ class Codec():
|
||||
source = None
|
||||
sink = None
|
||||
|
||||
def __str__(self): return f"<LXST/Codec>"
|
||||
|
||||
class CodecError(Exception):
|
||||
pass
|
||||
|
||||
@@ -28,8 +24,6 @@ class Null(Codec):
|
||||
def decode(self, frame):
|
||||
return frame
|
||||
|
||||
def __str__(self): return f"<LXST/NullCodec>"
|
||||
|
||||
def resample_bytes(sample_bytes, bitdepth, channels, input_rate, output_rate, normalize=False):
|
||||
sample_width = bitdepth//8
|
||||
audio = AudioSegment(
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import time
|
||||
import math
|
||||
import struct
|
||||
@@ -120,6 +118,4 @@ class Codec2(Codec):
|
||||
frame_samples = np.zeros((len(decoded_samples), 1), dtype="float32")
|
||||
frame_samples[:, 0] = decoded_samples
|
||||
|
||||
return frame_samples
|
||||
|
||||
def __str__(self): return f"<LXST/Codec2 @ {RNS.prettyspeed(self.mode)}>"
|
||||
return frame_samples
|
||||
+1
-18
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import io
|
||||
import RNS
|
||||
import time
|
||||
@@ -24,19 +22,6 @@ class Opus(Codec):
|
||||
PROFILE_AUDIO_HIGH = 0x07
|
||||
PROFILE_AUDIO_MAX = 0x08
|
||||
|
||||
@staticmethod
|
||||
def profile_name(profile):
|
||||
if profile == Opus.PROFILE_VOICE_LOW: return "Voice, Low"
|
||||
elif profile == Opus.PROFILE_VOICE_MEDIUM: return "Voice, Medium"
|
||||
elif profile == Opus.PROFILE_VOICE_HIGH: return "Voice, High"
|
||||
elif profile == Opus.PROFILE_VOICE_MAX: return "Voice, Max"
|
||||
elif profile == Opus.PROFILE_AUDIO_MIN: return "Audio, Min"
|
||||
elif profile == Opus.PROFILE_AUDIO_LOW: return "Audio, Low"
|
||||
elif profile == Opus.PROFILE_AUDIO_MEDIUM: return "Audio, Medium"
|
||||
elif profile == Opus.PROFILE_AUDIO_HIGH: return "Audio, High"
|
||||
elif profile == Opus.PROFILE_AUDIO_MAX: return "Audio, Max"
|
||||
else: return "Default"
|
||||
|
||||
def __init__(self, profile=PROFILE_VOICE_LOW):
|
||||
self.frame_quanta_ms = self.FRAME_QUANTA_MS
|
||||
self.frame_max_ms = self.FRAME_MAX_MS
|
||||
@@ -179,6 +164,4 @@ class Opus(Codec):
|
||||
decoded_samples = np.frombuffer(decoded_frame_bytes, dtype="int16")/self.TYPE_MAP_FACTOR
|
||||
frame_samples = decoded_samples.reshape(len(decoded_samples)//self.channels, self.channels)
|
||||
|
||||
return frame_samples
|
||||
|
||||
def __str__(self): return f"<LXST/Opus @ {self.profile_name(self.profile)}>"
|
||||
return frame_samples
|
||||
+1
-5
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import numpy as np
|
||||
from .Codec import Codec
|
||||
@@ -57,6 +55,4 @@ class Raw(Codec):
|
||||
frame_samples = frame_samples.reshape(len(frame_samples)//frame_channels, frame_channels)
|
||||
if not self.channels: self.channels = frame_channels
|
||||
|
||||
return frame_samples
|
||||
|
||||
def __str__(self): return f"<LXST/Raw @ {RNS.prettyspeed(self.channels*self.bitdepth*48000)}>"
|
||||
return frame_samples
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
from .Codec import CodecError as CodecError
|
||||
from .Codec import Codec as Codec
|
||||
from .Codec import Null as Null
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
@@ -1,22 +1 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from .audio_segment import AudioSegment
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import division
|
||||
|
||||
import array
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import sys
|
||||
import math
|
||||
import array
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
class PydubException(Exception):
|
||||
"""
|
||||
Base class for any Pydub exception
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
Each generator will return float samples from -1.0 to 1.0, which can be
|
||||
converted to actual audio with 8, 16, 24, or 32 bit depth using the
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
|
||||
"""
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
Support for playing AudioSegments. Pyaudio will be used if it's installed,
|
||||
otherwise will fallback to ffplay. Pyaudio is a *much* nicer solution, but
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
try:
|
||||
from __builtin__ import max as builtin_max
|
||||
from __builtin__ import min as builtin_min
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
This module provides scipy versions of high_pass_filter, and low_pass_filter
|
||||
as well as an additional band_pass_filter.
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
"""
|
||||
Various functions for finding/manipulating silence in AudioSegments
|
||||
"""
|
||||
|
||||
@@ -1,24 +1,3 @@
|
||||
# Copyright (c) 2011 James Robert, http://jiaaro.com
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
from __future__ import division
|
||||
|
||||
import json
|
||||
|
||||
@@ -1,213 +0,0 @@
|
||||
The following License terms are included in the scripts of the
|
||||
respective packages, so you will have to include them manually
|
||||
if you're distributing compiled sources:
|
||||
|
||||
==================================================
|
||||
Ogg License
|
||||
==================================================
|
||||
Copyright (c) 2002, Xiph.org Foundation
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
==================================================
|
||||
Opus License
|
||||
==================================================
|
||||
Copyright 2001-2011 Xiph.Org, Skype Limited, Octasic,
|
||||
Jean-Marc Valin, Timothy B. Terriberry,
|
||||
CSIRO, Gregory Maxwell, Mark Borgerding,
|
||||
Erik de Castro Lopo
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of Internet Society, IETF or IETF Trust, nor the
|
||||
names of specific contributors, may be used to endorse or promote
|
||||
products derived from this software without specific prior written
|
||||
permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
Opus is subject to the royalty-free patent licenses which are
|
||||
specified at:
|
||||
|
||||
Xiph.Org Foundation:
|
||||
https://datatracker.ietf.org/ipr/1524/
|
||||
|
||||
Microsoft Corporation:
|
||||
https://datatracker.ietf.org/ipr/1914/
|
||||
|
||||
Broadcom Corporation:
|
||||
https://datatracker.ietf.org/ipr/1526/
|
||||
|
||||
==================================================
|
||||
Opusfile License
|
||||
==================================================
|
||||
Copyright (c) 1994-2013 Xiph.Org Foundation and contributors
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.Org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
==================================================
|
||||
Opusenc License
|
||||
==================================================
|
||||
Copyright (c) 1994-2013 Xiph.Org Foundation and contributors
|
||||
Copyright (c) 2017 Jean-Marc Valin
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.Org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
==================================================
|
||||
Vorbis License
|
||||
==================================================
|
||||
Copyright (c) 2002-2015 Xiph.org Foundation
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION
|
||||
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
==================================================
|
||||
Flac License
|
||||
==================================================
|
||||
Copyright (C) 2000-2009 Josh Coalson
|
||||
Copyright (C) 2011-2016 Xiph.Org Foundation
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions
|
||||
are met:
|
||||
|
||||
- Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
|
||||
- Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
|
||||
- Neither the name of the Xiph.org Foundation nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR
|
||||
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
@@ -1,4 +1,2 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
def nop():
|
||||
pass
|
||||
+2
-4
@@ -1,5 +1,3 @@
|
||||
// Copyright 2024-2026, Mark Qvist
|
||||
|
||||
#include <math.h>
|
||||
|
||||
void highpass_filter(float* input, float* output, int samples, int channels, float alpha, float* filter_states, float* last_inputs) {
|
||||
@@ -64,8 +62,8 @@ void agc_process(float* input, float* output, int samples, int channels, float t
|
||||
float peak = 0.0f;
|
||||
for (int i = 0; i < samples; i++) { int idx = i * channels + ch; float abs_val = fabsf(output[idx]);
|
||||
if (abs_val > peak) { peak = abs_val; } }
|
||||
|
||||
|
||||
if (peak > peak_limit) { float scale = peak_limit / peak;
|
||||
for (int i = 0; i < samples; i++) { int idx = i * channels + ch; output[idx] *= scale; } }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// Copyright 2024-2026, Mark Qvist
|
||||
|
||||
void highpass_filter(float* input, float* output, int samples, int channels, float alpha, float* filter_states, float* last_inputs);
|
||||
void lowpass_filter(float* input, float* output, int samples, int channels, float alpha, float* filter_states);
|
||||
void agc_process(float* input, float* output, int samples, int channels, float target_linear, float max_gain_linear, float trigger_level, float attack_coeff, float release_coeff, float hold_samples, float* current_gain_lin, int* hold_counter, int block_target);
|
||||
+3
-1289
File diff suppressed because it is too large.
Load diff
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import os
|
||||
import RNS
|
||||
import math
|
||||
|
||||
+6
-19
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import LXST
|
||||
import time
|
||||
@@ -19,7 +17,6 @@ class Mixer(LocalSource, LocalSink):
|
||||
|
||||
def __init__(self, target_frame_ms=40, samplerate=None, codec=None, sink=None, gain=0.0):
|
||||
self.incoming_frames = {}
|
||||
self.reference_outs = []
|
||||
self.target_frame_ms = target_frame_ms
|
||||
self.frame_time = self.target_frame_ms/1000
|
||||
self.should_run = False
|
||||
@@ -102,7 +99,6 @@ class Mixer(LocalSource, LocalSink):
|
||||
else: return 10**(self.gain/10)
|
||||
|
||||
def _mixer_job(self):
|
||||
if self.mixer_lock.locked(): return
|
||||
with self.mixer_lock:
|
||||
while self.should_run:
|
||||
if self.sink and self.sink.can_receive():
|
||||
@@ -121,22 +117,13 @@ class Mixer(LocalSource, LocalSink):
|
||||
if mixed_frame.max() >= 1.0 or mixed_frame.min() <= -1.0:
|
||||
RNS.log(f"Signal clipped on {self}", RNS.LOG_WARNING)
|
||||
|
||||
try:
|
||||
if self.codec: self.sink.handle_frame(self.codec.encode(mixed_frame), self)
|
||||
else: self.sink.handle_frame(mixed_frame, self)
|
||||
|
||||
except Exception as e: RNS.log(f"Error while mixing frame on {self}: {e}", RNS.LOG_ERROR)
|
||||
if self.codec: self.sink.handle_frame(self.codec.encode(mixed_frame), self)
|
||||
else: self.sink.handle_frame(mixed_frame, self)
|
||||
else:
|
||||
time.sleep(self.frame_time*0.1)
|
||||
|
||||
try:
|
||||
for ref in self.reference_outs: ref.handle_reference(mixed_frame, self.samplerate)
|
||||
|
||||
except Exception as e: RNS.log(f"Error while handling reference output on {self}: {e}", RNS.LOG_ERROR)
|
||||
|
||||
else: time.sleep(self.frame_time*0.1)
|
||||
|
||||
else: time.sleep(self.frame_time*0.1)
|
||||
|
||||
RNS.log(f"{self} stopped", RNS.LOG_DEBUG)
|
||||
else:
|
||||
time.sleep(self.frame_time*0.1)
|
||||
|
||||
@property
|
||||
def codec(self):
|
||||
|
||||
+5
-10
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import time
|
||||
import threading
|
||||
@@ -25,8 +23,7 @@ class SignallingReceiver():
|
||||
if self.proxy: self.proxy.signalling_received(signals, source)
|
||||
|
||||
def signal(self, signal, destination, immediate=True):
|
||||
if type(signal) != list: signalling_data = {FIELD_SIGNALLING: [signal]}
|
||||
else: signalling_data = {FIELD_SIGNALLING: signal}
|
||||
signalling_data = {FIELD_SIGNALLING:[signal]}
|
||||
|
||||
if immediate:
|
||||
signalling_packet = RNS.Packet(destination, mp.packb(signalling_data), create_receipt=False)
|
||||
@@ -55,12 +52,11 @@ class Packetizer(RemoteSink):
|
||||
self.should_run = False
|
||||
self.source = None
|
||||
self.transmit_failure = False
|
||||
self.squelched = False
|
||||
self.__failure_calback = failure_callback
|
||||
|
||||
def handle_frame(self, frame, source=None):
|
||||
if type(self.destination) == RNS.Link and not self.destination.status == RNS.Link.ACTIVE: return
|
||||
if self.squelched: return
|
||||
if type(self.destination) == RNS.Link and not self.destination.status == RNS.Link.ACTIVE:
|
||||
return
|
||||
|
||||
# TODO: Add inband signalling scheduler
|
||||
frame = codec_header_byte(type(self.source.codec))+frame
|
||||
@@ -96,9 +92,8 @@ class Packetizer(RemoteSink):
|
||||
RNS.log(f"{self} starting", RNS.LOG_DEBUG)
|
||||
self.should_run = True
|
||||
|
||||
def stop(self): self.should_run = False
|
||||
def squelch(self): self.squelched = True
|
||||
def unsquelch(self): self.squelched = False
|
||||
def stop(self):
|
||||
self.should_run = False
|
||||
|
||||
class LinkSource(RemoteSource, SignallingReceiver):
|
||||
def __init__(self, link, signalling_receiver, sink=None):
|
||||
|
||||
+12
-21
@@ -1,7 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import threading
|
||||
|
||||
from .Sources import *
|
||||
from .Sinks import *
|
||||
from .Codecs import *
|
||||
@@ -12,8 +8,6 @@ class PipelineError(Exception):
|
||||
pass
|
||||
|
||||
class Pipeline():
|
||||
release_lock = threading.Lock()
|
||||
|
||||
def __init__(self, source, codec, sink, processor = None):
|
||||
if not issubclass(type(source), Source): raise PipelineError("Audio pipeline initialised with invalid source")
|
||||
if not issubclass(type(sink), Sink) : raise PipelineError("Audio pipeline initialised with invalid sink")
|
||||
@@ -26,22 +20,15 @@ class Pipeline():
|
||||
|
||||
if isinstance(sink, Loopback): sink.samplerate = source.samplerate
|
||||
if isinstance(source, Loopback): source._sink = sink
|
||||
if isinstance(source, Mixer): source._sink = sink
|
||||
if isinstance(sink, Packetizer): sink.source = source
|
||||
if isinstance(sink, OpusFileSink): sink.source = source
|
||||
|
||||
def release(self):
|
||||
if self.release_lock.locked(): return
|
||||
with self.release_lock:
|
||||
if not hasattr(self, "released") or not self.released:
|
||||
self.released = True
|
||||
self.source = None
|
||||
self._codec = None
|
||||
|
||||
@property
|
||||
def codec(self):
|
||||
if self.source: return self.source.codec
|
||||
else: return None
|
||||
if self.source:
|
||||
return self.source.codec
|
||||
else:
|
||||
return None
|
||||
|
||||
@codec.setter
|
||||
def codec(self, codec):
|
||||
@@ -53,15 +40,19 @@ class Pipeline():
|
||||
|
||||
@property
|
||||
def sink(self):
|
||||
if self.source: return self.source.sink
|
||||
else: return None
|
||||
if self.source:
|
||||
return self.source.sink
|
||||
else:
|
||||
return None
|
||||
|
||||
@property
|
||||
def running(self):
|
||||
return self.source.should_run
|
||||
|
||||
def start(self):
|
||||
if not self.running: self.source.start()
|
||||
if not self.running:
|
||||
self.source.start()
|
||||
|
||||
def stop(self):
|
||||
if self.running: self.source.stop()
|
||||
if self.running:
|
||||
self.source.stop()
|
||||
@@ -1,4 +1,32 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
# Reticulum License
|
||||
#
|
||||
# Copyright (c) 2025 Mark Qvist
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# - The Software shall not be used in any kind of system which includes amongst
|
||||
# its functions the ability to purposefully do harm to human beings.
|
||||
#
|
||||
# - The Software shall not be used, directly or indirectly, in the creation of
|
||||
# an artificial intelligence, machine learning or language model training
|
||||
# dataset, including but not limited to any use that contributes to the
|
||||
# training or development of such a model or algorithm.
|
||||
#
|
||||
# - The above copyright notice and this permission notice shall be included in
|
||||
# all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
import atexit
|
||||
import collections.abc
|
||||
@@ -420,7 +448,6 @@ class _Stream:
|
||||
|
||||
self.AudioManager = activity.getSystemService(autoclass("android.media.AudioManager"))
|
||||
self.AudioTrack = autoclass("android.media.AudioTrack")
|
||||
self.AudioRecord = autoclass("android.media.AudioRecord")
|
||||
self.AudioFormat = autoclass("android.media.AudioFormat")
|
||||
self.AudioDeviceInfo = autoclass("android.media.AudioDeviceInfo")
|
||||
|
||||
@@ -559,8 +586,8 @@ class _Stream:
|
||||
|
||||
else: raise ValueError(f"Unsupported channel count {channels} on Android audio backend")
|
||||
|
||||
self.min_buffer_playback = self.AudioTrack.getMinBufferSize(self._samplerate, self.audio_format_out, self.audio_encoding)
|
||||
self.min_buffer_recording = self.AudioRecord.getMinBufferSize(self._samplerate, self.audio_format_in, self.audio_encoding)
|
||||
self.min_buffer_playback = self.AudioTrack.getMinBufferSize(self._samplerate, self.audio_format_out, self.audio_encoding);
|
||||
self.min_buffer_recording = self.AudioTrack.getMinBufferSize(self._samplerate, self.audio_format_in, self.audio_encoding);
|
||||
self.bytes_per_sample = (self.bit_depth//8)*self.channels
|
||||
|
||||
self._samplerate = int(self.AudioManager.getProperty(self.AudioManager.PROPERTY_OUTPUT_SAMPLE_RATE))
|
||||
@@ -651,9 +678,7 @@ class _Player(_Stream):
|
||||
aa_builder.setContentType(AudioAttributes.CONTENT_TYPE_UNKNOWN)
|
||||
self.performance_mode = AudioTrack.PERFORMANCE_MODE_NONE
|
||||
|
||||
if _audio.android_api_version >= 29:
|
||||
aa_builder.setAllowedCapturePolicy(AudioAttributes.ALLOW_CAPTURE_BY_NONE)
|
||||
|
||||
aa_builder.setAllowedCapturePolicy(AudioAttributes.ALLOW_CAPTURE_BY_NONE)
|
||||
self.audio_attributes = aa_builder.build()
|
||||
|
||||
af_builder = AudioFormatBuilder()
|
||||
@@ -703,11 +728,6 @@ class _Player(_Stream):
|
||||
while data.nbytes > 0:
|
||||
samples_bytes = data.ravel().tobytes()
|
||||
written_bytes = self.audio_track.write(samples_bytes, 0, len(samples_bytes), self._write_mode)
|
||||
|
||||
if written_bytes < 0:
|
||||
RNS.log(f"{self} frame write error: {written_bytes}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
return
|
||||
|
||||
written_samples = written_bytes//self.bytes_per_sample
|
||||
|
||||
if self._low_latency_activated:
|
||||
@@ -723,9 +743,6 @@ class _Player(_Stream):
|
||||
written_samples = remaining_frame_samples
|
||||
# TODO: Remove debug
|
||||
# RNS.log(f"Buffer overrun. Target buffer samples {self._target_buffer_samples}. Needed to write {remaining_frame_samples} samples / {len(samples_bytes)} bytes. Discarding {written_samples} input samples.")
|
||||
else: time.sleep(0.001) # Yield thread, buffer full inside overrun lock window
|
||||
|
||||
if written_bytes == 0 and not self._low_latency_activated: time.sleep(0.001) # Yield thread, buffer full
|
||||
|
||||
data = data[written_samples:]
|
||||
|
||||
@@ -742,108 +759,40 @@ class _Player(_Stream):
|
||||
# RNS.log(f"{delta} underruns on {self}")
|
||||
|
||||
class _Recorder(_Stream):
|
||||
READ_MODE_FAST = "fast"
|
||||
READ_MODE_LEGACY = "legacy"
|
||||
READ_MODE_FAUX = "faux"
|
||||
READ_MODE = READ_MODE_FAST
|
||||
DBG_READ_PACING = 0.0
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(_Recorder, self).__init__(*args, **kwargs)
|
||||
self._pending_chunk = numpy.zeros((0, ), dtype='float32')
|
||||
self._helper_service = None
|
||||
self._helper_ok = False
|
||||
self.AudioRecord = autoclass("android.media.AudioRecord")
|
||||
self._pending_chunk = numpy.zeros((0, ), dtype='float32')
|
||||
|
||||
def _connect_stream(self):
|
||||
try:
|
||||
AudioSource = autoclass("android.media.MediaRecorder$AudioSource")
|
||||
self.min_buffer_recording = self.AudioRecord.getMinBufferSize(self._samplerate, self.audio_format_in, self.audio_encoding)
|
||||
|
||||
buffer_target_ms = 200
|
||||
buffer_target_samples = int((self._samplerate/1000)*buffer_target_ms)
|
||||
buffer_target_bytes = buffer_target_samples*self.bytes_per_sample
|
||||
# RNS.log(f"hz={self._samplerate}, Bps={self.bytes_per_sample}, bd={self.bit_depth}, ch={self.channels}, mbr={self.min_buffer_recording}")
|
||||
# RNS.log(f"ms={buffer_target_ms}, smpls={buffer_target_samples}, bytes={buffer_target_bytes}")
|
||||
if buffer_target_bytes < self.min_buffer_recording: buffer_target_bytes = self.min_buffer_recording
|
||||
self.audio_record = self.AudioRecord(AudioSource.VOICE_COMMUNICATION, self._samplerate, self.audio_format_in, self.audio_encoding, buffer_target_bytes)
|
||||
self.audio_record = self.AudioRecord(AudioSource.VOICE_COMMUNICATION, self._samplerate, self.audio_format_in, self.audio_encoding, self.min_buffer_recording)
|
||||
self.audio_record.startRecording()
|
||||
if _Recorder.READ_MODE == _Recorder.READ_MODE_FAST: self.__check_read_helper()
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"Error while connecting input audio stream via JNI: {e}", RNS.LOG_ERROR)
|
||||
RNS.trace_exception(e)
|
||||
|
||||
def __check_read_helper(self):
|
||||
def _record_chunk(self):
|
||||
try:
|
||||
service = autoclass("org.kivy.android.PythonService").mService
|
||||
if service == None: raise AttributeError("No PythonService instance available")
|
||||
probe = service.audioRecordRead(self.audio_record, 0, self.audio_record.READ_NON_BLOCKING)
|
||||
if probe == None: raise AttributeError("audioRecordRead returned None for probe")
|
||||
if len(probe) != 0: raise ValueError("audioRecordRead probe returned unexpected data")
|
||||
self._helper_service = service
|
||||
self._helper_ok = True
|
||||
RNS.log(f"{self} using audio read helper", RNS.LOG_DEBUG)
|
||||
return
|
||||
audio_data = bytearray(self.min_buffer_recording)
|
||||
bytes_read = self.audio_record.read(audio_data, 0, self.min_buffer_recording, self.audio_record.READ_NON_BLOCKING)
|
||||
if bytes_read == 0: time.sleep(0.005)
|
||||
|
||||
except Exception as e: RNS.log(f"{self} audio read helper not available, using legacy read path: {e}", RNS.LOG_DEBUG)
|
||||
|
||||
self._helper_service = None
|
||||
self._helper_ok = False
|
||||
|
||||
def _read_fast(self, read_bytes, read_mode):
|
||||
result = self._helper_service.audioRecordRead(self.audio_record, int(read_bytes), int(read_mode))
|
||||
|
||||
if result == None:
|
||||
bytes_read = -1
|
||||
RNS.log(f"{self} audio read error in helper", RNS.LOG_ERROR)
|
||||
return None
|
||||
|
||||
bytes_read = len(result)
|
||||
|
||||
if bytes_read == 0: return numpy.zeros((0, ), dtype="float32")
|
||||
else:
|
||||
recorded_samples = numpy.frombuffer(result.tostring(), dtype="int16")/self.TYPE_MAP_FACTOR
|
||||
return recorded_samples.astype("float32")
|
||||
|
||||
def _read_legacy(self, read_bytes, read_mode):
|
||||
audio_data = bytearray(int(read_bytes))
|
||||
bytes_read = self.audio_record.read(audio_data, 0, read_bytes, read_mode)
|
||||
|
||||
if bytes_read == self.audio_record.ERROR_INVALID_OPERATION: RNS.log(f"Invalid operation error from JNI on {self}", RNS.LOG_ERROR)
|
||||
elif bytes_read == self.audio_record.ERROR_BAD_VALUE: RNS.log(f"Bad value error from JNI on {self}", RNS.LOG_ERROR)
|
||||
elif bytes_read < 0: RNS.log(f"Audio read error ({bytes_read}) on {self}", RNS.LOG_ERROR)
|
||||
elif bytes_read == 0: return numpy.zeros((0, ), dtype="float32")
|
||||
else:
|
||||
recorded_samples = numpy.frombuffer(audio_data[:bytes_read], dtype="int16")/self.TYPE_MAP_FACTOR
|
||||
return recorded_samples.astype("float32")
|
||||
|
||||
# Debug-only faux-read shim
|
||||
def _read_faux(self, read_bytes, read_mode):
|
||||
bytes_read = int(read_bytes)
|
||||
audio_data = bytes(bytes_read)
|
||||
time.sleep(bytes_read/self.bytes_per_sample/self._samplerate)
|
||||
return numpy.zeros((bytes_read//2, ), dtype="float32")
|
||||
|
||||
def _record_chunk(self, read_bytes=None):
|
||||
try:
|
||||
if read_bytes:
|
||||
read_mode = self.audio_record.READ_BLOCKING
|
||||
if bytes_read == self.audio_record.ERROR_INVALID_OPERATION: RNS.log(f"Invalid operation error from JNI on {self}", RNS.LOG_ERROR)
|
||||
elif bytes_read == self.audio_record.ERROR_BAD_VALUE: RNS.log(f"Bad value error from JNI on {self}", RNS.LOG_ERROR)
|
||||
else:
|
||||
read_bytes = self.min_buffer_recording
|
||||
read_mode = self.audio_record.READ_NON_BLOCKING
|
||||
|
||||
if _Recorder.READ_MODE == _Recorder.READ_MODE_FAUX: chunk = self._read_faux(read_bytes, read_mode)
|
||||
elif _Recorder.READ_MODE == _Recorder.READ_MODE_FAST and self._helper_ok: chunk = self._read_fast(read_bytes, read_mode)
|
||||
else: chunk = self._read_legacy(read_bytes, read_mode)
|
||||
|
||||
if _Recorder.DBG_READ_PACING > 0 and _Recorder.READ_MODE != _Recorder.READ_MODE_FAUX: time.sleep(_Recorder.DBG_READ_PACING)
|
||||
|
||||
return chunk
|
||||
recorded_samples = numpy.frombuffer(audio_data[:bytes_read], dtype="int16")/self.TYPE_MAP_FACTOR
|
||||
return recorded_samples.astype("float32")
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"Error while reading audio chunk: {e}", RNS.LOG_ERROR)
|
||||
RNS.trace_exception(e)
|
||||
return None
|
||||
|
||||
|
||||
def record(self, numframes=None):
|
||||
if numframes is None: return numpy.reshape(numpy.concatenate([self.flush().ravel(), self._record_chunk()]), [-1, self.channels])
|
||||
else:
|
||||
@@ -854,30 +803,10 @@ class _Recorder(_Stream):
|
||||
return numpy.reshape(keep, [-1, self.channels])
|
||||
|
||||
else:
|
||||
timeout = time.time()+(numframes/self._samplerate)*8
|
||||
while captured_frames < numframes:
|
||||
if time.time() > timeout:
|
||||
RNS.log(f"{self} capture timed out at {captured_frames} out of {numframes} frames, emitting silence", RNS.LOG_WARNING)
|
||||
self._pending_chunk = numpy.zeros((0, ), dtype="float32")
|
||||
return numpy.zeros((int(numframes), self.channels), dtype="float32")
|
||||
|
||||
try:
|
||||
m_frames = numframes - captured_frames
|
||||
m_bytes = m_frames * self.bytes_per_sample
|
||||
# RNS.log(f"RECORD {m_bytes} bytes ({m_frames} samples) (min {self.min_buffer_recording})") # TODO: Remove
|
||||
chunk = self._record_chunk(read_bytes=m_bytes)
|
||||
captured_data.append(chunk)
|
||||
captured_frames += len(chunk)/self.channels
|
||||
if captured_frames < numframes:
|
||||
wait_factor=0.65
|
||||
m_frames = numframes - captured_frames
|
||||
st = (m_frames / self._samplerate) * wait_factor
|
||||
# RNS.log(f"Missing {m_frames}/{numframes} samples, sleeping for {RNS.prettyshorttime(st)}") # TODO: Remove
|
||||
time.sleep(st)
|
||||
|
||||
except Exception as e:
|
||||
RNS.log(f"Could not acquire audio frame: {e}", RNS.LOG_WARNING)
|
||||
return None
|
||||
chunk = self._record_chunk()
|
||||
captured_data.append(chunk)
|
||||
captured_frames += len(chunk)/self.channels
|
||||
|
||||
to_split = int(len(chunk) - (captured_frames - numframes) * self.channels)
|
||||
captured_data[-1], self._pending_chunk = numpy.split(captured_data[-1], [to_split])
|
||||
|
||||
@@ -147,8 +147,7 @@ class _PulseAudio:
|
||||
import sys
|
||||
prog_name = sys.argv[0]
|
||||
if prog_name == "-c":
|
||||
if len(sys.argv) > 1: return sys.argv[1][:30] + "..."
|
||||
else: return f"lxst_application_{os.getpid()}"
|
||||
return sys.argv[1][:30] + "..."
|
||||
if prog_name == "-m":
|
||||
prog_name = sys.argv[1]
|
||||
# Usually even with -m, sys.argv[0] will already be a path,
|
||||
@@ -231,7 +230,7 @@ class _PulseAudio:
|
||||
info.append(info_dict)
|
||||
|
||||
self._pa_context_get_source_info_by_name(self.context, id.encode(), callback, _ffi.NULL)
|
||||
return info[0] if len(info) else None
|
||||
return info[0]
|
||||
|
||||
@property
|
||||
def sink_list(self):
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
void PyInit_filterlib(void) { }
|
||||
@@ -1,23 +1,18 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import LXST
|
||||
import time
|
||||
import threading
|
||||
import os
|
||||
import gc
|
||||
|
||||
from LXST.Sinks import LineSink
|
||||
from LXST.Sources import OpusFileSource
|
||||
|
||||
class FilePlayer():
|
||||
def __init__(self, path=None, device=None, loop=False, gain=0.0, release_on_finish=False):
|
||||
def __init__(self, path=None, device=None, loop=False):
|
||||
self._file_path = path
|
||||
self._playback_device = None
|
||||
self.__finished_callback = None
|
||||
self.__release_on_finish = release_on_finish
|
||||
self.__loop = loop
|
||||
self.__source = None
|
||||
self.__gain = gain
|
||||
self.__sink = LineSink(self._playback_device)
|
||||
self.__raw = LXST.Codecs.Raw()
|
||||
self.__loopback = LXST.Sources.Loopback()
|
||||
@@ -25,32 +20,14 @@ class FilePlayer():
|
||||
self.__input_pipeline = None
|
||||
if path: self.set_source(self._file_path)
|
||||
|
||||
@property
|
||||
def gain(self): return self.__gain
|
||||
|
||||
@gain.setter
|
||||
def gain(self, db):
|
||||
try: db = float(db)
|
||||
except: raise TypeError("Invalid gain type, must be decibel as a floating point number")
|
||||
self.__gain = db
|
||||
if self.__source: self.__source.gain = self.__gain
|
||||
|
||||
@property
|
||||
def running(self):
|
||||
if not self.__source: return False
|
||||
else: return self.__source.should_run or len(self.__sink.frame_deque)
|
||||
else: return self.__source.should_run
|
||||
|
||||
@property
|
||||
def playing(self): return self.running
|
||||
|
||||
@property
|
||||
def release_on_finish(self): return self.__release_on_finish
|
||||
|
||||
@release_on_finish.setter
|
||||
def release_on_finish(self, value):
|
||||
if type(value) != bool: raise TypeError("Provided value is not bool")
|
||||
else: self.__release_on_finish = value
|
||||
|
||||
@property
|
||||
def finished_callback(self): return self.__finished_callback
|
||||
|
||||
@@ -61,18 +38,17 @@ class FilePlayer():
|
||||
else: self.__finished_callback = callback
|
||||
|
||||
def __callback_job(self):
|
||||
if self.__finished_callback or self.__release_on_finish:
|
||||
if self.__finished_callback:
|
||||
time.sleep(0.2)
|
||||
while self.running: time.sleep(0.1)
|
||||
if self.__finished_callback: self.__finished_callback(self)
|
||||
if self.__release_on_finish: self.release()
|
||||
self.__finished_callback(self)
|
||||
|
||||
def set_source(self, path=None):
|
||||
if not path: return
|
||||
else:
|
||||
if not os.path.isfile(path): raise OSError(f"File not found: {path}")
|
||||
else:
|
||||
self.__source = OpusFileSource(path, loop=self.__loop, gain=self.gain)
|
||||
self.__source = OpusFileSource(path, loop=self.__loop)
|
||||
self.__input_pipeline = LXST.Pipeline(source=self.__source, codec=self.__raw, sink=self.__loopback)
|
||||
|
||||
def loop(self, loop=True):
|
||||
@@ -84,7 +60,7 @@ class FilePlayer():
|
||||
if not self.running and self.__source:
|
||||
self.__input_pipeline.start()
|
||||
self.__output_pipeline.start()
|
||||
if self.__finished_callback or self.__release_on_finish:
|
||||
if self.__finished_callback:
|
||||
threading.Thread(target=self.__callback_job, daemon=True).start()
|
||||
|
||||
def stop(self):
|
||||
@@ -92,15 +68,4 @@ class FilePlayer():
|
||||
self.__input_pipeline.stop()
|
||||
self.__output_pipeline.stop()
|
||||
|
||||
def play(self): self.start()
|
||||
|
||||
def release(self):
|
||||
self.stop()
|
||||
self.__source.release()
|
||||
self.__input_pipeline.release()
|
||||
self.__output_pipeline.release()
|
||||
self.__input_pipeline = None
|
||||
self.__output_pipeline = None
|
||||
self.__sink = None
|
||||
self.__source = None
|
||||
self.__loopback = None
|
||||
def play(self): self.start()
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import LXST
|
||||
import time
|
||||
|
||||
+17
-201
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import os
|
||||
import RNS
|
||||
import LXST
|
||||
@@ -13,43 +11,23 @@ from LXST.Sinks import LineSink
|
||||
from LXST.Sources import LineSource, OpusFileSource
|
||||
from LXST.Generators import ToneSource
|
||||
from LXST.Network import SignallingReceiver, Packetizer, LinkSource
|
||||
from LXST.Filters import BandPass, AGC, EchoSuppressor
|
||||
from LXST.Filters import BandPass, AGC
|
||||
|
||||
|
||||
PRIMITIVE_NAME = "telephony"
|
||||
|
||||
class Profiles():
|
||||
BANDWIDTH_ULTRA_LOW = 0x10
|
||||
BANDWIDTH_VERY_LOW = 0x20
|
||||
BANDWIDTH_ULTRA_LOW = 0x10
|
||||
BANDWIDTH_VERY_LOW = 0x20
|
||||
BANDWIDTH_LOW = 0x30
|
||||
QUALITY_MEDIUM = 0x40
|
||||
QUALITY_HIGH = 0x50
|
||||
QUALITY_MAX = 0x60
|
||||
LATENCY_ULTRA_LOW = 0x70
|
||||
LATENCY_LOW = 0x80
|
||||
|
||||
DEFAULT_PROFILE = QUALITY_MEDIUM
|
||||
|
||||
MODE_FULL_DUPLEX = 0x01
|
||||
MODE_HALF_DUPLEX = 0x02
|
||||
DEFAULT_MODE = MODE_FULL_DUPLEX
|
||||
|
||||
@staticmethod
|
||||
def available_modes():
|
||||
return [Profiles.MODE_FULL_DUPLEX,
|
||||
Profiles.MODE_HALF_DUPLEX]
|
||||
|
||||
@staticmethod
|
||||
def mode_name(profile):
|
||||
if profile == Profiles.MODE_FULL_DUPLEX: return "Full Duplex"
|
||||
elif profile == Profiles.MODE_HALF_DUPLEX: return "Half Duplex"
|
||||
else: return "Default"
|
||||
|
||||
@staticmethod
|
||||
def mode_abbrevation(profile):
|
||||
if profile == Profiles.MODE_FULL_DUPLEX: return "FDX"
|
||||
elif profile == Profiles.MODE_HALF_DUPLEX: return "HDX"
|
||||
else: return "DFLT"
|
||||
|
||||
@staticmethod
|
||||
def available_profiles():
|
||||
return [Profiles.BANDWIDTH_ULTRA_LOW,
|
||||
@@ -114,18 +92,6 @@ class Profiles():
|
||||
elif profile == Profiles.LATENCY_ULTRA_LOW: return 10
|
||||
else: return 60
|
||||
|
||||
@staticmethod
|
||||
def get_buffer_frames(profile):
|
||||
if profile == Profiles.BANDWIDTH_ULTRA_LOW: return 2
|
||||
elif profile == Profiles.BANDWIDTH_VERY_LOW: return 2
|
||||
elif profile == Profiles.BANDWIDTH_LOW: return 2
|
||||
elif profile == Profiles.QUALITY_MEDIUM: return 5
|
||||
elif profile == Profiles.QUALITY_HIGH: return 5
|
||||
elif profile == Profiles.QUALITY_MAX: return 5
|
||||
elif profile == Profiles.LATENCY_LOW: return 3
|
||||
elif profile == Profiles.LATENCY_ULTRA_LOW: return 2
|
||||
else: return 5
|
||||
|
||||
@staticmethod
|
||||
def next_profile(profile):
|
||||
profile_list = Profiles.available_profiles()
|
||||
@@ -141,7 +107,6 @@ class Signalling():
|
||||
STATUS_RINGING = 0x04
|
||||
STATUS_CONNECTING = 0x05
|
||||
STATUS_ESTABLISHED = 0x06
|
||||
PREFERRED_MODE = 0xF0
|
||||
PREFERRED_PROFILE = 0xFF
|
||||
AUTO_STATUS_CODES = [STATUS_CALLING, STATUS_AVAILABLE, STATUS_RINGING,
|
||||
STATUS_CONNECTING, STATUS_ESTABLISHED]
|
||||
@@ -172,7 +137,6 @@ class Telephone(SignallingReceiver):
|
||||
|
||||
def __init__(self, identity, ring_time=RING_TIME, wait_time=WAIT_TIME, auto_answer=None, allowed=ALLOW_ALL, receive_gain=0.0, transmit_gain=0.0):
|
||||
super().__init__()
|
||||
RNS.Reticulum.get_instance().wants_destination_type(f"{APP_NAME}.{PRIMITIVE_NAME}")
|
||||
self.identity = identity
|
||||
self.destination = RNS.Destination(self.identity, RNS.Destination.IN, RNS.Destination.SINGLE, APP_NAME, PRIMITIVE_NAME)
|
||||
self.destination.set_proof_strategy(RNS.Destination.PROVE_NONE)
|
||||
@@ -191,8 +155,6 @@ class Telephone(SignallingReceiver):
|
||||
self.receive_gain = receive_gain
|
||||
self.transmit_gain = transmit_gain
|
||||
self.use_agc = True
|
||||
self.use_bandpass = True
|
||||
self.use_echo_cancellation = True
|
||||
self.active_call = None
|
||||
self.call_status = Signalling.STATUS_AVAILABLE
|
||||
self._external_busy = False
|
||||
@@ -202,7 +164,6 @@ class Telephone(SignallingReceiver):
|
||||
self.__busy_callback = None
|
||||
self.__rejected_callback = None
|
||||
self.target_frame_time_ms = None
|
||||
self.target_buffer_frames = None
|
||||
self.audio_output = None
|
||||
self.audio_input = None
|
||||
self.dial_tone = None
|
||||
@@ -217,13 +178,11 @@ class Telephone(SignallingReceiver):
|
||||
self.transmit_pipeline = None
|
||||
self.__receive_muted = False
|
||||
self.__transmit_muted = False
|
||||
self.__loudspeaker_on = False
|
||||
self.ringer_lock = threading.Lock()
|
||||
self.ringer_output = None
|
||||
self.ringer_pipeline = None
|
||||
self.ringtone_path = None
|
||||
self.speaker_device = None
|
||||
self.loudspeaker_device = None
|
||||
self.microphone_device = None
|
||||
self.ringer_device = None
|
||||
self.low_latency_output = False
|
||||
@@ -282,10 +241,6 @@ class Telephone(SignallingReceiver):
|
||||
self.speaker_device = device
|
||||
RNS.log(f"{self} speaker device set to {device}", RNS.LOG_DEBUG)
|
||||
|
||||
def set_loudspeaker(self, device):
|
||||
self.loudspeaker_device = device
|
||||
RNS.log(f"{self} loudspeaker device set to {device}", RNS.LOG_DEBUG)
|
||||
|
||||
def set_microphone(self, device):
|
||||
self.microphone_device = device
|
||||
RNS.log(f"{self} microphone device set to {device}", RNS.LOG_DEBUG)
|
||||
@@ -310,22 +265,6 @@ class Telephone(SignallingReceiver):
|
||||
if disable == True: self.use_agc = False
|
||||
else: self.use_agc = True
|
||||
|
||||
def enable_bandpass(self, enable=True):
|
||||
if enable == True: self.use_bandpass = True
|
||||
else: self.use_bandpass = False
|
||||
|
||||
def disable_bandpass(self, disable=True):
|
||||
if disable == True: self.use_bandpass = False
|
||||
else: self.use_bandpass = True
|
||||
|
||||
def enable_echo_cancellation(self, enable=True):
|
||||
if enable == True: self.use_echo_cancellation = True
|
||||
else: self.use_echo_cancellation = False
|
||||
|
||||
def disable_echo_cancellation(self, disable=True):
|
||||
if disable == True: self.use_echo_cancellation = False
|
||||
else: self.use_echo_cancellation = True
|
||||
|
||||
def set_low_latency_output(self, enabled):
|
||||
if enabled:
|
||||
self.low_latency_output = True
|
||||
@@ -382,9 +321,7 @@ class Telephone(SignallingReceiver):
|
||||
link.ring_timeout = False
|
||||
link.answered = False
|
||||
link.is_terminating = False
|
||||
link.established_at = None
|
||||
link.profile = None
|
||||
link.call_mode = None
|
||||
with self.call_handler_lock:
|
||||
if self.active_call or self.busy:
|
||||
RNS.log(f"Incoming call, but line is already active, signalling busy", RNS.LOG_DEBUG)
|
||||
@@ -423,7 +360,8 @@ class Telephone(SignallingReceiver):
|
||||
self.answer(identity)
|
||||
threading.Thread(target=cb, daemon=True).start()
|
||||
|
||||
else: self.__timeout_incoming_call_at(self.active_call, time.time()+self.ring_time)
|
||||
else:
|
||||
self.__timeout_incoming_call_at(self.active_call, time.time()+self.ring_time)
|
||||
|
||||
def __link_closed(self, link):
|
||||
if link == self.active_call:
|
||||
@@ -445,13 +383,6 @@ class Telephone(SignallingReceiver):
|
||||
if not hasattr(self.active_call, "profile"): return None
|
||||
else: return self.active_call.profile
|
||||
|
||||
@property
|
||||
def active_mode(self):
|
||||
if not self.active_call: return None
|
||||
else:
|
||||
if not hasattr(self.active_call, "call_mode"): return None
|
||||
else: return self.active_call.call_mode
|
||||
|
||||
@property
|
||||
def receive_muted(self):
|
||||
if not self.active_call: return False
|
||||
@@ -466,16 +397,9 @@ class Telephone(SignallingReceiver):
|
||||
if not self.transmit_mixer: return False
|
||||
else: return self.transmit_mixer.muted
|
||||
|
||||
@property
|
||||
def loudspeaker_on(self):
|
||||
return self.__loudspeaker_on
|
||||
|
||||
def signal(self, signals, link):
|
||||
if type(signals) != list: signals = [signals]
|
||||
for signal in signals:
|
||||
if signal in Signalling.AUTO_STATUS_CODES: self.call_status = signal
|
||||
|
||||
super().signal(signals, link)
|
||||
def signal(self, signal, link):
|
||||
if signal in Signalling.AUTO_STATUS_CODES: self.call_status = signal
|
||||
super().signal(signal, link)
|
||||
|
||||
def answer(self, identity):
|
||||
with self.call_handler_lock:
|
||||
@@ -491,7 +415,6 @@ class Telephone(SignallingReceiver):
|
||||
else:
|
||||
RNS.log(f"Answering call from {RNS.prettyhexrep(identity.hash)}", RNS.LOG_DEBUG)
|
||||
self.active_call.answered = True
|
||||
self.active_call.established_at = time.time()
|
||||
self.__open_pipelines(identity)
|
||||
self.__start_pipelines()
|
||||
RNS.log(f"Call setup complete for {RNS.prettyhexrep(identity.hash)}", RNS.LOG_DEBUG)
|
||||
@@ -520,7 +443,6 @@ class Telephone(SignallingReceiver):
|
||||
self.call_status = Signalling.STATUS_AVAILABLE
|
||||
self.__receive_muted = False
|
||||
self.__transmit_muted = False
|
||||
self.__loudspeaker_on = False
|
||||
if remote_identity: RNS.log(f"Call with {RNS.prettyhexrep(remote_identity.hash)} terminated", RNS.LOG_DEBUG)
|
||||
else: RNS.log(f"Outgoing call could not be connected, link establishment failed", RNS.LOG_DEBUG)
|
||||
|
||||
@@ -549,38 +471,6 @@ class Telephone(SignallingReceiver):
|
||||
self.__transmit_muted = not unmute
|
||||
if self.transmit_mixer: self.transmit_mixer.unmute(unmute)
|
||||
|
||||
def enable_loudspeaker(self, enable=True):
|
||||
was_on = self.__loudspeaker_on
|
||||
self.__loudspeaker_on = enable
|
||||
if was_on != self.__loudspeaker_on: self.__update_audio_output()
|
||||
|
||||
def disable_loudspeaker(self, disable=True):
|
||||
was_on = self.__loudspeaker_on
|
||||
self.__loudspeaker_on = not disable
|
||||
if was_on != self.__loudspeaker_on: self.__update_audio_output()
|
||||
|
||||
def pause_agc(self, pause=True):
|
||||
if self.active_call and hasattr(self.active_call, "filter_agc"):
|
||||
if pause: self.active_call.filter_agc.paused = True
|
||||
else: self.active_call.filter_agc.paused = False
|
||||
|
||||
def resume_agc(self, resume=True):
|
||||
if self.active_call and hasattr(self.active_call, "filter_agc"):
|
||||
if resume: self.active_call.filter_agc.paused = False
|
||||
else: self.active_call.filter_agc.paused = True
|
||||
|
||||
def squelch_transmit(self, squelch=True):
|
||||
self.pause_agc(squelch)
|
||||
if self.active_call and hasattr(self.active_call, "packetizer"):
|
||||
if squelch: self.active_call.packetizer.squelch()
|
||||
else: self.active_call.packetizer.unsquelch()
|
||||
|
||||
def unsquelch_transmit(self, unsquelch=True):
|
||||
self.resume_agc(unsquelch)
|
||||
if self.active_call and hasattr(self.active_call, "packetizer"):
|
||||
if unsquelch: self.active_call.packetizer.unsquelch()
|
||||
else: self.active_call.packetizer.squelch()
|
||||
|
||||
def set_receive_gain(self, gain=0.0):
|
||||
self.receive_gain = float(gain)
|
||||
if self.receive_mixer: self.receive_mixer.set_gain(self.receive_gain)
|
||||
@@ -589,31 +479,6 @@ class Telephone(SignallingReceiver):
|
||||
self.transmit_gain = float(gain)
|
||||
if self.transmit_mixer: self.transmit_mixer.set_gain(self.transmit_gain)
|
||||
|
||||
def disable_remote_mode_follow(self):
|
||||
if not self.active_call: return False
|
||||
else:
|
||||
self.active_call.mode_switch_disabled = True
|
||||
return True
|
||||
|
||||
def switch_mode(self, mode=None, from_signalling=False):
|
||||
if self.active_call:
|
||||
if from_signalling and hasattr(self.active_call, "mode_switch_disabled"): return
|
||||
if self.active_call.call_mode == mode: return
|
||||
elif not mode in Profiles.available_modes(): return
|
||||
else:
|
||||
if self.call_status == Signalling.STATUS_ESTABLISHED:
|
||||
self.active_call.call_mode = mode
|
||||
if not from_signalling: self.signal(Signalling.PREFERRED_MODE+self.active_call.call_mode, self.active_call)
|
||||
self.__select_call_mode(mode)
|
||||
|
||||
def __select_call_mode(self, mode=None):
|
||||
if mode == None: mode = Profiles.DEFAULT_MODE
|
||||
self.active_call.call_mode = mode
|
||||
if hasattr(self.active_call, "packetizer"):
|
||||
if self.active_call.call_mode == Profiles.MODE_HALF_DUPLEX: self.active_call.packetizer.squelch()
|
||||
elif self.active_call.call_mode == Profiles.MODE_FULL_DUPLEX: self.active_call.packetizer.unsquelch()
|
||||
RNS.log(f"Selected call mode 0x{RNS.hexrep(mode, delimit=False)}", RNS.LOG_DEBUG)
|
||||
|
||||
def switch_profile(self, profile=None, from_signalling=False):
|
||||
if self.active_call:
|
||||
if self.active_call.profile == profile: return
|
||||
@@ -622,18 +487,14 @@ class Telephone(SignallingReceiver):
|
||||
self.active_call.profile = profile
|
||||
self.transmit_codec = Profiles.get_codec(self.active_call.profile)
|
||||
self.target_frame_time_ms = Profiles.get_frame_time(self.active_call.profile)
|
||||
self.target_buffer_frames = Profiles.get_buffer_frames(self.active_call.profile)
|
||||
if not from_signalling: self.signal(Signalling.PREFERRED_PROFILE+self.active_call.profile, self.active_call)
|
||||
self.__reconfigure_transmit_pipeline()
|
||||
self.receive_mixer.set_source_max_frames(self.active_call.audio_source, self.target_buffer_frames)
|
||||
self.__update_output_buffer_targets()
|
||||
|
||||
def __select_call_profile(self, profile=None):
|
||||
if profile == None: profile = Profiles.DEFAULT_PROFILE
|
||||
self.active_call.profile = profile
|
||||
self.__select_call_codecs(self.active_call.profile)
|
||||
self.__select_call_frame_time(self.active_call.profile)
|
||||
self.__select_call_buffer_frames(self.active_call.profile)
|
||||
RNS.log(f"Selected call profile 0x{RNS.hexrep(profile, delimit=False)}", RNS.LOG_DEBUG)
|
||||
|
||||
def __select_call_codecs(self, profile=None):
|
||||
@@ -643,9 +504,6 @@ class Telephone(SignallingReceiver):
|
||||
def __select_call_frame_time(self, profile=None):
|
||||
self.target_frame_time_ms = Profiles.get_frame_time(profile)
|
||||
|
||||
def __select_call_buffer_frames(self, profile=None):
|
||||
self.target_buffer_frames = Profiles.get_buffer_frames(self.active_call.profile)
|
||||
|
||||
def __reset_dialling_pipelines(self):
|
||||
with self.pipeline_lock:
|
||||
if self.audio_output: self.audio_output.stop()
|
||||
@@ -658,37 +516,12 @@ class Telephone(SignallingReceiver):
|
||||
self.receive_mixer = None
|
||||
self.__prepare_dialling_pipelines()
|
||||
|
||||
def __update_output_buffer_targets(self):
|
||||
if self.audio_output and self.target_buffer_frames:
|
||||
if self.audio_output.buffer_max_height != self.target_buffer_frames:
|
||||
self.audio_output.buffer_max_height = self.target_buffer_frames+1
|
||||
RNS.log(f"Updated {self.audio_output} buffer size to {self.audio_output.buffer_max_height} frames", RNS.LOG_DEBUG)
|
||||
if self.audio_output.autostart_min != self.target_buffer_frames:
|
||||
self.audio_output.autostart_min = max(1, self.target_buffer_frames-2)
|
||||
RNS.log(f"Updated {self.audio_output} buffer trigger height to {self.audio_output.autostart_min} frames", RNS.LOG_DEBUG)
|
||||
self.audio_output.streaming = True
|
||||
self.audio_output.wait_for_frames()
|
||||
|
||||
def __prepare_dialling_pipelines(self):
|
||||
self.__select_call_profile(self.active_call.profile)
|
||||
self.__select_call_mode(self.active_call.call_mode)
|
||||
if self.audio_output == None: self.audio_output = LineSink(preferred_device=self.speaker_device) if not self.__loudspeaker_on else LineSink(preferred_device=self.loudspeaker_device)
|
||||
if self.audio_output == None: self.audio_output = LineSink(preferred_device=self.speaker_device)
|
||||
if self.receive_mixer == None: self.receive_mixer = Mixer(target_frame_ms=self.target_frame_time_ms, gain=self.receive_gain)
|
||||
if self.dial_tone == None: self.dial_tone = ToneSource(frequency=self.dial_tone_frequency, gain=0.0, ease_time_ms=self.dial_tone_ease_ms, target_frame_ms=self.target_frame_time_ms, codec=Null(), sink=self.receive_mixer)
|
||||
if self.receive_pipeline == None: self.receive_pipeline = Pipeline(source=self.receive_mixer, codec=Null(), sink=self.audio_output)
|
||||
self.__update_output_buffer_targets()
|
||||
|
||||
def __update_audio_output(self):
|
||||
if self.active_call and self.audio_output and self.receive_pipeline and self.receive_mixer:
|
||||
with self.pipeline_lock:
|
||||
previous_output = self.audio_output
|
||||
previous_pipeline = self.receive_pipeline
|
||||
self.audio_output = LineSink(preferred_device=self.speaker_device) if not self.__loudspeaker_on else LineSink(preferred_device=self.loudspeaker_device)
|
||||
self.receive_pipeline = Pipeline(source=self.receive_mixer, codec=Null(), sink=self.audio_output)
|
||||
self.receive_pipeline.start()
|
||||
previous_pipeline.stop()
|
||||
previous_output.stop()
|
||||
self.receive_mixer.start()
|
||||
|
||||
def __activate_ring_tone(self):
|
||||
if self.ringtone_path != None and os.path.isfile(self.ringtone_path):
|
||||
@@ -699,7 +532,6 @@ class Telephone(SignallingReceiver):
|
||||
|
||||
def job():
|
||||
with self.ringer_lock:
|
||||
time.sleep(0.5)
|
||||
while self.active_call and self.active_call.is_incoming and self.call_status == Signalling.STATUS_RINGING:
|
||||
if not self.ringer_pipeline.running: self.ringer_pipeline.start()
|
||||
time.sleep(0.1)
|
||||
@@ -773,20 +605,11 @@ class Telephone(SignallingReceiver):
|
||||
RNS.log(f"Opening audio pipelines for call with {RNS.prettyhexrep(identity.hash)}", RNS.LOG_DEBUG)
|
||||
if self.active_call.is_incoming: self.signal(Signalling.STATUS_CONNECTING, self.active_call)
|
||||
|
||||
filter_chain = []
|
||||
if self.use_bandpass: filter_chain.append(BandPass(250, 8500))
|
||||
if self.use_agc: self.active_call.filter_agc = AGC(target_level=-15.0)
|
||||
if self.use_agc: filter_chain.append(self.active_call.filter_agc)
|
||||
if self.use_echo_cancellation:
|
||||
self.active_call.echo_suppressor = EchoSuppressor()
|
||||
self.receive_mixer.reference_outs = [self.active_call.echo_suppressor]
|
||||
filter_chain.append(self.active_call.echo_suppressor)
|
||||
|
||||
self.active_call.filters = filter_chain
|
||||
if self.use_agc: self.active_call.filters = [BandPass(250, 8500), AGC(target_level=-15.0)]
|
||||
else: self.active_call.filters = [BandPass(250, 8500)]
|
||||
|
||||
self.__prepare_dialling_pipelines()
|
||||
self.active_call.packetizer = Packetizer(self.active_call, failure_callback=self.__packetizer_failure)
|
||||
if self.active_call.call_mode == Profiles.MODE_HALF_DUPLEX: self.active_call.packetizer.squelch()
|
||||
|
||||
self.transmit_mixer = Mixer(target_frame_ms=self.target_frame_time_ms, gain=self.transmit_gain)
|
||||
|
||||
@@ -796,7 +619,7 @@ class Telephone(SignallingReceiver):
|
||||
self.transmit_pipeline = Pipeline(source=self.transmit_mixer, codec=self.transmit_codec, sink=self.active_call.packetizer)
|
||||
|
||||
self.active_call.audio_source = LinkSource(link=self.active_call, signalling_receiver=self, sink=self.receive_mixer)
|
||||
self.receive_mixer.set_source_max_frames(self.active_call.audio_source, self.target_buffer_frames)
|
||||
self.receive_mixer.set_source_max_frames(self.active_call.audio_source, 2)
|
||||
|
||||
self.signal(Signalling.STATUS_ESTABLISHED, self.active_call)
|
||||
|
||||
@@ -822,7 +645,7 @@ class Telephone(SignallingReceiver):
|
||||
if self.transmit_pipeline: self.transmit_pipeline.stop()
|
||||
RNS.log(f"Audio pipelines stopped", RNS.LOG_DEBUG)
|
||||
|
||||
def call(self, identity, profile=None, mode=None):
|
||||
def call(self, identity, profile=None):
|
||||
with self.call_handler_lock:
|
||||
if not self.active_call:
|
||||
self.call_status = Signalling.STATUS_CALLING
|
||||
@@ -845,9 +668,7 @@ class Telephone(SignallingReceiver):
|
||||
self.active_call.is_outgoing = True
|
||||
self.active_call.is_terminating = False
|
||||
self.active_call.ring_timeout = False
|
||||
self.active_call.established_at = None
|
||||
self.active_call.profile = profile
|
||||
self.active_call.call_mode = mode
|
||||
self.__timeout_outgoing_call_at(self.active_call, outgoing_call_timeout)
|
||||
self.__timeout_outgoing_establishment_at(self.active_call, outgoing_establishment_timeout)
|
||||
|
||||
@@ -863,7 +684,8 @@ class Telephone(SignallingReceiver):
|
||||
for signal in signals:
|
||||
if source != self.active_call: RNS.log("Received signalling on non-active call, ignoring", RNS.LOG_DEBUG)
|
||||
else:
|
||||
if self.active_call.is_incoming and not self.active_call.answered and signal < Signalling.PREFERRED_MODE: return
|
||||
if self.active_call.is_incoming and not self.active_call.answered and signal < Signalling.PREFERRED_PROFILE:
|
||||
return
|
||||
elif signal == Signalling.STATUS_BUSY:
|
||||
RNS.log("Remote is busy, terminating", RNS.LOG_DEBUG)
|
||||
self.active_call.is_terminating = True
|
||||
@@ -883,8 +705,7 @@ class Telephone(SignallingReceiver):
|
||||
RNS.log("Identification accepted, remote is now ringing", RNS.LOG_DEBUG)
|
||||
self.call_status = signal
|
||||
self.__prepare_dialling_pipelines()
|
||||
self.signal([Signalling.PREFERRED_PROFILE+self.active_call.profile,
|
||||
Signalling.PREFERRED_MODE+self.active_call.call_mode], self.active_call)
|
||||
self.signal(Signalling.PREFERRED_PROFILE+self.active_call.profile, self.active_call)
|
||||
if self.active_call and self.active_call.is_outgoing: self.__activate_dial_tone()
|
||||
elif signal == Signalling.STATUS_CONNECTING:
|
||||
RNS.log("Call answered, remote is performing call setup, opening audio pipelines", RNS.LOG_DEBUG)
|
||||
@@ -900,17 +721,12 @@ class Telephone(SignallingReceiver):
|
||||
self.__disable_dial_tone()
|
||||
RNS.log(f"Call setup complete for {RNS.prettyhexrep(self.active_call.get_remote_identity().hash)}", RNS.LOG_DEBUG)
|
||||
self.call_status = signal
|
||||
self.active_call.established_at = time.time()
|
||||
if callable(self.__established_callback): self.__established_callback(self.active_call.get_remote_identity())
|
||||
if self.low_latency_output: self.audio_output.enable_low_latency()
|
||||
elif signal >= Signalling.PREFERRED_PROFILE:
|
||||
profile = signal - Signalling.PREFERRED_PROFILE
|
||||
if self.active_call and self.call_status == Signalling.STATUS_ESTABLISHED: self.switch_profile(profile, from_signalling=True)
|
||||
else: self.__select_call_profile(profile)
|
||||
elif signal >= Signalling.PREFERRED_MODE:
|
||||
mode = signal - Signalling.PREFERRED_MODE
|
||||
if self.active_call and self.call_status == Signalling.STATUS_ESTABLISHED: self.switch_mode(mode, from_signalling=True)
|
||||
else: self.__select_call_mode(mode)
|
||||
|
||||
def __str__(self):
|
||||
return f"<lxst.telephony/{RNS.hexrep(self.identity.hash, delimit=False)}>"
|
||||
@@ -1,3 +1 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
from .Telephony import Telephone
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
import os
|
||||
import time
|
||||
import threading
|
||||
from importlib.util import find_spec
|
||||
if find_spec("RPi"): import RPi.GPIO as GPIO
|
||||
else: raise OSError(f"No GPIO module available, cannot use {os.path.basename(__file__)} driver")
|
||||
|
||||
class Event:
|
||||
UP = 0x00
|
||||
DOWN = 0x01
|
||||
|
||||
class Keypad():
|
||||
ROWS = 5
|
||||
COLS = 5
|
||||
SCAN_INTERVAL_MS = 20
|
||||
|
||||
LOW = 0x00
|
||||
HIGH = 0x01
|
||||
|
||||
DEFAULT_MAP = [["P", "R", "M", "-", "+"],
|
||||
["1", "2", "3", "A", "B"],
|
||||
["4", "5", "6", "C", "D"],
|
||||
["7", "8", "9", "E", "F"],
|
||||
["*", "0", "#", "N", "K"]]
|
||||
|
||||
DEFAULT_ROWPINS = [21, 20, 16, 12, 7]
|
||||
DEFAULT_COLPINS = [26, 19, 13, 6, 5]
|
||||
DEFAULT_HOOKPIN = 11
|
||||
HOOK_DEBOUNCE_MS = 150
|
||||
|
||||
def __init__(self, row_pins=None, col_pins=None, key_map=None, callback=None):
|
||||
if not row_pins == None and (not type(row_pins) == list or len(row_pins) != 5):
|
||||
raise ValueError("Invalid row pins specification")
|
||||
if not col_pins == None and (not type(col_pins) == list or len(col_pins) != 5):
|
||||
raise ValueError("Invalid row pins specification")
|
||||
|
||||
self.row_pins = row_pins or self.DEFAULT_ROWPINS
|
||||
self.col_pins = col_pins or self.DEFAULT_COLPINS
|
||||
self.scan_lock = threading.Lock()
|
||||
self.callback = callback
|
||||
self.hook_time = 0
|
||||
self.hook_pin = None
|
||||
self.on_hook = True
|
||||
self.check_hook = False
|
||||
self.should_run = False
|
||||
self.ec = Event
|
||||
self.set_key_map(key_map)
|
||||
|
||||
def enable_hook(self, pin=None):
|
||||
if pin == None: pin = self.DEFAULT_HOOKPIN
|
||||
self.hook_pin = pin
|
||||
GPIO.setup(self.hook_pin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
|
||||
self.key_states["hook"] = False
|
||||
self.check_hook = True
|
||||
|
||||
def set_key_map(self, key_map):
|
||||
self.key_map = key_map or self.DEFAULT_MAP
|
||||
self.key_states = {}
|
||||
for row in self.key_map:
|
||||
for key in row: self.key_states[key] = False
|
||||
|
||||
def is_down(self, key):
|
||||
if not key in self.key_states: return False
|
||||
else:
|
||||
return self.key_states[key]
|
||||
|
||||
def is_up(self, key):
|
||||
if not key in self.key_states: return False
|
||||
else:
|
||||
return not self.key_states[key]
|
||||
|
||||
def __job(self):
|
||||
while self.should_run:
|
||||
self.__scan()
|
||||
time.sleep(self.SCAN_INTERVAL_MS/1000)
|
||||
|
||||
def __handle(self, active_keys):
|
||||
events = []
|
||||
for key in self.key_states:
|
||||
if self.key_states[key] == False:
|
||||
if key in active_keys:
|
||||
self.key_states[key] = True
|
||||
events.append((key, Event.DOWN))
|
||||
|
||||
elif self.key_states[key] == True:
|
||||
if not key in active_keys:
|
||||
self.key_states[key] = False
|
||||
events.append((key, Event.UP))
|
||||
|
||||
if callable(self.callback):
|
||||
for event in events:
|
||||
self.callback(self, event)
|
||||
|
||||
def __scan(self):
|
||||
active_keys = []
|
||||
for row in range(0, self.ROWS):
|
||||
GPIO.setup(self.row_pins[row], GPIO.OUT)
|
||||
GPIO.output(self.row_pins[row], GPIO.HIGH)
|
||||
for col in range(0, self.COLS):
|
||||
if GPIO.input(self.col_pins[col]):
|
||||
active_keys.append(self.key_map[row][col])
|
||||
|
||||
GPIO.output(self.row_pins[row], GPIO.LOW)
|
||||
GPIO.setup(self.row_pins[row], GPIO.IN, pull_up_down=GPIO.PUD_OFF)
|
||||
|
||||
if self.check_hook:
|
||||
on_hook = GPIO.input(self.hook_pin) == GPIO.LOW
|
||||
|
||||
if on_hook:
|
||||
active_keys.append("hook")
|
||||
self.hook_time = time.time()
|
||||
|
||||
if self.key_states["hook"] == True and not on_hook:
|
||||
if time.time()-self.hook_time < self.HOOK_DEBOUNCE_MS/1000:
|
||||
active_keys.append("hook")
|
||||
else:
|
||||
self.hook_time = time.time()
|
||||
|
||||
if len(active_keys) >= 0 and len(active_keys) <= 4: self.__handle(active_keys)
|
||||
|
||||
def start(self):
|
||||
GPIO.setwarnings(False)
|
||||
GPIO.setmode(GPIO.BCM)
|
||||
for row_pin in self.row_pins: GPIO.setup(row_pin, GPIO.OUT)
|
||||
for col_pin in self.col_pins: GPIO.setup(col_pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
|
||||
|
||||
self.should_run = True
|
||||
threading.Thread(target=self.__job, daemon=True).start()
|
||||
|
||||
def stop(self):
|
||||
self.should_run = False
|
||||
+3
-29
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import math
|
||||
import time
|
||||
@@ -111,16 +109,6 @@ def get_backend():
|
||||
Backend = get_backend()
|
||||
|
||||
class Sink():
|
||||
release_lock = threading.Lock()
|
||||
def release(self):
|
||||
if self.release_lock.locked(): return
|
||||
with self.release_lock:
|
||||
if not hasattr(self, "released") or not self.released:
|
||||
self.released = True
|
||||
self.should_run = False
|
||||
self.frame_deque = None
|
||||
self.backend = None
|
||||
|
||||
def handle_frame(self, frame, source): pass
|
||||
def can_receive(self, from_source=None): return True
|
||||
|
||||
@@ -145,7 +133,6 @@ class LineSink(LocalSink):
|
||||
self.autostart_min = self.AUTOSTART_MIN
|
||||
self.buffer_max_height = self.MAX_FRAMES-3
|
||||
self.low_latency = low_latency
|
||||
self.streaming = False
|
||||
|
||||
self.preferred_samplerate = Backend.SAMPLERATE
|
||||
self.backend = Backend(preferred_device=self.preferred_device, samplerate=self.preferred_samplerate)
|
||||
@@ -174,9 +161,7 @@ class LineSink(LocalSink):
|
||||
RNS.log(f"{self} starting at {self.samples_per_frame} samples per frame, {self.channels} channels", RNS.LOG_DEBUG)
|
||||
|
||||
if self.autodigest and not self.should_run:
|
||||
if len(self.frame_deque) >= self.autostart_min:
|
||||
RNS.log(f"Auto-digest buffer height of {self.autostart_min} reached on {self}, starting", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
self.start()
|
||||
if len(self.frame_deque) >= self.autostart_min: self.start()
|
||||
|
||||
def start(self):
|
||||
if not self.should_run:
|
||||
@@ -187,12 +172,6 @@ class LineSink(LocalSink):
|
||||
def stop(self):
|
||||
self.should_run = False
|
||||
|
||||
def wait_for_frames(self):
|
||||
if len(self.frame_deque) < self.autostart_min:
|
||||
self.stop()
|
||||
self.autodigest = True
|
||||
RNS.log(f"{self} waiting for frames before re-engaging output", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
|
||||
def enable_low_latency(self):
|
||||
self.__wants_low_latency = True
|
||||
|
||||
@@ -210,15 +189,11 @@ class LineSink(LocalSink):
|
||||
self.underrun_at = None
|
||||
|
||||
with self.insert_lock: frame = self.frame_deque.popleft()
|
||||
if self.channels != self.backend.device.channels:
|
||||
RNS.log(f"Underlying device for {self} re-configured channel map mid-stream (from {self.channels} to {self.backend.device.channels})", RNS.LOG_WARNING)
|
||||
self.channels = self.backend.device.channels
|
||||
|
||||
if frame.shape[1] > self.channels: frame = frame[:, 0:self.channels]
|
||||
player.play(frame)
|
||||
|
||||
if len(self.frame_deque) > self.buffer_max_height:
|
||||
RNS.log(f"Buffer lag on {self} (height {len(self.frame_deque)}), dropping one frame", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
RNS.log(f"Buffer lag on {self} (height {len(self.frame_deque)}), dropping one frame", RNS.LOG_DEBUG)
|
||||
self.frame_deque.popleft()
|
||||
|
||||
else:
|
||||
@@ -226,7 +201,6 @@ class LineSink(LocalSink):
|
||||
# TODO: Remove debug
|
||||
# RNS.log(f"Buffer underrun on {self}", RNS.LOG_DEBUG)
|
||||
self.underrun_at = time.time()
|
||||
if self.streaming: time.sleep((self.frame_time*self.buffer_max_height)/3.0)
|
||||
else:
|
||||
if time.time() > self.underrun_at+(self.frame_time*self.frame_timeout):
|
||||
RNS.log(f"No frames available on {self}, stopping playback", RNS.LOG_DEBUG)
|
||||
@@ -351,7 +325,7 @@ class OpusFileSink(LocalSink):
|
||||
frame = np.hstack([frame, frame[:, -1:]])
|
||||
|
||||
if frame.shape[0] < self.samples_per_frame:
|
||||
RNS.log("Insufficient frame data, padding with silence", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
RNS.log("Insufficient frame data, padding with silence", RNS.LOG_DEBUG)
|
||||
silence_frame = np.zeros((self.samples_per_frame-frame.shape[0], frame.shape[1]), dtype=frame.dtype)
|
||||
frame = np.vstack([frame, silence_frame])
|
||||
|
||||
|
||||
+6
-82
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import os
|
||||
import RNS
|
||||
import math
|
||||
@@ -120,21 +118,7 @@ def get_backend():
|
||||
|
||||
Backend = get_backend()
|
||||
|
||||
class Source():
|
||||
release_lock = threading.Lock()
|
||||
def release(self):
|
||||
if self.release_lock.locked(): return
|
||||
with self.release_lock:
|
||||
if not hasattr(self, "released") or not self.released:
|
||||
self.released = True
|
||||
self.should_run = False
|
||||
self.frame_deque = None
|
||||
self.codec = None
|
||||
self._sink = None
|
||||
self._source = None
|
||||
self._filters = None
|
||||
self.backend = None
|
||||
|
||||
class Source(): pass
|
||||
class LocalSource(Source): pass
|
||||
class RemoteSource(Source): pass
|
||||
|
||||
@@ -175,7 +159,6 @@ class Loopback(LocalSource, LocalSink):
|
||||
class LineSource(LocalSource):
|
||||
MAX_FRAMES = 128
|
||||
DEFAULT_FRAME_MS = 80
|
||||
SIGNAL_FAIL_REINIT_THRESHOLD = 1.5
|
||||
|
||||
@staticmethod
|
||||
def linear_gain(gain_db): return 10**(gain_db/10)
|
||||
@@ -200,11 +183,6 @@ class LineSource(LocalSource):
|
||||
self.__gain = self.linear_gain(self.gain)
|
||||
self.__target_gain = self.__gain
|
||||
|
||||
self.__check_signal = RNS.vendor.platformutils.is_android()
|
||||
self.__signal_failed = None
|
||||
self.__signal_ok = False
|
||||
self.__must_reinit = False
|
||||
|
||||
if filters != None:
|
||||
if type(filters) == list: self.filters = filters
|
||||
else: self.filters = [filters]
|
||||
@@ -265,46 +243,19 @@ class LineSource(LocalSource):
|
||||
ease_in_completed = True if self.ease_in <= 0.0 else False
|
||||
skip_completed = True if self.__skip <= 0.0 else False
|
||||
while self.should_run:
|
||||
# st = time.perf_counter() # TODO: Remove debug
|
||||
frame_samples = recorder.record(numframes=self.samples_per_frame)
|
||||
# rt = time.perf_counter()-st # TODO: Remove debug
|
||||
|
||||
if self.__check_signal and not self.__signal_ok:
|
||||
if np.all(frame_samples == 0):
|
||||
if not self.__signal_failed: self.__signal_failed = time.time()
|
||||
else:
|
||||
self.__signal_ok = True
|
||||
RNS.log(f"Input signal detected on {self}", RNS.LOG_DEBUG)
|
||||
|
||||
if not self.__signal_ok and self.__signal_failed:
|
||||
fail_duration = time.time()-self.__signal_failed
|
||||
RNS.log(f"No signal for {RNS.prettyshorttime(fail_duration)} on {self}", RNS.LOG_DEBUG)
|
||||
if fail_duration > self.SIGNAL_FAIL_REINIT_THRESHOLD:
|
||||
RNS.log(f"Scheduling re-init on {self}", RNS.LOG_DEBUG)
|
||||
self.__must_reinit = True
|
||||
self.stop()
|
||||
|
||||
if not skip_completed:
|
||||
if time.time()-started > self.__skip:
|
||||
skip_completed = True
|
||||
started = time.time()
|
||||
else:
|
||||
# ft = 0 # TODO: Remove debug
|
||||
if self.filters != None:
|
||||
# st = time.perf_counter() # TODO: Remove debug
|
||||
for f in self.filters: frame_samples = f.handle_frame(frame_samples, self.samplerate)
|
||||
# ft = time.perf_counter()-st # TODO: Remove debug
|
||||
if self.__gain != 1.0: frame_samples *= self.__gain
|
||||
if self.codec:
|
||||
frame = self.codec.encode(frame_samples)
|
||||
if self.sink and self.sink.can_receive(from_source=self):
|
||||
try:
|
||||
# st = time.perf_counter() # TODO: Remove debug
|
||||
frame = self.codec.encode(frame_samples)
|
||||
self.sink.handle_frame(frame, self)
|
||||
# et = time.perf_counter()-st # TODO: Remove debug
|
||||
except Exception as e: RNS.log(f"Encode error on {self}: {e}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
# RNS.log(f"REC/FLT/SNK: {RNS.prettyshorttime(rt)} / {RNS.prettyshorttime(ft)}, / {RNS.prettyshorttime(et)}", RNS.LOG_DEBUG) # TODO: Remove debug
|
||||
|
||||
self.sink.handle_frame(frame, self)
|
||||
if not ease_in_completed:
|
||||
d = time.time()-started
|
||||
self.__gain = (d/self.ease_in)*self.__target_gain
|
||||
@@ -312,22 +263,13 @@ class LineSource(LocalSource):
|
||||
self.__gain = self.__target_gain
|
||||
ease_in_completed = True
|
||||
|
||||
if self.__must_reinit:
|
||||
self.__must_reinit = False
|
||||
self.__signal_ok = False
|
||||
self.__signal_failed = None
|
||||
self.start()
|
||||
|
||||
|
||||
class OpusFileSource(LocalSource):
|
||||
MAX_FRAMES = 128
|
||||
DEFAULT_FRAME_MS = 100
|
||||
TYPE_MAP_FACTOR = np.iinfo("int16").max
|
||||
|
||||
@staticmethod
|
||||
def linear_gain(gain_db): return 10**(gain_db/10)
|
||||
|
||||
def __init__(self, file_path, target_frame_ms=DEFAULT_FRAME_MS, loop=False, codec=None, sink=None, timed=False, gain=0.0):
|
||||
def __init__(self, file_path, target_frame_ms=DEFAULT_FRAME_MS, loop=False, codec=None, sink=None, timed=False):
|
||||
self.target_frame_ms = target_frame_ms
|
||||
self.loop = loop
|
||||
self.timed = timed
|
||||
@@ -336,8 +278,6 @@ class OpusFileSource(LocalSource):
|
||||
self.ingest_thread = None
|
||||
self.next_frame = None
|
||||
self._codec = None
|
||||
self._gain_db = gain
|
||||
self.__gain = self.linear_gain(self._gain_db)
|
||||
|
||||
if file_path == None: raise TypeError(f"{self} initialised with invalid file path: {file_path}")
|
||||
elif os.path.isfile(file_path):
|
||||
@@ -356,19 +296,6 @@ class OpusFileSource(LocalSource):
|
||||
self.codec = codec
|
||||
self.sink = sink
|
||||
|
||||
@property
|
||||
def running(self): return self.should_run
|
||||
|
||||
@property
|
||||
def gain(self): return self._gain_db
|
||||
|
||||
@gain.setter
|
||||
def gain(self, db):
|
||||
try: db = float(db)
|
||||
except: raise TypeError("Invalid gain type, must be decibel as a floating point number")
|
||||
self._gain_db = db
|
||||
self.__gain = self.linear_gain(self._gain_db)
|
||||
|
||||
@property
|
||||
def codec(self): return self._codec
|
||||
|
||||
@@ -417,7 +344,6 @@ class OpusFileSource(LocalSource):
|
||||
fi += 1
|
||||
fs = (fi-1)*spf; fe = min(fi*spf, sc)
|
||||
frame_samples = self.samples[fs:fe, :]
|
||||
if self.__gain != 1.0: frame_samples *= self.__gain
|
||||
if len(frame_samples) < 1:
|
||||
if self.loop:
|
||||
RNS.log(f"{self} exhausted file samples, looping...", RNS.LOG_DEBUG)
|
||||
@@ -427,10 +353,8 @@ class OpusFileSource(LocalSource):
|
||||
self.should_run = False
|
||||
else:
|
||||
if self.codec:
|
||||
frame = self.codec.encode(frame_samples)
|
||||
if self.sink and self.sink.can_receive(from_source=self):
|
||||
try:
|
||||
frame = self.codec.encode(frame_samples)
|
||||
self.sink.handle_frame(frame, self)
|
||||
except Exception as e: RNS.log(f"Encode error on {self}: {e}", RNS.LOG_DEBUG) if RNS.sl(RNS.LOG_DEBUG) else None
|
||||
self.sink.handle_frame(frame, self)
|
||||
else:
|
||||
time.sleep(self.frame_time*0.1)
|
||||
@@ -1,7 +1,5 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
import RNS
|
||||
import os
|
||||
import sys
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
# Copyright 2024-2026, Mark Qvist
|
||||
|
||||
APP_NAME = "lxst"
|
||||
|
||||
from .Pipeline import Pipeline
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
__version__ = "0.6.0"
|
||||
__version__ = "0.4.5"
|
||||
@@ -21,15 +21,7 @@ create_symlinks:
|
||||
build_wheel:
|
||||
cp ./lib/static/* ./LXST/
|
||||
touch ./skip_extensions
|
||||
python3 setup.py bdist_wheel
|
||||
rm ./skip_extensions
|
||||
-@(rm ./LXST/*.so)
|
||||
-@(rm ./LXST/*.dll)
|
||||
|
||||
build_sdist:
|
||||
cp ./lib/static/* ./LXST/
|
||||
touch ./skip_extensions
|
||||
python3 setup.py sdist
|
||||
python3 setup.py sdist bdist_wheel
|
||||
rm ./skip_extensions
|
||||
-@(rm ./LXST/*.so)
|
||||
-@(rm ./LXST/*.dll)
|
||||
@@ -48,18 +40,11 @@ persist_libs:
|
||||
-cp ./lib/dev/*.so ./lib/static/
|
||||
-cp ./lib/dev/*.dll ./lib/static/
|
||||
|
||||
build_spkg: remove_symlinks build_sdist create_symlinks
|
||||
|
||||
release: remove_symlinks build_wheel create_symlinks
|
||||
|
||||
upload:
|
||||
@echo Ready to publish release over Reticulum
|
||||
@read VOID
|
||||
rngit release rns://7649a50d84610232d1416b41d2896aff/reticulum/lxst create $$(python setup.py --getversion):dist --name lxst
|
||||
|
||||
upload-pip:
|
||||
@echo Ready to publish release, hit enter to continue
|
||||
@read VOID
|
||||
@echo Uploading to PyPi...
|
||||
twine upload dist/lxst-*.whl
|
||||
twine upload dist/*
|
||||
@echo Release published
|
||||
@@ -13,8 +13,6 @@
|
||||
|
||||
*Due to the blatant copyright infringement and LLM-laundering, the source code in this repository is no longer updated. All development is happening over Reticulum, where the latest source is available. Packages and updates continue to ship on PyPI and over `rngit`.*
|
||||
|
||||
---
|
||||
|
||||
LXST is a simple and flexible real-time streaming format and delivery protocol that allows a wide variety of implementations, while using as little bandwidth as possible. It is built on top of [Reticulum](https://reticulum.network) and offers zero-conf stream routing, end-to-end encryption and Forward Secrecy, and can be transported over any kind of medium that Reticulum supports.
|
||||
|
||||
- Cross-platform, works on Linux, Android, Windows and Mac
|
||||
@@ -52,7 +50,6 @@ User-facing clients built on LXST include:
|
||||
- [MeshChatX](https://meshchatx.com/)
|
||||
- [Partyline](https://github.com/RFnexus/partyline)
|
||||
- [Columba](https://github.com/torlando-tech/columba)
|
||||
- [Ratspeak](https://github.com/ratspeak/)
|
||||
- [rnphone](https://reticulum.network/manual/software.html#reticulum-network-telephone)
|
||||
- [LXST Phone](https://github.com/kc1awv/lxst_phone)
|
||||
|
||||
@@ -64,21 +61,7 @@ LXST uses encryption provided by [Reticulum](https://reticulum.network), and thu
|
||||
|
||||
This software and its interfaces will change rapidly with ongoing development. Consider no APIs stable. Consider everything explosive. Not all features are implemented. Nothing is documented. For a fully functional LXST program, take a look at [Sideband](https://github.com/markqvist/Sideband) or the included `rnphone` program, which provides telephony service over Reticulum. Everything else will currently be a voyage of your own making.
|
||||
|
||||
The LXST project is available under a `CC BY-NC-ND 4.0` license. You can use and deploy LXST freely for non-commercial, personal and humanitarian purposes, including in your own programs. At this point, no derivatives are allowed without an explicit license.
|
||||
|
||||
For commercial (including institutionalised educational) licensing, contact me.
|
||||
|
||||
LXST uses third-party codecs, and where included in source and binary distributions, these are distributed under their respective licenses:
|
||||
|
||||
- Parts of `pydub`, under the [MIT License](./LXST/Codecs/libs/pydub/LICENSE), Copyright (c) 2011 James Robert.
|
||||
- The [Ogg License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
- The [Opus License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
- The [Opusenc License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
- The [Opusfile License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
- The [Vorbis License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
- The [Flac License](./LXST/Codecs/libs/pyogg/LICENSE)
|
||||
|
||||
Additionally, some parts of the platform abstraction code is released under the BSD 3-Clause license. See the relevant license headers for details.
|
||||
The LXST project is available under a `CC BY-NC-ND 4.0` license. You can deploy LXST freely for non-commercial, personal and humanitarian purposes. For commercial (including institutionalised educational) licensing, contact me.
|
||||
|
||||
## Installation
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ if loop:
|
||||
|
||||
else:
|
||||
player = FilePlayer("./docs/speech_stereo.opus")
|
||||
player.release_on_finish = True
|
||||
player.start()
|
||||
|
||||
while player.running: time.sleep(0.1)
|
||||
|
||||
@@ -2,23 +2,18 @@ import setuptools
|
||||
from setuptools import setup, Extension
|
||||
from setuptools.command.build_ext import build_ext
|
||||
import os
|
||||
import sys
|
||||
import platform
|
||||
|
||||
if os.path.isfile("./skip_extensions"): BUILD_EXTENSIONS = False
|
||||
else: BUILD_EXTENSIONS = True
|
||||
if os.name == "nt": BUILD_EXTENSIONS = False
|
||||
|
||||
with open("README.md", "r") as fh: long_description = fh.read()
|
||||
exec(open("LXST/_version.py", "r").read())
|
||||
|
||||
if "--getversion" in sys.argv:
|
||||
print(__version__, end="")
|
||||
exit(0)
|
||||
|
||||
if BUILD_EXTENSIONS: print(f"Building LXST with native extensions...")
|
||||
else: print(f"Building LXST without native extensions...")
|
||||
|
||||
with open("README.md", "r") as fh: long_description = fh.read()
|
||||
exec(open("LXST/_version.py", "r").read())
|
||||
|
||||
c_sources = ["LXST/Filters.c"]
|
||||
|
||||
if BUILD_EXTENSIONS: extensions = [ Extension("LXST.filterlib", sources=c_sources, include_dirs=["LXST"], language="c"), ]
|
||||
@@ -70,8 +65,8 @@ setuptools.setup(
|
||||
'rnphone=LXST.Utilities.rnphone:main',
|
||||
]
|
||||
},
|
||||
install_requires=["rns>=1.6.0",
|
||||
"lxmf>=1.3.0",
|
||||
install_requires=["rns>=1.0.4",
|
||||
"lxmf>=0.9.3",
|
||||
"numpy>=2.3.4",
|
||||
"pycodec2>=4.1.0",
|
||||
"audioop-lts>=0.2.1;python_version>='3.13'",
|
||||
|
||||
Reference in new issue
Block a user