From fdcdca41be3b31cc7948d7501909a8cd0e0e3b43 Mon Sep 17 00:00:00 2001 From: Gluzskiy Alexandr Date: Sun, 24 Feb 2013 16:20:17 +0200 Subject: conversion to cp866 for windows --- sound_detector/Makefile.mingw32 | 3 +- sound_detector/main.cpp | 28 +++++++++++++++---- sound_detector/sound_detector.project | 9 ++++-- sound_detector/toutf8.c | 50 ++++++++++++++++++++++++++++++++++ sound_detector/toutf8.h | 3 ++ sound_detector/toutf8.o | Bin 0 -> 1215 bytes 6 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 sound_detector/toutf8.c create mode 100644 sound_detector/toutf8.h create mode 100644 sound_detector/toutf8.o diff --git a/sound_detector/Makefile.mingw32 b/sound_detector/Makefile.mingw32 index 00e2207..201c84e 100644 --- a/sound_detector/Makefile.mingw32 +++ b/sound_detector/Makefile.mingw32 @@ -1,7 +1,8 @@ all: i686-pc-mingw32-gcc -c wingetopt.c -o wingetopt.o + i686-pc-mingw32-gcc -c toutf8.c -o toutf8.o i686-pc-mingw32-g++ -c main.cpp -std=gnu++0x -DBOOST_ALL_NO_LIB -DBOOST_ASIO_HASH_MAP_BUCKETS=1021 -DBOOST_EXCEPTION_DISABLE -DBOOST_SYSTEM_STATIC_LINK=1 -DBOOST_THREAD_USE_LIB -DBOOST_THREAD_USE_LIB=1 -DUNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -D_UNICODE -D_WIN32 -D_WIN32_WINNT=0x0500 -D__USE_W32_SOCKETS -DCURL_STATICLIB -o main.o - i686-pc-mingw32-g++ -o sound_detector.exe *.o -lwldap32 -liconv -lwldap32 -lws2_32 -lz -lgmp -lz -lboost_system-mt -lboost_date_time-mt -lboost_thread_win32-mt -lboost_chrono-mt -lboost_random-mt -lboost_filesystem-mt -lmswsock -lws2_32 -lgdi32 -lcrypt32 -lz -lportaudio -lwinmm -lm -ldsound -lole32 -lwinmm -lm -luuid -lsetupapi -lole32 -lwinmm -lm -lole32 -luuid -lwinmm -lm -lole32 -luuid -lvorbis -lvorbisenc -logg -Wl,-O1 -s + i686-pc-mingw32-g++ -o sound_detector.exe *.o -lwldap32 -liconv -lwldap32 -lws2_32 -lz -lgmp -lz -lboost_system-mt -lboost_date_time-mt -lboost_thread_win32-mt -lboost_chrono-mt -lboost_random-mt -lboost_filesystem-mt -lmswsock -lws2_32 -lgdi32 -lcrypt32 -lz -lportaudio -lwinmm -lm -ldsound -lole32 -lwinmm -lm -luuid -lsetupapi -lole32 -lwinmm -lm -lole32 -luuid -lwinmm -lm -lole32 -luuid -lvorbis -lvorbisenc -logg -liconv -Wl,-O1 -s upx --best sound_detector.exe clean: rm *.o diff --git a/sound_detector/main.cpp b/sound_detector/main.cpp index 8d7f331..b2064d8 100644 --- a/sound_detector/main.cpp +++ b/sound_detector/main.cpp @@ -16,13 +16,17 @@ +//c++ +#include + #ifndef WIN32 #include #else +//getopt #include "wingetopt.h" #endif -#include + //c #include @@ -31,6 +35,7 @@ #include //c++ +#include #include #include @@ -44,6 +49,9 @@ #include #include +//internal +#include "toutf8.h" + unsigned int precapture = 3, postcapture = 7, min_length = 1, thresold = 0, stop_thresold = 0; @@ -222,13 +230,13 @@ int stream_callback(const void *input, void *output, unsigned long frameCount, c int16_t *buf = bufs[0]; lock.lock(); buffer.insert(buffer.end(), buf, buf + frameCount); - lock.unlock(); //debug -/* for(unsigned long i = 0; i < frameCount; i++) +/* for(size_t i = 0; i < buffer.size(); i++) { - if(buf[i] > (int)((float)INT16_MAX/100.0*(float)thresold_percent)) - printf("%d ", buf[i]); - } */ + if(buffer[i] > (int)((float)INT16_MAX/100.0*(float)thresold_percent)) + printf("%d ", buffer[i]); + } */ + lock.unlock(); return paContinue; //debug end } @@ -281,8 +289,16 @@ int main(int argc, char **argv) for(PaDeviceIndex i =0, end = Pa_GetDeviceCount(); i < end; i++) { const PaDeviceInfo *info = Pa_GetDeviceInfo(i); + //windows +#ifdef WIN32 + char *name = to_utf8(info->name); + printf("%d. %s, input channels %d, output channels %d, default sample rate %f, lowest input latency %f, highest input latency %f\n", + i, name, info->maxInputChannels, info->maxOutputChannels, info->defaultSampleRate, info->defaultLowInputLatency, info->defaultHighInputLatency); + free(name); +#else printf("%d. %s, input channels %d, output channels %d, default sample rate %f, lowest input latency %f, highest input latency %f\n", i, info->name, info->maxInputChannels, info->maxOutputChannels, info->defaultSampleRate, info->defaultLowInputLatency, info->defaultHighInputLatency); +#endif } exit(0); } diff --git a/sound_detector/sound_detector.project b/sound_detector/sound_detector.project index 3b68ebd..319e841 100644 --- a/sound_detector/sound_detector.project +++ b/sound_detector/sound_detector.project @@ -9,6 +9,8 @@ + + @@ -33,9 +35,10 @@ - + - + @@ -76,6 +79,8 @@ + + ]]> diff --git a/sound_detector/toutf8.c b/sound_detector/toutf8.c new file mode 100644 index 0000000..1601bd1 --- /dev/null +++ b/sound_detector/toutf8.c @@ -0,0 +1,50 @@ +// Copyright © 2013 sss +// +// This program 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. +// +// This program 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. + +#ifdef WIN32 +//iconv +#include +#include +#include +#include +#include + +char *to_utf8(const char *koi8r) +{ + iconv_t id = iconv_open("CP866", "WINDOWS-1251"); + if((long)id == -1) + { + printf("failed to create iconv descriptor with error: %s\n", strerror(errno)); + return NULL; + } + int len = strlen(koi8r), outlen = 0; + len++; + outlen = len * 2; + char *outbuf = (char*)malloc(len * 2), *op, *ip; + op = outbuf; + ip = koi8r; + int enc_len = iconv(id, &ip, &len, &op, &outlen); + if(enc_len == -1) + { + printf("failed to convert buffer with error: %s\n", strerror(errno)); + return NULL; + } + //outbuf[len] = '\0'; + return outbuf; +} + + +#endif diff --git a/sound_detector/toutf8.h b/sound_detector/toutf8.h new file mode 100644 index 0000000..49d42d7 --- /dev/null +++ b/sound_detector/toutf8.h @@ -0,0 +1,3 @@ +#ifdef WIN32 +extern "C" char *to_utf8(const char *koi8r); +#endif diff --git a/sound_detector/toutf8.o b/sound_detector/toutf8.o new file mode 100644 index 0000000..213bd6c Binary files /dev/null and b/sound_detector/toutf8.o differ -- cgit v1.2.3