ATM music delay

Hello! For whatever reason, when I use the arduboy tracker music library the music takes a long time before it actually plays. I’m building off of the atm library example ‘song1,’ is there a way to fix it so it plays instantly?

Hi, that’s a bug in ATMLib. ATMLib2 fixes it (and includes many more bug fixes and improvements). However, the song format is different and not all example songs have been updated to the new format.

1 Like

Will songs made on the ATM tracker editor work with ATMlib2?

Negative, there is an updated version of the ATMLib tracker editor which should work but I am not sure where it is hosted.

1 Like

Dangit, I spent forever on those songs! :laughing: I guess I’ll look for the new editor. Thank you!

If memory serves you can fix the delay by setting the variable ‘cia’ to 1 before starting the song.

1 Like

Do I have to define ‘cia,’ or is it apart of the ATMlib, or how do I access it?

cia appears to be a variable that you cannot modify externally.

In the ATMLib.h, immediately after the void muteChannel(byte ch); line add:

....
void muteChannel(byte ch);
void ATMsynth::setCIA(const uint16_t val);
....

Then in the ATMLib.cpp file, add immediately before void ATMsynth::play(const byte *song) { :

....
void ATMsynth::setCIA(const uint16_t val) { 
  cia = val;
}

void ATMsynth::play(const byte *song) {
...

Now you can do atm.setCIA(0); in you code before you play the tunes. (atm is the variable name of your ATMLib instance).

I haven’t tested this but it should work!

Thanks for the tutorial! I did that, but it didn’t change anything. I put the atm.setCIA(1); before I start the music, but it didn’t fix it. Any insights?

Sorry, I know nothing about the ATMLib … just how to change it to expose the CIA variable. Hopefully @dxb will jump in with a solution.

1 Like

Whoops… I think I got the name of the variable wrong. The variable which should be set to 1 before starting the song is cia_count not cia. This is because cia_count is a counter which is reset to cia when it reaches 0. The bug in ATMlib is caused by cia_count not being initialised to 1, so when it is unconditionally decreased by one and then tested for being ‘0’ it usually ends up being 0xFFFF which means you have to wait for it to reach 0 again before the library advances the song data by one tick hence the delay on startup.

1 Like

Aahh, I think I get it :sweat_smile: I might be able to edit the code to do that, would it be similar to the code @filmote already sent??

Yes, just change:

to

cia_count = val;
1 Like

Will ATMlib2 replace ATMlib library or can both libraries be installed at the sametime?

1 Like

ATMLib2 is a replacement, but as I was answering your question I realised we should consider changing the header file for the C++ interface to ATMLib2.h so it is clear which one is being used.

2 Likes

changing it to cia_count worked!! Thank you so much! :slightly_smiling_face:

1 Like

I half take back my last reply, there’s actually a really strange glitch now. For one of my songs, it makes the song all glitchy, with a louder, slightly behind version fo the song playing at the same time, and with another, all of the tracks are all playing out of sync with each other. The thing is, this glitch only happens when the arduboy is unplugged from its cable.

Should I just look into searching for that ATMlib2 editor?

1 Like

Are you sure the glitches are caused by setting cia_count to 1 once, before starting the song? What happens when you remove the call to setCIA().

Yes, When I get rid of setCIA() the music is delayed again but it plays fine regardless.

By the way, do you know if the ATMlib2 tracker editor was made by @TEAMarg? I’m really hoping to try and fix this music issue as soon as I can :sweat_smile: