wav: Only create wav header if there is output available.
[paraslash.git] / wav.c
diff --git a/wav.c b/wav.c
index 4933afd..c03c21d 100644 (file)
--- a/wav.c
+++ b/wav.c
@@ -48,6 +48,7 @@ static void make_wav_header(unsigned int channels, unsigned int samplerate,
        int bytespersec = channels * samplerate * BITS / 8;
        int align = channels * BITS / 8;
 
+       assert(channels);
        PARA_DEBUG_LOG("writing wave header: %d channels, %d KHz\n", channels, samplerate);
        memset(headbuf, 0, WAV_HEADER_LEN);
        memcpy(headbuf, "RIFF", 4);
@@ -71,6 +72,8 @@ static ssize_t wav_convert(char *inbuf, size_t len, struct filter_node *fn)
        int *bof = fn->private_data;
 
        if (*bof) {
+               if (!len)
+                       return 0;
                make_wav_header(fn->fc->channels, fn->fc->samplerate, fn);
                fn->loaded = WAV_HEADER_LEN;
                *bof = 0;