|
Forum Index : Microcontroller and PC projects : CMM2: finding ticks in play sound
| Author | Message | ||||
| datawiz Newbie Joined: 10/08/2020 Location: United StatesPosts: 26 |
I've growing quite fond of the CMM2's play sound features, and while tinkering with trying to figure out how to best utilize it, I thought about using 'settick' to run at an interval (500 ms) and do basic audio stuff as a background task. I wrote some code to do that and play an increasing tone based on a counter. I expected to hear a slow rising tone, and it does that but there's an audio ticking going on before the sound increases. I figured this may be a byproduct of running it in an interrupt, so i wrote the loop to play in the main code and I still get ticking. Here's something you can test with: dim testmode% = 1 dim sflag1% = 500 if testmode% = 1 then settick 500,soundfx,1 end if cls do color rgb(rnd()*255,rnd()*255,rnd()*255) print chr$((rnd()*93)+33); ' play outside of interrupt, still get a tick? if testmode% <> 1 then play sound 1,B,S,sflag1%,25 sflag1% = sflag1%+1 if sflag1%>1000 then sflag1%=500 pause 400 end if pause 100 loop ' play sound in an interrupt, hear a tick. sub soundfx play sound 1,B,S,sflag1%,25 sflag1% = sflag1%+1 if sflag1%>1000 then sflag1%=500 end sub set testmode% = 1 to play sound in an interrupt, or any other value to play it inside the loop. Both methods produce an audible tick. Am I doing something wrong, or is this expected behavior for play sound? If so, ss there a way to reduce/remove the ticking? Thanks, Rich/dw |
||||
| hitsware2 Guru Joined: 03/08/2019 Location: United StatesPosts: 734 |
With either SINE or TRIANGLE there is an audible 'click' at the onset of the sound . This is not unusual with many synths . It is due to a fast attack on the envelope and no 0 crossing ( the sound turns on during a non 0 value in the waveform ) Using SQUARE or SAWTOOTH will mask the click . my site |
||||
| datawiz Newbie Joined: 10/08/2020 Location: United StatesPosts: 26 |
Thank you for that explanation, that makes sense. I haven't done much with sound programming in the past, so I wasn't sure if this was normal or otherwise. I'll play around with different waveform types as I experiment more with sound. Thanks, Rich/dw |
||||
| capsikin Guru Joined: 30/06/2020 Location: AustraliaPosts: 342 |
When I was trying to make a rising or falling square wave sound and wanted it to sound clean, I found I needed to have the frequency and number of seconds it was playing for multiply to a whole number. In your case it's playing for half a second at a time so the frequency needs to be an even number (multiple of 2) I tried it with your code and it fixed the tick, so it does work with sine waves too. I replaced sflag1% = sflag1%+1 with sflag1% = sflag1%+2 For my chirps program I included a function to round the frequency, I haven't tried it in other programs. function fixcycles(freq,t) 'new value for freq that gives a whole number of cycles in time t. 'integer number of cycles cycles% = freq * t / 1000 if cycles% < 1 then cycles%=1 fixcycles=cycles% * 1000 / t end function You give it a frequency and a number of milliseconds you want to play it for, it gives you a different frequency to play instead. |
||||
| capsikin Guru Joined: 30/06/2020 Location: AustraliaPosts: 342 |
This suggests if you can fix the click when you change sounds, you could fix the click at the starting and stopping of sounds by raising and lowering the volume over time instead of starting at full volume and stopping instantly from full volume. |
||||
| capsikin Guru Joined: 30/06/2020 Location: AustraliaPosts: 342 |
edited to add: another option would be to change how long you play the sounds for. |
||||
| hitsware2 Guru Joined: 03/08/2019 Location: United StatesPosts: 734 |
> frequency and number of seconds it was playing > for multiply to a whole number. I need to digest that ..... my site |
||||
| hitsware2 Guru Joined: 03/08/2019 Location: United StatesPosts: 734 |
audible 'click' at the onset of the sound . This is not unusual with many synths . It is due to a fast attack on the envelope and no 0 crossing ( the sound turns on during a non 0 value in the waveform ) Using SQUARE or SAWTOOTH will mask the click . This suggests if you can fix the click when you change sounds, you could fix the click at the starting and stopping of sounds by raising and lowering the volume over time instead of starting at full volume and stopping instantly from full volume. BBCBasic ENVELOPE my site |
||||
| capsikin Guru Joined: 30/06/2020 Location: AustraliaPosts: 342 |
> for multiply to a whole number. I need to digest that ..... I didn't explain that well, I've got two explanations that may make more sense. First explanation: The sound needs to play for a whole number of waves, not get cut off when it's played an extra half a wave, for example (I'm not sure I'm using the term "wave" correctly though. I could say "cycles" instead). Second explanation, just uses examples. If the sound plays for 1/2 of a second at a time, the frequency needs to be a multiple of 2. If the sound plays for 1/10 of a second at a time, the frequency needs to be a multiple of 10. If the sound pays for 1/50 of a second at a time, the frequency needs to be a multiple of 50. |
||||
| hitsware2 Guru Joined: 03/08/2019 Location: United StatesPosts: 734 |
> for multiply to a whole number. I need to digest that ..... I didn't explain that well, I've got two explanations that may make more sense. First explanation: The sound needs to play for a whole number of waves, not get cut off when it's played an extra half a wave, for example (I'm not sure I'm using the term "wave" correctly though. I could say "cycles" instead). Second explanation, just uses examples. If the sound plays for 1/2 of a second at a time, the frequency needs to be a multiple of 2. If the sound plays for 1/10 of a second at a time, the frequency needs to be a multiple of 10. If the sound pays for 1/50 of a second at a time, the frequency needs to be a multiple of 50. That makes sense for turning off .... But not for turning on ... You may be on to something though I had some frequency dependent artifacts happen ... I'll go back my site |
||||
| capsikin Guru Joined: 30/06/2020 Location: AustraliaPosts: 342 |
> for multiply to a whole number. I need to digest that ..... I didn't explain that well, I've got two explanations that may make more sense. First explanation: The sound needs to play for a whole number of waves, not get cut off when it's played an extra half a wave, for example (I'm not sure I'm using the term "wave" correctly though. I could say "cycles" instead). Second explanation, just uses examples. If the sound plays for 1/2 of a second at a time, the frequency needs to be a multiple of 2. If the sound plays for 1/10 of a second at a time, the frequency needs to be a multiple of 10. If the sound pays for 1/50 of a second at a time, the frequency needs to be a multiple of 50. That makes sense for turning off .... But not for turning on ... You may be on to something though I had some frequency dependent artifacts happen ... I'll go back It might work for turning the sound on or off, but it was initially used for replacing the sound with a new sound, when I'm changing the frequency. Which means I need to change the first explanation: The sound needs to play for a whole number of cycles, so it ends at the same part of the cycle that it starts (and the same part that the next one starts at) Edited 2020-09-02 11:42 by capsikin |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |