]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/classic/sound.cpp
3 // Purpose: wxSound class implementation: optional
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
20 #include "wx/object.h"
21 #include "wx/string.h"
25 #include "wx/mac/private.h"
32 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
36 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
37 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
39 Create(sFileName
, isResource
);
48 wxSound::wxSound(int size
, const wxByte
* data
)
49 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(false)
54 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
58 m_isResource
= isResource
;
68 SndDisposeChannel(sndChan, TRUE);
77 if (_access(lpSnd,0)) // no file, no service
80 // Allocate SndChannel
81 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
86 sndChan->qLength = 128;
88 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
95 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
97 SndDisposeChannel(sndChan, TRUE);
106 if (fdwSound & SND_ASYNC)
109 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
113 SndDisposeChannel (sndChan, TRUE);
120 { // haven't finish yet
121 timerID = SetTimer(0, 0, 250, TimerCallBack);
127 SndDisposeChannel (sndChan, TRUE);
137 //don't know what to do with looped, wth
138 bool wxSound::DoPlay(unsigned flags
) const
145 wxMacStringToPascal( m_sndname
, snd
) ;
148 hSnd
= (SndListHandle
) GetNamedResource('snd ', snd
);
150 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, (flags
& wxSOUND_ASYNC
)) == noErr
))
158 bool wxSound::FreeData()
176 //code below is from an old implementation used for telinfo with MSVC crossplatform support
177 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
178 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
180 /*static short MacOpenSndFile (char * path)
187 // first, get the volume reference number for the file. Start by
188 // making a Pstring with just the volume name
189 strcpy ((char *) name, path);
190 if (c = strchr ((char *) name, ':'))
196 c2pstr ((char *) name);
202 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
205 // next, buld an FSSpec for the file
206 strcpy ((char *) name, path);
207 c2pstr ((char *) name);
208 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
212 // now open the file, and return it's reference number
213 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
220 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
224 KillTimer(0,timerID);
230 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
231 if (scstat.scChannelPaused || scstat.scChannelBusy)
232 return; // not done yet
235 // either error or done.
238 SndDisposeChannel (sndChan, TRUE);
241 KillTimer(0,timerID);
244 #endif // wxUSE_SOUND