본문 바로가기
프로세싱+아두이노+안드로이드

Arduino Talkie

by YJHTPII 2022. 5. 9.
반응형

a wav file to c code converter

 

https://colinjs.com/wavtocode/wavtocode.htm

 

Help instructions for WAVToCode, A WAV File to C Code Converter

Introduction A freeware application for generating sound data in C code format from WAV files. This application enables you to read WAV audio files and convert them into C code for inclusion in embedded systems projects. I wrote it for an embedded processo

colinjs.com

 

 

Help instructions for WAVToCode, A WAV File to C Code Converter

Introduction

A freeware application for generating sound data in C code format from WAV files.

This application enables you to read WAV audio files and convert them into C code for inclusion in embedded systems projects. I wrote it for an embedded processor project of mine where I wanted to get sound data from my PC, but in a data format suitable for an embedded processor to send to a DAC, that could be included in a C compiler. Having failed to find an existing application suitable for my requirement, I decided to write my own.

Supported WAVE file formats:

Unsigned 8-bit PCM
Signed 16-bit PCM
Signed 24-bit PCM
Extensible format PCM (24-bit)
IEEE floating point 32-bit (read-only)
IEEE floating point 64-bit (read-only)

Number of input channels: 1-8

Bits per sample: 8, 16, 24

Mix output: 1 or 2 channels, 8, 16, or 24 bit

C format:
Interleaved / Separate arrays
Signed / unsigned
8/16/24 bit

Revision History

Installation

Download and unpack the relevant installation file(s):

Windows Download: Install_WavtoCode111_32.zip, Version 1.1.1, updated March 5, 2021, 957 kB (32 bit)

Run setup.exe or Setup.msi to start the installation.

Windows Download: Install_WavtoCode111_64.zip, Version 1.1.1, updated March 5, 2021, 966 kB (64 bit)

Run setup.exe or Setup.msi to start the installation.

Windows Download: Install_WavtoCode111_Both.zip, Version 1.1.1, updated March 5, 2021, 1.9 MB (64 bit) (both 32 bit & 64 bit)

The 32 bit installer is in folder \32\. The 64 bit installer is in folder \64\. Choose the setup files from the relevant folder and run setup.exe or Setup.msi to start the installation.

Always check downloads with anti-virus and anti-spyware tools, you can never be entirely sure what happens to files in transit!!

Target platform: Windows XP, Windows 7 or later, 32 bit or 64 bit. The 32 bit version should run OK on 64 bit Windows. The 64 bit version will only run on 64 bit Windows.

Usage

To open a WAV file, go to the main menu and select "File / Open a WAV file". The waveform of the loaded file will be displayed in the middle pane, with a graph for each channel, and information about the file format in the top panel.

Information Window

The top window shows information about the original WAV file read in, and the WAV format of the mix after generation.

The Information Window shows the technical data for the WAV format, i.e. data size, format, number of channels, number of samples per second, average number of bytes per second, block align, number of bits per sample, container size, data offset and number of samples. If there is Broadcast Wave Format (BWF) data in the original file, then the originator, origin date, origin time and description will also be shown.

Channels

Files containing up to 8 channels may be opened. The channels are shown with the lowest numbered channel at the top down to the highest at the bottom, colour-coded as follows (based on ANSI/CEA-863-A identification for surround sound channels):

WAV Channel Name
Colour
Front Left
White
Front Right
Red
Centre
Green
Subwoofer Frequency or Subwoofer Line-Level Output
Purple
Rear Left or Left Surround (side)
Blue
Rear Right or Right Surround (side)
Grey
Alternative Rear Left or Left Back Surround
Brown
Alternative Rear Right or Right Back Surround
Khaki or Tan
Channel colour coding

Mixing

C code is not generated from the sound file that is read in, but from a mono or stereo mix generated from the original file. This enables you to generate a representative mono mix for an embedded system from a stereo source file, or generate outputs with varying selections from the channels in the original file.

The bottom panel contains several fader controls. There will be one fader enabled for each channel in the original WAV file. A spin control at the top selects which channel is input to the mix, and a spin control at the bottom of the fader selects which channel is the output. Thus if the top spin controls are set to 0, 1, and the bottom spin controls are set to 0, 0, then channel 0 of the mix will be taken from channels 0 and 1 of the original file, in proportion according to the slider setting.

To the right of the faders is a spinner to select the number of channels in the mix (output) - either 1 (mono) or 2 (stereo) are available.

The resolution of the mix may be selected by the dropdown control labelled "No. of bits per channel" as 8 bit, 16 bit, 24 bit (obsolete) - which is in PCM format, or 24 bit - which is in extensible PCM format.

The "MIX" button in the bottom panel will generate the output mix waveform. Alternatively, the menu options "Tools / Mix to Mono" or "Tools / Mix to Stereo" may be used without needing to select the number of channels spinner.

The dropdown control labelled "Autoscale options" has the settings "None", "Auto-limit", and "Normalise", which should be selected before clicking the Mix button. These have the following functions:

"None": The proportions of the inputs in the mix amplitude is controlled by the slider proportions and the resulting sum may overload the dynamic range of the format. The slider settings must be adjusted to avoid overload.

"Auto-limit": The proportions of the inputs in the mix amplitude is controlled by the slider proportions, but if the resulting sum overloads the dynamic range the signal amplitude is automatically adjusted to fit the dynamic range. The mix amplitude can be reduced as desired.

"Normalise": The proportions of the inputs in the mix amplitude is controlled by the slider proportions, and the resulting sum is automatically adjusted to fit the dynamic range exactly.

When you have generated the mix output, you can compare the sound quality by using "Tools / Play original" and "Tools / Play entire mix".

Markers

You set the markers by left clicking on the mix waveform for the start, and right clicking for the end of the selected section. When the markers are set, the "Tools / Play mix between markers" command will play the selection.

Channel information dialog

The channel information dialog, opened from the main menu by Tools/Channel Information, shows information about the channel data in the original WAV file and the mix format. It contains two list views.

The top list view shows, in rows for each channel, the minimum and maximum sample values for the original data and the mix data.

The bottom list view shows, in rows for the original data and the mix data, basic details of the data format relating to the signal data, i.e. the number of channels, the number of bits per sample, the container size, and the specified maximum range of data values for the format. Therefore you can see numerically how the signal range relates to the maximum range.

Saving WAV files

The mix output can be saved as a WAV file by "File / Save Mix as WAV file". You might want to use that to save the mix for future reference. The file format used is based on the selection of the "No. of bits per channel" dropdown selector.

To restore a previously saved mix, open the file, then use the menu command Tools/Mix to Mono, or Tools/Mix to Stereo, according to whether the file is mono or stereo. Set the No. of bits per channel control to match the number of bits per channel of the original. If the file is stereo, set the bottom spin control of the second fader control to channel 1 before mixing.

Saving C files

The "File / Save Marked Section as C code" will save the part of the mix between the markers as C code.

The "File / Save Marked Section as C code" command brings up a dialog box with options for the embedded code output. If the mix is stereo, you have the option of generating arrays in either interleaved format, where alternate elements of the array contain the two channels in pairs, or in separate arrays, where one array contains one channel's data and the second array contains the second channel data. "Interleaved" has no meaning for mono output, as there is only one array containing sample elements for one channel. The data format can be selected to suit the embedded project, as either signed or unsigned data. The range of the data will correspond to whether 8 bit, 16 bit, or 24 bit data was selected. The C code generated has a comment header with information about the sound format, and each row of array data has a comment indicating the array indices, to assist in editing the arrays if necessary.

Note that, apart from the date/time and filename in the header, saved C files will be identical from both the 24 bit (obsolete) format and the 24 bit (extended PCM) formats, since this aspect of the WAV format has no bearing on the saved C data.

If you include multiple saved C files in a project, you will need to rename some of the data arrays from "data" or "data0" and "data1" to avoid compilation errors.

Save as 'C' dialog

Example of C code Output

/**********************************************************************
* Written by WAVToCode
* Date:             Wed Nov 14 09:41:29 AM
* FileName:         stereo_8bit_unsigned_separate_2.C
* Interleaved:      No
* Signed:           No
* No. of channels:  2
* No. of samples:   48651
* Bits/Sample:      8
**********************************************************************/

#define NUM_ELEMENTS 48651

unsigned char data0[NUM_ELEMENTS] = {
128, 128, 128, 128, 128, 128, 128, 128, /* 0-7 */
128, 128, 128, 128, 128, 128, 128, 128, /* 8-15 */
...
126, 126, 126, 126, 126, 126, 125, 126, /* 21096-21103 */
125, 120,  82,  65,  62,  69, 104, 112, /* 21104-21111 */
...
128, 128, 128, 128, 128, 128, 128, 128, /* 48632-48639 */
128, 128, 128, 128, 128, 128, 128, 128, /* 48640-48647 */
128, 128, 128}; /* 48648-48650 */
...
unsigned char data1[NUM_ELEMENTS] = {
128, 128, 128, 128, 128, 128, 128, 128, /* 0-7 */
128, 128, 128, 128, 128, 128, 128, 128, /* 8-15 */
...
191, 184, 187, 188, 178, 164, 155, 145, /* 28288-28295 */
136, 124, 111,  97,  87,  77,  74,  71, /* 28296-28303 */
 62,  67,  69,  61,  58,  68,  82,  89, /* 28304-28311 */
 89,  90,  96, 105, 116, 115, 106, 100, /* 28312-28319 */
102, 109, 110,  95,  80,  87,  92,  90, /* 28320-28327 */
...
128, 128, 128, 128, 128, 128, 128, 128, /* 48632-48639 */
128, 128, 128, 128, 128, 128, 128, 128, /* 48640-48647 */
128, 128, 128}; /* 48648-48650 */


About Dialog

The About dialog, opened from the main menu by Help/About, shows a brief summary of the app version and architecture (32 bit or 64 bit) and a link to the author's web page.

Help

The main menu Help/Help command shows HTML help for the application, which is the same as this help page.

Sample WAV files

High-quality wav files free for use in your audio projects (typically 44100 Hz, Stereo, 16-Bit).
https://freewavesamples.com/

CodePlex Archive: A repository of test audio files in a wide variety of formats.
https://archive.codeplex.com/?p=audiotestfiles

Audio test tones. All files are mono, sampled at 44100Hz, 16-bit.
https://www.mediacollege.com/audio/tone/download/

WAVE files with various data types including multi-Channel Examples.
http://www-mmsp.ece.mcgill.ca/Documents/AudioFormats/WAVE/Samples.html

Wavsource.com Sound Effects.
http://www.wavsource.com/sfx/sfx.htm

Bug Reports

If you use this program, please let me know of any issues you find using the contact form on my web pages:
http://colinjs.com/ or https://colinjs.com/

License

This application is made freely available under the terms of a license based on the new BSD license. This is displayed in the setup program and stored in the License.txt file in the installation folder.

반응형

댓글