audiotest.c 2.81 KB
#include <ultra64.h>
#include "zaru.h"

#define	AI_BUF_MAX 500  /* 440ɬ׽ʬ */
#define VOLMAX		5000

#define SEIGEN		ZARU_SINWAVE
#define NOKOGIRI	ZARU_SAWWAVE
#define SANKAKU		ZARU_TRIWAVE
#define KUKEI		  ZARU_RCTWAVE
#define ONLYL     ZARU_ONLYL
#define ONLYR     ZARU_ONLYR

#define PI		3.14159265358979

typedef struct
{
  s16	leftSound;
  s16	rightSound;
} soundElement_t;

typedef union
{
  soundElement_t	ele[AI_BUF_MAX];
  long long int		force_structure_alignment;
} aiBuffer;

aiBuffer	audioBuf;

void audioTest(u32 sound, u32 length)
{
  u32		i;
  u32		j;
  u32		count=0;

  i=0;
  switch(sound)
  {
  case ONLYR:
    while(i<440)
    {
      for(j=0; j<44; j++)
      {
	audioBuf.ele[i].leftSound = 0;
	audioBuf.ele[i].rightSound = (s16)(VOLMAX*sinf(2*PI*j/44));
	i++;
      }
    }
    break;
  case ONLYL:
    while(i<440)
    {
      for(j=0; j<44; j++)
      {
	audioBuf.ele[i].leftSound = (s16)(VOLMAX*sinf(2*PI*j/44));
	audioBuf.ele[i].rightSound =0;
	i++;
      }
    }
    break;
  case SEIGEN:
    while(i<440)
    {
      for(j=0; j<44; j++)
      {
	audioBuf.ele[i].leftSound = (s16)(VOLMAX*sinf(2*PI*j/44));
	audioBuf.ele[i].rightSound = (s16)(VOLMAX*sinf(2*PI*j/44));
	i++;
      }
    }
    break;
  case NOKOGIRI:
#ifdef	NOKOGIRI_PLUS
    while(i<440)
    {
      for(j=0; j<44; j++)
      {
	audioBuf.ele[i].leftSound = (s16)(VOLMAX - (float)(VOLMAX*j/43));
	audioBuf.ele[i].rightSound = (s16)(VOLMAX - (float)(VOLMAX*j/43));
	i++;
      }
    }
#else
    while(i<440)
    {
      for(j=0; j<44; j++)
      {
	audioBuf.ele[i].leftSound = (s16)(VOLMAX - (float)(VOLMAX*j/21.5F));
	audioBuf.ele[i].rightSound = (s16)(VOLMAX - (float)(VOLMAX*j/21.5F));
	i++;
      }
    }
#endif    
    break;
  case SANKAKU:
    while(i<440)
    {
      for(j=0; j<22; j++)
      {
	audioBuf.ele[i].leftSound = (s16)(2*VOLMAX*j/21) - VOLMAX;
	audioBuf.ele[i].rightSound = (s16)(2*VOLMAX*j/21) - VOLMAX;
	i++;
      }
      for(j=0; j<22; j++)
      {
	audioBuf.ele[i].leftSound = -(s16)(2*VOLMAX*j/21) + VOLMAX;
	audioBuf.ele[i].rightSound = -(s16)(2*VOLMAX*j/21) + VOLMAX;
	i++;
      }
    }
    break;
  case KUKEI:
    while(i<440)
    {
      for(j=0; j<22; j++)
      {
	audioBuf.ele[i].leftSound=VOLMAX;
	audioBuf.ele[i].rightSound=VOLMAX;
	i++;
      }
      for(j=0; j<22; j++)
      {
	audioBuf.ele[i].leftSound=-VOLMAX;
	audioBuf.ele[i].rightSound=-VOLMAX;
	i++;
      }
    }
    break;
  }  

#if 0
  if(sound == NOKOGIRI)
  {
    for(i=0; i<440; i++)
    {
      rmonPrintf("ele[%d].left = %d\n", i, audioBuf.ele[i].leftSound);
    }
  }
#endif  

  osAiSetFrequency(44100);
  osWritebackDCacheAll();
  
  osAiSetNextBuffer((void *)&audioBuf, 440*4);
  osAiSetNextBuffer((void *)&audioBuf, 440*4);
  for(i=0; i<length; i++)
  {
    while(osAiGetStatus() & AI_STATUS_FIFO_FULL)
      ;
    osAiSetNextBuffer((void *)&audioBuf, 440*4);
  }
}