/********* music class  music.h************

By Michael Garcia mgarcia

email gwald@start.com.au

********* music class  music.h************/

 

 
 
 

#ifndef MUSIC_H

#define MUSIC_H
#include <libps.h>
 

class music_c{
public:

       music_c(         unsigned long *seq = NULL,
                        unsigned long  *vh = NULL,
                        unsigned long *vb = NULL,
                        short mvol = 127,
                        short svol  = 127,
                        char mode = 1, // SSPLAY_PLAY
                        char count =  0 // SSPLAY_INFINITY
                         );

 void play(); //  Performance mode. SSPLAY_PAUSES = switches to pause state | SSPLAY_PLAY = Performs immediately  | SSPLAY_INFINITY = is specified if there are an infinite number of performances.
 void stop();
 char init();
        void fadeOut(unsigned long  dur = 1000);
        void fadeIn(unsigned long  dur = 1000);
  void vol(unsigned long  vol = 55);
 

        unsigned long  *seqAdd_m; // SEQ data:Score data
        unsigned long  *vhAdd_m;  // VH data: Sampled data (attribute part)
        unsigned long  *vbAdd_m;  // VB data: Sampled data (waveform part)
  short mvol_m, // main volume
  svol_m; // seq volume
 

 char vabId_m, // vab id
  seqId_m; // seq id
 

 char mode_m, //  Performance mode. SSPLAY_PAUSES = switches to pause state | SSPLAY_PLAY = Performs immediately  | SSPLAY_INFINITY = is specified if there are an infinite number of performances.
   count_m; //  Number of tune repetitions
 
 

};
#endif
 

/********* music class  music.cpp ************

By Michael Garcia mgarcia

email gwald@start.com.au

********* music class  music.cpp ************/

#include "music.h"
#include <stdio.h>

music_c::music_c(unsigned long *seq,
  unsigned long *vh,
  unsigned long *vb,
  short mvol,
  short svol,
  char mode,
   char count)
{
 seqAdd_m =seq;
 vhAdd_m = vh;
 vbAdd_m = vb;
 mvol_m = mvol;
 svol_m = svol;
 mode_m = mode;
 count_m = count;

 if(seq) init();

}
 

char music_c::init()
{
  /* VAB opening and transmission to sound buffer */
 vabId_m = SsVabTransfer( (unsigned char*)vhAdd_m, (unsigned char*)vbAdd_m, -1, 1 );
 if (vabId_m < 0) {
  printf("SsVabTransfer failed (%d)\n", vabId_m);
  return -1;
 }

 /* SEQ opening */
 seqId_m = SsSeqOpen((unsigned long *)seqAdd_m, vabId_m);
 if (seqId_m < 0)
 {
  printf("SsSeqOpen failed (%d)\n", seqAdd_m);
  return -1;
 }

 return vabId_m;

}
 

void music_c::play()
{
 SsSetMVol(mvol_m, mvol_m);   /* Main volume setting*/
 SsSeqSetVol(seqId_m, svol_m, svol_m);  /* Volume setting for each SEQ */
 SsSeqPlay(seqId_m, mode_m ,count_m);/* Playback switch ON */
}

/* Sound playback termination */
void music_c::stop()
{
 SsSeqStop(seqId_m);   /* Playback switch OFF */
 VSync(0);
 VSync(0);
 SsSeqClose(seqId_m);   /* SEQ close */
  SsVabClose(vabId_m);   /* VAB close */
}

void music_c::fadeOut(unsigned long  dur)
{

 for(int i = svol_m*dur; i>0; i--)
  SsSeqSetVol(seqId_m, i/dur, i/dur);  /* Volume setting for each SEQ */

 stop();

}
 
 

void music_c::fadeIn(unsigned long  dur)
{
 SsSetMVol(mvol_m, mvol_m);   /* Main volume setting*/

 SsSeqSetVol(seqId_m, 1, 1);  /* Volume setting for each SEQ */

 SsSeqPlay(seqId_m, mode_m ,count_m);/* Playback switch ON */

 for(int i = 0; i<svol_m*dur; i++)
 SsSeqSetVol(seqId_m, i/dur, i/dur);  /* Volume setting for each SEQ */

}
 

void music_c::vol(unsigned long  vol)
{
 SsSeqSetVol(seqId_m,vol,vol);  /* Volume setting for each SEQ */

}

/*
 *
 music class driver program
 

/*********  music class driver program music_d.cpp ************

By Michael Garcia mgarcia

email gwald@start.com.au

/*********  music class driver program music_d.cpp ************

 

 
 
 

#include <libps.h>
#include <rand.h>
#include <stdio.h>
#include "music.h"

/*  Macros relating to data arrangement */
#define VH_ADDR  0x80090000
#define VB_ADDR  0x800a0000
#define SEQ_ADDR 0x80110000
 
 

main()
{
 music_c m((u_long *)SEQ_ADDR,(u_long *)VH_ADDR,(u_long *)VB_ADDR);
 

/*
 m.play();

 for(int i=0; i<22096; i++)
 {
  m.vol(i);
  printf("\n vol %d ",i);
  for(int a=0; a<50; a++){;}
 }

*/

 m.fadeIn();
 printf(" fade finished\n");
 

/*
 for(int i=0; i<5000; i++){
 printf("playing 50\\%d\n",i/100);
 }

*/

 for(int i=0; ; i++){

 }
 

 printf("\n Fading.....\n ");
 m.fadeOut();
 printf("\n Finished OK ");

}