Skip to content

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
cleanup

cleanup

enhance plots

plot labels

cleanup test

meta

cleanup unused
  • Loading branch information
scivision committed Jan 6, 2019
1 parent e53ace4 commit e822005
Show file tree
Hide file tree
Showing 11 changed files with 183 additions and 240 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
image:
- Visual Studio 2017
- Ubuntu
- Ubuntu1804

stack: python 3

Expand Down
35 changes: 21 additions & 14 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: python
sudo: required
dist: xenial
group: travis_latest
dist: xenial

git:
depth: 3
Expand All @@ -11,20 +10,28 @@ python:
- 3.6
- 3.7

os:
- linux
matrix:
include:
- os: linux
python: 3.7
install: pip install -e .[tests,cov]
script:
- flake8
- mypy . --ignore-missing-imports
after_success:
- pytest --cov --cov-config=setup.cfg
- coveralls
- os: osx
language: sh
install: pip3 install -e .[tests]
- os: windows
language: sh
before_install:
- choco install python3
- export PATH="/c/Python37:/c/Python37/Scripts:$PATH"


install: pip install -e .[tests]

script:
- pytest -rsv
- flake8
- mypy . --ignore-missing-imports

after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then
pytest --cov --cov-config=setup.cfg;
coveralls;
fi
script: pytest -rsv

47 changes: 3 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
[![image](https://coveralls.io/repos/scivision/soothing-sounds/badge.svg)](https://coveralls.io/r/scivision/soothing-sounds)
[![Build status](https://ci.appveyor.com/api/projects/status/bg0wym66ousyk657?svg=true)](https://ci.appveyor.com/project/scivision/soothing-sounds)
[![pypi versions](https://img.shields.io/pypi/pyversions/soothingsounds.svg)](https://pypi.python.org/pypi/soothingsounds)
[![pypi format](https://img.shields.io/pypi/format/soothingsounds.svg)](https://pypi.python.org/pypi/soothingsounds)
[![PyPi Download stats](http://pepy.tech/badge/soothingsounds)](http://pepy.tech/project/soothingsounds)

# Soothing Sounds Generator
Expand Down Expand Up @@ -49,47 +48,7 @@ The core noise generation code is almost entirely from

### optional high performance Python FFTW install:

sudo apt-get install libfftw3-dev
### Optional PyAudio
```sh
apt install libfftw3-dev
```

* Linux: `apt install portaudio19-dev libjack-dev libjack0`
* Mac: ` brew install portaudio`

and then:

pip install pyaudio


### Optional Pygame

Pick one of the following methods to install pygame

#### pip

simplest way for PCs, but may require compiling for ARM CPU:

pip install pygame

#### Linux distro
For ARM CPU, this is the best choice generally for PyGame.

apt install python-pygame

#### compile Pygame via pip
Usually you don't want to bother with this

apt install mercurial libflac-dev libmad0-dev libmikmod2-dev libogg-dev libportmidi-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev libsmpeg-dev libvorbis-dev libwebp-dev libwebpdemux1 sharutils libswscale-dev libavformat-dev

pip install hg+http://bitbucket.org/pygame/pygame


cd /tmp

hg clone http://bitbucket.org/pygame/pygame

cd /tmp/pygame

python setup.py build

python setup.py install
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = soothingsounds
version = 1.0.0
version = 1.0.1
author = Michael Hirsch, Ph.D.
description = Generate a variety of white/brown/pink noises good for relaxation
url = https://github.com/scivision/soothing-sounds
Expand All @@ -9,6 +9,8 @@ keywords =
white noise
brown noise
pink noise
blue noise
violet noise
relaxation
classifiers =
Development Status :: 5 - Production/Stable
Expand Down
29 changes: 21 additions & 8 deletions soothing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,26 @@
"""
from time import sleep
import soothingsounds as ss
from soothingsounds.plots import plotspectrogram
from matplotlib.pyplot import show
from argparse import ArgumentParser
try:
import soothingsounds.plots as plots
from matplotlib.pyplot import show
except (ImportError, RuntimeError):
show = None

soundmod = 'sounddevice' # 'pygame'#'pyglet'#'pyaudio' #'pygame' #'scikits.audiolab'
wavapi = 'raw' # 'skaudio' #'scipy'

nbitfile = 16
nbitfloat = 32 # from generator.py

if __name__ == '__main__':
from argparse import ArgumentParser

def main():
P = ArgumentParser(description="noise generation program for Raspberry Pi or any Python-capable computer")
P.add_argument('nmode', help='what type of white noise [white, pink, brown...]', nargs='?', default='pink')
P.add_argument(
'hours', help='how many hours do you want sound generated for [default=8 hours]', type=float, nargs='?', default=8)
P.add_argument('hours',
help='how many hours do you want sound generated for [default=8 hours]',
type=float, nargs='?', default=8)
P.add_argument('-fs', help='sampling freq e.g. 16000 or 44100', type=int, default=16000)
P.add_argument('-o', '--ofn', help='output .wav filename')
P.add_argument('-nsec', help='length of unique noise sequence [seconds]', type=float, default=60)
Expand All @@ -54,9 +59,17 @@
ss.liveplay(samps, p.hours, p.fs, p.nsec, soundmod)
sleep(p.nsec) # for async playback, else sound doesn't play
except Exception as e:
raise RuntimeError('could not play live sound. Consider just saving to disk and using an SD card. {}'.format(e))
raise RuntimeError(f'could not play live sound. Consider just saving to disk and using an SD card. {e}')
else:
ss.savenoise(samps, p.hours, p.ofn, p.fs, p.nsec, wavapi)
plotspectrogram(samps, p.fs, p.nmode)

if show is not None:
plots.time(samps, p.fs, p.nmode)
plots.plotpsd(samps, p.fs, p.nmode)
# plots.plotspectrogram(samps, p.fs, p.nmode)

show()


if __name__ == '__main__':
main()
12 changes: 7 additions & 5 deletions soothingsounds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
from .generator import noise


def computenoise(ntype: str, fs: int, nsec: int, nbitfloat: int, nbitfile: int) -> np.ndarray:
def computenoise(ntype: str, fs: int, nsec: int,
nbitfloat: int, nbitfile: int,
verbose: bool = False) -> np.ndarray:
nsamp = int(fs*nsec)
ramused = nsamp*nbitfloat//8 # bytes, assuming np.float32, does NOT account for copies!
if ramused > 128e6:
Expand All @@ -26,13 +28,13 @@ def computenoise(ntype: str, fs: int, nsec: int, nbitfloat: int, nbitfile: int)
# TODO arbitary scaling to 16-bit, noise() outputs float64
samps = (noise(nsamp, color=ntype) * 32768 / 8).astype(np.int16)

print(f'it took {time()-tic:.2f} seconds to compute {nsec:.0f} sec. of {ntype:s} noise.')
print(f'max sample value {samps.max():.0f}')
if verbose:
print(f'it took {time()-tic:.2f} seconds to compute {nsec:.0f} sec. of {ntype:s} noise.')

return samps


def liveplay(samps: np.ndarray, nhours: int, fs: int, nsec: int, soundmod: str='sounddevice'):
def liveplay(samps: np.ndarray, nhours: int, fs: int, nsec: int, soundmod: str = 'sounddevice'):
smod: Any = importlib.import_module(soundmod)

if soundmod == 'sounddevice':
Expand All @@ -55,7 +57,7 @@ def liveplay(samps: np.ndarray, nhours: int, fs: int, nsec: int, soundmod: str='
elif soundmod == 'scikit.audiolab': # pragma: no cover
smod.play(samps)
elif soundmod == 'pyglet': # pragma: no cover
raise NotImplementedError('pyglet not yet implemented')
raise NotImplementedError('pyglet not implemented')
# """
# http://www.pyglet.org/doc-current/api/pyglet/media/pyglet.media.AudioFormat.html#pyglet.media.AudioFormat
# """
Expand Down
Loading

0 comments on commit e822005

Please sign in to comment.