Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement voice-processing #26

Open
JayFoxRox opened this issue Jan 31, 2019 · 0 comments
Open

Implement voice-processing #26

JayFoxRox opened this issue Jan 31, 2019 · 0 comments

Comments

@JayFoxRox
Copy link
Owner

Pseudocode:

      
    // Create a buffer for this voice
    int32_t voice_samples[NUM_SAMPLES_PER_FRAME];
    int voice_samples_left = ARRAY_SIZE(voice_samples);

    // Figure out how many samples we'll require from the input, to fill this
    // frame.
    int voice_buffer_sample_count = 1337; //FIXME!

    // Get the samples
    #define MAX_VOICE_SAMPLES 100
    int32_t voice_buffer_samples[MAX_VOICE_SAMPLES];

    // Decode some input samples for this voice
    input_sample_count = decode(voice_buffer_raw_samples, voice_buffer_samples, voice_buffer_sample_count);

    // Resample voice input
    while(voice_samples_left > 0) {

      // This needs to play back at 48kHz
      resample(f, 48000, &input_samples, &input_sample_count, &voice_samples, &voice_samples_left);

      // Handle end of input buffer
      if (input_sample_count == 0) {
        if (voice_loops) {
          // Voice loops; go back to start of buffer
          input_samples = voice_buffer_samples;
          input_sample_count = voice_buffer_sample_count;
        } else {
          // Voice finishes; fill with silence
          while(voice_samples_left--) {
            *voice_samples++ = 0;
          }
        }
      }

    }
#if 0
    //FIXME: Generate envelope for this voice
    uint8_t amplitude_level = get_envelope_level(voice);

    //FIXME: This buffer generation is not necessary.
    //       The envelope counter runs at 1500 Hz = 1 update per frame.
    //       We simply have to figure out if there's linear interpolation.
    //       Eitherway: We can apply it in the mixing step below
    uint8_t amplitude_envelope[NUM_SAMPLES_PER_FRAME];
    memset(amplitude_envelope, amplitude_level, sizeof(amplitude_envelope));

    // Apply amplitude envelopes
    multiply(voice_samples, amplitude_envelope, NUM_SAMPLES_PER_FRAME);
#endif

    // Add the output to each of the MIXBINs for this voice
    for(int i = 0; i < 8; i++) {
      mix(mixbin[voice_mixbin_target[i]], NUM_SAMPLES_PER_FRAME, voice_samples, ARRAY_SIZE(voice_samples), voice_mixbin_volume[i]);
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant