Playing a audio vector with a specific sampling rate?

Hallo,

I am working on a project where I am going to generate sounds using a Karplus-Strong string synthesis and I have encounted something I am unsure about.

The problem I need help with is that my algorithm generate a vector of N-size with a tone with a specific a frequency M, e.g. 2000 Hz, however, given sound depend on the sampling rate, let us say in my case 5000 Hz I want to make sure I am running with a specific sampling rate, but I am unsure how to make sure that the vector is sent out from a pin to a speaker with a specific sampling rate, so is there a way to do this?

Some other information regarding my project is that the board is either going to be a UNO R3 or a Zero and the vector to be played is fully calculated before hand.

For people not knowing what the Karplus-Strong synthesis is, it is noise that is delayed and filtered in the most simple version of the algorithm.

The low pass filter in my case is y[n] =ax[n] + (1−a)x[n−1]

I'm not sure of the speaker connection. Do you want to use a DAC to produce an analog signal, or how do you want to suppress an
audible 5kHz sampling frequency in the output signal? Using filtered PWM for the analog output should use a PWM frequency way above audible frequencies.

the vector to be played is fully calculated before hand.

No it's not. The point about that algorithm is that each output samples is calculate between samples. If you want to fully calculate the resulting audio sample then you need somewhere like an SD card to store the sample before playing.

A clock rate of 5KHz is way too slow for this as this gives you a top frequency output of 2.5KHz which is not a lot for a string and a you will have a hell of a job filtering out the sample noise.

A compleat program for doing this in real time for a Due class processor is in my book

Also the Teensy processors are much better and their is examples on their web site.