This will overflow:
Code:
u_int64_t filesize_in_bytes = channels * bytes_per_sample * samples_per_second * duration_in_second;
Example:
Code:
#include <stdio.h>
#include <stdint.h>
#include <inttypes.h>
uint64_t f( uint32_t a, uint32_t b, uint32_t c, uint32_t d )
{ return a * b * c * d; }
uint64_t g( uint32_t a, uint32_t b, uint32_t c, uint32_t d )
{ return (uint64_t)a * b * c * d; }
int main( void )
{
printf( "%" PRIu64 ", %" PRIu64 "\n",
f( 2, 129, 44100, 192*1024 ),
g( 2, 129, 44100, 192*1024 ) );
}
Results in:
Code:
$ cc -o test test.c
$ ./test
3583508480, 2236966502400