]>
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 wxSndFileCodec::m_mmerror
= wxMMFILE_INVALID
;
91 READ_STRING(chunk_name
, 4);
92 if (chunk_name
!= "FORM")
94 m_istream
->SeekI(4, wxFromCurrent
);
96 READ_STRING(chunk_name
, 4);
97 if (chunk_name
!= "AIFF" && chunk_name
!= "AIFC")
100 // To check whether the file is good
103 m_sndformat
.SetSampleRate(0);
104 while (!m_spos
|| !m_sndformat
.GetSampleRate()) {
105 READ_STRING(chunk_name
, 4);
108 if (chunk_name
== "SSND")
110 if (chunk_name
== "COMM")
113 m_istream
->SeekI(m_chunksize
, wxFromCurrent
);
116 m_sndmode
= wxSND_OUTPUT
;
118 wxUint32 sec1
= m_slen
/ m_sndformat
.GetCodec()->GetByteRate(),
121 m_sndtime
.hours
= sec1
/ 3600;
122 m_sndtime
.minutes
= sec2
/ 60;
123 m_sndtime
.seconds
= sec2
% 60;
125 wxSndFileCodec::m_mmerror
= wxMMFILE_NOERROR
;
127 m_istream
->SeekI(m_spos
, wxFromStart
);
128 wxSndFileCodec::m_fstate
= wxSFILE_PREPARED_TO_PLAY
;
133 void wxSndAiffCodec::ParseCOMM()
135 wxDataInputStream
data_s(*m_istream
);
138 wxUint32 srate
, num_samples
;
145 srate
= (wxUint32
)data_s
.ReadDouble();
146 m_sndformat
.SetSampleRate(srate
);
147 m_sndformat
.SetBps(bps
);
148 m_sndformat
.SetChannels(channels
);
149 m_sndformat
.SetByteOrder(wxSND_SAMPLE_BE
);
150 m_sndformat
.SetSign(wxSND_SAMPLE_UNSIGNED
);
151 ChangeCodec(WXSOUND_PCM
);
153 m_istream
->SeekI(m_chunksize
-18, wxFromCurrent
);
156 void wxSndAiffCodec::ParseSSND()
158 wxDataInputStream
data_s(*m_istream
);
162 m_istream
->SeekI(4, wxFromCurrent
);
164 m_slen
= m_chunksize
- m_spos
;
165 m_spos
+= m_istream
->TellI();
168 wxSndAiffCodec::~wxSndAiffCodec()
172 bool wxSndAiffCodec::OnNeedData(char *buf
, wxUint32 size
)
174 m_istream
->Read(buf
, size
);
178 bool wxSndAiffCodec::OnWriteData(char *buf
, wxUint32 size
)
180 return ( !(m_ostream
->Write(buf
, size
).LastError()) );
183 void wxSndAiffCodec::WriteCOMM()
186 wxDataOutputStream data_s(*m_ostream);
189 wxUint32 srate, num_samples;
193 WRITE32(m_chunksize);
194 channels = m_sndformat.GetChannels();
195 srate = m_sndformat.GetSampleRate();
196 bps = m_sndformat.GetBps();
199 WRITE32(num_samples);
202 data_s.WriteDouble((double)srate);
204 m_sndformat.SetByteOrder(wxSND_SAMPLE_BE);
205 m_sndformat.SetSign(wxSND_SAMPLE_UNSIGNED);
206 ChangeCodec(WXSOUND_PCM);
210 void wxSndAiffCodec::WriteSSND(wxUint32 fsize
)
216 // WRITE32(dummy ??);
218 m_slen = m_chunksize - m_spos;
219 m_spos += m_istream->TellI();
224 bool wxSndAiffCodec::PrepareToRecord(wxUint32 m_fsize
)
226 wxUint32 total_size
= m_fsize
+ 0;
229 m_ostream
->Write("FORM", 4);
232 m_ostream
->Write("AIFF", 4);
240 void wxSndAiffCodec::SetFile(wxInputStream
& s
, bool preload
, bool seekable
)
242 wxMMediaFile::SetFile(s
, preload
, seekable
);
247 void wxSndAiffCodec::SetFile(wxOutputStream
& s
, bool seekable
)
249 wxMMediaFile::SetFile(s
, seekable
);