Beispiel #1
0
TEST( WaveTable, Clone )
{
    int length       = randomInt( 2, 256 );
    float frequency  = randomFloat( 20, 880 );
    WaveTable* table = new WaveTable( length, frequency );

    table->setAccumulator( randomSample( 0.0, ( SAMPLE_TYPE ) length ));

    // randomly create content

    if ( randomBool() )
    {
        for ( int i = 0; i < length; ++i )
            table->getBuffer()[ i ] = randomSample( -1.0, 1.0 );
    }

    // create clone and validate its properties against the source table

    WaveTable* clone = table->clone();

    EXPECT_EQ( table->tableLength, clone->tableLength )
        << "expected cloned WaveTables length to equal the source WaveTables";

    EXPECT_EQ( table->getFrequency(), clone->getFrequency() )
        << "expected cloned WaveTable frequency to equal the source WaveTables";

    EXPECT_EQ( table->getAccumulator(), clone->getAccumulator() )
        << "expected cloned WaveTable accumulator to equal the source WaveTables";

    EXPECT_EQ( table->hasContent(), table->hasContent() )
        << "expected cloned WaveTable hasContent value to equal the source WaveTables";

    if ( table->hasContent() )
    {
        for ( int i = 0; i < length; ++i ) {
            EXPECT_EQ( table->getBuffer()[ i ], clone->getBuffer()[ i ])
                << "expected cloned WaveTable buffer to have equal buffer contents, but it didn't";
        }
    }
    delete table;
    delete clone;
}
Beispiel #2
0
TEST( WaveTable, HasContent )
{
    int length       = randomInt( 2, 256 );
    float frequency  = randomFloat( 20, 880 );
    WaveTable* table = new WaveTable( length, frequency );

    ASSERT_FALSE( table->hasContent() )
        << "expected WaveTable to have no content upon construction";

    SAMPLE_TYPE* buffer = table->getBuffer();

    for ( int i = 0; i < length; ++i )
        buffer[ i ] = randomSample( -1.0, 1.0 );

    ASSERT_TRUE( table->hasContent() )
        << "expected WaveTable to report to have content after assignment of sample values in buffer";

    delete table;
}
void JavaUtilities::cacheTable( jint tableLength, jint waveformType, jdoubleArray aBuffer )
{
    WaveTable* table = new WaveTable( tableLength, waveformType );
    SAMPLE_TYPE* buffer  = table->getBuffer();

    // get a pointer to the Java array
    jdouble* c_array;
    c_array = JavaBridge::getEnvironment()->GetDoubleArrayElements( aBuffer, 0 );

    // exception checking
    if ( c_array == NULL )
        return;

    // copy buffer contents

    for ( int i = 0; i < tableLength; i++ )
        buffer[ i ] = ( SAMPLE_TYPE ) c_array[ i ];

    // release the memory so Java can have it again
    JavaBridge::getEnvironment()->ReleaseDoubleArrayElements( aBuffer, c_array, 0 );

    // store the table inside the pool
    TablePool::setTable( table, waveformType );
}