Calculate / Display Byte Offsets in WAV Files by Audacity ?

Hi All,

I am a newbie to sound processing, please excuse silly questions!

I am going to process (play) wav files in a C-programm. Want to activate (play) selected sound sniplets within a longer sound stream. Appropriate sniplets (with a START point and an END point in Byte offsets from the file enty point) I intend to identify by Audacity in this WAV file before.

My simple processing idea: I identify by audacity an appropriate sound sequence and audacity displays the Byte offsets (from the file enty point) to the START of the sequence and the END of the sequence.
These two Byte offstes I will notice (write in a seperate CSV file ? / add to the wav file ?).

In my C-program I will jump the WAV file pointer to the START offset, activate my ALSA based replay routines and stop replaying when the END Byte offset has been reached.

Any good advice how to simplify?
Rough idea myself: I let audacity display the byte offsets of the START point and the END point on my screen and copy them in a CSV file …!

Up to now I have no idea, how I can motivate audacity to show me the Byte offsets in an opened wav file. Are there plugins available?

Better ideas are very welcome!

Thanks in advance.


Have I got this right:

You have some WAV files, and you want to know the number of bytes from the beginning of the file to a specific “start play time”, and the number of bytes from the beginning of the file to a specific “end play time”.

Exactly this I want to figure out! Do you know a solution?

Best regards


Audacity won’t be much help with this because Audacity does not act directly on audio files. Audacity “imports” the audio data (copies the audio data from the file) and acts on the imported data.

WAV files are a form of RIFF file. Detailed information about the format is readily available. Here’s a couple of links to get you started:

In order to work out the correct offset, you will need to know exactly where the wave-data chunk starts.

It would probably be easier if you use raw (headerless) PCM data. In this case, all you need to know is the sample rate and bit format. You can then calculate the offset (in bytes) as follows:

Offset-in-byes = offset-in-seconds x sample-rate x number-of-bytes-per-sample.

Thanks very much for your answer - understood.

Use Case background:

I am a ModelRailway Fan programing radio mobile control of locos. I identify motor sound in YouTube (e.g. howling engines - just take this as an example which I copy on a controlboard. The howling engine at different rpm should become coupled to the rpm of the electromotor engine. This is driven by a Pulse Width Modulation (PWM). PWM has 255 steps.

I intend to identify appropriate sound steps corresponding to the model engine RPM (0% … 100%) in the WAV file by the help of audacity. When controlling the electical engine by PWM I want replay the appropriate sound sniplet from the wav file. Therefore I need the exact byte position which corresponds to the intended PWM level (255 sniplets).

Calulating the offset by your proposed formula is very helpful - thank you, I wonder if the time resolution (microseconds ?) will be unique enough to jump to the before identified zero-crossings of the amplitude in order to avoid any cracks when linking neighboured sound sniplets in my program?

Supposed it is not - can I identify by programming methods (e.g. pattern matching in the wav byte sequences) the most nearby zero crossing amplitude to make up a unique marker?

Hope my language was clear enough to understand.



Is this an Arduino project?
If so, the audio quality is likely to be very poor whatever you do.PWM is a very poor way to encode audio (can be useful as a form of sound synthesis though).

Sorry - PWM is not used for sound - PWM is used for the motor power control!

No it is a Raspberry - Audio is decoded by the BCM processor and ALSA Library.



Actually - I have found a possible doable solution meanwhile:

I can mark a wav files with labels - didn’t know that. The time resolution for the labels is xx.yyyyyy (6 digits after period) which should be a sufficient resolution to refind the time marked postion with time to byte calculation. As labels can be stored in an adjacent .txt ASCII file, I can open the txt file in parallel to the wav file and identify lables - forwarding and backwarding to the relevant relative byte position in the wav files.

This seems a doable approach to start programming with.

Thanks a lot for pushing me into the right direction.