-
Apr 18th, 2020, 10:23 AM
#41
Thread Starter
Member
Re: Converting single bits into a sine waveform
Hi everyone
Another side issue I have is the buffer capacity. Am I right in thinking with the code I have been given that the module clsTrickSound2 has the code that governs this? The buffer has no limit except for the moment I stop recording input audio off my soundcard.
I know this as I have briefly included 3 text boxes to put the values of the following
* (capCount - 1) / Int(picWaveform.ScaleWidth)
* value
* Index
I can see each textbox's number value increases from one moment to the next
I was hoping to have the buffer size reduced to 10 seconds (Ie 11 seconds into the 'Start reception' button being clicked, the beginning 1st second of the original recording is removed. Then after 12 seconds of recording the beginning 2 seconds are removed, etc)
As much as I am thankful to you THE TRICK for your referral to your 'Trick Sound' contribution for me. I dont want to potentially overload my RAM memory of my machine if the reception/recording duration in a given scenario had to record for a considerable amount of time.
As much as the 'Trick Sound' program is to be respected, I am simply after discerning 0 or 1 bits of the sinewave instead so I need only a short buffer to deal with this task. The only problem is I dont know ow to edit the code to do it. ARGHH!!!
Do you have the time to help THE TRICK or can anyone else help me in this matter? Thanks
-
Apr 20th, 2020, 01:28 PM
#42
Thread Starter
Member
Re: Converting single bits into a sine waveform
I've managed to bump into a friend of mine briefly who helped discern the code in the cldTrickSound2 module. It appears that waveInOpen and waveInPrepare functions linked to file "winmm.dll" dictate. How do I limit the buffer size to say only 10 seconds no matter how long the recording will be the buffer will only contain the most recent 10 seconds of it. Can this be done?
-
Apr 20th, 2020, 01:30 PM
#43
Re: Converting single bits into a sine waveform
There is the example how to record a sound.
-
Apr 21st, 2020, 11:30 AM
#44
Thread Starter
Member
Re: Converting single bits into a sine waveform
No worries. Thanks for your input. I shall accept I cant create a dynamic buffer and limit it to 10 secs.
What I also need advice for is whether vb6 allows a tolerance range of a selected variable's value.
What I mean is say for a simple IF statement contains a variable to a certain value result such as
Code:
If NumVar = 100 then
Obviously the IF statement is executed once NumVar is equal to 1000. That is a specific number value.
What I am after is creating an IF statement where in the above example the IF statement is executed if NumVar is lets say 20 below 1000 or 20 above 1000 (980-1020). I know in mathematics the symbol for tolerance is ± . But I dont know if VB6 is capable of performing such a task. Can anyone shed some light on this please?
-
Apr 21st, 2020, 11:31 AM
#45
Thread Starter
Member
Re: Converting single bits into a sine waveform
No worries. Thanks for your input. I shall accept I cant create a dynamic buffer and limit it to 10 secs.
What I also need advice for is whether vb6 allows a tolerance range of a selected variable's value.
What I mean is say for a simple IF statement contains a variable to a certain value result such as
Code:
If NumVar = 1000 then
Obviously the IF statement is executed once NumVar is equal to 1000. That is a specific number value.
What I am after is creating an IF statement where in the above example the IF statement is executed if NumVar is lets say 20 below 1000 or 20 above 1000 (980-1020). I know in mathematics the symbol for tolerance is ± . But I dont know if VB6 is capable of performing such a task. Can anyone shed some light on this please?
PS I know that I can use 'more than' and 'less than' (< and >). But this can only be applied if NumVar is a fixed static value. The point is the NumVar value in my personal scenario is in a FOR loop setup where NumVar has dynamic values each time the for loop happens. So I cannot use < or > in IF statements. I shall appreciate any help given my way
Last edited by greenelephant150; Apr 21st, 2020 at 12:42 PM.
-
Apr 21st, 2020, 04:33 PM
#46
Re: Converting single bits into a sine waveform
There is no tolerance function, but you should be able to create one.
Code:
If Within(20, NumVar, 1000) Then
'...
End If
Function Within( Tolerance As Double, Value as Double, CheckValue) As Boolean
Within = Abs(CheckValue - Value) <= Tolerance)
End Function
Of course, you could inline it
If Abs(1000 - NumVar) <= 20 Then
"Anyone can do any amount of work, provided it isn't the work he is supposed to be doing at that moment" Robert Benchley, 1930
-
Apr 30th, 2020, 02:03 PM
#47
Thread Starter
Member
Re: Converting single bits into a sine waveform
Hello. Good News!!!
I have almost finished my entire project! (About Time). I can build the audio reception screen from this point on.
The main two things I lastly need help is with POST #16 of this thread. I dont know how to modify the code for my transmission form to convert it into a full-period sine wave.
Also how can I add a second frequency value to the transmission process (ie generate a full-period at a certain frequency, and another full-period at a different frequency.) Then cycle between the two frequencies till the end of transmission. Thats the last bit I need help with.
A big shout out goes to THE TRICK, for having the patience to put up with me plus anyone else who contributed (Schmidt, Passel, and whoever else I havent named I thank you!) Does anyone know how to complete this last task?
Can anyone help?
Last edited by greenelephant150; May 4th, 2020 at 09:28 PM.
-
May 6th, 2020, 05:10 AM
#48
Thread Starter
Member
Re: Converting single bits into a sine waveform
-
May 19th, 2020, 07:18 PM
#49
Thread Starter
Member
Re: Converting single bits into a sine waveform
The requests stated in post 47 is the final requests to finally bring my project to a close. Is there anyone who can help?
-
Jul 21st, 2020, 09:18 AM
#50
Thread Starter
Member
Re: Converting single bits into a sine waveform
Can THE TRICK or any one still help me. I still need help
-
Jan 9th, 2021, 02:10 AM
#51
Thread Starter
Member
Re: Converting single bits into a sine waveform
Hi Finally after many months I have managed to get help to complete the task in Post 47#!!! Got there in the end. However what I need to do next is modify the code so that the oscillator will output a square wave (as well as the sine wave generated by the code present in my project) Can anyone help. Are you available yet 'The_Trick'?
-
Jan 9th, 2021, 02:32 AM
#52
Re: Converting single bits into a sine waveform
Originally Posted by greenelephant150
Hi Finally after many months I have managed to get help to complete the task in Post 47#!!! Got there in the end. However what I need to do next is modify the code so that the oscillator will output a square wave (as well as the sine wave generated by the code present in my project) Can anyone help. Are you available yet 'The_Trick'?
Code:
dPhaseDelta = GetLogFrequency(sldFrequency.Value) / SAMPLE_RATE * 2
...
bData(lIndex) = ((m_dPhase > 0.5 - 1) * m_fSign) * 0.5 * lLevel + 127
...
If m_dPhase > 1 Then
m_dPhase = m_dPhase - 1
...
-
Jan 11th, 2021, 04:23 PM
#53
Thread Starter
Member
-
Jan 12th, 2021, 06:03 AM
#54
Re: Converting single bits into a sine waveform
To write code that can discern the time period(s) of both frequencies and use those 2 measurements to discern the remainding FM modulated cycles to convert into the relevant binary 1s and 0s. Are you there again The Trick with or pearls of vb6 wisdom? (Or anyone else for that matter?)
Maybe is it better to use PM (phase modulation)?
-
Jan 12th, 2021, 08:38 AM
#55
Thread Starter
Member
Re: Converting single bits into a sine waveform
OK That will be something I will be looking into (PM modulation). There has been a change of circumstances since Post #53. As much as I appreciate your 'TrickRecorder' mentioned in the 1st URL of post #35 . There is another vb6 project more suitable as it doesnt burden system RAM exponentially as does 'TrickRecorder' over the course of time (credit goes to 'DEETH' for the contribution many years ago).
So there has been some changes to the GUI interface since post #38 for the reception screen. An updated screenshot is below
The code for the screen is found below
Code:
'----------------------------------------------------------------------
' Deeth Stereo Oscilloscope v1.0
' A simple oscilloscope application -- now in <<stereo>>
'----------------------------------------------------------------------
' Opens a waveform audio device for 8-bit 11kHz input, and plots the
' waveform to a window. Can only be resized to a certain minimum
' size defined by the Shape box.
'----------------------------------------------------------------------
' It would be good to make this use the same double-buffering
' scheme as the Spectrum Analyzer.
'----------------------------------------------------------------------
' Murphy McCauley (MurphyMc@Concentric.NET) 08/12/99
'----------------------------------------------------------------------
Option Explicit
Private DevHandle As Long
Private InData(0 To 511) As Byte
Private Inited As Boolean
Public MinHeight As Long, MinWidth As Long
Private Type WaveFormatEx
FormatTag As Integer
Channels As Integer
SamplesPerSec As Long
AvgBytesPerSec As Long
BlockAlign As Integer
BitsPerSample As Integer
ExtraDataSize As Integer
End Type
Private Type WaveHdr
lpData As Long
dwBufferLength As Long
dwBytesRecorded As Long
dwUser As Long
dwFlags As Long
dwLoops As Long
lpNext As Long 'wavehdr_tag
Reserved As Long
End Type
Private Type WaveInCaps
ManufacturerID As Integer 'wMid
ProductID As Integer 'wPid
DriverVersion As Long 'MMVERSIONS vDriverVersion
ProductName(1 To 32) As Byte 'szPname[MAXPNAMELEN]
Formats As Long
Channels As Integer
Reserved As Integer
End Type
Private Const WAVE_INVALIDFORMAT = &H0& '/* invalid format */
Private Const WAVE_FORMAT_1M08 = &H1& '/* 11.025 kHz, Mono, 8-bit
Private Const WAVE_FORMAT_1S08 = &H2& '/* 11.025 kHz, Stereo, 8-bit
Private Const WAVE_FORMAT_1M16 = &H4& '/* 11.025 kHz, Mono, 16-bit
Private Const WAVE_FORMAT_1S16 = &H8& '/* 11.025 kHz, Stereo, 16-bit
Private Const WAVE_FORMAT_2M08 = &H10& '/* 22.05 kHz, Mono, 8-bit
Private Const WAVE_FORMAT_2S08 = &H20& '/* 22.05 kHz, Stereo, 8-bit
Private Const WAVE_FORMAT_2M16 = &H40& '/* 22.05 kHz, Mono, 16-bit
Private Const WAVE_FORMAT_2S16 = &H80& '/* 22.05 kHz, Stereo, 16-bit
Private Const WAVE_FORMAT_4M08 = &H100& '/* 44.1 kHz, Mono, 8-bit
Private Const WAVE_FORMAT_4S08 = &H200& '/* 44.1 kHz, Stereo, 8-bit
Private Const WAVE_FORMAT_4M16 = &H400& '/* 44.1 kHz, Mono, 16-bit
Private Const WAVE_FORMAT_4S16 = &H800& '/* 44.1 kHz, Stereo, 16-bit
Private Const WAVE_FORMAT_PCM = 1
Private Const WHDR_DONE = &H1& '/* done bit */
Private Const WHDR_PREPARED = &H2& '/* set if this header has been prepared */
Private Const WHDR_BEGINLOOP = &H4& '/* loop start block */
Private Const WHDR_ENDLOOP = &H8& '/* loop end block */
Private Const WHDR_INQUEUE = &H10& '/* reserved for driver */
Private Const WIM_OPEN = &H3BE
Private Const WIM_CLOSE = &H3BF
Private Const WIM_DATA = &H3C0
Private Declare Function waveInAddBuffer Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long
Private Declare Function waveInPrepareHeader Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long
Private Declare Function waveInUnprepareHeader Lib "winmm" (ByVal InputDeviceHandle As Long, ByVal WaveHdrPointer As Long, ByVal WaveHdrStructSize As Long) As Long
Private Declare Function waveInGetNumDevs Lib "winmm" () As Long
Private Declare Function waveInGetDevCaps Lib "winmm" Alias "waveInGetDevCapsA" (ByVal uDeviceID As Long, ByVal WaveInCapsPointer As Long, ByVal WaveInCapsStructSize As Long) As Long
Private Declare Function waveInOpen Lib "winmm" (WaveDeviceInputHandle As Long, ByVal WhichDevice As Long, ByVal WaveFormatExPointer As Long, ByVal CallBack As Long, ByVal CallBackInstance As Long, ByVal Flags As Long) As Long
Private Declare Function waveInClose Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInStart Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInReset Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Private Declare Function waveInStop Lib "winmm" (ByVal WaveDeviceInputHandle As Long) As Long
Private m_bData() As Byte
Private Start1() As Byte
Private Start2() As Byte
Private Start3() As Byte
Private Start4() As Byte
Private Start5() As Byte
Private m_lDataSize As Long
Private m_lCurPos As Long
Private m_lCurMask As Long
Private m_bIsActive As Boolean
Private m_hWaveOut As Long
'Private m_tBuffer() As tBuffer
Private m_pfnPrevProc As Long
Private m_bIsFirst As Boolean
Private m_dPhase As Double
Private m_fSign As Single
Private Hash As New MD5Hash
Private strFile As String
Private prgLen As Long
Private prgCnt As Long
Private MD52(0 To 31) As Byte
Private Trsmit() As Byte
Private TSCnt As Integer
Private OSCnt As Integer
Private TSCnt2 As Integer
Private OSCnt2 As Integer
Private TMCnt As Integer
Private OMCnt As Integer
Private THCnt As Integer
Private OHCnt As Integer
Sub InitDevices()
Dim Caps As WaveInCaps, Which As Long
cboDevices.Clear
For Which = 0 To waveInGetNumDevs - 1
Call waveInGetDevCaps(Which, VarPtr(Caps), Len(Caps))
'If Caps.Formats And WAVE_FORMAT_1M08 Then
If Caps.Formats And WAVE_FORMAT_1S08 Then 'Now is 1S08 -- Check for devices that can do stereo 8-bit 11kHz
Call cboDevices.AddItem(StrConv(Caps.ProductName, vbUnicode), Which)
End If
Next
If cboDevices.ListCount = 0 Then
MsgBox "You have no audio input devices!", vbCritical, "Ack!"
End
End If
cboDevices.ListIndex = 0
End Sub
Private Sub cmdExit_Click()
Call waveInReset(DevHandle)
Call waveInClose(DevHandle)
DevHandle = 0
picWaveform.Cls
frmRadioBinaryRAM.Hide
frmRadioBinary.Show
Unload frmRadioBinaryRAM
Set frmRadioBinaryRAM = Nothing
End Sub
Private Sub cmdIFile_Click()
Dim sFileName As String
Dim iFileNum As Integer
Dim FileArr As Byte
cd1.ShowOpen
'sFileName = GetOpenFile(Me.hWnd, "Open binary data", "All files" & vbNullChar & "*.*" & vbNullChar)
sFileName = cd1.FileName
m_lCurPos = 0
m_lCurMask = 1
m_dPhase = 0
m_fSign = 1
iFileNum = FreeFile
'prgLen = prgLen * 8
Open sFileName For Binary Access Read As iFileNum
m_lDataSize = LOF(iFileNum)
If m_lDataSize > 0 Then
ReDim m_bData(m_lDataSize - 1)
Get iFileNum, , m_bData()
cmdPlay.Enabled = True
Else
cmdPlay.Enabled = False
Erase m_bData()
End If
Close iFileNum
txtIFile.Text = sFileName
TSCnt2 = 0
OSCnt2 = 0
TSCnt = 0
OSCnt = 0
TMCnt = 0
OMCnt = 0
THCnt = 0
OHCnt = 0
End Sub
Private Sub cmdMD5Check_Click()
frmRadioBinaryRAM.Hide
frmTestMD5Binary.Show
End Sub
Private Sub cmdPlay_Click()
tmr1.Enabled = True
Static WaveFormat As WaveFormatEx
With WaveFormat
.FormatTag = WAVE_FORMAT_PCM
.Channels = 2 'Two channels -- left and right
.SamplesPerSec = 11025 '11khz
.BitsPerSample = 8
.BlockAlign = (.Channels * .BitsPerSample) \ 8
.AvgBytesPerSec = .BlockAlign * .SamplesPerSec
.ExtraDataSize = 0
End With
Debug.Print "waveInOpen:"; waveInOpen(DevHandle, cboDevices.ListIndex, VarPtr(WaveFormat), 0, 0, 0)
If DevHandle = 0 Then
Call MsgBox("Wave input device didn't open!", vbExclamation, "Ack!")
Exit Sub
End If
Debug.Print " "; DevHandle
Call waveInStart(DevHandle)
Inited = True
Call Visualize
End Sub
Private Sub cmdReset_Click()
txtIFile.Text = ""
picWaveform.Cls
End Sub
Private Sub cmdSettings_Click()
frmRadioBinarySettings.Show
frmRadioBinaryRAM.Hide
End Sub
Private Sub cmdStop_Click()
Call DoStop
End Sub
Private Sub Form_Load()
Call InitDevices
'Set MinWidth and MinHeight based on Shape...
Dim XAdjust As Long, YAdjust As Long
XAdjust = Me.Width \ Screen.TwipsPerPixelX - Me.ScaleWidth
YAdjust = Me.Height \ Screen.TwipsPerPixelY - Me.ScaleHeight
MinWidth = picWaveform.Width + XAdjust
MinHeight = picWaveform.Height + YAdjust
'picWaveform.BackStyle = vbTransparent
'Set the window proceedure to my own (which restricts the
'minimum size of the form...
'Comment out the SetWindowLong line if you're working with it
'in the development environment since it'll hang in stop mode.
MinMaxProc.Proc = GetWindowLong(Me.HWnd, GWL_WNDPROC)
SetWindowLong Me.HWnd, GWL_WNDPROC, AddressOf WindowProc2
End Sub
Private Sub tmr1_Timer()
TSCnt = TSCnt + 1
OSCnt = OSCnt + 1
If TSCnt = 10 Then
TSCnt2 = TSCnt2 + 1
TSCnt = 0
End If
If OSCnt = 10 Then
OSCnt2 = OSCnt2 + 1
OSCnt = 0
End If
If TSCnt2 = 60 Then
TMCnt = TMCnt + 1
TSCnt2 = 0
End If
If OSCnt2 = 60 Then
OMCnt = OMCnt + 1
OSCnt2 = 0
End If
If TMCnt = 60 Then
THCnt = THCnt + 1
TMCnt = 0
End If
If OMCnt = 60 Then
OHCnt = OHCnt + 1
OMCnt = 0
End If
lblTrans2.Caption = THCnt & "(H):" & TMCnt & "(M):" & TSCnt2 & "(S)"
lblOvr2.Caption = OHCnt & "(H):" & OMCnt & "(M):" & OSCnt2 & "(S)"
End Sub
Private Sub Visualize()
Static Wave As WaveHdr
Wave.lpData = VarPtr(InData(0))
Wave.dwBufferLength = 512 'This is now 512 so there's still 256 samples per channel
Wave.dwFlags = 0
Do
Call waveInPrepareHeader(DevHandle, VarPtr(Wave), Len(Wave))
Call waveInAddBuffer(DevHandle, VarPtr(Wave), Len(Wave))
Do
'Nothing -- we're waiting for the audio driver to mark
'this wave chunk as done.
Loop Until ((Wave.dwFlags And WHDR_DONE) = WHDR_DONE) Or DevHandle = 0
Call waveInUnprepareHeader(DevHandle, VarPtr(Wave), Len(Wave))
If DevHandle = 0 Then
'The device has closed...
Exit Do
End If
picWaveform.Cls
Call DrawData
DoEvents
Loop While DevHandle <> 0 'While the audio device is open
End Sub
Private Sub DrawData()
Static X As Long
picWaveform.CurrentX = 0
picWaveform.CurrentY = picWaveform.ScaleHeight
'Plot the data...
For X = 0 To 255
picWaveform.Line Step(0, 0)-(X, InData(X * 2))
'Scope(1).Line Step(0, 0)-(X, InData(X * 2 + 1)) 'For a good soundcard...
'Use these to plot dots instead of lines...
'Scope(0).PSet (X, InData(X * 2))
'Scope(1).PSet (X, InData(X * 2 + 1)) 'For a good soundcard...
'My soundcard is pretty cheap... the right is
'noticably less loud than the left... so I add five to it.
'Scope(1).Line Step(0, 0)-(X, InData(X * 2 + 1) + 5)
Next
picWaveform.CurrentY = picWaveform.Width
End Sub
Private Sub DoStop()
Call waveInReset(DevHandle)
Call waveInClose(DevHandle)
DevHandle = 0
picWaveform.Cls
tmr1.Enabled = False
TSCnt2 = 0
OSCnt2 = 0
TSCnt = 0
OSCnt = 0
TMCnt = 0
OMCnt = 0
THCnt = 0
OHCnt = 0
lblTrans2.Caption = THCnt & "(H):" & TMCnt & "(M):" & TSCnt2 & "(S)"
lblOvr2.Caption = OHCnt & "(H):" & OMCnt & "(M):" & OSCnt2 & "(S)"
End Sub
The relevant vb6 form attachment is below
frmRadioBinaryRAM.frm
My main issue is with the line of code that says
Code:
picWaveform.Line Step(0, 0)-(X, InData(X * 2))
In comparison to the 'TrickRecorder' line of code
Code:
picWaveform.Line (pix, picWaveform.ScaleHeight / 2 - value)-(pix, picWaveform.ScaleHeight / 2 + value), color
I know the variable 'value', the value (actual numerical number held inside the variable 'value') can be used to determine the height of an single instance of an amplitude wave. I just dont know how to incorporate the code within TrickRecorder of process 'Redraw' into the code of my new screen of process 'DrawData'. I want to take the initiative and solve it myself but I cant do it in my new scenario. I would stick to the code in 'TrickRecorder' and edit that myself but the memory usage is insane after a length of time and so isnt suitable for what I want to do. Can you help once more 'TheTrick'?
Last edited by greenelephant150; Jan 12th, 2021 at 09:10 AM.
-
Jan 12th, 2021, 05:11 PM
#56
Thread Starter
Member
Re: Converting single bits into a sine waveform
P.S Ive succeeded in working out the formula to create a sawtooth audio wave . I am still stuggling to figure out how to write code for a triangular wave. I know by looking on wikipedia at these two URLs https://en.wikipedia.org/wiki/Sine and https://en.wikipedia.org/wiki/Triangle_wave that a 45° angle in Sine is √2 / 2 But I dont know how to use this information to formulate a successful equation to create a triangular wave pattern. Any ideas?
-
Jan 13th, 2021, 12:43 AM
#57
Re: Converting single bits into a sine waveform
A triangle wave is the same as a saw only mirrored.
I know the variable 'value', the value (actual numerical number held inside the variable 'value') can be used to determine the height of an single instance of an amplitude wave. I just dont know how to incorporate the code within TrickRecorder of process 'Redraw' into the code of my new screen of process 'DrawData'. I want to take the initiative and solve it myself but I cant do it in my new scenario. I would stick to the code in 'TrickRecorder' and edit that myself but the memory usage is insane after a length of time and so isnt suitable for what I want to do. Can you help once more 'TheTrick'?
Just see ScaleMode/ScaleTop/ScaleLeft/ScaleWidth/ScaleHeight properties.
-
Jan 18th, 2021, 10:18 AM
#58
Thread Starter
Member
Re: Converting single bits into a sine waveform
Last edited by greenelephant150; Jan 18th, 2021 at 11:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|