Page 161 - The Definitive Guide to Building Java Robots
P. 161

Preston_5564C05.fm  Page 142  Tuesday, September 20, 2005  5:13 AM



                 142    CHAPTER 5  ■  SPEECH



                              /*
                               * Class:     TempConvert
                               * Method:    FtoC
                               * Signature: (F)F
                               */
                              JNIEXPORT jfloat JNICALL Java_com_scottpreston_javarobot_➥
                              chapter5_TempConvert_FtoC
                                (JNIEnv *, jobject, jfloat);

                              #ifdef __cplusplus
                              }
                              #endif
                              #endif
                            5. I had to make two modifications to this file because I compiled it from the /bin/com/
                              scottpreston/javarobot/chapter5 directory.

                              • I had to change the fully qualified class name from “Java_TempConvert” to
                                “Java_com_scottpreston_javarobot_chapter5_TempConvert”.

                              • I had to replace the “<jni.h>” with “jni.h”.
                            6. Copy jawt.h, jvmpi.h, jvmdi.h, jni_md.j, jni.h, and jawt_md.h to the project directory.
                              These are required for jni.h and for compiling.
                            7. Add your native code.



                        ■Note  In Example 5-3, I performed the calculation using the JNIEXPORT method. Later when discussing
                        Microsoft speech and voice recognition, calls to other classes and methods are inserted here, rather than
                        performing 100 percent of the native action within these methods.




                              Example 5-3. SimpleJNI.h
                              // SimpleJNI.h

                              #include "TempConvert.h"

                              JNIEXPORT jfloat JNICALL➥
                              Java_com_scottpreston_javarobot_chapter5_TempConvert_CtoF
                                (JNIEnv *, jobject, jfloat f)
                              {        // native code
                                      float out = f *1.8 + 32;
                                      return out;
                              }
   156   157   158   159   160   161   162   163   164   165   166