Skip to content

Commit

Permalink
Merge pull request #11 from sonos/develop
Browse files Browse the repository at this point in the history
Merge to main - v2.0.0
  • Loading branch information
conorsleithsonos authored Jul 20, 2021
2 parents 4516397 + 3c27540 commit 9bfba05
Show file tree
Hide file tree
Showing 22 changed files with 229 additions and 73 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install tox tox-gh-actions
pip install coverage
- name: Run tests
run: tox
run: coverage run setup.py test
- name: Run coveralls
uses: AndreMiras/coveralls-python-action@v20201129
with:
parallel: true
flag-name: unittest

macos:
runs-on: macos-latest
Expand All @@ -58,3 +63,12 @@ jobs:
submodules: recursive
- name: Check install
run: python setup.py install

coverage:
needs: linux
runs-on: ubuntu-latest
steps:
- name: coveralls
uses: AndreMiras/coveralls-python-action@v20201129
with:
parallel-finished: true
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ dmypy.json
# VSCode
.vscode/

# PyCharm
.idea/

# macOS
.DS_Store

Expand All @@ -143,4 +146,4 @@ dmypy.json
*.flac

# Development
.archive
.archive
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
pyFLAC Changelog
----------------

**v2.0.0**

* Added `seek` and `tell` callbacks to `StreamEncoder`
* Renamed the write callbacks from `callback` to `write_callback` for `StreamEncoder` and `StreamDecoder`

**v1.0.0**

* Added a `StreamEncoder` to compress raw audio data on-the-fly into a FLAC byte stream
Expand Down
28 changes: 18 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
pyFLAC
======

.. image:: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/lint.yml/badge.svg
:target: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/lint.yml
.. image:: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/test.yml/badge.svg
:target: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/test.yml
.. image:: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/build.yml/badge.svg
:target: https://github.com/Sonos-Inc/pyFLAC/actions/workflows/build.yml
.. image:: https://img.shields.io/pypi/pyversions/pysoundio
.. image:: https://raw.githubusercontent.com/sonos/pyFLAC/develop/assets/logo-white-background.jpg
:target: https://pyflac.readthedocs.io

.. image:: https://github.com/sonos/pyFLAC/actions/workflows/lint.yml/badge.svg
:target: https://github.com/sonos/pyFLAC/actions/workflows/lint.yml
.. image:: https://github.com/sonos/pyFLAC/actions/workflows/test.yml/badge.svg
:target: https://github.com/sonos/pyFLAC/actions/workflows/test.yml
.. image:: https://github.com/sonos/pyFLAC/actions/workflows/build.yml/badge.svg
:target: https://github.com/sonos/pyFLAC/actions/workflows/build.yml
.. image:: https://coveralls.io/repos/github/sonos/pyFLAC/badge.svg
:target: https://coveralls.io/github/sonos/pyFLAC
.. image:: https://readthedocs.org/projects/pyflac/badge
:target: https://pyflac.readthedocs.io/en/latest/
.. image:: https://badge.fury.io/py/pyFLAC.svg
:target: https://badge.fury.io/py/pyFLAC
.. image:: https://img.shields.io/pypi/pyversions/pyFLAC
:target: https://pypi.org/project/pyFLAC

-------------------------------------------------------------------

A simple Pythonic interface for `libFLAC <https://xiph.org/flac>`_.

FLAC stands for Free Lossless Audio Codec, an audio format similar to MP3, but lossless,
Expand Down
Binary file added assets/icon-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/icon-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-white-background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-white-wide.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/logo-white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions docs/_static/custom.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.wy-nav-content {
max-width: 960px !important;
}
16 changes: 13 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,25 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))


# -- Project information -----------------------------------------------------

project = 'pyFLAC'
copyright = '2021, Sonos, Inc'
author = 'Joe Todd'


# -- General configuration ---------------------------------------------------

autodoc_mock_imports = [
'numpy',
'soundfile',
'pyflac._encoder',
'pyflac._decoder'
]

# If your documentation needs a minimal Sphinx version, state it here.
#
needs_sphinx = '1.3' # for napoleon
Expand Down Expand Up @@ -83,10 +89,14 @@
# further. For a list of options available for each theme, see the
# documentation.
html_theme_options = {
'collapse_navigation': False
'collapse_navigation': False,
}

# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']

html_css_files = [
'custom.css',
]
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
cffi
Sphinx
sphinx-rtd-theme
4 changes: 2 additions & 2 deletions examples/passthrough.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ def __init__(self, args):
self.data, self.sr = sf.read(args.input_file, dtype='int16', always_2d=True)

self.encoder = pyflac.StreamEncoder(
callback=self.encoder_callback,
write_callback=self.encoder_callback,
sample_rate=self.sr,
blocksize=args.block_size,
)

self.decoder = pyflac.StreamDecoder(
callback=self.decoder_callback
write_callback=self.decoder_callback
)

def encode(self):
Expand Down
2 changes: 1 addition & 1 deletion examples/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __init__(self, args, stream):
self.num_channels = stream.channels
self.sample_size = stream.samplesize

self.encoder = pyflac.StreamEncoder(callback=self.encoder_callback,
self.encoder = pyflac.StreamEncoder(write_callback=self.encoder_callback,
sample_rate=int(stream.samplerate),
compression_level=args.compression_level)

Expand Down
2 changes: 1 addition & 1 deletion pyflac/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# ------------------------------------------------------------------------------

__title__ = 'pyFLAC'
__version__ = '1.0.0-beta.2'
__version__ = '2.0.0'
__all__ = [
'StreamEncoder',
'FileEncoder',
Expand Down
1 change: 1 addition & 0 deletions pyflac/builder/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, uint32_t value);
FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, uint32_t value);
FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
// GETTERS
FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
Expand Down
12 changes: 6 additions & 6 deletions pyflac/decoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class StreamDecoder(_Decoder):
the `callback`.
Args:
callback (fn): Function to call when there is uncompressed
write_callback (fn): Function to call when there is uncompressed
audio data ready, see the example below for more information.
Examples:
Expand Down Expand Up @@ -154,12 +154,12 @@ def callback(self,
DecoderInitException: If initialisation of the decoder fails
"""
def __init__(self,
callback: Callable[[np.ndarray, int, int, int], None]):
write_callback: Callable[[np.ndarray, int, int, int], None]):
super().__init__()

self._done = False
self._buffer = deque()
self.callback = callback
self.write_callback = write_callback

rc = _lib.FLAC__stream_decoder_init_stream(
self._decoder,
Expand Down Expand Up @@ -250,7 +250,7 @@ def __init__(self,
super().__init__()

self.__output = None
self.callback = self._callback
self.write_callback = self._write_callback
if output_file:
self.__output_file = output_file
else:
Expand Down Expand Up @@ -291,7 +291,7 @@ def process(self) -> Tuple[np.ndarray, int]:
self.__output.close()
return sf.read(str(self.__output_file), always_2d=True)

def _callback(self, data: np.ndarray, sample_rate: int, num_channels: int, num_samples: int):
def _write_callback(self, data: np.ndarray, sample_rate: int, num_channels: int, num_samples: int):
"""
Internal callback to write the decoded data to a WAV file.
"""
Expand Down Expand Up @@ -418,7 +418,7 @@ def _write_callback(_decoder,
np.frombuffer(cbuffer, dtype='int32').astype(np.int16)
)
output = np.column_stack(channels)
decoder.callback(
decoder.write_callback(
output,
int(frame.header.sample_rate),
int(frame.header.channels),
Expand Down
Loading

0 comments on commit 9bfba05

Please sign in to comment.