/* Copyright (c) 2013 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener adiener@sacredsoftware.net */ #include "pcmaudio/PCMAudio.h" #include #include #define stemobject_implementation PCMAudio stemobject_vtable_begin(); stemobject_vtable_entry(dispose); stemobject_vtable_end(); PCMAudio * PCMAudio_create(unsigned int bytesPerSample, unsigned int channelCount, unsigned int sampleRate, AudioFrameIndex frameCount, void * samples, bool copySamples) { stemobject_create_implementation(init, bytesPerSample, channelCount, sampleRate, frameCount, samples, copySamples) } bool PCMAudio_init(PCMAudio * self, unsigned int bytesPerSample, unsigned int channelCount, unsigned int sampleRate, AudioFrameIndex frameCount, void * samples, bool copySamples) { call_super(init, self); self->bytesPerSample = bytesPerSample; self->channelCount = channelCount; self->sampleRate = sampleRate; self->frameCount = frameCount; if (copySamples) { self->samples = malloc(bytesPerSample * channelCount * frameCount); memcpy(self->samples, samples, bytesPerSample * channelCount * frameCount); } else { self->samples = samples; } return true; } PCMAudio * PCMAudio_copy(PCMAudio * self) { stemobject_copy_implementation(initCopy) } bool PCMAudio_isEqual(PCMAudio * self, PCMAudio * compare) { if (self->bytesPerSample != compare->bytesPerSample || self->channelCount != compare->channelCount || self->sampleRate != compare->sampleRate || self->frameCount != compare->frameCount) { return false; } return !memcmp(self->samples, compare->samples, self->frameCount * self->bytesPerSample * self->channelCount); } void PCMAudio_initCopy(PCMAudio * self, PCMAudio * original) { call_super(init, self); self->bytesPerSample = original->bytesPerSample; self->channelCount = original->channelCount; self->sampleRate = original->sampleRate; self->frameCount = original->frameCount; self->samples = malloc(self->bytesPerSample * self->channelCount * self->frameCount); memcpy(self->samples, original->samples, self->bytesPerSample * self->channelCount * self->frameCount); } void PCMAudio_dispose(PCMAudio * self) { free(self->samples); call_super(dispose, self); }