Audio beep @ 192k and 24 bits

Just starting out? Need help? Post your questions and find answers here.
Wolfram
Enthusiast
Enthusiast
Posts: 606
Joined: Thu May 30, 2013 4:39 pm

Re: Audio beep @ 192k and 24 bits

Post by Wolfram »

Hi Simo_na,

you can use the RME Analyser (DIGICheck). This is a very good Analyser.
macOS Catalina 10.15.7
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio beep @ 192k and 24 bits

Post by infratec »

Hi,

as mentioned already: Audacity (Freeware)

Bernd
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio beep @ 192k and 24 bits

Post by Simo_na »

Wolfram wrote:Hi Simo_na,
you can use the RME Analyser (DIGICheck). This is a very good Analyser.
Hi Wolfram, with DIGICheck also sweep... :oops:
and DIGICheck does not drop over -50dBfs

Image
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio beep @ 192k and 24 bits

Post by Simo_na »

infratec wrote:Hi,
as mentioned already: Audacity (Freeware)
Bernd
Thank you Infratec for your work, now i will try it with Audacity ... :)
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio beep @ 192k and 24 bits

Post by Simo_na »

the same with audacity :cry: :cry:
Image
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio beep @ 192k and 24 bits

Post by infratec »

Hi,

found something :!:

If you add the if line after r + SineStep it works.

Code: Select all

r + SineStep
If r > #PI * 2 : r - #PI * 2 : EndIf
But why ???

I changed my last listing.


Bernd
infratec
Always Here
Always Here
Posts: 7625
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio beep @ 192k and 24 bits

Post by infratec »

Maybe it's a float problem:

Code: Select all

Define SineStep.f, i.i, r1.f, r2.f, s1.f, s2.f

SineStep = 0.002
For i = 0 To 1000000
  s1 = Sin(r1)
  s2 = Sin(r2)
  
  If s1 <> s2
    If Abs(s1 - s2) > 0.1
      Debug i
      Debug ""
      Debug r1
      Debug s1
      Debug Sin(r1)
      Debug ""
      Debug r2
      Debug s2
      Debug Sin(r2)
      Debug "-----"
      Break
    EndIf
  EndIf
  
  r1 + SineStep
  
  r2 + SineStep
  If r2 > #PI * 2 : r2 - #PI * 2 : EndIf
Next i
Bernd
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio beep @ 192k and 24 bits

Post by Simo_na »

now work fine !! :D :D :D

from 'BasicallyPure' code: (kindred??)
If La > #PIx2 : La - #PIx2 : EndIf ; limit to 2*PI radians
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio beep @ 192k and 24 bits

Post by Simo_na »

This is my personal version for very long beeps :D

now the code work very fine, this is 997 Hz
Image

(thank you^PI) :mrgreen:

Code: Select all

EnableExplicit

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 CreateSineWAV(*WAVBuffer,Freq.i=997,DurationMs.i=10000)
 
  Protected.i Result,dataOffset,Ptr,i,Value,MaxAmp,twi=2,zer=0,eit=8,one=1,fou=4,sixt=16,sarat=192000,bitsam=24,sev=7
  Protected.f SineStep,r,twf=2.0,durfix=1000.0,eitw=0.8
  Protected *RiffPtr.RIFFStructure,*fmtPtr.fmtStructure,*dataPtr.dataStructure
 
  If *WAVBuffer
    *RiffPtr=*WAVBuffer
    PokeS(@*RiffPtr\Riff,"RIFF",fou,#PB_Ascii|#PB_String_NoZero)
    PokeS(@*RiffPtr\Wave,"WAVE",fou,#PB_Ascii|#PB_String_NoZero)
    *fmtPtr=*WAVBuffer+SizeOf(RIFFStructure)
    PokeS(@*fmtPtr\fmt,"fmt ",fou,#PB_Ascii|#PB_String_NoZero)
    *fmtPtr\Length=SizeOf(fmtStructure)-eit
    *fmtPtr\Format=one
    *fmtPtr\Channels=one
    *fmtPtr\SampleRate=sarat
    *fmtPtr\BitsPerSample=bitsam
    *fmtPtr\BlockAlign=*fmtPtr\Channels*((*fmtPtr\BitsPerSample+sev) / eit)
    *fmtPtr\BytesPerSecond=*fmtPtr\SampleRate**fmtPtr\BlockAlign
    *dataPtr=*WAVBuffer+SizeOf(RIFFStructure)+SizeOf(fmtStructure)
    PokeS(@*dataPtr\Signature,"data",fou,#PB_Ascii|#PB_String_NoZero)
    dataOffset=SizeOf(RIFFStructure)+SizeOf(fmtStructure)+SizeOf(dataStructure)
    Ptr=zer
    SineStep=#PI*twf*Freq / *fmtPtr\SampleRate
    r=zer
    MaxAmp=((twi<<(*fmtPtr\BitsPerSample-twi))-one)*eitw
    Repeat
      Value=Sin(r)*MaxAmp
      r+SineStep
      If r > #PI*twf : r-#PI*twf : EndIf
      PokeA(*WAVBuffer+dataOffset+Ptr,Value & $FF)
      Ptr+one
      PokeA(*WAVBuffer+dataOffset+Ptr,(Value>>eit) & $FF)
      Ptr+one
      PokeA(*WAVBuffer+dataOffset+Ptr,(Value>>sixt) & $FF)
      Ptr+one
    Until Ptr >=  *fmtPtr\BytesPerSecond / durfix*DurationMs
    *dataPtr\Length=Ptr
    *RiffPtr\Length=SizeOf(RIFFStructure)+SizeOf(fmtStructure)+SizeOf(dataStructure)+Ptr-eit
    Result=*RiffPtr\Length+eit
  EndIf
  ProcedureReturn Result
EndProcedure

InitSound()
Define *Buffer,Length.i,mydura.i,myfreq.i
mydura=10000 ; duration
myfreq=997 ; frequency
*Buffer=AllocateMemory(mydura*myfreq*2)
If *Buffer
   Length=CreateSineWAV(*Buffer,myfreq,mydura)
  If Length
       If CreateFile(0,"c:\tmp\test.wav")
      WriteData(0,*Buffer,Length)
      CloseFile(0)
    EndIf
    If CatchSound(0,*Buffer,Length)
      PlaySound(0)
      While SoundStatus(0)=#PB_Sound_Playing
        Delay(10)
      Wend
    EndIf
  EndIf
  FreeMemory(*Buffer)
EndIf
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: Audio beep @ 192k and 24 bits

Post by CONVERT »

Thanks a lot for this code.

I set mydura to 1000

I set myfreq to 289. It works fine.
I set myfreq to 288. It works fine, but with F5, it says "The debugged executable quit unexpectedly" after a few seconds. The .exe takes somes seconds to quit (hourglass end).
I set myfreq to 285. The same as 288.

I set myfreq to 284. It does not work.
With F5, "Invalid memory access. (write error at address 84590592)
and the line 57 is red:
PokeA(*WAVBuffer+dataOffset+Ptr,(Value>>eit) & $FF)

The .exe does not play any sound, and stops after some seconds of hourglass.
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 130
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: Audio beep @ 192k and 24 bits

Post by CONVERT »

Hello,

When I set "myfreq=220", I have an abort at

Code: Select all

PokeA(*WAVBuffer+dataOffset+Ptr,Value & $FF)
after the repeat in CreateSineWAV().

When I change the line

Code: Select all

*Buffer=AllocateMemory(mydura*myfreq*2)
by

Code: Select all

*Buffer = AllocateMemory(44 + (mydura/1000)*sarat * channel * (bitsam / 8))
after InitSound(),

the abort disappears, and it works. And It works for all frequency, at least from 1 to 20000 Hz.

Of course, I had to declare new variables in the root, and add them as parameters in the procedure CreateSineWAV().

Thanks to Froggerprogger Date: 11. March 2005
http://www.purearea.net/pb/CodeArchiv/M ... nMemory.pb

His code is more understable, but has too many compilator errors with the actual Purebasic version.

The code working:

Code: Select all

EnableExplicit

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 CreateSineWAV(*WAVBuffer,Freq.i,DurationMs.i,sarat.i,Channel.i,bitsam.i)
 
  Protected.i Result,dataOffset,Ptr,i,Value,MaxAmp,twi=2,zer=0,eit=8,one=1,fou=4,sixt=16,sev=7
  Protected.f SineStep,r,twf=2.0,durfix=1000.0,eitw=0.8
  Protected *RiffPtr.RIFFStructure,*fmtPtr.fmtStructure,*dataPtr.dataStructure
  
  
 
  If *WAVBuffer
    *RiffPtr=*WAVBuffer
    PokeS(@*RiffPtr\Riff,"RIFF",fou,#PB_Ascii|#PB_String_NoZero)
    PokeS(@*RiffPtr\Wave,"WAVE",fou,#PB_Ascii|#PB_String_NoZero)
    *fmtPtr=*WAVBuffer+SizeOf(RIFFStructure)
    PokeS(@*fmtPtr\fmt,"fmt ",fou,#PB_Ascii|#PB_String_NoZero)
    *fmtPtr\Length=SizeOf(fmtStructure)-eit
    *fmtPtr\Format=one
    *fmtPtr\Channels=Channel
    *fmtPtr\SampleRate=sarat
    *fmtPtr\BitsPerSample=bitsam
    *fmtPtr\BlockAlign=*fmtPtr\Channels*((*fmtPtr\BitsPerSample+sev) / eit)
    *fmtPtr\BytesPerSecond=*fmtPtr\SampleRate**fmtPtr\BlockAlign
    *dataPtr=*WAVBuffer+SizeOf(RIFFStructure)+SizeOf(fmtStructure)
    PokeS(@*dataPtr\Signature,"data",fou,#PB_Ascii|#PB_String_NoZero)
    dataOffset=SizeOf(RIFFStructure)+SizeOf(fmtStructure)+SizeOf(dataStructure)
    Ptr=zer
    SineStep=#PI*twf*Freq / *fmtPtr\SampleRate
    r=zer
    MaxAmp=((twi<<(*fmtPtr\BitsPerSample-twi))-one)*eitw
    
    Repeat
      Value=Sin(r)*MaxAmp
      r+SineStep
      If r > #PI*twf 
        r-#PI*twf
      EndIf
      PokeA(*WAVBuffer+dataOffset+Ptr,Value & $FF)
      Ptr+one
      PokeA(*WAVBuffer+dataOffset+Ptr,(Value>>eit) & $FF)
      Ptr+one
      PokeA(*WAVBuffer+dataOffset+Ptr,(Value>>sixt) & $FF)
      Ptr+one
    Until Ptr >=  *fmtPtr\BytesPerSecond / durfix*DurationMs
    
    *dataPtr\Length=Ptr
    *RiffPtr\Length=SizeOf(RIFFStructure)+SizeOf(fmtStructure)+SizeOf(dataStructure)+Ptr-eit
    Result=*RiffPtr\Length+eit
  EndIf
  ProcedureReturn Result
EndProcedure

InitSound()
Define *Buffer,Length.i,mydura.i,myfreq.i,sarat.i,Channel.i,bitsam.i
mydura=1000 ; duration
myfreq=20000  ; frequency
sarat=192000; sample rate
Channel=1
bitsam=24   ; bitrate

; *Buffer=AllocateMemory(mydura*myfreq*2) 

*Buffer = AllocateMemory(44 + (mydura/1000)*sarat * channel * (bitsam / 8))    ; V03

   Length=CreateSineWAV(*Buffer,myfreq,mydura,sarat,Channel,bitsam)
  If Length
       If CreateFile(0,"test_" + Str(mydura) + "_" + Str(myfreq) + ".wav")
      WriteData(0,*Buffer,Length)
      CloseFile(0)
    EndIf
    If CatchSound(0,*Buffer,Length)
      PlaySound(0)
      While SoundStatus(0)=#PB_Sound_Playing
        Delay(10)
      Wend
    EndIf
  EndIf
  FreeMemory(*Buffer)
PureBasic 6.20 beta 2 (x64) | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled.
Come back to 6.11 LTS 64 bits because of an issue with #PB_ComboBox_UpperCase in ComboBoxGadget() (Oct. 10, 2024).
Post Reply