本文整理汇总了C++中sf_command函数的典型用法代码示例。如果您正苦于以下问题:C++ sf_command函数的具体用法?C++ sf_command怎么用?C++ sf_command使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sf_command函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: sf_open
// ----------------------------------------------------------------------------
bool ofOpenALSoundPlayer::sfReadFile(string path, vector<short> & buffer, vector<float> & fftAuxBuffer){
SF_INFO sfInfo;
SNDFILE* f = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!f){
ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: couldnt read " + path);
return false;
}
buffer.resize(sfInfo.frames*sfInfo.channels);
fftAuxBuffer.resize(sfInfo.frames*sfInfo.channels);
int subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE){
double scale ;
sf_command (f, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
sf_count_t samples_read = sf_read_float (f, &fftAuxBuffer[0], fftAuxBuffer.size());
if(samples_read<(int)fftAuxBuffer.size())
ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: couldnt read " + path);
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(f,&buffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: couldnt read buffer for " + path);
return false;
}
sf_seek(f,0,SEEK_SET);
frames_read = sf_readf_float(f,&fftAuxBuffer[0],sfInfo.frames);
if(frames_read<sfInfo.frames){
ofLog(OF_LOG_ERROR,"ofOpenALSoundPlayer: couldnt read fft buffer for " + path);
return false;
}
}
sf_close(f);
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
return true;
}
示例2: dump_log_buffer
void
dump_log_buffer (SNDFILE *file)
{ static char buffer [LOG_BUFFER_SIZE] ;
int count ;
memset (buffer, 0, LOG_BUFFER_SIZE) ;
/* Get the log buffer data. */
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
if (strlen (buffer) < 1)
puts ("Log buffer empty.\n") ;
else
puts (buffer) ;
return ;
} /* dump_log_buffer */
示例3: sf_error_number
std::string AudioFileSndfile::sndfileError(int errorNumber,
const std::string& userMessage) const
{
const std::string libraryMessage = sf_error_number(errorNumber);
char logInfo[LOGINFO_MAX_SIZE];
sf_command(_handle.get(), SFC_GET_LOG_INFO, logInfo, LOGINFO_MAX_SIZE);
LOG(INFO,
"Library error detailed information"
<< "\n\n"
<< "Sound file: " << _path << '\n'
<< "Library reports: " << libraryMessage << '\n'
<< "Library version: " << sf_version_string() << '\n'
<< "Library log follows:\n"
<< logInfo);
return userMessage + ": " + libraryMessage;
}
示例4: usage_exit
static void
usage_exit (const char *progname)
{ char lsf_ver [128] ;
const char *cptr ;
int k ;
if ((cptr = strrchr (progname, '/')) != NULL)
progname = cptr + 1 ;
if ((cptr = strrchr (progname, '\\')) != NULL)
progname = cptr + 1 ;
sf_command (NULL, SFC_GET_LIB_VERSION, lsf_ver, sizeof (lsf_ver)) ;
printf ("\n"
" A Sample Rate Converter using libsndfile for file I/O and Secret \n"
" Rabbit Code (aka libsamplerate) for performing the conversion.\n"
" It works on any file format supported by libsndfile with any \n"
" number of channels (limited only by host memory).\n"
"\n"
" %s\n"
" %s\n"
"\n"
" Usage : \n"
" %s -to <new sample rate> [-c <number>] <input file> <output file>\n"
" %s -by <amount> [-c <number>] <input file> <output file>\n"
"\n", src_get_version (), lsf_ver, progname, progname) ;
puts (
" The optional -c argument allows the converter type to be chosen from\n"
" the following list :"
"\n"
) ;
for (k = 0 ; (cptr = src_get_name (k)) != NULL ; k++)
printf (" %d : %s%s\n", k, cptr, k == DEFAULT_CONVERTER ? " (default)" : "") ;
puts ("\n"
" The --no-normalize option disables clipping check and normalization.") ;
puts ("") ;
exit (1) ;
} /* usage_exit */
示例5: main
int
main (int argc, char *argv [])
{ SNDFILE *file ;
SF_INFO sfinfo ;
SF_BROADCAST_INFO_2K binfo ;
const char *progname ;
const char * filename = NULL ;
int start ;
/* Store the program name. */
progname = program_name (argv [0]) ;
/* Check if we've been asked for help. */
if (argc <= 2 || strcmp (argv [1], "--help") == 0 || strcmp (argv [1], "-h") == 0)
usage_exit (progname, 0) ;
if (argv [argc - 1][0] != '-')
{ filename = argv [argc - 1] ;
start = 1 ;
}
else if (argv [1][0] != '-')
{ filename = argv [1] ;
start = 2 ;
}
else
{ printf ("Error : Either the first or the last command line parameter should be a filename.\n\n") ;
exit (1) ;
} ;
/* Get the time in case we need it later. */
memset (&sfinfo, 0, sizeof (sfinfo)) ;
if ((file = sf_open (filename, SFM_READ, &sfinfo)) == NULL)
{ printf ("Error : Open of file '%s' failed : %s\n\n", filename, sf_strerror (file)) ;
exit (1) ;
} ;
memset (&binfo, 0, sizeof (binfo)) ;
if (sf_command (file, SFC_GET_BROADCAST_INFO, &binfo, sizeof (binfo)) == 0)
memset (&binfo, 0, sizeof (binfo)) ;
process_args (file, &binfo, argc - 2, argv + start) ;
sf_close (file) ;
return 0 ;
} /* main */
示例6: string_in_log_buffer
int
string_in_log_buffer (SNDFILE *file, const char *s)
{ static char buffer [LOG_BUFFER_SIZE] ;
int count ;
memset (buffer, 0, LOG_BUFFER_SIZE) ;
/* Get the log buffer data. */
count = sf_command (file, SFC_GET_LOG_INFO, buffer, LOG_BUFFER_SIZE) ;
if (LOG_BUFFER_SIZE - count < 2)
{ printf ("Possible long log buffer.\n") ;
exit (1) ;
}
/* Look for string */
return strstr (buffer, s) ? SF_TRUE : SF_FALSE ;
} /* string_in_log_buffer */
示例7: sf_ctrl
// Write SF control
void sf_ctrl(u8 data)
{
if (data & SPIFL_MASK_EN)
// SF enabled
{
if (sf_state == SF_ST_INACT)
// enable SFI
sfi_enable();
else
// execute command
sf_command(data);
}
else
// disable SFI
sfi_disable(); // enable JTAG
}
示例8: startread
/*
* Open file in sndfile.
*/
static int startread(sox_format_t * ft)
{
priv_t * sf = (priv_t *)ft->priv;
unsigned bits_per_sample;
sox_encoding_t encoding;
sox_rate_t rate;
start(ft);
sf->sf_file = sf_open_fd(fileno(ft->fp), SFM_READ, sf->sf_info, 1);
ft->fp = NULL; /* Transfer ownership of fp to LSF */
drain_log_buffer(ft);
if (sf->sf_file == NULL) {
memset(ft->sox_errstr, 0, sizeof(ft->sox_errstr));
strncpy(ft->sox_errstr, sf_strerror(sf->sf_file), sizeof(ft->sox_errstr)-1);
free(sf->sf_file);
return SOX_EOF;
}
if (!(encoding = sox_enc(sf->sf_info->format, &bits_per_sample))) {
lsx_fail_errno(ft, SOX_EFMT, "unsupported sndfile encoding %#x", sf->sf_info->format);
return SOX_EOF;
}
/* Don't believe LSF's rate for raw files */
if ((sf->sf_info->format & SF_FORMAT_TYPEMASK) == SF_FORMAT_RAW && !ft->signal.rate) {
lsx_warn("'%s': sample rate not specified; trying 8kHz", ft->filename);
rate = 8000;
}
else rate = sf->sf_info->samplerate;
#if 0
if ((sf->sf_info->format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT)
sf_command(sf->sf_file, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
#endif
#if 0 /* FIXME */
sox_append_comments(&ft->oob.comments, buf);
#endif
return check_read_params(ft, (unsigned)sf->sf_info->channels, rate,
encoding, bits_per_sample, (off_t)(sf->sf_info->frames * sf->sf_info->channels));
}
示例9: main
int main (int argc, char *argv[])
{ static char strbuffer [BUFFER_LEN] ;
unsigned int linecount ;
char *progname, *infilename ;
SNDFILE *infile ;
SF_INFO sfinfo ;
int k, start, readcount ;
progname = strrchr (argv [0], '/') ;
progname = progname ? progname + 1 : argv [0] ;
if (argc != 2)
{ print_usage (progname) ;
return 1 ;
} ;
infilename = argv [1] ;
if (! (infile = sf_open (infilename, SFM_READ, &sfinfo)))
{ printf ("Error : Not able to open input file %s.\n", infilename) ;
sf_perror (NULL) ;
sf_command (NULL, SFC_GET_LOG_INFO, strbuffer, BUFFER_LEN) ;
printf (strbuffer) ;
return 1 ;
} ;
start = 0 ;
linecount = 24 ;
while ((readcount = sf_read_raw (infile, strbuffer, linecount)))
{ printf ("%08X: ", start) ;
for (k = 0 ; k < readcount ; k++)
printf ("%02X ", strbuffer [k] & 0xFF) ;
for (k = readcount ; k < 16 ; k++)
printf (" ") ;
printf ("\n") ;
start += readcount ;
} ;
sf_close (infile) ;
return 0 ;
} /* main */
示例10: TFileAudioStream
TReadFileAudioStream::TReadFileAudioStream(string name, long beginFrame): TFileAudioStream(name)
{
memset(&fInfo, 0, sizeof(fInfo));
char utf8name[512] = {0};
assert(fName.size() < 512);
Convert2UTF8(fName.c_str(), utf8name, 512);
fFile = sf_open(utf8name, SFM_READ, &fInfo);
// Check file
if (!fFile) {
throw - 1;
}
if (sf_seek(fFile, beginFrame, SEEK_SET) < 0) {
sf_close(fFile);
throw - 2;
}
fFramesNum = long(fInfo.frames);
fChannels = long(fInfo.channels);
fBeginFrame = beginFrame;
// Needed because we later on use sf_readf_short, should be removed is sf_readf_float is used instead.
if (fInfo.format & SF_FORMAT_FLOAT) {
int arg = SF_TRUE;
sf_command(fFile, SFC_SET_SCALE_FLOAT_INT_READ, &arg, sizeof(arg));
}
if (fInfo.samplerate != TAudioGlobals::fSampleRate) {
printf("Warning : file sample rate different from engine sample rate! lib sr = %ld file sr = %d\n", TAudioGlobals::fSampleRate, fInfo.samplerate);
}
// Dynamic allocation
fMemoryBuffer = new TLocalAudioBuffer<short>(TAudioGlobals::fStreamBufferSize, fChannels);
fCopyBuffer = new TLocalAudioBuffer<short>(TAudioGlobals::fStreamBufferSize, fChannels);
// Read first buffer directly
TBufferedAudioStream::ReadBuffer(fMemoryBuffer, TAudioGlobals::fStreamBufferSize, 0);
TAudioBuffer<short>::Copy(fCopyBuffer, 0, fMemoryBuffer, 0, TAudioGlobals::fStreamBufferSize);
fReady = true;
}
示例11: sf_command
void QcWaveform::doLoad( SNDFILE *new_sf, const SF_INFO &new_info, sf_count_t beg, sf_count_t dur )
{
// set up soundfile to scale data in range [-1,1] to int range
// when reading floating point data as int
sf_command( new_sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE );
// check beginning and duration validity
if( beg < 0 || dur < 1 || beg + dur > new_info.frames ) {
qcErrorMsg("Invalid beginning and/or duration.");
sf_close( new_sf );
return;
}
// cleanup previous state
// NOTE we have to delete SoundCacheStream before closing the soundfile, as it might be still
// loading it
// TODO: should SoundCacheStream open the soundfile on its own?
delete _cache;
if( sf ) sf_close( sf );
sf = new_sf;
sfInfo = new_info;
_beg = _rangeBeg = beg;
_dur = _rangeDur = dur;
_rangeEnd = _rangeBeg + _rangeDur;
updateFPP();
_cache = new SoundCacheStream();
connect( _cache, SIGNAL(loadProgress(int)),
this, SIGNAL(loadProgress(int)) );
connect( _cache, SIGNAL(loadProgress(int)),
this, SLOT(update()) );
connect( _cache, SIGNAL(loadingDone()), this, SIGNAL(loadingDone()) );
connect( _cache, SIGNAL(loadingDone()), this, SLOT(redraw()) );
_cache->load( sf, sfInfo, beg, dur, kMaxFramesPerCacheUnit, kMaxRawFrames );
redraw();
}
示例12: World_GetNRTBuf
bool BufWriteCmd::Stage2()
{
#ifdef NO_LIBSNDFILE
return false;
#else
SndBuf *buf = World_GetNRTBuf(mWorld, mBufIndex);
int framesToEnd = buf->frames - mBufOffset;
if (framesToEnd < 0) framesToEnd = 0;
mFileInfo.samplerate = (int)buf->samplerate;
mFileInfo.channels = buf->channels;
SNDFILE* sf = sf_open(mFilename, SFM_WRITE, &mFileInfo);
if (!sf) {
char str[512];
sprintf(str, "File '%s' could not be opened: %s\n", mFilename, sf_strerror(NULL));
SendFailureWithIntValue(&mReplyAddress, "/b_write", str, mBufIndex); //SendFailure(&mReplyAddress, "/b_write", str);
scprintf(str);
return false;
}
if (mNumFrames < 0 || mNumFrames > buf->frames) mNumFrames = buf->frames;
if (mNumFrames > framesToEnd) mNumFrames = framesToEnd;
sf_command(sf, SFC_SET_CLIPPING, NULL, SF_TRUE); // choose clipping rather than wraparound for integer-format files
if (mNumFrames > 0) {
sf_writef_float(sf, buf->data + (mBufOffset * buf->channels), mNumFrames);
}
if(buf->sndfile)
sf_close(buf->sndfile);
if (mLeaveFileOpen) {
buf->sndfile = sf;
} else {
sf_close(sf);
buf->sndfile = 0;
}
return true;
#endif
}
示例13: libsndfile_stream_open
int
libsndfile_stream_open(const char * filename, s_stream * stream,
s_params * params)
{
libsndfile_context *context;
FILE *dummyfile;
dummyfile = fopen(filename, "rb");
if (!dummyfile)
return 0;
else
fclose(dummyfile);
context = (libsndfile_context *) malloc(sizeof(libsndfile_context));
libsndfile_init_context(context);
context->file = sf_open (filename, SFM_READ, &context->sfinfo) ;
if (!context->file) {
libsndfile_cleanup_context(context);
free(context);
return 0;
}
sf_command (context->file, SFC_SET_NORM_DOUBLE, NULL, SF_TRUE) ;
s_stream_context_set(stream, (void *)context);
/* FIXME: SF_INFO::frames is of type sf_count_t, which is a 32bit
integer in some libsndfile version and 64bit on others (like the
Mac OS X one), so casting context->sfinfo.frames to int is not
totally correct - but necessary, since we do not have a 64bit
s_params type.
20030108 kyrah
*/
s_params_set(s_stream_params(stream),
"samplerate", S_INTEGER_PARAM_TYPE, context->sfinfo.samplerate,
"frames", S_INTEGER_PARAM_TYPE, (int) context->sfinfo.frames,
"channels", S_INTEGER_PARAM_TYPE, context->sfinfo.channels,
NULL);
return 1;
}
示例14: test
/* If byfd is true, try to open the file with sf_open_fd */
int test(const char* filename, int byfd)
{
SF_INFO info;
SNDFILE* file;
int fid, flags, st;
char buffer [2048];
st = 0;
flags = O_RDONLY;
#if (defined (WIN32) || defined (_WIN32))
flags |= O_BINARY;
#endif
info.format = 0;
if (byfd) {
fid = open(filename, flags);
if (fid < 0) {
fprintf(stderr, "%s:%s failed opening file %s\n", __FILE__, __func__, filename);
return -1;
}
file = sf_open_fd(fid, SFM_READ, &info, SF_TRUE);
} else {
file = sf_open(filename, SFM_READ, &info);
}
if (file == NULL) {
fprintf(stderr, "%s:%s failed opening file %s\n", __FILE__, __func__, filename);
sf_command (file, SFC_GET_LOG_INFO, buffer, sizeof (buffer)) ;
fprintf(stderr, "sndfile error is %s:\n", buffer);
close(fid);
exit(EXIT_FAILURE);
} else {
fprintf(stderr, "%s:%s file %s has %d frames \n", __FILE__, __func__, filename, info.frames);
}
sf_close(file);
return st;
}
示例15: AU_WaveGenVisual
/* Generate a reduced waveform for visualization purposes. */
int
AU_WaveGenVisual(AU_Wave *w, int reduce)
{
int i, j, ch;
float *pIn, *pViz;
if (reduce <= 0) {
AG_SetError("Reduction factor <= 0");
return (-1);
}
if (w->vizFrames != NULL) {
Free(w->vizFrames);
w->nVizFrames = 0;
}
sf_command(w->file, SFC_CALC_SIGNAL_MAX, &w->peak, sizeof(w->peak));
w->nVizFrames = w->nFrames/reduce;
if ((w->vizFrames = AG_TryMalloc(w->nVizFrames*sizeof(float))) == NULL) {
w->nVizFrames = 0;
return (-1);
}
pViz = &w->vizFrames[0];
for (i = 0; i < w->nVizFrames; i++) {
for (ch = 0; ch < w->ch; ch++)
*pViz++ = 0.0;
}
pIn = &w->frames[0];
pViz = &w->vizFrames[0];
for (i = 0; i < w->nVizFrames; i++) {
for (j = 0; j < reduce; j++) {
for (ch = 0; ch < w->ch; ch++) {
pViz[ch] += MAX(w->vizFrames[i],
fabs((*pIn++)/w->peak));
}
}
for (ch = 0; ch < w->ch; ch++)
*pViz++ /= reduce;
}
return (0);
}