]>
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
;
110 return riff_codec
.GetChunkLength();
113 wxSndWavCodec::~wxSndWavCodec()
117 bool wxSndWavCodec::OnNeedData(char *buf
, wxUint32 size
)
119 return riff_codec
.ReadData(buf
, size
);
122 bool wxSndWavCodec::OnWriteData(char *buf
, wxUint32 size
)
124 return riff_codec
.WriteData(buf
, size
);
127 bool wxSndWavCodec::PrepareToRecord(wxUint32 m_fsize
)
131 if (!riff_codec
.RiffReset(RIFF_WRITE
))
134 total_size
= 16 + sizeof(wav_hdr
) + m_fsize
;
136 if (!riff_codec
.CreateChunk("RIFF", total_size
))
138 riff_codec
.WriteData("WAVE", 4);
139 if (!riff_codec
.CreateChunk("fmt ", sizeof(wav_hdr
)))
142 wav_hdr
.format
= 1; // PCM_WAV_FORMAT
143 wav_hdr
.channels
= m_sndformat
.GetChannels();
144 wav_hdr
.sample_fq
= m_sndformat
.GetSampleRate();
145 wav_hdr
.byte_p_spl
= (m_sndformat
.GetBps() / 8) * wav_hdr
.channels
;
146 wav_hdr
.byte_p_sec
= m_sndformat
.GetCodec()->GetByteRate();
147 wav_hdr
.bits_p_spl
= m_sndformat
.GetBps();
148 ChangeCodec(WXSOUND_PCM
);
150 if (wav_hdr
.format
== WXSOUND_PCM
) {
151 m_sndformat
.SetSign(wxSND_SAMPLE_SIGNED
);
152 m_sndformat
.SetByteOrder(wxSND_SAMPLE_LE
);
155 riff_codec
.Write16(wav_hdr
.format
);
156 riff_codec
.Write16(wav_hdr
.channels
);
157 riff_codec
.Write32(wav_hdr
.sample_fq
);
158 riff_codec
.Write32(wav_hdr
.byte_p_sec
);
159 riff_codec
.Write16(wav_hdr
.byte_p_spl
);
160 riff_codec
.Write16(wav_hdr
.bits_p_spl
);
162 if (!riff_codec
.CreateChunk("data", m_fsize
))
167 void wxSndWavCodec::SetFile(wxInputStream
& s
, bool preload
, bool seekable
)
169 wxMMediaFile::SetFile(s
, preload
, seekable
);
173 riff_codec
.SetFile((seekable
) ? s
: *m_istream
);
176 void wxSndWavCodec::SetFile(wxOutputStream
& s
, bool seekable
)
178 wxMMediaFile::SetFile(s
, seekable
);
182 riff_codec
.SetFile((seekable
) ? s
: *m_ostream
);