1 /* 2 * Copyright (C) 2007 iptego GmbH 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 /** @file AmAudioMixIn.h */ 26 #ifndef _AM_AUDIO_MIX_IN_H 27 #define _AM_AUDIO_MIX_IN_H 28 29 #include "AmAudio.h" 30 #include "AmAudioFile.h" 31 32 33 #define MAX_PACKETLENGTH_MS 80 34 #define MAX_BUF_SAMPLES SYSTEM_SAMPLECLOCK_RATE * MAX_PACKETLENGTH_MS / 1000 35 #define DEFAULT_SAMPLE_RATE SYSTEM_SAMPLECLOCK_RATE // eh... 36 37 /** 38 * \brief \ref AmAudio to mix in every n seconds a file 39 * 40 * This is only for output (e.g. mixing in some tones into a call) 41 * 42 * AmAudio that plays Audio A and 43 * every s seconds mixes in AudioFile B with level l. 44 * If l == 0, playback of A is not continued when playing B, 45 * which means that it continues right where it was before 46 * playback of B started. 47 * 48 */ 49 #define AUDIO_MIXIN_FINISH_B_MIX 1 /* when A ends while mixing in B, end playback only after B has ended */ 50 #define AUDIO_MIXIN_ONCE 1 << 1 /* only mix in once */ 51 #define AUDIO_MIXIN_IMMEDIATE_START 1 << 2 /* start mixing in immediately, or wait s seconds before */ 52 53 class AmAudioMixIn : public AmAudio { 54 AmAudio* A; 55 AmAudio* B; 56 unsigned int s; 57 double l; 58 int flags; 59 60 bool mixing; 61 62 AmMutex B_mut; 63 64 unsigned long long next_start_ts; 65 bool next_start_ts_i; 66 67 short mix_buf[MAX_BUF_SAMPLES]; // 240 68 69 70 public: 71 AmAudioMixIn(AmAudio* A, AmAudio* B, 72 unsigned int s, double l, 73 unsigned int flags = 0); 74 ~AmAudioMixIn(); 75 76 void mixin(AmAudio* f); 77 78 protected: 79 // not used read(unsigned int user_ts,unsigned int size)80 int read(unsigned int user_ts, unsigned int size){ return -1; } write(unsigned int user_ts,unsigned int size)81 int write(unsigned int user_ts, unsigned int size){ return -1; } 82 83 // override AmAudio 84 int get(unsigned long long system_ts, unsigned char* buffer, 85 int output_sample_rate, unsigned int nb_samples); 86 87 int put(unsigned long long system_ts, unsigned char* buffer, 88 int input_sample_rate, unsigned int size); 89 }; 90 91 92 #endif // _AM_AUDIO_MIX_IN_H 93