changeset 52:e914b02b31b0

- Hacks to get a basic AIM-C compiling on windows
author tomwalters
date Thu, 22 Jul 2010 04:24:55 +0000
parents 978fb645eb0f
children c058da80d443
files SConstruct src/Main/aimc.cc src/Modules/Features/ModuleGaussians.cc src/Modules/SSI/ModuleSSI.cc src/Support/FileList.h src/Support/Module.h src/Support/ModuleFactory.cc src/Support/Parameters.cc src/Support/SimpleIni.h
diffstat 9 files changed, 238 insertions(+), 216 deletions(-) [+]
line wrap: on
line diff
--- a/SConstruct	Thu Jul 22 04:14:20 2010 +0000
+++ b/SConstruct	Thu Jul 22 04:24:55 2010 +0000
@@ -1,202 +1,205 @@
-# Copyright 2006-2010, Willem van Engen, Thomas Walters
-#
-# AIM-C: A C++ implementation of the Auditory Image Model
-# http://www.acousticscale.org/AIMC
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-## @author Thomas Walters <tom@acousticscale.org>
-#  @author Willem van Engen <cnbh@willem.engen.nl>
-#  @date created 2010/02/02
-#  @version \$Id$
-
-"""@package SConstruct
-SConstruct file for the aimc project
-
-"""
-
-import os
-import shutil
-
-# Location of libsndfile on Windows
-windows_libsndfile_location = "C:\\Program Files\\Mega-Nerd\\libsndfile\\"
-
-# Sources common to every version
-common_sources = ['Support/Common.cc',
-                  'Support/FileList.cc',
-                  'Support/SignalBank.cc',
-                  'Support/Parameters.cc',
-                  'Support/Module.cc',
-                  'Support/ModuleFactory.cc',
-                  'Modules/Input/ModuleFileInput.cc',
-                  'Modules/BMM/ModuleGammatone.cc',
-                  'Modules/BMM/ModulePZFC.cc',
-                  'Modules/NAP/ModuleHCL.cc',
-                  'Modules/Strobes/ModuleParabola.cc',
-                  'Modules/Strobes/ModuleLocalMax.cc',
-                  'Modules/SAI/ModuleSAI.cc',
-                  'Modules/SNR/ModuleNoise.cc',
-                  'Modules/SSI/ModuleSSI.cc',
-                  'Modules/Profile/ModuleSlice.cc',
-                  'Modules/Profile/ModuleScaler.cc',
-                  'Modules/Features/ModuleGaussians.cc',
-                  'Modules/Output/FileOutputHTK.cc',
-                  'Modules/Output/FileOutputAIMC.cc']
-
-# File which contains main()
-#sources = common_sources + ['Main/AIMCopy_SSI_Features_v4_PZFC.cc']
-sources = common_sources + ['Main/AIMCopy_SSI_Features_v5_smooth_nap.cc']
-
-# Test sources
-test_sources = ['Modules/Profile/ModuleSlice_unittest.cc']
-test_sources += common_sources
-
-# Define the command-line options for running scons
-options = Variables()
-options.Add(BoolVariable('mingw', 
-                         'Compile on Windows using mingw rather than msvc',
-                         False))
-options.Add(BoolVariable('symbols', 
-                         'Add debuging symbols when compiling on gcc',
-                         False))
-
-# Environment variables
-env = Environment(options = options, ENV = os.environ)
-if env['mingw']:
-  # SCons Defaults to MSVC if installed on Windows.
-  env = Environment(options = opts, ENV = os.environ, tools = ['mingw'])
-
-# Platform
-build_platform = env['PLATFORM']
-target_platform = build_platform
-
-# Build products location and executable name
-build_dir = os.path.join('build', target_platform + '-release')
-#target_executable = 'aimc'
-target_executable = 'AIMCopy'
-test_executable = 'aimc_tests'
-
-# Create build products directory if necessary
-if not os.path.exists(build_dir):
-  os.makedirs(build_dir)
-env.SConsignFile(os.path.join(build_dir,'.sconsign'))
-
-# Set any platform-specific environment variables and options
-if target_platform == 'win32':
-  env.AppendUnique(CPPDEFINES = ['_WINDOWS', 'WIN32', 
-                                 'WINVER=0x0400', '_CONSOLE'])
-elif target_platform == 'darwin':
-  env.AppendUnique(CPPDEFINES = ['_MACOSX'])
-
-# Compiler selection based on platform
-# compiler can be one of: gcc msvc
-compiler = 'gcc'
-if (build_platform == 'win32' 
-    and target_platform == 'win32' 
-    and not env['mingw']):
-  compiler = 'msvc'
-
-# Compiler-specific options:
-# Microsoft visual studio
-if compiler == 'msvc':
-  env.AppendUnique(CPPFLAGS = ['/arch:SSE2', '/nologo', '/W3', '/EHsc'])
-  env.AppendUnique(CPPDEFINES = ['_CRT_SECURE_NO_DEPRECATE', 
-                                 '_RINT_REQUIRED'])
-  env.AppendUnique(CPPFLAGS = ['/Ox'])
-  env.AppendUnique(CPPDEFINES = ['NDEBUG', '_ATL_MIN_CRT'])
-
-# GNU compiler collection
-elif compiler == 'gcc':
-  env['STRIP'] = 'strip'
-  env.AppendUnique(CPPFLAGS = ['-Wall'])
-  env.AppendUnique(CPPFLAGS = ['-O3', '-fomit-frame-pointer'])
-  if env['symbols']:
-    env.AppendUnique(CPPFLAGS = ['-g'])
-  if env['mingw']:
-    if not env['PLATFORM'] == 'win32':
-      print('Cross-compilation for Windows is not supported')
-      Exit(1)
-else:
-  print('Unsupported compiler: ' + compiler)
-  Exit(1)
- 
-# To make a statically-linked version for os 10.4 and up... 
-#if build_platform == 'darwin':
-#  env.AppendUnique(CPPFLAGS = ['-arch', 'i386'])
-#  env.AppendUnique(LINKFLAGS = ['-arch', 'i386'])
-#  env.AppendUnique(LINKFLAGS = ['-Wl'])
-#  env.AppendUnique(LINKFLAGS = ['-search_paths_first'])
-#  env.AppendUnique(MACOSX_DEPLOYMENT_TARGET = ['10.4'])
-#  env.AppendUnique(GCC_VERSION = ['4.0'])
-#  env.Replace(CC = ['gcc-4.0'])
-#  env.Replace(CXX = ['gcc-4.0'])
-#  env.AppendUnique(CPPFLAGS = ['-fno-stack-protector','-isysroot', '/Developer/SDKs/MacOSX10.5.sdk', '-mmacosx-version-min=10.4'])
-#  deplibs = ['sndfile', 'flac', 'vorbis', 'vorbisenc', 'ogg']  
-if not target_platform == 'win32':
-  # On windows, utf support is builtin for SimpleIni
-  # but not on other platforms
-  sources += ['Support/ConvertUTF.c']
-
-# Place the build products in the corect place
-env.VariantDir('#' + build_dir, '#', duplicate = 0)
-
-# Look for the sources in the correct place
-env.Append(CPPPATH = ['#src'])
-
-# Dependencies
-deplibs = ['sndfile']
-
-if target_platform != 'win32':
-  for depname in deplibs:
-    env.ParseConfig('pkg-config --cflags --libs ' + depname)
-  env.AppendUnique(LIBS = deplibs)
-else:
-  #env.AppendUnique(LIBS = ['wsock32', 'winmm'])
-  if 'sndfile' in deplibs:
-    ###### libsndfile ########################################
-    # This one is only valid for win32 and already precompiled
-    # Only need to create .lib file from .def
-    shutil.copyfile(windows_libsndfile_location + '/libsndfile-1.dll',
-                    build_dir+'/libsndfile-1.dll')
-    if compiler=='msvc':
-      shutil.copyfile(windows_libsndfile_location + '/libsndfile-1.def',
-                      build_dir+'/libsndfile-1.def')
-      env.Command(build_dir + '/libsndfile.lib', build_dir + '/libsndfile.def',
-                  env['AR'] + ' /nologo /machine:i386 /def:$SOURCE /out:$TARGET')
-      env.Append(CPPPATH = [windows_libsndfile_location])
-      env.AppendUnique(LIBPATH = [build_dir])
-      # Replace 'sndfile' with 'sndfile-1'
-      deplibs.remove('sndfile')
-      deplibs.append('sndfile-1')
-
-
-
-# Builder for the main program
-program = env.Program(target = os.path.join(build_dir, target_executable), 
-                      source = map(lambda x: '#' + build_dir + '/src/' + x,
-                                   sources))
-env.Alias(target_executable, os.path.join(build_dir, target_executable))
-env.Default(program)
-
-#test_env = env.Clone()
-#test_libs = ['gtest', 'gtest_main']
-##for depname in test_libs:
-##  test_env.ParseConfig('pkg-config --cflags --libs ' + depname)
-#test_env.AppendUnique(LIBPATH = ['/usr/local/lib'],
-#                      CPPPATH = ['/usr/local/lib'],
-#                      LIBS = test_libs)
-#
-#test = test_env.Program(target = os.path.join(build_dir, test_executable),
-#                        source = map(lambda x: '#' + build_dir + '/src/' + x,
-#                                     test_sources))
-#env.Alias('test', os.path.join(build_dir, test_executable))
+# Copyright 2006-2010, Willem van Engen, Thomas Walters
+#
+# AIM-C: A C++ implementation of the Auditory Image Model
+# http://www.acousticscale.org/AIMC
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+## @author Thomas Walters <tom@acousticscale.org>
+#  @author Willem van Engen <cnbh@willem.engen.nl>
+#  @date created 2010/02/02
+#  @version \$Id$
+
+"""@package SConstruct
+SConstruct file for the aimc project
+
+"""
+
+import os
+import shutil
+
+# Location of libsndfile on Windows
+windows_libsndfile_location = "C:\\Program Files\\Mega-Nerd\\libsndfile\\"
+
+# Sources common to every version
+common_sources = ['Support/Common.cc',
+                  'Support/FileList.cc',
+                  'Support/SignalBank.cc',
+                  'Support/Parameters.cc',
+                  'Support/Module.cc',
+                  'Support/ModuleFactory.cc',
+                  'Modules/Input/ModuleFileInput.cc',
+                  'Modules/BMM/ModuleGammatone.cc',
+                  'Modules/BMM/ModulePZFC.cc',
+                  'Modules/NAP/ModuleHCL.cc',
+                  'Modules/Strobes/ModuleParabola.cc',
+                  'Modules/Strobes/ModuleLocalMax.cc',
+                  'Modules/SAI/ModuleSAI.cc',
+                  'Modules/SSI/ModuleSSI.cc',
+                  'Modules/Profile/ModuleSlice.cc',
+                  'Modules/Profile/ModuleScaler.cc',
+                  'Modules/Output/FileOutputHTK.cc',
+                  'Modules/Output/FileOutputAIMC.cc']
+
+# List of currently incative source files which we may want to add back in
+sources_disabled = ['Modules/SNR/ModuleNoise.cc',
+                    'Modules/Features/ModuleGaussians.cc']
+
+# File which contains main()
+#sources = common_sources + ['Main/AIMCopy_SSI_Features_v4_PZFC.cc']
+#sources = common_sources + ['Main/AIMCopy_SSI_Features_v5_smooth_nap.cc']
+sources = common_sources + ['Main/aimc.cc']
+
+# Test sources
+test_sources = ['Modules/Profile/ModuleSlice_unittest.cc']
+test_sources += common_sources
+
+# Define the command-line options for running scons
+options = Variables()
+options.Add(BoolVariable('mingw', 
+                         'Compile on Windows using mingw rather than msvc',
+                         False))
+options.Add(BoolVariable('symbols', 
+                         'Add debuging symbols when compiling on gcc',
+                         False))
+
+# Environment variables
+env = Environment(options = options, ENV = os.environ)
+if env['mingw']:
+  # SCons Defaults to MSVC if installed on Windows.
+  env = Environment(options = opts, ENV = os.environ, tools = ['mingw'])
+
+# Platform
+build_platform = env['PLATFORM']
+target_platform = build_platform
+
+# Build products location and executable name
+build_dir = os.path.join('build', target_platform + '-release')
+target_executable = 'aimc'
+#target_executable = 'AIMCopy'
+test_executable = 'aimc_tests'
+
+# Create build products directory if necessary
+if not os.path.exists(build_dir):
+  os.makedirs(build_dir)
+env.SConsignFile(os.path.join(build_dir,'.sconsign'))
+
+# Set any platform-specific environment variables and options
+if target_platform == 'win32':
+  env.AppendUnique(CPPDEFINES = ['_WINDOWS', 'WIN32', 
+                                 'WINVER=0x0400', '_CONSOLE'])
+elif target_platform == 'darwin':
+  env.AppendUnique(CPPDEFINES = ['_MACOSX'])
+
+# Compiler selection based on platform
+# compiler can be one of: gcc msvc
+compiler = 'gcc'
+if (build_platform == 'win32' 
+    and target_platform == 'win32' 
+    and not env['mingw']):
+  compiler = 'msvc'
+
+# Compiler-specific options:
+# Microsoft visual studio
+if compiler == 'msvc':
+  env.AppendUnique(CPPFLAGS = ['/arch:SSE2', '/nologo', '/W3', '/EHsc'])
+  env.AppendUnique(CPPDEFINES = ['_CRT_SECURE_NO_DEPRECATE', 
+                                 '_RINT_REQUIRED'])
+  env.AppendUnique(CPPFLAGS = ['/Ox'])
+  env.AppendUnique(CPPDEFINES = ['NDEBUG', '_ATL_MIN_CRT'])
+
+# GNU compiler collection
+elif compiler == 'gcc':
+  env['STRIP'] = 'strip'
+  env.AppendUnique(CPPFLAGS = ['-Wall'])
+  env.AppendUnique(CPPFLAGS = ['-O3', '-fomit-frame-pointer'])
+  if env['symbols']:
+    env.AppendUnique(CPPFLAGS = ['-g'])
+  if env['mingw']:
+    if not env['PLATFORM'] == 'win32':
+      print('Cross-compilation for Windows is not supported')
+      Exit(1)
+else:
+  print('Unsupported compiler: ' + compiler)
+  Exit(1)
+ 
+# To make a statically-linked version for os 10.4 and up... 
+#if build_platform == 'darwin':
+#  env.AppendUnique(CPPFLAGS = ['-arch', 'i386'])
+#  env.AppendUnique(LINKFLAGS = ['-arch', 'i386'])
+#  env.AppendUnique(LINKFLAGS = ['-Wl'])
+#  env.AppendUnique(LINKFLAGS = ['-search_paths_first'])
+#  env.AppendUnique(MACOSX_DEPLOYMENT_TARGET = ['10.4'])
+#  env.AppendUnique(GCC_VERSION = ['4.0'])
+#  env.Replace(CC = ['gcc-4.0'])
+#  env.Replace(CXX = ['gcc-4.0'])
+#  env.AppendUnique(CPPFLAGS = ['-fno-stack-protector','-isysroot', '/Developer/SDKs/MacOSX10.5.sdk', '-mmacosx-version-min=10.4'])
+#  deplibs = ['sndfile', 'flac', 'vorbis', 'vorbisenc', 'ogg']  
+if not target_platform == 'win32':
+  # On windows, utf support is builtin for SimpleIni
+  # but not on other platforms
+  sources += ['Support/ConvertUTF.c']
+
+# Place the build products in the corect place
+env.VariantDir('#' + build_dir, '#', duplicate = 0)
+
+# Look for the sources in the correct place
+env.Append(CPPPATH = ['#src'])
+
+# Dependencies
+deplibs = ['sndfile']
+
+if target_platform != 'win32':
+  for depname in deplibs:
+    env.ParseConfig('pkg-config --cflags --libs ' + depname)
+else:
+  #env.AppendUnique(LIBS = ['wsock32', 'winmm'])
+  if 'sndfile' in deplibs:
+    ###### libsndfile ########################################
+    # This one is only valid for win32 and already precompiled
+    # Only need to create .lib file from .def
+    shutil.copyfile(windows_libsndfile_location + '/libsndfile-1.dll',
+                    build_dir+'/libsndfile-1.dll')
+    if compiler=='msvc':
+      shutil.copyfile(windows_libsndfile_location + '/libsndfile-1.def',
+                      build_dir+'/libsndfile-1.def')
+      env.Command(build_dir + '/libsndfile-1.lib', build_dir + '/libsndfile-1.def',
+                  env['AR'] + ' /nologo /machine:i386 /def:$SOURCE /out:$TARGET')
+      env.Append(CPPPATH = [windows_libsndfile_location + '/include/'])
+      env.AppendUnique(LIBPATH = [build_dir])
+      # Replace 'sndfile' with 'sndfile-1'
+      deplibs.remove('sndfile')
+      deplibs.append('libsndfile-1')
+env.AppendUnique(LIBS = deplibs)
+
+
+
+# Builder for the main program
+program = env.Program(target = os.path.join(build_dir, target_executable), 
+                      source = map(lambda x: '#' + build_dir + '/src/' + x,
+                                   sources))
+env.Alias(target_executable, os.path.join(build_dir, target_executable))
+env.Default(program)
+
+#test_env = env.Clone()
+#test_libs = ['gtest', 'gtest_main']
+##for depname in test_libs:
+##  test_env.ParseConfig('pkg-config --cflags --libs ' + depname)
+#test_env.AppendUnique(LIBPATH = ['/usr/local/lib'],
+#                      CPPPATH = ['/usr/local/lib'],
+#                      LIBS = test_libs)
+#
+#test = test_env.Program(target = os.path.join(build_dir, test_executable),
+#                        source = map(lambda x: '#' + build_dir + '/src/' + x,
+#                                     test_sources))
+#env.Alias('test', os.path.join(build_dir, test_executable))
--- a/src/Main/aimc.cc	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Main/aimc.cc	Thu Jul 22 04:24:55 2010 +0000
@@ -39,20 +39,14 @@
   params.SetInt("input.buffersize", buffer_length);
 
   aimc::ModuleFileInput input(&params);
-  aimc::ModuleGammatone bmm(&params);
-  aimc::ModuleHCL nap(&params);
-  aimc::ModuleLocalMax strobes(&params);
-  aimc::ModuleSAI sai(&params);
+  aimc::ModulePZFC bmm(&params);
   aimc::FileOutputAIMC output(&params);
 
   std::string parameters_string = params.WriteString();
   printf("%s", parameters_string.c_str());
 
   input.AddTarget(&bmm);
-  bmm.AddTarget(&nap);
-  nap.AddTarget(&strobes);
-  strobes.AddTarget(&sai);
-  sai.AddTarget(&output);
+  bmm.AddTarget(&output);
 
   output.OpenFile("test_output.aimc", params.GetFloat("sai.frame_period_ms"));
   if (input.LoadFile("test.wav")) {
--- a/src/Modules/Features/ModuleGaussians.cc	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Modules/Features/ModuleGaussians.cc	Thu Jul 22 04:24:55 2010 +0000
@@ -117,7 +117,7 @@
   for (int iChannel = 0;
        iChannel < input.channel_count();
        ++iChannel) {
-    m_pSpectralProfile[iChannel] = pow(m_pSpectralProfile[iChannel], 0.8);
+    m_pSpectralProfile[iChannel] = pow(m_pSpectralProfile[iChannel], 0.8f);
   }
 
   RubberGMMCore(2, true);
--- a/src/Modules/SSI/ModuleSSI.cc	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Modules/SSI/ModuleSSI.cc	Thu Jul 22 04:24:55 2010 +0000
@@ -26,6 +26,13 @@
 #include "Modules/SSI/ModuleSSI.h"
 
 namespace aimc {
+#ifdef _MSC_VER
+// MSVC doesn't define log2()
+float log2(float n) {
+  return log(n) / log(2.0);  
+}
+#endif
+
 ModuleSSI::ModuleSSI(Parameters *params) : Module(params) {
   module_description_ = "Size-shape image (aka the 'sscAI')";
   module_identifier_ = "ssi";
--- a/src/Support/FileList.h	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Support/FileList.h	Thu Jul 22 04:24:55 2010 +0000
@@ -25,6 +25,13 @@
  * \version \$Id$
  */
 
+#if defined(_WINDOWS)
+#  include <windows.h>
+#  ifndef PATH_MAX
+#    define PATH_MAX _MAX_PATH
+#  endif
+#endif
+#include <limits.h>
 #include <string>
 #include <utility>
 #include <vector>
--- a/src/Support/Module.h	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Support/Module.h	Thu Jul 22 04:24:55 2010 +0000
@@ -27,6 +27,13 @@
 #ifndef AIMC_SUPPORT_MODULE_H_
 #define AIMC_SUPPORT_MODULE_H_
 
+// Several modules expect the M_PI macro and isnan() to be defined
+#ifdef _MSC_VER
+#define M_PI 3.14159265359
+#define isnan _isnan
+#define isinf _isinf
+#endif
+
 #include <iostream>
 #include <set>
 #include <string>
--- a/src/Support/ModuleFactory.cc	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Support/ModuleFactory.cc	Thu Jul 22 04:24:55 2010 +0000
@@ -24,7 +24,7 @@
 #include "Modules/SSI/ModuleSSI.h"
 #include "Modules/Profile/ModuleSlice.h"
 #include "Modules/Profile/ModuleScaler.h"
-#include "Modules/Features/ModuleGaussians.h"
+//#include "Modules/Features/ModuleGaussians.h"
 #include "Modules/Output/FileOutputHTK.h"
 
 #include "Support/ModuleFactory.h"
@@ -37,8 +37,8 @@
   if (module_name_.compare("pzfc") == 0)
     return new ModulePZFC(params);
 
-  if (module_name_.compare("gaussians") == 0)
-    return new ModuleGaussians(params);
+  //if (module_name_.compare("gaussians") == 0)
+  //  return new ModuleGaussians(params);
 
   if (module_name_.compare("file_input") == 0)
     return new ModuleFileInput(params);
--- a/src/Support/Parameters.cc	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Support/Parameters.cc	Thu Jul 22 04:24:55 2010 +0000
@@ -31,6 +31,10 @@
 #include "Support/Common.h"
 #include "Support/Parameters.h"
 
+#ifdef _MSC_VER
+#define snprintf _snprintf
+#endif
+
 namespace aimc {
 const char *Parameters::m_SDefaultIniSection = "";
 
--- a/src/Support/SimpleIni.h	Thu Jul 22 04:14:20 2010 +0000
+++ b/src/Support/SimpleIni.h	Thu Jul 22 04:24:55 2010 +0000
@@ -5,7 +5,7 @@
         <tr><th>File        <td>SimpleIni.h
         <tr><th>Author      <td>Brodie Thiesfield [code at jellycan dot com]
         <tr><th>Source      <td>http://code.jellycan.com/simpleini/
-        <tr><th>Version     <td>4.12
+        <tr><th>Version     <td>4.13
     </table>
 
     Jump to the @link CSimpleIniTempl CSimpleIni @endlink interface documentation.
@@ -1878,7 +1878,7 @@
         if (a_pComment) {
             oKey.pComment = a_pComment;
         }
-        typename TKeyVal::value_type oEntry(oKey, NULL);
+        typename TKeyVal::value_type oEntry(oKey, (const SI_CHAR *) NULL);
         iKey = keyval.insert(oEntry);
         bInserted = true;
     }