You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#1
Sound?
Posted on: 2011/1/1 17:50
PVB Elite
Joined 2008/4/26
USA
950 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (12 Years) PVBCC 2010 EntryPVBCC 2013 Entry
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.
Top

#2
Re: Sound?
Posted on: 2011/1/1 21:42
PVB Elite
Joined 2008/12/28
Slovenia
635 Posts
Highscore Top ScoreHighscore Top ScoreCoderContributor10+ Game RatingsLong Time User (11 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Well, you can look at gccVB's audio.h file, and you can use the VSU register map

http://www.planetvb.com/modules/dokuw ... u.php?id=vsu_register_map

to get an idea of what is what.

I've asked about sound before, but got no answers. It'd be nice if someone who knows about sound programming would share their knowledge.
Top

#3
Re: Sound?
Posted on: 2011/1/1 23:18
VUE(xpert)
Joined 2006/9/29
USA
267 Posts
CoderLong Time User (13 Years) PVBCC 2010 3rd
Unfortunately, no, it's a lot harder than just calling up built-in sounds. I've never done it, but from looking at the programming manuals, my understanding is that the VSU (Virtual Sound Unit) has a number of registers which can be programmed with a very short "sound effect". (The "sound effect" is actually a wave pattern which defines an "instrument" of sorts.) It also has other registers which tell the VSU if the sound should be played, how fast it should be played (the frequency, or pitch of the sound), how loud it should be played, etc. This is mostly for making music though... To actually play sound effects, there are a few different techniques. One is to use the standard "instruments" (channels 1-4 of the VSU) to play beep boop sounds, use the sweep channel (channel 5 of the VSU) to make "boing" jumping noises, or use the noise generator (channel 6) to make explosion noises. However, DogP also wrote a demo/utility for converting wav files into a format that could (with some supporting code) be played on the VB. I just tried it, and in mednafen the default code seems to be playing the sound files too fast, (in fact, exactly 10x too fast!) but I just got it to work by changing the the definition of SR_DIV on line 126 of wavonvb.c to 3750000 instead of 375000. Beware though, that including wav files in your game will significantly increase the size of the ROM image. That demo with just the four sound files requires an 8Mbit cartridge! Hope this helps!
Top

#4
Re: Sound?
Posted on: 2011/1/1 23:49
PVB Elite
Joined 2008/4/26
USA
950 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (12 Years) PVBCC 2010 EntryPVBCC 2013 Entry
That's what I want to do: Make music. I played with the wav converter, but it seems like the game freezes while playing the file (you can't press a buton or anything.)
Top

#5
Re: Sound?
Posted on: 2011/1/2 1:13
Virtual Freak
Joined 2008/5/30
Spain
78 Posts
CoderLong Time User (12 Years) PVBCC 2010 2nd
interesting! if someone could give an example of code to make music or sounds would be great!!!!
Top

#6
Re: Sound?
Posted on: 2011/1/2 6:55
VUE(xpert)
Joined 2006/9/29
USA
267 Posts
CoderLong Time User (13 Years) PVBCC 2010 3rd
Quote:

VirtualChris wrote:
That's what I want to do: Make music. I played with the wav converter, but it seems like the game freezes while playing the file (you can't press a buton or anything.)

It's a good learning experience to try and understand what other people's code is doing. I think you mentioned that C isn't your first programming language VirtualChris, so a couple of good coding exercises would be: Can you see why the game "freezes" while the sound is playing? Can you make it so that the currently playing sound stops when a button is pressed?

Unfortunately, we don't have any good utilities right now for converting something like a midi file to a format the VB can play. (At least not any released ones... *cough*DanB*cough ) DogP's wav player really isn't a practical way to play music during the game. The practical way to play music during the game is to use the VB's built-in tone playing capabilities along with something like a timer interrupt, so that the speed of the game doesn't affect the pitch of the sound, and the sound doesn't freeze the game.
Top

#7
Re: Sound?
Posted on: 2011/1/2 11:30
PVB Elite
Joined 2008/12/28
Slovenia
635 Posts
Highscore Top ScoreHighscore Top ScoreCoderContributor10+ Game RatingsLong Time User (11 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Quote:

rubengar wrote:
interesting! if someone could give an example of code to make music or sounds would be great!!!!


Precisely. All I want is an example of how to program the VSU registers to generate tones and effects. I don't care whether they freeze the game or not.
Top

#8
Re: Sound?
Posted on: 2011/1/2 13:46
PVB Elite
Joined 2003/7/26
USA
1469 Posts
PVBCC EntryCoderContributorSpecial AchievementTop10 PosterHOTY09 EntryLong Time User (15 Years) App Coder20+ Game RatingsPVBCC 2013 Entry
Quote:

HorvatM wrote:
Quote:

rubengar wrote:
interesting! if someone could give an example of code to make music or sounds would be great!!!!


Precisely. All I want is an example of how to program the VSU registers to generate tones and effects. I don't care whether they freeze the game or not.


It really is as simple as writing to the VSU registers and RAM periodically (such as with the timer interrupt, as you said). But, if you want example code, just run the included example file (test.txt) through DogP's Virtual Boy Sound Generator and tell it to output VB source along with the WAV file. You can even use it to experiment with the sound registers and hear what it sounds like without the full compile(/program cart)/run cycle.

After you get that, it's pretty much just figuring out how all those registers and wave patterns affect the sound. Anyone familiar with how digital sound reproduction "works" (especially with regard to basic additive synthesizers like the VSU) and/or has some musical talent: feel free to write a tutorial on that topic for the wiki!
Edited by RunnerPack on 2011/1/2 14:03
Edited by RunnerPack on 2011/1/2 14:04
Top

#9
Re: Sound?
Posted on: 2011/1/2 17:38
PVB Elite
Joined 2008/4/26
USA
950 Posts
CoderContributorTop10 PosterHOTY09 3rdLong Time User (12 Years) PVBCC 2010 EntryPVBCC 2013 Entry
OK, so I put in the example.txt included and it spat out some VB code. I go to put it in my game, and it spat out a huge list of errors. So I change the top line to "#include modlibgccvb.h" and it gave me a much more managable error list. Only trouble is, I don't know what any of this stuff means.

EDIT: OK, figured it out.

Attach file:



png  imadeabooboo.png (45.33 KB)
768_4d20a9fd59864.png 678X341 px
Top

#10
Re: Sound?
Posted on: 2011/1/2 18:48
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
I can explain more later, but if you want to get started on making sound, pull up the code to Super Bounce. That is probably one of the most basic implementations of it.

What you have to wrap your head around when using this is that you're programming the frequencies, not samples. Where in a wav file, you're outputting each sample, and have to keep updating the sample or no sound comes out... with this, you can set the frequency to 1000Hz, and never touch it again and it'll keep playing.

For a quick start guide: SxFQL and SxFQH are the frequency registers (together they're 11 bits of frequency), SxLRV is volume for left/right (4 bits each), SxEV0 is the envelope register, which you should keep at 0xF0 for simplicity (sort of a master volume as well when not using other features). SxINT you should set to 0x80 to start playing, 0x00 to stop. And SxRAM selects which waveform RAM you're playing from... I'd set it to 0 (you should actually fill the waveform RAM, but it still plays sound without doing it). If you want to stop all channels, set SSTOP to 1. I'd only mess with SND_REGS[WAVE1] to begin with.

Hopefully that'll get you going.

DogP
Top

 Top   Previous Topic   Next Topic


Register To Post