1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2004 Forgotten and the VBA development team
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 m_streamCompressed
= NULL
;
37 AVIStreamClose(m_streamSound
);
39 if(m_streamCompressed
)
40 AVIStreamClose(m_streamCompressed
);
43 AVIStreamClose(m_stream
);
51 void AVIWrite::SetVideoFormat(BITMAPINFOHEADER
*bh
)
53 // force size to 0x28 to avoid extra fields
54 memcpy(&m_bitmap
, bh
, 0x28);
57 void AVIWrite::SetSoundFormat(WAVEFORMATEX
*format
)
59 memcpy(&m_soundFormat
, format
, sizeof(WAVEFORMATEX
));
60 ZeroMemory(&m_soundHeader
, sizeof(AVISTREAMINFO
));
61 // setup the sound stream header
62 m_soundHeader
.fccType
= streamtypeAUDIO
;
63 m_soundHeader
.dwQuality
= (DWORD
)-1;
64 m_soundHeader
.dwScale
= format
->nBlockAlign
;
65 m_soundHeader
.dwInitialFrames
= 1;
66 m_soundHeader
.dwRate
= format
->nAvgBytesPerSec
;
67 m_soundHeader
.dwSampleSize
= format
->nBlockAlign
;
69 // create the sound stream
70 if(FAILED(AVIFileCreateStream(m_file
, &m_streamSound
, &m_soundHeader
))) {
75 // setup the sound stream format
76 if(FAILED(AVIStreamSetFormat(m_streamSound
, 0 , (void *)&m_soundFormat
,
77 sizeof(WAVEFORMATEX
)))) {
83 bool AVIWrite::Open(const char *filename
)
85 // create the AVI file
86 if(FAILED(AVIFileOpen(&m_file
,
93 // setup the video stream information
94 ZeroMemory(&m_header
, sizeof(AVISTREAMINFO
));
95 m_header
.fccType
= streamtypeVIDEO
;
97 m_header
.dwRate
= m_fps
;
98 m_header
.dwSuggestedBufferSize
= m_bitmap
.biSizeImage
;
100 // create the video stream
101 if(FAILED(AVIFileCreateStream(m_file
,
108 ZeroMemory(&m_options
, sizeof(AVICOMPRESSOPTIONS
));
109 m_arrayOptions
[0] = &m_options
;
111 // call the dialog to setup the compress options to be used
112 if(!AVISaveOptions(AfxGetApp()->m_pMainWnd
->GetSafeHwnd(), 0, 1, &m_stream
, m_arrayOptions
)) {
117 // create the compressed stream
118 if(FAILED(AVIMakeCompressedStream(&m_streamCompressed
, m_stream
, &m_options
, NULL
))) {
123 // setup the video stream format
124 if(FAILED( AVIStreamSetFormat(m_streamCompressed
, 0,
127 m_bitmap
.biClrUsed
* sizeof(RGBQUAD
)))) {
135 bool AVIWrite::AddSound(const char *sound
, int len
)
137 // return if we failed somewhere already
141 int samples
= len
/ m_soundFormat
.nBlockAlign
;
143 if(FAILED(AVIStreamWrite(m_streamSound
,
154 m_samplesSound
+= samples
;
159 bool AVIWrite::AddFrame(const int frame
, const char *bmp
)
164 // write the frame to the video stream
165 if(FAILED(AVIStreamWrite(m_streamCompressed
,
169 m_bitmap
.biSizeImage
,
179 bool AVIWrite::IsSoundAdded()
181 return m_streamSound
!= NULL
;
184 void AVIWrite::SetFPS(int f
)