#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct head
{
	char ChunkID[4];
	long int ChunkSize;
	char Format[4];

	char SubChunkID[4];
	long int SubChunkSize;
	short int AudioFormat;
	short int NumChannels;
	long int SampleRate;
	long int BytesRate;
	short int  BlockAlign;
	short int BitsPerSample;

	char SubChunk2ID[4];
	long int SubChunk2Size;
}head;

void get_it(char * ptr, int size)
{
	char * dest = (char*) ptr;
	int i;
	for (i=0;i<size;i++)
	{
		*(dest+i) = getchar();
	} 
}

int take_it(char * ptr, int size)
{
	int dest = 0;
	dest = (int)*ptr;
	if (size > 1)
	{
		dest = ((dest) +(256 * (int)*(ptr+1)));
		//dest = ((int)*(ptr+1));
	}
	return dest;
}

int main(void)
{
	get_it((char*)&head,44);

	int vol = head.BitsPerSample/8;
	int slug = head.BlockAlign * head.NumChannels * vol ;
		int l=0;
	int cnt = 0;
	while (cnt <= head.SubChunk2Size)
	{
		char * continuous_read = malloc(slug);
		get_it(continuous_read,slug);
		cnt += slug;
		

		int j;
		for (j=0;j<head.BlockAlign;j++)
		{
			int k;
			for (k=0;k<head.NumChannels;k++)
			{
				int tmp = take_it(continuous_read+(j*vol)+(k*head.BlockAlign),vol);
				//float flt = ((float)tmp) / (2<<(head.BitsPerSample-1)-1);
				float flt;
				if (head.BitsPerSample == 8)
				{
					flt = 1.0 - (((float)tmp) / 127);
				}
				else
				{
					flt = (((float)tmp) / 32767);
				}
				printf("%f",flt);
				if (k == head.NumChannels-1)
				{
					if (l >= head.SampleRate)
					{
						printf("\n");
						l = 0;
					}
					else
					{
						printf(" ");
						l++;
					}
					//printf("%d ",l);
				}
				else
				{
					printf(":");
				}
			}
		}
		free(continuous_read);
	}
	//in case that the file is less than a second
	//we need to fill up the second to make sure
	//samplerate is recoverable 
	if(head.SubChunk2Size  < head.BytesRate)
	{
		int f;
		for (f=0;f<=(head.BytesRate-head.SubChunk2Size);f+=1)
		{
			printf(" _");
		}
		printf("\n");
	}	
	
	putchar(EOF);
	return 0;
}
