float* AUD_readSoundBuffer(const char* filename, float low, float high, float attack, float release, float threshold, int accumulate, int additive, int square, float sthreshold, double samplerate, int* length) { AUD_Buffer buffer; AUD_DeviceSpecs specs; specs.channels = AUD_CHANNELS_MONO; specs.rate = (AUD_SampleRate)samplerate; AUD_Reference<AUD_IFactory> sound; AUD_Reference<AUD_IFactory> file = new AUD_FileFactory(filename); AUD_Reference<AUD_IReader> reader = file->createReader(); AUD_SampleRate rate = reader->getSpecs().rate; sound = new AUD_ChannelMapperFactory(file, specs); if(high < rate) sound = new AUD_LowpassFactory(sound, high); if(low > 0) sound = new AUD_HighpassFactory(sound, low); sound = new AUD_EnvelopeFactory(sound, attack, release, threshold, 0.1f); sound = new AUD_LinearResampleFactory(sound, specs); if(square) sound = new AUD_SquareFactory(sound, sthreshold); if(accumulate) sound = new AUD_AccumulatorFactory(sound, additive); else if(additive) sound = new AUD_SumFactory(sound); reader = sound->createReader(); if(reader.isNull()) return NULL; int len; int position = 0; bool eos; do { len = samplerate; buffer.resize((position + len) * sizeof(float), true); reader->read(len, eos, buffer.getBuffer() + position); position += len; } while(!eos); float* result = (float*)malloc(position * sizeof(float)); memcpy(result, buffer.getBuffer(), position * sizeof(float)); *length = position; return result; }
AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep) { return play(factory->createReader(), keep); }
AUD_Reference<AUD_IHandle> AUD_OpenALDevice::play(AUD_Reference<AUD_IFactory> factory, bool keep) { /* AUD_XXX disabled AUD_OpenALHandle* sound = NULL; lock(); try { // check if it is a buffered factory for(AUD_BFIterator i = m_bufferedFactories->begin(); i != m_bufferedFactories->end(); i++) { if((*i)->factory == factory) { // create the handle sound = new AUD_OpenALHandle; sound->keep = keep; sound->current = -1; sound->isBuffered = true; sound->eos = true; sound->loopcount = 0; sound->stop = NULL; sound->stop_data = NULL; alcSuspendContext(m_context); // OpenAL playback code try { alGenSources(1, &sound->source); if(alGetError() != AL_NO_ERROR) AUD_THROW(AUD_ERROR_OPENAL, gensource_error); try { alSourcei(sound->source, AL_BUFFER, (*i)->buffer); if(alGetError() != AL_NO_ERROR) AUD_THROW(AUD_ERROR_OPENAL, queue_error); } catch(AUD_Exception&) { alDeleteSources(1, &sound->source); throw; } } catch(AUD_Exception&) { delete sound; alcProcessContext(m_context); throw; } // play sound m_playingSounds->push_back(sound); alSourcei(sound->source, AL_SOURCE_RELATIVE, 1); start(); alcProcessContext(m_context); } } } catch(AUD_Exception&) { unlock(); throw; } unlock(); if(sound) return sound;*/ return play(factory->createReader(), keep); }