]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/sndulaw.cpp
Minor changes.
[wxWidgets.git] / utils / wxMMedia2 / lib / sndulaw.cpp
CommitLineData
526ddb13
GL
1// --------------------------------------------------------------------------
2// Name: sndulaw.cpp
3// Purpose:
4// Date: 08/11/1999
5// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
6// CVSID: $Id$
7// --------------------------------------------------------------------------
8#ifdef __GNUG__
9#pragma implementation "sndulaw.cpp"
10#endif
11
6c5e6376 12#include <wx/wxprec.h>
526ddb13
GL
13#include "sndbase.h"
14#include "sndfile.h"
15#include "sndpcm.h"
16#include "sndulaw.h"
17#include "g72x.h"
18
19// --------------------------------------------------------------------------
20// wxSoundFormatUlaw
21// --------------------------------------------------------------------------
22
23wxSoundFormatUlaw::wxSoundFormatUlaw()
24 : m_srate(22050)
25{
26}
27
28wxSoundFormatUlaw::~wxSoundFormatUlaw()
29{
30}
31
32void wxSoundFormatUlaw::SetSampleRate(wxUint32 srate)
33{
34 m_srate = srate;
35}
36
37wxUint32 wxSoundFormatUlaw::GetSampleRate() const
38{
39 return m_srate;
40}
41
42wxSoundFormatBase *wxSoundFormatUlaw::Clone() const
43{
44 wxSoundFormatUlaw *ulaw = new wxSoundFormatUlaw();
45
46 ulaw->m_srate = m_srate;
47 return ulaw;
48}
49
622e48cb 50wxUint32 wxSoundFormatUlaw::GetTimeFromBytes(wxUint32 bytes) const
526ddb13
GL
51{
52 return (bytes / m_srate);
53}
54
622e48cb 55wxUint32 wxSoundFormatUlaw::GetBytesFromTime(wxUint32 time) const
526ddb13
GL
56{
57 return time * m_srate;
58}
59
60bool wxSoundFormatUlaw::operator !=(const wxSoundFormatBase& frmt2) const
61{
62 wxSoundFormatUlaw *ulaw = (wxSoundFormatUlaw *)&frmt2;
63
64 if (frmt2.GetType() != wxSOUND_ULAW)
65 return TRUE;
66
67 return (ulaw->m_srate != m_srate);
68}
69
70// --------------------------------------------------------------------------
71// wxSoundStreamUlaw
72// --------------------------------------------------------------------------
73wxSoundStreamUlaw::wxSoundStreamUlaw(wxSoundStream& sndio)
74 : wxSoundStreamCodec(sndio)
75{
76 // PCM converter
77 m_router = new wxSoundRouterStream(sndio);
78}
79
80wxSoundStreamUlaw::~wxSoundStreamUlaw()
81{
82 delete m_router;
83}
84
0662cd32 85wxSoundStream& wxSoundStreamUlaw::Read(void *buffer, wxUint32 len)
526ddb13
GL
86{
87 return *this;
88}
89
0662cd32 90wxSoundStream& wxSoundStreamUlaw::Write(const void *buffer, wxUint32 len)
526ddb13
GL
91{
92 wxUint16 *old_linear;
93 register wxUint16 *linear_buffer;
94 register const wxUint8 *ulaw_buffer;
0662cd32 95 register wxUint32 countdown = len;
526ddb13
GL
96
97 old_linear = linear_buffer = new wxUint16[len*2];
98 ulaw_buffer = (const wxUint8 *)buffer;
99
100 while (countdown != 0) {
101 *linear_buffer++ = ulaw2linear(*ulaw_buffer++);
102 countdown--;
103 }
104
105 m_router->Write(old_linear, len * 2);
106
107 delete[] old_linear;
108
109 return *m_router;
110}
111
56dc1ffd
GL
112wxUint32 wxSoundStreamUlaw::GetBestSize() const
113{
114 return m_sndio->GetBestSize() / 2;
115}
116
526ddb13
GL
117bool wxSoundStreamUlaw::SetSoundFormat(const wxSoundFormatBase& format)
118{
119 if (format.GetType() != wxSOUND_ULAW) {
120 m_snderror = wxSOUND_INVFRMT;
121 return FALSE;
122 }
123
124 wxSoundFormatPcm pcm;
125 wxSoundFormatUlaw *ulaw;
126
127 wxSoundStreamCodec::SetSoundFormat(format);
128
129 ulaw = (wxSoundFormatUlaw *)m_sndformat;
130
131 pcm.SetSampleRate(ulaw->GetSampleRate());
132 pcm.SetBPS(16);
133 pcm.SetChannels(1);
134 pcm.Signed(TRUE);
135 pcm.SetOrder(wxBYTE_ORDER);
136
137 m_router->SetSoundFormat(pcm);
138
139 return TRUE;
140}