Ejemplo n.º 1
0
    void writeBufferToFile( int aSampleRate, int aNumChannels, bool broadcastUpdate )
    {
        // quick assertion
        if ( DiskWriter::cachedBuffer == 0 )
            return;

        aNumChannels = 1;   // TODO : currently MONO only (see appendBuffer above)

        // we improve the use of the CPU resources
        // by creating a small local thread
        // TODO: do it ? (this non-threading blocks the renderer, but nicely omits issue w/ continuous writes ;) )

        //pthread_t t1;
        //pthread_create( &t1, NULL, &print_message, NULL );

        // copy string contents for appending of filename
        std::string outputFile = std::string( DiskWriter::outputDirectory.c_str());

        int bufferSize = DiskWriter::outputBufferSize;

        // uh oh.. recorded less than maximum available in buffer ? cut silence
        if ( DiskWriter::outputWriterIndex < bufferSize )
        {
            bufferSize = DiskWriter::outputWriterIndex;

            short int* tempBuffer = new short int[ bufferSize ];

            for ( int i = 0; i < bufferSize; ++i )
                tempBuffer[ i ] = DiskWriter::cachedBuffer[ i ];

            write_wav( outputFile.append( SSTR( recordingFileName )), bufferSize, tempBuffer, aSampleRate, aNumChannels );

            delete[] tempBuffer;
        }
        else {
            write_wav( outputFile.append( SSTR( recordingFileName )), bufferSize, DiskWriter::cachedBuffer, aSampleRate, aNumChannels );
        }
        DiskWriter::flushOutput(); // free memory

        if ( broadcastUpdate )
        {
            // broadcast update via JNI, pass buffer identifier name to identify last recording
            jmethodID native_method_id = getJavaMethod( JavaAPIs::RECORDING_UPDATE );

            if ( native_method_id != 0 )
            {
                JNIEnv* env = getEnvironment();

                if ( env != 0 )
                    env->CallStaticVoidMethod( getJavaInterface(), native_method_id, recordingFileName );
            }
        }
        //void* result;
        //pthread_join( t1, &result );
    }
Ejemplo n.º 2
0
/**
 * registers the reference to the JAVA_CLASS (and its host environment)
 * where all subsequent calls will be executed upon, the Java class
 * will only expose static methods for its interface with the native code
 *
 * upon registration the current BUFFER_SIZE will be returned to the JNI
 */
void JavaBridge::registerInterface( JNIEnv* env, jobject jobj )
{
    jclass localRefCls = env->FindClass( JAVA_CLASS );
    if (localRefCls == NULL) {
        return; /* exception thrown */
    }
    /* Create a global reference */
    _class = ( jclass ) env->NewGlobalRef( localRefCls );

    /* The local reference is no longer useful */
    env->DeleteLocalRef( localRefCls );

    /* Is the global reference created successfully? */
    if ( _class == NULL) {
        return; /* out of memory exception thrown */
    }

    jmethodID native_method_id = getJavaMethod( JavaAPIs::REGISTRATION_SUCCESS );

    if ( native_method_id != 0 )
        env->CallStaticVoidMethod( getJavaInterface(), native_method_id, 1 );
}