Register To Post



 Bottom   Previous Topic   Next Topic

#11
Re: Sound?
Posted on: 2011/1/2 21:48
VUE(xpert)
Joined 2008/12/28
Slovenia
456 Posts
Highscore Top ScoreCoderContributorTop10 Poster10+ Game RatingsLong Time User (4 Years) App CoderPVBCC 2010 Entry
Thanks!

I'm having some difficulty though. My libgccvb's audio.h is a bit different:


typedef struct SOUNDREG
{
    
u8 ctl;
    
u8 spacer1[3];
    
u8 vol;
    
u8 spacer2[3];
    
u8 fql;
    
u8 spacer3[3];
    
u8 fqh;
    
u8 spacer4[3];
    
u8 env;
    
u8 spacer5[3];
    
u8 unk;
    
u8 spacer6[3];
    
u8 ram;
    
u8 spacer7[3];
    
u8 spacer8[36];
SOUNDREG;


Which register is which? I'm assuming 'EV0' is 'env' and 'INT' is 'ctl'. What I'm trying to do is this:


int main 
()
{
  
unsigned int Freq;

  
SND_REGS[WAVE1].ram 0;
  
SND_REGS[WAVE1].vol 0x66;
  
SND_REGS[WAVE1].ctl 0x80;

  while(
1)
  {
    for(
Freq 0Freq <= 1000Freq++)
    {
      
SND_REGS[WAVE1].fql = (Freq << 4) & 0xFF;
      
SND_REGS[WAVE1].fqh = (Freq >> 4) + 1;
    }
  }
}
Top

#12
Re: Sound?
Posted on: 2011/1/3 6:48
PVB Elite
Joined 2003/7/25
USA
1244 Posts
PVBCC 1stCoderContributor#2 PosterHOTY09 EntryLong Time User (9 Years) App CoderPVBCC 2010 Entry
Check the libgccvb.h included in Super Bounce... they're defined like:


u8 SxINT
;
u8 spacer1[3];
u8 SxLRV;
u8 spacer2[3];
u8 SxFQL;
u8 spacer3[3];
u8 SxFQH;
u8 spacer4[3];
u8 SxEV0;
u8 spacer5[3];
u8 SxEV1;
u8 spacer6[3];
//Ch. 1-5 only 
u8 SxRAM;
u8 spacer7[3];
//Ch. 5 only
u8 S5SWP;
u8 spacer8[35];


DogP
Top

#13
Re: Sound?
Posted on: 2011/1/3 18:42
VUE(xpert)
Joined 2008/12/28
Slovenia
456 Posts
Highscore Top ScoreCoderContributorTop10 Poster10+ Game RatingsLong Time User (4 Years) App CoderPVBCC 2010 Entry
Nothing changes.
Top

#14
Re: Sound?
Posted on: 2011/1/3 21:15
VUE(xpert)
Joined 2003/9/3
Sweden
393 Posts
PVBCC EntryHighscore Top10CoderHOTY09 2ndLong Time User (9 Years) DonatorApp CoderPVBCC 2010 1st20+ Game Ratings
I think you do need to fill the waveform RAM to get sound?
At least in Mednafen...

Anyways, maybe it's time to share a little
Here is a basic function from my midi player that plays a single note:


void PlayNote
(u8 chanu16 frequ8 vol) {
    
//Set up the frequency the channel will play
    
SND_REGS[chan].SxFQH freq >> 8;
    
SND_REGS[chan].SxFQL freq 0xFF;

    
//Set the volume for the channel (0-15, same for left/right)
    
SND_REGS[chan].SxLRV = (vol << 4) | vol;

    
//Envelope for the channel (makes the tone fade out)
    
SND_REGS[chan].SxEV0 0xF7;
    
SND_REGS[chan].SxEV1 0x01;

    
//Start the channel without interval
    
SND_REGS[chan].SxINT 0x9F;
}


Usage:

#include "audio.h"
#include "notes.h"
#include "voices.h"

//Copy the piano "instrument" to soundbank 1
copymem((void*)WAVEDATA1, (void*)PIANO128);

//Tell channel 0 to use soundbank 1
SND_REGS[0].SxRAM 0;

//Play a "Middle-C" note on channel 0 with volume 8
PlayNote(0C_48);


The file "voices.h" includes a couple of different "instruments" that I made, to be loaded into the soundbanks.

The file "notes.h" defines all standard notes, fine-tuned manually to fit the VB's frequencies.

This should help you to get some tunes flowing
Just call PlayNote() with different note values (E_4, D_4, G_4 etc.) within your main loop (or better, on a timer interrupt)

Attach file:


h audio.h Size: 2.72 KB; Hits: 79
h notes.h Size: 3.50 KB; Hits: 80
h voices.h Size: 1.25 KB; Hits: 64
Edited by DanB on 2011/1/3 21:25
Top

#15
Re: Sound?
Posted on: 2011/1/3 21:57
VUE(xpert)
Joined 2008/12/28
Slovenia
456 Posts
Highscore Top ScoreCoderContributorTop10 Poster10+ Game RatingsLong Time User (4 Years) App CoderPVBCC 2010 Entry
Wow, that's great! Actually the only thing DogP wasn't clear on are the envelope registers and the waveform register. Now that I see how your PlayNote function works, it all seems really simple. Thank you once again!
Top

#16
Re: Sound?
Posted on: 2011/1/3 22:00
Newbie
Joined 2011/1/3
3 Posts
Long Time User (2 Years)
Unfortunately, your PlayNote() doesn't show tempo, and if it did, wouldn't it take a long time to get a complex song on there?
Top

#17
Re: Sound?
Posted on: 2011/1/3 22:11
VUE(xpert)
Joined 2008/12/28
Slovenia
456 Posts
Highscore Top ScoreCoderContributorTop10 Poster10+ Game RatingsLong Time User (4 Years) App CoderPVBCC 2010 Entry
It wouldn't be too difficult to write some code to read a music track from an array and play it at the right speed. Getting it to play in the background, however, is another thing.
Top

#18
Re: Sound?
Posted on: 2011/1/3 22:16
VUE(xpert)
Joined 2003/9/3
Sweden
393 Posts
PVBCC EntryHighscore Top10CoderHOTY09 2ndLong Time User (9 Years) DonatorApp CoderPVBCC 2010 1st20+ Game Ratings
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
Edited by DanB on 2011/1/3 22:34
Top

#19
Re: Sound?
Posted on: 2011/1/4 1:06
PVB Elite
Joined 2008/4/26
USA
529 Posts
CoderContributorLong Time User (5 Years)Top10 PosterHOTY09 3rdPVBCC 2010 Entry
Where do I get vsu.h?
Top

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

VirtualChris wrote:
Where do I get vsu.h?


here you have it! do not get it to work: (

Attach file:


h vsu.h Size: 1.05 KB; Hits: 63
Top

 Top   Previous Topic   Next Topic


Register To Post

You are not logged in.
Lost Password?
Register Resend Activation