Original Post

I want to learn how to program sound for the VB. Does the Virtual Boy have a set of sounds it can play and all you have to do is call them up, or is it much more difficult? Even so, I would still want to learn just how to do this. I want my games to have sound. I am musically inclined, so I can compose some songs if need be.

34 Replies

The duration of the note is until you stop it, unless you use fading.

Regarding waveform RAM… on real hardware you don’t need to initialize the waveform to get sound (I’m not sure if it’s a random waveform or a default one), but in the emulator you probably do. It’s obviously a good idea to do it anyway.

DogP

VirtualChris wrote:
Where do I get vsu.h?

I commented out its #include and it worked fine.

HorvatM wrote:

VirtualChris wrote:
Where do I get vsu.h?

I commented out its #include and it worked fine.

Yeah, that just contains some alternative #defines for the memory map that I used before. It’s not needed and should be removed.

DogP wrote:
The duration of the note is until you stop it, unless you use fading.

Regarding waveform RAM… on real hardware you don’t need to initialize the waveform to get sound (I’m not sure if it’s a random waveform or a default one), but in the emulator you probably do. It’s obviously a good idea to do it anyway.

DogP

My guess would be that on real hardware, the waveform RAM is filled with garbage when the system gets powered on, but in an emulator, the memory that gets allocated for waveform RAM might get initialized to zero depending on the implementation.

Anyway, thanks a bunch for the code samples DanB! (Especially the frequency tables… I really didn’t want to try to figure those out. 😀 )

Also, I looked at DanB’s instrument waveform definitions and was thinking about how difficult it would be to make new ones, when it occurred to me that many waveforms were already produced for commercial VB games! Not only that, but the mednafen debugger makes them incredibly easy to get at. To dump a waveform:

1. Load up the game that has the instrument you want in mednafen.
2. Once the music that uses the instrument begins, hit Alt+D to start the debugger
3. Press Alt+3 to bring up the memory editor
4. Now, by pressing < and >, you can switch between main memory, and the five VSU waveform banks. The cool thing is, the debugger even graphically displays the waveform that is loaded into the currently selected bank! (Another cool thing you can use the debugger for is editing these waveforms in real time – just press Insert to enter/exit edit mode.)
5. Once you find the waveform that you want a copy of, press D to bring up the dump dialog, then type

0000 001F wave.bin

to dump the entire waveform to a file called wave.bin.

This will give you a dump of the waveform memory segment that you selected, which is cool, but not really useful for coding purposes. If you want to change the raw binary into a usable format (a C header), I whipped up a python script which will do that for you. It’s attached to this post, and the syntax for it is

./bintoheader.py [hex dump filename] [header name without .h]

It probably has a few flaws, but it gets the job done more quickly than manually transcribing hex codes. Hope this helps someone out!

I do have one question about the VSU registers: What does setting the interval do? I tried changing the lower 4 bits of SxINT, but it didn’t seem to affect the sound.

Sorry for double posting, but I was playing around and answered my own question… I forgot to set bit 5 in SxINT. With bit 5 on, my sound gets chopped off after a different period of time depending on how I set bits 4-0.

Fwirt wrote:
My guess would be that on real hardware, the waveform RAM is filled with garbage when the system gets powered on, but in an emulator, the memory that gets allocated for waveform RAM might get initialized to zero depending on the implementation.

I don’t think it’s random garbage (it could just happen to come up as same/similar by accident)… it seems to sound the same every time, and random garbage wouldn’t really make a “note” (the frequency is 1/32 of the sampling frequency only because the waveform is periodic on 32 samples… if you make your waveform periodic on 8 samples, the frequency goes up by 4x… random would likely have a higher frequency. It’s definitely not all same values as that wouldn’t make any sound (like the emulator). I ripped the waveforms for the random channel using my sound card and MATLAB… I could probably answer this question the same way, but I guess it doesn’t really matter.

Fwirt wrote:

Also, I looked at DanB’s instrument waveform definitions and was thinking about how difficult it would be to make new ones, when it occurred to me that many waveforms were already produced for commercial VB games!

Why are new waveforms hard to make? I usually do them in Excel and save them as a CSV… there’s only 32 samples. I’m not very familiar with Mednafen’s debugging, so it’s cool to see your solution… but if you really wanted a waveform, you could easily copy 32 values down by hand from the memory viewer in RB/RD.

DogP

DogP wrote:
you could easily copy 32 values down by hand from the memory viewer in RB/RD.

What is this “by hand” you speak of? 😛

Hey Fwirt, thanks for the tip on Mednafen’s graphical waveform editor! I hadn’t seen that.

It looks like my waveforms aren’t interpreted as I intended though, that’s interesting… maybe it doesn’t like signed values.

hello, how to make a silence between notes?? thankss!!!!

rubengar wrote:
hello, how to make a silence between notes?? thankss!!!!

Just call PlayNote with the note parameter set to PAU (or 0)

ohh thanks, but I had already tested with PAU and I hear a bad sound 😕

rubengar wrote:
ohh thanks, but I had already tested with PAU and I hear a bad sound 😕

Then you can stop a channel completely by setting
SND_REGS[chan].SxINT = 0;

thanks!! I have it solved!! Capitan Sevilla 2 already has music, all thanks to your help!!

DanB wrote:
It looks like my waveforms aren’t interpreted as I intended though, that’s interesting…

Heh, those instruments I posted are totally messed up! 😛

Here are the correct ones instead:

 

Write a reply

You must be logged in to reply to this topic.