gpfce patch
[fceu.git] / drivers / win / wave.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 */
20
21static int16 MoBuffer[2048];
22static int wsize;
23void WriteWaveData(int32 *Buffer, int Count)
24{
25 int P;
26
27 for(P=0;P<Count;P++)
28 MoBuffer[P]=Buffer[P];
29 wsize+=fwrite(MoBuffer,1,Count<<1,soundlog);
30}
31
32static int CloseWave(void)
33{
34 int s;
35
36 if(!soundlog) return 0;
37 s=ftell(soundlog)-8;
38 fseek(soundlog,4,SEEK_SET);
39 fputc(s&0xFF,soundlog);
40 fputc((s>>8)&0xFF,soundlog);
41 fputc((s>>16)&0xFF,soundlog);
42 fputc((s>>24)&0xFF,soundlog);
43
44 fseek(soundlog,0x28,SEEK_SET);
45 s=wsize;
46 fputc(s&0xFF,soundlog);
47 fputc((s>>8)&0xFF,soundlog);
48 fputc((s>>16)&0xFF,soundlog);
49 fputc((s>>24)&0xFF,soundlog);
50
51 fclose(soundlog);
52 soundlog=0;
53 return 1;
54}
55int WriteWaveHeader(FILE *fp)
56{
57 int r;
58 fputs("RIFF",fp);
59 fseek(fp,4,SEEK_CUR); // Skip size
60 fputs("WAVEfmt ",fp);
61 fputc(0x10,fp);
62 fputc(0,fp);
63 fputc(0,fp);
64 fputc(0,fp);
65
66 fputc(1,fp); // PCM
67 fputc(0,fp);
68 fputc(1,fp); // Monophonic
69 fputc(0,fp);
70
71 r=44100;
72 fputc(r&0xFF,fp);
73 fputc((r>>8)&0xFF,fp);
74 fputc((r>>16)&0xFF,fp);
75 fputc((r>>24)&0xFF,fp);
76 r<<=1;
77 fputc(r&0xFF,fp);
78 fputc((r>>8)&0xFF,fp);
79 fputc((r>>16)&0xFF,fp);
80 fputc((r>>24)&0xFF,fp);
81 fputc(2,fp);
82 fputc(0,fp);
83 fputc(16,fp);
84 fputc(0,fp);
85
86 fputs("data",fp);
87 fseek(fp,4,SEEK_CUR);
88
89 return 1;
90}
91
92int StartSoundLog(char *str)
93{
94 wsize=0;
95 soundlog=fopen(str,"wb");
96 if(soundlog)
97 return WriteWaveHeader(soundlog);
98 else
99 return 0;
100}
101int CreateSoundSave(void)
102{
103 const char filter[]="MS WAVE(*.wav)\0*.wav\0";
104 char nameo[2048];
105 OPENFILENAME ofn;
106
107 if(soundlog)
108 {
109 CloseWave();
110 return 0;
111 }
112
113 memset(&ofn,0,sizeof(ofn));
114 ofn.lStructSize=sizeof(ofn);
115 ofn.hInstance=fceu_hInstance;
116 ofn.lpstrTitle="Log Sound As...";
117 ofn.lpstrFilter=filter;
118 nameo[0]=0;
119 ofn.lpstrFile=nameo;
120 ofn.nMaxFile=256;
121 ofn.Flags=OFN_EXPLORER|OFN_FILEMUSTEXIST|OFN_HIDEREADONLY;
122 if(GetSaveFileName(&ofn))
123 return StartSoundLog(nameo);
124 return 0;
125}