NESTUDIO - PCM Sample Based Drum Machine
Moderator: Moderators
NESTUDIO - PCM Sample Based Drum Machine
I've been interested in building a drum machine on a NES for a while... finally had the free time and learned enough assembly to take on such an endeavor.. still working on it but wanted to show off what the NES can do.. audio is 7bit with 22050hz sample rate. Time is based on PPU so arbitrary tempos can be set. This initial video doesn't demonstrate pitch shifting but pitch shifting is also possible up to one full octave
Video with sound
Right now it only loops the one pattern but I plan to add support for at least 16 patterns, possibly 32, and then a song mode which will allow you to arrange the patterns in any order you like. You will also be able to assign samples and tempo on a per-pattern basis, so you will have a lot of options as far as composing. I also hope to be able to get some of the NES internal synths going at the same time without impacting the sample rate
I'm using MMC4 for quick mapper changes and PRG-RAM, though a mapper with more RAM would be cool to be able to have more than one composition on the cart at a time, and possibly even put some samples in RAM to allow then to be manipulated
Pitch shifting is done via a variable sample rate using a clockslide, display buffer is based heavily on tepples' pop slide code, probably some other bits taken from the wiki for controllers and whatnot as well
Video with sound
Right now it only loops the one pattern but I plan to add support for at least 16 patterns, possibly 32, and then a song mode which will allow you to arrange the patterns in any order you like. You will also be able to assign samples and tempo on a per-pattern basis, so you will have a lot of options as far as composing. I also hope to be able to get some of the NES internal synths going at the same time without impacting the sample rate
I'm using MMC4 for quick mapper changes and PRG-RAM, though a mapper with more RAM would be cool to be able to have more than one composition on the cart at a time, and possibly even put some samples in RAM to allow then to be manipulated
Pitch shifting is done via a variable sample rate using a clockslide, display buffer is based heavily on tepples' pop slide code, probably some other bits taken from the wiki for controllers and whatnot as well
Re: NESTUDIO - PCM Sample Based Drum Machine
this is really great! later down the road what would you think about having it sync to midi or din/sync via some sort of controller hack?
Re: NESTUDIO - PCM Sample Based Drum Machine
Yes allowing an external sync would be pretty cool, especially if it didn't require a custom board like MIDI-NES. I only have 8 clock cycles free so it would have to be something faster than reading the controller though, though maybe if I wasn't also checking for nni it would have enough time. I was also thinking whatever converted the midi signals to nes would probably end up being more powerful than the nes itself... like Arduino converting MIDI to NES
Taking a look at the expansion port info, it looks like there's an IRQ line, I'm not much of a hardware guy but it seems like it'd probably be easy to make something to trigger that, but you'd need to add some way to connect to it, might be easier to just use a controller port with arduino though
Re: NESTUDIO - PCM Sample Based Drum Machine
You don't have to strobe 4017 to read the zapper? and hopefully there's an arduino library to send the zapper signal.. that could be cool, but a lil down the road. (actually looking a the doc, reading the trigger pull seems like a better choice metaphorically, and possibly easier to test with a real zapper?)
For now I'm gonna focus on getting multiple patterns going and then the "song mode" interface to allow you arrange the patterns into a song. Eventually I wanna work on incorporating the built in synths, though I'm not sure how well that will work. I think I will have enough time during the sample changes to also write to the APU and get some rudimentary stuff going.
For now I'm gonna focus on getting multiple patterns going and then the "song mode" interface to allow you arrange the patterns into a song. Eventually I wanna work on incorporating the built in synths, though I'm not sure how well that will work. I think I will have enough time during the sample changes to also write to the APU and get some rudimentary stuff going.
Last edited by frantik on Mon Dec 07, 2020 7:04 pm, edited 1 time in total.
Re: NESTUDIO - PCM Sample Based Drum Machine
Nope. NES/Famicom Zapper is just a single read from $4017. (Vs. System Zapper is different, but you don't care about that)
To send light to the zapper, just configure an LED to either flicker at 16kHz or be off.
A couple other controllers use something similar (e.g. Arkanoid controller trigger).
Also, if you leave $4016q0 (OUT0) high, you can use the A button on the standard controllers the same way.
To send light to the zapper, just configure an LED to either flicker at 16kHz or be off.
A couple other controllers use something similar (e.g. Arkanoid controller trigger).
Also, if you leave $4016q0 (OUT0) high, you can use the A button on the standard controllers the same way.
Re: NESTUDIO - PCM Sample Based Drum Machine
The zapper trigger seems like it's even easier to test, just pull the trigger, right? or just bridge one of the pins to ground.. that can definitely be implemented.. that actually seems like one of the simplest ways to send 1 bit of data to the nes
And I tried writing 0 to 4016 without then writing 1 but it seemed like it wasn't working right.. maybe i'll try again.
Re: NESTUDIO - PCM Sample Based Drum Machine
Yup. Read $4017 (or $4016, if NES on player 1 port) and AND with $10. Or arkanoid controller is the same, but AND with $08.
Other direction. Leave it high, and you'll only ever read out the first bit of the serial stream (because the shift register is continuously being reloaded, preempting any clocking)And I tried writing 0 to 4016 without then writing 1 but it seemed like it wasn't working right.. maybe i'll try again.
Re: NESTUDIO - PCM Sample Based Drum Machine
I think I tried both ways but I think what I attempted was to just do half a strobe before every read instead of setting it once and leaving it. (actually the problem was I was checking for the wrong bit) I may mess with that, though it seems like the trigger reading is easier to implement on the other side. I actually just tested out the trigger in an emulator and it worked, but one mouse click seems to cause the trigger to register as being down on multiple frames. I also realized I may have a little more room to work with input during the non-nmi cycles of the waveform output and may be able to detect when the trigger is released instead of just when it's set to 1.. maybe even get both B button and the trigger working if they can be read at the same timelidnariq wrote: ↑Mon Dec 07, 2020 8:40 pmOther direction. Leave it high, and you'll only ever read out the first bit of the serial stream (because the shift register is continuously being reloaded, preempting any clocking)And I tried writing 0 to 4016 without then writing 1 but it seemed like it wasn't working right.. maybe i'll try again.
Last edited by frantik on Tue Dec 08, 2020 4:23 pm, edited 2 times in total.
Re: NESTUDIO - PCM Sample Based Drum Machine
The actual physical zapper has a big ol' capacitor on the trigger that takes roughly 3 vblanks to charge.
The light sensor in it has a latency of 4 scanlines (≈250µs) and remains on for 8-16 scanlines (.5-1ms) afterwards.
Re: NESTUDIO - PCM Sample Based Drum Machine
i dont think anyone is actually gonna use the zapper to control it, sounds like either of those lines would work if some midi->arduino->nes thing was to be made. With a variable sample rate the window of time that the signal needs to be high changes so it's gonna make timing tricky unless I watch for the change
Re: NESTUDIO - PCM Sample Based Drum Machine
One advantage of actually using a Zapper, though, is that this sort of "optical sync" electrically isolates the drum machine from any possible ground noise. (Incidentally, it's the same reason MIDI inputs use an optoisolator.)
Re: NESTUDIO - PCM Sample Based Drum Machine
That is a cool advantage that I didn't think about, though from everything I've read the NES is a noisy beast regardless. Actually on that front, I do plan on turning off the display/setting colors to $0d for "high quality" output.
I think I'll allow the trigger, light change or a button on controller 2 if they can all be read at the same time. I don't have any midi outs currently so it's not really a high priority at this point.. I'm more focused on making it a self contained thing that can make whole songs rather than a component of a larger arrangement
I think I'll allow the trigger, light change or a button on controller 2 if they can all be read at the same time. I don't have any midi outs currently so it's not really a high priority at this point.. I'm more focused on making it a self contained thing that can make whole songs rather than a component of a larger arrangement
Re: NESTUDIO - PCM Sample Based Drum Machine
Seems like it would be cool to have a program that you can intern generate actual NES music with. Like make music on the NES for the NES.
Re: NESTUDIO - PCM Sample Based Drum Machine
Got multiple patterns going, also switched the interface to use decimal values, and indicating when you've got the pitch on various half steps. You can create up to 16 unique patterns with 16 beats each. Each pattern can have 8 unique samples/pitches and also has a unique tempo. Allowing tempos per-pattern will allow double time/half time and other effects
Now I need to create the 'Song Mode' interface so you can string together the patterns into a longer work. You will be able to have songs that are made up of up to 256 patterns long.
Then I hope to create separate step sequencer modes for hopefully all three synth channels going, even it's just basic stuff, if it could offer 4 channels of audio that would be pretty cool
Video update (turn on audio)
Now I need to create the 'Song Mode' interface so you can string together the patterns into a longer work. You will be able to have songs that are made up of up to 256 patterns long.
Then I hope to create separate step sequencer modes for hopefully all three synth channels going, even it's just basic stuff, if it could offer 4 channels of audio that would be pretty cool
Video update (turn on audio)
There are other programs out there that allow you to create music on the NES, I'm not sure if any of them allow you to use them in your own NES programs if that's what you mean. This one certainly wouldn't.. the CPU is spending almost all the time sending out the PCM audio. I do plan on adding the NES synths to this thing though