bool wxOSXSoundManagerSoundData::Play(unsigned flags) { Stop(); m_flags = flags; SoundComponentData data; unsigned long numframes, offset; ParseSndHeader((SndListHandle)m_hSnd, &data, &numframes, &offset); SndNewChannel(&m_pSndChannel, sampledSynth, initNoInterp + (data.numChannels == 1 ? initMono : initStereo), NULL); if(SndPlay(m_pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr) return false; if (flags & wxSOUND_ASYNC) CreateAndStartTimer(); else DoStop(); return true; }
void Notify() { if (m_pbPlaying && !*m_pbPlaying) { Shutdown(); } SCStatus stat; if (SndChannelStatus((SndChannelPtr)m_pSndChannel, sizeof(SCStatus), &stat) != 0) Shutdown(); //if the sound isn't playing anymore, see if it's looped, //and if so play it again, otherwise close things up if (stat.scChannelBusy == FALSE) { if (m_bLoop) { if(SndPlay((SndChannelPtr)m_pSndChannel, (SndListHandle) m_hSnd, true) != noErr) Shutdown(); } else Shutdown(); } }
//don't know what to do with looped, wth bool wxSound::DoPlay(unsigned flags) const { bool ret = false; if (m_isResource) { Str255 snd ; wxMacStringToPascal( m_sndname , snd ) ; SndListHandle hSnd; hSnd = (SndListHandle) GetNamedResource('snd ', snd); if ((hSnd != NULL) && (SndPlay((SndChannelPtr)m_sndChan, (SndListHandle) hSnd, (flags & wxSOUND_ASYNC)) == noErr)) ret = true; } return ret; }
static PyObject *SndCh_SndPlay(SndChannelObject *_self, PyObject *_args) { PyObject *_res = NULL; OSErr _err; SndListHandle sndHandle; Boolean async; if (!PyArg_ParseTuple(_args, "O&b", ResObj_Convert, &sndHandle, &async)) return NULL; _err = SndPlay(_self->ob_itself, sndHandle, async); if (_err != noErr) return PyMac_Error(_err); Py_INCREF(Py_None); _res = Py_None; return _res; }
void wxOSXSoundManagerSoundData::SoundTask() { SCStatus stat; if (SndChannelStatus((SndChannelPtr)m_pSndChannel, sizeof(SCStatus), &stat) != 0) Stop(); //if the sound isn't playing anymore, see if it's looped, //and if so play it again, otherwise close things up if (stat.scChannelBusy == FALSE) { if (m_flags & wxSOUND_LOOP) { if(SndPlay((SndChannelPtr)m_pSndChannel, (SndListHandle) m_hSnd, true) != noErr) Stop(); } else Stop(); } }
bool wxSound::DoPlay(unsigned flags) const { Stop(); Movie movie; switch(m_type) { case wxSound_MEMORY: { if (!wxInitQT()) return false; Handle myHandle, dataRef = nil; MovieImportComponent miComponent; Track targetTrack = nil; TimeValue addedDuration = 0; long outFlags = 0; OSErr err; ComponentResult result; myHandle = NewHandleClear((Size)m_waveLength); BlockMove(m_hSnd, *myHandle, m_waveLength); err = PtrToHand(&myHandle, &dataRef, sizeof(Handle)); if (memcmp(&m_hSnd[8], "WAVE", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeWave); else if (memcmp(&m_hSnd[8], "AIFF", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFF); else if (memcmp(&m_hSnd[8], "AIFC", 4) == 0) miComponent = OpenDefaultComponent(MovieImportType, kQTFileTypeAIFC); else { wxLogSysError(wxT("wxSound - Location in memory does not contain valid data")); return false; } movie = NewMovie(0); result = MovieImportDataRef(miComponent, dataRef, HandleDataHandlerSubType, movie, nil, &targetTrack, nil, &addedDuration, movieImportCreateTrack, &outFlags); if (result != noErr) { wxLogSysError(wxString::Format(wxT("Couldn't import movie data\nError:%i"), (int)result)); } SetMovieVolume(movie, kFullVolume); GoToBeginningOfMovie(movie); DisposeHandle(myHandle); } break; case wxSound_RESOURCE: { SoundComponentData data; unsigned long numframes, offset; ParseSndHeader((SndListHandle)m_hSnd, &data, &numframes, &offset); //m_waveLength = numFrames * data.numChannels; SndChannelPtr pSndChannel; SndNewChannel(&pSndChannel, sampledSynth, initNoInterp + (data.numChannels == 1 ? initMono : initStereo), NULL); if(SndPlay(pSndChannel, (SndListHandle) m_hSnd, flags & wxSOUND_ASYNC ? 1 : 0) != noErr) return false; if (flags & wxSOUND_ASYNC) { lastSoundTimer = ((wxSMTimer*&)m_pTimer) = new wxSMTimer(pSndChannel, m_hSnd, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else SndDisposeChannel(pSndChannel, TRUE); return true; } break; case wxSound_FILE: { if (!wxInitQT()) return false; OSErr err = noErr ; Handle dataRef = NULL; OSType dataRefType; err = QTNewDataReferenceFromFullPathCFString(wxMacCFStringHolder(m_sndname,wxLocale::GetSystemEncoding()), (UInt32)kQTNativeDefaultPathStyle, 0, &dataRef, &dataRefType); wxASSERT(err == noErr); if (NULL != dataRef || err != noErr) { err = NewMovieFromDataRef( &movie, newMovieDontAskUnresolvedDataRefs , NULL, dataRef, dataRefType ); wxASSERT(err == noErr); DisposeHandle(dataRef); } if (err != noErr) { wxLogSysError( wxString::Format(wxT("wxSound - Could not open file: %s\nError:%i"), m_sndname.c_str(), err ) ); return false; } } break; default: return false; }//end switch(m_type) //Start the movie! StartMovie(movie); if (flags & wxSOUND_ASYNC) { //Start timer and play movie asyncronously lastSoundTimer = ((wxQTTimer*&)m_pTimer) = new wxQTTimer(movie, flags & wxSOUND_LOOP ? 1 : 0, &lastSoundIsPlaying); lastSoundIsPlaying = true; ((wxQTTimer*)m_pTimer)->Start(MOVIE_DELAY, wxTIMER_CONTINUOUS); } else { wxASSERT_MSG(!(flags & wxSOUND_LOOP), wxT("Can't loop and play syncronously at the same time")); //Play movie until it ends, then exit //Note that due to quicktime caching this may not always //work 100% correctly while (!IsMovieDone(movie)) MoviesTask(movie, 1); DisposeMovie(movie); } return true; }
void GBSoundChannel::StartSound(GBSoundID id) { StopSound(); if ( SndPlay(channel, gSounds[id], true) ) throw GBGenericError("couldn't play sound"); priority = kSoundPriorities[id]; }
void play_sound(short which, short how_many_times) { // if < 0, play asynch #if defined(__APPLE__) Handle sndhandle; unsigned long dummy; OSErr err; SndCommand theCommand; if (!play_sounds || how_many_times == 0) return; if (abs(which) > NUM_SOUNDS) { //char msg[50]; /*s*/printf(/*msg,*/"Error: Sound #%i does not exist.\n",abs(which)); //give_error(msg,"",0); return; } channel++; if (channel > numchannel) channel = 0; if (!sound_going(abs(which)) && load_when_play[abs(which)]) sndhandle = GetResource('snd ',20000 + abs(which)); else sndhandle = sound_handles[abs(which)]; if (which > 0) if (always_asynch[which]) which *= -1; if (sndhandle != NULL) { HLock(sndhandle); if (which < 0) err = SndPlay(chan[channel],(SndListHandle) sndhandle,true); // Normal SndPlay else { err = SndPlay(chan[channel],(SndListHandle) sndhandle,false); } if (err != 0) { printf("Sound error.\n"); //add_string_to_buf("Sound Error. Error codes:"); //print_nums(channel,which,err); //add_string_to_buf("Your system could not play a sound."); //add_string_to_buf("Make sure editor isn't running."); //add_string_to_buf("Turn off sounds if necessary."); } HUnlock(sndhandle); snd_played[channel] = abs(which); theCommand.cmd = callBackCmd; theCommand.param1 = 0; #ifndef EXILE_BIG_GUNS theCommand.param2 = SetCurrentA5(); #endif #ifdef EXILE_BIG_GUNS theCommand.param2 = 0; #endif SndDoCommand(chan[channel],&theCommand,true); } else SysBeep(20); if (which < 0) Delay(sound_delay[-1 * which],&dummy); if(how_many_times > 1) play_sound(which, how_many_times - 1); #elif defined(WIN32) short i,num_fails = 0; char snd_name[30]; bool asyn = false,a_sound_did_get_played = false; bool not_asyn = false,check_sound; HRSRC h; if ((sounds_missing) || (!play_sounds) || (how_many_times == 0)) return; if (which < 0) { asyn = true; which = which * -1; } if (which >= 1000) { which -= 1000; not_asyn = true; } if (which >= 100) return; if ((always_asynch[which] == true) && ((can_ignore[which] == 1) || (can_ignore[which] >= 3))) asyn = true; if ((can_ignore[which] > 0) && (can_ignore[which] < 5) && (party.stuff_done[305][5] == 1)) return; if ((can_ignore[which] != 1) && (can_ignore[which] < 3)) asyn = false; if ((party.stuff_done[305][5] == 1) && (can_ignore[which] < 5)) asyn = false; if (not_asyn == true) asyn = false; if ((load_when_play[which] == true) && (sound_handles[which] == NULL)) { asyn = false; sprintf((char *)snd_name,"#%d",which + 1); h = FindResource(hModule,snd_name,"#100"); sound_handles[which] = LoadResource(hModule,h); snds[which] = (char *) LockResource(sound_handles[which]); } if (store_last_sound_played == 6) sndPlaySound(NULL,0); if (asyn == true) { if (can_ignore[which] >= 4) check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP); else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY); while (check_sound == false) { if (can_ignore[store_last_sound_played] == 4) {// then sound goes away return; } num_fails++; if (num_fails < 40) sound_pause(25); else { MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error a. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.", "Sound Error",MB_OK | MB_ICONEXCLAMATION); print_nums(111,which,num_fails); sounds_fucked = true; return; } sndPlaySound(NULL,0); if (can_ignore[which] >= 4) check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY | SND_NOSTOP); else check_sound = sndPlaySound(snds[which],SND_ASYNC | SND_MEMORY); } a_sound_did_get_played = true; } else { if (can_ignore[which] >= 4) check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP); else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY); while (check_sound == false) { if (can_ignore[store_last_sound_played] == 4) {// then sound goes away return; } num_fails++; if (num_fails < 40) sound_pause(25); else { MessageBox(mainPtr,"Cannot play sounds - Sounds stuck error b. Game can still be played, but quietly. Check to make sure your sound drivers are up to date and not corrupted.", "Sound Error",MB_OK | MB_ICONEXCLAMATION); print_nums(222,which,num_fails); sounds_fucked = true; return; } sndPlaySound(NULL,0); if (can_ignore[which] >= 4) check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY | SND_NOSTOP); else check_sound = sndPlaySound(snds[which],SND_SYNC | SND_MEMORY); } a_sound_did_get_played = true; } store_last_sound_played = which; if ((load_when_play[which] == true) && (asyn == false)) sound_handles[which] = NULL; for (i = 0; i < NUM_SOUNDS; i++) if ((load_when_play[which] == true) && (sound_handles[which] != NULL) && (a_sound_did_get_played == true) && (i != which)) { sound_handles[i] = NULL; } #endif }