Пример #1
0
// Calls the effect on input buffer and returns output buffer when complete
static int fxCallback( const void *inputBuffer, void *outputBuffer,
                         unsigned long framesPerBuffer,
                         const PaStreamCallbackTimeInfo* timeInfo,
                         PaStreamCallbackFlags statusFlags,
                         void *userData )
{
    // Port audio variables
    SAMPLE *out = (SAMPLE*)outputBuffer;
    SAMPLE *tmp_buff = (SAMPLE*)outputBuffer;
    const SAMPLE *in = (const SAMPLE*)inputBuffer;
    unsigned int i;
    (void) timeInfo; /* Prevent unused variable warnings. */
    (void) statusFlags;
    (void) userData;

    // Pitch Shift variables
    long buffer_size = FRAMES_PER_BUFFER;
    float sr = SAMPLE_RATE;
    long fftSize = 2048;
    long osamp = 32;
    float pitchShift = pow(2., semitones/12.);
    int measure = 0;

    // Fill input buffer
    if( inputBuffer == NULL )
    {
        for( i=0; i<framesPerBuffer; i++ )
        {
            *out++ = 0;  /* left - silent */
        }
    }
    else    // playback
    {
        // Buffer based effect
        PitchShift(pitchShift, buffer_size , fftSize, osamp, sr, (float *)in, out);

         // Melody
         measure = 10000;
         if (count == measure) {
           semitones = 0;
           printf("Setting semitone to %ld...\n", semitones);
         } else if (count == measure * 1/8) {
           semitones += 4;
           printf("Setting semitone to %ld...\n", semitones);
         } else if (count == measure * 2/4) {
           semitones += 3;
           printf("Setting semitone to %ld...\n", semitones);
         } else if (count == measure * 3/4) {
           semitones += 4;
           printf("Setting semitone to %ld...\n", semitones);
         }

    }
    // printf("%d\n", count );
count = (count + 1) % measure;

    return paContinue;
}
Пример #2
0
//
// Starting a sound means adding it
//  to the current list of active sounds
//  in the internal channels.
// As the SFX info struct contains
//  e.g. a pointer to the raw data,
//  it is ignored.
// As our sound handling does not handle
//  priority, it is ignored.
// Pitching (that is, increased speed of playback)
//  is set, but currently not used by mixing.
//
int I_SDL_StartSound(sfxinfo_t *sfxinfo, int channel, int vol, int sep, int pitch)
{
    allocated_sound_t   *snd;

    if (!sound_initialized || channel < 0 || channel >= NUM_CHANNELS)
        return -1;

    // Release a sound effect if there is already one playing
    // on this channel
    ReleaseSoundOnChannel(channel);

    // Get the sound data
    if (!LockSound(sfxinfo))
        return -1;

    snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, pitch);

    if (!snd)
    {
        allocated_sound_t       *newsnd;

        // fetch the base sound effect, un-pitch-shifted
        snd = GetAllocatedSoundBySfxInfoAndPitch(sfxinfo, NORM_PITCH);
        if (!snd)
            return -1;

        if (s_randompitch)
        {
            newsnd = PitchShift(snd, pitch);
            if (newsnd)
            {
                LockAllocatedSound(newsnd);
                UnlockAllocatedSound(snd);
                snd = newsnd;
            }
        }
    }
    else
        LockAllocatedSound(snd);

    // play sound
    Mix_PlayChannel(channel, &snd->chunk, 0);

    channels_playing[channel] = snd;

    // set separation, etc.
    I_SDL_UpdateSoundParams(channel, vol, sep);

    return channel;
}