]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia/sndmulaw.cpp
egcs compilation fix
[wxWidgets.git] / utils / wxMMedia / sndmulaw.cpp
CommitLineData
2a040d3f
GL
1////////////////////////////////////////////////////////////////////////////////
2// Name: sndmulaw.cpp
3// Purpose: wxMMedia
4// Author: Guilhem Lavaux
5// Created: 1997
6// Updated: December 1998
7// Copyright: (C) 1997, 1998, Guilhem Lavaux
8// License: wxWindows license
9////////////////////////////////////////////////////////////////////////////////
4d6306eb
GL
10#ifdef __GNUG__
11#pragma implementation "sndmulaw.h"
12#endif
13
14#include "sndsnd.h"
15#include "sndfrmt.h"
16#include "sndmulaw.h"
17#include "adpcm/g72x.h"
18
19wxSoundMulawCodec::wxSoundMulawCodec()
20 : wxSoundCodec()
21{
22}
23
24wxSoundMulawCodec::~wxSoundMulawCodec()
25{
26}
27
28void wxSoundMulawCodec::Decode()
29{
30 int smp;
31 wxSoundDataFormat pref_frmt;
32
33 pref_frmt = GetPreferredFormat(0);
34 if (m_io_format != pref_frmt)
35 ChainCodecAfter(pref_frmt);
36
37 InitMode(DECODING);
38
926c550d 39 while (!StreamOk()) {
4d6306eb
GL
40 smp = ulaw2linear(m_in_sound->GetChar());
41#ifdef USE_BE_MACH
42 m_out_sound->PutChar((smp & 0xff00) >> 8);
43 m_out_sound->PutChar(smp & 0xff);
44#else
45 m_out_sound->PutChar(smp & 0xff);
46 m_out_sound->PutChar((smp & 0xff00) >> 8);
47#endif
48 }
49}
50
51void wxSoundMulawCodec::Encode()
52{
53 int smp;
54 wxSoundDataFormat pref_frmt;
55
56 pref_frmt = GetPreferredFormat(0);
57 if (m_io_format != pref_frmt)
58 ChainCodecBefore(pref_frmt);
59
60 InitMode(ENCODING);
61
926c550d 62 while (!StreamOk()) {
4d6306eb
GL
63#ifdef USE_BE_MACH
64 smp = ((unsigned short)m_in_sound->GetChar()) << 8;
65 smp |= m_in_sound->GetChar() & 0xff;
66#else
67 smp = m_in_sound->GetChar() & 0xff;
68 smp |= ((unsigned short)m_in_sound->GetChar()) << 8;
69#endif
70 m_out_sound->PutChar(linear2ulaw(smp));
71 }
72}
73
74size_t wxSoundMulawCodec::GetByteRate() const
75{
76 return m_srate;
77}
78
79wxSoundDataFormat wxSoundMulawCodec::GetPreferredFormat(int WXUNUSED(no)) const
80{
81 wxSoundDataFormat format;
82
83 format.SetCodecNo(WXSOUND_PCM);
84 format.SetSampleRate(m_srate);
85 format.SetBps(16);
86 format.SetChannels(1);
87 format.SetSign(wxSND_SAMPLE_SIGNED);
88#ifdef USE_BE_MACH
89 format.SetByteOrder(wxSND_SAMPLE_BE);
90#else
91 format.SetByteOrder(wxSND_SAMPLE_LE);
92#endif
93 return format;
94}