Sound Library

Libraries, utilities, bootloaders...

Sound Library

Postby rodot » Fri May 02, 2014 12:34 pm

The purpose of this topic is to discuss features of the sound library. The purpose of the library is to easily play chiptunes and sound FX in games.
Disclaimer : what's described here is what is planned to be done, not what the current library is capable of.

How it works:
There is 57143 interrupts per second (I determined this with complicated calculation, trust me). At each interrupt, it write a different PWM value on the speaker output to generate a waveform (or a sum of waveform as there is several channels). At every frame (20 times/s), it update the waveform desired.

There is between 0 and 4 channels (set at compilation time to spare resources).
- each channel can play one track
- each channel can be set to loop or not

A track is made of notes.

Note are made of:
-Pitch
-Duration in number of frames. One frame = 1/20s by default. For 150bps, a quarter should last 8 frames.
-Instrument (not included in the library so each game will have its own instruments)
-Volume

Instruments are made of:
-Volume envelope
-Pitch envelope
-Waveform: square wave or almost-white noise
-Loop value, which determine how many steps should be looped if the duration of the not is longer than the duration of the instrument. 0 to disable looping.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Sound Library

Postby hrangan » Fri May 02, 2014 10:23 pm

rodot wrote:There is 57143 interrupts per second (I determined this with complicated calculation, trust me).

Is this 57143 the number of interrupts just for the audio library, or is it what the entire system is capable of handling?
User avatar
hrangan
 
Posts: 58
Joined: Thu Mar 20, 2014 9:35 pm
Location: Bangalore, India

Re: Sound Library

Postby erico » Fri May 02, 2014 11:36 pm

can´t wait till a tracker shows up, or we get to be able to use some tracker formats. ;)
User avatar
erico
 
Posts: 671
Joined: Thu Mar 27, 2014 9:29 pm
Location: Brazil

Re: Sound Library

Postby rodot » Sat May 03, 2014 2:29 pm

hrangan wrote:Is this 57143 the number of interrupts just for the audio library, or is it what the entire system is capable of handling?

As I said I determined this value myself... it's the lower interrupt frequency possible but with the highest note pitch accuracy (up to B5). You can see the worse note accuracy over the pitch range vs OCR (interrupt frequency = cpu freq/OCR).

Note pitch error vs OCR (red: max error, blue: avg error)
note_pitch_accuracy_vs_ocr.png
note_pitch_accuracy_vs_ocr.png (13.19 KiB) Viewed 8281 times

I picked the lone red point on the bottom left because it has a pretty good worse accuracy (0.6% err avg, 1.7% err max) for a low interrupt frequency (OCR = 280 => freq = ~57142.9Hz). BTW you can observe the funny pattern about the pitch accuracy on the right part of the plot. Pitch accuracy vs interruption frequency is far from linear as you can see. That was an interesting optimization to do.

Not sure if what I'm saying is clear, but it doesn't matter. Just trust me, it's the right frequency.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Sound Library

Postby martinsustek » Sun May 04, 2014 9:06 am

What about different waveforms? I mean square wave with different 0 to 1 ratio, triangle wave, sine wave. It makes a little difference in sound but I don't know if it will be hearable on gamebuino.
For example Uzebox has possibility to create own waveforms (just arrays of 8 bit samples which is played at a given frequency. Not real sine computation.

And what about sound samples?

Pitch envelope of instrument means tremolo?

From what you wrote it looks like a good synthetizer. How many bits does PWM have?
martinsustek
 
Posts: 19
Joined: Wed Mar 12, 2014 7:30 pm

Re: Sound Library

Postby rodot » Sun May 04, 2014 7:14 pm

The advantage of square waves it that it needs less interrupts, meaning more free CPU time for the game. I think it's enough for most of people, but of course we could make and "extended" sound library which features different waveform like the uzebox.

Playing raw sound sample probably won't be be included in the default library (at least not for now). You might want to take a look at this post, where Myndale streams raw sound from the SD card.

Yeah, you could do tremolo with pitch envelope.

PWM is 8 bit (as it's PWM from the Arduino), which means 256 different output value.
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Sound Library

Postby DFX2KX » Tue May 06, 2014 12:27 pm

Well, from the sounds of it, you should be able to get near midi-quality music out of Gamebuino. An update rate of 20fps should be able to give you pretty clear 150-200 beat-per-minute chip tunes without too much trouble.

I assume you'd implement any sound effects as C code, right? if so, you could get tricky and write code to 'translate' Mobinagi music tracks (which have a technical name I can't remember, used to have a music editor that would output them) If you could, then folks could use the same tools Mabi people use to make music sheets for their lutes.

Making sound effects, though, is a bit more challenging.
DFX2KX
 
Posts: 250
Joined: Mon Apr 14, 2014 3:48 am

Re: Sound Library

Postby cyberic » Thu May 08, 2014 6:01 pm

Hello!

* Do you have any idea of how the tracker will look like?
* Will we be able to compose directly on the gamebuino?
* Will it be possible to get more than 4 channels, even id there is less notes or effects?

I have a suggestion for instrument looping:
It would be great to be able to do normal loop, or 'ping-pong' loops

Thx
cyberic
 
Posts: 27
Joined: Thu May 08, 2014 5:36 pm

Re: Sound Library

Postby cyberic » Fri May 09, 2014 3:50 pm

Hello!

* Can you tell us if you plan to code a tracker to compose directly on the gamebuino, or if it will be done with an external tool?

* Is the limit on 4 channels compulsary? would it be possible to add more channels if there are fewer notes and effects?

* And finally, for instrument looping, could you give the choice between normal looping and ping pong looping?

Thank you!
Eric
cyberic
 
Posts: 27
Joined: Thu May 08, 2014 5:36 pm

Re: Sound Library

Postby rodot » Mon May 12, 2014 6:13 am

For now the tracker is an excel sheet, but I think it shouldn't be too difficult to code a tracker on Gamebuino. Still I think it would be more handy to compose on actual tracker and then convert to Gamebuino format ^^

4 channels is not compulsory... but the more channels you have, the lower is the volume of each of them. And it will consume more RAM and CPU. Usually 1 or 2 channels should be enough for games if you don't play music during game (it quickly gets annoying anyway).

Ping Pong looping... any other experienced chiptune composer would like too see this feature implemented ?
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Next

Return to Software Development

Who is online

Users browsing this forum: No registered users and 21 guests

cron