From 34a4bb998ef3dedc8ecf132a83a9b859b5f79063 Mon Sep 17 00:00:00 2001 From: Ron Pedde Date: Tue, 23 Oct 2007 03:37:51 +0000 Subject: [PATCH] Fix duration scanning for wav files --- src/scan-wav.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/scan-wav.c b/src/scan-wav.c index 6e9da45b..19b5cb0a 100644 --- a/src/scan-wav.c +++ b/src/scan-wav.c @@ -70,8 +70,8 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) { uint32_t current_offset; uint32_t block_len; - int found_fmt = 0; - int found_data = 0; + int found_fmt = FALSE; + int found_data = FALSE; DPRINTF(E_DBG,L_SCAN,"Getting WAV file info\n"); @@ -79,7 +79,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) { DPRINTF(E_LOG,L_SCAN,"Could not create file handle\n"); return FALSE; } - + if(!io_open(hfile,"file://%U",filename)) { DPRINTF(E_WARN,L_SCAN,"Could not open %s for reading: %s\n",filename, io_errstr(hfile)); @@ -110,7 +110,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) { /* now, walk through the chunks */ current_offset = 12; - while(!found_fmt && !found_data) { + while(!found_fmt || !found_data) { len = 8; if(!io_read(hfile,hdr,&len) || (len != 8)) { io_close(hfile); @@ -148,7 +148,7 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) { compression_code = GET_WAV_INT16(fmt); channel_count = GET_WAV_INT16(fmt+2); sample_rate = GET_WAV_INT32(fmt + 4); - sample_bit_length = GET_WAV_INT16(hdr + 14); + sample_bit_length = GET_WAV_INT16(fmt + 14); DPRINTF(E_DBG,L_SCAN,"Compression code: %d\n",compression_code); DPRINTF(E_DBG,L_SCAN,"Channel count: %d\n",channel_count); DPRINTF(E_DBG,L_SCAN,"Sample Rate: %d\n",sample_rate); @@ -175,6 +175,11 @@ int scan_get_wavinfo(char *filename, MP3FILE *pmp3) { } bit_rate = sample_rate * channel_count * ((sample_bit_length + 7) / 8) * 8; + if(!bit_rate) { + DPRINTF(E_WARN,L_SCAN,"Couldn't get bitrate\n"); + return FALSE; + } + pmp3->bitrate = bit_rate / 1000; pmp3->samplerate = sample_rate; sec = data_length / (bit_rate / 8);