]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/wave.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxWave class implementation: optional
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
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
143 wxMacStringToPascal( m_sndname
, snd
) ;
146 hSnd
= (SndListHandle
) GetNamedResource('snd ', snd
);
148 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, async
) == noErr
))
156 bool wxWave::FreeData()
174 //code below is from an old implementation used for telinfo with MSVC crossplatform support
175 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
176 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
178 /*static short MacOpenSndFile (char * path)
185 // first, get the volume reference number for the file. Start by
186 // making a Pstring with just the volume name
187 strcpy ((char *) name, path);
188 if (c = strchr ((char *) name, ':'))
194 c2pstr ((char *) name);
200 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
203 // next, buld an FSSpec for the file
204 strcpy ((char *) name, path);
205 c2pstr ((char *) name);
206 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
210 // now open the file, and return it's reference number
211 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
218 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
222 KillTimer(0,timerID);
228 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
229 if (scstat.scChannelPaused || scstat.scChannelBusy)
230 return; // not done yet
233 // either error or done.
236 SndDisposeChannel (sndChan, TRUE);
239 KillTimer(0,timerID);