GLBasic forum

Main forum => Bug Reports => Topic started by: S. P. Gardebiter on 2008-Oct-14

Title: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-14
Hab ein wenig mit meinem FMS programm rumgespielt und ich musst leider einen ziemlich üblen Fehler feststellen O_o

Code (glbasic) Select
// --------------------------------- //
// Project: Frequency Modulation Music 44
// Start: Sunday, October 12, 2008
// IDE Version: 5.360


Count = 0
CountX = 0
CountY = 0

SampleRate = 44100

TotalLength = 0

// Für Noten und erzeugung des Tones
DIM Volume[8192]
DIM Frequency[8192]
DIM Length[8192]
DIM Volume[8192]
DIM Note[120]
DIM Samples[13230000][2]
// Für die Frequenz Modulations Synthese
DIM FMS[16]
DIM FMFrequency[16]
DIM FMFineTune[16]
DIM FMShift[16]
DIM FMVolume[16]

// Noten, Notenlänge und Lautstärke definieren
Frequency[0] = 39
Frequency[1] = 42
Frequency[2] = 44
Frequency[3] = 46
Frequency[4] = 47
Frequency[5] = 51
Frequency[6] = 44
Frequency[7] = 51
Frequency[8] = 56
Frequency[9] = 58
Frequency[10] = 59
Frequency[11] = 56
Frequency[12] = 58
Frequency[13] = 54
Frequency[14] = 51
Frequency[15] = 44
Frequency[16] = 46
Frequency[17] = 47
Frequency[18] = 51
Frequency[19] = 44
Frequency[20] = 43
Frequency[21] = 44
Frequency[22] = 46
Frequency[23] = 47
Frequency[24] = 51
Frequency[25] = 47
Frequency[26] = 46
Frequency[27] = 44
Frequency[28] = 46
Frequency[29] = 47
Frequency[30] = 49
Frequency[31] = 51
Frequency[32] = 54
Frequency[33] = 56
Length[0] = 2
Length[1] = 2
Length[2] = 8
Length[3] = 2
Length[4] = 2
Length[5] = 4
Length[6] = 10
Length[7] = 2
Length[8] = 2
Length[9] = 2
Length[10] = 4
Length[11] = 4
Length[12] = 4
Length[13] = 4
Length[14] = 16
Length[15] = 8
Length[16] = 2
Length[17] = 2
Length[18] = 4
Length[19] = 8
Length[20] = 8
Length[21] = 2
Length[22] = 2
Length[23] = 2
Length[24] = 2
Length[25] = 2
Length[26] = 2
Length[27] = 2
Length[28] = 2
Length[29] = 2
Length[30] = 2
Length[31] = 2
Length[32] = 2
Length[33] = 8
Volume[0] = 20000
Volume[1] = 20000
Volume[2] = 20000
Volume[3] = 20000
Volume[4] = 20000
Volume[5] = 20000
Volume[6] = 20000
Volume[7] = 20000
Volume[8] = 20000
Volume[9] = 20000
Volume[10] = 20000
Volume[11] = 20000
Volume[12] = 20000
Volume[13] = 20000
Volume[14] = 20000
Volume[15] = 20000
Volume[16] = 20000
Volume[17] = 20000
Volume[18] = 20000
Volume[19] = 20000
Volume[20] = 20000
Volume[21] = 20000
Volume[22] = 20000
Volume[23] = 20000
Volume[24] = 20000
Volume[25] = 20000
Volume[26] = 20000
Volume[27] = 20000
Volume[28] = 20000
Volume[29] = 20000
Volume[30] = 20000
Volume[31] = 20000
Volume[32] = 20000
Volume[33] = 20000

// 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] = 12
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 Count = 0 TO 33
INC TotalLength, Length[Count][0]
NEXT

REDIM Samples[TotalLength*44100/10][2]

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

                // Nach diesem Code hier wird nichts mehr gespeichert:

FOR CountX = 0 TO 33
FOR CountY = 0 TO Length[CountX][0] * 44100 / 10
INC Count, 1
FMS[0] = (SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[0]]+FMShift[0])*Volume[CountX]*FMVolume[0])
FMS[1] = (SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[1]]+FMShift[1])*Volume[CountX]*FMVolume[1])
FMS[2] = SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[2]]+FMShift[2])
IF FMS[2] >= 0
FMS[2] = (1*Volume[CountX]*FMVolume[2])
ELSE
FMS[2] = (0*Volume[CountX]*FMVolume[2])
ENDIF
Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3
Samples[Count][0] = Samples[Count][1]
NEXT
NEXT

WRITEBYTE 1, 5 // Wird ignoriert und nicht als Datei gespeichert...

ENDIF


Bitte einmal nach ganz unten scrollen.
Weiß jemand warum? O_o
Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-14
Mit V6 oder V5?
Sollte in V6 gehen. Schau mal, ob ein CLOSEFILE am Ende hilft?
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-14
Ich hab Version 5 und das Online Update sagt mir auch das die Version aktuell ist O_o
Wo krieg ich 6 her? ;)

Naja, Closefile hilft auch nichts, hab ich schon probiert...
Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-14
Im IRC Chat "? betasdk" eingeben.
Title: Re: WRITE...
Post by: Schranz0r on 2008-Oct-14
QuoteVolume[0] = 20000
   Volume[1] = 20000
   Volume[2] = 20000
   Volume[3] = 20000
   Volume[4] = 20000
   Volume[5] = 20000
   Volume[6] = 20000
   Volume[7] = 20000
   Volume[8] = 20000
   Volume[9] = 20000
   Volume[10] = 20000
   Volume[11] = 20000
   Volume[12] = 20000
   Volume[13] = 20000
   Volume[14] = 20000
   Volume[15] = 20000
   Volume[16] = 20000
   Volume[17] = 20000
   Volume[18] = 20000
   Volume[19] = 20000
   Volume[20] = 20000
   Volume[21] = 20000
   Volume[22] = 20000
   Volume[23] = 20000
   Volume[24] = 20000
   Volume[25] = 20000
   Volume[26] = 20000
   Volume[27] = 20000
   Volume[28] = 20000
   Volume[29] = 20000
   Volume[30] = 20000
   Volume[31] = 20000
   Volume[32] = 20000
   Volume[33] = 20000

Mir wird schlecht :D

*öhm* For-Schleife  :nana:
Title: Re: WRITE...
Post by: Hemlos on 2008-Oct-14
If CountX=33, If CountY=35246, If Count=582120
When  these are true....this next line causes the crash:
Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3

:enc:

I hope you can figgure out why it is crashing, this is a really interesting program.

Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-14
You allocate 100 MB - is that really needed?
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-14
Quote from: Kitty Hello on 2008-Oct-14
Im IRC Chat "? betasdk" eingeben.

Danke.

Quote from: Schranz0r on 2008-Oct-14Mir wird schlecht :D

*öhm* For-Schleife  :nana:

Schon erledigt.

Quote from: Hemlos on 2008-Oct-14If CountX=33, If CountY=35246, If Count=582120
When  these are true....this next line causes the crash:
Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3

Uh...? I have no idea, normally it should work.

Quote from: Kitty Hello on 2008-Oct-14
You allocate 100 MB - is that really needed?

Yes, I think about 200 MB.
200 MB are for a 10 Minute Sound File.
And no that's not needed, I will edit it :)

Edit: Es funktioniert immer noch nicht :/ Selbst mit GLBasic V6 nicht.
Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-15
Der springt hier raus:
            Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3
Weil Count >= BOUNDS(Samples[], 0) wird.

Pack's mal nicht in ein Feld, sondern schreib die Daten direkt raus.
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-15
Quote from: Kitty Hello on 2008-Oct-15
Der springt hier raus:
            Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3
Weil Count >= BOUNDS(Samples[], 0) wird.

Pack's mal nicht in ein Feld, sondern schreib die Daten direkt raus.

Ich frag mich warum er kleiner ist als der Array ist.
Ich kann die daten nicht direkt ausgeben, weil ich sie für die bearbeitung zusammenschneiden will (Zweites Instrument z.B.). Andernfalls muss ich was sehr umständliches machen.
Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-15
OK, dann nimm mit V6 wenigstens ein array von DGNat. Also arr%[].
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-15
Quote from: Kitty Hello on 2008-Oct-15
OK, dann nimm mit V6 wenigstens ein array von DGNat. Also arr%[].


DIM Samples%[2][2]?
Title: Re: WRITE...
Post by: Kitty Hello on 2008-Oct-15
Jo so. Oder:
LOCAL Samples%[]
...

Das % ist dannach optional - nur beim ersten Mal, wenn der Precompiler ein % findet wird der Variablentyp festgelegt und dann konsequent beibehalten:

LOCAL a%
a = 5 // greift jetzt auf a% zu.
Title: Re: WRITE...
Post by: Schranz0r on 2008-Oct-15
Mehrere Instrumente... Types?
Title: Re: WRITE...
Post by: Hemlos on 2008-Oct-16
Any luck yet  S. P. Gardebiter
Did you figgure out if its a bug with glbasic using the debugger?

Did you try using gernots latest suggestion using samples%[]?

Im interested to see this work.

BTW if you do get it to work, may i suggest making a midi format sound generator?
Theres alot of sound features like, music instruments, ocean waves, and gunshots, helicopters etc etc etc Its all built into the midi drivers already, i think all you need to do is the same thing youre trying here with the wav, building with "write"...
...im working on such a midi program, however, my way requires me to parse data into a 3rd party program to create the file, using a text formated input. I dont like it this way using a second program, but I dont really understand the way write works.
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-16
Quote from: Hemlos on 2008-Oct-16
Any luck yet  S. P. Gardebiter
Did you figgure out if its a bug with glbasic using the debugger?

Did you try using gernots latest suggestion using samples%[]?

Im interested to see this work.

BTW if you do get it to work, may i suggest making a midi format sound generator?
Theres alot of sound features like, music instruments, ocean waves, and gunshots, helicopters etc etc etc Its all built into the midi drivers already, i think all you need to do is the same thing youre trying here with the wav, building with "write"...
...im working on such a midi program, however, my way requires me to parse data into a 3rd party program to create the file, using a text formated input. I dont like it this way using a second program, but I dont really understand the way write works.

The difference here is that mine is a synthesizer and therefor a sampler.
My code is a bit hard to explain, even I don't know sometimes what I'm doing exactly, it works at the end though it's buggy. If you want to know details it may be easier to contact me via IM or IRC.

Please take a look at this thread: http://www.glbasic.com/forum/index.php?topic=2403.0
Title: Re: WRITE...
Post by: S. P. Gardebiter on 2008-Oct-20
Quote from: Hemlos on 2008-Oct-18
Quote from: peterpan on October 18, 2008, 4:24:39 PMHi Hemlos,

your name is S.P.Gardebiter ?
I thought  that i have found, why that byte  will not stored.
That's all.  What did i do wrong here ? Can you say it to me ?

Peter


No.
Ill show you.
Yes.
Code (glbasic) Select
FOR CountX = 0 TO 33
         FOR CountY = 0 TO Length[CountX][0] * 44100 / 10
            INC Count, 1
            FMS[0] = (SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[0]]+FMShift[0])*Volume[CountX]*FMVolume[0])
            FMS[1] = (SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[1]]+FMShift[1])*Volume[CountX]*FMVolume[1])
            FMS[2] = SIN(360/SampleRate*Count*Note[Frequency[CountX]+FMFrequency[2]]+FMShift[2])
            IF FMS[2] >= 0
               FMS[2] = (1*Volume[CountX]*FMVolume[2])
            ELSE
               FMS[2] = (0*Volume[CountX]*FMVolume[2])
            ENDIF
            Samples[Count][1] = (FMS[0]+FMS[1]+FMS[2])/3
            Samples[Count][0] = Samples[Count][1]
         NEXT


Yes, this is why the fms[2]=,sin wont calculate...you wrote the IF above the same thing as this:

Code (glbasic) Select
if FMS[2] < 0
FMS[2] = 0
else
FMS[2] = Volume[CountX]*FMVolume[2]
endif

it removes negative numbers, also and the SIN before it; will not be calculated/read.

FMS[2] isn't a sin wave, it's a square wave.
Title: Re: WRITE...
Post by: Vampire on 2008-Oct-22
Quote from: Kitty Hello on 2008-Oct-14
Im IRC Chat "? betasdk" eingeben.

hallo zusammen :)

das habe ich grad versucht, funzt nicht.
bin mit opera da drin, könnte es daran liegen?
würde die beta sehr gern mal sehen...