Sound testing

Understanding the language, error messages, etc.

Re: Sound testing

Postby Myndale » Tue Mar 03, 2015 4:16 am

NicK wrote:Anyway - one thing I've noticed with the sound is that if you load the game from a file it works (Simbuino) but if you reload using CTRL+F5 then sound doesn't work.


I think you'll find that's been fixed in the most recent update, if not then pls let me know.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Sound testing

Postby NicK » Thu Mar 12, 2015 2:26 am

Myndale - it does indeed work - that's cool.

Can ANYBODY tell me how to program sound???????

const uint16_t testpatter[] PROGMEM = {0x0005,0x3089,0x208,0x238,0x7849,0x1468,0x0000}

I've tried messing with these numbers. The results make NO sense. Is there anyone that can just explain it so I don't have to waste the next year?

I don't want Jean-Michel-Jarre just how to put 2 or 3 notes together of variable duration?

PLEASE?????
NicK
 
Posts: 27
Joined: Tue Dec 23, 2014 11:25 pm

Re: Sound testing

Postby Myndale » Thu Mar 12, 2015 4:04 am

Best place to start is with the Gamebuino -> Intermediate -> Music example. Rodot creates 4 tracks (one per channel), each track references an index in the patternSet which in turn references the patterns.

As far as I'm aware a pattern is an array of 16-bit words of the following format:

Code: Select all
MSB             LSB
pppppp dddddd w vvv

Key:
     v: volume, 0-7
     w: waveform (0=square wave, 1=noise)
dddddd: duration, 0-63 (number of frames).
pppppp: pitch, 0-58 from A#2 to D#8, 63 is mute.


There are some more details on the wiki sound page.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Sound testing

Postby NicK » Fri Mar 13, 2015 12:15 am

Myndale - once again thanks for your help. Your status is legendary. I don't know what we'd do without you.

What you described is not stated anywhere in the reference WIKI, so thanks.

Nick.
NicK
 
Posts: 27
Joined: Tue Dec 23, 2014 11:25 pm

Re: Sound testing

Postby Myndale » Fri Mar 13, 2015 12:25 am

Thanks Nick :) Yeah, I wasn't able to find that in the wiki either, had to hunt and peck through the source code to get it.
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Sound testing

Postby NicK » Fri Mar 13, 2015 12:33 am

That's where we differ Myndale. I don't have the intellect to work this out!
NicK
 
Posts: 27
Joined: Tue Dec 23, 2014 11:25 pm

Re: Sound testing

Postby NicK » Fri Mar 13, 2015 3:20 am

So I think that I can clarify as below:

p p p p p p v v v w d d d d d d
128 64 32 16 8 4 2 1 128 64 32 16 8 4 2 1
32 16 8 4 2 1 32 16 8 4 2 1

i.e. a hex word 0x0000 is made up of 00 which is the duration - can go to FF or 255, and the second 00 which is the pitch. This is 2 bits displaced and therefore FC is the MAX (which is mute). As far as I can see the 4 bits in the middle make NO difference.

I can't get the diagram above to show properly.

Any ideas why the pitch bits have to be 2 to the right?
NicK
 
Posts: 27
Joined: Tue Dec 23, 2014 11:25 pm

Re: Sound testing

Postby Myndale » Fri Mar 13, 2015 5:12 am

Sorry Nick, I think I was looking at the effects code when I wrote that. I've just knocked up a quick sample, this should make things a lot easier:

Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

#define NOTE(pitch, duration) ((uint16_t)duration << 8) + ((uint16_t)pitch << 2)
#define PAUSE(duration) NOTE(63, duration)
#define END() 0x0000

enum NOTE
{
  _Bb2, _B2, _C3, _Db3, _D3, _Eb3, _E3, _F3, _Gb3, _G3, _Ab3, _A3,
  _Bb3, _B3, _C4, _Db4, _D4, _Eb4, _E4, _F4, _Gb4, _G4, _Ab4, _A4,
  _Bb4, _B4, _C5, _Db5, _D5, _Eb5, _E5, _F5, _Gb5, _G5, _Ab5, _A5,
  _Bb5, _B5, _C6, _Db6, _D6, _Eb6, _E6, _F6, _Gb6, _G6, _Ab6, _A6,
  _Bb6, _B6, _C7, _Db7, _D7, _Eb7, _E7, _F7, _Gb7, _G7, _Ab7, _A7,
  _Bb7, _B7, _C8, _Db8, _D8, _Eb8
};

const uint16_t p00[] PROGMEM =
{
  NOTE(_G3, 8),  PAUSE(1),
  NOTE(_G3, 8),  PAUSE(1),
  NOTE(_G3, 8),  PAUSE(1),
 
  NOTE(_Eb3, 6), PAUSE(1),
  NOTE(_Bb3, 2), PAUSE(1),
  NOTE(_G3,  8), PAUSE(1),
 
  NOTE(_Eb3, 6), PAUSE(1),
  NOTE(_Bb3, 2), PAUSE(1),
  NOTE(_G3,  8), PAUSE(1),
 
  PAUSE(8),
 
  NOTE(_D4, 8),  PAUSE(1),
  NOTE(_D4, 8),  PAUSE(1),
  NOTE(_D4, 8),  PAUSE(1),
 
  NOTE(_Eb4, 6), PAUSE(1),
  NOTE(_Bb3, 2), PAUSE(1),
  NOTE(_G3,  8), PAUSE(1),
 
  NOTE(_Eb3, 6), PAUSE(1),
  NOTE(_Bb3, 2), PAUSE(1),
  NOTE(_G3,  8), PAUSE(1),

  END()
};
               
const uint16_t* const patternSet[] PROGMEM = {p00};

const unsigned int track1[] PROGMEM = {0, 0xFFFF};

void setup(){
  gb.begin();
  gb.sound.changePatternSet(patternSet,0);
  gb.sound.playTrack(track1,0);
  gb.sound.command(CMD_INSTRUMENT, 1, 0, 3);
}

void loop(){
  if(gb.update()){
  }
}


*Sorry if I'm a few keys off...I'm in a rush to get out the door :)
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Re: Sound testing

Postby NicK » Fri Mar 13, 2015 1:23 pm

Myndale - both amazing cool AND really useful. Seriously helpful. Thanks so much.

You're ONE note off, but we'll let that slide! :lol:

Second to last should be - it's a G flat

NOTE(_Eb4, 6), PAUSE(1),
NOTE(_Bb3, 2), PAUSE(1),
NOTE(_Gb3, 8), PAUSE(1),

I'd like to request that your example gets added to the Example Libraries

Cheers,

Nick
NicK
 
Posts: 27
Joined: Tue Dec 23, 2014 11:25 pm

Re: Sound testing

Postby Myndale » Fri Mar 13, 2015 8:36 pm

Don't forget that the durations are number of frames, so if you need more accuracy with the timing then you can bump up the frame rate with a call to gb.setFrameRate().
Myndale
 
Posts: 507
Joined: Sat Mar 01, 2014 1:25 am

Previous

Return to Programming Questions

Who is online

Users browsing this forum: No registered users and 13 guests

cron