Hi, when I have my Oscilliscope unit running it seems like the data is being displayed offset by maybe 20 ms. I will start the song and about 20 ms before there is any sound coming through I will get data from the Scope unit. How do I sync my oscilliscope with the sound output???
- Paranoid_Android asked 15 years ago
Well, after looking at the C++ code I found out that I need to buffer the data. What I did was, in my callback I set it up to hold the current block in a variable called ScopeBlock. Then in my plotting function I used that to create an offset value which would be the offset of the oscilliscope so that it would display according to the audible music. Now, I cant figure out how to buffer the data using the offset. Heres my code:
Public Function ScopeCallback(ByVal originalbuffer As Long, ByVal newbuffer As Long, ByVal length As Integer, ByVal param As Integer) As Long
TotalBlocks = FSOUND_DSP_GetBufferLengthTotal() / FSOUND_DSP_GetBufferLength() ScopeBlock = ScopeBlock + 1 If ScopeBlock >= TotalBlocks Then ScopeBlock = 0 End If RealtimeBuf = originalbuffer ScopeCallback = newbuffer
Plotting of the oscilliscope:
Public Sub Vis_DisplayScope()
On Error Resume Next Dim Mixer As Integer Dim X As Integer Dim offset As Long Dim SrcInt() As Integer Dim SrcFPU() As Single Dim Step As Long Mixer = Settings.MixerType frmMain.picVisuals.Cls offset = (ScopeBlock + 1) * FSOUND_DSP_GetBufferLength() If (offset >= FSOUND_DSP_GetBufferLengthTotal()) Then offset = offset - FSOUND_DSP_GetBufferLengthTotal() End If Step = FSOUND_DSP_GetBufferLength() / frmMain.picVisuals.Width ReDim SrcInt(offset) ReDim SrcFPU(offset) If Mixer <> 0 Then 'MMX P5/6 GetScopeINT SrcInt For X = 0 To frmMain.picVisuals.Width LineTo frmMain.picVisuals.hdc, X, (SrcInt(X + Step) + 32768) / 65536 * frmMain.picVisuals.Height Next X Else 'FPU GetScopeFPU SrcFPU For X = 0 To frmMain.picVisuals.Width LineTo frmMain.picVisuals.hdc, X, (SrcFPU(X + Step) + 32768) / 65536 * frmMain.picVisuals.Height Next X End If frmMain.picVisuals.Refresh On Error GoTo 0
I hope somebody can help!
Ok, I took this from the documentation.
If you are thinking of plotting the data to sync with the audible output, it is wise to buffer the data in a circular buffer, for the number of samples specified by FSOUND_DSP_GetBufferLengthTotal. This length is divisible by the DSP callback length (always a multiple of 25ms).
From this point then you would plot the block of data preceeding the one you are filling, which is the one playing at that point in time!
See the FMOD example in the /samples/fmod directory for source code that does this, and many other examples of DSP processing.
How do I buffer the data in a circular buffer in VB??
Very good idea! What you want to make is incorporate in some way what a “FSOUND_DSP_ACCURATE” would call, making that the unit DSP reads data later.
Now then, I propose the opposite. That it would happen if I wanted to have those data 3 or 4 seconds before listening the sound. It would be appropriate to create a waveform that leaves creating in advance. This without increasing the FSOUND mix buffer for not increasing the latency.
The idea would be to put a buffer before Fmod.
He would have to take, for example, the value of FSOUND_Stream_GetPosition, to determine in what place of the file Fmod is, to this to add him the equivalent of 4,1 seconds (4 seconds + 100 milisecons of the buffer, position where would read the buffer) and read the data ahead +/- 3 seconds of Fmod. These data would be passed the DSP.
The problem is that I don’t believe that can make because it would be necessary to break the chain of the system DSP unit. Although if you can put back the process of DSP, perhaps it can be ahead…
- LeoCombes answered 14 years ago
Please login first to submit.