thanks thats really usefull advice.
I’ve done what you reccomended and it very nearly works…
I get successful playback of the audio stream from the video file, except it is quite badly distorted, and a lot louder than I would expect it to be.
heres my GetNextAudioBlock() function:
void VideoStreamAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
{
if(streamLoaded&&streamPlaying)
{
pActiveVFW16bitBlockL = (short *) &ByteBuffer[CurrentReadPosition * infoAudioStream.dwScale];
pActiveVFW16bitBlockR = &pActiveVFW16bitBlockL[1];
pActiveJuceBlockL = info.buffer->getSampleData (0, info.startSample);
pActiveJuceBlockR = info.buffer->getSampleData (1, info.startSample);
for (int i = 0; i < info.numSamples; ++i)
{
*pActiveJuceBlockL = (float)*pActiveVFW16bitBlockL;
*pActiveJuceBlockR = (float)*pActiveVFW16bitBlockR;
pActiveVFW16bitBlockL+=2;
pActiveVFW16bitBlockR+=2;
pActiveJuceBlockL++;
pActiveJuceBlockR++;
}
CurrentReadPosition += info.numSamples;
//newPosition = roundDoubleToInt (newPosition * sourceSampleRate / sampleRate);
}
}
AudioSourceChannelInfo& info comes into the function with StartSample = 0 and numSamples = 1024 every time the function is called.
maybe I’m missing something obvious. Like I have to set the sample Rate somewhere cos its different to my source sample rate? I’m not sure where in the chain that should be set now tho.
heres the code where I instantiate my new VideoStreamAudioSource objects and connect them to my mixer
VideoStreamAudio[0] = new VideoStreamAudioSource();
mixerSource.addInputSource(VideoStreamAudio[0], false);
VideoStreamAudio[1] = new VideoStreamAudioSource();
mixerSource.addInputSource(VideoStreamAudio[1], false);
VideoStreamAudio[2] = new VideoStreamAudioSource();
mixerSource.addInputSource(VideoStreamAudio[2], false);
VideoStreamAudio[3] = new VideoStreamAudioSource();
mixerSource.addInputSource(VideoStreamAudio[3], false);
And here is my vfw stream read function incase thats of any use?
[code]HRESULT VideoStreamAudioSource::ExtractAVIAudio(String szFileName)
{
AVIFileInit();
PAVIFILE avi;
LONG plBytes = 0;
LONG plSamples = 0;
int audioDataOffset = 0;
HRESULT res=AVIFileOpen(&avi, LPCTSTR(szFileName), OF_READ, NULL);
if (res!=AVIERR_OK)
{
if (avi!=NULL)
AVIFileRelease(avi);
return res;
}
AVIFILEINFO avi_info;
res = AVIFileInfo(avi, &avi_info, sizeof(AVIFILEINFO));
res = AVIFileGetStream(avi, &pAVIAudioStream, streamtypeAUDIO /*Audio stream*/, 0 /*first stream*/);
if(res!=AVIERR_OK) return(res);
LONG lSize;
audioDataOffset = AVIStreamStart(pAVIAudioStream);
AVIStreamReadFormat(pAVIAudioStream, AVIStreamStart(pAVIAudioStream), NULL, &lSize);
LPBYTE pChunk = new BYTE[lSize];
if(pChunk)
res = AVIStreamReadFormat(pAVIAudioStream, audioDataOffset, pChunk, &lSize);
if(res!=AVIERR_OK)
return(res);
pWaveFormat = (LPWAVEFORMATEX)pChunk;
AVIStreamInfo(pAVIAudioStream, &infoAudioStream, sizeof(infoAudioStream));
AVIStreamRead(pAVIAudioStream, 0, AVISTREAMREAD_CONVENIENT, NULL, 0, &lSize, NULL);
BufferSizeBytes = infoAudioStream.dwLength * infoAudioStream.dwScale;
ByteBuffer = new BYTE[BufferSizeBytes];
if(ByteBuffer)
res = AVIStreamRead(pAVIAudioStream, audioDataOffset, BufferSizeBytes - audioDataOffset, ByteBuffer,
BufferSizeBytes, &plBytes, &plSamples);
if(res==AVIERR_OK)
{
pAVIBufferDataL = (WORD *)ByteBuffer;
pAVIBufferDataR = (WORD *)&ByteBuffer[2];
pAVIBufferEnd = &ByteBuffer[BufferSizeBytes];
nSamples = infoAudioStream.dwLength;
streamLoaded = true;
}
return res;
}[/code]