NESTUDIO - PCM Sample Based Drum Machine

A place where you can keep others updated about your NES-related projects through screenshots, videos or information in general.

Moderator: Moderators

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 6:13 am

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

Image

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

dink
Posts: 91
Joined: Sun Jan 12, 2020 8:42 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by dink » Mon Dec 07, 2020 8:30 am

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?

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 11:12 am

dink wrote:
Mon Dec 07, 2020 8:30 am
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?
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

tepples
Posts: 22275
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by tepples » Mon Dec 07, 2020 3:16 pm

One plausible sync interface could pretend to be the Zapper light sensor. Then you can read $4017 bit 3: $00 means light or disconnected, and $08 means dark.

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 6:21 pm

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.
Last edited by frantik on Mon Dec 07, 2020 7:04 pm, edited 1 time in total.

lidnariq
Posts: 10235
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by lidnariq » Mon Dec 07, 2020 6:34 pm

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.

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 7:13 pm

lidnariq wrote:
Mon Dec 07, 2020 6:34 pm
to send light to the zapper, just configure an LED to either flicker at 16kHz or be off.
...
Also, if you leave $4016q0 (OUT0) high, you can use the A button on the standard controllers the same way.
The zapper trigger seems like it's even easier to test, just pull the trigger, right? :mrgreen: 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.

lidnariq
Posts: 10235
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by lidnariq » Mon Dec 07, 2020 8:40 pm

frantik wrote:
Mon Dec 07, 2020 7:13 pm
The zapper trigger seems like it's even easier to test, just pull the trigger, right? :mrgreen: 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
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.
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.
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)

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 9:02 pm

lidnariq wrote:
Mon Dec 07, 2020 8:40 pm
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.
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)
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 time
Last edited by frantik on Tue Dec 08, 2020 4:23 pm, edited 2 times in total.

lidnariq
Posts: 10235
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by lidnariq » Mon Dec 07, 2020 9:28 pm

frantik wrote:
Mon Dec 07, 2020 9:02 pm
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.
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.

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Mon Dec 07, 2020 11:42 pm

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

tepples
Posts: 22275
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by tepples » Tue Dec 08, 2020 7:00 am

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.)

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Tue Dec 08, 2020 9:38 am

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

Erockbrox
Posts: 384
Joined: Sun Nov 23, 2014 12:16 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by Erockbrox » Sat Dec 12, 2020 11:01 pm

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.

frantik
Posts: 370
Joined: Tue Mar 03, 2009 3:56 pm

Re: NESTUDIO - PCM Sample Based Drum Machine

Post by frantik » Sun Dec 13, 2020 5:08 pm

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)
Erockbrox wrote:
Sat Dec 12, 2020 11:01 pm
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.
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

Post Reply