Audio MultiTone 48000 Hz @ 24 Bit

Just starting out? Need help? Post your questions and find answers here.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Audio MultiTone 48000 Hz @ 24 Bit

Post by Simo_na »

it's possible to do something like this? :)
Image
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by infratec »

If there is a will, there is a way :mrgreen:


http://www.purebasic.fr/english/viewtop ... 12&t=31250
Oh, I see you found it already.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by Simo_na »

I'm sorry, I meant that I would like to create a Audio Multi-Tone 48000 Hz @ 24 Bit, sorry again.. :oops: :oops:
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by infratec »

What do you mean with a 'Audio Multi-Tone 48000 Hz' :?:

A tone with a frequence of 48000Hz is a single tone and never somehing with multi.

When I again look in my crystal ball I see that you can mean something like:

I want a sound which generates the shown FFT spectrum at a sample rate of 48000 and 24bits

Is this correct?

If yes, tell us exactly the frequencies at the peeks, because the picture is a bit small for this.
It looks like an addition of exact sinewaves with different frequencies.
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by Simo_na »

infratec wrote:It looks like an addition of exact sinewaves with different frequencies.
correct :D
sample rate of 48000 and 24bits
in Hz :
80
125
200
315
500
800
1250
2000
3150
5000
8000
12500
16000

is, is a sum of sinusoids with a peak level such as not to generate distortion when playing all together
PS
perhaps , each of the sine waves have approximately -12 dBFS
infratec
Always Here
Always Here
Posts: 7618
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by infratec »

Maybe this works:

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.f 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
      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


Structure SoundStructure
  Frequency.i
  *Buffer
  Sound.i
EndStructure


NewList SoundList.SoundStructure()

If InitSound()
  
  AddElement(SoundList())
  SoundList()\Frequency = 80
  
  AddElement(SoundList())
  SoundList()\Frequency = 125
  
  AddElement(SoundList())
  SoundList()\Frequency = 200
  
  AddElement(SoundList())
  SoundList()\Frequency = 315
  
  AddElement(SoundList())
  SoundList()\Frequency = 500
  
  AddElement(SoundList())
  SoundList()\Frequency = 800
  
  AddElement(SoundList())
  SoundList()\Frequency = 1250
  
  AddElement(SoundList())
  SoundList()\Frequency = 2000
  
  AddElement(SoundList())
  SoundList()\Frequency = 3150
  
  AddElement(SoundList())
  SoundList()\Frequency = 5000
  
  AddElement(SoundList())
  SoundList()\Frequency = 8000
  
  AddElement(SoundList())
  SoundList()\Frequency = 12500
  
  AddElement(SoundList())
  SoundList()\Frequency = 16000
  
  
  ForEach SoundList()
    SoundList()\Buffer = CreateSine24BitMonoWAV(48000, SoundList()\Frequency)
    If SoundList()\Buffer
      SoundList()\Sound = CatchSound(#PB_Any, SoundList()\Buffer)
      If SoundList()\Sound
        PlaySound(SoundList()\Sound, #PB_Sound_Loop)
      EndIf
    EndIf
  Next
  
  Delay(3000)
  
  ForEach SoundList()
    If SoundList()\Buffer
      If SoundList()\Sound
        StopSound(SoundList()\Sound)
      EndIf
      FreeMemory(SoundList()\Buffer)
    EndIf
  Next
  
EndIf
At the moment I can not record it to make a FFT.

But 16000Hz at 48000 samplingrate makes not really sense.
You get 3 points, which is definately not a sinewave.

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

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by Simo_na »

Thank you Infratec, now i will proof and study your code and will publish the optimized code, i will try... 8) :D
Simo_na
Enthusiast
Enthusiast
Posts: 177
Joined: Sun Mar 03, 2013 9:01 am

Re: Audio MultiTone 48000 Hz @ 24 Bit

Post by Simo_na »

i have set this frequency
AddElement(SoundList())
SoundList()\Frequency = 10000

but i get 12000 Hz in my 'Visual Analizer'
:oops:

i try to set 88200 Hz here
SoundList()\Buffer = CreateSine24BitMonoWAV(48000, SoundList()\Frequency)

but i get 11000 Hz in my 'Visual Analizer'

:oops:
Post Reply