mirror of
https://github.com/ZDoom/fluidsynth.git
synced 2024-11-10 15:01:40 +00:00
add test for API fluid_voice_add_mod()
This commit is contained in:
parent
2afab29bab
commit
4e0f436c9a
3 changed files with 264 additions and 0 deletions
|
@ -2231,4 +2231,65 @@ void fluid_print_voice_mod(fluid_voice_t *voice)
|
|||
}
|
||||
printf("modulateur num:%d, total members:%d\n", mod_idx, i);
|
||||
}
|
||||
|
||||
/*
|
||||
* return the number of modulators inside a voice. the number is the number
|
||||
* of simple modulator added to number of complex modualtors.
|
||||
* For example, let a voice with:
|
||||
* {m0} (simple), {m1} (simple), {m2 ,m3, m4} (complex), {m5} (simple)
|
||||
* The number returned will be 4. A complex modulator (i.e {m2 ,m3, m4}) is
|
||||
* considered as one modulator regardless how many members inside this complex
|
||||
* modulator.
|
||||
*
|
||||
* @param voice, pointer on voice.
|
||||
* @return number of modulators or FLUID_FALED otherwise.
|
||||
*/
|
||||
int fluid_voice_get_count_modulators(fluid_voice_t *voice)
|
||||
{
|
||||
int i, mod_idx;
|
||||
fluid_mod_t *mod;
|
||||
|
||||
fluid_return_val_if_fail(voice != NULL, FLUID_FAILED);
|
||||
|
||||
for(i = 0, mod_idx = 0; i < voice->mod_count; i+= fluid_get_num_mod(mod), mod_idx++)
|
||||
{
|
||||
mod = &voice->mod[i];
|
||||
}
|
||||
return mod_idx;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a modulator inside a voice from its index mod_idx.
|
||||
* For example, let a voice with:
|
||||
* {m0} (simple), {m1} (simple), {m2 ,m3, m4} (complex), {m5} (simple)
|
||||
* - mod_idx 0 will return a pointer on m0.
|
||||
* - mod_idx 1 will return a pointer on m1.
|
||||
* - mod_idx 2 will return a pointer on complex modulator m2 (i.e {m2 ,m3, m4}).
|
||||
* - mod_idx 3 will return a pointer on m5.
|
||||
* - mod_idx 4 will return NULL because mod_idx is >= modulators count.
|
||||
*
|
||||
* @param voice, pointer on voice.
|
||||
* @param mod_idx, modulator index (0 to fluid_voice_get_count_modulators() minus 1).
|
||||
* @return pointer on modulator if success or NULL otherwise.
|
||||
*/
|
||||
fluid_mod_t *fluid_voice_get_modulator(fluid_voice_t *voice, int mod_idx)
|
||||
{
|
||||
unsigned char count, i;
|
||||
fluid_mod_t *mod;
|
||||
|
||||
fluid_return_val_if_fail(voice != NULL, NULL);
|
||||
fluid_return_val_if_fail((0 <= mod_idx), NULL);
|
||||
|
||||
for (i = 0, count = 0; i < voice->mod_count; i += fluid_get_num_mod(mod))
|
||||
{
|
||||
mod = &voice->mod[i];
|
||||
if (count == mod_idx)
|
||||
{
|
||||
return mod;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,7 @@ ADD_FLUID_TEST(test_snprintf)
|
|||
ADD_FLUID_TEST(test_modulator_links)
|
||||
ADD_FLUID_TEST(test_modulator_amount)
|
||||
ADD_FLUID_TEST(test_fluid_zone_check_mod)
|
||||
ADD_FLUID_TEST(test_fluid_voice_add)
|
||||
ADD_FLUID_TEST(test_synth_process)
|
||||
|
||||
# if ( LIBSNDFILE_HASVORBIS )
|
||||
|
|
202
test/test_fluid_voice_add.c
Normal file
202
test/test_fluid_voice_add.c
Normal file
|
@ -0,0 +1,202 @@
|
|||
/*----------------------------------------------------------------------------
|
||||
Test of API fluid_voice_add_mod()function.
|
||||
|
||||
Adding simple modulators in a voice in mode:
|
||||
FLUID_VOICE_DEFAULT, FLUID_VOICE_ADD, FLUID_VOICE_OVERWRITE.
|
||||
----------------------------------------------------------------------------*/
|
||||
#include "test.h"
|
||||
#include "fluidsynth.h"
|
||||
#include "utils/fluid_sys.h"
|
||||
#include "synth/fluid_voice.h"
|
||||
#include "synth/fluid_chan.h"
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/* external functions */
|
||||
void fluid_print_voice_mod(fluid_voice_t *voice);
|
||||
int fluid_voice_get_count_modulators(fluid_voice_t *voice);
|
||||
fluid_mod_t *fluid_voice_get_modulator(fluid_voice_t *voice, int mod_idx);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
static int fluid_compare_mod_structure(fluid_mod_t *mod1, fluid_mod_t *mod2);
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
/*-- modulators to add to voice
|
||||
/* valid simple modulator (i.e unlinked): sources cc, sources cc 3 valid */
|
||||
fluid_mod_t mod1_simple_in[] =
|
||||
{
|
||||
{
|
||||
// dest , src1 , flags1 , src2 , flags2
|
||||
GEN_ATTENUATION , 3 , FLUID_MOD_CC, FLUID_MOD_NONE, FLUID_MOD_GC,
|
||||
// amount, link, next
|
||||
10.0 , 0.0 , NULL
|
||||
}
|
||||
};
|
||||
|
||||
/* valid simple modulator (i.e unlinked): sources cc, sources cc 4 valid */
|
||||
fluid_mod_t mod2_simple_in[] =
|
||||
{
|
||||
{
|
||||
// dest , src1 , flags1 , src2 , flags2
|
||||
GEN_ATTENUATION , 4 , FLUID_MOD_CC, FLUID_MOD_NONE, FLUID_MOD_GC,
|
||||
// amount, link, next
|
||||
10.0 , 0.0 , NULL
|
||||
}
|
||||
};
|
||||
|
||||
/* invalid simple modulator (i.e unlinked): sources cc, sources cc 0 invalid */
|
||||
fluid_mod_t mod3_simple_in[] =
|
||||
{
|
||||
{
|
||||
// dest , src1 , flags1 , src2 , flags2
|
||||
2 , 0 , FLUID_MOD_CC, FLUID_MOD_NONE, FLUID_MOD_GC,
|
||||
// amount, link, next
|
||||
10.0 , 0.0 , NULL
|
||||
}
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// Adding simple modulators in a voice
|
||||
// These tests add a simple modulator in a voice in mode
|
||||
// FLUID_VOICE_DEFAULT, FLUID_VOICE_ADD, FLUID_VOICE_OVERWRITE.
|
||||
int main(void)
|
||||
{
|
||||
fluid_voice_t * voice;
|
||||
int voice_mod_count; // numbers of default modulator
|
||||
int voice_mod_count1, voice_mod_count2, voice_mod_count3;
|
||||
int voice_mod_count4, voice_mod_count5;
|
||||
|
||||
voice = new_fluid_voice(NULL, 22050);
|
||||
TEST_ASSERT(voice != NULL);
|
||||
fluid_print_voice_mod(voice);
|
||||
voice_mod_count = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count == 0);
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
printf("\nTest 1_1: Add a valid new simple modulator to voice in mode FLUID_VOICE_DEFAULT\n");
|
||||
{
|
||||
fluid_mod_t * mod_out;
|
||||
|
||||
// add a valid new simple modulator in mode FLUID_VOICE_DEFAULT
|
||||
fluid_voice_add_mod(voice, mod1_simple_in, FLUID_VOICE_DEFAULT);
|
||||
fluid_print_voice_mod(voice);
|
||||
|
||||
// Check if the new modulator has been correctly added in mode
|
||||
// FLUID_VOICE_DEFAULT. Voice count of modulators must be voice_mod_count
|
||||
// plus one.
|
||||
voice_mod_count1 = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count1 == voice_mod_count + 1);
|
||||
|
||||
/* Compare new modulator in voice (mod_out) with modulator
|
||||
mod1_simple_in. Both must have equal structure
|
||||
*/
|
||||
mod_out = fluid_voice_get_modulator(voice, voice_mod_count1 - 1);
|
||||
TEST_ASSERT(mod_out != NULL);
|
||||
|
||||
TEST_ASSERT(fluid_compare_mod_structure(mod_out, mod1_simple_in) == TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
printf("\nTest 1_2: Add a valid identical simple modulator to voice in mode FLUID_VOICE_ADD\n");
|
||||
{
|
||||
fluid_mod_t * mod_out;
|
||||
|
||||
// add a valid identical simple modulator in mode FLUID_VOICE_ADD
|
||||
fluid_voice_add_mod(voice, mod1_simple_in, FLUID_VOICE_ADD);
|
||||
fluid_print_voice_mod(voice);
|
||||
|
||||
// Check if the identical modulator has been correctly added in mode
|
||||
// FLUID_VOICE_ADD. Voice count of modulators must be the same as for
|
||||
// test 1_1.
|
||||
voice_mod_count2 = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count2 == voice_mod_count1);
|
||||
|
||||
/* Compare added modulator in voice (mod_out) with modulator mod1_simple_in.
|
||||
- mod_out must be identical to mod1_simple_in
|
||||
- mod_out->amount must be: 2 * mod1_simple_in->amount
|
||||
*/
|
||||
mod_out = fluid_voice_get_modulator(voice, voice_mod_count2 - 1);
|
||||
TEST_ASSERT(mod_out != NULL);
|
||||
// compare mod_out and mod1_simple_in
|
||||
TEST_ASSERT(fluid_mod_test_identity(mod_out, mod1_simple_in) == TRUE);
|
||||
TEST_ASSERT(mod_out->amount == (2 * mod1_simple_in->amount));
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
printf("\nTest 1_3: Add a valid identical simple modulator to voice in mode FLUID_VOICE_OVERWRITE\n");
|
||||
{
|
||||
fluid_mod_t * mod_out;
|
||||
|
||||
// add a valid identical simple modulator in mode FLUID_VOICE_OVERWRITE
|
||||
fluid_voice_add_mod(voice, mod1_simple_in, FLUID_VOICE_OVERWRITE);
|
||||
fluid_print_voice_mod(voice);
|
||||
|
||||
// Check if the identical modulator has been correctly added in mode
|
||||
// FLUID_VOICE_OVERWRITE. Voice count of modulators must be the same as for
|
||||
// test 1_2.
|
||||
voice_mod_count3 = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count3 == voice_mod_count2);
|
||||
|
||||
/* Compare added modulator in voice (mod_out) with modulator
|
||||
mod1_simple_in. Both must have equal structure
|
||||
*/
|
||||
mod_out = fluid_voice_get_modulator(voice, voice_mod_count3 - 1);
|
||||
TEST_ASSERT(mod_out != NULL);
|
||||
// compare mod_out and mod1_simple_in
|
||||
TEST_ASSERT(fluid_compare_mod_structure(mod_out, mod1_simple_in) == TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
printf("\nTest 1_4: Add a valid not identical simple modulator to voice in mode FLUID_VOICE_ADD\n");
|
||||
{
|
||||
fluid_mod_t * mod_out;
|
||||
|
||||
// add a valid identical simple modulator in mode FLUID_VOICE_ADD
|
||||
fluid_voice_add_mod(voice, mod2_simple_in, FLUID_VOICE_ADD);
|
||||
fluid_print_voice_mod(voice);
|
||||
|
||||
// Check if the identical modulator has been correctly added in mode
|
||||
// FLUID_VOICE_ADD. Voice count of modulators must be the same as for
|
||||
// test 1_3 plus one.
|
||||
voice_mod_count4 = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count4 == voice_mod_count3 + 1);
|
||||
|
||||
/* Compare added modulator in voice (mod_out) with modulator mod1_simple_in.
|
||||
- mod_out must be identical to mod1_simple_in
|
||||
- mod_out->amount must be: 2 * mod1_simple_in->amount
|
||||
*/
|
||||
mod_out = fluid_voice_get_modulator(voice, voice_mod_count4 - 1);
|
||||
TEST_ASSERT(mod_out != NULL);
|
||||
// compare mod_out and mod2_simple_in
|
||||
TEST_ASSERT(fluid_compare_mod_structure(mod_out, mod2_simple_in) == TRUE);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
printf("\nTest 1_5: Add an invalid simple modulator to voice in mode FLUID_VOICE_DEFAULT\n");
|
||||
{
|
||||
fluid_mod_t * mod_out;
|
||||
|
||||
// add a valid new simple modulator in mode FLUID_VOICE_DEFAULT
|
||||
fluid_voice_add_mod(voice, mod3_simple_in, FLUID_VOICE_DEFAULT);
|
||||
fluid_print_voice_mod(voice);
|
||||
|
||||
// Check if the new modulator has been correctly added in mode
|
||||
// FLUID_VOICE_DEFAULT. Voice count of modulators must be voice_mod_count
|
||||
// plus one.
|
||||
voice_mod_count5 = fluid_voice_get_count_modulators(voice);
|
||||
TEST_ASSERT(voice_mod_count5 == voice_mod_count4);
|
||||
}
|
||||
|
||||
//freeing
|
||||
delete_fluid_voice(voice);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return TRUE if mod1 fluid_mod_t fields are equal to mod1 fluid_mod_t fields.
|
||||
* param mod1, mod2 pointer on fluid_mod_t structures.
|
||||
*/
|
||||
static int fluid_compare_mod_structure(fluid_mod_t *mod1, fluid_mod_t *mod2)
|
||||
{
|
||||
return ( fluid_mod_test_identity(mod1, mod2) &&
|
||||
(mod1->amount == mod2->amount));
|
||||
}
|
Loading…
Reference in a new issue