Frequenz Modulations Synthese

Previous topic - Next topic

S. P. Gardebiter

Falls irgendjemand dran interessiert ist.
Der Sourcecode ist vielleicht etwas schwer zu verstehen :o
Falls es Fragen gibt einfach an mich wenden.
Dieser Code gibt als Output nur Rohdaten aus, Format ist Mono bei 44100 Hz, signiertert, 16-Bit PCM.

Code (glbasic) Select
CountX = 0
CountY = 0
DIM Count[16]
DIM CountZ[16]

SampleRate = 44100

NumInstruments = 2
Samples = 0

// Für Noten und erzeugung des Tones
DIM Volume[8192][16]
DIM Frequency[8192][16]
DIM Length[8192][16]
DIM Volume[8192][16]
DIM Note[120]
DIM CurrentLength[16]
DIM TotalLength[16]
// Für die Frequenz Modulations Synthese
DIM FMS[16]
DIM FMFrequency[16]
DIM FMFineTune[16]
DIM FMShift[16]
DIM FMVolume[16]
DIM Sample[16]
// Noten, Notenlänge und Lautstärke definieren
Frequency[0][0] = 29
Frequency[1][0] = 32
Frequency[2][0] = 34
Frequency[3][0] = 36
Frequency[4][0] = 37
Frequency[5][0] = 41
Frequency[6][0] = 34
Frequency[7][0] = 41
Frequency[8][0] = 46
Frequency[9][0] = 48
Frequency[10][0] = 49
Frequency[11][0] = 46
Frequency[12][0] = 48
Frequency[13][0] = 44
Frequency[14][0] = 41
Frequency[15][0] = 34
Frequency[16][0] = 36
Frequency[17][0] = 37
Frequency[18][0] = 41
Frequency[19][0] = 34
Frequency[20][0] = 33
Frequency[21][0] = 34
Frequency[22][0] = 36
Frequency[23][0] = 37
Frequency[24][0] = 41
Frequency[25][0] = 37
Frequency[26][0] = 36
Frequency[27][0] = 34
Frequency[28][0] = 36
Frequency[29][0] = 37
Frequency[30][0] = 39
Frequency[31][0] = 41
Frequency[32][0] = 44
Frequency[33][0] = 46
Frequency[0][1] = 25
Frequency[1][1] = 28
Frequency[2][1] = 30
Frequency[3][1] = 32
Frequency[4][1] = 34
Frequency[5][1] = 37
Frequency[6][1] = 29
Frequency[7][1] = 37
Frequency[8][1] = 41
Frequency[9][1] = 41
Frequency[10][1] = 41
Frequency[11][1] = 37
Frequency[12][1] = 39
Frequency[13][1] = 36
Frequency[14][1] = 33
Frequency[15][1] = 30
Frequency[16][1] = 32
Frequency[17][1] = 34
Frequency[18][1] = 36
Frequency[19][1] = 25
Frequency[20][1] = 24
Frequency[21][1] = 25
Frequency[22][1] = 27
Frequency[23][1] = 29
Frequency[24][1] = 34
Frequency[25][1] = 29
Frequency[26][1] = 27
Frequency[27][1] = 25
Frequency[28][1] = 27
Frequency[29][1] = 29
Frequency[30][1] = 34
Frequency[31][1] = 36
Frequency[32][1] = 39
Frequency[33][1] = 41
Frequency[0][2] = 24
Frequency[1][2] = 18
Frequency[2][2] = 25
Frequency[3][2] = 18
Frequency[4][2] = 25
Frequency[5][2] = 20
Frequency[6][2] = 27
Frequency[7][2] = 20
Frequency[8][2] = 27
Frequency[9][2] = 22
Frequency[10][2] = 29
Frequency[11][2] = 22
Frequency[12][2] = 29
Frequency[13][2] = 22
Frequency[14][2] = 29
Frequency[15][2] = 22
Frequency[16][2] = 29
Frequency[17][2] = 18
Frequency[18][2] = 25
Frequency[19][2] = 18
Frequency[20][2] = 25
Frequency[21][2] = 20
Frequency[22][2] = 27
Frequency[23][2] = 20
Frequency[24][2] = 27
Frequency[25][2] = 17
Frequency[26][2] = 24
Frequency[27][2] = 17
Frequency[28][2] = 24
Frequency[29][2] = 17
Frequency[30][2] = 24
Frequency[31][2] = 17
Frequency[32][2] = 24
Frequency[33][2] = 15
Frequency[34][2] = 22
Frequency[35][2] = 15
Frequency[36][2] = 22
Frequency[37][2] = 17
Frequency[38][2] = 24
Frequency[39][2] = 17
Frequency[40][2] = 24
Frequency[41][2] = 18
Frequency[42][2] = 25
Frequency[43][2] = 18
Frequency[44][2] = 25
Frequency[45][2] = 17
Frequency[46][2] = 24
Frequency[47][2] = 17
Frequency[48][2] = 24
Frequency[49][2] = 18
Frequency[50][2] = 25
Frequency[51][2] = 18
Frequency[52][2] = 25
Frequency[53][2] = 20
Frequency[54][2] = 27
Frequency[55][2] = 20
Frequency[56][2] = 27
Frequency[57][2] = 22
Frequency[58][2] = 29
Frequency[59][2] = 24
Frequency[60][2] = 31
Frequency[61][2] = 26
Frequency[62][2] = 34
Frequency[63][2] = 38
Frequency[64][2] = 41
FOR CountY = 0 TO 1
Length[0][CountY] = 2
Length[1][CountY] = 2
Length[2][CountY] = 8
Length[3][CountY] = 2
Length[4][CountY] = 2
Length[5][CountY] = 4
Length[6][CountY] = 10
Length[7][CountY] = 2
Length[8][CountY] = 2
Length[9][CountY] = 2
Length[10][CountY] = 4
Length[11][CountY] = 4
Length[12][CountY] = 4
Length[13][CountY] = 4
Length[14][CountY] = 16
Length[15][CountY] = 8
Length[16][CountY] = 2
Length[17][CountY] = 2
Length[18][CountY] = 4
Length[19][CountY] = 8
Length[20][CountY] = 8
Length[21][CountY] = 2
Length[22][CountY] = 2
Length[23][CountY] = 2
Length[24][CountY] = 2
Length[25][CountY] = 2
Length[26][CountY] = 2
Length[27][CountY] = 2
Length[28][CountY] = 2
Length[29][CountY] = 2
Length[30][CountY] = 2
Length[31][CountY] = 2
Length[32][CountY] = 2
Length[33][CountY] = 8
NEXT
FOR CountX = 1 TO 64
Length[CountX][2] = 2
Volume[CountX][2] = 20000
NEXT
Length[0][2] = 4
Volume[0][2] = 0
FOR Count = 0 TO 33
FOR CountY = 0 TO 1
Volume[Count][CountY] = 20000
NEXT
NEXT

// Notenfrequenz

Note[0] = 27.5

FOR Count = 1 TO 119
Note[Count] = 1.059463094359 * Note[Count-1]
NEXT

// Für die Modulationssynthese: Frequenz, Phasenverschiebung und Lautstärke

FMFrequency[0] = 24
FMFrequency[1] = 12
FMFrequency[2] = 0
FMShift[0] = 0
FMShift[1] = 50
FMShift[2] = 0
FMVolume[0] = 1
FMVolume[1] = 1
FMVolume[2] = 0.5

FOR CountY = 0 TO 15
FOR CountX = 0 TO 8191
INC TotalLength[CountY], Length[CountX][CountY] * 4410
NEXT
NEXT

IF OPENFILE(1, "Output.wav", FALSE) // Save output

// Synthese, speicherung der Noten

CountX = 0
CountY = 0

WHILE TRUE
FOR CountY = 0 TO NumInstruments
IF Count[CountY] <> Length[CountZ[CountY]][CountY] * 4410
INC Count[CountY], 1
INC CurrentLength[CountY], 1
FMS[0] = (SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[0]]+FMShift[0])*Volume[CountZ[CountY]][CountY]*FMVolume[0])
FMS[1] = (SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[1]]+FMShift[1])*Volume[CountZ[CountY]][CountY]*FMVolume[1])
FMS[2] = SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[2]]+FMShift[2])
IF FMS[2] >= 0
FMS[2] = (1*Volume[CountZ[CountY]][CountY]*FMVolume[2])
ELSE
FMS[2] = (0*Volume[CountZ[CountY]][CountY]*FMVolume[2])
ENDIF
Sample[CountY] = (FMS[0]+FMS[1]+FMS[2])/3
ELSE
Count[CountY] = 0
IF CurrentLength[CountY] = TotalLength[CountY]
BREAK
ELSE
INC CountZ[CountY], 1
ENDIF
ENDIF
NEXT
WRITEWORD 1, (Sample[0]+Sample[1]+Sample[2])/3
WEND

CLOSEFILE 1

ENDIF

~ Cave Story rules! ~

Quentin

eine kurze Beschreibung, was das Teil eigentlich machen soll, ist generell kein Fehler ,))

die erzeugte Wav-Datei kann ich zumindest im Media-Player nicht abspielen.

S. P. Gardebiter

Update! Bin mal eben von 8-bit unsigniert auf 16-bit signiert umgestiegen, das macht vieles inzwischen einfacher.

Quote from: Quentin on 2008-Oct-13eine kurze Beschreibung, was das Teil eigentlich machen soll, ist generell kein Fehler ,))

Es legt zwei Sinus Kurven und eine Rechteck Kurve übereinander (Frequenz Modulation). Diese werden mit bestimmten werten mal genommen um bestimmte Noten rauszukriegen. 24 = A-2, 27 = C-3, 34 = G-3 u.s.w. (Synthese)

Quote from: Quentin on 2008-Oct-13die erzeugte Wav-Datei kann ich zumindest im Media-Player nicht abspielen.

:)

Quote from: S. P. Gardebiter on 2008-Oct-12Dieser Code gibt als Output nur Rohdaten aus, Format ist Mono bei 44100 Hz, signiertert, 16-Bit PCM.

Ein gutes Soundprogramm könnte diese Rohdaten auslesen. z.B. Audacity.
~ Cave Story rules! ~

Schranz0r

Rofl!

Tolle Melodie :D

Geöffnet mit Cool Edit Pro...

Geht evtl net in WMP weil kein Header angeben wird?
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

S. P. Gardebiter

Quote from: Schranz0r on 2008-Oct-14
Rofl!

Tolle Melodie :D

Geöffnet mit Cool Edit Pro...

Geht evtl net in WMP weil kein Header angeben wird?

Danke.
Ja exakt, wegen dem Header ;)
Hab ich aber schon geschrieben. Es werden nur Rohdaten ausgegeben.
~ Cave Story rules! ~

Schranz0r

Code (glbasic) Select
Wave File Header - RIFF Type Chunk
Wave file headers follow the standard RIFF file format structure. The first 8 bytes in the file is a standard RIFF chunk header which has a chunk ID of "RIFF" and a chunk size equal to the file size minus the 8 bytes used by the header. The first 4 data bytes in the "RIFF" chunk determines the type of resource found in the RIFF chunk. Wave files always use "WAVE". After the RIFF type comes all of the Wave file chunks that define the audio waveform.

Offset Size Description Value
0x00 4 Chunk ID "RIFF" (0x52494646)
0x04 4 Chunk Data Size (file size) - 8
0x08 4 RIFF Type "WAVE" (0x57415645)
0x10 Wave chunks
RIFF Type Chunk Values


Schau mal da:

http://www.sonicspot.com/guide/wavefiles.html
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

S. P. Gardebiter

http://www.glbasic.com/forum/index.php?topic=2378.0

Hatte ich schon, aber die ChunkSize war aus irgendwelchen Gründen immer falsch und der Wave somit unbrauchbar. :/
~ Cave Story rules! ~

S. P. Gardebiter

Habs geändert, das Output stimmt jetzt (Header geht aber immer noch nicht.), trozdem gibt mir der Debugger Fehler raus und ich hab keine Ahnung wieso.

Code (glbasic) Select
CountX = 0
CountY = 0
DIM Count[16]
DIM CountZ[16]

SampleRate = 44100

NumInstruments = 2
Samples = 0

// Für Noten und erzeugung des Tones
DIM Volume[8192][16]
DIM Frequency[8192][16]
DIM Length[8192][16]
DIM Volume[8192][16]
DIM Note[120]
DIM CurrentLength[16]
DIM TotalLength[16]
// Für die Frequenz Modulations Synthese
DIM FMS[16]
DIM FMFrequency[16]
DIM FMFineTune[16]
DIM FMShift[16]
DIM FMVolume[16]
DIM Sample[16]
// Noten, Notenlänge und Lautstärke definieren
Frequency[0][0] = 29
Frequency[1][0] = 32
Frequency[2][0] = 34
Frequency[3][0] = 36
Frequency[4][0] = 37
Frequency[5][0] = 41
Frequency[6][0] = 34
Frequency[7][0] = 41
Frequency[8][0] = 46
Frequency[9][0] = 48
Frequency[10][0] = 49
Frequency[11][0] = 46
Frequency[12][0] = 48
Frequency[13][0] = 44
Frequency[14][0] = 41
Frequency[15][0] = 34
Frequency[16][0] = 36
Frequency[17][0] = 37
Frequency[18][0] = 41
Frequency[19][0] = 34
Frequency[20][0] = 33
Frequency[21][0] = 34
Frequency[22][0] = 36
Frequency[23][0] = 37
Frequency[24][0] = 41
Frequency[25][0] = 37
Frequency[26][0] = 36
Frequency[27][0] = 34
Frequency[28][0] = 36
Frequency[29][0] = 37
Frequency[30][0] = 39
Frequency[31][0] = 41
Frequency[32][0] = 44
Frequency[33][0] = 46
Frequency[0][1] = 25
Frequency[1][1] = 28
Frequency[2][1] = 30
Frequency[3][1] = 32
Frequency[4][1] = 34
Frequency[5][1] = 37
Frequency[6][1] = 29
Frequency[7][1] = 37
Frequency[8][1] = 41
Frequency[9][1] = 41
Frequency[10][1] = 41
Frequency[11][1] = 37
Frequency[12][1] = 39
Frequency[13][1] = 36
Frequency[14][1] = 33
Frequency[15][1] = 30
Frequency[16][1] = 32
Frequency[17][1] = 34
Frequency[18][1] = 36
Frequency[19][1] = 25
Frequency[20][1] = 24
Frequency[21][1] = 25
Frequency[22][1] = 27
Frequency[23][1] = 29
Frequency[24][1] = 34
Frequency[25][1] = 29
Frequency[26][1] = 27
Frequency[27][1] = 25
Frequency[28][1] = 27
Frequency[29][1] = 29
Frequency[30][1] = 34
Frequency[31][1] = 36
Frequency[32][1] = 39
Frequency[33][1] = 41
Frequency[0][2] = 24
Frequency[1][2] = 18
Frequency[2][2] = 25
Frequency[3][2] = 18
Frequency[4][2] = 25
Frequency[5][2] = 20
Frequency[6][2] = 27
Frequency[7][2] = 20
Frequency[8][2] = 27
Frequency[9][2] = 22
Frequency[10][2] = 29
Frequency[11][2] = 22
Frequency[12][2] = 29
Frequency[13][2] = 22
Frequency[14][2] = 29
Frequency[15][2] = 22
Frequency[16][2] = 29
Frequency[17][2] = 18
Frequency[18][2] = 25
Frequency[19][2] = 18
Frequency[20][2] = 25
Frequency[21][2] = 20
Frequency[22][2] = 27
Frequency[23][2] = 20
Frequency[24][2] = 27
Frequency[25][2] = 17
Frequency[26][2] = 24
Frequency[27][2] = 17
Frequency[28][2] = 24
Frequency[29][2] = 17
Frequency[30][2] = 24
Frequency[31][2] = 17
Frequency[32][2] = 24
Frequency[33][2] = 15
Frequency[34][2] = 22
Frequency[35][2] = 15
Frequency[36][2] = 22
Frequency[37][2] = 17
Frequency[38][2] = 24
Frequency[39][2] = 17
Frequency[40][2] = 24
Frequency[41][2] = 18
Frequency[42][2] = 25
Frequency[43][2] = 18
Frequency[44][2] = 25
Frequency[45][2] = 17
Frequency[46][2] = 24
Frequency[47][2] = 17
Frequency[48][2] = 24
Frequency[49][2] = 18
Frequency[50][2] = 25
Frequency[51][2] = 18
Frequency[52][2] = 25
Frequency[53][2] = 20
Frequency[54][2] = 27
Frequency[55][2] = 20
Frequency[56][2] = 27
Frequency[57][2] = 22
Frequency[58][2] = 29
Frequency[59][2] = 24
Frequency[60][2] = 31
Frequency[61][2] = 26
Frequency[62][2] = 34
Frequency[63][2] = 38
Frequency[64][2] = 41
FOR CountY = 0 TO 1
Length[0][CountY] = 2
Length[1][CountY] = 2
Length[2][CountY] = 8
Length[3][CountY] = 2
Length[4][CountY] = 2
Length[5][CountY] = 4
Length[6][CountY] = 10
Length[7][CountY] = 2
Length[8][CountY] = 2
Length[9][CountY] = 2
Length[10][CountY] = 4
Length[11][CountY] = 4
Length[12][CountY] = 4
Length[13][CountY] = 4
Length[14][CountY] = 16
Length[15][CountY] = 8
Length[16][CountY] = 2
Length[17][CountY] = 2
Length[18][CountY] = 4
Length[19][CountY] = 8
Length[20][CountY] = 8
Length[21][CountY] = 2
Length[22][CountY] = 2
Length[23][CountY] = 2
Length[24][CountY] = 2
Length[25][CountY] = 2
Length[26][CountY] = 2
Length[27][CountY] = 2
Length[28][CountY] = 2
Length[29][CountY] = 2
Length[30][CountY] = 2
Length[31][CountY] = 2
Length[32][CountY] = 2
Length[33][CountY] = 8
NEXT
FOR CountX = 1 TO 64
Length[CountX][2] = 2
Volume[CountX][2] = 20000
NEXT
Length[0][2] = 4
Volume[0][2] = 0
FOR Count = 0 TO 33
FOR CountY = 0 TO 1
Volume[Count][CountY] = 20000
NEXT
NEXT

// Notenfrequenz

Note[0] = 27.5

FOR Count = 1 TO 119
Note[Count] = 1.059463094359 * Note[Count-1]
NEXT

// Für die Modulationssynthese: Frequenz, Phasenverschiebung und Lautstärke

FMFrequency[0] = 24
FMFrequency[1] = 12
FMFrequency[2] = 0
FMShift[0] = 0
FMShift[1] = 50
FMShift[2] = 0
FMVolume[0] = 1
FMVolume[1] = 1
FMVolume[2] = 0.5

FOR CountY = 0 TO 15
FOR CountX = 0 TO 8191
INC TotalLength[CountY], Length[CountX][CountY] * 4410
NEXT
NEXT

IF OPENFILE(1, "Output.wav", FALSE) // Save output

// Synthese, speicherung der Noten

CountX = 0
CountY = 0

WHILE TRUE
FOR CountY = 0 TO NumInstruments
IF Count[CountY] <> Length[CountZ[CountY]][CountY] * 4410
INC Count[CountY], 1
INC CurrentLength[CountY], 1
FMS[0] = (SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[0]]+FMShift[0])*Volume[CountZ[CountY]][CountY]*FMVolume[0])
FMS[1] = (SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[1]]+FMShift[1])*Volume[CountZ[CountY]][CountY]*FMVolume[1])
FMS[2] = SIN(360/SampleRate*Count[CountY]*Note[Frequency[CountZ[CountY]][CountY]+FMFrequency[2]]+FMShift[2])
IF FMS[2] >= 0
FMS[2] = (1*Volume[CountZ[CountY]][CountY]*FMVolume[2])
ELSE
FMS[2] = (0*Volume[CountZ[CountY]][CountY]*FMVolume[2])
ENDIF
Sample[CountY] = (FMS[0]+FMS[1]+FMS[2])/3
ELSE
Count[CountY] = 0
IF CurrentLength[CountY] = TotalLength[CountY]
BREAK
ELSE
INC CountZ[CountY], 1
ENDIF
ENDIF
NEXT
WRITEWORD 1, (Sample[0]+Sample[1]+Sample[2])/3
WEND

CLOSEFILE 1

ENDIF
~ Cave Story rules! ~

Kitty Hello

benutz den Befehl "DEBUG" um schneller debuggen zu können, indem Du die letzen Werte vor dem Crash rausscheibst.

Hemlos

#9
first of all....the program is crashing with that INC command...it has a limt.

I didnt figgure out wav format yet...but if im not mistaking, you need to have a header.
i did compile this with a different line instad of writeline, i used byte or shortieee..and it worked one time. i cant replicate....sucks. :(

i know that doesnt help much.....but i think im getting closer to being able to write the proper format.
heres what i figgured out so for for making a binary file:

midi format: you have to convert everything to be a BYTE, and not the standard way, using a 32bit unsigned.
This is good news...i started making midi files and i have a header done so far(thats why i came here. to tell you you might need all byte instead of line or shortieee
this might be the case for making a wav binary in glbasic too....you might have to convert everything to byte, and dont forget about adding a header to your bins. and reduce the number of samples so glbasic doesnt crash...


add this code at the end of program so you know if it is crashing or not.
Code (glbasic) Select

print "EOF",100,100
showscreen
mousewait


this is how i found the program crashing at count $
....i added this in the loop before each command:
Code (glbasic) Select
putfile "test.txt",line0#,"dataLine"+line0#+"="+count for a debugging method...the program crash count itteration will be on line 0 in test.txt.

here is how i am converting data into a binary:
MThd is 4 bytes, and length is 4 bytes ,not unsigned short 32bit
WRITEBYTE 1,ASC("M")
WRITEBYTE 1,ASC("T")
WRITEBYTE 1,ASC("h")
WRITEBYTE 1,ASC("d")
//MThd

WRITEBYTE 1,0
WRITEBYTE 1,0
WRITEBYTE 1,0
WRITEBYTE 1,6
//0x00000006
Bing ChatGpt is pretty smart :O

S. P. Gardebiter

I already know how to make a header, just the calculation of it's chunksize isn't correct, that's why it doesn't work. But it should work.
~ Cave Story rules! ~

Hemlos

Quote from: S. P. Gardebiter on 2008-Oct-21
I already know how to make a header, just the calculation of it's chunksize isn't correct, that's why it doesn't work. But it should work.

ok it should work...but it isnt because of the crash at array[]
theres a problem with the index number going into the array..im sure this is why it is crashing.
ass this to your file and check the test.txt to see at what INC CountY is crashing the array.
From there, do a workaround to limit the bounds to prevent crashing the array[]
If you crash an array, the program is ending before the end of the file.

putfile "test.txt",line0#,"dataLine"+line0#+"="+CountY

after the prgram run, open and look at the number in test.txt
Bing ChatGpt is pretty smart :O

Hemlos

#12
This might help:

Quote from: http://www.sonicspot.com/guide/wavefiles.htmlOne tricky thing about RIFF file chunks is that they must be word aligned. This means that their total size must be a multiple of 2 bytes (ie. 2, 4, 6, 8, and so on). If a chunk contains an odd number of data bytes, causing it not to be word aligned, an extra padding byte with a value of zero must follow the last data byte. This extra padding byte is not counted in the chunk size, therefor a program must always word align a chunk headers size value in order to calculate the offset of the following chunk.

so the volume 20000 is 4 bytes not 2, right?
0xff=256 is 2 bytes.
20000 needs to write to 4 bytes because it is >2 bytes.
0xff 0xff is for numbers >256 which is uptoi 65536 decimal value.

Also try this...make one simple and short length sound, keep it under 128 bytes if possible.
Then go up in size, and when you hit an issue with byte count being wrong...you know you need to to shift the value to a new 2 byte word group.
Bing ChatGpt is pretty smart :O

Hemlos

#13
I have an easy solution for you..
The first 8 bytes in the file is a standard RIFF chunk header which has a chunk ID of "RIFF" and a chunk size equal to the file size minus the 8 bytes used by the header.

Put the chunk data into a data.dat file...and read the total bytes like this:

Code (glbasic) Select
loadfile$="chunk.dat"
OPENFILE(0,loadfile$,TRUE)
FILESEEK(0, 0, -1) //go to last byte
a=FILEPOSITION(0) //byte total=position at end
PRINT "Total Bytes="+a,10,10
SHOWSCREEN
MOUSEWAIT


ps i wish i would of thought of this when i was making midi headers lol
Bing ChatGpt is pretty smart :O

S. P. Gardebiter

Quote from: Ocean on 2008-Oct-22
the way I read your code is that you're adding the base waveforms.  If that assertion is correct, you're actually doing amplitude modulation, not frequency modulation (even if varying audible frequencies result from it...)

I know. It isn't done yet :D
The most correct would be "Amplitude modulation synthesis".

Quote from: Hemlos on 2008-Oct-21From there, do a workaround to limit the bounds to prevent crashing the array[]
If you crash an array, the program is ending before the end of the file.

putfile "test.txt",line0#,"dataLine"+line0#+"="+CountY

after the prgram run, open and look at the number in test.txt

The weird thing is, I'm not missing any samples in the raw wave file.
I'll give it a shot, thanks.

Quote from: Hemlos on 2008-Oct-28so the volume 20000 is 4 bytes not 2, right?
0xff=256 is 2 bytes.
20000 needs to write to 4 bytes because it is >2 bytes.
0xff 0xff is for numbers >256 which is uptoi 65536 decimal value.

0xF = 11111111b = 1 Nybble
0xFF = 11111111 11111111b = 1 Byte
0xFFFF = Word (2 Bytes)

Quote from: Hemlos on 2008-Oct-28Put the chunk data into a data.dat file...and read the total bytes like this:

Code (glbasic) Select
loadfile$="chunk.dat"
OPENFILE(0,loadfile$,TRUE)
FILESEEK(0, 0, -1) //go to last byte
a=FILEPOSITION(0) //byte total=position at end
PRINT "Total Bytes="+a,10,10
SHOWSCREEN
MOUSEWAIT

Already done with calculation in my old code.
~ Cave Story rules! ~