コード例 #1
0
ファイル: no4.c プロジェクト: takunoko/j3jikken
void sample_replay(int mode)
     /* 録音または再生を行う関数 */
     /*   mode: PLAY, SAMPLE     */
{
   bufptr = 0;                             /* バッファポインタを初期化  */
	 if (mode == PLAY){                      /* 再生モードの処理 */
    /* ここにスピーカをスピーカとして使用する命令 */
    speaker_switch(SPEAKER);
    lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or # key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Playing... ");
		
    /* 音声出力処理内容を記述する */
    while(bufptr <= TIME){            /*   データ出力を繰り返す    */
			da_out( 0, databuf[bufptr]);    /* ◎D/Aにデータを出力    */
			bufptr++;                       /* ◎バッファポインタを +1   */
    }   
  }
  if (mode == INVERSE){                    /* 再生モードの処理 */
    /* ここにスピーカをスピーカとして使用する命令 */
    speaker_switch(SPEAKER);
    lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or 5 key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Inverse... ");
		
    /* 音声出力処理内容を記述する */
    while(bufptr <= TIME){             /*   データ出力を繰り返す    */
			da_out( 0, databuf[TIME-bufptr]);/* ◎D/Aにデータを出力    */
			bufptr++;                        /* ◎バッファポインタを +1   */
    }   
  }
  if (mode == SAMPLE){                              /* 録音モードの処理 */
    /* ここにスピーカをマイクとして使用する命令 */
    speaker_switch(MIC);
		lcd_init();
		lcd_cursor(0,0);
		lcd_printstr(" Push * or 5 key");
		lcd_cursor(0,1);
		lcd_printstr(" Now Sampling...");
		
    /* 音声取込処理内容を記述する */
    while(bufptr <= TIME){          /*   データ読込を繰り返す     */
			ad_start( 0, 0);              /* ◎A/D変換スタート       */
			while(ADSTATUS() == 0);			  /* ◎A/D変換終了待ち 約5us */
			databuf[bufptr] = ADREAD();	  /* ◎変換データを格納     */
			bufptr++;										  /* ◎バッファポインタを +1    */
    }
  }
  speaker_switch(MIC);      /* スピーカーオフ   */
}
コード例 #2
0
ファイル: sound.c プロジェクト: ainehanta/J3jikken
void sound_init(void)
     /* 音を鳴らすための初期化               */
     /* D/A変換用の初期化とスピーカの切り替え */
{
  da_init();               /* DAの初期化 */
  speaker_switch(SPEAKER); /* スピーカとして使用 */
}
コード例 #3
0
ファイル: ad-da.c プロジェクト: ainehanta/J3jikken
void sound(int vol,int div)
{
	speaker_switch(SPEAKER);

	for(;;)
	{
		da_out(0,vol);
		wait1_100ms(div);
		da_out(0,0);
		wait1_100ms(div);
	}
}
コード例 #4
0
ファイル: ad-da.c プロジェクト: ainehanta/J3jikken
void sound_sin(int vol,int div)
{
	unsigned char data[360];
	int wcount;
	int deg;

	speaker_switch(SPEAKER);
	for(;;)
	{
		for(deg=0;deg<360;deg+=16)
		{
			da_out(0,sin_data[deg]);
			for(wcount=div;wcount>0;wcount--);
		}
	}

}
コード例 #5
0
ファイル: ex.c プロジェクト: ainehanta/J3jikken
void note_on(int hz,int vol)
{
  unsigned int tmp;
  tmp = 1000*1000 / hz / 2;
  if(tmp==note_t&&note_flag_on==1)
  {
	note_vol = vol;
	return;
  }

  timer_stop(0);

  //各種設定をすること
  note_t = tmp;
  note_flag = 0;
  note_vol = vol;
  timer_set(0,note_t);

  speaker_switch(SPEAKER);
  note_flag_on = 1;
  timer_start(0);
  ENINT();
}
コード例 #6
0
ファイル: ex.c プロジェクト: ainehanta/J3jikken
void note_off(void)
{
  timer_stop(0);
  speaker_switch(MIC);
  note_flag_on = 0;
}