当前位置: 首页>>代码示例>>C++>>正文


C++ sf_read_float函数代码示例

本文整理汇总了C++中sf_read_float函数的典型用法代码示例。如果您正苦于以下问题:C++ sf_read_float函数的具体用法?C++ sf_read_float怎么用?C++ sf_read_float使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了sf_read_float函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的sf_read_float函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。