blob: ef6d17bbef08436e2d01bd628c5e49fb47833257 [file] [log] [blame]
// 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.
//
// Implementation of TtsDataReceiver that resamples the audio to a
// different sample rate and then passes the resampled audio through
// to another callback.
#ifndef SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_
#define SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_
#include <stdint.h>
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "tts_receiver.h"
namespace speech_synthesis {
class Resampler : public TtsDataReceiver {
public:
// Resamples the audio passed to this object's Receive method and passes
// the resampled audio through to the destination.
Resampler(TtsDataReceiver *destination,
int source_rate,
int dest_rate,
int buffer_size);
virtual ~Resampler();
// TtsDataReceiver override.
virtual tts_callback_status Receive(int rate,
int num_channels,
const int16_t* data,
int num_samples,
tts_synth_status status) OVERRIDE;
int source_rate() { return source_rate_; }
int dest_rate() { return dest_rate_; }
private:
TtsDataReceiver* destination_;
int source_rate_;
int dest_rate_;
double factor_;
int buffer_size_;
void* resample_handle_;
std::vector<float> in_floats_;
std::vector<float> out_floats_;
std::vector<int16_t> out_int16s_;
DISALLOW_COPY_AND_ASSIGN(Resampler);
};
} // namespace speech_synthesis
#endif // SPEECH_CLIENT_SYNTHESIS_SERVICE_RESAMPLER_H_