AUD_SoundInfo AUD_getInfo(AUD_Sound* sound) { assert(sound); AUD_SoundInfo info; info.specs.channels = AUD_CHANNELS_INVALID; info.specs.rate = AUD_RATE_INVALID; info.length = 0.0f; try { AUD_Reference<AUD_IReader> reader = (*sound)->createReader(); if(!reader.isNull()) { info.specs = reader->getSpecs(); info.length = reader->getLength() / (float) info.specs.rate; } } catch(AUD_Exception&) { } return info; }
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize) { AUD_Reference<AUD_IDevice> dev; if(!AUD_device.isNull()) AUD_exit(); try { switch(device) { case AUD_NULL_DEVICE: dev = new AUD_NULLDevice(); break; #ifdef WITH_SDL case AUD_SDL_DEVICE: dev = new AUD_SDLDevice(specs, buffersize); break; #endif #ifdef WITH_OPENAL case AUD_OPENAL_DEVICE: dev = new AUD_OpenALDevice(specs, buffersize); break; #endif #ifdef WITH_JACK case AUD_JACK_DEVICE: #ifdef __APPLE__ struct stat st; if(stat("/Library/Frameworks/Jackmp.framework", &st) != 0) { printf("Warning: Jack Framework not installed\n"); // No break, fall through to default, to return false } else { #endif dev = new AUD_JackDevice("Blender", specs, buffersize); break; #ifdef __APPLE__ } #endif #endif default: return false; } AUD_device = dev; AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get()); return true; } catch(AUD_Exception&) { return false; } }
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; }
static PyObject* AUD_getCDevice(PyObject* self) { if(!AUD_device.isNull()) { Device* device = (Device*)Device_empty(); if(device != NULL) { device->device = new AUD_Reference<AUD_IDevice>(AUD_device); return (PyObject*)device; } } Py_RETURN_NONE; }
int AUD_init(AUD_DeviceType device, AUD_DeviceSpecs specs, int buffersize) { AUD_Reference<AUD_IDevice> dev; if(!AUD_device.isNull()) AUD_exit(); try { switch(device) { case AUD_NULL_DEVICE: dev = new AUD_NULLDevice(); break; #ifdef WITH_SDL case AUD_SDL_DEVICE: dev = new AUD_SDLDevice(specs, buffersize); break; #endif #ifdef WITH_OPENAL case AUD_OPENAL_DEVICE: dev = new AUD_OpenALDevice(specs, buffersize); break; #endif #ifdef WITH_JACK case AUD_JACK_DEVICE: dev = new AUD_JackDevice("Blender", specs, buffersize); break; #endif default: return false; } AUD_device = dev; AUD_3ddevice = dynamic_cast<AUD_I3DDevice*>(AUD_device.get()); return true; } catch(AUD_Exception&) { return false; } }
AUD_Reference<AUD_IHandle> AUD_SoftwareDevice::play(AUD_Reference<AUD_IReader> reader, bool keep) { // prepare the reader // pitch AUD_Reference<AUD_PitchReader> pitch = new AUD_PitchReader(reader, 1); reader = AUD_Reference<AUD_IReader>(pitch); AUD_Reference<AUD_ResampleReader> resampler; // resample if(m_quality) resampler = new AUD_JOSResampleReader(reader, m_specs.specs); else resampler = new AUD_LinearResampleReader(reader, m_specs.specs); reader = AUD_Reference<AUD_IReader>(resampler); // rechannel AUD_Reference<AUD_ChannelMapperReader> mapper = new AUD_ChannelMapperReader(reader, m_specs.channels); reader = AUD_Reference<AUD_IReader>(mapper); if(reader.isNull()) return AUD_Reference<AUD_IHandle>(); // play sound AUD_Reference<AUD_SoftwareDevice::AUD_SoftwareHandle> sound = new AUD_SoftwareDevice::AUD_SoftwareHandle(this, reader, pitch, resampler, mapper, keep); lock(); m_playingSounds.push_back(sound); if(!m_playback) playing(m_playback = true); unlock(); return AUD_Reference<AUD_IHandle>(sound); }