www.pudn.com > raw-wave-lib-v0.1.zip > wave.h


#ifndef WAVE_H
#define WAVE_H
#include 
#include 

typedef short int sample_block;
typedef unsigned char sample_8;

typedef struct {
  unsigned int channels; //number of channels
  unsigned int sample_rate; //in hertz
  sample_block* samples;
  unsigned int num_of_samples;
  unsigned int appendage;
} wave_file_struct;

/****************************************************
  wave_file_16_bit:
    channels == number of channels (stereo or mono)
    sample_rate == sample rate in Hz (32000, 44100, etc)
    samples == pointer to raw data in 16-bit signed chunks
    num_of_samples == number of samples in each channel
      (num_of_samples = bytes / channels / bytes per sample)
    appendage == optional misc 32-bit integer value at end of wav
***********************************/


/****************************************************
  initialize_wave_struct_from_file(file, str, to_mono):
    read WAV data from already-opened 'file' and put data in
    'str'. This operation malloc's 'str' automatically.
    If 'to_mono' != 0, only the first channel will be read
    else, read all channels. 'file' remains open afterwards
*****************************************/
int initialize_wave_struct_from_file(FILE* file, wave_file_struct* str, int to_mono);
/****************************************************
  write_wave_struct_to_file(file, str):
    output WAV data to already-opened 'file' from 'str'. This
    does not change str in any way. 'file' remains open afterwards
*******************************************/

int write_wave_struct_to_file(FILE* file, wave_file_struct* str);

/****************************************************
  initialize_wave_struct(str, array, array_length, sample_rate,
  appendage, channels):
    create the struct 'str' from the array of data 'array' and
    'sample_rate', 'appendage', and 'channels'. space in 'str' is malloc'ed.
**********************************************/
int initialize_wave_struct(wave_file_struct* str, double* array, unsigned int array_length, int sample_rate, unsigned int appendage, int channels);
/*******************************************************
  free_wave_struct(str):
    frees previously malloc'ed elements in str. Presently this is only
    'str->sample'. Use after an initializing function
**************************************************/
void free_wave_struct(wave_file_struct* str);
/*****************************************************
  extract_double_array_from_struct(str, array):
    convert raw data from 'str' to doubles in 'array'. 'array' is assumed
    to be previously allocated somehow.
*************************************************/
int extract_double_array_from_struct(wave_file_struct* str, double* array);

/** APPENDAGE_NULL is the value in 'str->appendage' meaning, no appendage. */
#define APPENDAGE_NULL 0xffffffff
#endif