]>
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_sndformat
.SetSampleRate(wav_hdr
.sample_fq
);
90 m_sndformat
.SetBps(wav_hdr
.bits_p_spl
);
91 m_sndformat
.SetChannels(wav_hdr
.channels
);
92 m_sndmode
= wxSND_OUTPUT
;
93 ChangeCodec(wav_hdr
.format
);
95 m_sndformat
.SetSampleRate(wav_hdr
.sample_fq
);
96 m_sndformat
.SetBps(wav_hdr
.bits_p_spl
);
97 m_sndformat
.SetChannels(wav_hdr
.channels
);
99 if (wav_hdr
.format
== WXSOUND_PCM
) {
100 m_sndformat
.SetSign(wxSND_SAMPLE_SIGNED
);
101 m_sndformat
.SetByteOrder(wxSND_SAMPLE_LE
);
104 wxUint32 sec1
= riff_codec
.GetChunkLength() / wav_hdr
.byte_p_sec
,
107 m_sndtime
.hours
= sec1
/ 3600;
108 m_sndtime
.minutes
= sec2
/ 60;
109 m_sndtime
.seconds
= sec2
% 60;
111 wxSndFileCodec::m_mmerror
= wxMMFILE_NOERROR
;
113 return riff_codec
.GetChunkLength();
116 wxSndWavCodec::~wxSndWavCodec()
120 bool wxSndWavCodec::OnNeedData(char *buf
, wxUint32 size
)
122 return riff_codec
.ReadData(buf
, size
);
125 bool wxSndWavCodec::OnWriteData(char *buf
, wxUint32 size
)
127 return riff_codec
.WriteData(buf
, size
);
130 bool wxSndWavCodec::PrepareToRecord(wxUint32 m_fsize
)
134 if (!riff_codec
.RiffReset(RIFF_WRITE
))
137 total_size
= 16 + sizeof(wav_hdr
) + m_fsize
;
139 if (!riff_codec
.CreateChunk("RIFF", total_size
))
141 riff_codec
.WriteData("WAVE", 4);
142 if (!riff_codec
.CreateChunk("fmt ", sizeof(wav_hdr
)))
145 wav_hdr
.format
= 1; // PCM_WAV_FORMAT
146 wav_hdr
.channels
= m_sndformat
.GetChannels();
147 wav_hdr
.sample_fq
= m_sndformat
.GetSampleRate();
148 wav_hdr
.byte_p_spl
= (m_sndformat
.GetBps() / 8) * wav_hdr
.channels
;
149 wav_hdr
.byte_p_sec
= m_sndformat
.GetCodec()->GetByteRate();
150 wav_hdr
.bits_p_spl
= m_sndformat
.GetBps();
151 ChangeCodec(WXSOUND_PCM
);
153 if (wav_hdr
.format
== WXSOUND_PCM
) {
154 m_sndformat
.SetSign(wxSND_SAMPLE_SIGNED
);
155 m_sndformat
.SetByteOrder(wxSND_SAMPLE_LE
);
158 riff_codec
.Write16(wav_hdr
.format
);
159 riff_codec
.Write16(wav_hdr
.channels
);
160 riff_codec
.Write32(wav_hdr
.sample_fq
);
161 riff_codec
.Write32(wav_hdr
.byte_p_sec
);
162 riff_codec
.Write16(wav_hdr
.byte_p_spl
);
163 riff_codec
.Write16(wav_hdr
.bits_p_spl
);
165 if (!riff_codec
.CreateChunk("data", m_fsize
))
170 void wxSndWavCodec::SetFile(wxInputStream
& s
, bool preload
, bool seekable
)
172 wxMMediaFile::SetFile(s
, preload
, seekable
);
176 riff_codec
.SetFile((seekable
) ? s
: *m_istream
);
179 void wxSndWavCodec::SetFile(wxOutputStream
& s
, bool seekable
)
181 wxMMediaFile::SetFile(s
, seekable
);
185 riff_codec
.SetFile((seekable
) ? s
: *m_ostream
);