Author Topic: Music using Freq(  (Read 11941 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Music using Freq(
« on: November 01, 2010, 11:05:07 pm »
Hello: Which frequencies using the Freq( command correspond to which notes?
Like which frequency would give a middle C, or what would give an A sharp, etc...

Also, for time, how much equals a second, and how much equals half a second, etc...

Also, is it possible to play chords and hold notes longer then what I get when I input 65535 for time?

My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Music using Freq(
« Reply #1 on: November 02, 2010, 12:35:56 am »
Untested, but based on the source code provided, it looks like it's 47·n + 59 clock cycles per iteration (or on the 84+, 47·n + 61 in RAM, 55·n + 70 in a Flash app.)  Each iteration is only half a cycle of your square wave, though.  So if you wanted to play a tone of 440 Hz, you'd want the frequency parameter to be ((6,000,000 / 880) - 59) / 47 = 144.

For the time parameter, figure each tick is about 47/6 = 7.8333 microseconds, so a second would be 128,000 ticks.  This will vary depending on the frequency parameter, though.  (If you want to play notes longer than 65536, I think it would work so long as you ensure that the time parameter is a multiple of twice the frequency parameter.  Or maybe 1 less.)

Since it's all based on the CPU clock, your mileage will vary - you won't get perfectly precise hardware-independent tones in any case.  Still, you might want to experiment a little.

No, you can't play chords with that routine.
« Last Edit: November 02, 2010, 01:13:25 am by FloppusMaximus »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Music using Freq(
« Reply #2 on: November 02, 2010, 12:43:42 am »
Something I noticed is that when alternating between some notes extremly fast, back and forth, it sounded a bit different from regular square waves. More like Final Fantasy 1 NES style than SMB1.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Music using Freq(
« Reply #3 on: November 02, 2010, 06:06:34 pm »
Untested, but based on the source code provided, it looks like it's 47·n + 59 clock cycles per iteration (or on the 84+, 47·n + 61 in RAM, 55·n + 70 in a Flash app.)  Each iteration is only half a cycle of your square wave, though.  So if you wanted to play a tone of 440 Hz, you'd want the frequency parameter to be ((6,000,000 / 880) - 59) / 47 = 144.

For the time parameter, figure each tick is about 47/6 = 7.8333 microseconds, so a second would be 128,000 ticks.  This will vary depending on the frequency parameter, though.  (If you want to play notes longer than 65536, I think it would work so long as you ensure that the time parameter is a multiple of twice the frequency parameter.  Or maybe 1 less.)

?
I'm sorry - I barely understood that - it was too complex for me.
Do you think it's possible for you to churn out a few nice and simple formulas where I can plug in whatever hertz I want to output the frequency value I should put in?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Music using Freq(
« Reply #4 on: November 02, 2010, 08:30:16 pm »
I'm not sure what the actual tones correspond to, but I have been using the wavelength column of this table which seems to give pretty good results.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Music using Freq(
« Reply #5 on: November 02, 2010, 10:00:17 pm »
Funny, you're right, the wavelengths in that table are close to the values you want (though unless I've made a mistake somewhere, they're actually off by about an octave.)

If f is your frequency in hertz, and t is your duration in seconds,

frequency parameter (or I guess wavelength parameter would be a better name), k = ((3000000 / f) − 59) / 47
or k ≈ (63830 / f) − 1.3

duration parameter, d = t · 6000000 · k / (47k + 59)
or dt · 127660 · (k / (k + 1.3))
(or for low frequencies, dt · 127660)

and if you want to play a continuous tone using two 'Freq' commands, make sure that for the first command, d is a multiple of 2k.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Music using Freq(
« Reply #6 on: November 02, 2010, 10:02:51 pm »
I bookmarked that page. It might be useful when I start messing with Freq(.

Offline LordConiupiter

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 339
  • Rating: +3/-0
  • Just one of the thousands of Axe-fans...
    • View Profile
Re: Music using Freq(
« Reply #7 on: November 03, 2010, 11:17:58 am »
perhaps frequency could be overloaded with another parameter type? because it we have not so many tones we can access right now, and i think we just only use the Freq( command to play music with normal tones.
Example:
Code: (Axe) [Select]
.for a low A sharp
Freq(^A,1
.for a high B flat
Freq(vB,5
.for a central C
Freq(-C,3
everytime that I was down, you would always come around, and get my feedback on the ground. (modified part from 'Seasons in the sun')

No matter how many errors are bothering you, always try to stay rel-Axe!

The HoMM project will be resumed as soon Axe 1.0.0 will be released!
Projects:
Code: [Select]
HoMM:   [==--------]    Project 'resumed': I'm suffering overwhelming new ideas being popped up in my dreams :P
tiDE:   [----------]    Explored and understood the main part of the code: just started writing a Tokenizer.



password of the week: uvanapererubupa (Any pronunciation is the right one ;) )   :D click me, and you'll be raided :D

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Music using Freq(
« Reply #8 on: November 03, 2010, 03:12:59 pm »
perhaps frequency could be overloaded with another parameter type? because it we have not so many tones we can access right now, and i think we just only use the Freq( command to play music with normal tones.

I'm not sure if this'll be a good idea - you can use Freq( for sound effects, which requires more granular control, plus I think that might be a bit difficult to parse.

So question: How does my computer play chords when I'm listening to music?  Is it possible to do something similar on-calc?
Another question: Is it possible to control volume on the calculator?
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: Music using Freq(
« Reply #9 on: November 03, 2010, 03:29:41 pm »
So question: How does my computer play chords when I'm listening to music?  Is it possible to do something similar on-calc?
Another question: Is it possible to control volume on the calculator?

You can use Axe to play fake chords: play the notes of a chord in succession quickly with no breaks in between.

There is sadly no volume control on calc, afaik (even with assembly)

ASHBAD_ALVIN

  • Guest
Re: Music using Freq(
« Reply #10 on: November 03, 2010, 03:31:36 pm »
Yeah, with assembly all we are doing is sending value through the link port in a certain way -- the port isn't built with a way to recieve or handle volume requests :P

EDIT: oh and the chords sound decent, but not perfect -- kinda spasmism if you listen closely, but otherwise acceptable
« Last Edit: November 03, 2010, 03:32:17 pm by ASHBAD_ALVIN »

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Music using Freq(
« Reply #11 on: November 03, 2010, 08:12:15 pm »
Actually, volume can be controlled (to a point) by altering the duty cycle.  The duty cycle is how long the pulse lasts relative to the period of the pulses.  If anyone remembers the old Freq() command when it first came out in Axe, it was much softer because it had a much smaller duty cycle.  I do not have a control for the volume in the Freq() command because it would make the routine much larger.  Some sound players even have a separate routine for every possible volume in the duty cycle to speed it up for some decent quality audio.
« Last Edit: November 03, 2010, 08:12:23 pm by Quigibo »
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Music using Freq(
« Reply #12 on: November 03, 2010, 08:57:14 pm »
I'm not sure what the actual tones correspond to, but I have been using the wavelength column of this table which seems to give pretty good results.

Nice, a coincidence? And so that's why the docu says Freq(wavelength,time).




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Music using Freq(
« Reply #13 on: November 03, 2010, 11:56:55 pm »
Yeah, with assembly all we are doing is sending value through the link port in a certain way -- the port isn't built with a way to recieve or handle volume requests :P

EDIT: oh and the chords sound decent, but not perfect -- kinda spasmism if you listen closely, but otherwise acceptable
Really? I migth have done something wrong, or maybe it was Wabbitemu, because in my case it sounded like static or something metallic when alternating between notes too fast :(. It has been ages since I last tried, though.

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Music using Freq(
« Reply #14 on: November 04, 2010, 07:30:33 pm »
Tangentially related to this, I made a sort of piano/wind instrument sort of thing.

Turn the calc sideways, and press any of the keys from [2ND] to [STO>]
They're both C's, so [ALPHA] would be D, [MATH] would be E, etc...
If you press the left and right arrows (well, actually up and down from the sideways perspective), the range goes up and down by an octave (indicated by the number on the screen.
Pressing the other two buttons moves the range by a whole note (the letter on the screen indicates which note [2ND] is on.
For sharps, press the key over the appropiate one (C sharp is [MODE], the key above [2ND], which is C)
It works well in the middle region, but sounds weirder if you go too high or low.

(Wow - that was a long and complicated explanation.  But it's intuitive - just turn the calc on the side, try pressing the closest 2 row of keys and the arrows keys and experiment)

I compiled w/ Axe 0.4.5 - the file is source code.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.