]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia/sndadpcm.cpp
Removed unnecessary branch
[wxWidgets.git] / utils / wxMMedia / sndadpcm.cpp
CommitLineData
c06a465c
GL
1#ifdef __GNUG__
2#pragma implementation "sndmulaw.h"
3#endif
4
5#include "sndsnd.h"
6#include "sndfrmt.h"
7#include "sndadpcm.h"
8#include "adpcm/g72x.h"
9
10wxSoundAdpcmCodec::wxSoundAdpcmCodec()
11 : wxSoundCodec()
12{
8a7c9dcc
GL
13 // TODO: For the moment, only 1 channel is supported.
14 m_codec_state = new g72x_state;
15 g72x_init_state(m_codec_state);
c06a465c
GL
16}
17
18wxSoundAdpcmCodec::~wxSoundAdpcmCodec()
19{
20}
21
8a7c9dcc
GL
22void wxSoundAdpcmCodec::InitWith(const wxSoundDataFormat& format)
23{
24 m_srate = format.GetSampleRate();
25}
26
c06a465c
GL
27int wxSoundAdpcmCodec::GetBits(int nbits)
28{
29 unsigned int mask;
30 int bits;
31
8a7c9dcc
GL
32 if (m_bits_waiting == 0)
33 m_current_byte = m_in_sound->GetChar();
c06a465c
GL
34
35 mask = (1 << nbits) - 1;
8a7c9dcc
GL
36 bits = m_current_byte & mask;
37 m_current_byte >>= nbits;
38 m_bits_waiting -= nbits;
c06a465c
GL
39 return bits;
40}
41
c06a465c
GL
42void wxSoundAdpcmCodec::Decode()
43{
8a7c9dcc 44 int smp, bits;
c06a465c
GL
45 wxSoundDataFormat pref_frmt;
46
47 pref_frmt = GetPreferredFormat(0);
48 if (!(m_io_format == pref_frmt))
49 ChainCodecAfter(pref_frmt);
50
51 bits = GetBits(4);
52 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
53 while (!StreamOk()) {
8a7c9dcc 54 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
c06a465c
GL
55 m_out_sound->PutChar(smp & 0x00ff);
56 m_out_sound->PutChar((smp & 0xff00) >> 8);
57 bits = GetBits(4);
58 }
59 } else {
60 while (!StreamOk()) {
8a7c9dcc 61 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, m_codec_state);
c06a465c
GL
62 m_out_sound->PutChar((smp & 0xff00) >> 8);
63 m_out_sound->PutChar(smp & 0x00ff);
64 bits = GetBits(4);
65 }
66 }
67}
68
8a7c9dcc 69void wxSoundAdpcmCodec::Encode()
c06a465c 70{
8a7c9dcc
GL
71/*
72 int smp;
73 wxSoundDataFormat pref_frmt;
74
75 pref_frmt = GetPreferredFormat(0);
76 if (!(m_io_format == pref_frmt))
77 ChainCodecAfter(pref_frmt);
78
79 bits = GetBits(4);
80 if (m_io_format.GetByteOrder() == wxSND_SAMPLE_LE) {
81 while (!StreamOk()) {
82 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
83 m_out_sound->PutChar(smp & 0x00ff);
84 m_out_sound->PutChar((smp & 0xff00) >> 8);
85 bits = GetBits(4);
86 }
87 } else {
88 while (!StreamOk()) {
89 smp = g721_decoder(bits, AUDIO_ENCODING_LINEAR, codec_state);
90 m_out_sound->PutChar((smp & 0xff00) >> 8);
91 m_out_sound->PutChar(smp & 0x00ff);
92 bits = GetBits(4);
93 }
94 }
95*/
c06a465c
GL
96}
97
8a7c9dcc 98size_t wxSoundAdpcmCodec::GetByteRate() const
c06a465c 99{
8a7c9dcc 100 return (m_io_format.GetSampleRate() * m_io_format.GetChannels()) / 2;
c06a465c
GL
101}
102
8a7c9dcc 103wxSoundDataFormat wxSoundAdpcmCodec::GetPreferredFormat(int WXUNUSED(no)) const
c06a465c
GL
104{
105 wxSoundDataFormat format;
106
107 format.SetCodecNo(WXSOUND_PCM);
108 format.SetSampleRate(m_srate);
109 format.SetBps(16);
110 format.SetChannels(1);
111 format.SetSign(wxSND_SAMPLE_SIGNED);
112#ifdef USE_BE_MACH
113 format.SetByteOrder(wxSND_SAMPLE_BE);
114#else
115 format.SetByteOrder(wxSND_SAMPLE_LE);
116#endif
117 return format;
118}