Detuned DPCM Samples - FamiTracker

# FamiTracker

FamiTracker Support Forums

Skip to content

## Detuned DPCM Samples

General discussion about tracking, help and support.
Post Reply

- Print view

10 posts • Page 1 of 1

BioMechanicalDude
  Posts: 309
  Joined: Sun May 24, 2015 2:54 pm
  Location: Bulgaria

### Detuned DPCM Samples

- Quote

Post by BioMechanicalDude » Sun Oct 25, 2015 12:17 pm

So for a while, I've been experimenting with DPCM bass, but only now I've noticed, that something is wrong. I'm using a basic saw wave for the DPCM, created in Audacity. While working on the latest project, something felt off. The Lead and Bass melodies aren't harmonic. They sound off. So I made a test, where both a Square Wave channel and the DPCM channel play the same note at the same time. Normally the two sounds would mix and create a new timbre. But instead of sound mixing, there was chorusing. The DPCM samples are detuned. Now, at first I thought this is because note frequencies on NES can be very specific. For example, a B note would play at 246.9416506Hz. Tone generation in Audacity can't go that far, so it outputs only 246.942Hz. Then I tried playing an A-1 note, which is exactly 110 Hz and there was still detuning! Messing around with the Pxx effect on the Square wave channel also didn't help.
So can someone explain to me what's going on? Do .wav files get slightly detuned, when being imported into Famitracker? Admittedly, the A-1 note on the DPCM channel was actually an A-2, playing at pitch 12, so does that mean, that repitching will alter the notes' frequencies differently, than what one would expect? If so, how can I work around this?
Thanks.
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
Top

HertzDevil
  Posts: 475
  Joined: Thu Apr 23, 2015 7:39 pm
  Location: Hong Kong SAR
  Contact:
  Contact HertzDevil
  Website Facebook Twitter Skype
  YouTube

### Re: Detuned DPCM Samples

- Quote

Post by HertzDevil » Sun Oct 25, 2015 12:28 pm

How long is the DPCM sample and how many oscillations does it have?

> BioMechanicalDude wrote:Now, at first I thought this is because note frequencies on NES can be very specific. For example, a B note would play at 246.9416506Hz.

(1789772) ÷ 16 ÷ (0x1C4 + 1) = 246.9333233 Hz. A-1 gives (1789772) ÷ 16 ÷ (0x3F8 + 1) = 109.9909493.
Pitch 12 is also not at exactly half the frequency of pitch 15.
refactoring 0cc-famitracker
Top

BioMechanicalDude
  Posts: 309
  Joined: Sun May 24, 2015 2:54 pm
  Location: Bulgaria

### Re: Detuned DPCM Samples

- Quote

Post by BioMechanicalDude » Sun Oct 25, 2015 1:39 pm

> HertzDevil wrote:How long is the DPCM sample and how many oscillations does it have?

0.25 seconds long and with around 55 oscillations. Also, it has been put through a high-pass filter with a cut-off frequency of 500Hz, though I don't think changing the timbre will affect the frequency.

> HertzDevil wrote:Pitch 12 is also not at exactly half the frequency of pitch 15.

OK, in that case, how can I cover so many notes, without using up too many samples? If I slightly change the frequency of the A-2 sample, so that it doesn't sound detuned, when playing at pitch 12, then it's going to be detuned, when playing at pitch 15! How did professional companies like Sunsoft get around this?
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
Top

w7n
  Posts: 241
  Joined: Fri May 15, 2015 1:37 am
  Location: Nanamori-Chuu
  Contact:
  Contact w7n
  Website Twitter

### Re: Detuned DPCM Samples

- Quote

Post by w7n » Sun Oct 25, 2015 2:01 pm

If you ever listened to the Zombie Nation soundtrack, try listening to one of the tracks where the only channel used is the DPCM. The chime is a rather accurate F-4 when played at the highest sampling rate, but when played at pitch 12 it is somewhere between F-3 and F#3 and it's even hard to know which note it's closer to simply from hearing.
Since usually DPCM samples are sampled at pitch 15 and pitches under 8 are usually rarely used, pitch 12 is THE single pitch that is most inaccurate. Other pitches aren't accurate either, so if you want accurate pitch, don't sample something at pitch A and then play it at pitch B. Stay with the pitch where the sample was sampled from.
Sunsoft isn't Hogwarts and doesn't have magic that changes how the NES APU works. If you listen carefully, when Sunsoft bass samples are played at pitch 12 they're still detuned. (If you don't have absolute pitch though try doing some experiments with those samples.)
nsf.nesbbs.com under reconstruction, better player might be available in the future.
VRC6 PWM is GAY because it has colours of the rainbow in the NSFPlay keyboard visualizer.
Top

BioMechanicalDude
  Posts: 309
  Joined: Sun May 24, 2015 2:54 pm
  Location: Bulgaria

### Re: Detuned DPCM Samples

- Quote

Post by BioMechanicalDude » Sun Oct 25, 2015 2:36 pm

> w7n wrote:if you want accurate pitch, don't sample something at pitch A and then play it at pitch B.

Then how the f**k am I supposed to fit two octaves worth of notes into 16KB?! (And yes, Famitracker allows for 256KB, but I want to stick to the original limitations)

> w7n wrote:Sunsoft isn't Hogwarts and doesn't have magic that changes how the NES APU works.

Well does someone at least know how they managed to hide it so well? When I hear a Sunsoft track, I don't notice any detuning, but when I listen to my own track, its very obvious and feels annoying to listen to. How do I minimize that? There has to be way.
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
Top

HertzDevil
  Posts: 475
  Joined: Thu Apr 23, 2015 7:39 pm
  Location: Hong Kong SAR
  Contact:
  Contact HertzDevil
  Website Facebook Twitter Skype
  YouTube

### Re: Detuned DPCM Samples

- Quote

Post by HertzDevil » Sun Oct 25, 2015 3:21 pm

> BioMechanicalDude wrote:How did professional companies like Sunsoft get around this?

They simply do not use anything other than the DPCM for the bass in that case so there will be no chorusing; if they do the detune might be desired anyway. As long as nothing tuned at concert pitch appears near the bass frequency, the detune will not be noticeable in most cases (unless for instance you keep playing the same sample on every 8th note). From the DPCM pitch table I referred to, pitches 0 - 9 are all around 8 cents within each other, so samples that are recorded for this range will not sound terribly out of tune either, which is about as detuned as the 2A03 pulses near octave 4.
At most five samples are needed to cover a continuous range of 41 pitches, but everyone having experience with DPCM bass probably knows this already:

Code: Select all

`C-0 0----
C#0 -0---
D-0 1-0--
D#0 -1-0-
E-0 2-1-0
F-0 32-1-
F#0 -32-1
G-0 4-32-
G#0 -4-32
A-0 5-4-3
A#0 -5-4-
B-0 6-5-4
C-1 76-5-
C#1 -76-5
D-1 8-76-
D#1 -8-76
E-1 --8-7
F-1 9--8-
F#1 -9--8
G-1 A-9--
G#1 -A-9-
A-1 B-A-9
A#1 -B-A-
B-1 --B-A
C-2 C--B-
C#2 -C--B
D-2 --C--
D#2 ---C-
E-2 D---C
F-2 -D---
F#2 --D--
G-2 E--D-
G#2 -E--D
A-2 --E--
A#2 ---E-
B-2 ----E
C-3 F----
C#3 -F---
D-3 --F--
D#3 ---F-
E-3 ----F`
In situations where it is important to keep the same sample duration for different pitches, games may use separate samples for each pitch, though of course this requires more space to store the samples. Super C did this for its orchestra hits, all sampled for DPCM pitch 13, so they were not quite clean, but it managed to fit 10 samples into just 7 KB. You should not expect to use the same sample on multiple pitches with very little detuning; the DPCM was not designed with playing melodic notes as its main purpose.
On topic, since you already know Lua, I will just put this here:

Code: Select all

`local MACHINE = {NTSC = 1, PAL = 2}
local RATE = {
[MACHINE.NTSC] = {[0] = 428, 380, 340, 320, 286, 254, 226, 214, 190, 160, 142, 128, 106, 84, 72, 54},
[MACHINE.PAL] = {[0] = 398, 354, 316, 298, 276, 236, 210, 198, 176, 148, 132, 118, 98, 78, 66, 50},
}
local CLOCK = {
[MACHINE.NTSC] = 236250000 / 132,
[MACHINE.PAL] = 26601712.5 / 16,
}
local THRESHOLD = 0.5 -- cents
-- m: machine name
-- p: dpcm pitch
-- f: frequency
local gen = function (m, p, f)
local mstr = m
m = assert(MACHINE[m], "machine \"" .. m .. "\" does not exist")
assert(f > 0)
local t = {}
local rc = CLOCK[m] / RATE[m][p] / f / 8
for len = 0x1, 0xFF1, 0x10 do
local osc = math.floor(len / rc + .5)
local cent = 1200 * math.log(osc / len * rc, 2)
if math.abs(cent) <= THRESHOLD then
t[#t + 1] = {len = len, osc = osc, cent = cent}
end
end
table.sort(t, function (x, y) return math.abs(x.cent) < math.abs(y.cent) end)
print(("Frequency %.2f Hz, %s, DPCM pitch %.1X:"):format(f, mstr, p))
-- length in bytes, length in seconds, oscillation count, detune in cents
print(" Length (sec) Count Detune")
for _, v in ipairs(t) do
print(("%7d %7.3f %7d %+8.3f"):format(v.len, v.len * 8 / (CLOCK[m] / RATE[m][p]), v.osc, v.cent))
end
print(#t .. " results found.")
end
-- synopsis
-- note names, display only
local NOTE = {"A-1", "A#1", "B-1", "C-2", "C#2", "D-2", "D#2", "E-2", "F-2", "F#2", "G-2", "G#2"}
-- iterate through these notes
for i, v in ipairs(NOTE) do
-- real frequency, "- 25" is transposition
local realFreq = 440 * 2 ^ ((i - 25) / 12)
-- calculate the 2A03 period register, "- 25" is transposition
local preg = math.floor(CLOCK[MACHINE.NTSC] / 16 / realFreq - 1 + .5)
-- obtain the actual frequency on the 2A03
local freq = CLOCK[MACHINE.NTSC] / 16 / (preg + 1)
-- print info
print(("Note %s, real frequency = %.2f Hz, period register = $%04X"):format(v, realFreq, preg))
-- print results
gen("NTSC", 15, freq)
end
`
Sample output, modify the for loop for your own:

Code: Select all

`Note A-1, real frequency = 110.00 Hz, period register = $03F8
Frequency 109.99 Hz, NTSC, DPCM pitch F:
Length (sec) Count Detune
113 0.027 3 -0.000
1921 0.464 51 -0.000
3729 0.900 99 -0.000
3089 0.746 82 -0.187
2561 0.618 68 +0.225
3201 0.773 85 +0.361
1281 0.309 34 -0.451
3841 0.927 102 +0.451
2449 0.591 65 -0.471
3617 0.873 96 -0.479
10 results found.
Note A#1, real frequency = 116.54 Hz, period register = $03BF
Frequency 116.52 Hz, NTSC, DPCM pitch F:
Length (sec) Count Detune
4017 0.970 113 +0.335
3697 0.892 104 +0.364
3377 0.815 95 +0.399
3057 0.738 86 +0.440
3841 0.927 108 -0.451
3521 0.850 99 -0.492
2737 0.661 77 +0.492
7 results found.
Note B-1, real frequency = 123.47 Hz, period register = $0389
Frequency 123.47 Hz, NTSC, DPCM pitch F:
Length (sec) Count Detune
2785 0.672 83 +0.069
1745 0.421 52 -0.110
3825 0.923 114 +0.151
3121 0.753 93 -0.185
3489 0.842 104 +0.386
3457 0.834 103 -0.390
2449 0.591 73 +0.393
1409 0.340 42 +0.410
2081 0.502 62 -0.462
9 results found.
...`
You may want to acquire the number of WAV samples for very precise sample editing, since this is necessary to generate samples at the exact frequency if the sample is too short, especially when the DPCM pitch is also low.
refactoring 0cc-famitracker
Top

MiniMacro
  Posts: 933
  Joined: Mon Apr 20, 2015 8:47 pm
  Location: Trapped in a 2A03

### Re: Detuned DPCM Samples

- Quote

Post by MiniMacro » Sun Oct 25, 2015 3:50 pm

sunsoft has 5 samples which they detuned accordingly. a, a#, b, c, c# (i believe)
wow this is total BS
mmsound.bandcamp.com
you can see my beautiful music there~
Top

Tobikomi
  Posts: 511
  Joined: Wed Jun 10, 2015 8:17 pm
  Location: Wisconsin, USA

### Re: Detuned DPCM Samples

- Quote

Post by Tobikomi » Sun Oct 25, 2015 4:18 pm

> MiniMacro wrote:sunsoft has 5 samples which they detuned accordingly. a, a#, b, c, c# (i believe)

...and D
ぼくのなまえはブライアン（とびこみ）だ。はじめまして！
My name is Bryan (Tobikomi). Nice to meet you!
My Soundcloud: https://soundcloud.com/bryan-ness-699934457/tracks
My Chipmusic: http://chipmusic.org/gameputer_bryan3
Top

BioMechanicalDude
  Posts: 309
  Joined: Sun May 24, 2015 2:54 pm
  Location: Bulgaria

### Re: Detuned DPCM Samples

- Quote

Post by BioMechanicalDude » Sun Oct 25, 2015 4:23 pm

Wow! Thanks! This script will definitely come in handy.

> HertzDevil wrote:As long as nothing tuned at concert pitch appears near the bass frequency, the detune will not be noticeable in most cases

The chorusing itself is not really a problem, it's a cool effect actually. Things get messy when the lead(which is two or three octaves higher than the bass) sounds out of tune.

> HertzDevil wrote:since you already know Lua

That's not entirely true. I know some Lua but not much.
Greetings! I'm That Bio Mechanical Dude and I like creating various stuff like movies, games and of course chiptunes!
You can check out my YouTube Channel.
You can also follow me on Twitter.
Top

MiniMacro
  Posts: 933
  Joined: Mon Apr 20, 2015 8:47 pm
  Location: Trapped in a 2A03

### Re: Detuned DPCM Samples

- Quote

Post by MiniMacro » Sun Oct 25, 2015 5:26 pm

but that would make it six samples
wow this is total BS
mmsound.bandcamp.com
you can see my beautiful music there~
Top

Display posts from previous:
Sort by

Post Reply

- Print view

10 posts • Page 1 of 1

Return to “General Talk”

Jump to

- Rules
- Wiki
- FamiTracker
- General Talk
- Bug Reports
- Feature Requests
- Source and development
- Music
- Original Music
- Cover Music
- Other
- Site Issues & Suggestions