Faster than Real-Time sound-system?

BlitzMax Forums/BlitzMax Programming/Faster than Real-Time sound-system?

Danny(Posted 2011) [#1]
Hi all,

I want to render a movie file with a 3D rendered video stream and a mixed audio stream.

The audio comes originally from two files:
1. a background music (mp3 file)
2. a voice track (wav file)

I want to do a simple lip-sync on a character using the voice track.
And for the final movie I want to mix the background music with the voice tack to a (single) final audio track.

But I want to do this in batch-mode, doing dozens of files: as fast as possible!

In 'real time' this is no problem: Simply 'play' both samples, and check the voice channel's output level in real-time to animate some (very simple!) lip-sync on a character.

So how can I do this 'faster than real-time':

# Mix two audio streams into one new one?
# Analyze the voice stream itself (in stead of playing it out) to get the data required for lip-sync?


Can anyone recommend a sound library that might be able to do this?

Cheers,
Danny.

Last edited 2011


Midimaster(Posted 2011) [#2]
At first: Mixing two Sound Files is very easy using Audacity....

but if you want to do it in BMax....
mixing two sound files in BMax is easy too, if you know the characteristics of the two Sounds: Sample Frequency, Bit-Rate Stereo/Mono, EdianTyp.

Open the two files as 'Tsample' in BMax. Now you can pick each single Sample (Byte, Long or Double) of File A and add it to the corresponding Bytes, Longs or Doubles in File B.

The Values (0-255 f.e. if they are Bytes) representing the Wav-Altitude in a certain moment of time. Because the "0-Level" is represented by "128", do not forget to substract 128 to get real values from -127 to +127

Take care about, not to clip the sum signal! You can reach this if you combine the values with a 'volume' parameter. The sum of both volumes has to be below "1":

Select VolumeA, that...
0 < VolumeA < 1

Select VolumeB, that...
0 < VolumeB < (1- VolumeA)

Do this for each single Sample in the TSample:

PartA = SampleA[ posA ] -128
PartB = SampleB[ posB ] -128
FinalSample[pos] = VolumeA*PartA + VolumeB*PartB

There are some Threads here about "Samples", where you can find as a side effect these informations too.

http://www.blitzbasic.com/Community/posts.php?topic=95529#1101257

http://www.blitzbasic.com/Community/posts.php?topic=90830#1033522

...and more...


Danny(Posted 2011) [#3]
THANKS midimaster!

This is the pearl I've been looking for, cheers for explaining it so brief but clearly!
Although I was hoping to be able to use an external library for this so I wouldn't have to go this low-level - for fear of requiring to support every possible sample type.
But this is the best way to get full control over both processes (mixing and measuring for lip-sync).
To measure the volume level over time, I guess I only need to average a sample's amplitude at a given sample rate..

I'll study the topic and the posts you mentioned..

Cheers,
Danny.

Last edited 2011