Calculate / Display Byte Offsets in WAV Files by Audacity ?

Help for Audacity 2.x.x on GNU/Linux.

ImageThis forum is for Audacity 2.x.x on GNU/Linux and Unix-like operating systems.
Please state which version of Linux you are using, the exact three-section version number of Audacity from Help > About Audacity... and whether you installed your distribution's release or daily version of Audacity or compiled Audacity from source code.

Audacity 1.2.x and 1.3.x are obsolete and no longer supported. If you still have those versions, please upgrade at https://www.audacityteam.org/download/.
The old forums for those versions are now closed, but you can still read the archives of the 1.2.x and 1.3.x forums.

Calculate / Display Byte Offsets in WAV Files by Audacity ?

Permanent link to this post Posted by Mike2020 » Thu Mar 16, 2017 6:44 am

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.

Mike
Mike2020
 
Posts: 5
Joined: Thu Mar 16, 2017 6:20 am
Operating System: Linux Debian

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by steve » Thu Mar 16, 2017 10:17 am

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".
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45372
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by Mike2020 » Thu Mar 16, 2017 7:35 pm

steve wrote: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

Mike
Mike2020
 
Posts: 5
Joined: Thu Mar 16, 2017 6:20 am
Operating System: Linux Debian

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by steve » Thu Mar 16, 2017 10:27 pm

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:
https://msdn.microsoft.com/en-us/librar ... 36(v=vs.85).aspx
https://en.wikipedia.org/wiki/Resource_ ... ile_Format
http://www-mmsp.ece.mcgill.ca/Documents ... IFFNEW.pdf

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.
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45372
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by Mike2020 » Fri Mar 17, 2017 4:40 am

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 https://www.youtube.com/watch?v=w2FxDswFV8s&list=PL70t2tcMP0hbDb4dLbOBOcTFiZsYy2O5N&index=12) 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.

Regards

Mike
Mike2020
 
Posts: 5
Joined: Thu Mar 16, 2017 6:20 am
Operating System: Linux Debian

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by steve » Fri Mar 17, 2017 2:35 pm

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).
9/10 questions are answered in the FREQUENTLY ASKED QUESTIONS (FAQ)
steve
Site Admin
 
Posts: 45372
Joined: Sat Dec 01, 2007 11:43 am
Operating System: Linux *buntu

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by Mike2020 » Fri Mar 17, 2017 7:02 pm

steve wrote: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.

Regards

Mike
Mike2020
 
Posts: 5
Joined: Thu Mar 16, 2017 6:20 am
Operating System: Linux Debian

Re: Calculate / Display Byte Offsets in WAV Files by Audacit

Permanent link to this post Posted by Mike2020 » Sat Mar 18, 2017 8:26 am

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.

Mike
Mike2020
 
Posts: 5
Joined: Thu Mar 16, 2017 6:20 am
Operating System: Linux Debian


Return to GNU/Linux and Unix-like



Who is online

Users browsing this forum: No registered users and 3 guests