Inferno #01
31 декабря 2000

For Coderz - The Muse from PC (description of audio file formats).

<b>For Coderz</b> - The Muse from PC (description of audio file formats).
  Description audio formats

        File samples

          (Sample)


Search and edit by Penetrator (VFHB)
Add by Shaitan / Stars of Keladan


 This document describes the file formats
Sound samples for the IBM PC, which
You can use our privacy policy on your favorite
Spectrum. Information for the preparation of this document were 
obtained from various sources, so the author is not responsible 
for the errors or the accuracy of the assumption in

compiling this document.

 Let's first understand, sho si Take
is zvekovaya sampling.
 "Sample" - a value that is input to DAC or obtained from the 
ADC, usually an integer (either 8 or 16 bits).

Sampling characterizes the amplitude of the signal. The 
frequency of sampling is determined by the issuance of 
kilohertz (KHz), or samples / second. In addition, the sample 
may to go from one channel (mono) or two

(Stereo), or ..., a greater number of channels. Thus, in order 
to play sample except her own, you need to know:


- The number of bits per sample (8 / 16 bit, maybe up to 32 
bits); - Sampling rate (5KHz/44KHz, possibly

up to 48KHz);
- Number of channels (1/2-mono/stereo possibly up to 4 
channels). 


 There are three types of file format samples, with
extensions:
 . SAM,. RAW - just a sampling, you must
know what part of her play.
 . WAV - this format from Microsoft.
 . VOC - it's from Creative.



        R A W - format


 Now, guided by the above-described
perametrami, we are able proigrovat data samples.
 If the sample is stereo, which means that
first byte is the first channel, then
the second, and if more channels, then bytes is located 
respectively on the rising number of the channel. Frequency is 
characterized by the issuance of two bytes per second. For 
stereo left channel - the first.  Knowing Specifies the 
settings for some . RAW file, you will be able to play it 
correctly. 



        W A V - Format



  This is a RIFF file, which was developed
by Microsoft. It is used in Windows. Therefore it is very 
"popular." It is similar to AIFF - format Apple, which is used 
for storing high quality audio tools, it is also used by SGI. 
It is similar, but not compatible. 

At first comes the title RIFF file:

typedef struct {

        char id [4];
/ / File ID = "RIFF" =
/ / 0 x 46464952

        long len;
/ / Length of the file without this header
} IDRiff;


   Sam WAV-file can consist of several pieces and these pieces 
may contain a few samples, or some other information. But this 
is only theory at the moment we file with the

so perverted not met, therefore - and part of a sample of one.

 Title piece WAV:

typedef struct {

        char id [4];
/ / Id = "WAVE" = 0x45564157

        char fmt [4];
/ / Id = "fmt" = 0x20746D66

        long len;
/ / Length of this piece of WAV - file
} IDChuckWave;

Behind him is not mediocre piece WAV:

typedef struct {

   int type;
/ / - The type of audio data, is -!
/ / 1 - just a sampling;
/ / 0x101 - IBM mu-law;
/ / 0x102 - IBM a-law;
/ / 0x103 - ADPCM.
int channels;
/ / Number of channels 1 / 2 -!
long SamplesPerSec;
/ / Sampling frequency
long AvgBytesPerSec;
/ / Frequency of issuance of bytes
int align;
/ / Alignment
int bits;
/ / Number of bits per sample -!
} IDWave;

Marked with - are especially needed.
Further, the identifier of the sample:

typedef struct {

        char id [4];
/ / Id = "data" = 0x61746164

        long len;
/ / Length of sample (a multiple of 2)
} IDSampleWave;

Samples in the piece may be several.

Example program for viewing WAV:

# Include 
# Include 

typedef struct {

        char id_riff [4];

        long len_riff;


        char id_chuck [4];

        char fmt [4];

        long len_chuck;


        int type;

        int channels;

        long freq;

        long bytes;

        int align;

        int bits;


        char id_data [4];

        long len_data;
} TitleWave;


void main

        (Int argc, char * argv [])
{
FILE * f;
TitleWave tw;

if (argc <2) {printf ("Specify a name. wav

   file \ n "); return;}
f = fopen (argv [1], "rb");
if (f == 0) {printf ("Could not open file

   -% S \ n ", argv [1]); return;}
fread ('& amptw, sizeof (TitleWave), a, f);
fclose (f);
printf ("LEN RIFF \ t-% ld \ n",

   tw.len_riff);
if (strncmp (tw.id_riff, "RIFF", 4), = 0)
printf ("did not match the ID

   RIFF \ n ");
printf ("LEN Chuck \ t -% ld \ n",

   tw.len_chuck);
if (strncmp (tw.id_chuck, "WAVE", 4), = 0)

        printf ("did not match the ID

   CHUCK \ n ");
if (strncmp (tw.fmt, "fmt", 4), = 0)

        printf ("did not match the ID

   FMT \ n ");
printf ("Type \ t \ t -% d \ n", tw.type);
printf ("Channels \ t -% d \ n", tw.channels);
printf ("Sample Per Sec \ t-% d \ n",

   tw.freq);
printf ("Bytes Per Sec \ t -% d \ n",

   tw.bytes);
printf ("Bits \ t \ t -% d \ n", tw.bits);
printf ("Aligned \ t \ t -% d \ n", tw.align);
printf ("LEN Data \ t -% ld \ n",

   tw.len_data);
if (strncmp (tw.id_data, "data", 4), = 0)

        printf ("did not match the ID

   DATA \ n ");
}



        V O C - Format


Header. Voc:

typedef struct {

        char txt_id [20];
/ / "Creative Voice File \ x1A"

        unsigned int offset_data;
/ / Offset to the first block of data

        unsigned int ver;
/ / Version number

        unsigned int id;
/ / ID number of complementary
/ / Version number plus 1234h, ie
//(((~ Ver) +0 x1234) '& amp0xFFFF) == id
} VocHeader;

 Then there are blocks of data. They are divided into
subblocks of different types. Structure of the sub-blocks of 
data: 

Sub-block of audio data:

typedef struct {

        unsigned char type;
/ / Type of subblock

        unsigned long len;
/ / Length of the subblock (read only need to
/ / The first 3 bytes)
} VocBlock;

 Next come the data sub-block. Depending on the type of 
sub-blocks are different. Here Several types of sub-blocks:


type = 0. Ends a block of data.


type = 1. Sub-block of audio data:


 In this case, the length of the sub-block, you subtract two to 
get the length of the sound data.


The title of this sub-block.

typedef struct {

        unsigned char rate;
/ / Sample rate, as a team
/ / 40H

        unsigned char type_zip;
/ / Packaging method 0 - Not packaged
} VocBlock1;

Next come the audio data.

type = 2. Subblock continuation of sound

       Data:

Just the sound data.

type = 3. Subunit of silence


typedef struct {

        unsigned int time;
/ / Time of silence

        unsigned char rate;
/ / Sample rate, as a team
/ / 40H
} VocBlock3;

type = 4. Subunit marker


unsigned int marker; / / marker

type = 5. Sub-block text messages


 Text data, ending with zero

type = 6. Poblok sound cycle


unsigned int count_repeat;
/ / Number of repetitions minus one

type = 7. Subblock end audio cycle


 No data

type = 8. Subblock advanced configuration


typedef struct {

        unsigned int rate;
/ / Sample rate, as a team
/ / 40H
/ / Mono: 65536 - (256000000/rate)
/ / Stereo: 65536 - (25600000 / (2 * rate))
unsigned char pack;
/ / Packaging method 0 = unpacked
unsigned char mode;
/ / Mode: 0 - mono, 1 - Stereo
} VocBlock8;


Example program to show VOC:

# Include 
# Include 

typedef struct {

        char txt_id [20];
/ / "Creative Voice File \ x1A"

        unsigned int offset_data;
/ / Offset to the first block of data

        unsigned int ver;
/ / Version number

        unsigned int id;
/ / ID number of complementary
/ / Version number plus 1234h, ie
//(((~ Ver) +0 x1234) '& amp0xFFFF) = id
} VocHeader;

typedef struct {
unsigned char type;
/ / Type of subblock
unsigned long len;
/ / Length of the subblock
/ / (You need only read the first 3 bytes)
} VocBlock;

typedef struct {
unsigned char rate;
/ / Sample rate, as a team
/ / 40H
unsigned char type_zip;
/ / Packaging method 0 - Not packaged
} VocBlock1;

typedef struct {
unsigned int time;
/ / Time of silence
unsigned char rate;
/ / Sample rate, as a team
/ / 40H
} VocBlock3;

unsigned int marker;
/ / Marker
unsigned int count_repeat;
/ / Number of repetitions minus one

typedef struct {
unsigned int rate; / / frequency
/ / Sample rate, as a team 40H
/ / Mono: 65536 - (256000000/rate)
/ / Stereo: 65536 - (25600000 / (2 * rate))
unsigned char pack; / / packaging method
/ / 0 = unpacked
unsigned char mode; / / Mode: 0 - Mono
/ / 1 - Stereo
} VocBlock8;

void main

        (Int argc, char * argv [])
{
FILE * f;
VocHeader vh;
VocBlock vb;
VocBlock1 vb1;
VocBlock3 vb3;
VocBlock8 vb8;
unsigned int rate;

if (argc <2) {printf ("Specify a name. voc
file \ n "); return;}
f = fopen (argv [1], "rb"); if (f == 0) {
printf ("Could not open file -
% S \ n ", argv [1]); return;}
fread ('& ampvh, sizeof (VocHeader), a, f); if (
strncmp (vh.txt_id, "Creative Voice
File \ x1a ", 19), = 0)
{Printf ("Neto name \ n"); goto Fin;}
printf ("Creative Voice File \ t -
v% u.% 02u \ n ", (vh.ver>> 8) '& amp0xFF,
vh.cer '& amp0FF);
printf ("Start \ t \ t \ t -
% Xh \ n ", vh.offset_data); printf ("
Identifier \ t \ t
-% Xh \ n ", vh.id);
if ((((~ vh.ver) +0 x1234) '& amp0xFFFF)! = vh.id)
{Printf ("not matched \ n"); goto Fin;}

fseek (f, vh.offset_data, SEEK_SET);
while (1)
{
fread ('& ampvb, sizeof (VocBlock) -1,1, f);
vb.len '& = 0xffffffL; / / the first three bytes
if (ferror (f)! = 0)
{Printf ("Error reading \ n"); goto Fin;}
switch (vb.type)
{
case 0: printf ("The End. \ n"); goto Fin;
case 1: printf ("Sound:");
fread ('& ampvb1, sizeof (VocBlock1), a, f);
rate = (unsigned
int) (one million / (256-vb1.rate));
printf ("rate -% u, packing -% u,
len -% lu \ n ",
rate, vb1.type_zip, vb.len-2);
fseek (f, vb.len-2, SEEK_CUR);
break;

case 2: printf ("Continuation of sound:
% Lu \ n ", vb.len);
fseek (f, vb.len, SEEK_CUR);
break;


case 3:
fread ('& ampvb3, sizeof (VocBlock3), a, f);
printf ("Silence: time -% u, frequency -
% U \ n ",
vb3.time, vb3.rate);
break;

case 4:
fread ('& ampmarker, 2,1, f);
printf ("Marker -% u \ n", marker);
break;


case 5:
printf ("Text length -% lu \ n", vb.len);
break;

case 6:
fread ('& ampcount_repeat, 2,1, f);
printf ("Repetition -% u \ n",
count_repeat-1);
break;

case 7:
printf ("End of reps \ n");
break;

case 8:
fread ('& ampvb8, sizeof (VocBlock8), a, f);
rate = (unsigned
int) (256000000L / (65536L-vb8.rate));
printf ("Set-up: frequency -% u,
packaging -% u, mode -% s \ n ",
rate, vb8.pack,
vb8.mode == 0? "mono": "stereo");
break;
default:
printf ("T -% d ?????? \ n", vb.type);
fseek (f, vb.len, SEEK_CUR);
break;
}}

Fin:
fclose (f);
}






Other articles:

Others - overview Computer Profi OS and CP / M.

Others - Questionnaires: Sharing useful information.

Others - Russian Rulez: Elbrus - the description of the new processor developed by Russian engineers.

Interview - Jerri / Alien Factory: How did the game Walker.

For Coderz - Ports PC Profi.

For Coderz - The Muse from PC (description of audio file formats).

For Coderz - Pro ROM 48k Spectrum (# 0000 - # 1FFF).

For Coderz - Pro ROM 48k Spectrum (# 2000 - # 3FFF).

Shelezyaka - the prefix to the phone: the phone line signal amplifier.

Shelezyaka - ADC izngutri: simple analogotsifrovoy converter.

Gameland - game review Project-X.

Inferno - The authors.

Inferno - Intro.

Inferno - Managing zhunalom.

Softinka - ZX Word Updated: New, but not quite, a text editor.

Softinka - Extractor: software to extract the files from the Spectrum emulyatorskih formats.

Softinka - a review of programs for testing drives, as well as setting the magnetic head drives.

Humor - Unfiltered: marasmic real ads and statements of people both famous and not so out of "Crocodile".

Soap - Foam: e-mail section.


Темы: Игры, Программное обеспечение, Пресса, Аппаратное обеспечение, Сеть, Демосцена, Люди, Программирование

Similar articles:

В этот день...   6 May