1 /* 2 * Copyright (C) 2002-2003 Fhg Fokus 3 * 4 * This file is part of SEMS, a free SIP media server. 5 * 6 * SEMS is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 2 of the License, or 9 * (at your option) any later version. 10 * 11 * For a license to use the sems software under conditions 12 * other than those described here, or to purchase support for this 13 * software, please contact iptel.org by e-mail at the following addresses: 14 * info@iptel.org 15 * 16 * SEMS is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 */ 25 26 #ifndef _SampleArray_h_ 27 #define _SampleArray_h_ 28 29 /* MUST be a power of 2 */ 30 #define SIZE_MIX_BUFFER (1<<14) 31 /** \brief comparator for user timestamps */ 32 struct ts_less 33 { 34 bool operator()(const unsigned int& l, 35 const unsigned int& r) const; 36 }; 37 38 /** \brief comparator for system timestamps 39 * Note that system timestamps overflow at 48 bit boundaries. 40 */ 41 struct sys_ts_less 42 { 43 bool operator()(const unsigned long long& l, 44 const unsigned long long& r) const; 45 }; 46 47 /** \brief timed array of samples */ 48 template <typename T> 49 class SampleArray 50 { 51 public: 52 //protected: 53 54 T samples[SIZE_MIX_BUFFER]; 55 unsigned int last_ts; 56 bool init; 57 58 void clear_all(); 59 void clear(unsigned int start_ts,unsigned int end_ts); 60 void write(unsigned int ts, T* buffer, unsigned int size); 61 void read(unsigned int ts, T* buffer, unsigned int size); 62 63 //public: 64 SampleArray(); 65 66 /** 67 * @param size buffer size in [samples]. 68 */ 69 void put(unsigned int ts, T* buffer, unsigned int size); 70 71 /** 72 * @param buf_size buffer size in [samples]. 73 */ 74 void get(unsigned int ts, T* buffer, unsigned int buf_size); 75 }; 76 77 // 32 bit sample 78 typedef int IntSample; 79 80 // 32 bit sample array 81 typedef SampleArray<IntSample> SampleArrayInt; 82 83 // 16 bit sample 84 typedef short ShortSample; 85 86 // 16 bit sample array 87 typedef SampleArray<ShortSample> SampleArrayShort; 88 89 typedef short ShortSample; 90 91 #include "SampleArray.cc" 92 93 #endif 94 // Local Variables: 95 // mode:C++ 96 // End: 97 98