PCM Drum machine / sampler

Discuss NSF files, FamiTracker, MML tools, or anything else related to NES music.

Moderator: Moderators

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

Post by frantik » Fri Mar 06, 2009 7:47 pm

Here's an mp3 of the output

sound quality is pretty damn good for a NES :D well, ok, pretty good for FCEUD. VirtuaNes and Nestopia had some additional high pitched white noise which i don't know is an artifact of the emulator or an attempt to emulate the proper sound of the nes. wish i had $150 to drop on a powerpak right now for some actual hardware testing

It seems the biggest issue for sound quality is making sure the files survive the conversion to 7bit without being totally crapped on. I'm still working on perfecting the process but i've gotten it down pretty well.

Right now the PCM playing code takes 35 clock cycles. Each sample needs to be played 40.52 clock cycles apart to get ~44.1kHz sample rate, so i added some dummy code to get the cycles to total 40. These 5 extra dummy cycles will also hopefully leave me room to define custom start and end points in addition to the rom bank for each sound. in between each sound there is a bit more processing being done but it's not really noticeable.

the sounds in the rom are 16k but in this recording only the first 8k of each sample is playing. using 16k for a hihat seems like a waste so i'm hoping to use the variable start and end times to store more than 1 sound in some banks.
It's worth noting that having the screen on causes a bit of interference with the audio (maybe annoying if you're recording or something).
do you get interference if you use the RCA output from the NES (as opposed to the TV coax cable converter thing)? Now that i've got basic functionality down it would be cool to display stuff to the screen... but if it's going to cause noise on the output obviously it's not desirable. Will even showing a single image without changing it cause interference? this stuff doesn't even matter as long as i'm using an emulator but i don't want to work on something I can't use in the real hardware


edit:

added variable sound start and end locations at a resolution of 256 samples

using this i should probably be able to do some simple wavetable synthesis stuff though i'm not sure how good it's going to sound since there's going to be a slight time different each time a sample loads

I also figured out if I push the program code to the very end of the ROM I can include silence at the beginning of the 2nd bank.. so each sound bank will be 16k but there will be an additional 12k of silence after each sample.. this can be used to easily decrease the tempo or just add silence

now i have to learn the actual display and controller stuff so I could program the sampler without building a new ROM every time.. maybe even learn the battery backup stuff to save beats

yatagarasu
Posts: 35
Joined: Tue Apr 15, 2008 1:21 am

Post by yatagarasu » Sat Mar 07, 2009 5:38 am

That sounds great.
If you send me the ROM I can run it on my Power Pak light/CopyNES rig and record the output. PPL supports the mapper you're using, I believe.
Just thought I'd offer!

User avatar
Memblers
Site Admin
Posts: 3898
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Sat Mar 07, 2009 9:58 am

It sounds good. Wavetable synthesis would also be very cool. You can get a 16-bit frequency control for it pretty easily as a fixed-point number (a bit more 5 cpu cycles though).
frantik wrote:
It's worth noting that having the screen on causes a bit of interference with the audio (maybe annoying if you're recording or something).
do you get interference if you use the RCA output from the NES (as opposed to the TV coax cable converter thing)?
Yes, since it's from the PPU it's probably still there even when tapped from the CPU sound output pin and also if the PPU is on and displaying nothing. The MIDINES manual describes at as a 60hz buzz. http://wayfar.net/0xf00000_manual.php
Now that i've got basic functionality down it would be cool to display stuff to the screen... but if it's going to cause noise on the output obviously it's not desirable.
The sample updates should be interleaved with any other code. Sprite-DMA ($4014) however will cost 513 CPU cycles and mess the timing up.

Using NMI could introduce some timing problems at 44100. The PPU does 262 scanlines between each NMI I think, and each of those is 113.6667 cycles. I think it's easier to turn the screen and NMIs off when it's in play mode (or have the option to).

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

Post by frantik » Sat Mar 07, 2009 1:31 pm

lol ok you convinced me.. definitely no display during playback.. 60hz buzz and timing problems? no thanks!

for synthesis i think I'm going to write a different loop which will only handle sounds up 256 samples long. that will allow frequencies as low as 345hz to complete 1 wave cycle. no so good for basslines but for other notes that would be fine. perhaps I could get lower notes by just halving the sample rate, though i'm not sure how good it would sound.
If you send me the ROM I can run it on my Power Pak light/CopyNES rig
thanks :) I might take your offer up in the future once I get some more features completed.. it would be good to do a whole battery of tests to fully determine the capabilities and any quirks of the sound hardware

User avatar
dXtr
Posts: 375
Joined: Tue Sep 21, 2004 12:11 am
Location: Karlshamn (Sweden)

Post by dXtr » Sat Mar 07, 2009 5:56 pm

That sound pretty impressive :)

I would be cool if someone made a synthcart for the NES like midines but with an PIC or similar added that could do mixing of X extra channels for drums and output it to $4011. then we would have a "groovebox"-nes ;)

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

Post by frantik » Sun Mar 08, 2009 6:21 am

I would be cool if someone made a synthcart for the NES like midines but with an PIC or similar added that could do mixing of X extra channels for drums and output it to $4011. then we would have a "groovebox"-nes ;)
yeah.. perhaps Memblers Squeedo could be used for that.. using that mapper sounds more and more appealing. Do any emulators support the mapper? if not it would be pretty tough to develop using it

The problem with putting PCM-based programs on a cart is that 1 ROM can only hold a short amount of sound. Using a Powerpak would be ideal because you can store a whole bunch of ROMs on one cart, each with different sounds. I'm thinking about developing a synth too, which would require a totally different sound bank.

it IS frustrating that you have to balance available CPU time with audio quality :\ getting mixing or other features would be cool, but I'm hesitant to change the sample rate since most of my source samples are already at 44.1kHz and changing both the sample rate and bit rate of sounds means more loss of quality



So I was wondering, if I developed the software into a usable instrument, would anyone be interested in possibly purchasing sample packs? Ensuring sounds survive bitrate conversion is sometimes a tedious process. I would happily take the time to craft the highest possible quality 7bit versions of classic sounds like the 808, 909, Amen and other rave sounds, slower tempo live drums, etc, etc if people were interested in using them.

User avatar
Memblers
Site Admin
Posts: 3898
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Post by Memblers » Sun Mar 08, 2009 8:30 pm

frantik wrote: yeah.. perhaps Memblers Squeedo could be used for that.. using that mapper sounds more and more appealing. Do any emulators support the mapper? if not it would be pretty tough to develop using it
No emulators support it, but it can connect to a PC's serial port for file transfers (the NES program can also load/save between the flashrom and PC). I never developed the PC host software, but it works through a terminal.
http://www.parodius.com/~memblers/nes/s ... rminal.jpg
http://www.parodius.com/~memblers/nes/s ... 01menu.jpg

So for loading different samples and stuff with this, you'd have to connect it to a PC. But the advantage is you can do saving/loading without restarting the program to load a new ROM.

The the best PIC (AFAIK) to put on there is an 18F4525, which has 48kB of program memory and 3,800 bytes of RAM. That's good for the wavetable synth and everything but it's not a lot of memory for big samples. I had planned on something like 3 or 4 synth channels plus 1 sample channel (with the latter being handled on the NES-side). Sample channel then wouldn't have any volume control, since there'd not be enough time.

I just thought it was pretty cool that a program like this is much like I had in mind when I designed Squeedo. If you can work with it, I can piece another one together.

BTW I re-uploaded some (old!) Squeedo-related files that used to be on my old ISP's webspace. http://www.parodius.com/~memblers/nes/squeedo/ There's a few samples of the synth and some pics.

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

Post by tepples » Sun Mar 08, 2009 8:41 pm

If you use some sort of ADPCM-compression for the samples, like the Super NES sound chip does, you can fit twice as many into 48 KB. It might even help you overcome the 7-bit barrier, as your microcontroller code can do 16-bit mixing and then dither the end result down to 7 bits.

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

Post by frantik » Mon Mar 09, 2009 3:50 am

Memblers wrote:The the best PIC (AFAIK) to put on there is an 18F4525, which has 48kB of program memory and 3,800 bytes of RAM. That's good for the wavetable synth and everything but it's not a lot of memory for big samples.

I just thought it was pretty cool that a program like this is much like I had in mind when I designed Squeedo. If you can work with it, I can piece another one together.
yeah the 48k would only really be good for synth stuff i think.. for anything sample based i want at least 128k or 256k, and even that is only really enough to hold a drum kit or two

If you use some sort of ADPCM-compression for the samples, like the Super NES sound chip does, you can fit twice as many into 48 KB. It might even help you overcome the 7-bit barrier, as your microcontroller code can do 16-bit mixing and then dither the end result down to 7 bits.
I took a look at your ADPCM codec.. pretty cool, though I want to try to keep things as high quality as possible (ie no compression). plus i'm not sure how exactly to encode files into that format lol. as for reducing bitrate on the fly with the nes, the results would be less than satisfactory. I prefer to do all the bitrate conversion in a wave editor and use more advanced dithering algorithms than simple bit shifting.

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

Re: PCM Drum machine / sampler

Post by frantik » Sun Nov 29, 2020 6:16 pm

This is something that's been in the back of my mind for a while... still need to work on the interface but the proof of concept is working! I've got timing linked to NMI so that samples can be pitched via variable sample rate. I'm using a "clockslide" to create variable sample rates, which is something I saw mentioned here recently. Had to go down to 22050hz (max) for the sample rate to allow for the NMI timing, but that also gives twice as much granularity for tuning frequencies vs 44.1khz. Samples can be pitched down a whole octave though you can really hear the lower sample rate on the low notes (see example below). It's tough to get things perfectly in tune but I think I found the closest values. The pitch shifting is more suitable for percussion where exact tuning is less important

Mary had a little lamb - one sample used here.. low C sounds a little rough, it's pitched down a full octave

basic beat using 909 samples - a little bit of pitch shifting on the high hats for flavor here


I got some experience working on UI stuff on my last project so hopefully I can come up with a cool interface to allow for some creativity.. I'm thinking something like a grid interface, kinda want to add 808 style buttons, but not sure for what.. probably something like this Image

Post Reply