-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathpceth2_snd.c
More file actions
181 lines (156 loc) · 3.99 KB
/
pceth2_snd.c
File metadata and controls
181 lines (156 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
* pceth2 - SE、BGM関連
*
* (c)2005 てとら★ぽっと
*
* 2005/05/07 開発開始
* 2005/05/27 Win側pceth2bin2に対応(スクリプト形式を多少変更
*/
#include <string.h>
#include <piece.h>
#include "zurapce/zurapce.h"
#include "muslib2.h"
#include "common.h"
#include "pceth2_snd.h"
#include "pceth2_arc.h"
#include "pceth2_str.h"
extern SAVE_DATA play;
//=============================================================================
// PCEWAVEINFOを作成、再生、リピート再生、解放
//=============================================================================
/*
typedef struct tagPCEWAVEINFO {
volatile unsigned char stat; // 0 ステータス
unsigned char type; // 1 データ形式
unsigned short resv; // 2 予約
const void *pData; // 4 データへのポインタ
unsigned long len; // 8 データの長さ(サンプル数)
struct tagPCEWAVEINFO *next; // 12 次へのポインタ
void (*pfEndProc)( struct tagPCEWAVEINFO *); // 16 終了時コールバック←これを使ってリピート再生、解放を行います。
} PCEWAVEINFO;
*/
static PCEWAVEINFO pwav;
static BYTE *ppd;
/*
* リピート再生用コールバック
*
* *pWav コールバック呼び出し元PCEWACEINFOのポインタ
*/
static void Play_PieceWaveEx(PCEWAVEINFO *pWav)
{
pceWaveDataOut(SND_CH, pWav);
}
/*
* 解放用コールバック
*
* *pWav コールバック呼び出し元PCEWACEINFOのポインタ
*/
static void Stop_PieceWaveEx(PCEWAVEINFO *pWav)
{
Stop_PieceWave();
}
/*
* PCEWAVEINFO作成拡張(pfEndProcでリピート再生)
*
* *pWav PCEWAVEDATA構造体のポインタ
* *data メモリ上のppdファイルデータ
* rep リピートフラグ(0=なし/0以外=リピート)
*/
static void Get_PieceWaveEx(PCEWAVEINFO *pWav, BYTE *data, const int rep)
{
PceWaveInfo_Construct(pWav, data);
if (rep) { // リピート
pWav->pfEndProc = Play_PieceWaveEx;
} else { // 再生終了
pWav->pfEndProc = Stop_PieceWaveEx;
}
}
//=============================================================================
// SE再生、停止
//=============================================================================
void Play_PieceWave(const char *fName, int rep)
{
Stop_PieceWave(&pwav); // 前の再生が有る無し問わず止める
ppd = fpk_getEntryData((char*)fName, NULL, NULL);
if (ppd != NULL) {
Get_PieceWaveEx(&pwav, ppd, rep);
Play_PieceWaveEx(&pwav);
}
}
void Stop_PieceWave()
{
pceWaveAbort(SND_CH);
pceHeapFree(ppd);
ppd = NULL;
}
//=============================================================================
// SE再生(ファイルがなければ停止)
//=============================================================================
/*
* SEを読み込む SE_0000.ppd,0
*
* *s スクリプトデータ
*
* return 1(引き続き実行)
*/
#define FNAMELEN_SE 11
int pceth2_loadSE(SCRIPT_DATA *s)
{
char buf[FNAMELEN_SE + 1];
// ファイル名をバッファにコピー
pceth2_strcpy(buf, s, FNAMELEN_SE);
s->p++; // ,
Play_PieceWave(buf, (int)(*(s->data + s->p++) - '0'));
return 1;
}
//=============================================================================
// pmd再生、停止
//=============================================================================
// ヒープのフラグメンテーションを回避するため、固定で確保
// このサイズを超えることは無いと思うが、超えたら増やすこと
// (v1.04 時点、最大は M35.pmd の 3,998)
static BYTE pmd[4096];
/*
* BGM再生
*
* *fName pmdファイル名
*/
void Play_PieceMML(const char *fName)
{
if (strcmp(play.pmdname, fName) != 0) {
Stop_PieceMML();
strcpy(play.pmdname, fName);
if (fpk_getEntryData(play.pmdname, NULL, pmd)) {
PlayMusic(pmd);
} else {
*play.pmdname = '\0';
}
}
}
/*
* BGM停止
*/
void Stop_PieceMML()
{
*play.pmdname = '\0';
StopMusic();
pceWaveAbort(BGM_CH);
}
//=============================================================================
// BGM再生(ファイルがなければ停止)
//=============================================================================
/*
* BGMを再生 M00.pmd
*
* *s スクリプトデータ
*
* return 1(引き続き実行)
*/
#define FNAMELEN_BGM 7
int pceth2_loadBGM(SCRIPT_DATA *s)
{
char buf[FNAMELEN_BGM + 1];
pceth2_strcpy(buf, s, FNAMELEN_BGM);
Play_PieceMML(buf);
return 1;
}