musikinformatik/SuperDirt

playing samples in tune using pitch metadata

ahihi opened this issue · 2 comments

ahihi commented

currently, playing samples tonally is quite cumbersome unless they are recorded at some standard pitch (C seems to be a common choice). what if we could tag sample files with a base pitch, have SuperDirt read that information and make it automatically repitch the samples to match incoming notes?

in fact i have already implemented this :) here is how it works:

  1. pitch metadata is added to WAV files in the form of MIDI unity note / MIDI pitch fraction fields of a smpl chunk, using a utility such as my pitcheon
  2. SuperDirt obtains the pitch metadata by parsing Soundfile.readHeaderAsString1
  3. for events containing a tune argument with value 1, frequency and sample duration are scaled relative to the obtained pitch metadata (tune defaults to 0, preserving the old behavior)

or, from the musician's perspective:

  1. i have a bunch of one-shot samples recorded at wildly mismatched pitches; i do d1 $ n "<0 1 2 3 4>*8" # s "mysamples" and it sounds terrible!
  2. i run pitcheon on my samples
  3. i restart SuperDirt, do d1 $ n "<0 1 2 3 4>*8" # s "mysamples" # pF "tune" 1, everything plays in a beautiful consonance of C, audience erupts into applause, i am booked for numerous high-paying gigs

...anyway, would you be interested in upstreaming this feature? my implementation probably has room for improvement but i would be happy to work out the details in a PR.

Footnotes

  1. this string is basically a log written by libsndfile. it would be nicer to access the raw data, not only for performance and regex-matching-ugly reasons but because libsndfile does some questionable math on the pitch info which i have to undo.

Good thing! Perhaps it could be quite a bit simpler? One could just add a multiplier that is derived from baseFreq / 440 and multiplied at the end?

ahihi commented

closing this now that the PR is merged 🥳