Amplifier Circuit

You’ll have to be careful then. If you boost the volume for the STG and @JO3RI driver, any games using normal tones and other music may “blow people’s ears off”.

Keep in mind that, if the library is done properly, the STG/JO3RI driver won’t be compiled if it’s not used in a sketch, thus leaving more space available for application code. Some developers may decide to use simple square wave tones for their sound, to gain more code space, or just because that’s the kind of sound that they want.

Has it been considered there might be a logic error in the library that effects volume?

1 Like

Correct me if I’m wrong but if we use the differential driver then driving with only one pin using standard libraries will be half volume?

The key will be to balance the circuit so its just loud enough but not too loud.

This is a legitimate concern.

If the high-frequency PWM is driving to the voltage rails, then it should be able to generate voltage swings as high as an audio band PWM.

I realize you can’t actually fit a speaker in the Arduboy, but it would be informative to try one of the micro 8-ohm speakers with the various types of sound libraries. If the variation goes away while driving a speaker, that would suggest the difference is due to some feature of your piezo sounder.

Finally, one key feature of a high-frequency PWM module is the ease of making volume changes. It would be wise to be certain that the library that seems too soft doesn’t have a volume setting buried somewhere that has been set to less that unity (full volume).

If you have a detailed level of control, try setting up an audio band square wave PWM at several useful audio frequencies, scattered between 200 HZ and 5000 Hz - the main hearing band. Then use the high-frequency PWM library to produce square waves at the same frequencies. Electrically, the results should be identical. Thus, so should the sound. If they are still different, it’s time to break out the oscilloscope and check output drive levels.

If the square wave sound is the same, but other high-frequency samples are different, then you may be facing a difference problem - namely, that sound loudness is usually proportional to RMS power. Square waves (and audio PWM source) have about 40% more RMS power than an equivalent frequency sine wave (hi-freq PWM sources) , and as a result, will always sound louder. (They will also sound different.)

If that’s what you are encountering, then you have a tough decision to make, because no one solution will give you a consistent audio level between the two types of sources. If the audio PWM is fine, then hi-freq PWM will be lower. If hi-freq PWM is fine, then audio PWM risks being too loud.

I realize that the hi-freq PWM will generate nicer sound - it’s engineered to do that! But hi-freq PWM has to usually use pre-calculated sine wave tables. Those typically drive up the size of the library. That’s a key reason for people looking at this to know how much memory that audio driver takes from program memory and from RAM. Some programs may happily devote that space to the sound library, while other programs might need every last byte of program space they can scrounge for their code and screen data.

If you are going to do a survey, at least include all the relevant information so that any decisions are made while aware of the possible trade-offs.

You can indeed change the volume in the Squawk_TEAMarg library by modifying this line in Squawk.cpp:

// Reset volume
if(ix_period & 0x80) p_osc->vol = p_fxm->volume = 0x20;

Setting it to 0x40 will double the volume, but you will already hear a little bit of saturation when the 4 channels are playing at the same time. That is to be expected: the more channels you have, the less volume each channel must be, which is our problem… but maybe also our solution?

1 Like

It will give half the voltage swing but that may not result in half the volume. A recording of the result of an experiment I did, shifting between single sided and complimentary outputs of square wave tones, can be heard here. More details are in this post.

Note that this result is for the particular piezo speaker and resonator (bottom of a yoghurt cup) that I used. This may not be the same for other speaker circuits.

And also from CPU load/cycles/overhead.

1 Like

I set this to 0x80

And then:

Squawk.tune(4);

And the volume is great but sounds very distorted, could this be fixed?

How about if we modify the library so the user can set the volume parameter dynamically at any time? It could then be set based on the number of channels used, desired volume, distortion tolerance, etc.

The user should also be able to set either single ended or complimentary pin drive. Are we currently using complimentary output, or has it been tried?

Or you play only 1 channel at a time at 100% volume, like in Ölüm Savaşçısı. :yum:

It may be part of a programmers job to do sound design that keeps channel saturation and volume balanced.

However, would it be possible to watch any available channels for activity and attenuate the volume when the channel activity is high? This way the libs actively and dynamically do a little level boost when the hardware allows it?

It’s not really meant to be a sound api for a game, but rather a library to produce mixes.

It seems like this could be a solution, but even when playing individual notes with voices will not sound distorted.

Not really true, this is probably going to be the basis to become our sound API just needs some more work.

I’ve checked that just bringing the tune(4), and setting the volume back down to normal, the volume is about the same as the developer kits. It will probably get bumped up a little from some speaker holes I’m planning on drilling in the board.

Depending on the cost and complexity of adding the amplifier we are looking at adding this guy:

Which will be noted to have a digital volume control for 5, 8 and 11V RMS. The main key for this guy is making sure it fits on the damn board.

1 Like

Here is a sample of some of the speakers I tried… The Piezos are all off to the left actually I realize now I took a shitty picture lol

And just for fun, showing where I buy my arduinos and such

1 Like

Is that 5-10 mA draw while idle?

Jesus christ, possibly.

Will test. That’s a nail in the coffin probably if it’s that bad. Hope not.

I’m hopeful we can actually come up with a software solution like the dynamic volume allocation if the current draw is too much.

Good catch, would have seen it during testing but it’s good to keep an eye out. There is a shutdown pin, but dammit between that and volume we are in danger of running out of GPIO

1 Like

You could also try to put an inductance in parallel with the piezo buzzer (booster coil):

Do not try that with a magnetic buzzer as that will destroy them.

I realize you are really busy balancing a ton of things, but if you’re thinking that this will be the core sound API, then code size really matters a lot!

Don’t forget that just about every devkit game developed so far does NOT use this technique - and a lot of those look pretty good. If you say “ok now use this or your sound won’t sound right” you’re handing a memory bump to every developer whether they like it or not. If the memory hit isn’t too bad, then … ok. But the size of that memory hit is just as important as the quality of the sound; you’re always trading one off against the other.

I didn’t catch the survey you mentioned, but I would be interested in the results. Speaking for myself only, advanced sound like this is a very nice option - as long as it’s an option. On my list of things to try, only about half of them need anything more than an occasional monotone beep. Having to load in a largish sound library to make a beep when using the space for something else is important - like a crypto and USB HID library - could almost be a deal breaker for some apps. (We would likely never know when this happens, because developers typically don’t follow through on projects that run up against that type of limitation in the early stages.)

Meanwhile, some of the other things I see on my list depended on having both an output for tonal sound along with the second output for noise effects and other non-tonal happenings. If you go single-ended – which even the original devkit didn’t do – then you might be making what some consider to be a major change from the original thinking.

(Even an early version of the sound library’s equivalent of this page - https://www.das-labor.org/wiki/AVR-Crypto-Lib/en - where every function has a flash size, ram size, and cycle count would be a valuable contribution to this discussion.)

1 Like

So… what’s the conclusion…? Hardware or Software problem? :grin:

1 Like

Guess the arrival of 5,000 piezo discs means… everything is… good then?

2 Likes