It actually doesn't look too bad. Some minor nitpicks
You shouldn't cast the return value of
mallocYou shouldn't cast the return value ofmalloc.fByteRateandfBlockAligncan beconstsince they're being computed fromconstvalues only.I'm not entirely sure why pretty much all variables in
WriteWavePCMare prefixed withf. I suppose this is meant to indicate that they are related to data being written to a file. Since most code in this method is related to writing things to a file this seems redundant to me and a bit distracting but YMMV.A magic constant is being used here
fChunkSize = 36 + fSubchunk2Size;- replace with named constant (calculated or defined - depends where the 36 comes from).fBitsPerSampleis defined to 16 which assumes thatshortis 16bits (since it's related to writing theshort* sounddata into the file). This may not be the case on all platforms. SofBitsPerSampleshould either besizeof(*sound)or being passed in.You use inconsistent bracing style:
int main(int argc, char* argv[]){
vs
if (!sound)
{
You have defined
N_CHANNELSbut the main loop is hard coded to increment by2, so thisfor (i = 0, j = 0; i < N_SAMPLE_PAIRS * N_CHANNELS; i += 2, j++ )
should be
for (i = 0, j = 0; i < N_SAMPLE_PAIRS * N_CHANNELS; i += N_CHANNELS, j++)