]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndaiff.cpp
1 ////////////////////////////////////////////////////////////////////////////////
4 // Author: Guilhem Lavaux
6 // Updated: February 1998
7 // Copyright: (C) 1997, 1998, Guilhem Lavaux
8 // License: wxWindows license
9 ////////////////////////////////////////////////////////////////////////////////
11 #pragma implementation "sndaiff.h"
15 #include "wx/wxprec.h"
19 #include "wx/datstrm.h"
27 #define READ_DATA(n) m_istream->Read(tmp_buf,n)
28 #define WRITE_DATA(n) m_ostream->Write(tmp_buf,n)
30 #define READ_STRING(s,n) \
35 #define WRITE_STRING(s,n) WRITE_DATA((const char *)s, n)
39 i = (unsigned long)tmp_buf[3] | \
40 ((unsigned long)tmp_buf[2] << 8) | \
41 ((unsigned long)tmp_buf[1] << 16) | \
42 ((unsigned long)tmp_buf[0] << 24);
45 tmp_buf[3] = i & 0xFF; \
46 tmp_buf[2] = (i >> 8) & 0xFF; \
47 tmp_buf[1] = (i >> 16) & 0xFF; \
48 tmp_buf[0] = (i >> 24) & 0xFF; \
53 i = (unsigned short)tmp_buf[1] | \
54 ((unsigned short)tmp_buf[0] << 8);
56 wxSndAiffCodec::wxSndAiffCodec()
62 wxSndAiffCodec::wxSndAiffCodec(wxOutputStream
& s
, bool seekable
)
63 : wxSndFileCodec(s
, seekable
)
70 wxSndAiffCodec::wxSndAiffCodec(wxInputStream
& s
, bool preload
, bool seekable
)
71 : wxSndFileCodec(s
, preload
, seekable
)
78 wxSndAiffCodec::wxSndAiffCodec(const wxString
& fname
)
79 : wxSndFileCodec(fname
)
84 wxUint32
wxSndAiffCodec::PrepareToPlay()
89 m_istream
->SeekI(0, wxFromStart
);
91 wxSndFileCodec::m_mmerror
= wxMMFILE_INVALID
;
93 READ_STRING(chunk_name
, 4);
94 if (chunk_name
!= "FORM")
96 m_istream
->SeekI(4, wxFromCurrent
);
98 READ_STRING(chunk_name
, 4);
99 if (chunk_name
!= "AIFF" && chunk_name
!= "AIFC")
102 // To check whether the file is good
105 m_sndformat
.SetSampleRate(0);
107 READ_STRING(chunk_name
, 4);
110 if (chunk_name
== "SSND")
112 if (chunk_name
== "COMM")
115 m_istream
->SeekI(m_chunksize
, wxFromCurrent
);
117 if (m_spos
&& m_sndformat
.GetSampleRate())
121 m_sndmode
= wxSND_OUTPUT
;
123 wxUint32 sec1
= m_slen
/ m_sndformat
.GetCodec()->GetByteRate(),
126 m_sndtime
.hours
= sec1
/ 3600;
127 m_sndtime
.minutes
= sec2
/ 60;
128 m_sndtime
.seconds
= sec2
% 60;
130 wxSndFileCodec::m_mmerror
= wxMMFILE_NOERROR
;
132 m_istream
->SeekI(m_spos
, wxFromStart
);
136 void wxSndAiffCodec::ParseCOMM()
138 wxDataInputStream
data_s(*m_istream
);
141 wxUint32 srate
, num_samples
;
148 srate
= (wxUint32
)data_s
.ReadDouble();
149 m_sndformat
.SetSampleRate(srate
);
150 m_sndformat
.SetBps(bps
);
151 m_sndformat
.SetChannels(channels
);
152 m_sndformat
.SetByteOrder(wxSND_SAMPLE_BE
);
153 m_sndformat
.SetSign(wxSND_SAMPLE_UNSIGNED
);
154 ChangeCodec(WXSOUND_PCM
);
156 m_istream
->SeekI(m_chunksize
-18, wxFromCurrent
);
159 void wxSndAiffCodec::ParseSSND()
161 wxDataInputStream
data_s(*m_istream
);
165 m_istream
->SeekI(4, wxFromCurrent
);
167 m_slen
= m_chunksize
- m_spos
;
168 m_spos
+= m_istream
->TellI();
171 wxSndAiffCodec::~wxSndAiffCodec()
175 bool wxSndAiffCodec::OnNeedData(char *buf
, wxUint32 size
)
177 m_istream
->Read(buf
, size
);
181 bool wxSndAiffCodec::OnWriteData(char *buf
, wxUint32 size
)
183 return ( !(m_ostream
->Write(buf
, size
).LastError()) );
186 bool wxSndAiffCodec::PrepareToRecord(wxUint32 m_fsize
)
192 m_ostream->SeekO(0, wxBeginPosition);
194 m_ostream->Write("FORM", 4);
197 m_ostream->Write("AIFF", 4);
206 void wxSndAiffCodec::SetFile(wxInputStream
& s
, bool preload
, bool seekable
)
208 wxMMediaFile::SetFile(s
, preload
, seekable
);
213 void wxSndAiffCodec::SetFile(wxOutputStream
& s
, bool seekable
)
215 wxMMediaFile::SetFile(s
, seekable
);