How to make and lose Processed sound

My goal is to create a "Chirper" class. The chirper should be able to emit the processed chirp sound. The specific idea is that tweets should be processed procedurally rather than previously recorded sound.

What is the easiest way to achieve chirp-processed sound on an iPhone?

+5
source share
2 answers

You can do this with a sine wave, as you said, which you define with the sin functions. Create a buffer as long as you want the sound in the samples, for example:

// 1 second chirp
float samples[44100];

, , , , , - :

float startFreq = 1400;
float endFreq = 1100;

float thisFreq;
int x;
for(x = 0; x < 44100; x++)
{
    float lerp = float(float(x) / 44100.0);

    thisFreq = (lerp * endFreq) + ((1 - lerp) * startFreq);
    samples[x] = sin(thisFreq * x);
}

- , .

, - , . , saw() sqr() tri(), , .

========================

-

, - , OpenAL. OpenAL API iOS .

    alGenBuffers (1, &buffer); 
    alBufferData (buffer, AL_FORMAT_MONO16, buf, size, 8000); 
    alGenSources (1, &source); 

    ALint state; 

    // attach buffer and play 
    alSourcei (source, AL_BUFFER, buffer); 
    alSourcePlay (source); 

    do 
    { 
        wait (200); 
        alGetSourcei (source, AL_SOURCE_STATE, &state); 
    } 
    while ((state == AL_PLAYING) && play); 

    alSourceStop(source); 
    alDeleteSources (1, &source); 

    delete (buf) 
} 
+5

Nektarios -. ( ).

+1

All Articles