From 013c31d6e69abccc1135b40ab966174addc14348 Mon Sep 17 00:00:00 2001 From: Jean-Marc Valin <Jean-Marc.Valin@csiro.au> Date: Fri, 30 Nov 2007 11:36:46 +1100 Subject: [PATCH] Got MDCT analysis-synthesis to work --- .gitignore | 27 ++++++++++++++++++++ celt.kdevelop | 57 ++++-------------------------------------- libcelt/Makefile.am | 2 +- libcelt/celt.c | 8 +++--- libcelt/celt.h | 46 ++++++++++++++++++++++++++++++++++ libcelt/testcelt.c | 60 +++++++++++++++++++++++++++++++++++++++++++-- 6 files changed, 142 insertions(+), 58 deletions(-) create mode 100644 .gitignore create mode 100644 libcelt/celt.h diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..f98880590 --- /dev/null +++ b/.gitignore @@ -0,0 +1,27 @@ +Makefile +Makefile.in +aclocal.m4 +autom4te.cache +*.kdevelop.pcs +*.kdevses +config.guess +config.h +config.h.in +config.log +config.status +config.sub +configure +depcomp +install-sh +.deps +.libs +*.la +testcelt +libtool +ltmain.sh +missing +stamp-h1 +*.sw +*.o +*.lo +*~ diff --git a/celt.kdevelop b/celt.kdevelop index c4e915317..37c063b58 100644 --- a/celt.kdevelop +++ b/celt.kdevelop @@ -8,27 +8,12 @@ <primarylanguage>C</primarylanguage> <ignoreparts/> <projectname>celt</projectname> - <projectdirectory>.</projectdirectory> - <absoluteprojectpath>false</absoluteprojectpath> - <description/> - <defaultencoding/> </general> <kdevautoproject> <general> <useconfiguration>default</useconfiguration> </general> - <run> - <mainprogram/> - <programargs/> - <globaldebugarguments/> - <globalcwd/> - <useglobalprogram>true</useglobalprogram> - <terminal>false</terminal> - <autocompile>false</autocompile> - <autoinstall>false</autoinstall> - <autokdesu>false</autokdesu> - <envvars/> - </run> + <run/> <configurations> <optimized> <builddir>optimized</builddir> @@ -56,20 +41,7 @@ <kdevdebugger> <general> <dbgshell>libtool</dbgshell> - <gdbpath/> - <configGdbScript/> - <runShellScript/> - <runGdbScript/> - <breakonloadinglibs>true</breakonloadinglibs> - <separatetty>false</separatetty> - <floatingtoolbar>false</floatingtoolbar> - <raiseGDBOnStart>false</raiseGDBOnStart> </general> - <display> - <staticmembers>false</staticmembers> - <demanglenames>true</demanglenames> - <outputradix>10</outputradix> - </display> </kdevdebugger> <kdevdoctreeview> <ignoretocs> @@ -131,12 +103,13 @@ <used>false</used> <version>3</version> <includestyle>3</includestyle> - <root></root> + <root>/usr/share/qt3</root> <designerintegration>EmbeddedKDevDesigner</designerintegration> - <qmake></qmake> - <designer></designer> + <qmake>/usr/bin/qmake-qt3</qmake> + <designer>/usr/bin/designer</designer> <designerpluginpaths/> </qt> + <references/> <codecompletion> <automaticCodeCompletion>false</automaticCodeCompletion> <automaticArgumentsHint>true</automaticArgumentsHint> @@ -160,27 +133,7 @@ <alwaysIncludeNamespaces>false</alwaysIncludeNamespaces> <includePaths>.;</includePaths> </codecompletion> - <creategettersetter> - <prefixGet/> - <prefixSet>set</prefixSet> - <prefixVariable>m_,_</prefixVariable> - <parameterName>theValue</parameterName> - <inlineGet>true</inlineGet> - <inlineSet>true</inlineSet> - </creategettersetter> - <splitheadersource> - <enabled>false</enabled> - <synchronize>true</synchronize> - <orientation>Vertical</orientation> - </splitheadersource> - <references/> </kdevcppsupport> - <cppsupportpart> - <filetemplates> - <interfacesuffix>.h</interfacesuffix> - <implementationsuffix>.cpp</implementationsuffix> - </filetemplates> - </cppsupportpart> <kdevfileview> <groups> <hidenonprojectfiles>false</hidenonprojectfiles> diff --git a/libcelt/Makefile.am b/libcelt/Makefile.am index 44ea4941b..ec58f36c2 100644 --- a/libcelt/Makefile.am +++ b/libcelt/Makefile.am @@ -15,7 +15,7 @@ libcelt_la_SOURCES = celt.c mdct.c libcelt_la_LDFLAGS = -version-info @CELT_LT_CURRENT@:@CELT_LT_REVISION@:@CELT_LT_AGE@ -noinst_HEADERS = os_support.h arch.h mdct.h +noinst_HEADERS = arch.h celt.h mdct.h os_support.h noinst_PROGRAMS = testcelt testcelt_SOURCES = testcelt.c diff --git a/libcelt/celt.c b/libcelt/celt.c index 20c6e1705..22c3fd023 100644 --- a/libcelt/celt.c +++ b/libcelt/celt.c @@ -32,6 +32,8 @@ #include "os_support.h" #include "mdct.h" #include <math.h> +#include "celt.h" + #define MAX_PERIOD 2048 @@ -51,9 +53,9 @@ struct CELTState_ { float *out_mem; }; -typedef struct CELTState_ CELTState; -CELTState *celt_init(int blockSize, int blocksPerFrame) + +CELTState *celt_encoder_new(int blockSize, int blocksPerFrame) { int i, N; N = blockSize; @@ -127,7 +129,7 @@ void celt_encode(CELTState *st, short *pcm) st->mdct_overlap[j] = x[N+j]; for (j=0;j<N;j++) - pcm[i*N+j] = st->out_mem[MAX_PERIOD+(i-B)*N+j]; + pcm[i*N+j] = (short)floor(.5+st->out_mem[MAX_PERIOD+(i-B)*N+j]); } } diff --git a/libcelt/celt.h b/libcelt/celt.h new file mode 100644 index 000000000..3fe755841 --- /dev/null +++ b/libcelt/celt.h @@ -0,0 +1,46 @@ +/* (C) 2007 Jean-Marc Valin, CSIRO +*/ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +#ifndef CELT_H +#define CELT_H + +struct CELTState_; +typedef struct CELTState_ CELTState; + + + +CELTState *celt_encoder_new(int blockSize, int blocksPerFrame); + +void celt_encode(CELTState *st, short *pcm); + + + +#endif /*CELT_H */ diff --git a/libcelt/testcelt.c b/libcelt/testcelt.c index 5ec56018c..5f9812a3b 100644 --- a/libcelt/testcelt.c +++ b/libcelt/testcelt.c @@ -1,5 +1,61 @@ -int main() -{ +/* (C) 2007 Jean-Marc Valin, CSIRO +*/ +/* + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions + are met: + + - Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + + - Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + - Neither the name of the Xiph.org Foundation nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR + CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + + +#include "celt.h" +#include <stdio.h> + +#define FRAME_SIZE 256 +#define NBLOCKS 2 + +int main(int argc, char *argv[]) +{ + char *inFile, *outFile; + FILE *fin, *fout; + short in[FRAME_SIZE]; + CELTState *st; + + inFile = argv[1]; + fin = fopen(inFile, "rb"); + outFile = argv[2]; + fout = fopen(outFile, "wb+"); + + st = celt_encoder_new(FRAME_SIZE/NBLOCKS, NBLOCKS); + + while (!feof(fin)) + { + fread(in, sizeof(short), FRAME_SIZE, fin); + celt_encode(st, in); + fwrite(in, sizeof(short), FRAME_SIZE, fout); + } return 0; } -- GitLab