Пример #1
0
void 
audio_membuffer::audio_receive(unsigned char *data, unsigned int size)
{
    /* If there isn't a buffer, allocs memory for it of size*2, and copies audio data arrival */
    if ((audio_data == 0) || (buf_size == 0))
    {
        alloc_mem_(size * 2);
        memcpy(audio_data, data, size);
        return;
    }

    /* If buffer's free memory is < of `size', we have to realloc buffer memory
       of buf_size*2, while free memory is enough to contain `size' bytes.
       In this case free memory is represented by `buf_size - bytes_recorded' */
    unsigned int tot_mem = buf_size, free_mem = buf_size - bytes_received;
    if (free_mem < size)
    {
        /* Calcs new buffer size */
        /* TODO: flags for other behaviour? */
        while (free_mem < size)
        {
            tot_mem *= 2;
            free_mem = tot_mem - bytes_received;
        }

        /* Resize buffer memory */
        resize_mem_(tot_mem);
    }

    /* Now we have enough free space in the buffer, so let's copy audio data arrivals */
    memcpy(audio_data + bytes_received, data, size);

    if (audio_arrival)
        audio_arrival(aud_info.samples_in_bytes(size));
}
Пример #2
0
void 
audio_membuffer::alloc_seconds( unsigned int secs )
{
    
    alloc_mem_( aud_info.byte_rate() * secs );

}
Пример #3
0
void 
audio_membuffer::alloc_seconds( float secs )
{

    alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs ));

}
Пример #4
0
void 
audio_membuffer::alloc_bytes( unsigned int bytes )
{

    alloc_mem_( bytes );

}
Пример #5
0
void 
audio_membuffer::reset(void)
{
    /* Frees memory and reset to initial state */
    clear();
    /* Alloc memory of size specified at the constructor */
    alloc_mem_(init_size);
}
Пример #6
0
 audio_membuffer(unsigned int bytes) : audio_data(0),
                                       aud_info(_AUDIO_DEFAULT_FORMAT),
                                       buf_size(0),
                                       init_size(0)
 {
     /* Allocs memory for the specified bytes */
     init_size = bytes;
     alloc_mem_(init_size);
 }
Пример #7
0
 audio_membuffer(audio_format aud_fmt, float seconds) : audio_data(0),
                                                        aud_info(aud_fmt),
                                                        buf_size(0),
                                                        init_size(0)
 {
     /* Allocs memory for audio recording the specified number of seconds */
     init_size = (unsigned int)((float)aud_info.byte_rate() * seconds <= 0 ? 1 : seconds);
     alloc_mem_(init_size);
 }
Пример #8
0
 audio_membuffer(audio_format aud_fmt) : audio_data(0),
                                         aud_info(aud_fmt),
                                         buf_size(0),
                                         init_size(0)
 {
     /* Allocs memory for at least 1 or some seconds of recording */
     init_size = (unsigned int)((float)aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS);
     alloc_mem_(init_size);
 }
Пример #9
0
 audio_membuffer( audio_format aud_fmt, unsigned int seconds )
     : audio_data( 0 ), aud_info( aud_fmt ), buf_size( 0 ),
     init_size( 0 )
 {  
     
     //
     // Allocs memory for audio recording
     // the specified number of seconds.
     //
     init_size = aud_info.byte_rate() * seconds;
     alloc_mem_( init_size );
 
 }
Пример #10
0
        audio_membuffer( void )
            : audio_data( 0 ), aud_info( _AUDIO_DEFAULT_FORMAT ),
            buf_size( 0 ), init_size( 0 )
        {  
            
            //
            // Allocs memory for at least 1 or some seconds
            // of recording.
            //
            init_size = ( unsigned int )
                (( float )aud_info.byte_rate() * _AUDIO_DEFAULT_BUFSECS );


            alloc_mem_( init_size );

        
        }
Пример #11
0
    int ObStringBuf :: alloc_a_block_()
    {
      int err = OB_SUCCESS;
      void* tmp_ptr = NULL;
      MemBlock* cur_block = NULL;

      err = alloc_mem_(DEF_MEM_BLOCK_SIZE, tmp_ptr);
      if (OB_SUCCESS != err || NULL == tmp_ptr)
      {
        TBSYS_LOG(WARN, "failed to alloc mem, mem_size=%ld, err=%d",
            DEF_MEM_BLOCK_SIZE, err);
        err = OB_ERROR;
      }
      else
      {
        cur_block = static_cast<MemBlock*> (tmp_ptr);
        cur_block->next = NULL;
        cur_block->cur_pos = 0;
        cur_block->block_size = DEF_MEM_BLOCK_SIZE - sizeof(MemBlock);
        if (NULL == block_head_)
        {
          block_head_ = cur_block;
          block_tail_ = cur_block;
        }
        else
        {
          if (NULL == block_tail_)
          {
            TBSYS_LOG(WARN, "block_tail_ is NULL");
            err = OB_ERROR;
          }
          else
          {
            block_tail_->next = cur_block;
            block_tail_ = cur_block;
          }
        }
      }

      return err;
    }
Пример #12
0
void 
audio_membuffer::reset( void )
{


    //
    // Frees memory and reset
    // to initial state.
    //

    clear();



    //
    // Alloc memory of size specified
    // at the constructor.
    //

    alloc_mem_( init_size );


}