⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 recorder.cpp

📁 voudp - VoIP for NetBSD
💻 CPP
字号:
//// Copyright 2004 Alan Post//// This file is part of voudp.//// voudp is free software; you can redistribute it and/or modify it under the// terms of the GNU General Public License as published by the Free Software// Foundation; either version 2 of the License, or (at your option) any later// version.//// voudp is distributed in the hope that it will be useful, but WITHOUT ANY// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR// A PARTICULAR PURPOSE.  See the GNU General Public License for more details.//// You should have received a copy of the GNU General Public License along with// voudp; if not, write to the Free Software Foundation, Inc., 59 Temple Place,// Suite 330, Boston, MA  02111-1307  USA//#include "recorder.h"#include "sender.h"#include "die.h"#include <sys/audioio.h>#include <sys/ioctl.h>#include <algorithm>Recorder::Recorder(       u_int8_t    *dma_buf_,                    const int         &afd_,                    const size_t      &blocksize_,     // in bytes                    const size_t      &buffer_size_ )  // in bytes: dma_buf( dma_buf_ ),  afd( afd_ ),  blocksize( blocksize_ ),  blocks_in_buffer( buffer_size_ / blocksize_ ),  samples_per_block( blocksize_ / sizeof( hw_sample_t )),  last_read_block( -1 ),  frame_write_offset( 0 ){}static void convert( float *samples, hw_sample_t *hw, u_int n ){    for ( u_int i = 0; i < n; i++ )    {        samples[ i ] = (float) hw[i].s[0];    }}voidRecorder::record_if_needed( Sender &sender ){    audio_offset_t poff;    if ( ioctl( afd, AUDIO_GETIOFFS, &poff ) < 0 )        die( "failed to get mic offset" );    u_int recording_block = poff.samples / blocksize;    if ( last_read_block >= (ssize_t)recording_block - 1 ) return;    hw_sample_t *block = (hw_sample_t*)        ( dma_buf +   blocksize                    * ((recording_block - 1) % blocks_in_buffer));    u_int block_offset = 0;   // units in samples    while ( block_offset < samples_per_block )    {        u_int to_read = samples_per_block - block_offset;        u_int writing_space = samples_per_frame - frame_write_offset;        if ( writing_space == 0 )        {            sender.push_frame( frame );            frame_write_offset = 0;            continue;        }        u_int writing = min( to_read, writing_space );        convert( frame + frame_write_offset,                 block + block_offset,                 writing );        frame_write_offset += writing;        block_offset += writing;    }    last_read_block = recording_block - 1;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -