/* Copyright (c) 2020 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 alex@ludobloom.com */ #ifndef __AudioRecipe_H__ #define __AudioRecipe_H__ #ifdef __cplusplus extern "C" { #endif typedef struct AudioRecipe AudioRecipe; #define AudioRecipe_superclass StemObject #include "audiosynth/AudioMath.h" #include "pcmaudio/PCMAudio.h" #include "resourcemanager/ResourceManager.h" #include "serialization/DeserializationContext.h" #include "serialization/SerializationContext.h" #include "stemobject/StemObject.h" #include #define AUDIO_RECIPE_FORMAT_TYPE "audiolab_recipe" #define AUDIO_RECIPE_FORMAT_VERSION 0 typedef enum AudioRecipe_commandType { COMMAND_MIX, COMMAND_AMPLIFY, COMMAND_NORMALIZE, COMMAND_STRETCH, COMMAND_REVERSE, COMMAND_DELETE, COMMAND_FADE, COMMAND_EQUALIZE, COMMAND_CHANGE_SPEED, COMMAND_CHANGE_PITCH, COMMAND_SILENCE, COMMAND_TONE, COMMAND_NOISE } AudioRecipe_commandType; typedef enum AudioRecipe_sourceType { SOURCE_WAV_FILE, SOURCE_OGG_FILE, SOURCE_RECIPE, SOURCE_BFXR_SYNTH, SOURCE_SFXRX_SYNTH } AudioRecipe_sourceType; typedef enum AudioRecipe_outputFormat { OUTPUT_FORMAT_UNSPECIFIED, OUTPUT_FORMAT_WAV, OUTPUT_FORMAT_OGG } AudioRecipe_outputFormat; struct AudioRecipe_command { AudioRecipe_commandType type; uint64_t frameOffset; uint64_t frameCount; union { struct { AudioRecipe_sourceType sourceType; char * sourceName; uint64_t sourceFrameOffset; } mix; struct { int multiplier; int divisor; } scale; struct { AudioMath_envelopeFunction function; } envelope; struct { float bands[10]; // Decibels } equalize; struct { float frequency; // hertz AudioMath_waveFunction function; } tone; struct { uint32_t seed; } noise; } data; }; #define AudioRecipe_ivars \ StemObject_ivars \ \ char * outputFile; \ AudioRecipe_outputFormat outputFormat; \ unsigned int channelCount; \ unsigned int bytesPerSample; \ unsigned int sampleRate; \ unsigned int commandCount; \ struct AudioRecipe_command * commands; #define AudioRecipe_vtable(self_type) \ StemObject_vtable(self_type) stemobject_declare(AudioRecipe) AudioRecipe * AudioRecipe_create(void); bool AudioRecipe_init(AudioRecipe * self); void AudioRecipe_dispose(AudioRecipe * self); AudioRecipe * AudioRecipe_deserialize(compat_type(DeserializationContext *) deserializationContext); bool AudioRecipe_loadSerializedData(AudioRecipe * self, compat_type(DeserializationContext *) deserializationContext); void AudioRecipe_serialize(AudioRecipe * self, compat_type(SerializationContext *) serializationContext); PCMAudio * AudioRecipe_evaluate(AudioRecipe * self, ResourceManager * resourceManager); float AudioRecipe_envelope_rampUpLinear(float value); float AudioRecipe_envelope_rampDownLinear(float value); float AudioRecipe_wave_sine(float position); float AudioRecipe_wave_square(float position); float AudioRecipe_wave_triangle(float position); float AudioRecipe_wave_sawtooth(float position); #ifdef __cplusplus } #endif #endif