source: rrlib_speech_synthesis/tStreamBuffer.cpp

tip
Last change on this file was 7:d70de441dbce, checked in by Tobias Föhst <foehst@…>, 7 years ago

Added and updated license information

File size: 4.3 KB
Line 
1//
2// You received this file as part of RRLib
3// Robotics Research Library
4//
5// Copyright (C) Finroc GbR (finroc.org)
6//
7// This program is free software; you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation; either version 2 of the License, or
10// (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License along
18// with this program; if not, write to the Free Software Foundation, Inc.,
19// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20//
21//----------------------------------------------------------------------
22/*!\file    rrlib/speech_synthesis/tStreamBuffer.cpp
23 *
24 * \author  Tobias Föhst
25 *
26 * \date    2013-08-07
27 *
28 */
29//----------------------------------------------------------------------
30#include "rrlib/speech_synthesis/tStreamBuffer.h"
31
32//----------------------------------------------------------------------
33// External includes (system with <>, local with "")
34//----------------------------------------------------------------------
35#include <iostream>
36
37//----------------------------------------------------------------------
38// Internal includes with ""
39//----------------------------------------------------------------------
40
41//----------------------------------------------------------------------
42// Debugging
43//----------------------------------------------------------------------
44#include <cassert>
45
46//----------------------------------------------------------------------
47// Namespace usage
48//----------------------------------------------------------------------
49
50//----------------------------------------------------------------------
51// Namespace declaration
52//----------------------------------------------------------------------
53namespace rrlib
54{
55namespace speech_synthesis
56{
57
58//----------------------------------------------------------------------
59// Forward declarations / typedefs / enums
60//----------------------------------------------------------------------
61
62//----------------------------------------------------------------------
63// Const values
64//----------------------------------------------------------------------
65
66//----------------------------------------------------------------------
67// Implementation
68//----------------------------------------------------------------------
69
70//----------------------------------------------------------------------
71// tStreamBuffer constructors
72//----------------------------------------------------------------------
73tStreamBuffer::tStreamBuffer(speech_synthesis::tVoice &voice, std::size_t buffer_size) :
74  voice(voice),
75  buffer(buffer_size + 1)
76{
77  this->setp(this->buffer.data(), this->buffer.data() + buffer_size);
78}
79
80//----------------------------------------------------------------------
81// tStreamBuffer destructor
82//----------------------------------------------------------------------
83tStreamBuffer::~tStreamBuffer()
84{
85  this->sync();
86}
87
88//----------------------------------------------------------------------
89// tStreamBuffer ProcessBuffer
90//----------------------------------------------------------------------
91void tStreamBuffer::ProcessBuffer()
92{
93  std::ptrdiff_t n = this->pptr() - this->pbase();
94  this->pbump(-n);
95
96  this->voice.Say(std::string(this->pbase(), n));
97}
98
99//----------------------------------------------------------------------
100// tStreamBuffer overflow
101//----------------------------------------------------------------------
102tStreamBuffer::int_type tStreamBuffer::overflow(int_type c)
103{
104  if (c != traits_type::eof())
105  {
106    assert(this->pptr() <= this->epptr());
107    *this->pptr() = c;
108    this->pbump(1);
109    this->ProcessBuffer();
110  }
111
112  return c;
113}
114
115//----------------------------------------------------------------------
116// tStreamBuffer sync
117//----------------------------------------------------------------------
118int tStreamBuffer::sync()
119{
120  this->ProcessBuffer();
121  return 0;
122}
123
124//----------------------------------------------------------------------
125// End of namespace declaration
126//----------------------------------------------------------------------
127}
128}
Note: See TracBrowser for help on using the repository browser.