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

A few useful additions to wavfile.py (24 bit read/write support, cue markers support, loop makers support, etc.) #6849

Open
josephernest opened this Issue Dec 11, 2016 · 11 comments

Comments

Projects
None yet
5 participants
@josephernest

josephernest commented Dec 11, 2016

I've modified the file https://github.com/scipy/scipy/blob/master/scipy/io/wavfile.py over the past years to add 24-bit WAV files read/write support, cue markers support, loop makers support, etc.

Here is the result.

If you're interested, feel free to reuse this / commit (I won't have time to do a pull request soon).

Note: In WAV audio files, 24-bit is probably the most used bitrate for instrument sample sets, music production, sound engineering; much more than 16-bit (CD) or 32-bit (used in music software as internal processing bitrate).

@rgommers

This comment has been minimized.

Member

rgommers commented Dec 12, 2016

Thanks @josephernest. 24-bit support would indeed be nice. cross-linking the issue about that: gh-1930.

@josephernest

This comment has been minimized.

josephernest commented Dec 12, 2016

Thanks @rgommers
I use my code (especially 24-bit part) in many of my projects, and I confirm that it works and has been widely tested.


More informations:

Normally wavfile.py works like this:

(sr, samples) = read('hello.wav')

To keep backwards compatibility, I added parameters (default False) that state if we want extra metadatas while reading (br: bitrate, cue: list of markers, f0: frequency of the root note in Hz stored in some wav files (often the case in instrument sample sets), etc.):

(sr, samples, br, cue, f0, cuechunkstr, smplchunkstr, cuelabels) = read('hello.wav', \
   readmarkers=True, readpitch=True, cuechunk=True, smplchunk=True, cuelabels=True)

Drawbacks of my code:

  • not documented

  • to go fast, I removed RIFX support (I have never seen a single RIFX big-endian WAV audio file in 10+ years of audio production / audio programming), you probably wouldn't like this

So in short, I'm open to do a pull request, but I'd need help :)

@perimosocordiae

This comment has been minimized.

Member

perimosocordiae commented Dec 12, 2016

@josephernest I got this started in gh-6852. Could you contribute a small test file that exercises the additional functionality?

@josephernest

This comment has been minimized.

josephernest commented Dec 12, 2016

Here is a 24-bit 44.1 khz stereo WAV file named test24bit.wav. It has:

  • a marker at 0'04", another marker at 0'08"
  • an infinite loop from 0'12" to 0'16"
  • a pitch metadata of A5 (Sony SoundForge notation) that is the standard A4, i.e. 440 Hz

With my API proposal here,

read('test24bit.wav', metadata=True)

should return:

(44100, 
 array([[  ...  ]]), 
 {'loops': [[..., ...]], 
  'markers': [..., ....], 
  'markerlabels': ['...', '...'], 
  'pitch': 440.0, 
  'bitrate': 24})
@perimosocordiae

This comment has been minimized.

Member

perimosocordiae commented Dec 12, 2016

Thanks, no git shenanigans required! The test file you provided is pretty large (5.1MB vs a couple KB for most of the existing test fixtures). Is it possible to make a similar one with a tiny amount of data to keep filesize low?

@josephernest

This comment has been minimized.

josephernest commented Dec 12, 2016

Here is a small test file. I won't go below 250 milliseconds, because testing if a loop works wouldn't make sense with a 10 ms sound file.
Markers at 0.100 sec and 0.200 sec. Loop between 0.050 and 0.150 sec. A4 440 hz pitch metadata.

@perimosocordiae

This comment has been minimized.

Member

perimosocordiae commented Dec 12, 2016

Great, I've added this to the PR as a new test fixture. Thanks!

@josephernest

This comment has been minimized.

josephernest commented Dec 12, 2016

Thanks!

@X-Raym

This comment has been minimized.

X-Raym commented Jun 10, 2018

The write function for loops was broken, and few other things with markers,

I made an updated version here https://github.com/X-Raym/wavfile.py

It also fix various issues, like the loss of metadata (unsupported chinks are now supported), have LIST - INFO etc...

@ilayn

This comment has been minimized.

Member

ilayn commented Jun 10, 2018

@X-Raym Would you care to open a Pull Request for a more general audience? Then interested people can review and leave comments. Also your code can be tested against the existing codebase for regressions.

@X-Raym

This comment has been minimized.

X-Raym commented Jun 10, 2018

@ilayn I will make further testing on my own, to be sure it works ok, and I'll do that, maybe in few days. Still, the script can be tested for those who needed (just download it from my repo).

My own version may not respect Scipy conventions, as I don't know a lot of thing about it, apart from the original wavfile.py file. And just like Joseph code, I didn't write any updated usage doc for now.

Thanks for your interest interest, I hope this will help make these features (especially 24bit support brought by @josephernest and unsupported chunks read/write I made) be merged in your project 🐱

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment