]> git.saurik.com Git - wxWidgets.git/blame - utils/wxMMedia2/lib/sndaiff.cpp
Removed wxMMedia
[wxWidgets.git] / utils / wxMMedia2 / lib / sndaiff.cpp
CommitLineData
526ddb13
GL
1// --------------------------------------------------------------------------
2// Name: sndaiff.cpp
3// Purpose:
4// Date: 08/11/1999
5// Author: Guilhem Lavaux <lavaux@easynet.fr> (C) 1999
6// CVSID: $Id$
7// --------------------------------------------------------------------------
8#ifdef __GNUG__
9#pragma implementation "sndaiff.cpp"
10#endif
11
12#include <wx/defs.h>
13#include <wx/stream.h>
14#include <wx/datstrm.h>
15#include <wx/filefn.h>
16#include "sndbase.h"
17#include "sndcodec.h"
18#include "sndfile.h"
19#include "sndpcm.h"
20#include "sndaiff.h"
21
22#define BUILD_SIGNATURE(a,b,c,d) (((wxUint32)a) | (((wxUint32)b) << 8) | (((wxUint32)c) << 16) | (((wxUint32)d) << 24))
23
24#define FORM_SIGNATURE BUILD_SIGNATURE('F','O','R','M')
25#define AIFF_SIGNATURE BUILD_SIGNATURE('A','I','F','F')
26#define AIFC_SIGNATURE BUILD_SIGNATURE('A','I','F','C')
27#define COMM_SIGNATURE BUILD_SIGNATURE('C','O','M','M')
28#define SSND_SIGNATURE BUILD_SIGNATURE('S','S','N','D')
29
30wxSoundAiff::wxSoundAiff(wxInputStream& stream, wxSoundStream& io_sound)
31 : wxSoundFileStream(stream, io_sound)
32{
33}
34
35wxSoundAiff::wxSoundAiff(wxOutputStream& stream, wxSoundStream& io_sound)
36 : wxSoundFileStream(stream, io_sound)
37{
38}
39
40wxSoundAiff::~wxSoundAiff()
41{
42}
43
44#define FAIL_WITH(condition, err) if (condition) { m_snderror = err; return FALSE; }
45
46bool wxSoundAiff::PrepareToPlay()
47{
48 wxDataInputStream data(*m_input);
49 wxUint32 signature, len, ssnd;
50 bool end_headers;
51
52 if (!m_input) {
53 m_snderror = wxSOUND_INVSTRM;
54 return FALSE;
55 }
56
57 data.BigEndianOrdered(TRUE);
58
59 FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
60 FAIL_WITH(wxUINT32_SWAP_ON_BE(signature) != FORM_SIGNATURE, wxSOUND_INVSTRM);
61 // "FORM"
62
63 len = data.Read32();
64 FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
65 // dummy len
66
67 FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
68 FAIL_WITH(
69 wxUINT32_SWAP_ON_BE(signature) != AIFF_SIGNATURE &&
70 wxUINT32_SWAP_ON_BE(signature) != AIFC_SIGNATURE, wxSOUND_INVSTRM);
71 // "AIFF" / "AIFC"
72
73 end_headers = FALSE;
74 while (!end_headers) {
75 FAIL_WITH(m_input->Read(&signature, 4).LastRead() != 4, wxSOUND_INVSTRM);
76
77 len = data.Read32();
78 FAIL_WITH(m_input->LastRead() != 4, wxSOUND_INVSTRM);
79
80 switch (wxUINT32_SWAP_ON_BE(signature)) {
81 case COMM_SIGNATURE: { // "COMM"
82 wxUint16 channels, bps;
83 wxUint32 num_samples;
84 double srate;
85 wxSoundFormatPcm sndformat;
86
87 data >> channels >> num_samples >> bps >> srate;
88
89 sndformat.SetSampleRate((wxUint32) srate);
90 sndformat.SetBPS(bps);
91 sndformat.SetChannels(channels);
92 sndformat.Signed(TRUE);
93 sndformat.SetOrder(wxBIG_ENDIAN);
94
95 if (!SetSoundFormat(sndformat))
96 return FALSE;
97 m_input->SeekI(len-18, wxFromCurrent);
98 break;
99 }
100 case SSND_SIGNATURE: { // "SSND"
101 data >> ssnd;
102 // m_input->SeekI(4, wxFromCurrent); // Pass an INT32
103 // m_input->SeekI(len-4, wxFromCurrent); // Pass the rest
104 m_input->SeekI(ssnd + 4, wxFromCurrent);
105 end_headers = TRUE;
106 break;
107 }
108 default:
109 m_input->SeekI(len, wxFromCurrent);
110 break;
111 }
112 }
113 return TRUE;
114}
115
116bool wxSoundAiff::PrepareToRecord(unsigned long time)
117{
118 return FALSE;
119}
120
121bool wxSoundAiff::FinishRecording()
122{
123 return FALSE;
124}
125
126size_t wxSoundAiff::GetData(void *buffer, size_t len)
127{
128 return m_input->Read(buffer, len).LastRead();
129}
130
131size_t wxSoundAiff::PutData(const void *buffer, size_t len)
132{
133 return m_output->Write(buffer, len).LastWrite();
134}