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()
65 wxOSXAudioToolboxSoundData::CompletionCallback(SystemSoundID
WXUNUSED(mySSID
),
68 wxOSXAudioToolboxSoundData
* data
= (wxOSXAudioToolboxSoundData
*) soundRef
;
70 data
->SoundCompleted();
73 void wxOSXAudioToolboxSoundData::SoundCompleted()
75 if ( m_flags
& wxSOUND_ASYNC
)
77 if (m_flags
& wxSOUND_LOOP
)
78 AudioServicesPlaySystemSound(m_soundID
);
85 CFRunLoopStop(CFRunLoopGetCurrent());
90 void wxOSXAudioToolboxSoundData::DoStop()
94 AudioServicesDisposeSystemSoundID (m_soundID
);
97 wxSound::SoundStopped(this);
101 bool wxOSXAudioToolboxSoundData::Play(unsigned flags
)
107 wxCFRef
<CFMutableStringRef
> cfMutableString(CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(m_sndname
)));
108 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
109 wxCFRef
<CFURLRef
> url(CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kCFURLPOSIXPathStyle
, false));
111 AudioServicesCreateSystemSoundID(url
, &m_soundID
);
112 AudioServicesAddSystemSoundCompletion( m_soundID
, NULL
, NULL
, wxOSXAudioToolboxSoundData::CompletionCallback
, (void *) this );
114 bool sync
= !(flags
& wxSOUND_ASYNC
);
116 AudioServicesPlaySystemSound(m_soundID
);
129 bool wxSound::Create(int WXUNUSED(size
), const wxByte
* WXUNUSED(data
))
131 wxFAIL_MSG( "not implemented" );
136 bool wxSound::Create(const wxString
& fileName
, bool isResource
)
138 wxCHECK_MSG( !isResource
, false, "not implemented" );
140 m_data
= new wxOSXAudioToolboxSoundData(fileName
);
144 #endif // wxOSX_USE_AUDIOTOOLBOX