CodeNewbie Community

Sarn Ursell
Sarn Ursell

Posted on

Help needed in reversing the digits of an audio file, -please.

Please let me introduce myself...

My name is Mr. Sarn Richard Ursell, and I am messaging you from Wellington, new Zealand.

I am an avante guard composer of microtonal music and I was heavily influenced by the artists Laurie Anderson, John Cage and Ivor Darreg to name a few, (we will get to more of this later, if need be).

I have now got about 143 projects for manipulating audio and images that I want to do, and initially I had tried to do these in Wolfram Mathematica, but many of the people who I contacted suggested that I use the programming language C.

I heard the advice "use C to alter images and audio" quite a lot!

And so, I am going to have to learn to program in C, as a COMPLETE beginner!

One of the things that I want to do in C is to take an audio object's samples and to reverse their digits, ...-thus a sample depth of 8901 would become 1098, and a sample depth of 12456 would become 65421, -see the pattern?

I am looking at videos about programming in C, and one particular YouTube video for beginners from the Giraffe Academy seemed quite good...

I also am trying to modify the audio using an algorithm for reversing the digits of a number that I got from the GeeksForGeeks website, -however, -here this applies a digit reversal algorithm to a number, but, -personally I wish to do this to a set of audio data's sample's for the WHOLE audio object.

As I mentioned above, I have 143 projects for altering audio and images, which I wish to do, ...(obviously not all at once).

In due course, I will watch, and re-watch the rest of the Giraffe Academy video, and I need some help and suggestions, tips and idea for the audio digit reversal algorithm, indeed, it has been suggested to me that I use a pure sin wave tone...

Some things worth mentioning is that I wish to alter the audio object's samples by taking an absolute value, taking a ceiling value, converting the sample to another base, before reversing the digits.

I thought that we could experiment with all manner of different multipliers, different bases including really exotic ones like 6, 5, 3 16, 17, 18, 23, 56 etc...etc...

Essentially, the process could roughly be:

1.A programmed (scan command) prompt is shown for of the variable Multiplier,

2.A programmed prompt (scan command) is shown for the variable Base_n,

3.Input/import/read the audio file on your computer,

4.Strip off the header and meta data from the audio file getting at/to the raw data,

5.Take an absolute value of the audio file's elements/samples,

6.Take a ceiling value for the audio file's elements/samples,

7.Multiply the audio file's elements/samples by the Multiplier,

8.Take a Base_n calculation of the audio file's elements/samples,

9.Apply the sub-algorithms which reverses the audio file's elements/sample's digits,

10.Output/export/write the now mangled/altered audio file's elements/samples to a specific location on your computer,

11.Repeat steps 5.---> through to ---> 10., -iterativly until finished,

12.Manually take your newly created audio file and input it into an audio editor such as Audacity, and LISTEN TO THE RESULT.

Thus, we have a loop within a loop, -it would appear!


Have I made any errors?

Have I left anything out?

Am I missing something?

I would dearly like to chat with you about these projects and perhaps make new friends and acquaintances, sometime soon!

I look forward to hearing from you!

Please advise,


Mr. Sarn Richard Ursell.

Discussion (2)

djuber profile image
Daniel Uber • Edited

One idea on where to start (which validates that you're able to process the audio file, before deciding how to implement the data transformations) would be to focus on implementing your points 3, 4, and 11 (load file, pass over or process metadata, and loop over the stream of values in the file until done) would be to print the value stream - this is probably the part that's the most involved technically and least interesting to what you're trying to accomplish, since it's audio format specific, with the rest of your proposed project (modifying the values and saving back to another stream) are the parts you're more likely to experiment with continuously and discover as you go. Loading the file, finding the audio data values, and "processing" them one by one (in the empty case just printing these or something else that doesn't alter the input stream) is the framework that's probably going to be constant, and may be the part that's either totally non-interesting to you or possibly frustrating (I would assume this is the part that will probably require the most library use or C specific code, and probably involves looking into the audio format you're using).

Once you have a "do something to each value in the data" loop set up, choosing what to do (some mathematical transformation like base-N digit reversal) seems like it would be easier to add into that framework; more like tinkering with the transformation choices than building a "big project" each time - the audio file processing is more or less constant work, hopefully reusable for all files of the same format for any transformation you're making.

Not sure if that helps, and if you're not comfortable with C or another programming language already, you might find libraries in python that work sufficiently well. C is probably a good tool for the job, but there's a lot of overhead you might be able to avoid using a higher level language. The overhead is mainly in steps 3, 4, and 11 if I understand the problem and guess about what the code will look like when it's working.

If there's already a great library that makes steps 3, 4, and 11 easier for you that's awesome, and then making your inner loop steps 5 through 10 something you can plug into the outer framework (passing a function pointer that takes audio values and returns output values might make sense for that?). If you haven't already looked into this, libsndfile might be a good place to start.

Looking at the Mathematica docs ( for example) it looks like a high level Audio object based on arrays of numbers was already present, almost certainly you'll need to find the library that does this for you in C or read some file format docs to determine how to do it for yourself.

There's no harm (especially if it's not too slow for you) to do this in Mathematica first and only move to C if you need a speed boost or want to do things that aren't made easy there. My assumptions without a lot of experience are that Mathematica will be sufficiently fast for shorter samples and performance may suffer for longer or higher sample rate inputs.

djuber profile image
Daniel Uber

One other small comment that might help would be to add a tag (like help) to your post so it's more discoverable to the community. It helps others get a sense of the technology or problem domain or post type before they commit to reading.