Jaffe- / NESizer2

A synthesizer based on the 2A03 (NES APU)
107 stars 19 forks source link

How to upload samples? #6

Open KeenVox opened 3 years ago

KeenVox commented 3 years ago

Hi, I just wanted to ask, how to upload samples? I assume the samples have to be converted for sysex and then send while in sample select mode?

Thanks in advance! Keen

Jaffe- commented 3 years ago

If I recall correctly you can send samples when the system is in any mode. As soon as the MIDI receiver handling code sees a sysex command followed by SYSEX_CMD_SAMPLE_LOAD (0x01) it will change the global UI state into a "transfer mode". In this mode the 16 upper button LEDs will light up like a progress bar.

You can see in midi.c what is expected by this sysex command, but basically:

System Exclusive (0xF0)
MIDI_CMD_SAMPLE_LOAD (0x01)
<sample number> (0-127) (this is the number you use later to select this particular sample)
<sample type> (0: raw, 1: dpcm, only raw is supported at the moment so keep this at 0)
<sample length N, bits 0-7>
<sample length N, bits 8-13>
<sample length N, bits 14-20>
<data byte 0> (note: sample values are 7 bit unsigned) 
...
<data byte N-1>
End of Exclusive (0xF7)

What I did to load new samples was to first convert the sample from the source format (wav, mp3, whatever) to 7-bit unsigned audio. This can be done with a variety of tools, I believe I used SoX for this (in Linux). This produces the <data byte 0> to <data byte N-1> sequence above. I made a small script that read the file, added the rest that is shown above and wrote a resulting sysex file that could be sent over MIDI. I don't think I have that script around any more but it should not be hard to write.

KeenVox commented 3 years ago

Ah, okay. I will try it!

Thanks for you help, and for the fuse settings too. I'm relativly new to programming microcontroller outside of arduino, so I really appriciated the support!

Jaffe- commented 1 year ago

Hi @KeenVox,

Really late follow-up, but I recently started working some more on this project to try and finish most of the features.

If you're still interested, I have now done some fixes to the code such that uploading and using samples is a bit more user friendly. I actually realized that the LED progress bar feature was actually never pushed to the git repository, but I have done that now.

I have also added a tool for generating a sysex file with the correct format. To use this tool, you can look at the script convert-sample.sh. To put it short, convert the sample file to 16 kHz, 7-bit. unsigned raw format. SoX is a good utility for this, the script shows how to do this conversion for input files in wav format.

To create a sysex file from the converted raw sample, run the gensysex program like this:

./gensysex sample <index> <input raw sample file path> <sysex filename>

Where the index is which index you want the sample to have in the NESizer file system. Index 0 corresponds to MIDI note 60 (middle C). This is the note you will have to input on MIDI to trigger the sample on the DMC channel, or enter into the sequencer if making a pattern with DMC samples.

When you send the sysex data from the file, the NESizer should give you a progress bar on the LEDs, and the two digit display should show 'rr' (for now). If you see this, you can be sure that the NESizer is actually receiving the data and is storing it in memory. If it does not start, I would try to format the sample file system first, which is done by going into the settings mode/page and then pressing the 7th button on the second row.

beau-seidon commented 1 year ago

Hell yes! I know what I'm doing this weekend :). I have been meaning to experiment with this to get some samples in, but have been super busy with work lately. I'm going to try it out with your script.

Probably better to post this on another thread since unrelated to samples, but over the next month or so I will try to add some MIDI CC callbacks to modify some of the voice parameters like duty and the envelopes etc., to match the Famimimidi MIDI implementation. It takes me a while because I'm still learning C/C++.

I'll finish the build guide from my notes first, like I said I'd do previously. It's about 40% done.

Jaffe- commented 1 year ago

Hell yes! I know what I'm doing this weekend :). I have been meaning to experiment with this to get some samples in, but have been super busy with work lately. I'm going to try it out with your script.

Probably better to post this on another thread since unrelated to samples, but over the next month or so I will try to add some MIDI CC callbacks to modify some of the voice parameters like duty and the envelopes etc., to match the Famimimidi MIDI implementation. It takes me a while because I'm still learning C/C++.

That would be really great! I'd be happy to review a pull-request and get this in.

I'll finish the build guide from my notes first, like I said I'd do previously. It's about 40% done.

Really great work of you to make a build guide and updated BOM. I also would like to get the gerber files uploaded so people can order this without having the PCB tool. Don't know why I didn't do that already...

KeenVox commented 1 year ago

Hi Johan, very cool! Will definitly try everything out. Great to see you working on this project again!

Am 6. Oktober 2023 18:15:43 schrieb Johan Fjeldtvedt @.***>:

Hi @KeenVox, Really late follow-up, but I recently started working some more on this project to try and finish most of the features. If you're still interested, I have now done some fixes to the code such that uploading and using samples is a bit more user friendly. I actually realized that the LED progress bar feature was actually never pushed to the git repository, but I have done that now. I have also added a tool for generating a sysex file with the correct format. To use this tool, you can look at the script convert-sample.sh. To put it short, convert the sample file to 16 kHz, 7-bit. unsigned raw format. SoX is a good utility for this, the script shows how to do this conversion for input files in wav format.To create a sysex file from the converted raw sample, run the gensysex program like this: ./gensysex sample Where the index is which index you want the sample to have in the NESizer file system. Index 0 corresponds to MIDI note 60 (middle C). This is the note you will have to input on MIDI to trigger the sample on the DMC channel, or enter into the sequencer if making a pattern with DMC samples. When you send the sysex data from the file, the NESizer should give you a progress bar on the LEDs, and the two digit display should show 'rr' (for now). If you see this, you can be sure that the NESizer is actually receiving the data and is storing it in memory. If it does not start, I would try to format the sample file system first, which is done by going into the settings mode/page and then pressing the 7th button on the second row. — Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you were mentioned.Message ID: @.***>

Jaffe- commented 1 year ago

Probably better to post this on another thread since unrelated to samples, but over the next month or so I will try to add some MIDI CC callbacks to modify some of the voice parameters like duty and the envelopes etc., to match the Famimimidi MIDI implementation. It takes me a while because I'm still learning C/C++.

Regarding another thread for this, please make one under Discussion (instead of Issues), I added that feature to the repository now :) Also, I pushed a commit yesterday which changes the Makefile to compile the sources with -O2 instead of -O3 optimization level. This reduced the flash size from ~30 kB to ~22 kB (less aggressive unrolling of loops and branches), so there should be enough room to implement more features now. I did some quick testing that things still run fast enough, and it seems like it is.

jeff464 commented 3 months ago

I would also like to know how to upload samples to the NESizer. I converted my audio file to the proper format using sox, but I'm not sure what "run the gensysex program like this: ./gensysex sample " means in this context. The windows command line just errors out and double clicking the file sends me to VSC to edit it.

beau-seidon commented 3 months ago

The source for gensysex is in this repo under tools, and can be compiled with gcc or another c compiler (I used msvc). I'll upload my Windows-compiled gensysex.exe after work. I'm also working on a script to batch-upload sysex files to Nesizer using midiox, to load whole drum/sample kits at a time.

beau-seidon commented 3 months ago

gensysex.zip

here are the gensysex and deltacompress windows executables used to convert samples. you shouldn't need to do anything with dc.

take a look at the .sh script in tools to see how the process is automated in linux. it shows the syntax for calling gensysex in a terminal. I have a .sh and .bat script for converting big batches of samples, but I have some tweaks to make before I upload them.

I also have a little bit of experimenting to do regarding the indexing of samples (mapping to MIDI notes), which may lead to a wishlist item of my own.

the task I'm having a little bit of trouble with is learning the COM scripting API for midi-ox. when I figure that out I'll upload the script for batch upload too.