TeensyAudio / Wavetable-Synthesis

General repository for Wavetable Synthesis Capstone project at Portland State, Fall 2016 - Winter 2017
89 stars 19 forks source link

I modified the python script heavily #3

Open 8888clockradio opened 2 years ago

8888clockradio commented 2 years ago

I've been working on this for over a year. I have the python sf2 decoder script using struct and numpy to convert the 32-bit hex to 16-bit hex. Does anyone have any idea how to change the synth functionality to accept 16-bit samples? Do I have to change this section

out_fmt_str = \
        "\t\t{LOOP}, // LOOP\n" \
        "\t\t{LENGTH_BITS}, // LENGTH_BITS\n" \
        "\t\t(1 << (16 - {LENGTH_BITS})) * CENTS_SHIFT({CENTS_OFFSET}) * {SAMPLE_RATE:.1f} / NOTE({SAMPLE_NOTE}) / AUDIO_SAMPLE_RATE_EXACT + 0.5, // PER_HERTZ_PHASE_INCREMENT\n" \
        "\t\t((uint32_t){LENGTH} - 1) << (16 - {LENGTH_BITS}), // MAX_PHASE\n" \
        "\t\t((uint32_t){LOOP_END} - 1) << (16 - {LENGTH_BITS}), // LOOP_PHASE_END\n" \
        "\t\t(((uint32_t){LOOP_END} - 1) << (16 - {LENGTH_BITS})) - (((uint32_t){LOOP_START} - 1) << (16 - {LENGTH_BITS})), // LOOP_PHASE_LENGTH\n" \
        "\t\tuint16_t(UINT16_MAX * DECIBEL_SHIFT({INIT_ATTENUATION})), // INITIAL_ATTENUATION_SCALAR\n" \
        "\t\tuint32_t({DELAY_ENV:.2f} * SAMPLES_PER_MSEC / ENVELOPE_PERIOD + 0.5), // DELAY_COUNT\n" \
        "\t\tuint32_t({ATTACK_ENV:.2f} * SAMPLES_PER_MSEC / ENVELOPE_PERIOD + 0.5), // ATTACK_COUNT\n" \
        "\t\tuint32_t({HOLD_ENV:.2f} * SAMPLES_PER_MSEC / ENVELOPE_PERIOD + 0.5), // HOLD_COUNT\n" \
        "\t\tuint32_t({DECAY_ENV:.2f} * SAMPLES_PER_MSEC / ENVELOPE_PERIOD + 0.5), // DECAY_COUNT\n" \
        "\t\tuint32_t({RELEASE_ENV:.2f} * SAMPLES_PER_MSEC / ENVELOPE_PERIOD + 0.5), // RELEASE_COUNT\n" \
        "\t\tint32_t((1.0 - DECIBEL_SHIFT({SUSTAIN_FRAC:.1f})) * UNITY_GAIN), // SUSTAIN_MULT\n" \
        "\t\tuint32_t({VIB_DELAY_ENV:.2f} * SAMPLES_PER_MSEC / (2 * LFO_PERIOD)), // VIBRATO_DELAY\n" \
        "\t\tuint32_t({VIB_INC_ENV:.1f} * LFO_PERIOD * (UINT32_MAX / AUDIO_SAMPLE_RATE_EXACT)), // VIBRATO_INCREMENT\n" \
        "\t\t(CENTS_SHIFT({VIB_PITCH_INIT}) - 1.0) * 4, // VIBRATO_PITCH_COEFFICIENT_INITIAL\n" \
        "\t\t(1.0 - CENTS_SHIFT({VIB_PITCH_SCND})) * 4, // VIBRATO_COEFFICIENT_SECONDARY\n" \
        "\t\tuint32_t({MOD_DELAY_ENV:.2f} * SAMPLES_PER_MSEC / (2 * LFO_PERIOD)), // MODULATION_DELAY\n" \
        "\t\tuint32_t({MOD_INC_ENV:.1f} * LFO_PERIOD * (UINT32_MAX / AUDIO_SAMPLE_RATE_EXACT)), // MODULATION_INCREMENT\n" \
        "\t\t(CENTS_SHIFT({MOD_PITCH_INIT}) - 1.0) * 4, // MODULATION_PITCH_COEFFICIENT_INITIAL\n" \
        "\t\t(1.0 - CENTS_SHIFT({MOD_PITCH_SCND})) * 4, // MODULATION_PITCH_COEFFICIENT_SECOND\n" \
        "\t\tint32_t(UINT16_MAX * (DECIBEL_SHIFT({MOD_AMP_INIT_GAIN}) - 1.0)) * 4, // MODULATION_AMPLITUDE_INITIAL_GAIN\n" \
        "\t\tint32_t(UINT16_MAX * (1.0 - DECIBEL_SHIFT({MOD_AMP_SCND_GAIN}))) * 4, // MODULATION_AMPLITUDE_FINAL_GAIN\n" \
        "\t}},\n"

by changing the length bits from 32-bit to 16-bits and also here in the actual synth audio plugin

            index = tone_phase >> (16 - s->INDEX_BITS);
            //index = tone_phase >> (32 - s->INDEX_BITS);

My python script automagically decodes the entire sf2, puts the samples into separate files, put each instrument into a separate file and includes only the samples it needs adds to FLASHMEM instead of loading inline const_casts and the whole library is changed because i removed const from the sample_data struct using a const_cast instead. The python script also checks for samples that have the same name. The entire library has been changed but for my purposes could you help me? Right now it's crashing when I change the 32 to a 16 in the audio synth plugin

Also would this line be affected (mine is slightly modified)

if (!isLoadingFromSD) {
                tmp1 = *((uint32_t*)(s->sample + index));
}

I can fork the project if you want me to, it requires deleting all the text from teensys wavetable include thats part of the library