Tracker

Libraries, utilities, bootloaders...

Tracker

Postby rodot » Tue Aug 12, 2014 5:10 pm

Today I've been starting to work on the tracker. Java is new to me so I don't progress really fast, yet I already have something working. It's still in early development so all it can do for now is composing and encoding patterns. I did that first as it allows you to make sound effects for your Games.

To understand how the sound library works you can read the Sound wiki page.

Copy and paste the generated code to the beginning of your Arduino Sketch.
To play a pattern named myPattern, use the following at any point of your program.
Code: Select all
gb.sound.playPattern(myPattern, 0);


Code Example
This example plays myPattern when the button A is pressed
Code: Select all
#include <SPI.h>
#include <Gamebuino.h>
Gamebuino gb;

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

void setup(){
  gb.begin();
  gb.titleScreen(F("playPattern Example"));
}

void loop(){
  if(gb.update()){
    gb.display.println(F("Press \25 to play");
    if(gb.buttons.pressed(BTN_A)){
      gb.sound.playPattern(myPattern, 0);
    }
    if(gb.buttons.pressed(BTN_C)){
      gb.titleScreen(F("playPattern Example"));
    }
  }
}


alpha-tracker.PNG
Alpha tracker with the Gamebuino start up sound
alpha-tracker.PNG (30.2 KiB) Viewed 5374 times


Download
GitHub repo
Download ZIP

TODO
* save and open
* instruments, tracks
* audio playback
User avatar
rodot
Site Admin
 
Posts: 1290
Joined: Mon Nov 19, 2012 11:54 pm
Location: France

Re: Tracker

Postby DelphiMarkus » Wed Aug 13, 2014 11:24 am

Hi rodot!

I did some work on the audio playback. It is somehow buggy and lacks some documentation but it generates sound at least (even though it is not correct :D ). Some time ago I ported JSIDPlay2 to Pascal and they are emulating a whole C64 and its SID chip, so they use a cycle based approach on synchonizing the CPU and sound chip (SID) and all the other chips. I thought this might be the right way to go for this tracker to be as closest to the Gamebuino as possible.

Today evening I will work on this playback. But I wanted to show you my progress on that. Maybe you can find the bugs. SoundGenerator.java contains almost everything from Sound.h and Sound.c from GB library.

Bitbucket repository
Last edited by DelphiMarkus on Thu Aug 14, 2014 2:48 pm, edited 1 time in total.
User avatar
DelphiMarkus
 
Posts: 20
Joined: Sun May 04, 2014 7:59 pm

Re: Tracker

Postby jonnection » Wed Aug 13, 2014 1:22 pm

Impressive work DelphiMarkus

I have done a similar emulator myself when I was still trying to do stuff on the Hackvision.

I looked through your code, and was trying to understand how you plan to emulate the sound.

From SoundGenerator.java, line 628, where you generate noise output

Code: Select all
chanOutput[channel] = (byte) (rand % (chanOutputVolume[channel] & 0xff));


If you are directly outputting this sound value you will not get authentic emulation.

This is because on the PC the sound value will go through the DAC and the speaker will get a real analog input.

On the Gamebuino, however, the value is the duty cycle of the (was it 53,6 kHz ? Can't remember offhand. EDIT: 32kHZ) PWM signal.

If you want a faithful emulation of the PWM sound as produced by the Gamebuino, you will have to have emulate a PWM interrupt at 32 kHz that will only output 16-bit HIGH (32767 or however you plan to do it) if duty cycle is in high stage and off, if duty cycle is in low stage. 0xFF value means 100%duty cycle, means HIGH signal all the time. 0x80 means 50% duty cycle etc. This is an additional layer of emulation ON TOP of what you are already doing.

Emulating the atmega chip at 16MHz is irrelevant as long as you keep the track data coming in at equal speed . Emulating the 32 kHz PWM signal is the key to producing 1:1 sound emulation.

And, if I misunderstood your code and you're already doing this somehow, my apologies.

EDIT: here is what PWM sound looks like on an oscilloscope (its from Hackvision, but it works the same way as the Gamebuino). Whats on screen here is the point where a "sawtooth" wave drops from 100% duty down to zero and begins climbing again from zero.

Image
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Tracker

Postby DelphiMarkus » Wed Aug 13, 2014 7:43 pm

Hi!

I'm not emulating the entire AVR but just running the sound generation from Sound.c by simulating the interrupts etc. This is why I ported Sound.c over to Java: not emulating the avr itself. (Not like JSIDPlay2 does as mentioned in first post ;) )
In the end I am running it at 16MHz to get the timing right. I'm not experienced with timers on the avr and actually never used them "manually" (without another arduino library). So I don't know what is exactly going on.
But I obviously forgot that the avr uses pulse WIDTH modulation. I thought that the value OCR2B gets assigned is the value PWM outputs. That's obviously wrong and that's why I wasn't getting anything like a correct output. Now I fixed it. :D

Now I am using a counter to get the PWM duty cycle right. This counter is incremented every clock so it incremented 16 million times a second. When the counter reaches the duty cycle value, the actual sound output is set to -127 (I am using bytes there). Otherwise this value is set to HIGH=127 when the counter hasn't reached the duty cycle value yet.
With this method I am getting somehow the right sounds but arpeggio or tremolo is not working. E.g. the startup sound gets very annoying in the end by just outputting one squeaky note. I am hopeless regarding music I don't even know what these effects do... :lol: But hey, it somehow works. :P

So here is an slightly updated version still containing some bugs. But the output gets closer to the Gamebuino sound. :D


Bitbucket repository
Last edited by DelphiMarkus on Thu Aug 14, 2014 2:48 pm, edited 1 time in total.
User avatar
DelphiMarkus
 
Posts: 20
Joined: Sun May 04, 2014 7:59 pm

Re: Tracker

Postby jonnection » Wed Aug 13, 2014 9:04 pm

Wow, thanks for bursting my eardrums !

I just got "..." and one of the nastiest alarm clock sounds I have ever heard !

I guess playing an actual tracker file is not yet possible ... or have I misunderstood something ? I didn't see any file I/O code.

WBR,
Jonne
User avatar
jonnection
 
Posts: 317
Joined: Sun May 04, 2014 8:21 pm

Re: Tracker

Postby DelphiMarkus » Wed Aug 13, 2014 9:13 pm

Hi!

Sorry about your ears. ;)

No, there is no reading possible yet. This would require a parser etc. I'm not that far yet. ;)
You can change the pattern which is played back continually in GBTrackerPlayer.java in line 129. You need to stop manually. (Good for testing ;) )
Code: Select all
Pattern startupSound = new Pattern(new char[] {0x0005,0x3089,0x208,0x238,0x7849,0x1468,0x0000});
soundGen.playPattern(startupSound, (byte) 0);


I will create a repository tomorrow. So I don't need to post it every time...
The latest version sounds even better. (Got the timing better)

EDIT: 2014-08-14
I tweaked a bit on the timing again and now the output is relatively close to the Gamebuino. I also used (working) resamplers from JSidPlay2 as I have not enough knowledge about audio to create one on my own. These are GPL licensed, so as I put this little player under GPL there should be no problem. :)
I created a Bitbucket repository: Bitbucket repository
User avatar
DelphiMarkus
 
Posts: 20
Joined: Sun May 04, 2014 7:59 pm


Return to Software Development

Who is online

Users browsing this forum: Google [Bot] and 17 guests

cron