TIA ,
How can I generate a tone (a specific Frequency , perhaps A 440 ) ?
I see Frequency examples , but they come from a .ogg file .
Can't find any docs for Beep .
A simple example like:
[Play Tone] Button , [Stop Play] Button .
Generate a tone .pb example ?
Generate a tone .pb example ?
vmars.us Win11 x64 , Martin 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."
Re: Generate a tone .pb example ?
Maybe something like that:
https://www.purebasic.fr/english/viewto ... 06#p467606
Or simply:
https://docs.microsoft.com/en-us/window ... piset-beep
But you can not stop Beep_(). So my solution is more what you want.
https://www.purebasic.fr/english/viewto ... 06#p467606
Code: Select all
Structure RIFFStructure
Riff.a[4]
Length.l
Wave.a[4]
EndStructure
Structure fmtStructure
fmt.a[4]
Length.l
Format.u
Channels.u
SampleRate.l
BytesPerSecond.l
BlockAlign.u
BitsPerSample.u
EndStructure
Structure dataStructure
Signature.a[4]
Length.l
EndStructure
Procedure.i CreateSine24BitMonoWAV(SampleRate.i, Freq.i)
Protected.i i, n, Points, HeaderSize, DataSize, File, Value
Protected.d StepWidth, Angle
Protected *WAVBuffer, *RiffPtr.RIFFStructure, *fmtPtr.fmtStructure, *dataPtr.dataStructure, *audioPtr
Points = SampleRate / Freq
Debug "Points per wave: " + Str(Points)
HeaderSize = SizeOf(RIFFStructure)
HeaderSize + SizeOf(fmtStructure)
HeaderSize + SizeOf(dataStructure)
DataSize + (Points * 3)
*WAVBuffer = AllocateMemory(HeaderSize + DataSize)
If *WAVBuffer
*RiffPtr = *WAVBuffer
PokeS(@*RiffPtr\Riff, "RIFF", 4, #PB_Ascii|#PB_String_NoZero)
*RiffPtr\Length = HeaderSize + DataSize - 8
PokeS(@*RiffPtr\Wave, "WAVE", 4, #PB_Ascii|#PB_String_NoZero)
*fmtPtr = *WAVBuffer + SizeOf(RIFFStructure)
PokeS(@*fmtPtr\fmt, "fmt ", 4, #PB_Ascii|#PB_String_NoZero)
*fmtPtr\Length = SizeOf(fmtStructure) - 8
*fmtPtr\Format = 1
*fmtPtr\Channels = 1
*fmtPtr\SampleRate = SampleRate
*fmtPtr\BitsPerSample = 24
*fmtPtr\BlockAlign = *fmtPtr\Channels * ((*fmtPtr\BitsPerSample + 7) / 8)
*fmtPtr\BytesPerSecond = *fmtPtr\SampleRate * *fmtPtr\BlockAlign
*dataPtr = *WAVBuffer + SizeOf(RIFFStructure) + SizeOf(fmtStructure)
PokeS(@*dataPtr\Signature, "data", 4, #PB_Ascii|#PB_String_NoZero)
*dataPtr\Length = DataSize
*audioPtr = *WAVBuffer + SizeOf(RIFFStructure) + SizeOf(fmtStructure) + SizeOf(dataStructure) ; just behind the wav header
StepWidth = 2 * #PI / Points
For n = 0 To Points - 1
Value = Sin(Angle) * 8385000 ; max. $7FFFFF -> 100% better 80% -> 6710880 ($666660)
PokeA(*audioPtr + 2, (Value >> 16) & $FF)
PokeA(*audioPtr + 1, (Value >> 8) & $FF)
PokeA(*audioPtr + 0, (Value) & $FF)
Angle + StepWidth
*audioPtr + 3
Next n
EndIf
ProcedureReturn *WAVBuffer
EndProcedure
If InitSound()
*Buffer = CreateSine24BitMonoWAV(48000, 440)
If *Buffer
; If CreateFile(0, "Sine24BitMono.wav")
; WriteData(0, *Buffer, MemorySize(*Buffer))
; CloseFile(0)
; EndIf
Sound = CatchSound(#PB_Any, *Buffer)
If Sound
PlaySound(Sound, #PB_Sound_Loop)
Delay(3000)
StopSound(Sound)
EndIf
FreeMemory(*Buffer)
EndIf
EndIf
https://docs.microsoft.com/en-us/window ... piset-beep
Code: Select all
Beep_(440, 3000)
Re: Generate a tone .pb example ?
Thank you very much , infratec !
Your "Re: Audio MultiTone 48000 Hz @ 24 Bit" Answer is quite interesting also .
viewtopic.php?p=467606#p467606
Thanks
Your "Re: Audio MultiTone 48000 Hz @ 24 Bit" Answer is quite interesting also .
viewtopic.php?p=467606#p467606
Thanks
vmars.us Win11 x64 , Martin 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."
Re: Generate a tone .pb example ?
If you save the file to disk and open it with Audacity, you can 'see' the wave.
Re: Generate a tone .pb example ?
Thanks again !
vmars.us Win11 x64 , Martin 000-16 (1995)
"All things in moderation , except for love and forgiveness."
"All things in moderation , except for love and forgiveness."