Habe da gerade einen Code in der Schmiede... ist nicht gerade schön (um nicht pott hässlich zu sagen...) und enthält evtl. noch böse Bugs, aber vielleicht findest Du's ja trotzdem nützlich.
Code: Alles auswählen
DeclareModule pbex_Sound
#PBEX_Sound_Format_PCM = 1
#PBEX_Sound_Format_FLOAT = 3
#PBEX_Sound_Channels_MultiTrack = $00000
#PBEX_Sound_Channels_Mono = $00004
#PBEX_Sound_Channels_Stereo = $00003
#PBEX_Sound_Channels_Quadro = $00033
#PBEX_Sound_Channels_Surround = $00107
#PBEX_Sound_Channels_5point1 = $0003F
#PBEX_Sound_Channels_7point1 = $000FF
#PBEX_Sound_Speaker_FrontLeft = $00001
#PBEX_Sound_Speaker_FrontRight = $00002
#PBEX_Sound_Speaker_FrontCenter = $00004
#PBEX_Sound_Speaker_SubWoofer = $00008 ; Normal=20Hz...20kHz, Subwoofer=20...120Hz
#PBEX_Sound_Speaker_BackLeft = $00010
#PBEX_Sound_Speaker_BackRight = $00020
#PBEX_Sound_Speaker_FrontCenterLeft = $00040
#PBEX_Sound_Speaker_FrontCenterRight = $00080
#PBEX_Sound_Speaker_BackCenter = $00100
#PBEX_Sound_Speaker_SideLeft = $00200
#PBEX_Sound_Speaker_SideRight = $00400
#PBEX_Sound_Speaker_TopCenter = $00800
#PBEX_Sound_Speaker_TopFrontLeft = $01000
#PBEX_Sound_Speaker_TopFrontCenter = $02000
#PBEX_Sound_Speaker_TopFrontRight = $04000
#PBEX_Sound_Speaker_TopBackLeft = $08000
#PBEX_Sound_Speaker_TopBackCenter = $10000
#PBEX_Sound_Speaker_TopBackRight = $20000
#PBEX_Sound_LegacyMode_BITMASK = $0003
#PBEX_Sound_LegacyMode_Off = $0000
#PBEX_Sound_LegacyMode_Prefer = $0001
#PBEX_Sound_LegacyMode_Force = $0002
#PBEX_Sound_CatchMode_BITMASK = $0030
#PBEX_Sound_CatchMode_AutoDetect = $0000
#PBEX_Sound_CatchMode_Normal = $0010
#PBEX_Sound_CatchMode_MoveData = $0020
#PBEX_Sound_CatchMode_PokeHeader = $0030
Declare.i AllocateRawWaveMemory( Size , Flags = #PBEX_Sound_CatchMode_PokeHeader ) ; #PB_Memory_NoClear als Flag möglich
Declare.i CatchRawSound( Sound , *Data , DataBytes , Bits , SamplingRate , Channels = 1 , ChannelFormat = 0 , SoundFormat = #PBEX_Sound_Format_PCM , Flags = #PBEX_Sound_LegacyMode_Off | #PBEX_Sound_CatchMode_AutoDetect )
Declare.i DolbyDigitalChannels( Value1 , Value2 , Value3 = 0 )
Declare.i FreeRawWaveMemory( *RawWaveMemory )
Declare.i PokeWaveHeader( *Memory , WaveBytes , Bits , SamplingRate , Channels , ChannelFormat , SoundFormat , Flags = #PBEX_Sound_LegacyMode_Off )
Declare.i RawWaveMemorySize( *RawWaveMemory , FullSize = #False )
Declare.i ReAllocateRawWaveMemory( *RawWaveMemory , Size , Flags = #PBEX_Sound_CatchMode_AutoDetect ) ; #PB_Memory_NoClear als Flag möglich
EndDeclareModule
Module pbex_Sound
CompilerIf #PB_Any = #PB_Ignore : CompilerError "#PB_Any = #PB_Ignore" : CompilerEndIf
CompilerIf #PB_Ignore >= 0 : CompilerError "#PB_Ignore >= 0" : CompilerEndIf
CompilerIf #PB_Memory_NoClear & #PBEX_Sound_CatchMode_BITMASK : CompilerError "#PB_Memory_NoClear & #PBEX_Sound_CatchMode_BITMASK <> #False" : CompilerEndIf
EnableExplicit
Structure WAVE_EXTENSIBLE
zzz_Align1 .l
AddWaveBytes .l ; FileSize-8 ODER 72+WaveBytes=SizeOf(WAVE_EXTENSIBLE)-8+WaveBytes
zzz_Align2 .u[7]
Channels .u ; Channels
SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
ByteRate .l ; SampleRate * BlockSize
BlockSize .u ; (Bits+7)>>3 * Channels
Bits .u ; Bits (8, 16, 24, 32, 64)
zzz_Align3 .u
BitsValid .u ; = Bits (theoretisch auch z.B. ValidBits=12 und Bits=16)
ChannelMask .l ; 0 (Mono/Mehrkanal) oder #SPEAKER_~ (Stereo/Surround)
Format .u ; #WAVE_FORMAT_~
zzz_Align4 .u[11]
SamplesTotal .l ; Channels * SamplesPerChannel
zzz_Align5 .l
WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
EndStructure
Structure WAVE_FLOAT_LEGACY
zzz_Align1 .l
AddWaveBytes .l ; FileSize-8 ODER 50+WaveBytes=SizeOf(WAVE_FLOAT_LEGACY)-8+WaveBytes
zzz_Align2 .u[7]
Channels .u ; Channels
SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
ByteRate .l ; SampleRate * BlockSize
BlockSize .u ; (Bits+7)>>3 * Channels
Bits .u ; Bits (8, 16, 24, 32, 64)
zzz_Align3 .u[5]
SamplesTotal .l ; Channels * SamplesPerChannel
zzz_Align5 .l
WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
EndStructure
Structure WAVE_PCM_LEGACY
zzz_Align1 .l
AddWaveBytes .l ; FileSize-8 ODER 36+WaveBytes=SizeOf(WAVE_PCM_LEGACY)-8+WaveBytes
zzz_Align2 .u[7]
Channels .u ; Channels
SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
ByteRate .l ; SampleRate * BlockSize
BlockSize .u ; (Bits+7)>>3 * Channels
Bits .u ; Bits <= 16
zzz_Align3 .l
WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
EndStructure
Structure WAVE_UNION
StructureUnion
Extensible.WAVE_EXTENSIBLE
FloatLegacy.WAVE_FLOAT_LEGACY
PcmLegacy.WAVE_PCM_LEGACY
EndStructureUnion
EndStructure
;{ Structure WAVE_EXTENSIBLE_FULL
; a_txt_RIFF .a[4] ; "RIFF"
; b_FileSizeMinus8.l ; FileSize-8 ODER 72+WaveBytes=SizeOf(WAVE_EXTENSIBLE)-8+WaveBytes
; c_txt_WAVE .a[4] ; "WAVE"
; d_txt_fmt .a[4] ; "fmt "
; e_Size40 .l ; (40)
; f_Format .u ; $FFFE (#WAVE_FORMAT_EXTENSIBLE)
; g_Channels .u ; Channels
; h_SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
; i_ByteRate .l ; SampleRate * BlockSize
; j_BlockSize .u ; (Bits+7)>>3 * Channels
; k_Bits .u ; Bits (8, 16, 24, 32, 64)
; l_Size22 .u ; (22)
; m_ValidBits .u ; = Bits (theoretisch auch z.B. ValidBits=12 und Bits=16)
; n_ChannelMask .l ; 0 (Mono/Mehrkanal) oder #SPEAKER_~ (Stereo/Surround)
; o_SubFormat .u ; #WAVE_FORMAT_~
; p_FixedSubFormat.a[14] ; fester SubFormat-Wert (siehe gleichnamiges Label)
; q_txt_fact .a[4] ; "fact"
; r_Size4 .l ; (4)
; s_SamplesTotal .l ; Channels * SamplesPerChannel
; t_txt_data .a[4] ; "data"
; u_WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
;} EndStructure
;{ Structure WAVE_FLOAT_LEGACY_FULL
; a_txt_RIFF .a[4] ; "RIFF"
; b_FileSizeMinus8.l ; FileSize-8 ODER 50+WaveBytes=SizeOf(WAVE_FLOAT_LEGACY)-8+WaveBytes
; c_txt_WAVE .a[4] ; "WAVE"
; d_txt_fmt .a[4] ; "fmt "
; e_Size18 .l ; (18)
; f_Format .u ; 3 (#WAVE_FORMAT_IEEE_FLOAT)
; g_Channels .u ; Channels
; h_SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
; i_ByteRate .l ; SampleRate * BlockSize
; j_BlockSize .u ; (Bits+7)>>3 * Channels
; k_Bits .u ; Bits (8, 16, 24, 32, 64)
; l_Size0 .u ; (0)
; m_txt_fact .a[4] ; "fact"
; n_Size4 .l ; (4)
; o_SamplesTotal .l ; Channels * SamplesPerChannel
; p_txt_data .a[4] ; "data"
; q_WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
;} EndStructure
;{ Structure WAVE_PCM_LEGACY_FULL
; a_txt_RIFF .a[4] ; "RIFF"
; b_FileSizeMinus8.l ; FileSize-8 ODER 36+WaveBytes=SizeOf(WAVE_PCM_LEGACY)-8+WaveBytes
; c_txt_WAVE .a[4] ; "WAVE"
; d_txt_fmt .a[4] ; "fmt "
; e_Size16 .l ; (16)
; f_Format .u ; 1 (#WAVE_FORMAT_PCM)
; g_Channels .u ; Channels
; h_SampleRate .l ; SampleRate (8000, 11025, 22050, 44100, 48000, 96000, ...)
; i_ByteRate .l ; SampleRate * BlockSize
; j_BlockSize .u ; (Bits+7)>>3 * Channels
; k_Bits .u ; Bits <= 16
; l_txt_data .a[4] ; "data"
; m_WaveBytes .l ; BlockSize * Samples; (WaveBytes+1)&~1 (damit gerade!)
;} EndStructure
;{ Structure WAVE_UNION_FULL
; StructureUnion
; Extensible.WAVE_EXTENSIBLE_FULL
; FloatLegacy.WAVE_FLOAT_LEGACY_FULL
; PcmLegacy.WAVE_PCM_LEGACY_FULL
; EndStructureUnion
;} EndStructure
Structure RawWaveMemory
real.i
wave.i
mode.i
EndStructure
NewList RawWaveMemory.RawWaveMemory()
Procedure.i AllocateRawWaveMemory( Size , Flags = #PBEX_Sound_CatchMode_PokeHeader ) ; #PB_Memory_NoClear als Flag möglich
Shared RawWaveMemory()
Define Ergebnis , *Memory , Offset , CatchMode
If Size
CatchMode = Flags & #PBEX_Sound_CatchMode_BITMASK
Select CatchMode
Case #PBEX_Sound_CatchMode_PokeHeader
Size = SizeOf( WAVE_EXTENSIBLE ) + ( Size + 1 ) & ~1
Offset = SizeOf( WAVE_EXTENSIBLE )
Case #PBEX_Sound_CatchMode_MoveData
Size = SizeOf( WAVE_EXTENSIBLE ) + ( Size + 1 ) & ~1
;Offset = 0
Case #PBEX_Sound_CatchMode_Normal
Size = ( Size + 1 ) & ~1
;Offset = 0
Default ; #PBEX_Sound_CatchMode_AutoDetect
ProcedureReturn #False
EndSelect
*Memory = AllocateMemory( Size , Flags & #PB_Memory_NoClear )
If *Memory
If AddElement( RawWaveMemory() )
RawWaveMemory()\real = *Memory
RawWaveMemory()\wave = *Memory + Offset
RawWaveMemory()\mode = CatchMode
Ergebnis = RawWaveMemory()\wave
Else
FreeMemory( *Memory )
EndIf
EndIf
EndIf
ProcedureReturn Ergebnis
EndProcedure
Procedure.i ReAllocateRawWaveMemory( *RawWaveMemory , Size , Flags = #PBEX_Sound_CatchMode_AutoDetect ) ; #PB_Memory_NoClear als Flag möglich
Shared RawWaveMemory()
Define Ergebnis , *NewMemory , Offset , MemMoved
Define CatchMode = Flags & #PBEX_Sound_CatchMode_BITMASK
Define Memory_NoClear = Flags & #PB_Memory_NoClear
If Size
If *RawWaveMemory
ForEach RawWaveMemory()
If RawWaveMemory()\wave = *RawWaveMemory
Size = ( Size + 1 ) & ~1
Offset = RawWaveMemory()\wave - RawWaveMemory()\real
If CatchMode = #PBEX_Sound_CatchMode_AutoDetect
CatchMode = RawWaveMemory()\mode
EndIf
If RawWaveMemory()\mode <> CatchMode And RawWaveMemory()\wave <> RawWaveMemory()\real
MoveMemory( RawWaveMemory()\wave , RawWaveMemory()\real , MemorySize( RawWaveMemory()\real ) - Offset )
MemMoved = #True
EndIf
*NewMemory = ReAllocateMemory( RawWaveMemory()\real , Size + Offset , Memory_NoClear )
If *NewMemory
RawWaveMemory()\real = *NewMemory
RawWaveMemory()\wave = *NewMemory + Offset
RawWaveMemory()\mode = CatchMode
If MemMoved And RawWaveMemory()\real <> RawWaveMemory()\wave
MoveMemory( RawWaveMemory()\real , RawWaveMemory()\wave , Size )
EndIf
Ergebnis = RawWaveMemory()\wave
ElseIf MemMoved And RawWaveMemory()\real <> RawWaveMemory()\wave
MoveMemory( RawWaveMemory()\real , RawWaveMemory()\wave , MemorySize( RawWaveMemory()\real ) - Offset )
EndIf
Break
EndIf
Next
Else
Ergebnis = AllocateRawWaveMemory( Size , Flags )
EndIf
EndIf
ProcedureReturn Ergebnis
EndProcedure
Procedure.i FreeRawWaveMemory( *RawWaveMemory )
Shared RawWaveMemory()
ForEach RawWaveMemory()
If RawWaveMemory()\wave = *RawWaveMemory
FreeMemory( RawWaveMemory()\real )
DeleteElement( RawWaveMemory() )
ProcedureReturn #True
EndIf
Next
ProcedureReturn #False
EndProcedure
Procedure.i RawWaveMemorySize( *RawWaveMemory , ReturnFullSize = #False )
Shared RawWaveMemory()
ForEach RawWaveMemory()
If RawWaveMemory()\wave = *RawWaveMemory
If ReturnFullSize
ProcedureReturn MemorySize( RawWaveMemory()\real )
Else
ProcedureReturn MemorySize( RawWaveMemory()\real ) - ( RawWaveMemory()\wave - RawWaveMemory()\real )
EndIf
EndIf
Next
ProcedureReturn #False
EndProcedure
Procedure.i PokeWaveHeader( *Memory.WAVE_UNION , WaveBytes , Bits , SamplingRate , Channels , ChannelFormat , SoundFormat , Flags = #PBEX_Sound_LegacyMode_Off )
Define LegacyMode = Flags & #PBEX_Sound_LegacyMode_BITMASK
Define WaveBytes = ( WaveBytes + 1 ) & ~1
If LegacyMode = #PBEX_Sound_LegacyMode_Off
If *Memory
CopyMemory( ?Header_WAVE_EXTENSIBLE , *Memory , SizeOf( WAVE_EXTENSIBLE ) )
With *Memory\Extensible
\Format = SoundFormat
\SampleRate = SamplingRate
\Channels = Channels
\ChannelMask = ChannelFormat
\Bits = ( Bits + 7 ) & ~7
\BitsValid = Bits
\BlockSize = \Bits>>3 * \Channels
\ByteRate = \SampleRate * \BlockSize
\WaveBytes = WaveBytes
\SamplesTotal = \WaveBytes / \BlockSize
\AddWaveBytes + \WaveBytes
EndWith
EndIf
ProcedureReturn SizeOf( WAVE_EXTENSIBLE )
ElseIf SoundFormat = #PBEX_Sound_Format_FLOAT
If *Memory = 0 Or LegacyMode = #PBEX_Sound_LegacyMode_Force Or ( Channels <= 2 And Bits & ~7 = 0 And ChannelFormat = 0 )
If *Memory
CopyMemory( ?Header_WAVE_FLOAT_LEGACY , *Memory , SizeOf( WAVE_FLOAT_LEGACY ) )
With *Memory\FloatLegacy
\SampleRate = SamplingRate
\Channels = Channels
\Bits = Bits
\BlockSize = \Bits>>3 * \Channels
\ByteRate = \SampleRate * \BlockSize
\WaveBytes = WaveBytes
\SamplesTotal = \WaveBytes / \BlockSize
\AddWaveBytes + \WaveBytes
EndWith
EndIf
ProcedureReturn SizeOf( WAVE_FLOAT_LEGACY )
EndIf
ElseIf SoundFormat = #PBEX_Sound_Format_PCM
If *Memory = 0 Or LegacyMode = #PBEX_Sound_LegacyMode_Force Or ( Bits <= 16 And Channels <= 2 And Bits & ~7 = 0 And ChannelFormat = 0 )
If *Memory
CopyMemory( ?Header_WAVE_PCM_LEGACY , *Memory , SizeOf( WAVE_PCM_LEGACY ) )
With *Memory\PcmLegacy
\SampleRate = SamplingRate
\Channels = Channels
\Bits = Bits
\BlockSize = Bits>>3 * Channels
\ByteRate = \SampleRate * \BlockSize
\WaveBytes = WaveBytes
\AddWaveBytes + \WaveBytes
EndWith
EndIf
ProcedureReturn SizeOf( WAVE_PCM_LEGACY )
EndIf
EndIf
If LegacyMode = #PBEX_Sound_LegacyMode_Prefer
ProcedureReturn PokeWaveHeader( *Memory , WaveBytes , Bits , SamplingRate , Channels , ChannelFormat , SoundFormat , #PBEX_Sound_LegacyMode_Off )
EndIf
ProcedureReturn #False
EndProcedure
Procedure.i CatchRawSound( Sound , *RawData , DataBytes , Bits , SamplingRate , Channels = 1 , ChannelFormat = 0 , SoundFormat = #PBEX_Sound_Format_PCM , Flags = #PBEX_Sound_LegacyMode_Off | #PBEX_Sound_CatchMode_AutoDetect )
Shared RawWaveMemory()
Define Ergebnis
Define LegacyMode = Flags & #PBEX_Sound_LegacyMode_BITMASK
Define CatchMode = Flags & #PBEX_Sound_CatchMode_BITMASK
If CatchMode = #PBEX_Sound_CatchMode_AutoDetect
ForEach RawWaveMemory()
If RawWaveMemory()\wave = *RawData
Break
EndIf
Next
If ListSize( RawWaveMemory() ) And RawWaveMemory()\wave = *RawData
CatchMode = RawWaveMemory()\mode
Else
CatchMode = #PBEX_Sound_CatchMode_Normal
EndIf
EndIf
Define AlignedDataBytes = ( DataBytes + 1 ) & ~1
Define *Wave.WAVE_EXTENSIBLE
Define HeaderSize = PokeWaveHeader( 0 , DataBytes , Bits , SamplingRate , Channels , ChannelFormat , SoundFormat , Flags )
If HeaderSize And *RawData
Select CatchMode
Case #PBEX_Sound_CatchMode_Normal
*Wave.WAVE_EXTENSIBLE = AllocateMemory( SizeOf( WAVE_EXTENSIBLE ) + AlignedDataBytes , #PB_Memory_NoClear )
Case #PBEX_Sound_CatchMode_MoveData
*Wave.WAVE_EXTENSIBLE = *RawData
Case #PBEX_Sound_CatchMode_PokeHeader
*Wave.WAVE_EXTENSIBLE = *RawData - HeaderSize
EndSelect
If *Wave
Define *WaveData = *Wave + HeaderSize
If CatchMode = #PBEX_Sound_CatchMode_MoveData
MoveMemory( *RawData , *WaveData , DataBytes )
EndIf
PokeWaveHeader( *Wave , DataBytes , Bits , SamplingRate , Channels , ChannelFormat , SoundFormat , Flags )
If CatchMode = #PBEX_Sound_CatchMode_Normal
CopyMemory( *RawData , *WaveData , DataBytes )
EndIf
If DataBytes < AlignedDataBytes
PokeB( *WaveData + DataBytes , 0 )
EndIf
Ergebnis = CatchSound(Sound, *Wave)
EndIf
EndIf
If *Wave And CatchMode = #PBEX_Sound_CatchMode_Normal
FreeMemory(*Wave)
EndIf
ProcedureReturn Ergebnis
EndProcedure
Procedure.i DolbyDigitalChannels( Number1 , Number2 , Number3 = 0 )
If Number1 & ~7 Or Number2 & ~3 Or Number3 & ~1 : ProcedureReturn #False : EndIf
Define Ergebnis
If Number1 & 1 : Ergebnis | #PBEX_Sound_Speaker_FrontCenter : EndIf
If Number1 & 2 : Ergebnis | #PBEX_Sound_Speaker_FrontLeft | #PBEX_Sound_Speaker_FrontRight : EndIf
If Number1 & 4 : Ergebnis | #PBEX_Sound_Speaker_FrontCenterLeft | #PBEX_Sound_Speaker_FrontCenterRight : EndIf
If Number2 & 1 : Ergebnis | #PBEX_Sound_Speaker_BackCenter : EndIf
If Number2 & 2 : Ergebnis | #PBEX_Sound_Speaker_BackLeft | #PBEX_Sound_Speaker_BackRight : EndIf
If Number3 & 1 : Ergebnis | #PBEX_Sound_Speaker_SubWoofer : EndIf
ProcedureReturn Ergebnis
EndProcedure
DataSection
Header_WAVE_EXTENSIBLE: ;{
Data.a 'R','I','F','F' ; "RIFF"
Data.l 72 ; FileSize-8 ODER 72+WaveBytes=SizeOf(WAVE_EXTENSIBLE)-8+WaveBytes
Data.a 'W','A','V','E' ; "WAVE"
Data.a 'f','m','t',' ' ; "fmt "
Data.l 40 ; 40
Data.u $FFFE ; $FFFE (#WAVE_FORMAT_EXTENSIBLE)
Data.u 0 ; 2 Byte: Channels
Data.l 0 ; 4 Byte: SampleRate
Data.l 0 ; 4 Byte: ByteRate
Data.u 0 ; 2 Byte: BlockSize
Data.u 0 ; 2 Byte: Bits
Data.u 22 ; 22
Data.u 0 ; 2 Byte: ValidBits
Data.l 0 ; 4 Byte: ChannelMask
Data.q $0010000000000000 ; 2 Byte: SubFormat (#WAVE_FORMAT_~)
Data.q $719B3800AA000080 ; ...
Data.a 'f','a','c','t' ; "fact"
Data.l 4 ; 4
Data.l 0 ; SamplesTotal (Channels * SamplesPerChannel)
Data.a 'd','a','t','a' ; "data"
Data.l 0 ; 4 Byte: WaveBytes
EndHeader_WAVE_EXTENSIBLE: ;}
Header_WAVE_FLOAT_LEGACY: ;{
Data.a 'R','I','F','F' ; "RIFF"
Data.l 50 ; FileSize-8 ODER 50+WaveBytes=SizeOf(WAVE_FLOAT_LEGACY)-8+WaveBytes
Data.a 'W','A','V','E' ; "WAVE"
Data.a 'f','m','t',' ' ; "fmt "
Data.l 18 ; 18
Data.u 3 ; 3 (#WAVE_FORMAT_IEEE_FLOAT)
Data.u 0 ; 2 Byte: Channels
Data.l 0 ; 4 Byte: SampleRate
Data.l 0 ; 4 Byte: ByteRate
Data.u 0 ; 2 Byte: BlockSize
Data.u 0 ; 2 Byte: Bits
Data.u 0 ; 0
Data.a 'f','a','c','t' ; "fact"
Data.l 4 ; 4
Data.l 0 ; SamplesTotal (Channels * SamplesPerChannel)
Data.a 'd','a','t','a' ; "data"
Data.l 0 ; 4 Byte: WaveBytes
EndHeader_WAVE_FLOAT_LEGACY: ;}
Header_WAVE_PCM_LEGACY: ;{
Data.a 'R','I','F','F' ; "RIFF"
Data.l 36 ; FileSize-8 ODER 36+WaveBytes=SizeOf(WAVE_PCM_LEGACY)-8+WaveBytes
Data.a 'W','A','V','E' ; "WAVE"
Data.a 'f','m','t',' ' ; "fmt "
Data.l 16 ; 16
Data.u 1 ; 1 (#WAVE_FORMAT_PCM)
Data.u 0 ; 2 Byte: Channels
Data.l 0 ; 4 Byte: SampleRate
Data.l 0 ; 4 Byte: ByteRate
Data.u 0 ; 2 Byte: BlockSize
Data.u 0 ; 2 Byte: Bits
Data.a 'd','a','t','a' ; "data"
Data.l 0 ; 4 Byte: WaveBytes
EndHeader_WAVE_PCM_LEGACY: ;}
EndDataSection
EndModule
;{ ==== TESTCODE ====
CompilerIf #True And #PB_Compiler_IsMainFile And #PB_Compiler_Debugger
EnableExplicit
;XIncludeFile #PB_Compiler_FilePath + "pbex_Constants.pbi"
;XIncludeFile #PB_Compiler_FilePath + "pbex_Math.pbi"
;UseModule pbex_Constants
;UseModule pbex_Math
InitSound()
UseModule pbex_Sound
CompilerSelect 3
CompilerCase 1
Define i, *mem = AllocateMemory(44100 * SizeOf(Word) + 1)
Define *w.Word = *mem
For i = 1 To 44100
;*w\w = #WordMax * RandomD(1.0, -1.0)
;*w\w = #WordMax * Sin(#PI2 * i*1000/44100)
*w\w = $7FFF * Sin(#PI*2 * i*1000/44100)
*w + SizeOf(Word)
Next i
Debug CatchRawSound(0, *mem, MemorySize(*mem), 16, 44100)
Debug PlaySound(0)
MessageRequester("","")
CompilerCase 2
Define i, *mem = AllocateMemory(44100 * SizeOf(Float))
Define *f.Float = *mem
For i = 1 To 44100
;*w\w = #WordMax * RandomD(1.0, -1.0)
;*f\f = Sin(#pi2 * i*1000/44100)
*f\f = Sin(#PI*2 * i*1000/44100)
*f + SizeOf(Float)
Next i
Debug CatchRawSound(0, *mem, MemorySize(*mem), 32, 44100, 1, 0, #PBEX_Sound_Format_FLOAT)
Debug PlaySound(0)
MessageRequester("","")
CompilerCase 3
Define i, *mem = AllocateMemory(44100 * SizeOf(Float))
Define *f.Float = *mem
For i = 1 To 44100
;*f\f = Sin( #pi2 * i * 220 / 44100 )
*f\f = Sin( #PI*2 * i * 220 / 44100 )
If *f\f >= 0.0
*f\f = 1.0
Else
*f\f = -1.0
EndIf
*f + SizeOf(Float)
Next i
Debug CatchRawSound(0, *mem, MemorySize(*mem), 32, 44100, 1, 0, #PBEX_Sound_Format_FLOAT)
Debug PlaySound(0)
MessageRequester("","")
CompilerEndSelect
CompilerEndIf
;} ==== TESTCODE ====