Skip to content

Commit

Permalink
Merge pull request #23 from HEnquist/deprecated_actions
Browse files Browse the repository at this point in the history
Update deprecated actions
  • Loading branch information
HEnquist authored Aug 29, 2023
2 parents 45b566e + 66be16b commit 9567aa7
Show file tree
Hide file tree
Showing 7 changed files with 172 additions and 99 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,30 @@ on: [push]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.8', '3.11']
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
uses: actions/setup-python@v3
with:
python-version: '3.x'
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install PyYAML
pip install websocket_client
pip install .
pip install ".[dev]"
- name: Test with pytest
run: |
pip install pytest
pip install pytest-cov
pytest --cov=camilladsp --cov-report=html
- name: pylint
run: |
pylint camilladsp
- name: Lint types
run: |
mypy --install-types --non-interactive camilladsp
- name: Lint formatting
run: |
black . --check --verbose
5 changes: 3 additions & 2 deletions camilladsp/camilladsp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

VERSION = "2.0.0-alpha2"


class CamillaError(ValueError):
"""
A class representing errors returned by CamillaDSP.
Expand Down Expand Up @@ -858,8 +859,8 @@ def library(self) -> Tuple[str, str, str]:
Tuple[List[str], List[str]] | None: A tuple containing the pyCamillaDSP version,
as (major, minor, patch).
"""
v = VERSION.split(".")
return (v[0], v[1], v[2])
ver = VERSION.split(".")
return (ver[0], ver[1], ver[2])


class CamillaClient(_CamillaWS):
Expand Down
71 changes: 38 additions & 33 deletions examples/playwav/analyze_wav.py
Original file line number Diff line number Diff line change
@@ -1,83 +1,88 @@
import struct
import logging

sampleformats = {1: "int",
sampleformats = {
1: "int",
3: "float",
}
}


def analyze_chunk(type, start, length, file, wav_info):
if type == "fmt ":
data = file.read(length)
wav_info['SampleFormat'] = sampleformats[struct.unpack('<H', data[0:2])[0]]
wav_info['NumChannels'] = struct.unpack('<H', data[2:4])[0]
wav_info['SampleRate'] = struct.unpack('<L', data[4:8])[0]
wav_info['ByteRate'] = struct.unpack('<L', data[8:12])[0]
wav_info['BytesPerFrame'] = struct.unpack('<H', data[12:14])[0]
wav_info['BitsPerSample'] = struct.unpack('<H', data[14:16])[0]
bytes_per_sample = wav_info['BytesPerFrame']/wav_info['NumChannels']
if wav_info['SampleFormat'] == "int":
if wav_info['BitsPerSample'] == 16:
wav_info["SampleFormat"] = sampleformats[struct.unpack("<H", data[0:2])[0]]
wav_info["NumChannels"] = struct.unpack("<H", data[2:4])[0]
wav_info["SampleRate"] = struct.unpack("<L", data[4:8])[0]
wav_info["ByteRate"] = struct.unpack("<L", data[8:12])[0]
wav_info["BytesPerFrame"] = struct.unpack("<H", data[12:14])[0]
wav_info["BitsPerSample"] = struct.unpack("<H", data[14:16])[0]
bytes_per_sample = wav_info["BytesPerFrame"] / wav_info["NumChannels"]
if wav_info["SampleFormat"] == "int":
if wav_info["BitsPerSample"] == 16:
sfmt = "S16LE"
elif wav_info['BitsPerSample'] == 24 and bytes_per_sample == 3:
elif wav_info["BitsPerSample"] == 24 and bytes_per_sample == 3:
sfmt = "S24LE3"
elif wav_info['BitsPerSample'] == 24 and bytes_per_sample == 4:
elif wav_info["BitsPerSample"] == 24 and bytes_per_sample == 4:
sfmt = "S24LE"
elif wav_info['BitsPerSample'] == 32:
elif wav_info["BitsPerSample"] == 32:
sfmt = "S32LE"
elif wav_info['SampleFormat'] == "float":
if wav_info['BitsPerSample'] == 32:
elif wav_info["SampleFormat"] == "float":
if wav_info["BitsPerSample"] == 32:
sfmt = "FLOAT32LE"
elif wav_info['BitsPerSample'] == 64:
elif wav_info["BitsPerSample"] == 64:
sfmt = "FLOAT64LE"
else:
sfmt = "unknown"
wav_info['SampleFormat'] = sfmt
wav_info["SampleFormat"] = sfmt
elif type == "data":
wav_info['DataStart'] = start
wav_info['DataLength'] = length
wav_info["DataStart"] = start
wav_info["DataLength"] = length


def read_wav_header(filename):
"""
"""
Reads the wav header to extract sample format, number of channels, and location of the audio data in the file
"""
logging.basicConfig(level=logging.DEBUG)
try:
file_in = open(filename, 'rb')
file_in = open(filename, "rb")
except IOError as err:
logging.debug("Could not open input file %s" % (filename))
return

# Read fixed header
buf_header = file_in.read(12)
# Verify that the correct identifiers are present
if (buf_header[0:4] != b"RIFF") or \
(buf_header[8:12] != b"WAVE"):
logging.debug("Input file is not a standard WAV file")
return
if (buf_header[0:4] != b"RIFF") or (buf_header[8:12] != b"WAVE"):
logging.debug("Input file is not a standard WAV file")
return

wav_info = {}

# Get file length
file_in.seek(0, 2) # Seek to end of file
file_in.seek(0, 2) # Seek to end of file
input_filesize = file_in.tell()

next_chunk_location = 12 # skip the fixed header
next_chunk_location = 12 # skip the fixed header
while True:
file_in.seek(next_chunk_location)
buf_header = file_in.read(8)
chunk_type = buf_header[0:4].decode("utf-8")
chunk_length = struct.unpack('<L', buf_header[4:8])[0]
logging.debug("Found chunk of type {}, length {}".format(chunk_type, chunk_length))
chunk_length = struct.unpack("<L", buf_header[4:8])[0]
logging.debug(
"Found chunk of type {}, length {}".format(chunk_type, chunk_length)
)
analyze_chunk(chunk_type, next_chunk_location, chunk_length, file_in, wav_info)
next_chunk_location += (8 + chunk_length)
next_chunk_location += 8 + chunk_length
if next_chunk_location >= input_filesize:
break
file_in.close()
return wav_info



if __name__ == "__main__":
import sys

info = read_wav_header(sys.argv[1])
print("Wav properties:")
for name, val in info.items():
Expand Down
2 changes: 1 addition & 1 deletion examples/playwav/play_wav.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
cfg["devices"]["capture_samplerate"] = wav_info["SampleRate"]
cfg["devices"]["enable_rate_adjust"] = False
if cfg["devices"]["samplerate"] != cfg["devices"]["capture_samplerate"]:
cfg["devices"]["resampler"] = { "type": "Synchronous" }
cfg["devices"]["resampler"] = {"type": "Synchronous"}
else:
cfg["devices"]["resampler"] = None
cfg["devices"]["capture"] = capt_device
Expand Down
1 change: 0 additions & 1 deletion examples/read_rms/read_rms.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,3 @@
while True:
print(cdsp.levels.playback_rms())
time.sleep(1)

5 changes: 3 additions & 2 deletions examples/set_volume/set_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
port = int(sys.argv[1])
new_vol = float(sys.argv[2])
except:
print("Usage: Make sure that your pipeline includes Volume filters for each channel.")
print(
"Usage: Make sure that your pipeline includes Volume filters for each channel."
)
print("Then start CamillaDSP with the websocket server enabled:")
print("> camilladsp -p4321 yourconfig.yml")
print("Then set the volume")
Expand All @@ -21,4 +23,3 @@
print(f"Current volume: {current_vol} dB")
print(f"Changing volume to: {new_vol} dB")
cdsp.volume.set_main(new_vol)

Loading

0 comments on commit 9567aa7

Please sign in to comment.