]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/mmriff.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "mmriff.h"
26 wxRiffCodec::wxRiffCodec() :
27 riff_i_stream(NULL
), riff_o_stream(NULL
), chunk_length(INVALID_CHUNK_LEN
)
31 wxRiffCodec::wxRiffCodec(wxInputStream
& s
) :
32 riff_i_stream(&s
), riff_o_stream(NULL
), chunk_length(INVALID_CHUNK_LEN
)
36 wxRiffCodec::wxRiffCodec(wxOutputStream
& s
) :
37 riff_i_stream(NULL
), riff_o_stream(&s
), chunk_length(INVALID_CHUNK_LEN
)
41 wxRiffCodec::~wxRiffCodec()
45 bool wxRiffCodec::RiffReset(wxUint8 mode
)
51 riff_i_stream
->SeekI(0);
52 chunk_length
= INVALID_CHUNK_LEN
;
57 riff_o_stream
->SeekO(0);
58 chunk_length
= INVALID_CHUNK_LEN
;
64 bool wxRiffCodec::ReadData(void *data
, wxUint32 size
)
69 if (chunk_length
!= INVALID_CHUNK_LEN
&& (wxUint32
)chunk_length
< size
) {
70 riff_error
= wxMMFILE_EOF
;
73 if (chunk_length
!= INVALID_CHUNK_LEN
)
76 bool ret
= (riff_i_stream
->Read((char *)data
, size
).LastRead() == size
);
81 bool wxRiffCodec::WriteData(void *data
, wxUint32 size
)
86 if (chunk_length
< size
) {
87 riff_error
= wxMMFILE_EOF
;
92 riff_o_stream
->Write(data
, size
);
97 bool wxRiffCodec::Read32(wxUint32
& i32
)
101 if (!ReadData(i8
, 4))
105 i32
|= ((wxUint32
)i8
[1]) << 8;
106 i32
|= ((wxUint32
)i8
[2]) << 16;
107 i32
|= ((wxUint32
)i8
[3]) << 24;
112 bool wxRiffCodec::Write32(wxUint32 i32
)
117 i8
[1] = (i32
>> 8) & 0xff;
118 i8
[2] = (i32
>> 16) & 0xff;
119 i8
[3] = (i32
>> 24) & 0xff;
121 if (!WriteData(i8
, 4))
127 bool wxRiffCodec::Read16(wxUint16
& i16
)
131 if (!ReadData(i8
, 2))
135 i16
|= ((wxUint16
)i8
[1]) << 8;
140 bool wxRiffCodec::Write16(wxUint16 i16
)
145 i8
[1] = (i16
>> 8) & 0xff;
147 if (!WriteData(i8
, 2))
153 bool wxRiffCodec::Skip(wxUint32 skip
)
155 if (!riff_i_stream
|| (chunk_length
!= INVALID_CHUNK_LEN
&& (wxInt32
)skip
> chunk_length
))
158 if (chunk_length
!= INVALID_CHUNK_LEN
)
159 chunk_length
-= skip
;
160 riff_i_stream
->SeekI(skip
, wxFromCurrent
);
165 bool wxRiffCodec::CreateChunk(const wxString
& name
, wxUint32 size
)
167 if (!riff_o_stream
|| name
.Length() != 4)
170 if (riff_o_stream
->Write(name
.GetData(), 4).LastError()) {
171 riff_error
= wxMMFILE_EOF
;
175 chunk_length
= size
+4;
177 return Write32(size
);
180 bool wxRiffCodec::FindChunk(const wxString
& name
, bool from_here
)
188 if (chunk_length
!= INVALID_CHUNK_LEN
&& !from_here
)
191 if (riff_i_stream
->Read(buf
, 4).LastError()) {
192 riff_error
= wxMMFILE_EOF
;
196 chunk_length
= INVALID_CHUNK_LEN
;
197 if (!Read32(chunk_length
)) {
198 riff_error
= wxMMFILE_EOF
;
204 if ((!name
.IsNull()) && str2
!= name
) {