本文整理汇总了C++中sf_read_float函数的典型用法代码示例。如果您正苦于以下问题:C++ sf_read_float函数的具体用法?C++ sf_read_float怎么用?C++ sf_read_float使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了sf_read_float函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: alsa_play
static void
alsa_play (int argc, char *argv [])
{ static float buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
snd_pcm_t * alsa_dev ;
int k, readcount, subformat ;
for (k = 1 ; k < argc ; k++)
{ memset (&sfinfo, 0, sizeof (sfinfo)) ;
printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
if ((alsa_dev = alsa_open (sfinfo.channels, (unsigned) sfinfo.samplerate, SF_FALSE)) == NULL)
continue ;
subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)
{ double scale ;
int m ;
sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
while ((readcount = sf_read_float (sndfile, buffer, BUFFER_LEN)))
{ for (m = 0 ; m < readcount ; m++)
buffer [m] *= scale ;
alsa_write_float (alsa_dev, buffer, BUFFER_LEN / sfinfo.channels, sfinfo.channels) ;
} ;
}
else
{ while ((readcount = sf_read_float (sndfile, buffer, BUFFER_LEN)))
alsa_write_float (alsa_dev, buffer, BUFFER_LEN / sfinfo.channels, sfinfo.channels) ;
} ;
snd_pcm_drain (alsa_dev) ;
snd_pcm_close (alsa_dev) ;
sf_close (sndfile) ;
} ;
return ;
} /* alsa_play */
开发者ID:5in4,项目名称:libsox.dll,代码行数:56,代码来源:sndfile-play.c
示例2: sf_read_float
void IQFileAudioSource::getSamples(Ipp32f* samples_buf)
{
int len = sf_read_float(_f, samples_buf, 2*_nsamples);
if(len == 0)
{
sf_seek(_f, 0, SEEK_SET);
len = sf_read_float(_f, samples_buf, _nsamples);
if(!_loop)
_done = true;
}
usleep(_block_delay);
}
开发者ID:hrafnkelle,项目名称:tfsdr,代码行数:12,代码来源:IQFileAudioSource.cpp
示例3: get_samples_from_file
std::vector<fpoint> get_samples_from_file(std::string filename)
{
const int BUFFER_LEN = 1024;
static float data[BUFFER_LEN];
std::vector<fpoint> out;
SNDFILE *infile;
SF_INFO sfinfo;
sfinfo.channels = 1;
sfinfo.samplerate = Fs;
sfinfo.format = SF_FORMAT_WAV | SF_FORMAT_FLOAT;
int readcount;
filename.insert(0, "samples/");
filename.append(".wav");
if (! (infile = sf_open(filename.c_str(), SFM_READ, &sfinfo)))
{
std::cout << "no file named " << filename << std::endl;
return out;
}
while ((readcount = sf_read_float(infile, data, BUFFER_LEN)))
{
for(int i = 0; i < readcount; ++i)
{
out.push_back(data[i]);
}
}
sf_close (infile);
return out;
}
开发者ID:mujjingun,项目名称:KoreanTTS,代码行数:35,代码来源:soundio.cpp
示例4: macosx_audio_out_callback
static OSStatus
macosx_audio_out_callback (AudioDeviceID device, const AudioTimeStamp* current_time,
const AudioBufferList* data_in, const AudioTimeStamp* time_in,
AudioBufferList* data_out, const AudioTimeStamp* time_out,
void* client_data)
{ MacOSXAudioData *audio_data ;
int k, size, sample_count, read_count ;
float *buffer, rate = 44100 ;
audio_data = (MacOSXAudioData*) client_data ;
size = data_out->mBuffers[0].mDataByteSize ;
sample_count = size / sizeof(float) ;
buffer = (float*) data_out->mBuffers [0].mData ;
read_count = sf_read_float (audio_data->sndfile, buffer, sample_count) ;
if (read_count < sample_count)
{ memset (&(buffer [read_count]), 0, (sample_count - read_count) * sizeof (float)) ;
/* Tell the main application to terminate. */
audio_data->done_playing = SF_TRUE ;
} ;
return noErr ;
} /* macosx_audio_out_callback */
开发者ID:Kirushanr,项目名称:audacity,代码行数:26,代码来源:sndfile-play.c
示例5: sf_open
//------------------------------------------------------------
bool ofOpenALSoundPlayer::sfStream(string path,vector<short> & buffer,vector<float> & fftAuxBuffer){
if(!streamf){
SF_INFO sfInfo;
streamf = sf_open(path.c_str(),SFM_READ,&sfInfo);
if(!streamf){
ofLogError("ofOpenALSoundPlayer") << "sfStream(): couldn't read \"" << path << "\"";
return false;
}
stream_subformat = sfInfo.format & SF_FORMAT_SUBMASK ;
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_command (streamf, SFC_CALC_SIGNAL_MAX, &stream_scale, sizeof (stream_scale)) ;
if (stream_scale < 1e-10)
stream_scale = 1.0 ;
else
stream_scale = 32700.0 / stream_scale ;
}
channels = sfInfo.channels;
duration = float(sfInfo.frames) / float(sfInfo.samplerate);
samplerate = sfInfo.samplerate;
stream_samples_read = 0;
}
int curr_buffer_size = BUFFER_STREAM_SIZE*channels;
if(speed>1) curr_buffer_size *= (int)round(speed);
buffer.resize(curr_buffer_size);
fftAuxBuffer.resize(buffer.size());
if (stream_subformat == SF_FORMAT_FLOAT || stream_subformat == SF_FORMAT_DOUBLE){
sf_count_t samples_read = sf_read_float (streamf, &fftAuxBuffer[0], fftAuxBuffer.size());
stream_samples_read += samples_read;
if(samples_read<(int)fftAuxBuffer.size()){
fftAuxBuffer.resize(samples_read);
buffer.resize(samples_read);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for (int i = 0 ; i < int(fftAuxBuffer.size()) ; i++){
fftAuxBuffer[i] *= stream_scale ;
buffer[i] = 32565.0 * fftAuxBuffer[i];
}
}else{
sf_count_t frames_read = sf_readf_short(streamf,&buffer[0],curr_buffer_size/channels);
stream_samples_read += frames_read*channels;
if(frames_read<curr_buffer_size/channels){
fftAuxBuffer.resize(frames_read*channels);
buffer.resize(frames_read*channels);
setPosition(0);
if(!bLoop) stopThread();
stream_samples_read = 0;
stream_end = true;
}
for(int i=0;i<(int)buffer.size();i++){
fftAuxBuffer[i]=float(buffer[i])/32565.0f;
}
}
return true;
}
开发者ID:AnnaKolla,项目名称:openFrameworks,代码行数:61,代码来源:ofOpenALSoundPlayer.cpp
示例6: sf_open
//-----------------------------------------------------------------------------
// name: int ReadSoundFile( char filename[], TS_FLOAT * data, int datasize )
// desc: Reads given sound file into data array
//-----------------------------------------------------------------------------
int TreesynthIO::ReadSoundFile( char filename[], TS_FLOAT * data, int datasize )
{
if( !sfread ) {
sfread = sf_open( filename, SFM_READ, &info );
if( !sfread )
{
std::cerr << "TreesynthIO::ReadSoundFile : cannot open file '" << filename << "', quitting" << std::endl;
char x[256];
std::cin.getline( x, 256 );
exit(1);
}
}
datasize = rm_next_length;
sf_seek( sfread, rm_next_pos, SEEK_SET );
std::cerr << sfread << " " << data << " " << datasize << std::endl;
int itemsread = sf_read_float( sfread, data, datasize );
set_next_pos( filename );
// rt audio
/*if( !audio_initialize( info.samplerate ) ) { // 44100
std::cerr << "TreesynthIO::ReadSoundFile : cannot open audio interface, quitting" << std::endl;
char x[256];
std::cin.getline( x, 256 );
exit(1);
}*/
return itemsread;
}
开发者ID:alltom,项目名称:taps,代码行数:32,代码来源:Eliot.cpp
示例7: reverse_audio_file
void reverse_audio_file(char* filepath, char* fileOutputPath){
SF_INFO info;
SNDFILE *input, *output;
float *samples;
int len, i;
/* open input file */
input = sf_open(filepath, SFM_READ, &info);
/* allocate buffer */
len = info.frames;
samples = malloc(sizeof(float) * len);
/* read in input file */
sf_read_float(input, samples, len);
/* close the input file */
sf_close(input);
/* open output file */
output = sf_open(fileOutputPath, SFM_WRITE, &info);
/* write samples in reverse order to output file */
for (i=len-1; i>=0; i--)
{
sf_write_float(output, &samples[i], 1);
}
/* close output file */
sf_close(output);
/* deallocate buffer */
free(samples);
}
开发者ID:Alt-G,项目名称:AudioProgTest,代码行数:35,代码来源:Functions.c
示例8: sf_read_float
long int lp_sndfile_in::read_frames(float *buffer, long int len)
{
pv_sf_len = (sf_count_t)len;
pv_sf_len = sf_read_float(pv_snd_fd, buffer, pv_sf_len);
pv_sf_pos = pv_sf_pos + pv_sf_len;
return (long int)pv_sf_len;
}
开发者ID:BackupTheBerlios,项目名称:liveplayer0-svn,代码行数:7,代码来源:lp_sndfile_in.cpp
示例9: readsoundfilechunk
soundfile * readsoundfilechunk(char *path, int start, int len) {
soundfile * ret;
SF_INFO info;
SNDFILE *snd;
memset(&info, 0, sizeof(info));
if ( (snd = sf_open(path, SFM_READ, &info)) == NULL )
diem("Couldn't open sound file for reading", path);
if ( info.channels != 1 )
diem("Sound file has more than one channel", path);
if ( (ret = malloc(sizeof(*ret))) == NULL )
die("Couldn't malloc space for soundfile");
if ( (ret->data = malloc(sizeof(float)*len)) == NULL )
die("Couldn't malloc space for sound buffer");
sf_seek(snd, start, SEEK_SET);
int actuallen = sf_read_float(snd, ret->data, len); // assumption: channel count is 1, verified above
ret->length = actuallen;
ret->samplerate = info.samplerate;
if ( sf_close(snd) )
diem("Couldn't close sound file", path);
return ret;
}
开发者ID:encryptio,项目名称:convolute,代码行数:30,代码来源:readsoundfile.c
示例10: sf_close
int OlaRandom::ReadSoundFile( char filename[] )
{
// open file
if( sfread )
{
sf_close( sfread );
}
sfread = sf_open( filename, SFM_READ, &readinfo );
if( !sfread )
{
BB_log( BB_LOG_SEVERE, "[TreesynthIO]: Could not open input file '%s', %s",
filename, sf_error_number( sf_error( sfread ) ) );
return 0;
}
strcpy( ifilename, filename );
// determine number of buffers needed
origsize = readinfo.frames;
std::cerr << "frames: " << origsize << std::endl;
SAFE_DELETE_ARRAY(origbuffer);
origbuffer = new float[origsize];
// read
sf_seek( sfread, 0, SEEK_SET );
int itemsread = sf_read_float( sfread, origbuffer, origsize);
sf_close( sfread );
sfread = NULL;
return itemsread;
}
开发者ID:alltom,项目名称:taps,代码行数:30,代码来源:Ola.cpp
示例11: prSFRead
int prSFRead(struct VMGlobals *g, int numArgsPushed)
{
PyrSlot *a, *b;
a = g->sp - 1;
b = g->sp;
SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]);
if (!isKindOfSlot(b, class_rawarray)) return errWrongType;
switch (slotRawObject(b)->obj_format) {
case obj_int16 :
slotRawObject(b)->size = (int)sf_read_short(file, (short*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
break;
case obj_int32 :
slotRawObject(b)->size = (int)sf_read_int(file, (int*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
break;
case obj_float :
slotRawObject(b)->size = (int)sf_read_float(file, (float*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
break;
case obj_double :
slotRawObject(b)->size = (int)sf_read_double(file, (double*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
break;
default:
error("sample format not supported.\n");
return errFailed;
}
return errNone;
}
开发者ID:dpalkowski,项目名称:iSuperColliderKit,代码行数:31,代码来源:PyrFilePrim.cpp
示例12: opensoundsys_play
static int
opensoundsys_play (int argc, char *argv [])
{ static short buffer [BUFFER_LEN] ;
SNDFILE *sndfile ;
SF_INFO sfinfo ;
int k, audio_device, readcount, writecount, subformat ;
for (k = 1 ; k < argc ; k++)
{ memset (&sfinfo, 0, sizeof (sfinfo)) ;
printf ("Playing %s\n", argv [k]) ;
if (! (sndfile = sf_open (argv [k], SFM_READ, &sfinfo)))
{ puts (sf_strerror (NULL)) ;
continue ;
} ;
if (sfinfo.channels < 1 || sfinfo.channels > 2)
{ printf ("Error : channels = %d.\n", sfinfo.channels) ;
continue ;
} ;
audio_device = opensoundsys_open_device (sfinfo.channels, sfinfo.samplerate) ;
subformat = sfinfo.format & SF_FORMAT_SUBMASK ;
if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE)
{ static float float_buffer [BUFFER_LEN] ;
double scale ;
int m ;
sf_command (sndfile, SFC_CALC_SIGNAL_MAX, &scale, sizeof (scale)) ;
if (scale < 1e-10)
scale = 1.0 ;
else
scale = 32700.0 / scale ;
while ((readcount = sf_read_float (sndfile, float_buffer, BUFFER_LEN)))
{ for (m = 0 ; m < readcount ; m++)
buffer [m] = scale * float_buffer [m] ;
writecount = write (audio_device, buffer, readcount * sizeof (short)) ;
} ;
}
else
{ while ((readcount = sf_read_short (sndfile, buffer, BUFFER_LEN)))
writecount = write (audio_device, buffer, readcount * sizeof (short)) ;
} ;
if (ioctl (audio_device, SNDCTL_DSP_POST, 0) == -1)
perror ("ioctl (SNDCTL_DSP_POST) ") ;
if (ioctl (audio_device, SNDCTL_DSP_SYNC, 0) == -1)
perror ("ioctl (SNDCTL_DSP_SYNC) ") ;
close (audio_device) ;
sf_close (sndfile) ;
} ;
return writecount ;
} /* opensoundsys_play */
开发者ID:5in4,项目名称:libsox.dll,代码行数:60,代码来源:sndfile-play.c
示例13: sf_read_float
f_cnt_t SampleBuffer::decodeSampleSF( const char * _f,
int_sample_t * & _buf,
ch_cnt_t & _channels,
sample_rate_t & _samplerate )
{
SNDFILE * snd_file;
SF_INFO sf_info;
f_cnt_t frames = 0;
bool sf_rr = false;
sample_t * fbuf = 0;
if( ( snd_file = sf_open( _f, SFM_READ, &sf_info ) ) != NULL )
{
frames = sf_info.frames;
// check if float
if ( (sf_info.format & SF_FORMAT_SUBMASK) == SF_FORMAT_FLOAT ) // if yes, use float format for buffer
{
fbuf = new sample_t[sf_info.channels * frames];
sf_rr = sf_read_float( snd_file, fbuf, sf_info.channels * frames );
}
else // otherwise, use int
{
_buf = new int_sample_t[sf_info.channels * frames];
sf_rr = sf_read_short( snd_file, _buf, sf_info.channels * frames );
}
if( sf_rr < sf_info.channels * frames )
{
#ifdef DEBUG_LMMS
printf( "SampleBuffer::decodeSampleSF(): could not read"
" sample %s: %s\n", _f, sf_strerror( NULL ) );
#endif
}
_channels = sf_info.channels;
_samplerate = sf_info.samplerate;
sf_close( snd_file );
}
else
{
#ifdef DEBUG_LMMS
printf( "SampleBuffer::decodeSampleSF(): could not load "
"sample %s: %s\n", _f, sf_strerror( NULL ) );
#endif
}
//write down either directly or convert i->f depending on file type
if ( frames > 0 && fbuf != NULL )
{
directFloatWrite ( fbuf, frames, _channels);
}
else if ( frames > 0 && _buf != NULL )
{
convertIntToFloat ( _buf, frames, _channels);
}
return frames;
}
开发者ID:AHudon,项目名称:SOEN6471_LMMS,代码行数:59,代码来源:SampleBuffer.cpp
示例14: xsf_read_float
sf_count_t xsf_read_float(SNDFILE *sndfile, float *ptr, sf_count_t items)
{
sf_count_t err = sf_read_float(sndfile, ptr, items);
if(err < 0) {
xsf_handle_error(sndfile);
}
return err;
}
开发者ID:nihlaeth,项目名称:read-the-room,代码行数:8,代码来源:sound-file.c
示例15: macosx_audio_out_callback
static OSStatus
macosx_audio_out_callback (AudioDeviceID device, const AudioTimeStamp* current_time,
const AudioBufferList* data_in, const AudioTimeStamp* time_in,
AudioBufferList* data_out, const AudioTimeStamp* time_out,
void* client_data)
{ MacOSXAudioData *audio_data ;
int size, sample_count, read_count, k ;
float *buffer ;
/* Prevent compiler warnings. */
device = device ;
current_time = current_time ;
data_in = data_in ;
time_in = time_in ;
time_out = time_out ;
audio_data = (MacOSXAudioData*) client_data ;
size = data_out->mBuffers [0].mDataByteSize ;
sample_count = size / sizeof (float) ;
buffer = (float*) data_out->mBuffers [0].mData ;
if (audio_data->fake_stereo != 0)
{ read_count = sf_read_float (audio_data->sndfile, buffer, sample_count / 2) ;
for (k = read_count - 1 ; k >= 0 ; k--)
{ buffer [2 * k ] = buffer [k] ;
buffer [2 * k + 1] = buffer [k] ;
} ;
read_count *= 2 ;
}
else
read_count = sf_read_float (audio_data->sndfile, buffer, sample_count) ;
/* Fill the remainder with zeroes. */
if (read_count < sample_count)
{ if (audio_data->fake_stereo == 0)
memset (&(buffer [read_count]), 0, (sample_count - read_count) * sizeof (float)) ;
/* Tell the main application to terminate. */
audio_data->done_playing = SF_TRUE ;
} ;
return noErr ;
} /* macosx_audio_out_callback */
开发者ID:5in4,项目名称:libsox.dll,代码行数:45,代码来源:sndfile-play.c
示例16: SoundCtor
// TODO: Add streaming support.
bool SoundCtor(JSContext *ctx, unsigned argc, JS::Value *vp){
JS::CallArgs args = CallArgsFromVp(argc, vp);
if(!Turbo::CheckForSingleArg(ctx, args, Turbo::String, __func__))
return false;
struct Turbo::JSStringHolder<> file(ctx, JS_EncodeString(ctx, args[0].toString()));
const std::string full_path = std::string(TS_GetContextEnvironment(ctx)->directories->sound) + file.string;
if(!t5::IsFile(full_path)){
Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error no such file ") + file.string);
return false;
}
SF_INFO info;
SNDFILE *sound_file = sf_open(full_path.c_str(), SFM_READ, &info);
//sf_command(sound_file, SFC_SET_SCALE_FLOAT_INT_READ, nullptr, SF_TRUE);
if(!sound_file){
Turbo::SetError(ctx, std::string(BRACKNAME " SoundCtor Error could not open file ") + file.string);
return false;
}
int iters = 0;
Sound *sound = nullptr;
if(player.supportsFloat32()){
float buffer[0x8000];
sound = new Sound(player.load((float *)nullptr, 0, info.channels, info.samplerate, info.frames));
while(unsigned long this_read = sf_read_float(sound_file, buffer, 0x10000)){
player.addToSound(sound, buffer, SamplesToBytes(this_read));
iters++;
}
}
else if(player.supportsInt16()){
short buffer[0x10000];
sound = new Sound(player.load((short *)nullptr, 0, info.channels, info.samplerate, info.frames));
while(unsigned long this_read = sf_read_short(sound_file, buffer, 0x10000)){
player.addToSound(sound, buffer, SamplesToBytes(this_read));
iters++;
}
}
else{
puts(BRACKNAME " Error bad player on this platform");
}
printf(BRACKNAME " SoundCtor Info loaded file %s in %i iterations\n", file.string, iters);
sf_close(sound_file);
args.rval().set(OBJECT_TO_JSVAL(sound_proto.wrap(ctx, sound)));
return true;
}
开发者ID:FlyingJester,项目名称:TurboSphere,代码行数:58,代码来源:script.cpp
示例17: lsamp_add_file
void lsamp_add_file(lsamp_data *ls, const char *filename, const char *keyword) {
sqlite3_stmt *pStmt;
int rc;
int rowid;
int count;
int bufsize = LSBUFSIZE;
int blob_offset = 0;
if(!lsamp_open_sfile(ls, filename)) {
return;
}
rc = sqlite3_prepare_v2(ls->db,
"INSERT INTO lsamp(keyword, data) VALUES(?,ZEROBLOB(?));",
-1,
&pStmt,
NULL);
if(rc) {
fprintf(stderr, "SQL Error: %s\n", sqlite3_errmsg(ls->db));
return;
}
sqlite3_bind_text(pStmt, 1, keyword, -1, SQLITE_STATIC);
sqlite3_bind_int(pStmt, 2, ls->sfinfo.frames * sizeof(LSFLOAT));
rc = sqlite3_step(pStmt);
rc = sqlite3_finalize(pStmt);
sqlite3_blob *pBlob;
rc = sqlite3_blob_open(ls->db, "main", "lsamp", "data",
sqlite3_last_insert_rowid(ls->db), 1, &pBlob);
if(rc) {
fprintf(stderr, "Error opening blob: %s\n", sqlite3_errmsg(ls->db));
return;
}
count = ls->sfinfo.frames;
while(count != 0) {
#ifdef LS_DEBUG
fprintf(stderr, "Reading buffersize %d.\n", bufsize);
fflush(stderr);
#endif
bufsize = sf_read_float(ls->sfile, ls->buf, bufsize);
rc = sqlite3_blob_write(pBlob, ls->buf,
bufsize * sizeof(LSFLOAT), blob_offset * sizeof(LSFLOAT));
#ifdef LS_DEBUG
fprintf(stderr, "%d bytes Written. Writing %d bytes.\n",
blob_offset, bufsize);
fflush(stderr);
#endif
if(rc) {
fprintf(stderr, "SQL Error: %s\n", sqlite3_errmsg(ls->db));
return;
}
blob_offset += bufsize;
count -= bufsize;
}
lsamp_close_sfile(ls);
sqlite3_blob_close(pBlob);
}
开发者ID:PaulBatchelor,项目名称:lsamp,代码行数:57,代码来源:lsamp.c
示例18: play_file
static void play_file (const char *filename) {
SNDFILE *sndFile;
SF_INFO sfInfo;
sf_count_t count;
PaError error;
PaStreamParameters outputParameters;
PaStream *stream;
// open file
if (! (sndFile = sf_open(filename, SFM_READ, &sfInfo))) {
printf("Error: could not open file: %s\n", filename);
}
// initialize portaudio
Pa_Initialize();
outputParameters.device = Pa_GetDefaultOutputDevice();
outputParameters.channelCount = sfInfo.channels;
outputParameters.sampleFormat = paFloat32;
outputParameters.suggestedLatency = 0.2;
outputParameters.hostApiSpecificStreamInfo = 0;
error = Pa_OpenStream(
&stream,
NULL,
&outputParameters,
sfInfo.samplerate,
paFramesPerBufferUnspecified,
paNoFlag,
NULL,
NULL);
if (error) {
printf("Failed to open output, error: %i\n", error);
Pa_Terminate();
}
error = Pa_StartStream(stream);
if (error) {
printf("Failed to start stream: %i\n", error);
}
// read and play file in segments
int buffer_channel = BUFFER_LEN * sfInfo.channels;
float *buffer = malloc(buffer_channel * sizeof(float));
while ((count = sf_read_float(sndFile, buffer, buffer_channel)) > 0) {
error = Pa_WriteStream(stream, buffer, BUFFER_LEN);
}
// clean up
free(buffer);
Pa_StopStream(stream);
Pa_CloseStream(stream);
Pa_Terminate();
sf_close(sndFile);
}
开发者ID:aribold,项目名称:rpi,代码行数:57,代码来源:portaudio-example.c
示例19: __read_audio_file
CircularBuffer * __read_audio_file(AudioOptions audio_options)
{
struct stat st;
SF_INFO sf_info;
long wav_file_size;
float * buffer = NULL;
CircularBuffer * input_buffer = NULL;
SNDFILE * wav_file = NULL;
if (stat(audio_options.wav_path, &st) == 0) {
wav_file_size = st.st_size;
} else {
printf("Could not open wav file: %s\n", audio_options.wav_path);
fflush(stdout);
goto error;
}
input_buffer = CircularBuffer_create(wav_file_size);
printf("Opening wave file %s with size %ld\n", audio_options.wav_path, wav_file_size);
if (!(wav_file = sf_open(audio_options.wav_path, SFM_READ, &sf_info))) {
printf("Could not open wav file: %s\n", audio_options.wav_path);
fflush(stdout);
goto error;
}
buffer = (float *)malloc(sizeof(float) * WAV_BUFFER_SIZE);
if (!buffer) {
sf_close(wav_file);
goto error;
}
int readcount;
while ((readcount = sf_read_float(wav_file, buffer, WAV_BUFFER_SIZE))) {
CircularBuffer_produce_blocking(input_buffer, buffer, readcount);
}
free(buffer);
sf_close(wav_file);
return input_buffer;
error:
if (buffer) {
free(buffer);
}
if (input_buffer) {
CircularBuffer_destroy(input_buffer);
}
if (wav_file) {
sf_close(wav_file);
}
return NULL;
}
开发者ID:axiak,项目名称:speakers,代码行数:56,代码来源:audio.c
示例20: BOOST_ASSERT
bool StreamTrack::stream(ALuint buffer)
{
BOOST_ASSERT(m_audioEngine->getSettings().stream_buffer_size >= m_sfInfo.channels - 1);
#ifdef AUDIO_OPENAL_FLOAT
std::vector<ALfloat> pcm(m_audioEngine->getSettings().stream_buffer_size);
#else
std::vector<ALshort> pcm(m_audioEngine->getSettings().stream_buffer_size);
#endif
size_t size = 0;
// SBS - C + 1 is important to avoid endless loops if the buffer size isn't a multiple of the channels
while(size < pcm.size() - m_sfInfo.channels + 1)
{
// we need to read a multiple of sf_info.channels here
const size_t samplesToRead = (m_audioEngine->getSettings().stream_buffer_size - size) / m_sfInfo.channels * m_sfInfo.channels;
#ifdef AUDIO_OPENAL_FLOAT
const sf_count_t samplesRead = sf_read_float(m_sndFile, pcm.data() + size, samplesToRead);
#else
const sf_count_t samplesRead = sf_read_short(m_sndFile, pcm.data() + size, samplesToRead);
#endif
if(samplesRead > 0)
{
BOOST_ASSERT(static_cast<std::make_unsigned<sf_count_t>::type>(samplesRead) <= std::numeric_limits<size_t>::max());
size += static_cast<size_t>(samplesRead);
continue;
}
int error = sf_error(m_sndFile);
if(error != SF_ERR_NO_ERROR)
{
logSndfileError(error);
return false;
}
if(m_streamType == StreamType::Background)
{
sf_seek(m_sndFile, 0, SEEK_SET);
}
else
{
break; // Stream is ending - do nothing.
}
}
if(size == 0)
return false;
alBufferData(buffer, m_format, pcm.data(), static_cast<ALsizei>(size * sizeof(pcm[0])), m_rate);
DEBUG_CHECK_AL_ERROR();
return true;
}
开发者ID:stohrendorf,项目名称:EdisonEngine,代码行数:52,代码来源:streamtrack.cpp
注:本文中的sf_read_float函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论