Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to upload samples? #6

Open
KeenVox opened this issue Sep 15, 2021 · 10 comments
Open

How to upload samples? #6

KeenVox opened this issue Sep 15, 2021 · 10 comments

Comments

@KeenVox
Copy link

KeenVox commented Sep 15, 2021

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-
Copy link
Owner

Jaffe- commented Sep 15, 2021

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
Copy link
Author

KeenVox commented Sep 15, 2021

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-
Copy link
Owner

Jaffe- commented Oct 6, 2023

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
Copy link
Collaborator

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-
Copy link
Owner

Jaffe- commented Oct 8, 2023

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
Copy link
Author

KeenVox commented Oct 10, 2023 via email

@Jaffe-
Copy link
Owner

Jaffe- commented Oct 10, 2023

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
Copy link

jeff464 commented Aug 13, 2024

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
Copy link
Collaborator

beau-seidon commented Aug 14, 2024

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
Copy link
Collaborator

beau-seidon commented Aug 15, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants