Article View: borland.public.cppbuilder.nativeapi
Article #16248Re: Beep(freq,dur) MIDI-style
From: Ted Lyngmo
Date: Fri, 23 May 2003 02:18
Date: Fri, 23 May 2003 02:18
31 lines
1746 bytes
1746 bytes
Chris Hill wrote:
>
> DWORD FreqToNote(DWORD frequency)
> {
> double freq;
> int x;
>
> for(x = 0; x < 127; x++)
> {
> freq = (440.0 / 32) * pow(2,((x - 9) / 12));
> if (freq > frequency)
> break;
> }
>
> return x;
> }
An alternative way of doing the frequency to midi note conversion:
int FreqToNote(double frequency) {
static const double base=55.0*pow(2.0,-33.0/12.0); // C0
return (int) (log(frequency/base)/(log(2.0)/12.0)+.5);
}
Kind regards,
Ted Lyngmo
--
Replace MY_FIRST_NAME in my email address with my first name to send a private
email to me.
Technical Details
Message-ID:
<3ECD84FB.4050301@lyncon.se>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<3ec803f7@newsgroups.borland.com> <3ec9b925.815056399@forums.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,43257d87a9e437b6 X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-05-22 19:30:43 PST Message-ID: <3ECD84FB.4050301@lyncon.se> Date: Fri, 23 May 2003 04:18:35 +0200 From: Ted Lyngmo <MY_FIRST_NAME@lyncon.se> Organization: Lyncon - Computer & Music consulting User-Agent: Mozilla/5.0 (Windows; U; Win98; en-US; rv:0.9.4) Gecko/20011128 Netscape6/6.2.1 X-Accept-Language: sv,en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.nativeapi Subject: Re: Beep(freq,dur) MIDI-style References: <3ec803f7@newsgroups.borland.com> <3ec9b925.815056399@forums.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 217.215.147.98 X-Trace: newsgroups.borland.com 1053655950 217.215.147.98 (22 May 2003 19:12:30 -0700) Lines: 32 Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!newsfeed.news2me.com!border1.nntp.aus1.giganews.com!nntp.giganews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail