]>
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"
23 #include "wx/mac/private.h"
30 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
34 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
35 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
37 Create(sFileName
, isResource
);
46 wxWave::wxWave(int size
, const wxByte
* data
)
47 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(false)
52 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
56 m_isResource
= isResource
;
66 SndDisposeChannel(sndChan, TRUE);
75 if (_access(lpSnd,0)) // no file, no service
78 // Allocate SndChannel
79 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
84 sndChan->qLength = 128;
86 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
93 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
95 SndDisposeChannel(sndChan, TRUE);
104 if (fdwSound & SND_ASYNC)
107 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
111 SndDisposeChannel (sndChan, TRUE);
118 { // haven't finish yet
119 timerID = SetTimer(0, 0, 250, TimerCallBack);
125 SndDisposeChannel (sndChan, TRUE);
135 //don't know what to do with looped, wth
136 bool wxWave::Play(bool async
, bool looped
) const
144 c2pstrcpy((unsigned char *)lpSnd
, m_sndname
);
146 strcpy(lpSnd
, m_sndname
);
147 c2pstr((char *) lpSnd
);
151 hSnd
= (SndListHandle
) GetNamedResource('snd ',(const unsigned char *) lpSnd
);
153 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, async
) == noErr
))
161 bool wxWave::FreeData()
179 //code below is from an old implementation used for telinfo with MSVC crossplatform support
180 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
181 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
183 /*static short MacOpenSndFile (char * path)
190 // first, get the volume reference number for the file. Start by
191 // making a Pstring with just the volume name
192 strcpy ((char *) name, path);
193 if (c = strchr ((char *) name, ':'))
199 c2pstr ((char *) name);
205 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
208 // next, buld an FSSpec for the file
209 strcpy ((char *) name, path);
210 c2pstr ((char *) name);
211 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
215 // now open the file, and return it's reference number
216 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
223 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
227 KillTimer(0,timerID);
233 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
234 if (scstat.scChannelPaused || scstat.scChannelBusy)
235 return; // not done yet
238 // either error or done.
241 SndDisposeChannel (sndChan, TRUE);
244 KillTimer(0,timerID);