#include <stdio.h>
 
 
#ifdef SP_SUPPORT_AUDIO
 
static double fund_freq;
static double dur_time;
static double amplitude;
static double samp_freq;
static int num_channel;
static int samp_bit = 16;
static long buffer_size;
static int num_buffer;
 
static char *driver_name = NULL;
static char *plugin_search_path = NULL;
 
static int debug_level = -1;
 
    {"-f", "-freq", "sampling frequency [Hz]", NULL,
         SP_TYPE_DOUBLE, &samp_freq, "8000.0"},
    {"-c", "-channel", "number of channels", NULL,
         SP_TYPE_INT, &num_channel, "1"},
    {"-b", "-bit", "bits per sample", NULL,
         SP_TYPE_INT, &samp_bit, "16"},
    {"-f0", NULL, "fundamental frequency [Hz]", NULL,
         SP_TYPE_DOUBLE, &fund_freq, "1000.0"},
    {"-a", "-amp", "amplitude", NULL,
         SP_TYPE_DOUBLE, &litude, "0.9"},
    {"-d", "-dur", "duration [s]", NULL,
         SP_TYPE_DOUBLE, &dur_time, "5.0"},
    {"-buf", NULL, "buffer size", NULL,
         SP_TYPE_LONG, &buffer_size, "16384"},
    {"-nbuf", NULL, "number of buffers (valid only on Windows)", NULL,
         SP_TYPE_INT, &num_buffer, "16"},
    {"-driver", NULL, "audio driver name", NULL,
         SP_TYPE_STRING, &driver_name, NULL},
    {"-path", NULL, "plugin search path", NULL,
         SP_TYPE_STRING, &plugin_search_path, NULL},
    {"-debug", NULL, "debug level", NULL,
         SP_TYPE_INT, &debug_level, NULL},
    {"-help", "-h", "display this message", NULL,
};
 
static const char *filelabel[] = {
    "",
};
 
                           void *data1, void *data2, void *user_data)
{
        double samp_rate;
        spLong *ppos = (spLong *)data1;
        spLong *data_length = (spLong *)user_data;
 
        spDebug(10, 
"callbackFunc", 
"samp_rate = %f, ppos = %ld / %ld\n", samp_rate, (
long)*ppos, (
long)*data_length);
 
 
        printf("Time: %.2f / %.2f\r", (double)*ppos / samp_rate, (double)*data_length / samp_rate);
    }
    
}
 
int spMain(int argc, char *argv[])
{
    int c;
    spLong k;
    spLong offset;
    spLong data_length;
    double period;
    double *data;
 
 
        spDebug(10, 
"spMain", 
"plugin_search_path: %s\n", plugin_search_path);
 
    }
 
    spDebug(10, NULL, 
"samp_freq = %f, f0 = %f, duration = %f, num_channel = %d\n",
 
            samp_freq, fund_freq, dur_time, num_channel);
 
    num_channel = MAX(num_channel, 1);
    data_length = (spLong)
spRound(dur_time * samp_freq);
    period = samp_freq / fund_freq;
 
    spDebug(1, NULL, 
"data_length = %ld, period = %f\n", (
long)data_length, period);
 
    
        spError(1, 
"Can't initialize audio.\n");
 
    }
    spDebug(1, NULL, 
"init audio done\n");
 
 
 
 
    
        spError(1, 
"Can't open audio device.\n");
 
    }
    spDebug(1, NULL, 
"open output audio device done\n");
 
 
    
    data = 
xspAlloc(data_length * num_channel, 
double);
    for (k = 0; k < data_length; k++) {
        data[k * num_channel] = amplitude * sin(2.0 * PI * (double)k / period);
        for (c = 1; c < num_channel; c++) {
            data[k * num_channel + c] = data[k * num_channel];
        }
    }
    
    offset = 0;
    
    
    spWriteAudioDouble(audio, data + offset * num_channel, (data_length - offset) * num_channel);
 
 
    
 
    
    
    return 0;
}
#else
int spMain(int argc, char *argv[])
{
    spError(1, 
"Audio is not supported.\n");
 
    return 0;
}
#endif
A class to handle audio I/O.
#define spFreeAudioDriver(audio)
Definition spAudio.h:373
unsigned long spAudioCallbackType
Definition spAudio.h:63
#define SP_AUDIO_OUTPUT_POSITION_CALLBACK
Definition spAudio.h:66
void spError(int status, const char *format,...)
void spSetDebugLevel(int level)
void spSetDebugStdout(int flag)
void spDebug(int level, const char *func_name, const char *format,...)
#define spStrNone(string)
#define xspAlloc(n, type)
#define spGetOptions(argc, argv, option, file_label)
struct _spOptions * spOptions
void spGetOptionsValue(int argc, char **argv, spOptions options)
void spSetHelpMessage(spBool *flag, const char *format,...)
void spSetPluginSearchPath(const char *pathlist)
spAudioCallbackType spSetAudioCallbackFunc(spAudio audio, spAudioCallbackType call_type, spAudioCallbackFunc call_func, void *call_data)
spAudio spInitAudioDriver(const char *driver_name)
spBool spGetAudioSampleRate(spAudio audio, double *samp_rate)
spBool spSetAudioBufferSize(spAudio audio, int buffer_size)
spBool spSetAudioSampleBit(spAudio audio, int samp_bit)
long spWriteAudioDouble(spAudio audio, double *data, long length)
spBool spSetAudioSampleRate(spAudio audio, double samp_rate)
spBool spOpenAudioDevice(spAudio audio, const char *mode)
spBool spSetAudioNumBuffer(spAudio audio, int num_buffer)
spBool spSetAudioChannel(spAudio audio, int num_channel)
spBool spCloseAudioDevice(spAudio audio)