]>
git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndwav.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 "sndwav.h"
27 wxSndWavCodec::wxSndWavCodec()
28 : wxSndFileCodec(), riff_codec()
33 wxSndWavCodec::wxSndWavCodec(wxOutputStream
& s
, bool seekable
)
34 : wxSndFileCodec(s
, seekable
)
38 riff_codec
= wxRiffCodec(*m_ostream
);
42 wxSndWavCodec::wxSndWavCodec(wxInputStream
& s
, bool preload
, bool seekable
)
43 : wxSndFileCodec(s
, preload
, seekable
)
48 riff_codec
= wxRiffCodec(*m_istream
);
52 wxSndWavCodec::wxSndWavCodec(const wxString
& fname
)
53 : wxSndFileCodec(fname
)
55 riff_codec
= wxRiffCodec(*m_istream
);
59 wxUint32
wxSndWavCodec::PrepareToPlay()
61 if (!riff_codec
.RiffReset(RIFF_READ
))
64 if (!riff_codec
.FindChunk("RIFF", TRUE
)) {
65 wxSndFileCodec::m_mmerror
= wxMMFILE_INVALID
;
70 riff_codec
.ReadData(tmp_buf
, 4);
72 if (wxString("WAVE") != tmp_buf
) {
73 wxSndFileCodec::m_mmerror
= wxMMFILE_INVALID
;
76 if (!riff_codec
.FindChunk("fmt ", TRUE
))
79 riff_codec
.Read16(wav_hdr
.format
);
80 riff_codec
.Read16(wav_hdr
.channels
);
81 riff_codec
.Read32(wav_hdr
.sample_fq
);
82 riff_codec
.Read32(wav_hdr
.byte_p_sec
);
83 riff_codec
.Read16(wav_hdr
.byte_p_spl
);
84 riff_codec
.Read16(wav_hdr
.bits_p_spl
);
86 if (!riff_codec
.FindChunk("data"))
89 m_sndmode
= wxSND_OUTPUT
;
90 ChangeCodec(wav_hdr
.format
);
92 m_sndformat
.SetSampleRate(wav_hdr
.sample_fq
);
93 m_sndformat
.SetBps(wav_hdr
.bits_p_spl
);
94 m_sndformat
.SetChannels(wav_hdr
.channels
);
96 if (wav_hdr
.format
== WXSOUND_PCM
) {
97 m_sndformat
.SetSign(wxSND_SAMPLE_SIGNED
);
98 m_sndformat
.SetByteOrder(wxSND_SAMPLE_LE
);
101 wxUint32 sec1
= riff_codec
.GetChunkLength() / wav_hdr
.byte_p_sec
,
104 m_sndtime
.hours
= sec1
/ 3600;
105 m_sndtime
.minutes
= sec2
/ 60;
106 m_sndtime
.seconds
= sec2
% 60;
108 wxSndFileCodec::m_mmerror
= wxMMFILE_NOERROR
;
109 wxSndFileCodec::m_fstate
= wxSFILE_PREPARED_TO_PLAY
;
111 return riff_codec
.GetChunkLength();
114 wxSndWavCodec::~wxSndWavCodec()
118 bool wxSndWavCodec::OnNeedData(char *buf
, wxUint32 size
)
120 return riff_codec
.ReadData(buf
, size
);
123 bool wxSndWavCodec::OnWriteData(char *buf
, wxUint32 size
)
125 return riff_codec
.WriteData(buf
, size
);
128 bool wxSndWavCodec::PrepareToRecord(wxUint32 m_fsize
)
132 if (!riff_codec
.RiffReset(RIFF_WRITE
))
135 total_size
= 16 + sizeof(wav_hdr
) + m_fsize
;
137 if (!riff_codec
.CreateChunk("RIFF", total_size
))
139 riff_codec
.WriteData("WAVE", 4);
140 if (!riff_codec
.CreateChunk("fmt ", sizeof(wav_hdr
)))
143 wav_hdr
.format
= 1; // PCM_WAV_FORMAT
144 wav_hdr
.channels
= m_sndformat
.GetChannels();
145 wav_hdr
.sample_fq
= m_sndformat
.GetSampleRate();
146 wav_hdr
.byte_p_spl
= (m_sndformat
.GetBps() / 8) * wav_hdr
.channels
;
147 wav_hdr
.byte_p_sec
= m_sndformat
.GetCodec()->GetByteRate();
148 wav_hdr
.bits_p_spl
= m_sndformat
.GetBps();
149 ChangeCodec(WXSOUND_PCM
);
151 if (wav_hdr
.format
== WXSOUND_PCM
) {
152 m_sndformat
.SetSign(wxSND_SAMPLE_SIGNED
);
153 m_sndformat
.SetByteOrder(wxSND_SAMPLE_LE
);
156 riff_codec
.Write16(wav_hdr
.format
);
157 riff_codec
.Write16(wav_hdr
.channels
);
158 riff_codec
.Write32(wav_hdr
.sample_fq
);
159 riff_codec
.Write32(wav_hdr
.byte_p_sec
);
160 riff_codec
.Write16(wav_hdr
.byte_p_spl
);
161 riff_codec
.Write16(wav_hdr
.bits_p_spl
);
163 if (!riff_codec
.CreateChunk("data", m_fsize
))
168 void wxSndWavCodec::SetFile(wxInputStream
& s
, bool preload
, bool seekable
)
170 wxMMediaFile::SetFile(s
, preload
, seekable
);
174 riff_codec
.SetFile((seekable
) ? s
: *m_istream
);
177 void wxSndWavCodec::SetFile(wxOutputStream
& s
, bool seekable
)
179 wxMMediaFile::SetFile(s
, seekable
);
183 riff_codec
.SetFile((seekable
) ? s
: *m_ostream
);