2009/1/18 Arjan <[email protected]> > > Op 18 jan 2009, om 02:02 heeft Franco Amato het volgende geschreven: > > > 2009/1/17, Arjan <[email protected]>: > >> > >> > >> Op 18 jan 2009, om 00:54 heeft Franco Amato het volgende geschreven: > >> > >>> Hi to all, > >>> I have a problem that I can not solve. > >>> In my encoder I'm encoding video and audio, the problem comes with > >>> the audio > >>> part. > >>> My original audio raw samples are pcm float -1/+1 stereo. So I have > >>> 4 bytes > >>> (2 for the L channel and 2 for the R channel TOTAL = 4 bytes). > >> > >> floats are in fact 4 bytes -> 32bit > >> for a second of audio stored using float with a sample rate of 48Khz, > >> you would need 48000 * 2 chan * 4 bytes = 384000 bytes. > > > > > > I don't understand. Which is this size? > > let's break this down > > float sourceSamples[64]; > int16_t destSamples[64]; > > int i; > for(i=0; i<64; i++) { > > destSamples[i] = sourceSamples[i] * 0x7FFF; > } > > it's really very simple.. just let the compiler care about the sizes > of the types > > In regard to your question about the low audio level, try the following. > (please try to condense your messages, as not to litter the mailing > list) > > you first need to find the maximum amplitude > > float max = 0.0; > int i; > for(i=0; i<64; i++) { > > if( abs( sourceSamples[i] ) > max ) max = abs( sourceSamples[i] ); > } > > now max holds the largest amplitude in your collection of samples. > Your theoretical max is 1.0, so by calculating the difference, you can > check how much you can amplify your samples while remaining in the > 16bit range. > > (0x7FFF is the max of a 16 bit signed int) > float multiply = 0x7FFF; > if( max ) multiply *= 1.0 / max; > > so instead of multiplying with 0x7FFF, you now multiply with 'multiply' > Please note that you can't keep calculating this max value, as every > collection of samples will be differently amplified. You have to > calculate this max value once for all samples belonging to the same > piece of audio.
Thank you very much but it is not possible for me because I do not know the value of every sample from the begining. The audio is generated in real time. > > > - Arjan Franco > > _______________________________________________ > libav-user mailing list > [email protected] > https://lists.mplayerhq.hu/mailman/listinfo/libav-user > -- Franco Amato _______________________________________________ libav-user mailing list [email protected] https://lists.mplayerhq.hu/mailman/listinfo/libav-user
