[WIP] 4 channel Music

Awesome! Sorry if ya’ll mentioned it, already. I was only skimming the conversation and didn’t see it.

@MLXXXp https://github.com/arduino/Arduino/issues/5648

2 Likes

Can I use tone() while playing music ?

@boochow yeah, but why would you do that, just talk to the oscillator directly.
We’ve added functions to mute/unmute a channel, so you can make game sound effects using the oscillators.

I have submitted the Library to arduino, once it’s in I’ll post a new topic and I will make a dedicated webpage explaining “the what” and “the how”.

Oh I’m interested in how to talk to the osc. what I want to do is to play some sound effects while music track goes on.

@boochow give me some time to write up a small manual on redacted
Once I got everything documented a bit more, I’ll ping you :wink:


Moderator Note:
Links to Team ARG’s website have been removed due to malicious new owners.

@JO3RI, Are you planning to do this? I see that you’ve added mute() and unmute() calls to the ATMlib class but it would be nice if you implemented a global mute that follows the state of the Arduboy, Arduboy2 and Arglib libraries’ audio class by using a callback to the audio.enabled() function, as ArduboyTones and ArduboyPlaytune do.

Great ! I 'm looking for update of the manual. It must be important to use this library for games !

@MLXXXp this mute and unmute is something different. Those function mute 1 of the 4 channels, so that you can use the channel for a sound effect in the game (like shooting). They have nothing to do with the global sound on_off. This is how the Amiga games worked.

Normally global sound on_off should just work, because they set the pins from input to output … (I have to admit, I didn’t have time to test it yet)

@boochow creating those sound effects is up to the game coder, but I’ll provide examples in time.
Oké Oké here is a small example :slight_smile: , only a sound effect, without a timer or muting the channel:

for (int n = 1000; n < 4000; n += 40) {
  osc[CH_ZERO].vol = 63;
  osc[CH_ZERO].freq = n;
  delay(1);
  osc[CH_ZERO].vol = 0;
}

So one would mute the channel, do a sound effect on that channel and unmute the channel again.

@JO3RI Thank you for example code. I just tested this and it works good.

1 Like

The current standard V1.1 Arduboy library’s audio class doesn’t change the speaker pin modes. This was something added in the develop branch and which my Arduboy2 library inherited.

Besides, this was something that was added as a “safety” in the hopes that it would work for non-Arduboy-compliant libraries. There’s still a chance that it won’t work if whatever code generates the sound sets the pins back to outputs.

It’s expected that an Arduboy compliant sound library will initialise and control the speaker pin modes itself and that it will honour the current mute state using audio.enabled().

The bottom line is that although ATMlib works with the current Arduboy library V1.1 (I tried it), it doesn’t handle the standardised audio class muting in this case.

Ok thanks for clearing that out. I’ll look into this and come with a solution. I would prefer that the “main” library is able to set the pins and change their state, because … well those pins will always be the same pins. Maybe this is something we can look into together. BUT before all that, let me do some tests this week.

It’s only when all these small things are solved too, I’ll make a bigger announcement about the library.

But it’s the sound library that actually modulates the pins, so it has to know which ones they are, anyway. On that note, you should be using the defines PIN_SPEAKER_1 and/or PIN_SPEAKER_2 in your library rather than just hard coding them.

The reason that the sound library should be responsible for setting up and controlling the speaker pin modes is because the “main” library may not know how to, for a particular sound library.

For instance, with the current Arduboy hardware it’s possible to set one pin as an output and the other as an “input with pullup” (mode INPUT_PULLUP). If you then toggle only the output pin, the speaker is coupled to the input pin through the built in pullup resistor. This results in a lower volume. I’ve talked about this here. A particular sound library could take advantage of this. However, if the “main” library changes the pin modes each time it changes the mute state, this could screw up this “non-standard” pin configuration that the sound library has set.

I’ve proposed that the next generation Arduboy be based on the Arduino Zero (and I’ve seen hints that it may be). This will mean that there will probably be a true hardware DAC available for sound. Some sound libraries may use this. Others may just toggle the pin digitally as they do now. Again, you don’t want the “main” library messing with the pin configuration that the sound library has set up.

For the above reasons, I’m really tempted to change the Arduboy2 library so that it never touches the speaker pins (or at most just sets them both to outputs once, during boot). Required pin settings would be the sole responsibility of the sound library. The “main” library’s audio class would only logically maintain the global mute state, with no sound hardware control whatsoever. In the future, it’s possible that the audio class could maintain a global volume level, in addition to the mute state, but this would still only provide a volume level value to the sound library, and the sound library would control the hardware to provide this volume, within it’s capabilities.

If I were to make this change to the Arduboy2 library, the ArduboyTones and ArduboyPlaytune libraries would still work fine because they both set the speaker pin modes themselves and use a callback to audio.enabled() to handle global muting themselves, as they see fit.

Ok … Just tested one our games (using ARGlib) that uses the audio.enabled(), arduboy.audio.on() and arduboy.audio.off()
I added a song to the game and included ATMlib … nothing more

and … it just works out of the box, like I thought. The music is completely muted when I select sound Off in our menu.

1 Like

That’s with Arglib and Arduboy2. Did you try it with the Arduboy library?

huh … to be honest I never used the Arduboy Library, but ARGlib was based on it and the only thing I changed was ditching … tunes

It looks like pin control was added to the Arduboy library in March 2016 but only for the development code. Either Arglib is based on a development version or the changes were ported over.

However, as I said above, I’m highly inclined to remove the speaker pin control code from Aruduboy2 so as not to interfere with how some future sound libraries may need to set the pins. I don’t think it should be the responsibility of the main library to control the sound hardware.

Hi,

was wondering if there is a working Web Editor already ready.
And if a Zelda “song.h” is available somewhere?

Thanks,
derchris

1 Like

hi @derchris,

We don’t have a web editor yet … working hard to get something, but with the Holidays coming …

We do have all the examples songs AND we have a WEB PLAYER. You can download this for now (I will add it to our website later) just put the folder somewhere and open the index.html in the Chrome Browser. Now you can just drop a song.h file on it and it will start to play (good for testing)

PS: The Zelda tune playing on an arduboy was made for the OLD SQUAWK Library (witch no longer works …)

1 Like

Hi @JO3RI,

thanks for the quick response.
Yes, I actually tried to flash the demoScene3_AB.ino onto my Arduboy, and it was throwing error after error.
Would it be difficult to port the Melody/Aquawk into the current ATM format?
And how much different is the ATM format from lets say Midi.
Would there be a chance to put together a Midi to ATM converter?

Thanks,
derchris