A .wav file is typically just a header followed by 16 bit analog data sampled at 44.1 kHz.
It is far from being the only format suitable for transmitting sound to some on line service, but you can read more about .wav file formats here.
I typically dump raw 16 bit analog sound samples to SD card in binary format, then convert the data to .wav format using something like this on a PC:
/* make_wav.c
* base code written by Kevin Karplus
* Reads raw int16_t audio data file and creates .wav formatted output
*/
// https://karplus4arduino.wordpress.com/2011/10/08/making-wav-files-from-c-programs/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "make_wav.h"
#define S_RATE (16000)
//int16_t buffer[BUF_SIZE];
// Function prototypes
int getFileSize(FILE* inFile);
char filename[50]={0};
int main(int argc, char * argv)
{
int i;
printf("\nInput file? ");
scanf("%s",&filename);
FILE* wavFile = fopen(filename, "rb");
if (!wavFile)
{
fprintf(stderr, "Unable to open %s\n", filename);
return 1;
}
int filelength = getFileSize(wavFile);
printf("File contains %d bytes\n",filelength);
// create local buffer for entire audio snippet
const int buf_size=filelength/2;
int16_t buffer[buf_size];
float x=0, x2=0, xmax=-1E6, xmin=1E6;
float t;
int bytesRead = fread(buffer, 2, buf_size, wavFile);
for (i=0; i<buf_size; i++) {
t=buffer[i];
x += t;
x2 += t*t; //for rms calc, if desired
if (xmax < t) xmax=t;
if (xmin > t) xmin=t;
buffer[i]=t*5;
//dump
// if (i> 34040 && i<34050) printf(" >%d, %d\n",i,buffer[i]);
}
printf ("xbar = %8.1f, xmax = %8.1f, xmin = %8.1f\n", x/buf_size, xmax, xmin);
// output file
char outfile[20];
char dot[2]=".";
char *token;
token = strtok(filename,dot);
snprintf(outfile, sizeof(outfile),"%s.wav",token);
write_wav(outfile, buf_size, buffer, S_RATE);
printf("%s written\n",outfile);
return 0;
}
// find the file size
int getFileSize(FILE* inFile)
{
int fileSize = 0;
fseek(inFile, 0, SEEK_END);
fileSize = ftell(inFile);
fseek(inFile, 0, SEEK_SET);
return fileSize;
}
make_wav.h
/* make_wav.h
* Fri Jun 18 17:06:02 PDT 2010 Kevin Karplus
https://karplus4arduino.wordpress.com/2011/10/08/making-wav-files-from-c-programs/
*/
#ifndef MAKE_WAV_H
#define MAKE_WAV_H
#include <inttypes.h>
void write_wav(char * filename, uint32_t num_samples, int16_t * data, uint32_t s_rate);
/* open a file named filename, write signed 16-bit values as a
monoaural WAV file at the specified sampling rate
and close the file
*/
#endif
make_wav.c
/* make_wav.c
https://karplus4arduino.wordpress.com/2011/10/08/making-wav-files-from-c-programs/
* Creates a WAV file from an array of ints.
* Output is monophonic, signed 16-bit samples
* copyright
* Fri Jun 18 16:36:23 PDT 2010 Kevin Karplus
* Creative Commons license Attribution-NonCommercial
* http://creativecommons.org/licenses/by-nc/3.0/
*/
// fixed by using write binary "wb" sjr
#include <stdio.h>
#include "make_wav.h"
#include <assert.h>
#include <inttypes.h>
void write_little_endian(uint32_t word, uint32_t num_bytes, FILE *wav_file)
{
uint8_t buf;
while(num_bytes>0)
{ buf = word & 0xff;
fwrite(&buf, 1,1, wav_file);
num_bytes--;
word >>= 8;
}
}
/* information about the WAV file format from
http://ccrma.stanford.edu/courses/422/projects/WaveFormat/
*/
void write_wav(char * filename, uint32_t num_samples, int16_t * data, uint32_t s_rate)
{
FILE* wav_file;
uint32_t sample_rate;
uint16_t num_channels;
uint16_t bytes_per_sample;
uint32_t byte_rate;
uint32_t i; /* counter for samples */
num_channels = 1; /* monoaural */
bytes_per_sample = 2;
if (s_rate<=0) sample_rate = 44100;
else sample_rate = (uint32_t) s_rate;
byte_rate = sample_rate*num_channels*bytes_per_sample;
printf("writing wav file, samples %u\n", num_samples);
printf("bytes per sample %u, channels %u, sample rate %u\n",bytes_per_sample,
num_channels,sample_rate);
wav_file = fopen(filename, "wb"); //binary
assert(wav_file); /* make sure it opened */
/* write RIFF header */
fwrite("RIFF", 1, 4, wav_file);
write_little_endian(36 + bytes_per_sample* num_samples*num_channels, 4, wav_file);
fwrite("WAVE", 1, 4, wav_file);
/* write fmt subchunk */
fwrite("fmt ", 1, 4, wav_file);
write_little_endian(16, 4, wav_file); /* SubChunk1Size is 16 */
write_little_endian(1, 2, wav_file); /* PCM is format 1 */
write_little_endian(num_channels, 2, wav_file);
write_little_endian(sample_rate, 4, wav_file);
write_little_endian(byte_rate, 4, wav_file);
write_little_endian(num_channels*bytes_per_sample, 2, wav_file); /* block align */
write_little_endian(8*bytes_per_sample, 2, wav_file); /* bits/sample */
/* write data subchunk */
fwrite("data", 1, 4, wav_file);
write_little_endian(bytes_per_sample*num_samples*num_channels, 4, wav_file);
printf("data chunk size %ld\n",bytes_per_sample* num_samples*num_channels);
for (i=0; i< num_samples; i++)
{
write_little_endian((uint16_t)(data[i]),bytes_per_sample, wav_file);
}
fclose(wav_file);
}