Derren hat geschrieben:Vielleicht hilft dir das?
Wau .... das wäre es gewesen.
... naja ... fast !!!
Ich hab den alten Code mal auf 5.71 angepasst, aber irgendwie klappt das nicht die erzeugten Daten anschließend mit CatchSound() zu grabben.
Evtl. liegt's daran, dass im Wave-Header einige ASCII Strings drin sind und PB ja komplett auf Unicode umgestellt wurde?
Aber dazu hab' ich aber ja PokeS() angepasst ... sollte meiner Ansicht ja nun so klappen.
Der Wave-Header benötigt doch vermutlich nach wie vor noch die Header-Texte im ASCII Format, oder nicht?
Evtl. 'ne Idee woran's scheitert?
Code: Alles auswählen
EnableExplicit
Structure WAVE
wFormatTag.w
nChannels.w
nSamplesPerSec.l
nAvgBytesPerSec.l
nBlockAlign.w
wBitsPerSample.w
cbSize.w
EndStructure
Procedure MakeSound(nr,Frequency, Duration)
Protected SoundValue.b, Result
Protected w.f; // omega ( 2 * pi * frequency)
#Mono = $0001;
#SampleRate = 11025; // 8000, 11025, 22050, or 44100
#RiffId = "RIFF" ;
#WaveId = "WAVE" ;
#FmtId = "fmt " ;
#DataId = "data" ;
Protected WaveFormatEx.WAVE
WaveFormatEx\wFormatTag = #WAVE_FORMAT_PCM;
WaveFormatEx\nChannels = #Mono ;
WaveFormatEx\nSamplesPerSec = #SampleRate;
WaveFormatEx\wBitsPerSample = $0008 ;
WaveFormatEx\nBlockAlign = (WaveFormatEx\nChannels * WaveFormatEx\wBitsPerSample) /8
WaveFormatEx\nAvgBytesPerSec = WaveFormatEx\nSamplesPerSec * WaveFormatEx\nBlockAlign;
WaveFormatEx\cbSize = 0
Protected DataCount = (Duration * #SampleRate)/1000; // sound data
Protected RiffCount.l = 4+4 +4+ SizeOf(WAVE)+4 +4+ DataCount
Protected *start=AllocateMemory(RiffCount+100)
Protected MS.i=*start
PokeS(MS,#RiffId,4,#PB_Ascii | #PB_String_NoZero) : MS+4 ; 'RIFF'
PokeL(MS,RiffCount) : MS+4 ; file Data size
PokeS(MS,#WaveId,4,#PB_Ascii | #PB_String_NoZero) : MS+4 ; 'WAVE'
PokeS(MS,#FmtId ,4,#PB_Ascii | #PB_String_NoZero) : MS+4 ; 'fmt '
PokeL(MS,SizeOf(WAVE)) : MS+4 ; TWaveFormat data size
PokeW(MS,WaveFormatEx\wFormatTag) : MS+2 ; WaveFormatEx record
PokeW(MS,WaveFormatEx\nChannels) : MS+2
PokeL(MS,WaveFormatEx\nSamplesPerSec) : MS+4
PokeL(MS,WaveFormatEx\nAvgBytesPerSec) : MS+4
PokeW(MS,WaveFormatEx\nBlockAlign) : MS+2
PokeW(MS,WaveFormatEx\wBitsPerSample) : MS+2
PokeW(MS,WaveFormatEx\cbSize) : MS+2
PokeS(MS,#DataId,4,#PB_Ascii | #PB_String_NoZero) : MS+4 ;'data'
PokeL(MS,DataCount) : MS+4 ;sound data size
;{Calculate And write out the tone signal} // now the Data values
Protected i
w = 2 * #PI * Frequency ; omega
For i = 0 To DataCount - 1
;// wt = w *i /SampleRate
;SoundValue := 127 + trunc(127 * Sin(i * w / SampleRate));
SoundValue = 127 + 127 * Sin(i * w / #SampleRate);
PokeB(MS,SoundValue):MS+1 ;
Next
;// you could save the wave tone To file with :
;// MS.Seek(0, soFromBeginning);
;// MS.SaveToFile('C:\MyFile.wav');
;// then reload And play them without having To
;// construct them each time.
;{now play the sound}
;sndPlaySound(MS.Memory, SND_MEMORY Or SND_SYNC);
;MS.Free;
Result = CatchSound(nr,MS)
FreeMemory(*start)
ProcedureReturn Result
EndProcedure
Procedure QuitSound(nr)
StopSound(nr)
FreeSound(nr)
;FreeMemory(nr)
EndProcedure
InitSound()
If MakeSound(0,1100,2000)
PlaySound(0)
Delay(2000)
QuitSound(0)
Else
Debug "ERROR !!! MakeSound() / CachSound() failed" + #CRLF$
EndIf
Debug "done"
PS: Hab im CodeArchiv auch noch einen ähnlichen Code von Froggerprogger gefunden (Create&PlayWAVESoundsInMemory.pb für PB4.0)
Musste natürlich auch angepasst werden ... läuft aber leider genauso wenig.