mirror of
https://github.com/cookiengineer/audacity
synced 2025-11-26 07:10:09 +01:00
Reverting r12850...hopefully
Never removed one before, but I'm pretty sure it is correct.
This commit is contained in:
@@ -1,118 +1,118 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>SoundTouch in Android</title>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=windows-1252">
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta name="author" content="Olli Parviainen">
|
||||
<meta name="description"
|
||||
content="Readme file for SoundTouch library Android compilation">
|
||||
<style> <!-- .normal { font-family: Arial }
|
||||
--></style>
|
||||
</head>
|
||||
<body class="normal">
|
||||
<hr>
|
||||
<h1>SoundTouch in Android</h1>
|
||||
<hr>
|
||||
<h2>Compiling SoundTouch for Android</h2>
|
||||
<p>SoundTouch source code package contains "Android-lib" example project that compiles SoundTouch
|
||||
source codes into Android native library, and gives an example of JNI interface
|
||||
for invoking
|
||||
the native SoundTouch routines from an Android application written in Java.</p>
|
||||
<p style="font-weight: 700">Software prerequisites:</p>
|
||||
<ul>
|
||||
<li>Android SDK environment for developing your own Android application. Visit the <a href="http://developer.android.com/index.html">Android developers' site</a>
|
||||
for more information about the Android SDK and developing Android applications.</li>
|
||||
<li>Android NDK compiler kit for compiling native library binaries. The Android NDK
|
||||
is <a href="http://developer.android.com/tools/sdk/ndk/index.html">
|
||||
available for download</a> at the Android developer tools site.</li>
|
||||
<li>In case you're working in Windows environment, install
|
||||
<a href="http://cygwin.com/install.html">
|
||||
Cygwin</a> to run the Android NDK/SDK compiler scripts</li>
|
||||
<li>Latest SoundTouch source code package available at <a href="http://soundtouch.surina.net/sourcecode.html">
|
||||
soundtouch.surina.net</a>.</li>
|
||||
</ul>
|
||||
<p><b>Hint: </b>As installing and configuring all the components for an Android SDK/NDK
|
||||
environment requires fair effort, it's good idea to create a dedicated Virtual
|
||||
Machine environment for the Android development environment installation.
|
||||
Having the Android developer environment setup in dedicated Virtual Machine
|
||||
allows keeping all these settings isolated from your other PC operations, and
|
||||
eases taking backup snapshots of your full development environment.</p>
|
||||
<p><b>Compiling</b></p>
|
||||
<p>
|
||||
To compile the SoundTouch library source codes into an Android native library,
|
||||
open Cygwin/bash shell, go to directory <b>"soundtouch/source/Android-lib/jni"</b> and invoke the NDK
|
||||
compiler with following command:</p>
|
||||
<pre> $NDK/ndk-build</pre>
|
||||
<p>This will build the ARMv5 and ARMv7 versions of SoundTouch library (including
|
||||
also the example JNI
|
||||
interface, see below) into the "libs" subdirectory.</p>
|
||||
<p>Notice that to allow Cygwin/bash to locate the NDK compile scripts, you
|
||||
need to define the location of the NDK installation defined in environment
|
||||
variable "NDK". That's easiest done by adding the NDK path definition at end of
|
||||
your <b>~/.bash_profile</b> file, for instance as follows:</p>
|
||||
<pre> NDK=/cygdrive/d/Android/android-ndk-r6</pre>
|
||||
<hr />
|
||||
<h2>
|
||||
Android floating-point performance considerations</h2>
|
||||
<p>
|
||||
Default build target for
|
||||
Android NDK is ARMv5 CPU generation, as that works in
|
||||
all ARM-based Android devices.<p>
|
||||
This has a pitfall though: For ideal sound quality SoundTouch should be compiled
|
||||
to use floating-point algorithms, however, all low-end Android devices do not
|
||||
have floating-point hardware in their CPUs, and hence the default ARMv5 compilation uses software-emulation for floating-point calculations instead of
|
||||
hardware floating-point to allow running the binary executables also in low-end devices.<p>
|
||||
The floating point software-emulation is however several tens of times slower
|
||||
than real hardware-level floating-point calculations, making
|
||||
floating-point-intensive applications such as SoundTouch infeasible with low-end
|
||||
devices.<p>
|
||||
As workaround, the SoundTouch Android compilation builds two separate versions
|
||||
of the library:<ul>
|
||||
<li>ARMv5 version that compiles SoundTouch using integer algorithm version. The integer
|
||||
algorithm version compromises the sound quality but provides good performance also
|
||||
with low-end
|
||||
devices without hardware floating-point support in the CPU level.</li>
|
||||
<li>ARMv7 version that compiles SoundTouch using hardware floating-point algorithms.
|
||||
These algorithms provide ideal sound quality yet do not work in simpler CPU
|
||||
models.</li>
|
||||
</ul>
|
||||
<p>
|
||||
These two library compilations are already defined in file "<b>jni/Application.mk</b>"
|
||||
so that these two separate library targets are automatically built under the "<b>libs</b>"
|
||||
directory. As far as you include both these compiled library versions into your
|
||||
application delivery, the Android devices can automatically select the right
|
||||
library version based on the available device's capabilities.<p>
|
||||
Please yet be aware that depending on capabilities of the Android devices you
|
||||
will need to provide the SoundTouch routines with samples in either integer or
|
||||
floating-point format, so build your interface routines to take this into
|
||||
account.<hr />
|
||||
<h2>
|
||||
Calling SoundTouch native routines from Android application</h2>
|
||||
<p>The NDK tools build the SoundTouch c++ routines into a native binary library, while
|
||||
Android applications are written in Java language. To call the SoundTouch and other c/c++
|
||||
routines from an Android java application code, you'll need to use Java Native
|
||||
Interface (JNI).</p>
|
||||
<p>
|
||||
The SoundTouch source code package provides source code example how to
|
||||
use JNI to call native c++ routines from a Java class through the following
|
||||
source code file pair:<ul>
|
||||
<li><b>Android-lib/jni/soundtouch-jni.cpp</b>: This file contains c/c++ routine that
|
||||
calls SoundTouch library routine to return the library version string to the main
|
||||
Android application. The NDK compiles this file along with the SoundTouch
|
||||
routines into the native binary library.</li>
|
||||
<li><b>Android-lib/src/net/surina/soundtouch/SoundTouch.java</b>: This file provides
|
||||
a Java interface class to load the native library and to invoke the native routine implemented in
|
||||
the file <b>soundtouch-jni.cpp</b></li>
|
||||
</ul>
|
||||
<p>
|
||||
Feel free to examine and extend the provided cpp/java source code example file pair to
|
||||
implement and integrate the desired SoundTouch library capabilities into your Android application.</p>
|
||||
<hr />
|
||||
<p style="text-align: center"><i>Copyright © Olli Parviainen</i></p>
|
||||
<!--
|
||||
$Id: README-SoundTouch-Android.html 165 2012-12-28 19:55:23Z oparviai $
|
||||
-->
|
||||
</body>
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||||
<html>
|
||||
<head>
|
||||
<title>SoundTouch in Android</title>
|
||||
<meta http-equiv="Content-Type"
|
||||
content="text/html; charset=windows-1252">
|
||||
<meta http-equiv="Content-Language" content="en-us">
|
||||
<meta name="author" content="Olli Parviainen">
|
||||
<meta name="description"
|
||||
content="Readme file for SoundTouch library Android compilation">
|
||||
<style> <!-- .normal { font-family: Arial }
|
||||
--></style>
|
||||
</head>
|
||||
<body class="normal">
|
||||
<hr>
|
||||
<h1>SoundTouch in Android</h1>
|
||||
<hr>
|
||||
<h2>Compiling SoundTouch for Android</h2>
|
||||
<p>SoundTouch source code package contains "Android-lib" example project that compiles SoundTouch
|
||||
source codes into Android native library, and gives an example of JNI interface
|
||||
for invoking
|
||||
the native SoundTouch routines from an Android application written in Java.</p>
|
||||
<p style="font-weight: 700">Software prerequisites:</p>
|
||||
<ul>
|
||||
<li>Android SDK environment for developing your own Android application. Visit the <a href="http://developer.android.com/index.html">Android developers' site</a>
|
||||
for more information about the Android SDK and developing Android applications.</li>
|
||||
<li>Android NDK compiler kit for compiling native library binaries. The Android NDK
|
||||
is <a href="http://developer.android.com/tools/sdk/ndk/index.html">
|
||||
available for download</a> at the Android developer tools site.</li>
|
||||
<li>In case you're working in Windows environment, install
|
||||
<a href="http://cygwin.com/install.html">
|
||||
Cygwin</a> to run the Android NDK/SDK compiler scripts</li>
|
||||
<li>Latest SoundTouch source code package available at <a href="http://soundtouch.surina.net/sourcecode.html">
|
||||
soundtouch.surina.net</a>.</li>
|
||||
</ul>
|
||||
<p><b>Hint: </b>As installing and configuring all the components for an Android SDK/NDK
|
||||
environment requires fair effort, it's good idea to create a dedicated Virtual
|
||||
Machine environment for the Android development environment installation.
|
||||
Having the Android developer environment setup in dedicated Virtual Machine
|
||||
allows keeping all these settings isolated from your other PC operations, and
|
||||
eases taking backup snapshots of your full development environment.</p>
|
||||
<p><b>Compiling</b></p>
|
||||
<p>
|
||||
To compile the SoundTouch library source codes into an Android native library,
|
||||
open Cygwin/bash shell, go to directory <b>"soundtouch/source/Android-lib/jni"</b> and invoke the NDK
|
||||
compiler with following command:</p>
|
||||
<pre> $NDK/ndk-build</pre>
|
||||
<p>This will build the ARMv5 and ARMv7 versions of SoundTouch library (including
|
||||
also the example JNI
|
||||
interface, see below) into the "libs" subdirectory.</p>
|
||||
<p>Notice that to allow Cygwin/bash to locate the NDK compile scripts, you
|
||||
need to define the location of the NDK installation defined in environment
|
||||
variable "NDK". That's easiest done by adding the NDK path definition at end of
|
||||
your <b>~/.bash_profile</b> file, for instance as follows:</p>
|
||||
<pre> NDK=/cygdrive/d/Android/android-ndk-r6</pre>
|
||||
<hr />
|
||||
<h2>
|
||||
Android floating-point performance considerations</h2>
|
||||
<p>
|
||||
Default build target for
|
||||
Android NDK is ARMv5 CPU generation, as that works in
|
||||
all ARM-based Android devices.<p>
|
||||
This has a pitfall though: For ideal sound quality SoundTouch should be compiled
|
||||
to use floating-point algorithms, however, all low-end Android devices do not
|
||||
have floating-point hardware in their CPUs, and hence the default ARMv5 compilation uses software-emulation for floating-point calculations instead of
|
||||
hardware floating-point to allow running the binary executables also in low-end devices.<p>
|
||||
The floating point software-emulation is however several tens of times slower
|
||||
than real hardware-level floating-point calculations, making
|
||||
floating-point-intensive applications such as SoundTouch infeasible with low-end
|
||||
devices.<p>
|
||||
As workaround, the SoundTouch Android compilation builds two separate versions
|
||||
of the library:<ul>
|
||||
<li>ARMv5 version that compiles SoundTouch using integer algorithm version. The integer
|
||||
algorithm version compromises the sound quality but provides good performance also
|
||||
with low-end
|
||||
devices without hardware floating-point support in the CPU level.</li>
|
||||
<li>ARMv7 version that compiles SoundTouch using hardware floating-point algorithms.
|
||||
These algorithms provide ideal sound quality yet do not work in simpler CPU
|
||||
models.</li>
|
||||
</ul>
|
||||
<p>
|
||||
These two library compilations are already defined in file "<b>jni/Application.mk</b>"
|
||||
so that these two separate library targets are automatically built under the "<b>libs</b>"
|
||||
directory. As far as you include both these compiled library versions into your
|
||||
application delivery, the Android devices can automatically select the right
|
||||
library version based on the available device's capabilities.<p>
|
||||
Please yet be aware that depending on capabilities of the Android devices you
|
||||
will need to provide the SoundTouch routines with samples in either integer or
|
||||
floating-point format, so build your interface routines to take this into
|
||||
account.<hr />
|
||||
<h2>
|
||||
Calling SoundTouch native routines from Android application</h2>
|
||||
<p>The NDK tools build the SoundTouch c++ routines into a native binary library, while
|
||||
Android applications are written in Java language. To call the SoundTouch and other c/c++
|
||||
routines from an Android java application code, you'll need to use Java Native
|
||||
Interface (JNI).</p>
|
||||
<p>
|
||||
The SoundTouch source code package provides source code example how to
|
||||
use JNI to call native c++ routines from a Java class through the following
|
||||
source code file pair:<ul>
|
||||
<li><b>Android-lib/jni/soundtouch-jni.cpp</b>: This file contains c/c++ routine that
|
||||
calls SoundTouch library routine to return the library version string to the main
|
||||
Android application. The NDK compiles this file along with the SoundTouch
|
||||
routines into the native binary library.</li>
|
||||
<li><b>Android-lib/src/net/surina/soundtouch/SoundTouch.java</b>: This file provides
|
||||
a Java interface class to load the native library and to invoke the native routine implemented in
|
||||
the file <b>soundtouch-jni.cpp</b></li>
|
||||
</ul>
|
||||
<p>
|
||||
Feel free to examine and extend the provided cpp/java source code example file pair to
|
||||
implement and integrate the desired SoundTouch library capabilities into your Android application.</p>
|
||||
<hr />
|
||||
<p style="text-align: center"><i>Copyright © Olli Parviainen</i></p>
|
||||
<!--
|
||||
$Id: README-SoundTouch-Android.html 165 2012-12-28 19:55:23Z oparviai $
|
||||
-->
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,43 +1,43 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Example Interface class for SoundTouch native compilation
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// WWW : http://www.surina.net
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: soundtouch-jni.cpp 165 2012-12-28 19:55:23Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
//#include <string.h>
|
||||
//#include <stdio.h>
|
||||
//#include <dlfcn.h>
|
||||
|
||||
#include "../../../include/SoundTouch.h"
|
||||
//#include "TimeShiftEffect.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Example Interface class for SoundTouch native compilation
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// WWW : http://www.surina.net
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: soundtouch-jni.cpp 165 2012-12-28 19:55:23Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <jni.h>
|
||||
#include <android/log.h>
|
||||
//#include <string.h>
|
||||
//#include <stdio.h>
|
||||
//#include <dlfcn.h>
|
||||
|
||||
#include "../../../include/SoundTouch.h"
|
||||
//#include "TimeShiftEffect.h"
|
||||
|
||||
#define LOGV(...) __android_log_print((int)ANDROID_LOG_INFO, "SOUNDTOUCH", __VA_ARGS__)
|
||||
//#define LOGV(...)
|
||||
|
||||
|
||||
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
extern "C" DLL_PUBLIC jstring Java_net_surina_soundtouch_getVersionString(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
const char *verStr;
|
||||
|
||||
LOGV("JNI call soundtouch.getVersionString");
|
||||
|
||||
// Call example SoundTouch routine
|
||||
verStr = SoundTouch::getVersionString();
|
||||
|
||||
// return version as string
|
||||
return env->NewStringUTF(verStr);
|
||||
}
|
||||
|
||||
|
||||
#define DLL_PUBLIC __attribute__ ((visibility ("default")))
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
extern "C" DLL_PUBLIC jstring Java_net_surina_soundtouch_getVersionString(JNIEnv *env, jobject thiz)
|
||||
{
|
||||
const char *verStr;
|
||||
|
||||
LOGV("JNI call soundtouch.getVersionString");
|
||||
|
||||
// Call example SoundTouch routine
|
||||
verStr = SoundTouch::getVersionString();
|
||||
|
||||
// return version as string
|
||||
return env->NewStringUTF(verStr);
|
||||
}
|
||||
|
||||
@@ -1,29 +1,29 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Example class that invokes native SoundTouch routines through the JNI
|
||||
/// interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// WWW : http://www.surina.net
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouch.java 165 2012-12-28 19:55:23Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package net.surina.soundtouch;
|
||||
|
||||
public final class SoundTouch
|
||||
{
|
||||
// Native interface function that returns SoundTouch version string.
|
||||
// This invokes the native c++ routine defined in "soundtouch-jni.cpp".
|
||||
public native final String getVersionString();
|
||||
|
||||
// Load the native library upon startup
|
||||
static
|
||||
{
|
||||
System.loadLibrary("soundtouch");
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Example class that invokes native SoundTouch routines through the JNI
|
||||
/// interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// WWW : http://www.surina.net
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouch.java 165 2012-12-28 19:55:23Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package net.surina.soundtouch;
|
||||
|
||||
public final class SoundTouch
|
||||
{
|
||||
// Native interface function that returns SoundTouch version string.
|
||||
// This invokes the native c++ routine defined in "soundtouch-jni.cpp".
|
||||
public native final String getVersionString();
|
||||
|
||||
// Load the native library upon startup
|
||||
static
|
||||
{
|
||||
System.loadLibrary("soundtouch");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 38 2008-12-25 17:00:23Z oparviai $
|
||||
##
|
||||
## Copyright (C) 2003 - David W. Durham
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
SUBDIRS=SoundTouch SoundStretch
|
||||
|
||||
# set to something if you want other stuff to be included in the distribution tarball
|
||||
#EXTRA_DIST=
|
||||
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 38 2008-12-25 17:00:23Z oparviai $
|
||||
##
|
||||
## Copyright (C) 2003 - David W. Durham
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
SUBDIRS=SoundTouch SoundStretch
|
||||
|
||||
# set to something if you want other stuff to be included in the distribution tarball
|
||||
#EXTRA_DIST=
|
||||
|
||||
|
||||
@@ -1,54 +1,54 @@
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 128 2011-07-17 10:59:56Z oparviai $
|
||||
##
|
||||
## Copyright (C) 2003 - David W. Durham
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
|
||||
## bin_PROGRAMS is the macro that tells automake the name of the programs to
|
||||
## install in the bin directory (/usr/local/bin) by default. By setting
|
||||
## --prefix= at configure time the user can change this (eg: ./configure
|
||||
## --prefix=/usr will install soundstretch under /usr/bin/soundstretch )
|
||||
bin_PROGRAMS=soundstretch
|
||||
|
||||
noinst_HEADERS=RunParameters.h WavFile.h
|
||||
|
||||
# extra files to include in distrubution tarball
|
||||
EXTRA_DIST=soundstretch.dsp soundstretch.dsw soundstretch.sln soundstretch.vcproj
|
||||
|
||||
## for every name listed under bin_PROGRAMS, you have a <prog>_SOURCES. This lists
|
||||
## all the sources in the current directory that are used to build soundstretch.
|
||||
soundstretch_SOURCES=main.cpp RunParameters.cpp WavFile.cpp
|
||||
|
||||
## soundstretch_LDADD is a list of extras to pass at link time. All the objects
|
||||
## created by the above soundstretch_SOURCES are automatically linked in, so here I
|
||||
## list object files from other directories as well as flags passed to the
|
||||
## linker.
|
||||
soundstretch_LDADD=../SoundTouch/libSoundTouch.la -lm
|
||||
|
||||
## linker flags.
|
||||
# OP 2011-7-17 Linker flags disabled to prevent stripping symbols by default
|
||||
# soundstretch_LDFLAGS=-s
|
||||
|
||||
## additional compiler flags
|
||||
soundstretch_CXXFLAGS=-O3
|
||||
|
||||
#clean-local:
|
||||
# -rm -f additional-files-to-remove-on-make-clean
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 128 2011-07-17 10:59:56Z oparviai $
|
||||
##
|
||||
## Copyright (C) 2003 - David W. Durham
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
|
||||
## bin_PROGRAMS is the macro that tells automake the name of the programs to
|
||||
## install in the bin directory (/usr/local/bin) by default. By setting
|
||||
## --prefix= at configure time the user can change this (eg: ./configure
|
||||
## --prefix=/usr will install soundstretch under /usr/bin/soundstretch )
|
||||
bin_PROGRAMS=soundstretch
|
||||
|
||||
noinst_HEADERS=RunParameters.h WavFile.h
|
||||
|
||||
# extra files to include in distrubution tarball
|
||||
EXTRA_DIST=soundstretch.dsp soundstretch.dsw soundstretch.sln soundstretch.vcproj
|
||||
|
||||
## for every name listed under bin_PROGRAMS, you have a <prog>_SOURCES. This lists
|
||||
## all the sources in the current directory that are used to build soundstretch.
|
||||
soundstretch_SOURCES=main.cpp RunParameters.cpp WavFile.cpp
|
||||
|
||||
## soundstretch_LDADD is a list of extras to pass at link time. All the objects
|
||||
## created by the above soundstretch_SOURCES are automatically linked in, so here I
|
||||
## list object files from other directories as well as flags passed to the
|
||||
## linker.
|
||||
soundstretch_LDADD=../SoundTouch/libSoundTouch.la -lm
|
||||
|
||||
## linker flags.
|
||||
# OP 2011-7-17 Linker flags disabled to prevent stripping symbols by default
|
||||
# soundstretch_LDFLAGS=-s
|
||||
|
||||
## additional compiler flags
|
||||
soundstretch_CXXFLAGS=-O3
|
||||
|
||||
#clean-local:
|
||||
# -rm -f additional-files-to-remove-on-make-clean
|
||||
|
||||
@@ -1,301 +1,301 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// A class for parsing the 'soundstretch' application command line parameters
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2011-09-02 21:56:11 +0300 (Fri, 02 Sep 2011) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: RunParameters.cpp 131 2011-09-02 18:56:11Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "RunParameters.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Program usage instructions
|
||||
|
||||
static const char licenseText[] =
|
||||
" LICENSE:\n"
|
||||
" ========\n"
|
||||
" \n"
|
||||
" SoundTouch sound processing library\n"
|
||||
" Copyright (c) Olli Parviainen\n"
|
||||
" \n"
|
||||
" This library is free software; you can redistribute it and/or\n"
|
||||
" modify it under the terms of the GNU Lesser General Public\n"
|
||||
" License version 2.1 as published by the Free Software Foundation.\n"
|
||||
" \n"
|
||||
" This library is distributed in the hope that it will be useful,\n"
|
||||
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
|
||||
" Lesser General Public License for more details.\n"
|
||||
" \n"
|
||||
" You should have received a copy of the GNU Lesser General Public\n"
|
||||
" License along with this library; if not, write to the Free Software\n"
|
||||
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
|
||||
" \n"
|
||||
"This application is distributed with full source codes; however, if you\n"
|
||||
"didn't receive them, please visit the author's homepage (see the link above).";
|
||||
|
||||
static const char whatText[] =
|
||||
"This application processes WAV audio files by modifying the sound tempo,\n"
|
||||
"pitch and playback rate properties independently from each other.\n"
|
||||
"\n";
|
||||
|
||||
static const char usage[] =
|
||||
"Usage :\n"
|
||||
" soundstretch infilename outfilename [switches]\n"
|
||||
"\n"
|
||||
"To use standard input/output pipes, give 'stdin' and 'stdout' as filenames.\n"
|
||||
"\n"
|
||||
"Available switches are:\n"
|
||||
" -tempo=n : Change sound tempo by n percents (n=-95..+5000 %)\n"
|
||||
" -pitch=n : Change sound pitch by n semitones (n=-60..+60 semitones)\n"
|
||||
" -rate=n : Change sound rate by n percents (n=-95..+5000 %)\n"
|
||||
" -bpm=n : Detect the BPM rate of sound and adjust tempo to meet 'n' BPMs.\n"
|
||||
" If '=n' is omitted, just detects the BPM rate.\n"
|
||||
" -quick : Use quicker tempo change algorithm (gain speed, lose quality)\n"
|
||||
" -naa : Don't use anti-alias filtering (gain speed, lose quality)\n"
|
||||
" -speech : Tune algorithm for speech processing (default is for music)\n"
|
||||
" -license : Display the program license text (LGPL)\n";
|
||||
|
||||
|
||||
// Converts a char into lower case
|
||||
static int _toLowerCase(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
c += 'a' - 'A';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
RunParameters::RunParameters(const int nParams, const char * const paramStr[])
|
||||
{
|
||||
int i;
|
||||
int nFirstParam;
|
||||
|
||||
if (nParams < 3)
|
||||
{
|
||||
// Too few parameters
|
||||
if (nParams > 1 && paramStr[1][0] == '-' &&
|
||||
_toLowerCase(paramStr[1][1]) == 'l')
|
||||
{
|
||||
// '-license' switch
|
||||
throwLicense();
|
||||
}
|
||||
string msg = whatText;
|
||||
msg += usage;
|
||||
ST_THROW_RT_ERROR(msg.c_str());
|
||||
}
|
||||
|
||||
inFileName = NULL;
|
||||
outFileName = NULL;
|
||||
tempoDelta = 0;
|
||||
pitchDelta = 0;
|
||||
rateDelta = 0;
|
||||
quick = 0;
|
||||
noAntiAlias = 0;
|
||||
goalBPM = 0;
|
||||
speech = FALSE;
|
||||
detectBPM = FALSE;
|
||||
|
||||
// Get input & output file names
|
||||
inFileName = (char*)paramStr[1];
|
||||
outFileName = (char*)paramStr[2];
|
||||
|
||||
if (outFileName[0] == '-')
|
||||
{
|
||||
// no outputfile name was given but parameters
|
||||
outFileName = NULL;
|
||||
nFirstParam = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
nFirstParam = 3;
|
||||
}
|
||||
|
||||
// parse switch parameters
|
||||
for (i = nFirstParam; i < nParams; i ++)
|
||||
{
|
||||
parseSwitchParam(paramStr[i]);
|
||||
}
|
||||
|
||||
checkLimits();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Checks parameter limits
|
||||
void RunParameters::checkLimits()
|
||||
{
|
||||
if (tempoDelta < -95.0f)
|
||||
{
|
||||
tempoDelta = -95.0f;
|
||||
}
|
||||
else if (tempoDelta > 5000.0f)
|
||||
{
|
||||
tempoDelta = 5000.0f;
|
||||
}
|
||||
|
||||
if (pitchDelta < -60.0f)
|
||||
{
|
||||
pitchDelta = -60.0f;
|
||||
}
|
||||
else if (pitchDelta > 60.0f)
|
||||
{
|
||||
pitchDelta = 60.0f;
|
||||
}
|
||||
|
||||
if (rateDelta < -95.0f)
|
||||
{
|
||||
rateDelta = -95.0f;
|
||||
}
|
||||
else if (rateDelta > 5000.0f)
|
||||
{
|
||||
rateDelta = 5000.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Unknown switch parameter -- throws an exception with an error message
|
||||
void RunParameters::throwIllegalParamExp(const string &str) const
|
||||
{
|
||||
string msg = "ERROR : Illegal parameter \"";
|
||||
msg += str;
|
||||
msg += "\".\n\n";
|
||||
msg += usage;
|
||||
ST_THROW_RT_ERROR(msg.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RunParameters::throwLicense() const
|
||||
{
|
||||
ST_THROW_RT_ERROR(licenseText);
|
||||
}
|
||||
|
||||
|
||||
float RunParameters::parseSwitchValue(const string &str) const
|
||||
{
|
||||
int pos;
|
||||
|
||||
pos = (int)str.find_first_of('=');
|
||||
if (pos < 0)
|
||||
{
|
||||
// '=' missing
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
|
||||
// Read numerical parameter value after '='
|
||||
return (float)atof(str.substr(pos + 1).c_str());
|
||||
}
|
||||
|
||||
|
||||
// Interprets a single switch parameter string of format "-switch=xx"
|
||||
// Valid switches are "-tempo=xx", "-pitch=xx" and "-rate=xx". Stores
|
||||
// switch values into 'params' structure.
|
||||
void RunParameters::parseSwitchParam(const string &str)
|
||||
{
|
||||
int upS;
|
||||
|
||||
if (str[0] != '-')
|
||||
{
|
||||
// leading hyphen missing => not a valid parameter
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
|
||||
// Take the first character of switch name & change to lower case
|
||||
upS = _toLowerCase(str[1]);
|
||||
|
||||
// interpret the switch name & operate accordingly
|
||||
switch (upS)
|
||||
{
|
||||
case 't' :
|
||||
// switch '-tempo=xx'
|
||||
tempoDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
// switch '-pitch=xx'
|
||||
pitchDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
// switch '-rate=xx'
|
||||
rateDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'b' :
|
||||
// switch '-bpm=xx'
|
||||
detectBPM = TRUE;
|
||||
try
|
||||
{
|
||||
goalBPM = parseSwitchValue(str);
|
||||
}
|
||||
catch (const runtime_error)
|
||||
{
|
||||
// illegal or missing bpm value => just calculate bpm
|
||||
goalBPM = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'q' :
|
||||
// switch '-quick'
|
||||
quick = 1;
|
||||
break;
|
||||
|
||||
case 'n' :
|
||||
// switch '-naa'
|
||||
noAntiAlias = 1;
|
||||
break;
|
||||
|
||||
case 'l' :
|
||||
// switch '-license'
|
||||
throwLicense();
|
||||
break;
|
||||
|
||||
case 's' :
|
||||
// switch '-speech'
|
||||
speech = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
// unknown switch
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// A class for parsing the 'soundstretch' application command line parameters
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2011-09-02 21:56:11 +0300 (Fri, 02 Sep 2011) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: RunParameters.cpp 131 2011-09-02 18:56:11Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <string>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "RunParameters.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Program usage instructions
|
||||
|
||||
static const char licenseText[] =
|
||||
" LICENSE:\n"
|
||||
" ========\n"
|
||||
" \n"
|
||||
" SoundTouch sound processing library\n"
|
||||
" Copyright (c) Olli Parviainen\n"
|
||||
" \n"
|
||||
" This library is free software; you can redistribute it and/or\n"
|
||||
" modify it under the terms of the GNU Lesser General Public\n"
|
||||
" License version 2.1 as published by the Free Software Foundation.\n"
|
||||
" \n"
|
||||
" This library is distributed in the hope that it will be useful,\n"
|
||||
" but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
|
||||
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n"
|
||||
" Lesser General Public License for more details.\n"
|
||||
" \n"
|
||||
" You should have received a copy of the GNU Lesser General Public\n"
|
||||
" License along with this library; if not, write to the Free Software\n"
|
||||
" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\n"
|
||||
" \n"
|
||||
"This application is distributed with full source codes; however, if you\n"
|
||||
"didn't receive them, please visit the author's homepage (see the link above).";
|
||||
|
||||
static const char whatText[] =
|
||||
"This application processes WAV audio files by modifying the sound tempo,\n"
|
||||
"pitch and playback rate properties independently from each other.\n"
|
||||
"\n";
|
||||
|
||||
static const char usage[] =
|
||||
"Usage :\n"
|
||||
" soundstretch infilename outfilename [switches]\n"
|
||||
"\n"
|
||||
"To use standard input/output pipes, give 'stdin' and 'stdout' as filenames.\n"
|
||||
"\n"
|
||||
"Available switches are:\n"
|
||||
" -tempo=n : Change sound tempo by n percents (n=-95..+5000 %)\n"
|
||||
" -pitch=n : Change sound pitch by n semitones (n=-60..+60 semitones)\n"
|
||||
" -rate=n : Change sound rate by n percents (n=-95..+5000 %)\n"
|
||||
" -bpm=n : Detect the BPM rate of sound and adjust tempo to meet 'n' BPMs.\n"
|
||||
" If '=n' is omitted, just detects the BPM rate.\n"
|
||||
" -quick : Use quicker tempo change algorithm (gain speed, lose quality)\n"
|
||||
" -naa : Don't use anti-alias filtering (gain speed, lose quality)\n"
|
||||
" -speech : Tune algorithm for speech processing (default is for music)\n"
|
||||
" -license : Display the program license text (LGPL)\n";
|
||||
|
||||
|
||||
// Converts a char into lower case
|
||||
static int _toLowerCase(int c)
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
{
|
||||
c += 'a' - 'A';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
// Constructor
|
||||
RunParameters::RunParameters(const int nParams, const char * const paramStr[])
|
||||
{
|
||||
int i;
|
||||
int nFirstParam;
|
||||
|
||||
if (nParams < 3)
|
||||
{
|
||||
// Too few parameters
|
||||
if (nParams > 1 && paramStr[1][0] == '-' &&
|
||||
_toLowerCase(paramStr[1][1]) == 'l')
|
||||
{
|
||||
// '-license' switch
|
||||
throwLicense();
|
||||
}
|
||||
string msg = whatText;
|
||||
msg += usage;
|
||||
ST_THROW_RT_ERROR(msg.c_str());
|
||||
}
|
||||
|
||||
inFileName = NULL;
|
||||
outFileName = NULL;
|
||||
tempoDelta = 0;
|
||||
pitchDelta = 0;
|
||||
rateDelta = 0;
|
||||
quick = 0;
|
||||
noAntiAlias = 0;
|
||||
goalBPM = 0;
|
||||
speech = FALSE;
|
||||
detectBPM = FALSE;
|
||||
|
||||
// Get input & output file names
|
||||
inFileName = (char*)paramStr[1];
|
||||
outFileName = (char*)paramStr[2];
|
||||
|
||||
if (outFileName[0] == '-')
|
||||
{
|
||||
// no outputfile name was given but parameters
|
||||
outFileName = NULL;
|
||||
nFirstParam = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
nFirstParam = 3;
|
||||
}
|
||||
|
||||
// parse switch parameters
|
||||
for (i = nFirstParam; i < nParams; i ++)
|
||||
{
|
||||
parseSwitchParam(paramStr[i]);
|
||||
}
|
||||
|
||||
checkLimits();
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Checks parameter limits
|
||||
void RunParameters::checkLimits()
|
||||
{
|
||||
if (tempoDelta < -95.0f)
|
||||
{
|
||||
tempoDelta = -95.0f;
|
||||
}
|
||||
else if (tempoDelta > 5000.0f)
|
||||
{
|
||||
tempoDelta = 5000.0f;
|
||||
}
|
||||
|
||||
if (pitchDelta < -60.0f)
|
||||
{
|
||||
pitchDelta = -60.0f;
|
||||
}
|
||||
else if (pitchDelta > 60.0f)
|
||||
{
|
||||
pitchDelta = 60.0f;
|
||||
}
|
||||
|
||||
if (rateDelta < -95.0f)
|
||||
{
|
||||
rateDelta = -95.0f;
|
||||
}
|
||||
else if (rateDelta > 5000.0f)
|
||||
{
|
||||
rateDelta = 5000.0f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Unknown switch parameter -- throws an exception with an error message
|
||||
void RunParameters::throwIllegalParamExp(const string &str) const
|
||||
{
|
||||
string msg = "ERROR : Illegal parameter \"";
|
||||
msg += str;
|
||||
msg += "\".\n\n";
|
||||
msg += usage;
|
||||
ST_THROW_RT_ERROR(msg.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RunParameters::throwLicense() const
|
||||
{
|
||||
ST_THROW_RT_ERROR(licenseText);
|
||||
}
|
||||
|
||||
|
||||
float RunParameters::parseSwitchValue(const string &str) const
|
||||
{
|
||||
int pos;
|
||||
|
||||
pos = (int)str.find_first_of('=');
|
||||
if (pos < 0)
|
||||
{
|
||||
// '=' missing
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
|
||||
// Read numerical parameter value after '='
|
||||
return (float)atof(str.substr(pos + 1).c_str());
|
||||
}
|
||||
|
||||
|
||||
// Interprets a single switch parameter string of format "-switch=xx"
|
||||
// Valid switches are "-tempo=xx", "-pitch=xx" and "-rate=xx". Stores
|
||||
// switch values into 'params' structure.
|
||||
void RunParameters::parseSwitchParam(const string &str)
|
||||
{
|
||||
int upS;
|
||||
|
||||
if (str[0] != '-')
|
||||
{
|
||||
// leading hyphen missing => not a valid parameter
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
|
||||
// Take the first character of switch name & change to lower case
|
||||
upS = _toLowerCase(str[1]);
|
||||
|
||||
// interpret the switch name & operate accordingly
|
||||
switch (upS)
|
||||
{
|
||||
case 't' :
|
||||
// switch '-tempo=xx'
|
||||
tempoDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'p' :
|
||||
// switch '-pitch=xx'
|
||||
pitchDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'r' :
|
||||
// switch '-rate=xx'
|
||||
rateDelta = parseSwitchValue(str);
|
||||
break;
|
||||
|
||||
case 'b' :
|
||||
// switch '-bpm=xx'
|
||||
detectBPM = TRUE;
|
||||
try
|
||||
{
|
||||
goalBPM = parseSwitchValue(str);
|
||||
}
|
||||
catch (const runtime_error)
|
||||
{
|
||||
// illegal or missing bpm value => just calculate bpm
|
||||
goalBPM = 0;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'q' :
|
||||
// switch '-quick'
|
||||
quick = 1;
|
||||
break;
|
||||
|
||||
case 'n' :
|
||||
// switch '-naa'
|
||||
noAntiAlias = 1;
|
||||
break;
|
||||
|
||||
case 'l' :
|
||||
// switch '-license'
|
||||
throwLicense();
|
||||
break;
|
||||
|
||||
case 's' :
|
||||
// switch '-speech'
|
||||
speech = TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
// unknown switch
|
||||
throwIllegalParamExp(str);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,72 +1,72 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// A class for parsing the 'soundstretch' application command line parameters
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2009-05-17 19:48:30 +0300 (Sun, 17 May 2009) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: RunParameters.h 72 2009-05-17 16:48:30Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef RUNPARAMETERS_H
|
||||
#define RUNPARAMETERS_H
|
||||
|
||||
#include "STTypes.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/// Parses command line parameters into program parameters
|
||||
class RunParameters
|
||||
{
|
||||
private:
|
||||
void throwIllegalParamExp(const string &str) const;
|
||||
void throwLicense() const;
|
||||
void parseSwitchParam(const string &str);
|
||||
void checkLimits();
|
||||
float parseSwitchValue(const string &str) const;
|
||||
|
||||
public:
|
||||
char *inFileName;
|
||||
char *outFileName;
|
||||
float tempoDelta;
|
||||
float pitchDelta;
|
||||
float rateDelta;
|
||||
int quick;
|
||||
int noAntiAlias;
|
||||
float goalBPM;
|
||||
BOOL detectBPM;
|
||||
BOOL speech;
|
||||
|
||||
RunParameters(const int nParams, const char * const paramStr[]);
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// A class for parsing the 'soundstretch' application command line parameters
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2009-05-17 19:48:30 +0300 (Sun, 17 May 2009) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: RunParameters.h 72 2009-05-17 16:48:30Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef RUNPARAMETERS_H
|
||||
#define RUNPARAMETERS_H
|
||||
|
||||
#include "STTypes.h"
|
||||
#include <string>
|
||||
|
||||
using namespace std;
|
||||
|
||||
/// Parses command line parameters into program parameters
|
||||
class RunParameters
|
||||
{
|
||||
private:
|
||||
void throwIllegalParamExp(const string &str) const;
|
||||
void throwLicense() const;
|
||||
void parseSwitchParam(const string &str);
|
||||
void checkLimits();
|
||||
float parseSwitchValue(const string &str) const;
|
||||
|
||||
public:
|
||||
char *inFileName;
|
||||
char *outFileName;
|
||||
float tempoDelta;
|
||||
float pitchDelta;
|
||||
float rateDelta;
|
||||
int quick;
|
||||
int noAntiAlias;
|
||||
float goalBPM;
|
||||
BOOL detectBPM;
|
||||
BOOL speech;
|
||||
|
||||
RunParameters(const int nParams, const char * const paramStr[]);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,276 +1,276 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Classes for easy reading & writing of WAV sound files.
|
||||
///
|
||||
/// For big-endian CPU, define BIG_ENDIAN during compile-time to correctly
|
||||
/// parse the WAV files with such processors.
|
||||
///
|
||||
/// Admittingly, more complete WAV reader routines may exist in public domain, but
|
||||
/// the reason for 'yet another' one is that those generic WAV reader libraries are
|
||||
/// exhaustingly large and cumbersome! Wanted to have something simpler here, i.e.
|
||||
/// something that's not already larger than rest of the SoundTouch/SoundStretch program...
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-09-01 10:57:22 +0300 (Sat, 01 Sep 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: WavFile.h 153 2012-09-01 07:57:22Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef WAVFILE_H
|
||||
#define WAVFILE_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef uint
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
|
||||
/// WAV audio file 'riff' section header
|
||||
typedef struct
|
||||
{
|
||||
char riff_char[4];
|
||||
int package_len;
|
||||
char wave[4];
|
||||
} WavRiff;
|
||||
|
||||
/// WAV audio file 'format' section header
|
||||
typedef struct
|
||||
{
|
||||
char fmt[4];
|
||||
int format_len;
|
||||
short fixed;
|
||||
short channel_number;
|
||||
int sample_rate;
|
||||
int byte_rate;
|
||||
short byte_per_sample;
|
||||
short bits_per_sample;
|
||||
} WavFormat;
|
||||
|
||||
/// WAV audio file 'data' section header
|
||||
typedef struct
|
||||
{
|
||||
char data_field[4];
|
||||
uint data_len;
|
||||
} WavData;
|
||||
|
||||
|
||||
/// WAV audio file header
|
||||
typedef struct
|
||||
{
|
||||
WavRiff riff;
|
||||
WavFormat format;
|
||||
WavData data;
|
||||
} WavHeader;
|
||||
|
||||
|
||||
/// Base class for processing WAV audio files.
|
||||
class WavFileBase
|
||||
{
|
||||
private:
|
||||
/// Conversion working buffer;
|
||||
char *convBuff;
|
||||
int convBuffSize;
|
||||
|
||||
protected:
|
||||
WavFileBase();
|
||||
virtual ~WavFileBase();
|
||||
|
||||
/// Get pointer to conversion buffer of at min. given size
|
||||
void *getConvBuffer(int sizeByte);
|
||||
};
|
||||
|
||||
|
||||
/// Class for reading WAV audio files.
|
||||
class WavInFile : protected WavFileBase
|
||||
{
|
||||
private:
|
||||
/// File pointer.
|
||||
FILE *fptr;
|
||||
|
||||
/// Position within the audio stream
|
||||
long position;
|
||||
|
||||
/// Counter of how many bytes of sample data have been read from the file.
|
||||
long dataRead;
|
||||
|
||||
/// WAV header information
|
||||
WavHeader header;
|
||||
|
||||
/// Init the WAV file stream
|
||||
void init();
|
||||
|
||||
/// Read WAV file headers.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int readWavHeaders();
|
||||
|
||||
/// Checks WAV file header tags.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int checkCharTags() const;
|
||||
|
||||
/// Reads a single WAV file header block.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int readHeaderBlock();
|
||||
|
||||
/// Reads WAV file 'riff' block
|
||||
int readRIFFBlock();
|
||||
|
||||
public:
|
||||
/// Constructor: Opens the given WAV file. If the file can't be opened,
|
||||
/// throws 'runtime_error' exception.
|
||||
WavInFile(const char *filename);
|
||||
|
||||
WavInFile(FILE *file);
|
||||
|
||||
/// Destructor: Closes the file.
|
||||
~WavInFile();
|
||||
|
||||
/// Rewind to beginning of the file
|
||||
void rewind();
|
||||
|
||||
/// Get sample rate.
|
||||
uint getSampleRate() const;
|
||||
|
||||
/// Get number of bits per sample, i.e. 8 or 16.
|
||||
uint getNumBits() const;
|
||||
|
||||
/// Get sample data size in bytes. Ahem, this should return same information as
|
||||
/// 'getBytesPerSample'...
|
||||
uint getDataSizeInBytes() const;
|
||||
|
||||
/// Get total number of samples in file.
|
||||
uint getNumSamples() const;
|
||||
|
||||
/// Get number of bytes per audio sample (e.g. 16bit stereo = 4 bytes/sample)
|
||||
uint getBytesPerSample() const;
|
||||
|
||||
/// Get number of audio channels in the file (1=mono, 2=stereo)
|
||||
uint getNumChannels() const;
|
||||
|
||||
/// Get the audio file length in milliseconds
|
||||
uint getLengthMS() const;
|
||||
|
||||
/// Returns how many milliseconds of audio have so far been read from the file
|
||||
///
|
||||
/// \return elapsed duration in milliseconds
|
||||
uint getElapsedMS() const;
|
||||
|
||||
/// Reads audio samples from the WAV file. This routine works only for 8 bit samples.
|
||||
/// Reads given number of elements from the file or if end-of-file reached, as many
|
||||
/// elements as are left in the file.
|
||||
///
|
||||
/// \return Number of 8-bit integers read from the file.
|
||||
int read(unsigned char *buffer, int maxElems);
|
||||
|
||||
/// Reads audio samples from the WAV file to 16 bit integer format. Reads given number
|
||||
/// of elements from the file or if end-of-file reached, as many elements as are
|
||||
/// left in the file.
|
||||
///
|
||||
/// \return Number of 16-bit integers read from the file.
|
||||
int read(short *buffer, ///< Pointer to buffer where to read data.
|
||||
int maxElems ///< Size of 'buffer' array (number of array elements).
|
||||
);
|
||||
|
||||
/// Reads audio samples from the WAV file to floating point format, converting
|
||||
/// sample values to range [-1,1[. Reads given number of elements from the file
|
||||
/// or if end-of-file reached, as many elements as are left in the file.
|
||||
/// Notice that reading in float format supports 8/16/24/32bit sample formats.
|
||||
///
|
||||
/// \return Number of elements read from the file.
|
||||
int read(float *buffer, ///< Pointer to buffer where to read data.
|
||||
int maxElems ///< Size of 'buffer' array (number of array elements).
|
||||
);
|
||||
|
||||
/// Check end-of-file.
|
||||
///
|
||||
/// \return Nonzero if end-of-file reached.
|
||||
int eof() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Class for writing WAV audio files.
|
||||
class WavOutFile : protected WavFileBase
|
||||
{
|
||||
private:
|
||||
/// Pointer to the WAV file
|
||||
FILE *fptr;
|
||||
|
||||
/// WAV file header data.
|
||||
WavHeader header;
|
||||
|
||||
/// Counter of how many bytes have been written to the file so far.
|
||||
int bytesWritten;
|
||||
|
||||
/// Fills in WAV file header information.
|
||||
void fillInHeader(const uint sampleRate, const uint bits, const uint channels);
|
||||
|
||||
/// Finishes the WAV file header by supplementing information of amount of
|
||||
/// data written to file etc
|
||||
void finishHeader();
|
||||
|
||||
/// Writes the WAV file header.
|
||||
void writeHeader();
|
||||
|
||||
public:
|
||||
/// Constructor: Creates a new WAV file. Throws a 'runtime_error' exception
|
||||
/// if file creation fails.
|
||||
WavOutFile(const char *fileName, ///< Filename
|
||||
int sampleRate, ///< Sample rate (e.g. 44100 etc)
|
||||
int bits, ///< Bits per sample (8 or 16 bits)
|
||||
int channels ///< Number of channels (1=mono, 2=stereo)
|
||||
);
|
||||
|
||||
WavOutFile(FILE *file, int sampleRate, int bits, int channels);
|
||||
|
||||
/// Destructor: Finalizes & closes the WAV file.
|
||||
~WavOutFile();
|
||||
|
||||
/// Write data to WAV file. This function works only with 8bit samples.
|
||||
/// Throws a 'runtime_error' exception if writing to file fails.
|
||||
void write(const unsigned char *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
|
||||
/// Write data to WAV file. Throws a 'runtime_error' exception if writing to
|
||||
/// file fails.
|
||||
void write(const short *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
|
||||
/// Write data to WAV file in floating point format, saturating sample values to range
|
||||
/// [-1..+1[. Throws a 'runtime_error' exception if writing to file fails.
|
||||
void write(const float *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Classes for easy reading & writing of WAV sound files.
|
||||
///
|
||||
/// For big-endian CPU, define BIG_ENDIAN during compile-time to correctly
|
||||
/// parse the WAV files with such processors.
|
||||
///
|
||||
/// Admittingly, more complete WAV reader routines may exist in public domain, but
|
||||
/// the reason for 'yet another' one is that those generic WAV reader libraries are
|
||||
/// exhaustingly large and cumbersome! Wanted to have something simpler here, i.e.
|
||||
/// something that's not already larger than rest of the SoundTouch/SoundStretch program...
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-09-01 10:57:22 +0300 (Sat, 01 Sep 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: WavFile.h 153 2012-09-01 07:57:22Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef WAVFILE_H
|
||||
#define WAVFILE_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#ifndef uint
|
||||
typedef unsigned int uint;
|
||||
#endif
|
||||
|
||||
|
||||
/// WAV audio file 'riff' section header
|
||||
typedef struct
|
||||
{
|
||||
char riff_char[4];
|
||||
int package_len;
|
||||
char wave[4];
|
||||
} WavRiff;
|
||||
|
||||
/// WAV audio file 'format' section header
|
||||
typedef struct
|
||||
{
|
||||
char fmt[4];
|
||||
int format_len;
|
||||
short fixed;
|
||||
short channel_number;
|
||||
int sample_rate;
|
||||
int byte_rate;
|
||||
short byte_per_sample;
|
||||
short bits_per_sample;
|
||||
} WavFormat;
|
||||
|
||||
/// WAV audio file 'data' section header
|
||||
typedef struct
|
||||
{
|
||||
char data_field[4];
|
||||
uint data_len;
|
||||
} WavData;
|
||||
|
||||
|
||||
/// WAV audio file header
|
||||
typedef struct
|
||||
{
|
||||
WavRiff riff;
|
||||
WavFormat format;
|
||||
WavData data;
|
||||
} WavHeader;
|
||||
|
||||
|
||||
/// Base class for processing WAV audio files.
|
||||
class WavFileBase
|
||||
{
|
||||
private:
|
||||
/// Conversion working buffer;
|
||||
char *convBuff;
|
||||
int convBuffSize;
|
||||
|
||||
protected:
|
||||
WavFileBase();
|
||||
virtual ~WavFileBase();
|
||||
|
||||
/// Get pointer to conversion buffer of at min. given size
|
||||
void *getConvBuffer(int sizeByte);
|
||||
};
|
||||
|
||||
|
||||
/// Class for reading WAV audio files.
|
||||
class WavInFile : protected WavFileBase
|
||||
{
|
||||
private:
|
||||
/// File pointer.
|
||||
FILE *fptr;
|
||||
|
||||
/// Position within the audio stream
|
||||
long position;
|
||||
|
||||
/// Counter of how many bytes of sample data have been read from the file.
|
||||
long dataRead;
|
||||
|
||||
/// WAV header information
|
||||
WavHeader header;
|
||||
|
||||
/// Init the WAV file stream
|
||||
void init();
|
||||
|
||||
/// Read WAV file headers.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int readWavHeaders();
|
||||
|
||||
/// Checks WAV file header tags.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int checkCharTags() const;
|
||||
|
||||
/// Reads a single WAV file header block.
|
||||
/// \return zero if all ok, nonzero if file format is invalid.
|
||||
int readHeaderBlock();
|
||||
|
||||
/// Reads WAV file 'riff' block
|
||||
int readRIFFBlock();
|
||||
|
||||
public:
|
||||
/// Constructor: Opens the given WAV file. If the file can't be opened,
|
||||
/// throws 'runtime_error' exception.
|
||||
WavInFile(const char *filename);
|
||||
|
||||
WavInFile(FILE *file);
|
||||
|
||||
/// Destructor: Closes the file.
|
||||
~WavInFile();
|
||||
|
||||
/// Rewind to beginning of the file
|
||||
void rewind();
|
||||
|
||||
/// Get sample rate.
|
||||
uint getSampleRate() const;
|
||||
|
||||
/// Get number of bits per sample, i.e. 8 or 16.
|
||||
uint getNumBits() const;
|
||||
|
||||
/// Get sample data size in bytes. Ahem, this should return same information as
|
||||
/// 'getBytesPerSample'...
|
||||
uint getDataSizeInBytes() const;
|
||||
|
||||
/// Get total number of samples in file.
|
||||
uint getNumSamples() const;
|
||||
|
||||
/// Get number of bytes per audio sample (e.g. 16bit stereo = 4 bytes/sample)
|
||||
uint getBytesPerSample() const;
|
||||
|
||||
/// Get number of audio channels in the file (1=mono, 2=stereo)
|
||||
uint getNumChannels() const;
|
||||
|
||||
/// Get the audio file length in milliseconds
|
||||
uint getLengthMS() const;
|
||||
|
||||
/// Returns how many milliseconds of audio have so far been read from the file
|
||||
///
|
||||
/// \return elapsed duration in milliseconds
|
||||
uint getElapsedMS() const;
|
||||
|
||||
/// Reads audio samples from the WAV file. This routine works only for 8 bit samples.
|
||||
/// Reads given number of elements from the file or if end-of-file reached, as many
|
||||
/// elements as are left in the file.
|
||||
///
|
||||
/// \return Number of 8-bit integers read from the file.
|
||||
int read(unsigned char *buffer, int maxElems);
|
||||
|
||||
/// Reads audio samples from the WAV file to 16 bit integer format. Reads given number
|
||||
/// of elements from the file or if end-of-file reached, as many elements as are
|
||||
/// left in the file.
|
||||
///
|
||||
/// \return Number of 16-bit integers read from the file.
|
||||
int read(short *buffer, ///< Pointer to buffer where to read data.
|
||||
int maxElems ///< Size of 'buffer' array (number of array elements).
|
||||
);
|
||||
|
||||
/// Reads audio samples from the WAV file to floating point format, converting
|
||||
/// sample values to range [-1,1[. Reads given number of elements from the file
|
||||
/// or if end-of-file reached, as many elements as are left in the file.
|
||||
/// Notice that reading in float format supports 8/16/24/32bit sample formats.
|
||||
///
|
||||
/// \return Number of elements read from the file.
|
||||
int read(float *buffer, ///< Pointer to buffer where to read data.
|
||||
int maxElems ///< Size of 'buffer' array (number of array elements).
|
||||
);
|
||||
|
||||
/// Check end-of-file.
|
||||
///
|
||||
/// \return Nonzero if end-of-file reached.
|
||||
int eof() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/// Class for writing WAV audio files.
|
||||
class WavOutFile : protected WavFileBase
|
||||
{
|
||||
private:
|
||||
/// Pointer to the WAV file
|
||||
FILE *fptr;
|
||||
|
||||
/// WAV file header data.
|
||||
WavHeader header;
|
||||
|
||||
/// Counter of how many bytes have been written to the file so far.
|
||||
int bytesWritten;
|
||||
|
||||
/// Fills in WAV file header information.
|
||||
void fillInHeader(const uint sampleRate, const uint bits, const uint channels);
|
||||
|
||||
/// Finishes the WAV file header by supplementing information of amount of
|
||||
/// data written to file etc
|
||||
void finishHeader();
|
||||
|
||||
/// Writes the WAV file header.
|
||||
void writeHeader();
|
||||
|
||||
public:
|
||||
/// Constructor: Creates a new WAV file. Throws a 'runtime_error' exception
|
||||
/// if file creation fails.
|
||||
WavOutFile(const char *fileName, ///< Filename
|
||||
int sampleRate, ///< Sample rate (e.g. 44100 etc)
|
||||
int bits, ///< Bits per sample (8 or 16 bits)
|
||||
int channels ///< Number of channels (1=mono, 2=stereo)
|
||||
);
|
||||
|
||||
WavOutFile(FILE *file, int sampleRate, int bits, int channels);
|
||||
|
||||
/// Destructor: Finalizes & closes the WAV file.
|
||||
~WavOutFile();
|
||||
|
||||
/// Write data to WAV file. This function works only with 8bit samples.
|
||||
/// Throws a 'runtime_error' exception if writing to file fails.
|
||||
void write(const unsigned char *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
|
||||
/// Write data to WAV file. Throws a 'runtime_error' exception if writing to
|
||||
/// file fails.
|
||||
void write(const short *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
|
||||
/// Write data to WAV file in floating point format, saturating sample values to range
|
||||
/// [-1..+1[. Throws a 'runtime_error' exception if writing to file fails.
|
||||
void write(const float *buffer, ///< Pointer to sample data buffer.
|
||||
int numElems ///< How many array items are to be written to file.
|
||||
);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,333 +1,333 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundStretch main routine.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-04-04 22:47:28 +0300 (Wed, 04 Apr 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: main.cpp 141 2012-04-04 19:47:28Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "RunParameters.h"
|
||||
#include "WavFile.h"
|
||||
#include "SoundTouch.h"
|
||||
#include "BPMDetect.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
using namespace std;
|
||||
|
||||
// Processing chunk size
|
||||
#define BUFF_SIZE 2048
|
||||
|
||||
#if _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// Macro for Win32 standard input/output stream support: Sets a file stream into binary mode
|
||||
#define SET_STREAM_TO_BIN_MODE(f) (_setmode(_fileno(f), _O_BINARY))
|
||||
#else
|
||||
// Not needed for GNU environment...
|
||||
#define SET_STREAM_TO_BIN_MODE(f) {}
|
||||
#endif
|
||||
|
||||
|
||||
static const char _helloText[] =
|
||||
"\n"
|
||||
" SoundStretch v%s - Written by Olli Parviainen 2001 - 2012\n"
|
||||
"==================================================================\n"
|
||||
"author e-mail: <oparviai"
|
||||
"@"
|
||||
"iki.fi> - WWW: http://www.surina.net/soundtouch\n"
|
||||
"\n"
|
||||
"This program is subject to (L)GPL license. Run \"soundstretch -license\" for\n"
|
||||
"more information.\n"
|
||||
"\n";
|
||||
|
||||
static void openFiles(WavInFile **inFile, WavOutFile **outFile, const RunParameters *params)
|
||||
{
|
||||
int bits, samplerate, channels;
|
||||
|
||||
if (strcmp(params->inFileName, "stdin") == 0)
|
||||
{
|
||||
// used 'stdin' as input file
|
||||
SET_STREAM_TO_BIN_MODE(stdin);
|
||||
*inFile = new WavInFile(stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
// open input file...
|
||||
*inFile = new WavInFile(params->inFileName);
|
||||
}
|
||||
|
||||
// ... open output file with same sound parameters
|
||||
bits = (int)(*inFile)->getNumBits();
|
||||
samplerate = (int)(*inFile)->getSampleRate();
|
||||
channels = (int)(*inFile)->getNumChannels();
|
||||
|
||||
if (params->outFileName)
|
||||
{
|
||||
if (strcmp(params->outFileName, "stdout") == 0)
|
||||
{
|
||||
SET_STREAM_TO_BIN_MODE(stdout);
|
||||
*outFile = new WavOutFile(stdout, samplerate, bits, channels);
|
||||
}
|
||||
else
|
||||
{
|
||||
*outFile = new WavOutFile(params->outFileName, samplerate, bits, channels);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*outFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Sets the 'SoundTouch' object up according to input file sound format &
|
||||
// command line parameters
|
||||
static void setup(SoundTouch *pSoundTouch, const WavInFile *inFile, const RunParameters *params)
|
||||
{
|
||||
int sampleRate;
|
||||
int channels;
|
||||
|
||||
sampleRate = (int)inFile->getSampleRate();
|
||||
channels = (int)inFile->getNumChannels();
|
||||
pSoundTouch->setSampleRate(sampleRate);
|
||||
pSoundTouch->setChannels(channels);
|
||||
|
||||
pSoundTouch->setTempoChange(params->tempoDelta);
|
||||
pSoundTouch->setPitchSemiTones(params->pitchDelta);
|
||||
pSoundTouch->setRateChange(params->rateDelta);
|
||||
|
||||
pSoundTouch->setSetting(SETTING_USE_QUICKSEEK, params->quick);
|
||||
pSoundTouch->setSetting(SETTING_USE_AA_FILTER, !(params->noAntiAlias));
|
||||
|
||||
if (params->speech)
|
||||
{
|
||||
// use settings for speech processing
|
||||
pSoundTouch->setSetting(SETTING_SEQUENCE_MS, 40);
|
||||
pSoundTouch->setSetting(SETTING_SEEKWINDOW_MS, 15);
|
||||
pSoundTouch->setSetting(SETTING_OVERLAP_MS, 8);
|
||||
fprintf(stderr, "Tune processing parameters for speech processing.\n");
|
||||
}
|
||||
|
||||
// print processing information
|
||||
if (params->outFileName)
|
||||
{
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
fprintf(stderr, "Uses 16bit integer sample type in processing.\n\n");
|
||||
#else
|
||||
#ifndef SOUNDTOUCH_FLOAT_SAMPLES
|
||||
#error "Sampletype not defined"
|
||||
#endif
|
||||
fprintf(stderr, "Uses 32bit floating point sample type in processing.\n\n");
|
||||
#endif
|
||||
// print processing information only if outFileName given i.e. some processing will happen
|
||||
fprintf(stderr, "Processing the file with the following changes:\n");
|
||||
fprintf(stderr, " tempo change = %+g %%\n", params->tempoDelta);
|
||||
fprintf(stderr, " pitch change = %+g semitones\n", params->pitchDelta);
|
||||
fprintf(stderr, " rate change = %+g %%\n\n", params->rateDelta);
|
||||
fprintf(stderr, "Working...");
|
||||
}
|
||||
else
|
||||
{
|
||||
// outFileName not given
|
||||
fprintf(stderr, "Warning: output file name missing, won't output anything.\n\n");
|
||||
}
|
||||
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Processes the sound
|
||||
static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile)
|
||||
{
|
||||
int nSamples;
|
||||
int nChannels;
|
||||
int buffSizeSamples;
|
||||
SAMPLETYPE sampleBuffer[BUFF_SIZE];
|
||||
|
||||
if ((inFile == NULL) || (outFile == NULL)) return; // nothing to do.
|
||||
|
||||
nChannels = (int)inFile->getNumChannels();
|
||||
assert(nChannels > 0);
|
||||
buffSizeSamples = BUFF_SIZE / nChannels;
|
||||
|
||||
// Process samples read from the input file
|
||||
while (inFile->eof() == 0)
|
||||
{
|
||||
int num;
|
||||
|
||||
// Read a chunk of samples from the input file
|
||||
num = inFile->read(sampleBuffer, BUFF_SIZE);
|
||||
nSamples = num / (int)inFile->getNumChannels();
|
||||
|
||||
// Feed the samples into SoundTouch processor
|
||||
pSoundTouch->putSamples(sampleBuffer, nSamples);
|
||||
|
||||
// Read ready samples from SoundTouch processor & write them output file.
|
||||
// NOTES:
|
||||
// - 'receiveSamples' doesn't necessarily return any samples at all
|
||||
// during some rounds!
|
||||
// - On the other hand, during some round 'receiveSamples' may have more
|
||||
// ready samples than would fit into 'sampleBuffer', and for this reason
|
||||
// the 'receiveSamples' call is iterated for as many times as it
|
||||
// outputs samples.
|
||||
do
|
||||
{
|
||||
nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
|
||||
outFile->write(sampleBuffer, nSamples * nChannels);
|
||||
} while (nSamples != 0);
|
||||
}
|
||||
|
||||
// Now the input file is processed, yet 'flush' few last samples that are
|
||||
// hiding in the SoundTouch's internal processing pipeline.
|
||||
pSoundTouch->flush();
|
||||
do
|
||||
{
|
||||
nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
|
||||
outFile->write(sampleBuffer, nSamples * nChannels);
|
||||
} while (nSamples != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Detect BPM rate of inFile and adjust tempo setting accordingly if necessary
|
||||
static void detectBPM(WavInFile *inFile, RunParameters *params)
|
||||
{
|
||||
float bpmValue;
|
||||
int nChannels;
|
||||
BPMDetect bpm(inFile->getNumChannels(), inFile->getSampleRate());
|
||||
SAMPLETYPE sampleBuffer[BUFF_SIZE];
|
||||
|
||||
// detect bpm rate
|
||||
fprintf(stderr, "Detecting BPM rate...");
|
||||
fflush(stderr);
|
||||
|
||||
nChannels = (int)inFile->getNumChannels();
|
||||
assert(BUFF_SIZE % nChannels == 0);
|
||||
|
||||
// Process the 'inFile' in small blocks, repeat until whole file has
|
||||
// been processed
|
||||
while (inFile->eof() == 0)
|
||||
{
|
||||
int num, samples;
|
||||
|
||||
// Read sample data from input file
|
||||
num = inFile->read(sampleBuffer, BUFF_SIZE);
|
||||
|
||||
// Enter the new samples to the bpm analyzer class
|
||||
samples = num / nChannels;
|
||||
bpm.inputSamples(sampleBuffer, samples);
|
||||
}
|
||||
|
||||
// Now the whole song data has been analyzed. Read the resulting bpm.
|
||||
bpmValue = bpm.getBpm();
|
||||
fprintf(stderr, "Done!\n");
|
||||
|
||||
// rewind the file after bpm detection
|
||||
inFile->rewind();
|
||||
|
||||
if (bpmValue > 0)
|
||||
{
|
||||
fprintf(stderr, "Detected BPM rate %.1f\n\n", bpmValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Couldn't detect BPM rate.\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (params->goalBPM > 0)
|
||||
{
|
||||
// adjust tempo to given bpm
|
||||
params->tempoDelta = (params->goalBPM / bpmValue - 1.0f) * 100.0f;
|
||||
fprintf(stderr, "The file will be converted to %.1f BPM\n\n", params->goalBPM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(const int nParams, const char * const paramStr[])
|
||||
{
|
||||
WavInFile *inFile;
|
||||
WavOutFile *outFile;
|
||||
RunParameters *params;
|
||||
SoundTouch soundTouch;
|
||||
|
||||
fprintf(stderr, _helloText, SoundTouch::getVersionString());
|
||||
|
||||
try
|
||||
{
|
||||
// Parse command line parameters
|
||||
params = new RunParameters(nParams, paramStr);
|
||||
|
||||
// Open input & output files
|
||||
openFiles(&inFile, &outFile, params);
|
||||
|
||||
if (params->detectBPM == TRUE)
|
||||
{
|
||||
// detect sound BPM (and adjust processing parameters
|
||||
// accordingly if necessary)
|
||||
detectBPM(inFile, params);
|
||||
}
|
||||
|
||||
// Setup the 'SoundTouch' object for processing the sound
|
||||
setup(&soundTouch, inFile, params);
|
||||
|
||||
// clock_t cs = clock(); // for benchmarking processing duration
|
||||
// Process the sound
|
||||
process(&soundTouch, inFile, outFile);
|
||||
// clock_t ce = clock(); // for benchmarking processing duration
|
||||
// printf("duration: %lf\n", (double)(ce-cs)/CLOCKS_PER_SEC);
|
||||
|
||||
// Close WAV file handles & dispose of the objects
|
||||
delete inFile;
|
||||
delete outFile;
|
||||
delete params;
|
||||
|
||||
fprintf(stderr, "Done!\n");
|
||||
}
|
||||
catch (const runtime_error &e)
|
||||
{
|
||||
// An exception occurred during processing, display an error message
|
||||
fprintf(stderr, "%s\n", e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundStretch main routine.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-04-04 22:47:28 +0300 (Wed, 04 Apr 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: main.cpp 141 2012-04-04 19:47:28Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include "RunParameters.h"
|
||||
#include "WavFile.h"
|
||||
#include "SoundTouch.h"
|
||||
#include "BPMDetect.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
using namespace std;
|
||||
|
||||
// Processing chunk size
|
||||
#define BUFF_SIZE 2048
|
||||
|
||||
#if _WIN32
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
// Macro for Win32 standard input/output stream support: Sets a file stream into binary mode
|
||||
#define SET_STREAM_TO_BIN_MODE(f) (_setmode(_fileno(f), _O_BINARY))
|
||||
#else
|
||||
// Not needed for GNU environment...
|
||||
#define SET_STREAM_TO_BIN_MODE(f) {}
|
||||
#endif
|
||||
|
||||
|
||||
static const char _helloText[] =
|
||||
"\n"
|
||||
" SoundStretch v%s - Written by Olli Parviainen 2001 - 2012\n"
|
||||
"==================================================================\n"
|
||||
"author e-mail: <oparviai"
|
||||
"@"
|
||||
"iki.fi> - WWW: http://www.surina.net/soundtouch\n"
|
||||
"\n"
|
||||
"This program is subject to (L)GPL license. Run \"soundstretch -license\" for\n"
|
||||
"more information.\n"
|
||||
"\n";
|
||||
|
||||
static void openFiles(WavInFile **inFile, WavOutFile **outFile, const RunParameters *params)
|
||||
{
|
||||
int bits, samplerate, channels;
|
||||
|
||||
if (strcmp(params->inFileName, "stdin") == 0)
|
||||
{
|
||||
// used 'stdin' as input file
|
||||
SET_STREAM_TO_BIN_MODE(stdin);
|
||||
*inFile = new WavInFile(stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
// open input file...
|
||||
*inFile = new WavInFile(params->inFileName);
|
||||
}
|
||||
|
||||
// ... open output file with same sound parameters
|
||||
bits = (int)(*inFile)->getNumBits();
|
||||
samplerate = (int)(*inFile)->getSampleRate();
|
||||
channels = (int)(*inFile)->getNumChannels();
|
||||
|
||||
if (params->outFileName)
|
||||
{
|
||||
if (strcmp(params->outFileName, "stdout") == 0)
|
||||
{
|
||||
SET_STREAM_TO_BIN_MODE(stdout);
|
||||
*outFile = new WavOutFile(stdout, samplerate, bits, channels);
|
||||
}
|
||||
else
|
||||
{
|
||||
*outFile = new WavOutFile(params->outFileName, samplerate, bits, channels);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*outFile = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Sets the 'SoundTouch' object up according to input file sound format &
|
||||
// command line parameters
|
||||
static void setup(SoundTouch *pSoundTouch, const WavInFile *inFile, const RunParameters *params)
|
||||
{
|
||||
int sampleRate;
|
||||
int channels;
|
||||
|
||||
sampleRate = (int)inFile->getSampleRate();
|
||||
channels = (int)inFile->getNumChannels();
|
||||
pSoundTouch->setSampleRate(sampleRate);
|
||||
pSoundTouch->setChannels(channels);
|
||||
|
||||
pSoundTouch->setTempoChange(params->tempoDelta);
|
||||
pSoundTouch->setPitchSemiTones(params->pitchDelta);
|
||||
pSoundTouch->setRateChange(params->rateDelta);
|
||||
|
||||
pSoundTouch->setSetting(SETTING_USE_QUICKSEEK, params->quick);
|
||||
pSoundTouch->setSetting(SETTING_USE_AA_FILTER, !(params->noAntiAlias));
|
||||
|
||||
if (params->speech)
|
||||
{
|
||||
// use settings for speech processing
|
||||
pSoundTouch->setSetting(SETTING_SEQUENCE_MS, 40);
|
||||
pSoundTouch->setSetting(SETTING_SEEKWINDOW_MS, 15);
|
||||
pSoundTouch->setSetting(SETTING_OVERLAP_MS, 8);
|
||||
fprintf(stderr, "Tune processing parameters for speech processing.\n");
|
||||
}
|
||||
|
||||
// print processing information
|
||||
if (params->outFileName)
|
||||
{
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
fprintf(stderr, "Uses 16bit integer sample type in processing.\n\n");
|
||||
#else
|
||||
#ifndef SOUNDTOUCH_FLOAT_SAMPLES
|
||||
#error "Sampletype not defined"
|
||||
#endif
|
||||
fprintf(stderr, "Uses 32bit floating point sample type in processing.\n\n");
|
||||
#endif
|
||||
// print processing information only if outFileName given i.e. some processing will happen
|
||||
fprintf(stderr, "Processing the file with the following changes:\n");
|
||||
fprintf(stderr, " tempo change = %+g %%\n", params->tempoDelta);
|
||||
fprintf(stderr, " pitch change = %+g semitones\n", params->pitchDelta);
|
||||
fprintf(stderr, " rate change = %+g %%\n\n", params->rateDelta);
|
||||
fprintf(stderr, "Working...");
|
||||
}
|
||||
else
|
||||
{
|
||||
// outFileName not given
|
||||
fprintf(stderr, "Warning: output file name missing, won't output anything.\n\n");
|
||||
}
|
||||
|
||||
fflush(stderr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Processes the sound
|
||||
static void process(SoundTouch *pSoundTouch, WavInFile *inFile, WavOutFile *outFile)
|
||||
{
|
||||
int nSamples;
|
||||
int nChannels;
|
||||
int buffSizeSamples;
|
||||
SAMPLETYPE sampleBuffer[BUFF_SIZE];
|
||||
|
||||
if ((inFile == NULL) || (outFile == NULL)) return; // nothing to do.
|
||||
|
||||
nChannels = (int)inFile->getNumChannels();
|
||||
assert(nChannels > 0);
|
||||
buffSizeSamples = BUFF_SIZE / nChannels;
|
||||
|
||||
// Process samples read from the input file
|
||||
while (inFile->eof() == 0)
|
||||
{
|
||||
int num;
|
||||
|
||||
// Read a chunk of samples from the input file
|
||||
num = inFile->read(sampleBuffer, BUFF_SIZE);
|
||||
nSamples = num / (int)inFile->getNumChannels();
|
||||
|
||||
// Feed the samples into SoundTouch processor
|
||||
pSoundTouch->putSamples(sampleBuffer, nSamples);
|
||||
|
||||
// Read ready samples from SoundTouch processor & write them output file.
|
||||
// NOTES:
|
||||
// - 'receiveSamples' doesn't necessarily return any samples at all
|
||||
// during some rounds!
|
||||
// - On the other hand, during some round 'receiveSamples' may have more
|
||||
// ready samples than would fit into 'sampleBuffer', and for this reason
|
||||
// the 'receiveSamples' call is iterated for as many times as it
|
||||
// outputs samples.
|
||||
do
|
||||
{
|
||||
nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
|
||||
outFile->write(sampleBuffer, nSamples * nChannels);
|
||||
} while (nSamples != 0);
|
||||
}
|
||||
|
||||
// Now the input file is processed, yet 'flush' few last samples that are
|
||||
// hiding in the SoundTouch's internal processing pipeline.
|
||||
pSoundTouch->flush();
|
||||
do
|
||||
{
|
||||
nSamples = pSoundTouch->receiveSamples(sampleBuffer, buffSizeSamples);
|
||||
outFile->write(sampleBuffer, nSamples * nChannels);
|
||||
} while (nSamples != 0);
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Detect BPM rate of inFile and adjust tempo setting accordingly if necessary
|
||||
static void detectBPM(WavInFile *inFile, RunParameters *params)
|
||||
{
|
||||
float bpmValue;
|
||||
int nChannels;
|
||||
BPMDetect bpm(inFile->getNumChannels(), inFile->getSampleRate());
|
||||
SAMPLETYPE sampleBuffer[BUFF_SIZE];
|
||||
|
||||
// detect bpm rate
|
||||
fprintf(stderr, "Detecting BPM rate...");
|
||||
fflush(stderr);
|
||||
|
||||
nChannels = (int)inFile->getNumChannels();
|
||||
assert(BUFF_SIZE % nChannels == 0);
|
||||
|
||||
// Process the 'inFile' in small blocks, repeat until whole file has
|
||||
// been processed
|
||||
while (inFile->eof() == 0)
|
||||
{
|
||||
int num, samples;
|
||||
|
||||
// Read sample data from input file
|
||||
num = inFile->read(sampleBuffer, BUFF_SIZE);
|
||||
|
||||
// Enter the new samples to the bpm analyzer class
|
||||
samples = num / nChannels;
|
||||
bpm.inputSamples(sampleBuffer, samples);
|
||||
}
|
||||
|
||||
// Now the whole song data has been analyzed. Read the resulting bpm.
|
||||
bpmValue = bpm.getBpm();
|
||||
fprintf(stderr, "Done!\n");
|
||||
|
||||
// rewind the file after bpm detection
|
||||
inFile->rewind();
|
||||
|
||||
if (bpmValue > 0)
|
||||
{
|
||||
fprintf(stderr, "Detected BPM rate %.1f\n\n", bpmValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "Couldn't detect BPM rate.\n\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (params->goalBPM > 0)
|
||||
{
|
||||
// adjust tempo to given bpm
|
||||
params->tempoDelta = (params->goalBPM / bpmValue - 1.0f) * 100.0f;
|
||||
fprintf(stderr, "The file will be converted to %.1f BPM\n\n", params->goalBPM);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(const int nParams, const char * const paramStr[])
|
||||
{
|
||||
WavInFile *inFile;
|
||||
WavOutFile *outFile;
|
||||
RunParameters *params;
|
||||
SoundTouch soundTouch;
|
||||
|
||||
fprintf(stderr, _helloText, SoundTouch::getVersionString());
|
||||
|
||||
try
|
||||
{
|
||||
// Parse command line parameters
|
||||
params = new RunParameters(nParams, paramStr);
|
||||
|
||||
// Open input & output files
|
||||
openFiles(&inFile, &outFile, params);
|
||||
|
||||
if (params->detectBPM == TRUE)
|
||||
{
|
||||
// detect sound BPM (and adjust processing parameters
|
||||
// accordingly if necessary)
|
||||
detectBPM(inFile, params);
|
||||
}
|
||||
|
||||
// Setup the 'SoundTouch' object for processing the sound
|
||||
setup(&soundTouch, inFile, params);
|
||||
|
||||
// clock_t cs = clock(); // for benchmarking processing duration
|
||||
// Process the sound
|
||||
process(&soundTouch, inFile, outFile);
|
||||
// clock_t ce = clock(); // for benchmarking processing duration
|
||||
// printf("duration: %lf\n", (double)(ce-cs)/CLOCKS_PER_SEC);
|
||||
|
||||
// Close WAV file handles & dispose of the objects
|
||||
delete inFile;
|
||||
delete outFile;
|
||||
delete params;
|
||||
|
||||
fprintf(stderr, "Done!\n");
|
||||
}
|
||||
catch (const runtime_error &e)
|
||||
{
|
||||
// An exception occurred during processing, display an error message
|
||||
fprintf(stderr, "%s\n", e.what());
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
# Microsoft Developer Studio Project File - Name="soundstretch" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=soundstretch - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "soundstretch.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "soundstretch.mak" CFG="soundstretch - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "soundstretch - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "soundstretch - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "soundstretch - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /Zi /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x40b /d "NDEBUG"
|
||||
# ADD RSC /l 0x40b /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 SoundTouch.lib /nologo /subsystem:console /profile /map /debug /machine:I386 /libpath:"..\..\lib"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Cmds=copy Release\soundstretch.exe ..\..\bin\
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "soundstretch - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Zp16 /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x40b /d "_DEBUG"
|
||||
# ADD RSC /l 0x40b /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 SoundTouchD.lib /nologo /subsystem:console /map /debug /machine:I386 /nodefaultlib:"libc" /out:"Debug/soundstretchD.exe" /pdbtype:sept /libpath:"..\..\lib"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Cmds=copy Debug\soundstretchD.exe ..\..\bin\
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "soundstretch - Win32 Release"
|
||||
# Name "soundstretch - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RunParameters.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\WavFile.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RunParameters.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\include\SoundTouch.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\include\STTypes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\WavFile.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
# Microsoft Developer Studio Project File - Name="soundstretch" - Package Owner=<4>
|
||||
# Microsoft Developer Studio Generated Build File, Format Version 6.00
|
||||
# ** DO NOT EDIT **
|
||||
|
||||
# TARGTYPE "Win32 (x86) Console Application" 0x0103
|
||||
|
||||
CFG=soundstretch - Win32 Debug
|
||||
!MESSAGE This is not a valid makefile. To build this project using NMAKE,
|
||||
!MESSAGE use the Export Makefile command and run
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "soundstretch.mak".
|
||||
!MESSAGE
|
||||
!MESSAGE You can specify a configuration when running NMAKE
|
||||
!MESSAGE by defining the macro CFG on the command line. For example:
|
||||
!MESSAGE
|
||||
!MESSAGE NMAKE /f "soundstretch.mak" CFG="soundstretch - Win32 Debug"
|
||||
!MESSAGE
|
||||
!MESSAGE Possible choices for configuration are:
|
||||
!MESSAGE
|
||||
!MESSAGE "soundstretch - Win32 Release" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE "soundstretch - Win32 Debug" (based on "Win32 (x86) Console Application")
|
||||
!MESSAGE
|
||||
|
||||
# Begin Project
|
||||
# PROP AllowPerConfigDependencies 0
|
||||
# PROP Scc_ProjName ""
|
||||
# PROP Scc_LocalPath ""
|
||||
CPP=cl.exe
|
||||
RSC=rc.exe
|
||||
|
||||
!IF "$(CFG)" == "soundstretch - Win32 Release"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 0
|
||||
# PROP BASE Output_Dir "Release"
|
||||
# PROP BASE Intermediate_Dir "Release"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 0
|
||||
# PROP Output_Dir "Release"
|
||||
# PROP Intermediate_Dir "Release"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /c
|
||||
# ADD CPP /nologo /W3 /GX /Zi /O2 /I "..\..\include" /D "WIN32" /D "NDEBUG" /D "_CONSOLE" /D "_MBCS" /FD /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x40b /d "NDEBUG"
|
||||
# ADD RSC /l 0x40b /d "NDEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /machine:I386
|
||||
# ADD LINK32 SoundTouch.lib /nologo /subsystem:console /profile /map /debug /machine:I386 /libpath:"..\..\lib"
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Cmds=copy Release\soundstretch.exe ..\..\bin\
|
||||
# End Special Build Tool
|
||||
|
||||
!ELSEIF "$(CFG)" == "soundstretch - Win32 Debug"
|
||||
|
||||
# PROP BASE Use_MFC 0
|
||||
# PROP BASE Use_Debug_Libraries 1
|
||||
# PROP BASE Output_Dir "Debug"
|
||||
# PROP BASE Intermediate_Dir "Debug"
|
||||
# PROP BASE Target_Dir ""
|
||||
# PROP Use_MFC 0
|
||||
# PROP Use_Debug_Libraries 1
|
||||
# PROP Output_Dir "Debug"
|
||||
# PROP Intermediate_Dir "Debug"
|
||||
# PROP Ignore_Export_Lib 0
|
||||
# PROP Target_Dir ""
|
||||
# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /YX /FD /GZ /c
|
||||
# ADD CPP /nologo /Zp16 /W3 /Gm /GX /ZI /Od /I "..\..\include" /D "WIN32" /D "_DEBUG" /D "_CONSOLE" /D "_MBCS" /FR /FD /GZ /c
|
||||
# SUBTRACT CPP /YX
|
||||
# ADD BASE RSC /l 0x40b /d "_DEBUG"
|
||||
# ADD RSC /l 0x40b /d "_DEBUG"
|
||||
BSC32=bscmake.exe
|
||||
# ADD BASE BSC32 /nologo
|
||||
# ADD BSC32 /nologo
|
||||
LINK32=link.exe
|
||||
# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /subsystem:console /debug /machine:I386 /pdbtype:sept
|
||||
# ADD LINK32 SoundTouchD.lib /nologo /subsystem:console /map /debug /machine:I386 /nodefaultlib:"libc" /out:"Debug/soundstretchD.exe" /pdbtype:sept /libpath:"..\..\lib"
|
||||
# SUBTRACT LINK32 /pdb:none
|
||||
# Begin Special Build Tool
|
||||
SOURCE="$(InputPath)"
|
||||
PostBuild_Cmds=copy Debug\soundstretchD.exe ..\..\bin\
|
||||
# End Special Build Tool
|
||||
|
||||
!ENDIF
|
||||
|
||||
# Begin Target
|
||||
|
||||
# Name "soundstretch - Win32 Release"
|
||||
# Name "soundstretch - Win32 Debug"
|
||||
# Begin Group "Source Files"
|
||||
|
||||
# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\main.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RunParameters.cpp
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\WavFile.cpp
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Header Files"
|
||||
|
||||
# PROP Default_Filter "h;hpp;hxx;hm;inl"
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\RunParameters.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\include\SoundTouch.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=..\..\..\include\STTypes.h
|
||||
# End Source File
|
||||
# Begin Source File
|
||||
|
||||
SOURCE=.\WavFile.h
|
||||
# End Source File
|
||||
# End Group
|
||||
# Begin Group "Resource Files"
|
||||
|
||||
# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
|
||||
# End Group
|
||||
# End Target
|
||||
# End Project
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SoundTouch"=..\SoundTouch\SoundTouch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "soundstretch"=.\soundstretch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name SoundTouch
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Microsoft Developer Studio Workspace File, Format Version 6.00
|
||||
# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "SoundTouch"=..\SoundTouch\SoundTouch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Project: "soundstretch"=.\soundstretch.dsp - Package Owner=<4>
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<4>
|
||||
{{{
|
||||
Begin Project Dependency
|
||||
Project_Dep_Name SoundTouch
|
||||
End Project Dependency
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
Global:
|
||||
|
||||
Package=<5>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
Package=<3>
|
||||
{{{
|
||||
}}}
|
||||
|
||||
###############################################################################
|
||||
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "soundstretch", "soundstretch.vcproj", "{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
Release = Release
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectDependencies) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Debug.ActiveCfg = Debug|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Debug.Build.0 = Debug|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Release.ActiveCfg = Release|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Release.Build.0 = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.ActiveCfg = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.Build.0 = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.ActiveCfg = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Microsoft Visual Studio Solution File, Format Version 8.00
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "soundstretch", "soundstretch.vcproj", "{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfiguration) = preSolution
|
||||
Debug = Debug
|
||||
Release = Release
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectDependencies) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfiguration) = postSolution
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Debug.ActiveCfg = Debug|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Debug.Build.0 = Debug|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Release.ActiveCfg = Release|Win32
|
||||
{5AACDFFA-D491-44B8-A332-DA7ACCAAF2AF}.Release.Build.0 = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.ActiveCfg = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug.Build.0 = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.ActiveCfg = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityAddIns) = postSolution
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,370 +1,370 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Beats-per-minute (BPM) detection routine.
|
||||
///
|
||||
/// The beat detection algorithm works as follows:
|
||||
/// - Use function 'inputSamples' to input a chunks of samples to the class for
|
||||
/// analysis. It's a good idea to enter a large sound file or stream in smallish
|
||||
/// chunks of around few kilosamples in order not to extinguish too much RAM memory.
|
||||
/// - Inputted sound data is decimated to approx 500 Hz to reduce calculation burden,
|
||||
/// which is basically ok as low (bass) frequencies mostly determine the beat rate.
|
||||
/// Simple averaging is used for anti-alias filtering because the resulting signal
|
||||
/// quality isn't of that high importance.
|
||||
/// - Decimated sound data is enveloped, i.e. the amplitude shape is detected by
|
||||
/// taking absolute value that's smoothed by sliding average. Signal levels that
|
||||
/// are below a couple of times the general RMS amplitude level are cut away to
|
||||
/// leave only notable peaks there.
|
||||
/// - Repeating sound patterns (e.g. beats) are detected by calculating short-term
|
||||
/// autocorrelation function of the enveloped signal.
|
||||
/// - After whole sound data file has been analyzed as above, the bpm level is
|
||||
/// detected by function 'getBpm' that finds the highest peak of the autocorrelation
|
||||
/// function, calculates it's precise location and converts this reading to bpm's.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-08-30 22:45:25 +0300 (Thu, 30 Aug 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: BPMDetect.cpp 149 2012-08-30 19:45:25Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "FIFOSampleBuffer.h"
|
||||
#include "PeakFinder.h"
|
||||
#include "BPMDetect.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
#define INPUT_BLOCK_SAMPLES 2048
|
||||
#define DECIMATED_BLOCK_SAMPLES 256
|
||||
|
||||
/// decay constant for calculating RMS volume sliding average approximation
|
||||
/// (time constant is about 10 sec)
|
||||
const float avgdecay = 0.99986f;
|
||||
|
||||
/// Normalization coefficient for calculating RMS sliding average approximation.
|
||||
const float avgnorm = (1 - avgdecay);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Enable following define to create bpm analysis file:
|
||||
|
||||
// #define _CREATE_BPM_DEBUG_FILE
|
||||
|
||||
#ifdef _CREATE_BPM_DEBUG_FILE
|
||||
|
||||
#define DEBUGFILE_NAME "c:\\temp\\soundtouch-bpm-debug.txt"
|
||||
|
||||
static void _SaveDebugData(const float *data, int minpos, int maxpos, double coeff)
|
||||
{
|
||||
FILE *fptr = fopen(DEBUGFILE_NAME, "wt");
|
||||
int i;
|
||||
|
||||
if (fptr)
|
||||
{
|
||||
printf("\n\nWriting BPM debug data into file " DEBUGFILE_NAME "\n\n");
|
||||
for (i = minpos; i < maxpos; i ++)
|
||||
{
|
||||
fprintf(fptr, "%d\t%.1lf\t%f\n", i, coeff / (double)i, data[i]);
|
||||
}
|
||||
fclose(fptr);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define _SaveDebugData(a,b,c,d)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BPMDetect::BPMDetect(int numChannels, int aSampleRate)
|
||||
{
|
||||
this->sampleRate = aSampleRate;
|
||||
this->channels = numChannels;
|
||||
|
||||
decimateSum = 0;
|
||||
decimateCount = 0;
|
||||
|
||||
envelopeAccu = 0;
|
||||
|
||||
// Initialize RMS volume accumulator to RMS level of 1500 (out of 32768) that's
|
||||
// safe initial RMS signal level value for song data. This value is then adapted
|
||||
// to the actual level during processing.
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// integer samples
|
||||
RMSVolumeAccu = (1500 * 1500) / avgnorm;
|
||||
#else
|
||||
// float samples, scaled to range [-1..+1[
|
||||
RMSVolumeAccu = (0.045f * 0.045f) / avgnorm;
|
||||
#endif
|
||||
|
||||
// choose decimation factor so that result is approx. 1000 Hz
|
||||
decimateBy = sampleRate / 1000;
|
||||
assert(decimateBy > 0);
|
||||
assert(INPUT_BLOCK_SAMPLES < decimateBy * DECIMATED_BLOCK_SAMPLES);
|
||||
|
||||
// Calculate window length & starting item according to desired min & max bpms
|
||||
windowLen = (60 * sampleRate) / (decimateBy * MIN_BPM);
|
||||
windowStart = (60 * sampleRate) / (decimateBy * MAX_BPM);
|
||||
|
||||
assert(windowLen > windowStart);
|
||||
|
||||
// allocate new working objects
|
||||
xcorr = new float[windowLen];
|
||||
memset(xcorr, 0, windowLen * sizeof(float));
|
||||
|
||||
// allocate processing buffer
|
||||
buffer = new FIFOSampleBuffer();
|
||||
// we do processing in mono mode
|
||||
buffer->setChannels(1);
|
||||
buffer->clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
BPMDetect::~BPMDetect()
|
||||
{
|
||||
delete[] xcorr;
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// convert to mono, low-pass filter & decimate to about 500 Hz.
|
||||
/// return number of outputted samples.
|
||||
///
|
||||
/// Decimation is used to remove the unnecessary frequencies and thus to reduce
|
||||
/// the amount of data needed to be processed as calculating autocorrelation
|
||||
/// function is a very-very heavy operation.
|
||||
///
|
||||
/// Anti-alias filtering is done simply by averaging the samples. This is really a
|
||||
/// poor-man's anti-alias filtering, but it's not so critical in this kind of application
|
||||
/// (it'd also be difficult to design a high-quality filter with steep cut-off at very
|
||||
/// narrow band)
|
||||
int BPMDetect::decimate(SAMPLETYPE *dest, const SAMPLETYPE *src, int numsamples)
|
||||
{
|
||||
int count, outcount;
|
||||
LONG_SAMPLETYPE out;
|
||||
|
||||
assert(channels > 0);
|
||||
assert(decimateBy > 0);
|
||||
outcount = 0;
|
||||
for (count = 0; count < numsamples; count ++)
|
||||
{
|
||||
int j;
|
||||
|
||||
// convert to mono and accumulate
|
||||
for (j = 0; j < channels; j ++)
|
||||
{
|
||||
decimateSum += src[j];
|
||||
}
|
||||
src += j;
|
||||
|
||||
decimateCount ++;
|
||||
if (decimateCount >= decimateBy)
|
||||
{
|
||||
// Store every Nth sample only
|
||||
out = (LONG_SAMPLETYPE)(decimateSum / (decimateBy * channels));
|
||||
decimateSum = 0;
|
||||
decimateCount = 0;
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// check ranges for sure (shouldn't actually be necessary)
|
||||
if (out > 32767)
|
||||
{
|
||||
out = 32767;
|
||||
}
|
||||
else if (out < -32768)
|
||||
{
|
||||
out = -32768;
|
||||
}
|
||||
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||
dest[outcount] = (SAMPLETYPE)out;
|
||||
outcount ++;
|
||||
}
|
||||
}
|
||||
return outcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Calculates autocorrelation function of the sample history buffer
|
||||
void BPMDetect::updateXCorr(int process_samples)
|
||||
{
|
||||
int offs;
|
||||
SAMPLETYPE *pBuffer;
|
||||
|
||||
assert(buffer->numSamples() >= (uint)(process_samples + windowLen));
|
||||
|
||||
pBuffer = buffer->ptrBegin();
|
||||
for (offs = windowStart; offs < windowLen; offs ++)
|
||||
{
|
||||
LONG_SAMPLETYPE sum;
|
||||
int i;
|
||||
|
||||
sum = 0;
|
||||
for (i = 0; i < process_samples; i ++)
|
||||
{
|
||||
sum += pBuffer[i] * pBuffer[i + offs]; // scaling the sub-result shouldn't be necessary
|
||||
}
|
||||
// xcorr[offs] *= xcorr_decay; // decay 'xcorr' here with suitable coefficients
|
||||
// if it's desired that the system adapts automatically to
|
||||
// various bpms, e.g. in processing continouos music stream.
|
||||
// The 'xcorr_decay' should be a value that's smaller than but
|
||||
// close to one, and should also depend on 'process_samples' value.
|
||||
|
||||
xcorr[offs] += (float)sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Calculates envelope of the sample data
|
||||
void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
|
||||
{
|
||||
const static double decay = 0.7f; // decay constant for smoothing the envelope
|
||||
const static double norm = (1 - decay);
|
||||
|
||||
int i;
|
||||
LONG_SAMPLETYPE out;
|
||||
double val;
|
||||
|
||||
for (i = 0; i < numsamples; i ++)
|
||||
{
|
||||
// calc average RMS volume
|
||||
RMSVolumeAccu *= avgdecay;
|
||||
val = (float)fabs((float)samples[i]);
|
||||
RMSVolumeAccu += val * val;
|
||||
|
||||
// cut amplitudes that are below cutoff ~2 times RMS volume
|
||||
// (we're interested in peak values, not the silent moments)
|
||||
if (val < 0.5 * sqrt(RMSVolumeAccu * avgnorm))
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
// smooth amplitude envelope
|
||||
envelopeAccu *= decay;
|
||||
envelopeAccu += val;
|
||||
out = (LONG_SAMPLETYPE)(envelopeAccu * norm);
|
||||
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// cut peaks (shouldn't be necessary though)
|
||||
if (out > 32767) out = 32767;
|
||||
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||
samples[i] = (SAMPLETYPE)out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
|
||||
{
|
||||
SAMPLETYPE decimated[DECIMATED_BLOCK_SAMPLES];
|
||||
|
||||
// iterate so that max INPUT_BLOCK_SAMPLES processed per iteration
|
||||
while (numSamples > 0)
|
||||
{
|
||||
int block;
|
||||
int decSamples;
|
||||
|
||||
block = (numSamples > INPUT_BLOCK_SAMPLES) ? INPUT_BLOCK_SAMPLES : numSamples;
|
||||
|
||||
// decimate. note that converts to mono at the same time
|
||||
decSamples = decimate(decimated, samples, block);
|
||||
samples += block * channels;
|
||||
numSamples -= block;
|
||||
|
||||
// envelope new samples and add them to buffer
|
||||
calcEnvelope(decimated, decSamples);
|
||||
buffer->putSamples(decimated, decSamples);
|
||||
}
|
||||
|
||||
// when the buffer has enought samples for processing...
|
||||
if ((int)buffer->numSamples() > windowLen)
|
||||
{
|
||||
int processLength;
|
||||
|
||||
// how many samples are processed
|
||||
processLength = (int)buffer->numSamples() - windowLen;
|
||||
|
||||
// ... calculate autocorrelations for oldest samples...
|
||||
updateXCorr(processLength);
|
||||
// ... and remove them from the buffer
|
||||
buffer->receiveSamples(processLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BPMDetect::removeBias()
|
||||
{
|
||||
int i;
|
||||
float minval = 1e12f; // arbitrary large number
|
||||
|
||||
for (i = windowStart; i < windowLen; i ++)
|
||||
{
|
||||
if (xcorr[i] < minval)
|
||||
{
|
||||
minval = xcorr[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = windowStart; i < windowLen; i ++)
|
||||
{
|
||||
xcorr[i] -= minval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float BPMDetect::getBpm()
|
||||
{
|
||||
double peakPos;
|
||||
double coeff;
|
||||
PeakFinder peakFinder;
|
||||
|
||||
coeff = 60.0 * ((double)sampleRate / (double)decimateBy);
|
||||
|
||||
// save bpm debug analysis data if debug data enabled
|
||||
_SaveDebugData(xcorr, windowStart, windowLen, coeff);
|
||||
|
||||
// remove bias from xcorr data
|
||||
removeBias();
|
||||
|
||||
// find peak position
|
||||
peakPos = peakFinder.detectPeak(xcorr, windowStart, windowLen);
|
||||
|
||||
assert(decimateBy != 0);
|
||||
if (peakPos < 1e-9) return 0.0; // detection failed.
|
||||
|
||||
// calculate BPM
|
||||
return (float) (coeff / peakPos);
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Beats-per-minute (BPM) detection routine.
|
||||
///
|
||||
/// The beat detection algorithm works as follows:
|
||||
/// - Use function 'inputSamples' to input a chunks of samples to the class for
|
||||
/// analysis. It's a good idea to enter a large sound file or stream in smallish
|
||||
/// chunks of around few kilosamples in order not to extinguish too much RAM memory.
|
||||
/// - Inputted sound data is decimated to approx 500 Hz to reduce calculation burden,
|
||||
/// which is basically ok as low (bass) frequencies mostly determine the beat rate.
|
||||
/// Simple averaging is used for anti-alias filtering because the resulting signal
|
||||
/// quality isn't of that high importance.
|
||||
/// - Decimated sound data is enveloped, i.e. the amplitude shape is detected by
|
||||
/// taking absolute value that's smoothed by sliding average. Signal levels that
|
||||
/// are below a couple of times the general RMS amplitude level are cut away to
|
||||
/// leave only notable peaks there.
|
||||
/// - Repeating sound patterns (e.g. beats) are detected by calculating short-term
|
||||
/// autocorrelation function of the enveloped signal.
|
||||
/// - After whole sound data file has been analyzed as above, the bpm level is
|
||||
/// detected by function 'getBpm' that finds the highest peak of the autocorrelation
|
||||
/// function, calculates it's precise location and converts this reading to bpm's.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-08-30 22:45:25 +0300 (Thu, 30 Aug 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: BPMDetect.cpp 149 2012-08-30 19:45:25Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include "FIFOSampleBuffer.h"
|
||||
#include "PeakFinder.h"
|
||||
#include "BPMDetect.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
#define INPUT_BLOCK_SAMPLES 2048
|
||||
#define DECIMATED_BLOCK_SAMPLES 256
|
||||
|
||||
/// decay constant for calculating RMS volume sliding average approximation
|
||||
/// (time constant is about 10 sec)
|
||||
const float avgdecay = 0.99986f;
|
||||
|
||||
/// Normalization coefficient for calculating RMS sliding average approximation.
|
||||
const float avgnorm = (1 - avgdecay);
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Enable following define to create bpm analysis file:
|
||||
|
||||
// #define _CREATE_BPM_DEBUG_FILE
|
||||
|
||||
#ifdef _CREATE_BPM_DEBUG_FILE
|
||||
|
||||
#define DEBUGFILE_NAME "c:\\temp\\soundtouch-bpm-debug.txt"
|
||||
|
||||
static void _SaveDebugData(const float *data, int minpos, int maxpos, double coeff)
|
||||
{
|
||||
FILE *fptr = fopen(DEBUGFILE_NAME, "wt");
|
||||
int i;
|
||||
|
||||
if (fptr)
|
||||
{
|
||||
printf("\n\nWriting BPM debug data into file " DEBUGFILE_NAME "\n\n");
|
||||
for (i = minpos; i < maxpos; i ++)
|
||||
{
|
||||
fprintf(fptr, "%d\t%.1lf\t%f\n", i, coeff / (double)i, data[i]);
|
||||
}
|
||||
fclose(fptr);
|
||||
}
|
||||
}
|
||||
#else
|
||||
#define _SaveDebugData(a,b,c,d)
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
BPMDetect::BPMDetect(int numChannels, int aSampleRate)
|
||||
{
|
||||
this->sampleRate = aSampleRate;
|
||||
this->channels = numChannels;
|
||||
|
||||
decimateSum = 0;
|
||||
decimateCount = 0;
|
||||
|
||||
envelopeAccu = 0;
|
||||
|
||||
// Initialize RMS volume accumulator to RMS level of 1500 (out of 32768) that's
|
||||
// safe initial RMS signal level value for song data. This value is then adapted
|
||||
// to the actual level during processing.
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// integer samples
|
||||
RMSVolumeAccu = (1500 * 1500) / avgnorm;
|
||||
#else
|
||||
// float samples, scaled to range [-1..+1[
|
||||
RMSVolumeAccu = (0.045f * 0.045f) / avgnorm;
|
||||
#endif
|
||||
|
||||
// choose decimation factor so that result is approx. 1000 Hz
|
||||
decimateBy = sampleRate / 1000;
|
||||
assert(decimateBy > 0);
|
||||
assert(INPUT_BLOCK_SAMPLES < decimateBy * DECIMATED_BLOCK_SAMPLES);
|
||||
|
||||
// Calculate window length & starting item according to desired min & max bpms
|
||||
windowLen = (60 * sampleRate) / (decimateBy * MIN_BPM);
|
||||
windowStart = (60 * sampleRate) / (decimateBy * MAX_BPM);
|
||||
|
||||
assert(windowLen > windowStart);
|
||||
|
||||
// allocate new working objects
|
||||
xcorr = new float[windowLen];
|
||||
memset(xcorr, 0, windowLen * sizeof(float));
|
||||
|
||||
// allocate processing buffer
|
||||
buffer = new FIFOSampleBuffer();
|
||||
// we do processing in mono mode
|
||||
buffer->setChannels(1);
|
||||
buffer->clear();
|
||||
}
|
||||
|
||||
|
||||
|
||||
BPMDetect::~BPMDetect()
|
||||
{
|
||||
delete[] xcorr;
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// convert to mono, low-pass filter & decimate to about 500 Hz.
|
||||
/// return number of outputted samples.
|
||||
///
|
||||
/// Decimation is used to remove the unnecessary frequencies and thus to reduce
|
||||
/// the amount of data needed to be processed as calculating autocorrelation
|
||||
/// function is a very-very heavy operation.
|
||||
///
|
||||
/// Anti-alias filtering is done simply by averaging the samples. This is really a
|
||||
/// poor-man's anti-alias filtering, but it's not so critical in this kind of application
|
||||
/// (it'd also be difficult to design a high-quality filter with steep cut-off at very
|
||||
/// narrow band)
|
||||
int BPMDetect::decimate(SAMPLETYPE *dest, const SAMPLETYPE *src, int numsamples)
|
||||
{
|
||||
int count, outcount;
|
||||
LONG_SAMPLETYPE out;
|
||||
|
||||
assert(channels > 0);
|
||||
assert(decimateBy > 0);
|
||||
outcount = 0;
|
||||
for (count = 0; count < numsamples; count ++)
|
||||
{
|
||||
int j;
|
||||
|
||||
// convert to mono and accumulate
|
||||
for (j = 0; j < channels; j ++)
|
||||
{
|
||||
decimateSum += src[j];
|
||||
}
|
||||
src += j;
|
||||
|
||||
decimateCount ++;
|
||||
if (decimateCount >= decimateBy)
|
||||
{
|
||||
// Store every Nth sample only
|
||||
out = (LONG_SAMPLETYPE)(decimateSum / (decimateBy * channels));
|
||||
decimateSum = 0;
|
||||
decimateCount = 0;
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// check ranges for sure (shouldn't actually be necessary)
|
||||
if (out > 32767)
|
||||
{
|
||||
out = 32767;
|
||||
}
|
||||
else if (out < -32768)
|
||||
{
|
||||
out = -32768;
|
||||
}
|
||||
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||
dest[outcount] = (SAMPLETYPE)out;
|
||||
outcount ++;
|
||||
}
|
||||
}
|
||||
return outcount;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Calculates autocorrelation function of the sample history buffer
|
||||
void BPMDetect::updateXCorr(int process_samples)
|
||||
{
|
||||
int offs;
|
||||
SAMPLETYPE *pBuffer;
|
||||
|
||||
assert(buffer->numSamples() >= (uint)(process_samples + windowLen));
|
||||
|
||||
pBuffer = buffer->ptrBegin();
|
||||
for (offs = windowStart; offs < windowLen; offs ++)
|
||||
{
|
||||
LONG_SAMPLETYPE sum;
|
||||
int i;
|
||||
|
||||
sum = 0;
|
||||
for (i = 0; i < process_samples; i ++)
|
||||
{
|
||||
sum += pBuffer[i] * pBuffer[i + offs]; // scaling the sub-result shouldn't be necessary
|
||||
}
|
||||
// xcorr[offs] *= xcorr_decay; // decay 'xcorr' here with suitable coefficients
|
||||
// if it's desired that the system adapts automatically to
|
||||
// various bpms, e.g. in processing continouos music stream.
|
||||
// The 'xcorr_decay' should be a value that's smaller than but
|
||||
// close to one, and should also depend on 'process_samples' value.
|
||||
|
||||
xcorr[offs] += (float)sum;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Calculates envelope of the sample data
|
||||
void BPMDetect::calcEnvelope(SAMPLETYPE *samples, int numsamples)
|
||||
{
|
||||
const static double decay = 0.7f; // decay constant for smoothing the envelope
|
||||
const static double norm = (1 - decay);
|
||||
|
||||
int i;
|
||||
LONG_SAMPLETYPE out;
|
||||
double val;
|
||||
|
||||
for (i = 0; i < numsamples; i ++)
|
||||
{
|
||||
// calc average RMS volume
|
||||
RMSVolumeAccu *= avgdecay;
|
||||
val = (float)fabs((float)samples[i]);
|
||||
RMSVolumeAccu += val * val;
|
||||
|
||||
// cut amplitudes that are below cutoff ~2 times RMS volume
|
||||
// (we're interested in peak values, not the silent moments)
|
||||
if (val < 0.5 * sqrt(RMSVolumeAccu * avgnorm))
|
||||
{
|
||||
val = 0;
|
||||
}
|
||||
|
||||
// smooth amplitude envelope
|
||||
envelopeAccu *= decay;
|
||||
envelopeAccu += val;
|
||||
out = (LONG_SAMPLETYPE)(envelopeAccu * norm);
|
||||
|
||||
#ifdef SOUNDTOUCH_INTEGER_SAMPLES
|
||||
// cut peaks (shouldn't be necessary though)
|
||||
if (out > 32767) out = 32767;
|
||||
#endif // SOUNDTOUCH_INTEGER_SAMPLES
|
||||
samples[i] = (SAMPLETYPE)out;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BPMDetect::inputSamples(const SAMPLETYPE *samples, int numSamples)
|
||||
{
|
||||
SAMPLETYPE decimated[DECIMATED_BLOCK_SAMPLES];
|
||||
|
||||
// iterate so that max INPUT_BLOCK_SAMPLES processed per iteration
|
||||
while (numSamples > 0)
|
||||
{
|
||||
int block;
|
||||
int decSamples;
|
||||
|
||||
block = (numSamples > INPUT_BLOCK_SAMPLES) ? INPUT_BLOCK_SAMPLES : numSamples;
|
||||
|
||||
// decimate. note that converts to mono at the same time
|
||||
decSamples = decimate(decimated, samples, block);
|
||||
samples += block * channels;
|
||||
numSamples -= block;
|
||||
|
||||
// envelope new samples and add them to buffer
|
||||
calcEnvelope(decimated, decSamples);
|
||||
buffer->putSamples(decimated, decSamples);
|
||||
}
|
||||
|
||||
// when the buffer has enought samples for processing...
|
||||
if ((int)buffer->numSamples() > windowLen)
|
||||
{
|
||||
int processLength;
|
||||
|
||||
// how many samples are processed
|
||||
processLength = (int)buffer->numSamples() - windowLen;
|
||||
|
||||
// ... calculate autocorrelations for oldest samples...
|
||||
updateXCorr(processLength);
|
||||
// ... and remove them from the buffer
|
||||
buffer->receiveSamples(processLength);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void BPMDetect::removeBias()
|
||||
{
|
||||
int i;
|
||||
float minval = 1e12f; // arbitrary large number
|
||||
|
||||
for (i = windowStart; i < windowLen; i ++)
|
||||
{
|
||||
if (xcorr[i] < minval)
|
||||
{
|
||||
minval = xcorr[i];
|
||||
}
|
||||
}
|
||||
|
||||
for (i = windowStart; i < windowLen; i ++)
|
||||
{
|
||||
xcorr[i] -= minval;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
float BPMDetect::getBpm()
|
||||
{
|
||||
double peakPos;
|
||||
double coeff;
|
||||
PeakFinder peakFinder;
|
||||
|
||||
coeff = 60.0 * ((double)sampleRate / (double)decimateBy);
|
||||
|
||||
// save bpm debug analysis data if debug data enabled
|
||||
_SaveDebugData(xcorr, windowStart, windowLen, coeff);
|
||||
|
||||
// remove bias from xcorr data
|
||||
removeBias();
|
||||
|
||||
// find peak position
|
||||
peakPos = peakFinder.detectPeak(xcorr, windowStart, windowLen);
|
||||
|
||||
assert(decimateBy != 0);
|
||||
if (peakPos < 1e-9) return 0.0; // detection failed.
|
||||
|
||||
// calculate BPM
|
||||
return (float) (coeff / peakPos);
|
||||
}
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 138 2012-04-01 20:00:09Z oparviai $
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
|
||||
# set to something if you want other stuff to be included in the distribution tarball
|
||||
EXTRA_DIST=SoundTouch.dsp SoundTouch.dsw SoundTouch.sln SoundTouch.vcproj
|
||||
|
||||
noinst_HEADERS=AAFilter.h cpu_detect.h cpu_detect_x86.cpp FIRFilter.h RateTransposer.h TDStretch.h PeakFinder.h
|
||||
|
||||
lib_LTLIBRARIES=libSoundTouch.la
|
||||
#
|
||||
libSoundTouch_la_SOURCES=AAFilter.cpp FIRFilter.cpp FIFOSampleBuffer.cpp RateTransposer.cpp SoundTouch.cpp TDStretch.cpp cpu_detect_x86.cpp BPMDetect.cpp PeakFinder.cpp
|
||||
|
||||
|
||||
# Compiler flags
|
||||
AM_CXXFLAGS=-O3 -fcheck-new -I../../include
|
||||
|
||||
# Compile the files that need MMX and SSE individually.
|
||||
libSoundTouch_la_LIBADD=libSoundTouchMMX.la libSoundTouchSSE.la
|
||||
noinst_LTLIBRARIES=libSoundTouchMMX.la libSoundTouchSSE.la
|
||||
libSoundTouchMMX_la_SOURCES=mmx_optimized.cpp
|
||||
libSoundTouchSSE_la_SOURCES=sse_optimized.cpp
|
||||
|
||||
# We enable optimizations by default.
|
||||
# If MMX is supported compile with -mmmx.
|
||||
# Do not assume -msse is also supported.
|
||||
if HAVE_MMX
|
||||
libSoundTouchMMX_la_CXXFLAGS = -mmmx $(AM_CXXFLAGS)
|
||||
else
|
||||
libSoundTouchMMX_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
# We enable optimizations by default.
|
||||
# If SSE is supported compile with -msse.
|
||||
if HAVE_SSE
|
||||
libSoundTouchSSE_la_CXXFLAGS = -msse $(AM_CXXFLAGS)
|
||||
else
|
||||
libSoundTouchSSE_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
# Let the user disable optimizations if he wishes to.
|
||||
if !X86_OPTIMIZATIONS
|
||||
libSoundTouchMMX_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
libSoundTouchSSE_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
|
||||
# other linking flags to add
|
||||
# noinst_LTLIBRARIES = libSoundTouchOpt.la
|
||||
# libSoundTouch_la_LIBADD = libSoundTouchOpt.la
|
||||
# libSoundTouchOpt_la_SOURCES = mmx_optimized.cpp sse_optimized.cpp
|
||||
# libSoundTouchOpt_la_CXXFLAGS = -O3 -msse -fcheck-new -I../../include
|
||||
## Process this file with automake to create Makefile.in
|
||||
##
|
||||
## $Id: Makefile.am 138 2012-04-01 20:00:09Z oparviai $
|
||||
##
|
||||
## This file is part of SoundTouch, an audio processing library for pitch/time adjustments
|
||||
##
|
||||
## SoundTouch is free software; you can redistribute it and/or modify it under the
|
||||
## terms of the GNU General Public License as published by the Free Software
|
||||
## Foundation; either version 2 of the License, or (at your option) any later
|
||||
## version.
|
||||
##
|
||||
## SoundTouch is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
## WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
|
||||
## A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
##
|
||||
## You should have received a copy of the GNU General Public License along with
|
||||
## this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
||||
## Place - Suite 330, Boston, MA 02111-1307, USA
|
||||
|
||||
|
||||
include $(top_srcdir)/config/am_include.mk
|
||||
|
||||
|
||||
# set to something if you want other stuff to be included in the distribution tarball
|
||||
EXTRA_DIST=SoundTouch.dsp SoundTouch.dsw SoundTouch.sln SoundTouch.vcproj
|
||||
|
||||
noinst_HEADERS=AAFilter.h cpu_detect.h cpu_detect_x86.cpp FIRFilter.h RateTransposer.h TDStretch.h PeakFinder.h
|
||||
|
||||
lib_LTLIBRARIES=libSoundTouch.la
|
||||
#
|
||||
libSoundTouch_la_SOURCES=AAFilter.cpp FIRFilter.cpp FIFOSampleBuffer.cpp RateTransposer.cpp SoundTouch.cpp TDStretch.cpp cpu_detect_x86.cpp BPMDetect.cpp PeakFinder.cpp
|
||||
|
||||
|
||||
# Compiler flags
|
||||
AM_CXXFLAGS=-O3 -fcheck-new -I../../include
|
||||
|
||||
# Compile the files that need MMX and SSE individually.
|
||||
libSoundTouch_la_LIBADD=libSoundTouchMMX.la libSoundTouchSSE.la
|
||||
noinst_LTLIBRARIES=libSoundTouchMMX.la libSoundTouchSSE.la
|
||||
libSoundTouchMMX_la_SOURCES=mmx_optimized.cpp
|
||||
libSoundTouchSSE_la_SOURCES=sse_optimized.cpp
|
||||
|
||||
# We enable optimizations by default.
|
||||
# If MMX is supported compile with -mmmx.
|
||||
# Do not assume -msse is also supported.
|
||||
if HAVE_MMX
|
||||
libSoundTouchMMX_la_CXXFLAGS = -mmmx $(AM_CXXFLAGS)
|
||||
else
|
||||
libSoundTouchMMX_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
# We enable optimizations by default.
|
||||
# If SSE is supported compile with -msse.
|
||||
if HAVE_SSE
|
||||
libSoundTouchSSE_la_CXXFLAGS = -msse $(AM_CXXFLAGS)
|
||||
else
|
||||
libSoundTouchSSE_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
# Let the user disable optimizations if he wishes to.
|
||||
if !X86_OPTIMIZATIONS
|
||||
libSoundTouchMMX_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
libSoundTouchSSE_la_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
endif
|
||||
|
||||
|
||||
# other linking flags to add
|
||||
# noinst_LTLIBRARIES = libSoundTouchOpt.la
|
||||
# libSoundTouch_la_LIBADD = libSoundTouchOpt.la
|
||||
# libSoundTouchOpt_la_SOURCES = mmx_optimized.cpp sse_optimized.cpp
|
||||
# libSoundTouchOpt_la_CXXFLAGS = -O3 -msse -fcheck-new -I../../include
|
||||
|
||||
@@ -1,276 +1,276 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Peak detection routine.
|
||||
///
|
||||
/// The routine detects highest value on an array of values and calculates the
|
||||
/// precise peak location as a mass-center of the 'hump' around the peak value.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-12-28 21:52:47 +0200 (Fri, 28 Dec 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: PeakFinder.cpp 164 2012-12-28 19:52:47Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "PeakFinder.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
#define max(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
|
||||
PeakFinder::PeakFinder()
|
||||
{
|
||||
minPos = maxPos = 0;
|
||||
}
|
||||
|
||||
|
||||
// Finds real 'top' of a peak hump from neighnourhood of the given 'peakpos'.
|
||||
int PeakFinder::findTop(const float *data, int peakpos) const
|
||||
{
|
||||
int i;
|
||||
int start, end;
|
||||
float refvalue;
|
||||
|
||||
refvalue = data[peakpos];
|
||||
|
||||
// seek within <20>10 points
|
||||
start = peakpos - 10;
|
||||
if (start < minPos) start = minPos;
|
||||
end = peakpos + 10;
|
||||
if (end > maxPos) end = maxPos;
|
||||
|
||||
for (i = start; i <= end; i ++)
|
||||
{
|
||||
if (data[i] > refvalue)
|
||||
{
|
||||
peakpos = i;
|
||||
refvalue = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
// failure if max value is at edges of seek range => it's not peak, it's at slope.
|
||||
if ((peakpos == start) || (peakpos == end)) return 0;
|
||||
|
||||
return peakpos;
|
||||
}
|
||||
|
||||
|
||||
// Finds 'ground level' of a peak hump by starting from 'peakpos' and proceeding
|
||||
// to direction defined by 'direction' until next 'hump' after minimum value will
|
||||
// begin
|
||||
int PeakFinder::findGround(const float *data, int peakpos, int direction) const
|
||||
{
|
||||
int lowpos;
|
||||
int pos;
|
||||
int climb_count;
|
||||
float refvalue;
|
||||
float delta;
|
||||
|
||||
climb_count = 0;
|
||||
refvalue = data[peakpos];
|
||||
lowpos = peakpos;
|
||||
|
||||
pos = peakpos;
|
||||
|
||||
while ((pos > minPos+1) && (pos < maxPos-1))
|
||||
{
|
||||
int prevpos;
|
||||
|
||||
prevpos = pos;
|
||||
pos += direction;
|
||||
|
||||
// calculate derivate
|
||||
delta = data[pos] - data[prevpos];
|
||||
if (delta <= 0)
|
||||
{
|
||||
// going downhill, ok
|
||||
if (climb_count)
|
||||
{
|
||||
climb_count --; // decrease climb count
|
||||
}
|
||||
|
||||
// check if new minimum found
|
||||
if (data[pos] < refvalue)
|
||||
{
|
||||
// new minimum found
|
||||
lowpos = pos;
|
||||
refvalue = data[pos];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// going uphill, increase climbing counter
|
||||
climb_count ++;
|
||||
if (climb_count > 5) break; // we've been climbing too long => it's next uphill => quit
|
||||
}
|
||||
}
|
||||
return lowpos;
|
||||
}
|
||||
|
||||
|
||||
// Find offset where the value crosses the given level, when starting from 'peakpos' and
|
||||
// proceeds to direction defined in 'direction'
|
||||
int PeakFinder::findCrossingLevel(const float *data, float level, int peakpos, int direction) const
|
||||
{
|
||||
float peaklevel;
|
||||
int pos;
|
||||
|
||||
peaklevel = data[peakpos];
|
||||
assert(peaklevel >= level);
|
||||
pos = peakpos;
|
||||
while ((pos >= minPos) && (pos < maxPos))
|
||||
{
|
||||
if (data[pos + direction] < level) return pos; // crossing found
|
||||
pos += direction;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
|
||||
// Calculates the center of mass location of 'data' array items between 'firstPos' and 'lastPos'
|
||||
double PeakFinder::calcMassCenter(const float *data, int firstPos, int lastPos) const
|
||||
{
|
||||
int i;
|
||||
float sum;
|
||||
float wsum;
|
||||
|
||||
sum = 0;
|
||||
wsum = 0;
|
||||
for (i = firstPos; i <= lastPos; i ++)
|
||||
{
|
||||
sum += (float)i * data[i];
|
||||
wsum += data[i];
|
||||
}
|
||||
|
||||
if (wsum < 1e-6) return 0;
|
||||
return sum / wsum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// get exact center of peak near given position by calculating local mass of center
|
||||
double PeakFinder::getPeakCenter(const float *data, int peakpos) const
|
||||
{
|
||||
float peakLevel; // peak level
|
||||
int crosspos1, crosspos2; // position where the peak 'hump' crosses cutting level
|
||||
float cutLevel; // cutting value
|
||||
float groundLevel; // ground level of the peak
|
||||
int gp1, gp2; // bottom positions of the peak 'hump'
|
||||
|
||||
// find ground positions.
|
||||
gp1 = findGround(data, peakpos, -1);
|
||||
gp2 = findGround(data, peakpos, 1);
|
||||
|
||||
groundLevel = 0.5f * (data[gp1] + data[gp2]);
|
||||
peakLevel = data[peakpos];
|
||||
|
||||
// calculate 70%-level of the peak
|
||||
cutLevel = 0.70f * peakLevel + 0.30f * groundLevel;
|
||||
// find mid-level crossings
|
||||
crosspos1 = findCrossingLevel(data, cutLevel, peakpos, -1);
|
||||
crosspos2 = findCrossingLevel(data, cutLevel, peakpos, 1);
|
||||
|
||||
if ((crosspos1 < 0) || (crosspos2 < 0)) return 0; // no crossing, no peak..
|
||||
|
||||
// calculate mass center of the peak surroundings
|
||||
return calcMassCenter(data, crosspos1, crosspos2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double PeakFinder::detectPeak(const float *data, int aminPos, int amaxPos)
|
||||
{
|
||||
|
||||
int i;
|
||||
int peakpos; // position of peak level
|
||||
double highPeak, peak;
|
||||
|
||||
this->minPos = aminPos;
|
||||
this->maxPos = amaxPos;
|
||||
|
||||
// find absolute peak
|
||||
peakpos = minPos;
|
||||
peak = data[minPos];
|
||||
for (i = minPos + 1; i < maxPos; i ++)
|
||||
{
|
||||
if (data[i] > peak)
|
||||
{
|
||||
peak = data[i];
|
||||
peakpos = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate exact location of the highest peak mass center
|
||||
highPeak = getPeakCenter(data, peakpos);
|
||||
peak = highPeak;
|
||||
|
||||
// Now check if the highest peak were in fact harmonic of the true base beat peak
|
||||
// - sometimes the highest peak can be Nth harmonic of the true base peak yet
|
||||
// just a slightly higher than the true base
|
||||
|
||||
for (i = 3; i < 10; i ++)
|
||||
{
|
||||
double peaktmp, harmonic;
|
||||
int i1,i2;
|
||||
|
||||
harmonic = (double)i * 0.5;
|
||||
peakpos = (int)(highPeak / harmonic + 0.5f);
|
||||
if (peakpos < minPos) break;
|
||||
peakpos = findTop(data, peakpos); // seek true local maximum index
|
||||
if (peakpos == 0) continue; // no local max here
|
||||
|
||||
// calculate mass-center of possible harmonic peak
|
||||
peaktmp = getPeakCenter(data, peakpos);
|
||||
|
||||
// accept harmonic peak if
|
||||
// (a) it is found
|
||||
// (b) is within <20>4% of the expected harmonic interval
|
||||
// (c) has at least half x-corr value of the max. peak
|
||||
|
||||
double diff = harmonic * peaktmp / highPeak;
|
||||
if ((diff < 0.96) || (diff > 1.04)) continue; // peak too afar from expected
|
||||
|
||||
// now compare to highest detected peak
|
||||
i1 = (int)(highPeak + 0.5);
|
||||
i2 = (int)(peaktmp + 0.5);
|
||||
if (data[i2] >= 0.4*data[i1])
|
||||
{
|
||||
// The harmonic is at least half as high primary peak,
|
||||
// thus use the harmonic peak instead
|
||||
peak = peaktmp;
|
||||
}
|
||||
}
|
||||
|
||||
return peak;
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Peak detection routine.
|
||||
///
|
||||
/// The routine detects highest value on an array of values and calculates the
|
||||
/// precise peak location as a mass-center of the 'hump' around the peak value.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-12-28 21:52:47 +0200 (Fri, 28 Dec 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: PeakFinder.cpp 164 2012-12-28 19:52:47Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <math.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "PeakFinder.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
#define max(x, y) (((x) > (y)) ? (x) : (y))
|
||||
|
||||
|
||||
PeakFinder::PeakFinder()
|
||||
{
|
||||
minPos = maxPos = 0;
|
||||
}
|
||||
|
||||
|
||||
// Finds real 'top' of a peak hump from neighnourhood of the given 'peakpos'.
|
||||
int PeakFinder::findTop(const float *data, int peakpos) const
|
||||
{
|
||||
int i;
|
||||
int start, end;
|
||||
float refvalue;
|
||||
|
||||
refvalue = data[peakpos];
|
||||
|
||||
// seek within <20>10 points
|
||||
start = peakpos - 10;
|
||||
if (start < minPos) start = minPos;
|
||||
end = peakpos + 10;
|
||||
if (end > maxPos) end = maxPos;
|
||||
|
||||
for (i = start; i <= end; i ++)
|
||||
{
|
||||
if (data[i] > refvalue)
|
||||
{
|
||||
peakpos = i;
|
||||
refvalue = data[i];
|
||||
}
|
||||
}
|
||||
|
||||
// failure if max value is at edges of seek range => it's not peak, it's at slope.
|
||||
if ((peakpos == start) || (peakpos == end)) return 0;
|
||||
|
||||
return peakpos;
|
||||
}
|
||||
|
||||
|
||||
// Finds 'ground level' of a peak hump by starting from 'peakpos' and proceeding
|
||||
// to direction defined by 'direction' until next 'hump' after minimum value will
|
||||
// begin
|
||||
int PeakFinder::findGround(const float *data, int peakpos, int direction) const
|
||||
{
|
||||
int lowpos;
|
||||
int pos;
|
||||
int climb_count;
|
||||
float refvalue;
|
||||
float delta;
|
||||
|
||||
climb_count = 0;
|
||||
refvalue = data[peakpos];
|
||||
lowpos = peakpos;
|
||||
|
||||
pos = peakpos;
|
||||
|
||||
while ((pos > minPos+1) && (pos < maxPos-1))
|
||||
{
|
||||
int prevpos;
|
||||
|
||||
prevpos = pos;
|
||||
pos += direction;
|
||||
|
||||
// calculate derivate
|
||||
delta = data[pos] - data[prevpos];
|
||||
if (delta <= 0)
|
||||
{
|
||||
// going downhill, ok
|
||||
if (climb_count)
|
||||
{
|
||||
climb_count --; // decrease climb count
|
||||
}
|
||||
|
||||
// check if new minimum found
|
||||
if (data[pos] < refvalue)
|
||||
{
|
||||
// new minimum found
|
||||
lowpos = pos;
|
||||
refvalue = data[pos];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// going uphill, increase climbing counter
|
||||
climb_count ++;
|
||||
if (climb_count > 5) break; // we've been climbing too long => it's next uphill => quit
|
||||
}
|
||||
}
|
||||
return lowpos;
|
||||
}
|
||||
|
||||
|
||||
// Find offset where the value crosses the given level, when starting from 'peakpos' and
|
||||
// proceeds to direction defined in 'direction'
|
||||
int PeakFinder::findCrossingLevel(const float *data, float level, int peakpos, int direction) const
|
||||
{
|
||||
float peaklevel;
|
||||
int pos;
|
||||
|
||||
peaklevel = data[peakpos];
|
||||
assert(peaklevel >= level);
|
||||
pos = peakpos;
|
||||
while ((pos >= minPos) && (pos < maxPos))
|
||||
{
|
||||
if (data[pos + direction] < level) return pos; // crossing found
|
||||
pos += direction;
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
|
||||
// Calculates the center of mass location of 'data' array items between 'firstPos' and 'lastPos'
|
||||
double PeakFinder::calcMassCenter(const float *data, int firstPos, int lastPos) const
|
||||
{
|
||||
int i;
|
||||
float sum;
|
||||
float wsum;
|
||||
|
||||
sum = 0;
|
||||
wsum = 0;
|
||||
for (i = firstPos; i <= lastPos; i ++)
|
||||
{
|
||||
sum += (float)i * data[i];
|
||||
wsum += data[i];
|
||||
}
|
||||
|
||||
if (wsum < 1e-6) return 0;
|
||||
return sum / wsum;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// get exact center of peak near given position by calculating local mass of center
|
||||
double PeakFinder::getPeakCenter(const float *data, int peakpos) const
|
||||
{
|
||||
float peakLevel; // peak level
|
||||
int crosspos1, crosspos2; // position where the peak 'hump' crosses cutting level
|
||||
float cutLevel; // cutting value
|
||||
float groundLevel; // ground level of the peak
|
||||
int gp1, gp2; // bottom positions of the peak 'hump'
|
||||
|
||||
// find ground positions.
|
||||
gp1 = findGround(data, peakpos, -1);
|
||||
gp2 = findGround(data, peakpos, 1);
|
||||
|
||||
groundLevel = 0.5f * (data[gp1] + data[gp2]);
|
||||
peakLevel = data[peakpos];
|
||||
|
||||
// calculate 70%-level of the peak
|
||||
cutLevel = 0.70f * peakLevel + 0.30f * groundLevel;
|
||||
// find mid-level crossings
|
||||
crosspos1 = findCrossingLevel(data, cutLevel, peakpos, -1);
|
||||
crosspos2 = findCrossingLevel(data, cutLevel, peakpos, 1);
|
||||
|
||||
if ((crosspos1 < 0) || (crosspos2 < 0)) return 0; // no crossing, no peak..
|
||||
|
||||
// calculate mass center of the peak surroundings
|
||||
return calcMassCenter(data, crosspos1, crosspos2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
double PeakFinder::detectPeak(const float *data, int aminPos, int amaxPos)
|
||||
{
|
||||
|
||||
int i;
|
||||
int peakpos; // position of peak level
|
||||
double highPeak, peak;
|
||||
|
||||
this->minPos = aminPos;
|
||||
this->maxPos = amaxPos;
|
||||
|
||||
// find absolute peak
|
||||
peakpos = minPos;
|
||||
peak = data[minPos];
|
||||
for (i = minPos + 1; i < maxPos; i ++)
|
||||
{
|
||||
if (data[i] > peak)
|
||||
{
|
||||
peak = data[i];
|
||||
peakpos = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate exact location of the highest peak mass center
|
||||
highPeak = getPeakCenter(data, peakpos);
|
||||
peak = highPeak;
|
||||
|
||||
// Now check if the highest peak were in fact harmonic of the true base beat peak
|
||||
// - sometimes the highest peak can be Nth harmonic of the true base peak yet
|
||||
// just a slightly higher than the true base
|
||||
|
||||
for (i = 3; i < 10; i ++)
|
||||
{
|
||||
double peaktmp, harmonic;
|
||||
int i1,i2;
|
||||
|
||||
harmonic = (double)i * 0.5;
|
||||
peakpos = (int)(highPeak / harmonic + 0.5f);
|
||||
if (peakpos < minPos) break;
|
||||
peakpos = findTop(data, peakpos); // seek true local maximum index
|
||||
if (peakpos == 0) continue; // no local max here
|
||||
|
||||
// calculate mass-center of possible harmonic peak
|
||||
peaktmp = getPeakCenter(data, peakpos);
|
||||
|
||||
// accept harmonic peak if
|
||||
// (a) it is found
|
||||
// (b) is within <20>4% of the expected harmonic interval
|
||||
// (c) has at least half x-corr value of the max. peak
|
||||
|
||||
double diff = harmonic * peaktmp / highPeak;
|
||||
if ((diff < 0.96) || (diff > 1.04)) continue; // peak too afar from expected
|
||||
|
||||
// now compare to highest detected peak
|
||||
i1 = (int)(highPeak + 0.5);
|
||||
i2 = (int)(peaktmp + 0.5);
|
||||
if (data[i2] >= 0.4*data[i1])
|
||||
{
|
||||
// The harmonic is at least half as high primary peak,
|
||||
// thus use the harmonic peak instead
|
||||
peak = peaktmp;
|
||||
}
|
||||
}
|
||||
|
||||
return peak;
|
||||
}
|
||||
|
||||
@@ -1,97 +1,97 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// The routine detects highest value on an array of values and calculates the
|
||||
/// precise peak location as a mass-center of the 'hump' around the peak value.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2011-12-30 22:33:46 +0200 (Fri, 30 Dec 2011) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: PeakFinder.h 132 2011-12-30 20:33:46Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PeakFinder_H_
|
||||
#define _PeakFinder_H_
|
||||
|
||||
namespace soundtouch
|
||||
{
|
||||
|
||||
class PeakFinder
|
||||
{
|
||||
protected:
|
||||
/// Min, max allowed peak positions within the data vector
|
||||
int minPos, maxPos;
|
||||
|
||||
/// Calculates the mass center between given vector items.
|
||||
double calcMassCenter(const float *data, ///< Data vector.
|
||||
int firstPos, ///< Index of first vector item beloging to the peak.
|
||||
int lastPos ///< Index of last vector item beloging to the peak.
|
||||
) const;
|
||||
|
||||
/// Finds the data vector index where the monotoniously decreasing signal crosses the
|
||||
/// given level.
|
||||
int findCrossingLevel(const float *data, ///< Data vector.
|
||||
float level, ///< Goal crossing level.
|
||||
int peakpos, ///< Peak position index within the data vector.
|
||||
int direction /// Direction where to proceed from the peak: 1 = right, -1 = left.
|
||||
) const;
|
||||
|
||||
// Finds real 'top' of a peak hump from neighnourhood of the given 'peakpos'.
|
||||
int findTop(const float *data, int peakpos) const;
|
||||
|
||||
|
||||
/// Finds the 'ground' level, i.e. smallest level between two neighbouring peaks, to right-
|
||||
/// or left-hand side of the given peak position.
|
||||
int findGround(const float *data, /// Data vector.
|
||||
int peakpos, /// Peak position index within the data vector.
|
||||
int direction /// Direction where to proceed from the peak: 1 = right, -1 = left.
|
||||
) const;
|
||||
|
||||
/// get exact center of peak near given position by calculating local mass of center
|
||||
double getPeakCenter(const float *data, int peakpos) const;
|
||||
|
||||
public:
|
||||
/// Constructor.
|
||||
PeakFinder();
|
||||
|
||||
/// Detect exact peak position of the data vector by finding the largest peak 'hump'
|
||||
/// and calculating the mass-center location of the peak hump.
|
||||
///
|
||||
/// \return The location of the largest base harmonic peak hump.
|
||||
double detectPeak(const float *data, /// Data vector to be analyzed. The data vector has
|
||||
/// to be at least 'maxPos' items long.
|
||||
int minPos, ///< Min allowed peak location within the vector data.
|
||||
int maxPos ///< Max allowed peak location within the vector data.
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _PeakFinder_H_
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// The routine detects highest value on an array of values and calculates the
|
||||
/// precise peak location as a mass-center of the 'hump' around the peak value.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2011-12-30 22:33:46 +0200 (Fri, 30 Dec 2011) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: PeakFinder.h 132 2011-12-30 20:33:46Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _PeakFinder_H_
|
||||
#define _PeakFinder_H_
|
||||
|
||||
namespace soundtouch
|
||||
{
|
||||
|
||||
class PeakFinder
|
||||
{
|
||||
protected:
|
||||
/// Min, max allowed peak positions within the data vector
|
||||
int minPos, maxPos;
|
||||
|
||||
/// Calculates the mass center between given vector items.
|
||||
double calcMassCenter(const float *data, ///< Data vector.
|
||||
int firstPos, ///< Index of first vector item beloging to the peak.
|
||||
int lastPos ///< Index of last vector item beloging to the peak.
|
||||
) const;
|
||||
|
||||
/// Finds the data vector index where the monotoniously decreasing signal crosses the
|
||||
/// given level.
|
||||
int findCrossingLevel(const float *data, ///< Data vector.
|
||||
float level, ///< Goal crossing level.
|
||||
int peakpos, ///< Peak position index within the data vector.
|
||||
int direction /// Direction where to proceed from the peak: 1 = right, -1 = left.
|
||||
) const;
|
||||
|
||||
// Finds real 'top' of a peak hump from neighnourhood of the given 'peakpos'.
|
||||
int findTop(const float *data, int peakpos) const;
|
||||
|
||||
|
||||
/// Finds the 'ground' level, i.e. smallest level between two neighbouring peaks, to right-
|
||||
/// or left-hand side of the given peak position.
|
||||
int findGround(const float *data, /// Data vector.
|
||||
int peakpos, /// Peak position index within the data vector.
|
||||
int direction /// Direction where to proceed from the peak: 1 = right, -1 = left.
|
||||
) const;
|
||||
|
||||
/// get exact center of peak near given position by calculating local mass of center
|
||||
double getPeakCenter(const float *data, int peakpos) const;
|
||||
|
||||
public:
|
||||
/// Constructor.
|
||||
PeakFinder();
|
||||
|
||||
/// Detect exact peak position of the data vector by finding the largest peak 'hump'
|
||||
/// and calculating the mass-center location of the peak hump.
|
||||
///
|
||||
/// \return The location of the largest base harmonic peak hump.
|
||||
double detectPeak(const float *data, /// Data vector to be analyzed. The data vector has
|
||||
/// to be at least 'maxPos' items long.
|
||||
int minPos, ///< Min allowed peak location within the vector data.
|
||||
int maxPos ///< Max allowed peak location within the vector data.
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // _PeakFinder_H_
|
||||
|
||||
@@ -1,137 +1,137 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Generic version of the x86 CPU extension detection routine.
|
||||
///
|
||||
/// This file is for GNU & other non-Windows compilers, see 'cpu_detect_x86_win.cpp'
|
||||
/// for the Microsoft compiler version.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-11-08 20:44:37 +0200 (Thu, 08 Nov 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: cpu_detect_x86.cpp 159 2012-11-08 18:44:37Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "cpu_detect.h"
|
||||
#include "STTypes.h"
|
||||
|
||||
#if defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
// gcc
|
||||
#include "cpuid.h"
|
||||
#elif defined(_M_IX86)
|
||||
// windows non-gcc
|
||||
#include <intrin.h>
|
||||
#define bit_MMX (1 << 23)
|
||||
#define bit_SSE (1 << 25)
|
||||
#define bit_SSE2 (1 << 26)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// processor instructions extension detection routines
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Flag variable indicating whick ISA extensions are disabled (for debugging)
|
||||
static uint _dwDisabledISA = 0x00; // 0xffffffff; //<- use this to disable all extensions
|
||||
|
||||
// Disables given set of instruction extensions. See SUPPORT_... defines.
|
||||
void disableExtensions(uint dwDisableMask)
|
||||
{
|
||||
_dwDisabledISA = dwDisableMask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Checks which instruction set extensions are supported by the CPU.
|
||||
uint detectCPUextensions(void)
|
||||
{
|
||||
/// If building for a 64bit system (no Itanium) and the user wants optimizations.
|
||||
/// Return the OR of SUPPORT_{MMX,SSE,SSE2}. 11001 or 0x19.
|
||||
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||
#if ((defined(__GNUC__) && defined(__x86_64__)) \
|
||||
|| defined(_M_X64)) \
|
||||
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
return 0x19 & ~_dwDisabledISA;
|
||||
|
||||
/// If building for a 32bit system and the user wants optimizations.
|
||||
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||
#elif ((defined(__GNUC__) && defined(__i386__)) \
|
||||
|| defined(_M_IX86)) \
|
||||
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
|
||||
if (_dwDisabledISA == 0xffffffff) return 0;
|
||||
|
||||
uint res = 0;
|
||||
|
||||
#if defined(__GNUC__)
|
||||
// GCC version of cpuid. Requires GCC 4.3.0 or later for __cpuid intrinsic support.
|
||||
uint eax, ebx, ecx, edx; // unsigned int is the standard type. uint is defined by the compiler and not guaranteed to be portable.
|
||||
|
||||
// Check if no cpuid support.
|
||||
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) return 0; // always disable extensions.
|
||||
|
||||
if (edx & bit_MMX) res = res | SUPPORT_MMX;
|
||||
if (edx & bit_SSE) res = res | SUPPORT_SSE;
|
||||
if (edx & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||
|
||||
#else
|
||||
// Window / VS version of cpuid. Notice that Visual Studio 2005 or later required
|
||||
// for __cpuid intrinsic support.
|
||||
int reg[4] = {-1};
|
||||
|
||||
// Check if no cpuid support.
|
||||
__cpuid(reg,0);
|
||||
if ((unsigned int)reg[0] == 0) return 0; // always disable extensions.
|
||||
|
||||
__cpuid(reg,1);
|
||||
if ((unsigned int)reg[3] & bit_MMX) res = res | SUPPORT_MMX;
|
||||
if ((unsigned int)reg[3] & bit_SSE) res = res | SUPPORT_SSE;
|
||||
if ((unsigned int)reg[3] & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||
|
||||
#endif
|
||||
|
||||
return res & ~_dwDisabledISA;
|
||||
|
||||
#else
|
||||
|
||||
/// One of these is true:
|
||||
/// 1) We don't want optimizations.
|
||||
/// 2) Using an unsupported compiler.
|
||||
/// 3) Running on a non-x86 platform.
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// Generic version of the x86 CPU extension detection routine.
|
||||
///
|
||||
/// This file is for GNU & other non-Windows compilers, see 'cpu_detect_x86_win.cpp'
|
||||
/// for the Microsoft compiler version.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Last changed : $Date: 2012-11-08 20:44:37 +0200 (Thu, 08 Nov 2012) $
|
||||
// File revision : $Revision: 4 $
|
||||
//
|
||||
// $Id: cpu_detect_x86.cpp 159 2012-11-08 18:44:37Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "cpu_detect.h"
|
||||
#include "STTypes.h"
|
||||
|
||||
#if defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
|
||||
#if defined(__GNUC__) && defined(__i386__)
|
||||
// gcc
|
||||
#include "cpuid.h"
|
||||
#elif defined(_M_IX86)
|
||||
// windows non-gcc
|
||||
#include <intrin.h>
|
||||
#define bit_MMX (1 << 23)
|
||||
#define bit_SSE (1 << 25)
|
||||
#define bit_SSE2 (1 << 26)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// processor instructions extension detection routines
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Flag variable indicating whick ISA extensions are disabled (for debugging)
|
||||
static uint _dwDisabledISA = 0x00; // 0xffffffff; //<- use this to disable all extensions
|
||||
|
||||
// Disables given set of instruction extensions. See SUPPORT_... defines.
|
||||
void disableExtensions(uint dwDisableMask)
|
||||
{
|
||||
_dwDisabledISA = dwDisableMask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// Checks which instruction set extensions are supported by the CPU.
|
||||
uint detectCPUextensions(void)
|
||||
{
|
||||
/// If building for a 64bit system (no Itanium) and the user wants optimizations.
|
||||
/// Return the OR of SUPPORT_{MMX,SSE,SSE2}. 11001 or 0x19.
|
||||
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||
#if ((defined(__GNUC__) && defined(__x86_64__)) \
|
||||
|| defined(_M_X64)) \
|
||||
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
return 0x19 & ~_dwDisabledISA;
|
||||
|
||||
/// If building for a 32bit system and the user wants optimizations.
|
||||
/// Keep the _dwDisabledISA test (2 more operations, could be eliminated).
|
||||
#elif ((defined(__GNUC__) && defined(__i386__)) \
|
||||
|| defined(_M_IX86)) \
|
||||
&& defined(SOUNDTOUCH_ALLOW_X86_OPTIMIZATIONS)
|
||||
|
||||
if (_dwDisabledISA == 0xffffffff) return 0;
|
||||
|
||||
uint res = 0;
|
||||
|
||||
#if defined(__GNUC__)
|
||||
// GCC version of cpuid. Requires GCC 4.3.0 or later for __cpuid intrinsic support.
|
||||
uint eax, ebx, ecx, edx; // unsigned int is the standard type. uint is defined by the compiler and not guaranteed to be portable.
|
||||
|
||||
// Check if no cpuid support.
|
||||
if (!__get_cpuid (1, &eax, &ebx, &ecx, &edx)) return 0; // always disable extensions.
|
||||
|
||||
if (edx & bit_MMX) res = res | SUPPORT_MMX;
|
||||
if (edx & bit_SSE) res = res | SUPPORT_SSE;
|
||||
if (edx & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||
|
||||
#else
|
||||
// Window / VS version of cpuid. Notice that Visual Studio 2005 or later required
|
||||
// for __cpuid intrinsic support.
|
||||
int reg[4] = {-1};
|
||||
|
||||
// Check if no cpuid support.
|
||||
__cpuid(reg,0);
|
||||
if ((unsigned int)reg[0] == 0) return 0; // always disable extensions.
|
||||
|
||||
__cpuid(reg,1);
|
||||
if ((unsigned int)reg[3] & bit_MMX) res = res | SUPPORT_MMX;
|
||||
if ((unsigned int)reg[3] & bit_SSE) res = res | SUPPORT_SSE;
|
||||
if ((unsigned int)reg[3] & bit_SSE2) res = res | SUPPORT_SSE2;
|
||||
|
||||
#endif
|
||||
|
||||
return res & ~_dwDisabledISA;
|
||||
|
||||
#else
|
||||
|
||||
/// One of these is true:
|
||||
/// 1) We don't want optimizations.
|
||||
/// 2) Using an unsupported compiler.
|
||||
/// 3) Running on a non-x86 platform.
|
||||
return 0;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -1,338 +1,338 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundTouch DLL wrapper - wraps SoundTouch routines into a Dynamic Load
|
||||
/// Library interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.cpp 96 2010-12-12 19:12:12Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include "SoundTouchDLL.h"
|
||||
#include "soundtouch.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
BOOL APIENTRY DllMain( HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwMagic;
|
||||
SoundTouch *pst;
|
||||
} STHANDLE;
|
||||
|
||||
#define STMAGIC 0x1770C001
|
||||
|
||||
SOUNDTOUCHDLL_API HANDLE __stdcall soundtouch_createInstance()
|
||||
{
|
||||
STHANDLE *tmp = new STHANDLE;
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
tmp->dwMagic = STMAGIC;
|
||||
tmp->pst = new SoundTouch();
|
||||
if (tmp->pst == NULL)
|
||||
{
|
||||
delete tmp;
|
||||
tmp = NULL;
|
||||
}
|
||||
}
|
||||
return (HANDLE)tmp;
|
||||
}
|
||||
|
||||
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_destroyInstance(HANDLE h)
|
||||
{
|
||||
/*
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
*/
|
||||
|
||||
/*
|
||||
sth->dwMagic = 0;
|
||||
delete sth->pst;
|
||||
sth->pst = NULL;
|
||||
delete sth;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version string
|
||||
SOUNDTOUCHDLL_API const char *__stdcall soundtouch_getVersionString()
|
||||
{
|
||||
return SoundTouch::getVersionString();
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version string - alternative function for
|
||||
/// environments that can't properly handle character string as return value
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_getVersionString2(char* versionString, int bufferSize)
|
||||
{
|
||||
strncpy(versionString, SoundTouch::getVersionString(), bufferSize - 1);
|
||||
versionString[bufferSize - 1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version Id
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_getVersionId()
|
||||
{
|
||||
return SoundTouch::getVersionId();
|
||||
}
|
||||
|
||||
/// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
/// represent slower rate, larger faster rates.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRate(HANDLE h, float newRate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setRate(newRate);
|
||||
}
|
||||
|
||||
|
||||
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
/// represent slower tempo, larger faster tempo.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempo(HANDLE h, float newTempo)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setTempo(newTempo);
|
||||
}
|
||||
|
||||
/// Sets new rate control value as a difference in percents compared
|
||||
/// to the original rate (-50 .. +100 %)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRateChange(HANDLE h, float newRate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setRateChange(newRate);
|
||||
}
|
||||
|
||||
/// Sets new tempo control value as a difference in percents compared
|
||||
/// to the original tempo (-50 .. +100 %)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempoChange(HANDLE h, float newTempo)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setTempoChange(newTempo);
|
||||
}
|
||||
|
||||
/// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
/// represent lower pitches, larger values higher pitch.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitch(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitch(newPitch);
|
||||
}
|
||||
|
||||
/// Sets pitch change in octaves compared to the original pitch
|
||||
/// (-1.00 .. +1.00)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchOctaves(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitchOctaves(newPitch);
|
||||
}
|
||||
|
||||
/// Sets pitch change in semi-tones compared to the original pitch
|
||||
/// (-12 .. +12)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchSemiTones(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitchSemiTones(newPitch);
|
||||
}
|
||||
|
||||
|
||||
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setChannels(HANDLE h, uint numChannels)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setChannels(numChannels);
|
||||
}
|
||||
|
||||
/// Sets sample rate.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setSampleRate(HANDLE h, uint srate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setSampleRate(srate);
|
||||
}
|
||||
|
||||
/// Flushes the last samples from the processing pipeline to the output.
|
||||
/// Clears also the internal processing buffers.
|
||||
//
|
||||
/// Note: This function is meant for extracting the last samples of a sound
|
||||
/// stream. This function may introduce additional blank samples in the end
|
||||
/// of the sound stream, and thus it's not recommended to call this function
|
||||
/// in the middle of a sound stream.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_flush(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->flush();
|
||||
}
|
||||
|
||||
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
/// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
/// calling this function, otherwise throws a runtime_error exception.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_putSamples(HANDLE h,
|
||||
const SAMPLETYPE *samples, ///< Pointer to sample buffer.
|
||||
uint numSamples ///< Number of samples in buffer. Notice
|
||||
///< that in case of stereo-sound a single sample
|
||||
///< contains data for both channels.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->putSamples(samples, numSamples);
|
||||
}
|
||||
|
||||
/// Clears all the samples in the object's output and internal processing
|
||||
/// buffers.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_clear(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->clear();
|
||||
}
|
||||
|
||||
/// Changes a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return 'TRUE' if the setting was succesfully changed
|
||||
SOUNDTOUCHDLL_API BOOL __stdcall soundtouch_setSetting(HANDLE h,
|
||||
int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||
int value ///< New setting value.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return FALSE;
|
||||
|
||||
return sth->pst->setSetting(settingId, value);
|
||||
}
|
||||
|
||||
/// Reads a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return the setting value.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_getSetting(HANDLE h,
|
||||
int settingId ///< Setting ID number, see SETTING_... defines.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return -1;
|
||||
|
||||
return sth->pst->getSetting(settingId);
|
||||
}
|
||||
|
||||
|
||||
/// Returns number of samples currently unprocessed.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_numUnprocessedSamples(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
return sth->pst->numUnprocessedSamples();
|
||||
}
|
||||
|
||||
|
||||
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
/// sample buffer without copying them anywhere.
|
||||
///
|
||||
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
/// with 'ptrBegin' function.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_receiveSamples(HANDLE h,
|
||||
SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
|
||||
uint maxSamples ///< How many samples to receive at max.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
if (outBuffer)
|
||||
{
|
||||
return sth->pst->receiveSamples(outBuffer, maxSamples);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sth->pst->receiveSamples(maxSamples);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns number of samples currently available.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_numSamples(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
return sth->pst->numSamples();
|
||||
}
|
||||
|
||||
|
||||
/// Returns nonzero if there aren't any samples available for outputting.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_isEmpty(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return -1;
|
||||
|
||||
return sth->pst->isEmpty();
|
||||
}
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundTouch DLL wrapper - wraps SoundTouch routines into a Dynamic Load
|
||||
/// Library interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.cpp 96 2010-12-12 19:12:12Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <windows.h>
|
||||
#include <string.h>
|
||||
#include "SoundTouchDLL.h"
|
||||
#include "soundtouch.h"
|
||||
|
||||
using namespace soundtouch;
|
||||
|
||||
BOOL APIENTRY DllMain( HANDLE hModule,
|
||||
DWORD ul_reason_for_call,
|
||||
LPVOID lpReserved
|
||||
)
|
||||
{
|
||||
switch (ul_reason_for_call)
|
||||
{
|
||||
case DLL_PROCESS_ATTACH:
|
||||
case DLL_THREAD_ATTACH:
|
||||
case DLL_THREAD_DETACH:
|
||||
case DLL_PROCESS_DETACH:
|
||||
break;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
//////////////
|
||||
|
||||
typedef struct
|
||||
{
|
||||
DWORD dwMagic;
|
||||
SoundTouch *pst;
|
||||
} STHANDLE;
|
||||
|
||||
#define STMAGIC 0x1770C001
|
||||
|
||||
SOUNDTOUCHDLL_API HANDLE __stdcall soundtouch_createInstance()
|
||||
{
|
||||
STHANDLE *tmp = new STHANDLE;
|
||||
|
||||
if (tmp)
|
||||
{
|
||||
tmp->dwMagic = STMAGIC;
|
||||
tmp->pst = new SoundTouch();
|
||||
if (tmp->pst == NULL)
|
||||
{
|
||||
delete tmp;
|
||||
tmp = NULL;
|
||||
}
|
||||
}
|
||||
return (HANDLE)tmp;
|
||||
}
|
||||
|
||||
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_destroyInstance(HANDLE h)
|
||||
{
|
||||
/*
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
*/
|
||||
|
||||
/*
|
||||
sth->dwMagic = 0;
|
||||
delete sth->pst;
|
||||
sth->pst = NULL;
|
||||
delete sth;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version string
|
||||
SOUNDTOUCHDLL_API const char *__stdcall soundtouch_getVersionString()
|
||||
{
|
||||
return SoundTouch::getVersionString();
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version string - alternative function for
|
||||
/// environments that can't properly handle character string as return value
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_getVersionString2(char* versionString, int bufferSize)
|
||||
{
|
||||
strncpy(versionString, SoundTouch::getVersionString(), bufferSize - 1);
|
||||
versionString[bufferSize - 1] = 0;
|
||||
}
|
||||
|
||||
|
||||
/// Get SoundTouch library version Id
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_getVersionId()
|
||||
{
|
||||
return SoundTouch::getVersionId();
|
||||
}
|
||||
|
||||
/// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
/// represent slower rate, larger faster rates.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRate(HANDLE h, float newRate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setRate(newRate);
|
||||
}
|
||||
|
||||
|
||||
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
/// represent slower tempo, larger faster tempo.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempo(HANDLE h, float newTempo)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setTempo(newTempo);
|
||||
}
|
||||
|
||||
/// Sets new rate control value as a difference in percents compared
|
||||
/// to the original rate (-50 .. +100 %)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRateChange(HANDLE h, float newRate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setRateChange(newRate);
|
||||
}
|
||||
|
||||
/// Sets new tempo control value as a difference in percents compared
|
||||
/// to the original tempo (-50 .. +100 %)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempoChange(HANDLE h, float newTempo)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setTempoChange(newTempo);
|
||||
}
|
||||
|
||||
/// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
/// represent lower pitches, larger values higher pitch.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitch(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitch(newPitch);
|
||||
}
|
||||
|
||||
/// Sets pitch change in octaves compared to the original pitch
|
||||
/// (-1.00 .. +1.00)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchOctaves(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitchOctaves(newPitch);
|
||||
}
|
||||
|
||||
/// Sets pitch change in semi-tones compared to the original pitch
|
||||
/// (-12 .. +12)
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchSemiTones(HANDLE h, float newPitch)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setPitchSemiTones(newPitch);
|
||||
}
|
||||
|
||||
|
||||
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setChannels(HANDLE h, uint numChannels)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setChannels(numChannels);
|
||||
}
|
||||
|
||||
/// Sets sample rate.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setSampleRate(HANDLE h, uint srate)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->setSampleRate(srate);
|
||||
}
|
||||
|
||||
/// Flushes the last samples from the processing pipeline to the output.
|
||||
/// Clears also the internal processing buffers.
|
||||
//
|
||||
/// Note: This function is meant for extracting the last samples of a sound
|
||||
/// stream. This function may introduce additional blank samples in the end
|
||||
/// of the sound stream, and thus it's not recommended to call this function
|
||||
/// in the middle of a sound stream.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_flush(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->flush();
|
||||
}
|
||||
|
||||
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
/// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
/// calling this function, otherwise throws a runtime_error exception.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_putSamples(HANDLE h,
|
||||
const SAMPLETYPE *samples, ///< Pointer to sample buffer.
|
||||
uint numSamples ///< Number of samples in buffer. Notice
|
||||
///< that in case of stereo-sound a single sample
|
||||
///< contains data for both channels.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->putSamples(samples, numSamples);
|
||||
}
|
||||
|
||||
/// Clears all the samples in the object's output and internal processing
|
||||
/// buffers.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_clear(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return;
|
||||
|
||||
sth->pst->clear();
|
||||
}
|
||||
|
||||
/// Changes a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return 'TRUE' if the setting was succesfully changed
|
||||
SOUNDTOUCHDLL_API BOOL __stdcall soundtouch_setSetting(HANDLE h,
|
||||
int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||
int value ///< New setting value.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return FALSE;
|
||||
|
||||
return sth->pst->setSetting(settingId, value);
|
||||
}
|
||||
|
||||
/// Reads a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return the setting value.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_getSetting(HANDLE h,
|
||||
int settingId ///< Setting ID number, see SETTING_... defines.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return -1;
|
||||
|
||||
return sth->pst->getSetting(settingId);
|
||||
}
|
||||
|
||||
|
||||
/// Returns number of samples currently unprocessed.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_numUnprocessedSamples(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
return sth->pst->numUnprocessedSamples();
|
||||
}
|
||||
|
||||
|
||||
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
/// sample buffer without copying them anywhere.
|
||||
///
|
||||
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
/// with 'ptrBegin' function.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_receiveSamples(HANDLE h,
|
||||
SAMPLETYPE *outBuffer, ///< Buffer where to copy output samples.
|
||||
uint maxSamples ///< How many samples to receive at max.
|
||||
)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
if (outBuffer)
|
||||
{
|
||||
return sth->pst->receiveSamples(outBuffer, maxSamples);
|
||||
}
|
||||
else
|
||||
{
|
||||
return sth->pst->receiveSamples(maxSamples);
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns number of samples currently available.
|
||||
SOUNDTOUCHDLL_API uint __stdcall soundtouch_numSamples(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return 0;
|
||||
|
||||
return sth->pst->numSamples();
|
||||
}
|
||||
|
||||
|
||||
/// Returns nonzero if there aren't any samples available for outputting.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_isEmpty(HANDLE h)
|
||||
{
|
||||
STHANDLE *sth = (STHANDLE*)h;
|
||||
if (sth->dwMagic != STMAGIC) return -1;
|
||||
|
||||
return sth->pst->isEmpty();
|
||||
}
|
||||
|
||||
@@ -1,168 +1,168 @@
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundTouch DLL wrapper - wraps SoundTouch routines into a Dynamic Load
|
||||
/// Library interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.h 94 2010-12-12 18:28:49Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _SoundTouchDLL_h_
|
||||
#define _SoundTouchDLL_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DLL_EXPORTS
|
||||
#define SOUNDTOUCHDLL_API __declspec(dllexport)
|
||||
#else
|
||||
#define SOUNDTOUCHDLL_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
typedef void * HANDLE;
|
||||
|
||||
/// Create a new instance of SoundTouch processor.
|
||||
SOUNDTOUCHDLL_API HANDLE __stdcall soundtouch_createInstance();
|
||||
|
||||
/// Destroys a SoundTouch processor instance.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_destroyInstance(HANDLE h);
|
||||
|
||||
/// Get SoundTouch library version string
|
||||
SOUNDTOUCHDLL_API const char *__stdcall soundtouch_getVersionString();
|
||||
|
||||
/// Get SoundTouch library version string - alternative function for
|
||||
/// environments that can't properly handle character string as return value
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_getVersionString2(char* versionString, int bufferSize);
|
||||
|
||||
/// Get SoundTouch library version Id
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_getVersionId();
|
||||
|
||||
/// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
/// represent slower rate, larger faster rates.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRate(HANDLE h, float newRate);
|
||||
|
||||
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
/// represent slower tempo, larger faster tempo.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempo(HANDLE h, float newTempo);
|
||||
|
||||
/// Sets new rate control value as a difference in percents compared
|
||||
/// to the original rate (-50 .. +100 %);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRateChange(HANDLE h, float newRate);
|
||||
|
||||
/// Sets new tempo control value as a difference in percents compared
|
||||
/// to the original tempo (-50 .. +100 %);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempoChange(HANDLE h, float newTempo);
|
||||
|
||||
/// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
/// represent lower pitches, larger values higher pitch.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitch(HANDLE h, float newPitch);
|
||||
|
||||
/// Sets pitch change in octaves compared to the original pitch
|
||||
/// (-1.00 .. +1.00);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchOctaves(HANDLE h, float newPitch);
|
||||
|
||||
/// Sets pitch change in semi-tones compared to the original pitch
|
||||
/// (-12 .. +12);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchSemiTones(HANDLE h, float newPitch);
|
||||
|
||||
|
||||
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setChannels(HANDLE h, unsigned int numChannels);
|
||||
|
||||
/// Sets sample rate.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setSampleRate(HANDLE h, unsigned int srate);
|
||||
|
||||
/// Flushes the last samples from the processing pipeline to the output.
|
||||
/// Clears also the internal processing buffers.
|
||||
//
|
||||
/// Note: This function is meant for extracting the last samples of a sound
|
||||
/// stream. This function may introduce additional blank samples in the end
|
||||
/// of the sound stream, and thus it's not recommended to call this function
|
||||
/// in the middle of a sound stream.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_flush(HANDLE h);
|
||||
|
||||
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
/// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
/// calling this function, otherwise throws a runtime_error exception.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_putSamples(HANDLE h,
|
||||
const float *samples, ///< Pointer to sample buffer.
|
||||
unsigned int numSamples ///< Number of samples in buffer. Notice
|
||||
///< that in case of stereo-sound a single sample
|
||||
///< contains data for both channels.
|
||||
);
|
||||
|
||||
/// Clears all the samples in the object's output and internal processing
|
||||
/// buffers.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_clear(HANDLE h);
|
||||
|
||||
/// Changes a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return 'TRUE' if the setting was succesfully changed
|
||||
SOUNDTOUCHDLL_API BOOL __stdcall soundtouch_setSetting(HANDLE h,
|
||||
int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||
int value ///< New setting value.
|
||||
);
|
||||
|
||||
/// Reads a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return the setting value.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_getSetting(HANDLE h,
|
||||
int settingId ///< Setting ID number, see SETTING_... defines.
|
||||
);
|
||||
|
||||
|
||||
/// Returns number of samples currently unprocessed.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_numUnprocessedSamples(HANDLE h);
|
||||
|
||||
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
/// sample buffer without copying them anywhere.
|
||||
///
|
||||
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
/// with 'ptrBegin' function.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_receiveSamples(HANDLE h,
|
||||
float *outBuffer, ///< Buffer where to copy output samples.
|
||||
unsigned int maxSamples ///< How many samples to receive at max.
|
||||
);
|
||||
|
||||
/// Returns number of samples currently available.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_numSamples(HANDLE h);
|
||||
|
||||
/// Returns nonzero if there aren't any samples available for outputting.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_isEmpty(HANDLE h);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SoundTouchDLL_h_
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
///
|
||||
/// SoundTouch DLL wrapper - wraps SoundTouch routines into a Dynamic Load
|
||||
/// Library interface.
|
||||
///
|
||||
/// Author : Copyright (c) Olli Parviainen
|
||||
/// Author e-mail : oparviai 'at' iki.fi
|
||||
/// SoundTouch WWW: http://www.surina.net/soundtouch
|
||||
///
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.h 94 2010-12-12 18:28:49Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef _SoundTouchDLL_h_
|
||||
#define _SoundTouchDLL_h_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifdef DLL_EXPORTS
|
||||
#define SOUNDTOUCHDLL_API __declspec(dllexport)
|
||||
#else
|
||||
#define SOUNDTOUCHDLL_API __declspec(dllimport)
|
||||
#endif
|
||||
|
||||
typedef void * HANDLE;
|
||||
|
||||
/// Create a new instance of SoundTouch processor.
|
||||
SOUNDTOUCHDLL_API HANDLE __stdcall soundtouch_createInstance();
|
||||
|
||||
/// Destroys a SoundTouch processor instance.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_destroyInstance(HANDLE h);
|
||||
|
||||
/// Get SoundTouch library version string
|
||||
SOUNDTOUCHDLL_API const char *__stdcall soundtouch_getVersionString();
|
||||
|
||||
/// Get SoundTouch library version string - alternative function for
|
||||
/// environments that can't properly handle character string as return value
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_getVersionString2(char* versionString, int bufferSize);
|
||||
|
||||
/// Get SoundTouch library version Id
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_getVersionId();
|
||||
|
||||
/// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
/// represent slower rate, larger faster rates.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRate(HANDLE h, float newRate);
|
||||
|
||||
/// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
/// represent slower tempo, larger faster tempo.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempo(HANDLE h, float newTempo);
|
||||
|
||||
/// Sets new rate control value as a difference in percents compared
|
||||
/// to the original rate (-50 .. +100 %);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setRateChange(HANDLE h, float newRate);
|
||||
|
||||
/// Sets new tempo control value as a difference in percents compared
|
||||
/// to the original tempo (-50 .. +100 %);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setTempoChange(HANDLE h, float newTempo);
|
||||
|
||||
/// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
/// represent lower pitches, larger values higher pitch.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitch(HANDLE h, float newPitch);
|
||||
|
||||
/// Sets pitch change in octaves compared to the original pitch
|
||||
/// (-1.00 .. +1.00);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchOctaves(HANDLE h, float newPitch);
|
||||
|
||||
/// Sets pitch change in semi-tones compared to the original pitch
|
||||
/// (-12 .. +12);
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setPitchSemiTones(HANDLE h, float newPitch);
|
||||
|
||||
|
||||
/// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setChannels(HANDLE h, unsigned int numChannels);
|
||||
|
||||
/// Sets sample rate.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_setSampleRate(HANDLE h, unsigned int srate);
|
||||
|
||||
/// Flushes the last samples from the processing pipeline to the output.
|
||||
/// Clears also the internal processing buffers.
|
||||
//
|
||||
/// Note: This function is meant for extracting the last samples of a sound
|
||||
/// stream. This function may introduce additional blank samples in the end
|
||||
/// of the sound stream, and thus it's not recommended to call this function
|
||||
/// in the middle of a sound stream.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_flush(HANDLE h);
|
||||
|
||||
/// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
/// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
/// calling this function, otherwise throws a runtime_error exception.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_putSamples(HANDLE h,
|
||||
const float *samples, ///< Pointer to sample buffer.
|
||||
unsigned int numSamples ///< Number of samples in buffer. Notice
|
||||
///< that in case of stereo-sound a single sample
|
||||
///< contains data for both channels.
|
||||
);
|
||||
|
||||
/// Clears all the samples in the object's output and internal processing
|
||||
/// buffers.
|
||||
SOUNDTOUCHDLL_API void __stdcall soundtouch_clear(HANDLE h);
|
||||
|
||||
/// Changes a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return 'TRUE' if the setting was succesfully changed
|
||||
SOUNDTOUCHDLL_API BOOL __stdcall soundtouch_setSetting(HANDLE h,
|
||||
int settingId, ///< Setting ID number. see SETTING_... defines.
|
||||
int value ///< New setting value.
|
||||
);
|
||||
|
||||
/// Reads a setting controlling the processing system behaviour. See the
|
||||
/// 'SETTING_...' defines for available setting ID's.
|
||||
///
|
||||
/// \return the setting value.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_getSetting(HANDLE h,
|
||||
int settingId ///< Setting ID number, see SETTING_... defines.
|
||||
);
|
||||
|
||||
|
||||
/// Returns number of samples currently unprocessed.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_numUnprocessedSamples(HANDLE h);
|
||||
|
||||
/// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
/// sample buffer without copying them anywhere.
|
||||
///
|
||||
/// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
/// with 'ptrBegin' function.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_receiveSamples(HANDLE h,
|
||||
float *outBuffer, ///< Buffer where to copy output samples.
|
||||
unsigned int maxSamples ///< How many samples to receive at max.
|
||||
);
|
||||
|
||||
/// Returns number of samples currently available.
|
||||
SOUNDTOUCHDLL_API unsigned int __stdcall soundtouch_numSamples(HANDLE h);
|
||||
|
||||
/// Returns nonzero if there aren't any samples available for outputting.
|
||||
SOUNDTOUCHDLL_API int __stdcall soundtouch_isEmpty(HANDLE h);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // _SoundTouchDLL_h_
|
||||
|
||||
|
||||
@@ -1,469 +1,469 @@
|
||||
unit SoundTouchDLL;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SoundTouch.dll wrapper for accessing SoundTouch routines from Delphi/Pascal
|
||||
//
|
||||
// Module Author : Christian Budde
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.pas 66 2009-02-24 14:32:44Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows;
|
||||
|
||||
type
|
||||
TSoundTouchHandle = THandle;
|
||||
|
||||
// Create a new instance of SoundTouch processor.
|
||||
TSoundTouchCreateInstance = function : TSoundTouchHandle; stdcall;
|
||||
|
||||
// Destroys a SoundTouch processor instance.
|
||||
TSoundTouchDestroyInstance = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Get SoundTouch library version string
|
||||
TSoundTouchGetVersionString = function : PChar; stdcall;
|
||||
|
||||
// Get SoundTouch library version Id
|
||||
TSoundTouchGetVersionId = function : Cardinal; stdcall;
|
||||
|
||||
// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
// represent slower rate, larger faster rates.
|
||||
TSoundTouchSetRate = procedure (Handle: TSoundTouchHandle; newRate: Single); stdcall;
|
||||
|
||||
// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
// represent slower tempo, larger faster tempo.
|
||||
TSoundTouchSetTempo = procedure (Handle: TSoundTouchHandle; newTempo: Single); stdcall;
|
||||
|
||||
// Sets new rate control value as a difference in percents compared
|
||||
// to the original rate (-50 .. +100 %);
|
||||
TSoundTouchSetRateChange = procedure (Handle: TSoundTouchHandle; newRate: Single); stdcall;
|
||||
|
||||
// Sets new tempo control value as a difference in percents compared
|
||||
// to the original tempo (-50 .. +100 %);
|
||||
TSoundTouchSetTempoChange = procedure (Handle: TSoundTouchHandle; newTempo: Single); stdcall;
|
||||
|
||||
// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
// represent lower pitches, larger values higher pitch.
|
||||
TSoundTouchSetPitch = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
// Sets pitch change in octaves compared to the original pitch
|
||||
// (-1.00 .. +1.00);
|
||||
TSoundTouchSetPitchOctaves = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
// Sets pitch change in semi-tones compared to the original pitch
|
||||
// (-12 .. +12);
|
||||
TSoundTouchSetPitchSemiTones = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
|
||||
// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
TSoundTouchSetChannels = procedure (Handle: TSoundTouchHandle; numChannels: Cardinal); stdcall;
|
||||
|
||||
// Sets sample rate.
|
||||
TSoundTouchSetSampleRate = procedure (Handle: TSoundTouchHandle; SampleRate: Cardinal); stdcall;
|
||||
|
||||
// Flushes the last samples from the processing pipeline to the output.
|
||||
// Clears also the internal processing buffers.
|
||||
//
|
||||
// Note: This function is meant for extracting the last samples of a sound
|
||||
// stream. This function may introduce additional blank samples in the end
|
||||
// of the sound stream, and thus it
|
||||
// in the middle of a sound stream.
|
||||
TSoundTouchFlush = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
// calling this function, otherwise throws a runtime_error exception.
|
||||
TSoundTouchPutSamples = procedure (Handle: TSoundTouchHandle;
|
||||
const Samples: PSingle; //< Pointer to sample buffer.
|
||||
NumSamples: Cardinal //< Number of samples in buffer. Notice
|
||||
//< that in case of stereo-sound a single sample
|
||||
//< contains data for both channels.
|
||||
); stdcall;
|
||||
|
||||
// Clears all the samples in the object's output and internal processing
|
||||
// buffers.
|
||||
TSoundTouchClear = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Changes a setting controlling the processing system behaviour. See the
|
||||
// 'SETTING_...' defines for available setting ID's.
|
||||
//
|
||||
// \return 'TRUE' if the setting was succesfully changed
|
||||
TSoundTouchSetSetting = function (Handle: TSoundTouchHandle;
|
||||
SettingId: Integer; //< Setting ID number. see SETTING_... defines.
|
||||
Value: Integer //< New setting value.
|
||||
): Boolean; stdcall;
|
||||
|
||||
// Reads a setting controlling the processing system behaviour. See the
|
||||
// 'SETTING_...' defines for available setting ID's.
|
||||
//
|
||||
// \return the setting value.
|
||||
TSoundTouchGetSetting = function (Handle: TSoundTouchHandle;
|
||||
settingId: Integer //< Setting ID number, see SETTING_... defines.
|
||||
): Integer; stdcall;
|
||||
|
||||
|
||||
// Returns number of samples currently unprocessed.
|
||||
TSoundTouchNumUnprocessedSamples = function (Handle: TSoundTouchHandle): Cardinal; stdcall;
|
||||
|
||||
// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
// sample buffer without copying them anywhere.
|
||||
//
|
||||
// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
// with 'ptrBegin' function.
|
||||
TSoundTouchReceiveSamples = function (Handle: TSoundTouchHandle;
|
||||
outBuffer: PSingle; //< Buffer where to copy output samples.
|
||||
maxSamples: Integer //< How many samples to receive at max.
|
||||
): Cardinal; stdcall;
|
||||
|
||||
// Returns number of samples currently available.
|
||||
TSoundTouchNumSamples = function (Handle: TSoundTouchHandle): Cardinal; stdcall;
|
||||
|
||||
// Returns nonzero if there aren't any samples available for outputting.
|
||||
TSoundTouchIsEmpty = function (Handle: TSoundTouchHandle): Integer; stdcall;
|
||||
|
||||
var
|
||||
SoundTouchCreateInstance : TSoundTouchCreateInstance;
|
||||
SoundTouchDestroyInstance : TSoundTouchDestroyInstance;
|
||||
SoundTouchGetVersionString : TSoundTouchGetVersionString;
|
||||
SoundTouchGetVersionId : TSoundTouchGetVersionId;
|
||||
SoundTouchSetRate : TSoundTouchSetRate;
|
||||
SoundTouchSetTempo : TSoundTouchSetTempo;
|
||||
SoundTouchSetRateChange : TSoundTouchSetRateChange;
|
||||
SoundTouchSetTempoChange : TSoundTouchSetTempoChange;
|
||||
SoundTouchSetPitch : TSoundTouchSetPitch;
|
||||
SoundTouchSetPitchOctaves : TSoundTouchSetPitchOctaves;
|
||||
SoundTouchSetPitchSemiTones : TSoundTouchSetPitchSemiTones;
|
||||
SoundTouchSetChannels : TSoundTouchSetChannels;
|
||||
SoundTouchSetSampleRate : TSoundTouchSetSampleRate;
|
||||
SoundTouchFlush : TSoundTouchFlush;
|
||||
SoundTouchPutSamples : TSoundTouchPutSamples;
|
||||
SoundTouchClear : TSoundTouchClear;
|
||||
SoundTouchSetSetting : TSoundTouchSetSetting;
|
||||
SoundTouchGetSetting : TSoundTouchGetSetting;
|
||||
SoundTouchNumUnprocessedSamples : TSoundTouchNumUnprocessedSamples;
|
||||
SoundTouchReceiveSamples : TSoundTouchReceiveSamples;
|
||||
SoundTouchNumSamples : TSoundTouchNumSamples;
|
||||
SoundTouchIsEmpty : TSoundTouchIsEmpty;
|
||||
|
||||
type
|
||||
TSoundTouch = class
|
||||
private
|
||||
FHandle : TSoundTouchHandle;
|
||||
FRate : Single;
|
||||
FPitch : Single;
|
||||
FTempo : Single;
|
||||
FSampleRate : Single;
|
||||
FChannels : Cardinal;
|
||||
function GetNumSamples: Cardinal;
|
||||
function GetNumUnprocessedSamples: Cardinal;
|
||||
function GetIsEmpty: Integer;
|
||||
function GetPitchChange: Single;
|
||||
function GetRateChange: Single;
|
||||
function GetTempoChange: Single;
|
||||
procedure SetRate(const Value: Single);
|
||||
procedure SetPitch(const Value: Single);
|
||||
procedure SetTempo(const Value: Single);
|
||||
procedure SetPitchChange(const Value: Single);
|
||||
procedure SetRateChange(const Value: Single);
|
||||
procedure SetTempoChange(const Value: Single);
|
||||
procedure SetChannels(const Value: Cardinal);
|
||||
procedure SetSampleRate(const Value: Single);
|
||||
protected
|
||||
procedure SamplerateChanged; virtual;
|
||||
procedure ChannelsChanged; virtual;
|
||||
procedure PitchChanged; virtual;
|
||||
procedure TempoChanged; virtual;
|
||||
procedure RateChanged; virtual;
|
||||
public
|
||||
class function GetVersionString: string;
|
||||
class function GetVersionId: Cardinal;
|
||||
constructor Create; virtual;
|
||||
destructor Destroy; override;
|
||||
procedure Flush; virtual;
|
||||
procedure Clear; virtual;
|
||||
|
||||
procedure PutSamples(const Samples: PSingle; const NumSamples: Cardinal);
|
||||
function ReceiveSamples(const outBuffer: PSingle; const maxSamples: Integer): Cardinal;
|
||||
|
||||
function SetSetting(const SettingId: Integer; const Value: Integer): Boolean;
|
||||
function GetSetting(const settingId: Integer): Integer;
|
||||
|
||||
property VersionString: string read GetVersionString;
|
||||
property VersionID: Cardinal read GetVersionId;
|
||||
property Channels: Cardinal read FChannels write SetChannels;
|
||||
property Rate: Single read FRate write SetRate;
|
||||
property RateChange: Single read GetRateChange write SetRateChange;
|
||||
property Tempo: Single read FTempo write SetTempo;
|
||||
property TempoChange: Single read GetTempoChange write SetTempoChange;
|
||||
property Pitch: Single read FPitch write SetPitch;
|
||||
property PitchChange: Single read GetPitchChange write SetPitchChange;
|
||||
property SampleRate: Single read FSampleRate write SetSampleRate;
|
||||
|
||||
property NumSamples: Cardinal read GetNumSamples;
|
||||
property NumUnprocessedSamples: Cardinal read GetNumUnprocessedSamples;
|
||||
property IsEmpty: Integer read GetIsEmpty;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
{ TSoundTouch }
|
||||
|
||||
constructor TSoundTouch.Create;
|
||||
begin
|
||||
inherited;
|
||||
FHandle := SoundTouchCreateInstance;
|
||||
FRate := 1;
|
||||
FTempo := 1;
|
||||
FPitch := 1;
|
||||
FChannels := 1;
|
||||
FSampleRate := 44100;
|
||||
SamplerateChanged;
|
||||
ChannelsChanged;
|
||||
end;
|
||||
|
||||
destructor TSoundTouch.Destroy;
|
||||
begin
|
||||
SoundTouchDestroyInstance(FHandle);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.Flush;
|
||||
begin
|
||||
SoundTouchFlush(FHandle);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.Clear;
|
||||
begin
|
||||
SoundTouchClear(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetIsEmpty: Integer;
|
||||
begin
|
||||
result := SoundTouchIsEmpty(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetNumSamples: Cardinal;
|
||||
begin
|
||||
result := SoundTouchNumSamples(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetNumUnprocessedSamples: Cardinal;
|
||||
begin
|
||||
result := SoundTouchNumUnprocessedSamples(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetPitchChange: Single;
|
||||
begin
|
||||
result := 100 * (FPitch - 1.0);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetRateChange: Single;
|
||||
begin
|
||||
result := 100 * (FRate - 1.0);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetTempoChange: Single;
|
||||
begin
|
||||
result := 100 * (FTempo - 1.0);
|
||||
end;
|
||||
|
||||
class function TSoundTouch.GetVersionId: Cardinal;
|
||||
begin
|
||||
result := SoundTouchGetVersionId;
|
||||
end;
|
||||
|
||||
class function TSoundTouch.GetVersionString: string;
|
||||
begin
|
||||
result := StrPas(SoundTouchGetVersionString);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetChannels(const Value: Cardinal);
|
||||
begin
|
||||
if FChannels <> Value then
|
||||
begin
|
||||
FChannels := Value;
|
||||
ChannelsChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.ChannelsChanged;
|
||||
begin
|
||||
assert(FChannels in [1, 2]);
|
||||
SoundTouchSetChannels(FHandle, FChannels);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetPitch(const Value: Single);
|
||||
begin
|
||||
if FPitch <> Value then
|
||||
begin
|
||||
FPitch := Value;
|
||||
PitchChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.PitchChanged;
|
||||
begin
|
||||
SoundTouchSetPitch(FHandle, FPitch);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.putSamples(const Samples: PSingle;
|
||||
const NumSamples: Cardinal);
|
||||
begin
|
||||
SoundTouchPutSamples(FHandle, Samples, NumSamples);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.RateChanged;
|
||||
begin
|
||||
SoundTouchSetRate(FHandle, FRate);
|
||||
end;
|
||||
|
||||
function TSoundTouch.ReceiveSamples(const outBuffer: PSingle;
|
||||
const maxSamples: Integer): Cardinal;
|
||||
begin
|
||||
result := SoundTouchReceiveSamples(FHandle, outBuffer, maxSamples);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetPitchChange(const Value: Single);
|
||||
begin
|
||||
Pitch := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetRate(const Value: Single);
|
||||
begin
|
||||
if FRate <> Value then
|
||||
begin
|
||||
FRate := Value;
|
||||
RateChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetRateChange(const Value: Single);
|
||||
begin
|
||||
Rate := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetSampleRate(const Value: Single);
|
||||
begin
|
||||
if FSampleRate <> Value then
|
||||
begin
|
||||
FSampleRate := Value;
|
||||
SamplerateChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SamplerateChanged;
|
||||
begin
|
||||
assert(FSampleRate > 0);
|
||||
SoundTouchsetSampleRate(FHandle, round(FSampleRate));
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetTempo(const Value: Single);
|
||||
begin
|
||||
if FTempo <> Value then
|
||||
begin
|
||||
FTempo := Value;
|
||||
TempoChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetTempoChange(const Value: Single);
|
||||
begin
|
||||
Tempo := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetSetting(const SettingId: Integer): Integer;
|
||||
begin
|
||||
result := SoundTouchGetSetting(FHandle, SettingId);
|
||||
end;
|
||||
|
||||
function TSoundTouch.SetSetting(const SettingId: Integer;
|
||||
const Value: Integer): Boolean;
|
||||
begin
|
||||
result := SoundTouchSetSetting(FHandle, SettingId, Value);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.TempoChanged;
|
||||
begin
|
||||
SoundTouchsetTempo(FHandle, FTempo);
|
||||
end;
|
||||
|
||||
var
|
||||
SoundTouchLibHandle: HINST;
|
||||
SoundTouchDLL: PAnsiChar = 'SoundTouch.DLL';
|
||||
|
||||
procedure InitDLL;
|
||||
begin
|
||||
SoundTouchLibHandle := LoadLibrary(SoundTouchDLL);
|
||||
if SoundTouchLibHandle <> 0 then
|
||||
try
|
||||
SoundTouchCreateInstance := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 2)); //'soundtouch_createInstance');
|
||||
SoundTouchDestroyInstance := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 3)); //'soundtouch_destroyInstance');
|
||||
SoundTouchGetVersionString := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 7)); //'soundtouch_getVersionString');
|
||||
SoundTouchGetVersionId := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 6)); //'soundtouch_getVersionId');
|
||||
SoundTouchSetRate := GetProcAddress(SoundTouchLibHandle, PAnsiChar(17)); //'soundtouch_setRate');
|
||||
SoundTouchSetTempo := GetProcAddress(SoundTouchLibHandle, PAnsiChar(21)); //'soundtouch_setTempo');
|
||||
SoundTouchSetRateChange := GetProcAddress(SoundTouchLibHandle, PAnsiChar(18)); //'soundtouch_setRateChange');
|
||||
SoundTouchSetTempoChange := GetProcAddress(SoundTouchLibHandle, PAnsiChar(22)); //'soundtouch_setTempoChange');
|
||||
SoundTouchSetPitch := GetProcAddress(SoundTouchLibHandle, PAnsiChar(14)); //'soundtouch_setPitch');
|
||||
SoundTouchSetPitchOctaves := GetProcAddress(SoundTouchLibHandle, PAnsiChar(15)); //'soundtouch_setPitchOctaves');
|
||||
SoundTouchSetPitchSemiTones := GetProcAddress(SoundTouchLibHandle, PAnsiChar(16)); //'soundtouch_setPitchSemiTones');
|
||||
SoundTouchSetChannels := GetProcAddress(SoundTouchLibHandle, PAnsiChar(13)); //'soundtouch_setChannels');
|
||||
SoundTouchSetSampleRate := GetProcAddress(SoundTouchLibHandle, PAnsiChar(19)); //'soundtouch_setSampleRate');
|
||||
SoundTouchFlush := GetProcAddress(SoundTouchLibHandle, PAnsiChar(4)); //'soundtouch_flush');
|
||||
SoundTouchPutSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(11)); //'soundtouch_putSamples');
|
||||
SoundTouchClear := GetProcAddress(SoundTouchLibHandle, PAnsiChar(1)); //'soundtouch_clear');
|
||||
SoundTouchSetSetting := GetProcAddress(SoundTouchLibHandle, PAnsiChar(20)); //'soundtouch_SetSetting');
|
||||
SoundTouchGetSetting := GetProcAddress(SoundTouchLibHandle, PAnsiChar(5)); //'soundtouch_setSetting');
|
||||
SoundTouchNumUnprocessedSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(10)); //'soundtouch_numUnprocessedSamples');
|
||||
SoundTouchReceiveSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(12)); //'soundtouch_receiveSamples');
|
||||
SoundTouchNumSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(9)); //'soundtouch_numSamples');
|
||||
SoundTouchIsEmpty := GetProcAddress(SoundTouchLibHandle, PAnsiChar(8)); //'soundtouch_isEmpty');
|
||||
|
||||
except
|
||||
FreeLibrary(SoundTouchLibHandle);
|
||||
SoundTouchLibHandle := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure FreeDLL;
|
||||
begin
|
||||
if SoundTouchLibHandle <> 0 then FreeLibrary(SoundTouchLibHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
InitDLL;
|
||||
|
||||
finalization
|
||||
FreeDLL;
|
||||
|
||||
end.
|
||||
unit SoundTouchDLL;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SoundTouch.dll wrapper for accessing SoundTouch routines from Delphi/Pascal
|
||||
//
|
||||
// Module Author : Christian Budde
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// $Id: SoundTouchDLL.pas 66 2009-02-24 14:32:44Z oparviai $
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// License :
|
||||
//
|
||||
// SoundTouch audio processing library
|
||||
// Copyright (c) Olli Parviainen
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation; either
|
||||
// version 2.1 of the License, or (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Windows;
|
||||
|
||||
type
|
||||
TSoundTouchHandle = THandle;
|
||||
|
||||
// Create a new instance of SoundTouch processor.
|
||||
TSoundTouchCreateInstance = function : TSoundTouchHandle; stdcall;
|
||||
|
||||
// Destroys a SoundTouch processor instance.
|
||||
TSoundTouchDestroyInstance = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Get SoundTouch library version string
|
||||
TSoundTouchGetVersionString = function : PChar; stdcall;
|
||||
|
||||
// Get SoundTouch library version Id
|
||||
TSoundTouchGetVersionId = function : Cardinal; stdcall;
|
||||
|
||||
// Sets new rate control value. Normal rate = 1.0, smaller values
|
||||
// represent slower rate, larger faster rates.
|
||||
TSoundTouchSetRate = procedure (Handle: TSoundTouchHandle; newRate: Single); stdcall;
|
||||
|
||||
// Sets new tempo control value. Normal tempo = 1.0, smaller values
|
||||
// represent slower tempo, larger faster tempo.
|
||||
TSoundTouchSetTempo = procedure (Handle: TSoundTouchHandle; newTempo: Single); stdcall;
|
||||
|
||||
// Sets new rate control value as a difference in percents compared
|
||||
// to the original rate (-50 .. +100 %);
|
||||
TSoundTouchSetRateChange = procedure (Handle: TSoundTouchHandle; newRate: Single); stdcall;
|
||||
|
||||
// Sets new tempo control value as a difference in percents compared
|
||||
// to the original tempo (-50 .. +100 %);
|
||||
TSoundTouchSetTempoChange = procedure (Handle: TSoundTouchHandle; newTempo: Single); stdcall;
|
||||
|
||||
// Sets new pitch control value. Original pitch = 1.0, smaller values
|
||||
// represent lower pitches, larger values higher pitch.
|
||||
TSoundTouchSetPitch = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
// Sets pitch change in octaves compared to the original pitch
|
||||
// (-1.00 .. +1.00);
|
||||
TSoundTouchSetPitchOctaves = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
// Sets pitch change in semi-tones compared to the original pitch
|
||||
// (-12 .. +12);
|
||||
TSoundTouchSetPitchSemiTones = procedure (Handle: TSoundTouchHandle; newPitch: Single); stdcall;
|
||||
|
||||
|
||||
// Sets the number of channels, 1 = mono, 2 = stereo
|
||||
TSoundTouchSetChannels = procedure (Handle: TSoundTouchHandle; numChannels: Cardinal); stdcall;
|
||||
|
||||
// Sets sample rate.
|
||||
TSoundTouchSetSampleRate = procedure (Handle: TSoundTouchHandle; SampleRate: Cardinal); stdcall;
|
||||
|
||||
// Flushes the last samples from the processing pipeline to the output.
|
||||
// Clears also the internal processing buffers.
|
||||
//
|
||||
// Note: This function is meant for extracting the last samples of a sound
|
||||
// stream. This function may introduce additional blank samples in the end
|
||||
// of the sound stream, and thus it
|
||||
// in the middle of a sound stream.
|
||||
TSoundTouchFlush = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Adds 'numSamples' pcs of samples from the 'samples' memory position into
|
||||
// the input of the object. Notice that sample rate _has_to_ be set before
|
||||
// calling this function, otherwise throws a runtime_error exception.
|
||||
TSoundTouchPutSamples = procedure (Handle: TSoundTouchHandle;
|
||||
const Samples: PSingle; //< Pointer to sample buffer.
|
||||
NumSamples: Cardinal //< Number of samples in buffer. Notice
|
||||
//< that in case of stereo-sound a single sample
|
||||
//< contains data for both channels.
|
||||
); stdcall;
|
||||
|
||||
// Clears all the samples in the object's output and internal processing
|
||||
// buffers.
|
||||
TSoundTouchClear = procedure (Handle: TSoundTouchHandle); stdcall;
|
||||
|
||||
// Changes a setting controlling the processing system behaviour. See the
|
||||
// 'SETTING_...' defines for available setting ID's.
|
||||
//
|
||||
// \return 'TRUE' if the setting was succesfully changed
|
||||
TSoundTouchSetSetting = function (Handle: TSoundTouchHandle;
|
||||
SettingId: Integer; //< Setting ID number. see SETTING_... defines.
|
||||
Value: Integer //< New setting value.
|
||||
): Boolean; stdcall;
|
||||
|
||||
// Reads a setting controlling the processing system behaviour. See the
|
||||
// 'SETTING_...' defines for available setting ID's.
|
||||
//
|
||||
// \return the setting value.
|
||||
TSoundTouchGetSetting = function (Handle: TSoundTouchHandle;
|
||||
settingId: Integer //< Setting ID number, see SETTING_... defines.
|
||||
): Integer; stdcall;
|
||||
|
||||
|
||||
// Returns number of samples currently unprocessed.
|
||||
TSoundTouchNumUnprocessedSamples = function (Handle: TSoundTouchHandle): Cardinal; stdcall;
|
||||
|
||||
// Adjusts book-keeping so that given number of samples are removed from beginning of the
|
||||
// sample buffer without copying them anywhere.
|
||||
//
|
||||
// Used to reduce the number of samples in the buffer when accessing the sample buffer directly
|
||||
// with 'ptrBegin' function.
|
||||
TSoundTouchReceiveSamples = function (Handle: TSoundTouchHandle;
|
||||
outBuffer: PSingle; //< Buffer where to copy output samples.
|
||||
maxSamples: Integer //< How many samples to receive at max.
|
||||
): Cardinal; stdcall;
|
||||
|
||||
// Returns number of samples currently available.
|
||||
TSoundTouchNumSamples = function (Handle: TSoundTouchHandle): Cardinal; stdcall;
|
||||
|
||||
// Returns nonzero if there aren't any samples available for outputting.
|
||||
TSoundTouchIsEmpty = function (Handle: TSoundTouchHandle): Integer; stdcall;
|
||||
|
||||
var
|
||||
SoundTouchCreateInstance : TSoundTouchCreateInstance;
|
||||
SoundTouchDestroyInstance : TSoundTouchDestroyInstance;
|
||||
SoundTouchGetVersionString : TSoundTouchGetVersionString;
|
||||
SoundTouchGetVersionId : TSoundTouchGetVersionId;
|
||||
SoundTouchSetRate : TSoundTouchSetRate;
|
||||
SoundTouchSetTempo : TSoundTouchSetTempo;
|
||||
SoundTouchSetRateChange : TSoundTouchSetRateChange;
|
||||
SoundTouchSetTempoChange : TSoundTouchSetTempoChange;
|
||||
SoundTouchSetPitch : TSoundTouchSetPitch;
|
||||
SoundTouchSetPitchOctaves : TSoundTouchSetPitchOctaves;
|
||||
SoundTouchSetPitchSemiTones : TSoundTouchSetPitchSemiTones;
|
||||
SoundTouchSetChannels : TSoundTouchSetChannels;
|
||||
SoundTouchSetSampleRate : TSoundTouchSetSampleRate;
|
||||
SoundTouchFlush : TSoundTouchFlush;
|
||||
SoundTouchPutSamples : TSoundTouchPutSamples;
|
||||
SoundTouchClear : TSoundTouchClear;
|
||||
SoundTouchSetSetting : TSoundTouchSetSetting;
|
||||
SoundTouchGetSetting : TSoundTouchGetSetting;
|
||||
SoundTouchNumUnprocessedSamples : TSoundTouchNumUnprocessedSamples;
|
||||
SoundTouchReceiveSamples : TSoundTouchReceiveSamples;
|
||||
SoundTouchNumSamples : TSoundTouchNumSamples;
|
||||
SoundTouchIsEmpty : TSoundTouchIsEmpty;
|
||||
|
||||
type
|
||||
TSoundTouch = class
|
||||
private
|
||||
FHandle : TSoundTouchHandle;
|
||||
FRate : Single;
|
||||
FPitch : Single;
|
||||
FTempo : Single;
|
||||
FSampleRate : Single;
|
||||
FChannels : Cardinal;
|
||||
function GetNumSamples: Cardinal;
|
||||
function GetNumUnprocessedSamples: Cardinal;
|
||||
function GetIsEmpty: Integer;
|
||||
function GetPitchChange: Single;
|
||||
function GetRateChange: Single;
|
||||
function GetTempoChange: Single;
|
||||
procedure SetRate(const Value: Single);
|
||||
procedure SetPitch(const Value: Single);
|
||||
procedure SetTempo(const Value: Single);
|
||||
procedure SetPitchChange(const Value: Single);
|
||||
procedure SetRateChange(const Value: Single);
|
||||
procedure SetTempoChange(const Value: Single);
|
||||
procedure SetChannels(const Value: Cardinal);
|
||||
procedure SetSampleRate(const Value: Single);
|
||||
protected
|
||||
procedure SamplerateChanged; virtual;
|
||||
procedure ChannelsChanged; virtual;
|
||||
procedure PitchChanged; virtual;
|
||||
procedure TempoChanged; virtual;
|
||||
procedure RateChanged; virtual;
|
||||
public
|
||||
class function GetVersionString: string;
|
||||
class function GetVersionId: Cardinal;
|
||||
constructor Create; virtual;
|
||||
destructor Destroy; override;
|
||||
procedure Flush; virtual;
|
||||
procedure Clear; virtual;
|
||||
|
||||
procedure PutSamples(const Samples: PSingle; const NumSamples: Cardinal);
|
||||
function ReceiveSamples(const outBuffer: PSingle; const maxSamples: Integer): Cardinal;
|
||||
|
||||
function SetSetting(const SettingId: Integer; const Value: Integer): Boolean;
|
||||
function GetSetting(const settingId: Integer): Integer;
|
||||
|
||||
property VersionString: string read GetVersionString;
|
||||
property VersionID: Cardinal read GetVersionId;
|
||||
property Channels: Cardinal read FChannels write SetChannels;
|
||||
property Rate: Single read FRate write SetRate;
|
||||
property RateChange: Single read GetRateChange write SetRateChange;
|
||||
property Tempo: Single read FTempo write SetTempo;
|
||||
property TempoChange: Single read GetTempoChange write SetTempoChange;
|
||||
property Pitch: Single read FPitch write SetPitch;
|
||||
property PitchChange: Single read GetPitchChange write SetPitchChange;
|
||||
property SampleRate: Single read FSampleRate write SetSampleRate;
|
||||
|
||||
property NumSamples: Cardinal read GetNumSamples;
|
||||
property NumUnprocessedSamples: Cardinal read GetNumUnprocessedSamples;
|
||||
property IsEmpty: Integer read GetIsEmpty;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
SysUtils;
|
||||
|
||||
{ TSoundTouch }
|
||||
|
||||
constructor TSoundTouch.Create;
|
||||
begin
|
||||
inherited;
|
||||
FHandle := SoundTouchCreateInstance;
|
||||
FRate := 1;
|
||||
FTempo := 1;
|
||||
FPitch := 1;
|
||||
FChannels := 1;
|
||||
FSampleRate := 44100;
|
||||
SamplerateChanged;
|
||||
ChannelsChanged;
|
||||
end;
|
||||
|
||||
destructor TSoundTouch.Destroy;
|
||||
begin
|
||||
SoundTouchDestroyInstance(FHandle);
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.Flush;
|
||||
begin
|
||||
SoundTouchFlush(FHandle);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.Clear;
|
||||
begin
|
||||
SoundTouchClear(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetIsEmpty: Integer;
|
||||
begin
|
||||
result := SoundTouchIsEmpty(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetNumSamples: Cardinal;
|
||||
begin
|
||||
result := SoundTouchNumSamples(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetNumUnprocessedSamples: Cardinal;
|
||||
begin
|
||||
result := SoundTouchNumUnprocessedSamples(FHandle);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetPitchChange: Single;
|
||||
begin
|
||||
result := 100 * (FPitch - 1.0);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetRateChange: Single;
|
||||
begin
|
||||
result := 100 * (FRate - 1.0);
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetTempoChange: Single;
|
||||
begin
|
||||
result := 100 * (FTempo - 1.0);
|
||||
end;
|
||||
|
||||
class function TSoundTouch.GetVersionId: Cardinal;
|
||||
begin
|
||||
result := SoundTouchGetVersionId;
|
||||
end;
|
||||
|
||||
class function TSoundTouch.GetVersionString: string;
|
||||
begin
|
||||
result := StrPas(SoundTouchGetVersionString);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetChannels(const Value: Cardinal);
|
||||
begin
|
||||
if FChannels <> Value then
|
||||
begin
|
||||
FChannels := Value;
|
||||
ChannelsChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.ChannelsChanged;
|
||||
begin
|
||||
assert(FChannels in [1, 2]);
|
||||
SoundTouchSetChannels(FHandle, FChannels);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetPitch(const Value: Single);
|
||||
begin
|
||||
if FPitch <> Value then
|
||||
begin
|
||||
FPitch := Value;
|
||||
PitchChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.PitchChanged;
|
||||
begin
|
||||
SoundTouchSetPitch(FHandle, FPitch);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.putSamples(const Samples: PSingle;
|
||||
const NumSamples: Cardinal);
|
||||
begin
|
||||
SoundTouchPutSamples(FHandle, Samples, NumSamples);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.RateChanged;
|
||||
begin
|
||||
SoundTouchSetRate(FHandle, FRate);
|
||||
end;
|
||||
|
||||
function TSoundTouch.ReceiveSamples(const outBuffer: PSingle;
|
||||
const maxSamples: Integer): Cardinal;
|
||||
begin
|
||||
result := SoundTouchReceiveSamples(FHandle, outBuffer, maxSamples);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetPitchChange(const Value: Single);
|
||||
begin
|
||||
Pitch := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetRate(const Value: Single);
|
||||
begin
|
||||
if FRate <> Value then
|
||||
begin
|
||||
FRate := Value;
|
||||
RateChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetRateChange(const Value: Single);
|
||||
begin
|
||||
Rate := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetSampleRate(const Value: Single);
|
||||
begin
|
||||
if FSampleRate <> Value then
|
||||
begin
|
||||
FSampleRate := Value;
|
||||
SamplerateChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SamplerateChanged;
|
||||
begin
|
||||
assert(FSampleRate > 0);
|
||||
SoundTouchsetSampleRate(FHandle, round(FSampleRate));
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetTempo(const Value: Single);
|
||||
begin
|
||||
if FTempo <> Value then
|
||||
begin
|
||||
FTempo := Value;
|
||||
TempoChanged;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.SetTempoChange(const Value: Single);
|
||||
begin
|
||||
Tempo := 1.0 + 0.01 * Value;
|
||||
end;
|
||||
|
||||
function TSoundTouch.GetSetting(const SettingId: Integer): Integer;
|
||||
begin
|
||||
result := SoundTouchGetSetting(FHandle, SettingId);
|
||||
end;
|
||||
|
||||
function TSoundTouch.SetSetting(const SettingId: Integer;
|
||||
const Value: Integer): Boolean;
|
||||
begin
|
||||
result := SoundTouchSetSetting(FHandle, SettingId, Value);
|
||||
end;
|
||||
|
||||
procedure TSoundTouch.TempoChanged;
|
||||
begin
|
||||
SoundTouchsetTempo(FHandle, FTempo);
|
||||
end;
|
||||
|
||||
var
|
||||
SoundTouchLibHandle: HINST;
|
||||
SoundTouchDLL: PAnsiChar = 'SoundTouch.DLL';
|
||||
|
||||
procedure InitDLL;
|
||||
begin
|
||||
SoundTouchLibHandle := LoadLibrary(SoundTouchDLL);
|
||||
if SoundTouchLibHandle <> 0 then
|
||||
try
|
||||
SoundTouchCreateInstance := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 2)); //'soundtouch_createInstance');
|
||||
SoundTouchDestroyInstance := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 3)); //'soundtouch_destroyInstance');
|
||||
SoundTouchGetVersionString := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 7)); //'soundtouch_getVersionString');
|
||||
SoundTouchGetVersionId := GetProcAddress(SoundTouchLibHandle, PAnsiChar( 6)); //'soundtouch_getVersionId');
|
||||
SoundTouchSetRate := GetProcAddress(SoundTouchLibHandle, PAnsiChar(17)); //'soundtouch_setRate');
|
||||
SoundTouchSetTempo := GetProcAddress(SoundTouchLibHandle, PAnsiChar(21)); //'soundtouch_setTempo');
|
||||
SoundTouchSetRateChange := GetProcAddress(SoundTouchLibHandle, PAnsiChar(18)); //'soundtouch_setRateChange');
|
||||
SoundTouchSetTempoChange := GetProcAddress(SoundTouchLibHandle, PAnsiChar(22)); //'soundtouch_setTempoChange');
|
||||
SoundTouchSetPitch := GetProcAddress(SoundTouchLibHandle, PAnsiChar(14)); //'soundtouch_setPitch');
|
||||
SoundTouchSetPitchOctaves := GetProcAddress(SoundTouchLibHandle, PAnsiChar(15)); //'soundtouch_setPitchOctaves');
|
||||
SoundTouchSetPitchSemiTones := GetProcAddress(SoundTouchLibHandle, PAnsiChar(16)); //'soundtouch_setPitchSemiTones');
|
||||
SoundTouchSetChannels := GetProcAddress(SoundTouchLibHandle, PAnsiChar(13)); //'soundtouch_setChannels');
|
||||
SoundTouchSetSampleRate := GetProcAddress(SoundTouchLibHandle, PAnsiChar(19)); //'soundtouch_setSampleRate');
|
||||
SoundTouchFlush := GetProcAddress(SoundTouchLibHandle, PAnsiChar(4)); //'soundtouch_flush');
|
||||
SoundTouchPutSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(11)); //'soundtouch_putSamples');
|
||||
SoundTouchClear := GetProcAddress(SoundTouchLibHandle, PAnsiChar(1)); //'soundtouch_clear');
|
||||
SoundTouchSetSetting := GetProcAddress(SoundTouchLibHandle, PAnsiChar(20)); //'soundtouch_SetSetting');
|
||||
SoundTouchGetSetting := GetProcAddress(SoundTouchLibHandle, PAnsiChar(5)); //'soundtouch_setSetting');
|
||||
SoundTouchNumUnprocessedSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(10)); //'soundtouch_numUnprocessedSamples');
|
||||
SoundTouchReceiveSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(12)); //'soundtouch_receiveSamples');
|
||||
SoundTouchNumSamples := GetProcAddress(SoundTouchLibHandle, PAnsiChar(9)); //'soundtouch_numSamples');
|
||||
SoundTouchIsEmpty := GetProcAddress(SoundTouchLibHandle, PAnsiChar(8)); //'soundtouch_isEmpty');
|
||||
|
||||
except
|
||||
FreeLibrary(SoundTouchLibHandle);
|
||||
SoundTouchLibHandle := 0;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure FreeDLL;
|
||||
begin
|
||||
if SoundTouchLibHandle <> 0 then FreeLibrary(SoundTouchLibHandle);
|
||||
end;
|
||||
|
||||
initialization
|
||||
InitDLL;
|
||||
|
||||
finalization
|
||||
FreeDLL;
|
||||
|
||||
end.
|
||||
|
||||
@@ -1,114 +1,114 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Finnish resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FIN)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,7,0,0
|
||||
PRODUCTVERSION 1,7,0,0
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "SoundTouch Library licensed for 3rd party applications subject to LGPL license v2.1. Visit http://www.surina.net/soundtouch for more information about the SoundTouch library."
|
||||
VALUE "FileDescription", "SoundTouch Dynamic Link Library"
|
||||
VALUE "FileVersion", "1, 7, 0, 0"
|
||||
VALUE "InternalName", "SoundTouch"
|
||||
VALUE "LegalCopyright", "Copyright (C) Olli Parviainen 1999-2012"
|
||||
VALUE "OriginalFilename", "SoundTouch.dll"
|
||||
VALUE "ProductName", " SoundTouch Dynamic Link Library"
|
||||
VALUE "ProductVersion", "1, 7, 0, 0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // Finnish resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// English (U.S.) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
#endif // English (U.S.) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Finnish resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_FIN)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_FINNISH, SUBLANG_DEFAULT
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Version
|
||||
//
|
||||
|
||||
VS_VERSION_INFO VERSIONINFO
|
||||
FILEVERSION 1,7,0,0
|
||||
PRODUCTVERSION 1,7,0,0
|
||||
FILEFLAGSMASK 0x17L
|
||||
#ifdef _DEBUG
|
||||
FILEFLAGS 0x1L
|
||||
#else
|
||||
FILEFLAGS 0x0L
|
||||
#endif
|
||||
FILEOS 0x4L
|
||||
FILETYPE 0x2L
|
||||
FILESUBTYPE 0x0L
|
||||
BEGIN
|
||||
BLOCK "StringFileInfo"
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "Comments", "SoundTouch Library licensed for 3rd party applications subject to LGPL license v2.1. Visit http://www.surina.net/soundtouch for more information about the SoundTouch library."
|
||||
VALUE "FileDescription", "SoundTouch Dynamic Link Library"
|
||||
VALUE "FileVersion", "1, 7, 0, 0"
|
||||
VALUE "InternalName", "SoundTouch"
|
||||
VALUE "LegalCopyright", "Copyright (C) Olli Parviainen 1999-2012"
|
||||
VALUE "OriginalFilename", "SoundTouch.dll"
|
||||
VALUE "ProductName", " SoundTouch Dynamic Link Library"
|
||||
VALUE "ProductVersion", "1, 7, 0, 0"
|
||||
END
|
||||
END
|
||||
BLOCK "VarFileInfo"
|
||||
BEGIN
|
||||
VALUE "Translation", 0x0, 1200
|
||||
END
|
||||
END
|
||||
|
||||
#endif // Finnish resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
|
||||
@@ -1,28 +1,28 @@
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouchDLL", "SoundTouchDLL.vcproj", "{164DE61D-6391-4265-8273-30740117D356}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.Build.0 = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Studio 2008
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouchDLL", "SoundTouchDLL.vcproj", "{164DE61D-6391-4265-8273-30740117D356}"
|
||||
ProjectSection(ProjectDependencies) = postProject
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509} = {68A5DD20-7057-448B-8FE0-B6AC8D205509}
|
||||
EndProjectSection
|
||||
EndProject
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SoundTouch", "..\SoundTouch\SoundTouch.vcproj", "{68A5DD20-7057-448B-8FE0-B6AC8D205509}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{164DE61D-6391-4265-8273-30740117D356}.Release|Win32.Build.0 = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{68A5DD20-7057-448B-8FE0-B6AC8D205509}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by SoundTouchDLL.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by SoundTouchDLL.rc
|
||||
//
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 101
|
||||
#define _APS_NEXT_COMMAND_VALUE 40001
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user