SNES audio hardware info

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.
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES audio hardware info

Post by bazz »

Espozo wrote:
bazz wrote:
Espozo wrote:Wow, that's actually pretty awesome! So if I really wanted to (even though I'm not going to) I could probably nearly recreate all the instruments that play in the song while using a fraction of the space. The only thing is, It seems a bit more difficult to do this sort of thing when it comes to sound effects. Could you would use HDMA to constantly stream the sound effects, allowing more room for the actual song? I plan on using 6 channels for the actual song and 2 for sound effects, so could you have it to where an HDMA port works with one sound effect and the second for the other?
I wouldn't stream the sound effects, I would just load them into the SPC, and send a command to the SPC telling it to play that sound effect.
Well, I mean this wouldn't be the ideal thing to do, but if you have just about no space left for sound effects in ram, then you might have to.

I just think it's funny that you're learning about the non-traditional mechanics of SPC when you came here asking for an introduction, and for some reason the main topic has been streaming high quality audio or streaming BRR with HDMA and all this crap and it's like.. Is that seriously how you introduce someone to SPC audio hardware???

No!! It isn't!! We should be talking about the tradition of classic SPC music, which is not streaming, but tracking!!

Tracking is at the heart of SPC because it is sample-based.
1) Tracking -- you really ought to download a tracking application like Renoise, MilkyTracker, Schism Tracker ... these are the kind of sequencing tools people use to make sample-based music. If you actually learn how to do some basic tracking (Renoise has EXCELLENT tutorials -- google "renoise tutorial", here is a great example, the first tutorial to Renoise! : http://files.renoise.com/videos/Renoise ... rt%201.mp4 -- you might feel like you're learning Renoise but you actually learning also the fundamentals of every Tracker software :)

Understanding tracking is going to help you understand the fundamentals of how most games use the SPC -- and you will be able to visually see how most events will be parsed by an SPC driver. for basic level, we can say by rhythmically playing samples back at certain pitches and certain volumes.

Not only does SPC play the samples, it can shape them too. The most fundamental way to do this is by the ADSR envelope. Go, learn about it! There is also echo, pitch modulation, and noise, but these should be considered bonus topics until you understand the basics of tracking.
The SPC DSP has hardware ADSR envelope implementation, unlike most tracking software which define a software implementation. There is also a gain mode which has other ADSR qualities, or can be used in defining your own custom ADSR envelopes, I want you to know that but it's not something you should focus on.

Tracking then gets deep in-depth with "effects commands".. But I'm not going into that, I'm trying to lay a map for you. With the notion of SPC, we can consider effects commands as a way of modifying the DSP registers in interesting ways while the song is playing, for instance vibrato, which would alter the sample's pitch at specified rates, rates which may be associated mathematically with the BPM of the song.
-------
2) SPC and Tracking
How does the SPC rhythmically play music??? The answer is timers! The SPC has 3 of them!! You can do whatever with them --You set SPC to go off at a certain rate in time and you can base quarter notes 8th notes etc. from the timer.

But yeah!! once you have a timer firing, you can then play certain samples rhythmicaly!! That's it basically!

The rest is just special limitations of SPC700, and other Super Nintendo specifics.. but that's the nature of tracking and roughly how SPC correlates.


3) Choosing what song to play, or what SFX to play -- How does that work?
To do this, a protocol must be established, and the SPC must parse the SNES IO registers in the SPC loop, it checks for certain commands and command parameters on the SPC IO ports that you define.. when the SNES writes the trigger values and parameters, the SPC can react accordingly, ie "ie command:play SFX, parameter:#2" ..

4) Getting data to SPC from SNES
There is a communications protocol .. bla bla [I'm getting tired]


4) Putting it all together!!!
Not many people have put all of this together .. I am working on SNES Tracker which will do all of the above eventually.. Also there is pre-existing solutions like SNESMod and SNESGSS. But to actually put it all together, you will need ALOT.. and this is why for the most part people have relied on non-native solutions like SNESMOD -- which translates something originally not purposed for SNES into something that may work on SNES -- the downside of these solutions is that you can't hear immediately how they will sound on the SNES, for instance, especially if they use the SNES DSP-only effects like Pmod or echo.. -- SNESGSS is the closest it's gotten as far as "native" level released software goes... SNESGSS, along with SNES Tracker, uses an SPC emulator inside it so that the user can actually hear and interface with the "real" thing as he develops the music.

If you want to experiment doing things manually.. here's what you would do :
1) Use Bregalads BRR Tools and convert some small WAV file to BRR
2) Write an SPC program
. a barebones SPC program to play a sample. To do this, you need to decide a start address for the SPC program in SPC memory. let's say $200, then write a SPC program in something like TASM or wla-spc700 that inits the SPC and plays a sample.. primarily you must set FLG register, main / voice volume registers, voice ADSR/gain (use direct gain it's easiest), and set the DIR address, and create DIR entries.. I'll write a tutorial on this.. maybe.. maybe not..
You must have wondered what is DIR?? hehe :P
. include the SPC program and BRR sample in a SNES program that uploads to the SPC -- you need to learn how to communicate and send the data to SPC, but it is essentially just "send this many bytes from some place in SNES memory to some place in SPC memory, and maybe do that again from/to other places, and then start executing SPC from some SPC Address" .. that's it.
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: SNES audio hardware info

Post by psycopathicteen »

tomaitheous wrote:Is there a way to read the playback pointer of a given channel into the sample? I'm just trying to think of a way to do a real wave-table synth setup with a series of small waveforms (kinda like the PPG synth), without breaking the output stream of the channel and change the timbre on an internal level instead of a note-by-note basis. Can the DSP generate interrupt for when a channel sample block encounters a 'loop' point?
Maybe interrupt the spc700 every, say, 256 cycles to calculate if the next timbre change is about to happen or not, and change the sample directory when needed to.
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SNES audio hardware info

Post by tepples »

The SPC700 has no interrupt sources wired to it. It has only the interval timers.
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES audio hardware info

Post by bazz »

tepples wrote:The SPC700 has no interrupt sources wired to it. It has only the interval timers.
Hence "timers as interrupts.." == find an appropriate timer (3, one of which is high resolution), and evaluate an appriopriate interval to "interrupt on" -- but if you're doing "heavy" processing outside of your timer poll routine, you might sometimes arrive out of rhythm. I dunno what you guys are doing in-depth, and therefore cannot judge the effect of this possible circumstance and how it relates to your goal (real-time synthesis?)....

And if you actually build this thing, and you start incurring overhead and it's a problem, you can talk about curing this later, potentially with a less frequent timer interval... or please I invite you to summarize your effective repair of this situation, I know I am certainly interested in hearing the full development story of a synth on SNES. :)
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES audio hardware info

Post by bazz »

tomaitheous wrote:Can the DSP generate interrupt for when a channel sample block encounters a 'loop' point?
Yes and no, -- although an interrupt cannot be generated, you can use timers and check the ENDX register. ENDX signifies each voice's arrival to the BRR end block. This will be the last BRR block before the loop is started, of course only if the loop is enabled, however I am not sure exactly when in relation to the decoding of the BRR blocks, that this register is updated.

from me to you:

ENDX:
[Byte] nnnnnnnn -- each bit = voice #76543210
n=0: BRR END not yet reached [from KON, or from last write to this register]
n=1: BRR END reached [roughly, not sure exactly where in pipeline this is updated, check FullSNES or ask NoCash]

A Voice's bit in this register is cleared each time it is KON [or all voices' bits are cleared if you write to this register],
and if desired, you can reset "only all" of the bits by writing to ENDX register <--- this last feature could of maybe been helpful if you wanted to repeatedly know when the BRR end block was reached during looping, rather than just only from KON, however its limitation is that you could only do it for one voice, since the whole register is clobbered on write.
93143
Posts: 1371
Joined: Fri Jul 04, 2014 9:31 pm

Re: SNES audio hardware info

Post by 93143 »

93143 wrote:keeping the pitch the same while the timbre dulls [is] a job for either a long sample or an adventure in pitch modulation (you can sharpen the beginning of a sound with pitchmod, then fade out the modulating waveform, but doing this so as to match an existing sample might be quite difficult). [...] I suppose you could use a dynamic sample rate, but that would require you to continually change the playback rate so as to maintain the pitch...
Okay, no, there are at least three other ways to do something like that without streaming.

1) Wavetable synthesis, as tomaitheous suggested. (It's at least kinda possible; see the DKC2 credits.) If necessary, using two channels would allow chorus-type effects, mitigating the disadvantages of using short waveforms on a synthesizer that doesn't have a built-in chorus effect.
2) Use two channels, with one short low-rate sample for the bulk of the note and one short high-rate sample for the treble component, and just vary the relative volume of the high-rate sample. Not sure how good this would sound, but probably better than nothing, and it's the easiest option of the three. For certain sounds you might even be able to reuse the same sample...
3) Use the FIR filter on the echo, if nothing else is using echo. Could also possibly modify the filter on the fly to do a sort of phaser/flanger effect without using an extra channel, though I'm not sure how well that would work in practice 'cause I haven't tried it. Sadly there seems to be no way to hear the echo without the direct signal... What does EDL=0 do? Is it one sample or nine, or something else?

Other schemes may present themselves to intelligent cogitation. I'm not sure what all KFF is doing here - the saw filter seems to be similar to the DKC2 trick; the variable-pulse-width thing is something else, and there may be yet another trick in there - but whatever he's doing it works great (on synth waveforms, admittedly, not a distorted guitar)...

...you know, you can do a variable-width pulse wave by combining two phase-inverted saw waves and tweaking the pitch of one of them slightly to change the phase; I wonder if that's what he did? That also allows you to morph from pulse to saw by fading one of them out, and from any combination of pulse and saw towards sine using a lowpass filter or a wavetable (in this case moving to lower sample rates). Is there a name for this technique? I made a synth that did that for Emulator X, and had thought of doing the same on the SNES, but it looks like I might have been pre-empted...
KungFuFurby
Posts: 264
Joined: Wed Jul 09, 2008 8:46 pm

Re: SNES audio hardware info

Post by KungFuFurby »

That's a combination of pitch modulation and playing different samples...

I intend to enhance this effect with real time loop point modifications one day. I'm creating my own sound driver to do this job.
tomaitheous
Posts: 592
Joined: Thu Aug 28, 2008 1:17 am
Contact:

Re: SNES audio hardware info

Post by tomaitheous »

93143 wrote:keeping the pitch the same while the timbre dulls [is] a job for either a long sample or an adventure in pitch modulation (you can sharpen the beginning of a sound with pitchmod, then fade out the modulating waveform, but doing this so as to match an existing sample might be quite difficult).
I remember reading about that trick from somewhere. It kind of reminded me of LA synthesis, where the attack phase supposedly the most hardest part in replicating an instrument sound. I mean, not exactly the same thing - but the concept was similar. Making a more complex sound by having a more complex attack. I had the idea that you could stream really low bit-rate samples overlaying that part of the attack in the sample. I was counting on the higher resolution waveform to hide the noise of the low bit-rate attack phase sample.
...you know, you can do a variable-width pulse wave by combining two phase-inverted saw waves and tweaking the pitch of one of them slightly to change the phase; I wonder if that's what he did? That also allows you to morph from pulse to saw by fading one of them out, and from any combination of pulse and saw towards sine using a lowpass filter or a wavetable (in this case moving to lower sample rates). Is there a name for this technique? I made a synth that did that for Emulator X, and had thought of doing the same on the SNES, but it looks like I might have been pre-empted...
Not sure if this is the same thing, but I had this idea: http://pcedev.net/audio/sub_waveform6.xm (second pattern). The primary wavefrom has all sample data on the positive range of the waveform, and a second channel has all waveform data in the negative range (I forget the terms for this) - so when they 'accumulate', the effect is stronger. The volume controls the brightness of the sound, but it's obviously not enough. Instead, you think of the two waveforms as single waveform, and you 'walk' the phase of the second waveform in small increments. By advancing the frequency by a large amount and quickly putting it back - you're 'walking' the phase difference of the waveforms (you can do the opposite too; slow down the second warm and then put it back to the same frequency to retard the phase). Of course, you'll probably need translation tables. If the effect is strong enough, then you don't need to replicate on other channels (if you're doing chords), because the timbre sounding effect is strong enough to stand out. Though, I didn't really experiment with it much so I have no idea what type of waveforms are applicable to this approach.


bazz wrote:how it relates to your goal (real-time synthesis?)....
Yeah, or some sort of approximation. It seems all the hardware was there to do so such a thing (basic wave-table synthesis, it's just missing a few small but key features).

Probably not doable on the SNES, but I also had the idea of non linear playback of a waveform pointer (like with 80's Casio keyboards). But that would require an interrupt. The idea is that you deform a waveform that has two parts, by stretching or compression the first and second halfs. The timbre changes are you change the mid point between these two points in the waveform. If you have an interrupt, you could do 'hard sync' as well. I did it on the PCE with a 7khz timer, but it was kinda noise-y/gritty.
__________________________
http://pcedev.wordpress.com
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: SNES audio hardware info

Post by psycopathicteen »

Is there an easy way of getting an .spc file into a ROM? KungFuFurby's song is pretty epic. I also promised to use one of Augustus's songs a while ago.
Augustus Blackheart
Posts: 56
Joined: Sat Jul 26, 2014 9:50 am

Re: SNES audio hardware info

Post by Augustus Blackheart »

psycopathicteen wrote:Is there an easy way of getting an .spc file into a ROM? KungFuFurby's song is pretty epic. I also promised to use one of Augustus's songs a while ago.
http://jiggawatt.org/badc0de/spcplayer.htm
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: SNES audio hardware info

Post by psycopathicteen »

An .spc file is 65kB, so it must be the contents of the RAM plus some kind of header.
User avatar
bazz
Posts: 476
Joined: Fri Sep 02, 2011 8:34 pm
Contact:

Re: SNES audio hardware info

Post by bazz »

tomaitheous wrote: I did it on the PCE with a 7khz timer, but it was kinda noise-y/gritty.
The SPC has faster timers if it helps, one is 32,000 Hz.. the other 2 are 8000 Hz..
psycopathicteen wrote:An .spc file is 65kB, so it must be the contents of the RAM plus some kind of header.
Besides the header(s) and RAM are also the DSP registers, and CPU registers.
http://snesmusic.org/files/spc_file_format.txt


^ is there a newer SPC file format I should know about for SNES Tracker?
tepples
Posts: 22345
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: SNES audio hardware info

Post by tepples »

tomaitheous wrote:I remember reading about [storing the attack at a higher sample rate] from somewhere. It kind of reminded me of LA synthesis, where the attack phase supposedly the most hardest part in replicating an instrument sound.
This bit of inspiration from Roland LA synthesis is also why my NES music engine uses FamiTracker-style envelopes (at 2 bytes per frame, encoding arpeggio, duty, and volume) only for the attack and NerdTracker II-style fades (2 bytes encoding duty, initial volume, and decrease rate) for the decay or sustain.
I had the idea that you could stream really low bit-rate samples overlaying that part of the attack in the sample. I was counting on the higher resolution waveform to hide the noise of the low bit-rate attack phase sample.
I guess that means I need to get working on my proof of concept of half-bit-depth BRR using [-5, -1, 1, 5] and [-7, -2, 2, 7] quantization tables, expanded by either the S-CPU or S-SMP before being written to sample memory and played through the S-DSP. I've got so many things I could be doing that I need to put a list of projects I could be working on somewhere so that people can rank them.
psycopathicteen wrote:Is there an easy way of getting an .spc file into a ROM?
Perhaps we need a spec for a simplified .spc for inclusion in a ROM that disallows things like overwriting $0000-$01FF and $FFC0-$FFFF, leaves initial DSP and timer contents unspecified, and includes a standard way for the S-CPU to tell the S-SMP to jump back to the IPL at $FFC0.
psycopathicteen
Posts: 3001
Joined: Wed May 19, 2010 6:12 pm

Re: SNES audio hardware info

Post by psycopathicteen »

Do you guys write your music in ASM? If so, the ASM source file would be more useful when it comes to using music in homebrews.

I'm surprised how acceptable it is to use 2 channels for one instrument. I didn't notice any lack of polyphony. It could be that 4 simultaneous instruments is good enough for most melodies, or it's good enough to not use 2 channels for every instrument.
Augustus Blackheart
Posts: 56
Joined: Sat Jul 26, 2014 9:50 am

Re: SNES audio hardware info

Post by Augustus Blackheart »

psycopathicteen wrote:Do you guys write your music in ASM? If so, the ASM source file would be more useful when it comes to using music in homebrews.
Ever since I got Noise Tracker for the Amiga, back in the day, I've usually avoided writing songs in ASM. I like to be able to see the relation bewteen notes and to be able to play back anything immediately. If I have a song that is already completed for the Amiga or the SNES, sometimes I will go back and make a version in ASM or MML depending on what machine it's for.
psycopathicteen wrote:I'm surprised how acceptable it is to use 2 channels for one instrument. I didn't notice any lack of polyphony. It could be that 4 simultaneous instruments is good enough for most melodies, or it's good enough to not use 2 channels for every instrument.
Depending on how many channels I have available on a given pattern I'll use anywhere from 1-5 channels for a single instrument with somewhat alternating volume envelopes or different octaves.
tomaitheous wrote:Not sure if this is the same thing, but I had this idea: http://pcedev.net/audio/sub_waveform6.xm (second pattern)...
This is one of the techniques I like to use when I have the bytes and channels to spare.
Post Reply