CodeWalrus

Development => PC, Mac & Vintage Computers => Topic started by: unknownloner on January 20, 2015, 06:56:03 AM

Title: Haskell Audio Synthesizer
Post by: unknownloner on January 20, 2015, 06:56:03 AM
I decided I wanted to learn the ins and outs of how audio actually works, and figured I could get some more experience with Haskell at the same time.
Anyhow, here's some code
https://github.com/unknownloner/HaskellSynth

And some sample output (though it's pretty easy to modify it to play something else)
http://z80.ukl.me/rfact.mp3

It's not exactly the most sophisticated synthesizer, but it's something, and is kinda neat to play with it.
I've got basic tones playing, but I want to create an Attack-Decay-Sustain-Release envelope so I can have proper notes. I also want to actually learn more about how sound works so I can create more interesting sounds, like some of the stuff you hear in more modern electronic music, because I still have no idea how :P
I also want to be able to read midi files, and handle the Note On/Note Off events to play an existing midi file.
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 20, 2015, 07:24:34 AM
Oooh, old school sound there :D. You should keep it non-sophisticated :P. What would be cool is if it could produce both 8 bit and 16 bit chiptunes (maybe like the Sega Genesis)

Also reading midi files would be awesome. GXSCC does that but the drums are bad.
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 20, 2015, 02:59:02 PM
I might do some deeper research into the C64's SID and see if I can reproduce that sound, because I like what it can do.
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 21, 2015, 04:50:36 AM
Yeah it would be amazing indeed. :D
Title: Re: Haskell Audio Synthesizer
Post by: novenary on January 21, 2015, 02:47:10 PM
Nice, a chiptunes synth. :D Looking forward to what you can do with it.
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 22, 2015, 02:38:41 AM
Well I may not be the best at composition, but this sounds kinda neat http://z80.ukl.me/test.mp3

EDIT:
Low-pass filter stuff:
http://z80.ukl.me/lfo.mp3
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 22, 2015, 04:17:59 AM
Ooh I like that first one. It would fit well for a space game intro. :) Also interesting effects with the 2nd file :D
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 23, 2015, 02:53:02 AM
I keep using the same note sequences as I add more effects since I don't feel finding more, but it's a nice way to compare old vs new code
For example:
Here's a version of nightmare night from awhile ago when I just started: http://z80.ukl.me/nmn.mp3
Here's a new one with ADSR envelope (and some random values for it that I thought seemed alright): http://z80.ukl.me/nm.mp3
The synths aren't the same though so the style is a bit different.

Also here's a new rainbow factory, again with ADSR envelope
http://z80.ukl.me/rf.mp3

My file names keep getting shorter and shorter.

By the way if anyone has any sequences that might be fun to test with, let me know. As long as it's got sheet music (or a straight up list of notes), and a looping section that isn't too long, I might mess with it. (hint hint DJ_O ;))

EDIT:
lol bass
http://z80.ukl.me/bass.mp3
Title: Re: Haskell Audio Synthesizer
Post by: Yuki on January 23, 2015, 05:07:32 AM
Ooh nice stuff here.
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 24, 2015, 01:37:50 AM
Quote from: unknownloner on January 23, 2015, 02:53:02 AM
I keep using the same note sequences as I add more effects since I don't feel finding more, but it's a nice way to compare old vs new code
For example:
Here's a version of nightmare night from awhile ago when I just started: http://z80.ukl.me/nmn.mp3
Here's a new one with ADSR envelope (and some random values for it that I thought seemed alright): http://z80.ukl.me/nm.mp3
The synths aren't the same though so the style is a bit different.

Also here's a new rainbow factory, again with ADSR envelope
http://z80.ukl.me/rf.mp3

My file names keep getting shorter and shorter.

By the way if anyone has any sequences that might be fun to test with, let me know. As long as it's got sheet music (or a straight up list of notes), and a looping section that isn't too long, I might mess with it. (hint hint DJ_O ;))

EDIT:
lol bass
http://z80.ukl.me/bass.mp3
Unfortunately, I use an emulator so I cannot export note sequences for my songs, not to mention Music 2000 doesn't display note names so I am not very familiar with them.

Anyway your new examples sound nice. With ADSR values, are you able to make notes fade out, by the way? I noticed that you mostly use fade-in.
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 24, 2015, 01:38:48 AM
Yeah I can make them fade out.
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 24, 2015, 02:03:33 AM
Do you think some sort of reverb or echo like in some late NES games would be possible?
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 24, 2015, 02:17:59 AM
Could you link some examples?
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 24, 2015, 02:29:11 AM
https://www.youtube.com/watch?v=JFTy7438H4c

Another example, although it's not a song, but rather a sound effect, is in Journey to Silius title screen when you press Start. Also the intro music has some echo effect it seems.

https://www.youtube.com/watch?v=5GtpJ5xIngo
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 25, 2015, 08:45:27 AM
Not quite sure how this ended up working but kinda fun...
http://z80.ukl.me/notes.mp3

Sine wave with w/period of 0.9 * triangle wave w/period of 1.2 controlling notes

noteFor t = noteFreq (round (ctl t * 2) + 40)
    where ctl t = sineWave 0.9 t * triangleWave 1.2 t
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 26, 2015, 04:42:46 AM
Hmm interesting sound to say the least :P
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 28, 2015, 02:20:45 AM
Waves
http://z80.ukl.me/waves.mp3
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 28, 2015, 03:47:30 AM
Wait, are those generated by your synthetizer or are they pre-recorded wavs with support for WAV files added to your synthetizer? O.O
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 28, 2015, 03:48:17 AM
Generated by my code
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 28, 2015, 04:20:10 AM
That is awesome then. By the way, do you have any plans to use this in a game or something? It would be cool to have a small computer game with old school graphics and sound. Or could this be ported to an old platform?
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 28, 2015, 01:10:56 PM
Old platform: theoretically yes because there is a Haskell compiler which outputs C code, which can then be run on any system that supports C. In practice probably not, because any system GHC can't compile too directly is probably too slow to run it.

I have been wanting to use this to write a demo in the style of those demoscene demos where everything (textures/audio/models) are generated at run time. Generally those are 64K demos, but I can't get that small with haskell so I'd just ignore the filesize. Here's an example btw:
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 29, 2015, 07:29:24 AM
Ah yeah I know some of those. I remember seeing a 4K demo where the music and graphics were the same quality as many recent games. It was incredible. By the way if you ever make such demo do you plan to participate to contests?
Title: Re: Haskell Audio Synthesizer
Post by: unknownloner on January 30, 2015, 05:43:20 AM
This is more me learning how to make nice synths than advances on the actual code, but I started messing around with creating synths with a combination of detuned oscillators, and I also moved into stereo! I messed with the attack to make it act a little like a string instrument I guess, in that it ramps up relatively slowly.
http://z80.ukl.me/nms.mp3

EDIT:
Added some bass
http://z80.ukl.me/nmsb.mp3
Title: Re: Haskell Audio Synthesizer
Post by: Dream of Omnimaga on January 30, 2015, 06:53:42 AM
Ooh, the first one sounds very close to NES. :D

Although you plan to do demos with this, it would be cool if you wrote short covers of my songs :P (eg It's the end of agony intro)