]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWave class implementation: optional
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "wave.h"
16 #include "wx/object.h"
17 #include "wx/string.h"
21 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
25 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
26 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
28 Create(sFileName
, isResource
);
38 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
42 m_isResource
= isResource
;
52 SndDisposeChannel(sndChan, TRUE);
61 if (_access(lpSnd,0)) // no file, no service
64 // Allocate SndChannel
65 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
70 sndChan->qLength = 128;
72 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
79 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
81 SndDisposeChannel(sndChan, TRUE);
90 if (fdwSound & SND_ASYNC)
93 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
97 SndDisposeChannel (sndChan, TRUE);
104 { // haven't finish yet
105 timerID = SetTimer(0, 0, 250, TimerCallBack);
111 SndDisposeChannel (sndChan, TRUE);
121 //don't know what to do with looped, wth
122 bool wxWave::Play(bool async
, bool looped
) const
129 strcpy(lpSnd
, m_sndname
);
130 c2pstr((char *) lpSnd
);
133 hSnd
= (SndListHandle
) GetNamedResource('snd ',(const unsigned char *) lpSnd
);
135 if ((hSnd
!= NULL
) && (SndPlay(m_sndChan
, hSnd
, async
) == noErr
))
161 //code below is from an old implementation used for telinfo with MSVC crossplatform support
162 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
163 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
165 /*static short MacOpenSndFile (char * path)
172 // first, get the volume reference number for the file. Start by
173 // making a Pstring with just the volume name
174 strcpy ((char *) name, path);
175 if (c = strchr ((char *) name, ':'))
181 c2pstr ((char *) name);
187 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
190 // next, buld an FSSpec for the file
191 strcpy ((char *) name, path);
192 c2pstr ((char *) name);
193 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
197 // now open the file, and return it's reference number
198 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
205 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
209 KillTimer(0,timerID);
215 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
216 if (scstat.scChannelPaused || scstat.scChannelBusy)
217 return; // not done yet
220 // either error or done.
223 SndDisposeChannel (sndChan, TRUE);
226 KillTimer(0,timerID);