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)); }
void audio_membuffer::alloc_seconds( unsigned int secs ) { alloc_mem_( aud_info.byte_rate() * secs ); }
void audio_membuffer::alloc_seconds( float secs ) { alloc_mem_(( unsigned int )(( float ) aud_info.byte_rate() * secs )); }
void audio_membuffer::alloc_bytes( unsigned int bytes ) { alloc_mem_( bytes ); }
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); }
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); }
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); }
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); }
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 ); }
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 ); }
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; }
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 ); }