1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/carbon/sound.cpp
3 // Purpose: wxSound class implementation: optional
5 // Modified by: Stefan Csomor
7 // RCS-ID: $Id: sound.cpp 61475 2009-07-20 16:47:54Z VZ $
8 // Copyright: (c) Ryan Norton
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
19 #if wxOSX_USE_AUDIOTOOLBOX
22 #include "wx/object.h"
23 #include "wx/string.h"
31 #include "wx/osx/private.h"
33 #include <AudioToolbox/AudioToolbox.h>
35 class wxOSXAudioToolboxSoundData
: public wxSoundData
38 wxOSXAudioToolboxSoundData(const wxString
& fileName
);
40 ~wxOSXAudioToolboxSoundData();
42 virtual bool Play(unsigned flags
);
44 virtual void DoStop();
46 static void CompletionCallback(SystemSoundID mySSID
, void * soundRef
);
47 void SoundCompleted();
49 SystemSoundID m_soundID
;
50 wxString m_sndname
; //file path
53 wxOSXAudioToolboxSoundData::wxOSXAudioToolboxSoundData(const wxString
& fileName
) :
59 wxOSXAudioToolboxSoundData::~wxOSXAudioToolboxSoundData()
64 void wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID mySSID
, void * soundRef
)
66 wxOSXAudioToolboxSoundData
* data
= (wxOSXAudioToolboxSoundData
*) soundRef
;
68 data
->SoundCompleted();
71 void wxOSXAudioToolboxSoundData::SoundCompleted()
73 if ( m_flags
& wxSOUND_ASYNC
)
75 if (m_flags
& wxSOUND_LOOP
)
76 AudioServicesPlaySystemSound(m_soundID
);
83 CFRunLoopStop(CFRunLoopGetCurrent());
88 void wxOSXAudioToolboxSoundData::DoStop()
92 AudioServicesDisposeSystemSoundID (m_soundID
);
95 wxSound::SoundStopped(this);
99 bool wxOSXAudioToolboxSoundData::Play(unsigned flags
)
105 wxCFRef
<CFMutableStringRef
> cfMutableString(CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(m_sndname
)));
106 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
107 wxCFRef
<CFURLRef
> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kCFURLPOSIXPathStyle
, false));
109 AudioServicesCreateSystemSoundID(url
, &m_soundID
);
110 AudioServicesAddSystemSoundCompletion( m_soundID
, NULL
, NULL
, wxOSXAudioToolboxSoundData::CompletionCallback
, (void *) this );
112 bool sync
= !(flags
& wxSOUND_ASYNC
);
114 AudioServicesPlaySystemSound(m_soundID
);
127 bool wxSound::Create(int size
, const wxByte
* data
)
132 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
138 m_data
= new wxOSXAudioToolboxSoundData(fileName
);
142 #endif // wxOSX_USE_AUDIOTOOLBOX