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


C++ sf_readf_short函数代码示例

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


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

示例1: CHECK

size_t LibmediaPlayback::FillBuffer(void* data, size_t size) {
  CHECK(data);
  if (in_file_) {
    int frames_read = 0;
    int frame_size = audio_bytes_per_sample(audio_format_) * num_channels_;
    int sample_size = audio_bytes_per_sample(audio_format_);
    if (sample_size == 1) {
      void* temp = malloc(size * sizeof(short));
      frames_read = sf_readf_short(in_file_, reinterpret_cast<short*>(temp),
                                   size / frame_size);
      int num_samples = frames_read * frame_size / sample_size;
      memcpy_to_u8_from_i16(reinterpret_cast<uint8_t*>(data),
                            reinterpret_cast<int16_t*>(temp), num_samples);
      free(temp);
    } else if (sample_size == 2) {
      frames_read = sf_readf_short(in_file_, reinterpret_cast<short*>(data),
                                   size / frame_size);
    } else if (sample_size == 4) {
      frames_read = sf_readf_int(in_file_, reinterpret_cast<int*>(data),
                                 size / frame_size);
    } else {
      LOG(ERROR) << "Could not handle file with sample size = " << sample_size;
      return 0;
    }
    size = frame_size * frames_read;
  } else {
    size = (size < sine_data_buffer_->size()) ? size :
        sine_data_buffer_->size();
    memcpy(data, sine_data_buffer_->data(), size);
  }
  return size;
}
开发者ID:yudatun,项目名称:brillo_device_generic_brillo,代码行数:32,代码来源:libmedia_playback.cpp

示例2: ra_sound_read_short

static void ra_sound_read_short(RA_SOUND *snd, RA_BUFFER *buf, sf_count_t frames) {
    static short temp[1024];
    int temp_len = 1024;
    short *data = (short*)buf->data;
    short 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_short(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_short(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_short(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

示例3: file_decode_tests

static int file_decode_tests(super_tone_rx_state_t *super, const char *file_name)
{
    int16_t amp[8000];
    int sample;
    int frames;
    int x;
    awgn_state_t noise_source;

    printf("File decode tests\n");
    super_tone_rx_tone_callback(super, wakeup, (void *) "test");
    awgn_init_dbm0(&noise_source, 1234567, -30.0f);
    printf("Processing file\n");
    if ((inhandle = sf_open_telephony_read(file_name, 1)) == NULL)
    {
        fprintf(stderr, "    Cannot open audio file '%s'\n", file_name);
        exit(2);
    }
    while ((frames = sf_readf_short(inhandle, amp, 8000)))
    {
        /* Add some noise to the signal for a more meaningful test. */
        //for (sample = 0;  sample < frames;  sample++)
        //    amp[sample] += saturate(amp[sample] + awgn (&noise_source));
        for (sample = 0;  sample < frames;  )
        {
            x = super_tone_rx(super, amp + sample, frames - sample);
            sample += x;
        }
    }
    if (sf_close_telephony(inhandle))
    {
        fprintf(stderr, "    Cannot close audio file '%s'\n", file_name);
        exit(2);
    }
    return 0;
}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:35,代码来源:super_tone_rx_tests.c

示例4: talk_off_tests

static int talk_off_tests(super_tone_rx_state_t *super)
{
    int16_t amp[8000];
    int sample;
    int frames;
    int j;
    int x;

    /* Test for voice immunity */
    printf("Talk off tests\n");
    for (j = 0;  bellcore_files[j][0];  j++)
    {
        if ((inhandle = sf_open_telephony_read(bellcore_files[j], 1)) == NULL)
        {
            printf("    Cannot open audio file '%s'\n", bellcore_files[j]);
            exit(2);
        }
        while ((frames = sf_readf_short(inhandle, amp, 8000)))
        {
            for (sample = 0;  sample < frames;  )
            {
                x = super_tone_rx(super, amp + sample, frames - sample);
                sample += x;
            }
    	}
        if (sf_close_telephony(inhandle))
    	{
    	    printf("    Cannot close speech file '%s'\n", bellcore_files[j]);
            exit(2);
    	}
    }
    return 0;
}
开发者ID:AbrahamJewowich,项目名称:FreeSWITCH,代码行数:33,代码来源:super_tone_rx_tests.c

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

示例6: load_buffer

	size_t load_buffer(ALuint buf) {
		// seek to beginning if in a end
		if (is_end()) {
			if (info_.seekable) {
				if (sf_seek(file_.get(), 0, SEEK_SET) == -1) {
					Output::Error("libsndfile seek error: %s", sf_strerror(file_.get()));
					return 0;
				}
			} else {
				file_.reset(sf_open(filename_.c_str(), SFM_READ, &info_), sf_close);
				if (!file_) {
					Output::Error("libsndfile open error: %s", sf_strerror(NULL));
					return 0;
				}
			}
			loop_count_++;
			seek_pos_ = 0;
		}

		data_.resize(info_.channels * info_.samplerate * SECOND_PER_BUFFER);
		sf_count_t const read_size =
		    sf_readf_short(file_.get(), &data_.front(), data_.size() / info_.channels);
		alBufferData(buf, format_, &data_.front(), sizeof(int16_t) * data_.size(),
		             info_.samplerate);
		seek_pos_ += read_size;
		return read_size;
	}
开发者ID:FaithFeather,项目名称:Player,代码行数:27,代码来源:audio_al.cpp

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

示例8: __pulseaudio_stream_write_cb

static void __pulseaudio_stream_write_cb(pa_stream *stream, size_t length, void *user_data)
{
	sf_count_t read_length;
	short *data;
	SOUND_INFO *info = NULL;

	mmf_return_if_fail(user_data);

	info = (SOUND_INFO *)user_data;

	_mmcam_dbg_log("START");

	data = pa_xmalloc(length);

	read_length = (sf_count_t)(length/pa_frame_size(&(info->sample_spec)));

	if ((sf_readf_short(info->infile, data, read_length)) != read_length) {
		pa_xfree(data);
		return;
	}

	pa_stream_write(stream, data, length, pa_xfree, 0, PA_SEEK_RELATIVE);

	info->sample_length -= length;

	if (info->sample_length <= 0) {
		pa_stream_set_write_callback(info->sample_stream, NULL, NULL);
		pa_stream_finish_upload(info->sample_stream);

		pa_threaded_mainloop_signal(info->pulse_mainloop, 0);
		_mmcam_dbg_log("send signal DONE");
	}

	_mmcam_dbg_log("DONE read_length %d", read_length);
}
开发者ID:tizenorg,项目名称:framework.multimedia.libmm-camcorder,代码行数:35,代码来源:mm_camcorder_sound.c

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

示例10: sf_readf_short

void SndFileSource::process()
    {
    //open first file
    if (mSoundFile || openNextFile())
        {
        // read audio data
        do
            {
            sf_count_t res = sf_readf_short(mSoundFile, mAlsaFrame.getSoundBuffer(), mAlsaFrame.getDimensionT(AlsaFrame::Time).mResolution);
            if (res > 0)
                {
                // keep constant frame size, populate with zeros
                if (res < mAlsaFrame.getDimensionT(AlsaFrame::Time).mResolution)
                    memset(mAlsaFrame.getSoundBuffer() + res*mAlsaFrame.getDimensionT(AlsaFrame::Channels).mResolution, 0, (mAlsaFrame.getDimensionT(AlsaFrame::Time).mResolution - res)*sizeof(qint16)*mAlsaFrame.getDimensionT(AlsaFrame::Channels).mResolution);

                mAlsaFrame.incrementTimeStamp();
                emit framesReady();
                return;
                }
            }
        //open next file
        while (openNextFile());
        }

    //error openning file
    emit processingCompleted();
    }
开发者ID:rpietruc,项目名称:qmediamodeler,代码行数:27,代码来源:sndfilesource.cpp

示例11: callback

static void callback(SLBufferQueueItf bufq, void *param)
{
    assert(NULL == param);
    if (!eof) {
        short *buffer = &buffers[framesPerBuffer * sfinfo.channels * which];
        sf_count_t count;
        count = sf_readf_short(sndfile, buffer, (sf_count_t) framesPerBuffer);
        if (0 >= count) {
            eof = SL_BOOLEAN_TRUE;
        } else {
            SLuint32 nbytes = count * sfinfo.channels * sizeof(short);
            if (byteOrder != nativeByteOrder) {
                swab(buffer, buffer, nbytes);
            }
            if (bitsPerSample == 8) {
                squeeze(buffer, (unsigned char *) buffer, nbytes);
                nbytes /= 2;
            }
            SLresult result = (*bufq)->Enqueue(bufq, buffer, nbytes);
            assert(SL_RESULT_SUCCESS == result);
            if (++which >= numBuffers)
                which = 0;
        }
    }
}
开发者ID:JokeLook,项目名称:framework,代码行数:25,代码来源:playbq.c

示例12: memset

/// Read the data portion of the block file using libsndfile.  Convert it
/// to the given format if it is not already.
///
/// @param data   The buffer where the data will be stored
/// @param format The format the data will be stored in
/// @param start  The offset in this block file
/// @param len    The number of samples to read
int LegacyBlockFile::ReadData(samplePtr data, sampleFormat format,
                              sampleCount start, sampleCount len)
{
   SF_INFO info;

   memset(&info, 0, sizeof(info));

   switch(mFormat) {
   case int16Sample:
      info.format =
         SF_FORMAT_RAW | SF_FORMAT_PCM_16 | SF_ENDIAN_CPU;
      break;
   default:
   case floatSample:
      info.format =
         SF_FORMAT_RAW | SF_FORMAT_FLOAT | SF_ENDIAN_CPU;
      break;
   case int24Sample:
      info.format = SF_FORMAT_RAW | SF_FORMAT_PCM_32 | SF_ENDIAN_CPU;
      break;
   }
   info.samplerate = 44100; // Doesn't matter
   info.channels = 1;
   info.frames = mLen + (mSummaryInfo.totalSummaryBytes /
                         SAMPLE_SIZE(mFormat));
   
   SNDFILE *sf = sf_open(mFileName.GetFullPath(), SFM_READ, &info);

   if (!sf)
      return 0;

   sf_count_t seekstart = start +
      (mSummaryInfo.totalSummaryBytes / SAMPLE_SIZE(mFormat));
   sf_seek(sf, seekstart , SEEK_SET);

   samplePtr buffer = NewSamples(len, floatSample);

   int framesRead = 0;

   // If both the src and dest formats are integer formats,
   // read integers from the file (otherwise we would be
   // converting to float and back, which is unneccesary)
   if (format == int16Sample &&
       sf_subtype_is_integer(info.format)) {
      framesRead = sf_readf_short(sf, (short *)data, len);
   }
   else
   if (format == int24Sample &&
       sf_subtype_is_integer(info.format))
   {
      framesRead = sf_readf_int(sf, (int *)data, len);

      // libsndfile gave us the 3 byte sample in the 3 most
      // significant bytes -- we want it in the 3 least
      // significant bytes.
      int *intPtr = (int *)data;
      for( int i = 0; i < framesRead; i++ )
         intPtr[i] = intPtr[i] >> 8;
   }
开发者ID:ruthmagnus,项目名称:audacity,代码行数:66,代码来源:LegacyBlockFile.cpp

示例13: malloc

int Mp3Decoder::getMonoFrames(int numFrames, void *buffer) {
    void *tmpBuffer = malloc(2*numFrames*2);
    int readFrames = sf_readf_short(sfFile, (short*)tmpBuffer, numFrames);
    for(int i=0; i<readFrames;i++) {
        memcpy(buffer+2*i, tmpBuffer+4*i, 2);
    }
    return readFrames;
}
开发者ID:moritzschaefer,项目名称:synchronizer,代码行数:8,代码来源:mp3decoder.cpp

示例14: msleep

bool DRMReceiver::fRead(CVector<_SAMPLE>& psData)
{
	msleep(75);
	int len = BufferSize / 2;
	sf_count_t c = sf_readf_short(sfin, &psData[0], len);
	if(c != len)
	{
		if(m_loop)
		{
			/* rewind */
			sf_seek(sfin, 0, SEEK_SET);
			c = sf_readf_short(sfin, &psData[0], len);
		}
		else
			return true;
	}
	return false;
}
开发者ID:castrouk,项目名称:LinDrm,代码行数:18,代码来源:DrmReceiver.cpp

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


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