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


C++ sf_read_short函数代码示例

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


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

示例1: buffer_load

void
buffer_load(char* filename, ALint* buffer)
{
    SF_INFO file_infos;
    SNDFILE* file = sf_open(filename, SFM_READ, &file_infos);

    if(!file)
        printf("Unable to load the soundfile %s ! Ensure to be in the same directory as the ttymetronome binary.\n", filename);

    ALsizei sample_number = (ALsizei)(file_infos.channels * file_infos.frames);
    ALsizei samplerate = (ALsizei)(file_infos.samplerate);
    ALshort samples[sample_number];
    sf_read_short(file,samples,sample_number);

    sf_close(file);

    ALenum type;
    switch(file_infos.channels)
    {
        case 1:    type = AL_FORMAT_MONO16;    break;
        case 2:    type = AL_FORMAT_STEREO16;    break;
    }

    alGenBuffers(1,buffer);

    alBufferData(*buffer,type,samples,sample_number * sizeof(ALushort), samplerate);

    if(alGetError())
        printf("Internal OpenAL error !\n");
    
    return;
}
开发者ID:Cheaterman,项目名称:ttymetronome,代码行数:32,代码来源:sound_management.c

示例2: file

bool ALAudio::load_sndfile(std::string const& filename, EASYRPG_SHARED_PTR<buffer> const& buf) {
	SF_INFO info;
	EASYRPG_SHARED_PTR<SNDFILE> file(sf_open(filename.c_str(), SFM_READ, &info), sf_close);
	if(! file) { return false; }

	// load data
	std::vector<int16_t> data;
	EASYRPG_ARRAY<int16_t, 4096> read_buf;
	size_t read_size = 0;
	while((read_size = sf_read_short(file.get(), read_buf.data(), read_buf.size())) != 0) {
		data.insert(data.end(), read_buf.begin(), read_buf.begin() + read_size);
	}

	// channel check
	ALsizei const channels =
		(info.channels == 1)? AL_FORMAT_MONO16:
		(info.channels == 2)? AL_FORMAT_STEREO16:
		AL_INVALID_VALUE;
	if(channels == AL_INVALID_VALUE) { return false; }

	alBufferData(buf->get(), channels, &data.front(),
				 data.size() * sizeof(int16_t), info.samplerate);

	return true;
}
开发者ID:ChrisOelmueller,项目名称:Player,代码行数:25,代码来源:al_audio.cpp

示例3: Read

////////////////////////////////////////////////////////////
/// Read samples from the loaded sound
////////////////////////////////////////////////////////////
std::size_t SoundFileDefault::Read(Int16* Data, std::size_t NbSamples)
{
    if (myFile && Data && NbSamples)
        return static_cast<std::size_t>(sf_read_short(myFile, Data, NbSamples));
    else
        return 0;
}
开发者ID:AwkwardDev,项目名称:MangosFX,代码行数:10,代码来源:SoundFileDefault.cpp

示例4: opensoundsys_play

static void
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 ;
} /* opensoundsys_play */
开发者ID:ChristianFrisson,项目名称:JamomaCore,代码行数:60,代码来源:sndfile-play.c

示例5: win32_play_data

static void
win32_play_data (Win32_Audio_Data *audio_data)
{	int thisread, readcount ;

	/* fill a buffer if there is more data and we can read it sucessfully */
	readcount = (audio_data->remaining > audio_data->bufferlen) ? audio_data->bufferlen : (int) audio_data->remaining ;

	thisread = (int) sf_read_short (audio_data->sndfile, (short *) (audio_data->whdr [audio_data->current].lpData), readcount) ;

	audio_data->remaining -= thisread ;

	if (thisread > 0)
	{	/* Fix buffer length if this is only a partial block. */
		if (thisread < audio_data->bufferlen)
			audio_data->whdr [audio_data->current].dwBufferLength = thisread * sizeof (short) ;

		/* Queue the WAVEHDR */
		waveOutWrite (audio_data->hwave, (LPWAVEHDR) &(audio_data->whdr [audio_data->current]), sizeof (WAVEHDR)) ;

		/* count another buffer in use */
		EnterCriticalSection (&audio_data->mutex) ;
		audio_data->BuffersInUse ++ ;
		LeaveCriticalSection (&audio_data->mutex) ;

		/* use the other buffer next time */
		audio_data->current = (audio_data->current + 1) % 2 ;
		} ;

	return ;
} /* win32_play_data */
开发者ID:ChristianFrisson,项目名称:JamomaCore,代码行数:30,代码来源:sndfile-play.c

示例6: main

int		main (int argc, char *argv[])
{   SNDFILE	*file ;
    SF_INFO sfinfo ;
    int		k, count, max = 0, total = 0 ;

    if (argc < 2)
    {   printf ("Expecting input file name.\n") ;
        return 0 ;
    } ;

    if (! (file = sf_open_read (argv [1], &sfinfo)))
    {   printf ("sf_open_read failed with error : ") ;
        sf_perror (NULL) ;
        exit (1) ;
    } ;

    while ((count = sf_read_short (file, buffer, BUFFER_SIZE)))
    {   for (k = 0 ; k < count ; k++)
            if (abs (buffer [k]) > max)
                max = abs (buffer [k]) ;
        total += count ;
    } ;

    printf ("Total         : %d\n", total) ;
    printf ("Maximun value : %d\n", max) ;

    sf_close (file) ;

    return 0 ;
} /* main */
开发者ID:ruthmagnus,项目名称:audacity,代码行数:30,代码来源:sftest.c

示例7: 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 = sf_read_short(file, (short*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
			break;
		case obj_int32 :
			slotRawObject(b)->size = sf_read_int(file, (int*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
			break;
		case obj_float :
			slotRawObject(b)->size = sf_read_float(file, (float*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
			break;
		case obj_double :
			slotRawObject(b)->size = sf_read_double(file, (double*)slotRawInt8Array(b)->b, slotRawObject(b)->size);
			break;
		default:
			error("sample format not supported.\n");
			return errFailed;
	}

	return errNone;
}
开发者ID:beangoben,项目名称:supercollider,代码行数:31,代码来源:PyrFilePrim.cpp

示例8: ASSERT

int CWAV::ReadDataChunk(BYTE* pBuf, DWORD dwNumBytes)
{
	ASSERT(m_pSndFile);
	return (int)sf_read_short(	m_pSndFile,
							(PSHORT)pBuf,
							dwNumBytes / sizeof( SHORT ) ) * sizeof( SHORT );
}
开发者ID:joshlong,项目名称:libcd,代码行数:7,代码来源:AudioFile.cpp

示例9: win32_play_data

static void
win32_play_data (Win32_Audio_Data *audio_data)
{	int thisread, readcount ;
		
	readcount = (audio_data->remaining > audio_data->bufferlen) ? audio_data->bufferlen : (int) audio_data->remaining ;

	thisread = (int) sf_read_short (audio_data->sndfile, (short *) (audio_data->whdr [audio_data->current].lpData), readcount) ;

	audio_data->remaining -= thisread ;

	if (thisread > 0)
	{	/* Fix buffer length is only a partial block. */
		if (thisread * sizeof (short) < audio_data->bufferlen)
			audio_data->whdr [audio_data->current].dwBufferLength = thisread * sizeof (short) ;

		/* Queue the WAVEHDR */
		waveOutWrite (audio_data->hwave, (LPWAVEHDR) &(audio_data->whdr [audio_data->current]), sizeof (WAVEHDR)) ;
		}
	else
	{	/* Stop playback */
		waveOutPause (audio_data->hwave) ;

		SetEvent (audio_data->Event) ;
		} ;

	audio_data->current = (audio_data->current + 1) % 2 ;

} /* win32_play_data */
开发者ID:Kirushanr,项目名称:audacity,代码行数:28,代码来源:sndfile-play.c

示例10: 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

示例11: 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

示例12: sf_open

ALuint Lecture::LoadSound(const std::string& Filename)
{
    // Ouverture du fichier audio avec libsndfile
        SF_INFO FileInfos;
        SNDFILE* File = sf_open(Filename.c_str(), SFM_READ, &FileInfos);
        if (!File)
        {
            qDebug() << "Impossible d'ouvrir le fichier audio";
            return 0;
        }

        // Lecture du nombre d'échantillons et du taux d'échantillonnage (nombre d'échantillons à lire par seconde)
        ALsizei NbSamples  = static_cast<ALsizei>(FileInfos.channels * FileInfos.frames);
        ALsizei SampleRate = static_cast<ALsizei>(FileInfos.samplerate);



        // Lecture des échantillons audio au format entier 16 bits signé (le plus commun)
        std::vector<ALshort> Samples(NbSamples);
        if (sf_read_short(File, &Samples[0], NbSamples) < NbSamples)
        {
            qDebug() << "Impossible de lire les échantillons stockés dans le fichier audio";
            return 0;
        }

        // Fermeture du fichier
        sf_close(File);

        // Détermination du format en fonction du nombre de canaux
        ALenum Format;
        switch (FileInfos.channels)
        {
            case 1 : Format = AL_FORMAT_MONO16;   break;
            case 2 : Format = AL_FORMAT_STEREO16; break;
            default :
                qDebug() << "Format audio non supporté (plus de 2 canaux)";
                return 0;
        }

        // Création du tampon OpenAL
        ALuint Buffer;
        alGenBuffers(1, &Buffer);

        // Remplissage avec les échantillons lus
        alBufferData(Buffer, Format, &Samples[0], NbSamples * sizeof(ALushort), SampleRate);

        // Vérification des erreurs
        if (alGetError() != AL_NO_ERROR)
        {
            qDebug() << "Impossible de remplir le tampon OpenAL avec les échantillons du fichier audio" ;
            return 0;
        }

        return Buffer;
}
开发者ID:mamelon,项目名称:GuitareTools,代码行数:55,代码来源:lecture.cpp

示例13: M_loadSound

bool M_loadSound(const char * filename, void * data)
{
	SF_VIRTUAL_IO io;
	io.get_filelen = &M_SFGetFileLen;
	io.seek = &M_SFSeek;
	io.read = &M_SFRead;
	io.write = &M_SFWrite;
	io.tell = &M_SFTell;
	
	// open file
    SF_INFO infos;
	MFile* File = M_fopen(filename, "rb");
    SNDFILE * file = sf_open_virtual(&io, SFM_READ, &infos, File);
	if(! file){
		M_fclose(File);
		printf("ERROR Load Sound : unable to read %s file\n", filename);
		return false;
	}
	
	int nbSamples  = infos.channels * (int)infos.frames;
    int sampleRate = infos.samplerate;
	
	M_SOUND_FORMAT format;
    switch(infos.channels)
    {
		case 1 :
			format = M_SOUND_FORMAT_MONO16;
			break;
		case 2 :
			format = M_SOUND_FORMAT_STEREO16;
			break;
		default :
			printf("ERROR Load Sound : non supported format\n");
			M_fclose(File);
			return false;
    }
	
	MSound * sound = (MSound *)data;
	
	unsigned int size = nbSamples*2;
	sound->create(format, size, (unsigned int)sampleRate);
	
    // 16 bits file reading
	if(sf_read_short(file, (short*)sound->getData(), nbSamples) < nbSamples)
	{
		printf("ERROR Load Sound : unable to read samples\n");
		M_fclose(File);
        return false;
	}

    sf_close(file);
	M_fclose(File);
	return true;
}
开发者ID:Keedu,项目名称:maratis,代码行数:54,代码来源:MSndFileLoader.cpp

示例14: mbrpipe_play_icon

static void mbrpipe_play_icon(char *icon)
{
#if HAVE_SNDFILE
	int subformat;
	sf_count_t items;
	sf_count_t readcount;
	SNDFILE *sf;
	SF_INFO sfinfo;
	char filename[256];
	sprintf(filename, "%s/%s",MbrpipeSoundIconFolder,icon);

	log_msg(OTTS_LOG_DEBUG, MODULE_NAME": Playing |%s|", filename);
	memset(&sfinfo, 0, sizeof(sfinfo));
	sf = sf_open(filename, SFM_READ, &sfinfo);
	if (!sf) return;
	subformat = sfinfo.format & SF_FORMAT_SUBMASK;
	items = sfinfo.channels * sfinfo.frames;
	if (sfinfo.channels < 1 || sfinfo.channels > 2) {
		log_msg(OTTS_LOG_ERR, MODULE_NAME": channels = %d.\n",
		        sfinfo.channels);
		goto cleanup1;
	}
	if (sfinfo.frames > 0x7FFFFFFF) {
		log_msg(OTTS_LOG_ERR, MODULE_NAME": Unknown number of frames.");
		goto cleanup1;
	}
	if (subformat == SF_FORMAT_FLOAT || subformat == SF_FORMAT_DOUBLE) {
		/* Set scaling for float to integer conversion. */
		sf_command(sf, SFC_SET_SCALE_FLOAT_INT_READ, NULL, SF_TRUE);
	}
	AudioTrack track;
	track.num_samples = sfinfo.frames;
	track.num_channels = sfinfo.channels;
	track.sample_rate = sfinfo.samplerate;
	track.bits = 16;
	track.samples = g_malloc(items * sizeof(short));
	readcount = sf_read_short(sf, (short *)track.samples, items);

	if (readcount > 0) {
		track.num_samples = readcount / sfinfo.channels;
		opentts_audio_set_volume(module_audio_id, mbrpipe_volume);
		int ret = opentts_audio_play(module_audio_id, track, SPD_AUDIO_LE);
		if (ret < 0) {
			log_msg(OTTS_LOG_ERR, MODULE_NAME
			        ": Can't play track for unknown reason.");
			goto cleanup2;
		}
	}
cleanup2:
	g_free(track.samples);
cleanup1:
	sf_close(sf);
#endif
}
开发者ID:razr,项目名称:opentts,代码行数:54,代码来源:mbrpipe.c

示例15: sf_read_short

// --- Read ---
MediumFrame* SndFileHandler::m_read()
{
	current_ts += step;

	f->len	= sf_read_short(s_file, f->samples, AUDIO_BUFFER_SIZE * file_info.channels);
	f->ts	= current_ts;

	if (f->len == 0)
		return NULL;

	return f;
}
开发者ID:eroux,项目名称:transcriber-ag,代码行数:13,代码来源:SndFileHandler.cpp


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