changeset 111:7600cdfa8779

copy sound
author Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
date Thu, 09 Jun 2011 02:23:21 +0900
parents 8a525ec378fc
children 5106d8d12ded
files Magoroku.cc game.h sound.c sound.h sound/NEW.wav sound/bomber.wav sound/jikiout.wav sound/ring.wav sound/sample.wav sound/shota.wav sound/shotb.wav sound/shotc.wav
diffstat 12 files changed, 304 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Magoroku.cc	Thu Jun 09 01:45:25 2011 +0900
+++ b/Magoroku.cc	Thu Jun 09 02:23:21 2011 +0900
@@ -165,6 +165,7 @@
 static int light_sysswitch = 0;
 static int light_num = 4;
 
+/*
 static void 
 LightSysSwitch(Viewer *sgroot) {
   if (light_sysswitch == 1) {
@@ -180,6 +181,7 @@
     sgroot->OffLightSysSwitch();
   }
 }
+*/
 
 
 static int 
--- a/game.h	Thu Jun 09 01:45:25 2011 +0900
+++ b/game.h	Thu Jun 09 02:23:21 2011 +0900
@@ -14,7 +14,6 @@
 
 
 extern Game *game;
-
 extern void schedule(Game *game);
 
 #endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sound.c	Thu Jun 09 02:23:21 2011 +0900
@@ -0,0 +1,253 @@
+#include <stdio.h>
+#include <SDL.h>
+#include <SDL_mixer.h> //追加
+#include "sound.h"
+#include "Ss.h"
+
+#include "error.h"
+//#include "libps.h"
+
+//int vh_addr[10]={0x80140000,0x80141a00,0x80143000,0x80144400,0x80148200,
+//               0x80149300,0x8014f300,0x80130000,0x80130000,0x80130000};
+
+//_________________________________________________________
+Mix_Chunk *chunk[8]; // 音楽ファイルの読み込み変数
+int channel[8];
+//_________________________________________________________
+
+#if 0
+static char buf0[] = "pBAV";
+
+long vh_addr[10] =
+{ (long) buf0, (long) buf0, (long) buf0, (long) buf0, (long) buf0,
+  (long) buf0 };
+#endif
+
+int vb_addr[10] =
+{ 0x80140d00, 0x80142700, 0x80143d00, 0x80145100, 0x80148f00,
+  0x8014a100, 0x80150000, 0x80140000, 0x80140000, 0x80140000
+};
+
+int vab[10];			/* SE 用 VAB */
+unsigned char *buf;
+int cnt;
+int seqno = -1;
+
+int seq[4];			/* SEQ data id */
+int sdvab;			/* 常駐 SE.VAB */
+
+//CdlFILE vhfile, vbfile;
+
+int SQ[10] = { 0x80155000, 0x8015f000, 0x80168000, 0x8016e000, 0x80175000,
+	       0x80177000, 0xa00d0000, 0xa00e0000, 0x801e0000
+};
+
+void Soundss()
+{
+    /*
+      int i;
+
+      //Set Sound Reverb @@@  リバーブの設定 
+      printf("音源データをCDから読み込み中");
+      SsUtSetReverbType(SS_REV_TYPE_STUDIO_C);
+      SsUtReverbOn();
+
+
+      // 音源データのCDからの読み込み 
+      // 標準音源(VH属性部)の読み込み 
+      for (i = 0; i < 10; i++) {	// リトライループ 
+      if (CdSearchFile(&vhfile, VH_NAME) != 0)
+      break;		//正常終了ならばリトライループ中断 
+      else
+      printf("%s not found.\n", VH_NAME);
+      }
+      printf("♪");
+      for (i = 0; i < 10; i++) {	// リトライループ 
+      CdReadFile(VH_NAME, (void *) SQVH_ADDR, vhfile.size);
+
+      // リードの裏で通常の処理は実行できる。
+      // ここでは、Read が終了するまで残りのセクタ数を監視 
+      while ((cnt = CdReadSync(1, 0)) > 0)
+      VSync(0);		// 垂直同期割り込み待ち(時間調整用)
+      if (cnt == 0)
+      break;		// 正常終了ならばリトライループ中断 
+      }
+      // 標準音源(VB波形部)の読み込み 
+      for (i = 0; i < 10; i++) {	// リトライループ 
+      if (CdSearchFile(&vbfile, VB_NAME) != 0)
+      break;		// 正常終了ならばリトライループ中断 
+      else
+      printf("%s not found.\n", VB_NAME);
+      }
+      printf("♪");
+      for (i = 0; i < 10; i++) {	// リトライループ 
+      CdReadFile(VB_NAME, (void *) SQVB_ADDR, vbfile.size);
+
+      // リードの裏で通常の処理は実行できる。
+      // ここでは、Read が終了するまで残りのセクタ数を監視 
+      while ((cnt = CdReadSync(1, 0)) > 0)
+      VSync(0);		// 垂直同期割り込み待ち(時間調整用)
+
+      if (cnt == 0)
+      break;		// 正常終了ならばリトライループ中断 
+      }
+      printf("♪");
+      // Open & transfer VAB data @@@ *VAB データのオープン,転送 
+      sdvab = SsVabTransfer(SQVH_ADDR, SQVB_ADDR, -1, 1);
+      if (sdvab < 0) {
+      printf("VAB open failed(sdvab = %d)\n", sdvab);
+      return;
+      }
+      printf("完了。\n");
+      //      seq[0] = SsSeqOpen (SQ_ADDR, sdvab);
+      //      for (i=0;i<8;i++)
+      //      seq[i] = SsSeqOpen ((unsigned long*)SQ[i], sdvab);
+      */
+}
+
+void SoundPlay(int no)
+{
+    // Open SEQ/SEP datas @@@ * SEQ/SEP データのオープン 
+    //    SsSetMVol (127, 127);
+    //    SsUtSetReverbDepth( 40, 40 );
+
+    seq[no] = SsSeqOpen((unsigned int *) SQ[no], sdvab);
+    seqno = no;
+    //SsSeqPlay(seq[no], SSPLAY_PLAY, 0);
+
+}
+
+void SoundStop()
+{
+    if (seqno == -1)
+	return;
+    //SsSeqStop(seq[seqno]);
+    //SsSeqClose(seq[seqno]);
+}
+
+//__________________________________________________________________
+/**
+ * 全部これで判定するのはおかしい。
+ * んだけど、時間がががががが
+ */
+int no_useSDLMixer = 0;
+
+void
+InitSdlMixer(void)
+{
+    if (Mix_OpenAudio(MIX_DEFAULT_FREQUENCY,MIX_DEFAULT_FORMAT,2,1024) < 0) {
+        __debug("failed to initialize SDL_mixer.\n");
+	no_useSDLMixer = 1;
+    }
+}
+
+
+// 音楽ファイル読み込み関数
+void LoadSdlMixer()
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	chunk[BGM]=Mix_LoadWAV("./sound/sample.wav");
+	chunk[SHOT_A]=Mix_LoadWAV("./sound/shota.wav");
+	chunk[SHOT_B]=Mix_LoadWAV("./sound/shotb.wav");
+	chunk[SHOT_C]=Mix_LoadWAV("./sound/shotc.wav");
+	chunk[RING]=Mix_LoadWAV("./sound/ring.wav");
+	chunk[NEW]=Mix_LoadWAV("./sound/powerdown.wav");
+	chunk[JIKIOUT]=Mix_LoadWAV("./sound/jikiout.wav");
+	chunk[BOM]=Mix_LoadWAV("./sound/bomber.wav");
+	
+	// 読み込めないファイルがあればエラーで終了
+	if(!chunk[BGM] || !chunk[SHOT_A] || !chunk[SHOT_B] || !chunk[SHOT_C]
+	   ||!chunk[RING] || !chunk[NEW] || !chunk[JIKIOUT] || !chunk[BOM]) {
+	    fprintf(stderr,"failed to load sound.\n");
+	    //return -1;
+	    return;
+	}
+    }
+}
+
+/* 音楽再生関数
+   int fleg ... 再生回数。-1でループします。
+   int ch ... 再生する音の番号*/
+void
+PlaySdlMixer(int fleq, int ch)
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	channel[ch]=Mix_PlayChannel( ch ,chunk[ch], fleq);
+    }
+}
+
+void
+PauseSdlMixer(int ch)
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	Mix_Pause(ch);
+    }
+}
+
+void
+ResumeSdlMixer(int ch)
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	Mix_Resume(ch);
+    }
+}
+
+void
+TimeSdlMixer(int fleq, int ch, int time)
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	channel[ch]=Mix_PlayChannelTimed( ch ,chunk[ch], fleq, time);
+    }
+}
+
+
+// 音の解放関数
+void
+FreeSdlMixer()
+{
+    int i ;
+
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	for(i =0; i < 8; ++i) {
+	    Mix_FreeChunk(chunk[i]);
+	}
+    }
+}
+
+void
+InitVolume(void)
+{
+    if (no_useSDLMixer) {
+	__debug("%s is not executed because no_useSDLMixer is set\n",
+		__FUNCTION__);
+    } else {
+	Mix_Volume( 0, 255);       // BGM
+	Mix_Volume( 1, SE_VOLUME); // SHOT_A
+	Mix_Volume( 2, SE_VOLUME); // SHOT_B
+	Mix_Volume( 3, 100);       // SHOT_C
+	Mix_Volume( 4, 40);        // RING
+	Mix_Volume( 5, SE_VOLUME); // NEW
+	Mix_Volume( 6, SE_VOLUME); // JIKIOUT
+	Mix_Volume( 7, 100);       // BOM
+    }
+}
+
+//_________________________________________________________________
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sound.h	Thu Jun 09 02:23:21 2011 +0900
@@ -0,0 +1,49 @@
+#ifndef _SOUND_H_
+#define _SOUND_H_
+
+#define BGM 0
+#define SHOT_A 1
+#define SHOT_B 2
+#define SHOT_C 3
+#define RING 4
+#define NEW 5
+#define JIKIOUT 6
+#define BOM 7
+
+#define SE_VOLUME 60
+
+ #define LASER_A 4
+ #define LASER_C 5
+ #define JIKIOUT 6
+
+#define VH_NAME "\\DATA\\SOUND\\STD0.VH;1"
+#define VB_NAME "\\DATA\\SOUND\\STD0.VB;1"
+#define SQVH_ADDR (unsigned char*)0x80180000L
+#define SQVB_ADDR (unsigned char*)0x80190000L
+#define SQ_ADDR   (unsigned long*)0x80170000L
+
+extern void Soundss();
+extern void SoundPlay(int no);
+extern void SoundStop();
+extern int done ;
+extern void poked( int sig) ;
+//_______________________________
+extern void InitSdlMixer(void);
+extern void LoadSdlMixer(void);
+extern void FreeSdlMixer(void);
+extern void PlaySdlMixer(int freq, int ch );
+extern void PauseSdlMixer(int ch);
+extern void ResumeSdlMixer(int ch);
+extern void InitVolume(void);
+extern void TimeSdlMixer(int fleq, int ch, int time);
+//______________________________
+
+extern int se_voice[9];
+extern int vab[10];
+extern int seq[4];
+extern int vb_addr[10];
+
+extern unsigned char *buf;
+extern int vh_addr[10];
+
+#endif				// _SOUND_H_
Binary file sound/NEW.wav has changed
Binary file sound/bomber.wav has changed
Binary file sound/jikiout.wav has changed
Binary file sound/ring.wav has changed
Binary file sound/sample.wav has changed
Binary file sound/shota.wav has changed
Binary file sound/shotb.wav has changed
Binary file sound/shotc.wav has changed