// Decode bool Sound::decode(const RString& path, SoundInfo& info, float** data) { bool decoded = false; AudioSource* source = 0; if (path.find(OGG_FILE_EXT) != RString::npos) { #if MOAI_WITH_VORBIS OggAudioSource* as = new OggAudioSource(); source = as; if(as->init(path, true)) decoded = true; #endif } else { #if defined(__APPLE__) ExtAudioFileAudioSource *as = new ExtAudioFileAudioSource(); source = as; if(as->init(path, true)) decoded = true; #elif defined(__ANDROID__) | defined(__linux__) | defined(__OPENAL__) | defined ( __QNX__ ) WaveFileAudioSource *as = new WaveFileAudioSource(); source = as; if(as->init(path, true)) decoded = true; #else DShowAudioSource* as = new DShowAudioSource(); source = as; if(as->init(path, true)) decoded = true; #endif } // Couldn't decode the file if(!decoded) { if(source) delete source; return false; } RAudioBuffer* buffer = source->getBuffer(); UInt32 size = buffer->getDataSize(); // Allocate space and copy the buffer *data = (float*)new char[size]; buffer->copyInto(*data); info.mChannels = source->getNumChannels(); info.mBitsPerSample = 32; info.mSampleRate = source->getSampleRate(); info.mTotalFrames = size / 4 / source->getNumChannels(); info.mLength = (double)size / 4.0 / source->getNumChannels() / source->getSampleRate(); if(source) delete source; return true; }