473,394 Members | 1,642 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Problems with note-frequenzy algorithm

I'm writing a little C# / DirectSound piano which uses
SecondaryBuffer to play .wav-files. The SecondaryBuffer has a
Frequenzy property which I set to modulate the .wav file into
playing the right note.

The algorithm for a given frequenzy is «x * 2 ^ (y / 12)», where
'x' is the start frequenzy (I use 440 which is A) and 'y' is the
number of half notes from x the given note is. If I am going to
get the frequenzy of a C, the formula would look like this: «440
* 2 ^ (3 / 12)», and the result should be 523,251130601[...]Hz.

But I can't figure out a way to get this algorithm to work. If I
only use integers in the algorithm, it works, but I need a
_much_ higher precision level than int. I would like to use
decimal, but neither that, nor float or double works. I've tried
everything it seems, but nothing works.

How can I apply the ^ operator to other types than integer?

--
Asbjørn Ulsberg -=|=- X-No-Archive: No
"He's a loathsome offensive brute, yet I can't look away"
Nov 15 '05 #1
3 1641
The "^" operator is the "bitwise exlusive OR" operator and has nothing to do
with exponentiation, which I assume is what you want. x * 2 ^ (y / 12) may
compile, but it won't give you the result you're looking for.

Try x * Math.Pow(2.0, y / 12.0) instead.

"Asbjørn Ulsberg" <as*****@tigerstaden.no> wrote in message
news:Xn**********************************@news.onl ine.no...
I'm writing a little C# / DirectSound piano which uses
SecondaryBuffer to play .wav-files. The SecondaryBuffer has a
Frequenzy property which I set to modulate the .wav file into
playing the right note.

The algorithm for a given frequenzy is «x * 2 ^ (y / 12)», where
'x' is the start frequenzy (I use 440 which is A) and 'y' is the
number of half notes from x the given note is. If I am going to
get the frequenzy of a C, the formula would look like this: «440
* 2 ^ (3 / 12)», and the result should be 523,251130601[...]Hz.

But I can't figure out a way to get this algorithm to work. If I
only use integers in the algorithm, it works, but I need a
_much_ higher precision level than int. I would like to use
decimal, but neither that, nor float or double works. I've tried
everything it seems, but nothing works.

How can I apply the ^ operator to other types than integer?

--
Asbjørn Ulsberg -=|=- X-No-Archive: No
"He's a loathsome offensive brute, yet I can't look away"

Nov 15 '05 #2
On 24 Sep 2003 21:40:38 GMT, "=?ISO-8859-1?Q?Asbj=F8rn?= Ulsberg"
<as*****@tigerstaden.no> wrote:
I'm writing a little C# / DirectSound piano which uses
SecondaryBuffer to play .wav-files. The SecondaryBuffer has a
Frequenzy property which I set to modulate the .wav file into
playing the right note.

The algorithm for a given frequenzy is «x * 2 ^ (y / 12)», where
'x' is the start frequenzy (I use 440 which is A) and 'y' is the
number of half notes from x the given note is. If I am going to
get the frequenzy of a C, the formula would look like this: «440
* 2 ^ (3 / 12)», and the result should be 523,251130601[...]Hz.

But I can't figure out a way to get this algorithm to work. If I
only use integers in the algorithm, it works, but I need a
_much_ higher precision level than int. I would like to use
decimal, but neither that, nor float or double works. I've tried
everything it seems, but nothing works.

How can I apply the ^ operator to other types than integer?


You are confused about the ^ operator. ^ is an exclusive or (XOR)
operator, not an exponentiation/raise to a power operator.

C# does not have an exponentiation operator, but it does have a
Pow function in the Math class. Your proper expression should be:

440.0 * Math.Pow(2.0,3.0/12.0)

Oz
Nov 15 '05 #3
On 24 Sep 2003 21:40:38 GMT, "=?ISO-8859-1?Q?Asbj=F8rn?= Ulsberg"
<as*****@tigerstaden.no> wrote:
I'm writing a little C# / DirectSound piano which uses
SecondaryBuffer to play .wav-files. The SecondaryBuffer has a
Frequenzy property which I set to modulate the .wav file into
playing the right note.

The algorithm for a given frequenzy is «x * 2 ^ (y / 12)», where
'x' is the start frequenzy (I use 440 which is A) and 'y' is the
number of half notes from x the given note is. If I am going to
get the frequenzy of a C, the formula would look like this: «440
* 2 ^ (3 / 12)», and the result should be 523,251130601[...]Hz.

But I can't figure out a way to get this algorithm to work. If I
only use integers in the algorithm, it works, but I need a
_much_ higher precision level than int. I would like to use
decimal, but neither that, nor float or double works. I've tried
everything it seems, but nothing works.

How can I apply the ^ operator to other types than integer?


You are confused about the ^ operator. ^ is an exclusive or (XOR)
operator, not an exponentiation/raise to a power operator.

C# does not have an exponentiation operator, but it does have a
Pow function in the Math class. Your proper expression should be:

440.0 * Math.Pow(2.0,3.0/12.0)

Oz
Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: George | last post by:
Hi, I am trying to write a query in Oracle which I have not done before, and are having some difficulty getting my result. Please check my query and my results. select max(note.datetime),...
5
by: me | last post by:
I'm also having problems getting the bulk insert to work. I don't know anything about it except what I've gleened from BOL but I'm not seeming to get anywhere...Hopefully there is some little (or...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
20
by: Alan Silver | last post by:
Hello, I have read about the problems that IE has when using a doctype of HTML 4.01 Transitional. I was advised to use Strict wherever possible. My question is, does the same apply to XHTML...
4
by: sreekant | last post by:
Hi folks I hope someone here might be able to help. I scavenged some info and even code from the net and am trying to write a module that reads a text file and spits out a midi file. So far I...
0
by: Dijkstra | last post by:
Hi! I am writing a program in which I need to keep track of how many objects of a given class exists at a time. The task is to do it using templates. The objects to be counted are of the class Note:...
40
by: Spiros Bousbouras | last post by:
Do you have an example of an implementation where sizeof(short int) does not divide sizeof(int) or sizeof(int) does not divide sizeof(long int) or sizeof(long int) does not divide sizeof(long long...
2
by: teddysnips | last post by:
One of our clients has reported a problem. Everything was working fine on Monday, but since Tuesday all is going wrong. The sysadmin assures me that there have been no changes to the network, or...
2
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in...
5
by: Simon | last post by:
I have problem with namespaces. I have a program that consumes the web service and has for instance names space nsProgram. In this program I have defined several classes that I use for storing and...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.