How to add sound?

Hey everyone –
I’ve been trying to figure out how I might add simple sound effects, and no matter how hard I try, I can’t seem to get even single notes to work. My game feels awfully quiet.
Can someone please explain the playTone and playNote functions to me? The API docs don’t really help much when it comes to these…


Will make some examples for this

Sorry to dig up an old thread … did these examples get made?

Play a sound effect:

Play a melody using an in-build music player in PokittoLib:

These are very simple examples. There are other, more complex, examples in there also.

Thanks @Hanski … I had already tried the PlayMusic example but it does not make any sound.

I have now tried the PlaySFX and it makes a noise - not sure what it is supposed to be but at least it makes one. How are the sound effects for PlaySFX encoded?

Really? Then there has been some regression in PokittoLib then as they both have worked before.

PlaySfx can play RAW 8-bit or 4-bit audio data.

Edit: Also, PlaySfx is also used widely by MicroPython so it should work.
Edit2: Could the problems be related to the audio settings in mySettings.h?

Does PlaySFX work if you play the background music at the same time? You can enable this:

//Sound::playMusicStream("abbaye/music/0_PrayerofHopeN.raw", 0);

You should have The Abbaye Des Morts game in SD to have the audio file, or use your own.
PokittoLib should mix the audio together.

PlaySFX is working but PlayMusic is not.

How are the sound effects for PlaySFX encoded? If it is in RAW format I assume I need to convert it in something like Audacity. What I am rellay trying to do is find the Pokitto equivalent of the Arduboy’s AruboyTones which allows you to create simply music / sound effects using a simple {note, duration} notation.

How did you get it working? What was the problem?

Yes that is a pure RAW format.

I have used the tones as a car motor sound in Pokitto GP here:

Edit: More precisely here:

            m_tonefreq = fix16_to_int(abs(m_fxVel*5));
            if(m_tonefreq>50) m_tonefreq = 50;

I think the snd.playTone() is a wrapper for setOSC() which is more versatile.
m_fxVel is the speed of the car

Sorry I think you misunderstood my first post. PlaySFX was always working but PlayMusic is not. PlayMusic seems to be closer to the ArduboyTones model of {note / duration} pairs.

I will download the game and have a look.

Ok :wink:
I added detailed info in the previous post.

1 Like

There is a playTone function:

…which is sort of just a wrapper for the setOSC function:

…and I think takes note values in this format:

Maybe I am misunderstanding it but that function lets you play one note, not a series of notes like ArduboyTones. To create a sound effect or music with that, you would have to continually poll the sound to see if it is finished before starting the next tone.

I was sort of hoping for a fuction that allows you to point it to an array of bytes.

i ported the arduboy tones lib once

Would you like to use it 1:1?

That could work!

However, if there is a ‘native’ approach I would like to know that too. Although the game I am writing is actually a port from the Arduboy, I hope to write new, unique games soon.

That is exactly what the PlayMusic example, mentioned above, should do.

Yes it looks like what I want - but it doesn’t seem to work for me. If you have time, can you please try the example from the repo and see if it still works for you. Maybe I am doing something wrong - although other than the My_settings.h file and the code itself, I cannot see what I am doing wrong.

If @jonne has already done the work on ArduboyTones - that would be the best approach! Just looking at HWSound.cpp and PokittoSound.cpp is making my head start to hurt… this is what makes working with the Pokitto less appealing to me - the Arduboy2 library has one clear way of doing things, the Pokitto has sooo many ‘modes’ and layers, and swiss-army knives full of ways to approach video and audio! But no equivalent to play a simple sequence of tones? :confused:

1 Like

Message received and understood. We will fix that


Obviously I am new to the environment … but I must agree, the Arduboy library is simple and well documented.

@jonne how do I get my hands on that ArduboyTones port?