Can i make sound using sine function?

i really want to know play sound .

first i make a sine signal. for example 1second 300hz sampling 2048 during (t=0:1/2048:(1-1/2048))
signal=sin(2pi300*t)
then i try to generate sound. how do i do ? and how to adjust arduino's samping rates
as i found, arduino supports tone function, but it is not satisfied with me.
because i make several multisine signal sound.
i have a arduino uno , small amp which use stereo port and 4ohm 3W speaker

when i thought, after endcoding my sine signal, i can make sound using startPlayback(); fucntion

is it right? in my case i use only labview, matlab so, i can not understand specific process..

plz let me know.

because i make several multisine signal sound.

It's a digital output so you get a square wave.

You can make a sine wave in software, but the Arduino doesn't have a true digital-to-analog converter so it can't put-out a sine wave (or a quantized approximation).

It can only approximate analog with PWM. That works for dimming LEDs or controlling motor speed, but it doesn't work well for audio. PWM can be filtered to analog with a low-pass filter, but the Arduino's default PWM frequency is too low for "normal audio". There is a way to increase the PWM frequency (you'll have to research that) but I don't know if the audio quality will be useful to you.

You can get an audio shield with a DAC.

i can make sound using startPlayback(); fucntion

I believe startPlayback() reads a WAV file from a memory card (which might be included on the audio shield). So, you'd have to write the sine data to a WAV file, complete with a WAV file header.

I assume there's a way to read a "sine table" (from an array you create mathematically) and that would be easier than writing a proper WAV file. Or, maybe there's a way to calculate the sine on-the-fly and send one sample at a time to the audio shield.

and how to adjust arduino's samping rates

The audio shield should take care of that for you. Otherwise, I believe you have to use the micros() function to generate the timing yourself.

i can make sound using startPlayback(); fucntion

is it right?

No.

The Arduino is too slow to compute a sin wave on the fly let alone three of them. You have to use a look up table to get the samples.

how to adjust arduino's samping rates

You just output samples at the rate you want to output them, there is no "adjustment" as such. What sample rate do you want to output?

If you want to play a sample with minimul hardware then Try this

or this

The Uno can do a decent 1 KHz tone on the fly within the limits of PWM.

#include <TimerOne.h>

#define outPin  9

const float pi = 3.14159 ;
const float T = 100 ;    // sample time in microseconds
const float freq = 1000 ;  // frequency of tone in hertz
const float omega = 2*pi*freq ;
const float A = 490 ;  // amplitude
// next line initializes oscillation with amplitude A
float a[]={0.0, A*sin(omega*T/1000000.0),0.0}; 
// c1 is the difference equation coefficient
const float c1 = (8.0 - 2.0*pow(omega*T/1000000.0,2))/(4.0+pow(omega*T/1000000.0,2));

void setup()                 
{
  Timer1.initialize(T);  // set sample time for discrete tone signal
  Timer1.pwm(outPin, 0,T);
  Timer1.attachInterrupt(compute);
}

void loop()                   
{
}

void compute()
{
  a[2] = c1*a[1] - a[0] ;  // recursion equation
  a[0] = a[1] ;
  a[1] = a[2] ;  
  Timer1.setPwmDuty(outPin, map( a[2],-512, 512, 0, 1000));
}

charliesixpack:
The Uno can do a decent 1 KHz tone on the fly within the limits of PWM.

Yes but it is not a sin wave is it.
Also if you just want this it is much simpler to use the tone function.

Grumpy_Mike:
Yes but it is not a sin wave is it.

Yes, it is. Try it on the Due to verify (the DAC is necessary to see it).

Can you guess how it's done?