Hello! I am trying to make a software DSP for WAVE PCM sound format (16 bit). The DSP will have the following functionality - change the signal level, add delays and change the frequency. I first started by changing the level by multiplying the bytes with constant, but that didn't work correctly. Here is a picture of what happened:

Update: I find the solution, i was using wrong type variables.
Regards!

Update: I find the solution, i was using wrong type variables.
Regards!
Last edited:
Sample bytes need carry logic when multiplied. Think about how it would work if you lined up the LS byte and MS byte into a 16-bit word, then multiplied it that way. Bit positions with carries need to carry over to the next higher bit. For the simple case of unsigned 16-bit integer multiplication, if bit-15, the most significant bit, needs to carry over to bit-16 (word-length growth occurs) then you have to decide how to handle it. Otherwise it will produce an erroneous result or an exception. For one example, you could clip that sample (set it to the maximum 16-bit sample value).
EDIT: Also, 16-bit audio is normally in two's compliment form. That means two's compliment multiplication may be needed.
https://en.wikipedia.org/wiki/Audio_bit_depth#:~:text=The number of possible values,numbers in two's complement format.
https://pages.cs.wisc.edu/~markhill/cs354/Fall2008/beyond354/int.mult.html
EDIT: Also, 16-bit audio is normally in two's compliment form. That means two's compliment multiplication may be needed.
https://en.wikipedia.org/wiki/Audio_bit_depth#:~:text=The number of possible values,numbers in two's complement format.
https://pages.cs.wisc.edu/~markhill/cs354/Fall2008/beyond354/int.mult.html
Last edited:
That was exactly the problem. Thank you for the clear explanation. Now I'm thinking about the delays. They are also related to the frequency change. Assuming we have two samples A and B, and we want to stretch the wave, then we insert sample C between them, which is a linear interpolation of A and B. This should work? I haven't actually read anything on the subject, yet. I would appreciate some suitable reading material.
There are various ways to do frequency conversion. It may be done with FFTs where frequency shifting can be done by shifting FFT bin values up or down some number of bins, then do an inverse FFT. For more than small frequency changes, particularly for voices, formant preservation may be used to avoid chipmonk and or darth vader effects. If doing frequency conversion in real time, sliding window FFT techniques might be used. There are various books and online resources on how to do these things, the main question being how much you know about it in terms of a starting point. Are you already familiar with sampling, z-transforms, sigma notation, DSP flow graphs, etc.? If not, there are some easier ways to do what you want without starting from scratch. There are already freeware DSP libraries that can run on PCs. OTOH if you want to learn to code it all yourself, and or if there are no libraries for your target processor, then you may have to do more of the work.
Delays can be done with FIFO buffering.
Delays can be done with FIFO buffering.
Last edited:
I have no previous experience. The target platform is PC, so the processing will be done by the CPU. I will try to write the code myself first, only as a last resort I would use a library. The delay will not be fixed, but will vary continuously, relative to both channels. I.e. a sound source moving through space will be simulated.
So, ITD for left/right spatial localization rather than volume panning? Also, spatial perception of depth requires different kinds of cues, HF air lossyness with distance simulation, and changing the reverberant to direct sound ratio (not to mention a good system setup in a good room). And of course moving fast enough would produce audible doppler shifting. A lot of that stuff could probably be done in a DAW using VST plugins with parameter automation.
Exactly. The simulation will be in real time. I'm interested in what it takes to simulate sound coming from behind realistically. I've only seen one good implementation of this effect so far, but I suspect they might just be using different recordings instead of a true simulation.
Look into the HRTF.
Frankly, starting from scratch with DSP is quite hard. I second the recommendation of starting with a library if you must code.
There are quite big barriers to entry: terminology, acronyms, lots of Maths etc... etc....
https://www.dspguide.com/ is a good resource.
Frankly, starting from scratch with DSP is quite hard. I second the recommendation of starting with a library if you must code.
There are quite big barriers to entry: terminology, acronyms, lots of Maths etc... etc....
https://www.dspguide.com/ is a good resource.
Very useful link, thanks. Math is not a problem.
Are there readings on this topic? The nature of the various effects. Would be extremely helpful. On several test recordings that I reviewed, sounds coming from behind are presented only by suppressing high frequencies, which is far from realistic.
HF air lossyness with distance simulation, and changing the reverberant to direct sound ratio
Are there readings on this topic? The nature of the various effects. Would be extremely helpful. On several test recordings that I reviewed, sounds coming from behind are presented only by suppressing high frequencies, which is far from realistic.
Might try this and or its references: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4744263/
Maybe more here: https://www.google.com/search?q=per...AeIDBCBBGADiAwQgRhgAiAYB&sclient=gws-wiz-serp
Maybe more here: https://www.google.com/search?q=per...AeIDBCBBGADiAwQgRhgAiAYB&sclient=gws-wiz-serp
Some of the newer research on localization may be published under the field of Auditory Scene Analysis, rather than under Psychoacoustics.
https://www.google.com/search?q=perception+spatial+localization+in+auditory+scene+analysis&rlz=1C1CHBF_enUS771US771&sxsrf=ALiCzsZqfnS8OXJx829dWNECR5z2VA7oRw:1667840739779&ei=4zppY4aKL4PikPIPipS1UA&oq=perception+spatial+localization+in+auditory+scene+ana&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQARgAMgUIIRCgATIFCCEQoAEyBQghEKABMgUIIRCgATIFCCEQqwI6CggAEEcQ1gQQsAM6CgghEBYQHhAPEB06CAghEBYQHhAdSgQITRgBSgQIQRgASgQIRhgAUOADWKQeYNwtaAFwAXgAgAF8iAH3DZIBBDEzLjWYAQCgAQHIAQbAAQE&sclient=gws-wiz-serp
Also: https://courses.washington.edu/psy333/lecture_pdfs/chapter12_SoundLocalization.pdf
https://www.google.com/search?q=perception+spatial+localization+in+auditory+scene+analysis&rlz=1C1CHBF_enUS771US771&sxsrf=ALiCzsZqfnS8OXJx829dWNECR5z2VA7oRw:1667840739779&ei=4zppY4aKL4PikPIPipS1UA&oq=perception+spatial+localization+in+auditory+scene+ana&gs_lcp=Cgxnd3Mtd2l6LXNlcnAQARgAMgUIIRCgATIFCCEQoAEyBQghEKABMgUIIRCgATIFCCEQqwI6CggAEEcQ1gQQsAM6CgghEBYQHhAPEB06CAghEBYQHhAdSgQITRgBSgQIQRgASgQIRhgAUOADWKQeYNwtaAFwAXgAgAF8iAH3DZIBBDEzLjWYAQCgAQHIAQbAAQE&sclient=gws-wiz-serp
Also: https://courses.washington.edu/psy333/lecture_pdfs/chapter12_SoundLocalization.pdf
- Home
- Source & Line
- Digital Line Level
- Software DSP