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