SPC, DSP "Pitch Height" conversion formula

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

Hey I am working to try and understand SPC programming. I'm working on an example taking a sample at one frequency and then using it to create a diatonic scale (ie "do re mi").

I understand all the .BRR playback stuff, but I am confused about the conversion of desired pitch in Hz to a 14-bit hex value.

The Snes Dev Manual http://www.romhacking.net/documents/226/ specifies this:

f = f0 * (P/2^12)

Where P pitch value for the SNES. f is "the frequency of the reproduced sound" and f0 is the "frequency of the original sound (sound at the time of recording)"


while the SPC700 reference http://wiki.superfamicom.org/snes/show/SPC700+Reference says this:

HZ = 32000 * (P/2^12)


My understanding from the SNES Dev Manual is that f0 is the actual frequency of the note (ie 440Hz for A), but the sfc wiki implies this is the sample rate.

I am at work so I can't test it out right now. Just curious if anyone knows offhand, and subsequently if the sfc wiki is incorrect.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by tepples »

"Frequency of the original sound" can refer to the note's own fundamental frequency or to the sample rate. If you apply it to fundamental frequency, you get the fundamental frequency of the other note. If you apply it to sample rate, you get the sample rate of the other note.
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

ha, duh. :oops: that makes total sense. Thanks for the clarification.

I understand you are talking about the relationship of samplerate to pitch but where as I can see the direct benefit of knowing the frequency (ie getting the pitch of a sample), why would you want to know the samplerate of a re-pitched sample? The only thing I can think of is maybe if there is a noise in the sample that is too high to be audible but could be heard at a lower samplerate
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by tepples »

You need to know the new sample rate in order to play the sample at a different pitch.
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

I am asking from the perspective of needing to know the Pitch value "p" that has to go into the DSP.
If you know the original pitch (assuming you recorded/created the sample) and the desired pitch in Hz which seems like it would be easier to find out, you'd have all you need to get the Pitch value to go into the DSP right? I'm confused about where or how you would need to know the new samplerate.

Let me know if I'm misunderstanding.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by tepples »

The pitch value is the new sample rate in units of 32000/4096 = 7.8125 Hz. If you apply it to sample rate in pitch value register units, you get the sample rate of the other note in pitch value register units.
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

I get the mechanics of the formula, I'm just curious what utility it would serve to know the actual new samplerate of the pitched sample (as opposed to the pitch, which you would need for music/chords etc).
lidnariq
Posts: 10677
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: SPC, DSP "Pitch Height" conversion formula

Post by lidnariq »

Not all things are tonal (e.g. sound effects), but you may still want to play them at other speeds; there's nothing to measure or compare except the sample rate.
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

Yeah the only thing that I could think of is something like that, if you had a sample you wanted to extent/"contract" to a specific amount of time the samplerate would be important.

Or if you had a sample with a very high pitched (like inaudible) component in the signal that would become part of the audible range if pitched down, or an LFO that would maybe make some weird noises if pitched up
User avatar
benjaminsantiago
Posts: 84
Joined: Mon Jan 20, 2014 9:40 pm
Location: Astoria, NY
Contact:

Re: SPC, DSP "Pitch Height" conversion formula

Post by benjaminsantiago »

Hey I got the reason why I created this post working in case you were curious.

Here is a link with the source code and smc. I tested it quickly on a clone system with an SNES Power Pak and it works on the hardware.

https://drive.google.com/file/d/0B4wfhZ ... sp=sharing

(I cleaned up the comments, some of it is a little ghetto and as of right now a lot of my code is hacked together from examples. It compiles with wla-65816 and the sound code compiles with TASM. I have included the TAB file because it seems like some versions of the table I've found do not work for me)
Post Reply