tone generator...

  • Thread starter Thread starter seo gang ho
  • Start date Start date
S

seo gang ho

how to make tone generator..

set frequency and amplitude..


show me the example..



thank you for read..
 
seo said:
how to make tone generator..

set frequency and amplitude..


show me the example..

Try the C# classes to read, write, modify, and play MIDI
events/tracks/sequences/files in .NET provided by Stephen Toub [MS].

http://www.gotdotnet.com/Community/...mpleGuid=89CDE290-5580-40BF-90D2-5754B2E8137C
Includes multiple demo applications

Attention: the download file is a file calles MIDI (without extension).
In fact it is a zip-Archive, so change the filename to MIDI.zip after
downloading it.

Cheers

Arne Janning
 
thank you for your reply..


But..I meant "sine-wave tone generator"...
(Oscillator?)

not MIDI..


1) make digital signal(sin,cos)..

2) send to sound output device..

3) finally make "Bee~~~~~~~~~~~~"..


understand?


thank you from my heart..
 
Hello

Here is code I wrote long ago using C, you can convert it to C# easily
using interop

WAVEFORMATEX waveFormat;
ZeroMemory(&waveFormat, sizeof(waveFormat));

waveFormat.cbSize = sizeof(waveFormat);
waveFormat.wFormatTag = WAVE_FORMAT_PCM;
waveFormat.nChannels = 1;
waveFormat.nSamplesPerSec = 44100;
waveFormat.wBitsPerSample = 16;
waveFormat.nBlockAlign = waveFormat.nChannels * waveFormat.wBitsPerSample /
8;
waveFormat.nAvgBytesPerSec = waveFormat.nSamplesPerSec *
waveFormat.nBlockAlign;

float frequency = 100;

UINT ndevices = waveOutGetNumDevs();
HWAVEOUT waveOut = NULL;
MMRESULT openRes = waveOutOpen(&waveOut, WAVE_MAPPER, &waveFormat, 0, 0,
CALLBACK_NULL | WAVE_FORMAT_DIRECT);
if(openRes == MMSYSERR_NOERROR)
{
WAVEHDR hdr;
ZeroMemory(&hdr, sizeof(hdr));
unsigned short *data = new unsigned short[waveFormat.nSamplesPerSec];
if(data != NULL)
{
for(int i = 0; i < (int)waveFormat.nSamplesPerSec; i++)
{
data = (unsigned short)(65535.0f * sin(frequency * (float)i /
(float)waveFormat.nSamplesPerSec));
}
hdr.dwBufferLength = sizeof(unsigned short) * waveFormat.nSamplesPerSec;
hdr.lpData = (LPSTR)data;
hdr.dwLoops = 5;

MMRESULT prepareRes = waveOutPrepareHeader(waveOut, &hdr, sizeof(hdr));
hdr.dwFlags |= WHDR_BEGINLOOP | WHDR_ENDLOOP;

if(prepareRes == MMSYSERR_NOERROR)
{
MMRESULT playRes = waveOutWrite(waveOut, &hdr, sizeof(hdr));
if(playRes == MMSYSERR_NOERROR)
{
while(waveOutUnprepareHeader(waveOut, &hdr, sizeof(hdr)) ==
WAVERR_STILLPLAYING)
{
Sleep(100);
}
}
}
delete[] data;
}

}
 
Back
Top