want to write an emulator for an 'phasewheel' which delivers the rpm and the position of cylinders to the ECU.
The wheel has many teeth with a few missing to show a special position.
My idea was to create a sound with this as waveform. So far so good.
Now I want to setup different speeds.
I thought it is possible with SetSoundFrequency().
But I don't know what it does.
The second parameter is definately not the frequency.
An example:
Code: Select all
EnableExplicit
Structure RIFFStructure
Riff.s{4}
Length.l
Wave.s{4}
EndStructure
Structure fmtStructure
fmt.s{4}
Length.l
Format.u
Channels.u
SampleRate.l
BytesPerSecond.l
BlockAlign.u
BitsPerSample.u
EndStructure
Structure dataStructure
Signature.s{4}
Length.l
EndStructure
Procedure.i CreateSineWAV(*WAVBuffer)
Protected.i Result, dataOffset, Ptr, i
Protected *RiffPtr.RIFFStructure, *fmtPtr.fmtStructure, *dataPtr.dataStructure
If *WAVBuffer
*RiffPtr = *WAVBuffer
*RiffPtr\Riff = "RIFF"
*RiffPtr\Wave = "WAVE"
*fmtPtr = *WAVBuffer + SizeOf(RIFFStructure)
*fmtPtr\fmt = "fmt "
*fmtPtr\Length = SizeOf(fmtStructure) - 8
*fmtPtr\Format = 1
*fmtPtr\Channels = 1
*fmtPtr\SampleRate = 44100
*fmtPtr\BitsPerSample = 16
*fmtPtr\BlockAlign = *fmtPtr\Channels * ((*fmtPtr\BitsPerSample + 7) / 8)
*fmtPtr\BytesPerSecond = *fmtPtr\SampleRate * *fmtPtr\BlockAlign
*dataPtr = *WAVBuffer + SizeOf(RIFFStructure) + SizeOf(fmtStructure)
*dataPtr\Signature = "data"
dataOffset = SizeOf(RIFFStructure) + SizeOf(fmtStructure) + SizeOf(dataStructure)
Ptr = 0
For i = 0 To 359
PokeW(*WAVBuffer + dataOffset + Ptr, Sin(Radian(i)) * 30000)
Ptr + 2
Next i
*dataPtr\Length = Ptr
*RiffPtr\Length = SizeOf(RIFFStructure) + SizeOf(fmtStructure) + SizeOf(dataStructure) + Ptr - 8
;ShowMemoryViewer(*WAVBuffer, *RiffPtr\Length + 8)
Result = #True
EndIf
ProcedureReturn Result
EndProcedure
InitSound()
Define *Buffer
*Buffer = AllocateMemory(1024)
If *Buffer
If CreateSineWAV(*Buffer)
Debug "Created"
If CatchSound(0, *Buffer)
Debug "Play"
PlaySound(0, #PB_Sound_Loop)
Delay(3000)
Debug "Play 44100"
SetSoundFrequency(0, 44100)
Delay(3000)
EndIf
EndIf
FreeMemory(*Buffer)
EndIf
That's also what you can hear during the first 3 seconds.
Than I tried to use SetSoundFrequency()...
Not really successfull.
If I use the samplerate as 'frequency', than I see and hear the same sound.
Can anyone explain what exactly SetSoundFrequency() does?
Or is it a bug?
Bernd
P.S.: disable 'create unicode executable' in compiler options!