You are not logged in.
Lost Password?


Register To Post



 Bottom   Previous Topic   Next Topic

#21
Re: Sound?
Posted on: 2011/1/4 4:01
Virtual Freak
Joined 2008/5/30
Spain
78 Posts
CoderLong Time User (12 Years) PVBCC 2010 2nd
Quote:

DanB wrote:
Well, it's up to you to decide the tempo by controlling how often you call PlayNote()...

To play a simple song, you can do something like:


u16 song
[] = {C_4D_4E4FS4A_5};
u32 songTick 0;
u8 currNote 0;
while(
1){
  
//Playing the song in the background is easy,
  //just control its tempo by only calling playnote every
  //57:th (or whatever) pass through the game loop
  
if (songTick == 57) {
    
PlayNote(0song[currNote], 8);
    
currNote++;
    if (
currNote 4)
      
currNote 0;
    
songTick 0;
  }
  
  
//Do other game-stuff

  
songTick++;
}


For more complex song playing, you'll have to wait some more for the full midi player





One question, as define the duration of each note??? thanks for help me!!
Top

#22
Re: Sound?
Posted on: 2011/1/4 4:10
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
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
Top

#23
Re: Sound?
Posted on: 2011/1/4 11:28
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:

VirtualChris wrote:
Where do I get vsu.h?


I commented out its #include and it worked fine.
Top

#24
Re: Sound?
Posted on: 2011/1/4 13:28
VUE(xpert)
Joined 2003/9/3
Sweden
442 Posts
PVBCC EntryHighscore Top10 3rdCoderContributorHOTY09 2ndLong Time User (15 Years) DonatorApp CoderPVBCC 2010 1st20+ Game RatingsPVBCC 2013 2nd
Quote:

HorvatM wrote:
Quote:

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.
Top

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

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.

Attach file:


py bintoheader.py Size: 0.58 KB; Hits: 107
Top

#26
Re: Sound?
Posted on: 2011/1/5 2:42
VUE(xpert)
Joined 2006/9/29
USA
267 Posts
CoderLong Time User (13 Years) PVBCC 2010 3rd
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.
Top

#27
Re: Sound?
Posted on: 2011/1/5 9:40
PVB Elite
Joined 2003/7/25
USA
1507 Posts
PVBCC 1stCoderContributor#3 PosterHOTY09 EntryLong Time User (15 Years) App CoderPVBCC 2010 EntryPVBCC 2013 Entry
Quote:

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:
Quote:

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
Top

#28
Re: Sound?
Posted on: 2011/1/5 21:12
Nintendoid!
Joined 2003/7/28
USA
110 Posts
Long Time User (15 Years)
Quote:

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?
Top

#29
Re: Sound?
Posted on: 2011/1/5 21:30
VUE(xpert)
Joined 2003/9/3
Sweden
442 Posts
PVBCC EntryHighscore Top10 3rdCoderContributorHOTY09 2ndLong Time User (15 Years) DonatorApp CoderPVBCC 2010 1st20+ Game RatingsPVBCC 2013 2nd
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.
Top

#30
Re: Sound?
Posted on: 2011/1/5 23:54
Virtual Freak
Joined 2008/5/30
Spain
78 Posts
CoderLong Time User (12 Years) PVBCC 2010 2nd
hello, how to make a silence between notes?? thankss!!!!
Top

 Top   Previous Topic   Next Topic


Register To Post