Skip to content
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

playing samples in tune using pitch metadata #273

Closed
ahihi opened this issue Jun 26, 2022 · 2 comments
Closed

playing samples in tune using pitch metadata #273

ahihi opened this issue Jun 26, 2022 · 2 comments

Comments

@ahihi
Copy link
Contributor

ahihi commented Jun 26, 2022

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.

@telephon
Copy link
Contributor

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
Copy link
Contributor Author

ahihi commented Oct 11, 2023

closing this now that the PR is merged 🥳

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants