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