1*b290403dSRicardo Garcia /* Sonic library 2*b290403dSRicardo Garcia Copyright 2010 3*b290403dSRicardo Garcia Bill Cox 4*b290403dSRicardo Garcia This file is part of the Sonic Library. 5*b290403dSRicardo Garcia 6*b290403dSRicardo Garcia This file is licensed under the Apache 2.0 license. 7*b290403dSRicardo Garcia */ 8*b290403dSRicardo Garcia 9*b290403dSRicardo Garcia /* 10*b290403dSRicardo Garcia This is a stripped down version of sonic, to help it fit in micro-controllers. 11*b290403dSRicardo Garcia Only mono speedup remains. All buffers are allocated statically. 12*b290403dSRicardo Garcia */ 13*b290403dSRicardo Garcia 14*b290403dSRicardo Garcia #ifdef __cplusplus 15*b290403dSRicardo Garcia extern "C" { 16*b290403dSRicardo Garcia #endif 17*b290403dSRicardo Garcia 18*b290403dSRicardo Garcia /* Use a minimum pitch of 80 to reduce buffer sizes. Set it back to 65 if you 19*b290403dSRicardo Garcia have the room in memory and find it sounds better. */ 20*b290403dSRicardo Garcia #define SONIC_MIN_PITCH 65 21*b290403dSRicardo Garcia #define SONIC_MAX_PITCH 400 22*b290403dSRicardo Garcia 23*b290403dSRicardo Garcia /* These are used to down-sample some inputs to improve speed */ 24*b290403dSRicardo Garcia #define SONIC_AMDF_FREQ 4000 25*b290403dSRicardo Garcia 26*b290403dSRicardo Garcia /* This is the sample frequency. You must hard-code it rather than passing it in. */ 27*b290403dSRicardo Garcia #define SONIC_SAMPLE_RATE 8000 28*b290403dSRicardo Garcia 29*b290403dSRicardo Garcia /* This is the number of samples in the buffer size passed to Sonic. */ 30*b290403dSRicardo Garcia #define SONIC_INPUT_SAMPLES 80 31*b290403dSRicardo Garcia 32*b290403dSRicardo Garcia /* Initialize Sonic. */ 33*b290403dSRicardo Garcia void sonicInit(void); 34*b290403dSRicardo Garcia /* Write input samples to the stream. numSamples must be <= SONIC_INPUT_SAMPLES */ 35*b290403dSRicardo Garcia void sonicWriteShortToStream(short *samples, int numSamples); 36*b290403dSRicardo Garcia /* Use this to read 16-bit data out of the stream. Sometimes no data will 37*b290403dSRicardo Garcia be available, and zero is returned, which is not an error condition. */ 38*b290403dSRicardo Garcia int sonicReadShortFromStream(short *samples, int maxSamples); 39*b290403dSRicardo Garcia /* Force the sonic stream to generate output using whatever data it currently 40*b290403dSRicardo Garcia has. No extra delay will be added to the output, but flushing in the middle 41*b290403dSRicardo Garcia of words could introduce distortion. */ 42*b290403dSRicardo Garcia void sonicFlushStream(void); 43*b290403dSRicardo Garcia /* Return the number of samples in the output buffer */ 44*b290403dSRicardo Garcia int sonicSamplesAvailable(void); 45*b290403dSRicardo Garcia /* Set the speed of the stream. */ 46*b290403dSRicardo Garcia void sonicSetSpeed(float speed); 47*b290403dSRicardo Garcia /* Set the scaling factor of the stream. */ 48*b290403dSRicardo Garcia void sonicSetVolume(float volume); 49*b290403dSRicardo Garcia 50*b290403dSRicardo Garcia #ifdef __cplusplus 51*b290403dSRicardo Garcia } 52*b290403dSRicardo Garcia #endif 53