convert audacity data to 8 or 16 bit INHX32

Hello. this is the first time I have posted on this site. Thank you for reading my query.

I am using Audacity 2.0.2 and have used its predecessors for several years. I now wish to take advantage of the very low cost of flash ROM to store waveforms as a set of binary values in either 8 or 16 bit numbers. For the purposes of this query, I will refer only to 8-bit numbers, but the principle for 16 remains similar.

The process I wish to undertake is to convert values which are readily obtainable from Audacity.

Normally the Audacity values are in the range minus 1 to plus 1. I wish to translate these into normalised numbers in the range 0 to 255 where 128 is the centre point. These translated values should then be converted into INHX32 codes (such as is standard for many ROM programmers, and is frequently the output code from microcontroller assemblers/compilers such as the PIC series of devices).

I have for some time achieved this objective by a very tortuous 5-step process which only deals with small (32768) volumes of data at a time.

STEP 1. I send a signal to Audacity and normalise it to the range plus and minus one, then export it to a file which I can then input to Microsoft Excel. Unfortunately Excel has a data limit of 32768 items, so this has to be a piecemeal approach.

STEP 2. I use Excel to multiply the values by 128 and then to convert these into hexadecimal.

STEP 3. I export the hexadecimal file to Microsoft Word, and then use various Word features to tidy up the data, insert commas, get rid of unwanted values and also get all the characters into the same font and size (Excel usually varies these for no given reason).

STEP 4. I segment the data and install it into a Microchip MPLAB assembler, which generates the INHX32 code strings.

STEP 5. I pass these strings to a ROM programmer which will program the values into the selected ROM.

Apart from the clumsiness of this long method, there is the snag that only 32Kb can be processed in Excel at any one time.

The ROMs I use are of the A25LQ032 series (and similar types but differing capacities). I have also used Microchip 25LC1024 ROMs.

An 8 Khz sample at eight bits, when packed into this type of memory, can last for up to 62.5 seconds with the 25LC1024, or 500 seconds with the A25LQ032. Improved sample rate or signal resolution will reduce these times proportionately.

What I am looking for is a scheme which can accomplish the STEP 1 to STEP 5 sequence above (by whatever means) so that I have an INHX32 file corresponding to the 8/16 bit normalised data which can then be fed directly to a ROM programmer.

Although I am using the Microchip MPLAB software to produce the INHX32 code because I happen to have it, I am not restricted to this.

I also have a Batronix programmer which operates independently of the Microchip route.

I hope that I have given sufficient information, and not said anything which is confusing or ambiguous. If anyone can assist in this endeavour I shall be very grateful.

Thank you.

Tragic Boffin

I don’t know if this will help you, but standard 8-bit WAV files are unsigned integers with “silence” at 127 (or 128?) and 16-bit WAV files are 16-bit signed integers (-32,768 to +32,767) with silence at zero. If you can strip-out the header (or ignore it), you should be ready to go.

If you export to “Other Uncompressed Files”, and choose “RAW”, you may be able to get exactly what you are looking for.

I’m not familiar with INHX32, but most of this could be accomplished within Audacity using the built in “Nyquist” programming language.
You will find a lot of reference documentation for Nyquist here: https://forum.audacityteam.org/t/manuals-and-reference-material/32817/1

Those are the (actual) 32 bit float values.
For integer formats (usually 8, 16 or 24 bit), the numerical value of the sample is “normalized” to the range -1 to +1 Actually just less than +1 because there are an even number of bits and the “middle” one is at zero (for 8 bit, -128 to +127).

The value of a sample can be read by Nyquist with the command:

(snd-fetch s)

For “valid” audio (not greater than 0 dB) this can be converted to the equivalent integer format arithmetically.

Nyquist also includes several file commands which would allow the converted values to be written to disk as a file.

Nyquist code is written in plain text, which makes it easier to write develop and debug than compiled languages. Have a look at the “sample-data-export.ny” file (in the Audacity Plug-ins folder) as an example.

If this looks like a viable option for you, we have a part of the forum specifically for questions about Nyquist programming: http://forum.audacityteam.org/viewforum.php?f=39

Thank you DVDdoug and steve,

You have kindly provided two solutions, one to do with data export and the other to do with Nyquist.

in order to try the simpler route first, I have tried exporting wav files, and I feel optimistic about this.

I have exported some wav data and been pleasantly surprised that it seems to be accepted by my Batronix programmer. Looking at the (vast) data grid exhibited by the programmer software, I can see data patterns which seem to indicate that the wav data matches the patterns in the audio originally sent from Audacity. I shall know more in a day or so.

I now have to write some test software to read the series of 16-bit components which I shall program into a ROM using the Batronix device. If this works, I shall be very pleased.

Watch this (grateful) space!

I am also interested in the Nyquist route, and will follow this up just to try and expand my knowledge. However, as might be expected in the case of all reward-motivated engineers, I shall go for the wav route for my first shot.

Thank you both, again.

Tragic Boffin