here's the "scratchpad" code i was referring to earlier.
Code:sine *s = new sine(); s->a = 1; s->f = 0.0928798185941/2; controlPanel *p = new controlPanel(this,s); WAVEFORMATEX format; format.wFormatTag = WAVE_FORMAT_PCM; format.nChannels = 2; format.nSamplesPerSec = 44100; format.wBitsPerSample = 16; format.nBlockAlign = format.nChannels*format.wBitsPerSample/8; format.nAvgBytesPerSec = format.nBlockAlign*format.nSamplesPerSec; format.cbSize =0; HANDLE output; MMRESULT result = waveOutOpen( &output, WAVE_MAPPER, &format, 0, 0, CALLBACK_NULL ); if(result==MMSYSERR_NOERROR) { const unsigned int wl = 65536; unsigned short maxv = pow(2,8*sizeof(maxv)-1); char wave[wl]; for(int i=0;i<wl;i+=sizeof(maxv)) { short v = 0.025*maxv*s->value(i); *(short *)(wave+i)= v; } WAVEHDR header; header.lpData = wave; header.dwBufferLength = wl; header.dwFlags = WHDR_BEGINLOOP; header.dwLoops = 0; MMRESULT wowresult; MMRESULT wophresult = waveOutPrepareHeader( output, &header, sizeof(header) ); int a; switch(wophresult) { case MMSYSERR_NOERROR: wowresult = waveOutWrite(output,&header,wl); break; case MMSYSERR_INVALHANDLE: a=0; break; case MMSYSERR_NODRIVER: a=0; break; case MMSYSERR_NOMEM: a=0; break; } } else { }
notes in even temperament (the more or less standard tuning scale used for most keyed instruments) can be related to each other by a factor of 2^(n/12) where n is the difference in number of semitones (notes, including sharps/flats).
the note A is an integer. A4 is 440 Hz.