-
Notifications
You must be signed in to change notification settings - Fork 108
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add seeking to rawread and macca, and tests #73
Open
pconerly
wants to merge
5
commits into
beetbox:main
Choose a base branch
from
pconerly:seeking
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
*.pyc | ||
.DS_Store | ||
|
||
.tox/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import mad | ||
import os | ||
tf = os.path.abspath(os.path.join('test', 'fixtures', 'wavetest.wav')) | ||
|
||
fp = open(tf, 'rb') | ||
mf = mad.MadFile(fp) | ||
|
||
print('mf.total_time', mf.total_time()) | ||
print(mf.read()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import unittest | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
loader = unittest.TestLoader() | ||
tests = loader.discover('test') | ||
testRunner = unittest.runner.TextTestRunner() | ||
result = testRunner.run(tests) | ||
if not result.wasSuccessful(): | ||
sys.exit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
Audio file fixtures for the tests. | ||
|
||
#### test.wav | ||
Test.wav was produced by doing: | ||
|
||
```py | ||
import numpy as np | ||
from scipy.io import wavfile | ||
|
||
if __name__ == '__main__': | ||
size = 512 | ||
a = np.full((size, ), 0.) | ||
b = np.full((size, ), 0.2) | ||
c = np.full((size, ), 0.5) | ||
d = np.full((size, ), 0.9) | ||
t = np.concatenate((a, b, c, d)) | ||
|
||
wavfile.write('test.wav', 44100, t) | ||
``` | ||
|
||
#### wavetest.wav | ||
|
||
Produced with `make_test_wave.py` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import numpy as np | ||
import wave | ||
import struct | ||
|
||
def getData(): | ||
size = 512 | ||
|
||
a = np.full((size, ), 0., dtype=np.float16) | ||
b = np.full((size, ), 0.2, dtype=np.float16) | ||
c = np.full((size, ), 0.5, dtype=np.float16) | ||
d = np.full((size, ), 0.9, dtype=np.float16) | ||
return np.concatenate((a, b, c, d)) | ||
|
||
|
||
if __name__ == '__main__': | ||
fout = wave.open('test/fixtures/wavetest.wav', 'w') | ||
data = getData() | ||
fout.setnchannels(1) | ||
fout.setframerate(44100) | ||
fout.setsampwidth(2) | ||
fout.writeframes(data.tobytes()) | ||
fout.close() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import os | ||
import unittest | ||
import audioread | ||
|
||
numSamples = 512 | ||
|
||
testFilename = os.path.abspath(os.path.join('test', 'fixtures', 'wavetest.wav')) | ||
rowLookup = [ | ||
b'\x00\x00', | ||
b'f2', | ||
b'\x008', | ||
b'3;', | ||
] | ||
|
||
class TestAudioreadWav(unittest.TestCase): | ||
|
||
def test_audio_open_as_generator(self): | ||
result = [] | ||
with audioread.audio_open(testFilename, block_samples=numSamples) as f: | ||
print('wav decode class', f.__class__) | ||
gen = f.read_data() | ||
try: | ||
while True: | ||
data = next(gen) | ||
result.append(data) | ||
except StopIteration: | ||
pass | ||
|
||
self.assertEqual(len(bytes(result[0])), numSamples*2) | ||
self.assertEqual(len(rowLookup), len(result)) | ||
for i, row in enumerate(result): | ||
self.assertEqual(bytes(row[0:2]), rowLookup[i]) | ||
|
||
|
||
def test_audio_open_as_forloop(self): | ||
result = [] | ||
with audioread.audio_open(testFilename, block_samples=numSamples) as f: | ||
self.assertEqual(f.nframes, 2048) | ||
for buf in f: | ||
result.append(buf) | ||
|
||
self.assertEqual(len(bytes(result[0])), numSamples*2) | ||
self.assertEqual(len(rowLookup), len(result)) | ||
for i, row in enumerate(result): | ||
self.assertEqual(bytes(row[0:2]), rowLookup[i]) | ||
|
||
|
||
mp3TestFilename = os.path.abspath(os.path.join('test', 'fixtures', 'sample.mp3')) | ||
mp3RowLookup = [ | ||
b'\x00\x00', | ||
b'\x00\x00', | ||
b'N\xff', | ||
b'\xe8/', | ||
b'.5', | ||
b'\x089', | ||
b'\x00\x00', | ||
] | ||
|
||
class TestAudioreadMp3(unittest.TestCase): | ||
|
||
def test_audio_open_as_generator(self): | ||
result = [] | ||
with audioread.audio_open(mp3TestFilename, block_samples=numSamples) as f: | ||
print('Mp3 decode class', f.__class__) | ||
gen = f.read_data() | ||
try: | ||
while True: | ||
data = next(gen) | ||
result.append(data) | ||
except StopIteration: | ||
pass | ||
|
||
self.assertEqual(len(bytes(result[0])), numSamples*2) | ||
self.assertEqual(len(mp3RowLookup), len(result)) | ||
for i, row in enumerate(result): | ||
self.assertEqual(bytes(row[0:2]), mp3RowLookup[i]) | ||
|
||
|
||
def test_audio_open_as_forloop(self): | ||
result = [] | ||
with audioread.audio_open(mp3TestFilename, block_samples=numSamples) as f: | ||
# self.assertEqual(f.nframes, 4) | ||
for buf in f: | ||
result.append(buf) | ||
|
||
self.assertEqual(len(bytes(result[0])), numSamples*2) | ||
self.assertEqual(len(mp3RowLookup), len(result)) | ||
for i, row in enumerate(result): | ||
self.assertEqual(bytes(row[0:2]), mp3RowLookup[i]) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a little confusing that there are files called
test.wav
andwavtest.wav
. Maybe it would be useful to describe what each one is for, and how they're different?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm using
test.wav
for themacca
backend--- I'll find some better names for it. We also might not need both