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
182
183
184
185
186
187
188
|
/***************************************************************************
spu.c - description
-------------------
begin : Sun Jan 12 2003
copyright : (C) 2003 by Pete Bernert
email : BlackDove@addcom.de
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. See also the license.txt file for *
* additional informations. *
* *
***************************************************************************/
//*************************************************************************//
// History of changes:
//
// 2003/03/01 - Pete
// - added mono mode
//
// 2003/01/12 - Pete
// - added recording funcs (win version only)
//
//*************************************************************************//
#include "stdafx.h"
#ifdef _WINDOWS
#include <mmsystem.h>
#include "resource.h"
#include "externals.h"
#define _IN_RECORD
#include "record.h"
////////////////////////////////////////////////////////////////////////
int iDoRecord=0;
HMMIO hWaveFile=NULL;
MMCKINFO mmckMain;
MMCKINFO mmckData;
char szFileName[256];
////////////////////////////////////////////////////////////////////////
void RecordStart()
{
WAVEFORMATEX pcmwf;
// setup header in the same format as our directsound stream
memset(&pcmwf,0,sizeof(WAVEFORMATEX));
pcmwf.wFormatTag = WAVE_FORMAT_PCM;
if(iDisStereo)
{
pcmwf.nChannels = 1;
pcmwf.nBlockAlign = 2;
}
else
{
pcmwf.nChannels = 2;
pcmwf.nBlockAlign = 4;
}
pcmwf.nSamplesPerSec = 44100;
pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign;
pcmwf.wBitsPerSample = 16;
// create file
hWaveFile=mmioOpen(szFileName,NULL,MMIO_CREATE|MMIO_WRITE|MMIO_EXCLUSIVE | MMIO_ALLOCBUF);
if(!hWaveFile) return;
// setup WAVE, fmt and data chunks
memset(&mmckMain,0,sizeof(MMCKINFO));
mmckMain.fccType = mmioFOURCC('W','A','V','E');
mmioCreateChunk(hWaveFile,&mmckMain,MMIO_CREATERIFF);
memset(&mmckData,0,sizeof(MMCKINFO));
mmckData.ckid = mmioFOURCC('f','m','t',' ');
mmckData.cksize = sizeof(WAVEFORMATEX);
mmioCreateChunk(hWaveFile,&mmckData,0);
mmioWrite(hWaveFile,(char*)&pcmwf,sizeof(WAVEFORMATEX));
mmioAscend(hWaveFile,&mmckData,0);
mmckData.ckid = mmioFOURCC('d','a','t','a');
mmioCreateChunk(hWaveFile,&mmckData,0);
}
////////////////////////////////////////////////////////////////////////
void RecordStop()
{
// first some check, if recording is running
iDoRecord=0;
if(!hWaveFile) return;
// now finish writing & close the wave file
mmioAscend(hWaveFile,&mmckData,0);
mmioAscend(hWaveFile,&mmckMain,0);
mmioClose(hWaveFile,0);
// init var
hWaveFile=NULL;
}
////////////////////////////////////////////////////////////////////////
void RecordBuffer(unsigned char* pSound,long lBytes)
{
// write the samples
if(hWaveFile) mmioWrite(hWaveFile,pSound,lBytes);
}
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
BOOL CALLBACK RecordDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
//--------------------------------------------------// init
case WM_INITDIALOG:
{
SetDlgItemText(hW,IDC_WAVFILE,"C:\\PEOPS.WAV"); // init filename edit
ShowCursor(TRUE); // mmm... who is hiding it? main emu? tsts
return TRUE;
}
//--------------------------------------------------// destroy
case WM_DESTROY:
{
RecordStop();
}break;
//--------------------------------------------------// command
case WM_COMMAND:
{
if(wParam==IDCANCEL) iRecordMode=2; // cancel? raise flag for destroying the dialog
if(wParam==IDC_RECORD) // record start/stop?
{
if(IsWindowEnabled(GetDlgItem(hW,IDC_WAVFILE))) // not started yet (edit is not disabled):
{
GetDlgItemText(hW,IDC_WAVFILE,szFileName,255);// get filename
RecordStart(); // start recording
if(hWaveFile) // start was ok?
{ // -> disable filename edit, change text, raise flag
EnableWindow(GetDlgItem(hW,IDC_WAVFILE),FALSE);
SetDlgItemText(hW,IDC_RECORD,"Stop recording");
iDoRecord=1;
}
else MessageBeep(0xFFFFFFFF); // error starting recording? BEEP
}
else // stop recording?
{
RecordStop(); // -> just do it
EnableWindow(GetDlgItem(hW,IDC_WAVFILE),TRUE);// -> enable filename edit again
SetDlgItemText(hW,IDC_RECORD,"Start recording");
}
SetFocus(hWMain);
}
}break;
//--------------------------------------------------// size
case WM_SIZE:
if(wParam==SIZE_MINIMIZED) SetFocus(hWMain); // if we get minimized, set the foxus to the main window
break;
//--------------------------------------------------// setcursor
case WM_SETCURSOR:
{
SetCursor(LoadCursor(NULL,IDC_ARROW)); // force the arrow
return TRUE;
}
//--------------------------------------------------//
}
return FALSE;
}
////////////////////////////////////////////////////////////////////////
#endif
|