]>
git.saurik.com Git - wxWidgets.git/blob - src/mac/classic/sound.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSound class implementation: optional
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/object.h"
13 #include "wx/string.h"
19 #include "wx/mac/private.h"
26 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
30 wxSound::wxSound(const wxString
& sFileName
, bool isResource
)
31 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(true)
33 Create(sFileName
, isResource
);
42 wxSound::wxSound(int size
, const wxByte
* data
)
43 : m_sndChan(0), m_hSnd(NULL
), m_waveLength(0), m_isResource(false)
48 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
52 m_isResource
= isResource
;
62 SndDisposeChannel(sndChan, TRUE);
71 if (_access(lpSnd,0)) // no file, no service
74 // Allocate SndChannel
75 sndChan = (SndChannelPtr) malloc (sizeof(SndChannel));
80 sndChan->qLength = 128;
82 if (noErr != SndNewChannel (&sndChan, sampledSynth, initMono | initNoInterp, 0))
89 if (!(SndRefNum = MacOpenSndFile ((char *)lpSnd)))
91 SndDisposeChannel(sndChan, TRUE);
100 if (fdwSound & SND_ASYNC)
103 if (SndStartFilePlay(sndChan, SndRefNum, 0, 81920, 0, 0, 0, async) != noErr)
107 SndDisposeChannel (sndChan, TRUE);
114 { // haven't finish yet
115 timerID = SetTimer(0, 0, 250, TimerCallBack);
121 SndDisposeChannel (sndChan, TRUE);
131 //don't know what to do with looped, wth
132 bool wxSound::DoPlay(unsigned flags
) const
139 wxMacStringToPascal( m_sndname
, snd
) ;
142 hSnd
= (SndListHandle
) GetNamedResource('snd ', snd
);
144 if ((hSnd
!= NULL
) && (SndPlay((SndChannelPtr
)m_sndChan
, (SndListHandle
) hSnd
, (flags
& wxSOUND_ASYNC
)) == noErr
))
152 bool wxSound::FreeData()
170 //code below is from an old implementation used for telinfo with MSVC crossplatform support
171 //technology proceeds, so it would be the wisest to drop this code, but it's left here just
172 //for the sake of a reference. BTW: Wave files can now be played with QT, starting from V3
174 /*static short MacOpenSndFile (char * path)
181 // first, get the volume reference number for the file. Start by
182 // making a Pstring with just the volume name
183 strcpy ((char *) name, path);
184 if (c = strchr ((char *) name, ':'))
190 c2pstr ((char *) name);
196 if (PBGetVInfo((ParamBlockRec *)&vp, 0) != noErr)
199 // next, buld an FSSpec for the file
200 strcpy ((char *) name, path);
201 c2pstr ((char *) name);
202 if (FSMakeFSSpec (vp.ioVRefNum, 0, name, &fspec) != noErr)
206 // now open the file, and return it's reference number
207 if (FSpOpenDF(&fspec, fsRdPerm, &frefnum) != noErr)
214 void TimerCallBack(HWND hwnd,UINT uMsg,UINT idEvent,DWORD dwTime)
218 KillTimer(0,timerID);
224 if (noErr == SndChannelStatus (sndChan, sizeof (SCStatus), &scstat)) {
225 if (scstat.scChannelPaused || scstat.scChannelBusy)
226 return; // not done yet
229 // either error or done.
232 SndDisposeChannel (sndChan, TRUE);
235 KillTimer(0,timerID);