Author Topic: Help with keeping oscilloscope real time  (Read 3441 times)

0 Members and 1 Guest are viewing this topic.

Offline Craz1000

  • Forum Regular
  • Posts: 111
  • I'm OK
    • View Profile
    • Craz1000.net
Help with keeping oscilloscope real time
« on: July 18, 2021, 11:10:06 pm »
I seem to ask for help a lot it seems lol.

So after completing my Zelda game and posting it here, it has left me with some free time. Enough time to catch up with things I have been putting off around the house. Lately I have been playing with some ideas and concepts, One of which requires an oscilloscope of audio in real time. I have been playing with the _memsound example and another example I have found on here. However I cant seem to get it quite right. What I see graphically is either behind (i=i+2) or ahead (i=i+3) of the audio. I have tried doing a bytes per second on the fly adjustment, a frames per second adjustment, and a "how much time has advanced on the audio since the last display refresh adjustment." Nothing seems to work quite right.

Code: QB64: [Select]
  1. Dim leftchannel As _MEM
  2.  
  3. Display& = _NewImage(600, 200, 32)
  4. Buffer& = _NewImage(600, 200, 32)
  5.  
  6. Screen Display&
  7. _Dest Buffer&
  8.  
  9.  
  10. song& = _SndOpen("Sounds\singing stars.mp3") 'replace drums.ogg with a sound file you have
  11.  
  12.  
  13. leftchannel = _MemSound(song&, 1)
  14.  
  15.  
  16. i = 0
  17. PositionDifference = 2
  18. _SndPlay song&
  19.  
  20.  
  21.     _MemGet leftchannel, leftchannel.OFFSET + i, l% 'get sound data
  22.  
  23.     Locate 1, 1: Print leftchannel.OFFSET; "/"; leftchannel.SIZE, dframes, leftchannel.ELEMENTSIZE
  24.     nextposl = map(l%, -32768, 32767, -_Height / 2, _Height / 2) + (_Height / 2)
  25.     Line (x, prevposl)-(x + 1, nextposl + 2), _RGB32(254, 0, 0), BF
  26.     prevposl = nextposl
  27.  
  28.  
  29.  
  30.  
  31.     x = x + 1
  32.     If x > _Width Then
  33.         x = 0
  34.         dframes = frames
  35.         frames = 0
  36.         _PutImage , Buffer&, Display&
  37.  
  38.         Cls
  39.     End If
  40.     i = i + 2
  41.  
  42.     If i + 2 > leftchannel.SIZE Then Exit Do
  43.     frames = frames + 1
  44.  
  45.  
  46.  
  47.  
  48.  
  49. _SndClose song& 'closing the sound releases the mem blocks
  50.  
  51.  
  52. Function map! (value!, minRange!, maxRange!, newMinRange!, newMaxRange!)
  53.     map! = ((value! - minRange!) / (maxRange! - minRange!)) * (newMaxRange! - newMinRange!) + newMinRange!
  54.  

* Singing stars.mp3 (Filesize: 3.68 MB, Downloads: 222)