00001 /* 00002 * SpanDSP - a series of DSP components for telephony 00003 * 00004 * time_scale.h - Time scaling for linear speech data 00005 * 00006 * Written by Steve Underwood <steveu@coppice.org> 00007 * 00008 * Copyright (C) 2004 Steve Underwood 00009 * 00010 * All rights reserved. 00011 * 00012 * This program is free software; you can redistribute it and/or modify 00013 * it under the terms of the GNU Lesser General Public License version 2.1, 00014 * as published by the Free Software Foundation. 00015 * 00016 * This program is distributed in the hope that it will be useful, 00017 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00018 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00019 * GNU Lesser General Public License for more details. 00020 * 00021 * You should have received a copy of the GNU Lesser General Public 00022 * License along with this program; if not, write to the Free Software 00023 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 00024 * 00025 * $Id: time_scale.h,v 1.20 2009/02/10 13:06:47 steveu Exp $ 00026 */ 00027 00028 #if !defined(_SPANDSP_TIME_SCALE_H_) 00029 #define _SPANDSP_TIME_SCALE_H_ 00030 00031 /*! \page time_scale_page Time scaling speech 00032 \section time_scale_page_sec_1 What does it do? 00033 The time scaling module allows speech files to be played back at a 00034 different speed from the speed at which they were recorded. If this 00035 were done by simply speeding up or slowing down replay, the pitch of 00036 the voice would change, and sound very odd. This module keeps the pitch 00037 of the voice at its original level. 00038 00039 The speed of the voice may be altered over a wide range. However, the practical 00040 useful rates are between about half normal speed and twice normal speed. 00041 00042 \section time_scale_page_sec_2 How does it work? 00043 The time scaling module is based on the Pointer Interval Controlled 00044 OverLap and Add (PICOLA) method, developed by Morita Naotaka. 00045 Mikio Ikeda has an excellent web page on this subject at 00046 http://keizai.yokkaichi-u.ac.jp/~ikeda/research/picola.html 00047 There is also working code there. This implementation uses 00048 exactly the same algorithms, but the code is a complete rewrite. 00049 Mikio's code batch processes files. This version works incrementally 00050 on streams, and allows multiple streams to be processed concurrently. 00051 00052 \section time_scale_page_sec_3 How do I used it? 00053 The output buffer must be big enough to hold the maximum number of samples which 00054 could result from the data in the input buffer, which is: 00055 00056 input_len*playout_rate + sample_rate/TIME_SCALE_MIN_PITCH + 1 00057 */ 00058 00059 /*! Audio time scaling descriptor. */ 00060 typedef struct time_scale_state_s time_scale_state_t; 00061 00062 #if defined(__cplusplus) 00063 extern "C" 00064 { 00065 #endif 00066 00067 /*! Initialise a time scale context. This must be called before the first 00068 use of the context, to initialise its contents. 00069 \brief Initialise a time scale context. 00070 \param s The time scale context. 00071 \param sample_rate The sample rate of the signal. 00072 \param playout_rate The ratio between the output speed and the input speed. 00073 \return A pointer to the context, or NULL if there was a problem. */ 00074 SPAN_DECLARE(time_scale_state_t *) time_scale_init(time_scale_state_t *s, int sample_rate, float playout_rate); 00075 00076 /*! \brief Release a time scale context. 00077 \param s The time scale context. 00078 \return 0 for OK, else -1. */ 00079 SPAN_DECLARE(int) time_scale_release(time_scale_state_t *s); 00080 00081 /*! \brief Free a time scale context. 00082 \param s The time scale context. 00083 \return 0 for OK, else -1. */ 00084 SPAN_DECLARE(int) time_scale_free(time_scale_state_t *s); 00085 00086 /*! Change the time scale rate. 00087 \brief Change the time scale rate. 00088 \param s The time scale context. 00089 \param playout_rate The ratio between the output speed and the input speed. 00090 \return 0 if changed OK, else -1. */ 00091 SPAN_DECLARE(int) time_scale_rate(time_scale_state_t *s, float playout_rate); 00092 00093 /*! Find the maximum possible samples which could result from scaling the specified 00094 number of input samples, at the current playback rate. 00095 \brief Find the maximum possible output samples. 00096 \param s The time scale context. 00097 \param input_len The number of input samples. 00098 \return The maximum possible output samples. */ 00099 SPAN_DECLARE(int) time_scale_max_output_len(time_scale_state_t *s, int input_len); 00100 00101 /*! Time scale a chunk of audio samples. 00102 \brief Time scale a chunk of audio samples. 00103 \param s The time scale context. 00104 \param out The output audio sample buffer. This must be large enough to accept 00105 the longest possible result from processing the input data. See the 00106 algorithm documentation for how the longest possible result may be calculated. 00107 \param in The input audio sample buffer. 00108 \param len The number of input samples. 00109 \return The number of output samples. 00110 */ 00111 SPAN_DECLARE(int) time_scale(time_scale_state_t *s, int16_t out[], int16_t in[], int len); 00112 00113 #if defined(__cplusplus) 00114 } 00115 #endif 00116 00117 #endif 00118 /*- End of file ------------------------------------------------------------*/