#include <stdio.h>
 
 
#ifdef SP_SUPPORT_AUDIO
 
static double rec_time;
static long buffer_size;
static double input_gain;
static double samp_freq;
static int num_channel;
static int samp_bit;
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 channel", NULL,
         SP_TYPE_INT, &num_channel, "1"},
    {"-b", "-bit", "bits per sample", NULL,
         SP_TYPE_INT, &samp_bit, "16"},
    {"-igain", NULL, "input gain", NULL,
         SP_TYPE_DOUBLE, &input_gain, "1.0"},
    {"-time", NULL, "recording time [s]", NULL,
         SP_TYPE_DOUBLE, &rec_time, "3.0"},
    {"-buf", NULL, "buffer size", NULL,
         SP_TYPE_LONG, &buffer_size, "256"},
    {"-nbuf", NULL, "number of buffers (valid only on Windows/Mac)", NULL,
         SP_TYPE_INT, &num_buffer, "64"},
    {"-endless", NULL, "recording endlessly (full duplex mode only)", NULL,
    {"-duplex", NULL, "full duplex mode", NULL,
    {"-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[] = {
    "",
};
 
int spMain(int argc, char *argv[])
{
    long k, l;
    long nread;
    long length;
    long rec_length;
    double *wave_data;
    long wave_length;
 
 
        spDebug(10, 
"spMain", 
"plugin_search_path: %s\n", plugin_search_path);
 
    }
    
    rec_length = (long)
spRound(rec_time * samp_freq);
 
        spError(1, 
"Can't initialize audio.\n");
 
    }
    spDebug(1, NULL, 
"init audio done\n");
 
 
 
 
    if (duplex_flag == 
SP_TRUE) {
 
        for (l = 0; l < 2; l++) {
            
                spError(1, 
"Can't open audio device.\n");
 
            }
            spDebug(1, NULL, 
"open input audio device done\n");
 
            
            
                spError(1, 
"Can't open audio device with full duplex mode.\n");
 
            }
            
            
            wave_length = buffer_size / 2 / num_channel; 
            wave_data = 
xspAlloc(wave_length, 
double);
            
            length = 0;
            for (;;) {
                    break;
                }
 
                if (input_gain != 1.0) {
                    for (k = 0; k < nread; k++) {
                        wave_data[k] = input_gain * wave_data[k];
                    }
                }
            
            
                if (endless_flag == 
SP_FALSE) {
 
                    length += (nread / num_channel);
            
                    if (length >= rec_length) {
                        break;
                    }
                }
            }
            
        }
    } else {
        for (l = 0; l < 2; l++) {
            
                spError(1, 
"Can't open audio device.\n");
 
            }
            spDebug(1, NULL, 
"open input audio device done\n");
 
            
            
            wave_length = rec_length * num_channel;
            wave_data = 
xspAlloc(wave_length, 
double);
            
            
            if (input_gain != 1.0) {
                for (k = 0; k < nread; k++) {
                    wave_data[k] = input_gain * wave_data[k];
                }
            }
            
            
                spError(1, 
"Can't open audio device.\n");
 
            }
            spDebug(1, NULL, 
"open output audio device done\n");
 
            
            
        }
    }
 
    
    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
void spError(int status, const char *format,...)
void spSetDebugLevel(int level)
void spWarning(const char *format,...)
void spMessage(const char *format,...)
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)
spAudio spInitAudioDriver(const char *driver_name)
spBool spGetAudioChannel(spAudio audio, int *num_channel)
spBool spSetAudioBufferSize(spAudio audio, int buffer_size)
spBool spSetAudioSampleBit(spAudio audio, int samp_bit)
long spReadAudioDouble(spAudio audio, double *data, long length)
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)