]> git.saurik.com Git - wxWidgets.git/blob - utils/wxMMedia/sndau.cpp
Added test for sprintf and vsnprintf to fix string.cpp for non-GNU systems.
[wxWidgets.git] / utils / wxMMedia / sndau.cpp
1 // /////////////////////////////////////////////////////////////////////////////
2 // Name: sndau.cpp
3 // Purpose: wxMMedia Sun Audio File Codec
4 // Author: Guilhem Lavaux
5 // Created: 1998
6 // Updated:
7 // Copyright: (C) 1998, Guilhem Lavaux
8 // License: wxWindows license
9 // /////////////////////////////////////////////////////////////////////////////
10 #ifdef __GNUG__
11 #pragma implementation "sndau.h"
12 #endif
13
14 #include "mmriff.h"
15 #include "sndfile.h"
16 #include "sndau.h"
17
18 #define AU_ISDN_ULAW 1
19 #define AU_PCM_8BITS 2
20 #define AU_PCM_16BITS 3
21 #define AU_ADPCM 23
22
23 wxSndAuCodec::wxSndAuCodec()
24 : wxSndFileCodec()
25 {
26 }
27
28 wxSndAuCodec::wxSndAuCodec(wxInputStream& s, bool preload, bool seekable)
29 : wxSndFileCodec(s, preload, seekable)
30 {
31 }
32
33 wxSndAuCodec::wxSndAuCodec(wxOutputStream& s, bool seekable)
34 : wxSndFileCodec(s, seekable)
35 {
36 }
37
38 wxSndAuCodec::wxSndAuCodec(const wxString& fname)
39 : wxSndFileCodec(fname)
40 {
41 }
42
43 wxSndAuCodec::~wxSndAuCodec()
44 {
45 }
46
47 wxUint32 wxSndAuCodec::PrepareToPlay()
48 {
49 wxString id;
50 char temp_buf[5];
51 int offset, srate, codec, ch_count;
52 size_t len;
53
54 m_istream->SeekI(0);
55
56 m_istream->Read(temp_buf, 4);
57 temp_buf[4] = 0;
58
59 id = temp_buf;
60 if (id != ".snd") {
61 m_mmerror = wxMMFILE_INVALID;
62 return 0;
63 }
64
65 #define READ_BE_32(i) \
66 m_istream->Read(temp_buf, 4); \
67 i = (unsigned long)temp_buf[0] << 24; \
68 i |= (unsigned long)temp_buf[1] << 16; \
69 i |= (unsigned long)temp_buf[2] << 8; \
70 i |= (unsigned long)temp_buf[3];
71
72 READ_BE_32(offset);
73 READ_BE_32(len);
74 READ_BE_32(codec);
75 READ_BE_32(srate);
76 READ_BE_32(ch_count);
77
78 m_sndformat.SetSampleRate(srate);
79 m_sndformat.SetChannels(ch_count);
80 switch (codec) {
81 case AU_ISDN_ULAW:
82 ChangeCodec(WXSOUND_ULAW);
83 break;
84 case AU_PCM_8BITS:
85 ChangeCodec(WXSOUND_PCM);
86 m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
87 m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
88 break;
89 case AU_PCM_16BITS:
90 ChangeCodec(WXSOUND_PCM);
91 m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
92 m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
93 break;
94 case AU_ADPCM:
95 ChangeCodec(WXSOUND_ADPCM);
96 break;
97 }
98 return len;
99 }
100
101 bool wxSndAuCodec::OnNeedData(char *buf, wxUint32 size)
102 {
103 return m_istream->Read(buf, size).LastError();
104 }
105
106 bool wxSndAuCodec::OnWriteData(char *buf, wxUint32 size)
107 {
108 return m_ostream->Write(buf, size).LastError();
109 }
110
111 bool wxSndAuCodec::PrepareToRecord(wxUint32 file_size)
112 {
113 return FALSE;
114 }