]>
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 #include "wx/mac/private.h"
28 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
32 wxWave::wxWave(const wxString
& sFileName
, bool isResource
)
33 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
35 Create(sFileName
, isResource
);
44 wxWave::wxWave(int size
, const wxByte
* data
)
45 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(false)
50 bool wxWave::Create(const wxString
& fileName
, bool isResource
)
54 m_isResource
= isResource
;
64 SndDisposeChannel(sndChan, TRUE);
73 if (_access(lpSnd,0)) // no file, no service
76 // Allocate SndChannel
77 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
82 sndChan->qLength = 128;
84 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
91 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
93 SndDisposeChannel(sndChan, TRUE);
102 if (fdwSound & SND_ASYNC)
105 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
109 SndDisposeChannel (sndChan, TRUE);
116 { // haven't finish yet
117 timerID = SetTimer(0, 0, 250, TimerCallBack);
123 SndDisposeChannel (sndChan, TRUE);
133 //don't know what to do with looped, wth
134 bool wxWave::Play(bool async
, bool looped
) const
142 c2pstrcpy((unsigned char *)lpSnd
, m_sndname
);
144 strcpy(lpSnd
, m_sndname
);
145 c2pstr((char *) lpSnd
);
149 hSnd
= (SndListHandle
) GetNamedResource('snd ',(const unsigned char *) lpSnd
);
151 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, async
) == noErr
))
177 //code below is from an old implementation used for telinfo with MSVC crossplatform support
178 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
179 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
181 /*static short MacOpenSndFile (char * path)
188 // first, get the volume reference number for the file. Start by
189 // making a Pstring with just the volume name
190 strcpy ((char *) name, path);
191 if (c = strchr ((char *) name, ':'))
197 c2pstr ((char *) name);
203 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
206 // next, buld an FSSpec for the file
207 strcpy ((char *) name, path);
208 c2pstr ((char *) name);
209 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
213 // now open the file, and return it's reference number
214 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
221 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
225 KillTimer(0,timerID);
231 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
232 if (scstat.scChannelPaused || scstat.scChannelBusy)
233 return; // not done yet
236 // either error or done.
239 SndDisposeChannel (sndChan, TRUE);
242 KillTimer(0,timerID);