├── .gitignore
├── README.md
├── example-gstt_api_only
├── .cproject
├── .project
├── Makefile
├── addons.make
├── bin
│ └── data
│ │ ├── cacert.pem
│ │ └── speechToText.flac
├── config.make
└── src
│ ├── main.cpp
│ ├── ofAppSTT.cpp
│ └── ofAppSTT.h
├── example-gstt_basics
├── .cproject
├── .project
├── Makefile
├── addons.make
├── bin
│ └── data
│ │ ├── .gitkeep
│ │ └── cacert.pem
├── config.make
└── src
│ ├── main.cpp
│ ├── ofGsttApp.cpp
│ └── ofGsttApp.h
├── example-gstt_chrome_workaround
├── .cproject
├── .project
├── Makefile
├── addons.make
├── bin
│ └── data
│ │ └── web
│ │ └── index.html
├── config.make
└── src
│ ├── main.cpp
│ ├── ofAppSTTWorkaround.cpp
│ └── ofAppSTTWorkaround.h
├── libs
├── sndfile
│ ├── includes
│ │ ├── sndfile.h
│ │ └── sndfile.hh
│ └── lib
│ │ └── linux
│ │ └── libsndfile.a
└── stringencoders
│ ├── modp_b64.c
│ ├── modp_b64.h
│ └── modp_b64_data.h
└── src
├── googleResponseParser.h
├── ofxGSTT.cpp
├── ofxGSTT.h
├── ofxGSTTEvent.h
├── ofxGSTTTranscriptionThread.cpp
└── ofxGSTTTranscriptionThread.h
/.gitignore:
--------------------------------------------------------------------------------
1 | example*/obj/*
2 | example*/bin/*
3 | example*/.settings/
4 | !example*/bin/data/
5 | example*/bin/data/tmpAudio
6 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ofxGSTT
2 | ================
3 | openFrameworks addon/wrapper to the **Google Speech To Text API v2**.
4 |
5 | Unfortunately the first API version doesn't work anymore and API v2 is officially limited to 50 requests per day and it is still not possible to apply for a higher quota (but people reported that they were able to get up to 500 responses per day).
6 |
7 | Anyway I can't recommend using this addon in a production environment - only for prototyping purposes.
8 |
9 | **For unlimited requests check out the workaround example via Chrome.**
10 |
11 | Feedback is really welcome!
12 |
13 | Credits:
14 | ----------------
15 | Originally this addon was ported from the processing [library](http://stt.getflourish.com/) by Florian Schulz, which was based on Mike Pultz [article](http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/) that showed how to use the technology offered by Google without a browser.
16 |
17 | Informations to switch from v1 to v2 were found [here](https://github.com/gillesdemey/google-speech-v2).
18 |
19 | Examples:
20 | ----------------
21 |
22 | Before you start you need to generate your own [Speech API Key](http://www.chromium.org/developers/how-tos/api-keys).
23 |
24 | ### example-gstt_api_only:
25 |
26 | not using the addon at all, only showcasing the api request with a prerecorded audio file
27 |
28 | ### example-gstt_basics:
29 |
30 | basic addon example for recording and transcripting
31 |
32 | ### example-gstt_chrome_workaround
33 |
34 | Instead of using ofxGSTT, this workaround uses the Speech to Text API within Google Chrome and sends the results to openFrameworks via WebSockets. Idea (again) ported from Florian Schulz [example](http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/).
35 |
36 | Dependencies: Google Chrome (or Chromium) and [ofxLibwebsockets](http://github.com:labatrockwell/ofxLibwebsockets)
37 |
38 | Dependencies
39 | ----------------
40 | * [ofxJSON](https://github.com/jefftimesten/ofxJSON)
41 | * [ofxSSL](https://github.com/fx-lange/ofxSSL)
42 | * sndfile - recording audio to wav
43 |
44 | libsndfile is included as static libs for unix(32 and 64bit). for mac you might need to `brew install libsndfile` and for win you can try to install the binaries provided [here](http://www.mega-nerd.com/libsndfile/#Download).
45 |
--------------------------------------------------------------------------------
/example-gstt_api_only/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/example-gstt_api_only/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | example-gstt_api_only
4 |
5 |
6 | addons
7 | libs
8 | openFrameworks
9 |
10 |
11 |
12 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
13 | clean,full,incremental,
14 |
15 |
16 |
17 |
18 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
19 | full,incremental,
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.cdt.core.cnature
26 | org.eclipse.cdt.core.ccnature
27 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
28 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
29 |
30 |
31 |
--------------------------------------------------------------------------------
/example-gstt_api_only/Makefile:
--------------------------------------------------------------------------------
1 | include config.make
2 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples
3 |
--------------------------------------------------------------------------------
/example-gstt_api_only/addons.make:
--------------------------------------------------------------------------------
1 | ofxSSL
--------------------------------------------------------------------------------
/example-gstt_api_only/bin/data/speechToText.flac:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fx-lange/ofxGSTT/c4354777ca1d7aa2cc396e6026b82fbf36a7e30f/example-gstt_api_only/bin/data/speechToText.flac
--------------------------------------------------------------------------------
/example-gstt_api_only/config.make:
--------------------------------------------------------------------------------
1 | # add custom variables to this file
2 |
3 | # OF_ROOT allows to move projects outside apps/* just set this variable to the
4 | # absoulte path to the OF root folder
5 |
6 | OF_ROOT = ../../..
7 |
8 |
9 | # USER_CFLAGS allows to pass custom flags to the compiler
10 | # for example search paths like:
11 | # USER_CFLAGS = -I src/objects
12 |
13 | USER_CFLAGS =
14 |
15 |
16 | # USER_LDFLAGS allows to pass custom flags to the li nker
17 | # for example libraries like:
18 | # USER_LDFLAGS = libs/libawesomelib.a
19 |
20 | USER_LDFLAGS =
21 |
22 | EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj"
23 |
24 | # change this to add different compiler optimizations to your project
25 |
26 | USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os
27 |
28 |
29 | # android specific, in case you want to use different optimizations
30 | USER_LIBS_ARM =
31 | USER_LIBS_ARM7 =
32 | USER_LIBS_NEON =
33 |
34 | # android optimizations
35 |
36 | ANDROID_COMPILER_OPTIMIZATION = -Os
37 |
38 | NDK_PLATFORM = android-8
39 |
40 | # uncomment this for custom application name (if the folder name is different than the application name)
41 | #APPNAME = folderName
42 |
43 | # uncomment this for custom package name, must be the same as the java package that contains OFActivity
44 | #PKGNAME = cc.openframeworks.$(APPNAME)
45 |
46 |
47 |
48 |
49 |
50 | # linux arm flags
51 |
52 | LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/example-gstt_api_only/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofAppSTT.h"
3 |
4 | //========================================================================
5 | int main( )
6 | {
7 |
8 | // can be OF_WINDOW or OF_FULLSCREEN
9 | // pass in width and height too:
10 | ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
11 |
12 | // this kicks off the running of my app
13 | ofRunApp(new ofAppSTT);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/example-gstt_api_only/src/ofAppSTT.cpp:
--------------------------------------------------------------------------------
1 | #include "ofAppSTT.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofAppSTT::setup(){
5 | ofBackground(0);
6 | ofSetLogLevel(OF_LOG_VERBOSE);
7 | ofxSSL::appendData = true; //only needed to show http errors
8 | }
9 |
10 | //--------------------------------------------------------------
11 | void ofAppSTT::draw(){
12 | ofDrawBitmapString(result, 10, 10);
13 | }
14 |
15 | //--------------------------------------------------------------
16 | void ofAppSTT::keyPressed (int key){
17 | if(key == ' '){
18 |
19 | //TODO check the readme for generating your own key
20 | curl.setURL("https://www.google.com/speech-api/v2/recognize?output=json&lang=en-us&key=yourkey");
21 |
22 | // set form
23 | std::string uploadfile = ofToDataPath("speechToText.flac",true);
24 | curl.addFormFile("file",uploadfile,"audio/x-flac");
25 |
26 | // set header
27 | curl.addHeader("Expect:");
28 | curl.addHeader("Content-Type: audio/x-flac; rate=16000");
29 |
30 | curl.perform();
31 | result = curl.getResponseBody();
32 |
33 | curl.clear();
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/example-gstt_api_only/src/ofAppSTT.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxSSL.h"
5 |
6 | class ofAppSTT: public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void draw();
11 |
12 | void keyPressed (int key);
13 |
14 | ofxSSL curl;
15 | string result;
16 | };
17 |
18 |
--------------------------------------------------------------------------------
/example-gstt_basics/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
--------------------------------------------------------------------------------
/example-gstt_basics/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | example-gstt_basic
4 |
5 |
6 | addons
7 | libs
8 | openFrameworks
9 |
10 |
11 |
12 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
13 | clean,full,incremental,
14 |
15 |
16 |
17 |
18 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
19 | full,incremental,
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.cdt.core.cnature
26 | org.eclipse.cdt.core.ccnature
27 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
28 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
29 |
30 |
31 |
--------------------------------------------------------------------------------
/example-gstt_basics/Makefile:
--------------------------------------------------------------------------------
1 | # Attempt to load a config.make file.
2 | # If none is found, project defaults in config.project.make will be used.
3 | ifneq ($(wildcard config.make),)
4 | include config.make
5 | endif
6 |
7 | # make sure the the OF_ROOT location is defined
8 | ifndef OF_ROOT
9 | OF_ROOT=../../..
10 | endif
11 |
12 | # call the project makefile!
13 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/compile.project.mk
14 |
--------------------------------------------------------------------------------
/example-gstt_basics/addons.make:
--------------------------------------------------------------------------------
1 | ofxJSON
2 | ofxSSL
3 | ofxGSTT
--------------------------------------------------------------------------------
/example-gstt_basics/bin/data/.gitkeep:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fx-lange/ofxGSTT/c4354777ca1d7aa2cc396e6026b82fbf36a7e30f/example-gstt_basics/bin/data/.gitkeep
--------------------------------------------------------------------------------
/example-gstt_basics/config.make:
--------------------------------------------------------------------------------
1 | ################################################################################
2 | # CONFIGURE PROJECT MAKEFILE (optional)
3 | # This file is where we make project specific configurations.
4 | ################################################################################
5 |
6 | ################################################################################
7 | # OF ROOT
8 | # The location of your root openFrameworks installation
9 | # (default) OF_ROOT = ../../..
10 | ################################################################################
11 | # OF_ROOT = ../../..
12 |
13 | ################################################################################
14 | # PROJECT ROOT
15 | # The location of the project - a starting place for searching for files
16 | # (default) PROJECT_ROOT = . (this directory)
17 | #
18 | ################################################################################
19 | # PROJECT_ROOT = .
20 |
21 | ################################################################################
22 | # PROJECT SPECIFIC CHECKS
23 | # This is a project defined section to create internal makefile flags to
24 | # conditionally enable or disable the addition of various features within
25 | # this makefile. For instance, if you want to make changes based on whether
26 | # GTK is installed, one might test that here and create a variable to check.
27 | ################################################################################
28 | # None
29 |
30 | ################################################################################
31 | # PROJECT EXTERNAL SOURCE PATHS
32 | # These are fully qualified paths that are not within the PROJECT_ROOT folder.
33 | # Like source folders in the PROJECT_ROOT, these paths are subject to
34 | # exlclusion via the PROJECT_EXLCUSIONS list.
35 | #
36 | # (default) PROJECT_EXTERNAL_SOURCE_PATHS = (blank)
37 | #
38 | # Note: Leave a leading space when adding list items with the += operator
39 | ################################################################################
40 | # PROJECT_EXTERNAL_SOURCE_PATHS =
41 |
42 | ################################################################################
43 | # PROJECT EXCLUSIONS
44 | # These makefiles assume that all folders in your current project directory
45 | # and any listed in the PROJECT_EXTERNAL_SOURCH_PATHS are are valid locations
46 | # to look for source code. The any folders or files that match any of the
47 | # items in the PROJECT_EXCLUSIONS list below will be ignored.
48 | #
49 | # Each item in the PROJECT_EXCLUSIONS list will be treated as a complete
50 | # string unless teh user adds a wildcard (%) operator to match subdirectories.
51 | # GNU make only allows one wildcard for matching. The second wildcard (%) is
52 | # treated literally.
53 | #
54 | # (default) PROJECT_EXCLUSIONS = (blank)
55 | #
56 | # Will automatically exclude the following:
57 | #
58 | # $(PROJECT_ROOT)/bin%
59 | # $(PROJECT_ROOT)/obj%
60 | # $(PROJECT_ROOT)/%.xcodeproj
61 | #
62 | # Note: Leave a leading space when adding list items with the += operator
63 | ################################################################################
64 | # PROJECT_EXCLUSIONS =
65 |
66 | ################################################################################
67 | # PROJECT LINKER FLAGS
68 | # These flags will be sent to the linker when compiling the executable.
69 | #
70 | # (default) PROJECT_LDFLAGS = -Wl,-rpath=./libs
71 | #
72 | # Note: Leave a leading space when adding list items with the += operator
73 | ################################################################################
74 |
75 | # Currently, shared libraries that are needed are copied to the
76 | # $(PROJECT_ROOT)/bin/libs directory. The following LDFLAGS tell the linker to
77 | # add a runtime path to search for those shared libraries, since they aren't
78 | # incorporated directly into the final executable application binary.
79 | # TODO: should this be a default setting?
80 | # PROJECT_LDFLAGS=-Wl,-rpath=./libs
81 |
82 | ################################################################################
83 | # PROJECT DEFINES
84 | # Create a space-delimited list of DEFINES. The list will be converted into
85 | # CFLAGS with the "-D" flag later in the makefile.
86 | #
87 | # (default) PROJECT_DEFINES = (blank)
88 | #
89 | # Note: Leave a leading space when adding list items with the += operator
90 | ################################################################################
91 | # PROJECT_DEFINES =
92 |
93 | ################################################################################
94 | # PROJECT CFLAGS
95 | # This is a list of fully qualified CFLAGS required when compiling for this
96 | # project. These CFLAGS will be used IN ADDITION TO the PLATFORM_CFLAGS
97 | # defined in your platform specific core configuration files. These flags are
98 | # presented to the compiler BEFORE the PROJECT_OPTIMIZATION_CFLAGS below.
99 | #
100 | # (default) PROJECT_CFLAGS = (blank)
101 | #
102 | # Note: Before adding PROJECT_CFLAGS, note that the PLATFORM_CFLAGS defined in
103 | # your platform specific configuration file will be applied by default and
104 | # further flags here may not be needed.
105 | #
106 | # Note: Leave a leading space when adding list items with the += operator
107 | ################################################################################
108 | # PROJECT_CFLAGS =
109 |
110 | ################################################################################
111 | # PROJECT OPTIMIZATION CFLAGS
112 | # These are lists of CFLAGS that are target-specific. While any flags could
113 | # be conditionally added, they are usually limited to optimization flags.
114 | # These flags are added BEFORE the PROJECT_CFLAGS.
115 | #
116 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE flags are only applied to RELEASE targets.
117 | #
118 | # (default) PROJECT_OPTIMIZATION_CFLAGS_RELEASE = (blank)
119 | #
120 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG flags are only applied to DEBUG targets.
121 | #
122 | # (default) PROJECT_OPTIMIZATION_CFLAGS_DEBUG = (blank)
123 | #
124 | # Note: Before adding PROJECT_OPTIMIZATION_CFLAGS, please note that the
125 | # PLATFORM_OPTIMIZATION_CFLAGS defined in your platform specific configuration
126 | # file will be applied by default and further optimization flags here may not
127 | # be needed.
128 | #
129 | # Note: Leave a leading space when adding list items with the += operator
130 | ################################################################################
131 | # PROJECT_OPTIMIZATION_CFLAGS_RELEASE =
132 | # PROJECT_OPTIMIZATION_CFLAGS_DEBUG =
133 |
134 | ################################################################################
135 | # PROJECT COMPILERS
136 | # Custom compilers can be set for CC and CXX
137 | # (default) PROJECT_CXX = (blank)
138 | # (default) PROJECT_CC = (blank)
139 | # Note: Leave a leading space when adding list items with the += operator
140 | ################################################################################
141 | # PROJECT_CXX =
142 | # PROJECT_CC =
143 |
--------------------------------------------------------------------------------
/example-gstt_basics/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofGsttApp.h"
3 |
4 | //========================================================================
5 | int main( )
6 | {
7 |
8 | // can be OF_WINDOW or OF_FULLSCREEN
9 | // pass in width and height too:
10 | ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
11 |
12 | // this kicks off the running of my app
13 | ofRunApp(new ofGsttApp);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/example-gstt_basics/src/ofGsttApp.cpp:
--------------------------------------------------------------------------------
1 | #include "ofGsttApp.h"
2 |
3 | bool bAutoRecording = true;
4 | float volumeThreshold = 0.05f;
5 |
6 | //--------------------------------------------------------------
7 | void ofGsttApp::setup(){
8 | ofSetFrameRate(60);
9 | ofBackground(0, 0, 0);
10 | ofSetLogLevel(OF_LOG_VERBOSE);
11 |
12 | //init oF soundstream
13 | int sampleRate = 44100;
14 | int bufferSize = 256;
15 | int nChannels = 1;
16 | soundStream.printDeviceList();
17 | // soundStream.setDeviceID(3);
18 | soundStream.setup(0, nChannels, sampleRate, bufferSize, 4);
19 |
20 | //init ofxGSTT
21 | gstt.setup(sampleRate,nChannels,"en-us",YOUR_KEY_AS_A_STRING_HERE);//check the README for generating an API key
22 | gstt.setAutoRecording(bAutoRecording);
23 | gstt.setVolumeThreshold(volumeThreshold);
24 | //make gstt owner of the sound input stream
25 | soundStream.setInput(gstt);
26 |
27 | //register listener function to transcript response events
28 | ofAddListener(ofxGSTTTranscriptionThread::gsttApiResponseEvent,this,&ofGsttApp::gsttResponse);
29 |
30 |
31 | responseStr = "responses:\n(your might want to order them via tSend)\n";
32 | }
33 |
34 | //--------------------------------------------------------------
35 | void ofGsttApp::update(){
36 | }
37 |
38 | void ofGsttApp::gsttResponse(ofxGSTTResponseArgs & response){
39 | cout << "Response: " << response.msg << endl;
40 | cout << "with confidence: " << ofToString(response.confidence) << endl;
41 | float tProcessingTime = (response.tReceived - response.tSend)/1000.f;
42 | cout << "processing time(seconds): " << ofToString(tProcessingTime) << endl;
43 | if(response.msg != ""){
44 | responseStr += response.msg + " (after "+ofToString(tProcessingTime)+ "s )\n";
45 | }else{
46 | responseStr += "no results\n";
47 | }
48 | }
49 |
50 | //--------------------------------------------------------------
51 | void ofGsttApp::draw(){
52 | ofBackground(0);
53 | ofPushStyle();
54 | ofSetColor(255,255,255);
55 |
56 | if(gstt.isRecording()){
57 | ofSetColor(255,0,0);
58 | }else{
59 | ofSetColor(20,20,20);
60 | }
61 | ofDrawEllipse(ofGetWidth()/2,ofGetHeight()/2,200,200);
62 |
63 | ofSetColor(255,255,255);
64 | std::string status = "(s/S) start/stop recording\n";
65 | status += "( a ) toggle auto recording: " + ofToString(gstt.isAutoRecording());
66 | if(gstt.isAutoRecording())
67 | status += " (+/-) volume threshold: " + ofToString(gstt.getVolumeThreshold());
68 | status += "\nsmoothed volume: " + ofToString(gstt.getSmoothedVolume(),3);
69 | ofDrawBitmapString(status,50,20);
70 | ofDrawBitmapString(responseStr,50,100);
71 |
72 | ofPopStyle();
73 | }
74 |
75 | //--------------------------------------------------------------
76 | void ofGsttApp::keyPressed (int key){
77 | switch(key){
78 | case 'a':
79 | bAutoRecording = !bAutoRecording;
80 | gstt.setAutoRecording(bAutoRecording);
81 | break;
82 | case 's':
83 | gstt.startRecording();
84 | break;
85 | case 'S':
86 | gstt.stopRecording();
87 | break;
88 | case '+':
89 | volumeThreshold += 0.01f;
90 | gstt.setVolumeThreshold(volumeThreshold);
91 | break;
92 | case '-':
93 | volumeThreshold -= 0.01f;
94 | gstt.setVolumeThreshold(volumeThreshold);
95 | break;
96 | }
97 | }
98 |
99 | //--------------------------------------------------------------
100 | void ofGsttApp::keyReleased (int key){
101 | }
102 |
103 | //--------------------------------------------------------------
104 | void ofGsttApp::mouseMoved(int x, int y ){
105 | }
106 |
107 | //--------------------------------------------------------------
108 | void ofGsttApp::mouseDragged(int x, int y, int button){
109 | }
110 |
111 | //--------------------------------------------------------------
112 | void ofGsttApp::mousePressed(int x, int y, int button){
113 | }
114 |
115 | //--------------------------------------------------------------
116 | void ofGsttApp::mouseReleased(){
117 |
118 | }
119 |
120 |
--------------------------------------------------------------------------------
/example-gstt_basics/src/ofGsttApp.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxGSTT.h"
5 |
6 | class ofGsttApp: public ofBaseApp{
7 |
8 | public:
9 | void setup();
10 | void update();
11 | void draw();
12 |
13 | void keyPressed(int key);
14 | void keyReleased(int key);
15 | void mouseMoved(int x, int y);
16 | void mouseDragged(int x, int y, int button);
17 | void mousePressed(int x, int y, int button);
18 | void mouseReleased();
19 |
20 | void gsttResponse(ofxGSTTResponseArgs & response);
21 |
22 | string responseStr;
23 |
24 | ofxGSTT gstt;
25 | ofSoundStream soundStream;
26 | };
27 |
28 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/.cproject:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/.project:
--------------------------------------------------------------------------------
1 |
2 |
3 | example-gstt_chrome_workaround
4 |
5 |
6 | addons
7 | libs
8 | openFrameworks
9 |
10 |
11 |
12 | org.eclipse.cdt.managedbuilder.core.genmakebuilder
13 | clean,full,incremental,
14 |
15 |
16 |
17 |
18 | org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder
19 | full,incremental,
20 |
21 |
22 |
23 |
24 |
25 | org.eclipse.cdt.core.cnature
26 | org.eclipse.cdt.core.ccnature
27 | org.eclipse.cdt.managedbuilder.core.managedBuildNature
28 | org.eclipse.cdt.managedbuilder.core.ScannerConfigNature
29 |
30 |
31 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/Makefile:
--------------------------------------------------------------------------------
1 | include config.make
2 | include $(OF_ROOT)/libs/openFrameworksCompiled/project/makefileCommon/Makefile.examples
3 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/addons.make:
--------------------------------------------------------------------------------
1 | ofxLibwebsockets
2 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/bin/data/web/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
46 |
47 |
48 |
49 |
50 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/config.make:
--------------------------------------------------------------------------------
1 | # add custom variables to this file
2 |
3 | # OF_ROOT allows to move projects outside apps/* just set this variable to the
4 | # absoulte path to the OF root folder
5 |
6 | OF_ROOT = ../../..
7 |
8 |
9 | # USER_CFLAGS allows to pass custom flags to the compiler
10 | # for example search paths like:
11 | # USER_CFLAGS = -I src/objects
12 |
13 | USER_CFLAGS =
14 |
15 |
16 | # USER_LDFLAGS allows to pass custom flags to the li nker
17 | # for example libraries like:
18 | # USER_LDFLAGS = libs/libawesomelib.a
19 |
20 | USER_LDFLAGS =
21 |
22 | EXCLUDE_FROM_SOURCE="bin,.xcodeproj,obj"
23 |
24 | # change this to add different compiler optimizations to your project
25 |
26 | USER_COMPILER_OPTIMIZATION = -march=native -mtune=native -Os
27 |
28 |
29 | # android specific, in case you want to use different optimizations
30 | USER_LIBS_ARM =
31 | USER_LIBS_ARM7 =
32 | USER_LIBS_NEON =
33 |
34 | # android optimizations
35 |
36 | ANDROID_COMPILER_OPTIMIZATION = -Os
37 |
38 | NDK_PLATFORM = android-8
39 |
40 | # uncomment this for custom application name (if the folder name is different than the application name)
41 | #APPNAME = folderName
42 |
43 | # uncomment this for custom package name, must be the same as the java package that contains OFActivity
44 | #PKGNAME = cc.openframeworks.$(APPNAME)
45 |
46 |
47 |
48 |
49 |
50 | # linux arm flags
51 |
52 | LINUX_ARM7_COMPILER_OPTIMIZATIONS = -march=armv7-a -mtune=cortex-a8 -finline-functions -funroll-all-loops -O3 -funsafe-math-optimizations -mfpu=neon -ftree-vectorize -mfloat-abi=hard -mfpu=vfp
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include "ofMain.h"
2 | #include "ofAppSTTWorkaround.h"
3 |
4 | //========================================================================
5 | int main( )
6 | {
7 |
8 | // can be OF_WINDOW or OF_FULLSCREEN
9 | // pass in width and height too:
10 | ofSetupOpenGL(1024,768, OF_WINDOW); // <-------- setup the GL context
11 |
12 | // this kicks off the running of my app
13 | ofRunApp(new ofAppSTTWorkaround);
14 |
15 | }
16 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/src/ofAppSTTWorkaround.cpp:
--------------------------------------------------------------------------------
1 | #include "ofAppSTTWorkaround.h"
2 |
3 | //--------------------------------------------------------------
4 | void ofAppSTTWorkaround::setup(){
5 | // setup a server with default options on port 9092
6 | // - pass in true after port to set up with SSL
7 | //bSetup = server.setup( 9093 );
8 |
9 | ofxLibwebsockets::ServerOptions options = ofxLibwebsockets::defaultServerOptions();
10 | options.port = 9092;
11 | options.bUseSSL = false; // you'll have to manually accept this self-signed cert if 'true'!
12 | bSetup = server.setup( options );
13 |
14 | // this adds your app as a listener for the server
15 | server.addListener(this);
16 |
17 | ofBackground(0);
18 | ofSetFrameRate(60);
19 | }
20 |
21 | //--------------------------------------------------------------
22 | void ofAppSTTWorkaround::update(){
23 | }
24 |
25 | //--------------------------------------------------------------
26 | void ofAppSTTWorkaround::draw(){
27 | if ( bSetup ){
28 | ofDrawBitmapString("WebSocket server setup at "+ofToString( server.getPort() ) + ( server.usingSSL() ? " with SSL" : " without SSL"), 20, 20);
29 |
30 | ofSetColor(150);
31 | ofDrawBitmapString("Click anywhere to open up client example", 20, 40);
32 | } else {
33 | ofDrawBitmapString("WebSocket setup failed :(", 20,20);
34 | }
35 |
36 | int x = 20;
37 | int y = 100;
38 |
39 | ofSetColor(0,150,0);
40 | ofDrawBitmapString("Console", x, 80);
41 |
42 | ofSetColor(255);
43 | for (int i = messages.size() -1; i >= 0; i-- ){
44 | ofDrawBitmapString( messages[i], x, y );
45 | y += 20;
46 | }
47 | if (messages.size() > NUM_MESSAGES) messages.erase( messages.begin() );
48 |
49 | ofSetColor(150,0,0);
50 | ofDrawBitmapString("Type a message, hit [RETURN] to send:", x, ofGetHeight()-60);
51 | ofSetColor(255);
52 | ofDrawBitmapString(toSend, x, ofGetHeight() - 40);
53 | }
54 |
55 | //--------------------------------------------------------------
56 | void ofAppSTTWorkaround::onConnect( ofxLibwebsockets::Event& args ){
57 | cout<<"on connected"< 0 ){
103 | toSend.erase(toSend.end()-1);
104 | }
105 | } else {
106 | toSend += key;
107 | }
108 | } else {
109 | // send to all clients
110 | server.send( toSend );
111 | messages.push_back("Sent: '" + toSend + "' to "+ ofToString(server.getConnections().size())+" websockets" );
112 | toSend = "";
113 | }
114 | }
115 |
116 | //--------------------------------------------------------------
117 | void ofAppSTTWorkaround::keyReleased(int key){
118 |
119 | }
120 |
121 | //--------------------------------------------------------------
122 | void ofAppSTTWorkaround::mouseMoved(int x, int y ){
123 |
124 | }
125 |
126 | //--------------------------------------------------------------
127 | void ofAppSTTWorkaround::mouseDragged(int x, int y, int button){
128 |
129 | }
130 |
131 | //--------------------------------------------------------------
132 | void ofAppSTTWorkaround::mousePressed(int x, int y, int button){
133 | string url = "http";
134 | if ( server.usingSSL() ){
135 | url += "s";
136 | }
137 | url += "://localhost:" + ofToString( server.getPort() );
138 | ofLaunchBrowser(url);
139 | }
140 |
141 | //--------------------------------------------------------------
142 | void ofAppSTTWorkaround::mouseReleased(int x, int y, int button){
143 |
144 | }
145 |
146 | //--------------------------------------------------------------
147 | void ofAppSTTWorkaround::windowResized(int w, int h){
148 |
149 | }
150 |
151 | //--------------------------------------------------------------
152 | void ofAppSTTWorkaround::gotMessage(ofMessage msg){
153 |
154 | }
155 |
156 | //--------------------------------------------------------------
157 | void ofAppSTTWorkaround::dragEvent(ofDragInfo dragInfo){
158 |
159 | }
160 |
--------------------------------------------------------------------------------
/example-gstt_chrome_workaround/src/ofAppSTTWorkaround.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 |
5 | #include "ofxLibwebsockets.h"
6 |
7 | #define NUM_MESSAGES 30 // how many past messages we want to keep
8 |
9 | class ofAppSTTWorkaround : public ofBaseApp{
10 |
11 | public:
12 | void setup();
13 | void update();
14 | void draw();
15 |
16 | void keyPressed (int key);
17 | void keyReleased(int key);
18 | void mouseMoved(int x, int y );
19 | void mouseDragged(int x, int y, int button);
20 | void mousePressed(int x, int y, int button);
21 | void mouseReleased(int x, int y, int button);
22 | void windowResized(int w, int h);
23 | void dragEvent(ofDragInfo dragInfo);
24 | void gotMessage(ofMessage msg);
25 |
26 | ofxLibwebsockets::Server server;
27 |
28 | bool bSetup;
29 |
30 | //queue of rec'd messages
31 | vector messages;
32 |
33 | //string to send to clients
34 | string toSend;
35 |
36 | // websocket methods
37 | void onConnect( ofxLibwebsockets::Event& args );
38 | void onOpen( ofxLibwebsockets::Event& args );
39 | void onClose( ofxLibwebsockets::Event& args );
40 | void onIdle( ofxLibwebsockets::Event& args );
41 | void onMessage( ofxLibwebsockets::Event& args );
42 | void onBroadcast( ofxLibwebsockets::Event& args );
43 | };
44 |
--------------------------------------------------------------------------------
/libs/sndfile/includes/sndfile.h:
--------------------------------------------------------------------------------
1 | /*
2 | ** Copyright (C) 1999-2011Erik de Castro Lopo
3 | **
4 | ** This program is free software; you can redistribute it and/or modify
5 | ** it under the terms of the GNU Lesser General Public License as published by
6 | ** the Free Software Foundation; either version 2.1 of the License, or
7 | ** (at your option) any later version.
8 | **
9 | ** This program is distributed in the hope that it will be useful,
10 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of
11 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 | ** GNU Lesser General Public License for more details.
13 | **
14 | ** You should have received a copy of the GNU Lesser General Public License
15 | ** along with this program; if not, write to the Free Software
16 | ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 | */
18 |
19 | /*
20 | ** sndfile.h -- system-wide definitions
21 | **
22 | ** API documentation is in the doc/ directory of the source code tarball
23 | ** and at http://www.mega-nerd.com/libsndfile/api.html.
24 | */
25 |
26 | #ifndef SNDFILE_H
27 | #define SNDFILE_H
28 |
29 | /* This is the version 1.0.X header file. */
30 | #define SNDFILE_1
31 |
32 | #include
33 | #include
34 |
35 | #ifdef __cplusplus
36 | extern "C" {
37 | #endif /* __cplusplus */
38 |
39 | /* The following file types can be read and written.
40 | ** A file type would consist of a major type (ie SF_FORMAT_WAV) bitwise
41 | ** ORed with a minor type (ie SF_FORMAT_PCM). SF_FORMAT_TYPEMASK and
42 | ** SF_FORMAT_SUBMASK can be used to separate the major and minor file
43 | ** types.
44 | */
45 |
46 | enum
47 | { /* Major formats. */
48 | SF_FORMAT_WAV = 0x010000, /* Microsoft WAV format (little endian default). */
49 | SF_FORMAT_AIFF = 0x020000, /* Apple/SGI AIFF format (big endian). */
50 | SF_FORMAT_AU = 0x030000, /* Sun/NeXT AU format (big endian). */
51 | SF_FORMAT_RAW = 0x040000, /* RAW PCM data. */
52 | SF_FORMAT_PAF = 0x050000, /* Ensoniq PARIS file format. */
53 | SF_FORMAT_SVX = 0x060000, /* Amiga IFF / SVX8 / SV16 format. */
54 | SF_FORMAT_NIST = 0x070000, /* Sphere NIST format. */
55 | SF_FORMAT_VOC = 0x080000, /* VOC files. */
56 | SF_FORMAT_IRCAM = 0x0A0000, /* Berkeley/IRCAM/CARL */
57 | SF_FORMAT_W64 = 0x0B0000, /* Sonic Foundry's 64 bit RIFF/WAV */
58 | SF_FORMAT_MAT4 = 0x0C0000, /* Matlab (tm) V4.2 / GNU Octave 2.0 */
59 | SF_FORMAT_MAT5 = 0x0D0000, /* Matlab (tm) V5.0 / GNU Octave 2.1 */
60 | SF_FORMAT_PVF = 0x0E0000, /* Portable Voice Format */
61 | SF_FORMAT_XI = 0x0F0000, /* Fasttracker 2 Extended Instrument */
62 | SF_FORMAT_HTK = 0x100000, /* HMM Tool Kit format */
63 | SF_FORMAT_SDS = 0x110000, /* Midi Sample Dump Standard */
64 | SF_FORMAT_AVR = 0x120000, /* Audio Visual Research */
65 | SF_FORMAT_WAVEX = 0x130000, /* MS WAVE with WAVEFORMATEX */
66 | SF_FORMAT_SD2 = 0x160000, /* Sound Designer 2 */
67 | SF_FORMAT_FLAC = 0x170000, /* FLAC lossless file format */
68 | SF_FORMAT_CAF = 0x180000, /* Core Audio File format */
69 | SF_FORMAT_WVE = 0x190000, /* Psion WVE format */
70 | SF_FORMAT_OGG = 0x200000, /* Xiph OGG container */
71 | SF_FORMAT_MPC2K = 0x210000, /* Akai MPC 2000 sampler */
72 | SF_FORMAT_RF64 = 0x220000, /* RF64 WAV file */
73 |
74 | /* Subtypes from here on. */
75 |
76 | SF_FORMAT_PCM_S8 = 0x0001, /* Signed 8 bit data */
77 | SF_FORMAT_PCM_16 = 0x0002, /* Signed 16 bit data */
78 | SF_FORMAT_PCM_24 = 0x0003, /* Signed 24 bit data */
79 | SF_FORMAT_PCM_32 = 0x0004, /* Signed 32 bit data */
80 |
81 | SF_FORMAT_PCM_U8 = 0x0005, /* Unsigned 8 bit data (WAV and RAW only) */
82 |
83 | SF_FORMAT_FLOAT = 0x0006, /* 32 bit float data */
84 | SF_FORMAT_DOUBLE = 0x0007, /* 64 bit float data */
85 |
86 | SF_FORMAT_ULAW = 0x0010, /* U-Law encoded. */
87 | SF_FORMAT_ALAW = 0x0011, /* A-Law encoded. */
88 | SF_FORMAT_IMA_ADPCM = 0x0012, /* IMA ADPCM. */
89 | SF_FORMAT_MS_ADPCM = 0x0013, /* Microsoft ADPCM. */
90 |
91 | SF_FORMAT_GSM610 = 0x0020, /* GSM 6.10 encoding. */
92 | SF_FORMAT_VOX_ADPCM = 0x0021, /* OKI / Dialogix ADPCM */
93 |
94 | SF_FORMAT_G721_32 = 0x0030, /* 32kbs G721 ADPCM encoding. */
95 | SF_FORMAT_G723_24 = 0x0031, /* 24kbs G723 ADPCM encoding. */
96 | SF_FORMAT_G723_40 = 0x0032, /* 40kbs G723 ADPCM encoding. */
97 |
98 | SF_FORMAT_DWVW_12 = 0x0040, /* 12 bit Delta Width Variable Word encoding. */
99 | SF_FORMAT_DWVW_16 = 0x0041, /* 16 bit Delta Width Variable Word encoding. */
100 | SF_FORMAT_DWVW_24 = 0x0042, /* 24 bit Delta Width Variable Word encoding. */
101 | SF_FORMAT_DWVW_N = 0x0043, /* N bit Delta Width Variable Word encoding. */
102 |
103 | SF_FORMAT_DPCM_8 = 0x0050, /* 8 bit differential PCM (XI only) */
104 | SF_FORMAT_DPCM_16 = 0x0051, /* 16 bit differential PCM (XI only) */
105 |
106 | SF_FORMAT_VORBIS = 0x0060, /* Xiph Vorbis encoding. */
107 |
108 | /* Endian-ness options. */
109 |
110 | SF_ENDIAN_FILE = 0x00000000, /* Default file endian-ness. */
111 | SF_ENDIAN_LITTLE = 0x10000000, /* Force little endian-ness. */
112 | SF_ENDIAN_BIG = 0x20000000, /* Force big endian-ness. */
113 | SF_ENDIAN_CPU = 0x30000000, /* Force CPU endian-ness. */
114 |
115 | SF_FORMAT_SUBMASK = 0x0000FFFF,
116 | SF_FORMAT_TYPEMASK = 0x0FFF0000,
117 | SF_FORMAT_ENDMASK = 0x30000000
118 | } ;
119 |
120 | /*
121 | ** The following are the valid command numbers for the sf_command()
122 | ** interface. The use of these commands is documented in the file
123 | ** command.html in the doc directory of the source code distribution.
124 | */
125 |
126 | enum
127 | { SFC_GET_LIB_VERSION = 0x1000,
128 | SFC_GET_LOG_INFO = 0x1001,
129 | SFC_GET_CURRENT_SF_INFO = 0x1002,
130 |
131 |
132 | SFC_GET_NORM_DOUBLE = 0x1010,
133 | SFC_GET_NORM_FLOAT = 0x1011,
134 | SFC_SET_NORM_DOUBLE = 0x1012,
135 | SFC_SET_NORM_FLOAT = 0x1013,
136 | SFC_SET_SCALE_FLOAT_INT_READ = 0x1014,
137 | SFC_SET_SCALE_INT_FLOAT_WRITE = 0x1015,
138 |
139 | SFC_GET_SIMPLE_FORMAT_COUNT = 0x1020,
140 | SFC_GET_SIMPLE_FORMAT = 0x1021,
141 |
142 | SFC_GET_FORMAT_INFO = 0x1028,
143 |
144 | SFC_GET_FORMAT_MAJOR_COUNT = 0x1030,
145 | SFC_GET_FORMAT_MAJOR = 0x1031,
146 | SFC_GET_FORMAT_SUBTYPE_COUNT = 0x1032,
147 | SFC_GET_FORMAT_SUBTYPE = 0x1033,
148 |
149 | SFC_CALC_SIGNAL_MAX = 0x1040,
150 | SFC_CALC_NORM_SIGNAL_MAX = 0x1041,
151 | SFC_CALC_MAX_ALL_CHANNELS = 0x1042,
152 | SFC_CALC_NORM_MAX_ALL_CHANNELS = 0x1043,
153 | SFC_GET_SIGNAL_MAX = 0x1044,
154 | SFC_GET_MAX_ALL_CHANNELS = 0x1045,
155 |
156 | SFC_SET_ADD_PEAK_CHUNK = 0x1050,
157 | SFC_SET_ADD_HEADER_PAD_CHUNK = 0x1051,
158 |
159 | SFC_UPDATE_HEADER_NOW = 0x1060,
160 | SFC_SET_UPDATE_HEADER_AUTO = 0x1061,
161 |
162 | SFC_FILE_TRUNCATE = 0x1080,
163 |
164 | SFC_SET_RAW_START_OFFSET = 0x1090,
165 |
166 | SFC_SET_DITHER_ON_WRITE = 0x10A0,
167 | SFC_SET_DITHER_ON_READ = 0x10A1,
168 |
169 | SFC_GET_DITHER_INFO_COUNT = 0x10A2,
170 | SFC_GET_DITHER_INFO = 0x10A3,
171 |
172 | SFC_GET_EMBED_FILE_INFO = 0x10B0,
173 |
174 | SFC_SET_CLIPPING = 0x10C0,
175 | SFC_GET_CLIPPING = 0x10C1,
176 |
177 | SFC_GET_INSTRUMENT = 0x10D0,
178 | SFC_SET_INSTRUMENT = 0x10D1,
179 |
180 | SFC_GET_LOOP_INFO = 0x10E0,
181 |
182 | SFC_GET_BROADCAST_INFO = 0x10F0,
183 | SFC_SET_BROADCAST_INFO = 0x10F1,
184 |
185 | SFC_GET_CHANNEL_MAP_INFO = 0x1100,
186 | SFC_SET_CHANNEL_MAP_INFO = 0x1101,
187 |
188 | SFC_RAW_DATA_NEEDS_ENDSWAP = 0x1110,
189 |
190 | /* Support for Wavex Ambisonics Format */
191 | SFC_WAVEX_SET_AMBISONIC = 0x1200,
192 | SFC_WAVEX_GET_AMBISONIC = 0x1201,
193 |
194 | SFC_SET_VBR_ENCODING_QUALITY = 0x1300,
195 |
196 | /* Following commands for testing only. */
197 | SFC_TEST_IEEE_FLOAT_REPLACE = 0x6001,
198 |
199 | /*
200 | ** SFC_SET_ADD_* values are deprecated and will disappear at some
201 | ** time in the future. They are guaranteed to be here up to and
202 | ** including version 1.0.8 to avoid breakage of existng software.
203 | ** They currently do nothing and will continue to do nothing.
204 | */
205 | SFC_SET_ADD_DITHER_ON_WRITE = 0x1070,
206 | SFC_SET_ADD_DITHER_ON_READ = 0x1071
207 | } ;
208 |
209 |
210 | /*
211 | ** String types that can be set and read from files. Not all file types
212 | ** support this and even the file types which support one, may not support
213 | ** all string types.
214 | */
215 |
216 | enum
217 | { SF_STR_TITLE = 0x01,
218 | SF_STR_COPYRIGHT = 0x02,
219 | SF_STR_SOFTWARE = 0x03,
220 | SF_STR_ARTIST = 0x04,
221 | SF_STR_COMMENT = 0x05,
222 | SF_STR_DATE = 0x06,
223 | SF_STR_ALBUM = 0x07,
224 | SF_STR_LICENSE = 0x08,
225 | SF_STR_TRACKNUMBER = 0x09,
226 | SF_STR_GENRE = 0x10
227 | } ;
228 |
229 | /*
230 | ** Use the following as the start and end index when doing metadata
231 | ** transcoding.
232 | */
233 |
234 | #define SF_STR_FIRST SF_STR_TITLE
235 | #define SF_STR_LAST SF_STR_GENRE
236 |
237 | enum
238 | { /* True and false */
239 | SF_FALSE = 0,
240 | SF_TRUE = 1,
241 |
242 | /* Modes for opening files. */
243 | SFM_READ = 0x10,
244 | SFM_WRITE = 0x20,
245 | SFM_RDWR = 0x30,
246 |
247 | SF_AMBISONIC_NONE = 0x40,
248 | SF_AMBISONIC_B_FORMAT = 0x41
249 | } ;
250 |
251 | /* Public error values. These are guaranteed to remain unchanged for the duration
252 | ** of the library major version number.
253 | ** There are also a large number of private error numbers which are internal to
254 | ** the library which can change at any time.
255 | */
256 |
257 | enum
258 | { SF_ERR_NO_ERROR = 0,
259 | SF_ERR_UNRECOGNISED_FORMAT = 1,
260 | SF_ERR_SYSTEM = 2,
261 | SF_ERR_MALFORMED_FILE = 3,
262 | SF_ERR_UNSUPPORTED_ENCODING = 4
263 | } ;
264 |
265 |
266 | /* Channel map values (used with SFC_SET/GET_CHANNEL_MAP).
267 | */
268 |
269 | enum
270 | { SF_CHANNEL_MAP_INVALID = 0,
271 | SF_CHANNEL_MAP_MONO = 1,
272 | SF_CHANNEL_MAP_LEFT, /* Apple calls this 'Left' */
273 | SF_CHANNEL_MAP_RIGHT, /* Apple calls this 'Right' */
274 | SF_CHANNEL_MAP_CENTER, /* Apple calls this 'Center' */
275 | SF_CHANNEL_MAP_FRONT_LEFT,
276 | SF_CHANNEL_MAP_FRONT_RIGHT,
277 | SF_CHANNEL_MAP_FRONT_CENTER,
278 | SF_CHANNEL_MAP_REAR_CENTER, /* Apple calls this 'Center Surround', Msft calls this 'Back Center' */
279 | SF_CHANNEL_MAP_REAR_LEFT, /* Apple calls this 'Left Surround', Msft calls this 'Back Left' */
280 | SF_CHANNEL_MAP_REAR_RIGHT, /* Apple calls this 'Right Surround', Msft calls this 'Back Right' */
281 | SF_CHANNEL_MAP_LFE, /* Apple calls this 'LFEScreen', Msft calls this 'Low Frequency' */
282 | SF_CHANNEL_MAP_FRONT_LEFT_OF_CENTER, /* Apple calls this 'Left Center' */
283 | SF_CHANNEL_MAP_FRONT_RIGHT_OF_CENTER, /* Apple calls this 'Right Center */
284 | SF_CHANNEL_MAP_SIDE_LEFT, /* Apple calls this 'Left Surround Direct' */
285 | SF_CHANNEL_MAP_SIDE_RIGHT, /* Apple calls this 'Right Surround Direct' */
286 | SF_CHANNEL_MAP_TOP_CENTER, /* Apple calls this 'Top Center Surround' */
287 | SF_CHANNEL_MAP_TOP_FRONT_LEFT, /* Apple calls this 'Vertical Height Left' */
288 | SF_CHANNEL_MAP_TOP_FRONT_RIGHT, /* Apple calls this 'Vertical Height Right' */
289 | SF_CHANNEL_MAP_TOP_FRONT_CENTER, /* Apple calls this 'Vertical Height Center' */
290 | SF_CHANNEL_MAP_TOP_REAR_LEFT, /* Apple and MS call this 'Top Back Left' */
291 | SF_CHANNEL_MAP_TOP_REAR_RIGHT, /* Apple and MS call this 'Top Back Right' */
292 | SF_CHANNEL_MAP_TOP_REAR_CENTER, /* Apple and MS call this 'Top Back Center' */
293 |
294 | SF_CHANNEL_MAP_AMBISONIC_B_W,
295 | SF_CHANNEL_MAP_AMBISONIC_B_X,
296 | SF_CHANNEL_MAP_AMBISONIC_B_Y,
297 | SF_CHANNEL_MAP_AMBISONIC_B_Z,
298 |
299 | SF_CHANNEL_MAP_MAX
300 | } ;
301 |
302 |
303 | /* A SNDFILE* pointer can be passed around much like stdio.h's FILE* pointer. */
304 |
305 | typedef struct SNDFILE_tag SNDFILE ;
306 |
307 | /* The following typedef is system specific and is defined when libsndfile is
308 | ** compiled. sf_count_t will be a 64 bit value when the underlying OS allows
309 | ** 64 bit file offsets.
310 | ** On windows, we need to allow the same header file to be compiler by both GCC
311 | ** and the Microsoft compiler.
312 | */
313 |
314 | #if (defined (_MSCVER) || defined (_MSC_VER))
315 | typedef __int64 sf_count_t ;
316 | #define SF_COUNT_MAX 0x7fffffffffffffffi64
317 | #else
318 | typedef int64_t sf_count_t ;
319 | #define SF_COUNT_MAX 0x7FFFFFFFFFFFFFFFLL
320 | #endif
321 |
322 |
323 | /* A pointer to a SF_INFO structure is passed to sf_open () and filled in.
324 | ** On write, the SF_INFO structure is filled in by the user and passed into
325 | ** sf_open ().
326 | */
327 |
328 | struct SF_INFO
329 | { sf_count_t frames ; /* Used to be called samples. Changed to avoid confusion. */
330 | int samplerate ;
331 | int channels ;
332 | int format ;
333 | int sections ;
334 | int seekable ;
335 | } ;
336 |
337 | typedef struct SF_INFO SF_INFO ;
338 |
339 | /* The SF_FORMAT_INFO struct is used to retrieve information about the sound
340 | ** file formats libsndfile supports using the sf_command () interface.
341 | **
342 | ** Using this interface will allow applications to support new file formats
343 | ** and encoding types when libsndfile is upgraded, without requiring
344 | ** re-compilation of the application.
345 | **
346 | ** Please consult the libsndfile documentation (particularly the information
347 | ** on the sf_command () interface) for examples of its use.
348 | */
349 |
350 | typedef struct
351 | { int format ;
352 | const char *name ;
353 | const char *extension ;
354 | } SF_FORMAT_INFO ;
355 |
356 | /*
357 | ** Enums and typedefs for adding dither on read and write.
358 | ** See the html documentation for sf_command(), SFC_SET_DITHER_ON_WRITE
359 | ** and SFC_SET_DITHER_ON_READ.
360 | */
361 |
362 | enum
363 | { SFD_DEFAULT_LEVEL = 0,
364 | SFD_CUSTOM_LEVEL = 0x40000000,
365 |
366 | SFD_NO_DITHER = 500,
367 | SFD_WHITE = 501,
368 | SFD_TRIANGULAR_PDF = 502
369 | } ;
370 |
371 | typedef struct
372 | { int type ;
373 | double level ;
374 | const char *name ;
375 | } SF_DITHER_INFO ;
376 |
377 | /* Struct used to retrieve information about a file embedded within a
378 | ** larger file. See SFC_GET_EMBED_FILE_INFO.
379 | */
380 |
381 | typedef struct
382 | { sf_count_t offset ;
383 | sf_count_t length ;
384 | } SF_EMBED_FILE_INFO ;
385 |
386 | /*
387 | ** Structs used to retrieve music sample information from a file.
388 | */
389 |
390 | enum
391 | { /*
392 | ** The loop mode field in SF_INSTRUMENT will be one of the following.
393 | */
394 | SF_LOOP_NONE = 800,
395 | SF_LOOP_FORWARD,
396 | SF_LOOP_BACKWARD,
397 | SF_LOOP_ALTERNATING
398 | } ;
399 |
400 | typedef struct
401 | { int gain ;
402 | char basenote, detune ;
403 | char velocity_lo, velocity_hi ;
404 | char key_lo, key_hi ;
405 | int loop_count ;
406 |
407 | struct
408 | { int mode ;
409 | unsigned int start ;
410 | unsigned int end ;
411 | unsigned int count ;
412 | } loops [16] ; /* make variable in a sensible way */
413 | } SF_INSTRUMENT ;
414 |
415 |
416 |
417 | /* Struct used to retrieve loop information from a file.*/
418 | typedef struct
419 | {
420 | short time_sig_num ; /* any positive integer > 0 */
421 | short time_sig_den ; /* any positive power of 2 > 0 */
422 | int loop_mode ; /* see SF_LOOP enum */
423 |
424 | int num_beats ; /* this is NOT the amount of quarter notes !!!*/
425 | /* a full bar of 4/4 is 4 beats */
426 | /* a full bar of 7/8 is 7 beats */
427 |
428 | float bpm ; /* suggestion, as it can be calculated using other fields:*/
429 | /* file's lenght, file's sampleRate and our time_sig_den*/
430 | /* -> bpms are always the amount of _quarter notes_ per minute */
431 |
432 | int root_key ; /* MIDI note, or -1 for None */
433 | int future [6] ;
434 | } SF_LOOP_INFO ;
435 |
436 |
437 | /* Struct used to retrieve broadcast (EBU) information from a file.
438 | ** Strongly (!) based on EBU "bext" chunk format used in Broadcast WAVE.
439 | */
440 | #define SF_BROADCAST_INFO_VAR(coding_hist_size) \
441 | struct \
442 | { char description [256] ; \
443 | char originator [32] ; \
444 | char originator_reference [32] ; \
445 | char origination_date [10] ; \
446 | char origination_time [8] ; \
447 | unsigned int time_reference_low ; \
448 | unsigned int time_reference_high ; \
449 | short version ; \
450 | char umid [64] ; \
451 | char reserved [190] ; \
452 | unsigned int coding_history_size ; \
453 | char coding_history [coding_hist_size] ; \
454 | }
455 |
456 | /* SF_BROADCAST_INFO is the above struct with coding_history field of 256 bytes. */
457 | typedef SF_BROADCAST_INFO_VAR (256) SF_BROADCAST_INFO ;
458 |
459 |
460 | /* Virtual I/O functionality. */
461 |
462 | typedef sf_count_t (*sf_vio_get_filelen) (void *user_data) ;
463 | typedef sf_count_t (*sf_vio_seek) (sf_count_t offset, int whence, void *user_data) ;
464 | typedef sf_count_t (*sf_vio_read) (void *ptr, sf_count_t count, void *user_data) ;
465 | typedef sf_count_t (*sf_vio_write) (const void *ptr, sf_count_t count, void *user_data) ;
466 | typedef sf_count_t (*sf_vio_tell) (void *user_data) ;
467 |
468 | struct SF_VIRTUAL_IO
469 | { sf_vio_get_filelen get_filelen ;
470 | sf_vio_seek seek ;
471 | sf_vio_read read ;
472 | sf_vio_write write ;
473 | sf_vio_tell tell ;
474 | } ;
475 |
476 | typedef struct SF_VIRTUAL_IO SF_VIRTUAL_IO ;
477 |
478 |
479 | /* Open the specified file for read, write or both. On error, this will
480 | ** return a NULL pointer. To find the error number, pass a NULL SNDFILE
481 | ** to sf_strerror ().
482 | ** All calls to sf_open() should be matched with a call to sf_close().
483 | */
484 |
485 | SNDFILE* sf_open (const char *path, int mode, SF_INFO *sfinfo) ;
486 |
487 |
488 | /* Use the existing file descriptor to create a SNDFILE object. If close_desc
489 | ** is TRUE, the file descriptor will be closed when sf_close() is called. If
490 | ** it is FALSE, the descritor will not be closed.
491 | ** When passed a descriptor like this, the library will assume that the start
492 | ** of file header is at the current file offset. This allows sound files within
493 | ** larger container files to be read and/or written.
494 | ** On error, this will return a NULL pointer. To find the error number, pass a
495 | ** NULL SNDFILE to sf_strerror ().
496 | ** All calls to sf_open_fd() should be matched with a call to sf_close().
497 |
498 | */
499 |
500 | SNDFILE* sf_open_fd (int fd, int mode, SF_INFO *sfinfo, int close_desc) ;
501 |
502 | SNDFILE* sf_open_virtual (SF_VIRTUAL_IO *sfvirtual, int mode, SF_INFO *sfinfo, void *user_data) ;
503 |
504 |
505 | /* sf_error () returns a error number which can be translated to a text
506 | ** string using sf_error_number().
507 | */
508 |
509 | int sf_error (SNDFILE *sndfile) ;
510 |
511 |
512 | /* sf_strerror () returns to the caller a pointer to the current error message for
513 | ** the given SNDFILE.
514 | */
515 |
516 | const char* sf_strerror (SNDFILE *sndfile) ;
517 |
518 |
519 | /* sf_error_number () allows the retrieval of the error string for each internal
520 | ** error number.
521 | **
522 | */
523 |
524 | const char* sf_error_number (int errnum) ;
525 |
526 |
527 | /* The following two error functions are deprecated but they will remain in the
528 | ** library for the forseeable future. The function sf_strerror() should be used
529 | ** in their place.
530 | */
531 |
532 | int sf_perror (SNDFILE *sndfile) ;
533 | int sf_error_str (SNDFILE *sndfile, char* str, size_t len) ;
534 |
535 |
536 | /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
537 |
538 | int sf_command (SNDFILE *sndfile, int command, void *data, int datasize) ;
539 |
540 |
541 | /* Return TRUE if fields of the SF_INFO struct are a valid combination of values. */
542 |
543 | int sf_format_check (const SF_INFO *info) ;
544 |
545 |
546 | /* Seek within the waveform data chunk of the SNDFILE. sf_seek () uses
547 | ** the same values for whence (SEEK_SET, SEEK_CUR and SEEK_END) as
548 | ** stdio.h function fseek ().
549 | ** An offset of zero with whence set to SEEK_SET will position the
550 | ** read / write pointer to the first data sample.
551 | ** On success sf_seek returns the current position in (multi-channel)
552 | ** samples from the start of the file.
553 | ** Please see the libsndfile documentation for moving the read pointer
554 | ** separately from the write pointer on files open in mode SFM_RDWR.
555 | ** On error all of these functions return -1.
556 | */
557 |
558 | sf_count_t sf_seek (SNDFILE *sndfile, sf_count_t frames, int whence) ;
559 |
560 |
561 | /* Functions for retrieving and setting string data within sound files.
562 | ** Not all file types support this features; AIFF and WAV do. For both
563 | ** functions, the str_type parameter must be one of the SF_STR_* values
564 | ** defined above.
565 | ** On error, sf_set_string() returns non-zero while sf_get_string()
566 | ** returns NULL.
567 | */
568 |
569 | int sf_set_string (SNDFILE *sndfile, int str_type, const char* str) ;
570 |
571 | const char* sf_get_string (SNDFILE *sndfile, int str_type) ;
572 |
573 |
574 | /* Return the library version string. */
575 |
576 | const char * sf_version_string (void) ;
577 |
578 |
579 | /* Functions for reading/writing the waveform data of a sound file.
580 | */
581 |
582 | sf_count_t sf_read_raw (SNDFILE *sndfile, void *ptr, sf_count_t bytes) ;
583 | sf_count_t sf_write_raw (SNDFILE *sndfile, const void *ptr, sf_count_t bytes) ;
584 |
585 |
586 | /* Functions for reading and writing the data chunk in terms of frames.
587 | ** The number of items actually read/written = frames * number of channels.
588 | ** sf_xxxx_raw read/writes the raw data bytes from/to the file
589 | ** sf_xxxx_short passes data in the native short format
590 | ** sf_xxxx_int passes data in the native int format
591 | ** sf_xxxx_float passes data in the native float format
592 | ** sf_xxxx_double passes data in the native double format
593 | ** All of these read/write function return number of frames read/written.
594 | */
595 |
596 | sf_count_t sf_readf_short (SNDFILE *sndfile, short *ptr, sf_count_t frames) ;
597 | sf_count_t sf_writef_short (SNDFILE *sndfile, const short *ptr, sf_count_t frames) ;
598 |
599 | sf_count_t sf_readf_int (SNDFILE *sndfile, int *ptr, sf_count_t frames) ;
600 | sf_count_t sf_writef_int (SNDFILE *sndfile, const int *ptr, sf_count_t frames) ;
601 |
602 | sf_count_t sf_readf_float (SNDFILE *sndfile, float *ptr, sf_count_t frames) ;
603 | sf_count_t sf_writef_float (SNDFILE *sndfile, const float *ptr, sf_count_t frames) ;
604 |
605 | sf_count_t sf_readf_double (SNDFILE *sndfile, double *ptr, sf_count_t frames) ;
606 | sf_count_t sf_writef_double (SNDFILE *sndfile, const double *ptr, sf_count_t frames) ;
607 |
608 |
609 | /* Functions for reading and writing the data chunk in terms of items.
610 | ** Otherwise similar to above.
611 | ** All of these read/write function return number of items read/written.
612 | */
613 |
614 | sf_count_t sf_read_short (SNDFILE *sndfile, short *ptr, sf_count_t items) ;
615 | sf_count_t sf_write_short (SNDFILE *sndfile, const short *ptr, sf_count_t items) ;
616 |
617 | sf_count_t sf_read_int (SNDFILE *sndfile, int *ptr, sf_count_t items) ;
618 | sf_count_t sf_write_int (SNDFILE *sndfile, const int *ptr, sf_count_t items) ;
619 |
620 | sf_count_t sf_read_float (SNDFILE *sndfile, float *ptr, sf_count_t items) ;
621 | sf_count_t sf_write_float (SNDFILE *sndfile, const float *ptr, sf_count_t items) ;
622 |
623 | sf_count_t sf_read_double (SNDFILE *sndfile, double *ptr, sf_count_t items) ;
624 | sf_count_t sf_write_double (SNDFILE *sndfile, const double *ptr, sf_count_t items) ;
625 |
626 |
627 | /* Close the SNDFILE and clean up all memory allocations associated with this
628 | ** file.
629 | ** Returns 0 on success, or an error number.
630 | */
631 |
632 | int sf_close (SNDFILE *sndfile) ;
633 |
634 |
635 | /* If the file is opened SFM_WRITE or SFM_RDWR, call fsync() on the file
636 | ** to force the writing of data to disk. If the file is opened SFM_READ
637 | ** no action is taken.
638 | */
639 |
640 | void sf_write_sync (SNDFILE *sndfile) ;
641 |
642 |
643 |
644 | /* The function sf_wchar_open() is Windows Only!
645 | ** Open a file passing in a Windows Unicode filename. Otherwise, this is
646 | ** the same as sf_open().
647 | **
648 | ** In order for this to work, you need to do the following:
649 | **
650 | ** #include
651 | ** #define ENABLE_SNDFILE_WINDOWS_PROTOTYPES 1
652 | ** #including
653 | */
654 |
655 | #if (defined (ENABLE_SNDFILE_WINDOWS_PROTOTYPES) && ENABLE_SNDFILE_WINDOWS_PROTOTYPES)
656 | SNDFILE* sf_wchar_open (LPCWSTR wpath, int mode, SF_INFO *sfinfo) ;
657 | #endif
658 |
659 |
660 |
661 | #ifdef __cplusplus
662 | } /* extern "C" */
663 | #endif /* __cplusplus */
664 |
665 | #endif /* SNDFILE_H */
666 |
667 |
--------------------------------------------------------------------------------
/libs/sndfile/includes/sndfile.hh:
--------------------------------------------------------------------------------
1 | /*
2 | ** Copyright (C) 2005-2011 Erik de Castro Lopo
3 | **
4 | ** All rights reserved.
5 | **
6 | ** Redistribution and use in source and binary forms, with or without
7 | ** modification, are permitted provided that the following conditions are
8 | ** met:
9 | **
10 | ** * Redistributions of source code must retain the above copyright
11 | ** notice, this list of conditions and the following disclaimer.
12 | ** * Redistributions in binary form must reproduce the above copyright
13 | ** notice, this list of conditions and the following disclaimer in
14 | ** the documentation and/or other materials provided with the
15 | ** distribution.
16 | ** * Neither the author nor the names of any contributors may be used
17 | ** to endorse or promote products derived from this software without
18 | ** specific prior written permission.
19 | **
20 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 | ** TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 | ** PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24 | ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 | ** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26 | ** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27 | ** OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 | ** WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29 | ** OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
30 | ** ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 | */
32 |
33 | /*
34 | ** The above modified BSD style license (GPL and LGPL compatible) applies to
35 | ** this file. It does not apply to libsndfile itself which is released under
36 | ** the GNU LGPL or the libsndfile test suite which is released under the GNU
37 | ** GPL.
38 | ** This means that this header file can be used under this modified BSD style
39 | ** license, but the LGPL still holds for the libsndfile library itself.
40 | */
41 |
42 | /*
43 | ** sndfile.hh -- A lightweight C++ wrapper for the libsndfile API.
44 | **
45 | ** All the methods are inlines and all functionality is contained in this
46 | ** file. There is no separate implementation file.
47 | **
48 | ** API documentation is in the doc/ directory of the source code tarball
49 | ** and at http://www.mega-nerd.com/libsndfile/api.html.
50 | */
51 |
52 | #ifndef SNDFILE_HH
53 | #define SNDFILE_HH
54 |
55 | #include
56 |
57 | #include
58 | #include // for std::nothrow
59 |
60 | class SndfileHandle
61 | { private :
62 | struct SNDFILE_ref
63 | { SNDFILE_ref (void) ;
64 | ~SNDFILE_ref (void) ;
65 |
66 | SNDFILE *sf ;
67 | SF_INFO sfinfo ;
68 | int ref ;
69 | } ;
70 |
71 | SNDFILE_ref *p ;
72 |
73 | public :
74 | /* Default constructor */
75 | SndfileHandle (void) : p (NULL) {} ;
76 | SndfileHandle (const char *path, int mode = SFM_READ,
77 | int format = 0, int channels = 0, int samplerate = 0) ;
78 | SndfileHandle (std::string const & path, int mode = SFM_READ,
79 | int format = 0, int channels = 0, int samplerate = 0) ;
80 | SndfileHandle (int fd, bool close_desc, int mode = SFM_READ,
81 | int format = 0, int channels = 0, int samplerate = 0) ;
82 |
83 | #ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES
84 | SndfileHandle (LPCWSTR wpath, int mode = SFM_READ,
85 | int format = 0, int channels = 0, int samplerate = 0) ;
86 | #endif
87 |
88 | ~SndfileHandle (void) ;
89 |
90 | SndfileHandle (const SndfileHandle &orig) ;
91 | SndfileHandle & operator = (const SndfileHandle &rhs) ;
92 |
93 | /* Mainly for debugging/testing. */
94 | int refCount (void) const { return (p == NULL) ? 0 : p->ref ; }
95 |
96 | operator bool () const { return (p != NULL) ; }
97 |
98 | bool operator == (const SndfileHandle &rhs) const { return (p == rhs.p) ; }
99 |
100 | sf_count_t frames (void) const { return p ? p->sfinfo.frames : 0 ; }
101 | int format (void) const { return p ? p->sfinfo.format : 0 ; }
102 | int channels (void) const { return p ? p->sfinfo.channels : 0 ; }
103 | int samplerate (void) const { return p ? p->sfinfo.samplerate : 0 ; }
104 |
105 | int error (void) const ;
106 | const char * strError (void) const ;
107 |
108 | int command (int cmd, void *data, int datasize) ;
109 |
110 | sf_count_t seek (sf_count_t frames, int whence) ;
111 |
112 | void writeSync (void) ;
113 |
114 | int setString (int str_type, const char* str) ;
115 |
116 | const char* getString (int str_type) const ;
117 |
118 | static int formatCheck (int format, int channels, int samplerate) ;
119 |
120 | sf_count_t read (short *ptr, sf_count_t items) ;
121 | sf_count_t read (int *ptr, sf_count_t items) ;
122 | sf_count_t read (float *ptr, sf_count_t items) ;
123 | sf_count_t read (double *ptr, sf_count_t items) ;
124 |
125 | sf_count_t write (const short *ptr, sf_count_t items) ;
126 | sf_count_t write (const int *ptr, sf_count_t items) ;
127 | sf_count_t write (const float *ptr, sf_count_t items) ;
128 | sf_count_t write (const double *ptr, sf_count_t items) ;
129 |
130 | sf_count_t readf (short *ptr, sf_count_t frames) ;
131 | sf_count_t readf (int *ptr, sf_count_t frames) ;
132 | sf_count_t readf (float *ptr, sf_count_t frames) ;
133 | sf_count_t readf (double *ptr, sf_count_t frames) ;
134 |
135 | sf_count_t writef (const short *ptr, sf_count_t frames) ;
136 | sf_count_t writef (const int *ptr, sf_count_t frames) ;
137 | sf_count_t writef (const float *ptr, sf_count_t frames) ;
138 | sf_count_t writef (const double *ptr, sf_count_t frames) ;
139 |
140 | sf_count_t readRaw (void *ptr, sf_count_t bytes) ;
141 | sf_count_t writeRaw (const void *ptr, sf_count_t bytes) ;
142 |
143 | /**< Raw access to the handle. SndfileHandle keeps ownership. */
144 | SNDFILE * rawHandle (void) ;
145 |
146 | /**< Take ownership of handle, iff reference count is 1. */
147 | SNDFILE * takeOwnership (void) ;
148 | } ;
149 |
150 | /*==============================================================================
151 | ** Nothing but implementation below.
152 | */
153 |
154 | inline
155 | SndfileHandle::SNDFILE_ref::SNDFILE_ref (void)
156 | : ref (1)
157 | {}
158 |
159 | inline
160 | SndfileHandle::SNDFILE_ref::~SNDFILE_ref (void)
161 | { if (sf != NULL) sf_close (sf) ; }
162 |
163 | inline
164 | SndfileHandle::SndfileHandle (const char *path, int mode, int fmt, int chans, int srate)
165 | : p (NULL)
166 | {
167 | p = new (std::nothrow) SNDFILE_ref () ;
168 |
169 | if (p != NULL)
170 | { p->ref = 1 ;
171 |
172 | p->sfinfo.frames = 0 ;
173 | p->sfinfo.channels = chans ;
174 | p->sfinfo.format = fmt ;
175 | p->sfinfo.samplerate = srate ;
176 | p->sfinfo.sections = 0 ;
177 | p->sfinfo.seekable = 0 ;
178 |
179 | p->sf = sf_open (path, mode, &p->sfinfo) ;
180 | } ;
181 |
182 | return ;
183 | } /* SndfileHandle const char * constructor */
184 |
185 | inline
186 | SndfileHandle::SndfileHandle (std::string const & path, int mode, int fmt, int chans, int srate)
187 | : p (NULL)
188 | {
189 | p = new (std::nothrow) SNDFILE_ref () ;
190 |
191 | if (p != NULL)
192 | { p->ref = 1 ;
193 |
194 | p->sfinfo.frames = 0 ;
195 | p->sfinfo.channels = chans ;
196 | p->sfinfo.format = fmt ;
197 | p->sfinfo.samplerate = srate ;
198 | p->sfinfo.sections = 0 ;
199 | p->sfinfo.seekable = 0 ;
200 |
201 | p->sf = sf_open (path.c_str (), mode, &p->sfinfo) ;
202 | } ;
203 |
204 | return ;
205 | } /* SndfileHandle std::string constructor */
206 |
207 | inline
208 | SndfileHandle::SndfileHandle (int fd, bool close_desc, int mode, int fmt, int chans, int srate)
209 | : p (NULL)
210 | {
211 | if (fd < 0)
212 | return ;
213 |
214 | p = new (std::nothrow) SNDFILE_ref () ;
215 |
216 | if (p != NULL)
217 | { p->ref = 1 ;
218 |
219 | p->sfinfo.frames = 0 ;
220 | p->sfinfo.channels = chans ;
221 | p->sfinfo.format = fmt ;
222 | p->sfinfo.samplerate = srate ;
223 | p->sfinfo.sections = 0 ;
224 | p->sfinfo.seekable = 0 ;
225 |
226 | p->sf = sf_open_fd (fd, mode, &p->sfinfo, close_desc) ;
227 | } ;
228 |
229 | return ;
230 | } /* SndfileHandle fd constructor */
231 |
232 | inline
233 | SndfileHandle::~SndfileHandle (void)
234 | { if (p != NULL && --p->ref == 0)
235 | delete p ;
236 | } /* SndfileHandle destructor */
237 |
238 |
239 | inline
240 | SndfileHandle::SndfileHandle (const SndfileHandle &orig)
241 | : p (orig.p)
242 | { if (p != NULL)
243 | ++p->ref ;
244 | } /* SndfileHandle copy constructor */
245 |
246 | inline SndfileHandle &
247 | SndfileHandle::operator = (const SndfileHandle &rhs)
248 | {
249 | if (&rhs == this)
250 | return *this ;
251 | if (p != NULL && --p->ref == 0)
252 | delete p ;
253 |
254 | p = rhs.p ;
255 | if (p != NULL)
256 | ++p->ref ;
257 |
258 | return *this ;
259 | } /* SndfileHandle assignment operator */
260 |
261 | inline int
262 | SndfileHandle::error (void) const
263 | { return sf_error (p->sf) ; }
264 |
265 | inline const char *
266 | SndfileHandle::strError (void) const
267 | { return sf_strerror (p->sf) ; }
268 |
269 | inline int
270 | SndfileHandle::command (int cmd, void *data, int datasize)
271 | { return sf_command (p->sf, cmd, data, datasize) ; }
272 |
273 | inline sf_count_t
274 | SndfileHandle::seek (sf_count_t frame_count, int whence)
275 | { return sf_seek (p->sf, frame_count, whence) ; }
276 |
277 | inline void
278 | SndfileHandle::writeSync (void)
279 | { sf_write_sync (p->sf) ; }
280 |
281 | inline int
282 | SndfileHandle::setString (int str_type, const char* str)
283 | { return sf_set_string (p->sf, str_type, str) ; }
284 |
285 | inline const char*
286 | SndfileHandle::getString (int str_type) const
287 | { return sf_get_string (p->sf, str_type) ; }
288 |
289 | inline int
290 | SndfileHandle::formatCheck (int fmt, int chans, int srate)
291 | {
292 | SF_INFO sfinfo ;
293 |
294 | sfinfo.frames = 0 ;
295 | sfinfo.channels = chans ;
296 | sfinfo.format = fmt ;
297 | sfinfo.samplerate = srate ;
298 | sfinfo.sections = 0 ;
299 | sfinfo.seekable = 0 ;
300 |
301 | return sf_format_check (&sfinfo) ;
302 | }
303 |
304 | /*---------------------------------------------------------------------*/
305 |
306 | inline sf_count_t
307 | SndfileHandle::read (short *ptr, sf_count_t items)
308 | { return sf_read_short (p->sf, ptr, items) ; }
309 |
310 | inline sf_count_t
311 | SndfileHandle::read (int *ptr, sf_count_t items)
312 | { return sf_read_int (p->sf, ptr, items) ; }
313 |
314 | inline sf_count_t
315 | SndfileHandle::read (float *ptr, sf_count_t items)
316 | { return sf_read_float (p->sf, ptr, items) ; }
317 |
318 | inline sf_count_t
319 | SndfileHandle::read (double *ptr, sf_count_t items)
320 | { return sf_read_double (p->sf, ptr, items) ; }
321 |
322 | inline sf_count_t
323 | SndfileHandle::write (const short *ptr, sf_count_t items)
324 | { return sf_write_short (p->sf, ptr, items) ; }
325 |
326 | inline sf_count_t
327 | SndfileHandle::write (const int *ptr, sf_count_t items)
328 | { return sf_write_int (p->sf, ptr, items) ; }
329 |
330 | inline sf_count_t
331 | SndfileHandle::write (const float *ptr, sf_count_t items)
332 | { return sf_write_float (p->sf, ptr, items) ; }
333 |
334 | inline sf_count_t
335 | SndfileHandle::write (const double *ptr, sf_count_t items)
336 | { return sf_write_double (p->sf, ptr, items) ; }
337 |
338 | inline sf_count_t
339 | SndfileHandle::readf (short *ptr, sf_count_t frame_count)
340 | { return sf_readf_short (p->sf, ptr, frame_count) ; }
341 |
342 | inline sf_count_t
343 | SndfileHandle::readf (int *ptr, sf_count_t frame_count)
344 | { return sf_readf_int (p->sf, ptr, frame_count) ; }
345 |
346 | inline sf_count_t
347 | SndfileHandle::readf (float *ptr, sf_count_t frame_count)
348 | { return sf_readf_float (p->sf, ptr, frame_count) ; }
349 |
350 | inline sf_count_t
351 | SndfileHandle::readf (double *ptr, sf_count_t frame_count)
352 | { return sf_readf_double (p->sf, ptr, frame_count) ; }
353 |
354 | inline sf_count_t
355 | SndfileHandle::writef (const short *ptr, sf_count_t frame_count)
356 | { return sf_writef_short (p->sf, ptr, frame_count) ; }
357 |
358 | inline sf_count_t
359 | SndfileHandle::writef (const int *ptr, sf_count_t frame_count)
360 | { return sf_writef_int (p->sf, ptr, frame_count) ; }
361 |
362 | inline sf_count_t
363 | SndfileHandle::writef (const float *ptr, sf_count_t frame_count)
364 | { return sf_writef_float (p->sf, ptr, frame_count) ; }
365 |
366 | inline sf_count_t
367 | SndfileHandle::writef (const double *ptr, sf_count_t frame_count)
368 | { return sf_writef_double (p->sf, ptr, frame_count) ; }
369 |
370 | inline sf_count_t
371 | SndfileHandle::readRaw (void *ptr, sf_count_t bytes)
372 | { return sf_read_raw (p->sf, ptr, bytes) ; }
373 |
374 | inline sf_count_t
375 | SndfileHandle::writeRaw (const void *ptr, sf_count_t bytes)
376 | { return sf_write_raw (p->sf, ptr, bytes) ; }
377 |
378 | inline SNDFILE *
379 | SndfileHandle::rawHandle (void)
380 | { return (p ? p->sf : NULL) ; }
381 |
382 | inline SNDFILE *
383 | SndfileHandle::takeOwnership (void)
384 | {
385 | if (p == NULL || (p->ref != 1))
386 | return NULL ;
387 |
388 | SNDFILE * sf = p->sf ;
389 | p->sf = NULL ;
390 | delete p ;
391 | p = NULL ;
392 | return sf ;
393 | }
394 |
395 | #ifdef ENABLE_SNDFILE_WINDOWS_PROTOTYPES
396 |
397 | inline
398 | SndfileHandle::SndfileHandle (LPCWSTR wpath, int mode, int fmt, int chans, int srate)
399 | : p (NULL)
400 | {
401 | p = new (std::nothrow) SNDFILE_ref () ;
402 |
403 | if (p != NULL)
404 | { p->ref = 1 ;
405 |
406 | p->sfinfo.frames = 0 ;
407 | p->sfinfo.channels = chans ;
408 | p->sfinfo.format = fmt ;
409 | p->sfinfo.samplerate = srate ;
410 | p->sfinfo.sections = 0 ;
411 | p->sfinfo.seekable = 0 ;
412 |
413 | p->sf = sf_wchar_open (wpath, mode, &p->sfinfo) ;
414 | } ;
415 |
416 | return ;
417 | } /* SndfileHandle const wchar_t * constructor */
418 |
419 | #endif
420 |
421 | #endif /* SNDFILE_HH */
422 |
423 |
--------------------------------------------------------------------------------
/libs/sndfile/lib/linux/libsndfile.a:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/fx-lange/ofxGSTT/c4354777ca1d7aa2cc396e6026b82fbf36a7e30f/libs/sndfile/lib/linux/libsndfile.a
--------------------------------------------------------------------------------
/libs/stringencoders/modp_b64.c:
--------------------------------------------------------------------------------
1 | /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 | /* vi: set expandtab shiftwidth=4 tabstop=4: */
3 | /**
4 | * \file modp_b64.c
5 | *
6 | * MODP_B64 - High performance base64 encoder/decoder
7 | * http://code.google.com/p/stringencoders/
8 | *
9 | * Copyright © 2005, 2006, 2007 Nick Galbreath -- nickg [at] modp [dot] com
10 | * All rights reserved.
11 | *
12 | * Redistribution and use in source and binary forms, with or without
13 | * modification, are permitted provided that the following conditions are
14 | * met:
15 | *
16 | * Redistributions of source code must retain the above copyright
17 | * notice, this list of conditions and the following disclaimer.
18 | *
19 | * Redistributions in binary form must reproduce the above copyright
20 | * notice, this list of conditions and the following disclaimer in the
21 | * documentation and/or other materials provided with the distribution.
22 | *
23 | * Neither the name of the modp.com nor the names of its
24 | * contributors may be used to endorse or promote products derived from
25 | * this software without specific prior written permission.
26 | *
27 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 | *
39 | * This is the standard "new" BSD license:
40 | * http://www.opensource.org/licenses/bsd-license.php
41 | *
42 | */
43 |
44 | /* public header */
45 | #include "modp_b64.h"
46 |
47 | /*
48 | * If you are ripping this out of the library, comment out the next
49 | * line and uncomment the next lines as approrpiate
50 | */
51 | //#include "config.h"
52 |
53 | /* if on motoral, sun, ibm; uncomment this */
54 | /* #define WORDS_BIGENDIAN 1 */
55 | /* else for Intel, Amd; uncomment this */
56 | /* #undef WORDS_BIGENDIAN */
57 |
58 | #include "modp_b64_data.h"
59 |
60 | #define BADCHAR 0x01FFFFFF
61 |
62 | /**
63 | * you can control if we use padding by commenting out this
64 | * next line. However, I highly recommend you use padding and not
65 | * using it should only be for compatability with a 3rd party.
66 | * Also, 'no padding' is not tested!
67 | */
68 | #define DOPAD 1
69 |
70 | /*
71 | * if we aren't doing padding
72 | * set the pad character to NULL
73 | */
74 | #ifndef DOPAD
75 | #undef CHARPAD
76 | #define CHARPAD '\0'
77 | #endif
78 |
79 | int modp_b64_encode(char* dest, const char* str, int len)
80 | {
81 | int i;
82 | const uint8_t* s = (const uint8_t*) str;
83 | uint8_t* p = (uint8_t*) dest;
84 |
85 | /* unsigned here is important! */
86 | /* uint8_t is fastest on G4, amd */
87 | /* uint32_t is fastest on Intel */
88 | uint32_t t1, t2, t3;
89 |
90 | for (i = 0; i < len - 2; i += 3) {
91 | t1 = s[i]; t2 = s[i+1]; t3 = s[i+2];
92 | *p++ = e0[t1];
93 | *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
94 | *p++ = e1[((t2 & 0x0F) << 2) | ((t3 >> 6) & 0x03)];
95 | *p++ = e2[t3];
96 | }
97 |
98 | switch (len - i) {
99 | case 0:
100 | break;
101 | case 1:
102 | t1 = s[i];
103 | *p++ = e0[t1];
104 | *p++ = e1[(t1 & 0x03) << 4];
105 | *p++ = CHARPAD;
106 | *p++ = CHARPAD;
107 | break;
108 | default: /* case 2 */
109 | t1 = s[i]; t2 = s[i+1];
110 | *p++ = e0[t1];
111 | *p++ = e1[((t1 & 0x03) << 4) | ((t2 >> 4) & 0x0F)];
112 | *p++ = e2[(t2 & 0x0F) << 2];
113 | *p++ = CHARPAD;
114 | }
115 |
116 | *p = '\0';
117 | return (int)(p - (uint8_t*)dest);
118 | }
119 |
120 | #ifdef WORDS_BIGENDIAN /* BIG ENDIAN -- SUN / IBM / MOTOROLA */
121 | int modp_b64_decode(char* dest, const char* src, int len)
122 | {
123 | int i;
124 | if (len == 0) return 0;
125 |
126 | #ifdef DOPAD
127 | /* if padding is used, then the message must be at least
128 | 4 chars and be a multiple of 4.
129 | there can be at most 2 pad chars at the end */
130 | if (len < 4 || (len % 4 != 0)) return -1;
131 | if (src[len-1] == CHARPAD) {
132 | len--;
133 | if (src[len -1] == CHARPAD) {
134 | len--;
135 | }
136 | }
137 | #endif /* DOPAD */
138 |
139 | int leftover = len % 4;
140 | int chunks = (leftover == 0) ? len / 4 - 1 : len /4;
141 |
142 | uint8_t* p = (uint8_t*) dest;
143 | uint32_t x = 0;
144 | uint32_t* destInt = (uint32_t*) p;
145 | uint32_t* srcInt = (uint32_t*) src;
146 | uint32_t y = *srcInt++;
147 | for (i = 0; i < chunks; ++i) {
148 | x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
149 | d2[y >> 8 & 0xff] | d3[y & 0xff];
150 |
151 | if (x >= BADCHAR) return -1;
152 | *destInt = x << 8;
153 | p += 3;
154 | destInt = (uint32_t*)p;
155 | y = *srcInt++;
156 | }
157 |
158 | switch (leftover) {
159 | case 0:
160 | x = d0[y >> 24 & 0xff] | d1[y >> 16 & 0xff] |
161 | d2[y >> 8 & 0xff] | d3[y & 0xff];
162 | if (x >= BADCHAR) return -1;
163 | *p++ = ((uint8_t*)&x)[1];
164 | *p++ = ((uint8_t*)&x)[2];
165 | *p = ((uint8_t*)&x)[3];
166 | return (chunks+1)*3;
167 | #ifndef DOPAD
168 | case 1: /* with padding this is an impossible case */
169 | x = d3[y >> 24];
170 | *p = (uint8_t)x;
171 | break;
172 | #endif
173 | case 2:
174 | x = d3[y >> 24] *64 + d3[(y >> 16) & 0xff];
175 | *p = (uint8_t)(x >> 4);
176 | break;
177 | default: /* case 3 */
178 | x = (d3[y >> 24] *64 + d3[(y >> 16) & 0xff])*64 +
179 | d3[(y >> 8) & 0xff];
180 | *p++ = (uint8_t) (x >> 10);
181 | *p = (uint8_t) (x >> 2);
182 | break;
183 | }
184 |
185 | if (x >= BADCHAR) return -1;
186 | return 3*chunks + (6*leftover)/8;
187 | }
188 |
189 | #else /* LITTLE ENDIAN -- INTEL AND FRIENDS */
190 |
191 | int modp_b64_decode(char* dest, const char* src, int len)
192 | {
193 | int i;
194 | if (len == 0) return 0;
195 |
196 | #ifdef DOPAD
197 | /*
198 | * if padding is used, then the message must be at least
199 | * 4 chars and be a multiple of 4
200 | */
201 | if (len < 4 || (len % 4 != 0)) return -1; /* error */
202 | /* there can be at most 2 pad chars at the end */
203 | if (src[len-1] == CHARPAD) {
204 | len--;
205 | if (src[len -1] == CHARPAD) {
206 | len--;
207 | }
208 | }
209 | #endif
210 |
211 | int leftover = len % 4;
212 | int chunks = (leftover == 0) ? len / 4 - 1 : len /4;
213 |
214 | uint8_t* p = (uint8_t*) dest;
215 | uint32_t x = 0;
216 | uint32_t* destInt = (uint32_t*) p;
217 | uint32_t* srcInt = (uint32_t*) src;
218 | uint32_t y = *srcInt++;
219 | for (i = 0; i < chunks; ++i) {
220 | x = d0[y & 0xff] |
221 | d1[(y >> 8) & 0xff] |
222 | d2[(y >> 16) & 0xff] |
223 | d3[(y >> 24) & 0xff];
224 |
225 | if (x >= BADCHAR) return -1;
226 | *destInt = x ;
227 | p += 3;
228 | destInt = (uint32_t*)p;
229 | y = *srcInt++;}
230 |
231 |
232 | switch (leftover) {
233 | case 0:
234 | x = d0[y & 0xff] |
235 | d1[(y >> 8) & 0xff] |
236 | d2[(y >> 16) & 0xff] |
237 | d3[(y >> 24) & 0xff];
238 |
239 | if (x >= BADCHAR) return -1;
240 | *p++ = ((uint8_t*)(&x))[0];
241 | *p++ = ((uint8_t*)(&x))[1];
242 | *p = ((uint8_t*)(&x))[2];
243 | return (chunks+1)*3;
244 | break;
245 | #ifndef DOPAD
246 | case 1: /* with padding this is an impossible case */
247 | x = d0[y & 0xff];
248 | *p = *((uint8_t*)(&x)); // i.e. first char/byte in int
249 | break;
250 | #endif
251 | case 2: // * case 2, 1 output byte */
252 | x = d0[y & 0xff] | d1[y >> 8 & 0xff];
253 | *p = *((uint8_t*)(&x)); // i.e. first char
254 | break;
255 | default: /* case 3, 2 output bytes */
256 | x = d0[y & 0xff] |
257 | d1[y >> 8 & 0xff ] |
258 | d2[y >> 16 & 0xff]; /* 0x3c */
259 | *p++ = ((uint8_t*)(&x))[0];
260 | *p = ((uint8_t*)(&x))[1];
261 | break;
262 | }
263 |
264 | if (x >= BADCHAR) return -1;
265 |
266 | return 3*chunks + (6*leftover)/8;
267 | }
268 |
269 | #endif /* if bigendian / else / endif */
270 |
--------------------------------------------------------------------------------
/libs/stringencoders/modp_b64.h:
--------------------------------------------------------------------------------
1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 4 -*- */
2 | /* vi: set expandtab shiftwidth=4 tabstop=4: */
3 |
4 | /**
5 | * \file
6 | *
7 | * High performance base64 encoder / decoder
8 | *
9 | * Copyright © 2005, 2006, 2007 Nick Galbreath -- nickg [at] modp [dot] com
10 | * All rights reserved.
11 | *
12 | * http://code.google.com/p/stringencoders/
13 | *
14 | * Released under bsd license. See modp_b64.c for details.
15 | *
16 | *
17 | * This uses the standard base 64 alphabet. If you are planning
18 | * to embed a base 64 encoding inside a URL use modp_b64w instead.
19 | *
20 | */
21 |
22 | #ifndef COM_MODP_STRINGENCODERS_B64
23 | #define COM_MODP_STRINGENCODERS_B64
24 |
25 | #ifdef __cplusplus
26 | #define BEGIN_C extern "C" {
27 | #define END_C }
28 | #else
29 | #define BEGIN_C
30 | #define END_C
31 | #endif
32 |
33 | BEGIN_C
34 |
35 | /**
36 | * Encode a raw binary string into base 64.
37 | * \param[out] dest should be allocated by the caller to contain
38 | * at least modp_b64_encode_len(len) bytes (see below)
39 | * This will contain the null-terminated b64 encoded result
40 | * \param[in] src contains the bytes
41 | * \param[in] len contains the number of bytes in the src
42 | * \return length of the destination string plus the ending null byte
43 | * i.e. the result will be equal to strlen(dest) + 1
44 | *
45 | * Example
46 | *
47 | * \code
48 | * char* src = ...;
49 | * int srclen = ...; //the length of number of bytes in src
50 | * char* dest = (char*) malloc(modp_b64_encode_len);
51 | * int len = modp_b64_encode(dest, src, sourcelen);
52 | * if (len == -1) {
53 | * printf("Error\n");
54 | * } else {
55 | * printf("b64 = %s\n", dest);
56 | * }
57 | * \endcode
58 | *
59 | */
60 | int modp_b64_encode(char* dest, const char* str, int len);
61 |
62 | /**
63 | * Decode a base64 encoded string
64 | *
65 | * \param[out] dest should be allocated by the caller to contain at least
66 | * len * 3 / 4 bytes. The destination cannot be the same as the source
67 | * They must be different buffers.
68 | * \param[in] src should contain exactly len bytes of b64 characters.
69 | * if src contains -any- non-base characters (such as white
70 | * space, -1 is returned.
71 | * \param[in] len is the length of src
72 | *
73 | * \return the length (strlen) of the output, or -1 if unable to
74 | * decode
75 | *
76 | * \code
77 | * char* src = ...;
78 | * int srclen = ...; // or if you don't know use strlen(src)
79 | * char* dest = (char*) malloc(modp_b64_decode_len(srclen));
80 | * int len = modp_b64_decode(dest, src, sourcelen);
81 | * if (len == -1) { error }
82 | * \endcode
83 | */
84 | int modp_b64_decode(char* dest, const char* src, int len);
85 |
86 | /**
87 | * Given a source string of length len, this returns the amount of
88 | * memory the destination string should have.
89 | *
90 | * remember, this is integer math
91 | * 3 bytes turn into 4 chars
92 | * ceiling[len / 3] * 4 + 1
93 | *
94 | * +1 is for any extra null.
95 | */
96 | #define modp_b64_encode_len(A) ((A+2)/3 * 4 + 1)
97 |
98 | /**
99 | * Given a base64 string of length len,
100 | * this returns the amount of memory required for output string
101 | * It maybe be more than the actual number of bytes written.
102 | * NOTE: remember this is integer math
103 | * this allocates a bit more memory than traditional versions of b64
104 | * decode 4 chars turn into 3 bytes
105 | * floor[len * 3/4] + 2
106 | */
107 | #define modp_b64_decode_len(A) (A / 4 * 3 + 2)
108 |
109 | /**
110 | * Will return the strlen of the output from encoding.
111 | * This may be less than the required number of bytes allocated.
112 | *
113 | * This allows you to 'deserialized' a struct
114 | * \code
115 | * char* b64encoded = "...";
116 | * int len = strlen(b64encoded);
117 | *
118 | * struct datastuff foo;
119 | * if (modp_b64_encode_strlen(sizeof(struct datastuff)) != len) {
120 | * // wrong size
121 | * return false;
122 | * } else {
123 | * // safe to do;
124 | * if (modp_b64_decode((char*) &foo, b64encoded, len) == -1) {
125 | * // bad characters
126 | * return false;
127 | * }
128 | * }
129 | * // foo is filled out now
130 | * \endcode
131 | */
132 | #define modp_b64_encode_strlen(A) ((A + 2)/ 3 * 4)
133 |
134 | END_C
135 |
136 | #ifdef __cplusplus
137 | #include
138 | #include
139 |
140 | namespace modp {
141 | /** \brief b64 encode a cstr with len
142 | *
143 | * \param[in] s the input string to encode
144 | * \param[in] len the length of the input string
145 | * \return a newly allocated b64 string. Empty if failed.
146 | */
147 | inline std::string b64_encode(const char* s, size_t len)
148 | {
149 | std::string x(modp_b64_encode_len(len), '\0');
150 | int d = modp_b64_encode(const_cast(x.data()), s,
151 | static_cast(len));
152 | x.erase(d, std::string::npos);
153 | return x;
154 | }
155 |
156 | /** \brief b64 encode a cstr
157 | *
158 | * \param[in] s the input string to encode
159 | * \return a newly allocated b64 string. Empty if failed.
160 | */
161 | inline std::string b64_encode(const char* s)
162 | {
163 | return b64_encode(s, static_cast(strlen(s)));
164 | }
165 |
166 | /** \brief b64 encode a const std::string
167 | *
168 | * \param[in] s the input string to encode
169 | * \return a newly allocated b64 string. Empty if failed.
170 | */
171 | inline std::string b64_encode(const std::string& s)
172 | {
173 | return b64_encode(s.data(), s.size());
174 | }
175 |
176 | /**
177 | * base 64 encode a string (self-modifing)
178 | *
179 | * This function is for C++ only (duh)
180 | *
181 | * \param[in,out] s the string to be decoded
182 | * \return a reference to the input string
183 | */
184 | inline std::string& b64_encode(std::string& s)
185 | {
186 | std::string x(b64_encode(s.data(), s.size()));
187 | s.swap(x);
188 | return s;
189 | }
190 |
191 | inline std::string b64_decode(const char* src, size_t len)
192 | {
193 | std::string x(modp_b64_decode_len(len)+1, '\0');
194 | int d = modp_b64_decode(const_cast(x.data()), src,
195 | static_cast(len));
196 | if (d < 0) {
197 | x.clear();
198 | } else {
199 | x.erase(d, std::string::npos);
200 | }
201 | return x;
202 | }
203 |
204 | inline std::string b64_decode(const char* src)
205 | {
206 | return b64_decode(src, strlen(src));
207 | }
208 |
209 | /**
210 | * base 64 decode a string (self-modifing)
211 | * On failure, the string is empty.
212 | *
213 | * This function is for C++ only (duh)
214 | *
215 | * \param[in,out] s the string to be decoded
216 | * \return a reference to the input string
217 | */
218 | inline std::string& b64_decode(std::string& s)
219 | {
220 | std::string x(b64_decode(s.data(), s.size()));
221 | s.swap(x);
222 | return s;
223 | }
224 |
225 | inline std::string b64_decode(const std::string& s)
226 | {
227 | return b64_decode(s.data(), s.size());
228 | }
229 |
230 | }
231 |
232 | #endif /* __cplusplus */
233 |
234 | #endif /* MODP_B64 */
235 |
--------------------------------------------------------------------------------
/libs/stringencoders/modp_b64_data.h:
--------------------------------------------------------------------------------
1 | #include
2 | #define CHAR62 '+'
3 | #define CHAR63 '/'
4 | #define CHARPAD '='
5 | static const unsigned char e0[256] = {
6 | 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'C', 'C',
7 | 'C', 'C', 'D', 'D', 'D', 'D', 'E', 'E', 'E', 'E',
8 | 'F', 'F', 'F', 'F', 'G', 'G', 'G', 'G', 'H', 'H',
9 | 'H', 'H', 'I', 'I', 'I', 'I', 'J', 'J', 'J', 'J',
10 | 'K', 'K', 'K', 'K', 'L', 'L', 'L', 'L', 'M', 'M',
11 | 'M', 'M', 'N', 'N', 'N', 'N', 'O', 'O', 'O', 'O',
12 | 'P', 'P', 'P', 'P', 'Q', 'Q', 'Q', 'Q', 'R', 'R',
13 | 'R', 'R', 'S', 'S', 'S', 'S', 'T', 'T', 'T', 'T',
14 | 'U', 'U', 'U', 'U', 'V', 'V', 'V', 'V', 'W', 'W',
15 | 'W', 'W', 'X', 'X', 'X', 'X', 'Y', 'Y', 'Y', 'Y',
16 | 'Z', 'Z', 'Z', 'Z', 'a', 'a', 'a', 'a', 'b', 'b',
17 | 'b', 'b', 'c', 'c', 'c', 'c', 'd', 'd', 'd', 'd',
18 | 'e', 'e', 'e', 'e', 'f', 'f', 'f', 'f', 'g', 'g',
19 | 'g', 'g', 'h', 'h', 'h', 'h', 'i', 'i', 'i', 'i',
20 | 'j', 'j', 'j', 'j', 'k', 'k', 'k', 'k', 'l', 'l',
21 | 'l', 'l', 'm', 'm', 'm', 'm', 'n', 'n', 'n', 'n',
22 | 'o', 'o', 'o', 'o', 'p', 'p', 'p', 'p', 'q', 'q',
23 | 'q', 'q', 'r', 'r', 'r', 'r', 's', 's', 's', 's',
24 | 't', 't', 't', 't', 'u', 'u', 'u', 'u', 'v', 'v',
25 | 'v', 'v', 'w', 'w', 'w', 'w', 'x', 'x', 'x', 'x',
26 | 'y', 'y', 'y', 'y', 'z', 'z', 'z', 'z', '0', '0',
27 | '0', '0', '1', '1', '1', '1', '2', '2', '2', '2',
28 | '3', '3', '3', '3', '4', '4', '4', '4', '5', '5',
29 | '5', '5', '6', '6', '6', '6', '7', '7', '7', '7',
30 | '8', '8', '8', '8', '9', '9', '9', '9', '+', '+',
31 | '+', '+', '/', '/', '/', '/'
32 | };
33 |
34 | static const unsigned char e1[256] = {
35 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
36 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
37 | 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
38 | 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
39 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
40 | 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
41 | '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F',
42 | 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
43 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
44 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
45 | 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
46 | 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
47 | '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B',
48 | 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
49 | 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
50 | 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
51 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
52 | 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
53 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
54 | '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
55 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
56 | 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
57 | 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
58 | 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
59 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
60 | '6', '7', '8', '9', '+', '/'
61 | };
62 |
63 | static const unsigned char e2[256] = {
64 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
65 | 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
66 | 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
67 | 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
68 | 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
69 | 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
70 | '8', '9', '+', '/', 'A', 'B', 'C', 'D', 'E', 'F',
71 | 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
72 | 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
73 | 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
74 | 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
75 | 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3',
76 | '4', '5', '6', '7', '8', '9', '+', '/', 'A', 'B',
77 | 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
78 | 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
79 | 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
80 | 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
81 | 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
82 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
83 | '+', '/', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
84 | 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
85 | 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
86 | 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
87 | 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
88 | 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5',
89 | '6', '7', '8', '9', '+', '/'
90 | };
91 |
92 |
93 |
94 | #ifdef WORDS_BIGENDIAN
95 |
96 |
97 | /* SPECIAL DECODE TABLES FOR BIG ENDIAN (IBM/MOTOROLA/SUN) CPUS */
98 |
99 | static const uint32_t d0[256] = {
100 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
101 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
102 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
103 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
104 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
105 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
106 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
107 | 0x01ffffff, 0x00f80000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00fc0000,
108 | 0x00d00000, 0x00d40000, 0x00d80000, 0x00dc0000, 0x00e00000, 0x00e40000,
109 | 0x00e80000, 0x00ec0000, 0x00f00000, 0x00f40000, 0x01ffffff, 0x01ffffff,
110 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
111 | 0x00040000, 0x00080000, 0x000c0000, 0x00100000, 0x00140000, 0x00180000,
112 | 0x001c0000, 0x00200000, 0x00240000, 0x00280000, 0x002c0000, 0x00300000,
113 | 0x00340000, 0x00380000, 0x003c0000, 0x00400000, 0x00440000, 0x00480000,
114 | 0x004c0000, 0x00500000, 0x00540000, 0x00580000, 0x005c0000, 0x00600000,
115 | 0x00640000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
116 | 0x01ffffff, 0x00680000, 0x006c0000, 0x00700000, 0x00740000, 0x00780000,
117 | 0x007c0000, 0x00800000, 0x00840000, 0x00880000, 0x008c0000, 0x00900000,
118 | 0x00940000, 0x00980000, 0x009c0000, 0x00a00000, 0x00a40000, 0x00a80000,
119 | 0x00ac0000, 0x00b00000, 0x00b40000, 0x00b80000, 0x00bc0000, 0x00c00000,
120 | 0x00c40000, 0x00c80000, 0x00cc0000, 0x01ffffff, 0x01ffffff, 0x01ffffff,
121 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
122 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
123 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
124 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
125 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
126 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
127 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
128 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
129 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
130 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
131 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
132 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
133 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
134 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
135 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
136 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
137 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
138 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
139 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
140 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
141 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
142 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
143 | };
144 |
145 |
146 | static const uint32_t d1[256] = {
147 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
148 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
149 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
150 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
151 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
152 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
153 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
154 | 0x01ffffff, 0x0003e000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0003f000,
155 | 0x00034000, 0x00035000, 0x00036000, 0x00037000, 0x00038000, 0x00039000,
156 | 0x0003a000, 0x0003b000, 0x0003c000, 0x0003d000, 0x01ffffff, 0x01ffffff,
157 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
158 | 0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000,
159 | 0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000,
160 | 0x0000d000, 0x0000e000, 0x0000f000, 0x00010000, 0x00011000, 0x00012000,
161 | 0x00013000, 0x00014000, 0x00015000, 0x00016000, 0x00017000, 0x00018000,
162 | 0x00019000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
163 | 0x01ffffff, 0x0001a000, 0x0001b000, 0x0001c000, 0x0001d000, 0x0001e000,
164 | 0x0001f000, 0x00020000, 0x00021000, 0x00022000, 0x00023000, 0x00024000,
165 | 0x00025000, 0x00026000, 0x00027000, 0x00028000, 0x00029000, 0x0002a000,
166 | 0x0002b000, 0x0002c000, 0x0002d000, 0x0002e000, 0x0002f000, 0x00030000,
167 | 0x00031000, 0x00032000, 0x00033000, 0x01ffffff, 0x01ffffff, 0x01ffffff,
168 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
169 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
170 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
171 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
172 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
173 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
174 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
175 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
176 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
177 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
178 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
179 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
180 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
181 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
182 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
183 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
184 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
185 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
186 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
187 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
188 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
189 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
190 | };
191 |
192 |
193 | static const uint32_t d2[256] = {
194 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
195 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
196 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
197 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
198 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
199 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
200 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
201 | 0x01ffffff, 0x00000f80, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000fc0,
202 | 0x00000d00, 0x00000d40, 0x00000d80, 0x00000dc0, 0x00000e00, 0x00000e40,
203 | 0x00000e80, 0x00000ec0, 0x00000f00, 0x00000f40, 0x01ffffff, 0x01ffffff,
204 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
205 | 0x00000040, 0x00000080, 0x000000c0, 0x00000100, 0x00000140, 0x00000180,
206 | 0x000001c0, 0x00000200, 0x00000240, 0x00000280, 0x000002c0, 0x00000300,
207 | 0x00000340, 0x00000380, 0x000003c0, 0x00000400, 0x00000440, 0x00000480,
208 | 0x000004c0, 0x00000500, 0x00000540, 0x00000580, 0x000005c0, 0x00000600,
209 | 0x00000640, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
210 | 0x01ffffff, 0x00000680, 0x000006c0, 0x00000700, 0x00000740, 0x00000780,
211 | 0x000007c0, 0x00000800, 0x00000840, 0x00000880, 0x000008c0, 0x00000900,
212 | 0x00000940, 0x00000980, 0x000009c0, 0x00000a00, 0x00000a40, 0x00000a80,
213 | 0x00000ac0, 0x00000b00, 0x00000b40, 0x00000b80, 0x00000bc0, 0x00000c00,
214 | 0x00000c40, 0x00000c80, 0x00000cc0, 0x01ffffff, 0x01ffffff, 0x01ffffff,
215 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
216 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
217 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
218 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
219 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
220 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
221 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
222 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
223 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
224 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
225 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
226 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
227 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
228 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
229 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
230 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
231 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
232 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
233 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
234 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
235 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
236 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
237 | };
238 |
239 |
240 | static const uint32_t d3[256] = {
241 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
242 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
243 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
244 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
245 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
246 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
247 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
248 | 0x01ffffff, 0x0000003e, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000003f,
249 | 0x00000034, 0x00000035, 0x00000036, 0x00000037, 0x00000038, 0x00000039,
250 | 0x0000003a, 0x0000003b, 0x0000003c, 0x0000003d, 0x01ffffff, 0x01ffffff,
251 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
252 | 0x00000001, 0x00000002, 0x00000003, 0x00000004, 0x00000005, 0x00000006,
253 | 0x00000007, 0x00000008, 0x00000009, 0x0000000a, 0x0000000b, 0x0000000c,
254 | 0x0000000d, 0x0000000e, 0x0000000f, 0x00000010, 0x00000011, 0x00000012,
255 | 0x00000013, 0x00000014, 0x00000015, 0x00000016, 0x00000017, 0x00000018,
256 | 0x00000019, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
257 | 0x01ffffff, 0x0000001a, 0x0000001b, 0x0000001c, 0x0000001d, 0x0000001e,
258 | 0x0000001f, 0x00000020, 0x00000021, 0x00000022, 0x00000023, 0x00000024,
259 | 0x00000025, 0x00000026, 0x00000027, 0x00000028, 0x00000029, 0x0000002a,
260 | 0x0000002b, 0x0000002c, 0x0000002d, 0x0000002e, 0x0000002f, 0x00000030,
261 | 0x00000031, 0x00000032, 0x00000033, 0x01ffffff, 0x01ffffff, 0x01ffffff,
262 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
263 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
264 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
265 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
266 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
267 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
268 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
269 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
270 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
271 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
272 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
273 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
274 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
275 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
276 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
277 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
278 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
279 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
280 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
281 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
282 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
283 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
284 | };
285 |
286 |
287 | #else
288 |
289 |
290 | /* SPECIAL DECODE TABLES FOR LITTLE ENDIAN (INTEL) CPUS */
291 |
292 | static const uint32_t d0[256] = {
293 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
294 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
295 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
296 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
297 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
298 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
299 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
300 | 0x01ffffff, 0x000000f8, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x000000fc,
301 | 0x000000d0, 0x000000d4, 0x000000d8, 0x000000dc, 0x000000e0, 0x000000e4,
302 | 0x000000e8, 0x000000ec, 0x000000f0, 0x000000f4, 0x01ffffff, 0x01ffffff,
303 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
304 | 0x00000004, 0x00000008, 0x0000000c, 0x00000010, 0x00000014, 0x00000018,
305 | 0x0000001c, 0x00000020, 0x00000024, 0x00000028, 0x0000002c, 0x00000030,
306 | 0x00000034, 0x00000038, 0x0000003c, 0x00000040, 0x00000044, 0x00000048,
307 | 0x0000004c, 0x00000050, 0x00000054, 0x00000058, 0x0000005c, 0x00000060,
308 | 0x00000064, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
309 | 0x01ffffff, 0x00000068, 0x0000006c, 0x00000070, 0x00000074, 0x00000078,
310 | 0x0000007c, 0x00000080, 0x00000084, 0x00000088, 0x0000008c, 0x00000090,
311 | 0x00000094, 0x00000098, 0x0000009c, 0x000000a0, 0x000000a4, 0x000000a8,
312 | 0x000000ac, 0x000000b0, 0x000000b4, 0x000000b8, 0x000000bc, 0x000000c0,
313 | 0x000000c4, 0x000000c8, 0x000000cc, 0x01ffffff, 0x01ffffff, 0x01ffffff,
314 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
315 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
316 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
317 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
318 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
319 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
320 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
321 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
322 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
323 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
324 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
325 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
326 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
327 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
328 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
329 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
330 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
331 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
332 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
333 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
334 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
335 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
336 | };
337 |
338 |
339 | static const uint32_t d1[256] = {
340 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
341 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
342 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
343 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
344 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
345 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
346 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
347 | 0x01ffffff, 0x0000e003, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x0000f003,
348 | 0x00004003, 0x00005003, 0x00006003, 0x00007003, 0x00008003, 0x00009003,
349 | 0x0000a003, 0x0000b003, 0x0000c003, 0x0000d003, 0x01ffffff, 0x01ffffff,
350 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
351 | 0x00001000, 0x00002000, 0x00003000, 0x00004000, 0x00005000, 0x00006000,
352 | 0x00007000, 0x00008000, 0x00009000, 0x0000a000, 0x0000b000, 0x0000c000,
353 | 0x0000d000, 0x0000e000, 0x0000f000, 0x00000001, 0x00001001, 0x00002001,
354 | 0x00003001, 0x00004001, 0x00005001, 0x00006001, 0x00007001, 0x00008001,
355 | 0x00009001, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
356 | 0x01ffffff, 0x0000a001, 0x0000b001, 0x0000c001, 0x0000d001, 0x0000e001,
357 | 0x0000f001, 0x00000002, 0x00001002, 0x00002002, 0x00003002, 0x00004002,
358 | 0x00005002, 0x00006002, 0x00007002, 0x00008002, 0x00009002, 0x0000a002,
359 | 0x0000b002, 0x0000c002, 0x0000d002, 0x0000e002, 0x0000f002, 0x00000003,
360 | 0x00001003, 0x00002003, 0x00003003, 0x01ffffff, 0x01ffffff, 0x01ffffff,
361 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
362 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
363 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
364 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
365 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
366 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
367 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
368 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
369 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
370 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
371 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
372 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
373 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
374 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
375 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
376 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
377 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
378 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
379 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
380 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
381 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
382 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
383 | };
384 |
385 |
386 | static const uint32_t d2[256] = {
387 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
388 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
389 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
390 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
391 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
392 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
393 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
394 | 0x01ffffff, 0x00800f00, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00c00f00,
395 | 0x00000d00, 0x00400d00, 0x00800d00, 0x00c00d00, 0x00000e00, 0x00400e00,
396 | 0x00800e00, 0x00c00e00, 0x00000f00, 0x00400f00, 0x01ffffff, 0x01ffffff,
397 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
398 | 0x00400000, 0x00800000, 0x00c00000, 0x00000100, 0x00400100, 0x00800100,
399 | 0x00c00100, 0x00000200, 0x00400200, 0x00800200, 0x00c00200, 0x00000300,
400 | 0x00400300, 0x00800300, 0x00c00300, 0x00000400, 0x00400400, 0x00800400,
401 | 0x00c00400, 0x00000500, 0x00400500, 0x00800500, 0x00c00500, 0x00000600,
402 | 0x00400600, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
403 | 0x01ffffff, 0x00800600, 0x00c00600, 0x00000700, 0x00400700, 0x00800700,
404 | 0x00c00700, 0x00000800, 0x00400800, 0x00800800, 0x00c00800, 0x00000900,
405 | 0x00400900, 0x00800900, 0x00c00900, 0x00000a00, 0x00400a00, 0x00800a00,
406 | 0x00c00a00, 0x00000b00, 0x00400b00, 0x00800b00, 0x00c00b00, 0x00000c00,
407 | 0x00400c00, 0x00800c00, 0x00c00c00, 0x01ffffff, 0x01ffffff, 0x01ffffff,
408 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
409 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
410 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
411 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
412 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
413 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
414 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
415 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
416 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
417 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
418 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
419 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
420 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
421 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
422 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
423 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
424 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
425 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
426 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
427 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
428 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
429 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
430 | };
431 |
432 |
433 | static const uint32_t d3[256] = {
434 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
435 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
436 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
437 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
438 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
439 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
440 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
441 | 0x01ffffff, 0x003e0000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x003f0000,
442 | 0x00340000, 0x00350000, 0x00360000, 0x00370000, 0x00380000, 0x00390000,
443 | 0x003a0000, 0x003b0000, 0x003c0000, 0x003d0000, 0x01ffffff, 0x01ffffff,
444 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x00000000,
445 | 0x00010000, 0x00020000, 0x00030000, 0x00040000, 0x00050000, 0x00060000,
446 | 0x00070000, 0x00080000, 0x00090000, 0x000a0000, 0x000b0000, 0x000c0000,
447 | 0x000d0000, 0x000e0000, 0x000f0000, 0x00100000, 0x00110000, 0x00120000,
448 | 0x00130000, 0x00140000, 0x00150000, 0x00160000, 0x00170000, 0x00180000,
449 | 0x00190000, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
450 | 0x01ffffff, 0x001a0000, 0x001b0000, 0x001c0000, 0x001d0000, 0x001e0000,
451 | 0x001f0000, 0x00200000, 0x00210000, 0x00220000, 0x00230000, 0x00240000,
452 | 0x00250000, 0x00260000, 0x00270000, 0x00280000, 0x00290000, 0x002a0000,
453 | 0x002b0000, 0x002c0000, 0x002d0000, 0x002e0000, 0x002f0000, 0x00300000,
454 | 0x00310000, 0x00320000, 0x00330000, 0x01ffffff, 0x01ffffff, 0x01ffffff,
455 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
456 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
457 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
458 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
459 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
460 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
461 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
462 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
463 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
464 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
465 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
466 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
467 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
468 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
469 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
470 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
471 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
472 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
473 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
474 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
475 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff,
476 | 0x01ffffff, 0x01ffffff, 0x01ffffff, 0x01ffffff
477 | };
478 |
479 |
480 | #endif
481 |
--------------------------------------------------------------------------------
/src/googleResponseParser.h:
--------------------------------------------------------------------------------
1 | /***
2 | * Class to decode Googles response via jansson
3 | * REVISIT naming: parser is also parsed object
4 | */
5 |
6 | #pragma once
7 |
8 | #include "ofMain.h"
9 | #include "ofxJSONElement.h"
10 |
11 | class googleResponseParser{
12 | public:
13 |
14 | string utterance;
15 | int status;
16 | float confidence;
17 |
18 | ofxJSONElement root;
19 |
20 | bool parseJSON(const string & jsonLine){
21 |
22 | bool parsingSuccessful = root.parse(jsonLine);
23 | if (!parsingSuccessful) {
24 | ofLogError( "Failed to parse JSON:" + jsonLine);
25 | return false;
26 | }
27 |
28 | if(root.isMember("errors")) {
29 | cout << "error " + root.getRawString();
30 | } else if(root.isObject()) {
31 | // status = root["status"].asInt();
32 |
33 | // if(status == 0){
34 | // result["result"][0]["alternative"][0]["transcript"];
35 | ofxJSONElement alternative = root["result"][0]["alternative"];
36 | if(alternative.size() > 0){
37 | utterance = alternative[0]["transcript"].asString();
38 | confidence = alternative[0]["confidence"].asFloat();
39 | }else{
40 | confidence = 0;
41 | utterance = "";
42 | }
43 | return true;
44 | // }
45 | }
46 |
47 | ofLogVerbose("no valid response: ") << root.getRawString() << endl;
48 | return false;
49 | }
50 | };
51 |
--------------------------------------------------------------------------------
/src/ofxGSTT.cpp:
--------------------------------------------------------------------------------
1 | #include "ofxGSTT.h"
2 |
3 | ofxGSTT::ofxGSTT(){
4 | bAutoListen = bListen = false;
5 | transcriberId = 0;
6 | sampleRate = -1;
7 | volumeThreshold = 0.05;
8 | }
9 |
10 | void ofxGSTT::setup(int sampleRate, int nChannels, string language, string key){
11 | /*** SOUND RECORDING ***/
12 | info.format = SF_FORMAT_WAV | SF_FORMAT_PCM_16;
13 | info.frames = sampleRate * 60; //TODO revisit -> why *60? because of 60fps?
14 | info.samplerate = sampleRate;
15 | info.channels = nChannels;
16 |
17 | this->language = language;
18 | this->key = key;
19 |
20 | ofDirectory dir;
21 | if(!dir.doesDirectoryExist("tmpAudio")){
22 | dir.createDirectory("tmpAudio");
23 | }
24 |
25 | //add and setup default device
26 | addDevice(OFXGSTT_DEFAULTDEVICE_ID); //TODO multi device business
27 | }
28 |
29 | void ofxGSTT::setAutoRecording(bool listen){
30 | ofLogVerbose("set auto recording") << listen;
31 | bAutoListen = listen;
32 | if(bAutoListen)
33 | bListen = false;
34 | }
35 |
36 | bool ofxGSTT::isAutoRecording(){
37 | return bAutoListen;
38 | }
39 |
40 | void ofxGSTT::startRecording(){
41 | ofLogVerbose("start recording") << listen;
42 | bListen = true;
43 | bAutoListen = false;
44 | }
45 |
46 | void ofxGSTT::stopRecording(){
47 | ofLogVerbose("stop recording") << listen;
48 | bListen = false;
49 | bAutoListen = false;
50 | }
51 |
52 | void ofxGSTT::setVolumeThreshold(float volumeThreshold){
53 | this->volumeThreshold = ofClamp(volumeThreshold,0,1);
54 | }
55 |
56 | float ofxGSTT::getVolumeThreshold(){
57 | return volumeThreshold;
58 | }
59 |
60 | void ofxGSTT::addDevice(int deviceId){
61 | deviceIds.push_back(deviceId);
62 | outfiles.push_back(NULL);
63 | smoothedVolume.push_back(0.f);
64 | tLastUpdate.push_back(0);
65 | bRecording.push_back(false);
66 | bRecordingBlocked.push_back(false);
67 | deviceTanscriber.push_back(NULL);
68 |
69 | ofDirectory dir;
70 | if(!dir.doesDirectoryExist("tmpAudio/device"+ofToString(deviceId)+"/")){
71 | dir.createDirectory("tmpAudio/device"+ofToString(deviceId));
72 | }
73 |
74 | prepareRecording(deviceIds.size()-1);
75 | }
76 |
77 | bool ofxGSTT::isRecording(int deviceId){
78 | for(int i=0;i<(int)deviceIds.size();++i){
79 | if(deviceIds[i]==deviceId){
80 | return bRecording[i];
81 | }
82 | }
83 | ofLog(OF_LOG_WARNING,"no deviceId %d fount",deviceId);
84 | return false;
85 | }
86 |
87 | void ofxGSTT::audioIn(ofSoundBuffer & buffer){
88 | //TODO make better use of soundbuffer obj
89 | audioIn(&buffer[0], buffer.getNumFrames(), buffer.getNumChannels(), OFXGSTT_DEFAULTDEVICE_ID); //TODO multidevice business
90 | }
91 |
92 | void ofxGSTT::audioIn(float * buffer,int bufferSize, int nChannels, int deviceId){
93 | int deviceIdx=0;
94 | for(int i=0;i<(int)deviceIds.size();++i){
95 | if(deviceIds[i]==deviceId){
96 | deviceIdx=i;
97 | break;
98 | }
99 | }
100 |
101 | if(bRecordingBlocked[deviceIdx]){
102 | return;
103 | }
104 |
105 | float curVol = 0.0;
106 |
107 | // samples are "interleaved"
108 | int numCounted = 0;
109 |
110 | //lets go through each sample and calculate the root mean square which is a rough way to calculate volume
111 | vector left;
112 | vector right;
113 | left.assign(bufferSize, 0.0);
114 | right.assign(bufferSize, 0.0);
115 | for(int i = 0; i < bufferSize; i++){
116 | if(nChannels == 1){
117 | curVol += buffer[i] * buffer[i];
118 | numCounted += 1;
119 | }else if(nChannels == 2){
120 | left[i] = buffer[i * 2];
121 | right[i] = buffer[i * 2 + 1];
122 |
123 | curVol += left[i] * left[i];
124 | curVol += right[i] * right[i];
125 | numCounted += 2;
126 | }
127 | }
128 |
129 | //this is how we get the mean of rms :)
130 | curVol /= (float) numCounted;
131 |
132 | // this is how we get the root of rms :)
133 | curVol = sqrt(curVol);
134 |
135 | smoothedVolume[deviceIdx] *= 0.9; //TODO settings for this ratio needed
136 | smoothedVolume[deviceIdx] += 0.1 * curVol;
137 |
138 | //lets scale the vol up to a 0-1 range
139 | //float scaledVol = ofMap(smoothedVol, 0.0, 0.17, 0.0, 1.0, true);//TODO set by settings!
140 | // float scaledCurVolume = ofMap(curVol, 0.0, 0.17, 0.0, 1.0, true);
141 |
142 | bool bActiveVolume = curVol > volumeThreshold;
143 |
144 | //TODO revisit: should be in an extra update function?!
145 | unsigned long long tNow = ofGetElapsedTimeMillis();
146 | if(bListen || (bActiveVolume && bAutoListen)){
147 | tLastUpdate[deviceIdx] = tNow;
148 | bRecording[deviceIdx] = true;
149 | }
150 | if(bRecording[deviceIdx]){
151 | if(tNow - tLastUpdate[deviceIdx] > 500){ //TODO magic number, hard coded
152 | bRecording[deviceIdx] = false;
153 | finishRecording(deviceIdx);
154 | prepareRecording(deviceIdx);
155 | }else{
156 | sf_write_float(outfiles[deviceIdx], buffer, bufferSize * nChannels);
157 | }
158 | }
159 | }
160 |
161 | void ofxGSTT::prepareRecording(int deviceIdx){
162 | ofLog(OF_LOG_VERBOSE, "prepare recording (device%d)",deviceIds[deviceIdx]);
163 | ofxGSTTTranscriptionThread * nextTranscriber = NULL;
164 | transcriberId = 0;
165 | for(int i = 0; i < (int)transcriber.size(); ++i){
166 | ofxGSTTTranscriptionThread * tmpTranscriber = transcriber[i];
167 | if(tmpTranscriber->isFree()){
168 | ofLog(OF_LOG_VERBOSE, "free transcriber found");
169 | transcriberId = i;
170 | nextTranscriber = tmpTranscriber;
171 | break;
172 | }
173 | }
174 |
175 | //create new one if nothing is free
176 | if(nextTranscriber == NULL){
177 | ofLog(OF_LOG_VERBOSE, "no transcriber free -> create new one");
178 | transcriberId = transcriber.size();
179 | nextTranscriber = new ofxGSTTTranscriptionThread(transcriberId);
180 | transcriber.push_back(nextTranscriber);
181 | }
182 |
183 | string dataPath = ofToDataPath("tmpAudio");
184 | char filename[128];
185 | sprintf(filename, "%s/device%d/%d",dataPath.c_str(),deviceIds[deviceIdx],transcriberId);
186 | nextTranscriber->setup(deviceIds[deviceIdx],language,key);
187 | nextTranscriber->setFilename(filename);
188 | nextTranscriber->reserve();
189 | deviceTanscriber[deviceIdx] = nextTranscriber;
190 | sprintf(filename, "%s.wav", filename);
191 | outfiles[deviceIdx] = sf_open(filename, SFM_WRITE, &info);
192 | if(!outfiles[deviceIdx]){
193 | ofLog(OF_LOG_ERROR, "CAN NOT OPEN FILE "+ofToString(filename));
194 | ofLogError(ofToString(sf_strerror(outfiles[deviceIdx])));
195 | sf_close(outfiles[deviceIdx]);
196 | }else{
197 | bRecordingBlocked[deviceIdx] = false;
198 | }
199 | }
200 |
201 | void ofxGSTT::finishRecording(int deviceIdx){
202 | ofLog(OF_LOG_VERBOSE, "finish recording (device%d)",deviceIds[deviceIdx]);
203 | bRecordingBlocked[deviceIdx] = true;
204 | sf_close(outfiles[deviceIdx]);
205 | deviceTanscriber[deviceIdx]->startTranscription();
206 | }
207 |
208 |
209 |
--------------------------------------------------------------------------------
/src/ofxGSTT.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofxGSTTTranscriptionThread.h"
5 | #include "sndfile.h"
6 |
7 | #define OFXGSTT_DEFAULTDEVICE_ID 0
8 |
9 | using namespace std;
10 |
11 |
12 | /* TODO nice to have:
13 | SF_INFO per device - so each device can have its own settings!
14 | thread safe?
15 | naming
16 | volume calculation, smart detection instead of threshold?
17 | */
18 |
19 | class ofxGSTT : public ofBaseSoundInput{
20 | public:
21 | ofxGSTT();
22 |
23 | void setup(int sampleRate, int nChannels, string language, string key);
24 |
25 | void setAutoRecording(bool listen);
26 | bool isAutoRecording();
27 |
28 | void setVolumeThreshold(float volumeThreshold);
29 | float getVolumeThreshold();
30 |
31 | void startRecording();
32 | void stopRecording();
33 |
34 | bool isRecording(){
35 | return isRecording(OFXGSTT_DEFAULTDEVICE_ID);
36 | }
37 |
38 | float getSmoothedVolume(){
39 | return smoothedVolume[OFXGSTT_DEFAULTDEVICE_ID];
40 | }
41 |
42 | virtual void audioIn( ofSoundBuffer& buffer );
43 | virtual void audioIn(float * buffer,int bufferSize, int nChannels, int deviceId);
44 |
45 | //GUI settings
46 |
47 | protected:
48 | void addDevice(int deviceId); //single device - multiple devices not thread safe at all
49 | bool isRecording(int deviceId);
50 | void prepareRecording(int deviceIdx);
51 | void finishRecording(int deviceIdx);
52 |
53 | vector transcriber;
54 | string language, key;
55 |
56 | /*** SOUND INPUT ***/
57 | int sampleRate;
58 | bool bAutoListen, bListen;
59 | float volumeThreshold;
60 |
61 | /*** SOUND RECORDING ***/
62 | int transcriberId;
63 | SF_INFO info;
64 |
65 | vector deviceIds;
66 | vector outfiles;
67 | vector smoothedVolume;
68 | vector tLastUpdate;
69 | vector bRecording;
70 | vector bRecordingBlocked;
71 | vector bActiveVolume;
72 | vector deviceTanscriber;
73 | };
74 |
--------------------------------------------------------------------------------
/src/ofxGSTTEvent.h:
--------------------------------------------------------------------------------
1 | /**
2 | * Custom Event for Googles Response
3 | * */
4 |
5 | #pragma once
6 |
7 | #include "ofMain.h"
8 |
9 | class ofxGSTTResponseArgs: public ofEventArgs{
10 | public:
11 | int deviceId;
12 | long tSend;
13 | long tReceived;
14 | int source;
15 | string msg;
16 | float confidence;
17 | };
18 |
--------------------------------------------------------------------------------
/src/ofxGSTTTranscriptionThread.cpp:
--------------------------------------------------------------------------------
1 | #include "ofxGSTTTranscriptionThread.h"
2 |
3 | ofEvent ofxGSTTTranscriptionThread::gsttApiResponseEvent = ofEvent();
4 |
5 | ofxGSTTTranscriptionThread::ofxGSTTTranscriptionThread(int id) :
6 | ofThread(){
7 | this->id = id;
8 |
9 | this->bFinished = false;
10 | this->bFree = true;
11 | this->deviceId = -1;
12 | }
13 |
14 | void ofxGSTTTranscriptionThread::setup(int deviceId, string language, string key){
15 | string url = "https://www.google.com/speech-api/v2/recognize?output=json&lang="+language+"&key="+key;
16 | this->deviceId = deviceId;
17 |
18 | curl.setup();
19 | curl.setURL(url);
20 | }
21 |
22 | void ofxGSTTTranscriptionThread::setFilename(char * _filename){
23 | ofLog(OF_LOG_VERBOSE, "set filename: %s", _filename);
24 | sprintf(wavFile, "%s.wav", _filename);
25 | }
26 |
27 | bool ofxGSTTTranscriptionThread::isFree(){
28 | return bFree;
29 | }
30 |
31 | void ofxGSTTTranscriptionThread::reserve(){
32 | bFree = false;
33 | }
34 |
35 | bool ofxGSTTTranscriptionThread::isFinished(){
36 | return bFinished;
37 | }
38 |
39 | void ofxGSTTTranscriptionThread::startTranscription(){
40 | ofLog(OF_LOG_VERBOSE, "start transcription (device%d)",deviceId);
41 | startThread(true,false);
42 | }
43 |
44 | void ofxGSTTTranscriptionThread::stopTranscription(){
45 | ofLog(OF_LOG_VERBOSE, "stop transcription (device%d)",deviceId);
46 | bFinished = true;
47 | stopThread();
48 | }
49 |
50 | void ofxGSTTTranscriptionThread::threadedFunction(){
51 | //transcribe via google
52 | sendGoogleRequest();
53 | bFinished = true;
54 | bFree = true;
55 | }
56 |
57 | void ofxGSTTTranscriptionThread::sendGoogleRequest(){
58 | ofLog(OF_LOG_VERBOSE, "send request to google (device%d)",deviceId);
59 |
60 |
61 | curl.addFormFile("file",ofToString(wavFile),"audio/l16"); //TODO hardcoded
62 |
63 | // set header
64 | curl.addHeader("Expect:");
65 | curl.addHeader("Content-Type: audio/l16; rate=44100"); //TODO hardcoded
66 |
67 | ofxGSTTResponseArgs response;
68 | response.deviceId = deviceId;
69 | response.tSend = ofGetElapsedTimeMillis();
70 | curl.perform();
71 |
72 |
73 | std::string responseJson = curl.getResponseBody();
74 | ofLogNotice("sendGoogleRequest") << responseJson;
75 |
76 | //decode via json
77 | googleResponseParser parser;
78 | bool validResponse = parser.parseJSON(responseJson);
79 |
80 | if(validResponse){
81 | response.tReceived = ofGetElapsedTimeMillis();
82 | response.msg = parser.utterance;
83 | response.confidence = parser.confidence;
84 |
85 | ofNotifyEvent(gsttApiResponseEvent, response);
86 | }
87 |
88 | curl.clear();
89 | }
90 |
--------------------------------------------------------------------------------
/src/ofxGSTTTranscriptionThread.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include "ofMain.h"
4 | #include "ofThread.h"
5 | #include "googleResponseParser.h"
6 | #include "ofxGSTTEvent.h"
7 | #include "ofxSSL.h"
8 |
9 | #define READSIZE 1024
10 |
11 | using namespace std;
12 |
13 | struct callBackData{
14 | int id;
15 | int deviceId;
16 | long timestamp;
17 | };
18 |
19 | class ofxGSTTTranscriptionThread: protected ofThread{
20 | public:
21 | ofxGSTTTranscriptionThread(int id);
22 | virtual ~ofxGSTTTranscriptionThread(){
23 | }
24 |
25 | void setup(int deviceId, string language, string key);
26 |
27 | void setFilename(char filename[]);
28 |
29 | void startTranscription();
30 | void stopTranscription();
31 | void reserve(); //TODO mutex?
32 | bool isFree();
33 | bool isFinished();
34 |
35 | static ofEvent gsttApiResponseEvent;
36 |
37 | protected:
38 | int id;
39 | int deviceId;
40 | char wavFile[128];
41 | bool bFinished;
42 | bool bFree;
43 |
44 | virtual void threadedFunction();
45 |
46 | ofxSSL curl;
47 | void sendGoogleRequest();
48 | };
49 |
--------------------------------------------------------------------------------