Author Topic: Audio Programming From Scratch  (Read 2976 times)

0 Members and 3 Guests are viewing this topic.

L0rd_M@dness

  • Guest
Audio Programming From Scratch
« on: July 23, 2013, 02:52:51 am »
Yup; I wanna code music! xD
I did some research on this, so to start with:
Codes a MIDI creator, and writes music to MIDI file using C++: http://www.youtube.com/watch?v=6PFf6klllAE
OpenAL, obviously: [size=78%]http://connect.creativelabs.com/openal/default.aspx[/size]
A simple beep in C++: [size=78%]http://stackoverflow.com/questions/4060601/make-sounds-beep-with-c[/size]
Also using the Beep() function from windows.h


However, none of those were what I was looking for. To start with, I want to make the computer beep using the piezo buzzer (I'm actually not sure if computers use piezo buzzers to beep when speakers are not available), and make beep music using various frequencies & durations. Then move on to more advanced stuff.


I appreciate any of evilzoners' help in introducing me to some resources. :)
Oh, and I preferably want to stay away from libs (and trackers are out of context) to begin with... just for the sake of learning.
« Last Edit: July 23, 2013, 03:30:29 am by L0rd_M@dness »

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Creating Music Programmatically
« Reply #1 on: July 23, 2013, 03:16:23 am »
You better learn java then as it will give you a good start for audio programming. Also creating music programmatically sounds a bit odd and should be said as Audio programming. The thread title is misleading.
"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

L0rd_M@dness

  • Guest
Re: Audio Programming From Scratch
« Reply #2 on: July 23, 2013, 03:33:10 am »

Changed title.I know java, but I don't see how Java specifically is suitable for audio programming. Can you elaborate a bit on that?

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Audio Programming From Scratch
« Reply #3 on: July 23, 2013, 06:28:31 am »
I think I know what you're talking about... you cannot make the computer beep if it does not have a microphone for audio signals. And only desktops would have it.

To make the computer beep, try Pascal. I have been coding in pascal for few years and used this for audio signals: http://www.freepascal.org/docs-html/rtl/crt/sound.html

Ask here if you'll need help :)

L0rd_M@dness

  • Guest
Re: Audio Programming From Scratch
« Reply #4 on: July 23, 2013, 07:12:18 am »
I think I know what you're talking about... you cannot make the computer beep if it does not have a microphone for audio signals. And only desktops would have it.

To make the computer beep, try Pascal. I have been coding in pascal for few years and used this for audio signals: http://www.freepascal.org/docs-html/rtl/crt/sound.html

Ask here if you'll need help :)
I assume by 'Microphone' you mean 'Speaker' am i right?

It's surprising how few articles are available about this (or I just can't google right :P )
After some more research I found out that there's no piezo buzzer, it's a basic internal speaker that works independent from the sound card (which is probably what you meant). What I don't get is: 1. How would it function without a soundcard? 2. How to access it instead of external speakers? 3. How come it only beeps?


Oh, the doc says "On Windows the frequency is ignored :(" means no music! :( Just sound
« Last Edit: July 23, 2013, 08:29:48 am by L0rd_M@dness »

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Audio Programming From Scratch
« Reply #5 on: July 23, 2013, 08:23:04 am »
Lol sorry, yes I meant the speaker.
The speaker is independant because it is build that way. For sound card you need drivers and the pc speaker is controlled directly from the mobo. Thats why it is used for audio signals such as error beeps and whatnot on mobo system check.

The speaker can emit any kind of sound. Its kike saying that a piano can only make a note... Pascal and probably other langs can make the beep at different freqsand when they are timed you get some sort of music...

I will post more when I get home in the evening :P

L0rd_M@dness

  • Guest
Re: Audio Programming From Scratch
« Reply #6 on: July 23, 2013, 09:24:35 am »

Well, I made some sort of sound (can't call it music yet), but it's more like someone dialing a number on a digital home phone with a rhythm. :P
Here's the code if anyone is interested (It's better if you're not) (You've been warned, the sound is Not pleasant!)

Code: [Select]
#include <windows.h>
int main()
{


Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Sleep(200);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Sleep(200);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(800,150);
Beep(800,150);
Beep(900,150);
Beep(600,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(800,150);
Beep(800,150);
Beep(900,150);
Beep(600,150);


Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Sleep(200);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Sleep(200);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(800,150);
Beep(800,150);
Beep(900,150);
Beep(600,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(600,150);
Beep(600,150);
Beep(700,150);
Beep(800,150);
Beep(800,150);
Beep(900,150);
Beep(600,150);


return 0;
}

This C++ code will compile on windows only, but the pascal version of the same code will compile on everything except windows :P  For linux, gcc I believe has beep() and sleep()...

Now what I don't understand is the delay between each beep. It's really annoying.
Also the Beep sound will just be played through regular speakers in a laptop. On desktops, it'll probably be played through the internal pc speakers, but I haven't tested.
« Last Edit: July 23, 2013, 09:29:02 am by L0rd_M@dness »

Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
Re: Audio Programming From Scratch
« Reply #7 on: July 23, 2013, 09:41:39 am »
Make it beep dubstep!


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA

Offline Psycho_Coder

  • Knight
  • **
  • Posts: 166
  • Cookies: 84
  • Programmer, Forensic Analyst
    • View Profile
    • Code Hackers Blog
Re: Audio Programming From Scratch
« Reply #8 on: July 23, 2013, 12:20:14 pm »
Changed title.I know java, but I don't see how Java specifically is suitable for audio programming. Can you elaborate a bit on that?

I am talking about this :- http://www.jsresources.org/faq_audio.html#dataline_notification
http://docs.oracle.com/javase/1.4.2/docs/guide/sound/programmer_guide/contents.html

"Don't do anything by half. If you love someone, love them with all your soul. When you hate someone, hate them until it hurts."--- Henry Rollins

Offline Kulverstukas

  • Administrator
  • Zeus
  • *
  • Posts: 6627
  • Cookies: 542
  • Fascist dictator
    • View Profile
    • My blog
Re: Audio Programming From Scratch
« Reply #9 on: July 23, 2013, 08:44:52 pm »
Pascal does indeed compile on Windows, and FPC is a cross-platform compiler.
Here you can try this code I wrote some time back, it should work if your desktop has a hardware speaker in the box:

Code: (pascal) [Select]
program speaker;
uses Crt;
var note : integer;
begin
note := 1;
while note <> 500 do
  begin
    writeLn('Groju ',note,' tona');
    sound(note);
    delay(100);
    noSound;
    note := note + 1;
  end;
readLn;
end.
Or download the compiled version: http://upload.evilzone.org/download.php?id=7614772&type=zip

There was also a link posted on evilzone that I can't find. It was a tool to generate glitchy music by typing in commands.

L0rd_M@dness

  • Guest
Re: Audio Programming From Scratch
« Reply #10 on: July 23, 2013, 10:23:37 pm »
It does compile on windows, but instead of generating a hardware beep, "a system sound is played and the frequency parameter is ignored".
I have a laptop which probably does not have a hardware speaker at all, so probably that's the reason.
C++ Beep() though, does still produce a BEEP sound instead of a system sound, like the pascal program and cout << "\a"; do, but it's not the most pleasant beep sound (not at least as good as the one I remember from my PC).
In any case, I think I've had my dose of experimenting with the beep. Learning about MIDI right now.

[/size][/font]
Make it beep dubstep![/font]

Is this you: http://www.dj-rapture.com/
« Last Edit: July 23, 2013, 11:37:51 pm by L0rd_M@dness »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Audio Programming From Scratch
« Reply #11 on: July 24, 2013, 06:14:55 am »
http://jugad2.blogspot.nl/2013/04/pysynth-pure-python-music-synthesizer.html

No exactly scratch but its lower level and better than beeps.
Check out its source code and you just might learn something.
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline techb

  • Soy Sauce Feeler
  • Global Moderator
  • King
  • *
  • Posts: 2350
  • Cookies: 345
  • Aliens do in fact wear hats.
    • View Profile
    • github
Re: Audio Programming From Scratch
« Reply #12 on: July 24, 2013, 09:02:58 am »
This is all crap. Forests Mims can help you a lot here. You need to know how amplifiers work along with some PWM. Grab a few 555 timers and learn from the source.
>>>import this
-----------------------------

Offline hanorotu

  • Dj Rapture
  • VIP
  • Majesty
  • *
  • Posts: 1173
  • Cookies: 98
  • ( ͡° ʖ ͡°)
    • View Profile
    • Rapture
Re: Audio Programming From Scratch
« Reply #13 on: July 24, 2013, 03:02:42 pm »
Is this you: http://www.dj-rapture.com/

No, I am the US "Rapture" It was DJ Rapture but I stopped dj'ing so now it's just Rapture. www.youtube.com/djrapturemusic
« Last Edit: July 24, 2013, 03:03:12 pm by hanorotu »


Life is hard, then you get buried.
If you want to use my work all of my music is licensed under GNU General Public License v3 (GPL-3) - http://bit.ly/TfUOBA

L0rd_M@dness

  • Guest
Re: Audio Programming From Scratch
« Reply #14 on: July 27, 2013, 09:20:00 am »
This is all crap. Forests Mims can help you a lot here. You need to know how amplifiers work along with some PWM. Grab a few 555 timers and learn from the source.
I've made chiptune with piezo buzzer & arduino before, so I wanted to repeat the same experience on a computer then move on to more advanced stuff (amplifiers etc).
Which I kinda did... even though the sound was horrible and not as good as the piezo buzzer at all (maybe if I run it on a pc rather than a laptop I'll get a better noise since they have the hardware speakers)
I'm learning about MIDI right now, not sure if it's the perfect 2nd step, but whatev.