]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia/sndau.cpp
minimal now works in Unicode mode
[wxWidgets.git] / utils / wxMMedia / sndau.cpp
CommitLineData
4d6306eb
GL
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
23wxSndAuCodec::wxSndAuCodec()
24 : wxSndFileCodec()
25{
26}
27
28wxSndAuCodec::wxSndAuCodec(wxInputStream& s, bool preload, bool seekable)
29 : wxSndFileCodec(s, preload, seekable)
30{
31}
32
33wxSndAuCodec::wxSndAuCodec(wxOutputStream& s, bool seekable)
34 : wxSndFileCodec(s, seekable)
35{
36}
37
38wxSndAuCodec::wxSndAuCodec(const wxString& fname)
39 : wxSndFileCodec(fname)
40{
41}
42
43wxSndAuCodec::~wxSndAuCodec()
44{
45}
46
47wxUint32 wxSndAuCodec::PrepareToPlay()
48{
49 wxString id;
50 char temp_buf[5];
51 int offset, srate, codec, ch_count;
52 size_t len;
53
4d6306eb
GL
54 m_istream->Read(temp_buf, 4);
55 temp_buf[4] = 0;
56
57 id = temp_buf;
58 if (id != ".snd") {
59 m_mmerror = wxMMFILE_INVALID;
60 return 0;
61 }
62
63#define READ_BE_32(i) \
64m_istream->Read(temp_buf, 4); \
65i = (unsigned long)temp_buf[0] << 24; \
66i |= (unsigned long)temp_buf[1] << 16; \
67i |= (unsigned long)temp_buf[2] << 8; \
68i |= (unsigned long)temp_buf[3];
69
70 READ_BE_32(offset);
71 READ_BE_32(len);
72 READ_BE_32(codec);
73 READ_BE_32(srate);
74 READ_BE_32(ch_count);
75
76 m_sndformat.SetSampleRate(srate);
77 m_sndformat.SetChannels(ch_count);
78 switch (codec) {
79 case AU_ISDN_ULAW:
80 ChangeCodec(WXSOUND_ULAW);
81 break;
82 case AU_PCM_8BITS:
83 ChangeCodec(WXSOUND_PCM);
84 m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
85 m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
86 break;
87 case AU_PCM_16BITS:
88 ChangeCodec(WXSOUND_PCM);
89 m_sndformat.SetByteOrder(wxSND_SAMPLE_LE);
90 m_sndformat.SetSign(wxSND_SAMPLE_SIGNED);
91 break;
92 case AU_ADPCM:
93 ChangeCodec(WXSOUND_ADPCM);
94 break;
95 }
96 return len;
97}
98
99bool wxSndAuCodec::OnNeedData(char *buf, wxUint32 size)
100{
101 return m_istream->Read(buf, size).LastError();
102}
103
104bool wxSndAuCodec::OnWriteData(char *buf, wxUint32 size)
105{
106 return m_ostream->Write(buf, size).LastError();
107}
108
109bool wxSndAuCodec::PrepareToRecord(wxUint32 file_size)
110{
111 return FALSE;
112}