This site requires JavaScript, please enable it in your browser!
Greenfoot back
wabuilderman
wabuilderman wrote ...

2015/7/22

turning audio samples into a playable audio

wabuilderman wabuilderman

2015/7/22

#
Ok, using the following script I was a able to create raw audio samples. How would I play these in greenfoot?
// in hz, number of samples in one second
        sampleRate = 44100
        
        // this is the time BETWEEN Samples
        samplePeriod = 1.0 / sampleRate
        
        // 2ms
        duration = 0.002;
        durationInSamples = Math.ceil(duration * sampleRate);
        
        time = 0;
        for(int i = 0; i < durationInSamples; i++)
        {
          // sample a sine wave at 440 hertz at each time tick
          // substitute a function that generates a sawtooth as a function of time / freq
          // rawOutput[i] = function_of_time(other_relevant_info, time);
          rawOutput[i] = Math.sin(2 * Math.PI * 440 * time);
          time += samplePeriod;
        }
You need to login to post a reply.