| 1 |
/*************************************************************************** |
| 2 |
spu.c - description |
| 3 |
------------------- |
| 4 |
begin : Sun Jan 12 2003 |
| 5 |
copyright : (C) 2003 by Pete Bernert |
| 6 |
email : [email protected] |
| 7 |
***************************************************************************/ |
| 8 |
|
| 9 |
/*************************************************************************** |
| 10 |
* * |
| 11 |
* This program is free software; you can redistribute it and/or modify * |
| 12 |
* it under the terms of the GNU General Public License as published by * |
| 13 |
* the Free Software Foundation; either version 2 of the License, or * |
| 14 |
* (at your option) any later version. See also the license.txt file for * |
| 15 |
* additional informations. * |
| 16 |
* * |
| 17 |
***************************************************************************/ |
| 18 |
|
| 19 |
//*************************************************************************// |
| 20 |
// History of changes: |
| 21 |
// |
| 22 |
// 2003/03/01 - Pete |
| 23 |
// - added mono mode |
| 24 |
// |
| 25 |
// 2003/01/12 - Pete |
| 26 |
// - added recording funcs (win version only) |
| 27 |
// |
| 28 |
//*************************************************************************// |
| 29 |
|
| 30 |
#include "stdafx.h" |
| 31 |
|
| 32 |
#ifdef _WINDOWS |
| 33 |
|
| 34 |
#include <mmsystem.h> |
| 35 |
#include "resource.h" |
| 36 |
#include "externals.h" |
| 37 |
|
| 38 |
#define _IN_RECORD |
| 39 |
|
| 40 |
#include "record.h" |
| 41 |
|
| 42 |
//////////////////////////////////////////////////////////////////////// |
| 43 |
|
| 44 |
int iDoRecord=0; |
| 45 |
HMMIO hWaveFile=NULL; |
| 46 |
MMCKINFO mmckMain; |
| 47 |
MMCKINFO mmckData; |
| 48 |
char szFileName[256]; |
| 49 |
|
| 50 |
//////////////////////////////////////////////////////////////////////// |
| 51 |
|
| 52 |
void RecordStart() |
| 53 |
{ |
| 54 |
WAVEFORMATEX pcmwf; |
| 55 |
|
| 56 |
// setup header in the same format as our directsound stream |
| 57 |
memset(&pcmwf,0,sizeof(WAVEFORMATEX)); |
| 58 |
pcmwf.wFormatTag = WAVE_FORMAT_PCM; |
| 59 |
|
| 60 |
if(iDisStereo) |
| 61 |
{ |
| 62 |
pcmwf.nChannels = 1; |
| 63 |
pcmwf.nBlockAlign = 2; |
| 64 |
} |
| 65 |
else |
| 66 |
{ |
| 67 |
pcmwf.nChannels = 2; |
| 68 |
pcmwf.nBlockAlign = 4; |
| 69 |
} |
| 70 |
|
| 71 |
pcmwf.nSamplesPerSec = 44100; |
| 72 |
pcmwf.nAvgBytesPerSec = pcmwf.nSamplesPerSec * pcmwf.nBlockAlign; |
| 73 |
pcmwf.wBitsPerSample = 16; |
| 74 |
|
| 75 |
// create file |
| 76 |
hWaveFile=mmioOpen(szFileName,NULL,MMIO_CREATE|MMIO_WRITE|MMIO_EXCLUSIVE | MMIO_ALLOCBUF); |
| 77 |
if(!hWaveFile) return; |
| 78 |
|
| 79 |
// setup WAVE, fmt and data chunks |
| 80 |
memset(&mmckMain,0,sizeof(MMCKINFO)); |
| 81 |
mmckMain.fccType = mmioFOURCC('W','A','V','E'); |
| 82 |
|
| 83 |
mmioCreateChunk(hWaveFile,&mmckMain,MMIO_CREATERIFF); |
| 84 |
|
| 85 |
memset(&mmckData,0,sizeof(MMCKINFO)); |
| 86 |
mmckData.ckid = mmioFOURCC('f','m','t',' '); |
| 87 |
mmckData.cksize = sizeof(WAVEFORMATEX); |
| 88 |
|
| 89 |
mmioCreateChunk(hWaveFile,&mmckData,0); |
| 90 |
mmioWrite(hWaveFile,(char*)&pcmwf,sizeof(WAVEFORMATEX)); |
| 91 |
mmioAscend(hWaveFile,&mmckData,0); |
| 92 |
|
| 93 |
mmckData.ckid = mmioFOURCC('d','a','t','a'); |
| 94 |
mmioCreateChunk(hWaveFile,&mmckData,0); |
| 95 |
} |
| 96 |
|
| 97 |
//////////////////////////////////////////////////////////////////////// |
| 98 |
|
| 99 |
void RecordStop() |
| 100 |
{ |
| 101 |
// first some check, if recording is running |
| 102 |
iDoRecord=0; |
| 103 |
if(!hWaveFile) return; |
| 104 |
|
| 105 |
// now finish writing & close the wave file |
| 106 |
mmioAscend(hWaveFile,&mmckData,0); |
| 107 |
mmioAscend(hWaveFile,&mmckMain,0); |
| 108 |
mmioClose(hWaveFile,0); |
| 109 |
|
| 110 |
// init var |
| 111 |
hWaveFile=NULL; |
| 112 |
} |
| 113 |
|
| 114 |
//////////////////////////////////////////////////////////////////////// |
| 115 |
|
| 116 |
void RecordBuffer(unsigned char* pSound,long lBytes) |
| 117 |
{ |
| 118 |
// write the samples |
| 119 |
if(hWaveFile) mmioWrite(hWaveFile,pSound,lBytes); |
| 120 |
} |
| 121 |
|
| 122 |
//////////////////////////////////////////////////////////////////////// |
| 123 |
//////////////////////////////////////////////////////////////////////// |
| 124 |
//////////////////////////////////////////////////////////////////////// |
| 125 |
|
| 126 |
BOOL CALLBACK RecordDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) |
| 127 |
{ |
| 128 |
switch(uMsg) |
| 129 |
{ |
| 130 |
//--------------------------------------------------// init |
| 131 |
case WM_INITDIALOG: |
| 132 |
{ |
| 133 |
SetDlgItemText(hW,IDC_WAVFILE,"C:\\PEOPS.WAV"); // init filename edit |
| 134 |
ShowCursor(TRUE); // mmm... who is hiding it? main emu? tsts |
| 135 |
return TRUE; |
| 136 |
} |
| 137 |
//--------------------------------------------------// destroy |
| 138 |
case WM_DESTROY: |
| 139 |
{ |
| 140 |
RecordStop(); |
| 141 |
}break; |
| 142 |
//--------------------------------------------------// command |
| 143 |
case WM_COMMAND: |
| 144 |
{ |
| 145 |
if(wParam==IDCANCEL) iRecordMode=2; // cancel? raise flag for destroying the dialog |
| 146 |
|
| 147 |
if(wParam==IDC_RECORD) // record start/stop? |
| 148 |
{ |
| 149 |
if(IsWindowEnabled(GetDlgItem(hW,IDC_WAVFILE))) // not started yet (edit is not disabled): |
| 150 |
{ |
| 151 |
GetDlgItemText(hW,IDC_WAVFILE,szFileName,255);// get filename |
| 152 |
|
| 153 |
RecordStart(); // start recording |
| 154 |
|
| 155 |
if(hWaveFile) // start was ok? |
| 156 |
{ // -> disable filename edit, change text, raise flag |
| 157 |
EnableWindow(GetDlgItem(hW,IDC_WAVFILE),FALSE); |
| 158 |
SetDlgItemText(hW,IDC_RECORD,"Stop recording"); |
| 159 |
iDoRecord=1; |
| 160 |
} |
| 161 |
else MessageBeep(0xFFFFFFFF); // error starting recording? BEEP |
| 162 |
} |
| 163 |
else // stop recording? |
| 164 |
{ |
| 165 |
RecordStop(); // -> just do it |
| 166 |
EnableWindow(GetDlgItem(hW,IDC_WAVFILE),TRUE);// -> enable filename edit again |
| 167 |
SetDlgItemText(hW,IDC_RECORD,"Start recording"); |
| 168 |
} |
| 169 |
SetFocus(hWMain); |
| 170 |
} |
| 171 |
}break; |
| 172 |
//--------------------------------------------------// size |
| 173 |
case WM_SIZE: |
| 174 |
if(wParam==SIZE_MINIMIZED) SetFocus(hWMain); // if we get minimized, set the foxus to the main window |
| 175 |
break; |
| 176 |
//--------------------------------------------------// setcursor |
| 177 |
case WM_SETCURSOR: |
| 178 |
{ |
| 179 |
SetCursor(LoadCursor(NULL,IDC_ARROW)); // force the arrow |
| 180 |
return TRUE; |
| 181 |
} |
| 182 |
//--------------------------------------------------// |
| 183 |
} |
| 184 |
return FALSE; |
| 185 |
} |
| 186 |
|
| 187 |
//////////////////////////////////////////////////////////////////////// |
| 188 |
#endif |