From b72b70e54c2b5a0e80a48926e437a51dc44a9256 Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Fri, 28 Jul 2017 16:19:44 +0800 Subject: [PATCH] add soundfile read/write unitest --- .gitignore | 1 - setup.sh | 24 +++++++++++++----------- tests/test_setup.py | 15 +++++++++++++-- 3 files changed, 26 insertions(+), 14 deletions(-) delete mode 100644 .gitignore diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 0e0f559f..00000000 --- a/.gitignore +++ /dev/null @@ -1 +0,0 @@ -thirdparty diff --git a/setup.sh b/setup.sh index 854f879e..4d451a6f 100644 --- a/setup.sh +++ b/setup.sh @@ -10,19 +10,21 @@ if [ $? != 0 ]; then fi # install package libsndfile -DIR="$( cd "$(dirname "$0")" ; pwd -P )" -mkdir thirdparty -curl -O "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.28.tar.gz" +python -c "import soundfile" if [ $? != 0 ]; then - echo "Download libsndfile-1.0.28.tar.gz failed !!!" - exit 1 + echo "Install package libsndfile into default system path." + curl -O "http://www.mega-nerd.com/libsndfile/files/libsndfile-1.0.28.tar.gz" + if [ $? != 0 ]; then + echo "Download libsndfile-1.0.28.tar.gz failed !!!" + exit 1 + fi + tar -zxvf libsndfile-1.0.28.tar.gz + cd libsndfile-1.0.28 + ./configure && make && make install + cd .. + rm -rf libsndfile-1.0.28 + rm libsndfile-1.0.28.tar.gz fi -tar -zxvf libsndfile-1.0.28.tar.gz -cd libsndfile-1.0.28 -./configure --prefix=$DIR/thirdparty/libsndfile && make && make install -cd .. -rm -rf libsndfile-1.0.28 -rm libsndfile-1.0.28.tar.gz # prepare ./checkpoints mkdir checkpoints diff --git a/tests/test_setup.py b/tests/test_setup.py index bd6fabb0..71a46afb 100644 --- a/tests/test_setup.py +++ b/tests/test_setup.py @@ -1,11 +1,22 @@ """Test Setup.""" import unittest +import numpy as np +import os class TestSetup(unittest.TestCase): - # test the installation of libsndfile library def test_soundfile(self): - import soundfile + import soundfile as sf + # floating point data is typically limited to the interval [-1.0, 1.0], + # but smaller/larger values are supported as well + data = np.array([[1.75, -1.75], [1.0, -1.0], [0.5, -0.5], + [0.25, -0.25]]) + file = 'test.wav' + sf.write(file, data, 44100, format='WAV', subtype='FLOAT') + read, fs = sf.read(file) + assert np.all(read == data) + assert fs == 44100 + os.remove(file) if __name__ == '__main__':