Showsamples: View Wave File Sample Data

Feb 21, 2011

Showsamples is a C#.net application which lists exact audio sample data values for any PCM (uncompressed) valid RIFF wave file. Showsamples calculates the minimum and maximum sample values over the range of samples specified for each channel. Only stereo (2 channel) wave files with either 16 bit or 24 bit (signed integer) formats are currently supported, All sampling frequencies are supported.

Showsamples can be invoked from a command line with either no arguments or with one argument. The single argument is used to specify the display form for the sample data. For example:
(arguments are case insensitive).

Showsamples prompts for a user wave file, parses the wave file header to check for validity and displays the first 80 bytes as a hex dump. If for whatever reason the wave header chunks are not properly specified, the application exits. Extra "chunks" (such as "fact" chunks) are ignored.

If the wave file is valid, Showsamples displays all the parameters of the wave file, including the audio duration, number of (2 channel) samples and the byte location in the wave file at the start of the actual samples (i.e. the start of the "data" chunk). Note that the first byte in the wave file is called byte 0x00 which is common usage. The data samples are then read into a memory byte buffer. A SHA-1 hash is then calculated on this sample data and displayed. This is very convenient for checking if actual sample data has been altered, even by a single bit, after any data manipulation, compression-expansion cycles etc. Since the hash value is calculated only on the data samples, any changes to the WAVE header, including addition of extra chunks, will not affect the hash value. The 20 byte SHA-1 hash is displayed in hex.

Next the user is prompted for a start and end sample number which specifies the display range. The corresponding start time and end time in the playback is then displayed to a microsecond. The user is next prompted for displaying the samples to the console.

The samples are displayed in the following format:
[Sample Position]  [Sample#]  [Left Channel Sample Value]  [Right Channel Sample Value]
The sample position is in hex and is referred to the start of the wave file. The channel sample values are displayed in decimal by default but can be changed to hexadecimal with the single command argument.

The maximum and minimum sample values, for the range of samples specified, is next displayed in both decimal and hexadecimal. Finally the user is prompted for outputting the sample data including the file information to a text file. The file name is created as [originalwavefilename].txt

Download Showsamples.exe Version 1.1.1.0 (32,624 bytes)        Detailed Example





An example of the console output for a 24bit/96kHz stereo wave file is shown below with the default decimal format:

C:\....\desktop>Showsamples

Enter WAVE filename to view:  wav24_96_440_440.wav
Output file: Sam_wav24_96_440_440.txt

WAV header preview  [80 bytes]
52  49  46  46  3C  AC  07  01  57  41  56  45  66  6D  74  20
28  00  00  00  FE  FF  02  00  00  77  01  00  00  CA  08  00
06  00  18  00  16  00  18  00  03  00  00  00  01  00  00  00
00  00  10  00  80  00  00  AA  00  38  9B  71  64  61  74  61
00  AC  07  01  00  00  00  00  00  00  2B  9B  02  2B  9B  02
"data"  [64 61 74 61]

Skipping 24 bytes in fmt chunk ..

This appears to be a valid RIFF WAV header

Sampling Frequency: 96000     Bits Per Sample:  24
Channels: 2    nBlockAlign: 6   wavdata size: 17280000 bytes
Duration: 30 sec      Samples: 2880000    Time between samples: 0.0104 ms
Byte position at start of samples: 68 bytes  (0x44)


SHA-1 hash of the sample data chunk is:
D1 12 E2 4C 43 C0 1C 3E 21 62 40 A5 3E CB EE E1 23 69 82 B2

Enter start sample to display (1 to 2880000):  2500
Enter final sample to display (1 to 2880000):  2550
Time of chosen start sample: 26.031 ms
Time of chosen final sample: 26.552 ms

Display data on console?  y

24 bit max possible value is:  8388607  (0x7FFFFF)
24 bit min possible value is: -8388608  (0x800000)

Displaying samples in decimal

     Byte(hex)      Sample #        Left Channel       Right Channel
         3AD6          2500            1699560             1699560
         3ADC          2501            1535221             1535221
         3AE2          2502            1369609             1369609
         3AE8          2503            1202861             1202861
         3AEE          2504            1035115             1035115
         3AF4          2505             866512              866512
         3AFA          2506             697189              697189
         3B00          2507             527289              527289
         3B06          2508             356951              356951
         3B0C          2509             186317              186317
         3B12          2510              15528               15528
         3B18          2511            -155272             -155272
         3B1E          2512            -325944             -325944
         3B24          2513            -496346             -496346
         3B2A          2514            -666337             -666337
         3B30          2515            -835775             -835775
         3B36          2516           -1004520            -1004520
         3B3C          2517           -1172432            -1172432
    ......
         3BDE          2544           -4914656            -4914656
         3BE4          2545           -5008250            -5008250
         3BEA          2546           -5097690            -5097690
         3BF0          2547           -5182903            -5182903
         3BF6          2548           -5263817            -5263817
         3BFC          2549           -5340367            -5340367
         3C02          2550           -5412488            -5412488
     Byte(hex)      Sample #        Left Channel       Right Channel

Left Channel Max:
Position: 3AD6          Sample: 2500          Value: 1699560    (0x19EEE8)
Left Channel Min:
Position: 3C02          Sample: 2550          Value: -5412488   (0xAD6978)

Right Channel Max:
Position: 3AD6          Sample: 2500          Value: 1699560    (0x19EEE8)
Right Channel Min:
Position: 3C02          Sample: 2550          Value: -5412488   (0xAD6978)

Write output to file?  y
Creating file with sample data ...