1 /* Copyright (C) 2012 Olga Yakovleva <yakovleva.o.v@gmail.com> */ 2 3 /* This program is free software: you can redistribute it and/or modify */ 4 /* it under the terms of the GNU Lesser General Public License as published by */ 5 /* the Free Software Foundation, either version 2.1 of the License, or */ 6 /* (at your option) any later version. */ 7 8 /* This program is distributed in the hope that it will be useful, */ 9 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 10 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 11 /* GNU Lesser General Public License for more details. */ 12 13 /* You should have received a copy of the GNU Lesser General Public License */ 14 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */ 15 16 #ifndef RHVOICE_SPEECH_STREAM_HPP 17 #define RHVOICE_SPEECH_STREAM_HPP 18 19 #include <vector> 20 #include "sonic.h" 21 22 namespace RHVoice 23 { 24 class speech_stream 25 { 26 public: 27 typedef std::vector<short> buffer_type; 28 29 speech_stream(int sample_rate,double rate); 30 ~speech_stream()31 ~speech_stream() 32 { 33 if(sonic_stream) 34 sonicDestroyStream(sonic_stream); 35 } 36 set_start_offset(int offset)37 void set_start_offset(int offset) 38 { 39 start_offset=offset; 40 } 41 get_rate() const42 double get_rate() const 43 { 44 return (sonic_stream?sonicGetSpeed(sonic_stream):1); 45 } 46 47 void write(short sample); 48 bool read(buffer_type& buffer,int min_size=0); 49 void flush(); 50 get_offset() const51 int get_offset() const 52 { 53 return offset; 54 } 55 56 private: 57 speech_stream(const speech_stream&); 58 speech_stream& operator=(const speech_stream&); 59 60 void flush_input_buffer(); 61 62 int buffer_size; 63 buffer_type samples; 64 int offset,start_offset; 65 sonicStream sonic_stream; 66 }; 67 } 68 #endif 69