| // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| // |
| // An interface representing a real-time audio output system on a particular |
| // platform. |
| |
| #ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_ |
| #define SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_ |
| |
| #include <stdlib.h> |
| |
| namespace speech_synthesis { |
| |
| class Threading; |
| |
| // This is an interface defining the method that fills an audio buffer |
| // for real-time audio output. Typically the TtsService implements this |
| // method for AudioOutput, so that the service has all of the logic for |
| // computing the samples to be computed, but AudioOutput has all of the logic |
| // for dealing with the platform-specific audio hardware abstraction. |
| class AudioProvider { |
| public: |
| virtual ~AudioProvider() { } |
| |
| // This method must return quickly and not block. It must always |
| // fill all of the samples, with silence padding as needed. |
| // Returns false if audio should completely stop. |
| virtual bool FillAudioBuffer(int16_t* samples, int size) = 0; |
| }; |
| |
| // This is the abstract definition of a class that does real-time audio |
| // output. You must provide an implementation of an AudioProvider that |
| // provides the actual samples to output on demand (or silence, if there |
| // are not enough samples available immediately). Subclasses of AudioOutput |
| // implement these methods using various platform-specific methods. |
| class AudioOutput { |
| protected: |
| AudioOutput() { } |
| |
| public: |
| // Static factory method, creates whatever AudioOutput subclass |
| // has been linked in. |
| static AudioOutput* Create(Threading *threading); |
| |
| virtual ~AudioOutput() {} |
| |
| // Initialize audio output, getting audio samples from the given provider. |
| // Returns true on success. Safe to call more than once. |
| virtual bool Init(AudioProvider *provider) = 0; |
| |
| virtual void StartAudio() = 0; |
| |
| virtual void StopAudio() = 0; |
| |
| virtual int GetSampleRate() = 0; |
| |
| virtual int GetChannelCount() = 0; |
| |
| // The typical number of samples that will be requested at once. |
| // The TTS system may want to generate audio in increments of this |
| // many samples, but it's just a hint. |
| virtual int GetChunkSize() = 0; |
| |
| // The number of samples needed to completely fill the audio buffers. |
| // The provider must be able to quickly produce at least this many |
| // samples in order to avoid underflow. |
| virtual int GetTotalBufferSize() = 0; |
| }; |
| |
| } // namespace speech_synthesis |
| |
| #endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_AUDIO_OUTPUT_H_ |
| |