Skip to content

Commit

Permalink
add test file (#14)
Browse files Browse the repository at this point in the history
* add test file

* remove osx garbage

* update readme
  • Loading branch information
faroit authored Mar 13, 2019
1 parent 69e861a commit ee78d29
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 23 deletions.
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include tests/data/The Easton Ellises - Falcon 69.stem.mp4
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,15 @@ pip install stempeg

## Usage

There are very few freely available stem files. We [included](https://raw.githubusercontent.com/faroit/stempeg/master/tests/data/The%20Easton%20Ellises%20-%20Falcon%2069.stem.mp4) a small test track from the Canadian rock-band _The Easton Ellises_. The band [released them](https://www.heise.de/ct/artikel/c-t-Remix-Wettbewerb-The-Easton-Ellises-2542427.html) under Creative Commons license CC BY-NC-SA 3.0.
There are very few freely available stem files. We included a small test track from the Canadian rock-band _The Easton Ellises_. The band [released them](https://www.heise.de/ct/artikel/c-t-Remix-Wettbewerb-The-Easton-Ellises-2542427.html) under Creative Commons license CC BY-NC-SA 3.0.

To use the included stem example you can use `stempeg.example_stem_path()`.

### Reading stems

```python
import stempeg
S, rate = stempeg.read_stems("input.stem.mp4")
S, rate = stempeg.read_stems(stempeg.example_stem_path())
```

`S` is the stem tensor that includes the time domain signals scaled to `[-1..1]`. The shape is `(stems, samples, channels)`.
Expand All @@ -54,15 +56,15 @@ S, rate = stempeg.read_stems("input.stem.mp4")
you can read individual substreams of the stem file by passing the corresponding stem id (starting from 0):

```python
S, rate = stempeg.read_stems("input.stem.mp4", stem_id=[0, 1])
S, rate = stempeg.read_stems(stempeg.example_stem_path(), stem_id=[0, 1])
```

### Read excerpts (set seek position)

to read an excerpt from the stem instead of the full file, you can provide start (`start`) and duration (`duration`) in seconds to `read_stems`:

```python
S, _ = stempeg.read_stems("input.stem.mp4", start=1, duration=1.5)
S, _ = stempeg.read_stems(stempeg.example_stem_path(), start=1, duration=1.5)
# read from second 1.0 to second 2.5
```

Expand All @@ -71,8 +73,9 @@ S, _ = stempeg.read_stems("input.stem.mp4", start=1, duration=1.5)
if `read_stems` is called repeatedly, it always does two system calls, one for getting the [file info](https://github.com/faroit/stempeg/blob/a56349d2a8297ccf5db13712fc16048029503b26/stempeg/read.py#L120) and one for the [actual reading](https://github.com/faroit/stempeg/blob/a56349d2a8297ccf5db13712fc16048029503b26/stempeg/read.py#L160). To speed this up you could provide the `Info` object to `read_stems` if the number of streams, the number of channels and the samplerate is identical.

```python
info = stempeg.Info("input.stem.mp4")
S, _ = stempeg.read_stems("input.stem.mp4", info=info)
file_path = stempeg.example_stem_path()
info = stempeg.Info(file_path)
S, _ = stempeg.read_stems(file_path, info=info)
```

### Writing stems
Expand All @@ -92,5 +95,5 @@ _stempeg_ provides a convenient cli tool to convert a stem to multiple wavfiles.


```bash
stem2wav tests/data/The Easton Ellises - Falcon 69.stem.mp4 -s 1.0 -t 2.5
stem2wav The Easton Ellises - Falcon 69.stem.mp4 -s 1.0 -t 2.5
```
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='stempeg',
version='0.1.5',
version='0.1.6',
description='Read and write stem multistream audio files',
long_description=long_description,
long_description_content_type='text/markdown',
Expand Down Expand Up @@ -55,4 +55,5 @@
project_urls={ # Optional
'Bug Reports': 'https://github.com/faroit/stempeg/issues',
},
)
include_package_data=True
)
17 changes: 16 additions & 1 deletion stempeg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,23 @@
from os import path as op
import soundfile as sf
import argparse
import pkg_resources

__version__ = "0.1.5"
__version__ = "0.1.6"


def example_stem_path():
"""Get the path to an included stem file.
Returns
-------
filename : str
Path to the stem file
"""
return pkg_resources.resource_filename(
__name__,
'data/The Easton Ellises - Falcon 69.stem.mp4'
)


def ffmpeg_version():
Expand Down
16 changes: 6 additions & 10 deletions tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,24 @@ def duration(request):


def test_stem_id():
S, _ = stempeg.read_stems(
"tests/data/The Easton Ellises - Falcon 69.stem.mp4"
)
S, _ = stempeg.read_stems(stempeg.example_stem_path())
for k in range(S.shape[0]):
Sk, _ = stempeg.read_stems(
"tests/data/The Easton Ellises - Falcon 69.stem.mp4",
stempeg.example_stem_path(),
stem_id=k
)
assert Sk.ndim == 2


def test_shape():
S, _ = stempeg.read_stems(
"tests/data/The Easton Ellises - Falcon 69.stem.mp4"
)
S, _ = stempeg.read_stems(stempeg.example_stem_path())
assert S.shape[0] == 5
assert ((S.shape[1] % 1024) == 0 and S.shape[1] > 200000)
assert S.shape[2] == 2


def test_duration(start, duration):
fp = "tests/data/The Easton Ellises - Falcon 69.stem.mp4"
fp = stempeg.example_stem_path()
info = stempeg.Info(fp)
if start:
if start < min(info.duration_streams):
Expand All @@ -60,13 +56,13 @@ def test_duration(start, duration):

def test_outtype(dtype):
S, rate = stempeg.read_stems(
"tests/data/The Easton Ellises - Falcon 69.stem.mp4",
stempeg.example_stem_path(),
out_type=dtype
)
assert S.dtype == dtype


def test_info():
fp = "tests/data/The Easton Ellises - Falcon 69.stem.mp4"
fp = stempeg.example_stem_path()
info = stempeg.Info(fp)
S, rate = stempeg.read_stems(fp, info=info)
4 changes: 1 addition & 3 deletions tests/test_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,5 @@


def test_write():
S, rate = stempeg.read_stems(
"tests/data/The Easton Ellises - Falcon 69.stem.mp4"
)
S, rate = stempeg.read_stems(stempeg.example_stem_path())
stempeg.write_stems(S, "./stems.mp4")

0 comments on commit ee78d29

Please sign in to comment.