bool AudioDescriptor::RemoveOwner(hoa_mode_manager::GameMode *gm) { if(!gm) return false; // Don't deal with never owned audio descriptors. if(_owners.empty()) return false; // Check for duplicate entries std::vector<hoa_mode_manager::GameMode *>::iterator it = _owners.begin(); for(; it != _owners.end();) { if(*it != gm) { ++it; continue; } // Remove the owner and check whether the sound can be freed it = _owners.erase(it); if(_owners.empty()) { FreeAudio(); return true; } } return false; }
ULONG gw_FreeAudio( struct _Regs* regs ) { struct AHIPrivAudioCtrl* audioctrl = (struct AHIPrivAudioCtrl*) GET_LONG( regs->a2 ); struct AHIBase* AHIBase = (struct AHIBase*) GET_LONG( regs->a6 ); return FreeAudio( audioctrl, AHIBase ); }
ULONG gw_FreeAudio( void ) { struct AHIPrivAudioCtrl* audioctrl = (struct AHIPrivAudioCtrl*) REG_A2; struct AHIBase* AHIBase = (struct AHIBase*) REG_A6; return FreeAudio( audioctrl, AHIBase ); }
void RtsForm::OnFinalMessage(HWND hWnd) { if (show_endmsg_) { ShowEndMsg(); } if (type_ & nim::kNIMRtsChannelTypeVchat) { FreeAudio(); FreeMic(); } if (need_ack_) { nim::Rts::Ack(session_id_, type_, false, nim::Rts::AckCallback()); } else { nim::Rts::Hangup(session_id_, nim::Rts::HangupCallback()); } __super::OnFinalMessage(hWnd); }
ULONG ASMCALL gw_FreeAudio( REG(a2, struct AHIPrivAudioCtrl* audioctrl), REG(a6, struct AHIBase* AHIBase) ) { return FreeAudio( audioctrl, AHIBase ); }
void CResourceManager::ShutDown(void) { FreeTextures(); FreeAudio(); }
bool AudioDescriptor::LoadAudio(const std::string &filename, AUDIO_LOAD load_type, uint32 stream_buffer_size) { if(!AUDIO_ENABLE) return true; // Clean out any audio resources being used before trying to set new ones FreeAudio(); // Load the input file for the audio if(filename.size() <= 3) { // Name of file is at least 3 letters (so the extension is in there) IF_PRINT_WARNING(AUDIO_DEBUG) << "file name argument is too short: " << filename << std::endl; return false; } // Convert the file extension to uppercase and use it to create the proper input type std::string file_extension = filename.substr(filename.size() - 3, 3); file_extension = hoa_utils::Upcase(file_extension); // Based on the extension of the file, load properly one if(file_extension.compare("WAV") == 0) { _input = new WavFile(filename); } else if(file_extension.compare("OGG") == 0) { _input = new OggFile(filename); } else { IF_PRINT_WARNING(AUDIO_DEBUG) << "failed due to unsupported input file extension: " << file_extension << std::endl; return false; } if(_input->Initialize() == false) { IF_PRINT_WARNING(AUDIO_DEBUG) << "failed to load and initialize audio file: " << filename << std::endl; return false; } // Retreive audio data properties from the newly initialized input if(_input->GetBitsPerSample() == 8) { if(_input->GetNumberChannels() == 1) { _format = AL_FORMAT_MONO8; } else { _format = AL_FORMAT_STEREO8; } } else { // 16 bits per sample if(_input->GetNumberChannels() == 1) { _format = AL_FORMAT_MONO16; } else { _format = AL_FORMAT_STEREO16; } } // Load the audio data depending upon the load type requested if(load_type == AUDIO_LOAD_STATIC) { // For static sounds just 1 buffer is needed. We create it as an array here, so that // later we can delete it with a call of delete[], similar to the streaming cases _buffer = new AudioBuffer[1]; // Create space in memory for the audio data to be read and passed to the OpenAL buffer _data = new uint8[_input->GetDataSize()]; bool all_data_read = false; if(_input->Read(_data, _input->GetTotalNumberSamples(), all_data_read) != _input->GetTotalNumberSamples()) { IF_PRINT_WARNING(AUDIO_DEBUG) << "failed to read entire audio data stream for file: " << filename << std::endl; return false; } // Pass the buffer data to the OpenAL buffer _buffer->FillBuffer(_data, _format, _input->GetDataSize(), _input->GetSamplesPerSecond()); delete[] _data; _data = NULL; // Attempt to acquire a source for the new audio to use _AcquireSource(); if(_source == NULL) { IF_PRINT_WARNING(AUDIO_DEBUG) << "could not acquire audio source for new audio file: " << filename << std::endl; } } // if (load_type == AUDIO_LOAD_STATIC) // Stream the audio from the file data else if(load_type == AUDIO_LOAD_STREAM_FILE) { _buffer = new AudioBuffer[NUMBER_STREAMING_BUFFERS]; // For streaming we need to use multiple buffers _stream = new AudioStream(_input, _looping); _stream_buffer_size = stream_buffer_size; _data = new uint8[_stream_buffer_size * _input->GetSampleSize()]; // Attempt to acquire a source for the new audio to use _AcquireSource(); if(_source == NULL) { IF_PRINT_WARNING(AUDIO_DEBUG) << "could not acquire audio source for new audio file: " << filename << std::endl; } } // else if (load_type == AUDIO_LOAD_STREAM_FILE) // Allocate memory for the audio data to remain in and stream it from that location else if(load_type == AUDIO_LOAD_STREAM_MEMORY) { _buffer = new AudioBuffer[NUMBER_STREAMING_BUFFERS]; // For streaming we need to use multiple buffers _stream = new AudioStream(_input, _looping); _stream_buffer_size = stream_buffer_size; _data = new uint8[_stream_buffer_size * _input->GetSampleSize()]; // We need to replace the _input member with a AudioMemory class object AudioInput *temp_input = _input; _input = new AudioMemory(temp_input); delete temp_input; // Attempt to acquire a source for the new audio to use _AcquireSource(); if(_source == NULL) { IF_PRINT_WARNING(AUDIO_DEBUG) << "could not acquire audio source for new audio file: " << filename << std::endl; } } // else if (load_type == AUDIO_LOAD_STREAM_MEMORY) { else { IF_PRINT_WARNING(AUDIO_DEBUG) << "unknown load_type argument passed: " << load_type << std::endl; return false; } if(AudioManager->CheckALError()) IF_PRINT_WARNING(AUDIO_DEBUG) << "OpenAL generated the following error: " << AudioManager->CreateALErrorString() << std::endl; _state = AUDIO_STATE_STOPPED; return true; } // bool AudioDescriptor::LoadAudio(const string& file_name, AUDIO_LOAD load_type, uint32 stream_buffer_size)