]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia/sndfrmt.h
Removed GetSize from wxToolBar95
[wxWidgets.git] / utils / wxMMedia / sndfrmt.h
CommitLineData
2a040d3f
GL
1////////////////////////////////////////////////////////////////////////////////
2// Name: sndfrmt.h
3// Purpose: wxMMedia
4// Author: Guilhem Lavaux
5// Created: 1998
6// Updated: December 1998
7// Copyright: (C) 1997, 1998, Guilhem Lavaux
8// License: wxWindows license
9////////////////////////////////////////////////////////////////////////////////
4d6306eb
GL
10#ifndef __SNDFRMT_H__
11#define __SNDFRMT_H__
12
13#ifdef __GNUG__
14#pragma interface
15#endif
16
17#include <wx/object.h>
926c550d 18#include <wx/stream.h>
4d6306eb
GL
19
20class wxSndBuffer;
21
22// Standard Microsoft types (why change ?)
23#define WXSOUND_PCM 0x0001
24#define WXSOUND_ADPCM 0x0002
25#define WXSOUND_ALAW 0x0006
26#define WXSOUND_ULAW 0x0007
27
28class wxSoundCodec;
29class wxSoundDataFormat {
30 public:
31 wxSoundDataFormat();
926c550d 32 wxSoundDataFormat(const wxSoundDataFormat& format);
4d6306eb
GL
33 ~wxSoundDataFormat();
34
35 void SetSampleRate(int srate) { m_srate = srate; }
36 void SetChannels(int channels);
37 void SetStereo(bool on);
38 void SetCodecNo(int no);
9a1b2c28 39 int GetCodecNo() { return m_codno; }
4d6306eb
GL
40 void SetCodecCreate(bool create) { m_codcreate = create; }
41
42 int GetSampleRate() const { return m_srate; }
43 int GetChannels() const { return m_channels; }
44 bool GetStereo() const { return (m_channels == 2); }
45 int GetCodecNo() const { return m_codno; }
46
47 wxSoundCodec *GetCodec();
48
49 wxSoundDataFormat& operator =(const wxSoundDataFormat& format);
50 bool operator ==(const wxSoundDataFormat& format) const;
51 bool operator !=(const wxSoundDataFormat& format) const
52 { return !(operator ==(format)); }
53
54 /// PCM format
55 void SetByteOrder(int order);
56 void SetSign(int sign);
57 int GetByteOrder() const { return m_byteorder; }
58 int GetSign() const { return m_sign; }
59
60 void SetBps(int bps);
61 int GetBps() const { return m_bps; }
62
63 protected:
64 void CodecChange();
65
66 protected:
67 int m_srate, m_bps, m_channels, m_codno;
68 int m_byteorder, m_sign;
69 bool m_codchange, m_codcreate;
70 wxSoundCodec *m_codec;
71};
72
73class wxSoundCodec : public wxObject, public wxStreamBase {
74 DECLARE_ABSTRACT_CLASS(wxSoundCodec)
eb4e516d
GL
75 public:
76 typedef enum {
77 WAITING = 0,
78 ENCODING,
79 DECODING
80 } ModeType;
4d6306eb
GL
81 public:
82 wxSoundCodec();
83 virtual ~wxSoundCodec();
84
85 void SetIOBuffer(wxSndBuffer *sndbuf) { m_io_sndbuf = sndbuf; }
86 size_t Available();
87
88 void InitIO(const wxSoundDataFormat& format);
8a7c9dcc 89 virtual void InitWith(const wxSoundDataFormat& format) {}
4d6306eb
GL
90
91 inline void SetInStream(wxStreamBuffer *s)
92 { m_in_sound = s; }
93 inline void SetOutStream(wxStreamBuffer *s)
94 { m_out_sound = s; }
95 inline wxStreamBuffer *GetInStream() const { return m_in_sound; }
96 inline wxStreamBuffer *GetOutStream() const { return m_out_sound; }
97
926c550d
GL
98 inline bool StreamOk() const
99 { return (m_in_sound->Stream()->LastError() == wxStream_NOERROR) &&
100 (m_out_sound->Stream()->LastError() == wxStream_NOERROR); }
4d6306eb
GL
101
102 virtual size_t GetByteRate() const = 0;
103 virtual wxSoundDataFormat GetPreferredFormat(int codec = 0) const = 0;
104
eb4e516d
GL
105 virtual void InitMode(ModeType mode);
106 virtual void ExitMode();
4d6306eb
GL
107 virtual void Decode() = 0;
108 virtual void Encode() = 0;
109
110 static wxSoundCodec *Get(int no);
111
112 protected:
113 void CopyToOutput();
114
115 unsigned short Convert8_16(unsigned char s) { return (s & 0xff) << 8; }
116 unsigned char Convert16_8(unsigned short s) { return (s & 0xff00) >> 8; }
117
118 bool ChainCodecBefore(wxSoundDataFormat& cod_to);
119 bool ChainCodecAfter(wxSoundDataFormat& cod_to);
120
121 // -------------
122 // wxStream part
123 // -------------
124 size_t OnSysWrite(const void *buffer, size_t bsize);
125 size_t OnSysRead(void *buffer, size_t bsize);
126
127 protected:
128 wxSndBuffer *m_io_sndbuf;
129 wxSoundDataFormat m_io_format;
130 wxStreamBuffer *m_in_sound, *m_out_sound;
131 wxSoundCodec *m_chain_codec;
132 bool m_init, m_chain_before;
eb4e516d 133 ModeType m_mode;
4d6306eb
GL
134};
135
136#endif