• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ sf_readf_float函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: wav_read_samples

int wav_read_samples(struct wav_file *wav, float *buff, int count)
{
    int samples_read, i, j;

    /* If the source is mono, then simply read directly into the output buffer */
    if(wav->file_info.channels == 1)
        return sf_readf_float(wav->file_handle, buff, count);

    /* Otherwise resize internal buffer to hold stereo samples if necessary... */
    if(wav->buff_size < count * wav->file_info.channels)
    {
        wav->buff_size = count * wav->file_info.channels;
        if( !(wav->raw_buff = realloc(wav->raw_buff, wav->buff_size * sizeof(float))))
            return -1;
    }

    /* ...and read samples for all channels interleaved, then convert to mono. */
    samples_read = sf_readf_float(wav->file_handle, wav->raw_buff, count);
    for(i = 0; i < samples_read; i++)
    {
        buff[i] = 0;
        for(j = 0; j < wav->file_info.channels; j++)
            buff[i] += wav->raw_buff[i*wav->file_info.channels+j];
        buff[i] /= wav->file_info.channels;
    }

    return samples_read;
}
开发者ID:pdkelly,项目名称:audiograph,代码行数:28,代码来源:wav.c


示例2: file_buffer_worker

void file_buffer_worker(void *ctx)
{
    AudioFile::pimpl *fileImpl = (AudioFile::pimpl *)ctx;
    int writeBuffer = (fileImpl->currentBufIndex == 0) ? 1 : 0;
    sf_seek(fileImpl->sndfile, fileImpl->framesBuffered, SF_SEEK_SET);
    size_t read = sf_readf_float(fileImpl->sndfile, fileImpl->bufs[writeBuffer], FRAMES_PER_FILE_BUFFER);
    fileImpl->framesBuffered += read;
    if (read < FRAMES_PER_FILE_BUFFER)
    {
        if (fileImpl->looping)
        {
            sf_seek(fileImpl->sndfile, 0, SF_SEEK_SET);
            size_t samplesDidRead = read * fileImpl->sfInfo.channels;
            size_t framesToRead = (FRAMES_PER_FILE_BUFFER - read);
            sf_readf_float(fileImpl->sndfile, &(fileImpl->bufs[writeBuffer][samplesDidRead]), framesToRead);
            fileImpl->framesBuffered = framesToRead;
        }
        else
        {
            fileImpl->needsBuffer = false;
        }
    }
    
    fileImpl->isBuffering = false;
}
开发者ID:lukehabermehl,项目名称:blockdsp,代码行数:25,代码来源:autil_file.cpp


示例3: sf_open

static float *load_interleaved_samples(const wchar_t *filename, SF_INFO *sf_info){
  SNDFILE *sndfile          = sf_open(STRING_get_chars(filename),SFM_READ,sf_info);
  if(sndfile==NULL)
    return NULL;

  float   *ret              = talloc_atomic(sizeof(float) * sf_info->channels * sf_info->frames);
  int      allocated_frames = sf_info->frames;

  int total_read_frames     = sf_readf_float(sndfile, ret, sf_info->frames);

  if(total_read_frames==0)
    return NULL;

  while(true){
    float samples[1024*sf_info->channels];
    int read_now = sf_readf_float(sndfile, samples, 1024);
    if(read_now==0)
      break;

    if(total_read_frames + read_now > allocated_frames){
      allocated_frames = (total_read_frames+read_now) * 2;
      ret = talloc_realloc(ret, allocated_frames * sizeof(float) * sf_info->channels);
    }

    memcpy(ret + (total_read_frames*sf_info->channels), samples, sizeof(float)*1024*sf_info->channels);

    total_read_frames += read_now;
  }

  sf_close(sndfile);

  sf_info->frames = total_read_frames;
  return ret;
}
开发者ID:renno23,项目名称:radium,代码行数:34,代码来源:Sampler_plugin.c


示例4: WARNING

/* if channels is -1, then all channels are read into buffer
 (interleaved).  buf should be big enough to hold them all */
nframes_t
Audio_File_SF::read ( sample_t *buf, int channel, nframes_t len )
{
    if ( len > 256 * 100 )
        WARNING( "warning: attempt to read an insane number of frames (%lu) from soundfile\n", (unsigned long)len );

//    printf( "len = %lu, channels = %d\n", len, _channels );

    lock();

    nframes_t rlen;

    if ( _channels == 1 || channel == -1 )
        rlen = sf_readf_float( _in, buf, len );
    else
    {
        sample_t *tmp = new sample_t[ len * _channels ];

        rlen = sf_readf_float( _in, tmp, len );

        /* extract the requested channel */
        for ( unsigned int i = channel; i < rlen * _channels; i += _channels )
            *(buf++) = tmp[ i ];

        delete[] tmp;
    }

    _current_read += rlen;

    unlock();

    return rlen;
}
开发者ID:elthariel,项目名称:non-daw,代码行数:35,代码来源:Audio_File_SF.C


示例5: assert

int SoundStream::updateState(double time, double dt){
   int status = PV_SUCCESS;
   assert(fileStream);
    
    // if (time >= nextSampleTime) {
    //     nextSampleTime += (1.0 / sampleRate);
       //Read 1 frame
       int numRead = sf_readf_float(fileStream, soundBuf, 1);
       //EOF
       if(numRead == 0){
          sf_seek(fileStream, 0, SEEK_SET);
          numRead = sf_readf_float(fileStream, soundBuf, 1);
          if(numRead == 0){
             fprintf(stderr, "SoundStream:: Fatal error, is the file empty?\n");
             exit(EXIT_FAILURE);
          }
          std::cout << "Rewinding sound file\n";
       }
       else if(numRead > 1){
          fprintf(stderr, "SoundStream:: Fatal error, numRead is bigger than 1\n");
          exit(EXIT_FAILURE);
       }
       for(int fi = 0; fi < getLayerLoc()->nf; fi++){
          soundData[fi] = soundBuf[fi];
       }
   // }
    
   return status;
}
开发者ID:PetaVision,项目名称:Projects,代码行数:29,代码来源:SoundStream.cpp


示例6: ra_sound_read_float

static void ra_sound_read_float(RA_SOUND *snd, RA_BUFFER *buf, sf_count_t frames) {
    static float temp[1024];
    int temp_len = 1024;
    float *data = (float*)buf->data;
    float mix_sum;

    // Get info struct
    SF_INFO *info;
    Data_Get_Struct(snd->info, SF_INFO, info);

    // Up/Downmix based on channel matching
    sf_count_t read = 0, r, amount;
    int i, k;
    if(buf->channels == info->channels) { // Simply read data without mix
        read = sf_readf_float(snd->snd, data, frames);
    } else if(buf->channels == 1) { // Downmix to mono
        sf_count_t max = temp_len / info->channels;
        int channels;

        while(read < frames) {
            // Calculate # of frames to read
            amount = frames - read;
            if(amount > max) amount = max;

            r = sf_readf_float(snd->snd, temp, amount);
            if(r == 0) break;

            // Mix channels together by averaging all channels and store to buffer
            for(i = 0; i < r; i++) {
                mix_sum = 0;
                for(k = 0; k < info->channels; k++) mix_sum += temp[i * info->channels + k];
                data[read] = mix_sum/info->channels;
                read++;
            }
        }
    } else if(info->channels == 1) { // Upmix from mono by copying channel
        while(read < frames) {
            // Calculate # of frames to read
            amount = frames - read;
            if(amount > temp_len) amount = temp_len;

            r = sf_readf_float(snd->snd, temp, amount);
            if(r == 0) break;

            // Write every frame channel times to the buffer
            for(i = 0; i < r; i++) {
                for(k = 0; k < buf->channels; k++) {
                    data[read * buf->channels + k] = temp[i];
                }
                read++;
            }
        }
    } else {
        rb_raise(eRubyAudioError, "unsupported mix from %d to %d", buf->channels, info->channels);
    }

    buf->real_size = read;
}
开发者ID:zmack,项目名称:ruby-audio,代码行数:58,代码来源:ra_sound.c


示例7: playbackThread

void playbackThread(PaStream* stream, char* sampleBlock, SNDFILE* filePtr, bool* stopPlaybackThread, std::mutex* stopPlaybackThread_mutex, bool* playbackThreadFinishedPlaying, std::mutex* playbackThreadFinishedPlaying_mutex){
    PaError err;
    //uses mutex to be thread safe. stopPlaybackThread could change at any time
    playbackThreadFinishedPlaying_mutex->lock();
    *playbackThreadFinishedPlaying = false;
    playbackThreadFinishedPlaying_mutex->unlock();
    stopPlaybackThread_mutex->lock();
    *stopPlaybackThread = false;
    bool stop = *stopPlaybackThread;
    stopPlaybackThread_mutex->unlock();
    long frames = FRAMES_PER_BUFFER;
    memset(sampleBlock, 0, FRAMES_PER_BUFFER*NUM_CHANNELS*SAMPLE_SIZE);
    while (!stop && frames == FRAMES_PER_BUFFER) {
        frames = sf_readf_float(filePtr, (float*)sampleBlock, FRAMES_PER_BUFFER);
        
        err = Pa_WriteStream( stream, sampleBlock, FRAMES_PER_BUFFER );
        if( err != paNoError ){
            printError("Error in worker thread:");
            printPaError(err);
        }

        stopPlaybackThread_mutex->lock();
        stop = *stopPlaybackThread;
        stopPlaybackThread_mutex->unlock();
    }
    playbackThreadFinishedPlaying_mutex->lock();
    *playbackThreadFinishedPlaying = true;
    playbackThreadFinishedPlaying_mutex->unlock();
    //printLog("* Worker ending!");
}
开发者ID:malt3,项目名称:Audiologger,代码行数:30,代码来源:Player.cpp


示例8: sf_seek

void SoundFileStream::load( SNDFILE *sf, const SF_INFO &info, sf_count_t beg, sf_count_t dur )
{
  delete[] _data;

  _dataOffset = beg;
  _dataSize = dur;

  _data = new short [_dataSize * info.channels];
  sf_seek( sf, _dataOffset, SEEK_SET);

  if (info.format & SF_FORMAT_FLOAT || info.format & SF_FORMAT_DOUBLE)
  {
    // libsndfile reading float into short is broken for non-power-of-two channel counts
    int sampleCount = _dataSize * info.channels;
    float *tmp = new float [sampleCount];
    _dataSize = sf_readf_float( sf, tmp, _dataSize );
    for (int i = 0; i < sampleCount; ++i)
        _data[i] = std::max( -1.f, std::min( 1.f, tmp[i] ) ) * std::numeric_limits<short>::max();
    delete[] tmp;
  }
  else
  {
    _dataSize = sf_readf_short( sf, _data, _dataSize );
  }

  _ch = info.channels;
  _beg = _dataOffset;
  _dur = _dataSize;
}
开发者ID:8c6794b6,项目名称:supercollider,代码行数:29,代码来源:filestream.cpp


示例9: sp_ftbl_loadfile

int sp_ftbl_loadfile(sp_data *sp, sp_ftbl **ft, const char *filename)
{
    *ft = malloc(sizeof(sp_ftbl));
    sp_ftbl *ftp = *ft;
    SF_INFO info;
    memset(&info, 0, sizeof(SF_INFO));
    info.format = 0;
    SNDFILE *snd = sf_open(filename, SFM_READ, &info);
    if(snd == NULL) {
        return SP_NOT_OK;
    }
    size_t size = info.frames * info.channels;

    ftp->tbl = malloc(sizeof(SPFLOAT) * (size + 1));

    sp_ftbl_init(sp, ftp, size);

#ifdef USE_DOUBLE
    sf_readf_double(snd, ftp->tbl, ftp->size);
#else
    sf_readf_float(snd, ftp->tbl, ftp->size);
#endif
    sf_close(snd);
    return SP_OK;
}
开发者ID:carlosypunto,项目名称:AudioKit,代码行数:25,代码来源:ftbl.c


示例10: print

/*!	Read in a soundfile.
	The Array returned is one dimensional. Multi-channel soundfiles return multi-component arrays.
	
	<luacode>
	local sf = audio.soundfile(LuaAV.findfile("gong.wav"))
	print(sf)							--> Array
	print(sf.components)				--> 2 (stereo)
	print(sf.dim[1])					--> 265776 (sample frames)
	print(sf.dim[1]/audio.samplerate)	--> 6.03 (seconds)
	</luacode>
		
	@param soundfile path (string)
	@ret Array containing the soundfile data
	@name M.read
*/
int lua_soundfile_read(lua_State * L) {
	const char * path = luaL_checkstring(L, 1);
	
	SNDFILE *sf;
	SF_INFO sfinfo;
	
	sf = sf_open(path, SFM_READ, &sfinfo);
	if (sf == NULL) luaL_error(L, "failed to open soundfile %s", path);
	
	// call Array constructor with appropriate format:
	lua_pushcfunction(L, Glue<al::ArrayWrapper>::create);
	lua_pushinteger(L, sfinfo.channels);	
	lua_pushinteger(L, AlloFloat32Ty);
	lua_createtable(L, 1, 0);
	lua_pushinteger(L, sfinfo.frames);
	lua_rawseti(L, -2, 1);
	lua_call(L, 3, 1);
	
	al::ArrayWrapper * a = Glue<al::ArrayWrapper>::checkto(L, -1);

	// copy data in:
	sf_readf_float(sf, (float *)a->data.ptr, sfinfo.frames);
	
	sf_close(sf);
	
	return 1;
}
开发者ID:LuaAV,项目名称:LuaAV,代码行数:42,代码来源:luaav_audio_soundfile.cpp


示例11: sf_open

float* Util::loadSound(const std::string& fileName, int& size)
{
	SF_INFO soundInfo;
	SNDFILE* file = sf_open(fileName.c_str(), SFM_READ, &soundInfo);

	if(!file)
	{
		printf("Failed to open sound file");
		return 0;
	}



	sf_count_t frames = soundInfo.frames * soundInfo.channels;
	size = frames;

	float* data = new float[frames];

	sf_readf_float(file, data, frames);

	/*
	for(int i = 0; i < frames; i++)
	{

	}
	*/

	sf_close(file);

	return data;
}
开发者ID:JanneRemes,项目名称:janityengine,代码行数:31,代码来源:UtilWin.cpp


示例12: sa_sndfile_read

static ssize_t
sa_sndfile_read( simpleaudio *sa, void *buf, size_t nframes )
{
    SNDFILE *s = (SNDFILE *)sa->backend_handle;
    int n;
    switch ( sa->format ) {
	case SA_SAMPLE_FORMAT_FLOAT:
		n = sf_readf_float(s, buf, nframes);
		break;
	case SA_SAMPLE_FORMAT_S16:
		n = sf_readf_short(s, buf, nframes);
		break;
	default:
		assert(0);
		break;
    }
    if ( n < 0 ) {
	fprintf(stderr, "sf_read: ");
	sf_perror(s);
	return -1;
    }

    if ( sa->rxnoise != 0.0 ) {
	int i;
	float *fbuf = buf;
	float f = sa->rxnoise * 2;
	for ( i=0; i<nframes; i++ )
	    fbuf[i] += (drand48() - 0.5) * f;
    }

    // fprintf(stderr, "sf_read: nframes=%ld n=%d\n", nframes, n);
    return n;
}
开发者ID:TagPro-PreciousRoy,项目名称:minimodem,代码行数:33,代码来源:simpleaudio-sndfile.c


示例13: exit

sf_count_t Processor::read_frames(size_t start){
    size_t count = m_bufsize;
    sf_count_t readCount = 0;
    if (!m_file || !m_channelCount) {
        std::cerr << "no file or no channel" << std::endl;
        return 0;
    }
    if ((long)start >= m_fileInfo.frames) {
        std::cerr << "end of file" << std::endl;
	    return 0;
    }
    if (long(start + m_bufsize) > m_fileInfo.frames) {
	    count = m_fileInfo.frames - start;
    }
    if (sf_seek(m_file, start, SEEK_SET) < 0) {
        std::cerr << "sf_seek failed" << std::endl;
	    exit(EXIT_FAILURE);
	}
    if ((readCount = sf_readf_float(m_file, m_buffer, count)) < 0) {
        std::cerr << "sf_readf_float failed" << std::endl;
	    exit(EXIT_FAILURE);
	}
    //std::cout << readCount << std::endl;
    return readCount;
}
开发者ID:giliam,项目名称:data_analysis_soundcloud,代码行数:25,代码来源:Processor.cpp


示例14: while

size_t SndFileDecoder::read(char *buffer, size_t bytes)
{
    short *out = (short*)buffer;
    size_t frames = bytes / SndInfo.channels / 2;
    size_t total = 0;

    // It seems libsndfile has a bug with converting float samples from Vorbis
    // to the 16-bit shorts we use, which causes some PCM samples to overflow
    // and wrap, creating static. So instead, read the samples as floats and
    // convert to short ourselves.
    // Use a loop to convert a handful of samples at a time, avoiding a heap
    // allocation for temporary storage. 64 at a time works, though maybe it
    // could be more.
    while(total < frames)
    {
        size_t todo = MIN<size_t>(frames-total, 64/SndInfo.channels);
        float tmp[64];

        size_t got = (size_t)sf_readf_float(SndFile, tmp, todo);
        if(got < todo) frames = total + got;

        for(size_t i = 0;i < got*SndInfo.channels;i++)
            *out++ = (short)xs_CRoundToInt(clamp(tmp[i] * 32767.f, -32768.f, 32767.f));
        total += got;
    }
    return total * SndInfo.channels * 2;
}
开发者ID:ArcticPheenix,项目名称:gzdoom,代码行数:27,代码来源:sndfile_decoder.cpp


示例15: locker

void
WavFileReader::getInterleavedFrames(size_t start, size_t count,
				    SampleBlock &results) const
{
    if (count == 0) return;
    results.clear();
    results.reserve(count * m_fileInfo.channels);

    QMutexLocker locker(&m_mutex);

    if (!m_file || !m_channelCount) {
        return;
    }

    if ((long)start >= m_fileInfo.frames) {
//        SVDEBUG << "WavFileReader::getInterleavedFrames: " << start
//                  << " > " << m_fileInfo.frames << endl;
	return;
    }

    if (long(start + count) > m_fileInfo.frames) {
	count = m_fileInfo.frames - start;
    }

    sf_count_t readCount = 0;

    if (start != m_lastStart || count != m_lastCount) {

	if (sf_seek(m_file, start, SEEK_SET) < 0) {
//            std::cerr << "sf_seek failed" << std::endl;
	    return;
	}
	
	if (count * m_fileInfo.channels > m_bufsiz) {
//	    std::cerr << "WavFileReader: Reallocating buffer for " << count
//		      << " frames, " << m_fileInfo.channels << " channels: "
//		      << m_bufsiz << " floats" << std::endl;
	    m_bufsiz = count * m_fileInfo.channels;
	    delete[] m_buffer;
	    m_buffer = new float[m_bufsiz];
	}
	
	if ((readCount = sf_readf_float(m_file, m_buffer, count)) < 0) {
//            std::cerr << "sf_readf_float failed" << std::endl;
	    return;
	}

	m_lastStart = start;
	m_lastCount = readCount;
    }

    for (size_t i = 0; i < count * m_fileInfo.channels; ++i) {
        if (i >= m_bufsiz) {
            std::cerr << "INTERNAL ERROR: WavFileReader::getInterleavedFrames: " << i << " >= " << m_bufsiz << std::endl;
        }
	results.push_back(m_buffer[i]);
    }

    return;
}
开发者ID:iopenstack,项目名称:sonic-annotator,代码行数:60,代码来源:WavFileReader.cpp


示例16: OpenSoundFile

axSOUND_ERROR axAudioBuffer::OpenSoundFile( const string& snd_path )
{
    m_info = new SF_INFO;
    m_path = snd_path;

    if( !( m_sndFile = sf_open( m_path.c_str(), SFM_READ, m_info ) ) )
    {
        return axOPEN_SND_ERROR;
    }

    if( m_buffer )
    {
        delete m_buffer;
        m_buffer = nullptr;
    }

    m_buffer = new axFloat[m_info->frames * m_info->channels];

    /*unsigned int numFrames = */sf_readf_float( m_sndFile, m_buffer, m_info->frames );

    m_start = m_buffer;
    m_end = &m_buffer[ m_info->frames * m_info->channels - 1 ];

    sf_close( m_sndFile );

    return axNO_ERROR;
}
开发者ID:EQ4,项目名称:axLib,代码行数:27,代码来源:axAudioBuffer.cpp


示例17: g_object_new

GObject *phat_audiostream_new( char *filename ) {

    GObject *retval = g_object_new (PHAT_TYPE_AUDIOSTREAM, NULL);

    PhatAudiostream *stream = (PhatAudiostream *)  retval;

    // load file;
    SF_INFO info;
    SNDFILE *file = sf_open( filename, SFM_READ, &info );

    stream->data = malloc( sizeof(float) * info.frames * info.channels );
    if( stream->data == NULL ) {
	printf( "No Mem for audio file\n" );
	exit(20);
    }

    sf_readf_float( file, stream->data, info.frames );
    sf_close( file );

    stream->len = info.frames;
    stream->num_channels = info.channels;

    stream->src_buffer = malloc( sizeof(float) * 4096 * info.channels );
    if( stream->src_buffer == NULL ) {
	printf( "No Mem for Src Buffer\n" );
	exit(20);
    }


    return retval;
}
开发者ID:BackupTheBerlios,项目名称:phat-svn,代码行数:31,代码来源:phataudiostream.c


示例18: sf_readf_short

ALuint SndFileDecoder::read(ALvoid *ptr, ALuint count)
{
    sf_count_t got = 0;
    if(mSampleType == SampleType::Int16)
        got = sf_readf_short(mSndFile, static_cast<short*>(ptr), count);
    else if(mSampleType == SampleType::Float32)
        got = sf_readf_float(mSndFile, static_cast<float*>(ptr), count);
    return (ALuint)std::max<sf_count_t>(got, 0);
}
开发者ID:cpp-mirrors,项目名称:alure,代码行数:9,代码来源:sndfile.cpp


示例19: disk_thread

static void *
disk_thread (void *arg)
{	thread_info_t *info = (thread_info_t *) arg ;
	sf_count_t buf_avail, read_frames ;
	jack_ringbuffer_data_t vec [2] ;
	size_t bytes_per_frame = sample_size*info->channels ;

	pthread_setcanceltype (PTHREAD_CANCEL_ASYNCHRONOUS, NULL) ;
	pthread_mutex_lock (&disk_thread_lock) ;

	while (1)
	{	jack_ringbuffer_get_write_vector (ringbuf, vec) ;

		read_frames = 0 ;

		if (vec [0].len)
		{	/* Fill the first part of the ringbuffer. */
			buf_avail = vec [0].len / bytes_per_frame ;
			read_frames = sf_readf_float (info->sndfile, (float *) vec [0].buf, buf_avail) ;
			if (vec [1].len)
			{	/* Fill the second part of the ringbuffer? */
				buf_avail = vec [1].len / bytes_per_frame ;
				read_frames += sf_readf_float (info->sndfile, (float *) vec [1].buf, buf_avail) ;
				} ;
			} ;

		if (read_frames == 0)
			break ; /* end of file? */

		jack_ringbuffer_write_advance (ringbuf, read_frames * bytes_per_frame) ;

		/* Tell process that we've filled the ringbuffer. */
		info->can_process = 1 ;

		/* Wait for the process thread to wake us up. */
		pthread_cond_wait (&data_ready, &disk_thread_lock) ;
		} ;

	/* Tell that we're done reading the file. */
	info->read_done = 1 ;
	pthread_mutex_unlock (&disk_thread_lock) ;

	return 0 ;
} /* disk_thread */
开发者ID:Tanmay-r,项目名称:cs293Project,代码行数:44,代码来源:sndfile-jackplay.c


示例20: SendFailure

bool BufReadCmd::Stage2()
{
#ifdef NO_LIBSNDFILE
	SendFailure(&mReplyAddress, "/b_read", "scsynth compiled without libsndfile\n");
 	scprintf("scsynth compiled without libsndfile\n");
	return false;
#else
	SF_INFO fileinfo;

	SndBuf *buf = World_GetNRTBuf(mWorld, mBufIndex);
	int framesToEnd = buf->frames - mBufOffset;
	if (framesToEnd <= 0) return true;

	SNDFILE* sf = sf_open(mFilename, SFM_READ, &fileinfo);
	if (!sf) {
		char str[512];
		sprintf(str, "File '%s' could not be opened: %s\n", mFilename, sf_strerror(NULL));
		SendFailureWithIntValue(&mReplyAddress, "/b_read", str, mBufIndex); //SendFailure(&mReplyAddress, "/b_read", str);
		scprintf(str);
		return false;
	}
	if (fileinfo.channels != buf->channels) {
		char str[512];
		sf_close(sf);
		sprintf(str, "Channel mismatch. File '%s' has %d channels. Buffer has %d channels.\n", mFilename, fileinfo.channels, buf->channels);
		SendFailureWithIntValue(&mReplyAddress, "/b_read", str, mBufIndex); //SendFailure(&mReplyAddress, "/b_read", str);
		scprintf(str);
		return false;
	}

	if (mFileOffset < 0) mFileOffset = 0;
	else if (mFileOffset > fileinfo.frames) mFileOffset = fileinfo.frames;
	if (mNumFrames < 0 || mNumFrames + mFileOffset > fileinfo.frames) mNumFrames = fileinfo.frames - mFileOffset;

	if (mNumFrames > framesToEnd) mNumFrames = framesToEnd;

	sf_seek(sf, mFileOffset, SEEK_SET);
	if (mNumFrames > 0) {
		sf_readf_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;
	}

	mSampleRate = (double)fileinfo.samplerate;

	return true;
#endif
}
开发者ID:ARTisERR0R,项目名称:supercollider,代码行数:56,代码来源:SC_SequencedCommand.cpp



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ sf_register_machine_exported_symbols函数代码示例发布时间:2022-05-30
下一篇:
C++ sf_read_short函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap