SPC, DSP "Pitch Height" conversion formula
Moderator: Moderators
Forum rules
- For making cartridges of your Super NES games, see Reproduction.
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
SPC, DSP "Pitch Height" conversion formula
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.
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.
Re: SPC, DSP "Pitch Height" conversion formula
"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.
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
Re: SPC, DSP "Pitch Height" conversion formula
ha, duh.
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
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
Re: SPC, DSP "Pitch Height" conversion formula
You need to know the new sample rate in order to play the sample at a different pitch.
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
Re: SPC, DSP "Pitch Height" conversion formula
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.
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.
Re: SPC, DSP "Pitch Height" conversion formula
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.
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
Re: SPC, DSP "Pitch Height" conversion formula
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).
Re: SPC, DSP "Pitch Height" conversion formula
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.
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
Re: SPC, DSP "Pitch Height" conversion formula
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
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
- benjaminsantiago
- Posts: 84
- Joined: Mon Jan 20, 2014 9:40 pm
- Location: Astoria, NY
- Contact:
Re: SPC, DSP "Pitch Height" conversion formula
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)
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)